wishthis/node_modules/autoprefixer/lib/hacks/intrinsic.js

62 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-08-17 09:47:40 +00:00
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
function regexp(name) {
return new RegExp(`(^|[\\s,(])(${name}($|[\\s),]))`, 'gi')
2022-01-21 08:28:41 +00:00
}
2023-08-17 09:47:40 +00:00
class Intrinsic extends Value {
add(decl, prefix) {
if (decl.prop.includes('grid') && prefix !== '-webkit-') {
return undefined
2022-01-21 08:28:41 +00:00
}
2023-08-17 09:47:40 +00:00
return super.add(decl, prefix)
}
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
isStretch() {
return (
this.name === 'stretch' ||
this.name === 'fill' ||
this.name === 'fill-available'
)
}
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
old(prefix) {
let prefixed = prefix + this.name
2022-01-21 08:28:41 +00:00
if (this.isStretch()) {
if (prefix === '-moz-') {
2023-08-17 09:47:40 +00:00
prefixed = '-moz-available'
2022-01-21 08:28:41 +00:00
} else if (prefix === '-webkit-') {
2023-08-17 09:47:40 +00:00
prefixed = '-webkit-fill-available'
2022-01-21 08:28:41 +00:00
}
}
2023-08-17 09:47:40 +00:00
return new OldValue(this.name, prefixed, prefixed, regexp(prefixed))
}
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
regexp() {
if (!this.regexpCache) this.regexpCache = regexp(this.name)
return this.regexpCache
}
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
replace(string, prefix) {
if (prefix === '-moz-' && this.isStretch()) {
return string.replace(this.regexp(), '$1-moz-available$3')
2022-01-21 08:28:41 +00:00
}
2023-08-17 09:47:40 +00:00
if (prefix === '-webkit-' && this.isStretch()) {
return string.replace(this.regexp(), '$1-webkit-fill-available$3')
}
return super.replace(string, prefix)
}
}
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
Intrinsic.names = [
'max-content',
'min-content',
'fit-content',
'fill',
'fill-available',
'stretch'
]
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
module.exports = Intrinsic