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
@@ -4,10 +4,12 @@ var OVERLAY_STRINGS = {
4
4
  cancel: "Cancel",
5
5
  menu: "Menu",
6
6
  back: "Back: ",
7
- contextMenu: "Actions"
7
+ contextMenu: "Actions",
8
+ opensInNewTab: "opens in a new tab"
8
9
  };
9
10
  var SHELL_STRINGS = {
10
11
  sections: "Sections",
12
+ onThisPage: "On this page",
11
13
  more: "More",
12
14
  hubTitle: "Back to nish.software",
13
15
  hubLabel: "\u2190 nish.software",
@@ -25,6 +27,7 @@ var STATUS_STRINGS = {
25
27
  nothingHere: "Nothing here yet",
26
28
  loadingNamed: (label) => `Loading ${label}`,
27
29
  offline: "You're offline",
30
+ serverUnreachable: "Can't reach the server",
28
31
  actions: "Actions"
29
32
  };
30
33
  var THEME_STRINGS = {
@@ -50,9 +53,12 @@ var DISPLAY_STRINGS = {
50
53
  moreCount: (count) => `${count} more`,
51
54
  copy: "Copy",
52
55
  copied: "Copied",
56
+ copyFailed: "Copy failed",
53
57
  legend: "Legend",
54
58
  noData: "No data",
55
- noDataNamed: (label) => `${label}: no data`
59
+ noDataNamed: (label) => `${label}: no data`,
60
+ rangeLabel: (low, high, current, min, max) => `Range ${low} to ${high}${current != null ? `, current ${current}` : ""}, within ${min} to ${max}`,
61
+ chartTruncated: (shown, total) => `First ${shown} of ${total} points`
56
62
  };
57
63
  var FIELD_STRINGS = {
58
64
  optional: "Optional",
@@ -62,6 +68,7 @@ var FIELD_STRINGS = {
62
68
  removeNamed: (name) => `Remove ${name}`,
63
69
  clear: "Clear",
64
70
  noMatches: "No matches",
71
+ resultsCount: (n) => `${n} ${n === 1 ? "result" : "results"}`,
65
72
  searching: "Searching\u2026",
66
73
  removeTag: (tag) => `Remove ${tag}`,
67
74
  maxTags: (max) => `You can add up to ${max}`
@@ -155,7 +162,8 @@ var CANVAS_STRINGS = {
155
162
  zoomIn: "Zoom in",
156
163
  fitToScreen: "Fit to screen",
157
164
  followActivity: "Follow activity",
158
- canvasLines: "Lines"
165
+ canvasLines: "Lines",
166
+ canvasRole: "canvas"
159
167
  };
160
168
  var TOKEN_STRINGS = {
161
169
  serviceTokens: "Service tokens",
@@ -166,7 +174,11 @@ var TOKEN_STRINGS = {
166
174
  tokenRevokedAt: (when) => `Revoked ${when}`,
167
175
  tokenRevokeNamed: (name) => `Revoke ${name}`,
168
176
  tokenRevokeTitle: (name) => `Revoke ${name}?`,
169
- tokenRevokeFailed: "Could not revoke the token."
177
+ tokenRevokeFailed: "Could not revoke the token.",
178
+ tokenEmpty: "No service tokens. No machine client can read this app.",
179
+ tokenRevokeBody: '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.',
180
+ tokenCreated: (when) => `created ${when}`,
181
+ tokenFromEnv: "from SERVICE_TOKENS"
170
182
  };
171
183
  var INBOX_STRINGS = {
172
184
  inboxMarkHandled: "Mark handled",
@@ -183,6 +195,7 @@ var PAGING_STRINGS = {
183
195
  previousPage: "Previous page",
184
196
  nextPage: "Next page",
185
197
  pageLabel: (n) => `Page ${n}`,
198
+ pageOfCount: (page, count) => `Page ${page} of ${count}`,
186
199
  paginationLabel: "Pagination",
187
200
  breadcrumbs: "Breadcrumbs"
188
201
  };
@@ -40,9 +40,21 @@ function TableWrap({
40
40
  update();
41
41
  if (typeof ResizeObserver === "undefined") return;
42
42
  const ro = new ResizeObserver(update);
43
- ro.observe(el);
44
- for (const c of Array.from(el.children)) ro.observe(c);
45
- return () => ro.disconnect();
43
+ const watch = () => {
44
+ ro.disconnect();
45
+ ro.observe(el);
46
+ for (const c of Array.from(el.children)) ro.observe(c);
47
+ };
48
+ watch();
49
+ const mo = typeof MutationObserver === "undefined" ? null : new MutationObserver(() => {
50
+ watch();
51
+ update();
52
+ });
53
+ mo?.observe(el, { childList: true });
54
+ return () => {
55
+ ro.disconnect();
56
+ mo?.disconnect();
57
+ };
46
58
  }, []);
47
59
  const name = label ?? rest["aria-label"];
48
60
  const css = {
@@ -53,8 +53,9 @@ function ScrollingList({
53
53
  return /* @__PURE__ */ jsx("div", { ref: setRef, ...rest, children });
54
54
  }
55
55
  var Ctx = /* @__PURE__ */ createContext(null);
56
- var tabId = (base, v) => `${base}-tab-${v}`;
57
- var panelId = (base, v) => `${base}-panel-${v}`;
56
+ var idPart = (v) => v.replace(/[^A-Za-z0-9_-]/g, (c) => "_" + c.charCodeAt(0).toString(16));
57
+ var tabId = (base, v) => `${base}-tab-${idPart(v)}`;
58
+ var panelId = (base, v) => `${base}-panel-${idPart(v)}`;
58
59
  function Tabs({
59
60
  value: valueProp,
60
61
  defaultValue,
@@ -143,7 +143,11 @@ function TagInput({
143
143
  if (!SPLIT.test(pasted)) return;
144
144
  e.preventDefault();
145
145
  const parts = pasted.split(SPLIT);
146
- parts[0] = text + parts[0];
146
+ const el = e.currentTarget;
147
+ const start = Math.min(el.selectionStart ?? text.length, text.length);
148
+ const end = Math.min(el.selectionEnd ?? start, text.length);
149
+ parts[0] = text.slice(0, start) + parts[0];
150
+ parts[parts.length - 1] += text.slice(end);
147
151
  const { error: err, refused } = add(parts);
148
152
  setText(err ? refused.join(", ") : "");
149
153
  };
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  // src/components/time-field.tsx
4
- import { useEffect, useId, useRef, useState } from "react";
4
+ import { useCallback, useEffect, useId, useRef, useState } from "react";
5
5
  import { cn } from "../cn.js";
6
6
  import { getDefaultLocale } from "../format.js";
7
7
  import { resolveLocale } from "./calendar-classes.js";
@@ -109,6 +109,13 @@ function TimeField({
109
109
  const [own, setOwn] = useState(() => okProp("defaultValue", defaultValue));
110
110
  const value = controlled ? okProp("value", valueProp) : own;
111
111
  const hourRef = useRef(null);
112
+ const setHourNode = useCallback(
113
+ (node) => {
114
+ hourRef.current = node;
115
+ setRef(ref, node);
116
+ },
117
+ [ref]
118
+ );
112
119
  const minuteRef = useRef(null);
113
120
  const [draftState, setDraft] = useState(null);
114
121
  const [bad, setBad] = useState(false);
@@ -188,10 +195,14 @@ function TimeField({
188
195
  }
189
196
  } else if (key === "Home") {
190
197
  e.preventDefault();
191
- update(which === "h" ? { ...shown, h: hourText(0, cycle), pm: false } : { ...shown, m: "00" });
198
+ update(
199
+ which === "h" ? cycle === 12 ? { ...shown, h: "1" } : { ...shown, h: hourText(0, cycle), pm: false } : { ...shown, m: "00" }
200
+ );
192
201
  } else if (key === "End") {
193
202
  e.preventDefault();
194
- update(which === "h" ? { ...shown, h: hourText(23, cycle), pm: true } : { ...shown, m: pad2(lastMinute(st)) });
203
+ update(
204
+ which === "h" ? cycle === 12 ? { ...shown, h: "12" } : { ...shown, h: hourText(23, cycle), pm: true } : { ...shown, m: pad2(lastMinute(st)) }
205
+ );
195
206
  } else if (cycle === 12 && (key === "a" || key === "A" || key === "p" || key === "P")) {
196
207
  e.preventDefault();
197
208
  update({ ...shown, pm: key === "p" || key === "P" });
@@ -258,10 +269,7 @@ function TimeField({
258
269
  "input",
259
270
  {
260
271
  ...common,
261
- ref: (node) => {
262
- hourRef.current = node;
263
- setRef(ref, node);
264
- },
272
+ ref: setHourNode,
265
273
  id: inputId,
266
274
  value: shown.h,
267
275
  "aria-labelledby": names(hId),
@@ -40,7 +40,7 @@ function ToastCard({ t }) {
40
40
  el.style.opacity = dx === 0 ? "" : String(Math.max(0, 1 - Math.abs(dx) / width));
41
41
  };
42
42
  const onDown = (e) => {
43
- if (e.pointerType === "mouse") return;
43
+ if (e.pointerType === "mouse" || drag.current) return;
44
44
  drag.current = {
45
45
  pointerId: e.pointerId,
46
46
  startX: e.clientX,
@@ -71,8 +71,9 @@ function ToastCard({ t }) {
71
71
  const onUp = (e) => {
72
72
  const d = drag.current;
73
73
  const el = ref.current;
74
+ if (d && d.pointerId !== e.pointerId) return;
74
75
  drag.current = null;
75
- if (!d || !el || d.pointerId !== e.pointerId || !d.active) return;
76
+ if (!d || !el || !d.active) return;
76
77
  const dx = e.clientX - d.startX;
77
78
  const width = el.offsetWidth;
78
79
  const flung = Math.abs(d.velocity) > SWIPE_DISMISS_VELOCITY && Math.sign(d.velocity) === Math.sign(dx);
@@ -89,8 +90,9 @@ function ToastCard({ t }) {
89
90
  };
90
91
  const onCancel = (e) => {
91
92
  const d = drag.current;
93
+ if (d && d.pointerId !== e.pointerId) return;
92
94
  drag.current = null;
93
- if (!d?.active || d.pointerId !== e.pointerId) return;
95
+ if (!d?.active) return;
94
96
  setOffset(0, ref.current?.offsetWidth || 1);
95
97
  resumeTimer(t.id);
96
98
  };
@@ -61,8 +61,8 @@ function push(tone, title, bodyOrOptions) {
61
61
  const o = typeof bodyOrOptions === "string" ? { body: bodyOrOptions } : bodyOrOptions ?? {};
62
62
  const s = store();
63
63
  const id = s.nextId++;
64
- const asked = o.duration === Infinity ? "sticky" : o.duration;
65
- const duration = asked ?? (tone === "error" ? "sticky" : AUTO_DISMISS_MS);
64
+ const asked = o.duration;
65
+ const duration = asked === "sticky" ? "sticky" : typeof asked === "number" && asked > 0 ? asked >= 2 ** 31 - 1 ? "sticky" : asked : tone === "error" ? "sticky" : AUTO_DISMISS_MS;
66
66
  const item = {
67
67
  id,
68
68
  tone,
@@ -103,10 +103,22 @@ var toast = /* @__PURE__ */ Object.assign((title, o) => push("info", title, o),
103
103
  push("info", messages.loading, { duration: "sticky", id: slot });
104
104
  promise.then(
105
105
  (value) => {
106
- push("success", typeof messages.success === "function" ? messages.success(value) : messages.success, { id: slot });
106
+ let m;
107
+ try {
108
+ m = typeof messages.success === "function" ? messages.success(value) : messages.success;
109
+ } catch (e) {
110
+ return void push("error", String(e), { id: slot });
111
+ }
112
+ push("success", m, { id: slot });
107
113
  },
108
114
  (error) => {
109
- push("error", typeof messages.error === "function" ? messages.error(error) : messages.error, { id: slot });
115
+ let m;
116
+ try {
117
+ m = typeof messages.error === "function" ? messages.error(error) : messages.error;
118
+ } catch (e) {
119
+ m = String(e);
120
+ }
121
+ push("error", m, { id: slot });
110
122
  }
111
123
  );
112
124
  return promise;
@@ -116,7 +116,10 @@ function ToastFallback({ t, focusedRef }) {
116
116
  "div",
117
117
  {
118
118
  "data-nish-toast-fallback": "",
119
- className: "pointer-events-auto flex w-full max-w-md items-start gap-2.5 rounded-xl border border-th-line-strong bg-th-elevated px-3.5 py-3 shadow-pop animate-[nish-rise-in_160ms_var(--nish-ease-out)]",
119
+ onBlur: (e) => {
120
+ if (!e.currentTarget.contains(e.relatedTarget)) focusedRef.current = null;
121
+ },
122
+ className: `pointer-events-auto flex w-full max-w-md items-start gap-2.5 rounded-xl border ${{ success: "border-th-ok/35", error: "border-th-loss/40", warn: "border-th-warn/40", info: "border-th-line-strong" }[t.tone]} bg-th-elevated px-3.5 py-3 shadow-pop animate-[nish-rise-in_160ms_var(--nish-ease-out)]`,
120
123
  children: [
121
124
  /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
122
125
  /* @__PURE__ */ jsx("p", { className: "text-sm font-medium leading-snug text-th-hi", children: t.title }),
@@ -100,9 +100,10 @@ function Tooltip({ tip, children, className, side = "top", as = "span", focusabl
100
100
  if (!over) graceTimer.current = window.setTimeout(() => setOpen(false), TIP_GRACE_MS);
101
101
  }, []);
102
102
  const wrapperFocusable = focusable ?? !inner;
103
+ const own = rest ?? {};
103
104
  const a11y = {
104
- tabIndex: wrapperFocusable ? 0 : void 0,
105
- "aria-describedby": open && !inner ? id : void 0,
105
+ tabIndex: own.tabIndex ?? (wrapperFocusable ? 0 : void 0),
106
+ "aria-describedby": [own["aria-describedby"], open && !inner ? id : void 0].filter(Boolean).join(" ") || void 0,
106
107
  "data-state": open ? "open" : "closed"
107
108
  };
108
109
  const hint = variant === "hint" && "cursor-help underline decoration-th-hi3 decoration-dotted underline-offset-2";
@@ -2,7 +2,8 @@
2
2
 
3
3
  // src/components/url-state.ts
4
4
  import { useCallback, useMemo, useSyncExternalStore } from "react";
5
- var EVENT = "nish:urlstate";
5
+ var URL_STATE_EVENT = "nish:urlstate";
6
+ var EVENT = URL_STATE_EVENT;
6
7
  var locationAdapter = {
7
8
  get() {
8
9
  if (typeof location === "undefined") return new URLSearchParams();
@@ -69,8 +70,9 @@ function useUrlState(defaults, o = {}) {
69
70
  const comma = useMemo(() => JSON.parse(commaKey), [commaKey]);
70
71
  const defaultsKey = JSON.stringify(defaults);
71
72
  const stableDefaults = useMemo(() => JSON.parse(defaultsKey), [defaultsKey]);
73
+ const subscribe = useCallback((cb) => adapter.subscribe(cb), [adapter]);
72
74
  const search = useSyncExternalStore(
73
- adapter.subscribe,
75
+ subscribe,
74
76
  () => adapter.get().toString(),
75
77
  () => ""
76
78
  );
@@ -114,6 +116,7 @@ function useUrlState(defaults, o = {}) {
114
116
  return [state, patch, reset];
115
117
  }
116
118
  export {
119
+ URL_STATE_EVENT,
117
120
  locationAdapter,
118
121
  useUrlState
119
122
  };
@@ -11,14 +11,14 @@ import {
11
11
  } from "react";
12
12
  import { cn } from "../cn.js";
13
13
  import { useIsoLayoutEffect } from "./client.js";
14
- import { sortRows } from "./data-classes.js";
14
+ import { sortRows, tableInternals } from "./data-classes.js";
15
15
  import { useStrings } from "./provider.js";
16
16
  import { TABLE_STRINGS, STATUS_STRINGS } from "./strings.js";
17
17
  import { useLatest } from "./latest.js";
18
18
  import { Table, TableWrap, Td, Th, Tr } from "./table.js";
19
19
  import { useVirtualRows } from "./virtual.js";
20
20
  import { jsx, jsxs } from "react/jsx-runtime";
21
- var HIDE_BELOW = { sm: "hidden sm:table-cell", md: "hidden md:table-cell", lg: "hidden lg:table-cell" };
21
+ var { HIDE_BELOW } = tableInternals;
22
22
  var ROW_FOCUS = "focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-th-accent";
23
23
  var INTERACTIVE_CHILD = 'a,button,input,select,textarea,label,summary,[role="button"],[role="link"]';
24
24
  function VirtualTable({
@@ -46,12 +46,12 @@ function useVirtualRows(options) {
46
46
  const offsets = useMemo(
47
47
  () => buildOffsets(
48
48
  count,
49
- (i) => (measured.size === 0 ? void 0 : measured.get(getKey(i))) ?? (typeof itemSize === "number" ? itemSize : itemSize(i)),
49
+ (i) => (!measure || measured.size === 0 ? void 0 : measured.get(getKey(i))) ?? (typeof itemSize === "number" ? itemSize : itemSize(i)),
50
50
  gap
51
51
  ),
52
52
  // getKey only matters once something is measured, so an unstable getKey must not rebuild fixed-size offsets
53
53
  // eslint-disable-next-line react-hooks/exhaustive-deps
54
- [count, itemSize, measure ? getKey : null, gap, measured]
54
+ [count, itemSize, measure, measure ? getKey : null, gap, measured]
55
55
  );
56
56
  const total = offsets[count];
57
57
  const offsetOf = useCallback((i) => offsets[i], [offsets]);
@@ -179,7 +179,8 @@ function useVirtualRows(options) {
179
179
  const pin = useCallback((index) => setPinned(index), []);
180
180
  const scrollToIndex = useCallback(
181
181
  // eslint-disable-next-line react-hooks/preserve-manual-memoization -- reads the latest-value ref on purpose; the callback must stay stable
182
- (index, { align = "auto", behavior = "auto" } = {}) => {
182
+ (index, { align = "auto", behavior: wanted = "auto" } = {}) => {
183
+ const behavior = wanted === "smooth" && typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches ? "auto" : wanted;
183
184
  const jump = (minMove) => {
184
185
  const { offsets: o, count: n, gap: g } = latest.current;
185
186
  if (n === 0) return;
@@ -261,7 +262,10 @@ function VirtualList({
261
262
  ...rest,
262
263
  ref: mergeRefs(ref, rootRef),
263
264
  style: rootStyle,
264
- tabIndex: self ? count > 0 ? 0 : void 0 : rest.tabIndex,
265
+ tabIndex: self ? rest.tabIndex ?? (count > 0 ? 0 : void 0) : rest.tabIndex,
266
+ role: self && labelled && count > 0 && rest.role === void 0 ? "region" : rest.role,
267
+ "aria-label": self && labelled && count > 0 && !ariaLabelledBy ? ariaLabel : void 0,
268
+ "aria-labelledby": self && labelled && count > 0 ? ariaLabelledBy : void 0,
265
269
  className: cn("relative", self && "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-th-accent", className),
266
270
  children: count === 0 && empty != null ? empty : /* @__PURE__ */ jsx(
267
271
  "div",
@@ -47,7 +47,24 @@ function nf(locale, min, max) {
47
47
  () => new Intl.NumberFormat(locale, { minimumFractionDigits: min, maximumFractionDigits: max })
48
48
  );
49
49
  }
50
- function dtf(locale, key, options, timeZone) {
50
+ var zoneOk = /* @__PURE__ */ new Map();
51
+ function safeZone(timeZone) {
52
+ if (!timeZone) return void 0;
53
+ let ok = zoneOk.get(timeZone);
54
+ if (ok === void 0) {
55
+ try {
56
+ new Intl.DateTimeFormat("en-US", { timeZone });
57
+ ok = true;
58
+ } catch {
59
+ ok = false;
60
+ }
61
+ if (zoneOk.size >= 64) zoneOk.clear();
62
+ zoneOk.set(timeZone, ok);
63
+ }
64
+ return ok ? timeZone : void 0;
65
+ }
66
+ function dtf(locale, key, options, zone2) {
67
+ const timeZone = safeZone(zone2);
51
68
  return cached(
52
69
  `d|${locale}|${key}|${timeZone ?? ""}`,
53
70
  () => new Intl.DateTimeFormat(locale, timeZone ? { ...options, timeZone } : options)
@@ -117,7 +134,7 @@ function money(v, o = {}) {
117
134
  }
118
135
  function signedMoney(v, o = {}) {
119
136
  if (!finite(v)) return DASH;
120
- if (Math.abs(v) < 5e-3) return "No change";
137
+ if (Math.abs(v) < 5e-3) return o.zero ?? "No change";
121
138
  return (v < 0 ? MINUS : "+") + moneyAbs(Math.abs(v), o, loc(o));
122
139
  }
123
140
  function pct(v, o = {}) {
@@ -155,7 +172,8 @@ function bytes(v, o = {}) {
155
172
  i++;
156
173
  }
157
174
  const text = i === 0 || abs >= 100 ? fixed(abs, 0, 0, locale) : fixed(abs, 0, 1, locale);
158
- return (v < 0 ? MINUS : "") + text + " " + BYTE_UNITS[i];
175
+ const zero = Number(text.replace(/[^0-9]/g, "")) === 0;
176
+ return (v < 0 && !zero ? MINUS : "") + text + " " + BYTE_UNITS[i];
159
177
  }
160
178
  var DURATION_PARTS = [
161
179
  [86400, "d", "day"],
@@ -232,7 +250,12 @@ function ago(t, o = {}) {
232
250
  if (abs < 45) return english ? "just now" : rtf(locale, long ? "long" : "narrow").format(0, "second");
233
251
  let pick = AGO_UNITS[0];
234
252
  for (const u of AGO_UNITS) if (abs >= u[0]) pick = u;
235
- const n = Math.max(1, Math.round(abs / pick[0]));
253
+ let n = Math.max(1, Math.round(abs / pick[0]));
254
+ const next = AGO_UNITS[AGO_UNITS.indexOf(pick) + 1];
255
+ if (next && (n * pick[0] >= next[0] || pick[1] === "month" && n >= 12)) {
256
+ pick = next;
257
+ n = Math.max(1, Math.round(abs / pick[0]));
258
+ }
236
259
  const past = diff < 0;
237
260
  if (!english) return rtf(locale, long ? "long" : "narrow").format(past ? -n : n, pick[1]);
238
261
  if (long) return rtf(locale, "long").format(past ? -n : n, pick[1]);
@@ -1,14 +1,21 @@
1
1
  // src/runtime.ts
2
- var version = true ? "3.1.0" : "dev";
2
+ var version = true ? "3.3.0" : "dev";
3
3
  var VERSION = version;
4
4
  var KEY = /* @__PURE__ */ Symbol.for("nish-ui.runtime.v1");
5
5
  function runtime() {
6
6
  const g = globalThis;
7
7
  return g[KEY] ??= { versions: /* @__PURE__ */ new Set(), slots: {} };
8
8
  }
9
+ function isDevelopment() {
10
+ try {
11
+ return process.env.NODE_ENV !== "production";
12
+ } catch {
13
+ return false;
14
+ }
15
+ }
9
16
  function register(rt) {
10
17
  rt.versions.add(version);
11
- if (rt.versions.size > 1 && !rt.warned && globalThis.process?.env?.NODE_ENV !== "production") {
18
+ if (rt.versions.size > 1 && !rt.warned && isDevelopment()) {
12
19
  rt.warned = true;
13
20
  console.warn(
14
21
  `nish-ui: two versions are loaded on this page (${[...rt.versions].join(", ")}). Overlays, toasts and theme state are shared, but mixing versions is unsupported.`
@@ -236,6 +236,10 @@ function createInboxClient(options) {
236
236
  }
237
237
  if (queue[0] === head) queue.shift();
238
238
  if (result.kind === "ok") sentSinceDown++;
239
+ else if (!loggedInvalid.has(result.error)) {
240
+ loggedInvalid.add(result.error);
241
+ log(`queued event dropped: ${result.error}`);
242
+ }
239
243
  }
240
244
  retryStep = 0;
241
245
  if (down) {
@@ -361,7 +361,8 @@ function swapSlots(slots, a, b) {
361
361
  function narrowLayout(count, n, aspect) {
362
362
  if (count === 1) return leaf(0);
363
363
  const dir = n.dir === "auto" ? aspect >= 1.2 ? "row" : "col" : n.dir;
364
- const split = Math.min(0.8, Math.max(0.2, n.split));
364
+ const s = Number.isFinite(n.split) ? n.split : 0.5;
365
+ const split = Math.min(0.8, Math.max(0.2, s));
365
366
  return {
366
367
  type: "split",
367
368
  dir,
package/dist/esm/theme.js CHANGED
@@ -25,7 +25,10 @@ function storageKey() {
25
25
  return k && /^[A-Za-z0-9_-]+$/.test(k) ? k : DEFAULT_KEY;
26
26
  }
27
27
  function registerThemes(themes) {
28
- Object.assign(state().extra, themes);
28
+ for (const [name, scheme] of Object.entries(themes)) {
29
+ if (/^[a-z0-9-]+$/.test(name)) state().extra[name] = scheme;
30
+ else console.warn(`[nish-ui] registerThemes: skipped "${name}" (use lowercase letters, digits and hyphens)`);
31
+ }
29
32
  }
30
33
  var has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
31
34
  function isThemeName(v) {
@@ -34,7 +37,7 @@ function isThemeName(v) {
34
37
  function readCookie() {
35
38
  if (typeof document === "undefined") return null;
36
39
  try {
37
- const m = document.cookie.match(new RegExp(`(?:^|;\\s*)${storageKey()}=([a-z0-9-]+)`));
40
+ const m = document.cookie.match(new RegExp(`(?:^|;\\s*)${storageKey()}=([a-z0-9-]+)(?:;|$)`));
38
41
  return m ? m[1] : null;
39
42
  } catch {
40
43
  return null;
@@ -238,7 +241,7 @@ function mountThemeToggle(button, opts = {}) {
238
241
  if (svg.getAttribute("data-icon") === icon) svg.removeAttribute("display");
239
242
  else svg.setAttribute("display", "none");
240
243
  });
241
- const elsewhere = TOGGLE_ORDER.includes(choice) ? "" : ` (${elsewhereWords})`;
244
+ const elsewhere = TOGGLE_ORDER.includes(choice) || has(state().extra, choice) ? "" : ` (${elsewhereWords})`;
242
245
  const label = sentence(`${themeLabel(choice, words)}${elsewhere}`, themeLabel(nextChoice(choice), words));
243
246
  button.setAttribute("aria-label", label);
244
247
  button.setAttribute("title", label);
@@ -278,7 +281,8 @@ var toastRegion = null;
278
281
  var hideCurrent = null;
279
282
  function showToast(content, opts = {}) {
280
283
  hideCurrent?.();
281
- if (!toastRegion || !toastRegion.isConnected) {
284
+ if (!toastRegion || !toastRegion.isConnected) toastRegion = document.querySelector(".nish-toast-region");
285
+ if (!toastRegion) {
282
286
  toastRegion = document.createElement("div");
283
287
  toastRegion.setAttribute("role", "status");
284
288
  toastRegion.setAttribute("aria-live", "polite");
@@ -301,10 +305,13 @@ function showToast(content, opts = {}) {
301
305
  let remaining = opts.duration === "sticky" ? Infinity : opts.duration ?? TOAST_MS;
302
306
  let started = 0;
303
307
  let holds = 0;
308
+ let returnTo = null;
304
309
  const hide = () => {
305
310
  if (timer != null) clearTimeout(timer);
306
311
  timer = null;
312
+ const hadFocus = box.contains(document.activeElement);
307
313
  box.remove();
314
+ if (hadFocus && returnTo?.isConnected) returnTo.focus();
308
315
  if (hideCurrent === hide) hideCurrent = null;
309
316
  };
310
317
  const run = (ms) => {
@@ -347,7 +354,11 @@ function showToast(content, opts = {}) {
347
354
  box.append(close);
348
355
  box.addEventListener("pointerenter", (e) => e.pointerType === "mouse" && pause());
349
356
  box.addEventListener("pointerleave", (e) => e.pointerType === "mouse" && resume());
350
- box.addEventListener("focusin", (e) => !box.contains(e.relatedTarget) && pause());
357
+ box.addEventListener("focusin", (e) => {
358
+ if (box.contains(e.relatedTarget)) return;
359
+ if (e.relatedTarget instanceof HTMLElement) returnTo = e.relatedTarget;
360
+ pause();
361
+ });
351
362
  box.addEventListener("focusout", (e) => !box.contains(e.relatedTarget) && resume());
352
363
  box.addEventListener("keydown", (e) => {
353
364
  if (e.key === "Escape") hide();
@@ -361,6 +372,11 @@ function showToast(content, opts = {}) {
361
372
  return hide;
362
373
  }
363
374
  var dialogSeq = 0;
375
+ function onBackdrop(dialog, e) {
376
+ if (e.target !== dialog) return false;
377
+ const r = dialog.getBoundingClientRect();
378
+ return !(e.clientX >= r.left && e.clientX <= r.right && e.clientY >= r.top && e.clientY <= r.bottom);
379
+ }
364
380
  function confirmDialog(opts) {
365
381
  if (typeof document === "undefined") return Promise.resolve(false);
366
382
  const opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;
@@ -416,11 +432,12 @@ function confirmDialog(opts) {
416
432
  finish(false);
417
433
  });
418
434
  dialog.addEventListener("close", () => finish(false));
435
+ let pressedOnBackdrop = null;
436
+ dialog.addEventListener("pointerdown", (e) => pressedOnBackdrop = onBackdrop(dialog, e));
419
437
  dialog.addEventListener("click", (e) => {
420
- if (e.target !== dialog) return;
421
- const r = dialog.getBoundingClientRect();
422
- const inside = e.clientX >= r.left && e.clientX <= r.right && e.clientY >= r.top && e.clientY <= r.bottom;
423
- if (!inside) finish(false);
438
+ const down = pressedOnBackdrop;
439
+ pressedOnBackdrop = null;
440
+ if (down !== false && onBackdrop(dialog, e)) finish(false);
424
441
  });
425
442
  document.body.append(dialog);
426
443
  dialog.showModal();
@@ -497,11 +514,15 @@ function openSheet(dialog) {
497
514
  const onKey = (e) => {
498
515
  if (e.key === "Escape") e.stopPropagation();
499
516
  };
517
+ let pressedOnBackdrop = null;
518
+ const onPress = (e) => {
519
+ pressedOnBackdrop = onBackdrop(dialog, e);
520
+ };
500
521
  const onClick = (e) => {
501
522
  if (e.target === dialog) {
502
- const r = dialog.getBoundingClientRect();
503
- const inside = e.clientX >= r.left && e.clientX <= r.right && e.clientY >= r.top && e.clientY <= r.bottom;
504
- if (!inside) closeNow();
523
+ const down = pressedOnBackdrop;
524
+ pressedOnBackdrop = null;
525
+ if (down !== false && onBackdrop(dialog, e)) closeNow();
505
526
  return;
506
527
  }
507
528
  if (e.target instanceof Element && e.target.closest("[data-sheet-close]")) closeNow();
@@ -516,7 +537,7 @@ function openSheet(dialog) {
516
537
  if (typeof matchMedia !== "undefined" && matchMedia("(min-width: 640px)").matches) return;
517
538
  const r = dialog.getBoundingClientRect();
518
539
  const onHeader = e.target instanceof Element && e.target.closest(".nish-sheet-header") != null;
519
- if (!onHeader && e.clientY - r.top > 28) return;
540
+ if (!onHeader && e.clientY - r.top > 44) return;
520
541
  dragging = true;
521
542
  startY = lastY = e.clientY;
522
543
  lastT = e.timeStamp;
@@ -553,6 +574,7 @@ function openSheet(dialog) {
553
574
  dialog.removeEventListener("cancel", onCancel);
554
575
  dialog.removeEventListener("keydown", onKey);
555
576
  dialog.removeEventListener("click", onClick);
577
+ dialog.removeEventListener("pointerdown", onPress);
556
578
  dialog.removeEventListener("pointerdown", onDown);
557
579
  dialog.removeEventListener("pointermove", onMove);
558
580
  dialog.removeEventListener("pointerup", onUp);
@@ -563,6 +585,7 @@ function openSheet(dialog) {
563
585
  dialog.addEventListener("cancel", onCancel);
564
586
  dialog.addEventListener("keydown", onKey);
565
587
  dialog.addEventListener("click", onClick);
588
+ dialog.addEventListener("pointerdown", onPress);
566
589
  dialog.addEventListener("pointerdown", onDown);
567
590
  dialog.addEventListener("pointermove", onMove);
568
591
  dialog.addEventListener("pointerup", onUp);
@@ -792,7 +815,7 @@ function mountScrollspy(nav, o = {}) {
792
815
  };
793
816
  return Object.assign(stop, { lock });
794
817
  }
795
- function mountChecklist(list) {
818
+ function mountChecklist(list, opts = {}) {
796
819
  if (typeof document === "undefined") return () => void 0;
797
820
  const key = list.dataset.store || null;
798
821
  const boxes = () => Array.from(list.querySelectorAll('li[data-id] input[type="checkbox"]'));
@@ -816,7 +839,7 @@ function mountChecklist(list) {
816
839
  const all = boxes();
817
840
  const done = all.filter((b) => b.checked).length;
818
841
  if (progress) {
819
- progress.textContent = `${done} of ${all.length}`;
842
+ progress.textContent = opts.format ? opts.format(done, all.length) : `${done} of ${all.length}`;
820
843
  progress.style.setProperty("--p", `${all.length ? done / all.length * 100 : 0}%`);
821
844
  }
822
845
  };
@@ -1,6 +1,6 @@
1
1
  // The one source of truth for every design token. scripts/build.mjs turns this into
2
2
  // dist/tokens.css (--nish-* custom properties), tools/contrast.mjs checks it, and
3
- // src/theme.ts reads PRESETS from it. Edit values here, never in generated CSS.
3
+ // src/theme.ts builds PRESETS from THEMES. Edit values here, never in generated CSS.
4
4
  //
5
5
  // Colors are plain hex so static pages can use them as-is; Tailwind opacity
6
6
  // modifiers (bg-th-surface/50) work through color-mix in Tailwind 4.
package/dist/format.d.ts CHANGED
@@ -22,8 +22,10 @@ interface MoneyOptions extends LocaleOptions {
22
22
  }
23
23
  /** Money: 1234.56 → "$1,234.56"; negatives use a true minus sign. The symbol always comes first. */
24
24
  declare function money(v: number | null | undefined, o?: MoneyOptions): string;
25
- /** Signed money: "+$12.30", "−$4.00", and "No change" when |v| < 0.005. */
26
- declare function signedMoney(v: number | null | undefined, o?: MoneyOptions): string;
25
+ /** Signed money: "+$12.30", "−$4.00", and "No change" when |v| < 0.005. Pass `zero` for another language. */
26
+ declare function signedMoney(v: number | null | undefined, o?: MoneyOptions & {
27
+ zero?: string;
28
+ }): string;
27
29
  interface PctOptions extends LocaleOptions {
28
30
  /** Fraction digits. Default 1. */
29
31
  digits?: number;
@@ -35,7 +37,7 @@ interface PctOptions extends LocaleOptions {
35
37
  /** Percent: 0.123 → "12.3%". */
36
38
  declare function pct(v: number | null | undefined, o?: PctOptions): string;
37
39
  interface NumOptions extends LocaleOptions {
38
- /** Fixed fraction digits. Default: up to 2, trailing zeros trimmed (1 when compact). */
40
+ /** Fixed fraction digits. Default: up to 2, trailing zeros trimmed (1 when compact). With `compact`, digits is a maximum: 12000 gives "12k", not "12.00k". */
39
41
  digits?: number;
40
42
  /** Short form: 12.3k, 4.5M. */
41
43
  compact?: boolean;