@hansenexus/hud 0.7.0 → 0.9.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 (77) hide show
  1. package/README.md +153 -14
  2. package/dist/{access-Bc709qpl.d.ts → access-CwPCPsv0.d.ts} +1 -1
  3. package/dist/auto/runtime.d.ts +9 -9
  4. package/dist/auto.d.ts +2 -2
  5. package/dist/auto.js +1 -1
  6. package/dist/cli.js +34 -1
  7. package/dist/{define-hud-DTv3njuU.d.ts → define-hud-B0aFXrcK.d.ts} +1 -1
  8. package/dist/{design-BXG1a4we.js → design-BIXY1-Ex.js} +26 -8
  9. package/dist/{force-state-panel-mu-txJnA.js → force-state-panel-D5oDydLs.js} +1 -1
  10. package/dist/{handler-DMzSTqyG.d.ts → handler-BmFhaA2D.d.ts} +1 -1
  11. package/dist/{index-C3wzZS3o.d.ts → index-5B7foZut.d.ts} +2 -2
  12. package/dist/{index-D-hI-DRJ.d.ts → index-B2KCKkN0.d.ts} +1 -1
  13. package/dist/index-B7qaEUgh.d.ts +44 -0
  14. package/dist/{index-CQXiuMZQ.d.ts → index-BGFyuJyN.d.ts} +1 -1
  15. package/dist/{index-Caohnz3B.d.ts → index-BeqWehuh.d.ts} +38 -10
  16. package/dist/{index-BJJoAXJ2.d.ts → index-BqKysxTq.d.ts} +1 -1
  17. package/dist/{index-DLCSLWW4.d.ts → index-D97Fnoie.d.ts} +2 -2
  18. package/dist/{index-BR5OB7DO.d.ts → index-DS0yT0c-.d.ts} +1 -1
  19. package/dist/{index-BNoPbSYD.d.ts → index-DvlCkGB1.d.ts} +1 -1
  20. package/dist/index.d.ts +3 -3
  21. package/dist/index.js +49 -196
  22. package/dist/lanes-panel-Disg54DY.js +395 -0
  23. package/dist/navigation-CX6AXm7H.js +176 -0
  24. package/dist/next/config.cjs +2 -0
  25. package/dist/next/config.d.cts +1 -0
  26. package/dist/next/config.d.ts +1 -0
  27. package/dist/next/config.js +2 -0
  28. package/dist/next.d.ts +4 -1
  29. package/dist/next.js +12 -1
  30. package/dist/obstacles-CCmRFTcZ.js +176 -0
  31. package/dist/plugins/a11y.d.ts +1 -1
  32. package/dist/plugins/access/server.d.ts +3 -3
  33. package/dist/plugins/access.d.ts +2 -2
  34. package/dist/plugins/agent/server.js +1 -1
  35. package/dist/plugins/agent.d.ts +2 -2
  36. package/dist/plugins/capture.d.ts +2 -2
  37. package/dist/plugins/data/server.d.ts +1 -1
  38. package/dist/plugins/data/server.js +1 -1
  39. package/dist/plugins/data.d.ts +1 -1
  40. package/dist/plugins/design/server.d.ts +55 -15
  41. package/dist/plugins/design/server.js +187 -122
  42. package/dist/plugins/design.d.ts +3 -3
  43. package/dist/plugins/design.js +1 -1
  44. package/dist/plugins/inspect.d.ts +1 -1
  45. package/dist/plugins/lanes/server.d.ts +165 -0
  46. package/dist/plugins/lanes/server.js +845 -0
  47. package/dist/plugins/lanes.d.ts +22 -0
  48. package/dist/plugins/lanes.js +30 -0
  49. package/dist/plugins/observe.d.ts +1 -1
  50. package/dist/plugins/ops/server.d.ts +1 -1
  51. package/dist/plugins/ops.d.ts +1 -1
  52. package/dist/plugins/routes/server.d.ts +1 -1
  53. package/dist/plugins/routes.d.ts +3 -3
  54. package/dist/plugins/routes.js +381 -52
  55. package/dist/plugins/seo.d.ts +1 -1
  56. package/dist/plugins/vitals.d.ts +1 -1
  57. package/dist/{plugins-BZT-1LBe.d.ts → plugins-pL2CoWzI.d.ts} +7 -0
  58. package/dist/same-origin-BHuZO1_H.js +36 -0
  59. package/dist/server.d.ts +2 -2
  60. package/dist/store.d.ts +1 -1
  61. package/dist/store.js +1 -1
  62. package/dist/types-BkrkOP3h.js +6 -0
  63. package/dist/types-Dazn3aWZ.d.ts +86 -0
  64. package/dist/{meta-C_G7MB5w.d.ts → types-Dc6JWZR7.d.ts} +6 -6
  65. package/dist/variant-bar-BzZ0ln-C.js +768 -0
  66. package/dist/variant-picks-Byc0hC8a.js +144 -0
  67. package/dist/variants-export-vEtZ-OGC.js +75 -0
  68. package/dist/{variants-panel-B6zWcknV.js → variants-panel-D23v5KIp.js} +71 -54
  69. package/dist/variants-types-BOsZ5fDz.js +65 -0
  70. package/dist/variants-types-VkW7vFZF.d.ts +139 -0
  71. package/dist/variants.d.ts +1 -1
  72. package/dist/variants.js +1 -1
  73. package/dist/vite.d.ts +2 -2
  74. package/package.json +2 -2
  75. package/dist/index-B1vHAY9p.d.ts +0 -20
  76. package/dist/same-origin-BGet22CC.js +0 -21
  77. package/dist/variants-types-CcRf119M.d.ts +0 -63
@@ -0,0 +1,395 @@
1
+ import { n as HudApiError } from "./plugins-CcW_K7c2.js";
2
+ import { useCallback, useEffect, useState } from "react";
3
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ //#region src/plugins/lanes/styles.ts
5
+ /** The Lanes panel's styles, rendered in a `<style>` inside the HUD's shadow root. */
6
+ const LANES_CSS = `
7
+ .lanes { display: grid; gap: 12px; }
8
+ .lanes-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
9
+ .lanes-grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
10
+ .lanes-muted { color: var(--hud-fg-muted); }
11
+ .lanes-mono { font-family: var(--hud-mono); font-size: 11px; }
12
+ .lanes h3 { margin: 0; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--hud-fg-muted); }
13
+ .hud .lanes-btn {
14
+ padding: 4px 10px;
15
+ min-height: 28px;
16
+ border: 1px solid var(--hud-border);
17
+ border-radius: 6px;
18
+ background: var(--hud-bg-subtle);
19
+ text-decoration: none;
20
+ color: inherit;
21
+ display: inline-flex;
22
+ align-items: center;
23
+ gap: 4px;
24
+ }
25
+ .hud .lanes-btn[data-primary] { background: var(--hud-accent); color: var(--hud-accent-fg); border-color: transparent; }
26
+ .hud .lanes-btn:disabled { opacity: 0.5; cursor: not-allowed; }
27
+ .lanes-here {
28
+ display: grid;
29
+ gap: 8px;
30
+ padding: 8px;
31
+ border: 1px solid var(--hud-border);
32
+ border-radius: 8px;
33
+ background: var(--hud-bg-subtle);
34
+ }
35
+ .lanes textarea {
36
+ font: inherit;
37
+ color: inherit;
38
+ background: var(--hud-bg);
39
+ border: 1px solid var(--hud-border);
40
+ border-radius: 6px;
41
+ padding: 6px 8px;
42
+ min-height: 64px;
43
+ resize: vertical;
44
+ }
45
+ .lanes-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
46
+ .lanes-item {
47
+ display: grid;
48
+ gap: 4px;
49
+ padding: 6px 8px;
50
+ border: 1px solid var(--hud-border);
51
+ border-radius: 6px;
52
+ }
53
+ .lanes-item[data-current] { border-color: var(--hud-accent); }
54
+ .lanes-badge {
55
+ flex: none;
56
+ padding: 0 6px;
57
+ border-radius: 999px;
58
+ border: 1px solid currentColor;
59
+ font-size: 10px;
60
+ line-height: 16px;
61
+ color: var(--hud-fg-muted);
62
+ }
63
+ .lanes-badge[data-state="working"] { color: var(--hud-good); }
64
+ .lanes-badge[data-state="waiting-human"], .lanes-badge[data-state="blocked"] { color: var(--hud-warn); }
65
+ .lanes-result { display: grid; gap: 2px; margin: 0; }
66
+ .lanes-result[data-ok="false"] { color: var(--hud-poor); }
67
+ .lanes-result a { color: inherit; }
68
+ `;
69
+ //#endregion
70
+ //#region src/plugins/lanes/lanes-panel.tsx
71
+ /** How long Start keeps refreshing while the new server comes up. */
72
+ const START_WATCH_MS = 9e4;
73
+ function errorText(error) {
74
+ if (error instanceof HudApiError) {
75
+ const body = error.body;
76
+ return typeof body?.error === "string" ? body.error : `HTTP ${error.status}`;
77
+ }
78
+ return error instanceof Error ? error.message : String(error);
79
+ }
80
+ /** A preview link on the box's tailnet name; without one, on the host this page came from. */
81
+ function previewUrl(server, host, page = location) {
82
+ if (host) return server.url;
83
+ return `${page.protocol}//${page.hostname}:${server.port}/`;
84
+ }
85
+ function viewport() {
86
+ return {
87
+ width: Math.round(window.innerWidth),
88
+ height: Math.round(window.innerHeight)
89
+ };
90
+ }
91
+ function Result({ result }) {
92
+ if (!result.ok) {
93
+ const notes = "notes" in result ? result.notes : [];
94
+ return /* @__PURE__ */ jsxs("div", {
95
+ className: "lanes-result",
96
+ "data-ok": "false",
97
+ role: "status",
98
+ children: [/* @__PURE__ */ jsxs("span", { children: ["Failed: ", result.error] }), notes.map((n) => /* @__PURE__ */ jsx("span", {
99
+ className: "lanes-muted",
100
+ children: n
101
+ }, n))]
102
+ });
103
+ }
104
+ return /* @__PURE__ */ jsxs("div", {
105
+ className: "lanes-result",
106
+ "data-ok": "true",
107
+ role: "status",
108
+ children: [
109
+ /* @__PURE__ */ jsxs("span", { children: [result.delivered ? "Typed into the worker's terminal" : "Recorded on the ledger for the worker", result.prComment && /* @__PURE__ */ jsxs(Fragment, { children: [" · ", /* @__PURE__ */ jsx("a", {
110
+ href: result.prComment,
111
+ target: "_blank",
112
+ rel: "noreferrer",
113
+ children: "PR comment"
114
+ })] })] }),
115
+ result.ref && /* @__PURE__ */ jsx("span", {
116
+ className: "lanes-muted lanes-mono",
117
+ children: result.ref
118
+ }),
119
+ result.notes.map((n) => /* @__PURE__ */ jsx("span", {
120
+ className: "lanes-muted",
121
+ children: n
122
+ }, n))
123
+ ]
124
+ });
125
+ }
126
+ /** The comment box and Screenshot button for the lane this page is served from. */
127
+ function ThisLane({ lane, ctx }) {
128
+ const [text, setText] = useState("");
129
+ const [busy, setBusy] = useState(null);
130
+ const [result, setResult] = useState(null);
131
+ const [width, setWidth] = useState(() => viewport().width);
132
+ useEffect(() => {
133
+ const onResize = () => setWidth(viewport().width);
134
+ window.addEventListener("resize", onResize);
135
+ return () => window.removeEventListener("resize", onResize);
136
+ }, []);
137
+ async function send(kind) {
138
+ setBusy(kind);
139
+ setResult(null);
140
+ try {
141
+ const body = kind === "comment" ? {
142
+ lane: lane.lane,
143
+ text,
144
+ url: location.href,
145
+ viewport: viewport()
146
+ } : {
147
+ lane: lane.lane,
148
+ url: location.href,
149
+ viewport: viewport(),
150
+ text
151
+ };
152
+ const res = await ctx.api(kind === "comment" ? "/comment" : "/screenshot", {
153
+ method: "POST",
154
+ headers: { "content-type": "application/json" },
155
+ body: JSON.stringify(body)
156
+ });
157
+ setResult(res);
158
+ if (res.ok) setText("");
159
+ } catch (error) {
160
+ const body = error instanceof HudApiError ? error.body : void 0;
161
+ setResult(body && Array.isArray(body.notes) ? {
162
+ ok: false,
163
+ delivered: false,
164
+ notes: body.notes,
165
+ error: errorText(error)
166
+ } : {
167
+ ok: false,
168
+ error: errorText(error)
169
+ });
170
+ } finally {
171
+ setBusy(null);
172
+ }
173
+ }
174
+ const worker = lane.worker;
175
+ return /* @__PURE__ */ jsxs("section", {
176
+ className: "lanes-here",
177
+ "aria-label": "This lane",
178
+ children: [
179
+ /* @__PURE__ */ jsxs("div", {
180
+ className: "lanes-row",
181
+ children: [/* @__PURE__ */ jsxs("h3", {
182
+ className: "lanes-grow",
183
+ children: [
184
+ "This lane · ",
185
+ lane.repo,
186
+ lane.issue ? `#${lane.issue}` : ""
187
+ ]
188
+ }), worker ? /* @__PURE__ */ jsxs("span", {
189
+ className: "lanes-badge",
190
+ "data-state": worker.state,
191
+ title: worker.sid,
192
+ children: ["worker ", worker.state]
193
+ }) : /* @__PURE__ */ jsx("span", {
194
+ className: "lanes-badge",
195
+ children: "no worker"
196
+ })]
197
+ }),
198
+ /* @__PURE__ */ jsx("textarea", {
199
+ "aria-label": "Comment for the worker",
200
+ placeholder: "What should change on this page?",
201
+ value: text,
202
+ onChange: (e) => setText(e.target.value)
203
+ }),
204
+ /* @__PURE__ */ jsxs("div", {
205
+ className: "lanes-row",
206
+ children: [/* @__PURE__ */ jsx("button", {
207
+ type: "button",
208
+ className: "lanes-btn",
209
+ "data-primary": "",
210
+ disabled: busy !== null || !text.trim(),
211
+ onClick: () => void send("comment"),
212
+ children: busy === "comment" ? "Sending…" : "Send to worker"
213
+ }), /* @__PURE__ */ jsx("button", {
214
+ type: "button",
215
+ className: "lanes-btn",
216
+ disabled: busy !== null,
217
+ onClick: () => void send("screenshot"),
218
+ title: "Renders this page at your current width, posts it to the PR and hands it to the worker",
219
+ children: busy === "screenshot" ? "Capturing…" : `Screenshot · ${width}px`
220
+ })]
221
+ }),
222
+ result && /* @__PURE__ */ jsx(Result, { result })
223
+ ]
224
+ });
225
+ }
226
+ function LaneRow({ lane, host, starting, onStart }) {
227
+ return /* @__PURE__ */ jsxs("li", {
228
+ className: "lanes-item",
229
+ "data-current": lane.current ? "" : void 0,
230
+ "data-lane": lane.lane,
231
+ children: [
232
+ /* @__PURE__ */ jsxs("div", {
233
+ className: "lanes-row",
234
+ children: [/* @__PURE__ */ jsxs("span", {
235
+ className: "lanes-grow",
236
+ title: lane.lane,
237
+ children: [
238
+ /* @__PURE__ */ jsxs("strong", { children: [lane.repo, lane.issue ? `#${lane.issue}` : ""] }),
239
+ " ",
240
+ /* @__PURE__ */ jsx("span", {
241
+ className: "lanes-muted lanes-mono",
242
+ children: lane.lane
243
+ })
244
+ ]
245
+ }), lane.worker && /* @__PURE__ */ jsx("span", {
246
+ className: "lanes-badge",
247
+ "data-state": lane.worker.state,
248
+ children: lane.worker.state
249
+ })]
250
+ }),
251
+ lane.branch && /* @__PURE__ */ jsx("span", {
252
+ className: "lanes-muted lanes-mono lanes-grow",
253
+ children: lane.branch
254
+ }),
255
+ /* @__PURE__ */ jsxs("div", {
256
+ className: "lanes-row",
257
+ children: [lane.servers.map((server) => server.loopback ? /* @__PURE__ */ jsxs("span", {
258
+ className: "lanes-muted lanes-mono",
259
+ title: "bound to localhost only",
260
+ children: [
261
+ ":",
262
+ server.port,
263
+ " localhost only"
264
+ ]
265
+ }, server.port) : /* @__PURE__ */ jsxs("a", {
266
+ className: "lanes-btn lanes-mono",
267
+ href: previewUrl(server, host),
268
+ target: "_blank",
269
+ rel: "noreferrer",
270
+ children: [
271
+ ":",
272
+ server.port,
273
+ " Open ↗"
274
+ ]
275
+ }, server.port)), lane.servers.length === 0 && (lane.startable ? /* @__PURE__ */ jsx("button", {
276
+ type: "button",
277
+ className: "lanes-btn",
278
+ disabled: starting !== void 0,
279
+ onClick: onStart,
280
+ children: starting ?? "Start"
281
+ }) : /* @__PURE__ */ jsx("span", {
282
+ className: "lanes-muted",
283
+ children: "no dev script"
284
+ }))]
285
+ })
286
+ ]
287
+ });
288
+ }
289
+ function LanesPanel({ ctx, intervalMs }) {
290
+ const [data, setData] = useState(null);
291
+ const [error, setError] = useState(null);
292
+ const [starting, setStarting] = useState({});
293
+ const [startError, setStartError] = useState(null);
294
+ const load = useCallback(async () => {
295
+ try {
296
+ setData(await ctx.api("/lanes"));
297
+ setError(null);
298
+ } catch (e) {
299
+ setError(errorText(e));
300
+ }
301
+ }, [ctx]);
302
+ useEffect(() => {
303
+ load();
304
+ const timer = setInterval(() => {
305
+ if (!document.hidden) load();
306
+ }, intervalMs);
307
+ return () => clearInterval(timer);
308
+ }, [load, intervalMs]);
309
+ const pending = Object.keys(starting).length > 0;
310
+ useEffect(() => {
311
+ if (!pending) return;
312
+ const timer = setInterval(() => void load(), 3e3);
313
+ return () => clearInterval(timer);
314
+ }, [pending, load]);
315
+ useEffect(() => {
316
+ if (!data) return;
317
+ setStarting((s) => {
318
+ const left = Object.fromEntries(Object.entries(s).filter(([lane]) => !data.lanes.find((l) => l.lane === lane)?.servers.length));
319
+ return Object.keys(left).length === Object.keys(s).length ? s : left;
320
+ });
321
+ }, [data]);
322
+ async function start(lane) {
323
+ setStartError(null);
324
+ setStarting((s) => ({
325
+ ...s,
326
+ [lane]: "Starting…"
327
+ }));
328
+ try {
329
+ const res = await ctx.api("/start", {
330
+ method: "POST",
331
+ headers: { "content-type": "application/json" },
332
+ body: JSON.stringify({ lane })
333
+ });
334
+ if (res.ok) {
335
+ setStarting((s) => ({
336
+ ...s,
337
+ [lane]: `Starting on :${res.port}…`
338
+ }));
339
+ setTimeout(() => setStarting(({ [lane]: _gone, ...rest }) => rest), START_WATCH_MS);
340
+ }
341
+ } catch (e) {
342
+ setStartError(`${lane}: ${errorText(e)}`);
343
+ setStarting(({ [lane]: _gone, ...rest }) => rest);
344
+ }
345
+ }
346
+ const here = data?.lanes.find((l) => l.current);
347
+ return /* @__PURE__ */ jsxs("div", {
348
+ className: "lanes",
349
+ children: [
350
+ /* @__PURE__ */ jsx("style", { children: LANES_CSS }),
351
+ here && /* @__PURE__ */ jsx(ThisLane, {
352
+ lane: here,
353
+ ctx
354
+ }),
355
+ /* @__PURE__ */ jsxs("div", {
356
+ className: "lanes-row",
357
+ children: [/* @__PURE__ */ jsx("h3", {
358
+ className: "lanes-grow",
359
+ children: data ? `${data.lanes.length} lanes on ${data.host ?? "this box"}` : "Loading…"
360
+ }), /* @__PURE__ */ jsx("button", {
361
+ type: "button",
362
+ className: "lanes-btn",
363
+ onClick: () => void load(),
364
+ children: "Refresh"
365
+ })]
366
+ }),
367
+ error && /* @__PURE__ */ jsxs("p", {
368
+ className: "empty",
369
+ children: ["Lanes unavailable: ", error]
370
+ }),
371
+ startError && /* @__PURE__ */ jsxs("p", {
372
+ className: "lanes-result",
373
+ "data-ok": "false",
374
+ role: "alert",
375
+ children: ["Start failed: ", startError]
376
+ }),
377
+ data && data.lanes.length === 0 && /* @__PURE__ */ jsx("p", {
378
+ className: "empty",
379
+ children: "No lanes on this box."
380
+ }),
381
+ data && data.lanes.length > 0 && /* @__PURE__ */ jsx("ul", {
382
+ className: "lanes-list",
383
+ "aria-label": "Lanes",
384
+ children: data.lanes.map((lane) => /* @__PURE__ */ jsx(LaneRow, {
385
+ lane,
386
+ host: data.host,
387
+ starting: starting[lane.lane],
388
+ onStart: () => void start(lane.lane)
389
+ }, lane.lane))
390
+ })
391
+ ]
392
+ });
393
+ }
394
+ //#endregion
395
+ export { LanesPanel, LanesPanel as default, previewUrl };
@@ -0,0 +1,176 @@
1
+ import { useSyncExternalStore } from "react";
2
+ const VERSION = 1;
3
+ const EMPTY_PREFS = {
4
+ pins: [],
5
+ recent: []
6
+ };
7
+ function prefsKey(app) {
8
+ return `hansenexus-hud:routes:${app}`;
9
+ }
10
+ const prefs = /* @__PURE__ */ new Map();
11
+ const prefsListeners = /* @__PURE__ */ new Set();
12
+ function strings(value) {
13
+ return Array.isArray(value) ? [...new Set(value.filter((item) => typeof item === "string"))] : [];
14
+ }
15
+ /** Storage can be missing, blocked or hold someone else's JSON; every failure reads as empty. */
16
+ function loadPrefs(app) {
17
+ try {
18
+ const raw = window.localStorage.getItem(prefsKey(app));
19
+ const value = raw ? JSON.parse(raw) : null;
20
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return EMPTY_PREFS;
21
+ const record = value;
22
+ if (record.v !== VERSION) return EMPTY_PREFS;
23
+ return {
24
+ pins: strings(record.pins),
25
+ recent: strings(record.recent).slice(0, 8)
26
+ };
27
+ } catch {
28
+ return EMPTY_PREFS;
29
+ }
30
+ }
31
+ function savePrefs(app, value) {
32
+ prefs.set(app, value);
33
+ try {
34
+ window.localStorage.setItem(prefsKey(app), JSON.stringify({
35
+ v: VERSION,
36
+ ...value
37
+ }));
38
+ } catch {}
39
+ for (const listener of prefsListeners) listener();
40
+ }
41
+ function getPrefs(app) {
42
+ let value = prefs.get(app);
43
+ if (!value) {
44
+ value = typeof window === "undefined" ? EMPTY_PREFS : loadPrefs(app);
45
+ prefs.set(app, value);
46
+ }
47
+ return value;
48
+ }
49
+ function subscribePrefs(listener) {
50
+ prefsListeners.add(listener);
51
+ return () => prefsListeners.delete(listener);
52
+ }
53
+ /** The app's pins and recent routes; re-renders on every change. */
54
+ function usePrefs(app) {
55
+ return useSyncExternalStore(subscribePrefs, () => getPrefs(app), () => EMPTY_PREFS);
56
+ }
57
+ function togglePin(app, pathname) {
58
+ const current = getPrefs(app);
59
+ const pins = current.pins.includes(pathname) ? current.pins.filter((pin) => pin !== pathname) : [...current.pins, pathname];
60
+ savePrefs(app, {
61
+ ...current,
62
+ pins
63
+ });
64
+ }
65
+ /** Puts `pathname` at the head of the app's recent list. */
66
+ function recordVisit(app, pathname) {
67
+ const current = getPrefs(app);
68
+ const recent = [pathname, ...current.recent.filter((p) => p !== pathname)].slice(0, 8);
69
+ if (recent.length === current.recent.length && recent.every((p, i) => p === current.recent[i])) return;
70
+ savePrefs(app, {
71
+ ...current,
72
+ recent
73
+ });
74
+ }
75
+ let observedApp = null;
76
+ let pathname = "";
77
+ let restore = null;
78
+ const pathListeners = /* @__PURE__ */ new Set();
79
+ function readPathname() {
80
+ return typeof location === "undefined" ? "" : location.pathname;
81
+ }
82
+ function onNavigate() {
83
+ const next = readPathname();
84
+ if (next === pathname) return;
85
+ pathname = next;
86
+ if (observedApp !== null) recordVisit(observedApp, next);
87
+ for (const listener of pathListeners) listener();
88
+ }
89
+ function patch(method) {
90
+ const original = history[method];
91
+ const patched = function(...args) {
92
+ original.apply(this, args);
93
+ queueMicrotask(onNavigate);
94
+ };
95
+ history[method] = patched;
96
+ return () => {
97
+ if (history[method] === patched) history[method] = original;
98
+ };
99
+ }
100
+ /**
101
+ * Starts recording visits for `app`: the current pathname now, then every
102
+ * `pushState`, `replaceState` and `popstate`. Idempotent; the plugin calls it
103
+ * from its rail badge (HUD mount) and from the panel.
104
+ */
105
+ function startNavigationObserver(app) {
106
+ if (typeof window === "undefined") return;
107
+ if (restore) {
108
+ if (observedApp !== app) {
109
+ observedApp = app;
110
+ recordVisit(app, pathname);
111
+ }
112
+ return;
113
+ }
114
+ observedApp = app;
115
+ pathname = readPathname();
116
+ recordVisit(app, pathname);
117
+ const unpatch = [patch("pushState"), patch("replaceState")];
118
+ window.addEventListener("popstate", onNavigate);
119
+ restore = () => {
120
+ for (const undo of unpatch) undo();
121
+ window.removeEventListener("popstate", onNavigate);
122
+ };
123
+ }
124
+ function getPathname() {
125
+ return restore ? pathname : readPathname();
126
+ }
127
+ function subscribePathname(listener) {
128
+ pathListeners.add(listener);
129
+ return () => pathListeners.delete(listener);
130
+ }
131
+ /** The page's pathname, live across client-side navigation. */
132
+ function usePathname() {
133
+ return useSyncExternalStore(subscribePathname, getPathname, () => "");
134
+ }
135
+ /** Next's app or pages router, which dev builds expose as `window.next.router`. */
136
+ function clientRouter() {
137
+ if (typeof window === "undefined") return void 0;
138
+ const router = window.next?.router;
139
+ if (typeof router === "object" && router !== null && "push" in router) {
140
+ if (typeof router.push === "function") return router;
141
+ }
142
+ }
143
+ /** Client-side through the app's router when there is one, else a full load. */
144
+ function navigateTo(url) {
145
+ const router = clientRouter();
146
+ if (router) {
147
+ router.push(url);
148
+ return;
149
+ }
150
+ location.assign(url);
151
+ }
152
+ let focusPending = false;
153
+ let focusTick = 0;
154
+ const focusListeners = /* @__PURE__ */ new Set();
155
+ /** The command asks the panel to focus its filter; the panel takes the request once mounted. */
156
+ function requestFilterFocus() {
157
+ focusPending = true;
158
+ focusTick += 1;
159
+ for (const listener of focusListeners) listener();
160
+ }
161
+ /** Consumes the pending request; true once per `requestFilterFocus`. */
162
+ function takeFilterFocus() {
163
+ const pending = focusPending;
164
+ focusPending = false;
165
+ return pending;
166
+ }
167
+ function subscribeFocus(listener) {
168
+ focusListeners.add(listener);
169
+ return () => focusListeners.delete(listener);
170
+ }
171
+ /** Changes whenever the command runs, so the panel's focus effect re-runs. */
172
+ function useFilterFocusTick() {
173
+ return useSyncExternalStore(subscribeFocus, () => focusTick, () => 0);
174
+ }
175
+ //#endregion
176
+ export { togglePin as a, usePrefs as c, takeFilterFocus as i, requestFilterFocus as n, useFilterFocusTick as o, startNavigationObserver as r, usePathname as s, navigateTo as t };
@@ -164,12 +164,14 @@ function withHud(config, options = {}) {
164
164
  const webpack = base.webpack;
165
165
  const pinned = {};
166
166
  for (const key of HUD_PUBLIC_ENV) pinned[key] = process.env[key] ?? "";
167
+ const preview = process.env.HUD_PREVIEW_HOST;
167
168
  return {
168
169
  ...base,
169
170
  env: {
170
171
  ...pinned,
171
172
  ...base.env
172
173
  },
174
+ ...preview ? { allowedDevOrigins: [.../* @__PURE__ */ new Set([...base.allowedDevOrigins ?? [], preview])] } : {},
173
175
  turbopack: {
174
176
  ...base.turbopack,
175
177
  resolveAlias: {
@@ -51,6 +51,7 @@ export interface NextConfigLike {
51
51
  turbopack?: {
52
52
  resolveAlias?: Record<string, unknown> | undefined;
53
53
  } | undefined;
54
+ allowedDevOrigins?: string[] | undefined;
54
55
  webpack?(config: WebpackConfigLike, context: unknown): WebpackConfigLike;
55
56
  }
56
57
  /**
@@ -28,6 +28,7 @@ export interface NextConfigLike {
28
28
  turbopack?: {
29
29
  resolveAlias?: Record<string, unknown> | undefined;
30
30
  } | undefined;
31
+ allowedDevOrigins?: string[] | undefined;
31
32
  webpack?(config: WebpackConfigLike, context: unknown): WebpackConfigLike;
32
33
  }
33
34
  /**
@@ -51,12 +51,14 @@ function withHud(config, options = {}) {
51
51
  const webpack = base.webpack;
52
52
  const pinned = {};
53
53
  for (const key of HUD_PUBLIC_ENV) pinned[key] = process.env[key] ?? "";
54
+ const preview = process.env.HUD_PREVIEW_HOST;
54
55
  return {
55
56
  ...base,
56
57
  env: {
57
58
  ...pinned,
58
59
  ...base.env
59
60
  },
61
+ ...preview ? { allowedDevOrigins: [.../* @__PURE__ */ new Set([...base.allowedDevOrigins ?? [], preview])] } : {},
60
62
  turbopack: {
61
63
  ...base.turbopack,
62
64
  resolveAlias: {
package/dist/next.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { r as HudMountProps } from "./define-hud-DTv3njuU.js";
1
+ import { r as HudMountProps } from "./define-hud-B0aFXrcK.js";
2
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
@@ -36,6 +36,9 @@ interface HudLoaderOptions {
36
36
  * chunk would ship unreachable but readable (hn-monorepo#1283). Pass `null`
37
37
  * and the loader renders nothing.
38
38
  *
39
+ * A HUD chunk that fails to load renders nothing: a dev tool must not take
40
+ * the page down with it. The reason goes to the console.
41
+ *
39
42
  * Outside Next (Vite), gate on `import.meta.env.DEV` and pass `{ env }`.
40
43
  */
41
44
  export declare function createHudLoader(load: HudModuleLoader | null, options?: HudLoaderOptions): ComponentType<HudMountProps>;
package/dist/next.js CHANGED
@@ -25,11 +25,14 @@ import { jsx } from "react/jsx-runtime";
25
25
  * chunk would ship unreachable but readable (hn-monorepo#1283). Pass `null`
26
26
  * and the loader renders nothing.
27
27
  *
28
+ * A HUD chunk that fails to load renders nothing: a dev tool must not take
29
+ * the page down with it. The reason goes to the console.
30
+ *
28
31
  * Outside Next (Vite), gate on `import.meta.env.DEV` and pass `{ env }`.
29
32
  */
30
33
  function createHudLoader(load, options = {}) {
31
34
  if (!load) return NoHud;
32
- const LazyHud = lazy(load);
35
+ const LazyHud = lazy(() => loadOrNothing(load));
33
36
  function HudLoader(props) {
34
37
  const [mounted, setMounted] = useState(false);
35
38
  useEffect(() => setMounted(true), []);
@@ -47,6 +50,14 @@ function createHudLoader(load, options = {}) {
47
50
  }
48
51
  return HudLoader;
49
52
  }
53
+ async function loadOrNothing(load) {
54
+ try {
55
+ return await load();
56
+ } catch (error) {
57
+ console.warn("hud: the HUD chunk failed to load, rendering nothing", error);
58
+ return { default: NoHud };
59
+ }
60
+ }
50
61
  function NoHud(_props) {
51
62
  return null;
52
63
  }