| 1 |
let list = require('postcss').list |
| 2 |
|
| 3 |
let Declaration = require('../declaration') |
| 4 |
let flexSpec = require('./flex-spec') |
| 5 |
|
| 6 |
class Flex extends Declaration { |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
normalize() { |
| 11 |
return 'flex' |
| 12 |
} |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
prefixed(prop, prefix) { |
| 18 |
let spec |
| 19 |
;[spec, prefix] = flexSpec(prefix) |
| 20 |
if (spec === 2009) { |
| 21 |
return prefix + 'box-flex' |
| 22 |
} |
| 23 |
return super.prefixed(prop, prefix) |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
set(decl, prefix) { |
| 31 |
let spec = flexSpec(prefix)[0] |
| 32 |
if (spec === 2009) { |
| 33 |
decl.value = list.space(decl.value)[0] |
| 34 |
decl.value = Flex.oldValues[decl.value] || decl.value |
| 35 |
return super.set(decl, prefix) |
| 36 |
} |
| 37 |
if (spec === 2012) { |
| 38 |
let components = list.space(decl.value) |
| 39 |
if (components.length === 3 && components[2] === '0') { |
| 40 |
decl.value = components.slice(0, 2).concat('0px').join(' ') |
| 41 |
} |
| 42 |
} |
| 43 |
return super.set(decl, prefix) |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
Flex.names = ['flex', 'box-flex'] |
| 48 |
|
| 49 |
Flex.oldValues = { |
| 50 |
auto: '1', |
| 51 |
none: '0' |
| 52 |
} |
| 53 |
|
| 54 |
module.exports = Flex |