source: trip-planner-front/node_modules/postcss-reduce-transforms/dist/index.js@ 59329aa

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

initial commit

  • Property mode set to 100644
File size: 6.1 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _postcssValueParser = _interopRequireWildcard(require("postcss-value-parser"));
9
10var _cssnanoUtils = require("cssnano-utils");
11
12function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
14function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
16function getValues(list, node, index) {
17 if (index % 2 === 0) {
18 let value = NaN;
19
20 if (node.type === 'function' && (node.value === 'var' || node.value === 'env') && node.nodes.length === 1) {
21 value = (0, _postcssValueParser.stringify)(node.nodes);
22 } else if (node.type === 'word') {
23 value = parseFloat(node.value);
24 }
25
26 return [...list, value];
27 }
28
29 return list;
30}
31
32function matrix3d(node, values) {
33 if (values.length !== 16) {
34 return;
35 } // matrix3d(a, b, 0, 0, c, d, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1) => matrix(a, b, c, d, tx, ty)
36
37
38 if (values[15] && values[2] === 0 && values[3] === 0 && values[6] === 0 && values[7] === 0 && values[8] === 0 && values[9] === 0 && values[10] === 1 && values[11] === 0 && values[14] === 0 && values[15] === 1) {
39 const {
40 nodes
41 } = node;
42 node.value = 'matrix';
43 node.nodes = [nodes[0], // a
44 nodes[1], // ,
45 nodes[2], // b
46 nodes[3], // ,
47 nodes[8], // c
48 nodes[9], // ,
49 nodes[10], // d
50 nodes[11], // ,
51 nodes[24], // tx
52 nodes[25], // ,
53 nodes[26] // ty
54 ];
55 }
56}
57
58const rotate3dMappings = [['rotateX', [1, 0, 0]], // rotate3d(1, 0, 0, a) => rotateX(a)
59['rotateY', [0, 1, 0]], // rotate3d(0, 1, 0, a) => rotateY(a)
60['rotate', [0, 0, 1]] // rotate3d(0, 0, 1, a) => rotate(a)
61];
62const rotate3dMatch = (0, _cssnanoUtils.getMatch)(rotate3dMappings);
63
64function rotate3d(node, values) {
65 if (values.length !== 4) {
66 return;
67 }
68
69 const {
70 nodes
71 } = node;
72 const match = rotate3dMatch(values.slice(0, 3));
73
74 if (match.length) {
75 node.value = match;
76 node.nodes = [nodes[6]];
77 }
78}
79
80function rotateZ(node, values) {
81 if (values.length !== 1) {
82 return;
83 } // rotateZ(rz) => rotate(rz)
84
85
86 node.value = 'rotate';
87}
88
89function scale(node, values) {
90 if (values.length !== 2) {
91 return;
92 }
93
94 const {
95 nodes
96 } = node;
97 const [first, second] = values; // scale(sx, sy) => scale(sx)
98
99 if (first === second) {
100 node.nodes = [nodes[0]];
101 return;
102 } // scale(sx, 1) => scaleX(sx)
103
104
105 if (second === 1) {
106 node.value = 'scaleX';
107 node.nodes = [nodes[0]];
108 return;
109 } // scale(1, sy) => scaleY(sy)
110
111
112 if (first === 1) {
113 node.value = 'scaleY';
114 node.nodes = [nodes[2]];
115 return;
116 }
117}
118
119function scale3d(node, values) {
120 if (values.length !== 3) {
121 return;
122 }
123
124 const {
125 nodes
126 } = node;
127 const [first, second, third] = values; // scale3d(sx, 1, 1) => scaleX(sx)
128
129 if (second === 1 && third === 1) {
130 node.value = 'scaleX';
131 node.nodes = [nodes[0]];
132 return;
133 } // scale3d(1, sy, 1) => scaleY(sy)
134
135
136 if (first === 1 && third === 1) {
137 node.value = 'scaleY';
138 node.nodes = [nodes[2]];
139 return;
140 } // scale3d(1, 1, sz) => scaleZ(sz)
141
142
143 if (first === 1 && second === 1) {
144 node.value = 'scaleZ';
145 node.nodes = [nodes[4]];
146 return;
147 }
148}
149
150function translate(node, values) {
151 if (values.length !== 2) {
152 return;
153 }
154
155 const {
156 nodes
157 } = node; // translate(tx, 0) => translate(tx)
158
159 if (values[1] === 0) {
160 node.nodes = [nodes[0]];
161 return;
162 } // translate(0, ty) => translateY(ty)
163
164
165 if (values[0] === 0) {
166 node.value = 'translateY';
167 node.nodes = [nodes[2]];
168 return;
169 }
170}
171
172function translate3d(node, values) {
173 if (values.length !== 3) {
174 return;
175 }
176
177 const {
178 nodes
179 } = node; // translate3d(0, 0, tz) => translateZ(tz)
180
181 if (values[0] === 0 && values[1] === 0) {
182 node.value = 'translateZ';
183 node.nodes = [nodes[4]];
184 }
185}
186
187const reducers = {
188 matrix3d,
189 rotate3d,
190 rotateZ,
191 scale,
192 scale3d,
193 translate,
194 translate3d
195};
196
197function normalizeReducerName(name) {
198 const lowerCasedName = name.toLowerCase();
199
200 if (lowerCasedName === 'rotatez') {
201 return 'rotateZ';
202 }
203
204 return lowerCasedName;
205}
206
207function reduce(node) {
208 const {
209 nodes,
210 type,
211 value
212 } = node;
213 const normalizedReducerName = normalizeReducerName(value);
214
215 if (type === 'function' && Object.prototype.hasOwnProperty.call(reducers, normalizedReducerName)) {
216 reducers[normalizedReducerName](node, nodes.reduce(getValues, []));
217 }
218
219 return false;
220}
221
222function pluginCreator() {
223 return {
224 postcssPlugin: 'postcss-reduce-transforms',
225
226 prepare() {
227 const cache = {};
228 return {
229 OnceExit(css) {
230 css.walkDecls(/transform$/i, decl => {
231 const value = decl.value;
232
233 if (!value) {
234 return;
235 }
236
237 if (cache[value]) {
238 decl.value = cache[value];
239 return;
240 }
241
242 const result = (0, _postcssValueParser.default)(value).walk(reduce).toString();
243 decl.value = result;
244 cache[value] = result;
245 });
246 }
247
248 };
249 }
250
251 };
252}
253
254pluginCreator.postcss = true;
255var _default = pluginCreator;
256exports.default = _default;
257module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.