@nativescript/core 8.8.0-alpha.2 → 8.8.0-embed.1-next-07-01-2024-9752585063
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/application/application-common.d.ts +2 -1
- package/application/application-common.js +21 -7
- package/application/application-common.js.map +1 -1
- package/application/application.android.d.ts +1 -1
- package/application/application.android.js +4 -0
- package/application/application.android.js.map +1 -1
- package/application/application.ios.d.ts +1 -1
- package/application/application.ios.js +3 -2
- package/application/application.ios.js.map +1 -1
- package/config/config.interface.d.ts +6 -0
- package/css/parser.d.ts +0 -38
- package/css/parser.js +0 -108
- package/css/parser.js.map +1 -1
- package/css/reworkcss.d.ts +15 -1
- package/css-mediaquery/index.d.ts +27 -0
- package/css-mediaquery/index.js +118 -0
- package/css-mediaquery/index.js.map +1 -0
- package/globals/index.js +2 -0
- package/globals/index.js.map +1 -1
- package/media-query-list/index.d.ts +21 -0
- package/media-query-list/index.js +169 -0
- package/media-query-list/index.js.map +1 -0
- package/package.json +2 -1
- package/platform/{index.android.d.ts → device/index.android.d.ts} +1 -16
- package/platform/{index.android.js → device/index.android.js} +4 -47
- package/platform/device/index.android.js.map +1 -0
- package/platform/device/index.d.ts +70 -0
- package/platform/{index.ios.d.ts → device/index.ios.d.ts} +1 -14
- package/platform/{index.ios.js → device/index.ios.js} +1 -34
- package/platform/device/index.ios.js.map +1 -0
- package/platform/index.d.ts +2 -118
- package/platform/index.js +4 -0
- package/platform/index.js.map +1 -0
- package/platform/screen/index.android.d.ts +16 -0
- package/platform/screen/index.android.js +41 -0
- package/platform/screen/index.android.js.map +1 -0
- package/platform/screen/index.d.ts +48 -0
- package/platform/screen/index.ios.d.ts +15 -0
- package/platform/screen/index.ios.js +35 -0
- package/platform/screen/index.ios.js.map +1 -0
- package/platforms/android/widgets-release.aar +0 -0
- package/profiling/index.js.map +1 -1
- package/trace/index.d.ts +1 -0
- package/trace/index.js +2 -1
- package/trace/index.js.map +1 -1
- package/ui/action-bar/index.android.d.ts +0 -2
- package/ui/action-bar/index.android.js +0 -26
- package/ui/action-bar/index.android.js.map +1 -1
- package/ui/action-bar/index.ios.js +1 -1
- package/ui/action-bar/index.ios.js.map +1 -1
- package/ui/activity-indicator/index.android.js +3 -2
- package/ui/activity-indicator/index.android.js.map +1 -1
- package/ui/animation/keyframe-animation.d.ts +3 -0
- package/ui/animation/keyframe-animation.js +4 -2
- package/ui/animation/keyframe-animation.js.map +1 -1
- package/ui/builder/index.js.map +1 -1
- package/ui/builder/xml2ui.js.map +1 -1
- package/ui/button/index.android.d.ts +0 -2
- package/ui/button/index.android.js +0 -26
- package/ui/button/index.android.js.map +1 -1
- package/ui/core/view/index.android.d.ts +1 -1
- package/ui/core/view/index.android.js +49 -45
- package/ui/core/view/index.android.js.map +1 -1
- package/ui/core/view/view-common.d.ts +1 -1
- package/ui/core/view/view-common.js.map +1 -1
- package/ui/core/view/view-helper/index.android.d.ts +7 -0
- package/ui/core/view/view-helper/index.android.js +53 -0
- package/ui/core/view/view-helper/index.android.js.map +1 -1
- package/ui/core/view/view-helper/index.d.ts +10 -0
- package/ui/core/view/view-helper/index.ios.d.ts +1 -0
- package/ui/core/view/view-helper/index.ios.js +1 -0
- package/ui/core/view/view-helper/index.ios.js.map +1 -1
- package/ui/core/view-base/index.d.ts +7 -0
- package/ui/core/view-base/index.js +11 -2
- package/ui/core/view-base/index.js.map +1 -1
- package/ui/embedding/index.android.d.ts +4 -0
- package/ui/embedding/index.android.js +14 -0
- package/ui/embedding/index.android.js.map +1 -0
- package/ui/embedding/index.d.ts +10 -0
- package/ui/embedding/index.ios.d.ts +1 -0
- package/ui/embedding/index.ios.js +4 -0
- package/ui/embedding/index.ios.js.map +1 -0
- package/ui/frame/activity.android.js +106 -47
- package/ui/frame/activity.android.js.map +1 -1
- package/ui/frame/callbacks/activity-callbacks.d.ts +19 -0
- package/ui/frame/callbacks/activity-callbacks.js +301 -0
- package/ui/frame/callbacks/activity-callbacks.js.map +1 -0
- package/ui/frame/callbacks/fragment-callbacks.d.ts +18 -0
- package/ui/frame/callbacks/fragment-callbacks.js +323 -0
- package/ui/frame/callbacks/fragment-callbacks.js.map +1 -0
- package/ui/frame/fragment.android.d.ts +3 -1
- package/ui/frame/fragment.android.js +40 -3
- package/ui/frame/fragment.android.js.map +1 -1
- package/ui/frame/fragment.d.ts +5 -0
- package/ui/frame/fragment.ios.d.ts +3 -0
- package/ui/frame/fragment.ios.js +4 -0
- package/ui/frame/fragment.ios.js.map +1 -0
- package/ui/frame/index.android.d.ts +3 -2
- package/ui/frame/index.android.js +6 -622
- package/ui/frame/index.android.js.map +1 -1
- package/ui/frame/index.d.ts +18 -0
- package/ui/image/image-common.d.ts +3 -11
- package/ui/image/image-common.js +5 -3
- package/ui/image/image-common.js.map +1 -1
- package/ui/image/index.d.ts +1 -1
- package/ui/image/index.ios.js +12 -9
- package/ui/image/index.ios.js.map +1 -1
- package/ui/image/symbol-effects-common.d.ts +36 -0
- package/ui/image/symbol-effects-common.js +35 -0
- package/ui/image/symbol-effects-common.js.map +1 -0
- package/ui/image/symbol-effects.android.d.ts +4 -0
- package/ui/image/symbol-effects.android.js +8 -0
- package/ui/image/symbol-effects.android.js.map +1 -0
- package/ui/image/symbol-effects.d.ts +13 -0
- package/ui/image/symbol-effects.ios.d.ts +2 -0
- package/ui/image/symbol-effects.ios.js +93 -0
- package/ui/image/symbol-effects.ios.js.map +1 -0
- package/ui/index.d.ts +3 -2
- package/ui/index.js +3 -2
- package/ui/index.js.map +1 -1
- package/ui/layouts/grid-layout/grid-layout-common.d.ts +7 -2
- package/ui/layouts/grid-layout/grid-layout-common.js +32 -6
- package/ui/layouts/grid-layout/grid-layout-common.js.map +1 -1
- package/ui/layouts/grid-layout/index.android.d.ts +9 -3
- package/ui/layouts/grid-layout/index.android.js +65 -38
- package/ui/layouts/grid-layout/index.android.js.map +1 -1
- package/ui/list-picker/index.android.js.map +1 -1
- package/ui/page/index.android.js +5 -2
- package/ui/page/index.android.js.map +1 -1
- package/ui/progress/index.android.js +5 -4
- package/ui/progress/index.android.js.map +1 -1
- package/ui/segmented-bar/index.android.js +4 -13
- package/ui/segmented-bar/index.android.js.map +1 -1
- package/ui/slider/index.android.js +7 -4
- package/ui/slider/index.android.js.map +1 -1
- package/ui/styling/css-selector.d.ts +88 -32
- package/ui/styling/css-selector.js +480 -130
- package/ui/styling/css-selector.js.map +1 -1
- package/ui/styling/font-common.js.map +1 -1
- package/ui/styling/style-properties.js +1 -1
- package/ui/styling/style-properties.js.map +1 -1
- package/ui/styling/style-scope.js +275 -131
- package/ui/styling/style-scope.js.map +1 -1
- package/ui/switch/index.android.js +7 -6
- package/ui/switch/index.android.js.map +1 -1
- package/ui/tab-view/index.android.js +10 -14
- package/ui/tab-view/index.android.js.map +1 -1
- package/ui/transition/page-transition.android.d.ts +2 -1
- package/ui/transition/page-transition.android.js +11 -4
- package/ui/transition/page-transition.android.js.map +1 -1
- package/ui/utils.d.ts +5 -1
- package/ui/utils.ios.d.ts +1 -10
- package/ui/utils.ios.js.map +1 -1
- package/platform/index.android.js.map +0 -1
- package/platform/index.ios.js.map +0 -1
|
@@ -1,8 +1,30 @@
|
|
|
1
|
+
import { parse as convertToCSSWhatSelector } from 'css-what';
|
|
1
2
|
import '../../globals';
|
|
2
3
|
import { isCssVariable } from '../core/properties';
|
|
3
4
|
import { isNullOrUndefined } from '../../utils/types';
|
|
4
|
-
import { parseSelector } from '../../css/parser';
|
|
5
5
|
import { CSSUtils } from '../../css/system-classes';
|
|
6
|
+
import { checkIfMediaQueryMatches } from '../../media-query-list';
|
|
7
|
+
export const MEDIA_QUERY_SEPARATOR = '&&';
|
|
8
|
+
var Combinator;
|
|
9
|
+
(function (Combinator) {
|
|
10
|
+
Combinator["descendant"] = " ";
|
|
11
|
+
Combinator["child"] = ">";
|
|
12
|
+
Combinator["adjacent"] = "+";
|
|
13
|
+
Combinator["sibling"] = "~";
|
|
14
|
+
// Not supported
|
|
15
|
+
Combinator["parent"] = "<";
|
|
16
|
+
Combinator["column-combinator"] = "||";
|
|
17
|
+
})(Combinator || (Combinator = {}));
|
|
18
|
+
var AttributeSelectorOperator;
|
|
19
|
+
(function (AttributeSelectorOperator) {
|
|
20
|
+
AttributeSelectorOperator["exists"] = "";
|
|
21
|
+
AttributeSelectorOperator["equals"] = "=";
|
|
22
|
+
AttributeSelectorOperator["start"] = "^=";
|
|
23
|
+
AttributeSelectorOperator["end"] = "$=";
|
|
24
|
+
AttributeSelectorOperator["any"] = "*=";
|
|
25
|
+
AttributeSelectorOperator["element"] = "~=";
|
|
26
|
+
AttributeSelectorOperator["hyphen"] = "|=";
|
|
27
|
+
})(AttributeSelectorOperator || (AttributeSelectorOperator = {}));
|
|
6
28
|
var Match;
|
|
7
29
|
(function (Match) {
|
|
8
30
|
/**
|
|
@@ -14,7 +36,22 @@ var Match;
|
|
|
14
36
|
*/
|
|
15
37
|
Match.Static = false;
|
|
16
38
|
})(Match || (Match = {}));
|
|
17
|
-
function
|
|
39
|
+
function eachNodePreviousGeneralSibling(node, callback) {
|
|
40
|
+
if (!node.parent || !node.parent.getChildIndex || !node.parent.getChildAt || !node.parent.getChildrenCount) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const nodeIndex = node.parent.getChildIndex(node);
|
|
44
|
+
if (nodeIndex === 0) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const count = node.parent.getChildrenCount();
|
|
48
|
+
let retVal = true;
|
|
49
|
+
for (let i = nodeIndex - 1; i >= 0 && retVal; i--) {
|
|
50
|
+
const sibling = node.parent.getChildAt(i);
|
|
51
|
+
retVal = callback(sibling);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function getNodePreviousDirectSibling(node) {
|
|
18
55
|
if (!node.parent || !node.parent.getChildIndex || !node.parent.getChildAt) {
|
|
19
56
|
return null;
|
|
20
57
|
}
|
|
@@ -33,7 +70,19 @@ function SelectorProperties(specificity, rarity, dynamic = false) {
|
|
|
33
70
|
return cls;
|
|
34
71
|
};
|
|
35
72
|
}
|
|
36
|
-
|
|
73
|
+
function FunctionalPseudoClassProperties(specificity, rarity, pseudoSelectorListType) {
|
|
74
|
+
return (cls) => {
|
|
75
|
+
cls.prototype.specificity = specificity;
|
|
76
|
+
cls.prototype.rarity = rarity;
|
|
77
|
+
cls.prototype.combinator = undefined;
|
|
78
|
+
cls.prototype.dynamic = false;
|
|
79
|
+
cls.prototype.pseudoSelectorListType = pseudoSelectorListType;
|
|
80
|
+
return cls;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export class SelectorBase {
|
|
84
|
+
}
|
|
85
|
+
let SelectorCore = class SelectorCore extends SelectorBase {
|
|
37
86
|
lookupSort(sorter, base) {
|
|
38
87
|
sorter.sortAsUniversal(base || this);
|
|
39
88
|
}
|
|
@@ -70,7 +119,7 @@ let InvalidSelector = class InvalidSelector extends SimpleSelector {
|
|
|
70
119
|
this.e = e;
|
|
71
120
|
}
|
|
72
121
|
toString() {
|
|
73
|
-
return
|
|
122
|
+
return `<${this.e}>`;
|
|
74
123
|
}
|
|
75
124
|
match(node) {
|
|
76
125
|
return false;
|
|
@@ -159,52 +208,55 @@ ClassSelector = __decorate([
|
|
|
159
208
|
], ClassSelector);
|
|
160
209
|
export { ClassSelector };
|
|
161
210
|
let AttributeSelector = class AttributeSelector extends SimpleSelector {
|
|
162
|
-
constructor(attribute, test, value) {
|
|
211
|
+
constructor(attribute, test, value, ignoreCase) {
|
|
163
212
|
super();
|
|
164
213
|
this.attribute = attribute;
|
|
165
214
|
this.test = test;
|
|
166
215
|
this.value = value;
|
|
167
|
-
|
|
168
|
-
// HasAttribute
|
|
169
|
-
this.match = (node) => !isNullOrUndefined(node[attribute]);
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
if (!value) {
|
|
173
|
-
this.match = (node) => false;
|
|
174
|
-
}
|
|
175
|
-
this.match = (node) => {
|
|
176
|
-
const attr = node[attribute] + '';
|
|
177
|
-
if (test === '=') {
|
|
178
|
-
// Equals
|
|
179
|
-
return attr === value;
|
|
180
|
-
}
|
|
181
|
-
if (test === '^=') {
|
|
182
|
-
// PrefixMatch
|
|
183
|
-
return attr.startsWith(value);
|
|
184
|
-
}
|
|
185
|
-
if (test === '$=') {
|
|
186
|
-
// SuffixMatch
|
|
187
|
-
return attr.endsWith(value);
|
|
188
|
-
}
|
|
189
|
-
if (test === '*=') {
|
|
190
|
-
// SubstringMatch
|
|
191
|
-
return attr.indexOf(value) !== -1;
|
|
192
|
-
}
|
|
193
|
-
if (test === '~=') {
|
|
194
|
-
// Includes
|
|
195
|
-
const words = attr.split(' ');
|
|
196
|
-
return words && words.indexOf(value) !== -1;
|
|
197
|
-
}
|
|
198
|
-
if (test === '|=') {
|
|
199
|
-
// DashMatch
|
|
200
|
-
return attr === value || attr.startsWith(value + '-');
|
|
201
|
-
}
|
|
202
|
-
};
|
|
216
|
+
this.ignoreCase = ignoreCase;
|
|
203
217
|
}
|
|
204
218
|
toString() {
|
|
205
|
-
return `[${this.attribute}${wrap(this.test)}${
|
|
219
|
+
return `[${this.attribute}${wrap(AttributeSelectorOperator[this.test] ?? this.test)}${this.value || ''}]${wrap(this.combinator)}`;
|
|
206
220
|
}
|
|
207
221
|
match(node) {
|
|
222
|
+
let attr = node[this.attribute];
|
|
223
|
+
if (this.test === 'exists') {
|
|
224
|
+
return !isNullOrUndefined(attr);
|
|
225
|
+
}
|
|
226
|
+
if (!this.value) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
// Now, convert value to string
|
|
230
|
+
attr += '';
|
|
231
|
+
if (this.ignoreCase) {
|
|
232
|
+
attr = attr.toLowerCase();
|
|
233
|
+
this.value = this.value.toLowerCase();
|
|
234
|
+
}
|
|
235
|
+
// =
|
|
236
|
+
if (this.test === 'equals') {
|
|
237
|
+
return attr === this.value;
|
|
238
|
+
}
|
|
239
|
+
// ^=
|
|
240
|
+
if (this.test === 'start') {
|
|
241
|
+
return attr.startsWith(this.value);
|
|
242
|
+
}
|
|
243
|
+
// $=
|
|
244
|
+
if (this.test === 'end') {
|
|
245
|
+
return attr.endsWith(this.value);
|
|
246
|
+
}
|
|
247
|
+
// *=
|
|
248
|
+
if (this.test === 'any') {
|
|
249
|
+
return attr.indexOf(this.value) !== -1;
|
|
250
|
+
}
|
|
251
|
+
// ~=
|
|
252
|
+
if (this.test === 'element') {
|
|
253
|
+
const words = attr.split(' ');
|
|
254
|
+
return words && words.indexOf(this.value) !== -1;
|
|
255
|
+
}
|
|
256
|
+
// |=
|
|
257
|
+
if (this.test === 'hyphen') {
|
|
258
|
+
return attr === this.value || attr.startsWith(this.value + '-');
|
|
259
|
+
}
|
|
208
260
|
return false;
|
|
209
261
|
}
|
|
210
262
|
mayMatch(node) {
|
|
@@ -216,7 +268,7 @@ let AttributeSelector = class AttributeSelector extends SimpleSelector {
|
|
|
216
268
|
};
|
|
217
269
|
AttributeSelector = __decorate([
|
|
218
270
|
SelectorProperties(10 /* Specificity.Attribute */, 0 /* Rarity.Attribute */, Match.Dynamic),
|
|
219
|
-
__metadata("design:paramtypes", [String, String, String])
|
|
271
|
+
__metadata("design:paramtypes", [String, String, String, Boolean])
|
|
220
272
|
], AttributeSelector);
|
|
221
273
|
export { AttributeSelector };
|
|
222
274
|
let PseudoClassSelector = class PseudoClassSelector extends SimpleSelector {
|
|
@@ -242,12 +294,100 @@ PseudoClassSelector = __decorate([
|
|
|
242
294
|
__metadata("design:paramtypes", [String])
|
|
243
295
|
], PseudoClassSelector);
|
|
244
296
|
export { PseudoClassSelector };
|
|
297
|
+
export class FunctionalPseudoClassSelector extends PseudoClassSelector {
|
|
298
|
+
constructor(cssPseudoClass, dataType) {
|
|
299
|
+
super(cssPseudoClass);
|
|
300
|
+
const selectors = [];
|
|
301
|
+
const needsHighestSpecificity = this.specificity === -1 /* Specificity.SelectorListHighest */;
|
|
302
|
+
let specificity = 0;
|
|
303
|
+
if (Array.isArray(dataType)) {
|
|
304
|
+
for (const asts of dataType) {
|
|
305
|
+
const selector = createSelectorFromAst(asts);
|
|
306
|
+
if (selector instanceof InvalidSelector) {
|
|
307
|
+
// Only forgiving selector list can ignore invalid selectors
|
|
308
|
+
if (this.selectorListType !== 1 /* PseudoClassSelectorList.Forgiving */) {
|
|
309
|
+
selectors.splice(0);
|
|
310
|
+
specificity = 0;
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
// The specificity of some pseudo-classes is replaced by the specificity of the most specific selector in its comma-separated argument of selectors
|
|
316
|
+
if (needsHighestSpecificity && selector.specificity > specificity) {
|
|
317
|
+
specificity = selector.specificity;
|
|
318
|
+
}
|
|
319
|
+
selectors.push(selector);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
this.selectors = selectors;
|
|
323
|
+
this.specificity = specificity;
|
|
324
|
+
// Functional pseudo-classes become dynamic based on selectors in selector list
|
|
325
|
+
this.dynamic = this.selectors.some((sel) => sel.dynamic);
|
|
326
|
+
}
|
|
327
|
+
toString() {
|
|
328
|
+
return `:${this.cssPseudoClass}(${this.selectors.join(', ')})${wrap(this.combinator)}`;
|
|
329
|
+
}
|
|
330
|
+
match(node) {
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
mayMatch(node) {
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
trackChanges(node, map) {
|
|
337
|
+
this.selectors.forEach((sel) => sel.trackChanges(node, map));
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
let NotFunctionalPseudoClassSelector = class NotFunctionalPseudoClassSelector extends FunctionalPseudoClassSelector {
|
|
341
|
+
match(node) {
|
|
342
|
+
return !this.selectors.some((sel) => sel.match(node));
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
NotFunctionalPseudoClassSelector = __decorate([
|
|
346
|
+
FunctionalPseudoClassProperties(-1 /* Specificity.SelectorListHighest */, 0 /* Rarity.PseudoClass */, 0 /* PseudoClassSelectorList.Regular */)
|
|
347
|
+
], NotFunctionalPseudoClassSelector);
|
|
348
|
+
export { NotFunctionalPseudoClassSelector };
|
|
349
|
+
let IsFunctionalPseudoClassSelector = class IsFunctionalPseudoClassSelector extends FunctionalPseudoClassSelector {
|
|
350
|
+
match(node) {
|
|
351
|
+
return this.selectors.some((sel) => sel.match(node));
|
|
352
|
+
}
|
|
353
|
+
lookupSort(sorter, base) {
|
|
354
|
+
// A faster lookup can be performed when selector list contains just a single selector
|
|
355
|
+
if (this.selectors.length === 1) {
|
|
356
|
+
this.selectors[0].lookupSort(sorter, base || this);
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
super.lookupSort(sorter, base || this);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
IsFunctionalPseudoClassSelector = __decorate([
|
|
364
|
+
FunctionalPseudoClassProperties(-1 /* Specificity.SelectorListHighest */, 0 /* Rarity.PseudoClass */, 1 /* PseudoClassSelectorList.Forgiving */)
|
|
365
|
+
], IsFunctionalPseudoClassSelector);
|
|
366
|
+
export { IsFunctionalPseudoClassSelector };
|
|
367
|
+
let WhereFunctionalPseudoClassSelector = class WhereFunctionalPseudoClassSelector extends FunctionalPseudoClassSelector {
|
|
368
|
+
match(node) {
|
|
369
|
+
return this.selectors.some((sel) => sel.match(node));
|
|
370
|
+
}
|
|
371
|
+
lookupSort(sorter, base) {
|
|
372
|
+
// A faster lookup can be performed when selector list contains just a single selector
|
|
373
|
+
if (this.selectors.length === 1) {
|
|
374
|
+
this.selectors[0].lookupSort(sorter, base || this);
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
super.lookupSort(sorter, base || this);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
WhereFunctionalPseudoClassSelector = __decorate([
|
|
382
|
+
FunctionalPseudoClassProperties(0 /* Specificity.Zero */, 0 /* Rarity.PseudoClass */, 1 /* PseudoClassSelectorList.Forgiving */)
|
|
383
|
+
], WhereFunctionalPseudoClassSelector);
|
|
384
|
+
export { WhereFunctionalPseudoClassSelector };
|
|
245
385
|
export class SimpleSelectorSequence extends SimpleSelector {
|
|
246
386
|
constructor(selectors) {
|
|
247
387
|
super();
|
|
248
388
|
this.selectors = selectors;
|
|
249
389
|
this.specificity = selectors.reduce((sum, sel) => sel.specificity + sum, 0);
|
|
250
|
-
this.head =
|
|
390
|
+
this.head = selectors.reduce((prev, curr) => (!prev || curr.rarity > prev.rarity ? curr : prev), null);
|
|
251
391
|
this.dynamic = selectors.some((sel) => sel.dynamic);
|
|
252
392
|
}
|
|
253
393
|
toString() {
|
|
@@ -266,34 +406,41 @@ export class SimpleSelectorSequence extends SimpleSelector {
|
|
|
266
406
|
this.head.lookupSort(sorter, base || this);
|
|
267
407
|
}
|
|
268
408
|
}
|
|
269
|
-
export class
|
|
409
|
+
export class ComplexSelector extends SelectorCore {
|
|
270
410
|
constructor(selectors) {
|
|
271
411
|
super();
|
|
272
412
|
this.selectors = selectors;
|
|
273
|
-
|
|
274
|
-
let
|
|
275
|
-
let lastGroup;
|
|
413
|
+
let siblingsToGroup;
|
|
414
|
+
let currentGroup;
|
|
276
415
|
const groups = [];
|
|
277
416
|
this.specificity = 0;
|
|
278
417
|
this.dynamic = false;
|
|
279
|
-
for (let i = selectors.length - 1; i
|
|
418
|
+
for (let i = selectors.length - 1; i >= 0; i--) {
|
|
280
419
|
const sel = selectors[i];
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
420
|
+
switch (sel.combinator) {
|
|
421
|
+
case undefined:
|
|
422
|
+
case Combinator.descendant:
|
|
423
|
+
siblingsToGroup = [];
|
|
424
|
+
currentGroup = [siblingsToGroup];
|
|
425
|
+
groups.push(currentGroup);
|
|
426
|
+
break;
|
|
427
|
+
case Combinator.child:
|
|
428
|
+
siblingsToGroup = [];
|
|
429
|
+
currentGroup.push(siblingsToGroup);
|
|
430
|
+
break;
|
|
431
|
+
case Combinator.adjacent:
|
|
432
|
+
case Combinator.sibling:
|
|
433
|
+
break;
|
|
434
|
+
default:
|
|
435
|
+
throw new Error(`Unsupported combinator "${sel.combinator}" for selector ${sel}.`);
|
|
289
436
|
}
|
|
290
437
|
this.specificity += sel.specificity;
|
|
291
438
|
if (sel.dynamic) {
|
|
292
439
|
this.dynamic = true;
|
|
293
440
|
}
|
|
294
|
-
|
|
441
|
+
siblingsToGroup.push(sel);
|
|
295
442
|
}
|
|
296
|
-
this.groups = groups.map((g) => new Selector.ChildGroup(g.map((
|
|
443
|
+
this.groups = groups.map((g) => new Selector.ChildGroup(g.map((selectors) => (selectors.length > 1 ? new Selector.SiblingGroup(selectors) : selectors[0]))));
|
|
297
444
|
this.last = selectors[selectors.length - 1];
|
|
298
445
|
}
|
|
299
446
|
toString() {
|
|
@@ -302,13 +449,13 @@ export class Selector extends SelectorCore {
|
|
|
302
449
|
match(node) {
|
|
303
450
|
return this.groups.every((group, i) => {
|
|
304
451
|
if (i === 0) {
|
|
305
|
-
node = group.
|
|
452
|
+
node = group.getMatchingNode(node, true);
|
|
306
453
|
return !!node;
|
|
307
454
|
}
|
|
308
455
|
else {
|
|
309
456
|
let ancestor = node;
|
|
310
457
|
while ((ancestor = ancestor.parent ?? ancestor._modalParent)) {
|
|
311
|
-
if ((node = group.
|
|
458
|
+
if ((node = group.getMatchingNode(ancestor, true))) {
|
|
312
459
|
return true;
|
|
313
460
|
}
|
|
314
461
|
}
|
|
@@ -316,8 +463,14 @@ export class Selector extends SelectorCore {
|
|
|
316
463
|
}
|
|
317
464
|
});
|
|
318
465
|
}
|
|
466
|
+
mayMatch(node) {
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
trackChanges(node, map) {
|
|
470
|
+
this.selectors.forEach((sel) => sel.trackChanges(node, map));
|
|
471
|
+
}
|
|
319
472
|
lookupSort(sorter, base) {
|
|
320
|
-
this.last.lookupSort(sorter, this);
|
|
473
|
+
this.last.lookupSort(sorter, base || this);
|
|
321
474
|
}
|
|
322
475
|
accumulateChanges(node, map) {
|
|
323
476
|
if (!this.dynamic) {
|
|
@@ -326,7 +479,7 @@ export class Selector extends SelectorCore {
|
|
|
326
479
|
const bounds = [];
|
|
327
480
|
const mayMatch = this.groups.every((group, i) => {
|
|
328
481
|
if (i === 0) {
|
|
329
|
-
const nextNode = group.
|
|
482
|
+
const nextNode = group.getMatchingNode(node, false);
|
|
330
483
|
bounds.push({ left: node, right: node });
|
|
331
484
|
node = nextNode;
|
|
332
485
|
return !!node;
|
|
@@ -334,7 +487,7 @@ export class Selector extends SelectorCore {
|
|
|
334
487
|
else {
|
|
335
488
|
let ancestor = node;
|
|
336
489
|
while ((ancestor = ancestor.parent)) {
|
|
337
|
-
const nextNode = group.
|
|
490
|
+
const nextNode = group.getMatchingNode(ancestor, false);
|
|
338
491
|
if (nextNode) {
|
|
339
492
|
bounds.push({ left: ancestor, right: null });
|
|
340
493
|
node = nextNode;
|
|
@@ -367,37 +520,112 @@ export class Selector extends SelectorCore {
|
|
|
367
520
|
return mayMatch;
|
|
368
521
|
}
|
|
369
522
|
}
|
|
523
|
+
export var Selector;
|
|
370
524
|
(function (Selector) {
|
|
371
525
|
// Non-spec. Selector sequences are grouped by ancestor then by child combinators for easier backtracking.
|
|
372
|
-
class ChildGroup {
|
|
526
|
+
class ChildGroup extends SelectorBase {
|
|
373
527
|
constructor(selectors) {
|
|
528
|
+
super();
|
|
374
529
|
this.selectors = selectors;
|
|
375
530
|
this.dynamic = selectors.some((sel) => sel.dynamic);
|
|
376
531
|
}
|
|
532
|
+
getMatchingNode(node, strict) {
|
|
533
|
+
const funcName = strict ? 'match' : 'mayMatch';
|
|
534
|
+
return this.selectors.every((sel, i) => (node = i === 0 ? node : node.parent) && sel[funcName](node)) ? node : null;
|
|
535
|
+
}
|
|
377
536
|
match(node) {
|
|
378
|
-
return this.
|
|
537
|
+
return this.getMatchingNode(node, true) != null;
|
|
379
538
|
}
|
|
380
539
|
mayMatch(node) {
|
|
381
|
-
return this.
|
|
540
|
+
return this.getMatchingNode(node, false) != null;
|
|
382
541
|
}
|
|
383
542
|
trackChanges(node, map) {
|
|
384
|
-
this.selectors.forEach((sel, i) =>
|
|
543
|
+
this.selectors.forEach((sel, i) => {
|
|
544
|
+
if (i === 0) {
|
|
545
|
+
node && sel.trackChanges(node, map);
|
|
546
|
+
}
|
|
547
|
+
else {
|
|
548
|
+
node = node.parent;
|
|
549
|
+
if (node && sel.mayMatch(node)) {
|
|
550
|
+
sel.trackChanges(node, map);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
});
|
|
385
554
|
}
|
|
386
555
|
}
|
|
387
556
|
Selector.ChildGroup = ChildGroup;
|
|
388
|
-
class SiblingGroup {
|
|
557
|
+
class SiblingGroup extends SelectorBase {
|
|
389
558
|
constructor(selectors) {
|
|
559
|
+
super();
|
|
390
560
|
this.selectors = selectors;
|
|
391
561
|
this.dynamic = selectors.some((sel) => sel.dynamic);
|
|
392
562
|
}
|
|
393
563
|
match(node) {
|
|
394
|
-
return this.selectors.every((sel, i) =>
|
|
564
|
+
return this.selectors.every((sel, i) => {
|
|
565
|
+
if (i === 0) {
|
|
566
|
+
return node && sel.match(node);
|
|
567
|
+
}
|
|
568
|
+
if (sel.combinator === Combinator.adjacent) {
|
|
569
|
+
node = getNodePreviousDirectSibling(node);
|
|
570
|
+
return node && sel.match(node);
|
|
571
|
+
}
|
|
572
|
+
// Sibling combinator
|
|
573
|
+
let isMatching = false;
|
|
574
|
+
eachNodePreviousGeneralSibling(node, (sibling) => {
|
|
575
|
+
isMatching = sel.match(sibling);
|
|
576
|
+
return !isMatching;
|
|
577
|
+
});
|
|
578
|
+
return isMatching;
|
|
579
|
+
});
|
|
395
580
|
}
|
|
396
581
|
mayMatch(node) {
|
|
397
|
-
return this.selectors.every((sel, i) =>
|
|
582
|
+
return this.selectors.every((sel, i) => {
|
|
583
|
+
if (i === 0) {
|
|
584
|
+
return node && sel.mayMatch(node);
|
|
585
|
+
}
|
|
586
|
+
if (sel.combinator === Combinator.adjacent) {
|
|
587
|
+
node = getNodePreviousDirectSibling(node);
|
|
588
|
+
return node && sel.mayMatch(node);
|
|
589
|
+
}
|
|
590
|
+
// Sibling combinator
|
|
591
|
+
let isMatching = false;
|
|
592
|
+
eachNodePreviousGeneralSibling(node, (sibling) => {
|
|
593
|
+
isMatching = sel.mayMatch(sibling);
|
|
594
|
+
return !isMatching;
|
|
595
|
+
});
|
|
596
|
+
return isMatching;
|
|
597
|
+
});
|
|
398
598
|
}
|
|
399
599
|
trackChanges(node, map) {
|
|
400
|
-
this.selectors.forEach((sel, i) =>
|
|
600
|
+
this.selectors.forEach((sel, i) => {
|
|
601
|
+
if (i === 0) {
|
|
602
|
+
if (node) {
|
|
603
|
+
sel.trackChanges(node, map);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
if (sel.combinator === Combinator.adjacent) {
|
|
608
|
+
node = getNodePreviousDirectSibling(node);
|
|
609
|
+
if (node && sel.mayMatch(node)) {
|
|
610
|
+
sel.trackChanges(node, map);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
else {
|
|
614
|
+
// Sibling combinator
|
|
615
|
+
let matchingSibling;
|
|
616
|
+
eachNodePreviousGeneralSibling(node, (sibling) => {
|
|
617
|
+
const isMatching = sel.mayMatch(sibling);
|
|
618
|
+
if (isMatching) {
|
|
619
|
+
matchingSibling = sibling;
|
|
620
|
+
}
|
|
621
|
+
return !isMatching;
|
|
622
|
+
});
|
|
623
|
+
if (matchingSibling) {
|
|
624
|
+
sel.trackChanges(matchingSibling, map);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
});
|
|
401
629
|
}
|
|
402
630
|
}
|
|
403
631
|
Selector.SiblingGroup = SiblingGroup;
|
|
@@ -409,112 +637,161 @@ export class RuleSet {
|
|
|
409
637
|
this.selectors.forEach((sel) => (sel.ruleset = this));
|
|
410
638
|
}
|
|
411
639
|
toString() {
|
|
412
|
-
|
|
640
|
+
let desc = `${this.selectors.join(', ')} {${this.declarations.map((d, i) => `${i === 0 ? ' ' : ''}${d.property}: ${d.value}`).join('; ')} }`;
|
|
641
|
+
if (this.mediaQueryString) {
|
|
642
|
+
desc = `@media ${this.mediaQueryString} { ${desc} }`;
|
|
643
|
+
}
|
|
644
|
+
return desc;
|
|
413
645
|
}
|
|
414
646
|
lookupSort(sorter) {
|
|
415
647
|
this.selectors.forEach((sel) => sel.lookupSort(sorter));
|
|
416
648
|
}
|
|
417
649
|
}
|
|
418
|
-
export function
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
return new RuleSet(selectors, declarations);
|
|
423
|
-
});
|
|
650
|
+
export function fromAstNode(astRule) {
|
|
651
|
+
const declarations = astRule.declarations.filter(isDeclaration).map(createDeclaration);
|
|
652
|
+
const selectors = astRule.selectors.map(createSelector);
|
|
653
|
+
return new RuleSet(selectors, declarations);
|
|
424
654
|
}
|
|
425
655
|
function createDeclaration(decl) {
|
|
426
656
|
return { property: isCssVariable(decl.property) ? decl.property : decl.property.toLowerCase(), value: decl.value };
|
|
427
657
|
}
|
|
428
658
|
function createSimpleSelectorFromAst(ast) {
|
|
429
|
-
if (ast.type === '
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
return new
|
|
659
|
+
if (ast.type === 'attribute') {
|
|
660
|
+
if (ast.name === 'class') {
|
|
661
|
+
return new ClassSelector(ast.value);
|
|
662
|
+
}
|
|
663
|
+
if (ast.name === 'id') {
|
|
664
|
+
return new IdSelector(ast.value);
|
|
665
|
+
}
|
|
666
|
+
return new AttributeSelector(ast.name, ast.action, ast.value, !!ast.ignoreCase);
|
|
437
667
|
}
|
|
438
|
-
if (ast.type === '
|
|
439
|
-
return new
|
|
668
|
+
if (ast.type === 'tag') {
|
|
669
|
+
return new TypeSelector(ast.name.replace('-', '').toLowerCase());
|
|
440
670
|
}
|
|
441
|
-
if (ast.type === '
|
|
442
|
-
|
|
671
|
+
if (ast.type === 'pseudo') {
|
|
672
|
+
if (ast.name === 'is') {
|
|
673
|
+
return new IsFunctionalPseudoClassSelector(ast.name, ast.data);
|
|
674
|
+
}
|
|
675
|
+
if (ast.name === 'where') {
|
|
676
|
+
return new WhereFunctionalPseudoClassSelector(ast.name, ast.data);
|
|
677
|
+
}
|
|
678
|
+
if (ast.name === 'not') {
|
|
679
|
+
return new NotFunctionalPseudoClassSelector(ast.name, ast.data);
|
|
680
|
+
}
|
|
681
|
+
return new PseudoClassSelector(ast.name);
|
|
443
682
|
}
|
|
444
|
-
if (ast.type === '
|
|
683
|
+
if (ast.type === 'universal') {
|
|
445
684
|
return new UniversalSelector();
|
|
446
685
|
}
|
|
686
|
+
return new InvalidSelector(new Error(ast.type));
|
|
447
687
|
}
|
|
448
|
-
function createSimpleSelectorSequenceFromAst(
|
|
449
|
-
if (
|
|
688
|
+
function createSimpleSelectorSequenceFromAst(asts) {
|
|
689
|
+
if (asts.length === 0) {
|
|
450
690
|
return new InvalidSelector(new Error('Empty simple selector sequence.'));
|
|
451
691
|
}
|
|
452
|
-
|
|
453
|
-
return createSimpleSelectorFromAst(
|
|
692
|
+
if (asts.length === 1) {
|
|
693
|
+
return createSimpleSelectorFromAst(asts[0]);
|
|
454
694
|
}
|
|
455
|
-
|
|
456
|
-
|
|
695
|
+
const sequenceSelectors = [];
|
|
696
|
+
for (const ast of asts) {
|
|
697
|
+
const selector = createSimpleSelectorFromAst(ast);
|
|
698
|
+
if (selector instanceof InvalidSelector) {
|
|
699
|
+
return selector;
|
|
700
|
+
}
|
|
701
|
+
sequenceSelectors.push(selector);
|
|
457
702
|
}
|
|
703
|
+
return new SimpleSelectorSequence(sequenceSelectors);
|
|
458
704
|
}
|
|
459
|
-
function createSelectorFromAst(
|
|
460
|
-
|
|
705
|
+
function createSelectorFromAst(asts) {
|
|
706
|
+
let result;
|
|
707
|
+
if (asts.length === 0) {
|
|
461
708
|
return new InvalidSelector(new Error('Empty selector.'));
|
|
462
709
|
}
|
|
463
|
-
|
|
464
|
-
return
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
710
|
+
if (asts.length === 1) {
|
|
711
|
+
return createSimpleSelectorFromAst(asts[0]);
|
|
712
|
+
}
|
|
713
|
+
const simpleSelectorSequences = [];
|
|
714
|
+
let sequenceAsts = [];
|
|
715
|
+
let combinatorCount = 0;
|
|
716
|
+
for (const ast of asts) {
|
|
717
|
+
const combinator = Combinator[ast.type];
|
|
718
|
+
// Combinator means the end of a sequence
|
|
719
|
+
if (combinator != null) {
|
|
720
|
+
const selector = createSimpleSelectorSequenceFromAst(sequenceAsts);
|
|
721
|
+
if (selector instanceof InvalidSelector) {
|
|
722
|
+
return selector;
|
|
475
723
|
}
|
|
476
|
-
|
|
724
|
+
selector.combinator = combinator;
|
|
725
|
+
simpleSelectorSequences.push(selector);
|
|
726
|
+
combinatorCount++;
|
|
727
|
+
// Cleanup stored selectors for the new sequence to take place
|
|
728
|
+
sequenceAsts = [];
|
|
729
|
+
}
|
|
730
|
+
else {
|
|
731
|
+
sequenceAsts.push(ast);
|
|
477
732
|
}
|
|
478
|
-
return new Selector(simpleSelectorSequences);
|
|
479
733
|
}
|
|
734
|
+
if (combinatorCount > 0) {
|
|
735
|
+
// Create a sequence using the remaining selectors after the last combinator
|
|
736
|
+
if (sequenceAsts.length) {
|
|
737
|
+
const selector = createSimpleSelectorSequenceFromAst(sequenceAsts);
|
|
738
|
+
if (selector instanceof InvalidSelector) {
|
|
739
|
+
return selector;
|
|
740
|
+
}
|
|
741
|
+
simpleSelectorSequences.push(selector);
|
|
742
|
+
}
|
|
743
|
+
return new ComplexSelector(simpleSelectorSequences);
|
|
744
|
+
}
|
|
745
|
+
return createSimpleSelectorSequenceFromAst(sequenceAsts);
|
|
480
746
|
}
|
|
481
747
|
export function createSelector(sel) {
|
|
482
748
|
try {
|
|
483
|
-
const
|
|
484
|
-
if (!
|
|
749
|
+
const result = convertToCSSWhatSelector(sel);
|
|
750
|
+
if (!result?.length) {
|
|
485
751
|
return new InvalidSelector(new Error('Empty selector'));
|
|
486
752
|
}
|
|
487
|
-
return createSelectorFromAst(
|
|
753
|
+
return createSelectorFromAst(result[0]);
|
|
488
754
|
}
|
|
489
755
|
catch (e) {
|
|
490
756
|
return new InvalidSelector(e);
|
|
491
757
|
}
|
|
492
758
|
}
|
|
493
|
-
function isRule(node) {
|
|
494
|
-
return node.type === 'rule';
|
|
495
|
-
}
|
|
496
759
|
function isDeclaration(node) {
|
|
497
760
|
return node.type === 'declaration';
|
|
498
761
|
}
|
|
499
|
-
export
|
|
500
|
-
|
|
762
|
+
export function matchMediaQueryString(mediaQueryString, cachedQueries) {
|
|
763
|
+
// It can be a single or multiple queries in case of nested media queries
|
|
764
|
+
const mediaQueryStrings = mediaQueryString.split(MEDIA_QUERY_SEPARATOR);
|
|
765
|
+
return mediaQueryStrings.every((mq) => {
|
|
766
|
+
let isMatching;
|
|
767
|
+
// Query has already been validated
|
|
768
|
+
if (cachedQueries.includes(mq)) {
|
|
769
|
+
isMatching = true;
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
isMatching = checkIfMediaQueryMatches(mq);
|
|
773
|
+
if (isMatching) {
|
|
774
|
+
cachedQueries.push(mq);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
return isMatching;
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
export class SelectorScope {
|
|
781
|
+
constructor() {
|
|
501
782
|
this.id = {};
|
|
502
783
|
this.class = {};
|
|
503
784
|
this.type = {};
|
|
504
785
|
this.universal = [];
|
|
505
786
|
this.position = 0;
|
|
506
|
-
rulesets.forEach((rule) => rule.lookupSort(this));
|
|
507
787
|
}
|
|
508
|
-
|
|
509
|
-
const selectorsMatch = new SelectorsMatch();
|
|
788
|
+
getSelectorCandidates(node) {
|
|
510
789
|
const { cssClasses, id, cssType } = node;
|
|
511
790
|
const selectorClasses = [this.universal, this.id[id], this.type[cssType]];
|
|
512
791
|
if (cssClasses && cssClasses.size) {
|
|
513
792
|
cssClasses.forEach((c) => selectorClasses.push(this.class[c]));
|
|
514
793
|
}
|
|
515
|
-
|
|
516
|
-
selectorsMatch.selectors = selectors.filter((sel) => sel.accumulateChanges(node, selectorsMatch)).sort((a, b) => a.specificity - b.specificity || a.pos - b.pos);
|
|
517
|
-
return selectorsMatch;
|
|
794
|
+
return selectorClasses.reduce((cur, next) => cur.concat(next || []), []);
|
|
518
795
|
}
|
|
519
796
|
sortById(id, sel) {
|
|
520
797
|
this.addToMap(this.id, id, sel);
|
|
@@ -539,6 +816,77 @@ export class SelectorsMap {
|
|
|
539
816
|
return sel;
|
|
540
817
|
}
|
|
541
818
|
}
|
|
819
|
+
export class MediaQuerySelectorScope extends SelectorScope {
|
|
820
|
+
constructor(mediaQueryString) {
|
|
821
|
+
super();
|
|
822
|
+
this._mediaQueryString = mediaQueryString;
|
|
823
|
+
}
|
|
824
|
+
get mediaQueryString() {
|
|
825
|
+
return this._mediaQueryString;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
export class StyleSheetSelectorScope extends SelectorScope {
|
|
829
|
+
constructor(rulesets) {
|
|
830
|
+
super();
|
|
831
|
+
this.lookupRulesets(rulesets);
|
|
832
|
+
}
|
|
833
|
+
createMediaQuerySelectorScope(mediaQueryString) {
|
|
834
|
+
const selectorScope = new MediaQuerySelectorScope(mediaQueryString);
|
|
835
|
+
selectorScope.position = this.position;
|
|
836
|
+
if (this.mediaQuerySelectorScopes) {
|
|
837
|
+
this.mediaQuerySelectorScopes.push(selectorScope);
|
|
838
|
+
}
|
|
839
|
+
else {
|
|
840
|
+
this.mediaQuerySelectorScopes = [selectorScope];
|
|
841
|
+
}
|
|
842
|
+
return selectorScope;
|
|
843
|
+
}
|
|
844
|
+
lookupRulesets(rulesets) {
|
|
845
|
+
let lastMediaSelectorScope;
|
|
846
|
+
for (let i = 0, length = rulesets.length; i < length; i++) {
|
|
847
|
+
const ruleset = rulesets[i];
|
|
848
|
+
if (lastMediaSelectorScope && lastMediaSelectorScope.mediaQueryString !== ruleset.mediaQueryString) {
|
|
849
|
+
// Once done with current media query scope, update stylesheet scope position
|
|
850
|
+
this.position = lastMediaSelectorScope.position;
|
|
851
|
+
lastMediaSelectorScope = null;
|
|
852
|
+
}
|
|
853
|
+
if (ruleset.mediaQueryString) {
|
|
854
|
+
// Create media query selector scope and register selector lookups there
|
|
855
|
+
if (!lastMediaSelectorScope) {
|
|
856
|
+
lastMediaSelectorScope = this.createMediaQuerySelectorScope(ruleset.mediaQueryString);
|
|
857
|
+
}
|
|
858
|
+
ruleset.lookupSort(lastMediaSelectorScope);
|
|
859
|
+
}
|
|
860
|
+
else {
|
|
861
|
+
ruleset.lookupSort(this);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
// If reference of last media selector scope is still kept, update stylesheet scope position
|
|
865
|
+
if (lastMediaSelectorScope) {
|
|
866
|
+
this.position = lastMediaSelectorScope.position;
|
|
867
|
+
lastMediaSelectorScope = null;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
query(node) {
|
|
871
|
+
const selectorsMatch = new SelectorsMatch();
|
|
872
|
+
const selectors = this.getSelectorCandidates(node);
|
|
873
|
+
// Validate media queries and include their selectors if needed
|
|
874
|
+
if (this.mediaQuerySelectorScopes) {
|
|
875
|
+
// Cache media query results to avoid validations of other identical queries
|
|
876
|
+
const validatedMediaQueries = [];
|
|
877
|
+
for (let i = 0, length = this.mediaQuerySelectorScopes.length; i < length; i++) {
|
|
878
|
+
const selectorScope = this.mediaQuerySelectorScopes[i];
|
|
879
|
+
const isMatchingAllQueries = matchMediaQueryString(selectorScope.mediaQueryString, validatedMediaQueries);
|
|
880
|
+
if (isMatchingAllQueries) {
|
|
881
|
+
const mediaQuerySelectors = selectorScope.getSelectorCandidates(node);
|
|
882
|
+
selectors.push(...mediaQuerySelectors);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
selectorsMatch.selectors = selectors.filter((sel) => sel.accumulateChanges(node, selectorsMatch)).sort((a, b) => a.specificity - b.specificity || a.pos - b.pos);
|
|
887
|
+
return selectorsMatch;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
542
890
|
export class SelectorsMatch {
|
|
543
891
|
constructor() {
|
|
544
892
|
this.changeMap = new Map();
|
|
@@ -581,8 +929,10 @@ export const CSSHelper = {
|
|
|
581
929
|
SimpleSelectorSequence,
|
|
582
930
|
Selector,
|
|
583
931
|
RuleSet,
|
|
584
|
-
|
|
585
|
-
|
|
932
|
+
SelectorScope,
|
|
933
|
+
MediaQuerySelectorScope,
|
|
934
|
+
StyleSheetSelectorScope,
|
|
935
|
+
fromAstNode,
|
|
586
936
|
SelectorsMatch,
|
|
587
937
|
};
|
|
588
938
|
//# sourceMappingURL=css-selector.js.map
|