@asamuzakjp/dom-selector 0.21.0 → 0.21.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/package.json +1 -1
- package/src/js/matcher.js +43 -4
- package/types/js/matcher.d.ts +2 -2
package/package.json
CHANGED
package/src/js/matcher.js
CHANGED
|
@@ -28,6 +28,7 @@ const TARGET_SELF = 'self';
|
|
|
28
28
|
const DIR_VALUE = /^(?:auto|ltr|rtl)$/;
|
|
29
29
|
const HTML_FORM_INPUT = /^(?:(?:inpu|selec)t|textarea)$/;
|
|
30
30
|
const HTML_FORM_PARTS = /^(?:button|fieldset|opt(?:group|ion))$/;
|
|
31
|
+
const HTML_FORM_VALIDITY = /^(?:(?:(?:in|out)pu|selec)t|button|form|textarea)$/;
|
|
31
32
|
const HTML_INTERACT = /^d(?:etails|ialog)$/;
|
|
32
33
|
const INPUT_RANGE = /(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/;
|
|
33
34
|
const INPUT_TEXT = /^(?:(?:emai|te|ur)l|password|search|text)$/;
|
|
@@ -1122,20 +1123,58 @@ export class Matcher {
|
|
|
1122
1123
|
break;
|
|
1123
1124
|
}
|
|
1124
1125
|
case 'valid': {
|
|
1125
|
-
if (
|
|
1126
|
-
/^(?:f(?:ieldset|orm)|button)$/.test(localName)) {
|
|
1126
|
+
if (HTML_FORM_VALIDITY.test(localName)) {
|
|
1127
1127
|
if (node.checkValidity()) {
|
|
1128
1128
|
matched.add(node);
|
|
1129
1129
|
}
|
|
1130
|
+
} else if (/^fieldset$/.test(localName)) {
|
|
1131
|
+
const { document } = this.#root;
|
|
1132
|
+
const iterator = document.createNodeIterator(node, SHOW_ELEMENT);
|
|
1133
|
+
let refNode = iterator.nextNode();
|
|
1134
|
+
if (refNode === node) {
|
|
1135
|
+
refNode = iterator.nextNode();
|
|
1136
|
+
}
|
|
1137
|
+
let bool;
|
|
1138
|
+
while (refNode) {
|
|
1139
|
+
if (HTML_FORM_VALIDITY.test(refNode.localName)) {
|
|
1140
|
+
bool = refNode.checkValidity();
|
|
1141
|
+
if (!bool) {
|
|
1142
|
+
break;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
refNode = iterator.nextNode();
|
|
1146
|
+
}
|
|
1147
|
+
if (bool) {
|
|
1148
|
+
matched.add(node);
|
|
1149
|
+
}
|
|
1130
1150
|
}
|
|
1131
1151
|
break;
|
|
1132
1152
|
}
|
|
1133
1153
|
case 'invalid': {
|
|
1134
|
-
if (
|
|
1135
|
-
/^(?:f(?:ieldset|orm)|button)$/.test(localName)) {
|
|
1154
|
+
if (HTML_FORM_VALIDITY.test(localName)) {
|
|
1136
1155
|
if (!node.checkValidity()) {
|
|
1137
1156
|
matched.add(node);
|
|
1138
1157
|
}
|
|
1158
|
+
} else if (/^fieldset$/.test(localName)) {
|
|
1159
|
+
const { document } = this.#root;
|
|
1160
|
+
const iterator = document.createNodeIterator(node, SHOW_ELEMENT);
|
|
1161
|
+
let refNode = iterator.nextNode();
|
|
1162
|
+
if (refNode === node) {
|
|
1163
|
+
refNode = iterator.nextNode();
|
|
1164
|
+
}
|
|
1165
|
+
let bool;
|
|
1166
|
+
while (refNode) {
|
|
1167
|
+
if (HTML_FORM_VALIDITY.test(refNode.localName)) {
|
|
1168
|
+
bool = refNode.checkValidity();
|
|
1169
|
+
if (!bool) {
|
|
1170
|
+
break;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
refNode = iterator.nextNode();
|
|
1174
|
+
}
|
|
1175
|
+
if (!bool) {
|
|
1176
|
+
matched.add(node);
|
|
1177
|
+
}
|
|
1139
1178
|
}
|
|
1140
1179
|
break;
|
|
1141
1180
|
}
|
package/types/js/matcher.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export class Matcher {
|
|
|
7
7
|
_getRoot(node?: object): object;
|
|
8
8
|
_sortLeaves(leaves: Array<object>): Array<object>;
|
|
9
9
|
_prepare(selector?: string): Array<Array<object | undefined>>;
|
|
10
|
+
_throwOnPseudoElementSelector(astName: object): void;
|
|
10
11
|
_collectNthChild(anb: {
|
|
11
12
|
a: number;
|
|
12
13
|
b: number;
|
|
@@ -27,11 +28,10 @@ export class Matcher {
|
|
|
27
28
|
_matchAttributeSelector(ast: object, node: object): object | null;
|
|
28
29
|
_matchClassSelector(ast: object, node: object): object | null;
|
|
29
30
|
_matchIDSelector(ast: object, node: object): object | null;
|
|
30
|
-
_matchPseudoElementSelector(ast: object, node: object): void;
|
|
31
31
|
_matchTypeSelector(ast: object, node: object): object | null;
|
|
32
32
|
_matchSelector(ast: object, node: object): object;
|
|
33
33
|
_matchLeaves(leaves: Array<object>, node: object): boolean;
|
|
34
|
-
_findDescendantNodes(leaves: Array<object>,
|
|
34
|
+
_findDescendantNodes(leaves: Array<object>, baseNode: object): object;
|
|
35
35
|
_matchCombinator(twig: object, node: object, opt?: {
|
|
36
36
|
find?: string;
|
|
37
37
|
}): object;
|