Начат фронтенд
This commit is contained in:
164
node_modules/autoprefixer/lib/selector.js
generated
vendored
164
node_modules/autoprefixer/lib/selector.js
generated
vendored
@@ -1,8 +1,8 @@
|
||||
let { list } = require('postcss')
|
||||
|
||||
let Browsers = require('./browsers')
|
||||
let OldSelector = require('./old-selector')
|
||||
let Prefixer = require('./prefixer')
|
||||
let Browsers = require('./browsers')
|
||||
let utils = require('./utils')
|
||||
|
||||
class Selector extends Prefixer {
|
||||
@@ -12,17 +12,75 @@ class Selector extends Prefixer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone and add prefixes for at-rule
|
||||
* Is rule selectors need to be prefixed
|
||||
*/
|
||||
add(rule, prefix) {
|
||||
let prefixeds = this.prefixeds(rule)
|
||||
|
||||
if (this.already(rule, prefixeds, prefix)) {
|
||||
return
|
||||
check(rule) {
|
||||
if (rule.selector.includes(this.name)) {
|
||||
return !!rule.selector.match(this.regexp())
|
||||
}
|
||||
|
||||
let cloned = this.clone(rule, { selector: prefixeds[this.name][prefix] })
|
||||
rule.parent.insertBefore(rule, cloned)
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Return prefixed version of selector
|
||||
*/
|
||||
prefixed(prefix) {
|
||||
return this.name.replace(/^(\W*)/, `$1${prefix}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazy loadRegExp for name
|
||||
*/
|
||||
regexp(prefix) {
|
||||
if (!this.regexpCache.has(prefix)) {
|
||||
let name = prefix ? this.prefixed(prefix) : this.name
|
||||
this.regexpCache.set(
|
||||
prefix,
|
||||
new RegExp(`(^|[^:"'=])${utils.escapeRegexp(name)}`, 'gi')
|
||||
)
|
||||
}
|
||||
|
||||
return this.regexpCache.get(prefix)
|
||||
}
|
||||
|
||||
/**
|
||||
* All possible prefixes
|
||||
*/
|
||||
possible() {
|
||||
return Browsers.prefixes()
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all possible selector prefixes
|
||||
*/
|
||||
prefixeds(rule) {
|
||||
if (rule._autoprefixerPrefixeds) {
|
||||
if (rule._autoprefixerPrefixeds[this.name]) {
|
||||
return rule._autoprefixerPrefixeds
|
||||
}
|
||||
} else {
|
||||
rule._autoprefixerPrefixeds = {}
|
||||
}
|
||||
|
||||
let prefixeds = {}
|
||||
if (rule.selector.includes(',')) {
|
||||
let ruleParts = list.comma(rule.selector)
|
||||
let toProcess = ruleParts.filter(el => el.includes(this.name))
|
||||
|
||||
for (let prefix of this.possible()) {
|
||||
prefixeds[prefix] = toProcess
|
||||
.map(el => this.replace(el, prefix))
|
||||
.join(', ')
|
||||
}
|
||||
} else {
|
||||
for (let prefix of this.possible()) {
|
||||
prefixeds[prefix] = this.replace(rule.selector, prefix)
|
||||
}
|
||||
}
|
||||
|
||||
rule._autoprefixerPrefixeds[this.name] = prefixeds
|
||||
return rule._autoprefixerPrefixeds
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,14 +119,24 @@ class Selector extends Prefixer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is rule selectors need to be prefixed
|
||||
* Replace selectors by prefixed one
|
||||
*/
|
||||
check(rule) {
|
||||
if (rule.selector.includes(this.name)) {
|
||||
return !!rule.selector.match(this.regexp())
|
||||
replace(selector, prefix) {
|
||||
return selector.replace(this.regexp(), `$1${this.prefixed(prefix)}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone and add prefixes for at-rule
|
||||
*/
|
||||
add(rule, prefix) {
|
||||
let prefixeds = this.prefixeds(rule)
|
||||
|
||||
if (this.already(rule, prefixeds, prefix)) {
|
||||
return
|
||||
}
|
||||
|
||||
return false
|
||||
let cloned = this.clone(rule, { selector: prefixeds[this.name][prefix] })
|
||||
rule.parent.insertBefore(rule, cloned)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,74 +145,6 @@ class Selector extends Prefixer {
|
||||
old(prefix) {
|
||||
return new OldSelector(this, prefix)
|
||||
}
|
||||
|
||||
/**
|
||||
* All possible prefixes
|
||||
*/
|
||||
possible() {
|
||||
return Browsers.prefixes()
|
||||
}
|
||||
|
||||
/**
|
||||
* Return prefixed version of selector
|
||||
*/
|
||||
prefixed(prefix) {
|
||||
return this.name.replace(/^(\W*)/, `$1${prefix}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all possible selector prefixes
|
||||
*/
|
||||
prefixeds(rule) {
|
||||
if (rule._autoprefixerPrefixeds) {
|
||||
if (rule._autoprefixerPrefixeds[this.name]) {
|
||||
return rule._autoprefixerPrefixeds
|
||||
}
|
||||
} else {
|
||||
rule._autoprefixerPrefixeds = {}
|
||||
}
|
||||
|
||||
let prefixeds = {}
|
||||
if (rule.selector.includes(',')) {
|
||||
let ruleParts = list.comma(rule.selector)
|
||||
let toProcess = ruleParts.filter(el => el.includes(this.name))
|
||||
|
||||
for (let prefix of this.possible()) {
|
||||
prefixeds[prefix] = toProcess
|
||||
.map(el => this.replace(el, prefix))
|
||||
.join(', ')
|
||||
}
|
||||
} else {
|
||||
for (let prefix of this.possible()) {
|
||||
prefixeds[prefix] = this.replace(rule.selector, prefix)
|
||||
}
|
||||
}
|
||||
|
||||
rule._autoprefixerPrefixeds[this.name] = prefixeds
|
||||
return rule._autoprefixerPrefixeds
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazy loadRegExp for name
|
||||
*/
|
||||
regexp(prefix) {
|
||||
if (!this.regexpCache.has(prefix)) {
|
||||
let name = prefix ? this.prefixed(prefix) : this.name
|
||||
this.regexpCache.set(
|
||||
prefix,
|
||||
new RegExp(`(^|[^:"'=])${utils.escapeRegexp(name)}`, 'gi')
|
||||
)
|
||||
}
|
||||
|
||||
return this.regexpCache.get(prefix)
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace selectors by prefixed one
|
||||
*/
|
||||
replace(selector, prefix) {
|
||||
return selector.replace(this.regexp(), `$1${this.prefixed(prefix)}`)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Selector
|
||||
|
||||
Reference in New Issue
Block a user