source: trip-planner-front/node_modules/postcss-ordered-values/dist/index.js@ b738035

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

initial commit

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[6a3a178]1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
9
10var _animation = _interopRequireDefault(require("./rules/animation"));
11
12var _border = _interopRequireDefault(require("./rules/border"));
13
14var _boxShadow = _interopRequireDefault(require("./rules/boxShadow"));
15
16var _flexFlow = _interopRequireDefault(require("./rules/flexFlow"));
17
18var _transition = _interopRequireDefault(require("./rules/transition"));
19
20var _grid = require("./rules/grid");
21
22var _listStyle = _interopRequireDefault(require("./rules/listStyle"));
23
24var _columns = require("./rules/columns");
25
26function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
28// rules
29const borderRules = {
30 border: _border.default,
31 'border-block': _border.default,
32 'border-inline': _border.default,
33 'border-block-end': _border.default,
34 'border-block-start': _border.default,
35 'border-inline-end': _border.default,
36 'border-inline-start': _border.default,
37 'border-top': _border.default,
38 'border-right': _border.default,
39 'border-bottom': _border.default,
40 'border-left': _border.default
41};
42const grid = {
43 'grid-auto-flow': _grid.normalizeGridAutoFlow,
44 'grid-column-gap': _grid.normalizeGridColumnRowGap,
45 // normal | <length-percentage>
46 'grid-row-gap': _grid.normalizeGridColumnRowGap,
47 // normal | <length-percentage>
48 'grid-column': _grid.normalizeGridColumnRow,
49 // <grid-line>+
50 'grid-row': _grid.normalizeGridColumnRow,
51 // <grid-line>+
52 'grid-row-start': _grid.normalizeGridColumnRow,
53 // <grid-line>
54 'grid-row-end': _grid.normalizeGridColumnRow,
55 // <grid-line>
56 'grid-column-start': _grid.normalizeGridColumnRow,
57 // <grid-line>
58 'grid-column-end': _grid.normalizeGridColumnRow // <grid-line>
59
60};
61const columnRules = {
62 'column-rule': _columns.columnsRule,
63 columns: _columns.column
64};
65const rules = {
66 animation: _animation.default,
67 outline: _border.default,
68 'box-shadow': _boxShadow.default,
69 'flex-flow': _flexFlow.default,
70 'list-style': _listStyle.default,
71 transition: _transition.default,
72 ...borderRules,
73 ...grid,
74 ...columnRules
75};
76
77function vendorUnprefixed(prop) {
78 return prop.replace(/^-\w+-/, '');
79}
80
81function isVariableFunctionNode(node) {
82 if (node.type !== 'function') {
83 return false;
84 }
85
86 return ['var', 'env'].includes(node.value.toLowerCase());
87}
88
89function shouldAbort(parsed) {
90 let abort = false;
91 parsed.walk(node => {
92 if (node.type === 'comment' || isVariableFunctionNode(node) || node.type === 'word' && ~node.value.indexOf(`___CSS_LOADER_IMPORT___`)) {
93 abort = true;
94 return false;
95 }
96 });
97 return abort;
98}
99
100function getValue(decl) {
101 let {
102 value,
103 raws
104 } = decl;
105
106 if (raws && raws.value && raws.value.raw) {
107 value = raws.value.raw;
108 }
109
110 return value;
111}
112
113function pluginCreator() {
114 return {
115 postcssPlugin: 'postcss-ordered-values',
116
117 prepare() {
118 const cache = {};
119 return {
120 OnceExit(css) {
121 css.walkDecls(decl => {
122 const lowerCasedProp = decl.prop.toLowerCase();
123 const normalizedProp = vendorUnprefixed(lowerCasedProp);
124 const processor = rules[normalizedProp];
125
126 if (!processor) {
127 return;
128 }
129
130 const value = getValue(decl);
131
132 if (cache[value]) {
133 decl.value = cache[value];
134 return;
135 }
136
137 const parsed = (0, _postcssValueParser.default)(value);
138
139 if (parsed.nodes.length < 2 || shouldAbort(parsed)) {
140 cache[value] = value;
141 return;
142 }
143
144 const result = processor(parsed);
145 decl.value = result.toString();
146 cache[value] = result.toString();
147 });
148 }
149
150 };
151 }
152
153 };
154}
155
156pluginCreator.postcss = true;
157var _default = pluginCreator;
158exports.default = _default;
159module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.