@markuplint/selector 3.8.0 → 3.10.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/create-selector.d.ts +1 -1
- package/lib/create-selector.js +7 -5
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/invalid-selector-error.d.ts +3 -1
- package/lib/invalid-selector-error.js +3 -2
- package/lib/match-selector.d.ts +5 -5
- package/lib/regex-selector-matches.d.ts +2 -6
- package/lib/selector.d.ts +4 -4
- package/lib/selector.js +9 -6
- package/lib/types.d.ts +13 -13
- package/package.json +8 -8
package/lib/create-selector.d.ts
CHANGED
package/lib/create-selector.js
CHANGED
|
@@ -11,11 +11,13 @@ function createSelector(selector, specs) {
|
|
|
11
11
|
if (instance) {
|
|
12
12
|
return instance;
|
|
13
13
|
}
|
|
14
|
-
instance = new selector_1.Selector(selector,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
instance = new selector_1.Selector(selector, specs
|
|
15
|
+
? {
|
|
16
|
+
model: (0, content_model_pseudo_class_1.contentModelPseudoClass)(specs),
|
|
17
|
+
aria: (0, aria_pseudo_class_1.ariaPseudoClass)(),
|
|
18
|
+
role: (0, aria_role_pseudo_class_1.ariaRolePseudoClass)(specs),
|
|
19
|
+
}
|
|
20
|
+
: undefined);
|
|
19
21
|
caches.set(selector, instance);
|
|
20
22
|
return instance;
|
|
21
23
|
}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSelector = exports.matchSelector = exports.compareSpecificity = void 0;
|
|
3
|
+
exports.InvalidSelectorError = exports.createSelector = exports.matchSelector = exports.compareSpecificity = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
var compare_specificity_1 = require("./compare-specificity");
|
|
6
6
|
Object.defineProperty(exports, "compareSpecificity", { enumerable: true, get: function () { return compare_specificity_1.compareSpecificity; } });
|
|
@@ -8,4 +8,6 @@ var match_selector_1 = require("./match-selector");
|
|
|
8
8
|
Object.defineProperty(exports, "matchSelector", { enumerable: true, get: function () { return match_selector_1.matchSelector; } });
|
|
9
9
|
var create_selector_1 = require("./create-selector");
|
|
10
10
|
Object.defineProperty(exports, "createSelector", { enumerable: true, get: function () { return create_selector_1.createSelector; } });
|
|
11
|
+
var invalid_selector_error_1 = require("./invalid-selector-error");
|
|
12
|
+
Object.defineProperty(exports, "InvalidSelectorError", { enumerable: true, get: function () { return invalid_selector_error_1.InvalidSelectorError; } });
|
|
11
13
|
tslib_1.__exportStar(require("./types"), exports);
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InvalidSelectorError = void 0;
|
|
4
4
|
class InvalidSelectorError extends Error {
|
|
5
|
-
constructor() {
|
|
6
|
-
super(
|
|
5
|
+
constructor(selector, message) {
|
|
6
|
+
super(message !== null && message !== void 0 ? message : `Invalid selector: "${selector}"`);
|
|
7
7
|
this.name = 'InvalidSelectorError';
|
|
8
|
+
this.selector = selector;
|
|
8
9
|
}
|
|
9
10
|
}
|
|
10
11
|
exports.InvalidSelectorError = InvalidSelectorError;
|
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
|
+
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
|
-
|
|
10
|
+
readonly matched: false;
|
|
11
11
|
};
|
|
12
12
|
export declare function matchSelector(el: Node, selector: string | RegexSelector | undefined): SelectorMatches;
|
|
13
13
|
export {};
|
package/lib/selector.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { SelectorResult, Specificity } from './types';
|
|
2
2
|
type ExtendedPseudoClass = Readonly<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
|
@@ -51,21 +51,24 @@ class Ruleset {
|
|
|
51
51
|
}
|
|
52
52
|
catch (e) {
|
|
53
53
|
if (e instanceof Error) {
|
|
54
|
-
throw new
|
|
54
|
+
throw new invalid_selector_error_1.InvalidSelectorError(selector);
|
|
55
55
|
}
|
|
56
56
|
throw e;
|
|
57
57
|
}
|
|
58
58
|
return new Ruleset(selectors, extended, 0);
|
|
59
59
|
}
|
|
60
60
|
constructor(selectors, extended, depth) {
|
|
61
|
-
var _a, _b;
|
|
61
|
+
var _a, _b, _c;
|
|
62
62
|
_Ruleset_selectorGroup.set(this, []);
|
|
63
63
|
tslib_1.__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f").push(...selectors.map(selector => new StructuredSelector(selector, depth, extended)));
|
|
64
64
|
const head = tslib_1.__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f")[0];
|
|
65
65
|
this.headCombinator = (_a = head === null || head === void 0 ? void 0 : head.headCombinator) !== null && _a !== void 0 ? _a : null;
|
|
66
66
|
if (this.headCombinator) {
|
|
67
67
|
if (depth <= 0) {
|
|
68
|
-
|
|
68
|
+
if ((_b = tslib_1.__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f")[0]) === null || _b === void 0 ? void 0 : _b.selector) {
|
|
69
|
+
throw new invalid_selector_error_1.InvalidSelectorError((_c = tslib_1.__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f")[0]) === null || _c === void 0 ? void 0 : _c.selector);
|
|
70
|
+
}
|
|
71
|
+
throw new Error('Combinated selector depth is not expected');
|
|
69
72
|
}
|
|
70
73
|
}
|
|
71
74
|
}
|
|
@@ -227,7 +230,7 @@ class SelectorTarget {
|
|
|
227
230
|
const has = [];
|
|
228
231
|
const not = [];
|
|
229
232
|
let ancestor = el.parentElement;
|
|
230
|
-
let specificity;
|
|
233
|
+
let specificity = undefined;
|
|
231
234
|
while (ancestor) {
|
|
232
235
|
const res = target.match(ancestor, scope, count + 1);
|
|
233
236
|
if (!specificity) {
|
|
@@ -365,7 +368,7 @@ class SelectorTarget {
|
|
|
365
368
|
const has = [];
|
|
366
369
|
const not = [];
|
|
367
370
|
let prev = el.previousElementSibling;
|
|
368
|
-
let specificity;
|
|
371
|
+
let specificity = undefined;
|
|
369
372
|
while (prev) {
|
|
370
373
|
const res = target.match(prev, scope, count + 1);
|
|
371
374
|
if (!specificity) {
|
|
@@ -814,7 +817,7 @@ el) {
|
|
|
814
817
|
function getSpecificity(
|
|
815
818
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
816
819
|
results) {
|
|
817
|
-
let specificity;
|
|
820
|
+
let specificity = undefined;
|
|
818
821
|
for (const result of results) {
|
|
819
822
|
if (specificity) {
|
|
820
823
|
const order = (0, compare_specificity_1.compareSpecificity)(specificity, result.specificity);
|
package/lib/types.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
export type Specificity = readonly [number, number, number];
|
|
2
2
|
export type SelectorResult = SelectorMatchedResult | SelectorUnmatchedResult;
|
|
3
3
|
export type SelectorMatchedResult = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
readonly specificity: Specificity;
|
|
11
|
+
readonly matched: false;
|
|
12
|
+
readonly not?: readonly SelectorMatchedResult[];
|
|
13
13
|
};
|
|
14
14
|
export type RegexSelector = RegexSelectorWithoutCombination & {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
readonly combination?: {
|
|
16
|
+
readonly combinator: RegexSelectorCombinator;
|
|
17
|
+
} & RegexSelector;
|
|
18
18
|
};
|
|
19
19
|
export type RegexSelectorCombinator = ' ' | '>' | '+' | '~' | ':has(+)' | ':has(~)';
|
|
20
20
|
export type RegexSelectorWithoutCombination = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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.
|
|
3
|
+
"version": "3.10.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>",
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
"clean": "tsc --build --clean"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@markuplint/ml-spec": "3.
|
|
24
|
-
"@types/debug": "^4.1.
|
|
23
|
+
"@markuplint/ml-spec": "3.10.0",
|
|
24
|
+
"@types/debug": "^4.1.8",
|
|
25
25
|
"debug": "^4.3.4",
|
|
26
|
-
"postcss-selector-parser": "^6.0.
|
|
27
|
-
"tslib": "^2.
|
|
28
|
-
"type-fest": "^3.
|
|
26
|
+
"postcss-selector-parser": "^6.0.13",
|
|
27
|
+
"tslib": "^2.5.3",
|
|
28
|
+
"type-fest": "^3.11.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/jsdom": "21.1.1",
|
|
32
|
-
"jsdom": "
|
|
32
|
+
"jsdom": "22.0.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "9547b8dca20736a93e4d01af2d61bee314ba5718"
|
|
35
35
|
}
|