@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.
Files changed (87) hide show
  1. package/css/parser.d.ts +38 -0
  2. package/css/parser.js +108 -0
  3. package/css/parser.js.map +1 -1
  4. package/data/observable/index.d.ts +19 -60
  5. package/data/observable/index.js +155 -150
  6. package/data/observable/index.js.map +1 -1
  7. package/data/observable-array/index.d.ts +6 -10
  8. package/data/virtual-array/index.d.ts +5 -9
  9. package/image-source/index.android.d.ts +0 -2
  10. package/image-source/index.android.js +0 -6
  11. package/image-source/index.android.js.map +1 -1
  12. package/image-source/index.d.ts +0 -12
  13. package/image-source/index.ios.d.ts +0 -2
  14. package/image-source/index.ios.js +2 -25
  15. package/image-source/index.ios.js.map +1 -1
  16. package/package.json +1 -2
  17. package/references.d.ts +0 -1
  18. package/ui/action-bar/index.d.ts +6 -10
  19. package/ui/action-bar/index.ios.js +1 -1
  20. package/ui/action-bar/index.ios.js.map +1 -1
  21. package/ui/button/index.android.js +3 -3
  22. package/ui/button/index.android.js.map +1 -1
  23. package/ui/button/index.d.ts +5 -9
  24. package/ui/core/bindable/index.d.ts +0 -13
  25. package/ui/core/bindable/index.js +6 -27
  26. package/ui/core/bindable/index.js.map +1 -1
  27. package/ui/core/view/index.d.ts +12 -19
  28. package/ui/core/view/view-common.d.ts +5 -5
  29. package/ui/core/view/view-common.js +62 -52
  30. package/ui/core/view/view-common.js.map +1 -1
  31. package/ui/core/view-base/index.d.ts +0 -7
  32. package/ui/core/view-base/index.js +2 -11
  33. package/ui/core/view-base/index.js.map +1 -1
  34. package/ui/frame/index.d.ts +6 -10
  35. package/ui/gestures/gestures-common.d.ts +7 -10
  36. package/ui/gestures/gestures-common.js +71 -24
  37. package/ui/gestures/gestures-common.js.map +1 -1
  38. package/ui/gestures/index.android.js +46 -60
  39. package/ui/gestures/index.android.js.map +1 -1
  40. package/ui/gestures/index.d.ts +1 -3
  41. package/ui/gestures/index.ios.d.ts +2 -20
  42. package/ui/gestures/index.ios.js +66 -88
  43. package/ui/gestures/index.ios.js.map +1 -1
  44. package/ui/gestures/touch-manager.js +2 -2
  45. package/ui/gestures/touch-manager.js.map +1 -1
  46. package/ui/image/image-common.d.ts +0 -6
  47. package/ui/image/image-common.js +2 -21
  48. package/ui/image/image-common.js.map +1 -1
  49. package/ui/image/index.d.ts +0 -1
  50. package/ui/image/index.ios.js +1 -14
  51. package/ui/image/index.ios.js.map +1 -1
  52. package/ui/image-cache/index.d.ts +6 -10
  53. package/ui/index.d.ts +1 -1
  54. package/ui/index.js +1 -1
  55. package/ui/index.js.map +1 -1
  56. package/ui/list-view/index.d.ts +6 -10
  57. package/ui/page/index.d.ts +6 -10
  58. package/ui/placeholder/index.d.ts +5 -9
  59. package/ui/scroll-view/index.d.ts +5 -9
  60. package/ui/search-bar/index.d.ts +5 -9
  61. package/ui/segmented-bar/index.d.ts +5 -9
  62. package/ui/styling/css-selector.d.ts +23 -63
  63. package/ui/styling/css-selector.js +110 -372
  64. package/ui/styling/css-selector.js.map +1 -1
  65. package/ui/styling/style-properties.js +1 -1
  66. package/ui/styling/style-properties.js.map +1 -1
  67. package/ui/tab-view/index.d.ts +6 -10
  68. package/ui/transition/page-transition.android.js +1 -1
  69. package/ui/transition/page-transition.android.js.map +1 -1
  70. package/ui/web-view/index.d.ts +6 -10
  71. package/utils/common.d.ts +0 -1
  72. package/utils/common.js +1 -3
  73. package/utils/common.js.map +1 -1
  74. package/utils/index.ios.js +3 -2
  75. package/utils/index.ios.js.map +1 -1
  76. package/utils/ios/index.js +1 -1
  77. package/utils/ios/index.js.map +1 -1
  78. package/ui/image/symbol-effects-common.d.ts +0 -36
  79. package/ui/image/symbol-effects-common.js +0 -35
  80. package/ui/image/symbol-effects-common.js.map +0 -1
  81. package/ui/image/symbol-effects.android.d.ts +0 -4
  82. package/ui/image/symbol-effects.android.js +0 -8
  83. package/ui/image/symbol-effects.android.js.map +0 -1
  84. package/ui/image/symbol-effects.d.ts +0 -13
  85. package/ui/image/symbol-effects.ios.d.ts +0 -2
  86. package/ui/image/symbol-effects.ios.js +0 -93
  87. 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
- var Combinator;
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 eachNodePreviousGeneralSibling(node, callback) {
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
- function FunctionalPseudoClassProperties(specificity, rarity, pseudoSelectorListType) {
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 `<${this.e}>`;
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, ignoreCase) {
161
+ constructor(attribute, test, value) {
209
162
  super();
210
163
  this.attribute = attribute;
211
164
  this.test = test;
212
165
  this.value = value;
213
- this.ignoreCase = ignoreCase;
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(AttributeSelectorOperator[this.test] ?? this.test)}${this.value || ''}]${wrap(this.combinator)}`;
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, Boolean])
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 ComplexSelector extends SelectorCore {
268
+ export class Selector extends SelectorCore {
407
269
  constructor(selectors) {
408
270
  super();
409
271
  this.selectors = selectors;
410
- let siblingsToGroup;
411
- let currentGroup;
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 >= 0; i--) {
278
+ for (let i = selectors.length - 1; i > -1; i--) {
416
279
  const sel = selectors[i];
417
- switch (sel.combinator) {
418
- case undefined:
419
- case Combinator.descendant:
420
- siblingsToGroup = [];
421
- currentGroup = [siblingsToGroup];
422
- groups.push(currentGroup);
423
- break;
424
- case Combinator.child:
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
- siblingsToGroup.push(sel);
293
+ siblingGroup.push(sel);
439
294
  }
440
- this.groups = groups.map((g) => new Selector.ChildGroup(g.map((selectors) => (selectors.length > 1 ? new Selector.SiblingGroup(selectors) : selectors[0]))));
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.getMatchingNode(node, true);
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.getMatchingNode(ancestor, true))) {
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, base || this);
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.getMatchingNode(node, false);
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.getMatchingNode(ancestor, false);
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 extends SelectorBase {
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.getMatchingNode(node, true) != null;
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.getMatchingNode(node, false) != null;
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 extends SelectorBase {
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 === 'attribute') {
655
- if (ast.name === 'class') {
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 === 'tag') {
664
- return new TypeSelector(ast.name.replace('-', '').toLowerCase());
431
+ if (ast.type === '') {
432
+ return new TypeSelector(ast.identifier.replace('-', '').toLowerCase());
665
433
  }
666
- if (ast.type === 'pseudo') {
667
- if (ast.name === 'is') {
668
- return new IsFunctionalPseudoClassSelector(ast.name, ast.data);
669
- }
670
- if (ast.name === 'where') {
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 === 'universal') {
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(asts) {
684
- if (asts.length === 0) {
447
+ function createSimpleSelectorSequenceFromAst(ast) {
448
+ if (ast.length === 0) {
685
449
  return new InvalidSelector(new Error('Empty simple selector sequence.'));
686
450
  }
687
- if (asts.length === 1) {
688
- return createSimpleSelectorFromAst(asts[0]);
451
+ else if (ast.length === 1) {
452
+ return createSimpleSelectorFromAst(ast[0]);
689
453
  }
690
- const sequenceSelectors = [];
691
- for (const ast of asts) {
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(asts) {
701
- let result;
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 (asts.length === 1) {
706
- return createSimpleSelectorFromAst(asts[0]);
707
- }
708
- const simpleSelectorSequences = [];
709
- let sequenceAsts = [];
710
- let combinatorCount = 0;
711
- for (const ast of asts) {
712
- const combinator = Combinator[ast.type];
713
- // Combinator means the end of a sequence
714
- if (combinator != null) {
715
- const selector = createSimpleSelectorSequenceFromAst(sequenceAsts);
716
- if (selector instanceof InvalidSelector) {
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(selector);
475
+ simpleSelectorSequences.push(simpleSelectorSequence);
737
476
  }
738
- return new ComplexSelector(simpleSelectorSequences);
477
+ return new Selector(simpleSelectorSequences);
739
478
  }
740
- return createSimpleSelectorSequenceFromAst(sequenceAsts);
741
479
  }
742
480
  export function createSelector(sel) {
743
481
  try {
744
- const result = convertToCSSWhatSelector(sel);
745
- if (!result?.length) {
482
+ const parsedSelector = parseSelector(sel);
483
+ if (!parsedSelector) {
746
484
  return new InvalidSelector(new Error('Empty selector'));
747
485
  }
748
- return createSelectorFromAst(result[0]);
486
+ return createSelectorFromAst(parsedSelector.value);
749
487
  }
750
488
  catch (e) {
751
489
  return new InvalidSelector(e);