@stencil/mock-doc 5.0.0-beta.33 → 5.0.0-beta.35
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/dist/index.d.mts +13 -1
- package/dist/index.mjs +103 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -448,6 +448,18 @@ declare function cloneDocument(srcDoc: Document): Document;
|
|
|
448
448
|
* @param win the mock window instance to update
|
|
449
449
|
*/
|
|
450
450
|
declare function constrainTimeouts(win: MockWindow): void;
|
|
451
|
+
/**
|
|
452
|
+
* Reset a window so the same object can be used for another render, then parse `html` into its
|
|
453
|
+
* document.
|
|
454
|
+
*
|
|
455
|
+
* Code that captured the window's sub-objects (e.g. an SSR platform holding `win.location`,
|
|
456
|
+
* `win.console` or `win.document`) keeps working: those objects are kept and reset in place,
|
|
457
|
+
* rather than replaced. Everything else on the window - including anything a previous render
|
|
458
|
+
* added - is removed.
|
|
459
|
+
* @param win the window to reset
|
|
460
|
+
* @param html the HTML for the next render
|
|
461
|
+
*/
|
|
462
|
+
declare function resetWindowForReuse(win: MockWindow, html: string): void;
|
|
451
463
|
//#endregion
|
|
452
464
|
//#region src/event.d.ts
|
|
453
465
|
declare class MockEvent {
|
|
@@ -1041,4 +1053,4 @@ declare class MockResponse {
|
|
|
1041
1053
|
clone(): MockResponse;
|
|
1042
1054
|
}
|
|
1043
1055
|
//#endregion
|
|
1044
|
-
export { MockAttr, MockAttributeMap, MockComment, MockCustomEvent, MockDocument, MockElement, MockHTMLElement, MockHeaders, MockKeyboardEvent, MockMouseEvent, MockNode, MockRequest, type MockRequestInfo, type MockRequestInit, MockResponse, type MockResponseInit, MockTextNode, MockWindow, NODE_TYPES, type SerializeNodeToHtmlOptions, cloneAttributes, cloneDocument, cloneWindow, constrainTimeouts, createDocument, createFragment, parseHtmlToDocument, parseHtmlToFragment, patchWindow, resetDocument, serializeNodeToHtml, setupGlobal, teardownGlobal };
|
|
1056
|
+
export { MockAttr, MockAttributeMap, MockComment, MockCustomEvent, MockDocument, MockElement, MockHTMLElement, MockHeaders, MockKeyboardEvent, MockMouseEvent, MockNode, MockRequest, type MockRequestInfo, type MockRequestInit, MockResponse, type MockResponseInit, MockTextNode, MockWindow, NODE_TYPES, type SerializeNodeToHtmlOptions, cloneAttributes, cloneDocument, cloneWindow, constrainTimeouts, createDocument, createFragment, parseHtmlToDocument, parseHtmlToFragment, patchWindow, resetDocument, resetWindowForReuse, serializeNodeToHtml, setupGlobal, teardownGlobal };
|
package/dist/index.mjs
CHANGED
|
@@ -5269,6 +5269,77 @@ function constrainTimeouts(win) {
|
|
|
5269
5269
|
win.__allowInterval = false;
|
|
5270
5270
|
win.__maxTimeout = 0;
|
|
5271
5271
|
}
|
|
5272
|
+
/**
|
|
5273
|
+
* Reset a window so the same object can be used for another render, then parse `html` into its
|
|
5274
|
+
* document.
|
|
5275
|
+
*
|
|
5276
|
+
* Code that captured the window's sub-objects (e.g. an SSR platform holding `win.location`,
|
|
5277
|
+
* `win.console` or `win.document`) keeps working: those objects are kept and reset in place,
|
|
5278
|
+
* rather than replaced. Everything else on the window - including anything a previous render
|
|
5279
|
+
* added - is removed.
|
|
5280
|
+
* @param win the window to reset
|
|
5281
|
+
* @param html the HTML for the next render
|
|
5282
|
+
*/
|
|
5283
|
+
function resetWindowForReuse(win, html) {
|
|
5284
|
+
const retained = {
|
|
5285
|
+
console: win.console,
|
|
5286
|
+
document: win.document,
|
|
5287
|
+
eventCounts: win.performance.eventCounts,
|
|
5288
|
+
history: win.history,
|
|
5289
|
+
localStorage: win.localStorage,
|
|
5290
|
+
location: win.location,
|
|
5291
|
+
navigator: win.navigator,
|
|
5292
|
+
orientation: win.screen.orientation,
|
|
5293
|
+
performance: win.performance,
|
|
5294
|
+
screen: win.screen,
|
|
5295
|
+
sessionStorage: win.sessionStorage
|
|
5296
|
+
};
|
|
5297
|
+
if (win.__timeouts) win.__timeouts.forEach((timeoutId) => {
|
|
5298
|
+
nativeClearInterval(timeoutId);
|
|
5299
|
+
nativeClearTimeout(timeoutId);
|
|
5300
|
+
});
|
|
5301
|
+
resetObject(retained.console, createConsole());
|
|
5302
|
+
resetObject(retained.history, new MockHistory());
|
|
5303
|
+
resetObject(retained.location, new MockLocation());
|
|
5304
|
+
resetObject(retained.navigator, new MockNavigator());
|
|
5305
|
+
retained.localStorage.clear();
|
|
5306
|
+
retained.sessionStorage.clear();
|
|
5307
|
+
retained.eventCounts.clear();
|
|
5308
|
+
resetObject(retained.performance, {
|
|
5309
|
+
eventCounts: retained.eventCounts,
|
|
5310
|
+
interactionCount: 0,
|
|
5311
|
+
timeOrigin: Date.now()
|
|
5312
|
+
});
|
|
5313
|
+
for (const key of Reflect.ownKeys(win)) delete win[key];
|
|
5314
|
+
resetWindowDefaults(win);
|
|
5315
|
+
resetWindowDimensions(win);
|
|
5316
|
+
const defaultScreen = win.screen;
|
|
5317
|
+
resetObject(retained.orientation, defaultScreen.orientation);
|
|
5318
|
+
resetObject(retained.screen, {
|
|
5319
|
+
...defaultScreen,
|
|
5320
|
+
orientation: retained.orientation
|
|
5321
|
+
});
|
|
5322
|
+
win.console = retained.console;
|
|
5323
|
+
win.customElements = null;
|
|
5324
|
+
win.document = retained.document;
|
|
5325
|
+
win.history = retained.history;
|
|
5326
|
+
win.localStorage = retained.localStorage;
|
|
5327
|
+
win.location = retained.location;
|
|
5328
|
+
win.navigator = retained.navigator;
|
|
5329
|
+
win.performance = retained.performance;
|
|
5330
|
+
win.screen = retained.screen;
|
|
5331
|
+
win.sessionStorage = retained.sessionStorage;
|
|
5332
|
+
resetDocumentForReuse(retained.document, win, html);
|
|
5333
|
+
}
|
|
5334
|
+
/**
|
|
5335
|
+
* Replace every own property of `target` with those of `defaults`, keeping the object itself.
|
|
5336
|
+
* @param target the object to reset in place
|
|
5337
|
+
* @param defaults the properties it should have afterwards
|
|
5338
|
+
*/
|
|
5339
|
+
function resetObject(target, defaults) {
|
|
5340
|
+
for (const key of Reflect.ownKeys(target)) delete target[key];
|
|
5341
|
+
Object.assign(target, defaults);
|
|
5342
|
+
}
|
|
5272
5343
|
function resetWindow(win) {
|
|
5273
5344
|
if (win != null) {
|
|
5274
5345
|
if (win.__timeouts) {
|
|
@@ -5577,6 +5648,37 @@ function resetDocument(doc) {
|
|
|
5577
5648
|
} catch {}
|
|
5578
5649
|
}
|
|
5579
5650
|
}
|
|
5651
|
+
/**
|
|
5652
|
+
* Reset a document so the same object can be used for another render, then parse `html` into
|
|
5653
|
+
* it. The document object itself is kept (code holding a reference to it stays valid), but its
|
|
5654
|
+
* whole element tree is replaced with freshly parsed elements - so caches keyed on elements, like
|
|
5655
|
+
* the runtime's applied-styles cache keyed on `<head>`, start empty.
|
|
5656
|
+
* @param doc the document to reset
|
|
5657
|
+
* @param win the window that owns the document
|
|
5658
|
+
* @param html the HTML to parse into the document
|
|
5659
|
+
*/
|
|
5660
|
+
function resetDocumentForReuse(doc, win, html) {
|
|
5661
|
+
resetDocument(doc);
|
|
5662
|
+
for (const key of Reflect.ownKeys(doc)) if (typeof key !== "string" || !REUSABLE_DOC_KEY_KEEPERS.has(key)) delete doc[key];
|
|
5663
|
+
doc.defaultView = win;
|
|
5664
|
+
doc.documentElement = parseDocumentUtil(doc, html).documentElement;
|
|
5665
|
+
}
|
|
5666
|
+
/** Structural document properties kept by {@link resetDocumentForReuse}; everything else is per-render state. */
|
|
5667
|
+
const REUSABLE_DOC_KEY_KEEPERS = /* @__PURE__ */ new Set([
|
|
5668
|
+
"_nodeValue",
|
|
5669
|
+
"nodeName",
|
|
5670
|
+
"nodeType",
|
|
5671
|
+
"ownerDocument",
|
|
5672
|
+
"parentNode",
|
|
5673
|
+
"_childNodes",
|
|
5674
|
+
"__namespaceURI",
|
|
5675
|
+
"__localName",
|
|
5676
|
+
"defaultView",
|
|
5677
|
+
"cookie",
|
|
5678
|
+
"referrer",
|
|
5679
|
+
"compatMode",
|
|
5680
|
+
"contentType"
|
|
5681
|
+
]);
|
|
5580
5682
|
const DOC_KEY_KEEPERS = /* @__PURE__ */ new Set([
|
|
5581
5683
|
"nodeName",
|
|
5582
5684
|
"nodeType",
|
|
@@ -5615,4 +5717,4 @@ function setOwnerDocument(elm, ownerDocument) {
|
|
|
5615
5717
|
}
|
|
5616
5718
|
}
|
|
5617
5719
|
//#endregion
|
|
5618
|
-
export { MockAttr, MockAttributeMap, MockComment, MockCustomEvent, MockDocument, MockElement, MockHTMLElement, MockHeaders, MockKeyboardEvent, MockMouseEvent, MockNode, MockRequest, MockResponse, MockTextNode, MockWindow, NODE_TYPES, cloneAttributes, cloneDocument, cloneWindow, constrainTimeouts, createDocument, createFragment, parseHtmlToDocument, parseHtmlToFragment, patchWindow, resetDocument, serializeNodeToHtml, setupGlobal, teardownGlobal };
|
|
5720
|
+
export { MockAttr, MockAttributeMap, MockComment, MockCustomEvent, MockDocument, MockElement, MockHTMLElement, MockHeaders, MockKeyboardEvent, MockMouseEvent, MockNode, MockRequest, MockResponse, MockTextNode, MockWindow, NODE_TYPES, cloneAttributes, cloneDocument, cloneWindow, constrainTimeouts, createDocument, createFragment, parseHtmlToDocument, parseHtmlToFragment, patchWindow, resetDocument, resetWindowForReuse, serializeNodeToHtml, setupGlobal, teardownGlobal };
|