You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 0b43903
Browse filesBrowse the repository at this point in the historyBrowse files
Share jsdom adapter configuration per document (#213)
* Add document-scoped jsdom engine configuration
* Group repository tests and development scripts
* Test shared adapter setup and verify relocated runners
* Compile escaped identifiers without changing class token boundaries
Copy file name to clipboardExpand all lines: docs/api.md
+62-43Lines changed: 62 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,21 +11,21 @@ Query contexts default to the factory document when omitted. `closest()`, `first
11
11
12
12
| Method | Result |
13
13
| --- | --- |
14
-
|[`byClass(cls, context)`](../src/nwsapi.mts#L3003)| Returns elements with the class name. |
15
-
|[`byId(id, context)`](../src/nwsapi.mts#L3001)| Returns elements with the ID. Duplicate IDs are allowed by default. |
16
-
|[`byTag(tag, context)`](../src/nwsapi.mts#L3002)| Returns elements with the tag name. Use `*` for all elements. |
17
-
|[`closest(selectors, element, callback)`](../src/nwsapi.mts#L3009)| Returns the nearest match, starting with the element, or `null`. |
18
-
|[`compile(selector, mode, callback)`](../src/nwsapi.mts#L3011)| Compiles a selector into a resolver function. This is an advanced API. |
19
-
|[`configure(option, clear)`](../src/nwsapi.mts#L3012)| Reads or changes options. Pass `true` as the second argument to clear compiled selectors. |
20
-
|[`emit(message, proto)`](../src/nwsapi.mts#L3014)| Reports an error using the configured error policy. |
21
-
|[`first(selectors, context, callback)`](../src/nwsapi.mts#L3005)| Returns the first matching descendant, or `null`. |
22
-
|[`install(all)`](../src/nwsapi.mts#L3020)| Replaces native selector methods. Pass `true` to also replace collection methods. |
23
-
|[`match(selectors, element, callback)`](../src/nwsapi.mts#L3006)| Returns whether the element matches. |
24
-
|[`registerCombinator(combinator, resolver)`](../src/nwsapi.mts#L3027)| Adds a relationship between elements using trusted resolver code. |
25
-
|[`registerOperator(operator, resolver)`](../src/nwsapi.mts#L3052)| Adds an attribute operator using a resolver with `p1`, `p2`, and `p3` fields. |
26
-
|[`registerSelector(name, rexp, func)`](../src/nwsapi.mts#L3074)| Adds a selector pattern and a compiler callback that returns `source` and `status`. |
27
-
|[`select(selectors, context, callback)`](../src/nwsapi.mts#L3007)| Returns an array of matching descendants, or an empty array. |
28
-
|[`uninstall()`](../src/nwsapi.mts#L3021)| Restores the native methods saved by `install()`. |
14
+
|[`byClass(cls, context)`](../src/nwsapi.mts#L3014)| Returns elements with the class name. |
15
+
|[`byId(id, context)`](../src/nwsapi.mts#L3012)| Returns elements with the ID. Duplicate IDs are allowed by default. |
16
+
|[`byTag(tag, context)`](../src/nwsapi.mts#L3013)| Returns elements with the tag name. Use `*` for all elements. |
17
+
|[`closest(selectors, element, callback)`](../src/nwsapi.mts#L3020)| Returns the nearest match, starting with the element, or `null`. |
18
+
|[`compile(selector, mode, callback)`](../src/nwsapi.mts#L3022)| Compiles a selector into a resolver function. This is an advanced API. |
19
+
|[`configure(option, clear)`](../src/nwsapi.mts#L3023)| Reads or changes options. Pass `true` as the second argument to clear compiled selectors. |
20
+
|[`emit(message, proto)`](../src/nwsapi.mts#L3025)| Reports an error using the configured error policy. |
21
+
|[`first(selectors, context, callback)`](../src/nwsapi.mts#L3016)| Returns the first matching descendant, or `null`. |
22
+
|[`install(all)`](../src/nwsapi.mts#L3031)| Replaces native selector methods. Pass `true` to also replace collection methods. |
23
+
|[`match(selectors, element, callback)`](../src/nwsapi.mts#L3017)| Returns whether the element matches. |
24
+
|[`registerCombinator(combinator, resolver)`](../src/nwsapi.mts#L3038)| Adds a relationship between elements using trusted resolver code. |
25
+
|[`registerOperator(operator, resolver)`](../src/nwsapi.mts#L3063)| Adds an attribute operator using a resolver with `p1`, `p2`, and `p3` fields. |
26
+
|[`registerSelector(name, rexp, func)`](../src/nwsapi.mts#L3085)| Adds a selector pattern and a compiler callback that returns `source` and `status`. |
27
+
|[`select(selectors, context, callback)`](../src/nwsapi.mts#L3018)| Returns an array of matching descendants, or an empty array. |
28
+
|[`uninstall()`](../src/nwsapi.mts#L3032)| Restores the native methods saved by `install()`. |
29
29
30
30
<details>
31
31
<summary>Configuration</summary>
@@ -60,22 +60,22 @@ These exports support extensions and debugging. Prefer query methods and `config
60
60
61
61
| Member | Purpose |
62
62
| --- | --- |
63
-
|[`CFG`](../src/nwsapi.mts#L2989)| Contains the compiler syntax settings. |
64
-
|[`Config`](../src/nwsapi.mts#L3015)| Contains the active options. Use `configure()` to change them. |
65
-
|[`M_BODY`](../src/nwsapi.mts#L2992)| Contains the matching resolver body template. |
66
-
|[`M_TEST`](../src/nwsapi.mts#L2996)| Contains the matching resolver test template. |
67
-
|[`matchLambdas`](../src/nwsapi.mts#L2981)| Caches compiled matching functions, not DOM results. |
68
-
|[`matchResolvers`](../src/nwsapi.mts#L2984)| Caches matching plans, not DOM results. |
69
-
|[`N_BODY`](../src/nwsapi.mts#L2993)| Exposes the matching resolver body template. |
70
-
|[`N_TEST`](../src/nwsapi.mts#L2997)| Contains the alternate resolver test template. |
|[`selectResolvers`](../src/nwsapi.mts#L2996)| Caches selection plans, not DOM results. |
77
+
|[`Snapshot`](../src/nwsapi.mts#L3027)| Contains the document state and helpers used by compiled selectors. |
78
+
|[`Version`](../src/nwsapi.mts#L3029)| Contains the engine version string. |
79
79
80
80
</details>
81
81
@@ -87,20 +87,39 @@ These exports support extensions and debugging. Prefer query methods and `config
87
87
Access the adapter as `require("nwsapi").DOMSelector` or `require("nwsapi/src/dom-selector.js")`.
88
88
jsdom calls these methods through the package override. Query options can set `noexcept: true` to suppress selector errors.
89
89
90
+
Configure before parsing, because styles and scripts can use selectors during document creation:
91
+
92
+
```js
93
+
const { DOMSelector } =require("nwsapi")
94
+
const { JSDOM } =require("jsdom")
95
+
constdom=newJSDOM(html, {
96
+
beforeParse(window) {
97
+
DOMSelector.configure(window, { LEGACY:true })
98
+
}
99
+
})
100
+
```
101
+
102
+
To reuse an engine, create a document without styles, then call `DOMSelector.use(window, engine)` before adding styles or running queries. The engine must belong to that document and have `VERBOSITY: true`. DOM queries throw for invalid selectors; stylesheet checks return no match.
103
+
104
+
Setup locks on the first query, selector support check, or stylesheet match. Do not change the shared engine configuration directly after setup: jsdom can cache computed styles. Separate factory calls remain independent. Compatible adapter copies share setup even when the package override loads a second copy.
105
+
90
106
| Method | Result |
91
107
| --- | --- |
92
-
|[`check(selector, node)`](../src/dom-selector.mts#L151)| Returns matching stylesheet branches and their syntax tree. Loads `css-tree` on first use. |
93
-
|[`clear(clearAll = false)`](../src/dom-selector.mts#L87)| Clears compiled selectors and parsed stylesheet selectors when `clearAll` is `true`. |
94
-
|[`closest(selector, node, options)`](../src/dom-selector.mts#L75)| Returns the nearest matching element, or `null`. |
0 commit comments