@nativescript/core 8.8.0-embed.0 → 8.8.0-next-06-28-2024-9718658121

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 (41) hide show
  1. package/application/application.android.js +0 -4
  2. package/application/application.android.js.map +1 -1
  3. package/application/application.ios.js +1 -2
  4. package/application/application.ios.js.map +1 -1
  5. package/css/parser.d.ts +0 -38
  6. package/css/parser.js +0 -108
  7. package/css/parser.js.map +1 -1
  8. package/package.json +2 -1
  9. package/ui/core/view-base/index.d.ts +7 -0
  10. package/ui/core/view-base/index.js +11 -2
  11. package/ui/core/view-base/index.js.map +1 -1
  12. package/ui/frame/activity.android.js +47 -106
  13. package/ui/frame/activity.android.js.map +1 -1
  14. package/ui/frame/fragment.android.d.ts +1 -3
  15. package/ui/frame/fragment.android.js +3 -40
  16. package/ui/frame/fragment.android.js.map +1 -1
  17. package/ui/frame/index.android.d.ts +2 -3
  18. package/ui/frame/index.android.js +622 -6
  19. package/ui/frame/index.android.js.map +1 -1
  20. package/ui/frame/index.d.ts +0 -18
  21. package/ui/index.d.ts +0 -1
  22. package/ui/index.js +0 -1
  23. package/ui/index.js.map +1 -1
  24. package/ui/styling/css-selector.d.ts +63 -23
  25. package/ui/styling/css-selector.js +372 -110
  26. package/ui/styling/css-selector.js.map +1 -1
  27. package/ui/styling/style-properties.js +1 -1
  28. package/ui/styling/style-properties.js.map +1 -1
  29. package/ui/embedding/index.android.d.ts +0 -4
  30. package/ui/embedding/index.android.js +0 -14
  31. package/ui/embedding/index.android.js.map +0 -1
  32. package/ui/embedding/index.d.ts +0 -10
  33. package/ui/embedding/index.ios.d.ts +0 -1
  34. package/ui/embedding/index.ios.js +0 -4
  35. package/ui/embedding/index.ios.js.map +0 -1
  36. package/ui/frame/callbacks/activity-callbacks.d.ts +0 -19
  37. package/ui/frame/callbacks/activity-callbacks.js +0 -301
  38. package/ui/frame/callbacks/activity-callbacks.js.map +0 -1
  39. package/ui/frame/callbacks/fragment-callbacks.d.ts +0 -18
  40. package/ui/frame/callbacks/fragment-callbacks.js +0 -323
  41. package/ui/frame/callbacks/fragment-callbacks.js.map +0 -1
@@ -1,7 +1,27 @@
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
+ 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 = {}));
5
25
  var Match;
6
26
  (function (Match) {
7
27
  /**
@@ -13,7 +33,22 @@ var Match;
13
33
  */
14
34
  Match.Static = false;
15
35
  })(Match || (Match = {}));
16
- function getNodeDirectSibling(node) {
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) {
17
52
  if (!node.parent || !node.parent.getChildIndex || !node.parent.getChildAt) {
18
53
  return null;
19
54
  }
@@ -32,7 +67,19 @@ function SelectorProperties(specificity, rarity, dynamic = false) {
32
67
  return cls;
33
68
  };
34
69
  }
35
- let SelectorCore = class SelectorCore {
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 {
36
83
  lookupSort(sorter, base) {
37
84
  sorter.sortAsUniversal(base || this);
38
85
  }
@@ -69,7 +116,7 @@ let InvalidSelector = class InvalidSelector extends SimpleSelector {
69
116
  this.e = e;
70
117
  }
71
118
  toString() {
72
- return `<error: ${this.e}>`;
119
+ return `<${this.e}>`;
73
120
  }
74
121
  match(node) {
75
122
  return false;
@@ -158,52 +205,55 @@ ClassSelector = __decorate([
158
205
  ], ClassSelector);
159
206
  export { ClassSelector };
160
207
  let AttributeSelector = class AttributeSelector extends SimpleSelector {
161
- constructor(attribute, test, value) {
208
+ constructor(attribute, test, value, ignoreCase) {
162
209
  super();
163
210
  this.attribute = attribute;
164
211
  this.test = test;
165
212
  this.value = value;
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
- };
213
+ this.ignoreCase = ignoreCase;
202
214
  }
203
215
  toString() {
204
- return `[${this.attribute}${wrap(this.test)}${(this.test && this.value) || ''}]${wrap(this.combinator)}`;
216
+ return `[${this.attribute}${wrap(AttributeSelectorOperator[this.test] ?? this.test)}${this.value || ''}]${wrap(this.combinator)}`;
205
217
  }
206
218
  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
+ }
207
257
  return false;
208
258
  }
209
259
  mayMatch(node) {
@@ -215,7 +265,7 @@ let AttributeSelector = class AttributeSelector extends SimpleSelector {
215
265
  };
216
266
  AttributeSelector = __decorate([
217
267
  SelectorProperties(10 /* Specificity.Attribute */, 0 /* Rarity.Attribute */, Match.Dynamic),
218
- __metadata("design:paramtypes", [String, String, String])
268
+ __metadata("design:paramtypes", [String, String, String, Boolean])
219
269
  ], AttributeSelector);
220
270
  export { AttributeSelector };
221
271
  let PseudoClassSelector = class PseudoClassSelector extends SimpleSelector {
@@ -241,12 +291,100 @@ PseudoClassSelector = __decorate([
241
291
  __metadata("design:paramtypes", [String])
242
292
  ], PseudoClassSelector);
243
293
  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 };
244
382
  export class SimpleSelectorSequence extends SimpleSelector {
245
383
  constructor(selectors) {
246
384
  super();
247
385
  this.selectors = selectors;
248
386
  this.specificity = selectors.reduce((sum, sel) => sel.specificity + sum, 0);
249
- this.head = this.selectors.reduce((prev, curr) => (!prev || curr.rarity > prev.rarity ? curr : prev), null);
387
+ this.head = selectors.reduce((prev, curr) => (!prev || curr.rarity > prev.rarity ? curr : prev), null);
250
388
  this.dynamic = selectors.some((sel) => sel.dynamic);
251
389
  }
252
390
  toString() {
@@ -265,34 +403,41 @@ export class SimpleSelectorSequence extends SimpleSelector {
265
403
  this.head.lookupSort(sorter, base || this);
266
404
  }
267
405
  }
268
- export class Selector extends SelectorCore {
406
+ export class ComplexSelector extends SelectorCore {
269
407
  constructor(selectors) {
270
408
  super();
271
409
  this.selectors = selectors;
272
- const supportedCombinator = [undefined, ' ', '>', '+'];
273
- let siblingGroup;
274
- let lastGroup;
410
+ let siblingsToGroup;
411
+ let currentGroup;
275
412
  const groups = [];
276
413
  this.specificity = 0;
277
414
  this.dynamic = false;
278
- for (let i = selectors.length - 1; i > -1; i--) {
415
+ for (let i = selectors.length - 1; i >= 0; i--) {
279
416
  const sel = selectors[i];
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 = []));
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}.`);
288
433
  }
289
434
  this.specificity += sel.specificity;
290
435
  if (sel.dynamic) {
291
436
  this.dynamic = true;
292
437
  }
293
- siblingGroup.push(sel);
438
+ siblingsToGroup.push(sel);
294
439
  }
295
- this.groups = groups.map((g) => new Selector.ChildGroup(g.map((sg) => new Selector.SiblingGroup(sg))));
440
+ this.groups = groups.map((g) => new Selector.ChildGroup(g.map((selectors) => (selectors.length > 1 ? new Selector.SiblingGroup(selectors) : selectors[0]))));
296
441
  this.last = selectors[selectors.length - 1];
297
442
  }
298
443
  toString() {
@@ -301,13 +446,13 @@ export class Selector extends SelectorCore {
301
446
  match(node) {
302
447
  return this.groups.every((group, i) => {
303
448
  if (i === 0) {
304
- node = group.match(node);
449
+ node = group.getMatchingNode(node, true);
305
450
  return !!node;
306
451
  }
307
452
  else {
308
453
  let ancestor = node;
309
454
  while ((ancestor = ancestor.parent ?? ancestor._modalParent)) {
310
- if ((node = group.match(ancestor))) {
455
+ if ((node = group.getMatchingNode(ancestor, true))) {
311
456
  return true;
312
457
  }
313
458
  }
@@ -315,8 +460,14 @@ export class Selector extends SelectorCore {
315
460
  }
316
461
  });
317
462
  }
463
+ mayMatch(node) {
464
+ return false;
465
+ }
466
+ trackChanges(node, map) {
467
+ this.selectors.forEach((sel) => sel.trackChanges(node, map));
468
+ }
318
469
  lookupSort(sorter, base) {
319
- this.last.lookupSort(sorter, this);
470
+ this.last.lookupSort(sorter, base || this);
320
471
  }
321
472
  accumulateChanges(node, map) {
322
473
  if (!this.dynamic) {
@@ -325,7 +476,7 @@ export class Selector extends SelectorCore {
325
476
  const bounds = [];
326
477
  const mayMatch = this.groups.every((group, i) => {
327
478
  if (i === 0) {
328
- const nextNode = group.mayMatch(node);
479
+ const nextNode = group.getMatchingNode(node, false);
329
480
  bounds.push({ left: node, right: node });
330
481
  node = nextNode;
331
482
  return !!node;
@@ -333,7 +484,7 @@ export class Selector extends SelectorCore {
333
484
  else {
334
485
  let ancestor = node;
335
486
  while ((ancestor = ancestor.parent)) {
336
- const nextNode = group.mayMatch(ancestor);
487
+ const nextNode = group.getMatchingNode(ancestor, false);
337
488
  if (nextNode) {
338
489
  bounds.push({ left: ancestor, right: null });
339
490
  node = nextNode;
@@ -366,37 +517,112 @@ export class Selector extends SelectorCore {
366
517
  return mayMatch;
367
518
  }
368
519
  }
520
+ export var Selector;
369
521
  (function (Selector) {
370
522
  // Non-spec. Selector sequences are grouped by ancestor then by child combinators for easier backtracking.
371
- class ChildGroup {
523
+ class ChildGroup extends SelectorBase {
372
524
  constructor(selectors) {
525
+ super();
373
526
  this.selectors = selectors;
374
527
  this.dynamic = selectors.some((sel) => sel.dynamic);
375
528
  }
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
+ }
376
533
  match(node) {
377
- return this.selectors.every((sel, i) => (node = i === 0 ? node : node.parent) && sel.match(node)) ? node : null;
534
+ return this.getMatchingNode(node, true) != null;
378
535
  }
379
536
  mayMatch(node) {
380
- return this.selectors.every((sel, i) => (node = i === 0 ? node : node.parent) && sel.mayMatch(node)) ? node : null;
537
+ return this.getMatchingNode(node, false) != null;
381
538
  }
382
539
  trackChanges(node, map) {
383
- this.selectors.forEach((sel, i) => (node = i === 0 ? node : node.parent) && sel.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
+ });
384
551
  }
385
552
  }
386
553
  Selector.ChildGroup = ChildGroup;
387
- class SiblingGroup {
554
+ class SiblingGroup extends SelectorBase {
388
555
  constructor(selectors) {
556
+ super();
389
557
  this.selectors = selectors;
390
558
  this.dynamic = selectors.some((sel) => sel.dynamic);
391
559
  }
392
560
  match(node) {
393
- return this.selectors.every((sel, i) => (node = i === 0 ? node : getNodeDirectSibling(node)) && sel.match(node)) ? node : null;
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
+ });
394
577
  }
395
578
  mayMatch(node) {
396
- return this.selectors.every((sel, i) => (node = i === 0 ? node : getNodeDirectSibling(node)) && sel.mayMatch(node)) ? node : null;
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
+ });
397
595
  }
398
596
  trackChanges(node, map) {
399
- this.selectors.forEach((sel, i) => (node = i === 0 ? node : getNodeDirectSibling(node)) && sel.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
+ });
400
626
  }
401
627
  }
402
628
  Selector.SiblingGroup = SiblingGroup;
@@ -425,65 +651,101 @@ function createDeclaration(decl) {
425
651
  return { property: isCssVariable(decl.property) ? decl.property : decl.property.toLowerCase(), value: decl.value };
426
652
  }
427
653
  function createSimpleSelectorFromAst(ast) {
428
- if (ast.type === '.') {
429
- return new ClassSelector(ast.identifier);
430
- }
431
- if (ast.type === '') {
432
- return new TypeSelector(ast.identifier.replace('-', '').toLowerCase());
433
- }
434
- if (ast.type === '#') {
435
- return new IdSelector(ast.identifier);
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);
436
662
  }
437
- if (ast.type === '[]') {
438
- return new AttributeSelector(ast.property, ast.test, ast.test && ast.value);
663
+ if (ast.type === 'tag') {
664
+ return new TypeSelector(ast.name.replace('-', '').toLowerCase());
439
665
  }
440
- if (ast.type === ':') {
441
- return new PseudoClassSelector(ast.identifier);
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);
442
677
  }
443
- if (ast.type === '*') {
678
+ if (ast.type === 'universal') {
444
679
  return new UniversalSelector();
445
680
  }
681
+ return new InvalidSelector(new Error(ast.type));
446
682
  }
447
- function createSimpleSelectorSequenceFromAst(ast) {
448
- if (ast.length === 0) {
683
+ function createSimpleSelectorSequenceFromAst(asts) {
684
+ if (asts.length === 0) {
449
685
  return new InvalidSelector(new Error('Empty simple selector sequence.'));
450
686
  }
451
- else if (ast.length === 1) {
452
- return createSimpleSelectorFromAst(ast[0]);
687
+ if (asts.length === 1) {
688
+ return createSimpleSelectorFromAst(asts[0]);
453
689
  }
454
- else {
455
- return new SimpleSelectorSequence(ast.map(createSimpleSelectorFromAst));
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);
456
697
  }
698
+ return new SimpleSelectorSequence(sequenceSelectors);
457
699
  }
458
- function createSelectorFromAst(ast) {
459
- if (ast.length === 0) {
700
+ function createSelectorFromAst(asts) {
701
+ let result;
702
+ if (asts.length === 0) {
460
703
  return new InvalidSelector(new Error('Empty selector.'));
461
704
  }
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;
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;
474
735
  }
475
- simpleSelectorSequences.push(simpleSelectorSequence);
736
+ simpleSelectorSequences.push(selector);
476
737
  }
477
- return new Selector(simpleSelectorSequences);
738
+ return new ComplexSelector(simpleSelectorSequences);
478
739
  }
740
+ return createSimpleSelectorSequenceFromAst(sequenceAsts);
479
741
  }
480
742
  export function createSelector(sel) {
481
743
  try {
482
- const parsedSelector = parseSelector(sel);
483
- if (!parsedSelector) {
744
+ const result = convertToCSSWhatSelector(sel);
745
+ if (!result?.length) {
484
746
  return new InvalidSelector(new Error('Empty selector'));
485
747
  }
486
- return createSelectorFromAst(parsedSelector.value);
748
+ return createSelectorFromAst(result[0]);
487
749
  }
488
750
  catch (e) {
489
751
  return new InvalidSelector(e);