nish-ui 2.2.0 → 3.1.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 (99) hide show
  1. package/README.md +10 -6
  2. package/dist/chart.d.ts +8 -3
  3. package/dist/chart.js +2 -417
  4. package/dist/elements-all.js +81 -80
  5. package/dist/elements-charts.d.ts +7 -1
  6. package/dist/elements-charts.js +16 -16
  7. package/dist/elements-data.d.ts +7 -1
  8. package/dist/elements-data.js +5 -5
  9. package/dist/elements-forms.d.ts +7 -1
  10. package/dist/elements-forms.js +18 -17
  11. package/dist/elements.d.ts +7 -1
  12. package/dist/elements.js +4 -4
  13. package/dist/esm/components/accordion.js +3 -2
  14. package/dist/esm/components/app-shell.js +3 -2
  15. package/dist/esm/components/avatar.js +6 -5
  16. package/dist/esm/components/breadcrumbs.js +3 -2
  17. package/dist/esm/components/calendar-base.js +4 -3
  18. package/dist/esm/components/canvas/legend.js +7 -6
  19. package/dist/esm/components/canvas/node.js +3 -2
  20. package/dist/esm/components/canvas/system-canvas.js +27 -3
  21. package/dist/esm/components/carousel.js +24 -5
  22. package/dist/esm/components/charts.js +29 -20
  23. package/dist/esm/components/combobox.js +4 -3
  24. package/dist/esm/components/command.js +4 -3
  25. package/dist/esm/components/context-menu.js +3 -2
  26. package/dist/esm/components/data-classes.js +5 -4
  27. package/dist/esm/components/data.js +5 -8
  28. package/dist/esm/components/date-picker.js +5 -3
  29. package/dist/esm/components/date-range-picker.js +5 -3
  30. package/dist/esm/components/display.js +10 -9
  31. package/dist/esm/components/drawer.js +3 -2
  32. package/dist/esm/components/error-boundary.js +4 -2
  33. package/dist/esm/components/feedback.js +7 -6
  34. package/dist/esm/components/file-dropzone.js +24 -3
  35. package/dist/esm/components/filters.js +7 -4
  36. package/dist/esm/components/flow.js +17 -15
  37. package/dist/esm/components/forms.js +37 -10
  38. package/dist/esm/components/hooks.js +22 -19
  39. package/dist/esm/components/hover-card.js +2 -2
  40. package/dist/esm/components/inbox.js +12 -8
  41. package/dist/esm/components/layout-vars.js +10 -7
  42. package/dist/esm/components/layout.js +5 -4
  43. package/dist/esm/components/media.js +3 -2
  44. package/dist/esm/components/menu.js +12 -8
  45. package/dist/esm/components/modal.js +4 -3
  46. package/dist/esm/components/more-sheet.js +3 -2
  47. package/dist/esm/components/multi-select.js +10 -6
  48. package/dist/esm/components/nav-items.js +4 -3
  49. package/dist/esm/components/nav.js +5 -4
  50. package/dist/esm/components/overlay-core.js +31 -10
  51. package/dist/esm/components/overlay-dialog.js +20 -4
  52. package/dist/esm/components/pagination.js +7 -3
  53. package/dist/esm/components/popover.js +17 -11
  54. package/dist/esm/components/portal.js +2 -2
  55. package/dist/esm/components/primitives.js +1 -1
  56. package/dist/esm/components/progress.js +5 -2
  57. package/dist/esm/components/provider.js +34 -5
  58. package/dist/esm/components/range-calendar.js +4 -3
  59. package/dist/esm/components/resource-classes.js +34 -16
  60. package/dist/esm/components/resource.js +5 -4
  61. package/dist/esm/components/service-tokens.js +4 -3
  62. package/dist/esm/components/settings.js +8 -5
  63. package/dist/esm/components/slider.js +4 -2
  64. package/dist/esm/components/split.js +4 -3
  65. package/dist/esm/components/strings.js +182 -65
  66. package/dist/esm/components/tag-input.js +18 -9
  67. package/dist/esm/components/theme-toggle.js +3 -2
  68. package/dist/esm/components/time-field-classes.js +5 -2
  69. package/dist/esm/components/time-field.js +19 -10
  70. package/dist/esm/components/toast-card.js +155 -0
  71. package/dist/esm/components/toast-store.js +136 -0
  72. package/dist/esm/components/toast.js +38 -241
  73. package/dist/esm/components/tooltip.js +3 -3
  74. package/dist/esm/components/url-state.js +1 -0
  75. package/dist/esm/components/virtual-table.js +11 -4
  76. package/dist/esm/components/virtual.js +16 -2
  77. package/dist/esm/format.js +17 -14
  78. package/dist/esm/index.js +0 -20
  79. package/dist/esm/runtime.js +1 -1
  80. package/dist/esm/server/inbox/client.js +1 -1
  81. package/dist/esm/system-canvas.js +4 -0
  82. package/dist/esm/theme.js +73 -13
  83. package/dist/format.js +18 -15
  84. package/dist/inbox-client.js +1 -1
  85. package/dist/index.d.ts +43 -21
  86. package/dist/nish-components.css +41 -1
  87. package/dist/nish-components.min.css +1 -1
  88. package/dist/node/th-check.js +12 -3
  89. package/dist/server/hono.d.ts +1 -1
  90. package/dist/server/hono.js +20 -1
  91. package/dist/server/index.d.ts +2 -2
  92. package/dist/server/index.js +19 -5
  93. package/dist/{spa-BLlMc0eI.d.ts → spa-7myD4xvA.d.ts} +3 -2
  94. package/dist/system-canvas.d.ts +179 -2
  95. package/dist/theme.d.ts +23 -5
  96. package/dist/theme.global.js +87 -151
  97. package/dist/theme.js +87 -151
  98. package/package.json +1 -1
  99. package/dist/system-canvas-BLuWd69H.d.ts +0 -183
@@ -0,0 +1,155 @@
1
+ "use client";
2
+
3
+ // src/components/toast-card.tsx
4
+ import { useRef } from "react";
5
+ import { cn } from "../cn.js";
6
+ import { AlertTriangleIcon, CheckCircleIcon, InfoIcon, XIcon } from "./icons.js";
7
+ import { useStrings } from "./provider.js";
8
+ import { DISPLAY_STRINGS } from "./strings.js";
9
+ import { dismissToast, pauseTimer, resumeTimer } from "./toast-store.js";
10
+ import { jsx, jsxs } from "react/jsx-runtime";
11
+ var TONE = {
12
+ success: {
13
+ icon: /* @__PURE__ */ jsx(CheckCircleIcon, { size: 15, className: "text-th-ok" }),
14
+ className: "border-th-ok/35"
15
+ },
16
+ error: {
17
+ icon: /* @__PURE__ */ jsx(AlertTriangleIcon, { size: 15, className: "text-th-loss" }),
18
+ className: "border-th-loss/40"
19
+ },
20
+ warn: {
21
+ icon: /* @__PURE__ */ jsx(AlertTriangleIcon, { size: 15, className: "text-th-warn" }),
22
+ className: "border-th-warn/40"
23
+ },
24
+ info: {
25
+ icon: /* @__PURE__ */ jsx(InfoIcon, { size: 15, className: "text-th-accent" }),
26
+ className: "border-th-line-strong"
27
+ }
28
+ };
29
+ var SWIPE_DISMISS_FRACTION = 0.35;
30
+ var SWIPE_DISMISS_VELOCITY = 0.5;
31
+ var SWIPE_SLOP = 8;
32
+ function ToastCard({ t }) {
33
+ const strings = useStrings(DISPLAY_STRINGS);
34
+ const ref = useRef(null);
35
+ const drag = useRef(null);
36
+ const setOffset = (dx, width) => {
37
+ const el = ref.current;
38
+ if (!el) return;
39
+ el.style.transform = dx === 0 ? "" : `translateX(${dx}px)`;
40
+ el.style.opacity = dx === 0 ? "" : String(Math.max(0, 1 - Math.abs(dx) / width));
41
+ };
42
+ const onDown = (e) => {
43
+ if (e.pointerType === "mouse") return;
44
+ drag.current = {
45
+ pointerId: e.pointerId,
46
+ startX: e.clientX,
47
+ startY: e.clientY,
48
+ lastX: e.clientX,
49
+ lastT: e.timeStamp,
50
+ velocity: 0,
51
+ active: false
52
+ };
53
+ };
54
+ const onMove = (e) => {
55
+ const d = drag.current;
56
+ const el = ref.current;
57
+ if (!d || !el || d.pointerId !== e.pointerId) return;
58
+ const dx = e.clientX - d.startX;
59
+ if (!d.active) {
60
+ if (Math.abs(dx) < SWIPE_SLOP || Math.abs(dx) < Math.abs(e.clientY - d.startY)) return;
61
+ d.active = true;
62
+ el.setPointerCapture(e.pointerId);
63
+ pauseTimer(t.id);
64
+ }
65
+ const dt = e.timeStamp - d.lastT;
66
+ if (dt > 0) d.velocity = (e.clientX - d.lastX) / dt;
67
+ d.lastX = e.clientX;
68
+ d.lastT = e.timeStamp;
69
+ setOffset(dx, el.offsetWidth);
70
+ };
71
+ const onUp = (e) => {
72
+ const d = drag.current;
73
+ const el = ref.current;
74
+ drag.current = null;
75
+ if (!d || !el || d.pointerId !== e.pointerId || !d.active) return;
76
+ const dx = e.clientX - d.startX;
77
+ const width = el.offsetWidth;
78
+ const flung = Math.abs(d.velocity) > SWIPE_DISMISS_VELOCITY && Math.sign(d.velocity) === Math.sign(dx);
79
+ if (Math.abs(dx) > width * SWIPE_DISMISS_FRACTION || flung) {
80
+ dismissToast(t.id);
81
+ return;
82
+ }
83
+ el.style.transition = "transform 160ms var(--nish-ease-out), opacity 160ms var(--nish-ease-out)";
84
+ setOffset(0, width);
85
+ window.setTimeout(() => {
86
+ if (ref.current) ref.current.style.transition = "";
87
+ }, 180);
88
+ resumeTimer(t.id);
89
+ };
90
+ const onCancel = (e) => {
91
+ const d = drag.current;
92
+ drag.current = null;
93
+ if (!d?.active || d.pointerId !== e.pointerId) return;
94
+ setOffset(0, ref.current?.offsetWidth || 1);
95
+ resumeTimer(t.id);
96
+ };
97
+ const leave = (e) => {
98
+ if (!e.currentTarget.contains(e.relatedTarget)) resumeTimer(t.id);
99
+ };
100
+ const enter = (e) => {
101
+ if (!e.currentTarget.contains(e.relatedTarget)) pauseTimer(t.id);
102
+ };
103
+ return /* @__PURE__ */ jsxs(
104
+ "div",
105
+ {
106
+ ref,
107
+ onPointerDown: onDown,
108
+ onPointerMove: onMove,
109
+ onPointerUp: onUp,
110
+ onPointerCancel: onCancel,
111
+ onPointerEnter: (e) => e.pointerType === "mouse" && pauseTimer(t.id),
112
+ onPointerLeave: (e) => e.pointerType === "mouse" && resumeTimer(t.id),
113
+ onFocus: enter,
114
+ onBlur: leave,
115
+ className: cn(
116
+ "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",
117
+ "touch-pan-y animate-[nish-rise-in_160ms_var(--nish-ease-out)]",
118
+ "max-sm:[html[data-nish-layer-open]_&]:animate-[nish-toast-in-top_200ms_var(--nish-ease-out)]",
119
+ TONE[t.tone].className
120
+ ),
121
+ children: [
122
+ /* @__PURE__ */ jsx("span", { className: "mt-0.5 shrink-0", children: TONE[t.tone].icon }),
123
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
124
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium leading-snug text-th-hi", children: t.title }),
125
+ t.body ? /* @__PURE__ */ jsx("p", { className: "mt-0.5 break-words text-xs leading-snug text-th-hi2", children: t.body }) : null
126
+ ] }),
127
+ t.action ? /* @__PURE__ */ jsx(
128
+ "button",
129
+ {
130
+ type: "button",
131
+ onClick: () => {
132
+ t.action?.onClick();
133
+ dismissToast(t.id);
134
+ },
135
+ 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",
136
+ children: t.action.label
137
+ }
138
+ ) : null,
139
+ /* @__PURE__ */ jsx(
140
+ "button",
141
+ {
142
+ type: "button",
143
+ onClick: () => dismissToast(t.id),
144
+ "aria-label": strings.dismiss,
145
+ 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",
146
+ children: /* @__PURE__ */ jsx(XIcon, { size: 14 })
147
+ }
148
+ )
149
+ ]
150
+ }
151
+ );
152
+ }
153
+ export {
154
+ ToastCard
155
+ };
@@ -0,0 +1,136 @@
1
+ "use client";
2
+
3
+ // src/components/toast-store.ts
4
+ import { useSyncExternalStore } from "react";
5
+ import { shared } from "../runtime.js";
6
+ var AUTO_DISMISS_MS = 4e3;
7
+ var MAX_VISIBLE = 4;
8
+ var cachedStore;
9
+ function store() {
10
+ return cachedStore ??= shared("toast", () => ({
11
+ items: [],
12
+ nextId: 1,
13
+ subs: /* @__PURE__ */ new Set(),
14
+ timers: /* @__PURE__ */ new Map()
15
+ }));
16
+ }
17
+ var emit = () => store().subs.forEach((fn) => fn());
18
+ function startTimer(id, ms) {
19
+ const t = {
20
+ handle: null,
21
+ remaining: ms,
22
+ started: Date.now(),
23
+ paused: 0
24
+ };
25
+ t.handle = setTimeout(() => dismissToast(id), ms);
26
+ store().timers.set(id, t);
27
+ }
28
+ function clearTimer(id) {
29
+ const { timers } = store();
30
+ const t = timers.get(id);
31
+ if (t?.handle != null) clearTimeout(t.handle);
32
+ timers.delete(id);
33
+ }
34
+ function pauseTimer(id) {
35
+ const t = store().timers.get(id);
36
+ if (!t) return;
37
+ t.paused += 1;
38
+ if (t.paused > 1 || t.handle == null) return;
39
+ clearTimeout(t.handle);
40
+ t.handle = null;
41
+ t.remaining = Math.max(0, t.remaining - (Date.now() - t.started));
42
+ }
43
+ function resumeTimer(id) {
44
+ const t = store().timers.get(id);
45
+ if (!t || t.paused === 0) return;
46
+ t.paused -= 1;
47
+ if (t.paused > 0) return;
48
+ t.started = Date.now();
49
+ t.handle = setTimeout(() => dismissToast(id), Math.max(t.remaining, 1e3));
50
+ }
51
+ function dismissToast(id) {
52
+ clearTimer(id);
53
+ const s = store();
54
+ const next = s.items.filter((t) => t.id !== id);
55
+ if (next.length === s.items.length) return;
56
+ s.items = next;
57
+ emit();
58
+ }
59
+ var isKept = (t) => t.duration === "sticky" || t.tone === "error";
60
+ function push(tone, title, bodyOrOptions) {
61
+ const o = typeof bodyOrOptions === "string" ? { body: bodyOrOptions } : bodyOrOptions ?? {};
62
+ const s = store();
63
+ const id = s.nextId++;
64
+ const asked = o.duration === Infinity ? "sticky" : o.duration;
65
+ const duration = asked ?? (tone === "error" ? "sticky" : AUTO_DISMISS_MS);
66
+ const item = {
67
+ id,
68
+ tone,
69
+ title,
70
+ body: o.body,
71
+ action: o.action,
72
+ slot: o.id,
73
+ duration
74
+ };
75
+ const old = o.id ? s.items.find((t) => t.slot === o.id) : void 0;
76
+ if (old) {
77
+ clearTimer(old.id);
78
+ s.items = s.items.map((t) => t === old ? item : t);
79
+ } else {
80
+ let excess = s.items.length + 1 - MAX_VISIBLE;
81
+ const kept = [];
82
+ for (const t of s.items) {
83
+ if (excess > 0 && !isKept(t)) {
84
+ excess--;
85
+ clearTimer(t.id);
86
+ } else {
87
+ kept.push(t);
88
+ }
89
+ }
90
+ s.items = [...kept, item];
91
+ }
92
+ emit();
93
+ if (duration !== "sticky") startTimer(id, duration);
94
+ return id;
95
+ }
96
+ var toast = /* @__PURE__ */ Object.assign((title, o) => push("info", title, o), {
97
+ success: (title, o) => push("success", title, o),
98
+ error: (title, o) => push("error", title, o),
99
+ warn: (title, o) => push("warn", title, o),
100
+ info: (title, o) => push("info", title, o),
101
+ promise: (promise, messages) => {
102
+ const slot = "nish-promise-" + store().nextId;
103
+ push("info", messages.loading, { duration: "sticky", id: slot });
104
+ promise.then(
105
+ (value) => {
106
+ push("success", typeof messages.success === "function" ? messages.success(value) : messages.success, { id: slot });
107
+ },
108
+ (error) => {
109
+ push("error", typeof messages.error === "function" ? messages.error(error) : messages.error, { id: slot });
110
+ }
111
+ );
112
+ return promise;
113
+ }
114
+ });
115
+ function useToast() {
116
+ return toast;
117
+ }
118
+ function useToasts() {
119
+ return useSyncExternalStore(
120
+ (fn) => {
121
+ const { subs } = store();
122
+ subs.add(fn);
123
+ return () => subs.delete(fn);
124
+ },
125
+ () => store().items,
126
+ () => store().items
127
+ );
128
+ }
129
+ export {
130
+ dismissToast,
131
+ pauseTimer,
132
+ resumeTimer,
133
+ toast,
134
+ useToast,
135
+ useToasts
136
+ };
@@ -1,159 +1,23 @@
1
1
  "use client";
2
2
 
3
3
  // src/components/toast.tsx
4
- import {
5
- useEffect,
6
- useRef,
7
- useState,
8
- useSyncExternalStore
9
- } from "react";
4
+ import { useEffect, useRef, useState } from "react";
10
5
  import { cn } from "../cn.js";
11
- import { shared } from "../runtime.js";
12
- import { AlertTriangleIcon, CheckCircleIcon, InfoIcon, XIcon } from "./icons.js";
6
+ import { XIcon } from "./icons.js";
7
+ import { lazyModule, preloadWhenIdle, useLazyModule } from "./lazy-module.js";
13
8
  import { Portal } from "./portal.js";
14
- import { useNishStrings } from "./provider.js";
9
+ import { useStrings } from "./provider.js";
10
+ import { DISPLAY_STRINGS } from "./strings.js";
11
+ import { dismissToast, useToasts } from "./toast-store.js";
12
+ import { toast, useToast, dismissToast as dismissToast2 } from "./toast-store.js";
15
13
  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
- };
14
+ var cardFailed = false;
15
+ var cardModule = /* @__PURE__ */ lazyModule(
16
+ () => import("./toast-card.js").catch((e) => {
17
+ cardFailed = true;
18
+ throw e;
19
+ })
20
+ );
157
21
  var DESKTOP_BOTTOM = {
158
22
  sm: "sm:bottom-0 sm:pb-[calc(var(--nish-bottom-inset,0px)+1.25rem+min(var(--nish-bottom-bar-h,0px),1rem))]",
159
23
  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))]",
@@ -161,6 +25,20 @@ var DESKTOP_BOTTOM = {
161
25
  };
162
26
  function Toaster({ className, offset, offsetUntil = "md", style: userStyle, ref, ...rest }) {
163
27
  const list = useToasts();
28
+ useEffect(() => cardFailed ? void 0 : preloadWhenIdle(cardModule), []);
29
+ const card = useLazyModule(cardModule, list.length > 0 && !cardFailed);
30
+ const Card = card?.ToastCard;
31
+ const stack = useRef(null);
32
+ const focused = useRef(null);
33
+ useEffect(() => {
34
+ const f = focused.current;
35
+ if (!Card || !f || document.activeElement !== document.body) return;
36
+ const at = list.findIndex((i) => i.id === f[0]);
37
+ const btn = [...stack.current?.children[at]?.querySelectorAll("button") ?? []].find(
38
+ (b) => (b.getAttribute("aria-label") ?? b.textContent) === f[1]
39
+ );
40
+ btn?.focus();
41
+ }, [Card]);
164
42
  const [polite, setPolite] = useState({ text: "", seq: 0 });
165
43
  const [assertive, setAssertive] = useState({ text: "", seq: 0 });
166
44
  const announced = useRef(/* @__PURE__ */ new Set());
@@ -224,105 +102,22 @@ function Toaster({ className, offset, offsetUntil = "md", style: userStyle, ref,
224
102
  children: [
225
103
  /* @__PURE__ */ jsx("div", { role: "status", "aria-live": "polite", "aria-atomic": "true", className: "sr-only", children: /* @__PURE__ */ jsx("span", { children: polite.text }, polite.seq) }),
226
104
  /* @__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))
105
+ /* @__PURE__ */ jsx("div", { ref: stack, className: "contents", children: list.map((t) => Card ? /* @__PURE__ */ jsx(Card, { t }, t.id) : /* @__PURE__ */ jsx(ToastFallback, { t, focusedRef: focused }, t.id)) })
228
106
  ]
229
107
  }
230
108
  ) });
231
109
  }
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);
110
+ function ToastFallback({ t, focusedRef }) {
111
+ const strings = useStrings(DISPLAY_STRINGS);
112
+ const track = (e) => {
113
+ focusedRef.current = [t.id, e.currentTarget.getAttribute("aria-label") ?? e.currentTarget.textContent];
305
114
  };
306
115
  return /* @__PURE__ */ jsxs(
307
116
  "div",
308
117
  {
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
- ),
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)]",
324
120
  children: [
325
- /* @__PURE__ */ jsx("span", { className: "mt-0.5 shrink-0", children: TONE[t.tone].icon }),
326
121
  /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
327
122
  /* @__PURE__ */ jsx("p", { className: "text-sm font-medium leading-snug text-th-hi", children: t.title }),
328
123
  t.body ? /* @__PURE__ */ jsx("p", { className: "mt-0.5 break-words text-xs leading-snug text-th-hi2", children: t.body }) : null
@@ -331,6 +126,7 @@ function ToastCard({ t }) {
331
126
  "button",
332
127
  {
333
128
  type: "button",
129
+ onFocus: track,
334
130
  onClick: () => {
335
131
  t.action?.onClick();
336
132
  dismissToast(t.id);
@@ -343,6 +139,7 @@ function ToastCard({ t }) {
343
139
  "button",
344
140
  {
345
141
  type: "button",
142
+ onFocus: track,
346
143
  onClick: () => dismissToast(t.id),
347
144
  "aria-label": strings.dismiss,
348
145
  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",
@@ -355,7 +152,7 @@ function ToastCard({ t }) {
355
152
  }
356
153
  export {
357
154
  Toaster,
358
- dismissToast,
155
+ dismissToast2 as dismissToast,
359
156
  toast,
360
157
  useToast
361
158
  };
@@ -6,7 +6,7 @@ import { createPortal } from "react-dom";
6
6
  import { cn } from "../cn.js";
7
7
  import { shared } from "../runtime.js";
8
8
  import { useIsoLayoutEffect } from "./client.js";
9
- import { useNishConfig } from "./provider.js";
9
+ import { useNishContext } from "./provider.js";
10
10
  import { keyboardFocused, touchTracker } from "./overlay-classes.js";
11
11
  import { FOCUSABLE, layerHost, useMergedRef } from "./overlay-core.js";
12
12
  import { EDGE, useAnchoredPosition, floatingStyle } from "./overlay-position.js";
@@ -25,7 +25,7 @@ function Tooltip({ tip, children, className, side = "top", as = "span", focusabl
25
25
  const [measuredInner, setMeasuredInner] = useState(false);
26
26
  useIsoLayoutEffect(() => {
27
27
  const el = triggerRef.current;
28
- const found = only !== null && !!el && el.querySelector(FOCUSABLE) !== null;
28
+ const found = only !== null && !!el && !!el.firstElementChild?.matches(FOCUSABLE);
29
29
  setMeasuredInner(found);
30
30
  });
31
31
  const inner = only !== null && (staticInner || measuredInner);
@@ -146,7 +146,7 @@ function FloatingTip({
146
146
  onPointerEnter,
147
147
  onPointerLeave
148
148
  }) {
149
- const config = useNishConfig();
149
+ const config = useNishContext();
150
150
  const tipRef = useRef(null);
151
151
  const pos = useAnchoredPosition(anchor, tipRef, true, side, "center");
152
152
  return createPortal(
@@ -84,6 +84,7 @@ function useUrlState(defaults, o = {}) {
84
84
  const name = prefix + key;
85
85
  const value = next[key];
86
86
  params.delete(name);
87
+ if (value === void 0 || value === null) continue;
87
88
  if (same(value, d[key])) continue;
88
89
  if (Array.isArray(value)) {
89
90
  if (value.length === 0) params.append(name, "");