2023-08-17 09:47:40 +00:00
|
|
|
let list = require('postcss').list
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
let flexSpec = require('./flex-spec')
|
|
|
|
let Declaration = require('../declaration')
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
class Flex extends Declaration {
|
|
|
|
/**
|
|
|
|
* Return property name by final spec
|
|
|
|
*/
|
|
|
|
normalize() {
|
|
|
|
return 'flex'
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change property name for 2009 spec
|
|
|
|
*/
|
2023-08-17 09:47:40 +00:00
|
|
|
prefixed(prop, prefix) {
|
|
|
|
let spec
|
|
|
|
;[spec, prefix] = flexSpec(prefix)
|
2022-01-21 08:28:41 +00:00
|
|
|
if (spec === 2009) {
|
2023-08-17 09:47:40 +00:00
|
|
|
return prefix + 'box-flex'
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
2023-08-17 09:47:40 +00:00
|
|
|
return super.prefixed(prop, prefix)
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Spec 2009 supports only first argument
|
|
|
|
* Spec 2012 disallows unitless basis
|
|
|
|
*/
|
2023-08-17 09:47:40 +00:00
|
|
|
set(decl, prefix) {
|
|
|
|
let spec = flexSpec(prefix)[0]
|
2022-01-21 08:28:41 +00:00
|
|
|
if (spec === 2009) {
|
2023-08-17 09:47:40 +00:00
|
|
|
decl.value = list.space(decl.value)[0]
|
|
|
|
decl.value = Flex.oldValues[decl.value] || decl.value
|
|
|
|
return super.set(decl, prefix)
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
if (spec === 2012) {
|
2023-08-17 09:47:40 +00:00
|
|
|
let components = list.space(decl.value)
|
2022-01-21 08:28:41 +00:00
|
|
|
if (components.length === 3 && components[2] === '0') {
|
2023-08-17 09:47:40 +00:00
|
|
|
decl.value = components.slice(0, 2).concat('0px').join(' ')
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-17 09:47:40 +00:00
|
|
|
return super.set(decl, prefix)
|
|
|
|
}
|
|
|
|
}
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
Flex.names = ['flex', 'box-flex']
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
Flex.oldValues = {
|
2022-01-21 08:28:41 +00:00
|
|
|
auto: '1',
|
|
|
|
none: '0'
|
2023-08-17 09:47:40 +00:00
|
|
|
}
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
module.exports = Flex
|