@markuplint/selector 3.4.0 → 3.6.0

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.
@@ -6,7 +6,9 @@ const ml_spec_1 = require("@markuplint/ml-spec");
6
6
  * Version Syntax is not support yet.
7
7
  */
8
8
  function ariaPseudoClass() {
9
- return (content) => (el) => {
9
+ return (content) => (
10
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
11
+ el) => {
10
12
  const aria = ariaPseudoClassParser(content);
11
13
  const name = (0, ml_spec_1.getAccname)(el);
12
14
  switch (aria.type) {
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ariaRolePseudoClass = void 0;
4
4
  const ml_spec_1 = require("@markuplint/ml-spec");
5
5
  function ariaRolePseudoClass(specs) {
6
- return (content) => (el) => {
6
+ return (content) => (
7
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
8
+ el) => {
7
9
  var _a, _b;
8
10
  const aria = ariaPseudoClassParser(content);
9
11
  const computed = (0, ml_spec_1.getComputedRole)(specs, el, (_a = aria.version) !== null && _a !== void 0 ? _a : '1.2');
@@ -4,7 +4,9 @@ exports.contentModelPseudoClass = void 0;
4
4
  const ml_spec_1 = require("@markuplint/ml-spec");
5
5
  const create_selector_1 = require("../create-selector");
6
6
  function contentModelPseudoClass(specs) {
7
- return (category) => (el) => {
7
+ return (category) => (
8
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
9
+ el) => {
8
10
  category = category.trim().toLowerCase();
9
11
  const selectors = (0, ml_spec_1.contentModelCategoryToTagNames)(`#${category}`, specs.def);
10
12
  const matched = selectors
@@ -40,7 +42,7 @@ function contentModelPseudoClass(specs) {
40
42
  })
41
43
  .flat()
42
44
  .filter((m) => m.matched);
43
- if (matched.length) {
45
+ if (matched.length > 0) {
44
46
  return {
45
47
  specificity: [0, 1, 0],
46
48
  matched: true,
package/lib/is.js CHANGED
@@ -1,15 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isPureHTMLElement = exports.isNonDocumentTypeChildNode = exports.isElement = void 0;
4
- function isElement(node) {
4
+ function isElement(
5
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
6
+ node) {
5
7
  return node.nodeType === node.ELEMENT_NODE;
6
8
  }
7
9
  exports.isElement = isElement;
8
- function isNonDocumentTypeChildNode(node) {
10
+ function isNonDocumentTypeChildNode(
11
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
12
+ node) {
9
13
  return 'previousElementSibling' in node && 'nextElementSibling' in node;
10
14
  }
11
15
  exports.isNonDocumentTypeChildNode = isNonDocumentTypeChildNode;
12
- function isPureHTMLElement(el) {
16
+ function isPureHTMLElement(
17
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
18
+ el) {
13
19
  return el.localName !== el.nodeName;
14
20
  }
15
21
  exports.isPureHTMLElement = isPureHTMLElement;
@@ -1,13 +1,13 @@
1
1
  import type { Specificity, RegexSelector } from './types';
2
2
  export type SelectorMatches = SelectorMatched | SelectorUnmatched;
3
3
  type SelectorMatched = {
4
- matched: true;
5
- selector: string;
6
- specificity: Specificity;
7
- data?: Record<string, string>;
4
+ readonly matched: true;
5
+ readonly selector: string;
6
+ readonly specificity: Specificity;
7
+ readonly data?: Readonly<Record<string, string>>;
8
8
  };
9
9
  type SelectorUnmatched = {
10
- matched: false;
10
+ readonly matched: false;
11
11
  };
12
12
  export declare function matchSelector(el: Node, selector: string | RegexSelector | undefined): SelectorMatches;
13
13
  export {};
@@ -6,8 +6,10 @@ const tslib_1 = require("tslib");
6
6
  const is_1 = require("./is");
7
7
  const regex_selector_matches_1 = require("./regex-selector-matches");
8
8
  const selector_1 = require("./selector");
9
- function matchSelector(el, selector) {
10
- if (!selector) {
9
+ function matchSelector(
10
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
11
+ el, selector) {
12
+ if (selector == null || selector === '') {
11
13
  return {
12
14
  matched: false,
13
15
  };
@@ -15,7 +17,7 @@ function matchSelector(el, selector) {
15
17
  if (typeof selector === 'string') {
16
18
  const sel = new selector_1.Selector(selector);
17
19
  const specificity = sel.match(el);
18
- if (specificity) {
20
+ if (specificity !== false) {
19
21
  return {
20
22
  matched: true,
21
23
  selector,
@@ -29,7 +31,9 @@ function matchSelector(el, selector) {
29
31
  return regexSelect(el, selector);
30
32
  }
31
33
  exports.matchSelector = matchSelector;
32
- function regexSelect(el, selector) {
34
+ function regexSelect(
35
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
36
+ el, selector) {
33
37
  let edge = new SelectorTarget(selector);
34
38
  let edgeSelector = selector.combination;
35
39
  while (edgeSelector) {
@@ -49,7 +53,9 @@ class SelectorTarget {
49
53
  from(target, combinator) {
50
54
  tslib_1.__classPrivateFieldSet(this, _SelectorTarget_combinedFrom, { target, combinator }, "f");
51
55
  }
52
- match(el) {
56
+ match(
57
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
58
+ el) {
53
59
  const unitCheck = this._matchWithoutCombineChecking(el);
54
60
  if (!unitCheck.matched) {
55
61
  return unitCheck;
@@ -139,12 +145,16 @@ class SelectorTarget {
139
145
  }
140
146
  }
141
147
  }
142
- _matchWithoutCombineChecking(el) {
148
+ _matchWithoutCombineChecking(
149
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
150
+ el) {
143
151
  return uncombinedRegexSelect(el, tslib_1.__classPrivateFieldGet(this, _SelectorTarget_selector, "f"));
144
152
  }
145
153
  }
146
154
  _SelectorTarget_combinedFrom = new WeakMap(), _SelectorTarget_selector = new WeakMap();
147
- function uncombinedRegexSelect(el, selector) {
155
+ function uncombinedRegexSelect(
156
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
157
+ el, selector) {
148
158
  if (!(0, is_1.isElement)(el)) {
149
159
  return {
150
160
  matched: false,
package/lib/selector.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { SelectorResult, Specificity } from './types';
2
- type ExtendedPseudoClass = Record<string, (content: string) => (el: Element) => SelectorResult>;
2
+ type ExtendedPseudoClass = Readonly<Record<string, (content: string) => (el: Element) => SelectorResult>>;
3
3
  export declare class Selector {
4
4
  #private;
5
5
  constructor(selector: string, extended?: ExtendedPseudoClass);
package/lib/selector.js CHANGED
@@ -16,7 +16,12 @@ class Selector {
16
16
  _Selector_ruleset.set(this, void 0);
17
17
  tslib_1.__classPrivateFieldSet(this, _Selector_ruleset, Ruleset.parse(selector, extended), "f");
18
18
  }
19
- match(el, scope = (0, is_1.isElement)(el) ? el : null) {
19
+ match(
20
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
21
+ el,
22
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
23
+ scope) {
24
+ scope = (0, is_1.isElement)(el) ? el : null;
20
25
  const results = this.search(el, scope);
21
26
  for (const result of results) {
22
27
  if (result.matched) {
@@ -25,7 +30,12 @@ class Selector {
25
30
  }
26
31
  return false;
27
32
  }
28
- search(el, scope = (0, is_1.isElement)(el) ? el : null) {
33
+ search(
34
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
35
+ el,
36
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
37
+ scope) {
38
+ scope = (0, is_1.isElement)(el) ? el : null;
29
39
  return tslib_1.__classPrivateFieldGet(this, _Selector_ruleset, "f").match(el, scope);
30
40
  }
31
41
  }
@@ -48,18 +58,22 @@ class Ruleset {
48
58
  return new Ruleset(selectors, extended, 0);
49
59
  }
50
60
  constructor(selectors, extended, depth) {
51
- var _a;
61
+ var _a, _b;
52
62
  _Ruleset_selectorGroup.set(this, []);
53
63
  tslib_1.__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f").push(...selectors.map(selector => new StructuredSelector(selector, depth, extended)));
54
64
  const head = tslib_1.__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f")[0];
55
- this.headCombinator = (head === null || head === void 0 ? void 0 : head.headCombinator) || null;
65
+ this.headCombinator = (_a = head === null || head === void 0 ? void 0 : head.headCombinator) !== null && _a !== void 0 ? _a : null;
56
66
  if (this.headCombinator) {
57
67
  if (depth <= 0) {
58
- throw new invalid_selector_error_1.InvalidSelectorError(`'${(_a = tslib_1.__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f")[0]) === null || _a === void 0 ? void 0 : _a.selector}' is not a valid selector`);
68
+ throw new invalid_selector_error_1.InvalidSelectorError(`'${(_b = tslib_1.__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f")[0]) === null || _b === void 0 ? void 0 : _b.selector}' is not a valid selector`);
59
69
  }
60
70
  }
61
71
  }
62
- match(el, scope) {
72
+ match(
73
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
74
+ el,
75
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
76
+ scope) {
63
77
  (0, debug_1.log)('<%s> (%s)', (0, is_1.isElement)(el) ? el.localName : el.nodeName, scope ? ((0, is_1.isElement)(scope) ? scope.localName : scope.nodeName) : null);
64
78
  return tslib_1.__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f").map(selector => {
65
79
  selLog('"%s"', selector.selector);
@@ -72,17 +86,18 @@ class Ruleset {
72
86
  _Ruleset_selectorGroup = new WeakMap();
73
87
  class StructuredSelector {
74
88
  constructor(selector, depth, extended) {
75
- var _a;
89
+ var _a, _b;
76
90
  _StructuredSelector_edge.set(this, void 0);
77
91
  _StructuredSelector_selector.set(this, void 0);
78
92
  tslib_1.__classPrivateFieldSet(this, _StructuredSelector_selector, selector, "f");
79
93
  tslib_1.__classPrivateFieldSet(this, _StructuredSelector_edge, new SelectorTarget(extended, depth), "f");
80
94
  this.headCombinator =
81
- ((_a = tslib_1.__classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes[0]) === null || _a === void 0 ? void 0 : _a.type) === 'combinator' ? tslib_1.__classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes[0].value || null : null;
95
+ ((_a = tslib_1.__classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes[0]) === null || _a === void 0 ? void 0 : _a.type) === 'combinator' ? (_b = tslib_1.__classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes[0].value) !== null && _b !== void 0 ? _b : null : null;
96
+ const nodes = tslib_1.__classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes.slice();
82
97
  if (0 < depth && this.headCombinator) {
83
- tslib_1.__classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes.unshift((0, postcss_selector_parser_1.pseudo)({ value: ':scope' }));
98
+ nodes.unshift((0, postcss_selector_parser_1.pseudo)({ value: ':scope' }));
84
99
  }
85
- tslib_1.__classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes.forEach(node => {
100
+ nodes.forEach(node => {
86
101
  switch (node.type) {
87
102
  case 'combinator': {
88
103
  const combinedTarget = new SelectorTarget(extended, depth);
@@ -109,7 +124,11 @@ class StructuredSelector {
109
124
  get selector() {
110
125
  return tslib_1.__classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes.join('');
111
126
  }
112
- match(el, scope) {
127
+ match(
128
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
129
+ el,
130
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
131
+ scope) {
113
132
  return tslib_1.__classPrivateFieldGet(this, _StructuredSelector_edge, "f").match(el, scope, 0);
114
133
  }
115
134
  }
@@ -156,16 +175,20 @@ class SelectorTarget {
156
175
  from(target, combinator) {
157
176
  tslib_1.__classPrivateFieldSet(this, _SelectorTarget_combinedFrom, { target, combinator }, "f");
158
177
  }
159
- match(el, scope, count) {
160
- var _a;
178
+ match(
179
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
180
+ el,
181
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
182
+ scope, count) {
183
+ var _a, _b, _c;
161
184
  const result = this._match(el, scope, count);
162
185
  if (selLog.enabled) {
163
186
  const nodeName = el.nodeName;
164
- const selector = ((_a = tslib_1.__classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f")) === null || _a === void 0 ? void 0 : _a.target.toString()) || this.toString();
187
+ const selector = (_b = (_a = tslib_1.__classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f")) === null || _a === void 0 ? void 0 : _a.target.toString()) !== null && _b !== void 0 ? _b : this.toString();
165
188
  const combinator = result.combinator ? ` ${result.combinator}` : '';
166
189
  selLog('The %s element by "%s" => %s (%d)', nodeName, `${selector}${combinator}`, result.matched, count);
167
190
  if (selector === ':scope') {
168
- selLog(`† Scope is the ${(scope === null || scope === void 0 ? void 0 : scope.nodeName) || null}`);
191
+ selLog(`† Scope is the ${(_c = scope === null || scope === void 0 ? void 0 : scope.nodeName) !== null && _c !== void 0 ? _c : null}`);
169
192
  }
170
193
  }
171
194
  delete result.combinator;
@@ -181,7 +204,11 @@ class SelectorTarget {
181
204
  this.pseudo.map(pseudo => pseudo.value).join(''),
182
205
  ].join('');
183
206
  }
184
- _match(el, scope, count) {
207
+ _match(
208
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
209
+ el,
210
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
211
+ scope, count) {
185
212
  const unitCheck = this._matchWithoutCombineChecking(el, scope);
186
213
  if (!unitCheck.matched) {
187
214
  return unitCheck;
@@ -229,7 +256,7 @@ class SelectorTarget {
229
256
  unitCheck.specificity[2] + res.specificity[2],
230
257
  ];
231
258
  }
232
- if (matchedNodes.length) {
259
+ if (matchedNodes.length > 0) {
233
260
  return {
234
261
  combinator: '␣',
235
262
  specificity,
@@ -250,7 +277,7 @@ class SelectorTarget {
250
277
  const matchedNodes = [];
251
278
  const has = [];
252
279
  const not = [];
253
- const specificity = unitCheck.specificity;
280
+ const specificity = [...unitCheck.specificity];
254
281
  const parentNode = el.parentElement;
255
282
  if (parentNode) {
256
283
  const res = target.match(parentNode, scope, count + 1);
@@ -273,7 +300,7 @@ class SelectorTarget {
273
300
  specificity[1] += res.specificity[1];
274
301
  specificity[2] += res.specificity[2];
275
302
  }
276
- if (matchedNodes.length) {
303
+ if (matchedNodes.length > 0) {
277
304
  return {
278
305
  combinator: '>',
279
306
  specificity,
@@ -294,7 +321,7 @@ class SelectorTarget {
294
321
  const matchedNodes = [];
295
322
  const has = [];
296
323
  const not = [];
297
- const specificity = unitCheck.specificity;
324
+ const specificity = [...unitCheck.specificity];
298
325
  if (el.previousElementSibling) {
299
326
  const res = target.match(el.previousElementSibling, scope, count + 1);
300
327
  specificity[0] += res.specificity[0];
@@ -316,7 +343,7 @@ class SelectorTarget {
316
343
  specificity[1] += res.specificity[1];
317
344
  specificity[2] += res.specificity[2];
318
345
  }
319
- if (matchedNodes.length) {
346
+ if (matchedNodes.length > 0) {
320
347
  return {
321
348
  combinator: '+',
322
349
  specificity,
@@ -367,7 +394,7 @@ class SelectorTarget {
367
394
  unitCheck.specificity[2] + res.specificity[2],
368
395
  ];
369
396
  }
370
- if (matchedNodes.length) {
397
+ if (matchedNodes.length > 0) {
371
398
  return {
372
399
  combinator: '~',
373
400
  specificity,
@@ -392,7 +419,11 @@ class SelectorTarget {
392
419
  }
393
420
  }
394
421
  }
395
- _matchWithoutCombineChecking(el, scope) {
422
+ _matchWithoutCombineChecking(
423
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
424
+ el,
425
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
426
+ scope) {
396
427
  var _a;
397
428
  const specificity = [0, 0, 0];
398
429
  if (!(0, is_1.isElement)(el)) {
@@ -483,7 +514,9 @@ class SelectorTarget {
483
514
  }
484
515
  }
485
516
  _SelectorTarget_combinedFrom = new WeakMap(), _SelectorTarget_extended = new WeakMap(), _SelectorTarget_isAdded = new WeakMap();
486
- function attrMatch(attr, el) {
517
+ function attrMatch(attr,
518
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
519
+ el) {
487
520
  return Array.from(el.attributes).some(attrOfEl => {
488
521
  if (attr.attribute !== attrOfEl.localName) {
489
522
  return false;
@@ -521,7 +554,7 @@ function attrMatch(attr, el) {
521
554
  break;
522
555
  }
523
556
  case '*=': {
524
- if (valueOfEl.indexOf(value) === -1) {
557
+ if (!valueOfEl.includes(value)) {
525
558
  return false;
526
559
  }
527
560
  break;
@@ -543,7 +576,11 @@ function attrMatch(attr, el) {
543
576
  return true;
544
577
  });
545
578
  }
546
- function pseudoMatch(pseudo, el, scope, extended, depth) {
579
+ function pseudoMatch(pseudo,
580
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
581
+ el,
582
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
583
+ scope, extended, depth) {
547
584
  switch (pseudo.value) {
548
585
  //
549
586
  /**
@@ -555,7 +592,7 @@ function pseudoMatch(pseudo, el, scope, extended, depth) {
555
592
  let parent = el.parentElement;
556
593
  while (parent) {
557
594
  const matched = ruleset.match(parent, scope).filter((r) => r.matched);
558
- if (matched.length) {
595
+ if (matched.length > 0) {
559
596
  return {
560
597
  specificity,
561
598
  matched: true,
@@ -599,7 +636,7 @@ function pseudoMatch(pseudo, el, scope, extended, depth) {
599
636
  const matched = resList.filter((r) => r.matched);
600
637
  return {
601
638
  specificity,
602
- matched: !!matched.length,
639
+ matched: matched.length > 0,
603
640
  nodes: matched.map(m => m.nodes).flat(),
604
641
  has: matched.map(m => m.has).flat(),
605
642
  };
@@ -613,7 +650,7 @@ function pseudoMatch(pseudo, el, scope, extended, depth) {
613
650
  const has = getSiblings(el)
614
651
  .map(sib => ruleset.match(sib, el).filter((m) => m.matched))
615
652
  .flat();
616
- if (has.length) {
653
+ if (has.length > 0) {
617
654
  return {
618
655
  specificity,
619
656
  matched: true,
@@ -630,7 +667,7 @@ function pseudoMatch(pseudo, el, scope, extended, depth) {
630
667
  const has = getDescendants(el)
631
668
  .map(sib => ruleset.match(sib, el).filter((m) => m.matched))
632
669
  .flat();
633
- if (has.length) {
670
+ if (has.length > 0) {
634
671
  return {
635
672
  specificity,
636
673
  matched: true,
@@ -651,7 +688,7 @@ function pseudoMatch(pseudo, el, scope, extended, depth) {
651
688
  const matched = resList.filter((r) => r.matched);
652
689
  return {
653
690
  specificity: [0, 0, 0],
654
- matched: !!matched.length,
691
+ matched: matched.length > 0,
655
692
  nodes: matched.map(m => m.nodes).flat(),
656
693
  has: matched.map(m => m.has).flat(),
657
694
  };
@@ -750,10 +787,17 @@ function pseudoMatch(pseudo, el, scope, extended, depth) {
750
787
  }
751
788
  }
752
789
  }
753
- function isScope(el, scope) {
754
- return el === scope || el.parentNode === null;
790
+ function isScope(
791
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
792
+ el,
793
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
794
+ scope) {
795
+ var _a;
796
+ return (_a = el === scope) !== null && _a !== void 0 ? _a : el.parentNode === null;
755
797
  }
756
- function getDescendants(el, includeSelf = false) {
798
+ function getDescendants(
799
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
800
+ el, includeSelf = false) {
757
801
  return [
758
802
  ...Array.from(el.children)
759
803
  .map(child => getDescendants(child, true))
@@ -761,11 +805,15 @@ function getDescendants(el, includeSelf = false) {
761
805
  ...(includeSelf ? [el] : []),
762
806
  ];
763
807
  }
764
- function getSiblings(el) {
765
- var _a;
766
- return Array.from(((_a = el.parentElement) === null || _a === void 0 ? void 0 : _a.children) || []);
808
+ function getSiblings(
809
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
810
+ el) {
811
+ var _a, _b;
812
+ return Array.from((_b = (_a = el.parentElement) === null || _a === void 0 ? void 0 : _a.children) !== null && _b !== void 0 ? _b : []);
767
813
  }
768
- function getSpecificity(results) {
814
+ function getSpecificity(
815
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
816
+ results) {
769
817
  let specificity;
770
818
  for (const result of results) {
771
819
  if (specificity) {
package/lib/types.d.ts CHANGED
@@ -1,24 +1,24 @@
1
- export type Specificity = [number, number, number];
1
+ export type Specificity = readonly [number, number, number];
2
2
  export type SelectorResult = SelectorMatchedResult | SelectorUnmatchedResult;
3
3
  export type SelectorMatchedResult = {
4
- specificity: Specificity;
5
- matched: true;
6
- nodes: (Element | Text)[];
7
- has: SelectorMatchedResult[];
4
+ readonly specificity: Specificity;
5
+ readonly matched: true;
6
+ readonly nodes: readonly (Element | Text)[];
7
+ readonly has: readonly SelectorMatchedResult[];
8
8
  };
9
9
  export type SelectorUnmatchedResult = {
10
- specificity: Specificity;
11
- matched: false;
12
- not?: SelectorMatchedResult[];
10
+ readonly specificity: Specificity;
11
+ readonly matched: false;
12
+ readonly not?: readonly SelectorMatchedResult[];
13
13
  };
14
14
  export type RegexSelector = RegexSelectorWithoutCombination & {
15
- combination?: {
16
- combinator: RegexSelectorCombinator;
15
+ readonly combination?: {
16
+ readonly combinator: RegexSelectorCombinator;
17
17
  } & RegexSelector;
18
18
  };
19
19
  export type RegexSelectorCombinator = ' ' | '>' | '+' | '~' | ':has(+)' | ':has(~)';
20
20
  export type RegexSelectorWithoutCombination = {
21
- nodeName?: string;
22
- attrName?: string;
23
- attrValue?: string;
21
+ readonly nodeName?: string;
22
+ readonly attrName?: string;
23
+ readonly attrValue?: string;
24
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/selector",
3
- "version": "3.4.0",
3
+ "version": "3.6.0",
4
4
  "description": "Extended W3C Selectors matcher",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -25,10 +25,11 @@
25
25
  "tslib": "^2.4.1"
26
26
  },
27
27
  "devDependencies": {
28
- "@markuplint/ml-spec": "3.4.0",
28
+ "@markuplint/ml-spec": "3.6.0",
29
29
  "@types/debug": "^4.1.7",
30
30
  "@types/jsdom": "16",
31
- "jsdom": "19"
31
+ "jsdom": "19",
32
+ "type-fest": "^3.6.1"
32
33
  },
33
- "gitHead": "a83e0f5f214a9bbcc0286b9e269074ddca6189e7"
34
+ "gitHead": "715dd53d3b1064a9bcf616c1533921cad9e3b187"
34
35
  }