@miaskiewicz/turbo-dom 0.1.44 → 0.1.46
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miaskiewicz/turbo-dom",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.46",
|
|
4
4
|
"description": "Faster, more spec-correct DOM for test runners — native html5ever (Rust/WASM) parser + lazy copy-on-write DOM. A drop-in-style alternative to jsdom/happy-dom for vitest & jest.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.js",
|
package/src/runtime/window.mjs
CHANGED
|
@@ -85,6 +85,7 @@ const hostClearTimeout = globalThis.clearTimeout;
|
|
|
85
85
|
// self-replaces onto the per-env base, so each env gets its own instance; only
|
|
86
86
|
// the factory objects/closures are shared, saving ~28 allocations per test file.
|
|
87
87
|
const SHARED_LAZY = {
|
|
88
|
+
customElements: () => makeCustomElements(), // fresh registry per env, built on first access
|
|
88
89
|
localStorage: () => new Storage(),
|
|
89
90
|
sessionStorage: () => new Storage(),
|
|
90
91
|
matchMedia: () => makeMatchMedia(),
|
|
@@ -132,8 +133,10 @@ export function createWindow(document, { url = 'http://localhost/' } = {}) {
|
|
|
132
133
|
document,
|
|
133
134
|
name: '',
|
|
134
135
|
closed: false,
|
|
135
|
-
origin
|
|
136
|
-
|
|
136
|
+
// origin is lazy (per-env, captures url) — window.origin is rarely read, so the
|
|
137
|
+
// eager `new URL(url)` parse per createWindow was usually wasted.
|
|
138
|
+
// customElements is lazy (SHARED_LAZY) — env-independent + rarely used; building
|
|
139
|
+
// its two Maps eagerly per createWindow was wasted for the typical test.
|
|
137
140
|
Image: function Image(w, h) { const img = document.createElement('img'); if (w != null) img.setAttribute('width', w); if (h != null) img.setAttribute('height', h); return img; },
|
|
138
141
|
Audio: function Audio(src) { const a = document.createElement('audio'); if (src) a.setAttribute('src', src); return a; },
|
|
139
142
|
getSelection: () => document.getSelection(),
|
|
@@ -146,6 +149,7 @@ export function createWindow(document, { url = 'http://localhost/' } = {}) {
|
|
|
146
149
|
// Everything env-independent lives in the module-level SHARED_LAZY (built once,
|
|
147
150
|
// not re-allocated per test file) — see below. None constructed until touched.
|
|
148
151
|
const lazy = {
|
|
152
|
+
origin: () => new URL(url).origin,
|
|
149
153
|
// subsystem grouping: history co-materializes with (and shares) location
|
|
150
154
|
location: () => makeLocation(url),
|
|
151
155
|
history: () => makeHistory(windowProxy.location),
|
|
Binary file
|