wishthis/node_modules/autoprefixer/lib/hacks/display-flex.js

66 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-08-17 09:47:40 +00:00
let flexSpec = require('./flex-spec')
let OldValue = require('../old-value')
let Value = require('../value')
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
class DisplayFlex extends Value {
constructor(name, prefixes) {
super(name, prefixes)
2022-01-21 08:28:41 +00:00
if (name === 'display-flex') {
2023-08-17 09:47:40 +00:00
this.name = 'flex'
2022-01-21 08:28:41 +00:00
}
}
2023-08-17 09:47:40 +00:00
2022-01-21 08:28:41 +00:00
/**
* Faster check for flex value
*/
2023-08-17 09:47:40 +00:00
check(decl) {
return decl.prop === 'display' && decl.value === this.name
}
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
/**
* Change value for old specs
*/
old(prefix) {
let prefixed = this.prefixed(prefix)
if (!prefixed) return undefined
return new OldValue(this.name, prefixed)
2022-01-21 08:28:41 +00:00
}
2023-08-17 09:47:40 +00:00
2022-01-21 08:28:41 +00:00
/**
* Return value by spec
*/
2023-08-17 09:47:40 +00:00
prefixed(prefix) {
let spec, value
;[spec, prefix] = flexSpec(prefix)
2022-01-21 08:28:41 +00:00
if (spec === 2009) {
if (this.name === 'flex') {
2023-08-17 09:47:40 +00:00
value = 'box'
2022-01-21 08:28:41 +00:00
} else {
2023-08-17 09:47:40 +00:00
value = 'inline-box'
2022-01-21 08:28:41 +00:00
}
} else if (spec === 2012) {
if (this.name === 'flex') {
2023-08-17 09:47:40 +00:00
value = 'flexbox'
2022-01-21 08:28:41 +00:00
} else {
2023-08-17 09:47:40 +00:00
value = 'inline-flexbox'
2022-01-21 08:28:41 +00:00
}
} else if (spec === 'final') {
2023-08-17 09:47:40 +00:00
value = this.name
2022-01-21 08:28:41 +00:00
}
2023-08-17 09:47:40 +00:00
return prefix + value
2022-01-21 08:28:41 +00:00
}
2023-08-17 09:47:40 +00:00
2022-01-21 08:28:41 +00:00
/**
* Add prefix to value depend on flebox spec version
*/
2023-08-17 09:47:40 +00:00
replace(string, prefix) {
return this.prefixed(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
DisplayFlex.names = ['display-flex', 'inline-flex']
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
module.exports = DisplayFlex