@stencil/mock-doc 5.0.0-alpha.3 → 5.0.0-alpha.31
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/README.md +133 -0
- package/dist/index.d.mts +4 -11
- package/dist/index.mjs +188 -221
- package/package.json +7 -7
- /package/{LICENSE.md → LICENSE} +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# @stencil/mock-doc
|
|
2
|
+
|
|
3
|
+
A minimal mock DOM implementation for server-side rendering and unit testing of Stencil components.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install --save-dev @stencil/mock-doc
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### `createDocument(html?)` — lightweight document only
|
|
14
|
+
|
|
15
|
+
Use this when you only need a `Document` with no surrounding `window` object:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { createDocument, serializeNodeToHtml } from '@stencil/mock-doc';
|
|
19
|
+
|
|
20
|
+
const doc = createDocument('<div class="greeting">Hello</div>');
|
|
21
|
+
const el = doc.querySelector('.greeting');
|
|
22
|
+
el.textContent = 'Hello, world!';
|
|
23
|
+
|
|
24
|
+
console.log(serializeNodeToHtml(el, { outerHtml: true }));
|
|
25
|
+
// <div class="greeting">Hello, world!</div>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### `MockWindow(html?)` — full window environment
|
|
29
|
+
|
|
30
|
+
Use this when your code accesses `window`, `location`, `navigator`, `localStorage`, etc.:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { MockWindow, serializeNodeToHtml } from '@stencil/mock-doc';
|
|
34
|
+
|
|
35
|
+
const win = new MockWindow('<html><body><my-comp></my-comp></body></html>');
|
|
36
|
+
const doc = win.document;
|
|
37
|
+
|
|
38
|
+
const el = doc.querySelector('my-comp');
|
|
39
|
+
el.setAttribute('label', 'Hello');
|
|
40
|
+
|
|
41
|
+
const html = serializeNodeToHtml(doc);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### `parseHtmlToDocument` / `parseHtmlToFragment`
|
|
45
|
+
|
|
46
|
+
Parse an HTML string into a `Document` or a `DocumentFragment`:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { parseHtmlToDocument, parseHtmlToFragment } from '@stencil/mock-doc';
|
|
50
|
+
|
|
51
|
+
const doc = parseHtmlToDocument('<p>Hello</p>');
|
|
52
|
+
const frag = parseHtmlToFragment('<li>one</li><li>two</li>');
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### `serializeNodeToHtml(node, options?)`
|
|
56
|
+
|
|
57
|
+
Serialize any node back to an HTML string. Useful for snapshot tests and SSR output.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { serializeNodeToHtml } from '@stencil/mock-doc';
|
|
61
|
+
|
|
62
|
+
// Pretty-printed output
|
|
63
|
+
const pretty = serializeNodeToHtml(doc, { prettyHtml: true });
|
|
64
|
+
|
|
65
|
+
// Outer HTML of a single element (includes the element's own tag)
|
|
66
|
+
const outer = serializeNodeToHtml(el, { outerHtml: true });
|
|
67
|
+
|
|
68
|
+
// Serialize shadow roots as Declarative Shadow DOM
|
|
69
|
+
const dsd = serializeNodeToHtml(doc, {
|
|
70
|
+
serializeShadowRoot: 'declarative-shadow-dom',
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Key options:
|
|
75
|
+
|
|
76
|
+
| Option | Default | Description |
|
|
77
|
+
|---|---|---|
|
|
78
|
+
| `prettyHtml` | `false` | Indent and add newlines |
|
|
79
|
+
| `indentSpaces` | `2` (when pretty) | Spaces per indent level |
|
|
80
|
+
| `outerHtml` | `false` | Include the root element's own tag |
|
|
81
|
+
| `removeEmptyAttributes` | `true` | Strip attributes with empty string values |
|
|
82
|
+
| `removeHtmlComments` | `false` | Strip HTML comments |
|
|
83
|
+
| `serializeShadowRoot` | — | `'declarative-shadow-dom'` or `'scoped'` |
|
|
84
|
+
| `fullDocument` | `false` | Always emit a full `<!DOCTYPE html>` document |
|
|
85
|
+
|
|
86
|
+
### `setupGlobal` / `teardownGlobal` — test framework integration
|
|
87
|
+
|
|
88
|
+
Installs a `MockWindow` onto `global` so that `window`, `document`, `customElements`, etc. are available without a browser. Call in `beforeEach`/`afterEach` to get a fresh environment per test:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { setupGlobal, teardownGlobal } from '@stencil/mock-doc';
|
|
92
|
+
|
|
93
|
+
beforeEach(() => setupGlobal(global));
|
|
94
|
+
afterEach(() => teardownGlobal(global));
|
|
95
|
+
|
|
96
|
+
it('reads document.title', () => {
|
|
97
|
+
document.title = 'My Page';
|
|
98
|
+
expect(document.title).toBe('My Page');
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`setupGlobal` returns the `MockWindow` it created, which you can use to reach `window`-level APIs directly if needed.
|
|
103
|
+
|
|
104
|
+
### `patchWindow(win)` — fill gaps in a partial window
|
|
105
|
+
|
|
106
|
+
Useful when running in an environment that has _some_ browser globals but is missing others (e.g. a custom SSR runtime):
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import { patchWindow } from '@stencil/mock-doc';
|
|
110
|
+
|
|
111
|
+
patchWindow(globalThis); // fills in any missing window APIs with mock implementations
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Fetch mocks
|
|
115
|
+
|
|
116
|
+
Use `MockRequest`, `MockResponse`, and `MockHeaders` to test code that calls `fetch` without hitting the network:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { MockRequest, MockResponse, MockHeaders } from '@stencil/mock-doc';
|
|
120
|
+
|
|
121
|
+
// Simulate an incoming request
|
|
122
|
+
const req = new MockRequest('/api/data', { method: 'POST' });
|
|
123
|
+
console.log(req.method); // 'POST'
|
|
124
|
+
console.log(req.url); // 'http://localhost/api/data'
|
|
125
|
+
|
|
126
|
+
// Build a response your handler returns
|
|
127
|
+
const res = new MockResponse(JSON.stringify({ ok: true }), {
|
|
128
|
+
status: 200,
|
|
129
|
+
headers: new MockHeaders({ 'content-type': 'application/json' }),
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const body = await res.json(); // { ok: true }
|
|
133
|
+
```
|
package/dist/index.d.mts
CHANGED
|
@@ -219,7 +219,7 @@ declare class MockWindow {
|
|
|
219
219
|
__allowInterval: boolean;
|
|
220
220
|
URL: typeof URL;
|
|
221
221
|
console: Console;
|
|
222
|
-
customElements: CustomElementRegistry;
|
|
222
|
+
customElements: CustomElementRegistry | null;
|
|
223
223
|
document: Document;
|
|
224
224
|
performance: Performance;
|
|
225
225
|
devicePixelRatio: number;
|
|
@@ -433,7 +433,7 @@ declare class MockWindow {
|
|
|
433
433
|
onwebkitfullscreenerror(): void;
|
|
434
434
|
onwheel(): void;
|
|
435
435
|
}
|
|
436
|
-
declare function cloneWindow(srcWin: Window, opts?: {
|
|
436
|
+
declare function cloneWindow(srcWin: Window | MockWindow, opts?: {
|
|
437
437
|
customElementProxy?: boolean;
|
|
438
438
|
}): MockWindow | null;
|
|
439
439
|
declare function cloneDocument(srcDoc: Document): Document;
|
|
@@ -442,7 +442,7 @@ declare function cloneDocument(srcDoc: Document): Document;
|
|
|
442
442
|
* only allow setInterval() to fire once, also constrained to 1ms.
|
|
443
443
|
* @param win the mock window instance to update
|
|
444
444
|
*/
|
|
445
|
-
declare function constrainTimeouts(win:
|
|
445
|
+
declare function constrainTimeouts(win: MockWindow): void;
|
|
446
446
|
//#endregion
|
|
447
447
|
//#region src/event.d.ts
|
|
448
448
|
declare class MockEvent {
|
|
@@ -510,13 +510,6 @@ declare class MockEventListener {
|
|
|
510
510
|
handler: (ev?: any) => void;
|
|
511
511
|
constructor(type: string, handler: any);
|
|
512
512
|
}
|
|
513
|
-
/**
|
|
514
|
-
* Add an event listener to an element.
|
|
515
|
-
*
|
|
516
|
-
* @param elm - the element to add the listener to
|
|
517
|
-
* @param type - the event type to listen for
|
|
518
|
-
* @param handler - the event handler function
|
|
519
|
-
*/
|
|
520
513
|
interface EventTarget {
|
|
521
514
|
__listeners: MockEventListener[];
|
|
522
515
|
}
|
|
@@ -972,7 +965,7 @@ declare class MockHeaders {
|
|
|
972
965
|
value: string;
|
|
973
966
|
done: boolean;
|
|
974
967
|
};
|
|
975
|
-
[Symbol.iterator](): /*elided*/any;
|
|
968
|
+
[Symbol.iterator](): /*elided*/ any;
|
|
976
969
|
};
|
|
977
970
|
set(key: string, value: string): void;
|
|
978
971
|
values(): any;
|
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
9
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
10
10
|
var __copyProps = (to, from, except, desc) => {
|
|
11
11
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
12
|
key = keys[i];
|
|
@@ -17,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
21
21
|
value: mod,
|
|
22
22
|
enumerable: true
|
|
23
23
|
}) : target, mod));
|
|
@@ -48,13 +48,6 @@ let NODE_TYPES = /* @__PURE__ */ function(NODE_TYPES) {
|
|
|
48
48
|
NODE_TYPES[NODE_TYPES["DOCUMENT_FRAGMENT_NODE"] = 11] = "DOCUMENT_FRAGMENT_NODE";
|
|
49
49
|
return NODE_TYPES;
|
|
50
50
|
}({});
|
|
51
|
-
let NODE_NAMES = /* @__PURE__ */ function(NODE_NAMES) {
|
|
52
|
-
NODE_NAMES["COMMENT_NODE"] = "#comment";
|
|
53
|
-
NODE_NAMES["DOCUMENT_NODE"] = "#document";
|
|
54
|
-
NODE_NAMES["DOCUMENT_FRAGMENT_NODE"] = "#document-fragment";
|
|
55
|
-
NODE_NAMES["TEXT_NODE"] = "#text";
|
|
56
|
-
return NODE_NAMES;
|
|
57
|
-
}({});
|
|
58
51
|
//#endregion
|
|
59
52
|
//#region src/attribute.ts
|
|
60
53
|
const attrHandler = { get(obj, prop) {
|
|
@@ -63,6 +56,7 @@ const attrHandler = { get(obj, prop) {
|
|
|
63
56
|
} };
|
|
64
57
|
const createAttributeProxy = (caseInsensitive) => new Proxy(new MockAttributeMap(caseInsensitive), attrHandler);
|
|
65
58
|
var MockAttributeMap = class {
|
|
59
|
+
caseInsensitive;
|
|
66
60
|
__items = [];
|
|
67
61
|
constructor(caseInsensitive = false) {
|
|
68
62
|
this.caseInsensitive = caseInsensitive;
|
|
@@ -285,6 +279,7 @@ function jsCaseToCssCase(str) {
|
|
|
285
279
|
//#endregion
|
|
286
280
|
//#region src/custom-element-registry.ts
|
|
287
281
|
var MockCustomElementRegistry = class {
|
|
282
|
+
win;
|
|
288
283
|
__registry;
|
|
289
284
|
__whenDefined;
|
|
290
285
|
constructor(win) {
|
|
@@ -389,7 +384,7 @@ const proxyElements = /* @__PURE__ */ new WeakMap();
|
|
|
389
384
|
const upgradedElements = /* @__PURE__ */ new WeakSet();
|
|
390
385
|
function connectNode(ownerDocument, node) {
|
|
391
386
|
node.ownerDocument = ownerDocument;
|
|
392
|
-
if (node.nodeType ===
|
|
387
|
+
if (node.nodeType === 1) {
|
|
393
388
|
if (ownerDocument != null && node.nodeName.includes("-")) {
|
|
394
389
|
if (ownerDocument.defaultView != null && typeof node.connectedCallback === "function" && node.isConnected) fireConnectedCallback(node);
|
|
395
390
|
const shadowRoot = node.shadowRoot;
|
|
@@ -414,7 +409,7 @@ function fireConnectedCallback(node) {
|
|
|
414
409
|
}
|
|
415
410
|
}
|
|
416
411
|
function disconnectNode(node) {
|
|
417
|
-
if (node.nodeType ===
|
|
412
|
+
if (node.nodeType === 1) {
|
|
418
413
|
if (node.nodeName.includes("-") === true && typeof node.disconnectedCallback === "function") {
|
|
419
414
|
if (tempDisableCallbacks.has(node.ownerDocument) === false) try {
|
|
420
415
|
node.disconnectedCallback();
|
|
@@ -508,7 +503,7 @@ var MockEvent = class {
|
|
|
508
503
|
let currentElement = this.target;
|
|
509
504
|
while (currentElement) {
|
|
510
505
|
composedPath.push(currentElement);
|
|
511
|
-
if (!currentElement.parentElement && currentElement.nodeName ===
|
|
506
|
+
if (!currentElement.parentElement && currentElement.nodeName === "#document") {
|
|
512
507
|
composedPath.push(currentElement.defaultView);
|
|
513
508
|
break;
|
|
514
509
|
}
|
|
@@ -639,7 +634,7 @@ function triggerEventListener(elm, ev) {
|
|
|
639
634
|
}
|
|
640
635
|
});
|
|
641
636
|
if (ev.bubbles === false) return;
|
|
642
|
-
if (elm.nodeName ===
|
|
637
|
+
if (elm.nodeName === "#document") triggerEventListener(elm.defaultView, ev);
|
|
643
638
|
else if (elm.parentElement == null && elm.tagName === "HTML") triggerEventListener(elm.ownerDocument, ev);
|
|
644
639
|
else triggerEventListener(getNextEventTarget(elm, ev), ev);
|
|
645
640
|
}
|
|
@@ -688,7 +683,7 @@ function getParser(ownerDocument) {
|
|
|
688
683
|
if (parseOptions != null) return parseOptions;
|
|
689
684
|
parseOptions = { treeAdapter: {
|
|
690
685
|
createDocument() {
|
|
691
|
-
const doc = ownerDocument.createElement(
|
|
686
|
+
const doc = ownerDocument.createElement("#document");
|
|
692
687
|
doc["x-mode"] = "no-quirks";
|
|
693
688
|
return doc;
|
|
694
689
|
},
|
|
@@ -727,7 +722,7 @@ function getParser(ownerDocument) {
|
|
|
727
722
|
return templateElement.content;
|
|
728
723
|
},
|
|
729
724
|
setDocumentType(doc, name, publicId, systemId) {
|
|
730
|
-
let doctypeNode = doc.childNodes.find((n) => n.nodeType ===
|
|
725
|
+
let doctypeNode = doc.childNodes.find((n) => n.nodeType === 10);
|
|
731
726
|
if (doctypeNode == null) {
|
|
732
727
|
doctypeNode = ownerDocument.createDocumentTypeNode();
|
|
733
728
|
doc.insertBefore(doctypeNode, doc.firstChild);
|
|
@@ -748,12 +743,12 @@ function getParser(ownerDocument) {
|
|
|
748
743
|
},
|
|
749
744
|
insertText(parentNode, text) {
|
|
750
745
|
const lastChild = parentNode.lastChild;
|
|
751
|
-
if (lastChild != null && lastChild.nodeType ===
|
|
746
|
+
if (lastChild != null && lastChild.nodeType === 3) lastChild.nodeValue += text;
|
|
752
747
|
else parentNode.appendChild(ownerDocument.createTextNode(text));
|
|
753
748
|
},
|
|
754
749
|
insertTextBefore(parentNode, text, referenceNode) {
|
|
755
750
|
const prevNode = parentNode.childNodes[parentNode.childNodes.indexOf(referenceNode) - 1];
|
|
756
|
-
if (prevNode != null && prevNode.nodeType ===
|
|
751
|
+
if (prevNode != null && prevNode.nodeType === 3) prevNode.nodeValue += text;
|
|
757
752
|
else parentNode.insertBefore(ownerDocument.createTextNode(text), referenceNode);
|
|
758
753
|
},
|
|
759
754
|
adoptAttributes(recipient, attrs) {
|
|
@@ -805,16 +800,16 @@ function getParser(ownerDocument) {
|
|
|
805
800
|
return doctypeNode["x-systemId"];
|
|
806
801
|
},
|
|
807
802
|
isTextNode(node) {
|
|
808
|
-
return node.nodeType ===
|
|
803
|
+
return node.nodeType === 3;
|
|
809
804
|
},
|
|
810
805
|
isCommentNode(node) {
|
|
811
|
-
return node.nodeType ===
|
|
806
|
+
return node.nodeType === 8;
|
|
812
807
|
},
|
|
813
808
|
isDocumentTypeNode(node) {
|
|
814
|
-
return node.nodeType ===
|
|
809
|
+
return node.nodeType === 10;
|
|
815
810
|
},
|
|
816
811
|
isElementNode(node) {
|
|
817
|
-
return node.nodeType ===
|
|
812
|
+
return node.nodeType === 1;
|
|
818
813
|
}
|
|
819
814
|
} };
|
|
820
815
|
docParser.set(ownerDocument, parseOptions);
|
|
@@ -888,8 +883,8 @@ const shadowRootTag = "mock:shadow-root";
|
|
|
888
883
|
* @yields the serialized HTML in chunks
|
|
889
884
|
*/
|
|
890
885
|
function* streamToHtml(node, opts, output) {
|
|
891
|
-
const isShadowRoot = node.nodeType ===
|
|
892
|
-
if (node.nodeType ===
|
|
886
|
+
const isShadowRoot = node.nodeType === 11;
|
|
887
|
+
if (node.nodeType === 1 || isShadowRoot) {
|
|
893
888
|
const tagName = isShadowRoot ? shadowRootTag : getTagName(node);
|
|
894
889
|
if (tagName === "body") output.isWithinBody = true;
|
|
895
890
|
const ignoreTag = opts.excludeTags != null && opts.excludeTags.includes(tagName);
|
|
@@ -925,7 +920,7 @@ function* streamToHtml(node, opts, output) {
|
|
|
925
920
|
const attr = attributes.item(i);
|
|
926
921
|
const attrName = attr.name;
|
|
927
922
|
if (attrName === "style") continue;
|
|
928
|
-
if (tag === "template" && isShadowRoot && (attrName === "shadowrootmode" || attrName === "shadowrootdelegatesfocus")) continue;
|
|
923
|
+
if (tag === "template" && isShadowRoot && (attrName === "shadowrootmode" || attrName === "shadowrootdelegatesfocus" || attrName === "shadowrootcustomelementregistry")) continue;
|
|
929
924
|
let attrValue = attr.value;
|
|
930
925
|
if (opts.removeEmptyAttributes && attrValue === "" && REMOVE_EMPTY_ATTR.has(attrName)) continue;
|
|
931
926
|
const attrNamespaceURI = attr.namespaceURI;
|
|
@@ -939,14 +934,15 @@ function* streamToHtml(node, opts, output) {
|
|
|
939
934
|
} else if (attrNamespaceURI === "http://www.w3.org/XML/1998/namespace") {
|
|
940
935
|
yield " xml:" + attrLocalName;
|
|
941
936
|
output.currentLineWidth += attrLocalName.length + 5;
|
|
942
|
-
} else if (attrNamespaceURI === "http://www.w3.org/2000/xmlns/")
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
937
|
+
} else if (attrNamespaceURI === "http://www.w3.org/2000/xmlns/") {
|
|
938
|
+
if (attrLocalName !== "xmlns") {
|
|
939
|
+
yield " xmlns:" + attrLocalName;
|
|
940
|
+
output.currentLineWidth += attrLocalName.length + 7;
|
|
941
|
+
} else {
|
|
942
|
+
yield " " + attrLocalName;
|
|
943
|
+
output.currentLineWidth += attrLocalName.length + 1;
|
|
944
|
+
}
|
|
945
|
+
} else if (attrNamespaceURI === "http://www.w3.org/1999/xlink") {
|
|
950
946
|
yield " xlink:" + attrLocalName;
|
|
951
947
|
output.currentLineWidth += attrLocalName.length + 7;
|
|
952
948
|
} else {
|
|
@@ -988,7 +984,7 @@ function* streamToHtml(node, opts, output) {
|
|
|
988
984
|
yield* streamToHtml(shadowRoot, opts, output);
|
|
989
985
|
output.indent = output.indent - (opts.indentSpaces ?? 0);
|
|
990
986
|
const childNodes = getChildNodes(node);
|
|
991
|
-
if (opts.newLines && (childNodes.length === 0 || childNodes.length === 1 && childNodes[0].nodeType ===
|
|
987
|
+
if (opts.newLines && (childNodes.length === 0 || childNodes.length === 1 && childNodes[0].nodeType === 3 && childNodes[0].nodeValue?.trim() === "")) {
|
|
992
988
|
yield "\n";
|
|
993
989
|
output.currentLineWidth = 0;
|
|
994
990
|
for (let i = 0; i < output.indent; i++) yield " ";
|
|
@@ -999,34 +995,36 @@ function* streamToHtml(node, opts, output) {
|
|
|
999
995
|
const tag = tagName === shadowRootTag ? "template" : tagName;
|
|
1000
996
|
const childNodes = tagName === "template" ? node.content.childNodes : getChildNodes(node);
|
|
1001
997
|
const childNodeLength = childNodes.length;
|
|
1002
|
-
if (childNodeLength > 0)
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
if (ignoreTag === false) {
|
|
1022
|
-
if (opts.newLines && !isWithinWhitespaceSensitiveNode) {
|
|
1023
|
-
yield "\n";
|
|
1024
|
-
output.currentLineWidth = 0;
|
|
998
|
+
if (childNodeLength > 0) {
|
|
999
|
+
if (childNodeLength === 1 && childNodes[0].nodeType === 3 && (typeof childNodes[0].nodeValue !== "string" || childNodes[0].nodeValue.trim() === "")) {} else {
|
|
1000
|
+
const isWithinWhitespaceSensitiveNode = opts.newLines || (opts.indentSpaces ?? 0) > 0 ? isWithinWhitespaceSensitive(node) : false;
|
|
1001
|
+
if (!isWithinWhitespaceSensitiveNode && (opts.indentSpaces ?? 0) > 0 && ignoreTag === false) output.indent = output.indent + (opts.indentSpaces ?? 0);
|
|
1002
|
+
for (let i = 0; i < childNodeLength; i++) {
|
|
1003
|
+
/**
|
|
1004
|
+
* In cases where a user would pass in a declarative shadow dom of a
|
|
1005
|
+
* Stencil component, we want to skip over the template tag as we
|
|
1006
|
+
* will be parsing the shadow root of the component again.
|
|
1007
|
+
*
|
|
1008
|
+
* We know it is a hydrated Stencil component by checking if the `HYDRATE_ID`
|
|
1009
|
+
* is set on the node.
|
|
1010
|
+
*/
|
|
1011
|
+
const sId = node.attributes.getNamedItem(HYDRATE_ID);
|
|
1012
|
+
if (childNodes[i].nodeName.toLowerCase() === "template" && sId) {
|
|
1013
|
+
yield `\n${" ".repeat(output.indent)}<!--r.${sId.value}-->`;
|
|
1014
|
+
continue;
|
|
1015
|
+
}
|
|
1016
|
+
yield* streamToHtml(childNodes[i], opts, output);
|
|
1025
1017
|
}
|
|
1026
|
-
if (
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1018
|
+
if (ignoreTag === false) {
|
|
1019
|
+
if (opts.newLines && !isWithinWhitespaceSensitiveNode) {
|
|
1020
|
+
yield "\n";
|
|
1021
|
+
output.currentLineWidth = 0;
|
|
1022
|
+
}
|
|
1023
|
+
if ((opts.indentSpaces ?? 0) > 0 && !isWithinWhitespaceSensitiveNode) {
|
|
1024
|
+
output.indent = output.indent - (opts.indentSpaces ?? 0);
|
|
1025
|
+
for (let i = 0; i < output.indent; i++) yield " ";
|
|
1026
|
+
output.currentLineWidth += output.indent;
|
|
1027
|
+
}
|
|
1030
1028
|
}
|
|
1031
1029
|
}
|
|
1032
1030
|
}
|
|
@@ -1041,7 +1039,7 @@ function* streamToHtml(node, opts, output) {
|
|
|
1041
1039
|
output.currentLineWidth = 0;
|
|
1042
1040
|
}
|
|
1043
1041
|
if (tagName === "body") output.isWithinBody = false;
|
|
1044
|
-
} else if (node.nodeType ===
|
|
1042
|
+
} else if (node.nodeType === 3) {
|
|
1045
1043
|
let textContent = node.nodeValue;
|
|
1046
1044
|
if (typeof textContent === "string") {
|
|
1047
1045
|
const trimmedTextContent = textContent.trim();
|
|
@@ -1068,7 +1066,7 @@ function* streamToHtml(node, opts, output) {
|
|
|
1068
1066
|
}
|
|
1069
1067
|
let textContentLength = textContent.length;
|
|
1070
1068
|
if (textContentLength > 0) {
|
|
1071
|
-
const parentTagName = node.parentNode != null && node.parentNode.nodeType ===
|
|
1069
|
+
const parentTagName = node.parentNode != null && node.parentNode.nodeType === 1 ? node.parentNode.nodeName : null;
|
|
1072
1070
|
if (typeof parentTagName === "string" && NON_ESCAPABLE_CONTENT.has(parentTagName)) {
|
|
1073
1071
|
if (isWithinWhitespaceSensitive(node)) yield textContent;
|
|
1074
1072
|
else {
|
|
@@ -1082,13 +1080,15 @@ function* streamToHtml(node, opts, output) {
|
|
|
1082
1080
|
} else {
|
|
1083
1081
|
if (isWithinWhitespaceSensitive(node)) output.currentLineWidth += textContentLength;
|
|
1084
1082
|
else {
|
|
1085
|
-
if (/\s/.test(textContent.charAt(0))) textContent = " " + textContent.
|
|
1083
|
+
if (/\s/.test(textContent.charAt(0))) textContent = " " + textContent.trimStart();
|
|
1086
1084
|
textContentLength = textContent.length;
|
|
1087
1085
|
if (textContentLength > 1) {
|
|
1088
|
-
if (/\s/.test(textContent.charAt(textContentLength - 1)))
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1086
|
+
if (/\s/.test(textContent.charAt(textContentLength - 1))) {
|
|
1087
|
+
if (opts.approximateLineWidth && opts.approximateLineWidth > 0 && output.currentLineWidth + textContentLength > opts.approximateLineWidth) {
|
|
1088
|
+
textContent = textContent.trimEnd() + "\n";
|
|
1089
|
+
output.currentLineWidth = 0;
|
|
1090
|
+
} else textContent = textContent.trimEnd() + " ";
|
|
1091
|
+
}
|
|
1092
1092
|
}
|
|
1093
1093
|
output.currentLineWidth += textContentLength;
|
|
1094
1094
|
}
|
|
@@ -1097,7 +1097,7 @@ function* streamToHtml(node, opts, output) {
|
|
|
1097
1097
|
}
|
|
1098
1098
|
}
|
|
1099
1099
|
}
|
|
1100
|
-
} else if (node.nodeType ===
|
|
1100
|
+
} else if (node.nodeType === 8) {
|
|
1101
1101
|
const nodeValue = node.nodeValue;
|
|
1102
1102
|
const isHydrateAnnotation = nodeValue?.startsWith("r.") || nodeValue?.startsWith("o.") || nodeValue?.startsWith("s.") || nodeValue?.startsWith("t.");
|
|
1103
1103
|
/**
|
|
@@ -1116,7 +1116,7 @@ function* streamToHtml(node, opts, output) {
|
|
|
1116
1116
|
}
|
|
1117
1117
|
yield "<!--" + nodeValue + "-->";
|
|
1118
1118
|
if (nodeValue) output.currentLineWidth += nodeValue.length + 7;
|
|
1119
|
-
} else if (node.nodeType ===
|
|
1119
|
+
} else if (node.nodeType === 10) yield "<!doctype html>";
|
|
1120
1120
|
}
|
|
1121
1121
|
const AMP_REGEX = /&/g;
|
|
1122
1122
|
const NBSP_REGEX = /\u00a0/g;
|
|
@@ -1159,50 +1159,40 @@ function isWithinWhitespaceSensitive(node) {
|
|
|
1159
1159
|
function getChildNodes(node) {
|
|
1160
1160
|
return node.__childNodes || node.childNodes;
|
|
1161
1161
|
}
|
|
1162
|
-
const NON_ESCAPABLE_CONTENT = new Set([
|
|
1162
|
+
const NON_ESCAPABLE_CONTENT = /* @__PURE__ */ new Set([
|
|
1163
1163
|
"STYLE",
|
|
1164
1164
|
"SCRIPT",
|
|
1165
1165
|
"IFRAME",
|
|
1166
|
-
"NOSCRIPT"
|
|
1167
|
-
"XMP",
|
|
1168
|
-
"NOEMBED",
|
|
1169
|
-
"NOFRAMES",
|
|
1170
|
-
"PLAINTEXT"
|
|
1166
|
+
"NOSCRIPT"
|
|
1171
1167
|
]);
|
|
1172
1168
|
/**
|
|
1173
1169
|
* A list of whitespace sensitive tag names, such as `code`, `pre`, etc.
|
|
1174
1170
|
*/
|
|
1175
|
-
const WHITESPACE_SENSITIVE = new Set([
|
|
1171
|
+
const WHITESPACE_SENSITIVE = /* @__PURE__ */ new Set([
|
|
1176
1172
|
"CODE",
|
|
1177
1173
|
"OUTPUT",
|
|
1178
|
-
"PLAINTEXT",
|
|
1179
1174
|
"PRE",
|
|
1180
1175
|
"SCRIPT",
|
|
1181
1176
|
"TEMPLATE",
|
|
1182
1177
|
"TEXTAREA"
|
|
1183
1178
|
]);
|
|
1184
|
-
const EMPTY_ELEMENTS = new Set([
|
|
1179
|
+
const EMPTY_ELEMENTS = /* @__PURE__ */ new Set([
|
|
1185
1180
|
"area",
|
|
1186
1181
|
"base",
|
|
1187
|
-
"basefont",
|
|
1188
|
-
"bgsound",
|
|
1189
1182
|
"br",
|
|
1190
1183
|
"col",
|
|
1191
1184
|
"embed",
|
|
1192
|
-
"frame",
|
|
1193
1185
|
"hr",
|
|
1194
1186
|
"img",
|
|
1195
1187
|
"input",
|
|
1196
|
-
"keygen",
|
|
1197
1188
|
"link",
|
|
1198
1189
|
"meta",
|
|
1199
1190
|
"param",
|
|
1200
1191
|
"source",
|
|
1201
|
-
"trace",
|
|
1202
1192
|
"track",
|
|
1203
1193
|
"wbr"
|
|
1204
1194
|
]);
|
|
1205
|
-
const REMOVE_EMPTY_ATTR = new Set([
|
|
1195
|
+
const REMOVE_EMPTY_ATTR = /* @__PURE__ */ new Set([
|
|
1206
1196
|
"class",
|
|
1207
1197
|
"dir",
|
|
1208
1198
|
"id",
|
|
@@ -1210,52 +1200,37 @@ const REMOVE_EMPTY_ATTR = new Set([
|
|
|
1210
1200
|
"name",
|
|
1211
1201
|
"title"
|
|
1212
1202
|
]);
|
|
1213
|
-
const BOOLEAN_ATTR = new Set([
|
|
1203
|
+
const BOOLEAN_ATTR = /* @__PURE__ */ new Set([
|
|
1214
1204
|
"allowfullscreen",
|
|
1215
1205
|
"async",
|
|
1216
1206
|
"autofocus",
|
|
1217
1207
|
"autoplay",
|
|
1218
1208
|
"checked",
|
|
1219
|
-
"compact",
|
|
1220
1209
|
"controls",
|
|
1221
|
-
"declare",
|
|
1222
1210
|
"default",
|
|
1223
|
-
"defaultchecked",
|
|
1224
|
-
"defaultmuted",
|
|
1225
|
-
"defaultselected",
|
|
1226
1211
|
"defer",
|
|
1227
1212
|
"disabled",
|
|
1228
|
-
"enabled",
|
|
1229
1213
|
"formnovalidate",
|
|
1230
1214
|
"hidden",
|
|
1231
|
-
"indeterminate",
|
|
1232
1215
|
"inert",
|
|
1233
1216
|
"ismap",
|
|
1234
1217
|
"itemscope",
|
|
1235
1218
|
"loop",
|
|
1236
1219
|
"multiple",
|
|
1237
1220
|
"muted",
|
|
1238
|
-
"nohref",
|
|
1239
1221
|
"nomodule",
|
|
1240
|
-
"noresize",
|
|
1241
|
-
"noshade",
|
|
1242
1222
|
"novalidate",
|
|
1243
|
-
"nowrap",
|
|
1244
1223
|
"open",
|
|
1245
|
-
"pauseonexit",
|
|
1246
1224
|
"readonly",
|
|
1247
1225
|
"required",
|
|
1248
1226
|
"reversed",
|
|
1249
|
-
"scoped",
|
|
1250
|
-
"seamless",
|
|
1251
1227
|
"selected",
|
|
1228
|
+
"shadowrootclonable",
|
|
1229
|
+
"shadowrootcustomelementregistry",
|
|
1252
1230
|
"shadowrootdelegatesfocus",
|
|
1253
|
-
"
|
|
1254
|
-
"truespeed",
|
|
1255
|
-
"typemustmatch",
|
|
1256
|
-
"visible"
|
|
1231
|
+
"shadowrootserializable"
|
|
1257
1232
|
]);
|
|
1258
|
-
const STRUCTURE_ELEMENTS = new Set([
|
|
1233
|
+
const STRUCTURE_ELEMENTS = /* @__PURE__ */ new Set([
|
|
1259
1234
|
"html",
|
|
1260
1235
|
"body",
|
|
1261
1236
|
"head",
|
|
@@ -1270,6 +1245,8 @@ const STRUCTURE_ELEMENTS = new Set([
|
|
|
1270
1245
|
//#endregion
|
|
1271
1246
|
//#region src/token-list.ts
|
|
1272
1247
|
var MockTokenList = class {
|
|
1248
|
+
elm;
|
|
1249
|
+
attr;
|
|
1273
1250
|
constructor(elm, attr) {
|
|
1274
1251
|
this.elm = elm;
|
|
1275
1252
|
this.attr = attr;
|
|
@@ -1352,7 +1329,7 @@ var MockNode = class {
|
|
|
1352
1329
|
this._childNodes = value;
|
|
1353
1330
|
}
|
|
1354
1331
|
appendChild(newNode) {
|
|
1355
|
-
if (newNode.nodeType ===
|
|
1332
|
+
if (newNode.nodeType === 11) {
|
|
1356
1333
|
const nodes = newNode.childNodes.slice();
|
|
1357
1334
|
for (const child of nodes) this.appendChild(child);
|
|
1358
1335
|
} else {
|
|
@@ -1383,22 +1360,20 @@ var MockNode = class {
|
|
|
1383
1360
|
const DOCUMENT_POSITION_DISCONNECTED = 1;
|
|
1384
1361
|
const DOCUMENT_POSITION_PRECEDING = 2;
|
|
1385
1362
|
const DOCUMENT_POSITION_FOLLOWING = 4;
|
|
1386
|
-
const DOCUMENT_POSITION_CONTAINS = 8;
|
|
1387
|
-
const DOCUMENT_POSITION_CONTAINED_BY = 16;
|
|
1388
1363
|
if (this === other) return 0;
|
|
1389
1364
|
let thisRoot = this;
|
|
1390
1365
|
while (thisRoot.parentNode) thisRoot = thisRoot.parentNode;
|
|
1391
1366
|
let otherRoot = other;
|
|
1392
1367
|
while (otherRoot.parentNode) otherRoot = otherRoot.parentNode;
|
|
1393
|
-
if (thisRoot !== otherRoot) return
|
|
1368
|
+
if (thisRoot !== otherRoot) return 3;
|
|
1394
1369
|
let node = other;
|
|
1395
1370
|
while (node) {
|
|
1396
|
-
if (node === this) return
|
|
1371
|
+
if (node === this) return 10;
|
|
1397
1372
|
node = node.parentNode;
|
|
1398
1373
|
}
|
|
1399
1374
|
node = this;
|
|
1400
1375
|
while (node) {
|
|
1401
|
-
if (node === other) return
|
|
1376
|
+
if (node === other) return 20;
|
|
1402
1377
|
node = node.parentNode;
|
|
1403
1378
|
}
|
|
1404
1379
|
const getAncestors = (n) => {
|
|
@@ -1426,16 +1401,16 @@ var MockNode = class {
|
|
|
1426
1401
|
return this.childNodes[0] || null;
|
|
1427
1402
|
}
|
|
1428
1403
|
insertBefore(newNode, referenceNode) {
|
|
1429
|
-
if (newNode.nodeType ===
|
|
1404
|
+
if (newNode.nodeType === 11) for (let i = 0, ii = newNode.childNodes.length; i < ii; i++) insertBefore(this, newNode.childNodes[i], referenceNode);
|
|
1430
1405
|
else insertBefore(this, newNode, referenceNode);
|
|
1431
1406
|
return newNode;
|
|
1432
1407
|
}
|
|
1433
1408
|
get isConnected() {
|
|
1434
1409
|
let node = this;
|
|
1435
1410
|
while (node != null) {
|
|
1436
|
-
if (node.nodeType ===
|
|
1411
|
+
if (node.nodeType === 9) return true;
|
|
1437
1412
|
node = node.parentNode;
|
|
1438
|
-
if (node != null && node.nodeType ===
|
|
1413
|
+
if (node != null && node.nodeType === 11) node = node.host;
|
|
1439
1414
|
}
|
|
1440
1415
|
return false;
|
|
1441
1416
|
}
|
|
@@ -1481,7 +1456,7 @@ var MockNode = class {
|
|
|
1481
1456
|
const index = this.childNodes.indexOf(childNode);
|
|
1482
1457
|
if (index > -1) {
|
|
1483
1458
|
this.childNodes.splice(index, 1);
|
|
1484
|
-
if (this.nodeType ===
|
|
1459
|
+
if (this.nodeType === 1) {
|
|
1485
1460
|
const wasConnected = this.isConnected;
|
|
1486
1461
|
childNode.parentNode = null;
|
|
1487
1462
|
if (wasConnected === true) disconnectNode(childNode);
|
|
@@ -1490,8 +1465,10 @@ var MockNode = class {
|
|
|
1490
1465
|
return childNode;
|
|
1491
1466
|
}
|
|
1492
1467
|
remove() {
|
|
1493
|
-
if (this.parentNode != null)
|
|
1494
|
-
|
|
1468
|
+
if (this.parentNode != null) {
|
|
1469
|
+
if (this.__parentNode) this.__parentNode.removeChild(this);
|
|
1470
|
+
else this.parentNode.removeChild(this);
|
|
1471
|
+
}
|
|
1495
1472
|
}
|
|
1496
1473
|
replaceChild(newChild, oldChild) {
|
|
1497
1474
|
if (oldChild.parentNode === this) {
|
|
@@ -1550,7 +1527,7 @@ var MockElement = class extends MockNode {
|
|
|
1550
1527
|
} });
|
|
1551
1528
|
}
|
|
1552
1529
|
constructor(ownerDocument, nodeName, namespaceURI = null) {
|
|
1553
|
-
super(ownerDocument,
|
|
1530
|
+
super(ownerDocument, 1, typeof nodeName === "string" ? nodeName : null, null);
|
|
1554
1531
|
this.__namespaceURI = namespaceURI;
|
|
1555
1532
|
this.__localName = typeof nodeName === "string" ? nodeName : null;
|
|
1556
1533
|
this.__shadowRoot = null;
|
|
@@ -1625,10 +1602,10 @@ var MockElement = class extends MockNode {
|
|
|
1625
1602
|
this.__attributeMap = attrs;
|
|
1626
1603
|
}
|
|
1627
1604
|
get children() {
|
|
1628
|
-
return this.childNodes.filter((n) => n.nodeType ===
|
|
1605
|
+
return this.childNodes.filter((n) => n.nodeType === 1);
|
|
1629
1606
|
}
|
|
1630
1607
|
get childElementCount() {
|
|
1631
|
-
return this.childNodes.filter((n) => n.nodeType ===
|
|
1608
|
+
return this.childNodes.filter((n) => n.nodeType === 1).length;
|
|
1632
1609
|
}
|
|
1633
1610
|
get className() {
|
|
1634
1611
|
return this.getAttributeNS(null, "class") || "";
|
|
@@ -1821,7 +1798,7 @@ var MockElement = class extends MockNode {
|
|
|
1821
1798
|
}
|
|
1822
1799
|
get nextElementSibling() {
|
|
1823
1800
|
const parentElement = this.parentElement;
|
|
1824
|
-
if (parentElement != null && (parentElement.nodeType ===
|
|
1801
|
+
if (parentElement != null && (parentElement.nodeType === 1 || parentElement.nodeType === 11 || parentElement.nodeType === 9)) {
|
|
1825
1802
|
const index = parentElement.children.indexOf(this) + 1;
|
|
1826
1803
|
return parentElement.children[index] || null;
|
|
1827
1804
|
}
|
|
@@ -1836,7 +1813,7 @@ var MockElement = class extends MockNode {
|
|
|
1836
1813
|
}
|
|
1837
1814
|
get previousElementSibling() {
|
|
1838
1815
|
const parentElement = this.parentElement;
|
|
1839
|
-
if (parentElement != null && (parentElement.nodeType ===
|
|
1816
|
+
if (parentElement != null && (parentElement.nodeType === 1 || parentElement.nodeType === 11 || parentElement.nodeType === 9)) {
|
|
1840
1817
|
const index = parentElement.children.indexOf(this) - 1;
|
|
1841
1818
|
return parentElement.children[index] || null;
|
|
1842
1819
|
}
|
|
@@ -1885,12 +1862,13 @@ var MockElement = class extends MockNode {
|
|
|
1885
1862
|
const attributes = this.attributes;
|
|
1886
1863
|
let attr = attributes.getNamedItem(attrName);
|
|
1887
1864
|
const checkAttrChanged = checkAttributeChanged(this);
|
|
1888
|
-
if (attr != null)
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1865
|
+
if (attr != null) {
|
|
1866
|
+
if (checkAttrChanged === true) {
|
|
1867
|
+
const oldValue = attr.value;
|
|
1868
|
+
attr.value = value;
|
|
1869
|
+
if (oldValue !== attr.value) attributeChanged(this, attr.name, oldValue, attr.value);
|
|
1870
|
+
} else attr.value = value;
|
|
1871
|
+
} else {
|
|
1894
1872
|
if (attributes.caseInsensitive) attrName = attrName.toLowerCase();
|
|
1895
1873
|
attr = new MockAttr(attrName, value);
|
|
1896
1874
|
attributes.__items.push(attr);
|
|
@@ -1912,12 +1890,13 @@ var MockElement = class extends MockNode {
|
|
|
1912
1890
|
}
|
|
1913
1891
|
let attr = attributes.getNamedItemNS(namespaceURI, localName);
|
|
1914
1892
|
const checkAttrChanged = checkAttributeChanged(this);
|
|
1915
|
-
if (attr != null)
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1893
|
+
if (attr != null) {
|
|
1894
|
+
if (checkAttrChanged === true) {
|
|
1895
|
+
const oldValue = attr.value;
|
|
1896
|
+
attr.value = value;
|
|
1897
|
+
if (oldValue !== attr.value) attributeChanged(this, attr.name, oldValue, attr.value);
|
|
1898
|
+
} else attr.value = value;
|
|
1899
|
+
} else {
|
|
1921
1900
|
attr = new MockAttr(localName, value, namespaceURI, prefix);
|
|
1922
1901
|
attributes.__items.push(attr);
|
|
1923
1902
|
if (checkAttrChanged === true) attributeChanged(this, attr.name, null, attr.value);
|
|
@@ -2095,7 +2074,7 @@ function insertBefore(parentNode, newNode, referenceNode) {
|
|
|
2095
2074
|
var MockHTMLElement = class extends MockElement {
|
|
2096
2075
|
__namespaceURI = "http://www.w3.org/1999/xhtml";
|
|
2097
2076
|
constructor(ownerDocument, nodeName) {
|
|
2098
|
-
super(ownerDocument,
|
|
2077
|
+
super(ownerDocument, nodeName ? nodeName.toUpperCase() : null);
|
|
2099
2078
|
}
|
|
2100
2079
|
get tagName() {
|
|
2101
2080
|
return this.nodeName ?? "";
|
|
@@ -2127,7 +2106,7 @@ var MockHTMLElement = class extends MockElement {
|
|
|
2127
2106
|
};
|
|
2128
2107
|
var MockTextNode = class MockTextNode extends MockNode {
|
|
2129
2108
|
constructor(ownerDocument, text) {
|
|
2130
|
-
super(ownerDocument,
|
|
2109
|
+
super(ownerDocument, 3, "#text", text);
|
|
2131
2110
|
}
|
|
2132
2111
|
cloneNode(_deep) {
|
|
2133
2112
|
return new MockTextNode(null, this.nodeValue);
|
|
@@ -2149,7 +2128,7 @@ var MockTextNode = class MockTextNode extends MockNode {
|
|
|
2149
2128
|
const text = [];
|
|
2150
2129
|
for (let i = 0, ii = this.parentNode.childNodes.length; i < ii; i++) {
|
|
2151
2130
|
const childNode = this.parentNode.childNodes[i];
|
|
2152
|
-
if (childNode.nodeType ===
|
|
2131
|
+
if (childNode.nodeType === 3) text.push(childNode.nodeValue);
|
|
2153
2132
|
}
|
|
2154
2133
|
return text.join("");
|
|
2155
2134
|
}
|
|
@@ -2159,8 +2138,8 @@ var MockTextNode = class MockTextNode extends MockNode {
|
|
|
2159
2138
|
function getTextContent(childNodes, text) {
|
|
2160
2139
|
for (let i = 0, ii = childNodes.length; i < ii; i++) {
|
|
2161
2140
|
const childNode = childNodes[i];
|
|
2162
|
-
if (childNode.nodeType ===
|
|
2163
|
-
else if (childNode.nodeType ===
|
|
2141
|
+
if (childNode.nodeType === 3) text.push(childNode.nodeValue);
|
|
2142
|
+
else if (childNode.nodeType === 1) getTextContent(childNode.childNodes, text);
|
|
2164
2143
|
}
|
|
2165
2144
|
}
|
|
2166
2145
|
function setTextContent(elm, text) {
|
|
@@ -2205,7 +2184,7 @@ function unmarkAsDispatching(target, eventType) {
|
|
|
2205
2184
|
//#region src/comment-node.ts
|
|
2206
2185
|
var MockComment = class MockComment extends MockNode {
|
|
2207
2186
|
constructor(ownerDocument, data) {
|
|
2208
|
-
super(ownerDocument,
|
|
2187
|
+
super(ownerDocument, 8, "#comment", data);
|
|
2209
2188
|
}
|
|
2210
2189
|
cloneNode(_deep) {
|
|
2211
2190
|
return new MockComment(null, this.nodeValue);
|
|
@@ -2229,7 +2208,7 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
2229
2208
|
global.NW.Dom = factory(global, Export);
|
|
2230
2209
|
}
|
|
2231
2210
|
})(exports, function Factory(global, Export) {
|
|
2232
|
-
var version = "nwsapi-2.2.
|
|
2211
|
+
var version = "nwsapi-2.2.24", doc = global.document, root = doc.documentElement, slice = Array.prototype.slice, HSP = "\\x20\\t", VSP = "\\r\\n\\f", WSP = "[" + HSP + VSP + "]", CFG = {
|
|
2233
2212
|
operators: "[~*^$|]=|=",
|
|
2234
2213
|
combinators: "[\\x20\\t>+~](?=[^>+~])"
|
|
2235
2214
|
}, NOT = {
|
|
@@ -2254,9 +2233,9 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
2254
2233
|
apimethods: RegExp("^(?:\\w+|\\*)\\|"),
|
|
2255
2234
|
namespaces: RegExp("(\\*|\\w+)\\|[\\w-]+")
|
|
2256
2235
|
}, GROUPS = {
|
|
2257
|
-
linguistic: "(dir|lang)(?:\\x28\\s?([-\\w]{2,})\\s
|
|
2258
|
-
logicalsel: "(is|where|matches|not|has)(?:\\x28\\s?([^()]*|.*)\\s
|
|
2259
|
-
treestruct: "(nth(?:-last)?(?:-child|-of\\-type))(?:\\x28\\s?(even|odd|(?:[-+]?\\d*)(?:n\\s?[-+]?\\s?\\d*)?)\\s
|
|
2236
|
+
linguistic: "(dir|lang)(?:\\x28\\s?([-\\w]{2,})\\s?(?:\\x29|$))",
|
|
2237
|
+
logicalsel: "(is|where|matches|not|has)(?:\\x28\\s?([^()]*|.*)\\s?(?:\\x29|$))",
|
|
2238
|
+
treestruct: "(nth(?:-last)?(?:-child|-of\\-type))(?:\\x28\\s?(even|odd|(?:[-+]?\\d*)(?:n\\s?[-+]?\\s?\\d*)?)\\s?(?:\\x29|$))",
|
|
2260
2239
|
locationpc: "(any\\-link|link|visited|target|defined)\\b",
|
|
2261
2240
|
useraction: "(hover|active|focus\\-within|focus\\-visible|focus)\\b",
|
|
2262
2241
|
structural: "(scope|root|empty|(?:(?:first|last|only)(?:-child|\\-of\\-type)))\\b",
|
|
@@ -2455,7 +2434,7 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
2455
2434
|
if (codePoint < 1 || codePoint > 1114111 || codePoint > 55295 && codePoint < 57344) return "�";
|
|
2456
2435
|
if (codePoint < 65536) return String.fromCharCode(codePoint);
|
|
2457
2436
|
return String.fromCodePoint ? String.fromCodePoint(codePoint) : String.fromCharCode((codePoint - 65536 >> 10) + 55296, (codePoint - 65536) % 1024 + 56320);
|
|
2458
|
-
},
|
|
2437
|
+
}, escapeIdentifier = function(str) {
|
|
2459
2438
|
return REX.HasEscapes.test(str) ? str.replace(REX.FixEscapes, function(substring, p1, p2) {
|
|
2460
2439
|
return p2 ? "\\" + p2 : REX.HexNumbers.test(p1) ? codePointToUTF16(parseInt(p1, 16)) : REX.EscOrQuote.test(p1) ? substring : p1;
|
|
2461
2440
|
}) : str;
|
|
@@ -2485,12 +2464,14 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
2485
2464
|
var e, i, l, nodes, api = method["#"];
|
|
2486
2465
|
if (Config.IDS_DUPES === false) {
|
|
2487
2466
|
if (api in context) return (e = context[api](id)) ? [e] : none;
|
|
2488
|
-
} else if ("all" in context)
|
|
2489
|
-
if (e
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2467
|
+
} else if ("all" in context) {
|
|
2468
|
+
if (e = context.all[id]) {
|
|
2469
|
+
if (e.nodeType == 1) return e.getAttribute("id") != id ? [] : [e];
|
|
2470
|
+
else if (id == "length") return (e = context[api](id)) ? [e] : none;
|
|
2471
|
+
for (i = 0, l = e.length, nodes = []; l > i; ++i) if (e[i].id == id) nodes[nodes.length] = e[i];
|
|
2472
|
+
return nodes && nodes.length ? nodes : [nodes];
|
|
2473
|
+
} else return none;
|
|
2474
|
+
}
|
|
2494
2475
|
return byIdRaw(id, context);
|
|
2495
2476
|
}, byTagNS = function(context, tag) {
|
|
2496
2477
|
return byTag(tag, context);
|
|
@@ -2499,15 +2480,16 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
2499
2480
|
if (api in context) return slice.call(context[api](tag));
|
|
2500
2481
|
else {
|
|
2501
2482
|
tag = tag.toLowerCase();
|
|
2502
|
-
if (e = context.firstElementChild)
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2483
|
+
if (e = context.firstElementChild) {
|
|
2484
|
+
if (!(e.nextElementSibling || tag == "*" || e.localName == tag)) return slice.call(e[api](tag));
|
|
2485
|
+
else {
|
|
2486
|
+
nodes = [];
|
|
2487
|
+
do {
|
|
2488
|
+
if (tag == "*" || e.localName == tag) nodes[nodes.length] = e;
|
|
2489
|
+
concatList(nodes, e[api](tag));
|
|
2490
|
+
} while (e = e.nextElementSibling);
|
|
2491
|
+
}
|
|
2492
|
+
} else nodes = none;
|
|
2511
2493
|
}
|
|
2512
2494
|
return !Config.NODE_LIST ? nodes : isInstanceOf(nodes) ? nodes : toNodeList(nodes);
|
|
2513
2495
|
}, byClass = function(cls, context) {
|
|
@@ -2699,7 +2681,7 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
2699
2681
|
setIdentifierSyntax();
|
|
2700
2682
|
lastContext = switchContext(doc, true);
|
|
2701
2683
|
}, setIdentifierSyntax = function() {
|
|
2702
|
-
var
|
|
2684
|
+
var identifier = "(?:-|--|\\\\[0-9a-fA-F]{1,6}[" + HSP + "]?|\\\\[^" + VSP + "]|[^\\x00-\\x9f]|[\\w-])+", pseudonames = "[-\\w]+", pseudoparms = "(?:[-+]?\\d*)(?:n\\s?[-+]?\\s?\\d*)", attrparser = identifier + "|\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*(?:\"|$)|'[^'\\\\]*(?:\\\\.[^'\\\\]*)*(?:'|$)", attrvalues = "([\\x22\\x27]?)((?!\\3)*|(?:\\\\?.)*?)(?:\\3|$)", attributes = "\\[(?:\\*\\|)?" + WSP + "?(" + identifier + "(?::" + identifier + ")?)" + WSP + "?(?:(" + CFG.operators + ")" + WSP + "?(?:" + attrparser + "))?(?:" + WSP + "?\\b(i))?" + WSP + "?(?:\\]|$)", attrmatcher = attributes.replace(attrparser, attrvalues), pseudoclass = "(?:\\x28" + WSP + "*(?:" + pseudoparms + "?)?|(?:\\*|\\*\\|)|(?:(?::" + pseudonames + "(?:\\x28" + pseudoparms + "?(?:\\x29|$))?|)|(?:[.#]?" + identifier + ")|(?:" + attributes + "))+|(?:" + WSP + "?[>+~][^>+~]" + WSP + "?)|(?:" + WSP + "?," + WSP + "?)|(?:" + WSP + "?)|(?:\\x29|$))*", standardValidator = "(?=" + WSP + "?[^>+~(){}<>])(?:(?:\\*|\\*\\|)|(?:[.#]?" + identifier + ")+|(?:" + attributes + ")+|(?:::?" + pseudonames + pseudoclass + ")|(?:" + WSP + "?" + CFG.combinators + WSP + "?)|(?:" + WSP + "?," + WSP + "?)|(?:" + WSP + "?))+";
|
|
2703
2685
|
reOptimizer = RegExp("(?:([.:#*]?)(" + identifier + ")(?::[-\\w]+|\\[[^\\]]+(?:\\]|$)|\\x28[^\\x29]+(?:\\x29|$))*)$");
|
|
2704
2686
|
reValidator = RegExp(standardValidator, "g");
|
|
2705
2687
|
Patterns.id = RegExp("^#(" + identifier + ")(.*)");
|
|
@@ -2726,8 +2708,6 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
2726
2708
|
macro = N_BODY + (callback ? N_TEST : "") + N_TAIL;
|
|
2727
2709
|
head = N_HEAD;
|
|
2728
2710
|
loop = N_LOOP;
|
|
2729
|
-
break;
|
|
2730
|
-
default: break;
|
|
2731
2711
|
}
|
|
2732
2712
|
source = compileSelector(selector, macro, mode, callback);
|
|
2733
2713
|
loop += mode || mode === null ? "{" + source + "}" : source;
|
|
@@ -2744,9 +2724,10 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
2744
2724
|
factory = Function("s", F_INIT + "{" + head + vars + ";" + loop + "return r;}")(Snapshot);
|
|
2745
2725
|
return mode || mode === null ? selectLambdas[selector] = factory : matchLambdas[selector] = factory;
|
|
2746
2726
|
}, compileSelector = function(expression, source, mode, callback) {
|
|
2747
|
-
var a, b, n, f, name, NS, compat, expr, match, result, status, symbol, test, type, selector = expression, vars;
|
|
2727
|
+
var a, b, n, f, k = 0, name, NS, compat, expr, match, result, status, symbol, test, type, selector = expression, vars;
|
|
2748
2728
|
selector = selector.replace(STD.combinator, "$1");
|
|
2749
2729
|
selector_recursion_label: while (selector) {
|
|
2730
|
+
++k;
|
|
2750
2731
|
symbol = STD.apimethods.test(selector) ? "|" : selector[0];
|
|
2751
2732
|
switch (symbol) {
|
|
2752
2733
|
case "*":
|
|
@@ -2792,26 +2773,26 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
2792
2773
|
p3: "true"
|
|
2793
2774
|
} : test;
|
|
2794
2775
|
else if (match[2] == "~=" && match[4].includes(" ")) break;
|
|
2795
|
-
else if (match[4]) match[4] =
|
|
2776
|
+
else if (match[4]) match[4] = escapeIdentifier(match[4]).replace(REX.RegExpChar, "\\$&");
|
|
2796
2777
|
type = match[5] == "i" || HTML_DOCUMENT && HTML_TABLE[expr.toLowerCase()] ? "i" : "";
|
|
2797
2778
|
source = "if((" + (!match[2] ? NS ? "s.hasAttributeNS(e,\"" + name + "\")" : "e.hasAttribute&&e.hasAttribute(\"" + name + "\")" : !match[4] && ATTR_STD_OPS[match[2]] && match[2] != "~=" ? "e.getAttribute&&e.getAttribute(\"" + name + "\")==\"\"" : "(/" + test.p1 + match[4] + test.p2 + "/" + type + ").test(e.getAttribute&&e.getAttribute(\"" + name + "\"))==" + test.p3) + ")){" + source + "}";
|
|
2798
2779
|
break;
|
|
2799
2780
|
case "~":
|
|
2800
2781
|
match = selector.match(Patterns.relative);
|
|
2801
|
-
source = "while(e&&(e=e.previousElementSibling)){" + source + "}";
|
|
2782
|
+
source = "var N" + k + "=e;while(e&&(e=e.previousElementSibling)){" + source + "}e=N" + k + ";";
|
|
2802
2783
|
break;
|
|
2803
2784
|
case "+":
|
|
2804
2785
|
match = selector.match(Patterns.adjacent);
|
|
2805
|
-
source = "if(e&&(e=e.previousElementSibling)){" + source + "}";
|
|
2786
|
+
source = "var N" + k + "=e;if(e&&(e=e.previousElementSibling)){" + source + "}e=N" + k + ";";
|
|
2806
2787
|
break;
|
|
2807
2788
|
case " ":
|
|
2808
2789
|
case " ":
|
|
2809
2790
|
match = selector.match(Patterns.ancestor);
|
|
2810
|
-
source = "while(e&&(e=e.parentElement)){" + source + "}";
|
|
2791
|
+
source = "var N" + k + "=e;while(e&&(e=e.parentElement)){" + source + "}e=N" + k + ";";
|
|
2811
2792
|
break;
|
|
2812
2793
|
case ">":
|
|
2813
2794
|
match = selector.match(Patterns.children);
|
|
2814
|
-
source = "if(e&&(e=e.parentElement)){" + source + "}";
|
|
2795
|
+
source = "var N" + k + "=e;if(e&&(e=e.parentElement)){" + source + "}e=N" + k + ";";
|
|
2815
2796
|
break;
|
|
2816
2797
|
case symbol in Combinators ? symbol : void 0:
|
|
2817
2798
|
match[match.length - 1] = "*";
|
|
@@ -2848,9 +2829,7 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
2848
2829
|
case "first-of-type":
|
|
2849
2830
|
source = "n=e;o=e.localName;while((n=n.previousElementSibling)&&n.localName!=o);if(!n){" + source + "}";
|
|
2850
2831
|
break;
|
|
2851
|
-
default:
|
|
2852
|
-
emit("'" + expression + "'" + qsInvalid);
|
|
2853
|
-
break;
|
|
2832
|
+
default: emit("'" + expression + "'" + qsInvalid);
|
|
2854
2833
|
}
|
|
2855
2834
|
} else if (match = selector.match(Patterns.treestruct)) {
|
|
2856
2835
|
match[1] = match[1].toLowerCase();
|
|
@@ -2886,9 +2865,7 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
2886
2865
|
source = "n=s.nth" + expr + "(e," + type + ");if((" + test + ")){" + source + "}";
|
|
2887
2866
|
} else emit("'" + expression + "'" + qsInvalid);
|
|
2888
2867
|
break;
|
|
2889
|
-
default:
|
|
2890
|
-
emit("'" + expression + "'" + qsInvalid);
|
|
2891
|
-
break;
|
|
2868
|
+
default: emit("'" + expression + "'" + qsInvalid);
|
|
2892
2869
|
}
|
|
2893
2870
|
} else if (match = selector.match(Patterns.logicalsel)) {
|
|
2894
2871
|
match[1] = match[1].toLowerCase();
|
|
@@ -2907,11 +2884,9 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
2907
2884
|
break;
|
|
2908
2885
|
case "has":
|
|
2909
2886
|
if (/^\s*(\+|\~)/.test(match[2])) source = "if(e.parentElement&&Array.from(e.parentElement" + (/^\s*[+]/.test(match[2]) ? ".querySelectorAll(\"*" + expr + "\")" : ".children") + ").includes(e.nextElementSibling)){" + source + "}";
|
|
2910
|
-
else source = "if(
|
|
2911
|
-
break;
|
|
2912
|
-
default:
|
|
2913
|
-
emit("'" + expression + "'" + qsInvalid);
|
|
2887
|
+
else source = "if(s.first(\":scope " + expr + "\",e)){" + source + "}";
|
|
2914
2888
|
break;
|
|
2889
|
+
default: emit("'" + expression + "'" + qsInvalid);
|
|
2915
2890
|
}
|
|
2916
2891
|
} else if (match = selector.match(Patterns.linguistic)) {
|
|
2917
2892
|
match[1] = match[1].toLowerCase();
|
|
@@ -2923,9 +2898,7 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
2923
2898
|
expr = "(?:^|-)" + match[2] + "(?:-|$)";
|
|
2924
2899
|
source = "var p;if(((e.isConnected&&(e.lang==\"\"&&(p=s.ancestor(\"[lang]\",e)))&&(p.lang==\"" + match[2] + "\")||/" + expr + "/i.test(e.lang)))){" + source + "};";
|
|
2925
2900
|
break;
|
|
2926
|
-
default:
|
|
2927
|
-
emit("'" + expression + "'" + qsInvalid);
|
|
2928
|
-
break;
|
|
2901
|
+
default: emit("'" + expression + "'" + qsInvalid);
|
|
2929
2902
|
}
|
|
2930
2903
|
} else if (match = selector.match(Patterns.locationpc)) {
|
|
2931
2904
|
match[1] = match[1].toLowerCase();
|
|
@@ -2945,9 +2918,7 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
2945
2918
|
case "defined":
|
|
2946
2919
|
source = "n=s.doc.defaultView.customElements.get(e.localName);if(n&&e instanceof n){" + source + "}";
|
|
2947
2920
|
break;
|
|
2948
|
-
default:
|
|
2949
|
-
emit("'" + expression + "'" + qsInvalid);
|
|
2950
|
-
break;
|
|
2921
|
+
default: emit("'" + expression + "'" + qsInvalid);
|
|
2951
2922
|
}
|
|
2952
2923
|
} else if (match = selector.match(Patterns.useraction)) {
|
|
2953
2924
|
match[1] = match[1].toLowerCase();
|
|
@@ -2967,9 +2938,7 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
2967
2938
|
case "focus-within":
|
|
2968
2939
|
source = "if(n=s.isFocusable(e)){if(n!==e){while(n){n=n.parentElement;if(n===e)break;}}}if((n===e||n.autofocus)){" + source + "}";
|
|
2969
2940
|
break;
|
|
2970
|
-
default:
|
|
2971
|
-
emit("'" + expression + "'" + qsInvalid);
|
|
2972
|
-
break;
|
|
2941
|
+
default: emit("'" + expression + "'" + qsInvalid);
|
|
2973
2942
|
}
|
|
2974
2943
|
} else if (match = selector.match(Patterns.inputstate)) {
|
|
2975
2944
|
match[1] = match[1].toLowerCase();
|
|
@@ -2992,9 +2961,7 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
2992
2961
|
case "default":
|
|
2993
2962
|
source = "if((\"form\" in e && e.form)){var x=0;n=[];if(e.type==\"image\")n=e.form.getElementsByTagName(\"input\");if(e.type==\"submit\")n=e.form.elements;while(n[x]&&e!==n[x]){if(n[x].type==\"image\")break;if(n[x].type==\"submit\")break;x++;}}if((e.form&&(e===n[x]&&\"|image|submit|\".includes(\"|\"+e.type+\"|\"))||((/^option$/i.test(e.localName))&&e.defaultSelected)||((\"|radio|checkbox|\".includes(\"|\"+e.type+\"|\"))&&e.defaultChecked))){" + source + "}";
|
|
2994
2963
|
break;
|
|
2995
|
-
default:
|
|
2996
|
-
emit("'" + expression + "'" + qsInvalid);
|
|
2997
|
-
break;
|
|
2964
|
+
default: emit("'" + expression + "'" + qsInvalid);
|
|
2998
2965
|
}
|
|
2999
2966
|
} else if (match = selector.match(Patterns.inputvalue)) {
|
|
3000
2967
|
match[1] = match[1].toLowerCase();
|
|
@@ -3023,9 +2990,7 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
3023
2990
|
case "out-of-range":
|
|
3024
2991
|
source = "if((/^input$/i.test(e.localName))&&(e.willValidate&&!e.formNoValidate)&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(\"|date|datetime-local|month|number|range|time|week|\".includes(\"|\"+e.type+\"|\"))&&(\"range\"==e.type||e.getAttribute(\"min\")||e.getAttribute(\"max\"))){" + source + "}";
|
|
3025
2992
|
break;
|
|
3026
|
-
default:
|
|
3027
|
-
emit("'" + expression + "'" + qsInvalid);
|
|
3028
|
-
break;
|
|
2993
|
+
default: emit("'" + expression + "'" + qsInvalid);
|
|
3029
2994
|
}
|
|
3030
2995
|
} else if (match = selector.match(Patterns.rsrc_state)) {
|
|
3031
2996
|
match[1] = match[1].toLowerCase();
|
|
@@ -3041,11 +3006,7 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
3041
3006
|
break;
|
|
3042
3007
|
case "buffering": break;
|
|
3043
3008
|
case "stalled": break;
|
|
3044
|
-
case "muted":
|
|
3045
|
-
source = "if(e.localName==\"audio\"&&e.getAttribute(\"muted\")){" + source + "}";
|
|
3046
|
-
break;
|
|
3047
|
-
case "volume-locked": break;
|
|
3048
|
-
default: break;
|
|
3009
|
+
case "muted": source = "if(e.localName==\"audio\"&&e.getAttribute(\"muted\")){" + source + "}";
|
|
3049
3010
|
}
|
|
3050
3011
|
} else if (match = selector.match(Patterns.pseudo_nop)) break;
|
|
3051
3012
|
else if (match = selector.match(Patterns.pseudo_sng)) source = "if(e.element&&e.type.toLowerCase()==\":" + match[0].toLowerCase() + "\"){e=e.element;" + source + "}";
|
|
@@ -3089,7 +3050,7 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
3089
3050
|
return source;
|
|
3090
3051
|
}, makeref = function(selectors, element) {
|
|
3091
3052
|
if (element.nodeType === 9) element = element.documentElement;
|
|
3092
|
-
return selectors.replace(/:scope/i, element.localName + (element.id ? "#" +
|
|
3053
|
+
return selectors.replace(/:scope/i, element.localName + (element.id ? "#" + escapeIdentifier(element.id) : "") + (element.className ? "." + escapeIdentifier(element.classList[0]) : ""));
|
|
3093
3054
|
}, ancestor = function _closest(selectors, element, callback) {
|
|
3094
3055
|
parse(selectors, true);
|
|
3095
3056
|
selectors = makeref(selectors, element);
|
|
@@ -3112,10 +3073,12 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
3112
3073
|
} else if (arguments[0] === "") {
|
|
3113
3074
|
emit("''" + qsInvalid);
|
|
3114
3075
|
return Config.VERBOSITY ? void 0 : type ? none : false;
|
|
3076
|
+
} else if (/^[.#]?\d/.test(selectors)) {
|
|
3077
|
+
emit("''" + qsInvalid);
|
|
3078
|
+
return Config.VERBOSITY ? void 0 : type ? none : false;
|
|
3115
3079
|
}
|
|
3116
3080
|
if (typeof selectors != "string") selectors = "" + selectors;
|
|
3117
|
-
|
|
3118
|
-
parsed = unescape(selectors).replace(/\x00|\\$/g, "�").replace(REX.CombineWSP, " ").replace(REX.PseudosWSP, "$1").replace(REX.TabCharWSP, " ").replace(REX.CommaGroup, ",").replace(REX.TrimSpaces, "");
|
|
3081
|
+
parsed = selectors.replace(/\x00|\\$/g, "�").replace(REX.CombineWSP, " ").replace(REX.PseudosWSP, "$1").replace(REX.TabCharWSP, " ").replace(REX.CommaGroup, ",").replace(REX.TrimSpaces, "");
|
|
3119
3082
|
if ((selectors = parsed.match(reValidator)) && selectors.join("") == parsed) {
|
|
3120
3083
|
selectors = parsed.match(REX.SplitGroup);
|
|
3121
3084
|
if (parsed[parsed.length - 1] == ",") {
|
|
@@ -3286,6 +3249,7 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
3286
3249
|
byTag,
|
|
3287
3250
|
first,
|
|
3288
3251
|
match,
|
|
3252
|
+
select,
|
|
3289
3253
|
ancestor,
|
|
3290
3254
|
nthOfType,
|
|
3291
3255
|
nthElement,
|
|
@@ -3307,8 +3271,8 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
3307
3271
|
byId,
|
|
3308
3272
|
byTag,
|
|
3309
3273
|
byClass,
|
|
3310
|
-
match,
|
|
3311
3274
|
first,
|
|
3275
|
+
match,
|
|
3312
3276
|
select,
|
|
3313
3277
|
closest: ancestor,
|
|
3314
3278
|
compile,
|
|
@@ -3360,8 +3324,8 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
3360
3324
|
var MockDocumentFragment = class MockDocumentFragment extends MockHTMLElement {
|
|
3361
3325
|
constructor(ownerDocument) {
|
|
3362
3326
|
super(ownerDocument, null);
|
|
3363
|
-
this.nodeName =
|
|
3364
|
-
this.nodeType =
|
|
3327
|
+
this.nodeName = "#document-fragment";
|
|
3328
|
+
this.nodeType = 11;
|
|
3365
3329
|
}
|
|
3366
3330
|
getElementById(id) {
|
|
3367
3331
|
return getElementById(this, id);
|
|
@@ -3376,7 +3340,7 @@ var MockDocumentFragment = class MockDocumentFragment extends MockHTMLElement {
|
|
|
3376
3340
|
const cloned = new MockDocumentFragment(null);
|
|
3377
3341
|
if (deep) for (let i = 0, ii = this.childNodes.length; i < ii; i++) {
|
|
3378
3342
|
const childNode = this.childNodes[i];
|
|
3379
|
-
if (childNode.nodeType ===
|
|
3343
|
+
if (childNode.nodeType === 1 || childNode.nodeType === 3 || childNode.nodeType === 8) {
|
|
3380
3344
|
const clonedChildNode = this.childNodes[i].cloneNode(true);
|
|
3381
3345
|
cloned.appendChild(clonedChildNode);
|
|
3382
3346
|
}
|
|
@@ -3389,13 +3353,14 @@ var MockDocumentFragment = class MockDocumentFragment extends MockHTMLElement {
|
|
|
3389
3353
|
var MockDocumentTypeNode = class extends MockHTMLElement {
|
|
3390
3354
|
constructor(ownerDocument) {
|
|
3391
3355
|
super(ownerDocument, "!DOCTYPE");
|
|
3392
|
-
this.nodeType =
|
|
3356
|
+
this.nodeType = 10;
|
|
3393
3357
|
this.setAttribute("html", "");
|
|
3394
3358
|
}
|
|
3395
3359
|
};
|
|
3396
3360
|
//#endregion
|
|
3397
3361
|
//#region src/css-style-sheet.ts
|
|
3398
3362
|
var MockCSSRule = class {
|
|
3363
|
+
parentStyleSheet;
|
|
3399
3364
|
cssText = "";
|
|
3400
3365
|
type = 0;
|
|
3401
3366
|
constructor(parentStyleSheet) {
|
|
@@ -3883,8 +3848,8 @@ var MockSlotElement = class MockSlotElement extends MockHTMLElement {
|
|
|
3883
3848
|
const ownerHost = this.getRootNode().host;
|
|
3884
3849
|
if (!ownerHost) return nodesToReturn;
|
|
3885
3850
|
if (ownerHost.childNodes.length) {
|
|
3886
|
-
if (this.name) nodesToReturn = ownerHost.childNodes.filter((n) => n.nodeType ===
|
|
3887
|
-
else nodesToReturn = ownerHost.childNodes.filter((n) => n.nodeType ===
|
|
3851
|
+
if (this.name) nodesToReturn = ownerHost.childNodes.filter((n) => n.nodeType === 1 && n.getAttribute("slot") === this.name);
|
|
3852
|
+
else nodesToReturn = ownerHost.childNodes.filter((n) => n.nodeType === 1 && !n.getAttribute("slot") || n.nodeType !== 1);
|
|
3888
3853
|
if (nodesToReturn.length) return nodesToReturn;
|
|
3889
3854
|
}
|
|
3890
3855
|
if (!opts?.flatten) return this.childNodes.filter((n) => !(n instanceof MockSlotElement));
|
|
@@ -4234,11 +4199,13 @@ function createConsole() {
|
|
|
4234
4199
|
var MockHeaders = class {
|
|
4235
4200
|
_values = [];
|
|
4236
4201
|
constructor(init) {
|
|
4237
|
-
if (typeof init === "object")
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4202
|
+
if (typeof init === "object") {
|
|
4203
|
+
if (typeof init[Symbol.iterator] === "function") {
|
|
4204
|
+
const kvs = [];
|
|
4205
|
+
for (const kv of init) if (typeof kv[Symbol.iterator] === "function") kvs.push([...kv]);
|
|
4206
|
+
for (const kv of kvs) this.append(kv[0], kv[1]);
|
|
4207
|
+
} else for (const key in init) this.append(key, init[key]);
|
|
4208
|
+
}
|
|
4242
4209
|
}
|
|
4243
4210
|
append(key, value) {
|
|
4244
4211
|
this._values.push([key, value + ""]);
|
|
@@ -5317,8 +5284,8 @@ var MockDocument = class MockDocument extends MockHTMLElement {
|
|
|
5317
5284
|
#nwsapi = null;
|
|
5318
5285
|
constructor(html = null, win = null) {
|
|
5319
5286
|
super(null, null);
|
|
5320
|
-
this.nodeName =
|
|
5321
|
-
this.nodeType =
|
|
5287
|
+
this.nodeName = "#document";
|
|
5288
|
+
this.nodeType = 9;
|
|
5322
5289
|
this.defaultView = win;
|
|
5323
5290
|
this.cookie = "";
|
|
5324
5291
|
this.referrer = "";
|
|
@@ -5409,7 +5376,7 @@ var MockDocument = class MockDocument extends MockHTMLElement {
|
|
|
5409
5376
|
return documentElement;
|
|
5410
5377
|
}
|
|
5411
5378
|
set documentElement(documentElement) {
|
|
5412
|
-
for (let i = this.childNodes.length - 1; i >= 0; i--) if (this.childNodes[i].nodeType !==
|
|
5379
|
+
for (let i = this.childNodes.length - 1; i >= 0; i--) if (this.childNodes[i].nodeType !== 10) this.childNodes[i].remove();
|
|
5413
5380
|
if (documentElement != null) {
|
|
5414
5381
|
this.appendChild(documentElement);
|
|
5415
5382
|
setOwnerDocument(documentElement, this);
|
|
@@ -5461,7 +5428,7 @@ var MockDocument = class MockDocument extends MockHTMLElement {
|
|
|
5461
5428
|
return new MockAttr(attrName, "", namespaceURI);
|
|
5462
5429
|
}
|
|
5463
5430
|
createElement(tagName) {
|
|
5464
|
-
if (tagName ===
|
|
5431
|
+
if (tagName === "#document") {
|
|
5465
5432
|
const doc = new MockDocument(false);
|
|
5466
5433
|
doc.nodeName = tagName;
|
|
5467
5434
|
doc.parentNode = null;
|
|
@@ -5533,10 +5500,10 @@ function resetDocument(doc) {
|
|
|
5533
5500
|
}
|
|
5534
5501
|
for (const key in doc) if (doc.hasOwnProperty(key) && !DOC_KEY_KEEPERS.has(key)) delete doc[key];
|
|
5535
5502
|
try {
|
|
5536
|
-
doc.nodeName =
|
|
5503
|
+
doc.nodeName = "#document";
|
|
5537
5504
|
} catch {}
|
|
5538
5505
|
try {
|
|
5539
|
-
doc.nodeType =
|
|
5506
|
+
doc.nodeType = 9;
|
|
5540
5507
|
} catch {}
|
|
5541
5508
|
try {
|
|
5542
5509
|
doc.cookie = "";
|
|
@@ -5546,7 +5513,7 @@ function resetDocument(doc) {
|
|
|
5546
5513
|
} catch {}
|
|
5547
5514
|
}
|
|
5548
5515
|
}
|
|
5549
|
-
const DOC_KEY_KEEPERS = new Set([
|
|
5516
|
+
const DOC_KEY_KEEPERS = /* @__PURE__ */ new Set([
|
|
5550
5517
|
"nodeName",
|
|
5551
5518
|
"nodeType",
|
|
5552
5519
|
"nodeValue",
|
|
@@ -5580,7 +5547,7 @@ function getElementsByName(elm, elmName, foundElms = []) {
|
|
|
5580
5547
|
function setOwnerDocument(elm, ownerDocument) {
|
|
5581
5548
|
for (let i = 0, ii = elm.childNodes.length; i < ii; i++) {
|
|
5582
5549
|
elm.childNodes[i].ownerDocument = ownerDocument;
|
|
5583
|
-
if (elm.childNodes[i].nodeType ===
|
|
5550
|
+
if (elm.childNodes[i].nodeType === 1) setOwnerDocument(elm.childNodes[i], ownerDocument);
|
|
5584
5551
|
}
|
|
5585
5552
|
}
|
|
5586
5553
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stencil/mock-doc",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.31",
|
|
4
4
|
"description": "A minimal mock DOM implementation for SSR and testing",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dom",
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"nwsapi": "^2.2.
|
|
36
|
-
"parse5": "
|
|
35
|
+
"nwsapi": "^2.2.24",
|
|
36
|
+
"parse5": "^8.0.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@stencil/vitest": "^1.
|
|
40
|
-
"tsdown": "^0.
|
|
41
|
-
"typescript": "
|
|
42
|
-
"vitest": "^4.1.
|
|
39
|
+
"@stencil/vitest": "^1.14.0",
|
|
40
|
+
"tsdown": "^0.22.14",
|
|
41
|
+
"typescript": ">5.0.0 <7.0.0",
|
|
42
|
+
"vitest": "^4.1.10"
|
|
43
43
|
},
|
|
44
44
|
"volta": {
|
|
45
45
|
"extends": "../../package.json"
|
/package/{LICENSE.md → LICENSE}
RENAMED
|
File without changes
|