Начат фронтенд
This commit is contained in:
352
node_modules/autoprefixer/lib/supports.js
generated
vendored
352
node_modules/autoprefixer/lib/supports.js
generated
vendored
@@ -2,10 +2,10 @@ let featureQueries = require('caniuse-lite/data/features/css-featurequeries.js')
|
||||
let feature = require('caniuse-lite/dist/unpacker/feature')
|
||||
let { parse } = require('postcss')
|
||||
|
||||
let brackets = require('./brackets')
|
||||
let Browsers = require('./browsers')
|
||||
let utils = require('./utils')
|
||||
let brackets = require('./brackets')
|
||||
let Value = require('./value')
|
||||
let utils = require('./utils')
|
||||
|
||||
let data = feature(featureQueries)
|
||||
|
||||
@@ -27,25 +27,161 @@ class Supports {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add prefixes
|
||||
* Return prefixer only with @supports supported browsers
|
||||
*/
|
||||
add(nodes, all) {
|
||||
return nodes.map(i => {
|
||||
if (this.isProp(i)) {
|
||||
let prefixed = this.prefixed(i[0])
|
||||
if (prefixed.length > 1) {
|
||||
return this.convert(prefixed)
|
||||
prefixer() {
|
||||
if (this.prefixerCache) {
|
||||
return this.prefixerCache
|
||||
}
|
||||
|
||||
let filtered = this.all.browsers.selected.filter(i => {
|
||||
return supported.includes(i)
|
||||
})
|
||||
|
||||
let browsers = new Browsers(
|
||||
this.all.browsers.data,
|
||||
filtered,
|
||||
this.all.options
|
||||
)
|
||||
this.prefixerCache = new this.Prefixes(
|
||||
this.all.data,
|
||||
browsers,
|
||||
this.all.options
|
||||
)
|
||||
return this.prefixerCache
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse string into declaration property and value
|
||||
*/
|
||||
parse(str) {
|
||||
let parts = str.split(':')
|
||||
let prop = parts[0]
|
||||
let value = parts[1]
|
||||
if (!value) value = ''
|
||||
return [prop.trim(), value.trim()]
|
||||
}
|
||||
|
||||
/**
|
||||
* Create virtual rule to process it by prefixer
|
||||
*/
|
||||
virtual(str) {
|
||||
let [prop, value] = this.parse(str)
|
||||
let rule = parse('a{}').first
|
||||
rule.append({ prop, value, raws: { before: '' } })
|
||||
return rule
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of Declaration with all necessary prefixes
|
||||
*/
|
||||
prefixed(str) {
|
||||
let rule = this.virtual(str)
|
||||
if (this.disabled(rule.first)) {
|
||||
return rule.nodes
|
||||
}
|
||||
|
||||
let result = { warn: () => null }
|
||||
|
||||
let prefixer = this.prefixer().add[rule.first.prop]
|
||||
prefixer && prefixer.process && prefixer.process(rule.first, result)
|
||||
|
||||
for (let decl of rule.nodes) {
|
||||
for (let value of this.prefixer().values('add', rule.first.prop)) {
|
||||
value.process(decl)
|
||||
}
|
||||
Value.save(this.all, decl)
|
||||
}
|
||||
|
||||
return rule.nodes
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if brackets node is "not" word
|
||||
*/
|
||||
isNot(node) {
|
||||
return typeof node === 'string' && /not\s*/i.test(node)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if brackets node is "or" word
|
||||
*/
|
||||
isOr(node) {
|
||||
return typeof node === 'string' && /\s*or\s*/i.test(node)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if brackets node is (prop: value)
|
||||
*/
|
||||
isProp(node) {
|
||||
return (
|
||||
typeof node === 'object' &&
|
||||
node.length === 1 &&
|
||||
typeof node[0] === 'string'
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if prefixed property has no unprefixed
|
||||
*/
|
||||
isHack(all, unprefixed) {
|
||||
let check = new RegExp(`(\\(|\\s)${utils.escapeRegexp(unprefixed)}:`)
|
||||
return !check.test(all)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if we need to remove node
|
||||
*/
|
||||
toRemove(str, all) {
|
||||
let [prop, value] = this.parse(str)
|
||||
let unprefixed = this.all.unprefixed(prop)
|
||||
|
||||
let cleaner = this.all.cleaner()
|
||||
|
||||
if (
|
||||
cleaner.remove[prop] &&
|
||||
cleaner.remove[prop].remove &&
|
||||
!this.isHack(all, unprefixed)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
for (let checker of cleaner.values('remove', unprefixed)) {
|
||||
if (checker.check(value)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all unnecessary prefixes
|
||||
*/
|
||||
remove(nodes, all) {
|
||||
let i = 0
|
||||
while (i < nodes.length) {
|
||||
if (
|
||||
!this.isNot(nodes[i - 1]) &&
|
||||
this.isProp(nodes[i]) &&
|
||||
this.isOr(nodes[i + 1])
|
||||
) {
|
||||
if (this.toRemove(nodes[i][0], all)) {
|
||||
nodes.splice(i, 2)
|
||||
continue
|
||||
}
|
||||
|
||||
return i
|
||||
i += 2
|
||||
continue
|
||||
}
|
||||
|
||||
if (typeof i === 'object') {
|
||||
return this.add(i, all)
|
||||
if (typeof nodes[i] === 'object') {
|
||||
nodes[i] = this.remove(nodes[i], all)
|
||||
}
|
||||
|
||||
return i
|
||||
})
|
||||
i += 1
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,65 +214,6 @@ class Supports {
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Check global options
|
||||
*/
|
||||
disabled(node) {
|
||||
if (!this.all.options.grid) {
|
||||
if (node.prop === 'display' && node.value.includes('grid')) {
|
||||
return true
|
||||
}
|
||||
if (node.prop.includes('grid') || node.prop === 'justify-items') {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if (this.all.options.flexbox === false) {
|
||||
if (node.prop === 'display' && node.value.includes('flex')) {
|
||||
return true
|
||||
}
|
||||
let other = ['order', 'justify-content', 'align-items', 'align-content']
|
||||
if (node.prop.includes('flex') || other.includes(node.prop)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if prefixed property has no unprefixed
|
||||
*/
|
||||
isHack(all, unprefixed) {
|
||||
let check = new RegExp(`(\\(|\\s)${utils.escapeRegexp(unprefixed)}:`)
|
||||
return !check.test(all)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if brackets node is "not" word
|
||||
*/
|
||||
isNot(node) {
|
||||
return typeof node === 'string' && /not\s*/i.test(node)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if brackets node is "or" word
|
||||
*/
|
||||
isOr(node) {
|
||||
return typeof node === 'string' && /\s*or\s*/i.test(node)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if brackets node is (prop: value)
|
||||
*/
|
||||
isProp(node) {
|
||||
return (
|
||||
typeof node === 'object' &&
|
||||
node.length === 1 &&
|
||||
typeof node[0] === 'string'
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress value functions into a string nodes
|
||||
*/
|
||||
@@ -162,63 +239,25 @@ class Supports {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse string into declaration property and value
|
||||
* Add prefixes
|
||||
*/
|
||||
parse(str) {
|
||||
let parts = str.split(':')
|
||||
let prop = parts[0]
|
||||
let value = parts[1]
|
||||
if (!value) value = ''
|
||||
return [prop.trim(), value.trim()]
|
||||
}
|
||||
add(nodes, all) {
|
||||
return nodes.map(i => {
|
||||
if (this.isProp(i)) {
|
||||
let prefixed = this.prefixed(i[0])
|
||||
if (prefixed.length > 1) {
|
||||
return this.convert(prefixed)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of Declaration with all necessary prefixes
|
||||
*/
|
||||
prefixed(str) {
|
||||
let rule = this.virtual(str)
|
||||
if (this.disabled(rule.first)) {
|
||||
return rule.nodes
|
||||
}
|
||||
|
||||
let result = { warn: () => null }
|
||||
|
||||
let prefixer = this.prefixer().add[rule.first.prop]
|
||||
prefixer && prefixer.process && prefixer.process(rule.first, result)
|
||||
|
||||
for (let decl of rule.nodes) {
|
||||
for (let value of this.prefixer().values('add', rule.first.prop)) {
|
||||
value.process(decl)
|
||||
return i
|
||||
}
|
||||
Value.save(this.all, decl)
|
||||
}
|
||||
|
||||
return rule.nodes
|
||||
}
|
||||
if (typeof i === 'object') {
|
||||
return this.add(i, all)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return prefixer only with @supports supported browsers
|
||||
*/
|
||||
prefixer() {
|
||||
if (this.prefixerCache) {
|
||||
return this.prefixerCache
|
||||
}
|
||||
|
||||
let filtered = this.all.browsers.selected.filter(i => {
|
||||
return supported.includes(i)
|
||||
return i
|
||||
})
|
||||
|
||||
let browsers = new Browsers(
|
||||
this.all.browsers.data,
|
||||
filtered,
|
||||
this.all.options
|
||||
)
|
||||
this.prefixerCache = new this.Prefixes(
|
||||
this.all.data,
|
||||
browsers,
|
||||
this.all.options
|
||||
)
|
||||
return this.prefixerCache
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,69 +273,30 @@ class Supports {
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all unnecessary prefixes
|
||||
* Check global options
|
||||
*/
|
||||
remove(nodes, all) {
|
||||
let i = 0
|
||||
while (i < nodes.length) {
|
||||
if (
|
||||
!this.isNot(nodes[i - 1]) &&
|
||||
this.isProp(nodes[i]) &&
|
||||
this.isOr(nodes[i + 1])
|
||||
) {
|
||||
if (this.toRemove(nodes[i][0], all)) {
|
||||
nodes.splice(i, 2)
|
||||
continue
|
||||
}
|
||||
|
||||
i += 2
|
||||
continue
|
||||
disabled(node) {
|
||||
if (!this.all.options.grid) {
|
||||
if (node.prop === 'display' && node.value.includes('grid')) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (typeof nodes[i] === 'object') {
|
||||
nodes[i] = this.remove(nodes[i], all)
|
||||
if (node.prop.includes('grid') || node.prop === 'justify-items') {
|
||||
return true
|
||||
}
|
||||
|
||||
i += 1
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if we need to remove node
|
||||
*/
|
||||
toRemove(str, all) {
|
||||
let [prop, value] = this.parse(str)
|
||||
let unprefixed = this.all.unprefixed(prop)
|
||||
|
||||
let cleaner = this.all.cleaner()
|
||||
|
||||
if (
|
||||
cleaner.remove[prop] &&
|
||||
cleaner.remove[prop].remove &&
|
||||
!this.isHack(all, unprefixed)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
for (let checker of cleaner.values('remove', unprefixed)) {
|
||||
if (checker.check(value)) {
|
||||
if (this.all.options.flexbox === false) {
|
||||
if (node.prop === 'display' && node.value.includes('flex')) {
|
||||
return true
|
||||
}
|
||||
let other = ['order', 'justify-content', 'align-items', 'align-content']
|
||||
if (node.prop.includes('flex') || other.includes(node.prop)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Create virtual rule to process it by prefixer
|
||||
*/
|
||||
virtual(str) {
|
||||
let [prop, value] = this.parse(str)
|
||||
let rule = parse('a{}').first
|
||||
rule.append({ prop, raws: { before: '' }, value })
|
||||
return rule
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Supports
|
||||
|
||||
Reference in New Issue
Block a user