@hamsterbase/ui 0.1.0 → 0.2.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.
package/dist/index.js CHANGED
@@ -1,15 +1,21 @@
1
+ "use client";
1
2
  import { clsx } from "clsx/lite";
2
3
  import { jsx, jsxs } from "react/jsx-runtime";
3
- import { forwardRef, useImperativeHandle, useLayoutEffect, useRef, useState } from "react";
4
- import { Check, Minus } from "lucide-react";
4
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
5
+ import { Check, CircleAlert, Info, Minus, X } from "lucide-react";
6
+ // src/utils/focus.ts
7
+ /** 元素自身获得键盘焦点时。 */
8
+ var focusRing = "focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-hub-focus-ring";
9
+ /** 前一个兄弟节点(peer,如隐藏的原生 input)获得键盘焦点时。 */
10
+ var peerFocusRing = "peer-focus-visible:outline-2 peer-focus-visible:outline-solid peer-focus-visible:outline-offset-2 peer-focus-visible:outline-hub-focus-ring";
5
11
  // src/components/Button/styles.ts
6
12
  var buttonStyles = {
7
- base: clsx("inline-flex items-center justify-center gap-1.5", "select-none whitespace-nowrap border rounded-full", "font-sans font-medium leading-4", "transition-colors duration-150 motion-reduce:transition-none", "focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-hub-focus-ring", "disabled:cursor-not-allowed disabled:opacity-50"),
13
+ Root: clsx("inline-flex items-center justify-center gap-1.5", "select-none whitespace-nowrap border rounded-full", "font-sans font-medium leading-4", "transition-colors duration-(--hub-duration-normal) motion-reduce:transition-none", focusRing, "disabled:cursor-not-allowed disabled:opacity-50"),
8
14
  variants: {
9
- primary: "border-transparent bg-hub-primary-solid text-hub-primary-contrast enabled:hover:bg-hub-primary-solid/90",
15
+ primary: "border-transparent bg-hub-primary-solid text-hub-primary-contrast enabled:hover:bg-hub-primary-solid-hover",
10
16
  secondary: "border-hub-border bg-hub-bg-panel text-hub-fg enabled:hover:bg-hub-bg-muted",
11
17
  ghost: "border-transparent bg-transparent text-hub-fg enabled:hover:bg-hub-bg-muted",
12
- danger: "border-transparent bg-hub-error-solid text-hub-error-contrast enabled:hover:bg-hub-error-solid/90"
18
+ danger: "border-transparent bg-hub-error-solid text-hub-error-contrast enabled:hover:bg-hub-error-solid-hover"
13
19
  },
14
20
  sizes: {
15
21
  sm: "h-6 px-2.5 text-hub-sm",
@@ -22,43 +28,47 @@ function Button({ variant = "primary", size = "md", type = "button", className,
22
28
  return /* @__PURE__ */ jsx("button", {
23
29
  ...props,
24
30
  type,
25
- className: clsx(buttonStyles.base, buttonStyles.variants[variant], buttonStyles.sizes[size], className)
31
+ className: clsx(buttonStyles.Root, buttonStyles.variants[variant], buttonStyles.sizes[size], className)
26
32
  });
27
33
  }
28
34
  // src/components/IconButton/styles.ts
29
35
  var iconButtonStyles = {
30
- base: clsx("inline-grid flex-none select-none place-items-center rounded-full border-0", "transition-colors duration-100 motion-reduce:transition-none", "focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-hub-focus-ring", "disabled:cursor-not-allowed disabled:opacity-50", "aria-pressed:bg-hub-bg-muted aria-pressed:text-hub-fg", "aria-pressed:enabled:hover:bg-hub-bg-emphasized aria-pressed:enabled:active:bg-hub-bg-emphasized"),
36
+ Root: clsx("inline-grid flex-none select-none place-items-center rounded-full border-0", "transition-colors duration-(--hub-duration-fast) motion-reduce:transition-none", focusRing, "disabled:cursor-not-allowed disabled:opacity-50", "aria-pressed:bg-hub-bg-muted aria-pressed:text-hub-fg", "aria-pressed:enabled:hover:bg-hub-bg-emphasized aria-pressed:enabled:active:bg-hub-bg-emphasized"),
31
37
  sizes: {
32
38
  sm: "size-6 [&_svg]:size-3.5",
33
39
  md: "size-7 [&_svg]:size-3.5",
34
40
  lg: "size-8 [&_svg]:size-4"
35
41
  },
36
42
  variants: {
37
- primary: clsx("bg-hub-bg-panel text-hub-fg shadow-hub-sm", "enabled:hover:bg-hub-bg-muted enabled:active:bg-hub-bg-emphasized"),
38
- secondary: clsx("bg-transparent text-hub-fg-muted", "enabled:hover:bg-hub-bg-muted enabled:hover:text-hub-fg enabled:active:bg-hub-bg-muted")
43
+ surface: clsx("bg-hub-bg-panel text-hub-fg shadow-hub-sm", "enabled:hover:bg-hub-bg-muted enabled:active:bg-hub-bg-emphasized"),
44
+ ghost: clsx("bg-transparent text-hub-fg-muted", "enabled:hover:bg-hub-bg-muted enabled:hover:text-hub-fg enabled:active:bg-hub-bg-muted")
39
45
  }
40
46
  };
41
47
  // src/components/IconButton/IconButton.tsx
42
- function IconButton({ className, size = "md", type = "button", variant = "primary", pressed, ...props }) {
48
+ function IconButton({ className, size = "md", type = "button", variant = "surface", pressed, ...props }) {
43
49
  return /* @__PURE__ */ jsx("button", {
44
50
  ...props,
45
51
  type,
46
52
  "aria-pressed": pressed,
47
- className: clsx(iconButtonStyles.base, iconButtonStyles.sizes[size], iconButtonStyles.variants[variant], className)
53
+ className: clsx(iconButtonStyles.Root, iconButtonStyles.sizes[size], iconButtonStyles.variants[variant], className)
48
54
  });
49
55
  }
50
56
  // src/components/Checkbox/styles.ts
51
57
  var checkboxStyles = {
52
58
  Root: "group/checkbox relative inline-flex size-3.5 flex-none align-middle",
53
- Input: clsx("peer absolute inset-0 z-10 m-0 size-full cursor-pointer opacity-0", "disabled:cursor-default"),
54
- Surface: clsx("pointer-events-none box-border grid size-full place-items-center rounded-[3px] border", "border-hub-border-strong bg-transparent text-hub-primary-contrast", "transition-colors duration-[80ms] ease-out motion-reduce:transition-none", "peer-checked:border-hub-primary-solid peer-checked:bg-hub-primary-solid", "peer-indeterminate:border-hub-primary-solid peer-indeterminate:bg-hub-primary-solid", "peer-focus-visible:outline-2 peer-focus-visible:outline-offset-2 peer-focus-visible:outline-hub-focus-ring", "peer-disabled:opacity-40"),
59
+ Input: clsx("peer absolute inset-0 z-(--hub-z-raised) m-0 size-full cursor-pointer opacity-0", "disabled:cursor-default"),
60
+ Surface: clsx("pointer-events-none box-border grid size-full place-items-center rounded-hub-sm border", "border-hub-border-strong bg-transparent text-hub-primary-contrast", "transition-colors duration-(--hub-duration-fast) ease-out motion-reduce:transition-none", "peer-checked:border-hub-primary-solid peer-checked:bg-hub-primary-solid", "peer-indeterminate:border-hub-primary-solid peer-indeterminate:bg-hub-primary-solid", peerFocusRing, "peer-disabled:opacity-50"),
55
61
  Check: "hidden [grid-area:1/1] group-has-[:checked:not(:indeterminate)]/checkbox:block",
56
62
  Mixed: "hidden [grid-area:1/1] group-has-[:indeterminate]/checkbox:block"
57
63
  };
58
64
  // src/components/Checkbox/Checkbox.tsx
59
- var Checkbox = forwardRef(function Checkbox({ indeterminate = false, className, ...props }, ref) {
65
+ function Checkbox({ indeterminate = false, className, ref, ...props }) {
60
66
  const input = useRef(null);
61
- useImperativeHandle(ref, () => input.current, []);
67
+ const setInput = useCallback((node) => {
68
+ input.current = node;
69
+ if (typeof ref === "function") return ref(node);
70
+ if (ref) ref.current = node;
71
+ }, [ref]);
62
72
  useLayoutEffect(() => {
63
73
  if (input.current) input.current.indeterminate = indeterminate;
64
74
  }, [indeterminate]);
@@ -66,7 +76,7 @@ var Checkbox = forwardRef(function Checkbox({ indeterminate = false, className,
66
76
  className: clsx(checkboxStyles.Root, className),
67
77
  children: [/* @__PURE__ */ jsx("input", {
68
78
  ...props,
69
- ref: input,
79
+ ref: setInput,
70
80
  type: "checkbox",
71
81
  className: checkboxStyles.Input
72
82
  }), /* @__PURE__ */ jsxs("span", {
@@ -83,68 +93,82 @@ var Checkbox = forwardRef(function Checkbox({ indeterminate = false, className,
83
93
  })]
84
94
  })]
85
95
  });
86
- });
96
+ }
87
97
  // src/components/Divider/styles.ts
88
98
  var dividerStyles = {
89
99
  Root: "pointer-events-none block flex-none",
90
- horizontal: "h-[0.5px] w-full",
91
- vertical: "w-[0.5px] self-stretch",
92
- default: "bg-hub-border",
93
- subtle: "bg-hub-border/50"
100
+ orientations: {
101
+ horizontal: "h-(--hub-hairline) w-full",
102
+ vertical: "w-(--hub-hairline) self-stretch"
103
+ },
104
+ tones: {
105
+ default: "bg-hub-border",
106
+ subtle: "bg-hub-border-subtle"
107
+ }
94
108
  };
95
109
  // src/components/Divider/Divider.tsx
96
- var Divider = forwardRef(function Divider({ orientation = "horizontal", tone = "default", edge, inset = 0, length, className, style, ...props }, ref) {
97
- const direction = edge ? edge === "left" || edge === "right" ? "vertical" : "horizontal" : orientation;
98
- const horizontal = direction === "horizontal";
99
- const geometry = edge ? {
110
+ /** 贴边:绝对定位到容器的一条边,inset 为两端内缩。 */
111
+ function edgeGeometry(edge, horizontal, inset, length) {
112
+ return horizontal ? {
100
113
  [edge]: 0,
101
- ...horizontal ? {
102
- left: inset,
103
- right: inset,
104
- width: length ?? "auto"
105
- } : {
106
- top: inset,
107
- bottom: inset,
108
- height: length
109
- }
114
+ left: inset,
115
+ right: inset,
116
+ width: length ?? "auto"
110
117
  } : {
111
- ...horizontal ? {
112
- marginInline: inset,
113
- width: length ?? (inset ? `calc(100% - ${inset * 2}px)` : void 0)
114
- } : {
115
- marginBlock: inset,
116
- height: length
117
- },
118
- ...length === void 0 ? {} : { alignSelf: "center" }
118
+ [edge]: 0,
119
+ top: inset,
120
+ bottom: inset,
121
+ height: length
122
+ };
123
+ }
124
+ /** 文档流内:inset 为两端外边距;指定 length 时在交叉轴上居中。 */
125
+ function flowGeometry(horizontal, inset, length) {
126
+ const centered = length === void 0 ? {} : { alignSelf: "center" };
127
+ if (!horizontal) return {
128
+ marginBlock: inset,
129
+ height: length,
130
+ ...centered
119
131
  };
132
+ const fill = inset ? `calc(100% - ${inset * 2}px)` : void 0;
133
+ return {
134
+ marginInline: inset,
135
+ width: length ?? fill,
136
+ ...centered
137
+ };
138
+ }
139
+ function Divider({ orientation = "horizontal", tone = "default", edge, inset = 0, length, className, style, ...props }) {
140
+ const direction = edge ? edge === "left" || edge === "right" ? "vertical" : "horizontal" : orientation;
141
+ const horizontal = direction === "horizontal";
142
+ const geometry = edge ? edgeGeometry(edge, horizontal, inset, length) : flowGeometry(horizontal, inset, length);
120
143
  return /* @__PURE__ */ jsx("span", {
121
144
  ...props,
122
- ref,
123
145
  "aria-hidden": "true",
124
146
  "data-divider": "",
125
147
  "data-orientation": direction,
126
148
  "data-tone": tone,
127
149
  "data-edge": edge,
128
- className: clsx(dividerStyles.Root, dividerStyles[direction], dividerStyles[tone], edge && "absolute", className),
150
+ className: clsx(dividerStyles.Root, dividerStyles.orientations[direction], dividerStyles.tones[tone], edge && "absolute", className),
129
151
  style: {
130
152
  ...geometry,
131
153
  ...style
132
154
  }
133
155
  });
134
- });
156
+ }
135
157
  // src/components/ResizeHandle/styles.ts
136
- var line = "pointer-events-none absolute inset-y-0 left-[3px]";
158
+ var line = "pointer-events-none absolute inset-y-0 left-[calc((var(--hub-hit-area)_-_1px)_/_2)]";
137
159
  var resizeHandleStyles = {
138
- Root: clsx("group/resize absolute z-10 w-[7px] touch-none select-none cursor-col-resize outline-none"),
139
- left: "left-[-3.5px]",
140
- right: "right-[-3.5px]",
160
+ Root: clsx("group/resize absolute z-(--hub-z-raised) w-(--hub-hit-area) touch-none select-none cursor-col-resize outline-none"),
161
+ edges: {
162
+ left: "left-[calc(var(--hub-hit-area)_/_-2)]",
163
+ right: "right-[calc(var(--hub-hit-area)_/_-2)]"
164
+ },
141
165
  Line: line,
142
- Feedback: clsx(line, "w-px origin-left scale-x-50 overflow-hidden bg-hub-border opacity-0", "[mask-image:linear-gradient(transparent,black_10%,black_90%,transparent)]", "transition-opacity duration-250 ease-in-out motion-reduce:transition-none", "group-hover/resize:opacity-100 group-data-[dragging=true]/resize:opacity-100", "group-focus-visible/resize:opacity-100"),
166
+ Feedback: clsx(line, "w-px origin-left scale-x-50 overflow-hidden bg-hub-border opacity-0", "[mask-image:linear-gradient(transparent,black_10%,black_90%,transparent)]", "transition-opacity duration-(--hub-duration-slow) ease-in-out motion-reduce:transition-none", "group-hover/resize:opacity-100 group-data-[dragging=true]/resize:opacity-100", "group-focus-visible/resize:opacity-100"),
143
167
  Gradient: clsx("absolute -top-1/2 left-0 h-[200%] w-full bg-hub-fg", "[mask-image:linear-gradient(transparent_5%,black_40%,black_60%,transparent_95%)]"),
144
- DragShield: "fixed inset-0 z-40 cursor-col-resize"
168
+ DragShield: "fixed inset-0 z-(--hub-z-overlay) cursor-col-resize"
145
169
  };
146
170
  // src/components/ResizeHandle/ResizeHandle.tsx
147
- var ResizeHandle = forwardRef(function ResizeHandle({ label, controls, value, min, max, defaultValue, showDivider = true, inset = 0, edge = "right", onChange, className, style, ...props }, ref) {
171
+ function ResizeHandle({ label, controls, value, min, max, defaultValue, step = 16, showDivider = true, inset = 0, edge = "right", onChange, className, style, ...props }) {
148
172
  const sign = edge === "right" ? 1 : -1;
149
173
  const drag = useRef(void 0);
150
174
  const feedback = useRef(null);
@@ -156,7 +180,6 @@ var ResizeHandle = forwardRef(function ResizeHandle({ label, controls, value, mi
156
180
  const resize = (width) => onChange(Math.max(min, Math.min(max, width)));
157
181
  return /* @__PURE__ */ jsxs("div", {
158
182
  ...props,
159
- ref,
160
183
  role: "separator",
161
184
  "aria-label": label,
162
185
  "aria-controls": controls,
@@ -165,7 +188,7 @@ var ResizeHandle = forwardRef(function ResizeHandle({ label, controls, value, mi
165
188
  "aria-valuemax": max,
166
189
  "aria-valuenow": value,
167
190
  tabIndex: 0,
168
- className: clsx(resizeHandleStyles.Root, resizeHandleStyles[edge], className),
191
+ className: clsx(resizeHandleStyles.Root, resizeHandleStyles.edges[edge], className),
169
192
  style: {
170
193
  insetBlock: inset,
171
194
  ...style
@@ -176,7 +199,12 @@ var ResizeHandle = forwardRef(function ResizeHandle({ label, controls, value, mi
176
199
  if (defaultValue !== void 0) resize(defaultValue);
177
200
  },
178
201
  onKeyDown: (event) => {
179
- const width = event.key === "Home" ? min : event.key === "End" ? max : void 0;
202
+ const width = {
203
+ Home: min,
204
+ End: max,
205
+ ArrowLeft: value - step * sign,
206
+ ArrowRight: value + step * sign
207
+ }[event.key];
180
208
  if (width === void 0) return;
181
209
  event.preventDefault();
182
210
  event.stopPropagation();
@@ -235,5 +263,237 @@ var ResizeHandle = forwardRef(function ResizeHandle({ label, controls, value, mi
235
263
  }) : null
236
264
  ]
237
265
  });
238
- });
239
- export { Button, Checkbox, Divider, IconButton, ResizeHandle };
266
+ }
267
+ // src/components/Toast/styles.ts
268
+ var toastStyles = {
269
+ Viewport: clsx("fixed bottom-6 right-6 z-(--hub-z-toast)", "flex max-w-[calc(100vw_-_var(--hub-float-gutter)_*_2)] flex-col items-end gap-2"),
270
+ Root: clsx("animate-[hub-toast-in_var(--hub-duration-enter)_ease]", "data-closing:pointer-events-none data-closing:animate-[hub-toast-out_var(--hub-duration-exit)_ease_forwards]", "motion-reduce:animate-none motion-reduce:data-closing:animate-none"),
271
+ Card: clsx("box-border flex w-fit max-w-[min(var(--hub-float-width),calc(100vw_-_var(--hub-float-gutter)_*_2))] items-start gap-2", "rounded-hub-lg border-(length:--hub-hairline) border-solid border-hub-border bg-hub-bg-panel p-3 shadow-hub-md", "font-sans text-hub-md leading-4 text-hub-fg", "data-expanded:w-(--hub-float-width)"),
272
+ icons: {
273
+ info: "size-4 shrink-0 text-hub-fg-muted",
274
+ success: clsx("grid size-4 shrink-0 place-items-center rounded-full", "bg-hub-success-solid text-hub-success-contrast"),
275
+ error: "size-4 shrink-0 text-hub-error-solid"
276
+ },
277
+ Content: "min-w-0 flex-1 break-words",
278
+ Message: "font-medium",
279
+ Description: "mt-2 line-clamp-2 leading-5 text-hub-fg-muted",
280
+ Action: clsx("mt-3 block cursor-pointer border-0 bg-transparent p-0", "font-sans text-hub-md leading-5 text-hub-primary-solid", "enabled:hover:underline", focusRing, "disabled:cursor-not-allowed disabled:opacity-50"),
281
+ Close: "-m-1"
282
+ };
283
+ // src/components/Toast/Toast.tsx
284
+ /** 读取 CSS 变量里的时长(ms 或 s),返回毫秒;动效时长只在样式中定义。 */
285
+ function cssDuration(element, name) {
286
+ const value = getComputedStyle(element).getPropertyValue(name).trim();
287
+ return (value.endsWith("ms") ? parseFloat(value) : parseFloat(value) * 1e3) || 0;
288
+ }
289
+ var reducedMotion = () => matchMedia("(prefers-reduced-motion: reduce)").matches;
290
+ function Toast({ message, description, variant = "info", action, duration = variant === "error" ? 8e3 : 4e3, revision = 0, closeLabel, onDismiss, className, onMouseEnter, onMouseLeave, onFocus, onBlur, ...props }) {
291
+ const card = useRef(null);
292
+ const previousRevision = useRef(revision);
293
+ const dismiss = useRef(onDismiss);
294
+ dismiss.current = onDismiss;
295
+ const [hovered, setHovered] = useState(false);
296
+ const [focused, setFocused] = useState(false);
297
+ const [busy, setBusy] = useState(false);
298
+ const [closing, setClosing] = useState(false);
299
+ const paused = hovered || focused;
300
+ useEffect(() => {
301
+ if (previousRevision.current === revision) return;
302
+ previousRevision.current = revision;
303
+ setClosing(false);
304
+ const element = card.current;
305
+ if (!element || reducedMotion()) return;
306
+ const animation = element.animate([
307
+ {
308
+ transform: "scale(1)",
309
+ easing: "ease-out",
310
+ offset: 0
311
+ },
312
+ {
313
+ transform: "scale(1.05)",
314
+ easing: "linear",
315
+ offset: .125
316
+ },
317
+ {
318
+ transform: "scale(1.05)",
319
+ easing: "ease-in-out",
320
+ offset: .25
321
+ },
322
+ {
323
+ transform: "scale(1)",
324
+ offset: 1
325
+ }
326
+ ], { duration: cssDuration(element, "--hub-duration-emphasis") });
327
+ return () => animation.cancel();
328
+ }, [revision]);
329
+ useEffect(() => {
330
+ if (!duration || paused || busy) return;
331
+ const timer = setTimeout(() => setClosing(true), duration);
332
+ return () => clearTimeout(timer);
333
+ }, [
334
+ duration,
335
+ revision,
336
+ paused,
337
+ busy
338
+ ]);
339
+ useEffect(() => {
340
+ if (!closing) return;
341
+ let cancelled = false;
342
+ const animations = card.current?.parentElement?.getAnimations() ?? [];
343
+ Promise.allSettled(animations.map((animation) => animation.finished)).then(() => {
344
+ if (!cancelled) dismiss.current();
345
+ });
346
+ return () => {
347
+ cancelled = true;
348
+ };
349
+ }, [closing]);
350
+ const runAction = async () => {
351
+ if (busy || !action) return;
352
+ setBusy(true);
353
+ try {
354
+ await action.onClick();
355
+ setClosing(true);
356
+ } finally {
357
+ setBusy(false);
358
+ }
359
+ };
360
+ return /* @__PURE__ */ jsx("div", {
361
+ ...props,
362
+ className: clsx(toastStyles.Root, className),
363
+ "data-closing": closing || void 0,
364
+ onMouseEnter: (event) => {
365
+ setHovered(true);
366
+ onMouseEnter?.(event);
367
+ },
368
+ onMouseLeave: (event) => {
369
+ setHovered(false);
370
+ onMouseLeave?.(event);
371
+ },
372
+ onFocus: (event) => {
373
+ setFocused(true);
374
+ onFocus?.(event);
375
+ },
376
+ onBlur: (event) => {
377
+ if (!event.currentTarget.contains(event.relatedTarget)) setFocused(false);
378
+ onBlur?.(event);
379
+ },
380
+ children: /* @__PURE__ */ jsxs("div", {
381
+ ref: card,
382
+ className: toastStyles.Card,
383
+ "data-variant": variant,
384
+ "data-expanded": Boolean(description || action) || void 0,
385
+ children: [
386
+ /* @__PURE__ */ jsx("span", {
387
+ className: toastStyles.icons[variant],
388
+ children: variant === "success" ? /* @__PURE__ */ jsx(Check, {
389
+ size: 11,
390
+ strokeWidth: 3,
391
+ "aria-hidden": true
392
+ }) : variant === "error" ? /* @__PURE__ */ jsx(CircleAlert, {
393
+ size: 16,
394
+ "aria-hidden": true
395
+ }) : /* @__PURE__ */ jsx(Info, {
396
+ size: 16,
397
+ "aria-hidden": true
398
+ })
399
+ }),
400
+ /* @__PURE__ */ jsxs("div", {
401
+ className: toastStyles.Content,
402
+ children: [
403
+ /* @__PURE__ */ jsx("div", {
404
+ role: variant === "error" ? "alert" : "status",
405
+ "aria-atomic": "true",
406
+ className: toastStyles.Message,
407
+ children: message
408
+ }),
409
+ description && /* @__PURE__ */ jsx("div", {
410
+ className: toastStyles.Description,
411
+ children: description
412
+ }),
413
+ action && /* @__PURE__ */ jsx("button", {
414
+ type: "button",
415
+ className: toastStyles.Action,
416
+ disabled: busy,
417
+ onClick: () => void runAction(),
418
+ children: action.label
419
+ })
420
+ ]
421
+ }),
422
+ /* @__PURE__ */ jsx(IconButton, {
423
+ variant: "ghost",
424
+ size: "sm",
425
+ className: toastStyles.Close,
426
+ "aria-label": closeLabel,
427
+ disabled: busy,
428
+ onClick: () => setClosing(true),
429
+ children: /* @__PURE__ */ jsx(X, { "aria-hidden": true })
430
+ })
431
+ ]
432
+ })
433
+ });
434
+ }
435
+ // src/components/Toast/Toaster.tsx
436
+ function Toaster({ store, closeLabel, className, ...props }) {
437
+ const items = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
438
+ if (items.length === 0) return null;
439
+ return /* @__PURE__ */ jsx("div", {
440
+ role: "region",
441
+ ...props,
442
+ className: clsx(toastStyles.Viewport, className),
443
+ children: items.map(({ id, options: { onClose: _onClose, ...options }, revision }) => /* @__PURE__ */ jsx(Toast, {
444
+ ...options,
445
+ revision,
446
+ closeLabel,
447
+ onDismiss: () => store.dismiss(id)
448
+ }, id))
449
+ });
450
+ }
451
+ // src/components/Toast/ToastStore.ts
452
+ var isRepeat = (a, b) => a.message === b.message && a.description === b.description && (a.variant ?? "info") === (b.variant ?? "info") && !a.action && !b.action;
453
+ /** Toast 的状态容器,不依赖 React;由应用创建并交给 Toaster 渲染。 */
454
+ var ToastStore = class {
455
+ items = [];
456
+ listeners = /* @__PURE__ */ new Set();
457
+ max;
458
+ nextId = 0;
459
+ constructor(options = {}) {
460
+ this.max = Math.max(1, options.max ?? 1);
461
+ }
462
+ subscribe = (listener) => {
463
+ this.listeners.add(listener);
464
+ return () => {
465
+ this.listeners.delete(listener);
466
+ };
467
+ };
468
+ getSnapshot = () => this.items;
469
+ show(options) {
470
+ const repeated = this.items.find((item) => isRepeat(item.options, options));
471
+ if (repeated) {
472
+ this.commit(this.items.map((item) => item === repeated ? {
473
+ ...item,
474
+ options,
475
+ revision: item.revision + 1
476
+ } : item));
477
+ return repeated.id;
478
+ }
479
+ const id = `toast-${++this.nextId}`;
480
+ this.commit([...this.items, {
481
+ id,
482
+ options,
483
+ revision: 0
484
+ }].slice(-this.max));
485
+ return id;
486
+ }
487
+ /** 不传 id 时关闭全部。 */
488
+ dismiss(id) {
489
+ const next = id === void 0 ? [] : this.items.filter((item) => item.id !== id);
490
+ if (next.length !== this.items.length) this.commit(next);
491
+ }
492
+ commit(next) {
493
+ const removed = this.items.filter((item) => !next.some(({ id }) => id === item.id));
494
+ this.items = next;
495
+ for (const listener of [...this.listeners]) listener();
496
+ for (const item of removed) item.options.onClose?.();
497
+ }
498
+ };
499
+ export { Button, Checkbox, Divider, IconButton, ResizeHandle, Toast, ToastStore, Toaster };