brumate 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +97 -2
  3. package/dist/cli.d.ts +1 -0
  4. package/dist/cli.js +68 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/client-DuDTDePF.d.ts +190 -0
  7. package/dist/context-BG8KCF3v.js +15 -0
  8. package/dist/context-BG8KCF3v.js.map +1 -0
  9. package/dist/context-aeo9esY9.d.ts +16 -0
  10. package/dist/cookies-rgIAc8IE.js +165 -0
  11. package/dist/cookies-rgIAc8IE.js.map +1 -0
  12. package/dist/devtools-Bm8cS7hX.js +108 -0
  13. package/dist/devtools-Bm8cS7hX.js.map +1 -0
  14. package/dist/devtools-panel-CTbDSBBA.js +437 -0
  15. package/dist/devtools-panel-CTbDSBBA.js.map +1 -0
  16. package/dist/files-D_JUcSU5.js +158 -0
  17. package/dist/files-D_JUcSU5.js.map +1 -0
  18. package/dist/html-CxWpXngy.js +115 -0
  19. package/dist/html-CxWpXngy.js.map +1 -0
  20. package/dist/html-DV-Tezgq.d.ts +41 -0
  21. package/dist/index.d.ts +2031 -0
  22. package/dist/index.js +691 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/inspect-CGCWfaEx.js +6346 -0
  25. package/dist/inspect-CGCWfaEx.js.map +1 -0
  26. package/dist/loader-BUhNqDHw.d.ts +30 -0
  27. package/dist/loader-py4qu6tQ.js +215 -0
  28. package/dist/loader-py4qu6tQ.js.map +1 -0
  29. package/dist/navigate-C5dP89YL.js +369 -0
  30. package/dist/navigate-C5dP89YL.js.map +1 -0
  31. package/dist/produce-BRGHP7e0.js +126 -0
  32. package/dist/produce-BRGHP7e0.js.map +1 -0
  33. package/dist/produce-BjQGMpqL.d.ts +50 -0
  34. package/dist/rpc-B86KKjzx.js +83 -0
  35. package/dist/rpc-B86KKjzx.js.map +1 -0
  36. package/dist/runtime/client.d.ts +5 -0
  37. package/dist/runtime/client.js +1052 -0
  38. package/dist/runtime/client.js.map +1 -0
  39. package/dist/runtime/context.d.ts +2 -0
  40. package/dist/runtime/context.js +1 -0
  41. package/dist/runtime/devtools.d.ts +34 -0
  42. package/dist/runtime/devtools.js +1 -0
  43. package/dist/runtime/hot.d.ts +36 -0
  44. package/dist/runtime/hot.js +40 -0
  45. package/dist/runtime/hot.js.map +1 -0
  46. package/dist/runtime/html.d.ts +2 -0
  47. package/dist/runtime/html.js +1 -0
  48. package/dist/runtime/loader.d.ts +2 -0
  49. package/dist/runtime/loader.js +1 -0
  50. package/dist/runtime/routes.d.ts +21 -0
  51. package/dist/runtime/routes.js +18 -0
  52. package/dist/runtime/routes.js.map +1 -0
  53. package/dist/runtime/server.d.ts +5 -0
  54. package/dist/runtime/server.js +7 -0
  55. package/dist/runtime/signals.d.ts +46 -0
  56. package/dist/runtime/signals.js +74 -0
  57. package/dist/runtime/signals.js.map +1 -0
  58. package/dist/runtime/testing.d.ts +36 -0
  59. package/dist/runtime/testing.js +96 -0
  60. package/dist/runtime/testing.js.map +1 -0
  61. package/dist/server-CX3JnPCs.js +1205 -0
  62. package/dist/server-CX3JnPCs.js.map +1 -0
  63. package/dist/server-sQCvduOz.d.ts +562 -0
  64. package/dist/shared-BE_oBSDM.js +176 -0
  65. package/dist/shared-BE_oBSDM.js.map +1 -0
  66. package/dist/stream-cvhqOzfs.js +145 -0
  67. package/dist/stream-cvhqOzfs.js.map +1 -0
  68. package/dist/vite.d.ts +121 -0
  69. package/dist/vite.js +958 -0
  70. package/dist/vite.js.map +1 -0
  71. package/package.json +117 -3
  72. package/types.d.ts +36 -0
@@ -0,0 +1,108 @@
1
+ //#region src/runtime/devtools.ts
2
+ const DEVTOOLS = Symbol.for("brumate.devtools");
3
+ const MAX_LOG = 300;
4
+ /** A short text for a value in the log. */
5
+ function preview(value) {
6
+ if (typeof value === "string") return JSON.stringify(value.length > 40 ? `${value.slice(0, 40)}…` : value);
7
+ if (typeof value === "function") return "function";
8
+ if (Array.isArray(value)) return `Array(${value.length})`;
9
+ if (value instanceof Element) return `<${value.tagName.toLowerCase()}>`;
10
+ if (value !== null && typeof value === "object") {
11
+ const name = value.constructor?.name;
12
+ return name && name !== "Object" ? name : `{${Object.keys(value).slice(0, 3).join(", ")}}`;
13
+ }
14
+ return String(value);
15
+ }
16
+ /** Listens to the core, and adds the button that opens the panel. */
17
+ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate") {
18
+ const state = {
19
+ log: [],
20
+ written: /* @__PURE__ */ new Set(),
21
+ endpoint
22
+ };
23
+ const add = (entry) => {
24
+ state.log.push({
25
+ ...entry,
26
+ time: performance.now()
27
+ });
28
+ if (state.log.length > MAX_LOG) state.log.splice(0, state.log.length - MAX_LOG);
29
+ state.changed?.();
30
+ };
31
+ globalThis[DEVTOOLS] = {
32
+ attach(core) {
33
+ state.scopes = core.scopes;
34
+ state.set = core.set;
35
+ state.changed?.();
36
+ },
37
+ handler(ref, element, event) {
38
+ add({
39
+ kind: "handler",
40
+ text: `${event?.type ?? "call"} on <${element.tagName.toLowerCase()}>: ${ref}`
41
+ });
42
+ },
43
+ part(component, name) {
44
+ add({
45
+ kind: "part",
46
+ text: `loaded ${component} ${name}`
47
+ });
48
+ },
49
+ write(scope, slot, value) {
50
+ state.written.add(scope.id);
51
+ let root = scope;
52
+ while (root.p) root = root.p;
53
+ add({
54
+ kind: "write",
55
+ text: `scope ${scope.id} slot ${slot} = ${preview(value)}`,
56
+ scope: scope.id,
57
+ write: {
58
+ component: root.m ?? "",
59
+ k: scope.k,
60
+ slot
61
+ }
62
+ });
63
+ }
64
+ };
65
+ const original = globalThis.fetch.bind(globalThis);
66
+ globalThis.fetch = async (input, init) => {
67
+ const url = new URL(input instanceof Request ? input.url : String(input), location.href);
68
+ if (url.origin !== location.origin || !url.pathname.startsWith(`${rpc}/`)) return original(input, init);
69
+ const name = decodeURIComponent(url.pathname.slice(rpc.length + 1));
70
+ const started = performance.now();
71
+ try {
72
+ const response = await original(input, init);
73
+ const took = Math.round(performance.now() - started);
74
+ const redirect = response.headers.get("x-brumate-redirect");
75
+ add({
76
+ kind: "call",
77
+ text: `${name}: ${redirect ? `redirect to ${redirect}` : response.status} in ${took} ms`
78
+ });
79
+ return response;
80
+ } catch (error) {
81
+ add({
82
+ kind: "call",
83
+ text: `${name}: failed, ${error instanceof Error ? error.message : String(error)}`
84
+ });
85
+ throw error;
86
+ }
87
+ };
88
+ const host = document.createElement("brumate-devtools");
89
+ const root = host.attachShadow({ mode: "open" });
90
+ const button = document.createElement("button");
91
+ button.textContent = "brm";
92
+ button.title = "Open the brumate devtools";
93
+ button.setAttribute("style", "position:fixed;right:12px;bottom:12px;z-index:2147483647;font:600 12px ui-monospace,monospace;padding:6px 10px;border-radius:999px;border:1px solid #8884;background:#111;color:#fff;cursor:pointer");
94
+ button.addEventListener("click", () => {
95
+ import("./devtools-panel-CTbDSBBA.js").then(({ togglePanel }) => togglePanel(root, state));
96
+ });
97
+ root.append(button);
98
+ const append = () => {
99
+ document.documentElement.append(host);
100
+ };
101
+ if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", append);
102
+ else append();
103
+ return state;
104
+ }
105
+ //#endregion
106
+ export { preview as n, installDevtools as t };
107
+
108
+ //# sourceMappingURL=devtools-Bm8cS7hX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devtools-Bm8cS7hX.js","names":[],"sources":["../src/runtime/devtools.ts"],"sourcesContent":["// The devtools overlay of development builds. This module only listens to\n// the core and shows a button. The panel loads when the button is pressed,\n// so the page behaves as in production until then.\n\nimport type { DevtoolsHooks, Scope } from './client.ts';\n\n// The same key as the core's, without importing the core.\nconst DEVTOOLS = Symbol.for('brumate.devtools');\n\n/** Something that happened on the page, for the log of the panel. */\nexport interface DevtoolsEntry {\n time: number;\n kind: 'handler' | 'part' | 'write' | 'call';\n text: string;\n /** The scope of a write, so the panel can mark it. */\n scope?: number;\n /** For a write: the component, the scope in the compiled component, and the slot. */\n write?: { component: string; k: number; slot: number };\n}\n\nexport interface DevtoolsState {\n scopes?: Map<number, Scope>;\n /** Writes a slot, as a handler does, so the page updates. */\n set?: (scope: Scope, slot: number, value: unknown) => void;\n log: DevtoolsEntry[];\n /** The scopes written since the panel last drew, by scope ID. */\n written: Set<number>;\n /** The URL prefix of the inspect endpoint of the dev server. */\n endpoint: string;\n /** Called after each change, while the panel is open. */\n changed?: () => void;\n}\n\nconst MAX_LOG = 300;\n\n/** A short text for a value in the log. */\nexport function preview(value: unknown): string {\n if (typeof value === 'string') {\n return JSON.stringify(value.length > 40 ? `${value.slice(0, 40)}…` : value);\n }\n if (typeof value === 'function') {\n return 'function';\n }\n if (Array.isArray(value)) {\n return `Array(${value.length})`;\n }\n if (value instanceof Element) {\n return `<${value.tagName.toLowerCase()}>`;\n }\n if (value !== null && typeof value === 'object') {\n const name = value.constructor?.name;\n return name && name !== 'Object' ? name : `{${Object.keys(value).slice(0, 3).join(', ')}}`;\n }\n return String(value);\n}\n\n/** Listens to the core, and adds the button that opens the panel. */\nexport function installDevtools(endpoint = '/__brumate/inspect', rpc = '/_brumate'): DevtoolsState {\n const state: DevtoolsState = { log: [], written: new Set(), endpoint };\n const add = (entry: Omit<DevtoolsEntry, 'time'>): void => {\n state.log.push({ ...entry, time: performance.now() });\n if (state.log.length > MAX_LOG) {\n state.log.splice(0, state.log.length - MAX_LOG);\n }\n state.changed?.();\n };\n const hooks: DevtoolsHooks = {\n attach(core) {\n state.scopes = core.scopes;\n state.set = core.set;\n state.changed?.();\n },\n handler(ref, element, event) {\n add({\n kind: 'handler',\n text: `${event?.type ?? 'call'} on <${element.tagName.toLowerCase()}>: ${ref}`,\n });\n },\n part(component, name) {\n add({ kind: 'part', text: `loaded ${component} ${name}` });\n },\n write(scope, slot, value) {\n state.written.add(scope.id);\n let root = scope;\n while (root.p) {\n root = root.p;\n }\n add({\n kind: 'write',\n text: `scope ${scope.id} slot ${slot} = ${preview(value)}`,\n scope: scope.id,\n write: { component: root.m ?? '', k: scope.k, slot },\n });\n },\n };\n (globalThis as Record<symbol, DevtoolsHooks | undefined>)[DEVTOOLS] = hooks;\n\n // Server function calls, with how long each took and how it answered.\n const original = globalThis.fetch.bind(globalThis);\n globalThis.fetch = async (input, init) => {\n const url = new URL(input instanceof Request ? input.url : String(input), location.href);\n if (url.origin !== location.origin || !url.pathname.startsWith(`${rpc}/`)) {\n return original(input, init);\n }\n const name = decodeURIComponent(url.pathname.slice(rpc.length + 1));\n const started = performance.now();\n try {\n const response = await original(input, init);\n const took = Math.round(performance.now() - started);\n const redirect = response.headers.get('x-brumate-redirect');\n add({\n kind: 'call',\n text: `${name}: ${redirect ? `redirect to ${redirect}` : response.status} in ${took} ms`,\n });\n return response;\n } catch (error) {\n add({\n kind: 'call',\n text: `${name}: failed, ${error instanceof Error ? error.message : String(error)}`,\n });\n throw error;\n }\n };\n\n const host = document.createElement('brumate-devtools');\n const root = host.attachShadow({ mode: 'open' });\n const button = document.createElement('button');\n button.textContent = 'brm';\n button.title = 'Open the brumate devtools';\n button.setAttribute(\n 'style',\n 'position:fixed;right:12px;bottom:12px;z-index:2147483647;font:600 12px ui-monospace,monospace;padding:6px 10px;border-radius:999px;border:1px solid #8884;background:#111;color:#fff;cursor:pointer',\n );\n button.addEventListener('click', () => {\n void import('./devtools-panel.ts').then(({ togglePanel }) => togglePanel(root, state));\n });\n root.append(button);\n const append = (): void => {\n // Navigation replaces the body, so the button goes on the document element.\n document.documentElement.append(host);\n };\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', append);\n } else {\n append();\n }\n return state;\n}\n"],"mappings":";AAOA,MAAM,WAAW,OAAO,IAAI,kBAAkB;AA0B9C,MAAM,UAAU;;AAGhB,SAAgB,QAAQ,OAAwB;CAC9C,IAAI,OAAO,UAAU,UACnB,OAAO,KAAK,UAAU,MAAM,SAAS,KAAK,GAAG,MAAM,MAAM,GAAG,EAAE,EAAE,KAAK,KAAK;CAE5E,IAAI,OAA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AAC;CACD,KAAK,OAAO,MAAM;CAClB,MAAM,eAAqB;EAEzB,SAAS,gBAAgB,OAAO,IAAI;CACtC;CACA,IAAI,SAAS,eAAe,WAC1B,SAAS,iBAAiB,oBAAoB,MAAM;MAEpD,OAAO;CAET,OAAO;AACT"}
@@ -0,0 +1,437 @@
1
+ import { n as preview } from "./devtools-Bm8cS7hX.js";
2
+ //#region src/runtime/devtools-panel.ts
3
+ const STYLE = `
4
+ :host { all: initial; }
5
+ .panel { position: fixed; right: 12px; bottom: 52px; z-index: 2147483647; width: min(520px, calc(100vw - 24px)); height: min(64vh, 620px); display: flex; flex-direction: column; background: #111; color: #eee; font: 12px/1.5 ui-monospace, monospace; border: 1px solid #8884; border-radius: 8px; box-shadow: 0 8px 32px #0006; overflow: hidden; }
6
+ .bar { display: flex; gap: 4px; padding: 6px; border-bottom: 1px solid #8883; align-items: center; flex-wrap: wrap; }
7
+ button, select { font: inherit; color: inherit; background: none; border: 1px solid transparent; border-radius: 4px; padding: 2px 8px; cursor: pointer; }
8
+ select { border-color: #8884; background: #111; }
9
+ .bar .tab[aria-selected="true"], .bar button[aria-pressed="true"] { border-color: #8886; background: #fff1; }
10
+ .bar .end { margin-left: auto; }
11
+ .body { flex: 1; overflow: auto; padding: 8px; }
12
+ .component { margin-bottom: 10px; }
13
+ .component > button { font-weight: 600; color: #9cf; padding: 0; }
14
+ .scope { margin-left: 12px; padding-left: 8px; border-left: 1px solid #8883; }
15
+ .scope.selected { border-left-color: #9cf; background: #9cf1; }
16
+ .scope-label { color: #aaa; cursor: default; }
17
+ .slot { white-space: pre; }
18
+ .slot .name { color: #fc9; }
19
+ .slot .value { cursor: text; border-bottom: 1px dotted #8886; }
20
+ .slot input { font: inherit; color: inherit; background: #000; border: 1px solid #9cf; border-radius: 3px; padding: 0 4px; width: 60%; }
21
+ .written { animation: flash 0.8s; }
22
+ @keyframes flash { from { background: #fd04; } to { background: transparent; } }
23
+ .entry { white-space: pre-wrap; border-bottom: 1px solid #8882; padding: 2px 0; }
24
+ .entry .time { color: #888; margin-right: 6px; }
25
+ .entry.handler .kind { color: #9cf; }
26
+ .entry.part .kind { color: #9e9; }
27
+ .entry.write .kind { color: #fc9; }
28
+ .entry.call .kind { color: #f9c; }
29
+ .filters label { display: inline-flex; gap: 3px; align-items: center; margin-right: 6px; }
30
+ pre { margin: 0; white-space: pre-wrap; }
31
+ .empty { color: #888; }
32
+ svg text { fill: #eee; font: 11px ui-monospace, monospace; }
33
+ svg rect { fill: #222; stroke: #8886; }
34
+ svg .kind-signal rect, svg .kind-prop rect { stroke: #9cf; }
35
+ svg .kind-memo rect { stroke: #c9f; }
36
+ svg .kind-effect rect { stroke: #9e9; }
37
+ svg .hot rect { fill: #fd03; stroke: #fd0; }
38
+ .legend { color: #aaa; margin: 6px 0; }
39
+ .legend b { font-weight: normal; }
40
+ .legend .signal { color: #9cf; } .legend .memo { color: #c9f; } .legend .effect { color: #9e9; } .legend .hot { color: #fd0; }
41
+ svg line { stroke: #8886; }
42
+ svg .hot-edge { stroke: #fd0; }
43
+ .outline { position: fixed; pointer-events: none; border: 2px solid #9cf; background: #9cf2; border-radius: 3px; z-index: 2147483646; }
44
+ `;
45
+ const KINDS = [
46
+ "handler",
47
+ "part",
48
+ "write",
49
+ "call"
50
+ ];
51
+ /** How long a write marks the nodes of the graph. */
52
+ const HOT_MS = 1500;
53
+ const components = /* @__PURE__ */ new Map();
54
+ const known = /* @__PURE__ */ new Map();
55
+ /** Asks the dev server about a component, once. */
56
+ function componentInfo(state, id) {
57
+ let info = components.get(id);
58
+ if (!info) {
59
+ info = fetch(`${state.endpoint}/${encodeURIComponent(id)}`).then((response) => response.ok ? response.json() : void 0).then((value) => {
60
+ if (value) known.set(id, value);
61
+ return value;
62
+ }).catch(() => void 0);
63
+ components.set(id, info);
64
+ }
65
+ return info;
66
+ }
67
+ function element(tag, attributes = {}, ...children) {
68
+ const node = document.createElement(tag);
69
+ for (const [name, value] of Object.entries(attributes)) node.setAttribute(name, value);
70
+ node.append(...children);
71
+ return node;
72
+ }
73
+ function svg(tag, attributes, ...children) {
74
+ const node = document.createElementNS("http://www.w3.org/2000/svg", tag);
75
+ for (const [name, value] of Object.entries(attributes)) node.setAttribute(name, String(value));
76
+ node.append(...children);
77
+ return node;
78
+ }
79
+ /** The root scope of a scope, whose `m` names its component. */
80
+ function rootOf(scope) {
81
+ let root = scope;
82
+ while (root.p) root = root.p;
83
+ return root;
84
+ }
85
+ /** A value that can be edited as text: what JSON can hold. */
86
+ function editable(value) {
87
+ if (value === null || [
88
+ "string",
89
+ "number",
90
+ "boolean"
91
+ ].includes(typeof value)) return true;
92
+ if (typeof value !== "object" || value instanceof Element) return false;
93
+ try {
94
+ JSON.stringify(value);
95
+ return true;
96
+ } catch {
97
+ return false;
98
+ }
99
+ }
100
+ /** Reads what a person typed: JSON, or else the text as a string. */
101
+ function parseValue(text) {
102
+ try {
103
+ return JSON.parse(text);
104
+ } catch {
105
+ return text;
106
+ }
107
+ }
108
+ /** A write with the name of its slot, once the dev server has said what it is. */
109
+ function describe(entry) {
110
+ const write = entry.write;
111
+ const info = write && known.get(write.component);
112
+ const name = info?.scopes[write.k]?.slots[write.slot];
113
+ return name ? `${info.name} ${name} = ${entry.text.split(" = ").slice(1).join(" = ")}` : entry.text;
114
+ }
115
+ let panel;
116
+ /** Opens the panel, or closes it when it is open. */
117
+ function togglePanel(root, state) {
118
+ if (panel) {
119
+ panel.remove();
120
+ panel = void 0;
121
+ state.changed = void 0;
122
+ return;
123
+ }
124
+ let tab = "scopes";
125
+ let selected;
126
+ let selectedScope;
127
+ let editing;
128
+ let paused = false;
129
+ const shown = new Set(KINDS);
130
+ let frozen;
131
+ const body = element("div", { class: "body" });
132
+ const bar = element("div", {
133
+ class: "bar",
134
+ role: "tablist"
135
+ });
136
+ for (const [name, label] of [
137
+ ["scopes", "Scopes"],
138
+ ["graph", "Graph"],
139
+ ["log", "Log"],
140
+ ["report", "Report"]
141
+ ]) {
142
+ const button = element("button", {
143
+ class: "tab",
144
+ role: "tab",
145
+ "data-tab": name
146
+ }, label);
147
+ button.addEventListener("click", () => {
148
+ tab = name;
149
+ draw();
150
+ });
151
+ bar.append(button);
152
+ }
153
+ const pick = element("button", {
154
+ class: "end",
155
+ "aria-pressed": "false",
156
+ title: "Click an element of the page to find its scope"
157
+ }, "Pick");
158
+ bar.append(pick);
159
+ panel = element("div", { class: "panel" }, element("style", {}, STYLE), bar, body);
160
+ root.append(panel);
161
+ if (!state.scopes) document.dispatchEvent(new Event("brumate:core"));
162
+ const outlines = [];
163
+ const outline = (scope) => {
164
+ for (const box of outlines.splice(0)) box.remove();
165
+ if (scope === void 0) return;
166
+ for (const target of document.querySelectorAll(`[data-b^="${scope}:"]`)) {
167
+ const rect = target.getBoundingClientRect();
168
+ const box = element("div", {
169
+ class: "outline",
170
+ style: `left:${rect.left}px;top:${rect.top}px;width:${rect.width}px;height:${rect.height}px`
171
+ });
172
+ root.append(box);
173
+ outlines.push(box);
174
+ }
175
+ };
176
+ const onPick = (event) => {
177
+ const target = event.target?.closest?.("[data-b]");
178
+ if (!target || event.composedPath().includes(panel)) return;
179
+ event.preventDefault();
180
+ event.stopImmediatePropagation();
181
+ stopPicking();
182
+ selectedScope = Number(target.getAttribute("data-b").split(":")[0]);
183
+ const scope = state.scopes?.get(selectedScope);
184
+ selected = scope ? rootOf(scope).m : selected;
185
+ tab = "scopes";
186
+ draw();
187
+ };
188
+ const stopPicking = () => {
189
+ pick.setAttribute("aria-pressed", "false");
190
+ window.removeEventListener("click", onPick, true);
191
+ document.documentElement.style.cursor = "";
192
+ };
193
+ pick.addEventListener("click", () => {
194
+ if (pick.getAttribute("aria-pressed") === "true") {
195
+ stopPicking();
196
+ return;
197
+ }
198
+ pick.setAttribute("aria-pressed", "true");
199
+ document.documentElement.style.cursor = "crosshair";
200
+ window.addEventListener("click", onPick, true);
201
+ });
202
+ /** A slot with its name and value. A value that JSON can hold can be edited. */
203
+ const drawSlot = (scope, slot, name) => {
204
+ const value = scope.s[slot];
205
+ const line = element("div", { class: "slot" }, element("span", { class: "name" }, name), " = ");
206
+ if (editing?.scope === scope.id && editing.slot === slot) {
207
+ const input = element("input", { "aria-label": `New value of ${name}` });
208
+ input.value = typeof value === "string" ? JSON.stringify(value) : JSON.stringify(value) ?? "";
209
+ input.addEventListener("keydown", (event) => {
210
+ if (event.key === "Enter") {
211
+ editing = void 0;
212
+ state.set?.(scope, slot, parseValue(input.value));
213
+ draw();
214
+ } else if (event.key === "Escape") {
215
+ editing = void 0;
216
+ draw();
217
+ }
218
+ });
219
+ line.append(input);
220
+ queueMicrotask(() => input.focus());
221
+ return line;
222
+ }
223
+ const text = element("span", { class: editable(value) && state.set ? "value" : "" }, preview(value));
224
+ if (editable(value) && state.set) {
225
+ text.title = "Click to edit. Enter JSON, or text for a string.";
226
+ text.addEventListener("click", () => {
227
+ editing = {
228
+ scope: scope.id,
229
+ slot
230
+ };
231
+ draw();
232
+ });
233
+ }
234
+ line.append(text);
235
+ return line;
236
+ };
237
+ /** A scope with its slots and the scopes inside it, other than components. */
238
+ const drawScope = (scope, info) => {
239
+ const plan = info?.scopes[scope.k];
240
+ const classes = ["scope"];
241
+ if (state.written.has(scope.id)) classes.push("written");
242
+ if (selectedScope === scope.id) classes.push("selected");
243
+ const label = element("div", { class: "scope-label" }, `scope ${scope.id}${plan ? ` · ${plan.label}` : ""}`);
244
+ label.addEventListener("mouseenter", () => outline(scope.id));
245
+ label.addEventListener("mouseleave", () => outline());
246
+ const box = element("div", { class: classes.join(" ") }, label);
247
+ scope.s.forEach((_, slot) => box.append(drawSlot(scope, slot, plan?.slots[slot] ?? `slot ${slot}`)));
248
+ for (const child of scope.children) if (child.m === void 0) box.append(drawScope(child, info));
249
+ return box;
250
+ };
251
+ const roots = () => [...state.scopes?.values() ?? []].filter((scope) => scope.m !== void 0);
252
+ const drawScopes = async () => {
253
+ const list = roots();
254
+ const infos = await Promise.all(list.map((scope) => componentInfo(state, scope.m)));
255
+ const content = element("div");
256
+ list.forEach((scope, index) => {
257
+ const info = infos[index];
258
+ const name = element("button", {}, info ? `${info.name} (${info.file})` : scope.m);
259
+ name.title = "Show the graph of this component";
260
+ name.addEventListener("click", () => {
261
+ selected = scope.m;
262
+ tab = "graph";
263
+ draw();
264
+ });
265
+ content.append(element("div", { class: "component" }, name, drawScope(scope, info)));
266
+ });
267
+ if (list.length === 0) content.append(element("div", { class: "empty" }, "No scopes yet. The first event loads them."));
268
+ body.replaceChildren(content);
269
+ body.querySelector(".selected")?.scrollIntoView({ block: "nearest" });
270
+ };
271
+ /** A select of the components on the page, for Graph and Report. */
272
+ const chooser = (current) => {
273
+ const select = element("select", { "aria-label": "Component" });
274
+ for (const id of new Set(roots().map((scope) => scope.m))) {
275
+ const option = element("option", { value: id }, known.get(id)?.name ?? id);
276
+ option.selected = id === current;
277
+ select.append(option);
278
+ }
279
+ select.addEventListener("change", () => {
280
+ selected = select.value;
281
+ draw();
282
+ });
283
+ return element("div", {}, select);
284
+ };
285
+ let cooling;
286
+ const drawGraph = async () => {
287
+ const id = selected ?? roots()[0]?.m;
288
+ const info = id ? await componentInfo(state, id) : void 0;
289
+ if (!id || !info) {
290
+ body.replaceChildren(element("div", { class: "empty" }, "No component yet."));
291
+ return;
292
+ }
293
+ if (!info.graph) {
294
+ body.replaceChildren(chooser(id), element("div", { class: "empty" }, "The dev server sent no graph. It runs an older brumate than this panel: restart it."));
295
+ return;
296
+ }
297
+ const { nodes, edges } = info.graph;
298
+ const instance = roots().find((scope) => scope.m === id);
299
+ const scopeOfNode = (k) => {
300
+ const visit = (scope) => {
301
+ if (scope.k === k) return scope;
302
+ for (const child of scope.children) {
303
+ const found = child.m === void 0 ? visit(child) : void 0;
304
+ if (found) return found;
305
+ }
306
+ };
307
+ return instance && visit(instance);
308
+ };
309
+ const now = performance.now();
310
+ const hot = /* @__PURE__ */ new Set();
311
+ for (const entry of state.log) if (entry.write?.component === id && now - entry.time < HOT_MS) nodes.forEach((node, index) => {
312
+ if (node.scope === entry.write.k && node.slot === entry.write.slot) hot.add(index);
313
+ });
314
+ for (let grew = true; grew;) {
315
+ grew = false;
316
+ for (const [from, to] of edges) if (hot.has(from) && !hot.has(to)) {
317
+ hot.add(to);
318
+ grew = true;
319
+ }
320
+ }
321
+ const depth = nodes.map(() => 0);
322
+ for (let round = 0; round < nodes.length; round++) for (const [from, to] of edges) depth[to] = Math.max(depth[to], depth[from] + 1);
323
+ const rows = /* @__PURE__ */ new Map();
324
+ const position = nodes.map((_, index) => {
325
+ const column = depth[index];
326
+ const row = rows.get(column) ?? 0;
327
+ rows.set(column, row + 1);
328
+ return {
329
+ x: 8 + column * 150,
330
+ y: 8 + row * 34
331
+ };
332
+ });
333
+ const graph = svg("svg", {
334
+ width: 8 + (Math.max(0, ...depth) + 1) * 150,
335
+ height: 8 + Math.max(1, ...rows.values()) * 34,
336
+ role: "img",
337
+ "aria-label": `Graph of ${info.name}`
338
+ });
339
+ for (const [from, to] of edges) {
340
+ const a = position[from];
341
+ const b = position[to];
342
+ graph.append(svg("line", {
343
+ x1: a.x + 132,
344
+ y1: a.y + 12,
345
+ x2: b.x,
346
+ y2: b.y + 12,
347
+ class: hot.has(from) && hot.has(to) ? "hot-edge" : ""
348
+ }));
349
+ }
350
+ nodes.forEach((node, index) => {
351
+ const { x, y } = position[index];
352
+ const text = svg("text", {
353
+ x: x + 6,
354
+ y: y + 16
355
+ });
356
+ const owner = node.slot === void 0 ? void 0 : scopeOfNode(node.scope);
357
+ const value = owner && node.slot !== void 0 ? ` = ${preview(owner.s[node.slot])}` : "";
358
+ text.textContent = `${node.label}${value}`.slice(0, 22);
359
+ const title = svg("title", {});
360
+ title.textContent = `${node.kind} ${node.label}${value}`;
361
+ graph.append(svg("g", { class: `kind-${node.kind}${hot.has(index) ? " hot" : ""}` }, svg("rect", {
362
+ x,
363
+ y,
364
+ width: 132,
365
+ height: 24,
366
+ rx: 4
367
+ }), text, title));
368
+ });
369
+ const legend = element("div", { class: "legend" }, "What reads what, left to right: ", element("b", { class: "signal" }, "signals and props"), ", ", element("b", { class: "memo" }, "memos"), ", markup and ", element("b", { class: "effect" }, "effects"), ". A change lights up in ", element("b", { class: "hot" }, "yellow"), " what it reaches.");
370
+ body.replaceChildren(chooser(id), ...nodes.length > 0 ? [legend, graph] : [element("div", { class: "empty" }, "Nothing in this component changes in the browser.")]);
371
+ if (hot.size > 0) {
372
+ clearTimeout(cooling);
373
+ cooling = setTimeout(() => state.changed?.(), HOT_MS);
374
+ }
375
+ };
376
+ const drawLog = () => {
377
+ const filters = element("div", { class: "filters" });
378
+ for (const kind of KINDS) {
379
+ const box = element("input", { type: "checkbox" });
380
+ box.checked = shown.has(kind);
381
+ box.addEventListener("change", () => {
382
+ if (box.checked) shown.add(kind);
383
+ else shown.delete(kind);
384
+ draw();
385
+ });
386
+ filters.append(element("label", {}, box, kind));
387
+ }
388
+ const pause = element("button", { "aria-pressed": String(paused) }, paused ? "Resume" : "Pause");
389
+ pause.addEventListener("click", () => {
390
+ paused = !paused;
391
+ frozen = paused ? [...state.log] : void 0;
392
+ draw();
393
+ });
394
+ const clear = element("button", {}, "Clear");
395
+ clear.addEventListener("click", () => {
396
+ state.log.length = 0;
397
+ frozen = paused ? [] : void 0;
398
+ draw();
399
+ });
400
+ filters.append(pause, clear);
401
+ const list = element("div");
402
+ const entries = (frozen ?? state.log).filter((entry) => shown.has(entry.kind));
403
+ for (const entry of entries.toReversed()) list.append(element("div", { class: `entry ${entry.kind}` }, element("span", { class: "time" }, `${(entry.time / 1e3).toFixed(2)}s`), element("span", { class: "kind" }, entry.kind), ` ${entry.kind === "write" ? describe(entry) : entry.text}`));
404
+ if (entries.length === 0) list.append(element("div", { class: "empty" }, "Nothing to show."));
405
+ body.replaceChildren(filters, list);
406
+ };
407
+ const drawReport = async () => {
408
+ const id = selected ?? roots()[0]?.m;
409
+ const info = id ? await componentInfo(state, id) : void 0;
410
+ body.replaceChildren(...info ? [chooser(id), element("pre", {}, info.text)] : [element("div", { class: "empty" }, "No component yet.")]);
411
+ };
412
+ let queued = false;
413
+ const draw = () => {
414
+ for (const button of bar.querySelectorAll(".tab")) button.setAttribute("aria-selected", String(button.dataset.tab === tab));
415
+ if (tab === "log") {
416
+ drawLog();
417
+ return;
418
+ }
419
+ (tab === "scopes" ? drawScopes() : tab === "graph" ? drawGraph() : drawReport()).then(() => {
420
+ if (tab === "scopes") state.written.clear();
421
+ });
422
+ };
423
+ state.changed = () => {
424
+ if (!queued && !editing && !(paused && tab === "log")) {
425
+ queued = true;
426
+ requestAnimationFrame(() => {
427
+ queued = false;
428
+ if (panel) draw();
429
+ });
430
+ }
431
+ };
432
+ draw();
433
+ }
434
+ //#endregion
435
+ export { togglePanel };
436
+
437
+ //# sourceMappingURL=devtools-panel-CTbDSBBA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devtools-panel-CTbDSBBA.js","names":[],"sources":["../src/runtime/devtools-panel.ts"],"sourcesContent":["// The panel of the devtools overlay. It reads the core through the hooks in\n// `devtools.ts`, and asks the dev server about each component.\n//\n// - Scopes: each component on the page, its scopes and the value of each\n// slot by name. A value can be edited, which writes it as a handler does.\n// Hovering a scope outlines its elements, and Pick finds the scope of an\n// element of the page.\n// - Graph: the values and markup of a component that change in the\n// browser, and what reads what. A write marks its node and the nodes after it.\n// - Log: handlers, loaded parts, writes and server function calls.\n// - Report: the inspect report of a component.\n\nimport type { Scope } from './client.ts';\nimport { preview } from './devtools.ts';\nimport type { DevtoolsEntry, DevtoolsState } from './devtools.ts';\n\n/** What the dev server tells about a component: see the inspect endpoint of the plugin. */\ninterface ComponentInfo {\n name: string;\n file: string;\n /** Each scope of the component, by its number in the compiled component. */\n scopes: Record<number, { label: string; slots: string[] }>;\n graph?: {\n nodes: { kind: string; label: string; scope: number; slot?: number }[];\n /** Pairs of node indexes: the first is read by the second. */\n edges: [number, number][];\n };\n /** The inspect report as text. */\n text: string;\n}\n\nconst STYLE = `\n:host { all: initial; }\n.panel { position: fixed; right: 12px; bottom: 52px; z-index: 2147483647; width: min(520px, calc(100vw - 24px)); height: min(64vh, 620px); display: flex; flex-direction: column; background: #111; color: #eee; font: 12px/1.5 ui-monospace, monospace; border: 1px solid #8884; border-radius: 8px; box-shadow: 0 8px 32px #0006; overflow: hidden; }\n.bar { display: flex; gap: 4px; padding: 6px; border-bottom: 1px solid #8883; align-items: center; flex-wrap: wrap; }\nbutton, select { font: inherit; color: inherit; background: none; border: 1px solid transparent; border-radius: 4px; padding: 2px 8px; cursor: pointer; }\nselect { border-color: #8884; background: #111; }\n.bar .tab[aria-selected=\"true\"], .bar button[aria-pressed=\"true\"] { border-color: #8886; background: #fff1; }\n.bar .end { margin-left: auto; }\n.body { flex: 1; overflow: auto; padding: 8px; }\n.component { margin-bottom: 10px; }\n.component > button { font-weight: 600; color: #9cf; padding: 0; }\n.scope { margin-left: 12px; padding-left: 8px; border-left: 1px solid #8883; }\n.scope.selected { border-left-color: #9cf; background: #9cf1; }\n.scope-label { color: #aaa; cursor: default; }\n.slot { white-space: pre; }\n.slot .name { color: #fc9; }\n.slot .value { cursor: text; border-bottom: 1px dotted #8886; }\n.slot input { font: inherit; color: inherit; background: #000; border: 1px solid #9cf; border-radius: 3px; padding: 0 4px; width: 60%; }\n.written { animation: flash 0.8s; }\n@keyframes flash { from { background: #fd04; } to { background: transparent; } }\n.entry { white-space: pre-wrap; border-bottom: 1px solid #8882; padding: 2px 0; }\n.entry .time { color: #888; margin-right: 6px; }\n.entry.handler .kind { color: #9cf; }\n.entry.part .kind { color: #9e9; }\n.entry.write .kind { color: #fc9; }\n.entry.call .kind { color: #f9c; }\n.filters label { display: inline-flex; gap: 3px; align-items: center; margin-right: 6px; }\npre { margin: 0; white-space: pre-wrap; }\n.empty { color: #888; }\nsvg text { fill: #eee; font: 11px ui-monospace, monospace; }\nsvg rect { fill: #222; stroke: #8886; }\nsvg .kind-signal rect, svg .kind-prop rect { stroke: #9cf; }\nsvg .kind-memo rect { stroke: #c9f; }\nsvg .kind-effect rect { stroke: #9e9; }\nsvg .hot rect { fill: #fd03; stroke: #fd0; }\n.legend { color: #aaa; margin: 6px 0; }\n.legend b { font-weight: normal; }\n.legend .signal { color: #9cf; } .legend .memo { color: #c9f; } .legend .effect { color: #9e9; } .legend .hot { color: #fd0; }\nsvg line { stroke: #8886; }\nsvg .hot-edge { stroke: #fd0; }\n.outline { position: fixed; pointer-events: none; border: 2px solid #9cf; background: #9cf2; border-radius: 3px; z-index: 2147483646; }\n`;\n\ntype Tab = 'scopes' | 'graph' | 'log' | 'report';\nconst KINDS: DevtoolsEntry['kind'][] = ['handler', 'part', 'write', 'call'];\n/** How long a write marks the nodes of the graph. */\nconst HOT_MS = 1500;\n\nconst components = new Map<string, Promise<ComponentInfo | undefined>>();\nconst known = new Map<string, ComponentInfo>();\n\n/** Asks the dev server about a component, once. */\nfunction componentInfo(state: DevtoolsState, id: string): Promise<ComponentInfo | undefined> {\n let info = components.get(id);\n if (!info) {\n info = fetch(`${state.endpoint}/${encodeURIComponent(id)}`)\n .then((response) => (response.ok ? (response.json() as Promise<ComponentInfo>) : undefined))\n .then((value) => {\n if (value) {\n known.set(id, value);\n }\n return value;\n })\n .catch(() => undefined);\n components.set(id, info);\n }\n return info;\n}\n\nfunction element<K extends keyof HTMLElementTagNameMap>(\n tag: K,\n attributes: Record<string, string> = {},\n ...children: (Node | string)[]\n): HTMLElementTagNameMap[K] {\n const node = document.createElement(tag);\n for (const [name, value] of Object.entries(attributes)) {\n node.setAttribute(name, value);\n }\n node.append(...children);\n return node;\n}\n\nfunction svg(\n tag: string,\n attributes: Record<string, string | number>,\n ...children: Node[]\n): SVGElement {\n const node = document.createElementNS('http://www.w3.org/2000/svg', tag);\n for (const [name, value] of Object.entries(attributes)) {\n node.setAttribute(name, String(value));\n }\n node.append(...children);\n return node;\n}\n\n/** The root scope of a scope, whose `m` names its component. */\nfunction rootOf(scope: Scope): Scope {\n let root = scope;\n while (root.p) {\n root = root.p;\n }\n return root;\n}\n\n/** A value that can be edited as text: what JSON can hold. */\nfunction editable(value: unknown): boolean {\n if (value === null || ['string', 'number', 'boolean'].includes(typeof value)) {\n return true;\n }\n if (typeof value !== 'object' || value instanceof Element) {\n return false;\n }\n try {\n JSON.stringify(value);\n return true;\n } catch {\n return false;\n }\n}\n\n/** Reads what a person typed: JSON, or else the text as a string. */\nfunction parseValue(text: string): unknown {\n try {\n return JSON.parse(text);\n } catch {\n return text;\n }\n}\n\n/** A write with the name of its slot, once the dev server has said what it is. */\nfunction describe(entry: DevtoolsEntry): string {\n const write = entry.write;\n const info = write && known.get(write.component);\n const name = info?.scopes[write!.k]?.slots[write!.slot];\n return name\n ? `${info!.name} ${name} = ${entry.text.split(' = ').slice(1).join(' = ')}`\n : entry.text;\n}\n\nlet panel: HTMLElement | undefined;\n\n/** Opens the panel, or closes it when it is open. */\nexport function togglePanel(root: ShadowRoot, state: DevtoolsState): void {\n if (panel) {\n panel.remove();\n panel = undefined;\n state.changed = undefined;\n return;\n }\n let tab: Tab = 'scopes';\n let selected: string | undefined;\n let selectedScope: number | undefined;\n let editing: { scope: number; slot: number } | undefined;\n let paused = false;\n const shown = new Set<DevtoolsEntry['kind']>(KINDS);\n // The log as it was when Pause was pressed.\n let frozen: DevtoolsEntry[] | undefined;\n\n const body = element('div', { class: 'body' });\n const bar = element('div', { class: 'bar', role: 'tablist' });\n for (const [name, label] of [\n ['scopes', 'Scopes'],\n ['graph', 'Graph'],\n ['log', 'Log'],\n ['report', 'Report'],\n ] as const) {\n const button = element('button', { class: 'tab', role: 'tab', 'data-tab': name }, label);\n button.addEventListener('click', () => {\n tab = name;\n draw();\n });\n bar.append(button);\n }\n const pick = element(\n 'button',\n {\n class: 'end',\n 'aria-pressed': 'false',\n title: 'Click an element of the page to find its scope',\n },\n 'Pick',\n );\n bar.append(pick);\n panel = element('div', { class: 'panel' }, element('style', {}, STYLE), bar, body);\n root.append(panel);\n // Without an event, the core has not loaded yet, and nothing knows the components of the page.\n if (!state.scopes) {\n document.dispatchEvent(new Event('brumate:core'));\n }\n\n // Outlines the elements of a scope on the page.\n const outlines: HTMLElement[] = [];\n const outline = (scope?: number): void => {\n for (const box of outlines.splice(0)) {\n box.remove();\n }\n if (scope === undefined) {\n return;\n }\n for (const target of document.querySelectorAll(`[data-b^=\"${scope}:\"]`)) {\n const rect = target.getBoundingClientRect();\n const box = element('div', {\n class: 'outline',\n style: `left:${rect.left}px;top:${rect.top}px;width:${rect.width}px;height:${rect.height}px`,\n });\n root.append(box);\n outlines.push(box);\n }\n };\n\n // Pick: the next click on the page selects the scope of its element.\n const onPick = (event: MouseEvent): void => {\n const target = (event.target as Element | null)?.closest?.('[data-b]');\n if (!target || event.composedPath().includes(panel!)) {\n return;\n }\n event.preventDefault();\n event.stopImmediatePropagation();\n stopPicking();\n selectedScope = Number(target.getAttribute('data-b')!.split(':')[0]);\n const scope = state.scopes?.get(selectedScope);\n selected = scope ? rootOf(scope).m : selected;\n tab = 'scopes';\n draw();\n };\n const stopPicking = (): void => {\n pick.setAttribute('aria-pressed', 'false');\n window.removeEventListener('click', onPick, true);\n document.documentElement.style.cursor = '';\n };\n pick.addEventListener('click', () => {\n if (pick.getAttribute('aria-pressed') === 'true') {\n stopPicking();\n return;\n }\n pick.setAttribute('aria-pressed', 'true');\n document.documentElement.style.cursor = 'crosshair';\n // On the window, so it runs before the listeners of the loader on the document.\n window.addEventListener('click', onPick, true);\n });\n\n /** A slot with its name and value. A value that JSON can hold can be edited. */\n const drawSlot = (scope: Scope, slot: number, name: string): HTMLElement => {\n const value = scope.s[slot];\n const line = element('div', { class: 'slot' }, element('span', { class: 'name' }, name), ' = ');\n if (editing?.scope === scope.id && editing.slot === slot) {\n const input = element('input', { 'aria-label': `New value of ${name}` });\n input.value =\n typeof value === 'string' ? JSON.stringify(value) : (JSON.stringify(value) ?? '');\n input.addEventListener('keydown', (event) => {\n if (event.key === 'Enter') {\n editing = undefined;\n state.set?.(scope, slot, parseValue(input.value));\n draw();\n } else if (event.key === 'Escape') {\n editing = undefined;\n draw();\n }\n });\n line.append(input);\n queueMicrotask(() => input.focus());\n return line;\n }\n const text = element(\n 'span',\n { class: editable(value) && state.set ? 'value' : '' },\n preview(value),\n );\n if (editable(value) && state.set) {\n text.title = 'Click to edit. Enter JSON, or text for a string.';\n text.addEventListener('click', () => {\n editing = { scope: scope.id, slot };\n draw();\n });\n }\n line.append(text);\n return line;\n };\n\n /** A scope with its slots and the scopes inside it, other than components. */\n const drawScope = (scope: Scope, info: ComponentInfo | undefined): HTMLElement => {\n const plan = info?.scopes[scope.k];\n const classes = ['scope'];\n if (state.written.has(scope.id)) {\n classes.push('written');\n }\n if (selectedScope === scope.id) {\n classes.push('selected');\n }\n const label = element(\n 'div',\n { class: 'scope-label' },\n `scope ${scope.id}${plan ? ` · ${plan.label}` : ''}`,\n );\n label.addEventListener('mouseenter', () => outline(scope.id));\n label.addEventListener('mouseleave', () => outline());\n const box = element('div', { class: classes.join(' ') }, label);\n scope.s.forEach((_, slot) =>\n box.append(drawSlot(scope, slot, plan?.slots[slot] ?? `slot ${slot}`)),\n );\n for (const child of scope.children) {\n if (child.m === undefined) {\n box.append(drawScope(child, info));\n }\n }\n return box;\n };\n\n const roots = (): Scope[] =>\n [...(state.scopes?.values() ?? [])].filter((scope) => scope.m !== undefined);\n\n const drawScopes = async (): Promise<void> => {\n const list = roots();\n const infos = await Promise.all(list.map((scope) => componentInfo(state, scope.m!)));\n const content = element('div');\n list.forEach((scope, index) => {\n const info = infos[index];\n const name = element('button', {}, info ? `${info.name} (${info.file})` : scope.m!);\n name.title = 'Show the graph of this component';\n name.addEventListener('click', () => {\n selected = scope.m;\n tab = 'graph';\n draw();\n });\n content.append(element('div', { class: 'component' }, name, drawScope(scope, info)));\n });\n if (list.length === 0) {\n content.append(\n element('div', { class: 'empty' }, 'No scopes yet. The first event loads them.'),\n );\n }\n body.replaceChildren(content);\n body.querySelector('.selected')?.scrollIntoView({ block: 'nearest' });\n };\n\n /** A select of the components on the page, for Graph and Report. */\n const chooser = (current: string | undefined): HTMLElement => {\n const select = element('select', { 'aria-label': 'Component' });\n for (const id of new Set(roots().map((scope) => scope.m!))) {\n const option = element('option', { value: id }, known.get(id)?.name ?? id);\n option.selected = id === current;\n select.append(option);\n }\n select.addEventListener('change', () => {\n selected = select.value;\n draw();\n });\n return element('div', {}, select);\n };\n\n let cooling: ReturnType<typeof setTimeout> | undefined;\n\n const drawGraph = async (): Promise<void> => {\n const id = selected ?? roots()[0]?.m;\n const info = id ? await componentInfo(state, id) : undefined;\n if (!id || !info) {\n body.replaceChildren(element('div', { class: 'empty' }, 'No component yet.'));\n return;\n }\n if (!info.graph) {\n body.replaceChildren(\n chooser(id),\n element(\n 'div',\n { class: 'empty' },\n 'The dev server sent no graph. It runs an older brumate than this panel: restart it.',\n ),\n );\n return;\n }\n const { nodes, edges } = info.graph;\n // The current value of each value node, from the first instance of the component.\n const instance = roots().find((scope) => scope.m === id);\n const scopeOfNode = (k: number): Scope | undefined => {\n const visit = (scope: Scope): Scope | undefined => {\n if (scope.k === k) {\n return scope;\n }\n for (const child of scope.children) {\n const found = child.m === undefined ? visit(child) : undefined;\n if (found) {\n return found;\n }\n }\n return undefined;\n };\n return instance && visit(instance);\n };\n // Nodes that a recent write reached: the written value, and what reads it.\n const now = performance.now();\n const hot = new Set<number>();\n for (const entry of state.log) {\n if (entry.write?.component === id && now - entry.time < HOT_MS) {\n nodes.forEach((node, index) => {\n if (node.scope === entry.write!.k && node.slot === entry.write!.slot) {\n hot.add(index);\n }\n });\n }\n }\n for (let grew = true; grew;) {\n grew = false;\n for (const [from, to] of edges) {\n if (hot.has(from) && !hot.has(to)) {\n hot.add(to);\n grew = true;\n }\n }\n }\n // Columns by the longest path from a value that nothing feeds.\n const depth = nodes.map(() => 0);\n for (let round = 0; round < nodes.length; round++) {\n for (const [from, to] of edges) {\n depth[to] = Math.max(depth[to]!, depth[from]! + 1);\n }\n }\n const rows = new Map<number, number>();\n const position = nodes.map((_, index) => {\n const column = depth[index]!;\n const row = rows.get(column) ?? 0;\n rows.set(column, row + 1);\n return { x: 8 + column * 150, y: 8 + row * 34 };\n });\n const width = 8 + (Math.max(0, ...depth) + 1) * 150;\n const height = 8 + Math.max(1, ...rows.values()) * 34;\n const graph = svg('svg', { width, height, role: 'img', 'aria-label': `Graph of ${info.name}` });\n for (const [from, to] of edges) {\n const a = position[from]!;\n const b = position[to]!;\n graph.append(\n svg('line', {\n x1: a.x + 132,\n y1: a.y + 12,\n x2: b.x,\n y2: b.y + 12,\n class: hot.has(from) && hot.has(to) ? 'hot-edge' : '',\n }),\n );\n }\n nodes.forEach((node, index) => {\n const { x, y } = position[index]!;\n const text = svg('text', { x: x + 6, y: y + 16 });\n const owner = node.slot === undefined ? undefined : scopeOfNode(node.scope);\n const value = owner && node.slot !== undefined ? ` = ${preview(owner.s[node.slot])}` : '';\n text.textContent = `${node.label}${value}`.slice(0, 22);\n const title = svg('title', {});\n title.textContent = `${node.kind} ${node.label}${value}`;\n graph.append(\n svg(\n 'g',\n { class: `kind-${node.kind}${hot.has(index) ? ' hot' : ''}` },\n svg('rect', { x, y, width: 132, height: 24, rx: 4 }),\n text,\n title,\n ),\n );\n });\n const legend = element(\n 'div',\n { class: 'legend' },\n 'What reads what, left to right: ',\n element('b', { class: 'signal' }, 'signals and props'),\n ', ',\n element('b', { class: 'memo' }, 'memos'),\n ', markup and ',\n element('b', { class: 'effect' }, 'effects'),\n '. A change lights up in ',\n element('b', { class: 'hot' }, 'yellow'),\n ' what it reaches.',\n );\n body.replaceChildren(\n chooser(id),\n ...(nodes.length > 0\n ? [legend, graph]\n : [\n element('div', { class: 'empty' }, 'Nothing in this component changes in the browser.'),\n ]),\n );\n // Draws again when the marks of the last write expire.\n if (hot.size > 0) {\n clearTimeout(cooling);\n cooling = setTimeout(() => state.changed?.(), HOT_MS);\n }\n };\n\n const drawLog = (): void => {\n const filters = element('div', { class: 'filters' });\n for (const kind of KINDS) {\n const box = element('input', { type: 'checkbox' });\n box.checked = shown.has(kind);\n box.addEventListener('change', () => {\n if (box.checked) {\n shown.add(kind);\n } else {\n shown.delete(kind);\n }\n draw();\n });\n filters.append(element('label', {}, box, kind));\n }\n const pause = element(\n 'button',\n { 'aria-pressed': String(paused) },\n paused ? 'Resume' : 'Pause',\n );\n pause.addEventListener('click', () => {\n paused = !paused;\n frozen = paused ? [...state.log] : undefined;\n draw();\n });\n const clear = element('button', {}, 'Clear');\n clear.addEventListener('click', () => {\n state.log.length = 0;\n frozen = paused ? [] : undefined;\n draw();\n });\n filters.append(pause, clear);\n const list = element('div');\n const entries = (frozen ?? state.log).filter((entry) => shown.has(entry.kind));\n for (const entry of entries.toReversed()) {\n list.append(\n element(\n 'div',\n { class: `entry ${entry.kind}` },\n element('span', { class: 'time' }, `${(entry.time / 1000).toFixed(2)}s`),\n element('span', { class: 'kind' }, entry.kind),\n ` ${entry.kind === 'write' ? describe(entry) : entry.text}`,\n ),\n );\n }\n if (entries.length === 0) {\n list.append(element('div', { class: 'empty' }, 'Nothing to show.'));\n }\n body.replaceChildren(filters, list);\n };\n\n const drawReport = async (): Promise<void> => {\n const id = selected ?? roots()[0]?.m;\n const info = id ? await componentInfo(state, id) : undefined;\n body.replaceChildren(\n ...(info\n ? [chooser(id), element('pre', {}, info.text)]\n : [element('div', { class: 'empty' }, 'No component yet.')]),\n );\n };\n\n let queued = false;\n const draw = (): void => {\n for (const button of bar.querySelectorAll('.tab')) {\n button.setAttribute('aria-selected', String((button as HTMLElement).dataset.tab === tab));\n }\n if (tab === 'log') {\n drawLog();\n return;\n }\n const drawn = tab === 'scopes' ? drawScopes() : tab === 'graph' ? drawGraph() : drawReport();\n // Marks of writes show once, on the next draw of the scopes.\n void drawn.then(() => {\n if (tab === 'scopes') {\n state.written.clear();\n }\n });\n };\n // Changes come in bursts, so the panel draws once per frame. It waits while a value is edited.\n state.changed = () => {\n if (!queued && !editing && !(paused && tab === 'log')) {\n queued = true;\n requestAnimationFrame(() => {\n queued = false;\n if (panel) {\n draw();\n }\n });\n }\n };\n draw();\n}\n"],"mappings":";;AA+BA,MA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