brumate 0.7.2 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/{boot-CMy0f_iC.d.ts → boot-DQuAhAd5.d.ts} +2 -2
  2. package/dist/cli.js +3 -2
  3. package/dist/cli.js.map +1 -1
  4. package/dist/{client-DnFF9_lv.d.ts → client-4eabQtYJ.d.ts} +38 -12
  5. package/dist/{client-COm1iA6w.js → client-CwVcmymi.js} +145 -28
  6. package/dist/client-CwVcmymi.js.map +1 -0
  7. package/dist/{defer-Cesb-k2Q.js → defer-BaXWydb0.js} +2 -2
  8. package/dist/{defer-Cesb-k2Q.js.map → defer-BaXWydb0.js.map} +1 -1
  9. package/dist/{devtools-C9IEkgc1.js → devtools-CMuj12yR.js} +257 -118
  10. package/dist/devtools-CMuj12yR.js.map +1 -0
  11. package/dist/devtools-calls-DGW6nLZ2.js +249 -0
  12. package/dist/devtools-calls-DGW6nLZ2.js.map +1 -0
  13. package/dist/devtools-panel-Cq8LpsyW.js +3978 -0
  14. package/dist/devtools-panel-Cq8LpsyW.js.map +1 -0
  15. package/dist/error-catalog-DakxjSgj.js +308 -0
  16. package/dist/error-catalog-DakxjSgj.js.map +1 -0
  17. package/dist/error-catalog-VxLbz-6p.js +1 -0
  18. package/dist/{files-BuQvpBwF.js → files-DXS8RAtZ.js} +2 -2
  19. package/dist/{files-BuQvpBwF.js.map → files-DXS8RAtZ.js.map} +1 -1
  20. package/dist/index.d.ts +73 -18
  21. package/dist/index.js +11 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/{inspect-BSHv1_25.js → inspect-B5AoHh5O.js} +639 -412
  24. package/dist/inspect-B5AoHh5O.js.map +1 -0
  25. package/dist/{loader-CLKrJMqw.js → loader-CTeT6ie9.js} +4 -4
  26. package/dist/{loader-CLKrJMqw.js.map → loader-CTeT6ie9.js.map} +1 -1
  27. package/dist/{navigate-OHb0Uw1P.js → navigate-Bj73X4ZS.js} +22 -8
  28. package/dist/navigate-Bj73X4ZS.js.map +1 -0
  29. package/dist/{rpc-BAKbRWOT.js → rpc-kVB0Ujdx.js} +5 -4
  30. package/dist/rpc-kVB0Ujdx.js.map +1 -0
  31. package/dist/runtime/bundles.d.ts +3 -2
  32. package/dist/runtime/bundles.js +14 -3
  33. package/dist/runtime/bundles.js.map +1 -1
  34. package/dist/runtime/client.d.ts +2 -2
  35. package/dist/runtime/client.js +4 -3
  36. package/dist/runtime/devtools.d.ts +59 -1
  37. package/dist/runtime/devtools.js +1 -1
  38. package/dist/runtime/hot.d.ts +1 -1
  39. package/dist/runtime/hot.js +6 -2
  40. package/dist/runtime/hot.js.map +1 -1
  41. package/dist/runtime/loader.d.ts +2 -2
  42. package/dist/runtime/loader.js +2 -2
  43. package/dist/runtime/server.d.ts +1 -1
  44. package/dist/runtime/server.js +3 -2
  45. package/dist/runtime/signals.d.ts +1 -1
  46. package/dist/runtime/static-loader.d.ts +2 -2
  47. package/dist/runtime/static-loader.js +1 -1
  48. package/dist/runtime/store.d.ts +2 -2
  49. package/dist/runtime/store.js +1 -1
  50. package/dist/runtime/testing.d.ts +2 -2
  51. package/dist/runtime/testing.js +2 -2
  52. package/dist/search-params-Wg-0FsMj.js +148 -0
  53. package/dist/search-params-Wg-0FsMj.js.map +1 -0
  54. package/dist/{stream-RXLadXx1.js → serial-ioa17MuY.js} +67 -168
  55. package/dist/serial-ioa17MuY.js.map +1 -0
  56. package/dist/serial-ribg9NAj.js +1 -0
  57. package/dist/{server-BVObWh-w.js → server-BUuf7XPZ.js} +61 -16
  58. package/dist/server-BUuf7XPZ.js.map +1 -0
  59. package/dist/{server-0rS5vUW1.d.ts → server-DesBZv5g.d.ts} +8 -3
  60. package/dist/{search-params-C64liRBj.js → shared-CX_YacDm.js} +3 -148
  61. package/dist/shared-CX_YacDm.js.map +1 -0
  62. package/dist/{signals-DBnq9QRW.d.ts → signals-7VVD9C_H.d.ts} +2 -2
  63. package/dist/{static-loader-CxANokZ4.js → static-loader-BM0-wdIc.js} +2 -2
  64. package/dist/{static-loader-CxANokZ4.js.map → static-loader-BM0-wdIc.js.map} +1 -1
  65. package/dist/{static-loader-BYbXVJDY.d.ts → static-loader-BSAyFqG0.d.ts} +2 -2
  66. package/dist/{store-xlTzAM_r.d.ts → store-9_oa0HG1.d.ts} +15 -2
  67. package/dist/{store-BIBAYZo-.js → store-Cy4EEyZ7.js} +148 -2
  68. package/dist/store-Cy4EEyZ7.js.map +1 -0
  69. package/dist/stream-read-BTsYstJY.js +22 -0
  70. package/dist/stream-read-BTsYstJY.js.map +1 -0
  71. package/dist/stream-read-Dek3HnqO.js +1 -0
  72. package/dist/vite.d.ts +1 -1
  73. package/dist/vite.js +37 -5
  74. package/dist/vite.js.map +1 -1
  75. package/package.json +7 -4
  76. package/skills/brumate/SKILL.md +6 -2
  77. package/skills/brumate/references/errors.md +21 -2
  78. package/skills/brumate/references/state.md +31 -0
  79. package/skills/brumate/references/syntax.md +45 -1
  80. package/dist/client-COm1iA6w.js.map +0 -1
  81. package/dist/devtools-C9IEkgc1.js.map +0 -1
  82. package/dist/devtools-panel-Doit__YG.js +0 -2018
  83. package/dist/devtools-panel-Doit__YG.js.map +0 -1
  84. package/dist/inspect-BSHv1_25.js.map +0 -1
  85. package/dist/navigate-OHb0Uw1P.js.map +0 -1
  86. package/dist/rpc-BAKbRWOT.js.map +0 -1
  87. package/dist/search-params-C64liRBj.js.map +0 -1
  88. package/dist/server-BVObWh-w.js.map +0 -1
  89. package/dist/store-BIBAYZo-.js.map +0 -1
  90. package/dist/stream-RXLadXx1.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { hn as build, yn as skew } from "./client-COm1iA6w.js";
1
+ import { Sn as skew, vn as build } from "./client-CwVcmymi.js";
2
2
  import { n as trustedScript, t as trustedHTML } from "./trusted-g_zUJbh2.js";
3
3
  //#region src/runtime/defer.ts
4
4
  /** The nonce of a script. Browsers hide the attribute once the page loads, and keep the property. */
@@ -53,4 +53,4 @@ async function loadDeferred(template) {
53
53
  //#endregion
54
54
  export { loadDeferred };
55
55
 
56
- //# sourceMappingURL=defer-Cesb-k2Q.js.map
56
+ //# sourceMappingURL=defer-BaXWydb0.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"defer-Cesb-k2Q.js","names":[],"sources":["../src/runtime/defer.ts"],"sourcesContent":["// Loads the body of a `#defer` block. The loader imports this module when\n// the block's trigger fires, so a page without `#defer` does not load it.\n//\n// The server renders the route again for the request and answers with what\n// it streams for a `#loading` body that is ready: the body in a\n// `<template b-l>`, the script that swaps it in, and its state records.\n// This module adds that markup to the page and runs its scripts, in order.\n\nimport { build, skew } from './client.ts';\nimport { trustedHTML, trustedScript } from './trusted.ts';\n/** The nonce of a script. Browsers hide the attribute once the page loads, and keep the property. */\nfunction readNonce(script: HTMLScriptElement): string | null {\n return script.nonce || script.getAttribute('nonce');\n}\n\n/** The Content Security Policy nonce of the page, which the scripts of the answer need to run. */\nfunction pageNonce(): string | undefined {\n for (const script of document.querySelectorAll('script')) {\n const nonce = readNonce(script);\n if (nonce) {\n return nonce;\n }\n }\n return undefined;\n}\n\n/** The templates whose bodies were asked for. */\nconst requested = new WeakSet<Element>();\n\n/**\n * Asks the server for the body of the `#defer` block of a `<template\n * b-defer>`, and puts it in place of the fallback. When the server cannot\n * render it, such as a page that changed since it loaded, or a static host\n * that answers with the whole page, the fallback stays.\n */\nexport async function loadDeferred(template: Element): Promise<void> {\n // Once, so the devtools can fire the trigger before the loader does.\n if (requested.has(template)) {\n return;\n }\n requested.add(template);\n const [, boundary, base] = template.getAttribute('b-defer')!.split(':') as [\n string,\n string,\n string,\n ];\n const response = await fetch(location.href, {\n headers: {\n 'x-brumate-defer': `${boundary} ${template.getAttribute('b-b')}`,\n 'x-brumate-base': base,\n ...(build === undefined ? {} : { 'x-brumate-build': build }),\n },\n });\n if (response.status === 409 && response.headers.get('x-brumate-build')) {\n // The site changed since the page loaded. The fallback stays, and the next page loads in full.\n skew('defer');\n return;\n }\n if (!response.ok || response.headers.get('x-brumate-defer') !== boundary) {\n return;\n }\n const parsed = document.createElement('template');\n parsed.innerHTML = trustedHTML(await response.text());\n const nonce = pageNonce();\n // A copy, because appending moves nodes out of the live list.\n for (const node of Array.from(parsed.content.childNodes)) {\n if (node.nodeName !== 'SCRIPT') {\n document.body.append(node);\n continue;\n }\n // A script from `innerHTML` does not run, so a copy goes in its place.\n const script = node as HTMLScriptElement;\n const copy = document.createElement('script');\n for (const attribute of script.attributes) {\n if (attribute.name !== 'nonce') {\n copy.setAttribute(attribute.name, attribute.value);\n }\n }\n if (nonce) {\n copy.nonce = nonce;\n }\n copy.textContent = trustedScript(script.textContent ?? '');\n document.body.append(copy);\n }\n}\n"],"mappings":";;;;AAWA,SAAS,UAAU,QAA0C;CAC3D,OAAO,OAAO,SAAS,OAAO,aAAa,OAAO;AACpD;;AAGA,SAAS,YAAgC;CACvC,KAAK,MAAM,UAAU,SAAS,iBAAiB,QAAQ,GAAG;EACxD,MAAM,QAAQ,UAAU,MAAM;EAC9B,IAAI,OACF,OAAO;CAEX;AAEF;;AAGA,MAAM,4BAAY,IAAI,QAAiB;;;;;;;AAQvC,eAAsB,aAAa,UAAkC;CAEnE,IAAI,UAAU,IAAI,QAAQ,GACxB;CAEF,UAAU,IAAI,QAAQ;CACtB,MAAM,GAAG,UAAU,QAAQ,SAAS,aAAa,SAAS,CAAC,CAAE,MAAM,GAAG;CAKtE,MAAM,WAAW,MAAM,MAAM,SAAS,MAAM,EAC1C,SAAS;EACP,mBAAmB,GAAG,SAAS,GAAG,SAAS,aAAa,KAAK;EAC7D,kBAAkB;EAClB,GAAI,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,mBAAmB,MAAM;CAC5D,EACF,CAAC;CACD,IAAI,SAAS,WAAW,OAAO,SAAS,QAAQ,IAAI,iBAAiB,GAAG;EAEtE,KAAK,OAAO;EACZ;CACF;CACA,IAAI,CAAC,SAAS,MAAM,SAAS,QAAQ,IAAI,iBAAiB,MAAM,UAC9D;CAEF,MAAM,SAAS,SAAS,cAAc,UAAU;CAChD,OAAO,YAAY,YAAY,MAAM,SAAS,KAAK,CAAC;CACpD,MAAM,QAAQ,UAAU;CAExB,KAAK,MAAM,QAAQ,MAAM,KAAK,OAAO,QAAQ,UAAU,GAAG;EACxD,IAAI,KAAK,aAAa,UAAU;GAC9B,SAAS,KAAK,OAAO,IAAI;GACzB;EACF;EAEA,MAAM,SAAS;EACf,MAAM,OAAO,SAAS,cAAc,QAAQ;EAC5C,KAAK,MAAM,aAAa,OAAO,YAC7B,IAAI,UAAU,SAAS,SACrB,KAAK,aAAa,UAAU,MAAM,UAAU,KAAK;EAGrD,IAAI,OACF,KAAK,QAAQ;EAEf,KAAK,cAAc,cAAc,OAAO,eAAe,EAAE;EACzD,SAAS,KAAK,OAAO,IAAI;CAC3B;AACF"}
1
+ {"version":3,"file":"defer-BaXWydb0.js","names":[],"sources":["../src/runtime/defer.ts"],"sourcesContent":["// Loads the body of a `#defer` block. The loader imports this module when\n// the block's trigger fires, so a page without `#defer` does not load it.\n//\n// The server renders the route again for the request and answers with what\n// it streams for a `#loading` body that is ready: the body in a\n// `<template b-l>`, the script that swaps it in, and its state records.\n// This module adds that markup to the page and runs its scripts, in order.\n\nimport { build, skew } from './client.ts';\nimport { trustedHTML, trustedScript } from './trusted.ts';\n/** The nonce of a script. Browsers hide the attribute once the page loads, and keep the property. */\nfunction readNonce(script: HTMLScriptElement): string | null {\n return script.nonce || script.getAttribute('nonce');\n}\n\n/** The Content Security Policy nonce of the page, which the scripts of the answer need to run. */\nfunction pageNonce(): string | undefined {\n for (const script of document.querySelectorAll('script')) {\n const nonce = readNonce(script);\n if (nonce) {\n return nonce;\n }\n }\n return undefined;\n}\n\n/** The templates whose bodies were asked for. */\nconst requested = new WeakSet<Element>();\n\n/**\n * Asks the server for the body of the `#defer` block of a `<template\n * b-defer>`, and puts it in place of the fallback. When the server cannot\n * render it, such as a page that changed since it loaded, or a static host\n * that answers with the whole page, the fallback stays.\n */\nexport async function loadDeferred(template: Element): Promise<void> {\n // Once, so the devtools can fire the trigger before the loader does.\n if (requested.has(template)) {\n return;\n }\n requested.add(template);\n const [, boundary, base] = template.getAttribute('b-defer')!.split(':') as [\n string,\n string,\n string,\n ];\n const response = await fetch(location.href, {\n headers: {\n 'x-brumate-defer': `${boundary} ${template.getAttribute('b-b')}`,\n 'x-brumate-base': base,\n ...(build === undefined ? {} : { 'x-brumate-build': build }),\n },\n });\n if (response.status === 409 && response.headers.get('x-brumate-build')) {\n // The site changed since the page loaded. The fallback stays, and the next page loads in full.\n skew('defer');\n return;\n }\n if (!response.ok || response.headers.get('x-brumate-defer') !== boundary) {\n return;\n }\n const parsed = document.createElement('template');\n parsed.innerHTML = trustedHTML(await response.text());\n const nonce = pageNonce();\n // A copy, because appending moves nodes out of the live list.\n for (const node of Array.from(parsed.content.childNodes)) {\n if (node.nodeName !== 'SCRIPT') {\n document.body.append(node);\n continue;\n }\n // A script from `innerHTML` does not run, so a copy goes in its place.\n const script = node as HTMLScriptElement;\n const copy = document.createElement('script');\n for (const attribute of script.attributes) {\n if (attribute.name !== 'nonce') {\n copy.setAttribute(attribute.name, attribute.value);\n }\n }\n if (nonce) {\n copy.nonce = nonce;\n }\n copy.textContent = trustedScript(script.textContent ?? '');\n document.body.append(copy);\n }\n}\n"],"mappings":";;;;AAWA,SAAS,UAAU,QAA0C;CAC3D,OAAO,OAAO,SAAS,OAAO,aAAa,OAAO;AACpD;;AAGA,SAAS,YAAgC;CACvC,KAAK,MAAM,UAAU,SAAS,iBAAiB,QAAQ,GAAG;EACxD,MAAM,QAAQ,UAAU,MAAM;EAC9B,IAAI,OACF,OAAO;CAEX;AAEF;;AAGA,MAAM,4BAAY,IAAI,QAAiB;;;;;;;AAQvC,eAAsB,aAAa,UAAkC;CAEnE,IAAI,UAAU,IAAI,QAAQ,GACxB;CAEF,UAAU,IAAI,QAAQ;CACtB,MAAM,GAAG,UAAU,QAAQ,SAAS,aAAa,SAAS,CAAC,CAAE,MAAM,GAAG;CAKtE,MAAM,WAAW,MAAM,MAAM,SAAS,MAAM,EAC1C,SAAS;EACP,mBAAmB,GAAG,SAAS,GAAG,SAAS,aAAa,KAAK;EAC7D,kBAAkB;EAClB,GAAI,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,mBAAmB,MAAM;CAC5D,EACF,CAAC;CACD,IAAI,SAAS,WAAW,OAAO,SAAS,QAAQ,IAAI,iBAAiB,GAAG;EAEtE,KAAK,OAAO;EACZ;CACF;CACA,IAAI,CAAC,SAAS,MAAM,SAAS,QAAQ,IAAI,iBAAiB,MAAM,UAC9D;CAEF,MAAM,SAAS,SAAS,cAAc,UAAU;CAChD,OAAO,YAAY,YAAY,MAAM,SAAS,KAAK,CAAC;CACpD,MAAM,QAAQ,UAAU;CAExB,KAAK,MAAM,QAAQ,MAAM,KAAK,OAAO,QAAQ,UAAU,GAAG;EACxD,IAAI,KAAK,aAAa,UAAU;GAC9B,SAAS,KAAK,OAAO,IAAI;GACzB;EACF;EAEA,MAAM,SAAS;EACf,MAAM,OAAO,SAAS,cAAc,QAAQ;EAC5C,KAAK,MAAM,aAAa,OAAO,YAC7B,IAAI,UAAU,SAAS,SACrB,KAAK,aAAa,UAAU,MAAM,UAAU,KAAK;EAGrD,IAAI,OACF,KAAK,QAAQ;EAEf,KAAK,cAAc,cAAc,OAAO,eAAe,EAAE;EACzD,SAAS,KAAK,OAAO,IAAI;CAC3B;AACF"}
@@ -1,7 +1,207 @@
1
1
  import { t as trustedHTML } from "./trusted-g_zUJbh2.js";
2
2
  import { t as LOGO } from "./logo-DQ_OYhBi.js";
3
+ //#region src/runtime/devtools-flash.ts
4
+ /** Where the choice to outline changed elements is kept. */
5
+ const FLASH_KEY = "brumate:devtools:flash";
6
+ /** The colours of an outline, by how often the element changes. */
7
+ const HEAT = {
8
+ cool: {
9
+ line: "#7fd99a",
10
+ fill: "rgb(127 217 154 / 0.08)"
11
+ },
12
+ warm: {
13
+ line: "#ffd166",
14
+ fill: "rgb(255 209 102 / 0.1)"
15
+ },
16
+ hot: {
17
+ line: "#ff7a7a",
18
+ fill: "rgb(255 122 122 / 0.12)"
19
+ }
20
+ };
21
+ /** The heat of an outline, by how many times the element changed in the last second. */
22
+ function pickHeat(count) {
23
+ if (count >= 5) return "hot";
24
+ return count >= 2 ? "warm" : "cool";
25
+ }
26
+ function reducedMotion() {
27
+ return typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
28
+ }
29
+ /**
30
+ * Outlines the elements that change, as an update writes them: green for an
31
+ * element that changes now and then, yellow and red for one that changes
32
+ * often. A MutationObserver sees every change of the page, so it needs no
33
+ * hook of the core. The boxes are drawn on one canvas in the shadow root, so
34
+ * the page itself does not change.
35
+ */
36
+ function installFlash(state, root, host) {
37
+ const canvas = document.createElement("canvas");
38
+ canvas.className = "flashes";
39
+ canvas.style.cssText = "position:fixed;left:0;top:0;width:100vw;height:100vh;pointer-events:none;z-index:2147483646";
40
+ root.append(canvas);
41
+ const context = canvas.getContext("2d");
42
+ const boxes = [];
43
+ const heat = /* @__PURE__ */ new WeakMap();
44
+ const pending = /* @__PURE__ */ new Set();
45
+ let observed = false;
46
+ let mutationFrame = 0;
47
+ let loop = 0;
48
+ function fit() {
49
+ const ratio = window.devicePixelRatio || 1;
50
+ const width = Math.round(innerWidth * ratio);
51
+ const height = Math.round(innerHeight * ratio);
52
+ if (canvas.width !== width || canvas.height !== height) {
53
+ canvas.width = width;
54
+ canvas.height = height;
55
+ }
56
+ canvas.style.width = `${innerWidth}px`;
57
+ canvas.style.height = `${innerHeight}px`;
58
+ }
59
+ function paint(now) {
60
+ if (!context) return;
61
+ const ratio = window.devicePixelRatio || 1;
62
+ context.setTransform(ratio, 0, 0, ratio, 0, 0);
63
+ context.clearRect(0, 0, innerWidth, innerHeight);
64
+ const still = reducedMotion();
65
+ context.lineWidth = 2;
66
+ for (const box of boxes) {
67
+ const colours = HEAT[box.heat];
68
+ context.globalAlpha = still ? 1 : Math.max(0, 1 - (now - box.start) / 700);
69
+ context.fillStyle = colours.fill;
70
+ context.strokeStyle = colours.line;
71
+ context.beginPath();
72
+ const x = box.x;
73
+ const y = box.y;
74
+ if (typeof context.roundRect === "function") context.roundRect(x, y, box.width, box.height, 3);
75
+ else context.rect(x, y, box.width, box.height);
76
+ context.fill();
77
+ context.stroke();
78
+ }
79
+ context.globalAlpha = 1;
80
+ }
81
+ /** One frame of the loop: drops the boxes that ran out, draws the rest and goes on while any is left. */
82
+ function tick() {
83
+ loop = 0;
84
+ const now = performance.now();
85
+ let kept = 0;
86
+ for (const box of boxes) if (now - box.start < 700) boxes[kept++] = box;
87
+ boxes.length = kept;
88
+ paint(now);
89
+ if (boxes.length > 0) loop = requestAnimationFrame(tick);
90
+ }
91
+ /** Measures the boxes again, since a scroll moves the elements but not the fixed ones. */
92
+ function repaint() {
93
+ if (boxes.length === 0) return;
94
+ for (const box of boxes) if (box.element.isConnected) {
95
+ const rect = box.element.getBoundingClientRect();
96
+ box.x = rect.left;
97
+ box.y = rect.top;
98
+ box.width = rect.width;
99
+ box.height = rect.height;
100
+ }
101
+ paint(performance.now());
102
+ }
103
+ function resize() {
104
+ fit();
105
+ repaint();
106
+ }
107
+ function collect() {
108
+ mutationFrame = 0;
109
+ let drawn = 0;
110
+ for (const target of pending) {
111
+ if (drawn >= 200) break;
112
+ const rect = target.getBoundingClientRect();
113
+ if (rect.width === 0 && rect.height === 0) continue;
114
+ const now = performance.now();
115
+ const last = heat.get(target);
116
+ const count = last && now - last.time < 1e3 ? last.count + 1 : 1;
117
+ heat.set(target, {
118
+ count,
119
+ time: now
120
+ });
121
+ boxes.push({
122
+ element: target,
123
+ x: rect.left,
124
+ y: rect.top,
125
+ width: rect.width,
126
+ height: rect.height,
127
+ heat: pickHeat(count),
128
+ start: now
129
+ });
130
+ drawn++;
131
+ }
132
+ pending.clear();
133
+ if (drawn > 0) {
134
+ fit();
135
+ paint(performance.now());
136
+ if (loop === 0) loop = requestAnimationFrame(tick);
137
+ }
138
+ }
139
+ const observer = new MutationObserver((records) => {
140
+ for (const record of records) {
141
+ let target = record.target;
142
+ if (record.type === "childList") {
143
+ let added = 0;
144
+ for (const node of record.addedNodes) if (node.nodeType === 1) {
145
+ pending.add(node);
146
+ added++;
147
+ }
148
+ if (added > 0) continue;
149
+ }
150
+ if (target.nodeType !== 1) target = target.parentElement;
151
+ if (target && target !== host && target !== document.documentElement && target !== document.body) pending.add(target);
152
+ }
153
+ for (const target of pending) if (target === host || host.contains(target)) pending.delete(target);
154
+ if (pending.size > 0 && mutationFrame === 0) mutationFrame = requestAnimationFrame(collect);
155
+ });
156
+ state.setFlash = (on) => {
157
+ state.flash = on;
158
+ if (on && !observed) {
159
+ observed = true;
160
+ fit();
161
+ observer.observe(document.documentElement, {
162
+ subtree: true,
163
+ childList: true,
164
+ attributes: true,
165
+ characterData: true
166
+ });
167
+ addEventListener("resize", resize);
168
+ addEventListener("scroll", repaint, {
169
+ passive: true,
170
+ capture: true
171
+ });
172
+ } else if (!on && observed) {
173
+ observed = false;
174
+ observer.disconnect();
175
+ removeEventListener("resize", resize);
176
+ removeEventListener("scroll", repaint, { capture: true });
177
+ pending.clear();
178
+ boxes.length = 0;
179
+ if (loop !== 0) {
180
+ cancelAnimationFrame(loop);
181
+ loop = 0;
182
+ }
183
+ paint(performance.now());
184
+ }
185
+ try {
186
+ localStorage.setItem(FLASH_KEY, on ? "1" : "0");
187
+ } catch {}
188
+ state.changed?.();
189
+ };
190
+ let saved = false;
191
+ try {
192
+ saved = localStorage.getItem(FLASH_KEY) === "1";
193
+ } catch {}
194
+ if (saved) state.setFlash(true);
195
+ return {
196
+ boxes,
197
+ canvas
198
+ };
199
+ }
200
+ //#endregion
3
201
  //#region src/runtime/devtools.ts
4
202
  const DEVTOOLS = Symbol.for("brumate.devtools");
203
+ /** The state and the button of the devtools that a page has, so a second install does nothing. */
204
+ const INSTALLED = Symbol.for("brumate.devtools.installed");
5
205
  const MAX_LOG = 300;
6
206
  /** The root scope of a scope, whose `m` names its component. */
7
207
  function findRootScope(scope) {
@@ -148,96 +348,7 @@ function reportError(state, payload, source) {
148
348
  }
149
349
  /** The code of the panel, which loads when it opens. */
150
350
  function panelModule() {
151
- return import("./devtools-panel-Doit__YG.js");
152
- }
153
- /** Where the choice to outline changed elements is kept. */
154
- const FLASH_KEY = "brumate:devtools:flash";
155
- /** How long an outline shows. */
156
- const FLASH_MS = 700;
157
- /** The most outlines that one frame draws, so a big change does not stall the page. */
158
- const MAX_FLASHES = 200;
159
- /** The class of an outline, by how many times the element changed in the last second. */
160
- function heatClass(count) {
161
- if (count >= 5) return "hot";
162
- return count >= 2 ? "warm" : "";
163
- }
164
- /**
165
- * Outlines the elements that change, as an update writes them: green for an
166
- * element that changes now and then, yellow and red for one that changes
167
- * often. A MutationObserver sees every change of the page, so it needs no
168
- * hook of the core. The outlines are drawn in the shadow root, so the page
169
- * itself does not change.
170
- */
171
- function installFlash(state, root, host) {
172
- const layer = document.createElement("div");
173
- layer.className = "flashes";
174
- root.append(layer);
175
- const heat = /* @__PURE__ */ new WeakMap();
176
- const pending = /* @__PURE__ */ new Set();
177
- let frame = 0;
178
- function draw() {
179
- frame = 0;
180
- let drawn = 0;
181
- for (const target of pending) {
182
- if (drawn >= MAX_FLASHES) break;
183
- const rect = target.getBoundingClientRect();
184
- if (rect.width === 0 && rect.height === 0) continue;
185
- const now = performance.now();
186
- const last = heat.get(target);
187
- const count = last && now - last.time < 1e3 ? last.count + 1 : 1;
188
- heat.set(target, {
189
- count,
190
- time: now
191
- });
192
- const box = document.createElement("div");
193
- box.className = `flash ${heatClass(count)}`;
194
- box.style.cssText = `left:${rect.left}px;top:${rect.top}px;width:${rect.width}px;height:${rect.height}px`;
195
- layer.append(box);
196
- setTimeout(() => box.remove(), FLASH_MS);
197
- drawn++;
198
- }
199
- pending.clear();
200
- }
201
- const observer = new MutationObserver((records) => {
202
- for (const record of records) {
203
- let target = record.target;
204
- if (record.type === "childList") {
205
- let added = 0;
206
- for (const node of record.addedNodes) if (node.nodeType === 1) {
207
- pending.add(node);
208
- added++;
209
- }
210
- if (added > 0) continue;
211
- }
212
- if (target.nodeType !== 1) target = target.parentElement;
213
- if (target && target !== host && target !== document.documentElement && target !== document.body) pending.add(target);
214
- }
215
- for (const target of pending) if (target === host || host.contains(target)) pending.delete(target);
216
- if (pending.size > 0 && frame === 0) frame = requestAnimationFrame(draw);
217
- });
218
- state.setFlash = (on) => {
219
- state.flash = on;
220
- if (on) observer.observe(document.documentElement, {
221
- subtree: true,
222
- childList: true,
223
- attributes: true,
224
- characterData: true
225
- });
226
- else {
227
- observer.disconnect();
228
- pending.clear();
229
- layer.replaceChildren();
230
- }
231
- try {
232
- localStorage.setItem(FLASH_KEY, on ? "1" : "0");
233
- } catch {}
234
- state.changed?.();
235
- };
236
- let saved = false;
237
- try {
238
- saved = localStorage.getItem(FLASH_KEY) === "1";
239
- } catch {}
240
- if (saved) state.setFlash(true);
351
+ return import("./devtools-panel-Cq8LpsyW.js");
241
352
  }
242
353
  /** True for an error of code that is not of the page, such as of a browser extension. */
243
354
  function foreign(stack, file = "") {
@@ -245,6 +356,8 @@ function foreign(stack, file = "") {
245
356
  }
246
357
  /** Listens to the core, and adds the button that opens the panel. */
247
358
  function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", meta = {}, hot) {
359
+ const installed = globalThis[INSTALLED];
360
+ if (installed && (installed.host.isConnected || !installed.appended)) return installed.state;
248
361
  const state = {
249
362
  log: [],
250
363
  blocks: /* @__PURE__ */ new Map(),
@@ -396,7 +509,8 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
396
509
  state.changed?.();
397
510
  return true;
398
511
  };
399
- const original = globalThis.fetch.bind(globalThis);
512
+ const unwrapped = installed && globalThis.fetch === installed.wrapper ? installed.fetch : globalThis.fetch;
513
+ const original = unwrapped.bind(globalThis);
400
514
  globalThis.fetch = async (input, init) => {
401
515
  const url = new URL(input instanceof Request ? input.url : String(input), location.href);
402
516
  if (url.origin !== location.origin || !url.pathname.startsWith(`${rpc}/`)) return original(input, init);
@@ -406,6 +520,14 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
406
520
  name,
407
521
  start: started
408
522
  };
523
+ const headers = {};
524
+ for (const [header, value] of new Headers(init?.headers)) if (header === "content-type" || header.startsWith("x-brumate-")) headers[header] = value;
525
+ const body = init?.body;
526
+ call.request = {
527
+ url: url.pathname + url.search,
528
+ headers,
529
+ ...typeof body === "string" || body instanceof FormData ? { body } : {}
530
+ };
409
531
  owner(started)?.calls.push(call);
410
532
  try {
411
533
  const response = await original(input, init);
@@ -415,10 +537,24 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
415
537
  call.status = redirect ? "redirect" : response.status;
416
538
  const server = /brumate;dur=([\d.]+)/.exec(response.headers.get("server-timing") ?? "");
417
539
  if (server) call.server = Number(server[1]);
540
+ const arrived = call.end;
541
+ const copy = response.clone();
542
+ import("./devtools-calls-DGW6nLZ2.js").then(({ readCall }) => readCall({
543
+ name,
544
+ init,
545
+ response: copy,
546
+ started,
547
+ arrived,
548
+ module: Math.max(0, started - (owner(started)?.ready ?? started))
549
+ })).then((record) => {
550
+ call.record = record;
551
+ state.changed?.();
552
+ }).catch(() => {});
418
553
  state.changed?.();
419
554
  add({
420
555
  kind: "call",
421
- text: `${name}: ${redirect ? `redirect to ${redirect}` : response.status} in ${took} ms`
556
+ text: `${name}: ${redirect ? `redirect to ${redirect}` : response.status} in ${took} ms`,
557
+ call
422
558
  });
423
559
  return response;
424
560
  } catch (error) {
@@ -426,7 +562,8 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
426
562
  call.status = "failed";
427
563
  add({
428
564
  kind: "call",
429
- text: `${name}: failed, ${error instanceof Error ? error.message : String(error)}`
565
+ text: `${name}: failed, ${error instanceof Error ? error.message : String(error)}`,
566
+ call
430
567
  });
431
568
  throw error;
432
569
  }
@@ -449,7 +586,7 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
449
586
  });
450
587
  }
451
588
  state.fire = (block) => {
452
- if (block.kind === "defer" && block.template) deferred(block.template, import("./defer-Cesb-k2Q.js").then((module) => module.loadDeferred(block.template)));
589
+ if (block.kind === "defer" && block.template) deferred(block.template, import("./defer-BaXWydb0.js").then((module) => module.loadDeferred(block.template)));
453
590
  else if (block.template && block.ref) state.handle?.(block.template, block.ref);
454
591
  };
455
592
  if (typeof MutationObserver !== "undefined") {
@@ -470,36 +607,37 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
470
607
  }
471
608
  scanBlocks(state);
472
609
  const host = document.createElement("brumate-devtools");
610
+ globalThis[INSTALLED] = {
611
+ state,
612
+ host,
613
+ appended: false,
614
+ fetch: unwrapped,
615
+ wrapper: globalThis.fetch
616
+ };
617
+ const mark = globalThis[INSTALLED];
473
618
  const root = host.attachShadow({ mode: "open" });
474
619
  const style = document.createElement("style");
475
620
  style.textContent = `
476
- .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; }
621
+ .open { position: fixed; left: 50%; bottom: 0; z-index: 2147483647; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; height: 6px; max-width: 44px; padding: 0 10px; overflow: hidden; border: 0; border-radius: 7px 7px 0 0; background: #3a373d; color: #ece8e4; font: 500 12px/1 system-ui, -apple-system, sans-serif; white-space: nowrap; cursor: pointer; touch-action: none; outline: none; transition: height 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), max-width 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), background 0.2s; }
477
622
  .open[hidden] { display: none; }
478
- .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); }
479
- .open[data-errors] .grip { width: 56px; background: #e5484d; }
480
- .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); }
481
- .open:hover .content, .open:focus-visible .content, .open:active .content { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
482
- .open:hover .grip, .open:focus-visible .grip, .open:active .grip { opacity: 0; }
483
- .open:focus-visible .content { border-color: #ee7a3e; }
484
- .mark { display: inline-flex; width: 16px; height: 16px; }
485
- .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; }
486
- .chevron { width: 12px; height: 12px; color: #a39a92; }
487
- .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; }
623
+ .open > * { opacity: 0; transition: opacity 0.12s; }
624
+ .open[data-errors] { background: #c94a4a; max-width: 64px; }
625
+ .open:hover, .open:focus-visible { height: 30px; max-width: 320px; background: #1d1c1f; box-shadow: 0 0 0 1px #36333a; }
626
+ .open[data-errors]:hover, .open[data-errors]:focus-visible { box-shadow: 0 0 0 1px #ff6b6b66; }
627
+ .open:hover > *, .open:focus-visible > * { opacity: 1; transition-delay: 0.08s; }
628
+ .mark { display: inline-flex; width: 16px; height: 16px; flex: none; }
629
+ .name { font-weight: 600; }
630
+ .version { color: #a39a92; font: 11px ui-monospace, 'SF Mono', SFMono-Regular, Menlo, monospace; }
631
+ .count { padding: 0 6px; border-radius: 999px; background: #ff6b6b26; color: #ff6b6b; font: 600 10.5px/17px ui-monospace, 'SF Mono', SFMono-Regular, Menlo, monospace; }
488
632
  .count:empty { display: none; }
489
- .flashes { position: fixed; inset: 0; pointer-events: none; z-index: 2147483646; }
490
- .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; }
491
- .flash.warm { border-color: #ffd166; background: rgb(255 209 102 / 0.1); }
492
- .flash.hot { border-color: #ff7a7a; background: rgb(255 122 122 / 0.12); }
493
- @keyframes flash { from { opacity: 1; } to { opacity: 0; } }
494
- @media (prefers-reduced-motion: reduce) { .flash { animation: none; } }
495
- @media (prefers-reduced-motion: reduce) { .grip, .content { transition: none; } }
633
+ @media (prefers-reduced-motion: reduce) { .open, .open > * { transition: none; } }
496
634
  `;
497
635
  const button = document.createElement("button");
498
636
  button.type = "button";
499
637
  button.className = "open";
500
638
  button.title = "brumate devtools (Alt+Shift+D)";
501
- button.innerHTML = trustedHTML(`<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>`);
502
- button.querySelector(".version").textContent = meta.version ? `v${meta.version}` : "brumate";
639
+ button.innerHTML = trustedHTML(`<span class="mark">${LOGO}</span><span class="name">brumate</span><span class="version"></span><span class="count"></span>`);
640
+ button.querySelector(".version").textContent = meta.version ?? "";
503
641
  function label() {
504
642
  const errors = state.errors.length;
505
643
  button.setAttribute("aria-label", `Open the brumate devtools${meta.version ? `, version ${meta.version}` : ""}${errors > 0 ? `, ${errors} errors` : ""}`);
@@ -507,7 +645,7 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
507
645
  label();
508
646
  const count = button.querySelector(".count");
509
647
  state.errorCount = () => {
510
- count.textContent = state.errors.length > 0 ? String(state.errors.length) : "";
648
+ count.textContent = state.errors.length > 0 ? `${state.errors.length} ${state.errors.length === 1 ? "issue" : "issues"}` : "";
511
649
  button.toggleAttribute("data-errors", state.errors.length > 0);
512
650
  label();
513
651
  };
@@ -523,7 +661,7 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
523
661
  opened = true;
524
662
  dragged = true;
525
663
  panelModule().then(({ openPanel }) => {
526
- openPanel(root, state, "overview");
664
+ openPanel(root, state);
527
665
  state.resize?.(next.clientY);
528
666
  });
529
667
  return;
@@ -554,7 +692,7 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
554
692
  }
555
693
  });
556
694
  state.open = (tab) => {
557
- import("./devtools-panel-Doit__YG.js").then(({ openPanel }) => openPanel(root, state, tab));
695
+ import("./devtools-panel-Cq8LpsyW.js").then(({ openPanel }) => openPanel(root, state, tab));
558
696
  };
559
697
  root.append(style, button);
560
698
  installFlash(state, root, host);
@@ -597,6 +735,7 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
597
735
  });
598
736
  function append() {
599
737
  document.documentElement.append(host);
738
+ mark.appended = true;
600
739
  }
601
740
  if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", append);
602
741
  else append();
@@ -605,4 +744,4 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
605
744
  //#endregion
606
745
  export { preview as a, nextBlockState as i, installDevtools as n, reportError as o, moveBlock as r, scanBlocks as s, findRootScope as t };
607
746
 
608
- //# sourceMappingURL=devtools-C9IEkgc1.js.map
747
+ //# sourceMappingURL=devtools-CMuj12yR.js.map