@isoloop/dom 0.0.0-stage → 0.1.0-next.0
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/LICENSE +21 -0
- package/README.md +11 -2
- package/dist/applier-D5wb4gz9.js +200 -0
- package/dist/dom-Bctskbvg.d.ts +316 -0
- package/dist/dom-yLsf0Z4e.js +1140 -0
- package/dist/host.d.ts +29 -0
- package/dist/host.js +3 -0
- package/dist/install-D7m7By8i.js +37 -0
- package/dist/records-OXGckMg9.d.ts +61 -0
- package/dist/records-wVZrPpqr.js +44 -0
- package/dist/testing-worker.d.ts +57 -0
- package/dist/testing-worker.js +217 -0
- package/dist/testing.d.ts +159 -0
- package/dist/testing.js +699 -0
- package/dist/worker.d.ts +12 -0
- package/dist/worker.js +4 -0
- package/package.json +47 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sabin Pandelovitch
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @isoloop/dom
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
**Internal.** This is Isoloop's render bridge, format `isoloop-dom@1` ([ADR 0010](../../docs/adr/0010-own-render-bridge.md), [ADR 0011](../../docs/adr/0011-dom-package.md)). `@isoloop/runtime` and `@isoloop/host` depend on it. App and adapter code never imports it, and its API carries no semver promise beyond the format version: a breaking record change bumps it to `isoloop-dom@2`.
|
|
4
|
+
|
|
5
|
+
| Entry | Runs in | What it is |
|
|
6
|
+
| --- | --- | --- |
|
|
7
|
+
| `@isoloop/dom/worker` | isolate worker | The DOM subset Preact and React use, recorded as batches of plain records; `deliver()` dispatches host events with capture and bubble. |
|
|
8
|
+
| `@isoloop/dom/host` | main thread | The applier: applies batches through a required sanitising policy, maps node ids both ways, and turns DOM events into event records. |
|
|
9
|
+
| `@isoloop/dom/testing` | tests | The bridge conformance suite, `runBridgeConformance()`; `mountFixture()` and `checkDomUsage()` for fixture workers. It needs Vitest, an optional peer. |
|
|
10
|
+
| `@isoloop/dom/testing/worker` | fixture workers | `serveFixture()`, which wires a worker's subset to `mountFixture()` on the page, and `trackUsage()`, the DOM usage logger (M3a tasks 2 and 3). |
|
|
11
|
+
|
|
12
|
+
There's no root entry. The package has no runtime dependencies.
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { r as isDomBatch } from "./records-wVZrPpqr.js";
|
|
2
|
+
// src/host/applier.ts
|
|
3
|
+
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
4
|
+
const HTML_NS = "http://www.w3.org/1999/xhtml";
|
|
5
|
+
const isActive = (el) => {
|
|
6
|
+
const root = el.getRootNode();
|
|
7
|
+
return (root instanceof ShadowRoot || root instanceof Document) && root.activeElement === el;
|
|
8
|
+
};
|
|
9
|
+
const nsOf = (el) => el.namespaceURI === SVG_NS ? "svg" : "html";
|
|
10
|
+
const NO_MODS = {
|
|
11
|
+
alt: false,
|
|
12
|
+
ctrl: false,
|
|
13
|
+
meta: false,
|
|
14
|
+
shift: false
|
|
15
|
+
};
|
|
16
|
+
function createApplier(container, policy) {
|
|
17
|
+
const nodes = /* @__PURE__ */ new Map([[0, container]]);
|
|
18
|
+
const ids = new WeakMap([[container, 0]]);
|
|
19
|
+
const listens = /* @__PURE__ */ new Map();
|
|
20
|
+
const known = /* @__PURE__ */ new WeakMap();
|
|
21
|
+
const setAttr = (el, name, value) => {
|
|
22
|
+
const safe = value === null ? null : policy.attribute(el.localName, nsOf(el), name, value);
|
|
23
|
+
try {
|
|
24
|
+
if (safe === null) el.removeAttribute(name);
|
|
25
|
+
else el.setAttribute(name, safe);
|
|
26
|
+
} catch {}
|
|
27
|
+
};
|
|
28
|
+
const setProp = (el, name, value, force = false) => {
|
|
29
|
+
if (name === "checked") known.set(el, Boolean(value));
|
|
30
|
+
if (!policy.property(el, name, value, force)) return;
|
|
31
|
+
if (name === "checked" && el instanceof HTMLInputElement) el.checked = Boolean(value);
|
|
32
|
+
else if (name === "selected" && el instanceof HTMLOptionElement) el.selected = Boolean(value);
|
|
33
|
+
else if (name === "value" && (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement)) {
|
|
34
|
+
el.value = String(value);
|
|
35
|
+
if (force && !(el instanceof HTMLSelectElement) && isActive(el)) try {
|
|
36
|
+
el.setSelectionRange(el.value.length, el.value.length);
|
|
37
|
+
} catch {}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const listen = (id, type, on) => {
|
|
41
|
+
const set = listens.get(id) ?? /* @__PURE__ */ new Set();
|
|
42
|
+
if (on) set.add(type);
|
|
43
|
+
else set.delete(type);
|
|
44
|
+
if (set.size > 0) listens.set(id, set);
|
|
45
|
+
else listens.delete(id);
|
|
46
|
+
};
|
|
47
|
+
const build = (s) => {
|
|
48
|
+
let node;
|
|
49
|
+
if (s.k === "text") node = document.createTextNode(s.data);
|
|
50
|
+
else if (s.k === "comment") node = document.createComment(s.data);
|
|
51
|
+
else {
|
|
52
|
+
const { tag, ns } = policy.element(s.tag, s.ns);
|
|
53
|
+
const el = document.createElementNS(ns === "svg" ? SVG_NS : HTML_NS, tag);
|
|
54
|
+
for (const [name, value] of s.attrs) setAttr(el, name, value);
|
|
55
|
+
for (const c of s.children) el.append(build(c));
|
|
56
|
+
for (const [name, value] of s.props) setProp(el, name, value);
|
|
57
|
+
for (const type of s.listen) listen(s.id, type, true);
|
|
58
|
+
node = el;
|
|
59
|
+
}
|
|
60
|
+
nodes.set(s.id, node);
|
|
61
|
+
ids.set(node, s.id);
|
|
62
|
+
return node;
|
|
63
|
+
};
|
|
64
|
+
const forget = (node) => {
|
|
65
|
+
const id = ids.get(node);
|
|
66
|
+
if (id !== void 0) {
|
|
67
|
+
nodes.delete(id);
|
|
68
|
+
listens.delete(id);
|
|
69
|
+
ids.delete(node);
|
|
70
|
+
}
|
|
71
|
+
for (const c of node.childNodes) forget(c);
|
|
72
|
+
};
|
|
73
|
+
/** Moves keep the node, but browsers drop focus from a moved subtree; put it back. */
|
|
74
|
+
const move = (parent, node, before) => {
|
|
75
|
+
const root = container.getRootNode();
|
|
76
|
+
const active = root instanceof ShadowRoot || root instanceof Document ? root.activeElement : null;
|
|
77
|
+
const keep = active && node.contains(active) ? active : null;
|
|
78
|
+
const range = keep instanceof HTMLInputElement || keep instanceof HTMLTextAreaElement ? {
|
|
79
|
+
start: keep.selectionStart,
|
|
80
|
+
end: keep.selectionEnd
|
|
81
|
+
} : null;
|
|
82
|
+
parent.insertBefore(node, before);
|
|
83
|
+
if (keep instanceof HTMLElement || keep instanceof SVGElement) {
|
|
84
|
+
keep.focus({ preventScroll: true });
|
|
85
|
+
if (range && (keep instanceof HTMLInputElement || keep instanceof HTMLTextAreaElement)) try {
|
|
86
|
+
keep.setSelectionRange(range.start, range.end);
|
|
87
|
+
} catch {}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const applyRecord = (r) => {
|
|
91
|
+
switch (r[0]) {
|
|
92
|
+
case "insert": {
|
|
93
|
+
const parent = nodes.get(r[1]);
|
|
94
|
+
if (!parent) return;
|
|
95
|
+
const before = r[3] === null ? null : nodes.get(r[3]) ?? null;
|
|
96
|
+
parent.insertBefore(build(r[2]), before?.parentNode === parent ? before : null);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
case "move": {
|
|
100
|
+
const parent = nodes.get(r[1]);
|
|
101
|
+
const node = nodes.get(r[2]);
|
|
102
|
+
if (!parent || !node) return;
|
|
103
|
+
const before = r[3] === null ? null : nodes.get(r[3]) ?? null;
|
|
104
|
+
move(parent, node, before?.parentNode === parent ? before : null);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
case "remove": {
|
|
108
|
+
const node = nodes.get(r[1]);
|
|
109
|
+
if (!node || r[1] === 0) return;
|
|
110
|
+
node.parentNode?.removeChild(node);
|
|
111
|
+
forget(node);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
case "text": {
|
|
115
|
+
const node = nodes.get(r[1]);
|
|
116
|
+
if (node instanceof CharacterData) node.data = r[2];
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
case "attr": {
|
|
120
|
+
const el = nodes.get(r[1]);
|
|
121
|
+
if (el instanceof Element && el !== container) setAttr(el, r[2], r[3]);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
case "prop": {
|
|
125
|
+
const el = nodes.get(r[1]);
|
|
126
|
+
if (el instanceof Element) setProp(el, r[2], r[3], r[4] === true);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
case "listen":
|
|
130
|
+
if (nodes.has(r[1])) listen(r[1], r[2], r[3]);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
apply(batch) {
|
|
136
|
+
if (!isDomBatch(batch)) return false;
|
|
137
|
+
for (const r of batch) try {
|
|
138
|
+
applyRecord(r);
|
|
139
|
+
} catch {}
|
|
140
|
+
return true;
|
|
141
|
+
},
|
|
142
|
+
idFor: (node) => ids.get(node),
|
|
143
|
+
nodeFor: (id) => nodes.get(id),
|
|
144
|
+
eventFor(e) {
|
|
145
|
+
const path = e.composedPath();
|
|
146
|
+
let target;
|
|
147
|
+
const currentTargets = [];
|
|
148
|
+
for (const t of path) {
|
|
149
|
+
if (!(t instanceof Node)) continue;
|
|
150
|
+
const id = ids.get(t);
|
|
151
|
+
if (id === void 0) continue;
|
|
152
|
+
target ??= id;
|
|
153
|
+
if (listens.get(id)?.has(e.type)) currentTargets.push(id);
|
|
154
|
+
if (t === container) break;
|
|
155
|
+
}
|
|
156
|
+
if (target === void 0 || currentTargets.length === 0) return null;
|
|
157
|
+
const out = {
|
|
158
|
+
type: e.type,
|
|
159
|
+
target,
|
|
160
|
+
currentTargets,
|
|
161
|
+
mods: NO_MODS
|
|
162
|
+
};
|
|
163
|
+
const el = nodes.get(target);
|
|
164
|
+
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement) out.value = el.value;
|
|
165
|
+
if (el instanceof HTMLInputElement && el.type === "radio") out.checked = el.checked;
|
|
166
|
+
else if (el instanceof HTMLInputElement && el.type === "checkbox" && known.get(el) !== el.checked) {
|
|
167
|
+
out.checked = el.checked;
|
|
168
|
+
known.set(el, el.checked);
|
|
169
|
+
}
|
|
170
|
+
if (e instanceof MouseEvent || e instanceof KeyboardEvent) out.mods = {
|
|
171
|
+
alt: e.altKey,
|
|
172
|
+
ctrl: e.ctrlKey,
|
|
173
|
+
meta: e.metaKey,
|
|
174
|
+
shift: e.shiftKey
|
|
175
|
+
};
|
|
176
|
+
if (e instanceof KeyboardEvent) {
|
|
177
|
+
out.key = e.key;
|
|
178
|
+
out.code = e.code;
|
|
179
|
+
}
|
|
180
|
+
if (e.type === "scroll" && el instanceof Element) {
|
|
181
|
+
out.scrollTop = el.scrollTop;
|
|
182
|
+
out.scrollLeft = el.scrollLeft;
|
|
183
|
+
}
|
|
184
|
+
if (e instanceof MouseEvent) {
|
|
185
|
+
out.x = e.clientX;
|
|
186
|
+
out.y = e.clientY;
|
|
187
|
+
out.button = e.button;
|
|
188
|
+
}
|
|
189
|
+
return out;
|
|
190
|
+
},
|
|
191
|
+
clear() {
|
|
192
|
+
for (const c of Array.from(container.childNodes)) {
|
|
193
|
+
container.removeChild(c);
|
|
194
|
+
forget(c);
|
|
195
|
+
}
|
|
196
|
+
listens.clear();
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
export { createApplier as t };
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { i as DomRecord, n as DomEvent, o as Namespace, s as NodeId, t as DomBatch, u as SyncedProp } from "./records-OXGckMg9.js";
|
|
2
|
+
type ListenerFn = (event: Event) => void;
|
|
3
|
+
type Listener = {
|
|
4
|
+
fn: ListenerFn | {
|
|
5
|
+
handleEvent: ListenerFn;
|
|
6
|
+
};
|
|
7
|
+
capture: boolean;
|
|
8
|
+
once: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* One render root and where its records go. A worker has one; a pool has one
|
|
12
|
+
* per visual member, all in the same document (ADR 0015).
|
|
13
|
+
*/
|
|
14
|
+
type Owner = {
|
|
15
|
+
readonly root: WElement;
|
|
16
|
+
push(r: DomRecord): void;
|
|
17
|
+
};
|
|
18
|
+
/** Shared state of one document: ids, the render roots, known nodes. */
|
|
19
|
+
type Core = {
|
|
20
|
+
/** The render roots, in the order they were made. */
|
|
21
|
+
roots: Set<WElement>;
|
|
22
|
+
nextId: number;
|
|
23
|
+
known: Map<NodeId, WNode>;
|
|
24
|
+
/** An element was inserted into `document.head`, which the bridge doesn't render. */
|
|
25
|
+
onHead(tag: string): void;
|
|
26
|
+
};
|
|
27
|
+
/** Listener storage and capture/bubble dispatch through `isoParentTarget()`. */
|
|
28
|
+
declare class WEventTarget {
|
|
29
|
+
/** @internal */ isoListeners: Map<string, Listener[]>;
|
|
30
|
+
/** @internal */ isoParentTarget(): WEventTarget | null;
|
|
31
|
+
/** @internal Called when the first listener of `type` is added, or the last removed. */
|
|
32
|
+
isoListenChanged(_type: string, _on: boolean): void;
|
|
33
|
+
addEventListener(type: string, fn: ListenerFn | {
|
|
34
|
+
handleEvent: ListenerFn;
|
|
35
|
+
} | null, options?: boolean | AddEventListenerOptions): void;
|
|
36
|
+
removeEventListener(type: string, fn: ListenerFn | {
|
|
37
|
+
handleEvent: ListenerFn;
|
|
38
|
+
} | null, options?: boolean | EventListenerOptions): void;
|
|
39
|
+
/** Capture from the top, then the target, then bubble (if `bubbles`). */
|
|
40
|
+
dispatchEvent(event: Event): boolean;
|
|
41
|
+
}
|
|
42
|
+
declare abstract class WNode extends WEventTarget {
|
|
43
|
+
static readonly ELEMENT_NODE = 1;
|
|
44
|
+
static readonly TEXT_NODE = 3;
|
|
45
|
+
static readonly COMMENT_NODE = 8;
|
|
46
|
+
static readonly DOCUMENT_NODE = 9;
|
|
47
|
+
static readonly DOCUMENT_FRAGMENT_NODE = 11;
|
|
48
|
+
readonly ELEMENT_NODE = 1;
|
|
49
|
+
readonly TEXT_NODE = 3;
|
|
50
|
+
readonly COMMENT_NODE = 8;
|
|
51
|
+
readonly DOCUMENT_FRAGMENT_NODE = 11;
|
|
52
|
+
abstract readonly nodeType: number;
|
|
53
|
+
abstract readonly nodeName: string;
|
|
54
|
+
readonly ownerDocument: WDocument;
|
|
55
|
+
/** @internal */ readonly isoId: NodeId;
|
|
56
|
+
/** @internal */ isoParent: WParentNode | null;
|
|
57
|
+
/** @internal */ isoPrev: WNode | null;
|
|
58
|
+
/** @internal */ isoNext: WNode | null;
|
|
59
|
+
/** @internal Whether the host knows this node (it's in the tree under the root). */
|
|
60
|
+
isoKnown: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* @internal The root this node was rendered under, once it has been. Kept
|
|
63
|
+
* after the node leaves the tree, so it can't move to another member's root
|
|
64
|
+
* in a pool (ADR 0015, decision 3).
|
|
65
|
+
*/
|
|
66
|
+
isoOwner: Owner | null;
|
|
67
|
+
constructor(doc: WDocument, id: NodeId);
|
|
68
|
+
/** @internal */ override isoParentTarget(): WEventTarget | null;
|
|
69
|
+
/**
|
|
70
|
+
* @internal The id the host knows this node by: a render root is always
|
|
71
|
+
* `ROOT_ID` to its own surface, whatever its id in the document.
|
|
72
|
+
*/
|
|
73
|
+
get isoWire(): NodeId;
|
|
74
|
+
/** @internal */ override isoListenChanged(type: string, on: boolean): void;
|
|
75
|
+
get parentNode(): WParentNode | null;
|
|
76
|
+
get parentElement(): WElement | null;
|
|
77
|
+
get nextSibling(): WNode | null;
|
|
78
|
+
get previousSibling(): WNode | null;
|
|
79
|
+
get firstChild(): WNode | null;
|
|
80
|
+
get lastChild(): WNode | null;
|
|
81
|
+
get childNodes(): readonly WNode[];
|
|
82
|
+
get isConnected(): boolean;
|
|
83
|
+
abstract get textContent(): string;
|
|
84
|
+
abstract set textContent(v: string | null);
|
|
85
|
+
abstract get nodeValue(): string | null;
|
|
86
|
+
abstract set nodeValue(v: string | null);
|
|
87
|
+
hasChildNodes(): boolean;
|
|
88
|
+
contains(other: WNode | null): boolean;
|
|
89
|
+
remove(): void;
|
|
90
|
+
}
|
|
91
|
+
/** What text and comment nodes share: `data`, changed with a `text` record. */
|
|
92
|
+
declare abstract class WCharacterData extends WNode {
|
|
93
|
+
/** @internal */ isoData: string;
|
|
94
|
+
constructor(doc: WDocument, id: NodeId, data: string);
|
|
95
|
+
get data(): string;
|
|
96
|
+
set data(v: unknown);
|
|
97
|
+
get length(): number;
|
|
98
|
+
get textContent(): string;
|
|
99
|
+
set textContent(v: string | null);
|
|
100
|
+
get nodeValue(): string | null;
|
|
101
|
+
set nodeValue(v: string | null);
|
|
102
|
+
}
|
|
103
|
+
declare class WText extends WCharacterData {
|
|
104
|
+
readonly nodeType = 3;
|
|
105
|
+
readonly nodeName = "#text";
|
|
106
|
+
}
|
|
107
|
+
/** A comment node (DOM group 1, ADR 0010): rendered on the host, inert there. */
|
|
108
|
+
declare class WComment extends WCharacterData {
|
|
109
|
+
readonly nodeType = 8;
|
|
110
|
+
readonly nodeName = "#comment";
|
|
111
|
+
}
|
|
112
|
+
/** What `element.style` offers: declarations by property name, plus the methods frameworks call. */
|
|
113
|
+
type WStyle = {
|
|
114
|
+
setProperty(name: string, value: string | null): void;
|
|
115
|
+
removeProperty(name: string): string;
|
|
116
|
+
getPropertyValue(name: string): string;
|
|
117
|
+
cssText: string;
|
|
118
|
+
[property: string]: unknown;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* `element.classList` (DOM group 1, ADR 0010): a view of the `class`
|
|
122
|
+
* attribute, so every write travels as an `attr` record.
|
|
123
|
+
*/
|
|
124
|
+
declare class WDOMTokenList {
|
|
125
|
+
/** @internal */ readonly isoEl: WElement;
|
|
126
|
+
constructor(el: WElement);
|
|
127
|
+
/** @internal */ isoTokens(): string[];
|
|
128
|
+
/** @internal */ isoWrite(tokens: string[]): void;
|
|
129
|
+
get length(): number;
|
|
130
|
+
get value(): string;
|
|
131
|
+
set value(v: string);
|
|
132
|
+
item(i: number): string | null;
|
|
133
|
+
contains(token: string): boolean;
|
|
134
|
+
add(...tokens: string[]): void;
|
|
135
|
+
remove(...tokens: string[]): void;
|
|
136
|
+
toggle(token: string, force?: boolean): boolean;
|
|
137
|
+
replace(token: string, next: string): boolean;
|
|
138
|
+
toString(): string;
|
|
139
|
+
[Symbol.iterator](): IterableIterator<string>;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* What elements and fragments share: an ordered child list. Changes under a
|
|
143
|
+
* known parent become records; a fragment is never known.
|
|
144
|
+
*/
|
|
145
|
+
declare abstract class WParentNode extends WNode {
|
|
146
|
+
/** @internal */ isoFirst: WNode | null;
|
|
147
|
+
/** @internal */ isoLast: WNode | null;
|
|
148
|
+
/** @internal */ isoChildCache: WNode[] | null;
|
|
149
|
+
override get firstChild(): WNode | null;
|
|
150
|
+
override get lastChild(): WNode | null;
|
|
151
|
+
override get childNodes(): readonly WNode[];
|
|
152
|
+
get children(): readonly WElement[];
|
|
153
|
+
get firstElementChild(): WElement | null;
|
|
154
|
+
/** Text of the subtree; comments don't count, as in the DOM. */
|
|
155
|
+
get textContent(): string;
|
|
156
|
+
set textContent(v: string | null);
|
|
157
|
+
appendChild<T extends WNode>(child: T): T;
|
|
158
|
+
insertBefore<T extends WNode>(child: T, ref: WNode | null): T;
|
|
159
|
+
removeChild<T extends WNode>(child: T): T;
|
|
160
|
+
replaceChildren(...nodes: (WNode | string)[]): void;
|
|
161
|
+
append(...nodes: (WNode | string)[]): void;
|
|
162
|
+
/** @internal */ isoUnlink(child: WNode): void;
|
|
163
|
+
/** @internal */ isoLink(child: WNode, ref: WNode | null): void;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* `DocumentFragment` (DOM group 1, ADR 0010): a detached holder. Inserting
|
|
167
|
+
* it inserts its children, in order, and empties it; it never reaches the
|
|
168
|
+
* host itself.
|
|
169
|
+
*/
|
|
170
|
+
declare class WDocumentFragment extends WParentNode {
|
|
171
|
+
readonly nodeType = 11;
|
|
172
|
+
readonly nodeName = "#document-fragment";
|
|
173
|
+
get nodeValue(): string | null;
|
|
174
|
+
set nodeValue(_v: string | null);
|
|
175
|
+
}
|
|
176
|
+
declare class WElement extends WParentNode {
|
|
177
|
+
readonly nodeType = 1;
|
|
178
|
+
readonly localName: string;
|
|
179
|
+
readonly namespaceURI: string;
|
|
180
|
+
/** @internal */ readonly isoNs: Namespace;
|
|
181
|
+
/** @internal */ isoAttrs: Map<string, string>;
|
|
182
|
+
/** @internal */ isoProps: Map<SyncedProp, string | boolean>;
|
|
183
|
+
/** @internal */ isoStyle: WStyle | null;
|
|
184
|
+
/** @internal */ isoClassList: WDOMTokenList | null;
|
|
185
|
+
/** @internal */ isoDataset: Record<string, string | undefined> | null;
|
|
186
|
+
/** @internal The offsets the last `scroll` event brought (design §4.6). */
|
|
187
|
+
isoScroll: {
|
|
188
|
+
top: number;
|
|
189
|
+
left: number;
|
|
190
|
+
};
|
|
191
|
+
constructor(doc: WDocument, id: NodeId, localName: string, ns: Namespace);
|
|
192
|
+
get tagName(): string;
|
|
193
|
+
get nodeName(): string;
|
|
194
|
+
get nodeValue(): string | null;
|
|
195
|
+
set nodeValue(_v: string | null);
|
|
196
|
+
get attributes(): readonly {
|
|
197
|
+
name: string;
|
|
198
|
+
value: string;
|
|
199
|
+
}[];
|
|
200
|
+
getAttribute(name: string): string | null;
|
|
201
|
+
hasAttribute(name: string): boolean;
|
|
202
|
+
setAttribute(name: string, value: unknown): void;
|
|
203
|
+
removeAttribute(name: string): void;
|
|
204
|
+
/** @internal HTML attribute names are case-insensitive; SVG ones aren't. */
|
|
205
|
+
isoAttrName(name: string): string;
|
|
206
|
+
get style(): WStyle;
|
|
207
|
+
get classList(): WDOMTokenList;
|
|
208
|
+
get dataset(): Record<string, string | undefined>;
|
|
209
|
+
/**
|
|
210
|
+
* Read only, and as of the last `scroll` event the element got: the host
|
|
211
|
+
* owns scrolling. 0 until the element is scrolled and listens for `scroll`.
|
|
212
|
+
*/
|
|
213
|
+
get scrollTop(): number;
|
|
214
|
+
get scrollLeft(): number;
|
|
215
|
+
get id(): string;
|
|
216
|
+
set id(v: string);
|
|
217
|
+
/** @internal */ isoSetProp(name: SyncedProp, value: string | boolean, record: boolean): void;
|
|
218
|
+
}
|
|
219
|
+
declare class WHTMLElement extends WElement {}
|
|
220
|
+
declare class WDocument extends WEventTarget {
|
|
221
|
+
readonly nodeType = 9;
|
|
222
|
+
readonly nodeName = "#document";
|
|
223
|
+
/** @internal */ readonly isoCore: Core;
|
|
224
|
+
/** Set by `install()`: the worker global. */
|
|
225
|
+
defaultView: unknown;
|
|
226
|
+
readonly activeElement: null;
|
|
227
|
+
/** `null`, as for every document. */
|
|
228
|
+
readonly ownerDocument: null;
|
|
229
|
+
/** A detached body, for code that falls back to `document.body`. */
|
|
230
|
+
readonly body: WHTMLElement;
|
|
231
|
+
/**
|
|
232
|
+
* A detached head: React 19 hoists `<title>`, `<meta>` and `<link>` into
|
|
233
|
+
* it. The bridge doesn't render it (M3a task 3).
|
|
234
|
+
*/
|
|
235
|
+
readonly head: WHTMLElement;
|
|
236
|
+
constructor(core: Core);
|
|
237
|
+
createElement(tag: string): WElement;
|
|
238
|
+
createElementNS(ns: string | null, tag: string): WElement;
|
|
239
|
+
/** `data` is converted with `String()`, as in the DOM: Preact passes numbers. */
|
|
240
|
+
createTextNode(data: unknown): WText;
|
|
241
|
+
createComment(data: unknown): WComment;
|
|
242
|
+
/** Fragments never reach the host, so they take no id from the shared counter. */
|
|
243
|
+
createDocumentFragment(): WDocumentFragment;
|
|
244
|
+
/**
|
|
245
|
+
* The first element in tree order with this `id` (DOM group 1, ADR 0010):
|
|
246
|
+
* under the render root, then the detached head. Nodes not yet inserted
|
|
247
|
+
* aren't in the document, so they aren't found.
|
|
248
|
+
*/
|
|
249
|
+
getElementById(id: string): WElement | null;
|
|
250
|
+
/**
|
|
251
|
+
* Type selectors only, alone or as a `head > title` child chain: what React
|
|
252
|
+
* 19 asks when it hoists a `<title>`. Queries in general are DOM group 2
|
|
253
|
+
* (ADR 0010), built when a library needs them; anything else throws.
|
|
254
|
+
*/
|
|
255
|
+
querySelector(selector: string): WElement | null;
|
|
256
|
+
}
|
|
257
|
+
type WorkerDomOptions = {
|
|
258
|
+
/** Receives each batch, in order. */
|
|
259
|
+
onBatch(batch: DomBatch): void;
|
|
260
|
+
/** Called once per batch with the flush to run; default `queueMicrotask`. */
|
|
261
|
+
schedule?: (flush: () => void) => void;
|
|
262
|
+
/**
|
|
263
|
+
* An element was inserted into `document.head` (React 19 hoists `<title>`,
|
|
264
|
+
* `<meta>` and `<link>` there). The bridge doesn't render the head; the
|
|
265
|
+
* runtime tells the host, which warns in `dev` (M3a task 3).
|
|
266
|
+
*/
|
|
267
|
+
onHead?: (tag: string) => void;
|
|
268
|
+
};
|
|
269
|
+
interface WorkerDom {
|
|
270
|
+
readonly document: WDocument;
|
|
271
|
+
/** The isolate's render root; the host maps it to the surface. */
|
|
272
|
+
readonly root: WElement;
|
|
273
|
+
/** Sends pending records now, if any. */
|
|
274
|
+
flush(): void;
|
|
275
|
+
/** Dispatches an event from the host to the node it names (capture and bubble in the worker). */
|
|
276
|
+
deliver(event: DomEvent): void;
|
|
277
|
+
/** The id of a node, for tests and host calls. */
|
|
278
|
+
idOf(node: WNode): NodeId;
|
|
279
|
+
/**
|
|
280
|
+
* Sets an input's, textarea's or select's `value`. With `force`, the host
|
|
281
|
+
* applies it even while the user is focused on a host-owned input, and
|
|
282
|
+
* keeps the caret at its end; it's recorded even if the worker already
|
|
283
|
+
* holds that value, since what the user typed may differ (M3a task 6).
|
|
284
|
+
*/
|
|
285
|
+
setValue(node: WNode, value: string, opts?: {
|
|
286
|
+
force?: boolean;
|
|
287
|
+
}): void;
|
|
288
|
+
/**
|
|
289
|
+
* Adds another render root to this document, with its own batches: one per
|
|
290
|
+
* visual member of a pool (ADR 0015). Its surface knows it as `ROOT_ID`.
|
|
291
|
+
*/
|
|
292
|
+
addRoot(opts: RootOptions): RenderRoot;
|
|
293
|
+
}
|
|
294
|
+
type RootOptions = {
|
|
295
|
+
/** Receives this root's batches, in order. */
|
|
296
|
+
onBatch(batch: DomBatch): void;
|
|
297
|
+
/** Called once per batch with the flush to run; default `queueMicrotask`. */
|
|
298
|
+
schedule?: (flush: () => void) => void;
|
|
299
|
+
};
|
|
300
|
+
/** One member's render root in a shared document (ADR 0015). */
|
|
301
|
+
interface RenderRoot {
|
|
302
|
+
readonly root: WElement;
|
|
303
|
+
/** Sends this root's pending records now, if any. */
|
|
304
|
+
flush(): void;
|
|
305
|
+
/** Dispatches an event from this root's surface; `ROOT_ID` names the root. */
|
|
306
|
+
deliver(event: DomEvent): void;
|
|
307
|
+
/** The id this root's surface knows `node` by, or `undefined` if it isn't rendered under this root. */
|
|
308
|
+
idOf(node: WNode): NodeId | undefined;
|
|
309
|
+
setValue(node: WNode, value: string, opts?: {
|
|
310
|
+
force?: boolean;
|
|
311
|
+
}): void;
|
|
312
|
+
/** Stops sending this root's records and forgets its nodes: the member stopped. */
|
|
313
|
+
dispose(): void;
|
|
314
|
+
}
|
|
315
|
+
declare function createDom(opts: WorkerDomOptions): WorkerDom;
|
|
316
|
+
export { WDocumentFragment as a, WText as c, createDom as d, WDocument as i, WorkerDom as l, RootOptions as n, WElement as o, WComment as r, WNode as s, RenderRoot as t, WorkerDomOptions as u };
|