wishthis/node_modules/autoprefixer/lib/hacks/writing-mode.js

43 lines
1,002 B
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 WritingMode extends Declaration {
insert(decl, prefix, prefixes) {
2022-01-21 08:28:41 +00:00
if (prefix === '-ms-') {
2023-08-17 09:47:40 +00:00
let cloned = this.set(this.clone(decl), prefix)
2022-01-21 08:28:41 +00:00
if (this.needCascade(decl)) {
2023-08-17 09:47:40 +00:00
cloned.raws.before = this.calcBefore(prefixes, decl, prefix)
2022-01-21 08:28:41 +00:00
}
2023-08-17 09:47:40 +00:00
let direction = 'ltr'
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
decl.parent.nodes.forEach(i => {
2022-01-21 08:28:41 +00:00
if (i.prop === 'direction') {
2023-08-17 09:47:40 +00:00
if (i.value === 'rtl' || i.value === 'ltr') direction = i.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
2023-08-17 09:47:40 +00:00
cloned.value = WritingMode.msValues[direction][decl.value] || decl.value
return decl.parent.insertBefore(decl, cloned)
}
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
return super.insert(decl, prefix, prefixes)
}
}
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
WritingMode.names = ['writing-mode']
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
WritingMode.msValues = {
2022-01-21 08:28:41 +00:00
ltr: {
'horizontal-tb': 'lr-tb',
2023-08-17 09:47:40 +00:00
'vertical-lr': 'tb-lr',
'vertical-rl': 'tb-rl'
2022-01-21 08:28:41 +00:00
},
rtl: {
'horizontal-tb': 'rl-tb',
2023-08-17 09:47:40 +00:00
'vertical-lr': 'bt-lr',
'vertical-rl': 'bt-rl'
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
module.exports = WritingMode