@zovaris/sephiro 1.0.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,15 +29,20 @@ except for CSS, so a bundler can drop the rest.
29
29
 
30
30
  Import exactly one theme preset, not all of them:
31
31
 
32
- | Preset | Stylesheet |
33
- | ---------- | ----------------------------------------- |
34
- | `default` | `@zovaris/sephiro/css/theme-default.css` |
35
- | `dark` | `@zovaris/sephiro/css/theme-dark.css` |
36
- | `light` | `@zovaris/sephiro/css/theme-light.css` |
37
- | `asterism` | `@zovaris/sephiro/css/theme-asterism.css` |
38
- | `fizza` | `@zovaris/sephiro/css/theme-fizza.css` |
39
- | `pulso` | `@zovaris/sephiro/css/theme-pulso.css` |
40
- | `curie` | `@zovaris/sephiro/css/theme-curie.css` |
32
+ | Preset | Stylesheet |
33
+ | ----------- | ------------------------------------------ |
34
+ | `default` | `@zovaris/sephiro/css/theme-default.css` |
35
+ | `dark` | `@zovaris/sephiro/css/theme-dark.css` |
36
+ | `light` | `@zovaris/sephiro/css/theme-light.css` |
37
+ | `asterism` | `@zovaris/sephiro/css/theme-asterism.css` |
38
+ | `fizza` | `@zovaris/sephiro/css/theme-fizza.css` |
39
+ | `pulso` | `@zovaris/sephiro/css/theme-pulso.css` |
40
+ | `curie` | `@zovaris/sephiro/css/theme-curie.css` |
41
+ | `tinta` | `@zovaris/sephiro/css/theme-tinta.css` |
42
+ | `flexoki` | `@zovaris/sephiro/css/theme-flexoki.css` |
43
+ | `pizarra` | `@zovaris/sephiro/css/theme-pizarra.css` |
44
+ | `rose-pine` | `@zovaris/sephiro/css/theme-rose-pine.css` |
45
+ | `orquidea` | `@zovaris/sephiro/css/theme-orquidea.css` |
41
46
 
42
47
  `default` and `dark` are the same palette. Preset files are minified;
43
48
  `theme-default.css` and `theme-dark.css` also seed the dark fallback tokens,
@@ -78,7 +83,7 @@ Sephiro to Tailwind's source scan.
78
83
  </main>
79
84
  ```
80
85
 
81
- Available presets: `default`, `dark`, `light`, `asterism`, `fizza`, `pulso`, and `curie`. The default, dark, and light presets use the pine-rose palette; Pulso remains light by default with a forest-green accent and follows `data-theme="dark"` from its own element or an ancestor. Multiple themes can coexist on one page through `data-sephiro-theme` on any ancestor.
86
+ Available presets: `default`, `dark`, `light`, `asterism`, `fizza`, `pulso`, `curie`, `tinta`, `flexoki`, `pizarra`, `rose-pine`, and `orquidea`. The default, dark, and light presets use the ink-and-lime palette; Pulso remains light by default with a forest-green accent and follows `data-theme="dark"` from its own element or an ancestor. Multiple themes can coexist on one page through `data-sephiro-theme` on any ancestor.
82
87
 
83
88
  ## Sizing
84
89
 
@@ -3,9 +3,50 @@ import { t as node } from "./node-Dr67KnBr.js";
3
3
  import { Spinner } from "./spinner.js";
4
4
  import { useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
5
5
  import { jsx, jsxs } from "react/jsx-runtime";
6
- import { CheckIcon, InfoIcon, WarningIcon, XIcon } from "@phosphor-icons/react";
6
+ import { CheckCircleIcon, InfoIcon, WarningIcon, XCircleIcon, XIcon } from "@phosphor-icons/react";
7
7
  import { createPortal } from "react-dom";
8
8
  import { Toaster, toast } from "sonner";
9
+ const toastGlyphs = {
10
+ neutral: /* @__PURE__ */ jsx(InfoIcon, { size: 18 }),
11
+ info: /* @__PURE__ */ jsx(InfoIcon, { size: 18 }),
12
+ success: /* @__PURE__ */ jsx(CheckCircleIcon, { size: 18 }),
13
+ warning: /* @__PURE__ */ jsx(WarningIcon, { size: 18 }),
14
+ error: /* @__PURE__ */ jsx(XCircleIcon, { size: 18 }),
15
+ loading: /* @__PURE__ */ jsx(Spinner, { size: "md" })
16
+ };
17
+ /**
18
+ * A 14px ring that fills clockwise, sized like the other toast glyphs so it
19
+ * can stand in for the icon while work is in flight.
20
+ */
21
+ function ToastProgress({ value }) {
22
+ const clamped = Math.min(1, Math.max(0, value));
23
+ const radius = 6.25;
24
+ const length = 2 * Math.PI * radius;
25
+ return /* @__PURE__ */ jsxs("svg", {
26
+ className: "sph-toast-progress",
27
+ width: 18,
28
+ height: 18,
29
+ viewBox: "0 0 18 18",
30
+ role: "progressbar",
31
+ "aria-valuemin": 0,
32
+ "aria-valuemax": 100,
33
+ "aria-valuenow": Math.round(clamped * 100),
34
+ children: [/* @__PURE__ */ jsx("circle", {
35
+ className: "sph-toast-progress__track",
36
+ cx: "9",
37
+ cy: "9",
38
+ r: radius
39
+ }), /* @__PURE__ */ jsx("circle", {
40
+ className: "sph-toast-progress__value",
41
+ cx: "9",
42
+ cy: "9",
43
+ r: radius,
44
+ strokeDasharray: length,
45
+ strokeDashoffset: length * (1 - clamped)
46
+ })]
47
+ });
48
+ }
49
+ //#endregion
9
50
  //#region src/molecules/Toast/spring.tsx
10
51
  const DEFAULT_DURATION = 5e3;
11
52
  const EXIT_MS = 180;
@@ -117,11 +158,11 @@ const springToast = Object.assign(show, {
117
158
  }
118
159
  });
119
160
  const icons = {
120
- neutral: /* @__PURE__ */ jsx(InfoIcon, { size: 16 }),
121
- success: /* @__PURE__ */ jsx(CheckIcon, { size: 16 }),
122
- warning: /* @__PURE__ */ jsx(WarningIcon, { size: 16 }),
123
- error: /* @__PURE__ */ jsx(XIcon, { size: 16 }),
124
- loading: /* @__PURE__ */ jsx(Spinner, {})
161
+ neutral: toastGlyphs.neutral,
162
+ success: toastGlyphs.success,
163
+ warning: toastGlyphs.warning,
164
+ error: toastGlyphs.error,
165
+ loading: toastGlyphs.loading
125
166
  };
126
167
  function SpringToaster({ position = "top-center", offset = 24, label = "Notifications", className }) {
127
168
  const record = useSyncExternalStore(subscribe, snapshot, serverSnapshot);
@@ -130,7 +171,7 @@ function SpringToaster({ position = "top-center", offset = 24, label = "Notifica
130
171
  const [paused, setPaused] = useState(false);
131
172
  const last = useRef(null);
132
173
  const card = useRef(null);
133
- const height = useRef(0);
174
+ const size = useRef(null);
134
175
  useEffect(() => setPortaled(true), []);
135
176
  useEffect(() => {
136
177
  if (record) {
@@ -151,17 +192,42 @@ function SpringToaster({ position = "top-center", offset = 24, label = "Notifica
151
192
  const closing = record === null && exiting !== null;
152
193
  useLayoutEffect(() => {
153
194
  const element = card.current;
154
- if (!element || closing) return;
155
- const next = element.offsetHeight;
156
- if (height.current && Math.abs(height.current - next) > 1) {
157
- element.style.height = `${height.current}px`;
158
- element.getBoundingClientRect();
159
- element.style.height = `${next}px`;
160
- window.setTimeout(() => {
161
- element.style.height = "";
162
- }, 260);
195
+ if (!element || closing) {
196
+ size.current = null;
197
+ return;
163
198
  }
164
- height.current = next;
199
+ element.style.width = "";
200
+ element.style.height = "";
201
+ const body = element.querySelector(".sph-spring-toast__body");
202
+ if (body) {
203
+ body.style.flex = "";
204
+ body.style.width = "";
205
+ }
206
+ const next = {
207
+ width: element.offsetWidth,
208
+ height: element.offsetHeight
209
+ };
210
+ const previous = size.current;
211
+ size.current = next;
212
+ if (!previous || Math.abs(previous.width - next.width) < 1 && Math.abs(previous.height - next.height) < 1) return;
213
+ if (body) {
214
+ body.style.flex = "none";
215
+ body.style.width = `${Math.ceil(body.getBoundingClientRect().width)}px`;
216
+ }
217
+ element.style.width = `${previous.width}px`;
218
+ element.style.height = `${previous.height}px`;
219
+ element.getBoundingClientRect();
220
+ element.style.width = `${next.width}px`;
221
+ element.style.height = `${next.height}px`;
222
+ const settle = window.setTimeout(() => {
223
+ element.style.width = "";
224
+ element.style.height = "";
225
+ if (body) {
226
+ body.style.flex = "";
227
+ body.style.width = "";
228
+ }
229
+ }, 520);
230
+ return () => window.clearTimeout(settle);
165
231
  }, [
166
232
  active?.seq,
167
233
  active?.count,
@@ -208,7 +274,7 @@ function SpringToaster({ position = "top-center", offset = 24, label = "Notifica
208
274
  /* @__PURE__ */ jsx("span", {
209
275
  className: "sph-spring-toast__icon",
210
276
  "aria-hidden": "true",
211
- children: node(icons[active.tone])
277
+ children: active.progress !== void 0 ? /* @__PURE__ */ jsx(ToastProgress, { value: active.progress }) : /* @__PURE__ */ jsx("span", { children: node(icons[active.tone]) }, active.tone)
212
278
  }),
213
279
  /* @__PURE__ */ jsxs("span", {
214
280
  className: "sph-spring-toast__body",
@@ -222,7 +288,7 @@ function SpringToaster({ position = "top-center", offset = 24, label = "Notifica
222
288
  className: "sph-spring-toast__description",
223
289
  children: node(active.description)
224
290
  })]
225
- }),
291
+ }, `${active.tone}:${String(active.title)}`),
226
292
  action && /* @__PURE__ */ jsx("button", {
227
293
  type: "button",
228
294
  className: "sph-spring-toast__action",
@@ -242,11 +308,6 @@ function SpringToaster({ position = "top-center", offset = 24, label = "Notifica
242
308
  size: 12,
243
309
  "aria-hidden": "true"
244
310
  })
245
- }),
246
- active.progress !== void 0 && /* @__PURE__ */ jsx("span", {
247
- className: "sph-spring-toast__progress",
248
- "aria-hidden": "true",
249
- style: { transform: `scaleX(${Math.min(1, Math.max(0, active.progress))})` }
250
311
  })
251
312
  ]
252
313
  })
@@ -254,23 +315,16 @@ function SpringToaster({ position = "top-center", offset = 24, label = "Notifica
254
315
  }
255
316
  //#endregion
256
317
  //#region src/molecules/Toast/index.tsx
318
+ const wrap = (glyph) => /* @__PURE__ */ jsx("span", {
319
+ className: "sph-toast__status-icon",
320
+ children: node(glyph)
321
+ });
257
322
  const toastIcons = {
258
- success: /* @__PURE__ */ jsx("span", {
259
- className: "sph-toast__status-icon",
260
- children: /* @__PURE__ */ jsx(CheckIcon, { size: 20 })
261
- }),
262
- info: /* @__PURE__ */ jsx("span", {
263
- className: "sph-toast__status-icon",
264
- children: /* @__PURE__ */ jsx(InfoIcon, { size: 20 })
265
- }),
266
- warning: /* @__PURE__ */ jsx("span", {
267
- className: "sph-toast__status-icon",
268
- children: /* @__PURE__ */ jsx(WarningIcon, { size: 20 })
269
- }),
270
- error: /* @__PURE__ */ jsx("span", {
271
- className: "sph-toast__status-icon",
272
- children: /* @__PURE__ */ jsx(XIcon, { size: 20 })
273
- })
323
+ success: wrap(toastGlyphs.success),
324
+ info: wrap(toastGlyphs.info),
325
+ warning: wrap(toastGlyphs.warning),
326
+ error: wrap(toastGlyphs.error),
327
+ loading: wrap(toastGlyphs.loading)
274
328
  };
275
329
  function Toast({ open = true, id, title, description, variant = "neutral", action, duration, closeButton = true, className }) {
276
330
  useEffect(() => {
@@ -300,7 +354,7 @@ function Toast({ open = true, id, title, description, variant = "neutral", actio
300
354
  ]);
301
355
  return null;
302
356
  }
303
- function ToastViewport({ label = "Notifications", className, toastOptions, theme = "system", position = "top-right", closeButton = true, expand = false, ...props }) {
357
+ function ToastViewport({ label = "Notifications", className, toastOptions, theme = "system", position = "top-right", closeButton = true, expand = false, gap = 8, ...props }) {
304
358
  const [portaled, setPortaled] = useState(false);
305
359
  useEffect(() => setPortaled(true), []);
306
360
  const toaster = /* @__PURE__ */ jsx(Toaster, {
@@ -311,6 +365,7 @@ function ToastViewport({ label = "Notifications", className, toastOptions, theme
311
365
  icons: toastIcons,
312
366
  containerAriaLabel: label,
313
367
  expand,
368
+ gap,
314
369
  className: cn("sph-toast-viewport", className),
315
370
  toastOptions: {
316
371
  ...toastOptions,
@@ -323,6 +378,6 @@ function ToastViewport({ label = "Notifications", className, toastOptions, theme
323
378
  return portaled ? createPortal(toaster, document.body) : toaster;
324
379
  }
325
380
  //#endregion
326
- export { springToast as a, SpringToaster as i, ToastViewport as n, toast as r, Toast as t };
381
+ export { springToast as a, SpringToaster as i, ToastViewport as n, ToastProgress as o, toast as r, Toast as t };
327
382
 
328
- //# sourceMappingURL=Toast-CGHWMJFI.js.map
383
+ //# sourceMappingURL=Toast-CrL3aSID.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Toast-CrL3aSID.js","names":["SonnerToaster"],"sources":["../src/molecules/Toast/icons.tsx","../src/molecules/Toast/spring.tsx","../src/molecules/Toast/index.tsx"],"sourcesContent":["import {\n CheckCircleIcon,\n InfoIcon,\n WarningIcon,\n XCircleIcon,\n} from \"@phosphor-icons/react\";\nimport { Spinner } from \"@/atoms/Spinner/index.js\";\n\n/**\n * Every toast glyph sits in an 18px box. Phosphor pads its artwork, so an 18px\n * glyph draws a ~14px mark, the same as the 14px spinner and progress ring.\n */\nexport const TOAST_ICON_SIZE = 18;\n\nexport const toastGlyphs = {\n neutral: <InfoIcon size={TOAST_ICON_SIZE} />,\n info: <InfoIcon size={TOAST_ICON_SIZE} />,\n success: <CheckCircleIcon size={TOAST_ICON_SIZE} />,\n warning: <WarningIcon size={TOAST_ICON_SIZE} />,\n error: <XCircleIcon size={TOAST_ICON_SIZE} />,\n loading: <Spinner size=\"md\" />,\n};\n\nexport type ToastProgressProps = {\n /** 0 to 1. */\n value: number;\n};\n\n/**\n * A 14px ring that fills clockwise, sized like the other toast glyphs so it\n * can stand in for the icon while work is in flight.\n */\nexport function ToastProgress({ value }: ToastProgressProps) {\n const clamped = Math.min(1, Math.max(0, value));\n const radius = 6.25;\n const length = 2 * Math.PI * radius;\n return (\n <svg\n className=\"sph-toast-progress\"\n width={TOAST_ICON_SIZE}\n height={TOAST_ICON_SIZE}\n viewBox=\"0 0 18 18\"\n role=\"progressbar\"\n aria-valuemin={0}\n aria-valuemax={100}\n aria-valuenow={Math.round(clamped * 100)}\n >\n <circle className=\"sph-toast-progress__track\" cx=\"9\" cy=\"9\" r={radius} />\n <circle\n className=\"sph-toast-progress__value\"\n cx=\"9\"\n cy=\"9\"\n r={radius}\n strokeDasharray={length}\n strokeDashoffset={length * (1 - clamped)}\n />\n </svg>\n );\n}\n","import { XIcon } from \"@phosphor-icons/react\";\nimport { cn } from \"@/lib/cn.js\";\nimport { node, type Renderable } from \"@/lib/node.js\";\nimport {\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { ToastProgress, toastGlyphs } from \"./icons\";\n\nconst DEFAULT_DURATION = 5000;\nconst EXIT_MS = 180;\n\nexport type SpringToastPosition =\n | \"top-left\"\n | \"top-center\"\n | \"top-right\"\n | \"bottom-left\"\n | \"bottom-center\"\n | \"bottom-right\";\n\nexport type SpringToastTone =\n | \"neutral\"\n | \"success\"\n | \"warning\"\n | \"error\"\n | \"loading\";\n\nexport type SpringToastAction = {\n label: Renderable;\n /** Return a patch to morph the toast in place instead of closing it. */\n onClick?: () => SpringToastPatch | void;\n};\n\nexport type SpringToastPatch = {\n title?: Renderable;\n description?: Renderable;\n tone?: SpringToastTone;\n action?: SpringToastAction | null;\n progress?: number | null;\n meta?: Renderable;\n duration?: number;\n};\n\nexport type SpringToastOptions = SpringToastPatch & { id?: string };\n\nexport type SpringToastRecord = {\n id: string;\n title: Renderable;\n description?: Renderable;\n tone: SpringToastTone;\n action?: SpringToastAction;\n progress?: number;\n meta?: Renderable;\n duration: number;\n count: number;\n seq: number;\n};\n\n/**\n * One toast owns the screen, so a new call morphs the live record instead of\n * adding a second card. A new call *replaces* the content: a field it does not\n * send is gone, not inherited from whatever toast came before. Only `update`\n * patches, keeping the fields it leaves out.\n */\nexport function mergeSpringToast(\n current: SpringToastRecord | null,\n patch: SpringToastOptions,\n seq: number,\n mode: \"replace\" | \"patch\" = \"replace\",\n): SpringToastRecord {\n const previous = mode === \"patch\" ? current : null;\n const tone = patch.tone ?? previous?.tone ?? \"neutral\";\n const title = patch.title ?? previous?.title ?? \"\";\n const description =\n patch.description !== undefined ? patch.description : previous?.description;\n const action =\n patch.action === null ? undefined : (patch.action ?? previous?.action);\n const progress =\n patch.progress === null\n ? undefined\n : (patch.progress ?? previous?.progress);\n const meta = patch.meta !== undefined ? patch.meta : previous?.meta;\n const duration = patch.duration ?? previous?.duration ?? DEFAULT_DURATION;\n\n const repeat =\n current !== null &&\n title === current.title &&\n tone === current.tone &&\n description === current.description &&\n action === current.action &&\n progress === current.progress;\n\n return {\n // A new call owns a new id, so a delayed update from an older caller is\n // ignored instead of rewriting whatever toast is on screen by then. Only a\n // patch (or an explicit id) targets the card that is already live.\n id:\n mode === \"patch\"\n ? (current?.id ?? patch.id ?? `sph-spring-toast-${seq}`)\n : (patch.id ?? `sph-spring-toast-${seq}`),\n title,\n description,\n tone,\n action,\n progress,\n meta,\n duration,\n count: repeat ? current.count + 1 : 1,\n seq,\n };\n}\n\n/** Errors, loading and toasts with an action wait for the reader. */\nexport function springDuration(\n record: Pick<SpringToastRecord, \"tone\" | \"action\" | \"duration\">,\n): number {\n if (record.tone === \"error\" || record.tone === \"loading\" || record.action)\n return 0;\n return record.duration;\n}\n\nlet live: SpringToastRecord | null = null;\nlet seq = 0;\nconst listeners = new Set<() => void>();\nconst emit = () => {\n for (const listener of listeners) listener();\n};\nconst subscribe = (listener: () => void) => {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n};\nconst snapshot = () => live;\nconst serverSnapshot = () => null;\n\nfunction show(title: Renderable, options: SpringToastOptions = {}): string {\n seq += 1;\n live = mergeSpringToast(live, { ...options, title }, seq, \"replace\");\n emit();\n return live.id;\n}\n\nexport const springToast = Object.assign(show, {\n success: (title: Renderable, options?: SpringToastOptions) =>\n show(title, { ...options, tone: \"success\" }),\n error: (title: Renderable, options?: SpringToastOptions) =>\n show(title, { ...options, tone: \"error\" }),\n warning: (title: Renderable, options?: SpringToastOptions) =>\n show(title, { ...options, tone: \"warning\" }),\n info: (title: Renderable, options?: SpringToastOptions) =>\n show(title, { ...options, tone: \"neutral\" }),\n loading: (title: Renderable, options?: SpringToastOptions) =>\n show(title, { ...options, tone: \"loading\" }),\n update(id: string, patch: SpringToastPatch) {\n if (!live || live.id !== id) return;\n seq += 1;\n live = mergeSpringToast(live, patch, seq, \"patch\");\n emit();\n },\n dismiss(id?: string) {\n if (!live || (id !== undefined && live.id !== id)) return;\n live = null;\n emit();\n },\n async promise<T>(\n promise: Promise<T>,\n messages: {\n loading: Renderable;\n success: Renderable | ((value: T) => Renderable);\n error: Renderable | ((error: unknown) => Renderable);\n },\n ): Promise<T> {\n const id = show(messages.loading, { tone: \"loading\" });\n try {\n const value = await promise;\n springToast.update(id, {\n tone: \"success\",\n title:\n typeof messages.success === \"function\"\n ? messages.success(value)\n : messages.success,\n });\n return value;\n } catch (error) {\n springToast.update(id, {\n tone: \"error\",\n title:\n typeof messages.error === \"function\"\n ? messages.error(error)\n : messages.error,\n });\n throw error;\n }\n },\n});\n\nconst icons: Record<SpringToastTone, Renderable> = {\n neutral: toastGlyphs.neutral,\n success: toastGlyphs.success,\n warning: toastGlyphs.warning,\n error: toastGlyphs.error,\n loading: toastGlyphs.loading,\n};\n\nexport type SpringToasterProps = {\n position?: SpringToastPosition;\n /** Distance from the viewport edge; raise it to clear a sticky header. */\n offset?: number;\n label?: string;\n className?: string;\n};\n\nexport function SpringToaster({\n position = \"top-center\",\n offset = 24,\n label = \"Notifications\",\n className,\n}: SpringToasterProps) {\n const record = useSyncExternalStore(subscribe, snapshot, serverSnapshot);\n const [portaled, setPortaled] = useState(false);\n const [exiting, setExiting] = useState<SpringToastRecord | null>(null);\n const [paused, setPaused] = useState(false);\n const last = useRef<SpringToastRecord | null>(null);\n const card = useRef<HTMLDivElement>(null);\n const size = useRef<{ width: number; height: number } | null>(null);\n\n useEffect(() => setPortaled(true), []);\n\n // Keep the closed card on screen long enough to play its exit.\n useEffect(() => {\n if (record) {\n last.current = record;\n setExiting(null);\n return;\n }\n const previous = last.current;\n if (!previous) return;\n setExiting(previous);\n const timer = window.setTimeout(() => {\n last.current = null;\n setExiting(null);\n }, EXIT_MS);\n return () => window.clearTimeout(timer);\n }, [record]);\n\n const active = record ?? exiting;\n const closing = record === null && exiting !== null;\n\n // Morph the island between records: pin the old box, let the browser take\n // the new one as the transition target, then hand control back to auto so\n // the next change can measure again.\n useLayoutEffect(() => {\n const element = card.current;\n if (!element || closing) {\n size.current = null;\n return;\n }\n element.style.width = \"\";\n element.style.height = \"\";\n const body = element.querySelector<HTMLElement>(\".sph-spring-toast__body\");\n if (body) {\n body.style.flex = \"\";\n body.style.width = \"\";\n }\n const next = { width: element.offsetWidth, height: element.offsetHeight };\n const previous = size.current;\n size.current = next;\n if (\n !previous ||\n (Math.abs(previous.width - next.width) < 1 &&\n Math.abs(previous.height - next.height) < 1)\n )\n return;\n // Lock the content at its final layout so text does not reflow while the\n // island's box springs between sizes; the island clips it meanwhile.\n if (body) {\n body.style.flex = \"none\";\n body.style.width = `${Math.ceil(body.getBoundingClientRect().width)}px`;\n }\n element.style.width = `${previous.width}px`;\n element.style.height = `${previous.height}px`;\n element.getBoundingClientRect();\n element.style.width = `${next.width}px`;\n element.style.height = `${next.height}px`;\n const settle = window.setTimeout(() => {\n element.style.width = \"\";\n element.style.height = \"\";\n if (body) {\n body.style.flex = \"\";\n body.style.width = \"\";\n }\n }, 520);\n return () => window.clearTimeout(settle);\n }, [active?.seq, active?.count, closing]);\n\n useEffect(() => {\n if (!record || paused) return;\n const ms = springDuration(record);\n if (!ms) return;\n const timer = window.setTimeout(() => springToast.dismiss(record.id), ms);\n return () => window.clearTimeout(timer);\n }, [record, paused]);\n\n useEffect(() => {\n if (!record) return;\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") springToast.dismiss();\n };\n document.addEventListener(\"keydown\", onKeyDown);\n return () => document.removeEventListener(\"keydown\", onKeyDown);\n }, [record]);\n\n if (!portaled || !active) return null;\n\n const action = active.action;\n\n return createPortal(\n <section\n className={cn(\"sph-spring-toast-region\", className)}\n data-position={position}\n aria-label={label}\n style={{\n top: position.startsWith(\"top\") ? offset : undefined,\n bottom: position.startsWith(\"bottom\") ? offset : undefined,\n }}\n >\n <div\n ref={card}\n className=\"sph-spring-toast\"\n data-tone={active.tone}\n data-closing={closing || undefined}\n role={active.tone === \"error\" ? \"alert\" : \"status\"}\n aria-atomic=\"true\"\n tabIndex={-1}\n onPointerEnter={() => setPaused(true)}\n onPointerLeave={() => setPaused(false)}\n onFocus={() => setPaused(true)}\n onBlur={() => setPaused(false)}\n >\n <span className=\"sph-spring-toast__icon\" aria-hidden=\"true\">\n {active.progress !== undefined ? (\n <ToastProgress value={active.progress} />\n ) : (\n <span key={active.tone}>{node(icons[active.tone])}</span>\n )}\n </span>\n <span\n key={`${active.tone}:${String(active.title)}`}\n className=\"sph-spring-toast__body\"\n >\n <span className=\"sph-spring-toast__title\">\n {node(active.title)}\n {active.count > 1 && (\n <span className=\"sph-spring-toast__count\">×{active.count}</span>\n )}\n </span>\n {active.description !== undefined && (\n <span className=\"sph-spring-toast__description\">\n {node(active.description)}\n </span>\n )}\n </span>\n {action && (\n <button\n type=\"button\"\n className=\"sph-spring-toast__action\"\n onClick={() => {\n const patch = action.onClick?.();\n if (patch) springToast.update(active.id, patch);\n else springToast.dismiss(active.id);\n }}\n >\n {node(action.label)}\n </button>\n )}\n <button\n type=\"button\"\n className=\"sph-spring-toast__close\"\n aria-label=\"Dismiss notification\"\n onClick={() => springToast.dismiss(active.id)}\n >\n <XIcon size={12} aria-hidden=\"true\" />\n </button>\n </div>\n </section>,\n document.body,\n );\n}\n","import { cn } from \"@/lib/cn.js\";\nimport { useEffect, useState } from \"react\";\nimport { toastGlyphs } from \"./icons\";\nimport { createPortal } from \"react-dom\";\nimport {\n type ExternalToast,\n Toaster as SonnerToaster,\n type ToasterProps as SonnerToasterProps,\n toast,\n} from \"sonner\";\nimport { node, type Renderable } from \"@/lib/node.js\";\n\nexport type { ExternalToast } from \"sonner\";\nexport { toast };\nexport { ToastProgress, type ToastProgressProps } from \"./icons\";\nexport {\n SpringToaster,\n type SpringToasterProps,\n springToast,\n type SpringToastAction,\n type SpringToastOptions,\n type SpringToastPatch,\n type SpringToastPosition,\n type SpringToastRecord,\n type SpringToastTone,\n} from \"./spring\";\n\nconst wrap = (glyph: Renderable) => (\n <span className=\"sph-toast__status-icon\">{node(glyph)}</span>\n);\n\nconst toastIcons = {\n success: wrap(toastGlyphs.success),\n info: wrap(toastGlyphs.info),\n warning: wrap(toastGlyphs.warning),\n error: wrap(toastGlyphs.error),\n loading: wrap(toastGlyphs.loading),\n};\n\nexport type ToastProps = {\n open?: boolean;\n id?: string | number;\n title: Renderable;\n description?: Renderable;\n variant?: \"neutral\" | \"success\" | \"warning\" | \"danger\";\n action?: ExternalToast[\"action\"];\n duration?: number;\n closeButton?: boolean;\n className?: string;\n};\n\nexport function Toast({\n open = true,\n id,\n title,\n description,\n variant = \"neutral\",\n action,\n duration,\n closeButton = true,\n className,\n}: ToastProps) {\n useEffect(() => {\n if (!open) return;\n const options: ExternalToast = {\n id,\n action,\n closeButton,\n description: node(description),\n duration,\n className: cn(\"sph-toast\", className),\n unstyled: true,\n };\n const toastId =\n variant === \"success\"\n ? toast.success(node(title), options)\n : variant === \"warning\"\n ? toast.warning(node(title), options)\n : variant === \"danger\"\n ? toast.error(node(title), options)\n : toast(node(title), options);\n\n return () => {\n toast.dismiss(toastId);\n };\n }, [open, id, action, closeButton, duration, title, description, variant]);\n\n return null;\n}\n\nexport type ToastViewportProps = Omit<\n SonnerToasterProps,\n \"className\" | \"containerAriaLabel\" | \"icons\" | \"toastOptions\"\n> & {\n label?: string;\n className?: string;\n toastOptions?: SonnerToasterProps[\"toastOptions\"];\n};\n\nexport function ToastViewport({\n label = \"Notifications\",\n className,\n toastOptions,\n theme = \"system\",\n position = \"top-right\",\n closeButton = true,\n expand = false,\n gap = 8,\n ...props\n}: ToastViewportProps) {\n const [portaled, setPortaled] = useState(false);\n useEffect(() => setPortaled(true), []);\n\n const toaster = (\n <SonnerToaster\n {...node(props)}\n theme={theme}\n position={position}\n closeButton={closeButton}\n icons={toastIcons}\n containerAriaLabel={label}\n expand={expand}\n gap={gap}\n className={cn(\"sph-toast-viewport\", className)}\n toastOptions={{\n ...toastOptions,\n closeButton: toastOptions?.closeButton ?? closeButton,\n closeButtonAriaLabel:\n toastOptions?.closeButtonAriaLabel ?? \"Dismiss notification\",\n className: cn(\"sph-toast\", toastOptions?.className),\n unstyled: true,\n }}\n />\n );\n\n // Sonner mounts where it is rendered, so an ancestor with `isolation` or a\n // transform traps it in that stacking context and the toast paints under a\n // sticky header however high its z-index is. Portal it to the document.\n return portaled ? createPortal(toaster, document.body) : toaster;\n}\n"],"mappings":";;;;;;;;AAcA,MAAa,cAAc;CACzB,SAAS,oBAAC,U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