nish-ui 3.1.0 → 3.3.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 (107) hide show
  1. package/README.md +13 -6
  2. package/dist/base-tailwind.css +30 -15
  3. package/dist/base.css +30 -15
  4. package/dist/chart.js +2 -2
  5. package/dist/elements-all.js +78 -78
  6. package/dist/elements-charts.d.ts +1 -1
  7. package/dist/elements-charts.js +43 -42
  8. package/dist/elements-data.d.ts +10 -0
  9. package/dist/elements-data.js +4 -5
  10. package/dist/elements-forms.js +9 -9
  11. package/dist/elements.d.ts +1 -0
  12. package/dist/elements.js +4 -4
  13. package/dist/esm/chart-values.js +2 -1
  14. package/dist/esm/combobox-filter.js +6 -5
  15. package/dist/esm/command-filter.js +83 -0
  16. package/dist/esm/components/accordion.js +5 -3
  17. package/dist/esm/components/app-shell.js +9 -5
  18. package/dist/esm/components/breadcrumbs.js +8 -4
  19. package/dist/esm/components/calendar-base.js +33 -6
  20. package/dist/esm/components/calendar-classes.js +14 -2
  21. package/dist/esm/components/canvas/follow-caption.js +31 -21
  22. package/dist/esm/components/canvas/follow.js +5 -6
  23. package/dist/esm/components/canvas/minimap.js +3 -3
  24. package/dist/esm/components/canvas/system-canvas.js +3 -1
  25. package/dist/esm/components/canvas/view.js +0 -2
  26. package/dist/esm/components/carousel.js +2 -3
  27. package/dist/esm/components/charts.js +18 -7
  28. package/dist/esm/components/combobox.js +20 -9
  29. package/dist/esm/components/command.js +25 -63
  30. package/dist/esm/components/context-menu.js +2 -1
  31. package/dist/esm/components/data-classes.js +23 -8
  32. package/dist/esm/components/data.js +19 -10
  33. package/dist/esm/components/display.js +24 -15
  34. package/dist/esm/components/drawer.js +17 -4
  35. package/dist/esm/components/error-boundary.js +3 -3
  36. package/dist/esm/components/feedback.js +4 -4
  37. package/dist/esm/components/file-dropzone.js +39 -7
  38. package/dist/esm/components/filters.js +42 -1
  39. package/dist/esm/components/flow.js +12 -9
  40. package/dist/esm/components/forms-classes.js +3 -1
  41. package/dist/esm/components/forms.js +8 -6
  42. package/dist/esm/components/hooks.js +47 -13
  43. package/dist/esm/components/hover-card.js +2 -1
  44. package/dist/esm/components/inbox.js +9 -2
  45. package/dist/esm/components/latest.js +4 -2
  46. package/dist/esm/components/layout.js +7 -4
  47. package/dist/esm/components/menu.js +14 -1
  48. package/dist/esm/components/modal.js +17 -4
  49. package/dist/esm/components/multi-select.js +7 -7
  50. package/dist/esm/components/nav-classes.js +9 -0
  51. package/dist/esm/components/nav.js +32 -12
  52. package/dist/esm/components/navigate.js +1 -1
  53. package/dist/esm/components/overlay-dialog.js +35 -1
  54. package/dist/esm/components/pagination.js +1 -1
  55. package/dist/esm/components/primitives-classes.js +4 -4
  56. package/dist/esm/components/primitives.js +18 -5
  57. package/dist/esm/components/progress.js +2 -1
  58. package/dist/esm/components/radio-group.js +1 -1
  59. package/dist/esm/components/resource-classes.js +7 -3
  60. package/dist/esm/components/resource.js +17 -6
  61. package/dist/esm/components/segmented.js +2 -0
  62. package/dist/esm/components/separator.js +6 -1
  63. package/dist/esm/components/service-tokens.js +18 -7
  64. package/dist/esm/components/settings.js +21 -1
  65. package/dist/esm/components/slider.js +5 -1
  66. package/dist/esm/components/split.js +4 -2
  67. package/dist/esm/components/strings.js +17 -4
  68. package/dist/esm/components/table.js +15 -3
  69. package/dist/esm/components/tabs.js +3 -2
  70. package/dist/esm/components/tag-input.js +5 -1
  71. package/dist/esm/components/time-field.js +15 -7
  72. package/dist/esm/components/toast-card.js +5 -3
  73. package/dist/esm/components/toast-store.js +16 -4
  74. package/dist/esm/components/toast.js +4 -1
  75. package/dist/esm/components/tooltip.js +3 -2
  76. package/dist/esm/components/url-state.js +5 -2
  77. package/dist/esm/components/virtual-table.js +2 -2
  78. package/dist/esm/components/virtual.js +8 -4
  79. package/dist/esm/format.js +27 -4
  80. package/dist/esm/runtime.js +9 -2
  81. package/dist/esm/server/inbox/client.js +4 -0
  82. package/dist/esm/split-layout.js +2 -1
  83. package/dist/esm/theme.js +38 -15
  84. package/dist/esm/tokens.mjs +1 -1
  85. package/dist/format.d.ts +5 -3
  86. package/dist/format.js +36 -7
  87. package/dist/inbox-client.d.ts +6 -2
  88. package/dist/inbox-client.js +4 -1
  89. package/dist/index.d.ts +65 -30
  90. package/dist/nish-components.css +70 -23
  91. package/dist/nish-components.min.css +1 -1
  92. package/dist/nish.css +30 -15
  93. package/dist/nish.min.css +1 -1
  94. package/dist/node/vite.js +1 -1
  95. package/dist/server/hono.d.ts +10 -3
  96. package/dist/server/hono.js +108 -11
  97. package/dist/server/index.d.ts +21 -13
  98. package/dist/server/index.js +124 -29
  99. package/dist/service-tokens.d.ts +4 -4
  100. package/dist/{spa-7myD4xvA.d.ts → spa-FwS7yZ8p.d.ts} +36 -7
  101. package/dist/split-layout.js +2 -2
  102. package/dist/system-canvas.d.ts +11 -10
  103. package/dist/theme.d.ts +30 -2
  104. package/dist/theme.global.js +53 -21
  105. package/dist/theme.js +53 -20
  106. package/package.json +3 -2
  107. package/dist/tokens.js +0 -425
@@ -9,11 +9,12 @@ import {
9
9
  } from "react";
10
10
  import { cn } from "../cn.js";
11
11
  import { mergeRefs } from "./data-classes.js";
12
- import { FORCED_MARK } from "./display-classes.js";
12
+ import { FORCED_MARK, warnDev } from "./display-classes.js";
13
13
  import { chipClass } from "./forms.js";
14
14
  import { useMediaQuery } from "./hooks.js";
15
15
  import { PanelLeftCloseIcon, PanelLeftOpenIcon } from "./icons.js";
16
16
  import { useHeightVar, useScrollEdges } from "./layout-vars.js";
17
+ import { navRailItemClass } from "./nav-classes.js";
17
18
  import { NavBadge, FOCUS, renderItem, useEndSide, visibleNavItems } from "./nav-items.js";
18
19
  import { IconButton } from "./primitives.js";
19
20
  import { useStrings } from "./provider.js";
@@ -127,7 +128,7 @@ function NavRail({
127
128
  ref: mergeRefs(ref, refProp),
128
129
  "aria-label": label ?? strings.sections,
129
130
  className: cn(
130
- "hidden w-[72px] shrink-0 flex-col items-center gap-1 border-e border-th-line bg-th-surface py-3 pl-[env(safe-area-inset-left)]",
131
+ "hidden w-[72px] shrink-0 flex-col items-center gap-1 border-e border-th-line bg-th-surface py-3 ltr:pl-[env(safe-area-inset-left)] rtl:pr-[env(safe-area-inset-right)]",
131
132
  RAIL_SHOW[showFrom],
132
133
  hideFrom ? RAIL_HIDE[hideFrom] : null,
133
134
  className
@@ -136,7 +137,7 @@ function NavRail({
136
137
  shown.map((item) => {
137
138
  const node = renderItem(
138
139
  item,
139
- cn("group flex min-h-14 w-full flex-col items-center justify-center gap-0.5 text-2xs leading-tight", FOCUS, item.active ? "font-medium text-th-accent" : "text-th-hi3 hover:text-th-hi"),
140
+ navRailItemClass(!!item.active),
140
141
  /* @__PURE__ */ jsxs(Fragment2, { children: [
141
142
  /* @__PURE__ */ jsxs(
142
143
  "span",
@@ -192,7 +193,7 @@ function NavSidebar({
192
193
  ref: mergeRefs(ref, refProp),
193
194
  "data-state": collapsed ? "closed" : "open",
194
195
  className: cn(
195
- "flex h-full shrink-0 flex-col border-e border-th-line bg-th-surface py-3 pl-[env(safe-area-inset-left)] transition-[width] duration-200 motion-reduce:transition-none",
196
+ "flex h-full shrink-0 flex-col border-e border-th-line bg-th-surface py-3 ltr:pl-[env(safe-area-inset-left)] rtl:pr-[env(safe-area-inset-right)] transition-[width] duration-200 motion-reduce:transition-none",
196
197
  collapsed ? "w-16" : "w-56",
197
198
  className
198
199
  ),
@@ -275,6 +276,7 @@ function ScrollRow({
275
276
  }
276
277
  );
277
278
  }
279
+ var SCROLL_SPY_GIVE_UP_MS = 1e4;
278
280
  function useScrollSpy(ids, { rootMargin = "-45% 0px -50% 0px" } = {}) {
279
281
  const [active, setActive] = useState(ids[0] ?? null);
280
282
  const key = ids.join("\0");
@@ -309,6 +311,15 @@ function useScrollSpy(ids, { rootMargin = "-45% 0px -50% 0px" } = {}) {
309
311
  );
310
312
  const seen = /* @__PURE__ */ new Set();
311
313
  let mo = null;
314
+ let frame = 0;
315
+ let giveUp;
316
+ const stopLooking = () => {
317
+ mo?.disconnect();
318
+ mo = null;
319
+ clearTimeout(giveUp);
320
+ if (frame) cancelAnimationFrame(frame);
321
+ frame = 0;
322
+ };
312
323
  const attach = () => {
313
324
  for (const id of list) {
314
325
  if (seen.has(id)) continue;
@@ -318,15 +329,23 @@ function useScrollSpy(ids, { rootMargin = "-45% 0px -50% 0px" } = {}) {
318
329
  io.observe(el);
319
330
  }
320
331
  }
321
- if (seen.size === list.length && mo) {
322
- mo.disconnect();
323
- mo = null;
324
- }
332
+ if (seen.size === list.length) stopLooking();
325
333
  };
326
334
  attach();
327
335
  if (seen.size < list.length && typeof MutationObserver !== "undefined") {
328
- mo = new MutationObserver(attach);
336
+ mo = new MutationObserver(() => {
337
+ if (frame) return;
338
+ frame = requestAnimationFrame(() => {
339
+ frame = 0;
340
+ attach();
341
+ });
342
+ });
329
343
  mo.observe(document.body, { childList: true, subtree: true });
344
+ giveUp = setTimeout(() => {
345
+ const missing = list.filter((id) => !seen.has(id));
346
+ stopLooking();
347
+ if (missing.length) warnDev(`useScrollSpy: no element with id ${missing.map((id) => `"${id}"`).join(", ")} appeared, so it is not tracked.`);
348
+ }, SCROLL_SPY_GIVE_UP_MS);
330
349
  }
331
350
  const onScroll = () => {
332
351
  if (window.scrollY < 8) setActive(list[0]);
@@ -334,7 +353,7 @@ function useScrollSpy(ids, { rootMargin = "-45% 0px -50% 0px" } = {}) {
334
353
  window.addEventListener("scroll", onScroll, { passive: true });
335
354
  return () => {
336
355
  io.disconnect();
337
- mo?.disconnect();
356
+ stopLooking();
338
357
  window.removeEventListener("scroll", onScroll);
339
358
  };
340
359
  }, [key, rootMargin]);
@@ -345,12 +364,13 @@ function SectionNav({
345
364
  sticky = true,
346
365
  onSelect,
347
366
  updateHash = true,
348
- label = "On this page",
367
+ label,
349
368
  className,
350
369
  style,
351
370
  ref: refProp,
352
371
  ...rest
353
372
  }) {
373
+ const strings = useStrings(SHELL_STRINGS);
354
374
  const ref = useRef(null);
355
375
  const spy = useScrollSpy(items.map((i) => i.id));
356
376
  const [locked, setLocked] = useState(null);
@@ -412,7 +432,7 @@ function SectionNav({
412
432
  {
413
433
  ...rest,
414
434
  ref: mergeRefs(ref, refProp),
415
- "aria-label": label,
435
+ "aria-label": label ?? strings.onThisPage,
416
436
  "data-nish-bar": sticky ? "" : void 0,
417
437
  style: sticky ? { top: "var(--nish-header-h, 0px)", ...style } : style,
418
438
  className: cn("z-[var(--nish-z-sticky,20)] border-b border-th-line bg-th-bg py-2", sticky && "sticky", className),
@@ -3,7 +3,7 @@ import { safeUrl } from "../url.js";
3
3
  import { whenHistorySettled } from "./overlay-core.js";
4
4
  function warnUnsafe(href) {
5
5
  try {
6
- if (process.env.NODE_ENV !== "production") console.warn(`CommandPalette: ignored an unsafe href (${href.slice(0, 40)}).`);
6
+ if (process.env.NODE_ENV !== "production") console.warn(`nish-ui: ignored an unsafe href (${href.slice(0, 40)}).`);
7
7
  } catch {
8
8
  }
9
9
  }
@@ -7,8 +7,27 @@ import { useLatest } from "./latest.js";
7
7
  import { useStrings } from "./provider.js";
8
8
  import { OVERLAY_STRINGS } from "./strings.js";
9
9
  import { SHEET_EXIT_MS } from "./overlay-classes.js";
10
+ import { URL_STATE_EVENT } from "./url-state.js";
10
11
  import { ov, isTop, syncLayerAttr, pushInert, popInert, acquireGuard, releaseGuard, prefersReducedMotion, closeVetoes, focusables, lockScroll, queueHistoryPush, cancelHistoryPush } from "./overlay-core.js";
11
12
  import { jsx } from "react/jsx-runtime";
13
+ function carryUrl(from, to) {
14
+ if (!from || to === from) return;
15
+ let a;
16
+ let b;
17
+ try {
18
+ a = new URL(from);
19
+ b = new URL(to);
20
+ } catch {
21
+ return;
22
+ }
23
+ if (a.origin !== b.origin || a.pathname !== b.pathname || location.href !== from) return;
24
+ try {
25
+ history.replaceState(history.state, "", b.pathname + b.search + b.hash);
26
+ } catch {
27
+ return;
28
+ }
29
+ window.dispatchEvent(new Event(URL_STATE_EVENT));
30
+ }
12
31
  function useDialog(panelRef, onClose, closeOnBackProp = false) {
13
32
  const closeOnBack = closeOnBackProp && (typeof window === "undefined" || window.self === window.top);
14
33
  const onCloseRef = useLatest(onClose);
@@ -25,11 +44,17 @@ function useDialog(panelRef, onClose, closeOnBackProp = false) {
25
44
  const layerId = `nish-layer-${++s.layerSeq}`;
26
45
  let pushed = false;
27
46
  let rePushTimer = 0;
47
+ let pushedUrl = "";
48
+ let layerUrl = "";
28
49
  const pushEntry = () => {
29
50
  const prev = history.state && typeof history.state === "object" ? history.state : {};
30
51
  history.pushState({ ...prev, nishLayer: layerId }, "");
31
52
  pushed = true;
53
+ pushedUrl = layerUrl = location.href;
32
54
  };
55
+ function onUrlState() {
56
+ if (pushed && history.state?.nishLayer === layerId) layerUrl = location.href;
57
+ }
33
58
  const queuedPush = () => queueHistoryPush(pushEntry);
34
59
  if (closeOnBack) acquireGuard();
35
60
  const pushTimer = closeOnBack ? window.setTimeout(queuedPush, 0) : 0;
@@ -37,6 +62,7 @@ function useDialog(panelRef, onClose, closeOnBackProp = false) {
37
62
  if (!pushed) return;
38
63
  if (history.state?.nishLayer === layerId) return;
39
64
  pushed = false;
65
+ carryUrl(pushedUrl, layerUrl);
40
66
  if (!isTop(self)) {
41
67
  pushEntry();
42
68
  return;
@@ -47,7 +73,10 @@ function useDialog(panelRef, onClose, closeOnBackProp = false) {
47
73
  if (!pushed) queuedPush();
48
74
  }, SHEET_EXIT_MS + 60);
49
75
  }
50
- if (closeOnBack) window.addEventListener("popstate", onPop);
76
+ if (closeOnBack) {
77
+ window.addEventListener("popstate", onPop);
78
+ window.addEventListener(URL_STATE_EVENT, onUrlState);
79
+ }
51
80
  const focusTimer = window.setTimeout(() => {
52
81
  if (panel && !panel.contains(document.activeElement)) {
53
82
  (panel.querySelector("[data-autofocus],[autofocus]") ?? panel).focus();
@@ -88,6 +117,7 @@ function useDialog(panelRef, onClose, closeOnBackProp = false) {
88
117
  window.clearTimeout(rePushTimer);
89
118
  cancelHistoryPush(pushEntry);
90
119
  window.removeEventListener("popstate", onPop);
120
+ window.removeEventListener(URL_STATE_EVENT, onUrlState);
91
121
  const at = s.layerStack.indexOf(self);
92
122
  if (at >= 0) s.layerStack.splice(at, 1);
93
123
  s.dialogCount--;
@@ -97,8 +127,11 @@ function useDialog(panelRef, onClose, closeOnBackProp = false) {
97
127
  unlock();
98
128
  opener?.focus?.();
99
129
  if (pushed && history.state?.nishLayer === layerId) {
130
+ const from = pushedUrl;
131
+ const to = location.href;
100
132
  s.pendingBacks++;
101
133
  history.back();
134
+ if (to !== from) queueHistoryPush(() => carryUrl(from, to));
102
135
  }
103
136
  if (closeOnBack) releaseGuard();
104
137
  };
@@ -265,6 +298,7 @@ function SheetHandle({ onClose, swipe, className }) {
265
298
  }
266
299
  export {
267
300
  SheetHandle,
301
+ carryUrl,
268
302
  useDialog,
269
303
  useSheetExit,
270
304
  useSheetSwipe
@@ -144,7 +144,7 @@ function Pagination({
144
144
  className: cn("w-full min-w-0", className),
145
145
  children: /* @__PURE__ */ jsxs("ul", { className: cn("flex flex-wrap items-center gap-1", compact && "justify-between"), children: [
146
146
  prev,
147
- compact ? /* @__PURE__ */ jsx("li", { className: "px-2 text-sm tabular-nums text-th-hi2", children: (compactLabel ?? ((p, c) => `${strings.pageLabel(p)} of ${c}`))(page, count) }) : paginationRange(page, count, siblings, boundaries).map(
147
+ compact ? /* @__PURE__ */ jsx("li", { className: "px-2 text-sm tabular-nums text-th-hi2", children: (compactLabel ?? strings.pageOfCount)(page, count) }) : paginationRange(page, count, siblings, boundaries).map(
148
148
  (slot) => typeof slot === "number" ? control(slot, pageName(slot), slot === page, disabled, slot, `p${slot}`) : /* @__PURE__ */ jsx("li", { "aria-hidden": "true", className: cn("inline-flex items-center justify-center text-th-hi3", "min-w-6", SIZE[size].split(" ")[0]), children: "\u2026" }, slot)
149
149
  ),
150
150
  next
@@ -10,9 +10,9 @@ var BUTTON_VARIANT = {
10
10
  link: "h-auto p-0 font-medium text-th-accent underline-offset-2 hover:underline"
11
11
  };
12
12
  var BUTTON_SIZE = {
13
- xs: "h-6 gap-1 px-2 text-2xs pointer-coarse:min-h-11",
14
- sm: "h-7 gap-1.5 px-2.5 text-xs pointer-coarse:min-h-11",
15
- md: "h-9 gap-2 px-3.5 text-sm pointer-coarse:min-h-11",
13
+ xs: "h-6 gap-1 px-2 text-2xs pointer-coarse:min-h-11 pointer-coarse:min-w-11",
14
+ sm: "h-7 gap-1.5 px-2.5 text-xs pointer-coarse:min-h-11 pointer-coarse:min-w-11",
15
+ md: "h-9 gap-2 px-3.5 text-sm pointer-coarse:min-h-11 pointer-coarse:min-w-11",
16
16
  lg: "h-11 gap-2 px-5 text-base"
17
17
  };
18
18
  var LINK_SIZE = {
@@ -24,7 +24,7 @@ var LINK_SIZE = {
24
24
  var BUTTON_BASE = "inline-flex shrink-0 select-none items-center justify-center whitespace-nowrap rounded-lg font-medium transition-[color,background-color,border-color,transform] duration-150";
25
25
  var BUTTON_FORCED = "forced-colors:border forced-colors:border-[ButtonText]";
26
26
  var PRESS = "pointer-coarse:not-disabled:active:scale-[0.97]";
27
- var LINK_HIT = "pointer-coarse:relative pointer-coarse:after:absolute pointer-coarse:after:-inset-x-2 pointer-coarse:after:-inset-y-3 pointer-coarse:after:content-['']";
27
+ var LINK_HIT = "pointer-coarse:relative pointer-coarse:after:absolute pointer-coarse:after:-inset-x-2 pointer-coarse:after:-inset-y-3.5 pointer-coarse:after:content-['']";
28
28
  var BUTTON_DISABLED = "disabled:pointer-events-none disabled:border disabled:border-th-line disabled:bg-th-elevated disabled:text-th-ghost disabled:shadow-none forced-colors:disabled:border-[GrayText] forced-colors:disabled:text-[GrayText]";
29
29
  var LINK_DISABLED = "disabled:pointer-events-none disabled:text-th-ghost disabled:no-underline forced-colors:disabled:text-[GrayText]";
30
30
  function buttonClass({ variant = "secondary", size = "md", inline = false, className } = {}) {
@@ -50,21 +50,32 @@ function Button({
50
50
  ...rest
51
51
  }) {
52
52
  const off = !!disabled || loading;
53
+ const softOff = loading && !disabled;
54
+ const { onClick, ...restProps } = rest;
53
55
  return /* @__PURE__ */ jsxs(
54
56
  "button",
55
57
  {
56
58
  ref,
57
59
  type,
58
- disabled: off,
60
+ disabled: !!disabled,
61
+ "aria-disabled": softOff ? true : void 0,
59
62
  "aria-busy": loading || void 0,
60
63
  "data-disabled": off ? "" : void 0,
64
+ onClick: softOff ? (e) => {
65
+ e.preventDefault();
66
+ e.stopPropagation();
67
+ } : onClick,
61
68
  className: buttonClass({
62
69
  variant,
63
70
  size,
64
71
  inline,
65
- className: cn(variant === "link" ? LINK_DISABLED : BUTTON_DISABLED, className)
72
+ className: cn(
73
+ variant === "link" ? LINK_DISABLED : BUTTON_DISABLED,
74
+ softOff && (variant === "link" ? "pointer-events-none text-th-ghost no-underline forced-colors:text-[GrayText]" : "pointer-events-none border border-th-line bg-th-elevated text-th-ghost shadow-none forced-colors:border-[GrayText] forced-colors:text-[GrayText]"),
75
+ className
76
+ )
66
77
  }),
67
- ...rest,
78
+ ...restProps,
68
79
  children: [
69
80
  loading ? /* @__PURE__ */ jsx(
70
81
  LoaderIcon,
@@ -104,7 +115,7 @@ function IconButton({
104
115
  disabled,
105
116
  "aria-label": label,
106
117
  title: label,
107
- "aria-pressed": pressed || void 0,
118
+ "aria-pressed": active === void 0 ? void 0 : pressed,
108
119
  "data-state": active === void 0 ? void 0 : pressed ? "active" : "inactive",
109
120
  "data-disabled": disabled ? "" : void 0,
110
121
  className: iconButtonClass({ size, variant, tone, active: pressed, className }),
@@ -143,7 +154,7 @@ function CardHeader({
143
154
  description ? /* @__PURE__ */ jsx("p", { className: "mt-0.5 text-xs text-th-hi3", children: description }) : null
144
155
  ] })
145
156
  ] }),
146
- action ? /* @__PURE__ */ jsx("div", { className: "flex shrink-0 flex-wrap items-center gap-2", children: action }) : null
157
+ action ? /* @__PURE__ */ jsx("div", { className: "flex min-w-0 max-w-full flex-wrap items-center gap-2", children: action }) : null
147
158
  ]
148
159
  }
149
160
  );
@@ -155,6 +166,7 @@ function Card({
155
166
  interactive = false,
156
167
  variant = "surface",
157
168
  title,
169
+ titleAs,
158
170
  description,
159
171
  action,
160
172
  className,
@@ -178,6 +190,7 @@ function Card({
178
190
  CardHeader,
179
191
  {
180
192
  title,
193
+ as: titleAs,
181
194
  description,
182
195
  action,
183
196
  titleId: headingId,
@@ -66,7 +66,8 @@ function Progress({
66
66
  "absolute inset-y-0 start-0 rounded-full transition-[width] duration-300 ease-out motion-reduce:transition-none",
67
67
  FILL[tone],
68
68
  "forced-color-adjust-none forced-colors:bg-[Highlight]",
69
- indeterminate && "motion-safe:animate-pulse"
69
+ // Pulses while motion is allowed; under reduced motion and forced colors it is a short bar, never a full one that reads as complete.
70
+ indeterminate && "motion-safe:animate-pulse motion-reduce:!w-2/5 forced-colors:!w-2/5"
70
71
  ),
71
72
  style: { width: `${pct}%` }
72
73
  }
@@ -148,7 +148,7 @@ function Radio({ value, label, description, className, disabled, required, name,
148
148
  name: name ?? ctx?.name,
149
149
  disabled: off,
150
150
  required: required ?? ctx?.required,
151
- "aria-describedby": description != null ? descId : rest["aria-describedby"],
151
+ "aria-describedby": [description != null ? descId : null, rest["aria-describedby"]].filter(Boolean).join(" ") || void 0,
152
152
  onChange: (e) => {
153
153
  onChange?.(e);
154
154
  if (e.target.checked) ctx?.select(value);
@@ -23,7 +23,7 @@ function configureApi(c) {
23
23
  store.config = { ...store.config, ...c };
24
24
  }
25
25
  function isRawBody(b) {
26
- return typeof b === "string" || typeof FormData !== "undefined" && b instanceof FormData || typeof Blob !== "undefined" && b instanceof Blob || typeof URLSearchParams !== "undefined" && b instanceof URLSearchParams || b instanceof ArrayBuffer || ArrayBuffer.isView(b);
26
+ return typeof b === "string" || typeof FormData !== "undefined" && b instanceof FormData || typeof Blob !== "undefined" && b instanceof Blob || typeof URLSearchParams !== "undefined" && b instanceof URLSearchParams || typeof ReadableStream !== "undefined" && b instanceof ReadableStream || b instanceof ArrayBuffer || ArrayBuffer.isView(b);
27
27
  }
28
28
  var ERROR_CODE = /^[a-z0-9_]+$/;
29
29
  function errorMessage(body, status) {
@@ -84,8 +84,12 @@ async function apiFetch(path, o = {}) {
84
84
  if (extraHeaders) new Headers(extraHeaders).forEach((v, k) => headers.set(k, v));
85
85
  let payload;
86
86
  if (body !== void 0) {
87
- if (isRawBody(body)) payload = body;
88
- else {
87
+ if (isRawBody(body)) {
88
+ payload = body;
89
+ if (typeof ReadableStream !== "undefined" && body instanceof ReadableStream && !("duplex" in init)) {
90
+ init.duplex = "half";
91
+ }
92
+ } else {
89
93
  payload = JSON.stringify(body);
90
94
  if (!headers.has("content-type")) headers.set("content-type", "application/json");
91
95
  }
@@ -7,6 +7,7 @@ import { apiFetch } from "./resource-classes.js";
7
7
  import { ApiError, apiFetch as apiFetch2, configureApi } from "./resource-classes.js";
8
8
  var MAX_BACKOFF_MS = 3e5;
9
9
  var inflight = /* @__PURE__ */ new Map();
10
+ var clock = 0;
10
11
  function sharedFetch(key, fetcher, signal) {
11
12
  let entry = inflight.get(key);
12
13
  if (!entry || entry.fetcher !== fetcher) {
@@ -15,6 +16,7 @@ function sharedFetch(key, fetcher, signal) {
15
16
  fetcher,
16
17
  ctl,
17
18
  refs: 0,
19
+ seq: ++clock,
18
20
  promise: fetcher ? fetcher(ctl.signal) : apiFetch(key, { signal: ctl.signal })
19
21
  };
20
22
  const forget = () => {
@@ -70,6 +72,7 @@ function useResource(key, fetcher, o = {}) {
70
72
  }));
71
73
  const fetcherRef = useLatest(fetcher);
72
74
  const keyRef = useLatest(key);
75
+ const activeRef = useLatest(active);
73
76
  const keepPrevRef = useLatest(keepPrevious);
74
77
  const initialRef = useLatest(o.initialData);
75
78
  const ctlRef = useRef(null);
@@ -81,12 +84,12 @@ function useResource(key, fetcher, o = {}) {
81
84
  const load = useCallback(
82
85
  async (fresh = false) => {
83
86
  const k = keyRef.current;
84
- if (k === null) return;
87
+ if (k === null || !activeRef.current) return;
85
88
  ctlRef.current?.abort();
86
89
  const ctl = new AbortController();
87
90
  ctlRef.current = ctl;
88
91
  const run = ++runRef.current;
89
- const mutatedAtStart = mutatedRef.current;
92
+ let startedAt = 0;
90
93
  pollSkippedRef.current = false;
91
94
  setState(
92
95
  (s) => s.key === k ? { ...s, fetching: true } : {
@@ -101,10 +104,18 @@ function useResource(key, fetcher, o = {}) {
101
104
  );
102
105
  try {
103
106
  const fn = fetcherRef.current;
104
- const data2 = await (fresh ? fn ? fn(ctl.signal) : apiFetch(k, { signal: ctl.signal }) : sharedFetch(k, fn, ctl.signal));
107
+ let pending;
108
+ if (fresh) {
109
+ startedAt = ++clock;
110
+ pending = fn ? fn(ctl.signal) : apiFetch(k, { signal: ctl.signal });
111
+ } else {
112
+ pending = sharedFetch(k, fn, ctl.signal);
113
+ startedAt = inflight.get(k)?.seq ?? ++clock;
114
+ }
115
+ const data2 = await pending;
105
116
  if (run !== runRef.current || ctl.signal.aborted) return;
106
117
  failuresRef.current = 0;
107
- if (mutatedRef.current !== mutatedAtStart) {
118
+ if (mutatedRef.current > startedAt) {
108
119
  setState((s) => ({ ...s, key: k, error: void 0, fetching: false, settled: s.settled + 1, loaded: true }));
109
120
  return;
110
121
  }
@@ -116,7 +127,7 @@ function useResource(key, fetcher, o = {}) {
116
127
  setState((s) => ({ ...s, key: k, error: error2, fetching: false, settled: s.settled + 1 }));
117
128
  }
118
129
  },
119
- [fetcherRef, initialRef, keepPrevRef, keyRef]
130
+ [activeRef, fetcherRef, initialRef, keepPrevRef, keyRef]
120
131
  );
121
132
  useEffect(() => {
122
133
  if (!active) return;
@@ -180,7 +191,7 @@ function useResource(key, fetcher, o = {}) {
180
191
  return () => clearInterval(id);
181
192
  }, [intervalMs, updatedAt]);
182
193
  const mutate = useCallback((next) => {
183
- mutatedRef.current++;
194
+ mutatedRef.current = ++clock;
184
195
  setState((s) => ({
185
196
  ...s,
186
197
  data: typeof next === "function" ? next(s.data) : next
@@ -92,6 +92,8 @@ function Segmented({
92
92
  const from = refs.current.findIndex((el) => el === document.activeElement);
93
93
  const at = from >= 0 ? from : selected;
94
94
  if (e.key === "Escape" && tipAt != null) {
95
+ e.preventDefault();
96
+ e.stopPropagation();
95
97
  setTipAt(null);
96
98
  return;
97
99
  }
@@ -1,8 +1,12 @@
1
+ "use client";
2
+
1
3
  // src/components/separator.tsx
4
+ import { useId } from "react";
2
5
  import { cn } from "../cn.js";
3
6
  import { jsx, jsxs } from "react/jsx-runtime";
4
7
  var LINE = "bg-th-line forced-colors:bg-[CanvasText]";
5
8
  function Separator({ orientation = "horizontal", decorative = true, label, className, ref, ...rest }) {
9
+ const labelId = useId();
6
10
  const a11y = decorative ? { role: "none" } : { role: "separator", "aria-orientation": orientation };
7
11
  const hasLabel = label != null && label !== false && label !== "" && orientation === "horizontal";
8
12
  if (hasLabel) {
@@ -11,12 +15,13 @@ function Separator({ orientation = "horizontal", decorative = true, label, class
11
15
  {
12
16
  "data-orientation": orientation,
13
17
  ...a11y,
18
+ ...!decorative && rest["aria-label"] === void 0 && rest["aria-labelledby"] === void 0 ? { "aria-labelledby": labelId } : {},
14
19
  ...rest,
15
20
  ref,
16
21
  className: cn("flex w-full items-center gap-3 text-xs text-th-hi3", className),
17
22
  children: [
18
23
  /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: cn("h-px flex-1", LINE) }),
19
- /* @__PURE__ */ jsx("span", { className: "shrink-0", children: label }),
24
+ /* @__PURE__ */ jsx("span", { id: labelId, className: "shrink-0", children: label }),
20
25
  /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: cn("h-px flex-1", LINE) })
21
26
  ]
22
27
  }
@@ -25,18 +25,26 @@ function useServiceTokens(url = "/api/service-tokens") {
25
25
  );
26
26
  const [loading, setLoading] = useState(true);
27
27
  const [error, setError] = useState(null);
28
+ const [ownerUrl, setOwnerUrl] = useState(url);
28
29
  const [nonce, setNonce] = useState(0);
29
30
  const seq = useRef(0);
31
+ const ownerRef = useRef(url);
30
32
  useEffect(() => {
31
33
  const mine = ++seq.current;
32
34
  const ctl = new AbortController();
33
35
  apiFetch(url, { signal: ctl.signal }).then((r) => {
34
36
  if (seq.current !== mine) return;
37
+ ownerRef.current = url;
38
+ setOwnerUrl(url);
35
39
  setTokens(r.tokens);
40
+ setError(null);
36
41
  setLoading(false);
37
42
  }).catch((e) => {
38
43
  if (seq.current !== mine || e instanceof Error && e.name === "AbortError")
39
44
  return;
45
+ if (ownerRef.current !== url) setTokens(void 0);
46
+ ownerRef.current = url;
47
+ setOwnerUrl(url);
40
48
  setError(e instanceof Error ? e.message : strings.failedToLoad);
41
49
  setLoading(false);
42
50
  });
@@ -55,12 +63,15 @@ function useServiceTokens(url = "/api/service-tokens") {
55
63
  { method: "POST", body: {} }
56
64
  );
57
65
  seq.current++;
66
+ ownerRef.current = url;
67
+ setOwnerUrl(url);
58
68
  setTokens(r.tokens);
59
69
  setError(null);
60
70
  setLoading(false);
61
71
  },
62
72
  [url]
63
73
  );
74
+ if (ownerUrl !== url) return { tokens: void 0, loading: true, error: null, reload, revoke };
64
75
  return { tokens, loading, error, reload, revoke };
65
76
  }
66
77
  function when(raw) {
@@ -83,10 +94,10 @@ function ServiceTokensSection({
83
94
  description: descriptionProp,
84
95
  id = "service-tokens",
85
96
  className,
86
- emptyMessage = "No service tokens. No machine client can read this app.",
97
+ emptyMessage,
87
98
  revokeBody,
88
- createdLabel = (when2) => `created ${when2}`,
89
- envSourceLabel = "from SERVICE_TOKENS",
99
+ createdLabel,
100
+ envSourceLabel,
90
101
  ...rest
91
102
  }) {
92
103
  const strings = useStrings(TOKEN_STRINGS, STATUS_STRINGS, ERROR_STRINGS, OVERLAY_STRINGS);
@@ -148,12 +159,12 @@ function ServiceTokensSection({
148
159
  } else if (sorted.length === 0) {
149
160
  content = /* @__PURE__ */ jsxs(Fragment, { children: [
150
161
  errorRow,
151
- /* @__PURE__ */ jsx("p", { className: "px-4 py-6 text-sm text-th-hi3", children: emptyMessage })
162
+ /* @__PURE__ */ jsx("p", { className: "px-4 py-6 text-sm text-th-hi3", children: emptyMessage ?? strings.tokenEmpty })
152
163
  ] });
153
164
  } else {
154
165
  const rows = sorted.map((t) => {
155
- const parts = [t.id, t.scopes.join(", "), createdLabel(when(t.created))];
156
- if (t.source === "env") parts.push(envSourceLabel);
166
+ const parts = [t.id, t.scopes.join(", "), (createdLabel ?? strings.tokenCreated)(when(t.created))];
167
+ if (t.source === "env") parts.push(envSourceLabel ?? strings.tokenFromEnv);
157
168
  return /* @__PURE__ */ jsx(
158
169
  SettingRow,
159
170
  {
@@ -203,7 +214,7 @@ function ServiceTokensSection({
203
214
  {
204
215
  title: strings.tokenRevokeTitle(target.name),
205
216
  body: /* @__PURE__ */ jsxs(Fragment, { children: [
206
- revokeBody ?? /* @__PURE__ */ jsx("p", { children: 'Anything using this token gets "Unauthorized" from now on. This cannot be undone: to restore access, issue a new token with npm run tokens in nishant/mcp.' }),
217
+ revokeBody ?? /* @__PURE__ */ jsx("p", { children: strings.tokenRevokeBody }),
207
218
  failure ? /* @__PURE__ */ jsx("p", { role: "alert", className: "mt-3 text-th-loss", children: failure }) : null
208
219
  ] }),
209
220
  confirmLabel: strings.tokenRevoke,
@@ -52,6 +52,21 @@ function SettingRow({
52
52
  const auto = useId();
53
53
  const labelId = `${auto}-label`;
54
54
  const descId = `${auto}-desc`;
55
+ const controlRef = useRef(null);
56
+ const hasDescription = description != null;
57
+ useEffect(() => {
58
+ if (!htmlFor || !hasDescription) return;
59
+ const el = controlRef.current?.ownerDocument.getElementById(htmlFor);
60
+ if (!el) return;
61
+ const had = (el.getAttribute("aria-describedby") ?? "").split(/\s+/).filter(Boolean);
62
+ if (had.includes(descId)) return;
63
+ el.setAttribute("aria-describedby", [...had, descId].join(" "));
64
+ return () => {
65
+ const now = (el.getAttribute("aria-describedby") ?? "").split(/\s+/).filter((t) => t && t !== descId);
66
+ if (now.length) el.setAttribute("aria-describedby", now.join(" "));
67
+ else el.removeAttribute("aria-describedby");
68
+ };
69
+ }, [htmlFor, hasDescription, descId]);
55
70
  const side = inline || compact && !stacked;
56
71
  const layout = stacked ? "flex flex-col gap-2" : side ? "grid grid-cols-[1fr_auto] items-center gap-4" : "flex flex-col gap-2 sm:grid sm:grid-cols-[1fr_auto] sm:items-center sm:gap-4";
57
72
  return /* @__PURE__ */ jsxs(
@@ -68,6 +83,7 @@ function SettingRow({
68
83
  /* @__PURE__ */ jsxs(
69
84
  "div",
70
85
  {
86
+ ref: controlRef,
71
87
  ...htmlFor ? {} : { role: "group", "aria-labelledby": labelId, "aria-describedby": description != null ? descId : void 0 },
72
88
  className: cn("flex min-w-0 items-center gap-2", stacked ? "w-full" : side ? "justify-end" : "w-full sm:w-auto sm:justify-end"),
73
89
  children: [
@@ -124,7 +140,11 @@ function useSaveStatus() {
124
140
  const tone = status === "saved" ? "ok" : status === "error" ? "error" : "muted";
125
141
  return { status, error, label, tone, run };
126
142
  }
127
- var parseDraft = (text) => Number(text.trim().replace(/,/g, "").replace(/\u2212/g, "-"));
143
+ var parseDraft = (text) => {
144
+ const t = text.trim().replace(/,/g, "").replace(/\u2212/g, "-");
145
+ const n = /^-?(?:\d+(?:\.\d*)?|\.\d+)$/.test(t) ? Number(t) : NaN;
146
+ return Number.isFinite(n) ? n : NaN;
147
+ };
128
148
  var fmt = (v) => v == null ? "" : String(v);
129
149
  var decimals = (n) => String(n).split(".")[1]?.length ?? 0;
130
150
  function NumberField({
@@ -119,7 +119,11 @@ function Slider({
119
119
  const cur = live.current;
120
120
  let i = 0;
121
121
  if (cur.length === 2) {
122
- if (v <= cur[0]) i = 0;
122
+ if (cur[0] === cur[1]) {
123
+ if (cur[0] === min) i = 1;
124
+ else if (cur[1] === max) i = 0;
125
+ else i = v >= cur[0] ? 1 : 0;
126
+ } else if (v <= cur[0]) i = 0;
123
127
  else if (v >= cur[1]) i = 1;
124
128
  else i = v - cur[0] <= cur[1] - v ? 0 : 1;
125
129
  }
@@ -84,7 +84,8 @@ function SplitDividers({ layout, w, h, gap, onResize, onDragChange, minPane, bar
84
84
  };
85
85
  const fraction = (d) => {
86
86
  const node = nodeAt(layout, d.path);
87
- return node && node.type === "split" ? node.sizes[d.index] ?? 0.5 : 0.5;
87
+ if (!node || node.type !== "split") return 0.5;
88
+ return Math.min(1, node.sizes.slice(0, d.index + 1).reduce((a, b) => a + b, 0));
88
89
  };
89
90
  const down = (e) => {
90
91
  if (e.button !== 0) return;
@@ -236,6 +237,7 @@ function SplitStage({
236
237
  return () => ro.disconnect();
237
238
  }, []);
238
239
  useEffect(() => {
240
+ if (size.w === 0 && size.h === 0) return;
239
241
  onSizeRef.current?.(size);
240
242
  }, [size]);
241
243
  const measured = size.w > 0 && size.h > 0;
@@ -362,7 +364,7 @@ function LayoutPresetPicker({
362
364
  className
363
365
  ),
364
366
  children: [
365
- /* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ jsx(ScrollRow, { label, children: /* @__PURE__ */ jsx(
367
+ /* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ jsx(ScrollRow, { children: /* @__PURE__ */ jsx(
366
368
  "div",
367
369
  {
368
370
  ref: group,