brumate 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{boot-CMy0f_iC.d.ts → boot-BkUdiYOF.d.ts} +2 -2
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -1
- package/dist/{client-Bm0XbjHr.js → client-B0FXW5Kw.js} +50 -15
- package/dist/client-B0FXW5Kw.js.map +1 -0
- package/dist/{client-DnFF9_lv.d.ts → client-Cq6aTiDs.d.ts} +15 -7
- package/dist/{defer-BWwxv7Qf.js → defer-BMIMP4Hq.js} +3 -3
- package/dist/{defer-BWwxv7Qf.js.map → defer-BMIMP4Hq.js.map} +1 -1
- package/dist/{devtools-Cl6AhENB.js → devtools-B4prrxht.js} +258 -118
- package/dist/devtools-B4prrxht.js.map +1 -0
- package/dist/devtools-calls-DGW6nLZ2.js +249 -0
- package/dist/devtools-calls-DGW6nLZ2.js.map +1 -0
- package/dist/devtools-panel-B1nF1KB7.js +3978 -0
- package/dist/devtools-panel-B1nF1KB7.js.map +1 -0
- package/dist/error-catalog-DakxjSgj.js +308 -0
- package/dist/error-catalog-DakxjSgj.js.map +1 -0
- package/dist/error-catalog-VxLbz-6p.js +1 -0
- package/dist/{files-BuQvpBwF.js → files-D5GtxwEQ.js} +2 -2
- package/dist/{files-BuQvpBwF.js.map → files-D5GtxwEQ.js.map} +1 -1
- package/dist/index.d.ts +73 -18
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/{inspect-BSHv1_25.js → inspect-CGl5Y8q6.js} +581 -399
- package/dist/inspect-CGl5Y8q6.js.map +1 -0
- package/dist/{loader-BPNSRA2A.js → loader-BsaSuIoG.js} +4 -4
- package/dist/{loader-BPNSRA2A.js.map → loader-BsaSuIoG.js.map} +1 -1
- package/dist/{navigate-r23FFR6e.js → navigate-BlowKvhB.js} +18 -10
- package/dist/navigate-BlowKvhB.js.map +1 -0
- package/dist/{rpc-DqfCaYgF.js → rpc-C1jYVNAe.js} +5 -4
- package/dist/rpc-C1jYVNAe.js.map +1 -0
- package/dist/runtime/bundles.d.ts +1 -1
- package/dist/runtime/client.d.ts +2 -2
- package/dist/runtime/client.js +4 -3
- package/dist/runtime/devtools.d.ts +59 -1
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/hot.js +6 -2
- package/dist/runtime/hot.js.map +1 -1
- package/dist/runtime/loader.d.ts +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/server.d.ts +1 -1
- package/dist/runtime/server.js +3 -2
- package/dist/runtime/signals.d.ts +1 -1
- package/dist/runtime/static-loader.d.ts +2 -2
- package/dist/runtime/static-loader.js +1 -1
- package/dist/runtime/store.d.ts +2 -2
- package/dist/runtime/store.js +1 -1
- package/dist/runtime/testing.d.ts +2 -2
- package/dist/runtime/testing.js +2 -2
- package/dist/search-params-Wg-0FsMj.js +148 -0
- package/dist/search-params-Wg-0FsMj.js.map +1 -0
- package/dist/{stream-RXLadXx1.js → serial-ioa17MuY.js} +67 -168
- package/dist/serial-ioa17MuY.js.map +1 -0
- package/dist/serial-ribg9NAj.js +1 -0
- package/dist/{server-BVObWh-w.js → server-BUuf7XPZ.js} +61 -16
- package/dist/server-BUuf7XPZ.js.map +1 -0
- package/dist/{server-0rS5vUW1.d.ts → server-DesBZv5g.d.ts} +8 -3
- package/dist/{search-params-C64liRBj.js → shared-CX_YacDm.js} +3 -148
- package/dist/shared-CX_YacDm.js.map +1 -0
- package/dist/{signals-DBnq9QRW.d.ts → signals-7VVD9C_H.d.ts} +2 -2
- package/dist/skew-CwmX_GFI.js +21 -0
- package/dist/skew-CwmX_GFI.js.map +1 -0
- package/dist/{static-loader-V4V1Oy6G.js → static-loader-C_en-4v8.js} +2 -2
- package/dist/{static-loader-V4V1Oy6G.js.map → static-loader-C_en-4v8.js.map} +1 -1
- package/dist/{static-loader-BYbXVJDY.d.ts → static-loader-UKnK11Em.d.ts} +2 -2
- package/dist/{store-xlTzAM_r.d.ts → store-9_oa0HG1.d.ts} +15 -2
- package/dist/{store-BIBAYZo-.js → store-Cy4EEyZ7.js} +148 -2
- package/dist/store-Cy4EEyZ7.js.map +1 -0
- package/dist/stream-read-BTsYstJY.js +22 -0
- package/dist/stream-read-BTsYstJY.js.map +1 -0
- package/dist/stream-read-Dek3HnqO.js +1 -0
- package/dist/{skew-FRmAy9iy.js → trusted-g_zUJbh2.js} +11 -22
- package/dist/trusted-g_zUJbh2.js.map +1 -0
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +37 -5
- package/dist/vite.js.map +1 -1
- package/package.json +7 -4
- package/skills/brumate/SKILL.md +6 -2
- package/skills/brumate/references/errors.md +21 -2
- package/skills/brumate/references/state.md +31 -0
- package/skills/brumate/references/syntax.md +45 -1
- package/dist/client-Bm0XbjHr.js.map +0 -1
- package/dist/devtools-Cl6AhENB.js.map +0 -1
- package/dist/devtools-panel-DLIeWcAj.js +0 -2017
- package/dist/devtools-panel-DLIeWcAj.js.map +0 -1
- package/dist/inspect-BSHv1_25.js.map +0 -1
- package/dist/navigate-r23FFR6e.js.map +0 -1
- package/dist/rpc-DqfCaYgF.js.map +0 -1
- package/dist/search-params-C64liRBj.js.map +0 -1
- package/dist/server-BVObWh-w.js.map +0 -1
- package/dist/skew-FRmAy9iy.js.map +0 -1
- package/dist/store-BIBAYZo-.js.map +0 -1
- package/dist/stream-RXLadXx1.js.map +0 -1
|
@@ -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,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as
|
|
1
|
+
import { bn as skew, gn as build } from "./client-B0FXW5Kw.js";
|
|
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. */
|
|
5
5
|
function readNonce(script) {
|
|
@@ -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,6 +1,207 @@
|
|
|
1
|
+
import { t as trustedHTML } from "./trusted-g_zUJbh2.js";
|
|
1
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
|
|
2
201
|
//#region src/runtime/devtools.ts
|
|
3
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");
|
|
4
205
|
const MAX_LOG = 300;
|
|
5
206
|
/** The root scope of a scope, whose `m` names its component. */
|
|
6
207
|
function findRootScope(scope) {
|
|
@@ -147,96 +348,7 @@ function reportError(state, payload, source) {
|
|
|
147
348
|
}
|
|
148
349
|
/** The code of the panel, which loads when it opens. */
|
|
149
350
|
function panelModule() {
|
|
150
|
-
return import("./devtools-panel-
|
|
151
|
-
}
|
|
152
|
-
/** Where the choice to outline changed elements is kept. */
|
|
153
|
-
const FLASH_KEY = "brumate:devtools:flash";
|
|
154
|
-
/** How long an outline shows. */
|
|
155
|
-
const FLASH_MS = 700;
|
|
156
|
-
/** The most outlines that one frame draws, so a big change does not stall the page. */
|
|
157
|
-
const MAX_FLASHES = 200;
|
|
158
|
-
/** The class of an outline, by how many times the element changed in the last second. */
|
|
159
|
-
function heatClass(count) {
|
|
160
|
-
if (count >= 5) return "hot";
|
|
161
|
-
return count >= 2 ? "warm" : "";
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Outlines the elements that change, as an update writes them: green for an
|
|
165
|
-
* element that changes now and then, yellow and red for one that changes
|
|
166
|
-
* often. A MutationObserver sees every change of the page, so it needs no
|
|
167
|
-
* hook of the core. The outlines are drawn in the shadow root, so the page
|
|
168
|
-
* itself does not change.
|
|
169
|
-
*/
|
|
170
|
-
function installFlash(state, root, host) {
|
|
171
|
-
const layer = document.createElement("div");
|
|
172
|
-
layer.className = "flashes";
|
|
173
|
-
root.append(layer);
|
|
174
|
-
const heat = /* @__PURE__ */ new WeakMap();
|
|
175
|
-
const pending = /* @__PURE__ */ new Set();
|
|
176
|
-
let frame = 0;
|
|
177
|
-
function draw() {
|
|
178
|
-
frame = 0;
|
|
179
|
-
let drawn = 0;
|
|
180
|
-
for (const target of pending) {
|
|
181
|
-
if (drawn >= MAX_FLASHES) break;
|
|
182
|
-
const rect = target.getBoundingClientRect();
|
|
183
|
-
if (rect.width === 0 && rect.height === 0) continue;
|
|
184
|
-
const now = performance.now();
|
|
185
|
-
const last = heat.get(target);
|
|
186
|
-
const count = last && now - last.time < 1e3 ? last.count + 1 : 1;
|
|
187
|
-
heat.set(target, {
|
|
188
|
-
count,
|
|
189
|
-
time: now
|
|
190
|
-
});
|
|
191
|
-
const box = document.createElement("div");
|
|
192
|
-
box.className = `flash ${heatClass(count)}`;
|
|
193
|
-
box.style.cssText = `left:${rect.left}px;top:${rect.top}px;width:${rect.width}px;height:${rect.height}px`;
|
|
194
|
-
layer.append(box);
|
|
195
|
-
setTimeout(() => box.remove(), FLASH_MS);
|
|
196
|
-
drawn++;
|
|
197
|
-
}
|
|
198
|
-
pending.clear();
|
|
199
|
-
}
|
|
200
|
-
const observer = new MutationObserver((records) => {
|
|
201
|
-
for (const record of records) {
|
|
202
|
-
let target = record.target;
|
|
203
|
-
if (record.type === "childList") {
|
|
204
|
-
let added = 0;
|
|
205
|
-
for (const node of record.addedNodes) if (node.nodeType === 1) {
|
|
206
|
-
pending.add(node);
|
|
207
|
-
added++;
|
|
208
|
-
}
|
|
209
|
-
if (added > 0) continue;
|
|
210
|
-
}
|
|
211
|
-
if (target.nodeType !== 1) target = target.parentElement;
|
|
212
|
-
if (target && target !== host && target !== document.documentElement && target !== document.body) pending.add(target);
|
|
213
|
-
}
|
|
214
|
-
for (const target of pending) if (target === host || host.contains(target)) pending.delete(target);
|
|
215
|
-
if (pending.size > 0 && frame === 0) frame = requestAnimationFrame(draw);
|
|
216
|
-
});
|
|
217
|
-
state.setFlash = (on) => {
|
|
218
|
-
state.flash = on;
|
|
219
|
-
if (on) observer.observe(document.documentElement, {
|
|
220
|
-
subtree: true,
|
|
221
|
-
childList: true,
|
|
222
|
-
attributes: true,
|
|
223
|
-
characterData: true
|
|
224
|
-
});
|
|
225
|
-
else {
|
|
226
|
-
observer.disconnect();
|
|
227
|
-
pending.clear();
|
|
228
|
-
layer.replaceChildren();
|
|
229
|
-
}
|
|
230
|
-
try {
|
|
231
|
-
localStorage.setItem(FLASH_KEY, on ? "1" : "0");
|
|
232
|
-
} catch {}
|
|
233
|
-
state.changed?.();
|
|
234
|
-
};
|
|
235
|
-
let saved = false;
|
|
236
|
-
try {
|
|
237
|
-
saved = localStorage.getItem(FLASH_KEY) === "1";
|
|
238
|
-
} catch {}
|
|
239
|
-
if (saved) state.setFlash(true);
|
|
351
|
+
return import("./devtools-panel-B1nF1KB7.js");
|
|
240
352
|
}
|
|
241
353
|
/** True for an error of code that is not of the page, such as of a browser extension. */
|
|
242
354
|
function foreign(stack, file = "") {
|
|
@@ -244,6 +356,8 @@ function foreign(stack, file = "") {
|
|
|
244
356
|
}
|
|
245
357
|
/** Listens to the core, and adds the button that opens the panel. */
|
|
246
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;
|
|
247
361
|
const state = {
|
|
248
362
|
log: [],
|
|
249
363
|
blocks: /* @__PURE__ */ new Map(),
|
|
@@ -395,7 +509,8 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
|
|
|
395
509
|
state.changed?.();
|
|
396
510
|
return true;
|
|
397
511
|
};
|
|
398
|
-
const
|
|
512
|
+
const unwrapped = installed && globalThis.fetch === installed.wrapper ? installed.fetch : globalThis.fetch;
|
|
513
|
+
const original = unwrapped.bind(globalThis);
|
|
399
514
|
globalThis.fetch = async (input, init) => {
|
|
400
515
|
const url = new URL(input instanceof Request ? input.url : String(input), location.href);
|
|
401
516
|
if (url.origin !== location.origin || !url.pathname.startsWith(`${rpc}/`)) return original(input, init);
|
|
@@ -405,6 +520,14 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
|
|
|
405
520
|
name,
|
|
406
521
|
start: started
|
|
407
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
|
+
};
|
|
408
531
|
owner(started)?.calls.push(call);
|
|
409
532
|
try {
|
|
410
533
|
const response = await original(input, init);
|
|
@@ -414,10 +537,24 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
|
|
|
414
537
|
call.status = redirect ? "redirect" : response.status;
|
|
415
538
|
const server = /brumate;dur=([\d.]+)/.exec(response.headers.get("server-timing") ?? "");
|
|
416
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(() => {});
|
|
417
553
|
state.changed?.();
|
|
418
554
|
add({
|
|
419
555
|
kind: "call",
|
|
420
|
-
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
|
|
421
558
|
});
|
|
422
559
|
return response;
|
|
423
560
|
} catch (error) {
|
|
@@ -425,7 +562,8 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
|
|
|
425
562
|
call.status = "failed";
|
|
426
563
|
add({
|
|
427
564
|
kind: "call",
|
|
428
|
-
text: `${name}: failed, ${error instanceof Error ? error.message : String(error)}
|
|
565
|
+
text: `${name}: failed, ${error instanceof Error ? error.message : String(error)}`,
|
|
566
|
+
call
|
|
429
567
|
});
|
|
430
568
|
throw error;
|
|
431
569
|
}
|
|
@@ -448,7 +586,7 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
|
|
|
448
586
|
});
|
|
449
587
|
}
|
|
450
588
|
state.fire = (block) => {
|
|
451
|
-
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)));
|
|
452
590
|
else if (block.template && block.ref) state.handle?.(block.template, block.ref);
|
|
453
591
|
};
|
|
454
592
|
if (typeof MutationObserver !== "undefined") {
|
|
@@ -469,36 +607,37 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
|
|
|
469
607
|
}
|
|
470
608
|
scanBlocks(state);
|
|
471
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];
|
|
472
618
|
const root = host.attachShadow({ mode: "open" });
|
|
473
619
|
const style = document.createElement("style");
|
|
474
620
|
style.textContent = `
|
|
475
|
-
.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; }
|
|
476
622
|
.open[hidden] { display: none; }
|
|
477
|
-
.
|
|
478
|
-
.open[data-errors]
|
|
479
|
-
.
|
|
480
|
-
.open:hover
|
|
481
|
-
.open:hover
|
|
482
|
-
.
|
|
483
|
-
.
|
|
484
|
-
.version {
|
|
485
|
-
.
|
|
486
|
-
.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; }
|
|
487
632
|
.count:empty { display: none; }
|
|
488
|
-
|
|
489
|
-
.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; }
|
|
490
|
-
.flash.warm { border-color: #ffd166; background: rgb(255 209 102 / 0.1); }
|
|
491
|
-
.flash.hot { border-color: #ff7a7a; background: rgb(255 122 122 / 0.12); }
|
|
492
|
-
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
|
|
493
|
-
@media (prefers-reduced-motion: reduce) { .flash { animation: none; } }
|
|
494
|
-
@media (prefers-reduced-motion: reduce) { .grip, .content { transition: none; } }
|
|
633
|
+
@media (prefers-reduced-motion: reduce) { .open, .open > * { transition: none; } }
|
|
495
634
|
`;
|
|
496
635
|
const button = document.createElement("button");
|
|
497
636
|
button.type = "button";
|
|
498
637
|
button.className = "open";
|
|
499
638
|
button.title = "brumate devtools (Alt+Shift+D)";
|
|
500
|
-
button.innerHTML = `<span class="
|
|
501
|
-
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 ?? "";
|
|
502
641
|
function label() {
|
|
503
642
|
const errors = state.errors.length;
|
|
504
643
|
button.setAttribute("aria-label", `Open the brumate devtools${meta.version ? `, version ${meta.version}` : ""}${errors > 0 ? `, ${errors} errors` : ""}`);
|
|
@@ -506,7 +645,7 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
|
|
|
506
645
|
label();
|
|
507
646
|
const count = button.querySelector(".count");
|
|
508
647
|
state.errorCount = () => {
|
|
509
|
-
count.textContent = state.errors.length > 0 ?
|
|
648
|
+
count.textContent = state.errors.length > 0 ? `${state.errors.length} ${state.errors.length === 1 ? "issue" : "issues"}` : "";
|
|
510
649
|
button.toggleAttribute("data-errors", state.errors.length > 0);
|
|
511
650
|
label();
|
|
512
651
|
};
|
|
@@ -522,7 +661,7 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
|
|
|
522
661
|
opened = true;
|
|
523
662
|
dragged = true;
|
|
524
663
|
panelModule().then(({ openPanel }) => {
|
|
525
|
-
openPanel(root, state
|
|
664
|
+
openPanel(root, state);
|
|
526
665
|
state.resize?.(next.clientY);
|
|
527
666
|
});
|
|
528
667
|
return;
|
|
@@ -553,7 +692,7 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
|
|
|
553
692
|
}
|
|
554
693
|
});
|
|
555
694
|
state.open = (tab) => {
|
|
556
|
-
import("./devtools-panel-
|
|
695
|
+
import("./devtools-panel-B1nF1KB7.js").then(({ openPanel }) => openPanel(root, state, tab));
|
|
557
696
|
};
|
|
558
697
|
root.append(style, button);
|
|
559
698
|
installFlash(state, root, host);
|
|
@@ -596,6 +735,7 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
|
|
|
596
735
|
});
|
|
597
736
|
function append() {
|
|
598
737
|
document.documentElement.append(host);
|
|
738
|
+
mark.appended = true;
|
|
599
739
|
}
|
|
600
740
|
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", append);
|
|
601
741
|
else append();
|
|
@@ -604,4 +744,4 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
|
|
|
604
744
|
//#endregion
|
|
605
745
|
export { preview as a, nextBlockState as i, installDevtools as n, reportError as o, moveBlock as r, scanBlocks as s, findRootScope as t };
|
|
606
746
|
|
|
607
|
-
//# sourceMappingURL=devtools-
|
|
747
|
+
//# sourceMappingURL=devtools-B4prrxht.js.map
|