@miaskiewicz/turbo-dom 0.1.11 → 0.1.13
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.13",
|
|
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/window.mjs
CHANGED
|
@@ -57,6 +57,23 @@ class TurboFormData {
|
|
|
57
57
|
[Symbol.iterator]() { return this.entries(); }
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
// A tag-specific HTML*Element interface. Not constructible — exists so
|
|
61
|
+
// `el instanceof HTMLXElement` is true only for elements with the matching
|
|
62
|
+
// localName (matcher = string or RegExp). Avoids aliasing every interface to
|
|
63
|
+
// Element (which made `instanceof HTMLAnchorElement` true for ALL elements).
|
|
64
|
+
function tagClass(matcher) {
|
|
65
|
+
const test = typeof matcher === 'string' ? (n) => n === matcher : (n) => matcher.test(n);
|
|
66
|
+
const C = function () { throw new TypeError('Illegal constructor'); };
|
|
67
|
+
// share Element.prototype so prototype-level spies/reads resolve (e.g.
|
|
68
|
+
// vi.spyOn(HTMLAnchorElement.prototype, 'click')); instanceof is decided by
|
|
69
|
+
// the tag matcher below, not the prototype chain.
|
|
70
|
+
C.prototype = Element.prototype;
|
|
71
|
+
Object.defineProperty(C, Symbol.hasInstance, {
|
|
72
|
+
value: (o) => o != null && o.nodeType === 1 && test(o.localName),
|
|
73
|
+
});
|
|
74
|
+
return C;
|
|
75
|
+
}
|
|
76
|
+
|
|
60
77
|
// Capture host functions at module load — BEFORE any installGlobals() can shadow
|
|
61
78
|
// the bare names on globalThis (which would make these delegates call themselves).
|
|
62
79
|
const hostSetTimeout = globalThis.setTimeout;
|
|
@@ -83,17 +100,21 @@ export function createWindow(document, { url = 'http://localhost/' } = {}) {
|
|
|
83
100
|
UIEvent, MouseEvent, PointerEvent, KeyboardEvent, InputEvent, FocusEvent,
|
|
84
101
|
CompositionEvent, WheelEvent, TouchEvent, DragEvent, ProgressEvent, ClipboardEvent,
|
|
85
102
|
DataTransfer,
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
//
|
|
103
|
+
// every element is a plain Element → `el instanceof HTMLElement` is true.
|
|
104
|
+
// Tag-specific interfaces match by localName via Symbol.hasInstance, so
|
|
105
|
+
// `el instanceof HTMLAnchorElement` is true ONLY for <a> (not every element),
|
|
106
|
+
// and React's `while (el instanceof HTMLIFrameElement)` loop terminates.
|
|
89
107
|
HTMLElement: Element, SVGElement: Element,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
HTMLOptionElement:
|
|
93
|
-
HTMLFormElement:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
108
|
+
HTMLAnchorElement: tagClass('a'), HTMLInputElement: tagClass('input'),
|
|
109
|
+
HTMLTextAreaElement: tagClass('textarea'), HTMLSelectElement: tagClass('select'),
|
|
110
|
+
HTMLOptionElement: tagClass('option'), HTMLButtonElement: tagClass('button'),
|
|
111
|
+
HTMLFormElement: tagClass('form'), HTMLImageElement: tagClass('img'),
|
|
112
|
+
HTMLCanvasElement: tagClass('canvas'), HTMLTemplateElement: tagClass('template'),
|
|
113
|
+
HTMLLabelElement: tagClass('label'), HTMLDivElement: tagClass('div'),
|
|
114
|
+
HTMLSpanElement: tagClass('span'), HTMLParagraphElement: tagClass('p'),
|
|
115
|
+
HTMLUListElement: tagClass('ul'), HTMLLIElement: tagClass('li'),
|
|
116
|
+
HTMLBodyElement: tagClass('body'), HTMLIFrameElement: tagClass('iframe'),
|
|
117
|
+
HTMLHeadingElement: tagClass(/^h[1-6]$/),
|
|
97
118
|
HTMLDocument: Document, DocumentFragment, ShadowRoot: DocumentFragment,
|
|
98
119
|
MutationObserver, DOMParser, XMLSerializer,
|
|
99
120
|
URL: makeURL(), URLSearchParams,
|
|
Binary file
|