@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
package/dist/index.js CHANGED
@@ -1,7 +1,134 @@
1
- import { a as resolvePlugins, i as definePlugin, n as HudApiError, r as createPluginContext } from "./plugins-CzUiTn_r.js";
2
- import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
3
- import { jsx, jsxs } from "react/jsx-runtime";
4
- import { createPortal } from "react-dom";
1
+ import { n as useGrab, t as createGrabber } from "./store-Ync9eb1G.js";
2
+ import { n as HUD_HOST_TAG, t as HUD_DEV_MARKER } from "./marker-uZYPOJ4M.js";
3
+ import { a as resolvePlugins, i as definePlugin, n as HudApiError, r as createPluginContext } from "./plugins-DVy_vaYr.js";
4
+ import { a as buildGrabPayload, i as parseShortcut, n as isApplePlatform, o as describeElement, r as matchesShortcut, s as matchComponentHints, t as formatShortcut } from "./shortcut-s_mjGeU8.js";
5
+ import { i as PICKER_CSS, n as ShadowHost, r as ElementPicker, t as HUD_CSS } from "./styles-BA8ueHoV.js";
6
+ import { Component, Suspense, createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
7
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
+ //#region src/core/grabber/outline.tsx
9
+ function toBox(element) {
10
+ const r = element.getBoundingClientRect();
11
+ return {
12
+ left: r.left,
13
+ top: r.top,
14
+ width: r.width,
15
+ height: r.height
16
+ };
17
+ }
18
+ /**
19
+ * Outlines one element with the grabber's overlay without entering grab mode:
20
+ * findings in a panel point at the page this way. The box follows scrolling
21
+ * and resizes; the outline goes away on Escape, on a press on the page, or
22
+ * when the element is removed.
23
+ */
24
+ function ElementOutline({ element, label, onDismiss, reveal = true }) {
25
+ const layer = useRef(null);
26
+ const [box, setBox] = useState(null);
27
+ const dismiss = useRef(onDismiss);
28
+ dismiss.current = onDismiss;
29
+ useEffect(() => {
30
+ if (!element) {
31
+ setBox(null);
32
+ return;
33
+ }
34
+ const doc = element.ownerDocument;
35
+ const win = doc.defaultView ?? window;
36
+ const root = layer.current?.getRootNode();
37
+ const ownHost = root instanceof ShadowRoot ? root.host : null;
38
+ if (reveal && typeof element.scrollIntoView === "function") element.scrollIntoView({
39
+ block: "center",
40
+ inline: "nearest"
41
+ });
42
+ function measure() {
43
+ if (!element?.isConnected) {
44
+ dismiss.current();
45
+ return;
46
+ }
47
+ setBox(toBox(element));
48
+ }
49
+ function onKey(event) {
50
+ if (event.key === "Escape") dismiss.current();
51
+ }
52
+ function onPress(event) {
53
+ if (ownHost && event.composedPath().includes(ownHost)) return;
54
+ dismiss.current();
55
+ }
56
+ measure();
57
+ win.addEventListener("scroll", measure, true);
58
+ win.addEventListener("resize", measure);
59
+ win.addEventListener("keydown", onKey, true);
60
+ doc.addEventListener("pointerdown", onPress, true);
61
+ return () => {
62
+ win.removeEventListener("scroll", measure, true);
63
+ win.removeEventListener("resize", measure);
64
+ win.removeEventListener("keydown", onKey, true);
65
+ doc.removeEventListener("pointerdown", onPress, true);
66
+ setBox(null);
67
+ };
68
+ }, [element, reveal]);
69
+ return /* @__PURE__ */ jsx("div", {
70
+ ref: layer,
71
+ className: "grab-layer",
72
+ "data-outline": "",
73
+ hidden: !element || !box,
74
+ children: element && box && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
75
+ className: "grab-outline",
76
+ style: {
77
+ left: box.left - 2,
78
+ top: box.top - 2,
79
+ width: box.width + 4,
80
+ height: box.height + 4
81
+ }
82
+ }), /* @__PURE__ */ jsx("div", {
83
+ className: "grab-label",
84
+ style: {
85
+ left: Math.max(box.left - 2, 4),
86
+ top: box.top >= 22 ? box.top - 20 : box.top + box.height + 4
87
+ },
88
+ children: label
89
+ })] })
90
+ });
91
+ }
92
+ //#endregion
93
+ //#region src/shell/grabber.tsx
94
+ const GRAB_CSS = PICKER_CSS + `
95
+ .hud .grab-toggle { font-size: 14px; line-height: 1; padding: 2px 6px; }
96
+ .hud .grab-toggle[aria-pressed="true"] { color: var(--hud-accent); }
97
+ `;
98
+ /**
99
+ * Grab mode for the shell. It lives beside the panels, not inside one, so a
100
+ * grab never unmounts or closes a panel; the picker ignores clicks inside the
101
+ * HUD, so open panels stay usable while it is active. Outside a grab the same
102
+ * overlay outlines whatever a plugin pointed at with `ctx.grab.highlight`.
103
+ */
104
+ function Grabber({ app, store, slots }) {
105
+ const { grabbing, highlight } = useGrab(store);
106
+ const onPick = useCallback((element) => {
107
+ const payload = buildGrabPayload(element, { app });
108
+ store.complete(payload);
109
+ for (const { plugin, ctx } of slots) try {
110
+ plugin.onGrab?.(payload, ctx);
111
+ } catch (error) {
112
+ console.error(`hud: ${plugin.id} onGrab failed`, error);
113
+ }
114
+ }, [
115
+ app,
116
+ store,
117
+ slots
118
+ ]);
119
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(ElementPicker, {
120
+ active: grabbing,
121
+ onPick,
122
+ onCancel: store.cancel,
123
+ describe: describeElement,
124
+ hint: "Grab: click an element · Esc cancels"
125
+ }), !grabbing && /* @__PURE__ */ jsx(ElementOutline, {
126
+ element: highlight?.element ?? null,
127
+ label: highlight?.label ?? "",
128
+ onDismiss: store.clearHighlight
129
+ })] });
130
+ }
131
+ //#endregion
5
132
  //#region src/shell/commands/context.ts
6
133
  const RegistryContext = createContext(null);
7
134
  function useRegistry() {
@@ -24,46 +151,7 @@ function useRegisterCommands(commands) {
24
151
  }, [registry, commands]);
25
152
  }
26
153
  //#endregion
27
- //#region src/shell/commands/shortcut.ts
28
- function parseShortcut(spec) {
29
- const parts = spec.toLowerCase().split("+");
30
- return {
31
- key: parts.at(-1) ?? "",
32
- mod: parts.includes("mod"),
33
- shift: parts.includes("shift"),
34
- alt: parts.includes("alt")
35
- };
36
- }
37
- function isApplePlatform() {
38
- return typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.userAgent);
39
- }
40
- function matchesShortcut(event, shortcut, apple) {
41
- if ((apple ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey) !== shortcut.mod) return false;
42
- if (event.shiftKey !== shortcut.shift || event.altKey !== shortcut.alt) return false;
43
- if (event.key.toLowerCase() === shortcut.key) return true;
44
- if (/^[a-z]$/.test(shortcut.key)) return event.code === `Key${shortcut.key.toUpperCase()}`;
45
- if (/^\d$/.test(shortcut.key)) return event.code === `Digit${shortcut.key}`;
46
- return false;
47
- }
48
- function formatShortcut(shortcut, apple) {
49
- const key = shortcut.key.toUpperCase();
50
- if (apple) return `${shortcut.mod ? "⌘" : ""}${shortcut.alt ? "⌥" : ""}${shortcut.shift ? "⇧" : ""}${key}`;
51
- return [
52
- shortcut.mod && "Ctrl",
53
- shortcut.alt && "Alt",
54
- shortcut.shift && "Shift",
55
- key
56
- ].filter(Boolean).join("+");
57
- }
58
- //#endregion
59
154
  //#region src/shell/commands/registry.ts
60
- /** Element grab arrives with the grabber slice (hud#7); the shortcut is reserved now. */
61
- const GRAB_COMMAND = {
62
- id: "hud.grab",
63
- title: "Grab element",
64
- shortcut: "mod+shift+g",
65
- run: () => {}
66
- };
67
155
  /**
68
156
  * Commands the shell and plugins contribute. Registering an id again
69
157
  * replaces the earlier command; the first registered shortcut match wins.
@@ -106,12 +194,11 @@ var CommandRegistry = class {
106
194
  };
107
195
  //#endregion
108
196
  //#region src/shell/commands/command-provider.tsx
109
- const BUILTIN = [GRAB_COMMAND];
110
197
  /** Owns one HUD's command registry and binds its shortcuts on `window`. */
111
198
  function CommandProvider({ commands, children }) {
112
199
  const [registry] = useState(() => new CommandRegistry());
113
200
  useEffect(() => {
114
- const unregister = [...BUILTIN, ...commands].map((command) => registry.register(command));
201
+ const unregister = commands.map((command) => registry.register(command));
115
202
  return () => {
116
203
  for (const off of unregister) off();
117
204
  };
@@ -136,7 +223,8 @@ const EMPTY_LAYOUT = {
136
223
  open: [],
137
224
  floats: {},
138
225
  pins: {},
139
- hidden: false
226
+ hidden: false,
227
+ pill: null
140
228
  };
141
229
  /** A pinned edge never takes more than this share of the viewport. */
142
230
  const MAX_SHARE = .4;
@@ -428,6 +516,13 @@ const EDGES = [
428
516
  "right",
429
517
  "bottom"
430
518
  ];
519
+ /** Search order when the pill picks its own corner: the bottom first, top-right last (host CTAs). */
520
+ const CORNERS = [
521
+ "bottom-left",
522
+ "bottom-right",
523
+ "top-left",
524
+ "top-right"
525
+ ];
431
526
  //#endregion
432
527
  //#region src/shell/panels/reserve.ts
433
528
  const PADDING = {
@@ -499,6 +594,9 @@ function isRecord(value) {
499
594
  function isPosition(value) {
500
595
  return isRecord(value) && Number.isFinite(value.x) && Number.isFinite(value.y);
501
596
  }
597
+ function isCorner(value) {
598
+ return CORNERS.some((corner) => corner === value);
599
+ }
502
600
  function isEdge(value) {
503
601
  return EDGES.some((edge) => edge === value);
504
602
  }
@@ -520,14 +618,15 @@ function sanitizeLayout(value, known) {
520
618
  open,
521
619
  floats,
522
620
  pins,
523
- hidden: value.hidden === true
621
+ hidden: value.hidden === true,
622
+ pill: isCorner(value.pill) ? value.pill : null
524
623
  };
525
624
  }
526
625
  function subscribeResize(listener) {
527
626
  window.addEventListener("resize", listener);
528
627
  return () => window.removeEventListener("resize", listener);
529
628
  }
530
- let cached = {
629
+ let cached$1 = {
531
630
  w: 0,
532
631
  h: 0
533
632
  };
@@ -539,11 +638,11 @@ function readViewport() {
539
638
  const root = document.documentElement;
540
639
  const w = root.clientWidth || window.innerWidth;
541
640
  const h = root.clientHeight || window.innerHeight;
542
- if (w !== cached.w || h !== cached.h) cached = {
641
+ if (w !== cached$1.w || h !== cached$1.h) cached$1 = {
543
642
  w,
544
643
  h
545
644
  };
546
- return cached;
645
+ return cached$1;
547
646
  }
548
647
  function useViewport() {
549
648
  return useSyncExternalStore(subscribeResize, readViewport, readViewport);
@@ -602,8 +701,24 @@ function Workspace({ appSlug, panels, apiRef, children }) {
602
701
  open: (id) => setLayout((l) => openPanel(l, id, defaultPosition(l.open.length))),
603
702
  close: (id) => setLayout((l) => closePanel(l, id)),
604
703
  toggle: (id) => setLayout((l) => !l.hidden && l.open.includes(id) ? closePanel(l, id) : openPanel(l, id, defaultPosition(l.open.length))),
605
- pin: (id, edge) => setLayout((l) => pinPanel(l, id, edge))
606
- }), [panels, layout]);
704
+ pin: (id, edge) => setLayout((l) => pinPanel(l, id, edge)),
705
+ reserve: {
706
+ left,
707
+ right,
708
+ bottom
709
+ },
710
+ pillCorner: layout.pill,
711
+ setPillCorner: (pill) => setLayout((l) => l.pill === pill ? l : {
712
+ ...l,
713
+ pill
714
+ })
715
+ }), [
716
+ panels,
717
+ layout,
718
+ left,
719
+ right,
720
+ bottom
721
+ ]);
607
722
  useLayoutEffect(() => {
608
723
  if (!apiRef) return;
609
724
  apiRef.current = api;
@@ -632,15 +747,10 @@ function Workspace({ appSlug, panels, apiRef, children }) {
632
747
  close: () => api.close(id)
633
748
  });
634
749
  const snapRect = snap ? pinGeometry(pinPanel(layout, snap.id, snap.edge), viewport).rects[snap.id] : void 0;
635
- const offsets = {
636
- "--hud-reserve-left": `${left}px`,
637
- "--hud-reserve-bottom": `${bottom}px`
638
- };
639
750
  return /* @__PURE__ */ jsx(PanelsContext.Provider, {
640
751
  value: api,
641
752
  children: /* @__PURE__ */ jsxs("div", {
642
753
  className: "hud-layout",
643
- style: offsets,
644
754
  children: [
645
755
  children,
646
756
  narrow ? active && /* @__PURE__ */ jsx(PanelSheet, {
@@ -682,8 +792,12 @@ function Workspace({ appSlug, panels, apiRef, children }) {
682
792
  }
683
793
  //#endregion
684
794
  //#region src/shell/panels/pill-menu.tsx
685
- /** The pill's "⋯" menu: every panel, every command with its shortcut, and Reset layout. */
686
- function PillMenu() {
795
+ /**
796
+ * The pill's "⋯" menu: every panel, every command with its shortcut, and Reset
797
+ * layout. `overflow` counts the pill items that did not fit; their panels are
798
+ * reachable here.
799
+ */
800
+ function PillMenu({ overflow = 0 }) {
687
801
  const panels = usePanels();
688
802
  const commands = useCommands();
689
803
  const apple = useMemo(isApplePlatform, []);
@@ -707,14 +821,17 @@ function PillMenu() {
707
821
  return /* @__PURE__ */ jsxs("div", {
708
822
  className: "menu-anchor",
709
823
  ref,
710
- children: [/* @__PURE__ */ jsx("button", {
824
+ children: [/* @__PURE__ */ jsxs("button", {
711
825
  type: "button",
712
826
  className: "pill-item",
713
- "aria-label": "HUD menu",
827
+ "aria-label": overflow > 0 ? `HUD menu, ${overflow} more` : "HUD menu",
714
828
  "aria-haspopup": "menu",
715
829
  "aria-expanded": open,
716
830
  onClick: () => setOpen((o) => !o),
717
- children: "⋯"
831
+ children: ["⋯", overflow > 0 && /* @__PURE__ */ jsxs("span", {
832
+ className: "menu-badge",
833
+ children: ["+", overflow]
834
+ })]
718
835
  }), open && /* @__PURE__ */ jsxs("div", {
719
836
  className: "menu",
720
837
  role: "menu",
@@ -762,14 +879,25 @@ function PillMenu() {
762
879
  const PANEL_CSS = `
763
880
  .hud-layout { display: contents; }
764
881
 
765
- /* Pinned panels push the page; the pill moves with it so it stays visible. */
766
- .pill {
767
- left: calc(12px + var(--hud-reserve-left, 0px));
768
- bottom: calc(12px + var(--hud-reserve-bottom, 0px));
769
- }
770
-
771
882
  .menu-anchor { position: relative; display: flex; }
772
883
 
884
+ /* The menu opens away from the pill's corner. */
885
+ .pill[data-corner^="top"] .menu { bottom: auto; top: calc(100% + 8px); }
886
+ .pill[data-corner$="right"] .menu { left: auto; right: 0; }
887
+
888
+ .menu-badge {
889
+ position: absolute;
890
+ top: -6px;
891
+ right: -4px;
892
+ padding: 0 4px;
893
+ border-radius: 999px;
894
+ background: var(--hud-accent);
895
+ color: var(--hud-accent-fg);
896
+ font-size: 9px;
897
+ line-height: 14px;
898
+ pointer-events: none;
899
+ }
900
+
773
901
  .menu {
774
902
  position: absolute;
775
903
  left: 0;
@@ -777,6 +905,8 @@ const PANEL_CSS = `
777
905
  display: flex;
778
906
  flex-direction: column;
779
907
  min-width: 220px;
908
+ max-height: min(70vh, 520px);
909
+ overflow-y: auto;
780
910
  padding: 4px;
781
911
  background: var(--hud-bg);
782
912
  border: 1px solid var(--hud-border);
@@ -858,6 +988,7 @@ const PANEL_CSS = `
858
988
  }
859
989
  .hud .panel-action:hover { background: var(--hud-border); color: var(--hud-fg); }
860
990
  .panel-body { flex: 1; padding: 8px 10px; overflow: auto; }
991
+ .panel-error { color: var(--hud-poor); }
861
992
 
862
993
  .snap-zone {
863
994
  position: fixed;
@@ -900,7 +1031,7 @@ const PANEL_CSS = `
900
1031
  //#endregion
901
1032
  //#region src/shell/plugin-slots.tsx
902
1033
  /** One stable context per plugin, so panels and pills can depend on `ctx` in effects. */
903
- function usePluginSlots(plugins, { app, apiBase, can, close, pin }) {
1034
+ function usePluginSlots(plugins, { app, apiBase, can, close, open, pin, grab }) {
904
1035
  return useMemo(() => plugins.map((plugin) => ({
905
1036
  plugin,
906
1037
  title: plugin.title ?? plugin.id,
@@ -909,7 +1040,9 @@ function usePluginSlots(plugins, { app, apiBase, can, close, pin }) {
909
1040
  apiBase,
910
1041
  can,
911
1042
  close: () => close(plugin.id),
912
- pin: (edge) => pin(plugin.id, edge)
1043
+ open: () => open(plugin.id),
1044
+ pin: (edge) => pin(plugin.id, edge),
1045
+ grab
913
1046
  })
914
1047
  })), [
915
1048
  plugins,
@@ -917,182 +1050,561 @@ function usePluginSlots(plugins, { app, apiBase, can, close, pin }) {
917
1050
  apiBase,
918
1051
  can,
919
1052
  close,
920
- pin
1053
+ open,
1054
+ pin,
1055
+ grab
921
1056
  ]);
922
1057
  }
923
1058
  /**
924
1059
  * A plugin's pill item. With a panel it is a toggle button; without one it
925
1060
  * only shows the plugin's `pill` content.
926
1061
  */
927
- function PluginPillItem({ slot, open, onToggle }) {
1062
+ function PluginPillItem({ slot, open, overflow = false, onToggle }) {
928
1063
  const { plugin, ctx, title } = slot;
929
1064
  const Pill = plugin.pill;
930
1065
  const content = Pill ? /* @__PURE__ */ jsx(Pill, { ctx }) : title;
1066
+ const shared = {
1067
+ className: overflow ? "pill-item pill-overflow" : "pill-item",
1068
+ "data-pill-id": plugin.id,
1069
+ "aria-hidden": overflow || void 0
1070
+ };
931
1071
  if (!plugin.panel) return Pill ? /* @__PURE__ */ jsx("span", {
932
- className: "pill-item",
1072
+ ...shared,
933
1073
  children: content
934
1074
  }) : null;
935
1075
  return /* @__PURE__ */ jsx("button", {
936
1076
  type: "button",
937
- className: "pill-item",
1077
+ ...shared,
1078
+ tabIndex: overflow ? -1 : void 0,
938
1079
  "aria-pressed": open,
939
1080
  title,
940
1081
  onClick: onToggle,
941
1082
  children: content
942
1083
  });
943
1084
  }
1085
+ /**
1086
+ * A plugin's panel content. Panels are dynamic imports (`lazy(() => import(...))`),
1087
+ * so the body suspends on first open and shows a loading line meanwhile. A
1088
+ * panel that fails to load or throws while rendering is contained here: the
1089
+ * frame stays, the message replaces the body, the rest of the HUD keeps going.
1090
+ */
944
1091
  function PluginPanelBody({ slot }) {
945
1092
  const Panel = slot.plugin.panel;
946
- return Panel ? /* @__PURE__ */ jsx(Panel, { ctx: slot.ctx }) : null;
1093
+ if (!Panel) return null;
1094
+ return /* @__PURE__ */ jsx(PanelBoundary, {
1095
+ title: slot.title,
1096
+ children: /* @__PURE__ */ jsx(Suspense, {
1097
+ fallback: /* @__PURE__ */ jsx("p", {
1098
+ className: "empty panel-loading",
1099
+ role: "status",
1100
+ children: "Loading…"
1101
+ }),
1102
+ children: /* @__PURE__ */ jsx(Panel, { ctx: slot.ctx })
1103
+ })
1104
+ });
947
1105
  }
1106
+ var PanelBoundary = class extends Component {
1107
+ state = { error: null };
1108
+ static getDerivedStateFromError(error) {
1109
+ return { error: error instanceof Error ? error : new Error(String(error)) };
1110
+ }
1111
+ componentDidCatch(error, info) {
1112
+ console.error(`hud: the ${this.props.title} panel failed`, error, info.componentStack);
1113
+ }
1114
+ render() {
1115
+ const { error } = this.state;
1116
+ if (error) return /* @__PURE__ */ jsxs("p", {
1117
+ className: "empty panel-error",
1118
+ role: "alert",
1119
+ children: [
1120
+ this.props.title,
1121
+ " failed: ",
1122
+ error.message
1123
+ ]
1124
+ });
1125
+ return this.props.children;
1126
+ }
1127
+ };
948
1128
  //#endregion
949
- //#region src/core/marker.ts
1129
+ //#region src/shell/pill/obstacles.ts
1130
+ /** Fixed elements covering more than this share of the viewport are backdrops, not corners. */
1131
+ const MAX_AREA_SHARE = .5;
1132
+ /** DOM changes settle for this long before the page is scanned again. */
1133
+ const RESCAN_MS = 250;
1134
+ function isFloating(el) {
1135
+ const { position } = getComputedStyle(el);
1136
+ return position === "fixed" || position === "sticky";
1137
+ }
950
1138
  /**
951
- * Literal a consumer's CI bundle gate greps for in production client chunks.
952
- * It is rendered as an attribute on the HUD root, so a bundler cannot drop it
953
- * while keeping the HUD, and it is unmistakably deliberate rather than an
954
- * incidental string a refactor could rename away.
1139
+ * The host page's fixed and sticky elements: what fights the pill for a
1140
+ * corner. Nested ones are dropped since their floating ancestor already
1141
+ * counts, and the HUD's own host is skipped.
955
1142
  */
956
- const HUD_DEV_MARKER = "__HANSENEXUS_HUD_DEV__";
957
- /** Tag name of the element that hosts the HUD's shadow root. */
958
- const HUD_HOST_TAG = "hn-hud";
959
- //#endregion
960
- //#region src/shell/shadow-host.tsx
1143
+ function scanFloating(root = document.body) {
1144
+ const found = [];
1145
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, { acceptNode: (node) => {
1146
+ const el = node;
1147
+ if (el.localName === "hn-hud") return NodeFilter.FILTER_REJECT;
1148
+ return isFloating(el) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
1149
+ } });
1150
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
1151
+ const el = node;
1152
+ if (!found.some((outer) => outer.contains(el))) found.push(el);
1153
+ }
1154
+ return found;
1155
+ }
1156
+ /** Visible rects of `elements`, minus backdrops and anything off screen. */
1157
+ function obstacleRects(elements) {
1158
+ const vw = window.innerWidth;
1159
+ const vh = window.innerHeight;
1160
+ const rects = [];
1161
+ for (const el of elements) {
1162
+ const { left, top, width, height } = el.getBoundingClientRect();
1163
+ if (width === 0 || height === 0) continue;
1164
+ if (width * height > vw * vh * MAX_AREA_SHARE) continue;
1165
+ if (left >= vw || top >= vh || left + width <= 0 || top + height <= 0) continue;
1166
+ const style = getComputedStyle(el);
1167
+ if (style.visibility === "hidden" || style.opacity === "0") continue;
1168
+ rects.push({
1169
+ left,
1170
+ top,
1171
+ width,
1172
+ height
1173
+ });
1174
+ }
1175
+ return rects;
1176
+ }
1177
+ function sameRects(a, b) {
1178
+ return a.length === b.length && a.every((r, i) => r.left === b[i]?.left && r.top === b[i]?.top && r.width === b[i]?.width && r.height === b[i]?.height);
1179
+ }
1180
+ const NONE = [];
961
1181
  /**
962
- * Inline `!important` on the host element: author `!important` in a host
963
- * stylesheet (`* { position: static !important }`) loses to inline
964
- * `!important`, so this is the one set of rules a client site cannot override.
965
- * The host covers the viewport but lets every click through; HUD surfaces opt
966
- * back in with `pointer-events: auto`.
1182
+ * Live obstacle rects. The element list is rescanned when the DOM settles
1183
+ * after a change; rects are re-measured on scroll (sticky elements move) and
1184
+ * resize, once per frame.
967
1185
  */
968
- const HOST_STYLE = {
969
- all: "initial",
970
- position: "fixed",
971
- inset: "0",
972
- "z-index": "2147483000",
973
- "pointer-events": "none",
974
- display: "block"
975
- };
1186
+ function useObstacles() {
1187
+ const [rects, setRects] = useState(NONE);
1188
+ useEffect(() => {
1189
+ let elements = scanFloating();
1190
+ let frame = 0;
1191
+ let timer;
1192
+ const measure = () => {
1193
+ frame = 0;
1194
+ const next = obstacleRects(elements);
1195
+ setRects((prev) => sameRects(prev, next) ? prev : next);
1196
+ };
1197
+ const schedule = () => {
1198
+ if (!frame) frame = requestAnimationFrame(measure);
1199
+ };
1200
+ const rescan = () => {
1201
+ schedule();
1202
+ clearTimeout(timer);
1203
+ timer = setTimeout(() => {
1204
+ elements = scanFloating();
1205
+ schedule();
1206
+ }, RESCAN_MS);
1207
+ };
1208
+ measure();
1209
+ const observer = new MutationObserver(rescan);
1210
+ observer.observe(document.body, {
1211
+ childList: true,
1212
+ subtree: true,
1213
+ attributes: true,
1214
+ attributeFilter: [
1215
+ "class",
1216
+ "style",
1217
+ "hidden"
1218
+ ]
1219
+ });
1220
+ window.addEventListener("scroll", schedule, {
1221
+ capture: true,
1222
+ passive: true
1223
+ });
1224
+ window.addEventListener("resize", schedule);
1225
+ return () => {
1226
+ observer.disconnect();
1227
+ clearTimeout(timer);
1228
+ if (frame) cancelAnimationFrame(frame);
1229
+ window.removeEventListener("scroll", schedule, { capture: true });
1230
+ window.removeEventListener("resize", schedule);
1231
+ };
1232
+ }, []);
1233
+ return rects;
1234
+ }
1235
+ /** Clearance kept between the pill and a host element it moves away from. */
1236
+ const CLEARANCE = 8;
1237
+ /** The pill never moves further than this share of the viewport height off its edge. */
1238
+ const MAX_SHIFT_SHARE = .4;
1239
+ /** Extra cost of a top corner when every corner needs a shift: host navs live up there. */
1240
+ const TOP_PENALTY = 48;
1241
+ const isBottom = (corner) => corner.startsWith("bottom");
1242
+ const isRight = (corner) => corner.endsWith("right");
1243
+ function pillRect({ corner, shift }, size, viewport, reserve) {
1244
+ return {
1245
+ left: isRight(corner) ? viewport.w - reserve.right - 12 - size.width : reserve.left + 12,
1246
+ top: isBottom(corner) ? viewport.h - reserve.bottom - 12 - shift - size.height : 12 + shift,
1247
+ width: size.width,
1248
+ height: size.height
1249
+ };
1250
+ }
1251
+ function intersects(a, b) {
1252
+ return a.left < b.left + b.width && b.left < a.left + a.width && a.top < b.top + b.height && b.top < a.top + a.height;
1253
+ }
976
1254
  /**
977
- * Renders children into a shadow root on a host element appended to <body>.
978
- * Mounted in an effect, so server rendering emits nothing and hydration never
979
- * differs.
1255
+ * Shifts the pill away from its corner's edge until it clears every obstacle,
1256
+ * or returns null when that would take it past the shift cap.
980
1257
  */
981
- function ShadowHost({ css, children }) {
982
- const [mount, setMount] = useState(null);
983
- useLayoutEffect(() => {
984
- const host = document.createElement(HUD_HOST_TAG);
985
- for (const [prop, value] of Object.entries(HOST_STYLE)) host.style.setProperty(prop, value, "important");
986
- const shadow = host.attachShadow({ mode: "open" });
987
- const style = document.createElement("style");
988
- style.textContent = css;
989
- const root = document.createElement("div");
990
- root.className = "hud";
991
- root.setAttribute("data-hud-marker", HUD_DEV_MARKER);
992
- shadow.append(style, root);
993
- document.body.appendChild(host);
994
- setMount(root);
995
- return () => {
996
- host.remove();
997
- setMount(null);
1258
+ function shiftWithin(corner, options) {
1259
+ const { viewport, size, obstacles, reserve } = options;
1260
+ const max = viewport.h * MAX_SHIFT_SHARE;
1261
+ let placement = {
1262
+ corner,
1263
+ shift: 0
1264
+ };
1265
+ for (let round = 0; round <= obstacles.length; round++) {
1266
+ const rect = pillRect(placement, size, viewport, reserve);
1267
+ const hits = obstacles.filter((o) => intersects(rect, o));
1268
+ if (hits.length === 0) return placement;
1269
+ const shift = Math.max(...hits.map((o) => isBottom(corner) ? viewport.h - reserve.bottom - 12 - o.top + CLEARANCE : o.top + o.height + CLEARANCE - 12));
1270
+ if (shift > max || shift <= placement.shift) return null;
1271
+ placement = {
1272
+ corner,
1273
+ shift
998
1274
  };
999
- }, [css]);
1000
- return mount ? createPortal(children, mount) : null;
1275
+ }
1276
+ return null;
1277
+ }
1278
+ /**
1279
+ * Where the pill goes. A dragged corner is kept and only shifted. Otherwise the
1280
+ * first corner that is free as is wins; when none is, the corner that needs
1281
+ * the smallest shift, with top corners penalised. Null when no corner clears its obstacles within the cap:
1282
+ * the caller then shrinks the pill to compact mode and tries again.
1283
+ */
1284
+ function placePill(options) {
1285
+ if (options.pinned) return shiftWithin(options.pinned, options);
1286
+ const cost = ({ corner, shift }) => shift + (isBottom(corner) ? 0 : TOP_PENALTY);
1287
+ let best = null;
1288
+ for (const corner of CORNERS) {
1289
+ const placement = shiftWithin(corner, options);
1290
+ if (placement?.shift === 0) return placement;
1291
+ if (placement && (!best || cost(placement) < cost(best))) best = placement;
1292
+ }
1293
+ return best;
1294
+ }
1295
+ /** The corner a dragged pill lands in: the viewport quadrant of the drop point. */
1296
+ function nearestCorner(x, y, viewport) {
1297
+ return `${y > viewport.h / 2 ? "bottom" : "top"}-${x > viewport.w / 2 ? "right" : "left"}`;
1298
+ }
1299
+ /**
1300
+ * Which plugin items fit in `budget` pixels. Higher priority first, then pill
1301
+ * order; an item that does not fit is skipped, so a smaller one after it can
1302
+ * still take the remaining room. `compact` keeps only prioritised items.
1303
+ */
1304
+ function fitItems(items, budget, { compact = false, gap = 0 } = {}) {
1305
+ const ranked = items.map((item, index) => ({
1306
+ item,
1307
+ index
1308
+ })).filter(({ item }) => !compact || item.priority > 0).sort((a, b) => b.item.priority - a.item.priority || a.index - b.index);
1309
+ const visible = /* @__PURE__ */ new Set();
1310
+ let left = budget;
1311
+ for (const { item } of ranked) {
1312
+ const cost = item.width + gap;
1313
+ if (cost > left) continue;
1314
+ visible.add(item.id);
1315
+ left -= cost;
1316
+ }
1317
+ return visible;
1001
1318
  }
1002
1319
  //#endregion
1003
- //#region src/shell/hud.tsx
1004
- const CSS = `
1005
- .hud {
1006
- all: initial;
1007
- --hud-bg: #ffffff;
1008
- --hud-bg-subtle: #f4f4f5;
1009
- --hud-fg: #18181b;
1010
- --hud-fg-muted: #71717a;
1011
- --hud-border: rgba(24, 24, 27, 0.14);
1012
- --hud-accent: #0369a1;
1013
- --hud-good: #15803d;
1014
- --hud-warn: #b45309;
1015
- --hud-poor: #b91c1c;
1016
- --hud-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.08);
1017
- --hud-radius: 8px;
1018
- --hud-font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
1019
- --hud-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
1020
-
1021
- font-family: var(--hud-font);
1022
- font-size: 12px;
1023
- line-height: 1.5;
1024
- color: var(--hud-fg);
1320
+ //#region src/shell/pill/visual-viewport.ts
1321
+ function subscribe(listener) {
1322
+ const vv = window.visualViewport;
1323
+ window.addEventListener("resize", listener);
1324
+ vv?.addEventListener("resize", listener);
1325
+ vv?.addEventListener("scroll", listener);
1326
+ return () => {
1327
+ window.removeEventListener("resize", listener);
1328
+ vv?.removeEventListener("resize", listener);
1329
+ vv?.removeEventListener("scroll", listener);
1330
+ };
1025
1331
  }
1026
-
1027
- @media (prefers-color-scheme: dark) {
1028
- .hud {
1029
- --hud-bg: #18181b;
1030
- --hud-bg-subtle: #27272a;
1031
- --hud-fg: #f4f4f5;
1032
- --hud-fg-muted: #a1a1aa;
1033
- --hud-border: rgba(244, 244, 245, 0.16);
1034
- --hud-accent: #38bdf8;
1035
- --hud-good: #4ade80;
1036
- --hud-warn: #fbbf24;
1037
- --hud-poor: #f87171;
1038
- --hud-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
1039
- }
1332
+ let cached = {
1333
+ x: 0,
1334
+ y: 0,
1335
+ w: 0,
1336
+ h: 0,
1337
+ detached: false
1338
+ };
1339
+ /**
1340
+ * On a phone, a page wider than the screen (an image with a fixed width is
1341
+ * enough) grows the layout viewport past the visible area, and a pill fixed
1342
+ * to the bottom edge ends up below the fold. The visual viewport is what the
1343
+ * user sees; the pill places itself in it.
1344
+ */
1345
+ function read() {
1346
+ const root = document.documentElement;
1347
+ const layoutW = root.clientWidth || window.innerWidth;
1348
+ const layoutH = root.clientHeight || window.innerHeight;
1349
+ const vv = window.visualViewport;
1350
+ const x = vv?.offsetLeft ?? 0;
1351
+ const y = vv?.offsetTop ?? 0;
1352
+ const w = Math.round(vv?.width ?? layoutW);
1353
+ const h = Math.round(vv?.height ?? layoutH);
1354
+ const detached = x !== 0 || y !== 0 || window.innerWidth > w + 1 || window.innerHeight > h + 1;
1355
+ const next = {
1356
+ x,
1357
+ y,
1358
+ w: detached ? w : layoutW,
1359
+ h: detached ? h : layoutH,
1360
+ detached
1361
+ };
1362
+ if (next.x !== cached.x || next.y !== cached.y || next.w !== cached.w || next.h !== cached.h || next.detached !== cached.detached) cached = next;
1363
+ return cached;
1040
1364
  }
1041
-
1042
- .hud *, .hud *::before, .hud *::after { box-sizing: border-box; }
1043
-
1044
- .hud button {
1045
- font: inherit;
1046
- color: inherit;
1047
- background: none;
1048
- border: 0;
1049
- margin: 0;
1050
- padding: 0;
1051
- cursor: pointer;
1365
+ function useVisualViewport() {
1366
+ return useSyncExternalStore(subscribe, read, read);
1052
1367
  }
1053
-
1054
- .hud :focus-visible { outline: 2px solid var(--hud-accent); outline-offset: 1px; }
1055
-
1056
- .pill {
1057
- position: fixed;
1058
- left: 12px;
1059
- bottom: 12px;
1060
- display: flex;
1061
- align-items: center;
1062
- gap: 2px;
1063
- padding: 3px;
1064
- background: var(--hud-bg);
1065
- border: 1px solid var(--hud-border);
1066
- border-radius: 999px;
1067
- box-shadow: var(--hud-shadow);
1068
- font-family: var(--hud-mono);
1069
- pointer-events: auto;
1368
+ //#endregion
1369
+ //#region src/shell/pill/pill.tsx
1370
+ /** `.pill` gap, padding and border, which the item widths do not include. */
1371
+ const ITEM_GAP = 2;
1372
+ const CHROME = 8;
1373
+ /** A press that moves less than this is a click, not a drag. */
1374
+ const DRAG_THRESHOLD = 4;
1375
+ const EMPTY = {
1376
+ items: {},
1377
+ fixed: 0,
1378
+ height: 0
1379
+ };
1380
+ function measure(pill) {
1381
+ const items = {};
1382
+ let fixed = 0;
1383
+ let count = 0;
1384
+ for (const child of pill.children) {
1385
+ if (!(child instanceof HTMLElement)) continue;
1386
+ const id = child.dataset.pillId;
1387
+ if (id) items[id] = child.offsetWidth;
1388
+ else {
1389
+ fixed += child.offsetWidth;
1390
+ count++;
1391
+ }
1392
+ }
1393
+ return {
1394
+ items,
1395
+ fixed: fixed + ITEM_GAP * Math.max(0, count - 1),
1396
+ height: pill.offsetHeight
1397
+ };
1070
1398
  }
1071
-
1072
- .hud .pill-item {
1073
- display: flex;
1074
- align-items: center;
1075
- gap: 6px;
1076
- padding: 2px 8px;
1077
- border-radius: 999px;
1078
- white-space: nowrap;
1399
+ function sameMeasure(a, b) {
1400
+ const keys = Object.keys(b.items);
1401
+ return a.fixed === b.fixed && a.height === b.height && keys.length === Object.keys(a.items).length && keys.every((key) => a.items[key] === b.items[key]);
1079
1402
  }
1080
-
1081
- .pill-item:hover, .pill-item[aria-pressed="true"] { background: var(--hud-bg-subtle); }
1082
-
1083
- .env { font-weight: 600; color: var(--hud-accent); }
1084
-
1085
- .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--hud-fg-muted); }
1086
- .dot[data-rating="good"] { background: var(--hud-good); }
1087
- .dot[data-rating="needs-improvement"] { background: var(--hud-warn); }
1088
- .dot[data-rating="poor"] { background: var(--hud-poor); }
1089
-
1090
- .vitals { width: 100%; border-collapse: collapse; font-family: var(--hud-mono); }
1091
- .vitals td { padding: 3px 0; }
1092
- .vitals td:last-child { text-align: right; }
1093
- .vitals .label { color: var(--hud-fg-muted); }
1094
- .empty { color: var(--hud-fg-muted); }
1095
- ` + PANEL_CSS;
1403
+ /**
1404
+ * Fits the items into the width left by pinned panels, then places the pill.
1405
+ * When no corner is free even after shifting, compact mode keeps only
1406
+ * prioritised items and the pill is placed again at that size.
1407
+ */
1408
+ function arrange(slots, measured, options) {
1409
+ const { viewport, reserve } = options;
1410
+ const items = slots.map(({ plugin }) => ({
1411
+ id: plugin.id,
1412
+ width: measured.items[plugin.id] ?? 0,
1413
+ priority: plugin.pillPriority ?? 0
1414
+ }));
1415
+ const budget = viewport.w - reserve.left - reserve.right - 24 - CHROME - measured.fixed;
1416
+ const sizeOf = (visible) => ({
1417
+ width: CHROME + measured.fixed + items.reduce((sum, item) => sum + (visible.has(item.id) ? item.width + ITEM_GAP : 0), 0),
1418
+ height: measured.height
1419
+ });
1420
+ const full = fitItems(items, budget, { gap: ITEM_GAP });
1421
+ const fullSize = sizeOf(full);
1422
+ const placed = placePill({
1423
+ ...options,
1424
+ size: fullSize
1425
+ });
1426
+ if (placed) return {
1427
+ visible: full,
1428
+ placement: placed,
1429
+ size: fullSize,
1430
+ compact: false
1431
+ };
1432
+ const compact = fitItems(items, budget, {
1433
+ gap: ITEM_GAP,
1434
+ compact: true
1435
+ });
1436
+ const compactSize = sizeOf(compact);
1437
+ const fallback = {
1438
+ corner: options.pinned ?? "bottom-left",
1439
+ shift: 0
1440
+ };
1441
+ return {
1442
+ visible: compact,
1443
+ placement: placePill({
1444
+ ...options,
1445
+ size: compactSize
1446
+ }) ?? fallback,
1447
+ size: compactSize,
1448
+ compact: true
1449
+ };
1450
+ }
1451
+ /**
1452
+ * Anchored to its corner's edges, so the pill stays put while its width
1453
+ * changes. When the visible area is detached from the layout viewport (a
1454
+ * page wider than the phone), it is positioned inside the visible area.
1455
+ */
1456
+ function placementStyle(placement, size, reserve, visual) {
1457
+ if (visual.detached) {
1458
+ const rect = pillRect(placement, size, {
1459
+ w: visual.w,
1460
+ h: visual.h
1461
+ }, reserve);
1462
+ return {
1463
+ top: visual.y + rect.top,
1464
+ left: visual.x + rect.left,
1465
+ bottom: "auto",
1466
+ right: "auto"
1467
+ };
1468
+ }
1469
+ const { corner, shift } = placement;
1470
+ const bottom = corner.startsWith("bottom");
1471
+ const right = corner.endsWith("right");
1472
+ const vertical = 12 + shift + (bottom ? reserve.bottom : 0);
1473
+ const horizontal = 12 + (right ? reserve.right : reserve.left);
1474
+ return {
1475
+ top: bottom ? "auto" : vertical,
1476
+ bottom: bottom ? vertical : "auto",
1477
+ left: right ? "auto" : horizontal,
1478
+ right: right ? horizontal : "auto"
1479
+ };
1480
+ }
1481
+ /**
1482
+ * The status pill. It picks a corner free of the host's fixed and sticky
1483
+ * elements, moves low-priority items into its menu when the viewport is too
1484
+ * narrow, and can be dragged by its env badge into another corner, which is
1485
+ * then kept (Reset layout forgets it).
1486
+ */
1487
+ function Pill({ appSlug, envLabel, slots, grab }) {
1488
+ const panels = usePanels();
1489
+ const { grabbing } = useGrab(grab);
1490
+ const visual = useVisualViewport();
1491
+ const viewport = useMemo(() => ({
1492
+ w: visual.w,
1493
+ h: visual.h
1494
+ }), [visual.w, visual.h]);
1495
+ const rawObstacles = useObstacles();
1496
+ const obstacles = useMemo(() => visual.x === 0 && visual.y === 0 ? rawObstacles : rawObstacles.map((o) => ({
1497
+ ...o,
1498
+ left: o.left - visual.x,
1499
+ top: o.top - visual.y
1500
+ })), [
1501
+ rawObstacles,
1502
+ visual.x,
1503
+ visual.y
1504
+ ]);
1505
+ const ref = useRef(null);
1506
+ const [measured, setMeasured] = useState(EMPTY);
1507
+ const [drag, setDrag] = useState(null);
1508
+ const press = useRef(null);
1509
+ useLayoutEffect(() => {
1510
+ const pill = ref.current;
1511
+ if (!pill) return;
1512
+ const update = () => setMeasured((prev) => sameMeasure(prev, measure(pill)) ? prev : measure(pill));
1513
+ update();
1514
+ if (typeof ResizeObserver === "undefined") return;
1515
+ const observer = new ResizeObserver(update);
1516
+ for (const child of pill.children) observer.observe(child);
1517
+ return () => observer.disconnect();
1518
+ }, [slots]);
1519
+ const { visible, placement, size, compact } = useMemo(() => arrange(slots, measured, {
1520
+ viewport,
1521
+ reserve: panels.reserve,
1522
+ obstacles,
1523
+ pinned: panels.pillCorner
1524
+ }), [
1525
+ slots,
1526
+ measured,
1527
+ viewport,
1528
+ panels.reserve,
1529
+ panels.pillCorner,
1530
+ obstacles
1531
+ ]);
1532
+ const hidden = slots.filter(({ plugin }) => !visible.has(plugin.id)).length;
1533
+ const onPointerDown = (e) => {
1534
+ if (e.button !== 0) return;
1535
+ e.currentTarget.setPointerCapture(e.pointerId);
1536
+ press.current = {
1537
+ x: e.clientX,
1538
+ y: e.clientY,
1539
+ moved: false
1540
+ };
1541
+ };
1542
+ const onPointerMove = (e) => {
1543
+ const start = press.current;
1544
+ if (!start) return;
1545
+ const x = e.clientX - start.x;
1546
+ const y = e.clientY - start.y;
1547
+ if (!start.moved && Math.hypot(x, y) < DRAG_THRESHOLD) return;
1548
+ start.moved = true;
1549
+ setDrag({
1550
+ x,
1551
+ y
1552
+ });
1553
+ };
1554
+ const onPointerUp = (e) => {
1555
+ const start = press.current;
1556
+ press.current = null;
1557
+ setDrag(null);
1558
+ if (start?.moved) panels.setPillCorner(nearestCorner(e.clientX, e.clientY, viewport));
1559
+ };
1560
+ const style = {
1561
+ ...placementStyle(placement, size, panels.reserve, visual),
1562
+ ...drag ? { transform: `translate(${drag.x}px, ${drag.y}px)` } : {}
1563
+ };
1564
+ return /* @__PURE__ */ jsxs("div", {
1565
+ ref,
1566
+ className: "pill",
1567
+ role: "toolbar",
1568
+ "aria-label": `${appSlug} hud`,
1569
+ "data-corner": placement.corner,
1570
+ "data-compact": compact || void 0,
1571
+ "data-dragging": drag ? true : void 0,
1572
+ style,
1573
+ children: [
1574
+ /* @__PURE__ */ jsx("span", {
1575
+ className: "pill-item env",
1576
+ title: "Drag to move the pill to another corner",
1577
+ onPointerDown,
1578
+ onPointerMove,
1579
+ onPointerUp,
1580
+ onPointerCancel: () => {
1581
+ press.current = null;
1582
+ setDrag(null);
1583
+ },
1584
+ children: envLabel
1585
+ }),
1586
+ slots.map((slot) => /* @__PURE__ */ jsx(PluginPillItem, {
1587
+ slot,
1588
+ open: panels.isOpen(slot.plugin.id),
1589
+ overflow: !visible.has(slot.plugin.id),
1590
+ onToggle: () => panels.toggle(slot.plugin.id)
1591
+ }, slot.plugin.id)),
1592
+ /* @__PURE__ */ jsx("button", {
1593
+ type: "button",
1594
+ className: "pill-item grab-toggle",
1595
+ "aria-label": "Grab element",
1596
+ "aria-pressed": grabbing,
1597
+ title: "Grab element",
1598
+ onClick: () => grabbing ? grab.cancel() : grab.start(),
1599
+ children: "⌖"
1600
+ }),
1601
+ /* @__PURE__ */ jsx(PillMenu, { overflow: hidden })
1602
+ ]
1603
+ });
1604
+ }
1605
+ //#endregion
1606
+ //#region src/shell/hud.tsx
1607
+ const CSS = HUD_CSS + PANEL_CSS + GRAB_CSS;
1096
1608
  const NO_PLUGINS = [];
1097
1609
  const GRANT_ALL = () => true;
1098
1610
  /**
@@ -1106,6 +1618,7 @@ function Hud({ appSlug, envLabel = "DEV", plugins = NO_PLUGINS, apiBase = "/api/
1106
1618
  const resolved = useMemo(() => resolvePlugins(plugins, can), [plugins, can]);
1107
1619
  return /* @__PURE__ */ jsx(ShadowHost, {
1108
1620
  css: CSS,
1621
+ marker: HUD_DEV_MARKER,
1109
1622
  children: /* @__PURE__ */ jsx(Shell, {
1110
1623
  appSlug,
1111
1624
  envLabel,
@@ -1117,54 +1630,50 @@ function Hud({ appSlug, envLabel = "DEV", plugins = NO_PLUGINS, apiBase = "/api/
1117
1630
  }
1118
1631
  function Shell({ appSlug, envLabel, plugins, apiBase, can }) {
1119
1632
  const panelsRef = useRef(null);
1633
+ const close = useCallback((id) => panelsRef.current?.close(id), []);
1634
+ const open = useCallback((id) => panelsRef.current?.open(id), []);
1635
+ const pin = useCallback((id, edge) => panelsRef.current?.pin(id, edge), []);
1636
+ const [grab] = useState(createGrabber);
1120
1637
  const slots = usePluginSlots(plugins, {
1121
1638
  app: appSlug,
1122
1639
  apiBase,
1123
1640
  can,
1124
- close: useCallback((id) => panelsRef.current?.close(id), []),
1125
- pin: useCallback((id, edge) => panelsRef.current?.pin(id, edge), [])
1641
+ close,
1642
+ open,
1643
+ pin,
1644
+ grab
1126
1645
  });
1127
1646
  const panels = useMemo(() => slots.filter((slot) => slot.plugin.panel).map((slot) => ({
1128
1647
  id: slot.plugin.id,
1129
1648
  title: slot.title,
1130
1649
  render: () => /* @__PURE__ */ jsx(PluginPanelBody, { slot })
1131
1650
  })), [slots]);
1132
- const commands = useMemo(() => slots.flatMap(({ plugin, ctx }) => (plugin.commands ?? []).map((command) => ({
1651
+ const commands = useMemo(() => [{
1652
+ id: "hud.grab",
1653
+ title: "Grab element",
1654
+ shortcut: "mod+shift+g",
1655
+ run: () => grab.getState().grabbing ? grab.cancel() : grab.start()
1656
+ }, ...slots.flatMap(({ plugin, ctx }) => (plugin.commands ?? []).map((command) => ({
1133
1657
  id: `${plugin.id}.${command.id}`,
1134
1658
  title: command.title,
1135
1659
  shortcut: command.shortcut,
1136
1660
  run: () => command.run(ctx)
1137
- }))), [slots]);
1138
- return /* @__PURE__ */ jsx(PanelManager, {
1661
+ })))], [slots, grab]);
1662
+ return /* @__PURE__ */ jsxs(PanelManager, {
1139
1663
  appSlug,
1140
1664
  panels,
1141
1665
  commands,
1142
1666
  apiRef: panelsRef,
1143
- children: /* @__PURE__ */ jsx(Pill, {
1667
+ children: [/* @__PURE__ */ jsx(Pill, {
1144
1668
  appSlug,
1145
1669
  envLabel,
1670
+ slots,
1671
+ grab
1672
+ }), /* @__PURE__ */ jsx(Grabber, {
1673
+ app: appSlug,
1674
+ store: grab,
1146
1675
  slots
1147
- })
1148
- });
1149
- }
1150
- function Pill({ appSlug, envLabel, slots }) {
1151
- const panels = usePanels();
1152
- return /* @__PURE__ */ jsxs("div", {
1153
- className: "pill",
1154
- role: "toolbar",
1155
- "aria-label": `${appSlug} hud`,
1156
- children: [
1157
- /* @__PURE__ */ jsx("span", {
1158
- className: "pill-item env",
1159
- children: envLabel
1160
- }),
1161
- slots.map((slot) => /* @__PURE__ */ jsx(PluginPillItem, {
1162
- slot,
1163
- open: panels.isOpen(slot.plugin.id),
1164
- onToggle: () => panels.toggle(slot.plugin.id)
1165
- }, slot.plugin.id)),
1166
- /* @__PURE__ */ jsx(PillMenu, {})
1167
- ]
1676
+ })]
1168
1677
  });
1169
1678
  }
1170
1679
  //#endregion
@@ -1179,10 +1688,25 @@ function Pill({ appSlug, envLabel, slots }) {
1179
1688
  * Returns a component. The plugin list is frozen here, so the shell sees a
1180
1689
  * stable array across renders.
1181
1690
  */
1182
- function defineHud({ app, plugins, apiBase, can }) {
1183
- resolvePlugins(plugins, () => true);
1184
- const list = Object.freeze([...plugins]);
1185
- function DefinedHud({ envLabel }) {
1691
+ function defineHud({ app, plugins, auto, apiBase, can }) {
1692
+ if (!plugins && !auto) throw new Error("hud: defineHud needs `plugins`, `auto` or both");
1693
+ const explicit = resolvePlugins(plugins ?? [], () => true);
1694
+ const detected = typeof auto === "function" ? auto() : auto ?? [];
1695
+ const list = Object.freeze(mergePlugins(detected, explicit));
1696
+ resolvePlugins(list, () => true);
1697
+ const access = list.find((plugin) => plugin.access)?.access;
1698
+ function DefinedHud({ envLabel, env = "development" }) {
1699
+ if (env === "disabled") return null;
1700
+ if (access) return /* @__PURE__ */ jsx(AccessHud, {
1701
+ access,
1702
+ env,
1703
+ app,
1704
+ plugins: list,
1705
+ apiBase: apiBase ?? "/api/hud",
1706
+ ...envLabel === void 0 ? {} : { envLabel },
1707
+ ...can === void 0 ? {} : { can }
1708
+ });
1709
+ if (env !== "development") return null;
1186
1710
  return /* @__PURE__ */ jsx(Hud, {
1187
1711
  appSlug: app,
1188
1712
  plugins: list,
@@ -1194,5 +1718,39 @@ function defineHud({ app, plugins, apiBase, can }) {
1194
1718
  DefinedHud.displayName = `Hud(${app})`;
1195
1719
  return DefinedHud;
1196
1720
  }
1721
+ /**
1722
+ * The detected list with explicit plugins merged in: same id replaces in
1723
+ * place (pill position kept), a new id goes to the end.
1724
+ */
1725
+ function mergePlugins(detected, explicit) {
1726
+ const byId = new Map(explicit.map((plugin) => [plugin.id, plugin]));
1727
+ const merged = detected.map((plugin) => byId.get(plugin.id) ?? plugin);
1728
+ const seen = new Set(detected.map((plugin) => plugin.id));
1729
+ for (const plugin of explicit) if (!seen.has(plugin.id)) merged.push(plugin);
1730
+ return merged;
1731
+ }
1732
+ /**
1733
+ * The shell behind the access plugin's lock and capability matrix.
1734
+ *
1735
+ * Display only: hiding a plugin here protects nothing, since its code ships
1736
+ * in the bundle and its routes are one URL away. The server guard
1737
+ * (`accessGuard`) is what enforces the tier.
1738
+ */
1739
+ function AccessHud({ access, env, app, plugins, apiBase, envLabel, can }) {
1740
+ const unlocked = access.useUnlocked(env, apiBase);
1741
+ const gated = useCallback((capability) => access.can(env, capability) && (can?.(capability) ?? true), [
1742
+ access,
1743
+ env,
1744
+ can
1745
+ ]);
1746
+ const shown = useMemo(() => unlocked ? plugins : plugins.filter((plugin) => plugin.access), [unlocked, plugins]);
1747
+ return /* @__PURE__ */ jsx(Hud, {
1748
+ appSlug: app,
1749
+ plugins: shown,
1750
+ apiBase,
1751
+ can: gated,
1752
+ ...envLabel === void 0 ? {} : { envLabel }
1753
+ });
1754
+ }
1197
1755
  //#endregion
1198
- export { HUD_DEV_MARKER, HUD_HOST_TAG, Hud, HudApiError, defineHud, definePlugin };
1756
+ export { ElementOutline, ElementPicker, HUD_DEV_MARKER, HUD_HOST_TAG, Hud, HudApiError, PICKER_CSS, defineHud, definePlugin, matchComponentHints, useGrab };