@markuplint/selector 3.3.0 → 3.4.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.
- package/lib/extended-selector/aria-pseudo-class.js +1 -1
- package/lib/extended-selector/aria-role-pseudo-class.js +2 -1
- package/lib/invalid-selector-error.d.ts +1 -1
- package/lib/match-selector.d.ts +5 -5
- package/lib/regex-selector-matches.d.ts +6 -2
- package/lib/regex-selector-matches.js +1 -1
- package/lib/selector.d.ts +4 -4
- package/lib/selector.js +7 -2
- package/lib/types.d.ts +13 -13
- package/package.json +3 -3
|
@@ -44,7 +44,7 @@ function ariaPseudoClass() {
|
|
|
44
44
|
exports.ariaPseudoClass = ariaPseudoClass;
|
|
45
45
|
function ariaPseudoClassParser(syntax) {
|
|
46
46
|
const [_query, _version] = syntax.split('|');
|
|
47
|
-
const query = _query.replace(/\s+/g, '').toLowerCase();
|
|
47
|
+
const query = _query === null || _query === void 0 ? void 0 : _query.replace(/\s+/g, '').toLowerCase();
|
|
48
48
|
const version = _version === '1.1' ? '1.1' : '1.2';
|
|
49
49
|
switch (query) {
|
|
50
50
|
case 'hasname': {
|
|
@@ -23,10 +23,11 @@ function ariaRolePseudoClass(specs) {
|
|
|
23
23
|
}
|
|
24
24
|
exports.ariaRolePseudoClass = ariaRolePseudoClass;
|
|
25
25
|
function ariaPseudoClassParser(syntax) {
|
|
26
|
+
var _a;
|
|
26
27
|
const [roleName, _version] = syntax.split('|');
|
|
27
28
|
const version = _version === '1.1' ? '1.1' : '1.2';
|
|
28
29
|
return {
|
|
29
|
-
role: roleName.trim().toLowerCase(),
|
|
30
|
+
role: (_a = roleName === null || roleName === void 0 ? void 0 : roleName.trim().toLowerCase()) !== null && _a !== void 0 ? _a : syntax.trim().toLowerCase(),
|
|
30
31
|
version,
|
|
31
32
|
};
|
|
32
33
|
}
|
package/lib/match-selector.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { Specificity, RegexSelector } from './types';
|
|
2
2
|
export type SelectorMatches = SelectorMatched | SelectorUnmatched;
|
|
3
3
|
type SelectorMatched = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
matched: true;
|
|
5
|
+
selector: string;
|
|
6
|
+
specificity: Specificity;
|
|
7
|
+
data?: Record<string, string>;
|
|
8
8
|
};
|
|
9
9
|
type SelectorUnmatched = {
|
|
10
|
-
|
|
10
|
+
matched: false;
|
|
11
11
|
};
|
|
12
12
|
export declare function matchSelector(el: Node, selector: string | RegexSelector | undefined): SelectorMatches;
|
|
13
13
|
export {};
|
|
@@ -18,7 +18,7 @@ function regexSelectorMatches(reg, raw, ignoreCase) {
|
|
|
18
18
|
exports.regexSelectorMatches = regexSelectorMatches;
|
|
19
19
|
function toRegexp(pattern) {
|
|
20
20
|
const matched = pattern.match(/^\/(.+)\/([ig]*)$/i);
|
|
21
|
-
if (matched) {
|
|
21
|
+
if (matched && matched[1]) {
|
|
22
22
|
return new RegExp(matched[1], matched[2]);
|
|
23
23
|
}
|
|
24
24
|
return pattern;
|
package/lib/selector.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { SelectorResult, Specificity } from './types';
|
|
2
2
|
type ExtendedPseudoClass = Record<string, (content: string) => (el: Element) => SelectorResult>;
|
|
3
3
|
export declare class Selector {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
#private;
|
|
5
|
+
constructor(selector: string, extended?: ExtendedPseudoClass);
|
|
6
|
+
match(el: Node, scope?: ParentNode | null): Specificity | false;
|
|
7
|
+
search(el: Node, scope?: ParentNode | null): SelectorResult[];
|
|
8
8
|
}
|
|
9
9
|
export {};
|
package/lib/selector.js
CHANGED
|
@@ -48,13 +48,14 @@ class Ruleset {
|
|
|
48
48
|
return new Ruleset(selectors, extended, 0);
|
|
49
49
|
}
|
|
50
50
|
constructor(selectors, extended, depth) {
|
|
51
|
+
var _a;
|
|
51
52
|
_Ruleset_selectorGroup.set(this, []);
|
|
52
53
|
tslib_1.__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f").push(...selectors.map(selector => new StructuredSelector(selector, depth, extended)));
|
|
53
54
|
const head = tslib_1.__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f")[0];
|
|
54
55
|
this.headCombinator = (head === null || head === void 0 ? void 0 : head.headCombinator) || null;
|
|
55
56
|
if (this.headCombinator) {
|
|
56
57
|
if (depth <= 0) {
|
|
57
|
-
throw new invalid_selector_error_1.InvalidSelectorError(`'${tslib_1.__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f")[0].selector}' is not a valid selector`);
|
|
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`);
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
}
|
|
@@ -71,12 +72,13 @@ class Ruleset {
|
|
|
71
72
|
_Ruleset_selectorGroup = new WeakMap();
|
|
72
73
|
class StructuredSelector {
|
|
73
74
|
constructor(selector, depth, extended) {
|
|
75
|
+
var _a;
|
|
74
76
|
_StructuredSelector_edge.set(this, void 0);
|
|
75
77
|
_StructuredSelector_selector.set(this, void 0);
|
|
76
78
|
tslib_1.__classPrivateFieldSet(this, _StructuredSelector_selector, selector, "f");
|
|
77
79
|
tslib_1.__classPrivateFieldSet(this, _StructuredSelector_edge, new SelectorTarget(extended, depth), "f");
|
|
78
80
|
this.headCombinator =
|
|
79
|
-
tslib_1.__classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes[0].type === 'combinator' ? tslib_1.__classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes[0].value || null : null;
|
|
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;
|
|
80
82
|
if (0 < depth && this.headCombinator) {
|
|
81
83
|
tslib_1.__classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes.unshift((0, postcss_selector_parser_1.pseudo)({ value: ':scope' }));
|
|
82
84
|
}
|
|
@@ -738,6 +740,9 @@ function pseudoMatch(pseudo, el, scope, extended, depth) {
|
|
|
738
740
|
}
|
|
739
741
|
const content = pseudo.nodes.map(node => node.toString()).join('');
|
|
740
742
|
const hook = extended[ext];
|
|
743
|
+
if (!hook) {
|
|
744
|
+
continue;
|
|
745
|
+
}
|
|
741
746
|
const matcher = hook(content);
|
|
742
747
|
return matcher(el);
|
|
743
748
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
export type Specificity = [number, number, number];
|
|
2
2
|
export type SelectorResult = SelectorMatchedResult | SelectorUnmatchedResult;
|
|
3
3
|
export type SelectorMatchedResult = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
specificity: Specificity;
|
|
5
|
+
matched: true;
|
|
6
|
+
nodes: (Element | Text)[];
|
|
7
|
+
has: SelectorMatchedResult[];
|
|
8
8
|
};
|
|
9
9
|
export type SelectorUnmatchedResult = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
specificity: Specificity;
|
|
11
|
+
matched: false;
|
|
12
|
+
not?: SelectorMatchedResult[];
|
|
13
13
|
};
|
|
14
14
|
export type RegexSelector = RegexSelectorWithoutCombination & {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
combination?: {
|
|
16
|
+
combinator: RegexSelectorCombinator;
|
|
17
|
+
} & RegexSelector;
|
|
18
18
|
};
|
|
19
19
|
export type RegexSelectorCombinator = ' ' | '>' | '+' | '~' | ':has(+)' | ':has(~)';
|
|
20
20
|
export type RegexSelectorWithoutCombination = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
nodeName?: string;
|
|
22
|
+
attrName?: string;
|
|
23
|
+
attrValue?: string;
|
|
24
24
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/selector",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.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,10 @@
|
|
|
25
25
|
"tslib": "^2.4.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@markuplint/ml-spec": "3.
|
|
28
|
+
"@markuplint/ml-spec": "3.4.0",
|
|
29
29
|
"@types/debug": "^4.1.7",
|
|
30
30
|
"@types/jsdom": "16",
|
|
31
31
|
"jsdom": "19"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "a83e0f5f214a9bbcc0286b9e269074ddca6189e7"
|
|
34
34
|
}
|