source: trip-planner-front/node_modules/postcss-discard-overridden/dist/index.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[6a3a178]1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7const OVERRIDABLE_RULES = ['keyframes', 'counter-style'];
8const SCOPE_RULES = ['media', 'supports'];
9
10function vendorUnprefixed(prop) {
11 return prop.replace(/^-\w+-/, '');
12}
13
14function isOverridable(name) {
15 return ~OVERRIDABLE_RULES.indexOf(vendorUnprefixed(name.toLowerCase()));
16}
17
18function isScope(name) {
19 return ~SCOPE_RULES.indexOf(vendorUnprefixed(name.toLowerCase()));
20}
21
22function getScope(node) {
23 let current = node.parent;
24 const chain = [node.name.toLowerCase(), node.params];
25
26 do {
27 if (current.type === 'atrule' && isScope(current.name)) {
28 chain.unshift(current.name + ' ' + current.params);
29 }
30
31 current = current.parent;
32 } while (current);
33
34 return chain.join('|');
35}
36
37function pluginCreator() {
38 return {
39 postcssPlugin: 'postcss-discard-overridden',
40
41 prepare() {
42 const cache = {};
43 const rules = [];
44 return {
45 OnceExit(css) {
46 css.walkAtRules(node => {
47 if (isOverridable(node.name)) {
48 const scope = getScope(node);
49 cache[scope] = node;
50 rules.push({
51 node,
52 scope
53 });
54 }
55 });
56 rules.forEach(rule => {
57 if (cache[rule.scope] !== rule.node) {
58 rule.node.remove();
59 }
60 });
61 }
62
63 };
64 }
65
66 };
67}
68
69pluginCreator.postcss = true;
70var _default = pluginCreator;
71exports.default = _default;
72module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.