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 FlexDirection extends Declaration {
|
2022-01-21 08:28:41 +00:00
|
|
|
/**
|
|
|
|
* Use two properties for 2009 spec
|
|
|
|
*/
|
2023-08-17 09:47:40 +00:00
|
|
|
insert(decl, prefix, prefixes) {
|
|
|
|
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 super.insert(decl, prefix, prefixes)
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
2023-08-17 09:47:40 +00:00
|
|
|
let already = decl.parent.some(
|
|
|
|
i =>
|
|
|
|
i.prop === prefix + 'box-orient' || i.prop === prefix + 'box-direction'
|
|
|
|
)
|
2022-01-21 08:28:41 +00:00
|
|
|
if (already) {
|
2023-08-17 09:47:40 +00:00
|
|
|
return undefined
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
let v = decl.value
|
|
|
|
let orient, dir
|
2022-01-21 08:28:41 +00:00
|
|
|
if (v === 'inherit' || v === 'initial' || v === 'unset') {
|
2023-08-17 09:47:40 +00:00
|
|
|
orient = v
|
|
|
|
dir = v
|
2022-01-21 08:28:41 +00:00
|
|
|
} else {
|
2023-08-17 09:47:40 +00:00
|
|
|
orient = v.includes('row') ? 'horizontal' : 'vertical'
|
|
|
|
dir = v.includes('reverse') ? 'reverse' : 'normal'
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
let cloned = this.clone(decl)
|
|
|
|
cloned.prop = prefix + 'box-orient'
|
|
|
|
cloned.value = orient
|
2022-01-21 08:28:41 +00:00
|
|
|
if (this.needCascade(decl)) {
|
2023-08-17 09:47:40 +00:00
|
|
|
cloned.raws.before = this.calcBefore(prefixes, decl, prefix)
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
2023-08-17 09:47:40 +00:00
|
|
|
decl.parent.insertBefore(decl, cloned)
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
cloned = this.clone(decl)
|
|
|
|
cloned.prop = prefix + 'box-direction'
|
|
|
|
cloned.value = dir
|
2022-01-21 08:28:41 +00:00
|
|
|
if (this.needCascade(decl)) {
|
2023-08-17 09:47:40 +00:00
|
|
|
cloned.raws.before = this.calcBefore(prefixes, decl, prefix)
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
2023-08-17 09:47:40 +00:00
|
|
|
return decl.parent.insertBefore(decl, cloned)
|
|
|
|
}
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
/**
|
|
|
|
* Return property name by final spec
|
|
|
|
*/
|
|
|
|
normalize() {
|
|
|
|
return 'flex-direction'
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
2023-08-17 09:47:40 +00:00
|
|
|
|
2022-01-21 08:28:41 +00:00
|
|
|
/**
|
|
|
|
* Clean two properties for 2009 spec
|
|
|
|
*/
|
2023-08-17 09:47:40 +00:00
|
|
|
old(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-orient', prefix + 'box-direction']
|
2022-01-21 08:28:41 +00:00
|
|
|
} else {
|
2023-08-17 09:47:40 +00:00
|
|
|
return super.old(prop, prefix)
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
2023-08-17 09:47:40 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
FlexDirection.names = ['flex-direction', 'box-direction', 'box-orient']
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
module.exports = FlexDirection
|