1 | "use strict";
|
2 |
|
3 | function _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); }
|
4 |
|
5 | function _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); }
|
6 |
|
7 | function _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; }
|
8 |
|
9 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
10 |
|
11 | var parser = require('postcss-value-parser');
|
12 |
|
13 | var vendor = require('postcss').vendor;
|
14 |
|
15 | var list = require('postcss').list;
|
16 |
|
17 | var Browsers = require('./browsers');
|
18 |
|
19 | var Transition = function () {
|
20 | function Transition(prefixes) {
|
21 | _defineProperty(this, "props", ['transition', 'transition-property']);
|
22 |
|
23 | this.prefixes = prefixes;
|
24 | }
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 | var _proto = Transition.prototype;
|
31 |
|
32 | _proto.add = function add(decl, result) {
|
33 | var _this = this;
|
34 |
|
35 | var prefix, prop;
|
36 | var add = this.prefixes.add[decl.prop];
|
37 | var vendorPrefixes = this.ruleVendorPrefixes(decl);
|
38 | var declPrefixes = vendorPrefixes || add && add.prefixes || [];
|
39 | var params = this.parse(decl.value);
|
40 | var names = params.map(function (i) {
|
41 | return _this.findProp(i);
|
42 | });
|
43 | var added = [];
|
44 |
|
45 | if (names.some(function (i) {
|
46 | return i[0] === '-';
|
47 | })) {
|
48 | return;
|
49 | }
|
50 |
|
51 | for (var _iterator = _createForOfIteratorHelperLoose(params), _step; !(_step = _iterator()).done;) {
|
52 | var param = _step.value;
|
53 | prop = this.findProp(param);
|
54 | if (prop[0] === '-') continue;
|
55 | var prefixer = this.prefixes.add[prop];
|
56 | if (!prefixer || !prefixer.prefixes) continue;
|
57 |
|
58 | for (var _iterator3 = _createForOfIteratorHelperLoose(prefixer.prefixes), _step3; !(_step3 = _iterator3()).done;) {
|
59 | prefix = _step3.value;
|
60 |
|
61 | if (vendorPrefixes && !vendorPrefixes.some(function (p) {
|
62 | return prefix.includes(p);
|
63 | })) {
|
64 | continue;
|
65 | }
|
66 |
|
67 | var prefixed = this.prefixes.prefixed(prop, prefix);
|
68 |
|
69 | if (prefixed !== '-ms-transform' && !names.includes(prefixed)) {
|
70 | if (!this.disabled(prop, prefix)) {
|
71 | added.push(this.clone(prop, prefixed, param));
|
72 | }
|
73 | }
|
74 | }
|
75 | }
|
76 |
|
77 | params = params.concat(added);
|
78 | var value = this.stringify(params);
|
79 | var webkitClean = this.stringify(this.cleanFromUnprefixed(params, '-webkit-'));
|
80 |
|
81 | if (declPrefixes.includes('-webkit-')) {
|
82 | this.cloneBefore(decl, "-webkit-" + decl.prop, webkitClean);
|
83 | }
|
84 |
|
85 | this.cloneBefore(decl, decl.prop, webkitClean);
|
86 |
|
87 | if (declPrefixes.includes('-o-')) {
|
88 | var operaClean = this.stringify(this.cleanFromUnprefixed(params, '-o-'));
|
89 | this.cloneBefore(decl, "-o-" + decl.prop, operaClean);
|
90 | }
|
91 |
|
92 | for (var _iterator2 = _createForOfIteratorHelperLoose(declPrefixes), _step2; !(_step2 = _iterator2()).done;) {
|
93 | prefix = _step2.value;
|
94 |
|
95 | if (prefix !== '-webkit-' && prefix !== '-o-') {
|
96 | var prefixValue = this.stringify(this.cleanOtherPrefixes(params, prefix));
|
97 | this.cloneBefore(decl, prefix + decl.prop, prefixValue);
|
98 | }
|
99 | }
|
100 |
|
101 | if (value !== decl.value && !this.already(decl, decl.prop, value)) {
|
102 | this.checkForWarning(result, decl);
|
103 | decl.cloneBefore();
|
104 | decl.value = value;
|
105 | }
|
106 | }
|
107 | |
108 |
|
109 |
|
110 | ;
|
111 |
|
112 | _proto.findProp = function findProp(param) {
|
113 | var prop = param[0].value;
|
114 |
|
115 | if (/^\d/.test(prop)) {
|
116 | for (var _iterator4 = _createForOfIteratorHelperLoose(param.entries()), _step4; !(_step4 = _iterator4()).done;) {
|
117 | var _step4$value = _step4.value,
|
118 | i = _step4$value[0],
|
119 | token = _step4$value[1];
|
120 |
|
121 | if (i !== 0 && token.type === 'word') {
|
122 | return token.value;
|
123 | }
|
124 | }
|
125 | }
|
126 |
|
127 | return prop;
|
128 | }
|
129 | |
130 |
|
131 |
|
132 | ;
|
133 |
|
134 | _proto.already = function already(decl, prop, value) {
|
135 | return decl.parent.some(function (i) {
|
136 | return i.prop === prop && i.value === value;
|
137 | });
|
138 | }
|
139 | |
140 |
|
141 |
|
142 | ;
|
143 |
|
144 | _proto.cloneBefore = function cloneBefore(decl, prop, value) {
|
145 | if (!this.already(decl, prop, value)) {
|
146 | decl.cloneBefore({
|
147 | prop: prop,
|
148 | value: value
|
149 | });
|
150 | }
|
151 | }
|
152 | |
153 |
|
154 |
|
155 | ;
|
156 |
|
157 | _proto.checkForWarning = function checkForWarning(result, decl) {
|
158 | if (decl.prop !== 'transition-property') {
|
159 | return;
|
160 | }
|
161 |
|
162 | decl.parent.each(function (i) {
|
163 | if (i.type !== 'decl') {
|
164 | return undefined;
|
165 | }
|
166 |
|
167 | if (i.prop.indexOf('transition-') !== 0) {
|
168 | return undefined;
|
169 | }
|
170 |
|
171 | if (i.prop === 'transition-property') {
|
172 | return undefined;
|
173 | }
|
174 |
|
175 | if (list.comma(i.value).length > 1) {
|
176 | decl.warn(result, 'Replace transition-property to transition, ' + 'because Autoprefixer could not support ' + 'any cases of transition-property ' + 'and other transition-*');
|
177 | }
|
178 |
|
179 | return false;
|
180 | });
|
181 | }
|
182 | |
183 |
|
184 |
|
185 | ;
|
186 |
|
187 | _proto.remove = function remove(decl) {
|
188 | var _this2 = this;
|
189 |
|
190 | var params = this.parse(decl.value);
|
191 | params = params.filter(function (i) {
|
192 | var prop = _this2.prefixes.remove[_this2.findProp(i)];
|
193 |
|
194 | return !prop || !prop.remove;
|
195 | });
|
196 | var value = this.stringify(params);
|
197 |
|
198 | if (decl.value === value) {
|
199 | return;
|
200 | }
|
201 |
|
202 | if (params.length === 0) {
|
203 | decl.remove();
|
204 | return;
|
205 | }
|
206 |
|
207 | var _double = decl.parent.some(function (i) {
|
208 | return i.prop === decl.prop && i.value === value;
|
209 | });
|
210 |
|
211 | var smaller = decl.parent.some(function (i) {
|
212 | return i !== decl && i.prop === decl.prop && i.value.length > value.length;
|
213 | });
|
214 |
|
215 | if (_double || smaller) {
|
216 | decl.remove();
|
217 | return;
|
218 | }
|
219 |
|
220 | decl.value = value;
|
221 | }
|
222 | |
223 |
|
224 |
|
225 | ;
|
226 |
|
227 | _proto.parse = function parse(value) {
|
228 | var ast = parser(value);
|
229 | var result = [];
|
230 | var param = [];
|
231 |
|
232 | for (var _iterator5 = _createForOfIteratorHelperLoose(ast.nodes), _step5; !(_step5 = _iterator5()).done;) {
|
233 | var node = _step5.value;
|
234 | param.push(node);
|
235 |
|
236 | if (node.type === 'div' && node.value === ',') {
|
237 | result.push(param);
|
238 | param = [];
|
239 | }
|
240 | }
|
241 |
|
242 | result.push(param);
|
243 | return result.filter(function (i) {
|
244 | return i.length > 0;
|
245 | });
|
246 | }
|
247 | |
248 |
|
249 |
|
250 | ;
|
251 |
|
252 | _proto.stringify = function stringify(params) {
|
253 | if (params.length === 0) {
|
254 | return '';
|
255 | }
|
256 |
|
257 | var nodes = [];
|
258 |
|
259 | for (var _iterator6 = _createForOfIteratorHelperLoose(params), _step6; !(_step6 = _iterator6()).done;) {
|
260 | var param = _step6.value;
|
261 |
|
262 | if (param[param.length - 1].type !== 'div') {
|
263 | param.push(this.div(params));
|
264 | }
|
265 |
|
266 | nodes = nodes.concat(param);
|
267 | }
|
268 |
|
269 | if (nodes[0].type === 'div') {
|
270 | nodes = nodes.slice(1);
|
271 | }
|
272 |
|
273 | if (nodes[nodes.length - 1].type === 'div') {
|
274 | nodes = nodes.slice(0, +-2 + 1 || undefined);
|
275 | }
|
276 |
|
277 | return parser.stringify({
|
278 | nodes: nodes
|
279 | });
|
280 | }
|
281 | |
282 |
|
283 |
|
284 | ;
|
285 |
|
286 | _proto.clone = function clone(origin, name, param) {
|
287 | var result = [];
|
288 | var changed = false;
|
289 |
|
290 | for (var _iterator7 = _createForOfIteratorHelperLoose(param), _step7; !(_step7 = _iterator7()).done;) {
|
291 | var i = _step7.value;
|
292 |
|
293 | if (!changed && i.type === 'word' && i.value === origin) {
|
294 | result.push({
|
295 | type: 'word',
|
296 | value: name
|
297 | });
|
298 | changed = true;
|
299 | } else {
|
300 | result.push(i);
|
301 | }
|
302 | }
|
303 |
|
304 | return result;
|
305 | }
|
306 | |
307 |
|
308 |
|
309 | ;
|
310 |
|
311 | _proto.div = function div(params) {
|
312 | for (var _iterator8 = _createForOfIteratorHelperLoose(params), _step8; !(_step8 = _iterator8()).done;) {
|
313 | var param = _step8.value;
|
314 |
|
315 | for (var _iterator9 = _createForOfIteratorHelperLoose(param), _step9; !(_step9 = _iterator9()).done;) {
|
316 | var node = _step9.value;
|
317 |
|
318 | if (node.type === 'div' && node.value === ',') {
|
319 | return node;
|
320 | }
|
321 | }
|
322 | }
|
323 |
|
324 | return {
|
325 | type: 'div',
|
326 | value: ',',
|
327 | after: ' '
|
328 | };
|
329 | };
|
330 |
|
331 | _proto.cleanOtherPrefixes = function cleanOtherPrefixes(params, prefix) {
|
332 | var _this3 = this;
|
333 |
|
334 | return params.filter(function (param) {
|
335 | var current = vendor.prefix(_this3.findProp(param));
|
336 | return current === '' || current === prefix;
|
337 | });
|
338 | }
|
339 | |
340 |
|
341 |
|
342 | ;
|
343 |
|
344 | _proto.cleanFromUnprefixed = function cleanFromUnprefixed(params, prefix) {
|
345 | var _this4 = this;
|
346 |
|
347 | var remove = params.map(function (i) {
|
348 | return _this4.findProp(i);
|
349 | }).filter(function (i) {
|
350 | return i.slice(0, prefix.length) === prefix;
|
351 | }).map(function (i) {
|
352 | return _this4.prefixes.unprefixed(i);
|
353 | });
|
354 | var result = [];
|
355 |
|
356 | for (var _iterator10 = _createForOfIteratorHelperLoose(params), _step10; !(_step10 = _iterator10()).done;) {
|
357 | var param = _step10.value;
|
358 | var prop = this.findProp(param);
|
359 | var p = vendor.prefix(prop);
|
360 |
|
361 | if (!remove.includes(prop) && (p === prefix || p === '')) {
|
362 | result.push(param);
|
363 | }
|
364 | }
|
365 |
|
366 | return result;
|
367 | }
|
368 | |
369 |
|
370 |
|
371 | ;
|
372 |
|
373 | _proto.disabled = function disabled(prop, prefix) {
|
374 | var other = ['order', 'justify-content', 'align-self', 'align-content'];
|
375 |
|
376 | if (prop.includes('flex') || other.includes(prop)) {
|
377 | if (this.prefixes.options.flexbox === false) {
|
378 | return true;
|
379 | }
|
380 |
|
381 | if (this.prefixes.options.flexbox === 'no-2009') {
|
382 | return prefix.includes('2009');
|
383 | }
|
384 | }
|
385 |
|
386 | return undefined;
|
387 | }
|
388 | |
389 |
|
390 |
|
391 | ;
|
392 |
|
393 | _proto.ruleVendorPrefixes = function ruleVendorPrefixes(decl) {
|
394 | var parent = decl.parent;
|
395 |
|
396 | if (parent.type !== 'rule') {
|
397 | return false;
|
398 | } else if (!parent.selector.includes(':-')) {
|
399 | return false;
|
400 | }
|
401 |
|
402 | var selectors = Browsers.prefixes().filter(function (s) {
|
403 | return parent.selector.includes(':' + s);
|
404 | });
|
405 | return selectors.length > 0 ? selectors : false;
|
406 | };
|
407 |
|
408 | return Transition;
|
409 | }();
|
410 |
|
411 | module.exports = Transition; |
\ | No newline at end of file |