nish-ui 1.9.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 +218 -58
  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 +71 -0
  9. package/dist/elements-charts.js +56 -57
  10. package/dist/elements-data.d.ts +71 -0
  11. package/dist/elements-data.js +5 -6
  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 +1686 -667
  110. package/dist/nish-components.css +4649 -4506
  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 +243 -4
  130. package/dist/theme.global.js +356 -89
  131. package/dist/theme.js +337 -67
  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,746 @@
1
+ "use client";
2
+
3
+ // src/components/flow.tsx
4
+ import {
5
+ useCallback,
6
+ useEffect,
7
+ useMemo,
8
+ useRef,
9
+ useState
10
+ } from "react";
11
+ import { cn } from "../cn.js";
12
+ import { ago } from "../format.js";
13
+ import { useIsoLayoutEffect } from "./client.js";
14
+ import { useMediaQuery, useNow } from "./hooks.js";
15
+ import { Tooltip } from "./overlay.js";
16
+ import { Badge } from "./primitives.js";
17
+ import { useNishStrings } from "./provider.js";
18
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
19
+ var EASE = "cubic-bezier(0.22, 1, 0.36, 1)";
20
+ function usePrefersReducedMotion() {
21
+ return useMediaQuery("(prefers-reduced-motion: reduce)");
22
+ }
23
+ var warned = /* @__PURE__ */ new Set();
24
+ function warnDev(message) {
25
+ if (warned.has(message)) return;
26
+ try {
27
+ if (process.env.NODE_ENV !== "production") {
28
+ warned.add(message);
29
+ console.warn(message);
30
+ }
31
+ } catch {
32
+ }
33
+ }
34
+ function assignRef(ref, el) {
35
+ if (typeof ref === "function") ref(el);
36
+ else if (ref) ref.current = el;
37
+ }
38
+ function useMergedRef(a, b) {
39
+ return useCallback(
40
+ (el) => {
41
+ assignRef(a, el);
42
+ assignRef(b, el);
43
+ },
44
+ [a, b]
45
+ );
46
+ }
47
+ function useTransitionFx(value, ref, pick) {
48
+ const prev = useRef(value);
49
+ useIsoLayoutEffect(() => {
50
+ const from = prev.current;
51
+ prev.current = value;
52
+ if (from === value) return;
53
+ const el = ref.current;
54
+ if (!el) return;
55
+ el.removeAttribute("data-fx");
56
+ const fx = pick(from, value);
57
+ if (!fx) return;
58
+ void el.offsetWidth;
59
+ el.setAttribute("data-fx", fx);
60
+ const timer = setTimeout(() => el.removeAttribute("data-fx"), 700);
61
+ return () => {
62
+ clearTimeout(timer);
63
+ el.removeAttribute("data-fx");
64
+ };
65
+ }, [value, ref, pick]);
66
+ }
67
+ function useFreshIds(ids, skipFirst) {
68
+ const key = ids.join("\n");
69
+ const [seen, setSeen] = useState(() => ({
70
+ key,
71
+ known: new Set(ids),
72
+ fresh: new Set(skipFirst ? [] : ids)
73
+ }));
74
+ if (seen.key === key) return seen.fresh;
75
+ const fresh = new Set([...seen.fresh].filter((id) => ids.includes(id)));
76
+ for (const id of ids) if (!seen.known.has(id)) fresh.add(id);
77
+ setSeen({ key, known: new Set(ids), fresh });
78
+ return fresh;
79
+ }
80
+ function CheckSvg({ size, className }) {
81
+ return /* @__PURE__ */ jsx(
82
+ "svg",
83
+ {
84
+ className: cn("nish-flow-check", className),
85
+ width: size,
86
+ height: size,
87
+ viewBox: "0 0 24 24",
88
+ fill: "none",
89
+ stroke: "currentColor",
90
+ strokeWidth: 3,
91
+ strokeLinecap: "round",
92
+ strokeLinejoin: "round",
93
+ "aria-hidden": "true",
94
+ focusable: "false",
95
+ children: /* @__PURE__ */ jsx("path", { d: "M5 12.5l4.5 4.5L19 7.5", pathLength: 1 })
96
+ }
97
+ );
98
+ }
99
+ function CrossSvg({ size }) {
100
+ return /* @__PURE__ */ jsx(
101
+ "svg",
102
+ {
103
+ width: size,
104
+ height: size,
105
+ viewBox: "0 0 24 24",
106
+ fill: "none",
107
+ stroke: "currentColor",
108
+ strokeWidth: 3,
109
+ strokeLinecap: "round",
110
+ "aria-hidden": "true",
111
+ focusable: "false",
112
+ children: /* @__PURE__ */ jsx("path", { d: "M6.5 6.5l11 11M17.5 6.5l-11 11" })
113
+ }
114
+ );
115
+ }
116
+ var NODE_STATUS = {
117
+ pending: "border-2 border-th-line text-th-hi3",
118
+ active: "border-2 border-th-accent text-th-hi",
119
+ done: "bg-th-ok-fill text-th-on-ok forced-colors:border-2 forced-colors:border-[color:Highlight]",
120
+ failed: "bg-th-loss-fill text-th-on-loss forced-colors:border-2 forced-colors:border-dashed forced-colors:border-[color:CanvasText]"
121
+ };
122
+ var STEP_SR_DEFAULT = { done: ", done", failed: ", failed" };
123
+ function pickStepFx(from, to) {
124
+ if (to === "done") return "done";
125
+ if (to === "failed") return "failed";
126
+ return from === to ? null : null;
127
+ }
128
+ function withFullText(text, label) {
129
+ if (typeof text !== "string") return label;
130
+ return /* @__PURE__ */ jsx(Tooltip, { tip: text, className: "nish-flow-label-tip max-w-full min-w-0", children: label });
131
+ }
132
+ function StepRow({
133
+ step,
134
+ index,
135
+ last,
136
+ sweeping,
137
+ statusWord
138
+ }) {
139
+ const nodeRef = useRef(null);
140
+ useTransitionFx(step.status, nodeRef, pickStepFx);
141
+ const { status } = step;
142
+ return /* @__PURE__ */ jsxs(
143
+ "li",
144
+ {
145
+ className: "nish-flow-step nish-flow-rise",
146
+ "data-status": status,
147
+ "aria-current": status === "active" ? "step" : void 0,
148
+ style: { "--nish-flow-delay": `${Math.min(index * 40, 400)}ms` },
149
+ children: [
150
+ /* @__PURE__ */ jsxs(
151
+ "span",
152
+ {
153
+ ref: nodeRef,
154
+ className: cn(
155
+ "nish-flow-node grid size-7 place-items-center rounded-full text-xs font-medium tabular-nums",
156
+ NODE_STATUS[status]
157
+ ),
158
+ "aria-hidden": "true",
159
+ children: [
160
+ status === "done" ? /* @__PURE__ */ jsx(CheckSvg, { size: 16 }) : status === "failed" ? /* @__PURE__ */ jsx(CrossSvg, { size: 14 }) : index + 1,
161
+ status === "active" ? /* @__PURE__ */ jsxs(Fragment, { children: [
162
+ /* @__PURE__ */ jsx("svg", { className: "nish-flow-arc text-th-accent", viewBox: "0 0 28 28", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx("circle", { cx: "14", cy: "14", r: "13", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeDasharray: "20 62" }) }),
163
+ /* @__PURE__ */ jsx("span", { className: "nish-flow-ripple" })
164
+ ] }) : null
165
+ ]
166
+ }
167
+ ),
168
+ /* @__PURE__ */ jsxs("span", { className: "nish-flow-text", children: [
169
+ withFullText(
170
+ step.label,
171
+ /* @__PURE__ */ jsxs(
172
+ "span",
173
+ {
174
+ className: cn(
175
+ "nish-flow-label text-sm",
176
+ status === "active" ? "font-medium text-th-hi" : status === "failed" ? "text-th-loss" : "text-th-hi2"
177
+ ),
178
+ children: [
179
+ step.label,
180
+ statusWord ? /* @__PURE__ */ jsx("span", { className: "sr-only", children: statusWord }) : null
181
+ ]
182
+ }
183
+ )
184
+ ),
185
+ step.meta != null ? /* @__PURE__ */ jsx("span", { className: "nish-flow-meta text-xs text-th-hi3", children: step.meta }) : null
186
+ ] }),
187
+ last ? null : /* @__PURE__ */ jsxs(
188
+ "span",
189
+ {
190
+ className: "nish-flow-conn",
191
+ "data-on": status === "done",
192
+ "aria-hidden": "true",
193
+ style: sweeping ? { "--nish-flow-delay": `${index * 60}ms` } : void 0,
194
+ children: [
195
+ /* @__PURE__ */ jsx("span", { className: "nish-flow-fill" }),
196
+ /* @__PURE__ */ jsx("span", { className: "nish-flow-shimmer" }),
197
+ /* @__PURE__ */ jsx("span", { className: "nish-flow-sweep" })
198
+ ]
199
+ }
200
+ )
201
+ ]
202
+ }
203
+ );
204
+ }
205
+ function FlowSteps({ steps, orientation = "auto", label, statusLabels, className, ref, ...rest }) {
206
+ const s = useNishStrings();
207
+ const allDone = steps.length > 0 && steps.every((s2) => s2.status === "done");
208
+ const prevAll = useRef(null);
209
+ const [sweeping, setSweeping] = useState(false);
210
+ useIsoLayoutEffect(() => {
211
+ const was = prevAll.current;
212
+ prevAll.current = allDone;
213
+ if (!allDone) {
214
+ setSweeping(false);
215
+ return;
216
+ }
217
+ if (was === false && steps.length > 1) {
218
+ setSweeping(true);
219
+ const timer = setTimeout(() => setSweeping(false), steps.length * 60 + 1e3);
220
+ return () => clearTimeout(timer);
221
+ }
222
+ }, [allDone]);
223
+ const orient = orientation === "auto" && steps.length > 8 ? "vertical" : orientation;
224
+ return /* @__PURE__ */ jsx("div", { ...rest, ref, className: cn("nish-flow-steps-box", className), children: /* @__PURE__ */ jsx("ol", { className: "nish-flow-steps", "data-orient": orient, "data-sweep": sweeping || void 0, "aria-label": label ?? s.progress, children: steps.map((step, i) => /* @__PURE__ */ jsx(
225
+ StepRow,
226
+ {
227
+ step,
228
+ index: i,
229
+ last: i === steps.length - 1,
230
+ sweeping,
231
+ statusWord: step.status === "done" || step.status === "failed" ? statusLabels?.[step.status] ?? STEP_SR_DEFAULT[step.status] : void 0
232
+ },
233
+ step.id
234
+ )) }) });
235
+ }
236
+ function StepBar({ total, done, active = false, label, className, ref, ...rest }) {
237
+ const s = useNishStrings();
238
+ const t = Number.isFinite(total) ? Math.max(0, Math.floor(total)) : 0;
239
+ const d = Number.isFinite(done) ? Math.min(t, Math.max(0, Math.floor(done))) : 0;
240
+ const props = {
241
+ ...rest,
242
+ ref,
243
+ role: "progressbar",
244
+ "aria-valuemin": 0,
245
+ "aria-valuemax": t,
246
+ "aria-valuenow": d,
247
+ "aria-label": label ?? s.progress
248
+ };
249
+ if (t > 12) {
250
+ return /* @__PURE__ */ jsxs("div", { ...props, className: cn("relative h-1.5 overflow-hidden rounded-full bg-th-line forced-colors:bg-[color:GrayText]", className), children: [
251
+ /* @__PURE__ */ jsx(
252
+ "div",
253
+ {
254
+ className: "h-full rounded-full bg-th-ok-fill motion-safe:transition-[width] motion-safe:duration-[400ms] forced-colors:bg-[color:Highlight]",
255
+ style: { width: `${d / t * 100}%` }
256
+ }
257
+ ),
258
+ active && d < t ? /* @__PURE__ */ jsx(
259
+ "div",
260
+ {
261
+ className: "absolute inset-y-0 rounded-full bg-th-accent motion-safe:animate-pulse forced-colors:bg-[color:Highlight]",
262
+ style: { insetInlineStart: `${d / t * 100}%`, width: `max(6px, ${100 / t}%)` }
263
+ }
264
+ ) : null
265
+ ] });
266
+ }
267
+ return /* @__PURE__ */ jsx("div", { ...props, className: cn("flex h-1.5 gap-[3px]", className), children: Array.from({ length: t }, (_, i) => /* @__PURE__ */ jsxs("div", { className: "relative h-full min-w-0 flex-1 overflow-hidden rounded-full bg-th-line forced-colors:bg-[color:GrayText]", children: [
268
+ /* @__PURE__ */ jsx(
269
+ "div",
270
+ {
271
+ className: cn(
272
+ "absolute inset-0 origin-left rounded-full bg-th-ok-fill motion-safe:transition-transform motion-safe:duration-[400ms] rtl:origin-right forced-colors:bg-[color:Highlight]",
273
+ i < d ? "scale-x-100" : "scale-x-0"
274
+ )
275
+ }
276
+ ),
277
+ i === d ? /* @__PURE__ */ jsx("div", { className: cn("absolute inset-0 rounded-full bg-th-accent forced-colors:bg-[color:Highlight]", active ? "motion-safe:animate-pulse" : "opacity-0") }) : null
278
+ ] }, i)) });
279
+ }
280
+ function TickerText({ text, as = "span", className, ref, ...rest }) {
281
+ const reduced = usePrefersReducedMotion();
282
+ const [state, setState] = useState({ text, prev: null });
283
+ let cur = state;
284
+ if (state.text !== text) {
285
+ cur = { text, prev: reduced ? null : state.text };
286
+ setState(cur);
287
+ }
288
+ const animating = cur.prev !== null;
289
+ useEffect(() => {
290
+ if (!animating) return;
291
+ const timer = setTimeout(() => setState((s) => s.prev === null ? s : { ...s, prev: null }), 300);
292
+ return () => clearTimeout(timer);
293
+ }, [animating, cur.text]);
294
+ const Tag = as;
295
+ return /* @__PURE__ */ jsxs(Tag, { ...rest, ref, className: cn("nish-flow-ticker grid min-w-0 overflow-hidden", className), title: cur.text, children: [
296
+ cur.prev !== null ? /* @__PURE__ */ jsx("span", { className: "nish-flow-ticker-out", "aria-hidden": "true", children: cur.prev }, `prev:${cur.prev}`) : null,
297
+ /* @__PURE__ */ jsx("span", { className: animating ? "nish-flow-ticker-in" : void 0, children: cur.text }, cur.text)
298
+ ] });
299
+ }
300
+ var STATE_WORD = {
301
+ queued: "Queued",
302
+ running: "Running",
303
+ done: "Done",
304
+ failed: "Failed"
305
+ };
306
+ var AGENT_STATE = {
307
+ queued: "border-dashed border-th-line opacity-70",
308
+ running: "border-th-accent",
309
+ done: "border-th-ok-fill/40",
310
+ failed: "border-th-loss-fill"
311
+ };
312
+ var MODEL_HUE = [
313
+ ["opus", "violet"],
314
+ ["sonnet", "sky"],
315
+ ["haiku", "emerald"],
316
+ ["fable", "amber"]
317
+ ];
318
+ function modelFamily(model) {
319
+ const m = model.toLowerCase();
320
+ return MODEL_HUE.find(([name]) => m.includes(name));
321
+ }
322
+ function ModelBadge({ model }) {
323
+ const family = modelFamily(model);
324
+ return /* @__PURE__ */ jsx(Badge, { size: "xs", hue: family?.[1], className: "shrink-0", children: family ? family[0] : model });
325
+ }
326
+ function pickAgentFx(from, to) {
327
+ if (from === to) return null;
328
+ if (to === "done") return "done";
329
+ if (to === "failed") return "failed";
330
+ return null;
331
+ }
332
+ function AgentIcon({ state }) {
333
+ if (state === "running") {
334
+ return /* @__PURE__ */ jsx("span", { className: "nish-flow-agent-icon grid size-5 shrink-0 place-items-center text-th-accent", children: /* @__PURE__ */ jsxs("svg", { className: "nish-flow-agent-spin", width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: [
335
+ /* @__PURE__ */ jsx("circle", { cx: "8", cy: "8", r: "6", stroke: "currentColor", strokeOpacity: "0.25", strokeWidth: "2" }),
336
+ /* @__PURE__ */ jsx("path", { d: "M8 2a6 6 0 0 1 6 6", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" })
337
+ ] }) });
338
+ }
339
+ if (state === "done") {
340
+ return /* @__PURE__ */ jsx("span", { className: "nish-flow-agent-icon grid size-5 shrink-0 place-items-center rounded-full bg-th-ok-fill text-th-on-ok", children: /* @__PURE__ */ jsx(CheckSvg, { size: 12 }) });
341
+ }
342
+ if (state === "failed") {
343
+ return /* @__PURE__ */ jsx("span", { className: "nish-flow-agent-icon grid size-5 shrink-0 place-items-center rounded-full bg-th-loss-fill text-th-on-loss", children: /* @__PURE__ */ jsx(CrossSvg, { size: 11 }) });
344
+ }
345
+ return /* @__PURE__ */ jsx("span", { className: "nish-flow-agent-icon grid size-5 shrink-0 place-items-center", children: /* @__PURE__ */ jsx("span", { className: "size-4 rounded-full border-2 border-dashed border-th-ghost" }) });
346
+ }
347
+ function AgentNode({ label, state, model, activity, meta, onClick, stateLabels, className, ref: refProp, ...rest }) {
348
+ const own = useRef(null);
349
+ const ref = useMergedRef(own, refProp);
350
+ useTransitionFx(state, own, pickAgentFx);
351
+ const aria = `${label}: ${stateLabels?.[state] ?? STATE_WORD[state]}`;
352
+ const classes = cn(
353
+ "nish-flow-agent block min-h-16 w-full min-w-0 rounded-xl border bg-th-surface p-3 text-start",
354
+ AGENT_STATE[state],
355
+ onClick && "cursor-pointer transition-colors hover:bg-th-elevated focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-th-accent",
356
+ className
357
+ );
358
+ const body = /* @__PURE__ */ jsxs(Fragment, { children: [
359
+ /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 items-start gap-2", children: [
360
+ /* @__PURE__ */ jsx(AgentIcon, { state }),
361
+ /* @__PURE__ */ jsx("span", { className: "line-clamp-2 min-w-0 flex-1 text-sm font-medium leading-5 text-th-hi [overflow-wrap:anywhere]", children: label }),
362
+ meta != null ? /* @__PURE__ */ jsx("span", { className: "shrink-0 text-xs leading-5 tabular-nums text-th-hi3", children: meta }) : null
363
+ ] }),
364
+ model || activity ? /* @__PURE__ */ jsxs("span", { className: "mt-1.5 flex min-w-0 items-center gap-2", children: [
365
+ model ? /* @__PURE__ */ jsx(ModelBadge, { model }) : null,
366
+ activity ? /* @__PURE__ */ jsx(TickerText, { as: "span", text: activity, className: "min-w-0 flex-1 text-xs text-th-hi3" }) : null
367
+ ] }) : null
368
+ ] });
369
+ if (onClick) {
370
+ return /* @__PURE__ */ jsx(
371
+ "button",
372
+ {
373
+ ...rest,
374
+ type: "button",
375
+ ref,
376
+ className: classes,
377
+ "data-state": state,
378
+ "aria-label": aria,
379
+ onClick,
380
+ children: body
381
+ }
382
+ );
383
+ }
384
+ return /* @__PURE__ */ jsx("article", { ...rest, ref, className: classes, "data-state": state, "aria-label": aria, children: body });
385
+ }
386
+ var OTHER_ID = "__nish-flow-other__";
387
+ function phaseState(agents) {
388
+ if (agents.length === 0) return "waiting";
389
+ if (agents.some((a) => a.state === "running")) return "active";
390
+ if (agents.every((a) => a.state === "done" || a.state === "failed")) return "done";
391
+ return "pending";
392
+ }
393
+ function PhaseConnector({ flowing }) {
394
+ return /* @__PURE__ */ jsxs("svg", { className: "nish-flow-phase-conn", "data-flow": flowing, viewBox: "0 0 24 12", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
395
+ /* @__PURE__ */ jsx("path", { className: "nish-flow-dashline", d: "M1 6h15", strokeDasharray: "3 3" }),
396
+ /* @__PURE__ */ jsx("path", { d: "M16 2.5L20.5 6 16 9.5" })
397
+ ] });
398
+ }
399
+ function WorkflowBoard({ phases, agents, label, otherLabel, waitingLabel, className, ref, ...rest }) {
400
+ const s = useNishStrings();
401
+ const otherTitle = otherLabel ?? s.other;
402
+ const fresh = useFreshIds(
403
+ agents.map((a) => a.id),
404
+ false
405
+ );
406
+ const columns = useMemo(() => {
407
+ const byId = /* @__PURE__ */ new Map();
408
+ const byTitle = /* @__PURE__ */ new Map();
409
+ for (const p of phases) {
410
+ if (!byId.has(p.id)) byId.set(p.id, p);
411
+ if (!byTitle.has(p.title)) byTitle.set(p.title, p);
412
+ }
413
+ const groups = /* @__PURE__ */ new Map();
414
+ const other = [];
415
+ for (const a of agents) {
416
+ const phase = a.phase === null ? void 0 : byId.get(a.phase) ?? byTitle.get(a.phase);
417
+ if (!phase) {
418
+ other.push(a);
419
+ continue;
420
+ }
421
+ const list = groups.get(phase.id);
422
+ if (list) list.push(a);
423
+ else groups.set(phase.id, [a]);
424
+ }
425
+ const cols = phases.map((phase) => {
426
+ const list = groups.get(phase.id) ?? [];
427
+ return { phase, agents: list, state: phaseState(list) };
428
+ });
429
+ const seen = /* @__PURE__ */ new Set();
430
+ for (const c of cols) {
431
+ if (seen.has(c.phase.id)) {
432
+ c.agents = [];
433
+ c.state = "waiting";
434
+ }
435
+ seen.add(c.phase.id);
436
+ }
437
+ if (other.length) cols.push({ phase: { id: OTHER_ID, title: otherTitle }, agents: other, state: phaseState(other) });
438
+ return cols;
439
+ }, [phases, agents, otherTitle]);
440
+ return /* @__PURE__ */ jsx("section", { ...rest, ref, "aria-label": label ?? s.workflow, className: cn("nish-flow-board-box", className), children: /* @__PURE__ */ jsx("div", { className: "nish-flow-board", children: columns.map((col, ci) => {
441
+ const { phase, state } = col;
442
+ const finished = col.agents.filter((a) => a.state === "done" || a.state === "failed").length;
443
+ const total = col.agents.length;
444
+ const next = columns[ci + 1];
445
+ const flowing = (state === "done" || state === "active") && next !== void 0 && (next.state === "waiting" || next.state === "pending" || next.state === "active");
446
+ return /* @__PURE__ */ jsxs(
447
+ "div",
448
+ {
449
+ role: "group",
450
+ "aria-label": phase.title,
451
+ "data-state": state,
452
+ className: cn(
453
+ "nish-flow-phase rounded-xl border bg-th-elevated/40 p-3",
454
+ state === "active" ? "border-th-accent/50" : "border-th-line"
455
+ ),
456
+ children: [
457
+ /* @__PURE__ */ jsxs("div", { className: cn("flex min-w-0 items-center gap-2", state === "waiting" && "opacity-60"), children: [
458
+ state === "done" ? /* @__PURE__ */ jsx("span", { className: "grid size-4 shrink-0 place-items-center rounded-full bg-th-ok-fill text-th-on-ok", children: /* @__PURE__ */ jsx(CheckSvg, { size: 10 }) }) : null,
459
+ /* @__PURE__ */ jsx("span", { className: cn("min-w-0 flex-1 truncate text-sm font-medium", state === "active" ? "text-th-accent" : "text-th-hi"), children: phase.title }),
460
+ phase.model ? /* @__PURE__ */ jsx(ModelBadge, { model: phase.model }) : null,
461
+ /* @__PURE__ */ jsxs("span", { className: "shrink-0 text-xs tabular-nums text-th-hi3", children: [
462
+ finished,
463
+ "/",
464
+ total
465
+ ] })
466
+ ] }),
467
+ /* @__PURE__ */ jsx(
468
+ "div",
469
+ {
470
+ className: cn("mt-2 h-1 overflow-hidden rounded-full bg-th-line forced-colors:bg-[color:GrayText]", state === "waiting" && "opacity-60"),
471
+ "aria-hidden": "true",
472
+ children: /* @__PURE__ */ jsx(
473
+ "div",
474
+ {
475
+ className: "h-full rounded-full bg-th-ok-fill motion-safe:transition-[width] motion-safe:duration-500 forced-colors:bg-[color:Highlight]",
476
+ style: { width: total ? `${finished / total * 100}%` : "0%" }
477
+ }
478
+ )
479
+ }
480
+ ),
481
+ phase.detail != null ? /* @__PURE__ */ jsx("div", { className: "mt-2 text-xs text-th-hi3", children: phase.detail }) : null,
482
+ /* @__PURE__ */ jsx("div", { className: "mt-3 flex min-w-0 flex-col gap-2", children: total === 0 ? /* @__PURE__ */ jsx("p", { className: "text-xs text-th-hi3", children: waitingLabel ?? s.waiting }) : col.agents.map((a, ai) => {
483
+ const { id, phase: _phase, ...node } = a;
484
+ return /* @__PURE__ */ jsx(
485
+ "div",
486
+ {
487
+ className: fresh.has(id) ? "nish-flow-rise" : void 0,
488
+ style: fresh.has(id) ? { "--nish-flow-delay": `${Math.min(ai * 60, 600)}ms` } : void 0,
489
+ children: /* @__PURE__ */ jsx(AgentNode, { ...node })
490
+ },
491
+ id
492
+ );
493
+ }) }),
494
+ next ? /* @__PURE__ */ jsx(PhaseConnector, { flowing }) : null
495
+ ]
496
+ },
497
+ phase.id
498
+ );
499
+ }) }) });
500
+ }
501
+ var FEED_DOT = {
502
+ neutral: "bg-th-ghost",
503
+ accent: "bg-th-accent",
504
+ ok: "bg-th-ok-fill",
505
+ warn: "bg-th-warn-fill",
506
+ loss: "bg-th-loss-fill"
507
+ };
508
+ var FEED_DOT_FORCED = "forced-colors:bg-[color:CanvasText]";
509
+ function ActivityFeed({ items, max = 50, now, label, empty, className, ref, ...rest }) {
510
+ const s = useNishStrings();
511
+ const internalNow = useNow(15e3);
512
+ const clock = now ?? internalNow;
513
+ const shown = useMemo(() => [...items].sort((a, b) => b.at - a.at).slice(0, Math.max(0, max)), [items, max]);
514
+ const fresh = useFreshIds(
515
+ shown.map((i) => i.id),
516
+ true
517
+ );
518
+ if (shown.length === 0) {
519
+ return /* @__PURE__ */ jsx("div", { ...rest, ref, className: cn("text-sm text-th-hi3", className), children: empty ?? s.noActivity });
520
+ }
521
+ return /* @__PURE__ */ jsx("ol", { ...rest, ref, className: cn("nish-flow-feed", className), "aria-label": label ?? s.activity, children: shown.map((item) => /* @__PURE__ */ jsx("li", { className: "nish-flow-feed-item", "data-fresh": fresh.has(item.id) || void 0, "data-tone": item.tone ?? "neutral", children: /* @__PURE__ */ jsx("div", { className: "nish-flow-feed-inner", children: /* @__PURE__ */ jsxs("div", { className: "nish-flow-feed-row", children: [
522
+ /* @__PURE__ */ jsx("span", { className: cn("nish-flow-feed-dot", FEED_DOT[item.tone ?? "neutral"], FEED_DOT_FORCED), "aria-hidden": "true" }),
523
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
524
+ /* @__PURE__ */ jsx("div", { className: "break-words text-sm text-th-hi2", children: item.text }),
525
+ item.source != null ? /* @__PURE__ */ jsx("div", { className: "break-words text-xs text-th-hi3", children: item.source }) : null
526
+ ] }),
527
+ /* @__PURE__ */ jsx("span", { className: "pt-0.5 text-end text-xs tabular-nums text-th-hi3", children: ago(item.at, { now: clock, style: "short" }) })
528
+ ] }) }) }, item.id)) });
529
+ }
530
+ var ENTER_MS = 400;
531
+ var MOVE_MS = 300;
532
+ var MAX_ANIMATED = 50;
533
+ function reconcile(prev, items, getKey, animate) {
534
+ const prevMap = new Map(prev.map((e) => [e.key, e]));
535
+ const seen = /* @__PURE__ */ new Set();
536
+ const next = [];
537
+ for (const item of items) {
538
+ const key = getKey(item);
539
+ if (seen.has(key)) {
540
+ warnDev(`AnimatedList: duplicate key "${key}"; only the first item with it is shown.`);
541
+ continue;
542
+ }
543
+ seen.add(key);
544
+ const old = prevMap.get(key);
545
+ const phase = !old ? animate ? "enter" : "idle" : old.phase === "exit" ? "idle" : old.phase;
546
+ next.push({ key, item, phase: animate ? phase : "idle" });
547
+ }
548
+ if (!animate) return next;
549
+ const exitAfter = /* @__PURE__ */ new Map();
550
+ const leading = [];
551
+ prev.forEach((e, i) => {
552
+ if (seen.has(e.key)) return;
553
+ const gone = e.phase === "exit" ? e : { ...e, phase: "exit" };
554
+ if (i === 0) leading.push(gone);
555
+ else exitAfter.set(prev[i - 1].key, gone);
556
+ });
557
+ if (leading.length === 0 && exitAfter.size === 0) return next;
558
+ const out = [];
559
+ const trail = (key) => {
560
+ for (let gone = exitAfter.get(key); gone; gone = exitAfter.get(gone.key)) out.push(gone);
561
+ };
562
+ for (const e of leading) {
563
+ out.push(e);
564
+ trail(e.key);
565
+ }
566
+ for (const e of next) {
567
+ out.push(e);
568
+ trail(e.key);
569
+ }
570
+ return out;
571
+ }
572
+ function AnimatedList({
573
+ items,
574
+ getKey,
575
+ children,
576
+ exitMs = 420,
577
+ as = "ul",
578
+ className,
579
+ itemClassName,
580
+ ref,
581
+ ...rest
582
+ }) {
583
+ const reduced = usePrefersReducedMotion();
584
+ const [state, setState] = useState(() => ({
585
+ src: items,
586
+ reduced,
587
+ entries: reconcile([], items, getKey, false)
588
+ }));
589
+ let current = state;
590
+ if (state.src !== items || state.reduced !== reduced) {
591
+ current = { src: items, reduced, entries: reconcile(state.entries, items, getKey, !reduced) };
592
+ setState(current);
593
+ }
594
+ const entries = current.entries;
595
+ const els = useRef(/* @__PURE__ */ new Map());
596
+ const rects = useRef(/* @__PURE__ */ new Map());
597
+ const anims = useRef(/* @__PURE__ */ new Map());
598
+ const lastKeys = useRef(null);
599
+ const timers = useRef(/* @__PURE__ */ new Map());
600
+ const itemRef = useCallback((el) => {
601
+ const key = el?.getAttribute("data-nish-key");
602
+ if (!el || key == null) return;
603
+ els.current.set(key, el);
604
+ return () => {
605
+ if (els.current.get(key) === el) els.current.delete(key);
606
+ };
607
+ }, []);
608
+ useEffect(() => {
609
+ const wanted = /* @__PURE__ */ new Set();
610
+ for (const e of entries) {
611
+ if (e.phase === "idle") continue;
612
+ const id = `${e.phase}:${e.key}`;
613
+ wanted.add(id);
614
+ if (timers.current.has(id)) continue;
615
+ timers.current.set(
616
+ id,
617
+ setTimeout(
618
+ () => {
619
+ timers.current.delete(id);
620
+ if (e.phase === "exit") {
621
+ const fresh = /* @__PURE__ */ new Map();
622
+ els.current.forEach((el, k) => fresh.set(k, { x: el.offsetLeft, y: el.offsetTop }));
623
+ rects.current = fresh;
624
+ }
625
+ setState((s) => ({
626
+ ...s,
627
+ entries: e.phase === "exit" ? s.entries.filter((x) => !(x.key === e.key && x.phase === "exit")) : s.entries.map((x) => x.key === e.key && x.phase === "enter" ? { ...x, phase: "idle" } : x)
628
+ }));
629
+ },
630
+ e.phase === "exit" ? exitMs : ENTER_MS
631
+ )
632
+ );
633
+ }
634
+ timers.current.forEach((timer, id) => {
635
+ if (!wanted.has(id)) {
636
+ clearTimeout(timer);
637
+ timers.current.delete(id);
638
+ }
639
+ });
640
+ }, [entries, exitMs]);
641
+ useEffect(
642
+ () => () => {
643
+ timers.current.forEach((timer) => clearTimeout(timer));
644
+ timers.current.clear();
645
+ },
646
+ []
647
+ );
648
+ useIsoLayoutEffect(() => {
649
+ const next = /* @__PURE__ */ new Map();
650
+ els.current.forEach((el, k) => next.set(k, { x: el.offsetLeft, y: el.offsetTop }));
651
+ const keyList = entries.map((e) => e.key).join("\n");
652
+ const reordered = lastKeys.current !== null && lastKeys.current !== keyList;
653
+ lastKeys.current = keyList;
654
+ const live = new Set(entries.map((e) => e.key));
655
+ anims.current.forEach((anim, k) => {
656
+ if (!live.has(k)) {
657
+ anim.cancel();
658
+ anims.current.delete(k);
659
+ }
660
+ });
661
+ const active = typeof document !== "undefined" ? document.activeElement : null;
662
+ if (active) {
663
+ const ei = entries.findIndex((e) => e.phase === "exit" && els.current.get(e.key)?.contains(active));
664
+ if (ei !== -1) {
665
+ const target = [...entries.slice(ei + 1), ...entries.slice(0, ei).reverse()].find((e) => e.phase !== "exit");
666
+ const focusable = target ? els.current.get(target.key)?.querySelector('a[href], button, input, select, textarea, [tabindex]:not([tabindex="-1"])') : null;
667
+ if (focusable) focusable.focus({ preventScroll: true });
668
+ }
669
+ }
670
+ if (!reduced && reordered) {
671
+ const moves = [];
672
+ for (const e of entries) {
673
+ if (e.phase === "exit") continue;
674
+ const a = rects.current.get(e.key);
675
+ const b = next.get(e.key);
676
+ const el = els.current.get(e.key);
677
+ if (!a || !b || !el || typeof el.animate !== "function") continue;
678
+ const dx = a.x - b.x;
679
+ const dy = a.y - b.y;
680
+ const running = anims.current.get(e.key);
681
+ if (!running && Math.abs(dx) < 1 && Math.abs(dy) < 1) continue;
682
+ moves.push({ key: e.key, el, dx, dy, running });
683
+ }
684
+ const drawn = moves.map((m) => m.el.getBoundingClientRect());
685
+ for (const m of moves) {
686
+ if (!m.running) continue;
687
+ m.running.cancel();
688
+ anims.current.delete(m.key);
689
+ }
690
+ const settled = moves.map((m) => m.running ? m.el.getBoundingClientRect() : null);
691
+ const vw = window.innerWidth;
692
+ const vh = window.innerHeight;
693
+ const inView = (r, dx, dy) => r.bottom + dy >= 0 && r.top + dy <= vh && r.right + dx >= 0 && r.left + dx <= vw;
694
+ let started = 0;
695
+ moves.forEach((m, i) => {
696
+ const r1 = drawn[i];
697
+ const r2 = settled[i];
698
+ let { dx, dy } = m;
699
+ if (r2) {
700
+ dx += r1.left - r2.left;
701
+ dy += r1.top - r2.top;
702
+ }
703
+ if (Math.abs(dx) < 1 && Math.abs(dy) < 1) return;
704
+ if (started >= MAX_ANIMATED) return;
705
+ const home = r2 ?? r1;
706
+ if (!inView(home, 0, 0) && !inView(home, dx, dy)) return;
707
+ started++;
708
+ const anim = m.el.animate([{ transform: `translate(${dx}px, ${dy}px)` }, { transform: "none" }], {
709
+ duration: MOVE_MS,
710
+ easing: EASE
711
+ });
712
+ anims.current.set(m.key, anim);
713
+ anim.onfinish = () => {
714
+ if (anims.current.get(m.key) === anim) anims.current.delete(m.key);
715
+ };
716
+ });
717
+ }
718
+ rects.current = next;
719
+ }, [entries, reduced]);
720
+ const Root = as;
721
+ const Item = as === "div" ? "div" : "li";
722
+ return /* @__PURE__ */ jsx(Root, { ...rest, ref, className, children: entries.map((e) => /* @__PURE__ */ jsx(
723
+ Item,
724
+ {
725
+ ref: itemRef,
726
+ "data-nish-key": e.key,
727
+ className: cn("nish-flow-item", itemClassName),
728
+ "data-phase": e.phase,
729
+ "aria-hidden": e.phase === "exit" || void 0,
730
+ inert: e.phase === "exit" || void 0,
731
+ style: e.phase === "exit" ? { "--nish-flow-exit-ms": `${exitMs}ms` } : void 0,
732
+ children: /* @__PURE__ */ jsx("div", { className: "nish-flow-item-inner", children: children(e.item, e.phase) })
733
+ },
734
+ e.key
735
+ )) });
736
+ }
737
+ export {
738
+ ActivityFeed,
739
+ AgentNode,
740
+ AnimatedList,
741
+ FlowSteps,
742
+ StepBar,
743
+ TickerText,
744
+ WorkflowBoard,
745
+ usePrefersReducedMotion
746
+ };