@hansenexus/hud 0.7.0 → 0.8.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 (66) hide show
  1. package/README.md +111 -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 +45 -196
  22. package/dist/navigation-CX6AXm7H.js +176 -0
  23. package/dist/next.d.ts +4 -1
  24. package/dist/next.js +12 -1
  25. package/dist/obstacles-CCmRFTcZ.js +176 -0
  26. package/dist/plugins/a11y.d.ts +1 -1
  27. package/dist/plugins/access/server.d.ts +3 -3
  28. package/dist/plugins/access.d.ts +2 -2
  29. package/dist/plugins/agent/server.js +1 -1
  30. package/dist/plugins/agent.d.ts +2 -2
  31. package/dist/plugins/capture.d.ts +2 -2
  32. package/dist/plugins/data/server.d.ts +1 -1
  33. package/dist/plugins/data/server.js +1 -1
  34. package/dist/plugins/data.d.ts +1 -1
  35. package/dist/plugins/design/server.d.ts +55 -15
  36. package/dist/plugins/design/server.js +187 -122
  37. package/dist/plugins/design.d.ts +3 -3
  38. package/dist/plugins/design.js +1 -1
  39. package/dist/plugins/inspect.d.ts +1 -1
  40. package/dist/plugins/observe.d.ts +1 -1
  41. package/dist/plugins/ops/server.d.ts +1 -1
  42. package/dist/plugins/ops.d.ts +1 -1
  43. package/dist/plugins/routes/server.d.ts +1 -1
  44. package/dist/plugins/routes.d.ts +3 -3
  45. package/dist/plugins/routes.js +381 -52
  46. package/dist/plugins/seo.d.ts +1 -1
  47. package/dist/plugins/vitals.d.ts +1 -1
  48. package/dist/{plugins-BZT-1LBe.d.ts → plugins-pL2CoWzI.d.ts} +7 -0
  49. package/dist/same-origin-BHuZO1_H.js +36 -0
  50. package/dist/server.d.ts +2 -2
  51. package/dist/store.d.ts +1 -1
  52. package/dist/store.js +1 -1
  53. package/dist/{meta-C_G7MB5w.d.ts → types-Dc6JWZR7.d.ts} +6 -6
  54. package/dist/variant-bar-BzZ0ln-C.js +768 -0
  55. package/dist/variant-picks-Byc0hC8a.js +144 -0
  56. package/dist/variants-export-vEtZ-OGC.js +75 -0
  57. package/dist/{variants-panel-B6zWcknV.js → variants-panel-D23v5KIp.js} +71 -54
  58. package/dist/variants-types-BOsZ5fDz.js +65 -0
  59. package/dist/variants-types-VkW7vFZF.d.ts +139 -0
  60. package/dist/variants.d.ts +1 -1
  61. package/dist/variants.js +1 -1
  62. package/dist/vite.d.ts +2 -2
  63. package/package.json +1 -1
  64. package/dist/index-B1vHAY9p.d.ts +0 -20
  65. package/dist/same-origin-BGet22CC.js +0 -21
  66. package/dist/variants-types-CcRf119M.d.ts +0 -63
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import { n as HUD_HOST_TAG, t as HUD_DEV_MARKER } from "./marker-uZYPOJ4M.js";
4
4
  import { a as ratingTone, i as definePlugin, n as HudApiError, o as resolvePlugins, r as createPluginContext } from "./plugins-CcW_K7c2.js";
5
5
  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";
6
6
  import { i as PICKER_CSS, n as ShadowHost, r as ElementPicker, t as HUD_CSS } from "./styles-BA8ueHoV.js";
7
+ import { a as usePanels, i as PanelsContext, n as useObstacles, r as useVisualViewport, t as offsetObstacles } from "./obstacles-CCmRFTcZ.js";
7
8
  import { Component, Suspense, createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
8
9
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
10
  //#region src/core/grabber/outline.tsx
@@ -566,14 +567,6 @@ function PanelSheet({ panels, active, onSelect, onClose, children }) {
566
567
  });
567
568
  }
568
569
  //#endregion
569
- //#region src/shell/panels/panels-context.ts
570
- const PanelsContext = createContext(null);
571
- function usePanels() {
572
- const api = useContext(PanelsContext);
573
- if (!api) throw new Error("usePanels() used outside <PanelManager>");
574
- return api;
575
- }
576
- //#endregion
577
570
  //#region src/shell/panels/reserve.ts
578
571
  const PADDING = {
579
572
  left: "padding-left",
@@ -690,7 +683,7 @@ function subscribeResize(listener) {
690
683
  window.addEventListener("resize", listener);
691
684
  return () => window.removeEventListener("resize", listener);
692
685
  }
693
- let cached$1 = {
686
+ let cached = {
694
687
  w: 0,
695
688
  h: 0
696
689
  };
@@ -702,11 +695,11 @@ function readViewport() {
702
695
  const root = document.documentElement;
703
696
  const w = root.clientWidth || window.innerWidth;
704
697
  const h = root.clientHeight || window.innerHeight;
705
- if (w !== cached$1.w || h !== cached$1.h) cached$1 = {
698
+ if (w !== cached.w || h !== cached.h) cached = {
706
699
  w,
707
700
  h
708
701
  };
709
- return cached$1;
702
+ return cached;
710
703
  }
711
704
  function useViewport() {
712
705
  return useSyncExternalStore(subscribeResize, readViewport, readViewport);
@@ -1049,55 +1042,6 @@ function clampOffset(rect, area, margin) {
1049
1042
  };
1050
1043
  }
1051
1044
  //#endregion
1052
- //#region src/shell/pill/visual-viewport.ts
1053
- function subscribe$1(listener) {
1054
- const vv = window.visualViewport;
1055
- window.addEventListener("resize", listener);
1056
- vv?.addEventListener("resize", listener);
1057
- vv?.addEventListener("scroll", listener);
1058
- return () => {
1059
- window.removeEventListener("resize", listener);
1060
- vv?.removeEventListener("resize", listener);
1061
- vv?.removeEventListener("scroll", listener);
1062
- };
1063
- }
1064
- let cached = {
1065
- x: 0,
1066
- y: 0,
1067
- w: 0,
1068
- h: 0,
1069
- detached: false
1070
- };
1071
- /**
1072
- * On a phone, a page wider than the screen (an image with a fixed width is
1073
- * enough) grows the layout viewport past the visible area, and a pill fixed
1074
- * to the bottom edge ends up below the fold. The visual viewport is what the
1075
- * user sees; the pill places itself in it.
1076
- */
1077
- function read$1() {
1078
- const root = document.documentElement;
1079
- const layoutW = root.clientWidth || window.innerWidth;
1080
- const layoutH = root.clientHeight || window.innerHeight;
1081
- const vv = window.visualViewport;
1082
- const x = vv?.offsetLeft ?? 0;
1083
- const y = vv?.offsetTop ?? 0;
1084
- const w = Math.round(vv?.width ?? layoutW);
1085
- const h = Math.round(vv?.height ?? layoutH);
1086
- const detached = x !== 0 || y !== 0 || window.innerWidth > w + 1 || window.innerHeight > h + 1;
1087
- const next = {
1088
- x,
1089
- y,
1090
- w: detached ? w : layoutW,
1091
- h: detached ? h : layoutH,
1092
- detached
1093
- };
1094
- if (next.x !== cached.x || next.y !== cached.y || next.w !== cached.w || next.h !== cached.h || next.detached !== cached.detached) cached = next;
1095
- return cached;
1096
- }
1097
- function useVisualViewport() {
1098
- return useSyncExternalStore(subscribe$1, read$1, read$1);
1099
- }
1100
- //#endregion
1101
1045
  //#region src/shell/panels/pill-menu.tsx
1102
1046
  /** Distance the open menu keeps from the edges of the visible area. */
1103
1047
  const MENU_MARGIN = 8;
@@ -1486,145 +1430,46 @@ function PluginPanelBody({ slot }) {
1486
1430
  })
1487
1431
  });
1488
1432
  }
1433
+ /** A plugin's overlay. A loading or failed overlay is nothing; the rest of the HUD keeps going. */
1434
+ function PluginOverlay({ slot }) {
1435
+ const Overlay = slot.plugin.overlay;
1436
+ if (!Overlay) return null;
1437
+ return /* @__PURE__ */ jsx(PanelBoundary, {
1438
+ title: slot.title,
1439
+ silent: true,
1440
+ children: /* @__PURE__ */ jsx(Suspense, {
1441
+ fallback: null,
1442
+ children: /* @__PURE__ */ jsx(Overlay, { ctx: slot.ctx })
1443
+ })
1444
+ });
1445
+ }
1489
1446
  var PanelBoundary = class extends Component {
1490
1447
  state = { error: null };
1491
1448
  static getDerivedStateFromError(error) {
1492
1449
  return { error: error instanceof Error ? error : new Error(String(error)) };
1493
1450
  }
1494
1451
  componentDidCatch(error, info) {
1495
- console.error(`hud: the ${this.props.title} panel failed`, error, info.componentStack);
1452
+ const what = this.props.silent ? "overlay" : "panel";
1453
+ console.error(`hud: the ${this.props.title} ${what} failed`, error, info.componentStack);
1496
1454
  }
1497
1455
  render() {
1498
1456
  const { error } = this.state;
1499
- if (error) return /* @__PURE__ */ jsxs("p", {
1500
- className: "empty panel-error",
1501
- role: "alert",
1502
- children: [
1503
- this.props.title,
1504
- " failed: ",
1505
- error.message
1506
- ]
1507
- });
1457
+ if (error) {
1458
+ if (this.props.silent) return null;
1459
+ return /* @__PURE__ */ jsxs("p", {
1460
+ className: "empty panel-error",
1461
+ role: "alert",
1462
+ children: [
1463
+ this.props.title,
1464
+ " failed: ",
1465
+ error.message
1466
+ ]
1467
+ });
1468
+ }
1508
1469
  return this.props.children;
1509
1470
  }
1510
1471
  };
1511
1472
  //#endregion
1512
- //#region src/shell/pill/obstacles.ts
1513
- /** Fixed elements covering more than this share of the viewport are backdrops, not corners. */
1514
- const MAX_AREA_SHARE = .5;
1515
- /** DOM changes settle for this long before the page is scanned again. */
1516
- const RESCAN_MS = 250;
1517
- function isFloating(el) {
1518
- const { position } = getComputedStyle(el);
1519
- return position === "fixed" || position === "sticky";
1520
- }
1521
- /**
1522
- * The host page's fixed and sticky elements: what fights the pill for a
1523
- * corner. Nested ones are dropped since their floating ancestor already
1524
- * counts, and the HUD's own host is skipped.
1525
- */
1526
- function scanFloating(root = document.body) {
1527
- const found = [];
1528
- const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, { acceptNode: (node) => {
1529
- const el = node;
1530
- if (el.localName === "hn-hud") return NodeFilter.FILTER_REJECT;
1531
- return isFloating(el) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
1532
- } });
1533
- for (let node = walker.nextNode(); node; node = walker.nextNode()) {
1534
- const el = node;
1535
- if (!found.some((outer) => outer.contains(el))) found.push(el);
1536
- }
1537
- return found;
1538
- }
1539
- /** Visible rects of `elements`, minus backdrops and anything off screen. */
1540
- function obstacleRects(elements) {
1541
- const vw = window.innerWidth;
1542
- const vh = window.innerHeight;
1543
- const rects = [];
1544
- for (const el of elements) {
1545
- const { left, top, width, height } = el.getBoundingClientRect();
1546
- if (width === 0 || height === 0) continue;
1547
- if (width * height > vw * vh * MAX_AREA_SHARE) continue;
1548
- if (left >= vw || top >= vh || left + width <= 0 || top + height <= 0) continue;
1549
- const style = getComputedStyle(el);
1550
- if (style.visibility === "hidden" || style.opacity === "0") continue;
1551
- rects.push({
1552
- left,
1553
- top,
1554
- width,
1555
- height
1556
- });
1557
- }
1558
- return rects;
1559
- }
1560
- function sameRects(a, b) {
1561
- 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);
1562
- }
1563
- const NONE = [];
1564
- /** Obstacle rects moved into visible-area coordinates when the visual viewport is offset. */
1565
- function offsetObstacles(rects, offset) {
1566
- if (offset.x === 0 && offset.y === 0) return rects;
1567
- return rects.map((o) => ({
1568
- ...o,
1569
- left: o.left - offset.x,
1570
- top: o.top - offset.y
1571
- }));
1572
- }
1573
- /**
1574
- * Live obstacle rects. The element list is rescanned when the DOM settles
1575
- * after a change; rects are re-measured on scroll (sticky elements move) and
1576
- * resize, once per frame.
1577
- */
1578
- function useObstacles() {
1579
- const [rects, setRects] = useState(NONE);
1580
- useEffect(() => {
1581
- let elements = scanFloating();
1582
- let frame = 0;
1583
- let timer;
1584
- const measure = () => {
1585
- frame = 0;
1586
- const next = obstacleRects(elements);
1587
- setRects((prev) => sameRects(prev, next) ? prev : next);
1588
- };
1589
- const schedule = () => {
1590
- if (!frame) frame = requestAnimationFrame(measure);
1591
- };
1592
- const rescan = () => {
1593
- schedule();
1594
- clearTimeout(timer);
1595
- timer = setTimeout(() => {
1596
- elements = scanFloating();
1597
- schedule();
1598
- }, RESCAN_MS);
1599
- };
1600
- measure();
1601
- const observer = new MutationObserver(rescan);
1602
- observer.observe(document.body, {
1603
- childList: true,
1604
- subtree: true,
1605
- attributes: true,
1606
- attributeFilter: [
1607
- "class",
1608
- "style",
1609
- "hidden"
1610
- ]
1611
- });
1612
- window.addEventListener("scroll", schedule, {
1613
- capture: true,
1614
- passive: true
1615
- });
1616
- window.addEventListener("resize", schedule);
1617
- return () => {
1618
- observer.disconnect();
1619
- clearTimeout(timer);
1620
- if (frame) cancelAnimationFrame(frame);
1621
- window.removeEventListener("scroll", schedule, { capture: true });
1622
- window.removeEventListener("resize", schedule);
1623
- };
1624
- }, []);
1625
- return rects;
1626
- }
1627
- //#endregion
1628
1473
  //#region src/shell/pill/pill.tsx
1629
1474
  /** `.pill` gap, padding and border, which the item widths do not include. */
1630
1475
  const ITEM_GAP = 2;
@@ -2854,16 +2699,20 @@ function Shell({ appSlug, envLabel, plugins, apiBase, can, dock }) {
2854
2699
  panels,
2855
2700
  commands,
2856
2701
  apiRef: panelsRef,
2857
- children: [/* @__PURE__ */ jsx(dock === "rail" ? Rail : Pill, {
2858
- appSlug,
2859
- envLabel,
2860
- slots,
2861
- grab
2862
- }), /* @__PURE__ */ jsx(Grabber, {
2863
- app: appSlug,
2864
- store: grab,
2865
- slots
2866
- })]
2702
+ children: [
2703
+ /* @__PURE__ */ jsx(dock === "rail" ? Rail : Pill, {
2704
+ appSlug,
2705
+ envLabel,
2706
+ slots,
2707
+ grab
2708
+ }),
2709
+ slots.map((slot) => slot.plugin.overlay && /* @__PURE__ */ jsx(PluginOverlay, { slot }, slot.plugin.id)),
2710
+ /* @__PURE__ */ jsx(Grabber, {
2711
+ app: appSlug,
2712
+ store: grab,
2713
+ slots
2714
+ })
2715
+ ]
2867
2716
  });
2868
2717
  }
2869
2718
  //#endregion
@@ -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 };
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
  }
@@ -0,0 +1,176 @@
1
+ import "./marker-uZYPOJ4M.js";
2
+ import { createContext, useContext, useEffect, useState, useSyncExternalStore } from "react";
3
+ //#region src/shell/panels/panels-context.ts
4
+ const PanelsContext = createContext(null);
5
+ function usePanels() {
6
+ const api = useContext(PanelsContext);
7
+ if (!api) throw new Error("usePanels() used outside <PanelManager>");
8
+ return api;
9
+ }
10
+ //#endregion
11
+ //#region src/shell/pill/visual-viewport.ts
12
+ function subscribe(listener) {
13
+ const vv = window.visualViewport;
14
+ window.addEventListener("resize", listener);
15
+ vv?.addEventListener("resize", listener);
16
+ vv?.addEventListener("scroll", listener);
17
+ return () => {
18
+ window.removeEventListener("resize", listener);
19
+ vv?.removeEventListener("resize", listener);
20
+ vv?.removeEventListener("scroll", listener);
21
+ };
22
+ }
23
+ let cached = {
24
+ x: 0,
25
+ y: 0,
26
+ w: 0,
27
+ h: 0,
28
+ detached: false
29
+ };
30
+ /**
31
+ * On a phone, a page wider than the screen (an image with a fixed width is
32
+ * enough) grows the layout viewport past the visible area, and a pill fixed
33
+ * to the bottom edge ends up below the fold. The visual viewport is what the
34
+ * user sees; the pill places itself in it.
35
+ */
36
+ function read() {
37
+ const root = document.documentElement;
38
+ const layoutW = root.clientWidth || window.innerWidth;
39
+ const layoutH = root.clientHeight || window.innerHeight;
40
+ const vv = window.visualViewport;
41
+ const x = vv?.offsetLeft ?? 0;
42
+ const y = vv?.offsetTop ?? 0;
43
+ const w = Math.round(vv?.width ?? layoutW);
44
+ const h = Math.round(vv?.height ?? layoutH);
45
+ const detached = x !== 0 || y !== 0 || window.innerWidth > w + 1 || window.innerHeight > h + 1;
46
+ const next = {
47
+ x,
48
+ y,
49
+ w: detached ? w : layoutW,
50
+ h: detached ? h : layoutH,
51
+ detached
52
+ };
53
+ if (next.x !== cached.x || next.y !== cached.y || next.w !== cached.w || next.h !== cached.h || next.detached !== cached.detached) cached = next;
54
+ return cached;
55
+ }
56
+ function useVisualViewport() {
57
+ return useSyncExternalStore(subscribe, read, read);
58
+ }
59
+ //#endregion
60
+ //#region src/shell/pill/obstacles.ts
61
+ /** Fixed elements covering more than this share of the viewport are backdrops, not corners. */
62
+ const MAX_AREA_SHARE = .5;
63
+ /** DOM changes settle for this long before the page is scanned again. */
64
+ const RESCAN_MS = 250;
65
+ function isFloating(el) {
66
+ const { position } = getComputedStyle(el);
67
+ return position === "fixed" || position === "sticky";
68
+ }
69
+ /**
70
+ * The host page's fixed and sticky elements: what fights the pill for a
71
+ * corner. Nested ones are dropped since their floating ancestor already
72
+ * counts, and the HUD's own host is skipped.
73
+ */
74
+ function scanFloating(root = document.body) {
75
+ const found = [];
76
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, { acceptNode: (node) => {
77
+ const el = node;
78
+ if (el.localName === "hn-hud") return NodeFilter.FILTER_REJECT;
79
+ return isFloating(el) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
80
+ } });
81
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
82
+ const el = node;
83
+ if (!found.some((outer) => outer.contains(el))) found.push(el);
84
+ }
85
+ return found;
86
+ }
87
+ /** Visible rects of `elements`, minus backdrops and anything off screen. */
88
+ function obstacleRects(elements) {
89
+ const vw = window.innerWidth;
90
+ const vh = window.innerHeight;
91
+ const rects = [];
92
+ for (const el of elements) {
93
+ const { left, top, width, height } = el.getBoundingClientRect();
94
+ if (width === 0 || height === 0) continue;
95
+ if (width * height > vw * vh * MAX_AREA_SHARE) continue;
96
+ if (left >= vw || top >= vh || left + width <= 0 || top + height <= 0) continue;
97
+ const style = getComputedStyle(el);
98
+ if (style.visibility === "hidden" || style.opacity === "0") continue;
99
+ rects.push({
100
+ left,
101
+ top,
102
+ width,
103
+ height
104
+ });
105
+ }
106
+ return rects;
107
+ }
108
+ function sameRects(a, b) {
109
+ 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);
110
+ }
111
+ const NONE = [];
112
+ /** Obstacle rects moved into visible-area coordinates when the visual viewport is offset. */
113
+ function offsetObstacles(rects, offset) {
114
+ if (offset.x === 0 && offset.y === 0) return rects;
115
+ return rects.map((o) => ({
116
+ ...o,
117
+ left: o.left - offset.x,
118
+ top: o.top - offset.y
119
+ }));
120
+ }
121
+ /**
122
+ * Live obstacle rects. The element list is rescanned when the DOM settles
123
+ * after a change; rects are re-measured on scroll (sticky elements move) and
124
+ * resize, once per frame.
125
+ */
126
+ function useObstacles() {
127
+ const [rects, setRects] = useState(NONE);
128
+ useEffect(() => {
129
+ let elements = scanFloating();
130
+ let frame = 0;
131
+ let timer;
132
+ const measure = () => {
133
+ frame = 0;
134
+ const next = obstacleRects(elements);
135
+ setRects((prev) => sameRects(prev, next) ? prev : next);
136
+ };
137
+ const schedule = () => {
138
+ if (!frame) frame = requestAnimationFrame(measure);
139
+ };
140
+ const rescan = () => {
141
+ schedule();
142
+ clearTimeout(timer);
143
+ timer = setTimeout(() => {
144
+ elements = scanFloating();
145
+ schedule();
146
+ }, RESCAN_MS);
147
+ };
148
+ measure();
149
+ const observer = new MutationObserver(rescan);
150
+ observer.observe(document.body, {
151
+ childList: true,
152
+ subtree: true,
153
+ attributes: true,
154
+ attributeFilter: [
155
+ "class",
156
+ "style",
157
+ "hidden"
158
+ ]
159
+ });
160
+ window.addEventListener("scroll", schedule, {
161
+ capture: true,
162
+ passive: true
163
+ });
164
+ window.addEventListener("resize", schedule);
165
+ return () => {
166
+ observer.disconnect();
167
+ clearTimeout(timer);
168
+ if (frame) cancelAnimationFrame(frame);
169
+ window.removeEventListener("scroll", schedule, { capture: true });
170
+ window.removeEventListener("resize", schedule);
171
+ };
172
+ }, []);
173
+ return rects;
174
+ }
175
+ //#endregion
176
+ export { usePanels as a, PanelsContext as i, useObstacles as n, useVisualViewport as r, offsetObstacles as t };