UNPKG

2.83 kBJavaScriptView Raw
1"use strict";
2
3function _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
5function _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); }
6
7function _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); }
8
9function _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; }
10
11function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _defaults(subClass, superClass); }
12
13var Prefixer = require('./prefixer');
14
15var AtRule = /*#__PURE__*/function (_Prefixer) {
16 _inheritsLoose(AtRule, _Prefixer);
17
18 function AtRule() {
19 return _Prefixer.apply(this, arguments) || this;
20 }
21
22 var _proto = AtRule.prototype;
23
24 /**
25 * Clone and add prefixes for at-rule
26 */
27 _proto.add = function add(rule, prefix) {
28 var prefixed = prefix + rule.name;
29 var already = rule.parent.some(function (i) {
30 return i.name === prefixed && i.params === rule.params;
31 });
32
33 if (already) {
34 return undefined;
35 }
36
37 var cloned = this.clone(rule, {
38 name: prefixed
39 });
40 return rule.parent.insertBefore(rule, cloned);
41 }
42 /**
43 * Clone node with prefixes
44 */
45 ;
46
47 _proto.process = function process(node) {
48 var parent = this.parentPrefix(node);
49
50 for (var _iterator = _createForOfIteratorHelperLoose(this.prefixes), _step; !(_step = _iterator()).done;) {
51 var prefix = _step.value;
52
53 if (!parent || parent === prefix) {
54 this.add(node, prefix);
55 }
56 }
57 };
58
59 return AtRule;
60}(Prefixer);
61
62module.exports = AtRule;
\No newline at end of file