@esportsplus/ui 0.51.6 → 0.53.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 (183) hide show
  1. package/.github/workflows/bump.yml +4 -1
  2. package/.github/workflows/publish.yml +4 -0
  3. package/README.md +2 -3
  4. package/build/components/accordion/index.d.ts +22 -16
  5. package/build/components/accordion/index.js +10 -36
  6. package/build/components/accordion/scss/index.scss +1 -1
  7. package/build/components/back/index.d.ts +16 -13
  8. package/build/components/back/index.js +11 -11
  9. package/build/components/button/index.d.ts +22 -22
  10. package/build/components/button/index.js +25 -25
  11. package/build/components/checkbox/index.d.ts +1 -1
  12. package/build/components/checkbox/index.js +27 -23
  13. package/build/components/clipboard/index.d.ts +23 -20
  14. package/build/components/clipboard/index.js +1 -0
  15. package/build/components/clipboard/onclick.d.ts +1 -1
  16. package/build/components/clipboard/onclick.js +16 -16
  17. package/build/components/clipboard/write.d.ts +1 -1
  18. package/build/components/counter/index.d.ts +5 -5
  19. package/build/components/counter/index.js +34 -34
  20. package/build/components/ellipsis/index.d.ts +1 -1
  21. package/build/components/ellipsis/index.js +5 -5
  22. package/build/components/form/action.d.ts +3 -3
  23. package/build/components/form/action.js +8 -8
  24. package/build/components/form/index.d.ts +2 -2
  25. package/build/components/form/input.d.ts +8 -6
  26. package/build/components/form/input.js +3 -3
  27. package/build/components/frame/index.d.ts +16 -15
  28. package/build/components/frame/index.js +11 -5
  29. package/build/components/highlight/index.d.ts +17 -16
  30. package/build/components/highlight/index.js +16 -16
  31. package/build/components/icon/index.d.ts +11 -11
  32. package/build/components/icon/index.js +8 -8
  33. package/build/components/index.d.ts +1 -4
  34. package/build/components/index.js +1 -4
  35. package/build/components/input/index.d.ts +1 -1
  36. package/build/components/input/index.js +21 -21
  37. package/build/components/json/download.d.ts +1 -1
  38. package/build/components/loader/index.d.ts +17 -16
  39. package/build/components/loader/index.js +35 -35
  40. package/build/components/loader/scss/index.scss +1 -1
  41. package/build/components/loading/index.d.ts +1 -1
  42. package/build/components/loading/index.js +5 -5
  43. package/build/components/overlay/index.d.ts +16 -15
  44. package/build/components/overlay/index.js +11 -5
  45. package/build/components/overlay/scss/index.scss +1 -1
  46. package/build/components/page/scss/index.scss +1 -1
  47. package/build/components/radio/index.js +1 -1
  48. package/build/components/range/index.d.ts +1 -1
  49. package/build/components/range/index.js +26 -26
  50. package/build/components/root/index.d.ts +1 -4
  51. package/build/components/root/onclick.d.ts +4 -4
  52. package/build/components/root/scss/index.scss +1 -1
  53. package/build/components/select/index.d.ts +4 -7
  54. package/build/components/select/index.js +92 -98
  55. package/build/components/sidebar/index.d.ts +16 -15
  56. package/build/components/sidebar/index.js +11 -5
  57. package/build/components/sidebar/scss/index.scss +1 -1
  58. package/build/components/switch/index.js +1 -1
  59. package/build/components/textarea/index.d.ts +1 -1
  60. package/build/components/textarea/index.js +21 -21
  61. package/build/components/toast/index.d.ts +9 -0
  62. package/build/components/toast/index.js +157 -0
  63. package/build/components/toast/manager.d.ts +60 -0
  64. package/build/components/toast/manager.js +203 -0
  65. package/build/components/toast/scss/index.scss +2 -0
  66. package/build/components/toast/svg/check.svg +1 -0
  67. package/build/components/toast/svg/chevron.svg +1 -0
  68. package/build/components/toast/svg/close.svg +1 -0
  69. package/build/components/toast/svg/copy.svg +1 -0
  70. package/build/components/toast/svg/error.svg +1 -0
  71. package/build/components/toast/svg/info.svg +1 -0
  72. package/build/components/toast/svg/loading.svg +1 -0
  73. package/build/components/toast/svg/success.svg +1 -0
  74. package/build/components/toast/svg/warning.svg +1 -0
  75. package/build/components/tooltip/index.d.ts +40 -40
  76. package/build/components/tooltip/menu.d.ts +11 -12
  77. package/build/components/tooltip/menu.js +38 -24
  78. package/build/components/tooltip/onclick.d.ts +1151 -1151
  79. package/build/components/tooltip/onclick.js +17 -17
  80. package/build/components/tooltip/onhover.d.ts +17 -16
  81. package/build/components/tooltip/onhover.js +17 -17
  82. package/build/components/typewriter/index.d.ts +11 -11
  83. package/build/components/typewriter/index.js +16 -16
  84. package/build/css-utilities/index.scss +1 -1
  85. package/build/css-utilities/scroll-fade/scss/index.scss +2 -0
  86. package/build/css-utilities/scrollbar/scss/index.scss +2 -0
  87. package/build/themes/dark/back.d.ts +8 -4
  88. package/build/themes/dark/index.d.ts +0 -1
  89. package/build/themes/dark/index.js +0 -1
  90. package/build/themes/dark/input.d.ts +2 -2
  91. package/build/themes/dark/select.d.ts +60 -110
  92. package/build/themes/dark/textarea.d.ts +2 -2
  93. package/package.json +15 -15
  94. package/pnpm-workspace.yaml +11 -0
  95. package/src/components/accordion/index.ts +7 -30
  96. package/src/components/accordion/scss/index.scss +9 -12
  97. package/src/components/back/index.ts +4 -5
  98. package/src/components/button/index.ts +2 -3
  99. package/src/components/checkbox/index.ts +7 -2
  100. package/src/components/clipboard/index.ts +2 -1
  101. package/src/components/clipboard/onclick.ts +3 -4
  102. package/src/components/form/input.ts +4 -4
  103. package/src/components/frame/index.ts +9 -5
  104. package/src/components/highlight/index.ts +2 -3
  105. package/src/components/icon/index.ts +2 -3
  106. package/src/components/index.ts +1 -4
  107. package/src/components/loader/index.ts +5 -6
  108. package/src/components/loader/scss/index.scss +1 -1
  109. package/src/components/overlay/index.ts +9 -5
  110. package/src/components/overlay/scss/index.scss +0 -1
  111. package/src/components/page/scss/index.scss +1 -1
  112. package/src/components/root/scss/index.scss +35 -4
  113. package/src/components/root/scss/variables.scss +1 -2
  114. package/src/components/select/index.ts +71 -83
  115. package/src/components/sidebar/index.ts +9 -5
  116. package/src/components/sidebar/scss/index.scss +0 -1
  117. package/src/components/toast/index.ts +188 -0
  118. package/src/components/toast/manager.ts +312 -0
  119. package/src/components/toast/scss/index.scss +276 -0
  120. package/src/components/toast/scss/variables.scss +19 -0
  121. package/src/components/toast/svg/check.svg +1 -0
  122. package/src/components/toast/svg/chevron.svg +1 -0
  123. package/src/components/toast/svg/close.svg +1 -0
  124. package/src/components/toast/svg/copy.svg +1 -0
  125. package/src/components/toast/svg/error.svg +1 -0
  126. package/src/components/toast/svg/info.svg +1 -0
  127. package/src/components/toast/svg/loading.svg +1 -0
  128. package/src/components/toast/svg/success.svg +1 -0
  129. package/src/components/toast/svg/warning.svg +1 -0
  130. package/src/components/tooltip/menu.ts +8 -4
  131. package/src/components/tooltip/onclick.ts +3 -4
  132. package/src/components/tooltip/onhover.ts +2 -3
  133. package/src/components/typewriter/index.ts +2 -3
  134. package/src/css-utilities/index.scss +3 -2
  135. package/src/css-utilities/scroll-fade/scss/index.scss +47 -0
  136. package/src/css-utilities/scroll-fade/scss/variables.scss +3 -0
  137. package/src/css-utilities/scrollbar/scss/index.scss +53 -0
  138. package/src/css-utilities/scrollbar/scss/variables.scss +5 -0
  139. package/src/themes/dark/index.ts +0 -1
  140. package/src/tokens/scss/color.scss +14 -14
  141. package/src/tokens/scss/font-size.scss +12 -11
  142. package/src/tokens/scss/line-height.scss +7 -4
  143. package/src/tokens/scss/scale.scss +22 -0
  144. package/src/tokens/scss/size.scss +12 -9
  145. package/src/tokens/scss/spacer.scss +9 -9
  146. package/storage/svg/bolt.svg +1 -0
  147. package/storage/svg/star.svg +1 -0
  148. package/tsconfig.json +6 -2
  149. package/vite-env.d.ts +1 -0
  150. package/vite.config.ts +73 -72
  151. package/build/components/alert/index.d.ts +0 -19
  152. package/build/components/alert/index.js +0 -151
  153. package/build/components/alert/scss/index.scss +0 -2
  154. package/build/components/alert/svg/check.svg +0 -11
  155. package/build/components/alert/svg/close.svg +0 -12
  156. package/build/components/alert/svg/error.svg +0 -18
  157. package/build/components/scrollbar/index.d.ts +0 -27
  158. package/build/components/scrollbar/index.js +0 -56
  159. package/build/components/scrollbar/scss/index.scss +0 -2
  160. package/build/components/site/index.d.ts +0 -20
  161. package/build/components/site/index.js +0 -9
  162. package/build/components/site/scss/index.scss +0 -2
  163. package/build/components/template/index.d.ts +0 -13
  164. package/build/components/template/index.js +0 -21
  165. package/build/css-utilities/scroller/scss/index.scss +0 -2
  166. package/build/themes/dark/alert.d.ts +0 -11
  167. package/build/themes/dark/alert.js +0 -20
  168. package/src/components/accordion/scss/variables.scss +0 -9
  169. package/src/components/alert/index.ts +0 -165
  170. package/src/components/alert/scss/index.scss +0 -25
  171. package/src/components/alert/scss/variables.scss +0 -3
  172. package/src/components/alert/svg/check.svg +0 -11
  173. package/src/components/alert/svg/close.svg +0 -12
  174. package/src/components/alert/svg/error.svg +0 -18
  175. package/src/components/scrollbar/index.ts +0 -70
  176. package/src/components/scrollbar/scss/index.scss +0 -82
  177. package/src/components/scrollbar/scss/variables.scss +0 -6
  178. package/src/components/site/index.ts +0 -11
  179. package/src/components/site/scss/index.scss +0 -3
  180. package/src/components/template/index.ts +0 -40
  181. package/src/css-utilities/scroller/scss/index.scss +0 -8
  182. package/src/css-utilities/scroller/scss/variables.scss +0 -4
  183. package/src/themes/dark/alert.ts +0 -23
@@ -0,0 +1,188 @@
1
+ import { html } from '@esportsplus/template';
2
+ import { reactive } from '@esportsplus/reactivity';
3
+ import clipboard from '~/components/clipboard';
4
+ import icon from '~/components/icon';
5
+ import { buildVisibleToastLayout, remove, state, toast } from './manager';
6
+ import { toasts } from './manager';
7
+ import type { Toast } from './manager';
8
+ import check from './svg/check.svg';
9
+ import close from './svg/close.svg';
10
+ import copy from './svg/copy.svg';
11
+ import error from './svg/error.svg';
12
+ import info from './svg/info.svg';
13
+ import loading from './svg/loading.svg';
14
+ import success from './svg/success.svg';
15
+ import warning from './svg/warning.svg';
16
+ import './scss/index.scss';
17
+
18
+
19
+ type Position = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'top-center' | 'bottom-center';
20
+
21
+
22
+ type ToastElement = HTMLElement & { __toastObserver?: ResizeObserver };
23
+
24
+
25
+ const ICONS = { error, info, loading, success, warning };
26
+
27
+ const dismiss = toast.dismiss;
28
+
29
+
30
+ function row(toast: Toast, position: Position) {
31
+ let swipe = reactive({ direction: '', x: 0, y: 0 }),
32
+ horizontal = position.endsWith('left') || position.endsWith('right'),
33
+ pointerId = -1,
34
+ pressed = false,
35
+ startX = 0,
36
+ startY = 0,
37
+ swiping = false,
38
+ top = position.startsWith('top');
39
+
40
+ const finish = () => {
41
+ pressed = false;
42
+
43
+ if (!swiping) {
44
+ return;
45
+ }
46
+
47
+ swiping = false;
48
+
49
+ if (Math.hypot(swipe.x, swipe.y) > 80) {
50
+ swipe.direction = Math.abs(swipe.x) > Math.abs(swipe.y)
51
+ ? (swipe.x < 0 ? 'left' : 'right')
52
+ : (swipe.y < 0 ? 'up' : 'down');
53
+
54
+ dismiss(toast.id);
55
+ }
56
+ else {
57
+ swipe.direction = '';
58
+ swipe.x = 0;
59
+ swipe.y = 0;
60
+ }
61
+ };
62
+
63
+ return html`
64
+ <div
65
+ class='${() => `toast toast--${toast.type}${toast.status === 'starting' ? ' toast--starting' : toast.status === 'ending' ? ' toast--ending' : ''}${swipe.x !== 0 || swipe.y !== 0 ? ' toast--swiping' : ''}`}'
66
+ ${{
67
+ style: () => {
68
+ let item = buildVisibleToastLayout([...toasts]).items.find((i) => i.toast === toast),
69
+ visibleIndex = item?.visibleIndex ?? 0, offsetY = item?.offsetY ?? 0;
70
+
71
+ return `
72
+ --toast-index:${visibleIndex};
73
+ --toast-offset-y:${offsetY}px;
74
+ --toast-height:${toast.height}px;
75
+ --toast-swipe-x:${swipe.x}px;
76
+ --toast-swipe-y:${swipe.y}px;`;
77
+ },
78
+ 'data-swipe-direction': () => swipe.direction,
79
+ onconnect: (el: HTMLElement) => {
80
+ // offsetHeight is the untransformed layout height; getBoundingClientRect
81
+ // would include the collapsed scale() transform and report shrunken
82
+ // heights, giving uneven offsets/spacing when the stack expands.
83
+ let observer = new ResizeObserver(() => { toast.height = el.offsetHeight; });
84
+
85
+ (el as ToastElement).__toastObserver = observer;
86
+ observer.observe(el);
87
+ },
88
+ ondisconnect: (el: HTMLElement) => {
89
+ (el as ToastElement).__toastObserver?.disconnect();
90
+ },
91
+ onpointerdown: (e: PointerEvent) => {
92
+ pointerId = e.pointerId;
93
+ pressed = true;
94
+ startX = e.clientX;
95
+ startY = e.clientY;
96
+ },
97
+ onpointermove: (e: PointerEvent) => {
98
+ if (!pressed) {
99
+ return;
100
+ }
101
+
102
+ let x = horizontal ? e.clientX - startX : 0,
103
+ y = top ? Math.min(0, e.clientY - startY) : Math.max(0, e.clientY - startY);
104
+
105
+ // Defer swipe + pointer capture until real movement, otherwise a
106
+ // plain click's captured pointer redirects the click off the
107
+ // close/action buttons and they never fire.
108
+ if (!swiping) {
109
+ if (Math.hypot(x, y) < 6) {
110
+ return;
111
+ }
112
+
113
+ swiping = true;
114
+ (e.currentTarget as HTMLElement).setPointerCapture(pointerId);
115
+ }
116
+
117
+ swipe.x = x;
118
+ swipe.y = y;
119
+ },
120
+ onpointerup: finish,
121
+ onpointercancel: finish
122
+ }}
123
+ >
124
+ <div class='toast-content'>
125
+ ${toast.type !== 'message' ? icon({ class: 'toast-icon' }, ICONS[toast.type]) : ''}
126
+
127
+ <div class='--flex-column --flex-fill'>
128
+ <div class='toast-title'>${toast.title}</div>
129
+ ${toast.description && html`
130
+ <div class='toast-description ${toast.type === 'error' && typeof toast.description === 'string' && toast.description.length > 180 && 'toast-description--clamp'}'>
131
+ ${toast.description}
132
+ </div>
133
+ `}
134
+ </div>
135
+
136
+ ${toast.type === 'error' && typeof toast.description === 'string' && clipboard.onclick(
137
+ {
138
+ class: 'toast-copy button',
139
+ value: String(toast.description)
140
+ },
141
+ (state) => icon(state.copied ? check : copy)
142
+ )}
143
+
144
+ ${toast.action && html`
145
+ <div
146
+ class='toast-action button button--primary'
147
+ onclick=${() => {
148
+ toast.action?.onclick();
149
+ dismiss(toast.id);
150
+ }}
151
+ >
152
+ ${toast.action?.label}
153
+ </div>
154
+ `}
155
+ </div>
156
+
157
+ ${() => toast.dismissible && html`
158
+ <button class='toast-close' aria-label='Dismiss' onclick=${() => dismiss(toast.id)}>
159
+ ${icon(close)}
160
+ </button>
161
+ `}
162
+ </div>
163
+ `;
164
+ }
165
+
166
+
167
+ const toaster = (options?: { position?: Position }) => {
168
+ let position = options?.position ?? 'top-right';
169
+
170
+ return html`
171
+ <div
172
+ class='toaster ${() => state.active ? '--active' : ''}'
173
+ data-position='${position}'
174
+ ${{
175
+ style: () => `--toast-frontmost-height:${buildVisibleToastLayout([...toasts]).frontmostHeight}px;`,
176
+ onmouseenter: () => { state.active = true; },
177
+ onmouseleave: () => { state.active = false; }
178
+ }}
179
+ >
180
+ ${html.reactive(toasts, (value: Toast) => row(value, position))}
181
+ </div>
182
+ `;
183
+ };
184
+
185
+
186
+ export default toaster;
187
+ export { remove, toast };
188
+ export type { Position };
@@ -0,0 +1,312 @@
1
+ import { effect, reactive, ReactiveArray } from '@esportsplus/reactivity';
2
+ import { type Renderable } from '@esportsplus/template';
3
+
4
+
5
+ type Action = {
6
+ label: string;
7
+ onclick: () => void;
8
+ };
9
+
10
+ type Options = {
11
+ action?: Action;
12
+ description?: Renderable<unknown> | string;
13
+ dismissible?: boolean;
14
+ duration?: number;
15
+ id?: string;
16
+ priority?: 'low' | 'high';
17
+ };
18
+
19
+ type Status = 'ending' | 'starting' | 'visible';
20
+
21
+ type Timer = {
22
+ handle: ReturnType<typeof setTimeout> | undefined;
23
+ remaining: number;
24
+ started: number;
25
+ };
26
+
27
+ type Toast = {
28
+ action?: Action;
29
+ createdAt: number;
30
+ description?: Renderable<unknown> | string;
31
+ dismissible: boolean;
32
+ duration: number;
33
+ height: number;
34
+ id: string;
35
+ priority: 'low' | 'high';
36
+ status: Status;
37
+ title: Renderable<unknown> | string;
38
+ type: Type;
39
+ };
40
+
41
+ type Type = 'success' | 'error' | 'info' | 'warning' | 'loading' | 'message';
42
+
43
+
44
+ const DURATIONS: Record<Type, number> = {
45
+ error: 6000,
46
+ info: 4000,
47
+ loading: 0,
48
+ message: 4000,
49
+ success: 4000,
50
+ warning: 6000
51
+ };
52
+
53
+ const EXIT_DURATION = 300;
54
+
55
+
56
+ let counter = 0,
57
+ paused = false,
58
+ timers = new Map<string, Timer>();
59
+
60
+
61
+ function buildVisibleToastLayout(toasts: Toast[]): {
62
+ frontmostHeight: number;
63
+ items: { offsetY: number, toast: Toast, visibleIndex: number }[];
64
+ } {
65
+ // Two parallel cursors:
66
+ // - `full*` advances on every toast, so an ending toast keeps the slot it
67
+ // occupied before dismissal and its exit transform originates from the
68
+ // correct position (otherwise it would snap to Y=0 and slide diagonally).
69
+ // - `live*` advances only on non-ending toasts, so live toasts reflow past
70
+ // the vacated slot in parallel with the exit animation instead of
71
+ // waiting for it to finish (which caused a visible "stop and bump").
72
+ let fullIndex = 0,
73
+ fullOffsetY = 0,
74
+ liveIndex = 0,
75
+ liveOffsetY = 0,
76
+ items = toasts.map((toast) => {
77
+ let height = normalizeToastHeight(toast.height),
78
+ item;
79
+
80
+ if (toast.status === 'ending') {
81
+ item = {
82
+ offsetY: fullOffsetY,
83
+ toast,
84
+ visibleIndex: fullIndex
85
+ };
86
+
87
+ fullOffsetY += height;
88
+ fullIndex += 1;
89
+
90
+ return item;
91
+ }
92
+
93
+ item = {
94
+ offsetY: liveOffsetY,
95
+ toast,
96
+ visibleIndex: liveIndex
97
+ };
98
+
99
+ fullOffsetY += height;
100
+ fullIndex += 1;
101
+ liveOffsetY += height;
102
+ liveIndex += 1;
103
+
104
+ return item;
105
+ }),
106
+ frontmostLiveToast = toasts.find((toast) => toast.status !== 'ending');
107
+
108
+ return {
109
+ frontmostHeight: normalizeToastHeight(frontmostLiveToast?.height),
110
+ items
111
+ };
112
+ }
113
+
114
+ function clearTimer(id: string) {
115
+ let timer = timers.get(id);
116
+
117
+ if (!timer) {
118
+ return;
119
+ }
120
+
121
+ if (timer.handle !== undefined) {
122
+ clearTimeout(timer.handle);
123
+ }
124
+
125
+ timers.delete(id);
126
+ }
127
+
128
+ function create(type: Type, title: Renderable<unknown> | string, options: Options = {}): string {
129
+ let id = options.id ?? `toast-${++counter}`,
130
+ toast = reactive({
131
+ action: options.action,
132
+ createdAt: Date.now(),
133
+ description: options.description,
134
+ dismissible: options.dismissible ?? true,
135
+ duration: options.duration ?? DURATIONS[type],
136
+ height: 0,
137
+ id,
138
+ priority: options.priority ?? 'low',
139
+ status: 'starting' as Status,
140
+ title,
141
+ type
142
+ }) as Toast;
143
+
144
+ toasts.push(toast);
145
+
146
+ queueMicrotask(() => {
147
+ if (toast.status === 'starting' && toasts.includes(toast)) {
148
+ toast.status = 'visible';
149
+ }
150
+ });
151
+
152
+ if (type !== 'loading' && toast.duration > 0) {
153
+ schedule(toast);
154
+ }
155
+
156
+ return id;
157
+ }
158
+
159
+ function dismiss(id: string) {
160
+ let toast = toasts.find((value) => value.id === id);
161
+
162
+ if (!toast || toast.status === 'ending') {
163
+ return;
164
+ }
165
+
166
+ clearTimer(id);
167
+
168
+ toast.status = 'ending';
169
+
170
+ setTimeout(() => remove(id), EXIT_DURATION);
171
+ }
172
+
173
+ function normalizeToastHeight(height: number | null | undefined): number {
174
+ return typeof height === 'number' && Number.isFinite(height) && height > 0 ? height : 0;
175
+ }
176
+
177
+ function pause() {
178
+ for (let timer of timers.values()) {
179
+ if (timer.handle === undefined) {
180
+ continue;
181
+ }
182
+
183
+ clearTimeout(timer.handle);
184
+
185
+ timer.remaining = Math.max(0, timer.remaining - (performance.now() - timer.started));
186
+ timer.handle = undefined;
187
+ }
188
+ }
189
+
190
+ function remove(id: string) {
191
+ let index = toasts.findIndex((toast) => toast.id === id);
192
+
193
+ clearTimer(id);
194
+
195
+ if (index !== -1) {
196
+ toasts.splice(index, 1);
197
+ }
198
+ }
199
+
200
+ function resume() {
201
+ for (let [id, timer] of timers) {
202
+ if (timer.handle !== undefined) {
203
+ continue;
204
+ }
205
+
206
+ timer.started = performance.now();
207
+ timer.handle = setTimeout(() => dismiss(id), timer.remaining);
208
+ }
209
+ }
210
+
211
+ function schedule(toast: Toast) {
212
+ if (toast.duration <= 0) {
213
+ return;
214
+ }
215
+
216
+ if (state.active) {
217
+ timers.set(toast.id, {
218
+ handle: undefined,
219
+ remaining: toast.duration,
220
+ started: 0
221
+ });
222
+
223
+ return;
224
+ }
225
+
226
+ timers.set(toast.id, {
227
+ handle: setTimeout(() => dismiss(toast.id), toast.duration),
228
+ remaining: toast.duration,
229
+ started: performance.now()
230
+ });
231
+ }
232
+
233
+ function update(id: string, options: Options) {
234
+ let toast = toasts.find((value) => value.id === id);
235
+
236
+ if (!toast) {
237
+ return;
238
+ }
239
+
240
+ if (options.action !== undefined) {
241
+ toast.action = options.action;
242
+ }
243
+
244
+ if (options.description !== undefined) {
245
+ toast.description = options.description;
246
+ }
247
+
248
+ if (options.dismissible !== undefined) {
249
+ toast.dismissible = options.dismissible;
250
+ }
251
+
252
+ if (options.priority !== undefined) {
253
+ toast.priority = options.priority;
254
+ }
255
+
256
+ if (options.duration !== undefined) {
257
+ toast.duration = options.duration;
258
+
259
+ clearTimer(id);
260
+
261
+ if (toast.type !== 'loading' && toast.duration > 0 && toast.status !== 'ending') {
262
+ schedule(toast);
263
+ }
264
+ }
265
+ }
266
+
267
+
268
+ const state = reactive({ active: false });
269
+
270
+ const toasts = new ReactiveArray<Toast>();
271
+
272
+ effect(() => {
273
+ let active = state.active;
274
+
275
+ if (active === paused) {
276
+ return;
277
+ }
278
+
279
+ paused = active;
280
+
281
+ if (active) {
282
+ pause();
283
+ }
284
+ else {
285
+ resume();
286
+ }
287
+ });
288
+
289
+ const toast = {
290
+ dismiss: (id?: string) => {
291
+ if (id === undefined) {
292
+ for (let value of [...toasts]) {
293
+ dismiss(value.id);
294
+ }
295
+
296
+ return;
297
+ }
298
+
299
+ dismiss(id);
300
+ },
301
+ error: (title: Renderable<unknown> | string, options?: Options) => create('error', title, options),
302
+ info: (title: Renderable<unknown> | string, options?: Options) => create('info', title, options),
303
+ loading: (title: Renderable<unknown> | string, options?: Options) => create('loading', title, options),
304
+ message: (title: Renderable<unknown> | string, options?: Options) => create('message', title, options),
305
+ success: (title: Renderable<unknown> | string, options?: Options) => create('success', title, options),
306
+ update,
307
+ warning: (title: Renderable<unknown> | string, options?: Options) => create('warning', title, options)
308
+ };
309
+
310
+
311
+ export { buildVisibleToastLayout, remove, state, toast, toasts };
312
+ export type { Options, Toast, Type };