nish-ui 1.8.0 → 2.0.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 (152) hide show
  1. package/README.md +223 -61
  2. package/dist/base-tailwind.css +1757 -0
  3. package/dist/base.css +1590 -1445
  4. package/dist/chart.d.ts +4 -1
  5. package/dist/chart.js +122 -49
  6. package/dist/elements-all.d.ts +8 -0
  7. package/dist/elements-all.js +178 -0
  8. package/dist/elements-charts.d.ts +124 -2
  9. package/dist/elements-charts.js +131 -1
  10. package/dist/elements-data.d.ts +166 -2
  11. package/dist/elements-data.js +46 -1
  12. package/dist/elements-forms.d.ts +71 -0
  13. package/dist/elements-forms.js +24 -25
  14. package/dist/elements.d.ts +71 -0
  15. package/dist/elements.js +4 -5
  16. package/dist/esm/chart-values.js +58 -0
  17. package/dist/esm/chart.js +10 -0
  18. package/dist/esm/cn.js +19 -0
  19. package/dist/esm/combobox-filter.js +13 -0
  20. package/dist/esm/components/accordion.js +166 -0
  21. package/dist/esm/components/app-shell.js +198 -0
  22. package/dist/esm/components/avatar-classes.js +28 -0
  23. package/dist/esm/components/avatar.js +113 -0
  24. package/dist/esm/components/breadcrumbs.js +154 -0
  25. package/dist/esm/components/canvas/follow-caption.js +32 -0
  26. package/dist/esm/components/canvas/follow.js +119 -0
  27. package/dist/esm/components/canvas/icons.js +70 -0
  28. package/dist/esm/components/canvas/index.js +10 -0
  29. package/dist/esm/components/canvas/layout.js +258 -0
  30. package/dist/esm/components/canvas/legend.js +93 -0
  31. package/dist/esm/components/canvas/minimap.js +127 -0
  32. package/dist/esm/components/canvas/node.js +87 -0
  33. package/dist/esm/components/canvas/route.js +262 -0
  34. package/dist/esm/components/canvas/system-canvas.js +837 -0
  35. package/dist/esm/components/canvas/types.js +10 -0
  36. package/dist/esm/components/canvas/view.js +47 -0
  37. package/dist/esm/components/chart-hooks.js +19 -0
  38. package/dist/esm/components/charts.js +467 -0
  39. package/dist/esm/components/client.js +24 -0
  40. package/dist/esm/components/combobox.js +343 -0
  41. package/dist/esm/components/command.js +403 -0
  42. package/dist/esm/components/data-classes.js +159 -0
  43. package/dist/esm/components/data.js +517 -0
  44. package/dist/esm/components/display-classes.js +130 -0
  45. package/dist/esm/components/display.js +755 -0
  46. package/dist/esm/components/error-boundary.js +64 -0
  47. package/dist/esm/components/feedback.js +136 -0
  48. package/dist/esm/components/file-dropzone.js +184 -0
  49. package/dist/esm/components/filters.js +108 -0
  50. package/dist/esm/components/flow.js +746 -0
  51. package/dist/esm/components/forms-classes.js +43 -0
  52. package/dist/esm/components/forms.js +581 -0
  53. package/dist/esm/components/hooks-classes.js +9 -0
  54. package/dist/esm/components/hooks.js +236 -0
  55. package/dist/esm/components/icons.js +96 -0
  56. package/dist/esm/components/inbox-classes.js +29 -0
  57. package/dist/esm/components/inbox.js +257 -0
  58. package/dist/esm/components/latest.js +13 -0
  59. package/dist/esm/components/layout-vars.js +96 -0
  60. package/dist/esm/components/layout.js +272 -0
  61. package/dist/esm/components/media.js +143 -0
  62. package/dist/esm/components/nav.js +614 -0
  63. package/dist/esm/components/overlay-classes.js +66 -0
  64. package/dist/esm/components/overlay.js +1447 -0
  65. package/dist/esm/components/pagination-classes.js +29 -0
  66. package/dist/esm/components/pagination.js +154 -0
  67. package/dist/esm/components/portal.js +16 -0
  68. package/dist/esm/components/primitives-classes.js +198 -0
  69. package/dist/esm/components/primitives.js +268 -0
  70. package/dist/esm/components/progress.js +77 -0
  71. package/dist/esm/components/provider.js +32 -0
  72. package/dist/esm/components/radio-group.js +186 -0
  73. package/dist/esm/components/resource-classes.js +133 -0
  74. package/dist/esm/components/resource.js +209 -0
  75. package/dist/esm/components/segmented.js +178 -0
  76. package/dist/esm/components/separator.js +38 -0
  77. package/dist/esm/components/service-tokens.js +221 -0
  78. package/dist/esm/components/settings.js +301 -0
  79. package/dist/esm/components/slider.js +262 -0
  80. package/dist/esm/components/split-classes.js +8 -0
  81. package/dist/esm/components/split.js +411 -0
  82. package/dist/esm/components/strings.js +119 -0
  83. package/dist/esm/components/table.js +144 -0
  84. package/dist/esm/components/tabs-classes.js +21 -0
  85. package/dist/esm/components/tabs.js +201 -0
  86. package/dist/esm/components/tag-input.js +257 -0
  87. package/dist/esm/components/theme-toggle.js +177 -0
  88. package/dist/esm/components/toast.js +361 -0
  89. package/dist/esm/components/url-state.js +118 -0
  90. package/dist/esm/components/visually-hidden.js +20 -0
  91. package/dist/esm/format.js +320 -0
  92. package/dist/esm/inbox-client.js +2 -0
  93. package/dist/esm/inbox-types.js +2 -0
  94. package/dist/esm/index.js +320 -0
  95. package/dist/esm/runtime.js +37 -0
  96. package/dist/esm/server/inbox/client.js +297 -0
  97. package/dist/esm/server/inbox/types.js +24 -0
  98. package/dist/esm/sparkline-path.js +59 -0
  99. package/dist/esm/split-layout.js +419 -0
  100. package/dist/esm/system-canvas.js +2 -0
  101. package/dist/esm/theme.js +804 -0
  102. package/dist/esm/tokens.mjs +425 -0
  103. package/dist/esm/url.js +20 -0
  104. package/dist/files.json +5 -1
  105. package/dist/fonts/LICENSE-Inter.txt +93 -0
  106. package/dist/format.d.ts +32 -18
  107. package/dist/format.js +227 -82
  108. package/dist/inbox-client.js +3 -1
  109. package/dist/index.d.ts +1689 -667
  110. package/dist/nish-components.css +4701 -3169
  111. package/dist/nish-components.min.css +1 -0
  112. package/dist/nish.css +1603 -1450
  113. package/dist/nish.min.css +1 -0
  114. package/dist/node/eslint.js +29 -14
  115. package/dist/node/th-check.js +29 -14
  116. package/dist/node/vite.d.ts +12 -0
  117. package/dist/node/vite.js +12 -2
  118. package/dist/server/hono.d.ts +15 -6
  119. package/dist/server/hono.js +30 -25
  120. package/dist/server/index.d.ts +3 -10
  121. package/dist/server/index.js +71 -38
  122. package/dist/{spa-DuVB5O7S.d.ts → spa-BLlMc0eI.d.ts} +38 -5
  123. package/dist/system-canvas-BLuWd69H.d.ts +183 -0
  124. package/dist/system-canvas.d.ts +2 -168
  125. package/dist/tailwind-core.css +114 -0
  126. package/dist/tailwind.css +3 -7
  127. package/dist/theme-init.js +23 -9
  128. package/dist/theme-init.sha256 +1 -0
  129. package/dist/theme.d.ts +246 -4
  130. package/dist/theme.global.js +357 -90
  131. package/dist/theme.js +338 -68
  132. package/dist/tokens.css +14 -6
  133. package/dist/tokens.dtcg.json +1513 -0
  134. package/dist/tokens.js +29 -14
  135. package/dist/tokens.json +512 -0
  136. package/package.json +51 -13
  137. package/dist/chart.js.map +0 -1
  138. package/dist/elements-charts.js.map +0 -1
  139. package/dist/elements-data.js.map +0 -1
  140. package/dist/elements-forms.js.map +0 -1
  141. package/dist/elements.js.map +0 -1
  142. package/dist/format.js.map +0 -1
  143. package/dist/inbox-client.js.map +0 -1
  144. package/dist/index.js +0 -10260
  145. package/dist/index.js.map +0 -1
  146. package/dist/server/hono.js.map +0 -1
  147. package/dist/server/index.js.map +0 -1
  148. package/dist/split-layout.js.map +0 -1
  149. package/dist/system-canvas.js +0 -2204
  150. package/dist/system-canvas.js.map +0 -1
  151. package/dist/theme.global.js.map +0 -1
  152. package/dist/theme.js.map +0 -1
@@ -0,0 +1,361 @@
1
+ "use client";
2
+
3
+ // src/components/toast.tsx
4
+ import {
5
+ useEffect,
6
+ useRef,
7
+ useState,
8
+ useSyncExternalStore
9
+ } from "react";
10
+ import { cn } from "../cn.js";
11
+ import { shared } from "../runtime.js";
12
+ import { AlertTriangleIcon, CheckCircleIcon, InfoIcon, XIcon } from "./icons.js";
13
+ import { Portal } from "./portal.js";
14
+ import { useNishStrings } from "./provider.js";
15
+ import { jsx, jsxs } from "react/jsx-runtime";
16
+ var AUTO_DISMISS_MS = 4e3;
17
+ var MAX_VISIBLE = 4;
18
+ var cachedStore;
19
+ function store() {
20
+ return cachedStore ??= shared("toast", () => ({
21
+ items: [],
22
+ nextId: 1,
23
+ subs: /* @__PURE__ */ new Set(),
24
+ timers: /* @__PURE__ */ new Map()
25
+ }));
26
+ }
27
+ var emit = () => store().subs.forEach((fn) => fn());
28
+ function startTimer(id, ms) {
29
+ const t = {
30
+ handle: null,
31
+ remaining: ms,
32
+ started: Date.now(),
33
+ paused: 0
34
+ };
35
+ t.handle = setTimeout(() => dismissToast(id), ms);
36
+ store().timers.set(id, t);
37
+ }
38
+ function clearTimer(id) {
39
+ const { timers } = store();
40
+ const t = timers.get(id);
41
+ if (t?.handle != null) clearTimeout(t.handle);
42
+ timers.delete(id);
43
+ }
44
+ function pauseTimer(id) {
45
+ const t = store().timers.get(id);
46
+ if (!t) return;
47
+ t.paused += 1;
48
+ if (t.paused > 1 || t.handle == null) return;
49
+ clearTimeout(t.handle);
50
+ t.handle = null;
51
+ t.remaining = Math.max(0, t.remaining - (Date.now() - t.started));
52
+ }
53
+ function resumeTimer(id) {
54
+ const t = store().timers.get(id);
55
+ if (!t || t.paused === 0) return;
56
+ t.paused -= 1;
57
+ if (t.paused > 0) return;
58
+ t.started = Date.now();
59
+ t.handle = setTimeout(() => dismissToast(id), Math.max(t.remaining, 1e3));
60
+ }
61
+ function dismissToast(id) {
62
+ clearTimer(id);
63
+ const s = store();
64
+ const next = s.items.filter((t) => t.id !== id);
65
+ if (next.length === s.items.length) return;
66
+ s.items = next;
67
+ emit();
68
+ }
69
+ var isKept = (t) => t.duration === "sticky" || t.tone === "error";
70
+ function push(tone, title, bodyOrOptions) {
71
+ const o = typeof bodyOrOptions === "string" ? { body: bodyOrOptions } : bodyOrOptions ?? {};
72
+ const s = store();
73
+ const id = s.nextId++;
74
+ const asked = o.duration === Infinity ? "sticky" : o.duration;
75
+ const duration = asked ?? (tone === "error" ? "sticky" : AUTO_DISMISS_MS);
76
+ const item = {
77
+ id,
78
+ tone,
79
+ title,
80
+ body: o.body,
81
+ action: o.action,
82
+ slot: o.id,
83
+ duration
84
+ };
85
+ const old = o.id ? s.items.find((t) => t.slot === o.id) : void 0;
86
+ if (old) {
87
+ clearTimer(old.id);
88
+ s.items = s.items.map((t) => t === old ? item : t);
89
+ } else {
90
+ let excess = s.items.length + 1 - MAX_VISIBLE;
91
+ const kept = [];
92
+ for (const t of s.items) {
93
+ if (excess > 0 && !isKept(t)) {
94
+ excess--;
95
+ clearTimer(t.id);
96
+ } else {
97
+ kept.push(t);
98
+ }
99
+ }
100
+ s.items = [...kept, item];
101
+ }
102
+ emit();
103
+ if (duration !== "sticky") startTimer(id, duration);
104
+ return id;
105
+ }
106
+ var toast = /* @__PURE__ */ Object.assign((title, o) => push("info", title, o), {
107
+ success: (title, o) => push("success", title, o),
108
+ error: (title, o) => push("error", title, o),
109
+ warn: (title, o) => push("warn", title, o),
110
+ info: (title, o) => push("info", title, o),
111
+ promise: (promise, messages) => {
112
+ const slot = "nish-promise-" + store().nextId;
113
+ push("info", messages.loading, { duration: "sticky", id: slot });
114
+ promise.then(
115
+ (value) => {
116
+ push("success", typeof messages.success === "function" ? messages.success(value) : messages.success, { id: slot });
117
+ },
118
+ (error) => {
119
+ push("error", typeof messages.error === "function" ? messages.error(error) : messages.error, { id: slot });
120
+ }
121
+ );
122
+ return promise;
123
+ }
124
+ });
125
+ function useToast() {
126
+ return toast;
127
+ }
128
+ function useToasts() {
129
+ return useSyncExternalStore(
130
+ (fn) => {
131
+ const { subs } = store();
132
+ subs.add(fn);
133
+ return () => subs.delete(fn);
134
+ },
135
+ () => store().items,
136
+ () => store().items
137
+ );
138
+ }
139
+ var TONE = {
140
+ success: {
141
+ icon: /* @__PURE__ */ jsx(CheckCircleIcon, { size: 15, className: "text-th-ok" }),
142
+ className: "border-th-ok/35"
143
+ },
144
+ error: {
145
+ icon: /* @__PURE__ */ jsx(AlertTriangleIcon, { size: 15, className: "text-th-loss" }),
146
+ className: "border-th-loss/40"
147
+ },
148
+ warn: {
149
+ icon: /* @__PURE__ */ jsx(AlertTriangleIcon, { size: 15, className: "text-th-warn" }),
150
+ className: "border-th-warn/40"
151
+ },
152
+ info: {
153
+ icon: /* @__PURE__ */ jsx(InfoIcon, { size: 15, className: "text-th-accent" }),
154
+ className: "border-th-line-strong"
155
+ }
156
+ };
157
+ var DESKTOP_BOTTOM = {
158
+ sm: "sm:bottom-0 sm:pb-[calc(var(--nish-bottom-inset,0px)+1.25rem+min(var(--nish-bottom-bar-h,0px),1rem))]",
159
+ md: "sm:bottom-0 sm:pb-[var(--nish-toast-offset,calc(var(--nish-bottom-inset,0px)+1.25rem+min(var(--nish-bottom-bar-h,0px),1rem)))] md:pb-[calc(var(--nish-bottom-inset,0px)+1.25rem+min(var(--nish-bottom-bar-h,0px),1rem))]",
160
+ lg: "sm:bottom-0 sm:pb-[var(--nish-toast-offset,calc(var(--nish-bottom-inset,0px)+1.25rem+min(var(--nish-bottom-bar-h,0px),1rem)))] lg:pb-[calc(var(--nish-bottom-inset,0px)+1.25rem+min(var(--nish-bottom-bar-h,0px),1rem))]"
161
+ };
162
+ function Toaster({ className, offset, offsetUntil = "md", style: userStyle, ref, ...rest }) {
163
+ const list = useToasts();
164
+ const [polite, setPolite] = useState({ text: "", seq: 0 });
165
+ const [assertive, setAssertive] = useState({ text: "", seq: 0 });
166
+ const announced = useRef(/* @__PURE__ */ new Set());
167
+ const timers = useRef({
168
+ queue: { polite: [], assertive: [] },
169
+ flush: {},
170
+ clear: {}
171
+ });
172
+ useEffect(() => {
173
+ const t = timers.current;
174
+ for (const item of list) {
175
+ if (announced.current.has(item.id)) continue;
176
+ announced.current.add(item.id);
177
+ const text = item.body ? `${item.title}. ${item.body}` : item.title;
178
+ t.queue[item.tone === "error" ? "assertive" : "polite"].push(text);
179
+ }
180
+ for (const kind of ["polite", "assertive"]) {
181
+ if (t.queue[kind].length === 0 || t.flush[kind] !== void 0) continue;
182
+ const write = kind === "assertive" ? setAssertive : setPolite;
183
+ t.flush[kind] = setTimeout(() => {
184
+ t.flush[kind] = void 0;
185
+ const text = t.queue[kind].join(". ");
186
+ t.queue[kind] = [];
187
+ write((p) => ({ text, seq: p.seq + 1 }));
188
+ clearTimeout(t.clear[kind]);
189
+ t.clear[kind] = setTimeout(() => write((p) => ({ text: "", seq: p.seq + 1 })), 5e3);
190
+ }, 100);
191
+ }
192
+ const live = new Set(list.map((i) => i.id));
193
+ announced.current.forEach((id) => {
194
+ if (!live.has(id)) announced.current.delete(id);
195
+ });
196
+ }, [list]);
197
+ useEffect(() => {
198
+ const t = timers.current;
199
+ return () => {
200
+ clearTimeout(t.flush.polite);
201
+ clearTimeout(t.flush.assertive);
202
+ t.flush = {};
203
+ t.queue = { polite: [], assertive: [] };
204
+ clearTimeout(t.clear.polite);
205
+ clearTimeout(t.clear.assertive);
206
+ };
207
+ }, []);
208
+ const style = offset ? { ...userStyle, "--nish-toast-offset": offset } : userStyle;
209
+ return /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsxs(
210
+ "div",
211
+ {
212
+ ...rest,
213
+ ref,
214
+ style,
215
+ "data-nish-keep-active": "",
216
+ className: cn(
217
+ "pointer-events-none fixed inset-x-0 bottom-0 z-[var(--nish-z-toast,60)] flex flex-col items-center gap-2 px-3",
218
+ "pb-[var(--nish-toast-offset,max(calc(var(--nish-bottom-inset,0px)+8px),calc(12px+env(safe-area-inset-bottom))))]",
219
+ "max-sm:[html[data-nish-layer-open]_&]:bottom-auto max-sm:[html[data-nish-layer-open]_&]:top-[max(12px,env(safe-area-inset-top))] max-sm:[html[data-nish-layer-open]_&]:pb-0",
220
+ "sm:inset-x-auto sm:end-5 sm:w-96 sm:items-stretch sm:px-0",
221
+ DESKTOP_BOTTOM[offsetUntil],
222
+ className
223
+ ),
224
+ children: [
225
+ /* @__PURE__ */ jsx("div", { role: "status", "aria-live": "polite", "aria-atomic": "true", className: "sr-only", children: /* @__PURE__ */ jsx("span", { children: polite.text }, polite.seq) }),
226
+ /* @__PURE__ */ jsx("div", { role: "alert", "aria-live": "assertive", "aria-atomic": "true", className: "sr-only", children: /* @__PURE__ */ jsx("span", { children: assertive.text }, assertive.seq) }),
227
+ list.map((t) => /* @__PURE__ */ jsx(ToastCard, { t }, t.id))
228
+ ]
229
+ }
230
+ ) });
231
+ }
232
+ var SWIPE_DISMISS_FRACTION = 0.35;
233
+ var SWIPE_DISMISS_VELOCITY = 0.5;
234
+ var SWIPE_SLOP = 8;
235
+ function ToastCard({ t }) {
236
+ const strings = useNishStrings();
237
+ const ref = useRef(null);
238
+ const drag = useRef(null);
239
+ const setOffset = (dx, width) => {
240
+ const el = ref.current;
241
+ if (!el) return;
242
+ el.style.transform = dx === 0 ? "" : `translateX(${dx}px)`;
243
+ el.style.opacity = dx === 0 ? "" : String(Math.max(0, 1 - Math.abs(dx) / width));
244
+ };
245
+ const onDown = (e) => {
246
+ if (e.pointerType === "mouse") return;
247
+ drag.current = {
248
+ pointerId: e.pointerId,
249
+ startX: e.clientX,
250
+ startY: e.clientY,
251
+ lastX: e.clientX,
252
+ lastT: e.timeStamp,
253
+ velocity: 0,
254
+ active: false
255
+ };
256
+ };
257
+ const onMove = (e) => {
258
+ const d = drag.current;
259
+ const el = ref.current;
260
+ if (!d || !el || d.pointerId !== e.pointerId) return;
261
+ const dx = e.clientX - d.startX;
262
+ if (!d.active) {
263
+ if (Math.abs(dx) < SWIPE_SLOP || Math.abs(dx) < Math.abs(e.clientY - d.startY)) return;
264
+ d.active = true;
265
+ el.setPointerCapture(e.pointerId);
266
+ pauseTimer(t.id);
267
+ }
268
+ const dt = e.timeStamp - d.lastT;
269
+ if (dt > 0) d.velocity = (e.clientX - d.lastX) / dt;
270
+ d.lastX = e.clientX;
271
+ d.lastT = e.timeStamp;
272
+ setOffset(dx, el.offsetWidth);
273
+ };
274
+ const onUp = (e) => {
275
+ const d = drag.current;
276
+ const el = ref.current;
277
+ drag.current = null;
278
+ if (!d || !el || d.pointerId !== e.pointerId || !d.active) return;
279
+ const dx = e.clientX - d.startX;
280
+ const width = el.offsetWidth;
281
+ const flung = Math.abs(d.velocity) > SWIPE_DISMISS_VELOCITY && Math.sign(d.velocity) === Math.sign(dx);
282
+ if (Math.abs(dx) > width * SWIPE_DISMISS_FRACTION || flung) {
283
+ dismissToast(t.id);
284
+ return;
285
+ }
286
+ el.style.transition = "transform 160ms var(--nish-ease-out), opacity 160ms var(--nish-ease-out)";
287
+ setOffset(0, width);
288
+ window.setTimeout(() => {
289
+ if (ref.current) ref.current.style.transition = "";
290
+ }, 180);
291
+ resumeTimer(t.id);
292
+ };
293
+ const onCancel = (e) => {
294
+ const d = drag.current;
295
+ drag.current = null;
296
+ if (!d?.active || d.pointerId !== e.pointerId) return;
297
+ setOffset(0, ref.current?.offsetWidth || 1);
298
+ resumeTimer(t.id);
299
+ };
300
+ const leave = (e) => {
301
+ if (!e.currentTarget.contains(e.relatedTarget)) resumeTimer(t.id);
302
+ };
303
+ const enter = (e) => {
304
+ if (!e.currentTarget.contains(e.relatedTarget)) pauseTimer(t.id);
305
+ };
306
+ return /* @__PURE__ */ jsxs(
307
+ "div",
308
+ {
309
+ ref,
310
+ onPointerDown: onDown,
311
+ onPointerMove: onMove,
312
+ onPointerUp: onUp,
313
+ onPointerCancel: onCancel,
314
+ onPointerEnter: (e) => e.pointerType === "mouse" && pauseTimer(t.id),
315
+ onPointerLeave: (e) => e.pointerType === "mouse" && resumeTimer(t.id),
316
+ onFocus: enter,
317
+ onBlur: leave,
318
+ className: cn(
319
+ "pointer-events-auto flex w-full max-w-md items-start gap-2.5 rounded-xl border bg-th-elevated px-3.5 py-3 shadow-pop",
320
+ "touch-pan-y animate-[nish-rise-in_160ms_var(--nish-ease-out)]",
321
+ "max-sm:[html[data-nish-layer-open]_&]:animate-[nish-toast-in-top_200ms_var(--nish-ease-out)]",
322
+ TONE[t.tone].className
323
+ ),
324
+ children: [
325
+ /* @__PURE__ */ jsx("span", { className: "mt-0.5 shrink-0", children: TONE[t.tone].icon }),
326
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
327
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium leading-snug text-th-hi", children: t.title }),
328
+ t.body ? /* @__PURE__ */ jsx("p", { className: "mt-0.5 break-words text-xs leading-snug text-th-hi2", children: t.body }) : null
329
+ ] }),
330
+ t.action ? /* @__PURE__ */ jsx(
331
+ "button",
332
+ {
333
+ type: "button",
334
+ onClick: () => {
335
+ t.action?.onClick();
336
+ dismissToast(t.id);
337
+ },
338
+ className: "-my-1 inline-flex shrink-0 items-center justify-center rounded-md px-2 py-1 text-sm font-medium text-th-accent transition-colors hover:bg-th-accent-soft pointer-coarse:-my-2.5 pointer-coarse:min-h-11 pointer-coarse:min-w-11",
339
+ children: t.action.label
340
+ }
341
+ ) : null,
342
+ /* @__PURE__ */ jsx(
343
+ "button",
344
+ {
345
+ type: "button",
346
+ onClick: () => dismissToast(t.id),
347
+ "aria-label": strings.dismiss,
348
+ className: "-m-1 inline-flex shrink-0 items-center justify-center rounded-md p-1 text-th-hi3 transition-colors hover:bg-th-overlay hover:text-th-hi pointer-coarse:-my-2 pointer-coarse:min-h-11 pointer-coarse:min-w-11",
349
+ children: /* @__PURE__ */ jsx(XIcon, { size: 14 })
350
+ }
351
+ )
352
+ ]
353
+ }
354
+ );
355
+ }
356
+ export {
357
+ Toaster,
358
+ dismissToast,
359
+ toast,
360
+ useToast
361
+ };
@@ -0,0 +1,118 @@
1
+ "use client";
2
+
3
+ // src/components/url-state.ts
4
+ import { useCallback, useMemo, useSyncExternalStore } from "react";
5
+ var EVENT = "nish:urlstate";
6
+ var locationAdapter = {
7
+ get() {
8
+ if (typeof location === "undefined") return new URLSearchParams();
9
+ try {
10
+ return new URLSearchParams(location.search);
11
+ } catch {
12
+ return new URLSearchParams();
13
+ }
14
+ },
15
+ set(next) {
16
+ if (typeof location === "undefined" || typeof history === "undefined") return;
17
+ const qs = next.toString();
18
+ try {
19
+ history.replaceState(history.state, "", location.pathname + (qs ? `?${qs}` : "") + location.hash);
20
+ } catch {
21
+ return;
22
+ }
23
+ window.dispatchEvent(new Event(EVENT));
24
+ },
25
+ subscribe(onChange) {
26
+ if (typeof window === "undefined") return () => {
27
+ };
28
+ window.addEventListener("popstate", onChange);
29
+ window.addEventListener(EVENT, onChange);
30
+ return () => {
31
+ window.removeEventListener("popstate", onChange);
32
+ window.removeEventListener(EVENT, onChange);
33
+ };
34
+ }
35
+ };
36
+ function parseValue(params, key, fallback, comma) {
37
+ if (!params.has(key)) return fallback;
38
+ if (Array.isArray(fallback)) {
39
+ const all = params.getAll(key);
40
+ return (comma && all.length === 1 ? all[0].split(",") : all).filter(Boolean);
41
+ }
42
+ const raw = params.get(key) ?? "";
43
+ if (typeof fallback === "number") {
44
+ if (raw.trim() === "") return fallback;
45
+ const n = Number(raw);
46
+ return Number.isFinite(n) ? n : fallback;
47
+ }
48
+ if (typeof fallback === "boolean") {
49
+ if (raw === "1" || raw === "true") return true;
50
+ if (raw === "0" || raw === "false") return false;
51
+ return fallback;
52
+ }
53
+ return raw;
54
+ }
55
+ function same(a, b) {
56
+ if (Array.isArray(a) && Array.isArray(b)) return a.length === b.length && a.every((v, i) => v === b[i]);
57
+ return a === b;
58
+ }
59
+ function parse(params, defaults, prefix, comma) {
60
+ const out = {};
61
+ for (const key of Object.keys(defaults)) out[key] = parseValue(params, prefix + key, defaults[key], isComma(comma, key));
62
+ return out;
63
+ }
64
+ var isComma = (comma, key) => Array.isArray(comma) ? comma.includes(key) : comma === true;
65
+ function useUrlState(defaults, o = {}) {
66
+ const adapter = o.adapter ?? locationAdapter;
67
+ const prefix = o.prefix ? `${o.prefix}.` : "";
68
+ const commaKey = JSON.stringify(o.comma ?? false);
69
+ const comma = useMemo(() => JSON.parse(commaKey), [commaKey]);
70
+ const defaultsKey = JSON.stringify(defaults);
71
+ const stableDefaults = useMemo(() => JSON.parse(defaultsKey), [defaultsKey]);
72
+ const search = useSyncExternalStore(
73
+ adapter.subscribe,
74
+ () => adapter.get().toString(),
75
+ () => ""
76
+ );
77
+ const state = useMemo(() => parse(new URLSearchParams(search), stableDefaults, prefix, comma), [search, prefix, stableDefaults, comma]);
78
+ const write = useCallback(
79
+ (next) => {
80
+ const d = stableDefaults;
81
+ const params = adapter.get();
82
+ for (const key of Object.keys(next)) {
83
+ if (!(key in d)) continue;
84
+ const name = prefix + key;
85
+ const value = next[key];
86
+ params.delete(name);
87
+ if (same(value, d[key])) continue;
88
+ if (Array.isArray(value)) {
89
+ if (value.length === 0) params.append(name, "");
90
+ else {
91
+ for (const v of value) params.append(name, v);
92
+ if (isComma(comma, key) && value.length === 1 && value[0].includes(",")) params.append(name, "");
93
+ }
94
+ } else if (typeof value === "boolean") params.set(name, value ? "1" : "0");
95
+ else params.set(name, String(value));
96
+ }
97
+ adapter.set(params);
98
+ },
99
+ [adapter, stableDefaults, prefix, comma]
100
+ );
101
+ const patch = useCallback(
102
+ (p) => {
103
+ const prev = parse(adapter.get(), stableDefaults, prefix, comma);
104
+ write(typeof p === "function" ? p(prev) : p);
105
+ },
106
+ [adapter, stableDefaults, prefix, comma, write]
107
+ );
108
+ const reset = useCallback(() => {
109
+ const params = adapter.get();
110
+ for (const key of Object.keys(stableDefaults)) params.delete(prefix + key);
111
+ adapter.set(params);
112
+ }, [adapter, stableDefaults, prefix]);
113
+ return [state, patch, reset];
114
+ }
115
+ export {
116
+ locationAdapter,
117
+ useUrlState
118
+ };
@@ -0,0 +1,20 @@
1
+ // src/components/visually-hidden.tsx
2
+ import { jsx } from "react/jsx-runtime";
3
+ var HIDDEN = {
4
+ position: "absolute",
5
+ width: 1,
6
+ height: 1,
7
+ padding: 0,
8
+ margin: -1,
9
+ overflow: "hidden",
10
+ clip: "rect(0, 0, 0, 0)",
11
+ whiteSpace: "nowrap",
12
+ borderWidth: 0
13
+ };
14
+ function VisuallyHidden({ as = "span", style, ref, ...rest }) {
15
+ const Tag = as;
16
+ return /* @__PURE__ */ jsx(Tag, { ref, style: { ...HIDDEN, ...style }, ...rest });
17
+ }
18
+ export {
19
+ VisuallyHidden
20
+ };