@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/bootstrap.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
  init_dist();
559
614
  init_busy();
560
615
  /** Constructors whose `prototype` and statics are frozen, if this engine has them. */
@@ -717,7 +772,188 @@ function freezeBuiltins() {
717
772
  Object.freeze(JSON);
718
773
  Object.freeze(Reflect);
719
774
  }
720
- // src/bus-client.ts
775
+ // src/isolate/inspector.ts
776
+ function createInspectorClient() {
777
+ let port = null;
778
+ let ended = false;
779
+ let lastSnapshot;
780
+ /** What was asked before the port arrived. */
781
+ const queue = [];
782
+ const pending = /* @__PURE__ */ new Map();
783
+ const taps = /* @__PURE__ */ new Map();
784
+ const listeners = /* @__PURE__ */ new Set();
785
+ let next = 0;
786
+ const send = (m) => {
787
+ if (port) port.postMessage(m);
788
+ else queue.push(m);
789
+ };
790
+ const ask = (m) => {
791
+ const id = `i${++next}`;
792
+ const done = new Promise((resolve, reject) => {
793
+ pending.set(id, {
794
+ resolve,
795
+ reject
796
+ });
797
+ });
798
+ send({
799
+ v: 1,
800
+ id,
801
+ ...m
802
+ });
803
+ return {
804
+ id,
805
+ done
806
+ };
807
+ };
808
+ const onMessage = (e) => {
809
+ const msg = e.data;
810
+ if (!isInspectToIsolate(msg)) return;
811
+ if (msg.t === "record") {
812
+ if (msg.re !== void 0) taps.get(msg.re)?.fn(msg.p);
813
+ return;
814
+ }
815
+ if (msg.t === "skipped") {
816
+ if (msg.re !== void 0) taps.get(msg.re)?.onSkipped?.(msg.p.count);
817
+ return;
818
+ }
819
+ if (msg.re !== void 0) {
820
+ const p = pending.get(msg.re);
821
+ if (!p) return;
822
+ pending.delete(msg.re);
823
+ if (msg.t === "snapshot") {
824
+ lastSnapshot = msg.p;
825
+ p.resolve(msg.p);
826
+ } else if (msg.t === "result") {
827
+ const err = failure(msg.p);
828
+ if (err) p.reject(err);
829
+ else p.resolve(msg.p.ok ? msg.p.value : void 0);
830
+ }
831
+ return;
832
+ }
833
+ if (msg.t === "result") return;
834
+ for (const fn of listeners) try {
835
+ fn(msg);
836
+ } catch (err) {
837
+ setTimeout(() => {
838
+ throw err;
839
+ });
840
+ }
841
+ };
842
+ const control = async (action, id, ms) => {
843
+ if (ended) throw endedError();
844
+ await ask({
845
+ t: "control",
846
+ p: ms === void 0 ? {
847
+ action,
848
+ id
849
+ } : {
850
+ action,
851
+ id,
852
+ ms
853
+ }
854
+ }).done;
855
+ };
856
+ const client = {
857
+ inspector: {
858
+ async snapshot() {
859
+ if (ended) {
860
+ if (lastSnapshot) return lastSnapshot;
861
+ throw endedError();
862
+ }
863
+ return await ask({
864
+ t: "snapshot",
865
+ p: {}
866
+ }).done;
867
+ },
868
+ on(fn) {
869
+ const entry = (m) => fn(m);
870
+ listeners.add(entry);
871
+ if (listeners.size === 1) send({
872
+ v: 1,
873
+ t: "listen",
874
+ p: {}
875
+ });
876
+ return () => {
877
+ if (!listeners.delete(entry)) return;
878
+ if (listeners.size === 0) send({
879
+ v: 1,
880
+ t: "unlisten",
881
+ p: {}
882
+ });
883
+ };
884
+ },
885
+ async records(topic, o) {
886
+ return await ask({
887
+ t: "records",
888
+ p: {
889
+ topic,
890
+ last: o.last
891
+ }
892
+ }).done;
893
+ },
894
+ tap(o, fn) {
895
+ const p = o.maxPerSec === void 0 ? { topics: [...o.topics] } : {
896
+ topics: [...o.topics],
897
+ maxPerSec: o.maxPerSec
898
+ };
899
+ const { id, done } = ask({
900
+ t: "tap",
901
+ p
902
+ });
903
+ taps.set(id, {
904
+ fn,
905
+ onSkipped: o.onSkipped
906
+ });
907
+ let open = true;
908
+ done.catch(() => {
909
+ taps.delete(id);
910
+ });
911
+ return () => {
912
+ if (!open) return;
913
+ open = false;
914
+ taps.delete(id);
915
+ send({
916
+ v: 1,
917
+ t: "untap",
918
+ re: id,
919
+ p: {}
920
+ });
921
+ };
922
+ },
923
+ restart: (id) => control("restart", id),
924
+ kill: (id) => control("kill", id),
925
+ block: (id, ms) => control("block", id, ms)
926
+ },
927
+ attach(p) {
928
+ if (port) return;
929
+ port = p;
930
+ p.addEventListener("message", onMessage);
931
+ p.addEventListener("close", () => {
932
+ client.end();
933
+ });
934
+ p.start();
935
+ for (const m of queue.splice(0)) p.postMessage(m);
936
+ },
937
+ end() {
938
+ if (ended) return;
939
+ ended = true;
940
+ queue.length = 0;
941
+ for (const p of pending.values()) p.reject(endedError());
942
+ pending.clear();
943
+ taps.clear();
944
+ listeners.clear();
945
+ port?.removeEventListener("message", onMessage);
946
+ port?.close();
947
+ }
948
+ };
949
+ return client;
950
+ }
951
+ var failure, endedError;
952
+ var init_inspector = __esmMin((() => {
953
+ failure = (r) => r.ok ? void 0 : new BusError(r.error);
954
+ endedError = () => /* @__PURE__ */ new Error("inspector: its port has ended; controls no longer act");
955
+ }));
956
+ // src/bus/bus-client.ts
721
957
  function createBusClient(first, o = {}) {
722
958
  const limit = o.inboxLimit ?? 1e3;
723
959
  const now = o.now ?? (() => performance.now());
@@ -1001,13 +1237,14 @@ function isThenable(x) {
1001
1237
  }
1002
1238
  var randomEpoch, check, REQUEST_TIMEOUT_MS;
1003
1239
  var init_bus_client = __esmMin((() => {
1240
+ init_dist();
1004
1241
  randomEpoch = () => crypto.getRandomValues(/* @__PURE__ */ new Uint32Array(1))[0] ?? 0;
1005
1242
  check = (r) => {
1006
1243
  if (!r.ok) throw new BusError(r.error);
1007
1244
  };
1008
1245
  REQUEST_TIMEOUT_MS = 3e4;
1009
1246
  }));
1010
- // src/host-calls.ts
1247
+ // src/isolate/host-calls.ts
1011
1248
  function createHostCalls(opts) {
1012
1249
  const timeoutMs = opts.timeoutMs ?? 5e3;
1013
1250
  const pending = /* @__PURE__ */ new Map();
@@ -1081,7 +1318,12 @@ function createHostCalls(opts) {
1081
1318
  var HostCallError, isRect;
1082
1319
  var init_host_calls = __esmMin((() => {
1083
1320
  HostCallError = class extends Error {
1321
+ /** What went wrong: `not_found`, `no_surface`, `forbidden`, `invalid`, `timeout`, … */
1084
1322
  code;
1323
+ /**
1324
+ * @param code What went wrong.
1325
+ * @param message A sentence for people.
1326
+ */
1085
1327
  constructor(code, message) {
1086
1328
  super(message);
1087
1329
  this.name = "HostCallError";
@@ -1095,7 +1337,7 @@ var init_host_calls = __esmMin((() => {
1095
1337
  "height"
1096
1338
  ].every((k) => typeof Reflect.get(x, k) === "number");
1097
1339
  }));
1098
- // src/keep-awake.ts
1340
+ // src/isolate/keep-awake.ts
1099
1341
  function createKeepAwake(now = () => performance.now()) {
1100
1342
  const holds = /* @__PURE__ */ new Map();
1101
1343
  let next = 0;
@@ -1120,12 +1362,12 @@ function createKeepAwake(now = () => performance.now()) {
1120
1362
  };
1121
1363
  }
1122
1364
  var init_keep_awake = __esmMin((() => {}));
1123
- // ../dom/dist/records-wVZrPpqr.js
1365
+ // ../dom/dist/records-qo23ZEsQ.js
1124
1366
  var ISOLOOP_DOM_FMT;
1125
- var init_records_wVZrPpqr = __esmMin((() => {
1367
+ var init_records_qo23ZEsQ = __esmMin((() => {
1126
1368
  ISOLOOP_DOM_FMT = "isoloop-dom@1";
1127
1369
  }));
1128
- // ../dom/dist/dom-yLsf0Z4e.js
1370
+ // ../dom/dist/dom-Bd22osRG.js
1129
1371
  function createStyle(el) {
1130
1372
  const decls = /* @__PURE__ */ new Map();
1131
1373
  const write = () => {
@@ -1177,7 +1419,7 @@ function createStyle(el) {
1177
1419
  });
1178
1420
  }
1179
1421
  /**
1180
- * `element.dataset` (DOM group 1, ADR 0010): camelCase keys over the
1422
+ * `element.dataset`: camelCase keys over the
1181
1423
  * `data-*` attributes, so every write travels as an `attr` record.
1182
1424
  */
1183
1425
  function createDataset(el) {
@@ -1228,6 +1470,21 @@ function defineHandlers(proto) {
1228
1470
  }
1229
1471
  });
1230
1472
  }
1473
+ function defineLayoutStubs(proto) {
1474
+ for (const [name, instead] of Object.entries(LAYOUT_METHODS)) Object.defineProperty(proto, name, {
1475
+ configurable: true,
1476
+ writable: true,
1477
+ value() {
1478
+ throw layoutError(`${name}()`, instead);
1479
+ }
1480
+ });
1481
+ for (const [name, instead] of Object.entries(LAYOUT_PROPERTIES)) Object.defineProperty(proto, name, {
1482
+ configurable: true,
1483
+ get() {
1484
+ throw layoutError(name, instead);
1485
+ }
1486
+ });
1487
+ }
1231
1488
  /** The subtree as `insert` sends it. */
1232
1489
  function serialize(n) {
1233
1490
  if (n instanceof WText) return {
@@ -1324,6 +1581,7 @@ function recorder(root, onBatch, schedule) {
1324
1581
  }
1325
1582
  };
1326
1583
  }
1584
+ /** @internal */
1327
1585
  function createDom(opts) {
1328
1586
  const schedule = opts.schedule ?? ((fn) => queueMicrotask(fn));
1329
1587
  const core = {
@@ -1401,8 +1659,8 @@ function toEvent(e) {
1401
1659
  });
1402
1660
  return ev;
1403
1661
  }
1404
- 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;
1405
- var init_dom_yLsf0Z4e = __esmMin((() => {
1662
+ 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;
1663
+ var init_dom_Bd22osRG = __esmMin((() => {
1406
1664
  HTML_NS = "http://www.w3.org/1999/xhtml";
1407
1665
  SVG_NS = "http://www.w3.org/2000/svg";
1408
1666
  str = (v) => typeof v === "string" ? v : typeof v === "number" || typeof v === "boolean" || typeof v === "bigint" ? String(v) : "";
@@ -1559,7 +1817,7 @@ var init_dom_yLsf0Z4e = __esmMin((() => {
1559
1817
  /**
1560
1818
  * @internal The root this node was rendered under, once it has been. Kept
1561
1819
  * after the node leaves the tree, so it can't move to another member's root
1562
- * in a pool (ADR 0015, decision 3).
1820
+ * in a pool.
1563
1821
  */
1564
1822
  isoOwner = null;
1565
1823
  constructor(doc, id) {
@@ -1850,7 +2108,7 @@ var init_dom_yLsf0Z4e = __esmMin((() => {
1850
2108
  /** @internal */ isoStyle = null;
1851
2109
  /** @internal */ isoClassList = null;
1852
2110
  /** @internal */ isoDataset = null;
1853
- /** @internal The offsets the last `scroll` event brought (design §4.6). */
2111
+ /** @internal The offsets the last `scroll` event brought. */
1854
2112
  isoScroll = {
1855
2113
  top: 0,
1856
2114
  left: 0
@@ -2009,6 +2267,29 @@ var init_dom_yLsf0Z4e = __esmMin((() => {
2009
2267
  "wheel"
2010
2268
  ];
2011
2269
  defineHandlers(WElement.prototype);
2270
+ MEASURE = "ask the host with `ctx.host.measure(node)` (`useHost().measure` in React and Preact)";
2271
+ ANIMATE = "animate with CSS transitions or animations, set through classes or `style`";
2272
+ LAYOUT_METHODS = {
2273
+ getBoundingClientRect: MEASURE,
2274
+ getClientRects: MEASURE,
2275
+ animate: ANIMATE,
2276
+ getAnimations: ANIMATE
2277
+ };
2278
+ LAYOUT_PROPERTIES = {
2279
+ offsetWidth: MEASURE,
2280
+ offsetHeight: MEASURE,
2281
+ offsetTop: MEASURE,
2282
+ offsetLeft: MEASURE,
2283
+ offsetParent: MEASURE,
2284
+ clientWidth: MEASURE,
2285
+ clientHeight: MEASURE,
2286
+ clientTop: MEASURE,
2287
+ clientLeft: MEASURE,
2288
+ scrollWidth: MEASURE,
2289
+ scrollHeight: MEASURE
2290
+ };
2291
+ layoutError = (name, instead) => domError("NotSupportedError", `${name} needs layout, which an isolate doesn't have; ${instead}`);
2292
+ defineLayoutStubs(WElement.prototype);
2012
2293
  WHTMLElement = class extends WElement {};
2013
2294
  WSVGElement = class extends WElement {};
2014
2295
  WHTMLIFrameElement = class extends WHTMLElement {};
@@ -2156,7 +2437,7 @@ var init_dom_yLsf0Z4e = __esmMin((() => {
2156
2437
  body;
2157
2438
  /**
2158
2439
  * A detached head: React 19 hoists `<title>`, `<meta>` and `<link>` into
2159
- * it. The bridge doesn't render it (M3a task 3).
2440
+ * it. The bridge doesn't render it.
2160
2441
  */
2161
2442
  head;
2162
2443
  constructor(core) {
@@ -2186,7 +2467,7 @@ var init_dom_yLsf0Z4e = __esmMin((() => {
2186
2467
  return new WDocumentFragment(this, -3);
2187
2468
  }
2188
2469
  /**
2189
- * The first element in tree order with this `id` (DOM group 1, ADR 0010):
2470
+ * The first element in tree order with this `id`:
2190
2471
  * under the render root, then the detached head. Nodes not yet inserted
2191
2472
  * aren't in the document, so they aren't found.
2192
2473
  */
@@ -2207,8 +2488,7 @@ var init_dom_yLsf0Z4e = __esmMin((() => {
2207
2488
  }
2208
2489
  /**
2209
2490
  * Type selectors only, alone or as a `head > title` child chain: what React
2210
- * 19 asks when it hoists a `<title>`. Queries in general are DOM group 2
2211
- * (ADR 0010), built when a library needs them; anything else throws.
2491
+ * 19 asks when it hoists a `<title>`. Anything else throws.
2212
2492
  */
2213
2493
  querySelector(selector) {
2214
2494
  const steps = selector.split(">").map((t) => t.trim().toLowerCase());
@@ -2240,11 +2520,13 @@ var init_dom_yLsf0Z4e = __esmMin((() => {
2240
2520
  defineHandlers(WDocument.prototype);
2241
2521
  isControl = (node) => node instanceof WHTMLInputElement || node instanceof WHTMLTextAreaElement || node instanceof WHTMLSelectElement;
2242
2522
  }));
2243
- // ../dom/dist/install-D7m7By8i.js
2523
+ // ../dom/dist/install-0dSawI50.js
2244
2524
  /**
2245
2525
  * Exposes `dom` as the worker's `document`, `window` and DOM classes, so
2246
2526
  * frameworks find them where they look. Only for isolates with a surface; a
2247
2527
  * headless isolate never calls this.
2528
+ *
2529
+ * @internal
2248
2530
  */
2249
2531
  function install(dom, scope) {
2250
2532
  const define = (name, value) => {
@@ -2257,11 +2539,14 @@ function install(dom, scope) {
2257
2539
  define("document", dom.document);
2258
2540
  if (!("window" in scope)) define("window", scope);
2259
2541
  for (const [name, value] of Object.entries(DOM_GLOBALS)) define(name, value);
2542
+ if (!("getComputedStyle" in scope)) define("getComputedStyle", () => {
2543
+ throw layoutError("getComputedStyle()", "read the styles the isolate set (`el.style`), or ask the host for sizes with `ctx.host.measure(node)`");
2544
+ });
2260
2545
  dom.document.defaultView = scope;
2261
2546
  }
2262
2547
  var DOM_GLOBALS;
2263
- var init_install_D7m7By8i = __esmMin((() => {
2264
- init_dom_yLsf0Z4e();
2548
+ var init_install_0dSawI50 = __esmMin((() => {
2549
+ init_dom_Bd22osRG();
2265
2550
  DOM_GLOBALS = {
2266
2551
  Node: WNode,
2267
2552
  Element: WElement,
@@ -2280,11 +2565,11 @@ var init_install_D7m7By8i = __esmMin((() => {
2280
2565
  }));
2281
2566
  // ../dom/dist/worker.js
2282
2567
  var init_worker = __esmMin((() => {
2283
- init_records_wVZrPpqr();
2284
- init_dom_yLsf0Z4e();
2285
- init_install_D7m7By8i();
2568
+ init_records_qo23ZEsQ();
2569
+ init_dom_Bd22osRG();
2570
+ init_install_0dSawI50();
2286
2571
  }));
2287
- // src/render/index.ts
2572
+ // src/render/render.ts
2288
2573
  function sharedDom(scope) {
2289
2574
  if (!shared) {
2290
2575
  shared = createDom({
@@ -2418,8 +2703,8 @@ var init_render = __esmMin((() => {
2418
2703
  headListeners = /* @__PURE__ */ new Set();
2419
2704
  }));
2420
2705
  // package.json
2421
- var version = "0.1.0-next.1";
2422
- // src/vanilla.ts
2706
+ var version = "0.1.0-next.11";
2707
+ // src/isolate/vanilla.ts
2423
2708
  var vanilla_exports = /* @__PURE__ */ __exportAll({
2424
2709
  REQUIRES: () => REQUIRES,
2425
2710
  createVanillaIsolate: () => createVanillaIsolate,
@@ -2427,7 +2712,23 @@ var vanilla_exports = /* @__PURE__ */ __exportAll({
2427
2712
  });
2428
2713
  /**
2429
2714
  * Types an isolate module's default export and stamps it with the version
2430
- * it was built against. `Root` defaults to the structural `IsolateRoot`.
2715
+ * it was built against.
2716
+ * @param def The isolate: its `start(ctx)`.
2717
+ * @returns The definition, with `requires` set to this build's `major.minor`.
2718
+ * @example
2719
+ * ```ts
2720
+ * import { defineIsolate } from '@isoloop/runtime';
2721
+ * import { count } from './topics';
2722
+ *
2723
+ * export default defineIsolate<HTMLElement>({
2724
+ * start(ctx) {
2725
+ * const button = document.createElement('button');
2726
+ * button.textContent = 'Add one';
2727
+ * button.addEventListener('click', () => void ctx.bus.publish(count, { value: 1 }));
2728
+ * ctx.root?.append(button);
2729
+ * },
2730
+ * });
2731
+ * ```
2431
2732
  */
2432
2733
  function defineIsolate(def) {
2433
2734
  return {
@@ -2466,6 +2767,7 @@ function createVanillaIsolate(init, post, scope, pooled = false, member = null)
2466
2767
  });
2467
2768
  const onShutdown = [];
2468
2769
  let portal;
2770
+ const inspect = init.grants.inspect === true ? createInspectorClient() : void 0;
2469
2771
  const ctx = {
2470
2772
  id: init.isolateId,
2471
2773
  config: init.config,
@@ -2488,6 +2790,7 @@ function createVanillaIsolate(init, post, scope, pooled = false, member = null)
2488
2790
  },
2489
2791
  host: calls.api,
2490
2792
  bus: bus.client,
2793
+ inspector: inspect?.inspector,
2491
2794
  styles: (css) => render?.styles(css),
2492
2795
  setValue(node, value, o) {
2493
2796
  if (!render) return;
@@ -2527,6 +2830,10 @@ function createVanillaIsolate(init, post, scope, pooled = false, member = null)
2527
2830
  return {
2528
2831
  ctx,
2529
2832
  renderFmt: render ? render.fmt : "none",
2833
+ attachInspect(port) {
2834
+ if (inspect) inspect.attach(port);
2835
+ else port.close();
2836
+ },
2530
2837
  receive(msg) {
2531
2838
  if (isHostToIsolate(msg)) {
2532
2839
  if (msg.t === "event") render?.receive(msg.p);
@@ -2544,6 +2851,7 @@ function createVanillaIsolate(init, post, scope, pooled = false, member = null)
2544
2851
  },
2545
2852
  async shutdown(reason) {
2546
2853
  await Promise.allSettled(onShutdown.map(async (fn) => fn(reason)));
2854
+ inspect?.end();
2547
2855
  await bus.close();
2548
2856
  render?.flush();
2549
2857
  render?.dispose();
@@ -2552,6 +2860,7 @@ function createVanillaIsolate(init, post, scope, pooled = false, member = null)
2552
2860
  }
2553
2861
  var REQUIRES;
2554
2862
  var init_vanilla = __esmMin((() => {
2863
+ init_inspector();
2555
2864
  init_dist();
2556
2865
  init_bus_client();
2557
2866
  init_busy();
@@ -2590,6 +2899,14 @@ const fatal = (m, message, code) => {
2590
2899
  });
2591
2900
  };
2592
2901
  let beating = false;
2902
+ /**
2903
+ * `block { ms }` (ADR 0020, decision 4): a real busy loop, so the beat goes
2904
+ * late and the supervisor acts as it would for a stuck isolate.
2905
+ */
2906
+ function blockFor(ms) {
2907
+ const until = performance.now() + Math.min(Math.max(0, ms), MAX_BLOCK_MS);
2908
+ while (performance.now() < until);
2909
+ }
2593
2910
  /** Once per worker, after the first isolate's protocol check. */
2594
2911
  function startHeartbeat(everyMs) {
2595
2912
  if (beating) return;
@@ -2637,7 +2954,7 @@ function shutdownMember(m, graceMs, reason) {
2637
2954
  t: "bye",
2638
2955
  p: {}
2639
2956
  });
2640
- if (members.size === 0) self.close();
2957
+ if (mode !== "pool" && members.size === 0) self.close();
2641
2958
  });
2642
2959
  }
2643
2960
  /** Routes one message from the host to the member it is for. */
@@ -2645,7 +2962,15 @@ function route(msg) {
2645
2962
  const m = members.get(mode === "pool" ? msg.isolate : void 0);
2646
2963
  if (!m) return;
2647
2964
  if (msg.t === "shutdown") shutdownMember(m, msg.p.graceMs, msg.p.reason);
2648
- else if (m.receive) busy.run(busy.of(m.name, m.life), m.receive, void 0, [msg]);
2965
+ else if (msg.t === "inspect") {
2966
+ const port = msg.p.port;
2967
+ if (!(port instanceof MessagePort)) return;
2968
+ if (m.onInspect) m.onInspect(port);
2969
+ else m.inspectPort = port;
2970
+ } else if (msg.t === "block") {
2971
+ const ms = msg.p.ms;
2972
+ if (typeof ms === "number") busy.run(busy.of(m.name, m.life), blockFor, void 0, [ms]);
2973
+ } else if (m.receive) busy.run(busy.of(m.name, m.life), m.receive, void 0, [msg]);
2649
2974
  }
2650
2975
  async function boot(m, init) {
2651
2976
  if (init.protocol.min > PROTOCOL.v || init.protocol.max < PROTOCOL.min) {
@@ -2661,6 +2986,13 @@ async function boot(m, init) {
2661
2986
  mode === "pool",
2662
2987
  m.name
2663
2988
  ]);
2989
+ m.onInspect = (port) => {
2990
+ runtime.attachInspect(port);
2991
+ };
2992
+ if (m.inspectPort) {
2993
+ m.onInspect(m.inspectPort);
2994
+ m.inspectPort = null;
2995
+ }
2664
2996
  let mod;
2665
2997
  try {
2666
2998
  mod = await import(
@@ -2700,7 +3032,8 @@ async function startIsolate(m, runtime, start, requires) {
2700
3032
  runtime: "@isoloop/runtime",
2701
3033
  adapter: "vanilla",
2702
3034
  renderFmt: runtime.renderFmt,
2703
- ...requires === void 0 ? {} : { requires }
3035
+ ...requires === void 0 ? {} : { requires },
3036
+ ...Reflect.get(self, Symbol.for("isoloop.worker-entry")) === true ? { entry: true } : {}
2704
3037
  }
2705
3038
  });
2706
3039
  try {
@@ -2731,7 +3064,9 @@ function onMessage(e) {
2731
3064
  post: memberPost(name),
2732
3065
  shutdownHook: null,
2733
3066
  idleReport: null,
2734
- receive: null
3067
+ receive: null,
3068
+ inspectPort: null,
3069
+ onInspect: null
2735
3070
  };
2736
3071
  members.set(name, m);
2737
3072
  boot(m, msg.p).catch((err) => {
@@ -2749,3 +3084,4 @@ if (Reflect.get(self, STARTED) === true) {
2749
3084
  Reflect.set(self, STARTED, true);
2750
3085
  startOnce();
2751
3086
  }
3087
+ export { blockFor };