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 FlexFlow 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 values = decl.value
|
|
|
|
.split(/\s+/)
|
|
|
|
.filter(i => i !== 'wrap' && i !== 'nowrap' && 'wrap-reverse')
|
2022-01-21 08:28:41 +00:00
|
|
|
if (values.length === 0) {
|
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 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 value = values[0]
|
|
|
|
let orient = value.includes('row') ? 'horizontal' : 'vertical'
|
|
|
|
let dir = value.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
|
|
|
FlexFlow.names = ['flex-flow', 'box-direction', 'box-orient']
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
module.exports = FlexFlow
|