@miaskiewicz/turbo-dom 0.1.5 → 0.1.6
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.6",
|
|
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
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
package/src/runtime/dom.mjs
CHANGED
|
@@ -7,7 +7,10 @@
|
|
|
7
7
|
// across the boundary — a buffer-backed read and an owned read are indistinguishable.
|
|
8
8
|
|
|
9
9
|
import { createRequire } from 'node:module';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
EventTarget, Event, CustomEvent,
|
|
12
|
+
UIEvent, MouseEvent, KeyboardEvent, FocusEvent,
|
|
13
|
+
} from './events.mjs';
|
|
11
14
|
import { liveNodeList, liveHTMLCollection } from './collections.mjs';
|
|
12
15
|
import { matchesSelector, querySelector as qsel, querySelectorAll as qselAll } from './selectors.mjs';
|
|
13
16
|
import { serializeInner, serializeOuter } from './html-serialize.mjs';
|
|
@@ -988,7 +991,16 @@ export class Document extends Node {
|
|
|
988
991
|
createTextNode(data) { return new Text(this, String(data)); }
|
|
989
992
|
createComment(data) { return new Comment(this, String(data)); }
|
|
990
993
|
createDocumentFragment() { return new DocumentFragment(this); }
|
|
991
|
-
createEvent(
|
|
994
|
+
createEvent(type = 'Event') {
|
|
995
|
+
switch (String(type)) {
|
|
996
|
+
case 'CustomEvent': return new CustomEvent('');
|
|
997
|
+
case 'MouseEvent': case 'MouseEvents': return new MouseEvent('');
|
|
998
|
+
case 'KeyboardEvent': case 'KeyEvents': return new KeyboardEvent('');
|
|
999
|
+
case 'UIEvent': case 'UIEvents': return new UIEvent('');
|
|
1000
|
+
case 'FocusEvent': return new FocusEvent('');
|
|
1001
|
+
default: return new Event('');
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
992
1004
|
createRange() { return new Range(this); }
|
|
993
1005
|
createAttribute(name) { return { name, value: '', ownerElement: null }; }
|
|
994
1006
|
createComment(data) { return new Comment(this, String(data)); }
|
package/src/runtime/events.mjs
CHANGED
|
@@ -41,6 +41,13 @@ export class Event {
|
|
|
41
41
|
set returnValue(v) { if (v === false) this.preventDefault(); }
|
|
42
42
|
|
|
43
43
|
composedPath() { return this._path.slice(); }
|
|
44
|
+
|
|
45
|
+
// legacy init — react-dom's dev rethrow path uses createEvent('Event')+initEvent
|
|
46
|
+
initEvent(type, bubbles = false, cancelable = false) {
|
|
47
|
+
this.type = String(type);
|
|
48
|
+
this.bubbles = !!bubbles;
|
|
49
|
+
this.cancelable = !!cancelable;
|
|
50
|
+
}
|
|
44
51
|
}
|
|
45
52
|
|
|
46
53
|
export class CustomEvent extends Event {
|
|
@@ -48,6 +55,10 @@ export class CustomEvent extends Event {
|
|
|
48
55
|
super(type, init);
|
|
49
56
|
this.detail = init.detail ?? null;
|
|
50
57
|
}
|
|
58
|
+
initCustomEvent(type, bubbles = false, cancelable = false, detail = null) {
|
|
59
|
+
this.initEvent(type, bubbles, cancelable);
|
|
60
|
+
this.detail = detail;
|
|
61
|
+
}
|
|
51
62
|
}
|
|
52
63
|
|
|
53
64
|
// Typed events. Real libraries (RTL/user-event) construct these by name; we copy
|
|
@@ -68,12 +79,19 @@ const TYPED_DEFAULTS = {
|
|
|
68
79
|
|
|
69
80
|
function makeTyped(name) {
|
|
70
81
|
const defaults = TYPED_DEFAULTS[name];
|
|
71
|
-
|
|
82
|
+
const cls = class extends Event {
|
|
72
83
|
constructor(type, init = {}) {
|
|
73
84
|
super(type, init);
|
|
74
85
|
Object.assign(this, defaults, init);
|
|
75
86
|
}
|
|
76
87
|
};
|
|
88
|
+
// legacy initMouseEvent/initKeyboardEvent/initUIEvent(type, bubbles, cancelable, ...rest)
|
|
89
|
+
cls.prototype['init' + name] = function (type, bubbles = false, cancelable = false, ...rest) {
|
|
90
|
+
this.initEvent(type, bubbles, cancelable);
|
|
91
|
+
// view is the common 4th arg for UI/Mouse/Keyboard events; ignore the rest's exact slots
|
|
92
|
+
if (rest.length) this.view = rest[0];
|
|
93
|
+
};
|
|
94
|
+
return cls;
|
|
77
95
|
}
|
|
78
96
|
|
|
79
97
|
export const UIEvent = makeTyped('UIEvent');
|
package/src/runtime/window.mjs
CHANGED
|
@@ -179,9 +179,9 @@ export function createWindow(document, { url = 'http://localhost/' } = {}) {
|
|
|
179
179
|
};
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
+
import { performance as nodePerformance } from 'node:perf_hooks';
|
|
182
183
|
function performanceNow() {
|
|
183
|
-
|
|
184
|
-
return s * 1000 + ns / 1e6;
|
|
184
|
+
return nodePerformance.now();
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
let __objUrlSeq = 0;
|
|
Binary file
|