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 TransformDecl extends Declaration {
|
2022-01-21 08:28:41 +00:00
|
|
|
/**
|
|
|
|
* Is transform contain 3D commands
|
|
|
|
*/
|
2023-08-17 09:47:40 +00:00
|
|
|
contain3d(decl) {
|
2022-01-21 08:28:41 +00:00
|
|
|
if (decl.prop === 'transform-origin') {
|
2023-08-17 09:47:40 +00:00
|
|
|
return false
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
for (let func of TransformDecl.functions3d) {
|
|
|
|
if (decl.value.includes(`${func}(`)) {
|
|
|
|
return true
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
return false
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Don't add prefix for IE in keyframes
|
|
|
|
*/
|
2023-08-17 09:47:40 +00:00
|
|
|
insert(decl, prefix, prefixes) {
|
2022-01-21 08:28:41 +00:00
|
|
|
if (prefix === '-ms-') {
|
|
|
|
if (!this.contain3d(decl) && !this.keyframeParents(decl)) {
|
2023-08-17 09:47:40 +00:00
|
|
|
return super.insert(decl, prefix, prefixes)
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
} else if (prefix === '-o-') {
|
|
|
|
if (!this.contain3d(decl)) {
|
2023-08-17 09:47:40 +00:00
|
|
|
return super.insert(decl, prefix, prefixes)
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
} else {
|
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
|
|
|
return undefined
|
|
|
|
}
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
/**
|
|
|
|
* Recursively check all parents for @keyframes
|
|
|
|
*/
|
|
|
|
keyframeParents(decl) {
|
|
|
|
let { parent } = decl
|
|
|
|
while (parent) {
|
|
|
|
if (parent.type === 'atrule' && parent.name === 'keyframes') {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
;({ parent } = parent)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
/**
|
|
|
|
* Replace rotateZ to rotate for IE 9
|
|
|
|
*/
|
|
|
|
set(decl, prefix) {
|
|
|
|
decl = super.set(decl, prefix)
|
|
|
|
if (prefix === '-ms-') {
|
|
|
|
decl.value = decl.value.replace(/rotatez/gi, 'rotate')
|
|
|
|
}
|
|
|
|
return decl
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TransformDecl.names = ['transform', 'transform-origin']
|
|
|
|
|
|
|
|
TransformDecl.functions3d = [
|
|
|
|
'matrix3d',
|
|
|
|
'translate3d',
|
|
|
|
'translateZ',
|
|
|
|
'scale3d',
|
|
|
|
'scaleZ',
|
|
|
|
'rotate3d',
|
|
|
|
'rotateX',
|
|
|
|
'rotateY',
|
|
|
|
'perspective'
|
|
|
|
]
|
|
|
|
|
|
|
|
module.exports = TransformDecl
|