1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = void 0;
|
---|
7 |
|
---|
8 | var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
---|
9 |
|
---|
10 | var _animation = _interopRequireDefault(require("./rules/animation"));
|
---|
11 |
|
---|
12 | var _border = _interopRequireDefault(require("./rules/border"));
|
---|
13 |
|
---|
14 | var _boxShadow = _interopRequireDefault(require("./rules/boxShadow"));
|
---|
15 |
|
---|
16 | var _flexFlow = _interopRequireDefault(require("./rules/flexFlow"));
|
---|
17 |
|
---|
18 | var _transition = _interopRequireDefault(require("./rules/transition"));
|
---|
19 |
|
---|
20 | var _grid = require("./rules/grid");
|
---|
21 |
|
---|
22 | var _listStyle = _interopRequireDefault(require("./rules/listStyle"));
|
---|
23 |
|
---|
24 | var _columns = require("./rules/columns");
|
---|
25 |
|
---|
26 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
27 |
|
---|
28 | // rules
|
---|
29 | const 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 | };
|
---|
42 | const 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 | };
|
---|
61 | const columnRules = {
|
---|
62 | 'column-rule': _columns.columnsRule,
|
---|
63 | columns: _columns.column
|
---|
64 | };
|
---|
65 | const 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 |
|
---|
77 | function vendorUnprefixed(prop) {
|
---|
78 | return prop.replace(/^-\w+-/, '');
|
---|
79 | }
|
---|
80 |
|
---|
81 | function isVariableFunctionNode(node) {
|
---|
82 | if (node.type !== 'function') {
|
---|
83 | return false;
|
---|
84 | }
|
---|
85 |
|
---|
86 | return ['var', 'env'].includes(node.value.toLowerCase());
|
---|
87 | }
|
---|
88 |
|
---|
89 | function 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 |
|
---|
100 | function 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 |
|
---|
113 | function 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 |
|
---|
156 | pluginCreator.postcss = true;
|
---|
157 | var _default = pluginCreator;
|
---|
158 | exports.default = _default;
|
---|
159 | module.exports = exports.default; |
---|