happy-dom 9.9.2 → 9.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.
Potentially problematic release.
This version of happy-dom might be problematic. Click here for more details.
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementStyle.js +1 -1
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementStyle.js.map +1 -1
- package/lib/nodes/element/Element.d.ts.map +1 -1
- package/lib/nodes/element/Element.js +2 -15
- package/lib/nodes/element/Element.js.map +1 -1
- package/lib/nodes/node/Node.d.ts +0 -8
- package/lib/nodes/node/Node.d.ts.map +1 -1
- package/lib/nodes/node/Node.js +1 -23
- package/lib/nodes/node/Node.js.map +1 -1
- package/lib/query-selector/ISelectorAttribute.d.ts +6 -0
- package/lib/query-selector/ISelectorAttribute.d.ts.map +1 -0
- package/lib/query-selector/ISelectorAttribute.js +3 -0
- package/lib/query-selector/ISelectorAttribute.js.map +1 -0
- package/lib/query-selector/ISelectorMatch.d.ts +4 -0
- package/lib/query-selector/ISelectorMatch.d.ts.map +1 -0
- package/lib/query-selector/ISelectorMatch.js +3 -0
- package/lib/query-selector/ISelectorMatch.js.map +1 -0
- package/lib/query-selector/QuerySelector.d.ts +21 -31
- package/lib/query-selector/QuerySelector.d.ts.map +1 -1
- package/lib/query-selector/QuerySelector.js +123 -131
- package/lib/query-selector/QuerySelector.js.map +1 -1
- package/lib/query-selector/SelectorCombinatorEnum.d.ts +7 -0
- package/lib/query-selector/SelectorCombinatorEnum.d.ts.map +1 -0
- package/lib/query-selector/SelectorCombinatorEnum.js +10 -0
- package/lib/query-selector/SelectorCombinatorEnum.js.map +1 -0
- package/lib/query-selector/SelectorItem.d.ts +41 -56
- package/lib/query-selector/SelectorItem.d.ts.map +1 -1
- package/lib/query-selector/SelectorItem.js +194 -220
- package/lib/query-selector/SelectorItem.js.map +1 -1
- package/lib/query-selector/SelectorParser.d.ts +21 -0
- package/lib/query-selector/SelectorParser.d.ts.map +1 -0
- package/lib/query-selector/SelectorParser.js +154 -0
- package/lib/query-selector/SelectorParser.js.map +1 -0
- package/package.json +1 -1
- package/src/css/declaration/utilities/CSSStyleDeclarationElementStyle.ts +2 -2
- package/src/nodes/element/Element.ts +3 -17
- package/src/nodes/node/Node.ts +1 -25
- package/src/query-selector/ISelectorAttribute.ts +5 -0
- package/src/query-selector/ISelectorMatch.ts +3 -0
- package/src/query-selector/QuerySelector.ts +187 -170
- package/src/query-selector/SelectorCombinatorEnum.ts +7 -0
- package/src/query-selector/SelectorItem.ts +238 -264
- package/src/query-selector/SelectorParser.ts +148 -0
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
const Node_1 = __importDefault(require("../nodes/node/Node"));
|
7
|
-
const SelectorItem_1 = __importDefault(require("./SelectorItem"));
|
8
6
|
const NodeList_1 = __importDefault(require("../nodes/node/NodeList"));
|
9
|
-
const
|
7
|
+
const NodeTypeEnum_1 = __importDefault(require("../nodes/node/NodeTypeEnum"));
|
8
|
+
const SelectorCombinatorEnum_1 = __importDefault(require("./SelectorCombinatorEnum"));
|
9
|
+
const SelectorParser_1 = __importDefault(require("./SelectorParser"));
|
10
10
|
/**
|
11
11
|
* Utility for query selection in an HTML element.
|
12
12
|
*
|
@@ -21,21 +21,24 @@ class QuerySelector {
|
|
21
21
|
* @returns HTML elements.
|
22
22
|
*/
|
23
23
|
static querySelectorAll(node, selector) {
|
24
|
-
const
|
24
|
+
const nodeList = new NodeList_1.default();
|
25
|
+
const allMatches = {};
|
25
26
|
if (selector === '') {
|
26
27
|
throw new Error("Failed to execute 'querySelectorAll' on 'Element': The provided selector is empty.");
|
27
28
|
}
|
28
29
|
if (selector === null || selector === undefined) {
|
29
|
-
return
|
30
|
+
return nodeList;
|
30
31
|
}
|
31
|
-
for (const
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
for (const items of SelectorParser_1.default.getSelectorGroups(selector)) {
|
33
|
+
const matches = node.nodeType === NodeTypeEnum_1.default.elementNode
|
34
|
+
? this.findAll(node, [node], items)
|
35
|
+
: this.findAll(null, node.children, items);
|
36
|
+
Object.assign(allMatches, matches);
|
37
|
+
}
|
38
|
+
for (const key of Object.keys(allMatches).sort()) {
|
39
|
+
nodeList.push(allMatches[key]);
|
37
40
|
}
|
38
|
-
return
|
41
|
+
return nodeList;
|
39
42
|
}
|
40
43
|
/**
|
41
44
|
* Finds an element based on a query selector.
|
@@ -51,8 +54,10 @@ class QuerySelector {
|
|
51
54
|
if (selector === null || selector === undefined) {
|
52
55
|
return null;
|
53
56
|
}
|
54
|
-
for (const
|
55
|
-
const match =
|
57
|
+
for (const items of SelectorParser_1.default.getSelectorGroups(selector)) {
|
58
|
+
const match = node.nodeType === NodeTypeEnum_1.default.elementNode
|
59
|
+
? this.findFirst(node, [node], items)
|
60
|
+
: this.findFirst(null, node.children, items);
|
56
61
|
if (match) {
|
57
62
|
return match;
|
58
63
|
}
|
@@ -60,85 +65,104 @@ class QuerySelector {
|
|
60
65
|
return null;
|
61
66
|
}
|
62
67
|
/**
|
63
|
-
* Checks if
|
68
|
+
* Checks if an element matches a selector and returns priority weight.
|
64
69
|
*
|
65
|
-
* @param
|
66
|
-
* @param selector Selector.
|
70
|
+
* @param element Element to match.
|
71
|
+
* @param selector Selector to match with.
|
67
72
|
* @returns Result.
|
68
73
|
*/
|
69
|
-
static match(
|
70
|
-
for (const
|
71
|
-
const result = this.
|
72
|
-
if (result
|
74
|
+
static match(element, selector) {
|
75
|
+
for (const items of SelectorParser_1.default.getSelectorGroups(selector)) {
|
76
|
+
const result = this.matchSelector(element, element, items.reverse());
|
77
|
+
if (result) {
|
73
78
|
return result;
|
74
79
|
}
|
75
80
|
}
|
76
|
-
return
|
81
|
+
return null;
|
77
82
|
}
|
78
83
|
/**
|
79
84
|
* Checks if a node matches a selector.
|
80
85
|
*
|
81
|
-
* @param
|
82
|
-
* @param
|
83
|
-
* @param
|
86
|
+
* @param targetElement Target element.
|
87
|
+
* @param currentElement Current element.
|
88
|
+
* @param selectorItems Selector items.
|
84
89
|
* @param [priorityWeight] Priority weight.
|
85
90
|
* @returns Result.
|
86
91
|
*/
|
87
|
-
static
|
88
|
-
const
|
89
|
-
|
90
|
-
|
91
|
-
if (
|
92
|
-
return {
|
92
|
+
static matchSelector(targetElement, currentElement, selectorItems, priorityWeight = 0) {
|
93
|
+
const selectorItem = selectorItems[0];
|
94
|
+
const result = selectorItem.match(currentElement);
|
95
|
+
if (result) {
|
96
|
+
if (selectorItems.length === 1) {
|
97
|
+
return {
|
98
|
+
priorityWeight: priorityWeight + result.priorityWeight
|
99
|
+
};
|
100
|
+
}
|
101
|
+
switch (selectorItem.combinator) {
|
102
|
+
case SelectorCombinatorEnum_1.default.adjacentSibling:
|
103
|
+
if (currentElement.previousElementSibling) {
|
104
|
+
const match = this.matchSelector(targetElement, currentElement.previousElementSibling, selectorItems.slice(1), priorityWeight + result.priorityWeight);
|
105
|
+
if (match) {
|
106
|
+
return match;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
break;
|
110
|
+
case SelectorCombinatorEnum_1.default.child:
|
111
|
+
case SelectorCombinatorEnum_1.default.descendant:
|
112
|
+
if (currentElement.parentElement) {
|
113
|
+
const match = this.matchSelector(targetElement, currentElement.parentElement, selectorItems.slice(1), priorityWeight + result.priorityWeight);
|
114
|
+
if (match) {
|
115
|
+
return match;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
break;
|
93
119
|
}
|
94
120
|
}
|
95
|
-
if (
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
const result = selector.match(currentNode);
|
100
|
-
if (result.matches && selectorParts.length === 1) {
|
101
|
-
return {
|
102
|
-
priorityWeight: priorityWeight + result.priorityWeight,
|
103
|
-
matches: true
|
104
|
-
};
|
105
|
-
}
|
106
|
-
if (!currentNode.parentElement || (targetNode === currentNode && !result.matches)) {
|
107
|
-
return { priorityWeight: 0, matches: false };
|
121
|
+
if (selectorItem.combinator === SelectorCombinatorEnum_1.default.descendant &&
|
122
|
+
targetElement !== currentElement &&
|
123
|
+
currentElement.parentElement) {
|
124
|
+
return this.matchSelector(targetElement, currentElement.parentElement, selectorItems, priorityWeight);
|
108
125
|
}
|
109
|
-
return
|
126
|
+
return null;
|
110
127
|
}
|
111
128
|
/**
|
112
129
|
* Finds elements based on a query selector for a part of a list of selectors separated with comma.
|
113
130
|
*
|
114
|
-
* @param
|
115
|
-
* @param
|
116
|
-
* @param
|
117
|
-
* @param [
|
118
|
-
* @returns
|
131
|
+
* @param rootElement Root element.
|
132
|
+
* @param children Child elements.
|
133
|
+
* @param selectorItems Selector items.
|
134
|
+
* @param [documentPosition] Document position of the element.
|
135
|
+
* @returns Document position and element map.
|
119
136
|
*/
|
120
|
-
static findAll(
|
121
|
-
const
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
if (rootNode !== node) {
|
132
|
-
matched.push(node);
|
133
|
-
}
|
137
|
+
static findAll(rootElement, children, selectorItems, documentPosition) {
|
138
|
+
const selectorItem = selectorItems[0];
|
139
|
+
const nextSelectorItem = selectorItems[1];
|
140
|
+
const matched = {};
|
141
|
+
for (let i = 0, max = children.length; i < max; i++) {
|
142
|
+
const child = children[i];
|
143
|
+
const position = (documentPosition ? documentPosition + '>' : '') + i;
|
144
|
+
if (selectorItem.match(child)) {
|
145
|
+
if (!nextSelectorItem) {
|
146
|
+
if (rootElement !== child) {
|
147
|
+
matched[position] = child;
|
134
148
|
}
|
135
|
-
|
136
|
-
|
149
|
+
}
|
150
|
+
else {
|
151
|
+
switch (nextSelectorItem.combinator) {
|
152
|
+
case SelectorCombinatorEnum_1.default.adjacentSibling:
|
153
|
+
if (child.nextElementSibling) {
|
154
|
+
Object.assign(matched, this.findAll(rootElement, [child.nextElementSibling], selectorItems.slice(1), position));
|
155
|
+
}
|
156
|
+
break;
|
157
|
+
case SelectorCombinatorEnum_1.default.descendant:
|
158
|
+
case SelectorCombinatorEnum_1.default.child:
|
159
|
+
Object.assign(matched, this.findAll(rootElement, child.children, selectorItems.slice(1), position));
|
160
|
+
break;
|
137
161
|
}
|
138
162
|
}
|
139
163
|
}
|
140
|
-
if (
|
141
|
-
matched
|
164
|
+
if (selectorItem.combinator === SelectorCombinatorEnum_1.default.descendant && child.children.length) {
|
165
|
+
Object.assign(matched, this.findAll(rootElement, child.children, selectorItems, position));
|
142
166
|
}
|
143
167
|
}
|
144
168
|
return matched;
|
@@ -146,82 +170,50 @@ class QuerySelector {
|
|
146
170
|
/**
|
147
171
|
* Finds an element based on a query selector for a part of a list of selectors separated with comma.
|
148
172
|
*
|
149
|
-
* @param
|
150
|
-
* @param
|
151
|
-
* @param
|
152
|
-
* @param selectorParts
|
153
|
-
* @param [selectorItem] Selector item.
|
173
|
+
* @param rootElement Root element.
|
174
|
+
* @param children Child elements.
|
175
|
+
* @param selectorItems Selector items.
|
154
176
|
* @returns HTML element.
|
155
177
|
*/
|
156
|
-
static findFirst(
|
157
|
-
const
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
if (selectorParts.length === 1) {
|
165
|
-
if (rootNode !== node) {
|
166
|
-
return node;
|
178
|
+
static findFirst(rootElement, children, selectorItems) {
|
179
|
+
const selectorItem = selectorItems[0];
|
180
|
+
const nextSelectorItem = selectorItems[1];
|
181
|
+
for (const child of children) {
|
182
|
+
if (selectorItem.match(child)) {
|
183
|
+
if (!nextSelectorItem) {
|
184
|
+
if (rootElement !== child) {
|
185
|
+
return child;
|
167
186
|
}
|
168
187
|
}
|
169
188
|
else {
|
170
|
-
|
171
|
-
|
172
|
-
|
189
|
+
switch (nextSelectorItem.combinator) {
|
190
|
+
case SelectorCombinatorEnum_1.default.adjacentSibling:
|
191
|
+
if (child.nextElementSibling) {
|
192
|
+
const match = this.findFirst(rootElement, [child.nextElementSibling], selectorItems.slice(1));
|
193
|
+
if (match) {
|
194
|
+
return match;
|
195
|
+
}
|
196
|
+
}
|
197
|
+
break;
|
198
|
+
case SelectorCombinatorEnum_1.default.descendant:
|
199
|
+
case SelectorCombinatorEnum_1.default.child:
|
200
|
+
const match = this.findFirst(rootElement, child.children, selectorItems.slice(1));
|
201
|
+
if (match) {
|
202
|
+
return match;
|
203
|
+
}
|
204
|
+
break;
|
173
205
|
}
|
174
206
|
}
|
175
207
|
}
|
176
|
-
if (
|
177
|
-
const
|
178
|
-
if (
|
179
|
-
return
|
208
|
+
if (selectorItem.combinator === SelectorCombinatorEnum_1.default.descendant && child.children.length) {
|
209
|
+
const match = this.findFirst(rootElement, child.children, selectorItems);
|
210
|
+
if (match) {
|
211
|
+
return match;
|
180
212
|
}
|
181
213
|
}
|
182
214
|
}
|
183
215
|
return null;
|
184
216
|
}
|
185
|
-
/**
|
186
|
-
* Splits a selector string into groups and parts.
|
187
|
-
*
|
188
|
-
* @param selector Selector.
|
189
|
-
* @returns HTML element.
|
190
|
-
*/
|
191
|
-
static getSelectorParts(selector) {
|
192
|
-
if (selector === '*' || (!selector.includes(',') && !selector.includes(' '))) {
|
193
|
-
return [[selector]];
|
194
|
-
}
|
195
|
-
const regexp = new RegExp(SELECTOR_PART_REGEXP);
|
196
|
-
const groups = [];
|
197
|
-
let currentSelector = '';
|
198
|
-
let parts = [];
|
199
|
-
let match;
|
200
|
-
while ((match = regexp.exec(selector))) {
|
201
|
-
if (match[2]) {
|
202
|
-
const trimmed = match[2].trim();
|
203
|
-
parts.push(currentSelector);
|
204
|
-
currentSelector = '';
|
205
|
-
if (trimmed === ',') {
|
206
|
-
groups.push(parts);
|
207
|
-
parts = [];
|
208
|
-
}
|
209
|
-
else if (trimmed === '>') {
|
210
|
-
parts.push('>');
|
211
|
-
}
|
212
|
-
}
|
213
|
-
else if (match[1]) {
|
214
|
-
currentSelector += match[1];
|
215
|
-
}
|
216
|
-
}
|
217
|
-
if (currentSelector !== '') {
|
218
|
-
parts.push(currentSelector);
|
219
|
-
}
|
220
|
-
if (parts.length > 0) {
|
221
|
-
groups.push(parts);
|
222
|
-
}
|
223
|
-
return groups;
|
224
|
-
}
|
225
217
|
}
|
226
218
|
exports.default = QuerySelector;
|
227
219
|
//# sourceMappingURL=QuerySelector.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"QuerySelector.js","sourceRoot":"","sources":["../../src/query-selector/QuerySelector.ts"],"names":[],"mappings":";;;;;AAGA,
|
1
|
+
{"version":3,"file":"QuerySelector.js","sourceRoot":"","sources":["../../src/query-selector/QuerySelector.ts"],"names":[],"mappings":";;;;;AAGA,sEAA8C;AAC9C,8EAAsD;AACtD,sFAA8D;AAG9D,sEAA8C;AAG9C;;;;GAIG;AACH,MAAqB,aAAa;IACjC;;;;;;OAMG;IACI,MAAM,CAAC,gBAAgB,CAC7B,IAA8C,EAC9C,QAAgB;QAEhB,MAAM,QAAQ,GAAG,IAAI,kBAAQ,EAAY,CAAC;QAC1C,MAAM,UAAU,GAAG,EAAE,CAAC;QAEtB,IAAI,QAAQ,KAAK,EAAE,EAAE;YACpB,MAAM,IAAI,KAAK,CACd,oFAAoF,CACpF,CAAC;SACF;QAED,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,SAAS,EAAE;YAChD,OAAO,QAAQ,CAAC;SAChB;QAED,KAAK,MAAM,KAAK,IAAI,wBAAc,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE;YAC/D,MAAM,OAAO,GACZ,IAAI,CAAC,QAAQ,KAAK,sBAAY,CAAC,WAAW;gBACzC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAW,IAAI,EAAE,CAAW,IAAI,CAAC,EAAE,KAAK,CAAC;gBACvD,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YAC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CACtB,CAAC;gCACF,IAAI,KAAK,EAAE;oCACV,OAAO,KAAK,CAAC;iCACb;6BACD;4BACD,MAAM;wBACP,KAAK,gCAAsB,CAAC,UAAU,CAAC;wBACvC,KAAK,gCAAsB,CAAC,KAAK;4BAChC,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,CAAC,QAAQ,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;4BAClF,IAAI,KAAK,EAAE;gCACV,OAAO,KAAK,CAAC;6BACb;4BACD,MAAM;qBACP;iBACD;aACD;YAED,IAAI,YAAY,CAAC,UAAU,KAAK,gCAAsB,CAAC,UAAU,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE;gBAC3F,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;gBAEzE,IAAI,KAAK,EAAE;oBACV,OAAO,KAAK,CAAC;iBACb;aACD;SACD;QAED,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AA/RD,gCA+RC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"SelectorCombinatorEnum.d.ts","sourceRoot":"","sources":["../../src/query-selector/SelectorCombinatorEnum.ts"],"names":[],"mappings":"AAAA,aAAK,sBAAsB;IAC1B,UAAU,eAAe;IACzB,KAAK,UAAU;IACf,eAAe,oBAAoB;CACnC;AAED,eAAe,sBAAsB,CAAC"}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
var SelectorCombinatorEnum;
|
4
|
+
(function (SelectorCombinatorEnum) {
|
5
|
+
SelectorCombinatorEnum["descendant"] = "descendant";
|
6
|
+
SelectorCombinatorEnum["child"] = "child";
|
7
|
+
SelectorCombinatorEnum["adjacentSibling"] = "adjacentSibling";
|
8
|
+
})(SelectorCombinatorEnum || (SelectorCombinatorEnum = {}));
|
9
|
+
exports.default = SelectorCombinatorEnum;
|
10
|
+
//# sourceMappingURL=SelectorCombinatorEnum.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"SelectorCombinatorEnum.js","sourceRoot":"","sources":["../../src/query-selector/SelectorCombinatorEnum.ts"],"names":[],"mappings":";;AAAA,IAAK,sBAIJ;AAJD,WAAK,sBAAsB;IAC1B,mDAAyB,CAAA;IACzB,yCAAe,CAAA;IACf,6DAAmC,CAAA;AACpC,CAAC,EAJI,sBAAsB,KAAtB,sBAAsB,QAI1B;AAED,kBAAe,sBAAsB,CAAC"}
|
@@ -1,99 +1,84 @@
|
|
1
1
|
import IElement from '../nodes/element/IElement';
|
2
|
+
import SelectorCombinatorEnum from './SelectorCombinatorEnum';
|
3
|
+
import ISelectorAttribute from './ISelectorAttribute';
|
4
|
+
import ISelectorMatch from './ISelectorMatch';
|
2
5
|
/**
|
3
6
|
* Selector item.
|
4
7
|
*/
|
5
8
|
export default class SelectorItem {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
private id;
|
9
|
+
all: string | null;
|
10
|
+
tagName: string | null;
|
11
|
+
id: string | null;
|
12
|
+
classNames: string[] | null;
|
13
|
+
attributes: ISelectorAttribute[] | null;
|
14
|
+
pseudoClass: string | null;
|
15
|
+
pseudoArguments: string | null;
|
16
|
+
combinator: SelectorCombinatorEnum;
|
15
17
|
/**
|
16
18
|
* Constructor.
|
17
19
|
*
|
18
|
-
* @param
|
20
|
+
* @param [options] Options.
|
21
|
+
* @param [options.combinator] Combinator.
|
22
|
+
* @param [options.all] All.
|
23
|
+
* @param [options.tagName] Tag name.
|
24
|
+
* @param [options.id] ID.
|
25
|
+
* @param [options.classNames] Class names.
|
26
|
+
* @param [options.attributes] Attributes.
|
27
|
+
* @param [options.pseudoClass] Pseudo class.
|
28
|
+
* @param [options.pseudoArguments] Pseudo arguments.
|
19
29
|
*/
|
20
|
-
constructor(
|
30
|
+
constructor(options?: {
|
31
|
+
all?: string;
|
32
|
+
tagName?: string;
|
33
|
+
id?: string;
|
34
|
+
classNames?: string[];
|
35
|
+
attributes?: ISelectorAttribute[];
|
36
|
+
pseudoClass?: string;
|
37
|
+
pseudoArguments?: string;
|
38
|
+
combinator?: SelectorCombinatorEnum;
|
39
|
+
});
|
21
40
|
/**
|
22
41
|
* Matches a selector against an element.
|
23
42
|
*
|
24
43
|
* @param element HTML element.
|
25
44
|
* @returns Result.
|
26
45
|
*/
|
27
|
-
match(element: IElement):
|
28
|
-
priorityWeight: number;
|
29
|
-
matches: boolean;
|
30
|
-
};
|
46
|
+
match(element: IElement): ISelectorMatch | null;
|
31
47
|
/**
|
32
48
|
* Matches a psuedo selector.
|
33
49
|
*
|
34
50
|
* @param element Element.
|
35
|
-
* @
|
36
|
-
* @returns True if it is a match.
|
51
|
+
* @returns Result.
|
37
52
|
*/
|
38
|
-
private
|
53
|
+
private matchPsuedo;
|
39
54
|
/**
|
40
55
|
* Matches a nth-child selector.
|
41
56
|
*
|
42
57
|
* @param element Element.
|
43
|
-
* @param
|
44
|
-
* @param
|
58
|
+
* @param parentChildren Parent children.
|
59
|
+
* @param placement Placement.
|
45
60
|
* @returns True if it is a match.
|
46
61
|
*/
|
47
|
-
private
|
48
|
-
/**
|
49
|
-
* Matches a psuedo selector expression.
|
50
|
-
*
|
51
|
-
* @param element Element.
|
52
|
-
* @param psuedo Psuedo name.
|
53
|
-
* @returns True if it is a match.
|
54
|
-
*/
|
55
|
-
private matchesPsuedoExpression;
|
62
|
+
private matchNthChild;
|
56
63
|
/**
|
57
64
|
* Matches attribute.
|
58
65
|
*
|
59
66
|
* @param element Element.
|
60
|
-
* @param selector Selector.
|
61
67
|
* @returns Result.
|
62
68
|
*/
|
63
|
-
private
|
69
|
+
private matchAttributes;
|
64
70
|
/**
|
65
71
|
* Matches class.
|
66
72
|
*
|
67
73
|
* @param element Element.
|
68
|
-
* @param selector Selector.
|
69
74
|
* @returns Result.
|
70
75
|
*/
|
71
|
-
private
|
72
|
-
/**
|
73
|
-
* Matches attribute name only.
|
74
|
-
*
|
75
|
-
* @param element Element.
|
76
|
-
* @param attributeName Attribute name.
|
77
|
-
* @returns True if it is a match.
|
78
|
-
*/
|
79
|
-
private matchesAttributeName;
|
80
|
-
/** .
|
81
|
-
*
|
82
|
-
* Matches attribute name and value.
|
83
|
-
*
|
84
|
-
* @param element Element.
|
85
|
-
* @param attributeName Attribute name.
|
86
|
-
* @param attributeValue Attribute value.
|
87
|
-
* @param [matchType] Match type.
|
88
|
-
* @returns True if it is a match.
|
89
|
-
*/
|
76
|
+
private matchClass;
|
90
77
|
/**
|
78
|
+
* Returns the selector string.
|
91
79
|
*
|
92
|
-
* @
|
93
|
-
* @param attributeName
|
94
|
-
* @param attributeValue
|
95
|
-
* @param matchType
|
80
|
+
* @returns Selector string.
|
96
81
|
*/
|
97
|
-
private
|
82
|
+
private getSelectorString;
|
98
83
|
}
|
99
84
|
//# sourceMappingURL=SelectorItem.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SelectorItem.d.ts","sourceRoot":"","sources":["../../src/query-selector/SelectorItem.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,2BAA2B,CAAC;
|
1
|
+
{"version":3,"file":"SelectorItem.d.ts","sourceRoot":"","sources":["../../src/query-selector/SelectorItem.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,2BAA2B,CAAC;AAGjD,OAAO,sBAAsB,MAAM,0BAA0B,CAAC;AAC9D,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAEtD,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,YAAY;IACzB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,EAAE,EAAE,MAAM,GAAG,IAA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