Начат фронтенд

This commit is contained in:
Georgiy Syralev
2025-09-16 14:47:30 +03:00
parent f37e85e2e0
commit 40de29041d
2100 changed files with 305701 additions and 11807 deletions

View File

@@ -1,14 +1,7 @@
let Declaration = require('../declaration')
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
*/
@@ -21,6 +14,13 @@ class AlignContent extends Declaration {
return super.prefixed(prop, prefix)
}
/**
* Return property name by final spec
*/
normalize() {
return 'align-content'
}
/**
* Change value for 2012 spec and ignore prefix for 2009
*/
@@ -42,8 +42,8 @@ AlignContent.names = ['align-content', 'flex-line-pack']
AlignContent.oldValues = {
'flex-end': 'end',
'flex-start': 'start',
'space-around': 'distribute',
'space-between': 'justify'
'space-between': 'justify',
'space-around': 'distribute'
}
module.exports = AlignContent

View File

@@ -1,14 +1,7 @@
let Declaration = require('../declaration')
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
*/
@@ -24,6 +17,13 @@ class AlignItems extends Declaration {
return super.prefixed(prop, prefix)
}
/**
* Return property name by final spec
*/
normalize() {
return 'align-items'
}
/**
* Change value for 2009 and 2012 specs
*/

View File

@@ -1,5 +1,5 @@
let Declaration = require('../declaration')
let flexSpec = require('./flex-spec')
let Declaration = require('../declaration')
class AlignSelf extends Declaration {
check(decl) {
@@ -11,13 +11,6 @@ class AlignSelf extends Declaration {
)
}
/**
* Return property name by final spec
*/
normalize() {
return 'align-self'
}
/**
* Change property name for 2012 specs
*/
@@ -30,6 +23,13 @@ class AlignSelf extends Declaration {
return super.prefixed(prop, prefix)
}
/**
* Return property name by final spec
*/
normalize() {
return 'align-self'
}
/**
* Change value for 2012 spec and ignore prefix for 2009
*/

View File

@@ -1,16 +1,6 @@
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-
*/
@@ -20,6 +10,16 @@ class BlockLogical extends Declaration {
}
return prefix + prop.replace('-block-end', '-after')
}
/**
* Return property name by spec
*/
normalize(prop) {
if (prop.includes('-before')) {
return prop.replace('-before', '-block-start')
}
return prop.replace('-after', '-block-end')
}
}
BlockLogical.names = [

View File

@@ -1,13 +1,6 @@
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
*/
@@ -17,6 +10,13 @@ class BorderRadius extends Declaration {
}
return super.prefixed(prop, prefix)
}
/**
* Return unprefixed version of property
*/
normalize(prop) {
return BorderRadius.toNormal[prop] || prop
}
}
BorderRadius.names = ['border-radius']

View File

@@ -2,16 +2,10 @@ let Declaration = require('../declaration')
class BreakProps extends Declaration {
/**
* Dont prefix some values
* Change name for -webkit- and -moz- prefix
*/
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)
prefixed(prop, prefix) {
return `${prefix}column-${prop}`
}
/**
@@ -27,13 +21,6 @@ class BreakProps extends Declaration {
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
*/
@@ -46,6 +33,19 @@ class BreakProps extends Declaration {
}
return super.set(decl, prefix)
}
/**
* Dont 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)
}
}
BreakProps.names = [

View File

@@ -1,6 +1,6 @@
let flexSpec = require('./flex-spec')
let OldValue = require('../old-value')
let Value = require('../value')
let flexSpec = require('./flex-spec')
class DisplayFlex extends Value {
constructor(name, prefixes) {
@@ -17,15 +17,6 @@ class DisplayFlex extends Value {
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
*/
@@ -58,6 +49,15 @@ class DisplayFlex extends Value {
replace(string, prefix) {
return this.prefixed(prefix)
}
/**
* Change value for old specs
*/
old(prefix) {
let prefixed = this.prefixed(prefix)
if (!prefixed) return undefined
return new OldValue(this.name, prefixed)
}
}
DisplayFlex.names = ['display-flex', 'inline-flex']

View File

@@ -1,5 +1,5 @@
let Declaration = require('../declaration')
let flexSpec = require('./flex-spec')
let Declaration = require('../declaration')
class FlexBasis extends Declaration {
/**

View File

@@ -1,7 +1,14 @@
let Declaration = require('../declaration')
let flexSpec = require('./flex-spec')
let Declaration = require('../declaration')
class FlexDirection extends Declaration {
/**
* Return property name by final spec
*/
normalize() {
return 'flex-direction'
}
/**
* Use two properties for 2009 spec
*/
@@ -20,7 +27,7 @@ class FlexDirection extends Declaration {
}
let v = decl.value
let dir, orient
let orient, dir
if (v === 'inherit' || v === 'initial' || v === 'unset') {
orient = v
dir = v
@@ -46,13 +53,6 @@ class FlexDirection extends Declaration {
return decl.parent.insertBefore(decl, cloned)
}
/**
* Return property name by final spec
*/
normalize() {
return 'flex-direction'
}
/**
* Clean two properties for 2009 spec
*/

View File

@@ -1,5 +1,5 @@
let Declaration = require('../declaration')
let flexSpec = require('./flex-spec')
let Declaration = require('../declaration')
class FlexFlow extends Declaration {
/**

View File

@@ -1,5 +1,5 @@
let Declaration = require('../declaration')
let flexSpec = require('./flex-spec')
let Declaration = require('../declaration')
class Flex extends Declaration {
/**

View File

@@ -1,5 +1,5 @@
let Declaration = require('../declaration')
let flexSpec = require('./flex-spec')
let Declaration = require('../declaration')
class FlexShrink extends Declaration {
/**

View File

@@ -1,5 +1,5 @@
let Declaration = require('../declaration')
let flexSpec = require('./flex-spec')
let Declaration = require('../declaration')
class FlexWrap extends Declaration {
/**

View File

@@ -1,16 +1,9 @@
let list = require('postcss').list
let Declaration = require('../declaration')
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
*/
@@ -23,6 +16,13 @@ class Flex extends Declaration {
return super.prefixed(prop, prefix)
}
/**
* Return property name by final spec
*/
normalize() {
return 'flex'
}
/**
* Spec 2009 supports only first argument
* Spec 2012 disallows unitless basis

View File

@@ -1,219 +1,57 @@
let range = require('normalize-range')
let parser = require('postcss-value-parser')
let range = require('normalize-range')
let OldValue = require('../old-value')
let utils = require('../utils')
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
* Change degrees for webkit prefix
*/
add(decl, prefix) {
let p = decl.prop
if (p.includes('mask')) {
if (prefix === '-webkit-' || prefix === '-webkit- old') {
return super.add(decl, 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
}
}
} 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
return ast.toString()
}
/**
* Get div token from exists parameters
* Replace first token
*/
cloneDiv(params) {
for (let i of params) {
if (i.type === 'div' && i.value === ',') {
return i
replaceFirst(params, ...words) {
let prefix = words.map(i => {
if (i === ' ') {
return { type: 'space', value: i }
}
}
return { after: ' ', type: 'div', value: ',' }
return { type: 'word', value: i }
})
return prefix.concat(params.slice(1))
}
/**
* Change colors syntax to old webkit
* Convert angle unit to deg
*/
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
normalizeUnit(str, full) {
let num = parseFloat(str)
let deg = (num / full) * 360
return `${deg}deg`
}
/**
@@ -257,66 +95,146 @@ class Gradient extends Value {
}
/**
* Convert angle unit to deg
* Replace old direction to new
*/
normalizeUnit(str, full) {
let num = parseFloat(str)
let deg = (num / full) * 360
return `${deg}deg`
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
}
/**
* Remove old WebKit gradient too
* Look for at word
*/
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'
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 {
type = 'radial'
state = 'before'
}
let string = '-gradient'
let regexp = utils.regexp(
`-webkit-(${type}-gradient|gradient\\(\\s*${type})`,
false
)
}
return false
}
return new OldValue(this.name, prefix + this.name, string, regexp)
} else {
return super.old(prefix)
/**
* 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
}
/**
* 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)
}
}
}
/**
* Change direction syntax to old webkit
* Add 90 degrees
*/
oldDirection(params) {
let div = this.cloneDiv(params[0])
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`
}
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())
}
/**
* 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)
}
words = words.join(' ')
let old = Gradient.oldDirections[words] || words
params[0] = [{ type: 'word', value: old }, div]
return params[0]
}
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)
}
revertDirection(word) {
return Gradient.directions[word.toLowerCase()] || word
}
/**
* Round float and save digits under dot
*/
roundFloat(float, digits) {
return parseFloat(float.toFixed(digits))
}
/**
@@ -366,51 +284,133 @@ class Gradient extends Value {
}
/**
* Change degrees for webkit prefix
* Change direction syntax to old webkit
*/
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
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]
}
return ast.toString()
}
/**
* Replace first token
* Get div token from exists parameters
*/
replaceFirst(params, ...words) {
let prefix = words.map(i => {
if (i === ' ') {
return { type: 'space', value: i }
cloneDiv(params) {
for (let i of params) {
if (i.type === 'div' && i.value === ',') {
return i
}
return { type: 'word', value: i }
})
return prefix.concat(params.slice(1))
}
revertDirection(word) {
return Gradient.directions[word.toLowerCase()] || word
}
return { type: 'div', value: ',', after: ' ' }
}
/**
* Round float and save digits under dot
* Change colors syntax to old webkit
*/
roundFloat(float, digits) {
return parseFloat(float.toFixed(digits))
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
}
/**
* 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)
}
}
/**
* 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
}
}
@@ -422,27 +422,27 @@ Gradient.names = [
]
Gradient.directions = {
bottom: 'top',
top: 'bottom', // default value
left: 'right',
right: 'left',
top: 'bottom' // default value
bottom: 'top',
right: 'left'
}
// 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',
'left': 'right top, left top',
'bottom': 'left top, left bottom',
'right': 'left top, right top',
'top right': 'left bottom, right top',
'top left': 'right bottom, left top',
'top right': 'left bottom, right top'
'right top': 'left bottom, right top',
'right bottom': 'left top, right bottom',
'bottom right': 'left top, right bottom',
'bottom left': 'right top, left bottom',
'left top': 'right bottom, left top',
'left bottom': 'right top, left bottom'
}
module.exports = Gradient

View File

@@ -8,19 +8,19 @@ class GridColumnAlign extends Declaration {
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'
}
/**
* Change IE property back
*/
normalize() {
return 'justify-self'
}
}
GridColumnAlign.names = ['grid-column-align']

View File

@@ -8,19 +8,19 @@ class GridRowAlign extends Declaration {
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'
}
/**
* Change IE property back
*/
normalize() {
return 'align-self'
}
}
GridRowAlign.names = ['grid-row-align']

View File

@@ -1,14 +1,31 @@
let Declaration = require('../declaration')
let Processor = require('../processor')
let {
prefixTrackProp,
prefixTrackValue,
autoplaceGridItems,
getGridGap,
inheritGridGap,
prefixTrackProp,
prefixTrackValue
inheritGridGap
} = require('./grid-utils')
let Processor = require('../processor')
class GridRowsColumns extends Declaration {
/**
* Change property name for IE
*/
prefixed(prop, prefix) {
if (prefix === '-ms-') {
return prefixTrackProp({ prop, prefix })
}
return super.prefixed(prop, prefix)
}
/**
* Change IE property back
*/
normalize(prop) {
return prop.replace(/^grid-(rows|columns)/, 'grid-template-$1')
}
insert(decl, prefix, prefixes, result) {
if (prefix !== '-ms-') return super.insert(decl, prefix, prefixes)
@@ -39,15 +56,15 @@ class GridRowsColumns extends Declaration {
}
let prefixValue = prefixTrackValue({
gap: gapValue,
value
value,
gap: gapValue
})
/**
* Insert prefixes
*/
decl.cloneBefore({
prop: prefixTrackProp({ prefix, prop }),
prop: prefixTrackProp({ prop, prefix }),
value: prefixValue
})
@@ -96,23 +113,6 @@ class GridRowsColumns extends Declaration {
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 = [

View File

@@ -1,12 +1,12 @@
let Declaration = require('../declaration')
let {
getGridGap,
inheritGridGap,
parseGridAreas,
warnMissedAreas,
prefixTrackProp,
prefixTrackValue,
getGridGap,
warnGridGap,
warnMissedAreas
inheritGridGap
} = require('./grid-utils')
function getGridRows(tpl) {
@@ -39,8 +39,8 @@ class GridTemplateAreas extends Declaration {
hasRows = true
let { prop, value } = trackDecl
trackDecl.cloneBefore({
prop: prefixTrackProp({ prefix, prop }),
value: prefixTrackValue({ gap: gap.row, value })
prop: prefixTrackProp({ prop, prefix }),
value: prefixTrackValue({ value, gap: gap.row })
})
} else {
hasColumns = true
@@ -52,25 +52,25 @@ class GridTemplateAreas extends Declaration {
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)`
})
value: `repeat(${gridRows.length}, auto)`,
gap: gap.row
}),
raws: {}
})
}
// warnings
warnGridGap({
decl,
gap,
hasColumns,
decl,
result
})
let areas = parseGridAreas({
gap,
rows: gridRows
rows: gridRows,
gap
})
warnMissedAreas(areas, decl, result)

View File

@@ -1,10 +1,10 @@
let Declaration = require('../declaration')
let {
getGridGap,
inheritGridGap,
parseTemplate,
warnMissedAreas,
getGridGap,
warnGridGap,
warnMissedAreas
inheritGridGap
} = require('./grid-utils')
class GridTemplate extends Declaration {
@@ -26,7 +26,7 @@ class GridTemplate extends Declaration {
*/
let inheritedGap = inheritGridGap(decl, gap)
let { areas, columns, rows } = parseTemplate({
let { rows, columns, areas } = parseTemplate({
decl,
gap: inheritedGap || gap
})
@@ -36,9 +36,9 @@ class GridTemplate extends Declaration {
let hasColumns = Boolean(columns)
warnGridGap({
decl,
gap,
hasColumns,
decl,
result
})
@@ -47,16 +47,16 @@ class GridTemplate extends Declaration {
if ((hasRows && hasColumns) || hasAreas) {
decl.cloneBefore({
prop: '-ms-grid-rows',
raws: {},
value: rows
value: rows,
raws: {}
})
}
if (hasColumns) {
decl.cloneBefore({
prop: '-ms-grid-columns',
raws: {},
value: columns
value: columns,
raws: {}
})
}

View File

@@ -90,7 +90,7 @@ function insertDecl(decl, prop, value) {
exports.prefixTrackProp = prefixTrackProp
function prefixTrackProp({ prefix, prop }) {
function prefixTrackProp({ prop, prefix }) {
return prefix + prop.replace('template-', '')
}
@@ -105,9 +105,9 @@ function transformRepeat({ nodes }, { gap }) {
return result
},
{
count: [],
key: 'count',
size: []
size: [],
count: []
}
)
@@ -132,7 +132,7 @@ function transformRepeat({ nodes }, { gap }) {
exports.prefixTrackValue = prefixTrackValue
function prefixTrackValue({ gap, value }) {
function prefixTrackValue({ value, gap }) {
let result = parser(value).nodes.reduce((nodes, node) => {
if (node.type === 'function' && node.value === 'repeat') {
return nodes.concat({
@@ -164,7 +164,7 @@ function prefixTrackValue({ gap, value }) {
let DOTS = /^\.+$/
function track(start, end) {
return { end, span: end - start, start }
return { start, end, span: end - start }
}
function getColumns(line) {
@@ -173,7 +173,7 @@ function getColumns(line) {
exports.parseGridAreas = parseGridAreas
function parseGridAreas({ gap, rows }) {
function parseGridAreas({ rows, gap }) {
return rows.reduce((areas, line, rowIndex) => {
if (gap.row) rowIndex *= 2
@@ -248,25 +248,25 @@ function parseTemplate({ decl, gap }) {
return result
},
{
areas: [],
columns: [],
key: 'rows',
rows: []
columns: [],
rows: [],
areas: []
}
)
return {
areas: parseGridAreas({
gap,
rows: gridTemplate.areas
rows: gridTemplate.areas,
gap
}),
columns: prefixTrackValue({
gap: gap.column,
value: gridTemplate.columns.join(' ')
value: gridTemplate.columns.join(' '),
gap: gap.column
}),
rows: prefixTrackValue({
gap: gap.row,
value: gridTemplate.rows.join(' ')
value: gridTemplate.rows.join(' '),
gap: gap.row
})
}
}
@@ -429,12 +429,12 @@ function parseGridTemplatesData(css) {
parsed[index].allAreas = uniq([...allAreas, ...areaNames])
parsed[index].rules.push({
areas,
duplicateAreaNames,
hasDuplicates: !hasNoDuplicates,
node: rule,
params: media.params,
selectors: rule.selectors
selectors: rule.selectors,
node: rule,
duplicateAreaNames,
areas
})
} else {
// index is NOT found, push the new item to the parsed array
@@ -443,13 +443,13 @@ function parseGridTemplatesData(css) {
areasCount: 0,
rules: [
{
areas,
duplicateAreaNames: [],
duplicateRules: [],
hasDuplicates: false,
node: rule,
duplicateRules: [],
params: media.params,
selectors: rule.selectors
selectors: rule.selectors,
node: rule,
duplicateAreaNames: [],
areas
}
]
})
@@ -993,7 +993,7 @@ function inheritGridGap(decl, gap) {
exports.warnGridGap = warnGridGap
function warnGridGap({ decl, gap, hasColumns, result }) {
function warnGridGap({ gap, hasColumns, decl, result }) {
let hasBothGaps = gap.row && gap.column
if (!hasColumns && (hasBothGaps || (gap.column && !gap.row))) {
delete gap.column
@@ -1079,7 +1079,7 @@ function autoplaceGridItems(decl, result, gap, autoflowValue = 'row') {
).join(' ')
})
let areas = parseGridAreas({ gap, rows: filledRows })
let areas = parseGridAreas({ rows: filledRows, gap })
let keys = Object.keys(areas)
let items = keys.map(i => areas[i])

View File

@@ -8,13 +8,6 @@ class ImageRendering extends Declaration {
return decl.value === 'pixelated'
}
/**
* Return property name by spec
*/
normalize() {
return 'image-rendering'
}
/**
* Change property name for IE
*/
@@ -25,13 +18,6 @@ class ImageRendering extends Declaration {
return super.prefixed(prop, prefix)
}
/**
* Warn on old value
*/
process(node, result) {
return super.process(node, result)
}
/**
* Change property and value for IE
*/
@@ -41,6 +27,20 @@ class ImageRendering extends Declaration {
decl.value = 'nearest-neighbor'
return decl
}
/**
* Return property name by spec
*/
normalize() {
return 'image-rendering'
}
/**
* Warn on old value
*/
process(node, result) {
return super.process(node, result)
}
}
ImageRendering.names = ['image-rendering', 'interpolation-mode']

View File

@@ -1,19 +1,19 @@
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', '')
}
/**
* Return property name by spec
*/
normalize(prop) {
return prop.replace(/(margin|padding|border)-(start|end)/, '$1-inline-$2')
}
}
InlineLogical.names = [

View File

@@ -6,11 +6,9 @@ function regexp(name) {
}
class Intrinsic extends Value {
add(decl, prefix) {
if (decl.prop.includes('grid') && prefix !== '-webkit-') {
return undefined
}
return super.add(decl, prefix)
regexp() {
if (!this.regexpCache) this.regexpCache = regexp(this.name)
return this.regexpCache
}
isStretch() {
@@ -21,6 +19,16 @@ class Intrinsic extends Value {
)
}
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)
}
old(prefix) {
let prefixed = prefix + this.name
if (this.isStretch()) {
@@ -33,19 +41,11 @@ class Intrinsic extends Value {
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')
add(decl, prefix) {
if (decl.prop.includes('grid') && prefix !== '-webkit-') {
return undefined
}
if (prefix === '-webkit-' && this.isStretch()) {
return string.replace(this.regexp(), '$1-webkit-fill-available$3')
}
return super.replace(string, prefix)
return super.add(decl, prefix)
}
}

View File

@@ -1,14 +1,7 @@
let Declaration = require('../declaration')
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
*/
@@ -24,6 +17,13 @@ class JustifyContent extends Declaration {
return super.prefixed(prop, prefix)
}
/**
* Return property name by final spec
*/
normalize() {
return 'justify-content'
}
/**
* Change value for 2009 and 2012 specs
*/
@@ -47,8 +47,8 @@ JustifyContent.names = ['justify-content', 'flex-pack', 'box-pack']
JustifyContent.oldValues = {
'flex-end': 'end',
'flex-start': 'start',
'space-around': 'distribute',
'space-between': 'justify'
'space-between': 'justify',
'space-around': 'distribute'
}
module.exports = JustifyContent

View File

@@ -73,9 +73,9 @@ MaskComposite.names = ['mask', 'mask-composite']
MaskComposite.oldValues = {
add: 'source-over',
exclude: 'xor',
subtract: 'source-out',
intersect: 'source-in',
subtract: 'source-out'
exclude: 'xor'
}
MaskComposite.regexp = new RegExp(

View File

@@ -1,14 +1,7 @@
let Declaration = require('../declaration')
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
*/
@@ -24,6 +17,13 @@ class Order extends Declaration {
return super.prefixed(prop, prefix)
}
/**
* Return property name by final spec
*/
normalize() {
return 'order'
}
/**
* Fix value for 2009 spec
*/

View File

@@ -1,13 +1,6 @@
let Declaration = require('../declaration')
class OverscrollBehavior extends Declaration {
/**
* Return property name by spec
*/
normalize() {
return 'overscroll-behavior'
}
/**
* Change property name for IE
*/
@@ -15,6 +8,13 @@ class OverscrollBehavior extends Declaration {
return prefix + 'scroll-chaining'
}
/**
* Return property name by spec
*/
normalize() {
return 'overscroll-behavior'
}
/**
* Change value for IE
*/

View File

@@ -2,19 +2,6 @@ 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
*/
@@ -27,6 +14,19 @@ class Pixelated extends Value {
}
return super.replace(string, prefix)
}
/**
* 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)
}
}
Pixelated.names = ['pixelated']

View File

@@ -5,9 +5,7 @@ class PlaceholderShown extends Selector {
* Return different selectors depend on prefix
*/
prefixed(prefix) {
if (prefix === '-moz-') {
return ':-moz-placeholder'
} else if (prefix === '-ms-') {
if (prefix === '-ms-') {
return ':-ms-input-placeholder'
}
return `:${prefix}placeholder-shown`

View File

@@ -1,13 +1,6 @@
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
*/
@@ -18,6 +11,13 @@ class PrintColorAdjust extends Declaration {
return prefix + 'print-color-adjust'
}
}
/**
* Return property name by spec
*/
normalize() {
return 'print-color-adjust'
}
}
PrintColorAdjust.names = ['print-color-adjust', 'color-adjust']

View File

@@ -1,6 +1,20 @@
let Declaration = require('../declaration')
class TransformDecl extends Declaration {
/**
* 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
}
/**
* Is transform contain 3D commands
*/
@@ -18,6 +32,17 @@ class TransformDecl extends Declaration {
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
}
/**
* Don't add prefix for IE in keyframes
*/
@@ -35,31 +60,6 @@ class TransformDecl extends Declaration {
}
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']

View File

@@ -1,22 +1,6 @@
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 if (
decl.value === 'contain' &&
(prefix === '-moz-' || prefix === '-webkit-')
) {
return undefined
} else {
return super.insert(decl, prefix, prefixes)
}
}
/**
* Change prefixed value for IE
*/
@@ -26,6 +10,17 @@ class UserSelect extends Declaration {
}
return super.set(decl, prefix)
}
/**
* Avoid prefixing all in IE
*/
insert(decl, prefix, prefixes) {
if (decl.value === 'all' && prefix === '-ms-') {
return undefined
} else {
return super.insert(decl, prefix, prefixes)
}
}
}
UserSelect.names = ['user-select']

View File

@@ -29,13 +29,13 @@ WritingMode.names = ['writing-mode']
WritingMode.msValues = {
ltr: {
'horizontal-tb': 'lr-tb',
'vertical-lr': 'tb-lr',
'vertical-rl': 'tb-rl'
'vertical-rl': 'tb-rl',
'vertical-lr': 'tb-lr'
},
rtl: {
'horizontal-tb': 'rl-tb',
'vertical-lr': 'bt-lr',
'vertical-rl': 'bt-rl'
'vertical-rl': 'bt-rl',
'vertical-lr': 'bt-lr'
}
}