source: trip-planner-front/node_modules/postcss-merge-rules/dist/lib/ensureCompatibility.js

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

primeNG components

  • Property mode set to 100644
File size: 5.9 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.sameVendor = sameVendor;
7exports.noVendor = noVendor;
8exports.ensureCompatibility = ensureCompatibility;
9exports.pseudoElements = void 0;
10
11var _caniuseApi = require("caniuse-api");
12
13var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
14
15function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
17const simpleSelectorRe = /^#?[-._a-z0-9 ]+$/i;
18const cssSel2 = 'css-sel2';
19const cssSel3 = 'css-sel3';
20const cssGencontent = 'css-gencontent';
21const cssFirstLetter = 'css-first-letter';
22const cssFirstLine = 'css-first-line';
23const cssInOutOfRange = 'css-in-out-of-range';
24const formValidation = 'form-validation';
25const vendorPrefix = /-(ah|apple|atsc|epub|hp|khtml|moz|ms|o|rim|ro|tc|wap|webkit|xv)-/;
26/**
27 * @param {string} selector
28 * @return {string[]}
29 */
30
31function filterPrefixes(selector) {
32 return selector.match(vendorPrefix);
33} // Internet Explorer use :-ms-input-placeholder.
34// Microsoft Edge use ::-ms-input-placeholder.
35
36
37const findMsInputPlaceholder = selector => ~selector.search(/-ms-input-placeholder/i);
38
39function sameVendor(selectorsA, selectorsB) {
40 let same = selectors => selectors.map(filterPrefixes).join();
41
42 let findMsVendor = selectors => selectors.find(findMsInputPlaceholder);
43
44 return same(selectorsA) === same(selectorsB) && !(findMsVendor(selectorsA) && findMsVendor(selectorsB));
45}
46/**
47 * @param {string} selector
48 * @return {boolean}
49 */
50
51
52function noVendor(selector) {
53 return !vendorPrefix.test(selector);
54}
55
56const pseudoElements = {
57 ':active': cssSel2,
58 ':after': cssGencontent,
59 ':any-link': 'css-any-link',
60 ':before': cssGencontent,
61 ':checked': cssSel3,
62 ':default': 'css-default-pseudo',
63 ':dir': 'css-dir-pseudo',
64 ':disabled': cssSel3,
65 ':empty': cssSel3,
66 ':enabled': cssSel3,
67 ':first-child': cssSel2,
68 ':first-letter': cssFirstLetter,
69 ':first-line': cssFirstLine,
70 ':first-of-type': cssSel3,
71 ':focus': cssSel2,
72 ':focus-within': 'css-focus-within',
73 ':focus-visible': 'css-focus-visible',
74 ':has': 'css-has',
75 ':hover': cssSel2,
76 ':in-range': cssInOutOfRange,
77 ':indeterminate': 'css-indeterminate-pseudo',
78 ':invalid': formValidation,
79 ':is': 'css-matches-pseudo',
80 ':lang': cssSel2,
81 ':last-child': cssSel3,
82 ':last-of-type': cssSel3,
83 ':link': cssSel2,
84 ':matches': 'css-matches-pseudo',
85 ':not': cssSel3,
86 ':nth-child': cssSel3,
87 ':nth-last-child': cssSel3,
88 ':nth-last-of-type': cssSel3,
89 ':nth-of-type': cssSel3,
90 ':only-child': cssSel3,
91 ':only-of-type': cssSel3,
92 ':optional': 'css-optional-pseudo',
93 ':out-of-range': cssInOutOfRange,
94 ':placeholder-shown': 'css-placeholder-shown',
95 ':required': formValidation,
96 ':root': cssSel3,
97 ':target': cssSel3,
98 '::after': cssGencontent,
99 '::backdrop': 'dialog',
100 '::before': cssGencontent,
101 '::first-letter': cssFirstLetter,
102 '::first-line': cssFirstLine,
103 '::marker': 'css-marker-pseudo',
104 '::placeholder': 'css-placeholder',
105 '::selection': 'css-selection',
106 ':valid': formValidation,
107 ':visited': cssSel2
108};
109exports.pseudoElements = pseudoElements;
110
111function isCssMixin(selector) {
112 return selector[selector.length - 1] === ':';
113}
114
115function isHostPseudoClass(selector) {
116 return selector.includes(':host');
117}
118
119const isSupportedCache = {}; // Move to util in future
120
121function isSupportedCached(feature, browsers) {
122 const key = JSON.stringify({
123 feature,
124 browsers
125 });
126 let result = isSupportedCache[key];
127
128 if (!result) {
129 result = (0, _caniuseApi.isSupported)(feature, browsers);
130 isSupportedCache[key] = result;
131 }
132
133 return result;
134}
135
136function ensureCompatibility(selectors, browsers, compatibilityCache) {
137 // Should not merge mixins
138 if (selectors.some(isCssMixin)) {
139 return false;
140 } // Should not merge :host selector https://github.com/angular/angular-cli/issues/18672
141
142
143 if (selectors.some(isHostPseudoClass)) {
144 return false;
145 }
146
147 return selectors.every(selector => {
148 if (simpleSelectorRe.test(selector)) {
149 return true;
150 }
151
152 if (compatibilityCache && selector in compatibilityCache) {
153 return compatibilityCache[selector];
154 }
155
156 let compatible = true;
157 (0, _postcssSelectorParser.default)(ast => {
158 ast.walk(node => {
159 const {
160 type,
161 value
162 } = node;
163
164 if (type === 'pseudo') {
165 const entry = pseudoElements[value];
166
167 if (!entry && noVendor(value)) {
168 compatible = false;
169 }
170
171 if (entry && compatible) {
172 compatible = isSupportedCached(entry, browsers);
173 }
174 }
175
176 if (type === 'combinator') {
177 if (~value.indexOf('~')) {
178 compatible = isSupportedCached(cssSel3, browsers);
179 }
180
181 if (~value.indexOf('>') || ~value.indexOf('+')) {
182 compatible = isSupportedCached(cssSel2, browsers);
183 }
184 }
185
186 if (type === 'attribute' && node.attribute) {
187 // [foo]
188 if (!node.operator) {
189 compatible = isSupportedCached(cssSel2, browsers);
190 }
191
192 if (value) {
193 // [foo="bar"], [foo~="bar"], [foo|="bar"]
194 if (~['=', '~=', '|='].indexOf(node.operator)) {
195 compatible = isSupportedCached(cssSel2, browsers);
196 } // [foo^="bar"], [foo$="bar"], [foo*="bar"]
197
198
199 if (~['^=', '$=', '*='].indexOf(node.operator)) {
200 compatible = isSupportedCached(cssSel3, browsers);
201 }
202 } // [foo="bar" i]
203
204
205 if (node.insensitive) {
206 compatible = isSupportedCached('css-case-insensitive', browsers);
207 }
208 }
209
210 if (!compatible) {
211 // If this node was not compatible,
212 // break out early from walking the rest
213 return false;
214 }
215 });
216 }).processSync(selector);
217
218 if (compatibilityCache) {
219 compatibilityCache[selector] = compatible;
220 }
221
222 return compatible;
223 });
224}
Note: See TracBrowser for help on using the repository browser.