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.

105 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 MaskComposite =
  7. /*#__PURE__*/
  8. function (_Declaration) {
  9. _inheritsLoose(MaskComposite, _Declaration);
  10. function MaskComposite() {
  11. return _Declaration.apply(this, arguments) || this;
  12. }
  13. var _proto = MaskComposite.prototype;
  14. /**
  15. * Prefix mask-composite for webkit
  16. */
  17. _proto.insert = function insert(decl, prefix, prefixes) {
  18. var isCompositeProp = decl.prop === 'mask-composite';
  19. var compositeValues;
  20. if (isCompositeProp) {
  21. compositeValues = decl.value.split(',');
  22. } else {
  23. compositeValues = decl.value.match(MaskComposite.regexp) || [];
  24. }
  25. compositeValues = compositeValues.map(function (el) {
  26. return el.trim();
  27. }).filter(function (el) {
  28. return el;
  29. });
  30. var hasCompositeValues = compositeValues.length;
  31. var compositeDecl;
  32. if (hasCompositeValues) {
  33. compositeDecl = this.clone(decl);
  34. compositeDecl.value = compositeValues.map(function (value) {
  35. return MaskComposite.oldValues[value] || value;
  36. }).join(', ');
  37. if (compositeValues.includes('intersect')) {
  38. compositeDecl.value += ', xor';
  39. }
  40. compositeDecl.prop = prefix + 'mask-composite';
  41. }
  42. if (isCompositeProp) {
  43. if (!hasCompositeValues) {
  44. return undefined;
  45. }
  46. if (this.needCascade(decl)) {
  47. compositeDecl.raws.before = this.calcBefore(prefixes, decl, prefix);
  48. }
  49. return decl.parent.insertBefore(decl, compositeDecl);
  50. }
  51. var cloned = this.clone(decl);
  52. cloned.prop = prefix + cloned.prop;
  53. if (hasCompositeValues) {
  54. cloned.value = cloned.value.replace(MaskComposite.regexp, '');
  55. }
  56. if (this.needCascade(decl)) {
  57. cloned.raws.before = this.calcBefore(prefixes, decl, prefix);
  58. }
  59. decl.parent.insertBefore(decl, cloned);
  60. if (!hasCompositeValues) {
  61. return decl;
  62. }
  63. if (this.needCascade(decl)) {
  64. compositeDecl.raws.before = this.calcBefore(prefixes, decl, prefix);
  65. }
  66. return decl.parent.insertBefore(decl, compositeDecl);
  67. };
  68. return MaskComposite;
  69. }(Declaration);
  70. _defineProperty(MaskComposite, "names", ['mask', 'mask-composite']);
  71. _defineProperty(MaskComposite, "oldValues", {
  72. add: 'source-over',
  73. substract: 'source-out',
  74. intersect: 'source-in',
  75. exclude: 'xor'
  76. });
  77. _defineProperty(MaskComposite, "regexp", new RegExp("\\s+(" + Object.keys(MaskComposite.oldValues).join('|') + ")\\b(?!\\))\\s*(?=[,])", 'ig'));
  78. module.exports = MaskComposite;