@hansenexus/hud 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +634 -12
- package/dist/a11y-B5DUaiCs.js +246 -0
- package/dist/a11y-panel-p_t4eD7p.js +207 -0
- package/dist/{capabilities-CjulXFQX.js → access-C7zlaqj6.js} +1 -90
- package/dist/{access-CNvJOwKM.d.ts → access-D_ewAEJG.d.ts} +11 -4
- package/dist/access-panel-CEfTr9ZI.js +123 -0
- package/dist/adapter-BYoxPYTI.d.ts +33 -0
- package/dist/adapter-hcwmJtNx.js +65 -0
- package/dist/auto/runtime.d.ts +65 -0
- package/dist/auto/runtime.js +50 -0
- package/dist/auto.d.ts +15 -0
- package/dist/auto.js +33 -0
- package/dist/capabilities-rDSKjXpq.js +110 -0
- package/dist/capture-CwrIwLqi.js +300 -0
- package/dist/capture-buffer-Bbbo6omF.d.ts +35 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +275 -0
- package/dist/data-panel-DhxAmP91.js +817 -0
- package/dist/data-store-ChF1td_P.js +164 -0
- package/dist/define-hud-CHPedaQ5.d.ts +50 -0
- package/dist/design-D0kGgPoP.js +87 -0
- package/dist/detect-BxHZ0pxW.d.ts +25 -0
- package/dist/detect-CHZiSeZs.js +63 -0
- package/dist/dispatch-panel-B-xr_Giy.js +279 -0
- package/dist/{env-vEjyJfPW.d.ts → env-CApnbI0r.d.ts} +2 -0
- package/dist/{env-DfxpPfs9.js → env-CaiFPIhF.js} +3 -0
- package/dist/file-xdSaQ2uR.js +103 -0
- package/dist/flags-DVtaJ8pQ.d.ts +58 -0
- package/dist/flags.d.ts +2 -0
- package/dist/flags.js +82 -0
- package/dist/force-state-panel-_otVYh9i.js +97 -0
- package/dist/generate-C8lQl3Eh.js +53 -0
- package/dist/handler-BpVhxEmU.js +106 -0
- package/dist/{handler-WmE4Lu7l.d.ts → handler-DtYVCZY6.d.ts} +1 -1
- package/dist/index-BAV_1W8a.d.ts +43 -0
- package/dist/index-BJ26pse9.d.ts +70 -0
- package/dist/index-BnQ0dTZf.d.ts +19 -0
- package/dist/index-CwfX-W87.d.ts +72 -0
- package/dist/index-DcH9V3cU.d.ts +48 -0
- package/dist/index-DqOyNf1u.d.ts +65 -0
- package/dist/index-DstI_ike.d.ts +66 -0
- package/dist/index-Dxz4fn4j.d.ts +42 -0
- package/dist/index-Hhh7OXzU.d.ts +129 -0
- package/dist/index-ReFbhQ9p.d.ts +25 -0
- package/dist/index-RgXfMBuW.d.ts +48 -0
- package/dist/{index-BYsdS-7d.d.ts → index-gCZBO53s.d.ts} +21 -3
- package/dist/index.d.ts +5 -5
- package/dist/index.js +710 -69
- package/dist/inspect-C9Ft8fqn.js +142 -0
- package/dist/inspect-root-BkaupBMp.js +429 -0
- package/dist/meta-Bv0sEao3.js +6 -0
- package/dist/meta-C_G7MB5w.d.ts +49 -0
- package/dist/mocks-CA-wM2SB.d.ts +109 -0
- package/dist/mocks-ESiRqk9o.js +150 -0
- package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
- package/dist/next/config.cjs +201 -0
- package/dist/next/config.d.cts +87 -0
- package/dist/next/config.d.ts +64 -0
- package/dist/next/config.js +84 -0
- package/dist/next.d.ts +14 -4
- package/dist/next.js +5 -3
- package/dist/observe-CdDnDBRP.js +89 -0
- package/dist/observe-panel-Cgp1M8oT.js +347 -0
- package/dist/ops-panel-CEqDe_UT.js +234 -0
- package/dist/{payload-CLKDVZWl.d.ts → payload-MUQ9ciER.d.ts} +25 -1
- package/dist/plugins/a11y.d.ts +2 -0
- package/dist/plugins/a11y.js +2 -0
- package/dist/plugins/access/server.d.ts +5 -5
- package/dist/plugins/access/server.js +4 -3
- package/dist/plugins/access.d.ts +5 -5
- package/dist/plugins/access.js +16 -215
- package/dist/plugins/agent/server.d.ts +3 -38
- package/dist/plugins/agent/server.js +47 -21
- package/dist/plugins/agent.d.ts +4 -4
- package/dist/plugins/agent.js +6 -348
- package/dist/plugins/capture/server.d.ts +92 -0
- package/dist/plugins/capture/server.js +248 -0
- package/dist/plugins/capture.d.ts +24 -0
- package/dist/plugins/capture.js +70 -0
- package/dist/plugins/data/msw-browser.d.ts +2 -0
- package/dist/plugins/data/msw-browser.js +39 -0
- package/dist/plugins/data/msw-node.d.ts +36 -0
- package/dist/plugins/data/msw-node.js +68 -0
- package/dist/plugins/data/server.d.ts +257 -0
- package/dist/plugins/data/server.js +717 -0
- package/dist/plugins/data.d.ts +6 -0
- package/dist/plugins/data.js +51 -0
- package/dist/plugins/design/server.d.ts +54 -0
- package/dist/plugins/design/server.js +198 -0
- package/dist/plugins/design.d.ts +4 -124
- package/dist/plugins/design.js +4 -619
- package/dist/plugins/inspect/convex.d.ts +2 -0
- package/dist/plugins/inspect/convex.js +486 -0
- package/dist/plugins/inspect/react-query.d.ts +2 -0
- package/dist/plugins/inspect/react-query.js +237 -0
- package/dist/plugins/inspect/sockets.d.ts +51 -0
- package/dist/plugins/inspect/sockets.js +397 -0
- package/dist/plugins/inspect/swr.d.ts +2 -0
- package/dist/plugins/inspect/swr.js +218 -0
- package/dist/plugins/inspect.d.ts +4 -0
- package/dist/plugins/inspect.js +3 -0
- package/dist/plugins/observe.d.ts +4 -64
- package/dist/plugins/observe.js +1 -616
- package/dist/plugins/ops/server.d.ts +1 -1
- package/dist/plugins/ops/server.js +2 -1
- package/dist/plugins/ops.d.ts +2 -1
- package/dist/plugins/ops.js +15 -336
- package/dist/plugins/routes/server.d.ts +88 -0
- package/dist/plugins/routes/server.js +62 -0
- package/dist/plugins/routes.d.ts +3 -0
- package/dist/plugins/routes.js +216 -0
- package/dist/plugins/seo.d.ts +2 -0
- package/dist/plugins/seo.js +2 -0
- package/dist/plugins/vitals.d.ts +2 -25
- package/dist/plugins/vitals.js +3 -2
- package/dist/{plugins-CQ_0w1ot.d.ts → plugins-BZvDqGx5.d.ts} +33 -3
- package/dist/poll-CjKsWZi8.js +89 -0
- package/dist/requests-BwD6MKEq.js +282 -0
- package/dist/requests-CJrUf465.d.ts +50 -0
- package/dist/review.js +2 -2
- package/dist/same-origin-BGet22CC.js +21 -0
- package/dist/scan-DzJNXqOk.js +165 -0
- package/dist/seo-Dq9q_QkO.js +551 -0
- package/dist/seo-panel-CfiY-TnT.js +124 -0
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -105
- package/dist/sessions-panel-COvhPAzv.js +98 -0
- package/dist/{shortcut-U6ftVY06.js → shortcut-s_mjGeU8.js} +1 -44
- package/dist/{types-QJUajwWq.js → state-CjjZPjPJ.js} +13 -8
- package/dist/store/convex.d.ts +33 -0
- package/dist/store/convex.js +52 -0
- package/dist/{vitals-panel-Dvc5dnR-.js → store-CQqIIKTc.js} +1 -29
- package/dist/store-Ync9eb1G.js +67 -0
- package/dist/store.d.ts +76 -0
- package/dist/store.js +188 -0
- package/dist/{styles--slk86ZQ.js → styles-BA8ueHoV.js} +13 -3
- package/dist/styles-DKU_P8MH.js +139 -0
- package/dist/styles-DPpDPmzi.js +68 -0
- package/dist/tokens-panel-CbMQfasZ.js +142 -0
- package/dist/types-B-ulf2Jp.js +8 -0
- package/dist/types-BIgGf-0C.d.ts +25 -0
- package/dist/types-BIkI-qN8.js +30 -0
- package/dist/{types-DADBRiGk.d.ts → types-Cxh4twqc.d.ts} +1 -1
- package/dist/types-DIdPfjtV.js +6 -0
- package/dist/types-DaJcsEjO.d.ts +44 -0
- package/dist/types-Dn68psVz.d.ts +118 -0
- package/dist/types-szkr2QOF.d.ts +39 -0
- package/dist/unlock-store-4V3vR4Eg.js +96 -0
- package/dist/variant-groups-TIfO3NIj.js +137 -0
- package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
- package/dist/variants-panel-BDoSkwBJ.js +457 -0
- package/dist/variants-types-CcRf119M.d.ts +63 -0
- package/dist/variants.d.ts +43 -0
- package/dist/variants.js +83 -0
- package/dist/vitals-panel-BCmMUntW.js +30 -0
- package/dist/vite.d.ts +37 -0
- package/dist/vite.js +134 -0
- package/package.json +72 -5
- package/dist/define-hud-BBzsSl8b.d.ts +0 -36
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { n as detectHudAuto, r as parsePackageJson } from "../detect-CHZiSeZs.js";
|
|
2
|
+
import { t as generateAutoModule } from "../generate-C8lQl3Eh.js";
|
|
3
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { dirname, resolve } from "node:path";
|
|
5
|
+
//#region src/next/config.ts
|
|
6
|
+
/** What the app imports; the wrapper aliases it to the generated file. */
|
|
7
|
+
const AUTO_ID = "@hansenexus/hud/auto";
|
|
8
|
+
/** Where the generated module lives, relative to the app dir. Add it to .gitignore. */
|
|
9
|
+
const AUTO_FILE = ".hud/auto.mjs";
|
|
10
|
+
/**
|
|
11
|
+
* The client variables the loader gate and the env ladder read. Next inlines a
|
|
12
|
+
* `NEXT_PUBLIC_*` read only when the variable is set at build time; Turbopack
|
|
13
|
+
* leaves an unset one as a runtime `process.env` lookup, so the gate
|
|
14
|
+
* `NODE_ENV === "development" || NEXT_PUBLIC_HUD_ENABLED === "true"` does not
|
|
15
|
+
* fold and the dev HUD ships as a production chunk (hud#64). `withHud` pins
|
|
16
|
+
* each to a build-time literal, `""` when unset.
|
|
17
|
+
*/
|
|
18
|
+
const HUD_PUBLIC_ENV = [
|
|
19
|
+
"NEXT_PUBLIC_HUD_ENABLED",
|
|
20
|
+
"NEXT_PUBLIC_HUD_DISABLED",
|
|
21
|
+
"NEXT_PUBLIC_HUD_ENV"
|
|
22
|
+
];
|
|
23
|
+
/** Reads, detects and writes `.hud/auto.mjs`; returns the detection and the file's absolute path. */
|
|
24
|
+
function writeAutoModule({ dir = process.cwd(), packageJson } = {}) {
|
|
25
|
+
const manifest = packageJson ?? resolve(dir, "package.json");
|
|
26
|
+
let text = "{}";
|
|
27
|
+
try {
|
|
28
|
+
text = readFileSync(manifest, "utf8");
|
|
29
|
+
} catch {
|
|
30
|
+
console.warn(`hud: ${manifest} not found; @hansenexus/hud/auto enables the base plugins only`);
|
|
31
|
+
}
|
|
32
|
+
const detected = detectHudAuto(parsePackageJson(text));
|
|
33
|
+
const file = resolve(dir, AUTO_FILE);
|
|
34
|
+
const source = generateAutoModule(detected, manifest);
|
|
35
|
+
let current;
|
|
36
|
+
try {
|
|
37
|
+
current = readFileSync(file, "utf8");
|
|
38
|
+
} catch {}
|
|
39
|
+
if (current !== source) {
|
|
40
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
41
|
+
writeFileSync(file, source, "utf8");
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
detected,
|
|
45
|
+
file
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function withHud(config, options = {}) {
|
|
49
|
+
const base = config ?? {};
|
|
50
|
+
const { file } = writeAutoModule(options);
|
|
51
|
+
const webpack = base.webpack;
|
|
52
|
+
const pinned = {};
|
|
53
|
+
for (const key of HUD_PUBLIC_ENV) pinned[key] = process.env[key] ?? "";
|
|
54
|
+
return {
|
|
55
|
+
...base,
|
|
56
|
+
env: {
|
|
57
|
+
...pinned,
|
|
58
|
+
...base.env
|
|
59
|
+
},
|
|
60
|
+
turbopack: {
|
|
61
|
+
...base.turbopack,
|
|
62
|
+
resolveAlias: {
|
|
63
|
+
...base.turbopack?.resolveAlias,
|
|
64
|
+
[AUTO_ID]: `./${AUTO_FILE}`
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
webpack(webpackConfig, context) {
|
|
68
|
+
const own = webpack ? webpack.call(base, webpackConfig, context) : webpackConfig;
|
|
69
|
+
const resolveOptions = own.resolve ?? {};
|
|
70
|
+
const alias = resolveOptions.alias;
|
|
71
|
+
resolveOptions.alias = Array.isArray(alias) ? [...alias, {
|
|
72
|
+
name: AUTO_ID,
|
|
73
|
+
alias: file
|
|
74
|
+
}] : {
|
|
75
|
+
...alias,
|
|
76
|
+
[`${AUTO_ID}$`]: file
|
|
77
|
+
};
|
|
78
|
+
own.resolve = resolveOptions;
|
|
79
|
+
return own;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
export { AUTO_FILE, AUTO_ID, HUD_PUBLIC_ENV, withHud, writeAutoModule };
|
package/dist/next.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as hudEnvLabel, r as resolveHudEnv, t as HudEnv } from "./env-
|
|
1
|
+
import { r as HudMountProps } from "./define-hud-CHPedaQ5.js";
|
|
2
|
+
import { n as hudEnvLabel, r as resolveHudEnv, t as HudEnv } from "./env-CApnbI0r.js";
|
|
3
3
|
import { ComponentType } from "react";
|
|
4
4
|
//#region src/next/loader.d.ts
|
|
5
5
|
type HudModuleLoader = () => Promise<{
|
|
6
6
|
default: ComponentType<HudMountProps>;
|
|
7
7
|
}>;
|
|
8
|
+
interface HudLoaderOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The tier, when the env ladder cannot read it. A Vite client has no
|
|
11
|
+
* `process`, so pass a literal the bundler folds:
|
|
12
|
+
* `import.meta.env.DEV ? "development" : "production"`. Default: `resolveHudEnv()`.
|
|
13
|
+
*/
|
|
14
|
+
env?: HudEnv;
|
|
15
|
+
}
|
|
8
16
|
/**
|
|
9
17
|
* Mounts the app's `defineHud` module, lazily and client side only.
|
|
10
18
|
*
|
|
@@ -27,7 +35,9 @@ type HudModuleLoader = () => Promise<{
|
|
|
27
35
|
* do that: the `import()` would still sit in the consumer's module and the
|
|
28
36
|
* chunk would ship unreachable but readable (hn-monorepo#1283). Pass `null`
|
|
29
37
|
* and the loader renders nothing.
|
|
38
|
+
*
|
|
39
|
+
* Outside Next (Vite), gate on `import.meta.env.DEV` and pass `{ env }`.
|
|
30
40
|
*/
|
|
31
|
-
export declare function createHudLoader(load: HudModuleLoader | null): ComponentType<HudMountProps>;
|
|
41
|
+
export declare function createHudLoader(load: HudModuleLoader | null, options?: HudLoaderOptions): ComponentType<HudMountProps>;
|
|
32
42
|
//#endregion
|
|
33
|
-
export { type HudEnv, type HudModuleLoader, type HudMountProps, hudEnvLabel, resolveHudEnv };
|
|
43
|
+
export { type HudEnv, type HudLoaderOptions, type HudModuleLoader, type HudMountProps, hudEnvLabel, resolveHudEnv };
|
package/dist/next.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as resolveHudEnv, t as hudEnvLabel } from "./env-
|
|
1
|
+
import { n as resolveHudEnv, t as hudEnvLabel } from "./env-CaiFPIhF.js";
|
|
2
2
|
import { Suspense, lazy, useEffect, useState } from "react";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
//#region src/next/loader.tsx
|
|
@@ -24,15 +24,17 @@ import { jsx } from "react/jsx-runtime";
|
|
|
24
24
|
* do that: the `import()` would still sit in the consumer's module and the
|
|
25
25
|
* chunk would ship unreachable but readable (hn-monorepo#1283). Pass `null`
|
|
26
26
|
* and the loader renders nothing.
|
|
27
|
+
*
|
|
28
|
+
* Outside Next (Vite), gate on `import.meta.env.DEV` and pass `{ env }`.
|
|
27
29
|
*/
|
|
28
|
-
function createHudLoader(load) {
|
|
30
|
+
function createHudLoader(load, options = {}) {
|
|
29
31
|
if (!load) return NoHud;
|
|
30
32
|
const LazyHud = lazy(load);
|
|
31
33
|
function HudLoader(props) {
|
|
32
34
|
const [mounted, setMounted] = useState(false);
|
|
33
35
|
useEffect(() => setMounted(true), []);
|
|
34
36
|
if (!mounted) return null;
|
|
35
|
-
const env = resolveHudEnv();
|
|
37
|
+
const env = options.env ?? resolveHudEnv();
|
|
36
38
|
if (env === "disabled") return null;
|
|
37
39
|
return /* @__PURE__ */ jsx(Suspense, {
|
|
38
40
|
fallback: null,
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { i as definePlugin } from "./plugins-DVy_vaYr.js";
|
|
2
|
+
import { _ as captureBuffer, v as isError } from "./requests-BwD6MKEq.js";
|
|
3
|
+
import { t as installCapture } from "./capture-CwrIwLqi.js";
|
|
4
|
+
import { r as startVitals } from "./store-CQqIIKTc.js";
|
|
5
|
+
import { lazy, useEffect, useSyncExternalStore } from "react";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
//#region src/plugins/observe/view.ts
|
|
8
|
+
const FILTERS = [
|
|
9
|
+
"all",
|
|
10
|
+
"errors",
|
|
11
|
+
"warn",
|
|
12
|
+
"log",
|
|
13
|
+
"fetch",
|
|
14
|
+
"xhr",
|
|
15
|
+
"longtask"
|
|
16
|
+
];
|
|
17
|
+
function matches(entry, filter) {
|
|
18
|
+
if (filter === "all") return true;
|
|
19
|
+
if (filter === "errors") return isError(entry);
|
|
20
|
+
return entry.kind === filter;
|
|
21
|
+
}
|
|
22
|
+
let view = {
|
|
23
|
+
tab: "console",
|
|
24
|
+
filter: "all"
|
|
25
|
+
};
|
|
26
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
27
|
+
function setView(next) {
|
|
28
|
+
view = {
|
|
29
|
+
...view,
|
|
30
|
+
...next
|
|
31
|
+
};
|
|
32
|
+
for (const listener of listeners) listener();
|
|
33
|
+
}
|
|
34
|
+
function subscribe(listener) {
|
|
35
|
+
listeners.add(listener);
|
|
36
|
+
return () => listeners.delete(listener);
|
|
37
|
+
}
|
|
38
|
+
const getView = () => view;
|
|
39
|
+
function useView() {
|
|
40
|
+
return useSyncExternalStore(subscribe, getView, getView);
|
|
41
|
+
}
|
|
42
|
+
function useCapture() {
|
|
43
|
+
return useSyncExternalStore(captureBuffer.subscribe, captureBuffer.getSnapshot, captureBuffer.getSnapshot);
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/plugins/observe/index.tsx
|
|
47
|
+
const Panel = lazy(() => import("./observe-panel-Cgp1M8oT.js"));
|
|
48
|
+
const NO_ENV = {};
|
|
49
|
+
const noUser = () => void 0;
|
|
50
|
+
function useErrorCount() {
|
|
51
|
+
return useCapture().filter(isError).length;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Console and network capture, an app/build/browser/user snapshot and the
|
|
55
|
+
* page's Web Vitals. The pill counts errors; opening the panel while there are
|
|
56
|
+
* any lands on the console filtered to them.
|
|
57
|
+
*/
|
|
58
|
+
function observe({ env = NO_ENV, useUser = noUser, ignore } = {}) {
|
|
59
|
+
function ObservePill() {
|
|
60
|
+
useEffect(() => installCapture(ignore ? { ignore } : {}), []);
|
|
61
|
+
useEffect(() => startVitals(), []);
|
|
62
|
+
const errors = useErrorCount();
|
|
63
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
64
|
+
className: "dot",
|
|
65
|
+
"data-rating": errors > 0 ? "poor" : "good"
|
|
66
|
+
}), errors === 1 ? "1 error" : `${errors} errors`] });
|
|
67
|
+
}
|
|
68
|
+
function ObservePanel({ ctx }) {
|
|
69
|
+
return /* @__PURE__ */ jsx(Panel, {
|
|
70
|
+
ctx,
|
|
71
|
+
env,
|
|
72
|
+
useUser
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return definePlugin({
|
|
76
|
+
id: "observe",
|
|
77
|
+
title: "Observe",
|
|
78
|
+
pill: ObservePill,
|
|
79
|
+
pillPriority: 20,
|
|
80
|
+
panel: ObservePanel,
|
|
81
|
+
commands: [{
|
|
82
|
+
id: "clear",
|
|
83
|
+
title: "Clear console capture",
|
|
84
|
+
run: () => captureBuffer.clear()
|
|
85
|
+
}]
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
export { useCapture as a, setView as i, FILTERS as n, useView as o, matches as r, observe as t };
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import { _ as captureBuffer, v as isError } from "./requests-BwD6MKEq.js";
|
|
2
|
+
import { a as useCapture, i as setView, n as FILTERS, o as useView, r as matches } from "./observe-CdDnDBRP.js";
|
|
3
|
+
import { VitalsPanel } from "./vitals-panel-BCmMUntW.js";
|
|
4
|
+
import { useEffect, useLayoutEffect, useState, version } from "react";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
//#region src/plugins/observe/console-tab.tsx
|
|
7
|
+
function statusLevel(status) {
|
|
8
|
+
if (status === 0 || status >= 500) return "error";
|
|
9
|
+
return status >= 400 ? "warn" : "ok";
|
|
10
|
+
}
|
|
11
|
+
/** Console, fetch and long-task capture, newest first. */
|
|
12
|
+
function ConsoleTab() {
|
|
13
|
+
const entries = useCapture();
|
|
14
|
+
const { filter } = useView();
|
|
15
|
+
const rows = entries.filter((entry) => matches(entry, filter)).slice(-200).reverse();
|
|
16
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
17
|
+
className: "obs-toolbar",
|
|
18
|
+
role: "toolbar",
|
|
19
|
+
"aria-label": "Filter",
|
|
20
|
+
children: [FILTERS.map((f) => /* @__PURE__ */ jsxs("button", {
|
|
21
|
+
type: "button",
|
|
22
|
+
className: "obs-chip",
|
|
23
|
+
"aria-pressed": filter === f,
|
|
24
|
+
onClick: () => setView({ filter: f }),
|
|
25
|
+
children: [f, f !== "all" && /* @__PURE__ */ jsx("span", {
|
|
26
|
+
className: "obs-count",
|
|
27
|
+
children: entries.filter((e) => matches(e, f)).length
|
|
28
|
+
})]
|
|
29
|
+
}, f)), /* @__PURE__ */ jsx("button", {
|
|
30
|
+
type: "button",
|
|
31
|
+
className: "obs-chip obs-clear",
|
|
32
|
+
onClick: () => captureBuffer.clear(),
|
|
33
|
+
children: "clear"
|
|
34
|
+
})]
|
|
35
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
36
|
+
className: "obs-log",
|
|
37
|
+
children: rows.length === 0 ? /* @__PURE__ */ jsx("p", {
|
|
38
|
+
className: "empty",
|
|
39
|
+
children: filter === "all" ? "Nothing captured yet. Console output, requests and long tasks land here." : `No ${filter} captured.`
|
|
40
|
+
}) : rows.map((entry) => /* @__PURE__ */ jsx(EntryRow, { entry }, entry.id))
|
|
41
|
+
})] });
|
|
42
|
+
}
|
|
43
|
+
function EntryRow({ entry }) {
|
|
44
|
+
const time = new Date(entry.ts).toLocaleTimeString(void 0, { hour12: false });
|
|
45
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
46
|
+
className: "obs-row",
|
|
47
|
+
"data-kind": entry.kind,
|
|
48
|
+
children: [
|
|
49
|
+
/* @__PURE__ */ jsx("span", {
|
|
50
|
+
className: "obs-time",
|
|
51
|
+
children: time
|
|
52
|
+
}),
|
|
53
|
+
/* @__PURE__ */ jsx("span", {
|
|
54
|
+
className: "obs-kind",
|
|
55
|
+
"data-kind": entry.kind,
|
|
56
|
+
children: entry.kind
|
|
57
|
+
}),
|
|
58
|
+
/* @__PURE__ */ jsx("span", {
|
|
59
|
+
className: "obs-text",
|
|
60
|
+
title: entry.text,
|
|
61
|
+
children: entry.text
|
|
62
|
+
}),
|
|
63
|
+
entry.status !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
64
|
+
className: "obs-status",
|
|
65
|
+
"data-level": statusLevel(entry.status),
|
|
66
|
+
children: entry.status || "ERR"
|
|
67
|
+
}),
|
|
68
|
+
entry.durationMs !== void 0 && /* @__PURE__ */ jsxs("span", {
|
|
69
|
+
className: "obs-ms",
|
|
70
|
+
children: [entry.durationMs, " ms"]
|
|
71
|
+
})
|
|
72
|
+
]
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/plugins/observe/info-tab.tsx
|
|
77
|
+
/** App, build, browser and user snapshot: what runs here right now. */
|
|
78
|
+
function InfoTab({ app, env, useUser }) {
|
|
79
|
+
const user = useUser();
|
|
80
|
+
const viewport = useViewportLabel();
|
|
81
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
82
|
+
/* @__PURE__ */ jsxs(Section, {
|
|
83
|
+
title: "App",
|
|
84
|
+
children: [
|
|
85
|
+
/* @__PURE__ */ jsx(Row, {
|
|
86
|
+
label: "App",
|
|
87
|
+
value: app
|
|
88
|
+
}),
|
|
89
|
+
/* @__PURE__ */ jsx(Row, {
|
|
90
|
+
label: "Origin",
|
|
91
|
+
value: window.location.origin,
|
|
92
|
+
copy: true
|
|
93
|
+
}),
|
|
94
|
+
/* @__PURE__ */ jsx(Row, {
|
|
95
|
+
label: "Path",
|
|
96
|
+
value: window.location.pathname + window.location.search,
|
|
97
|
+
copy: true
|
|
98
|
+
})
|
|
99
|
+
]
|
|
100
|
+
}),
|
|
101
|
+
/* @__PURE__ */ jsxs(Section, {
|
|
102
|
+
title: "Build",
|
|
103
|
+
children: [/* @__PURE__ */ jsx(Row, {
|
|
104
|
+
label: "React",
|
|
105
|
+
value: version
|
|
106
|
+
}), Object.entries(env).map(([label, value]) => /* @__PURE__ */ jsx(Row, {
|
|
107
|
+
label,
|
|
108
|
+
value: value ?? "not set",
|
|
109
|
+
copy: value !== void 0
|
|
110
|
+
}, label))]
|
|
111
|
+
}),
|
|
112
|
+
user && /* @__PURE__ */ jsxs(Section, {
|
|
113
|
+
title: "User",
|
|
114
|
+
children: [
|
|
115
|
+
user.name !== void 0 && /* @__PURE__ */ jsx(Row, {
|
|
116
|
+
label: "Name",
|
|
117
|
+
value: user.name
|
|
118
|
+
}),
|
|
119
|
+
user.email !== void 0 && /* @__PURE__ */ jsx(Row, {
|
|
120
|
+
label: "Email",
|
|
121
|
+
value: user.email,
|
|
122
|
+
copy: true
|
|
123
|
+
}),
|
|
124
|
+
user.id !== void 0 && /* @__PURE__ */ jsx(Row, {
|
|
125
|
+
label: "ID",
|
|
126
|
+
value: user.id,
|
|
127
|
+
copy: true
|
|
128
|
+
}),
|
|
129
|
+
user.role !== void 0 && /* @__PURE__ */ jsx(Row, {
|
|
130
|
+
label: "Role",
|
|
131
|
+
value: user.role
|
|
132
|
+
}),
|
|
133
|
+
Object.entries(user.extra ?? {}).map(([label, value]) => /* @__PURE__ */ jsx(Row, {
|
|
134
|
+
label,
|
|
135
|
+
value
|
|
136
|
+
}, label))
|
|
137
|
+
]
|
|
138
|
+
}),
|
|
139
|
+
/* @__PURE__ */ jsxs(Section, {
|
|
140
|
+
title: "Browser",
|
|
141
|
+
children: [
|
|
142
|
+
/* @__PURE__ */ jsx(Row, {
|
|
143
|
+
label: "Viewport",
|
|
144
|
+
value: viewport
|
|
145
|
+
}),
|
|
146
|
+
/* @__PURE__ */ jsx(Row, {
|
|
147
|
+
label: "Language",
|
|
148
|
+
value: navigator.language
|
|
149
|
+
}),
|
|
150
|
+
/* @__PURE__ */ jsx(Row, {
|
|
151
|
+
label: "User agent",
|
|
152
|
+
value: navigator.userAgent,
|
|
153
|
+
copy: true
|
|
154
|
+
})
|
|
155
|
+
]
|
|
156
|
+
})
|
|
157
|
+
] });
|
|
158
|
+
}
|
|
159
|
+
function viewportLabel() {
|
|
160
|
+
const dark = window.matchMedia?.("(prefers-color-scheme: dark)").matches ?? false;
|
|
161
|
+
return `${window.innerWidth}×${window.innerHeight} @${window.devicePixelRatio}x · ${dark ? "dark" : "light"}`;
|
|
162
|
+
}
|
|
163
|
+
function useViewportLabel() {
|
|
164
|
+
const [label, setLabel] = useState(viewportLabel);
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
const update = () => setLabel(viewportLabel());
|
|
167
|
+
window.addEventListener("resize", update);
|
|
168
|
+
return () => window.removeEventListener("resize", update);
|
|
169
|
+
}, []);
|
|
170
|
+
return label;
|
|
171
|
+
}
|
|
172
|
+
function Section({ title, children }) {
|
|
173
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
174
|
+
className: "obs-section",
|
|
175
|
+
"aria-label": title,
|
|
176
|
+
children: [/* @__PURE__ */ jsx("h4", {
|
|
177
|
+
className: "obs-heading",
|
|
178
|
+
children: title
|
|
179
|
+
}), /* @__PURE__ */ jsx("dl", {
|
|
180
|
+
className: "obs-info",
|
|
181
|
+
children
|
|
182
|
+
})]
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
function Row({ label, value, copy = false }) {
|
|
186
|
+
const [copied, setCopied] = useState(false);
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
if (!copied) return;
|
|
189
|
+
const timer = setTimeout(() => setCopied(false), 1200);
|
|
190
|
+
return () => clearTimeout(timer);
|
|
191
|
+
}, [copied]);
|
|
192
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("dt", {
|
|
193
|
+
title: label,
|
|
194
|
+
children: label
|
|
195
|
+
}), /* @__PURE__ */ jsx("dd", { children: /* @__PURE__ */ jsxs("div", {
|
|
196
|
+
className: "obs-value",
|
|
197
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
198
|
+
title: value,
|
|
199
|
+
children: value
|
|
200
|
+
}), copy && /* @__PURE__ */ jsx("button", {
|
|
201
|
+
type: "button",
|
|
202
|
+
className: "obs-copy",
|
|
203
|
+
"aria-label": `Copy ${label}`,
|
|
204
|
+
onClick: () => {
|
|
205
|
+
navigator.clipboard?.writeText(value).then(() => setCopied(true), () => {});
|
|
206
|
+
},
|
|
207
|
+
children: copied ? "copied" : "copy"
|
|
208
|
+
})]
|
|
209
|
+
}) })] });
|
|
210
|
+
}
|
|
211
|
+
//#endregion
|
|
212
|
+
//#region src/plugins/observe/styles.ts
|
|
213
|
+
/**
|
|
214
|
+
* The observe panel's styles. The panel renders them in its own `<style>`,
|
|
215
|
+
* which still sits inside the HUD's shadow root, so they ship only with this
|
|
216
|
+
* plugin and build on the shell's `--hud-*` tokens.
|
|
217
|
+
*/
|
|
218
|
+
const OBSERVE_CSS = `
|
|
219
|
+
/* Fixed width, so switching tabs does not resize the floating panel. */
|
|
220
|
+
.obs { display: flex; flex-direction: column; gap: 8px; width: 396px; max-width: 100%; }
|
|
221
|
+
|
|
222
|
+
.obs-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--hud-border); }
|
|
223
|
+
.hud .obs-tab {
|
|
224
|
+
padding: 3px 10px 5px;
|
|
225
|
+
margin-bottom: -1px;
|
|
226
|
+
border-bottom: 2px solid transparent;
|
|
227
|
+
color: var(--hud-fg-muted);
|
|
228
|
+
}
|
|
229
|
+
.hud .obs-tab[aria-selected="true"] { border-bottom-color: var(--hud-accent); color: var(--hud-fg); font-weight: 600; }
|
|
230
|
+
|
|
231
|
+
.obs-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; }
|
|
232
|
+
.hud .obs-chip {
|
|
233
|
+
padding: 1px 7px;
|
|
234
|
+
border-radius: 999px;
|
|
235
|
+
font-family: var(--hud-mono);
|
|
236
|
+
font-size: 11px;
|
|
237
|
+
color: var(--hud-fg-muted);
|
|
238
|
+
}
|
|
239
|
+
.hud .obs-chip:hover { background: var(--hud-bg-subtle); }
|
|
240
|
+
.hud .obs-chip[aria-pressed="true"] { background: var(--hud-bg-subtle); color: var(--hud-fg); }
|
|
241
|
+
.obs-chip .obs-count { margin-left: 4px; opacity: 0.6; }
|
|
242
|
+
.hud .obs-clear { margin-left: auto; }
|
|
243
|
+
|
|
244
|
+
.obs-log {
|
|
245
|
+
max-height: 320px;
|
|
246
|
+
overflow: auto;
|
|
247
|
+
border: 1px solid var(--hud-border);
|
|
248
|
+
border-radius: 4px;
|
|
249
|
+
font-family: var(--hud-mono);
|
|
250
|
+
font-size: 11px;
|
|
251
|
+
}
|
|
252
|
+
.obs-row { display: flex; align-items: baseline; gap: 8px; padding: 2px 6px; }
|
|
253
|
+
.obs-row:hover { background: var(--hud-bg-subtle); }
|
|
254
|
+
.obs-row + .obs-row { border-top: 1px solid var(--hud-border); }
|
|
255
|
+
.obs-time, .obs-ms { flex-shrink: 0; color: var(--hud-fg-muted); }
|
|
256
|
+
.obs-kind { flex-shrink: 0; width: 56px; text-transform: uppercase; color: var(--hud-fg-muted); }
|
|
257
|
+
.obs-kind[data-kind="warn"] { color: var(--hud-warn); }
|
|
258
|
+
.obs-kind[data-kind="error"] { color: var(--hud-poor); }
|
|
259
|
+
.obs-kind[data-kind="fetch"], .obs-kind[data-kind="xhr"] { color: var(--hud-accent); }
|
|
260
|
+
.obs-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
261
|
+
.obs-status { flex-shrink: 0; color: var(--hud-good); }
|
|
262
|
+
.obs-status[data-level="warn"] { color: var(--hud-warn); }
|
|
263
|
+
.obs-status[data-level="error"] { color: var(--hud-poor); }
|
|
264
|
+
.obs-log .empty { margin: 0; padding: 6px; font-family: var(--hud-font); }
|
|
265
|
+
|
|
266
|
+
.obs-section + .obs-section { margin-top: 10px; }
|
|
267
|
+
.obs-heading {
|
|
268
|
+
margin: 0 0 4px;
|
|
269
|
+
font-size: 10px;
|
|
270
|
+
font-weight: 600;
|
|
271
|
+
letter-spacing: 0.06em;
|
|
272
|
+
text-transform: uppercase;
|
|
273
|
+
color: var(--hud-fg-muted);
|
|
274
|
+
}
|
|
275
|
+
.obs-info {
|
|
276
|
+
display: grid;
|
|
277
|
+
grid-template-columns: 88px minmax(0, 1fr);
|
|
278
|
+
gap: 2px 12px;
|
|
279
|
+
margin: 0;
|
|
280
|
+
}
|
|
281
|
+
.obs-info dt { color: var(--hud-fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
282
|
+
.obs-info dd { margin: 0; min-width: 0; font-family: var(--hud-mono); }
|
|
283
|
+
.obs-value { display: flex; align-items: center; gap: 6px; }
|
|
284
|
+
.obs-value span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
285
|
+
.hud .obs-copy { flex-shrink: 0; padding: 0 4px; border-radius: 4px; font-size: 10px; color: var(--hud-fg-muted); }
|
|
286
|
+
.hud .obs-copy:hover { background: var(--hud-bg-subtle); color: var(--hud-fg); }
|
|
287
|
+
`;
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/plugins/observe/observe-panel.tsx
|
|
290
|
+
const TABS = [
|
|
291
|
+
{
|
|
292
|
+
id: "console",
|
|
293
|
+
label: "Console"
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
id: "info",
|
|
297
|
+
label: "Info"
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
id: "vitals",
|
|
301
|
+
label: "Vitals"
|
|
302
|
+
}
|
|
303
|
+
];
|
|
304
|
+
/** The observe panel: console, info and vitals tabs. Loaded on first open. */
|
|
305
|
+
function ObservePanel({ ctx, env, useUser }) {
|
|
306
|
+
const { tab } = useView();
|
|
307
|
+
useLayoutEffect(() => {
|
|
308
|
+
if (captureBuffer.getSnapshot().some(isError)) setView({
|
|
309
|
+
tab: "console",
|
|
310
|
+
filter: "errors"
|
|
311
|
+
});
|
|
312
|
+
}, []);
|
|
313
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
314
|
+
className: "obs",
|
|
315
|
+
children: [
|
|
316
|
+
/* @__PURE__ */ jsx("style", { children: OBSERVE_CSS }),
|
|
317
|
+
/* @__PURE__ */ jsx("div", {
|
|
318
|
+
className: "obs-tabs",
|
|
319
|
+
role: "tablist",
|
|
320
|
+
"aria-label": "Observe",
|
|
321
|
+
children: TABS.map(({ id, label }) => /* @__PURE__ */ jsx("button", {
|
|
322
|
+
type: "button",
|
|
323
|
+
role: "tab",
|
|
324
|
+
className: "obs-tab",
|
|
325
|
+
"aria-selected": tab === id,
|
|
326
|
+
onClick: () => setView({ tab: id }),
|
|
327
|
+
children: label
|
|
328
|
+
}, id))
|
|
329
|
+
}),
|
|
330
|
+
/* @__PURE__ */ jsxs("div", {
|
|
331
|
+
role: "tabpanel",
|
|
332
|
+
"aria-label": TABS.find((t) => t.id === tab)?.label,
|
|
333
|
+
children: [
|
|
334
|
+
tab === "console" && /* @__PURE__ */ jsx(ConsoleTab, {}),
|
|
335
|
+
tab === "info" && /* @__PURE__ */ jsx(InfoTab, {
|
|
336
|
+
app: ctx.app,
|
|
337
|
+
env,
|
|
338
|
+
useUser
|
|
339
|
+
}),
|
|
340
|
+
tab === "vitals" && /* @__PURE__ */ jsx(VitalsPanel, {})
|
|
341
|
+
]
|
|
342
|
+
})
|
|
343
|
+
]
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
//#endregion
|
|
347
|
+
export { ObservePanel as default };
|