Skip to content

Commit

Permalink
Update dependencies and code style
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Jul 8, 2023
1 parent 4a629f5 commit 66d23f6
Show file tree
Hide file tree
Showing 50 changed files with 2,046 additions and 1,926 deletions.
356 changes: 178 additions & 178 deletions data/prefixes.js

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions lib/autoprefixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ function plugin(...reqs) {
}

let brwlstOpts = {
env: options.env,
ignoreUnknownVersions: options.ignoreUnknownVersions,
stats: options.stats,
env: options.env
stats: options.stats
}

function loadPrefixes(opts) {
Expand All @@ -114,12 +114,21 @@ function plugin(...reqs) {
}

return {
postcssPlugin: 'autoprefixer',
browsers: reqs,

info(opts) {
opts = opts || {}
opts.from = opts.from || process.cwd()
return getInfo(loadPrefixes(opts))
},

options,

postcssPlugin: 'autoprefixer',
prepare(result) {
let prefixes = loadPrefixes({
from: result.opts.from,
env: options.env
env: options.env,
from: result.opts.from
})

return {
Expand All @@ -133,16 +142,7 @@ function plugin(...reqs) {
}
}
}
},

info(opts) {
opts = opts || {}
opts.from = opts.from || process.cwd()
return getInfo(loadPrefixes(opts))
},

options,
browsers: reqs
}
}
}

Expand Down
24 changes: 12 additions & 12 deletions lib/browsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ let { agents } = require('caniuse-lite/dist/unpacker/agents')
let utils = require('./utils')

class Browsers {
constructor(data, requirements, options, browserslistOpts) {
this.data = data
this.options = options || {}
this.browserslistOpts = browserslistOpts || {}
this.selected = this.parse(requirements)
}

/**
* Return all prefixes for default browser data
*/
Expand Down Expand Up @@ -35,11 +42,11 @@ class Browsers {
return this.prefixesRegexp.test(value)
}

constructor(data, requirements, options, browserslistOpts) {
this.data = data
this.options = options || {}
this.browserslistOpts = browserslistOpts || {}
this.selected = this.parse(requirements)
/**
* Is browser is selected by requirements
*/
isSelected(browser) {
return this.selected.includes(browser)
}

/**
Expand Down Expand Up @@ -67,13 +74,6 @@ class Browsers {
}
return `-${prefix}-`
}

/**
* Is browser is selected by requirements
*/
isSelected(browser) {
return this.selected.includes(browser)
}
}

module.exports = Browsers
184 changes: 92 additions & 92 deletions lib/declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,70 @@ let utils = require('./utils')

class Declaration extends Prefixer {
/**
* Always true, because we already get prefixer by property name
* Clone and add prefixes for declaration
*/
check(/* decl */) {
return true
add(decl, prefix, prefixes, result) {
let prefixed = this.prefixed(decl.prop, prefix)
if (
this.isAlready(decl, prefixed) ||
this.otherPrefixes(decl.value, prefix)
) {
return undefined
}
return this.insert(decl, prefix, prefixes, result)
}

/**
* Return prefixed version of property
* Calculate indentation to create visual cascade
*/
prefixed(prop, prefix) {
return prefix + prop
calcBefore(prefixes, decl, prefix = '') {
let max = this.maxPrefixed(prefixes, decl)
let diff = max - utils.removeNote(prefix).length

let before = decl.raw('before')
if (diff > 0) {
before += Array(diff).fill(' ').join('')
}

return before
}

/**
* Return unprefixed version of property
* Always true, because we already get prefixer by property name
*/
normalize(prop) {
return prop
check(/* decl */) {
return true
}

/**
* Check `value`, that it contain other prefixes, rather than `prefix`
* Clone and insert new declaration
*/
otherPrefixes(value, prefix) {
for (let other of Browsers.prefixes()) {
if (other === prefix) {
continue
}
if (value.includes(other)) {
return value.replace(/var\([^)]+\)/, '').includes(other)
}
insert(decl, prefix, prefixes) {
let cloned = this.set(this.clone(decl), prefix)
if (!cloned) return undefined

let already = decl.parent.some(
i => i.prop === cloned.prop && i.value === cloned.value
)
if (already) {
return undefined
}
return false
}

/**
* Set prefix to declaration
*/
set(decl, prefix) {
decl.prop = this.prefixed(decl.prop, prefix)
return decl
if (this.needCascade(decl)) {
cloned.raws.before = this.calcBefore(prefixes, decl, prefix)
}
return decl.parent.insertBefore(decl, cloned)
}

/**
* Should we use visual cascade for prefixes
* Did this declaration has this prefix above
*/
needCascade(decl) {
if (!decl._autoprefixerCascade) {
decl._autoprefixerCascade =
this.all.options.cascade !== false && decl.raw('before').includes('\n')
isAlready(decl, prefixed) {
let already = this.all.group(decl).up(i => i.prop === prefixed)
if (!already) {
already = this.all.group(decl).down(i => i.prop === prefixed)
}
return decl._autoprefixerCascade
return already
}

/**
Expand All @@ -79,82 +91,50 @@ class Declaration extends Prefixer {
}

/**
* Calculate indentation to create visual cascade
* Should we use visual cascade for prefixes
*/
calcBefore(prefixes, decl, prefix = '') {
let max = this.maxPrefixed(prefixes, decl)
let diff = max - utils.removeNote(prefix).length

let before = decl.raw('before')
if (diff > 0) {
before += Array(diff).fill(' ').join('')
needCascade(decl) {
if (!decl._autoprefixerCascade) {
decl._autoprefixerCascade =
this.all.options.cascade !== false && decl.raw('before').includes('\n')
}

return before
return decl._autoprefixerCascade
}

/**
* Remove visual cascade
* Return unprefixed version of property
*/
restoreBefore(decl) {
let lines = decl.raw('before').split('\n')
let min = lines[lines.length - 1]

this.all.group(decl).up(prefixed => {
let array = prefixed.raw('before').split('\n')
let last = array[array.length - 1]
if (last.length < min.length) {
min = last
}
})

lines[lines.length - 1] = min
decl.raws.before = lines.join('\n')
normalize(prop) {
return prop
}

/**
* Clone and insert new declaration
* Return list of prefixed properties to clean old prefixes
*/
insert(decl, prefix, prefixes) {
let cloned = this.set(this.clone(decl), prefix)
if (!cloned) return undefined

let already = decl.parent.some(
i => i.prop === cloned.prop && i.value === cloned.value
)
if (already) {
return undefined
}

if (this.needCascade(decl)) {
cloned.raws.before = this.calcBefore(prefixes, decl, prefix)
}
return decl.parent.insertBefore(decl, cloned)
old(prop, prefix) {
return [this.prefixed(prop, prefix)]
}

/**
* Did this declaration has this prefix above
* Check `value`, that it contain other prefixes, rather than `prefix`
*/
isAlready(decl, prefixed) {
let already = this.all.group(decl).up(i => i.prop === prefixed)
if (!already) {
already = this.all.group(decl).down(i => i.prop === prefixed)
otherPrefixes(value, prefix) {
for (let other of Browsers.prefixes()) {
if (other === prefix) {
continue
}
if (value.includes(other)) {
return value.replace(/var\([^)]+\)/, '').includes(other)
}
}
return already
return false
}

/**
* Clone and add prefixes for declaration
* Return prefixed version of property
*/
add(decl, prefix, prefixes, result) {
let prefixed = this.prefixed(decl.prop, prefix)
if (
this.isAlready(decl, prefixed) ||
this.otherPrefixes(decl.value, prefix)
) {
return undefined
}
return this.insert(decl, prefix, prefixes, result)
prefixed(prop, prefix) {
return prefix + prop
}

/**
Expand All @@ -177,10 +157,30 @@ class Declaration extends Prefixer {
}

/**
* Return list of prefixed properties to clean old prefixes
* Remove visual cascade
*/
old(prop, prefix) {
return [this.prefixed(prop, prefix)]
restoreBefore(decl) {
let lines = decl.raw('before').split('\n')
let min = lines[lines.length - 1]

this.all.group(decl).up(prefixed => {
let array = prefixed.raw('before').split('\n')
let last = array[array.length - 1]
if (last.length < min.length) {
min = last
}
})

lines[lines.length - 1] = min
decl.raws.before = lines.join('\n')
}

/**
* Set prefix to declaration
*/
set(decl, prefix) {
decl.prop = this.prefixed(decl.prop, prefix)
return decl
}
}

Expand Down
18 changes: 9 additions & 9 deletions lib/hacks/align-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ let flexSpec = require('./flex-spec')
let Declaration = require('../declaration')

class AlignContent extends Declaration {
/**
* Return property name by final spec
*/
normalize() {
return 'align-content'
}

/**
* Change property name for 2012 spec
*/
Expand All @@ -14,13 +21,6 @@ class AlignContent extends Declaration {
return super.prefixed(prop, prefix)
}

/**
* Return property name by final spec
*/
normalize() {
return 'align-content'
}

/**
* Change value for 2012 spec and ignore prefix for 2009
*/
Expand All @@ -42,8 +42,8 @@ AlignContent.names = ['align-content', 'flex-line-pack']
AlignContent.oldValues = {
'flex-end': 'end',
'flex-start': 'start',
'space-between': 'justify',
'space-around': 'distribute'
'space-around': 'distribute',
'space-between': 'justify'
}

module.exports = AlignContent
Loading

0 comments on commit 66d23f6

Please sign in to comment.