source: trip-planner-front/node_modules/autoprefixer/lib/processor.js@ 6a3a178

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

initial commit

  • Property mode set to 100644
File size: 22.9 KB
Line 
1"use strict";
2
3function _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
5function _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
7function _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
9var parser = require('postcss-value-parser');
10
11var Value = require('./value');
12
13var insertAreas = require('./hacks/grid-utils').insertAreas;
14
15var OLD_LINEAR = /(^|[^-])linear-gradient\(\s*(top|left|right|bottom)/i;
16var OLD_RADIAL = /(^|[^-])radial-gradient\(\s*\d+(\w*|%)\s+\d+(\w*|%)\s*,/i;
17var IGNORE_NEXT = /(!\s*)?autoprefixer:\s*ignore\s+next/i;
18var GRID_REGEX = /(!\s*)?autoprefixer\s*grid:\s*(on|off|(no-)?autoplace)/i;
19var SIZES = ['width', 'height', 'min-width', 'max-width', 'min-height', 'max-height', 'inline-size', 'min-inline-size', 'max-inline-size', 'block-size', 'min-block-size', 'max-block-size'];
20
21function hasGridTemplate(decl) {
22 return decl.parent.some(function (i) {
23 return i.prop === 'grid-template' || i.prop === 'grid-template-areas';
24 });
25}
26
27function hasRowsAndColumns(decl) {
28 var hasRows = decl.parent.some(function (i) {
29 return i.prop === 'grid-template-rows';
30 });
31 var hasColumns = decl.parent.some(function (i) {
32 return i.prop === 'grid-template-columns';
33 });
34 return hasRows && hasColumns;
35}
36
37var Processor = /*#__PURE__*/function () {
38 function Processor(prefixes) {
39 this.prefixes = prefixes;
40 }
41 /**
42 * Add necessary prefixes
43 */
44
45
46 var _proto = Processor.prototype;
47
48 _proto.add = function add(css, result) {
49 var _this = this;
50
51 // At-rules
52 var resolution = this.prefixes.add['@resolution'];
53 var keyframes = this.prefixes.add['@keyframes'];
54 var viewport = this.prefixes.add['@viewport'];
55 var supports = this.prefixes.add['@supports'];
56 css.walkAtRules(function (rule) {
57 if (rule.name === 'keyframes') {
58 if (!_this.disabled(rule, result)) {
59 return keyframes && keyframes.process(rule);
60 }
61 } else if (rule.name === 'viewport') {
62 if (!_this.disabled(rule, result)) {
63 return viewport && viewport.process(rule);
64 }
65 } else if (rule.name === 'supports') {
66 if (_this.prefixes.options.supports !== false && !_this.disabled(rule, result)) {
67 return supports.process(rule);
68 }
69 } else if (rule.name === 'media' && rule.params.includes('-resolution')) {
70 if (!_this.disabled(rule, result)) {
71 return resolution && resolution.process(rule);
72 }
73 }
74
75 return undefined;
76 }); // Selectors
77
78 css.walkRules(function (rule) {
79 if (_this.disabled(rule, result)) return undefined;
80 return _this.prefixes.add.selectors.map(function (selector) {
81 return selector.process(rule, result);
82 });
83 });
84
85 function insideGrid(decl) {
86 return decl.parent.nodes.some(function (node) {
87 if (node.type !== 'decl') return false;
88 var displayGrid = node.prop === 'display' && /(inline-)?grid/.test(node.value);
89 var gridTemplate = node.prop.startsWith('grid-template');
90 var gridGap = /^grid-([A-z]+-)?gap/.test(node.prop);
91 return displayGrid || gridTemplate || gridGap;
92 });
93 }
94
95 function insideFlex(decl) {
96 return decl.parent.some(function (node) {
97 return node.prop === 'display' && /(inline-)?flex/.test(node.value);
98 });
99 }
100
101 var gridPrefixes = this.gridStatus(css, result) && this.prefixes.add['grid-area'] && this.prefixes.add['grid-area'].prefixes;
102 css.walkDecls(function (decl) {
103 if (_this.disabledDecl(decl, result)) return undefined;
104 var parent = decl.parent;
105 var prop = decl.prop;
106 var value = decl.value;
107
108 if (prop === 'grid-row-span') {
109 result.warn('grid-row-span is not part of final Grid Layout. Use grid-row.', {
110 node: decl
111 });
112 return undefined;
113 } else if (prop === 'grid-column-span') {
114 result.warn('grid-column-span is not part of final Grid Layout. Use grid-column.', {
115 node: decl
116 });
117 return undefined;
118 } else if (prop === 'display' && value === 'box') {
119 result.warn('You should write display: flex by final spec ' + 'instead of display: box', {
120 node: decl
121 });
122 return undefined;
123 } else if (prop === 'text-emphasis-position') {
124 if (value === 'under' || value === 'over') {
125 result.warn('You should use 2 values for text-emphasis-position ' + 'For example, `under left` instead of just `under`.', {
126 node: decl
127 });
128 }
129 } else if (/^(align|justify|place)-(items|content)$/.test(prop) && insideFlex(decl)) {
130 if (value === 'start' || value === 'end') {
131 result.warn(value + " value has mixed support, consider using " + ("flex-" + value + " instead"), {
132 node: decl
133 });
134 }
135 } else if (prop === 'text-decoration-skip' && value === 'ink') {
136 result.warn('Replace text-decoration-skip: ink to ' + 'text-decoration-skip-ink: auto, because spec had been changed', {
137 node: decl
138 });
139 } else {
140 if (gridPrefixes && _this.gridStatus(decl, result)) {
141 if (decl.value === 'subgrid') {
142 result.warn('IE does not support subgrid', {
143 node: decl
144 });
145 }
146
147 if (/^(align|justify|place)-items$/.test(prop) && insideGrid(decl)) {
148 var fixed = prop.replace('-items', '-self');
149 result.warn("IE does not support " + prop + " on grid containers. " + ("Try using " + fixed + " on child elements instead: ") + (decl.parent.selector + " > * { " + fixed + ": " + decl.value + " }"), {
150 node: decl
151 });
152 } else if (/^(align|justify|place)-content$/.test(prop) && insideGrid(decl)) {
153 result.warn("IE does not support " + decl.prop + " on grid containers", {
154 node: decl
155 });
156 } else if (prop === 'display' && decl.value === 'contents') {
157 result.warn('Please do not use display: contents; ' + 'if you have grid setting enabled', {
158 node: decl
159 });
160 return undefined;
161 } else if (decl.prop === 'grid-gap') {
162 var status = _this.gridStatus(decl, result);
163
164 if (status === 'autoplace' && !hasRowsAndColumns(decl) && !hasGridTemplate(decl)) {
165 result.warn('grid-gap only works if grid-template(-areas) is being ' + 'used or both rows and columns have been declared ' + 'and cells have not been manually ' + 'placed inside the explicit grid', {
166 node: decl
167 });
168 } else if ((status === true || status === 'no-autoplace') && !hasGridTemplate(decl)) {
169 result.warn('grid-gap only works if grid-template(-areas) is being used', {
170 node: decl
171 });
172 }
173 } else if (prop === 'grid-auto-columns') {
174 result.warn('grid-auto-columns is not supported by IE', {
175 node: decl
176 });
177 return undefined;
178 } else if (prop === 'grid-auto-rows') {
179 result.warn('grid-auto-rows is not supported by IE', {
180 node: decl
181 });
182 return undefined;
183 } else if (prop === 'grid-auto-flow') {
184 var hasRows = parent.some(function (i) {
185 return i.prop === 'grid-template-rows';
186 });
187 var hasCols = parent.some(function (i) {
188 return i.prop === 'grid-template-columns';
189 });
190
191 if (hasGridTemplate(decl)) {
192 result.warn('grid-auto-flow is not supported by IE', {
193 node: decl
194 });
195 } else if (value.includes('dense')) {
196 result.warn('grid-auto-flow: dense is not supported by IE', {
197 node: decl
198 });
199 } else if (!hasRows && !hasCols) {
200 result.warn('grid-auto-flow works only if grid-template-rows and ' + 'grid-template-columns are present in the same rule', {
201 node: decl
202 });
203 }
204
205 return undefined;
206 } else if (value.includes('auto-fit')) {
207 result.warn('auto-fit value is not supported by IE', {
208 node: decl,
209 word: 'auto-fit'
210 });
211 return undefined;
212 } else if (value.includes('auto-fill')) {
213 result.warn('auto-fill value is not supported by IE', {
214 node: decl,
215 word: 'auto-fill'
216 });
217 return undefined;
218 } else if (prop.startsWith('grid-template') && value.includes('[')) {
219 result.warn('Autoprefixer currently does not support line names. ' + 'Try using grid-template-areas instead.', {
220 node: decl,
221 word: '['
222 });
223 }
224 }
225
226 if (value.includes('radial-gradient')) {
227 if (OLD_RADIAL.test(decl.value)) {
228 result.warn('Gradient has outdated direction syntax. ' + 'New syntax is like `closest-side at 0 0` ' + 'instead of `0 0, closest-side`.', {
229 node: decl
230 });
231 } else {
232 var ast = parser(value);
233
234 for (var _iterator = _createForOfIteratorHelperLoose(ast.nodes), _step; !(_step = _iterator()).done;) {
235 var i = _step.value;
236
237 if (i.type === 'function' && i.value === 'radial-gradient') {
238 for (var _iterator2 = _createForOfIteratorHelperLoose(i.nodes), _step2; !(_step2 = _iterator2()).done;) {
239 var word = _step2.value;
240
241 if (word.type === 'word') {
242 if (word.value === 'cover') {
243 result.warn('Gradient has outdated direction syntax. ' + 'Replace `cover` to `farthest-corner`.', {
244 node: decl
245 });
246 } else if (word.value === 'contain') {
247 result.warn('Gradient has outdated direction syntax. ' + 'Replace `contain` to `closest-side`.', {
248 node: decl
249 });
250 }
251 }
252 }
253 }
254 }
255 }
256 }
257
258 if (value.includes('linear-gradient')) {
259 if (OLD_LINEAR.test(value)) {
260 result.warn('Gradient has outdated direction syntax. ' + 'New syntax is like `to left` instead of `right`.', {
261 node: decl
262 });
263 }
264 }
265 }
266
267 if (SIZES.includes(decl.prop)) {
268 if (!decl.value.includes('-fill-available')) {
269 if (decl.value.includes('fill-available')) {
270 result.warn('Replace fill-available to stretch, ' + 'because spec had been changed', {
271 node: decl
272 });
273 } else if (decl.value.includes('fill')) {
274 var _ast = parser(value);
275
276 if (_ast.nodes.some(function (i) {
277 return i.type === 'word' && i.value === 'fill';
278 })) {
279 result.warn('Replace fill to stretch, because spec had been changed', {
280 node: decl
281 });
282 }
283 }
284 }
285 }
286
287 var prefixer;
288
289 if (decl.prop === 'transition' || decl.prop === 'transition-property') {
290 // Transition
291 return _this.prefixes.transition.add(decl, result);
292 } else if (decl.prop === 'align-self') {
293 // align-self flexbox or grid
294 var display = _this.displayType(decl);
295
296 if (display !== 'grid' && _this.prefixes.options.flexbox !== false) {
297 prefixer = _this.prefixes.add['align-self'];
298
299 if (prefixer && prefixer.prefixes) {
300 prefixer.process(decl);
301 }
302 }
303
304 if (_this.gridStatus(decl, result) !== false) {
305 prefixer = _this.prefixes.add['grid-row-align'];
306
307 if (prefixer && prefixer.prefixes) {
308 return prefixer.process(decl, result);
309 }
310 }
311 } else if (decl.prop === 'justify-self') {
312 // justify-self flexbox or grid
313 if (_this.gridStatus(decl, result) !== false) {
314 prefixer = _this.prefixes.add['grid-column-align'];
315
316 if (prefixer && prefixer.prefixes) {
317 return prefixer.process(decl, result);
318 }
319 }
320 } else if (decl.prop === 'place-self') {
321 prefixer = _this.prefixes.add['place-self'];
322
323 if (prefixer && prefixer.prefixes && _this.gridStatus(decl, result) !== false) {
324 return prefixer.process(decl, result);
325 }
326 } else {
327 // Properties
328 prefixer = _this.prefixes.add[decl.prop];
329
330 if (prefixer && prefixer.prefixes) {
331 return prefixer.process(decl, result);
332 }
333 }
334
335 return undefined;
336 }); // Insert grid-area prefixes. We need to be able to store the different
337 // rules as a data and hack API is not enough for this
338
339 if (this.gridStatus(css, result)) {
340 insertAreas(css, this.disabled);
341 } // Values
342
343
344 return css.walkDecls(function (decl) {
345 if (_this.disabledValue(decl, result)) return;
346
347 var unprefixed = _this.prefixes.unprefixed(decl.prop);
348
349 var list = _this.prefixes.values('add', unprefixed);
350
351 if (Array.isArray(list)) {
352 for (var _iterator3 = _createForOfIteratorHelperLoose(list), _step3; !(_step3 = _iterator3()).done;) {
353 var value = _step3.value;
354 if (value.process) value.process(decl, result);
355 }
356 }
357
358 Value.save(_this.prefixes, decl);
359 });
360 }
361 /**
362 * Remove unnecessary pefixes
363 */
364 ;
365
366 _proto.remove = function remove(css, result) {
367 var _this2 = this;
368
369 // At-rules
370 var resolution = this.prefixes.remove['@resolution'];
371 css.walkAtRules(function (rule, i) {
372 if (_this2.prefixes.remove["@" + rule.name]) {
373 if (!_this2.disabled(rule, result)) {
374 rule.parent.removeChild(i);
375 }
376 } else if (rule.name === 'media' && rule.params.includes('-resolution') && resolution) {
377 resolution.clean(rule);
378 }
379 }); // Selectors
380
381 var _loop = function _loop() {
382 var checker = _step4.value;
383 css.walkRules(function (rule, i) {
384 if (checker.check(rule)) {
385 if (!_this2.disabled(rule, result)) {
386 rule.parent.removeChild(i);
387 }
388 }
389 });
390 };
391
392 for (var _iterator4 = _createForOfIteratorHelperLoose(this.prefixes.remove.selectors), _step4; !(_step4 = _iterator4()).done;) {
393 _loop();
394 }
395
396 return css.walkDecls(function (decl, i) {
397 if (_this2.disabled(decl, result)) return;
398 var rule = decl.parent;
399
400 var unprefixed = _this2.prefixes.unprefixed(decl.prop); // Transition
401
402
403 if (decl.prop === 'transition' || decl.prop === 'transition-property') {
404 _this2.prefixes.transition.remove(decl);
405 } // Properties
406
407
408 if (_this2.prefixes.remove[decl.prop] && _this2.prefixes.remove[decl.prop].remove) {
409 var notHack = _this2.prefixes.group(decl).down(function (other) {
410 return _this2.prefixes.normalize(other.prop) === unprefixed;
411 });
412
413 if (unprefixed === 'flex-flow') {
414 notHack = true;
415 }
416
417 if (decl.prop === '-webkit-box-orient') {
418 var hacks = {
419 'flex-direction': true,
420 'flex-flow': true
421 };
422 if (!decl.parent.some(function (j) {
423 return hacks[j.prop];
424 })) return;
425 }
426
427 if (notHack && !_this2.withHackValue(decl)) {
428 if (decl.raw('before').includes('\n')) {
429 _this2.reduceSpaces(decl);
430 }
431
432 rule.removeChild(i);
433 return;
434 }
435 } // Values
436
437
438 for (var _iterator5 = _createForOfIteratorHelperLoose(_this2.prefixes.values('remove', unprefixed)), _step5; !(_step5 = _iterator5()).done;) {
439 var checker = _step5.value;
440 if (!checker.check) continue;
441 if (!checker.check(decl.value)) continue;
442 unprefixed = checker.unprefixed;
443
444 var _notHack = _this2.prefixes.group(decl).down(function (other) {
445 return other.value.includes(unprefixed);
446 });
447
448 if (_notHack) {
449 rule.removeChild(i);
450 return;
451 }
452 }
453 });
454 }
455 /**
456 * Some rare old values, which is not in standard
457 */
458 ;
459
460 _proto.withHackValue = function withHackValue(decl) {
461 return decl.prop === '-webkit-background-clip' && decl.value === 'text';
462 }
463 /**
464 * Check for grid/flexbox options.
465 */
466 ;
467
468 _proto.disabledValue = function disabledValue(node, result) {
469 if (this.gridStatus(node, result) === false && node.type === 'decl') {
470 if (node.prop === 'display' && node.value.includes('grid')) {
471 return true;
472 }
473 }
474
475 if (this.prefixes.options.flexbox === false && node.type === 'decl') {
476 if (node.prop === 'display' && node.value.includes('flex')) {
477 return true;
478 }
479 }
480
481 return this.disabled(node, result);
482 }
483 /**
484 * Check for grid/flexbox options.
485 */
486 ;
487
488 _proto.disabledDecl = function disabledDecl(node, result) {
489 if (this.gridStatus(node, result) === false && node.type === 'decl') {
490 if (node.prop.includes('grid') || node.prop === 'justify-items') {
491 return true;
492 }
493 }
494
495 if (this.prefixes.options.flexbox === false && node.type === 'decl') {
496 var other = ['order', 'justify-content', 'align-items', 'align-content'];
497
498 if (node.prop.includes('flex') || other.includes(node.prop)) {
499 return true;
500 }
501 }
502
503 return this.disabled(node, result);
504 }
505 /**
506 * Check for control comment and global options
507 */
508 ;
509
510 _proto.disabled = function disabled(node, result) {
511 if (!node) return false;
512
513 if (node._autoprefixerDisabled !== undefined) {
514 return node._autoprefixerDisabled;
515 }
516
517 if (node.parent) {
518 var p = node.prev();
519
520 if (p && p.type === 'comment' && IGNORE_NEXT.test(p.text)) {
521 node._autoprefixerDisabled = true;
522 node._autoprefixerSelfDisabled = true;
523 return true;
524 }
525 }
526
527 var value = null;
528
529 if (node.nodes) {
530 var status;
531 node.each(function (i) {
532 if (i.type !== 'comment') return;
533
534 if (/(!\s*)?autoprefixer:\s*(off|on)/i.test(i.text)) {
535 if (typeof status !== 'undefined') {
536 result.warn('Second Autoprefixer control comment ' + 'was ignored. Autoprefixer applies control ' + 'comment to whole block, not to next rules.', {
537 node: i
538 });
539 } else {
540 status = /on/i.test(i.text);
541 }
542 }
543 });
544
545 if (status !== undefined) {
546 value = !status;
547 }
548 }
549
550 if (!node.nodes || value === null) {
551 if (node.parent) {
552 var isParentDisabled = this.disabled(node.parent, result);
553
554 if (node.parent._autoprefixerSelfDisabled === true) {
555 value = false;
556 } else {
557 value = isParentDisabled;
558 }
559 } else {
560 value = false;
561 }
562 }
563
564 node._autoprefixerDisabled = value;
565 return value;
566 }
567 /**
568 * Normalize spaces in cascade declaration group
569 */
570 ;
571
572 _proto.reduceSpaces = function reduceSpaces(decl) {
573 var stop = false;
574 this.prefixes.group(decl).up(function () {
575 stop = true;
576 return true;
577 });
578
579 if (stop) {
580 return;
581 }
582
583 var parts = decl.raw('before').split('\n');
584 var prevMin = parts[parts.length - 1].length;
585 var diff = false;
586 this.prefixes.group(decl).down(function (other) {
587 parts = other.raw('before').split('\n');
588 var last = parts.length - 1;
589
590 if (parts[last].length > prevMin) {
591 if (diff === false) {
592 diff = parts[last].length - prevMin;
593 }
594
595 parts[last] = parts[last].slice(0, -diff);
596 other.raws.before = parts.join('\n');
597 }
598 });
599 }
600 /**
601 * Is it flebox or grid rule
602 */
603 ;
604
605 _proto.displayType = function displayType(decl) {
606 for (var _iterator6 = _createForOfIteratorHelperLoose(decl.parent.nodes), _step6; !(_step6 = _iterator6()).done;) {
607 var i = _step6.value;
608
609 if (i.prop !== 'display') {
610 continue;
611 }
612
613 if (i.value.includes('flex')) {
614 return 'flex';
615 }
616
617 if (i.value.includes('grid')) {
618 return 'grid';
619 }
620 }
621
622 return false;
623 }
624 /**
625 * Set grid option via control comment
626 */
627 ;
628
629 _proto.gridStatus = function gridStatus(node, result) {
630 if (!node) return false;
631
632 if (node._autoprefixerGridStatus !== undefined) {
633 return node._autoprefixerGridStatus;
634 }
635
636 var value = null;
637
638 if (node.nodes) {
639 var status;
640 node.each(function (i) {
641 if (i.type !== 'comment') return;
642
643 if (GRID_REGEX.test(i.text)) {
644 var hasAutoplace = /:\s*autoplace/i.test(i.text);
645 var noAutoplace = /no-autoplace/i.test(i.text);
646
647 if (typeof status !== 'undefined') {
648 result.warn('Second Autoprefixer grid control comment was ' + 'ignored. Autoprefixer applies control comments to the whole ' + 'block, not to the next rules.', {
649 node: i
650 });
651 } else if (hasAutoplace) {
652 status = 'autoplace';
653 } else if (noAutoplace) {
654 status = true;
655 } else {
656 status = /on/i.test(i.text);
657 }
658 }
659 });
660
661 if (status !== undefined) {
662 value = status;
663 }
664 }
665
666 if (node.type === 'atrule' && node.name === 'supports') {
667 var params = node.params;
668
669 if (params.includes('grid') && params.includes('auto')) {
670 value = false;
671 }
672 }
673
674 if (!node.nodes || value === null) {
675 if (node.parent) {
676 var isParentGrid = this.gridStatus(node.parent, result);
677
678 if (node.parent._autoprefixerSelfDisabled === true) {
679 value = false;
680 } else {
681 value = isParentGrid;
682 }
683 } else if (typeof this.prefixes.options.grid !== 'undefined') {
684 value = this.prefixes.options.grid;
685 } else if (typeof process.env.AUTOPREFIXER_GRID !== 'undefined') {
686 if (process.env.AUTOPREFIXER_GRID === 'autoplace') {
687 value = 'autoplace';
688 } else {
689 value = true;
690 }
691 } else {
692 value = false;
693 }
694 }
695
696 node._autoprefixerGridStatus = value;
697 return value;
698 };
699
700 return Processor;
701}();
702
703module.exports = Processor;
Note: See TracBrowser for help on using the repository browser.