brumate 0.1.1 → 0.3.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-DN1ZU8Hg.d.ts → boot-C25Sa6vq.d.ts} +27 -2
- package/dist/cli.js +2 -2
- package/dist/client-BD6XT-s5.js +1968 -0
- package/dist/client-BD6XT-s5.js.map +1 -0
- package/dist/{client-DwJInP_a.d.ts → client-D0CqSxoO.d.ts} +211 -30
- package/dist/{client-routes-DakuM32C.js → client-routes-JTbGtukf.js} +28 -15
- package/dist/client-routes-JTbGtukf.js.map +1 -0
- package/dist/context-CTiSzQRc.js +27 -0
- package/dist/context-CTiSzQRc.js.map +1 -0
- package/dist/context-btHuB01Z.d.ts +42 -0
- package/dist/{cookies-Av5WFmcf.js → cookies-BzllthiF.js} +2 -1
- package/dist/cookies-BzllthiF.js.map +1 -0
- package/dist/defer-BbD7JQhj.js +56 -0
- package/dist/defer-BbD7JQhj.js.map +1 -0
- package/dist/devtools-CQgD7NPB.js +623 -0
- package/dist/devtools-CQgD7NPB.js.map +1 -0
- package/dist/devtools-panel-BVB-W5q4.js +1930 -0
- package/dist/devtools-panel-BVB-W5q4.js.map +1 -0
- package/dist/events-CSs7OwIC.js +85 -0
- package/dist/events-CSs7OwIC.js.map +1 -0
- package/dist/{files-DdT84mPy.js → files-BXSSrQgc.js} +34 -6
- package/dist/files-BXSSrQgc.js.map +1 -0
- package/dist/forms-Bg-CwGqX.js +406 -0
- package/dist/forms-Bg-CwGqX.js.map +1 -0
- package/dist/forms-Cl21hkHt.d.ts +281 -0
- package/dist/highlight.d.ts +17 -0
- package/dist/highlight.js +269 -0
- package/dist/highlight.js.map +1 -0
- package/dist/html-Bq1rFxX_.d.ts +92 -0
- package/dist/html-mNTKzaDD.js +241 -0
- package/dist/html-mNTKzaDD.js.map +1 -0
- package/dist/index.d.ts +123 -30
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/dist/{inspect-BPchdWbU.js → inspect-BHpOw1LF.js} +1400 -121
- package/dist/inspect-BHpOw1LF.js.map +1 -0
- package/dist/{loader-Dc9OwY5I.js → loader-Dos_3NP0.js} +47 -11
- package/dist/loader-Dos_3NP0.js.map +1 -0
- package/dist/{navigate-CzLjnoPH.js → navigate-O78d_zGN.js} +115 -13
- package/dist/navigate-O78d_zGN.js.map +1 -0
- package/dist/produce-D0V0ICkz.d.ts +114 -0
- package/dist/produce-Doc91GkX.js +274 -0
- package/dist/produce-Doc91GkX.js.map +1 -0
- package/dist/routes-BZNt7DSZ.d.ts +38 -0
- package/dist/{rpc-9fSqL_YK.js → rpc-ygMRPmN4.js} +39 -23
- package/dist/rpc-ygMRPmN4.js.map +1 -0
- package/dist/runtime/batch.d.ts +23 -0
- package/dist/runtime/batch.js +69 -0
- package/dist/runtime/batch.js.map +1 -0
- package/dist/runtime/client.d.ts +5 -5
- package/dist/runtime/client.js +5 -1345
- package/dist/runtime/context.d.ts +2 -2
- package/dist/runtime/context.js +1 -1
- package/dist/runtime/devtools.d.ts +191 -5
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/env.d.ts +44 -0
- package/dist/runtime/env.js +61 -0
- package/dist/runtime/env.js.map +1 -0
- package/dist/runtime/events.d.ts +42 -0
- package/dist/runtime/events.js +1 -0
- package/dist/runtime/forms.d.ts +2 -0
- package/dist/runtime/forms.js +1 -0
- package/dist/runtime/gather.d.ts +25 -0
- package/dist/runtime/gather.js +33 -0
- package/dist/runtime/gather.js.map +1 -0
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/html.d.ts +2 -2
- package/dist/runtime/html.js +1 -1
- package/dist/runtime/loader.d.ts +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/routes.d.ts +2 -21
- package/dist/runtime/routes.js +31 -1
- package/dist/runtime/routes.js.map +1 -1
- package/dist/runtime/server.d.ts +7 -5
- package/dist/runtime/server.js +6 -7
- package/dist/runtime/signals.d.ts +60 -3
- package/dist/runtime/signals.js +40 -2
- package/dist/runtime/signals.js.map +1 -1
- package/dist/runtime/static-loader.d.ts +2 -2
- package/dist/runtime/static-loader.js +1 -1
- package/dist/runtime/testing.d.ts +46 -5
- package/dist/runtime/testing.js +240 -33
- package/dist/runtime/testing.js.map +1 -1
- package/dist/runtime/values.d.ts +2 -0
- package/dist/runtime/values.js +24 -0
- package/dist/runtime/values.js.map +1 -0
- package/dist/secrets-BxagsJxJ.js +23 -0
- package/dist/secrets-BxagsJxJ.js.map +1 -0
- package/dist/server-CxVDYE_V.js +3417 -0
- package/dist/server-CxVDYE_V.js.map +1 -0
- package/dist/server-DuFYRXrd.d.ts +1460 -0
- package/dist/skew-FRmAy9iy.js +49 -0
- package/dist/skew-FRmAy9iy.js.map +1 -0
- package/dist/standard-schema-BNY82yX3.d.ts +63 -0
- package/dist/{static-loader-BcFh4ebX.d.ts → static-loader-Drpr0AzI.d.ts} +2 -2
- package/dist/static-loader-nZssh66R.js +333 -0
- package/dist/static-loader-nZssh66R.js.map +1 -0
- package/dist/stream-DCYZO4IF.js +424 -0
- package/dist/stream-DCYZO4IF.js.map +1 -0
- package/dist/values-B8C7CLvG.d.ts +63 -0
- package/dist/vite.d.ts +49 -1
- package/dist/vite.js +598 -68
- package/dist/vite.js.map +1 -1
- package/forms/forms.brm.ts +141 -0
- package/package.json +45 -3
- package/types.d.ts +9 -1
- package/dist/client-routes-DakuM32C.js.map +0 -1
- package/dist/context-BG8KCF3v.js +0 -15
- package/dist/context-BG8KCF3v.js.map +0 -1
- package/dist/context-aeo9esY9.d.ts +0 -16
- package/dist/cookies-Av5WFmcf.js.map +0 -1
- package/dist/devtools-BKjnHrnv.js +0 -113
- package/dist/devtools-BKjnHrnv.js.map +0 -1
- package/dist/devtools-panel-AWOn0VK2.js +0 -434
- package/dist/devtools-panel-AWOn0VK2.js.map +0 -1
- package/dist/files-DdT84mPy.js.map +0 -1
- package/dist/html-DEeoepg3.js +0 -152
- package/dist/html-DEeoepg3.js.map +0 -1
- package/dist/html-Du8jY2Cc.d.ts +0 -53
- package/dist/inspect-BPchdWbU.js.map +0 -1
- package/dist/loader-Dc9OwY5I.js.map +0 -1
- package/dist/navigate-CzLjnoPH.js.map +0 -1
- package/dist/produce-BRGHP7e0.js +0 -126
- package/dist/produce-BRGHP7e0.js.map +0 -1
- package/dist/produce-CtZ32UGG.d.ts +0 -60
- package/dist/rpc-9fSqL_YK.js.map +0 -1
- package/dist/runtime/client.js.map +0 -1
- package/dist/server-BxqjLUnV.d.ts +0 -753
- package/dist/server-DZsgnPKS.js +0 -1615
- package/dist/server-DZsgnPKS.js.map +0 -1
- package/dist/shared-CWYOd0H3.js +0 -40
- package/dist/shared-CWYOd0H3.js.map +0 -1
- package/dist/static-loader-ClNkHZGn.js +0 -185
- package/dist/static-loader-ClNkHZGn.js.map +0 -1
- package/dist/stream-bgNCMcaA.js +0 -280
- package/dist/stream-bgNCMcaA.js.map +0 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { n as trustedHTML, r as trustedScript } from "./skew-FRmAy9iy.js";
|
|
2
|
+
import { dt as skew, p as build } from "./client-BD6XT-s5.js";
|
|
3
|
+
//#region src/runtime/defer.ts
|
|
4
|
+
/** The nonce of a script. Browsers hide the attribute once the page loads, and keep the property. */
|
|
5
|
+
function nonceOf(script) {
|
|
6
|
+
return script.nonce || script.getAttribute("nonce");
|
|
7
|
+
}
|
|
8
|
+
/** The Content Security Policy nonce of the page, which the scripts of the answer need to run. */
|
|
9
|
+
function pageNonce() {
|
|
10
|
+
for (const script of document.querySelectorAll("script")) {
|
|
11
|
+
const nonce = nonceOf(script);
|
|
12
|
+
if (nonce) return nonce;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** The templates whose bodies were asked for. */
|
|
16
|
+
const requested = /* @__PURE__ */ new WeakSet();
|
|
17
|
+
/**
|
|
18
|
+
* Asks the server for the body of the `#defer` block of a `<template
|
|
19
|
+
* b-defer>`, and puts it in place of the fallback. When the server cannot
|
|
20
|
+
* render it, such as a page that changed since it loaded, or a static host
|
|
21
|
+
* that answers with the whole page, the fallback stays.
|
|
22
|
+
*/
|
|
23
|
+
async function loadDeferred(template) {
|
|
24
|
+
if (requested.has(template)) return;
|
|
25
|
+
requested.add(template);
|
|
26
|
+
const [, boundary, base] = template.getAttribute("b-defer").split(":");
|
|
27
|
+
const response = await fetch(location.href, { headers: {
|
|
28
|
+
"x-brumate-defer": `${boundary} ${template.getAttribute("b-b")}`,
|
|
29
|
+
"x-brumate-base": base,
|
|
30
|
+
...build === void 0 ? {} : { "x-brumate-build": build }
|
|
31
|
+
} });
|
|
32
|
+
if (response.status === 409 && response.headers.get("x-brumate-build")) {
|
|
33
|
+
skew("defer");
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!response.ok || response.headers.get("x-brumate-defer") !== boundary) return;
|
|
37
|
+
const parsed = document.createElement("template");
|
|
38
|
+
parsed.innerHTML = trustedHTML(await response.text());
|
|
39
|
+
const nonce = pageNonce();
|
|
40
|
+
for (const node of Array.from(parsed.content.childNodes)) {
|
|
41
|
+
if (node.nodeName !== "SCRIPT") {
|
|
42
|
+
document.body.append(node);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const script = node;
|
|
46
|
+
const copy = document.createElement("script");
|
|
47
|
+
for (const attribute of script.attributes) if (attribute.name !== "nonce") copy.setAttribute(attribute.name, attribute.value);
|
|
48
|
+
if (nonce) copy.nonce = nonce;
|
|
49
|
+
copy.textContent = trustedScript(script.textContent ?? "");
|
|
50
|
+
document.body.append(copy);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { loadDeferred };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=defer-BbD7JQhj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defer-BbD7JQhj.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 nonceOf(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 = nonceOf(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,QAAQ,QAA0C;CACzD,OAAO,OAAO,SAAS,OAAO,aAAa,OAAO;AACpD;;AAGA,SAAS,YAAgC;CACvC,KAAK,MAAM,UAAU,SAAS,iBAAiB,QAAQ,GAAG;EACxD,MAAM,QAAQ,QAAQ,MAAM;EAC5B,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"}
|
|
@@ -0,0 +1,623 @@
|
|
|
1
|
+
//#region src/runtime/devtools.ts
|
|
2
|
+
const DEVTOOLS = Symbol.for("brumate.devtools");
|
|
3
|
+
/** The loads that are preloads, which the Loading tab marks when nothing used them. */
|
|
4
|
+
const PRELOADS = /* @__PURE__ */ new Set([
|
|
5
|
+
"hover",
|
|
6
|
+
"visible",
|
|
7
|
+
"idle",
|
|
8
|
+
"eager"
|
|
9
|
+
]);
|
|
10
|
+
const MAX_LOG = 300;
|
|
11
|
+
/**
|
|
12
|
+
* The logo of brumate: the pole and the bowl of a b, in outline, where the
|
|
13
|
+
* pole runs through the left of the bowl. The part they share is orange.
|
|
14
|
+
*/
|
|
15
|
+
const LOGO = `<svg viewBox="0 0 32 32" width="100%" height="100%" aria-hidden="true"><defs><linearGradient id="brumate-logo-fill" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#ffc38a"/><stop offset=".5" stop-color="#ee7a3e"/><stop offset="1" stop-color="#e0445a"/></linearGradient><clipPath id="brumate-logo-pole"><rect x="7.5" y="2.5" width="8" height="27" rx="4"/></clipPath></defs><circle cx="18" cy="19.5" r="10" fill="url(#brumate-logo-fill)" clip-path="url(#brumate-logo-pole)"/><g fill="none" stroke="#ece8e4" stroke-width="2.2"><rect x="7.5" y="2.5" width="8" height="27" rx="4"/><circle cx="18" cy="19.5" r="10"/></g></svg>`;
|
|
16
|
+
/** The root scope of a scope, whose `m` names its component. */
|
|
17
|
+
function rootOf(scope) {
|
|
18
|
+
let root = scope;
|
|
19
|
+
while (root.p) root = root.p;
|
|
20
|
+
return root;
|
|
21
|
+
}
|
|
22
|
+
/** A short text for a value in the log. */
|
|
23
|
+
function preview(value) {
|
|
24
|
+
if (typeof value === "string") return JSON.stringify(value.length > 40 ? `${value.slice(0, 40)}…` : value);
|
|
25
|
+
if (typeof value === "function") return "function";
|
|
26
|
+
if (Array.isArray(value)) return `Array(${value.length})`;
|
|
27
|
+
if (value instanceof Element) return `<${value.tagName.toLowerCase()}>`;
|
|
28
|
+
if (value !== null && typeof value === "object") {
|
|
29
|
+
const name = value.constructor?.name;
|
|
30
|
+
return name && name !== "Object" ? name : `{${Object.keys(value).slice(0, 3).join(", ")}}`;
|
|
31
|
+
}
|
|
32
|
+
return String(value);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Reads the blocks of the page from their markers, and updates their state.
|
|
36
|
+
* Returns true when something changed.
|
|
37
|
+
*
|
|
38
|
+
* - `#defer`: a `<template b-defer>`, and `<!--l…-->` around its fallback until its body arrives.
|
|
39
|
+
* - `#loading`: `<!--l…-->` around its fallback until the server streams its body.
|
|
40
|
+
* - `#client`: a `<template b-client>` with a `#k` reference, and a marker that gets `:1` once
|
|
41
|
+
* its body rendered.
|
|
42
|
+
* - `$client`: a `<template b-client>` with a `#c` reference.
|
|
43
|
+
*/
|
|
44
|
+
function scanBlocks(state) {
|
|
45
|
+
const now = performance.now();
|
|
46
|
+
let changed = false;
|
|
47
|
+
const open = /* @__PURE__ */ new Map();
|
|
48
|
+
const markers = /* @__PURE__ */ new Map();
|
|
49
|
+
const walker = document.createTreeWalker(document, NodeFilter.SHOW_COMMENT);
|
|
50
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
51
|
+
const data = node.data;
|
|
52
|
+
if (/^l[\d.-]+$/.test(data)) open.set(data.slice(1), node);
|
|
53
|
+
else if (/^b-?[\d.]+:\d+/.test(data)) markers.set(data.slice(1).split(":").slice(0, 2).join(":"), node);
|
|
54
|
+
}
|
|
55
|
+
const seen = /* @__PURE__ */ new Set();
|
|
56
|
+
const update = (key, make, next) => {
|
|
57
|
+
seen.add(key);
|
|
58
|
+
let block = state.blocks.get(key);
|
|
59
|
+
if (!block) {
|
|
60
|
+
block = make();
|
|
61
|
+
state.blocks.set(key, block);
|
|
62
|
+
changed = true;
|
|
63
|
+
}
|
|
64
|
+
if (block.state === "rendered" || block.state === next) return;
|
|
65
|
+
if (block.state === "loading" && next === "waiting") return;
|
|
66
|
+
block.state = next;
|
|
67
|
+
if (next === "rendered") block.rendered = now;
|
|
68
|
+
changed = true;
|
|
69
|
+
};
|
|
70
|
+
const deferBoundaries = /* @__PURE__ */ new Set();
|
|
71
|
+
for (const template of document.querySelectorAll("template[b-defer]")) {
|
|
72
|
+
const [trigger, boundary] = template.getAttribute("b-defer").split(":");
|
|
73
|
+
deferBoundaries.add(boundary);
|
|
74
|
+
update(`defer:${boundary}`, () => ({
|
|
75
|
+
kind: "defer",
|
|
76
|
+
id: boundary,
|
|
77
|
+
trigger,
|
|
78
|
+
template,
|
|
79
|
+
state: "waiting",
|
|
80
|
+
seen: now
|
|
81
|
+
}), open.has(boundary) ? "waiting" : "rendered");
|
|
82
|
+
}
|
|
83
|
+
for (const boundary of open.keys()) if (!deferBoundaries.has(boundary)) update(`loading:${boundary}`, () => ({
|
|
84
|
+
kind: "loading",
|
|
85
|
+
id: boundary,
|
|
86
|
+
state: "streaming",
|
|
87
|
+
seen: now
|
|
88
|
+
}), "streaming");
|
|
89
|
+
for (const template of document.querySelectorAll("template[b-client]")) {
|
|
90
|
+
const [trigger, ref] = template.getAttribute("b-client").split("=");
|
|
91
|
+
const id = template.getAttribute("b-b") ?? "";
|
|
92
|
+
const block = /#k\d+$/.test(ref);
|
|
93
|
+
const marker = markers.get(id);
|
|
94
|
+
update(`client:${id}`, () => ({
|
|
95
|
+
kind: block ? "client" : "$client",
|
|
96
|
+
id,
|
|
97
|
+
trigger,
|
|
98
|
+
ref,
|
|
99
|
+
template,
|
|
100
|
+
state: "waiting",
|
|
101
|
+
seen: now
|
|
102
|
+
}), (block ? marker && marker.data.split(":").length > 2 : state.blocks.get(`client:${id}`)?.fired) ? "rendered" : "waiting");
|
|
103
|
+
}
|
|
104
|
+
for (const [key, block] of state.blocks) {
|
|
105
|
+
if (seen.has(key)) continue;
|
|
106
|
+
if (block.kind === "loading") {
|
|
107
|
+
if (block.state === "streaming") {
|
|
108
|
+
block.state = "rendered";
|
|
109
|
+
block.rendered = now;
|
|
110
|
+
changed = true;
|
|
111
|
+
}
|
|
112
|
+
} else if (!block.template?.isConnected) {
|
|
113
|
+
state.blocks.delete(key);
|
|
114
|
+
changed = true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return changed;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Adds an error to the Errors tab. An error of the server or of Vite opens
|
|
121
|
+
* the panel on it, as Vite's overlay would. An error of the browser only
|
|
122
|
+
* counts on the button.
|
|
123
|
+
*/
|
|
124
|
+
function reportError(state, payload, source) {
|
|
125
|
+
const file = payload.loc?.file ?? payload.id;
|
|
126
|
+
const entry = {
|
|
127
|
+
time: performance.now(),
|
|
128
|
+
source: source === "server" && payload.plugin ? "compile" : source,
|
|
129
|
+
message: payload.message,
|
|
130
|
+
...payload.stack ? { stack: payload.stack } : {},
|
|
131
|
+
...payload.frame ? { frame: payload.frame } : {},
|
|
132
|
+
...payload.plugin ? { plugin: payload.plugin } : {},
|
|
133
|
+
...payload.loc && file ? { loc: {
|
|
134
|
+
file,
|
|
135
|
+
line: payload.loc.line,
|
|
136
|
+
column: payload.loc.column
|
|
137
|
+
} } : {}
|
|
138
|
+
};
|
|
139
|
+
const last = state.errors.at(-1);
|
|
140
|
+
if (last?.message !== entry.message || last.stack !== entry.stack) {
|
|
141
|
+
state.errors.push(entry);
|
|
142
|
+
if (state.errors.length > 50) state.errors.shift();
|
|
143
|
+
}
|
|
144
|
+
state.errorCount?.();
|
|
145
|
+
state.changed?.();
|
|
146
|
+
if (source !== "browser") state.open?.("errors");
|
|
147
|
+
}
|
|
148
|
+
/** The code of the panel, which loads when it opens. */
|
|
149
|
+
const panelModule = () => import("./devtools-panel-BVB-W5q4.js");
|
|
150
|
+
/** Where the choice to outline changed elements is kept. */
|
|
151
|
+
const FLASH_KEY = "brumate:devtools:flash";
|
|
152
|
+
/** How long an outline shows. */
|
|
153
|
+
const FLASH_MS = 700;
|
|
154
|
+
/** The most outlines that one frame draws, so a big change does not stall the page. */
|
|
155
|
+
const MAX_FLASHES = 200;
|
|
156
|
+
/** The class of an outline, by how many times the element changed in the last second. */
|
|
157
|
+
function heatClass(count) {
|
|
158
|
+
if (count >= 5) return "hot";
|
|
159
|
+
return count >= 2 ? "warm" : "";
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Outlines the elements that change, as an update writes them: green for an
|
|
163
|
+
* element that changes now and then, yellow and red for one that changes
|
|
164
|
+
* often. A MutationObserver sees every change of the page, so it needs no
|
|
165
|
+
* hook of the core. The outlines are drawn in the shadow root, so the page
|
|
166
|
+
* itself does not change.
|
|
167
|
+
*/
|
|
168
|
+
function installFlash(state, root, host) {
|
|
169
|
+
const layer = document.createElement("div");
|
|
170
|
+
layer.className = "flashes";
|
|
171
|
+
root.append(layer);
|
|
172
|
+
const heat = /* @__PURE__ */ new WeakMap();
|
|
173
|
+
const pending = /* @__PURE__ */ new Set();
|
|
174
|
+
let frame = 0;
|
|
175
|
+
const draw = () => {
|
|
176
|
+
frame = 0;
|
|
177
|
+
let drawn = 0;
|
|
178
|
+
for (const target of pending) {
|
|
179
|
+
if (drawn >= MAX_FLASHES) break;
|
|
180
|
+
const rect = target.getBoundingClientRect();
|
|
181
|
+
if (rect.width === 0 && rect.height === 0) continue;
|
|
182
|
+
const now = performance.now();
|
|
183
|
+
const last = heat.get(target);
|
|
184
|
+
const count = last && now - last.time < 1e3 ? last.count + 1 : 1;
|
|
185
|
+
heat.set(target, {
|
|
186
|
+
count,
|
|
187
|
+
time: now
|
|
188
|
+
});
|
|
189
|
+
const box = document.createElement("div");
|
|
190
|
+
box.className = `flash ${heatClass(count)}`;
|
|
191
|
+
box.style.cssText = `left:${rect.left}px;top:${rect.top}px;width:${rect.width}px;height:${rect.height}px`;
|
|
192
|
+
layer.append(box);
|
|
193
|
+
setTimeout(() => box.remove(), FLASH_MS);
|
|
194
|
+
drawn++;
|
|
195
|
+
}
|
|
196
|
+
pending.clear();
|
|
197
|
+
};
|
|
198
|
+
const observer = new MutationObserver((records) => {
|
|
199
|
+
for (const record of records) {
|
|
200
|
+
let target = record.target;
|
|
201
|
+
if (record.type === "childList") {
|
|
202
|
+
const added = [...record.addedNodes].filter((node) => node.nodeType === 1);
|
|
203
|
+
for (const node of added) pending.add(node);
|
|
204
|
+
if (added.length > 0) continue;
|
|
205
|
+
}
|
|
206
|
+
if (target.nodeType !== 1) target = target.parentElement;
|
|
207
|
+
if (target && target !== host && target !== document.documentElement && target !== document.body) pending.add(target);
|
|
208
|
+
}
|
|
209
|
+
for (const target of pending) if (target === host || host.contains(target)) pending.delete(target);
|
|
210
|
+
if (pending.size > 0 && frame === 0) frame = requestAnimationFrame(draw);
|
|
211
|
+
});
|
|
212
|
+
state.setFlash = (on) => {
|
|
213
|
+
state.flash = on;
|
|
214
|
+
if (on) observer.observe(document.documentElement, {
|
|
215
|
+
subtree: true,
|
|
216
|
+
childList: true,
|
|
217
|
+
attributes: true,
|
|
218
|
+
characterData: true
|
|
219
|
+
});
|
|
220
|
+
else {
|
|
221
|
+
observer.disconnect();
|
|
222
|
+
pending.clear();
|
|
223
|
+
layer.replaceChildren();
|
|
224
|
+
}
|
|
225
|
+
try {
|
|
226
|
+
localStorage.setItem(FLASH_KEY, on ? "1" : "0");
|
|
227
|
+
} catch {}
|
|
228
|
+
state.changed?.();
|
|
229
|
+
};
|
|
230
|
+
let saved = false;
|
|
231
|
+
try {
|
|
232
|
+
saved = localStorage.getItem(FLASH_KEY) === "1";
|
|
233
|
+
} catch {}
|
|
234
|
+
if (saved) state.setFlash(true);
|
|
235
|
+
}
|
|
236
|
+
/** True for an error of code that is not of the page, such as of a browser extension. */
|
|
237
|
+
const foreign = (stack, file = "") => /^[a-z-]+-extension:/.test(file) || stack !== void 0 && /[a-z-]+-extension:\/\//.test(stack) && !stack.includes(location.origin);
|
|
238
|
+
/** Listens to the core, and adds the button that opens the panel. */
|
|
239
|
+
function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", meta = {}, hot) {
|
|
240
|
+
const state = {
|
|
241
|
+
log: [],
|
|
242
|
+
loads: /* @__PURE__ */ new Map(),
|
|
243
|
+
blocks: /* @__PURE__ */ new Map(),
|
|
244
|
+
written: /* @__PURE__ */ new Set(),
|
|
245
|
+
endpoint,
|
|
246
|
+
meta,
|
|
247
|
+
errors: [],
|
|
248
|
+
timeline: [],
|
|
249
|
+
effects: /* @__PURE__ */ new Map(),
|
|
250
|
+
navigations: [],
|
|
251
|
+
flash: false
|
|
252
|
+
};
|
|
253
|
+
/** The handler that a server call or an update that starts now belongs to. */
|
|
254
|
+
const owner = (time) => {
|
|
255
|
+
for (let index = state.timeline.length - 1; index >= 0; index--) {
|
|
256
|
+
const run = state.timeline[index];
|
|
257
|
+
if (run.begun <= time && (run.settled === void 0 || time <= run.settled + 32)) return run;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
const load = (component, part, reason, done) => {
|
|
261
|
+
const key = `${component}:${part}`;
|
|
262
|
+
const known = state.loads.get(key);
|
|
263
|
+
if (known) {
|
|
264
|
+
if (!PRELOADS.has(reason)) known.used = true;
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const entry = {
|
|
268
|
+
component,
|
|
269
|
+
part,
|
|
270
|
+
reason,
|
|
271
|
+
start: performance.now(),
|
|
272
|
+
used: false
|
|
273
|
+
};
|
|
274
|
+
state.loads.set(key, entry);
|
|
275
|
+
done.then(() => {
|
|
276
|
+
entry.end = performance.now();
|
|
277
|
+
state.changed?.();
|
|
278
|
+
}, () => {
|
|
279
|
+
entry.end = performance.now();
|
|
280
|
+
entry.failed = true;
|
|
281
|
+
state.changed?.();
|
|
282
|
+
});
|
|
283
|
+
state.changed?.();
|
|
284
|
+
};
|
|
285
|
+
const add = (entry) => {
|
|
286
|
+
state.log.push({
|
|
287
|
+
...entry,
|
|
288
|
+
time: performance.now()
|
|
289
|
+
});
|
|
290
|
+
if (state.log.length > MAX_LOG) state.log.splice(0, state.log.length - MAX_LOG);
|
|
291
|
+
state.changed?.();
|
|
292
|
+
};
|
|
293
|
+
globalThis[DEVTOOLS] = {
|
|
294
|
+
attach(core) {
|
|
295
|
+
state.scopes = core.scopes;
|
|
296
|
+
state.set = core.set;
|
|
297
|
+
state.handle = core.handle;
|
|
298
|
+
state.changed?.();
|
|
299
|
+
},
|
|
300
|
+
load,
|
|
301
|
+
handled(run) {
|
|
302
|
+
const entry = {
|
|
303
|
+
ref: run.ref,
|
|
304
|
+
label: `${run.event ?? "call"} on <${run.element.tagName.toLowerCase()}>`,
|
|
305
|
+
begun: run.begun,
|
|
306
|
+
ready: run.ready,
|
|
307
|
+
end: run.end,
|
|
308
|
+
calls: [],
|
|
309
|
+
updates: []
|
|
310
|
+
};
|
|
311
|
+
if (run.result instanceof Promise) run.result.then(() => {
|
|
312
|
+
entry.settled = performance.now();
|
|
313
|
+
state.changed?.();
|
|
314
|
+
}, () => {
|
|
315
|
+
entry.settled = performance.now();
|
|
316
|
+
entry.failed = true;
|
|
317
|
+
state.changed?.();
|
|
318
|
+
});
|
|
319
|
+
else entry.settled = run.end;
|
|
320
|
+
state.timeline.push(entry);
|
|
321
|
+
if (state.timeline.length > 100) state.timeline.shift();
|
|
322
|
+
state.changed?.();
|
|
323
|
+
},
|
|
324
|
+
updated(count, start, end) {
|
|
325
|
+
if (count > 0) owner(start)?.updates.push({
|
|
326
|
+
count,
|
|
327
|
+
start,
|
|
328
|
+
end
|
|
329
|
+
});
|
|
330
|
+
},
|
|
331
|
+
defer(template, done) {
|
|
332
|
+
deferred(template, done);
|
|
333
|
+
},
|
|
334
|
+
handler(ref, element, event) {
|
|
335
|
+
const [component, name] = ref.split("@")[0].split("#");
|
|
336
|
+
const part = state.loads.get(`${component}:${/^[hct]\d/.test(name) ? name : "update"}`);
|
|
337
|
+
if (part) part.used = true;
|
|
338
|
+
if (element.tagName === "TEMPLATE") {
|
|
339
|
+
const block = [...state.blocks.values()].find((item) => item.template === element);
|
|
340
|
+
if (block && block.fired === void 0) {
|
|
341
|
+
block.fired = performance.now();
|
|
342
|
+
if (block.kind === "$client") {
|
|
343
|
+
block.state = "rendered";
|
|
344
|
+
block.rendered = block.fired;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
add({
|
|
349
|
+
kind: "handler",
|
|
350
|
+
text: `${event?.type ?? "call"} on <${element.tagName.toLowerCase()}>: ${ref}`
|
|
351
|
+
});
|
|
352
|
+
},
|
|
353
|
+
part(component, name) {
|
|
354
|
+
add({
|
|
355
|
+
kind: "part",
|
|
356
|
+
text: `loaded ${component} ${name}`
|
|
357
|
+
});
|
|
358
|
+
},
|
|
359
|
+
effect(scope, name, kind, time) {
|
|
360
|
+
const key = `${scope.id}:${name}`;
|
|
361
|
+
let entry = state.effects.get(key);
|
|
362
|
+
if (!entry) {
|
|
363
|
+
entry = {
|
|
364
|
+
scope: scope.id,
|
|
365
|
+
component: rootOf(scope).m ?? "",
|
|
366
|
+
k: scope.k,
|
|
367
|
+
name,
|
|
368
|
+
runs: 0,
|
|
369
|
+
recent: [],
|
|
370
|
+
time: 0,
|
|
371
|
+
cleanups: 0,
|
|
372
|
+
active: false
|
|
373
|
+
};
|
|
374
|
+
state.effects.set(key, entry);
|
|
375
|
+
}
|
|
376
|
+
const now = performance.now();
|
|
377
|
+
if (kind === "run") {
|
|
378
|
+
entry.runs++;
|
|
379
|
+
entry.time += time;
|
|
380
|
+
entry.recent.push(now);
|
|
381
|
+
if (entry.recent.length > 50) entry.recent.shift();
|
|
382
|
+
entry.active = true;
|
|
383
|
+
} else {
|
|
384
|
+
entry.cleanups++;
|
|
385
|
+
entry.lastCleanup = now;
|
|
386
|
+
entry.active = false;
|
|
387
|
+
}
|
|
388
|
+
state.changed?.();
|
|
389
|
+
},
|
|
390
|
+
navigated(report) {
|
|
391
|
+
state.navigations.push(report);
|
|
392
|
+
if (state.navigations.length > 20) state.navigations.shift();
|
|
393
|
+
state.changed?.();
|
|
394
|
+
},
|
|
395
|
+
write(scope, slot, value) {
|
|
396
|
+
state.written.add(scope.id);
|
|
397
|
+
const root = rootOf(scope);
|
|
398
|
+
add({
|
|
399
|
+
kind: "write",
|
|
400
|
+
text: `scope ${scope.id} slot ${slot} = ${preview(value)}`,
|
|
401
|
+
scope: scope.id,
|
|
402
|
+
write: {
|
|
403
|
+
component: root.m ?? "",
|
|
404
|
+
k: scope.k,
|
|
405
|
+
slot
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
state.showFallback = (block, on) => {
|
|
411
|
+
const kept = globalThis.$bD?.[block.id];
|
|
412
|
+
if (!kept || (block.fallback ?? false) === on) return false;
|
|
413
|
+
const [shown, hidden] = on ? [kept.b, kept.f] : [kept.f, kept.b];
|
|
414
|
+
const anchor = shown.find((node) => node.parentNode);
|
|
415
|
+
if (!anchor) return false;
|
|
416
|
+
for (const node of hidden) anchor.parentNode.insertBefore(node, anchor);
|
|
417
|
+
for (const node of shown) node.parentNode?.removeChild(node);
|
|
418
|
+
block.fallback = on;
|
|
419
|
+
state.changed?.();
|
|
420
|
+
return true;
|
|
421
|
+
};
|
|
422
|
+
const original = globalThis.fetch.bind(globalThis);
|
|
423
|
+
globalThis.fetch = async (input, init) => {
|
|
424
|
+
const url = new URL(input instanceof Request ? input.url : String(input), location.href);
|
|
425
|
+
if (url.origin !== location.origin || !url.pathname.startsWith(`${rpc}/`)) return original(input, init);
|
|
426
|
+
const name = decodeURIComponent(url.pathname.slice(rpc.length + 1));
|
|
427
|
+
const started = performance.now();
|
|
428
|
+
const call = {
|
|
429
|
+
name,
|
|
430
|
+
start: started
|
|
431
|
+
};
|
|
432
|
+
owner(started)?.calls.push(call);
|
|
433
|
+
try {
|
|
434
|
+
const response = await original(input, init);
|
|
435
|
+
const took = Math.round(performance.now() - started);
|
|
436
|
+
const redirect = response.headers.get("x-brumate-redirect");
|
|
437
|
+
call.end = performance.now();
|
|
438
|
+
call.status = redirect ? "redirect" : response.status;
|
|
439
|
+
const server = /brumate;dur=([\d.]+)/.exec(response.headers.get("server-timing") ?? "");
|
|
440
|
+
if (server) call.server = Number(server[1]);
|
|
441
|
+
state.changed?.();
|
|
442
|
+
add({
|
|
443
|
+
kind: "call",
|
|
444
|
+
text: `${name}: ${redirect ? `redirect to ${redirect}` : response.status} in ${took} ms`
|
|
445
|
+
});
|
|
446
|
+
return response;
|
|
447
|
+
} catch (error) {
|
|
448
|
+
call.end = performance.now();
|
|
449
|
+
call.status = "failed";
|
|
450
|
+
add({
|
|
451
|
+
kind: "call",
|
|
452
|
+
text: `${name}: failed, ${error instanceof Error ? error.message : String(error)}`
|
|
453
|
+
});
|
|
454
|
+
throw error;
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
const deferred = (template, done) => {
|
|
458
|
+
const block = [...state.blocks.values()].find((item) => item.template === template);
|
|
459
|
+
if (block) {
|
|
460
|
+
block.fired ??= performance.now();
|
|
461
|
+
block.state = "loading";
|
|
462
|
+
}
|
|
463
|
+
done.finally(() => {
|
|
464
|
+
scanBlocks(state);
|
|
465
|
+
state.changed?.();
|
|
466
|
+
});
|
|
467
|
+
};
|
|
468
|
+
state.fire = (block) => {
|
|
469
|
+
if (block.kind === "defer" && block.template) deferred(block.template, import("./defer-BbD7JQhj.js").then((module) => module.loadDeferred(block.template)));
|
|
470
|
+
else if (block.template && block.ref) state.handle?.(block.template, block.ref);
|
|
471
|
+
};
|
|
472
|
+
if (typeof MutationObserver !== "undefined") {
|
|
473
|
+
let queued = false;
|
|
474
|
+
new MutationObserver(() => {
|
|
475
|
+
if (!queued) {
|
|
476
|
+
queued = true;
|
|
477
|
+
queueMicrotask(() => {
|
|
478
|
+
queued = false;
|
|
479
|
+
if (scanBlocks(state)) state.changed?.();
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
}).observe(document, {
|
|
483
|
+
childList: true,
|
|
484
|
+
subtree: true,
|
|
485
|
+
characterData: true
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
scanBlocks(state);
|
|
489
|
+
const host = document.createElement("brumate-devtools");
|
|
490
|
+
const root = host.attachShadow({ mode: "open" });
|
|
491
|
+
const style = document.createElement("style");
|
|
492
|
+
style.textContent = `
|
|
493
|
+
.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; }
|
|
494
|
+
.open[hidden] { display: none; }
|
|
495
|
+
.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); }
|
|
496
|
+
.open[data-errors] .grip { width: 56px; background: #e5484d; }
|
|
497
|
+
.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); }
|
|
498
|
+
.open:hover .content, .open:focus-visible .content, .open:active .content { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
|
|
499
|
+
.open:hover .grip, .open:focus-visible .grip, .open:active .grip { opacity: 0; }
|
|
500
|
+
.open:focus-visible .content { border-color: #ee7a3e; }
|
|
501
|
+
.mark { display: inline-flex; width: 16px; height: 16px; }
|
|
502
|
+
.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; }
|
|
503
|
+
.chevron { width: 12px; height: 12px; color: #a39a92; }
|
|
504
|
+
.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; }
|
|
505
|
+
.count:empty { display: none; }
|
|
506
|
+
.flashes { position: fixed; inset: 0; pointer-events: none; z-index: 2147483646; }
|
|
507
|
+
.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; }
|
|
508
|
+
.flash.warm { border-color: #ffd166; background: rgb(255 209 102 / 0.1); }
|
|
509
|
+
.flash.hot { border-color: #ff7a7a; background: rgb(255 122 122 / 0.12); }
|
|
510
|
+
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
|
|
511
|
+
@media (prefers-reduced-motion: reduce) { .flash { animation: none; } }
|
|
512
|
+
@media (prefers-reduced-motion: reduce) { .grip, .content { transition: none; } }
|
|
513
|
+
`;
|
|
514
|
+
const button = document.createElement("button");
|
|
515
|
+
button.type = "button";
|
|
516
|
+
button.className = "open";
|
|
517
|
+
button.title = "brumate devtools (Alt+Shift+D)";
|
|
518
|
+
button.innerHTML = `<span class="grip"></span><span class="content"><span class="mark">${LOGO}</span><span class="version"></span><span class="count"></span><svg class="chevron" viewBox="0 0 12 12" aria-hidden="true"><path d="M3 7.5 6 4.5 9 7.5" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg></span>`;
|
|
519
|
+
button.querySelector(".version").textContent = meta.version ? `v${meta.version}` : "brumate";
|
|
520
|
+
const label = () => {
|
|
521
|
+
const errors = state.errors.length;
|
|
522
|
+
button.setAttribute("aria-label", `Open the brumate devtools${meta.version ? `, version ${meta.version}` : ""}${errors > 0 ? `, ${errors} errors` : ""}`);
|
|
523
|
+
};
|
|
524
|
+
label();
|
|
525
|
+
const count = button.querySelector(".count");
|
|
526
|
+
state.errorCount = () => {
|
|
527
|
+
count.textContent = state.errors.length > 0 ? String(state.errors.length) : "";
|
|
528
|
+
button.toggleAttribute("data-errors", state.errors.length > 0);
|
|
529
|
+
label();
|
|
530
|
+
};
|
|
531
|
+
let dragged = false;
|
|
532
|
+
button.addEventListener("pointerdown", (event) => {
|
|
533
|
+
if (event.button !== 0) return;
|
|
534
|
+
const start = event.clientY;
|
|
535
|
+
let opened = false;
|
|
536
|
+
dragged = false;
|
|
537
|
+
const move = (next) => {
|
|
538
|
+
if (!opened) {
|
|
539
|
+
if (start - next.clientY < 4) return;
|
|
540
|
+
opened = true;
|
|
541
|
+
dragged = true;
|
|
542
|
+
panelModule().then(({ openPanel }) => {
|
|
543
|
+
openPanel(root, state, "overview");
|
|
544
|
+
state.resize?.(next.clientY);
|
|
545
|
+
});
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
state.resize?.(next.clientY);
|
|
549
|
+
};
|
|
550
|
+
const end = () => {
|
|
551
|
+
removeEventListener("pointermove", move);
|
|
552
|
+
removeEventListener("pointerup", end);
|
|
553
|
+
removeEventListener("pointercancel", end);
|
|
554
|
+
if (opened) state.resized?.();
|
|
555
|
+
};
|
|
556
|
+
addEventListener("pointermove", move);
|
|
557
|
+
addEventListener("pointerup", end);
|
|
558
|
+
addEventListener("pointercancel", end);
|
|
559
|
+
});
|
|
560
|
+
button.addEventListener("click", () => {
|
|
561
|
+
if (dragged) {
|
|
562
|
+
dragged = false;
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
panelModule().then(({ togglePanel }) => togglePanel(root, state));
|
|
566
|
+
});
|
|
567
|
+
addEventListener("keydown", (event) => {
|
|
568
|
+
if (event.altKey && event.shiftKey && event.code === "KeyD") {
|
|
569
|
+
event.preventDefault();
|
|
570
|
+
panelModule().then(({ togglePanel }) => togglePanel(root, state));
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
state.open = (tab) => {
|
|
574
|
+
import("./devtools-panel-BVB-W5q4.js").then(({ openPanel }) => openPanel(root, state, tab));
|
|
575
|
+
};
|
|
576
|
+
root.append(style, button);
|
|
577
|
+
installFlash(state, root, host);
|
|
578
|
+
addEventListener("error", (event) => {
|
|
579
|
+
const stack = event.error?.stack;
|
|
580
|
+
if (foreign(stack, event.filename)) return;
|
|
581
|
+
const error = event.error;
|
|
582
|
+
reportError(state, {
|
|
583
|
+
message: error?.message ?? event.message,
|
|
584
|
+
stack: error?.stack
|
|
585
|
+
}, "browser");
|
|
586
|
+
});
|
|
587
|
+
addEventListener("unhandledrejection", (event) => {
|
|
588
|
+
const reason = event.reason;
|
|
589
|
+
if (foreign(reason?.stack)) return;
|
|
590
|
+
reportError(state, {
|
|
591
|
+
message: reason?.message ?? String(event.reason),
|
|
592
|
+
stack: reason?.stack
|
|
593
|
+
}, "browser");
|
|
594
|
+
});
|
|
595
|
+
addEventListener("brumate:error", (event) => {
|
|
596
|
+
const error = event.detail.error;
|
|
597
|
+
reportError(state, {
|
|
598
|
+
message: error?.message ?? String(error),
|
|
599
|
+
stack: error?.stack
|
|
600
|
+
}, "browser");
|
|
601
|
+
});
|
|
602
|
+
hot?.on("vite:error", (payload) => {
|
|
603
|
+
reportError(state, payload.err, "compile");
|
|
604
|
+
});
|
|
605
|
+
hot?.on("vite:afterUpdate", () => {
|
|
606
|
+
const before = state.errors.length;
|
|
607
|
+
state.errors = state.errors.filter((error) => error.source !== "compile");
|
|
608
|
+
if (state.errors.length !== before) {
|
|
609
|
+
state.errorCount?.();
|
|
610
|
+
state.changed?.();
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
const append = () => {
|
|
614
|
+
document.documentElement.append(host);
|
|
615
|
+
};
|
|
616
|
+
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", append);
|
|
617
|
+
else append();
|
|
618
|
+
return state;
|
|
619
|
+
}
|
|
620
|
+
//#endregion
|
|
621
|
+
export { reportError as a, preview as i, PRELOADS as n, rootOf as o, installDevtools as r, scanBlocks as s, LOGO as t };
|
|
622
|
+
|
|
623
|
+
//# sourceMappingURL=devtools-CQgD7NPB.js.map
|