@plexui/ui 0.28.1 → 0.30.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 (230) hide show
  1. package/dist/es/components/Alert/Alert.js +2 -2
  2. package/dist/es/components/Alert/Alert.js.map +1 -1
  3. package/dist/es/components/Avatar/Avatar.js +3 -1
  4. package/dist/es/components/Avatar/Avatar.js.map +1 -1
  5. package/dist/es/components/Badge/index.js +1 -1
  6. package/dist/es/components/Badge/index.js.map +1 -1
  7. package/dist/es/components/Button/Button.js +4 -3
  8. package/dist/es/components/Button/Button.js.map +1 -1
  9. package/dist/es/components/Button/NavigationButton.js +10 -0
  10. package/dist/es/components/Button/NavigationButton.js.map +1 -0
  11. package/dist/es/components/Button/NavigationGlyph.js +19 -0
  12. package/dist/es/components/Button/NavigationGlyph.js.map +1 -0
  13. package/dist/es/components/Button/index.js +1 -0
  14. package/dist/es/components/Button/index.js.map +1 -1
  15. package/dist/es/components/Checkbox/Checkbox.js +2 -1
  16. package/dist/es/components/Checkbox/Checkbox.js.map +1 -1
  17. package/dist/es/components/ColorPicker/ColorPicker.js +227 -0
  18. package/dist/es/components/ColorPicker/ColorPicker.js.map +1 -0
  19. package/dist/es/components/ColorPicker/ColorWell.js +58 -0
  20. package/dist/es/components/ColorPicker/ColorWell.js.map +1 -0
  21. package/dist/es/components/ColorPicker/index.js +3 -0
  22. package/dist/es/components/ColorPicker/index.js.map +1 -0
  23. package/dist/es/components/ColorPicker/shared.js +132 -0
  24. package/dist/es/components/ColorPicker/shared.js.map +1 -0
  25. package/dist/es/components/ContextMenu/ContextMenu.js +164 -0
  26. package/dist/es/components/ContextMenu/ContextMenu.js.map +1 -0
  27. package/dist/es/components/ContextMenu/index.js +2 -0
  28. package/dist/es/components/ContextMenu/index.js.map +1 -0
  29. package/dist/es/components/ContextMenu/shared.js +56 -0
  30. package/dist/es/components/ContextMenu/shared.js.map +1 -0
  31. package/dist/es/components/DateInput/DateInput.js +4 -2
  32. package/dist/es/components/DateInput/DateInput.js.map +1 -1
  33. package/dist/es/components/DatePicker/Calendar.js +89 -55
  34. package/dist/es/components/DatePicker/Calendar.js.map +1 -1
  35. package/dist/es/components/DatePicker/CalendarNavigationIcon.js +13 -0
  36. package/dist/es/components/DatePicker/CalendarNavigationIcon.js.map +1 -0
  37. package/dist/es/components/DatePicker/DatePicker.js +9 -2
  38. package/dist/es/components/DatePicker/DatePicker.js.map +1 -1
  39. package/dist/es/components/DatePicker/useCalendarGutter.js +8 -0
  40. package/dist/es/components/DatePicker/useCalendarGutter.js.map +1 -0
  41. package/dist/es/components/DateRangePicker/Calendar.js +66 -49
  42. package/dist/es/components/DateRangePicker/Calendar.js.map +1 -1
  43. package/dist/es/components/DateRangePicker/DateRangePicker.js +6 -1
  44. package/dist/es/components/DateRangePicker/DateRangePicker.js.map +1 -1
  45. package/dist/es/components/DateRangePicker/Trigger.js +1 -1
  46. package/dist/es/components/DateRangePicker/Trigger.js.map +1 -1
  47. package/dist/es/components/Dialog/Dialog.js +136 -20
  48. package/dist/es/components/Dialog/Dialog.js.map +1 -1
  49. package/dist/es/components/Dialog/index.js.map +1 -1
  50. package/dist/es/components/Dialog/sheetDrag.js +77 -24
  51. package/dist/es/components/Dialog/sheetDrag.js.map +1 -1
  52. package/dist/es/components/Field/Field.js +51 -4
  53. package/dist/es/components/Field/Field.js.map +1 -1
  54. package/dist/es/components/FieldGroup/FieldGroup.js +4 -2
  55. package/dist/es/components/FieldGroup/FieldGroup.js.map +1 -1
  56. package/dist/es/components/FileUpload/FileUpload.js +43 -3
  57. package/dist/es/components/FileUpload/FileUpload.js.map +1 -1
  58. package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js +18 -16
  59. package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js.map +1 -1
  60. package/dist/es/components/FloatingLabelSelect/FloatingLabelSelect.js +11 -6
  61. package/dist/es/components/FloatingLabelSelect/FloatingLabelSelect.js.map +1 -1
  62. package/dist/es/components/Icon/index.js +2 -0
  63. package/dist/es/components/Icon/index.js.map +1 -1
  64. package/dist/es/components/Icon/svg/Disclosure.js +5 -0
  65. package/dist/es/components/Icon/svg/Disclosure.js.map +1 -0
  66. package/dist/es/components/Icon/svg/Eyedropper.js +6 -0
  67. package/dist/es/components/Icon/svg/Eyedropper.js.map +1 -0
  68. package/dist/es/components/Indicator/LoadingIndicator.js +1 -1
  69. package/dist/es/components/Indicator/LoadingIndicator.js.map +1 -1
  70. package/dist/es/components/Input/Input.js +3 -3
  71. package/dist/es/components/Input/Input.js.map +1 -1
  72. package/dist/es/components/InputGroup/InputGroup.js +3 -1
  73. package/dist/es/components/InputGroup/InputGroup.js.map +1 -1
  74. package/dist/es/components/MarkdownEditor/MarkdownEditor.js +95 -93
  75. package/dist/es/components/MarkdownEditor/MarkdownEditor.js.map +1 -1
  76. package/dist/es/components/Menu/Menu.js +306 -34
  77. package/dist/es/components/Menu/Menu.js.map +1 -1
  78. package/dist/es/components/OTPInput/OTPInput.js +4 -1
  79. package/dist/es/components/OTPInput/OTPInput.js.map +1 -1
  80. package/dist/es/components/Page/Page.js +147 -19
  81. package/dist/es/components/Page/Page.js.map +1 -1
  82. package/dist/es/components/Page/index.js.map +1 -1
  83. package/dist/es/components/PageControl/PageControl.js +146 -0
  84. package/dist/es/components/PageControl/PageControl.js.map +1 -0
  85. package/dist/es/components/PageControl/index.js +2 -0
  86. package/dist/es/components/PageControl/index.js.map +1 -0
  87. package/dist/es/components/Popover/Popover.js +75 -33
  88. package/dist/es/components/Popover/Popover.js.map +1 -1
  89. package/dist/es/components/Popover/deferredOutsidePress.js +90 -0
  90. package/dist/es/components/Popover/deferredOutsidePress.js.map +1 -0
  91. package/dist/es/components/Popover/usePopoverContext.js.map +1 -1
  92. package/dist/es/components/RadioGroup/RadioGroup.js +1 -1
  93. package/dist/es/components/RadioGroup/RadioGroup.js.map +1 -1
  94. package/dist/es/components/Select/Select.js +98 -32
  95. package/dist/es/components/Select/Select.js.map +1 -1
  96. package/dist/es/components/SelectControl/SelectControl.js +48 -29
  97. package/dist/es/components/SelectControl/SelectControl.js.map +1 -1
  98. package/dist/es/components/SelectControl/index.js +1 -1
  99. package/dist/es/components/SelectControl/index.js.map +1 -1
  100. package/dist/es/components/ShimmerText/ShimmerText.js +17 -7
  101. package/dist/es/components/ShimmerText/ShimmerText.js.map +1 -1
  102. package/dist/es/components/Sidebar/Sidebar.js +21 -8
  103. package/dist/es/components/Sidebar/Sidebar.js.map +1 -1
  104. package/dist/es/components/Slider/Slider.js +61 -15
  105. package/dist/es/components/Slider/Slider.js.map +1 -1
  106. package/dist/es/components/Sortable/Sortable.js +16 -6
  107. package/dist/es/components/Sortable/Sortable.js.map +1 -1
  108. package/dist/es/components/Stepper/Stepper.js +114 -0
  109. package/dist/es/components/Stepper/Stepper.js.map +1 -0
  110. package/dist/es/components/Stepper/index.js +2 -0
  111. package/dist/es/components/Stepper/index.js.map +1 -0
  112. package/dist/es/components/Switch/Switch.js +2 -2
  113. package/dist/es/components/Switch/Switch.js.map +1 -1
  114. package/dist/es/components/TabBar/TabBar.js +128 -0
  115. package/dist/es/components/TabBar/TabBar.js.map +1 -0
  116. package/dist/es/components/TabBar/index.js +2 -0
  117. package/dist/es/components/TabBar/index.js.map +1 -0
  118. package/dist/es/components/Tabs/Tabs.js +27 -11
  119. package/dist/es/components/Tabs/Tabs.js.map +1 -1
  120. package/dist/es/components/TagInput/TagInput.js +40 -4
  121. package/dist/es/components/TagInput/TagInput.js.map +1 -1
  122. package/dist/es/components/Textarea/Textarea.js +7 -1
  123. package/dist/es/components/Textarea/Textarea.js.map +1 -1
  124. package/dist/es/components/Toast/ToastRenderer.js +86 -0
  125. package/dist/es/components/Toast/ToastRenderer.js.map +1 -0
  126. package/dist/es/components/Toast/Toaster.js +31 -16
  127. package/dist/es/components/Toast/Toaster.js.map +1 -1
  128. package/dist/es/components/Toast/toastLifecycle.js +283 -0
  129. package/dist/es/components/Toast/toastLifecycle.js.map +1 -0
  130. package/dist/es/components/Toolbar/Toolbar.js +92 -0
  131. package/dist/es/components/Toolbar/Toolbar.js.map +1 -0
  132. package/dist/es/components/Toolbar/index.js +2 -0
  133. package/dist/es/components/Toolbar/index.js.map +1 -0
  134. package/dist/es/components/Tooltip/CopyTooltip.js +37 -11
  135. package/dist/es/components/Tooltip/CopyTooltip.js.map +1 -1
  136. package/dist/es/components/Tooltip/Tooltip.js +61 -9
  137. package/dist/es/components/Tooltip/Tooltip.js.map +1 -1
  138. package/dist/es/hooks/useFloatingBoundary.js +35 -0
  139. package/dist/es/hooks/useFloatingBoundary.js.map +1 -0
  140. package/dist/es/hooks/usePhoneSubmenu.js +22 -0
  141. package/dist/es/hooks/usePhoneSubmenu.js.map +1 -0
  142. package/dist/es/lib/copyToClipboard.js +16 -7
  143. package/dist/es/lib/copyToClipboard.js.map +1 -1
  144. package/dist/es/lib/fieldRow.js +7 -1
  145. package/dist/es/lib/fieldRow.js.map +1 -1
  146. package/dist/es/lib/floatingBoundary.js +90 -0
  147. package/dist/es/lib/floatingBoundary.js.map +1 -0
  148. package/dist/es/lib/focusRestore.js +56 -0
  149. package/dist/es/lib/focusRestore.js.map +1 -0
  150. package/dist/es/lib/helpers.js +0 -18
  151. package/dist/es/lib/helpers.js.map +1 -1
  152. package/dist/es/lib/inputMode.js +9 -0
  153. package/dist/es/lib/inputMode.js.map +1 -0
  154. package/dist/es/lib/menuInitialFocus.js +100 -0
  155. package/dist/es/lib/menuInitialFocus.js.map +1 -0
  156. package/dist/es/lib/menuSubmenuPlacement.js +264 -0
  157. package/dist/es/lib/menuSubmenuPlacement.js.map +1 -0
  158. package/dist/es/lib/menuTriggerCover.js +70 -0
  159. package/dist/es/lib/menuTriggerCover.js.map +1 -0
  160. package/dist/es/lib/observeTextareaWidth.js +49 -0
  161. package/dist/es/lib/observeTextareaWidth.js.map +1 -0
  162. package/dist/es/lib/scrollEdges.js +34 -0
  163. package/dist/es/lib/scrollEdges.js.map +1 -0
  164. package/dist/es/lib/selectPress.js +34 -0
  165. package/dist/es/lib/selectPress.js.map +1 -0
  166. package/dist/es/lib/sortable.js +74 -20
  167. package/dist/es/lib/sortable.js.map +1 -1
  168. package/dist/es/styles/mobile-materials.css +1 -0
  169. package/dist/es/styles/mobile-surfaces.css +1 -0
  170. package/dist/types/components/Button/Button.d.ts +2 -0
  171. package/dist/types/components/Button/NavigationButton.d.ts +8 -0
  172. package/dist/types/components/Button/NavigationGlyph.d.ts +7 -0
  173. package/dist/types/components/Button/index.d.ts +1 -0
  174. package/dist/types/components/ColorPicker/ColorPicker.d.ts +34 -0
  175. package/dist/types/components/ColorPicker/ColorWell.d.ts +32 -0
  176. package/dist/types/components/ColorPicker/index.d.ts +3 -0
  177. package/dist/types/components/ColorPicker/shared.d.ts +69 -0
  178. package/dist/types/components/ContextMenu/ContextMenu.d.ts +78 -0
  179. package/dist/types/components/ContextMenu/index.d.ts +1 -0
  180. package/dist/types/components/ContextMenu/shared.d.ts +50 -0
  181. package/dist/types/components/DatePicker/CalendarNavigationIcon.d.ts +5 -0
  182. package/dist/types/components/DatePicker/DatePicker.d.ts +7 -1
  183. package/dist/types/components/DatePicker/useCalendarGutter.d.ts +1 -0
  184. package/dist/types/components/DateRangePicker/DateRangePicker.d.ts +2 -0
  185. package/dist/types/components/Dialog/Dialog.d.ts +17 -6
  186. package/dist/types/components/Dialog/index.d.ts +1 -1
  187. package/dist/types/components/Field/Field.d.ts +12 -2
  188. package/dist/types/components/FieldGroup/FieldGroup.d.ts +11 -2
  189. package/dist/types/components/Icon/index.d.ts +2 -0
  190. package/dist/types/components/Icon/svg/Disclosure.d.ts +6 -0
  191. package/dist/types/components/Icon/svg/Eyedropper.d.ts +6 -0
  192. package/dist/types/components/Indicator/LoadingIndicator.d.ts +1 -1
  193. package/dist/types/components/Menu/Menu.d.ts +74 -9
  194. package/dist/types/components/Page/Page.d.ts +24 -9
  195. package/dist/types/components/Page/index.d.ts +1 -1
  196. package/dist/types/components/PageControl/PageControl.d.ts +52 -0
  197. package/dist/types/components/PageControl/index.d.ts +1 -0
  198. package/dist/types/components/Popover/Popover.d.ts +11 -6
  199. package/dist/types/components/Popover/deferredOutsidePress.d.ts +14 -0
  200. package/dist/types/components/Popover/usePopoverContext.d.ts +1 -0
  201. package/dist/types/components/Select/Select.d.ts +3 -3
  202. package/dist/types/components/SelectControl/SelectControl.d.ts +2 -2
  203. package/dist/types/components/SelectControl/index.d.ts +1 -1
  204. package/dist/types/components/Sortable/Sortable.d.ts +1 -1
  205. package/dist/types/components/Stepper/Stepper.d.ts +56 -0
  206. package/dist/types/components/Stepper/index.d.ts +1 -0
  207. package/dist/types/components/Switch/Switch.d.ts +3 -1
  208. package/dist/types/components/TabBar/TabBar.d.ts +74 -0
  209. package/dist/types/components/TabBar/index.d.ts +1 -0
  210. package/dist/types/components/Toast/ToastRenderer.d.ts +3 -0
  211. package/dist/types/components/Toast/Toaster.d.ts +4 -2
  212. package/dist/types/components/Toast/toastLifecycle.d.ts +90 -0
  213. package/dist/types/components/Toolbar/Toolbar.d.ts +93 -0
  214. package/dist/types/components/Toolbar/index.d.ts +1 -0
  215. package/dist/types/components/Tooltip/Tooltip.d.ts +2 -2
  216. package/dist/types/hooks/useFloatingBoundary.d.ts +24 -0
  217. package/dist/types/hooks/usePhoneSubmenu.d.ts +3 -0
  218. package/dist/types/lib/fieldRow.d.ts +6 -0
  219. package/dist/types/lib/floatingBoundary.d.ts +9 -0
  220. package/dist/types/lib/focusRestore.d.ts +5 -0
  221. package/dist/types/lib/helpers.d.ts +1 -5
  222. package/dist/types/lib/inputMode.d.ts +7 -0
  223. package/dist/types/lib/menuInitialFocus.d.ts +9 -0
  224. package/dist/types/lib/menuSubmenuPlacement.d.ts +57 -0
  225. package/dist/types/lib/menuTriggerCover.d.ts +23 -0
  226. package/dist/types/lib/observeTextareaWidth.d.ts +2 -0
  227. package/dist/types/lib/scrollEdges.d.ts +16 -0
  228. package/dist/types/lib/selectPress.d.ts +23 -0
  229. package/dist/types/lib/sortable.d.ts +1 -1
  230. package/package.json +6 -2
@@ -0,0 +1,86 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import clsx from "clsx";
4
+ import { isValidElement, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
5
+ import { toast, useSonner } from "sonner";
6
+ import { CheckCircle, InfoCircle, Warning, XCircle } from "../Icon/index.js";
7
+ import { documentDirection, offsetStyles, ToastLifecycle } from "./toastLifecycle.js";
8
+ const CloseIcon = () => _jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true", width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", children: [_jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" }), _jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" })] });
9
+ const fallbackIcons = { success: _jsx(CheckCircle, { "aria-hidden": "true" }), error: _jsx(XCircle, { "aria-hidden": "true" }), warning: _jsx(Warning, { "aria-hidden": "true" }), info: _jsx(InfoCircle, { "aria-hidden": "true" }) };
10
+ const actionObject = (value) => typeof value === "object" && value !== null && "label" in value;
11
+ const content = (value) => typeof value === "function" ? value() : value;
12
+ function ToastItem({ entry, lifecycle, props, index, count }) {
13
+ const node = useRef(null);
14
+ const item = entry.toast;
15
+ const classes = props.toastOptions?.classNames;
16
+ const slot = (name) => clsx(classes?.[name], item.classNames?.[name]);
17
+ const position = lifecycle.position(entry);
18
+ const [y, x] = position.split("-");
19
+ const visible = index < (props.visibleToasts ?? 3);
20
+ const disabled = item.dismissible === false || item.type === "loading";
21
+ const type = item.type === "normal" || item.type === "default" ? undefined : item.type;
22
+ const iconKey = type && type in fallbackIcons ? type : undefined;
23
+ const icon = item.icon !== undefined ? item.icon : iconKey ? props.icons?.[iconKey] !== undefined ? props.icons[iconKey] : fallbackIcons[iconKey] : undefined;
24
+ useLayoutEffect(() => {
25
+ const element = node.current;
26
+ if (!element)
27
+ return;
28
+ lifecycle.setNode(item.id, element);
29
+ const measure = () => {
30
+ const height = element.style.height;
31
+ element.style.height = "auto";
32
+ lifecycle.measure(item.id, element.offsetHeight || element.getBoundingClientRect().height);
33
+ element.style.height = height;
34
+ };
35
+ measure();
36
+ const observer = typeof ResizeObserver !== "undefined" ? new ResizeObserver(measure) : null;
37
+ observer?.observe(element);
38
+ for (const child of element.children)
39
+ observer?.observe(child);
40
+ return () => { observer?.disconnect(); lifecycle.setNode(item.id, null); };
41
+ }, [item, lifecycle]);
42
+ const actionButton = (kind) => {
43
+ const action = item[kind];
44
+ if (isValidElement(action))
45
+ return action;
46
+ if (!actionObject(action))
47
+ return null;
48
+ return _jsx("button", { type: "button", "data-button": "true", [`data-${kind}`]: "true", disabled: kind === "cancel" && disabled, className: slot(kind === "action" ? "actionButton" : "cancelButton"), style: kind === "action" ? item.actionButtonStyle ?? props.toastOptions?.actionButtonStyle : item.cancelButtonStyle ?? props.toastOptions?.cancelButtonStyle, onClick: (event) => {
49
+ if (kind === "cancel" && disabled)
50
+ return;
51
+ action.onClick(event);
52
+ if (kind === "action" && event.defaultPrevented)
53
+ return;
54
+ lifecycle.close(item.id, "action");
55
+ }, children: action.label });
56
+ };
57
+ return _jsxs("li", { ref: node, tabIndex: visible && !entry.removed ? 0 : -1, inert: !visible || entry.removed || undefined, "aria-hidden": !visible || entry.removed || undefined, className: clsx(props.toastOptions?.className, item.className, slot("toast"), slot("default"), type && slot(type)), "data-sonner-toast": "", "data-rich-colors": item.richColors ?? props.richColors, "data-styled": !Boolean(item.jsx || item.unstyled || props.toastOptions?.unstyled), "data-mounted": entry.mounted, "data-promise": Boolean(item.promise), "data-swiped": Boolean(entry.x || entry.y), "data-removed": entry.removed, "data-visible": visible, "data-y-position": y, "data-x-position": x, "data-index": index, "data-front": index === 0, "data-swiping": entry.swiping, "data-dismissible": item.dismissible !== false, "data-type": type, "data-invert": item.invert || props.invert, "data-swipe-out": Boolean(entry.swipeOut), "data-swipe-direction": entry.swipeOut, "data-expanded": lifecycle.expanded || Boolean(props.expand && entry.mounted), "data-testid": item.testId, style: { "--index": index, "--toasts-before": index, "--z-index": count - index, "--offset": `${lifecycle.offset(entry)}px`, "--initial-height": props.expand ? "auto" : `${entry.height}px`, "--swipe-amount-x": `${entry.x}px`, "--swipe-amount-y": `${entry.y}px`, ...props.toastOptions?.style, ...item.style }, onPointerDown: (event) => lifecycle.pointerDown(item.id, event.nativeEvent), onPointerMove: (event) => lifecycle.pointerMove(item.id, event.nativeEvent), onPointerUp: (event) => lifecycle.pointerEnd(item.id, event.nativeEvent), onPointerCancel: (event) => lifecycle.pointerEnd(item.id, event.nativeEvent, true), onLostPointerCapture: (event) => lifecycle.pointerEnd(item.id, event.nativeEvent, true), children: [(item.closeButton ?? props.toastOptions?.closeButton ?? props.closeButton) && !item.jsx && item.type !== "loading" && _jsx("button", { type: "button", "aria-label": props.toastOptions?.closeButtonAriaLabel ?? "Close toast", "data-disabled": disabled, disabled: disabled, "data-close-button": "true", className: slot("closeButton"), onClick: () => lifecycle.close(item.id, "dismiss"), children: props.icons?.close ?? _jsx(CloseIcon, {}) }), (type || item.icon || item.promise) && item.icon !== null && icon !== null && _jsxs("div", { "data-icon": "", className: slot("icon"), children: [item.promise || item.type === "loading" ? item.icon ?? _jsx("div", { className: clsx("sonner-loading-wrapper", slot("loader")), "data-visible": item.type === "loading", children: props.icons?.loading ? _jsx("div", { className: "sonner-loader", "data-visible": item.type === "loading", children: props.icons.loading }) : _jsx("div", { className: "sonner-spinner", children: Array.from({ length: 12 }, (_, i) => _jsx("div", { className: "sonner-loading-bar" }, i)) }) }) : null, item.type !== "loading" ? icon : null] }), _jsxs("div", { "data-content": "", className: slot("content"), children: [_jsx("div", { "data-title": "", className: slot("title"), children: item.jsx ?? content(item.title) }), item.description ? _jsx("div", { "data-description": "", className: clsx(props.toastOptions?.descriptionClassName, item.descriptionClassName, slot("description")), children: content(item.description) }) : null] }), actionButton("cancel"), actionButton("action")] });
58
+ }
59
+ /** Owns presentation/interaction only; Sonner remains the public toast store. */
60
+ export function ToastRenderer(props) {
61
+ const { toasts } = useSonner();
62
+ const [lifecycle] = useState(() => new ToastLifecycle(toast.dismiss, (reason, item) => reason === "auto" ? item.onAutoClose?.(item) : item.onDismiss?.(item)));
63
+ useSyncExternalStore(lifecycle.subscribe, lifecycle.snapshot, lifecycle.snapshot);
64
+ const hotkey = props.hotkey ?? ["altKey", "KeyT"];
65
+ const hotkeyKey = hotkey.join("+");
66
+ useEffect(() => {
67
+ lifecycle.connect(document);
68
+ return () => lifecycle.disconnect();
69
+ }, [lifecycle]);
70
+ useEffect(() => {
71
+ const keydown = (event) => lifecycle.keyDown(event, hotkeyKey ? hotkeyKey.split("+") : []);
72
+ document.addEventListener("keydown", keydown);
73
+ return () => document.removeEventListener("keydown", keydown);
74
+ }, [lifecycle, hotkeyKey]);
75
+ useEffect(() => {
76
+ lifecycle.sync(toasts, { id: props.id, position: props.position ?? "bottom-right", duration: props.toastOptions?.duration ?? props.duration ?? 4000, gap: props.gap ?? 14, visibleToasts: props.visibleToasts ?? 3, expand: props.expand, swipeDirections: props.swipeDirections });
77
+ }, [lifecycle, toasts, props.id, props.position, props.duration, props.toastOptions?.duration, props.gap, props.visibleToasts, props.expand, props.swipeDirections]);
78
+ const positions = [...new Set(lifecycle.entries.map((entry) => lifecycle.position(entry)))];
79
+ const dir = props.dir === "auto" || !props.dir ? documentDirection(typeof document === "undefined" ? undefined : document) : props.dir;
80
+ return _jsx("section", { "aria-label": `${props.containerAriaLabel ?? "Notifications"} ${hotkeyKey.replace(/Key|Digit/g, "")}`, tabIndex: -1, "aria-live": "polite", "aria-relevant": "additions text", "aria-atomic": false, children: positions.map((position) => {
81
+ const entries = lifecycle.at(position);
82
+ const [y, x] = position.split("-");
83
+ return _jsx("ol", { ref: (node) => lifecycle.setList(position, node), dir: dir, tabIndex: -1, className: props.className, "data-sonner-toaster": "true", "data-sonner-theme": props.theme ?? "light", "data-y-position": y, "data-x-position": x, style: { "--front-toast-height": `${entries.find((entry) => !entry.removed)?.height ?? 0}px`, "--width": "356px", "--gap": `${props.gap ?? 14}px`, ...props.style, ...offsetStyles(props.offset, props.mobileOffset) }, onFocus: (event) => lifecycle.focusIn(event.nativeEvent), onBlur: (event) => lifecycle.focusOut(event.nativeEvent), onPointerEnter: (event) => lifecycle.pointerEnter(event.nativeEvent), onMouseEnter: () => lifecycle.hover(true), onMouseMove: () => lifecycle.hover(true), onMouseLeave: () => lifecycle.hover(false), children: entries.map((entry, index) => _jsx(ToastItem, { entry: entry, lifecycle: lifecycle, props: props, index: index, count: entries.length }, entry.toast.id)) }, position);
84
+ }) });
85
+ }
86
+ //# sourceMappingURL=ToastRenderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToastRenderer.js","sourceRoot":"","sources":["../../../../src/components/Toast/ToastRenderer.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAoB,EAAsC,MAAM,OAAO,CAAA;AAC9I,OAAO,EAAE,KAAK,EAAE,SAAS,EAA+C,MAAM,QAAQ,CAAA;AACtF,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACnE,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,cAAc,EAAkC,MAAM,kBAAkB,CAAA;AAElH,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,eAAK,KAAK,EAAC,4BAA4B,iBAAa,MAAM,EAAC,KAAK,EAAC,IAAI,EAAC,MAAM,EAAC,IAAI,EAAC,OAAO,EAAC,WAAW,EAAC,IAAI,EAAC,MAAM,EAAC,MAAM,EAAC,cAAc,EAAC,WAAW,EAAC,KAAK,EAAC,aAAa,EAAC,OAAO,EAAC,cAAc,EAAC,OAAO,aAAC,eAAM,EA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,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,YACpM,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAC,SAAS,IAAsB,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,IAArG,KAAK,CAAC,KAAK,CAAC,EAAE,CAA2F,CAAC,IAL3I,QAAQ,CAMnB,CAAA;QACP,CAAC,CAAC,GACM,CAAA;AACZ,CAAC","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { isValidElement, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore, type CSSProperties, type ReactNode } from \"react\"\nimport { toast, useSonner, type Action, type ToastT, type ToasterProps } from \"sonner\"\nimport { CheckCircle, InfoCircle, Warning, XCircle } from \"../Icon\"\nimport { documentDirection, offsetStyles, ToastLifecycle, type Position, type ToastEntry } from \"./toastLifecycle\"\n\nconst CloseIcon = () => <svg xmlns=\"http://www.w3.org/2000/svg\" aria-hidden=\"true\" width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\"><line x1=\"18\" y1=\"6\" x2=\"6\" y2=\"18\" /><line x1=\"6\" y1=\"6\" x2=\"18\" y2=\"18\" /></svg>\nconst fallbackIcons = { success: <CheckCircle aria-hidden=\"true\" />, error: <XCircle aria-hidden=\"true\" />, warning: <Warning aria-hidden=\"true\" />, info: <InfoCircle aria-hidden=\"true\" /> }\nconst actionObject = (value: Action | ReactNode): value is Action => typeof value === \"object\" && value !== null && \"label\" in value\nconst content = (value: ToastT[\"title\"]) => typeof value === \"function\" ? value() : value\n\nfunction ToastItem({ entry, lifecycle, props, index, count }: { entry: ToastEntry<ToastT>; lifecycle: ToastLifecycle<ToastT>; props: ToasterProps; index: number; count: number }) {\n const node = useRef<HTMLLIElement>(null)\n const item = entry.toast\n const classes = props.toastOptions?.classNames\n const slot = (name: keyof NonNullable<typeof classes>) => clsx(classes?.[name], item.classNames?.[name])\n const position = lifecycle.position(entry)\n const [y, x] = position.split(\"-\")\n const visible = index < (props.visibleToasts ?? 3)\n const disabled = item.dismissible === false || item.type === \"loading\"\n const type = item.type === \"normal\" || item.type === \"default\" ? undefined : item.type\n const iconKey = type && type in fallbackIcons ? type as keyof typeof fallbackIcons : undefined\n const icon = item.icon !== undefined ? item.icon : iconKey ? props.icons?.[iconKey] !== undefined ? props.icons[iconKey] : fallbackIcons[iconKey] : undefined\n useLayoutEffect(() => {\n const element = node.current\n if (!element) return\n lifecycle.setNode(item.id, element)\n const measure = () => {\n const height = element.style.height\n element.style.height = \"auto\"\n lifecycle.measure(item.id, element.offsetHeight || element.getBoundingClientRect().height)\n element.style.height = height\n }\n measure()\n const observer = typeof ResizeObserver !== \"undefined\" ? new ResizeObserver(measure) : null\n observer?.observe(element)\n for (const child of element.children) observer?.observe(child)\n return () => { observer?.disconnect(); lifecycle.setNode(item.id, null) }\n }, [item, lifecycle])\n const actionButton = (kind: \"action\" | \"cancel\") => {\n const action = item[kind]\n if (isValidElement(action)) return action\n if (!actionObject(action)) return null\n return <button type=\"button\" data-button=\"true\" {...{ [`data-${kind}`]: \"true\" }} disabled={kind === \"cancel\" && disabled}\n className={slot(kind === \"action\" ? \"actionButton\" : \"cancelButton\")}\n style={kind === \"action\" ? item.actionButtonStyle ?? props.toastOptions?.actionButtonStyle : item.cancelButtonStyle ?? props.toastOptions?.cancelButtonStyle}\n onClick={(event) => {\n if (kind === \"cancel\" && disabled) return\n action.onClick(event)\n if (kind === \"action\" && event.defaultPrevented) return\n lifecycle.close(item.id, \"action\")\n }}>{action.label}</button>\n }\n return <li ref={node} tabIndex={visible && !entry.removed ? 0 : -1} inert={!visible || entry.removed || undefined}\n aria-hidden={!visible || entry.removed || undefined}\n className={clsx(props.toastOptions?.className, item.className, slot(\"toast\"), slot(\"default\"), type && slot(type as keyof NonNullable<typeof classes>))}\n data-sonner-toast=\"\" data-rich-colors={item.richColors ?? props.richColors} data-styled={!Boolean(item.jsx || item.unstyled || props.toastOptions?.unstyled)}\n data-mounted={entry.mounted} data-promise={Boolean(item.promise)} data-swiped={Boolean(entry.x || entry.y)} data-removed={entry.removed}\n data-visible={visible} data-y-position={y} data-x-position={x} data-index={index} data-front={index === 0} data-swiping={entry.swiping}\n data-dismissible={item.dismissible !== false} data-type={type} data-invert={item.invert || props.invert}\n data-swipe-out={Boolean(entry.swipeOut)} data-swipe-direction={entry.swipeOut} data-expanded={lifecycle.expanded || Boolean(props.expand && entry.mounted)} data-testid={item.testId}\n style={{ \"--index\": index, \"--toasts-before\": index, \"--z-index\": count - index, \"--offset\": `${lifecycle.offset(entry)}px`, \"--initial-height\": props.expand ? \"auto\" : `${entry.height}px`, \"--swipe-amount-x\": `${entry.x}px`, \"--swipe-amount-y\": `${entry.y}px`, ...props.toastOptions?.style, ...item.style } as CSSProperties}\n onPointerDown={(event) => lifecycle.pointerDown(item.id, event.nativeEvent)} onPointerMove={(event) => lifecycle.pointerMove(item.id, event.nativeEvent)}\n onPointerUp={(event) => lifecycle.pointerEnd(item.id, event.nativeEvent)} onPointerCancel={(event) => lifecycle.pointerEnd(item.id, event.nativeEvent, true)}\n onLostPointerCapture={(event) => lifecycle.pointerEnd(item.id, event.nativeEvent, true)}>\n {(item.closeButton ?? props.toastOptions?.closeButton ?? props.closeButton) && !item.jsx && item.type !== \"loading\" && <button type=\"button\" aria-label={props.toastOptions?.closeButtonAriaLabel ?? \"Close toast\"} data-disabled={disabled} disabled={disabled} data-close-button=\"true\" className={slot(\"closeButton\")} onClick={() => lifecycle.close(item.id, \"dismiss\")}>{props.icons?.close ?? <CloseIcon />}</button>}\n {(type || item.icon || item.promise) && item.icon !== null && icon !== null && <div data-icon=\"\" className={slot(\"icon\")}>\n {item.promise || item.type === \"loading\" ? item.icon ?? <div className={clsx(\"sonner-loading-wrapper\", slot(\"loader\"))} data-visible={item.type === \"loading\"}>\n {props.icons?.loading ? <div className=\"sonner-loader\" data-visible={item.type === \"loading\"}>{props.icons.loading}</div> : <div className=\"sonner-spinner\">{Array.from({ length: 12 }, (_, i) => <div key={i} className=\"sonner-loading-bar\" />)}</div>}\n </div> : null}\n {item.type !== \"loading\" ? icon : null}\n </div>}\n <div data-content=\"\" className={slot(\"content\")}><div data-title=\"\" className={slot(\"title\")}>{item.jsx ?? content(item.title)}</div>\n {item.description ? <div data-description=\"\" className={clsx(props.toastOptions?.descriptionClassName, item.descriptionClassName, slot(\"description\"))}>{content(item.description)}</div> : null}</div>\n {actionButton(\"cancel\")}{actionButton(\"action\")}\n </li>\n}\n\n/** Owns presentation/interaction only; Sonner remains the public toast store. */\nexport function ToastRenderer(props: ToasterProps) {\n const { toasts } = useSonner()\n const [lifecycle] = useState(() => new ToastLifecycle<ToastT>(toast.dismiss, (reason, item) => reason === \"auto\" ? item.onAutoClose?.(item) : item.onDismiss?.(item)))\n useSyncExternalStore(lifecycle.subscribe, lifecycle.snapshot, lifecycle.snapshot)\n const hotkey = props.hotkey ?? [\"altKey\", \"KeyT\"]\n const hotkeyKey = hotkey.join(\"+\")\n useEffect(() => {\n lifecycle.connect(document)\n return () => lifecycle.disconnect()\n }, [lifecycle])\n useEffect(() => {\n const keydown = (event: KeyboardEvent) => lifecycle.keyDown(event, hotkeyKey ? hotkeyKey.split(\"+\") : [])\n document.addEventListener(\"keydown\", keydown)\n return () => document.removeEventListener(\"keydown\", keydown)\n }, [lifecycle, hotkeyKey])\n useEffect(() => {\n lifecycle.sync(toasts, { id: props.id, position: props.position ?? \"bottom-right\", duration: props.toastOptions?.duration ?? props.duration ?? 4000, gap: props.gap ?? 14, visibleToasts: props.visibleToasts ?? 3, expand: props.expand, swipeDirections: props.swipeDirections })\n }, [lifecycle, toasts, props.id, props.position, props.duration, props.toastOptions?.duration, props.gap, props.visibleToasts, props.expand, props.swipeDirections])\n const positions = [...new Set(lifecycle.entries.map((entry) => lifecycle.position(entry)))]\n const dir = props.dir === \"auto\" || !props.dir ? documentDirection(typeof document === \"undefined\" ? undefined : document) : props.dir\n return <section aria-label={`${props.containerAriaLabel ?? \"Notifications\"} ${hotkeyKey.replace(/Key|Digit/g, \"\")}`} tabIndex={-1} aria-live=\"polite\" aria-relevant=\"additions text\" aria-atomic={false}>\n {positions.map((position: Position) => {\n const entries = lifecycle.at(position)\n const [y, x] = position.split(\"-\")\n return <ol key={position} ref={(node) => lifecycle.setList(position, node)} dir={dir} tabIndex={-1} className={props.className}\n data-sonner-toaster=\"true\" data-sonner-theme={props.theme ?? \"light\"} data-y-position={y} data-x-position={x}\n style={{ \"--front-toast-height\": `${entries.find((entry) => !entry.removed)?.height ?? 0}px`, \"--width\": \"356px\", \"--gap\": `${props.gap ?? 14}px`, ...props.style, ...offsetStyles(props.offset, props.mobileOffset) } as CSSProperties}\n onFocus={(event) => lifecycle.focusIn(event.nativeEvent)} onBlur={(event) => lifecycle.focusOut(event.nativeEvent)}\n onPointerEnter={(event) => lifecycle.pointerEnter(event.nativeEvent)} onMouseEnter={() => lifecycle.hover(true)} onMouseMove={() => lifecycle.hover(true)} onMouseLeave={() => lifecycle.hover(false)}>\n {entries.map((entry, index) => <ToastItem key={entry.toast.id} entry={entry} lifecycle={lifecycle} props={props} index={index} count={entries.length} />)}\n </ol>\n })}\n </section>\n}\n"]}
@@ -1,7 +1,8 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useEffect, useState } from "react";
4
- import { Toaster as SonnerToaster } from "sonner";
3
+ import { useSyncExternalStore } from "react";
4
+ import {} from "sonner";
5
+ import { ToastRenderer as SonnerToaster } from "./ToastRenderer.js";
5
6
  import { CheckCircle, InfoCircle, Warning, XCircle } from "../Icon/index.js";
6
7
  import s from "@plexui/styles/components/Toast/Toast.module.css";
7
8
  /**
@@ -10,6 +11,31 @@ import s from "@plexui/styles/components/Toast/Toast.module.css";
10
11
  */
11
12
  export const compact = { className: s.Compact };
12
13
  const readTheme = () => document.documentElement.getAttribute("data-theme") === "dark" ? "dark" : "light";
14
+ const subscribeTheme = (onChange) => {
15
+ const observer = new MutationObserver(onChange);
16
+ observer.observe(document.documentElement, {
17
+ attributes: true,
18
+ attributeFilter: ["data-theme"],
19
+ });
20
+ return () => observer.disconnect();
21
+ };
22
+ // Keep a gutter outside the safe area; explicit offsets override each supplied
23
+ // edge, while omitted edges retain the safe default. Sonner applies these only
24
+ // at its mobile breakpoint, so desktop positioning is unchanged.
25
+ const safeMobileOffset = {
26
+ top: "calc(16px + var(--safe-area-inset-top, env(safe-area-inset-top, 0px)))",
27
+ right: "calc(16px + var(--safe-area-inset-right, env(safe-area-inset-right, 0px)))",
28
+ bottom: "calc(16px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)))",
29
+ left: "calc(16px + var(--safe-area-inset-left, env(safe-area-inset-left, 0px)))",
30
+ };
31
+ const resolveMobileOffset = (offset) => typeof offset === "number" || typeof offset === "string"
32
+ ? offset
33
+ : {
34
+ top: offset?.top ?? safeMobileOffset.top,
35
+ right: offset?.right ?? safeMobileOffset.right,
36
+ bottom: offset?.bottom ?? safeMobileOffset.bottom,
37
+ left: offset?.left ?? safeMobileOffset.left,
38
+ };
13
39
  /* Maps PlexUI semantic tokens onto sonner's CSS-variable hooks. Sonner's own
14
40
  stylesheet reads these for every toast, so the base look stays aligned with
15
41
  <Popover> / <Menu> without overriding each slot. */
@@ -20,20 +46,9 @@ const toasterStyle = {
20
46
  "--border-radius": "var(--radius-xl)",
21
47
  "--width": "400px",
22
48
  };
23
- export const Toaster = ({ position = "top-center", duration = 3000, offset, gap, ...restProps }) => {
24
- const [theme, setTheme] = useState("light");
25
- useEffect(() => {
26
- setTheme(readTheme());
27
- const observer = new MutationObserver(() => {
28
- setTheme(readTheme());
29
- });
30
- observer.observe(document.documentElement, {
31
- attributes: true,
32
- attributeFilter: ["data-theme"],
33
- });
34
- return () => observer.disconnect();
35
- }, []);
36
- return (_jsx(SonnerToaster, { theme: theme, position: position, duration: duration, offset: offset, gap: gap, className: s.Toaster, style: toasterStyle, icons: {
49
+ export const Toaster = ({ position = "top-center", duration = 3000, offset, mobileOffset, gap, ...restProps }) => {
50
+ const theme = useSyncExternalStore(subscribeTheme, readTheme, () => "light");
51
+ return (_jsx(SonnerToaster, { theme: theme, position: position, duration: duration, offset: offset, mobileOffset: resolveMobileOffset(mobileOffset), gap: gap, className: s.Toaster, style: toasterStyle, icons: {
37
52
  success: _jsx(CheckCircle, { "aria-hidden": "true" }),
38
53
  error: _jsx(XCircle, { "aria-hidden": "true" }),
39
54
  warning: _jsx(Warning, { "aria-hidden": "true" }),
@@ -1 +1 @@
1
- {"version":3,"file":"Toaster.js","sourceRoot":"","sources":["../../../../src/components/Toast/Toaster.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAsB,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC/D,OAAO,EAAE,OAAO,IAAI,aAAa,EAA2C,MAAM,QAAQ,CAAA;AAC1F,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACnE,OAAO,CAAC,MAAM,kDAAkD,CAAA;AAEhE;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,OAAO,EAAW,CAAA;AAsBxD,MAAM,SAAS,GAAG,GAAc,EAAE,CAChC,QAAQ,CAAC,eAAe,CAAC,YAAY,CAAC,YAAY,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAA;AAEnF;;sDAEsD;AACtD,MAAM,YAAY,GAAkB;IAClC,aAAa,EAAE,+BAA+B;IAC9C,eAAe,EAAE,mBAAmB;IACpC,iBAAiB,EAAE,aAAa;IAChC,iBAAiB,EAAE,kBAAkB;IACrC,SAAS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AW,EAAE,CAAC,CAAC,WAAW;gBAC1B,OAAO,EAAE,CAAC,CAAC,OAAO;gBAClB,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,YAAY,EAAE,CAAC,CAAC,YAAY;gBAC5B,YAAY,EAAE,CAAC,CAAC,YAAY;gBAC5B,OAAO,EAAE,CAAC,CAAC,OAAO;gBAClB,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,OAAO,EAAE,CAAC,CAAC,OAAO;gBAClB,IAAI,EAAE,CAAC,CAAC,IAAI;aACb;SACF,KACG,SAAS,GACb,CACH,CAAA;AACH,CAAC,CAAA","sourcesContent":["\"use client\"\n\nimport { type CSSProperties, useEffect, useState } from \"react\"\nimport { Toaster as SonnerToaster, type ToasterProps as SonnerToasterProps } from \"sonner\"\nimport { CheckCircle, InfoCircle, Warning, XCircle } from \"../Icon\"\nimport s from \"@plexui/styles/components/Toast/Toast.module.css\"\n\n/**\n * Spread into any `toast(...)` options to get a shrink-to-fit, centered\n * layout: `toast(\"Saved\", compact)`, `toast.success(\"Done\", { ...compact, description })`.\n */\nexport const compact = { className: s.Compact } as const\n\ntype PlexTheme = \"light\" | \"dark\"\n\nexport type ToasterProps = {\n position?: SonnerToasterProps[\"position\"]\n duration?: SonnerToasterProps[\"duration\"]\n offset?: SonnerToasterProps[\"offset\"]\n gap?: SonnerToasterProps[\"gap\"]\n} & Omit<\n SonnerToasterProps,\n | \"position\"\n | \"duration\"\n | \"closeButton\"\n | \"offset\"\n | \"gap\"\n | \"theme\"\n | \"richColors\"\n | \"toastOptions\"\n | \"style\"\n>\n\nconst readTheme = (): PlexTheme =>\n document.documentElement.getAttribute(\"data-theme\") === \"dark\" ? \"dark\" : \"light\"\n\n/* Maps PlexUI semantic tokens onto sonner's CSS-variable hooks. Sonner's own\n stylesheet reads these for every toast, so the base look stays aligned with\n <Popover> / <Menu> without overriding each slot. */\nconst toasterStyle: CSSProperties = {\n \"--normal-bg\": \"var(--color-surface-elevated)\",\n \"--normal-text\": \"var(--color-text)\",\n \"--normal-border\": \"transparent\",\n \"--border-radius\": \"var(--radius-xl)\",\n \"--width\": \"400px\",\n} as CSSProperties\n\nexport const Toaster = ({\n position = \"top-center\",\n duration = 3000,\n offset,\n gap,\n ...restProps\n}: ToasterProps) => {\n const [theme, setTheme] = useState<PlexTheme>(\"light\")\n\n useEffect(() => {\n setTheme(readTheme())\n\n const observer = new MutationObserver(() => {\n setTheme(readTheme())\n })\n\n observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: [\"data-theme\"],\n })\n\n return () => observer.disconnect()\n }, [])\n\n return (\n <SonnerToaster\n theme={theme}\n position={position}\n duration={duration}\n offset={offset}\n gap={gap}\n className={s.Toaster}\n style={toasterStyle}\n icons={{\n success: <CheckCircle aria-hidden=\"true\" />,\n error: <XCircle aria-hidden=\"true\" />,\n warning: <Warning aria-hidden=\"true\" />,\n info: <InfoCircle aria-hidden=\"true\" />,\n }}\n toastOptions={{\n classNames: {\n toast: s.Toast,\n title: s.Title,\n description: s.Description,\n content: s.Content,\n icon: s.Icon,\n actionButton: s.ActionButton,\n cancelButton: s.CancelButton,\n success: s.Success,\n error: s.Error,\n warning: s.Warning,\n info: s.Info,\n },\n }}\n {...restProps}\n />\n )\n}\n"]}
1
+ {"version":3,"file":"Toaster.js","sourceRoot":"","sources":["../../../../src/components/Toast/Toaster.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAsB,oBAAoB,EAAE,MAAM,OAAO,CAAA;AAChE,OAAO,EAA2C,MAAM,QAAQ,CAAA;AAChE,OAAO,EAAE,aAAa,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAChE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACnE,OAAO,CAAC,MAAM,kDAAkD,CAAA;AAEhE;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,O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,CAAC,CAAC,IAAI;aACb;SACF,KACG,SAAS,GACb,CACH,CAAA;AACH,CAAC,CAAA","sourcesContent":["\"use client\"\n\nimport { type CSSProperties, useSyncExternalStore } from \"react\"\nimport { type ToasterProps as SonnerToasterProps } from \"sonner\"\nimport { ToastRenderer as SonnerToaster } from \"./ToastRenderer\"\nimport { CheckCircle, InfoCircle, Warning, XCircle } from \"../Icon\"\nimport s from \"@plexui/styles/components/Toast/Toast.module.css\"\n\n/**\n * Spread into any `toast(...)` options to get a shrink-to-fit, centered\n * layout: `toast(\"Saved\", compact)`, `toast.success(\"Done\", { ...compact, description })`.\n */\nexport const compact = { className: s.Compact } as const\n\ntype PlexTheme = \"light\" | \"dark\"\n\nexport type ToasterProps = {\n position?: SonnerToasterProps[\"position\"]\n duration?: SonnerToasterProps[\"duration\"]\n offset?: SonnerToasterProps[\"offset\"]\n /** Mobile gutter outside the safe area; explicit edges override the safe defaults. */\n mobileOffset?: SonnerToasterProps[\"mobileOffset\"]\n gap?: SonnerToasterProps[\"gap\"]\n} & Omit<\n SonnerToasterProps,\n | \"position\"\n | \"duration\"\n | \"closeButton\"\n | \"offset\"\n | \"mobileOffset\"\n | \"gap\"\n | \"theme\"\n | \"richColors\"\n | \"toastOptions\"\n | \"style\"\n>\n\nconst readTheme = (): PlexTheme =>\n document.documentElement.getAttribute(\"data-theme\") === \"dark\" ? \"dark\" : \"light\"\n\nconst subscribeTheme = (onChange: () => void) => {\n const observer = new MutationObserver(onChange)\n observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: [\"data-theme\"],\n })\n return () => observer.disconnect()\n}\n\n// Keep a gutter outside the safe area; explicit offsets override each supplied\n// edge, while omitted edges retain the safe default. Sonner applies these only\n// at its mobile breakpoint, so desktop positioning is unchanged.\nconst safeMobileOffset = {\n top: \"calc(16px + var(--safe-area-inset-top, env(safe-area-inset-top, 0px)))\",\n right: \"calc(16px + var(--safe-area-inset-right, env(safe-area-inset-right, 0px)))\",\n bottom: \"calc(16px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)))\",\n left: \"calc(16px + var(--safe-area-inset-left, env(safe-area-inset-left, 0px)))\",\n}\n\nconst resolveMobileOffset = (offset: SonnerToasterProps[\"mobileOffset\"]) =>\n typeof offset === \"number\" || typeof offset === \"string\"\n ? offset\n : {\n top: offset?.top ?? safeMobileOffset.top,\n right: offset?.right ?? safeMobileOffset.right,\n bottom: offset?.bottom ?? safeMobileOffset.bottom,\n left: offset?.left ?? safeMobileOffset.left,\n }\n\n/* Maps PlexUI semantic tokens onto sonner's CSS-variable hooks. Sonner's own\n stylesheet reads these for every toast, so the base look stays aligned with\n <Popover> / <Menu> without overriding each slot. */\nconst toasterStyle: CSSProperties = {\n \"--normal-bg\": \"var(--color-surface-elevated)\",\n \"--normal-text\": \"var(--color-text)\",\n \"--normal-border\": \"transparent\",\n \"--border-radius\": \"var(--radius-xl)\",\n \"--width\": \"400px\",\n} as CSSProperties\n\nexport const Toaster = ({\n position = \"top-center\",\n duration = 3000,\n offset,\n mobileOffset,\n gap,\n ...restProps\n}: ToasterProps) => {\n const theme = useSyncExternalStore(subscribeTheme, readTheme, (): PlexTheme => \"light\")\n\n return (\n <SonnerToaster\n theme={theme}\n position={position}\n duration={duration}\n offset={offset}\n mobileOffset={resolveMobileOffset(mobileOffset)}\n gap={gap}\n className={s.Toaster}\n style={toasterStyle}\n icons={{\n success: <CheckCircle aria-hidden=\"true\" />,\n error: <XCircle aria-hidden=\"true\" />,\n warning: <Warning aria-hidden=\"true\" />,\n info: <InfoCircle aria-hidden=\"true\" />,\n }}\n toastOptions={{\n classNames: {\n toast: s.Toast,\n title: s.Title,\n description: s.Description,\n content: s.Content,\n icon: s.Icon,\n actionButton: s.ActionButton,\n cancelButton: s.CancelButton,\n success: s.Success,\n error: s.Error,\n warning: s.Warning,\n info: s.Info,\n },\n }}\n {...restProps}\n />\n )\n}\n"]}
@@ -0,0 +1,283 @@
1
+ const EXIT_DURATION = 200;
2
+ export class ToastLifecycle {
3
+ dismissStore;
4
+ notify;
5
+ entries = [];
6
+ config = { position: "top-center", duration: 3000, gap: 14, visibleToasts: 3 };
7
+ listeners = new Set();
8
+ revision = 0;
9
+ doc = null;
10
+ hidden = false;
11
+ hovered = false;
12
+ focused = false;
13
+ gesture;
14
+ previousFocus = null;
15
+ nodes = new Map();
16
+ lists = new Map();
17
+ suppressed = new Map();
18
+ lastPointerType = "";
19
+ constructor(dismissStore, notify) {
20
+ this.dismissStore = dismissStore;
21
+ this.notify = notify;
22
+ }
23
+ subscribe = (listener) => { this.listeners.add(listener); return () => { this.listeners.delete(listener); }; };
24
+ snapshot = () => this.revision;
25
+ emit() { this.revision++; this.listeners.forEach((listener) => listener()); }
26
+ get expanded() { return this.hovered || this.focused; }
27
+ get paused() { return this.expanded || Boolean(this.gesture) || this.hidden; }
28
+ connect(doc) { this.doc = doc; this.hidden = doc.hidden; doc.addEventListener("visibilitychange", this.visibility); this.refreshTimers(); }
29
+ visibility = () => { this.hidden = Boolean(this.doc?.hidden); this.refreshTimers(); this.emit(); };
30
+ disconnect() {
31
+ this.doc?.removeEventListener("visibilitychange", this.visibility);
32
+ for (const entry of this.entries) {
33
+ clearTimeout(entry.timer);
34
+ clearTimeout(entry.exitTimer);
35
+ clearTimeout(entry.mountTimer);
36
+ entry.timer = undefined;
37
+ entry.started = undefined;
38
+ }
39
+ this.doc = null;
40
+ this.gesture = undefined;
41
+ this.hovered = false;
42
+ this.focused = false;
43
+ this.previousFocus = null;
44
+ }
45
+ sync(toasts, config) {
46
+ const oldDuration = this.config.duration;
47
+ this.config = config;
48
+ const incoming = toasts.filter((toast) => config.id ? toast.toasterId === config.id : !toast.toasterId);
49
+ const present = new Set(incoming.map((toast) => toast.id));
50
+ for (const entry of this.entries)
51
+ if (!present.has(entry.toast.id) && !entry.removed)
52
+ this.close(entry.toast.id, toasts.some((toast) => toast.id === entry.toast.id) ? "detach" : "external");
53
+ const ordered = [];
54
+ for (const toast of incoming) {
55
+ if (this.suppressed.get(toast.id) === toast)
56
+ continue;
57
+ let entry = this.entries.find((item) => item.toast.id === toast.id);
58
+ if (!entry) {
59
+ entry = { toast, removed: false, mounted: false, height: 0, x: 0, y: 0, swiping: false, remaining: toast.duration || config.duration, exitOffset: 0 };
60
+ const mountedEntry = entry;
61
+ entry.mountTimer = setTimeout(() => { mountedEntry.mounted = true; this.emit(); }, 0);
62
+ }
63
+ else if (entry.toast !== toast || entry.detached) {
64
+ const restart = entry.removed || entry.toast.type !== toast.type || entry.toast.duration !== toast.duration;
65
+ entry.toast = toast;
66
+ entry.detached = false;
67
+ // Same-id updates restart the current budget; only an actual pause
68
+ // subtracts elapsed time (the public Sonner store/update contract).
69
+ clearTimeout(entry.timer);
70
+ entry.timer = undefined;
71
+ entry.started = undefined;
72
+ if (restart) {
73
+ clearTimeout(entry.exitTimer);
74
+ this.pause(entry);
75
+ entry.removed = false;
76
+ entry.swipeOut = undefined;
77
+ entry.remaining = toast.duration || config.duration;
78
+ }
79
+ }
80
+ if (this.gesture?.id === toast.id && (toast.type === "loading" || toast.dismissible === false)) {
81
+ this.gesture = undefined;
82
+ entry.swiping = false;
83
+ entry.x = 0;
84
+ entry.y = 0;
85
+ }
86
+ if (oldDuration !== config.duration && !toast.duration) {
87
+ this.pause(entry);
88
+ entry.remaining = config.duration;
89
+ }
90
+ ordered.push(entry);
91
+ }
92
+ this.entries = [...ordered, ...this.entries.filter((entry) => entry.removed && !present.has(entry.toast.id))];
93
+ for (const id of this.suppressed.keys())
94
+ if (!present.has(id))
95
+ this.suppressed.delete(id);
96
+ this.refreshTimers();
97
+ this.emit();
98
+ }
99
+ pause(entry) {
100
+ if (entry.started !== undefined)
101
+ entry.remaining = Math.max(0, entry.remaining - (Date.now() - entry.started));
102
+ clearTimeout(entry.timer);
103
+ entry.timer = undefined;
104
+ entry.started = undefined;
105
+ }
106
+ refreshTimers() {
107
+ for (const entry of this.entries) {
108
+ if (entry.removed || this.paused || entry.toast.type === "loading" || entry.remaining === Infinity) {
109
+ this.pause(entry);
110
+ continue;
111
+ }
112
+ if (entry.timer !== undefined)
113
+ continue;
114
+ entry.started = Date.now();
115
+ entry.timer = setTimeout(() => this.close(entry.toast.id, "auto"), Math.max(0, entry.remaining));
116
+ }
117
+ }
118
+ position(entry) { return entry.toast.position ?? this.config.position; }
119
+ at(position) { return this.entries.filter((entry) => this.position(entry) === position); }
120
+ offset(entry) {
121
+ if (entry.removed)
122
+ return entry.exitOffset;
123
+ const siblings = this.at(this.position(entry)).filter((item) => !item.removed);
124
+ return siblings.slice(0, siblings.indexOf(entry)).reduce((sum, item) => sum + item.height + this.config.gap, 0);
125
+ }
126
+ setNode(id, node) { if (node)
127
+ this.nodes.set(id, node);
128
+ else
129
+ this.nodes.delete(id); }
130
+ setList(position, node) { if (node)
131
+ this.lists.set(position, node);
132
+ else
133
+ this.lists.delete(position); }
134
+ measure(id, height) { const entry = this.entries.find((item) => item.toast.id === id); if (entry && entry.height !== height) {
135
+ entry.height = height;
136
+ this.emit();
137
+ } }
138
+ close(id, reason) {
139
+ const entry = this.entries.find((item) => item.toast.id === id);
140
+ if (!entry || entry.removed || reason === "dismiss" && (entry.toast.dismissible === false || entry.toast.type === "loading"))
141
+ return;
142
+ entry.exitOffset = this.offset(entry);
143
+ entry.removed = true;
144
+ entry.detached = reason === "detach";
145
+ this.pause(entry);
146
+ if (this.gesture?.id === id)
147
+ this.gesture = undefined;
148
+ entry.swiping = false;
149
+ if (reason === "dismiss" || reason === "auto" || reason === "external")
150
+ this.notify(reason === "external" ? "dismiss" : reason, entry.toast);
151
+ const node = this.nodes.get(id);
152
+ if (node?.contains(this.doc?.activeElement ?? null))
153
+ this.restoreFocus();
154
+ entry.exitTimer = setTimeout(() => {
155
+ if (reason !== "detach")
156
+ this.suppressed.set(id, entry.toast);
157
+ this.entries = this.entries.filter((item) => item !== entry);
158
+ if (reason !== "external" && reason !== "detach")
159
+ this.dismissStore(id);
160
+ this.emit();
161
+ }, EXIT_DURATION);
162
+ this.refreshTimers();
163
+ this.emit();
164
+ }
165
+ ownsFocus(target) { return target instanceof Node && [...this.lists.values()].some((list) => list.contains(target)); }
166
+ focusIn(event) {
167
+ if (!this.focused && event.relatedTarget instanceof HTMLElement && !this.ownsFocus(event.relatedTarget))
168
+ this.previousFocus = event.relatedTarget;
169
+ this.focused = true;
170
+ this.refreshTimers();
171
+ this.emit();
172
+ }
173
+ focusOut(event) {
174
+ if (this.ownsFocus(event.relatedTarget))
175
+ return;
176
+ this.focused = false;
177
+ // An intentional move to another control owns focus. Never bounce through the opener.
178
+ if (event.relatedTarget instanceof HTMLElement)
179
+ this.previousFocus = null;
180
+ this.refreshTimers();
181
+ this.emit();
182
+ }
183
+ restoreFocus() {
184
+ const previous = this.previousFocus;
185
+ this.previousFocus = null;
186
+ this.focused = false;
187
+ if (previous?.isConnected)
188
+ previous.focus({ preventScroll: true });
189
+ }
190
+ keyDown(event, hotkey) {
191
+ if (hotkey.length && hotkey.every((key) => key === event.code || (key === "altKey" && event.altKey) || (key === "ctrlKey" && event.ctrlKey) || (key === "metaKey" && event.metaKey) || (key === "shiftKey" && event.shiftKey))) {
192
+ const list = this.lists.values().next().value;
193
+ if (list) {
194
+ event.preventDefault();
195
+ list.focus({ preventScroll: true });
196
+ }
197
+ }
198
+ else if (event.key === "Escape" && this.ownsFocus(this.doc?.activeElement ?? null)) {
199
+ this.hovered = false;
200
+ this.restoreFocus();
201
+ this.refreshTimers();
202
+ this.emit();
203
+ }
204
+ }
205
+ pointerEnter(event) { this.lastPointerType = event.pointerType; this.hover(event.pointerType !== "touch"); }
206
+ hover(value) {
207
+ if (value && (this.lastPointerType === "touch" || this.doc?.documentElement.dataset.input === "touch" || this.doc?.defaultView?.matchMedia?.("(hover: none) and (pointer: coarse)").matches))
208
+ return;
209
+ this.hovered = value;
210
+ this.refreshTimers();
211
+ this.emit();
212
+ }
213
+ pointerDown(id, event) {
214
+ this.lastPointerType = event.pointerType;
215
+ if (event.pointerType === "touch" && this.hovered) {
216
+ this.hovered = false;
217
+ this.refreshTimers();
218
+ this.emit();
219
+ }
220
+ const entry = this.entries.find((item) => item.toast.id === id);
221
+ if (this.gesture || !entry || entry.removed || event.button !== 0 || entry.toast.type === "loading" || entry.toast.dismissible === false)
222
+ return;
223
+ if (event.target instanceof Element && event.target.closest("button, a, input, textarea, select, [contenteditable='true']"))
224
+ return;
225
+ this.gesture = { id, pointerId: event.pointerId, x: event.clientX, y: event.clientY, started: Date.now() };
226
+ entry.swiping = true;
227
+ this.nodes.get(id)?.setPointerCapture?.(event.pointerId);
228
+ this.refreshTimers();
229
+ this.emit();
230
+ }
231
+ pointerMove(id, event) {
232
+ const gesture = this.gesture;
233
+ const entry = this.entries.find((item) => item.toast.id === id);
234
+ if (!gesture || gesture.id !== id || gesture.pointerId !== event.pointerId || !entry)
235
+ return;
236
+ if (this.doc?.getSelection()?.toString())
237
+ return;
238
+ const dx = event.clientX - gesture.x, dy = event.clientY - gesture.y;
239
+ if (!gesture.axis && Math.max(Math.abs(dx), Math.abs(dy)) > 1)
240
+ gesture.axis = Math.abs(dx) > Math.abs(dy) ? "x" : "y";
241
+ const [vertical, horizontal] = this.position(entry).split("-");
242
+ const allowed = this.config.swipeDirections ?? [vertical, horizontal];
243
+ entry.x = gesture.axis === "x" && allowed.includes(dx > 0 ? "right" : "left") ? dx : 0;
244
+ entry.y = gesture.axis === "y" && allowed.includes(dy > 0 ? "bottom" : "top") ? dy : 0;
245
+ this.emit();
246
+ }
247
+ pointerEnd(id, event, cancelled = false) {
248
+ const gesture = this.gesture;
249
+ const entry = this.entries.find((item) => item.toast.id === id);
250
+ if (!gesture || gesture.id !== id || gesture.pointerId !== event.pointerId || !entry)
251
+ return;
252
+ const distance = Math.max(Math.abs(entry.x), Math.abs(entry.y));
253
+ this.gesture = undefined;
254
+ entry.swiping = false;
255
+ if (!cancelled && (distance >= 45 || distance > 3 && distance / Math.max(1, Date.now() - gesture.started) > 0.11)) {
256
+ entry.swipeOut = entry.x ? entry.x > 0 ? "right" : "left" : entry.y > 0 ? "down" : "up";
257
+ this.close(id, "dismiss");
258
+ }
259
+ else {
260
+ entry.x = 0;
261
+ entry.y = 0;
262
+ }
263
+ this.refreshTimers();
264
+ this.emit();
265
+ }
266
+ }
267
+ export const offsetStyles = (offset, mobileOffset) => {
268
+ const style = {};
269
+ for (const [prefix, value, fallback] of [["--offset", offset, "32px"], ["--mobile-offset", mobileOffset, "16px"]]) {
270
+ for (const edge of ["top", "right", "bottom", "left"]) {
271
+ const size = typeof value === "object" ? value[edge] ?? fallback : value ?? fallback;
272
+ style[`${prefix}-${edge}`] = typeof size === "number" ? `${size}px` : size;
273
+ }
274
+ }
275
+ return style;
276
+ };
277
+ export const documentDirection = (doc) => {
278
+ const direction = doc?.documentElement.getAttribute("dir");
279
+ if (direction === "ltr" || direction === "rtl")
280
+ return direction;
281
+ return doc?.defaultView?.getComputedStyle(doc.documentElement).direction === "rtl" ? "rtl" : "ltr";
282
+ };
283
+ //# sourceMappingURL=toastLifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toastLifecycle.js","sourceRoot":"","sources":["../../../../src/components/Toast/toastLifecycle.ts"],"names":[],"mappings":"AASA,MAAM,aAAa,GAAG,GAAG,CAAA;AAEzB,MAAM,OAAO,cAAc;IAgBL;IAAgD;IAfpE,OAAO,GAAoB,EAAE,CAAA;IAC7B,MAAM,GAAgB,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,aAAa,EAAE,CAAC,EAAE,CAAA;IACnF,SAAS,GAAG,IAAI,GAAG,EAAc,CAAA;IACjC,QAAQ,GAAG,CAAC,CAAA;IACZ,GAAG,GAAoB,IAAI,CAAA;IAC3B,MAAM,GAAG,KAAK,CAAA;IACd,OAAO,GAAG,KAAK,CAAA;IACf,OAAO,GAAG,KAAK,CAAA;IACf,OAAO,CAAU;IACjB,aAAa,GAAuB,IAAI,CAAA;IACxC,KAAK,GAAG,IAAI,GAAG,EAAwB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,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAU,EAAE,CAAC;YAC/D,MAAM,IAAI,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,QAAQ,CAAA;YACpF,KAAK,CAAC,GAAG,MAAM,IAAI,IAAI,EAAE,CAAC,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAA;QAC5E,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,GAAyB,EAAE,EAAE;IAC7D,MAAM,SAAS,GAAG,GAAG,EAAE,eAAe,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;IAC1D,IAAI,SAAS,KAAK,KAAK,IAAI,SAAS,KAAK,KAAK;QAAE,OAAO,SAAS,CAAA;IAChE,OAAO,GAAG,EAAE,WAAW,EAAE,gBAAgB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;AACpG,CAAC,CAAA","sourcesContent":["/** Framework-independent lifecycle, mirrored in the Vue/React packages so neither\n * published port depends on the other framework. Vendor stores remain public. */\nexport type ToastId = string | number\nexport type Position = \"top-left\" | \"top-center\" | \"top-right\" | \"bottom-left\" | \"bottom-center\" | \"bottom-right\"\nexport type Direction = \"top\" | \"bottom\" | \"left\" | \"right\"\ntype ToastData = { id: ToastId; toasterId?: string; position?: Position; duration?: number; type?: string; dismissible?: boolean }\nexport type ToastConfig = { id?: string; position: Position; duration: number; gap: number; visibleToasts: number; expand?: boolean; swipeDirections?: Direction[] }\nexport type ToastEntry<T> = { toast: T; removed: boolean; detached?: boolean; mounted: boolean; height: number; x: number; y: number; swiping: boolean; swipeOut?: \"up\" | \"down\" | \"left\" | \"right\"; remaining: number; started?: number; timer?: ReturnType<typeof setTimeout>; exitTimer?: ReturnType<typeof setTimeout>; mountTimer?: ReturnType<typeof setTimeout>; exitOffset: number }\ntype Gesture = { id: ToastId; pointerId: number; x: number; y: number; started: number; axis?: \"x\" | \"y\" }\nconst EXIT_DURATION = 200\n\nexport class ToastLifecycle<T extends ToastData> {\n entries: ToastEntry<T>[] = []\n config: ToastConfig = { position: \"top-center\", duration: 3000, gap: 14, visibleToasts: 3 }\n private listeners = new Set<() => void>()\n private revision = 0\n private doc: Document | null = null\n private hidden = false\n private hovered = false\n private focused = false\n private gesture?: Gesture\n private previousFocus: HTMLElement | null = null\n private nodes = new Map<ToastId, HTMLElement>()\n private lists = new Map<Position, HTMLElement>()\n private suppressed = new Map<ToastId, T>()\n private lastPointerType = \"\"\n\n constructor(private dismissStore: (id: ToastId) => unknown, private notify: (reason: \"dismiss\" | \"auto\", toast: T) => void) {}\n subscribe = (listener: () => void) => { this.listeners.add(listener); return () => { this.listeners.delete(listener) } }\n snapshot = () => this.revision\n private emit() { this.revision++; this.listeners.forEach((listener) => listener()) }\n get expanded() { return this.hovered || this.focused }\n get paused() { return this.expanded || Boolean(this.gesture) || this.hidden }\n connect(doc: Document) { this.doc = doc; this.hidden = doc.hidden; doc.addEventListener(\"visibilitychange\", this.visibility); this.refreshTimers() }\n private visibility = () => { this.hidden = Boolean(this.doc?.hidden); this.refreshTimers(); this.emit() }\n disconnect() {\n this.doc?.removeEventListener(\"visibilitychange\", this.visibility)\n for (const entry of this.entries) { clearTimeout(entry.timer); clearTimeout(entry.exitTimer); clearTimeout(entry.mountTimer); entry.timer = undefined; entry.started = undefined }\n this.doc = null\n this.gesture = undefined\n this.hovered = false\n this.focused = false\n this.previousFocus = null\n }\n sync(toasts: T[], config: ToastConfig) {\n const oldDuration = this.config.duration\n this.config = config\n const incoming = toasts.filter((toast) => config.id ? toast.toasterId === config.id : !toast.toasterId)\n const present = new Set(incoming.map((toast) => toast.id))\n for (const entry of this.entries) if (!present.has(entry.toast.id) && !entry.removed) this.close(entry.toast.id, toasts.some((toast) => toast.id === entry.toast.id) ? \"detach\" : \"external\")\n const ordered: ToastEntry<T>[] = []\n for (const toast of incoming) {\n if (this.suppressed.get(toast.id) === toast) continue\n let entry = this.entries.find((item) => item.toast.id === toast.id)\n if (!entry) {\n entry = { toast, removed: false, mounted: false, height: 0, x: 0, y: 0, swiping: false, remaining: toast.duration || config.duration, exitOffset: 0 }\n const mountedEntry = entry\n entry.mountTimer = setTimeout(() => { mountedEntry.mounted = true; this.emit() }, 0)\n } else if (entry.toast !== toast || entry.detached) {\n const restart = entry.removed || entry.toast.type !== toast.type || entry.toast.duration !== toast.duration\n entry.toast = toast\n entry.detached = false\n // Same-id updates restart the current budget; only an actual pause\n // subtracts elapsed time (the public Sonner store/update contract).\n clearTimeout(entry.timer); entry.timer = undefined; entry.started = undefined\n if (restart) {\n clearTimeout(entry.exitTimer); this.pause(entry); entry.removed = false; entry.swipeOut = undefined\n entry.remaining = toast.duration || config.duration\n }\n }\n if (this.gesture?.id === toast.id && (toast.type === \"loading\" || toast.dismissible === false)) { this.gesture = undefined; entry.swiping = false; entry.x = 0; entry.y = 0 }\n if (oldDuration !== config.duration && !toast.duration) { this.pause(entry); entry.remaining = config.duration }\n ordered.push(entry)\n }\n this.entries = [...ordered, ...this.entries.filter((entry) => entry.removed && !present.has(entry.toast.id))]\n for (const id of this.suppressed.keys()) if (!present.has(id)) this.suppressed.delete(id)\n this.refreshTimers()\n this.emit()\n }\n private pause(entry: ToastEntry<T>) {\n if (entry.started !== undefined) entry.remaining = Math.max(0, entry.remaining - (Date.now() - entry.started))\n clearTimeout(entry.timer); entry.timer = undefined; entry.started = undefined\n }\n private refreshTimers() {\n for (const entry of this.entries) {\n if (entry.removed || this.paused || entry.toast.type === \"loading\" || entry.remaining === Infinity) { this.pause(entry); continue }\n if (entry.timer !== undefined) continue\n entry.started = Date.now()\n entry.timer = setTimeout(() => this.close(entry.toast.id, \"auto\"), Math.max(0, entry.remaining))\n }\n }\n position(entry: ToastEntry<T>) { return entry.toast.position ?? this.config.position }\n at(position: Position) { return this.entries.filter((entry) => this.position(entry) === position) }\n offset(entry: ToastEntry<T>) {\n if (entry.removed) return entry.exitOffset\n const siblings = this.at(this.position(entry)).filter((item) => !item.removed)\n return siblings.slice(0, siblings.indexOf(entry)).reduce((sum, item) => sum + item.height + this.config.gap, 0)\n }\n setNode(id: ToastId, node: HTMLElement | null) { if (node) this.nodes.set(id, node); else this.nodes.delete(id) }\n setList(position: Position, node: HTMLElement | null) { if (node) this.lists.set(position, node); else this.lists.delete(position) }\n measure(id: ToastId, height: number) { const entry = this.entries.find((item) => item.toast.id === id); if (entry && entry.height !== height) { entry.height = height; this.emit() } }\n close(id: ToastId, reason: \"dismiss\" | \"auto\" | \"action\" | \"external\" | \"detach\") {\n const entry = this.entries.find((item) => item.toast.id === id)\n if (!entry || entry.removed || reason === \"dismiss\" && (entry.toast.dismissible === false || entry.toast.type === \"loading\")) return\n entry.exitOffset = this.offset(entry)\n entry.removed = true\n entry.detached = reason === \"detach\"\n this.pause(entry)\n if (this.gesture?.id === id) this.gesture = undefined\n entry.swiping = false\n if (reason === \"dismiss\" || reason === \"auto\" || reason === \"external\") this.notify(reason === \"external\" ? \"dismiss\" : reason, entry.toast)\n const node = this.nodes.get(id)\n if (node?.contains(this.doc?.activeElement ?? null)) this.restoreFocus()\n entry.exitTimer = setTimeout(() => {\n if (reason !== \"detach\") this.suppressed.set(id, entry.toast)\n this.entries = this.entries.filter((item) => item !== entry)\n if (reason !== \"external\" && reason !== \"detach\") this.dismissStore(id)\n this.emit()\n }, EXIT_DURATION)\n this.refreshTimers(); this.emit()\n }\n private ownsFocus(target: EventTarget | null) { return target instanceof Node && [...this.lists.values()].some((list) => list.contains(target)) }\n focusIn(event: FocusEvent) {\n if (!this.focused && event.relatedTarget instanceof HTMLElement && !this.ownsFocus(event.relatedTarget)) this.previousFocus = event.relatedTarget\n this.focused = true; this.refreshTimers(); this.emit()\n }\n focusOut(event: FocusEvent) {\n if (this.ownsFocus(event.relatedTarget)) return\n this.focused = false\n // An intentional move to another control owns focus. Never bounce through the opener.\n if (event.relatedTarget instanceof HTMLElement) this.previousFocus = null\n this.refreshTimers(); this.emit()\n }\n private restoreFocus() {\n const previous = this.previousFocus\n this.previousFocus = null; this.focused = false\n if (previous?.isConnected) previous.focus({ preventScroll: true })\n }\n keyDown(event: KeyboardEvent, hotkey: string[]) {\n if (hotkey.length && hotkey.every((key) => key === event.code || (key === \"altKey\" && event.altKey) || (key === \"ctrlKey\" && event.ctrlKey) || (key === \"metaKey\" && event.metaKey) || (key === \"shiftKey\" && event.shiftKey))) {\n const list = this.lists.values().next().value\n if (list) { event.preventDefault(); list.focus({ preventScroll: true }) }\n } else if (event.key === \"Escape\" && this.ownsFocus(this.doc?.activeElement ?? null)) {\n this.hovered = false; this.restoreFocus(); this.refreshTimers(); this.emit()\n }\n }\n pointerEnter(event: PointerEvent) { this.lastPointerType = event.pointerType; this.hover(event.pointerType !== \"touch\") }\n hover(value: boolean) {\n if (value && (this.lastPointerType === \"touch\" || this.doc?.documentElement.dataset.input === \"touch\" || this.doc?.defaultView?.matchMedia?.(\"(hover: none) and (pointer: coarse)\").matches)) return\n this.hovered = value; this.refreshTimers(); this.emit()\n }\n pointerDown(id: ToastId, event: PointerEvent) {\n this.lastPointerType = event.pointerType\n if (event.pointerType === \"touch\" && this.hovered) { this.hovered = false; this.refreshTimers(); this.emit() }\n const entry = this.entries.find((item) => item.toast.id === id)\n if (this.gesture || !entry || entry.removed || event.button !== 0 || entry.toast.type === \"loading\" || entry.toast.dismissible === false) return\n if (event.target instanceof Element && event.target.closest(\"button, a, input, textarea, select, [contenteditable='true']\")) return\n this.gesture = { id, pointerId: event.pointerId, x: event.clientX, y: event.clientY, started: Date.now() }\n entry.swiping = true\n this.nodes.get(id)?.setPointerCapture?.(event.pointerId)\n this.refreshTimers(); this.emit()\n }\n pointerMove(id: ToastId, event: PointerEvent) {\n const gesture = this.gesture\n const entry = this.entries.find((item) => item.toast.id === id)\n if (!gesture || gesture.id !== id || gesture.pointerId !== event.pointerId || !entry) return\n if (this.doc?.getSelection()?.toString()) return\n const dx = event.clientX - gesture.x, dy = event.clientY - gesture.y\n if (!gesture.axis && Math.max(Math.abs(dx), Math.abs(dy)) > 1) gesture.axis = Math.abs(dx) > Math.abs(dy) ? \"x\" : \"y\"\n const [vertical, horizontal] = this.position(entry).split(\"-\")\n const allowed = this.config.swipeDirections ?? [vertical, horizontal]\n entry.x = gesture.axis === \"x\" && allowed.includes(dx > 0 ? \"right\" : \"left\") ? dx : 0\n entry.y = gesture.axis === \"y\" && allowed.includes(dy > 0 ? \"bottom\" : \"top\") ? dy : 0\n this.emit()\n }\n pointerEnd(id: ToastId, event: PointerEvent, cancelled = false) {\n const gesture = this.gesture\n const entry = this.entries.find((item) => item.toast.id === id)\n if (!gesture || gesture.id !== id || gesture.pointerId !== event.pointerId || !entry) return\n const distance = Math.max(Math.abs(entry.x), Math.abs(entry.y))\n this.gesture = undefined; entry.swiping = false\n if (!cancelled && (distance >= 45 || distance > 3 && distance / Math.max(1, Date.now() - gesture.started) > 0.11)) {\n entry.swipeOut = entry.x ? entry.x > 0 ? \"right\" : \"left\" : entry.y > 0 ? \"down\" : \"up\"\n this.close(id, \"dismiss\")\n } else { entry.x = 0; entry.y = 0 }\n this.refreshTimers(); this.emit()\n }\n}\n\nexport type Offset = number | string | Partial<Record<\"top\" | \"right\" | \"bottom\" | \"left\", number | string>>\nexport const offsetStyles = (offset: Offset | undefined, mobileOffset: Offset | undefined) => {\n const style: Record<string, string> = {}\n for (const [prefix, value, fallback] of [[\"--offset\", offset, \"32px\"], [\"--mobile-offset\", mobileOffset, \"16px\"]] as const) {\n for (const edge of [\"top\", \"right\", \"bottom\", \"left\"] as const) {\n const size = typeof value === \"object\" ? value[edge] ?? fallback : value ?? fallback\n style[`${prefix}-${edge}`] = typeof size === \"number\" ? `${size}px` : size\n }\n }\n return style\n}\n\nexport const documentDirection = (doc: Document | undefined) => {\n const direction = doc?.documentElement.getAttribute(\"dir\")\n if (direction === \"ltr\" || direction === \"rtl\") return direction\n return doc?.defaultView?.getComputedStyle(doc.documentElement).direction === \"rtl\" ? \"rtl\" : \"ltr\"\n}\n"]}