brumate 0.7.1 → 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.
- package/dist/{boot-CMy0f_iC.d.ts → boot-BkUdiYOF.d.ts} +2 -2
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -1
- package/dist/{client-Bm0XbjHr.js → client-B0FXW5Kw.js} +50 -15
- package/dist/client-B0FXW5Kw.js.map +1 -0
- package/dist/{client-DnFF9_lv.d.ts → client-Cq6aTiDs.d.ts} +15 -7
- package/dist/{defer-BWwxv7Qf.js → defer-BMIMP4Hq.js} +3 -3
- package/dist/{defer-BWwxv7Qf.js.map → defer-BMIMP4Hq.js.map} +1 -1
- package/dist/{devtools-Cl6AhENB.js → devtools-B4prrxht.js} +258 -118
- package/dist/devtools-B4prrxht.js.map +1 -0
- package/dist/devtools-calls-DGW6nLZ2.js +249 -0
- package/dist/devtools-calls-DGW6nLZ2.js.map +1 -0
- package/dist/devtools-panel-B1nF1KB7.js +3978 -0
- package/dist/devtools-panel-B1nF1KB7.js.map +1 -0
- package/dist/error-catalog-DakxjSgj.js +308 -0
- package/dist/error-catalog-DakxjSgj.js.map +1 -0
- package/dist/error-catalog-VxLbz-6p.js +1 -0
- package/dist/{files-BuQvpBwF.js → files-D5GtxwEQ.js} +2 -2
- package/dist/{files-BuQvpBwF.js.map → files-D5GtxwEQ.js.map} +1 -1
- package/dist/index.d.ts +73 -18
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/{inspect-BSHv1_25.js → inspect-CGl5Y8q6.js} +581 -399
- package/dist/inspect-CGl5Y8q6.js.map +1 -0
- package/dist/{loader-BPNSRA2A.js → loader-BsaSuIoG.js} +4 -4
- package/dist/{loader-BPNSRA2A.js.map → loader-BsaSuIoG.js.map} +1 -1
- package/dist/{navigate-r23FFR6e.js → navigate-BlowKvhB.js} +18 -10
- package/dist/navigate-BlowKvhB.js.map +1 -0
- package/dist/{rpc-DqfCaYgF.js → rpc-C1jYVNAe.js} +5 -4
- package/dist/rpc-C1jYVNAe.js.map +1 -0
- package/dist/runtime/bundles.d.ts +1 -1
- package/dist/runtime/client.d.ts +2 -2
- package/dist/runtime/client.js +4 -3
- package/dist/runtime/devtools.d.ts +59 -1
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/hot.js +6 -2
- package/dist/runtime/hot.js.map +1 -1
- package/dist/runtime/loader.d.ts +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/server.d.ts +1 -1
- package/dist/runtime/server.js +3 -2
- package/dist/runtime/signals.d.ts +1 -1
- package/dist/runtime/static-loader.d.ts +2 -2
- package/dist/runtime/static-loader.js +1 -1
- package/dist/runtime/store.d.ts +2 -2
- package/dist/runtime/store.js +1 -1
- package/dist/runtime/testing.d.ts +2 -2
- package/dist/runtime/testing.js +2 -2
- package/dist/search-params-Wg-0FsMj.js +148 -0
- package/dist/search-params-Wg-0FsMj.js.map +1 -0
- package/dist/{stream-RXLadXx1.js → serial-ioa17MuY.js} +67 -168
- package/dist/serial-ioa17MuY.js.map +1 -0
- package/dist/serial-ribg9NAj.js +1 -0
- package/dist/{server-BVObWh-w.js → server-BUuf7XPZ.js} +61 -16
- package/dist/server-BUuf7XPZ.js.map +1 -0
- package/dist/{server-0rS5vUW1.d.ts → server-DesBZv5g.d.ts} +8 -3
- package/dist/{search-params-C64liRBj.js → shared-CX_YacDm.js} +3 -148
- package/dist/shared-CX_YacDm.js.map +1 -0
- package/dist/{signals-DBnq9QRW.d.ts → signals-7VVD9C_H.d.ts} +2 -2
- package/dist/skew-CwmX_GFI.js +21 -0
- package/dist/skew-CwmX_GFI.js.map +1 -0
- package/dist/{static-loader-V4V1Oy6G.js → static-loader-C_en-4v8.js} +2 -2
- package/dist/{static-loader-V4V1Oy6G.js.map → static-loader-C_en-4v8.js.map} +1 -1
- package/dist/{static-loader-BYbXVJDY.d.ts → static-loader-UKnK11Em.d.ts} +2 -2
- package/dist/{store-xlTzAM_r.d.ts → store-9_oa0HG1.d.ts} +15 -2
- package/dist/{store-BIBAYZo-.js → store-Cy4EEyZ7.js} +148 -2
- package/dist/store-Cy4EEyZ7.js.map +1 -0
- package/dist/stream-read-BTsYstJY.js +22 -0
- package/dist/stream-read-BTsYstJY.js.map +1 -0
- package/dist/stream-read-Dek3HnqO.js +1 -0
- package/dist/{skew-FRmAy9iy.js → trusted-g_zUJbh2.js} +11 -22
- package/dist/trusted-g_zUJbh2.js.map +1 -0
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +37 -5
- package/dist/vite.js.map +1 -1
- package/package.json +7 -4
- package/skills/brumate/SKILL.md +6 -2
- package/skills/brumate/references/errors.md +21 -2
- package/skills/brumate/references/state.md +31 -0
- package/skills/brumate/references/syntax.md +45 -1
- package/dist/client-Bm0XbjHr.js.map +0 -1
- package/dist/devtools-Cl6AhENB.js.map +0 -1
- package/dist/devtools-panel-DLIeWcAj.js +0 -2017
- package/dist/devtools-panel-DLIeWcAj.js.map +0 -1
- package/dist/inspect-BSHv1_25.js.map +0 -1
- package/dist/navigate-r23FFR6e.js.map +0 -1
- package/dist/rpc-DqfCaYgF.js.map +0 -1
- package/dist/search-params-C64liRBj.js.map +0 -1
- package/dist/server-BVObWh-w.js.map +0 -1
- package/dist/skew-FRmAy9iy.js.map +0 -1
- package/dist/store-BIBAYZo-.js.map +0 -1
- package/dist/stream-RXLadXx1.js.map +0 -1
|
@@ -0,0 +1,3978 @@
|
|
|
1
|
+
import { t as trustedHTML } from "./trusted-g_zUJbh2.js";
|
|
2
|
+
import { a as preview, t as findRootScope } from "./devtools-B4prrxht.js";
|
|
3
|
+
import { t as LOGO } from "./logo-DQ_OYhBi.js";
|
|
4
|
+
//#region src/runtime/devtools-panel/dom.ts
|
|
5
|
+
function element(tag, attributes = {}, ...children) {
|
|
6
|
+
const node = document.createElement(tag);
|
|
7
|
+
for (const [name, value] of Object.entries(attributes)) node.setAttribute(name, value);
|
|
8
|
+
node.append(...children);
|
|
9
|
+
return node;
|
|
10
|
+
}
|
|
11
|
+
function svg(tag, attributes, ...children) {
|
|
12
|
+
const node = document.createElementNS("http://www.w3.org/2000/svg", tag);
|
|
13
|
+
for (const [name, value] of Object.entries(attributes)) node.setAttribute(name, String(value));
|
|
14
|
+
node.append(...children);
|
|
15
|
+
return node;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The icons of the panel: strokes on a grid of 24, in the colour of the text.
|
|
19
|
+
*/
|
|
20
|
+
const ICONS = {
|
|
21
|
+
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\"/>",
|
|
22
|
+
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\"/>",
|
|
23
|
+
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\"/>",
|
|
24
|
+
elements: "<path d=\"M5 4.5 18 10l-5.5 2L10 17.5z\"/><path d=\"m13 13 5.5 5.5\"/>",
|
|
25
|
+
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\"/>",
|
|
26
|
+
log: "<path d=\"M9 6h11M9 12h11M9 18h11\"/><path d=\"M4.5 6h.01M4.5 12h.01M4.5 18h.01\" stroke-width=\"2.6\"/>",
|
|
27
|
+
loading: "<path d=\"M4 6h7M8 12h9M13 18h7\"/>",
|
|
28
|
+
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\"/>",
|
|
29
|
+
effects: "<path d=\"M19.5 12a7.5 7.5 0 1 1-2.2-5.3\"/><path d=\"M19.5 4v4h-4\"/>",
|
|
30
|
+
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\"/>",
|
|
31
|
+
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\"/>",
|
|
32
|
+
timeline: "<circle cx=\"12\" cy=\"13\" r=\"7.5\"/><path d=\"M12 9.5V13l2.5 1.6M10 3h4\"/>",
|
|
33
|
+
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\"/>",
|
|
34
|
+
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\"/>",
|
|
35
|
+
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\"/>",
|
|
36
|
+
close: "<path d=\"m6 9.5 6 6 6-6\"/>",
|
|
37
|
+
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\"/>",
|
|
38
|
+
pause: "<path d=\"M9 5.5v13M15 5.5v13\"/>",
|
|
39
|
+
play: "<path d=\"M8 5.5v13l10.5-6.5z\"/>",
|
|
40
|
+
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\"/>",
|
|
41
|
+
plus: "<path d=\"M12 5v14M5 12h14\"/>",
|
|
42
|
+
minus: "<path d=\"M5 12h14\"/>",
|
|
43
|
+
bolt: "<path d=\"M13 3 5 13.5h6L10 21l9-11h-6z\"/>",
|
|
44
|
+
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\"/>"
|
|
45
|
+
};
|
|
46
|
+
/** An icon by its name, for a button or a tab. */
|
|
47
|
+
function icon(name, size = 14) {
|
|
48
|
+
const node = svg("svg", {
|
|
49
|
+
class: "icon",
|
|
50
|
+
viewBox: "0 0 24 24",
|
|
51
|
+
width: size,
|
|
52
|
+
height: size,
|
|
53
|
+
fill: "none",
|
|
54
|
+
stroke: "currentColor",
|
|
55
|
+
"stroke-width": 1.8,
|
|
56
|
+
"stroke-linecap": "round",
|
|
57
|
+
"stroke-linejoin": "round",
|
|
58
|
+
"aria-hidden": "true"
|
|
59
|
+
});
|
|
60
|
+
node.innerHTML = trustedHTML(ICONS[name]);
|
|
61
|
+
return node;
|
|
62
|
+
}
|
|
63
|
+
/** A button with an icon, and its text or, for an icon alone, its label for screen readers. */
|
|
64
|
+
function iconButton(name, text, attributes = {}, iconOnly = false) {
|
|
65
|
+
const button = element("button", {
|
|
66
|
+
class: `tool${iconOnly ? " only" : ""}`,
|
|
67
|
+
...attributes
|
|
68
|
+
}, icon(name));
|
|
69
|
+
if (iconOnly) {
|
|
70
|
+
button.setAttribute("aria-label", text);
|
|
71
|
+
button.title ||= text;
|
|
72
|
+
} else button.append(text);
|
|
73
|
+
return button;
|
|
74
|
+
}
|
|
75
|
+
function pill(text, color = "") {
|
|
76
|
+
return element("span", { class: `pill ${color}` }, text);
|
|
77
|
+
}
|
|
78
|
+
/** A row of cells, as a table row. */
|
|
79
|
+
function row(cells, tag = "td") {
|
|
80
|
+
const items = [];
|
|
81
|
+
for (const cell of cells) items.push(element(tag, {}, cell));
|
|
82
|
+
return element("tr", {}, ...items);
|
|
83
|
+
}
|
|
84
|
+
/** A square of colour and its meaning, for a legend. */
|
|
85
|
+
function key(color, text) {
|
|
86
|
+
return element("span", {}, element("i", { style: `background: ${color}` }), text);
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/runtime/devtools-panel/format.ts
|
|
90
|
+
/** The type of a value, for the column next to it. */
|
|
91
|
+
function readType(value) {
|
|
92
|
+
if (value === null) return "null";
|
|
93
|
+
if (Array.isArray(value)) return "array";
|
|
94
|
+
if (value instanceof Element) return "element";
|
|
95
|
+
if (typeof value === "object") {
|
|
96
|
+
const name = value.constructor?.name;
|
|
97
|
+
return name && name !== "Object" ? name : "object";
|
|
98
|
+
}
|
|
99
|
+
return typeof value;
|
|
100
|
+
}
|
|
101
|
+
function ms(time) {
|
|
102
|
+
return `${Math.round(time)} ms`;
|
|
103
|
+
}
|
|
104
|
+
function seconds(time) {
|
|
105
|
+
return `${(time / 1e3).toFixed(2)} s`;
|
|
106
|
+
}
|
|
107
|
+
function kilobytes(bytes) {
|
|
108
|
+
return `${(bytes / 1024).toFixed(1)} kB`;
|
|
109
|
+
}
|
|
110
|
+
/** The keys and values of an object, a map or a set, or the items of an array, in a row. */
|
|
111
|
+
function listEntries(value) {
|
|
112
|
+
if (value instanceof Map) return [...value].flat();
|
|
113
|
+
if (value instanceof Set || Array.isArray(value)) return [...value];
|
|
114
|
+
return Object.entries(value).flat();
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* About how many bytes a value takes in the page state. The state is code
|
|
118
|
+
* that seroval writes, which this follows closely enough to compare values.
|
|
119
|
+
*/
|
|
120
|
+
function measureSize(value, seen = /* @__PURE__ */ new Set()) {
|
|
121
|
+
if (value === null || value === void 0) return 6;
|
|
122
|
+
switch (typeof value) {
|
|
123
|
+
case "string": return value.length + 2;
|
|
124
|
+
case "number":
|
|
125
|
+
case "boolean":
|
|
126
|
+
case "bigint": return String(value).length;
|
|
127
|
+
case "function": return 24;
|
|
128
|
+
case "object": {
|
|
129
|
+
if (seen.has(value)) return 6;
|
|
130
|
+
seen.add(value);
|
|
131
|
+
if (value instanceof Date) return 30;
|
|
132
|
+
const entries = listEntries(value);
|
|
133
|
+
let bytes = 2;
|
|
134
|
+
for (const entry of entries) bytes += measureSize(entry, seen) + 1;
|
|
135
|
+
return bytes;
|
|
136
|
+
}
|
|
137
|
+
default: return 8;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** The bytes of the state records of the page. */
|
|
141
|
+
function stateBytes() {
|
|
142
|
+
let bytes = 0;
|
|
143
|
+
for (const script of document.querySelectorAll("script[b-state]")) bytes += script.textContent?.length ?? 0;
|
|
144
|
+
return bytes;
|
|
145
|
+
}
|
|
146
|
+
/** A label cut to the width of a node of the graph. */
|
|
147
|
+
function clip(text) {
|
|
148
|
+
return text.length > 34 ? `${text.slice(0, 33)}…` : text;
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/runtime/devtools-panel/info.ts
|
|
152
|
+
const components = /* @__PURE__ */ new Map();
|
|
153
|
+
const known = /* @__PURE__ */ new Map();
|
|
154
|
+
/** Asks the dev server about a component, once. */
|
|
155
|
+
function componentInfo(state, id) {
|
|
156
|
+
let info = components.get(id);
|
|
157
|
+
if (!info) {
|
|
158
|
+
info = fetch(`${state.endpoint}/${encodeURIComponent(id)}`).then((response) => response.ok ? response.json() : void 0).then((value) => {
|
|
159
|
+
if (value) known.set(id, value);
|
|
160
|
+
return value;
|
|
161
|
+
}).catch(() => void 0);
|
|
162
|
+
components.set(id, info);
|
|
163
|
+
}
|
|
164
|
+
return info;
|
|
165
|
+
}
|
|
166
|
+
/** The IDs of the components that instances in a list belong to. */
|
|
167
|
+
function collectModules(instances) {
|
|
168
|
+
const ids = /* @__PURE__ */ new Set();
|
|
169
|
+
for (const scope of instances) ids.add(scope.m);
|
|
170
|
+
return ids;
|
|
171
|
+
}
|
|
172
|
+
/** How many blocks of the page are in a state. */
|
|
173
|
+
function countBlocks(blocks, blockState) {
|
|
174
|
+
let count = 0;
|
|
175
|
+
for (const block of blocks) if (block.state === blockState) count++;
|
|
176
|
+
return count;
|
|
177
|
+
}
|
|
178
|
+
/** The infos of many components, in the order of their IDs. */
|
|
179
|
+
function loadComponents(state, ids) {
|
|
180
|
+
const pending = [];
|
|
181
|
+
for (const id of ids) pending.push(componentInfo(state, id));
|
|
182
|
+
return Promise.all(pending);
|
|
183
|
+
}
|
|
184
|
+
/** The value of a name that a scope or one of the scopes around it holds. */
|
|
185
|
+
function readValue(scope, name) {
|
|
186
|
+
for (let current = scope; current; current = current.p) {
|
|
187
|
+
const slot = (known.get(findRootScope(current).m ?? "")?.scopes[current.k]?.slots)?.indexOf(name) ?? -1;
|
|
188
|
+
if (slot !== -1) return preview(current.s[slot]);
|
|
189
|
+
if (current.m !== void 0) break;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/** A button that opens a place of a file in the editor, through the dev server. */
|
|
193
|
+
function source(info, at = "1:1") {
|
|
194
|
+
if (!info) return "";
|
|
195
|
+
const label = at === "1:1" ? info.file : `${info.file}:${at}`;
|
|
196
|
+
if (!info.path) return element("span", { class: "mono sub" }, label);
|
|
197
|
+
const open = element("button", {
|
|
198
|
+
class: "link",
|
|
199
|
+
title: "Open in the editor"
|
|
200
|
+
}, label, icon("open", 12));
|
|
201
|
+
open.addEventListener("click", () => {
|
|
202
|
+
fetch(`/__open-in-editor?file=${encodeURIComponent(`${info.path}:${at}`)}`);
|
|
203
|
+
});
|
|
204
|
+
return open;
|
|
205
|
+
}
|
|
206
|
+
/** A button that opens the place of a graph node in the editor. */
|
|
207
|
+
function place(info, at) {
|
|
208
|
+
const label = `line ${at.line}`;
|
|
209
|
+
const file = at.file ?? info.path;
|
|
210
|
+
if (!file) return element("span", { class: "mono sub" }, label);
|
|
211
|
+
const open = element("button", {
|
|
212
|
+
class: "link",
|
|
213
|
+
title: `Open ${at.file ?? info.file}:${at.line}:${at.column}`
|
|
214
|
+
}, label, icon("open", 12));
|
|
215
|
+
open.addEventListener("click", () => {
|
|
216
|
+
fetch(`/__open-in-editor?file=${encodeURIComponent(`${file}:${at.line}:${at.column}`)}`);
|
|
217
|
+
});
|
|
218
|
+
return open;
|
|
219
|
+
}
|
|
220
|
+
/** The scopes of a component instance, without the components inside it. */
|
|
221
|
+
function countScopes(scope) {
|
|
222
|
+
let count = 1;
|
|
223
|
+
for (const child of scope.children ?? []) if (child.m === void 0) count += countScopes(child);
|
|
224
|
+
return count;
|
|
225
|
+
}
|
|
226
|
+
/** The scopes of component instances. */
|
|
227
|
+
function roots(state) {
|
|
228
|
+
const result = [];
|
|
229
|
+
for (const scope of state.scopes?.values() ?? []) if (scope.m !== void 0) result.push(scope);
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
/** The scope with an ID, or nothing when the browser does not have it. */
|
|
233
|
+
function findScope(state, id) {
|
|
234
|
+
return state.scopes?.get(/^-?\d+$/.test(id) ? Number(id) : id);
|
|
235
|
+
}
|
|
236
|
+
async function findAnchor(state, scope, anchor) {
|
|
237
|
+
const component = findRootScope(scope);
|
|
238
|
+
const info = component.m ? await componentInfo(state, component.m) : void 0;
|
|
239
|
+
return {
|
|
240
|
+
info,
|
|
241
|
+
component,
|
|
242
|
+
place: info?.anchors?.[scope.k]?.[anchor]
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
/** The names that an anchor reads, with their values in the scope. */
|
|
246
|
+
function drawReads(scope, reads) {
|
|
247
|
+
const pills = [];
|
|
248
|
+
for (const name of reads) {
|
|
249
|
+
const value = readValue(scope, name);
|
|
250
|
+
pills.push(element("span", {
|
|
251
|
+
class: "pill",
|
|
252
|
+
style: "margin: 0 4px 2px 0"
|
|
253
|
+
}, element("span", { class: "name" }, name), value === void 0 ? "" : ` = ${value}`));
|
|
254
|
+
}
|
|
255
|
+
return pills;
|
|
256
|
+
}
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region src/runtime/devtools-panel/copy.ts
|
|
259
|
+
/** The longest text of a value on screen, as the record cuts them. */
|
|
260
|
+
const TEXT_LIMIT = 1e3;
|
|
261
|
+
/** The longest value on one line of a list. */
|
|
262
|
+
const INLINE_LIMIT = 300;
|
|
263
|
+
/** The lines of source on each side of the line of an error. */
|
|
264
|
+
const SOURCE_AROUND = 6;
|
|
265
|
+
const LEFT_OUT = "[left out]";
|
|
266
|
+
/** Keys that hold cookies, headers or credentials, by a word anywhere in the name. */
|
|
267
|
+
const SECRET_KEY = /(cookie|authorization|headers?|x-auth|api[-_]?key|csrf|token|secret|password)/i;
|
|
268
|
+
/** A name with a credential word in it, then `:` or `=`, such as `Cookie: a=1` or `sessionCookie = x`. */
|
|
269
|
+
const SECRET_LINE = /([\w-]*(?:cookie|authorization|token|api[-_]?key|secret|password|x-auth)[\w-]*)(["'\\\s]*[:=]\s*)[^\n]*/gi;
|
|
270
|
+
const BEARER = /\bBearer\s+[\w.~+/=-]+/gi;
|
|
271
|
+
/** The text without what a cookie, an authorization or a token holds. */
|
|
272
|
+
function scrub(text) {
|
|
273
|
+
return text.replace(SECRET_LINE, `$1$2${LEFT_OUT}`).replace(BEARER, `Bearer ${LEFT_OUT}`);
|
|
274
|
+
}
|
|
275
|
+
/** Cuts a text at a length, and marks the cut. */
|
|
276
|
+
function cutLong(text, limit = TEXT_LIMIT) {
|
|
277
|
+
return text.length > limit ? `${text.slice(0, limit)}… (${text.length - limit} more)` : text;
|
|
278
|
+
}
|
|
279
|
+
/** A copy of a value that JSON can write: long texts cut, maps and sets as plain values, cycles marked. */
|
|
280
|
+
function toPlain(value, ancestors) {
|
|
281
|
+
if (typeof value === "bigint") return `${value}n`;
|
|
282
|
+
if (typeof value === "string") return cutLong(scrub(value));
|
|
283
|
+
if (typeof value === "function") return `[Function ${value.name || "anonymous"}]`;
|
|
284
|
+
if (value instanceof Error) return {
|
|
285
|
+
name: value.name,
|
|
286
|
+
message: cutLong(scrub(value.message))
|
|
287
|
+
};
|
|
288
|
+
if (typeof Headers !== "undefined" && value instanceof Headers) return "[headers]";
|
|
289
|
+
if (typeof value === "object" && value !== null && "tagName" in value) return `<${String(value.tagName).toLowerCase()}>`;
|
|
290
|
+
if (typeof value !== "object" || value === null || value instanceof Date) return value;
|
|
291
|
+
if (ancestors.has(value)) return "[Circular]";
|
|
292
|
+
ancestors.add(value);
|
|
293
|
+
let result;
|
|
294
|
+
if (Array.isArray(value) || value instanceof Set) {
|
|
295
|
+
const items = [];
|
|
296
|
+
for (const item of value) if (Array.isArray(item) && item.length === 2 && typeof item[0] === "string" && SECRET_KEY.test(item[0])) items.push([item[0], LEFT_OUT]);
|
|
297
|
+
else items.push(toPlain(item, ancestors));
|
|
298
|
+
result = items;
|
|
299
|
+
} else {
|
|
300
|
+
const copy = {};
|
|
301
|
+
const entries = value instanceof Map ? value.entries() : Object.entries(value);
|
|
302
|
+
for (const [key, item] of entries) copy[String(key)] = SECRET_KEY.test(String(key)) ? LEFT_OUT : toPlain(item, ancestors);
|
|
303
|
+
result = copy;
|
|
304
|
+
}
|
|
305
|
+
ancestors.delete(value);
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
/** The text of a value for a person or an agent, with long texts cut and cycles left out. */
|
|
309
|
+
function printValue(value) {
|
|
310
|
+
return JSON.stringify(toPlain(value, /* @__PURE__ */ new Set()), void 0, 2) ?? "undefined";
|
|
311
|
+
}
|
|
312
|
+
/** A value on one line, cut at a length: for a list of values. */
|
|
313
|
+
function printInline(value) {
|
|
314
|
+
return cutLong(JSON.stringify(toPlain(value, /* @__PURE__ */ new Set())) ?? "undefined", INLINE_LIMIT);
|
|
315
|
+
}
|
|
316
|
+
/** A block of code in a fence that its content cannot close. */
|
|
317
|
+
function fence(text, language = "") {
|
|
318
|
+
const mark = text.includes("```") ? "````" : "```";
|
|
319
|
+
return `${mark}${language}\n${text}\n${mark}`;
|
|
320
|
+
}
|
|
321
|
+
/** The lines around a line of a source, numbered, with the line itself marked. */
|
|
322
|
+
function cutSource(text, line) {
|
|
323
|
+
const lines = text.split("\n");
|
|
324
|
+
const start = Math.max(1, line - SOURCE_AROUND);
|
|
325
|
+
const end = Math.min(lines.length, line + SOURCE_AROUND);
|
|
326
|
+
const width = String(end).length;
|
|
327
|
+
const out = [];
|
|
328
|
+
for (let number = start; number <= end; number++) out.push(`${number === line ? ">" : " "} ${String(number).padStart(width)} | ${cutLong(lines[number - 1], 200)}`);
|
|
329
|
+
return out.join("\n");
|
|
330
|
+
}
|
|
331
|
+
/** The first lines of the text that tells the versions that the app runs on. */
|
|
332
|
+
function writeVersions(meta) {
|
|
333
|
+
const parts = [];
|
|
334
|
+
if (meta.version) parts.push(`brumate ${meta.version}`);
|
|
335
|
+
if (meta.vite) parts.push(`Vite ${meta.vite}`);
|
|
336
|
+
return parts.length > 0 ? `Versions: ${parts.join(", ")}` : void 0;
|
|
337
|
+
}
|
|
338
|
+
/** The text of an error: the message, the place, the code around it, the stack and the versions. */
|
|
339
|
+
function writeIssue(entry, label, meta = {}, code) {
|
|
340
|
+
const lines = [
|
|
341
|
+
`An error in the dev server of a brumate app: ${label}`,
|
|
342
|
+
"",
|
|
343
|
+
"Message:",
|
|
344
|
+
fence(cutLong(entry.message))
|
|
345
|
+
];
|
|
346
|
+
const place = code ?? entry.loc;
|
|
347
|
+
if (place) {
|
|
348
|
+
lines.push("", `Place: ${place.file}:${place.line}${"column" in place ? `:${place.column}` : ""}`);
|
|
349
|
+
const name = /([^/\\]+)\.brm$/.exec(place.file)?.[1];
|
|
350
|
+
if (name) lines.push(`Component: ${name}`);
|
|
351
|
+
}
|
|
352
|
+
if (entry.plugin) lines.push(`Plugin: ${entry.plugin}`);
|
|
353
|
+
if (code) lines.push("", "Source around the line:", fence(cutSource(code.text, code.line)));
|
|
354
|
+
else if (entry.frame) lines.push("", "Source around the line:", fence(cutLong(entry.frame, 2e3)));
|
|
355
|
+
if (entry.stack) lines.push("", "Stack:", fence(cutLong(entry.stack, 2e3)));
|
|
356
|
+
const versions = writeVersions(meta);
|
|
357
|
+
if (versions) lines.push("", versions);
|
|
358
|
+
return scrub(lines.join("\n"));
|
|
359
|
+
}
|
|
360
|
+
/** The scopes of a component instance, without the components inside it. */
|
|
361
|
+
function listScopes(scope, into = []) {
|
|
362
|
+
into.push(scope);
|
|
363
|
+
for (const child of scope.children ?? []) if (child.m === void 0) listScopes(child, into);
|
|
364
|
+
return into;
|
|
365
|
+
}
|
|
366
|
+
/** The components that an instance renders directly, by name. */
|
|
367
|
+
function listInner(scope, into = []) {
|
|
368
|
+
for (const child of scope.children ?? []) if (child.m === void 0) listInner(child, into);
|
|
369
|
+
else into.push(known.get(child.m)?.name ?? child.m);
|
|
370
|
+
return into;
|
|
371
|
+
}
|
|
372
|
+
/** The text of a component: its file, the value of each slot by name, its contexts and its report. */
|
|
373
|
+
function writeComponent(component, info, meta = {}) {
|
|
374
|
+
const lines = [`A component in the dev server of a brumate app: ${info?.name ?? component.m ?? "component"}`];
|
|
375
|
+
if (info?.file) lines.push(`File: ${info.file}`);
|
|
376
|
+
for (const scope of listScopes(component)) {
|
|
377
|
+
const plan = info?.scopes[scope.k];
|
|
378
|
+
if (scope.s.length === 0) continue;
|
|
379
|
+
lines.push("", `Values of ${scope === component ? "the component" : plan?.label ?? "a scope"}:`);
|
|
380
|
+
for (const [slot, value] of scope.s.entries()) lines.push(`- ${plan?.slots[slot] ?? `slot ${slot}`}: ${printInline(value)}`);
|
|
381
|
+
}
|
|
382
|
+
const inner = listInner(component);
|
|
383
|
+
if (inner.length > 0) lines.push("", `Components inside: ${inner.join(", ")}`);
|
|
384
|
+
const contexts = [];
|
|
385
|
+
for (const scope of listScopes(component)) {
|
|
386
|
+
for (const [key, value] of Object.entries(scope.v ?? {})) contexts.push(`- provides ${key}: ${printInline(value)}`);
|
|
387
|
+
for (const key of Object.keys(scope.x ?? {})) contexts.push(`- reads ${key}`);
|
|
388
|
+
}
|
|
389
|
+
if (contexts.length > 0) lines.push("", "Contexts:", ...contexts);
|
|
390
|
+
if (info?.text) lines.push("", "Report of brumate inspect:", fence(cutLong(info.text, 4e3)));
|
|
391
|
+
const versions = writeVersions(meta);
|
|
392
|
+
if (versions) lines.push("", versions);
|
|
393
|
+
return scrub(lines.join("\n"));
|
|
394
|
+
}
|
|
395
|
+
/** The text of a handler run: the event, the writes, the updates and the server calls with times. */
|
|
396
|
+
function writeRun(run, name, writes) {
|
|
397
|
+
const lines = [`A handler run in the dev server of a brumate app: ${name}`];
|
|
398
|
+
lines.push(`Event: ${run.label}`, `Handler: ${run.ref}`);
|
|
399
|
+
lines.push(`Times: ready after ${ms(run.ready - run.begun)}, code ran ${ms(run.end - run.ready)}` + (run.settled === void 0 ? "" : `, settled after ${ms(run.settled - run.begun)}`));
|
|
400
|
+
if (run.failed) lines.push("The handler failed.");
|
|
401
|
+
if (writes.length > 0) {
|
|
402
|
+
lines.push("", "Writes:");
|
|
403
|
+
for (const text of writes) lines.push(`- ${cutLong(text)}`);
|
|
404
|
+
}
|
|
405
|
+
if (run.updates.length > 0) {
|
|
406
|
+
lines.push("", "Updates:");
|
|
407
|
+
for (const update of run.updates) lines.push(`- ${update.count} ${update.count === 1 ? "update" : "updates"} in ${ms(update.end - update.start)}`);
|
|
408
|
+
}
|
|
409
|
+
if (run.calls.length > 0) {
|
|
410
|
+
lines.push("", "Server calls:");
|
|
411
|
+
for (const call of run.calls) {
|
|
412
|
+
const took = call.end === void 0 ? "pending" : ms(call.end - call.start);
|
|
413
|
+
lines.push(`- ${call.name}(): ${call.status ?? "pending"}, ${took}`);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return scrub(lines.join("\n"));
|
|
417
|
+
}
|
|
418
|
+
/** The text for a coding agent: what was called, with what, what came back and what ran on the server. */
|
|
419
|
+
function writeForAgent(call, from, writes = []) {
|
|
420
|
+
const record = call.record;
|
|
421
|
+
const lines = [`A server function call in the dev server of a brumate app: ${call.name}()`];
|
|
422
|
+
lines.push(`Status: ${call.status ?? "pending"}`);
|
|
423
|
+
if (from) lines.push(`Called by: ${from}`);
|
|
424
|
+
if (record) {
|
|
425
|
+
lines.push("", "Arguments:", printValue(record.args));
|
|
426
|
+
if (record.error) {
|
|
427
|
+
lines.push("", "Error on the server:", cutLong(record.error.message));
|
|
428
|
+
if (record.error.stack) lines.push(cutLong(record.error.stack, 2e3));
|
|
429
|
+
} else if ("result" in record) lines.push("", "Result:", printValue(record.result));
|
|
430
|
+
const { module, network, server, decode } = record.timing;
|
|
431
|
+
lines.push("", `Timing: module ${module} ms, network ${network} ms, server ${server} ms, decode ${decode} ms`);
|
|
432
|
+
const ran = record.server;
|
|
433
|
+
if (ran) {
|
|
434
|
+
if (ran.reads.length > 0) lines.push(`Reloads: ${ran.reads.join(", ")}`);
|
|
435
|
+
if (ran.calls.length > 0) lines.push(`Called on the server: ${ran.calls.join(", ")}`);
|
|
436
|
+
for (const log of ran.logs) lines.push(`console.${log.level}: ${cutLong(log.text)}`);
|
|
437
|
+
if (ran.truncated) lines.push("Some console output was left out.");
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
if (writes.length > 0) lines.push("", "The result changed:", ...writes);
|
|
441
|
+
return scrub(lines.join("\n"));
|
|
442
|
+
}
|
|
443
|
+
/** Writes with a hidden text area, for a page where the clipboard API is missing or refuses. */
|
|
444
|
+
function copyByArea(value) {
|
|
445
|
+
let active = document.activeElement;
|
|
446
|
+
while (active?.shadowRoot?.activeElement) active = active.shadowRoot.activeElement;
|
|
447
|
+
const area = document.createElement("textarea");
|
|
448
|
+
area.value = value;
|
|
449
|
+
area.setAttribute("readonly", "");
|
|
450
|
+
area.style.cssText = "position:fixed;top:0;left:0;opacity:0;pointer-events:none";
|
|
451
|
+
document.body.append(area);
|
|
452
|
+
area.select();
|
|
453
|
+
let done = false;
|
|
454
|
+
try {
|
|
455
|
+
done = document.execCommand("copy");
|
|
456
|
+
} catch {
|
|
457
|
+
done = false;
|
|
458
|
+
}
|
|
459
|
+
area.remove();
|
|
460
|
+
if (active instanceof HTMLElement) active.focus({ preventScroll: true });
|
|
461
|
+
return done;
|
|
462
|
+
}
|
|
463
|
+
/** Puts a text on the clipboard without a promise of it. It tells whether the text arrived. */
|
|
464
|
+
async function writeClipboard(value) {
|
|
465
|
+
try {
|
|
466
|
+
if (navigator.clipboard) {
|
|
467
|
+
await navigator.clipboard.writeText(value);
|
|
468
|
+
return true;
|
|
469
|
+
}
|
|
470
|
+
} catch {}
|
|
471
|
+
return copyByArea(value);
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Starts the write inside the click with a promise of the text, which Safari needs. It gives
|
|
475
|
+
* nothing when the browser has no `ClipboardItem`.
|
|
476
|
+
*/
|
|
477
|
+
function startWrite(pending) {
|
|
478
|
+
if (typeof ClipboardItem === "undefined" || !navigator.clipboard?.write) return;
|
|
479
|
+
const blob = pending.then((value) => {
|
|
480
|
+
if (value === void 0) throw new Error("Nothing to copy");
|
|
481
|
+
return new Blob([value], { type: "text/plain" });
|
|
482
|
+
});
|
|
483
|
+
return navigator.clipboard.write([new ClipboardItem({ "text/plain": blob })]);
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Puts a text on the clipboard from a button. The button answers at once with "Copying", then shows
|
|
487
|
+
* "Copied", or "Copy failed" when the text did not arrive, and goes back after a moment. The text
|
|
488
|
+
* may be read later, such as a source that is fetched when the button is pressed.
|
|
489
|
+
*/
|
|
490
|
+
function copyText(button, text) {
|
|
491
|
+
const original = [...button.childNodes];
|
|
492
|
+
let timer;
|
|
493
|
+
let latest = 0;
|
|
494
|
+
button.addEventListener("click", (event) => {
|
|
495
|
+
event.stopPropagation();
|
|
496
|
+
const run = ++latest;
|
|
497
|
+
button.replaceChildren("Copying");
|
|
498
|
+
clearTimeout(timer);
|
|
499
|
+
let pending;
|
|
500
|
+
try {
|
|
501
|
+
pending = Promise.resolve(text());
|
|
502
|
+
} catch (error) {
|
|
503
|
+
pending = Promise.reject(error);
|
|
504
|
+
}
|
|
505
|
+
let started;
|
|
506
|
+
try {
|
|
507
|
+
started = startWrite(pending);
|
|
508
|
+
} catch {
|
|
509
|
+
started = void 0;
|
|
510
|
+
}
|
|
511
|
+
(async () => {
|
|
512
|
+
let done = false;
|
|
513
|
+
let nothing = false;
|
|
514
|
+
try {
|
|
515
|
+
const value = await pending;
|
|
516
|
+
if (value === void 0) nothing = true;
|
|
517
|
+
else {
|
|
518
|
+
try {
|
|
519
|
+
await started;
|
|
520
|
+
done = started !== void 0;
|
|
521
|
+
} catch {
|
|
522
|
+
done = false;
|
|
523
|
+
}
|
|
524
|
+
done ||= await writeClipboard(value);
|
|
525
|
+
}
|
|
526
|
+
} catch {
|
|
527
|
+
done = false;
|
|
528
|
+
}
|
|
529
|
+
if (run !== latest) return;
|
|
530
|
+
if (nothing) {
|
|
531
|
+
button.replaceChildren(...original);
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
button.replaceChildren(done ? "Copied" : "Copy failed");
|
|
535
|
+
timer = setTimeout(() => {
|
|
536
|
+
button.replaceChildren(...original);
|
|
537
|
+
}, 1200);
|
|
538
|
+
})();
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
/** The icon of the copy button: two sheets. */
|
|
542
|
+
function drawCopyIcon() {
|
|
543
|
+
const node = svg("svg", {
|
|
544
|
+
class: "icon",
|
|
545
|
+
viewBox: "0 0 24 24",
|
|
546
|
+
width: 14,
|
|
547
|
+
height: 14,
|
|
548
|
+
fill: "none",
|
|
549
|
+
stroke: "currentColor",
|
|
550
|
+
"stroke-width": 1.8,
|
|
551
|
+
"stroke-linecap": "round",
|
|
552
|
+
"stroke-linejoin": "round",
|
|
553
|
+
"aria-hidden": "true"
|
|
554
|
+
});
|
|
555
|
+
node.innerHTML = trustedHTML("<rect x=\"8.5\" y=\"8.5\" width=\"11\" height=\"11\" rx=\"2\"/><path d=\"M15.5 8.5V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v7.5a2 2 0 0 0 2 2h2.5\"/>");
|
|
556
|
+
return node;
|
|
557
|
+
}
|
|
558
|
+
/** The Copy for an agent button of a detail header, in the style of the other tools. */
|
|
559
|
+
function drawCopyTool(text) {
|
|
560
|
+
const button = element("button", {
|
|
561
|
+
class: "tool dock-copy",
|
|
562
|
+
"data-focus": "copy"
|
|
563
|
+
});
|
|
564
|
+
button.append(drawCopyIcon(), "Copy for an agent");
|
|
565
|
+
copyText(button, text);
|
|
566
|
+
return button;
|
|
567
|
+
}
|
|
568
|
+
/** The same, as an icon alone, for a row. */
|
|
569
|
+
function drawCopyRowTool(text) {
|
|
570
|
+
const button = element("button", {
|
|
571
|
+
class: "tool only dock-copy dock-copy-row",
|
|
572
|
+
"aria-label": "Copy for an agent",
|
|
573
|
+
title: "Copy for an agent"
|
|
574
|
+
});
|
|
575
|
+
button.append(drawCopyIcon());
|
|
576
|
+
copyText(button, text);
|
|
577
|
+
return button;
|
|
578
|
+
}
|
|
579
|
+
//#endregion
|
|
580
|
+
//#region src/runtime/devtools-panel/activity.ts
|
|
581
|
+
const KIND_ORDER = [
|
|
582
|
+
"nav",
|
|
583
|
+
"block",
|
|
584
|
+
"handler",
|
|
585
|
+
"write",
|
|
586
|
+
"effect",
|
|
587
|
+
"server"
|
|
588
|
+
];
|
|
589
|
+
const LABELS = {
|
|
590
|
+
nav: "Navigation",
|
|
591
|
+
block: "Block",
|
|
592
|
+
handler: "Handler",
|
|
593
|
+
write: "Write",
|
|
594
|
+
effect: "Effect",
|
|
595
|
+
server: "Server"
|
|
596
|
+
};
|
|
597
|
+
const COLORS = {
|
|
598
|
+
nav: "var(--blue)",
|
|
599
|
+
block: "var(--purple)",
|
|
600
|
+
handler: "var(--accent)",
|
|
601
|
+
write: "var(--yellow)",
|
|
602
|
+
effect: "var(--green)",
|
|
603
|
+
server: "var(--pink)"
|
|
604
|
+
};
|
|
605
|
+
function readWork(shell) {
|
|
606
|
+
let work = shell.work.activity;
|
|
607
|
+
if (!work) {
|
|
608
|
+
work = {
|
|
609
|
+
shown: new Set(KIND_ORDER),
|
|
610
|
+
pausedAt: void 0,
|
|
611
|
+
cleared: -1,
|
|
612
|
+
selected: void 0,
|
|
613
|
+
drawn: -1,
|
|
614
|
+
atEnd: true,
|
|
615
|
+
scrollTop: 0,
|
|
616
|
+
detail: void 0
|
|
617
|
+
};
|
|
618
|
+
shell.work.activity = work;
|
|
619
|
+
}
|
|
620
|
+
return work;
|
|
621
|
+
}
|
|
622
|
+
/** A write with the name of its slot, once the dev server has said what it is. */
|
|
623
|
+
function describe$1(entry) {
|
|
624
|
+
const write = entry.write;
|
|
625
|
+
const info = write && known.get(write.component);
|
|
626
|
+
const name = info?.scopes[write.k]?.slots[write.slot];
|
|
627
|
+
return name ? `${info.name} ${name} = ${entry.text.split(" = ").slice(1).join(" = ")}` : entry.text;
|
|
628
|
+
}
|
|
629
|
+
/** The name of a handler, such as `Index h16`, once the dev server said the component. */
|
|
630
|
+
function handlerName(ref) {
|
|
631
|
+
const [component, name = ""] = ref.split("#");
|
|
632
|
+
return `${known.get(component)?.name ?? component} ${name}`;
|
|
633
|
+
}
|
|
634
|
+
/** A round step for the ticks of a ruler: 1, 2 or 5 times a power of ten, at least `rough`. */
|
|
635
|
+
function tickStep(rough) {
|
|
636
|
+
const power = 10 ** Math.floor(Math.log10(rough));
|
|
637
|
+
for (const factor of [
|
|
638
|
+
1,
|
|
639
|
+
2,
|
|
640
|
+
5
|
|
641
|
+
]) if (factor * power >= rough) return factor * power;
|
|
642
|
+
return 10 * power;
|
|
643
|
+
}
|
|
644
|
+
/** The IDs of the components that the rows name, to ask the dev server for their names. */
|
|
645
|
+
function listComponents(state) {
|
|
646
|
+
const ids = /* @__PURE__ */ new Set();
|
|
647
|
+
for (const entry of state.log) if (entry.write) ids.add(entry.write.component);
|
|
648
|
+
else if (entry.kind === "handler") ids.add(readHandler(entry).split("#")[0]);
|
|
649
|
+
else ids.add(entry.text.split(":")[0].split("#")[0]);
|
|
650
|
+
for (const run of state.timeline) {
|
|
651
|
+
ids.add(run.ref.split("#")[0]);
|
|
652
|
+
for (const call of run.calls) ids.add(call.name.split("#")[0]);
|
|
653
|
+
}
|
|
654
|
+
for (const effect of state.effects.values()) ids.add(effect.component);
|
|
655
|
+
return ids;
|
|
656
|
+
}
|
|
657
|
+
/** The reference of a handler entry: `click on <button>: Cart_1#h2` is `Cart_1#h2`. */
|
|
658
|
+
function readHandler(entry) {
|
|
659
|
+
return entry.text.slice(entry.text.lastIndexOf(": ") + 2);
|
|
660
|
+
}
|
|
661
|
+
function addHandler(state, entry, rows, matched) {
|
|
662
|
+
const ref = readHandler(entry);
|
|
663
|
+
const label = entry.text.slice(0, Math.max(0, entry.text.lastIndexOf(": ")));
|
|
664
|
+
let own;
|
|
665
|
+
let bad = false;
|
|
666
|
+
let found;
|
|
667
|
+
for (const run of state.timeline) if (run.ref === ref && Math.abs(run.begun - entry.time) < 100) {
|
|
668
|
+
own = ms(run.end - run.ready);
|
|
669
|
+
bad = run.failed === true;
|
|
670
|
+
matched.add(run);
|
|
671
|
+
found = run;
|
|
672
|
+
}
|
|
673
|
+
rows.push({
|
|
674
|
+
time: entry.time,
|
|
675
|
+
kind: "handler",
|
|
676
|
+
text: handlerName(ref),
|
|
677
|
+
sub: label,
|
|
678
|
+
d: own,
|
|
679
|
+
bad,
|
|
680
|
+
run: found
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
function addCall(entry, rows) {
|
|
684
|
+
const timing = entry.call;
|
|
685
|
+
if (timing) {
|
|
686
|
+
let status = String(timing.status ?? "…");
|
|
687
|
+
if (timing.status === "redirect") {
|
|
688
|
+
const target = /redirect to (.*) in \d+ ms$/.exec(entry.text)?.[1];
|
|
689
|
+
status = target ? `redirect → ${target}` : status;
|
|
690
|
+
}
|
|
691
|
+
rows.push({
|
|
692
|
+
time: entry.time,
|
|
693
|
+
kind: "server",
|
|
694
|
+
text: `${handlerName(timing.name)}()`,
|
|
695
|
+
sub: status,
|
|
696
|
+
d: timing.end === void 0 ? "…" : ms(timing.end - timing.start),
|
|
697
|
+
bad: timing.status === "failed" || typeof timing.status === "number" && timing.status >= 400,
|
|
698
|
+
call: entry
|
|
699
|
+
});
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
const cut = entry.text.indexOf(": ");
|
|
703
|
+
const name = cut === -1 ? entry.text : entry.text.slice(0, cut);
|
|
704
|
+
rows.push({
|
|
705
|
+
time: entry.time,
|
|
706
|
+
kind: "server",
|
|
707
|
+
text: `${handlerName(name)}()`,
|
|
708
|
+
sub: cut === -1 ? void 0 : entry.text.slice(cut + 2),
|
|
709
|
+
bad: entry.text.includes(": failed"),
|
|
710
|
+
call: entry
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
/** Every row of the page, oldest first, before the filters. */
|
|
714
|
+
function collectRows(state) {
|
|
715
|
+
const rows = [];
|
|
716
|
+
const matched = /* @__PURE__ */ new Set();
|
|
717
|
+
for (const entry of state.log) if (entry.kind === "handler") addHandler(state, entry, rows, matched);
|
|
718
|
+
else if (entry.kind === "write") rows.push({
|
|
719
|
+
time: entry.time,
|
|
720
|
+
kind: "write",
|
|
721
|
+
text: describe$1(entry)
|
|
722
|
+
});
|
|
723
|
+
else addCall(entry, rows);
|
|
724
|
+
for (const run of state.timeline) if (!matched.has(run)) rows.push({
|
|
725
|
+
time: run.begun,
|
|
726
|
+
kind: "handler",
|
|
727
|
+
text: handlerName(run.ref),
|
|
728
|
+
sub: run.label,
|
|
729
|
+
d: ms(run.end - run.ready),
|
|
730
|
+
bad: run.failed === true,
|
|
731
|
+
run
|
|
732
|
+
});
|
|
733
|
+
const now = performance.now();
|
|
734
|
+
for (const effect of state.effects.values()) {
|
|
735
|
+
const name = `${known.get(effect.component)?.name ?? effect.component} ${effect.name}`;
|
|
736
|
+
const sub = effect.name.startsWith("c") ? "$client" : "$effect";
|
|
737
|
+
let lastSecond = 0;
|
|
738
|
+
for (const at of effect.recent) if (now - at < 1e3) lastSecond++;
|
|
739
|
+
for (const [index, at] of effect.recent.entries()) {
|
|
740
|
+
const newest = index === effect.recent.length - 1;
|
|
741
|
+
rows.push({
|
|
742
|
+
time: at,
|
|
743
|
+
kind: "effect",
|
|
744
|
+
text: name,
|
|
745
|
+
sub,
|
|
746
|
+
d: newest ? `${effect.runs} runs` : void 0,
|
|
747
|
+
bad: newest && lastSecond >= 10
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
for (const navigation of state.navigations) {
|
|
752
|
+
const url = new URL(navigation.url);
|
|
753
|
+
rows.push({
|
|
754
|
+
time: navigation.start,
|
|
755
|
+
kind: "nav",
|
|
756
|
+
text: url.pathname + url.search,
|
|
757
|
+
sub: navigation.kind,
|
|
758
|
+
d: ms(navigation.time)
|
|
759
|
+
});
|
|
760
|
+
const at = navigation.start;
|
|
761
|
+
if (navigation.full) rows.push({
|
|
762
|
+
time: at,
|
|
763
|
+
kind: "nav",
|
|
764
|
+
text: "the whole page was replaced",
|
|
765
|
+
child: true
|
|
766
|
+
});
|
|
767
|
+
for (const route of navigation.kept) rows.push({
|
|
768
|
+
time: at,
|
|
769
|
+
kind: "nav",
|
|
770
|
+
text: `kept ${route}`,
|
|
771
|
+
child: true
|
|
772
|
+
});
|
|
773
|
+
for (const change of navigation.replaced) rows.push({
|
|
774
|
+
time: at,
|
|
775
|
+
kind: "nav",
|
|
776
|
+
text: `replaced ${change.slot}: ${change.from} → ${change.to}`,
|
|
777
|
+
child: true
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
for (const block of state.blocks.values()) rows.push({
|
|
781
|
+
time: block.rendered ?? block.fired ?? block.seen,
|
|
782
|
+
kind: "block",
|
|
783
|
+
text: `${block.kind} ${block.id}`,
|
|
784
|
+
sub: block.state,
|
|
785
|
+
bad: block.state === "failed"
|
|
786
|
+
});
|
|
787
|
+
return rows.toSorted((a, b) => a.time - b.time);
|
|
788
|
+
}
|
|
789
|
+
/** Marks the writes, effects and calls that a handler caused, so they hang under it. */
|
|
790
|
+
function nestRows(state, rows) {
|
|
791
|
+
for (const row of rows) {
|
|
792
|
+
if (row.kind !== "write" && row.kind !== "effect" && row.kind !== "server") continue;
|
|
793
|
+
for (const run of state.timeline) if (run.begun <= row.time && row.time <= (run.settled ?? run.end) + 32) {
|
|
794
|
+
row.child = true;
|
|
795
|
+
break;
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
/** The ruler above the log: a tick for each row and a mark for each round step. */
|
|
800
|
+
function drawStrip(rows) {
|
|
801
|
+
const strip = element("div", { class: "strip" });
|
|
802
|
+
if (rows.length === 0) return strip;
|
|
803
|
+
const first = rows[0].time;
|
|
804
|
+
const span = Math.max(rows.at(-1).time - first, 1e3);
|
|
805
|
+
const step = tickStep(span / 5);
|
|
806
|
+
for (let at = 0; at <= span; at += step) {
|
|
807
|
+
const left = `left:${at / span * 100}%`;
|
|
808
|
+
strip.append(element("span", {
|
|
809
|
+
class: "rule",
|
|
810
|
+
style: left
|
|
811
|
+
}), element("span", {
|
|
812
|
+
class: "rl",
|
|
813
|
+
style: left
|
|
814
|
+
}, `${+(at / 1e3).toFixed(1)}s`));
|
|
815
|
+
}
|
|
816
|
+
for (const row of rows) strip.append(element("span", {
|
|
817
|
+
class: "tick",
|
|
818
|
+
style: `left:${(row.time - first) / span * 100}%;height:${row.child ? 10 : 16}px;background:${COLORS[row.kind]}`
|
|
819
|
+
}));
|
|
820
|
+
return strip;
|
|
821
|
+
}
|
|
822
|
+
function drawFilters(ctx, work) {
|
|
823
|
+
const { shell, state } = ctx;
|
|
824
|
+
const tools = element("div", { class: "tools" });
|
|
825
|
+
for (const kind of KIND_ORDER) {
|
|
826
|
+
const chip = element("button", {
|
|
827
|
+
class: "chip",
|
|
828
|
+
"aria-pressed": String(work.shown.has(kind))
|
|
829
|
+
}, element("i", { style: `background:${COLORS[kind]}` }), LABELS[kind]);
|
|
830
|
+
chip.addEventListener("click", () => {
|
|
831
|
+
if (work.shown.has(kind)) work.shown.delete(kind);
|
|
832
|
+
else work.shown.add(kind);
|
|
833
|
+
ctx.draw();
|
|
834
|
+
});
|
|
835
|
+
tools.append(chip);
|
|
836
|
+
}
|
|
837
|
+
const pause = element("button", {
|
|
838
|
+
class: "chip",
|
|
839
|
+
"aria-pressed": String(shell.paused)
|
|
840
|
+
}, shell.paused ? "Resume" : "Pause");
|
|
841
|
+
pause.addEventListener("click", () => {
|
|
842
|
+
shell.paused = !shell.paused;
|
|
843
|
+
work.pausedAt = shell.paused ? performance.now() : void 0;
|
|
844
|
+
ctx.draw();
|
|
845
|
+
});
|
|
846
|
+
const clear = element("button", { class: "chip" }, "Clear");
|
|
847
|
+
clear.addEventListener("click", () => {
|
|
848
|
+
work.cleared = performance.now();
|
|
849
|
+
state.log.length = 0;
|
|
850
|
+
state.timeline.length = 0;
|
|
851
|
+
work.selected = void 0;
|
|
852
|
+
ctx.draw();
|
|
853
|
+
});
|
|
854
|
+
tools.append(element("span", { class: "grow" }), pause, clear);
|
|
855
|
+
return tools;
|
|
856
|
+
}
|
|
857
|
+
function toggleCall(ctx, work, entry) {
|
|
858
|
+
work.selected = work.selected === entry ? void 0 : entry;
|
|
859
|
+
ctx.draw();
|
|
860
|
+
}
|
|
861
|
+
function drawRow(ctx, work, row) {
|
|
862
|
+
const classes = ["ent"];
|
|
863
|
+
if (row.child) classes.push("child");
|
|
864
|
+
if (row.time > work.drawn && work.drawn >= 0) classes.push("new");
|
|
865
|
+
const text = element("span", { class: "x" }, ...row.child ? [element("span", { class: "faint" }, "└ ")] : [], element("span", { class: row.bad ? "bad" : "" }, row.text));
|
|
866
|
+
if (row.sub) text.append(" ", element("span", { class: `sub${row.bad ? " bad" : ""}` }, row.sub));
|
|
867
|
+
const line = element("div", {}, element("span", { class: "t" }, seconds(row.time)), element("span", { class: "k" }, element("i", { style: `background:${COLORS[row.kind]}` }), LABELS[row.kind]), text, element("span", { class: "d" }, row.d ?? ""));
|
|
868
|
+
const run = row.run;
|
|
869
|
+
if (run) line.lastElementChild.append(drawCopyRowTool(() => {
|
|
870
|
+
const writes = [];
|
|
871
|
+
for (const item of ctx.state.log) if (item.kind === "write" && item.time >= run.begun && item.time <= (run.settled ?? run.end) + 32) writes.push(describe$1(item));
|
|
872
|
+
return writeRun(run, handlerName(run.ref), writes);
|
|
873
|
+
}));
|
|
874
|
+
const entry = row.call;
|
|
875
|
+
if (entry) {
|
|
876
|
+
classes.push("call");
|
|
877
|
+
line.setAttribute("tabindex", "0");
|
|
878
|
+
line.setAttribute("role", "button");
|
|
879
|
+
line.setAttribute("aria-current", String(entry === work.selected));
|
|
880
|
+
line.addEventListener("click", () => toggleCall(ctx, work, entry));
|
|
881
|
+
line.addEventListener("keydown", (event) => {
|
|
882
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
883
|
+
event.preventDefault();
|
|
884
|
+
toggleCall(ctx, work, entry);
|
|
885
|
+
}
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
line.className = classes.join(" ");
|
|
889
|
+
return line;
|
|
890
|
+
}
|
|
891
|
+
function drawLogColumn(ctx, work, rows) {
|
|
892
|
+
const log = element("div", { class: "log" });
|
|
893
|
+
if (rows.length === 0) log.append(element("div", { class: "empty" }, "Nothing yet. Use the page."));
|
|
894
|
+
for (const row of rows) log.append(drawRow(ctx, work, row));
|
|
895
|
+
log.addEventListener("scroll", () => {
|
|
896
|
+
work.atEnd = log.scrollHeight - log.scrollTop - log.clientHeight < 8;
|
|
897
|
+
work.scrollTop = log.scrollTop;
|
|
898
|
+
});
|
|
899
|
+
queueMicrotask(() => {
|
|
900
|
+
log.scrollTop = work.atEnd ? log.scrollHeight : work.scrollTop;
|
|
901
|
+
});
|
|
902
|
+
return element("div", { class: "act" }, drawFilters(ctx, work), drawStrip(rows), log);
|
|
903
|
+
}
|
|
904
|
+
function drawCloseIcon() {
|
|
905
|
+
const node = svg("svg", {
|
|
906
|
+
class: "icon",
|
|
907
|
+
viewBox: "0 0 24 24",
|
|
908
|
+
width: 14,
|
|
909
|
+
height: 14,
|
|
910
|
+
fill: "none",
|
|
911
|
+
stroke: "currentColor",
|
|
912
|
+
"stroke-width": 1.8,
|
|
913
|
+
"stroke-linecap": "round",
|
|
914
|
+
"aria-hidden": "true"
|
|
915
|
+
});
|
|
916
|
+
node.innerHTML = trustedHTML("<path d=\"m6 6 12 12M18 6 6 18\"/>");
|
|
917
|
+
return node;
|
|
918
|
+
}
|
|
919
|
+
/** The detail pane: the module of the call detail for the selected call. */
|
|
920
|
+
function drawDetail(ctx, work, entry, into) {
|
|
921
|
+
const close = element("button", {
|
|
922
|
+
class: "act-close",
|
|
923
|
+
"aria-label": "Close"
|
|
924
|
+
}, drawCloseIcon());
|
|
925
|
+
close.title = "Close";
|
|
926
|
+
close.addEventListener("click", () => {
|
|
927
|
+
work.selected = void 0;
|
|
928
|
+
ctx.draw();
|
|
929
|
+
});
|
|
930
|
+
const timing = entry.call;
|
|
931
|
+
const kept = work.detail;
|
|
932
|
+
if (!kept || kept.entry !== entry || kept.timing !== timing || kept.record !== timing?.record) {
|
|
933
|
+
const node = ctx.drawCallDetail(entry);
|
|
934
|
+
node.classList.add("call-detail");
|
|
935
|
+
work.detail = {
|
|
936
|
+
entry,
|
|
937
|
+
timing,
|
|
938
|
+
record: timing?.record,
|
|
939
|
+
node
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
into.replaceChildren(close, work.detail.node);
|
|
943
|
+
}
|
|
944
|
+
const ACTIVITY_STYLE = `
|
|
945
|
+
.act, .act-detail { --line2: #36333a; --pink: #ff9ecf; --sel: #ee7a3e14; --ring: #ee7a3e47; }
|
|
946
|
+
.split.activity > .list { padding: 0; gap: 0; }
|
|
947
|
+
.split.activity > .detail { position: relative; padding: 0; }
|
|
948
|
+
.act-detail .calld { width: auto; }
|
|
949
|
+
.act { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100%; }
|
|
950
|
+
.act .tools { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-height: 38px; padding: 7px 10px; border-bottom: 1px solid var(--line); flex: none; }
|
|
951
|
+
.act .grow { flex: 1; }
|
|
952
|
+
.act .chip { height: 24px; padding: 0 9px; border-radius: 7px; background: none; color: var(--faint); font: inherit; font-size: 11.5px; display: inline-flex; gap: 6px; align-items: center; }
|
|
953
|
+
.act .chip:hover { background: var(--hover); color: var(--dim); }
|
|
954
|
+
.act .chip[aria-pressed="true"] { color: var(--text); }
|
|
955
|
+
.act .chip i { width: 7px; height: 7px; border-radius: 2px; opacity: .35; }
|
|
956
|
+
.act .chip[aria-pressed="true"] i { opacity: 1; }
|
|
957
|
+
.strip { position: relative; height: 34px; margin: 0 14px; border-bottom: 1px solid var(--line); flex: none; }
|
|
958
|
+
.strip .tick { position: absolute; bottom: 8px; width: 2px; border-radius: 1px; }
|
|
959
|
+
.strip .rule { position: absolute; bottom: 0; height: 4px; width: 1px; background: var(--line2); }
|
|
960
|
+
.strip .rl { position: absolute; top: 2px; font: 10px var(--mono); color: var(--faint); transform: translateX(-50%); }
|
|
961
|
+
.act .log { flex: 1; overflow: auto; padding: 4px 6px; }
|
|
962
|
+
.ent { display: grid; grid-template-columns: 56px 82px minmax(0, 1fr) auto; gap: 10px; align-items: center; height: 28px; padding: 0 8px; border-radius: 7px; font: 11.5px var(--mono); }
|
|
963
|
+
.ent:hover { background: var(--hover); }
|
|
964
|
+
.ent .t { color: var(--faint); }
|
|
965
|
+
.ent .k { display: flex; align-items: center; gap: 6px; color: var(--dim); font-family: system-ui, sans-serif; font-size: 11.5px; }
|
|
966
|
+
.ent .k i { width: 7px; height: 7px; border-radius: 2px; }
|
|
967
|
+
.ent .x { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
968
|
+
.ent .x .sub { color: var(--faint); margin-right: 6px; }
|
|
969
|
+
.ent .d { color: var(--faint); display: inline-flex; align-items: center; justify-content: flex-end; gap: 6px; }
|
|
970
|
+
.ent .dock-copy-row { height: 20px; padding: 0 5px; font: 10.5px system-ui, sans-serif; color: var(--dim); opacity: 0; transition: opacity .12s; }
|
|
971
|
+
.ent:hover .dock-copy-row, .ent .dock-copy-row:focus-visible, .ent[aria-current="true"] .dock-copy-row { opacity: 1; }
|
|
972
|
+
.ent.child .k { visibility: hidden; }
|
|
973
|
+
.ent.call { cursor: pointer; }
|
|
974
|
+
.ent.call .x::after { content: " details ›"; color: var(--faint); opacity: 0; transition: opacity .12s; }
|
|
975
|
+
.ent.call:hover .x::after, .ent.call:focus-visible .x::after { opacity: 1; }
|
|
976
|
+
.ent[aria-current="true"] { background: var(--sel); box-shadow: inset 0 0 0 1px var(--ring); }
|
|
977
|
+
.ent .bad { color: var(--red); }
|
|
978
|
+
.ent.new { animation: act-fresh .9s ease-out; }
|
|
979
|
+
@keyframes act-fresh { from { background: #ee7a3e1f; } to { background: transparent; } }
|
|
980
|
+
.act-close { position: absolute; top: 10px; right: 12px; width: 26px; height: 26px; padding: 0; display: grid; place-items: center; color: var(--dim); border-radius: 7px; }
|
|
981
|
+
`;
|
|
982
|
+
function drawActivity(ctx, into) {
|
|
983
|
+
const { state, shell } = ctx;
|
|
984
|
+
const work = readWork(shell);
|
|
985
|
+
return loadComponents(state, listComponents(state)).then(() => {
|
|
986
|
+
if (work.selected && !state.log.includes(work.selected)) work.selected = void 0;
|
|
987
|
+
const rows = [];
|
|
988
|
+
for (const row of collectRows(state)) if (row.time > work.cleared && (work.pausedAt === void 0 || row.time <= work.pausedAt) && work.shown.has(row.kind)) rows.push(row);
|
|
989
|
+
nestRows(state, rows);
|
|
990
|
+
const shown = rows.slice(-400);
|
|
991
|
+
const log = drawLogColumn(ctx, work, shown);
|
|
992
|
+
let box;
|
|
993
|
+
if (work.selected) {
|
|
994
|
+
const columns = ctx.split({
|
|
995
|
+
key: "activity",
|
|
996
|
+
min: [320, 280],
|
|
997
|
+
start: 560
|
|
998
|
+
});
|
|
999
|
+
box = columns.box;
|
|
1000
|
+
box.classList.add("activity");
|
|
1001
|
+
columns.second.classList.add("act-detail");
|
|
1002
|
+
columns.first.append(log);
|
|
1003
|
+
drawDetail(ctx, work, work.selected, columns.second);
|
|
1004
|
+
} else {
|
|
1005
|
+
work.detail = void 0;
|
|
1006
|
+
box = element("div", { class: "split activity solo" }, log);
|
|
1007
|
+
}
|
|
1008
|
+
if (!ctx.root.querySelector("style[data-activity]")) ctx.root.append(element("style", { "data-activity": "" }, ACTIVITY_STYLE));
|
|
1009
|
+
into.replaceChildren(box);
|
|
1010
|
+
work.drawn = shown.at(-1)?.time ?? work.drawn;
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
const activity = {
|
|
1014
|
+
id: "activity",
|
|
1015
|
+
label: "Activity",
|
|
1016
|
+
icon: "log",
|
|
1017
|
+
tabs: {
|
|
1018
|
+
log: drawActivity,
|
|
1019
|
+
timeline: drawActivity,
|
|
1020
|
+
effects: drawActivity,
|
|
1021
|
+
navigation: drawActivity,
|
|
1022
|
+
server: drawActivity
|
|
1023
|
+
},
|
|
1024
|
+
draw: drawActivity
|
|
1025
|
+
};
|
|
1026
|
+
//#endregion
|
|
1027
|
+
//#region src/runtime/devtools-panel/stack.ts
|
|
1028
|
+
/** The places of a stack, with their files as the dev server can read them. */
|
|
1029
|
+
function parseFrames(stack) {
|
|
1030
|
+
const frames = [];
|
|
1031
|
+
for (const line of (stack ?? "").split("\n")) {
|
|
1032
|
+
const match = /^\s*at (?:(.*?) \()?(.+?):(\d+):(\d+)\)?\s*$/.exec(line);
|
|
1033
|
+
if (!match) continue;
|
|
1034
|
+
let file = match[2];
|
|
1035
|
+
let compiled = false;
|
|
1036
|
+
if (/^[a-z-]+-extension:/.test(file) || file.startsWith("<")) continue;
|
|
1037
|
+
if (/^https?:/.test(file)) {
|
|
1038
|
+
const url = new URL(file);
|
|
1039
|
+
if (url.origin !== location.origin) continue;
|
|
1040
|
+
compiled = true;
|
|
1041
|
+
file = url.pathname.startsWith("/@fs/") ? url.pathname.slice(4) : url.pathname;
|
|
1042
|
+
} else if (file.startsWith("file://")) file = decodeURIComponent(new URL(file).pathname);
|
|
1043
|
+
frames.push({
|
|
1044
|
+
fn: match[1] ?? "(anonymous)",
|
|
1045
|
+
file,
|
|
1046
|
+
line: Number(match[3]),
|
|
1047
|
+
column: Number(match[4]),
|
|
1048
|
+
library: file.startsWith("node:") || file.includes("/node_modules/") || /\/brumate\/(?:src|dist)\/runtime\//.test(file) || file.includes("/@vite/"),
|
|
1049
|
+
compiled
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
return frames;
|
|
1053
|
+
}
|
|
1054
|
+
/** The places in the sources of frames that the browser ran, by their compiled place. */
|
|
1055
|
+
const mapped = /* @__PURE__ */ new Map();
|
|
1056
|
+
/**
|
|
1057
|
+
* Maps the frames that the browser ran to their sources, by the source maps
|
|
1058
|
+
* of the dev server, so a frame of a component or a module function names
|
|
1059
|
+
* its own file and line. A frame that the dev server cannot map stays as it is.
|
|
1060
|
+
*/
|
|
1061
|
+
function mapFrames(frames, urls) {
|
|
1062
|
+
const results = [];
|
|
1063
|
+
for (const [index, frame] of frames.entries()) {
|
|
1064
|
+
const url = urls[index];
|
|
1065
|
+
if (!frame.compiled || frame.library || !url) {
|
|
1066
|
+
results.push(frame);
|
|
1067
|
+
continue;
|
|
1068
|
+
}
|
|
1069
|
+
const unmapped = {
|
|
1070
|
+
...frame,
|
|
1071
|
+
url
|
|
1072
|
+
};
|
|
1073
|
+
const key = `${url}:${frame.line}:${frame.column}`;
|
|
1074
|
+
let result = mapped.get(key);
|
|
1075
|
+
if (!result) {
|
|
1076
|
+
const query = new URLSearchParams({
|
|
1077
|
+
url,
|
|
1078
|
+
line: String(frame.line),
|
|
1079
|
+
column: String(frame.column)
|
|
1080
|
+
});
|
|
1081
|
+
result = fetch(`/__brumate/position?${query}`).then((response) => response.ok ? response.json() : null).then((place) => place ? {
|
|
1082
|
+
...frame,
|
|
1083
|
+
...place,
|
|
1084
|
+
compiled: false
|
|
1085
|
+
} : unmapped).catch(() => unmapped);
|
|
1086
|
+
mapped.set(key, result);
|
|
1087
|
+
}
|
|
1088
|
+
results.push(result);
|
|
1089
|
+
}
|
|
1090
|
+
return Promise.all(results);
|
|
1091
|
+
}
|
|
1092
|
+
/** The URLs that the frames of a stack name, as the dev server knows the modules. */
|
|
1093
|
+
function frameUrls(stack) {
|
|
1094
|
+
const urls = [];
|
|
1095
|
+
for (const line of (stack ?? "").split("\n")) {
|
|
1096
|
+
const file = /^\s*at (?:(.*?) \()?(.+?):(\d+):(\d+)\)?\s*$/.exec(line)?.[2];
|
|
1097
|
+
if (!file || /^[a-z-]+-extension:/.test(file) || file.startsWith("<")) continue;
|
|
1098
|
+
if (/^https?:/.test(file)) {
|
|
1099
|
+
const url = new URL(file);
|
|
1100
|
+
urls.push(url.origin === location.origin ? url.pathname + url.search : "");
|
|
1101
|
+
if (url.origin !== location.origin) urls.pop();
|
|
1102
|
+
} else urls.push("");
|
|
1103
|
+
}
|
|
1104
|
+
return urls;
|
|
1105
|
+
}
|
|
1106
|
+
/** The highlighter, which loads with the first code that the Errors tab shows. */
|
|
1107
|
+
let highlighter;
|
|
1108
|
+
/** The sources of files, by path. */
|
|
1109
|
+
const sources = /* @__PURE__ */ new Map();
|
|
1110
|
+
/** The code of a module as the dev server sent it to the browser. */
|
|
1111
|
+
function fetchCompiled(url) {
|
|
1112
|
+
let text = sources.get(url);
|
|
1113
|
+
if (!text) {
|
|
1114
|
+
text = fetch(url).then((response) => response.ok ? response.text() : void 0).catch(() => void 0);
|
|
1115
|
+
sources.set(url, text);
|
|
1116
|
+
}
|
|
1117
|
+
return text;
|
|
1118
|
+
}
|
|
1119
|
+
function fetchSource(file) {
|
|
1120
|
+
let text = sources.get(file);
|
|
1121
|
+
if (!text) {
|
|
1122
|
+
text = fetch(`/__brumate/source?file=${encodeURIComponent(file)}`).then((response) => response.ok ? response.text() : void 0).catch(() => void 0);
|
|
1123
|
+
sources.set(file, text);
|
|
1124
|
+
}
|
|
1125
|
+
return text;
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
1128
|
+
* The lines around a place of a file, highlighted by twinkleplop, with the
|
|
1129
|
+
* line of the place and the word at its column marked. Without the source,
|
|
1130
|
+
* the frame of the error is shown as it is.
|
|
1131
|
+
*/
|
|
1132
|
+
async function codeView(place, fallback) {
|
|
1133
|
+
const box = element("div", { class: "code" });
|
|
1134
|
+
const [text, module] = await Promise.all([place.url ? fetchCompiled(place.url) : fetchSource(place.file), highlighter ??= import("./highlight.js")]);
|
|
1135
|
+
if (text === void 0) {
|
|
1136
|
+
box.append(element("pre", { class: "plain" }, fallback ?? "The dev server cannot read this file."));
|
|
1137
|
+
return box;
|
|
1138
|
+
}
|
|
1139
|
+
const lines = text.split("\n");
|
|
1140
|
+
const start = Math.max(1, place.line - 6);
|
|
1141
|
+
const end = Math.min(lines.length, place.line + 6);
|
|
1142
|
+
const target = place.line;
|
|
1143
|
+
const word = /^[\w$.]*/.exec(lines[place.line - 1]?.slice(place.column - 1) ?? "")?.[0] ?? "";
|
|
1144
|
+
box.append(element("style", {}, module.themeCSS("dark")));
|
|
1145
|
+
box.insertAdjacentHTML("beforeend", trustedHTML(module.highlightFile(place.url ? "compiled.ts" : place.file, text, {
|
|
1146
|
+
line_numbers: { start: 1 },
|
|
1147
|
+
line: (index) => index === target ? { class: "error-line" } : void 0,
|
|
1148
|
+
overlays: word.length > 0 ? [{
|
|
1149
|
+
start: {
|
|
1150
|
+
line: target,
|
|
1151
|
+
character: place.column - 1
|
|
1152
|
+
},
|
|
1153
|
+
end: {
|
|
1154
|
+
line: target,
|
|
1155
|
+
character: place.column - 1 + word.length
|
|
1156
|
+
},
|
|
1157
|
+
class: "error-mark"
|
|
1158
|
+
}] : []
|
|
1159
|
+
})));
|
|
1160
|
+
const shown = [...box.querySelectorAll("code > .l")];
|
|
1161
|
+
for (const [index, line] of shown.entries()) if (index + 1 < start || index + 1 > end) {
|
|
1162
|
+
if (line.nextSibling?.nodeType === Node.TEXT_NODE) line.nextSibling.remove();
|
|
1163
|
+
line.remove();
|
|
1164
|
+
}
|
|
1165
|
+
return box;
|
|
1166
|
+
}
|
|
1167
|
+
//#endregion
|
|
1168
|
+
//#region src/runtime/devtools-panel/call-detail.ts
|
|
1169
|
+
/** The longest wait for the writes that the result made, after the answer. */
|
|
1170
|
+
const AFTER_MS = 300;
|
|
1171
|
+
const DEPTH_LIMIT = 8;
|
|
1172
|
+
const PHASES = [
|
|
1173
|
+
["module", "var(--faint)"],
|
|
1174
|
+
["network", "var(--blue)"],
|
|
1175
|
+
["server", "var(--pink)"],
|
|
1176
|
+
["decode", "var(--green)"]
|
|
1177
|
+
];
|
|
1178
|
+
const STYLE$2 = `
|
|
1179
|
+
.calld { --bg2: #161517; --line2: #36333a; --pink: #ff8fc8; width: 440px; flex: none; padding: 16px 20px 20px; min-width: 0; }
|
|
1180
|
+
.calld .title { display: flex; align-items: center; gap: 10px; }
|
|
1181
|
+
.calld .title h3 { margin: 0; font: 600 14px var(--mono); color: var(--text); text-transform: none; letter-spacing: 0; }
|
|
1182
|
+
.calld .sec { margin: 22px 0 8px; display: flex; align-items: baseline; gap: 8px; font-size: 11px; font-weight: 600; color: var(--faint); }
|
|
1183
|
+
.calld .sec .n { font: 10.5px var(--mono); font-weight: 400; }
|
|
1184
|
+
.calld .from { color: var(--dim); margin-top: 6px; }
|
|
1185
|
+
.calld .from .link-button { color: var(--text); cursor: pointer; text-decoration: underline; text-decoration-color: var(--line2); text-underline-offset: 3px; padding: 0; border: 0; background: none; font: inherit; }
|
|
1186
|
+
.calld .from .link-button:hover { text-decoration-color: var(--accent); }
|
|
1187
|
+
.calld .val { font: 11.5px/1.8 var(--mono); background: var(--bg2); border-radius: 8px; padding: 8px 12px; box-shadow: inset 0 0 0 1px var(--line); overflow: auto; }
|
|
1188
|
+
.calld .val details > div, .calld .val details > details { margin-left: 16px; }
|
|
1189
|
+
.calld .val summary { cursor: pointer; list-style: none; }
|
|
1190
|
+
.calld .val summary::-webkit-details-marker { display: none; }
|
|
1191
|
+
.calld .val summary::before { content: '›'; display: inline-block; width: 12px; color: var(--faint); transition: transform 0.15s; }
|
|
1192
|
+
.calld .val details[open] > summary::before { transform: rotate(90deg); }
|
|
1193
|
+
.calld .kk { color: #ffc28f; }
|
|
1194
|
+
.calld .str { color: var(--green); } .calld .num { color: var(--blue); } .calld .bool { color: var(--purple); } .calld .nil { color: var(--faint); }
|
|
1195
|
+
.calld .tbar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; gap: 2px; margin: 4px 0 10px; }
|
|
1196
|
+
.calld .leg { display: flex; gap: 14px; flex-wrap: wrap; color: var(--dim); font: 11px var(--mono); }
|
|
1197
|
+
.calld .leg i { display: inline-block; width: 7px; height: 7px; border-radius: 2px; margin-right: 6px; }
|
|
1198
|
+
.calld .lines { font: 11.5px/1.95 var(--mono); }
|
|
1199
|
+
.calld .lines .faint { display: inline-block; width: 56px; color: var(--faint); }
|
|
1200
|
+
.calld .lines .warn { color: var(--yellow); }
|
|
1201
|
+
.calld .errline { color: var(--red); }
|
|
1202
|
+
.calld .acts { margin-top: 20px; display: flex; gap: 8px; flex-wrap: wrap; }
|
|
1203
|
+
.calld .btn { height: 28px; padding: 0 12px; border-radius: 8px; background: var(--raised); box-shadow: inset 0 0 0 1px var(--line2); display: inline-flex; gap: 7px; align-items: center; font-weight: 500; transition: background 0.12s, box-shadow 0.12s; }
|
|
1204
|
+
.calld .btn:hover { background: var(--hover); box-shadow: inset 0 0 0 1px #4a464f; }
|
|
1205
|
+
.calld .btn.pri { background: var(--text); color: #121113; box-shadow: none; }
|
|
1206
|
+
.calld .btn.pri:hover { background: #fff; }
|
|
1207
|
+
.calld .btn.warn { background: #ffd1661a; color: var(--yellow); box-shadow: inset 0 0 0 1px #ffd16655; }
|
|
1208
|
+
.calld .note { color: var(--yellow); font-size: 11.5px; margin-top: 8px; }
|
|
1209
|
+
.calld .dim { color: var(--dim); }
|
|
1210
|
+
.calld .frames { margin: 6px 0; }
|
|
1211
|
+
`;
|
|
1212
|
+
/** The call of an entry, with the interaction that made it. */
|
|
1213
|
+
function findOwner(state, call) {
|
|
1214
|
+
for (const run of state.timeline) if (run.calls.includes(call)) return run;
|
|
1215
|
+
}
|
|
1216
|
+
/** The root scope of the component whose handler made the call, if the page still has it. */
|
|
1217
|
+
function findCaller(state, run) {
|
|
1218
|
+
const component = run.ref.split("#")[0];
|
|
1219
|
+
for (const scope of state.scopes?.values() ?? []) if (scope.m === component && !scope.p) return scope;
|
|
1220
|
+
}
|
|
1221
|
+
/** The writes that the result of a call made, from the log: the lines of the first moments after the answer. */
|
|
1222
|
+
function findWrites(state, call) {
|
|
1223
|
+
const writes = [];
|
|
1224
|
+
if (call.end === void 0) return writes;
|
|
1225
|
+
for (const entry of state.log) if (entry.kind === "write" && entry.time >= call.end && entry.time <= call.end + AFTER_MS) writes.push(entry.text);
|
|
1226
|
+
return writes;
|
|
1227
|
+
}
|
|
1228
|
+
/** The phases of the timing, with the total. */
|
|
1229
|
+
function readPhases(record) {
|
|
1230
|
+
const phases = [];
|
|
1231
|
+
for (const [name, color] of PHASES) phases.push({
|
|
1232
|
+
name,
|
|
1233
|
+
color,
|
|
1234
|
+
time: record.timing[name]
|
|
1235
|
+
});
|
|
1236
|
+
return phases;
|
|
1237
|
+
}
|
|
1238
|
+
/** The `fetch` call that repeats a call, without cookies and without headers that are not the protocol's. */
|
|
1239
|
+
function writeFetch(call) {
|
|
1240
|
+
const request = call.request;
|
|
1241
|
+
if (!request) return;
|
|
1242
|
+
const url = JSON.stringify(request.url);
|
|
1243
|
+
const body = request.body;
|
|
1244
|
+
if (body instanceof FormData) {
|
|
1245
|
+
const lines = ["const body = new FormData();"];
|
|
1246
|
+
for (const [name, value] of body) if (typeof value === "string") lines.push(`body.set(${JSON.stringify(name)}, ${JSON.stringify(value)});`);
|
|
1247
|
+
else lines.push(`// ${JSON.stringify(name)}: the file ${JSON.stringify(value.name)} (${value.size} bytes), attach it here`);
|
|
1248
|
+
const header = request.headers["x-brumate-args"];
|
|
1249
|
+
lines.push(`await fetch(${url}, { method: 'POST', ${header ? `headers: { 'x-brumate-args': ${JSON.stringify(header)} }, ` : ""}body });`);
|
|
1250
|
+
return lines.join("\n");
|
|
1251
|
+
}
|
|
1252
|
+
const json = typeof body === "string" ? JSON.stringify(body) : void 0;
|
|
1253
|
+
return `await fetch(${url}, {\n method: 'POST',\n${json ? ` body: new Blob([${json}], { type: 'application/json' }),\n` : ""}});`;
|
|
1254
|
+
}
|
|
1255
|
+
/** A value in the tree: texts, numbers and the like in a colour, lists and objects that fold. */
|
|
1256
|
+
function drawValue(value, depth = 0) {
|
|
1257
|
+
if (typeof value === "string") return element("span", { class: "str" }, JSON.stringify(cutLong(value)));
|
|
1258
|
+
if (typeof value === "number" || typeof value === "bigint") return element("span", { class: "num" }, String(value));
|
|
1259
|
+
if (typeof value === "boolean") return element("span", { class: "bool" }, String(value));
|
|
1260
|
+
if (value === null || value === void 0) return element("span", { class: "nil" }, String(value));
|
|
1261
|
+
if (value instanceof Date) return element("span", { class: "str" }, value.toISOString());
|
|
1262
|
+
let entries;
|
|
1263
|
+
let label;
|
|
1264
|
+
if (Array.isArray(value) || value instanceof Set) {
|
|
1265
|
+
entries = [];
|
|
1266
|
+
for (const [index, item] of [...value].entries()) entries.push([String(index), item]);
|
|
1267
|
+
label = `${value instanceof Set ? "Set" : "Array"}(${entries.length})`;
|
|
1268
|
+
} else if (value instanceof Map) {
|
|
1269
|
+
entries = [];
|
|
1270
|
+
for (const [key, item] of value) entries.push([String(key), item]);
|
|
1271
|
+
label = `Map(${value.size})`;
|
|
1272
|
+
} else if (typeof value === "object") {
|
|
1273
|
+
entries = Object.entries(value);
|
|
1274
|
+
label = `{${entries.length}}`;
|
|
1275
|
+
} else return element("span", { class: "nil" }, String(value));
|
|
1276
|
+
if (entries.length === 0 || depth >= DEPTH_LIMIT) return element("span", { class: "nil" }, entries.length === 0 ? label : "…");
|
|
1277
|
+
const details = element("details", {}, element("summary", {}, label));
|
|
1278
|
+
details.open = depth < 2;
|
|
1279
|
+
for (const [key, item] of entries) details.append(element("div", {}, element("span", { class: "kk" }, `${key}: `), drawValue(item, depth + 1)));
|
|
1280
|
+
return details;
|
|
1281
|
+
}
|
|
1282
|
+
/** A button that opens a place of a file in the editor. */
|
|
1283
|
+
function openInEditor$1(frame) {
|
|
1284
|
+
const button = element("button", {
|
|
1285
|
+
class: "link",
|
|
1286
|
+
title: "Open in the editor"
|
|
1287
|
+
}, `${frame.file.replace(/^.*\/(src|test|routes)\//, "$1/")}:${frame.line}:${frame.column}`, icon("open", 12));
|
|
1288
|
+
button.addEventListener("click", () => {
|
|
1289
|
+
fetch(`/__open-in-editor?file=${encodeURIComponent(`${frame.file}:${frame.line}:${frame.column}`)}`);
|
|
1290
|
+
});
|
|
1291
|
+
return button;
|
|
1292
|
+
}
|
|
1293
|
+
/** Marks a frame of the list as the chosen one, and shows its code. */
|
|
1294
|
+
async function showFrame(list, code, frame, button) {
|
|
1295
|
+
for (const other of list.children) other.setAttribute("aria-current", String(other === button));
|
|
1296
|
+
code.replaceChildren(await codeView(frame));
|
|
1297
|
+
}
|
|
1298
|
+
/** Fills the box with the frames of the app, a count of the others, and the code of the chosen frame. */
|
|
1299
|
+
async function fillStack(box, stack) {
|
|
1300
|
+
const frames = await mapFrames(parseFrames(stack), frameUrls(stack));
|
|
1301
|
+
const own = [];
|
|
1302
|
+
for (const frame of frames) if (!frame.library) own.push(frame);
|
|
1303
|
+
const list = element("div", { class: "frames lines" });
|
|
1304
|
+
const code = element("div");
|
|
1305
|
+
for (const frame of own) {
|
|
1306
|
+
const button = element("button", {
|
|
1307
|
+
class: "frame dim",
|
|
1308
|
+
"aria-current": "false",
|
|
1309
|
+
title: "Show this code"
|
|
1310
|
+
}, element("span", { class: "fn" }, frame.fn), element("span", { class: "where" }, `${frame.file}:${frame.line}:${frame.column}`));
|
|
1311
|
+
button.addEventListener("click", () => void showFrame(list, code, frame, button));
|
|
1312
|
+
list.append(button);
|
|
1313
|
+
}
|
|
1314
|
+
box.replaceChildren(list);
|
|
1315
|
+
if (own.length < frames.length) box.append(element("div", { class: "dim" }, `${frames.length - own.length} frames of libraries hidden`));
|
|
1316
|
+
if (own[0]) {
|
|
1317
|
+
box.append(openInEditor$1(own[0]), code);
|
|
1318
|
+
await showFrame(list, code, own[0], list.children[0]);
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
/** The stack of the server error, which fills in once the frames are mapped. */
|
|
1322
|
+
function drawStack(stack) {
|
|
1323
|
+
const box = element("div");
|
|
1324
|
+
if (stack) fillStack(box, stack).catch(() => {
|
|
1325
|
+
box.replaceChildren(element("div", { class: "dim" }, "Could not read the code."));
|
|
1326
|
+
});
|
|
1327
|
+
return box;
|
|
1328
|
+
}
|
|
1329
|
+
/** A section with a heading, hidden by its caller when it has no data. */
|
|
1330
|
+
function drawSection(title, note, ...children) {
|
|
1331
|
+
const heading = element("div", { class: "sec" }, title);
|
|
1332
|
+
if (note) heading.append(element("span", { class: "n" }, note));
|
|
1333
|
+
const section = element("div", {}, heading);
|
|
1334
|
+
section.append(...children);
|
|
1335
|
+
return section;
|
|
1336
|
+
}
|
|
1337
|
+
/** Switches Run again between asking and ready: the warning note and Cancel show while it asks. */
|
|
1338
|
+
function armRun(run, cancel, note, on) {
|
|
1339
|
+
run.textContent = on ? "Run it again" : "Run again";
|
|
1340
|
+
run.className = `btn ${on ? "warn" : "pri"}`;
|
|
1341
|
+
note.hidden = !on;
|
|
1342
|
+
cancel.hidden = !on;
|
|
1343
|
+
}
|
|
1344
|
+
/** Draws the detail of a server call, from the record of its entry. */
|
|
1345
|
+
function drawCallDetail(ctx, entry) {
|
|
1346
|
+
const call = entry.call;
|
|
1347
|
+
const root = element("div", { class: "calld" }, element("style", {}, STYLE$2));
|
|
1348
|
+
if (!call) {
|
|
1349
|
+
root.append(element("div", { class: "empty" }, "No details for this call."));
|
|
1350
|
+
return root;
|
|
1351
|
+
}
|
|
1352
|
+
const { state } = ctx;
|
|
1353
|
+
const record = call.record;
|
|
1354
|
+
const owner = findOwner(state, call);
|
|
1355
|
+
const from = owner?.label;
|
|
1356
|
+
const writes = findWrites(state, call);
|
|
1357
|
+
let total = call.end === void 0 ? 0 : Math.round(call.end - call.start);
|
|
1358
|
+
if (record) {
|
|
1359
|
+
total = 0;
|
|
1360
|
+
for (const phase of readPhases(record)) total += phase.time;
|
|
1361
|
+
}
|
|
1362
|
+
const failed = call.status === "failed" || typeof call.status === "number" && call.status >= 400;
|
|
1363
|
+
root.append(element("div", { class: "title" }, element("h3", {}, `${call.name}()`), element("span", { class: `pill ${failed ? "red" : "green"}` }, String(call.status ?? "pending")), element("span", { class: "dim" }, ms(total))));
|
|
1364
|
+
if (owner) {
|
|
1365
|
+
const caller = findCaller(state, owner);
|
|
1366
|
+
const line = element("div", { class: "from" }, "Called by ");
|
|
1367
|
+
if (caller) {
|
|
1368
|
+
const link = element("button", { class: "link-button" }, owner.label);
|
|
1369
|
+
link.addEventListener("click", () => {
|
|
1370
|
+
ctx.shell.selectedScope = caller.id;
|
|
1371
|
+
ctx.select("inspect");
|
|
1372
|
+
});
|
|
1373
|
+
line.append(link);
|
|
1374
|
+
} else line.append(owner.label);
|
|
1375
|
+
root.append(line);
|
|
1376
|
+
}
|
|
1377
|
+
if (record) {
|
|
1378
|
+
if (record.args.length > 0) {
|
|
1379
|
+
const values = element("div", { class: "val" });
|
|
1380
|
+
for (const [index, arg] of record.args.entries()) values.append(element("div", {}, element("span", { class: "kk" }, `${index}: `), drawValue(arg)));
|
|
1381
|
+
root.append(drawSection("Arguments", void 0, values));
|
|
1382
|
+
}
|
|
1383
|
+
if (record.error) root.append(drawSection("Error on the server", void 0, element("div", { class: "lines" }, element("div", { class: "errline" }, cutLong(record.error.message)), drawStack(record.error.stack))));
|
|
1384
|
+
else if ("result" in record) root.append(drawSection("Result", void 0, element("div", { class: "val" }, drawValue(record.result))));
|
|
1385
|
+
const bar = element("div", { class: "tbar" });
|
|
1386
|
+
const legend = element("div", { class: "leg" });
|
|
1387
|
+
for (const phase of readPhases(record)) {
|
|
1388
|
+
bar.append(element("span", { style: `flex: ${phase.time || .2}; background: ${phase.color}` }));
|
|
1389
|
+
legend.append(element("span", {}, element("i", { style: `background: ${phase.color}` }), `${phase.name} ${ms(phase.time)}`));
|
|
1390
|
+
}
|
|
1391
|
+
root.append(drawSection("Timing", ms(total), bar, legend));
|
|
1392
|
+
const ran = record.server;
|
|
1393
|
+
if (ran && (ran.reads.length > 0 || ran.calls.length > 0 || ran.logs.length > 0)) {
|
|
1394
|
+
const lines = element("div", { class: "lines" });
|
|
1395
|
+
for (const id of ran.reads) lines.append(element("div", {}, element("span", { class: "faint" }, "read"), id));
|
|
1396
|
+
for (const id of ran.calls) lines.append(element("div", {}, element("span", { class: "faint" }, "called"), id));
|
|
1397
|
+
for (const log of ran.logs) lines.append(element("div", {}, element("span", { class: "faint" }, log.level), element("span", { class: log.level }, cutLong(log.text))));
|
|
1398
|
+
if (ran.truncated) lines.append(element("div", { class: "dim" }, "Some output was left out to fit."));
|
|
1399
|
+
root.append(drawSection("On the server", void 0, lines));
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
if (writes.length > 0) {
|
|
1403
|
+
const lines = element("div", { class: "lines" });
|
|
1404
|
+
for (const text of writes) lines.append(element("div", {}, text));
|
|
1405
|
+
root.append(drawSection("After the call", void 0, lines));
|
|
1406
|
+
}
|
|
1407
|
+
const run = element("button", { class: "btn pri" }, "Run again");
|
|
1408
|
+
const cancel = element("button", {
|
|
1409
|
+
class: "btn",
|
|
1410
|
+
hidden: ""
|
|
1411
|
+
}, "Cancel");
|
|
1412
|
+
const fetchButton = element("button", { class: "btn" }, "Copy as fetch");
|
|
1413
|
+
const agentButton = element("button", { class: "btn" }, "Copy for an agent");
|
|
1414
|
+
const note = element("div", {
|
|
1415
|
+
class: "note",
|
|
1416
|
+
hidden: ""
|
|
1417
|
+
}, `Runs ${call.name}() on the server with the same arguments. Its side effects happen again.`);
|
|
1418
|
+
if (!call.request) {
|
|
1419
|
+
run.disabled = true;
|
|
1420
|
+
run.title = "The request was not kept";
|
|
1421
|
+
}
|
|
1422
|
+
run.addEventListener("click", () => {
|
|
1423
|
+
if (note.hidden) {
|
|
1424
|
+
armRun(run, cancel, note, true);
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
armRun(run, cancel, note, false);
|
|
1428
|
+
const request = call.request;
|
|
1429
|
+
if (request) {
|
|
1430
|
+
fetch(request.url, {
|
|
1431
|
+
method: "POST",
|
|
1432
|
+
headers: request.headers,
|
|
1433
|
+
...request.body === void 0 ? {} : { body: request.body }
|
|
1434
|
+
}).catch(() => {});
|
|
1435
|
+
run.textContent = "Ran";
|
|
1436
|
+
setTimeout(() => {
|
|
1437
|
+
run.textContent = "Run again";
|
|
1438
|
+
}, 1200);
|
|
1439
|
+
}
|
|
1440
|
+
});
|
|
1441
|
+
cancel.addEventListener("click", () => armRun(run, cancel, note, false));
|
|
1442
|
+
copyText(fetchButton, () => writeFetch(call));
|
|
1443
|
+
copyText(agentButton, () => writeForAgent(call, from, writes));
|
|
1444
|
+
root.append(element("div", { class: "acts" }, run, cancel, fetchButton, agentButton), note);
|
|
1445
|
+
return root;
|
|
1446
|
+
}
|
|
1447
|
+
//#endregion
|
|
1448
|
+
//#region src/runtime/devtools-panel/workspace.ts
|
|
1449
|
+
/** The kinds of entries that the log shows. */
|
|
1450
|
+
const KINDS = [
|
|
1451
|
+
"handler",
|
|
1452
|
+
"write",
|
|
1453
|
+
"call"
|
|
1454
|
+
];
|
|
1455
|
+
/** A shell in its first state. */
|
|
1456
|
+
function createShell(tab) {
|
|
1457
|
+
return {
|
|
1458
|
+
panel: void 0,
|
|
1459
|
+
showTab: void 0,
|
|
1460
|
+
endPick: void 0,
|
|
1461
|
+
tab,
|
|
1462
|
+
selectedError: void 0,
|
|
1463
|
+
selectedFrame: -1,
|
|
1464
|
+
selected: void 0,
|
|
1465
|
+
selectedScope: void 0,
|
|
1466
|
+
editing: void 0,
|
|
1467
|
+
paused: false,
|
|
1468
|
+
filter: "",
|
|
1469
|
+
logSearch: "",
|
|
1470
|
+
shown: new Set(KINDS),
|
|
1471
|
+
frozen: void 0,
|
|
1472
|
+
picked: void 0,
|
|
1473
|
+
graphNode: void 0,
|
|
1474
|
+
view: {
|
|
1475
|
+
x: 0,
|
|
1476
|
+
y: 0,
|
|
1477
|
+
scale: 1,
|
|
1478
|
+
fitted: ""
|
|
1479
|
+
},
|
|
1480
|
+
cooling: void 0,
|
|
1481
|
+
work: {}
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
/** Draws the tab of the shell, when the workspace holds it. */
|
|
1485
|
+
function drawTabOf(tabs, ctx, into) {
|
|
1486
|
+
return tabs[ctx.shell.tab]?.(ctx, into);
|
|
1487
|
+
}
|
|
1488
|
+
//#endregion
|
|
1489
|
+
//#region src/runtime/devtools-panel/graph.ts
|
|
1490
|
+
/** How long a write marks the nodes of the graph. */
|
|
1491
|
+
const HOT_MS = 1500;
|
|
1492
|
+
/** How long a mark waits at each node it passes, so a write shows its order. */
|
|
1493
|
+
const STEP_MS = 140;
|
|
1494
|
+
/** The height of a node, the distance between rows, the space between columns and the margin. */
|
|
1495
|
+
const NODE_HEIGHT = 42;
|
|
1496
|
+
const ROW = 54;
|
|
1497
|
+
const GAP = 56;
|
|
1498
|
+
const PAD = 24;
|
|
1499
|
+
/** The colour of a node in the graph: signals and props peach, memos purple, effects green, markup blue. */
|
|
1500
|
+
function pickNodeColor(kind, slot) {
|
|
1501
|
+
if (kind === "memo") return "var(--purple)";
|
|
1502
|
+
if (kind === "effect") return "var(--green)";
|
|
1503
|
+
return slot === void 0 ? "var(--blue)" : "#ffc28f";
|
|
1504
|
+
}
|
|
1505
|
+
/** What the tooltip of a node calls its kind. */
|
|
1506
|
+
function nameKind(kind) {
|
|
1507
|
+
if (kind === "memo" || kind === "effect") return `$${kind}`;
|
|
1508
|
+
return kind === "binding" ? "markup" : kind;
|
|
1509
|
+
}
|
|
1510
|
+
/**
|
|
1511
|
+
* Places the nodes of a graph in columns, left to right. A node's column is
|
|
1512
|
+
* its depth, the longest path from a value that nothing feeds, so a memo of
|
|
1513
|
+
* a memo sits one column further. An edge that skips columns passes through
|
|
1514
|
+
* a placeholder in each column it crosses, so no line goes through a node.
|
|
1515
|
+
* Within a column, rows are ordered by the average place of the neighbours,
|
|
1516
|
+
* a few times in each direction, so edges cross less. Each column is as wide
|
|
1517
|
+
* as its widest node and is centred against the tallest one.
|
|
1518
|
+
*
|
|
1519
|
+
* `routes` has, for each edge, the placeholders it passes through.
|
|
1520
|
+
*/
|
|
1521
|
+
function arrangeGraph(nodes, edges, getWidth) {
|
|
1522
|
+
const count = nodes.length;
|
|
1523
|
+
const depth = [];
|
|
1524
|
+
const waiting = [];
|
|
1525
|
+
const nextOf = [];
|
|
1526
|
+
for (let index = 0; index < count; index++) {
|
|
1527
|
+
depth.push(0);
|
|
1528
|
+
waiting.push(0);
|
|
1529
|
+
nextOf.push([]);
|
|
1530
|
+
}
|
|
1531
|
+
for (const [from, to] of edges) {
|
|
1532
|
+
nextOf[from].push(to);
|
|
1533
|
+
waiting[to]++;
|
|
1534
|
+
}
|
|
1535
|
+
const ready = [];
|
|
1536
|
+
for (let index = 0; index < count; index++) if (waiting[index] === 0) ready.push(index);
|
|
1537
|
+
for (let next = ready.pop(); next !== void 0; next = ready.pop()) for (const to of nextOf[next]) {
|
|
1538
|
+
depth[to] = Math.max(depth[to], depth[next] + 1);
|
|
1539
|
+
if (--waiting[to] === 0) ready.push(to);
|
|
1540
|
+
}
|
|
1541
|
+
const level = depth.slice();
|
|
1542
|
+
const links = [];
|
|
1543
|
+
const through = [];
|
|
1544
|
+
const placeholders = /* @__PURE__ */ new Map();
|
|
1545
|
+
for (const [from, to] of edges) {
|
|
1546
|
+
const via = [];
|
|
1547
|
+
let last = from;
|
|
1548
|
+
for (let column = depth[from] + 1; column < depth[to]; column++) {
|
|
1549
|
+
const key = from * (count + 1) + column;
|
|
1550
|
+
let item = placeholders.get(key);
|
|
1551
|
+
if (item === void 0) {
|
|
1552
|
+
item = level.length;
|
|
1553
|
+
level.push(column);
|
|
1554
|
+
placeholders.set(key, item);
|
|
1555
|
+
links.push([last, item]);
|
|
1556
|
+
}
|
|
1557
|
+
via.push(item);
|
|
1558
|
+
last = item;
|
|
1559
|
+
}
|
|
1560
|
+
links.push([last, to]);
|
|
1561
|
+
through.push(via);
|
|
1562
|
+
}
|
|
1563
|
+
const columns = [];
|
|
1564
|
+
for (let index = 0; index < level.length; index++) (columns[level[index]] ??= []).push(index);
|
|
1565
|
+
const filled = [];
|
|
1566
|
+
for (const column of columns) if (column) filled.push(column);
|
|
1567
|
+
const order = /* @__PURE__ */ new Map();
|
|
1568
|
+
for (const column of filled) for (const [index, item] of column.entries()) order.set(item, index);
|
|
1569
|
+
const before = [];
|
|
1570
|
+
const after = [];
|
|
1571
|
+
for (let index = 0; index < level.length; index++) {
|
|
1572
|
+
before.push([]);
|
|
1573
|
+
after.push([]);
|
|
1574
|
+
}
|
|
1575
|
+
for (const [from, to] of links) {
|
|
1576
|
+
after[from].push(to);
|
|
1577
|
+
before[to].push(from);
|
|
1578
|
+
}
|
|
1579
|
+
function average(list, fallback) {
|
|
1580
|
+
if (list.length === 0) return fallback;
|
|
1581
|
+
let sum = 0;
|
|
1582
|
+
for (const item of list) sum += order.get(item);
|
|
1583
|
+
return sum / list.length;
|
|
1584
|
+
}
|
|
1585
|
+
for (let sweep = 0; sweep < 8; sweep++) {
|
|
1586
|
+
const forward = sweep % 2 === 0;
|
|
1587
|
+
const sequence = forward ? filled.slice(1) : filled.slice(0, -1).toReversed();
|
|
1588
|
+
for (const column of sequence) {
|
|
1589
|
+
const weight = /* @__PURE__ */ new Map();
|
|
1590
|
+
for (const item of column) weight.set(item, average(forward ? before[item] : after[item], order.get(item)));
|
|
1591
|
+
column.sort((a, b) => weight.get(a) - weight.get(b));
|
|
1592
|
+
for (const [index, item] of column.entries()) order.set(item, index);
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
let tallest = 1;
|
|
1596
|
+
for (const column of filled) tallest = Math.max(tallest, column.length);
|
|
1597
|
+
const spots = [];
|
|
1598
|
+
let x = PAD;
|
|
1599
|
+
for (const column of filled) {
|
|
1600
|
+
let width = 0;
|
|
1601
|
+
for (const item of column) if (item < count) width = Math.max(width, getWidth(item));
|
|
1602
|
+
const top = PAD + (tallest - column.length) * ROW / 2;
|
|
1603
|
+
for (const [index, item] of column.entries()) spots[item] = {
|
|
1604
|
+
x,
|
|
1605
|
+
y: top + index * ROW,
|
|
1606
|
+
width
|
|
1607
|
+
};
|
|
1608
|
+
x += width + GAP;
|
|
1609
|
+
}
|
|
1610
|
+
const routes = [];
|
|
1611
|
+
for (const via of through) {
|
|
1612
|
+
const route = [];
|
|
1613
|
+
for (const item of via) route.push(spots[item]);
|
|
1614
|
+
routes.push(route);
|
|
1615
|
+
}
|
|
1616
|
+
return {
|
|
1617
|
+
position: spots.slice(0, count),
|
|
1618
|
+
routes
|
|
1619
|
+
};
|
|
1620
|
+
}
|
|
1621
|
+
/** The place of each node, as `arrangeGraph` puts it. */
|
|
1622
|
+
function layoutGraph(nodes, edges, getWidth) {
|
|
1623
|
+
return arrangeGraph(nodes, edges, getWidth).position;
|
|
1624
|
+
}
|
|
1625
|
+
/** The path of an edge: from the right side of its source, through its placeholders, to its target. */
|
|
1626
|
+
function drawEdge(from, via, to) {
|
|
1627
|
+
const half = NODE_HEIGHT / 2;
|
|
1628
|
+
let x = from.x + from.width;
|
|
1629
|
+
let y = from.y + half;
|
|
1630
|
+
let d = `M${x},${y}`;
|
|
1631
|
+
for (const spot of via) {
|
|
1632
|
+
const middle = (x + spot.x) / 2;
|
|
1633
|
+
d += ` C${middle},${y} ${middle},${spot.y + half} ${spot.x},${spot.y + half} L${spot.x + spot.width},${spot.y + half}`;
|
|
1634
|
+
x = spot.x + spot.width;
|
|
1635
|
+
y = spot.y + half;
|
|
1636
|
+
}
|
|
1637
|
+
const end = to.x - 7;
|
|
1638
|
+
const middle = (x + end) / 2;
|
|
1639
|
+
return `${d} C${middle},${y} ${middle},${to.y + half} ${end},${to.y + half}`;
|
|
1640
|
+
}
|
|
1641
|
+
/** The colour class of a value in its text. */
|
|
1642
|
+
function classifyValue(value) {
|
|
1643
|
+
if (value.startsWith("\"")) return "str";
|
|
1644
|
+
if (value === "true" || value === "false") return "bool";
|
|
1645
|
+
return /^-?\d/.test(value) ? "num" : "dim";
|
|
1646
|
+
}
|
|
1647
|
+
const GRAPH_STYLE = `
|
|
1648
|
+
.gwrap { position: relative; height: calc(100% - 42px); min-height: 180px; margin-top: 8px; border-top: 1px solid var(--line); overflow: hidden; cursor: grab; touch-action: none; background: radial-gradient(circle, #ffffff0d 1px, transparent 1.2px) 0 0 / 18px 18px; }
|
|
1649
|
+
.gwrap.dragging { cursor: grabbing; }
|
|
1650
|
+
.gwrap > svg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
|
|
1651
|
+
.gwrap .node { cursor: pointer; outline: none; }
|
|
1652
|
+
.gwrap .node rect.box { fill: var(--raised); stroke: #36333a; stroke-width: 1; transition: fill 0.2s, stroke 0.2s; }
|
|
1653
|
+
.gwrap .node:hover rect.box { stroke: #4a464f; }
|
|
1654
|
+
.gwrap .node:focus-visible rect.box { stroke: var(--accent); }
|
|
1655
|
+
.gwrap .node .name { fill: var(--text); font: 500 12px var(--mono); }
|
|
1656
|
+
.gwrap .node .meta { fill: var(--dim); font: 11px var(--mono); }
|
|
1657
|
+
.gwrap .node .meta.str { fill: var(--green); }
|
|
1658
|
+
.gwrap .node .meta.num { fill: var(--blue); }
|
|
1659
|
+
.gwrap .node .meta.bool { fill: var(--purple); }
|
|
1660
|
+
.gwrap .node.selected rect.box { fill: #ee7a3e14; stroke: #ee7a3e80; }
|
|
1661
|
+
.gwrap .node.hot rect.box { animation: graph-mark 0.2s both; }
|
|
1662
|
+
.gwrap path.gedge.hot-edge { animation: graph-mark-edge 0.2s both; }
|
|
1663
|
+
@keyframes graph-mark { to { fill: #ffd16624; stroke: #ffd166; } }
|
|
1664
|
+
@keyframes graph-mark-edge { to { stroke: #ffd166; stroke-width: 1.6; } }
|
|
1665
|
+
.gwrap .node.faded { opacity: 0.35; }
|
|
1666
|
+
.gwrap path.gedge { fill: none; stroke: #4a464f; stroke-width: 1.2; transition: stroke 0.2s, opacity 0.2s; }
|
|
1667
|
+
.gwrap path.gedge.lit { stroke: var(--accent); stroke-width: 1.6; }
|
|
1668
|
+
.gwrap path.gedge.faded { opacity: 0.25; }
|
|
1669
|
+
.gtools { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 2px; padding: 3px; border-radius: 9px; background: var(--bg); box-shadow: 0 0 0 1px #36333a, 0 8px 20px #0007; }
|
|
1670
|
+
.gtools button { width: 26px; height: 26px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border: 0; }
|
|
1671
|
+
.graph-side { position: absolute; top: 10px; right: 10px; bottom: 10px; width: 250px; overflow: auto; padding: 14px 16px; border: 0; border-radius: 10px; background: var(--bg); box-shadow: 0 0 0 1px #36333a, 0 12px 32px #0009; cursor: default; }
|
|
1672
|
+
.graph-side h4 { margin: 0; display: flex; align-items: center; gap: 8px; font: 600 13px var(--mono); }
|
|
1673
|
+
.graph-side h4 i { flex: none; width: 8px; height: 8px; border-radius: 2px; }
|
|
1674
|
+
.graph-side h4 button { margin-left: auto; width: 24px; height: 24px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border: 0; }
|
|
1675
|
+
.graph-side .kind { margin-top: 4px; display: flex; align-items: center; gap: 8px; color: var(--dim); font: 11.5px var(--mono); }
|
|
1676
|
+
.graph-side .gv { margin-top: 10px; font: 12px var(--mono); overflow-wrap: anywhere; }
|
|
1677
|
+
.graph-side .sec { margin: 16px 0 6px; color: var(--faint); font-size: 11px; }
|
|
1678
|
+
.graph-side .lk { display: flex; align-items: center; gap: 7px; width: calc(100% + 16px); height: 26px; margin: 0 -8px; padding: 0 8px; border: 0; border-radius: 6px; font: 11.5px var(--mono); text-align: left; }
|
|
1679
|
+
.graph-side .lk i { flex: none; width: 7px; height: 7px; border-radius: 2px; }
|
|
1680
|
+
.graph-side .lk span { margin-left: auto; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1681
|
+
.graph-side .str { color: var(--green); }
|
|
1682
|
+
.graph-side .num { color: var(--blue); }
|
|
1683
|
+
.graph-side .bool { color: var(--purple); }
|
|
1684
|
+
.graph-side .dim { color: var(--dim); }
|
|
1685
|
+
`;
|
|
1686
|
+
/** A cross, to close the side. */
|
|
1687
|
+
function drawCross() {
|
|
1688
|
+
return svg("svg", {
|
|
1689
|
+
width: 14,
|
|
1690
|
+
height: 14,
|
|
1691
|
+
viewBox: "0 0 24 24",
|
|
1692
|
+
fill: "none",
|
|
1693
|
+
stroke: "currentColor",
|
|
1694
|
+
"stroke-width": 2,
|
|
1695
|
+
"stroke-linecap": "round",
|
|
1696
|
+
"aria-hidden": "true"
|
|
1697
|
+
}, svg("path", { d: "M6 6l12 12M18 6 6 18" }));
|
|
1698
|
+
}
|
|
1699
|
+
/** The arrowhead of an edge, in the colour of its stroke, so it follows the stroke when that changes. */
|
|
1700
|
+
function drawArrow(name) {
|
|
1701
|
+
return svg("marker", {
|
|
1702
|
+
id: name,
|
|
1703
|
+
viewBox: "0 0 8 8",
|
|
1704
|
+
refX: 1,
|
|
1705
|
+
refY: 4,
|
|
1706
|
+
markerWidth: 8,
|
|
1707
|
+
markerHeight: 8,
|
|
1708
|
+
orient: "auto"
|
|
1709
|
+
}, svg("path", {
|
|
1710
|
+
d: "M0,0.5 L7,4 L0,7.5 z",
|
|
1711
|
+
fill: "context-stroke"
|
|
1712
|
+
}));
|
|
1713
|
+
}
|
|
1714
|
+
/** What a node reaches by the edges of an adjacency list, at any depth, with the steps it took. */
|
|
1715
|
+
function follow(start, adjacent) {
|
|
1716
|
+
const found = /* @__PURE__ */ new Map([[start, 0]]);
|
|
1717
|
+
const queue = [start];
|
|
1718
|
+
for (let at = 0; at < queue.length; at++) {
|
|
1719
|
+
const next = queue[at];
|
|
1720
|
+
for (const far of adjacent[next]) if (!found.has(far)) {
|
|
1721
|
+
found.set(far, found.get(next) + 1);
|
|
1722
|
+
queue.push(far);
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
return found;
|
|
1726
|
+
}
|
|
1727
|
+
/**
|
|
1728
|
+
* The graph of a component as a panel, from any scope of one of its instances.
|
|
1729
|
+
* Without the dev server's graph, or without nodes, it shows an empty state.
|
|
1730
|
+
*/
|
|
1731
|
+
function drawGraph(ctx, scope, info) {
|
|
1732
|
+
if (!info?.graph) return element("div", { class: "empty" }, "No graph for this component.");
|
|
1733
|
+
const instance = findRootScope(scope);
|
|
1734
|
+
return drawNodes(ctx, instance.m ?? "", instance, info);
|
|
1735
|
+
}
|
|
1736
|
+
function drawNodes(ctx, id, instance, info) {
|
|
1737
|
+
const { state, shell } = ctx;
|
|
1738
|
+
const { nodes, edges } = info.graph;
|
|
1739
|
+
if (nodes.length === 0) return element("div", { class: "empty" }, "Nothing in this component changes in the browser.");
|
|
1740
|
+
if (!ctx.root.querySelector("style[data-graph]")) ctx.root.append(element("style", { "data-graph": "" }, GRAPH_STYLE));
|
|
1741
|
+
const scopeByNode = /* @__PURE__ */ new Map();
|
|
1742
|
+
function visit(scope) {
|
|
1743
|
+
if (!scopeByNode.has(scope.k)) scopeByNode.set(scope.k, scope);
|
|
1744
|
+
for (const child of scope.children ?? []) if (child.m === void 0) visit(child);
|
|
1745
|
+
}
|
|
1746
|
+
if (instance) visit(instance);
|
|
1747
|
+
const readsOf = [];
|
|
1748
|
+
const readersOf = [];
|
|
1749
|
+
for (let index = 0; index < nodes.length; index++) {
|
|
1750
|
+
readsOf.push([]);
|
|
1751
|
+
readersOf.push([]);
|
|
1752
|
+
}
|
|
1753
|
+
for (const [from, to] of edges) {
|
|
1754
|
+
readersOf[from].push(to);
|
|
1755
|
+
readsOf[to].push(from);
|
|
1756
|
+
}
|
|
1757
|
+
const now = performance.now();
|
|
1758
|
+
const hot = /* @__PURE__ */ new Map();
|
|
1759
|
+
const written = /* @__PURE__ */ new Map();
|
|
1760
|
+
for (const [index, node] of nodes.entries()) if (node.slot !== void 0) {
|
|
1761
|
+
const key = `${node.scope}:${node.slot}`;
|
|
1762
|
+
const list = written.get(key);
|
|
1763
|
+
if (list) list.push(index);
|
|
1764
|
+
else written.set(key, [index]);
|
|
1765
|
+
}
|
|
1766
|
+
const reached = /* @__PURE__ */ new Map();
|
|
1767
|
+
for (const entry of state.log) {
|
|
1768
|
+
if (entry.write?.component !== id) continue;
|
|
1769
|
+
const elapsed = now - entry.time;
|
|
1770
|
+
for (const start of written.get(`${entry.write.k}:${entry.write.slot}`) ?? []) {
|
|
1771
|
+
let found = reached.get(start);
|
|
1772
|
+
if (!found) {
|
|
1773
|
+
const steps = follow(start, readersOf);
|
|
1774
|
+
found = {
|
|
1775
|
+
steps,
|
|
1776
|
+
deepest: Math.max(...steps.values())
|
|
1777
|
+
};
|
|
1778
|
+
reached.set(start, found);
|
|
1779
|
+
}
|
|
1780
|
+
if (elapsed >= found.deepest * STEP_MS + 1500) continue;
|
|
1781
|
+
for (const [index, steps] of found.steps) {
|
|
1782
|
+
const end = entry.time + steps * STEP_MS + HOT_MS;
|
|
1783
|
+
if (end > now && end > (hot.get(index)?.end ?? 0)) hot.set(index, {
|
|
1784
|
+
delay: steps * STEP_MS - elapsed,
|
|
1785
|
+
end
|
|
1786
|
+
});
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
const parts = [];
|
|
1791
|
+
for (const node of nodes) {
|
|
1792
|
+
const at = node.at ? `${node.at.line}:${node.at.column}` : void 0;
|
|
1793
|
+
const owner = node.slot === void 0 ? void 0 : scopeByNode.get(node.scope);
|
|
1794
|
+
const value = owner && node.slot !== void 0 ? preview(owner.s[node.slot]) : void 0;
|
|
1795
|
+
let meta = at ? `${nameKind(node.kind)} · ${at}` : nameKind(node.kind);
|
|
1796
|
+
if (value !== void 0) meta = value;
|
|
1797
|
+
parts.push({
|
|
1798
|
+
name: node.label,
|
|
1799
|
+
meta,
|
|
1800
|
+
value,
|
|
1801
|
+
at
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
function getNodeWidth(index) {
|
|
1805
|
+
return Math.min(262, Math.max(120, 36 + 7 * Math.max(clip(parts[index].name).length, clip(parts[index].meta).length)));
|
|
1806
|
+
}
|
|
1807
|
+
const { position, routes } = arrangeGraph(nodes, edges, getNodeWidth);
|
|
1808
|
+
const selected = shell.graphNode !== void 0 && shell.graphNode < nodes.length ? shell.graphNode : void 0;
|
|
1809
|
+
const upstream = selected === void 0 ? void 0 : follow(selected, readsOf);
|
|
1810
|
+
const downstream = selected === void 0 ? void 0 : follow(selected, readersOf);
|
|
1811
|
+
const lineage = /* @__PURE__ */ new Set([...upstream?.keys() ?? [], ...downstream?.keys() ?? []]);
|
|
1812
|
+
let graphWidth = 0;
|
|
1813
|
+
let graphHeight = 0;
|
|
1814
|
+
for (const spot of position) {
|
|
1815
|
+
graphWidth = Math.max(graphWidth, spot.x + spot.width);
|
|
1816
|
+
graphHeight = Math.max(graphHeight, spot.y + NODE_HEIGHT);
|
|
1817
|
+
}
|
|
1818
|
+
graphWidth += PAD;
|
|
1819
|
+
graphHeight += PAD;
|
|
1820
|
+
const layer = svg("g", { class: "layer" });
|
|
1821
|
+
const behind = [];
|
|
1822
|
+
const plain = [];
|
|
1823
|
+
const front = [];
|
|
1824
|
+
for (const [index, [from, to]] of edges.entries()) {
|
|
1825
|
+
const classes = ["gedge"];
|
|
1826
|
+
let style = "";
|
|
1827
|
+
let pile = plain;
|
|
1828
|
+
if (hot.has(from) && hot.has(to)) {
|
|
1829
|
+
classes.push("hot-edge");
|
|
1830
|
+
style = `animation-delay: ${hot.get(to).delay}ms`;
|
|
1831
|
+
pile = front;
|
|
1832
|
+
} else if (selected !== void 0) {
|
|
1833
|
+
const through = upstream.has(from) && upstream.has(to) || downstream.has(from) && downstream.has(to);
|
|
1834
|
+
classes.push(through ? "lit" : "faded");
|
|
1835
|
+
pile = through ? front : behind;
|
|
1836
|
+
}
|
|
1837
|
+
pile.push(svg("path", {
|
|
1838
|
+
class: classes.join(" "),
|
|
1839
|
+
"data-edge": index,
|
|
1840
|
+
d: drawEdge(position[from], routes[index], position[to]),
|
|
1841
|
+
"marker-end": "url(#arrow)",
|
|
1842
|
+
...style ? { style } : {}
|
|
1843
|
+
}));
|
|
1844
|
+
}
|
|
1845
|
+
layer.append(...behind, ...plain, ...front);
|
|
1846
|
+
for (const [index, node] of nodes.entries()) {
|
|
1847
|
+
const { x, y, width: nodeWidth } = position[index];
|
|
1848
|
+
const part = parts[index];
|
|
1849
|
+
const classes = ["node"];
|
|
1850
|
+
if (hot.has(index)) classes.push("hot");
|
|
1851
|
+
if (selected === index) classes.push("selected");
|
|
1852
|
+
if (selected !== void 0 && !lineage.has(index)) classes.push("faded");
|
|
1853
|
+
const name = svg("text", {
|
|
1854
|
+
class: "name",
|
|
1855
|
+
x: x + 24,
|
|
1856
|
+
y: y + 19
|
|
1857
|
+
});
|
|
1858
|
+
name.textContent = clip(part.name);
|
|
1859
|
+
const meta = svg("text", {
|
|
1860
|
+
class: part.value === void 0 ? "meta" : `meta ${classifyValue(part.value)}`,
|
|
1861
|
+
x: x + 24,
|
|
1862
|
+
y: y + 33
|
|
1863
|
+
});
|
|
1864
|
+
meta.textContent = clip(part.meta);
|
|
1865
|
+
const title = svg("title", {});
|
|
1866
|
+
title.textContent = `${nameKind(node.kind)} ${node.label}${part.value === void 0 ? "" : ` = ${part.value}`}${part.at ? `, line ${node.at.line}` : ""}`;
|
|
1867
|
+
const group = svg("g", {
|
|
1868
|
+
class: classes.join(" "),
|
|
1869
|
+
"data-node": index,
|
|
1870
|
+
tabindex: 0,
|
|
1871
|
+
role: "button",
|
|
1872
|
+
"aria-label": `${nameKind(node.kind)} ${node.label}`
|
|
1873
|
+
}, svg("rect", {
|
|
1874
|
+
class: "box",
|
|
1875
|
+
x,
|
|
1876
|
+
y,
|
|
1877
|
+
width: nodeWidth,
|
|
1878
|
+
height: NODE_HEIGHT,
|
|
1879
|
+
rx: 8,
|
|
1880
|
+
...hot.has(index) ? { style: `animation-delay: ${hot.get(index).delay}ms` } : {}
|
|
1881
|
+
}), svg("circle", {
|
|
1882
|
+
class: "kind",
|
|
1883
|
+
cx: x + 14,
|
|
1884
|
+
cy: y + 15,
|
|
1885
|
+
r: 3.5,
|
|
1886
|
+
fill: pickNodeColor(node.kind, node.slot)
|
|
1887
|
+
}), name, meta, title);
|
|
1888
|
+
function choose() {
|
|
1889
|
+
select(shell.graphNode === index ? void 0 : index, index);
|
|
1890
|
+
}
|
|
1891
|
+
group.addEventListener("click", (event) => {
|
|
1892
|
+
event.stopPropagation();
|
|
1893
|
+
choose();
|
|
1894
|
+
});
|
|
1895
|
+
group.addEventListener("keydown", (event) => {
|
|
1896
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
1897
|
+
event.preventDefault();
|
|
1898
|
+
choose();
|
|
1899
|
+
}
|
|
1900
|
+
});
|
|
1901
|
+
layer.append(group);
|
|
1902
|
+
}
|
|
1903
|
+
const frame = element("div", { class: "gwrap" }, svg("svg", {
|
|
1904
|
+
role: "img",
|
|
1905
|
+
"aria-label": `Graph of ${info.name}`
|
|
1906
|
+
}, svg("defs", {}, drawArrow("arrow")), layer));
|
|
1907
|
+
function select(index, focus) {
|
|
1908
|
+
shell.graphNode = index;
|
|
1909
|
+
const next = drawNodes(ctx, id, instance, info);
|
|
1910
|
+
frame.replaceWith(next);
|
|
1911
|
+
if (focus !== void 0) next.querySelector(`[data-node="${focus}"]`)?.focus();
|
|
1912
|
+
}
|
|
1913
|
+
function apply() {
|
|
1914
|
+
layer.setAttribute("transform", `translate(${shell.view.x},${shell.view.y}) scale(${shell.view.scale})`);
|
|
1915
|
+
}
|
|
1916
|
+
function fit() {
|
|
1917
|
+
const box = frame.getBoundingClientRect();
|
|
1918
|
+
if (box.width === 0) return;
|
|
1919
|
+
shell.view.fitted = id;
|
|
1920
|
+
const room = box.width - (shell.graphNode === void 0 ? 0 : 270);
|
|
1921
|
+
shell.view.scale = Math.min(1.1, Math.max(.4, Math.min(room / graphWidth, box.height / graphHeight)));
|
|
1922
|
+
shell.view.x = Math.max(0, (room - graphWidth * shell.view.scale) / 2);
|
|
1923
|
+
shell.view.y = Math.max(0, (box.height - graphHeight * shell.view.scale) / 2);
|
|
1924
|
+
apply();
|
|
1925
|
+
}
|
|
1926
|
+
function zoomAt(factor, px, py) {
|
|
1927
|
+
const next = Math.min(2, Math.max(.4, shell.view.scale * factor));
|
|
1928
|
+
shell.view.x = px - (px - shell.view.x) * next / shell.view.scale;
|
|
1929
|
+
shell.view.y = py - (py - shell.view.y) * next / shell.view.scale;
|
|
1930
|
+
shell.view.scale = next;
|
|
1931
|
+
apply();
|
|
1932
|
+
}
|
|
1933
|
+
frame.addEventListener("wheel", (event) => {
|
|
1934
|
+
event.preventDefault();
|
|
1935
|
+
const box = frame.getBoundingClientRect();
|
|
1936
|
+
zoomAt(Math.exp(-event.deltaY * .0015), event.clientX - box.left, event.clientY - box.top);
|
|
1937
|
+
}, { passive: false });
|
|
1938
|
+
frame.addEventListener("pointerdown", (event) => {
|
|
1939
|
+
if (event.target.closest(".node, .gtools, .graph-side")) return;
|
|
1940
|
+
const start = {
|
|
1941
|
+
x: event.clientX - shell.view.x,
|
|
1942
|
+
y: event.clientY - shell.view.y
|
|
1943
|
+
};
|
|
1944
|
+
let moved = false;
|
|
1945
|
+
frame.classList.add("dragging");
|
|
1946
|
+
function move(next) {
|
|
1947
|
+
moved = true;
|
|
1948
|
+
shell.view.x = next.clientX - start.x;
|
|
1949
|
+
shell.view.y = next.clientY - start.y;
|
|
1950
|
+
apply();
|
|
1951
|
+
}
|
|
1952
|
+
function up() {
|
|
1953
|
+
frame.classList.remove("dragging");
|
|
1954
|
+
window.removeEventListener("pointermove", move);
|
|
1955
|
+
window.removeEventListener("pointerup", up);
|
|
1956
|
+
if (!moved && shell.graphNode !== void 0) select(void 0);
|
|
1957
|
+
}
|
|
1958
|
+
window.addEventListener("pointermove", move);
|
|
1959
|
+
window.addEventListener("pointerup", up);
|
|
1960
|
+
});
|
|
1961
|
+
function zoomButton(name, title, factor) {
|
|
1962
|
+
const button = iconButton(name, title, {}, true);
|
|
1963
|
+
button.addEventListener("click", () => {
|
|
1964
|
+
const box = frame.getBoundingClientRect();
|
|
1965
|
+
zoomAt(factor, box.width / 2, box.height / 2);
|
|
1966
|
+
});
|
|
1967
|
+
return button;
|
|
1968
|
+
}
|
|
1969
|
+
const fitButton = iconButton("fit", "Fit the graph in view", {}, true);
|
|
1970
|
+
fitButton.addEventListener("click", fit);
|
|
1971
|
+
frame.append(element("div", { class: "gtools" }, zoomButton("minus", "Zoom out", 1 / 1.2), zoomButton("plus", "Zoom in", 1.2), fitButton));
|
|
1972
|
+
if (selected !== void 0) {
|
|
1973
|
+
const node = nodes[selected];
|
|
1974
|
+
const part = parts[selected];
|
|
1975
|
+
function list(title, indexes) {
|
|
1976
|
+
if (indexes.length === 0) return [];
|
|
1977
|
+
const links = [];
|
|
1978
|
+
for (const index of indexes) {
|
|
1979
|
+
const { label } = nodes[index];
|
|
1980
|
+
const at = parts[index].at;
|
|
1981
|
+
let shared = false;
|
|
1982
|
+
for (const [i, other] of nodes.entries()) if (i !== index && other.label === label) {
|
|
1983
|
+
shared = true;
|
|
1984
|
+
break;
|
|
1985
|
+
}
|
|
1986
|
+
const link = element("button", { class: "lk" }, element("i", { style: `background: ${pickNodeColor(nodes[index].kind, nodes[index].slot)}` }), shared && at ? `${label} ${at}` : label);
|
|
1987
|
+
const value = parts[index].value;
|
|
1988
|
+
if (value !== void 0) link.append(element("span", {}, clip(value)));
|
|
1989
|
+
link.addEventListener("click", () => {
|
|
1990
|
+
select(index, index);
|
|
1991
|
+
});
|
|
1992
|
+
links.push(link);
|
|
1993
|
+
}
|
|
1994
|
+
return [element("div", { class: "sec" }, title), ...links];
|
|
1995
|
+
}
|
|
1996
|
+
const reads = [];
|
|
1997
|
+
const readBy = [];
|
|
1998
|
+
for (const [from, to] of edges) {
|
|
1999
|
+
if (to === selected) reads.push(from);
|
|
2000
|
+
if (from === selected) readBy.push(to);
|
|
2001
|
+
}
|
|
2002
|
+
const close = element("button", {
|
|
2003
|
+
title: "Close",
|
|
2004
|
+
"aria-label": "Close"
|
|
2005
|
+
}, drawCross());
|
|
2006
|
+
close.addEventListener("click", () => {
|
|
2007
|
+
select(void 0, selected);
|
|
2008
|
+
});
|
|
2009
|
+
const side = element("aside", { class: "graph-side" }, element("h4", {}, element("i", { style: `background: ${pickNodeColor(node.kind, node.slot)}` }), part.name, close), element("div", { class: "kind" }, nameKind(node.kind), node.at ? place(info, node.at) : ""), ...part.value === void 0 ? [] : [element("div", { class: `gv ${classifyValue(part.value)}` }, part.value)], ...list("Reads", reads), ...list("Read by", readBy));
|
|
2010
|
+
frame.append(side);
|
|
2011
|
+
}
|
|
2012
|
+
if (shell.view.fitted === id) apply();
|
|
2013
|
+
else {
|
|
2014
|
+
shell.view = {
|
|
2015
|
+
x: 0,
|
|
2016
|
+
y: 0,
|
|
2017
|
+
scale: 1,
|
|
2018
|
+
fitted: ""
|
|
2019
|
+
};
|
|
2020
|
+
apply();
|
|
2021
|
+
requestAnimationFrame(fit);
|
|
2022
|
+
}
|
|
2023
|
+
if (hot.size > 0) {
|
|
2024
|
+
let last = 0;
|
|
2025
|
+
for (const { end } of hot.values()) last = Math.max(last, end);
|
|
2026
|
+
clearTimeout(shell.cooling);
|
|
2027
|
+
shell.cooling = setTimeout(() => state.changed?.(), last - now);
|
|
2028
|
+
}
|
|
2029
|
+
return frame;
|
|
2030
|
+
}
|
|
2031
|
+
//#endregion
|
|
2032
|
+
//#region src/runtime/devtools-panel/inspect.ts
|
|
2033
|
+
const INSPECT_STYLE = `
|
|
2034
|
+
.ins { --bg2: #161517; --line2: #36333a; --sel: #ee7a3e14; --ring: #ee7a3e47; --accent-text: #ffb48a; }
|
|
2035
|
+
.ins > .list { padding: 8px; gap: 1px; }
|
|
2036
|
+
.ins .filter { display: block; flex: none; margin: 0 0 6px; }
|
|
2037
|
+
.ins .filter input { width: 100%; box-sizing: border-box; height: 30px; padding: 0 10px; border-radius: 7px; background: var(--bg2); border: 0; box-shadow: inset 0 0 0 1px var(--line); outline: none; }
|
|
2038
|
+
.ins .filter input:focus-visible { box-shadow: inset 0 0 0 1px var(--ring); outline: none; }
|
|
2039
|
+
.ins .tree-row { box-sizing: border-box; flex: none; display: flex; align-items: center; justify-content: flex-start; gap: 7px; width: 100%; height: 28px; margin: 0; padding: 0 8px; border: 0; border-radius: 7px; text-align: left; white-space: nowrap; font-weight: 400; transition: background 0.12s; }
|
|
2040
|
+
.ins .tree-row:hover { background: var(--hover); }
|
|
2041
|
+
.ins .tree-row:focus-visible { outline: none; box-shadow: inset 0 0 0 1px var(--ring); }
|
|
2042
|
+
.ins .tree-row[aria-current="true"] { background: var(--sel); box-shadow: inset 0 0 0 1px var(--ring); }
|
|
2043
|
+
.ins .tree-row[aria-current="true"] .name { color: var(--accent-text); }
|
|
2044
|
+
.ins .tree-row .ind { flex: none; align-self: stretch; background: linear-gradient(90deg, transparent 5px, var(--line) 5px, var(--line) 6px, transparent 6px) 0 0 / 14px 100% repeat-x; }
|
|
2045
|
+
.ins .tree-row .tw { flex: none; width: 12px; height: 12px; display: grid; place-items: center; color: var(--faint); border-radius: 3px; }
|
|
2046
|
+
.ins .tree-row .tw svg { transition: transform 0.12s; }
|
|
2047
|
+
.ins .tree-row .tw.shut svg { transform: rotate(-90deg); }
|
|
2048
|
+
.ins .tree-row .tw:hover { color: var(--text); }
|
|
2049
|
+
.ins .tree-row .name, .ins .tree-row .blk { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
2050
|
+
.ins .tree-row .name { font-weight: 500; }
|
|
2051
|
+
.ins .tree-row.off { opacity: .45; }
|
|
2052
|
+
.ins .tree-row .blk { font: 11.5px var(--mono); color: var(--purple); }
|
|
2053
|
+
.ins .tree-row .meta { flex: none; margin-left: auto; font: 10.5px var(--mono); color: var(--faint); }
|
|
2054
|
+
.ins .heat { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--yellow); opacity: 0; }
|
|
2055
|
+
.ins .heat.on { animation: ins-heat 1.1s ease-out; }
|
|
2056
|
+
@keyframes ins-heat { 0% { opacity: 1; transform: scale(1.7); } 100% { opacity: 0; } }
|
|
2057
|
+
.ins > .detail.gmode { display: flex; flex-direction: column; padding-bottom: 0; }
|
|
2058
|
+
.ins .title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
|
|
2059
|
+
.ins .title { min-width: 0; }
|
|
2060
|
+
.ins .title h3 { margin: 0; min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; font-weight: 600; letter-spacing: -0.015em; text-transform: none; color: var(--text); }
|
|
2061
|
+
.ins .path { min-width: 0; max-width: 100%; display: inline-flex; align-items: center; gap: 4px; font: 11.5px var(--mono); color: var(--dim); }
|
|
2062
|
+
.ins .path .link { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: inherit; }
|
|
2063
|
+
.ins .path:hover, .ins .path .link:hover { color: var(--blue); }
|
|
2064
|
+
.ins .views { display: inline-flex; flex: none; gap: 2px; padding: 2px; margin-left: auto; border-radius: 8px; background: var(--bg2); box-shadow: inset 0 0 0 1px var(--line); }
|
|
2065
|
+
.ins .views button { height: 24px; padding: 0 10px; border: 0; border-radius: 6px; color: var(--dim); font-size: 11.5px; font-weight: 500; transition: background 0.12s, color 0.12s; }
|
|
2066
|
+
.ins .views button:hover { color: var(--text); }
|
|
2067
|
+
.ins .views button[aria-pressed="true"] { background: var(--hover); color: var(--text); box-shadow: inset 0 0 0 1px var(--line2); }
|
|
2068
|
+
.ins .views button:focus-visible { outline: none; box-shadow: inset 0 0 0 1px var(--ring); }
|
|
2069
|
+
.ins .tags { display: flex; gap: 6px; margin: 10px 0 0; flex-wrap: wrap; }
|
|
2070
|
+
.ins .tag { font: 11px/20px var(--mono); padding: 0 7px; border-radius: 6px; background: var(--hover); color: var(--dim); }
|
|
2071
|
+
.ins .tag.y { color: var(--yellow); background: #ffd16618; }
|
|
2072
|
+
.ins .sec { font-size: 11px; font-weight: 600; color: var(--faint); margin: 22px 0 8px; display: flex; align-items: baseline; gap: 8px; }
|
|
2073
|
+
.ins .sec .n { font: 10.5px var(--mono); font-weight: 400; }
|
|
2074
|
+
.ins .vals { display: grid; grid-template-columns: max-content max-content minmax(0, 1fr) max-content; column-gap: 16px; align-items: center; }
|
|
2075
|
+
.ins .slot { display: contents; }
|
|
2076
|
+
.ins .vals > *, .ins .slot > * { padding: 5px 0; border-top: 1px solid var(--line); min-width: 0; }
|
|
2077
|
+
.ins .vals > :first-child > *, .ins .vals > .rd:nth-child(2) { border-top: 0; }
|
|
2078
|
+
.ins .slot .k { font: 11.5px var(--mono); color: #ffc28f; }
|
|
2079
|
+
.ins .slot .ty { font: 11px var(--mono); color: var(--faint); }
|
|
2080
|
+
.ins .vals > .rd { max-width: 34ch; font: 11px var(--mono); color: var(--faint); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
2081
|
+
.ins .slot .value { color: var(--text); display: block; width: 100%; box-sizing: border-box; margin-left: -6px; padding: 3px 6px; border: 0; border-radius: 5px; text-align: left; font: 11.5px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: text; transition: background 0.12s, box-shadow 0.12s; }
|
|
2082
|
+
.ins .slot .value:hover { background: var(--bg2); }
|
|
2083
|
+
.ins .slot .value:focus-visible { background: var(--bg2); outline: none; box-shadow: inset 0 0 0 1px var(--ring); }
|
|
2084
|
+
.ins .slot .value.fixed { cursor: default; }
|
|
2085
|
+
.ins .slot .value.fixed:hover { background: none; }
|
|
2086
|
+
.ins .slot .value.fixed { color: var(--dim); }
|
|
2087
|
+
.ins .slot .value.str { color: var(--green); }
|
|
2088
|
+
.ins .slot .value.num { color: var(--blue); }
|
|
2089
|
+
.ins .slot .value.bool { color: var(--purple); }
|
|
2090
|
+
.ins .slot input.value { background: transparent; outline: none; }
|
|
2091
|
+
.ins .slot input.value:focus { background: var(--bg2); box-shadow: inset 0 0 0 1px var(--ring); }
|
|
2092
|
+
.ins .graph { flex: 1; min-height: 120px; margin: 14px -14px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; position: relative; overflow: hidden; }
|
|
2093
|
+
.ins .graph > * { flex: 1; min-height: 0; }
|
|
2094
|
+
.ins .graph > .gwrap { height: auto; margin-top: 0; border-top: 0; }
|
|
2095
|
+
`;
|
|
2096
|
+
/** A value that can be edited as text: what JSON can hold. */
|
|
2097
|
+
function editable(value) {
|
|
2098
|
+
if (value === null || [
|
|
2099
|
+
"string",
|
|
2100
|
+
"number",
|
|
2101
|
+
"boolean"
|
|
2102
|
+
].includes(typeof value)) return true;
|
|
2103
|
+
if (typeof value !== "object" || value instanceof Element) return false;
|
|
2104
|
+
try {
|
|
2105
|
+
JSON.stringify(value);
|
|
2106
|
+
return true;
|
|
2107
|
+
} catch {
|
|
2108
|
+
return false;
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
/** Reads what a person typed: JSON, or else the text as a string. */
|
|
2112
|
+
function parseValue(text) {
|
|
2113
|
+
try {
|
|
2114
|
+
return JSON.parse(text);
|
|
2115
|
+
} catch {
|
|
2116
|
+
return text;
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
function findWork(ctx) {
|
|
2120
|
+
const { work } = ctx.shell;
|
|
2121
|
+
let mine = work.inspect;
|
|
2122
|
+
if (!mine) {
|
|
2123
|
+
mine = {
|
|
2124
|
+
mode: "values",
|
|
2125
|
+
closed: /* @__PURE__ */ new Set(),
|
|
2126
|
+
focus: void 0,
|
|
2127
|
+
seenScope: void 0,
|
|
2128
|
+
seenModule: void 0
|
|
2129
|
+
};
|
|
2130
|
+
work.inspect = mine;
|
|
2131
|
+
}
|
|
2132
|
+
return mine;
|
|
2133
|
+
}
|
|
2134
|
+
/** A slot as a row of the values: name, type, value and what reads it. The reads sit outside the slot. */
|
|
2135
|
+
function drawSlot(ctx, scope, slot, name, readers) {
|
|
2136
|
+
const { state } = ctx;
|
|
2137
|
+
const work = findWork(ctx);
|
|
2138
|
+
const value = scope.s[slot];
|
|
2139
|
+
const cell = element("div", { class: "v" });
|
|
2140
|
+
const line = element("div", { class: "slot" }, element("div", { class: "k" }, name), element("div", { class: "ty" }, readType(value)), cell);
|
|
2141
|
+
const reads = element("div", {
|
|
2142
|
+
class: "rd",
|
|
2143
|
+
title: readers.join(", ")
|
|
2144
|
+
}, readers.join(", "));
|
|
2145
|
+
const canEdit = editable(value) && state.set !== void 0;
|
|
2146
|
+
const kinds = {
|
|
2147
|
+
string: "str",
|
|
2148
|
+
number: "num",
|
|
2149
|
+
boolean: "bool"
|
|
2150
|
+
};
|
|
2151
|
+
const classes = ["value"];
|
|
2152
|
+
if (typeof value in kinds) classes.push(kinds[typeof value]);
|
|
2153
|
+
if (!canEdit) {
|
|
2154
|
+
cell.append(element("span", { class: `${classes.join(" ")} fixed` }, preview(value)));
|
|
2155
|
+
return [line, reads];
|
|
2156
|
+
}
|
|
2157
|
+
const input = element("input", {
|
|
2158
|
+
class: classes.join(" "),
|
|
2159
|
+
"aria-label": `Value of ${name}`,
|
|
2160
|
+
title: "Enter JSON, or text for a string.",
|
|
2161
|
+
spellcheck: "false",
|
|
2162
|
+
"data-focus": `value-${slot}`
|
|
2163
|
+
});
|
|
2164
|
+
input.value = JSON.stringify(value) ?? "";
|
|
2165
|
+
input.defaultValue = input.value;
|
|
2166
|
+
function commit() {
|
|
2167
|
+
if (input.value === input.defaultValue) return;
|
|
2168
|
+
input.defaultValue = input.value;
|
|
2169
|
+
state.set?.(scope, slot, parseValue(input.value));
|
|
2170
|
+
ctx.draw();
|
|
2171
|
+
}
|
|
2172
|
+
input.addEventListener("change", commit);
|
|
2173
|
+
input.addEventListener("keydown", (event) => {
|
|
2174
|
+
if (event.key === "Enter") {
|
|
2175
|
+
work.focus = `value-${slot}`;
|
|
2176
|
+
commit();
|
|
2177
|
+
work.focus = void 0;
|
|
2178
|
+
} else if (event.key === "Escape") input.value = input.defaultValue;
|
|
2179
|
+
});
|
|
2180
|
+
cell.append(input);
|
|
2181
|
+
return [line, reads];
|
|
2182
|
+
}
|
|
2183
|
+
/**
|
|
2184
|
+
* The scope to show. Whichever of `shell.selectedScope` (Pick, the call detail) and `shell.selected`
|
|
2185
|
+
* (Page, a component chosen by its module) changed since the last draw wins, the scope first.
|
|
2186
|
+
*/
|
|
2187
|
+
function findCurrent(ctx, list) {
|
|
2188
|
+
const { state, shell } = ctx;
|
|
2189
|
+
const work = findWork(ctx);
|
|
2190
|
+
let current = shell.selectedScope === void 0 ? void 0 : state.scopes?.get(shell.selectedScope);
|
|
2191
|
+
if (shell.selectedScope === work.seenScope && shell.selected !== work.seenModule) {
|
|
2192
|
+
for (const scope of list) if (scope.m === shell.selected) {
|
|
2193
|
+
current = scope;
|
|
2194
|
+
break;
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
current ??= list[0];
|
|
2198
|
+
shell.selectedScope = current.id;
|
|
2199
|
+
work.seenScope = current.id;
|
|
2200
|
+
work.seenModule = findRootScope(current).m;
|
|
2201
|
+
shell.selected = work.seenModule;
|
|
2202
|
+
return current;
|
|
2203
|
+
}
|
|
2204
|
+
/** The scopes of a component instance, itself included, without the components inside it. */
|
|
2205
|
+
function countOwn(scope) {
|
|
2206
|
+
let count = 1;
|
|
2207
|
+
for (const child of scope.children ?? []) if (child.m === void 0) count += countOwn(child);
|
|
2208
|
+
return count;
|
|
2209
|
+
}
|
|
2210
|
+
function hasOwnChildren(group) {
|
|
2211
|
+
for (const scope of group) for (const child of scope.children ?? []) if (child.m === void 0) return true;
|
|
2212
|
+
return false;
|
|
2213
|
+
}
|
|
2214
|
+
/** The name of a block from the label of its scope: `body of #for (95:3)` is `#for`. */
|
|
2215
|
+
function readBlock(label) {
|
|
2216
|
+
const body = /^body of (#\w+)/.exec(label ?? "");
|
|
2217
|
+
return body ? body[1] : label ?? "scope";
|
|
2218
|
+
}
|
|
2219
|
+
/** The name of the control that has the focus inside the body, and the caret of a text field. */
|
|
2220
|
+
function findFocus(ctx, into) {
|
|
2221
|
+
const active = ctx.root.activeElement;
|
|
2222
|
+
const key = active && into.contains(active) ? active.dataset.focus : void 0;
|
|
2223
|
+
if (key === void 0) return;
|
|
2224
|
+
const field = active;
|
|
2225
|
+
return {
|
|
2226
|
+
key,
|
|
2227
|
+
from: field.selectionStart ?? null,
|
|
2228
|
+
to: field.selectionEnd ?? null
|
|
2229
|
+
};
|
|
2230
|
+
}
|
|
2231
|
+
async function drawInspect(ctx, into) {
|
|
2232
|
+
const { state, shell } = ctx;
|
|
2233
|
+
const work = findWork(ctx);
|
|
2234
|
+
const list = roots(state);
|
|
2235
|
+
const listed = [];
|
|
2236
|
+
for (const scope of list) listed.push(scope.m);
|
|
2237
|
+
const infos = await loadComponents(state, listed);
|
|
2238
|
+
if (!ctx.root.querySelector("style[data-inspect]")) ctx.root.append(element("style", { "data-inspect": "" }, INSPECT_STYLE));
|
|
2239
|
+
if (list.length === 0) {
|
|
2240
|
+
into.replaceChildren(element("div", { class: "empty" }, "No scopes yet. The first event loads them."));
|
|
2241
|
+
return;
|
|
2242
|
+
}
|
|
2243
|
+
const current = findCurrent(ctx, list);
|
|
2244
|
+
const component = findRootScope(current);
|
|
2245
|
+
const trail = /* @__PURE__ */ new Set();
|
|
2246
|
+
for (let scope = current.p; scope; scope = scope.p) trail.add(scope.id);
|
|
2247
|
+
const search = element("input", {
|
|
2248
|
+
type: "search",
|
|
2249
|
+
placeholder: "Filter components and values",
|
|
2250
|
+
"aria-label": "Filter components",
|
|
2251
|
+
"data-focus": "filter"
|
|
2252
|
+
});
|
|
2253
|
+
search.value = shell.filter;
|
|
2254
|
+
search.addEventListener("input", () => {
|
|
2255
|
+
shell.filter = search.value;
|
|
2256
|
+
drawInspect(ctx, into);
|
|
2257
|
+
});
|
|
2258
|
+
const { box, first: tree, second: detail } = ctx.split({
|
|
2259
|
+
key: "scopes",
|
|
2260
|
+
min: [200, 300],
|
|
2261
|
+
start: 280
|
|
2262
|
+
});
|
|
2263
|
+
box.classList.add("ins");
|
|
2264
|
+
tree.append(element("label", { class: "filter" }, search));
|
|
2265
|
+
const rows = [];
|
|
2266
|
+
function select(group, focus) {
|
|
2267
|
+
const at = group.indexOf(current);
|
|
2268
|
+
const scope = group[at === -1 ? 0 : (at + 1) % group.length];
|
|
2269
|
+
shell.selectedScope = scope.id;
|
|
2270
|
+
shell.selected = findRootScope(scope).m;
|
|
2271
|
+
if (focus) work.focus = `row-${group[0].id}`;
|
|
2272
|
+
ctx.draw();
|
|
2273
|
+
}
|
|
2274
|
+
function visit(group, info, depth, layout) {
|
|
2275
|
+
const first = group[0];
|
|
2276
|
+
const isComponent = first.m !== void 0;
|
|
2277
|
+
const nested = hasOwnChildren(group);
|
|
2278
|
+
let onTrail = false;
|
|
2279
|
+
for (const scope of group) onTrail ||= trail.has(scope.id);
|
|
2280
|
+
const shut = work.closed.has(first.id) && !onTrail;
|
|
2281
|
+
const chevron = element("span", { class: shut ? "tw shut" : "tw" });
|
|
2282
|
+
if (nested) {
|
|
2283
|
+
chevron.append(icon("close", 12));
|
|
2284
|
+
chevron.addEventListener("click", (event) => {
|
|
2285
|
+
event.stopPropagation();
|
|
2286
|
+
if (work.closed.has(first.id)) work.closed.delete(first.id);
|
|
2287
|
+
else {
|
|
2288
|
+
work.closed.add(first.id);
|
|
2289
|
+
shell.selectedScope = first.id;
|
|
2290
|
+
shell.selected = findRootScope(first).m;
|
|
2291
|
+
}
|
|
2292
|
+
work.focus = `row-${first.id}`;
|
|
2293
|
+
ctx.draw();
|
|
2294
|
+
});
|
|
2295
|
+
}
|
|
2296
|
+
let label;
|
|
2297
|
+
let meta;
|
|
2298
|
+
if (isComponent) {
|
|
2299
|
+
label = info?.name ?? first.m;
|
|
2300
|
+
meta = `${countOwn(first)} ${countOwn(first) === 1 ? "scope" : "scopes"}`;
|
|
2301
|
+
} else {
|
|
2302
|
+
label = readBlock(layout?.label);
|
|
2303
|
+
meta = label === "#for" ? `${group.length} ${group.length === 1 ? "item" : "items"}` : `#${first.id}`;
|
|
2304
|
+
}
|
|
2305
|
+
const classes = ["tree-row"];
|
|
2306
|
+
if (isComponent) classes.push("component");
|
|
2307
|
+
else if (first.h) classes.push("off");
|
|
2308
|
+
const button = element("button", {
|
|
2309
|
+
class: classes.join(" "),
|
|
2310
|
+
"aria-current": String(group.includes(current)),
|
|
2311
|
+
"data-focus": `row-${first.id}`,
|
|
2312
|
+
title: group.length > 1 ? "Click again for the next scope of this block." : label
|
|
2313
|
+
}, element("span", {
|
|
2314
|
+
class: "ind",
|
|
2315
|
+
style: `width: ${depth * 14}px`
|
|
2316
|
+
}), chevron, element("span", { class: isComponent ? "name" : "blk" }, label), element("span", { class: group.some((scope) => state.written.has(scope.id)) ? "heat on" : "heat" }), element("span", { class: "meta" }, meta));
|
|
2317
|
+
button.addEventListener("click", () => select(group));
|
|
2318
|
+
button.addEventListener("mouseenter", () => ctx.outline(first.id));
|
|
2319
|
+
button.addEventListener("mouseleave", () => ctx.outline());
|
|
2320
|
+
rows.push([button, group]);
|
|
2321
|
+
tree.append(button);
|
|
2322
|
+
if (shut) return;
|
|
2323
|
+
const blocks = /* @__PURE__ */ new Map();
|
|
2324
|
+
for (const scope of group) for (const child of scope.children ?? []) if (child.m === void 0) {
|
|
2325
|
+
const same = blocks.get(child.k);
|
|
2326
|
+
if (same) same.push(child);
|
|
2327
|
+
else blocks.set(child.k, [child]);
|
|
2328
|
+
}
|
|
2329
|
+
for (const [k, inside] of blocks) visit(inside, info, depth + 1, info?.scopes[k]);
|
|
2330
|
+
}
|
|
2331
|
+
const needle = shell.filter.trim().toLowerCase();
|
|
2332
|
+
for (const [index, scope] of list.entries()) {
|
|
2333
|
+
const info = infos[index];
|
|
2334
|
+
if (needle && !`${info?.name ?? scope.m} ${info?.file ?? ""}`.toLowerCase().includes(needle)) {
|
|
2335
|
+
let matched = false;
|
|
2336
|
+
for (const value of scope.s) if (preview(value).toLowerCase().includes(needle)) {
|
|
2337
|
+
matched = true;
|
|
2338
|
+
break;
|
|
2339
|
+
}
|
|
2340
|
+
if (!matched) continue;
|
|
2341
|
+
}
|
|
2342
|
+
visit([scope], info, 0, void 0);
|
|
2343
|
+
}
|
|
2344
|
+
tree.addEventListener("keydown", (event) => {
|
|
2345
|
+
if (event.target instanceof HTMLInputElement) return;
|
|
2346
|
+
let at = -1;
|
|
2347
|
+
for (const [index, [button]] of rows.entries()) if (button === event.target) {
|
|
2348
|
+
at = index;
|
|
2349
|
+
break;
|
|
2350
|
+
}
|
|
2351
|
+
if (at < 0) return;
|
|
2352
|
+
const focused = rows[at][1];
|
|
2353
|
+
const firstId = focused[0].id;
|
|
2354
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
2355
|
+
const next = rows[at + (event.key === "ArrowDown" ? 1 : -1)];
|
|
2356
|
+
if (next) {
|
|
2357
|
+
event.preventDefault();
|
|
2358
|
+
select(next[1], true);
|
|
2359
|
+
}
|
|
2360
|
+
} else if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
|
|
2361
|
+
const shutNow = event.key === "ArrowLeft";
|
|
2362
|
+
if (hasOwnChildren(focused) && work.closed.has(firstId) !== shutNow) {
|
|
2363
|
+
event.preventDefault();
|
|
2364
|
+
if (shutNow) work.closed.add(firstId);
|
|
2365
|
+
else work.closed.delete(firstId);
|
|
2366
|
+
work.focus = `row-${firstId}`;
|
|
2367
|
+
ctx.draw();
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
});
|
|
2371
|
+
const info = known.get(component.m ?? "");
|
|
2372
|
+
const plan = info?.scopes[current.k];
|
|
2373
|
+
const graphing = work.mode === "graph";
|
|
2374
|
+
if (graphing) detail.classList.add("gmode");
|
|
2375
|
+
const views = element("span", {
|
|
2376
|
+
class: "views",
|
|
2377
|
+
role: "group",
|
|
2378
|
+
"aria-label": "View"
|
|
2379
|
+
});
|
|
2380
|
+
for (const mode of ["values", "graph"]) {
|
|
2381
|
+
const button = element("button", {
|
|
2382
|
+
"aria-pressed": String(work.mode === mode),
|
|
2383
|
+
"data-focus": `mode-${mode}`
|
|
2384
|
+
}, mode === "values" ? "Values" : "Graph");
|
|
2385
|
+
button.addEventListener("click", () => {
|
|
2386
|
+
work.mode = mode;
|
|
2387
|
+
work.focus = `mode-${mode}`;
|
|
2388
|
+
if (shell.tab === "graph" || shell.tab === "elements") shell.tab = "scopes";
|
|
2389
|
+
ctx.draw();
|
|
2390
|
+
});
|
|
2391
|
+
views.append(button);
|
|
2392
|
+
}
|
|
2393
|
+
const tags = element("div", { class: "tags" }, element("span", { class: "tag" }, `scope ${current.id}`), current === component ? "" : element("span", { class: "tag" }, readBlock(plan?.label)), element("span", { class: "tag" }, `${countOwn(component)} ${countOwn(component) === 1 ? "scope" : "scopes"}`), current.h ? element("span", { class: "tag y" }, "hidden") : "");
|
|
2394
|
+
detail.append(element("div", { class: "title" }, element("h3", { title: info?.name ?? component.m ?? "" }, info?.name ?? component.m ?? ""), element("span", { class: "path" }, source(info)), drawCopyTool(() => writeComponent(component, info, state.meta)), views), tags);
|
|
2395
|
+
if (graphing) detail.append(element("div", { class: "graph" }, ctx.drawGraph(component, info)));
|
|
2396
|
+
else if (current.s.length === 0) detail.append(element("div", { class: "sec" }, "Values", element("span", { class: "n" }, "0")), element("div", { class: "empty" }, "This scope holds no values."));
|
|
2397
|
+
else {
|
|
2398
|
+
const grid = element("div", { class: "vals" });
|
|
2399
|
+
for (let slot = 0; slot < current.s.length; slot++) grid.append(...drawSlot(ctx, current, slot, plan?.slots[slot] ?? `slot ${slot}`, plan?.readers?.[slot] ?? []));
|
|
2400
|
+
detail.append(element("div", { class: "sec" }, "Values", element("span", { class: "n" }, String(current.s.length))), grid);
|
|
2401
|
+
}
|
|
2402
|
+
const typing = ctx.root.activeElement;
|
|
2403
|
+
if (typing instanceof HTMLInputElement && into.contains(typing) && typing.dataset.focus?.startsWith("value-") && typing.value !== typing.defaultValue) return;
|
|
2404
|
+
const focused = findFocus(ctx, into);
|
|
2405
|
+
into.replaceChildren(box);
|
|
2406
|
+
const wanted = work.focus ?? focused?.key;
|
|
2407
|
+
work.focus = void 0;
|
|
2408
|
+
if (wanted !== void 0) {
|
|
2409
|
+
const target = into.querySelector(`[data-focus="${wanted}"]`);
|
|
2410
|
+
target?.focus({ preventScroll: true });
|
|
2411
|
+
if (target && focused?.key === wanted && focused.from !== null && "setSelectionRange" in target) target.setSelectionRange(focused.from, focused.to);
|
|
2412
|
+
}
|
|
2413
|
+
into.querySelector("[aria-current=\"true\"]")?.scrollIntoView({ block: "nearest" });
|
|
2414
|
+
}
|
|
2415
|
+
const inspect = {
|
|
2416
|
+
id: "inspect",
|
|
2417
|
+
label: "Inspect",
|
|
2418
|
+
icon: "scopes",
|
|
2419
|
+
tabs: {
|
|
2420
|
+
scopes: drawInspect,
|
|
2421
|
+
elements: drawInspect,
|
|
2422
|
+
graph: (ctx, into) => {
|
|
2423
|
+
findWork(ctx).mode = "graph";
|
|
2424
|
+
return drawInspect(ctx, into);
|
|
2425
|
+
}
|
|
2426
|
+
},
|
|
2427
|
+
draw: (ctx, into) => drawTabOf(inspect.tabs, ctx, into)
|
|
2428
|
+
};
|
|
2429
|
+
//#endregion
|
|
2430
|
+
//#region src/runtime/devtools-panel/issues.ts
|
|
2431
|
+
const ISSUES_STYLE = `
|
|
2432
|
+
.issues { --sel: #ee7a3e14; --ring: #ee7a3e47; }
|
|
2433
|
+
.issues > .list { padding: 8px; gap: 2px; }
|
|
2434
|
+
.issues .iss { display: block; width: 100%; text-align: left; padding: 9px 10px; border-radius: 8px; transition: background .12s; }
|
|
2435
|
+
.issues .iss:hover { background: var(--hover); }
|
|
2436
|
+
.issues .iss[aria-current="true"] { background: var(--sel); box-shadow: inset 0 0 0 1px var(--ring); }
|
|
2437
|
+
.issues .iss .src { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--faint); }
|
|
2438
|
+
.issues .iss .src i { width: 7px; height: 7px; border-radius: 50%; flex: none; }
|
|
2439
|
+
.issues .iss .msg { display: block; margin-top: 3px; font-weight: 500; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
2440
|
+
.issues .iss .at { display: block; margin-top: 2px; font: 11px var(--mono); color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
2441
|
+
.issues > .detail { padding: 14px; overflow: auto; }
|
|
2442
|
+
.issues .title { margin: 0 0 4px; font: 600 14px/1.4 var(--mono); color: var(--text); white-space: pre-wrap; }
|
|
2443
|
+
.issues .code { margin: 14px 0 0; border: 0; border-radius: 10px; background: #0d0c0e; box-shadow: inset 0 0 0 1px var(--line); }
|
|
2444
|
+
.issues .sec { margin: 16px 0 6px; color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
|
|
2445
|
+
.issues .frame[aria-current="true"] { background: var(--sel); box-shadow: inset 0 0 0 1px var(--ring); }
|
|
2446
|
+
.issues .frame[aria-current="true"] .fn { color: var(--text); }
|
|
2447
|
+
.issues .acts { margin-top: 20px; display: flex; gap: 8px; flex-wrap: wrap; }
|
|
2448
|
+
.issues .btn { height: 28px; padding: 0 12px; border-radius: 8px; background: var(--raised); box-shadow: inset 0 0 0 1px var(--line); font-weight: 500; }
|
|
2449
|
+
.issues .btn:hover { background: var(--hover); }
|
|
2450
|
+
.issues .btn.pri { background: var(--text); color: #121113; box-shadow: none; }
|
|
2451
|
+
.issues .btn.pri:hover { background: #fff; }
|
|
2452
|
+
.issues .hint { margin-top: 12px; padding: 10px 12px; border-radius: 8px; background: #161517; color: var(--dim); }
|
|
2453
|
+
.issues .hint b { color: var(--text); font-weight: 500; }
|
|
2454
|
+
.issues .hint a { color: var(--accent); margin-left: 6px; }
|
|
2455
|
+
.issues .iss .src .mono { font-family: var(--mono); }
|
|
2456
|
+
`;
|
|
2457
|
+
function openInEditor(place) {
|
|
2458
|
+
fetch(`/__open-in-editor?file=${encodeURIComponent(`${place.file}:${place.line}:${place.column}`)}`);
|
|
2459
|
+
}
|
|
2460
|
+
/** A button that opens a place of a file in the editor. */
|
|
2461
|
+
function open(place) {
|
|
2462
|
+
const button = element("button", {
|
|
2463
|
+
class: "link",
|
|
2464
|
+
title: "Open in the editor"
|
|
2465
|
+
}, `${place.file.replace(/^.*\/(src|test|routes)\//, "$1/")}:${place.line}:${place.column}`, icon("open", 12));
|
|
2466
|
+
button.addEventListener("click", () => openInEditor(place));
|
|
2467
|
+
return button;
|
|
2468
|
+
}
|
|
2469
|
+
let catalog;
|
|
2470
|
+
/** The code of an issue, such as BRM012, from its message or from the catalog. */
|
|
2471
|
+
function readCode(entry, found) {
|
|
2472
|
+
return /\[(BRM\d+)\]$/.exec(entry.message)?.[1] ?? found?.findError(entry.message)?.code;
|
|
2473
|
+
}
|
|
2474
|
+
/** The key of an issue that stays the same when a newer one arrives. */
|
|
2475
|
+
function makeIssueKey(entry, entries) {
|
|
2476
|
+
let same = 0;
|
|
2477
|
+
for (const other of entries) {
|
|
2478
|
+
if (other === entry) break;
|
|
2479
|
+
if (other.time === entry.time) same++;
|
|
2480
|
+
}
|
|
2481
|
+
return `issue:${entry.time}:${same}`;
|
|
2482
|
+
}
|
|
2483
|
+
/** The label, dot colour and kind of an issue, as the prototype names them. */
|
|
2484
|
+
function describe(source) {
|
|
2485
|
+
if (source === "browser") return {
|
|
2486
|
+
label: "Browser error",
|
|
2487
|
+
color: "var(--red)"
|
|
2488
|
+
};
|
|
2489
|
+
if (source === "compile") return {
|
|
2490
|
+
label: "Compiler check",
|
|
2491
|
+
color: "var(--yellow)"
|
|
2492
|
+
};
|
|
2493
|
+
return {
|
|
2494
|
+
label: "Server error",
|
|
2495
|
+
color: "var(--red)"
|
|
2496
|
+
};
|
|
2497
|
+
}
|
|
2498
|
+
/** Where an issue happened, short enough for a row. */
|
|
2499
|
+
function locate(entry) {
|
|
2500
|
+
if (entry.loc) return `${entry.loc.file.replace(/^.*\/(src|test|routes)\//, "$1/")}:${entry.loc.line}:${entry.loc.column}`;
|
|
2501
|
+
return seconds(entry.time);
|
|
2502
|
+
}
|
|
2503
|
+
/** Keeps the keyboard focus on the same row after the workspace draws again. */
|
|
2504
|
+
function focusAgain(into, key) {
|
|
2505
|
+
if (key === void 0) return;
|
|
2506
|
+
for (const item of into.querySelectorAll("[data-key]")) if (item.dataset.key === key) {
|
|
2507
|
+
item.focus();
|
|
2508
|
+
return;
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
async function drawErrors(ctx, into) {
|
|
2512
|
+
const { state, shell } = ctx;
|
|
2513
|
+
if (!ctx.root.querySelector("style[data-issues]")) ctx.root.append(element("style", { "data-issues": "" }, ISSUES_STYLE));
|
|
2514
|
+
const active = ctx.root.activeElement;
|
|
2515
|
+
const focused = active instanceof HTMLElement && into.contains(active) ? active : void 0;
|
|
2516
|
+
if (state.errors.length === 0) {
|
|
2517
|
+
into.replaceChildren(element("h2", {}, "Issues"), element("p", { class: "sub" }, "No issues. 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."));
|
|
2518
|
+
return;
|
|
2519
|
+
}
|
|
2520
|
+
if (!shell.selectedError || !state.errors.includes(shell.selectedError)) {
|
|
2521
|
+
shell.selectedError = state.errors.at(-1);
|
|
2522
|
+
shell.selectedFrame = -1;
|
|
2523
|
+
}
|
|
2524
|
+
const error = shell.selectedError;
|
|
2525
|
+
const { box, first: list, second: detail } = ctx.split({
|
|
2526
|
+
key: "errors",
|
|
2527
|
+
min: [200, 300],
|
|
2528
|
+
start: 280
|
|
2529
|
+
});
|
|
2530
|
+
box.classList.add("issues");
|
|
2531
|
+
let found;
|
|
2532
|
+
try {
|
|
2533
|
+
found = await (catalog ??= import("./error-catalog-VxLbz-6p.js"));
|
|
2534
|
+
} catch {
|
|
2535
|
+
catalog = void 0;
|
|
2536
|
+
}
|
|
2537
|
+
const entries = state.errors.toReversed();
|
|
2538
|
+
for (const entry of entries) {
|
|
2539
|
+
const { label, color } = describe(entry.source);
|
|
2540
|
+
const code = readCode(entry, found);
|
|
2541
|
+
const button = element("button", {
|
|
2542
|
+
class: "iss",
|
|
2543
|
+
"data-key": makeIssueKey(entry, entries),
|
|
2544
|
+
"aria-current": String(entry === error)
|
|
2545
|
+
}, element("span", { class: "src" }, element("i", { style: `background: ${color}` }), label, code ? " · " : "", code ? element("span", { class: "mono" }, code) : ""), element("span", { class: "msg" }, entry.message.split("\n")[0]), element("span", { class: "at" }, locate(entry)));
|
|
2546
|
+
button.addEventListener("click", () => {
|
|
2547
|
+
shell.selectedError = entry;
|
|
2548
|
+
shell.selectedFrame = -1;
|
|
2549
|
+
ctx.draw();
|
|
2550
|
+
});
|
|
2551
|
+
list.append(button);
|
|
2552
|
+
}
|
|
2553
|
+
list.addEventListener("keydown", (event) => {
|
|
2554
|
+
if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return;
|
|
2555
|
+
const at = entries.indexOf(shell.selectedError);
|
|
2556
|
+
event.preventDefault();
|
|
2557
|
+
if (at === -1) return;
|
|
2558
|
+
const next = entries[at + (event.key === "ArrowDown" ? 1 : -1)];
|
|
2559
|
+
if (next) {
|
|
2560
|
+
shell.selectedError = next;
|
|
2561
|
+
shell.selectedFrame = -1;
|
|
2562
|
+
shell.work.issues = { focus: makeIssueKey(next, entries) };
|
|
2563
|
+
ctx.draw();
|
|
2564
|
+
}
|
|
2565
|
+
});
|
|
2566
|
+
const frames = await mapFrames(parseFrames(error.stack), frameUrls(error.stack));
|
|
2567
|
+
if (shell.selectedFrame === -1) {
|
|
2568
|
+
shell.selectedFrame = -2;
|
|
2569
|
+
if (!error.loc) {
|
|
2570
|
+
shell.selectedFrame = -1;
|
|
2571
|
+
for (const [index, item] of frames.entries()) if (!item.library && !item.compiled) {
|
|
2572
|
+
shell.selectedFrame = index;
|
|
2573
|
+
break;
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
const frame = shell.selectedFrame >= 0 ? frames[shell.selectedFrame] : void 0;
|
|
2578
|
+
const place = shell.selectedFrame === -2 ? error.loc : frame;
|
|
2579
|
+
const editable = place && !("url" in place && place.url) ? place : void 0;
|
|
2580
|
+
detail.append(element("h3", { class: "title" }, error.message));
|
|
2581
|
+
if (editable) detail.append(open(editable));
|
|
2582
|
+
if (place) detail.append(await codeView(place, error.frame));
|
|
2583
|
+
else if (error.frame) detail.append(element("div", { class: "code" }, element("pre", { class: "plain" }, error.frame)));
|
|
2584
|
+
if (frames.length > 0) {
|
|
2585
|
+
const stack = element("div", { class: "frames" });
|
|
2586
|
+
for (const [index, item] of frames.entries()) {
|
|
2587
|
+
const button = element("button", {
|
|
2588
|
+
class: `frame${item.library ? " library" : ""}`,
|
|
2589
|
+
"data-key": `frame:${index}`,
|
|
2590
|
+
"aria-current": String(index === shell.selectedFrame),
|
|
2591
|
+
title: item.compiled ? "The lines of code that the browser ran" : "Show this code"
|
|
2592
|
+
}, element("span", { class: "fn" }, item.fn), element("span", { class: "where" }, `${item.file}:${item.line}:${item.column}`));
|
|
2593
|
+
button.addEventListener("click", () => {
|
|
2594
|
+
shell.selectedFrame = index;
|
|
2595
|
+
ctx.draw();
|
|
2596
|
+
});
|
|
2597
|
+
stack.append(button);
|
|
2598
|
+
}
|
|
2599
|
+
detail.append(element("div", { class: "sec" }, "Stack"), stack);
|
|
2600
|
+
}
|
|
2601
|
+
const hint = found?.findError(error.message);
|
|
2602
|
+
if (hint) {
|
|
2603
|
+
const note = element("div", { class: "hint" }, element("b", {}, hint.cause));
|
|
2604
|
+
if (hint.link) note.append(element("a", {
|
|
2605
|
+
href: hint.link,
|
|
2606
|
+
target: "_blank",
|
|
2607
|
+
rel: "noopener"
|
|
2608
|
+
}, "Docs"));
|
|
2609
|
+
detail.append(note);
|
|
2610
|
+
}
|
|
2611
|
+
const actions = element("div", { class: "acts" });
|
|
2612
|
+
if (editable) {
|
|
2613
|
+
const edit = element("button", { class: "btn pri" }, "Open in editor");
|
|
2614
|
+
edit.addEventListener("click", () => openInEditor(editable));
|
|
2615
|
+
actions.append(edit);
|
|
2616
|
+
}
|
|
2617
|
+
const copy = element("button", {
|
|
2618
|
+
class: "btn",
|
|
2619
|
+
"data-key": "copy"
|
|
2620
|
+
}, "Copy for an agent");
|
|
2621
|
+
copyText(copy, async () => {
|
|
2622
|
+
let around;
|
|
2623
|
+
if (place) try {
|
|
2624
|
+
const url = "url" in place && typeof place.url === "string" ? place.url : void 0;
|
|
2625
|
+
const text = await (url ? fetchCompiled(url) : fetchSource(place.file));
|
|
2626
|
+
around = text === void 0 ? void 0 : {
|
|
2627
|
+
file: place.file,
|
|
2628
|
+
line: place.line,
|
|
2629
|
+
text
|
|
2630
|
+
};
|
|
2631
|
+
} catch {
|
|
2632
|
+
around = void 0;
|
|
2633
|
+
}
|
|
2634
|
+
return writeIssue(error, describe(error.source).label, state.meta, around);
|
|
2635
|
+
});
|
|
2636
|
+
actions.append(copy);
|
|
2637
|
+
if (error.source === "browser") {
|
|
2638
|
+
const show = element("button", { class: "btn" }, "Show in Activity");
|
|
2639
|
+
show.addEventListener("click", () => ctx.select("activity", "log"));
|
|
2640
|
+
actions.append(show);
|
|
2641
|
+
}
|
|
2642
|
+
detail.append(actions);
|
|
2643
|
+
into.replaceChildren(box);
|
|
2644
|
+
const wanted = shell.work.issues;
|
|
2645
|
+
focusAgain(into, wanted?.focus ?? focused?.dataset.key);
|
|
2646
|
+
shell.work.issues = {};
|
|
2647
|
+
}
|
|
2648
|
+
const issues = {
|
|
2649
|
+
id: "issues",
|
|
2650
|
+
label: "Issues",
|
|
2651
|
+
icon: "errors",
|
|
2652
|
+
tabs: { errors: drawErrors },
|
|
2653
|
+
draw: (ctx, into) => drawTabOf(issues.tabs, ctx, into)
|
|
2654
|
+
};
|
|
2655
|
+
//#endregion
|
|
2656
|
+
//#region src/runtime/devtools-panel/page.ts
|
|
2657
|
+
const STATE_COLORS = {
|
|
2658
|
+
waiting: "",
|
|
2659
|
+
loading: "blue",
|
|
2660
|
+
streaming: "blue",
|
|
2661
|
+
rendered: "green",
|
|
2662
|
+
failed: "red"
|
|
2663
|
+
};
|
|
2664
|
+
function blockLabel(block) {
|
|
2665
|
+
return block.kind === "$client" ? "$client" : `#${block.kind}`;
|
|
2666
|
+
}
|
|
2667
|
+
const PAGE_STYLE = `
|
|
2668
|
+
.pg { min-width: 0; }
|
|
2669
|
+
.pg .metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; margin: -12px -14px 0; background: var(--line); border-bottom: 1px solid var(--line); }
|
|
2670
|
+
.panel.right .pg .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
2671
|
+
.pg .metric { min-width: 0; padding: 14px 18px; background: var(--bg); }
|
|
2672
|
+
.pg .metric .l, .pg .metric .s { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
2673
|
+
.pg .metric .l { color: var(--dim); }
|
|
2674
|
+
.pg .metric .big { margin-top: 6px; font: 500 24px/1.15 var(--mono); letter-spacing: -.03em; white-space: nowrap; }
|
|
2675
|
+
.pg .metric .big small { margin-left: 3px; font-size: 12px; color: var(--faint); letter-spacing: 0; }
|
|
2676
|
+
.pg .metric .s { margin-top: 2px; font: 11px var(--mono); color: var(--faint); }
|
|
2677
|
+
.pg .cols { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); margin: 0 -14px; }
|
|
2678
|
+
.panel.right .pg .cols { grid-template-columns: minmax(0, 1fr); }
|
|
2679
|
+
.pg .cols > section { padding: 4px 18px 18px; min-width: 0; }
|
|
2680
|
+
.pg .cols > section + section { border-left: 1px solid var(--line); }
|
|
2681
|
+
.panel.right .pg .cols > section + section { border-left: 0; border-top: 1px solid var(--line); }
|
|
2682
|
+
.pg .sec { display: flex; align-items: baseline; gap: 8px; margin: 18px 0 8px; color: var(--faint); font-size: 11px; font-weight: 600; }
|
|
2683
|
+
.pg .sec .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 10.5px var(--mono); font-weight: 400; }
|
|
2684
|
+
.pg .sizes { display: flex; height: 8px; margin: 4px 0 10px; gap: 2px; border-radius: 4px; overflow: hidden; }
|
|
2685
|
+
.pg .sizes span { min-width: 3px; }
|
|
2686
|
+
.pg .legend { margin-bottom: 4px; gap: 6px 14px; font: 11px var(--mono); }
|
|
2687
|
+
.pg .block-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 12px; min-height: 36px; border-top: 1px solid var(--line); }
|
|
2688
|
+
.pg .blocks > .block-row:first-child { border-top: 0; }
|
|
2689
|
+
.pg .block-row > * { min-width: 0; }
|
|
2690
|
+
.pg .block-row .what { display: flex; align-items: center; gap: 8px; overflow: hidden; white-space: nowrap; font-family: var(--mono); }
|
|
2691
|
+
.pg .block-row .what .mono, .pg .block-row .what .sub { overflow: hidden; text-overflow: ellipsis; }
|
|
2692
|
+
.pg .block-row .state { display: flex; align-items: center; gap: 8px; white-space: nowrap; font: 11px var(--mono); color: var(--faint); }
|
|
2693
|
+
.pg .block-row .go { display: flex; gap: 6px; }
|
|
2694
|
+
.pg .scroll-x { overflow-x: auto; }
|
|
2695
|
+
.pg .values { width: 100%; table-layout: fixed; border-collapse: collapse; }
|
|
2696
|
+
.pg .values th, .pg .values td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
2697
|
+
.pg .values th:nth-child(4), .pg .values th:nth-child(5) { width: 54px; }
|
|
2698
|
+
.pg .env { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 20px; font: 11.5px var(--mono); }
|
|
2699
|
+
.pg .env > :nth-child(odd) { color: var(--faint); }
|
|
2700
|
+
.pg .env > :nth-child(even) { min-width: 0; overflow-wrap: anywhere; }
|
|
2701
|
+
.pg .acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
|
|
2702
|
+
.pg .btn { height: 28px; padding: 0 12px; border-radius: 8px; background: var(--raised); box-shadow: inset 0 0 0 1px var(--line); font-weight: 500; }
|
|
2703
|
+
.pg .btn:hover { background: var(--hover); }
|
|
2704
|
+
`;
|
|
2705
|
+
const SEGMENTS = [
|
|
2706
|
+
"var(--accent)",
|
|
2707
|
+
"var(--blue)",
|
|
2708
|
+
"var(--purple)",
|
|
2709
|
+
"var(--green)",
|
|
2710
|
+
"var(--yellow)"
|
|
2711
|
+
];
|
|
2712
|
+
/** The slots of the scopes that the server sent. The slots of every instance add up. */
|
|
2713
|
+
function readSlots(state) {
|
|
2714
|
+
const found = /* @__PURE__ */ new Map();
|
|
2715
|
+
let scopes = 0;
|
|
2716
|
+
for (const scope of state.scopes?.values() ?? []) {
|
|
2717
|
+
if (typeof scope.id === "number" && scope.id < 0) continue;
|
|
2718
|
+
scopes++;
|
|
2719
|
+
const component = findRootScope(scope).m ?? "";
|
|
2720
|
+
for (const [slot, value] of scope.s.entries()) {
|
|
2721
|
+
const id = `${component}:${scope.k}:${slot}`;
|
|
2722
|
+
const entry = found.get(id) ?? {
|
|
2723
|
+
component,
|
|
2724
|
+
k: scope.k,
|
|
2725
|
+
slot,
|
|
2726
|
+
bytes: 0,
|
|
2727
|
+
count: 0
|
|
2728
|
+
};
|
|
2729
|
+
entry.bytes += measureSize(value);
|
|
2730
|
+
entry.count++;
|
|
2731
|
+
found.set(id, entry);
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
return {
|
|
2735
|
+
slots: [...found.values()].toSorted((a, b) => b.bytes - a.bytes),
|
|
2736
|
+
scopes
|
|
2737
|
+
};
|
|
2738
|
+
}
|
|
2739
|
+
/** How long the page took to get ready, from the navigation timing, when the browser has it. */
|
|
2740
|
+
function readReady() {
|
|
2741
|
+
const [timing] = performance.getEntriesByType("navigation");
|
|
2742
|
+
if (!timing || timing.domContentLoadedEventEnd <= 0) return;
|
|
2743
|
+
return {
|
|
2744
|
+
total: timing.domContentLoadedEventEnd,
|
|
2745
|
+
server: timing.responseStart
|
|
2746
|
+
};
|
|
2747
|
+
}
|
|
2748
|
+
function makeMetric(label, big, small, note) {
|
|
2749
|
+
return element("div", { class: "metric" }, element("div", { class: "l" }, label), element("div", { class: "big" }, big, small ? element("small", {}, small) : ""), element("div", { class: "s" }, note));
|
|
2750
|
+
}
|
|
2751
|
+
function drawMetrics(state, components, scopes) {
|
|
2752
|
+
let handlers = 0;
|
|
2753
|
+
let calls = 0;
|
|
2754
|
+
for (const entry of state.log) if (entry.kind === "handler") handlers++;
|
|
2755
|
+
else if (entry.kind === "call") calls++;
|
|
2756
|
+
const bytes = (stateBytes() / 1024).toFixed(1);
|
|
2757
|
+
const ready = readReady();
|
|
2758
|
+
return element("div", { class: "metrics" }, makeMetric("Components", String(components), "", `${scopes} scopes in the browser`), makeMetric("Page state", bytes, "kB", "records from the server"), makeMetric("Handlers run", String(handlers), "", `${calls} server calls`), ready ? makeMetric("Ready in", String(Math.round(ready.total)), "ms", `server ${Math.round(ready.server)} · browser ${Math.round(ready.total - ready.server)}`) : makeMetric("Open for", seconds(performance.now()), "", "since the page started"));
|
|
2759
|
+
}
|
|
2760
|
+
/** The state of the page by component, as one bar with a legend, and its largest values. */
|
|
2761
|
+
function drawState(state) {
|
|
2762
|
+
const { slots } = readSlots(state);
|
|
2763
|
+
const first = document.querySelector("script[b-state][b-scopes]")?.textContent?.length ?? 0;
|
|
2764
|
+
const total = stateBytes();
|
|
2765
|
+
const byComponent = /* @__PURE__ */ new Map();
|
|
2766
|
+
for (const slot of slots) byComponent.set(slot.component, (byComponent.get(slot.component) ?? 0) + slot.bytes);
|
|
2767
|
+
const parts = [...byComponent].toSorted((a, b) => b[1] - a[1]);
|
|
2768
|
+
const stack = element("div", { class: "sizes" });
|
|
2769
|
+
const legend = element("div", { class: "legend" });
|
|
2770
|
+
for (const [index, [component, bytes]] of parts.entries()) {
|
|
2771
|
+
const color = SEGMENTS[index] ?? "var(--faint)";
|
|
2772
|
+
if (index < SEGMENTS.length) {
|
|
2773
|
+
stack.append(element("span", { style: `flex: ${bytes}; background: ${color}` }));
|
|
2774
|
+
legend.append(key(color, `${known.get(component)?.name ?? component} ${kilobytes(bytes)}`));
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
const table = element("table", { class: "rows values" }, row([
|
|
2778
|
+
"component",
|
|
2779
|
+
"scope",
|
|
2780
|
+
"value",
|
|
2781
|
+
"copies",
|
|
2782
|
+
"size",
|
|
2783
|
+
"read by"
|
|
2784
|
+
], "th"));
|
|
2785
|
+
for (const entry of slots.slice(0, 200)) {
|
|
2786
|
+
const info = known.get(entry.component);
|
|
2787
|
+
const layout = info?.scopes[entry.k];
|
|
2788
|
+
const readers = layout?.readers?.[entry.slot] ?? [];
|
|
2789
|
+
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", {
|
|
2790
|
+
class: "mono",
|
|
2791
|
+
style: "white-space: nowrap"
|
|
2792
|
+
}, kilobytes(entry.bytes)), element("td", { class: "mono" }, readers.join(", ") || "—"));
|
|
2793
|
+
for (const cell of tr.children) cell.setAttribute("title", cell.textContent ?? "");
|
|
2794
|
+
if (entry.bytes > 1024) {
|
|
2795
|
+
tr.className = "large";
|
|
2796
|
+
tr.title = "More than 1 kB. Send only the fields that the browser reads.";
|
|
2797
|
+
}
|
|
2798
|
+
table.append(tr);
|
|
2799
|
+
}
|
|
2800
|
+
return {
|
|
2801
|
+
summary: [
|
|
2802
|
+
element("div", { class: "sec" }, "Page state", element("span", { class: "n" }, `${kilobytes(total)}, the first record ${kilobytes(first)}`)),
|
|
2803
|
+
slots.length > 0 ? stack : "",
|
|
2804
|
+
slots.length > 0 ? legend : "",
|
|
2805
|
+
slots.length > 0 ? "" : element("div", { class: "empty" }, "The page sent no state.")
|
|
2806
|
+
],
|
|
2807
|
+
values: slots.length > 0 ? [element("div", { class: "sec" }, "Values", element("span", { class: "n" }, "largest first")), element("div", { class: "scroll-x" }, table)] : []
|
|
2808
|
+
};
|
|
2809
|
+
}
|
|
2810
|
+
function drawBlocks(ctx) {
|
|
2811
|
+
const { state } = ctx;
|
|
2812
|
+
const blocks = [...state.blocks.values()];
|
|
2813
|
+
const list = element("div", { class: "blocks" });
|
|
2814
|
+
for (const block of blocks) {
|
|
2815
|
+
const action = element("span", { class: "go" });
|
|
2816
|
+
if (block.state === "waiting" && (block.kind === "defer" || block.kind === "client")) {
|
|
2817
|
+
const fire = iconButton("bolt", "Trigger now", { title: "Fire the trigger now" });
|
|
2818
|
+
fire.addEventListener("click", () => {
|
|
2819
|
+
state.fire?.(block);
|
|
2820
|
+
ctx.draw();
|
|
2821
|
+
});
|
|
2822
|
+
action.append(fire);
|
|
2823
|
+
}
|
|
2824
|
+
const kept = globalThis.$bD?.[block.id];
|
|
2825
|
+
if (block.state === "rendered" && kept && (block.kind === "loading" || block.kind === "defer")) {
|
|
2826
|
+
const toggle = iconButton(block.fallback ? "play" : "pause", block.fallback ? "Body" : "Fallback", {
|
|
2827
|
+
title: block.fallback ? "Show the body again" : "Show the fallback in place of the body",
|
|
2828
|
+
"aria-pressed": String(block.fallback === true)
|
|
2829
|
+
});
|
|
2830
|
+
toggle.addEventListener("click", () => {
|
|
2831
|
+
state.showFallback?.(block, !block.fallback);
|
|
2832
|
+
ctx.draw();
|
|
2833
|
+
});
|
|
2834
|
+
action.append(toggle);
|
|
2835
|
+
}
|
|
2836
|
+
let took = "";
|
|
2837
|
+
if (block.rendered !== void 0) took = block.fired === void 0 ? seconds(block.rendered) : `+${ms(block.rendered - block.fired)}`;
|
|
2838
|
+
const times = [];
|
|
2839
|
+
if (block.fired !== void 0) times.push(seconds(block.fired));
|
|
2840
|
+
if (took) times.push(took);
|
|
2841
|
+
list.append(element("div", { class: "block-row" }, element("span", { class: "what" }, pill(blockLabel(block), block.kind === "$client" ? "blue" : "accent"), element("span", { class: "mono" }, block.id), element("span", { class: "sub" }, block.trigger ?? "")), element("span", { class: "state" }, pill(block.state, STATE_COLORS[block.state]), times.join(" ")), action));
|
|
2842
|
+
}
|
|
2843
|
+
return [element("div", { class: "sec" }, "Blocks", element("span", { class: "n" }, String(blocks.length))), blocks.length > 0 ? list : element("div", { class: "empty" }, "No blocks that render later on this page.")];
|
|
2844
|
+
}
|
|
2845
|
+
function drawEnvironment(ctx) {
|
|
2846
|
+
const { state } = ctx;
|
|
2847
|
+
const issues = element("button", { class: "btn" }, plural(state.errors.length, "issue"));
|
|
2848
|
+
issues.addEventListener("click", () => ctx.select("issues", "errors"));
|
|
2849
|
+
const activity = element("button", { class: "btn" }, "Activity");
|
|
2850
|
+
activity.addEventListener("click", () => ctx.select("activity", "log"));
|
|
2851
|
+
return [
|
|
2852
|
+
element("div", { class: "sec" }, "Environment"),
|
|
2853
|
+
element("div", { class: "env" }, element("span", {}, "brumate"), element("span", {}, state.meta.version ?? "unknown"), element("span", {}, "vite"), element("span", {}, state.meta.vite ?? "unknown"), element("span", {}, "route"), element("span", {}, location.pathname + location.search), element("span", {}, "open for"), element("span", {}, seconds(performance.now()))),
|
|
2854
|
+
element("div", { class: "acts" }, issues, activity)
|
|
2855
|
+
];
|
|
2856
|
+
}
|
|
2857
|
+
function plural(count, word) {
|
|
2858
|
+
return `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
2859
|
+
}
|
|
2860
|
+
/** Draws the whole workspace. The old tabs of the tab bar draw the same page. */
|
|
2861
|
+
function drawPage(ctx, into) {
|
|
2862
|
+
const { state } = ctx;
|
|
2863
|
+
if (!ctx.root.querySelector("style[data-page]")) ctx.root.append(element("style", { "data-page": "" }, PAGE_STYLE));
|
|
2864
|
+
const ids = [...collectModules(roots(state))];
|
|
2865
|
+
function render() {
|
|
2866
|
+
let scopes = 0;
|
|
2867
|
+
for (const scope of roots(state)) scopes += countScopes(scope);
|
|
2868
|
+
const shown = drawState(state);
|
|
2869
|
+
into.replaceChildren(element("div", { class: "pg" }, drawMetrics(state, ids.length, state.scopes?.size ?? scopes), element("div", { class: "cols" }, element("section", {}, ...shown.summary, ...drawBlocks(ctx), ...shown.values), element("section", {}, ...drawEnvironment(ctx)))));
|
|
2870
|
+
}
|
|
2871
|
+
render();
|
|
2872
|
+
let missing = false;
|
|
2873
|
+
for (const id of ids) if (!known.has(id)) missing = true;
|
|
2874
|
+
if (missing) return loadComponents(state, ids).then(render);
|
|
2875
|
+
}
|
|
2876
|
+
const page = {
|
|
2877
|
+
id: "page",
|
|
2878
|
+
label: "Page",
|
|
2879
|
+
icon: "overview",
|
|
2880
|
+
tabs: {
|
|
2881
|
+
overview: drawPage,
|
|
2882
|
+
state: drawPage,
|
|
2883
|
+
blocks: drawPage
|
|
2884
|
+
},
|
|
2885
|
+
draw: drawPage
|
|
2886
|
+
};
|
|
2887
|
+
//#endregion
|
|
2888
|
+
//#region src/runtime/devtools-panel/search.ts
|
|
2889
|
+
/** The most lines of one group. */
|
|
2890
|
+
const PER_GROUP = 6;
|
|
2891
|
+
/** The ID of the first instance of a component. */
|
|
2892
|
+
function firstScope(list, id) {
|
|
2893
|
+
for (const scope of list) if (scope.m === id) return scope.id;
|
|
2894
|
+
}
|
|
2895
|
+
/** The lines for components and issues. The entry adds the actions. */
|
|
2896
|
+
function collectItems(ctx) {
|
|
2897
|
+
const { state, shell } = ctx;
|
|
2898
|
+
const items = [];
|
|
2899
|
+
const list = roots(state);
|
|
2900
|
+
for (const id of collectModules(list)) {
|
|
2901
|
+
const info = known.get(id);
|
|
2902
|
+
items.push({
|
|
2903
|
+
group: "Components",
|
|
2904
|
+
label: info?.name ?? id,
|
|
2905
|
+
hint: info?.file ?? "",
|
|
2906
|
+
run() {
|
|
2907
|
+
shell.selected = id;
|
|
2908
|
+
shell.selectedScope = firstScope(list, id);
|
|
2909
|
+
shell.graphNode = void 0;
|
|
2910
|
+
ctx.select("inspect");
|
|
2911
|
+
}
|
|
2912
|
+
});
|
|
2913
|
+
}
|
|
2914
|
+
for (const entry of state.errors.toReversed()) items.push({
|
|
2915
|
+
group: "Issues",
|
|
2916
|
+
label: entry.message.split("\n")[0],
|
|
2917
|
+
hint: entry.source,
|
|
2918
|
+
run() {
|
|
2919
|
+
shell.selectedError = entry;
|
|
2920
|
+
shell.selectedFrame = -1;
|
|
2921
|
+
ctx.select("issues");
|
|
2922
|
+
}
|
|
2923
|
+
});
|
|
2924
|
+
return items;
|
|
2925
|
+
}
|
|
2926
|
+
/** Filters the lines by the query, at most a few of each group. */
|
|
2927
|
+
function filterItems(items, query) {
|
|
2928
|
+
const text = query.trim().toLowerCase();
|
|
2929
|
+
const counts = /* @__PURE__ */ new Map();
|
|
2930
|
+
const found = [];
|
|
2931
|
+
for (const item of items) {
|
|
2932
|
+
if (text && !item.label.toLowerCase().includes(text) && !item.hint.toLowerCase().includes(text)) continue;
|
|
2933
|
+
const count = counts.get(item.group) ?? 0;
|
|
2934
|
+
if (count < PER_GROUP) {
|
|
2935
|
+
counts.set(item.group, count + 1);
|
|
2936
|
+
found.push(item);
|
|
2937
|
+
}
|
|
2938
|
+
}
|
|
2939
|
+
return found;
|
|
2940
|
+
}
|
|
2941
|
+
/** The search of a dock. `actions` gives the lines for what the dock can do. */
|
|
2942
|
+
function createSearch(ctx, actions) {
|
|
2943
|
+
const { root } = ctx;
|
|
2944
|
+
let scrim;
|
|
2945
|
+
let before = null;
|
|
2946
|
+
function open() {
|
|
2947
|
+
if (scrim) return;
|
|
2948
|
+
before = root.activeElement;
|
|
2949
|
+
const magnifier = svg("svg", {
|
|
2950
|
+
viewBox: "0 0 24 24",
|
|
2951
|
+
width: 16,
|
|
2952
|
+
height: 16,
|
|
2953
|
+
fill: "none",
|
|
2954
|
+
stroke: "currentColor",
|
|
2955
|
+
"stroke-width": 2,
|
|
2956
|
+
"stroke-linecap": "round",
|
|
2957
|
+
"aria-hidden": "true"
|
|
2958
|
+
});
|
|
2959
|
+
magnifier.innerHTML = trustedHTML("<circle cx=\"11\" cy=\"11\" r=\"7\"/><path d=\"m20 20-3.5-3.5\"/>");
|
|
2960
|
+
const input = element("input", {
|
|
2961
|
+
type: "text",
|
|
2962
|
+
role: "combobox",
|
|
2963
|
+
"aria-expanded": "true",
|
|
2964
|
+
"aria-controls": "dock-search-list",
|
|
2965
|
+
"aria-label": "Search the dock",
|
|
2966
|
+
placeholder: "Components, issues, actions",
|
|
2967
|
+
autocomplete: "off",
|
|
2968
|
+
spellcheck: "false"
|
|
2969
|
+
});
|
|
2970
|
+
const results = element("div", {
|
|
2971
|
+
class: "res",
|
|
2972
|
+
role: "listbox",
|
|
2973
|
+
id: "dock-search-list"
|
|
2974
|
+
});
|
|
2975
|
+
const layer = element("div", { class: "scrim" }, element("div", {
|
|
2976
|
+
class: "pal",
|
|
2977
|
+
role: "dialog",
|
|
2978
|
+
"aria-modal": "true",
|
|
2979
|
+
"aria-label": "Search the dock"
|
|
2980
|
+
}, element("div", { class: "in" }, magnifier, input, element("kbd", {}, "esc")), results, element("div", { class: "end" }, element("span", {}, element("kbd", {}, "↑"), element("kbd", {}, "↓"), " move"), element("span", {}, element("kbd", {}, "↵"), " open"), element("span", { class: "grow" }), element("span", {}, `brumate ${ctx.state.meta.version ?? ""}`.trim()))));
|
|
2981
|
+
scrim = layer;
|
|
2982
|
+
let items = [...collectItems(ctx), ...actions()];
|
|
2983
|
+
let found = [];
|
|
2984
|
+
let hit = 0;
|
|
2985
|
+
function draw() {
|
|
2986
|
+
found = filterItems(items, input.value);
|
|
2987
|
+
hit = Math.max(0, Math.min(hit, found.length - 1));
|
|
2988
|
+
results.replaceChildren();
|
|
2989
|
+
if (found.length === 0) {
|
|
2990
|
+
results.append(element("div", { class: "none" }, "No match."));
|
|
2991
|
+
input.removeAttribute("aria-activedescendant");
|
|
2992
|
+
return;
|
|
2993
|
+
}
|
|
2994
|
+
let group = "";
|
|
2995
|
+
for (const [index, item] of found.entries()) {
|
|
2996
|
+
if (item.group !== group) {
|
|
2997
|
+
group = item.group;
|
|
2998
|
+
results.append(element("div", { class: "grp" }, group));
|
|
2999
|
+
}
|
|
3000
|
+
const line = element("div", {
|
|
3001
|
+
class: "it",
|
|
3002
|
+
role: "option",
|
|
3003
|
+
id: `dock-search-${index}`,
|
|
3004
|
+
"aria-selected": String(index === hit)
|
|
3005
|
+
}, element("span", {}, item.label), element("span", { class: "h" }, item.hint));
|
|
3006
|
+
line.addEventListener("click", () => choose(index));
|
|
3007
|
+
line.addEventListener("pointermove", () => {
|
|
3008
|
+
if (hit !== index) {
|
|
3009
|
+
hit = index;
|
|
3010
|
+
draw();
|
|
3011
|
+
}
|
|
3012
|
+
});
|
|
3013
|
+
results.append(line);
|
|
3014
|
+
}
|
|
3015
|
+
input.setAttribute("aria-activedescendant", `dock-search-${hit}`);
|
|
3016
|
+
results.querySelector("[aria-selected=\"true\"]")?.scrollIntoView?.({ block: "nearest" });
|
|
3017
|
+
}
|
|
3018
|
+
function choose(index) {
|
|
3019
|
+
const item = found[index];
|
|
3020
|
+
close(false);
|
|
3021
|
+
item?.run();
|
|
3022
|
+
}
|
|
3023
|
+
input.addEventListener("input", () => {
|
|
3024
|
+
hit = 0;
|
|
3025
|
+
draw();
|
|
3026
|
+
});
|
|
3027
|
+
input.addEventListener("keydown", (event) => {
|
|
3028
|
+
if (event.key === "Escape") {
|
|
3029
|
+
event.preventDefault();
|
|
3030
|
+
event.stopPropagation();
|
|
3031
|
+
close(true);
|
|
3032
|
+
} else if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
3033
|
+
event.preventDefault();
|
|
3034
|
+
hit = Math.max(0, Math.min(hit + (event.key === "ArrowDown" ? 1 : -1), found.length - 1));
|
|
3035
|
+
draw();
|
|
3036
|
+
} else if (event.key === "Enter") {
|
|
3037
|
+
event.preventDefault();
|
|
3038
|
+
choose(hit);
|
|
3039
|
+
}
|
|
3040
|
+
});
|
|
3041
|
+
layer.addEventListener("keydown", (event) => {
|
|
3042
|
+
if (event.key === "Tab") {
|
|
3043
|
+
event.preventDefault();
|
|
3044
|
+
input.focus();
|
|
3045
|
+
}
|
|
3046
|
+
});
|
|
3047
|
+
layer.addEventListener("pointerdown", (event) => {
|
|
3048
|
+
if (event.target === layer) close(true);
|
|
3049
|
+
});
|
|
3050
|
+
root.append(layer);
|
|
3051
|
+
draw();
|
|
3052
|
+
input.focus();
|
|
3053
|
+
loadComponents(ctx.state, collectModules(roots(ctx.state))).then(() => {
|
|
3054
|
+
if (scrim === layer) {
|
|
3055
|
+
items = [...collectItems(ctx), ...actions()];
|
|
3056
|
+
draw();
|
|
3057
|
+
}
|
|
3058
|
+
});
|
|
3059
|
+
}
|
|
3060
|
+
/** Closes the search. Focus goes back to where it was, unless a line moved it on. */
|
|
3061
|
+
function close(restore = true) {
|
|
3062
|
+
scrim?.remove();
|
|
3063
|
+
scrim = void 0;
|
|
3064
|
+
if (restore && before instanceof HTMLElement && before.isConnected) before.focus();
|
|
3065
|
+
before = null;
|
|
3066
|
+
}
|
|
3067
|
+
return {
|
|
3068
|
+
open,
|
|
3069
|
+
close: () => close(true),
|
|
3070
|
+
isOpen: () => scrim !== void 0
|
|
3071
|
+
};
|
|
3072
|
+
}
|
|
3073
|
+
//#endregion
|
|
3074
|
+
//#region src/runtime/devtools-panel/shell.ts
|
|
3075
|
+
const PREFS = {
|
|
3076
|
+
height: "brumate:devtools:height",
|
|
3077
|
+
width: "brumate:devtools:width",
|
|
3078
|
+
side: "brumate:devtools:side",
|
|
3079
|
+
workspace: "brumate:devtools:workspace"
|
|
3080
|
+
};
|
|
3081
|
+
/** The least and the greatest size of the dock, in pixels or as a share of the window. */
|
|
3082
|
+
const LIMITS = {
|
|
3083
|
+
height: {
|
|
3084
|
+
min: 160,
|
|
3085
|
+
share: .9
|
|
3086
|
+
},
|
|
3087
|
+
width: {
|
|
3088
|
+
min: 340,
|
|
3089
|
+
share: .7
|
|
3090
|
+
}
|
|
3091
|
+
};
|
|
3092
|
+
/** Reads what the dock kept, or nothing. */
|
|
3093
|
+
function readPref(name) {
|
|
3094
|
+
try {
|
|
3095
|
+
return localStorage.getItem(PREFS[name]) ?? void 0;
|
|
3096
|
+
} catch {
|
|
3097
|
+
return;
|
|
3098
|
+
}
|
|
3099
|
+
}
|
|
3100
|
+
/** Keeps a choice for the next open. */
|
|
3101
|
+
function writePref(name, value) {
|
|
3102
|
+
try {
|
|
3103
|
+
localStorage.setItem(PREFS[name], value);
|
|
3104
|
+
} catch {}
|
|
3105
|
+
}
|
|
3106
|
+
/** The strokes of the icons of the header, on a grid of 24. */
|
|
3107
|
+
const GLYPHS = {
|
|
3108
|
+
inspect: "<path d=\"M4 6h16M4 12h10M4 18h6\"/>",
|
|
3109
|
+
activity: "<path d=\"M3 12h4l3-8 4 16 3-8h4\"/>",
|
|
3110
|
+
issues: "<circle cx=\"12\" cy=\"12\" r=\"9\"/><path d=\"M12 7v6M12 17h.01\"/>",
|
|
3111
|
+
page: "<rect x=\"4\" y=\"3\" width=\"16\" height=\"18\" rx=\"2\"/><path d=\"M8 8h8M8 12h8M8 16h5\"/>",
|
|
3112
|
+
search: "<circle cx=\"11\" cy=\"11\" r=\"7\"/><path d=\"m20 20-3.5-3.5\"/>",
|
|
3113
|
+
pick: "<path d=\"M4 4l7 17 2.5-7.5L21 11z\"/>",
|
|
3114
|
+
updates: "<rect x=\"4\" y=\"4\" width=\"16\" height=\"16\" rx=\"3\" stroke-dasharray=\"3 3\"/>",
|
|
3115
|
+
side: "<rect x=\"3\" y=\"4\" width=\"18\" height=\"16\" rx=\"2\"/><path d=\"M15 4v16\"/>",
|
|
3116
|
+
close: "<path d=\"M6 6l12 12M18 6 6 18\"/>"
|
|
3117
|
+
};
|
|
3118
|
+
function glyph(name, size) {
|
|
3119
|
+
const node = svg("svg", {
|
|
3120
|
+
viewBox: "0 0 24 24",
|
|
3121
|
+
width: size,
|
|
3122
|
+
height: size,
|
|
3123
|
+
fill: "none",
|
|
3124
|
+
stroke: "currentColor",
|
|
3125
|
+
"stroke-width": 2,
|
|
3126
|
+
"stroke-linecap": "round",
|
|
3127
|
+
"stroke-linejoin": "round",
|
|
3128
|
+
"aria-hidden": "true"
|
|
3129
|
+
});
|
|
3130
|
+
node.innerHTML = trustedHTML(GLYPHS[name]);
|
|
3131
|
+
return node;
|
|
3132
|
+
}
|
|
3133
|
+
function toolButton(name, label) {
|
|
3134
|
+
return element("button", {
|
|
3135
|
+
class: "tbtn",
|
|
3136
|
+
title: label,
|
|
3137
|
+
"aria-label": label
|
|
3138
|
+
}, glyph(name, 15));
|
|
3139
|
+
}
|
|
3140
|
+
/** The chrome of a closed dock, with the nav of the workspaces. */
|
|
3141
|
+
function createChrome(state, workspaces) {
|
|
3142
|
+
const tabs = /* @__PURE__ */ new Map();
|
|
3143
|
+
const counts = /* @__PURE__ */ new Map();
|
|
3144
|
+
const indicator = element("span", { class: "ind" });
|
|
3145
|
+
const nav = element("nav", {
|
|
3146
|
+
class: "ws",
|
|
3147
|
+
role: "tablist",
|
|
3148
|
+
"aria-label": "Workspaces"
|
|
3149
|
+
}, indicator);
|
|
3150
|
+
for (const workspace of workspaces) {
|
|
3151
|
+
const count = element("span", { class: workspace.id === "issues" ? "c red" : "c" });
|
|
3152
|
+
const button = element("button", {
|
|
3153
|
+
role: "tab",
|
|
3154
|
+
"data-ws": workspace.id,
|
|
3155
|
+
title: workspace.label
|
|
3156
|
+
}, glyph(workspace.id, 14), element("span", { class: "l" }, workspace.label), count);
|
|
3157
|
+
tabs.set(workspace.id, button);
|
|
3158
|
+
counts.set(workspace.id, count);
|
|
3159
|
+
nav.append(button);
|
|
3160
|
+
}
|
|
3161
|
+
const mark = element("i");
|
|
3162
|
+
mark.innerHTML = trustedHTML(LOGO);
|
|
3163
|
+
const vite = state.meta.vite ? ` · Vite ${state.meta.vite}` : "";
|
|
3164
|
+
const brand = element("div", { class: "brand" }, mark, element("b", {}, "brumate"), element("span", {
|
|
3165
|
+
class: "ver",
|
|
3166
|
+
title: `brumate ${state.meta.version ?? "?"}${vite}`
|
|
3167
|
+
}, state.meta.version ?? "?"));
|
|
3168
|
+
const search = element("button", {
|
|
3169
|
+
class: "cmd",
|
|
3170
|
+
"aria-label": "Search",
|
|
3171
|
+
title: "Search (Cmd+K)"
|
|
3172
|
+
}, glyph("search", 14), element("span", { class: "t" }, "Search"), element("kbd", {}, "⌘K"));
|
|
3173
|
+
const pick = toolButton("pick", "Pick an element");
|
|
3174
|
+
pick.setAttribute("aria-pressed", "false");
|
|
3175
|
+
pick.title = "Click an element of the page to see its scope, handlers and code";
|
|
3176
|
+
const updates = toolButton("updates", "Outline updates");
|
|
3177
|
+
updates.setAttribute("aria-pressed", String(state.flash));
|
|
3178
|
+
updates.title = "Outline the elements that change: green now and then, red often";
|
|
3179
|
+
const side = toolButton("side", "Dock to the right");
|
|
3180
|
+
side.setAttribute("aria-pressed", "false");
|
|
3181
|
+
const close = toolButton("close", "Close (Esc)");
|
|
3182
|
+
const live = element("span", { class: "live" }, element("i"), "live");
|
|
3183
|
+
const facts = {
|
|
3184
|
+
route: element("b"),
|
|
3185
|
+
components: element("b"),
|
|
3186
|
+
scopes: element("b"),
|
|
3187
|
+
size: element("b")
|
|
3188
|
+
};
|
|
3189
|
+
const up = element("b");
|
|
3190
|
+
const viteFact = element("span", {});
|
|
3191
|
+
if (state.meta.vite) viteFact.append("Vite ", element("b", {}, state.meta.vite));
|
|
3192
|
+
const edge = element("div", {
|
|
3193
|
+
class: "edge",
|
|
3194
|
+
role: "separator",
|
|
3195
|
+
tabindex: "0",
|
|
3196
|
+
"aria-label": "Resize the dock",
|
|
3197
|
+
title: "Drag, or use the arrow keys"
|
|
3198
|
+
});
|
|
3199
|
+
const body = element("div", { class: "body" });
|
|
3200
|
+
return {
|
|
3201
|
+
panel: element("section", {
|
|
3202
|
+
class: "panel bottom",
|
|
3203
|
+
"aria-label": "brumate dev dock"
|
|
3204
|
+
}, edge, element("header", { class: "head" }, brand, nav, element("span", { class: "grow" }), search, pick, updates, side, close), body, element("footer", { class: "foot" }, live, element("span", {}, facts.route), element("span", {}, facts.components, " components"), element("span", {}, facts.scopes, " scopes"), element("span", {}, facts.size, " page state"), element("span", { class: "grow" }), viteFact, element("span", {}, "up ", up))),
|
|
3205
|
+
edge,
|
|
3206
|
+
body,
|
|
3207
|
+
tabs,
|
|
3208
|
+
counts,
|
|
3209
|
+
indicator,
|
|
3210
|
+
search,
|
|
3211
|
+
pick,
|
|
3212
|
+
updates,
|
|
3213
|
+
side,
|
|
3214
|
+
close,
|
|
3215
|
+
live,
|
|
3216
|
+
facts,
|
|
3217
|
+
up
|
|
3218
|
+
};
|
|
3219
|
+
}
|
|
3220
|
+
/** Moves the highlight of the nav under the selected workspace. */
|
|
3221
|
+
function placeIndicator(chrome, current) {
|
|
3222
|
+
const button = chrome.tabs.get(current);
|
|
3223
|
+
chrome.indicator.style.left = `${button.offsetLeft}px`;
|
|
3224
|
+
chrome.indicator.style.width = `${button.offsetWidth}px`;
|
|
3225
|
+
}
|
|
3226
|
+
/** Sets the side of the dock, with the label of the button that switches it. */
|
|
3227
|
+
function applySide(chrome, side) {
|
|
3228
|
+
chrome.panel.classList.toggle("bottom", side === "bottom");
|
|
3229
|
+
chrome.panel.classList.toggle("right", side === "right");
|
|
3230
|
+
chrome.side.setAttribute("aria-pressed", String(side === "right"));
|
|
3231
|
+
const label = side === "right" ? "Dock to the bottom" : "Dock to the right";
|
|
3232
|
+
chrome.side.title = label;
|
|
3233
|
+
chrome.side.setAttribute("aria-label", label);
|
|
3234
|
+
}
|
|
3235
|
+
/** The selected workspace, the counts of the nav and the footer. */
|
|
3236
|
+
function drawChrome(chrome, state, current, paused) {
|
|
3237
|
+
for (const [id, button] of chrome.tabs) {
|
|
3238
|
+
button.setAttribute("aria-selected", String(id === current));
|
|
3239
|
+
button.tabIndex = id === current ? 0 : -1;
|
|
3240
|
+
}
|
|
3241
|
+
placeIndicator(chrome, current);
|
|
3242
|
+
const errors = state.errors.length;
|
|
3243
|
+
const entries = state.log.length;
|
|
3244
|
+
chrome.counts.get("activity").textContent = entries > 0 ? String(entries) : "";
|
|
3245
|
+
chrome.counts.get("issues").textContent = errors > 0 ? String(errors) : "";
|
|
3246
|
+
chrome.tabs.get("issues").setAttribute("aria-label", errors > 0 ? `Issues, ${errors}` : "Issues");
|
|
3247
|
+
const list = roots(state);
|
|
3248
|
+
chrome.live.classList.toggle("paused", paused);
|
|
3249
|
+
chrome.live.lastChild.textContent = paused ? "paused" : "live";
|
|
3250
|
+
chrome.facts.route.textContent = location.pathname + location.search;
|
|
3251
|
+
chrome.facts.components.textContent = String(collectModules(list).size);
|
|
3252
|
+
chrome.facts.scopes.textContent = String(state.scopes?.size ?? 0);
|
|
3253
|
+
chrome.facts.size.textContent = kilobytes(stateBytes());
|
|
3254
|
+
const waiting = countBlocks(state.blocks.values(), "waiting");
|
|
3255
|
+
chrome.tabs.get("page").title = waiting > 0 ? `Page · ${waiting} blocks wait for their trigger` : "Page";
|
|
3256
|
+
chrome.up.textContent = `${Math.round(performance.now() / 1e3)} s`;
|
|
3257
|
+
}
|
|
3258
|
+
//#endregion
|
|
3259
|
+
//#region src/runtime/devtools-panel/style.ts
|
|
3260
|
+
const STYLE$1 = `
|
|
3261
|
+
:host { all: initial; }
|
|
3262
|
+
.panel {
|
|
3263
|
+
--bg: #121113; --bg2: #161517; --surface: #161517; --raised: #1d1c1f; --hover: #232125;
|
|
3264
|
+
--line: #29272b; --line2: #36333a;
|
|
3265
|
+
--text: #ece8e4; --dim: #a39a92; --faint: #6f6862;
|
|
3266
|
+
--accent: #ee7a3e; --accent-text: #ffb48a; --sel: #ee7a3e14; --ring: #ee7a3e47;
|
|
3267
|
+
--blue: #7cb7ff; --purple: #c49bff; --green: #7fd99a; --yellow: #ffd166; --red: #ff6b6b; --pink: #ff8fc8;
|
|
3268
|
+
--mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, monospace;
|
|
3269
|
+
--ease: cubic-bezier(.2, .8, .2, 1);
|
|
3270
|
+
position: fixed; z-index: 2147483647; display: flex; flex-direction: column;
|
|
3271
|
+
background: var(--bg); color: var(--text); transition: transform 0.26s var(--ease);
|
|
3272
|
+
font: 12.5px/1.5 system-ui, -apple-system, sans-serif; font-variant-numeric: tabular-nums;
|
|
3273
|
+
-webkit-font-smoothing: antialiased; color-scheme: dark;
|
|
3274
|
+
}
|
|
3275
|
+
.panel.bottom { left: 0; right: 0; bottom: 0; height: var(--h, 340px); min-height: 160px; max-height: 90vh; box-shadow: 0 -1px 0 var(--line2), 0 -24px 48px -24px #0009; }
|
|
3276
|
+
.panel.right { top: 0; right: 0; bottom: 0; width: var(--w, 480px); min-width: 340px; max-width: 70vw; box-shadow: -1px 0 0 var(--line2), -24px 0 48px -24px #0009; }
|
|
3277
|
+
.panel.closed { transform: translateY(100%); pointer-events: none; }
|
|
3278
|
+
.panel.right.closed { transform: translateX(100%); }
|
|
3279
|
+
.panel.dragging { transition: none; }
|
|
3280
|
+
.edge { position: absolute; z-index: 2; touch-action: none; }
|
|
3281
|
+
.panel.bottom .edge { left: 0; right: 0; top: -3px; height: 7px; cursor: ns-resize; }
|
|
3282
|
+
.panel.right .edge { top: 0; bottom: 0; left: -3px; width: 7px; cursor: ew-resize; }
|
|
3283
|
+
.edge::after { content: ""; position: absolute; inset: 3px 0; background: var(--accent); opacity: 0; transition: opacity 0.15s; }
|
|
3284
|
+
.panel.right .edge::after { inset: 0 3px; }
|
|
3285
|
+
.edge:hover::after, .panel.dragging .edge::after { opacity: 0.7; }
|
|
3286
|
+
.edge:focus-visible { outline: none; }
|
|
3287
|
+
.edge:focus-visible::after { opacity: 1; }
|
|
3288
|
+
.head { display: flex; align-items: center; gap: 4px; height: 42px; padding: 0 8px 0 12px; border-bottom: 1px solid var(--line); flex: none; }
|
|
3289
|
+
.brand { display: flex; align-items: center; gap: 8px; padding-right: 12px; margin-right: 4px; height: 20px; border-right: 1px solid var(--line); }
|
|
3290
|
+
.brand i { display: inline-block; width: 16px; height: 16px; }
|
|
3291
|
+
.brand b { font-weight: 600; letter-spacing: -0.01em; }
|
|
3292
|
+
.ver { font: 11px/18px var(--mono); padding: 0 6px; border-radius: 5px; background: var(--hover); color: var(--dim); }
|
|
3293
|
+
.ws { position: relative; display: flex; gap: 2px; }
|
|
3294
|
+
.ws button { position: relative; z-index: 1; display: flex; align-items: center; gap: 7px; height: 28px; padding: 0 11px; border-radius: 7px; border: 0; color: var(--dim); font-weight: 500; transition: color 0.15s; }
|
|
3295
|
+
.ws button:hover { background: none; color: var(--text); }
|
|
3296
|
+
.ws button[aria-selected="true"] { color: var(--text); }
|
|
3297
|
+
.ws .ind { position: absolute; top: 0; left: 0; width: 0; height: 28px; border-radius: 7px; background: var(--hover); box-shadow: inset 0 0 0 1px var(--line2); transition: left 0.25s var(--ease), width 0.25s var(--ease); }
|
|
3298
|
+
.ws .c { font: 10.5px/16px var(--mono); color: var(--faint); }
|
|
3299
|
+
.ws .c:empty { display: none; }
|
|
3300
|
+
.ws .c.red { color: var(--red); }
|
|
3301
|
+
.grow { flex: 1; }
|
|
3302
|
+
.head button.cmd { display: flex; align-items: center; gap: 8px; height: 28px; padding: 0 5px 0 10px; width: 220px; border: 0; border-radius: 8px; background: var(--bg2); box-shadow: inset 0 0 0 1px var(--line); color: var(--faint); margin-right: 4px; transition: box-shadow 0.15s, color 0.15s; }
|
|
3303
|
+
.head button.cmd:hover { box-shadow: inset 0 0 0 1px var(--line2); color: var(--dim); }
|
|
3304
|
+
.cmd .t { flex: 1; text-align: left; }
|
|
3305
|
+
kbd { font: 10.5px/18px var(--mono); min-width: 18px; text-align: center; padding: 0 4px; border-radius: 5px; background: var(--hover); color: var(--dim); }
|
|
3306
|
+
.head button.tbtn { display: grid; place-items: center; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 7px; color: var(--dim); transition: background 0.15s, color 0.15s; }
|
|
3307
|
+
.head button.tbtn:hover { background: var(--hover); color: var(--text); }
|
|
3308
|
+
.head button.tbtn[aria-pressed="true"] { background: var(--sel); color: var(--accent-text); box-shadow: inset 0 0 0 1px var(--ring); }
|
|
3309
|
+
.panel.right .cmd { width: 28px; padding: 0; justify-content: center; }
|
|
3310
|
+
.panel.right .cmd .t, .panel.right .cmd kbd, .panel.right .ws .l, .panel.right .brand b { display: none; }
|
|
3311
|
+
.foot { display: flex; align-items: center; gap: 16px; height: 26px; padding: 0 14px; border-top: 1px solid var(--line); color: var(--faint); font: 11px var(--mono); flex: none; overflow: hidden; white-space: nowrap; }
|
|
3312
|
+
.foot b { color: var(--dim); font-weight: 400; }
|
|
3313
|
+
.panel.right .foot span:nth-child(n+4):not(:last-child) { display: none; }
|
|
3314
|
+
.live { display: inline-flex; align-items: center; gap: 6px; }
|
|
3315
|
+
.live i { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
|
|
3316
|
+
.live.paused i { background: var(--faint); }
|
|
3317
|
+
.scrim { position: fixed; inset: 0; z-index: 2147483647; display: grid; place-items: start center; padding-top: 14vh; background: #0a090b99; backdrop-filter: blur(2px); animation: fade 0.15s ease-out; }
|
|
3318
|
+
@keyframes fade { from { opacity: 0; } }
|
|
3319
|
+
@keyframes rise { from { transform: translateY(8px) scale(0.985); opacity: 0; } }
|
|
3320
|
+
.pal { --bg: #121113; --raised: #1d1c1f; --hover: #232125; --line: #29272b; --line2: #36333a; --text: #ece8e4; --dim: #a39a92; --faint: #6f6862; --mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, monospace; width: min(580px, calc(100vw - 32px)); background: var(--bg); color: var(--text); border-radius: 14px; box-shadow: 0 0 0 1px var(--line2), 0 30px 80px #000c; overflow: hidden; font: 12.5px/1.5 system-ui, -apple-system, sans-serif; color-scheme: dark; animation: rise 0.2s var(--ease, ease-out); }
|
|
3321
|
+
.pal .in { display: flex; align-items: center; gap: 10px; padding: 0 16px; height: 50px; border-bottom: 1px solid var(--line); color: var(--faint); }
|
|
3322
|
+
.pal input { flex: 1; min-width: 0; background: none; border: 0; font: 15px system-ui, -apple-system, sans-serif; color: var(--text); outline: none; }
|
|
3323
|
+
.pal .res { max-height: 340px; overflow: auto; padding: 6px; }
|
|
3324
|
+
.pal .grp { padding: 10px 10px 4px; font-size: 11px; font-weight: 600; color: var(--faint); }
|
|
3325
|
+
.pal .it { display: flex; gap: 10px; align-items: center; height: 36px; padding: 0 10px; border-radius: 8px; cursor: pointer; }
|
|
3326
|
+
.pal .it[aria-selected="true"] { background: var(--hover); }
|
|
3327
|
+
.pal .it .h { margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 11px var(--mono); color: var(--faint); }
|
|
3328
|
+
.pal .none { padding: 14px 10px; color: var(--faint); }
|
|
3329
|
+
.pal .end { display: flex; gap: 16px; align-items: center; padding: 0 14px; height: 36px; border-top: 1px solid var(--line); color: var(--faint); font-size: 11px; }
|
|
3330
|
+
.pal .end span { display: inline-flex; gap: 6px; align-items: center; }
|
|
3331
|
+
.pal .end .grow { flex: 1; }
|
|
3332
|
+
@media (prefers-reduced-motion: reduce) { .panel, .ws .ind, .scrim, .pal { transition: none; animation: none; } }
|
|
3333
|
+
.spacer { flex: 1; }
|
|
3334
|
+
button, select, input { font: inherit; color: inherit; }
|
|
3335
|
+
button { background: none; border: 1px solid transparent; border-radius: 6px; padding: 2px 8px; cursor: pointer; }
|
|
3336
|
+
button:hover { background: var(--hover); }
|
|
3337
|
+
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
|
|
3338
|
+
.pal input:focus-visible { outline: none; }
|
|
3339
|
+
button.tool { display: inline-flex; align-items: center; gap: 6px; border-color: var(--line); background: var(--surface); }
|
|
3340
|
+
button.tool .icon { color: var(--dim); flex: none; }
|
|
3341
|
+
button.tool:hover .icon { color: var(--text); }
|
|
3342
|
+
button.tool.only { padding: 3px 5px; }
|
|
3343
|
+
.link { display: inline-flex; align-items: center; gap: 4px; }
|
|
3344
|
+
.link .icon { opacity: 0.7; }
|
|
3345
|
+
button.tool[aria-pressed="true"] { border-color: var(--accent); background: #ee7a3e22; color: #ffb48a; }
|
|
3346
|
+
select, input[type="search"] { background: var(--raised); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; }
|
|
3347
|
+
.icon { flex: none; }
|
|
3348
|
+
.code { margin: 6px 0 10px; border: 1px solid var(--line); border-radius: 8px; background: #0d1117; overflow: auto; }
|
|
3349
|
+
.code .twinkleplop { margin: 0; padding: 8px 0; font: 12px/1.6 var(--mono); background: none; white-space: normal; }
|
|
3350
|
+
.code .l { display: block; padding: 0 12px 0 0; white-space: pre; min-height: 1.6em; }
|
|
3351
|
+
.code .ln { display: inline-block; width: 44px; padding-right: 12px; text-align: right; color: var(--faint); user-select: none; }
|
|
3352
|
+
.code .l.error-line { background: #e5484d24; }
|
|
3353
|
+
.code .l.error-line .ln { color: var(--red); }
|
|
3354
|
+
.code .error-mark { text-decoration: wavy underline #e5484d; text-underline-offset: 3px; }
|
|
3355
|
+
.code pre.plain { margin: 0; padding: 8px 12px; font: 12px/1.6 var(--mono); white-space: pre; }
|
|
3356
|
+
.frames { display: flex; flex-direction: column; gap: 1px; }
|
|
3357
|
+
.frame { display: flex; gap: 10px; width: 100%; text-align: left; padding: 3px 8px; border-radius: 5px; font: 11.5px var(--mono); }
|
|
3358
|
+
.frame .fn { color: var(--text); white-space: nowrap; }
|
|
3359
|
+
.frame .where { color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
3360
|
+
.frame.library .fn, .frame.library .where { color: var(--faint); }
|
|
3361
|
+
.frame[aria-current="true"] { background: #ee7a3e14; box-shadow: 0 0 0 1px #ee7a3e40; }
|
|
3362
|
+
.frame[aria-current="true"] .fn { color: #ffb48a; }
|
|
3363
|
+
.body { flex: 1; overflow: auto; padding: 12px 14px; min-width: 0; min-height: 0; }
|
|
3364
|
+
.split { display: flex; height: calc(100% + 24px); margin: -12px -14px; }
|
|
3365
|
+
.split > .list { width: 280px; flex: none; overflow: auto; border-right: 1px solid var(--line); padding: 8px; display: flex; flex-direction: column; gap: 1px; }
|
|
3366
|
+
.split > .list input { margin-bottom: 6px; }
|
|
3367
|
+
.split > .detail { flex: 1; overflow: auto; padding: 12px 14px; min-width: 0; }
|
|
3368
|
+
h2 { margin: 0 0 8px; font-size: 13px; font-weight: 600; }
|
|
3369
|
+
h3 { margin: 14px 0 6px; font-size: 11px; font-weight: 600; color: var(--dim); text-transform: uppercase; letter-spacing: 0.05em; }
|
|
3370
|
+
.sub { color: var(--dim); font-weight: 400; }
|
|
3371
|
+
.mono { font-family: var(--mono); }
|
|
3372
|
+
.empty { color: var(--faint); padding: 16px 0; }
|
|
3373
|
+
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
|
|
3374
|
+
.card { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
|
|
3375
|
+
.card .label { color: var(--dim); font-size: 11px; }
|
|
3376
|
+
.card .value { font-size: 18px; font-weight: 650; letter-spacing: -0.02em; }
|
|
3377
|
+
.card .note { color: var(--faint); font-size: 11px; }
|
|
3378
|
+
.rows { width: 100%; border-collapse: collapse; }
|
|
3379
|
+
.rows th { text-align: left; color: var(--faint); font-weight: 500; font-size: 11px; }
|
|
3380
|
+
.rows td, .rows th { padding: 4px 10px 4px 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
|
|
3381
|
+
.rows tr:hover td { background: #ffffff05; }
|
|
3382
|
+
tr.large td { color: var(--yellow); }
|
|
3383
|
+
.pill { display: inline-block; padding: 0 7px; border-radius: 999px; font: 11px/18px var(--mono); background: var(--raised); color: var(--dim); white-space: nowrap; }
|
|
3384
|
+
.pill.blue { background: #7cb7ff1f; color: var(--blue); } .pill.purple { background: #c49bff1f; color: var(--purple); }
|
|
3385
|
+
.pill.green { background: #7fd99a1f; color: var(--green); } .pill.yellow { background: #ffd1661f; color: var(--yellow); }
|
|
3386
|
+
.pill.red { background: #ff7a7a1f; color: var(--red); } .pill.accent { background: #ee7a3e22; color: #ffb48a; }
|
|
3387
|
+
.pill .name { color: #ffc28f; }
|
|
3388
|
+
.link { color: var(--blue); padding: 0; border: 0; font-family: var(--mono); text-align: left; }
|
|
3389
|
+
.link:hover { background: none; text-decoration: underline; }
|
|
3390
|
+
.legend { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; color: var(--dim); }
|
|
3391
|
+
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
|
|
3392
|
+
.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); }
|
|
3393
|
+
.inspect-card .card-head { display: flex; justify-content: space-between; gap: 12px; color: #ffb48a; }
|
|
3394
|
+
.inspect-card .card-component { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
|
|
3395
|
+
.inspect-card .card-pills { display: flex; flex-wrap: wrap; gap: 4px; }
|
|
3396
|
+
.inspect-card .card-hint { margin-top: 2px; padding-top: 6px; border-top: 1px solid #2f2c31; color: #6f6862; font-size: 11px; }
|
|
3397
|
+
.outline { position: fixed; pointer-events: none; border: 2px solid #ee7a3e; background: #ee7a3e22; border-radius: 3px; z-index: 2147483646; }
|
|
3398
|
+
`;
|
|
3399
|
+
//#endregion
|
|
3400
|
+
//#region src/runtime/devtools-panel/split.ts
|
|
3401
|
+
const STYLE = `
|
|
3402
|
+
.split > .handle { position: relative; flex: none; width: 0; z-index: 3; touch-action: none; outline: none; cursor: col-resize; }
|
|
3403
|
+
.split > .handle::before { content: ""; position: absolute; top: 0; bottom: 0; left: -4px; width: 9px; }
|
|
3404
|
+
.split > .handle::after { content: ""; position: absolute; top: 0; bottom: 0; left: -0.5px; width: 1px; background: var(--accent); opacity: 0; transition: opacity .15s, width .15s; border-radius: 2px; }
|
|
3405
|
+
.split > .handle i { position: absolute; top: 50%; left: 0; width: 4px; height: 28px; border-radius: 3px; background: var(--accent); opacity: 0; transform: translate(-50%, -50%); transition: opacity .15s; }
|
|
3406
|
+
.split > .handle:hover::after, .split > .handle.on::after { opacity: .7; }
|
|
3407
|
+
.split > .handle:hover i, .split > .handle.on i { opacity: 1; }
|
|
3408
|
+
.split > .handle:focus-visible::after { opacity: 1; width: 2px; left: -1px; }
|
|
3409
|
+
.split > .handle:focus-visible i { opacity: 1; }
|
|
3410
|
+
.split.stack { flex-direction: column; }
|
|
3411
|
+
.split.stack > .list { width: auto; border-right: 0; border-bottom: 1px solid var(--line); }
|
|
3412
|
+
.split.stack > .handle { width: auto; height: 0; cursor: row-resize; }
|
|
3413
|
+
.split.stack > .handle::before { top: -4px; bottom: auto; left: 0; right: 0; width: auto; height: 9px; }
|
|
3414
|
+
.split.stack > .handle::after { top: -0.5px; bottom: auto; left: 0; right: 0; width: auto; height: 1px; }
|
|
3415
|
+
.split.stack > .handle i { top: 0; left: 50%; width: 28px; height: 4px; transform: translate(-50%, -50%); }
|
|
3416
|
+
.split.stack > .handle:focus-visible::after { width: auto; height: 2px; top: -1px; left: 0; }
|
|
3417
|
+
@media (prefers-reduced-motion: reduce) { .split > .handle::after, .split > .handle i { transition: none; } }
|
|
3418
|
+
`;
|
|
3419
|
+
/** The step of an arrow key, and of an arrow key with Shift, in pixels. */
|
|
3420
|
+
const STEP = 16;
|
|
3421
|
+
const BIG_STEP = 64;
|
|
3422
|
+
function storeName(key, side) {
|
|
3423
|
+
return `brumate:devtools:split:${key}:${side}`;
|
|
3424
|
+
}
|
|
3425
|
+
function readSize(name) {
|
|
3426
|
+
try {
|
|
3427
|
+
const value = Number(localStorage.getItem(name));
|
|
3428
|
+
return Number.isFinite(value) && value > 0 ? value : void 0;
|
|
3429
|
+
} catch {
|
|
3430
|
+
return;
|
|
3431
|
+
}
|
|
3432
|
+
}
|
|
3433
|
+
function writeSize(name, size) {
|
|
3434
|
+
try {
|
|
3435
|
+
if (size === void 0) localStorage.removeItem(name);
|
|
3436
|
+
else localStorage.setItem(name, String(size));
|
|
3437
|
+
} catch {}
|
|
3438
|
+
}
|
|
3439
|
+
/** Makes the `split` of a dock context. The sizes are kept for the side the dock has when it is drawn. */
|
|
3440
|
+
function createSplit(root) {
|
|
3441
|
+
return function split({ key, min, start }) {
|
|
3442
|
+
if (!root.querySelector("style[data-split]")) root.append(element("style", { "data-split": "" }, STYLE));
|
|
3443
|
+
const side = root.querySelector(".panel.right") ? "right" : "bottom";
|
|
3444
|
+
const stacked = side === "right";
|
|
3445
|
+
const name = storeName(key, side);
|
|
3446
|
+
const first = element("div", { class: "list" });
|
|
3447
|
+
const second = element("div", { class: "detail" });
|
|
3448
|
+
const grab = element("i");
|
|
3449
|
+
const handle = element("div", {
|
|
3450
|
+
class: "handle",
|
|
3451
|
+
role: "separator",
|
|
3452
|
+
tabindex: "0",
|
|
3453
|
+
"aria-orientation": stacked ? "horizontal" : "vertical",
|
|
3454
|
+
"aria-label": "Resize the panels",
|
|
3455
|
+
title: "Drag, or use the arrow keys. Double-click to reset."
|
|
3456
|
+
}, grab);
|
|
3457
|
+
const box = element("div", { class: stacked ? "split stack" : "split" }, first, handle, second);
|
|
3458
|
+
const [low, high] = stacked ? ["minHeight", "maxHeight"] : ["minWidth", "maxWidth"];
|
|
3459
|
+
first.style[low] = `${min[0]}px`;
|
|
3460
|
+
first.style[high] = `calc(100% - ${min[1]}px)`;
|
|
3461
|
+
second.style[low] = `${min[1]}px`;
|
|
3462
|
+
if (stacked) first.style.width = "auto";
|
|
3463
|
+
function most() {
|
|
3464
|
+
const total = stacked ? box.clientHeight : box.clientWidth;
|
|
3465
|
+
return total > 0 ? Math.max(min[0], total - min[1]) : Infinity;
|
|
3466
|
+
}
|
|
3467
|
+
function clamp(size) {
|
|
3468
|
+
return Math.round(Math.min(most(), Math.max(min[0], size)));
|
|
3469
|
+
}
|
|
3470
|
+
let size = clamp(readSize(name) ?? start);
|
|
3471
|
+
function apply(next) {
|
|
3472
|
+
size = clamp(next);
|
|
3473
|
+
first.style[stacked ? "height" : "width"] = `${size}px`;
|
|
3474
|
+
handle.setAttribute("aria-valuenow", String(size));
|
|
3475
|
+
handle.setAttribute("aria-valuemin", String(min[0]));
|
|
3476
|
+
if (most() !== Infinity) handle.setAttribute("aria-valuemax", String(most()));
|
|
3477
|
+
}
|
|
3478
|
+
apply(size);
|
|
3479
|
+
if (typeof ResizeObserver === "function") new ResizeObserver(() => apply(size)).observe(box);
|
|
3480
|
+
let from;
|
|
3481
|
+
function end(event) {
|
|
3482
|
+
if (!from) return;
|
|
3483
|
+
from = void 0;
|
|
3484
|
+
handle.classList.remove("on");
|
|
3485
|
+
if (handle.hasPointerCapture(event.pointerId)) handle.releasePointerCapture(event.pointerId);
|
|
3486
|
+
writeSize(name, size);
|
|
3487
|
+
}
|
|
3488
|
+
handle.addEventListener("pointerdown", (event) => {
|
|
3489
|
+
if (event.button !== 0) return;
|
|
3490
|
+
event.preventDefault();
|
|
3491
|
+
handle.setPointerCapture(event.pointerId);
|
|
3492
|
+
handle.focus();
|
|
3493
|
+
handle.classList.add("on");
|
|
3494
|
+
size = clamp(size);
|
|
3495
|
+
from = {
|
|
3496
|
+
x: stacked ? event.clientY : event.clientX,
|
|
3497
|
+
size
|
|
3498
|
+
};
|
|
3499
|
+
});
|
|
3500
|
+
handle.addEventListener("pointermove", (event) => {
|
|
3501
|
+
if (from) apply(from.size + (stacked ? event.clientY : event.clientX) - from.x);
|
|
3502
|
+
});
|
|
3503
|
+
handle.addEventListener("pointerup", end);
|
|
3504
|
+
handle.addEventListener("pointercancel", end);
|
|
3505
|
+
handle.addEventListener("dblclick", () => {
|
|
3506
|
+
apply(start);
|
|
3507
|
+
writeSize(name, void 0);
|
|
3508
|
+
});
|
|
3509
|
+
handle.addEventListener("keydown", (event) => {
|
|
3510
|
+
const step = event.shiftKey ? BIG_STEP : STEP;
|
|
3511
|
+
size = clamp(size);
|
|
3512
|
+
let next;
|
|
3513
|
+
if (event.key === (stacked ? "ArrowDown" : "ArrowRight")) next = size + step;
|
|
3514
|
+
else if (event.key === (stacked ? "ArrowUp" : "ArrowLeft")) next = size - step;
|
|
3515
|
+
else if (event.key === "Home") next = min[0];
|
|
3516
|
+
else if (event.key === "End") next = most();
|
|
3517
|
+
else return;
|
|
3518
|
+
event.preventDefault();
|
|
3519
|
+
apply(next === Infinity ? size : next);
|
|
3520
|
+
writeSize(name, size);
|
|
3521
|
+
});
|
|
3522
|
+
return {
|
|
3523
|
+
box,
|
|
3524
|
+
first,
|
|
3525
|
+
second
|
|
3526
|
+
};
|
|
3527
|
+
};
|
|
3528
|
+
}
|
|
3529
|
+
//#endregion
|
|
3530
|
+
//#region src/runtime/devtools-panel.ts
|
|
3531
|
+
/** The workspaces, in the order of the nav. */
|
|
3532
|
+
const WORKSPACES = [
|
|
3533
|
+
inspect,
|
|
3534
|
+
activity,
|
|
3535
|
+
issues,
|
|
3536
|
+
page
|
|
3537
|
+
];
|
|
3538
|
+
/** The workspace with an ID. */
|
|
3539
|
+
function findWorkspaceById(id) {
|
|
3540
|
+
for (const workspace of WORKSPACES) if (workspace.id === id) return workspace;
|
|
3541
|
+
}
|
|
3542
|
+
/** The workspace that holds a tab. */
|
|
3543
|
+
function findWorkspace(tab) {
|
|
3544
|
+
for (const workspace of WORKSPACES) if (tab in workspace.tabs) return workspace;
|
|
3545
|
+
return WORKSPACES[0];
|
|
3546
|
+
}
|
|
3547
|
+
/** The state of the open panel, or nothing when it is closed. */
|
|
3548
|
+
let docked;
|
|
3549
|
+
/** What closes the open dock, or reopens it while it slides out. */
|
|
3550
|
+
let leave;
|
|
3551
|
+
/** True while the dock slides out. */
|
|
3552
|
+
let closing = false;
|
|
3553
|
+
/** Opens the dock on a tab, or switches to it when the dock is open. Without a tab, it opens on the last workspace. */
|
|
3554
|
+
function openPanel(root, state, tab) {
|
|
3555
|
+
if (docked?.panel) {
|
|
3556
|
+
if (closing) leave?.reopen();
|
|
3557
|
+
if (tab) docked.showTab?.(tab);
|
|
3558
|
+
} else togglePanel(root, state, tab);
|
|
3559
|
+
}
|
|
3560
|
+
/** The first tab of a workspace, which the nav opens it on. */
|
|
3561
|
+
function defaultTab(workspace) {
|
|
3562
|
+
return Object.keys(workspace.tabs)[0];
|
|
3563
|
+
}
|
|
3564
|
+
/** True on macOS, where Ctrl+K is not the key of the search. */
|
|
3565
|
+
function isMac() {
|
|
3566
|
+
return /Mac|iPhone|iPad/.test(navigator.platform);
|
|
3567
|
+
}
|
|
3568
|
+
/** Keeps a size between its least and its greatest. */
|
|
3569
|
+
function clamp(size, min, max) {
|
|
3570
|
+
return Math.min(Math.max(size, min), max);
|
|
3571
|
+
}
|
|
3572
|
+
/** Opens the dock, or closes it when it is open. */
|
|
3573
|
+
function togglePanel(root, state, initial) {
|
|
3574
|
+
const opener = root.querySelector("button.open");
|
|
3575
|
+
if (docked?.panel) {
|
|
3576
|
+
if (closing) leave?.reopen();
|
|
3577
|
+
else leave?.close();
|
|
3578
|
+
return;
|
|
3579
|
+
}
|
|
3580
|
+
const remembered = findWorkspaceById(readPref("workspace")) ?? WORKSPACES[0];
|
|
3581
|
+
const shell = createShell(initial ?? defaultTab(remembered));
|
|
3582
|
+
const chrome = createChrome(state, WORKSPACES);
|
|
3583
|
+
const { panel, body, pick } = chrome;
|
|
3584
|
+
shell.panel = panel;
|
|
3585
|
+
panel.prepend(element("style", {}, STYLE$1));
|
|
3586
|
+
let side = readPref("side") === "right" ? "right" : "bottom";
|
|
3587
|
+
let height = Number(readPref("height")) || 340;
|
|
3588
|
+
let width = Number(readPref("width")) || 480;
|
|
3589
|
+
const errorPage = document.getElementById("brumate-error") !== null;
|
|
3590
|
+
if (errorPage) {
|
|
3591
|
+
side = "bottom";
|
|
3592
|
+
height = window.innerHeight;
|
|
3593
|
+
}
|
|
3594
|
+
const ctx = {
|
|
3595
|
+
root,
|
|
3596
|
+
state,
|
|
3597
|
+
shell,
|
|
3598
|
+
draw,
|
|
3599
|
+
select,
|
|
3600
|
+
split: createSplit(root),
|
|
3601
|
+
outline,
|
|
3602
|
+
pick: () => pick.click(),
|
|
3603
|
+
drawGraph: (scope, info) => drawGraph(ctx, scope, info),
|
|
3604
|
+
drawCallDetail: (entry) => drawCallDetail(ctx, entry)
|
|
3605
|
+
};
|
|
3606
|
+
function applySize() {
|
|
3607
|
+
panel.style.setProperty("--h", `${height}px`);
|
|
3608
|
+
panel.style.setProperty("--w", `${width}px`);
|
|
3609
|
+
if (errorPage) panel.style.maxHeight = "none";
|
|
3610
|
+
document.documentElement.style.paddingBottom = side === "bottom" ? `${height}px` : "";
|
|
3611
|
+
document.documentElement.style.paddingRight = side === "right" ? `${width}px` : "";
|
|
3612
|
+
}
|
|
3613
|
+
function keepSize() {
|
|
3614
|
+
if (!errorPage) writePref("height", String(Math.round(height)));
|
|
3615
|
+
writePref("width", String(Math.round(width)));
|
|
3616
|
+
}
|
|
3617
|
+
function moveEdge(clientX, clientY) {
|
|
3618
|
+
if (side === "bottom") height = clamp(window.innerHeight - clientY, LIMITS.height.min, window.innerHeight * LIMITS.height.share);
|
|
3619
|
+
else width = clamp(window.innerWidth - clientX, LIMITS.width.min, window.innerWidth * LIMITS.width.share);
|
|
3620
|
+
applySize();
|
|
3621
|
+
}
|
|
3622
|
+
docked = shell;
|
|
3623
|
+
applySide(chrome, side);
|
|
3624
|
+
applySize();
|
|
3625
|
+
drawEdge();
|
|
3626
|
+
panel.classList.add("closed");
|
|
3627
|
+
root.append(panel);
|
|
3628
|
+
panel.offsetHeight;
|
|
3629
|
+
panel.classList.remove("closed");
|
|
3630
|
+
if (opener) opener.hidden = true;
|
|
3631
|
+
state.resize = (clientY) => {
|
|
3632
|
+
if (side === "bottom") moveEdge(0, clientY);
|
|
3633
|
+
};
|
|
3634
|
+
state.resized = () => {
|
|
3635
|
+
keepSize();
|
|
3636
|
+
ctx.draw();
|
|
3637
|
+
};
|
|
3638
|
+
let endDrag;
|
|
3639
|
+
chrome.edge.addEventListener("pointerdown", (event) => {
|
|
3640
|
+
event.preventDefault();
|
|
3641
|
+
endDrag?.();
|
|
3642
|
+
panel.classList.add("dragging");
|
|
3643
|
+
function move(next) {
|
|
3644
|
+
moveEdge(next.clientX, next.clientY);
|
|
3645
|
+
}
|
|
3646
|
+
function up() {
|
|
3647
|
+
endDrag?.();
|
|
3648
|
+
state.resized?.();
|
|
3649
|
+
}
|
|
3650
|
+
endDrag = () => {
|
|
3651
|
+
window.removeEventListener("pointermove", move);
|
|
3652
|
+
window.removeEventListener("pointerup", up);
|
|
3653
|
+
panel.classList.remove("dragging");
|
|
3654
|
+
endDrag = void 0;
|
|
3655
|
+
};
|
|
3656
|
+
window.addEventListener("pointermove", move);
|
|
3657
|
+
window.addEventListener("pointerup", up);
|
|
3658
|
+
});
|
|
3659
|
+
chrome.edge.addEventListener("keydown", (event) => {
|
|
3660
|
+
const grow = side === "bottom" ? "ArrowUp" : "ArrowLeft";
|
|
3661
|
+
const shrink = side === "bottom" ? "ArrowDown" : "ArrowRight";
|
|
3662
|
+
if (event.key !== grow && event.key !== shrink) return;
|
|
3663
|
+
event.preventDefault();
|
|
3664
|
+
const step = (event.shiftKey ? 64 : 16) * (event.key === grow ? 1 : -1);
|
|
3665
|
+
if (side === "bottom") moveEdge(0, window.innerHeight - (height + step));
|
|
3666
|
+
else moveEdge(window.innerWidth - (width + step), 0);
|
|
3667
|
+
drawEdge();
|
|
3668
|
+
state.resized?.();
|
|
3669
|
+
});
|
|
3670
|
+
function drawEdge() {
|
|
3671
|
+
chrome.edge.setAttribute("aria-orientation", side === "bottom" ? "horizontal" : "vertical");
|
|
3672
|
+
chrome.edge.setAttribute("aria-valuenow", String(Math.round(side === "bottom" ? height : width)));
|
|
3673
|
+
}
|
|
3674
|
+
chrome.side.addEventListener("click", () => {
|
|
3675
|
+
side = side === "bottom" ? "right" : "bottom";
|
|
3676
|
+
writePref("side", side);
|
|
3677
|
+
applySide(chrome, side);
|
|
3678
|
+
applySize();
|
|
3679
|
+
drawEdge();
|
|
3680
|
+
ctx.draw();
|
|
3681
|
+
});
|
|
3682
|
+
chrome.close.addEventListener("click", () => togglePanel(root, state));
|
|
3683
|
+
chrome.updates.addEventListener("click", () => {
|
|
3684
|
+
state.setFlash?.(!state.flash);
|
|
3685
|
+
chrome.updates.setAttribute("aria-pressed", String(state.flash));
|
|
3686
|
+
});
|
|
3687
|
+
for (const [id, button] of chrome.tabs) button.addEventListener("click", () => {
|
|
3688
|
+
if (findWorkspace(shell.tab).id !== id) select(id);
|
|
3689
|
+
});
|
|
3690
|
+
chrome.tabs.get(WORKSPACES[0].id).parentElement.addEventListener("keydown", (event) => {
|
|
3691
|
+
const step = {
|
|
3692
|
+
ArrowRight: 1,
|
|
3693
|
+
ArrowLeft: -1
|
|
3694
|
+
}[event.key];
|
|
3695
|
+
if (!step) return;
|
|
3696
|
+
event.preventDefault();
|
|
3697
|
+
let at = 0;
|
|
3698
|
+
for (const [index, item] of WORKSPACES.entries()) if (item === findWorkspace(shell.tab)) at = index;
|
|
3699
|
+
const next = WORKSPACES[(at + step + WORKSPACES.length) % WORKSPACES.length];
|
|
3700
|
+
select(next.id);
|
|
3701
|
+
chrome.tabs.get(next.id).focus();
|
|
3702
|
+
});
|
|
3703
|
+
window.addEventListener("resize", placeNav);
|
|
3704
|
+
function placeNav() {
|
|
3705
|
+
placeIndicator(chrome, findWorkspace(shell.tab).id);
|
|
3706
|
+
}
|
|
3707
|
+
const search = createSearch(ctx, listActions);
|
|
3708
|
+
chrome.search.addEventListener("click", () => search.open());
|
|
3709
|
+
function listActions() {
|
|
3710
|
+
const items = [
|
|
3711
|
+
{
|
|
3712
|
+
group: "Actions",
|
|
3713
|
+
label: "Pick an element",
|
|
3714
|
+
hint: "",
|
|
3715
|
+
run: () => ctx.pick()
|
|
3716
|
+
},
|
|
3717
|
+
{
|
|
3718
|
+
group: "Actions",
|
|
3719
|
+
label: side === "right" ? "Dock to the bottom" : "Dock to the right",
|
|
3720
|
+
hint: "",
|
|
3721
|
+
run: () => chrome.side.click()
|
|
3722
|
+
},
|
|
3723
|
+
{
|
|
3724
|
+
group: "Actions",
|
|
3725
|
+
label: state.flash ? "Stop outlining updates" : "Outline updates",
|
|
3726
|
+
hint: "",
|
|
3727
|
+
run: () => chrome.updates.click()
|
|
3728
|
+
}
|
|
3729
|
+
];
|
|
3730
|
+
for (const item of WORKSPACES) items.push({
|
|
3731
|
+
group: "Actions",
|
|
3732
|
+
label: `Open ${item.label}`,
|
|
3733
|
+
hint: "",
|
|
3734
|
+
run: () => select(item.id)
|
|
3735
|
+
});
|
|
3736
|
+
return items;
|
|
3737
|
+
}
|
|
3738
|
+
function onKey(event) {
|
|
3739
|
+
const target = event.composedPath()[0];
|
|
3740
|
+
const typing = target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement || target instanceof HTMLElement && target.isContentEditable;
|
|
3741
|
+
if (event.key.toLowerCase() === "k" && !event.altKey) {
|
|
3742
|
+
const ctrl = event.ctrlKey && !isMac() && !(typing && !root.contains(target));
|
|
3743
|
+
if (event.metaKey || ctrl) {
|
|
3744
|
+
event.preventDefault();
|
|
3745
|
+
search.open();
|
|
3746
|
+
return;
|
|
3747
|
+
}
|
|
3748
|
+
}
|
|
3749
|
+
if (event.key !== "Escape" || event.defaultPrevented || search.isOpen() || typing) return;
|
|
3750
|
+
if (closing) return;
|
|
3751
|
+
togglePanel(root, state);
|
|
3752
|
+
}
|
|
3753
|
+
window.addEventListener("keydown", onKey);
|
|
3754
|
+
const clock = setInterval(() => {
|
|
3755
|
+
chrome.up.textContent = `${Math.round(performance.now() / 1e3)} s`;
|
|
3756
|
+
}, 1e3);
|
|
3757
|
+
let timer;
|
|
3758
|
+
function finishClose() {
|
|
3759
|
+
clearTimeout(timer);
|
|
3760
|
+
panel.removeEventListener("transitionend", onSlid);
|
|
3761
|
+
window.removeEventListener("keydown", onKey);
|
|
3762
|
+
window.removeEventListener("resize", placeNav);
|
|
3763
|
+
clearInterval(clock);
|
|
3764
|
+
endDrag?.();
|
|
3765
|
+
search.close();
|
|
3766
|
+
shell.endPick?.();
|
|
3767
|
+
shell.endPick = void 0;
|
|
3768
|
+
panel.remove();
|
|
3769
|
+
shell.panel = void 0;
|
|
3770
|
+
shell.showTab = void 0;
|
|
3771
|
+
docked = void 0;
|
|
3772
|
+
leave = void 0;
|
|
3773
|
+
closing = false;
|
|
3774
|
+
state.changed = void 0;
|
|
3775
|
+
document.documentElement.style.removeProperty("padding-bottom");
|
|
3776
|
+
document.documentElement.style.removeProperty("padding-right");
|
|
3777
|
+
state.resize = void 0;
|
|
3778
|
+
state.resized = void 0;
|
|
3779
|
+
}
|
|
3780
|
+
function onSlid(event) {
|
|
3781
|
+
if (event.target === panel && event.propertyName === "transform") finishClose();
|
|
3782
|
+
}
|
|
3783
|
+
leave = {
|
|
3784
|
+
close() {
|
|
3785
|
+
shell.endPick?.();
|
|
3786
|
+
search.close();
|
|
3787
|
+
endDrag?.();
|
|
3788
|
+
closing = true;
|
|
3789
|
+
if (opener) {
|
|
3790
|
+
opener.hidden = false;
|
|
3791
|
+
opener.focus();
|
|
3792
|
+
}
|
|
3793
|
+
if (!(Number.parseFloat(getComputedStyle(panel).transitionDuration) > 0)) {
|
|
3794
|
+
finishClose();
|
|
3795
|
+
return;
|
|
3796
|
+
}
|
|
3797
|
+
panel.classList.add("closed");
|
|
3798
|
+
panel.addEventListener("transitionend", onSlid);
|
|
3799
|
+
timer = setTimeout(finishClose, 400);
|
|
3800
|
+
},
|
|
3801
|
+
reopen() {
|
|
3802
|
+
closing = false;
|
|
3803
|
+
clearTimeout(timer);
|
|
3804
|
+
panel.removeEventListener("transitionend", onSlid);
|
|
3805
|
+
panel.classList.remove("closed");
|
|
3806
|
+
if (opener) {
|
|
3807
|
+
const lost = root.activeElement === opener;
|
|
3808
|
+
opener.hidden = true;
|
|
3809
|
+
if (lost) chrome.tabs.get(findWorkspace(shell.tab).id)?.focus();
|
|
3810
|
+
}
|
|
3811
|
+
}
|
|
3812
|
+
};
|
|
3813
|
+
if (!state.scopes) document.dispatchEvent(new Event("brumate:core"));
|
|
3814
|
+
const outlines = [];
|
|
3815
|
+
function outline(scope) {
|
|
3816
|
+
for (const box of outlines.splice(0)) box.remove();
|
|
3817
|
+
if (scope === void 0) return;
|
|
3818
|
+
for (const target of document.querySelectorAll(`[b-b^="${scope}:"]`)) {
|
|
3819
|
+
const rect = target.getBoundingClientRect();
|
|
3820
|
+
const box = element("div", {
|
|
3821
|
+
class: "outline",
|
|
3822
|
+
style: `left:${rect.left}px;top:${rect.top}px;width:${rect.width}px;height:${rect.height}px`
|
|
3823
|
+
});
|
|
3824
|
+
root.append(box);
|
|
3825
|
+
outlines.push(box);
|
|
3826
|
+
}
|
|
3827
|
+
}
|
|
3828
|
+
function onPick(event) {
|
|
3829
|
+
const clicked = event.target;
|
|
3830
|
+
if (!clicked?.closest || event.composedPath().includes(shell.panel)) return;
|
|
3831
|
+
event.preventDefault();
|
|
3832
|
+
event.stopImmediatePropagation();
|
|
3833
|
+
stopPicking();
|
|
3834
|
+
shell.picked = clicked;
|
|
3835
|
+
const id = clicked.closest("[b-b]")?.getAttribute("b-b").split(":")[0];
|
|
3836
|
+
if (id !== void 0) {
|
|
3837
|
+
shell.selectedScope = /^-?\d+$/.test(id) ? Number(id) : id;
|
|
3838
|
+
const scope = state.scopes?.get(shell.selectedScope);
|
|
3839
|
+
shell.selected = scope ? findRootScope(scope).m : shell.selected;
|
|
3840
|
+
}
|
|
3841
|
+
shell.tab = "elements";
|
|
3842
|
+
ctx.draw();
|
|
3843
|
+
}
|
|
3844
|
+
const inspectCard = element("div", {
|
|
3845
|
+
class: "inspect-card",
|
|
3846
|
+
role: "tooltip"
|
|
3847
|
+
});
|
|
3848
|
+
const hoverBox = element("div", { class: "outline" });
|
|
3849
|
+
let hovered;
|
|
3850
|
+
let hoverToken = 0;
|
|
3851
|
+
function onHover(event) {
|
|
3852
|
+
const target = event.target;
|
|
3853
|
+
if (!target?.closest || event.composedPath().includes(shell.panel) || target === hovered) return;
|
|
3854
|
+
hovered = target;
|
|
3855
|
+
showCard(target);
|
|
3856
|
+
}
|
|
3857
|
+
async function showCard(target) {
|
|
3858
|
+
const token = ++hoverToken;
|
|
3859
|
+
const rect = target.getBoundingClientRect();
|
|
3860
|
+
hoverBox.style.cssText = `left:${rect.left}px;top:${rect.top}px;width:${rect.width}px;height:${rect.height}px`;
|
|
3861
|
+
root.append(hoverBox, inspectCard);
|
|
3862
|
+
const tag = target.tagName.toLowerCase();
|
|
3863
|
+
let classes = "";
|
|
3864
|
+
for (const name of [...target.classList].slice(0, 2)) classes += `.${name}`;
|
|
3865
|
+
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)}`))];
|
|
3866
|
+
const anchored = target.closest("[b-b]");
|
|
3867
|
+
const [id = "", anchorText = "0"] = anchored?.getAttribute("b-b").split(":") ?? [];
|
|
3868
|
+
const scope = anchored ? findScope(state, id) : void 0;
|
|
3869
|
+
if (scope) {
|
|
3870
|
+
const { info, component: owner, place } = await findAnchor(state, scope, Number(anchorText));
|
|
3871
|
+
if (token !== hoverToken) return;
|
|
3872
|
+
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"}`}`));
|
|
3873
|
+
const handled = target.closest("[b-on]");
|
|
3874
|
+
if (handled && anchored.contains(handled)) {
|
|
3875
|
+
const handlers = element("div", { class: "card-pills" });
|
|
3876
|
+
for (const raw of (handled.getAttribute("b-on") ?? "").split(/\s+/)) {
|
|
3877
|
+
if (!raw) continue;
|
|
3878
|
+
const [head] = raw.split("=");
|
|
3879
|
+
handlers.append(pill(head));
|
|
3880
|
+
}
|
|
3881
|
+
rows.push(handlers);
|
|
3882
|
+
}
|
|
3883
|
+
if (place && place.reads.length > 0) rows.push(element("div", { class: "card-pills" }, ...drawReads(scope, place.reads.slice(0, 4))));
|
|
3884
|
+
} else rows.push(element("div", { class: "sub" }, "Nothing in the browser updates this element."));
|
|
3885
|
+
rows.push(element("div", { class: "card-hint" }, "Click to see it in Inspect · Esc to stop"));
|
|
3886
|
+
inspectCard.replaceChildren(...rows);
|
|
3887
|
+
const cardHeight = inspectCard.offsetHeight;
|
|
3888
|
+
const top = rect.bottom + 8 + cardHeight < window.innerHeight ? rect.bottom + 8 : Math.max(8, rect.top - 8 - cardHeight);
|
|
3889
|
+
const left = Math.min(Math.max(8, rect.left), window.innerWidth - inspectCard.offsetWidth - 8);
|
|
3890
|
+
inspectCard.style.cssText = `top:${top}px;left:${left}px`;
|
|
3891
|
+
}
|
|
3892
|
+
function onEscape(event) {
|
|
3893
|
+
if (event.key === "Escape") {
|
|
3894
|
+
event.preventDefault();
|
|
3895
|
+
event.stopPropagation();
|
|
3896
|
+
stopPicking();
|
|
3897
|
+
}
|
|
3898
|
+
}
|
|
3899
|
+
shell.endPick = () => stopPicking();
|
|
3900
|
+
function stopPicking() {
|
|
3901
|
+
pick.setAttribute("aria-pressed", "false");
|
|
3902
|
+
window.removeEventListener("click", onPick, true);
|
|
3903
|
+
window.removeEventListener("pointermove", onHover, true);
|
|
3904
|
+
window.removeEventListener("keydown", onEscape, true);
|
|
3905
|
+
document.documentElement.style.cursor = "";
|
|
3906
|
+
hovered = void 0;
|
|
3907
|
+
hoverToken++;
|
|
3908
|
+
hoverBox.remove();
|
|
3909
|
+
inspectCard.remove();
|
|
3910
|
+
}
|
|
3911
|
+
pick.addEventListener("click", () => {
|
|
3912
|
+
if (pick.getAttribute("aria-pressed") === "true") {
|
|
3913
|
+
stopPicking();
|
|
3914
|
+
return;
|
|
3915
|
+
}
|
|
3916
|
+
pick.setAttribute("aria-pressed", "true");
|
|
3917
|
+
document.documentElement.style.cursor = "crosshair";
|
|
3918
|
+
window.addEventListener("click", onPick, true);
|
|
3919
|
+
window.addEventListener("pointermove", onHover, true);
|
|
3920
|
+
window.addEventListener("keydown", onEscape, true);
|
|
3921
|
+
});
|
|
3922
|
+
/** Opens a workspace. The target is a tab of the workspace, for the one that has several. */
|
|
3923
|
+
function select(id, target) {
|
|
3924
|
+
const workspace = WORKSPACES.find((item) => item.id === id);
|
|
3925
|
+
shell.tab = target ?? defaultTab(workspace);
|
|
3926
|
+
draw();
|
|
3927
|
+
}
|
|
3928
|
+
let shown;
|
|
3929
|
+
/** The header and the counts of the nav. */
|
|
3930
|
+
function drawHeader() {
|
|
3931
|
+
const current = findWorkspace(shell.tab).id;
|
|
3932
|
+
drawChrome(chrome, state, current, shell.paused);
|
|
3933
|
+
if (current !== shown) {
|
|
3934
|
+
shown = current;
|
|
3935
|
+
writePref("workspace", current);
|
|
3936
|
+
}
|
|
3937
|
+
}
|
|
3938
|
+
let queued = false;
|
|
3939
|
+
function draw() {
|
|
3940
|
+
drawHeader();
|
|
3941
|
+
const drawing = shell.tab;
|
|
3942
|
+
const drawn = findWorkspace(drawing).draw(ctx, body);
|
|
3943
|
+
function settle() {
|
|
3944
|
+
if (findWorkspace(shell.tab).id === "inspect") state.written.clear();
|
|
3945
|
+
}
|
|
3946
|
+
if (!drawn) {
|
|
3947
|
+
settle();
|
|
3948
|
+
return;
|
|
3949
|
+
}
|
|
3950
|
+
drawn.then(() => {
|
|
3951
|
+
if (shell.tab !== drawing) {
|
|
3952
|
+
draw();
|
|
3953
|
+
return;
|
|
3954
|
+
}
|
|
3955
|
+
drawHeader();
|
|
3956
|
+
settle();
|
|
3957
|
+
});
|
|
3958
|
+
}
|
|
3959
|
+
state.changed = () => {
|
|
3960
|
+
const typing = root.activeElement?.matches?.("input[type=\"search\"]");
|
|
3961
|
+
if (!queued && !shell.editing && !typing && !(shell.paused && shell.tab === "log")) {
|
|
3962
|
+
queued = true;
|
|
3963
|
+
requestAnimationFrame(() => {
|
|
3964
|
+
queued = false;
|
|
3965
|
+
if (shell.panel) draw();
|
|
3966
|
+
});
|
|
3967
|
+
}
|
|
3968
|
+
};
|
|
3969
|
+
shell.showTab = (next) => {
|
|
3970
|
+
shell.tab = next;
|
|
3971
|
+
draw();
|
|
3972
|
+
};
|
|
3973
|
+
draw();
|
|
3974
|
+
}
|
|
3975
|
+
//#endregion
|
|
3976
|
+
export { layoutGraph, openPanel, togglePanel };
|
|
3977
|
+
|
|
3978
|
+
//# sourceMappingURL=devtools-panel-B1nF1KB7.js.map
|