@markuplint/selector 4.0.1 → 4.1.1
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/lib/compare-specificity.d.ts.map +1 -0
- package/lib/create-selector.d.ts.map +1 -0
- package/lib/debug.d.ts.map +1 -0
- package/lib/extended-selector/aria-pseudo-class.d.ts.map +1 -0
- package/lib/extended-selector/aria-role-pseudo-class.d.ts.map +1 -0
- package/lib/extended-selector/content-model-pseudo-class.d.ts.map +1 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/invalid-selector-error.d.ts.map +1 -0
- package/lib/is.d.ts +9 -0
- package/lib/is.d.ts.map +1 -0
- package/lib/is.js +9 -0
- package/lib/match-selector.d.ts.map +1 -0
- package/lib/regex-selector-matches.d.ts.map +1 -0
- package/lib/selector.d.ts.map +1 -0
- package/lib/selector.js +44 -28
- package/lib/types.d.ts.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare-specificity.d.ts","sourceRoot":"","sources":["../src/compare-specificity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,cAehE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-selector.d.ts","sourceRoot":"","sources":["../src/create-selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAKpD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAIzC,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,QAAQ,YAkBhE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,eAAO,MAAM,GAAG,gBAAoB,CAAC;AAErC,wBAAgB,WAAW,SAU1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aria-pseudo-class.d.ts","sourceRoot":"","sources":["../../src/extended-selector/aria-pseudo-class.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAKlD;;GAEG;AACH,wBAAgB,eAAe,cACb,MAAM,UAGjB,OAAO,KACT,cAAc,CAkClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aria-role-pseudo-class.d.ts","sourceRoot":"","sources":["../../src/extended-selector/aria-role-pseudo-class.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAe,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAIjE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,QAAQ,aACjC,MAAM,UAGjB,OAAO,KACT,cAAc,CAmBlB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-model-pseudo-class.d.ts","sourceRoot":"","sources":["../../src/extended-selector/content-model-pseudo-class.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyB,cAAc,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,KAAK,EAAY,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAM9D,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,QAAQ,cACpC,MAAM,UAGlB,OAAO,KACT,cAAc,CAoDlB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalid-selector-error.d.ts","sourceRoot":"","sources":["../src/invalid-selector-error.ts"],"names":[],"mappings":"AAAA,qBAAa,oBAAqB,SAAQ,KAAK;IAC9C,IAAI,SAA0B;IAC9B,QAAQ,EAAE,MAAM,CAAC;gBACL,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAI9C"}
|
package/lib/is.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
export declare function isElement(node: Node): node is Element;
|
|
2
2
|
export declare function isNonDocumentTypeChildNode(node: Node): node is Element | CharacterData;
|
|
3
|
+
/**
|
|
4
|
+
* Checks if the given element is a pure HTML element.
|
|
5
|
+
*
|
|
6
|
+
* If a pure HTML element, `localName` returns lowercase,
|
|
7
|
+
* `nodeName` returns uppercase.
|
|
8
|
+
*
|
|
9
|
+
* @param el The element to check.
|
|
10
|
+
* @returns Returns true if the element is a pure HTML element, otherwise returns false.
|
|
11
|
+
*/
|
|
3
12
|
export declare function isPureHTMLElement(el: Element): boolean;
|
package/lib/is.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../src/is.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAExB,IAAI,EAAE,IAAI,GACR,IAAI,IAAI,OAAO,CAEjB;AAED,wBAAgB,0BAA0B,CAEzC,IAAI,EAAE,IAAI,GACR,IAAI,IAAI,OAAO,GAAG,aAAa,CAEjC;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAEhC,EAAE,EAAE,OAAO,WAGX"}
|
package/lib/is.js
CHANGED
|
@@ -8,6 +8,15 @@ export function isNonDocumentTypeChildNode(
|
|
|
8
8
|
node) {
|
|
9
9
|
return 'previousElementSibling' in node && 'nextElementSibling' in node;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Checks if the given element is a pure HTML element.
|
|
13
|
+
*
|
|
14
|
+
* If a pure HTML element, `localName` returns lowercase,
|
|
15
|
+
* `nodeName` returns uppercase.
|
|
16
|
+
*
|
|
17
|
+
* @param el The element to check.
|
|
18
|
+
* @returns Returns true if the element is a pure HTML element, otherwise returns false.
|
|
19
|
+
*/
|
|
11
20
|
export function isPureHTMLElement(
|
|
12
21
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
13
22
|
el) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-selector.d.ts","sourceRoot":"","sources":["../src/match-selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAA4D,MAAM,YAAY,CAAC;AAOvH,MAAM,MAAM,eAAe,GAAG,eAAe,GAAG,iBAAiB,CAAC;AAElE,KAAK,eAAe,GAAG;IACtB,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACjD,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACxB,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;CACxB,CAAC;AAEF,wBAAgB,aAAa,CAE5B,EAAE,EAAE,IAAI,EACR,QAAQ,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,GAC1C,eAAe,CAuBjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regex-selector-matches.d.ts","sourceRoot":"","sources":["../src/regex-selector-matches.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO;;SAiB7F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selector.d.ts","sourceRoot":"","sources":["../src/selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyB,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAcrF,KAAK,mBAAmB,GAAG,QAAQ,CAClC,MAAM,CACL,MAAM,EACN,CAAC,OAAO,EAAE,MAAM,KAAK,CAEpB,EAAE,EAAE,OAAO,KACP,cAAc,CACnB,CACD,CAAC;AAEF,qBAAa,QAAQ;;gBAGR,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAE,mBAAwB;IAIhE,KAAK,CAEJ,EAAE,EAAE,IAAI,EAER,KAAK,CAAC,EAAE,UAAU,GAAG,IAAI,GACvB,WAAW,GAAG,KAAK;IAWtB,MAAM,CAEL,EAAE,EAAE,IAAI,EAER,KAAK,CAAC,EAAE,UAAU,GAAG,IAAI;CAK1B"}
|
package/lib/selector.js
CHANGED
|
@@ -28,7 +28,7 @@ export class Selector {
|
|
|
28
28
|
el,
|
|
29
29
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
30
30
|
scope) {
|
|
31
|
-
scope = isElement(el) ? el : null;
|
|
31
|
+
scope = scope ?? (isElement(el) ? el : null);
|
|
32
32
|
const results = this.search(el, scope);
|
|
33
33
|
for (const result of results) {
|
|
34
34
|
if (result.matched) {
|
|
@@ -42,7 +42,7 @@ export class Selector {
|
|
|
42
42
|
el,
|
|
43
43
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
44
44
|
scope) {
|
|
45
|
-
scope = isElement(el) ? el : null;
|
|
45
|
+
scope = scope ?? (isElement(el) ? el : null);
|
|
46
46
|
return __classPrivateFieldGet(this, _Selector_ruleset, "f").match(el, scope);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -80,11 +80,17 @@ class Ruleset {
|
|
|
80
80
|
el,
|
|
81
81
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
82
82
|
scope) {
|
|
83
|
-
|
|
83
|
+
if (coreLog.enabled) {
|
|
84
|
+
coreLog('<%s> (%s)', isElement(el) ? el.localName : el.nodeName, scope ? (isElement(scope) ? scope.localName : scope.nodeName) : null);
|
|
85
|
+
}
|
|
84
86
|
return __classPrivateFieldGet(this, _Ruleset_selectorGroup, "f").map(selector => {
|
|
85
|
-
selLog
|
|
87
|
+
if (selLog.enabled) {
|
|
88
|
+
selLog('"%s"', selector.selector);
|
|
89
|
+
}
|
|
86
90
|
const res = selector.match(el, scope);
|
|
87
|
-
|
|
91
|
+
if (resLog.enabled) {
|
|
92
|
+
resLog('%s "%s" => %o', isElement(el) ? el.localName : el.nodeName, selector.selector, res);
|
|
93
|
+
}
|
|
88
94
|
return res;
|
|
89
95
|
});
|
|
90
96
|
}
|
|
@@ -423,6 +429,14 @@ class SelectorTarget {
|
|
|
423
429
|
}
|
|
424
430
|
}
|
|
425
431
|
}
|
|
432
|
+
/**
|
|
433
|
+
* Matching is executed in this order: ID > tag name > classes > attributes > pseudo-elements.
|
|
434
|
+
* If any of the selectors are unmatched, the rest of the selectors is skipped for better performance.
|
|
435
|
+
*
|
|
436
|
+
* @param el
|
|
437
|
+
* @param scope
|
|
438
|
+
* @private
|
|
439
|
+
*/
|
|
426
440
|
_matchWithoutCombineChecking(
|
|
427
441
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
428
442
|
el,
|
|
@@ -464,32 +478,11 @@ class SelectorTarget {
|
|
|
464
478
|
if (!__classPrivateFieldGet(this, _SelectorTarget_isAdded, "f") && !isScope(el, scope)) {
|
|
465
479
|
matched = false;
|
|
466
480
|
}
|
|
467
|
-
if (!this.id.every(id => id.value === el.id)) {
|
|
481
|
+
if (matched && !this.id.every(id => id.value === el.id)) {
|
|
468
482
|
matched = false;
|
|
469
483
|
}
|
|
470
484
|
specificity[0] += this.id.length;
|
|
471
|
-
if (
|
|
472
|
-
matched = false;
|
|
473
|
-
}
|
|
474
|
-
specificity[1] += this.class.length;
|
|
475
|
-
if (!this.attr.every(attr => attrMatch(attr, el))) {
|
|
476
|
-
matched = false;
|
|
477
|
-
}
|
|
478
|
-
specificity[1] += this.attr.length;
|
|
479
|
-
for (const pseudo of this.pseudo) {
|
|
480
|
-
const pseudoRes = pseudoMatch(pseudo, el, scope, __classPrivateFieldGet(this, _SelectorTarget_extended, "f"), this.depth);
|
|
481
|
-
specificity[0] += pseudoRes.specificity[0];
|
|
482
|
-
specificity[1] += pseudoRes.specificity[1];
|
|
483
|
-
specificity[2] += pseudoRes.specificity[2];
|
|
484
|
-
if (pseudoRes.matched) {
|
|
485
|
-
has.push(...pseudoRes.has);
|
|
486
|
-
}
|
|
487
|
-
else {
|
|
488
|
-
not.push(...(pseudoRes.not ?? []));
|
|
489
|
-
matched = false;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
if (this.tag && this.tag.type === 'tag') {
|
|
485
|
+
if (matched && this.tag && this.tag.type === 'tag') {
|
|
493
486
|
specificity[2] += 1;
|
|
494
487
|
let a = this.tag.value;
|
|
495
488
|
let b = el.localName;
|
|
@@ -501,6 +494,29 @@ class SelectorTarget {
|
|
|
501
494
|
matched = false;
|
|
502
495
|
}
|
|
503
496
|
}
|
|
497
|
+
if (matched && !this.class.every(className => el.classList.contains(className.value))) {
|
|
498
|
+
matched = false;
|
|
499
|
+
}
|
|
500
|
+
specificity[1] += this.class.length;
|
|
501
|
+
if (matched && !this.attr.every(attr => attrMatch(attr, el))) {
|
|
502
|
+
matched = false;
|
|
503
|
+
}
|
|
504
|
+
specificity[1] += this.attr.length;
|
|
505
|
+
if (matched) {
|
|
506
|
+
for (const pseudo of this.pseudo) {
|
|
507
|
+
const pseudoRes = pseudoMatch(pseudo, el, scope, __classPrivateFieldGet(this, _SelectorTarget_extended, "f"), this.depth);
|
|
508
|
+
specificity[0] += pseudoRes.specificity[0];
|
|
509
|
+
specificity[1] += pseudoRes.specificity[1];
|
|
510
|
+
specificity[2] += pseudoRes.specificity[2];
|
|
511
|
+
if (pseudoRes.matched) {
|
|
512
|
+
has.push(...pseudoRes.has);
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
not.push(...(pseudoRes.not ?? []));
|
|
516
|
+
matched = false;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
504
520
|
if (matched) {
|
|
505
521
|
return {
|
|
506
522
|
specificity,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE5D,MAAM,MAAM,cAAc,GAAG,qBAAqB,GAAG,uBAAuB,CAAC;AAE7E,MAAM,MAAM,qBAAqB,GAAG;IACnC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;IAC5C,QAAQ,CAAC,GAAG,EAAE,SAAS,qBAAqB,EAAE,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACrC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IACxB,QAAQ,CAAC,GAAG,CAAC,EAAE,SAAS,qBAAqB,EAAE,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,+BAA+B,GAAG;IAC7D,QAAQ,CAAC,WAAW,CAAC,EAAE;QACtB,QAAQ,CAAC,UAAU,EAAE,uBAAuB,CAAC;KAC7C,GAAG,aAAa,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,SAAS,GAAG,SAAS,CAAC;AAEpF,MAAM,MAAM,+BAA+B,GAAG;IAC7C,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/selector",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.1",
|
|
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,7 +25,7 @@
|
|
|
25
25
|
"clean": "tsc --build --clean"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@markuplint/ml-spec": "4.0.
|
|
28
|
+
"@markuplint/ml-spec": "4.0.2",
|
|
29
29
|
"@types/debug": "^4.1.12",
|
|
30
30
|
"debug": "^4.3.4",
|
|
31
31
|
"postcss-selector-parser": "^6.0.15",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"@types/jsdom": "21.1.6",
|
|
36
36
|
"jsdom": "24.0.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "10ce6c8374106f311eeaaffbae8f3fdcbb40f877"
|
|
39
39
|
}
|