brumate 0.3.0 → 0.4.1

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.
Files changed (122) hide show
  1. package/README.md +2 -2
  2. package/check.d.ts +49 -0
  3. package/dist/{boot-C25Sa6vq.d.ts → boot-SCWYwuUd.d.ts} +8 -10
  4. package/dist/cli.js +275 -15
  5. package/dist/cli.js.map +1 -1
  6. package/dist/client-BBtVTOIt.js +3506 -0
  7. package/dist/client-BBtVTOIt.js.map +1 -0
  8. package/dist/{client-D0CqSxoO.d.ts → client-Cs3o4key.d.ts} +390 -181
  9. package/dist/{client-routes-JTbGtukf.js → client-routes-BtGpYCef.js} +60 -30
  10. package/dist/client-routes-BtGpYCef.js.map +1 -0
  11. package/dist/{cookies-BzllthiF.js → cookies-Cnbf4w-S.js} +14 -7
  12. package/dist/cookies-Cnbf4w-S.js.map +1 -0
  13. package/dist/{defer-BbD7JQhj.js → defer-BLJjxqVc.js} +4 -4
  14. package/dist/defer-BLJjxqVc.js.map +1 -0
  15. package/dist/{devtools-CQgD7NPB.js → devtools-DTpsVFbn.js} +56 -82
  16. package/dist/devtools-DTpsVFbn.js.map +1 -0
  17. package/dist/{devtools-panel-BVB-W5q4.js → devtools-panel-C1Dfv6nq.js} +397 -333
  18. package/dist/devtools-panel-C1Dfv6nq.js.map +1 -0
  19. package/dist/{events-CSs7OwIC.js → events-LgLdp1R7.js} +34 -5
  20. package/dist/events-LgLdp1R7.js.map +1 -0
  21. package/dist/features-CHY5Ekku.js +30 -0
  22. package/dist/features-CHY5Ekku.js.map +1 -0
  23. package/dist/files-DZIiMDnS.js +506 -0
  24. package/dist/files-DZIiMDnS.js.map +1 -0
  25. package/dist/{forms-Cl21hkHt.d.ts → forms-j1xPAR14.d.ts} +3 -3
  26. package/dist/{forms-Bg-CwGqX.js → forms-nXK7-Lv_.js} +78 -44
  27. package/dist/forms-nXK7-Lv_.js.map +1 -0
  28. package/dist/highlight.js +31 -22
  29. package/dist/highlight.js.map +1 -1
  30. package/dist/{html-mNTKzaDD.js → html-DS9B1H-M.js} +92 -22
  31. package/dist/html-DS9B1H-M.js.map +1 -0
  32. package/dist/{html-Bq1rFxX_.d.ts → html-Gggepsf-.d.ts} +22 -5
  33. package/dist/index.d.ts +98 -10
  34. package/dist/index.js +639 -104
  35. package/dist/index.js.map +1 -1
  36. package/dist/{inspect-BHpOw1LF.js → inspect-DomFHy5O.js} +3832 -695
  37. package/dist/inspect-DomFHy5O.js.map +1 -0
  38. package/dist/{loader-Dos_3NP0.js → loader-D62komKu.js} +20 -14
  39. package/dist/loader-D62komKu.js.map +1 -0
  40. package/dist/logo-DQ_OYhBi.js +10 -0
  41. package/dist/logo-DQ_OYhBi.js.map +1 -0
  42. package/dist/{navigate-O78d_zGN.js → navigate-CfOr-TRF.js} +94 -31
  43. package/dist/navigate-CfOr-TRF.js.map +1 -0
  44. package/dist/nesting-DA5vJw9X.js +265 -0
  45. package/dist/nesting-DA5vJw9X.js.map +1 -0
  46. package/dist/{produce-Doc91GkX.js → produce-BNIpmZq2.js} +138 -9
  47. package/dist/produce-BNIpmZq2.js.map +1 -0
  48. package/dist/{produce-D0V0ICkz.d.ts → produce-CRfouraC.d.ts} +44 -5
  49. package/dist/{rpc-ygMRPmN4.js → rpc-BTMb8jap.js} +11 -6
  50. package/dist/rpc-BTMb8jap.js.map +1 -0
  51. package/dist/runtime/batch.js +9 -7
  52. package/dist/runtime/batch.js.map +1 -1
  53. package/dist/runtime/client.d.ts +4 -4
  54. package/dist/runtime/client.js +4 -4
  55. package/dist/runtime/devtools.d.ts +11 -29
  56. package/dist/runtime/devtools.js +3 -1
  57. package/dist/runtime/env.js +14 -2
  58. package/dist/runtime/env.js.map +1 -1
  59. package/dist/runtime/events.d.ts +23 -1
  60. package/dist/runtime/events.js +1 -1
  61. package/dist/runtime/forms.d.ts +2 -2
  62. package/dist/runtime/forms.js +1 -1
  63. package/dist/runtime/hot.d.ts +1 -1
  64. package/dist/runtime/hot.js +5 -2
  65. package/dist/runtime/hot.js.map +1 -1
  66. package/dist/runtime/html.d.ts +2 -2
  67. package/dist/runtime/html.js +1 -1
  68. package/dist/runtime/loader.d.ts +2 -2
  69. package/dist/runtime/loader.js +2 -2
  70. package/dist/runtime/routes.js +4 -1
  71. package/dist/runtime/routes.js.map +1 -1
  72. package/dist/runtime/server.d.ts +5 -5
  73. package/dist/runtime/server.js +5 -5
  74. package/dist/runtime/signals.d.ts +38 -1
  75. package/dist/runtime/signals.js +33 -1
  76. package/dist/runtime/signals.js.map +1 -1
  77. package/dist/runtime/static-loader.d.ts +2 -2
  78. package/dist/runtime/static-loader.js +1 -1
  79. package/dist/runtime/testing.d.ts +18 -3
  80. package/dist/runtime/testing.js +150 -33
  81. package/dist/runtime/testing.js.map +1 -1
  82. package/dist/{server-CxVDYE_V.js → server-BTtsQFFw.js} +633 -163
  83. package/dist/server-BTtsQFFw.js.map +1 -0
  84. package/dist/{server-DuFYRXrd.d.ts → server-CYw15Dsg.d.ts} +103 -22
  85. package/dist/{static-loader-nZssh66R.js → static-loader-C_GYIFtt.js} +79 -99
  86. package/dist/static-loader-C_GYIFtt.js.map +1 -0
  87. package/dist/{static-loader-Drpr0AzI.d.ts → static-loader-DVuLmXeu.d.ts} +2 -2
  88. package/dist/{stream-DCYZO4IF.js → stream-r4V5zBKm.js} +102 -16
  89. package/dist/stream-r4V5zBKm.js.map +1 -0
  90. package/dist/vite.d.ts +13 -20
  91. package/dist/vite.js +1956 -554
  92. package/dist/vite.js.map +1 -1
  93. package/elements.d.ts +951 -0
  94. package/forms/forms.brm.ts +3 -3
  95. package/package.json +12 -3
  96. package/skills/brumate/SKILL.md +58 -0
  97. package/skills/brumate/references/errors.md +2078 -0
  98. package/skills/brumate/references/events.md +117 -0
  99. package/skills/brumate/references/signals.md +61 -0
  100. package/skills/brumate/references/state.md +235 -0
  101. package/skills/brumate/references/syntax.md +250 -0
  102. package/types.d.ts +4 -4
  103. package/dist/client-BD6XT-s5.js +0 -1968
  104. package/dist/client-BD6XT-s5.js.map +0 -1
  105. package/dist/client-routes-JTbGtukf.js.map +0 -1
  106. package/dist/cookies-BzllthiF.js.map +0 -1
  107. package/dist/defer-BbD7JQhj.js.map +0 -1
  108. package/dist/devtools-CQgD7NPB.js.map +0 -1
  109. package/dist/devtools-panel-BVB-W5q4.js.map +0 -1
  110. package/dist/events-CSs7OwIC.js.map +0 -1
  111. package/dist/files-BXSSrQgc.js +0 -205
  112. package/dist/files-BXSSrQgc.js.map +0 -1
  113. package/dist/forms-Bg-CwGqX.js.map +0 -1
  114. package/dist/html-mNTKzaDD.js.map +0 -1
  115. package/dist/inspect-BHpOw1LF.js.map +0 -1
  116. package/dist/loader-Dos_3NP0.js.map +0 -1
  117. package/dist/navigate-O78d_zGN.js.map +0 -1
  118. package/dist/produce-Doc91GkX.js.map +0 -1
  119. package/dist/rpc-ygMRPmN4.js.map +0 -1
  120. package/dist/server-CxVDYE_V.js.map +0 -1
  121. package/dist/static-loader-nZssh66R.js.map +0 -1
  122. package/dist/stream-DCYZO4IF.js.map +0 -1
@@ -1,4 +1,5 @@
1
- import { i as preview, n as PRELOADS, o as rootOf, t as LOGO } from "./devtools-CQgD7NPB.js";
1
+ import { t as LOGO } from "./logo-DQ_OYhBi.js";
2
+ import { r as preview, t as findRootScope } from "./devtools-DTpsVFbn.js";
2
3
  //#region src/runtime/devtools-panel.ts
3
4
  const STYLE = `
4
5
  :host { all: initial; }
@@ -122,11 +123,8 @@ tr.large td, tr.busy td { color: var(--yellow); }
122
123
  tr.ended td { color: var(--faint); }
123
124
  .bar-track { position: relative; height: 12px; }
124
125
  .bar { position: absolute; top: 2px; height: 8px; min-width: 3px; border-radius: 3px; background: var(--blue); }
125
- .bar.preload { background: var(--purple); } .bar.other { background: var(--faint); }
126
- .bar.unused { background: repeating-linear-gradient(45deg, var(--purple) 0 3px, transparent 3px 6px); box-shadow: inset 0 0 0 1px var(--purple); }
127
126
  .bar.failed { background: var(--red); }
128
127
  .bar.render { background: var(--accent); } .bar.memo { background: var(--green); } .bar.body { background: var(--purple); } .bar.stream { background: var(--faint); }
129
- tr.unused td:not(.bar-cell) { color: var(--yellow); }
130
128
  tr.failed td:not(.bar-cell) { color: var(--red); }
131
129
  .interaction { margin-bottom: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
132
130
  .run-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
@@ -189,7 +187,6 @@ const TABS = [
189
187
  ["graph", "Graph"],
190
188
  ["log", "Log"],
191
189
  ["timeline", "Timeline"],
192
- ["loading", "Loading"],
193
190
  ["state", "Page state"],
194
191
  ["effects", "Effects"],
195
192
  ["navigation", "Navigation"],
@@ -199,7 +196,6 @@ const TABS = [
199
196
  ];
200
197
  const KINDS = [
201
198
  "handler",
202
- "part",
203
199
  "write",
204
200
  "call"
205
201
  ];
@@ -221,6 +217,24 @@ function componentInfo(state, id) {
221
217
  }
222
218
  return info;
223
219
  }
220
+ /** The IDs of the components that instances in a list belong to. */
221
+ function collectModules(instances) {
222
+ const ids = /* @__PURE__ */ new Set();
223
+ for (const scope of instances) ids.add(scope.m);
224
+ return ids;
225
+ }
226
+ /** How many blocks of the page are in a state. */
227
+ function countBlocks(blocks, blockState) {
228
+ let count = 0;
229
+ for (const block of blocks) if (block.state === blockState) count++;
230
+ return count;
231
+ }
232
+ /** The infos of many components, in the order of their IDs. */
233
+ function loadComponents(state, ids) {
234
+ const pending = [];
235
+ for (const id of ids) pending.push(componentInfo(state, id));
236
+ return Promise.all(pending);
237
+ }
224
238
  function element(tag, attributes = {}, ...children) {
225
239
  const node = document.createElement(tag);
226
240
  for (const [name, value] of Object.entries(attributes)) node.setAttribute(name, value);
@@ -316,7 +330,7 @@ function parseValue(text) {
316
330
  }
317
331
  }
318
332
  /** The type of a value, for the column next to it. */
319
- function typeOf(value) {
333
+ function readType(value) {
320
334
  if (value === null) return "null";
321
335
  if (Array.isArray(value)) return "array";
322
336
  if (value instanceof Element) return "element";
@@ -333,26 +347,17 @@ function describe(entry) {
333
347
  const name = info?.scopes[write.k]?.slots[write.slot];
334
348
  return name ? `${info.name} ${name} = ${entry.text.split(" = ").slice(1).join(" = ")}` : entry.text;
335
349
  }
336
- const ms = (time) => `${Math.round(time)} ms`;
337
- const seconds = (time) => `${(time / 1e3).toFixed(2)} s`;
338
- const kilobytes = (bytes) => `${(bytes / 1024).toFixed(1)} kB`;
339
- /** The bytes of the code of a part, as the dev server sent it, from the timing of its request. */
340
- function bytesOf(info, part) {
341
- if (!info?.url || typeof performance.getEntriesByType !== "function") return 0;
342
- const entry = performance.getEntriesByType("resource").find((item) => {
343
- const url = new URL(item.name, location.href);
344
- return url.pathname === info.url && url.searchParams.has("brumate-client") && (part === "entry" || part === "all" ? !url.searchParams.has("part") : url.searchParams.get("part") === part);
345
- });
346
- return entry ? entry.encodedBodySize || entry.transferSize : 0;
350
+ function ms(time) {
351
+ return `${Math.round(time)} ms`;
347
352
  }
348
- /** The bytes of the code that loaded. */
349
- function codeBytes(state) {
350
- let bytes = 0;
351
- for (const load of state.loads.values()) bytes += bytesOf(known.get(load.component), load.part);
352
- return bytes;
353
+ function seconds(time) {
354
+ return `${(time / 1e3).toFixed(2)} s`;
355
+ }
356
+ function kilobytes(bytes) {
357
+ return `${(bytes / 1024).toFixed(1)} kB`;
353
358
  }
354
359
  /** The keys and values of an object, a map or a set, or the items of an array, in a row. */
355
- function entriesOf(value) {
360
+ function listEntries(value) {
356
361
  if (value instanceof Map) return [...value].flat();
357
362
  if (value instanceof Set || Array.isArray(value)) return [...value];
358
363
  return Object.entries(value).flat();
@@ -361,7 +366,7 @@ function entriesOf(value) {
361
366
  * About how many bytes a value takes in the page state. The state is code
362
367
  * that seroval writes, which this follows closely enough to compare values.
363
368
  */
364
- function sizeOf(value, seen = /* @__PURE__ */ new Set()) {
369
+ function measureSize(value, seen = /* @__PURE__ */ new Set()) {
365
370
  if (value === null || value === void 0) return 6;
366
371
  switch (typeof value) {
367
372
  case "string": return value.length + 2;
@@ -373,9 +378,9 @@ function sizeOf(value, seen = /* @__PURE__ */ new Set()) {
373
378
  if (seen.has(value)) return 6;
374
379
  seen.add(value);
375
380
  if (value instanceof Date) return 30;
376
- const entries = entriesOf(value);
381
+ const entries = listEntries(value);
377
382
  let bytes = 2;
378
- for (const entry of entries) bytes += sizeOf(entry, seen) + 1;
383
+ for (const entry of entries) bytes += measureSize(entry, seen) + 1;
379
384
  return bytes;
380
385
  }
381
386
  default: return 8;
@@ -388,18 +393,13 @@ function stateBytes() {
388
393
  return bytes;
389
394
  }
390
395
  /** The value of a name that a scope or one of the scopes around it holds. */
391
- function valueOf(scope, name) {
396
+ function readValue(scope, name) {
392
397
  for (let current = scope; current; current = current.p) {
393
- const slot = (known.get(rootOf(current).m ?? "")?.scopes[current.k]?.slots)?.indexOf(name) ?? -1;
398
+ const slot = (known.get(findRootScope(current).m ?? "")?.scopes[current.k]?.slots)?.indexOf(name) ?? -1;
394
399
  if (slot !== -1) return preview(current.s[slot]);
395
400
  if (current.m !== void 0) break;
396
401
  }
397
402
  }
398
- /** The colour of the pill of a reason to load. */
399
- function reasonColor(reason) {
400
- if (PRELOADS.has(reason)) return "purple";
401
- return reason === "event" || reason === "block" ? "blue" : "";
402
- }
403
403
  const STATE_COLORS = {
404
404
  waiting: "",
405
405
  loading: "blue",
@@ -418,14 +418,26 @@ function speedColor(total) {
418
418
  if (total < 100) return "green";
419
419
  return total < 300 ? "yellow" : "red";
420
420
  }
421
- const blockLabel = (block) => block.kind === "$client" ? "$client" : `#${block.kind}`;
422
- const pill = (text, color = "") => element("span", { class: `pill ${color}` }, text);
421
+ function blockLabel(block) {
422
+ return block.kind === "$client" ? "$client" : `#${block.kind}`;
423
+ }
424
+ function pill(text, color = "") {
425
+ return element("span", { class: `pill ${color}` }, text);
426
+ }
423
427
  /** A row of cells, as a table row. */
424
- const row = (cells, tag = "td") => element("tr", {}, ...cells.map((cell) => element(tag, {}, cell)));
428
+ function row(cells, tag = "td") {
429
+ const items = [];
430
+ for (const cell of cells) items.push(element(tag, {}, cell));
431
+ return element("tr", {}, ...items);
432
+ }
425
433
  /** A card of a number, with a label above and a note below. */
426
- const card = (label, value, note) => element("div", { class: "card" }, element("div", { class: "label" }, label), element("div", { class: "value" }, value), element("div", { class: "note" }, note));
434
+ function card(label, value, note) {
435
+ return element("div", { class: "card" }, element("div", { class: "label" }, label), element("div", { class: "value" }, value), element("div", { class: "note" }, note));
436
+ }
427
437
  /** A square of colour and its meaning, for a legend. */
428
- const key = (color, text) => element("span", {}, element("i", { style: `background: ${color}` }), text);
438
+ function key(color, text) {
439
+ return element("span", {}, element("i", { style: `background: ${color}` }), text);
440
+ }
429
441
  /** A button that opens a place of a file in the editor, through the dev server. */
430
442
  function source(info, at = "1:1") {
431
443
  if (!info) return "";
@@ -446,8 +458,9 @@ function source(info, at = "1:1") {
446
458
  * by the average place of the nodes they connect to, a few times in each
447
459
  * direction, so edges cross less. Each column is as wide as its widest node.
448
460
  */
449
- function layoutGraph(nodes, edges, widthOf) {
450
- const depth = nodes.map(() => 0);
461
+ function layoutGraph(nodes, edges, getWidth) {
462
+ const depth = [];
463
+ for (let index = 0; index < nodes.length; index++) depth.push(0);
451
464
  for (let round = 0, changed = true; changed && round < nodes.length; round++) {
452
465
  changed = false;
453
466
  for (const [from, to] of edges) if (depth[from] + 1 > depth[to]) {
@@ -456,43 +469,52 @@ function layoutGraph(nodes, edges, widthOf) {
456
469
  }
457
470
  }
458
471
  const columns = [];
459
- nodes.forEach((_, index) => {
460
- (columns[depth[index]] ??= []).push(index);
461
- });
462
- const filled = columns.filter(Boolean);
472
+ for (let index = 0; index < nodes.length; index++) (columns[depth[index]] ??= []).push(index);
473
+ const filled = [];
474
+ for (const column of columns) if (column) filled.push(column);
463
475
  const order = /* @__PURE__ */ new Map();
464
- for (const column of filled) column.forEach((node, index) => order.set(node, index));
465
- const before = nodes.map(() => []);
466
- const after = nodes.map(() => []);
476
+ for (const column of filled) for (const [index, node] of column.entries()) order.set(node, index);
477
+ const before = [];
478
+ const after = [];
479
+ for (let index = 0; index < nodes.length; index++) {
480
+ before.push([]);
481
+ after.push([]);
482
+ }
467
483
  for (const [from, to] of edges) {
468
484
  after[from].push(to);
469
485
  before[to].push(from);
470
486
  }
471
- const average = (list, fallback) => list.length === 0 ? fallback : list.reduce((sum, node) => sum + order.get(node), 0) / list.length;
487
+ function average(list, fallback) {
488
+ if (list.length === 0) return fallback;
489
+ let sum = 0;
490
+ for (const node of list) sum += order.get(node);
491
+ return sum / list.length;
492
+ }
472
493
  for (let sweep = 0; sweep < 8; sweep++) {
473
494
  const forward = sweep % 2 === 0;
474
495
  const sequence = forward ? filled.slice(1) : filled.slice(0, -1).toReversed();
475
496
  for (const column of sequence) {
476
- const weight = new Map(column.map((node) => [node, average(forward ? before[node] : after[node], order.get(node))]));
497
+ const weight = /* @__PURE__ */ new Map();
498
+ for (const node of column) weight.set(node, average(forward ? before[node] : after[node], order.get(node)));
477
499
  column.sort((a, b) => weight.get(a) - weight.get(b));
478
- column.forEach((node, index) => order.set(node, index));
500
+ for (const [index, node] of column.entries()) order.set(node, index);
479
501
  }
480
502
  }
481
503
  const ROW = 50;
482
504
  const GAP = 72;
483
- const tallest = Math.max(1, ...filled.map((column) => column.length));
505
+ let tallest = 1;
506
+ for (const column of filled) tallest = Math.max(tallest, column.length);
484
507
  const result = [];
485
508
  let x = 16;
486
509
  for (const column of filled) {
487
- const width = Math.max(...column.map(widthOf));
510
+ let width = -Infinity;
511
+ for (const node of column) width = Math.max(width, getWidth(node));
488
512
  const top = 16 + (tallest - column.length) * ROW / 2;
489
- column.forEach((node, index) => {
490
- result[node] = {
491
- x,
492
- y: top + index * ROW,
493
- width
494
- };
495
- });
513
+ for (const [index, node] of column.entries()) result[node] = {
514
+ x,
515
+ y: top + index * ROW,
516
+ width
517
+ };
496
518
  x += width + GAP;
497
519
  }
498
520
  return result;
@@ -500,21 +522,19 @@ function layoutGraph(nodes, edges, widthOf) {
500
522
  /** The scopes of a component instance, without the components inside it. */
501
523
  function countScopes(scope) {
502
524
  let count = 1;
503
- for (const child of scope.children) if (child.m === void 0) count += countScopes(child);
525
+ for (const child of scope.children ?? []) if (child.m === void 0) count += countScopes(child);
504
526
  return count;
505
527
  }
506
528
  /** A label cut to the width of a node of the graph. */
507
- const clip = (text) => text.length > 34 ? `${text.slice(0, 33)}…` : text;
529
+ function clip(text) {
530
+ return text.length > 34 ? `${text.slice(0, 33)}…` : text;
531
+ }
508
532
  /** The text of an entry of the log. */
509
- const textOf = (entry) => entry.kind === "write" ? describe(entry) : entry.text;
510
- /** The class of the bar of a load: its reason, and whether it was used or failed. */
511
- function barClass(load) {
512
- if (load.failed) return "failed";
513
- if (PRELOADS.has(load.reason)) return load.used ? "preload" : "unused";
514
- return load.reason === "event" || load.reason === "block" ? "" : "other";
533
+ function readText(entry) {
534
+ return entry.kind === "write" ? describe(entry) : entry.text;
515
535
  }
516
536
  /** The places of a stack, with their files as the dev server can read them. */
517
- function framesOf(stack) {
537
+ function parseFrames(stack) {
518
538
  const frames = [];
519
539
  for (const line of (stack ?? "").split("\n")) {
520
540
  const match = /^\s*at (?:(.*?) \()?(.+?):(\d+):(\d+)\)?\s*$/.exec(line);
@@ -547,9 +567,13 @@ const mapped = /* @__PURE__ */ new Map();
547
567
  * its own file and line. A frame that the dev server cannot map stays as it is.
548
568
  */
549
569
  function mapFrames(frames, urls) {
550
- return Promise.all(frames.map((frame, index) => {
570
+ const results = [];
571
+ for (const [index, frame] of frames.entries()) {
551
572
  const url = urls[index];
552
- if (!frame.compiled || frame.library || !url) return frame;
573
+ if (!frame.compiled || frame.library || !url) {
574
+ results.push(frame);
575
+ continue;
576
+ }
553
577
  const unmapped = {
554
578
  ...frame,
555
579
  url
@@ -569,8 +593,9 @@ function mapFrames(frames, urls) {
569
593
  } : unmapped).catch(() => unmapped);
570
594
  mapped.set(key, result);
571
595
  }
572
- return result;
573
- }));
596
+ results.push(result);
597
+ }
598
+ return Promise.all(results);
574
599
  }
575
600
  /** The URLs that the frames of a stack name, as the dev server knows the modules. */
576
601
  function frameUrls(stack) {
@@ -591,7 +616,7 @@ let highlighter;
591
616
  /** The sources of files, by path. */
592
617
  const sources = /* @__PURE__ */ new Map();
593
618
  /** The code of a module as the dev server sent it to the browser. */
594
- function compiledOf(url) {
619
+ function fetchCompiled(url) {
595
620
  let text = sources.get(url);
596
621
  if (!text) {
597
622
  text = fetch(url).then((response) => response.ok ? response.text() : void 0).catch(() => void 0);
@@ -599,7 +624,7 @@ function compiledOf(url) {
599
624
  }
600
625
  return text;
601
626
  }
602
- function sourceOf(file) {
627
+ function fetchSource(file) {
603
628
  let text = sources.get(file);
604
629
  if (!text) {
605
630
  text = fetch(`/__brumate/source?file=${encodeURIComponent(file)}`).then((response) => response.ok ? response.text() : void 0).catch(() => void 0);
@@ -614,7 +639,7 @@ function sourceOf(file) {
614
639
  */
615
640
  async function codeView(place, fallback) {
616
641
  const box = element("div", { class: "code" });
617
- const [text, module] = await Promise.all([place.url ? compiledOf(place.url) : sourceOf(place.file), highlighter ??= import("./highlight.js")]);
642
+ const [text, module] = await Promise.all([place.url ? fetchCompiled(place.url) : fetchSource(place.file), highlighter ??= import("./highlight.js")]);
618
643
  if (text === void 0) {
619
644
  box.append(element("pre", { class: "plain" }, fallback ?? "The dev server cannot read this file."));
620
645
  return box;
@@ -640,19 +665,18 @@ async function codeView(place, fallback) {
640
665
  class: "error-mark"
641
666
  }] : []
642
667
  }));
643
- [...box.querySelectorAll("code > .l")].forEach((line, index) => {
644
- if (index + 1 < start || index + 1 > end) {
645
- if (line.nextSibling?.nodeType === Node.TEXT_NODE) line.nextSibling.remove();
646
- line.remove();
647
- }
648
- });
668
+ const shown = [...box.querySelectorAll("code > .l")];
669
+ for (const [index, line] of shown.entries()) if (index + 1 < start || index + 1 > end) {
670
+ if (line.nextSibling?.nodeType === Node.TEXT_NODE) line.nextSibling.remove();
671
+ line.remove();
672
+ }
649
673
  return box;
650
674
  }
651
675
  /** The name of a handler, such as `Index h16`, once the dev server said the component. */
652
- const handlerName = (ref) => {
676
+ function handlerName(ref) {
653
677
  const [component, name = ""] = ref.split("#");
654
678
  return `${known.get(component)?.name ?? component} ${name}`;
655
- };
679
+ }
656
680
  /** A round step for the ticks of a ruler: 1, 2 or 5 times a power of ten, at least `rough`. */
657
681
  function tickStep(rough) {
658
682
  const power = 10 ** Math.floor(Math.log10(rough));
@@ -773,11 +797,11 @@ function togglePanel(root, state, initial = "overview") {
773
797
  role: "region",
774
798
  "aria-label": "brumate devtools"
775
799
  }, element("style", {}, STYLE), resize, element("div", { class: "top" }, element("span", { class: "brand" }, logo, "brumate"), ...versions, routeText, stats, element("span", { class: "spacer" }), flash, pick, close), element("div", { class: "main" }, nav, body));
776
- const applyHeight = () => {
800
+ function applyHeight() {
777
801
  panel.style.height = `${height}px`;
778
802
  if (errorPage) panel.style.maxHeight = "none";
779
803
  document.documentElement.style.paddingBottom = `${height}px`;
780
- };
804
+ }
781
805
  applyHeight();
782
806
  root.append(panel);
783
807
  if (opener) opener.hidden = true;
@@ -793,18 +817,20 @@ function togglePanel(root, state, initial = "overview") {
793
817
  };
794
818
  resize.addEventListener("pointerdown", (event) => {
795
819
  event.preventDefault();
796
- const move = (next) => state.resize?.(next.clientY);
797
- const up = () => {
820
+ function move(next) {
821
+ state.resize?.(next.clientY);
822
+ }
823
+ function up() {
798
824
  window.removeEventListener("pointermove", move);
799
825
  window.removeEventListener("pointerup", up);
800
826
  state.resized?.();
801
- };
827
+ }
802
828
  window.addEventListener("pointermove", move);
803
829
  window.addEventListener("pointerup", up);
804
830
  });
805
831
  if (!state.scopes) document.dispatchEvent(new Event("brumate:core"));
806
832
  const outlines = [];
807
- const outline = (scope) => {
833
+ function outline(scope) {
808
834
  for (const box of outlines.splice(0)) box.remove();
809
835
  if (scope === void 0) return;
810
836
  for (const target of document.querySelectorAll(`[b-b^="${scope}:"]`)) {
@@ -816,8 +842,8 @@ function togglePanel(root, state, initial = "overview") {
816
842
  root.append(box);
817
843
  outlines.push(box);
818
844
  }
819
- };
820
- const onPick = (event) => {
845
+ }
846
+ function onPick(event) {
821
847
  const clicked = event.target;
822
848
  if (!clicked?.closest || event.composedPath().includes(panel)) return;
823
849
  event.preventDefault();
@@ -828,11 +854,11 @@ function togglePanel(root, state, initial = "overview") {
828
854
  if (id !== void 0) {
829
855
  selectedScope = /^-?\d+$/.test(id) ? Number(id) : id;
830
856
  const scope = state.scopes?.get(selectedScope);
831
- selected = scope ? rootOf(scope).m : selected;
857
+ selected = scope ? findRootScope(scope).m : selected;
832
858
  }
833
859
  tab = "elements";
834
860
  draw();
835
- };
861
+ }
836
862
  const inspectCard = element("div", {
837
863
  class: "inspect-card",
838
864
  role: "tooltip"
@@ -840,34 +866,35 @@ function togglePanel(root, state, initial = "overview") {
840
866
  const hoverBox = element("div", { class: "outline" });
841
867
  let hovered;
842
868
  let hoverToken = 0;
843
- const onHover = (event) => {
869
+ function onHover(event) {
844
870
  const target = event.target;
845
871
  if (!target?.closest || event.composedPath().includes(panel) || target === hovered) return;
846
872
  hovered = target;
847
873
  inspect(target);
848
- };
849
- const inspect = async (target) => {
874
+ }
875
+ async function inspect(target) {
850
876
  const token = ++hoverToken;
851
877
  const rect = target.getBoundingClientRect();
852
878
  hoverBox.style.cssText = `left:${rect.left}px;top:${rect.top}px;width:${rect.width}px;height:${rect.height}px`;
853
879
  root.append(hoverBox, inspectCard);
854
- const rows = [element("div", { class: "card-head" }, element("span", { class: "mono" }, `${target.tagName.toLowerCase()}${[...target.classList].slice(0, 2).map((name) => `.${name}`).join("")}`), element("span", { class: "sub" }, `${Math.round(rect.width)} × ${Math.round(rect.height)}`))];
880
+ const tag = target.tagName.toLowerCase();
881
+ let classes = "";
882
+ for (const name of [...target.classList].slice(0, 2)) classes += `.${name}`;
883
+ const rows = [element("div", { class: "card-head" }, element("span", { class: "mono" }, `${tag}${classes}`), element("span", { class: "sub" }, `${Math.round(rect.width)} × ${Math.round(rect.height)}`))];
855
884
  const anchored = target.closest("[b-b]");
856
885
  const [id = "", anchorText = "0"] = anchored?.getAttribute("b-b").split(":") ?? [];
857
- const scope = anchored ? scopeOf(id) : void 0;
886
+ const scope = anchored ? findScope(id) : void 0;
858
887
  if (scope) {
859
- const { info, component: owner, place } = await anchorOf(scope, Number(anchorText));
888
+ const { info, component: owner, place } = await findAnchor(scope, Number(anchorText));
860
889
  if (token !== hoverToken) return;
861
890
  rows.push(element("div", { class: "card-component" }, element("strong", {}, info?.name ?? owner.m ?? "component"), element("span", { class: "mono sub" }, place?.at ? `${info?.file}:${place.at}` : info?.file ?? "")), element("div", { class: "sub" }, `scope ${scope.id} · ${info?.scopes[scope.k]?.label ?? "scope"}${anchored === target ? "" : ` · in ${place?.label ?? "an element"}`}`));
862
891
  const handled = target.closest("[b-on]");
863
892
  if (handled && anchored.contains(handled)) {
864
893
  const handlers = element("div", { class: "card-pills" });
865
- for (const raw of (handled.getAttribute("b-on") ?? "").split(/\s+/).filter(Boolean)) {
866
- const [head, ref = ""] = raw.split("=");
867
- const [handlerComponent, name = ""] = ref.split("@")[0].split("#");
868
- const part = /^[hct]\d/.test(name) ? name : "update";
869
- const load = state.loads.get(`${handlerComponent}:${part}`) ?? state.loads.get(`${handlerComponent}:all`);
870
- handlers.append(pill(`${head} · ${load?.end === void 0 ? "not loaded" : "loaded"}`, load?.end === void 0 ? "" : "green"));
894
+ for (const raw of (handled.getAttribute("b-on") ?? "").split(/\s+/)) {
895
+ if (!raw) continue;
896
+ const [head] = raw.split("=");
897
+ handlers.append(pill(head));
871
898
  }
872
899
  rows.push(handlers);
873
900
  }
@@ -879,12 +906,12 @@ function togglePanel(root, state, initial = "overview") {
879
906
  const top = rect.bottom + 8 + cardHeight < window.innerHeight ? rect.bottom + 8 : Math.max(8, rect.top - 8 - cardHeight);
880
907
  const left = Math.min(Math.max(8, rect.left), window.innerWidth - inspectCard.offsetWidth - 8);
881
908
  inspectCard.style.cssText = `top:${top}px;left:${left}px`;
882
- };
883
- const onEscape = (event) => {
909
+ }
910
+ function onEscape(event) {
884
911
  if (event.key === "Escape") stopPicking();
885
- };
912
+ }
886
913
  endPick = () => stopPicking();
887
- const stopPicking = () => {
914
+ function stopPicking() {
888
915
  pick.setAttribute("aria-pressed", "false");
889
916
  window.removeEventListener("click", onPick, true);
890
917
  window.removeEventListener("pointermove", onHover, true);
@@ -894,7 +921,7 @@ function togglePanel(root, state, initial = "overview") {
894
921
  hoverToken++;
895
922
  hoverBox.remove();
896
923
  inspectCard.remove();
897
- };
924
+ }
898
925
  pick.addEventListener("click", () => {
899
926
  if (pick.getAttribute("aria-pressed") === "true") {
900
927
  stopPicking();
@@ -906,28 +933,30 @@ function togglePanel(root, state, initial = "overview") {
906
933
  window.addEventListener("pointermove", onHover, true);
907
934
  window.addEventListener("keydown", onEscape, true);
908
935
  });
909
- const roots = () => [...state.scopes?.values() ?? []].filter((scope) => scope.m !== void 0);
910
- const scopeOf = (id) => state.scopes?.get(/^-?\d+$/.test(id) ? Number(id) : id);
936
+ /** The scopes of component instances. */
937
+ function roots() {
938
+ const result = [];
939
+ for (const scope of state.scopes?.values() ?? []) if (scope.m !== void 0) result.push(scope);
940
+ return result;
941
+ }
942
+ function findScope(id) {
943
+ return state.scopes?.get(/^-?\d+$/.test(id) ? Number(id) : id);
944
+ }
911
945
  /** The header and the counts of the tabs. */
912
- const drawChrome = () => {
946
+ function drawChrome() {
913
947
  for (const button of nav.querySelectorAll(".tab")) button.setAttribute("aria-selected", String(button.dataset.tab === tab));
914
948
  const list = roots();
915
- const loads = [...state.loads.values()];
916
- const code = codeBytes(state);
917
949
  routeText.textContent = location.pathname + location.search;
918
950
  stats.textContent = [
919
- `${new Set(list.map((scope) => scope.m)).size} components`,
951
+ `${collectModules(list).size} components`,
920
952
  `${state.scopes?.size ?? 0} scopes`,
921
- `${loads.length} parts${code ? ` (${kilobytes(code)})` : ""}`,
922
953
  `state ${kilobytes(stateBytes())}`
923
954
  ].join(" · ");
924
- const unused = loads.filter((load) => PRELOADS.has(load.reason) && !load.used).length;
925
- const waiting = [...state.blocks.values()].filter((block) => block.state === "waiting").length;
955
+ const waiting = countBlocks(state.blocks.values(), "waiting");
926
956
  const counts = {
927
957
  errors: [state.errors.length, "Errors"],
928
- scopes: [new Set(list.map((scope) => scope.m)).size],
958
+ scopes: [collectModules(list).size],
929
959
  log: [state.log.length],
930
- loading: unused > 0 ? [unused, "Preloads that nothing used"] : [loads.length],
931
960
  blocks: waiting > 0 ? [waiting, "Blocks that wait for their trigger"] : [state.blocks.size]
932
961
  };
933
962
  for (const [name, badge] of badges) {
@@ -938,11 +967,11 @@ function togglePanel(root, state, initial = "overview") {
938
967
  badge.className = `badge${kind}`;
939
968
  badge.title = warning ?? "";
940
969
  }
941
- };
970
+ }
942
971
  /** A select of the components on the page, for Graph and Report. */
943
- const chooser = (current) => {
972
+ function chooser(current) {
944
973
  const select = element("select", { "aria-label": "Component" });
945
- for (const id of new Set(roots().map((scope) => scope.m))) {
974
+ for (const id of collectModules(roots())) {
946
975
  const info = known.get(id);
947
976
  const option = element("option", { value: id }, info ? `${info.name} · ${info.file}` : id);
948
977
  option.selected = id === current;
@@ -954,8 +983,8 @@ function togglePanel(root, state, initial = "overview") {
954
983
  draw();
955
984
  });
956
985
  return select;
957
- };
958
- const drawErrors = async () => {
986
+ }
987
+ async function drawErrors() {
959
988
  if (state.errors.length === 0) {
960
989
  body.replaceChildren(element("h2", {}, "Errors"), element("p", { class: "sub" }, "No errors. Errors of a render on the server, of Vite, such as a compile error after an edit, and of code in the browser show here."));
961
990
  return;
@@ -985,8 +1014,17 @@ function togglePanel(root, state, initial = "overview") {
985
1014
  draw();
986
1015
  });
987
1016
  list.append(element("div", { style: "margin-top: 8px" }, clear));
988
- const frames = await mapFrames(framesOf(error.stack), frameUrls(error.stack));
989
- if (selectedFrame === -1) selectedFrame = error.loc ? -2 : frames.findIndex((frame) => !frame.library && !frame.compiled);
1017
+ const frames = await mapFrames(parseFrames(error.stack), frameUrls(error.stack));
1018
+ if (selectedFrame === -1) {
1019
+ selectedFrame = -2;
1020
+ if (!error.loc) {
1021
+ selectedFrame = -1;
1022
+ for (const [index, item] of frames.entries()) if (!item.library && !item.compiled) {
1023
+ selectedFrame = index;
1024
+ break;
1025
+ }
1026
+ }
1027
+ }
990
1028
  const frame = selectedFrame >= 0 ? frames[selectedFrame] : void 0;
991
1029
  const place = selectedFrame === -2 ? error.loc : frame;
992
1030
  const detail = element("div", { class: "detail" });
@@ -995,7 +1033,7 @@ function togglePanel(root, state, initial = "overview") {
995
1033
  else if (error.frame) detail.append(element("div", { class: "code" }, element("pre", { class: "plain" }, error.frame)));
996
1034
  if (frames.length > 0) {
997
1035
  const stack = element("div", { class: "frames" });
998
- frames.forEach((item, index) => {
1036
+ for (const [index, item] of frames.entries()) {
999
1037
  const button = element("button", {
1000
1038
  class: `frame${item.library ? " library" : ""}`,
1001
1039
  "aria-current": String(index === selectedFrame),
@@ -1006,13 +1044,13 @@ function togglePanel(root, state, initial = "overview") {
1006
1044
  draw();
1007
1045
  });
1008
1046
  stack.append(button);
1009
- });
1047
+ }
1010
1048
  detail.append(element("h3", {}, "Stack"), stack);
1011
1049
  }
1012
1050
  body.replaceChildren(element("div", { class: "split" }, list, detail));
1013
- };
1051
+ }
1014
1052
  /** A button that opens a place of a file in the editor. */
1015
- const open = (place) => {
1053
+ function open(place) {
1016
1054
  const button = element("button", {
1017
1055
  class: "link",
1018
1056
  title: "Open in the editor"
@@ -1021,27 +1059,30 @@ function togglePanel(root, state, initial = "overview") {
1021
1059
  fetch(`/__open-in-editor?file=${encodeURIComponent(`${place.file}:${place.line}:${place.column}`)}`);
1022
1060
  });
1023
1061
  return button;
1024
- };
1025
- const drawOverview = async () => {
1062
+ }
1063
+ async function drawOverview() {
1026
1064
  const list = roots();
1027
- const ids = [...new Set(list.map((scope) => scope.m))];
1028
- const infos = await Promise.all(ids.map((id) => componentInfo(state, id)));
1029
- const loads = [...state.loads.values()];
1030
- const code = codeBytes(state);
1031
- const unused = loads.filter((load) => PRELOADS.has(load.reason) && !load.used).length;
1065
+ const ids = [...collectModules(list)];
1066
+ const infos = await loadComponents(state, ids);
1032
1067
  const blocks = [...state.blocks.values()];
1033
- const handlers = state.log.filter((entry) => entry.kind === "handler").length;
1034
- const calls = state.log.filter((entry) => entry.kind === "call").length;
1068
+ let handlers = 0;
1069
+ let calls = 0;
1070
+ for (const entry of state.log) if (entry.kind === "handler") handlers++;
1071
+ else if (entry.kind === "call") calls++;
1035
1072
  const table = element("table", { class: "rows" }, row([
1036
1073
  "component",
1037
1074
  "file",
1038
1075
  "instances",
1039
- "scopes",
1040
- "parts loaded"
1076
+ "scopes"
1041
1077
  ], "th"));
1042
- ids.forEach((id, index) => {
1078
+ for (const [index, id] of ids.entries()) {
1043
1079
  const info = infos[index];
1044
- const instances = list.filter((scope) => scope.m === id);
1080
+ const instances = [];
1081
+ let scopeCount = 0;
1082
+ for (const scope of list) if (scope.m === id) {
1083
+ instances.push(scope);
1084
+ scopeCount += countScopes(scope);
1085
+ }
1045
1086
  const name = element("button", {
1046
1087
  class: "link",
1047
1088
  title: "Show its scopes"
@@ -1052,25 +1093,23 @@ function togglePanel(root, state, initial = "overview") {
1052
1093
  tab = "scopes";
1053
1094
  draw();
1054
1095
  });
1055
- const parts = loads.filter((load) => load.component === id).map((load) => load.part);
1056
1096
  table.append(row([
1057
1097
  name,
1058
1098
  source(info),
1059
1099
  String(instances.length),
1060
- String(instances.reduce((sum, scope) => sum + countScopes(scope), 0)),
1061
- element("span", { class: "mono" }, parts.join(", ") || "—")
1100
+ String(scopeCount)
1062
1101
  ]));
1063
- });
1102
+ }
1064
1103
  body.replaceChildren(element("div", {
1065
1104
  class: "kv",
1066
1105
  style: "margin-bottom: 12px"
1067
- }, element("span", {}, "Page"), element("span", { class: "mono" }, location.href), element("span", {}, "brumate"), element("span", { class: "mono" }, state.meta.version ?? "unknown"), element("span", {}, "Vite"), element("span", { class: "mono" }, state.meta.vite ?? "unknown"), element("span", {}, "Open for"), element("span", { class: "mono" }, seconds(performance.now()))), element("div", { class: "cards" }, card("Components", String(ids.length), `${state.scopes?.size ?? 0} scopes in the browser`), card("Client code", code ? kilobytes(code) : String(loads.length), `${loads.length} parts loaded${unused ? `, ${unused} preloads unused` : ""}`), card("Page state", kilobytes(stateBytes()), "state records from the server"), card("Blocks", String(blocks.length), `${blocks.filter((block) => block.state === "waiting").length} waiting, ${blocks.filter((block) => block.state === "rendered").length} rendered`), card("Handlers run", String(handlers), `${calls} server function calls`)), element("h3", {}, "Components on the page"), ids.length > 0 ? table : element("div", { class: "empty" }, "No components with client state yet."));
1068
- };
1106
+ }, element("span", {}, "Page"), element("span", { class: "mono" }, location.href), element("span", {}, "brumate"), element("span", { class: "mono" }, state.meta.version ?? "unknown"), element("span", {}, "Vite"), element("span", { class: "mono" }, state.meta.vite ?? "unknown"), element("span", {}, "Open for"), element("span", { class: "mono" }, seconds(performance.now()))), element("div", { class: "cards" }, card("Components", String(ids.length), `${state.scopes?.size ?? 0} scopes in the browser`), card("Page state", kilobytes(stateBytes()), "state records from the server"), card("Blocks", String(blocks.length), `${countBlocks(blocks, "waiting")} waiting, ${countBlocks(blocks, "rendered")} rendered`), card("Handlers run", String(handlers), `${calls} server function calls`)), element("h3", {}, "Components on the page"), ids.length > 0 ? table : element("div", { class: "empty" }, "No components with client state yet."));
1107
+ }
1069
1108
  /** A slot with its name, type and value. A value that JSON can hold can be edited. */
1070
- const drawSlot = (scope, slot, name) => {
1109
+ function drawSlot(scope, slot, name) {
1071
1110
  const value = scope.s[slot];
1072
1111
  const cell = element("td");
1073
- const line = element("tr", { class: "slot" }, element("td", { class: "name" }, name), element("td", { class: "type" }, typeOf(value)), cell);
1112
+ const line = element("tr", { class: "slot" }, element("td", { class: "name" }, name), element("td", { class: "type" }, readType(value)), cell);
1074
1113
  if (editing?.scope === scope.id && editing.slot === slot) {
1075
1114
  const input = element("input", { "aria-label": `New value of ${name}` });
1076
1115
  input.value = JSON.stringify(value) ?? "";
@@ -1102,10 +1141,12 @@ function togglePanel(root, state, initial = "overview") {
1102
1141
  }
1103
1142
  cell.append(text);
1104
1143
  return line;
1105
- };
1106
- const drawScopes = async () => {
1144
+ }
1145
+ async function drawScopes() {
1107
1146
  const list = roots();
1108
- const infos = await Promise.all(list.map((scope) => componentInfo(state, scope.m)));
1147
+ const listed = [];
1148
+ for (const scope of list) listed.push(scope.m);
1149
+ const infos = await loadComponents(state, listed);
1109
1150
  if (list.length === 0) {
1110
1151
  body.replaceChildren(element("div", { class: "empty" }, "No scopes yet. The first event loads them."));
1111
1152
  return;
@@ -1126,7 +1167,7 @@ function togglePanel(root, state, initial = "overview") {
1126
1167
  });
1127
1168
  });
1128
1169
  const tree = element("div", { class: "list" }, search);
1129
- const visit = (scope, info, depth) => {
1170
+ function visit(scope, info, depth) {
1130
1171
  const label = scope.m === void 0 ? `${info?.scopes[scope.k]?.label ?? "scope"}${scope.h ? " · hidden" : ""}` : info?.name ?? scope.m;
1131
1172
  const classes = ["tree-row"];
1132
1173
  if (scope.m !== void 0) classes.push("component");
@@ -1138,21 +1179,28 @@ function togglePanel(root, state, initial = "overview") {
1138
1179
  }, element("span", {}, label), element("span", { class: "file" }, scope.m === void 0 ? `#${scope.id}` : info?.file ?? ""));
1139
1180
  button.addEventListener("click", () => {
1140
1181
  selectedScope = scope.id;
1141
- selected = rootOf(scope).m;
1182
+ selected = findRootScope(scope).m;
1142
1183
  draw();
1143
1184
  });
1144
1185
  button.addEventListener("mouseenter", () => outline(scope.id));
1145
1186
  button.addEventListener("mouseleave", () => outline());
1146
1187
  tree.append(button);
1147
- for (const child of scope.children) if (child.m === void 0) visit(child, info, depth + 1);
1148
- };
1188
+ for (const child of scope.children ?? []) if (child.m === void 0) visit(child, info, depth + 1);
1189
+ }
1149
1190
  const needle = filter.trim().toLowerCase();
1150
- list.forEach((scope, index) => {
1191
+ for (const [index, scope] of list.entries()) {
1151
1192
  const info = infos[index];
1152
- if (needle && !`${info?.name ?? scope.m} ${info?.file ?? ""}`.toLowerCase().includes(needle) && !scope.s.some((value) => preview(value).toLowerCase().includes(needle))) return;
1193
+ if (needle && !`${info?.name ?? scope.m} ${info?.file ?? ""}`.toLowerCase().includes(needle)) {
1194
+ let matched = false;
1195
+ for (const value of scope.s) if (preview(value).toLowerCase().includes(needle)) {
1196
+ matched = true;
1197
+ break;
1198
+ }
1199
+ if (!matched) continue;
1200
+ }
1153
1201
  visit(scope, info, 0);
1154
- });
1155
- const component = rootOf(current);
1202
+ }
1203
+ const component = findRootScope(current);
1156
1204
  const info = known.get(component.m ?? "");
1157
1205
  const plan = info?.scopes[current.k];
1158
1206
  const slots = element("table", { class: "rows slots" }, row([
@@ -1160,7 +1208,7 @@ function togglePanel(root, state, initial = "overview") {
1160
1208
  "type",
1161
1209
  "value"
1162
1210
  ], "th"));
1163
- current.s.forEach((_, slot) => slots.append(drawSlot(current, slot, plan?.slots[slot] ?? `slot ${slot}`)));
1211
+ for (let slot = 0; slot < current.s.length; slot++) slots.append(drawSlot(current, slot, plan?.slots[slot] ?? `slot ${slot}`));
1164
1212
  const graph = iconButton("graph", "Show the graph");
1165
1213
  graph.addEventListener("click", () => {
1166
1214
  selected = component.m;
@@ -1170,56 +1218,43 @@ function togglePanel(root, state, initial = "overview") {
1170
1218
  const detail = element("div", { class: `detail${state.written.has(current.id) ? " written" : ""}` }, element("h2", {}, info?.name ?? component.m ?? "", element("span", { class: "sub" }, ` · ${plan?.label ?? "scope"}`)), element("div", { class: "toolbar" }, pill(`scope ${current.id}`), current.h ? pill("hidden", "yellow") : "", source(info), element("span", { class: "spacer" }), graph), current.s.length > 0 ? slots : element("div", { class: "empty" }, "This scope holds no values."));
1171
1219
  body.replaceChildren(element("div", { class: "split" }, tree, detail));
1172
1220
  body.querySelector("[aria-current=\"true\"]")?.scrollIntoView({ block: "nearest" });
1173
- };
1221
+ }
1174
1222
  /** What the dev server says about an anchor of a scope, with the component that has it. */
1175
- const anchorOf = async (scope, anchor) => {
1176
- const component = rootOf(scope);
1223
+ async function findAnchor(scope, anchor) {
1224
+ const component = findRootScope(scope);
1177
1225
  const info = component.m ? await componentInfo(state, component.m) : void 0;
1178
1226
  return {
1179
1227
  info,
1180
1228
  component,
1181
1229
  place: info?.anchors?.[scope.k]?.[anchor]
1182
1230
  };
1183
- };
1231
+ }
1184
1232
  /** The names that an anchor reads, with their values in the scope. */
1185
- const drawReads = (scope, reads) => reads.map((name) => {
1186
- const value = valueOf(scope, name);
1187
- return element("span", {
1188
- class: "pill",
1189
- style: "margin: 0 4px 2px 0"
1190
- }, element("span", { class: "name" }, name), value === void 0 ? "" : ` = ${value}`);
1191
- });
1192
- /** The handlers of an element, from its `b-on`, with the state of the code of each one. */
1193
- const drawHandlers = (target) => {
1194
- const table = element("table", { class: "rows" }, row([
1195
- "event",
1196
- "handler",
1197
- "part",
1198
- "code",
1199
- "size"
1200
- ], "th"));
1201
- for (const raw of (target.getAttribute("b-on") ?? "").split(/\s+/).filter(Boolean)) {
1233
+ function drawReads(scope, reads) {
1234
+ const pills = [];
1235
+ for (const name of reads) {
1236
+ const value = readValue(scope, name);
1237
+ pills.push(element("span", {
1238
+ class: "pill",
1239
+ style: "margin: 0 4px 2px 0"
1240
+ }, element("span", { class: "name" }, name), value === void 0 ? "" : ` = ${value}`));
1241
+ }
1242
+ return pills;
1243
+ }
1244
+ /** The handlers of an element, from its `b-on`. */
1245
+ function drawHandlers(target) {
1246
+ const table = element("table", { class: "rows" }, row(["event", "handler"], "th"));
1247
+ for (const raw of (target.getAttribute("b-on") ?? "").split(/\s+/)) {
1248
+ if (!raw) continue;
1202
1249
  const [head, ref = ""] = raw.split("=");
1203
1250
  const [type, ...modifiers] = head.split(":");
1204
1251
  const [component, name = ""] = ref.split("@")[0].split("#");
1205
- const part = /^[hct]\d/.test(name) ? name : "update";
1206
- const load = state.loads.get(`${component}:${part}`) ?? state.loads.get(`${component}:all`);
1207
1252
  const info = known.get(component);
1208
- let status = pill("not loaded");
1209
- if (load && load.end === void 0) status = pill("loading", "blue");
1210
- else if (load && load.end !== void 0) status = pill(`${load.failed ? "failed" : "loaded"} in ${ms(load.end - load.start)} (${load.reason})`, load.failed ? "red" : "green");
1211
- const bytes = bytesOf(info, load?.part ?? part);
1212
- table.append(row([
1213
- element("span", { class: "mono" }, [type, ...modifiers].join(":")),
1214
- element("span", { class: "mono" }, `${info?.name ?? component} ${name}`),
1215
- element("span", { class: "mono" }, part),
1216
- status,
1217
- bytes ? kilobytes(bytes) : ""
1218
- ]));
1253
+ table.append(row([element("span", { class: "mono" }, [type, ...modifiers].join(":")), element("span", { class: "mono" }, `${info?.name ?? component} ${name}`)]));
1219
1254
  }
1220
1255
  return table;
1221
- };
1222
- const drawElements = async () => {
1256
+ }
1257
+ async function drawElements() {
1223
1258
  if (!picked?.isConnected) {
1224
1259
  const start = iconButton("pick", "Pick an element");
1225
1260
  start.addEventListener("click", () => pick.click());
@@ -1230,10 +1265,10 @@ function togglePanel(root, state, initial = "overview") {
1230
1265
  const content = element("div");
1231
1266
  const anchored = picked.closest("[b-b]");
1232
1267
  const [id = "", anchorText = "0"] = anchored?.getAttribute("b-b").split(":") ?? [];
1233
- const scope = anchored ? scopeOf(id) : void 0;
1268
+ const scope = anchored ? findScope(id) : void 0;
1234
1269
  if (scope) {
1235
1270
  const anchor = Number(anchorText);
1236
- const { info, component, place } = await anchorOf(scope, anchor);
1271
+ const { info, component, place } = await findAnchor(scope, anchor);
1237
1272
  const scopeButton = element("button", {
1238
1273
  class: "link",
1239
1274
  title: "Show the scope"
@@ -1252,32 +1287,34 @@ function togglePanel(root, state, initial = "overview") {
1252
1287
  for (let node = walker.nextNode(); node; node = walker.nextNode()) {
1253
1288
  const data = node.data;
1254
1289
  const match = /^[tb](-?[\d.]+):(\d+)/.exec(data);
1255
- const markerScope = match && scopeOf(match[1]);
1290
+ const markerScope = match && findScope(match[1]);
1256
1291
  if (markerScope) markers.push({
1257
1292
  data,
1258
1293
  scope: markerScope,
1259
1294
  anchor: Number(match[2])
1260
1295
  });
1261
1296
  }
1262
- const places = await Promise.all(markers.map((marker) => anchorOf(marker.scope, marker.anchor)));
1297
+ const pending = [];
1298
+ for (const marker of markers) pending.push(findAnchor(marker.scope, marker.anchor));
1299
+ const places = await Promise.all(pending);
1263
1300
  const inside = element("table", { class: "rows" }, row([
1264
1301
  "marker",
1265
1302
  "source",
1266
1303
  "reads"
1267
1304
  ], "th"));
1268
- markers.forEach((marker, index) => {
1305
+ for (const [index, marker] of markers.entries()) {
1269
1306
  const { info, place } = places[index];
1270
1307
  inside.append(row([
1271
1308
  element("span", { class: "mono" }, place?.label ?? marker.data),
1272
1309
  place?.at ? source(info, place.at) : "",
1273
1310
  element("span", {}, ...drawReads(marker.scope, place?.reads ?? []))
1274
1311
  ]));
1275
- });
1312
+ }
1276
1313
  if (markers.length > 0) content.append(element("h3", {}, "Inside it"), inside);
1277
1314
  body.replaceChildren(content);
1278
- };
1315
+ }
1279
1316
  let cooling;
1280
- const drawGraph = async () => {
1317
+ async function drawGraph() {
1281
1318
  const id = selected ?? roots()[0]?.m;
1282
1319
  const info = id ? await componentInfo(state, id) : void 0;
1283
1320
  if (!id || !info) {
@@ -1289,18 +1326,22 @@ function togglePanel(root, state, initial = "overview") {
1289
1326
  return;
1290
1327
  }
1291
1328
  const { nodes, edges } = info.graph;
1292
- const instance = roots().find((scope) => scope.m === id);
1329
+ let instance;
1330
+ for (const scope of roots()) if (scope.m === id) {
1331
+ instance = scope;
1332
+ break;
1333
+ }
1293
1334
  const scopeOfNode = /* @__PURE__ */ new Map();
1294
- const visit = (scope) => {
1335
+ function visit(scope) {
1295
1336
  if (!scopeOfNode.has(scope.k)) scopeOfNode.set(scope.k, scope);
1296
- for (const child of scope.children) if (child.m === void 0) visit(child);
1297
- };
1337
+ for (const child of scope.children ?? []) if (child.m === void 0) visit(child);
1338
+ }
1298
1339
  if (instance) visit(instance);
1299
1340
  const now = performance.now();
1300
1341
  const hot = /* @__PURE__ */ new Set();
1301
- for (const entry of state.log) if (entry.write?.component === id && now - entry.time < HOT_MS) nodes.forEach((node, index) => {
1302
- if (node.scope === entry.write.k && node.slot === entry.write.slot) hot.add(index);
1303
- });
1342
+ for (const entry of state.log) if (entry.write?.component === id && now - entry.time < HOT_MS) {
1343
+ for (const [index, node] of nodes.entries()) if (node.scope === entry.write.k && node.slot === entry.write.slot) hot.add(index);
1344
+ }
1304
1345
  for (let grew = true; grew;) {
1305
1346
  grew = false;
1306
1347
  for (const [from, to] of edges) if (hot.has(from) && !hot.has(to)) {
@@ -1308,21 +1349,24 @@ function togglePanel(root, state, initial = "overview") {
1308
1349
  grew = true;
1309
1350
  }
1310
1351
  }
1311
- const parts = nodes.map((node) => {
1352
+ const parts = [];
1353
+ for (const node of nodes) {
1312
1354
  const at = /^(.*) (\d+:\d+)$/.exec(node.label);
1313
1355
  const owner = node.slot === void 0 ? void 0 : scopeOfNode.get(node.scope);
1314
1356
  const value = owner && node.slot !== void 0 ? preview(owner.s[node.slot]) : void 0;
1315
1357
  let meta = at ? `${node.kind} · ${at[2]}` : node.kind;
1316
1358
  if (value !== void 0) meta = `= ${value}`;
1317
- return {
1359
+ parts.push({
1318
1360
  name: at ? at[1] : node.label,
1319
1361
  meta,
1320
1362
  value,
1321
1363
  at: at?.[2]
1322
- };
1323
- });
1324
- const widthOf = (index) => Math.min(262, Math.max(112, 36 + 7 * Math.max(clip(parts[index].name).length, clip(parts[index].meta).length)));
1325
- const position = layoutGraph(nodes, edges, widthOf);
1364
+ });
1365
+ }
1366
+ function getNodeWidth(index) {
1367
+ return Math.min(262, Math.max(112, 36 + 7 * Math.max(clip(parts[index].name).length, clip(parts[index].meta).length)));
1368
+ }
1369
+ const position = layoutGraph(nodes, edges, getNodeWidth);
1326
1370
  const related = /* @__PURE__ */ new Set();
1327
1371
  if (graphNode !== void 0 && graphNode < nodes.length) {
1328
1372
  related.add(graphNode);
@@ -1337,8 +1381,14 @@ function togglePanel(root, state, initial = "overview") {
1337
1381
  }
1338
1382
  }
1339
1383
  }
1340
- const graphWidth = Math.max(0, ...position.map((place) => place.x + place.width)) + 16;
1341
- const graphHeight = Math.max(0, ...position.map((place) => place.y)) + 56;
1384
+ let graphWidth = 0;
1385
+ let graphHeight = 0;
1386
+ for (const place of position) {
1387
+ graphWidth = Math.max(graphWidth, place.x + place.width);
1388
+ graphHeight = Math.max(graphHeight, place.y);
1389
+ }
1390
+ graphWidth += 16;
1391
+ graphHeight += 56;
1342
1392
  const layer = svg("g", { class: "layer" });
1343
1393
  for (const [from, to] of edges) {
1344
1394
  const a = position[from];
@@ -1357,7 +1407,7 @@ function togglePanel(root, state, initial = "overview") {
1357
1407
  "marker-end": "url(#arrow)"
1358
1408
  }));
1359
1409
  }
1360
- nodes.forEach((node, index) => {
1410
+ for (const [index, node] of nodes.entries()) {
1361
1411
  const { x, y, width: nodeWidth } = position[index];
1362
1412
  const part = parts[index];
1363
1413
  const classes = ["node", `k-${node.kind}`];
@@ -1400,7 +1450,7 @@ function togglePanel(root, state, initial = "overview") {
1400
1450
  draw();
1401
1451
  });
1402
1452
  layer.append(group);
1403
- });
1453
+ }
1404
1454
  const canvas = svg("svg", {
1405
1455
  role: "img",
1406
1456
  "aria-label": `Graph of ${info.name}`
@@ -1417,24 +1467,24 @@ function togglePanel(root, state, initial = "overview") {
1417
1467
  fill: "#8a8280"
1418
1468
  }))), layer);
1419
1469
  const frame = element("div", { class: "graph-view" }, canvas);
1420
- const apply = () => {
1470
+ function apply() {
1421
1471
  layer.setAttribute("transform", `translate(${view.x},${view.y}) scale(${view.scale})`);
1422
- };
1423
- const fit = () => {
1472
+ }
1473
+ function fit() {
1424
1474
  const box = frame.getBoundingClientRect();
1425
1475
  if (box.width === 0) return;
1426
1476
  view.scale = Math.min(1.2, Math.max(.3, Math.min(box.width / graphWidth, box.height / graphHeight)));
1427
1477
  view.x = (box.width - graphWidth * view.scale) / 2;
1428
1478
  view.y = Math.max(0, (box.height - graphHeight * view.scale) / 2);
1429
1479
  apply();
1430
- };
1431
- const zoomAt = (factor, px, py) => {
1480
+ }
1481
+ function zoomAt(factor, px, py) {
1432
1482
  const next = Math.min(3, Math.max(.2, view.scale * factor));
1433
1483
  view.x = px - (px - view.x) * next / view.scale;
1434
1484
  view.y = py - (py - view.y) * next / view.scale;
1435
1485
  view.scale = next;
1436
1486
  apply();
1437
- };
1487
+ }
1438
1488
  frame.addEventListener("wheel", (event) => {
1439
1489
  event.preventDefault();
1440
1490
  const box = frame.getBoundingClientRect();
@@ -1447,16 +1497,16 @@ function togglePanel(root, state, initial = "overview") {
1447
1497
  y: event.clientY - view.y
1448
1498
  };
1449
1499
  frame.classList.add("dragging");
1450
- const move = (next) => {
1500
+ function move(next) {
1451
1501
  view.x = next.clientX - start.x;
1452
1502
  view.y = next.clientY - start.y;
1453
1503
  apply();
1454
- };
1455
- const up = () => {
1504
+ }
1505
+ function up() {
1456
1506
  frame.classList.remove("dragging");
1457
1507
  window.removeEventListener("pointermove", move);
1458
1508
  window.removeEventListener("pointerup", up);
1459
- };
1509
+ }
1460
1510
  window.addEventListener("pointermove", move);
1461
1511
  window.addEventListener("pointerup", up);
1462
1512
  });
@@ -1466,14 +1516,14 @@ function togglePanel(root, state, initial = "overview") {
1466
1516
  draw();
1467
1517
  }
1468
1518
  });
1469
- const zoomButton = (name, title, factor) => {
1519
+ function zoomButton(name, title, factor) {
1470
1520
  const button = iconButton(name, title, {}, true);
1471
1521
  button.addEventListener("click", () => {
1472
1522
  const box = frame.getBoundingClientRect();
1473
1523
  zoomAt(factor, box.width / 2, box.height / 2);
1474
1524
  });
1475
1525
  return button;
1476
- };
1526
+ }
1477
1527
  const fitButton = iconButton("fit", "Fit the graph in view", {}, true);
1478
1528
  fitButton.addEventListener("click", fit);
1479
1529
  frame.append(element("div", { class: "zoom" }, zoomButton("minus", "Zoom out", 1 / 1.2), zoomButton("plus", "Zoom in", 1.2), fitButton));
@@ -1481,9 +1531,20 @@ function togglePanel(root, state, initial = "overview") {
1481
1531
  if (graphNode !== void 0 && graphNode < nodes.length) {
1482
1532
  const node = nodes[graphNode];
1483
1533
  const part = parts[graphNode];
1484
- const list = (indexes) => indexes.length > 0 ? element("div", {}, ...indexes.map((index) => element("div", { class: "mono" }, nodes[index].label))) : element("div", { class: "sub" }, "nothing");
1534
+ function list(indexes) {
1535
+ if (indexes.length === 0) return element("div", { class: "sub" }, "nothing");
1536
+ const labels = [];
1537
+ for (const index of indexes) labels.push(element("div", { class: "mono" }, nodes[index].label));
1538
+ return element("div", {}, ...labels);
1539
+ }
1540
+ const reads = [];
1541
+ const readBy = [];
1542
+ for (const [from, to] of edges) {
1543
+ if (to === graphNode) reads.push(from);
1544
+ if (from === graphNode) readBy.push(to);
1545
+ }
1485
1546
  const color = nodeColor(node.kind, node.slot);
1486
- side.append(element("h2", {}, part.name), element("div", { class: "toolbar" }, pill(node.kind, color), part.at ? source(info, part.at) : ""), ...part.value === void 0 ? [] : [element("h3", {}, "Value"), element("div", { class: "mono" }, part.value)], element("h3", {}, "Reads"), list(edges.filter(([, to]) => to === graphNode).map(([from]) => from)), element("h3", {}, "Read by"), list(edges.filter(([from]) => from === graphNode).map(([, to]) => to)));
1547
+ side.append(element("h2", {}, part.name), element("div", { class: "toolbar" }, pill(node.kind, color), part.at ? source(info, part.at) : ""), ...part.value === void 0 ? [] : [element("h3", {}, "Value"), element("div", { class: "mono" }, part.value)], element("h3", {}, "Reads"), list(reads), element("h3", {}, "Read by"), list(readBy));
1487
1548
  } else side.append(element("h2", {}, info.name), element("p", {
1488
1549
  class: "sub",
1489
1550
  style: "margin-top: 0"
@@ -1507,8 +1568,8 @@ function togglePanel(root, state, initial = "overview") {
1507
1568
  clearTimeout(cooling);
1508
1569
  cooling = setTimeout(() => state.changed?.(), HOT_MS);
1509
1570
  }
1510
- };
1511
- const drawLog = () => {
1571
+ }
1572
+ function drawLog() {
1512
1573
  const filters = element("div", { class: "toolbar filters" });
1513
1574
  for (const kind of KINDS) {
1514
1575
  const box = element("input", { type: "checkbox" });
@@ -1547,63 +1608,28 @@ function togglePanel(root, state, initial = "overview") {
1547
1608
  });
1548
1609
  filters.append(search, pause, clear);
1549
1610
  const needle = logSearch.trim().toLowerCase();
1550
- const entries = (frozen ?? state.log).filter((entry) => shown.has(entry.kind) && (!needle || textOf(entry).toLowerCase().includes(needle)));
1611
+ const entries = [];
1612
+ for (const entry of frozen ?? state.log) if (shown.has(entry.kind) && (!needle || readText(entry).toLowerCase().includes(needle))) entries.push(entry);
1551
1613
  const list = element("table", { class: "rows" });
1552
1614
  for (const entry of entries.toReversed()) list.append(element("tr", { class: `entry ${entry.kind}` }, element("td", { class: "time" }, seconds(entry.time)), element("td", {
1553
1615
  class: `kind-${entry.kind}`,
1554
1616
  style: "width: 1%"
1555
- }, entry.kind), element("td", {}, textOf(entry))));
1617
+ }, entry.kind), element("td", {}, readText(entry))));
1556
1618
  body.replaceChildren(filters, entries.length > 0 ? list : element("div", { class: "empty" }, "Nothing to show."));
1557
- };
1558
- const drawLoading = async () => {
1559
- const loads = [...state.loads.values()].toSorted((a, b) => a.start - b.start);
1560
- await Promise.all([...new Set(loads.map((load) => load.component))].map((id) => componentInfo(state, id)));
1561
- const unused = loads.filter((load) => PRELOADS.has(load.reason) && !load.used).length;
1562
- const end = Math.max(1, ...loads.map((load) => load.end ?? performance.now()));
1563
- const total = codeBytes(state);
1564
- const table = element("table", { class: "rows" }, row([
1565
- "component",
1566
- "part",
1567
- "why",
1568
- "took",
1569
- "size",
1570
- `when, 0 to ${seconds(end)}`
1571
- ], "th"));
1572
- for (const load of loads) {
1573
- const info = known.get(load.component);
1574
- let marks = PRELOADS.has(load.reason) && !load.used ? "unused" : "";
1575
- if (load.failed) marks = "failed";
1576
- const stop = load.end ?? performance.now();
1577
- const bytes = bytesOf(info, load.part);
1578
- const tr = element("tr", {}, element("td", {}, info?.name ?? load.component), element("td", { class: "mono" }, load.part), element("td", {}, pill(load.reason, reasonColor(load.reason))), element("td", { class: "mono" }, load.end === void 0 ? "…" : ms(load.end - load.start)), element("td", { class: "mono" }, bytes ? kilobytes(bytes) : ""), element("td", { class: "bar-cell" }, element("div", { class: "bar-track" }, element("span", {
1579
- class: `bar ${barClass(load)}`,
1580
- style: `left:${load.start / end * 100}%;width:${(stop - load.start) / end * 100}%`,
1581
- title: `${seconds(load.start)} to ${seconds(stop)}`
1582
- }))));
1583
- if (marks) {
1584
- tr.className = marks;
1585
- tr.title = marks === "unused" ? "Preloaded, and nothing has run it yet" : "It failed to load";
1586
- }
1587
- table.append(tr);
1619
+ }
1620
+ async function drawState() {
1621
+ const scopes = [];
1622
+ const ids = /* @__PURE__ */ new Set();
1623
+ for (const scope of state.scopes?.values() ?? []) if (typeof scope.id !== "number" || scope.id >= 0) {
1624
+ scopes.push(scope);
1625
+ const id = findRootScope(scope).m ?? "";
1626
+ if (id) ids.add(id);
1588
1627
  }
1589
- body.replaceChildren(element("div", { class: "cards" }, card("Parts loaded", String(loads.length), total ? `${kilobytes(total)} from the dev server` : "sizes come with the requests"), card("Unused preloads", String(unused), "loaded, and nothing ran them yet")), element("div", {
1590
- class: "legend",
1591
- style: "margin: 10px 0 6px"
1592
- }, key("var(--blue)", "event or block"), key("var(--purple)", "preload"), element("span", {}, element("i", { style: "background: repeating-linear-gradient(45deg, var(--purple) 0 2px, transparent 2px 4px); box-shadow: inset 0 0 0 1px var(--purple)" }), "unused preload"), key("var(--faint)", "a write, state and others"), element("span", { class: "sub" }, "Sizes are of the dev server, which does not minify.")), loads.length > 0 ? table : element("div", { class: "empty" }, "No code loaded yet."));
1593
- };
1594
- /**
1595
- * The values that the page state sends, by the slot that holds them, with
1596
- * about how many bytes each takes and the client code that reads it, which
1597
- * is why it is sent.
1598
- */
1599
- const drawState = async () => {
1600
- const scopes = [...state.scopes?.values() ?? []].filter((scope) => typeof scope.id !== "number" || scope.id >= 0);
1601
- const ids = [...new Set(scopes.map((scope) => rootOf(scope).m ?? ""))].filter(Boolean);
1602
- await Promise.all(ids.map((id) => componentInfo(state, id)));
1628
+ await loadComponents(state, ids);
1603
1629
  const slots = /* @__PURE__ */ new Map();
1604
1630
  for (const scope of scopes) {
1605
- const component = rootOf(scope).m ?? "";
1606
- scope.s.forEach((value, slot) => {
1631
+ const component = findRootScope(scope).m ?? "";
1632
+ for (const [slot, value] of scope.s.entries()) {
1607
1633
  const key = `${component}:${scope.k}:${slot}`;
1608
1634
  const entry = slots.get(key) ?? {
1609
1635
  component,
@@ -1612,10 +1638,10 @@ function togglePanel(root, state, initial = "overview") {
1612
1638
  bytes: 0,
1613
1639
  count: 0
1614
1640
  };
1615
- entry.bytes += sizeOf(value);
1641
+ entry.bytes += measureSize(value);
1616
1642
  entry.count++;
1617
1643
  slots.set(key, entry);
1618
- });
1644
+ }
1619
1645
  }
1620
1646
  const sorted = [...slots.values()].toSorted((a, b) => b.bytes - a.bytes);
1621
1647
  const first = document.querySelector("script[b-state][b-scopes]")?.textContent?.length ?? 0;
@@ -1645,13 +1671,19 @@ function togglePanel(root, state, initial = "overview") {
1645
1671
  class: "legend",
1646
1672
  style: "margin: 10px 0 6px"
1647
1673
  }, element("span", { class: "sub" }, "A value is sent because code in the browser reads it. Sizes are about what the state takes, and a value of many instances adds them up.")), slots.size > 0 ? table : element("div", { class: "empty" }, "The page sent no state."));
1648
- };
1674
+ }
1649
1675
  /** The effects and `$client` callbacks, with how often each ran and when its cleanup ran. */
1650
- const drawEffects = async () => {
1676
+ async function drawEffects() {
1651
1677
  const effects = [...state.effects.values()];
1652
- await Promise.all([...new Set(effects.map((effect) => effect.component))].map((id) => componentInfo(state, id)));
1678
+ const ids = /* @__PURE__ */ new Set();
1679
+ for (const effect of effects) ids.add(effect.component);
1680
+ await loadComponents(state, ids);
1653
1681
  const now = performance.now();
1654
- const lastSecond = (recent) => recent.filter((at) => now - at < 1e3).length;
1682
+ function lastSecond(recent) {
1683
+ let count = 0;
1684
+ for (const at of recent) if (now - at < 1e3) count++;
1685
+ return count;
1686
+ }
1655
1687
  const sorted = effects.toSorted((a, b) => lastSecond(b.recent) - lastSecond(a.recent) || b.runs - a.runs);
1656
1688
  const table = element("table", { class: "rows" }, row([
1657
1689
  "component",
@@ -1677,16 +1709,25 @@ function togglePanel(root, state, initial = "overview") {
1677
1709
  }
1678
1710
  table.append(tr);
1679
1711
  }
1680
- const active = effects.filter((effect) => effect.active).length;
1681
- body.replaceChildren(element("div", { class: "cards" }, card("Active", String(active), `of ${effects.length} that ran`), card("Runs", String(effects.reduce((sum, effect) => sum + effect.runs, 0)), "since the page loaded"), card("Busy", String(effects.filter((effect) => lastSecond(effect.recent) >= 10).length), "ran 10 times or more in the last second")), effects.length > 0 ? table : element("div", { class: "empty" }, "No effect or $client callback has run yet."));
1682
- };
1712
+ let active = 0;
1713
+ let runs = 0;
1714
+ let busy = 0;
1715
+ for (const effect of effects) {
1716
+ if (effect.active) active++;
1717
+ runs += effect.runs;
1718
+ if (lastSecond(effect.recent) >= 10) busy++;
1719
+ }
1720
+ body.replaceChildren(element("div", { class: "cards" }, card("Active", String(active), `of ${effects.length} that ran`), card("Runs", String(runs), "since the page loaded"), card("Busy", String(busy), "ran 10 times or more in the last second")), effects.length > 0 ? table : element("div", { class: "empty" }, "No effect or $client callback has run yet."));
1721
+ }
1683
1722
  /**
1684
1723
  * The client navigations of the page, newest first: the routes that
1685
1724
  * stayed, those that were replaced, or the whole page, and how far the
1686
1725
  * IDs of the new page moved.
1687
1726
  */
1688
- const drawNavigation = async () => {
1689
- const items = state.navigations.toReversed().map((navigation) => {
1727
+ async function drawNavigation() {
1728
+ const list = state.navigations.toReversed();
1729
+ const items = [];
1730
+ for (const navigation of list) {
1690
1731
  const path = new URL(navigation.url).pathname + new URL(navigation.url).search;
1691
1732
  const routes = element("div", { class: "routes" });
1692
1733
  if (navigation.full) routes.append(element("div", { class: "sub" }, navigation.kind === "form" ? "The whole page: a form changes what can show anywhere on it." : "The whole page: its root route or its layouts did not match the page before."));
@@ -1694,17 +1735,17 @@ function togglePanel(root, state, initial = "overview") {
1694
1735
  for (const key of navigation.kept) routes.append(element("div", { class: "mono" }, pill("kept", "green"), " ", key));
1695
1736
  for (const change of navigation.replaced) routes.append(element("div", { class: "mono" }, pill("replaced", "yellow"), ` ${change.slot}: ${change.from} → ${change.to}`));
1696
1737
  }
1697
- return element("div", { class: "navigation" }, element("div", { class: "toolbar" }, element("span", { class: "mono" }, path), pill(navigation.kind, navigation.kind === "form" ? "purple" : "blue"), element("span", { class: "sub" }, `${ms(navigation.time)} until the page changed`), navigation.shift === void 0 ? "" : element("span", { class: "sub" }, `IDs moved by ${navigation.shift}`)), routes);
1698
- });
1738
+ items.push(element("div", { class: "navigation" }, element("div", { class: "toolbar" }, element("span", { class: "mono" }, path), pill(navigation.kind, navigation.kind === "form" ? "purple" : "blue"), element("span", { class: "sub" }, `${ms(navigation.time)} until the page changed`), navigation.shift === void 0 ? "" : element("span", { class: "sub" }, `IDs moved by ${navigation.shift}`)), routes));
1739
+ }
1699
1740
  body.replaceChildren(...items.length > 0 ? items : [element("div", { class: "empty" }, "No client navigation yet. Follow a link of the page to see what it keeps.")]);
1700
- };
1741
+ }
1701
1742
  /**
1702
1743
  * What the server did for the last page that loaded: the render until the
1703
1744
  * page could stream, each memo that loaded and each server function call,
1704
1745
  * each `#loading` body, and the rest of the stream, on one scale. The
1705
1746
  * server writes it at the end of the page, in development.
1706
1747
  */
1707
- const drawServer = async () => {
1748
+ async function drawServer() {
1708
1749
  const script = [...document.querySelectorAll("script[b-trace]")].at(-1);
1709
1750
  let trace;
1710
1751
  try {
@@ -1717,7 +1758,8 @@ function togglePanel(root, state, initial = "overview") {
1717
1758
  return;
1718
1759
  }
1719
1760
  const entries = trace.entries.toSorted((a, b) => a.start - b.start);
1720
- const total = Math.max(1, ...entries.map((entry) => entry.end ?? entry.start));
1761
+ let total = 1;
1762
+ for (const entry of entries) total = Math.max(total, entry.end ?? entry.start);
1721
1763
  const table = element("table", { class: "rows" }, row([
1722
1764
  "step",
1723
1765
  "what",
@@ -1734,23 +1776,33 @@ function togglePanel(root, state, initial = "overview") {
1734
1776
  if (entry.failed) tr.className = "failed";
1735
1777
  table.append(tr);
1736
1778
  }
1737
- const render = entries.find((entry) => entry.kind === "render");
1738
- const count = (kind) => entries.filter((entry) => entry.kind === kind).length;
1779
+ let render;
1780
+ const counts = /* @__PURE__ */ new Map();
1781
+ for (const entry of entries) {
1782
+ if (entry.kind === "render" && !render) render = entry;
1783
+ counts.set(entry.kind, (counts.get(entry.kind) ?? 0) + 1);
1784
+ }
1785
+ function count(kind) {
1786
+ return counts.get(kind) ?? 0;
1787
+ }
1739
1788
  body.replaceChildren(element("div", { class: "cards" }, card("Until it streamed", render?.end === void 0 ? "…" : ms(render.end), `the render of ${trace.route}`), card("Whole page", ms(total), "until the last body streamed"), card("Memos that loaded", String(count("memo")), `${count("call")} server function calls`), card("Bodies", String(count("body")), "#loading bodies that streamed")), element("div", {
1740
1789
  class: "legend",
1741
1790
  style: "margin: 10px 0 6px"
1742
1791
  }, key("var(--accent)", "render"), key("var(--green)", "memo"), key("var(--blue)", "server function call"), key("var(--purple)", "#loading body"), key("var(--faint)", "the rest of the stream"), element("span", { class: "sub" }, "Of the last page that the dev server rendered.")), table);
1743
- };
1744
- const drawTimeline = async () => {
1792
+ }
1793
+ async function drawTimeline() {
1745
1794
  const runs = state.timeline.toReversed().slice(0, 40);
1746
- await Promise.all([...new Set(runs.map((run) => run.ref.split("#")[0]))].map((id) => componentInfo(state, id)));
1795
+ const ids = /* @__PURE__ */ new Set();
1796
+ for (const run of runs) ids.add(run.ref.split("#")[0]);
1797
+ await loadComponents(state, ids);
1747
1798
  if (runs.length === 0) {
1748
1799
  body.replaceChildren(element("h2", {}, "Timeline"), element("p", { class: "sub" }, "Each handler that runs shows here, with the time its code took to load, its own run, the server functions it called and the updates that followed."));
1749
1800
  return;
1750
1801
  }
1751
1802
  const now = performance.now();
1752
- const totals = runs.map((run) => (run.settled ?? now) - run.begun);
1753
- const segment = (run, scale, start, end, kind, title) => {
1803
+ const totals = [];
1804
+ for (const run of runs) totals.push((run.settled ?? now) - run.begun);
1805
+ function segment(run, scale, start, end, kind, title) {
1754
1806
  const left = Math.min(Math.max((start - run.begun) / scale * 100, 0), 100);
1755
1807
  const width = Math.min(Math.max((end - start) / scale * 100, 0), 100 - left);
1756
1808
  return element("span", {
@@ -1758,11 +1810,13 @@ function togglePanel(root, state, initial = "overview") {
1758
1810
  style: `left:${left}%;width:${width}%`,
1759
1811
  title
1760
1812
  });
1761
- };
1813
+ }
1762
1814
  const list = element("div");
1763
- runs.forEach((run, index) => {
1815
+ for (const [index, run] of runs.entries()) {
1764
1816
  const total = totals[index];
1765
- const last = Math.max(run.settled ?? now, ...run.calls.map((call) => call.end ?? now), ...run.updates.map((update) => update.end));
1817
+ let last = run.settled ?? now;
1818
+ for (const call of run.calls) last = Math.max(last, call.end ?? now);
1819
+ for (const update of run.updates) last = Math.max(last, update.end);
1766
1820
  const step = tickStep(Math.max(last - run.begun, 1) / 4);
1767
1821
  const scale = Math.ceil(Math.max(last - run.begun, 1) / step) * step;
1768
1822
  const ticks = element("div", { class: "ruler" });
@@ -1795,29 +1849,40 @@ function togglePanel(root, state, initial = "overview") {
1795
1849
  }, ...parts), element("span", { class: "took" }, call.end === void 0 ? "…" : `${ms(end - call.start)}${call.server === void 0 ? "" : ` (${ms(call.server)})`}`)));
1796
1850
  }
1797
1851
  if (run.updates.length > 0) {
1798
- const count = run.updates.reduce((sum, update) => sum + update.count, 0);
1799
- const took = run.updates.reduce((sum, update) => sum + update.end - update.start, 0);
1852
+ let count = 0;
1853
+ let took = 0;
1854
+ const updateSegments = [];
1855
+ for (const update of run.updates) {
1856
+ count += update.count;
1857
+ took += update.end - update.start;
1858
+ updateSegments.push(segment(run, scale, update.start, update.end, "update", `${update.count} ${update.count === 1 ? "update" : "updates"} and their effects: ${ms(update.end - update.start)}`));
1859
+ }
1800
1860
  const batches = run.updates.length;
1801
1861
  rows.push(element("div", { class: "run-row" }, element("span", { class: "name" }, `${count} ${count === 1 ? "update" : "updates"}${batches > 1 ? `, ${batches} batches` : ""}`), element("div", {
1802
1862
  class: "track",
1803
1863
  style: grid
1804
- }, ...run.updates.map((update) => segment(run, scale, update.start, update.end, "update", `${update.count} ${update.count === 1 ? "update" : "updates"} and their effects: ${ms(update.end - update.start)}`))), element("span", { class: "took" }, ms(took))));
1864
+ }, ...updateSegments), element("span", { class: "took" }, ms(took))));
1805
1865
  }
1806
1866
  const speed = speedColor(total);
1807
1867
  list.append(element("div", { class: "interaction" }, element("div", { class: "run-head" }, element("span", { class: "what" }, run.label), element("span", { class: "ref" }, handlerName(run.ref)), element("span", { class: "spacer" }), run.failed ? pill("failed", "red") : "", pill(run.settled === void 0 ? "running" : ms(total), run.settled === void 0 ? "blue" : speed), element("span", { class: "sub" }, seconds(run.begun))), ...rows));
1808
- });
1809
- const settled = totals.filter((_, index) => runs[index].settled !== void 0);
1868
+ }
1869
+ const settled = [];
1870
+ let callCount = 0;
1871
+ for (const [index, run] of runs.entries()) {
1872
+ if (run.settled !== void 0) settled.push(totals[index]);
1873
+ callCount += run.calls.length;
1874
+ }
1810
1875
  const clear = iconButton("trash", "Clear");
1811
1876
  clear.addEventListener("click", () => {
1812
1877
  state.timeline.length = 0;
1813
1878
  draw();
1814
1879
  });
1815
- body.replaceChildren(element("div", { class: "cards" }, card("Handlers", String(state.timeline.length), "the last 40 show here"), card("Slowest", settled.length > 0 ? ms(Math.max(...settled)) : "—", "from the event to the end of its promise"), card("Server calls", String(runs.reduce((sum, run) => sum + run.calls.length, 0)), "made by these handlers")), element("div", {
1880
+ body.replaceChildren(element("div", { class: "cards" }, card("Handlers", String(state.timeline.length), "the last 40 show here"), card("Slowest", settled.length > 0 ? ms(Math.max(...settled)) : "—", "from the event to the end of its promise"), card("Server calls", String(callCount), "made by these handlers")), element("div", {
1816
1881
  class: "toolbar",
1817
1882
  style: "margin-top: 8px"
1818
1883
  }, element("div", { class: "legend" }, element("span", {}, element("i", { style: "background: repeating-linear-gradient(45deg, var(--faint) 0 2px, transparent 2px 4px)" }), "waiting for code"), key("var(--blue)", "run"), key("#7cb7ff55", "its promise"), key("#ff9ecf88", "server call"), key("#ff9ecf", "on the server"), key("var(--green)", "updates")), element("span", { class: "spacer" }), clear), list);
1819
- };
1820
- const drawBlocks = () => {
1884
+ }
1885
+ function drawBlocks() {
1821
1886
  const blocks = [...state.blocks.values()];
1822
1887
  const table = element("table", { class: "rows" }, row([
1823
1888
  "block",
@@ -1866,19 +1931,18 @@ function togglePanel(root, state, initial = "overview") {
1866
1931
  class: "sub",
1867
1932
  style: "margin-top: 0"
1868
1933
  }, "Streaming bodies come with the page. Waiting ones wait for their trigger, and Fire runs it now. Fallback shows the fallback of a body again, to check both sides."), blocks.length > 0 ? table : element("div", { class: "empty" }, "No blocks that render later on this page."));
1869
- };
1870
- const drawReport = async () => {
1934
+ }
1935
+ async function drawReport() {
1871
1936
  const id = selected ?? roots()[0]?.m;
1872
1937
  const info = id ? await componentInfo(state, id) : void 0;
1873
1938
  body.replaceChildren(...info ? [element("div", { class: "toolbar" }, chooser(id), source(info)), element("pre", { class: "report" }, info.text)] : [element("div", { class: "empty" }, "No component yet.")]);
1874
- };
1939
+ }
1875
1940
  /** The draw of each tab that loads what it shows. Log and Blocks draw at once. */
1876
1941
  const drawTab = {
1877
1942
  overview: drawOverview,
1878
1943
  errors: drawErrors,
1879
1944
  scopes: drawScopes,
1880
1945
  elements: drawElements,
1881
- loading: drawLoading,
1882
1946
  state: drawState,
1883
1947
  effects: drawEffects,
1884
1948
  navigation: drawNavigation,
@@ -1888,7 +1952,7 @@ function togglePanel(root, state, initial = "overview") {
1888
1952
  report: drawReport
1889
1953
  };
1890
1954
  let queued = false;
1891
- const draw = () => {
1955
+ function draw() {
1892
1956
  drawChrome();
1893
1957
  if (tab === "log") {
1894
1958
  drawLog();
@@ -1907,7 +1971,7 @@ function togglePanel(root, state, initial = "overview") {
1907
1971
  drawChrome();
1908
1972
  if (tab === "scopes") state.written.clear();
1909
1973
  });
1910
- };
1974
+ }
1911
1975
  state.changed = () => {
1912
1976
  const typing = root.activeElement?.matches?.("input[type=\"search\"]");
1913
1977
  if (!queued && !editing && !typing && !(paused && tab === "log")) {
@@ -1927,4 +1991,4 @@ function togglePanel(root, state, initial = "overview") {
1927
1991
  //#endregion
1928
1992
  export { layoutGraph, openPanel, togglePanel };
1929
1993
 
1930
- //# sourceMappingURL=devtools-panel-BVB-W5q4.js.map
1994
+ //# sourceMappingURL=devtools-panel-C1Dfv6nq.js.map