@miaskiewicz/turbo-dom 0.1.11 → 0.1.12

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.11",
3
+ "version": "0.1.12",
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",
@@ -57,6 +57,19 @@ 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
+ Object.defineProperty(C, Symbol.hasInstance, {
68
+ value: (o) => o != null && o.nodeType === 1 && test(o.localName),
69
+ });
70
+ return C;
71
+ }
72
+
60
73
  // Capture host functions at module load — BEFORE any installGlobals() can shadow
61
74
  // the bare names on globalThis (which would make these delegates call themselves).
62
75
  const hostSetTimeout = globalThis.setTimeout;
@@ -83,17 +96,21 @@ export function createWindow(document, { url = 'http://localhost/' } = {}) {
83
96
  UIEvent, MouseEvent, PointerEvent, KeyboardEvent, InputEvent, FocusEvent,
84
97
  CompositionEvent, WheelEvent, TouchEvent, DragEvent, ProgressEvent, ClipboardEvent,
85
98
  DataTransfer,
86
- // generic elements are plain Element → `el instanceof HTMLElement` is true.
87
- // HTMLIFrameElement MUST be a distinct class so React's iframe-descent loop
88
- // (`while (el instanceof HTMLIFrameElement)`) terminates on normal elements.
99
+ // every element is a plain Element → `el instanceof HTMLElement` is true.
100
+ // Tag-specific interfaces match by localName via Symbol.hasInstance, so
101
+ // `el instanceof HTMLAnchorElement` is true ONLY for <a> (not every element),
102
+ // and React's `while (el instanceof HTMLIFrameElement)` loop terminates.
89
103
  HTMLElement: Element, SVGElement: Element,
90
- HTMLIFrameElement: class HTMLIFrameElement extends Element {},
91
- HTMLInputElement: Element, HTMLTextAreaElement: Element, HTMLSelectElement: Element,
92
- HTMLOptionElement: Element, HTMLButtonElement: Element, HTMLAnchorElement: Element,
93
- HTMLFormElement: Element, HTMLImageElement: Element, HTMLCanvasElement: Element,
94
- HTMLTemplateElement: Element, HTMLLabelElement: Element, HTMLDivElement: Element,
95
- HTMLSpanElement: Element, HTMLParagraphElement: Element, HTMLUListElement: Element,
96
- HTMLLIElement: Element, HTMLHeadingElement: Element, HTMLBodyElement: Element,
104
+ HTMLAnchorElement: tagClass('a'), HTMLInputElement: tagClass('input'),
105
+ HTMLTextAreaElement: tagClass('textarea'), HTMLSelectElement: tagClass('select'),
106
+ HTMLOptionElement: tagClass('option'), HTMLButtonElement: tagClass('button'),
107
+ HTMLFormElement: tagClass('form'), HTMLImageElement: tagClass('img'),
108
+ HTMLCanvasElement: tagClass('canvas'), HTMLTemplateElement: tagClass('template'),
109
+ HTMLLabelElement: tagClass('label'), HTMLDivElement: tagClass('div'),
110
+ HTMLSpanElement: tagClass('span'), HTMLParagraphElement: tagClass('p'),
111
+ HTMLUListElement: tagClass('ul'), HTMLLIElement: tagClass('li'),
112
+ HTMLBodyElement: tagClass('body'), HTMLIFrameElement: tagClass('iframe'),
113
+ HTMLHeadingElement: tagClass(/^h[1-6]$/),
97
114
  HTMLDocument: Document, DocumentFragment, ShadowRoot: DocumentFragment,
98
115
  MutationObserver, DOMParser, XMLSerializer,
99
116
  URL: makeURL(), URLSearchParams,