| 1 | let Declaration = require('../declaration')
|
|---|
| 2 |
|
|---|
| 3 | class TransformDecl extends Declaration {
|
|---|
| 4 | /**
|
|---|
| 5 | * Is transform contain 3D commands
|
|---|
| 6 | */
|
|---|
| 7 | contain3d(decl) {
|
|---|
| 8 | if (decl.prop === 'transform-origin') {
|
|---|
| 9 | return false
|
|---|
| 10 | }
|
|---|
| 11 |
|
|---|
| 12 | for (let func of TransformDecl.functions3d) {
|
|---|
| 13 | if (decl.value.includes(`${func}(`)) {
|
|---|
| 14 | return true
|
|---|
| 15 | }
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | return false
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | /**
|
|---|
| 22 | * Don't add prefix for IE in keyframes
|
|---|
| 23 | */
|
|---|
| 24 | insert(decl, prefix, prefixes) {
|
|---|
| 25 | if (prefix === '-ms-') {
|
|---|
| 26 | if (!this.contain3d(decl) && !this.keyframeParents(decl)) {
|
|---|
| 27 | return super.insert(decl, prefix, prefixes)
|
|---|
| 28 | }
|
|---|
| 29 | } else if (prefix === '-o-') {
|
|---|
| 30 | if (!this.contain3d(decl)) {
|
|---|
| 31 | return super.insert(decl, prefix, prefixes)
|
|---|
| 32 | }
|
|---|
| 33 | } else {
|
|---|
| 34 | return super.insert(decl, prefix, prefixes)
|
|---|
| 35 | }
|
|---|
| 36 | return undefined
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | /**
|
|---|
| 40 | * Recursively check all parents for @keyframes
|
|---|
| 41 | */
|
|---|
| 42 | keyframeParents(decl) {
|
|---|
| 43 | let { parent } = decl
|
|---|
| 44 | while (parent) {
|
|---|
| 45 | if (parent.type === 'atrule' && parent.name === 'keyframes') {
|
|---|
| 46 | return true
|
|---|
| 47 | }
|
|---|
| 48 | ;({ parent } = parent)
|
|---|
| 49 | }
|
|---|
| 50 | return false
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | /**
|
|---|
| 54 | * Replace rotateZ to rotate for IE 9
|
|---|
| 55 | */
|
|---|
| 56 | set(decl, prefix) {
|
|---|
| 57 | decl = super.set(decl, prefix)
|
|---|
| 58 | if (prefix === '-ms-') {
|
|---|
| 59 | decl.value = decl.value.replace(/rotatez/gi, 'rotate')
|
|---|
| 60 | }
|
|---|
| 61 | return decl
|
|---|
| 62 | }
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | TransformDecl.names = ['transform', 'transform-origin']
|
|---|
| 66 |
|
|---|
| 67 | TransformDecl.functions3d = [
|
|---|
| 68 | 'matrix3d',
|
|---|
| 69 | 'translate3d',
|
|---|
| 70 | 'translateZ',
|
|---|
| 71 | 'scale3d',
|
|---|
| 72 | 'scaleZ',
|
|---|
| 73 | 'rotate3d',
|
|---|
| 74 | 'rotateX',
|
|---|
| 75 | 'rotateY',
|
|---|
| 76 | 'perspective'
|
|---|
| 77 | ]
|
|---|
| 78 |
|
|---|
| 79 | module.exports = TransformDecl
|
|---|