@isoloop/dom 0.0.0-next.69da74b
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 +12 -0
- package/dist/applier-CkaI6Dw-.js +190 -0
- package/dist/dom-9S5T0UVQ.js +1051 -0
- package/dist/dom-BrJVEi7G.d.ts +261 -0
- package/dist/host.d.ts +28 -0
- package/dist/host.js +3 -0
- package/dist/install-DBKGtAel.js +37 -0
- package/dist/records-2Jf3U4Sp.d.ts +58 -0
- package/dist/records-wVZrPpqr.js +44 -0
- package/dist/testing-worker.d.ts +49 -0
- package/dist/testing-worker.js +183 -0
- package/dist/testing.d.ts +152 -0
- package/dist/testing.js +671 -0
- package/dist/worker.d.ts +11 -0
- package/dist/worker.js +4 -0
- package/package.json +50 -0
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
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @isoloop/dom
|
|
2
|
+
|
|
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,190 @@
|
|
|
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 setAttr = (el, name, value) => {
|
|
21
|
+
const safe = value === null ? null : policy.attribute(el.localName, nsOf(el), name, value);
|
|
22
|
+
try {
|
|
23
|
+
if (safe === null) el.removeAttribute(name);
|
|
24
|
+
else el.setAttribute(name, safe);
|
|
25
|
+
} catch {}
|
|
26
|
+
};
|
|
27
|
+
const setProp = (el, name, value, force = false) => {
|
|
28
|
+
if (!policy.property(el, name, value, force)) return;
|
|
29
|
+
if (name === "checked" && el instanceof HTMLInputElement) el.checked = Boolean(value);
|
|
30
|
+
else if (name === "selected" && el instanceof HTMLOptionElement) el.selected = Boolean(value);
|
|
31
|
+
else if (name === "value" && (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement)) {
|
|
32
|
+
el.value = String(value);
|
|
33
|
+
if (force && !(el instanceof HTMLSelectElement) && isActive(el)) try {
|
|
34
|
+
el.setSelectionRange(el.value.length, el.value.length);
|
|
35
|
+
} catch {}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const listen = (id, type, on) => {
|
|
39
|
+
const set = listens.get(id) ?? /* @__PURE__ */ new Set();
|
|
40
|
+
if (on) set.add(type);
|
|
41
|
+
else set.delete(type);
|
|
42
|
+
if (set.size > 0) listens.set(id, set);
|
|
43
|
+
else listens.delete(id);
|
|
44
|
+
};
|
|
45
|
+
const build = (s) => {
|
|
46
|
+
let node;
|
|
47
|
+
if (s.k === "text") node = document.createTextNode(s.data);
|
|
48
|
+
else if (s.k === "comment") node = document.createComment(s.data);
|
|
49
|
+
else {
|
|
50
|
+
const { tag, ns } = policy.element(s.tag, s.ns);
|
|
51
|
+
const el = document.createElementNS(ns === "svg" ? SVG_NS : HTML_NS, tag);
|
|
52
|
+
for (const [name, value] of s.attrs) setAttr(el, name, value);
|
|
53
|
+
for (const c of s.children) el.append(build(c));
|
|
54
|
+
for (const [name, value] of s.props) setProp(el, name, value);
|
|
55
|
+
for (const type of s.listen) listen(s.id, type, true);
|
|
56
|
+
node = el;
|
|
57
|
+
}
|
|
58
|
+
nodes.set(s.id, node);
|
|
59
|
+
ids.set(node, s.id);
|
|
60
|
+
return node;
|
|
61
|
+
};
|
|
62
|
+
const forget = (node) => {
|
|
63
|
+
const id = ids.get(node);
|
|
64
|
+
if (id !== void 0) {
|
|
65
|
+
nodes.delete(id);
|
|
66
|
+
listens.delete(id);
|
|
67
|
+
ids.delete(node);
|
|
68
|
+
}
|
|
69
|
+
for (const c of node.childNodes) forget(c);
|
|
70
|
+
};
|
|
71
|
+
/** Moves keep the node, but browsers drop focus from a moved subtree; put it back. */
|
|
72
|
+
const move = (parent, node, before) => {
|
|
73
|
+
const root = container.getRootNode();
|
|
74
|
+
const active = root instanceof ShadowRoot || root instanceof Document ? root.activeElement : null;
|
|
75
|
+
const keep = active && node.contains(active) ? active : null;
|
|
76
|
+
const range = keep instanceof HTMLInputElement || keep instanceof HTMLTextAreaElement ? {
|
|
77
|
+
start: keep.selectionStart,
|
|
78
|
+
end: keep.selectionEnd
|
|
79
|
+
} : null;
|
|
80
|
+
parent.insertBefore(node, before);
|
|
81
|
+
if (keep instanceof HTMLElement || keep instanceof SVGElement) {
|
|
82
|
+
keep.focus({ preventScroll: true });
|
|
83
|
+
if (range && (keep instanceof HTMLInputElement || keep instanceof HTMLTextAreaElement)) try {
|
|
84
|
+
keep.setSelectionRange(range.start, range.end);
|
|
85
|
+
} catch {}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const applyRecord = (r) => {
|
|
89
|
+
switch (r[0]) {
|
|
90
|
+
case "insert": {
|
|
91
|
+
const parent = nodes.get(r[1]);
|
|
92
|
+
if (!parent) return;
|
|
93
|
+
const before = r[3] === null ? null : nodes.get(r[3]) ?? null;
|
|
94
|
+
parent.insertBefore(build(r[2]), before?.parentNode === parent ? before : null);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
case "move": {
|
|
98
|
+
const parent = nodes.get(r[1]);
|
|
99
|
+
const node = nodes.get(r[2]);
|
|
100
|
+
if (!parent || !node) return;
|
|
101
|
+
const before = r[3] === null ? null : nodes.get(r[3]) ?? null;
|
|
102
|
+
move(parent, node, before?.parentNode === parent ? before : null);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
case "remove": {
|
|
106
|
+
const node = nodes.get(r[1]);
|
|
107
|
+
if (!node || r[1] === 0) return;
|
|
108
|
+
node.parentNode?.removeChild(node);
|
|
109
|
+
forget(node);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
case "text": {
|
|
113
|
+
const node = nodes.get(r[1]);
|
|
114
|
+
if (node instanceof CharacterData) node.data = r[2];
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
case "attr": {
|
|
118
|
+
const el = nodes.get(r[1]);
|
|
119
|
+
if (el instanceof Element && el !== container) setAttr(el, r[2], r[3]);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
case "prop": {
|
|
123
|
+
const el = nodes.get(r[1]);
|
|
124
|
+
if (el instanceof Element) setProp(el, r[2], r[3], r[4] === true);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
case "listen":
|
|
128
|
+
if (nodes.has(r[1])) listen(r[1], r[2], r[3]);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
return {
|
|
133
|
+
apply(batch) {
|
|
134
|
+
if (!isDomBatch(batch)) return false;
|
|
135
|
+
for (const r of batch) try {
|
|
136
|
+
applyRecord(r);
|
|
137
|
+
} catch {}
|
|
138
|
+
return true;
|
|
139
|
+
},
|
|
140
|
+
idFor: (node) => ids.get(node),
|
|
141
|
+
nodeFor: (id) => nodes.get(id),
|
|
142
|
+
eventFor(e) {
|
|
143
|
+
const path = e.composedPath();
|
|
144
|
+
let target;
|
|
145
|
+
const currentTargets = [];
|
|
146
|
+
for (const t of path) {
|
|
147
|
+
if (!(t instanceof Node)) continue;
|
|
148
|
+
const id = ids.get(t);
|
|
149
|
+
if (id === void 0) continue;
|
|
150
|
+
target ??= id;
|
|
151
|
+
if (listens.get(id)?.has(e.type)) currentTargets.push(id);
|
|
152
|
+
if (t === container) break;
|
|
153
|
+
}
|
|
154
|
+
if (target === void 0 || currentTargets.length === 0) return null;
|
|
155
|
+
const out = {
|
|
156
|
+
type: e.type,
|
|
157
|
+
target,
|
|
158
|
+
currentTargets,
|
|
159
|
+
mods: NO_MODS
|
|
160
|
+
};
|
|
161
|
+
const el = nodes.get(target);
|
|
162
|
+
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement) out.value = el.value;
|
|
163
|
+
if (el instanceof HTMLInputElement && (el.type === "checkbox" || el.type === "radio")) out.checked = el.checked;
|
|
164
|
+
if (e instanceof MouseEvent || e instanceof KeyboardEvent) out.mods = {
|
|
165
|
+
alt: e.altKey,
|
|
166
|
+
ctrl: e.ctrlKey,
|
|
167
|
+
meta: e.metaKey,
|
|
168
|
+
shift: e.shiftKey
|
|
169
|
+
};
|
|
170
|
+
if (e instanceof KeyboardEvent) {
|
|
171
|
+
out.key = e.key;
|
|
172
|
+
out.code = e.code;
|
|
173
|
+
}
|
|
174
|
+
if (e instanceof MouseEvent) {
|
|
175
|
+
out.x = e.clientX;
|
|
176
|
+
out.y = e.clientY;
|
|
177
|
+
out.button = e.button;
|
|
178
|
+
}
|
|
179
|
+
return out;
|
|
180
|
+
},
|
|
181
|
+
clear() {
|
|
182
|
+
for (const c of Array.from(container.childNodes)) {
|
|
183
|
+
container.removeChild(c);
|
|
184
|
+
forget(c);
|
|
185
|
+
}
|
|
186
|
+
listens.clear();
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
export { createApplier as t };
|