transform-decl.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. "use strict";
  2. 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; }
  3. function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } it = o[Symbol.iterator](); return it.next.bind(it); }
  4. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  5. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  6. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _defaults(subClass, superClass); }
  7. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  8. var Declaration = require('../declaration');
  9. var TransformDecl = /*#__PURE__*/function (_Declaration) {
  10. _inheritsLoose(TransformDecl, _Declaration);
  11. function TransformDecl() {
  12. return _Declaration.apply(this, arguments) || this;
  13. }
  14. var _proto = TransformDecl.prototype;
  15. /**
  16. * Recursively check all parents for @keyframes
  17. */
  18. _proto.keyframeParents = function keyframeParents(decl) {
  19. var parent = decl.parent;
  20. while (parent) {
  21. if (parent.type === 'atrule' && parent.name === 'keyframes') {
  22. return true;
  23. }
  24. var _parent = parent;
  25. parent = _parent.parent;
  26. }
  27. return false;
  28. }
  29. /**
  30. * Is transform contain 3D commands
  31. */
  32. ;
  33. _proto.contain3d = function contain3d(decl) {
  34. if (decl.prop === 'transform-origin') {
  35. return false;
  36. }
  37. for (var _iterator = _createForOfIteratorHelperLoose(TransformDecl.functions3d), _step; !(_step = _iterator()).done;) {
  38. var func = _step.value;
  39. if (decl.value.includes(func + "(")) {
  40. return true;
  41. }
  42. }
  43. return false;
  44. }
  45. /**
  46. * Replace rotateZ to rotate for IE 9
  47. */
  48. ;
  49. _proto.set = function set(decl, prefix) {
  50. decl = _Declaration.prototype.set.call(this, decl, prefix);
  51. if (prefix === '-ms-') {
  52. decl.value = decl.value.replace(/rotatez/gi, 'rotate');
  53. }
  54. return decl;
  55. }
  56. /**
  57. * Don't add prefix for IE in keyframes
  58. */
  59. ;
  60. _proto.insert = function insert(decl, prefix, prefixes) {
  61. if (prefix === '-ms-') {
  62. if (!this.contain3d(decl) && !this.keyframeParents(decl)) {
  63. return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  64. }
  65. } else if (prefix === '-o-') {
  66. if (!this.contain3d(decl)) {
  67. return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  68. }
  69. } else {
  70. return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  71. }
  72. return undefined;
  73. };
  74. return TransformDecl;
  75. }(Declaration);
  76. _defineProperty(TransformDecl, "names", ['transform', 'transform-origin']);
  77. _defineProperty(TransformDecl, "functions3d", ['matrix3d', 'translate3d', 'translateZ', 'scale3d', 'scaleZ', 'rotate3d', 'rotateX', 'rotateY', 'perspective']);
  78. module.exports = TransformDecl;