brumate 0.7.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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-COm1iA6w.js → client-B0FXW5Kw.js} +48 -14
- package/dist/client-B0FXW5Kw.js.map +1 -0
- package/dist/{client-DnFF9_lv.d.ts → client-Cq6aTiDs.d.ts} +15 -7
- package/dist/{defer-Cesb-k2Q.js → defer-BMIMP4Hq.js} +2 -2
- package/dist/{defer-Cesb-k2Q.js.map → defer-BMIMP4Hq.js.map} +1 -1
- package/dist/{devtools-C9IEkgc1.js → devtools-B4prrxht.js} +257 -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-CLKrJMqw.js → loader-BsaSuIoG.js} +4 -4
- package/dist/{loader-CLKrJMqw.js.map → loader-BsaSuIoG.js.map} +1 -1
- package/dist/{navigate-OHb0Uw1P.js → navigate-BlowKvhB.js} +13 -6
- package/dist/navigate-BlowKvhB.js.map +1 -0
- package/dist/{rpc-BAKbRWOT.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/{static-loader-CxANokZ4.js → static-loader-C_en-4v8.js} +2 -2
- package/dist/{static-loader-CxANokZ4.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/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-COm1iA6w.js.map +0 -1
- package/dist/devtools-C9IEkgc1.js.map +0 -1
- package/dist/devtools-panel-Doit__YG.js +0 -2018
- package/dist/devtools-panel-Doit__YG.js.map +0 -1
- package/dist/inspect-BSHv1_25.js.map +0 -1
- package/dist/navigate-OHb0Uw1P.js.map +0 -1
- package/dist/rpc-BAKbRWOT.js.map +0 -1
- package/dist/search-params-C64liRBj.js.map +0 -1
- package/dist/server-BVObWh-w.js.map +0 -1
- package/dist/store-BIBAYZo-.js.map +0 -1
- package/dist/stream-RXLadXx1.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as Context } from "./context-BNgBXVUQ.js";
|
|
2
2
|
import { a as PageState, c as ScopeId, m as Raw, n as ElementReference, t as Binding } from "./shared-CuJdWifz.js";
|
|
3
|
-
import { a as Store } from "./store-
|
|
3
|
+
import { a as Store } from "./store-9_oa0HG1.js";
|
|
4
4
|
import { r as SerialEntry } from "./values-B8C7CLvG.js";
|
|
5
|
-
import { M as SearchParamOptions } from "./signals-
|
|
5
|
+
import { M as SearchParamOptions } from "./signals-7VVD9C_H.js";
|
|
6
6
|
//#region src/runtime/navigate.d.ts
|
|
7
7
|
/** What the devtools learn of a navigation. See `DevtoolsHooks.navigated`. */
|
|
8
8
|
interface NavigationReport {
|
|
@@ -123,8 +123,12 @@ declare function dynamicNodes(tag: unknown, attributes: Record<string, unknown>,
|
|
|
123
123
|
declare function foreignNodes(foreign: string, tag: unknown, attributes: Record<string, unknown>, inner: Raw | Children | undefined, ctx?: unknown, scope?: Scope | number, ref?: unknown): string | Node;
|
|
124
124
|
declare function dynamic(tag: unknown, attributes: Record<string, unknown>, inner: Raw | Children | undefined, _ctx?: unknown, scope?: Scope | number, ref?: unknown): string;
|
|
125
125
|
/**
|
|
126
|
-
*
|
|
127
|
-
* once the scope is in the page.
|
|
126
|
+
* Marks the value of a memo of a render that cannot hold an error: a promise or a stream is
|
|
127
|
+
* loaded by `setSlots` once the scope is in the page.
|
|
128
|
+
*/
|
|
129
|
+
declare function memoNow(value: unknown): unknown;
|
|
130
|
+
/**
|
|
131
|
+
* Computes a memo of a render. A throw is held in a `MemoError`, as the server holds the error
|
|
128
132
|
* of a memo until a read.
|
|
129
133
|
*/
|
|
130
134
|
declare function renderMemo(compute: () => unknown): unknown;
|
|
@@ -596,7 +600,11 @@ interface Parking {
|
|
|
596
600
|
}
|
|
597
601
|
//#endregion
|
|
598
602
|
//#region src/runtime/client/page.d.ts
|
|
599
|
-
/**
|
|
603
|
+
/**
|
|
604
|
+
* Sets a style variable on the top-level elements of a component or block instance. `b-v` lists
|
|
605
|
+
* the IDs of the instances whose variables an element carries, since an element at the top level
|
|
606
|
+
* of a block inside another carries both.
|
|
607
|
+
*/
|
|
600
608
|
declare function setVar(scope: Scope, name: string, value: unknown): void;
|
|
601
609
|
/**
|
|
602
610
|
* Warns in development that the browser renders a `#defer` block of a
|
|
@@ -825,5 +833,5 @@ declare const loader: {
|
|
|
825
833
|
updateRoute: typeof updateRoute;
|
|
826
834
|
};
|
|
827
835
|
//#endregion
|
|
828
|
-
export { list as $, hooks as $t, nodes as A, leavePage as At, descendants as B, consumeContext as Bt, clone as C,
|
|
829
|
-
//# sourceMappingURL=client-
|
|
836
|
+
export { list as $, hooks as $t, nodes as A, leavePage as At, descendants as B, consumeContext as Bt, clone as C, offscreen as Cn, wait as Ct, keepText as D, NavigationReport as Dn, dispose as Dt, keep as E, retag as En, nameComment as Et, setOn as F, handle as Ft, sink as G, toStore as Gt, makeId as H, provideValue as Ht, setSpread as I, handlerProp as It, addHead as J, CoreOptions as Jt, prop as K, updateRoute as Kt, template as L, rpc as Lt, setAttr as M, remount as Mt, setAttrText as N, removeRoot as Nt, listNodes as O, forget as Ot, setContent as P, action as Pt, setVar as Q, build as Qt, afterInsert as R, spread as Rt, branchNodes as S, held as Sn, started as St, fillList as T, reset as Tn, loadModule as Tt, removeScope as U, setGlobal as Ut, getScope as V, consumeStore as Vt, setOwner as W, storeUpdate as Wt, addStyle as X, DevtoolsHooks as Xt, addPortal as Y, DEVTOOLS as Yt, deferInBrowser as Z, Scope as Zt, updated as _, insert as _n, fillSpread as _t, cells as a, componentNodes as an, content as at, searchParam as b, branch as bn, loading as bt, get as c, elementAt as cn, text as ct, pending as d, place as dn, track as dt, rpcPrefix as en, toList as et, resolve as f, readMemo as fn, after as ft, update as g, children as gn, fillSettled as gt, unreadMemo as h, setSlots as hn, fillAttrs as ht, bindings as i, component as in, attrs as it, putText as j, leaveRoutes as jt, markBlock as k, init as kt, isBound as l, foreignNodes as ln, writeText as lt, timed as m, setItem as mn, countLoads as mt, asyncMemo as n, skew as nn, windowStart as nt, effect as o, dynamic as on, portalTo as ot, set as p, renderMemo as pn, attempt as pt, spreadProps as q, ClientModule as qt, binding as r, Component as rn, attr as rt, gate as s, dynamicNodes as sn, restRef as st, loader as t, scopes as tn, windowList as tt, memo as u, memoNow as un, guess as ut, title as v, templateCall as vn, fillValue as vt, fillBranch as w, rekey as wn, fail as wt, appendText as x, fill as xn, reveal as xt, paramEffect as y, HiddenBody as yn, keepValue as yt, createScope as z, submitAction as zt };
|
|
837
|
+
//# sourceMappingURL=client-Cq6aTiDs.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bn as skew, gn as build } from "./client-B0FXW5Kw.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-
|
|
56
|
+
//# sourceMappingURL=defer-BMIMP4Hq.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defer-
|
|
1
|
+
{"version":3,"file":"defer-BMIMP4Hq.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-
|
|
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-B1nF1KB7.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
|
|
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-
|
|
589
|
+
if (block.kind === "defer" && block.template) deferred(block.template, import("./defer-BMIMP4Hq.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;
|
|
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
|
-
.
|
|
479
|
-
.open[data-errors]
|
|
480
|
-
.
|
|
481
|
-
.open:hover
|
|
482
|
-
.open:hover
|
|
483
|
-
.
|
|
484
|
-
.
|
|
485
|
-
.version {
|
|
486
|
-
.
|
|
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
|
-
|
|
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="
|
|
502
|
-
button.querySelector(".version").textContent = meta.version
|
|
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 ?
|
|
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
|
|
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-
|
|
695
|
+
import("./devtools-panel-B1nF1KB7.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-
|
|
747
|
+
//# sourceMappingURL=devtools-B4prrxht.js.map
|