@isoloop/runtime 0.1.0-next.1 → 0.1.0-next.11

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/worker.js CHANGED
@@ -25,7 +25,7 @@ var __exportAll = (all, flags) => {
25
25
  * Says nothing about whether `t` is known; see the per-port guards.
26
26
  */
27
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"]);
28
+ return isRecord$1(x) && x["v"] === PROTOCOL.v && typeof x["t"] === "string" && "p" in x && isOptionalString(x["id"]) && isOptionalString(x["re"]) && isOptionalString(x["isolate"]);
29
29
  }
30
30
  /**
31
31
  * Builds a guard for one port's union from its message types. Each side drops
@@ -42,7 +42,9 @@ function isSystemTopic(topic) {
42
42
  * The commit point each record of one `deliver` settles to, in order. A
43
43
  * record settles its delivery `seq` only as the delivery's last record, and
44
44
  * `seq − 1` before that: a delivery counts once all its records are settled,
45
- * and records settle in the order they arrived. Its offset is the highest
45
+ * and records settle in the order they arrived. Before the last, the `i`-th
46
+ * record also settles the first `i + 1` records of its delivery (`partial`,
47
+ * ADR 0016, point 17). Its offset is the highest
46
48
  * delivered on the subscription up to it, `highest` being the highest before
47
49
  * this delivery (`-1` for none), so a commit that counts a delivery settled
48
50
  * also reaches every offset in it.
@@ -51,12 +53,30 @@ function deliveryPoints(seq, offsets, highest) {
51
53
  let top = highest;
52
54
  return offsets.map((offset, i) => {
53
55
  top = Math.max(top, offset);
54
- return {
56
+ return i === offsets.length - 1 ? {
57
+ offset: top,
58
+ seq
59
+ } : {
55
60
  offset: top,
56
- seq: i === offsets.length - 1 ? seq : seq - 1
61
+ seq: seq - 1,
62
+ partial: i + 1
57
63
  };
58
64
  });
59
65
  }
66
+ /**
67
+ * The further of two commit points: the highest offset, and the delivery
68
+ * reached furthest, a whole delivery being further than any part of it.
69
+ */
70
+ function later(a, b) {
71
+ const offset = Math.max(a.offset, b.offset);
72
+ const reach = (p) => [p.seq, p.partial ?? 0];
73
+ const [as, ap] = reach(a);
74
+ const [bs, bp] = reach(b);
75
+ return point({
76
+ ...bs > as || bs === as && bp >= ap ? b : a,
77
+ offset
78
+ });
79
+ }
60
80
  function createCommitter(o) {
61
81
  const intervalMs = o.intervalMs ?? 100;
62
82
  const half = Math.max(1, Math.floor((o.credit ?? 1e3) / 2));
@@ -74,7 +94,12 @@ function createCommitter(o) {
74
94
  queued = false;
75
95
  if (offsets.size === 0) return void 0;
76
96
  const out = [];
77
- for (const [topic, { offset, seq }] of offsets) out.push({
97
+ for (const [topic, { offset, seq, partial }] of offsets) out.push(partial ? {
98
+ topic,
99
+ offset,
100
+ seq,
101
+ partial
102
+ } : {
78
103
  topic,
79
104
  offset,
80
105
  seq
@@ -101,13 +126,7 @@ function createCommitter(o) {
101
126
  return {
102
127
  settle(topic, at, records = 1) {
103
128
  const prev = offsets.get(topic);
104
- offsets.set(topic, prev === void 0 ? {
105
- offset: at.offset,
106
- seq: at.seq
107
- } : {
108
- offset: Math.max(prev.offset, at.offset),
109
- seq: Math.max(prev.seq, at.seq)
110
- });
129
+ offsets.set(topic, prev === void 0 ? point(at) : later(prev, at));
111
130
  const n = (counts.get(topic) ?? 0) + records;
112
131
  counts.set(topic, n);
113
132
  if (n >= half) flush();
@@ -151,13 +170,13 @@ function majorMinor(version) {
151
170
  const m = /^(\d+)\.(\d+)(?:[.+-].*)?$/.exec(version);
152
171
  return m ? `${Number(m[1])}.${Number(m[2])}` : void 0;
153
172
  }
154
- var PROTOCOL, isRecord, isOptionalString, ERROR_CODES, SYSTEM_TOPIC_PREFIX, HOST_TO_ISOLATE, isHostToIsolate, BUS_TO_ISOLATE, isBusToIsolate, BusError, isObject, issue, checks, stringOrNull;
173
+ var PROTOCOL, isRecord$1, isOptionalString, ERROR_CODES, SYSTEM_TOPIC_PREFIX, MAX_BLOCK_MS, HOST_TO_ISOLATE, isHostToIsolate, BUS_TO_ISOLATE, isBusToIsolate, point, BusError, isObject, issue, checks, stringOrNull, INSPECT_MESSAGES, INSPECT_TO_ISOLATE, isInspectToIsolate;
155
174
  var init_dist = __esmMin((() => {
156
175
  PROTOCOL = {
157
176
  v: 1,
158
177
  min: 1
159
178
  };
160
- isRecord = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
179
+ isRecord$1 = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
161
180
  isOptionalString = (x) => x === void 0 || typeof x === "string";
162
181
  ERROR_CODES = [
163
182
  "protocol_mismatch",
@@ -178,6 +197,9 @@ var init_dist = __esmMin((() => {
178
197
  "not_requestable",
179
198
  "already_replied",
180
199
  "reply_invalid",
200
+ "aborted",
201
+ "no_responder",
202
+ "dropped",
181
203
  "contracts_failed",
182
204
  "contracts_invalid",
183
205
  "contracts_mismatch",
@@ -187,23 +209,42 @@ var init_dist = __esmMin((() => {
187
209
  ];
188
210
  new Set(ERROR_CODES);
189
211
  SYSTEM_TOPIC_PREFIX = "isoloop.";
212
+ MAX_BLOCK_MS = 1e4;
190
213
  HOST_TO_ISOLATE = {
191
214
  init: true,
192
215
  event: true,
193
216
  result: true,
194
217
  shutdown: true,
195
- reattach: true
218
+ reattach: true,
219
+ block: true,
220
+ inspect: true
196
221
  };
197
222
  isHostToIsolate = envelopeGuard(HOST_TO_ISOLATE);
223
+ Object.freeze([
224
+ "mcp",
225
+ "webmcp",
226
+ "builder"
227
+ ]);
198
228
  BUS_TO_ISOLATE = {
199
229
  deliver: true,
200
230
  reset: true,
201
231
  result: true
202
232
  };
203
233
  isBusToIsolate = envelopeGuard(BUS_TO_ISOLATE);
234
+ point = ({ offset, seq, partial }) => partial ? {
235
+ offset,
236
+ seq,
237
+ partial
238
+ } : {
239
+ offset,
240
+ seq
241
+ };
204
242
  BusError = class extends Error {
243
+ /** What went wrong, to branch on: `invalid`, `forbidden`, `timeout`, `bus_unavailable`, … */
205
244
  code;
245
+ /** For `invalid`: where the value failed its schema, and why. */
206
246
  issues;
247
+ /** @param error The broker's error: its code, message and issues. */
207
248
  constructor(error) {
208
249
  super(error.message);
209
250
  this.name = "BusError";
@@ -240,8 +281,22 @@ var init_dist = __esmMin((() => {
240
281
  })),
241
282
  retention: { kind: "compacted" }
242
283
  });
284
+ INSPECT_MESSAGES = {
285
+ snapshot: true,
286
+ event: true,
287
+ beats: true,
288
+ metrics: true,
289
+ memory: true
290
+ };
291
+ INSPECT_TO_ISOLATE = {
292
+ ...INSPECT_MESSAGES,
293
+ result: true,
294
+ record: true,
295
+ skipped: true
296
+ };
297
+ isInspectToIsolate = envelopeGuard(INSPECT_TO_ISOLATE);
243
298
  }));
244
- // src/busy.ts
299
+ // src/pools/busy.ts
245
300
  function createBusy(now = () => performance.now()) {
246
301
  let frame = null;
247
302
  const spent = /* @__PURE__ */ new Map();
@@ -554,7 +609,7 @@ var init_busy = __esmMin((() => {
554
609
  busy = createBusy();
555
610
  BUSY = Symbol.for("isoloop.busy");
556
611
  }));
557
- // src/freeze.ts
612
+ // src/pools/freeze.ts
558
613
  /** The protected properties, per prototype, that are left as frozen data. */
559
614
  function protectedProperties() {
560
615
  const out = /* @__PURE__ */ new Map();
@@ -698,7 +753,189 @@ var init_freeze = __esmMin((() => {
698
753
  ];
699
754
  ITERATOR = Symbol.iterator;
700
755
  }));
701
- // src/bus-client.ts
756
+ // src/isolate/inspector.ts
757
+ function createInspectorClient() {
758
+ let port = null;
759
+ let ended = false;
760
+ let lastSnapshot;
761
+ /** What was asked before the port arrived. */
762
+ const queue = [];
763
+ const pending = /* @__PURE__ */ new Map();
764
+ const taps = /* @__PURE__ */ new Map();
765
+ const listeners = /* @__PURE__ */ new Set();
766
+ let next = 0;
767
+ const send = (m) => {
768
+ if (port) port.postMessage(m);
769
+ else queue.push(m);
770
+ };
771
+ const ask = (m) => {
772
+ const id = `i${++next}`;
773
+ const done = new Promise((resolve, reject) => {
774
+ pending.set(id, {
775
+ resolve,
776
+ reject
777
+ });
778
+ });
779
+ send({
780
+ v: 1,
781
+ id,
782
+ ...m
783
+ });
784
+ return {
785
+ id,
786
+ done
787
+ };
788
+ };
789
+ const onMessage = (e) => {
790
+ const msg = e.data;
791
+ if (!isInspectToIsolate(msg)) return;
792
+ if (msg.t === "record") {
793
+ if (msg.re !== void 0) taps.get(msg.re)?.fn(msg.p);
794
+ return;
795
+ }
796
+ if (msg.t === "skipped") {
797
+ if (msg.re !== void 0) taps.get(msg.re)?.onSkipped?.(msg.p.count);
798
+ return;
799
+ }
800
+ if (msg.re !== void 0) {
801
+ const p = pending.get(msg.re);
802
+ if (!p) return;
803
+ pending.delete(msg.re);
804
+ if (msg.t === "snapshot") {
805
+ lastSnapshot = msg.p;
806
+ p.resolve(msg.p);
807
+ } else if (msg.t === "result") {
808
+ const err = failure(msg.p);
809
+ if (err) p.reject(err);
810
+ else p.resolve(msg.p.ok ? msg.p.value : void 0);
811
+ }
812
+ return;
813
+ }
814
+ if (msg.t === "result") return;
815
+ for (const fn of listeners) try {
816
+ fn(msg);
817
+ } catch (err) {
818
+ setTimeout(() => {
819
+ throw err;
820
+ });
821
+ }
822
+ };
823
+ const control = async (action, id, ms) => {
824
+ if (ended) throw endedError();
825
+ await ask({
826
+ t: "control",
827
+ p: ms === void 0 ? {
828
+ action,
829
+ id
830
+ } : {
831
+ action,
832
+ id,
833
+ ms
834
+ }
835
+ }).done;
836
+ };
837
+ const client = {
838
+ inspector: {
839
+ async snapshot() {
840
+ if (ended) {
841
+ if (lastSnapshot) return lastSnapshot;
842
+ throw endedError();
843
+ }
844
+ return await ask({
845
+ t: "snapshot",
846
+ p: {}
847
+ }).done;
848
+ },
849
+ on(fn) {
850
+ const entry = (m) => fn(m);
851
+ listeners.add(entry);
852
+ if (listeners.size === 1) send({
853
+ v: 1,
854
+ t: "listen",
855
+ p: {}
856
+ });
857
+ return () => {
858
+ if (!listeners.delete(entry)) return;
859
+ if (listeners.size === 0) send({
860
+ v: 1,
861
+ t: "unlisten",
862
+ p: {}
863
+ });
864
+ };
865
+ },
866
+ async records(topic, o) {
867
+ return await ask({
868
+ t: "records",
869
+ p: {
870
+ topic,
871
+ last: o.last
872
+ }
873
+ }).done;
874
+ },
875
+ tap(o, fn) {
876
+ const p = o.maxPerSec === void 0 ? { topics: [...o.topics] } : {
877
+ topics: [...o.topics],
878
+ maxPerSec: o.maxPerSec
879
+ };
880
+ const { id, done } = ask({
881
+ t: "tap",
882
+ p
883
+ });
884
+ taps.set(id, {
885
+ fn,
886
+ onSkipped: o.onSkipped
887
+ });
888
+ let open = true;
889
+ done.catch(() => {
890
+ taps.delete(id);
891
+ });
892
+ return () => {
893
+ if (!open) return;
894
+ open = false;
895
+ taps.delete(id);
896
+ send({
897
+ v: 1,
898
+ t: "untap",
899
+ re: id,
900
+ p: {}
901
+ });
902
+ };
903
+ },
904
+ restart: (id) => control("restart", id),
905
+ kill: (id) => control("kill", id),
906
+ block: (id, ms) => control("block", id, ms)
907
+ },
908
+ attach(p) {
909
+ if (port) return;
910
+ port = p;
911
+ p.addEventListener("message", onMessage);
912
+ p.addEventListener("close", () => {
913
+ client.end();
914
+ });
915
+ p.start();
916
+ for (const m of queue.splice(0)) p.postMessage(m);
917
+ },
918
+ end() {
919
+ if (ended) return;
920
+ ended = true;
921
+ queue.length = 0;
922
+ for (const p of pending.values()) p.reject(endedError());
923
+ pending.clear();
924
+ taps.clear();
925
+ listeners.clear();
926
+ port?.removeEventListener("message", onMessage);
927
+ port?.close();
928
+ }
929
+ };
930
+ return client;
931
+ }
932
+ var failure, endedError;
933
+ var init_inspector = __esmMin((() => {
934
+ init_dist();
935
+ failure = (r) => r.ok ? void 0 : new BusError(r.error);
936
+ endedError = () => /* @__PURE__ */ new Error("inspector: its port has ended; controls no longer act");
937
+ }));
938
+ // src/bus/bus-client.ts
702
939
  function createBusClient(first, o = {}) {
703
940
  const limit = o.inboxLimit ?? 1e3;
704
941
  const now = o.now ?? (() => performance.now());
@@ -989,7 +1226,7 @@ var init_bus_client = __esmMin((() => {
989
1226
  };
990
1227
  REQUEST_TIMEOUT_MS = 3e4;
991
1228
  }));
992
- // src/host-calls.ts
1229
+ // src/isolate/host-calls.ts
993
1230
  function createHostCalls(opts) {
994
1231
  const timeoutMs = opts.timeoutMs ?? 5e3;
995
1232
  const pending = /* @__PURE__ */ new Map();
@@ -1063,7 +1300,12 @@ function createHostCalls(opts) {
1063
1300
  var HostCallError, isRect;
1064
1301
  var init_host_calls = __esmMin((() => {
1065
1302
  HostCallError = class extends Error {
1303
+ /** What went wrong: `not_found`, `no_surface`, `forbidden`, `invalid`, `timeout`, … */
1066
1304
  code;
1305
+ /**
1306
+ * @param code What went wrong.
1307
+ * @param message A sentence for people.
1308
+ */
1067
1309
  constructor(code, message) {
1068
1310
  super(message);
1069
1311
  this.name = "HostCallError";
@@ -1077,7 +1319,7 @@ var init_host_calls = __esmMin((() => {
1077
1319
  "height"
1078
1320
  ].every((k) => typeof Reflect.get(x, k) === "number");
1079
1321
  }));
1080
- // src/keep-awake.ts
1322
+ // src/isolate/keep-awake.ts
1081
1323
  function createKeepAwake(now = () => performance.now()) {
1082
1324
  const holds = /* @__PURE__ */ new Map();
1083
1325
  let next = 0;
@@ -1102,12 +1344,12 @@ function createKeepAwake(now = () => performance.now()) {
1102
1344
  };
1103
1345
  }
1104
1346
  var init_keep_awake = __esmMin((() => {}));
1105
- // ../dom/dist/records-wVZrPpqr.js
1347
+ // ../dom/dist/records-qo23ZEsQ.js
1106
1348
  var ISOLOOP_DOM_FMT;
1107
- var init_records_wVZrPpqr = __esmMin((() => {
1349
+ var init_records_qo23ZEsQ = __esmMin((() => {
1108
1350
  ISOLOOP_DOM_FMT = "isoloop-dom@1";
1109
1351
  }));
1110
- // ../dom/dist/dom-yLsf0Z4e.js
1352
+ // ../dom/dist/dom-Bd22osRG.js
1111
1353
  function createStyle(el) {
1112
1354
  const decls = /* @__PURE__ */ new Map();
1113
1355
  const write = () => {
@@ -1159,7 +1401,7 @@ function createStyle(el) {
1159
1401
  });
1160
1402
  }
1161
1403
  /**
1162
- * `element.dataset` (DOM group 1, ADR 0010): camelCase keys over the
1404
+ * `element.dataset`: camelCase keys over the
1163
1405
  * `data-*` attributes, so every write travels as an `attr` record.
1164
1406
  */
1165
1407
  function createDataset(el) {
@@ -1210,6 +1452,21 @@ function defineHandlers(proto) {
1210
1452
  }
1211
1453
  });
1212
1454
  }
1455
+ function defineLayoutStubs(proto) {
1456
+ for (const [name, instead] of Object.entries(LAYOUT_METHODS)) Object.defineProperty(proto, name, {
1457
+ configurable: true,
1458
+ writable: true,
1459
+ value() {
1460
+ throw layoutError(`${name}()`, instead);
1461
+ }
1462
+ });
1463
+ for (const [name, instead] of Object.entries(LAYOUT_PROPERTIES)) Object.defineProperty(proto, name, {
1464
+ configurable: true,
1465
+ get() {
1466
+ throw layoutError(name, instead);
1467
+ }
1468
+ });
1469
+ }
1213
1470
  /** The subtree as `insert` sends it. */
1214
1471
  function serialize(n) {
1215
1472
  if (n instanceof WText) return {
@@ -1306,6 +1563,7 @@ function recorder(root, onBatch, schedule) {
1306
1563
  }
1307
1564
  };
1308
1565
  }
1566
+ /** @internal */
1309
1567
  function createDom(opts) {
1310
1568
  const schedule = opts.schedule ?? ((fn) => queueMicrotask(fn));
1311
1569
  const core = {
@@ -1383,8 +1641,8 @@ function toEvent(e) {
1383
1641
  });
1384
1642
  return ev;
1385
1643
  }
1386
- 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;
1387
- var init_dom_yLsf0Z4e = __esmMin((() => {
1644
+ var HTML_NS, SVG_NS, str, domError, emit, WEventTarget, WNode, WCharacterData, WText, WComment, kebab, WDOMTokenList, dataAttr, dataKey, WParentNode, WDocumentFragment, WElement, HANDLER_EVENTS, MEASURE, ANIMATE, LAYOUT_METHODS, LAYOUT_PROPERTIES, layoutError, WHTMLElement, WSVGElement, WHTMLIFrameElement, WHTMLInputElement, WHTMLTextAreaElement, WHTMLSelectElement, WHTMLOptionElement, HTML_CLASSES, WDocument, isControl;
1645
+ var init_dom_Bd22osRG = __esmMin((() => {
1388
1646
  HTML_NS = "http://www.w3.org/1999/xhtml";
1389
1647
  SVG_NS = "http://www.w3.org/2000/svg";
1390
1648
  str = (v) => typeof v === "string" ? v : typeof v === "number" || typeof v === "boolean" || typeof v === "bigint" ? String(v) : "";
@@ -1541,7 +1799,7 @@ var init_dom_yLsf0Z4e = __esmMin((() => {
1541
1799
  /**
1542
1800
  * @internal The root this node was rendered under, once it has been. Kept
1543
1801
  * after the node leaves the tree, so it can't move to another member's root
1544
- * in a pool (ADR 0015, decision 3).
1802
+ * in a pool.
1545
1803
  */
1546
1804
  isoOwner = null;
1547
1805
  constructor(doc, id) {
@@ -1832,7 +2090,7 @@ var init_dom_yLsf0Z4e = __esmMin((() => {
1832
2090
  /** @internal */ isoStyle = null;
1833
2091
  /** @internal */ isoClassList = null;
1834
2092
  /** @internal */ isoDataset = null;
1835
- /** @internal The offsets the last `scroll` event brought (design §4.6). */
2093
+ /** @internal The offsets the last `scroll` event brought. */
1836
2094
  isoScroll = {
1837
2095
  top: 0,
1838
2096
  left: 0
@@ -1991,6 +2249,29 @@ var init_dom_yLsf0Z4e = __esmMin((() => {
1991
2249
  "wheel"
1992
2250
  ];
1993
2251
  defineHandlers(WElement.prototype);
2252
+ MEASURE = "ask the host with `ctx.host.measure(node)` (`useHost().measure` in React and Preact)";
2253
+ ANIMATE = "animate with CSS transitions or animations, set through classes or `style`";
2254
+ LAYOUT_METHODS = {
2255
+ getBoundingClientRect: MEASURE,
2256
+ getClientRects: MEASURE,
2257
+ animate: ANIMATE,
2258
+ getAnimations: ANIMATE
2259
+ };
2260
+ LAYOUT_PROPERTIES = {
2261
+ offsetWidth: MEASURE,
2262
+ offsetHeight: MEASURE,
2263
+ offsetTop: MEASURE,
2264
+ offsetLeft: MEASURE,
2265
+ offsetParent: MEASURE,
2266
+ clientWidth: MEASURE,
2267
+ clientHeight: MEASURE,
2268
+ clientTop: MEASURE,
2269
+ clientLeft: MEASURE,
2270
+ scrollWidth: MEASURE,
2271
+ scrollHeight: MEASURE
2272
+ };
2273
+ layoutError = (name, instead) => domError("NotSupportedError", `${name} needs layout, which an isolate doesn't have; ${instead}`);
2274
+ defineLayoutStubs(WElement.prototype);
1994
2275
  WHTMLElement = class extends WElement {};
1995
2276
  WSVGElement = class extends WElement {};
1996
2277
  WHTMLIFrameElement = class extends WHTMLElement {};
@@ -2138,7 +2419,7 @@ var init_dom_yLsf0Z4e = __esmMin((() => {
2138
2419
  body;
2139
2420
  /**
2140
2421
  * A detached head: React 19 hoists `<title>`, `<meta>` and `<link>` into
2141
- * it. The bridge doesn't render it (M3a task 3).
2422
+ * it. The bridge doesn't render it.
2142
2423
  */
2143
2424
  head;
2144
2425
  constructor(core) {
@@ -2168,7 +2449,7 @@ var init_dom_yLsf0Z4e = __esmMin((() => {
2168
2449
  return new WDocumentFragment(this, -3);
2169
2450
  }
2170
2451
  /**
2171
- * The first element in tree order with this `id` (DOM group 1, ADR 0010):
2452
+ * The first element in tree order with this `id`:
2172
2453
  * under the render root, then the detached head. Nodes not yet inserted
2173
2454
  * aren't in the document, so they aren't found.
2174
2455
  */
@@ -2189,8 +2470,7 @@ var init_dom_yLsf0Z4e = __esmMin((() => {
2189
2470
  }
2190
2471
  /**
2191
2472
  * Type selectors only, alone or as a `head > title` child chain: what React
2192
- * 19 asks when it hoists a `<title>`. Queries in general are DOM group 2
2193
- * (ADR 0010), built when a library needs them; anything else throws.
2473
+ * 19 asks when it hoists a `<title>`. Anything else throws.
2194
2474
  */
2195
2475
  querySelector(selector) {
2196
2476
  const steps = selector.split(">").map((t) => t.trim().toLowerCase());
@@ -2222,11 +2502,13 @@ var init_dom_yLsf0Z4e = __esmMin((() => {
2222
2502
  defineHandlers(WDocument.prototype);
2223
2503
  isControl = (node) => node instanceof WHTMLInputElement || node instanceof WHTMLTextAreaElement || node instanceof WHTMLSelectElement;
2224
2504
  }));
2225
- // ../dom/dist/install-D7m7By8i.js
2505
+ // ../dom/dist/install-0dSawI50.js
2226
2506
  /**
2227
2507
  * Exposes `dom` as the worker's `document`, `window` and DOM classes, so
2228
2508
  * frameworks find them where they look. Only for isolates with a surface; a
2229
2509
  * headless isolate never calls this.
2510
+ *
2511
+ * @internal
2230
2512
  */
2231
2513
  function install(dom, scope) {
2232
2514
  const define = (name, value) => {
@@ -2239,11 +2521,14 @@ function install(dom, scope) {
2239
2521
  define("document", dom.document);
2240
2522
  if (!("window" in scope)) define("window", scope);
2241
2523
  for (const [name, value] of Object.entries(DOM_GLOBALS)) define(name, value);
2524
+ if (!("getComputedStyle" in scope)) define("getComputedStyle", () => {
2525
+ throw layoutError("getComputedStyle()", "read the styles the isolate set (`el.style`), or ask the host for sizes with `ctx.host.measure(node)`");
2526
+ });
2242
2527
  dom.document.defaultView = scope;
2243
2528
  }
2244
2529
  var DOM_GLOBALS;
2245
- var init_install_D7m7By8i = __esmMin((() => {
2246
- init_dom_yLsf0Z4e();
2530
+ var init_install_0dSawI50 = __esmMin((() => {
2531
+ init_dom_Bd22osRG();
2247
2532
  DOM_GLOBALS = {
2248
2533
  Node: WNode,
2249
2534
  Element: WElement,
@@ -2262,11 +2547,11 @@ var init_install_D7m7By8i = __esmMin((() => {
2262
2547
  }));
2263
2548
  // ../dom/dist/worker.js
2264
2549
  var init_worker = __esmMin((() => {
2265
- init_records_wVZrPpqr();
2266
- init_dom_yLsf0Z4e();
2267
- init_install_D7m7By8i();
2550
+ init_records_qo23ZEsQ();
2551
+ init_dom_Bd22osRG();
2552
+ init_install_0dSawI50();
2268
2553
  }));
2269
- // src/render/index.ts
2554
+ // src/render/render.ts
2270
2555
  function sharedDom(scope) {
2271
2556
  if (!shared) {
2272
2557
  shared = createDom({
@@ -2401,8 +2686,8 @@ var init_render = __esmMin((() => {
2401
2686
  headListeners = /* @__PURE__ */ new Set();
2402
2687
  }));
2403
2688
  // package.json
2404
- var version = "0.1.0-next.1";
2405
- // src/vanilla.ts
2689
+ var version = "0.1.0-next.11";
2690
+ // src/isolate/vanilla.ts
2406
2691
  var vanilla_exports = /* @__PURE__ */ __exportAll({
2407
2692
  REQUIRES: () => REQUIRES,
2408
2693
  createVanillaIsolate: () => createVanillaIsolate,
@@ -2410,7 +2695,23 @@ var vanilla_exports = /* @__PURE__ */ __exportAll({
2410
2695
  });
2411
2696
  /**
2412
2697
  * Types an isolate module's default export and stamps it with the version
2413
- * it was built against. `Root` defaults to the structural `IsolateRoot`.
2698
+ * it was built against.
2699
+ * @param def The isolate: its `start(ctx)`.
2700
+ * @returns The definition, with `requires` set to this build's `major.minor`.
2701
+ * @example
2702
+ * ```ts
2703
+ * import { defineIsolate } from '@isoloop/runtime';
2704
+ * import { count } from './topics';
2705
+ *
2706
+ * export default defineIsolate<HTMLElement>({
2707
+ * start(ctx) {
2708
+ * const button = document.createElement('button');
2709
+ * button.textContent = 'Add one';
2710
+ * button.addEventListener('click', () => void ctx.bus.publish(count, { value: 1 }));
2711
+ * ctx.root?.append(button);
2712
+ * },
2713
+ * });
2714
+ * ```
2414
2715
  */
2415
2716
  function defineIsolate(def) {
2416
2717
  return {
@@ -2449,6 +2750,7 @@ function createVanillaIsolate(init, post, scope, pooled = false, member = null)
2449
2750
  });
2450
2751
  const onShutdown = [];
2451
2752
  let portal;
2753
+ const inspect = init.grants.inspect === true ? createInspectorClient() : void 0;
2452
2754
  const ctx = {
2453
2755
  id: init.isolateId,
2454
2756
  config: init.config,
@@ -2471,6 +2773,7 @@ function createVanillaIsolate(init, post, scope, pooled = false, member = null)
2471
2773
  },
2472
2774
  host: calls.api,
2473
2775
  bus: bus.client,
2776
+ inspector: inspect?.inspector,
2474
2777
  styles: (css) => render?.styles(css),
2475
2778
  setValue(node, value, o) {
2476
2779
  if (!render) return;
@@ -2510,6 +2813,10 @@ function createVanillaIsolate(init, post, scope, pooled = false, member = null)
2510
2813
  return {
2511
2814
  ctx,
2512
2815
  renderFmt: render ? render.fmt : "none",
2816
+ attachInspect(port) {
2817
+ if (inspect) inspect.attach(port);
2818
+ else port.close();
2819
+ },
2513
2820
  receive(msg) {
2514
2821
  if (isHostToIsolate(msg)) {
2515
2822
  if (msg.t === "event") render?.receive(msg.p);
@@ -2527,6 +2834,7 @@ function createVanillaIsolate(init, post, scope, pooled = false, member = null)
2527
2834
  },
2528
2835
  async shutdown(reason) {
2529
2836
  await Promise.allSettled(onShutdown.map(async (fn) => fn(reason)));
2837
+ inspect?.end();
2530
2838
  await bus.close();
2531
2839
  render?.flush();
2532
2840
  render?.dispose();
@@ -2535,6 +2843,7 @@ function createVanillaIsolate(init, post, scope, pooled = false, member = null)
2535
2843
  }
2536
2844
  var REQUIRES;
2537
2845
  var init_vanilla = __esmMin((() => {
2846
+ init_inspector();
2538
2847
  init_dist();
2539
2848
  init_bus_client();
2540
2849
  init_busy();
@@ -2545,7 +2854,15 @@ var init_vanilla = __esmMin((() => {
2545
2854
  REQUIRES = majorMinor(version) ?? "0.0";
2546
2855
  }));
2547
2856
  // src/bootstrap.ts
2548
- var bootstrap_exports = /* @__PURE__ */ __exportAll({});
2857
+ var bootstrap_exports = /* @__PURE__ */ __exportAll({ blockFor: () => blockFor });
2858
+ /**
2859
+ * `block { ms }` (ADR 0020, decision 4): a real busy loop, so the beat goes
2860
+ * late and the supervisor acts as it would for a stuck isolate.
2861
+ */
2862
+ function blockFor(ms) {
2863
+ const until = performance.now() + Math.min(Math.max(0, ms), MAX_BLOCK_MS);
2864
+ while (performance.now() < until);
2865
+ }
2549
2866
  /** Once per worker, after the first isolate's protocol check. */
2550
2867
  function startHeartbeat(everyMs) {
2551
2868
  if (beating) return;
@@ -2593,7 +2910,7 @@ function shutdownMember(m, graceMs, reason) {
2593
2910
  t: "bye",
2594
2911
  p: {}
2595
2912
  });
2596
- if (members.size === 0) self.close();
2913
+ if (mode !== "pool" && members.size === 0) self.close();
2597
2914
  });
2598
2915
  }
2599
2916
  /** Routes one message from the host to the member it is for. */
@@ -2601,7 +2918,15 @@ function route(msg) {
2601
2918
  const m = members.get(mode === "pool" ? msg.isolate : void 0);
2602
2919
  if (!m) return;
2603
2920
  if (msg.t === "shutdown") shutdownMember(m, msg.p.graceMs, msg.p.reason);
2604
- else if (m.receive) busy.run(busy.of(m.name, m.life), m.receive, void 0, [msg]);
2921
+ else if (msg.t === "inspect") {
2922
+ const port = msg.p.port;
2923
+ if (!(port instanceof MessagePort)) return;
2924
+ if (m.onInspect) m.onInspect(port);
2925
+ else m.inspectPort = port;
2926
+ } else if (msg.t === "block") {
2927
+ const ms = msg.p.ms;
2928
+ if (typeof ms === "number") busy.run(busy.of(m.name, m.life), blockFor, void 0, [ms]);
2929
+ } else if (m.receive) busy.run(busy.of(m.name, m.life), m.receive, void 0, [msg]);
2605
2930
  }
2606
2931
  async function boot(m, init) {
2607
2932
  if (init.protocol.min > PROTOCOL.v || init.protocol.max < PROTOCOL.min) {
@@ -2617,6 +2942,13 @@ async function boot(m, init) {
2617
2942
  mode === "pool",
2618
2943
  m.name
2619
2944
  ]);
2945
+ m.onInspect = (port) => {
2946
+ runtime.attachInspect(port);
2947
+ };
2948
+ if (m.inspectPort) {
2949
+ m.onInspect(m.inspectPort);
2950
+ m.inspectPort = null;
2951
+ }
2620
2952
  let mod;
2621
2953
  try {
2622
2954
  mod = await import(
@@ -2656,7 +2988,8 @@ async function startIsolate(m, runtime, start, requires) {
2656
2988
  runtime: "@isoloop/runtime",
2657
2989
  adapter: "vanilla",
2658
2990
  renderFmt: runtime.renderFmt,
2659
- ...requires === void 0 ? {} : { requires }
2991
+ ...requires === void 0 ? {} : { requires },
2992
+ ...Reflect.get(self, Symbol.for("isoloop.worker-entry")) === true ? { entry: true } : {}
2660
2993
  }
2661
2994
  });
2662
2995
  try {
@@ -2687,7 +3020,9 @@ function onMessage(e) {
2687
3020
  post: memberPost(name),
2688
3021
  shutdownHook: null,
2689
3022
  idleReport: null,
2690
- receive: null
3023
+ receive: null,
3024
+ inspectPort: null,
3025
+ onInspect: null
2691
3026
  };
2692
3027
  members.set(name, m);
2693
3028
  boot(m, msg.p).catch((err) => {
@@ -2738,6 +3073,7 @@ var init_bootstrap = __esmMin((() => {
2738
3073
  }
2739
3074
  }));
2740
3075
  // src/worker.ts
3076
+ Reflect.set(self, Symbol.for("isoloop.worker-entry"), true);
2741
3077
  const held = [];
2742
3078
  const hold = (e) => {
2743
3079
  held.push(e);