@miaskiewicz/turbo-dom 0.1.40 → 0.1.42
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.42",
|
|
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.
|
|
@@ -238,8 +238,13 @@ export class EventTarget {
|
|
|
238
238
|
event.target = retarget(target, node);
|
|
239
239
|
if (relatedTarget != null) event.relatedTarget = retarget(relatedTarget, node);
|
|
240
240
|
}
|
|
241
|
-
// snapshot — listeners added during dispatch don't fire this round
|
|
242
|
-
for
|
|
241
|
+
// snapshot — listeners added during dispatch don't fire this round. Skip the
|
|
242
|
+
// slice alloc for the single-listener case (common React-delegated one): a
|
|
243
|
+
// 1-element, length-captured iteration can't be disturbed by an add/remove in
|
|
244
|
+
// that one call. Multi-listener keeps the slice (concurrent-mutation guard).
|
|
245
|
+
const snap = list.length === 1 ? list : list.slice();
|
|
246
|
+
for (let k = 0, len = snap.length; k < len; k++) {
|
|
247
|
+
const l = snap[k];
|
|
243
248
|
if (phase === PHASE_CAPTURING && !l.capture) continue;
|
|
244
249
|
if (phase === PHASE_BUBBLING && l.capture) continue;
|
|
245
250
|
if (l.once) {
|
|
Binary file
|