.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / autoprefixer / lib / hacks / transform-decl.js
1 'use strict';
2
3 function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
4
5 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
7 function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
8
9 function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
10
11 var Declaration = require('../declaration');
12
13 var TransformDecl = function (_Declaration) {
14     _inherits(TransformDecl, _Declaration);
15
16     function TransformDecl() {
17         _classCallCheck(this, TransformDecl);
18
19         return _possibleConstructorReturn(this, _Declaration.apply(this, arguments));
20     }
21
22     /**
23      * Recursively check all parents for @keyframes
24      */
25     TransformDecl.prototype.keyframeParents = function keyframeParents(decl) {
26         var parent = decl.parent;
27
28         while (parent) {
29             if (parent.type === 'atrule' && parent.name === 'keyframes') {
30                 return true;
31             }
32             var _parent = parent;
33             parent = _parent.parent;
34         }
35         return false;
36     };
37
38     /**
39      * Is transform contain 3D commands
40      */
41
42
43     TransformDecl.prototype.contain3d = function contain3d(decl) {
44         if (decl.prop === 'transform-origin') {
45             return false;
46         }
47
48         for (var _iterator = TransformDecl.functions3d, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
49             var _ref;
50
51             if (_isArray) {
52                 if (_i >= _iterator.length) break;
53                 _ref = _iterator[_i++];
54             } else {
55                 _i = _iterator.next();
56                 if (_i.done) break;
57                 _ref = _i.value;
58             }
59
60             var func = _ref;
61
62             if (decl.value.indexOf(func + '(') !== -1) {
63                 return true;
64             }
65         }
66
67         return false;
68     };
69
70     /**
71      * Replace rotateZ to rotate for IE 9
72      */
73
74
75     TransformDecl.prototype.set = function set(decl, prefix) {
76         decl = _Declaration.prototype.set.call(this, decl, prefix);
77         if (prefix === '-ms-') {
78             decl.value = decl.value.replace(/rotateZ/gi, 'rotate');
79         }
80         return decl;
81     };
82
83     /**
84      * Don't add prefix for IE in keyframes
85      */
86
87
88     TransformDecl.prototype.insert = function insert(decl, prefix, prefixes) {
89         if (prefix === '-ms-') {
90             if (!this.contain3d(decl) && !this.keyframeParents(decl)) {
91                 return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
92             }
93         } else if (prefix === '-o-') {
94             if (!this.contain3d(decl)) {
95                 return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
96             }
97         } else {
98             return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
99         }
100         return undefined;
101     };
102
103     return TransformDecl;
104 }(Declaration);
105
106 Object.defineProperty(TransformDecl, 'names', {
107     enumerable: true,
108     writable: true,
109     value: ['transform', 'transform-origin']
110 });
111 Object.defineProperty(TransformDecl, 'functions3d', {
112     enumerable: true,
113     writable: true,
114     value: ['matrix3d', 'translate3d', 'translateZ', 'scale3d', 'scaleZ', 'rotate3d', 'rotateX', 'rotateY', 'perspective']
115 });
116
117
118 module.exports = TransformDecl;