You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.2 KiB

4 years ago
  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 _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _defaults(subClass, superClass); }
  4. 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; }
  5. var Declaration = require('../declaration');
  6. var TransformDecl =
  7. /*#__PURE__*/
  8. function (_Declaration) {
  9. _inheritsLoose(TransformDecl, _Declaration);
  10. function TransformDecl() {
  11. return _Declaration.apply(this, arguments) || this;
  12. }
  13. var _proto = TransformDecl.prototype;
  14. /**
  15. * Recursively check all parents for @keyframes
  16. */
  17. _proto.keyframeParents = function keyframeParents(decl) {
  18. var parent = decl.parent;
  19. while (parent) {
  20. if (parent.type === 'atrule' && parent.name === 'keyframes') {
  21. return true;
  22. }
  23. var _parent = parent;
  24. parent = _parent.parent;
  25. }
  26. return false;
  27. }
  28. /**
  29. * Is transform contain 3D commands
  30. */
  31. ;
  32. _proto.contain3d = function contain3d(decl) {
  33. if (decl.prop === 'transform-origin') {
  34. return false;
  35. }
  36. for (var _iterator = TransformDecl.functions3d, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
  37. var _ref;
  38. if (_isArray) {
  39. if (_i >= _iterator.length) break;
  40. _ref = _iterator[_i++];
  41. } else {
  42. _i = _iterator.next();
  43. if (_i.done) break;
  44. _ref = _i.value;
  45. }
  46. var func = _ref;
  47. if (decl.value.includes(func + "(")) {
  48. return true;
  49. }
  50. }
  51. return false;
  52. }
  53. /**
  54. * Replace rotateZ to rotate for IE 9
  55. */
  56. ;
  57. _proto.set = function set(decl, prefix) {
  58. decl = _Declaration.prototype.set.call(this, decl, prefix);
  59. if (prefix === '-ms-') {
  60. decl.value = decl.value.replace(/rotatez/gi, 'rotate');
  61. }
  62. return decl;
  63. }
  64. /**
  65. * Don't add prefix for IE in keyframes
  66. */
  67. ;
  68. _proto.insert = function insert(decl, prefix, prefixes) {
  69. if (prefix === '-ms-') {
  70. if (!this.contain3d(decl) && !this.keyframeParents(decl)) {
  71. return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  72. }
  73. } else if (prefix === '-o-') {
  74. if (!this.contain3d(decl)) {
  75. return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  76. }
  77. } else {
  78. return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  79. }
  80. return undefined;
  81. };
  82. return TransformDecl;
  83. }(Declaration);
  84. _defineProperty(TransformDecl, "names", ['transform', 'transform-origin']);
  85. _defineProperty(TransformDecl, "functions3d", ['matrix3d', 'translate3d', 'translateZ', 'scale3d', 'scaleZ', 'rotate3d', 'rotateX', 'rotateY', 'perspective']);
  86. module.exports = TransformDecl;