@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.
Files changed (159) hide show
  1. package/README.md +634 -12
  2. package/dist/a11y-B5DUaiCs.js +246 -0
  3. package/dist/a11y-panel-p_t4eD7p.js +207 -0
  4. package/dist/{capabilities-CjulXFQX.js → access-C7zlaqj6.js} +1 -90
  5. package/dist/{access-CNvJOwKM.d.ts → access-D_ewAEJG.d.ts} +11 -4
  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-vEjyJfPW.d.ts → env-CApnbI0r.d.ts} +2 -0
  26. package/dist/{env-DfxpPfs9.js → env-CaiFPIhF.js} +3 -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-panel-_otVYh9i.js +97 -0
  32. package/dist/generate-C8lQl3Eh.js +53 -0
  33. package/dist/handler-BpVhxEmU.js +106 -0
  34. package/dist/{handler-WmE4Lu7l.d.ts → handler-DtYVCZY6.d.ts} +1 -1
  35. package/dist/index-BAV_1W8a.d.ts +43 -0
  36. package/dist/index-BJ26pse9.d.ts +70 -0
  37. package/dist/index-BnQ0dTZf.d.ts +19 -0
  38. package/dist/index-CwfX-W87.d.ts +72 -0
  39. package/dist/index-DcH9V3cU.d.ts +48 -0
  40. package/dist/index-DqOyNf1u.d.ts +65 -0
  41. package/dist/index-DstI_ike.d.ts +66 -0
  42. package/dist/index-Dxz4fn4j.d.ts +42 -0
  43. package/dist/index-Hhh7OXzU.d.ts +129 -0
  44. package/dist/index-ReFbhQ9p.d.ts +25 -0
  45. package/dist/index-RgXfMBuW.d.ts +48 -0
  46. package/dist/{index-BYsdS-7d.d.ts → index-gCZBO53s.d.ts} +21 -3
  47. package/dist/index.d.ts +5 -5
  48. package/dist/index.js +710 -69
  49. package/dist/inspect-C9Ft8fqn.js +142 -0
  50. package/dist/inspect-root-BkaupBMp.js +429 -0
  51. package/dist/meta-Bv0sEao3.js +6 -0
  52. package/dist/meta-C_G7MB5w.d.ts +49 -0
  53. package/dist/mocks-CA-wM2SB.d.ts +109 -0
  54. package/dist/mocks-ESiRqk9o.js +150 -0
  55. package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
  56. package/dist/next/config.cjs +201 -0
  57. package/dist/next/config.d.cts +87 -0
  58. package/dist/next/config.d.ts +64 -0
  59. package/dist/next/config.js +84 -0
  60. package/dist/next.d.ts +14 -4
  61. package/dist/next.js +5 -3
  62. package/dist/observe-CdDnDBRP.js +89 -0
  63. package/dist/observe-panel-Cgp1M8oT.js +347 -0
  64. package/dist/ops-panel-CEqDe_UT.js +234 -0
  65. package/dist/{payload-CLKDVZWl.d.ts → payload-MUQ9ciER.d.ts} +25 -1
  66. package/dist/plugins/a11y.d.ts +2 -0
  67. package/dist/plugins/a11y.js +2 -0
  68. package/dist/plugins/access/server.d.ts +5 -5
  69. package/dist/plugins/access/server.js +4 -3
  70. package/dist/plugins/access.d.ts +5 -5
  71. package/dist/plugins/access.js +16 -215
  72. package/dist/plugins/agent/server.d.ts +3 -38
  73. package/dist/plugins/agent/server.js +47 -21
  74. package/dist/plugins/agent.d.ts +4 -4
  75. package/dist/plugins/agent.js +6 -348
  76. package/dist/plugins/capture/server.d.ts +92 -0
  77. package/dist/plugins/capture/server.js +248 -0
  78. package/dist/plugins/capture.d.ts +24 -0
  79. package/dist/plugins/capture.js +70 -0
  80. package/dist/plugins/data/msw-browser.d.ts +2 -0
  81. package/dist/plugins/data/msw-browser.js +39 -0
  82. package/dist/plugins/data/msw-node.d.ts +36 -0
  83. package/dist/plugins/data/msw-node.js +68 -0
  84. package/dist/plugins/data/server.d.ts +257 -0
  85. package/dist/plugins/data/server.js +717 -0
  86. package/dist/plugins/data.d.ts +6 -0
  87. package/dist/plugins/data.js +51 -0
  88. package/dist/plugins/design/server.d.ts +54 -0
  89. package/dist/plugins/design/server.js +198 -0
  90. package/dist/plugins/design.d.ts +4 -124
  91. package/dist/plugins/design.js +4 -619
  92. package/dist/plugins/inspect/convex.d.ts +2 -0
  93. package/dist/plugins/inspect/convex.js +486 -0
  94. package/dist/plugins/inspect/react-query.d.ts +2 -0
  95. package/dist/plugins/inspect/react-query.js +237 -0
  96. package/dist/plugins/inspect/sockets.d.ts +51 -0
  97. package/dist/plugins/inspect/sockets.js +397 -0
  98. package/dist/plugins/inspect/swr.d.ts +2 -0
  99. package/dist/plugins/inspect/swr.js +218 -0
  100. package/dist/plugins/inspect.d.ts +4 -0
  101. package/dist/plugins/inspect.js +3 -0
  102. package/dist/plugins/observe.d.ts +4 -64
  103. package/dist/plugins/observe.js +1 -616
  104. package/dist/plugins/ops/server.d.ts +1 -1
  105. package/dist/plugins/ops/server.js +2 -1
  106. package/dist/plugins/ops.d.ts +2 -1
  107. package/dist/plugins/ops.js +15 -336
  108. package/dist/plugins/routes/server.d.ts +88 -0
  109. package/dist/plugins/routes/server.js +62 -0
  110. package/dist/plugins/routes.d.ts +3 -0
  111. package/dist/plugins/routes.js +216 -0
  112. package/dist/plugins/seo.d.ts +2 -0
  113. package/dist/plugins/seo.js +2 -0
  114. package/dist/plugins/vitals.d.ts +2 -25
  115. package/dist/plugins/vitals.js +3 -2
  116. package/dist/{plugins-CQ_0w1ot.d.ts → plugins-BZvDqGx5.d.ts} +33 -3
  117. package/dist/poll-CjKsWZi8.js +89 -0
  118. package/dist/requests-BwD6MKEq.js +282 -0
  119. package/dist/requests-CJrUf465.d.ts +50 -0
  120. package/dist/review.js +2 -2
  121. package/dist/same-origin-BGet22CC.js +21 -0
  122. package/dist/scan-DzJNXqOk.js +165 -0
  123. package/dist/seo-Dq9q_QkO.js +551 -0
  124. package/dist/seo-panel-CfiY-TnT.js +124 -0
  125. package/dist/server.d.ts +2 -2
  126. package/dist/server.js +2 -105
  127. package/dist/sessions-panel-COvhPAzv.js +98 -0
  128. package/dist/{shortcut-U6ftVY06.js → shortcut-s_mjGeU8.js} +1 -44
  129. package/dist/{types-QJUajwWq.js → state-CjjZPjPJ.js} +13 -8
  130. package/dist/store/convex.d.ts +33 -0
  131. package/dist/store/convex.js +52 -0
  132. package/dist/{vitals-panel-Dvc5dnR-.js → store-CQqIIKTc.js} +1 -29
  133. package/dist/store-Ync9eb1G.js +67 -0
  134. package/dist/store.d.ts +76 -0
  135. package/dist/store.js +188 -0
  136. package/dist/{styles--slk86ZQ.js → styles-BA8ueHoV.js} +13 -3
  137. package/dist/styles-DKU_P8MH.js +139 -0
  138. package/dist/styles-DPpDPmzi.js +68 -0
  139. package/dist/tokens-panel-CbMQfasZ.js +142 -0
  140. package/dist/types-B-ulf2Jp.js +8 -0
  141. package/dist/types-BIgGf-0C.d.ts +25 -0
  142. package/dist/types-BIkI-qN8.js +30 -0
  143. package/dist/{types-DADBRiGk.d.ts → types-Cxh4twqc.d.ts} +1 -1
  144. package/dist/types-DIdPfjtV.js +6 -0
  145. package/dist/types-DaJcsEjO.d.ts +44 -0
  146. package/dist/types-Dn68psVz.d.ts +118 -0
  147. package/dist/types-szkr2QOF.d.ts +39 -0
  148. package/dist/unlock-store-4V3vR4Eg.js +96 -0
  149. package/dist/variant-groups-TIfO3NIj.js +137 -0
  150. package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
  151. package/dist/variants-panel-BDoSkwBJ.js +457 -0
  152. package/dist/variants-types-CcRf119M.d.ts +63 -0
  153. package/dist/variants.d.ts +43 -0
  154. package/dist/variants.js +83 -0
  155. package/dist/vitals-panel-BCmMUntW.js +30 -0
  156. package/dist/vite.d.ts +37 -0
  157. package/dist/vite.js +134 -0
  158. package/package.json +72 -5
  159. package/dist/define-hud-BBzsSl8b.d.ts +0 -36
@@ -0,0 +1,216 @@
1
+ import { i as definePlugin, n as HudApiError } from "../plugins-DVy_vaYr.js";
2
+ import { n as ROUTES_ID, t as ROUTES_CAPABILITY } from "../meta-Bv0sEao3.js";
3
+ import { useCallback, useEffect, useState } from "react";
4
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
+ //#region src/plugins/routes/styles.ts
6
+ /** Panel styles, rendered as a `<style>` inside the panel, so inside the shadow root. */
7
+ const ROUTES_CSS = `
8
+ .routes { display: grid; gap: 10px; min-width: 260px; }
9
+ .routes .head { display: flex; align-items: center; gap: 6px; }
10
+ .routes .head input {
11
+ flex: 1;
12
+ min-width: 0;
13
+ font: inherit;
14
+ color: inherit;
15
+ padding: 3px 8px;
16
+ background: var(--hud-bg);
17
+ border: 1px solid var(--hud-border);
18
+ border-radius: 6px;
19
+ }
20
+ .routes .head .count { color: var(--hud-fg-muted); font-family: var(--hud-mono); white-space: nowrap; }
21
+ .routes button.chip { padding: 1px 6px; border-radius: 999px; font-family: var(--hud-mono); }
22
+ .routes button.chip:hover { background: var(--hud-bg-subtle); }
23
+ .routes section { display: grid; gap: 2px; }
24
+ .routes h3 {
25
+ margin: 0 0 2px;
26
+ font-size: 10px;
27
+ font-weight: 600;
28
+ letter-spacing: 0.06em;
29
+ text-transform: uppercase;
30
+ color: var(--hud-fg-muted);
31
+ }
32
+ .routes ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
33
+ .routes li a, .routes li > span {
34
+ display: grid;
35
+ grid-template-columns: minmax(0, 1fr) auto;
36
+ align-items: center;
37
+ gap: 8px;
38
+ padding: 3px 6px;
39
+ border-radius: 4px;
40
+ font-family: var(--hud-mono);
41
+ color: inherit;
42
+ text-decoration: none;
43
+ overflow: hidden;
44
+ text-overflow: ellipsis;
45
+ white-space: nowrap;
46
+ }
47
+ .routes li a:hover { background: var(--hud-bg-subtle); }
48
+ .routes li a[aria-current="page"] { color: var(--hud-accent); font-weight: 600; }
49
+ .routes li > span { color: var(--hud-fg-muted); }
50
+ .routes li small { color: var(--hud-fg-muted); font-family: var(--hud-font); }
51
+ .routes .warn { color: var(--hud-warn); margin: 0; }
52
+ .routes .muted { color: var(--hud-fg-muted); margin: 0; }
53
+ `;
54
+ //#endregion
55
+ //#region src/plugins/routes/routes-panel.tsx
56
+ /** A readable message for a failed request; the route's own 500 bodies carry one. */
57
+ function describeError(error) {
58
+ if (error instanceof HudApiError) {
59
+ if (error.status === 404) return "route not mounted: add routes() to createHudHandler";
60
+ const body = error.body;
61
+ if (typeof body?.error === "string") return body.error;
62
+ return `HTTP ${error.status}`;
63
+ }
64
+ return error instanceof Error ? error.message : "request failed";
65
+ }
66
+ /** Loads the route list once per panel mount; `refresh` scans again. */
67
+ function useRoutes(ctx) {
68
+ const [state, setState] = useState({ loading: true });
69
+ const load = useCallback(() => {
70
+ let live = true;
71
+ setState((prev) => ({
72
+ ...prev,
73
+ loading: true
74
+ }));
75
+ ctx.api("/routes").then((data) => live && setState({
76
+ data,
77
+ loading: false
78
+ }), (error) => live && setState((prev) => ({
79
+ ...prev,
80
+ error: describeError(error),
81
+ loading: false
82
+ })));
83
+ return () => {
84
+ live = false;
85
+ };
86
+ }, [ctx]);
87
+ useEffect(load, [load]);
88
+ const refresh = useCallback(() => void load(), [load]);
89
+ return {
90
+ ...state,
91
+ refresh
92
+ };
93
+ }
94
+ function groupLabel(group) {
95
+ return group ?? "root";
96
+ }
97
+ /**
98
+ * Routes whose path or pattern contains the query, case-insensitive. A query
99
+ * that only matches some of a route's URLs narrows the route to those.
100
+ */
101
+ function filterRoutes(routes, query) {
102
+ const q = query.trim().toLowerCase();
103
+ if (!q) return [...routes];
104
+ return routes.flatMap((route) => {
105
+ if (route.path.toLowerCase().includes(q) || route.pattern.toLowerCase().includes(q)) return [route];
106
+ const urls = route.urls.filter(({ url }) => url.toLowerCase().includes(q));
107
+ return urls.length > 0 ? [{
108
+ ...route,
109
+ urls
110
+ }] : [];
111
+ });
112
+ }
113
+ function currentPath() {
114
+ return typeof location === "undefined" ? void 0 : location.pathname;
115
+ }
116
+ function RouteRow({ route, here }) {
117
+ if (route.unresolved.length > 0) return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("span", {
118
+ title: `${route.pattern}: no fixture for ${route.unresolved.join(", ")}`,
119
+ children: [route.path, /* @__PURE__ */ jsxs("small", { children: ["no fixture: ", route.unresolved.join(", ")] })]
120
+ }) });
121
+ return /* @__PURE__ */ jsx(Fragment, { children: route.urls.map(({ url, params }) => {
122
+ const values = Object.values(params).filter(Boolean);
123
+ return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("a", {
124
+ href: url,
125
+ title: route.pattern,
126
+ "aria-current": url === here ? "page" : void 0,
127
+ children: [url, values.length > 0 && /* @__PURE__ */ jsx("small", { children: route.path })]
128
+ }) }, url);
129
+ }) });
130
+ }
131
+ function RoutesPanel({ ctx }) {
132
+ const { data, error, loading, refresh } = useRoutes(ctx);
133
+ const [query, setQuery] = useState("");
134
+ const here = currentPath();
135
+ const routes = data ? filterRoutes(data.routes, query) : [];
136
+ const groups = [...new Set(routes.map((route) => groupLabel(route.group)))].sort();
137
+ const urlCount = data ? data.routes.reduce((n, route) => n + route.urls.length, 0) : 0;
138
+ return /* @__PURE__ */ jsxs("div", {
139
+ className: "routes",
140
+ children: [
141
+ /* @__PURE__ */ jsx("style", { children: ROUTES_CSS }),
142
+ /* @__PURE__ */ jsxs("div", {
143
+ className: "head",
144
+ children: [
145
+ /* @__PURE__ */ jsx("input", {
146
+ type: "search",
147
+ value: query,
148
+ onChange: (e) => setQuery(e.target.value),
149
+ placeholder: "Filter routes…",
150
+ "aria-label": "Filter routes"
151
+ }),
152
+ data && /* @__PURE__ */ jsxs("span", {
153
+ className: "count",
154
+ title: `${data.routes.length} routes in ${data.dir}`,
155
+ children: [
156
+ routes.length,
157
+ "/",
158
+ data.routes.length,
159
+ " · ",
160
+ urlCount,
161
+ " urls"
162
+ ]
163
+ }),
164
+ /* @__PURE__ */ jsx("button", {
165
+ type: "button",
166
+ className: "chip",
167
+ onClick: refresh,
168
+ title: "Scan the app directory again",
169
+ children: "rescan"
170
+ })
171
+ ]
172
+ }),
173
+ loading && !data && /* @__PURE__ */ jsx("p", {
174
+ className: "muted",
175
+ children: "Scanning…"
176
+ }),
177
+ error && /* @__PURE__ */ jsx("p", {
178
+ className: "warn",
179
+ children: error
180
+ }),
181
+ data && data.routes.length === 0 && /* @__PURE__ */ jsxs("p", {
182
+ className: "muted",
183
+ children: [
184
+ "No pages under ",
185
+ data.dir,
186
+ "."
187
+ ]
188
+ }),
189
+ groups.map((group) => /* @__PURE__ */ jsxs("section", {
190
+ "aria-label": group,
191
+ children: [/* @__PURE__ */ jsx("h3", { children: group }), /* @__PURE__ */ jsx("ul", { children: routes.filter((route) => groupLabel(route.group) === group).map((route) => /* @__PURE__ */ jsx(RouteRow, {
192
+ route,
193
+ here
194
+ }, route.pattern)) })]
195
+ }, group))
196
+ ]
197
+ });
198
+ }
199
+ //#endregion
200
+ //#region src/plugins/routes/index.tsx
201
+ /**
202
+ * Route index: every page of the app's `app/` tree, dynamic segments filled
203
+ * from the fixtures the server half knows, one click away. Client half; the
204
+ * scanner lives in `@hansenexus/hud/plugins/routes/server`, which also feeds
205
+ * the `hud sweep` CLI.
206
+ */
207
+ function routes() {
208
+ return definePlugin({
209
+ id: ROUTES_ID,
210
+ title: "Routes",
211
+ capability: ROUTES_CAPABILITY,
212
+ panel: RoutesPanel
213
+ });
214
+ }
215
+ //#endregion
216
+ export { ROUTES_CAPABILITY, ROUTES_ID, routes };
@@ -0,0 +1,2 @@
1
+ import { a as SeoLevel, i as SeoGroup, n as SeoSnapshot, o as runSeoChecks, r as SeoCheck, t as seo } from "../index-DcH9V3cU.js";
2
+ export { type SeoCheck, type SeoGroup, type SeoLevel, type SeoSnapshot, runSeoChecks, seo };
@@ -0,0 +1,2 @@
1
+ import { a as runSeoChecks, t as seo } from "../seo-Dq9q_QkO.js";
2
+ export { runSeoChecks, seo };
@@ -1,25 +1,2 @@
1
- import { Metric } from "web-vitals";
2
- //#region src/plugins/vitals/vitals-panel.d.ts
3
- declare function VitalsPanel(): import("react").JSX.Element;
4
- //#endregion
5
- //#region src/plugins/vitals/store.d.ts
6
- type VitalName = Metric["name"];
7
- type VitalRating = Metric["rating"];
8
- interface Vital {
9
- name: VitalName;
10
- value: number;
11
- rating: VitalRating;
12
- }
13
- type VitalsSnapshot = Partial<Record<VitalName, Vital>>;
14
- //#endregion
15
- //#region src/plugins/vitals/index.d.ts
16
- declare function VitalsPill(): import("react").JSX.Element;
17
- /** Core Web Vitals: LCP in the pill, all five metrics in the panel. Client only. */
18
- export declare function vitals(): {
19
- readonly id: "vitals";
20
- readonly title: "Vitals";
21
- readonly pill: typeof VitalsPill;
22
- readonly panel: typeof VitalsPanel;
23
- };
24
- //#endregion
25
- export type { Vital, VitalName, VitalRating, VitalsSnapshot };
1
+ import { a as VitalsSnapshot, i as VitalRating, n as Vital, r as VitalName, t as vitals } from "../index-ReFbhQ9p.js";
2
+ export { type Vital, type VitalName, type VitalRating, type VitalsSnapshot, vitals };
@@ -1,8 +1,9 @@
1
1
  import { i as definePlugin } from "../plugins-DVy_vaYr.js";
2
- import { i as useVitals, n as formatVital, r as startVitals, t as VitalsPanel } from "../vitals-panel-Dvc5dnR-.js";
3
- import { useEffect } from "react";
2
+ import { i as useVitals, n as formatVital, r as startVitals } from "../store-CQqIIKTc.js";
3
+ import { lazy, useEffect } from "react";
4
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
5
  //#region src/plugins/vitals/index.tsx
6
+ const VitalsPanel = lazy(() => import("../vitals-panel-BCmMUntW.js"));
6
7
  function VitalsPill() {
7
8
  useEffect(() => {
8
9
  startVitals();
@@ -1,11 +1,18 @@
1
- import { r as GrabPayload } from "./payload-CLKDVZWl.js";
1
+ import { r as GrabPayload } from "./payload-MUQ9ciER.js";
2
2
  import { ComponentType } from "react";
3
3
  //#region src/core/grabber/store.d.ts
4
+ /** An element a plugin asked the shell to outline, with the label shown beside it. */
5
+ interface HudHighlight {
6
+ element: Element;
7
+ label: string;
8
+ }
4
9
  interface HudGrabState {
5
10
  /** The picker is active: the next click on the page completes the grab. */
6
11
  grabbing: boolean;
7
12
  /** The last completed grab, until a plugin clears it. */
8
13
  payload: GrabPayload | null;
14
+ /** The element the grabber overlay currently outlines on a plugin's behalf. */
15
+ highlight: HudHighlight | null;
9
16
  }
10
17
  /** Grab mode for one HUD, shared by the shell and every plugin's `ctx.grab`. */
11
18
  interface HudGrab {
@@ -13,6 +20,18 @@ interface HudGrab {
13
20
  cancel: () => void;
14
21
  /** Forgets the last payload, e.g. once it has been dispatched. */
15
22
  clear: () => void;
23
+ /**
24
+ * Merges `patch` into the last payload (no-op without one). For plugins that
25
+ * enrich a grab after the fact, such as `capture` attaching a screenshot;
26
+ * compare `grabbedAt` first so a late result never lands on a newer grab.
27
+ */
28
+ amend: (patch: Partial<GrabPayload>) => void;
29
+ /**
30
+ * Outlines `element` with the grabber overlay and scrolls it into view, until
31
+ * `clearHighlight`, Escape, a click on the page or the next grab.
32
+ */
33
+ highlight: (element: Element, label?: string) => void;
34
+ clearHighlight: () => void;
16
35
  getState: () => HudGrabState;
17
36
  subscribe: (listener: () => void) => () => void;
18
37
  }
@@ -82,10 +101,21 @@ interface HudPlugin {
82
101
  title?: string;
83
102
  /** Without it the plugin is dropped, client and server side. */
84
103
  capability?: HudCapability;
85
- /** Floating panel content, opened from the plugin's pill item. */
104
+ /**
105
+ * Floating panel content, opened from the plugin's pill item. Make it a
106
+ * dynamic import, `lazy(() => import("./panel"))`, so its code loads on
107
+ * first open and stays out of the eager HUD bundle; the shell renders the
108
+ * loading state and contains a panel that fails.
109
+ */
86
110
  panel?: ComponentType<HudPluginProps>;
87
111
  /** Live content inside the plugin's pill item. Keep it inline and non-interactive. */
88
112
  pill?: ComponentType<HudPluginProps>;
113
+ /**
114
+ * When the pill runs out of room, items with a higher priority stay visible
115
+ * longest; the rest move into the pill menu. Above 0 the item also survives
116
+ * compact mode. Default 0.
117
+ */
118
+ pillPriority?: number;
89
119
  commands?: readonly HudCommand[];
90
120
  /** Called when a grab (⌘⇧G or the pill's crosshair) completes. */
91
121
  onGrab?: (payload: GrabPayload, ctx: HudPluginContext) => void;
@@ -111,4 +141,4 @@ declare class HudApiError extends Error {
111
141
  constructor(status: number, body: unknown, url: string);
112
142
  }
113
143
  //#endregion
114
- export { HudHttpMethod as a, HudPluginProps as c, HudRoutes as d, PinEdge as f, useGrab as g, HudGrabState as h, HudCommand as i, HudRouteContext as l, HudGrab as m, HudApiError as n, HudPlugin as o, definePlugin as p, HudCapability as r, HudPluginContext as s, HudAccessControl as t, HudRouteHandler as u };
144
+ export { useGrab as _, HudHttpMethod as a, HudPluginProps as c, HudRoutes as d, PinEdge as f, HudHighlight as g, HudGrabState as h, HudCommand as i, HudRouteContext as l, HudGrab as m, HudApiError as n, HudPlugin as o, definePlugin as p, HudCapability as r, HudPluginContext as s, HudAccessControl as t, HudRouteHandler as u };
@@ -0,0 +1,89 @@
1
+ import { n as HudApiError } from "./plugins-DVy_vaYr.js";
2
+ import { useCallback, useSyncExternalStore } from "react";
3
+ //#region src/plugins/ops/poll.ts
4
+ /** Entries per plugin context, so the pill and the panel share one poller per path. */
5
+ const entries = /* @__PURE__ */ new WeakMap();
6
+ function entryFor(ctx, path) {
7
+ let byPath = entries.get(ctx);
8
+ if (!byPath) {
9
+ byPath = /* @__PURE__ */ new Map();
10
+ entries.set(ctx, byPath);
11
+ }
12
+ let entry = byPath.get(path);
13
+ if (!entry) {
14
+ entry = {
15
+ state: { loading: true },
16
+ listeners: /* @__PURE__ */ new Set(),
17
+ inflight: false
18
+ };
19
+ byPath.set(path, entry);
20
+ }
21
+ return entry;
22
+ }
23
+ /** A readable message for a failed poll; 502 bodies carry the provider's own. */
24
+ function describeError(error) {
25
+ if (error instanceof HudApiError) {
26
+ if (error.status === 404) return "route not mounted: add ops() to createHudHandler";
27
+ const body = error.body;
28
+ if (typeof body?.error === "string") return body.error;
29
+ return `HTTP ${error.status}`;
30
+ }
31
+ return error instanceof Error ? error.message : "request failed";
32
+ }
33
+ function set(entry, state) {
34
+ entry.state = state;
35
+ for (const listener of entry.listeners) listener();
36
+ }
37
+ async function tick(ctx, path, entry, force = false) {
38
+ if (entry.inflight || !force && typeof document !== "undefined" && document.hidden) return;
39
+ entry.inflight = true;
40
+ try {
41
+ set(entry, {
42
+ data: await ctx.api(path),
43
+ loading: false
44
+ });
45
+ } catch (error) {
46
+ set(entry, {
47
+ ...entry.state,
48
+ error: describeError(error),
49
+ loading: false
50
+ });
51
+ } finally {
52
+ entry.inflight = false;
53
+ }
54
+ }
55
+ /**
56
+ * Polls one of the plugin's routes while anything renders it. Pauses while
57
+ * the tab is hidden; subscribers of the same path share one request.
58
+ */
59
+ function usePoll(ctx, path, intervalMs) {
60
+ const entry = entryFor(ctx, path);
61
+ const subscribe = useCallback((listener) => {
62
+ entry.listeners.add(listener);
63
+ if (entry.listeners.size === 1) {
64
+ tick(ctx, path, entry);
65
+ entry.timer = setInterval(() => void tick(ctx, path, entry), intervalMs);
66
+ }
67
+ return () => {
68
+ entry.listeners.delete(listener);
69
+ if (entry.listeners.size === 0) clearInterval(entry.timer);
70
+ };
71
+ }, [
72
+ ctx,
73
+ path,
74
+ entry,
75
+ intervalMs
76
+ ]);
77
+ const state = useSyncExternalStore(subscribe, () => entry.state, () => entry.state);
78
+ const refresh = useCallback(() => void tick(ctx, path, entry, true), [
79
+ ctx,
80
+ path,
81
+ entry
82
+ ]);
83
+ return {
84
+ ...state,
85
+ refresh
86
+ };
87
+ }
88
+ //#endregion
89
+ export { usePoll as t };