| 1 |
let Declaration = require('../declaration') |
| 2 |
let flexSpec = require('./flex-spec') |
| 3 |
|
| 4 |
class FlexDirection extends Declaration { |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
insert(decl, prefix, prefixes) { |
| 9 |
let spec |
| 10 |
;[spec, prefix] = flexSpec(prefix) |
| 11 |
if (spec !== 2009) { |
| 12 |
return super.insert(decl, prefix, prefixes) |
| 13 |
} |
| 14 |
let already = decl.parent.some( |
| 15 |
i => |
| 16 |
i.prop === prefix + 'box-orient' || i.prop === prefix + 'box-direction' |
| 17 |
) |
| 18 |
if (already) { |
| 19 |
return undefined |
| 20 |
} |
| 21 |
|
| 22 |
let v = decl.value |
| 23 |
let dir, orient |
| 24 |
if (v === 'inherit' || v === 'initial' || v === 'unset') { |
| 25 |
orient = v |
| 26 |
dir = v |
| 27 |
} else { |
| 28 |
orient = v.includes('row') ? 'horizontal' : 'vertical' |
| 29 |
dir = v.includes('reverse') ? 'reverse' : 'normal' |
| 30 |
} |
| 31 |
|
| 32 |
let cloned = this.clone(decl) |
| 33 |
cloned.prop = prefix + 'box-orient' |
| 34 |
cloned.value = orient |
| 35 |
if (this.needCascade(decl)) { |
| 36 |
cloned.raws.before = this.calcBefore(prefixes, decl, prefix) |
| 37 |
} |
| 38 |
decl.parent.insertBefore(decl, cloned) |
| 39 |
|
| 40 |
cloned = this.clone(decl) |
| 41 |
cloned.prop = prefix + 'box-direction' |
| 42 |
cloned.value = dir |
| 43 |
if (this.needCascade(decl)) { |
| 44 |
cloned.raws.before = this.calcBefore(prefixes, decl, prefix) |
| 45 |
} |
| 46 |
return decl.parent.insertBefore(decl, cloned) |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
normalize() { |
| 53 |
return 'flex-direction' |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
old(prop, prefix) { |
| 60 |
let spec |
| 61 |
;[spec, prefix] = flexSpec(prefix) |
| 62 |
if (spec === 2009) { |
| 63 |
return [prefix + 'box-orient', prefix + 'box-direction'] |
| 64 |
} else { |
| 65 |
return super.old(prop, prefix) |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
FlexDirection.names = ['flex-direction', 'box-direction', 'box-orient'] |
| 71 |
|
| 72 |
module.exports = FlexDirection |