wishthis/node_modules/autoprefixer/lib/hacks/break-props.js

64 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-08-17 09:47:40 +00:00
let Declaration = require('../declaration')
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
class BreakProps extends Declaration {
2022-01-21 08:28:41 +00:00
/**
2023-08-17 09:47:40 +00:00
* Dont prefix some values
2022-01-21 08:28:41 +00:00
*/
2023-08-17 09:47:40 +00:00
insert(decl, prefix, prefixes) {
if (decl.prop !== 'break-inside') {
return super.insert(decl, prefix, prefixes)
}
if (/region/i.test(decl.value) || /page/i.test(decl.value)) {
return undefined
}
return super.insert(decl, prefix, prefixes)
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 property name by final spec
*/
2023-08-17 09:47:40 +00:00
normalize(prop) {
2022-01-21 08:28:41 +00:00
if (prop.includes('inside')) {
2023-08-17 09:47:40 +00:00
return 'break-inside'
2022-01-21 08:28:41 +00:00
}
if (prop.includes('before')) {
2023-08-17 09:47:40 +00:00
return 'break-before'
2022-01-21 08:28:41 +00:00
}
2023-08-17 09:47:40 +00:00
return 'break-after'
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
* Change name for -webkit- and -moz- prefix
2022-01-21 08:28:41 +00:00
*/
2023-08-17 09:47:40 +00:00
prefixed(prop, prefix) {
return `${prefix}column-${prop}`
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
* Change prefixed value for avoid-column and avoid-page
2022-01-21 08:28:41 +00:00
*/
2023-08-17 09:47:40 +00:00
set(decl, prefix) {
if (
(decl.prop === 'break-inside' && decl.value === 'avoid-column') ||
decl.value === 'avoid-page'
) {
decl.value = 'avoid'
2022-01-21 08:28:41 +00:00
}
2023-08-17 09:47:40 +00:00
return super.set(decl, prefix)
}
}
BreakProps.names = [
'break-inside',
'page-break-inside',
'column-break-inside',
'break-before',
'page-break-before',
'column-break-before',
'break-after',
'page-break-after',
'column-break-after'
]
module.exports = BreakProps