aktion-runtime 0.5.9 → 0.5.10

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 (56) hide show
  1. package/README.md +196 -26
  2. package/dist/aktion.iife.js +877 -78
  3. package/dist/aktion.iife.js.map +1 -1
  4. package/dist/aktion.js +16394 -10312
  5. package/dist/aktion.js.map +1 -1
  6. package/dist/aktion.umd.cjs +877 -78
  7. package/dist/aktion.umd.cjs.map +1 -1
  8. package/dist/devtools.js +554 -20
  9. package/dist/devtools.js.map +1 -1
  10. package/dist/language.js +4883 -572
  11. package/dist/language.js.map +1 -1
  12. package/dist/plugin.cjs +2 -2
  13. package/dist/plugin.cjs.map +1 -1
  14. package/dist/plugin.js +2 -2
  15. package/dist/plugin.js.map +1 -1
  16. package/dist/system_prompt.txt +269 -20
  17. package/dist/system_prompt_chat.txt +3 -3
  18. package/dist/testing.js +15975 -7890
  19. package/dist/testing.js.map +1 -1
  20. package/dist/types/devtools/panel.d.ts +32 -0
  21. package/dist/types/devtools/styles.d.ts +1 -1
  22. package/dist/types/element.d.ts +26 -0
  23. package/dist/types/icons/index.d.ts +10 -0
  24. package/dist/types/library/components/_internal.d.ts +18 -0
  25. package/dist/types/library/components/a11y.d.ts +5 -0
  26. package/dist/types/library/components/canvas.d.ts +3 -0
  27. package/dist/types/library/components/extras.d.ts +15 -0
  28. package/dist/types/library/components/feedback.d.ts +1 -0
  29. package/dist/types/library/components/forms-shared.d.ts +55 -0
  30. package/dist/types/library/components/layout-motion.d.ts +14 -0
  31. package/dist/types/library/components/layout.d.ts +1 -0
  32. package/dist/types/library/components/marketing.d.ts +35 -0
  33. package/dist/types/library/components/new-components.d.ts +1 -0
  34. package/dist/types/library/components/scheduling.d.ts +2 -0
  35. package/dist/types/library/components/wave3.d.ts +6 -0
  36. package/dist/types/library/highlight.d.ts +21 -0
  37. package/dist/types/library/qr.d.ts +12 -0
  38. package/dist/types/library/responsive-style.d.ts +51 -0
  39. package/dist/types/library/sx.d.ts +51 -0
  40. package/dist/types/runtime/env.d.ts +33 -0
  41. package/dist/types/runtime/evaluator.d.ts +30 -0
  42. package/dist/types/runtime/http.d.ts +37 -1
  43. package/dist/types/runtime/index.d.ts +2 -0
  44. package/dist/types/runtime/namespaces-extra.d.ts +73 -0
  45. package/dist/types/runtime/realtime.d.ts +46 -0
  46. package/dist/types/runtime/router.d.ts +42 -4
  47. package/dist/types/runtime/ssr.d.ts +29 -0
  48. package/dist/types/runtime/util.d.ts +65 -0
  49. package/dist/types/testing/index.d.ts +35 -0
  50. package/dist/types/theme/fonts.d.ts +30 -0
  51. package/dist/types/theme/index.d.ts +28 -0
  52. package/dist/types/theme/styles.d.ts +1 -1
  53. package/dist/types/tooling/html-import.d.ts +19 -0
  54. package/dist/types/tooling/index.d.ts +3 -0
  55. package/dist/types/tooling/schema.d.ts +58 -0
  56. package/package.json +1 -1
package/dist/devtools.js CHANGED
@@ -477,6 +477,179 @@ table.dt-table tr:hover td { background: rgba(255,255,255,0.03); }
477
477
  }
478
478
  .filter-chip.is-on { color: var(--dt-text); border-color: var(--dt-border-strong); background: var(--dt-bg-raised); }
479
479
 
480
+ /* ---- Stat grid (perf / effect summaries) ---- */
481
+ .stat-grid {
482
+ display: grid;
483
+ grid-template-columns: repeat(auto-fit, minmax(78px, 1fr));
484
+ gap: 6px;
485
+ }
486
+ .stat {
487
+ display: flex;
488
+ flex-direction: column;
489
+ gap: 1px;
490
+ padding: 6px 8px;
491
+ background: var(--dt-bg-inset);
492
+ border: 1px solid var(--dt-border);
493
+ border-radius: 7px;
494
+ }
495
+ .stat.is-link { cursor: pointer; }
496
+ .stat.is-link:hover { border-color: var(--dt-accent); }
497
+ .stat-val {
498
+ font-family: var(--dt-mono);
499
+ font-size: 14px;
500
+ font-weight: 700;
501
+ color: var(--dt-text);
502
+ font-variant-numeric: tabular-nums;
503
+ }
504
+ .stat-val.t-warn { color: var(--dt-amber); }
505
+ .stat-val.t-good { color: var(--dt-green); }
506
+ .stat-val.t-bad { color: var(--dt-red); }
507
+ .stat-label {
508
+ font-size: 9.5px;
509
+ text-transform: uppercase;
510
+ letter-spacing: 0.5px;
511
+ color: var(--dt-text-faint);
512
+ }
513
+
514
+ /* ---- Horizontal bar rows (hot atoms) ---- */
515
+ .bar-row {
516
+ display: flex;
517
+ align-items: center;
518
+ gap: 8px;
519
+ padding: 2px 0;
520
+ font-size: 11px;
521
+ }
522
+ .bar-row-label {
523
+ flex: 0 0 34%;
524
+ font-family: var(--dt-mono);
525
+ color: var(--dt-purple);
526
+ overflow: hidden;
527
+ text-overflow: ellipsis;
528
+ white-space: nowrap;
529
+ }
530
+ .bar-row-track {
531
+ flex: 1;
532
+ height: 10px;
533
+ background: var(--dt-bg-inset);
534
+ border-radius: 3px;
535
+ overflow: hidden;
536
+ }
537
+ .bar-row-fill {
538
+ display: block;
539
+ height: 100%;
540
+ background: linear-gradient(90deg, var(--dt-accent-soft), var(--dt-accent));
541
+ border-radius: 3px;
542
+ }
543
+ .bar-row-num {
544
+ flex: 0 0 auto;
545
+ font-family: var(--dt-mono);
546
+ color: var(--dt-text-dim);
547
+ font-size: 10px;
548
+ font-variant-numeric: tabular-nums;
549
+ }
550
+
551
+ /* ---- Insights ---- */
552
+ .insights { display: flex; flex-direction: column; gap: 5px; }
553
+ .insight {
554
+ display: flex;
555
+ gap: 7px;
556
+ align-items: flex-start;
557
+ font-size: 11px;
558
+ line-height: 1.4;
559
+ padding: 6px 8px;
560
+ border-radius: 7px;
561
+ border: 1px solid var(--dt-border);
562
+ background: var(--dt-bg-inset);
563
+ color: var(--dt-text-dim);
564
+ }
565
+ .insight-ic { flex: 0 0 auto; font-weight: 700; }
566
+ .insight.t-warn { border-color: rgba(240,179,94,0.4); }
567
+ .insight.t-warn .insight-ic { color: var(--dt-amber); }
568
+ .insight.t-bad { border-color: rgba(248,113,113,0.4); }
569
+ .insight.t-bad .insight-ic { color: var(--dt-red); }
570
+ .insight.t-good .insight-ic { color: var(--dt-green); }
571
+
572
+ /* ---- Reactivity heat badge (state tree) ---- */
573
+ .row .grow { flex: 1; min-width: 8px; }
574
+ .heat { display: inline-flex; align-items: center; gap: 5px; flex: 0 0 auto; }
575
+ .heat-bar {
576
+ width: 40px;
577
+ height: 5px;
578
+ border-radius: 3px;
579
+ background: var(--dt-bg-inset);
580
+ overflow: hidden;
581
+ }
582
+ .heat-fill {
583
+ display: block;
584
+ height: 100%;
585
+ background: linear-gradient(90deg, var(--dt-blue), var(--dt-amber));
586
+ }
587
+ .heat-num {
588
+ font-family: var(--dt-mono);
589
+ font-size: 9.5px;
590
+ color: var(--dt-text-faint);
591
+ min-width: 18px;
592
+ text-align: right;
593
+ }
594
+
595
+ /* ---- Sortable table headers ---- */
596
+ table.dt-table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
597
+ table.dt-table th.sortable:hover { color: var(--dt-text-dim); }
598
+
599
+ /* ---- Effect visual timeline ---- */
600
+ .tl-head {
601
+ display: flex;
602
+ align-items: center;
603
+ justify-content: space-between;
604
+ padding: 8px 10px 4px;
605
+ }
606
+ .tl-axis {
607
+ position: relative;
608
+ flex: 0 0 120px;
609
+ font-family: var(--dt-mono);
610
+ font-size: 9px;
611
+ color: var(--dt-text-faint);
612
+ }
613
+ .tl-axis-end { float: right; }
614
+ .tl-row {
615
+ display: flex;
616
+ align-items: center;
617
+ gap: 8px;
618
+ padding: 3px 10px;
619
+ border-bottom: 1px solid rgba(43,47,56,0.4);
620
+ }
621
+ .tl-name {
622
+ flex: 0 0 38%;
623
+ font-family: var(--dt-mono);
624
+ font-size: 10.5px;
625
+ color: var(--dt-text-dim);
626
+ overflow: hidden;
627
+ text-overflow: ellipsis;
628
+ white-space: nowrap;
629
+ }
630
+ .tl-track {
631
+ position: relative;
632
+ flex: 1;
633
+ height: 16px;
634
+ background: var(--dt-bg-inset);
635
+ border-radius: 4px;
636
+ }
637
+ .tl-dot {
638
+ position: absolute;
639
+ top: 50%;
640
+ width: 8px;
641
+ height: 8px;
642
+ margin-top: -4px;
643
+ margin-left: -4px;
644
+ border-radius: 50%;
645
+ box-shadow: 0 0 0 1px var(--dt-bg-inset);
646
+ }
647
+ .tl-dot.green { background: var(--dt-green); }
648
+ .tl-dot.blue { background: var(--dt-blue); }
649
+ .tl-dot.purple { background: var(--dt-purple); }
650
+ .tl-dot.grey { background: var(--dt-grey); }
651
+ .tl-dot.red { background: var(--dt-red); }
652
+
480
653
  /* ---- Resize grip ---- */
481
654
  .resize {
482
655
  position: absolute;
@@ -495,7 +668,7 @@ const MAX_COMMITS = 200;
495
668
  const MAX_EFFECT_EVENTS = 400;
496
669
  const FLASH_MS = 1100;
497
670
  function emptyModel() {
498
- return { commits: [], effects: [], state: {}, changed: /* @__PURE__ */ new Map(), firstTime: null };
671
+ return { commits: [], effects: [], state: {}, changed: /* @__PURE__ */ new Map(), changeCounts: /* @__PURE__ */ new Map(), firstTime: null };
499
672
  }
500
673
  function h(tag, attrs = {}, ...children) {
501
674
  const node = document.createElement(tag);
@@ -569,6 +742,14 @@ function fmtRel(ms) {
569
742
  if (ms >= 1e4) return `${(ms / 1e3).toFixed(1)} s`;
570
743
  return `${ms.toFixed(0)} ms`;
571
744
  }
745
+ function fmtCount(n) {
746
+ if (n >= 1e4) return `${(n / 1e3).toFixed(1)}k`;
747
+ return String(n);
748
+ }
749
+ function fmtPct(num, den) {
750
+ if (den <= 0) return "—";
751
+ return `${Math.round(num / den * 100)}%`;
752
+ }
572
753
  const PHASE_CHIP = {
573
754
  mount: "green",
574
755
  update: "blue",
@@ -592,11 +773,17 @@ class AktionDevtoolsElement extends HTMLElement {
592
773
  __publicField(this, "stateFilter", "");
593
774
  __publicField(this, "expanded", /* @__PURE__ */ new Set());
594
775
  __publicField(this, "editingPath", null);
776
+ /** Sort atoms by change frequency (reactivity heat) instead of name. */
777
+ __publicField(this, "stateSortByActivity", false);
595
778
  // Profiler tab
596
779
  __publicField(this, "selectedCommitId", null);
597
780
  __publicField(this, "flashOnCommit", false);
781
+ /** Sort key + direction for the ranked-components table. */
782
+ __publicField(this, "rankedSort", { key: "total", dir: -1 });
598
783
  // Effects tab
599
784
  __publicField(this, "phaseFilter", /* @__PURE__ */ new Set(["mount", "run", "cleanup", "unmount", "error"]));
785
+ /** Group the effect timeline into per-effect lanes vs. a flat log. */
786
+ __publicField(this, "effectView", "timeline");
600
787
  // chrome
601
788
  __publicField(this, "collapsed", false);
602
789
  __publicField(this, "renderScheduled", false);
@@ -712,7 +899,9 @@ class AktionDevtoolsElement extends HTMLElement {
712
899
  case "state": {
713
900
  model.state = event.snapshot;
714
901
  for (const p of event.changedPaths) {
715
- model.changed.set(rootOf(p), event.time);
902
+ const root = rootOf(p);
903
+ model.changed.set(root, event.time);
904
+ model.changeCounts.set(root, (model.changeCounts.get(root) ?? 0) + 1);
716
905
  }
717
906
  break;
718
907
  }
@@ -870,6 +1059,7 @@ class AktionDevtoolsElement extends HTMLElement {
870
1059
  /* State inspector */
871
1060
  /* ---------------------------------------------------------------------- */
872
1061
  renderStateTab(app, model) {
1062
+ const totalChanges = [...model.changeCounts.values()].reduce((a, b) => a + b, 0);
873
1063
  const toolbar = h(
874
1064
  "div",
875
1065
  { class: "toolbar" },
@@ -882,7 +1072,15 @@ class AktionDevtoolsElement extends HTMLElement {
882
1072
  this.renderTreeOnly(app, model);
883
1073
  }
884
1074
  }),
885
- h("span", { class: "muted" }, `${Object.keys(model.state).length} atoms`)
1075
+ h("button", {
1076
+ class: `filter-chip ${this.stateSortByActivity ? "is-on" : ""}`,
1077
+ title: "Sort atoms by how often they change (reactivity heat)",
1078
+ onclick: () => {
1079
+ this.stateSortByActivity = !this.stateSortByActivity;
1080
+ this.renderTreeOnly(app, model);
1081
+ }
1082
+ }, "Sort by activity"),
1083
+ h("span", { class: "muted" }, `${Object.keys(model.state).length} atoms · ${fmtCount(totalChanges)} changes`)
886
1084
  );
887
1085
  const tree = h("div", { class: "tree" });
888
1086
  this.fillTree(tree, app, model);
@@ -897,25 +1095,35 @@ class AktionDevtoolsElement extends HTMLElement {
897
1095
  }
898
1096
  fillTree(tree, app, model) {
899
1097
  const filter = this.stateFilter.trim().toLowerCase();
900
- const names = Object.keys(model.state).sort((a, b) => a.localeCompare(b));
1098
+ const maxChanges = Math.max(1, ...model.changeCounts.values());
1099
+ const names = Object.keys(model.state).sort((a, b) => {
1100
+ if (this.stateSortByActivity) {
1101
+ const ca = model.changeCounts.get(a) ?? 0;
1102
+ const cb = model.changeCounts.get(b) ?? 0;
1103
+ if (cb !== ca) return cb - ca;
1104
+ }
1105
+ return a.localeCompare(b);
1106
+ });
901
1107
  const now = typeof performance !== "undefined" ? performance.now() : Date.now();
902
1108
  let shown = 0;
903
1109
  for (const name of names) {
904
1110
  if (filter && !name.toLowerCase().includes(filter)) continue;
905
1111
  shown += 1;
906
- this.appendRow(tree, app, model, name, name, model.state[name], 0, now);
1112
+ this.appendRow(tree, app, model, name, name, model.state[name], 0, now, maxChanges);
907
1113
  }
908
1114
  if (shown === 0) {
909
1115
  tree.appendChild(h("div", { class: "empty" }, filter ? "No atoms match the filter." : "No reactive state yet."));
910
1116
  }
911
1117
  }
912
- appendRow(container, app, model, path, key, value, depth, now) {
1118
+ appendRow(container, app, model, path, key, value, depth, now, maxChanges) {
913
1119
  const type = valueType(value);
914
1120
  const expandable = isExpandable(value);
915
1121
  const isOpen = this.expanded.has(path);
916
1122
  const reserved = depth === 0 && RESERVED_ATOMS.has(key);
917
- const changedAt = model.changed.get(rootOf(path));
1123
+ const root = rootOf(path);
1124
+ const changedAt = model.changed.get(root);
918
1125
  const justChanged = changedAt != null && now - changedAt < FLASH_MS;
1126
+ const changeCount = depth === 0 ? model.changeCounts.get(root) ?? 0 : 0;
919
1127
  const twist = h("span", {
920
1128
  class: `twist ${expandable ? "" : "is-leaf"}`,
921
1129
  onclick: expandable ? () => {
@@ -930,6 +1138,19 @@ class AktionDevtoolsElement extends HTMLElement {
930
1138
  valueSpan.title = "Click to edit";
931
1139
  valueSpan.addEventListener("click", () => this.beginEdit(app, path, value, valueSpan));
932
1140
  }
1141
+ const heat = changeCount > 0 ? h(
1142
+ "span",
1143
+ {
1144
+ class: "heat",
1145
+ title: `${changeCount} change${changeCount === 1 ? "" : "s"} this session`
1146
+ },
1147
+ h(
1148
+ "span",
1149
+ { class: "heat-bar" },
1150
+ h("span", { class: "heat-fill", style: `width:${Math.max(8, Math.round(changeCount / maxChanges * 100))}%` })
1151
+ ),
1152
+ h("span", { class: "heat-num" }, fmtCount(changeCount))
1153
+ ) : null;
933
1154
  const row = h(
934
1155
  "div",
935
1156
  { class: `row ${justChanged ? "is-changed" : ""}`, style: `padding-left:${8 + depth * 14}px` },
@@ -937,12 +1158,14 @@ class AktionDevtoolsElement extends HTMLElement {
937
1158
  h("span", { class: "k" }, key),
938
1159
  h("span", { class: "sep" }, ": "),
939
1160
  valueSpan,
940
- reserved ? h("span", { class: "tag" }, "reserved") : null
1161
+ reserved ? h("span", { class: "tag" }, "reserved") : null,
1162
+ h("span", { class: "grow" }),
1163
+ heat
941
1164
  );
942
1165
  container.appendChild(row);
943
1166
  if (expandable && isOpen) {
944
1167
  for (const [childKey, childValue] of childEntries(value)) {
945
- this.appendRow(container, app, model, `${path}.${childKey}`, childKey, childValue, depth + 1, now);
1168
+ this.appendRow(container, app, model, `${path}.${childKey}`, childKey, childValue, depth + 1, now, maxChanges);
946
1169
  }
947
1170
  }
948
1171
  }
@@ -1035,9 +1258,148 @@ class AktionDevtoolsElement extends HTMLElement {
1035
1258
  }));
1036
1259
  }
1037
1260
  const selected = model.commits.find((c) => c.commitId === this.selectedCommitId) ?? last;
1261
+ const summary = this.renderPerfSummary(model);
1262
+ const insights = this.renderProfilerInsights(model);
1263
+ const hotAtoms = this.renderHotAtoms(model);
1038
1264
  const detail = this.renderCommitDetail(selected);
1039
1265
  const ranked = this.renderRankedComponents(model);
1040
- this.bodyEl.replaceChildren(toolbar, strip, detail, ranked);
1266
+ const sections = [toolbar, summary, strip, insights, detail, hotAtoms, ranked].filter((n) => n != null);
1267
+ this.bodyEl.replaceChildren(...sections);
1268
+ }
1269
+ /** A compact grid of headline performance numbers for the session. */
1270
+ renderPerfSummary(model) {
1271
+ const commits = model.commits;
1272
+ const totalTime = commits.reduce((a, c) => a + c.duration, 0);
1273
+ const avg = commits.length ? totalTime / commits.length : 0;
1274
+ const slowest = commits.reduce((m, c) => !m || c.duration > m.duration ? c : m, null);
1275
+ let rendered = 0, memoized = 0, fullRenders = 0;
1276
+ for (const c of commits) {
1277
+ rendered += c.rendered;
1278
+ memoized += c.memoized;
1279
+ if (c.fullRender) fullRenders += 1;
1280
+ }
1281
+ const first = commits[0];
1282
+ const lastCommit = commits[commits.length - 1];
1283
+ const span = first && lastCommit ? lastCommit.startTime - first.startTime : 0;
1284
+ const rate = span > 0 ? commits.length / (span / 1e3) : 0;
1285
+ const stat = (label, value, opts = {}) => h(
1286
+ "div",
1287
+ { class: `stat ${opts.onclick ? "is-link" : ""}`, title: opts.title, onclick: opts.onclick },
1288
+ h("span", { class: `stat-val ${opts.tone ? `t-${opts.tone}` : ""}` }, value),
1289
+ h("span", { class: "stat-label" }, label)
1290
+ );
1291
+ return h(
1292
+ "div",
1293
+ { class: "section" },
1294
+ h("p", { class: "section-title" }, "Performance summary"),
1295
+ h(
1296
+ "div",
1297
+ { class: "stat-grid" },
1298
+ stat("commits", fmtCount(commits.length)),
1299
+ stat("total render", fmtMs(totalTime)),
1300
+ stat("avg / commit", fmtMs(avg), { tone: avg >= 8 ? "warn" : void 0 }),
1301
+ slowest ? stat("slowest", fmtMs(slowest.duration), {
1302
+ tone: slowest.duration >= 16 ? "warn" : void 0,
1303
+ title: `Commit #${slowest.commitId} — click to inspect`,
1304
+ onclick: () => {
1305
+ this.selectedCommitId = slowest.commitId;
1306
+ this.scheduleRender();
1307
+ }
1308
+ }) : stat("slowest", "—"),
1309
+ stat("memoized", fmtPct(memoized, rendered + memoized), {
1310
+ tone: rendered + memoized > 0 && memoized / (rendered + memoized) < 0.2 ? "warn" : "good",
1311
+ title: `${fmtCount(memoized)} skipped / ${fmtCount(rendered + memoized)} component evaluations`
1312
+ }),
1313
+ stat("full renders", fmtCount(fullRenders), {
1314
+ tone: fullRenders > Math.max(1, commits.length * 0.5) ? "warn" : void 0,
1315
+ title: "Commits that bypassed memoization and re-evaluated the whole tree"
1316
+ }),
1317
+ rate > 0 ? stat("commit rate", `${rate.toFixed(1)}/s`, { tone: rate >= 30 ? "warn" : void 0 }) : null
1318
+ )
1319
+ );
1320
+ }
1321
+ /**
1322
+ * Reactivity insight: which `$state` paths triggered the most commits.
1323
+ * Surfaces the "hot" atoms driving re-renders so an author can see what
1324
+ * their UI actually reacts to.
1325
+ */
1326
+ renderHotAtoms(model) {
1327
+ const counts = /* @__PURE__ */ new Map();
1328
+ for (const c of model.commits) {
1329
+ for (const p of c.changedPaths) counts.set(p, (counts.get(p) ?? 0) + 1);
1330
+ }
1331
+ const rows = [...counts.entries()].sort((a, b) => b[1] - a[1]).slice(0, 8);
1332
+ const max = Math.max(1, ...rows.map(([, n]) => n));
1333
+ const body = rows.length ? h("div", {}, ...rows.map(([path, n]) => h(
1334
+ "div",
1335
+ { class: "bar-row" },
1336
+ h("span", { class: "bar-row-label" }, path),
1337
+ h(
1338
+ "span",
1339
+ { class: "bar-row-track" },
1340
+ h("span", { class: "bar-row-fill", style: `width:${Math.round(n / max * 100)}%` })
1341
+ ),
1342
+ h("span", { class: "bar-row-num" }, `${fmtCount(n)} commit${n === 1 ? "" : "s"}`)
1343
+ ))) : h("div", { class: "faint", style: "font-size:11px" }, "No state-driven commits yet (forced / initial only).");
1344
+ return h(
1345
+ "div",
1346
+ { class: "section" },
1347
+ h("p", { class: "section-title" }, "Reactivity — state paths that triggered commits"),
1348
+ body
1349
+ );
1350
+ }
1351
+ /**
1352
+ * Heuristic insights: surface likely performance problems derived from the
1353
+ * captured commits (frequent re-renders, heavy bodies, low memoization).
1354
+ */
1355
+ renderProfilerInsights(model) {
1356
+ const aggs = /* @__PURE__ */ new Map();
1357
+ for (const commit of model.commits) {
1358
+ for (const c of commit.components) {
1359
+ let a = aggs.get(c.name);
1360
+ if (!a) {
1361
+ a = { name: c.name, kind: c.kind, renders: 0, memo: 0, total: 0, max: 0 };
1362
+ aggs.set(c.name, a);
1363
+ }
1364
+ if (c.phase === "memo") a.memo += 1;
1365
+ else {
1366
+ a.renders += 1;
1367
+ a.total += c.selfTime;
1368
+ a.max = Math.max(a.max, c.selfTime);
1369
+ }
1370
+ }
1371
+ }
1372
+ const insights = [];
1373
+ const commitCount = model.commits.length;
1374
+ for (const a of aggs.values()) {
1375
+ if (a.renders === 0) continue;
1376
+ const avg = a.total / a.renders;
1377
+ if (avg >= 8) {
1378
+ insights.push({ tone: "warn", icon: "▲", text: `${a.name} averages ${fmtMs(avg)} per render — consider splitting or memoizing its work.` });
1379
+ }
1380
+ if (a.kind === "user" && a.renders >= 12 && a.memo === 0 && commitCount >= 4) {
1381
+ insights.push({ tone: "warn", icon: "↻", text: `${a.name} re-rendered ${fmtCount(a.renders)}× and was never memoized — check its $state reads.` });
1382
+ }
1383
+ }
1384
+ const fullAfterInitial = model.commits.filter((c) => c.fullRender && !c.initial).length;
1385
+ if (fullAfterInitial >= 3) {
1386
+ insights.push({ tone: "warn", icon: "⛶", text: `${fmtCount(fullAfterInitial)} commits forced a full re-render (memoization disabled) — often async/timer/effect notifies.` });
1387
+ }
1388
+ if (insights.length === 0 && commitCount > 0) {
1389
+ insights.push({ tone: "good", icon: "✓", text: "No render hot-spots detected. Component bodies are cheap and memoization is doing its job." });
1390
+ }
1391
+ if (insights.length === 0) return null;
1392
+ return h(
1393
+ "div",
1394
+ { class: "section" },
1395
+ h("p", { class: "section-title" }, "Insights"),
1396
+ h("div", { class: "insights" }, ...insights.slice(0, 6).map((i) => h(
1397
+ "div",
1398
+ { class: `insight t-${i.tone}` },
1399
+ h("span", { class: "insight-ic" }, i.icon),
1400
+ h("span", {}, i.text)
1401
+ )))
1402
+ );
1041
1403
  }
1042
1404
  renderCommitDetail(commit) {
1043
1405
  const trigger = commit.initial ? "initial mount" : commit.changedPaths.length > 0 ? commit.changedPaths.join(", ") : "forced (async / effect / timer)";
@@ -1098,30 +1460,63 @@ deps: ${c.deps.join(", ")}` : ""}`
1098
1460
  for (const c of commit.components) {
1099
1461
  let a = aggs.get(c.name);
1100
1462
  if (!a) {
1101
- a = { name: c.name, kind: c.kind, renders: 0, memo: 0, total: 0 };
1463
+ a = { name: c.name, kind: c.kind, renders: 0, memo: 0, total: 0, max: 0 };
1102
1464
  aggs.set(c.name, a);
1103
1465
  }
1104
1466
  if (c.phase === "memo") a.memo += 1;
1105
1467
  else {
1106
1468
  a.renders += 1;
1107
1469
  a.total += c.selfTime;
1470
+ a.max = Math.max(a.max, c.selfTime);
1108
1471
  }
1109
1472
  }
1110
1473
  }
1111
- const rows = [...aggs.values()].sort((a, b) => b.total - a.total);
1474
+ const sortKey = this.rankedSort.key;
1475
+ const dir = this.rankedSort.dir;
1476
+ const valueOf = (r) => {
1477
+ switch (sortKey) {
1478
+ case "name":
1479
+ return r.name;
1480
+ case "renders":
1481
+ return r.renders;
1482
+ case "memo":
1483
+ return r.memo;
1484
+ case "avg":
1485
+ return r.renders ? r.total / r.renders : 0;
1486
+ case "max":
1487
+ return r.max;
1488
+ default:
1489
+ return r.total;
1490
+ }
1491
+ };
1492
+ const rows = [...aggs.values()].sort((a, b) => {
1493
+ const va = valueOf(a), vb = valueOf(b);
1494
+ if (typeof va === "string" || typeof vb === "string") {
1495
+ return dir * String(va).localeCompare(String(vb));
1496
+ }
1497
+ return dir * (vb - va) * -1;
1498
+ });
1112
1499
  const maxTotal = Math.max(...rows.map((r) => r.total), 1e-3);
1500
+ const sortFor = (key) => () => {
1501
+ if (this.rankedSort.key === key) this.rankedSort.dir = this.rankedSort.dir === 1 ? -1 : 1;
1502
+ else this.rankedSort = { key, dir: key === "name" ? 1 : -1 };
1503
+ this.scheduleRender();
1504
+ };
1505
+ const arrow = (key) => sortKey === key ? dir === 1 ? " ▲" : " ▼" : "";
1506
+ const th = (key, label, right = false) => h("th", { class: "sortable", style: right ? "text-align:right" : "", onclick: sortFor(key) }, label + arrow(key));
1113
1507
  const table = h(
1114
1508
  "table",
1115
1509
  { class: "dt-table" },
1116
1510
  h("thead", {}, h(
1117
1511
  "tr",
1118
1512
  {},
1119
- h("th", {}, "Component"),
1513
+ th("name", "Component"),
1120
1514
  h("th", {}, "Type"),
1121
- h("th", { style: "text-align:right" }, "Renders"),
1122
- h("th", { style: "text-align:right" }, "Memo"),
1123
- h("th", { style: "text-align:right" }, "Total"),
1124
- h("th", { style: "text-align:right" }, "Avg")
1515
+ th("renders", "Renders", true),
1516
+ th("memo", "Memo", true),
1517
+ th("total", "Total", true),
1518
+ th("avg", "Avg", true),
1519
+ th("max", "Max", true)
1125
1520
  )),
1126
1521
  h("tbody", {}, ...rows.map(
1127
1522
  (r) => h(
@@ -1137,14 +1532,15 @@ deps: ${c.deps.join(", ")}` : ""}`
1137
1532
  h("span", { class: "barfill", style: `width:${Math.round(r.total / maxTotal * 100)}%` }),
1138
1533
  h("span", {}, fmtMs(r.total))
1139
1534
  ),
1140
- h("td", { class: "num" }, r.renders ? fmtMs(r.total / r.renders) : "—")
1535
+ h("td", { class: "num" }, r.renders ? fmtMs(r.total / r.renders) : "—"),
1536
+ h("td", { class: "num" }, r.renders ? fmtMs(r.max) : "—")
1141
1537
  )
1142
1538
  ))
1143
1539
  );
1144
1540
  return h(
1145
1541
  "div",
1146
1542
  { class: "section" },
1147
- h("p", { class: "section-title" }, "Components — ranked by total self time"),
1543
+ h("p", { class: "section-title" }, "Components — ranked by self time"),
1148
1544
  rows.length ? table : h("div", { class: "faint", style: "font-size:11px" }, "No component renders captured.")
1149
1545
  );
1150
1546
  }
@@ -1167,6 +1563,14 @@ deps: ${c.deps.join(", ")}` : ""}`
1167
1563
  }, p)
1168
1564
  )),
1169
1565
  h("div", { class: "grow" }),
1566
+ h("button", {
1567
+ class: `filter-chip ${this.effectView === "timeline" ? "is-on" : ""}`,
1568
+ title: "Toggle the visual timeline",
1569
+ onclick: () => {
1570
+ this.effectView = this.effectView === "timeline" ? "log" : "timeline";
1571
+ this.scheduleRender();
1572
+ }
1573
+ }, this.effectView === "timeline" ? "Timeline" : "Log"),
1170
1574
  h("button", {
1171
1575
  class: "icon-btn",
1172
1576
  title: "Clear effect events",
@@ -1185,7 +1589,137 @@ deps: ${c.deps.join(", ")}` : ""}`
1185
1589
  ));
1186
1590
  return;
1187
1591
  }
1188
- this.bodyEl.replaceChildren(toolbar, this.renderEffectLanes(model), this.renderEffectLog(model));
1592
+ const summary = this.renderEffectSummary(model);
1593
+ const insights = this.renderEffectInsights(model);
1594
+ const viz = this.effectView === "timeline" ? this.renderEffectTimeline(model) : this.renderEffectLog(model);
1595
+ const sections = [toolbar, summary, insights, this.renderEffectLanes(model), viz].filter((n) => n != null);
1596
+ this.bodyEl.replaceChildren(...sections);
1597
+ }
1598
+ /** Headline counters for the effect session. */
1599
+ renderEffectSummary(model) {
1600
+ const keys = /* @__PURE__ */ new Set();
1601
+ let runs = 0, total = 0, cleanups = 0, errors = 0;
1602
+ for (const e of model.effects) {
1603
+ keys.add(e.effectKey);
1604
+ if (e.phase === "run") {
1605
+ runs += 1;
1606
+ total += e.duration ?? 0;
1607
+ } else if (e.phase === "cleanup") cleanups += 1;
1608
+ else if (e.phase === "error") errors += 1;
1609
+ }
1610
+ const stat = (label, value, tone) => h(
1611
+ "div",
1612
+ { class: "stat" },
1613
+ h("span", { class: `stat-val ${tone ? `t-${tone}` : ""}` }, value),
1614
+ h("span", { class: "stat-label" }, label)
1615
+ );
1616
+ return h(
1617
+ "div",
1618
+ { class: "section" },
1619
+ h("p", { class: "section-title" }, "Effect summary"),
1620
+ h(
1621
+ "div",
1622
+ { class: "stat-grid" },
1623
+ stat("effects", fmtCount(keys.size)),
1624
+ stat("runs", fmtCount(runs)),
1625
+ stat("total run", fmtMs(total)),
1626
+ stat("avg run", fmtMs(runs ? total / runs : 0)),
1627
+ stat("cleanups", fmtCount(cleanups)),
1628
+ stat("errors", fmtCount(errors), errors > 0 ? "bad" : "good")
1629
+ )
1630
+ );
1631
+ }
1632
+ /** Re-run thrash + error detection for effects. */
1633
+ renderEffectInsights(model) {
1634
+ const aggs = /* @__PURE__ */ new Map();
1635
+ for (const e of model.effects) {
1636
+ let a = aggs.get(e.effectKey);
1637
+ if (!a) {
1638
+ a = { label: e.label, runs: 0, errors: 0, total: 0 };
1639
+ aggs.set(e.effectKey, a);
1640
+ }
1641
+ if (e.phase === "run") {
1642
+ a.runs += 1;
1643
+ a.total += e.duration ?? 0;
1644
+ } else if (e.phase === "error") a.errors += 1;
1645
+ }
1646
+ const insights = [];
1647
+ for (const a of aggs.values()) {
1648
+ if (a.errors > 0) {
1649
+ insights.push({ tone: "bad", icon: "✖", text: `${a.label} threw ${fmtCount(a.errors)}× — check the effect body.` });
1650
+ }
1651
+ if (a.runs >= 20) {
1652
+ insights.push({ tone: "warn", icon: "↻", text: `${a.label} ran ${fmtCount(a.runs)}× — a hot trigger; confirm its dependency list is intentional.` });
1653
+ } else if (a.runs >= 1 && a.total / Math.max(1, a.runs) >= 6) {
1654
+ insights.push({ tone: "warn", icon: "▲", text: `${a.label} averages ${fmtMs(a.total / a.runs)} per run — heavy work in an effect body.` });
1655
+ }
1656
+ }
1657
+ if (insights.length === 0) return null;
1658
+ return h(
1659
+ "div",
1660
+ { class: "section" },
1661
+ h("p", { class: "section-title" }, "Insights"),
1662
+ h("div", { class: "insights" }, ...insights.slice(0, 6).map((i) => h(
1663
+ "div",
1664
+ { class: `insight t-${i.tone}` },
1665
+ h("span", { class: "insight-ic" }, i.icon),
1666
+ h("span", {}, i.text)
1667
+ )))
1668
+ );
1669
+ }
1670
+ /**
1671
+ * A visual, time-positioned timeline: one lane per effect, with a marker
1672
+ * for every event placed along a shared time axis and coloured by phase.
1673
+ * Makes overlapping runs, cleanup→run pairing, and bursts obvious at a
1674
+ * glance in a way the chronological log can't.
1675
+ */
1676
+ renderEffectTimeline(model) {
1677
+ const base = model.firstTime ?? 0;
1678
+ const last = model.effects.reduce((m, e) => Math.max(m, e.time), base);
1679
+ const span = Math.max(1, last - base);
1680
+ const order = [];
1681
+ const byKey = /* @__PURE__ */ new Map();
1682
+ for (const e of model.effects) {
1683
+ let lane = byKey.get(e.effectKey);
1684
+ if (!lane) {
1685
+ lane = { label: e.label, instance: e.instanceKey != null, events: [] };
1686
+ byKey.set(e.effectKey, lane);
1687
+ order.push(e.effectKey);
1688
+ }
1689
+ lane.events.push(e);
1690
+ }
1691
+ const wrap = h("div", { class: "section", style: "padding:0" });
1692
+ wrap.appendChild(h(
1693
+ "div",
1694
+ { class: "tl-head" },
1695
+ h("span", { class: "section-title", style: "margin:0" }, `Timeline · ${fmtRel(span)} span`),
1696
+ h("span", { class: "tl-axis" }, "0", h("span", { class: "tl-axis-end" }, fmtRel(span)))
1697
+ ));
1698
+ for (const key of order) {
1699
+ const lane = byKey.get(key);
1700
+ const track = h("div", { class: "tl-track" });
1701
+ for (const e of lane.events) {
1702
+ if (!this.phaseFilter.has(e.phase)) continue;
1703
+ const leftPct = (e.time - base) / span * 100;
1704
+ track.appendChild(h("span", {
1705
+ class: `tl-dot ${PHASE_CHIP[e.phase] ?? "grey"}`,
1706
+ style: `left:${Math.min(99, Math.max(0, leftPct))}%`,
1707
+ title: `${e.phase} · ${e.reason}${e.duration != null ? ` · ${fmtMs(e.duration)}` : ""} · ${fmtRel(e.time - base)}`
1708
+ }));
1709
+ }
1710
+ wrap.appendChild(h(
1711
+ "div",
1712
+ { class: "tl-row" },
1713
+ h(
1714
+ "span",
1715
+ { class: "tl-name" },
1716
+ lane.label,
1717
+ lane.instance ? h("span", { class: "chip purple", style: "margin-left:5px" }, "inst") : null
1718
+ ),
1719
+ track
1720
+ ));
1721
+ }
1722
+ return wrap;
1189
1723
  }
1190
1724
  renderEffectLanes(model) {
1191
1725
  const lanes = /* @__PURE__ */ new Map();