@nativescript/core 8.7.3-next-06-28-2024-9718379905 → 8.7.4
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/css/parser.d.ts +38 -0
- package/css/parser.js +108 -0
- package/css/parser.js.map +1 -1
- package/data/observable/index.d.ts +19 -60
- package/data/observable/index.js +155 -150
- package/data/observable/index.js.map +1 -1
- package/data/observable-array/index.d.ts +6 -10
- package/data/virtual-array/index.d.ts +5 -9
- package/image-source/index.android.d.ts +0 -2
- package/image-source/index.android.js +0 -6
- package/image-source/index.android.js.map +1 -1
- package/image-source/index.d.ts +0 -12
- package/image-source/index.ios.d.ts +0 -2
- package/image-source/index.ios.js +2 -25
- package/image-source/index.ios.js.map +1 -1
- package/package.json +1 -2
- package/references.d.ts +0 -1
- package/ui/action-bar/index.d.ts +6 -10
- package/ui/action-bar/index.ios.js +1 -1
- package/ui/action-bar/index.ios.js.map +1 -1
- package/ui/button/index.android.js +3 -3
- package/ui/button/index.android.js.map +1 -1
- package/ui/button/index.d.ts +5 -9
- package/ui/core/bindable/index.d.ts +0 -13
- package/ui/core/bindable/index.js +6 -27
- package/ui/core/bindable/index.js.map +1 -1
- package/ui/core/view/index.d.ts +12 -19
- package/ui/core/view/view-common.d.ts +5 -5
- package/ui/core/view/view-common.js +62 -52
- package/ui/core/view/view-common.js.map +1 -1
- package/ui/core/view-base/index.d.ts +0 -7
- package/ui/core/view-base/index.js +2 -11
- package/ui/core/view-base/index.js.map +1 -1
- package/ui/frame/index.d.ts +6 -10
- package/ui/gestures/gestures-common.d.ts +7 -10
- package/ui/gestures/gestures-common.js +71 -24
- package/ui/gestures/gestures-common.js.map +1 -1
- package/ui/gestures/index.android.js +46 -60
- package/ui/gestures/index.android.js.map +1 -1
- package/ui/gestures/index.d.ts +1 -3
- package/ui/gestures/index.ios.d.ts +2 -20
- package/ui/gestures/index.ios.js +66 -88
- package/ui/gestures/index.ios.js.map +1 -1
- package/ui/gestures/touch-manager.js +2 -2
- package/ui/gestures/touch-manager.js.map +1 -1
- package/ui/image/image-common.d.ts +0 -6
- package/ui/image/image-common.js +2 -21
- package/ui/image/image-common.js.map +1 -1
- package/ui/image/index.d.ts +0 -1
- package/ui/image/index.ios.js +1 -14
- package/ui/image/index.ios.js.map +1 -1
- package/ui/image-cache/index.d.ts +6 -10
- package/ui/index.d.ts +1 -1
- package/ui/index.js +1 -1
- package/ui/index.js.map +1 -1
- package/ui/list-view/index.d.ts +6 -10
- package/ui/page/index.d.ts +6 -10
- package/ui/placeholder/index.d.ts +5 -9
- package/ui/scroll-view/index.d.ts +5 -9
- package/ui/search-bar/index.d.ts +5 -9
- package/ui/segmented-bar/index.d.ts +5 -9
- package/ui/styling/css-selector.d.ts +23 -63
- package/ui/styling/css-selector.js +110 -372
- package/ui/styling/css-selector.js.map +1 -1
- package/ui/styling/style-properties.js +1 -1
- package/ui/styling/style-properties.js.map +1 -1
- package/ui/tab-view/index.d.ts +6 -10
- package/ui/transition/page-transition.android.js +1 -1
- package/ui/transition/page-transition.android.js.map +1 -1
- package/ui/web-view/index.d.ts +6 -10
- package/utils/common.d.ts +0 -1
- package/utils/common.js +1 -3
- package/utils/common.js.map +1 -1
- package/utils/index.ios.js +3 -2
- package/utils/index.ios.js.map +1 -1
- package/utils/ios/index.js +1 -1
- package/utils/ios/index.js.map +1 -1
- package/ui/image/symbol-effects-common.d.ts +0 -36
- package/ui/image/symbol-effects-common.js +0 -35
- package/ui/image/symbol-effects-common.js.map +0 -1
- package/ui/image/symbol-effects.android.d.ts +0 -4
- package/ui/image/symbol-effects.android.js +0 -8
- package/ui/image/symbol-effects.android.js.map +0 -1
- package/ui/image/symbol-effects.d.ts +0 -13
- package/ui/image/symbol-effects.ios.d.ts +0 -2
- package/ui/image/symbol-effects.ios.js +0 -93
- package/ui/image/symbol-effects.ios.js.map +0 -1
|
@@ -1,27 +1,7 @@
|
|
|
1
|
-
import { parse as convertToCSSWhatSelector } from 'css-what';
|
|
2
1
|
import '../../globals';
|
|
3
2
|
import { isCssVariable } from '../core/properties';
|
|
4
3
|
import { isNullOrUndefined } from '../../utils/types';
|
|
5
|
-
|
|
6
|
-
(function (Combinator) {
|
|
7
|
-
Combinator["descendant"] = " ";
|
|
8
|
-
Combinator["child"] = ">";
|
|
9
|
-
Combinator["adjacent"] = "+";
|
|
10
|
-
Combinator["sibling"] = "~";
|
|
11
|
-
// Not supported
|
|
12
|
-
Combinator["parent"] = "<";
|
|
13
|
-
Combinator["column-combinator"] = "||";
|
|
14
|
-
})(Combinator || (Combinator = {}));
|
|
15
|
-
var AttributeSelectorOperator;
|
|
16
|
-
(function (AttributeSelectorOperator) {
|
|
17
|
-
AttributeSelectorOperator["exists"] = "";
|
|
18
|
-
AttributeSelectorOperator["equals"] = "=";
|
|
19
|
-
AttributeSelectorOperator["start"] = "^=";
|
|
20
|
-
AttributeSelectorOperator["end"] = "$=";
|
|
21
|
-
AttributeSelectorOperator["any"] = "*=";
|
|
22
|
-
AttributeSelectorOperator["element"] = "~=";
|
|
23
|
-
AttributeSelectorOperator["hyphen"] = "|=";
|
|
24
|
-
})(AttributeSelectorOperator || (AttributeSelectorOperator = {}));
|
|
4
|
+
import { parseSelector } from '../../css/parser';
|
|
25
5
|
var Match;
|
|
26
6
|
(function (Match) {
|
|
27
7
|
/**
|
|
@@ -33,22 +13,7 @@ var Match;
|
|
|
33
13
|
*/
|
|
34
14
|
Match.Static = false;
|
|
35
15
|
})(Match || (Match = {}));
|
|
36
|
-
function
|
|
37
|
-
if (!node.parent || !node.parent.getChildIndex || !node.parent.getChildAt || !node.parent.getChildrenCount) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const nodeIndex = node.parent.getChildIndex(node);
|
|
41
|
-
if (nodeIndex === 0) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const count = node.parent.getChildrenCount();
|
|
45
|
-
let retVal = true;
|
|
46
|
-
for (let i = nodeIndex - 1; i >= 0 && retVal; i--) {
|
|
47
|
-
const sibling = node.parent.getChildAt(i);
|
|
48
|
-
retVal = callback(sibling);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function getNodePreviousDirectSibling(node) {
|
|
16
|
+
function getNodeDirectSibling(node) {
|
|
52
17
|
if (!node.parent || !node.parent.getChildIndex || !node.parent.getChildAt) {
|
|
53
18
|
return null;
|
|
54
19
|
}
|
|
@@ -67,19 +32,7 @@ function SelectorProperties(specificity, rarity, dynamic = false) {
|
|
|
67
32
|
return cls;
|
|
68
33
|
};
|
|
69
34
|
}
|
|
70
|
-
|
|
71
|
-
return (cls) => {
|
|
72
|
-
cls.prototype.specificity = specificity;
|
|
73
|
-
cls.prototype.rarity = rarity;
|
|
74
|
-
cls.prototype.combinator = undefined;
|
|
75
|
-
cls.prototype.dynamic = false;
|
|
76
|
-
cls.prototype.pseudoSelectorListType = pseudoSelectorListType;
|
|
77
|
-
return cls;
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
export class SelectorBase {
|
|
81
|
-
}
|
|
82
|
-
let SelectorCore = class SelectorCore extends SelectorBase {
|
|
35
|
+
let SelectorCore = class SelectorCore {
|
|
83
36
|
lookupSort(sorter, base) {
|
|
84
37
|
sorter.sortAsUniversal(base || this);
|
|
85
38
|
}
|
|
@@ -116,7 +69,7 @@ let InvalidSelector = class InvalidSelector extends SimpleSelector {
|
|
|
116
69
|
this.e = e;
|
|
117
70
|
}
|
|
118
71
|
toString() {
|
|
119
|
-
return
|
|
72
|
+
return `<error: ${this.e}>`;
|
|
120
73
|
}
|
|
121
74
|
match(node) {
|
|
122
75
|
return false;
|
|
@@ -205,55 +158,52 @@ ClassSelector = __decorate([
|
|
|
205
158
|
], ClassSelector);
|
|
206
159
|
export { ClassSelector };
|
|
207
160
|
let AttributeSelector = class AttributeSelector extends SimpleSelector {
|
|
208
|
-
constructor(attribute, test, value
|
|
161
|
+
constructor(attribute, test, value) {
|
|
209
162
|
super();
|
|
210
163
|
this.attribute = attribute;
|
|
211
164
|
this.test = test;
|
|
212
165
|
this.value = value;
|
|
213
|
-
|
|
166
|
+
if (!test) {
|
|
167
|
+
// HasAttribute
|
|
168
|
+
this.match = (node) => !isNullOrUndefined(node[attribute]);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (!value) {
|
|
172
|
+
this.match = (node) => false;
|
|
173
|
+
}
|
|
174
|
+
this.match = (node) => {
|
|
175
|
+
const attr = node[attribute] + '';
|
|
176
|
+
if (test === '=') {
|
|
177
|
+
// Equals
|
|
178
|
+
return attr === value;
|
|
179
|
+
}
|
|
180
|
+
if (test === '^=') {
|
|
181
|
+
// PrefixMatch
|
|
182
|
+
return attr.startsWith(value);
|
|
183
|
+
}
|
|
184
|
+
if (test === '$=') {
|
|
185
|
+
// SuffixMatch
|
|
186
|
+
return attr.endsWith(value);
|
|
187
|
+
}
|
|
188
|
+
if (test === '*=') {
|
|
189
|
+
// SubstringMatch
|
|
190
|
+
return attr.indexOf(value) !== -1;
|
|
191
|
+
}
|
|
192
|
+
if (test === '~=') {
|
|
193
|
+
// Includes
|
|
194
|
+
const words = attr.split(' ');
|
|
195
|
+
return words && words.indexOf(value) !== -1;
|
|
196
|
+
}
|
|
197
|
+
if (test === '|=') {
|
|
198
|
+
// DashMatch
|
|
199
|
+
return attr === value || attr.startsWith(value + '-');
|
|
200
|
+
}
|
|
201
|
+
};
|
|
214
202
|
}
|
|
215
203
|
toString() {
|
|
216
|
-
return `[${this.attribute}${wrap(
|
|
204
|
+
return `[${this.attribute}${wrap(this.test)}${(this.test && this.value) || ''}]${wrap(this.combinator)}`;
|
|
217
205
|
}
|
|
218
206
|
match(node) {
|
|
219
|
-
let attr = node[this.attribute];
|
|
220
|
-
if (this.test === 'exists') {
|
|
221
|
-
return !isNullOrUndefined(attr);
|
|
222
|
-
}
|
|
223
|
-
if (!this.value) {
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
// Now, convert value to string
|
|
227
|
-
attr += '';
|
|
228
|
-
if (this.ignoreCase) {
|
|
229
|
-
attr = attr.toLowerCase();
|
|
230
|
-
this.value = this.value.toLowerCase();
|
|
231
|
-
}
|
|
232
|
-
// =
|
|
233
|
-
if (this.test === 'equals') {
|
|
234
|
-
return attr === this.value;
|
|
235
|
-
}
|
|
236
|
-
// ^=
|
|
237
|
-
if (this.test === 'start') {
|
|
238
|
-
return attr.startsWith(this.value);
|
|
239
|
-
}
|
|
240
|
-
// $=
|
|
241
|
-
if (this.test === 'end') {
|
|
242
|
-
return attr.endsWith(this.value);
|
|
243
|
-
}
|
|
244
|
-
// *=
|
|
245
|
-
if (this.test === 'any') {
|
|
246
|
-
return attr.indexOf(this.value) !== -1;
|
|
247
|
-
}
|
|
248
|
-
// ~=
|
|
249
|
-
if (this.test === 'element') {
|
|
250
|
-
const words = attr.split(' ');
|
|
251
|
-
return words && words.indexOf(this.value) !== -1;
|
|
252
|
-
}
|
|
253
|
-
// |=
|
|
254
|
-
if (this.test === 'hyphen') {
|
|
255
|
-
return attr === this.value || attr.startsWith(this.value + '-');
|
|
256
|
-
}
|
|
257
207
|
return false;
|
|
258
208
|
}
|
|
259
209
|
mayMatch(node) {
|
|
@@ -265,7 +215,7 @@ let AttributeSelector = class AttributeSelector extends SimpleSelector {
|
|
|
265
215
|
};
|
|
266
216
|
AttributeSelector = __decorate([
|
|
267
217
|
SelectorProperties(10 /* Specificity.Attribute */, 0 /* Rarity.Attribute */, Match.Dynamic),
|
|
268
|
-
__metadata("design:paramtypes", [String, String, String
|
|
218
|
+
__metadata("design:paramtypes", [String, String, String])
|
|
269
219
|
], AttributeSelector);
|
|
270
220
|
export { AttributeSelector };
|
|
271
221
|
let PseudoClassSelector = class PseudoClassSelector extends SimpleSelector {
|
|
@@ -291,100 +241,12 @@ PseudoClassSelector = __decorate([
|
|
|
291
241
|
__metadata("design:paramtypes", [String])
|
|
292
242
|
], PseudoClassSelector);
|
|
293
243
|
export { PseudoClassSelector };
|
|
294
|
-
export class FunctionalPseudoClassSelector extends PseudoClassSelector {
|
|
295
|
-
constructor(cssPseudoClass, dataType) {
|
|
296
|
-
super(cssPseudoClass);
|
|
297
|
-
const selectors = [];
|
|
298
|
-
const needsHighestSpecificity = this.specificity === -1 /* Specificity.SelectorListHighest */;
|
|
299
|
-
let specificity = 0;
|
|
300
|
-
if (Array.isArray(dataType)) {
|
|
301
|
-
for (const asts of dataType) {
|
|
302
|
-
const selector = createSelectorFromAst(asts);
|
|
303
|
-
if (selector instanceof InvalidSelector) {
|
|
304
|
-
// Only forgiving selector list can ignore invalid selectors
|
|
305
|
-
if (this.selectorListType !== 1 /* PseudoClassSelectorList.Forgiving */) {
|
|
306
|
-
selectors.splice(0);
|
|
307
|
-
specificity = 0;
|
|
308
|
-
break;
|
|
309
|
-
}
|
|
310
|
-
continue;
|
|
311
|
-
}
|
|
312
|
-
// The specificity of some pseudo-classes is replaced by the specificity of the most specific selector in its comma-separated argument of selectors
|
|
313
|
-
if (needsHighestSpecificity && selector.specificity > specificity) {
|
|
314
|
-
specificity = selector.specificity;
|
|
315
|
-
}
|
|
316
|
-
selectors.push(selector);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
this.selectors = selectors;
|
|
320
|
-
this.specificity = specificity;
|
|
321
|
-
// Functional pseudo-classes become dynamic based on selectors in selector list
|
|
322
|
-
this.dynamic = this.selectors.some((sel) => sel.dynamic);
|
|
323
|
-
}
|
|
324
|
-
toString() {
|
|
325
|
-
return `:${this.cssPseudoClass}(${this.selectors.join(', ')})${wrap(this.combinator)}`;
|
|
326
|
-
}
|
|
327
|
-
match(node) {
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
mayMatch(node) {
|
|
331
|
-
return true;
|
|
332
|
-
}
|
|
333
|
-
trackChanges(node, map) {
|
|
334
|
-
this.selectors.forEach((sel) => sel.trackChanges(node, map));
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
let NotFunctionalPseudoClassSelector = class NotFunctionalPseudoClassSelector extends FunctionalPseudoClassSelector {
|
|
338
|
-
match(node) {
|
|
339
|
-
return !this.selectors.some((sel) => sel.match(node));
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
NotFunctionalPseudoClassSelector = __decorate([
|
|
343
|
-
FunctionalPseudoClassProperties(-1 /* Specificity.SelectorListHighest */, 0 /* Rarity.PseudoClass */, 0 /* PseudoClassSelectorList.Regular */)
|
|
344
|
-
], NotFunctionalPseudoClassSelector);
|
|
345
|
-
export { NotFunctionalPseudoClassSelector };
|
|
346
|
-
let IsFunctionalPseudoClassSelector = class IsFunctionalPseudoClassSelector extends FunctionalPseudoClassSelector {
|
|
347
|
-
match(node) {
|
|
348
|
-
return this.selectors.some((sel) => sel.match(node));
|
|
349
|
-
}
|
|
350
|
-
lookupSort(sorter, base) {
|
|
351
|
-
// A faster lookup can be performed when selector list contains just a single selector
|
|
352
|
-
if (this.selectors.length === 1) {
|
|
353
|
-
this.selectors[0].lookupSort(sorter, base || this);
|
|
354
|
-
}
|
|
355
|
-
else {
|
|
356
|
-
super.lookupSort(sorter, base || this);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
IsFunctionalPseudoClassSelector = __decorate([
|
|
361
|
-
FunctionalPseudoClassProperties(-1 /* Specificity.SelectorListHighest */, 0 /* Rarity.PseudoClass */, 1 /* PseudoClassSelectorList.Forgiving */)
|
|
362
|
-
], IsFunctionalPseudoClassSelector);
|
|
363
|
-
export { IsFunctionalPseudoClassSelector };
|
|
364
|
-
let WhereFunctionalPseudoClassSelector = class WhereFunctionalPseudoClassSelector extends FunctionalPseudoClassSelector {
|
|
365
|
-
match(node) {
|
|
366
|
-
return this.selectors.some((sel) => sel.match(node));
|
|
367
|
-
}
|
|
368
|
-
lookupSort(sorter, base) {
|
|
369
|
-
// A faster lookup can be performed when selector list contains just a single selector
|
|
370
|
-
if (this.selectors.length === 1) {
|
|
371
|
-
this.selectors[0].lookupSort(sorter, base || this);
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
super.lookupSort(sorter, base || this);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
WhereFunctionalPseudoClassSelector = __decorate([
|
|
379
|
-
FunctionalPseudoClassProperties(0 /* Specificity.Zero */, 0 /* Rarity.PseudoClass */, 1 /* PseudoClassSelectorList.Forgiving */)
|
|
380
|
-
], WhereFunctionalPseudoClassSelector);
|
|
381
|
-
export { WhereFunctionalPseudoClassSelector };
|
|
382
244
|
export class SimpleSelectorSequence extends SimpleSelector {
|
|
383
245
|
constructor(selectors) {
|
|
384
246
|
super();
|
|
385
247
|
this.selectors = selectors;
|
|
386
248
|
this.specificity = selectors.reduce((sum, sel) => sel.specificity + sum, 0);
|
|
387
|
-
this.head = selectors.reduce((prev, curr) => (!prev || curr.rarity > prev.rarity ? curr : prev), null);
|
|
249
|
+
this.head = this.selectors.reduce((prev, curr) => (!prev || curr.rarity > prev.rarity ? curr : prev), null);
|
|
388
250
|
this.dynamic = selectors.some((sel) => sel.dynamic);
|
|
389
251
|
}
|
|
390
252
|
toString() {
|
|
@@ -403,41 +265,34 @@ export class SimpleSelectorSequence extends SimpleSelector {
|
|
|
403
265
|
this.head.lookupSort(sorter, base || this);
|
|
404
266
|
}
|
|
405
267
|
}
|
|
406
|
-
export class
|
|
268
|
+
export class Selector extends SelectorCore {
|
|
407
269
|
constructor(selectors) {
|
|
408
270
|
super();
|
|
409
271
|
this.selectors = selectors;
|
|
410
|
-
|
|
411
|
-
let
|
|
272
|
+
const supportedCombinator = [undefined, ' ', '>', '+'];
|
|
273
|
+
let siblingGroup;
|
|
274
|
+
let lastGroup;
|
|
412
275
|
const groups = [];
|
|
413
276
|
this.specificity = 0;
|
|
414
277
|
this.dynamic = false;
|
|
415
|
-
for (let i = selectors.length - 1; i
|
|
278
|
+
for (let i = selectors.length - 1; i > -1; i--) {
|
|
416
279
|
const sel = selectors[i];
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
siblingsToGroup = [];
|
|
426
|
-
currentGroup.push(siblingsToGroup);
|
|
427
|
-
break;
|
|
428
|
-
case Combinator.adjacent:
|
|
429
|
-
case Combinator.sibling:
|
|
430
|
-
break;
|
|
431
|
-
default:
|
|
432
|
-
throw new Error(`Unsupported combinator "${sel.combinator}" for selector ${sel}.`);
|
|
280
|
+
if (supportedCombinator.indexOf(sel.combinator) === -1) {
|
|
281
|
+
throw new Error(`Unsupported combinator "${sel.combinator}".`);
|
|
282
|
+
}
|
|
283
|
+
if (sel.combinator === undefined || sel.combinator === ' ') {
|
|
284
|
+
groups.push((lastGroup = [(siblingGroup = [])]));
|
|
285
|
+
}
|
|
286
|
+
if (sel.combinator === '>') {
|
|
287
|
+
lastGroup.push((siblingGroup = []));
|
|
433
288
|
}
|
|
434
289
|
this.specificity += sel.specificity;
|
|
435
290
|
if (sel.dynamic) {
|
|
436
291
|
this.dynamic = true;
|
|
437
292
|
}
|
|
438
|
-
|
|
293
|
+
siblingGroup.push(sel);
|
|
439
294
|
}
|
|
440
|
-
this.groups = groups.map((g) => new Selector.ChildGroup(g.map((
|
|
295
|
+
this.groups = groups.map((g) => new Selector.ChildGroup(g.map((sg) => new Selector.SiblingGroup(sg))));
|
|
441
296
|
this.last = selectors[selectors.length - 1];
|
|
442
297
|
}
|
|
443
298
|
toString() {
|
|
@@ -446,13 +301,13 @@ export class ComplexSelector extends SelectorCore {
|
|
|
446
301
|
match(node) {
|
|
447
302
|
return this.groups.every((group, i) => {
|
|
448
303
|
if (i === 0) {
|
|
449
|
-
node = group.
|
|
304
|
+
node = group.match(node);
|
|
450
305
|
return !!node;
|
|
451
306
|
}
|
|
452
307
|
else {
|
|
453
308
|
let ancestor = node;
|
|
454
309
|
while ((ancestor = ancestor.parent ?? ancestor._modalParent)) {
|
|
455
|
-
if ((node = group.
|
|
310
|
+
if ((node = group.match(ancestor))) {
|
|
456
311
|
return true;
|
|
457
312
|
}
|
|
458
313
|
}
|
|
@@ -460,14 +315,8 @@ export class ComplexSelector extends SelectorCore {
|
|
|
460
315
|
}
|
|
461
316
|
});
|
|
462
317
|
}
|
|
463
|
-
mayMatch(node) {
|
|
464
|
-
return false;
|
|
465
|
-
}
|
|
466
|
-
trackChanges(node, map) {
|
|
467
|
-
this.selectors.forEach((sel) => sel.trackChanges(node, map));
|
|
468
|
-
}
|
|
469
318
|
lookupSort(sorter, base) {
|
|
470
|
-
this.last.lookupSort(sorter,
|
|
319
|
+
this.last.lookupSort(sorter, this);
|
|
471
320
|
}
|
|
472
321
|
accumulateChanges(node, map) {
|
|
473
322
|
if (!this.dynamic) {
|
|
@@ -476,7 +325,7 @@ export class ComplexSelector extends SelectorCore {
|
|
|
476
325
|
const bounds = [];
|
|
477
326
|
const mayMatch = this.groups.every((group, i) => {
|
|
478
327
|
if (i === 0) {
|
|
479
|
-
const nextNode = group.
|
|
328
|
+
const nextNode = group.mayMatch(node);
|
|
480
329
|
bounds.push({ left: node, right: node });
|
|
481
330
|
node = nextNode;
|
|
482
331
|
return !!node;
|
|
@@ -484,7 +333,7 @@ export class ComplexSelector extends SelectorCore {
|
|
|
484
333
|
else {
|
|
485
334
|
let ancestor = node;
|
|
486
335
|
while ((ancestor = ancestor.parent)) {
|
|
487
|
-
const nextNode = group.
|
|
336
|
+
const nextNode = group.mayMatch(ancestor);
|
|
488
337
|
if (nextNode) {
|
|
489
338
|
bounds.push({ left: ancestor, right: null });
|
|
490
339
|
node = nextNode;
|
|
@@ -517,112 +366,37 @@ export class ComplexSelector extends SelectorCore {
|
|
|
517
366
|
return mayMatch;
|
|
518
367
|
}
|
|
519
368
|
}
|
|
520
|
-
export var Selector;
|
|
521
369
|
(function (Selector) {
|
|
522
370
|
// Non-spec. Selector sequences are grouped by ancestor then by child combinators for easier backtracking.
|
|
523
|
-
class ChildGroup
|
|
371
|
+
class ChildGroup {
|
|
524
372
|
constructor(selectors) {
|
|
525
|
-
super();
|
|
526
373
|
this.selectors = selectors;
|
|
527
374
|
this.dynamic = selectors.some((sel) => sel.dynamic);
|
|
528
375
|
}
|
|
529
|
-
getMatchingNode(node, strict) {
|
|
530
|
-
const funcName = strict ? 'match' : 'mayMatch';
|
|
531
|
-
return this.selectors.every((sel, i) => (node = i === 0 ? node : node.parent) && sel[funcName](node)) ? node : null;
|
|
532
|
-
}
|
|
533
376
|
match(node) {
|
|
534
|
-
return this.
|
|
377
|
+
return this.selectors.every((sel, i) => (node = i === 0 ? node : node.parent) && sel.match(node)) ? node : null;
|
|
535
378
|
}
|
|
536
379
|
mayMatch(node) {
|
|
537
|
-
return this.
|
|
380
|
+
return this.selectors.every((sel, i) => (node = i === 0 ? node : node.parent) && sel.mayMatch(node)) ? node : null;
|
|
538
381
|
}
|
|
539
382
|
trackChanges(node, map) {
|
|
540
|
-
this.selectors.forEach((sel, i) =>
|
|
541
|
-
if (i === 0) {
|
|
542
|
-
node && sel.trackChanges(node, map);
|
|
543
|
-
}
|
|
544
|
-
else {
|
|
545
|
-
node = node.parent;
|
|
546
|
-
if (node && sel.mayMatch(node)) {
|
|
547
|
-
sel.trackChanges(node, map);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
});
|
|
383
|
+
this.selectors.forEach((sel, i) => (node = i === 0 ? node : node.parent) && sel.trackChanges(node, map));
|
|
551
384
|
}
|
|
552
385
|
}
|
|
553
386
|
Selector.ChildGroup = ChildGroup;
|
|
554
|
-
class SiblingGroup
|
|
387
|
+
class SiblingGroup {
|
|
555
388
|
constructor(selectors) {
|
|
556
|
-
super();
|
|
557
389
|
this.selectors = selectors;
|
|
558
390
|
this.dynamic = selectors.some((sel) => sel.dynamic);
|
|
559
391
|
}
|
|
560
392
|
match(node) {
|
|
561
|
-
return this.selectors.every((sel, i) =>
|
|
562
|
-
if (i === 0) {
|
|
563
|
-
return node && sel.match(node);
|
|
564
|
-
}
|
|
565
|
-
if (sel.combinator === Combinator.adjacent) {
|
|
566
|
-
node = getNodePreviousDirectSibling(node);
|
|
567
|
-
return node && sel.match(node);
|
|
568
|
-
}
|
|
569
|
-
// Sibling combinator
|
|
570
|
-
let isMatching = false;
|
|
571
|
-
eachNodePreviousGeneralSibling(node, (sibling) => {
|
|
572
|
-
isMatching = sel.match(sibling);
|
|
573
|
-
return !isMatching;
|
|
574
|
-
});
|
|
575
|
-
return isMatching;
|
|
576
|
-
});
|
|
393
|
+
return this.selectors.every((sel, i) => (node = i === 0 ? node : getNodeDirectSibling(node)) && sel.match(node)) ? node : null;
|
|
577
394
|
}
|
|
578
395
|
mayMatch(node) {
|
|
579
|
-
return this.selectors.every((sel, i) =>
|
|
580
|
-
if (i === 0) {
|
|
581
|
-
return node && sel.mayMatch(node);
|
|
582
|
-
}
|
|
583
|
-
if (sel.combinator === Combinator.adjacent) {
|
|
584
|
-
node = getNodePreviousDirectSibling(node);
|
|
585
|
-
return node && sel.mayMatch(node);
|
|
586
|
-
}
|
|
587
|
-
// Sibling combinator
|
|
588
|
-
let isMatching = false;
|
|
589
|
-
eachNodePreviousGeneralSibling(node, (sibling) => {
|
|
590
|
-
isMatching = sel.mayMatch(sibling);
|
|
591
|
-
return !isMatching;
|
|
592
|
-
});
|
|
593
|
-
return isMatching;
|
|
594
|
-
});
|
|
396
|
+
return this.selectors.every((sel, i) => (node = i === 0 ? node : getNodeDirectSibling(node)) && sel.mayMatch(node)) ? node : null;
|
|
595
397
|
}
|
|
596
398
|
trackChanges(node, map) {
|
|
597
|
-
this.selectors.forEach((sel, i) =>
|
|
598
|
-
if (i === 0) {
|
|
599
|
-
if (node) {
|
|
600
|
-
sel.trackChanges(node, map);
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
else {
|
|
604
|
-
if (sel.combinator === Combinator.adjacent) {
|
|
605
|
-
node = getNodePreviousDirectSibling(node);
|
|
606
|
-
if (node && sel.mayMatch(node)) {
|
|
607
|
-
sel.trackChanges(node, map);
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
else {
|
|
611
|
-
// Sibling combinator
|
|
612
|
-
let matchingSibling;
|
|
613
|
-
eachNodePreviousGeneralSibling(node, (sibling) => {
|
|
614
|
-
const isMatching = sel.mayMatch(sibling);
|
|
615
|
-
if (isMatching) {
|
|
616
|
-
matchingSibling = sibling;
|
|
617
|
-
}
|
|
618
|
-
return !isMatching;
|
|
619
|
-
});
|
|
620
|
-
if (matchingSibling) {
|
|
621
|
-
sel.trackChanges(matchingSibling, map);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
});
|
|
399
|
+
this.selectors.forEach((sel, i) => (node = i === 0 ? node : getNodeDirectSibling(node)) && sel.trackChanges(node, map));
|
|
626
400
|
}
|
|
627
401
|
}
|
|
628
402
|
Selector.SiblingGroup = SiblingGroup;
|
|
@@ -651,101 +425,65 @@ function createDeclaration(decl) {
|
|
|
651
425
|
return { property: isCssVariable(decl.property) ? decl.property : decl.property.toLowerCase(), value: decl.value };
|
|
652
426
|
}
|
|
653
427
|
function createSimpleSelectorFromAst(ast) {
|
|
654
|
-
if (ast.type === '
|
|
655
|
-
|
|
656
|
-
return new ClassSelector(ast.value);
|
|
657
|
-
}
|
|
658
|
-
if (ast.name === 'id') {
|
|
659
|
-
return new IdSelector(ast.value);
|
|
660
|
-
}
|
|
661
|
-
return new AttributeSelector(ast.name, ast.action, ast.value, !!ast.ignoreCase);
|
|
428
|
+
if (ast.type === '.') {
|
|
429
|
+
return new ClassSelector(ast.identifier);
|
|
662
430
|
}
|
|
663
|
-
if (ast.type === '
|
|
664
|
-
return new TypeSelector(ast.
|
|
431
|
+
if (ast.type === '') {
|
|
432
|
+
return new TypeSelector(ast.identifier.replace('-', '').toLowerCase());
|
|
665
433
|
}
|
|
666
|
-
if (ast.type === '
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
return new WhereFunctionalPseudoClassSelector(ast.name, ast.data);
|
|
672
|
-
}
|
|
673
|
-
if (ast.name === 'not') {
|
|
674
|
-
return new NotFunctionalPseudoClassSelector(ast.name, ast.data);
|
|
675
|
-
}
|
|
676
|
-
return new PseudoClassSelector(ast.name);
|
|
434
|
+
if (ast.type === '#') {
|
|
435
|
+
return new IdSelector(ast.identifier);
|
|
436
|
+
}
|
|
437
|
+
if (ast.type === '[]') {
|
|
438
|
+
return new AttributeSelector(ast.property, ast.test, ast.test && ast.value);
|
|
677
439
|
}
|
|
678
|
-
if (ast.type === '
|
|
440
|
+
if (ast.type === ':') {
|
|
441
|
+
return new PseudoClassSelector(ast.identifier);
|
|
442
|
+
}
|
|
443
|
+
if (ast.type === '*') {
|
|
679
444
|
return new UniversalSelector();
|
|
680
445
|
}
|
|
681
|
-
return new InvalidSelector(new Error(ast.type));
|
|
682
446
|
}
|
|
683
|
-
function createSimpleSelectorSequenceFromAst(
|
|
684
|
-
if (
|
|
447
|
+
function createSimpleSelectorSequenceFromAst(ast) {
|
|
448
|
+
if (ast.length === 0) {
|
|
685
449
|
return new InvalidSelector(new Error('Empty simple selector sequence.'));
|
|
686
450
|
}
|
|
687
|
-
if (
|
|
688
|
-
return createSimpleSelectorFromAst(
|
|
451
|
+
else if (ast.length === 1) {
|
|
452
|
+
return createSimpleSelectorFromAst(ast[0]);
|
|
689
453
|
}
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
const selector = createSimpleSelectorFromAst(ast);
|
|
693
|
-
if (selector instanceof InvalidSelector) {
|
|
694
|
-
return selector;
|
|
695
|
-
}
|
|
696
|
-
sequenceSelectors.push(selector);
|
|
454
|
+
else {
|
|
455
|
+
return new SimpleSelectorSequence(ast.map(createSimpleSelectorFromAst));
|
|
697
456
|
}
|
|
698
|
-
return new SimpleSelectorSequence(sequenceSelectors);
|
|
699
457
|
}
|
|
700
|
-
function createSelectorFromAst(
|
|
701
|
-
|
|
702
|
-
if (asts.length === 0) {
|
|
458
|
+
function createSelectorFromAst(ast) {
|
|
459
|
+
if (ast.length === 0) {
|
|
703
460
|
return new InvalidSelector(new Error('Empty selector.'));
|
|
704
461
|
}
|
|
705
|
-
if (
|
|
706
|
-
return
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
return selector;
|
|
718
|
-
}
|
|
719
|
-
selector.combinator = combinator;
|
|
720
|
-
simpleSelectorSequences.push(selector);
|
|
721
|
-
combinatorCount++;
|
|
722
|
-
// Cleanup stored selectors for the new sequence to take place
|
|
723
|
-
sequenceAsts = [];
|
|
724
|
-
}
|
|
725
|
-
else {
|
|
726
|
-
sequenceAsts.push(ast);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
if (combinatorCount > 0) {
|
|
730
|
-
// Create a sequence using the remaining selectors after the last combinator
|
|
731
|
-
if (sequenceAsts.length) {
|
|
732
|
-
const selector = createSimpleSelectorSequenceFromAst(sequenceAsts);
|
|
733
|
-
if (selector instanceof InvalidSelector) {
|
|
734
|
-
return selector;
|
|
462
|
+
else if (ast.length === 1) {
|
|
463
|
+
return createSimpleSelectorSequenceFromAst(ast[0][0]);
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
const simpleSelectorSequences = [];
|
|
467
|
+
let simpleSelectorSequence;
|
|
468
|
+
let combinator;
|
|
469
|
+
for (let i = 0; i < ast.length; i++) {
|
|
470
|
+
simpleSelectorSequence = createSimpleSelectorSequenceFromAst(ast[i][0]);
|
|
471
|
+
combinator = ast[i][1];
|
|
472
|
+
if (combinator) {
|
|
473
|
+
simpleSelectorSequence.combinator = combinator;
|
|
735
474
|
}
|
|
736
|
-
simpleSelectorSequences.push(
|
|
475
|
+
simpleSelectorSequences.push(simpleSelectorSequence);
|
|
737
476
|
}
|
|
738
|
-
return new
|
|
477
|
+
return new Selector(simpleSelectorSequences);
|
|
739
478
|
}
|
|
740
|
-
return createSimpleSelectorSequenceFromAst(sequenceAsts);
|
|
741
479
|
}
|
|
742
480
|
export function createSelector(sel) {
|
|
743
481
|
try {
|
|
744
|
-
const
|
|
745
|
-
if (!
|
|
482
|
+
const parsedSelector = parseSelector(sel);
|
|
483
|
+
if (!parsedSelector) {
|
|
746
484
|
return new InvalidSelector(new Error('Empty selector'));
|
|
747
485
|
}
|
|
748
|
-
return createSelectorFromAst(
|
|
486
|
+
return createSelectorFromAst(parsedSelector.value);
|
|
749
487
|
}
|
|
750
488
|
catch (e) {
|
|
751
489
|
return new InvalidSelector(e);
|