@hansenexus/hud 0.3.0 → 0.5.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.
Files changed (172) hide show
  1. package/README.md +782 -6
  2. package/dist/a11y-B5DUaiCs.js +246 -0
  3. package/dist/a11y-panel-p_t4eD7p.js +207 -0
  4. package/dist/access-C7zlaqj6.js +100 -0
  5. package/dist/access-D_ewAEJG.d.ts +61 -0
  6. package/dist/access-panel-CEfTr9ZI.js +123 -0
  7. package/dist/adapter-BYoxPYTI.d.ts +33 -0
  8. package/dist/adapter-hcwmJtNx.js +65 -0
  9. package/dist/auto/runtime.d.ts +65 -0
  10. package/dist/auto/runtime.js +50 -0
  11. package/dist/auto.d.ts +15 -0
  12. package/dist/auto.js +33 -0
  13. package/dist/capabilities-rDSKjXpq.js +110 -0
  14. package/dist/capture-CwrIwLqi.js +300 -0
  15. package/dist/capture-buffer-Bbbo6omF.d.ts +35 -0
  16. package/dist/cli.d.ts +1 -0
  17. package/dist/cli.js +275 -0
  18. package/dist/data-panel-DhxAmP91.js +817 -0
  19. package/dist/data-store-ChF1td_P.js +164 -0
  20. package/dist/define-hud-CHPedaQ5.d.ts +50 -0
  21. package/dist/design-D0kGgPoP.js +87 -0
  22. package/dist/detect-BxHZ0pxW.d.ts +25 -0
  23. package/dist/detect-CHZiSeZs.js +63 -0
  24. package/dist/dispatch-panel-B-xr_Giy.js +279 -0
  25. package/dist/env-CApnbI0r.d.ts +19 -0
  26. package/dist/env-CaiFPIhF.js +31 -0
  27. package/dist/file-xdSaQ2uR.js +103 -0
  28. package/dist/flags-DVtaJ8pQ.d.ts +58 -0
  29. package/dist/flags.d.ts +2 -0
  30. package/dist/flags.js +82 -0
  31. package/dist/force-state-BaqWsmrf.js +153 -0
  32. package/dist/force-state-CCqoTfVB.d.ts +23 -0
  33. package/dist/force-state-panel-_otVYh9i.js +97 -0
  34. package/dist/generate-C8lQl3Eh.js +53 -0
  35. package/dist/handler-BpVhxEmU.js +106 -0
  36. package/dist/handler-DtYVCZY6.d.ts +39 -0
  37. package/dist/index-BAV_1W8a.d.ts +43 -0
  38. package/dist/index-BJ26pse9.d.ts +70 -0
  39. package/dist/index-BnQ0dTZf.d.ts +19 -0
  40. package/dist/index-CwfX-W87.d.ts +72 -0
  41. package/dist/index-DcH9V3cU.d.ts +48 -0
  42. package/dist/index-DqOyNf1u.d.ts +65 -0
  43. package/dist/index-DstI_ike.d.ts +66 -0
  44. package/dist/index-Dxz4fn4j.d.ts +42 -0
  45. package/dist/index-Hhh7OXzU.d.ts +129 -0
  46. package/dist/index-ReFbhQ9p.d.ts +25 -0
  47. package/dist/index-RgXfMBuW.d.ts +48 -0
  48. package/dist/index-gCZBO53s.d.ts +73 -0
  49. package/dist/index.d.ts +6 -36
  50. package/dist/index.js +798 -240
  51. package/dist/inspect-C9Ft8fqn.js +142 -0
  52. package/dist/inspect-root-BkaupBMp.js +429 -0
  53. package/dist/marker-C66LxOhJ.d.ts +9 -0
  54. package/dist/marker-CMrvxPmS.d.ts +12 -0
  55. package/dist/marker-DjeGvL-F.js +9 -0
  56. package/dist/marker-uZYPOJ4M.js +12 -0
  57. package/dist/markers.d.ts +3 -0
  58. package/dist/markers.js +3 -0
  59. package/dist/meta-Bv0sEao3.js +6 -0
  60. package/dist/meta-C_G7MB5w.d.ts +49 -0
  61. package/dist/mocks-CA-wM2SB.d.ts +109 -0
  62. package/dist/mocks-ESiRqk9o.js +150 -0
  63. package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
  64. package/dist/next/config.d.ts +52 -0
  65. package/dist/next/config.js +78 -0
  66. package/dist/next.d.ts +14 -19
  67. package/dist/next.js +7 -30
  68. package/dist/observe-CdDnDBRP.js +89 -0
  69. package/dist/observe-panel-Cgp1M8oT.js +347 -0
  70. package/dist/ops-panel-CEqDe_UT.js +234 -0
  71. package/dist/payload-MUQ9ciER.d.ts +92 -0
  72. package/dist/plugins/a11y.d.ts +2 -0
  73. package/dist/plugins/a11y.js +2 -0
  74. package/dist/plugins/access/server.d.ts +122 -0
  75. package/dist/plugins/access/server.js +340 -0
  76. package/dist/plugins/access.d.ts +41 -0
  77. package/dist/plugins/access.js +51 -0
  78. package/dist/plugins/agent/server.d.ts +94 -0
  79. package/dist/plugins/agent/server.js +455 -0
  80. package/dist/plugins/agent.d.ts +37 -0
  81. package/dist/plugins/agent.js +69 -0
  82. package/dist/plugins/capture/server.d.ts +92 -0
  83. package/dist/plugins/capture/server.js +248 -0
  84. package/dist/plugins/capture.d.ts +24 -0
  85. package/dist/plugins/capture.js +70 -0
  86. package/dist/plugins/data/msw-browser.d.ts +2 -0
  87. package/dist/plugins/data/msw-browser.js +39 -0
  88. package/dist/plugins/data/msw-node.d.ts +36 -0
  89. package/dist/plugins/data/msw-node.js +68 -0
  90. package/dist/plugins/data/server.d.ts +257 -0
  91. package/dist/plugins/data/server.js +717 -0
  92. package/dist/plugins/data.d.ts +6 -0
  93. package/dist/plugins/data.js +51 -0
  94. package/dist/plugins/design/server.d.ts +54 -0
  95. package/dist/plugins/design/server.js +198 -0
  96. package/dist/plugins/design.d.ts +5 -0
  97. package/dist/plugins/design.js +4 -0
  98. package/dist/plugins/inspect/convex.d.ts +2 -0
  99. package/dist/plugins/inspect/convex.js +486 -0
  100. package/dist/plugins/inspect/react-query.d.ts +2 -0
  101. package/dist/plugins/inspect/react-query.js +225 -0
  102. package/dist/plugins/inspect/sockets.d.ts +51 -0
  103. package/dist/plugins/inspect/sockets.js +397 -0
  104. package/dist/plugins/inspect/swr.d.ts +2 -0
  105. package/dist/plugins/inspect/swr.js +218 -0
  106. package/dist/plugins/inspect.d.ts +4 -0
  107. package/dist/plugins/inspect.js +3 -0
  108. package/dist/plugins/observe.d.ts +4 -0
  109. package/dist/plugins/observe.js +2 -0
  110. package/dist/plugins/ops/server.d.ts +82 -0
  111. package/dist/plugins/ops/server.js +381 -0
  112. package/dist/plugins/ops.d.ts +27 -0
  113. package/dist/plugins/ops.js +41 -0
  114. package/dist/plugins/routes/server.d.ts +88 -0
  115. package/dist/plugins/routes/server.js +62 -0
  116. package/dist/plugins/routes.d.ts +3 -0
  117. package/dist/plugins/routes.js +216 -0
  118. package/dist/plugins/seo.d.ts +2 -0
  119. package/dist/plugins/seo.js +2 -0
  120. package/dist/plugins/vitals.d.ts +2 -25
  121. package/dist/plugins/vitals.js +4 -86
  122. package/dist/plugins-BZvDqGx5.d.ts +144 -0
  123. package/dist/{plugins-CzUiTn_r.js → plugins-DVy_vaYr.js} +3 -1
  124. package/dist/poll-CjKsWZi8.js +89 -0
  125. package/dist/requests-BwD6MKEq.js +282 -0
  126. package/dist/requests-CJrUf465.d.ts +50 -0
  127. package/dist/review.d.ts +181 -0
  128. package/dist/review.js +1017 -0
  129. package/dist/same-origin-BGet22CC.js +21 -0
  130. package/dist/scan-DzJNXqOk.js +165 -0
  131. package/dist/selector-NSYSe7AZ.js +28 -0
  132. package/dist/seo-Dq9q_QkO.js +551 -0
  133. package/dist/seo-panel-CfiY-TnT.js +124 -0
  134. package/dist/server.d.ts +3 -39
  135. package/dist/server.js +2 -105
  136. package/dist/sessions-panel-COvhPAzv.js +98 -0
  137. package/dist/shortcut-s_mjGeU8.js +179 -0
  138. package/dist/state-CjjZPjPJ.js +40 -0
  139. package/dist/state-boundary.d.ts +26 -0
  140. package/dist/state-boundary.js +61 -0
  141. package/dist/store/convex.d.ts +33 -0
  142. package/dist/store/convex.js +52 -0
  143. package/dist/store-CQqIIKTc.js +59 -0
  144. package/dist/store-Ync9eb1G.js +67 -0
  145. package/dist/store.d.ts +76 -0
  146. package/dist/store.js +188 -0
  147. package/dist/styles-BA8ueHoV.js +342 -0
  148. package/dist/styles-DKU_P8MH.js +139 -0
  149. package/dist/styles-DPpDPmzi.js +68 -0
  150. package/dist/tokens-panel-CbMQfasZ.js +142 -0
  151. package/dist/types-B-ulf2Jp.js +8 -0
  152. package/dist/types-BIgGf-0C.d.ts +25 -0
  153. package/dist/types-BIkI-qN8.js +30 -0
  154. package/dist/types-Cxh4twqc.d.ts +50 -0
  155. package/dist/types-DIdPfjtV.js +6 -0
  156. package/dist/types-DaJcsEjO.d.ts +44 -0
  157. package/dist/types-Dn68psVz.d.ts +118 -0
  158. package/dist/types-f3jlNxzw.d.ts +92 -0
  159. package/dist/types-szkr2QOF.d.ts +39 -0
  160. package/dist/unlock-store-4V3vR4Eg.js +96 -0
  161. package/dist/variant-groups-TIfO3NIj.js +137 -0
  162. package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
  163. package/dist/variants-panel-BDoSkwBJ.js +457 -0
  164. package/dist/variants-types-CcRf119M.d.ts +63 -0
  165. package/dist/variants.d.ts +43 -0
  166. package/dist/variants.js +83 -0
  167. package/dist/vitals-panel-BCmMUntW.js +30 -0
  168. package/dist/vite.d.ts +37 -0
  169. package/dist/vite.js +134 -0
  170. package/package.json +85 -5
  171. package/dist/define-hud-BHQR8Lbv.d.ts +0 -31
  172. package/dist/plugins-1QmTmZyL.d.ts +0 -76
@@ -0,0 +1,31 @@
1
+ //#region src/next/env.ts
2
+ /**
3
+ * Env ladder: kill switch → `NODE_ENV` (inlined by Next, so production
4
+ * bundles fold the development branch) → `NEXT_PUBLIC_HUD_ENV` (k8s overlays)
5
+ * → `VERCEL_ENV` → production.
6
+ *
7
+ * Each read is a literal `process.env.X` so Next can inline it in client code.
8
+ * Where there is no `process` at all (a Vite client) the ladder has nothing to
9
+ * read and answers production; pass the tier to `createHudLoader` instead.
10
+ */
11
+ function resolveHudEnv() {
12
+ if (typeof process === "undefined") return "production";
13
+ if (process.env.NEXT_PUBLIC_HUD_DISABLED === "true") return "disabled";
14
+ if (process.env.NODE_ENV === "development") return "development";
15
+ const explicit = process.env.NEXT_PUBLIC_HUD_ENV;
16
+ if (explicit === "staging" || explicit === "preview" || explicit === "production") return explicit;
17
+ if (process.env.VERCEL_ENV === "preview") return "preview";
18
+ return "production";
19
+ }
20
+ const LABELS = {
21
+ development: "DEV",
22
+ preview: "PREVIEW",
23
+ staging: "STAGING",
24
+ production: "PROD",
25
+ disabled: "OFF"
26
+ };
27
+ function hudEnvLabel(env = resolveHudEnv()) {
28
+ return LABELS[env];
29
+ }
30
+ //#endregion
31
+ export { resolveHudEnv as n, hudEnvLabel as t };
@@ -0,0 +1,103 @@
1
+ import { a as assertId, i as assertCollection, o as assertValue, s as isStoreValue, t as HudStoreError } from "./types-BIkI-qN8.js";
2
+ //#region src/store/file.ts
3
+ /** `process.cwd()`, or undefined where there is none (a browser, an edge runtime). */
4
+ function currentDir() {
5
+ const proc = globalThis.process;
6
+ return typeof proc?.cwd === "function" ? proc.cwd() : void 0;
7
+ }
8
+ async function nodeModules() {
9
+ try {
10
+ const [fs, path] = await Promise.all([import("node:fs/promises"), import("node:path")]);
11
+ return {
12
+ fs,
13
+ path
14
+ };
15
+ } catch {
16
+ throw new HudStoreError("hud store: file() needs a Node runtime", 500);
17
+ }
18
+ }
19
+ function isNotFound(error) {
20
+ return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
21
+ }
22
+ /**
23
+ * The default store: one JSON file per collection under `.hud/`, keyed by id,
24
+ * so a human or an agent can read and edit it (`.hud/variants.json`:
25
+ * `{ "hero:b": { "score": 8, "rationale": "…", "scoredBy": "claude" } }`).
26
+ *
27
+ * Server side only: the browser reaches it through `storeRoutes()` or a
28
+ * plugin's own routes. The collection name is validated and the resolved
29
+ * path checked against `dir`, so no request can name a file outside it.
30
+ * Writes go to a temporary file and are renamed into place, one at a time
31
+ * per collection.
32
+ */
33
+ function file({ dir } = {}) {
34
+ const queues = /* @__PURE__ */ new Map();
35
+ async function resolved(collection) {
36
+ assertCollection(collection);
37
+ const { fs, path } = await nodeModules();
38
+ const base = dir ?? (currentDir() === void 0 ? void 0 : `${currentDir()}/.hud`);
39
+ if (!base) throw new HudStoreError("hud store: file() has no directory (no cwd)", 500);
40
+ const root = path.resolve(base);
41
+ const target = path.resolve(root, `${collection}.json`);
42
+ if (!target.startsWith(root + path.sep)) throw new HudStoreError(`hud store: "${collection}" resolves outside ${root}`);
43
+ return {
44
+ fs,
45
+ path,
46
+ root,
47
+ target
48
+ };
49
+ }
50
+ async function read(collection) {
51
+ const { fs, target } = await resolved(collection);
52
+ let text;
53
+ try {
54
+ text = await fs.readFile(target, "utf8");
55
+ } catch (error) {
56
+ if (isNotFound(error)) return {};
57
+ throw error;
58
+ }
59
+ let parsed;
60
+ try {
61
+ parsed = JSON.parse(text);
62
+ } catch {
63
+ throw new HudStoreError(`hud store: ${target} is not valid JSON`, 500);
64
+ }
65
+ if (!isStoreValue(parsed)) throw new HudStoreError(`hud store: ${target} must hold a JSON object keyed by id`, 500);
66
+ const documents = {};
67
+ for (const [id, value] of Object.entries(parsed)) if (isStoreValue(value)) documents[id] = value;
68
+ return documents;
69
+ }
70
+ /** Runs `task` after every earlier write to the collection has finished. */
71
+ function serial(collection, task) {
72
+ const next = (queues.get(collection) ?? Promise.resolve()).then(task, task);
73
+ queues.set(collection, next.catch(() => void 0));
74
+ return next;
75
+ }
76
+ return {
77
+ async get(collection, id) {
78
+ assertId(id);
79
+ return (await read(collection))[id] ?? null;
80
+ },
81
+ async set(collection, id, value) {
82
+ assertId(id);
83
+ assertValue(value);
84
+ await serial(collection, async () => {
85
+ const { fs, root, target } = await resolved(collection);
86
+ const documents = await read(collection);
87
+ documents[id] = value;
88
+ await fs.mkdir(root, { recursive: true });
89
+ const tmp = `${target}.${Date.now().toString(36)}.tmp`;
90
+ await fs.writeFile(tmp, `${JSON.stringify(documents, null, 2)}\n`, "utf8");
91
+ await fs.rename(tmp, target);
92
+ });
93
+ },
94
+ async list(collection) {
95
+ return Object.entries(await read(collection)).map(([id, value]) => ({
96
+ id,
97
+ value
98
+ }));
99
+ }
100
+ };
101
+ }
102
+ //#endregion
103
+ export { file as t };
@@ -0,0 +1,58 @@
1
+ //#region src/plugins/data/flags.d.ts
2
+ /**
3
+ * `@hansenexus/hud/flags`: how an app reads the HUD's feature-flag overrides.
4
+ *
5
+ * Production-safe and dependency-free: it parses two small JSON documents the
6
+ * data plugin writes, one in the `hud-flags` cookie (scope `cookie`, read by
7
+ * the server and the client) and one in `localStorage["hud-flags"]` (scope
8
+ * `local`, client only). Nothing here knows whether the HUD exists; an
9
+ * override is whatever those two places say. Gate the read at the import
10
+ * site like the HUD itself (`NODE_ENV`, `NEXT_PUBLIC_HUD_ENABLED`), since a
11
+ * visitor can set a cookie by hand and production never gets one from the HUD.
12
+ */
13
+ type HudFlagValue = boolean | string | number;
14
+ /** Where an override lives, which decides who can read it. */
15
+ type HudFlagScope = "cookie" | "local";
16
+ declare const HUD_FLAG_SCOPES: readonly HudFlagScope[];
17
+ /** One override, as the data plugin stores it (`.hud/flags.json` with `file()`). */
18
+ interface HudFlagOverride {
19
+ key: string;
20
+ value: HudFlagValue;
21
+ scope: HudFlagScope;
22
+ }
23
+ /** Cookie carrying the `cookie`-scoped overrides, URL-encoded JSON `{ key: value }`. */
24
+ declare const FLAGS_COOKIE = "hud-flags";
25
+ /** `localStorage` key carrying the `local`-scoped overrides, JSON `{ key: value }`. */
26
+ declare const FLAGS_STORAGE_KEY = "hud-flags";
27
+ /** Flag keys are slugs with dots allowed (`checkout.new`), one line, bounded. */
28
+ declare const FLAG_KEY: RegExp;
29
+ declare function isFlagValue(value: unknown): value is HudFlagValue;
30
+ declare function isFlagScope(value: unknown): value is HudFlagScope;
31
+ /** Parses a `{ key: value }` document; anything malformed reads as no overrides. */
32
+ declare function parseFlagOverrides(text: string | null | undefined): Record<string, HudFlagValue>;
33
+ /** The `hud-flags` cookie out of a `Cookie:` header or `document.cookie`. */
34
+ declare function readFlagCookie(cookieHeader: string | null | undefined): string | undefined;
35
+ interface FlagOverrideSource {
36
+ /** A `Cookie:` request header on the server, `document.cookie` in the browser. */
37
+ cookie?: string | null | undefined;
38
+ /** `localStorage` (or anything with `getItem`) in the browser; omit on the server. */
39
+ storage?: Pick<Storage, "getItem"> | null | undefined;
40
+ }
41
+ /**
42
+ * Every override the app should honour, `local` winning over `cookie` when
43
+ * both name a key. On the server pass the request's cookie header; in the
44
+ * browser pass `document.cookie` and `localStorage`.
45
+ */
46
+ declare function readFlagOverrides({ cookie, storage }: FlagOverrideSource): Record<string, HudFlagValue>;
47
+ /** One flag's override, or `fallback` (the app's real value) when there is none. */
48
+ declare function flagOverride<T extends HudFlagValue>(key: string, source: FlagOverrideSource, fallback: T): HudFlagValue | T;
49
+ /** The JSON document for one scope: `{ key: value }`, keys sorted so the cookie is stable. */
50
+ declare function serializeFlagOverrides(overrides: readonly HudFlagOverride[], scope: HudFlagScope): string;
51
+ /**
52
+ * `Set-Cookie` value for the cookie scope: the document when there is one
53
+ * override, removal when there is none. Not httpOnly on purpose, since the
54
+ * app reads it in the browser too; `SameSite=Lax` so it survives navigation.
55
+ */
56
+ declare function flagCookieString(overrides: readonly HudFlagOverride[]): string;
57
+ //#endregion
58
+ export { HUD_FLAG_SCOPES as a, HudFlagValue as c, isFlagScope as d, isFlagValue as f, serializeFlagOverrides as g, readFlagOverrides as h, FlagOverrideSource as i, flagCookieString as l, readFlagCookie as m, FLAGS_STORAGE_KEY as n, HudFlagOverride as o, parseFlagOverrides as p, FLAG_KEY as r, HudFlagScope as s, FLAGS_COOKIE as t, flagOverride as u };
@@ -0,0 +1,2 @@
1
+ import { a as HUD_FLAG_SCOPES, c as HudFlagValue, d as isFlagScope, f as isFlagValue, g as serializeFlagOverrides, h as readFlagOverrides, i as FlagOverrideSource, l as flagCookieString, m as readFlagCookie, n as FLAGS_STORAGE_KEY, o as HudFlagOverride, p as parseFlagOverrides, r as FLAG_KEY, s as HudFlagScope, t as FLAGS_COOKIE, u as flagOverride } from "./flags-DVtaJ8pQ.js";
2
+ export { FLAGS_COOKIE, FLAGS_STORAGE_KEY, FLAG_KEY, FlagOverrideSource, HUD_FLAG_SCOPES, HudFlagOverride, HudFlagScope, HudFlagValue, flagCookieString, flagOverride, isFlagScope, isFlagValue, parseFlagOverrides, readFlagCookie, readFlagOverrides, serializeFlagOverrides };
package/dist/flags.js ADDED
@@ -0,0 +1,82 @@
1
+ //#region src/plugins/data/flags.ts
2
+ const HUD_FLAG_SCOPES = ["cookie", "local"];
3
+ /** Cookie carrying the `cookie`-scoped overrides, URL-encoded JSON `{ key: value }`. */
4
+ const FLAGS_COOKIE = "hud-flags";
5
+ /** `localStorage` key carrying the `local`-scoped overrides, JSON `{ key: value }`. */
6
+ const FLAGS_STORAGE_KEY = "hud-flags";
7
+ /** Flag keys are slugs with dots allowed (`checkout.new`), one line, bounded. */
8
+ const FLAG_KEY = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,99}$/;
9
+ function isFlagValue(value) {
10
+ return typeof value === "boolean" || typeof value === "string" || typeof value === "number" && Number.isFinite(value);
11
+ }
12
+ function isFlagScope(value) {
13
+ return value === "cookie" || value === "local";
14
+ }
15
+ /** Parses a `{ key: value }` document; anything malformed reads as no overrides. */
16
+ function parseFlagOverrides(text) {
17
+ if (!text) return {};
18
+ let parsed;
19
+ try {
20
+ parsed = JSON.parse(text);
21
+ } catch {
22
+ return {};
23
+ }
24
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return {};
25
+ const overrides = {};
26
+ for (const [key, value] of Object.entries(parsed)) if (FLAG_KEY.test(key) && isFlagValue(value)) overrides[key] = value;
27
+ return overrides;
28
+ }
29
+ /** The `hud-flags` cookie out of a `Cookie:` header or `document.cookie`. */
30
+ function readFlagCookie(cookieHeader) {
31
+ if (!cookieHeader) return void 0;
32
+ for (const part of cookieHeader.split(";")) {
33
+ const trimmed = part.trim();
34
+ if (trimmed.startsWith(`hud-flags=`)) try {
35
+ return decodeURIComponent(trimmed.slice(10));
36
+ } catch {
37
+ return;
38
+ }
39
+ }
40
+ }
41
+ /**
42
+ * Every override the app should honour, `local` winning over `cookie` when
43
+ * both name a key. On the server pass the request's cookie header; in the
44
+ * browser pass `document.cookie` and `localStorage`.
45
+ */
46
+ function readFlagOverrides({ cookie, storage }) {
47
+ const fromCookie = parseFlagOverrides(readFlagCookie(cookie));
48
+ let fromStorage = {};
49
+ if (storage) try {
50
+ fromStorage = parseFlagOverrides(storage.getItem(FLAGS_STORAGE_KEY));
51
+ } catch {
52
+ fromStorage = {};
53
+ }
54
+ return {
55
+ ...fromCookie,
56
+ ...fromStorage
57
+ };
58
+ }
59
+ /** One flag's override, or `fallback` (the app's real value) when there is none. */
60
+ function flagOverride(key, source, fallback) {
61
+ const value = readFlagOverrides(source)[key];
62
+ return value === void 0 ? fallback : value;
63
+ }
64
+ /** The JSON document for one scope: `{ key: value }`, keys sorted so the cookie is stable. */
65
+ function serializeFlagOverrides(overrides, scope) {
66
+ const document = {};
67
+ for (const override of [...overrides].sort((a, b) => a.key.localeCompare(b.key))) if (override.scope === scope) document[override.key] = override.value;
68
+ return JSON.stringify(document);
69
+ }
70
+ /**
71
+ * `Set-Cookie` value for the cookie scope: the document when there is one
72
+ * override, removal when there is none. Not httpOnly on purpose, since the
73
+ * app reads it in the browser too; `SameSite=Lax` so it survives navigation.
74
+ */
75
+ function flagCookieString(overrides) {
76
+ const document = serializeFlagOverrides(overrides, "cookie");
77
+ const base = `${FLAGS_COOKIE}=`;
78
+ if (document === "{}") return `${base}; Path=/; SameSite=Lax; Max-Age=0`;
79
+ return `${base}${encodeURIComponent(document)}; Path=/; SameSite=Lax; Max-Age=2592000`;
80
+ }
81
+ //#endregion
82
+ export { FLAGS_COOKIE, FLAGS_STORAGE_KEY, FLAG_KEY, HUD_FLAG_SCOPES, flagCookieString, flagOverride, isFlagScope, isFlagValue, parseFlagOverrides, readFlagCookie, readFlagOverrides, serializeFlagOverrides };
@@ -0,0 +1,153 @@
1
+ //#region src/plugins/design/force-state.ts
2
+ /**
3
+ * Force-state store: lets a reviewer (the States panel) or an agent
4
+ * (`?__state=`) render any registered state boundary as loading, empty or
5
+ * error without faking data.
6
+ *
7
+ * Development only. `StateBoundary` reaches this module behind a
8
+ * `NODE_ENV === "development"` constant, so production builds drop it; a
9
+ * consumer's bundle gate greps client chunks for FORCE_STATE_MARKER to prove it.
10
+ */
11
+ const FORCED_STATES = [
12
+ "loading",
13
+ "empty",
14
+ "error"
15
+ ];
16
+ /** `?__state=loading` forces top-level boundaries; `?__state=<id>:error` one boundary. */
17
+ const FORCE_STATE_PARAM = "__state";
18
+ /**
19
+ * globalThis key of the store singleton, and the bundle-gate marker. Holding
20
+ * the store on globalThis keeps one instance even if the module is evaluated
21
+ * twice: HMR, or the app's `StateBoundary` chunk and the HUD's States panel
22
+ * chunk each carrying a copy.
23
+ */
24
+ const FORCE_STATE_MARKER = "__HANSENEXUS_HUD_FORCE_STATE__";
25
+ function isForcedState(value) {
26
+ return FORCED_STATES.includes(value);
27
+ }
28
+ /** Parses the value of `?__state=`; anything unrecognised is ignored (null). */
29
+ function parseForceStateParam(value) {
30
+ if (!value) return null;
31
+ const separator = value.lastIndexOf(":");
32
+ if (separator === -1) return isForcedState(value) ? {
33
+ state: value,
34
+ target: null
35
+ } : null;
36
+ const target = value.slice(0, separator);
37
+ const state = value.slice(separator + 1);
38
+ if (!target || !isForcedState(state)) return null;
39
+ return {
40
+ state,
41
+ target
42
+ };
43
+ }
44
+ /** Reads the param out of a `location.search` string. */
45
+ function forceStateParamFromSearch(search) {
46
+ return parseForceStateParam(new URLSearchParams(search).get(FORCE_STATE_PARAM));
47
+ }
48
+ /** The param's value as it appears in the URL, `<id>:<state>` or `<state>`. */
49
+ function formatForceStateParam(param) {
50
+ return param.target === null ? param.state : `${param.target}:${param.state}`;
51
+ }
52
+ /**
53
+ * The state a boundary renders. A panel override for the boundary wins; else
54
+ * the URL param applies to its target, or, untargeted, to the nearest
55
+ * boundaries: the top-level ones. Forcing an outer boundary unmounts the
56
+ * inner ones anyway, so the page-level state is what a screenshot wants.
57
+ */
58
+ function resolveForcedState(snapshot, boundary) {
59
+ const override = snapshot.overrides[boundary.id];
60
+ if (override) return override;
61
+ const { param } = snapshot;
62
+ if (!param) return null;
63
+ if (param.target !== null) return param.target === boundary.id ? param.state : null;
64
+ return boundary.parentId === null ? param.state : null;
65
+ }
66
+ var ForceStateStore = class {
67
+ registrations = /* @__PURE__ */ new Map();
68
+ overrides = {};
69
+ search = "";
70
+ snapshot = {
71
+ boundaries: [],
72
+ overrides: {},
73
+ param: null
74
+ };
75
+ listeners = /* @__PURE__ */ new Set();
76
+ getSnapshot = () => this.snapshot;
77
+ subscribe = (listener) => {
78
+ this.listeners.add(listener);
79
+ return () => {
80
+ this.listeners.delete(listener);
81
+ };
82
+ };
83
+ /** Registers a mounted boundary; the returned function unregisters it. Mounts are counted. */
84
+ register(id, parentId) {
85
+ const existing = this.registrations.get(id);
86
+ this.registrations.set(id, {
87
+ parentId,
88
+ count: (existing?.count ?? 0) + 1
89
+ });
90
+ this.emit();
91
+ return () => {
92
+ const current = this.registrations.get(id);
93
+ if (!current) return;
94
+ if (current.count > 1) this.registrations.set(id, {
95
+ ...current,
96
+ count: current.count - 1
97
+ });
98
+ else this.registrations.delete(id);
99
+ this.emit();
100
+ };
101
+ }
102
+ /** Forces one boundary (panel toggle); null returns it to auto. */
103
+ force(id, state) {
104
+ const next = { ...this.overrides };
105
+ if (state) next[id] = state;
106
+ else delete next[id];
107
+ this.overrides = next;
108
+ this.emit();
109
+ }
110
+ clearOverrides() {
111
+ this.overrides = {};
112
+ this.emit();
113
+ }
114
+ /** Feeds the current `location.search`; a no-op when it did not change. */
115
+ syncSearch(search) {
116
+ if (search === this.search) return;
117
+ this.search = search;
118
+ this.emit();
119
+ }
120
+ emit() {
121
+ this.snapshot = {
122
+ boundaries: [...this.registrations].map(([id, { parentId }]) => ({
123
+ id,
124
+ parentId
125
+ })),
126
+ overrides: this.overrides,
127
+ param: forceStateParamFromSearch(this.search)
128
+ };
129
+ for (const listener of this.listeners) listener();
130
+ }
131
+ };
132
+ /** The page's store, created on first use. */
133
+ function getForceStateStore() {
134
+ const holder = globalThis;
135
+ holder[FORCE_STATE_MARKER] ??= new ForceStateStore();
136
+ return holder[FORCE_STATE_MARKER];
137
+ }
138
+ /** Subscribes to the page's store and keeps it in step with back/forward navigation. */
139
+ function subscribeForceState(listener) {
140
+ const store = getForceStateStore();
141
+ const onPopState = () => store.syncSearch(window.location.search);
142
+ window.addEventListener("popstate", onPopState);
143
+ const unsubscribe = store.subscribe(listener);
144
+ return () => {
145
+ window.removeEventListener("popstate", onPopState);
146
+ unsubscribe();
147
+ };
148
+ }
149
+ function getForceStateSnapshot() {
150
+ return getForceStateStore().getSnapshot();
151
+ }
152
+ //#endregion
153
+ export { getForceStateSnapshot as a, subscribeForceState as c, formatForceStateParam as i, FORCE_STATE_MARKER as n, getForceStateStore as o, FORCE_STATE_PARAM as r, resolveForcedState as s, FORCED_STATES as t };
@@ -0,0 +1,23 @@
1
+ //#region src/plugins/design/force-state.d.ts
2
+ /**
3
+ * Force-state store: lets a reviewer (the States panel) or an agent
4
+ * (`?__state=`) render any registered state boundary as loading, empty or
5
+ * error without faking data.
6
+ *
7
+ * Development only. `StateBoundary` reaches this module behind a
8
+ * `NODE_ENV === "development"` constant, so production builds drop it; a
9
+ * consumer's bundle gate greps client chunks for FORCE_STATE_MARKER to prove it.
10
+ */
11
+ declare const FORCED_STATES: readonly ["loading", "empty", "error"];
12
+ type ForcedState = (typeof FORCED_STATES)[number];
13
+ /** `?__state=loading` forces top-level boundaries; `?__state=<id>:error` one boundary. */
14
+ declare const FORCE_STATE_PARAM = "__state";
15
+ /**
16
+ * globalThis key of the store singleton, and the bundle-gate marker. Holding
17
+ * the store on globalThis keeps one instance even if the module is evaluated
18
+ * twice: HMR, or the app's `StateBoundary` chunk and the HUD's States panel
19
+ * chunk each carrying a copy.
20
+ */
21
+ declare const FORCE_STATE_MARKER = "__HANSENEXUS_HUD_FORCE_STATE__";
22
+ //#endregion
23
+ export { ForcedState as i, FORCE_STATE_MARKER as n, FORCE_STATE_PARAM as r, FORCED_STATES as t };
@@ -0,0 +1,97 @@
1
+ import { i as formatForceStateParam, o as getForceStateStore, r as FORCE_STATE_PARAM, s as resolveForcedState, t as FORCED_STATES } from "./force-state-BaqWsmrf.js";
2
+ import { i as useForceState } from "./design-D0kGgPoP.js";
3
+ import { t as DESIGN_CSS } from "./styles-DKU_P8MH.js";
4
+ import { useEffect } from "react";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ //#region src/plugins/design/force-state-panel.tsx
7
+ const CHOICES = [null, ...FORCED_STATES];
8
+ /**
9
+ * Toggles every mounted `StateBoundary` between its real state and a forced
10
+ * loading, empty or error. Toggles live in memory: a reload returns every
11
+ * boundary to auto, so a forgotten toggle cannot outlive the page.
12
+ */
13
+ function ForceStatePanel() {
14
+ const store = getForceStateStore();
15
+ const snapshot = useForceState();
16
+ const hasOverrides = Object.keys(snapshot.overrides).length > 0;
17
+ useEffect(() => store.syncSearch(window.location.search), [store]);
18
+ return /* @__PURE__ */ jsxs("div", {
19
+ className: "design",
20
+ "data-hud-force-state": "",
21
+ children: [
22
+ /* @__PURE__ */ jsx("style", { children: DESIGN_CSS }),
23
+ /* @__PURE__ */ jsxs("section", {
24
+ className: "design-section",
25
+ "aria-label": "State boundaries",
26
+ children: [/* @__PURE__ */ jsxs("div", {
27
+ className: "design-heading",
28
+ children: [/* @__PURE__ */ jsx("span", { children: "State boundaries" }), hasOverrides && /* @__PURE__ */ jsx("button", {
29
+ type: "button",
30
+ className: "design-link",
31
+ onClick: () => store.clearOverrides(),
32
+ children: "reset all"
33
+ })]
34
+ }), snapshot.boundaries.length === 0 ? /* @__PURE__ */ jsx("p", {
35
+ className: "design-hint",
36
+ children: "No state boundary on this page. Wrap a query branch in StateBoundary from @hansenexus/hud/state-boundary to list it here."
37
+ }) : snapshot.boundaries.map((boundary) => {
38
+ const override = snapshot.overrides[boundary.id] ?? null;
39
+ const effective = resolveForcedState(snapshot, boundary);
40
+ return /* @__PURE__ */ jsxs("div", {
41
+ className: "design-boundary",
42
+ children: [/* @__PURE__ */ jsxs("div", {
43
+ className: "design-row",
44
+ children: [/* @__PURE__ */ jsxs("span", {
45
+ className: "design-grow design-mono",
46
+ children: [boundary.parentId ? "↳ " : "", boundary.id]
47
+ }), /* @__PURE__ */ jsx("span", {
48
+ className: "design-badge",
49
+ "data-tone": effective ? "forced" : void 0,
50
+ children: effective ?? "real"
51
+ })]
52
+ }), /* @__PURE__ */ jsx("fieldset", {
53
+ className: "design-segments",
54
+ "aria-label": `${boundary.id} state`,
55
+ children: CHOICES.map((choice) => /* @__PURE__ */ jsx("button", {
56
+ type: "button",
57
+ className: "design-segment",
58
+ "aria-pressed": override === choice,
59
+ onClick: () => store.force(boundary.id, choice),
60
+ children: choice ?? "auto"
61
+ }, choice ?? "auto"))
62
+ })]
63
+ }, boundary.id);
64
+ })]
65
+ }),
66
+ /* @__PURE__ */ jsxs("section", {
67
+ className: "design-section",
68
+ "aria-label": "URL param",
69
+ children: [/* @__PURE__ */ jsxs("div", {
70
+ className: "design-row",
71
+ children: [/* @__PURE__ */ jsxs("span", {
72
+ className: "design-grow design-mono",
73
+ children: [
74
+ "?",
75
+ FORCE_STATE_PARAM,
76
+ "="
77
+ ]
78
+ }), /* @__PURE__ */ jsx("span", {
79
+ className: "design-mono",
80
+ children: snapshot.param ? formatForceStateParam(snapshot.param) : "not set"
81
+ })]
82
+ }), /* @__PURE__ */ jsxs("p", {
83
+ className: "design-hint",
84
+ children: [
85
+ "?",
86
+ FORCE_STATE_PARAM,
87
+ "=loading|empty|error forces the top-level boundaries; ?",
88
+ FORCE_STATE_PARAM,
89
+ "=<id>:error targets one. A toggle here wins over the param."
90
+ ]
91
+ })]
92
+ })
93
+ ]
94
+ });
95
+ }
96
+ //#endregion
97
+ export { ForceStatePanel, ForceStatePanel as default };
@@ -0,0 +1,53 @@
1
+ //#region src/auto/generate.ts
2
+ const PACKAGE = "@hansenexus/hud";
3
+ /** Which import each feature adds: `name` from `subpath`. */
4
+ const FEATURE_IMPORTS = {
5
+ configured: null,
6
+ next: ["routes", "plugins/routes"],
7
+ convex: ["inspectConvex", "plugins/inspect/convex"],
8
+ reactQuery: ["inspectReactQuery", "plugins/inspect/react-query"],
9
+ swr: ["inspectSwr", "plugins/inspect/swr"],
10
+ msw: ["data", "plugins/data"],
11
+ betterAuth: ["data", "plugins/data"],
12
+ convexAuth: ["data", "plugins/data"]
13
+ };
14
+ /** The base plugins every auto HUD carries. */
15
+ const BASE_IMPORTS = [
16
+ ["a11y", "plugins/a11y"],
17
+ ["forceState", "plugins/design"],
18
+ ["inspect", "plugins/inspect"],
19
+ ["observe", "plugins/observe"],
20
+ ["seo", "plugins/seo"],
21
+ ["vitals", "plugins/vitals"]
22
+ ];
23
+ /** The factories the generated module hands `assembleAuto`, in import order. */
24
+ function autoImports(detected) {
25
+ const imports = new Map(BASE_IMPORTS);
26
+ for (const [feature, entry] of Object.entries(FEATURE_IMPORTS)) if (entry && detected[feature]) imports.set(entry[0], entry[1]);
27
+ return imports;
28
+ }
29
+ /**
30
+ * The generated module. `source` names where detection read from, for the
31
+ * header comment. Exports match the stand-in in `src/auto/index.ts`
32
+ * (`detected`, `auto`, default), so the types in `dist/auto.d.ts` apply.
33
+ */
34
+ function generateAutoModule(detected, source = "package.json") {
35
+ const imports = [...autoImports(detected)].sort(([, a], [, b]) => a < b ? -1 : a > b ? 1 : 0).map(([name, subpath]) => `import { ${name} } from "${PACKAGE}/${subpath}";`);
36
+ const factories = [...autoImports(detected).keys()].sort().join(", ");
37
+ return [
38
+ `// Generated by ${PACKAGE} from ${source}. Do not edit: it is rewritten on every start.`,
39
+ `import { assembleAuto } from "${PACKAGE}/auto/runtime";`,
40
+ ...imports,
41
+ "",
42
+ `export const detected = Object.freeze(${JSON.stringify(detected)});`,
43
+ "",
44
+ "export function auto(options) {",
45
+ ` return assembleAuto(detected, { ${factories} }, options);`,
46
+ "}",
47
+ "",
48
+ "export default auto;",
49
+ ""
50
+ ].join("\n");
51
+ }
52
+ //#endregion
53
+ export { generateAutoModule as t };