diff options
Diffstat (limited to 'node_modules/autoprefixer/lib/hacks')
59 files changed, 3782 insertions, 0 deletions
diff --git a/node_modules/autoprefixer/lib/hacks/align-content.js b/node_modules/autoprefixer/lib/hacks/align-content.js new file mode 100644 index 0000000..a06f381 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/align-content.js @@ -0,0 +1,49 @@ +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 + */ + prefixed(prop, prefix) { + let spec + ;[spec, prefix] = flexSpec(prefix) + if (spec === 2012) { + return prefix + 'flex-line-pack' + } + return super.prefixed(prop, prefix) + } + + /** + * Change value for 2012 spec and ignore prefix for 2009 + */ + set(decl, prefix) { + let spec = flexSpec(prefix)[0] + if (spec === 2012) { + decl.value = AlignContent.oldValues[decl.value] || decl.value + return super.set(decl, prefix) + } + if (spec === 'final') { + return super.set(decl, prefix) + } + return undefined + } +} + +AlignContent.names = ['align-content', 'flex-line-pack'] + +AlignContent.oldValues = { + 'flex-end': 'end', + 'flex-start': 'start', + 'space-around': 'distribute', + 'space-between': 'justify' +} + +module.exports = AlignContent diff --git a/node_modules/autoprefixer/lib/hacks/align-items.js b/node_modules/autoprefixer/lib/hacks/align-items.js new file mode 100644 index 0000000..4dfdd45 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/align-items.js @@ -0,0 +1,46 @@ +let flexSpec = require('./flex-spec') +let Declaration = require('../declaration') + +class AlignItems extends Declaration { + /** + * Return property name by final spec + */ + normalize() { + return 'align-items' + } + + /** + * Change property name for 2009 and 2012 specs + */ + prefixed(prop, prefix) { + let spec + ;[spec, prefix] = flexSpec(prefix) + if (spec === 2009) { + return prefix + 'box-align' + } + if (spec === 2012) { + return prefix + 'flex-align' + } + return super.prefixed(prop, prefix) + } + + /** + * Change value for 2009 and 2012 specs + */ + set(decl, prefix) { + let spec = flexSpec(prefix)[0] + if (spec === 2009 || spec === 2012) { + decl.value = AlignItems.oldValues[decl.value] || decl.value + } + return super.set(decl, prefix) + } +} + +AlignItems.names = ['align-items', 'flex-align', 'box-align'] + +AlignItems.oldValues = { + 'flex-end': 'end', + 'flex-start': 'start' +} + +module.exports = AlignItems diff --git a/node_modules/autoprefixer/lib/hacks/align-self.js b/node_modules/autoprefixer/lib/hacks/align-self.js new file mode 100644 index 0000000..a22b166 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/align-self.js @@ -0,0 +1,56 @@ +let flexSpec = require('./flex-spec') +let Declaration = require('../declaration') + +class AlignSelf extends Declaration { + check(decl) { + return ( + decl.parent && + !decl.parent.some(i => { + return i.prop && i.prop.startsWith('grid-') + }) + ) + } + + /** + * Return property name by final spec + */ + normalize() { + return 'align-self' + } + + /** + * Change property name for 2012 specs + */ + prefixed(prop, prefix) { + let spec + ;[spec, prefix] = flexSpec(prefix) + if (spec === 2012) { + return prefix + 'flex-item-align' + } + return super.prefixed(prop, prefix) + } + + /** + * Change value for 2012 spec and ignore prefix for 2009 + */ + set(decl, prefix) { + let spec = flexSpec(prefix)[0] + if (spec === 2012) { + decl.value = AlignSelf.oldValues[decl.value] || decl.value + return super.set(decl, prefix) + } + if (spec === 'final') { + return super.set(decl, prefix) + } + return undefined + } +} + +AlignSelf.names = ['align-self', 'flex-item-align'] + +AlignSelf.oldValues = { + 'flex-end': 'end', + 'flex-start': 'start' +} + +module.exports = AlignSelf diff --git a/node_modules/autoprefixer/lib/hacks/animation.js b/node_modules/autoprefixer/lib/hacks/animation.js new file mode 100644 index 0000000..7ce949a --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/animation.js @@ -0,0 +1,17 @@ +let Declaration = require('../declaration') + +class Animation extends Declaration { + /** + * Don’t add prefixes for modern values. + */ + check(decl) { + return !decl.value.split(/\s+/).some(i => { + let lower = i.toLowerCase() + return lower === 'reverse' || lower === 'alternate-reverse' + }) + } +} + +Animation.names = ['animation', 'animation-direction'] + +module.exports = Animation diff --git a/node_modules/autoprefixer/lib/hacks/appearance.js b/node_modules/autoprefixer/lib/hacks/appearance.js new file mode 100644 index 0000000..34be384 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/appearance.js @@ -0,0 +1,23 @@ +let Declaration = require('../declaration') +let utils = require('../utils') + +class Appearance extends Declaration { + constructor(name, prefixes, all) { + super(name, prefixes, all) + + if (this.prefixes) { + this.prefixes = utils.uniq( + this.prefixes.map(i => { + if (i === '-ms-') { + return '-webkit-' + } + return i + }) + ) + } + } +} + +Appearance.names = ['appearance'] + +module.exports = Appearance diff --git a/node_modules/autoprefixer/lib/hacks/autofill.js b/node_modules/autoprefixer/lib/hacks/autofill.js new file mode 100644 index 0000000..a9c49ce --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/autofill.js @@ -0,0 +1,26 @@ +let Selector = require('../selector') +let utils = require('../utils') + +class Autofill extends Selector { + constructor(name, prefixes, all) { + super(name, prefixes, all) + + if (this.prefixes) { + this.prefixes = utils.uniq(this.prefixes.map(() => '-webkit-')) + } + } + + /** + * Return different selectors depend on prefix + */ + prefixed(prefix) { + if (prefix === '-webkit-') { + return ':-webkit-autofill' + } + return `:${prefix}autofill` + } +} + +Autofill.names = [':autofill'] + +module.exports = Autofill diff --git a/node_modules/autoprefixer/lib/hacks/backdrop-filter.js b/node_modules/autoprefixer/lib/hacks/backdrop-filter.js new file mode 100644 index 0000000..f9b4b05 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/backdrop-filter.js @@ -0,0 +1,20 @@ +let Declaration = require('../declaration') +let utils = require('../utils') + +class BackdropFilter extends Declaration { + constructor(name, prefixes, all) { + super(name, prefixes, all) + + if (this.prefixes) { + this.prefixes = utils.uniq( + this.prefixes.map(i => { + return i === '-ms-' ? '-webkit-' : i + }) + ) + } + } +} + +BackdropFilter.names = ['backdrop-filter'] + +module.exports = BackdropFilter diff --git a/node_modules/autoprefixer/lib/hacks/background-clip.js b/node_modules/autoprefixer/lib/hacks/background-clip.js new file mode 100644 index 0000000..92c714c --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/background-clip.js @@ -0,0 +1,24 @@ +let Declaration = require('../declaration') +let utils = require('../utils') + +class BackgroundClip extends Declaration { + constructor(name, prefixes, all) { + super(name, prefixes, all) + + if (this.prefixes) { + this.prefixes = utils.uniq( + this.prefixes.map(i => { + return i === '-ms-' ? '-webkit-' : i + }) + ) + } + } + + check(decl) { + return decl.value.toLowerCase() === 'text' + } +} + +BackgroundClip.names = ['background-clip'] + +module.exports = BackgroundClip diff --git a/node_modules/autoprefixer/lib/hacks/background-size.js b/node_modules/autoprefixer/lib/hacks/background-size.js new file mode 100644 index 0000000..1fba894 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/background-size.js @@ -0,0 +1,23 @@ +let Declaration = require('../declaration') + +class BackgroundSize extends Declaration { + /** + * Duplication parameter for -webkit- browsers + */ + set(decl, prefix) { + let value = decl.value.toLowerCase() + if ( + prefix === '-webkit-' && + !value.includes(' ') && + value !== 'contain' && + value !== 'cover' + ) { + decl.value = decl.value + ' ' + decl.value + } + return super.set(decl, prefix) + } +} + +BackgroundSize.names = ['background-size'] + +module.exports = BackgroundSize diff --git a/node_modules/autoprefixer/lib/hacks/block-logical.js b/node_modules/autoprefixer/lib/hacks/block-logical.js new file mode 100644 index 0000000..cb795f7 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/block-logical.js @@ -0,0 +1,40 @@ +let Declaration = require('../declaration') + +class BlockLogical extends Declaration { + /** + * Return property name by spec + */ + normalize(prop) { + if (prop.includes('-before')) { + return prop.replace('-before', '-block-start') + } + return prop.replace('-after', '-block-end') + } + + /** + * Use old syntax for -moz- and -webkit- + */ + prefixed(prop, prefix) { + if (prop.includes('-start')) { + return prefix + prop.replace('-block-start', '-before') + } + return prefix + prop.replace('-block-end', '-after') + } +} + +BlockLogical.names = [ + 'border-block-start', + 'border-block-end', + 'margin-block-start', + 'margin-block-end', + 'padding-block-start', + 'padding-block-end', + 'border-before', + 'border-after', + 'margin-before', + 'margin-after', + 'padding-before', + 'padding-after' +] + +module.exports = BlockLogical diff --git a/node_modules/autoprefixer/lib/hacks/border-image.js b/node_modules/autoprefixer/lib/hacks/border-image.js new file mode 100644 index 0000000..f5cbd2c --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/border-image.js @@ -0,0 +1,15 @@ +let Declaration = require('../declaration') + +class BorderImage extends Declaration { + /** + * Remove fill parameter for prefixed declarations + */ + set(decl, prefix) { + decl.value = decl.value.replace(/\s+fill(\s)/, '$1') + return super.set(decl, prefix) + } +} + +BorderImage.names = ['border-image'] + +module.exports = BorderImage diff --git a/node_modules/autoprefixer/lib/hacks/border-radius.js b/node_modules/autoprefixer/lib/hacks/border-radius.js new file mode 100644 index 0000000..47ea835 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/border-radius.js @@ -0,0 +1,40 @@ +let Declaration = require('../declaration') + +class BorderRadius extends Declaration { + /** + * Return unprefixed version of property + */ + normalize(prop) { + return BorderRadius.toNormal[prop] || prop + } + + /** + * Change syntax, when add Mozilla prefix + */ + prefixed(prop, prefix) { + if (prefix === '-moz-') { + return prefix + (BorderRadius.toMozilla[prop] || prop) + } + return super.prefixed(prop, prefix) + } +} + +BorderRadius.names = ['border-radius'] + +BorderRadius.toMozilla = {} +BorderRadius.toNormal = {} + +for (let ver of ['top', 'bottom']) { + for (let hor of ['left', 'right']) { + let normal = `border-${ver}-${hor}-radius` + let mozilla = `border-radius-${ver}${hor}` + + BorderRadius.names.push(normal) + BorderRadius.names.push(mozilla) + + BorderRadius.toMozilla[normal] = mozilla + BorderRadius.toNormal[mozilla] = normal + } +} + +module.exports = BorderRadius diff --git a/node_modules/autoprefixer/lib/hacks/break-props.js b/node_modules/autoprefixer/lib/hacks/break-props.js new file mode 100644 index 0000000..b67b12f --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/break-props.js @@ -0,0 +1,63 @@ +let Declaration = require('../declaration') + +class BreakProps extends Declaration { + /** + * Don’t prefix some values + */ + insert(decl, prefix, prefixes) { + if (decl.prop !== 'break-inside') { + return super.insert(decl, prefix, prefixes) + } + if (/region/i.test(decl.value) || /page/i.test(decl.value)) { + return undefined + } + return super.insert(decl, prefix, prefixes) + } + + /** + * Return property name by final spec + */ + normalize(prop) { + if (prop.includes('inside')) { + return 'break-inside' + } + if (prop.includes('before')) { + return 'break-before' + } + return 'break-after' + } + + /** + * Change name for -webkit- and -moz- prefix + */ + prefixed(prop, prefix) { + return `${prefix}column-${prop}` + } + + /** + * Change prefixed value for avoid-column and avoid-page + */ + set(decl, prefix) { + if ( + (decl.prop === 'break-inside' && decl.value === 'avoid-column') || + decl.value === 'avoid-page' + ) { + decl.value = 'avoid' + } + return super.set(decl, prefix) + } +} + +BreakProps.names = [ + 'break-inside', + 'page-break-inside', + 'column-break-inside', + 'break-before', + 'page-break-before', + 'column-break-before', + 'break-after', + 'page-break-after', + 'column-break-after' +] + +module.exports = BreakProps diff --git a/node_modules/autoprefixer/lib/hacks/cross-fade.js b/node_modules/autoprefixer/lib/hacks/cross-fade.js new file mode 100644 index 0000000..caaa90d --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/cross-fade.js @@ -0,0 +1,35 @@ +let list = require('postcss').list + +let Value = require('../value') + +class CrossFade extends Value { + replace(string, prefix) { + return list + .space(string) + .map(value => { + if (value.slice(0, +this.name.length + 1) !== this.name + '(') { + return value + } + + let close = value.lastIndexOf(')') + let after = value.slice(close + 1) + let args = value.slice(this.name.length + 1, close) + + if (prefix === '-webkit-') { + let match = args.match(/\d*.?\d+%?/) + if (match) { + args = args.slice(match[0].length).trim() + args += `, ${match[0]}` + } else { + args += ', 0.5' + } + } + return prefix + this.name + '(' + args + ')' + after + }) + .join(' ') + } +} + +CrossFade.names = ['cross-fade'] + +module.exports = CrossFade diff --git a/node_modules/autoprefixer/lib/hacks/display-flex.js b/node_modules/autoprefixer/lib/hacks/display-flex.js new file mode 100644 index 0000000..8a5473e --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/display-flex.js @@ -0,0 +1,65 @@ +let flexSpec = require('./flex-spec') +let OldValue = require('../old-value') +let Value = require('../value') + +class DisplayFlex extends Value { + constructor(name, prefixes) { + super(name, prefixes) + if (name === 'display-flex') { + this.name = 'flex' + } + } + + /** + * Faster check for flex value + */ + check(decl) { + return decl.prop === 'display' && decl.value === this.name + } + + /** + * Change value for old specs + */ + old(prefix) { + let prefixed = this.prefixed(prefix) + if (!prefixed) return undefined + return new OldValue(this.name, prefixed) + } + + /** + * Return value by spec + */ + prefixed(prefix) { + let spec, value + ;[spec, prefix] = flexSpec(prefix) + + if (spec === 2009) { + if (this.name === 'flex') { + value = 'box' + } else { + value = 'inline-box' + } + } else if (spec === 2012) { + if (this.name === 'flex') { + value = 'flexbox' + } else { + value = 'inline-flexbox' + } + } else if (spec === 'final') { + value = this.name + } + + return prefix + value + } + + /** + * Add prefix to value depend on flebox spec version + */ + replace(string, prefix) { + return this.prefixed(prefix) + } +} + +DisplayFlex.names = ['display-flex', 'inline-flex'] + +module.exports = DisplayFlex diff --git a/node_modules/autoprefixer/lib/hacks/display-grid.js b/node_modules/autoprefixer/lib/hacks/display-grid.js new file mode 100644 index 0000000..290ec8b --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/display-grid.js @@ -0,0 +1,21 @@ +let Value = require('../value') + +class DisplayGrid extends Value { + constructor(name, prefixes) { + super(name, prefixes) + if (name === 'display-grid') { + this.name = 'grid' + } + } + + /** + * Faster check for flex value + */ + check(decl) { + return decl.prop === 'display' && decl.value === this.name + } +} + +DisplayGrid.names = ['display-grid', 'inline-grid'] + +module.exports = DisplayGrid diff --git a/node_modules/autoprefixer/lib/hacks/file-selector-button.js b/node_modules/autoprefixer/lib/hacks/file-selector-button.js new file mode 100644 index 0000000..18ebcea --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/file-selector-button.js @@ -0,0 +1,26 @@ +let Selector = require('../selector') +let utils = require('../utils') + +class FileSelectorButton extends Selector { + constructor(name, prefixes, all) { + super(name, prefixes, all) + + if (this.prefixes) { + this.prefixes = utils.uniq(this.prefixes.map(() => '-webkit-')) + } + } + + /** + * Return different selectors depend on prefix + */ + prefixed(prefix) { + if (prefix === '-webkit-') { + return '::-webkit-file-upload-button' + } + return `::${prefix}file-selector-button` + } +} + +FileSelectorButton.names = ['::file-selector-button'] + +module.exports = FileSelectorButton diff --git a/node_modules/autoprefixer/lib/hacks/filter-value.js b/node_modules/autoprefixer/lib/hacks/filter-value.js new file mode 100644 index 0000000..98e5f61 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/filter-value.js @@ -0,0 +1,14 @@ +let Value = require('../value') + +class FilterValue extends Value { + constructor(name, prefixes) { + super(name, prefixes) + if (name === 'filter-function') { + this.name = 'filter' + } + } +} + +FilterValue.names = ['filter', 'filter-function'] + +module.exports = FilterValue diff --git a/node_modules/autoprefixer/lib/hacks/filter.js b/node_modules/autoprefixer/lib/hacks/filter.js new file mode 100644 index 0000000..7ec6fbe --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/filter.js @@ -0,0 +1,19 @@ +let Declaration = require('../declaration') + +class Filter extends Declaration { + /** + * Check is it Internet Explorer filter + */ + check(decl) { + let v = decl.value + return ( + !v.toLowerCase().includes('alpha(') && + !v.includes('DXImageTransform.Microsoft') && + !v.includes('data:image/svg+xml') + ) + } +} + +Filter.names = ['filter'] + +module.exports = Filter diff --git a/node_modules/autoprefixer/lib/hacks/flex-basis.js b/node_modules/autoprefixer/lib/hacks/flex-basis.js new file mode 100644 index 0000000..959cf4c --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/flex-basis.js @@ -0,0 +1,39 @@ +let flexSpec = require('./flex-spec') +let Declaration = require('../declaration') + +class FlexBasis extends Declaration { + /** + * Return property name by final spec + */ + normalize() { + return 'flex-basis' + } + + /** + * Return flex property for 2012 spec + */ + prefixed(prop, prefix) { + let spec + ;[spec, prefix] = flexSpec(prefix) + if (spec === 2012) { + return prefix + 'flex-preferred-size' + } + return super.prefixed(prop, prefix) + } + + /** + * Ignore 2009 spec and use flex property for 2012 + */ + set(decl, prefix) { + let spec + ;[spec, prefix] = flexSpec(prefix) + if (spec === 2012 || spec === 'final') { + return super.set(decl, prefix) + } + return undefined + } +} + +FlexBasis.names = ['flex-basis', 'flex-preferred-size'] + +module.exports = FlexBasis diff --git a/node_modules/autoprefixer/lib/hacks/flex-direction.js b/node_modules/autoprefixer/lib/hacks/flex-direction.js new file mode 100644 index 0000000..83fe6a9 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/flex-direction.js @@ -0,0 +1,72 @@ +let flexSpec = require('./flex-spec') +let Declaration = require('../declaration') + +class FlexDirection extends Declaration { + /** + * Use two properties for 2009 spec + */ + insert(decl, prefix, prefixes) { + let spec + ;[spec, prefix] = flexSpec(prefix) + if (spec !== 2009) { + return super.insert(decl, prefix, prefixes) + } + let already = decl.parent.some( + i => + i.prop === prefix + 'box-orient' || i.prop === prefix + 'box-direction' + ) + if (already) { + return undefined + } + + let v = decl.value + let orient, dir + if (v === 'inherit' || v === 'initial' || v === 'unset') { + orient = v + dir = v + } else { + orient = v.includes('row') ? 'horizontal' : 'vertical' + dir = v.includes('reverse') ? 'reverse' : 'normal' + } + + let cloned = this.clone(decl) + cloned.prop = prefix + 'box-orient' + cloned.value = orient + if (this.needCascade(decl)) { + cloned.raws.before = this.calcBefore(prefixes, decl, prefix) + } + decl.parent.insertBefore(decl, cloned) + + cloned = this.clone(decl) + cloned.prop = prefix + 'box-direction' + cloned.value = dir + if (this.needCascade(decl)) { + cloned.raws.before = this.calcBefore(prefixes, decl, prefix) + } + return decl.parent.insertBefore(decl, cloned) + } + + /** + * Return property name by final spec + */ + normalize() { + return 'flex-direction' + } + + /** + * Clean two properties for 2009 spec + */ + old(prop, prefix) { + let spec + ;[spec, prefix] = flexSpec(prefix) + if (spec === 2009) { + return [prefix + 'box-orient', prefix + 'box-direction'] + } else { + return super.old(prop, prefix) + } + } +} + +FlexDirection.names = ['flex-direction', 'box-direction', 'box-orient'] + +module.exports = FlexDirection diff --git a/node_modules/autoprefixer/lib/hacks/flex-flow.js b/node_modules/autoprefixer/lib/hacks/flex-flow.js new file mode 100644 index 0000000..0223bd8 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/flex-flow.js @@ -0,0 +1,53 @@ +let flexSpec = require('./flex-spec') +let Declaration = require('../declaration') + +class FlexFlow extends Declaration { + /** + * Use two properties for 2009 spec + */ + insert(decl, prefix, prefixes) { + let spec + ;[spec, prefix] = flexSpec(prefix) + if (spec !== 2009) { + return super.insert(decl, prefix, prefixes) + } + let values = decl.value + .split(/\s+/) + .filter(i => i !== 'wrap' && i !== 'nowrap' && 'wrap-reverse') + if (values.length === 0) { + return undefined + } + + let already = decl.parent.some( + i => + i.prop === prefix + 'box-orient' || i.prop === prefix + 'box-direction' + ) + if (already) { + return undefined + } + + let value = values[0] + let orient = value.includes('row') ? 'horizontal' : 'vertical' + let dir = value.includes('reverse') ? 'reverse' : 'normal' + + let cloned = this.clone(decl) + cloned.prop = prefix + 'box-orient' + cloned.value = orient + if (this.needCascade(decl)) { + cloned.raws.before = this.calcBefore(prefixes, decl, prefix) + } + decl.parent.insertBefore(decl, cloned) + + cloned = this.clone(decl) + cloned.prop = prefix + 'box-direction' + cloned.value = dir + if (this.needCascade(decl)) { + cloned.raws.before = this.calcBefore(prefixes, decl, prefix) + } + return decl.parent.insertBefore(decl, cloned) + } +} + +FlexFlow.names = ['flex-flow', 'box-direction', 'box-orient'] + +module.exports = FlexFlow diff --git a/node_modules/autoprefixer/lib/hacks/flex-grow.js b/node_modules/autoprefixer/lib/hacks/flex-grow.js new file mode 100644 index 0000000..d53374b --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/flex-grow.js @@ -0,0 +1,30 @@ +let flexSpec = require('./flex-spec') +let Declaration = require('../declaration') + +class Flex extends Declaration { + /** + * Return property name by final spec + */ + normalize() { + return 'flex' + } + + /** + * Return flex property for 2009 and 2012 specs + */ + prefixed(prop, prefix) { + let spec + ;[spec, prefix] = flexSpec(prefix) + if (spec === 2009) { + return prefix + 'box-flex' + } + if (spec === 2012) { + return prefix + 'flex-positive' + } + return super.prefixed(prop, prefix) + } +} + +Flex.names = ['flex-grow', 'flex-positive'] + +module.exports = Flex diff --git a/node_modules/autoprefixer/lib/hacks/flex-shrink.js b/node_modules/autoprefixer/lib/hacks/flex-shrink.js new file mode 100644 index 0000000..fbd0e82 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/flex-shrink.js @@ -0,0 +1,39 @@ +let flexSpec = require('./flex-spec') +let Declaration = require('../declaration') + +class FlexShrink extends Declaration { + /** + * Return property name by final spec + */ + normalize() { + return 'flex-shrink' + } + + /** + * Return flex property for 2012 spec + */ + prefixed(prop, prefix) { + let spec + ;[spec, prefix] = flexSpec(prefix) + if (spec === 2012) { + return prefix + 'flex-negative' + } + return super.prefixed(prop, prefix) + } + + /** + * Ignore 2009 spec and use flex property for 2012 + */ + set(decl, prefix) { + let spec + ;[spec, prefix] = flexSpec(prefix) + if (spec === 2012 || spec === 'final') { + return super.set(decl, prefix) + } + return undefined + } +} + +FlexShrink.names = ['flex-shrink', 'flex-negative'] + +module.exports = FlexShrink diff --git a/node_modules/autoprefixer/lib/hacks/flex-spec.js b/node_modules/autoprefixer/lib/hacks/flex-spec.js new file mode 100644 index 0000000..a077d66 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/flex-spec.js @@ -0,0 +1,19 @@ +/** + * Return flexbox spec versions by prefix + */ +module.exports = function (prefix) { + let spec + if (prefix === '-webkit- 2009' || prefix === '-moz-') { + spec = 2009 + } else if (prefix === '-ms-') { + spec = 2012 + } else if (prefix === '-webkit-') { + spec = 'final' + } + + if (prefix === '-webkit- 2009') { + prefix = '-webkit-' + } + + return [spec, prefix] +} diff --git a/node_modules/autoprefixer/lib/hacks/flex-wrap.js b/node_modules/autoprefixer/lib/hacks/flex-wrap.js new file mode 100644 index 0000000..8570476 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/flex-wrap.js @@ -0,0 +1,19 @@ +let flexSpec = require('./flex-spec') +let Declaration = require('../declaration') + +class FlexWrap extends Declaration { + /** + * Don't add prefix for 2009 spec + */ + set(decl, prefix) { + let spec = flexSpec(prefix)[0] + if (spec !== 2009) { + return super.set(decl, prefix) + } + return undefined + } +} + +FlexWrap.names = ['flex-wrap'] + +module.exports = FlexWrap diff --git a/node_modules/autoprefixer/lib/hacks/flex.js b/node_modules/autoprefixer/lib/hacks/flex.js new file mode 100644 index 0000000..e3b2fef --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/flex.js @@ -0,0 +1,54 @@ +let list = require('postcss').list + +let flexSpec = require('./flex-spec') +let Declaration = require('../declaration') + +class Flex extends Declaration { + /** + * Return property name by final spec + */ + normalize() { + return 'flex' + } + + /** + * Change property name for 2009 spec + */ + prefixed(prop, prefix) { + let spec + ;[spec, prefix] = flexSpec(prefix) + if (spec === 2009) { + return prefix + 'box-flex' + } + return super.prefixed(prop, prefix) + } + + /** + * Spec 2009 supports only first argument + * Spec 2012 disallows unitless basis + */ + set(decl, prefix) { + let spec = flexSpec(prefix)[0] + if (spec === 2009) { + decl.value = list.space(decl.value)[0] + decl.value = Flex.oldValues[decl.value] || decl.value + return super.set(decl, prefix) + } + if (spec === 2012) { + let components = list.space(decl.value) + if (components.length === 3 && components[2] === '0') { + decl.value = components.slice(0, 2).concat('0px').join(' ') + } + } + return super.set(decl, prefix) + } +} + +Flex.names = ['flex', 'box-flex'] + +Flex.oldValues = { + auto: '1', + none: '0' +} + +module.exports = Flex diff --git a/node_modules/autoprefixer/lib/hacks/fullscreen.js b/node_modules/autoprefixer/lib/hacks/fullscreen.js new file mode 100644 index 0000000..5a74390 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/fullscreen.js @@ -0,0 +1,20 @@ +let Selector = require('../selector') + +class Fullscreen extends Selector { + /** + * Return different selectors depend on prefix + */ + prefixed(prefix) { + if (prefix === '-webkit-') { + return ':-webkit-full-screen' + } + if (prefix === '-moz-') { + return ':-moz-full-screen' + } + return `:${prefix}fullscreen` + } +} + +Fullscreen.names = [':fullscreen'] + +module.exports = Fullscreen diff --git a/node_modules/autoprefixer/lib/hacks/gradient.js b/node_modules/autoprefixer/lib/hacks/gradient.js new file mode 100644 index 0000000..f2345b0 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/gradient.js @@ -0,0 +1,448 @@ +let parser = require('postcss-value-parser') +let range = require('normalize-range') + +let OldValue = require('../old-value') +let Value = require('../value') +let utils = require('../utils') + +let IS_DIRECTION = /top|left|right|bottom/gi + +class Gradient extends Value { + /** + * Do not add non-webkit prefixes for list-style and object + */ + add(decl, prefix) { + let p = decl.prop + if (p.includes('mask')) { + if (prefix === '-webkit-' || prefix === '-webkit- old') { + return super.add(decl, prefix) + } + } else if ( + p === 'list-style' || + p === 'list-style-image' || + p === 'content' + ) { + if (prefix === '-webkit-' || prefix === '-webkit- old') { + return super.add(decl, prefix) + } + } else { + return super.add(decl, prefix) + } + return undefined + } + + /** + * Get div token from exists parameters + */ + cloneDiv(params) { + for (let i of params) { + if (i.type === 'div' && i.value === ',') { + return i + } + } + return { after: ' ', type: 'div', value: ',' } + } + + /** + * Change colors syntax to old webkit + */ + colorStops(params) { + let result = [] + for (let i = 0; i < params.length; i++) { + let pos + let param = params[i] + let item + if (i === 0) { + continue + } + + let color = parser.stringify(param[0]) + if (param[1] && param[1].type === 'word') { + pos = param[1].value + } else if (param[2] && param[2].type === 'word') { + pos = param[2].value + } + + let stop + if (i === 1 && (!pos || pos === '0%')) { + stop = `from(${color})` + } else if (i === params.length - 1 && (!pos || pos === '100%')) { + stop = `to(${color})` + } else if (pos) { + stop = `color-stop(${pos}, ${color})` + } else { + stop = `color-stop(${color})` + } + + let div = param[param.length - 1] + params[i] = [{ type: 'word', value: stop }] + if (div.type === 'div' && div.value === ',') { + item = params[i].push(div) + } + result.push(item) + } + return result + } + + /** + * Change new direction to old + */ + convertDirection(params) { + if (params.length > 0) { + if (params[0].value === 'to') { + this.fixDirection(params) + } else if (params[0].value.includes('deg')) { + this.fixAngle(params) + } else if (this.isRadial(params)) { + this.fixRadial(params) + } + } + return params + } + + /** + * Add 90 degrees + */ + fixAngle(params) { + let first = params[0].value + first = parseFloat(first) + first = Math.abs(450 - first) % 360 + first = this.roundFloat(first, 3) + params[0].value = `${first}deg` + } + + /** + * Replace `to top left` to `bottom right` + */ + fixDirection(params) { + params.splice(0, 2) + + for (let param of params) { + if (param.type === 'div') { + break + } + if (param.type === 'word') { + param.value = this.revertDirection(param.value) + } + } + } + + /** + * Fix radial direction syntax + */ + fixRadial(params) { + let first = [] + let second = [] + let a, b, c, i, next + + for (i = 0; i < params.length - 2; i++) { + a = params[i] + b = params[i + 1] + c = params[i + 2] + if (a.type === 'space' && b.value === 'at' && c.type === 'space') { + next = i + 3 + break + } else { + first.push(a) + } + } + + let div + for (i = next; i < params.length; i++) { + if (params[i].type === 'div') { + div = params[i] + break + } else { + second.push(params[i]) + } + } + + params.splice(0, i, ...second, div, ...first) + } + + /** + * Look for at word + */ + isRadial(params) { + let state = 'before' + for (let param of params) { + if (state === 'before' && param.type === 'space') { + state = 'at' + } else if (state === 'at' && param.value === 'at') { + state = 'after' + } else if (state === 'after' && param.type === 'space') { + return true + } else if (param.type === 'div') { + break + } else { + state = 'before' + } + } + return false + } + + /** + * Replace old direction to new + */ + newDirection(params) { + if (params[0].value === 'to') { + return params + } + IS_DIRECTION.lastIndex = 0 // reset search index of global regexp + if (!IS_DIRECTION.test(params[0].value)) { + return params + } + + params.unshift( + { + type: 'word', + value: 'to' + }, + { + type: 'space', + value: ' ' + } + ) + + for (let i = 2; i < params.length; i++) { + if (params[i].type === 'div') { + break + } + if (params[i].type === 'word') { + params[i].value = this.revertDirection(params[i].value) + } + } + + return params + } + + /** + * Normalize angle + */ + normalize(nodes, gradientName) { + if (!nodes[0]) return nodes + + if (/-?\d+(.\d+)?grad/.test(nodes[0].value)) { + nodes[0].value = this.normalizeUnit(nodes[0].value, 400) + } else if (/-?\d+(.\d+)?rad/.test(nodes[0].value)) { + nodes[0].value = this.normalizeUnit(nodes[0].value, 2 * Math.PI) + } else if (/-?\d+(.\d+)?turn/.test(nodes[0].value)) { + nodes[0].value = this.normalizeUnit(nodes[0].value, 1) + } else if (nodes[0].value.includes('deg')) { + let num = parseFloat(nodes[0].value) + num = range.wrap(0, 360, num) + nodes[0].value = `${num}deg` + } + + if ( + gradientName === 'linear-gradient' || + gradientName === 'repeating-linear-gradient' + ) { + let direction = nodes[0].value + + // Unitless zero for `<angle>` values are allowed in CSS gradients and transforms. + // Spec: https://github.com/w3c/csswg-drafts/commit/602789171429b2231223ab1e5acf8f7f11652eb3 + if (direction === '0deg' || direction === '0') { + nodes = this.replaceFirst(nodes, 'to', ' ', 'top') + } else if (direction === '90deg') { + nodes = this.replaceFirst(nodes, 'to', ' ', 'right') + } else if (direction === '180deg') { + nodes = this.replaceFirst(nodes, 'to', ' ', 'bottom') // default value + } else if (direction === '270deg') { + nodes = this.replaceFirst(nodes, 'to', ' ', 'left') + } + } + + return nodes + } + + /** + * Convert angle unit to deg + */ + normalizeUnit(str, full) { + let num = parseFloat(str) + let deg = (num / full) * 360 + return `${deg}deg` + } + + /** + * Remove old WebKit gradient too + */ + old(prefix) { + if (prefix === '-webkit-') { + let type + if (this.name === 'linear-gradient') { + type = 'linear' + } else if (this.name === 'repeating-linear-gradient') { + type = 'repeating-linear' + } else if (this.name === 'repeating-radial-gradient') { + type = 'repeating-radial' + } else { + type = 'radial' + } + let string = '-gradient' + let regexp = utils.regexp( + `-webkit-(${type}-gradient|gradient\\(\\s*${type})`, + false + ) + + return new OldValue(this.name, prefix + this.name, string, regexp) + } else { + return super.old(prefix) + } + } + + /** + * Change direction syntax to old webkit + */ + oldDirection(params) { + let div = this.cloneDiv(params[0]) + + if (params[0][0].value !== 'to') { + return params.unshift([ + { type: 'word', value: Gradient.oldDirections.bottom }, + div + ]) + } else { + let words = [] + for (let node of params[0].slice(2)) { + if (node.type === 'word') { + words.push(node.value.toLowerCase()) + } + } + + words = words.join(' ') + let old = Gradient.oldDirections[words] || words + + params[0] = [{ type: 'word', value: old }, div] + return params[0] + } + } + + /** + * Convert to old webkit syntax + */ + oldWebkit(node) { + let { nodes } = node + let string = parser.stringify(node.nodes) + + if (this.name !== 'linear-gradient') { + return false + } + if (nodes[0] && nodes[0].value.includes('deg')) { + return false + } + if ( + string.includes('px') || + string.includes('-corner') || + string.includes('-side') + ) { + return false + } + + let params = [[]] + for (let i of nodes) { + params[params.length - 1].push(i) + if (i.type === 'div' && i.value === ',') { + params.push([]) + } + } + + this.oldDirection(params) + this.colorStops(params) + + node.nodes = [] + for (let param of params) { + node.nodes = node.nodes.concat(param) + } + + node.nodes.unshift( + { type: 'word', value: 'linear' }, + this.cloneDiv(node.nodes) + ) + node.value = '-webkit-gradient' + + return true + } + + /** + * Change degrees for webkit prefix + */ + replace(string, prefix) { + let ast = parser(string) + for (let node of ast.nodes) { + let gradientName = this.name // gradient name + if (node.type === 'function' && node.value === gradientName) { + node.nodes = this.newDirection(node.nodes) + node.nodes = this.normalize(node.nodes, gradientName) + if (prefix === '-webkit- old') { + let changes = this.oldWebkit(node) + if (!changes) { + return false + } + } else { + node.nodes = this.convertDirection(node.nodes) + node.value = prefix + node.value + } + } + } + return ast.toString() + } + + /** + * Replace first token + */ + replaceFirst(params, ...words) { + let prefix = words.map(i => { + if (i === ' ') { + return { type: 'space', value: i } + } + return { type: 'word', value: i } + }) + return prefix.concat(params.slice(1)) + } + + revertDirection(word) { + return Gradient.directions[word.toLowerCase()] || word + } + + /** + * Round float and save digits under dot + */ + roundFloat(float, digits) { + return parseFloat(float.toFixed(digits)) + } +} + +Gradient.names = [ + 'linear-gradient', + 'repeating-linear-gradient', + 'radial-gradient', + 'repeating-radial-gradient' +] + +Gradient.directions = { + bottom: 'top', + left: 'right', + right: 'left', + top: 'bottom' // default value +} + +// Direction to replace +Gradient.oldDirections = { + 'bottom': 'left top, left bottom', + 'bottom left': 'right top, left bottom', + 'bottom right': 'left top, right bottom', + 'left': 'right top, left top', + + 'left bottom': 'right top, left bottom', + 'left top': 'right bottom, left top', + 'right': 'left top, right top', + 'right bottom': 'left top, right bottom', + 'right top': 'left bottom, right top', + 'top': 'left bottom, left top', + 'top left': 'right bottom, left top', + 'top right': 'left bottom, right top' +} + +module.exports = Gradient diff --git a/node_modules/autoprefixer/lib/hacks/grid-area.js b/node_modules/autoprefixer/lib/hacks/grid-area.js new file mode 100644 index 0000000..0a2d86c --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/grid-area.js @@ -0,0 +1,34 @@ +let Declaration = require('../declaration') +let utils = require('./grid-utils') + +class GridArea extends Declaration { + /** + * Translate grid-area to separate -ms- prefixed properties + */ + insert(decl, prefix, prefixes, result) { + if (prefix !== '-ms-') return super.insert(decl, prefix, prefixes) + + let values = utils.parse(decl) + + let [rowStart, rowSpan] = utils.translate(values, 0, 2) + let [columnStart, columnSpan] = utils.translate(values, 1, 3) + + ;[ + ['grid-row', rowStart], + ['grid-row-span', rowSpan], + ['grid-column', columnStart], + ['grid-column-span', columnSpan] + ].forEach(([prop, value]) => { + utils.insertDecl(decl, prop, value) + }) + + utils.warnTemplateSelectorNotFound(decl, result) + utils.warnIfGridRowColumnExists(decl, result) + + return undefined + } +} + +GridArea.names = ['grid-area'] + +module.exports = GridArea diff --git a/node_modules/autoprefixer/lib/hacks/grid-column-align.js b/node_modules/autoprefixer/lib/hacks/grid-column-align.js new file mode 100644 index 0000000..91f10f0 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/grid-column-align.js @@ -0,0 +1,28 @@ +let Declaration = require('../declaration') + +class GridColumnAlign extends Declaration { + /** + * Do not prefix flexbox values + */ + check(decl) { + return !decl.value.includes('flex-') && decl.value !== 'baseline' + } + + /** + * Change IE property back + */ + normalize() { + return 'justify-self' + } + + /** + * Change property name for IE + */ + prefixed(prop, prefix) { + return prefix + 'grid-column-align' + } +} + +GridColumnAlign.names = ['grid-column-align'] + +module.exports = GridColumnAlign diff --git a/node_modules/autoprefixer/lib/hacks/grid-end.js b/node_modules/autoprefixer/lib/hacks/grid-end.js new file mode 100644 index 0000000..63f6a42 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/grid-end.js @@ -0,0 +1,52 @@ +let Declaration = require('../declaration') +let { isPureNumber } = require('../utils') + +class GridEnd extends Declaration { + /** + * Change repeating syntax for IE + */ + insert(decl, prefix, prefixes, result) { + if (prefix !== '-ms-') return super.insert(decl, prefix, prefixes) + + let clonedDecl = this.clone(decl) + + let startProp = decl.prop.replace(/end$/, 'start') + let spanProp = prefix + decl.prop.replace(/end$/, 'span') + + if (decl.parent.some(i => i.prop === spanProp)) { + return undefined + } + + clonedDecl.prop = spanProp + + if (decl.value.includes('span')) { + clonedDecl.value = decl.value.replace(/span\s/i, '') + } else { + let startDecl + decl.parent.walkDecls(startProp, d => { + startDecl = d + }) + if (startDecl) { + if (isPureNumber(startDecl.value)) { + let value = Number(decl.value) - Number(startDecl.value) + '' + clonedDecl.value = value + } else { + return undefined + } + } else { + decl.warn( + result, + `Can not prefix ${decl.prop} (${startProp} is not found)` + ) + } + } + + decl.cloneBefore(clonedDecl) + + return undefined + } +} + +GridEnd.names = ['grid-row-end', 'grid-column-end'] + +module.exports = GridEnd diff --git a/node_modules/autoprefixer/lib/hacks/grid-row-align.js b/node_modules/autoprefixer/lib/hacks/grid-row-align.js new file mode 100644 index 0000000..cba8aee --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/grid-row-align.js @@ -0,0 +1,28 @@ +let Declaration = require('../declaration') + +class GridRowAlign extends Declaration { + /** + * Do not prefix flexbox values + */ + check(decl) { + return !decl.value.includes('flex-') && decl.value !== 'baseline' + } + + /** + * Change IE property back + */ + normalize() { + return 'align-self' + } + + /** + * Change property name for IE + */ + prefixed(prop, prefix) { + return prefix + 'grid-row-align' + } +} + +GridRowAlign.names = ['grid-row-align'] + +module.exports = GridRowAlign diff --git a/node_modules/autoprefixer/lib/hacks/grid-row-column.js b/node_modules/autoprefixer/lib/hacks/grid-row-column.js new file mode 100644 index 0000000..2199f78 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/grid-row-column.js @@ -0,0 +1,33 @@ +let Declaration = require('../declaration') +let utils = require('./grid-utils') + +class GridRowColumn extends Declaration { + /** + * Translate grid-row / grid-column to separate -ms- prefixed properties + */ + insert(decl, prefix, prefixes) { + if (prefix !== '-ms-') return super.insert(decl, prefix, prefixes) + + let values = utils.parse(decl) + let [start, span] = utils.translate(values, 0, 1) + + let hasStartValueSpan = values[0] && values[0].includes('span') + + if (hasStartValueSpan) { + span = values[0].join('').replace(/\D/g, '') + } + + ;[ + [decl.prop, start], + [`${decl.prop}-span`, span] + ].forEach(([prop, value]) => { + utils.insertDecl(decl, prop, value) + }) + + return undefined + } +} + +GridRowColumn.names = ['grid-row', 'grid-column'] + +module.exports = GridRowColumn diff --git a/node_modules/autoprefixer/lib/hacks/grid-rows-columns.js b/node_modules/autoprefixer/lib/hacks/grid-rows-columns.js new file mode 100644 index 0000000..dfc266b --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/grid-rows-columns.js @@ -0,0 +1,125 @@ +let Declaration = require('../declaration') +let { + autoplaceGridItems, + getGridGap, + inheritGridGap, + prefixTrackProp, + prefixTrackValue +} = require('./grid-utils') +let Processor = require('../processor') + +class GridRowsColumns extends Declaration { + insert(decl, prefix, prefixes, result) { + if (prefix !== '-ms-') return super.insert(decl, prefix, prefixes) + + let { parent, prop, value } = decl + let isRowProp = prop.includes('rows') + let isColumnProp = prop.includes('columns') + + let hasGridTemplate = parent.some( + i => i.prop === 'grid-template' || i.prop === 'grid-template-areas' + ) + + /** + * Not to prefix rows declaration if grid-template(-areas) is present + */ + if (hasGridTemplate && isRowProp) { + return false + } + + let processor = new Processor({ options: {} }) + let status = processor.gridStatus(parent, result) + let gap = getGridGap(decl) + gap = inheritGridGap(decl, gap) || gap + + let gapValue = isRowProp ? gap.row : gap.column + + if ((status === 'no-autoplace' || status === true) && !hasGridTemplate) { + gapValue = null + } + + let prefixValue = prefixTrackValue({ + gap: gapValue, + value + }) + + /** + * Insert prefixes + */ + decl.cloneBefore({ + prop: prefixTrackProp({ prefix, prop }), + value: prefixValue + }) + + let autoflow = parent.nodes.find(i => i.prop === 'grid-auto-flow') + let autoflowValue = 'row' + + if (autoflow && !processor.disabled(autoflow, result)) { + autoflowValue = autoflow.value.trim() + } + if (status === 'autoplace') { + /** + * Show warning if grid-template-rows decl is not found + */ + let rowDecl = parent.nodes.find(i => i.prop === 'grid-template-rows') + + if (!rowDecl && hasGridTemplate) { + return undefined + } else if (!rowDecl && !hasGridTemplate) { + decl.warn( + result, + 'Autoplacement does not work without grid-template-rows property' + ) + return undefined + } + + /** + * Show warning if grid-template-columns decl is not found + */ + let columnDecl = parent.nodes.find(i => { + return i.prop === 'grid-template-columns' + }) + if (!columnDecl && !hasGridTemplate) { + decl.warn( + result, + 'Autoplacement does not work without grid-template-columns property' + ) + } + + /** + * Autoplace grid items + */ + if (isColumnProp && !hasGridTemplate) { + autoplaceGridItems(decl, result, gap, autoflowValue) + } + } + + return undefined + } + + /** + * Change IE property back + */ + normalize(prop) { + return prop.replace(/^grid-(rows|columns)/, 'grid-template-$1') + } + + /** + * Change property name for IE + */ + prefixed(prop, prefix) { + if (prefix === '-ms-') { + return prefixTrackProp({ prefix, prop }) + } + return super.prefixed(prop, prefix) + } +} + +GridRowsColumns.names = [ + 'grid-template-rows', + 'grid-template-columns', + 'grid-rows', + 'grid-columns' +] + +module.exports = GridRowsColumns diff --git a/node_modules/autoprefixer/lib/hacks/grid-start.js b/node_modules/autoprefixer/lib/hacks/grid-start.js new file mode 100644 index 0000000..32cebc1 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/grid-start.js @@ -0,0 +1,33 @@ +let Declaration = require('../declaration') + +class GridStart extends Declaration { + /** + * Do not add prefix for unsupported value in IE + */ + check(decl) { + let value = decl.value + return !value.includes('/') && !value.includes('span') + } + + /** + * Return a final spec property + */ + normalize(prop) { + return prop.replace('-start', '') + } + + /** + * Change property name for IE + */ + prefixed(prop, prefix) { + let result = super.prefixed(prop, prefix) + if (prefix === '-ms-') { + result = result.replace('-start', '') + } + return result + } +} + +GridStart.names = ['grid-row-start', 'grid-column-start'] + +module.exports = GridStart diff --git a/node_modules/autoprefixer/lib/hacks/grid-template-areas.js b/node_modules/autoprefixer/lib/hacks/grid-template-areas.js new file mode 100644 index 0000000..ffc9673 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/grid-template-areas.js @@ -0,0 +1,84 @@ +let Declaration = require('../declaration') +let { + getGridGap, + inheritGridGap, + parseGridAreas, + prefixTrackProp, + prefixTrackValue, + warnGridGap, + warnMissedAreas +} = require('./grid-utils') + +function getGridRows(tpl) { + return tpl + .trim() + .slice(1, -1) + .split(/["']\s*["']?/g) +} + +class GridTemplateAreas extends Declaration { + /** + * Translate grid-template-areas to separate -ms- prefixed properties + */ + insert(decl, prefix, prefixes, result) { + if (prefix !== '-ms-') return super.insert(decl, prefix, prefixes) + + let hasColumns = false + let hasRows = false + let parent = decl.parent + let gap = getGridGap(decl) + gap = inheritGridGap(decl, gap) || gap + + // remove already prefixed rows + // to prevent doubling prefixes + parent.walkDecls(/-ms-grid-rows/, i => i.remove()) + + // add empty tracks to rows + parent.walkDecls(/grid-template-(rows|columns)/, trackDecl => { + if (trackDecl.prop === 'grid-template-rows') { + hasRows = true + let { prop, value } = trackDecl + trackDecl.cloneBefore({ + prop: prefixTrackProp({ prefix, prop }), + value: prefixTrackValue({ gap: gap.row, value }) + }) + } else { + hasColumns = true + } + }) + + let gridRows = getGridRows(decl.value) + + if (hasColumns && !hasRows && gap.row && gridRows.length > 1) { + decl.cloneBefore({ + prop: '-ms-grid-rows', + raws: {}, + value: prefixTrackValue({ + gap: gap.row, + value: `repeat(${gridRows.length}, auto)` + }) + }) + } + + // warnings + warnGridGap({ + decl, + gap, + hasColumns, + result + }) + + let areas = parseGridAreas({ + gap, + rows: gridRows + }) + + warnMissedAreas(areas, decl, result) + + return decl + } +} + +GridTemplateAreas.names = ['grid-template-areas'] + +module.exports = GridTemplateAreas diff --git a/node_modules/autoprefixer/lib/hacks/grid-template.js b/node_modules/autoprefixer/lib/hacks/grid-template.js new file mode 100644 index 0000000..4e28637 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/grid-template.js @@ -0,0 +1,69 @@ +let Declaration = require('../declaration') +let { + getGridGap, + inheritGridGap, + parseTemplate, + warnGridGap, + warnMissedAreas +} = require('./grid-utils') + +class GridTemplate extends Declaration { + /** + * Translate grid-template to separate -ms- prefixed properties + */ + insert(decl, prefix, prefixes, result) { + if (prefix !== '-ms-') return super.insert(decl, prefix, prefixes) + + if (decl.parent.some(i => i.prop === '-ms-grid-rows')) { + return undefined + } + + let gap = getGridGap(decl) + + /** + * we must insert inherited gap values in some cases: + * if we are inside media query && if we have no grid-gap value + */ + let inheritedGap = inheritGridGap(decl, gap) + + let { areas, columns, rows } = parseTemplate({ + decl, + gap: inheritedGap || gap + }) + + let hasAreas = Object.keys(areas).length > 0 + let hasRows = Boolean(rows) + let hasColumns = Boolean(columns) + + warnGridGap({ + decl, + gap, + hasColumns, + result + }) + + warnMissedAreas(areas, decl, result) + + if ((hasRows && hasColumns) || hasAreas) { + decl.cloneBefore({ + prop: '-ms-grid-rows', + raws: {}, + value: rows + }) + } + + if (hasColumns) { + decl.cloneBefore({ + prop: '-ms-grid-columns', + raws: {}, + value: columns + }) + } + + return decl + } +} + +GridTemplate.names = ['grid-template'] + +module.exports = GridTemplate diff --git a/node_modules/autoprefixer/lib/hacks/grid-utils.js b/node_modules/autoprefixer/lib/hacks/grid-utils.js new file mode 100644 index 0000000..e894231 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/grid-utils.js @@ -0,0 +1,1113 @@ +let parser = require('postcss-value-parser') +let list = require('postcss').list + +let uniq = require('../utils').uniq +let escapeRegexp = require('../utils').escapeRegexp +let splitSelector = require('../utils').splitSelector + +function convert(value) { + if ( + value && + value.length === 2 && + value[0] === 'span' && + parseInt(value[1], 10) > 0 + ) { + return [false, parseInt(value[1], 10)] + } + + if (value && value.length === 1 && parseInt(value[0], 10) > 0) { + return [parseInt(value[0], 10), false] + } + + return [false, false] +} + +exports.translate = translate + +function translate(values, startIndex, endIndex) { + let startValue = values[startIndex] + let endValue = values[endIndex] + + if (!startValue) { + return [false, false] + } + + let [start, spanStart] = convert(startValue) + let [end, spanEnd] = convert(endValue) + + if (start && !endValue) { + return [start, false] + } + + if (spanStart && end) { + return [end - spanStart, spanStart] + } + + if (start && spanEnd) { + return [start, spanEnd] + } + + if (start && end) { + return [start, end - start] + } + + return [false, false] +} + +exports.parse = parse + +function parse(decl) { + let node = parser(decl.value) + + let values = [] + let current = 0 + values[current] = [] + + for (let i of node.nodes) { + if (i.type === 'div') { + current += 1 + values[current] = [] + } else if (i.type === 'word') { + values[current].push(i.value) + } + } + + return values +} + +exports.insertDecl = insertDecl + +function insertDecl(decl, prop, value) { + if (value && !decl.parent.some(i => i.prop === `-ms-${prop}`)) { + decl.cloneBefore({ + prop: `-ms-${prop}`, + value: value.toString() + }) + } +} + +// Track transforms + +exports.prefixTrackProp = prefixTrackProp + +function prefixTrackProp({ prefix, prop }) { + return prefix + prop.replace('template-', '') +} + +function transformRepeat({ nodes }, { gap }) { + let { count, size } = nodes.reduce( + (result, node) => { + if (node.type === 'div' && node.value === ',') { + result.key = 'size' + } else { + result[result.key].push(parser.stringify(node)) + } + return result + }, + { + count: [], + key: 'count', + size: [] + } + ) + + // insert gap values + if (gap) { + size = size.filter(i => i.trim()) + let val = [] + for (let i = 1; i <= count; i++) { + size.forEach((item, index) => { + if (index > 0 || i > 1) { + val.push(gap) + } + val.push(item) + }) + } + + return val.join(' ') + } + + return `(${size.join('')})[${count.join('')}]` +} + +exports.prefixTrackValue = prefixTrackValue + +function prefixTrackValue({ gap, value }) { + let result = parser(value).nodes.reduce((nodes, node) => { + if (node.type === 'function' && node.value === 'repeat') { + return nodes.concat({ + type: 'word', + value: transformRepeat(node, { gap }) + }) + } + if (gap && node.type === 'space') { + return nodes.concat( + { + type: 'space', + value: ' ' + }, + { + type: 'word', + value: gap + }, + node + ) + } + return nodes.concat(node) + }, []) + + return parser.stringify(result) +} + +// Parse grid-template-areas + +let DOTS = /^\.+$/ + +function track(start, end) { + return { end, span: end - start, start } +} + +function getColumns(line) { + return line.trim().split(/\s+/g) +} + +exports.parseGridAreas = parseGridAreas + +function parseGridAreas({ gap, rows }) { + return rows.reduce((areas, line, rowIndex) => { + if (gap.row) rowIndex *= 2 + + if (line.trim() === '') return areas + + getColumns(line).forEach((area, columnIndex) => { + if (DOTS.test(area)) return + + if (gap.column) columnIndex *= 2 + + if (typeof areas[area] === 'undefined') { + areas[area] = { + column: track(columnIndex + 1, columnIndex + 2), + row: track(rowIndex + 1, rowIndex + 2) + } + } else { + let { column, row } = areas[area] + + column.start = Math.min(column.start, columnIndex + 1) + column.end = Math.max(column.end, columnIndex + 2) + column.span = column.end - column.start + + row.start = Math.min(row.start, rowIndex + 1) + row.end = Math.max(row.end, rowIndex + 2) + row.span = row.end - row.start + } + }) + + return areas + }, {}) +} + +// Parse grid-template + +function testTrack(node) { + return node.type === 'word' && /^\[.+]$/.test(node.value) +} + +function verifyRowSize(result) { + if (result.areas.length > result.rows.length) { + result.rows.push('auto') + } + return result +} + +exports.parseTemplate = parseTemplate + +function parseTemplate({ decl, gap }) { + let gridTemplate = parser(decl.value).nodes.reduce( + (result, node) => { + let { type, value } = node + + if (testTrack(node) || type === 'space') return result + + // area + if (type === 'string') { + result = verifyRowSize(result) + result.areas.push(value) + } + + // values and function + if (type === 'word' || type === 'function') { + result[result.key].push(parser.stringify(node)) + } + + // divider(/) + if (type === 'div' && value === '/') { + result.key = 'columns' + result = verifyRowSize(result) + } + + return result + }, + { + areas: [], + columns: [], + key: 'rows', + rows: [] + } + ) + + return { + areas: parseGridAreas({ + gap, + rows: gridTemplate.areas + }), + columns: prefixTrackValue({ + gap: gap.column, + value: gridTemplate.columns.join(' ') + }), + rows: prefixTrackValue({ + gap: gap.row, + value: gridTemplate.rows.join(' ') + }) + } +} + +// Insert parsed grid areas + +/** + * Get an array of -ms- prefixed props and values + * @param {Object} [area] area object with column and row data + * @param {Boolean} [addRowSpan] should we add grid-column-row value? + * @param {Boolean} [addColumnSpan] should we add grid-column-span value? + * @return {Array<Object>} + */ +function getMSDecls(area, addRowSpan = false, addColumnSpan = false) { + let result = [ + { + prop: '-ms-grid-row', + value: String(area.row.start) + } + ] + if (area.row.span > 1 || addRowSpan) { + result.push({ + prop: '-ms-grid-row-span', + value: String(area.row.span) + }) + } + result.push({ + prop: '-ms-grid-column', + value: String(area.column.start) + }) + if (area.column.span > 1 || addColumnSpan) { + result.push({ + prop: '-ms-grid-column-span', + value: String(area.column.span) + }) + } + return result +} + +function getParentMedia(parent) { + if (parent.type === 'atrule' && parent.name === 'media') { + return parent + } + if (!parent.parent) { + return false + } + return getParentMedia(parent.parent) +} + +/** + * change selectors for rules with duplicate grid-areas. + * @param {Array<Rule>} rules + * @param {Array<String>} templateSelectors + * @return {Array<Rule>} rules with changed selectors + */ +function changeDuplicateAreaSelectors(ruleSelectors, templateSelectors) { + ruleSelectors = ruleSelectors.map(selector => { + let selectorBySpace = list.space(selector) + let selectorByComma = list.comma(selector) + + if (selectorBySpace.length > selectorByComma.length) { + selector = selectorBySpace.slice(-1).join('') + } + return selector + }) + + return ruleSelectors.map(ruleSelector => { + let newSelector = templateSelectors.map((tplSelector, index) => { + let space = index === 0 ? '' : ' ' + return `${space}${tplSelector} > ${ruleSelector}` + }) + + return newSelector + }) +} + +/** + * check if selector of rules are equal + * @param {Rule} ruleA + * @param {Rule} ruleB + * @return {Boolean} + */ +function selectorsEqual(ruleA, ruleB) { + return ruleA.selectors.some(sel => { + return ruleB.selectors.includes(sel) + }) +} + +/** + * Parse data from all grid-template(-areas) declarations + * @param {Root} css css root + * @return {Object} parsed data + */ +function parseGridTemplatesData(css) { + let parsed = [] + + // we walk through every grid-template(-areas) declaration and store + // data with the same area names inside the item + css.walkDecls(/grid-template(-areas)?$/, d => { + let rule = d.parent + let media = getParentMedia(rule) + let gap = getGridGap(d) + let inheritedGap = inheritGridGap(d, gap) + let { areas } = parseTemplate({ decl: d, gap: inheritedGap || gap }) + let areaNames = Object.keys(areas) + + // skip node if it doesn't have areas + if (areaNames.length === 0) { + return true + } + + // check parsed array for item that include the same area names + // return index of that item + let index = parsed.reduce((acc, { allAreas }, idx) => { + let hasAreas = allAreas && areaNames.some(area => allAreas.includes(area)) + return hasAreas ? idx : acc + }, null) + + if (index !== null) { + // index is found, add the grid-template data to that item + let { allAreas, rules } = parsed[index] + + // check if rule has no duplicate area names + let hasNoDuplicates = rules.some(r => { + return r.hasDuplicates === false && selectorsEqual(r, rule) + }) + + let duplicatesFound = false + + // check need to gather all duplicate area names + let duplicateAreaNames = rules.reduce((acc, r) => { + if (!r.params && selectorsEqual(r, rule)) { + duplicatesFound = true + return r.duplicateAreaNames + } + if (!duplicatesFound) { + areaNames.forEach(name => { + if (r.areas[name]) { + acc.push(name) + } + }) + } + return uniq(acc) + }, []) + + // update grid-row/column-span values for areas with duplicate + // area names. @see #1084 and #1146 + rules.forEach(r => { + areaNames.forEach(name => { + let area = r.areas[name] + if (area && area.row.span !== areas[name].row.span) { + areas[name].row.updateSpan = true + } + + if (area && area.column.span !== areas[name].column.span) { + areas[name].column.updateSpan = true + } + }) + }) + + parsed[index].allAreas = uniq([...allAreas, ...areaNames]) + parsed[index].rules.push({ + areas, + duplicateAreaNames, + hasDuplicates: !hasNoDuplicates, + node: rule, + params: media.params, + selectors: rule.selectors + }) + } else { + // index is NOT found, push the new item to the parsed array + parsed.push({ + allAreas: areaNames, + areasCount: 0, + rules: [ + { + areas, + duplicateAreaNames: [], + duplicateRules: [], + hasDuplicates: false, + node: rule, + params: media.params, + selectors: rule.selectors + } + ] + }) + } + + return undefined + }) + + return parsed +} + +/** + * insert prefixed grid-area declarations + * @param {Root} css css root + * @param {Function} isDisabled check if the rule is disabled + * @return {void} + */ +exports.insertAreas = insertAreas + +function insertAreas(css, isDisabled) { + // parse grid-template declarations + let gridTemplatesData = parseGridTemplatesData(css) + + // return undefined if no declarations found + if (gridTemplatesData.length === 0) { + return undefined + } + + // we need to store the rules that we will insert later + let rulesToInsert = {} + + css.walkDecls('grid-area', gridArea => { + let gridAreaRule = gridArea.parent + let hasPrefixedRow = gridAreaRule.first.prop === '-ms-grid-row' + let gridAreaMedia = getParentMedia(gridAreaRule) + + if (isDisabled(gridArea)) { + return undefined + } + + let gridAreaRuleIndex = css.index(gridAreaMedia || gridAreaRule) + + let value = gridArea.value + // found the data that matches grid-area identifier + let data = gridTemplatesData.filter(d => d.allAreas.includes(value))[0] + + if (!data) { + return true + } + + let lastArea = data.allAreas[data.allAreas.length - 1] + let selectorBySpace = list.space(gridAreaRule.selector) + let selectorByComma = list.comma(gridAreaRule.selector) + let selectorIsComplex = + selectorBySpace.length > 1 && + selectorBySpace.length > selectorByComma.length + + // prevent doubling of prefixes + if (hasPrefixedRow) { + return false + } + + // create the empty object with the key as the last area name + // e.g if we have templates with "a b c" values, "c" will be the last area + if (!rulesToInsert[lastArea]) { + rulesToInsert[lastArea] = {} + } + + let lastRuleIsSet = false + + // walk through every grid-template rule data + for (let rule of data.rules) { + let area = rule.areas[value] + let hasDuplicateName = rule.duplicateAreaNames.includes(value) + + // if we can't find the area name, update lastRule and continue + if (!area) { + let lastRule = rulesToInsert[lastArea].lastRule + let lastRuleIndex + if (lastRule) { + lastRuleIndex = css.index(lastRule) + } else { + /* c8 ignore next 2 */ + lastRuleIndex = -1 + } + + if (gridAreaRuleIndex > lastRuleIndex) { + rulesToInsert[lastArea].lastRule = gridAreaMedia || gridAreaRule + } + continue + } + + // for grid-templates inside media rule we need to create empty + // array to push prefixed grid-area rules later + if (rule.params && !rulesToInsert[lastArea][rule.params]) { + rulesToInsert[lastArea][rule.params] = [] + } + + if ((!rule.hasDuplicates || !hasDuplicateName) && !rule.params) { + // grid-template has no duplicates and not inside media rule + + getMSDecls(area, false, false) + .reverse() + .forEach(i => + gridAreaRule.prepend( + Object.assign(i, { + raws: { + between: gridArea.raws.between + } + }) + ) + ) + + rulesToInsert[lastArea].lastRule = gridAreaRule + lastRuleIsSet = true + } else if (rule.hasDuplicates && !rule.params && !selectorIsComplex) { + // grid-template has duplicates and not inside media rule + let cloned = gridAreaRule.clone() + cloned.removeAll() + + getMSDecls(area, area.row.updateSpan, area.column.updateSpan) + .reverse() + .forEach(i => + cloned.prepend( + Object.assign(i, { + raws: { + between: gridArea.raws.between + } + }) + ) + ) + + cloned.selectors = changeDuplicateAreaSelectors( + cloned.selectors, + rule.selectors + ) + + if (rulesToInsert[lastArea].lastRule) { + rulesToInsert[lastArea].lastRule.after(cloned) + } + rulesToInsert[lastArea].lastRule = cloned + lastRuleIsSet = true + } else if ( + rule.hasDuplicates && + !rule.params && + selectorIsComplex && + gridAreaRule.selector.includes(rule.selectors[0]) + ) { + // grid-template has duplicates and not inside media rule + // and the selector is complex + gridAreaRule.walkDecls(/-ms-grid-(row|column)/, d => d.remove()) + getMSDecls(area, area.row.updateSpan, area.column.updateSpan) + .reverse() + .forEach(i => + gridAreaRule.prepend( + Object.assign(i, { + raws: { + between: gridArea.raws.between + } + }) + ) + ) + } else if (rule.params) { + // grid-template is inside media rule + // if we're inside media rule, we need to store prefixed rules + // inside rulesToInsert object to be able to preserve the order of media + // rules and merge them easily + let cloned = gridAreaRule.clone() + cloned.removeAll() + + getMSDecls(area, area.row.updateSpan, area.column.updateSpan) + .reverse() + .forEach(i => + cloned.prepend( + Object.assign(i, { + raws: { + between: gridArea.raws.between + } + }) + ) + ) + + if (rule.hasDuplicates && hasDuplicateName) { + cloned.selectors = changeDuplicateAreaSelectors( + cloned.selectors, + rule.selectors + ) + } + + cloned.raws = rule.node.raws + + if (css.index(rule.node.parent) > gridAreaRuleIndex) { + // append the prefixed rules right inside media rule + // with grid-template + rule.node.parent.append(cloned) + } else { + // store the rule to insert later + rulesToInsert[lastArea][rule.params].push(cloned) + } + + // set new rule as last rule ONLY if we didn't set lastRule for + // this grid-area before + if (!lastRuleIsSet) { + rulesToInsert[lastArea].lastRule = gridAreaMedia || gridAreaRule + } + } + } + + return undefined + }) + + // append stored rules inside the media rules + Object.keys(rulesToInsert).forEach(area => { + let data = rulesToInsert[area] + let lastRule = data.lastRule + Object.keys(data) + .reverse() + .filter(p => p !== 'lastRule') + .forEach(params => { + if (data[params].length > 0 && lastRule) { + lastRule.after({ name: 'media', params }) + lastRule.next().append(data[params]) + } + }) + }) + + return undefined +} + +/** + * Warn user if grid area identifiers are not found + * @param {Object} areas + * @param {Declaration} decl + * @param {Result} result + * @return {void} + */ +exports.warnMissedAreas = warnMissedAreas + +function warnMissedAreas(areas, decl, result) { + let missed = Object.keys(areas) + + decl.root().walkDecls('grid-area', gridArea => { + missed = missed.filter(e => e !== gridArea.value) + }) + + if (missed.length > 0) { + decl.warn(result, 'Can not find grid areas: ' + missed.join(', ')) + } + + return undefined +} + +/** + * compare selectors with grid-area rule and grid-template rule + * show warning if grid-template selector is not found + * (this function used for grid-area rule) + * @param {Declaration} decl + * @param {Result} result + * @return {void} + */ +exports.warnTemplateSelectorNotFound = warnTemplateSelectorNotFound + +function warnTemplateSelectorNotFound(decl, result) { + let rule = decl.parent + let root = decl.root() + let duplicatesFound = false + + // slice selector array. Remove the last part (for comparison) + let slicedSelectorArr = list + .space(rule.selector) + .filter(str => str !== '>') + .slice(0, -1) + + // we need to compare only if selector is complex. + // e.g '.grid-cell' is simple, but '.parent > .grid-cell' is complex + if (slicedSelectorArr.length > 0) { + let gridTemplateFound = false + let foundAreaSelector = null + + root.walkDecls(/grid-template(-areas)?$/, d => { + let parent = d.parent + let templateSelectors = parent.selectors + + let { areas } = parseTemplate({ decl: d, gap: getGridGap(d) }) + let hasArea = areas[decl.value] + + // find the the matching selectors + for (let tplSelector of templateSelectors) { + if (gridTemplateFound) { + break + } + let tplSelectorArr = list.space(tplSelector).filter(str => str !== '>') + + gridTemplateFound = tplSelectorArr.every( + (item, idx) => item === slicedSelectorArr[idx] + ) + } + + if (gridTemplateFound || !hasArea) { + return true + } + + if (!foundAreaSelector) { + foundAreaSelector = parent.selector + } + + // if we found the duplicate area with different selector + if (foundAreaSelector && foundAreaSelector !== parent.selector) { + duplicatesFound = true + } + + return undefined + }) + + // warn user if we didn't find template + if (!gridTemplateFound && duplicatesFound) { + decl.warn( + result, + 'Autoprefixer cannot find a grid-template ' + + `containing the duplicate grid-area "${decl.value}" ` + + `with full selector matching: ${slicedSelectorArr.join(' ')}` + ) + } + } +} + +/** + * warn user if both grid-area and grid-(row|column) + * declarations are present in the same rule + * @param {Declaration} decl + * @param {Result} result + * @return {void} + */ +exports.warnIfGridRowColumnExists = warnIfGridRowColumnExists + +function warnIfGridRowColumnExists(decl, result) { + let rule = decl.parent + let decls = [] + rule.walkDecls(/^grid-(row|column)/, d => { + if ( + !d.prop.endsWith('-end') && + !d.value.startsWith('span') && + !d.prop.endsWith('-gap') + ) { + decls.push(d) + } + }) + if (decls.length > 0) { + decls.forEach(d => { + d.warn( + result, + 'You already have a grid-area declaration present in the rule. ' + + `You should use either grid-area or ${d.prop}, not both` + ) + }) + } + + return undefined +} + +// Gap utils + +exports.getGridGap = getGridGap + +function getGridGap(decl) { + let gap = {} + + // try to find gap + let testGap = /^(grid-)?((row|column)-)?gap$/ + decl.parent.walkDecls(testGap, ({ prop, value }) => { + if (/^(grid-)?gap$/.test(prop)) { + let [row, , column] = parser(value).nodes + + gap.row = row && parser.stringify(row) + gap.column = column ? parser.stringify(column) : gap.row + } + if (/^(grid-)?row-gap$/.test(prop)) gap.row = value + if (/^(grid-)?column-gap$/.test(prop)) gap.column = value + }) + + return gap +} + +/** + * parse media parameters (for example 'min-width: 500px') + * @param {String} params parameter to parse + * @return {} + */ +function parseMediaParams(params) { + if (!params) { + return [] + } + let parsed = parser(params) + let prop + let value + + parsed.walk(node => { + if (node.type === 'word' && /min|max/g.test(node.value)) { + prop = node.value + } else if (node.value.includes('px')) { + value = parseInt(node.value.replace(/\D/g, '')) + } + }) + + return [prop, value] +} + +/** + * Compare the selectors and decide if we + * need to inherit gap from compared selector or not. + * @type {String} selA + * @type {String} selB + * @return {Boolean} + */ +function shouldInheritGap(selA, selB) { + let result + + // get arrays of selector split in 3-deep array + let splitSelectorArrA = splitSelector(selA) + let splitSelectorArrB = splitSelector(selB) + + if (splitSelectorArrA[0].length < splitSelectorArrB[0].length) { + // abort if selectorA has lower descendant specificity then selectorB + // (e.g '.grid' and '.hello .world .grid') + return false + } else if (splitSelectorArrA[0].length > splitSelectorArrB[0].length) { + // if selectorA has higher descendant specificity then selectorB + // (e.g '.foo .bar .grid' and '.grid') + + let idx = splitSelectorArrA[0].reduce((res, [item], index) => { + let firstSelectorPart = splitSelectorArrB[0][0][0] + if (item === firstSelectorPart) { + return index + } + return false + }, false) + + if (idx) { + result = splitSelectorArrB[0].every((arr, index) => { + return arr.every( + (part, innerIndex) => + // because selectorA has more space elements, we need to slice + // selectorA array by 'idx' number to compare them + splitSelectorArrA[0].slice(idx)[index][innerIndex] === part + ) + }) + } + } else { + // if selectorA has the same descendant specificity as selectorB + // this condition covers cases such as: '.grid.foo.bar' and '.grid' + result = splitSelectorArrB.some(byCommaArr => { + return byCommaArr.every((bySpaceArr, index) => { + return bySpaceArr.every( + (part, innerIndex) => splitSelectorArrA[0][index][innerIndex] === part + ) + }) + }) + } + + return result +} +/** + * inherit grid gap values from the closest rule above + * with the same selector + * @param {Declaration} decl + * @param {Object} gap gap values + * @return {Object | Boolean} return gap values or false (if not found) + */ +exports.inheritGridGap = inheritGridGap + +function inheritGridGap(decl, gap) { + let rule = decl.parent + let mediaRule = getParentMedia(rule) + let root = rule.root() + + // get an array of selector split in 3-deep array + let splitSelectorArr = splitSelector(rule.selector) + + // abort if the rule already has gaps + if (Object.keys(gap).length > 0) { + return false + } + + // e.g ['min-width'] + let [prop] = parseMediaParams(mediaRule.params) + + let lastBySpace = splitSelectorArr[0] + + // get escaped value from the selector + // if we have '.grid-2.foo.bar' selector, will be '\.grid\-2' + let escaped = escapeRegexp(lastBySpace[lastBySpace.length - 1][0]) + + let regexp = new RegExp(`(${escaped}$)|(${escaped}[,.])`) + + // find the closest rule with the same selector + let closestRuleGap + root.walkRules(regexp, r => { + let gridGap + + // abort if are checking the same rule + if (rule.toString() === r.toString()) { + return false + } + + // find grid-gap values + r.walkDecls('grid-gap', d => (gridGap = getGridGap(d))) + + // skip rule without gaps + if (!gridGap || Object.keys(gridGap).length === 0) { + return true + } + + // skip rules that should not be inherited from + if (!shouldInheritGap(rule.selector, r.selector)) { + return true + } + + let media = getParentMedia(r) + if (media) { + // if we are inside media, we need to check that media props match + // e.g ('min-width' === 'min-width') + let propToCompare = parseMediaParams(media.params)[0] + if (propToCompare === prop) { + closestRuleGap = gridGap + return true + } + } else { + closestRuleGap = gridGap + return true + } + + return undefined + }) + + // if we find the closest gap object + if (closestRuleGap && Object.keys(closestRuleGap).length > 0) { + return closestRuleGap + } + return false +} + +exports.warnGridGap = warnGridGap + +function warnGridGap({ decl, gap, hasColumns, result }) { + let hasBothGaps = gap.row && gap.column + if (!hasColumns && (hasBothGaps || (gap.column && !gap.row))) { + delete gap.column + decl.warn( + result, + 'Can not implement grid-gap without grid-template-columns' + ) + } +} + +/** + * normalize the grid-template-rows/columns values + * @param {String} str grid-template-rows/columns value + * @return {Array} normalized array with values + * @example + * let normalized = normalizeRowColumn('1fr repeat(2, 20px 50px) 1fr') + * normalized // <= ['1fr', '20px', '50px', '20px', '50px', '1fr'] + */ +function normalizeRowColumn(str) { + let normalized = parser(str).nodes.reduce((result, node) => { + if (node.type === 'function' && node.value === 'repeat') { + let key = 'count' + + let [count, value] = node.nodes.reduce( + (acc, n) => { + if (n.type === 'word' && key === 'count') { + acc[0] = Math.abs(parseInt(n.value)) + return acc + } + if (n.type === 'div' && n.value === ',') { + key = 'value' + return acc + } + if (key === 'value') { + acc[1] += parser.stringify(n) + } + return acc + }, + [0, ''] + ) + + if (count) { + for (let i = 0; i < count; i++) { + result.push(value) + } + } + + return result + } + if (node.type === 'space') { + return result + } + return result.concat(parser.stringify(node)) + }, []) + + return normalized +} + +exports.autoplaceGridItems = autoplaceGridItems + +/** + * Autoplace grid items + * @param {Declaration} decl + * @param {Result} result + * @param {Object} gap gap values + * @param {String} autoflowValue grid-auto-flow value + * @return {void} + * @see https://github.com/postcss/autoprefixer/issues/1148 + */ +function autoplaceGridItems(decl, result, gap, autoflowValue = 'row') { + let { parent } = decl + + let rowDecl = parent.nodes.find(i => i.prop === 'grid-template-rows') + let rows = normalizeRowColumn(rowDecl.value) + let columns = normalizeRowColumn(decl.value) + + // Build array of area names with dummy values. If we have 3 columns and + // 2 rows, filledRows will be equal to ['1 2 3', '4 5 6'] + let filledRows = rows.map((_, rowIndex) => { + return Array.from( + { length: columns.length }, + (v, k) => k + rowIndex * columns.length + 1 + ).join(' ') + }) + + let areas = parseGridAreas({ gap, rows: filledRows }) + let keys = Object.keys(areas) + let items = keys.map(i => areas[i]) + + // Change the order of cells if grid-auto-flow value is 'column' + if (autoflowValue.includes('column')) { + items = items.sort((a, b) => a.column.start - b.column.start) + } + + // Insert new rules + items.reverse().forEach((item, index) => { + let { column, row } = item + let nodeSelector = parent.selectors + .map(sel => sel + ` > *:nth-child(${keys.length - index})`) + .join(', ') + + // create new rule + let node = parent.clone().removeAll() + + // change rule selector + node.selector = nodeSelector + + // insert prefixed row/column values + node.append({ prop: '-ms-grid-row', value: row.start }) + node.append({ prop: '-ms-grid-column', value: column.start }) + + // insert rule + parent.after(node) + }) + + return undefined +} diff --git a/node_modules/autoprefixer/lib/hacks/image-rendering.js b/node_modules/autoprefixer/lib/hacks/image-rendering.js new file mode 100644 index 0000000..38b571b --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/image-rendering.js @@ -0,0 +1,48 @@ +let Declaration = require('../declaration') + +class ImageRendering extends Declaration { + /** + * Add hack only for crisp-edges + */ + check(decl) { + return decl.value === 'pixelated' + } + + /** + * Return property name by spec + */ + normalize() { + return 'image-rendering' + } + + /** + * Change property name for IE + */ + prefixed(prop, prefix) { + if (prefix === '-ms-') { + return '-ms-interpolation-mode' + } + return super.prefixed(prop, prefix) + } + + /** + * Warn on old value + */ + process(node, result) { + return super.process(node, result) + } + + /** + * Change property and value for IE + */ + set(decl, prefix) { + if (prefix !== '-ms-') return super.set(decl, prefix) + decl.prop = '-ms-interpolation-mode' + decl.value = 'nearest-neighbor' + return decl + } +} + +ImageRendering.names = ['image-rendering', 'interpolation-mode'] + +module.exports = ImageRendering diff --git a/node_modules/autoprefixer/lib/hacks/image-set.js b/node_modules/autoprefixer/lib/hacks/image-set.js new file mode 100644 index 0000000..fecd088 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/image-set.js @@ -0,0 +1,18 @@ +let Value = require('../value') + +class ImageSet extends Value { + /** + * Use non-standard name for WebKit and Firefox + */ + replace(string, prefix) { + let fixed = super.replace(string, prefix) + if (prefix === '-webkit-') { + fixed = fixed.replace(/("[^"]+"|'[^']+')(\s+\d+\w)/gi, 'url($1)$2') + } + return fixed + } +} + +ImageSet.names = ['image-set'] + +module.exports = ImageSet diff --git a/node_modules/autoprefixer/lib/hacks/inline-logical.js b/node_modules/autoprefixer/lib/hacks/inline-logical.js new file mode 100644 index 0000000..31dc968 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/inline-logical.js @@ -0,0 +1,34 @@ +let Declaration = require('../declaration') + +class InlineLogical extends Declaration { + /** + * Return property name by spec + */ + normalize(prop) { + return prop.replace(/(margin|padding|border)-(start|end)/, '$1-inline-$2') + } + + /** + * Use old syntax for -moz- and -webkit- + */ + prefixed(prop, prefix) { + return prefix + prop.replace('-inline', '') + } +} + +InlineLogical.names = [ + 'border-inline-start', + 'border-inline-end', + 'margin-inline-start', + 'margin-inline-end', + 'padding-inline-start', + 'padding-inline-end', + 'border-start', + 'border-end', + 'margin-start', + 'margin-end', + 'padding-start', + 'padding-end' +] + +module.exports = InlineLogical diff --git a/node_modules/autoprefixer/lib/hacks/intrinsic.js b/node_modules/autoprefixer/lib/hacks/intrinsic.js new file mode 100644 index 0000000..7c5bb50 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/intrinsic.js @@ -0,0 +1,61 @@ +let OldValue = require('../old-value') +let Value = require('../value') + +function regexp(name) { + return new RegExp(`(^|[\\s,(])(${name}($|[\\s),]))`, 'gi') +} + +class Intrinsic extends Value { + add(decl, prefix) { + if (decl.prop.includes('grid') && prefix !== '-webkit-') { + return undefined + } + return super.add(decl, prefix) + } + + isStretch() { + return ( + this.name === 'stretch' || + this.name === 'fill' || + this.name === 'fill-available' + ) + } + + old(prefix) { + let prefixed = prefix + this.name + if (this.isStretch()) { + if (prefix === '-moz-') { + prefixed = '-moz-available' + } else if (prefix === '-webkit-') { + prefixed = '-webkit-fill-available' + } + } + return new OldValue(this.name, prefixed, prefixed, regexp(prefixed)) + } + + regexp() { + if (!this.regexpCache) this.regexpCache = regexp(this.name) + return this.regexpCache + } + + replace(string, prefix) { + if (prefix === '-moz-' && this.isStretch()) { + return string.replace(this.regexp(), '$1-moz-available$3') + } + if (prefix === '-webkit-' && this.isStretch()) { + return string.replace(this.regexp(), '$1-webkit-fill-available$3') + } + return super.replace(string, prefix) + } +} + +Intrinsic.names = [ + 'max-content', + 'min-content', + 'fit-content', + 'fill', + 'fill-available', + 'stretch' +] + +module.exports = Intrinsic diff --git a/node_modules/autoprefixer/lib/hacks/justify-content.js b/node_modules/autoprefixer/lib/hacks/justify-content.js new file mode 100644 index 0000000..8ad863f --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/justify-content.js @@ -0,0 +1,54 @@ +let flexSpec = require('./flex-spec') +let Declaration = require('../declaration') + +class JustifyContent extends Declaration { + /** + * Return property name by final spec + */ + normalize() { + return 'justify-content' + } + + /** + * Change property name for 2009 and 2012 specs + */ + prefixed(prop, prefix) { + let spec + ;[spec, prefix] = flexSpec(prefix) + if (spec === 2009) { + return prefix + 'box-pack' + } + if (spec === 2012) { + return prefix + 'flex-pack' + } + return super.prefixed(prop, prefix) + } + + /** + * Change value for 2009 and 2012 specs + */ + set(decl, prefix) { + let spec = flexSpec(prefix)[0] + if (spec === 2009 || spec === 2012) { + let value = JustifyContent.oldValues[decl.value] || decl.value + decl.value = value + if (spec !== 2009 || value !== 'distribute') { + return super.set(decl, prefix) + } + } else if (spec === 'final') { + return super.set(decl, prefix) + } + return undefined + } +} + +JustifyContent.names = ['justify-content', 'flex-pack', 'box-pack'] + +JustifyContent.oldValues = { + 'flex-end': 'end', + 'flex-start': 'start', + 'space-around': 'distribute', + 'space-between': 'justify' +} + +module.exports = JustifyContent diff --git a/node_modules/autoprefixer/lib/hacks/mask-border.js b/node_modules/autoprefixer/lib/hacks/mask-border.js new file mode 100644 index 0000000..d5efde2 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/mask-border.js @@ -0,0 +1,38 @@ +let Declaration = require('../declaration') + +class MaskBorder extends Declaration { + /** + * Return property name by final spec + */ + normalize() { + return this.name.replace('box-image', 'border') + } + + /** + * Return flex property for 2012 spec + */ + prefixed(prop, prefix) { + let result = super.prefixed(prop, prefix) + if (prefix === '-webkit-') { + result = result.replace('border', 'box-image') + } + return result + } +} + +MaskBorder.names = [ + 'mask-border', + 'mask-border-source', + 'mask-border-slice', + 'mask-border-width', + 'mask-border-outset', + 'mask-border-repeat', + 'mask-box-image', + 'mask-box-image-source', + 'mask-box-image-slice', + 'mask-box-image-width', + 'mask-box-image-outset', + 'mask-box-image-repeat' +] + +module.exports = MaskBorder diff --git a/node_modules/autoprefixer/lib/hacks/mask-composite.js b/node_modules/autoprefixer/lib/hacks/mask-composite.js new file mode 100644 index 0000000..a30df13 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/mask-composite.js @@ -0,0 +1,88 @@ +let Declaration = require('../declaration') + +class MaskComposite extends Declaration { + /** + * Prefix mask-composite for webkit + */ + insert(decl, prefix, prefixes) { + let isCompositeProp = decl.prop === 'mask-composite' + + let compositeValues + + if (isCompositeProp) { + compositeValues = decl.value.split(',') + } else { + compositeValues = decl.value.match(MaskComposite.regexp) || [] + } + + compositeValues = compositeValues.map(el => el.trim()).filter(el => el) + let hasCompositeValues = compositeValues.length + + let compositeDecl + + if (hasCompositeValues) { + compositeDecl = this.clone(decl) + compositeDecl.value = compositeValues + .map(value => MaskComposite.oldValues[value] || value) + .join(', ') + + if (compositeValues.includes('intersect')) { + compositeDecl.value += ', xor' + } + + compositeDecl.prop = prefix + 'mask-composite' + } + + if (isCompositeProp) { + if (!hasCompositeValues) { + return undefined + } + + if (this.needCascade(decl)) { + compositeDecl.raws.before = this.calcBefore(prefixes, decl, prefix) + } + + return decl.parent.insertBefore(decl, compositeDecl) + } + + let cloned = this.clone(decl) + cloned.prop = prefix + cloned.prop + + if (hasCompositeValues) { + cloned.value = cloned.value.replace(MaskComposite.regexp, '') + } + + if (this.needCascade(decl)) { + cloned.raws.before = this.calcBefore(prefixes, decl, prefix) + } + + decl.parent.insertBefore(decl, cloned) + + if (!hasCompositeValues) { + return decl + } + + if (this.needCascade(decl)) { + compositeDecl.raws.before = this.calcBefore(prefixes, decl, prefix) + } + return decl.parent.insertBefore(decl, compositeDecl) + } +} + +MaskComposite.names = ['mask', 'mask-composite'] + +MaskComposite.oldValues = { + add: 'source-over', + exclude: 'xor', + intersect: 'source-in', + subtract: 'source-out' +} + +MaskComposite.regexp = new RegExp( + `\\s+(${Object.keys(MaskComposite.oldValues).join( + '|' + )})\\b(?!\\))\\s*(?=[,])`, + 'ig' +) + +module.exports = MaskComposite diff --git a/node_modules/autoprefixer/lib/hacks/order.js b/node_modules/autoprefixer/lib/hacks/order.js new file mode 100644 index 0000000..3150a94 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/order.js @@ -0,0 +1,42 @@ +let flexSpec = require('./flex-spec') +let Declaration = require('../declaration') + +class Order extends Declaration { + /** + * Return property name by final spec + */ + normalize() { + return 'order' + } + + /** + * Change property name for 2009 and 2012 specs + */ + prefixed(prop, prefix) { + let spec + ;[spec, prefix] = flexSpec(prefix) + if (spec === 2009) { + return prefix + 'box-ordinal-group' + } + if (spec === 2012) { + return prefix + 'flex-order' + } + return super.prefixed(prop, prefix) + } + + /** + * Fix value for 2009 spec + */ + set(decl, prefix) { + let spec = flexSpec(prefix)[0] + if (spec === 2009 && /\d/.test(decl.value)) { + decl.value = (parseInt(decl.value) + 1).toString() + return super.set(decl, prefix) + } + return super.set(decl, prefix) + } +} + +Order.names = ['order', 'flex-order', 'box-ordinal-group'] + +module.exports = Order diff --git a/node_modules/autoprefixer/lib/hacks/overscroll-behavior.js b/node_modules/autoprefixer/lib/hacks/overscroll-behavior.js new file mode 100644 index 0000000..03bd7d4 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/overscroll-behavior.js @@ -0,0 +1,33 @@ +let Declaration = require('../declaration') + +class OverscrollBehavior extends Declaration { + /** + * Return property name by spec + */ + normalize() { + return 'overscroll-behavior' + } + + /** + * Change property name for IE + */ + prefixed(prop, prefix) { + return prefix + 'scroll-chaining' + } + + /** + * Change value for IE + */ + set(decl, prefix) { + if (decl.value === 'auto') { + decl.value = 'chained' + } else if (decl.value === 'none' || decl.value === 'contain') { + decl.value = 'none' + } + return super.set(decl, prefix) + } +} + +OverscrollBehavior.names = ['overscroll-behavior', 'scroll-chaining'] + +module.exports = OverscrollBehavior diff --git a/node_modules/autoprefixer/lib/hacks/pixelated.js b/node_modules/autoprefixer/lib/hacks/pixelated.js new file mode 100644 index 0000000..6084826 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/pixelated.js @@ -0,0 +1,34 @@ +let OldValue = require('../old-value') +let Value = require('../value') + +class Pixelated extends Value { + /** + * Different name for WebKit and Firefox + */ + old(prefix) { + if (prefix === '-webkit-') { + return new OldValue(this.name, '-webkit-optimize-contrast') + } + if (prefix === '-moz-') { + return new OldValue(this.name, '-moz-crisp-edges') + } + return super.old(prefix) + } + + /** + * Use non-standard name for WebKit and Firefox + */ + replace(string, prefix) { + if (prefix === '-webkit-') { + return string.replace(this.regexp(), '$1-webkit-optimize-contrast') + } + if (prefix === '-moz-') { + return string.replace(this.regexp(), '$1-moz-crisp-edges') + } + return super.replace(string, prefix) + } +} + +Pixelated.names = ['pixelated'] + +module.exports = Pixelated diff --git a/node_modules/autoprefixer/lib/hacks/place-self.js b/node_modules/autoprefixer/lib/hacks/place-self.js new file mode 100644 index 0000000..e0ce3e8 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/place-self.js @@ -0,0 +1,32 @@ +let Declaration = require('../declaration') +let utils = require('./grid-utils') + +class PlaceSelf extends Declaration { + /** + * Translate place-self to separate -ms- prefixed properties + */ + insert(decl, prefix, prefixes) { + if (prefix !== '-ms-') return super.insert(decl, prefix, prefixes) + + // prevent doubling of prefixes + if (decl.parent.some(i => i.prop === '-ms-grid-row-align')) { + return undefined + } + + let [[first, second]] = utils.parse(decl) + + if (second) { + utils.insertDecl(decl, 'grid-row-align', first) + utils.insertDecl(decl, 'grid-column-align', second) + } else { + utils.insertDecl(decl, 'grid-row-align', first) + utils.insertDecl(decl, 'grid-column-align', first) + } + + return undefined + } +} + +PlaceSelf.names = ['place-self'] + +module.exports = PlaceSelf diff --git a/node_modules/autoprefixer/lib/hacks/placeholder-shown.js b/node_modules/autoprefixer/lib/hacks/placeholder-shown.js new file mode 100644 index 0000000..8bb1cc8 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/placeholder-shown.js @@ -0,0 +1,17 @@ +let Selector = require('../selector') + +class PlaceholderShown extends Selector { + /** + * Return different selectors depend on prefix + */ + prefixed(prefix) { + if (prefix === '-ms-') { + return ':-ms-input-placeholder' + } + return `:${prefix}placeholder-shown` + } +} + +PlaceholderShown.names = [':placeholder-shown'] + +module.exports = PlaceholderShown diff --git a/node_modules/autoprefixer/lib/hacks/placeholder.js b/node_modules/autoprefixer/lib/hacks/placeholder.js new file mode 100644 index 0000000..45730a5 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/placeholder.js @@ -0,0 +1,33 @@ +let Selector = require('../selector') + +class Placeholder extends Selector { + /** + * Add old mozilla to possible prefixes + */ + possible() { + return super.possible().concat(['-moz- old', '-ms- old']) + } + + /** + * Return different selectors depend on prefix + */ + prefixed(prefix) { + if (prefix === '-webkit-') { + return '::-webkit-input-placeholder' + } + if (prefix === '-ms-') { + return '::-ms-input-placeholder' + } + if (prefix === '-ms- old') { + return ':-ms-input-placeholder' + } + if (prefix === '-moz- old') { + return ':-moz-placeholder' + } + return `::${prefix}placeholder` + } +} + +Placeholder.names = ['::placeholder'] + +module.exports = Placeholder diff --git a/node_modules/autoprefixer/lib/hacks/print-color-adjust.js b/node_modules/autoprefixer/lib/hacks/print-color-adjust.js new file mode 100644 index 0000000..6526a8e --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/print-color-adjust.js @@ -0,0 +1,25 @@ +let Declaration = require('../declaration') + +class PrintColorAdjust extends Declaration { + /** + * Return property name by spec + */ + normalize() { + return 'print-color-adjust' + } + + /** + * Change property name for WebKit-based browsers + */ + prefixed(prop, prefix) { + if (prefix === '-moz-') { + return 'color-adjust' + } else { + return prefix + 'print-color-adjust' + } + } +} + +PrintColorAdjust.names = ['print-color-adjust', 'color-adjust'] + +module.exports = PrintColorAdjust diff --git a/node_modules/autoprefixer/lib/hacks/text-decoration-skip-ink.js b/node_modules/autoprefixer/lib/hacks/text-decoration-skip-ink.js new file mode 100644 index 0000000..25dc4db --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/text-decoration-skip-ink.js @@ -0,0 +1,23 @@ +let Declaration = require('../declaration') + +class TextDecorationSkipInk extends Declaration { + /** + * Change prefix for ink value + */ + set(decl, prefix) { + if (decl.prop === 'text-decoration-skip-ink' && decl.value === 'auto') { + decl.prop = prefix + 'text-decoration-skip' + decl.value = 'ink' + return decl + } else { + return super.set(decl, prefix) + } + } +} + +TextDecorationSkipInk.names = [ + 'text-decoration-skip-ink', + 'text-decoration-skip' +] + +module.exports = TextDecorationSkipInk diff --git a/node_modules/autoprefixer/lib/hacks/text-decoration.js b/node_modules/autoprefixer/lib/hacks/text-decoration.js new file mode 100644 index 0000000..148d98a --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/text-decoration.js @@ -0,0 +1,25 @@ +let Declaration = require('../declaration') + +const BASIC = [ + 'none', + 'underline', + 'overline', + 'line-through', + 'blink', + 'inherit', + 'initial', + 'unset' +] + +class TextDecoration extends Declaration { + /** + * Do not add prefixes for basic values. + */ + check(decl) { + return decl.value.split(/\s+/).some(i => !BASIC.includes(i)) + } +} + +TextDecoration.names = ['text-decoration'] + +module.exports = TextDecoration diff --git a/node_modules/autoprefixer/lib/hacks/text-emphasis-position.js b/node_modules/autoprefixer/lib/hacks/text-emphasis-position.js new file mode 100644 index 0000000..0d04f8b --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/text-emphasis-position.js @@ -0,0 +1,14 @@ +let Declaration = require('../declaration') + +class TextEmphasisPosition extends Declaration { + set(decl, prefix) { + if (prefix === '-webkit-') { + decl.value = decl.value.replace(/\s*(right|left)\s*/i, '') + } + return super.set(decl, prefix) + } +} + +TextEmphasisPosition.names = ['text-emphasis-position'] + +module.exports = TextEmphasisPosition diff --git a/node_modules/autoprefixer/lib/hacks/transform-decl.js b/node_modules/autoprefixer/lib/hacks/transform-decl.js new file mode 100644 index 0000000..cecd06d --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/transform-decl.js @@ -0,0 +1,79 @@ +let Declaration = require('../declaration') + +class TransformDecl extends Declaration { + /** + * Is transform contain 3D commands + */ + contain3d(decl) { + if (decl.prop === 'transform-origin') { + return false + } + + for (let func of TransformDecl.functions3d) { + if (decl.value.includes(`${func}(`)) { + return true + } + } + + return false + } + + /** + * Don't add prefix for IE in keyframes + */ + insert(decl, prefix, prefixes) { + if (prefix === '-ms-') { + if (!this.contain3d(decl) && !this.keyframeParents(decl)) { + return super.insert(decl, prefix, prefixes) + } + } else if (prefix === '-o-') { + if (!this.contain3d(decl)) { + return super.insert(decl, prefix, prefixes) + } + } else { + return super.insert(decl, prefix, prefixes) + } + return undefined + } + + /** + * Recursively check all parents for @keyframes + */ + keyframeParents(decl) { + let { parent } = decl + while (parent) { + if (parent.type === 'atrule' && parent.name === 'keyframes') { + return true + } + ;({ parent } = parent) + } + return false + } + + /** + * Replace rotateZ to rotate for IE 9 + */ + set(decl, prefix) { + decl = super.set(decl, prefix) + if (prefix === '-ms-') { + decl.value = decl.value.replace(/rotatez/gi, 'rotate') + } + return decl + } +} + +TransformDecl.names = ['transform', 'transform-origin'] + +TransformDecl.functions3d = [ + 'matrix3d', + 'translate3d', + 'translateZ', + 'scale3d', + 'scaleZ', + 'rotate3d', + 'rotateX', + 'rotateY', + 'perspective' +] + +module.exports = TransformDecl diff --git a/node_modules/autoprefixer/lib/hacks/user-select.js b/node_modules/autoprefixer/lib/hacks/user-select.js new file mode 100644 index 0000000..850f981 --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/user-select.js @@ -0,0 +1,28 @@ +let Declaration = require('../declaration') + +class UserSelect extends Declaration { + /** + * Avoid prefixing all in IE + */ + insert(decl, prefix, prefixes) { + if (decl.value === 'all' && prefix === '-ms-') { + return undefined + } else { + return super.insert(decl, prefix, prefixes) + } + } + + /** + * Change prefixed value for IE + */ + set(decl, prefix) { + if (prefix === '-ms-' && decl.value === 'contain') { + decl.value = 'element' + } + return super.set(decl, prefix) + } +} + +UserSelect.names = ['user-select'] + +module.exports = UserSelect diff --git a/node_modules/autoprefixer/lib/hacks/writing-mode.js b/node_modules/autoprefixer/lib/hacks/writing-mode.js new file mode 100644 index 0000000..71c8eeb --- /dev/null +++ b/node_modules/autoprefixer/lib/hacks/writing-mode.js @@ -0,0 +1,42 @@ +let Declaration = require('../declaration') + +class WritingMode extends Declaration { + insert(decl, prefix, prefixes) { + if (prefix === '-ms-') { + let cloned = this.set(this.clone(decl), prefix) + + if (this.needCascade(decl)) { + cloned.raws.before = this.calcBefore(prefixes, decl, prefix) + } + let direction = 'ltr' + + decl.parent.nodes.forEach(i => { + if (i.prop === 'direction') { + if (i.value === 'rtl' || i.value === 'ltr') direction = i.value + } + }) + + cloned.value = WritingMode.msValues[direction][decl.value] || decl.value + return decl.parent.insertBefore(decl, cloned) + } + + return super.insert(decl, prefix, prefixes) + } +} + +WritingMode.names = ['writing-mode'] + +WritingMode.msValues = { + ltr: { + 'horizontal-tb': 'lr-tb', + 'vertical-lr': 'tb-lr', + 'vertical-rl': 'tb-rl' + }, + rtl: { + 'horizontal-tb': 'rl-tb', + 'vertical-lr': 'bt-lr', + 'vertical-rl': 'bt-rl' + } +} + +module.exports = WritingMode |