@miaskiewicz/turbo-dom 0.1.39 → 0.1.41
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.41",
|
|
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/events.mjs
CHANGED
|
@@ -106,12 +106,6 @@ export const TouchEvent = makeTyped('TouchEvent');
|
|
|
106
106
|
export const DragEvent = makeTyped('DragEvent');
|
|
107
107
|
export const ProgressEvent = makeTyped('ProgressEvent');
|
|
108
108
|
|
|
109
|
-
function normalizeOptions(options) {
|
|
110
|
-
if (typeof options === 'boolean') return { capture: options, once: false, passive: false };
|
|
111
|
-
options = options || {};
|
|
112
|
-
return { capture: !!options.capture, once: !!options.once, passive: !!options.passive };
|
|
113
|
-
}
|
|
114
|
-
|
|
115
109
|
// ---- shadow DOM event support ----
|
|
116
110
|
// Duck-typed (ShadowRoot sets `__isShadowRoot`/`host`) to avoid a dom.mjs import
|
|
117
111
|
// cycle. NONE of this runs unless the document has a shadow root attached — the
|
|
@@ -149,22 +143,28 @@ export class EventTarget {
|
|
|
149
143
|
|
|
150
144
|
addEventListener(type, callback, options) {
|
|
151
145
|
if (callback == null) return;
|
|
152
|
-
|
|
146
|
+
// Inlined option parsing — avoids a throwaway normalizeOptions object AND a
|
|
147
|
+
// per-call .some() closure on this hot path (React attaches many listeners
|
|
148
|
+
// at mount). Boolean options → capture; object → capture/once/passive.
|
|
149
|
+
let capture = false, once = false, passive = false;
|
|
150
|
+
if (typeof options === 'boolean') capture = options;
|
|
151
|
+
else if (options) { capture = !!options.capture; once = !!options.once; passive = !!options.passive; }
|
|
153
152
|
if (!this.__listeners) this.__listeners = new Map();
|
|
154
153
|
let list = this.__listeners.get(type);
|
|
155
154
|
if (!list) { list = []; this.__listeners.set(type, list); }
|
|
156
155
|
// dedupe on (callback, capture) per spec
|
|
157
|
-
|
|
158
|
-
list.push({ callback, capture
|
|
156
|
+
for (let i = 0; i < list.length; i++) if (list[i].callback === callback && list[i].capture === capture) return;
|
|
157
|
+
list.push({ callback, capture, once, passive });
|
|
159
158
|
}
|
|
160
159
|
|
|
161
160
|
removeEventListener(type, callback, options) {
|
|
162
161
|
if (!this.__listeners) return;
|
|
163
|
-
const
|
|
162
|
+
const capture = typeof options === 'boolean' ? options : !!(options && options.capture);
|
|
164
163
|
const list = this.__listeners.get(type);
|
|
165
164
|
if (!list) return;
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
for (let i = 0; i < list.length; i++) {
|
|
166
|
+
if (list[i].callback === callback && list[i].capture === capture) { list.splice(i, 1); return; }
|
|
167
|
+
}
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
// Build the event path: target up through ancestors to the root.
|
package/src/runtime/index.mjs
CHANGED
|
@@ -23,11 +23,14 @@ export * from './dom.mjs';
|
|
|
23
23
|
// native parse + boundary marshaling entirely. Bounded (fixtures are few).
|
|
24
24
|
const __parseCache = new Map();
|
|
25
25
|
const __PARSE_CACHE_MAX = 64;
|
|
26
|
+
let __parseCacheMRU; // last (most-recently-used) key — skip the LRU re-insert when unchanged
|
|
26
27
|
function parseBufferCached(html) {
|
|
27
28
|
const hit = __parseCache.get(html);
|
|
28
29
|
if (hit !== undefined) {
|
|
29
|
-
// LRU bump: re-insert so this entry is
|
|
30
|
-
|
|
30
|
+
// LRU bump: re-insert so this entry is most-recently-used (Map keeps order).
|
|
31
|
+
// Skip the delete+set entirely when this key is ALREADY the MRU — the common
|
|
32
|
+
// case for a suite that reuses one shell HTML across every file.
|
|
33
|
+
if (html !== __parseCacheMRU) { __parseCache.delete(html); __parseCache.set(html, hit); __parseCacheMRU = html; }
|
|
31
34
|
return hit;
|
|
32
35
|
}
|
|
33
36
|
const soa = native.parseBuffer(html);
|
|
@@ -35,6 +38,7 @@ function parseBufferCached(html) {
|
|
|
35
38
|
// shells should keep its hot fixtures warm, not thrash every one cold on overflow.
|
|
36
39
|
if (__parseCache.size >= __PARSE_CACHE_MAX) __parseCache.delete(__parseCache.keys().next().value);
|
|
37
40
|
__parseCache.set(html, soa);
|
|
41
|
+
__parseCacheMRU = html;
|
|
38
42
|
return soa;
|
|
39
43
|
}
|
|
40
44
|
|
|
Binary file
|