brumate 0.7.2 → 0.8.0

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 (88) hide show
  1. package/dist/{boot-CMy0f_iC.d.ts → boot-BkUdiYOF.d.ts} +2 -2
  2. package/dist/cli.js +3 -2
  3. package/dist/cli.js.map +1 -1
  4. package/dist/{client-COm1iA6w.js → client-B0FXW5Kw.js} +48 -14
  5. package/dist/client-B0FXW5Kw.js.map +1 -0
  6. package/dist/{client-DnFF9_lv.d.ts → client-Cq6aTiDs.d.ts} +15 -7
  7. package/dist/{defer-Cesb-k2Q.js → defer-BMIMP4Hq.js} +2 -2
  8. package/dist/{defer-Cesb-k2Q.js.map → defer-BMIMP4Hq.js.map} +1 -1
  9. package/dist/{devtools-C9IEkgc1.js → devtools-B4prrxht.js} +257 -118
  10. package/dist/devtools-B4prrxht.js.map +1 -0
  11. package/dist/devtools-calls-DGW6nLZ2.js +249 -0
  12. package/dist/devtools-calls-DGW6nLZ2.js.map +1 -0
  13. package/dist/devtools-panel-B1nF1KB7.js +3978 -0
  14. package/dist/devtools-panel-B1nF1KB7.js.map +1 -0
  15. package/dist/error-catalog-DakxjSgj.js +308 -0
  16. package/dist/error-catalog-DakxjSgj.js.map +1 -0
  17. package/dist/error-catalog-VxLbz-6p.js +1 -0
  18. package/dist/{files-BuQvpBwF.js → files-D5GtxwEQ.js} +2 -2
  19. package/dist/{files-BuQvpBwF.js.map → files-D5GtxwEQ.js.map} +1 -1
  20. package/dist/index.d.ts +73 -18
  21. package/dist/index.js +11 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/{inspect-BSHv1_25.js → inspect-CGl5Y8q6.js} +581 -399
  24. package/dist/inspect-CGl5Y8q6.js.map +1 -0
  25. package/dist/{loader-CLKrJMqw.js → loader-BsaSuIoG.js} +4 -4
  26. package/dist/{loader-CLKrJMqw.js.map → loader-BsaSuIoG.js.map} +1 -1
  27. package/dist/{navigate-OHb0Uw1P.js → navigate-BlowKvhB.js} +13 -6
  28. package/dist/navigate-BlowKvhB.js.map +1 -0
  29. package/dist/{rpc-BAKbRWOT.js → rpc-C1jYVNAe.js} +5 -4
  30. package/dist/rpc-C1jYVNAe.js.map +1 -0
  31. package/dist/runtime/bundles.d.ts +1 -1
  32. package/dist/runtime/client.d.ts +2 -2
  33. package/dist/runtime/client.js +4 -3
  34. package/dist/runtime/devtools.d.ts +59 -1
  35. package/dist/runtime/devtools.js +1 -1
  36. package/dist/runtime/hot.d.ts +1 -1
  37. package/dist/runtime/hot.js +6 -2
  38. package/dist/runtime/hot.js.map +1 -1
  39. package/dist/runtime/loader.d.ts +2 -2
  40. package/dist/runtime/loader.js +2 -2
  41. package/dist/runtime/server.d.ts +1 -1
  42. package/dist/runtime/server.js +3 -2
  43. package/dist/runtime/signals.d.ts +1 -1
  44. package/dist/runtime/static-loader.d.ts +2 -2
  45. package/dist/runtime/static-loader.js +1 -1
  46. package/dist/runtime/store.d.ts +2 -2
  47. package/dist/runtime/store.js +1 -1
  48. package/dist/runtime/testing.d.ts +2 -2
  49. package/dist/runtime/testing.js +2 -2
  50. package/dist/search-params-Wg-0FsMj.js +148 -0
  51. package/dist/search-params-Wg-0FsMj.js.map +1 -0
  52. package/dist/{stream-RXLadXx1.js → serial-ioa17MuY.js} +67 -168
  53. package/dist/serial-ioa17MuY.js.map +1 -0
  54. package/dist/serial-ribg9NAj.js +1 -0
  55. package/dist/{server-BVObWh-w.js → server-BUuf7XPZ.js} +61 -16
  56. package/dist/server-BUuf7XPZ.js.map +1 -0
  57. package/dist/{server-0rS5vUW1.d.ts → server-DesBZv5g.d.ts} +8 -3
  58. package/dist/{search-params-C64liRBj.js → shared-CX_YacDm.js} +3 -148
  59. package/dist/shared-CX_YacDm.js.map +1 -0
  60. package/dist/{signals-DBnq9QRW.d.ts → signals-7VVD9C_H.d.ts} +2 -2
  61. package/dist/{static-loader-CxANokZ4.js → static-loader-C_en-4v8.js} +2 -2
  62. package/dist/{static-loader-CxANokZ4.js.map → static-loader-C_en-4v8.js.map} +1 -1
  63. package/dist/{static-loader-BYbXVJDY.d.ts → static-loader-UKnK11Em.d.ts} +2 -2
  64. package/dist/{store-xlTzAM_r.d.ts → store-9_oa0HG1.d.ts} +15 -2
  65. package/dist/{store-BIBAYZo-.js → store-Cy4EEyZ7.js} +148 -2
  66. package/dist/store-Cy4EEyZ7.js.map +1 -0
  67. package/dist/stream-read-BTsYstJY.js +22 -0
  68. package/dist/stream-read-BTsYstJY.js.map +1 -0
  69. package/dist/stream-read-Dek3HnqO.js +1 -0
  70. package/dist/vite.d.ts +1 -1
  71. package/dist/vite.js +37 -5
  72. package/dist/vite.js.map +1 -1
  73. package/package.json +7 -4
  74. package/skills/brumate/SKILL.md +6 -2
  75. package/skills/brumate/references/errors.md +21 -2
  76. package/skills/brumate/references/state.md +31 -0
  77. package/skills/brumate/references/syntax.md +45 -1
  78. package/dist/client-COm1iA6w.js.map +0 -1
  79. package/dist/devtools-C9IEkgc1.js.map +0 -1
  80. package/dist/devtools-panel-Doit__YG.js +0 -2018
  81. package/dist/devtools-panel-Doit__YG.js.map +0 -1
  82. package/dist/inspect-BSHv1_25.js.map +0 -1
  83. package/dist/navigate-OHb0Uw1P.js.map +0 -1
  84. package/dist/rpc-BAKbRWOT.js.map +0 -1
  85. package/dist/search-params-C64liRBj.js.map +0 -1
  86. package/dist/server-BVObWh-w.js.map +0 -1
  87. package/dist/store-BIBAYZo-.js.map +0 -1
  88. package/dist/stream-RXLadXx1.js.map +0 -1
@@ -1,2018 +0,0 @@
1
- import { t as trustedHTML } from "./trusted-g_zUJbh2.js";
2
- import { t as LOGO } from "./logo-DQ_OYhBi.js";
3
- import { a as preview, t as findRootScope } from "./devtools-C9IEkgc1.js";
4
- //#region src/runtime/devtools-panel.ts
5
- const STYLE = `
6
- :host { all: initial; }
7
- .panel {
8
- --bg: #121113; --surface: #19181a; --raised: #222023; --hover: #2a282c; --line: #2f2c31;
9
- --text: #ece8e4; --dim: #a39a92; --faint: #6f6862; --accent: #ee7a3e;
10
- --blue: #7cb7ff; --purple: #c49bff; --green: #7fd99a; --yellow: #ffd166; --red: #ff7a7a;
11
- --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
12
- position: fixed; left: 0; right: 0; bottom: 0; z-index: 2147483647;
13
- display: flex; flex-direction: column; min-height: 160px; max-height: 90vh;
14
- background: var(--bg); color: var(--text); border-top: 1px solid var(--line);
15
- box-shadow: 0 -8px 32px #0007; font: 12px/1.5 system-ui, -apple-system, sans-serif;
16
- color-scheme: dark;
17
- }
18
- .resize { position: absolute; top: -4px; left: 0; right: 0; height: 8px; cursor: ns-resize; }
19
- .top { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--surface); white-space: nowrap; overflow: hidden; }
20
- .brand { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; letter-spacing: -0.01em; }
21
- .brand i { display: inline-block; width: 18px; height: 18px; }
22
- .chip { padding: 1px 7px; border-radius: 999px; background: var(--raised); color: var(--dim); font: 11px var(--mono); }
23
- .chip.accent { background: #ee7a3e22; color: #ffb48a; }
24
- .route { font: 12px var(--mono); color: var(--text); overflow: hidden; text-overflow: ellipsis; }
25
- .stats { color: var(--dim); overflow: hidden; text-overflow: ellipsis; }
26
- .spacer { flex: 1; }
27
- button, select, input { font: inherit; color: inherit; }
28
- button { background: none; border: 1px solid transparent; border-radius: 6px; padding: 2px 8px; cursor: pointer; }
29
- button:hover { background: var(--hover); }
30
- button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
31
- button.tool { display: inline-flex; align-items: center; gap: 6px; border-color: var(--line); background: var(--surface); }
32
- button.tool .icon { color: var(--dim); flex: none; }
33
- button.tool:hover .icon { color: var(--text); }
34
- button.tool.only { padding: 3px 5px; }
35
- .link { display: inline-flex; align-items: center; gap: 4px; }
36
- .link .icon { opacity: 0.7; }
37
- .zoom button.tool { background: var(--raised); }
38
- button.tool[aria-pressed="true"] { border-color: var(--accent); background: #ee7a3e22; color: #ffb48a; }
39
- select, input[type="search"] { background: var(--raised); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; }
40
- .main { flex: 1; display: flex; min-height: 0; }
41
- .nav { display: flex; flex-direction: column; gap: 1px; padding: 6px; width: 156px; flex: none; border-right: 1px solid var(--line); background: var(--surface); overflow: auto; }
42
- .nav .tab { display: flex; justify-content: space-between; align-items: center; text-align: left; padding: 4px 8px; color: var(--dim); }
43
- .nav .tab { gap: 8px; }
44
- .nav .tab .label { flex: 1; }
45
- .icon { flex: none; }
46
- .nav .tab .icon { color: var(--faint); transition: color 0.15s; }
47
- .nav .tab:hover .icon { color: var(--dim); }
48
- .nav .tab[aria-selected="true"] { background: var(--raised); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
49
- .nav .tab[aria-selected="true"] .icon { color: var(--accent); }
50
- .badge { min-width: 16px; padding: 0 5px; border-radius: 999px; background: var(--raised); color: var(--dim); font: 10px/16px var(--mono); text-align: center; }
51
- .badge:empty { display: none; }
52
- .tab[aria-selected="true"] .badge { background: var(--hover); }
53
- .badge.warn { background: #ffd16622; color: var(--yellow); }
54
- .badge.error, .tab[aria-selected="true"] .badge.error { background: #e5484d; color: #fff; }
55
- .error-message { margin: 0 0 8px; color: var(--red); font: 600 14px/1.4 var(--mono); white-space: pre-wrap; }
56
- .error-row { display: block; width: 100%; text-align: left; padding: 6px 8px; border-radius: 6px; }
57
- .error-row[aria-current="true"] { background: #e5484d14; box-shadow: 0 0 0 1px #e5484d40; }
58
- .error-row .text { display: block; color: var(--text); font: 12px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
59
- .error-row .when { color: var(--faint); font-size: 11px; }
60
- .code { margin: 6px 0 10px; border: 1px solid var(--line); border-radius: 8px; background: #0d1117; overflow: auto; }
61
- .code .twinkleplop { margin: 0; padding: 8px 0; font: 12px/1.6 var(--mono); background: none; white-space: normal; }
62
- .code .l { display: block; padding: 0 12px 0 0; white-space: pre; min-height: 1.6em; }
63
- .code .ln { display: inline-block; width: 44px; padding-right: 12px; text-align: right; color: var(--faint); user-select: none; }
64
- .code .l.error-line { background: #e5484d24; }
65
- .code .l.error-line .ln { color: var(--red); }
66
- .code .error-mark { text-decoration: wavy underline #e5484d; text-underline-offset: 3px; }
67
- .code pre.plain { margin: 0; padding: 8px 12px; font: 12px/1.6 var(--mono); white-space: pre; }
68
- .frames { display: flex; flex-direction: column; gap: 1px; }
69
- .frame { display: flex; gap: 10px; width: 100%; text-align: left; padding: 3px 8px; border-radius: 5px; font: 11.5px var(--mono); }
70
- .frame .fn { color: var(--text); white-space: nowrap; }
71
- .frame .where { color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
72
- .frame.library .fn, .frame.library .where { color: var(--faint); }
73
- .frame[aria-current="true"] { background: #ee7a3e14; box-shadow: 0 0 0 1px #ee7a3e40; }
74
- .frame[aria-current="true"] .fn { color: #ffb48a; }
75
- .body { flex: 1; overflow: auto; padding: 12px 14px; min-width: 0; }
76
- .split { display: flex; height: calc(100% + 24px); margin: -12px -14px; }
77
- .split > .list { width: 280px; flex: none; overflow: auto; border-right: 1px solid var(--line); padding: 8px; display: flex; flex-direction: column; gap: 1px; }
78
- .split > .list input { margin-bottom: 6px; }
79
- .split > .detail { flex: 1; overflow: auto; padding: 12px 14px; min-width: 0; }
80
- h2 { margin: 0 0 8px; font-size: 13px; font-weight: 600; }
81
- h3 { margin: 14px 0 6px; font-size: 11px; font-weight: 600; color: var(--dim); text-transform: uppercase; letter-spacing: 0.05em; }
82
- .sub { color: var(--dim); font-weight: 400; }
83
- .mono { font-family: var(--mono); }
84
- .empty { color: var(--faint); padding: 16px 0; }
85
- .toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
86
- .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; margin-bottom: 6px; }
87
- .card { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
88
- .card .label { color: var(--dim); font-size: 11px; }
89
- .card .value { font-size: 18px; font-weight: 650; letter-spacing: -0.02em; }
90
- .card .note { color: var(--faint); font-size: 11px; }
91
- .rows { width: 100%; border-collapse: collapse; }
92
- .rows th { text-align: left; color: var(--faint); font-weight: 500; font-size: 11px; }
93
- .rows td, .rows th { padding: 4px 10px 4px 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
94
- .rows tr:hover td { background: #ffffff05; }
95
- .kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; align-items: baseline; }
96
- .kv > :nth-child(odd) { color: var(--dim); }
97
- .pill { display: inline-block; padding: 0 7px; border-radius: 999px; font: 11px/18px var(--mono); background: var(--raised); color: var(--dim); white-space: nowrap; }
98
- .pill.blue { background: #7cb7ff1f; color: var(--blue); } .pill.purple { background: #c49bff1f; color: var(--purple); }
99
- .pill.green { background: #7fd99a1f; color: var(--green); } .pill.yellow { background: #ffd1661f; color: var(--yellow); }
100
- .pill.red { background: #ff7a7a1f; color: var(--red); } .pill.accent { background: #ee7a3e22; color: #ffb48a; }
101
- .pill .name { color: #ffc28f; }
102
- .link { color: var(--blue); padding: 0; border: 0; font-family: var(--mono); text-align: left; }
103
- .link:hover { background: none; text-decoration: underline; }
104
- .tree-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; width: 100%; text-align: left; padding: 2px 6px; border-radius: 5px; }
105
- .tree-row.component { font-weight: 600; margin-top: 4px; }
106
- .tree-row .file { color: var(--faint); font: 11px var(--mono); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
107
- .tree-row[aria-current="true"] { background: #ee7a3e14; box-shadow: 0 0 0 1px #ee7a3e40; }
108
- .tree-row[aria-current="true"] > span:first-child { color: #ffb48a; }
109
- .written { animation: flash 0.8s; }
110
- @keyframes flash { from { background: #ffd16633; } to { background: transparent; } }
111
- .slots td.name { color: #ffc28f; font-family: var(--mono); width: 1%; white-space: nowrap; }
112
- .slots td.type { color: var(--faint); font-family: var(--mono); width: 1%; white-space: nowrap; }
113
- .slot .value { font-family: var(--mono); cursor: text; border-bottom: 1px dotted var(--faint); }
114
- .slot .value.fixed { cursor: default; border: 0; }
115
- .slot input { font: 12px var(--mono); color: var(--text); background: #000; border: 1px solid var(--accent); border-radius: 4px; padding: 1px 6px; width: 100%; box-sizing: border-box; }
116
- .filters label { display: inline-flex; gap: 4px; align-items: center; padding: 1px 8px; border-radius: 999px; background: var(--raised); cursor: pointer; }
117
- .entry td { font-family: var(--mono); }
118
- .entry .time { color: var(--faint); white-space: nowrap; width: 1%; }
119
- .kind-handler { color: var(--blue); } .kind-part { color: var(--green); } .kind-write { color: var(--yellow); } .kind-call { color: #ff9ecf; }
120
- .bar-cell { width: 40%; min-width: 160px; }
121
- .navigation { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
122
- .navigation .routes { display: flex; flex-direction: column; gap: 3px; }
123
- tr.large td, tr.busy td { color: var(--yellow); }
124
- tr.ended td { color: var(--faint); }
125
- .bar-track { position: relative; height: 12px; }
126
- .bar { position: absolute; top: 2px; height: 8px; min-width: 3px; border-radius: 3px; background: var(--blue); }
127
- .bar.failed { background: var(--red); }
128
- .bar.render { background: var(--accent); } .bar.memo { background: var(--green); } .bar.body { background: var(--purple); } .bar.stream { background: var(--faint); }
129
- tr.failed td:not(.bar-cell) { color: var(--red); }
130
- .interaction { margin-bottom: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
131
- .run-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
132
- .run-head .what { font-weight: 600; }
133
- .run-head .ref { color: var(--dim); font: 11.5px var(--mono); }
134
- .run-row { display: grid; grid-template-columns: 170px minmax(0, 1fr) 90px; align-items: center; gap: 10px; font: 11.5px var(--mono); color: var(--dim); }
135
- .run-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
136
- .run-row .took { text-align: right; color: var(--text); }
137
- .track { position: relative; height: 14px; overflow: hidden; border-radius: 4px; background-color: #ffffff08; }
138
- .ruler { position: relative; height: 16px; color: var(--faint); font: 10.5px var(--mono); }
139
- .ruler span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
140
- .ruler span:first-child { transform: none; }
141
- .ruler span.end { transform: translateX(-100%); }
142
- .seg { position: absolute; top: 3px; height: 8px; min-width: 2px; border-radius: 3px; }
143
- .seg.wait { background: repeating-linear-gradient(45deg, var(--faint) 0 3px, transparent 3px 6px); }
144
- .seg.run { background: var(--blue); }
145
- .seg.async { background: #7cb7ff55; }
146
- .seg.call { background: #ff9ecf88; }
147
- .seg.server { background: #ff9ecf; }
148
- .seg.update { background: var(--green); }
149
- .seg.failed { background: var(--red); }
150
- .legend { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; color: var(--dim); }
151
- .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
152
- .graph-wrap { display: flex; gap: 10px; height: calc(100% - 42px); min-height: 180px; }
153
- .graph-view { position: relative; flex: 1; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: radial-gradient(circle, #ffffff12 1px, transparent 1px) 0 0 / 16px 16px; cursor: grab; touch-action: none; }
154
- .graph-view.dragging { cursor: grabbing; }
155
- .graph-view svg { display: block; width: 100%; height: 100%; }
156
- .graph-side { width: 250px; flex: none; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--surface); }
157
- .zoom { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 4px; }
158
- .zoom button { background: var(--raised); border-color: var(--line); min-width: 28px; }
159
- svg .node rect.box { fill: var(--surface); stroke: var(--line); }
160
- svg .node .kind { fill: var(--faint); }
161
- svg .node .name { fill: var(--text); font: 600 11.5px var(--mono); }
162
- svg .node .meta { fill: var(--dim); font: 10.5px var(--mono); }
163
- svg .node { cursor: pointer; }
164
- svg .node:hover rect.box { stroke: var(--dim); }
165
- svg .k-signal .kind, svg .k-prop .kind { fill: var(--blue); }
166
- svg .k-memo .kind { fill: var(--purple); }
167
- svg .k-effect .kind { fill: var(--green); }
168
- svg .node.selected rect.box { stroke: var(--accent); stroke-width: 1.5; }
169
- svg .node.hot rect.box { fill: #3a3020; stroke: var(--yellow); }
170
- svg .node.faded { opacity: 0.3; }
171
- svg path.edge { fill: none; stroke: #8a828066; stroke-width: 1.25; }
172
- svg path.edge.lit { stroke: var(--accent); stroke-width: 1.75; }
173
- svg path.edge.hot-edge { stroke: var(--yellow); stroke-width: 1.75; }
174
- svg path.edge.faded { opacity: 0.15; }
175
- pre.report { margin: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font: 11.5px/1.55 var(--mono); white-space: pre-wrap; }
176
- .inspect-card { position: fixed; z-index: 2147483647; display: flex; flex-direction: column; gap: 5px; max-width: 340px; padding: 9px 11px; border: 1px solid var(--line, #2f2c31); border-radius: 10px; background: #19181aee; color: #ece8e4; font: 12px/1.4 system-ui, -apple-system, sans-serif; box-shadow: 0 10px 28px #0008; pointer-events: none; backdrop-filter: blur(6px); }
177
- .inspect-card .card-head { display: flex; justify-content: space-between; gap: 12px; color: #ffb48a; }
178
- .inspect-card .card-component { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
179
- .inspect-card .card-pills { display: flex; flex-wrap: wrap; gap: 4px; }
180
- .inspect-card .card-hint { margin-top: 2px; padding-top: 6px; border-top: 1px solid #2f2c31; color: #6f6862; font-size: 11px; }
181
- .outline { position: fixed; pointer-events: none; border: 2px solid #ee7a3e; background: #ee7a3e22; border-radius: 3px; z-index: 2147483646; }
182
- `;
183
- const TABS = [
184
- ["overview", "Overview"],
185
- ["errors", "Errors"],
186
- ["scopes", "Components"],
187
- ["elements", "Elements"],
188
- ["graph", "Graph"],
189
- ["log", "Log"],
190
- ["timeline", "Timeline"],
191
- ["state", "Page state"],
192
- ["effects", "Effects"],
193
- ["navigation", "Navigation"],
194
- ["server", "Server"],
195
- ["blocks", "Blocks"],
196
- ["report", "Report"]
197
- ];
198
- const KINDS = [
199
- "handler",
200
- "write",
201
- "call"
202
- ];
203
- /** How long a write marks the nodes of the graph. */
204
- const HOT_MS = 1500;
205
- /** The height of the panel, kept between pages. */
206
- const HEIGHT_KEY = "brumate:devtools:height";
207
- const components = /* @__PURE__ */ new Map();
208
- const known = /* @__PURE__ */ new Map();
209
- /** Asks the dev server about a component, once. */
210
- function componentInfo(state, id) {
211
- let info = components.get(id);
212
- if (!info) {
213
- info = fetch(`${state.endpoint}/${encodeURIComponent(id)}`).then((response) => response.ok ? response.json() : void 0).then((value) => {
214
- if (value) known.set(id, value);
215
- return value;
216
- }).catch(() => void 0);
217
- components.set(id, info);
218
- }
219
- return info;
220
- }
221
- /** The IDs of the components that instances in a list belong to. */
222
- function collectModules(instances) {
223
- const ids = /* @__PURE__ */ new Set();
224
- for (const scope of instances) ids.add(scope.m);
225
- return ids;
226
- }
227
- /** How many blocks of the page are in a state. */
228
- function countBlocks(blocks, blockState) {
229
- let count = 0;
230
- for (const block of blocks) if (block.state === blockState) count++;
231
- return count;
232
- }
233
- /** The infos of many components, in the order of their IDs. */
234
- function loadComponents(state, ids) {
235
- const pending = [];
236
- for (const id of ids) pending.push(componentInfo(state, id));
237
- return Promise.all(pending);
238
- }
239
- function element(tag, attributes = {}, ...children) {
240
- const node = document.createElement(tag);
241
- for (const [name, value] of Object.entries(attributes)) node.setAttribute(name, value);
242
- node.append(...children);
243
- return node;
244
- }
245
- function svg(tag, attributes, ...children) {
246
- const node = document.createElementNS("http://www.w3.org/2000/svg", tag);
247
- for (const [name, value] of Object.entries(attributes)) node.setAttribute(name, String(value));
248
- node.append(...children);
249
- return node;
250
- }
251
- /**
252
- * The icons of the panel: strokes on a grid of 24, in the colour of the text.
253
- */
254
- const ICONS = {
255
- overview: "<rect x=\"3.5\" y=\"3.5\" width=\"7\" height=\"7\" rx=\"1.75\"/><rect x=\"13.5\" y=\"3.5\" width=\"7\" height=\"7\" rx=\"1.75\"/><rect x=\"3.5\" y=\"13.5\" width=\"7\" height=\"7\" rx=\"1.75\"/><rect x=\"13.5\" y=\"13.5\" width=\"7\" height=\"7\" rx=\"1.75\"/>",
256
- errors: "<path d=\"M10.3 4.6a2 2 0 0 1 3.4 0l7 12.2a2 2 0 0 1-1.7 3H5a2 2 0 0 1-1.7-3z\"/><path d=\"M12 9.5v4\"/><path d=\"M12 16.8v.2\"/>",
257
- scopes: "<rect x=\"9\" y=\"3\" width=\"6\" height=\"5\" rx=\"1.25\"/><rect x=\"3\" y=\"16\" width=\"6\" height=\"5\" rx=\"1.25\"/><rect x=\"15\" y=\"16\" width=\"6\" height=\"5\" rx=\"1.25\"/><path d=\"M12 8v4M6 16v-2.25A1.75 1.75 0 0 1 7.75 12h8.5A1.75 1.75 0 0 1 18 13.75V16\"/>",
258
- elements: "<path d=\"M5 4.5 18 10l-5.5 2L10 17.5z\"/><path d=\"m13 13 5.5 5.5\"/>",
259
- graph: "<circle cx=\"6\" cy=\"12\" r=\"2.5\"/><circle cx=\"18\" cy=\"6\" r=\"2.5\"/><circle cx=\"18\" cy=\"18\" r=\"2.5\"/><path d=\"m8.3 10.8 7.4-3.6M8.3 13.2l7.4 3.6\"/>",
260
- log: "<path d=\"M9 6h11M9 12h11M9 18h11\"/><path d=\"M4.5 6h.01M4.5 12h.01M4.5 18h.01\" stroke-width=\"2.6\"/>",
261
- loading: "<path d=\"M4 6h7M8 12h9M13 18h7\"/>",
262
- state: "<ellipse cx=\"12\" cy=\"6\" rx=\"7.5\" ry=\"2.75\"/><path d=\"M4.5 6v6c0 1.5 3.4 2.75 7.5 2.75s7.5-1.25 7.5-2.75V6\"/><path d=\"M4.5 12v6c0 1.5 3.4 2.75 7.5 2.75s7.5-1.25 7.5-2.75v-6\"/>",
263
- effects: "<path d=\"M19.5 12a7.5 7.5 0 1 1-2.2-5.3\"/><path d=\"M19.5 4v4h-4\"/>",
264
- navigation: "<path d=\"M4 7h11M4 7l3.5-3.5M4 7l3.5 3.5\"/><path d=\"M20 17H9M20 17l-3.5-3.5M20 17l-3.5 3.5\"/>",
265
- server: "<rect x=\"4\" y=\"4\" width=\"16\" height=\"6.5\" rx=\"1.5\"/><rect x=\"4\" y=\"13.5\" width=\"16\" height=\"6.5\" rx=\"1.5\"/><path d=\"M7.5 7.25h.01M7.5 16.75h.01\" stroke-width=\"2.6\"/>",
266
- timeline: "<circle cx=\"12\" cy=\"13\" r=\"7.5\"/><path d=\"M12 9.5V13l2.5 1.6M10 3h4\"/>",
267
- blocks: "<path d=\"M12 3.5 3.5 8 12 12.5 20.5 8z\"/><path d=\"M3.5 12 12 16.5 20.5 12M3.5 16 12 20.5 20.5 16\"/>",
268
- report: "<path d=\"M14 3.5H7a1.5 1.5 0 0 0-1.5 1.5v14A1.5 1.5 0 0 0 7 20.5h10a1.5 1.5 0 0 0 1.5-1.5V8z\"/><path d=\"M14 3.5V8h4.5M9 12.5h6M9 16h6\"/>",
269
- flash: "<path d=\"M12 3v3M12 18v3M3 12h3M18 12h3M5.6 5.6l2.1 2.1M16.3 16.3l2.1 2.1M5.6 18.4l2.1-2.1M16.3 7.7l2.1-2.1\"/><circle cx=\"12\" cy=\"12\" r=\"2.5\"/>",
270
- pick: "<circle cx=\"12\" cy=\"12\" r=\"7\"/><path d=\"M12 2.5v4M12 17.5v4M2.5 12h4M17.5 12h4\"/><circle cx=\"12\" cy=\"12\" r=\"1.2\" fill=\"currentColor\" stroke=\"none\"/>",
271
- close: "<path d=\"m6 9.5 6 6 6-6\"/>",
272
- trash: "<path d=\"M4.5 7h15M9.5 7V5a1 1 0 0 1 1-1h3a1 1 0 0 1 1 1v2M6.5 7l.9 12.1a1.5 1.5 0 0 0 1.5 1.4h6.2a1.5 1.5 0 0 0 1.5-1.4L17.5 7\"/>",
273
- pause: "<path d=\"M9 5.5v13M15 5.5v13\"/>",
274
- play: "<path d=\"M8 5.5v13l10.5-6.5z\"/>",
275
- fit: "<path d=\"M4 9V5a1 1 0 0 1 1-1h4M20 9V5a1 1 0 0 0-1-1h-4M4 15v4a1 1 0 0 0 1 1h4M20 15v4a1 1 0 0 1-1 1h-4\"/>",
276
- plus: "<path d=\"M12 5v14M5 12h14\"/>",
277
- minus: "<path d=\"M5 12h14\"/>",
278
- bolt: "<path d=\"M13 3 5 13.5h6L10 21l9-11h-6z\"/>",
279
- open: "<path d=\"M14 4h6v6M20 4l-8.5 8.5M18 14v4.5a1.5 1.5 0 0 1-1.5 1.5h-11A1.5 1.5 0 0 1 4 18.5v-11A1.5 1.5 0 0 1 5.5 6H10\"/>"
280
- };
281
- /** An icon by its name, for a button or a tab. */
282
- function icon(name, size = 14) {
283
- const node = svg("svg", {
284
- class: "icon",
285
- viewBox: "0 0 24 24",
286
- width: size,
287
- height: size,
288
- fill: "none",
289
- stroke: "currentColor",
290
- "stroke-width": 1.8,
291
- "stroke-linecap": "round",
292
- "stroke-linejoin": "round",
293
- "aria-hidden": "true"
294
- });
295
- node.innerHTML = trustedHTML(ICONS[name]);
296
- return node;
297
- }
298
- /** A button with an icon, and its text or, for an icon alone, its label for screen readers. */
299
- function iconButton(name, text, attributes = {}, iconOnly = false) {
300
- const button = element("button", {
301
- class: `tool${iconOnly ? " only" : ""}`,
302
- ...attributes
303
- }, icon(name));
304
- if (iconOnly) {
305
- button.setAttribute("aria-label", text);
306
- button.title ||= text;
307
- } else button.append(text);
308
- return button;
309
- }
310
- /** A value that can be edited as text: what JSON can hold. */
311
- function editable(value) {
312
- if (value === null || [
313
- "string",
314
- "number",
315
- "boolean"
316
- ].includes(typeof value)) return true;
317
- if (typeof value !== "object" || value instanceof Element) return false;
318
- try {
319
- JSON.stringify(value);
320
- return true;
321
- } catch {
322
- return false;
323
- }
324
- }
325
- /** Reads what a person typed: JSON, or else the text as a string. */
326
- function parseValue(text) {
327
- try {
328
- return JSON.parse(text);
329
- } catch {
330
- return text;
331
- }
332
- }
333
- /** The type of a value, for the column next to it. */
334
- function readType(value) {
335
- if (value === null) return "null";
336
- if (Array.isArray(value)) return "array";
337
- if (value instanceof Element) return "element";
338
- if (typeof value === "object") {
339
- const name = value.constructor?.name;
340
- return name && name !== "Object" ? name : "object";
341
- }
342
- return typeof value;
343
- }
344
- /** A write with the name of its slot, once the dev server has said what it is. */
345
- function describe(entry) {
346
- const write = entry.write;
347
- const info = write && known.get(write.component);
348
- const name = info?.scopes[write.k]?.slots[write.slot];
349
- return name ? `${info.name} ${name} = ${entry.text.split(" = ").slice(1).join(" = ")}` : entry.text;
350
- }
351
- function ms(time) {
352
- return `${Math.round(time)} ms`;
353
- }
354
- function seconds(time) {
355
- return `${(time / 1e3).toFixed(2)} s`;
356
- }
357
- function kilobytes(bytes) {
358
- return `${(bytes / 1024).toFixed(1)} kB`;
359
- }
360
- /** The keys and values of an object, a map or a set, or the items of an array, in a row. */
361
- function listEntries(value) {
362
- if (value instanceof Map) return [...value].flat();
363
- if (value instanceof Set || Array.isArray(value)) return [...value];
364
- return Object.entries(value).flat();
365
- }
366
- /**
367
- * About how many bytes a value takes in the page state. The state is code
368
- * that seroval writes, which this follows closely enough to compare values.
369
- */
370
- function measureSize(value, seen = /* @__PURE__ */ new Set()) {
371
- if (value === null || value === void 0) return 6;
372
- switch (typeof value) {
373
- case "string": return value.length + 2;
374
- case "number":
375
- case "boolean":
376
- case "bigint": return String(value).length;
377
- case "function": return 24;
378
- case "object": {
379
- if (seen.has(value)) return 6;
380
- seen.add(value);
381
- if (value instanceof Date) return 30;
382
- const entries = listEntries(value);
383
- let bytes = 2;
384
- for (const entry of entries) bytes += measureSize(entry, seen) + 1;
385
- return bytes;
386
- }
387
- default: return 8;
388
- }
389
- }
390
- /** The bytes of the state records of the page. */
391
- function stateBytes() {
392
- let bytes = 0;
393
- for (const script of document.querySelectorAll("script[b-state]")) bytes += script.textContent?.length ?? 0;
394
- return bytes;
395
- }
396
- /** The value of a name that a scope or one of the scopes around it holds. */
397
- function readValue(scope, name) {
398
- for (let current = scope; current; current = current.p) {
399
- const slot = (known.get(findRootScope(current).m ?? "")?.scopes[current.k]?.slots)?.indexOf(name) ?? -1;
400
- if (slot !== -1) return preview(current.s[slot]);
401
- if (current.m !== void 0) break;
402
- }
403
- }
404
- const STATE_COLORS = {
405
- waiting: "",
406
- loading: "blue",
407
- streaming: "blue",
408
- rendered: "green",
409
- failed: "red"
410
- };
411
- /** The colour of a node in the graph. Other kinds are blue when they hold a value. */
412
- function nodeColor(kind, slot) {
413
- if (kind === "memo") return "purple";
414
- if (kind === "effect") return "green";
415
- return slot === void 0 ? "" : "blue";
416
- }
417
- /** The colour of how long a run took, in milliseconds. */
418
- function speedColor(total) {
419
- if (total < 100) return "green";
420
- return total < 300 ? "yellow" : "red";
421
- }
422
- function blockLabel(block) {
423
- return block.kind === "$client" ? "$client" : `#${block.kind}`;
424
- }
425
- function pill(text, color = "") {
426
- return element("span", { class: `pill ${color}` }, text);
427
- }
428
- /** A row of cells, as a table row. */
429
- function row(cells, tag = "td") {
430
- const items = [];
431
- for (const cell of cells) items.push(element(tag, {}, cell));
432
- return element("tr", {}, ...items);
433
- }
434
- /** A card of a number, with a label above and a note below. */
435
- function card(label, value, note) {
436
- return element("div", { class: "card" }, element("div", { class: "label" }, label), element("div", { class: "value" }, value), element("div", { class: "note" }, note));
437
- }
438
- /** A square of colour and its meaning, for a legend. */
439
- function key(color, text) {
440
- return element("span", {}, element("i", { style: `background: ${color}` }), text);
441
- }
442
- /** A button that opens a place of a file in the editor, through the dev server. */
443
- function source(info, at = "1:1") {
444
- if (!info) return "";
445
- const label = at === "1:1" ? info.file : `${info.file}:${at}`;
446
- if (!info.path) return element("span", { class: "mono sub" }, label);
447
- const open = element("button", {
448
- class: "link",
449
- title: "Open in the editor"
450
- }, label, icon("open", 12));
451
- open.addEventListener("click", () => {
452
- fetch(`/__open-in-editor?file=${encodeURIComponent(`${info.path}:${at}`)}`);
453
- });
454
- return open;
455
- }
456
- /** A button that opens the place of a graph node in the editor. */
457
- function place(info, at) {
458
- const label = `line ${at.line}`;
459
- const file = at.file ?? info.path;
460
- if (!file) return element("span", { class: "mono sub" }, label);
461
- const open = element("button", {
462
- class: "link",
463
- title: `Open ${at.file ?? info.file}:${at.line}:${at.column}`
464
- }, label, icon("open", 12));
465
- open.addEventListener("click", () => {
466
- fetch(`/__open-in-editor?file=${encodeURIComponent(`${file}:${at.line}:${at.column}`)}`);
467
- });
468
- return open;
469
- }
470
- /**
471
- * Places the nodes of a graph in columns, left to right, by the longest
472
- * path from a value that nothing feeds. Within a column, nodes are ordered
473
- * by the average place of the nodes they connect to, a few times in each
474
- * direction, so edges cross less. Each column is as wide as its widest node.
475
- */
476
- function layoutGraph(nodes, edges, getWidth) {
477
- const depth = [];
478
- for (let index = 0; index < nodes.length; index++) depth.push(0);
479
- for (let round = 0, changed = true; changed && round < nodes.length; round++) {
480
- changed = false;
481
- for (const [from, to] of edges) if (depth[from] + 1 > depth[to]) {
482
- depth[to] = depth[from] + 1;
483
- changed = true;
484
- }
485
- }
486
- const columns = [];
487
- for (let index = 0; index < nodes.length; index++) (columns[depth[index]] ??= []).push(index);
488
- const filled = [];
489
- for (const column of columns) if (column) filled.push(column);
490
- const order = /* @__PURE__ */ new Map();
491
- for (const column of filled) for (const [index, node] of column.entries()) order.set(node, index);
492
- const before = [];
493
- const after = [];
494
- for (let index = 0; index < nodes.length; index++) {
495
- before.push([]);
496
- after.push([]);
497
- }
498
- for (const [from, to] of edges) {
499
- after[from].push(to);
500
- before[to].push(from);
501
- }
502
- function average(list, fallback) {
503
- if (list.length === 0) return fallback;
504
- let sum = 0;
505
- for (const node of list) sum += order.get(node);
506
- return sum / list.length;
507
- }
508
- for (let sweep = 0; sweep < 8; sweep++) {
509
- const forward = sweep % 2 === 0;
510
- const sequence = forward ? filled.slice(1) : filled.slice(0, -1).toReversed();
511
- for (const column of sequence) {
512
- const weight = /* @__PURE__ */ new Map();
513
- for (const node of column) weight.set(node, average(forward ? before[node] : after[node], order.get(node)));
514
- column.sort((a, b) => weight.get(a) - weight.get(b));
515
- for (const [index, node] of column.entries()) order.set(node, index);
516
- }
517
- }
518
- const ROW = 50;
519
- const GAP = 72;
520
- let tallest = 1;
521
- for (const column of filled) tallest = Math.max(tallest, column.length);
522
- const result = [];
523
- let x = 16;
524
- for (const column of filled) {
525
- let width = -Infinity;
526
- for (const node of column) width = Math.max(width, getWidth(node));
527
- const top = 16 + (tallest - column.length) * ROW / 2;
528
- for (const [index, node] of column.entries()) result[node] = {
529
- x,
530
- y: top + index * ROW,
531
- width
532
- };
533
- x += width + GAP;
534
- }
535
- return result;
536
- }
537
- /** The scopes of a component instance, without the components inside it. */
538
- function countScopes(scope) {
539
- let count = 1;
540
- for (const child of scope.children ?? []) if (child.m === void 0) count += countScopes(child);
541
- return count;
542
- }
543
- /** A label cut to the width of a node of the graph. */
544
- function clip(text) {
545
- return text.length > 34 ? `${text.slice(0, 33)}…` : text;
546
- }
547
- /** The text of an entry of the log. */
548
- function readText(entry) {
549
- return entry.kind === "write" ? describe(entry) : entry.text;
550
- }
551
- /** The places of a stack, with their files as the dev server can read them. */
552
- function parseFrames(stack) {
553
- const frames = [];
554
- for (const line of (stack ?? "").split("\n")) {
555
- const match = /^\s*at (?:(.*?) \()?(.+?):(\d+):(\d+)\)?\s*$/.exec(line);
556
- if (!match) continue;
557
- let file = match[2];
558
- let compiled = false;
559
- if (/^[a-z-]+-extension:/.test(file) || file.startsWith("<")) continue;
560
- if (/^https?:/.test(file)) {
561
- const url = new URL(file);
562
- if (url.origin !== location.origin) continue;
563
- compiled = true;
564
- file = url.pathname.startsWith("/@fs/") ? url.pathname.slice(4) : url.pathname;
565
- } else if (file.startsWith("file://")) file = decodeURIComponent(new URL(file).pathname);
566
- frames.push({
567
- fn: match[1] ?? "(anonymous)",
568
- file,
569
- line: Number(match[3]),
570
- column: Number(match[4]),
571
- library: file.startsWith("node:") || file.includes("/node_modules/") || /\/brumate\/(?:src|dist)\/runtime\//.test(file) || file.includes("/@vite/"),
572
- compiled
573
- });
574
- }
575
- return frames;
576
- }
577
- /** The places in the sources of frames that the browser ran, by their compiled place. */
578
- const mapped = /* @__PURE__ */ new Map();
579
- /**
580
- * Maps the frames that the browser ran to their sources, by the source maps
581
- * of the dev server, so a frame of a component or a module function names
582
- * its own file and line. A frame that the dev server cannot map stays as it is.
583
- */
584
- function mapFrames(frames, urls) {
585
- const results = [];
586
- for (const [index, frame] of frames.entries()) {
587
- const url = urls[index];
588
- if (!frame.compiled || frame.library || !url) {
589
- results.push(frame);
590
- continue;
591
- }
592
- const unmapped = {
593
- ...frame,
594
- url
595
- };
596
- const key = `${url}:${frame.line}:${frame.column}`;
597
- let result = mapped.get(key);
598
- if (!result) {
599
- const query = new URLSearchParams({
600
- url,
601
- line: String(frame.line),
602
- column: String(frame.column)
603
- });
604
- result = fetch(`/__brumate/position?${query}`).then((response) => response.ok ? response.json() : null).then((place) => place ? {
605
- ...frame,
606
- ...place,
607
- compiled: false
608
- } : unmapped).catch(() => unmapped);
609
- mapped.set(key, result);
610
- }
611
- results.push(result);
612
- }
613
- return Promise.all(results);
614
- }
615
- /** The URLs that the frames of a stack name, as the dev server knows the modules. */
616
- function frameUrls(stack) {
617
- const urls = [];
618
- for (const line of (stack ?? "").split("\n")) {
619
- const file = /^\s*at (?:(.*?) \()?(.+?):(\d+):(\d+)\)?\s*$/.exec(line)?.[2];
620
- if (!file || /^[a-z-]+-extension:/.test(file) || file.startsWith("<")) continue;
621
- if (/^https?:/.test(file)) {
622
- const url = new URL(file);
623
- urls.push(url.origin === location.origin ? url.pathname + url.search : "");
624
- if (url.origin !== location.origin) urls.pop();
625
- } else urls.push("");
626
- }
627
- return urls;
628
- }
629
- /** The highlighter, which loads with the first code that the Errors tab shows. */
630
- let highlighter;
631
- /** The sources of files, by path. */
632
- const sources = /* @__PURE__ */ new Map();
633
- /** The code of a module as the dev server sent it to the browser. */
634
- function fetchCompiled(url) {
635
- let text = sources.get(url);
636
- if (!text) {
637
- text = fetch(url).then((response) => response.ok ? response.text() : void 0).catch(() => void 0);
638
- sources.set(url, text);
639
- }
640
- return text;
641
- }
642
- function fetchSource(file) {
643
- let text = sources.get(file);
644
- if (!text) {
645
- text = fetch(`/__brumate/source?file=${encodeURIComponent(file)}`).then((response) => response.ok ? response.text() : void 0).catch(() => void 0);
646
- sources.set(file, text);
647
- }
648
- return text;
649
- }
650
- /**
651
- * The lines around a place of a file, highlighted by twinkleplop, with the
652
- * line of the place and the word at its column marked. Without the source,
653
- * the frame of the error is shown as it is.
654
- */
655
- async function codeView(place, fallback) {
656
- const box = element("div", { class: "code" });
657
- const [text, module] = await Promise.all([place.url ? fetchCompiled(place.url) : fetchSource(place.file), highlighter ??= import("./highlight.js")]);
658
- if (text === void 0) {
659
- box.append(element("pre", { class: "plain" }, fallback ?? "The dev server cannot read this file."));
660
- return box;
661
- }
662
- const lines = text.split("\n");
663
- const start = Math.max(1, place.line - 6);
664
- const end = Math.min(lines.length, place.line + 6);
665
- const target = place.line;
666
- const word = /^[\w$.]*/.exec(lines[place.line - 1]?.slice(place.column - 1) ?? "")?.[0] ?? "";
667
- box.append(element("style", {}, module.themeCSS("dark")));
668
- box.insertAdjacentHTML("beforeend", trustedHTML(module.highlightFile(place.url ? "compiled.ts" : place.file, text, {
669
- line_numbers: { start: 1 },
670
- line: (index) => index === target ? { class: "error-line" } : void 0,
671
- overlays: word.length > 0 ? [{
672
- start: {
673
- line: target,
674
- character: place.column - 1
675
- },
676
- end: {
677
- line: target,
678
- character: place.column - 1 + word.length
679
- },
680
- class: "error-mark"
681
- }] : []
682
- })));
683
- const shown = [...box.querySelectorAll("code > .l")];
684
- for (const [index, line] of shown.entries()) if (index + 1 < start || index + 1 > end) {
685
- if (line.nextSibling?.nodeType === Node.TEXT_NODE) line.nextSibling.remove();
686
- line.remove();
687
- }
688
- return box;
689
- }
690
- /** The name of a handler, such as `Index h16`, once the dev server said the component. */
691
- function handlerName(ref) {
692
- const [component, name = ""] = ref.split("#");
693
- return `${known.get(component)?.name ?? component} ${name}`;
694
- }
695
- /** A round step for the ticks of a ruler: 1, 2 or 5 times a power of ten, at least `rough`. */
696
- function tickStep(rough) {
697
- const power = 10 ** Math.floor(Math.log10(rough));
698
- for (const factor of [
699
- 1,
700
- 2,
701
- 5
702
- ]) if (factor * power >= rough) return factor * power;
703
- return 10 * power;
704
- }
705
- let panel;
706
- /** Switches the tab of the open panel. */
707
- let showTab;
708
- /** Stops picking, with its outline and card, when the panel closes. */
709
- let endPick;
710
- /** Opens the panel on a tab, or switches to it when the panel is open. */
711
- function openPanel(root, state, tab) {
712
- if (panel) showTab?.(tab);
713
- else togglePanel(root, state, tab);
714
- }
715
- /** Opens the panel, or closes it when it is open. */
716
- function togglePanel(root, state, initial = "overview") {
717
- const opener = root.querySelector("button.open");
718
- if (panel) {
719
- endPick?.();
720
- endPick = void 0;
721
- panel.remove();
722
- panel = void 0;
723
- state.changed = void 0;
724
- document.documentElement.style.removeProperty("padding-bottom");
725
- if (opener) opener.hidden = false;
726
- state.resize = void 0;
727
- state.resized = void 0;
728
- showTab = void 0;
729
- return;
730
- }
731
- let tab = initial;
732
- let selectedError;
733
- let selectedFrame = -1;
734
- let selected;
735
- let selectedScope;
736
- let editing;
737
- let paused = false;
738
- let filter = "";
739
- let logSearch = "";
740
- const shown = new Set(KINDS);
741
- let frozen;
742
- let picked;
743
- let graphNode;
744
- let view = {
745
- x: 0,
746
- y: 0,
747
- scale: 1,
748
- fitted: ""
749
- };
750
- let height = 340;
751
- try {
752
- height = Number(localStorage.getItem(HEIGHT_KEY)) || height;
753
- } catch {}
754
- const errorPage = document.getElementById("brumate-error") !== null;
755
- if (errorPage) height = window.innerHeight;
756
- const body = element("div", { class: "body" });
757
- const nav = element("div", {
758
- class: "nav",
759
- role: "tablist",
760
- "aria-orientation": "vertical"
761
- });
762
- const badges = /* @__PURE__ */ new Map();
763
- for (const [name, label] of TABS) {
764
- const badge = element("span", { class: "badge" });
765
- const button = element("button", {
766
- class: "tab",
767
- role: "tab",
768
- "data-tab": name
769
- }, icon(name === "scopes" ? "scopes" : name, 15), element("span", { class: "label" }, label), badge);
770
- badges.set(name, badge);
771
- button.addEventListener("click", () => {
772
- tab = name;
773
- draw();
774
- });
775
- nav.append(button);
776
- }
777
- const routeText = element("span", {
778
- class: "route",
779
- title: "The page"
780
- });
781
- const stats = element("span", { class: "stats" });
782
- const pick = iconButton("pick", "Pick", {
783
- "aria-pressed": "false",
784
- title: "Click an element of the page to see its scope, handlers and code"
785
- });
786
- const flash = iconButton("flash", "Updates", {
787
- "aria-pressed": String(state.flash),
788
- title: "Outline the elements that change: green now and then, red often"
789
- });
790
- flash.addEventListener("click", () => {
791
- state.setFlash?.(!state.flash);
792
- flash.setAttribute("aria-pressed", String(state.flash));
793
- });
794
- const close = iconButton("close", "Close the devtools (Alt+Shift+D)", {}, true);
795
- close.addEventListener("click", () => togglePanel(root, state));
796
- const versions = [element("span", {
797
- class: "chip accent",
798
- title: "The version of brumate"
799
- }, `v${state.meta.version ?? "?"}`)];
800
- if (state.meta.vite) versions.push(element("span", {
801
- class: "chip",
802
- title: "The version of Vite"
803
- }, `Vite ${state.meta.vite}`));
804
- const logo = element("i");
805
- logo.innerHTML = trustedHTML(LOGO);
806
- const resize = element("div", {
807
- class: "resize",
808
- title: "Drag to resize"
809
- });
810
- panel = element("div", {
811
- class: "panel",
812
- role: "region",
813
- "aria-label": "brumate devtools"
814
- }, 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));
815
- function applyHeight() {
816
- panel.style.height = `${height}px`;
817
- if (errorPage) panel.style.maxHeight = "none";
818
- document.documentElement.style.paddingBottom = `${height}px`;
819
- }
820
- applyHeight();
821
- root.append(panel);
822
- if (opener) opener.hidden = true;
823
- state.resize = (clientY) => {
824
- height = Math.min(Math.max(window.innerHeight - clientY, 160), window.innerHeight * .9);
825
- applyHeight();
826
- };
827
- state.resized = () => {
828
- try {
829
- localStorage.setItem(HEIGHT_KEY, String(Math.round(height)));
830
- } catch {}
831
- draw();
832
- };
833
- resize.addEventListener("pointerdown", (event) => {
834
- event.preventDefault();
835
- function move(next) {
836
- state.resize?.(next.clientY);
837
- }
838
- function up() {
839
- window.removeEventListener("pointermove", move);
840
- window.removeEventListener("pointerup", up);
841
- state.resized?.();
842
- }
843
- window.addEventListener("pointermove", move);
844
- window.addEventListener("pointerup", up);
845
- });
846
- if (!state.scopes) document.dispatchEvent(new Event("brumate:core"));
847
- const outlines = [];
848
- function outline(scope) {
849
- for (const box of outlines.splice(0)) box.remove();
850
- if (scope === void 0) return;
851
- for (const target of document.querySelectorAll(`[b-b^="${scope}:"]`)) {
852
- const rect = target.getBoundingClientRect();
853
- const box = element("div", {
854
- class: "outline",
855
- style: `left:${rect.left}px;top:${rect.top}px;width:${rect.width}px;height:${rect.height}px`
856
- });
857
- root.append(box);
858
- outlines.push(box);
859
- }
860
- }
861
- function onPick(event) {
862
- const clicked = event.target;
863
- if (!clicked?.closest || event.composedPath().includes(panel)) return;
864
- event.preventDefault();
865
- event.stopImmediatePropagation();
866
- stopPicking();
867
- picked = clicked;
868
- const id = clicked.closest("[b-b]")?.getAttribute("b-b").split(":")[0];
869
- if (id !== void 0) {
870
- selectedScope = /^-?\d+$/.test(id) ? Number(id) : id;
871
- const scope = state.scopes?.get(selectedScope);
872
- selected = scope ? findRootScope(scope).m : selected;
873
- }
874
- tab = "elements";
875
- draw();
876
- }
877
- const inspectCard = element("div", {
878
- class: "inspect-card",
879
- role: "tooltip"
880
- });
881
- const hoverBox = element("div", { class: "outline" });
882
- let hovered;
883
- let hoverToken = 0;
884
- function onHover(event) {
885
- const target = event.target;
886
- if (!target?.closest || event.composedPath().includes(panel) || target === hovered) return;
887
- hovered = target;
888
- inspect(target);
889
- }
890
- async function inspect(target) {
891
- const token = ++hoverToken;
892
- const rect = target.getBoundingClientRect();
893
- hoverBox.style.cssText = `left:${rect.left}px;top:${rect.top}px;width:${rect.width}px;height:${rect.height}px`;
894
- root.append(hoverBox, inspectCard);
895
- const tag = target.tagName.toLowerCase();
896
- let classes = "";
897
- for (const name of [...target.classList].slice(0, 2)) classes += `.${name}`;
898
- 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)}`))];
899
- const anchored = target.closest("[b-b]");
900
- const [id = "", anchorText = "0"] = anchored?.getAttribute("b-b").split(":") ?? [];
901
- const scope = anchored ? findScope(id) : void 0;
902
- if (scope) {
903
- const { info, component: owner, place } = await findAnchor(scope, Number(anchorText));
904
- if (token !== hoverToken) return;
905
- 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"}`}`));
906
- const handled = target.closest("[b-on]");
907
- if (handled && anchored.contains(handled)) {
908
- const handlers = element("div", { class: "card-pills" });
909
- for (const raw of (handled.getAttribute("b-on") ?? "").split(/\s+/)) {
910
- if (!raw) continue;
911
- const [head] = raw.split("=");
912
- handlers.append(pill(head));
913
- }
914
- rows.push(handlers);
915
- }
916
- if (place && place.reads.length > 0) rows.push(element("div", { class: "card-pills" }, ...drawReads(scope, place.reads.slice(0, 4))));
917
- } else rows.push(element("div", { class: "sub" }, "Nothing in the browser updates this element."));
918
- rows.push(element("div", { class: "card-hint" }, "Click to see it in Elements · Esc to stop"));
919
- inspectCard.replaceChildren(...rows);
920
- const cardHeight = inspectCard.offsetHeight;
921
- const top = rect.bottom + 8 + cardHeight < window.innerHeight ? rect.bottom + 8 : Math.max(8, rect.top - 8 - cardHeight);
922
- const left = Math.min(Math.max(8, rect.left), window.innerWidth - inspectCard.offsetWidth - 8);
923
- inspectCard.style.cssText = `top:${top}px;left:${left}px`;
924
- }
925
- function onEscape(event) {
926
- if (event.key === "Escape") stopPicking();
927
- }
928
- endPick = () => stopPicking();
929
- function stopPicking() {
930
- pick.setAttribute("aria-pressed", "false");
931
- window.removeEventListener("click", onPick, true);
932
- window.removeEventListener("pointermove", onHover, true);
933
- window.removeEventListener("keydown", onEscape, true);
934
- document.documentElement.style.cursor = "";
935
- hovered = void 0;
936
- hoverToken++;
937
- hoverBox.remove();
938
- inspectCard.remove();
939
- }
940
- pick.addEventListener("click", () => {
941
- if (pick.getAttribute("aria-pressed") === "true") {
942
- stopPicking();
943
- return;
944
- }
945
- pick.setAttribute("aria-pressed", "true");
946
- document.documentElement.style.cursor = "crosshair";
947
- window.addEventListener("click", onPick, true);
948
- window.addEventListener("pointermove", onHover, true);
949
- window.addEventListener("keydown", onEscape, true);
950
- });
951
- /** The scopes of component instances. */
952
- function roots() {
953
- const result = [];
954
- for (const scope of state.scopes?.values() ?? []) if (scope.m !== void 0) result.push(scope);
955
- return result;
956
- }
957
- function findScope(id) {
958
- return state.scopes?.get(/^-?\d+$/.test(id) ? Number(id) : id);
959
- }
960
- /** The header and the counts of the tabs. */
961
- function drawChrome() {
962
- for (const button of nav.querySelectorAll(".tab")) button.setAttribute("aria-selected", String(button.dataset.tab === tab));
963
- const list = roots();
964
- routeText.textContent = location.pathname + location.search;
965
- stats.textContent = [
966
- `${collectModules(list).size} components`,
967
- `${state.scopes?.size ?? 0} scopes`,
968
- `state ${kilobytes(stateBytes())}`
969
- ].join(" · ");
970
- const waiting = countBlocks(state.blocks.values(), "waiting");
971
- const counts = {
972
- errors: [state.errors.length, "Errors"],
973
- scopes: [collectModules(list).size],
974
- log: [state.log.length],
975
- blocks: waiting > 0 ? [waiting, "Blocks that wait for their trigger"] : [state.blocks.size]
976
- };
977
- for (const [name, badge] of badges) {
978
- const [count = 0, warning] = counts[name] ?? [];
979
- badge.textContent = count > 0 ? String(count) : "";
980
- let kind = warning ? " warn" : "";
981
- if (name === "errors") kind = " error";
982
- badge.className = `badge${kind}`;
983
- badge.title = warning ?? "";
984
- }
985
- }
986
- /** A select of the components on the page, for Graph and Report. */
987
- function chooser(current) {
988
- const select = element("select", { "aria-label": "Component" });
989
- for (const id of collectModules(roots())) {
990
- const info = known.get(id);
991
- const option = element("option", { value: id }, info ? `${info.name} · ${info.file}` : id);
992
- option.selected = id === current;
993
- select.append(option);
994
- }
995
- select.addEventListener("change", () => {
996
- selected = select.value;
997
- graphNode = void 0;
998
- draw();
999
- });
1000
- return select;
1001
- }
1002
- async function drawErrors() {
1003
- if (state.errors.length === 0) {
1004
- 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."));
1005
- return;
1006
- }
1007
- if (!selectedError || !state.errors.includes(selectedError)) {
1008
- selectedError = state.errors.at(-1);
1009
- selectedFrame = -1;
1010
- }
1011
- const error = selectedError;
1012
- const list = element("div", { class: "list" });
1013
- for (const entry of state.errors.toReversed()) {
1014
- const button = element("button", {
1015
- class: "error-row",
1016
- "aria-current": String(entry === error)
1017
- }, element("span", { class: "text" }, entry.message.split("\n")[0]), element("span", { class: "when" }, `${entry.source} · ${seconds(entry.time)}`));
1018
- button.addEventListener("click", () => {
1019
- selectedError = entry;
1020
- selectedFrame = -1;
1021
- draw();
1022
- });
1023
- list.append(button);
1024
- }
1025
- const clear = iconButton("trash", "Clear");
1026
- clear.addEventListener("click", () => {
1027
- state.errors.length = 0;
1028
- state.errorCount?.();
1029
- draw();
1030
- });
1031
- list.append(element("div", { style: "margin-top: 8px" }, clear));
1032
- const frames = await mapFrames(parseFrames(error.stack), frameUrls(error.stack));
1033
- if (selectedFrame === -1) {
1034
- selectedFrame = -2;
1035
- if (!error.loc) {
1036
- selectedFrame = -1;
1037
- for (const [index, item] of frames.entries()) if (!item.library && !item.compiled) {
1038
- selectedFrame = index;
1039
- break;
1040
- }
1041
- }
1042
- }
1043
- const frame = selectedFrame >= 0 ? frames[selectedFrame] : void 0;
1044
- const place = selectedFrame === -2 ? error.loc : frame;
1045
- const detail = element("div", { class: "detail" });
1046
- detail.append(element("pre", { class: "error-message" }, error.message), element("div", { class: "toolbar" }, pill(error.source, error.source === "browser" ? "yellow" : "red"), error.plugin ? pill(`plugin ${error.plugin}`) : "", place && !("url" in place && place.url) ? open(place) : ""));
1047
- if (place) detail.append(await codeView(place, error.frame));
1048
- else if (error.frame) detail.append(element("div", { class: "code" }, element("pre", { class: "plain" }, error.frame)));
1049
- if (frames.length > 0) {
1050
- const stack = element("div", { class: "frames" });
1051
- for (const [index, item] of frames.entries()) {
1052
- const button = element("button", {
1053
- class: `frame${item.library ? " library" : ""}`,
1054
- "aria-current": String(index === selectedFrame),
1055
- title: item.compiled ? "The lines of code that the browser ran" : "Show this code"
1056
- }, element("span", { class: "fn" }, item.fn), element("span", { class: "where" }, `${item.file}:${item.line}:${item.column}`));
1057
- button.addEventListener("click", () => {
1058
- selectedFrame = index;
1059
- draw();
1060
- });
1061
- stack.append(button);
1062
- }
1063
- detail.append(element("h3", {}, "Stack"), stack);
1064
- }
1065
- body.replaceChildren(element("div", { class: "split" }, list, detail));
1066
- }
1067
- /** A button that opens a place of a file in the editor. */
1068
- function open(place) {
1069
- const button = element("button", {
1070
- class: "link",
1071
- title: "Open in the editor"
1072
- }, `${place.file.replace(/^.*\/(src|test|routes)\//, "$1/")}:${place.line}:${place.column}`, icon("open", 12));
1073
- button.addEventListener("click", () => {
1074
- fetch(`/__open-in-editor?file=${encodeURIComponent(`${place.file}:${place.line}:${place.column}`)}`);
1075
- });
1076
- return button;
1077
- }
1078
- async function drawOverview() {
1079
- const list = roots();
1080
- const ids = [...collectModules(list)];
1081
- const infos = await loadComponents(state, ids);
1082
- const blocks = [...state.blocks.values()];
1083
- let handlers = 0;
1084
- let calls = 0;
1085
- for (const entry of state.log) if (entry.kind === "handler") handlers++;
1086
- else if (entry.kind === "call") calls++;
1087
- const table = element("table", { class: "rows" }, row([
1088
- "component",
1089
- "file",
1090
- "instances",
1091
- "scopes"
1092
- ], "th"));
1093
- for (const [index, id] of ids.entries()) {
1094
- const info = infos[index];
1095
- const instances = [];
1096
- let scopeCount = 0;
1097
- for (const scope of list) if (scope.m === id) {
1098
- instances.push(scope);
1099
- scopeCount += countScopes(scope);
1100
- }
1101
- const name = element("button", {
1102
- class: "link",
1103
- title: "Show its scopes"
1104
- }, info?.name ?? id);
1105
- name.addEventListener("click", () => {
1106
- selected = id;
1107
- selectedScope = instances[0]?.id;
1108
- tab = "scopes";
1109
- draw();
1110
- });
1111
- table.append(row([
1112
- name,
1113
- source(info),
1114
- String(instances.length),
1115
- String(scopeCount)
1116
- ]));
1117
- }
1118
- body.replaceChildren(element("div", {
1119
- class: "kv",
1120
- style: "margin-bottom: 12px"
1121
- }, 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."));
1122
- }
1123
- /** A slot with its name, type and value. A value that JSON can hold can be edited. */
1124
- function drawSlot(scope, slot, name) {
1125
- const value = scope.s[slot];
1126
- const cell = element("td");
1127
- const line = element("tr", { class: "slot" }, element("td", { class: "name" }, name), element("td", { class: "type" }, readType(value)), cell);
1128
- if (editing?.scope === scope.id && editing.slot === slot) {
1129
- const input = element("input", { "aria-label": `New value of ${name}` });
1130
- input.value = JSON.stringify(value) ?? "";
1131
- input.addEventListener("keydown", (event) => {
1132
- if (event.key === "Enter") {
1133
- editing = void 0;
1134
- state.set?.(scope, slot, parseValue(input.value));
1135
- draw();
1136
- } else if (event.key === "Escape") {
1137
- editing = void 0;
1138
- draw();
1139
- }
1140
- });
1141
- cell.append(input);
1142
- queueMicrotask(() => input.focus());
1143
- return line;
1144
- }
1145
- const canEdit = editable(value) && state.set !== void 0;
1146
- const text = element("span", { class: canEdit ? "value" : "value fixed" }, preview(value));
1147
- if (canEdit) {
1148
- text.title = "Click to edit. Enter JSON, or text for a string.";
1149
- text.addEventListener("click", () => {
1150
- editing = {
1151
- scope: scope.id,
1152
- slot
1153
- };
1154
- draw();
1155
- });
1156
- }
1157
- cell.append(text);
1158
- return line;
1159
- }
1160
- async function drawScopes() {
1161
- const list = roots();
1162
- const listed = [];
1163
- for (const scope of list) listed.push(scope.m);
1164
- const infos = await loadComponents(state, listed);
1165
- if (list.length === 0) {
1166
- body.replaceChildren(element("div", { class: "empty" }, "No scopes yet. The first event loads them."));
1167
- return;
1168
- }
1169
- const current = selectedScope !== void 0 && state.scopes?.get(selectedScope) || list[0];
1170
- const search = element("input", {
1171
- type: "search",
1172
- placeholder: "Filter components and values",
1173
- "aria-label": "Filter scopes"
1174
- });
1175
- search.value = filter;
1176
- search.addEventListener("input", () => {
1177
- filter = search.value;
1178
- drawScopes().then(() => {
1179
- const next = body.querySelector("input[type=\"search\"]");
1180
- next?.focus();
1181
- next?.setSelectionRange(filter.length, filter.length);
1182
- });
1183
- });
1184
- const tree = element("div", { class: "list" }, search);
1185
- function visit(scope, info, depth) {
1186
- const label = scope.m === void 0 ? `${info?.scopes[scope.k]?.label ?? "scope"}${scope.h ? " · hidden" : ""}` : info?.name ?? scope.m;
1187
- const classes = ["tree-row"];
1188
- if (scope.m !== void 0) classes.push("component");
1189
- if (state.written.has(scope.id)) classes.push("written");
1190
- const button = element("button", {
1191
- class: classes.join(" "),
1192
- style: `padding-left: ${6 + depth * 14}px`,
1193
- "aria-current": String(scope === current)
1194
- }, element("span", {}, label), element("span", { class: "file" }, scope.m === void 0 ? `#${scope.id}` : info?.file ?? ""));
1195
- button.addEventListener("click", () => {
1196
- selectedScope = scope.id;
1197
- selected = findRootScope(scope).m;
1198
- draw();
1199
- });
1200
- button.addEventListener("mouseenter", () => outline(scope.id));
1201
- button.addEventListener("mouseleave", () => outline());
1202
- tree.append(button);
1203
- for (const child of scope.children ?? []) if (child.m === void 0) visit(child, info, depth + 1);
1204
- }
1205
- const needle = filter.trim().toLowerCase();
1206
- for (const [index, scope] of list.entries()) {
1207
- const info = infos[index];
1208
- if (needle && !`${info?.name ?? scope.m} ${info?.file ?? ""}`.toLowerCase().includes(needle)) {
1209
- let matched = false;
1210
- for (const value of scope.s) if (preview(value).toLowerCase().includes(needle)) {
1211
- matched = true;
1212
- break;
1213
- }
1214
- if (!matched) continue;
1215
- }
1216
- visit(scope, info, 0);
1217
- }
1218
- const component = findRootScope(current);
1219
- const info = known.get(component.m ?? "");
1220
- const plan = info?.scopes[current.k];
1221
- const slots = element("table", { class: "rows slots" }, row([
1222
- "name",
1223
- "type",
1224
- "value"
1225
- ], "th"));
1226
- for (let slot = 0; slot < current.s.length; slot++) slots.append(drawSlot(current, slot, plan?.slots[slot] ?? `slot ${slot}`));
1227
- const graph = iconButton("graph", "Show the graph");
1228
- graph.addEventListener("click", () => {
1229
- selected = component.m;
1230
- tab = "graph";
1231
- draw();
1232
- });
1233
- 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."));
1234
- body.replaceChildren(element("div", { class: "split" }, tree, detail));
1235
- body.querySelector("[aria-current=\"true\"]")?.scrollIntoView({ block: "nearest" });
1236
- }
1237
- /** What the dev server says about an anchor of a scope, with the component that has it. */
1238
- async function findAnchor(scope, anchor) {
1239
- const component = findRootScope(scope);
1240
- const info = component.m ? await componentInfo(state, component.m) : void 0;
1241
- return {
1242
- info,
1243
- component,
1244
- place: info?.anchors?.[scope.k]?.[anchor]
1245
- };
1246
- }
1247
- /** The names that an anchor reads, with their values in the scope. */
1248
- function drawReads(scope, reads) {
1249
- const pills = [];
1250
- for (const name of reads) {
1251
- const value = readValue(scope, name);
1252
- pills.push(element("span", {
1253
- class: "pill",
1254
- style: "margin: 0 4px 2px 0"
1255
- }, element("span", { class: "name" }, name), value === void 0 ? "" : ` = ${value}`));
1256
- }
1257
- return pills;
1258
- }
1259
- /** The handlers of an element, from its `b-on`. */
1260
- function drawHandlers(target) {
1261
- const table = element("table", { class: "rows" }, row(["event", "handler"], "th"));
1262
- for (const raw of (target.getAttribute("b-on") ?? "").split(/\s+/)) {
1263
- if (!raw) continue;
1264
- const [head, ref = ""] = raw.split("=");
1265
- const [type, ...modifiers] = head.split(":");
1266
- const [component, name = ""] = ref.split("@")[0].split("#");
1267
- const info = known.get(component);
1268
- table.append(row([element("span", { class: "mono" }, [type, ...modifiers].join(":")), element("span", { class: "mono" }, `${info?.name ?? component} ${name}`)]));
1269
- }
1270
- return table;
1271
- }
1272
- async function drawElements() {
1273
- if (!picked?.isConnected) {
1274
- const start = iconButton("pick", "Pick an element");
1275
- start.addEventListener("click", () => pick.click());
1276
- body.replaceChildren(element("h2", {}, "Elements"), element("p", { class: "sub" }, "Pick an element of the page to see the component that renders it, its place in the file, its handlers and the values that update it."), start);
1277
- return;
1278
- }
1279
- const tag = `<${picked.tagName.toLowerCase()}>`;
1280
- const content = element("div");
1281
- const anchored = picked.closest("[b-b]");
1282
- const [id = "", anchorText = "0"] = anchored?.getAttribute("b-b").split(":") ?? [];
1283
- const scope = anchored ? findScope(id) : void 0;
1284
- if (scope) {
1285
- const anchor = Number(anchorText);
1286
- const { info, component, place } = await findAnchor(scope, anchor);
1287
- const scopeButton = element("button", {
1288
- class: "link",
1289
- title: "Show the scope"
1290
- }, `scope ${scope.id}${info?.scopes[scope.k] ? ` · ${info.scopes[scope.k].label}` : ""}`);
1291
- scopeButton.addEventListener("click", () => {
1292
- selectedScope = scope.id;
1293
- tab = "scopes";
1294
- draw();
1295
- });
1296
- content.append(element("h2", {}, picked === anchored ? place?.label ?? tag : `${tag} in ${place?.label ?? "an element"}`, element("span", { class: "sub" }, ` · ${info?.name ?? component.m}`)), element("div", { class: "kv" }, element("span", {}, "source"), element("span", {}, place?.at ? source(info, place.at) : "—"), element("span", {}, "scope"), element("span", {}, scopeButton), element("span", {}, "anchor"), element("span", { class: "mono" }, String(anchor)), element("span", {}, "reads"), element("span", {}, ...place && place.reads.length > 0 ? drawReads(scope, place.reads) : ["—"])));
1297
- const handled = picked.closest("[b-on]");
1298
- if (handled && anchored.contains(handled)) content.append(element("h3", {}, "Handlers"), drawHandlers(handled));
1299
- } else content.append(element("h2", {}, tag), element("div", { class: "empty" }, anchored ? `Scope ${id} is not in the browser yet.` : "Nothing in the browser updates this element or the elements around it."));
1300
- const markers = [];
1301
- const walker = document.createTreeWalker(picked, NodeFilter.SHOW_COMMENT);
1302
- for (let node = walker.nextNode(); node; node = walker.nextNode()) {
1303
- const data = node.data;
1304
- const match = /^[tb](-?[\d.]+):(\d+)/.exec(data);
1305
- const markerScope = match && findScope(match[1]);
1306
- if (markerScope) markers.push({
1307
- data,
1308
- scope: markerScope,
1309
- anchor: Number(match[2])
1310
- });
1311
- }
1312
- const pending = [];
1313
- for (const marker of markers) pending.push(findAnchor(marker.scope, marker.anchor));
1314
- const places = await Promise.all(pending);
1315
- const inside = element("table", { class: "rows" }, row([
1316
- "marker",
1317
- "source",
1318
- "reads"
1319
- ], "th"));
1320
- for (const [index, marker] of markers.entries()) {
1321
- const { info, place } = places[index];
1322
- inside.append(row([
1323
- element("span", { class: "mono" }, place?.label ?? marker.data),
1324
- place?.at ? source(info, place.at) : "",
1325
- element("span", {}, ...drawReads(marker.scope, place?.reads ?? []))
1326
- ]));
1327
- }
1328
- if (markers.length > 0) content.append(element("h3", {}, "Inside it"), inside);
1329
- body.replaceChildren(content);
1330
- }
1331
- let cooling;
1332
- async function drawGraph() {
1333
- const id = selected ?? roots()[0]?.m;
1334
- const info = id ? await componentInfo(state, id) : void 0;
1335
- if (!id || !info) {
1336
- body.replaceChildren(element("div", { class: "empty" }, "No component yet."));
1337
- return;
1338
- }
1339
- if (!info.graph) {
1340
- body.replaceChildren(element("div", { class: "toolbar" }, chooser(id)), element("div", { class: "empty" }, "The dev server sent no graph. It runs an older brumate than this panel: restart it."));
1341
- return;
1342
- }
1343
- const { nodes, edges } = info.graph;
1344
- let instance;
1345
- for (const scope of roots()) if (scope.m === id) {
1346
- instance = scope;
1347
- break;
1348
- }
1349
- const scopeOfNode = /* @__PURE__ */ new Map();
1350
- function visit(scope) {
1351
- if (!scopeOfNode.has(scope.k)) scopeOfNode.set(scope.k, scope);
1352
- for (const child of scope.children ?? []) if (child.m === void 0) visit(child);
1353
- }
1354
- if (instance) visit(instance);
1355
- const now = performance.now();
1356
- const hot = /* @__PURE__ */ new Set();
1357
- for (const entry of state.log) if (entry.write?.component === id && now - entry.time < HOT_MS) {
1358
- for (const [index, node] of nodes.entries()) if (node.scope === entry.write.k && node.slot === entry.write.slot) hot.add(index);
1359
- }
1360
- for (let grew = true; grew;) {
1361
- grew = false;
1362
- for (const [from, to] of edges) if (hot.has(from) && !hot.has(to)) {
1363
- hot.add(to);
1364
- grew = true;
1365
- }
1366
- }
1367
- const parts = [];
1368
- for (const node of nodes) {
1369
- const at = node.at ? `${node.at.line}:${node.at.column}` : void 0;
1370
- const owner = node.slot === void 0 ? void 0 : scopeOfNode.get(node.scope);
1371
- const value = owner && node.slot !== void 0 ? preview(owner.s[node.slot]) : void 0;
1372
- let meta = at ? `${node.kind} · ${at}` : node.kind;
1373
- if (value !== void 0) meta = `= ${value}`;
1374
- parts.push({
1375
- name: node.label,
1376
- meta,
1377
- value,
1378
- at
1379
- });
1380
- }
1381
- function getNodeWidth(index) {
1382
- return Math.min(262, Math.max(112, 36 + 7 * Math.max(clip(parts[index].name).length, clip(parts[index].meta).length)));
1383
- }
1384
- const position = layoutGraph(nodes, edges, getNodeWidth);
1385
- const related = /* @__PURE__ */ new Set();
1386
- if (graphNode !== void 0 && graphNode < nodes.length) {
1387
- related.add(graphNode);
1388
- for (const [from, to] of [[0, 1], [1, 0]]) {
1389
- const queue = [graphNode];
1390
- while (queue.length > 0) {
1391
- const next = queue.pop();
1392
- for (const edge of edges) if (edge[from] === next && !related.has(edge[to])) {
1393
- related.add(edge[to]);
1394
- queue.push(edge[to]);
1395
- }
1396
- }
1397
- }
1398
- }
1399
- let graphWidth = 0;
1400
- let graphHeight = 0;
1401
- for (const place of position) {
1402
- graphWidth = Math.max(graphWidth, place.x + place.width);
1403
- graphHeight = Math.max(graphHeight, place.y);
1404
- }
1405
- graphWidth += 16;
1406
- graphHeight += 56;
1407
- const layer = svg("g", { class: "layer" });
1408
- for (const [from, to] of edges) {
1409
- const a = position[from];
1410
- const b = position[to];
1411
- const x1 = a.x + a.width;
1412
- const y1 = a.y + 19;
1413
- const x2 = b.x - 3;
1414
- const y2 = b.y + 19;
1415
- const bend = Math.max(28, (x2 - x1) / 2);
1416
- const classes = ["edge"];
1417
- if (hot.has(from) && hot.has(to)) classes.push("hot-edge");
1418
- else if (related.size > 0) classes.push(related.has(from) && related.has(to) ? "lit" : "faded");
1419
- layer.append(svg("path", {
1420
- class: classes.join(" "),
1421
- d: `M${x1},${y1} C${x1 + bend},${y1} ${x2 - bend},${y2} ${x2},${y2}`,
1422
- "marker-end": "url(#arrow)"
1423
- }));
1424
- }
1425
- for (const [index, node] of nodes.entries()) {
1426
- const { x, y, width: nodeWidth } = position[index];
1427
- const part = parts[index];
1428
- const classes = ["node", `k-${node.kind}`];
1429
- if (hot.has(index)) classes.push("hot");
1430
- if (graphNode === index) classes.push("selected");
1431
- if (related.size > 0 && !related.has(index)) classes.push("faded");
1432
- const name = svg("text", {
1433
- class: "name",
1434
- x: x + 23,
1435
- y: y + 16
1436
- });
1437
- name.textContent = clip(part.name);
1438
- const meta = svg("text", {
1439
- class: "meta",
1440
- x: x + 23,
1441
- y: y + 30
1442
- });
1443
- meta.textContent = clip(part.meta);
1444
- const title = svg("title", {});
1445
- title.textContent = `${node.kind} ${node.label}${part.value === void 0 ? "" : ` = ${part.value}`}${part.at ? `, line ${node.at.line}` : ""}`;
1446
- const group = svg("g", {
1447
- class: classes.join(" "),
1448
- "data-node": index
1449
- }, svg("rect", {
1450
- class: "box",
1451
- x,
1452
- y,
1453
- width: nodeWidth,
1454
- height: 38,
1455
- rx: 7
1456
- }), svg("circle", {
1457
- class: "kind",
1458
- cx: x + 13,
1459
- cy: y + 12.5,
1460
- r: 3.5
1461
- }), name, meta, title);
1462
- group.addEventListener("click", (event) => {
1463
- event.stopPropagation();
1464
- graphNode = graphNode === index ? void 0 : index;
1465
- draw();
1466
- });
1467
- layer.append(group);
1468
- }
1469
- const canvas = svg("svg", {
1470
- role: "img",
1471
- "aria-label": `Graph of ${info.name}`
1472
- }, svg("defs", {}, svg("marker", {
1473
- id: "arrow",
1474
- viewBox: "0 0 8 8",
1475
- refX: 7,
1476
- refY: 4,
1477
- markerWidth: 6,
1478
- markerHeight: 6,
1479
- orient: "auto"
1480
- }, svg("path", {
1481
- d: "M0,0 L8,4 L0,8 z",
1482
- fill: "#8a8280"
1483
- }))), layer);
1484
- const frame = element("div", { class: "graph-view" }, canvas);
1485
- function apply() {
1486
- layer.setAttribute("transform", `translate(${view.x},${view.y}) scale(${view.scale})`);
1487
- }
1488
- function fit() {
1489
- const box = frame.getBoundingClientRect();
1490
- if (box.width === 0) return;
1491
- view.scale = Math.min(1.2, Math.max(.3, Math.min(box.width / graphWidth, box.height / graphHeight)));
1492
- view.x = (box.width - graphWidth * view.scale) / 2;
1493
- view.y = Math.max(0, (box.height - graphHeight * view.scale) / 2);
1494
- apply();
1495
- }
1496
- function zoomAt(factor, px, py) {
1497
- const next = Math.min(3, Math.max(.2, view.scale * factor));
1498
- view.x = px - (px - view.x) * next / view.scale;
1499
- view.y = py - (py - view.y) * next / view.scale;
1500
- view.scale = next;
1501
- apply();
1502
- }
1503
- frame.addEventListener("wheel", (event) => {
1504
- event.preventDefault();
1505
- const box = frame.getBoundingClientRect();
1506
- zoomAt(event.deltaY < 0 ? 1.1 : 1 / 1.1, event.clientX - box.left, event.clientY - box.top);
1507
- }, { passive: false });
1508
- frame.addEventListener("pointerdown", (event) => {
1509
- if (event.target.closest(".node, button")) return;
1510
- const start = {
1511
- x: event.clientX - view.x,
1512
- y: event.clientY - view.y
1513
- };
1514
- frame.classList.add("dragging");
1515
- function move(next) {
1516
- view.x = next.clientX - start.x;
1517
- view.y = next.clientY - start.y;
1518
- apply();
1519
- }
1520
- function up() {
1521
- frame.classList.remove("dragging");
1522
- window.removeEventListener("pointermove", move);
1523
- window.removeEventListener("pointerup", up);
1524
- }
1525
- window.addEventListener("pointermove", move);
1526
- window.addEventListener("pointerup", up);
1527
- });
1528
- canvas.addEventListener("click", () => {
1529
- if (graphNode !== void 0) {
1530
- graphNode = void 0;
1531
- draw();
1532
- }
1533
- });
1534
- function zoomButton(name, title, factor) {
1535
- const button = iconButton(name, title, {}, true);
1536
- button.addEventListener("click", () => {
1537
- const box = frame.getBoundingClientRect();
1538
- zoomAt(factor, box.width / 2, box.height / 2);
1539
- });
1540
- return button;
1541
- }
1542
- const fitButton = iconButton("fit", "Fit the graph in view", {}, true);
1543
- fitButton.addEventListener("click", fit);
1544
- frame.append(element("div", { class: "zoom" }, zoomButton("minus", "Zoom out", 1 / 1.2), zoomButton("plus", "Zoom in", 1.2), fitButton));
1545
- const side = element("div", { class: "graph-side" });
1546
- if (graphNode !== void 0 && graphNode < nodes.length) {
1547
- const node = nodes[graphNode];
1548
- const part = parts[graphNode];
1549
- function list(indexes) {
1550
- if (indexes.length === 0) return element("div", { class: "sub" }, "nothing");
1551
- const labels = [];
1552
- for (const index of indexes) {
1553
- const { label } = nodes[index];
1554
- const at = parts[index].at;
1555
- let shared = false;
1556
- for (const [i, other] of nodes.entries()) if (i !== index && other.label === label) {
1557
- shared = true;
1558
- break;
1559
- }
1560
- labels.push(element("div", { class: "mono" }, shared && at ? `${label} ${at}` : label));
1561
- }
1562
- return element("div", {}, ...labels);
1563
- }
1564
- const reads = [];
1565
- const readBy = [];
1566
- for (const [from, to] of edges) {
1567
- if (to === graphNode) reads.push(from);
1568
- if (from === graphNode) readBy.push(to);
1569
- }
1570
- const color = nodeColor(node.kind, node.slot);
1571
- side.append(element("h2", {}, part.name), element("div", { class: "toolbar" }, pill(node.kind, color), node.at ? place(info, node.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));
1572
- } else side.append(element("h2", {}, info.name), element("p", {
1573
- class: "sub",
1574
- style: "margin-top: 0"
1575
- }, "What changes in the browser, and what reads what, left to right. Click a node to follow it. Drag to pan, and scroll to zoom."), element("div", {
1576
- class: "legend",
1577
- style: "flex-direction: column; align-items: flex-start; gap: 4px"
1578
- }, key("var(--blue)", "signals and props"), key("var(--purple)", "memos"), key("var(--faint)", "markup"), key("var(--green)", "effects"), key("var(--yellow)", "what a change reached")));
1579
- body.replaceChildren(element("div", { class: "toolbar" }, chooser(id), element("span", { class: "sub" }, `${nodes.length} nodes · ${edges.length} edges`)), nodes.length > 0 ? element("div", { class: "graph-wrap" }, frame, side) : element("div", { class: "empty" }, "Nothing in this component changes in the browser."));
1580
- if (view.fitted === id) apply();
1581
- else {
1582
- view = {
1583
- x: 0,
1584
- y: 0,
1585
- scale: 1,
1586
- fitted: id
1587
- };
1588
- apply();
1589
- requestAnimationFrame(fit);
1590
- }
1591
- if (hot.size > 0) {
1592
- clearTimeout(cooling);
1593
- cooling = setTimeout(() => state.changed?.(), HOT_MS);
1594
- }
1595
- }
1596
- function drawLog() {
1597
- const filters = element("div", { class: "toolbar filters" });
1598
- for (const kind of KINDS) {
1599
- const box = element("input", { type: "checkbox" });
1600
- box.checked = shown.has(kind);
1601
- box.addEventListener("change", () => {
1602
- if (box.checked) shown.add(kind);
1603
- else shown.delete(kind);
1604
- draw();
1605
- });
1606
- filters.append(element("label", { class: `kind-${kind}` }, box, kind));
1607
- }
1608
- const search = element("input", {
1609
- type: "search",
1610
- placeholder: "Search the log",
1611
- "aria-label": "Search the log"
1612
- });
1613
- search.value = logSearch;
1614
- search.addEventListener("input", () => {
1615
- logSearch = search.value;
1616
- drawLog();
1617
- const next = body.querySelector("input[type=\"search\"]");
1618
- next?.focus();
1619
- next?.setSelectionRange(logSearch.length, logSearch.length);
1620
- });
1621
- const pause = iconButton(paused ? "play" : "pause", paused ? "Resume" : "Pause", { "aria-pressed": String(paused) });
1622
- pause.addEventListener("click", () => {
1623
- paused = !paused;
1624
- frozen = paused ? [...state.log] : void 0;
1625
- draw();
1626
- });
1627
- const clear = iconButton("trash", "Clear");
1628
- clear.addEventListener("click", () => {
1629
- state.log.length = 0;
1630
- frozen = paused ? [] : void 0;
1631
- draw();
1632
- });
1633
- filters.append(search, pause, clear);
1634
- const needle = logSearch.trim().toLowerCase();
1635
- const entries = [];
1636
- for (const entry of frozen ?? state.log) if (shown.has(entry.kind) && (!needle || readText(entry).toLowerCase().includes(needle))) entries.push(entry);
1637
- const list = element("table", { class: "rows" });
1638
- for (const entry of entries.toReversed()) list.append(element("tr", { class: `entry ${entry.kind}` }, element("td", { class: "time" }, seconds(entry.time)), element("td", {
1639
- class: `kind-${entry.kind}`,
1640
- style: "width: 1%"
1641
- }, entry.kind), element("td", {}, readText(entry))));
1642
- body.replaceChildren(filters, entries.length > 0 ? list : element("div", { class: "empty" }, "Nothing to show."));
1643
- }
1644
- async function drawState() {
1645
- const scopes = [];
1646
- const ids = /* @__PURE__ */ new Set();
1647
- for (const scope of state.scopes?.values() ?? []) if (typeof scope.id !== "number" || scope.id >= 0) {
1648
- scopes.push(scope);
1649
- const id = findRootScope(scope).m ?? "";
1650
- if (id) ids.add(id);
1651
- }
1652
- await loadComponents(state, ids);
1653
- const slots = /* @__PURE__ */ new Map();
1654
- for (const scope of scopes) {
1655
- const component = findRootScope(scope).m ?? "";
1656
- for (const [slot, value] of scope.s.entries()) {
1657
- const key = `${component}:${scope.k}:${slot}`;
1658
- const entry = slots.get(key) ?? {
1659
- component,
1660
- k: scope.k,
1661
- slot,
1662
- bytes: 0,
1663
- count: 0
1664
- };
1665
- entry.bytes += measureSize(value);
1666
- entry.count++;
1667
- slots.set(key, entry);
1668
- }
1669
- }
1670
- const sorted = [...slots.values()].toSorted((a, b) => b.bytes - a.bytes);
1671
- const first = document.querySelector("script[b-state][b-scopes]")?.textContent?.length ?? 0;
1672
- const table = element("table", { class: "rows" }, row([
1673
- "component",
1674
- "scope",
1675
- "value",
1676
- "instances",
1677
- "about",
1678
- "read in the browser by"
1679
- ], "th"));
1680
- for (const entry of sorted.slice(0, 200)) {
1681
- const info = known.get(entry.component);
1682
- const layout = info?.scopes[entry.k];
1683
- const readers = layout?.readers?.[entry.slot] ?? [];
1684
- const tr = element("tr", {}, element("td", {}, info?.name ?? entry.component), element("td", { class: "mono" }, layout?.label ?? String(entry.k)), element("td", { class: "mono" }, layout?.slots[entry.slot] ?? `slot ${entry.slot}`), element("td", { class: "mono" }, String(entry.count)), element("td", {
1685
- class: "mono",
1686
- style: "white-space: nowrap"
1687
- }, kilobytes(entry.bytes)), element("td", { class: "mono" }, readers.join(", ") || "—"));
1688
- if (entry.bytes > 1024) {
1689
- tr.className = "large";
1690
- tr.title = "More than 1 kB. Send only the fields that the browser reads.";
1691
- }
1692
- table.append(tr);
1693
- }
1694
- body.replaceChildren(element("div", { class: "cards" }, card("Page state", kilobytes(stateBytes()), "every state record of the page"), card("First record", kilobytes(first), "the state that the page started with"), card("Values", String(slots.size), `in ${scopes.length} scopes`)), element("div", {
1695
- class: "legend",
1696
- style: "margin: 10px 0 6px"
1697
- }, 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."));
1698
- }
1699
- /** The effects and `$client` callbacks, with how often each ran and when its cleanup ran. */
1700
- async function drawEffects() {
1701
- const effects = [...state.effects.values()];
1702
- const ids = /* @__PURE__ */ new Set();
1703
- for (const effect of effects) ids.add(effect.component);
1704
- await loadComponents(state, ids);
1705
- const now = performance.now();
1706
- function lastSecond(recent) {
1707
- let count = 0;
1708
- for (const at of recent) if (now - at < 1e3) count++;
1709
- return count;
1710
- }
1711
- const sorted = effects.toSorted((a, b) => lastSecond(b.recent) - lastSecond(a.recent) || b.runs - a.runs);
1712
- const table = element("table", { class: "rows" }, row([
1713
- "component",
1714
- "scope",
1715
- "name",
1716
- "runs",
1717
- "last second",
1718
- "time",
1719
- "cleanups",
1720
- "last run"
1721
- ], "th"));
1722
- for (const effect of sorted) {
1723
- const info = known.get(effect.component);
1724
- const recent = lastSecond(effect.recent);
1725
- const last = effect.recent.at(-1);
1726
- const tr = element("tr", {}, element("td", {}, info?.name ?? effect.component), element("td", { class: "mono" }, info?.scopes[effect.k]?.label ?? String(effect.scope)), element("td", {}, pill(effect.name.startsWith("c") ? "$client" : "$effect", effect.name.startsWith("c") ? "purple" : "blue"), " ", element("span", { class: "mono" }, effect.name)), element("td", { class: "mono" }, String(effect.runs)), element("td", { class: "mono" }, String(recent)), element("td", { class: "mono" }, ms(effect.time)), element("td", { class: "mono" }, String(effect.cleanups)), element("td", { class: "mono" }, last === void 0 ? "" : `${seconds(now - last)} ago`));
1727
- if (recent >= 10) {
1728
- tr.className = "busy";
1729
- tr.title = "It ran 10 times or more in the last second. Check what it reads.";
1730
- } else if (!effect.active) {
1731
- tr.className = "ended";
1732
- tr.title = "Its cleanup ran, and it has not run again, such as in a scope that went.";
1733
- }
1734
- table.append(tr);
1735
- }
1736
- let active = 0;
1737
- let runs = 0;
1738
- let busy = 0;
1739
- for (const effect of effects) {
1740
- if (effect.active) active++;
1741
- runs += effect.runs;
1742
- if (lastSecond(effect.recent) >= 10) busy++;
1743
- }
1744
- 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."));
1745
- }
1746
- /**
1747
- * The client navigations of the page, newest first: the routes that
1748
- * stayed, those that were replaced, or the whole page, and how far the
1749
- * IDs of the new page moved.
1750
- */
1751
- async function drawNavigation() {
1752
- const list = state.navigations.toReversed();
1753
- const items = [];
1754
- for (const navigation of list) {
1755
- const path = new URL(navigation.url).pathname + new URL(navigation.url).search;
1756
- const routes = element("div", { class: "routes" });
1757
- 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."));
1758
- else {
1759
- for (const key of navigation.kept) routes.append(element("div", { class: "mono" }, pill("kept", "green"), " ", key));
1760
- for (const change of navigation.replaced) routes.append(element("div", { class: "mono" }, pill("replaced", "yellow"), ` ${change.slot}: ${change.from} → ${change.to}`));
1761
- }
1762
- 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));
1763
- }
1764
- 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.")]);
1765
- }
1766
- /**
1767
- * What the server did for the last page that loaded: the render until the
1768
- * page could stream, each memo that loaded and each server function call,
1769
- * each `#loading` body, and the rest of the stream, on one scale. The
1770
- * server writes it at the end of the page, in development.
1771
- */
1772
- async function drawServer() {
1773
- const script = [...document.querySelectorAll("script[b-trace]")].at(-1);
1774
- let trace;
1775
- try {
1776
- trace = script ? JSON.parse(script.textContent ?? "") : void 0;
1777
- } catch {
1778
- trace = void 0;
1779
- }
1780
- if (!trace) {
1781
- body.replaceChildren(element("div", { class: "empty" }, "No trace yet. The dev server writes one at the end of each page that it renders."));
1782
- return;
1783
- }
1784
- const entries = trace.entries.toSorted((a, b) => a.start - b.start);
1785
- let total = 1;
1786
- for (const entry of entries) total = Math.max(total, entry.end ?? entry.start);
1787
- const table = element("table", { class: "rows" }, row([
1788
- "step",
1789
- "what",
1790
- "took",
1791
- `when, 0 to ${ms(total)}`
1792
- ], "th"));
1793
- for (const entry of entries) {
1794
- const end = entry.end ?? total;
1795
- const tr = element("tr", {}, element("td", {}, pill(entry.kind, entry.failed ? "red" : "")), element("td", { class: "mono" }, entry.label), element("td", { class: "mono" }, entry.end === void 0 ? "…" : ms(end - entry.start)), element("td", { class: "bar-cell" }, element("div", { class: "bar-track" }, element("span", {
1796
- class: `bar ${entry.failed ? "failed" : entry.kind}`,
1797
- style: `left:${entry.start / total * 100}%;width:${(end - entry.start) / total * 100}%`,
1798
- title: `${ms(entry.start)} to ${ms(end)}`
1799
- }))));
1800
- if (entry.failed) tr.className = "failed";
1801
- table.append(tr);
1802
- }
1803
- let render;
1804
- const counts = /* @__PURE__ */ new Map();
1805
- for (const entry of entries) {
1806
- if (entry.kind === "render" && !render) render = entry;
1807
- counts.set(entry.kind, (counts.get(entry.kind) ?? 0) + 1);
1808
- }
1809
- function count(kind) {
1810
- return counts.get(kind) ?? 0;
1811
- }
1812
- 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", {
1813
- class: "legend",
1814
- style: "margin: 10px 0 6px"
1815
- }, 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);
1816
- }
1817
- async function drawTimeline() {
1818
- const runs = state.timeline.toReversed().slice(0, 40);
1819
- const ids = /* @__PURE__ */ new Set();
1820
- for (const run of runs) ids.add(run.ref.split("#")[0]);
1821
- await loadComponents(state, ids);
1822
- if (runs.length === 0) {
1823
- 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."));
1824
- return;
1825
- }
1826
- const now = performance.now();
1827
- const totals = [];
1828
- for (const run of runs) totals.push((run.settled ?? now) - run.begun);
1829
- function segment(run, scale, start, end, kind, title) {
1830
- const left = Math.min(Math.max((start - run.begun) / scale * 100, 0), 100);
1831
- const width = Math.min(Math.max((end - start) / scale * 100, 0), 100 - left);
1832
- return element("span", {
1833
- class: `seg ${kind}`,
1834
- style: `left:${left}%;width:${width}%`,
1835
- title
1836
- });
1837
- }
1838
- const list = element("div");
1839
- for (const [index, run] of runs.entries()) {
1840
- const total = totals[index];
1841
- let last = run.settled ?? now;
1842
- for (const call of run.calls) last = Math.max(last, call.end ?? now);
1843
- for (const update of run.updates) last = Math.max(last, update.end);
1844
- const step = tickStep(Math.max(last - run.begun, 1) / 4);
1845
- const scale = Math.ceil(Math.max(last - run.begun, 1) / step) * step;
1846
- const ticks = element("div", { class: "ruler" });
1847
- for (let time = 0; time <= scale + step / 2; time += step) {
1848
- const at = time / scale * 100;
1849
- ticks.append(element("span", {
1850
- class: at > 99 ? "end" : "",
1851
- style: `left:${at}%`
1852
- }, ms(time)));
1853
- }
1854
- const grid = `background-image: repeating-linear-gradient(to right, #ffffff1a 0 1px, transparent 1px ${step / scale * 100}%)`;
1855
- const handler = element("div", {
1856
- class: "track",
1857
- style: grid
1858
- }, ...run.ready - run.begun > .5 ? [segment(run, scale, run.begun, run.ready, "wait", `waiting for its code and the handlers before it: ${ms(run.ready - run.begun)}`)] : [], segment(run, scale, run.ready, run.end, run.failed ? "failed" : "run", `its run: ${ms(run.end - run.ready)}`), ...run.settled !== void 0 && run.settled - run.end > .5 ? [segment(run, scale, run.end, run.settled, "async", `its promise: ${ms(run.settled - run.end)}`)] : []);
1859
- const rows = [element("div", { class: "run-row" }, element("span"), ticks, element("span")), element("div", { class: "run-row" }, element("span", { class: "name" }, "handler"), handler, element("span", { class: "took" }, run.settled === void 0 ? "…" : ms(total)))];
1860
- for (const call of run.calls) {
1861
- const end = call.end ?? now;
1862
- const parts = [segment(run, scale, call.start, end, call.status === "failed" ? "failed" : "call", `the round trip: ${ms(end - call.start)}`)];
1863
- if (call.server !== void 0) {
1864
- const middle = call.start + (end - call.start - call.server) / 2;
1865
- parts.push(segment(run, scale, middle, middle + call.server, "server", `on the server: ${ms(call.server)}`));
1866
- }
1867
- rows.push(element("div", { class: "run-row" }, element("span", {
1868
- class: "name",
1869
- title: call.name
1870
- }, `call ${handlerName(call.name)}`), element("div", {
1871
- class: "track",
1872
- style: grid
1873
- }, ...parts), element("span", { class: "took" }, call.end === void 0 ? "…" : `${ms(end - call.start)}${call.server === void 0 ? "" : ` (${ms(call.server)})`}`)));
1874
- }
1875
- if (run.updates.length > 0) {
1876
- let count = 0;
1877
- let took = 0;
1878
- const updateSegments = [];
1879
- for (const update of run.updates) {
1880
- count += update.count;
1881
- took += update.end - update.start;
1882
- 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)}`));
1883
- }
1884
- const batches = run.updates.length;
1885
- rows.push(element("div", { class: "run-row" }, element("span", { class: "name" }, `${count} ${count === 1 ? "update" : "updates"}${batches > 1 ? `, ${batches} batches` : ""}`), element("div", {
1886
- class: "track",
1887
- style: grid
1888
- }, ...updateSegments), element("span", { class: "took" }, ms(took))));
1889
- }
1890
- const speed = speedColor(total);
1891
- 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));
1892
- }
1893
- const settled = [];
1894
- let callCount = 0;
1895
- for (const [index, run] of runs.entries()) {
1896
- if (run.settled !== void 0) settled.push(totals[index]);
1897
- callCount += run.calls.length;
1898
- }
1899
- const clear = iconButton("trash", "Clear");
1900
- clear.addEventListener("click", () => {
1901
- state.timeline.length = 0;
1902
- draw();
1903
- });
1904
- 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", {
1905
- class: "toolbar",
1906
- style: "margin-top: 8px"
1907
- }, 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);
1908
- }
1909
- function drawBlocks() {
1910
- const blocks = [...state.blocks.values()];
1911
- const table = element("table", { class: "rows" }, row([
1912
- "block",
1913
- "id",
1914
- "trigger",
1915
- "state",
1916
- "fired",
1917
- "rendered",
1918
- ""
1919
- ], "th"));
1920
- for (const block of blocks) {
1921
- const action = element("span");
1922
- if (block.state === "waiting" && (block.kind === "defer" || block.kind === "client")) {
1923
- const fire = iconButton("bolt", "Fire", { title: "Fire the trigger now" });
1924
- fire.addEventListener("click", () => {
1925
- state.fire?.(block);
1926
- draw();
1927
- });
1928
- action.append(fire);
1929
- }
1930
- const kept = globalThis.$bD?.[block.id];
1931
- if (block.state === "rendered" && kept && (block.kind === "loading" || block.kind === "defer")) {
1932
- const toggle = iconButton(block.fallback ? "play" : "pause", block.fallback ? "Body" : "Fallback", {
1933
- title: block.fallback ? "Show the body again" : "Show the fallback in place of the body",
1934
- "aria-pressed": String(block.fallback === true)
1935
- });
1936
- toggle.addEventListener("click", () => {
1937
- state.showFallback?.(block, !block.fallback);
1938
- draw();
1939
- });
1940
- action.append(toggle);
1941
- }
1942
- let took = "";
1943
- if (block.rendered !== void 0) took = block.fired === void 0 ? seconds(block.rendered) : `+${ms(block.rendered - block.fired)}`;
1944
- table.append(row([
1945
- pill(blockLabel(block), block.kind === "$client" ? "blue" : "accent"),
1946
- element("span", { class: "mono" }, block.id),
1947
- block.trigger ?? "",
1948
- pill(block.state, STATE_COLORS[block.state]),
1949
- block.fired === void 0 ? "" : seconds(block.fired),
1950
- took,
1951
- action
1952
- ]));
1953
- }
1954
- body.replaceChildren(element("h2", {}, "Blocks that render after the page"), element("p", {
1955
- class: "sub",
1956
- style: "margin-top: 0"
1957
- }, "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."));
1958
- }
1959
- async function drawReport() {
1960
- const id = selected ?? roots()[0]?.m;
1961
- const info = id ? await componentInfo(state, id) : void 0;
1962
- body.replaceChildren(...info ? [element("div", { class: "toolbar" }, chooser(id), source(info)), element("pre", { class: "report" }, info.text)] : [element("div", { class: "empty" }, "No component yet.")]);
1963
- }
1964
- /** The draw of each tab that loads what it shows. Log and Blocks draw at once. */
1965
- const drawTab = {
1966
- overview: drawOverview,
1967
- errors: drawErrors,
1968
- scopes: drawScopes,
1969
- elements: drawElements,
1970
- state: drawState,
1971
- effects: drawEffects,
1972
- navigation: drawNavigation,
1973
- server: drawServer,
1974
- timeline: drawTimeline,
1975
- graph: drawGraph,
1976
- report: drawReport
1977
- };
1978
- let queued = false;
1979
- function draw() {
1980
- drawChrome();
1981
- if (tab === "log") {
1982
- drawLog();
1983
- return;
1984
- }
1985
- if (tab === "blocks") {
1986
- drawBlocks();
1987
- return;
1988
- }
1989
- const drawing = tab;
1990
- drawTab[tab]().then(() => {
1991
- if (tab !== drawing) {
1992
- draw();
1993
- return;
1994
- }
1995
- drawChrome();
1996
- if (tab === "scopes") state.written.clear();
1997
- });
1998
- }
1999
- state.changed = () => {
2000
- const typing = root.activeElement?.matches?.("input[type=\"search\"]");
2001
- if (!queued && !editing && !typing && !(paused && tab === "log")) {
2002
- queued = true;
2003
- requestAnimationFrame(() => {
2004
- queued = false;
2005
- if (panel) draw();
2006
- });
2007
- }
2008
- };
2009
- showTab = (next) => {
2010
- tab = next;
2011
- draw();
2012
- };
2013
- draw();
2014
- }
2015
- //#endregion
2016
- export { layoutGraph, openPanel, togglePanel };
2017
-
2018
- //# sourceMappingURL=devtools-panel-Doit__YG.js.map