@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
|
@@ -0,0 +1,1051 @@
|
|
|
1
|
+
import "./records-wVZrPpqr.js";
|
|
2
|
+
// src/worker/dom.ts
|
|
3
|
+
const HTML_NS = "http://www.w3.org/1999/xhtml";
|
|
4
|
+
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
5
|
+
/** Strings as the DOM coerces them: numbers and booleans become text, null and undefined empty. */
|
|
6
|
+
const str = (v) => typeof v === "string" ? v : typeof v === "number" || typeof v === "boolean" || typeof v === "bigint" ? String(v) : "";
|
|
7
|
+
const domError = (name, message) => {
|
|
8
|
+
const e = new Error(message);
|
|
9
|
+
e.name = name;
|
|
10
|
+
return e;
|
|
11
|
+
};
|
|
12
|
+
/** Listener storage and capture/bubble dispatch through `isoParentTarget()`. */
|
|
13
|
+
var WEventTarget = class {
|
|
14
|
+
/** @internal */ isoListeners = /* @__PURE__ */ new Map();
|
|
15
|
+
/** @internal */ isoParentTarget() {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
/** @internal Called when the first listener of `type` is added, or the last removed. */
|
|
19
|
+
isoListenChanged(_type, _on) {}
|
|
20
|
+
addEventListener(type, fn, options) {
|
|
21
|
+
if (!fn) return;
|
|
22
|
+
const capture = typeof options === "boolean" ? options : Boolean(options?.capture);
|
|
23
|
+
const once = typeof options === "object" && Boolean(options.once);
|
|
24
|
+
const list = this.isoListeners.get(type) ?? [];
|
|
25
|
+
if (list.some((l) => l.fn === fn && l.capture === capture)) return;
|
|
26
|
+
list.push({
|
|
27
|
+
fn,
|
|
28
|
+
capture,
|
|
29
|
+
once
|
|
30
|
+
});
|
|
31
|
+
this.isoListeners.set(type, list);
|
|
32
|
+
if (list.length === 1) this.isoListenChanged(type, true);
|
|
33
|
+
}
|
|
34
|
+
removeEventListener(type, fn, options) {
|
|
35
|
+
const capture = typeof options === "boolean" ? options : Boolean(options?.capture);
|
|
36
|
+
const list = this.isoListeners.get(type);
|
|
37
|
+
if (!list) return;
|
|
38
|
+
const i = list.findIndex((l) => l.fn === fn && l.capture === capture);
|
|
39
|
+
if (i < 0) return;
|
|
40
|
+
list.splice(i, 1);
|
|
41
|
+
if (list.length === 0) {
|
|
42
|
+
this.isoListeners.delete(type);
|
|
43
|
+
this.isoListenChanged(type, false);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Capture from the top, then the target, then bubble (if `bubbles`). */
|
|
47
|
+
dispatchEvent(event) {
|
|
48
|
+
const path = [this];
|
|
49
|
+
for (let t = this.isoParentTarget(); t; t = t.isoParentTarget()) path.push(t);
|
|
50
|
+
let stopped = false;
|
|
51
|
+
let stoppedNow = false;
|
|
52
|
+
const stop = event.stopPropagation.bind(event);
|
|
53
|
+
const stopNow = event.stopImmediatePropagation.bind(event);
|
|
54
|
+
Object.defineProperties(event, {
|
|
55
|
+
target: {
|
|
56
|
+
value: this,
|
|
57
|
+
configurable: true
|
|
58
|
+
},
|
|
59
|
+
srcElement: {
|
|
60
|
+
value: this,
|
|
61
|
+
configurable: true
|
|
62
|
+
},
|
|
63
|
+
stopPropagation: {
|
|
64
|
+
value: () => {
|
|
65
|
+
stopped = true;
|
|
66
|
+
stop();
|
|
67
|
+
},
|
|
68
|
+
configurable: true
|
|
69
|
+
},
|
|
70
|
+
stopImmediatePropagation: {
|
|
71
|
+
value: () => {
|
|
72
|
+
stopped = true;
|
|
73
|
+
stoppedNow = true;
|
|
74
|
+
stopNow();
|
|
75
|
+
},
|
|
76
|
+
configurable: true
|
|
77
|
+
},
|
|
78
|
+
composedPath: {
|
|
79
|
+
value: () => path.slice(),
|
|
80
|
+
configurable: true
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
const invoke = (t, phase, capture) => {
|
|
84
|
+
Object.defineProperties(event, {
|
|
85
|
+
currentTarget: {
|
|
86
|
+
value: t,
|
|
87
|
+
configurable: true
|
|
88
|
+
},
|
|
89
|
+
eventPhase: {
|
|
90
|
+
value: phase,
|
|
91
|
+
configurable: true
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
for (const l of (t.isoListeners.get(event.type) ?? []).slice()) {
|
|
95
|
+
if (capture !== null && l.capture !== capture) continue;
|
|
96
|
+
if (l.once) t.removeEventListener(event.type, l.fn, l.capture);
|
|
97
|
+
if (typeof l.fn === "function") l.fn.call(t, event);
|
|
98
|
+
else l.fn.handleEvent(event);
|
|
99
|
+
if (stoppedNow) return;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const phases = [];
|
|
103
|
+
for (let i = path.length - 1; i > 0; i--) {
|
|
104
|
+
const t = path[i];
|
|
105
|
+
if (t) phases.push([
|
|
106
|
+
t,
|
|
107
|
+
1,
|
|
108
|
+
true
|
|
109
|
+
]);
|
|
110
|
+
}
|
|
111
|
+
phases.push([
|
|
112
|
+
this,
|
|
113
|
+
2,
|
|
114
|
+
null
|
|
115
|
+
]);
|
|
116
|
+
if (event.bubbles) for (const t of path.slice(1)) phases.push([
|
|
117
|
+
t,
|
|
118
|
+
3,
|
|
119
|
+
false
|
|
120
|
+
]);
|
|
121
|
+
for (const [t, phase, capture] of phases) {
|
|
122
|
+
if (stopped) break;
|
|
123
|
+
invoke(t, phase, capture);
|
|
124
|
+
}
|
|
125
|
+
Object.defineProperties(event, {
|
|
126
|
+
currentTarget: {
|
|
127
|
+
value: null,
|
|
128
|
+
configurable: true
|
|
129
|
+
},
|
|
130
|
+
eventPhase: {
|
|
131
|
+
value: 0,
|
|
132
|
+
configurable: true
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
return !event.defaultPrevented;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
var WNode = class extends WEventTarget {
|
|
139
|
+
static ELEMENT_NODE = 1;
|
|
140
|
+
static TEXT_NODE = 3;
|
|
141
|
+
static COMMENT_NODE = 8;
|
|
142
|
+
static DOCUMENT_NODE = 9;
|
|
143
|
+
static DOCUMENT_FRAGMENT_NODE = 11;
|
|
144
|
+
ELEMENT_NODE = 1;
|
|
145
|
+
TEXT_NODE = 3;
|
|
146
|
+
COMMENT_NODE = 8;
|
|
147
|
+
DOCUMENT_FRAGMENT_NODE = 11;
|
|
148
|
+
ownerDocument;
|
|
149
|
+
/** @internal */ isoId;
|
|
150
|
+
/** @internal */ isoParent = null;
|
|
151
|
+
/** @internal */ isoPrev = null;
|
|
152
|
+
/** @internal */ isoNext = null;
|
|
153
|
+
/** @internal Whether the host knows this node (it's in the tree under the root). */
|
|
154
|
+
isoKnown = false;
|
|
155
|
+
constructor(doc, id) {
|
|
156
|
+
super();
|
|
157
|
+
this.ownerDocument = doc;
|
|
158
|
+
this.isoId = id;
|
|
159
|
+
}
|
|
160
|
+
/** @internal */ isoParentTarget() {
|
|
161
|
+
return this.isoParent;
|
|
162
|
+
}
|
|
163
|
+
/** @internal */ isoListenChanged(type, on) {
|
|
164
|
+
if (this.isoKnown) this.ownerDocument.isoCore.record([
|
|
165
|
+
"listen",
|
|
166
|
+
this.isoId,
|
|
167
|
+
type,
|
|
168
|
+
on
|
|
169
|
+
]);
|
|
170
|
+
}
|
|
171
|
+
get parentNode() {
|
|
172
|
+
return this.isoParent;
|
|
173
|
+
}
|
|
174
|
+
get parentElement() {
|
|
175
|
+
return this.isoParent instanceof WElement ? this.isoParent : null;
|
|
176
|
+
}
|
|
177
|
+
get nextSibling() {
|
|
178
|
+
return this.isoNext;
|
|
179
|
+
}
|
|
180
|
+
get previousSibling() {
|
|
181
|
+
return this.isoPrev;
|
|
182
|
+
}
|
|
183
|
+
get firstChild() {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
get lastChild() {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
get childNodes() {
|
|
190
|
+
return [];
|
|
191
|
+
}
|
|
192
|
+
get isConnected() {
|
|
193
|
+
return this.isoKnown;
|
|
194
|
+
}
|
|
195
|
+
hasChildNodes() {
|
|
196
|
+
return this.firstChild !== null;
|
|
197
|
+
}
|
|
198
|
+
contains(other) {
|
|
199
|
+
for (let n = other; n; n = n.isoParent) if (n === this) return true;
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
remove() {
|
|
203
|
+
this.isoParent?.removeChild(this);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
/** What text and comment nodes share: `data`, changed with a `text` record. */
|
|
207
|
+
var WCharacterData = class extends WNode {
|
|
208
|
+
/** @internal */ isoData;
|
|
209
|
+
constructor(doc, id, data) {
|
|
210
|
+
super(doc, id);
|
|
211
|
+
this.isoData = data;
|
|
212
|
+
}
|
|
213
|
+
get data() {
|
|
214
|
+
return this.isoData;
|
|
215
|
+
}
|
|
216
|
+
set data(v) {
|
|
217
|
+
const data = str(v);
|
|
218
|
+
if (data === this.isoData) return;
|
|
219
|
+
this.isoData = data;
|
|
220
|
+
if (this.isoKnown) this.ownerDocument.isoCore.record([
|
|
221
|
+
"text",
|
|
222
|
+
this.isoId,
|
|
223
|
+
data
|
|
224
|
+
]);
|
|
225
|
+
}
|
|
226
|
+
get length() {
|
|
227
|
+
return this.isoData.length;
|
|
228
|
+
}
|
|
229
|
+
get textContent() {
|
|
230
|
+
return this.isoData;
|
|
231
|
+
}
|
|
232
|
+
set textContent(v) {
|
|
233
|
+
this.data = v ?? "";
|
|
234
|
+
}
|
|
235
|
+
get nodeValue() {
|
|
236
|
+
return this.isoData;
|
|
237
|
+
}
|
|
238
|
+
set nodeValue(v) {
|
|
239
|
+
this.data = v ?? "";
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
var WText = class extends WCharacterData {
|
|
243
|
+
nodeType = 3;
|
|
244
|
+
nodeName = "#text";
|
|
245
|
+
};
|
|
246
|
+
/** A comment node (DOM group 1, ADR 0010): rendered on the host, inert there. */
|
|
247
|
+
var WComment = class extends WCharacterData {
|
|
248
|
+
nodeType = 8;
|
|
249
|
+
nodeName = "#comment";
|
|
250
|
+
};
|
|
251
|
+
/** `element.style`: property writes and setProperty, kept as the `style` attribute. */
|
|
252
|
+
const kebab = (name) => name.startsWith("--") ? name : name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
253
|
+
function createStyle(el) {
|
|
254
|
+
const decls = /* @__PURE__ */ new Map();
|
|
255
|
+
const write = () => {
|
|
256
|
+
const text = [...decls].map(([k, v]) => `${k}: ${v};`).join(" ");
|
|
257
|
+
if (text) el.setAttribute("style", text);
|
|
258
|
+
else el.removeAttribute("style");
|
|
259
|
+
};
|
|
260
|
+
const set = (name, value) => {
|
|
261
|
+
const v = str(value);
|
|
262
|
+
if (v === "") decls.delete(name);
|
|
263
|
+
else decls.set(name, v);
|
|
264
|
+
};
|
|
265
|
+
return new Proxy({
|
|
266
|
+
setProperty(name, value) {
|
|
267
|
+
set(kebab(name), value);
|
|
268
|
+
write();
|
|
269
|
+
},
|
|
270
|
+
removeProperty(name) {
|
|
271
|
+
const old = decls.get(kebab(name)) ?? "";
|
|
272
|
+
decls.delete(kebab(name));
|
|
273
|
+
write();
|
|
274
|
+
return old;
|
|
275
|
+
},
|
|
276
|
+
getPropertyValue(name) {
|
|
277
|
+
return decls.get(kebab(name)) ?? "";
|
|
278
|
+
},
|
|
279
|
+
get cssText() {
|
|
280
|
+
return [...decls].map(([k, v]) => `${k}: ${v};`).join(" ");
|
|
281
|
+
},
|
|
282
|
+
set cssText(text) {
|
|
283
|
+
decls.clear();
|
|
284
|
+
for (const part of text.split(";")) {
|
|
285
|
+
const i = part.indexOf(":");
|
|
286
|
+
if (i > 0) set(part.slice(0, i).trim(), part.slice(i + 1).trim());
|
|
287
|
+
}
|
|
288
|
+
write();
|
|
289
|
+
}
|
|
290
|
+
}, {
|
|
291
|
+
get(t, key, receiver) {
|
|
292
|
+
if (typeof key !== "string" || key in t) return Reflect.get(t, key, receiver);
|
|
293
|
+
return decls.get(kebab(key === "cssFloat" ? "float" : key)) ?? "";
|
|
294
|
+
},
|
|
295
|
+
set(t, key, value, receiver) {
|
|
296
|
+
if (typeof key !== "string" || key in t) return Reflect.set(t, key, value, receiver);
|
|
297
|
+
set(kebab(key === "cssFloat" ? "float" : key), value);
|
|
298
|
+
write();
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* `element.classList` (DOM group 1, ADR 0010): a view of the `class`
|
|
305
|
+
* attribute, so every write travels as an `attr` record.
|
|
306
|
+
*/
|
|
307
|
+
var WDOMTokenList = class {
|
|
308
|
+
/** @internal */ isoEl;
|
|
309
|
+
constructor(el) {
|
|
310
|
+
this.isoEl = el;
|
|
311
|
+
}
|
|
312
|
+
/** @internal */ isoTokens() {
|
|
313
|
+
const tokens = [];
|
|
314
|
+
for (const t of (this.isoEl.getAttribute("class") ?? "").split(/[\t\n\f\r ]+/)) if (t !== "" && !tokens.includes(t)) tokens.push(t);
|
|
315
|
+
return tokens;
|
|
316
|
+
}
|
|
317
|
+
/** @internal */ isoWrite(tokens) {
|
|
318
|
+
this.isoEl.setAttribute("class", tokens.join(" "));
|
|
319
|
+
}
|
|
320
|
+
get length() {
|
|
321
|
+
return this.isoTokens().length;
|
|
322
|
+
}
|
|
323
|
+
get value() {
|
|
324
|
+
return this.isoEl.getAttribute("class") ?? "";
|
|
325
|
+
}
|
|
326
|
+
set value(v) {
|
|
327
|
+
this.isoEl.setAttribute("class", v);
|
|
328
|
+
}
|
|
329
|
+
item(i) {
|
|
330
|
+
return this.isoTokens()[i] ?? null;
|
|
331
|
+
}
|
|
332
|
+
contains(token) {
|
|
333
|
+
return this.isoTokens().includes(token);
|
|
334
|
+
}
|
|
335
|
+
add(...tokens) {
|
|
336
|
+
const list = this.isoTokens();
|
|
337
|
+
for (const t of tokens) if (!list.includes(t)) list.push(t);
|
|
338
|
+
this.isoWrite(list);
|
|
339
|
+
}
|
|
340
|
+
remove(...tokens) {
|
|
341
|
+
this.isoWrite(this.isoTokens().filter((t) => !tokens.includes(t)));
|
|
342
|
+
}
|
|
343
|
+
toggle(token, force) {
|
|
344
|
+
const has = this.contains(token);
|
|
345
|
+
const on = force ?? !has;
|
|
346
|
+
if (on && !has) this.add(token);
|
|
347
|
+
else if (!on && has) this.remove(token);
|
|
348
|
+
return on;
|
|
349
|
+
}
|
|
350
|
+
replace(token, next) {
|
|
351
|
+
const list = this.isoTokens();
|
|
352
|
+
const i = list.indexOf(token);
|
|
353
|
+
if (i < 0) return false;
|
|
354
|
+
list[i] = next;
|
|
355
|
+
this.isoWrite(list.filter((t, j) => list.indexOf(t) === j));
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
toString() {
|
|
359
|
+
return this.value;
|
|
360
|
+
}
|
|
361
|
+
[Symbol.iterator]() {
|
|
362
|
+
return this.isoTokens()[Symbol.iterator]();
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
const dataAttr = (key) => `data-${key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)}`;
|
|
366
|
+
const dataKey = (attr) => attr.slice(5).replace(/-([a-z])/g, (_m, c) => c.toUpperCase());
|
|
367
|
+
/**
|
|
368
|
+
* `element.dataset` (DOM group 1, ADR 0010): camelCase keys over the
|
|
369
|
+
* `data-*` attributes, so every write travels as an `attr` record.
|
|
370
|
+
*/
|
|
371
|
+
function createDataset(el) {
|
|
372
|
+
return new Proxy({}, {
|
|
373
|
+
get: (_t, key) => typeof key === "string" ? el.getAttribute(dataAttr(key)) ?? void 0 : void 0,
|
|
374
|
+
set(_t, key, value) {
|
|
375
|
+
if (typeof key !== "string") return false;
|
|
376
|
+
el.setAttribute(dataAttr(key), value);
|
|
377
|
+
return true;
|
|
378
|
+
},
|
|
379
|
+
deleteProperty(_t, key) {
|
|
380
|
+
if (typeof key === "string") el.removeAttribute(dataAttr(key));
|
|
381
|
+
return true;
|
|
382
|
+
},
|
|
383
|
+
has: (_t, key) => typeof key === "string" && el.hasAttribute(dataAttr(key)),
|
|
384
|
+
ownKeys: () => [...el.isoAttrs.keys()].filter((n) => n.startsWith("data-")).map(dataKey),
|
|
385
|
+
getOwnPropertyDescriptor(_t, key) {
|
|
386
|
+
if (typeof key !== "string" || !el.hasAttribute(dataAttr(key))) return void 0;
|
|
387
|
+
return {
|
|
388
|
+
value: el.getAttribute(dataAttr(key)),
|
|
389
|
+
writable: true,
|
|
390
|
+
enumerable: true,
|
|
391
|
+
configurable: true
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* What elements and fragments share: an ordered child list. Changes under a
|
|
398
|
+
* known parent become records; a fragment is never known.
|
|
399
|
+
*/
|
|
400
|
+
var WParentNode = class extends WNode {
|
|
401
|
+
/** @internal */ isoFirst = null;
|
|
402
|
+
/** @internal */ isoLast = null;
|
|
403
|
+
/** @internal */ isoChildCache = null;
|
|
404
|
+
get firstChild() {
|
|
405
|
+
return this.isoFirst;
|
|
406
|
+
}
|
|
407
|
+
get lastChild() {
|
|
408
|
+
return this.isoLast;
|
|
409
|
+
}
|
|
410
|
+
get childNodes() {
|
|
411
|
+
if (!this.isoChildCache) {
|
|
412
|
+
const list = [];
|
|
413
|
+
for (let n = this.isoFirst; n; n = n.isoNext) list.push(n);
|
|
414
|
+
this.isoChildCache = list;
|
|
415
|
+
}
|
|
416
|
+
return this.isoChildCache;
|
|
417
|
+
}
|
|
418
|
+
get children() {
|
|
419
|
+
return this.childNodes.filter((n) => n instanceof WElement);
|
|
420
|
+
}
|
|
421
|
+
get firstElementChild() {
|
|
422
|
+
return this.children[0] ?? null;
|
|
423
|
+
}
|
|
424
|
+
/** Text of the subtree; comments don't count, as in the DOM. */
|
|
425
|
+
get textContent() {
|
|
426
|
+
let out = "";
|
|
427
|
+
for (let n = this.isoFirst; n; n = n.isoNext) if (!(n instanceof WComment)) out += n.textContent;
|
|
428
|
+
return out;
|
|
429
|
+
}
|
|
430
|
+
set textContent(v) {
|
|
431
|
+
this.replaceChildren(...v ? [this.ownerDocument.createTextNode(v)] : []);
|
|
432
|
+
}
|
|
433
|
+
appendChild(child) {
|
|
434
|
+
return this.insertBefore(child, null);
|
|
435
|
+
}
|
|
436
|
+
insertBefore(child, ref) {
|
|
437
|
+
if (!(child instanceof WNode)) throw new TypeError("insertBefore: not a node");
|
|
438
|
+
if (ref && ref.isoParent !== this) throw domError("NotFoundError", "insertBefore: the reference node is not a child");
|
|
439
|
+
if (child.contains(this)) throw domError("HierarchyRequestError", "insertBefore: would create a cycle");
|
|
440
|
+
if (ref === child) ref = child.isoNext;
|
|
441
|
+
if (child instanceof WDocumentFragment) {
|
|
442
|
+
for (const c of child.childNodes) this.insertBefore(c, ref);
|
|
443
|
+
return child;
|
|
444
|
+
}
|
|
445
|
+
if (this.ownerDocument.head === this && child instanceof WElement) this.ownerDocument.isoCore.onHead(child.localName);
|
|
446
|
+
const wasKnown = child.isoKnown;
|
|
447
|
+
child.isoParent?.isoUnlink(child);
|
|
448
|
+
this.isoLink(child, ref);
|
|
449
|
+
const core = this.ownerDocument.isoCore;
|
|
450
|
+
if (wasKnown && this.isoKnown) core.record([
|
|
451
|
+
"move",
|
|
452
|
+
this.isoId,
|
|
453
|
+
child.isoId,
|
|
454
|
+
ref?.isoId ?? null
|
|
455
|
+
]);
|
|
456
|
+
else if (wasKnown) {
|
|
457
|
+
core.record(["remove", child.isoId]);
|
|
458
|
+
forget(child, core);
|
|
459
|
+
} else if (this.isoKnown) {
|
|
460
|
+
core.record([
|
|
461
|
+
"insert",
|
|
462
|
+
this.isoId,
|
|
463
|
+
serialize(child),
|
|
464
|
+
ref?.isoId ?? null
|
|
465
|
+
]);
|
|
466
|
+
learn(child, core);
|
|
467
|
+
}
|
|
468
|
+
return child;
|
|
469
|
+
}
|
|
470
|
+
removeChild(child) {
|
|
471
|
+
if (child.isoParent !== this) throw domError("NotFoundError", "removeChild: not a child");
|
|
472
|
+
this.isoUnlink(child);
|
|
473
|
+
if (child.isoKnown) {
|
|
474
|
+
const core = this.ownerDocument.isoCore;
|
|
475
|
+
core.record(["remove", child.isoId]);
|
|
476
|
+
forget(child, core);
|
|
477
|
+
}
|
|
478
|
+
return child;
|
|
479
|
+
}
|
|
480
|
+
replaceChildren(...nodes) {
|
|
481
|
+
while (this.isoLast) this.removeChild(this.isoLast);
|
|
482
|
+
this.append(...nodes);
|
|
483
|
+
}
|
|
484
|
+
append(...nodes) {
|
|
485
|
+
for (const n of nodes) this.appendChild(typeof n === "string" ? this.ownerDocument.createTextNode(n) : n);
|
|
486
|
+
}
|
|
487
|
+
/** @internal */ isoUnlink(child) {
|
|
488
|
+
if (child.isoPrev) child.isoPrev.isoNext = child.isoNext;
|
|
489
|
+
else this.isoFirst = child.isoNext;
|
|
490
|
+
if (child.isoNext) child.isoNext.isoPrev = child.isoPrev;
|
|
491
|
+
else this.isoLast = child.isoPrev;
|
|
492
|
+
child.isoParent = null;
|
|
493
|
+
child.isoPrev = null;
|
|
494
|
+
child.isoNext = null;
|
|
495
|
+
this.isoChildCache = null;
|
|
496
|
+
}
|
|
497
|
+
/** @internal */ isoLink(child, ref) {
|
|
498
|
+
child.isoParent = this;
|
|
499
|
+
child.isoNext = ref;
|
|
500
|
+
child.isoPrev = ref ? ref.isoPrev : this.isoLast;
|
|
501
|
+
if (child.isoPrev) child.isoPrev.isoNext = child;
|
|
502
|
+
else this.isoFirst = child;
|
|
503
|
+
if (ref) ref.isoPrev = child;
|
|
504
|
+
else this.isoLast = child;
|
|
505
|
+
this.isoChildCache = null;
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
/**
|
|
509
|
+
* `DocumentFragment` (DOM group 1, ADR 0010): a detached holder. Inserting
|
|
510
|
+
* it inserts its children, in order, and empties it; it never reaches the
|
|
511
|
+
* host itself.
|
|
512
|
+
*/
|
|
513
|
+
var WDocumentFragment = class extends WParentNode {
|
|
514
|
+
nodeType = 11;
|
|
515
|
+
nodeName = "#document-fragment";
|
|
516
|
+
get nodeValue() {
|
|
517
|
+
return null;
|
|
518
|
+
}
|
|
519
|
+
set nodeValue(_v) {}
|
|
520
|
+
};
|
|
521
|
+
var WElement = class extends WParentNode {
|
|
522
|
+
nodeType = 1;
|
|
523
|
+
localName;
|
|
524
|
+
namespaceURI;
|
|
525
|
+
/** @internal */ isoNs;
|
|
526
|
+
/** @internal */ isoAttrs = /* @__PURE__ */ new Map();
|
|
527
|
+
/** @internal */ isoProps = /* @__PURE__ */ new Map();
|
|
528
|
+
/** @internal */ isoStyle = null;
|
|
529
|
+
/** @internal */ isoClassList = null;
|
|
530
|
+
/** @internal */ isoDataset = null;
|
|
531
|
+
constructor(doc, id, localName, ns) {
|
|
532
|
+
super(doc, id);
|
|
533
|
+
this.localName = localName;
|
|
534
|
+
this.isoNs = ns;
|
|
535
|
+
this.namespaceURI = ns === "svg" ? SVG_NS : HTML_NS;
|
|
536
|
+
}
|
|
537
|
+
get tagName() {
|
|
538
|
+
return this.isoNs === "html" ? this.localName.toUpperCase() : this.localName;
|
|
539
|
+
}
|
|
540
|
+
get nodeName() {
|
|
541
|
+
return this.tagName;
|
|
542
|
+
}
|
|
543
|
+
get nodeValue() {
|
|
544
|
+
return null;
|
|
545
|
+
}
|
|
546
|
+
set nodeValue(_v) {}
|
|
547
|
+
get attributes() {
|
|
548
|
+
return [...this.isoAttrs].map(([name, value]) => ({
|
|
549
|
+
name,
|
|
550
|
+
value
|
|
551
|
+
}));
|
|
552
|
+
}
|
|
553
|
+
getAttribute(name) {
|
|
554
|
+
return this.isoAttrs.get(this.isoAttrName(name)) ?? null;
|
|
555
|
+
}
|
|
556
|
+
hasAttribute(name) {
|
|
557
|
+
return this.isoAttrs.has(this.isoAttrName(name));
|
|
558
|
+
}
|
|
559
|
+
setAttribute(name, value) {
|
|
560
|
+
const n = this.isoAttrName(name);
|
|
561
|
+
const v = str(value);
|
|
562
|
+
if (this.isoAttrs.get(n) === v) return;
|
|
563
|
+
this.isoAttrs.set(n, v);
|
|
564
|
+
if (this.isoKnown) this.ownerDocument.isoCore.record([
|
|
565
|
+
"attr",
|
|
566
|
+
this.isoId,
|
|
567
|
+
n,
|
|
568
|
+
v
|
|
569
|
+
]);
|
|
570
|
+
}
|
|
571
|
+
removeAttribute(name) {
|
|
572
|
+
const n = this.isoAttrName(name);
|
|
573
|
+
if (!this.isoAttrs.delete(n)) return;
|
|
574
|
+
if (this.isoKnown) this.ownerDocument.isoCore.record([
|
|
575
|
+
"attr",
|
|
576
|
+
this.isoId,
|
|
577
|
+
n,
|
|
578
|
+
null
|
|
579
|
+
]);
|
|
580
|
+
}
|
|
581
|
+
/** @internal HTML attribute names are case-insensitive; SVG ones aren't. */
|
|
582
|
+
isoAttrName(name) {
|
|
583
|
+
return this.isoNs === "html" ? name.toLowerCase() : name;
|
|
584
|
+
}
|
|
585
|
+
get style() {
|
|
586
|
+
this.isoStyle ??= createStyle(this);
|
|
587
|
+
return this.isoStyle;
|
|
588
|
+
}
|
|
589
|
+
get classList() {
|
|
590
|
+
this.isoClassList ??= new WDOMTokenList(this);
|
|
591
|
+
return this.isoClassList;
|
|
592
|
+
}
|
|
593
|
+
get dataset() {
|
|
594
|
+
this.isoDataset ??= createDataset(this);
|
|
595
|
+
return this.isoDataset;
|
|
596
|
+
}
|
|
597
|
+
get id() {
|
|
598
|
+
return this.getAttribute("id") ?? "";
|
|
599
|
+
}
|
|
600
|
+
set id(v) {
|
|
601
|
+
this.setAttribute("id", v);
|
|
602
|
+
}
|
|
603
|
+
/** @internal */ isoSetProp(name, value, record) {
|
|
604
|
+
if (this.isoProps.get(name) === value) return;
|
|
605
|
+
this.isoProps.set(name, value);
|
|
606
|
+
if (record && this.isoKnown) this.ownerDocument.isoCore.record([
|
|
607
|
+
"prop",
|
|
608
|
+
this.isoId,
|
|
609
|
+
name,
|
|
610
|
+
value
|
|
611
|
+
]);
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
/**
|
|
615
|
+
* Event handler properties (`onclick`…), as in the DOM's GlobalEventHandlers.
|
|
616
|
+
* Frameworks check `'oninput' in document` and `'onclick' in el` to learn
|
|
617
|
+
* event names (React's input events, Preact 10's lowercasing); setting one
|
|
618
|
+
* adds the handler as a listener, as in the DOM.
|
|
619
|
+
*/
|
|
620
|
+
const HANDLER_EVENTS = [
|
|
621
|
+
"abort",
|
|
622
|
+
"animationend",
|
|
623
|
+
"animationiteration",
|
|
624
|
+
"animationstart",
|
|
625
|
+
"auxclick",
|
|
626
|
+
"beforeinput",
|
|
627
|
+
"blur",
|
|
628
|
+
"cancel",
|
|
629
|
+
"change",
|
|
630
|
+
"click",
|
|
631
|
+
"close",
|
|
632
|
+
"contextmenu",
|
|
633
|
+
"copy",
|
|
634
|
+
"cut",
|
|
635
|
+
"dblclick",
|
|
636
|
+
"drag",
|
|
637
|
+
"dragend",
|
|
638
|
+
"dragenter",
|
|
639
|
+
"dragleave",
|
|
640
|
+
"dragover",
|
|
641
|
+
"dragstart",
|
|
642
|
+
"drop",
|
|
643
|
+
"error",
|
|
644
|
+
"focus",
|
|
645
|
+
"input",
|
|
646
|
+
"invalid",
|
|
647
|
+
"keydown",
|
|
648
|
+
"keypress",
|
|
649
|
+
"keyup",
|
|
650
|
+
"load",
|
|
651
|
+
"mousedown",
|
|
652
|
+
"mouseenter",
|
|
653
|
+
"mouseleave",
|
|
654
|
+
"mousemove",
|
|
655
|
+
"mouseout",
|
|
656
|
+
"mouseover",
|
|
657
|
+
"mouseup",
|
|
658
|
+
"paste",
|
|
659
|
+
"pointercancel",
|
|
660
|
+
"pointerdown",
|
|
661
|
+
"pointerenter",
|
|
662
|
+
"pointerleave",
|
|
663
|
+
"pointermove",
|
|
664
|
+
"pointerout",
|
|
665
|
+
"pointerover",
|
|
666
|
+
"pointerup",
|
|
667
|
+
"reset",
|
|
668
|
+
"resize",
|
|
669
|
+
"scroll",
|
|
670
|
+
"select",
|
|
671
|
+
"submit",
|
|
672
|
+
"toggle",
|
|
673
|
+
"touchcancel",
|
|
674
|
+
"touchend",
|
|
675
|
+
"touchmove",
|
|
676
|
+
"touchstart",
|
|
677
|
+
"transitionend",
|
|
678
|
+
"wheel"
|
|
679
|
+
];
|
|
680
|
+
function defineHandlers(proto) {
|
|
681
|
+
const handlers = /* @__PURE__ */ new WeakMap();
|
|
682
|
+
for (const type of HANDLER_EVENTS) Object.defineProperty(proto, `on${type}`, {
|
|
683
|
+
configurable: true,
|
|
684
|
+
enumerable: true,
|
|
685
|
+
get() {
|
|
686
|
+
return handlers.get(this)?.get(type) ?? null;
|
|
687
|
+
},
|
|
688
|
+
set(fn) {
|
|
689
|
+
const own = handlers.get(this) ?? /* @__PURE__ */ new Map();
|
|
690
|
+
handlers.set(this, own);
|
|
691
|
+
const old = own.get(type);
|
|
692
|
+
if (old) this.removeEventListener(type, old);
|
|
693
|
+
if (typeof fn === "function") {
|
|
694
|
+
const handler = (e) => {
|
|
695
|
+
Reflect.apply(fn, this, [e]);
|
|
696
|
+
};
|
|
697
|
+
own.set(type, handler);
|
|
698
|
+
this.addEventListener(type, handler);
|
|
699
|
+
} else own.delete(type);
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
defineHandlers(WElement.prototype);
|
|
704
|
+
var WHTMLElement = class extends WElement {};
|
|
705
|
+
var WSVGElement = class extends WElement {};
|
|
706
|
+
/** Only for `instanceof` checks; never created by the host (the registry drops iframes). */
|
|
707
|
+
var WHTMLIFrameElement = class extends WHTMLElement {};
|
|
708
|
+
var WHTMLInputElement = class extends WHTMLElement {
|
|
709
|
+
get value() {
|
|
710
|
+
const v = this.isoProps.get("value");
|
|
711
|
+
return typeof v === "string" ? v : this.getAttribute("value") ?? "";
|
|
712
|
+
}
|
|
713
|
+
set value(v) {
|
|
714
|
+
this.isoSetProp("value", str(v), true);
|
|
715
|
+
}
|
|
716
|
+
get checked() {
|
|
717
|
+
const v = this.isoProps.get("checked");
|
|
718
|
+
return typeof v === "boolean" ? v : this.hasAttribute("checked");
|
|
719
|
+
}
|
|
720
|
+
set checked(v) {
|
|
721
|
+
this.isoSetProp("checked", Boolean(v), true);
|
|
722
|
+
}
|
|
723
|
+
get defaultValue() {
|
|
724
|
+
return this.getAttribute("value") ?? "";
|
|
725
|
+
}
|
|
726
|
+
set defaultValue(v) {
|
|
727
|
+
this.setAttribute("value", v);
|
|
728
|
+
}
|
|
729
|
+
get defaultChecked() {
|
|
730
|
+
return this.hasAttribute("checked");
|
|
731
|
+
}
|
|
732
|
+
set defaultChecked(v) {
|
|
733
|
+
if (v) this.setAttribute("checked", "");
|
|
734
|
+
else this.removeAttribute("checked");
|
|
735
|
+
}
|
|
736
|
+
get name() {
|
|
737
|
+
return this.getAttribute("name") ?? "";
|
|
738
|
+
}
|
|
739
|
+
set name(v) {
|
|
740
|
+
this.setAttribute("name", v);
|
|
741
|
+
}
|
|
742
|
+
get type() {
|
|
743
|
+
return this.getAttribute("type") ?? "text";
|
|
744
|
+
}
|
|
745
|
+
set type(v) {
|
|
746
|
+
this.setAttribute("type", v);
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
var WHTMLTextAreaElement = class extends WHTMLElement {
|
|
750
|
+
get value() {
|
|
751
|
+
const v = this.isoProps.get("value");
|
|
752
|
+
return typeof v === "string" ? v : this.textContent;
|
|
753
|
+
}
|
|
754
|
+
set value(v) {
|
|
755
|
+
this.isoSetProp("value", str(v), true);
|
|
756
|
+
}
|
|
757
|
+
get defaultValue() {
|
|
758
|
+
return this.textContent;
|
|
759
|
+
}
|
|
760
|
+
set defaultValue(v) {
|
|
761
|
+
this.textContent = v;
|
|
762
|
+
}
|
|
763
|
+
get name() {
|
|
764
|
+
return this.getAttribute("name") ?? "";
|
|
765
|
+
}
|
|
766
|
+
set name(v) {
|
|
767
|
+
this.setAttribute("name", v);
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
var WHTMLSelectElement = class extends WHTMLElement {
|
|
771
|
+
/** The `<option>`s under the select, `<optgroup>`s included, in tree order. React walks it. */
|
|
772
|
+
get options() {
|
|
773
|
+
const out = [];
|
|
774
|
+
const walk = (el) => {
|
|
775
|
+
for (const c of el.children) if (c instanceof WHTMLOptionElement) out.push(c);
|
|
776
|
+
else if (c.localName === "optgroup") walk(c);
|
|
777
|
+
};
|
|
778
|
+
walk(this);
|
|
779
|
+
return out;
|
|
780
|
+
}
|
|
781
|
+
get multiple() {
|
|
782
|
+
return this.hasAttribute("multiple");
|
|
783
|
+
}
|
|
784
|
+
set multiple(v) {
|
|
785
|
+
if (v) this.setAttribute("multiple", "");
|
|
786
|
+
else this.removeAttribute("multiple");
|
|
787
|
+
}
|
|
788
|
+
get value() {
|
|
789
|
+
const v = this.isoProps.get("value");
|
|
790
|
+
return typeof v === "string" ? v : "";
|
|
791
|
+
}
|
|
792
|
+
set value(v) {
|
|
793
|
+
this.isoSetProp("value", str(v), true);
|
|
794
|
+
}
|
|
795
|
+
get name() {
|
|
796
|
+
return this.getAttribute("name") ?? "";
|
|
797
|
+
}
|
|
798
|
+
set name(v) {
|
|
799
|
+
this.setAttribute("name", v);
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
var WHTMLOptionElement = class extends WHTMLElement {
|
|
803
|
+
/** The `value` attribute, or the text when there's none, as in the DOM. */
|
|
804
|
+
get value() {
|
|
805
|
+
return this.getAttribute("value") ?? this.textContent;
|
|
806
|
+
}
|
|
807
|
+
set value(v) {
|
|
808
|
+
this.setAttribute("value", v);
|
|
809
|
+
}
|
|
810
|
+
get selected() {
|
|
811
|
+
const v = this.isoProps.get("selected");
|
|
812
|
+
return typeof v === "boolean" ? v : this.hasAttribute("selected");
|
|
813
|
+
}
|
|
814
|
+
set selected(v) {
|
|
815
|
+
this.isoSetProp("selected", Boolean(v), true);
|
|
816
|
+
}
|
|
817
|
+
get defaultSelected() {
|
|
818
|
+
return this.hasAttribute("selected");
|
|
819
|
+
}
|
|
820
|
+
set defaultSelected(v) {
|
|
821
|
+
if (v) this.setAttribute("selected", "");
|
|
822
|
+
else this.removeAttribute("selected");
|
|
823
|
+
}
|
|
824
|
+
get disabled() {
|
|
825
|
+
return this.hasAttribute("disabled");
|
|
826
|
+
}
|
|
827
|
+
set disabled(v) {
|
|
828
|
+
if (v) this.setAttribute("disabled", "");
|
|
829
|
+
else this.removeAttribute("disabled");
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
const HTML_CLASSES = {
|
|
833
|
+
input: WHTMLInputElement,
|
|
834
|
+
textarea: WHTMLTextAreaElement,
|
|
835
|
+
select: WHTMLSelectElement,
|
|
836
|
+
option: WHTMLOptionElement,
|
|
837
|
+
iframe: WHTMLIFrameElement
|
|
838
|
+
};
|
|
839
|
+
var WDocument = class extends WEventTarget {
|
|
840
|
+
nodeType = 9;
|
|
841
|
+
nodeName = "#document";
|
|
842
|
+
/** @internal */ isoCore;
|
|
843
|
+
/** Set by `install()`: the worker global. */
|
|
844
|
+
defaultView = null;
|
|
845
|
+
activeElement = null;
|
|
846
|
+
/** `null`, as for every document. */
|
|
847
|
+
ownerDocument = null;
|
|
848
|
+
/** A detached body, for code that falls back to `document.body`. */
|
|
849
|
+
body;
|
|
850
|
+
/**
|
|
851
|
+
* A detached head: React 19 hoists `<title>`, `<meta>` and `<link>` into
|
|
852
|
+
* it. The bridge doesn't render it (M3a task 3).
|
|
853
|
+
*/
|
|
854
|
+
head;
|
|
855
|
+
constructor(core) {
|
|
856
|
+
super();
|
|
857
|
+
this.isoCore = core;
|
|
858
|
+
this.body = new WHTMLElement(this, -1, "body", "html");
|
|
859
|
+
this.head = new WHTMLElement(this, -2, "head", "html");
|
|
860
|
+
}
|
|
861
|
+
createElement(tag) {
|
|
862
|
+
const t = tag.toLowerCase();
|
|
863
|
+
return new ((Object.hasOwn(HTML_CLASSES, t) ? HTML_CLASSES[t] : void 0) ?? WHTMLElement)(this, this.isoCore.nextId++, t, "html");
|
|
864
|
+
}
|
|
865
|
+
createElementNS(ns, tag) {
|
|
866
|
+
if (ns === SVG_NS) return new WSVGElement(this, this.isoCore.nextId++, tag, "svg");
|
|
867
|
+
if (ns === HTML_NS || ns === null) return this.createElement(tag);
|
|
868
|
+
throw domError("NotSupportedError", `createElementNS: namespace ${ns} isn't supported`);
|
|
869
|
+
}
|
|
870
|
+
/** `data` is converted with `String()`, as in the DOM: Preact passes numbers. */
|
|
871
|
+
createTextNode(data) {
|
|
872
|
+
return new WText(this, this.isoCore.nextId++, String(data));
|
|
873
|
+
}
|
|
874
|
+
createComment(data) {
|
|
875
|
+
return new WComment(this, this.isoCore.nextId++, String(data));
|
|
876
|
+
}
|
|
877
|
+
/** Fragments never reach the host, so they take no id from the shared counter. */
|
|
878
|
+
createDocumentFragment() {
|
|
879
|
+
return new WDocumentFragment(this, -3);
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* The first element in tree order with this `id` (DOM group 1, ADR 0010):
|
|
883
|
+
* under the render root, then the detached head. Nodes not yet inserted
|
|
884
|
+
* aren't in the document, so they aren't found.
|
|
885
|
+
*/
|
|
886
|
+
getElementById(id) {
|
|
887
|
+
const walk = (el) => {
|
|
888
|
+
for (const c of el.children) {
|
|
889
|
+
if (c.getAttribute("id") === id) return c;
|
|
890
|
+
const deeper = walk(c);
|
|
891
|
+
if (deeper) return deeper;
|
|
892
|
+
}
|
|
893
|
+
return null;
|
|
894
|
+
};
|
|
895
|
+
const root = this.isoCore.root;
|
|
896
|
+
return (root ? walk(root) : null) ?? walk(this.head);
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Type selectors only, alone or as a `head > title` child chain: what React
|
|
900
|
+
* 19 asks when it hoists a `<title>`. Queries in general are DOM group 2
|
|
901
|
+
* (ADR 0010), built when a library needs them; anything else throws.
|
|
902
|
+
*/
|
|
903
|
+
querySelector(selector) {
|
|
904
|
+
const steps = selector.split(">").map((t) => t.trim().toLowerCase());
|
|
905
|
+
if (!steps.every((t) => /^[a-z][a-z0-9-]*$/.test(t))) throw domError("NotSupportedError", `querySelector: "${selector}" isn't supported yet`);
|
|
906
|
+
const matches = (el) => {
|
|
907
|
+
let n = el;
|
|
908
|
+
for (let i = steps.length - 1; i >= 0; i--) {
|
|
909
|
+
if (!n || n.localName !== steps[i]) return false;
|
|
910
|
+
n = i > 0 ? n.parentElement : null;
|
|
911
|
+
}
|
|
912
|
+
return true;
|
|
913
|
+
};
|
|
914
|
+
const walk = (el) => {
|
|
915
|
+
for (const c of el.children) {
|
|
916
|
+
if (matches(c)) return c;
|
|
917
|
+
const deeper = walk(c);
|
|
918
|
+
if (deeper) return deeper;
|
|
919
|
+
}
|
|
920
|
+
return null;
|
|
921
|
+
};
|
|
922
|
+
for (const top of [this.head, this.body]) {
|
|
923
|
+
if (matches(top)) return top;
|
|
924
|
+
const hit = walk(top);
|
|
925
|
+
if (hit) return hit;
|
|
926
|
+
}
|
|
927
|
+
return null;
|
|
928
|
+
}
|
|
929
|
+
};
|
|
930
|
+
defineHandlers(WDocument.prototype);
|
|
931
|
+
/** The subtree as `insert` sends it. */
|
|
932
|
+
function serialize(n) {
|
|
933
|
+
if (n instanceof WText) return {
|
|
934
|
+
k: "text",
|
|
935
|
+
id: n.isoId,
|
|
936
|
+
data: n.isoData
|
|
937
|
+
};
|
|
938
|
+
if (n instanceof WComment) return {
|
|
939
|
+
k: "comment",
|
|
940
|
+
id: n.isoId,
|
|
941
|
+
data: n.isoData
|
|
942
|
+
};
|
|
943
|
+
if (!(n instanceof WElement)) throw new TypeError("serialize: unknown node");
|
|
944
|
+
return {
|
|
945
|
+
k: "el",
|
|
946
|
+
id: n.isoId,
|
|
947
|
+
tag: n.localName,
|
|
948
|
+
ns: n.isoNs,
|
|
949
|
+
attrs: [...n.isoAttrs],
|
|
950
|
+
props: [...n.isoProps],
|
|
951
|
+
listen: [...n.isoListeners.keys()],
|
|
952
|
+
children: n.childNodes.map(serialize)
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
function learn(n, core) {
|
|
956
|
+
n.isoKnown = true;
|
|
957
|
+
core.known.set(n.isoId, n);
|
|
958
|
+
for (const c of n.childNodes) learn(c, core);
|
|
959
|
+
}
|
|
960
|
+
function forget(n, core) {
|
|
961
|
+
n.isoKnown = false;
|
|
962
|
+
core.known.delete(n.isoId);
|
|
963
|
+
for (const c of n.childNodes) forget(c, core);
|
|
964
|
+
}
|
|
965
|
+
function createDom(opts) {
|
|
966
|
+
const schedule = opts.schedule ?? ((fn) => queueMicrotask(fn));
|
|
967
|
+
let pending = [];
|
|
968
|
+
let scheduled = false;
|
|
969
|
+
const flush = () => {
|
|
970
|
+
scheduled = false;
|
|
971
|
+
if (pending.length === 0) return;
|
|
972
|
+
const batch = pending;
|
|
973
|
+
pending = [];
|
|
974
|
+
opts.onBatch(batch);
|
|
975
|
+
};
|
|
976
|
+
const core = {
|
|
977
|
+
root: null,
|
|
978
|
+
nextId: 1,
|
|
979
|
+
known: /* @__PURE__ */ new Map(),
|
|
980
|
+
onHead: opts.onHead ?? (() => {}),
|
|
981
|
+
record(r) {
|
|
982
|
+
pending.push(r);
|
|
983
|
+
if (!scheduled) {
|
|
984
|
+
scheduled = true;
|
|
985
|
+
schedule(flush);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
};
|
|
989
|
+
const document = new WDocument(core);
|
|
990
|
+
const root = new WHTMLElement(document, 0, "iso-root", "html");
|
|
991
|
+
root.isoKnown = true;
|
|
992
|
+
core.known.set(0, root);
|
|
993
|
+
core.root = root;
|
|
994
|
+
return {
|
|
995
|
+
document,
|
|
996
|
+
root,
|
|
997
|
+
flush,
|
|
998
|
+
idOf: (node) => node.isoId,
|
|
999
|
+
setValue(node, value, o = {}) {
|
|
1000
|
+
if (!(node instanceof WHTMLInputElement || node instanceof WHTMLTextAreaElement || node instanceof WHTMLSelectElement)) throw new TypeError("setValue: not an input, textarea or select");
|
|
1001
|
+
if (!o.force) {
|
|
1002
|
+
node.value = value;
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
node.isoSetProp("value", value, false);
|
|
1006
|
+
if (node.isoKnown) core.record([
|
|
1007
|
+
"prop",
|
|
1008
|
+
node.isoId,
|
|
1009
|
+
"value",
|
|
1010
|
+
value,
|
|
1011
|
+
true
|
|
1012
|
+
]);
|
|
1013
|
+
},
|
|
1014
|
+
deliver(event) {
|
|
1015
|
+
const node = core.known.get(event.target);
|
|
1016
|
+
if (!node) return;
|
|
1017
|
+
if ((node instanceof WHTMLInputElement || node instanceof WHTMLTextAreaElement || node instanceof WHTMLSelectElement) && event.value !== void 0) node.isoSetProp("value", event.value, false);
|
|
1018
|
+
if (node instanceof WHTMLInputElement && event.checked !== void 0) node.isoSetProp("checked", event.checked, false);
|
|
1019
|
+
node.dispatchEvent(toEvent(event));
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
/** A real `Event` with the fields frameworks read from mouse and keyboard events. */
|
|
1024
|
+
function toEvent(e) {
|
|
1025
|
+
const ev = new Event(e.type, {
|
|
1026
|
+
bubbles: true,
|
|
1027
|
+
cancelable: true
|
|
1028
|
+
});
|
|
1029
|
+
const mods = {
|
|
1030
|
+
Alt: e.mods.alt,
|
|
1031
|
+
Control: e.mods.ctrl,
|
|
1032
|
+
Meta: e.mods.meta,
|
|
1033
|
+
Shift: e.mods.shift
|
|
1034
|
+
};
|
|
1035
|
+
Object.defineProperties(ev, {
|
|
1036
|
+
altKey: { value: e.mods.alt },
|
|
1037
|
+
ctrlKey: { value: e.mods.ctrl },
|
|
1038
|
+
metaKey: { value: e.mods.meta },
|
|
1039
|
+
shiftKey: { value: e.mods.shift },
|
|
1040
|
+
getModifierState: { value: (k) => mods[k] ?? false },
|
|
1041
|
+
key: { value: e.key },
|
|
1042
|
+
code: { value: e.code },
|
|
1043
|
+
button: { value: e.button ?? 0 },
|
|
1044
|
+
clientX: { value: e.x ?? 0 },
|
|
1045
|
+
clientY: { value: e.y ?? 0 },
|
|
1046
|
+
width: { value: e.width },
|
|
1047
|
+
height: { value: e.height }
|
|
1048
|
+
});
|
|
1049
|
+
return ev;
|
|
1050
|
+
}
|
|
1051
|
+
export { WText as _, WDocumentFragment as a, WHTMLElement as c, WHTMLOptionElement as d, WHTMLSelectElement as f, WSVGElement as g, WParentNode as h, WDocument as i, WHTMLIFrameElement as l, WNode as m, WComment as n, WElement as o, WHTMLTextAreaElement as p, WDOMTokenList as r, WEventTarget as s, WCharacterData as t, WHTMLInputElement as u, createDom as v };
|