@markuplint/selector 3.0.0-dev.25 → 3.0.0-dev.300
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 +1 -1
- package/lib/compare-specificity.js +1 -5
- package/lib/create-selector.d.ts +2 -2
- package/lib/create-selector.js +12 -14
- package/lib/debug.js +9 -14
- package/lib/extended-selector/aria-pseudo-class.d.ts +1 -1
- package/lib/extended-selector/aria-pseudo-class.js +11 -10
- package/lib/extended-selector/aria-role-pseudo-class.d.ts +1 -1
- package/lib/extended-selector/aria-role-pseudo-class.js +12 -12
- package/lib/extended-selector/content-model-pseudo-class.d.ts +1 -1
- package/lib/extended-selector/content-model-pseudo-class.js +9 -11
- package/lib/index.d.ts +5 -4
- package/lib/index.js +5 -11
- package/lib/invalid-selector-error.d.ts +2 -0
- package/lib/invalid-selector-error.js +4 -7
- package/lib/is.js +9 -9
- package/lib/match-selector.d.ts +6 -6
- package/lib/match-selector.js +33 -27
- package/lib/regex-selector-matches.js +2 -6
- package/lib/selector.d.ts +2 -2
- package/lib/selector.js +133 -87
- package/lib/types.d.ts +13 -13
- package/lib/types.js +1 -2
- package/package.json +18 -9
- package/tsconfig.test.json +0 -3
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Specificity } from './types';
|
|
1
|
+
import type { Specificity } from './types.js';
|
|
2
2
|
export declare function compareSpecificity(a: Specificity, b: Specificity): 0 | 1 | -1;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compareSpecificity = void 0;
|
|
4
|
-
function compareSpecificity(a, b) {
|
|
1
|
+
export function compareSpecificity(a, b) {
|
|
5
2
|
if (a[0] < b[0]) {
|
|
6
3
|
return -1;
|
|
7
4
|
}
|
|
@@ -22,4 +19,3 @@ function compareSpecificity(a, b) {
|
|
|
22
19
|
}
|
|
23
20
|
return 0;
|
|
24
21
|
}
|
|
25
|
-
exports.compareSpecificity = compareSpecificity;
|
package/lib/create-selector.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { MLMLSpec } from '@markuplint/ml-spec';
|
|
2
|
-
import { Selector } from './selector';
|
|
3
|
-
export declare function createSelector(selector: string, specs
|
|
2
|
+
import { Selector } from './selector.js';
|
|
3
|
+
export declare function createSelector(selector: string, specs?: MLMLSpec): Selector;
|
package/lib/create-selector.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const aria_role_pseudo_class_1 = require("./extended-selector/aria-role-pseudo-class");
|
|
6
|
-
const content_model_pseudo_class_1 = require("./extended-selector/content-model-pseudo-class");
|
|
7
|
-
const selector_1 = require("./selector");
|
|
1
|
+
import { ariaPseudoClass } from './extended-selector/aria-pseudo-class.js';
|
|
2
|
+
import { ariaRolePseudoClass } from './extended-selector/aria-role-pseudo-class.js';
|
|
3
|
+
import { contentModelPseudoClass } from './extended-selector/content-model-pseudo-class.js';
|
|
4
|
+
import { Selector } from './selector.js';
|
|
8
5
|
const caches = new Map();
|
|
9
|
-
function createSelector(selector, specs) {
|
|
6
|
+
export function createSelector(selector, specs) {
|
|
10
7
|
let instance = caches.get(selector);
|
|
11
8
|
if (instance) {
|
|
12
9
|
return instance;
|
|
13
10
|
}
|
|
14
|
-
instance = new
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
instance = new Selector(selector, specs
|
|
12
|
+
? {
|
|
13
|
+
model: contentModelPseudoClass(specs),
|
|
14
|
+
aria: ariaPseudoClass(),
|
|
15
|
+
role: ariaRolePseudoClass(specs),
|
|
16
|
+
}
|
|
17
|
+
: undefined);
|
|
19
18
|
caches.set(selector, instance);
|
|
20
19
|
return instance;
|
|
21
20
|
}
|
|
22
|
-
exports.createSelector = createSelector;
|
package/lib/debug.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.enableDebug = exports.log = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
1
|
+
import debug from 'debug';
|
|
6
2
|
const CLI_NS = 'markuplint-cli';
|
|
7
|
-
|
|
8
|
-
function enableDebug() {
|
|
9
|
-
if (!
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (!
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
export const log = debug('selector');
|
|
4
|
+
export function enableDebug() {
|
|
5
|
+
if (!log.enabled) {
|
|
6
|
+
debug.enable(`${log.namespace}*`);
|
|
7
|
+
log(`Debug enable: ${log.namespace}`);
|
|
8
|
+
if (!debug.enabled(CLI_NS)) {
|
|
9
|
+
debug.enable(`${log.namespace}*,${CLI_NS}*`);
|
|
10
|
+
log(`Debug enable: ${log.namespace}, ${CLI_NS}`);
|
|
15
11
|
}
|
|
16
12
|
}
|
|
17
13
|
}
|
|
18
|
-
exports.enableDebug = enableDebug;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ariaPseudoClass = void 0;
|
|
4
|
-
const ml_spec_1 = require("@markuplint/ml-spec");
|
|
1
|
+
import { validateAriaVersion, ARIA_RECOMMENDED_VERSION, getAccname } from '@markuplint/ml-spec';
|
|
5
2
|
/**
|
|
6
3
|
* Version Syntax is not support yet.
|
|
7
4
|
*/
|
|
8
|
-
function ariaPseudoClass() {
|
|
9
|
-
return (content) => (
|
|
5
|
+
export function ariaPseudoClass() {
|
|
6
|
+
return (content) => (
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
8
|
+
el) => {
|
|
10
9
|
const aria = ariaPseudoClassParser(content);
|
|
11
|
-
const name =
|
|
10
|
+
const name = getAccname(el);
|
|
12
11
|
switch (aria.type) {
|
|
13
12
|
case 'hasName': {
|
|
14
13
|
if (name) {
|
|
@@ -41,11 +40,13 @@ function ariaPseudoClass() {
|
|
|
41
40
|
}
|
|
42
41
|
};
|
|
43
42
|
}
|
|
44
|
-
exports.ariaPseudoClass = ariaPseudoClass;
|
|
45
43
|
function ariaPseudoClassParser(syntax) {
|
|
46
44
|
const [_query, _version] = syntax.split('|');
|
|
47
|
-
const query = _query
|
|
48
|
-
const version = _version
|
|
45
|
+
const query = _query?.replace(/\s+/g, '').toLowerCase();
|
|
46
|
+
const version = _version ?? ARIA_RECOMMENDED_VERSION;
|
|
47
|
+
if (!validateAriaVersion(version)) {
|
|
48
|
+
throw new SyntaxError(`Unsupported ARIA version: ${version}`);
|
|
49
|
+
}
|
|
49
50
|
switch (query) {
|
|
50
51
|
case 'hasname': {
|
|
51
52
|
return {
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return (content) => (el) => {
|
|
7
|
-
var _a, _b;
|
|
1
|
+
import { validateAriaVersion, ARIA_RECOMMENDED_VERSION, getComputedRole } from '@markuplint/ml-spec';
|
|
2
|
+
export function ariaRolePseudoClass(specs) {
|
|
3
|
+
return (content) => (
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
5
|
+
el) => {
|
|
8
6
|
const aria = ariaPseudoClassParser(content);
|
|
9
|
-
const computed =
|
|
10
|
-
if (
|
|
7
|
+
const computed = getComputedRole(specs, el, aria.version ?? ARIA_RECOMMENDED_VERSION);
|
|
8
|
+
if (computed.role?.name === aria.role) {
|
|
11
9
|
return {
|
|
12
10
|
specificity: [0, 1, 0],
|
|
13
11
|
matched: true,
|
|
@@ -21,12 +19,14 @@ function ariaRolePseudoClass(specs) {
|
|
|
21
19
|
};
|
|
22
20
|
};
|
|
23
21
|
}
|
|
24
|
-
exports.ariaRolePseudoClass = ariaRolePseudoClass;
|
|
25
22
|
function ariaPseudoClassParser(syntax) {
|
|
26
23
|
const [roleName, _version] = syntax.split('|');
|
|
27
|
-
const version = _version
|
|
24
|
+
const version = _version ?? ARIA_RECOMMENDED_VERSION;
|
|
25
|
+
if (!validateAriaVersion(version)) {
|
|
26
|
+
throw new SyntaxError(`Unsupported ARIA version: ${version}`);
|
|
27
|
+
}
|
|
28
28
|
return {
|
|
29
|
-
role: roleName.trim().toLowerCase(),
|
|
29
|
+
role: roleName?.trim().toLowerCase() ?? syntax.trim().toLowerCase(),
|
|
30
30
|
version,
|
|
31
31
|
};
|
|
32
32
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { SelectorResult } from '../types';
|
|
1
|
+
import type { SelectorResult } from '../types.js';
|
|
2
2
|
import type { MLMLSpec } from '@markuplint/ml-spec';
|
|
3
3
|
export declare function contentModelPseudoClass(specs: MLMLSpec): (category: string) => (el: Element) => SelectorResult;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return (category) => (el) => {
|
|
1
|
+
import { contentModelCategoryToTagNames } from '@markuplint/ml-spec';
|
|
2
|
+
import { createSelector } from '../create-selector.js';
|
|
3
|
+
export function contentModelPseudoClass(specs) {
|
|
4
|
+
return (category) => (
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
6
|
+
el) => {
|
|
8
7
|
category = category.trim().toLowerCase();
|
|
9
|
-
const selectors =
|
|
8
|
+
const selectors = contentModelCategoryToTagNames(`#${category}`, specs.def);
|
|
10
9
|
const matched = selectors
|
|
11
10
|
.map(selector => {
|
|
12
11
|
if (selector === '#custom') {
|
|
@@ -36,11 +35,11 @@ function contentModelPseudoClass(specs) {
|
|
|
36
35
|
},
|
|
37
36
|
];
|
|
38
37
|
}
|
|
39
|
-
return
|
|
38
|
+
return createSelector(selector, specs).search(el);
|
|
40
39
|
})
|
|
41
40
|
.flat()
|
|
42
41
|
.filter((m) => m.matched);
|
|
43
|
-
if (matched.length) {
|
|
42
|
+
if (matched.length > 0) {
|
|
44
43
|
return {
|
|
45
44
|
specificity: [0, 1, 0],
|
|
46
45
|
matched: true,
|
|
@@ -54,4 +53,3 @@ function contentModelPseudoClass(specs) {
|
|
|
54
53
|
};
|
|
55
54
|
};
|
|
56
55
|
}
|
|
57
|
-
exports.contentModelPseudoClass = contentModelPseudoClass;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { compareSpecificity } from './compare-specificity';
|
|
2
|
-
export { matchSelector } from './match-selector';
|
|
3
|
-
export { createSelector } from './create-selector';
|
|
4
|
-
export
|
|
1
|
+
export { compareSpecificity } from './compare-specificity.js';
|
|
2
|
+
export { matchSelector } from './match-selector.js';
|
|
3
|
+
export { createSelector } from './create-selector.js';
|
|
4
|
+
export { InvalidSelectorError } from './invalid-selector-error.js';
|
|
5
|
+
export * from './types.js';
|
package/lib/index.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Object.defineProperty(exports, "compareSpecificity", { enumerable: true, get: function () { return compare_specificity_1.compareSpecificity; } });
|
|
7
|
-
var match_selector_1 = require("./match-selector");
|
|
8
|
-
Object.defineProperty(exports, "matchSelector", { enumerable: true, get: function () { return match_selector_1.matchSelector; } });
|
|
9
|
-
var create_selector_1 = require("./create-selector");
|
|
10
|
-
Object.defineProperty(exports, "createSelector", { enumerable: true, get: function () { return create_selector_1.createSelector; } });
|
|
11
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
1
|
+
export { compareSpecificity } from './compare-specificity.js';
|
|
2
|
+
export { matchSelector } from './match-selector.js';
|
|
3
|
+
export { createSelector } from './create-selector.js';
|
|
4
|
+
export { InvalidSelectorError } from './invalid-selector-error.js';
|
|
5
|
+
export * from './types.js';
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class InvalidSelectorError extends Error {
|
|
5
|
-
constructor() {
|
|
6
|
-
super(...arguments);
|
|
1
|
+
export class InvalidSelectorError extends Error {
|
|
2
|
+
constructor(selector, message) {
|
|
3
|
+
super(message ?? `Invalid selector: "${selector}"`);
|
|
7
4
|
this.name = 'InvalidSelectorError';
|
|
5
|
+
this.selector = selector;
|
|
8
6
|
}
|
|
9
7
|
}
|
|
10
|
-
exports.InvalidSelectorError = InvalidSelectorError;
|
package/lib/is.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function isElement(node) {
|
|
1
|
+
export function isElement(
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
3
|
+
node) {
|
|
5
4
|
return node.nodeType === node.ELEMENT_NODE;
|
|
6
5
|
}
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export function isNonDocumentTypeChildNode(
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
8
|
+
node) {
|
|
9
9
|
return 'previousElementSibling' in node && 'nextElementSibling' in node;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
export function isPureHTMLElement(
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
13
|
+
el) {
|
|
13
14
|
return el.localName !== el.nodeName;
|
|
14
15
|
}
|
|
15
|
-
exports.isPureHTMLElement = isPureHTMLElement;
|
package/lib/match-selector.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { Specificity, RegexSelector } from './types';
|
|
1
|
+
import type { Specificity, RegexSelector } from './types.js';
|
|
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 {};
|
package/lib/match-selector.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var _SelectorTarget_combinedFrom, _SelectorTarget_selector;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
+
import { isElement, isNonDocumentTypeChildNode, isPureHTMLElement } from './is.js';
|
|
4
|
+
import { regexSelectorMatches } from './regex-selector-matches.js';
|
|
5
|
+
import { Selector } from './selector.js';
|
|
6
|
+
export function matchSelector(
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
8
|
+
el, selector) {
|
|
9
|
+
if (selector == null || selector === '') {
|
|
11
10
|
return {
|
|
12
11
|
matched: false,
|
|
13
12
|
};
|
|
14
13
|
}
|
|
15
14
|
if (typeof selector === 'string') {
|
|
16
|
-
const sel = new
|
|
15
|
+
const sel = new Selector(selector);
|
|
17
16
|
const specificity = sel.match(el);
|
|
18
|
-
if (specificity) {
|
|
17
|
+
if (specificity !== false) {
|
|
19
18
|
return {
|
|
20
19
|
matched: true,
|
|
21
20
|
selector,
|
|
@@ -28,8 +27,9 @@ function matchSelector(el, selector) {
|
|
|
28
27
|
}
|
|
29
28
|
return regexSelect(el, selector);
|
|
30
29
|
}
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
function regexSelect(
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
32
|
+
el, selector) {
|
|
33
33
|
let edge = new SelectorTarget(selector);
|
|
34
34
|
let edgeSelector = selector.combination;
|
|
35
35
|
while (edgeSelector) {
|
|
@@ -44,23 +44,25 @@ class SelectorTarget {
|
|
|
44
44
|
constructor(selector) {
|
|
45
45
|
_SelectorTarget_combinedFrom.set(this, null);
|
|
46
46
|
_SelectorTarget_selector.set(this, void 0);
|
|
47
|
-
|
|
47
|
+
__classPrivateFieldSet(this, _SelectorTarget_selector, selector, "f");
|
|
48
48
|
}
|
|
49
49
|
from(target, combinator) {
|
|
50
|
-
|
|
50
|
+
__classPrivateFieldSet(this, _SelectorTarget_combinedFrom, { target, combinator }, "f");
|
|
51
51
|
}
|
|
52
|
-
match(
|
|
52
|
+
match(
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
54
|
+
el) {
|
|
53
55
|
const unitCheck = this._matchWithoutCombineChecking(el);
|
|
54
56
|
if (!unitCheck.matched) {
|
|
55
57
|
return unitCheck;
|
|
56
58
|
}
|
|
57
|
-
if (!
|
|
59
|
+
if (!__classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f")) {
|
|
58
60
|
return unitCheck;
|
|
59
61
|
}
|
|
60
|
-
if (!
|
|
62
|
+
if (!isNonDocumentTypeChildNode(el)) {
|
|
61
63
|
return unitCheck;
|
|
62
64
|
}
|
|
63
|
-
const { target, combinator } =
|
|
65
|
+
const { target, combinator } = __classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f");
|
|
64
66
|
switch (combinator) {
|
|
65
67
|
// Descendant combinator
|
|
66
68
|
case ' ': {
|
|
@@ -135,17 +137,21 @@ class SelectorTarget {
|
|
|
135
137
|
return { matched: false };
|
|
136
138
|
}
|
|
137
139
|
default: {
|
|
138
|
-
throw new Error(`Unsupported ${
|
|
140
|
+
throw new Error(`Unsupported ${__classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f").combinator} combinator in selector`);
|
|
139
141
|
}
|
|
140
142
|
}
|
|
141
143
|
}
|
|
142
|
-
_matchWithoutCombineChecking(
|
|
143
|
-
|
|
144
|
+
_matchWithoutCombineChecking(
|
|
145
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
146
|
+
el) {
|
|
147
|
+
return uncombinedRegexSelect(el, __classPrivateFieldGet(this, _SelectorTarget_selector, "f"));
|
|
144
148
|
}
|
|
145
149
|
}
|
|
146
150
|
_SelectorTarget_combinedFrom = new WeakMap(), _SelectorTarget_selector = new WeakMap();
|
|
147
|
-
function uncombinedRegexSelect(
|
|
148
|
-
|
|
151
|
+
function uncombinedRegexSelect(
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
153
|
+
el, selector) {
|
|
154
|
+
if (!isElement(el)) {
|
|
149
155
|
return {
|
|
150
156
|
matched: false,
|
|
151
157
|
};
|
|
@@ -156,7 +162,7 @@ function uncombinedRegexSelect(el, selector) {
|
|
|
156
162
|
const specificity = [0, 0, 0];
|
|
157
163
|
const specifiedAttr = new Map();
|
|
158
164
|
if (selector.nodeName) {
|
|
159
|
-
const matchedNodeName =
|
|
165
|
+
const matchedNodeName = regexSelectorMatches(selector.nodeName, el.localName, isPureHTMLElement(el));
|
|
160
166
|
if (matchedNodeName) {
|
|
161
167
|
delete matchedNodeName.$0;
|
|
162
168
|
}
|
|
@@ -174,7 +180,7 @@ function uncombinedRegexSelect(el, selector) {
|
|
|
174
180
|
const selectorAttrName = selector.attrName;
|
|
175
181
|
const matchedAttrNameList = Array.from(el.attributes).map(attr => {
|
|
176
182
|
const attrName = attr.name;
|
|
177
|
-
const matchedAttrName =
|
|
183
|
+
const matchedAttrName = regexSelectorMatches(selectorAttrName, attrName, isPureHTMLElement(el));
|
|
178
184
|
if (matchedAttrName) {
|
|
179
185
|
delete matchedAttrName.$0;
|
|
180
186
|
data = {
|
|
@@ -194,7 +200,7 @@ function uncombinedRegexSelect(el, selector) {
|
|
|
194
200
|
const matchedAttrValueList = Array.from(el.attributes).map(attr => {
|
|
195
201
|
const attrName = attr.name;
|
|
196
202
|
const attrValue = attr.value;
|
|
197
|
-
const matchedAttrValue =
|
|
203
|
+
const matchedAttrValue = regexSelectorMatches(selectorAttrValue, attrValue, isPureHTMLElement(el));
|
|
198
204
|
if (matchedAttrValue) {
|
|
199
205
|
delete matchedAttrValue.$0;
|
|
200
206
|
data = {
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.regexSelectorMatches = void 0;
|
|
4
|
-
function regexSelectorMatches(reg, raw, ignoreCase) {
|
|
1
|
+
export function regexSelectorMatches(reg, raw, ignoreCase) {
|
|
5
2
|
const res = {};
|
|
6
3
|
const pattern = toRegexp(reg);
|
|
7
4
|
const regex = new RegExp(pattern instanceof RegExp ? pattern : `^${pattern.trim()}$`, ignoreCase ? 'i' : undefined);
|
|
@@ -15,10 +12,9 @@ function regexSelectorMatches(reg, raw, ignoreCase) {
|
|
|
15
12
|
...matched.groups,
|
|
16
13
|
};
|
|
17
14
|
}
|
|
18
|
-
exports.regexSelectorMatches = regexSelectorMatches;
|
|
19
15
|
function toRegexp(pattern) {
|
|
20
16
|
const matched = pattern.match(/^\/(.+)\/([ig]*)$/i);
|
|
21
|
-
if (matched) {
|
|
17
|
+
if (matched && matched[1]) {
|
|
22
18
|
return new RegExp(matched[1], matched[2]);
|
|
23
19
|
}
|
|
24
20
|
return pattern;
|
package/lib/selector.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SelectorResult, Specificity } from './types';
|
|
2
|
-
type ExtendedPseudoClass = Record<string, (content: string) => (el: Element) => SelectorResult
|
|
1
|
+
import type { SelectorResult, Specificity } from './types.js';
|
|
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);
|