@isoloop/runtime 0.0.0-next.f57e259 → 0.0.0-next.g3322248
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/dist/bootstrap.js +495 -54
- package/dist/worker.js +2648 -0
- package/package.json +12 -4
package/dist/worker.js
ADDED
|
@@ -0,0 +1,2648 @@
|
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __esmMin = (fn, res, err) => () => {
|
|
4
|
+
if (err) throw err[0];
|
|
5
|
+
try {
|
|
6
|
+
return fn && (res = fn(fn = 0)), res;
|
|
7
|
+
} catch (e) {
|
|
8
|
+
throw err = [e], e;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var __exportAll = (all, flags) => {
|
|
12
|
+
let target = Object.setPrototypeOf({}, null);
|
|
13
|
+
for (var name in all) __defProp(target, name, {
|
|
14
|
+
get: all[name],
|
|
15
|
+
enumerable: true
|
|
16
|
+
});
|
|
17
|
+
if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
18
|
+
return flags & 2 ? target : Object.preventExtensions(target);
|
|
19
|
+
};
|
|
20
|
+
// ../protocol/dist/index.js
|
|
21
|
+
/**
|
|
22
|
+
* True for a well-formed envelope this build can read: `v` is a supported
|
|
23
|
+
* version, `t` is a string, `id`/`re`/`isolate` are absent or strings, and `p`
|
|
24
|
+
* is present.
|
|
25
|
+
* Says nothing about whether `t` is known; see the per-port guards.
|
|
26
|
+
*/
|
|
27
|
+
function isEnvelope(x) {
|
|
28
|
+
return isRecord(x) && x["v"] === PROTOCOL.v && typeof x["t"] === "string" && "p" in x && isOptionalString(x["id"]) && isOptionalString(x["re"]) && isOptionalString(x["isolate"]);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Builds a guard for one port's union from its message types. Each side drops
|
|
32
|
+
* (and counts) envelopes with an unknown `v` or `t` (design §3), so a guard
|
|
33
|
+
* only checks the envelope and the type, not the payload.
|
|
34
|
+
*/
|
|
35
|
+
function envelopeGuard(types) {
|
|
36
|
+
return (x) => isEnvelope(x) && Object.hasOwn(types, x.t);
|
|
37
|
+
}
|
|
38
|
+
function isSystemTopic(topic) {
|
|
39
|
+
return topic.startsWith(SYSTEM_TOPIC_PREFIX);
|
|
40
|
+
}
|
|
41
|
+
function createCommitter(o) {
|
|
42
|
+
const intervalMs = o.intervalMs ?? 100;
|
|
43
|
+
const half = Math.max(1, Math.floor((o.credit ?? 1e3) / 2));
|
|
44
|
+
/** Highest settled offset per topic, not yet sent. */
|
|
45
|
+
const offsets = /* @__PURE__ */ new Map();
|
|
46
|
+
/** Records settled per topic since its last send: the early send at half the credit. */
|
|
47
|
+
const counts = /* @__PURE__ */ new Map();
|
|
48
|
+
let timer;
|
|
49
|
+
let queued = false;
|
|
50
|
+
const take = () => {
|
|
51
|
+
if (timer !== void 0) {
|
|
52
|
+
clearTimeout(timer);
|
|
53
|
+
timer = void 0;
|
|
54
|
+
}
|
|
55
|
+
queued = false;
|
|
56
|
+
if (offsets.size === 0) return void 0;
|
|
57
|
+
const out = [];
|
|
58
|
+
for (const [topic, offset] of offsets) out.push({
|
|
59
|
+
topic,
|
|
60
|
+
offset
|
|
61
|
+
});
|
|
62
|
+
offsets.clear();
|
|
63
|
+
counts.clear();
|
|
64
|
+
return out;
|
|
65
|
+
};
|
|
66
|
+
const flush = () => {
|
|
67
|
+
const out = take();
|
|
68
|
+
if (out) o.send(out);
|
|
69
|
+
};
|
|
70
|
+
const schedule = () => {
|
|
71
|
+
if (intervalMs === 0) {
|
|
72
|
+
if (queued) return;
|
|
73
|
+
queued = true;
|
|
74
|
+
queueMicrotask(() => {
|
|
75
|
+
if (queued) flush();
|
|
76
|
+
});
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
timer ??= setTimeout(flush, intervalMs);
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
settle(topic, offset, records = 1) {
|
|
83
|
+
const prev = offsets.get(topic);
|
|
84
|
+
if (prev === void 0 || offset > prev) offsets.set(topic, offset);
|
|
85
|
+
const n = (counts.get(topic) ?? 0) + records;
|
|
86
|
+
counts.set(topic, n);
|
|
87
|
+
if (n >= half) flush();
|
|
88
|
+
else schedule();
|
|
89
|
+
},
|
|
90
|
+
flush,
|
|
91
|
+
take,
|
|
92
|
+
drop(topic) {
|
|
93
|
+
offsets.delete(topic);
|
|
94
|
+
counts.delete(topic);
|
|
95
|
+
},
|
|
96
|
+
pending: () => offsets,
|
|
97
|
+
dispose() {
|
|
98
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
99
|
+
timer = void 0;
|
|
100
|
+
queued = false;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** Wraps a hand-written check as a Standard Schema that passes valid values through unchanged. */
|
|
105
|
+
function systemSchema(check) {
|
|
106
|
+
return { "~standard": {
|
|
107
|
+
version: 1,
|
|
108
|
+
vendor: "isoloop",
|
|
109
|
+
validate: (value) => {
|
|
110
|
+
const issues = check(value, []);
|
|
111
|
+
return issues.length === 0 ? { value } : { issues };
|
|
112
|
+
}
|
|
113
|
+
} };
|
|
114
|
+
}
|
|
115
|
+
/** Defines a system topic. The name must start with `isoloop.`. */
|
|
116
|
+
function systemTopic(name, def) {
|
|
117
|
+
if (!isSystemTopic(name)) throw new Error(`system topic names start with isoloop.: ${name}`);
|
|
118
|
+
return Object.freeze({
|
|
119
|
+
...def,
|
|
120
|
+
name
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/** `"0.4.2"` → `"0.4"`. Anything that isn't `major.minor[.patch…]` gives `undefined`. */
|
|
124
|
+
function majorMinor(version) {
|
|
125
|
+
const m = /^(\d+)\.(\d+)(?:[.+-].*)?$/.exec(version);
|
|
126
|
+
return m ? `${Number(m[1])}.${Number(m[2])}` : void 0;
|
|
127
|
+
}
|
|
128
|
+
var PROTOCOL, isRecord, isOptionalString, ERROR_CODES, SYSTEM_TOPIC_PREFIX, HOST_TO_ISOLATE, isHostToIsolate, BUS_TO_ISOLATE, isBusToIsolate, BusError, isObject, issue, checks, stringOrNull;
|
|
129
|
+
var init_dist = __esmMin((() => {
|
|
130
|
+
PROTOCOL = {
|
|
131
|
+
v: 1,
|
|
132
|
+
min: 1
|
|
133
|
+
};
|
|
134
|
+
isRecord = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
|
|
135
|
+
isOptionalString = (x) => x === void 0 || typeof x === "string";
|
|
136
|
+
ERROR_CODES = [
|
|
137
|
+
"protocol_mismatch",
|
|
138
|
+
"timeout",
|
|
139
|
+
"no_surface",
|
|
140
|
+
"forbidden",
|
|
141
|
+
"not_found",
|
|
142
|
+
"unsupported",
|
|
143
|
+
"cross_origin",
|
|
144
|
+
"routing_disabled",
|
|
145
|
+
"navigate_failed",
|
|
146
|
+
"unknown_topic",
|
|
147
|
+
"too_large",
|
|
148
|
+
"invalid",
|
|
149
|
+
"not_encodable",
|
|
150
|
+
"quota_exceeded",
|
|
151
|
+
"bus_unavailable",
|
|
152
|
+
"not_requestable",
|
|
153
|
+
"already_replied",
|
|
154
|
+
"reply_invalid",
|
|
155
|
+
"contracts_failed",
|
|
156
|
+
"contracts_invalid",
|
|
157
|
+
"contracts_mismatch",
|
|
158
|
+
"reserved_topic",
|
|
159
|
+
"seed_async",
|
|
160
|
+
"seed_pending"
|
|
161
|
+
];
|
|
162
|
+
new Set(ERROR_CODES);
|
|
163
|
+
SYSTEM_TOPIC_PREFIX = "isoloop.";
|
|
164
|
+
HOST_TO_ISOLATE = {
|
|
165
|
+
init: true,
|
|
166
|
+
event: true,
|
|
167
|
+
result: true,
|
|
168
|
+
shutdown: true,
|
|
169
|
+
reattach: true
|
|
170
|
+
};
|
|
171
|
+
isHostToIsolate = envelopeGuard(HOST_TO_ISOLATE);
|
|
172
|
+
BUS_TO_ISOLATE = {
|
|
173
|
+
deliver: true,
|
|
174
|
+
reset: true,
|
|
175
|
+
result: true
|
|
176
|
+
};
|
|
177
|
+
isBusToIsolate = envelopeGuard(BUS_TO_ISOLATE);
|
|
178
|
+
BusError = class extends Error {
|
|
179
|
+
code;
|
|
180
|
+
issues;
|
|
181
|
+
constructor(error) {
|
|
182
|
+
super(error.message);
|
|
183
|
+
this.name = "BusError";
|
|
184
|
+
this.code = error.code;
|
|
185
|
+
this.issues = error.issues;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
189
|
+
issue = (path, message) => [{
|
|
190
|
+
message,
|
|
191
|
+
path
|
|
192
|
+
}];
|
|
193
|
+
checks = {
|
|
194
|
+
string: (v, path) => typeof v === "string" ? [] : issue(path, "expected a string"),
|
|
195
|
+
optionalString: (v, path) => v === void 0 || typeof v === "string" ? [] : issue(path, "expected a string or nothing"),
|
|
196
|
+
object: (fields) => (v, path) => {
|
|
197
|
+
if (!isObject(v)) return issue(path, "expected an object");
|
|
198
|
+
return Object.entries(fields).flatMap(([k, check]) => check(v[k], [...path, k]));
|
|
199
|
+
},
|
|
200
|
+
any: () => []
|
|
201
|
+
};
|
|
202
|
+
stringOrNull = (v, path) => v === null || typeof v === "string" ? [] : [{
|
|
203
|
+
message: "expected a string or null",
|
|
204
|
+
path
|
|
205
|
+
}];
|
|
206
|
+
systemTopic("isoloop.route.v1", {
|
|
207
|
+
schema: systemSchema(checks.object({
|
|
208
|
+
href: checks.string,
|
|
209
|
+
pathname: checks.string,
|
|
210
|
+
path: stringOrNull,
|
|
211
|
+
search: checks.string,
|
|
212
|
+
hash: checks.string,
|
|
213
|
+
state: checks.any
|
|
214
|
+
})),
|
|
215
|
+
retention: { kind: "compacted" }
|
|
216
|
+
});
|
|
217
|
+
}));
|
|
218
|
+
// src/busy.ts
|
|
219
|
+
function createBusy(now = () => performance.now()) {
|
|
220
|
+
let frame = null;
|
|
221
|
+
const spent = /* @__PURE__ */ new Map();
|
|
222
|
+
const containers = /* @__PURE__ */ new WeakMap();
|
|
223
|
+
const bill = (key, ms) => {
|
|
224
|
+
spent.set(key, (spent.get(key) ?? 0) + ms);
|
|
225
|
+
};
|
|
226
|
+
const settle = (f) => {
|
|
227
|
+
const fallback = f.owner.key === PENDING ? null : f.owner.key;
|
|
228
|
+
if (f.pending) for (const o of f.pending) o.key = fallback;
|
|
229
|
+
if (f.roots && f.roots.length > 0) {
|
|
230
|
+
const unique = [...new Set(f.roots)];
|
|
231
|
+
const share = f.spent / unique.length;
|
|
232
|
+
for (const key of unique) bill(key, share);
|
|
233
|
+
} else if (fallback !== null) bill(fallback, f.spent);
|
|
234
|
+
};
|
|
235
|
+
const busy = {
|
|
236
|
+
run(owner, fn, self, args) {
|
|
237
|
+
const t = now();
|
|
238
|
+
const outer = frame;
|
|
239
|
+
if (outer) outer.spent += t - outer.start;
|
|
240
|
+
const f = {
|
|
241
|
+
owner,
|
|
242
|
+
start: t,
|
|
243
|
+
spent: 0,
|
|
244
|
+
parent: outer,
|
|
245
|
+
roots: null,
|
|
246
|
+
pending: null
|
|
247
|
+
};
|
|
248
|
+
frame = f;
|
|
249
|
+
try {
|
|
250
|
+
return fn.apply(self, args);
|
|
251
|
+
} finally {
|
|
252
|
+
const end = now();
|
|
253
|
+
f.spent += end - f.start;
|
|
254
|
+
frame = outer;
|
|
255
|
+
if (outer) outer.start = end;
|
|
256
|
+
settle(f);
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
capture() {
|
|
260
|
+
const f = frame;
|
|
261
|
+
if (!f) return { key: null };
|
|
262
|
+
const o = { key: PENDING };
|
|
263
|
+
(f.pending ??= []).push(o);
|
|
264
|
+
return o;
|
|
265
|
+
},
|
|
266
|
+
of: (key) => ({ key }),
|
|
267
|
+
bind(fn) {
|
|
268
|
+
const owner = busy.capture();
|
|
269
|
+
return (...args) => busy.run(owner, fn, void 0, args);
|
|
270
|
+
},
|
|
271
|
+
report(key) {
|
|
272
|
+
const f = frame;
|
|
273
|
+
if (!f) return;
|
|
274
|
+
(f.roots ??= []).push(key);
|
|
275
|
+
if (f.pending) {
|
|
276
|
+
for (const o of f.pending) o.key = key;
|
|
277
|
+
f.pending = null;
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
take(key) {
|
|
281
|
+
const ms = spent.get(key) ?? 0;
|
|
282
|
+
spent.delete(key);
|
|
283
|
+
return ms;
|
|
284
|
+
},
|
|
285
|
+
claim(container, key) {
|
|
286
|
+
containers.set(container, key);
|
|
287
|
+
},
|
|
288
|
+
keyOf(container) {
|
|
289
|
+
if (typeof container !== "object" || container === null) return null;
|
|
290
|
+
return containers.has(container) ? containers.get(container) ?? void 0 : null;
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
return busy;
|
|
294
|
+
}
|
|
295
|
+
/** Keeps a wrapper's `name` and `length` the native function's. */
|
|
296
|
+
function like(wrapper, native) {
|
|
297
|
+
Object.defineProperty(wrapper, "name", {
|
|
298
|
+
value: native.name,
|
|
299
|
+
configurable: true
|
|
300
|
+
});
|
|
301
|
+
Object.defineProperty(wrapper, "length", {
|
|
302
|
+
value: native.length,
|
|
303
|
+
configurable: true
|
|
304
|
+
});
|
|
305
|
+
return wrapper;
|
|
306
|
+
}
|
|
307
|
+
/** `f` as a callback, when it is a function: schedulers call any function. */
|
|
308
|
+
function callable(f) {
|
|
309
|
+
return typeof f === "function" ? f : null;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* `cb` run as `owner` when the scheduler calls it, with the scheduler's `this`
|
|
313
|
+
* and arguments. Always in a frame, even for nobody: a shared framework's
|
|
314
|
+
* task (React's scheduler port, set up while its module loaded) still splits
|
|
315
|
+
* among the roots it reports.
|
|
316
|
+
*/
|
|
317
|
+
function billed(busy, owner, cb) {
|
|
318
|
+
return function(...args) {
|
|
319
|
+
return busy.run(owner, cb, this, args);
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Wraps a scheduling function on `scope` so the callback in argument 0 is
|
|
324
|
+
* billed to the owner current at registration. Everything else (the return
|
|
325
|
+
* value, ids, `clear*`, other arguments) is the native's.
|
|
326
|
+
*/
|
|
327
|
+
function wrapScheduler(scope, name, busy) {
|
|
328
|
+
const native = Reflect.get(scope, name);
|
|
329
|
+
if (typeof native !== "function") return;
|
|
330
|
+
const wrapper = like(function(...args) {
|
|
331
|
+
const cb = callable(args[0]);
|
|
332
|
+
if (cb) args[0] = billed(busy, busy.capture(), cb);
|
|
333
|
+
return Reflect.apply(native, this ?? scope, args);
|
|
334
|
+
}, native);
|
|
335
|
+
Reflect.set(scope, name, wrapper);
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Wraps `MessagePort`'s `onmessage` and its `message` listeners, so a port
|
|
339
|
+
* a member creates (a scheduler's `MessageChannel`, say) bills its messages
|
|
340
|
+
* to that member. `onmessage` still reads back the function that was set,
|
|
341
|
+
* and `removeEventListener` still removes what `addEventListener` added.
|
|
342
|
+
*/
|
|
343
|
+
function wrapPorts(scope, busy) {
|
|
344
|
+
const Port = Reflect.get(scope, "MessagePort");
|
|
345
|
+
if (typeof Port !== "function") return;
|
|
346
|
+
const proto = Reflect.get(Port, "prototype");
|
|
347
|
+
if (typeof proto !== "object" || proto === null) return;
|
|
348
|
+
const on = Object.getOwnPropertyDescriptor(proto, "onmessage");
|
|
349
|
+
const get = callable(on ? Reflect.get(on, "get") : void 0);
|
|
350
|
+
const set = callable(on ? Reflect.get(on, "set") : void 0);
|
|
351
|
+
if (on && get && set) {
|
|
352
|
+
/** What each port's `onmessage` was set to, as read back. */
|
|
353
|
+
const assigned = /* @__PURE__ */ new WeakMap();
|
|
354
|
+
Object.defineProperty(proto, "onmessage", {
|
|
355
|
+
configurable: true,
|
|
356
|
+
enumerable: on.enumerable ?? true,
|
|
357
|
+
get: like(function() {
|
|
358
|
+
if (typeof this === "object" && this !== null && assigned.has(this)) return assigned.get(this);
|
|
359
|
+
return get.call(this);
|
|
360
|
+
}, get),
|
|
361
|
+
set: like(function(fn) {
|
|
362
|
+
if (typeof this === "object" && this !== null) assigned.set(this, fn);
|
|
363
|
+
const cb = callable(fn);
|
|
364
|
+
set.call(this, cb ? billed(busy, busy.capture(), cb) : fn);
|
|
365
|
+
}, set)
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
const add = callable(Reflect.get(proto, "addEventListener"));
|
|
369
|
+
const remove = callable(Reflect.get(proto, "removeEventListener"));
|
|
370
|
+
if (!add || !remove) return;
|
|
371
|
+
/** Per port, per listener and capture flag: the wrapper `addEventListener` was given. */
|
|
372
|
+
const added = /* @__PURE__ */ new WeakMap();
|
|
373
|
+
Object.defineProperty(proto, "addEventListener", {
|
|
374
|
+
configurable: true,
|
|
375
|
+
writable: true,
|
|
376
|
+
enumerable: true,
|
|
377
|
+
value: like(function(...args) {
|
|
378
|
+
const [type, listener, options] = args;
|
|
379
|
+
if (type !== "message" && type !== "messageerror" || !isListener(listener) || typeof this !== "object" || this === null) return add.apply(this, args);
|
|
380
|
+
const capture = captureOf(options);
|
|
381
|
+
let byListener = added.get(this);
|
|
382
|
+
if (!byListener) added.set(this, byListener = /* @__PURE__ */ new Map());
|
|
383
|
+
let byCapture = byListener.get(listener);
|
|
384
|
+
if (!byCapture) byListener.set(listener, byCapture = /* @__PURE__ */ new Map());
|
|
385
|
+
let wrapper = byCapture.get(capture);
|
|
386
|
+
if (!wrapper) {
|
|
387
|
+
const fn = callable(listener);
|
|
388
|
+
const call = function(e) {
|
|
389
|
+
if (fn) return fn.call(this, e);
|
|
390
|
+
return callable(Reflect.get(listener, "handleEvent"))?.call(listener, e);
|
|
391
|
+
};
|
|
392
|
+
wrapper = billed(busy, busy.capture(), call);
|
|
393
|
+
byCapture.set(capture, wrapper);
|
|
394
|
+
}
|
|
395
|
+
return add.apply(this, [
|
|
396
|
+
type,
|
|
397
|
+
wrapper,
|
|
398
|
+
...args.slice(2)
|
|
399
|
+
]);
|
|
400
|
+
}, add)
|
|
401
|
+
});
|
|
402
|
+
Object.defineProperty(proto, "removeEventListener", {
|
|
403
|
+
configurable: true,
|
|
404
|
+
writable: true,
|
|
405
|
+
enumerable: true,
|
|
406
|
+
value: like(function(...args) {
|
|
407
|
+
const [type, listener, options] = args;
|
|
408
|
+
const byCapture = typeof this === "object" && this !== null && isListener(listener) ? added.get(this)?.get(listener) : void 0;
|
|
409
|
+
const capture = captureOf(options);
|
|
410
|
+
const wrapper = byCapture?.get(capture);
|
|
411
|
+
if (!wrapper || type !== "message" && type !== "messageerror") return remove.apply(this, args);
|
|
412
|
+
byCapture?.delete(capture);
|
|
413
|
+
return remove.apply(this, [
|
|
414
|
+
type,
|
|
415
|
+
wrapper,
|
|
416
|
+
...args.slice(2)
|
|
417
|
+
]);
|
|
418
|
+
}, remove)
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* React's devtools hook, the smallest one react-dom accepts (production
|
|
423
|
+
* builds call it too): it reports each committed root's member, and each
|
|
424
|
+
* root whose passive effects just ran, to the current frame.
|
|
425
|
+
*/
|
|
426
|
+
function installReactHook(scope, busy) {
|
|
427
|
+
const KEY = "__REACT_DEVTOOLS_GLOBAL_HOOK__";
|
|
428
|
+
if (Reflect.get(scope, KEY) !== void 0) return;
|
|
429
|
+
let renderers = 0;
|
|
430
|
+
const committed = (_renderer, root) => {
|
|
431
|
+
if (typeof root !== "object" || root === null) return;
|
|
432
|
+
const key = busy.keyOf(Reflect.get(root, "containerInfo"));
|
|
433
|
+
if (key !== null) busy.report(key);
|
|
434
|
+
};
|
|
435
|
+
Reflect.set(scope, KEY, {
|
|
436
|
+
supportsFiber: true,
|
|
437
|
+
inject: () => ++renderers,
|
|
438
|
+
onCommitFiberRoot: committed,
|
|
439
|
+
onPostCommitFiberRoot: committed,
|
|
440
|
+
onCommitFiberUnmount: () => {},
|
|
441
|
+
checkDCE: () => {}
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Installs attribution on a worker's global, once, before any member loads:
|
|
446
|
+
* the scheduling functions, `MessagePort` listeners and React's hook.
|
|
447
|
+
*/
|
|
448
|
+
function installBusy(scope, busy) {
|
|
449
|
+
const q = Reflect.get(scope, "queueMicrotask");
|
|
450
|
+
if (typeof q === "function") nativeQueueMicrotask = (fn) => {
|
|
451
|
+
Reflect.apply(q, scope, [fn]);
|
|
452
|
+
};
|
|
453
|
+
for (const name of SCHEDULERS) wrapScheduler(scope, name, busy);
|
|
454
|
+
wrapPorts(scope, busy);
|
|
455
|
+
installReactHook(scope, busy);
|
|
456
|
+
}
|
|
457
|
+
var PENDING, SCHEDULERS, captureOf, isListener, nativeQueueMicrotask, busy, BUSY;
|
|
458
|
+
var init_busy = __esmMin((() => {
|
|
459
|
+
PENDING = Symbol("pending");
|
|
460
|
+
SCHEDULERS = [
|
|
461
|
+
"setTimeout",
|
|
462
|
+
"setInterval",
|
|
463
|
+
"requestAnimationFrame",
|
|
464
|
+
"queueMicrotask",
|
|
465
|
+
"requestIdleCallback"
|
|
466
|
+
];
|
|
467
|
+
captureOf = (options) => typeof options === "boolean" ? options : typeof options === "object" && options !== null && Reflect.get(options, "capture") === true;
|
|
468
|
+
isListener = (l) => typeof l === "function" || typeof l === "object" && l !== null && typeof Reflect.get(l, "handleEvent") === "function";
|
|
469
|
+
nativeQueueMicrotask = (fn) => {
|
|
470
|
+
queueMicrotask(fn);
|
|
471
|
+
};
|
|
472
|
+
busy = createBusy();
|
|
473
|
+
BUSY = Symbol.for("isoloop.busy");
|
|
474
|
+
}));
|
|
475
|
+
// src/freeze.ts
|
|
476
|
+
/** The protected properties, per prototype, that are left as frozen data. */
|
|
477
|
+
function protectedProperties() {
|
|
478
|
+
const out = /* @__PURE__ */ new Map();
|
|
479
|
+
const add = (o, ...keys) => {
|
|
480
|
+
if (typeof o !== "object" && typeof o !== "function" || o === null) return;
|
|
481
|
+
out.set(o, /* @__PURE__ */ new Set([...out.get(o) ?? [], ...keys]));
|
|
482
|
+
};
|
|
483
|
+
const typedArrayCtor = Object.getPrototypeOf(Int8Array);
|
|
484
|
+
const typedArray = typeof typedArrayCtor === "function" ? Reflect.get(typedArrayCtor, "prototype") : void 0;
|
|
485
|
+
add(Array.prototype, ITERATOR, "constructor");
|
|
486
|
+
add(Object.getPrototypeOf([][Symbol.iterator]()), "next");
|
|
487
|
+
add(Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())), ITERATOR);
|
|
488
|
+
add(typedArray, ITERATOR, "constructor");
|
|
489
|
+
for (const c of [
|
|
490
|
+
Int8Array,
|
|
491
|
+
Uint8Array,
|
|
492
|
+
Uint8ClampedArray,
|
|
493
|
+
Int16Array,
|
|
494
|
+
Uint16Array,
|
|
495
|
+
Int32Array,
|
|
496
|
+
Uint32Array,
|
|
497
|
+
Float32Array,
|
|
498
|
+
Float64Array,
|
|
499
|
+
BigInt64Array,
|
|
500
|
+
BigUint64Array
|
|
501
|
+
]) add(c.prototype, "constructor");
|
|
502
|
+
add(Map.prototype, ITERATOR);
|
|
503
|
+
add(Object.getPrototypeOf((/* @__PURE__ */ new Map())[Symbol.iterator]()), "next");
|
|
504
|
+
add(Set.prototype, ITERATOR);
|
|
505
|
+
add(Object.getPrototypeOf((/* @__PURE__ */ new Set())[Symbol.iterator]()), "next");
|
|
506
|
+
add(String.prototype, ...Reflect.ownKeys(String.prototype));
|
|
507
|
+
add(Object.getPrototypeOf(""[Symbol.iterator]()), "next");
|
|
508
|
+
add(Promise.prototype, "then", "constructor");
|
|
509
|
+
add(RegExp.prototype, ...Reflect.ownKeys(RegExp.prototype));
|
|
510
|
+
return out;
|
|
511
|
+
}
|
|
512
|
+
function tameOverrides(proto) {
|
|
513
|
+
skip ??= protectedProperties();
|
|
514
|
+
const keep = skip.get(proto);
|
|
515
|
+
for (const key of Reflect.ownKeys(proto)) if (!keep?.has(key)) tameOverride(proto, key);
|
|
516
|
+
}
|
|
517
|
+
function tameOverride(proto, key) {
|
|
518
|
+
const d = Object.getOwnPropertyDescriptor(proto, key);
|
|
519
|
+
if (!d || !("value" in d) || !d.configurable) return;
|
|
520
|
+
const value = d.value;
|
|
521
|
+
Object.defineProperty(proto, key, {
|
|
522
|
+
get() {
|
|
523
|
+
return value;
|
|
524
|
+
},
|
|
525
|
+
set(v) {
|
|
526
|
+
if (this === proto) throw new TypeError(`Cannot assign to read only property '${String(key)}' of a frozen built-in`);
|
|
527
|
+
if (typeof this !== "object" && typeof this !== "function") return;
|
|
528
|
+
if (this === null) return;
|
|
529
|
+
Object.defineProperty(this, key, {
|
|
530
|
+
value: v,
|
|
531
|
+
writable: true,
|
|
532
|
+
enumerable: true,
|
|
533
|
+
configurable: true
|
|
534
|
+
});
|
|
535
|
+
},
|
|
536
|
+
enumerable: d.enumerable ?? false,
|
|
537
|
+
configurable: false
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
function hardenProto(proto) {
|
|
541
|
+
if (typeof proto !== "object" && typeof proto !== "function" || proto === null) return;
|
|
542
|
+
if (Object.isFrozen(proto)) return;
|
|
543
|
+
tameOverrides(proto);
|
|
544
|
+
Object.freeze(proto);
|
|
545
|
+
}
|
|
546
|
+
function freezeWithPrototype(c) {
|
|
547
|
+
if (typeof c !== "function") return;
|
|
548
|
+
hardenProto(Reflect.get(c, "prototype"));
|
|
549
|
+
if (c !== Error) Object.freeze(c);
|
|
550
|
+
}
|
|
551
|
+
/** Freezes the shared intrinsics. Call once, before any member module loads. */
|
|
552
|
+
function freezeBuiltins() {
|
|
553
|
+
const g = globalThis;
|
|
554
|
+
for (const name of NAMES) freezeWithPrototype(Reflect.get(g, name));
|
|
555
|
+
freezeWithPrototype(Object.getPrototypeOf(Int8Array));
|
|
556
|
+
const protos = [
|
|
557
|
+
Object.getPrototypeOf([][Symbol.iterator]()),
|
|
558
|
+
Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())),
|
|
559
|
+
Object.getPrototypeOf((/* @__PURE__ */ new Map())[Symbol.iterator]()),
|
|
560
|
+
Object.getPrototypeOf((/* @__PURE__ */ new Set())[Symbol.iterator]()),
|
|
561
|
+
Object.getPrototypeOf(""[Symbol.iterator]()),
|
|
562
|
+
Object.getPrototypeOf(function* () {}),
|
|
563
|
+
Object.getPrototypeOf(async function() {}),
|
|
564
|
+
Object.getPrototypeOf(async function* () {})
|
|
565
|
+
];
|
|
566
|
+
for (const p of protos) {
|
|
567
|
+
if (typeof p !== "object" && typeof p !== "function" || p === null) continue;
|
|
568
|
+
hardenProto(Reflect.get(p, "prototype"));
|
|
569
|
+
hardenProto(p);
|
|
570
|
+
}
|
|
571
|
+
Object.freeze(Math);
|
|
572
|
+
Object.freeze(JSON);
|
|
573
|
+
Object.freeze(Reflect);
|
|
574
|
+
}
|
|
575
|
+
var NAMES, ITERATOR, skip;
|
|
576
|
+
var init_freeze = __esmMin((() => {
|
|
577
|
+
NAMES = [
|
|
578
|
+
"Object",
|
|
579
|
+
"Function",
|
|
580
|
+
"Array",
|
|
581
|
+
"String",
|
|
582
|
+
"Number",
|
|
583
|
+
"Boolean",
|
|
584
|
+
"Symbol",
|
|
585
|
+
"BigInt",
|
|
586
|
+
"Date",
|
|
587
|
+
"RegExp",
|
|
588
|
+
"Error",
|
|
589
|
+
"EvalError",
|
|
590
|
+
"RangeError",
|
|
591
|
+
"ReferenceError",
|
|
592
|
+
"SyntaxError",
|
|
593
|
+
"TypeError",
|
|
594
|
+
"URIError",
|
|
595
|
+
"AggregateError",
|
|
596
|
+
"Promise",
|
|
597
|
+
"Map",
|
|
598
|
+
"Set",
|
|
599
|
+
"WeakMap",
|
|
600
|
+
"WeakSet",
|
|
601
|
+
"WeakRef",
|
|
602
|
+
"FinalizationRegistry",
|
|
603
|
+
"ArrayBuffer",
|
|
604
|
+
"DataView",
|
|
605
|
+
"Int8Array",
|
|
606
|
+
"Uint8Array",
|
|
607
|
+
"Uint8ClampedArray",
|
|
608
|
+
"Int16Array",
|
|
609
|
+
"Uint16Array",
|
|
610
|
+
"Int32Array",
|
|
611
|
+
"Uint32Array",
|
|
612
|
+
"Float32Array",
|
|
613
|
+
"Float64Array",
|
|
614
|
+
"BigInt64Array",
|
|
615
|
+
"BigUint64Array"
|
|
616
|
+
];
|
|
617
|
+
ITERATOR = Symbol.iterator;
|
|
618
|
+
}));
|
|
619
|
+
// src/bus-client.ts
|
|
620
|
+
function createBusClient(first, o = {}) {
|
|
621
|
+
const limit = o.inboxLimit ?? 1e3;
|
|
622
|
+
const now = o.now ?? (() => performance.now());
|
|
623
|
+
let lastDelivery = now();
|
|
624
|
+
let port = first;
|
|
625
|
+
let nextId = 0;
|
|
626
|
+
const epoch = o.epoch ?? randomEpoch();
|
|
627
|
+
/** Publishes and requests sent by this instance: the `seq` of publish ids. */
|
|
628
|
+
let seq = 0;
|
|
629
|
+
const pending = /* @__PURE__ */ new Map();
|
|
630
|
+
const subs = /* @__PURE__ */ new Map();
|
|
631
|
+
/** Which topic a delivered record came from, for `reply` and `commit`. */
|
|
632
|
+
const topicOf = /* @__PURE__ */ new WeakMap();
|
|
633
|
+
const send = (msg) => {
|
|
634
|
+
port.postMessage(msg);
|
|
635
|
+
};
|
|
636
|
+
const call = (msg) => {
|
|
637
|
+
if (pending.size >= limit) return Promise.resolve({
|
|
638
|
+
ok: false,
|
|
639
|
+
error: {
|
|
640
|
+
code: "bus_unavailable",
|
|
641
|
+
message: "Too many bus calls waiting for an answer"
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
const id = `b${++nextId}`;
|
|
645
|
+
return new Promise((settle) => {
|
|
646
|
+
const withId = {
|
|
647
|
+
...msg,
|
|
648
|
+
id
|
|
649
|
+
};
|
|
650
|
+
pending.set(id, {
|
|
651
|
+
msg: withId,
|
|
652
|
+
settle
|
|
653
|
+
});
|
|
654
|
+
send(withId);
|
|
655
|
+
});
|
|
656
|
+
};
|
|
657
|
+
const committer = createCommitter({
|
|
658
|
+
send: (offsets) => {
|
|
659
|
+
send({
|
|
660
|
+
v: 1,
|
|
661
|
+
t: "commits",
|
|
662
|
+
p: { offsets }
|
|
663
|
+
});
|
|
664
|
+
},
|
|
665
|
+
...o.commitIntervalMs === void 0 ? {} : { intervalMs: o.commitIntervalMs },
|
|
666
|
+
...o.credit === void 0 ? {} : { credit: o.credit }
|
|
667
|
+
});
|
|
668
|
+
const commit = (topic, offset) => {
|
|
669
|
+
committer.settle(topic, offset);
|
|
670
|
+
};
|
|
671
|
+
const drain = async (sub) => {
|
|
672
|
+
if (sub.running) return;
|
|
673
|
+
sub.running = true;
|
|
674
|
+
while (sub.queue.length > 0 && subs.get(sub.topic) === sub) {
|
|
675
|
+
const r = sub.queue.shift();
|
|
676
|
+
if (!r) break;
|
|
677
|
+
topicOf.set(r, sub.topic);
|
|
678
|
+
try {
|
|
679
|
+
const done = sub.fn(r);
|
|
680
|
+
if (isThenable(done)) await done;
|
|
681
|
+
} catch (err) {
|
|
682
|
+
sub.stuck = true;
|
|
683
|
+
o.onError?.(err);
|
|
684
|
+
}
|
|
685
|
+
if (sub.opts.autoCommit !== false && !sub.stuck) commit(sub.topic, r.offset);
|
|
686
|
+
}
|
|
687
|
+
sub.running = false;
|
|
688
|
+
};
|
|
689
|
+
const sendSubscribe = (sub) => {
|
|
690
|
+
const p = {
|
|
691
|
+
topic: sub.topic,
|
|
692
|
+
from: sub.opts.from ?? "latest"
|
|
693
|
+
};
|
|
694
|
+
if (o.wake && p.from === "latest") p.from = "committed";
|
|
695
|
+
if (sub.opts.group !== void 0) p.group = sub.opts.group;
|
|
696
|
+
call({
|
|
697
|
+
v: 1,
|
|
698
|
+
t: "subscribe",
|
|
699
|
+
p
|
|
700
|
+
}).then((r) => {
|
|
701
|
+
if (!r.ok) o.onError?.(new BusError(r.error));
|
|
702
|
+
});
|
|
703
|
+
};
|
|
704
|
+
const receive = (msg) => {
|
|
705
|
+
switch (msg.t) {
|
|
706
|
+
case "result": {
|
|
707
|
+
const p = msg.re === void 0 ? void 0 : pending.get(msg.re);
|
|
708
|
+
if (!p || msg.re === void 0) return;
|
|
709
|
+
pending.delete(msg.re);
|
|
710
|
+
p.settle(msg.p);
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
case "deliver": {
|
|
714
|
+
const sub = subs.get(msg.p.topic);
|
|
715
|
+
if (!sub) return;
|
|
716
|
+
lastDelivery = now();
|
|
717
|
+
const { gap } = msg.p;
|
|
718
|
+
if (gap) try {
|
|
719
|
+
sub.opts.onGap?.(gap);
|
|
720
|
+
} catch (err) {
|
|
721
|
+
o.onError?.(err);
|
|
722
|
+
}
|
|
723
|
+
sub.queue.push(...msg.p.records);
|
|
724
|
+
drain(sub);
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
case "reset": {
|
|
728
|
+
const sub = subs.get(msg.p.topic);
|
|
729
|
+
if (!sub) return;
|
|
730
|
+
sub.queue.length = 0;
|
|
731
|
+
committer.drop(msg.p.topic);
|
|
732
|
+
try {
|
|
733
|
+
sub.opts.onReset?.();
|
|
734
|
+
} catch (err) {
|
|
735
|
+
o.onError?.(err);
|
|
736
|
+
}
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
default: return msg;
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
const listen = (p) => {
|
|
743
|
+
p.addEventListener("message", (e) => {
|
|
744
|
+
if (port === p && isBusToIsolate(e.data)) receive(e.data);
|
|
745
|
+
});
|
|
746
|
+
p.start();
|
|
747
|
+
};
|
|
748
|
+
listen(first);
|
|
749
|
+
return {
|
|
750
|
+
client: {
|
|
751
|
+
async publish(topic, rec) {
|
|
752
|
+
const p = {
|
|
753
|
+
topic: topic.name,
|
|
754
|
+
value: rec.value,
|
|
755
|
+
epoch,
|
|
756
|
+
seq: ++seq
|
|
757
|
+
};
|
|
758
|
+
if (rec.key !== void 0) p.key = rec.key;
|
|
759
|
+
check(await call({
|
|
760
|
+
v: 1,
|
|
761
|
+
t: "publish",
|
|
762
|
+
p
|
|
763
|
+
}));
|
|
764
|
+
},
|
|
765
|
+
subscribe(topic, fn, opts = {}) {
|
|
766
|
+
subs.get(topic.name)?.queue.splice(0);
|
|
767
|
+
const sub = {
|
|
768
|
+
topic: topic.name,
|
|
769
|
+
fn,
|
|
770
|
+
opts,
|
|
771
|
+
queue: [],
|
|
772
|
+
running: false,
|
|
773
|
+
stuck: false
|
|
774
|
+
};
|
|
775
|
+
subs.set(topic.name, sub);
|
|
776
|
+
sendSubscribe(sub);
|
|
777
|
+
return () => {
|
|
778
|
+
if (subs.get(topic.name) !== sub) return;
|
|
779
|
+
subs.delete(topic.name);
|
|
780
|
+
committer.flush();
|
|
781
|
+
send({
|
|
782
|
+
v: 1,
|
|
783
|
+
t: "unsubscribe",
|
|
784
|
+
p: { topic: topic.name }
|
|
785
|
+
});
|
|
786
|
+
};
|
|
787
|
+
},
|
|
788
|
+
async request(topic, value, opts = {}) {
|
|
789
|
+
const timeoutMs = opts.timeoutMs ?? REQUEST_TIMEOUT_MS;
|
|
790
|
+
const p = {
|
|
791
|
+
topic: topic.name,
|
|
792
|
+
value,
|
|
793
|
+
timeoutMs,
|
|
794
|
+
epoch,
|
|
795
|
+
seq: ++seq
|
|
796
|
+
};
|
|
797
|
+
if (opts.key !== void 0) p.key = opts.key;
|
|
798
|
+
let timer;
|
|
799
|
+
const timeout = new Promise((resolve) => {
|
|
800
|
+
timer = setTimeout(() => {
|
|
801
|
+
resolve({
|
|
802
|
+
ok: false,
|
|
803
|
+
error: {
|
|
804
|
+
code: "timeout",
|
|
805
|
+
message: `No reply on ${topic.name} within ${timeoutMs} ms`
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
}, timeoutMs);
|
|
809
|
+
});
|
|
810
|
+
const r = await Promise.race([call({
|
|
811
|
+
v: 1,
|
|
812
|
+
t: "request",
|
|
813
|
+
p
|
|
814
|
+
}), timeout]);
|
|
815
|
+
clearTimeout(timer);
|
|
816
|
+
check(r);
|
|
817
|
+
return r.value;
|
|
818
|
+
},
|
|
819
|
+
async reply(record, value) {
|
|
820
|
+
const topic = topicOf.get(record);
|
|
821
|
+
if (topic === void 0) throw new Error("reply: this record was not delivered to this isolate");
|
|
822
|
+
check(await call({
|
|
823
|
+
v: 1,
|
|
824
|
+
t: "reply",
|
|
825
|
+
p: {
|
|
826
|
+
topic,
|
|
827
|
+
offset: record.offset,
|
|
828
|
+
value
|
|
829
|
+
}
|
|
830
|
+
}));
|
|
831
|
+
},
|
|
832
|
+
commit(record) {
|
|
833
|
+
const topic = topicOf.get(record);
|
|
834
|
+
if (topic === void 0) throw new Error("commit: this record was not delivered to this isolate");
|
|
835
|
+
commit(topic, record.offset);
|
|
836
|
+
}
|
|
837
|
+
},
|
|
838
|
+
idle: () => ({
|
|
839
|
+
sinceDeliveryMs: now() - lastDelivery,
|
|
840
|
+
inFlight: pending.size
|
|
841
|
+
}),
|
|
842
|
+
reattach(next) {
|
|
843
|
+
const old = port;
|
|
844
|
+
port = next;
|
|
845
|
+
old.close();
|
|
846
|
+
listen(next);
|
|
847
|
+
const unanswered = [...pending.values()];
|
|
848
|
+
for (const p of unanswered) {
|
|
849
|
+
if (p.msg.t !== "subscribe") continue;
|
|
850
|
+
pending.delete(p.msg.id);
|
|
851
|
+
p.settle({
|
|
852
|
+
ok: true,
|
|
853
|
+
value: null
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
committer.take();
|
|
857
|
+
for (const sub of subs.values()) {
|
|
858
|
+
sub.queue.length = 0;
|
|
859
|
+
sendSubscribe(sub);
|
|
860
|
+
}
|
|
861
|
+
for (const p of unanswered) if (p.msg.t !== "subscribe") send(p.msg);
|
|
862
|
+
},
|
|
863
|
+
async close() {
|
|
864
|
+
const offsets = committer.take();
|
|
865
|
+
committer.dispose();
|
|
866
|
+
if (offsets) await call({
|
|
867
|
+
v: 1,
|
|
868
|
+
t: "commits",
|
|
869
|
+
p: { offsets }
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
function isThenable(x) {
|
|
875
|
+
return (typeof x === "object" || typeof x === "function") && x !== null && typeof x.then === "function";
|
|
876
|
+
}
|
|
877
|
+
var randomEpoch, check, REQUEST_TIMEOUT_MS;
|
|
878
|
+
var init_bus_client = __esmMin((() => {
|
|
879
|
+
init_dist();
|
|
880
|
+
randomEpoch = () => crypto.getRandomValues(/* @__PURE__ */ new Uint32Array(1))[0] ?? 0;
|
|
881
|
+
check = (r) => {
|
|
882
|
+
if (!r.ok) throw new BusError(r.error);
|
|
883
|
+
};
|
|
884
|
+
REQUEST_TIMEOUT_MS = 3e4;
|
|
885
|
+
}));
|
|
886
|
+
// src/host-calls.ts
|
|
887
|
+
function createHostCalls(opts) {
|
|
888
|
+
const timeoutMs = opts.timeoutMs ?? 5e3;
|
|
889
|
+
const pending = /* @__PURE__ */ new Map();
|
|
890
|
+
let seq = 0;
|
|
891
|
+
const send = (method, args) => {
|
|
892
|
+
const id = `c${++seq}`;
|
|
893
|
+
return new Promise((resolve, reject) => {
|
|
894
|
+
const timer = setTimeout(() => {
|
|
895
|
+
pending.delete(id);
|
|
896
|
+
reject(new HostCallError("timeout", `${method}: no answer within ${timeoutMs} ms`));
|
|
897
|
+
}, timeoutMs);
|
|
898
|
+
pending.set(id, {
|
|
899
|
+
resolve,
|
|
900
|
+
reject,
|
|
901
|
+
timer
|
|
902
|
+
});
|
|
903
|
+
opts.post({
|
|
904
|
+
v: 1,
|
|
905
|
+
t: "call",
|
|
906
|
+
id,
|
|
907
|
+
p: {
|
|
908
|
+
method,
|
|
909
|
+
args
|
|
910
|
+
}
|
|
911
|
+
});
|
|
912
|
+
});
|
|
913
|
+
};
|
|
914
|
+
const call = (method, node, extra = []) => {
|
|
915
|
+
const nodeId = opts.idOf(node);
|
|
916
|
+
if (opts.surface && nodeId === void 0) return Promise.reject(new HostCallError("not_found", `${method}: not a rendered node`));
|
|
917
|
+
opts.beforeCall();
|
|
918
|
+
return send(method, [nodeId ?? null, ...extra]);
|
|
919
|
+
};
|
|
920
|
+
return {
|
|
921
|
+
api: {
|
|
922
|
+
async navigate(href, o = {}) {
|
|
923
|
+
if (!opts.navigate) throw new HostCallError("forbidden", "navigate: this isolate has no navigate grant (ADR 0002)");
|
|
924
|
+
return await send("navigate", [href, {
|
|
925
|
+
replace: o.replace ?? false,
|
|
926
|
+
state: o.state
|
|
927
|
+
}]) === true;
|
|
928
|
+
},
|
|
929
|
+
async measure(node) {
|
|
930
|
+
const value = await call("measure", node);
|
|
931
|
+
if (!isRect(value)) throw new HostCallError("invalid", "measure: the host sent no rect");
|
|
932
|
+
return value;
|
|
933
|
+
},
|
|
934
|
+
async focus(node) {
|
|
935
|
+
await call("focus", node);
|
|
936
|
+
},
|
|
937
|
+
async scrollIntoView(node, o) {
|
|
938
|
+
await call("scrollIntoView", node, o === void 0 ? [] : [o]);
|
|
939
|
+
},
|
|
940
|
+
async requestCanvas(node, size) {
|
|
941
|
+
const value = await call("requestCanvas", node, size === void 0 ? [] : [size]);
|
|
942
|
+
if (!(value instanceof OffscreenCanvas)) throw new HostCallError("invalid", "requestCanvas: the host sent no OffscreenCanvas");
|
|
943
|
+
return value;
|
|
944
|
+
}
|
|
945
|
+
},
|
|
946
|
+
pending: () => pending.size,
|
|
947
|
+
receive(re, result) {
|
|
948
|
+
const p = pending.get(re);
|
|
949
|
+
if (!p) return;
|
|
950
|
+
pending.delete(re);
|
|
951
|
+
clearTimeout(p.timer);
|
|
952
|
+
if (result.ok) p.resolve(result.value);
|
|
953
|
+
else p.reject(new HostCallError(result.error.code, result.error.message));
|
|
954
|
+
}
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
var HostCallError, isRect;
|
|
958
|
+
var init_host_calls = __esmMin((() => {
|
|
959
|
+
HostCallError = class extends Error {
|
|
960
|
+
code;
|
|
961
|
+
constructor(code, message) {
|
|
962
|
+
super(message);
|
|
963
|
+
this.name = "HostCallError";
|
|
964
|
+
this.code = code;
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
isRect = (x) => typeof x === "object" && x !== null && [
|
|
968
|
+
"x",
|
|
969
|
+
"y",
|
|
970
|
+
"width",
|
|
971
|
+
"height"
|
|
972
|
+
].every((k) => typeof Reflect.get(x, k) === "number");
|
|
973
|
+
}));
|
|
974
|
+
// src/keep-awake.ts
|
|
975
|
+
function createKeepAwake(now = () => performance.now()) {
|
|
976
|
+
const holds = /* @__PURE__ */ new Map();
|
|
977
|
+
let next = 0;
|
|
978
|
+
return {
|
|
979
|
+
hold() {
|
|
980
|
+
const id = ++next;
|
|
981
|
+
const stack = (/* @__PURE__ */ new Error("keepAwake")).stack?.split("\n").slice(2).join("\n");
|
|
982
|
+
holds.set(id, {
|
|
983
|
+
since: now(),
|
|
984
|
+
stack
|
|
985
|
+
});
|
|
986
|
+
return () => {
|
|
987
|
+
holds.delete(id);
|
|
988
|
+
};
|
|
989
|
+
},
|
|
990
|
+
report(at) {
|
|
991
|
+
return [...holds.values()].map((h) => h.stack === void 0 ? { ageMs: at - h.since } : {
|
|
992
|
+
ageMs: at - h.since,
|
|
993
|
+
stack: h.stack
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
var init_keep_awake = __esmMin((() => {}));
|
|
999
|
+
// ../dom/dist/records-wVZrPpqr.js
|
|
1000
|
+
var ISOLOOP_DOM_FMT;
|
|
1001
|
+
var init_records_wVZrPpqr = __esmMin((() => {
|
|
1002
|
+
ISOLOOP_DOM_FMT = "isoloop-dom@1";
|
|
1003
|
+
}));
|
|
1004
|
+
// ../dom/dist/dom-yLsf0Z4e.js
|
|
1005
|
+
function createStyle(el) {
|
|
1006
|
+
const decls = /* @__PURE__ */ new Map();
|
|
1007
|
+
const write = () => {
|
|
1008
|
+
const text = [...decls].map(([k, v]) => `${k}: ${v};`).join(" ");
|
|
1009
|
+
if (text) el.setAttribute("style", text);
|
|
1010
|
+
else el.removeAttribute("style");
|
|
1011
|
+
};
|
|
1012
|
+
const set = (name, value) => {
|
|
1013
|
+
const v = str(value);
|
|
1014
|
+
if (v === "") decls.delete(name);
|
|
1015
|
+
else decls.set(name, v);
|
|
1016
|
+
};
|
|
1017
|
+
return new Proxy({
|
|
1018
|
+
setProperty(name, value) {
|
|
1019
|
+
set(kebab(name), value);
|
|
1020
|
+
write();
|
|
1021
|
+
},
|
|
1022
|
+
removeProperty(name) {
|
|
1023
|
+
const old = decls.get(kebab(name)) ?? "";
|
|
1024
|
+
decls.delete(kebab(name));
|
|
1025
|
+
write();
|
|
1026
|
+
return old;
|
|
1027
|
+
},
|
|
1028
|
+
getPropertyValue(name) {
|
|
1029
|
+
return decls.get(kebab(name)) ?? "";
|
|
1030
|
+
},
|
|
1031
|
+
get cssText() {
|
|
1032
|
+
return [...decls].map(([k, v]) => `${k}: ${v};`).join(" ");
|
|
1033
|
+
},
|
|
1034
|
+
set cssText(text) {
|
|
1035
|
+
decls.clear();
|
|
1036
|
+
for (const part of text.split(";")) {
|
|
1037
|
+
const i = part.indexOf(":");
|
|
1038
|
+
if (i > 0) set(part.slice(0, i).trim(), part.slice(i + 1).trim());
|
|
1039
|
+
}
|
|
1040
|
+
write();
|
|
1041
|
+
}
|
|
1042
|
+
}, {
|
|
1043
|
+
get(t, key, receiver) {
|
|
1044
|
+
if (typeof key !== "string" || key in t) return Reflect.get(t, key, receiver);
|
|
1045
|
+
return decls.get(kebab(key === "cssFloat" ? "float" : key)) ?? "";
|
|
1046
|
+
},
|
|
1047
|
+
set(t, key, value, receiver) {
|
|
1048
|
+
if (typeof key !== "string" || key in t) return Reflect.set(t, key, value, receiver);
|
|
1049
|
+
set(kebab(key === "cssFloat" ? "float" : key), value);
|
|
1050
|
+
write();
|
|
1051
|
+
return true;
|
|
1052
|
+
}
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
/**
|
|
1056
|
+
* `element.dataset` (DOM group 1, ADR 0010): camelCase keys over the
|
|
1057
|
+
* `data-*` attributes, so every write travels as an `attr` record.
|
|
1058
|
+
*/
|
|
1059
|
+
function createDataset(el) {
|
|
1060
|
+
return new Proxy({}, {
|
|
1061
|
+
get: (_t, key) => typeof key === "string" ? el.getAttribute(dataAttr(key)) ?? void 0 : void 0,
|
|
1062
|
+
set(_t, key, value) {
|
|
1063
|
+
if (typeof key !== "string") return false;
|
|
1064
|
+
el.setAttribute(dataAttr(key), value);
|
|
1065
|
+
return true;
|
|
1066
|
+
},
|
|
1067
|
+
deleteProperty(_t, key) {
|
|
1068
|
+
if (typeof key === "string") el.removeAttribute(dataAttr(key));
|
|
1069
|
+
return true;
|
|
1070
|
+
},
|
|
1071
|
+
has: (_t, key) => typeof key === "string" && el.hasAttribute(dataAttr(key)),
|
|
1072
|
+
ownKeys: () => [...el.isoAttrs.keys()].filter((n) => n.startsWith("data-")).map(dataKey),
|
|
1073
|
+
getOwnPropertyDescriptor(_t, key) {
|
|
1074
|
+
if (typeof key !== "string" || !el.hasAttribute(dataAttr(key))) return void 0;
|
|
1075
|
+
return {
|
|
1076
|
+
value: el.getAttribute(dataAttr(key)),
|
|
1077
|
+
writable: true,
|
|
1078
|
+
enumerable: true,
|
|
1079
|
+
configurable: true
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
function defineHandlers(proto) {
|
|
1085
|
+
const handlers = /* @__PURE__ */ new WeakMap();
|
|
1086
|
+
for (const type of HANDLER_EVENTS) Object.defineProperty(proto, `on${type}`, {
|
|
1087
|
+
configurable: true,
|
|
1088
|
+
enumerable: true,
|
|
1089
|
+
get() {
|
|
1090
|
+
return handlers.get(this)?.get(type) ?? null;
|
|
1091
|
+
},
|
|
1092
|
+
set(fn) {
|
|
1093
|
+
const own = handlers.get(this) ?? /* @__PURE__ */ new Map();
|
|
1094
|
+
handlers.set(this, own);
|
|
1095
|
+
const old = own.get(type);
|
|
1096
|
+
if (old) this.removeEventListener(type, old);
|
|
1097
|
+
if (typeof fn === "function") {
|
|
1098
|
+
const handler = (e) => {
|
|
1099
|
+
Reflect.apply(fn, this, [e]);
|
|
1100
|
+
};
|
|
1101
|
+
own.set(type, handler);
|
|
1102
|
+
this.addEventListener(type, handler);
|
|
1103
|
+
} else own.delete(type);
|
|
1104
|
+
}
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
/** The subtree as `insert` sends it. */
|
|
1108
|
+
function serialize(n) {
|
|
1109
|
+
if (n instanceof WText) return {
|
|
1110
|
+
k: "text",
|
|
1111
|
+
id: n.isoId,
|
|
1112
|
+
data: n.isoData
|
|
1113
|
+
};
|
|
1114
|
+
if (n instanceof WComment) return {
|
|
1115
|
+
k: "comment",
|
|
1116
|
+
id: n.isoId,
|
|
1117
|
+
data: n.isoData
|
|
1118
|
+
};
|
|
1119
|
+
if (!(n instanceof WElement)) throw new TypeError("serialize: unknown node");
|
|
1120
|
+
return {
|
|
1121
|
+
k: "el",
|
|
1122
|
+
id: n.isoId,
|
|
1123
|
+
tag: n.localName,
|
|
1124
|
+
ns: n.isoNs,
|
|
1125
|
+
attrs: [...n.isoAttrs],
|
|
1126
|
+
props: [...n.isoProps],
|
|
1127
|
+
listen: [...n.isoListeners.keys()],
|
|
1128
|
+
children: n.childNodes.map(serialize)
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1131
|
+
/** Whether `n` or anything under it was rendered under a root other than `owner`. */
|
|
1132
|
+
function ownedElsewhere(n, owner) {
|
|
1133
|
+
if (n.isoOwner && n.isoOwner !== owner) return true;
|
|
1134
|
+
return !n.isoKnown && n.childNodes.some((c) => ownedElsewhere(c, owner));
|
|
1135
|
+
}
|
|
1136
|
+
function learn(n, core, owner) {
|
|
1137
|
+
n.isoKnown = true;
|
|
1138
|
+
n.isoOwner = owner;
|
|
1139
|
+
core.known.set(n.isoId, n);
|
|
1140
|
+
for (const c of n.childNodes) learn(c, core, owner);
|
|
1141
|
+
}
|
|
1142
|
+
function forget(n, core) {
|
|
1143
|
+
n.isoKnown = false;
|
|
1144
|
+
core.known.delete(n.isoId);
|
|
1145
|
+
for (const c of n.childNodes) forget(c, core);
|
|
1146
|
+
}
|
|
1147
|
+
function setValueOf(node, value, o) {
|
|
1148
|
+
if (!isControl(node)) throw new TypeError("setValue: not an input, textarea or select");
|
|
1149
|
+
if (!o.force) {
|
|
1150
|
+
node.value = value;
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
node.isoSetProp("value", value, false);
|
|
1154
|
+
if (node.isoKnown) emit(node, [
|
|
1155
|
+
"prop",
|
|
1156
|
+
node.isoWire,
|
|
1157
|
+
"value",
|
|
1158
|
+
value,
|
|
1159
|
+
true
|
|
1160
|
+
]);
|
|
1161
|
+
}
|
|
1162
|
+
function deliverTo(node, event) {
|
|
1163
|
+
if (!node) return;
|
|
1164
|
+
if (isControl(node) && event.value !== void 0) node.isoSetProp("value", event.value, false);
|
|
1165
|
+
if (node instanceof WHTMLInputElement && event.checked !== void 0) node.isoSetProp("checked", event.checked, false);
|
|
1166
|
+
if (event.type === "scroll" && node instanceof WElement) node.isoScroll = {
|
|
1167
|
+
top: event.scrollTop ?? 0,
|
|
1168
|
+
left: event.scrollLeft ?? 0
|
|
1169
|
+
};
|
|
1170
|
+
node.dispatchEvent(toEvent(event));
|
|
1171
|
+
}
|
|
1172
|
+
/** A root's recorder: records batched per microtask (or `schedule`) into `onBatch`. */
|
|
1173
|
+
function recorder(root, onBatch, schedule) {
|
|
1174
|
+
let pending = [];
|
|
1175
|
+
let scheduled = false;
|
|
1176
|
+
let live = true;
|
|
1177
|
+
const flush = () => {
|
|
1178
|
+
scheduled = false;
|
|
1179
|
+
if (pending.length === 0) return;
|
|
1180
|
+
const batch = pending;
|
|
1181
|
+
pending = [];
|
|
1182
|
+
if (live) onBatch(batch);
|
|
1183
|
+
};
|
|
1184
|
+
return {
|
|
1185
|
+
owner: {
|
|
1186
|
+
root,
|
|
1187
|
+
push(r) {
|
|
1188
|
+
if (!live) return;
|
|
1189
|
+
pending.push(r);
|
|
1190
|
+
if (!scheduled) {
|
|
1191
|
+
scheduled = true;
|
|
1192
|
+
schedule(flush);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
},
|
|
1196
|
+
flush,
|
|
1197
|
+
stop: () => {
|
|
1198
|
+
live = false;
|
|
1199
|
+
pending = [];
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
function createDom(opts) {
|
|
1204
|
+
const schedule = opts.schedule ?? ((fn) => queueMicrotask(fn));
|
|
1205
|
+
const core = {
|
|
1206
|
+
roots: /* @__PURE__ */ new Set(),
|
|
1207
|
+
nextId: 1,
|
|
1208
|
+
known: /* @__PURE__ */ new Map(),
|
|
1209
|
+
onHead: opts.onHead ?? (() => {})
|
|
1210
|
+
};
|
|
1211
|
+
const document = new WDocument(core);
|
|
1212
|
+
const makeRoot = (id) => {
|
|
1213
|
+
const root = new WHTMLElement(document, id, "iso-root", "html");
|
|
1214
|
+
root.isoKnown = true;
|
|
1215
|
+
core.known.set(id, root);
|
|
1216
|
+
core.roots.add(root);
|
|
1217
|
+
return root;
|
|
1218
|
+
};
|
|
1219
|
+
const root = makeRoot(0);
|
|
1220
|
+
const main = recorder(root, (b) => opts.onBatch(b), schedule);
|
|
1221
|
+
root.isoOwner = main.owner;
|
|
1222
|
+
return {
|
|
1223
|
+
document,
|
|
1224
|
+
root,
|
|
1225
|
+
flush: main.flush,
|
|
1226
|
+
idOf: (node) => node.isoId,
|
|
1227
|
+
setValue: (node, value, o = {}) => setValueOf(node, value, o),
|
|
1228
|
+
deliver: (event) => deliverTo(core.known.get(event.target), event),
|
|
1229
|
+
addRoot(o) {
|
|
1230
|
+
const member = makeRoot(core.nextId++);
|
|
1231
|
+
const rec = recorder(member, (b) => o.onBatch(b), o.schedule ?? schedule);
|
|
1232
|
+
member.isoOwner = rec.owner;
|
|
1233
|
+
const mine = (node) => node?.isoKnown && node.isoOwner === rec.owner ? node : void 0;
|
|
1234
|
+
return {
|
|
1235
|
+
root: member,
|
|
1236
|
+
flush: rec.flush,
|
|
1237
|
+
idOf: (node) => mine(node) ? node.isoWire : void 0,
|
|
1238
|
+
setValue(node, value, so = {}) {
|
|
1239
|
+
if (node.isoOwner && node.isoOwner !== rec.owner) throw new TypeError("setValue: not a node of this member's root");
|
|
1240
|
+
setValueOf(node, value, so);
|
|
1241
|
+
},
|
|
1242
|
+
deliver: (event) => deliverTo(mine(event.target === 0 ? member : core.known.get(event.target)), event),
|
|
1243
|
+
dispose() {
|
|
1244
|
+
rec.stop();
|
|
1245
|
+
core.roots.delete(member);
|
|
1246
|
+
forget(member, core);
|
|
1247
|
+
}
|
|
1248
|
+
};
|
|
1249
|
+
}
|
|
1250
|
+
};
|
|
1251
|
+
}
|
|
1252
|
+
/** A real `Event` with the fields frameworks read from mouse and keyboard events. */
|
|
1253
|
+
function toEvent(e) {
|
|
1254
|
+
const ev = new Event(e.type, {
|
|
1255
|
+
bubbles: e.type !== "scroll",
|
|
1256
|
+
cancelable: true
|
|
1257
|
+
});
|
|
1258
|
+
const mods = {
|
|
1259
|
+
Alt: e.mods.alt,
|
|
1260
|
+
Control: e.mods.ctrl,
|
|
1261
|
+
Meta: e.mods.meta,
|
|
1262
|
+
Shift: e.mods.shift
|
|
1263
|
+
};
|
|
1264
|
+
Object.defineProperties(ev, {
|
|
1265
|
+
altKey: { value: e.mods.alt },
|
|
1266
|
+
ctrlKey: { value: e.mods.ctrl },
|
|
1267
|
+
metaKey: { value: e.mods.meta },
|
|
1268
|
+
shiftKey: { value: e.mods.shift },
|
|
1269
|
+
getModifierState: { value: (k) => mods[k] ?? false },
|
|
1270
|
+
key: { value: e.key },
|
|
1271
|
+
code: { value: e.code },
|
|
1272
|
+
button: { value: e.button ?? 0 },
|
|
1273
|
+
clientX: { value: e.x ?? 0 },
|
|
1274
|
+
clientY: { value: e.y ?? 0 },
|
|
1275
|
+
width: { value: e.width },
|
|
1276
|
+
height: { value: e.height }
|
|
1277
|
+
});
|
|
1278
|
+
return ev;
|
|
1279
|
+
}
|
|
1280
|
+
var HTML_NS, SVG_NS, str, domError, emit, WEventTarget, WNode, WCharacterData, WText, WComment, kebab, WDOMTokenList, dataAttr, dataKey, WParentNode, WDocumentFragment, WElement, HANDLER_EVENTS, WHTMLElement, WSVGElement, WHTMLIFrameElement, WHTMLInputElement, WHTMLTextAreaElement, WHTMLSelectElement, WHTMLOptionElement, HTML_CLASSES, WDocument, isControl;
|
|
1281
|
+
var init_dom_yLsf0Z4e = __esmMin((() => {
|
|
1282
|
+
HTML_NS = "http://www.w3.org/1999/xhtml";
|
|
1283
|
+
SVG_NS = "http://www.w3.org/2000/svg";
|
|
1284
|
+
str = (v) => typeof v === "string" ? v : typeof v === "number" || typeof v === "boolean" || typeof v === "bigint" ? String(v) : "";
|
|
1285
|
+
domError = (name, message) => {
|
|
1286
|
+
const e = new Error(message);
|
|
1287
|
+
e.name = name;
|
|
1288
|
+
return e;
|
|
1289
|
+
};
|
|
1290
|
+
emit = (n, r) => {
|
|
1291
|
+
n.isoOwner?.push(r);
|
|
1292
|
+
};
|
|
1293
|
+
WEventTarget = class {
|
|
1294
|
+
/** @internal */ isoListeners = /* @__PURE__ */ new Map();
|
|
1295
|
+
/** @internal */ isoParentTarget() {
|
|
1296
|
+
return null;
|
|
1297
|
+
}
|
|
1298
|
+
/** @internal Called when the first listener of `type` is added, or the last removed. */
|
|
1299
|
+
isoListenChanged(_type, _on) {}
|
|
1300
|
+
addEventListener(type, fn, options) {
|
|
1301
|
+
if (!fn) return;
|
|
1302
|
+
const capture = typeof options === "boolean" ? options : Boolean(options?.capture);
|
|
1303
|
+
const once = typeof options === "object" && Boolean(options.once);
|
|
1304
|
+
const list = this.isoListeners.get(type) ?? [];
|
|
1305
|
+
if (list.some((l) => l.fn === fn && l.capture === capture)) return;
|
|
1306
|
+
list.push({
|
|
1307
|
+
fn,
|
|
1308
|
+
capture,
|
|
1309
|
+
once
|
|
1310
|
+
});
|
|
1311
|
+
this.isoListeners.set(type, list);
|
|
1312
|
+
if (list.length === 1) this.isoListenChanged(type, true);
|
|
1313
|
+
}
|
|
1314
|
+
removeEventListener(type, fn, options) {
|
|
1315
|
+
const capture = typeof options === "boolean" ? options : Boolean(options?.capture);
|
|
1316
|
+
const list = this.isoListeners.get(type);
|
|
1317
|
+
if (!list) return;
|
|
1318
|
+
const i = list.findIndex((l) => l.fn === fn && l.capture === capture);
|
|
1319
|
+
if (i < 0) return;
|
|
1320
|
+
list.splice(i, 1);
|
|
1321
|
+
if (list.length === 0) {
|
|
1322
|
+
this.isoListeners.delete(type);
|
|
1323
|
+
this.isoListenChanged(type, false);
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
/** Capture from the top, then the target, then bubble (if `bubbles`). */
|
|
1327
|
+
dispatchEvent(event) {
|
|
1328
|
+
const path = [this];
|
|
1329
|
+
for (let t = this.isoParentTarget(); t; t = t.isoParentTarget()) path.push(t);
|
|
1330
|
+
let stopped = false;
|
|
1331
|
+
let stoppedNow = false;
|
|
1332
|
+
const stop = event.stopPropagation.bind(event);
|
|
1333
|
+
const stopNow = event.stopImmediatePropagation.bind(event);
|
|
1334
|
+
Object.defineProperties(event, {
|
|
1335
|
+
target: {
|
|
1336
|
+
value: this,
|
|
1337
|
+
configurable: true
|
|
1338
|
+
},
|
|
1339
|
+
srcElement: {
|
|
1340
|
+
value: this,
|
|
1341
|
+
configurable: true
|
|
1342
|
+
},
|
|
1343
|
+
stopPropagation: {
|
|
1344
|
+
value: () => {
|
|
1345
|
+
stopped = true;
|
|
1346
|
+
stop();
|
|
1347
|
+
},
|
|
1348
|
+
configurable: true
|
|
1349
|
+
},
|
|
1350
|
+
stopImmediatePropagation: {
|
|
1351
|
+
value: () => {
|
|
1352
|
+
stopped = true;
|
|
1353
|
+
stoppedNow = true;
|
|
1354
|
+
stopNow();
|
|
1355
|
+
},
|
|
1356
|
+
configurable: true
|
|
1357
|
+
},
|
|
1358
|
+
composedPath: {
|
|
1359
|
+
value: () => path.slice(),
|
|
1360
|
+
configurable: true
|
|
1361
|
+
}
|
|
1362
|
+
});
|
|
1363
|
+
const invoke = (t, phase, capture) => {
|
|
1364
|
+
Object.defineProperties(event, {
|
|
1365
|
+
currentTarget: {
|
|
1366
|
+
value: t,
|
|
1367
|
+
configurable: true
|
|
1368
|
+
},
|
|
1369
|
+
eventPhase: {
|
|
1370
|
+
value: phase,
|
|
1371
|
+
configurable: true
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
for (const l of (t.isoListeners.get(event.type) ?? []).slice()) {
|
|
1375
|
+
if (capture !== null && l.capture !== capture) continue;
|
|
1376
|
+
if (l.once) t.removeEventListener(event.type, l.fn, l.capture);
|
|
1377
|
+
if (typeof l.fn === "function") l.fn.call(t, event);
|
|
1378
|
+
else l.fn.handleEvent(event);
|
|
1379
|
+
if (stoppedNow) return;
|
|
1380
|
+
}
|
|
1381
|
+
};
|
|
1382
|
+
const phases = [];
|
|
1383
|
+
for (let i = path.length - 1; i > 0; i--) {
|
|
1384
|
+
const t = path[i];
|
|
1385
|
+
if (t) phases.push([
|
|
1386
|
+
t,
|
|
1387
|
+
1,
|
|
1388
|
+
true
|
|
1389
|
+
]);
|
|
1390
|
+
}
|
|
1391
|
+
phases.push([
|
|
1392
|
+
this,
|
|
1393
|
+
2,
|
|
1394
|
+
null
|
|
1395
|
+
]);
|
|
1396
|
+
if (event.bubbles) for (const t of path.slice(1)) phases.push([
|
|
1397
|
+
t,
|
|
1398
|
+
3,
|
|
1399
|
+
false
|
|
1400
|
+
]);
|
|
1401
|
+
for (const [t, phase, capture] of phases) {
|
|
1402
|
+
if (stopped) break;
|
|
1403
|
+
invoke(t, phase, capture);
|
|
1404
|
+
}
|
|
1405
|
+
Object.defineProperties(event, {
|
|
1406
|
+
currentTarget: {
|
|
1407
|
+
value: null,
|
|
1408
|
+
configurable: true
|
|
1409
|
+
},
|
|
1410
|
+
eventPhase: {
|
|
1411
|
+
value: 0,
|
|
1412
|
+
configurable: true
|
|
1413
|
+
}
|
|
1414
|
+
});
|
|
1415
|
+
return !event.defaultPrevented;
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
WNode = class extends WEventTarget {
|
|
1419
|
+
static ELEMENT_NODE = 1;
|
|
1420
|
+
static TEXT_NODE = 3;
|
|
1421
|
+
static COMMENT_NODE = 8;
|
|
1422
|
+
static DOCUMENT_NODE = 9;
|
|
1423
|
+
static DOCUMENT_FRAGMENT_NODE = 11;
|
|
1424
|
+
ELEMENT_NODE = 1;
|
|
1425
|
+
TEXT_NODE = 3;
|
|
1426
|
+
COMMENT_NODE = 8;
|
|
1427
|
+
DOCUMENT_FRAGMENT_NODE = 11;
|
|
1428
|
+
ownerDocument;
|
|
1429
|
+
/** @internal */ isoId;
|
|
1430
|
+
/** @internal */ isoParent = null;
|
|
1431
|
+
/** @internal */ isoPrev = null;
|
|
1432
|
+
/** @internal */ isoNext = null;
|
|
1433
|
+
/** @internal Whether the host knows this node (it's in the tree under the root). */
|
|
1434
|
+
isoKnown = false;
|
|
1435
|
+
/**
|
|
1436
|
+
* @internal The root this node was rendered under, once it has been. Kept
|
|
1437
|
+
* after the node leaves the tree, so it can't move to another member's root
|
|
1438
|
+
* in a pool (ADR 0015, decision 3).
|
|
1439
|
+
*/
|
|
1440
|
+
isoOwner = null;
|
|
1441
|
+
constructor(doc, id) {
|
|
1442
|
+
super();
|
|
1443
|
+
this.ownerDocument = doc;
|
|
1444
|
+
this.isoId = id;
|
|
1445
|
+
}
|
|
1446
|
+
/** @internal */ isoParentTarget() {
|
|
1447
|
+
return this.isoParent;
|
|
1448
|
+
}
|
|
1449
|
+
/**
|
|
1450
|
+
* @internal The id the host knows this node by: a render root is always
|
|
1451
|
+
* `ROOT_ID` to its own surface, whatever its id in the document.
|
|
1452
|
+
*/
|
|
1453
|
+
get isoWire() {
|
|
1454
|
+
return this.isoOwner?.root === this ? 0 : this.isoId;
|
|
1455
|
+
}
|
|
1456
|
+
/** @internal */ isoListenChanged(type, on) {
|
|
1457
|
+
if (this.isoKnown) emit(this, [
|
|
1458
|
+
"listen",
|
|
1459
|
+
this.isoWire,
|
|
1460
|
+
type,
|
|
1461
|
+
on
|
|
1462
|
+
]);
|
|
1463
|
+
}
|
|
1464
|
+
get parentNode() {
|
|
1465
|
+
return this.isoParent;
|
|
1466
|
+
}
|
|
1467
|
+
get parentElement() {
|
|
1468
|
+
return this.isoParent instanceof WElement ? this.isoParent : null;
|
|
1469
|
+
}
|
|
1470
|
+
get nextSibling() {
|
|
1471
|
+
return this.isoNext;
|
|
1472
|
+
}
|
|
1473
|
+
get previousSibling() {
|
|
1474
|
+
return this.isoPrev;
|
|
1475
|
+
}
|
|
1476
|
+
get firstChild() {
|
|
1477
|
+
return null;
|
|
1478
|
+
}
|
|
1479
|
+
get lastChild() {
|
|
1480
|
+
return null;
|
|
1481
|
+
}
|
|
1482
|
+
get childNodes() {
|
|
1483
|
+
return [];
|
|
1484
|
+
}
|
|
1485
|
+
get isConnected() {
|
|
1486
|
+
return this.isoKnown;
|
|
1487
|
+
}
|
|
1488
|
+
hasChildNodes() {
|
|
1489
|
+
return this.firstChild !== null;
|
|
1490
|
+
}
|
|
1491
|
+
contains(other) {
|
|
1492
|
+
for (let n = other; n; n = n.isoParent) if (n === this) return true;
|
|
1493
|
+
return false;
|
|
1494
|
+
}
|
|
1495
|
+
remove() {
|
|
1496
|
+
this.isoParent?.removeChild(this);
|
|
1497
|
+
}
|
|
1498
|
+
};
|
|
1499
|
+
WCharacterData = class extends WNode {
|
|
1500
|
+
/** @internal */ isoData;
|
|
1501
|
+
constructor(doc, id, data) {
|
|
1502
|
+
super(doc, id);
|
|
1503
|
+
this.isoData = data;
|
|
1504
|
+
}
|
|
1505
|
+
get data() {
|
|
1506
|
+
return this.isoData;
|
|
1507
|
+
}
|
|
1508
|
+
set data(v) {
|
|
1509
|
+
const data = str(v);
|
|
1510
|
+
if (data === this.isoData) return;
|
|
1511
|
+
this.isoData = data;
|
|
1512
|
+
if (this.isoKnown) emit(this, [
|
|
1513
|
+
"text",
|
|
1514
|
+
this.isoWire,
|
|
1515
|
+
data
|
|
1516
|
+
]);
|
|
1517
|
+
}
|
|
1518
|
+
get length() {
|
|
1519
|
+
return this.isoData.length;
|
|
1520
|
+
}
|
|
1521
|
+
get textContent() {
|
|
1522
|
+
return this.isoData;
|
|
1523
|
+
}
|
|
1524
|
+
set textContent(v) {
|
|
1525
|
+
this.data = v ?? "";
|
|
1526
|
+
}
|
|
1527
|
+
get nodeValue() {
|
|
1528
|
+
return this.isoData;
|
|
1529
|
+
}
|
|
1530
|
+
set nodeValue(v) {
|
|
1531
|
+
this.data = v ?? "";
|
|
1532
|
+
}
|
|
1533
|
+
};
|
|
1534
|
+
WText = class extends WCharacterData {
|
|
1535
|
+
nodeType = 3;
|
|
1536
|
+
nodeName = "#text";
|
|
1537
|
+
};
|
|
1538
|
+
WComment = class extends WCharacterData {
|
|
1539
|
+
nodeType = 8;
|
|
1540
|
+
nodeName = "#comment";
|
|
1541
|
+
};
|
|
1542
|
+
kebab = (name) => name.startsWith("--") ? name : name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
1543
|
+
WDOMTokenList = class {
|
|
1544
|
+
/** @internal */ isoEl;
|
|
1545
|
+
constructor(el) {
|
|
1546
|
+
this.isoEl = el;
|
|
1547
|
+
}
|
|
1548
|
+
/** @internal */ isoTokens() {
|
|
1549
|
+
const tokens = [];
|
|
1550
|
+
for (const t of (this.isoEl.getAttribute("class") ?? "").split(/[\t\n\f\r ]+/)) if (t !== "" && !tokens.includes(t)) tokens.push(t);
|
|
1551
|
+
return tokens;
|
|
1552
|
+
}
|
|
1553
|
+
/** @internal */ isoWrite(tokens) {
|
|
1554
|
+
this.isoEl.setAttribute("class", tokens.join(" "));
|
|
1555
|
+
}
|
|
1556
|
+
get length() {
|
|
1557
|
+
return this.isoTokens().length;
|
|
1558
|
+
}
|
|
1559
|
+
get value() {
|
|
1560
|
+
return this.isoEl.getAttribute("class") ?? "";
|
|
1561
|
+
}
|
|
1562
|
+
set value(v) {
|
|
1563
|
+
this.isoEl.setAttribute("class", v);
|
|
1564
|
+
}
|
|
1565
|
+
item(i) {
|
|
1566
|
+
return this.isoTokens()[i] ?? null;
|
|
1567
|
+
}
|
|
1568
|
+
contains(token) {
|
|
1569
|
+
return this.isoTokens().includes(token);
|
|
1570
|
+
}
|
|
1571
|
+
add(...tokens) {
|
|
1572
|
+
const list = this.isoTokens();
|
|
1573
|
+
for (const t of tokens) if (!list.includes(t)) list.push(t);
|
|
1574
|
+
this.isoWrite(list);
|
|
1575
|
+
}
|
|
1576
|
+
remove(...tokens) {
|
|
1577
|
+
this.isoWrite(this.isoTokens().filter((t) => !tokens.includes(t)));
|
|
1578
|
+
}
|
|
1579
|
+
toggle(token, force) {
|
|
1580
|
+
const has = this.contains(token);
|
|
1581
|
+
const on = force ?? !has;
|
|
1582
|
+
if (on && !has) this.add(token);
|
|
1583
|
+
else if (!on && has) this.remove(token);
|
|
1584
|
+
return on;
|
|
1585
|
+
}
|
|
1586
|
+
replace(token, next) {
|
|
1587
|
+
const list = this.isoTokens();
|
|
1588
|
+
const i = list.indexOf(token);
|
|
1589
|
+
if (i < 0) return false;
|
|
1590
|
+
list[i] = next;
|
|
1591
|
+
this.isoWrite(list.filter((t, j) => list.indexOf(t) === j));
|
|
1592
|
+
return true;
|
|
1593
|
+
}
|
|
1594
|
+
toString() {
|
|
1595
|
+
return this.value;
|
|
1596
|
+
}
|
|
1597
|
+
[Symbol.iterator]() {
|
|
1598
|
+
return this.isoTokens()[Symbol.iterator]();
|
|
1599
|
+
}
|
|
1600
|
+
};
|
|
1601
|
+
dataAttr = (key) => `data-${key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)}`;
|
|
1602
|
+
dataKey = (attr) => attr.slice(5).replace(/-([a-z])/g, (_m, c) => c.toUpperCase());
|
|
1603
|
+
WParentNode = class extends WNode {
|
|
1604
|
+
/** @internal */ isoFirst = null;
|
|
1605
|
+
/** @internal */ isoLast = null;
|
|
1606
|
+
/** @internal */ isoChildCache = null;
|
|
1607
|
+
get firstChild() {
|
|
1608
|
+
return this.isoFirst;
|
|
1609
|
+
}
|
|
1610
|
+
get lastChild() {
|
|
1611
|
+
return this.isoLast;
|
|
1612
|
+
}
|
|
1613
|
+
get childNodes() {
|
|
1614
|
+
if (!this.isoChildCache) {
|
|
1615
|
+
const list = [];
|
|
1616
|
+
for (let n = this.isoFirst; n; n = n.isoNext) list.push(n);
|
|
1617
|
+
this.isoChildCache = list;
|
|
1618
|
+
}
|
|
1619
|
+
return this.isoChildCache;
|
|
1620
|
+
}
|
|
1621
|
+
get children() {
|
|
1622
|
+
return this.childNodes.filter((n) => n instanceof WElement);
|
|
1623
|
+
}
|
|
1624
|
+
get firstElementChild() {
|
|
1625
|
+
return this.children[0] ?? null;
|
|
1626
|
+
}
|
|
1627
|
+
/** Text of the subtree; comments don't count, as in the DOM. */
|
|
1628
|
+
get textContent() {
|
|
1629
|
+
let out = "";
|
|
1630
|
+
for (let n = this.isoFirst; n; n = n.isoNext) if (!(n instanceof WComment)) out += n.textContent;
|
|
1631
|
+
return out;
|
|
1632
|
+
}
|
|
1633
|
+
set textContent(v) {
|
|
1634
|
+
this.replaceChildren(...v ? [this.ownerDocument.createTextNode(v)] : []);
|
|
1635
|
+
}
|
|
1636
|
+
appendChild(child) {
|
|
1637
|
+
return this.insertBefore(child, null);
|
|
1638
|
+
}
|
|
1639
|
+
insertBefore(child, ref) {
|
|
1640
|
+
if (!(child instanceof WNode)) throw new TypeError("insertBefore: not a node");
|
|
1641
|
+
if (ref && ref.isoParent !== this) throw domError("NotFoundError", "insertBefore: the reference node is not a child");
|
|
1642
|
+
if (child.contains(this)) throw domError("HierarchyRequestError", "insertBefore: would create a cycle");
|
|
1643
|
+
if (ref === child) ref = child.isoNext;
|
|
1644
|
+
if (child instanceof WDocumentFragment) {
|
|
1645
|
+
for (const c of child.childNodes) this.insertBefore(c, ref);
|
|
1646
|
+
return child;
|
|
1647
|
+
}
|
|
1648
|
+
if (this.ownerDocument.head === this && child instanceof WElement) this.ownerDocument.isoCore.onHead(child.localName);
|
|
1649
|
+
if (this.isoKnown && ownedElsewhere(child, this.isoOwner)) throw domError("HierarchyRequestError", "insertBefore: a node can't move to another member's root in a pool");
|
|
1650
|
+
const wasKnown = child.isoKnown;
|
|
1651
|
+
child.isoParent?.isoUnlink(child);
|
|
1652
|
+
this.isoLink(child, ref);
|
|
1653
|
+
const core = this.ownerDocument.isoCore;
|
|
1654
|
+
if (wasKnown && this.isoKnown) emit(this, [
|
|
1655
|
+
"move",
|
|
1656
|
+
this.isoWire,
|
|
1657
|
+
child.isoId,
|
|
1658
|
+
ref?.isoId ?? null
|
|
1659
|
+
]);
|
|
1660
|
+
else if (wasKnown) {
|
|
1661
|
+
emit(child, ["remove", child.isoId]);
|
|
1662
|
+
forget(child, core);
|
|
1663
|
+
} else if (this.isoKnown) {
|
|
1664
|
+
emit(this, [
|
|
1665
|
+
"insert",
|
|
1666
|
+
this.isoWire,
|
|
1667
|
+
serialize(child),
|
|
1668
|
+
ref?.isoId ?? null
|
|
1669
|
+
]);
|
|
1670
|
+
learn(child, core, this.isoOwner);
|
|
1671
|
+
}
|
|
1672
|
+
return child;
|
|
1673
|
+
}
|
|
1674
|
+
removeChild(child) {
|
|
1675
|
+
if (child.isoParent !== this) throw domError("NotFoundError", "removeChild: not a child");
|
|
1676
|
+
this.isoUnlink(child);
|
|
1677
|
+
if (child.isoKnown) {
|
|
1678
|
+
emit(child, ["remove", child.isoId]);
|
|
1679
|
+
forget(child, this.ownerDocument.isoCore);
|
|
1680
|
+
}
|
|
1681
|
+
return child;
|
|
1682
|
+
}
|
|
1683
|
+
replaceChildren(...nodes) {
|
|
1684
|
+
while (this.isoLast) this.removeChild(this.isoLast);
|
|
1685
|
+
this.append(...nodes);
|
|
1686
|
+
}
|
|
1687
|
+
append(...nodes) {
|
|
1688
|
+
for (const n of nodes) this.appendChild(typeof n === "string" ? this.ownerDocument.createTextNode(n) : n);
|
|
1689
|
+
}
|
|
1690
|
+
/** @internal */ isoUnlink(child) {
|
|
1691
|
+
if (child.isoPrev) child.isoPrev.isoNext = child.isoNext;
|
|
1692
|
+
else this.isoFirst = child.isoNext;
|
|
1693
|
+
if (child.isoNext) child.isoNext.isoPrev = child.isoPrev;
|
|
1694
|
+
else this.isoLast = child.isoPrev;
|
|
1695
|
+
child.isoParent = null;
|
|
1696
|
+
child.isoPrev = null;
|
|
1697
|
+
child.isoNext = null;
|
|
1698
|
+
this.isoChildCache = null;
|
|
1699
|
+
}
|
|
1700
|
+
/** @internal */ isoLink(child, ref) {
|
|
1701
|
+
child.isoParent = this;
|
|
1702
|
+
child.isoNext = ref;
|
|
1703
|
+
child.isoPrev = ref ? ref.isoPrev : this.isoLast;
|
|
1704
|
+
if (child.isoPrev) child.isoPrev.isoNext = child;
|
|
1705
|
+
else this.isoFirst = child;
|
|
1706
|
+
if (ref) ref.isoPrev = child;
|
|
1707
|
+
else this.isoLast = child;
|
|
1708
|
+
this.isoChildCache = null;
|
|
1709
|
+
}
|
|
1710
|
+
};
|
|
1711
|
+
WDocumentFragment = class extends WParentNode {
|
|
1712
|
+
nodeType = 11;
|
|
1713
|
+
nodeName = "#document-fragment";
|
|
1714
|
+
get nodeValue() {
|
|
1715
|
+
return null;
|
|
1716
|
+
}
|
|
1717
|
+
set nodeValue(_v) {}
|
|
1718
|
+
};
|
|
1719
|
+
WElement = class extends WParentNode {
|
|
1720
|
+
nodeType = 1;
|
|
1721
|
+
localName;
|
|
1722
|
+
namespaceURI;
|
|
1723
|
+
/** @internal */ isoNs;
|
|
1724
|
+
/** @internal */ isoAttrs = /* @__PURE__ */ new Map();
|
|
1725
|
+
/** @internal */ isoProps = /* @__PURE__ */ new Map();
|
|
1726
|
+
/** @internal */ isoStyle = null;
|
|
1727
|
+
/** @internal */ isoClassList = null;
|
|
1728
|
+
/** @internal */ isoDataset = null;
|
|
1729
|
+
/** @internal The offsets the last `scroll` event brought (design §4.6). */
|
|
1730
|
+
isoScroll = {
|
|
1731
|
+
top: 0,
|
|
1732
|
+
left: 0
|
|
1733
|
+
};
|
|
1734
|
+
constructor(doc, id, localName, ns) {
|
|
1735
|
+
super(doc, id);
|
|
1736
|
+
this.localName = localName;
|
|
1737
|
+
this.isoNs = ns;
|
|
1738
|
+
this.namespaceURI = ns === "svg" ? SVG_NS : HTML_NS;
|
|
1739
|
+
}
|
|
1740
|
+
get tagName() {
|
|
1741
|
+
return this.isoNs === "html" ? this.localName.toUpperCase() : this.localName;
|
|
1742
|
+
}
|
|
1743
|
+
get nodeName() {
|
|
1744
|
+
return this.tagName;
|
|
1745
|
+
}
|
|
1746
|
+
get nodeValue() {
|
|
1747
|
+
return null;
|
|
1748
|
+
}
|
|
1749
|
+
set nodeValue(_v) {}
|
|
1750
|
+
get attributes() {
|
|
1751
|
+
return [...this.isoAttrs].map(([name, value]) => ({
|
|
1752
|
+
name,
|
|
1753
|
+
value
|
|
1754
|
+
}));
|
|
1755
|
+
}
|
|
1756
|
+
getAttribute(name) {
|
|
1757
|
+
return this.isoAttrs.get(this.isoAttrName(name)) ?? null;
|
|
1758
|
+
}
|
|
1759
|
+
hasAttribute(name) {
|
|
1760
|
+
return this.isoAttrs.has(this.isoAttrName(name));
|
|
1761
|
+
}
|
|
1762
|
+
setAttribute(name, value) {
|
|
1763
|
+
const n = this.isoAttrName(name);
|
|
1764
|
+
const v = str(value);
|
|
1765
|
+
if (this.isoAttrs.get(n) === v) return;
|
|
1766
|
+
this.isoAttrs.set(n, v);
|
|
1767
|
+
if (this.isoKnown) emit(this, [
|
|
1768
|
+
"attr",
|
|
1769
|
+
this.isoWire,
|
|
1770
|
+
n,
|
|
1771
|
+
v
|
|
1772
|
+
]);
|
|
1773
|
+
}
|
|
1774
|
+
removeAttribute(name) {
|
|
1775
|
+
const n = this.isoAttrName(name);
|
|
1776
|
+
if (!this.isoAttrs.delete(n)) return;
|
|
1777
|
+
if (this.isoKnown) emit(this, [
|
|
1778
|
+
"attr",
|
|
1779
|
+
this.isoWire,
|
|
1780
|
+
n,
|
|
1781
|
+
null
|
|
1782
|
+
]);
|
|
1783
|
+
}
|
|
1784
|
+
/** @internal HTML attribute names are case-insensitive; SVG ones aren't. */
|
|
1785
|
+
isoAttrName(name) {
|
|
1786
|
+
return this.isoNs === "html" ? name.toLowerCase() : name;
|
|
1787
|
+
}
|
|
1788
|
+
get style() {
|
|
1789
|
+
this.isoStyle ??= createStyle(this);
|
|
1790
|
+
return this.isoStyle;
|
|
1791
|
+
}
|
|
1792
|
+
get classList() {
|
|
1793
|
+
this.isoClassList ??= new WDOMTokenList(this);
|
|
1794
|
+
return this.isoClassList;
|
|
1795
|
+
}
|
|
1796
|
+
get dataset() {
|
|
1797
|
+
this.isoDataset ??= createDataset(this);
|
|
1798
|
+
return this.isoDataset;
|
|
1799
|
+
}
|
|
1800
|
+
/**
|
|
1801
|
+
* Read only, and as of the last `scroll` event the element got: the host
|
|
1802
|
+
* owns scrolling. 0 until the element is scrolled and listens for `scroll`.
|
|
1803
|
+
*/
|
|
1804
|
+
get scrollTop() {
|
|
1805
|
+
return this.isoScroll.top;
|
|
1806
|
+
}
|
|
1807
|
+
get scrollLeft() {
|
|
1808
|
+
return this.isoScroll.left;
|
|
1809
|
+
}
|
|
1810
|
+
get id() {
|
|
1811
|
+
return this.getAttribute("id") ?? "";
|
|
1812
|
+
}
|
|
1813
|
+
set id(v) {
|
|
1814
|
+
this.setAttribute("id", v);
|
|
1815
|
+
}
|
|
1816
|
+
/** @internal */ isoSetProp(name, value, record) {
|
|
1817
|
+
if (this.isoProps.get(name) === value) return;
|
|
1818
|
+
this.isoProps.set(name, value);
|
|
1819
|
+
if (record && this.isoKnown) emit(this, [
|
|
1820
|
+
"prop",
|
|
1821
|
+
this.isoWire,
|
|
1822
|
+
name,
|
|
1823
|
+
value
|
|
1824
|
+
]);
|
|
1825
|
+
}
|
|
1826
|
+
};
|
|
1827
|
+
HANDLER_EVENTS = [
|
|
1828
|
+
"abort",
|
|
1829
|
+
"animationend",
|
|
1830
|
+
"animationiteration",
|
|
1831
|
+
"animationstart",
|
|
1832
|
+
"auxclick",
|
|
1833
|
+
"beforeinput",
|
|
1834
|
+
"blur",
|
|
1835
|
+
"cancel",
|
|
1836
|
+
"change",
|
|
1837
|
+
"click",
|
|
1838
|
+
"close",
|
|
1839
|
+
"contextmenu",
|
|
1840
|
+
"copy",
|
|
1841
|
+
"cut",
|
|
1842
|
+
"dblclick",
|
|
1843
|
+
"drag",
|
|
1844
|
+
"dragend",
|
|
1845
|
+
"dragenter",
|
|
1846
|
+
"dragleave",
|
|
1847
|
+
"dragover",
|
|
1848
|
+
"dragstart",
|
|
1849
|
+
"drop",
|
|
1850
|
+
"error",
|
|
1851
|
+
"focus",
|
|
1852
|
+
"input",
|
|
1853
|
+
"invalid",
|
|
1854
|
+
"keydown",
|
|
1855
|
+
"keypress",
|
|
1856
|
+
"keyup",
|
|
1857
|
+
"load",
|
|
1858
|
+
"mousedown",
|
|
1859
|
+
"mouseenter",
|
|
1860
|
+
"mouseleave",
|
|
1861
|
+
"mousemove",
|
|
1862
|
+
"mouseout",
|
|
1863
|
+
"mouseover",
|
|
1864
|
+
"mouseup",
|
|
1865
|
+
"paste",
|
|
1866
|
+
"pointercancel",
|
|
1867
|
+
"pointerdown",
|
|
1868
|
+
"pointerenter",
|
|
1869
|
+
"pointerleave",
|
|
1870
|
+
"pointermove",
|
|
1871
|
+
"pointerout",
|
|
1872
|
+
"pointerover",
|
|
1873
|
+
"pointerup",
|
|
1874
|
+
"reset",
|
|
1875
|
+
"resize",
|
|
1876
|
+
"scroll",
|
|
1877
|
+
"select",
|
|
1878
|
+
"submit",
|
|
1879
|
+
"toggle",
|
|
1880
|
+
"touchcancel",
|
|
1881
|
+
"touchend",
|
|
1882
|
+
"touchmove",
|
|
1883
|
+
"touchstart",
|
|
1884
|
+
"transitionend",
|
|
1885
|
+
"wheel"
|
|
1886
|
+
];
|
|
1887
|
+
defineHandlers(WElement.prototype);
|
|
1888
|
+
WHTMLElement = class extends WElement {};
|
|
1889
|
+
WSVGElement = class extends WElement {};
|
|
1890
|
+
WHTMLIFrameElement = class extends WHTMLElement {};
|
|
1891
|
+
WHTMLInputElement = class extends WHTMLElement {
|
|
1892
|
+
get value() {
|
|
1893
|
+
const v = this.isoProps.get("value");
|
|
1894
|
+
return typeof v === "string" ? v : this.getAttribute("value") ?? "";
|
|
1895
|
+
}
|
|
1896
|
+
set value(v) {
|
|
1897
|
+
this.isoSetProp("value", str(v), true);
|
|
1898
|
+
}
|
|
1899
|
+
get checked() {
|
|
1900
|
+
const v = this.isoProps.get("checked");
|
|
1901
|
+
return typeof v === "boolean" ? v : this.hasAttribute("checked");
|
|
1902
|
+
}
|
|
1903
|
+
set checked(v) {
|
|
1904
|
+
this.isoSetProp("checked", Boolean(v), true);
|
|
1905
|
+
}
|
|
1906
|
+
get defaultValue() {
|
|
1907
|
+
return this.getAttribute("value") ?? "";
|
|
1908
|
+
}
|
|
1909
|
+
set defaultValue(v) {
|
|
1910
|
+
this.setAttribute("value", v);
|
|
1911
|
+
}
|
|
1912
|
+
get defaultChecked() {
|
|
1913
|
+
return this.hasAttribute("checked");
|
|
1914
|
+
}
|
|
1915
|
+
set defaultChecked(v) {
|
|
1916
|
+
if (v) this.setAttribute("checked", "");
|
|
1917
|
+
else this.removeAttribute("checked");
|
|
1918
|
+
}
|
|
1919
|
+
get name() {
|
|
1920
|
+
return this.getAttribute("name") ?? "";
|
|
1921
|
+
}
|
|
1922
|
+
set name(v) {
|
|
1923
|
+
this.setAttribute("name", v);
|
|
1924
|
+
}
|
|
1925
|
+
get type() {
|
|
1926
|
+
return this.getAttribute("type") ?? "text";
|
|
1927
|
+
}
|
|
1928
|
+
set type(v) {
|
|
1929
|
+
this.setAttribute("type", v);
|
|
1930
|
+
}
|
|
1931
|
+
};
|
|
1932
|
+
WHTMLTextAreaElement = class extends WHTMLElement {
|
|
1933
|
+
get value() {
|
|
1934
|
+
const v = this.isoProps.get("value");
|
|
1935
|
+
return typeof v === "string" ? v : this.textContent;
|
|
1936
|
+
}
|
|
1937
|
+
set value(v) {
|
|
1938
|
+
this.isoSetProp("value", str(v), true);
|
|
1939
|
+
}
|
|
1940
|
+
get defaultValue() {
|
|
1941
|
+
return this.textContent;
|
|
1942
|
+
}
|
|
1943
|
+
set defaultValue(v) {
|
|
1944
|
+
this.textContent = v;
|
|
1945
|
+
}
|
|
1946
|
+
get name() {
|
|
1947
|
+
return this.getAttribute("name") ?? "";
|
|
1948
|
+
}
|
|
1949
|
+
set name(v) {
|
|
1950
|
+
this.setAttribute("name", v);
|
|
1951
|
+
}
|
|
1952
|
+
};
|
|
1953
|
+
WHTMLSelectElement = class extends WHTMLElement {
|
|
1954
|
+
/** The `<option>`s under the select, `<optgroup>`s included, in tree order. React walks it. */
|
|
1955
|
+
get options() {
|
|
1956
|
+
const out = [];
|
|
1957
|
+
const walk = (el) => {
|
|
1958
|
+
for (const c of el.children) if (c instanceof WHTMLOptionElement) out.push(c);
|
|
1959
|
+
else if (c.localName === "optgroup") walk(c);
|
|
1960
|
+
};
|
|
1961
|
+
walk(this);
|
|
1962
|
+
return out;
|
|
1963
|
+
}
|
|
1964
|
+
get multiple() {
|
|
1965
|
+
return this.hasAttribute("multiple");
|
|
1966
|
+
}
|
|
1967
|
+
set multiple(v) {
|
|
1968
|
+
if (v) this.setAttribute("multiple", "");
|
|
1969
|
+
else this.removeAttribute("multiple");
|
|
1970
|
+
}
|
|
1971
|
+
get value() {
|
|
1972
|
+
const v = this.isoProps.get("value");
|
|
1973
|
+
return typeof v === "string" ? v : "";
|
|
1974
|
+
}
|
|
1975
|
+
set value(v) {
|
|
1976
|
+
this.isoSetProp("value", str(v), true);
|
|
1977
|
+
}
|
|
1978
|
+
get name() {
|
|
1979
|
+
return this.getAttribute("name") ?? "";
|
|
1980
|
+
}
|
|
1981
|
+
set name(v) {
|
|
1982
|
+
this.setAttribute("name", v);
|
|
1983
|
+
}
|
|
1984
|
+
};
|
|
1985
|
+
WHTMLOptionElement = class extends WHTMLElement {
|
|
1986
|
+
/** The `value` attribute, or the text when there's none, as in the DOM. */
|
|
1987
|
+
get value() {
|
|
1988
|
+
return this.getAttribute("value") ?? this.textContent;
|
|
1989
|
+
}
|
|
1990
|
+
set value(v) {
|
|
1991
|
+
this.setAttribute("value", v);
|
|
1992
|
+
}
|
|
1993
|
+
get selected() {
|
|
1994
|
+
const v = this.isoProps.get("selected");
|
|
1995
|
+
return typeof v === "boolean" ? v : this.hasAttribute("selected");
|
|
1996
|
+
}
|
|
1997
|
+
set selected(v) {
|
|
1998
|
+
this.isoSetProp("selected", Boolean(v), true);
|
|
1999
|
+
}
|
|
2000
|
+
get defaultSelected() {
|
|
2001
|
+
return this.hasAttribute("selected");
|
|
2002
|
+
}
|
|
2003
|
+
set defaultSelected(v) {
|
|
2004
|
+
if (v) this.setAttribute("selected", "");
|
|
2005
|
+
else this.removeAttribute("selected");
|
|
2006
|
+
}
|
|
2007
|
+
get disabled() {
|
|
2008
|
+
return this.hasAttribute("disabled");
|
|
2009
|
+
}
|
|
2010
|
+
set disabled(v) {
|
|
2011
|
+
if (v) this.setAttribute("disabled", "");
|
|
2012
|
+
else this.removeAttribute("disabled");
|
|
2013
|
+
}
|
|
2014
|
+
};
|
|
2015
|
+
HTML_CLASSES = {
|
|
2016
|
+
input: WHTMLInputElement,
|
|
2017
|
+
textarea: WHTMLTextAreaElement,
|
|
2018
|
+
select: WHTMLSelectElement,
|
|
2019
|
+
option: WHTMLOptionElement,
|
|
2020
|
+
iframe: WHTMLIFrameElement
|
|
2021
|
+
};
|
|
2022
|
+
WDocument = class extends WEventTarget {
|
|
2023
|
+
nodeType = 9;
|
|
2024
|
+
nodeName = "#document";
|
|
2025
|
+
/** @internal */ isoCore;
|
|
2026
|
+
/** Set by `install()`: the worker global. */
|
|
2027
|
+
defaultView = null;
|
|
2028
|
+
activeElement = null;
|
|
2029
|
+
/** `null`, as for every document. */
|
|
2030
|
+
ownerDocument = null;
|
|
2031
|
+
/** A detached body, for code that falls back to `document.body`. */
|
|
2032
|
+
body;
|
|
2033
|
+
/**
|
|
2034
|
+
* A detached head: React 19 hoists `<title>`, `<meta>` and `<link>` into
|
|
2035
|
+
* it. The bridge doesn't render it (M3a task 3).
|
|
2036
|
+
*/
|
|
2037
|
+
head;
|
|
2038
|
+
constructor(core) {
|
|
2039
|
+
super();
|
|
2040
|
+
this.isoCore = core;
|
|
2041
|
+
this.body = new WHTMLElement(this, -1, "body", "html");
|
|
2042
|
+
this.head = new WHTMLElement(this, -2, "head", "html");
|
|
2043
|
+
}
|
|
2044
|
+
createElement(tag) {
|
|
2045
|
+
const t = tag.toLowerCase();
|
|
2046
|
+
return new ((Object.hasOwn(HTML_CLASSES, t) ? HTML_CLASSES[t] : void 0) ?? WHTMLElement)(this, this.isoCore.nextId++, t, "html");
|
|
2047
|
+
}
|
|
2048
|
+
createElementNS(ns, tag) {
|
|
2049
|
+
if (ns === SVG_NS) return new WSVGElement(this, this.isoCore.nextId++, tag, "svg");
|
|
2050
|
+
if (ns === HTML_NS || ns === null) return this.createElement(tag);
|
|
2051
|
+
throw domError("NotSupportedError", `createElementNS: namespace ${ns} isn't supported`);
|
|
2052
|
+
}
|
|
2053
|
+
/** `data` is converted with `String()`, as in the DOM: Preact passes numbers. */
|
|
2054
|
+
createTextNode(data) {
|
|
2055
|
+
return new WText(this, this.isoCore.nextId++, String(data));
|
|
2056
|
+
}
|
|
2057
|
+
createComment(data) {
|
|
2058
|
+
return new WComment(this, this.isoCore.nextId++, String(data));
|
|
2059
|
+
}
|
|
2060
|
+
/** Fragments never reach the host, so they take no id from the shared counter. */
|
|
2061
|
+
createDocumentFragment() {
|
|
2062
|
+
return new WDocumentFragment(this, -3);
|
|
2063
|
+
}
|
|
2064
|
+
/**
|
|
2065
|
+
* The first element in tree order with this `id` (DOM group 1, ADR 0010):
|
|
2066
|
+
* under the render root, then the detached head. Nodes not yet inserted
|
|
2067
|
+
* aren't in the document, so they aren't found.
|
|
2068
|
+
*/
|
|
2069
|
+
getElementById(id) {
|
|
2070
|
+
const walk = (el) => {
|
|
2071
|
+
for (const c of el.children) {
|
|
2072
|
+
if (c.getAttribute("id") === id) return c;
|
|
2073
|
+
const deeper = walk(c);
|
|
2074
|
+
if (deeper) return deeper;
|
|
2075
|
+
}
|
|
2076
|
+
return null;
|
|
2077
|
+
};
|
|
2078
|
+
for (const root of this.isoCore.roots) {
|
|
2079
|
+
const hit = walk(root);
|
|
2080
|
+
if (hit) return hit;
|
|
2081
|
+
}
|
|
2082
|
+
return walk(this.head);
|
|
2083
|
+
}
|
|
2084
|
+
/**
|
|
2085
|
+
* Type selectors only, alone or as a `head > title` child chain: what React
|
|
2086
|
+
* 19 asks when it hoists a `<title>`. Queries in general are DOM group 2
|
|
2087
|
+
* (ADR 0010), built when a library needs them; anything else throws.
|
|
2088
|
+
*/
|
|
2089
|
+
querySelector(selector) {
|
|
2090
|
+
const steps = selector.split(">").map((t) => t.trim().toLowerCase());
|
|
2091
|
+
if (!steps.every((t) => /^[a-z][a-z0-9-]*$/.test(t))) throw domError("NotSupportedError", `querySelector: "${selector}" isn't supported yet`);
|
|
2092
|
+
const matches = (el) => {
|
|
2093
|
+
let n = el;
|
|
2094
|
+
for (let i = steps.length - 1; i >= 0; i--) {
|
|
2095
|
+
if (!n || n.localName !== steps[i]) return false;
|
|
2096
|
+
n = i > 0 ? n.parentElement : null;
|
|
2097
|
+
}
|
|
2098
|
+
return true;
|
|
2099
|
+
};
|
|
2100
|
+
const walk = (el) => {
|
|
2101
|
+
for (const c of el.children) {
|
|
2102
|
+
if (matches(c)) return c;
|
|
2103
|
+
const deeper = walk(c);
|
|
2104
|
+
if (deeper) return deeper;
|
|
2105
|
+
}
|
|
2106
|
+
return null;
|
|
2107
|
+
};
|
|
2108
|
+
for (const top of [this.head, this.body]) {
|
|
2109
|
+
if (matches(top)) return top;
|
|
2110
|
+
const hit = walk(top);
|
|
2111
|
+
if (hit) return hit;
|
|
2112
|
+
}
|
|
2113
|
+
return null;
|
|
2114
|
+
}
|
|
2115
|
+
};
|
|
2116
|
+
defineHandlers(WDocument.prototype);
|
|
2117
|
+
isControl = (node) => node instanceof WHTMLInputElement || node instanceof WHTMLTextAreaElement || node instanceof WHTMLSelectElement;
|
|
2118
|
+
}));
|
|
2119
|
+
// ../dom/dist/install-D7m7By8i.js
|
|
2120
|
+
/**
|
|
2121
|
+
* Exposes `dom` as the worker's `document`, `window` and DOM classes, so
|
|
2122
|
+
* frameworks find them where they look. Only for isolates with a surface; a
|
|
2123
|
+
* headless isolate never calls this.
|
|
2124
|
+
*/
|
|
2125
|
+
function install(dom, scope) {
|
|
2126
|
+
const define = (name, value) => {
|
|
2127
|
+
Object.defineProperty(scope, name, {
|
|
2128
|
+
value,
|
|
2129
|
+
configurable: true,
|
|
2130
|
+
writable: true
|
|
2131
|
+
});
|
|
2132
|
+
};
|
|
2133
|
+
define("document", dom.document);
|
|
2134
|
+
if (!("window" in scope)) define("window", scope);
|
|
2135
|
+
for (const [name, value] of Object.entries(DOM_GLOBALS)) define(name, value);
|
|
2136
|
+
dom.document.defaultView = scope;
|
|
2137
|
+
}
|
|
2138
|
+
var DOM_GLOBALS;
|
|
2139
|
+
var init_install_D7m7By8i = __esmMin((() => {
|
|
2140
|
+
init_dom_yLsf0Z4e();
|
|
2141
|
+
DOM_GLOBALS = {
|
|
2142
|
+
Node: WNode,
|
|
2143
|
+
Element: WElement,
|
|
2144
|
+
HTMLElement: WHTMLElement,
|
|
2145
|
+
SVGElement: WSVGElement,
|
|
2146
|
+
Text: WText,
|
|
2147
|
+
Comment: WComment,
|
|
2148
|
+
DocumentFragment: WDocumentFragment,
|
|
2149
|
+
HTMLInputElement: WHTMLInputElement,
|
|
2150
|
+
HTMLTextAreaElement: WHTMLTextAreaElement,
|
|
2151
|
+
HTMLSelectElement: WHTMLSelectElement,
|
|
2152
|
+
HTMLOptionElement: WHTMLOptionElement,
|
|
2153
|
+
HTMLIFrameElement: WHTMLIFrameElement,
|
|
2154
|
+
DOMTokenList: WDOMTokenList
|
|
2155
|
+
};
|
|
2156
|
+
}));
|
|
2157
|
+
// ../dom/dist/worker.js
|
|
2158
|
+
var init_worker = __esmMin((() => {
|
|
2159
|
+
init_records_wVZrPpqr();
|
|
2160
|
+
init_dom_yLsf0Z4e();
|
|
2161
|
+
init_install_D7m7By8i();
|
|
2162
|
+
}));
|
|
2163
|
+
// src/render/index.ts
|
|
2164
|
+
function sharedDom(scope) {
|
|
2165
|
+
if (!shared) {
|
|
2166
|
+
shared = createDom({
|
|
2167
|
+
onBatch: () => {},
|
|
2168
|
+
onHead: (tag) => {
|
|
2169
|
+
for (const fn of headListeners) fn(tag);
|
|
2170
|
+
}
|
|
2171
|
+
});
|
|
2172
|
+
if (scope) install(shared, scope);
|
|
2173
|
+
}
|
|
2174
|
+
return shared;
|
|
2175
|
+
}
|
|
2176
|
+
/**
|
|
2177
|
+
* Builds the DOM subset and posts its batches. With `scope`, also installs it
|
|
2178
|
+
* as that global's `document` and DOM classes, which frameworks need. With
|
|
2179
|
+
* `pooled`, the isolate gets its own root in the worker's shared document
|
|
2180
|
+
* instead (ADR 0015).
|
|
2181
|
+
*/
|
|
2182
|
+
function createRender(post, scope, pooled = false, member = null) {
|
|
2183
|
+
const owner = member === null ? null : busy.of(member);
|
|
2184
|
+
const schedule = (flush) => {
|
|
2185
|
+
if (owner === null || member === null) {
|
|
2186
|
+
queueMicrotask(flush);
|
|
2187
|
+
return;
|
|
2188
|
+
}
|
|
2189
|
+
busy.report(member);
|
|
2190
|
+
nativeQueueMicrotask(() => {
|
|
2191
|
+
busy.run(owner, flush, void 0, []);
|
|
2192
|
+
});
|
|
2193
|
+
};
|
|
2194
|
+
let pendingStyles = [];
|
|
2195
|
+
let pendingHead = [];
|
|
2196
|
+
/** Head tags already reported: each goes to the host once. */
|
|
2197
|
+
const headSeen = /* @__PURE__ */ new Set();
|
|
2198
|
+
let extrasScheduled = false;
|
|
2199
|
+
const postPatch = (batch) => {
|
|
2200
|
+
const styles = pendingStyles;
|
|
2201
|
+
const head = pendingHead;
|
|
2202
|
+
pendingStyles = [];
|
|
2203
|
+
pendingHead = [];
|
|
2204
|
+
post({
|
|
2205
|
+
v: 1,
|
|
2206
|
+
t: "patch",
|
|
2207
|
+
p: {
|
|
2208
|
+
fmt: ISOLOOP_DOM_FMT,
|
|
2209
|
+
batch,
|
|
2210
|
+
...styles.length > 0 ? { styles } : {},
|
|
2211
|
+
...head.length > 0 ? { head } : {}
|
|
2212
|
+
}
|
|
2213
|
+
});
|
|
2214
|
+
};
|
|
2215
|
+
/** Styles or head tags with no DOM change still need a patch to travel in. */
|
|
2216
|
+
const scheduleExtras = () => {
|
|
2217
|
+
if (extrasScheduled) return;
|
|
2218
|
+
extrasScheduled = true;
|
|
2219
|
+
queueMicrotask(() => {
|
|
2220
|
+
extrasScheduled = false;
|
|
2221
|
+
target.flush();
|
|
2222
|
+
if (pendingStyles.length > 0 || pendingHead.length > 0) postPatch([]);
|
|
2223
|
+
});
|
|
2224
|
+
};
|
|
2225
|
+
const onHead = (tag) => {
|
|
2226
|
+
if (headSeen.has(tag)) return;
|
|
2227
|
+
headSeen.add(tag);
|
|
2228
|
+
pendingHead.push(tag);
|
|
2229
|
+
scheduleExtras();
|
|
2230
|
+
};
|
|
2231
|
+
let target;
|
|
2232
|
+
if (pooled) {
|
|
2233
|
+
const own = sharedDom(scope).addRoot({
|
|
2234
|
+
onBatch: postPatch,
|
|
2235
|
+
schedule
|
|
2236
|
+
});
|
|
2237
|
+
headListeners.add(onHead);
|
|
2238
|
+
target = {
|
|
2239
|
+
...own,
|
|
2240
|
+
dispose() {
|
|
2241
|
+
headListeners.delete(onHead);
|
|
2242
|
+
own.dispose();
|
|
2243
|
+
}
|
|
2244
|
+
};
|
|
2245
|
+
} else {
|
|
2246
|
+
const dom = createDom({
|
|
2247
|
+
onBatch: postPatch,
|
|
2248
|
+
schedule,
|
|
2249
|
+
onHead
|
|
2250
|
+
});
|
|
2251
|
+
if (scope) install(dom, scope);
|
|
2252
|
+
target = {
|
|
2253
|
+
root: dom.root,
|
|
2254
|
+
flush: () => dom.flush(),
|
|
2255
|
+
deliver: (event) => dom.deliver(event),
|
|
2256
|
+
idOf: (node) => node.isConnected ? dom.idOf(node) : void 0,
|
|
2257
|
+
setValue: (node, value, o) => dom.setValue(node, value, o),
|
|
2258
|
+
dispose: () => {}
|
|
2259
|
+
};
|
|
2260
|
+
}
|
|
2261
|
+
return {
|
|
2262
|
+
fmt: ISOLOOP_DOM_FMT,
|
|
2263
|
+
root: target.root,
|
|
2264
|
+
flush: () => target.flush(),
|
|
2265
|
+
setValue: (node, value, o) => target.setValue(node, value, o),
|
|
2266
|
+
dispose: () => target.dispose(),
|
|
2267
|
+
styles(css) {
|
|
2268
|
+
pendingStyles.push(...typeof css === "string" ? [css] : css);
|
|
2269
|
+
scheduleExtras();
|
|
2270
|
+
},
|
|
2271
|
+
idOf(node) {
|
|
2272
|
+
if (!(node instanceof WNode)) return void 0;
|
|
2273
|
+
const id = target.idOf(node);
|
|
2274
|
+
return id === void 0 ? void 0 : String(id);
|
|
2275
|
+
},
|
|
2276
|
+
receive(e) {
|
|
2277
|
+
const t = nodeId(e.target);
|
|
2278
|
+
if (t === void 0) return;
|
|
2279
|
+
const currentTargets = e.currentTargets.map(nodeId).filter((n) => n !== void 0);
|
|
2280
|
+
const { target: _t, currentTargets: _c, ...rest } = e;
|
|
2281
|
+
target.deliver({
|
|
2282
|
+
...rest,
|
|
2283
|
+
target: t,
|
|
2284
|
+
currentTargets
|
|
2285
|
+
});
|
|
2286
|
+
}
|
|
2287
|
+
};
|
|
2288
|
+
}
|
|
2289
|
+
var nodeId, shared, headListeners;
|
|
2290
|
+
var init_render = __esmMin((() => {
|
|
2291
|
+
init_worker();
|
|
2292
|
+
init_busy();
|
|
2293
|
+
nodeId = (s) => /^\d+$/.test(s) ? Number(s) : void 0;
|
|
2294
|
+
shared = null;
|
|
2295
|
+
headListeners = /* @__PURE__ */ new Set();
|
|
2296
|
+
}));
|
|
2297
|
+
// package.json
|
|
2298
|
+
var version = "0.0.0";
|
|
2299
|
+
// src/vanilla.ts
|
|
2300
|
+
var vanilla_exports = /* @__PURE__ */ __exportAll({
|
|
2301
|
+
REQUIRES: () => REQUIRES,
|
|
2302
|
+
createVanillaIsolate: () => createVanillaIsolate,
|
|
2303
|
+
defineIsolate: () => defineIsolate
|
|
2304
|
+
});
|
|
2305
|
+
/**
|
|
2306
|
+
* Types an isolate module's default export and stamps it with the version
|
|
2307
|
+
* it was built against. `Root` defaults to the structural `IsolateRoot`.
|
|
2308
|
+
*/
|
|
2309
|
+
function defineIsolate(def) {
|
|
2310
|
+
return {
|
|
2311
|
+
requires: REQUIRES,
|
|
2312
|
+
...def
|
|
2313
|
+
};
|
|
2314
|
+
}
|
|
2315
|
+
/** Builds the context for `start(ctx)`. `scope` is the worker global the DOM subset installs on. */
|
|
2316
|
+
function createVanillaIsolate(init, post, scope, pooled = false, member = null) {
|
|
2317
|
+
const render = init.renderFmt === "none" ? null : createRender(post, scope, pooled, member);
|
|
2318
|
+
const calls = createHostCalls({
|
|
2319
|
+
post,
|
|
2320
|
+
beforeCall: () => render?.flush(),
|
|
2321
|
+
idOf: (node) => render ? render.idOf(node) : void 0,
|
|
2322
|
+
surface: render !== null,
|
|
2323
|
+
navigate: init.grants.navigate === true
|
|
2324
|
+
});
|
|
2325
|
+
const awake = createKeepAwake();
|
|
2326
|
+
const bus = createBusClient(init.busPort, {
|
|
2327
|
+
...init.wake ? { wake: true } : {},
|
|
2328
|
+
...init.commitIntervalMs === void 0 ? {} : { commitIntervalMs: init.commitIntervalMs },
|
|
2329
|
+
onError: (err) => {
|
|
2330
|
+
post({
|
|
2331
|
+
v: 1,
|
|
2332
|
+
t: "error",
|
|
2333
|
+
p: err instanceof Error && err.stack !== void 0 ? {
|
|
2334
|
+
message: err.message,
|
|
2335
|
+
stack: err.stack,
|
|
2336
|
+
fatal: false
|
|
2337
|
+
} : {
|
|
2338
|
+
message: String(err),
|
|
2339
|
+
fatal: false
|
|
2340
|
+
}
|
|
2341
|
+
});
|
|
2342
|
+
}
|
|
2343
|
+
});
|
|
2344
|
+
const onShutdown = [];
|
|
2345
|
+
let portal;
|
|
2346
|
+
const ctx = {
|
|
2347
|
+
id: init.isolateId,
|
|
2348
|
+
config: init.config,
|
|
2349
|
+
root: render?.root,
|
|
2350
|
+
portalRoot: void 0,
|
|
2351
|
+
reportError(error, o = {}) {
|
|
2352
|
+
const fatal = o.fatal ?? true;
|
|
2353
|
+
post({
|
|
2354
|
+
v: 1,
|
|
2355
|
+
t: "error",
|
|
2356
|
+
p: error instanceof Error ? {
|
|
2357
|
+
message: error.message,
|
|
2358
|
+
...error.stack === void 0 ? {} : { stack: error.stack },
|
|
2359
|
+
fatal
|
|
2360
|
+
} : {
|
|
2361
|
+
message: String(error),
|
|
2362
|
+
fatal
|
|
2363
|
+
}
|
|
2364
|
+
});
|
|
2365
|
+
},
|
|
2366
|
+
host: calls.api,
|
|
2367
|
+
bus: bus.client,
|
|
2368
|
+
styles: (css) => render?.styles(css),
|
|
2369
|
+
setValue(node, value, o) {
|
|
2370
|
+
if (!render) return;
|
|
2371
|
+
if (!(node instanceof WNode)) throw new TypeError("setValue: not a node of this isolate");
|
|
2372
|
+
render.setValue(node, value, o);
|
|
2373
|
+
},
|
|
2374
|
+
onShutdown: (fn) => {
|
|
2375
|
+
onShutdown.push(fn);
|
|
2376
|
+
},
|
|
2377
|
+
keepAwake: () => awake.hold()
|
|
2378
|
+
};
|
|
2379
|
+
if (member !== null) Object.defineProperty(ctx, BUSY, {
|
|
2380
|
+
value: {
|
|
2381
|
+
claim: (container) => {
|
|
2382
|
+
busy.claim(container, member);
|
|
2383
|
+
},
|
|
2384
|
+
bind: (fn) => busy.bind(fn)
|
|
2385
|
+
},
|
|
2386
|
+
enumerable: false
|
|
2387
|
+
});
|
|
2388
|
+
Object.defineProperty(ctx, "portalRoot", {
|
|
2389
|
+
enumerable: false,
|
|
2390
|
+
get() {
|
|
2391
|
+
if (!render) return void 0;
|
|
2392
|
+
if (!portal) {
|
|
2393
|
+
const { root } = render;
|
|
2394
|
+
const div = root.ownerDocument.createElement("div");
|
|
2395
|
+
div.setAttribute("data-isoloop-portal", "");
|
|
2396
|
+
queueMicrotask(() => {
|
|
2397
|
+
if (div.parentNode !== root) root.appendChild(div);
|
|
2398
|
+
});
|
|
2399
|
+
portal = div;
|
|
2400
|
+
}
|
|
2401
|
+
return portal;
|
|
2402
|
+
}
|
|
2403
|
+
});
|
|
2404
|
+
return {
|
|
2405
|
+
ctx,
|
|
2406
|
+
renderFmt: render ? render.fmt : "none",
|
|
2407
|
+
receive(msg) {
|
|
2408
|
+
if (isHostToIsolate(msg)) {
|
|
2409
|
+
if (msg.t === "event") render?.receive(msg.p);
|
|
2410
|
+
else if (msg.t === "reattach") bus.reattach(msg.p.busPort);
|
|
2411
|
+
else if (msg.t === "result" && msg.re !== void 0) calls.receive(msg.re, msg.p);
|
|
2412
|
+
}
|
|
2413
|
+
},
|
|
2414
|
+
idle() {
|
|
2415
|
+
const b = bus.idle();
|
|
2416
|
+
return {
|
|
2417
|
+
sinceDeliveryMs: b.sinceDeliveryMs,
|
|
2418
|
+
inFlight: b.inFlight + calls.pending(),
|
|
2419
|
+
holds: awake.report(performance.now())
|
|
2420
|
+
};
|
|
2421
|
+
},
|
|
2422
|
+
async shutdown(reason) {
|
|
2423
|
+
await Promise.allSettled(onShutdown.map(async (fn) => fn(reason)));
|
|
2424
|
+
await bus.close();
|
|
2425
|
+
render?.flush();
|
|
2426
|
+
render?.dispose();
|
|
2427
|
+
}
|
|
2428
|
+
};
|
|
2429
|
+
}
|
|
2430
|
+
var REQUIRES;
|
|
2431
|
+
var init_vanilla = __esmMin((() => {
|
|
2432
|
+
init_dist();
|
|
2433
|
+
init_bus_client();
|
|
2434
|
+
init_busy();
|
|
2435
|
+
init_host_calls();
|
|
2436
|
+
init_keep_awake();
|
|
2437
|
+
init_worker();
|
|
2438
|
+
init_render();
|
|
2439
|
+
REQUIRES = majorMinor(version) ?? "0.0";
|
|
2440
|
+
}));
|
|
2441
|
+
// src/bootstrap.ts
|
|
2442
|
+
var bootstrap_exports = /* @__PURE__ */ __exportAll({});
|
|
2443
|
+
/** Once per worker, after the first isolate's protocol check. */
|
|
2444
|
+
function startHeartbeat(everyMs) {
|
|
2445
|
+
if (beating) return;
|
|
2446
|
+
beating = true;
|
|
2447
|
+
let last = performance.now();
|
|
2448
|
+
setInterval(() => {
|
|
2449
|
+
const now = performance.now();
|
|
2450
|
+
const lagMs = Math.max(0, now - last - everyMs);
|
|
2451
|
+
if (mode === "pool") {
|
|
2452
|
+
const reports = {};
|
|
2453
|
+
for (const m of members.values()) if (m.name !== void 0 && m.idleReport) reports[m.name] = m.idleReport();
|
|
2454
|
+
postWorker({
|
|
2455
|
+
v: 1,
|
|
2456
|
+
t: "beat",
|
|
2457
|
+
p: {
|
|
2458
|
+
lagMs,
|
|
2459
|
+
members: reports
|
|
2460
|
+
}
|
|
2461
|
+
});
|
|
2462
|
+
} else {
|
|
2463
|
+
const idle = members.get(void 0)?.idleReport?.();
|
|
2464
|
+
postWorker({
|
|
2465
|
+
v: 1,
|
|
2466
|
+
t: "beat",
|
|
2467
|
+
p: idle ? {
|
|
2468
|
+
lagMs,
|
|
2469
|
+
idle
|
|
2470
|
+
} : { lagMs }
|
|
2471
|
+
});
|
|
2472
|
+
}
|
|
2473
|
+
last = now;
|
|
2474
|
+
}, everyMs);
|
|
2475
|
+
}
|
|
2476
|
+
/** `shutdown` for a member: `bye` once its handlers settle or the grace runs out. */
|
|
2477
|
+
function shutdownMember(m, graceMs, reason) {
|
|
2478
|
+
if (members.get(m.name) === m) members.delete(m.name);
|
|
2479
|
+
m.receive = null;
|
|
2480
|
+
const hook = m.shutdownHook;
|
|
2481
|
+
const done = (hook ? busy.run(busy.of(m.name), hook, void 0, [reason]) : void 0) ?? Promise.resolve();
|
|
2482
|
+
const grace = new Promise((r) => setTimeout(r, Math.max(0, graceMs - 50)));
|
|
2483
|
+
Promise.race([done, grace]).finally(() => {
|
|
2484
|
+
m.post({
|
|
2485
|
+
v: 1,
|
|
2486
|
+
t: "bye",
|
|
2487
|
+
p: {}
|
|
2488
|
+
});
|
|
2489
|
+
if (members.size === 0) self.close();
|
|
2490
|
+
});
|
|
2491
|
+
}
|
|
2492
|
+
/** Routes one message from the host to the member it is for. */
|
|
2493
|
+
function route(msg) {
|
|
2494
|
+
const m = members.get(mode === "pool" ? msg.isolate : void 0);
|
|
2495
|
+
if (!m) return;
|
|
2496
|
+
if (msg.t === "shutdown") shutdownMember(m, msg.p.graceMs, msg.p.reason);
|
|
2497
|
+
else if (m.receive) busy.run(busy.of(m.name), m.receive, void 0, [msg]);
|
|
2498
|
+
}
|
|
2499
|
+
async function boot(m, init) {
|
|
2500
|
+
if (init.protocol.min > PROTOCOL.v || init.protocol.max < PROTOCOL.min) {
|
|
2501
|
+
fatal(m, `Host speaks protocol ${init.protocol.min}–${init.protocol.max}, this runtime ${PROTOCOL.min}–${PROTOCOL.v}`, "protocol_mismatch");
|
|
2502
|
+
return;
|
|
2503
|
+
}
|
|
2504
|
+
startHeartbeat(init.heartbeatMs);
|
|
2505
|
+
const { createVanillaIsolate } = await Promise.resolve().then(() => (init_vanilla(), vanilla_exports));
|
|
2506
|
+
const runtime = busy.run(busy.of(m.name), createVanillaIsolate, void 0, [
|
|
2507
|
+
init,
|
|
2508
|
+
m.post,
|
|
2509
|
+
self,
|
|
2510
|
+
mode === "pool",
|
|
2511
|
+
m.name
|
|
2512
|
+
]);
|
|
2513
|
+
let mod;
|
|
2514
|
+
try {
|
|
2515
|
+
mod = await import(
|
|
2516
|
+
/* @vite-ignore */
|
|
2517
|
+
init.src
|
|
2518
|
+
);
|
|
2519
|
+
} catch (err) {
|
|
2520
|
+
const why = err instanceof Error ? err.message : String(err);
|
|
2521
|
+
const cross = new URL(init.src).origin !== self.location.origin;
|
|
2522
|
+
fatal(m, `Could not import ${init.src}: ${why}${cross ? " (a cross-origin isolate needs CORS headers; see docs/guide/hosting.md)" : ""}`);
|
|
2523
|
+
return;
|
|
2524
|
+
}
|
|
2525
|
+
const main = typeof mod === "object" && mod !== null && "default" in mod ? mod.default : void 0;
|
|
2526
|
+
if (typeof main === "object" && main !== null && "start" in main) {
|
|
2527
|
+
const start = main.start;
|
|
2528
|
+
if (typeof start === "function") {
|
|
2529
|
+
const requires = "requires" in main ? main.requires : void 0;
|
|
2530
|
+
await startIsolate(m, runtime, (ctx) => Reflect.apply(start, main, [ctx]), typeof requires === "string" ? requires : void 0);
|
|
2531
|
+
return;
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
fatal(m, `${init.src} has no default export with start(ctx)`);
|
|
2535
|
+
}
|
|
2536
|
+
async function startIsolate(m, runtime, start, requires) {
|
|
2537
|
+
m.receive = (msg) => {
|
|
2538
|
+
runtime.receive(msg);
|
|
2539
|
+
};
|
|
2540
|
+
m.shutdownHook = (reason) => runtime.shutdown(reason);
|
|
2541
|
+
m.idleReport = () => ({
|
|
2542
|
+
...runtime.idle(),
|
|
2543
|
+
busyMs: busy.take(m.name)
|
|
2544
|
+
});
|
|
2545
|
+
m.post({
|
|
2546
|
+
v: 1,
|
|
2547
|
+
t: "ready",
|
|
2548
|
+
p: {
|
|
2549
|
+
runtime: "@isoloop/runtime",
|
|
2550
|
+
adapter: "vanilla",
|
|
2551
|
+
renderFmt: runtime.renderFmt,
|
|
2552
|
+
...requires === void 0 ? {} : { requires }
|
|
2553
|
+
}
|
|
2554
|
+
});
|
|
2555
|
+
try {
|
|
2556
|
+
await busy.run(busy.of(m.name), start, void 0, [runtime.ctx]);
|
|
2557
|
+
} catch (err) {
|
|
2558
|
+
fatal(m, `start() threw: ${err instanceof Error ? err.message : String(err)}`);
|
|
2559
|
+
}
|
|
2560
|
+
}
|
|
2561
|
+
/** Handles one message from the host: `init` boots a member, the rest is routed. */
|
|
2562
|
+
function onMessage(e) {
|
|
2563
|
+
const msg = e.data;
|
|
2564
|
+
if (!isHostToIsolate(msg)) return;
|
|
2565
|
+
if (msg.t !== "init") {
|
|
2566
|
+
route(msg);
|
|
2567
|
+
return;
|
|
2568
|
+
}
|
|
2569
|
+
const name = msg.isolate;
|
|
2570
|
+
const wants = name === void 0 ? "own" : "pool";
|
|
2571
|
+
if (mode === "own" || mode === "pool" && wants === "own") return;
|
|
2572
|
+
if (mode === null) {
|
|
2573
|
+
mode = wants;
|
|
2574
|
+
if (mode === "pool") freezeBuiltins();
|
|
2575
|
+
}
|
|
2576
|
+
if (members.has(name)) return;
|
|
2577
|
+
const m = {
|
|
2578
|
+
name,
|
|
2579
|
+
post: memberPost(name),
|
|
2580
|
+
shutdownHook: null,
|
|
2581
|
+
idleReport: null,
|
|
2582
|
+
receive: null
|
|
2583
|
+
};
|
|
2584
|
+
members.set(name, m);
|
|
2585
|
+
boot(m, msg.p).catch((err) => {
|
|
2586
|
+
fatal(m, err instanceof Error ? err.message : String(err));
|
|
2587
|
+
});
|
|
2588
|
+
}
|
|
2589
|
+
function startOnce() {
|
|
2590
|
+
installBusy(self, busy);
|
|
2591
|
+
self.addEventListener("message", onMessage);
|
|
2592
|
+
}
|
|
2593
|
+
var mode, members, postWorker, memberPost, fatal, beating, STARTED;
|
|
2594
|
+
var init_bootstrap = __esmMin((() => {
|
|
2595
|
+
init_dist();
|
|
2596
|
+
init_busy();
|
|
2597
|
+
init_freeze();
|
|
2598
|
+
mode = null;
|
|
2599
|
+
members = /* @__PURE__ */ new Map();
|
|
2600
|
+
postWorker = (msg) => {
|
|
2601
|
+
self.postMessage(msg);
|
|
2602
|
+
};
|
|
2603
|
+
memberPost = (name) => (msg) => {
|
|
2604
|
+
self.postMessage(name === void 0 ? msg : {
|
|
2605
|
+
...msg,
|
|
2606
|
+
isolate: name
|
|
2607
|
+
});
|
|
2608
|
+
};
|
|
2609
|
+
fatal = (m, message, code) => {
|
|
2610
|
+
m.post({
|
|
2611
|
+
v: 1,
|
|
2612
|
+
t: "error",
|
|
2613
|
+
p: code ? {
|
|
2614
|
+
message,
|
|
2615
|
+
fatal: true,
|
|
2616
|
+
code
|
|
2617
|
+
} : {
|
|
2618
|
+
message,
|
|
2619
|
+
fatal: true
|
|
2620
|
+
}
|
|
2621
|
+
});
|
|
2622
|
+
};
|
|
2623
|
+
beating = false;
|
|
2624
|
+
STARTED = Symbol.for("isoloop.bootstrap");
|
|
2625
|
+
if (Reflect.get(self, STARTED) === true) {
|
|
2626
|
+
if (import.meta.env?.DEV === true) console.warn("isoloop: worker entry evaluated twice; ignoring");
|
|
2627
|
+
} else {
|
|
2628
|
+
Reflect.set(self, STARTED, true);
|
|
2629
|
+
startOnce();
|
|
2630
|
+
}
|
|
2631
|
+
}));
|
|
2632
|
+
// src/worker.ts
|
|
2633
|
+
const held = [];
|
|
2634
|
+
const hold = (e) => {
|
|
2635
|
+
held.push(e);
|
|
2636
|
+
};
|
|
2637
|
+
self.addEventListener("message", hold);
|
|
2638
|
+
Promise.resolve().then(() => (init_bootstrap(), bootstrap_exports)).then(() => {
|
|
2639
|
+
self.removeEventListener("message", hold);
|
|
2640
|
+
for (const e of held.splice(0)) self.dispatchEvent(new MessageEvent("message", {
|
|
2641
|
+
data: e.data,
|
|
2642
|
+
ports: [...e.ports]
|
|
2643
|
+
}));
|
|
2644
|
+
}, (err) => {
|
|
2645
|
+
setTimeout(() => {
|
|
2646
|
+
throw err;
|
|
2647
|
+
});
|
|
2648
|
+
});
|