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 JustifyContent extends Declaration {
|
|
|
|
/**
|
|
|
|
* Return property name by final spec
|
|
|
|
*/
|
|
|
|
normalize() {
|
|
|
|
return 'justify-content'
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change property name for 2009 and 2012 specs
|
|
|
|
*/
|
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-pack'
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
if (spec === 2012) {
|
2023-08-17 09:47:40 +00:00
|
|
|
return prefix + 'flex-pack'
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change value for 2009 and 2012 specs
|
|
|
|
*/
|
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 || spec === 2012) {
|
2023-08-17 09:47:40 +00:00
|
|
|
let value = JustifyContent.oldValues[decl.value] || decl.value
|
|
|
|
decl.value = value
|
2022-01-21 08:28:41 +00:00
|
|
|
if (spec !== 2009 || value !== 'distribute') {
|
2023-08-17 09:47:40 +00:00
|
|
|
return super.set(decl, prefix)
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
} else if (spec === 'final') {
|
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
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
}
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
JustifyContent.names = ['justify-content', 'flex-pack', 'box-pack']
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
JustifyContent.oldValues = {
|
2022-01-21 08:28:41 +00:00
|
|
|
'flex-end': 'end',
|
|
|
|
'flex-start': 'start',
|
2023-08-17 09:47:40 +00:00
|
|
|
'space-around': 'distribute',
|
|
|
|
'space-between': 'justify'
|
|
|
|
}
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
module.exports = JustifyContent
|