brumate 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +2 -2
  2. package/check.d.ts +49 -0
  3. package/dist/{boot-D-IdPy7B.d.ts → boot-DLlRmD9z.d.ts} +11 -10
  4. package/dist/cli.js +275 -15
  5. package/dist/cli.js.map +1 -1
  6. package/dist/client-BvDsC6Qr.js +3463 -0
  7. package/dist/client-BvDsC6Qr.js.map +1 -0
  8. package/dist/client-DBwL2wKQ.d.ts +669 -0
  9. package/dist/{client-routes-JTbGtukf.js → client-routes-BtGpYCef.js} +60 -30
  10. package/dist/client-routes-BtGpYCef.js.map +1 -0
  11. package/dist/{cookies-Av5WFmcf.js → cookies-Cnbf4w-S.js} +15 -7
  12. package/dist/cookies-Cnbf4w-S.js.map +1 -0
  13. package/dist/{defer-D0bo1Gqx.js → defer-CKWZLv2K.js} +8 -4
  14. package/dist/defer-CKWZLv2K.js.map +1 -0
  15. package/dist/devtools-4uTPwR_v.js +597 -0
  16. package/dist/devtools-4uTPwR_v.js.map +1 -0
  17. package/dist/devtools-panel-Be9pxYgv.js +1994 -0
  18. package/dist/devtools-panel-Be9pxYgv.js.map +1 -0
  19. package/dist/events-LgLdp1R7.js +114 -0
  20. package/dist/events-LgLdp1R7.js.map +1 -0
  21. package/dist/features-CHY5Ekku.js +30 -0
  22. package/dist/features-CHY5Ekku.js.map +1 -0
  23. package/dist/files-WW4RlajL.js +506 -0
  24. package/dist/files-WW4RlajL.js.map +1 -0
  25. package/dist/forms-j1xPAR14.d.ts +281 -0
  26. package/dist/forms-nXK7-Lv_.js +440 -0
  27. package/dist/forms-nXK7-Lv_.js.map +1 -0
  28. package/dist/highlight.d.ts +17 -0
  29. package/dist/highlight.js +278 -0
  30. package/dist/highlight.js.map +1 -0
  31. package/dist/html-BtKRyi7g.js +305 -0
  32. package/dist/html-BtKRyi7g.js.map +1 -0
  33. package/dist/html-Bw9Qwu6F.d.ts +107 -0
  34. package/dist/index.d.ts +142 -11
  35. package/dist/index.js +641 -106
  36. package/dist/index.js.map +1 -1
  37. package/dist/{inspect-BJtACnQp.js → inspect-Y6y4uNZp.js} +4333 -681
  38. package/dist/inspect-Y6y4uNZp.js.map +1 -0
  39. package/dist/{loader-B18i3_-T.js → loader-BjKGJzLN.js} +21 -14
  40. package/dist/loader-BjKGJzLN.js.map +1 -0
  41. package/dist/logo-DQ_OYhBi.js +10 -0
  42. package/dist/logo-DQ_OYhBi.js.map +1 -0
  43. package/dist/{navigate-BwuZveDF.js → navigate-CfOr-TRF.js} +130 -24
  44. package/dist/navigate-CfOr-TRF.js.map +1 -0
  45. package/dist/nesting-DA5vJw9X.js +265 -0
  46. package/dist/nesting-DA5vJw9X.js.map +1 -0
  47. package/dist/produce-B7X9ori9.js +402 -0
  48. package/dist/produce-B7X9ori9.js.map +1 -0
  49. package/dist/produce-DIgHBVwL.d.ts +148 -0
  50. package/dist/{rpc-B-Zkn6Ch.js → rpc-Q-XkLwFh.js} +28 -13
  51. package/dist/rpc-Q-XkLwFh.js.map +1 -0
  52. package/dist/runtime/batch.js +9 -7
  53. package/dist/runtime/batch.js.map +1 -1
  54. package/dist/runtime/client.d.ts +4 -4
  55. package/dist/runtime/client.js +4 -4
  56. package/dist/runtime/devtools.d.ts +172 -5
  57. package/dist/runtime/devtools.js +3 -1
  58. package/dist/runtime/env.js +14 -2
  59. package/dist/runtime/env.js.map +1 -1
  60. package/dist/runtime/events.d.ts +38 -1
  61. package/dist/runtime/events.js +1 -1
  62. package/dist/runtime/forms.d.ts +2 -0
  63. package/dist/runtime/forms.js +1 -0
  64. package/dist/runtime/gather.d.ts +25 -0
  65. package/dist/runtime/gather.js +33 -0
  66. package/dist/runtime/gather.js.map +1 -0
  67. package/dist/runtime/hot.d.ts +1 -1
  68. package/dist/runtime/hot.js +5 -2
  69. package/dist/runtime/hot.js.map +1 -1
  70. package/dist/runtime/html.d.ts +2 -2
  71. package/dist/runtime/html.js +1 -1
  72. package/dist/runtime/loader.d.ts +2 -2
  73. package/dist/runtime/loader.js +2 -2
  74. package/dist/runtime/routes.js +4 -1
  75. package/dist/runtime/routes.js.map +1 -1
  76. package/dist/runtime/server.d.ts +5 -4
  77. package/dist/runtime/server.js +5 -5
  78. package/dist/runtime/signals.d.ts +75 -2
  79. package/dist/runtime/signals.js +44 -2
  80. package/dist/runtime/signals.js.map +1 -1
  81. package/dist/runtime/static-loader.d.ts +2 -2
  82. package/dist/runtime/static-loader.js +1 -1
  83. package/dist/runtime/testing.d.ts +18 -3
  84. package/dist/runtime/testing.js +150 -33
  85. package/dist/runtime/testing.js.map +1 -1
  86. package/dist/runtime/values.d.ts +2 -0
  87. package/dist/runtime/values.js +24 -0
  88. package/dist/runtime/values.js.map +1 -0
  89. package/dist/{server-BA9SJ2Vm.d.ts → server-BvPIg9pT.d.ts} +363 -32
  90. package/dist/{server-BqfM95r1.js → server-DjyOVJtJ.js} +1309 -220
  91. package/dist/server-DjyOVJtJ.js.map +1 -0
  92. package/dist/{static-loader-BzE9SRaj.d.ts → static-loader-BGgdp_Y5.d.ts} +2 -2
  93. package/dist/static-loader-BZR17hSw.js +312 -0
  94. package/dist/static-loader-BZR17hSw.js.map +1 -0
  95. package/dist/{stream-JaMHMdBD.js → stream-BP5AVmg5.js} +182 -17
  96. package/dist/stream-BP5AVmg5.js.map +1 -0
  97. package/dist/values-B8C7CLvG.d.ts +63 -0
  98. package/dist/vite.d.ts +20 -20
  99. package/dist/vite.js +2031 -539
  100. package/dist/vite.js.map +1 -1
  101. package/elements.d.ts +951 -0
  102. package/forms/forms.brm.ts +141 -0
  103. package/package.json +41 -3
  104. package/skills/brumate/SKILL.md +58 -0
  105. package/skills/brumate/references/errors.md +2078 -0
  106. package/skills/brumate/references/events.md +117 -0
  107. package/skills/brumate/references/signals.md +61 -0
  108. package/skills/brumate/references/state.md +235 -0
  109. package/skills/brumate/references/syntax.md +250 -0
  110. package/types.d.ts +4 -4
  111. package/dist/client-C0UCNL3J.js +0 -1643
  112. package/dist/client-C0UCNL3J.js.map +0 -1
  113. package/dist/client-MD0ZmcFR.d.ts +0 -354
  114. package/dist/client-routes-JTbGtukf.js.map +0 -1
  115. package/dist/cookies-Av5WFmcf.js.map +0 -1
  116. package/dist/defer-D0bo1Gqx.js.map +0 -1
  117. package/dist/devtools-C50VH8gZ.js +0 -113
  118. package/dist/devtools-C50VH8gZ.js.map +0 -1
  119. package/dist/devtools-panel-AYjfwPhj.js +0 -435
  120. package/dist/devtools-panel-AYjfwPhj.js.map +0 -1
  121. package/dist/events-BKWRqtMg.js +0 -52
  122. package/dist/events-BKWRqtMg.js.map +0 -1
  123. package/dist/files-Bnn1JqHx.js +0 -192
  124. package/dist/files-Bnn1JqHx.js.map +0 -1
  125. package/dist/html-bHZbkK-h.js +0 -170
  126. package/dist/html-bHZbkK-h.js.map +0 -1
  127. package/dist/html-y1q7-t7D.d.ts +0 -60
  128. package/dist/inspect-BJtACnQp.js.map +0 -1
  129. package/dist/loader-B18i3_-T.js.map +0 -1
  130. package/dist/navigate-BwuZveDF.js.map +0 -1
  131. package/dist/produce-CWfJ4byV.js +0 -167
  132. package/dist/produce-CWfJ4byV.js.map +0 -1
  133. package/dist/produce-D4K7qpaL.d.ts +0 -72
  134. package/dist/rpc-B-Zkn6Ch.js.map +0 -1
  135. package/dist/server-BqfM95r1.js.map +0 -1
  136. package/dist/static-loader-DOygOFj5.js +0 -216
  137. package/dist/static-loader-DOygOFj5.js.map +0 -1
  138. package/dist/stream-JaMHMdBD.js.map +0 -1
@@ -0,0 +1,597 @@
1
+ import { t as LOGO } from "./logo-DQ_OYhBi.js";
2
+ //#region src/runtime/devtools.ts
3
+ const DEVTOOLS = Symbol.for("brumate.devtools");
4
+ const MAX_LOG = 300;
5
+ /** The root scope of a scope, whose `m` names its component. */
6
+ function findRootScope(scope) {
7
+ let root = scope;
8
+ while (root.p) root = root.p;
9
+ return root;
10
+ }
11
+ /** A short text for a value in the log. */
12
+ function preview(value) {
13
+ if (typeof value === "string") return JSON.stringify(value.length > 40 ? `${value.slice(0, 40)}…` : value);
14
+ if (typeof value === "function") return "function";
15
+ if (Array.isArray(value)) return `Array(${value.length})`;
16
+ if (value instanceof Element) return `<${value.tagName.toLowerCase()}>`;
17
+ if (value !== null && typeof value === "object") {
18
+ const name = value.constructor?.name;
19
+ return name && name !== "Object" ? name : `{${Object.keys(value).slice(0, 3).join(", ")}}`;
20
+ }
21
+ return String(value);
22
+ }
23
+ /**
24
+ * Reads the blocks of the page from their markers, and updates their state.
25
+ * Returns true when something changed.
26
+ *
27
+ * - `#defer`: a `<template b-defer>`, and `<!--l…-->` around its fallback until its body arrives.
28
+ * - `#loading`: `<!--l…-->` around its fallback until the server streams its body.
29
+ * - `#client`: a `<template b-client>` with a `#k` reference, and a marker that gets `:1` once
30
+ * its body rendered.
31
+ * - `$client`: a `<template b-client>` with a `#c` reference.
32
+ */
33
+ function scanBlocks(state) {
34
+ const now = performance.now();
35
+ let changed = false;
36
+ const open = /* @__PURE__ */ new Map();
37
+ const markers = /* @__PURE__ */ new Map();
38
+ const walker = document.createTreeWalker(document, NodeFilter.SHOW_COMMENT);
39
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
40
+ const data = node.data;
41
+ if (/^l[\d.-]+$/.test(data)) open.set(data.slice(1), node);
42
+ else if (/^b-?[\d.]+:\d+/.test(data)) markers.set(data.slice(1).split(":").slice(0, 2).join(":"), node);
43
+ }
44
+ const seen = /* @__PURE__ */ new Set();
45
+ function update(key, make, next) {
46
+ seen.add(key);
47
+ let block = state.blocks.get(key);
48
+ if (!block) {
49
+ block = make();
50
+ state.blocks.set(key, block);
51
+ changed = true;
52
+ }
53
+ if (block.state === "rendered" || block.state === next) return;
54
+ if (block.state === "loading" && next === "waiting") return;
55
+ block.state = next;
56
+ if (next === "rendered") block.rendered = now;
57
+ changed = true;
58
+ }
59
+ const deferBoundaries = /* @__PURE__ */ new Set();
60
+ for (const template of document.querySelectorAll("template[b-defer]")) {
61
+ const [trigger, boundary] = template.getAttribute("b-defer").split(":");
62
+ deferBoundaries.add(boundary);
63
+ update(`defer:${boundary}`, () => ({
64
+ kind: "defer",
65
+ id: boundary,
66
+ trigger,
67
+ template,
68
+ state: "waiting",
69
+ seen: now
70
+ }), open.has(boundary) ? "waiting" : "rendered");
71
+ }
72
+ for (const boundary of open.keys()) if (!deferBoundaries.has(boundary)) update(`loading:${boundary}`, () => ({
73
+ kind: "loading",
74
+ id: boundary,
75
+ state: "streaming",
76
+ seen: now
77
+ }), "streaming");
78
+ for (const template of document.querySelectorAll("template[b-client]")) {
79
+ const [trigger, ref] = template.getAttribute("b-client").split("=");
80
+ const id = template.getAttribute("b-b") ?? "";
81
+ const block = /#k\d+$/.test(ref);
82
+ const marker = markers.get(id);
83
+ update(`client:${id}`, () => ({
84
+ kind: block ? "client" : "$client",
85
+ id,
86
+ trigger,
87
+ ref,
88
+ template,
89
+ state: "waiting",
90
+ seen: now
91
+ }), (block ? marker && marker.data.split(":").length > 2 : state.blocks.get(`client:${id}`)?.fired) ? "rendered" : "waiting");
92
+ }
93
+ for (const [key, block] of state.blocks) {
94
+ if (seen.has(key)) continue;
95
+ if (block.kind === "loading") {
96
+ if (block.state === "streaming") {
97
+ block.state = "rendered";
98
+ block.rendered = now;
99
+ changed = true;
100
+ }
101
+ } else if (!block.template?.isConnected) {
102
+ state.blocks.delete(key);
103
+ changed = true;
104
+ }
105
+ }
106
+ return changed;
107
+ }
108
+ /**
109
+ * Adds an error to the Errors tab. An error of the server or of Vite opens
110
+ * the panel on it, as Vite's overlay would. An error of the browser only
111
+ * counts on the button.
112
+ */
113
+ function reportError(state, payload, source) {
114
+ const file = payload.loc?.file ?? payload.id;
115
+ const entry = {
116
+ time: performance.now(),
117
+ source: source === "server" && payload.plugin ? "compile" : source,
118
+ message: payload.message,
119
+ ...payload.stack ? { stack: payload.stack } : {},
120
+ ...payload.frame ? { frame: payload.frame } : {},
121
+ ...payload.plugin ? { plugin: payload.plugin } : {},
122
+ ...payload.loc && file ? { loc: {
123
+ file,
124
+ line: payload.loc.line,
125
+ column: payload.loc.column
126
+ } } : {}
127
+ };
128
+ const last = state.errors.at(-1);
129
+ if (last?.message !== entry.message || last.stack !== entry.stack) {
130
+ state.errors.push(entry);
131
+ if (state.errors.length > 50) state.errors.shift();
132
+ }
133
+ state.errorCount?.();
134
+ state.changed?.();
135
+ if (source !== "browser") state.open?.("errors");
136
+ }
137
+ /** The code of the panel, which loads when it opens. */
138
+ function panelModule() {
139
+ return import("./devtools-panel-Be9pxYgv.js");
140
+ }
141
+ /** Where the choice to outline changed elements is kept. */
142
+ const FLASH_KEY = "brumate:devtools:flash";
143
+ /** How long an outline shows. */
144
+ const FLASH_MS = 700;
145
+ /** The most outlines that one frame draws, so a big change does not stall the page. */
146
+ const MAX_FLASHES = 200;
147
+ /** The class of an outline, by how many times the element changed in the last second. */
148
+ function heatClass(count) {
149
+ if (count >= 5) return "hot";
150
+ return count >= 2 ? "warm" : "";
151
+ }
152
+ /**
153
+ * Outlines the elements that change, as an update writes them: green for an
154
+ * element that changes now and then, yellow and red for one that changes
155
+ * often. A MutationObserver sees every change of the page, so it needs no
156
+ * hook of the core. The outlines are drawn in the shadow root, so the page
157
+ * itself does not change.
158
+ */
159
+ function installFlash(state, root, host) {
160
+ const layer = document.createElement("div");
161
+ layer.className = "flashes";
162
+ root.append(layer);
163
+ const heat = /* @__PURE__ */ new WeakMap();
164
+ const pending = /* @__PURE__ */ new Set();
165
+ let frame = 0;
166
+ function draw() {
167
+ frame = 0;
168
+ let drawn = 0;
169
+ for (const target of pending) {
170
+ if (drawn >= MAX_FLASHES) break;
171
+ const rect = target.getBoundingClientRect();
172
+ if (rect.width === 0 && rect.height === 0) continue;
173
+ const now = performance.now();
174
+ const last = heat.get(target);
175
+ const count = last && now - last.time < 1e3 ? last.count + 1 : 1;
176
+ heat.set(target, {
177
+ count,
178
+ time: now
179
+ });
180
+ const box = document.createElement("div");
181
+ box.className = `flash ${heatClass(count)}`;
182
+ box.style.cssText = `left:${rect.left}px;top:${rect.top}px;width:${rect.width}px;height:${rect.height}px`;
183
+ layer.append(box);
184
+ setTimeout(() => box.remove(), FLASH_MS);
185
+ drawn++;
186
+ }
187
+ pending.clear();
188
+ }
189
+ const observer = new MutationObserver((records) => {
190
+ for (const record of records) {
191
+ let target = record.target;
192
+ if (record.type === "childList") {
193
+ let added = 0;
194
+ for (const node of record.addedNodes) if (node.nodeType === 1) {
195
+ pending.add(node);
196
+ added++;
197
+ }
198
+ if (added > 0) continue;
199
+ }
200
+ if (target.nodeType !== 1) target = target.parentElement;
201
+ if (target && target !== host && target !== document.documentElement && target !== document.body) pending.add(target);
202
+ }
203
+ for (const target of pending) if (target === host || host.contains(target)) pending.delete(target);
204
+ if (pending.size > 0 && frame === 0) frame = requestAnimationFrame(draw);
205
+ });
206
+ state.setFlash = (on) => {
207
+ state.flash = on;
208
+ if (on) observer.observe(document.documentElement, {
209
+ subtree: true,
210
+ childList: true,
211
+ attributes: true,
212
+ characterData: true
213
+ });
214
+ else {
215
+ observer.disconnect();
216
+ pending.clear();
217
+ layer.replaceChildren();
218
+ }
219
+ try {
220
+ localStorage.setItem(FLASH_KEY, on ? "1" : "0");
221
+ } catch {}
222
+ state.changed?.();
223
+ };
224
+ let saved = false;
225
+ try {
226
+ saved = localStorage.getItem(FLASH_KEY) === "1";
227
+ } catch {}
228
+ if (saved) state.setFlash(true);
229
+ }
230
+ /** True for an error of code that is not of the page, such as of a browser extension. */
231
+ function foreign(stack, file = "") {
232
+ return /^[a-z-]+-extension:/.test(file) || stack !== void 0 && /[a-z-]+-extension:\/\//.test(stack) && !stack.includes(location.origin);
233
+ }
234
+ /** Listens to the core, and adds the button that opens the panel. */
235
+ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", meta = {}, hot) {
236
+ const state = {
237
+ log: [],
238
+ blocks: /* @__PURE__ */ new Map(),
239
+ written: /* @__PURE__ */ new Set(),
240
+ endpoint,
241
+ meta,
242
+ errors: [],
243
+ timeline: [],
244
+ effects: /* @__PURE__ */ new Map(),
245
+ navigations: [],
246
+ flash: false
247
+ };
248
+ /** The handler that a server call or an update that starts now belongs to. */
249
+ function owner(time) {
250
+ for (let index = state.timeline.length - 1; index >= 0; index--) {
251
+ const run = state.timeline[index];
252
+ if (run.begun <= time && (run.settled === void 0 || time <= run.settled + 32)) return run;
253
+ }
254
+ }
255
+ function add(entry) {
256
+ state.log.push({
257
+ ...entry,
258
+ time: performance.now()
259
+ });
260
+ if (state.log.length > MAX_LOG) state.log.splice(0, state.log.length - MAX_LOG);
261
+ state.changed?.();
262
+ }
263
+ globalThis[DEVTOOLS] = {
264
+ attach(core) {
265
+ state.scopes = core.scopes;
266
+ state.set = core.set;
267
+ state.handle = core.handle;
268
+ state.changed?.();
269
+ },
270
+ handled(run) {
271
+ const entry = {
272
+ ref: run.ref,
273
+ label: `${run.event ?? "call"} on <${run.element.tagName.toLowerCase()}>`,
274
+ begun: run.begun,
275
+ ready: run.ready,
276
+ end: run.end,
277
+ calls: [],
278
+ updates: []
279
+ };
280
+ if (run.result instanceof Promise) run.result.then(() => {
281
+ entry.settled = performance.now();
282
+ state.changed?.();
283
+ }, () => {
284
+ entry.settled = performance.now();
285
+ entry.failed = true;
286
+ state.changed?.();
287
+ });
288
+ else entry.settled = run.end;
289
+ state.timeline.push(entry);
290
+ if (state.timeline.length > 100) state.timeline.shift();
291
+ state.changed?.();
292
+ },
293
+ updated(count, start, end) {
294
+ if (count > 0) owner(start)?.updates.push({
295
+ count,
296
+ start,
297
+ end
298
+ });
299
+ },
300
+ defer(template, done) {
301
+ deferred(template, done);
302
+ },
303
+ handler(ref, element, event) {
304
+ if (element.tagName === "TEMPLATE") {
305
+ let block;
306
+ for (const item of state.blocks.values()) if (item.template === element) {
307
+ block = item;
308
+ break;
309
+ }
310
+ if (block && block.fired === void 0) {
311
+ block.fired = performance.now();
312
+ if (block.kind === "$client") {
313
+ block.state = "rendered";
314
+ block.rendered = block.fired;
315
+ }
316
+ }
317
+ }
318
+ add({
319
+ kind: "handler",
320
+ text: `${event?.type ?? "call"} on <${element.tagName.toLowerCase()}>: ${ref}`
321
+ });
322
+ },
323
+ effect(scope, name, kind, time) {
324
+ const key = `${scope.id}:${name}`;
325
+ let entry = state.effects.get(key);
326
+ if (!entry) {
327
+ entry = {
328
+ scope: scope.id,
329
+ component: findRootScope(scope).m ?? "",
330
+ k: scope.k,
331
+ name,
332
+ runs: 0,
333
+ recent: [],
334
+ time: 0,
335
+ cleanups: 0,
336
+ active: false
337
+ };
338
+ state.effects.set(key, entry);
339
+ }
340
+ const now = performance.now();
341
+ if (kind === "run") {
342
+ entry.runs++;
343
+ entry.time += time;
344
+ entry.recent.push(now);
345
+ if (entry.recent.length > 50) entry.recent.shift();
346
+ entry.active = true;
347
+ } else {
348
+ entry.cleanups++;
349
+ entry.lastCleanup = now;
350
+ entry.active = false;
351
+ }
352
+ state.changed?.();
353
+ },
354
+ navigated(report) {
355
+ state.navigations.push(report);
356
+ if (state.navigations.length > 20) state.navigations.shift();
357
+ state.changed?.();
358
+ },
359
+ write(scope, slot, value) {
360
+ state.written.add(scope.id);
361
+ const root = findRootScope(scope);
362
+ add({
363
+ kind: "write",
364
+ text: `scope ${scope.id} slot ${slot} = ${preview(value)}`,
365
+ scope: scope.id,
366
+ write: {
367
+ component: root.m ?? "",
368
+ k: scope.k,
369
+ slot
370
+ }
371
+ });
372
+ }
373
+ };
374
+ state.showFallback = (block, on) => {
375
+ const kept = globalThis.$bD?.[block.id];
376
+ if (!kept || (block.fallback ?? false) === on) return false;
377
+ const [shown, hidden] = on ? [kept.b, kept.f] : [kept.f, kept.b];
378
+ let anchor;
379
+ for (const node of shown) if (node.parentNode) {
380
+ anchor = node;
381
+ break;
382
+ }
383
+ if (!anchor) return false;
384
+ for (const node of hidden) anchor.parentNode.insertBefore(node, anchor);
385
+ for (const node of shown) node.parentNode?.removeChild(node);
386
+ block.fallback = on;
387
+ state.changed?.();
388
+ return true;
389
+ };
390
+ const original = globalThis.fetch.bind(globalThis);
391
+ globalThis.fetch = async (input, init) => {
392
+ const url = new URL(input instanceof Request ? input.url : String(input), location.href);
393
+ if (url.origin !== location.origin || !url.pathname.startsWith(`${rpc}/`)) return original(input, init);
394
+ const name = decodeURIComponent(url.pathname.slice(rpc.length + 1));
395
+ const started = performance.now();
396
+ const call = {
397
+ name,
398
+ start: started
399
+ };
400
+ owner(started)?.calls.push(call);
401
+ try {
402
+ const response = await original(input, init);
403
+ const took = Math.round(performance.now() - started);
404
+ const redirect = response.headers.get("x-brumate-redirect");
405
+ call.end = performance.now();
406
+ call.status = redirect ? "redirect" : response.status;
407
+ const server = /brumate;dur=([\d.]+)/.exec(response.headers.get("server-timing") ?? "");
408
+ if (server) call.server = Number(server[1]);
409
+ state.changed?.();
410
+ add({
411
+ kind: "call",
412
+ text: `${name}: ${redirect ? `redirect to ${redirect}` : response.status} in ${took} ms`
413
+ });
414
+ return response;
415
+ } catch (error) {
416
+ call.end = performance.now();
417
+ call.status = "failed";
418
+ add({
419
+ kind: "call",
420
+ text: `${name}: failed, ${error instanceof Error ? error.message : String(error)}`
421
+ });
422
+ throw error;
423
+ }
424
+ };
425
+ function deferred(template, done) {
426
+ let block;
427
+ for (const item of state.blocks.values()) if (item.template === template) {
428
+ block = item;
429
+ break;
430
+ }
431
+ if (block) {
432
+ block.fired ??= performance.now();
433
+ block.state = "loading";
434
+ }
435
+ done.finally(() => {
436
+ scanBlocks(state);
437
+ state.changed?.();
438
+ });
439
+ }
440
+ state.fire = (block) => {
441
+ if (block.kind === "defer" && block.template) deferred(block.template, import("./defer-CKWZLv2K.js").then((module) => module.loadDeferred(block.template)));
442
+ else if (block.template && block.ref) state.handle?.(block.template, block.ref);
443
+ };
444
+ if (typeof MutationObserver !== "undefined") {
445
+ let queued = false;
446
+ new MutationObserver(() => {
447
+ if (!queued) {
448
+ queued = true;
449
+ queueMicrotask(() => {
450
+ queued = false;
451
+ if (scanBlocks(state)) state.changed?.();
452
+ });
453
+ }
454
+ }).observe(document, {
455
+ childList: true,
456
+ subtree: true,
457
+ characterData: true
458
+ });
459
+ }
460
+ scanBlocks(state);
461
+ const host = document.createElement("brumate-devtools");
462
+ const root = host.attachShadow({ mode: "open" });
463
+ const style = document.createElement("style");
464
+ style.textContent = `
465
+ .open { position: fixed; left: 50%; bottom: 0; z-index: 2147483647; transform: translateX(-50%); display: flex; justify-content: center; padding: 8px 16px 0; border: 0; background: none; color: #ece8e4; font: 600 12px/1 system-ui, -apple-system, sans-serif; cursor: pointer; touch-action: none; outline: none; }
466
+ .open[hidden] { display: none; }
467
+ .grip { width: 40px; height: 5px; border-radius: 4px 4px 0 0; background: rgb(25 24 26 / 0.88); box-shadow: 0 0 0 1px rgb(255 255 255 / 0.3); transition: opacity 150ms cubic-bezier(0.4, 0, 0.2, 1), width 150ms cubic-bezier(0.4, 0, 0.2, 1); }
468
+ .open[data-errors] .grip { width: 56px; background: #e5484d; }
469
+ .content { position: absolute; left: 50%; bottom: 0; transform: translate(-50%, 100%); display: flex; align-items: center; gap: 8px; padding: 5px 8px 5px 10px; white-space: nowrap; background: #222023; border: 1px solid #2f2c31; border-bottom: 0; border-radius: 10px 10px 0 0; box-shadow: 0 -4px 16px rgb(0 0 0 / 0.3); opacity: 0; pointer-events: none; transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1), opacity 150ms cubic-bezier(0.4, 0, 0.2, 1); }
470
+ .open:hover .content, .open:focus-visible .content, .open:active .content { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
471
+ .open:hover .grip, .open:focus-visible .grip, .open:active .grip { opacity: 0; }
472
+ .open:focus-visible .content { border-color: #ee7a3e; }
473
+ .mark { display: inline-flex; width: 16px; height: 16px; }
474
+ .version { padding: 1px 8px; border-radius: 999px; background: rgb(238 122 62 / 0.16); color: #ffb48a; font: 600 12px/20px ui-monospace, SFMono-Regular, Menlo, monospace; }
475
+ .chevron { width: 12px; height: 12px; color: #a39a92; }
476
+ .count { min-width: 18px; padding: 0 5px; box-sizing: border-box; border-radius: 999px; background: #e5484d; color: #fff; font: 600 11px/18px system-ui, sans-serif; text-align: center; }
477
+ .count:empty { display: none; }
478
+ .flashes { position: fixed; inset: 0; pointer-events: none; z-index: 2147483646; }
479
+ .flash { position: fixed; box-sizing: border-box; border: 2px solid #7fd99a; border-radius: 3px; background: rgb(127 217 154 / 0.08); animation: flash 700ms ease-out forwards; }
480
+ .flash.warm { border-color: #ffd166; background: rgb(255 209 102 / 0.1); }
481
+ .flash.hot { border-color: #ff7a7a; background: rgb(255 122 122 / 0.12); }
482
+ @keyframes flash { from { opacity: 1; } to { opacity: 0; } }
483
+ @media (prefers-reduced-motion: reduce) { .flash { animation: none; } }
484
+ @media (prefers-reduced-motion: reduce) { .grip, .content { transition: none; } }
485
+ `;
486
+ const button = document.createElement("button");
487
+ button.type = "button";
488
+ button.className = "open";
489
+ button.title = "brumate devtools (Alt+Shift+D)";
490
+ button.innerHTML = `<span class="grip"></span><span class="content"><span class="mark">${LOGO}</span><span class="version"></span><span class="count"></span><svg class="chevron" viewBox="0 0 12 12" aria-hidden="true"><path d="M3 7.5 6 4.5 9 7.5" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg></span>`;
491
+ button.querySelector(".version").textContent = meta.version ? `v${meta.version}` : "brumate";
492
+ function label() {
493
+ const errors = state.errors.length;
494
+ button.setAttribute("aria-label", `Open the brumate devtools${meta.version ? `, version ${meta.version}` : ""}${errors > 0 ? `, ${errors} errors` : ""}`);
495
+ }
496
+ label();
497
+ const count = button.querySelector(".count");
498
+ state.errorCount = () => {
499
+ count.textContent = state.errors.length > 0 ? String(state.errors.length) : "";
500
+ button.toggleAttribute("data-errors", state.errors.length > 0);
501
+ label();
502
+ };
503
+ let dragged = false;
504
+ button.addEventListener("pointerdown", (event) => {
505
+ if (event.button !== 0) return;
506
+ const start = event.clientY;
507
+ let opened = false;
508
+ dragged = false;
509
+ function move(next) {
510
+ if (!opened) {
511
+ if (start - next.clientY < 4) return;
512
+ opened = true;
513
+ dragged = true;
514
+ panelModule().then(({ openPanel }) => {
515
+ openPanel(root, state, "overview");
516
+ state.resize?.(next.clientY);
517
+ });
518
+ return;
519
+ }
520
+ state.resize?.(next.clientY);
521
+ }
522
+ function end() {
523
+ removeEventListener("pointermove", move);
524
+ removeEventListener("pointerup", end);
525
+ removeEventListener("pointercancel", end);
526
+ if (opened) state.resized?.();
527
+ }
528
+ addEventListener("pointermove", move);
529
+ addEventListener("pointerup", end);
530
+ addEventListener("pointercancel", end);
531
+ });
532
+ button.addEventListener("click", () => {
533
+ if (dragged) {
534
+ dragged = false;
535
+ return;
536
+ }
537
+ panelModule().then(({ togglePanel }) => togglePanel(root, state));
538
+ });
539
+ addEventListener("keydown", (event) => {
540
+ if (event.altKey && event.shiftKey && event.code === "KeyD") {
541
+ event.preventDefault();
542
+ panelModule().then(({ togglePanel }) => togglePanel(root, state));
543
+ }
544
+ });
545
+ state.open = (tab) => {
546
+ import("./devtools-panel-Be9pxYgv.js").then(({ openPanel }) => openPanel(root, state, tab));
547
+ };
548
+ root.append(style, button);
549
+ installFlash(state, root, host);
550
+ addEventListener("error", (event) => {
551
+ const stack = event.error?.stack;
552
+ if (foreign(stack, event.filename)) return;
553
+ const error = event.error;
554
+ reportError(state, {
555
+ message: error?.message ?? event.message,
556
+ stack: error?.stack
557
+ }, "browser");
558
+ });
559
+ addEventListener("unhandledrejection", (event) => {
560
+ const reason = event.reason;
561
+ if (foreign(reason?.stack)) return;
562
+ reportError(state, {
563
+ message: reason?.message ?? String(event.reason),
564
+ stack: reason?.stack
565
+ }, "browser");
566
+ });
567
+ addEventListener("brumate:error", (event) => {
568
+ const error = event.detail.error;
569
+ reportError(state, {
570
+ message: error?.message ?? String(error),
571
+ stack: error?.stack
572
+ }, "browser");
573
+ });
574
+ hot?.on("vite:error", (payload) => {
575
+ reportError(state, payload.err, "compile");
576
+ });
577
+ hot?.on("vite:afterUpdate", () => {
578
+ const before = state.errors.length;
579
+ const remaining = [];
580
+ for (const error of state.errors) if (error.source !== "compile") remaining.push(error);
581
+ state.errors = remaining;
582
+ if (state.errors.length !== before) {
583
+ state.errorCount?.();
584
+ state.changed?.();
585
+ }
586
+ });
587
+ function append() {
588
+ document.documentElement.append(host);
589
+ }
590
+ if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", append);
591
+ else append();
592
+ return state;
593
+ }
594
+ //#endregion
595
+ export { scanBlocks as a, reportError as i, installDevtools as n, preview as r, findRootScope as t };
596
+
597
+ //# sourceMappingURL=devtools-4uTPwR_v.js.map