@stencil/mock-doc 5.0.0-alpha.2 → 5.0.0-alpha.21
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 +7 -3
- package/dist/index.mjs +77 -97
- package/package.json +7 -7
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
|
@@ -164,12 +164,16 @@ declare class MockResizeObserver {
|
|
|
164
164
|
//#endregion
|
|
165
165
|
//#region src/shadow-root.d.ts
|
|
166
166
|
declare class MockShadowRoot extends MockDocumentFragment {
|
|
167
|
+
private _mode;
|
|
168
|
+
private _delegatesFocus;
|
|
167
169
|
get activeElement(): HTMLElement | null;
|
|
168
170
|
get cloneable(): boolean;
|
|
169
171
|
get delegatesFocus(): boolean;
|
|
172
|
+
set delegatesFocus(value: boolean);
|
|
170
173
|
get fullscreenElement(): HTMLElement | null;
|
|
171
174
|
get host(): HTMLElement | null;
|
|
172
175
|
get mode(): 'open' | 'closed';
|
|
176
|
+
set mode(value: 'open' | 'closed');
|
|
173
177
|
get pictureInPictureElement(): HTMLElement | null;
|
|
174
178
|
get pointerLockElement(): HTMLElement | null;
|
|
175
179
|
get serializable(): boolean;
|
|
@@ -215,7 +219,7 @@ declare class MockWindow {
|
|
|
215
219
|
__allowInterval: boolean;
|
|
216
220
|
URL: typeof URL;
|
|
217
221
|
console: Console;
|
|
218
|
-
customElements: CustomElementRegistry;
|
|
222
|
+
customElements: CustomElementRegistry | null;
|
|
219
223
|
document: Document;
|
|
220
224
|
performance: Performance;
|
|
221
225
|
devicePixelRatio: number;
|
|
@@ -429,7 +433,7 @@ declare class MockWindow {
|
|
|
429
433
|
onwebkitfullscreenerror(): void;
|
|
430
434
|
onwheel(): void;
|
|
431
435
|
}
|
|
432
|
-
declare function cloneWindow(srcWin: Window, opts?: {
|
|
436
|
+
declare function cloneWindow(srcWin: Window | MockWindow, opts?: {
|
|
433
437
|
customElementProxy?: boolean;
|
|
434
438
|
}): MockWindow | null;
|
|
435
439
|
declare function cloneDocument(srcDoc: Document): Document;
|
|
@@ -438,7 +442,7 @@ declare function cloneDocument(srcDoc: Document): Document;
|
|
|
438
442
|
* only allow setInterval() to fire once, also constrained to 1ms.
|
|
439
443
|
* @param win the mock window instance to update
|
|
440
444
|
*/
|
|
441
|
-
declare function constrainTimeouts(win:
|
|
445
|
+
declare function constrainTimeouts(win: MockWindow): void;
|
|
442
446
|
//#endregion
|
|
443
447
|
//#region src/event.d.ts
|
|
444
448
|
declare class MockEvent {
|
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];
|
|
@@ -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;
|
|
@@ -988,7 +983,7 @@ function* streamToHtml(node, opts, output) {
|
|
|
988
983
|
yield* streamToHtml(shadowRoot, opts, output);
|
|
989
984
|
output.indent = output.indent - (opts.indentSpaces ?? 0);
|
|
990
985
|
const childNodes = getChildNodes(node);
|
|
991
|
-
if (opts.newLines && (childNodes.length === 0 || childNodes.length === 1 && childNodes[0].nodeType ===
|
|
986
|
+
if (opts.newLines && (childNodes.length === 0 || childNodes.length === 1 && childNodes[0].nodeType === 3 && childNodes[0].nodeValue?.trim() === "")) {
|
|
992
987
|
yield "\n";
|
|
993
988
|
output.currentLineWidth = 0;
|
|
994
989
|
for (let i = 0; i < output.indent; i++) yield " ";
|
|
@@ -999,7 +994,7 @@ function* streamToHtml(node, opts, output) {
|
|
|
999
994
|
const tag = tagName === shadowRootTag ? "template" : tagName;
|
|
1000
995
|
const childNodes = tagName === "template" ? node.content.childNodes : getChildNodes(node);
|
|
1001
996
|
const childNodeLength = childNodes.length;
|
|
1002
|
-
if (childNodeLength > 0) if (childNodeLength === 1 && childNodes[0].nodeType ===
|
|
997
|
+
if (childNodeLength > 0) if (childNodeLength === 1 && childNodes[0].nodeType === 3 && (typeof childNodes[0].nodeValue !== "string" || childNodes[0].nodeValue.trim() === "")) {} else {
|
|
1003
998
|
const isWithinWhitespaceSensitiveNode = opts.newLines || (opts.indentSpaces ?? 0) > 0 ? isWithinWhitespaceSensitive(node) : false;
|
|
1004
999
|
if (!isWithinWhitespaceSensitiveNode && (opts.indentSpaces ?? 0) > 0 && ignoreTag === false) output.indent = output.indent + (opts.indentSpaces ?? 0);
|
|
1005
1000
|
for (let i = 0; i < childNodeLength; i++) {
|
|
@@ -1041,7 +1036,7 @@ function* streamToHtml(node, opts, output) {
|
|
|
1041
1036
|
output.currentLineWidth = 0;
|
|
1042
1037
|
}
|
|
1043
1038
|
if (tagName === "body") output.isWithinBody = false;
|
|
1044
|
-
} else if (node.nodeType ===
|
|
1039
|
+
} else if (node.nodeType === 3) {
|
|
1045
1040
|
let textContent = node.nodeValue;
|
|
1046
1041
|
if (typeof textContent === "string") {
|
|
1047
1042
|
const trimmedTextContent = textContent.trim();
|
|
@@ -1068,7 +1063,7 @@ function* streamToHtml(node, opts, output) {
|
|
|
1068
1063
|
}
|
|
1069
1064
|
let textContentLength = textContent.length;
|
|
1070
1065
|
if (textContentLength > 0) {
|
|
1071
|
-
const parentTagName = node.parentNode != null && node.parentNode.nodeType ===
|
|
1066
|
+
const parentTagName = node.parentNode != null && node.parentNode.nodeType === 1 ? node.parentNode.nodeName : null;
|
|
1072
1067
|
if (typeof parentTagName === "string" && NON_ESCAPABLE_CONTENT.has(parentTagName)) {
|
|
1073
1068
|
if (isWithinWhitespaceSensitive(node)) yield textContent;
|
|
1074
1069
|
else {
|
|
@@ -1082,13 +1077,13 @@ function* streamToHtml(node, opts, output) {
|
|
|
1082
1077
|
} else {
|
|
1083
1078
|
if (isWithinWhitespaceSensitive(node)) output.currentLineWidth += textContentLength;
|
|
1084
1079
|
else {
|
|
1085
|
-
if (/\s/.test(textContent.charAt(0))) textContent = " " + textContent.
|
|
1080
|
+
if (/\s/.test(textContent.charAt(0))) textContent = " " + textContent.trimStart();
|
|
1086
1081
|
textContentLength = textContent.length;
|
|
1087
1082
|
if (textContentLength > 1) {
|
|
1088
1083
|
if (/\s/.test(textContent.charAt(textContentLength - 1))) if (opts.approximateLineWidth && opts.approximateLineWidth > 0 && output.currentLineWidth + textContentLength > opts.approximateLineWidth) {
|
|
1089
|
-
textContent = textContent.
|
|
1084
|
+
textContent = textContent.trimEnd() + "\n";
|
|
1090
1085
|
output.currentLineWidth = 0;
|
|
1091
|
-
} else textContent = textContent.
|
|
1086
|
+
} else textContent = textContent.trimEnd() + " ";
|
|
1092
1087
|
}
|
|
1093
1088
|
output.currentLineWidth += textContentLength;
|
|
1094
1089
|
}
|
|
@@ -1097,7 +1092,7 @@ function* streamToHtml(node, opts, output) {
|
|
|
1097
1092
|
}
|
|
1098
1093
|
}
|
|
1099
1094
|
}
|
|
1100
|
-
} else if (node.nodeType ===
|
|
1095
|
+
} else if (node.nodeType === 8) {
|
|
1101
1096
|
const nodeValue = node.nodeValue;
|
|
1102
1097
|
const isHydrateAnnotation = nodeValue?.startsWith("r.") || nodeValue?.startsWith("o.") || nodeValue?.startsWith("s.") || nodeValue?.startsWith("t.");
|
|
1103
1098
|
/**
|
|
@@ -1116,7 +1111,7 @@ function* streamToHtml(node, opts, output) {
|
|
|
1116
1111
|
}
|
|
1117
1112
|
yield "<!--" + nodeValue + "-->";
|
|
1118
1113
|
if (nodeValue) output.currentLineWidth += nodeValue.length + 7;
|
|
1119
|
-
} else if (node.nodeType ===
|
|
1114
|
+
} else if (node.nodeType === 10) yield "<!doctype html>";
|
|
1120
1115
|
}
|
|
1121
1116
|
const AMP_REGEX = /&/g;
|
|
1122
1117
|
const NBSP_REGEX = /\u00a0/g;
|
|
@@ -1163,11 +1158,7 @@ const NON_ESCAPABLE_CONTENT = new Set([
|
|
|
1163
1158
|
"STYLE",
|
|
1164
1159
|
"SCRIPT",
|
|
1165
1160
|
"IFRAME",
|
|
1166
|
-
"NOSCRIPT"
|
|
1167
|
-
"XMP",
|
|
1168
|
-
"NOEMBED",
|
|
1169
|
-
"NOFRAMES",
|
|
1170
|
-
"PLAINTEXT"
|
|
1161
|
+
"NOSCRIPT"
|
|
1171
1162
|
]);
|
|
1172
1163
|
/**
|
|
1173
1164
|
* A list of whitespace sensitive tag names, such as `code`, `pre`, etc.
|
|
@@ -1175,7 +1166,6 @@ const NON_ESCAPABLE_CONTENT = new Set([
|
|
|
1175
1166
|
const WHITESPACE_SENSITIVE = new Set([
|
|
1176
1167
|
"CODE",
|
|
1177
1168
|
"OUTPUT",
|
|
1178
|
-
"PLAINTEXT",
|
|
1179
1169
|
"PRE",
|
|
1180
1170
|
"SCRIPT",
|
|
1181
1171
|
"TEMPLATE",
|
|
@@ -1184,21 +1174,16 @@ const WHITESPACE_SENSITIVE = new Set([
|
|
|
1184
1174
|
const EMPTY_ELEMENTS = new Set([
|
|
1185
1175
|
"area",
|
|
1186
1176
|
"base",
|
|
1187
|
-
"basefont",
|
|
1188
|
-
"bgsound",
|
|
1189
1177
|
"br",
|
|
1190
1178
|
"col",
|
|
1191
1179
|
"embed",
|
|
1192
|
-
"frame",
|
|
1193
1180
|
"hr",
|
|
1194
1181
|
"img",
|
|
1195
1182
|
"input",
|
|
1196
|
-
"keygen",
|
|
1197
1183
|
"link",
|
|
1198
1184
|
"meta",
|
|
1199
1185
|
"param",
|
|
1200
1186
|
"source",
|
|
1201
|
-
"trace",
|
|
1202
1187
|
"track",
|
|
1203
1188
|
"wbr"
|
|
1204
1189
|
]);
|
|
@@ -1216,44 +1201,29 @@ const BOOLEAN_ATTR = new Set([
|
|
|
1216
1201
|
"autofocus",
|
|
1217
1202
|
"autoplay",
|
|
1218
1203
|
"checked",
|
|
1219
|
-
"compact",
|
|
1220
1204
|
"controls",
|
|
1221
|
-
"declare",
|
|
1222
1205
|
"default",
|
|
1223
|
-
"defaultchecked",
|
|
1224
|
-
"defaultmuted",
|
|
1225
|
-
"defaultselected",
|
|
1226
1206
|
"defer",
|
|
1227
1207
|
"disabled",
|
|
1228
|
-
"enabled",
|
|
1229
1208
|
"formnovalidate",
|
|
1230
1209
|
"hidden",
|
|
1231
|
-
"indeterminate",
|
|
1232
1210
|
"inert",
|
|
1233
1211
|
"ismap",
|
|
1234
1212
|
"itemscope",
|
|
1235
1213
|
"loop",
|
|
1236
1214
|
"multiple",
|
|
1237
1215
|
"muted",
|
|
1238
|
-
"nohref",
|
|
1239
1216
|
"nomodule",
|
|
1240
|
-
"noresize",
|
|
1241
|
-
"noshade",
|
|
1242
1217
|
"novalidate",
|
|
1243
|
-
"nowrap",
|
|
1244
1218
|
"open",
|
|
1245
|
-
"pauseonexit",
|
|
1246
1219
|
"readonly",
|
|
1247
1220
|
"required",
|
|
1248
1221
|
"reversed",
|
|
1249
|
-
"scoped",
|
|
1250
|
-
"seamless",
|
|
1251
1222
|
"selected",
|
|
1223
|
+
"shadowrootclonable",
|
|
1224
|
+
"shadowrootcustomelementregistry",
|
|
1252
1225
|
"shadowrootdelegatesfocus",
|
|
1253
|
-
"
|
|
1254
|
-
"truespeed",
|
|
1255
|
-
"typemustmatch",
|
|
1256
|
-
"visible"
|
|
1226
|
+
"shadowrootserializable"
|
|
1257
1227
|
]);
|
|
1258
1228
|
const STRUCTURE_ELEMENTS = new Set([
|
|
1259
1229
|
"html",
|
|
@@ -1270,6 +1240,8 @@ const STRUCTURE_ELEMENTS = new Set([
|
|
|
1270
1240
|
//#endregion
|
|
1271
1241
|
//#region src/token-list.ts
|
|
1272
1242
|
var MockTokenList = class {
|
|
1243
|
+
elm;
|
|
1244
|
+
attr;
|
|
1273
1245
|
constructor(elm, attr) {
|
|
1274
1246
|
this.elm = elm;
|
|
1275
1247
|
this.attr = attr;
|
|
@@ -1352,7 +1324,7 @@ var MockNode = class {
|
|
|
1352
1324
|
this._childNodes = value;
|
|
1353
1325
|
}
|
|
1354
1326
|
appendChild(newNode) {
|
|
1355
|
-
if (newNode.nodeType ===
|
|
1327
|
+
if (newNode.nodeType === 11) {
|
|
1356
1328
|
const nodes = newNode.childNodes.slice();
|
|
1357
1329
|
for (const child of nodes) this.appendChild(child);
|
|
1358
1330
|
} else {
|
|
@@ -1383,22 +1355,20 @@ var MockNode = class {
|
|
|
1383
1355
|
const DOCUMENT_POSITION_DISCONNECTED = 1;
|
|
1384
1356
|
const DOCUMENT_POSITION_PRECEDING = 2;
|
|
1385
1357
|
const DOCUMENT_POSITION_FOLLOWING = 4;
|
|
1386
|
-
const DOCUMENT_POSITION_CONTAINS = 8;
|
|
1387
|
-
const DOCUMENT_POSITION_CONTAINED_BY = 16;
|
|
1388
1358
|
if (this === other) return 0;
|
|
1389
1359
|
let thisRoot = this;
|
|
1390
1360
|
while (thisRoot.parentNode) thisRoot = thisRoot.parentNode;
|
|
1391
1361
|
let otherRoot = other;
|
|
1392
1362
|
while (otherRoot.parentNode) otherRoot = otherRoot.parentNode;
|
|
1393
|
-
if (thisRoot !== otherRoot) return
|
|
1363
|
+
if (thisRoot !== otherRoot) return 3;
|
|
1394
1364
|
let node = other;
|
|
1395
1365
|
while (node) {
|
|
1396
|
-
if (node === this) return
|
|
1366
|
+
if (node === this) return 10;
|
|
1397
1367
|
node = node.parentNode;
|
|
1398
1368
|
}
|
|
1399
1369
|
node = this;
|
|
1400
1370
|
while (node) {
|
|
1401
|
-
if (node === other) return
|
|
1371
|
+
if (node === other) return 20;
|
|
1402
1372
|
node = node.parentNode;
|
|
1403
1373
|
}
|
|
1404
1374
|
const getAncestors = (n) => {
|
|
@@ -1426,16 +1396,16 @@ var MockNode = class {
|
|
|
1426
1396
|
return this.childNodes[0] || null;
|
|
1427
1397
|
}
|
|
1428
1398
|
insertBefore(newNode, referenceNode) {
|
|
1429
|
-
if (newNode.nodeType ===
|
|
1399
|
+
if (newNode.nodeType === 11) for (let i = 0, ii = newNode.childNodes.length; i < ii; i++) insertBefore(this, newNode.childNodes[i], referenceNode);
|
|
1430
1400
|
else insertBefore(this, newNode, referenceNode);
|
|
1431
1401
|
return newNode;
|
|
1432
1402
|
}
|
|
1433
1403
|
get isConnected() {
|
|
1434
1404
|
let node = this;
|
|
1435
1405
|
while (node != null) {
|
|
1436
|
-
if (node.nodeType ===
|
|
1406
|
+
if (node.nodeType === 9) return true;
|
|
1437
1407
|
node = node.parentNode;
|
|
1438
|
-
if (node != null && node.nodeType ===
|
|
1408
|
+
if (node != null && node.nodeType === 11) node = node.host;
|
|
1439
1409
|
}
|
|
1440
1410
|
return false;
|
|
1441
1411
|
}
|
|
@@ -1481,7 +1451,7 @@ var MockNode = class {
|
|
|
1481
1451
|
const index = this.childNodes.indexOf(childNode);
|
|
1482
1452
|
if (index > -1) {
|
|
1483
1453
|
this.childNodes.splice(index, 1);
|
|
1484
|
-
if (this.nodeType ===
|
|
1454
|
+
if (this.nodeType === 1) {
|
|
1485
1455
|
const wasConnected = this.isConnected;
|
|
1486
1456
|
childNode.parentNode = null;
|
|
1487
1457
|
if (wasConnected === true) disconnectNode(childNode);
|
|
@@ -1550,7 +1520,7 @@ var MockElement = class extends MockNode {
|
|
|
1550
1520
|
} });
|
|
1551
1521
|
}
|
|
1552
1522
|
constructor(ownerDocument, nodeName, namespaceURI = null) {
|
|
1553
|
-
super(ownerDocument,
|
|
1523
|
+
super(ownerDocument, 1, typeof nodeName === "string" ? nodeName : null, null);
|
|
1554
1524
|
this.__namespaceURI = namespaceURI;
|
|
1555
1525
|
this.__localName = typeof nodeName === "string" ? nodeName : null;
|
|
1556
1526
|
this.__shadowRoot = null;
|
|
@@ -1561,6 +1531,7 @@ var MockElement = class extends MockNode {
|
|
|
1561
1531
|
}
|
|
1562
1532
|
attachShadow(_opts) {
|
|
1563
1533
|
const shadowRoot = this.ownerDocument.createDocumentFragment();
|
|
1534
|
+
shadowRoot.mode = _opts.mode ?? "open";
|
|
1564
1535
|
shadowRoot.delegatesFocus = _opts.delegatesFocus ?? false;
|
|
1565
1536
|
this.shadowRoot = shadowRoot;
|
|
1566
1537
|
return shadowRoot;
|
|
@@ -1624,10 +1595,10 @@ var MockElement = class extends MockNode {
|
|
|
1624
1595
|
this.__attributeMap = attrs;
|
|
1625
1596
|
}
|
|
1626
1597
|
get children() {
|
|
1627
|
-
return this.childNodes.filter((n) => n.nodeType ===
|
|
1598
|
+
return this.childNodes.filter((n) => n.nodeType === 1);
|
|
1628
1599
|
}
|
|
1629
1600
|
get childElementCount() {
|
|
1630
|
-
return this.childNodes.filter((n) => n.nodeType ===
|
|
1601
|
+
return this.childNodes.filter((n) => n.nodeType === 1).length;
|
|
1631
1602
|
}
|
|
1632
1603
|
get className() {
|
|
1633
1604
|
return this.getAttributeNS(null, "class") || "";
|
|
@@ -1820,7 +1791,7 @@ var MockElement = class extends MockNode {
|
|
|
1820
1791
|
}
|
|
1821
1792
|
get nextElementSibling() {
|
|
1822
1793
|
const parentElement = this.parentElement;
|
|
1823
|
-
if (parentElement != null && (parentElement.nodeType ===
|
|
1794
|
+
if (parentElement != null && (parentElement.nodeType === 1 || parentElement.nodeType === 11 || parentElement.nodeType === 9)) {
|
|
1824
1795
|
const index = parentElement.children.indexOf(this) + 1;
|
|
1825
1796
|
return parentElement.children[index] || null;
|
|
1826
1797
|
}
|
|
@@ -1835,7 +1806,7 @@ var MockElement = class extends MockNode {
|
|
|
1835
1806
|
}
|
|
1836
1807
|
get previousElementSibling() {
|
|
1837
1808
|
const parentElement = this.parentElement;
|
|
1838
|
-
if (parentElement != null && (parentElement.nodeType ===
|
|
1809
|
+
if (parentElement != null && (parentElement.nodeType === 1 || parentElement.nodeType === 11 || parentElement.nodeType === 9)) {
|
|
1839
1810
|
const index = parentElement.children.indexOf(this) - 1;
|
|
1840
1811
|
return parentElement.children[index] || null;
|
|
1841
1812
|
}
|
|
@@ -2094,7 +2065,7 @@ function insertBefore(parentNode, newNode, referenceNode) {
|
|
|
2094
2065
|
var MockHTMLElement = class extends MockElement {
|
|
2095
2066
|
__namespaceURI = "http://www.w3.org/1999/xhtml";
|
|
2096
2067
|
constructor(ownerDocument, nodeName) {
|
|
2097
|
-
super(ownerDocument,
|
|
2068
|
+
super(ownerDocument, nodeName ? nodeName.toUpperCase() : null);
|
|
2098
2069
|
}
|
|
2099
2070
|
get tagName() {
|
|
2100
2071
|
return this.nodeName ?? "";
|
|
@@ -2126,7 +2097,7 @@ var MockHTMLElement = class extends MockElement {
|
|
|
2126
2097
|
};
|
|
2127
2098
|
var MockTextNode = class MockTextNode extends MockNode {
|
|
2128
2099
|
constructor(ownerDocument, text) {
|
|
2129
|
-
super(ownerDocument,
|
|
2100
|
+
super(ownerDocument, 3, "#text", text);
|
|
2130
2101
|
}
|
|
2131
2102
|
cloneNode(_deep) {
|
|
2132
2103
|
return new MockTextNode(null, this.nodeValue);
|
|
@@ -2148,7 +2119,7 @@ var MockTextNode = class MockTextNode extends MockNode {
|
|
|
2148
2119
|
const text = [];
|
|
2149
2120
|
for (let i = 0, ii = this.parentNode.childNodes.length; i < ii; i++) {
|
|
2150
2121
|
const childNode = this.parentNode.childNodes[i];
|
|
2151
|
-
if (childNode.nodeType ===
|
|
2122
|
+
if (childNode.nodeType === 3) text.push(childNode.nodeValue);
|
|
2152
2123
|
}
|
|
2153
2124
|
return text.join("");
|
|
2154
2125
|
}
|
|
@@ -2158,8 +2129,8 @@ var MockTextNode = class MockTextNode extends MockNode {
|
|
|
2158
2129
|
function getTextContent(childNodes, text) {
|
|
2159
2130
|
for (let i = 0, ii = childNodes.length; i < ii; i++) {
|
|
2160
2131
|
const childNode = childNodes[i];
|
|
2161
|
-
if (childNode.nodeType ===
|
|
2162
|
-
else if (childNode.nodeType ===
|
|
2132
|
+
if (childNode.nodeType === 3) text.push(childNode.nodeValue);
|
|
2133
|
+
else if (childNode.nodeType === 1) getTextContent(childNode.childNodes, text);
|
|
2163
2134
|
}
|
|
2164
2135
|
}
|
|
2165
2136
|
function setTextContent(elm, text) {
|
|
@@ -2204,7 +2175,7 @@ function unmarkAsDispatching(target, eventType) {
|
|
|
2204
2175
|
//#region src/comment-node.ts
|
|
2205
2176
|
var MockComment = class MockComment extends MockNode {
|
|
2206
2177
|
constructor(ownerDocument, data) {
|
|
2207
|
-
super(ownerDocument,
|
|
2178
|
+
super(ownerDocument, 8, "#comment", data);
|
|
2208
2179
|
}
|
|
2209
2180
|
cloneNode(_deep) {
|
|
2210
2181
|
return new MockComment(null, this.nodeValue);
|
|
@@ -3359,8 +3330,8 @@ var import_nwsapi = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
3359
3330
|
var MockDocumentFragment = class MockDocumentFragment extends MockHTMLElement {
|
|
3360
3331
|
constructor(ownerDocument) {
|
|
3361
3332
|
super(ownerDocument, null);
|
|
3362
|
-
this.nodeName =
|
|
3363
|
-
this.nodeType =
|
|
3333
|
+
this.nodeName = "#document-fragment";
|
|
3334
|
+
this.nodeType = 11;
|
|
3364
3335
|
}
|
|
3365
3336
|
getElementById(id) {
|
|
3366
3337
|
return getElementById(this, id);
|
|
@@ -3375,7 +3346,7 @@ var MockDocumentFragment = class MockDocumentFragment extends MockHTMLElement {
|
|
|
3375
3346
|
const cloned = new MockDocumentFragment(null);
|
|
3376
3347
|
if (deep) for (let i = 0, ii = this.childNodes.length; i < ii; i++) {
|
|
3377
3348
|
const childNode = this.childNodes[i];
|
|
3378
|
-
if (childNode.nodeType ===
|
|
3349
|
+
if (childNode.nodeType === 1 || childNode.nodeType === 3 || childNode.nodeType === 8) {
|
|
3379
3350
|
const clonedChildNode = this.childNodes[i].cloneNode(true);
|
|
3380
3351
|
cloned.appendChild(clonedChildNode);
|
|
3381
3352
|
}
|
|
@@ -3388,13 +3359,14 @@ var MockDocumentFragment = class MockDocumentFragment extends MockHTMLElement {
|
|
|
3388
3359
|
var MockDocumentTypeNode = class extends MockHTMLElement {
|
|
3389
3360
|
constructor(ownerDocument) {
|
|
3390
3361
|
super(ownerDocument, "!DOCTYPE");
|
|
3391
|
-
this.nodeType =
|
|
3362
|
+
this.nodeType = 10;
|
|
3392
3363
|
this.setAttribute("html", "");
|
|
3393
3364
|
}
|
|
3394
3365
|
};
|
|
3395
3366
|
//#endregion
|
|
3396
3367
|
//#region src/css-style-sheet.ts
|
|
3397
3368
|
var MockCSSRule = class {
|
|
3369
|
+
parentStyleSheet;
|
|
3398
3370
|
cssText = "";
|
|
3399
3371
|
type = 0;
|
|
3400
3372
|
constructor(parentStyleSheet) {
|
|
@@ -3882,8 +3854,8 @@ var MockSlotElement = class MockSlotElement extends MockHTMLElement {
|
|
|
3882
3854
|
const ownerHost = this.getRootNode().host;
|
|
3883
3855
|
if (!ownerHost) return nodesToReturn;
|
|
3884
3856
|
if (ownerHost.childNodes.length) {
|
|
3885
|
-
if (this.name) nodesToReturn = ownerHost.childNodes.filter((n) => n.nodeType ===
|
|
3886
|
-
else nodesToReturn = ownerHost.childNodes.filter((n) => n.nodeType ===
|
|
3857
|
+
if (this.name) nodesToReturn = ownerHost.childNodes.filter((n) => n.nodeType === 1 && n.getAttribute("slot") === this.name);
|
|
3858
|
+
else nodesToReturn = ownerHost.childNodes.filter((n) => n.nodeType === 1 && !n.getAttribute("slot") || n.nodeType !== 1);
|
|
3887
3859
|
if (nodesToReturn.length) return nodesToReturn;
|
|
3888
3860
|
}
|
|
3889
3861
|
if (!opts?.flatten) return this.childNodes.filter((n) => !(n instanceof MockSlotElement));
|
|
@@ -4687,6 +4659,8 @@ var MockResizeObserver = class {
|
|
|
4687
4659
|
//#endregion
|
|
4688
4660
|
//#region src/shadow-root.ts
|
|
4689
4661
|
var MockShadowRoot = class extends MockDocumentFragment {
|
|
4662
|
+
_mode = "open";
|
|
4663
|
+
_delegatesFocus = false;
|
|
4690
4664
|
get activeElement() {
|
|
4691
4665
|
return null;
|
|
4692
4666
|
}
|
|
@@ -4694,7 +4668,10 @@ var MockShadowRoot = class extends MockDocumentFragment {
|
|
|
4694
4668
|
return false;
|
|
4695
4669
|
}
|
|
4696
4670
|
get delegatesFocus() {
|
|
4697
|
-
return
|
|
4671
|
+
return this._delegatesFocus;
|
|
4672
|
+
}
|
|
4673
|
+
set delegatesFocus(value) {
|
|
4674
|
+
this._delegatesFocus = value;
|
|
4698
4675
|
}
|
|
4699
4676
|
get fullscreenElement() {
|
|
4700
4677
|
return null;
|
|
@@ -4708,7 +4685,10 @@ var MockShadowRoot = class extends MockDocumentFragment {
|
|
|
4708
4685
|
return null;
|
|
4709
4686
|
}
|
|
4710
4687
|
get mode() {
|
|
4711
|
-
return
|
|
4688
|
+
return this._mode;
|
|
4689
|
+
}
|
|
4690
|
+
set mode(value) {
|
|
4691
|
+
this._mode = value;
|
|
4712
4692
|
}
|
|
4713
4693
|
get pictureInPictureElement() {
|
|
4714
4694
|
return null;
|
|
@@ -5308,8 +5288,8 @@ var MockDocument = class MockDocument extends MockHTMLElement {
|
|
|
5308
5288
|
#nwsapi = null;
|
|
5309
5289
|
constructor(html = null, win = null) {
|
|
5310
5290
|
super(null, null);
|
|
5311
|
-
this.nodeName =
|
|
5312
|
-
this.nodeType =
|
|
5291
|
+
this.nodeName = "#document";
|
|
5292
|
+
this.nodeType = 9;
|
|
5313
5293
|
this.defaultView = win;
|
|
5314
5294
|
this.cookie = "";
|
|
5315
5295
|
this.referrer = "";
|
|
@@ -5400,7 +5380,7 @@ var MockDocument = class MockDocument extends MockHTMLElement {
|
|
|
5400
5380
|
return documentElement;
|
|
5401
5381
|
}
|
|
5402
5382
|
set documentElement(documentElement) {
|
|
5403
|
-
for (let i = this.childNodes.length - 1; i >= 0; i--) if (this.childNodes[i].nodeType !==
|
|
5383
|
+
for (let i = this.childNodes.length - 1; i >= 0; i--) if (this.childNodes[i].nodeType !== 10) this.childNodes[i].remove();
|
|
5404
5384
|
if (documentElement != null) {
|
|
5405
5385
|
this.appendChild(documentElement);
|
|
5406
5386
|
setOwnerDocument(documentElement, this);
|
|
@@ -5452,7 +5432,7 @@ var MockDocument = class MockDocument extends MockHTMLElement {
|
|
|
5452
5432
|
return new MockAttr(attrName, "", namespaceURI);
|
|
5453
5433
|
}
|
|
5454
5434
|
createElement(tagName) {
|
|
5455
|
-
if (tagName ===
|
|
5435
|
+
if (tagName === "#document") {
|
|
5456
5436
|
const doc = new MockDocument(false);
|
|
5457
5437
|
doc.nodeName = tagName;
|
|
5458
5438
|
doc.parentNode = null;
|
|
@@ -5524,10 +5504,10 @@ function resetDocument(doc) {
|
|
|
5524
5504
|
}
|
|
5525
5505
|
for (const key in doc) if (doc.hasOwnProperty(key) && !DOC_KEY_KEEPERS.has(key)) delete doc[key];
|
|
5526
5506
|
try {
|
|
5527
|
-
doc.nodeName =
|
|
5507
|
+
doc.nodeName = "#document";
|
|
5528
5508
|
} catch {}
|
|
5529
5509
|
try {
|
|
5530
|
-
doc.nodeType =
|
|
5510
|
+
doc.nodeType = 9;
|
|
5531
5511
|
} catch {}
|
|
5532
5512
|
try {
|
|
5533
5513
|
doc.cookie = "";
|
|
@@ -5571,7 +5551,7 @@ function getElementsByName(elm, elmName, foundElms = []) {
|
|
|
5571
5551
|
function setOwnerDocument(elm, ownerDocument) {
|
|
5572
5552
|
for (let i = 0, ii = elm.childNodes.length; i < ii; i++) {
|
|
5573
5553
|
elm.childNodes[i].ownerDocument = ownerDocument;
|
|
5574
|
-
if (elm.childNodes[i].nodeType ===
|
|
5554
|
+
if (elm.childNodes[i].nodeType === 1) setOwnerDocument(elm.childNodes[i], ownerDocument);
|
|
5575
5555
|
}
|
|
5576
5556
|
}
|
|
5577
5557
|
//#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.21",
|
|
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.
|
|
36
|
-
"parse5": "
|
|
35
|
+
"nwsapi": "^2.0.0",
|
|
36
|
+
"parse5": "^8.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@stencil/vitest": "^1.
|
|
40
|
-
"tsdown": "
|
|
41
|
-
"typescript": "
|
|
42
|
-
"vitest": "^4.1.
|
|
39
|
+
"@stencil/vitest": "^1.12.1",
|
|
40
|
+
"tsdown": ">=0.21.0 <1.0.0",
|
|
41
|
+
"typescript": ">4.0.0 <7.0.0",
|
|
42
|
+
"vitest": "^4.1.7"
|
|
43
43
|
},
|
|
44
44
|
"volta": {
|
|
45
45
|
"extends": "../../package.json"
|