transform-decl.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. (function() {
  2. var Declaration, TransformDecl,
  3. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  4. __hasProp = {}.hasOwnProperty;
  5. Declaration = require('../declaration');
  6. TransformDecl = (function(_super) {
  7. __extends(TransformDecl, _super);
  8. function TransformDecl() {
  9. return TransformDecl.__super__.constructor.apply(this, arguments);
  10. }
  11. TransformDecl.names = ['transform', 'transform-origin'];
  12. TransformDecl.functions3d = ['matrix3d', 'translate3d', 'translateZ', 'scale3d', 'scaleZ', 'rotate3d', 'rotateX', 'rotateY', 'rotateZ', 'perspective'];
  13. TransformDecl.prototype.keykrameParents = function(decl) {
  14. var parent;
  15. parent = decl.parent;
  16. while (parent) {
  17. if (parent.type === 'atrule' && parent.name === 'keyframes') {
  18. return true;
  19. }
  20. parent = parent.parent;
  21. }
  22. return false;
  23. };
  24. TransformDecl.prototype.contain3d = function(decl) {
  25. var func, _i, _len, _ref;
  26. if (decl.prop === 'transform-origin') {
  27. return false;
  28. }
  29. _ref = TransformDecl.functions3d;
  30. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  31. func = _ref[_i];
  32. if (decl.value.indexOf(func + "(") !== -1) {
  33. return true;
  34. }
  35. }
  36. return false;
  37. };
  38. TransformDecl.prototype.insert = function(decl, prefix, prefixes) {
  39. if (prefix === '-ms-') {
  40. if (!this.contain3d(decl) && !this.keykrameParents(decl)) {
  41. return TransformDecl.__super__.insert.apply(this, arguments);
  42. }
  43. } else if (prefix === '-o-') {
  44. if (!this.contain3d(decl)) {
  45. return TransformDecl.__super__.insert.apply(this, arguments);
  46. }
  47. } else {
  48. return TransformDecl.__super__.insert.apply(this, arguments);
  49. }
  50. };
  51. return TransformDecl;
  52. })(Declaration);
  53. module.exports = TransformDecl;
  54. }).call(this);