@rkosafo/cai.components 0.0.79 → 0.0.81

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.
@@ -1,337 +1,176 @@
1
1
  <script lang="ts" module>
2
- export type ToastType = 'success' | 'error' | 'warning' | 'info' | 'loading' | 'custom';
3
- export type ToastPosition =
4
- | 'top-left'
5
- | 'top-center'
6
- | 'top-right'
7
- | 'bottom-left'
8
- | 'bottom-center'
9
- | 'bottom-right';
10
-
11
- export interface CustomToastOptions extends ToastOptions {
12
- icon?: string;
13
- showProgress?: boolean;
14
- progressColor?: string;
15
- borderColor?: string;
16
- backgroundColor?: string;
17
- textColor?: string;
18
- iconColor?: string;
19
- style?: any;
20
- action?: {
21
- label: string | boolean;
22
- onClick: () => void;
23
- buttonStyle?: string;
24
- };
25
- }
26
-
27
- export interface ToastTheme {
28
- success?: Partial<CustomToastOptions>;
29
- error?: Partial<CustomToastOptions>;
30
- warning?: Partial<CustomToastOptions>;
31
- info?: Partial<CustomToastOptions>;
32
- loading?: Partial<CustomToastOptions>;
33
- custom?: Partial<CustomToastOptions>;
34
- }
2
+ import {
3
+ toast as originalToast,
4
+ type DefaultToastOptions,
5
+ type Renderable,
6
+ resolveValue,
7
+ type ToastOptions,
8
+ type ToastPosition,
9
+ type ToastType,
10
+ type ValueOrFunction
11
+ } from 'svelte-french-toast';
12
+ export {
13
+ CheckmarkIcon,
14
+ ErrorIcon,
15
+ LoaderIcon,
16
+ ToastBar,
17
+ ToastIcon,
18
+ useToaster,
19
+ useToasterStore
20
+ } from 'svelte-french-toast';
21
+ export { resolveValue };
22
+
23
+ export type {
24
+ DefaultToastOptions,
25
+ IconTheme,
26
+ Toast,
27
+ ToastOptions,
28
+ ToastPosition,
29
+ ToastType,
30
+ Renderable,
31
+ ValueFunction,
32
+ ValueOrFunction
33
+ } from 'svelte-french-toast';
34
+ export type CustomToastOptions = ToastOptions;
35
+ export type ToastTheme = Record<string, never>;
35
36
 
36
37
  export interface ToasterProps {
37
38
  position?: ToastPosition;
38
39
  duration?: number;
39
- theme?: ToastTheme;
40
+ toastOptions?: DefaultToastOptions;
41
+ reverseOrder?: boolean;
42
+ gutter?: number;
43
+ containerStyle?: string;
44
+ containerClassName?: string;
45
+ fireWithSound?: boolean;
46
+ // Kept for backward compatibility (no-op in wrapper mode)
40
47
  className?: string;
41
- toastOptions?: ToastOptions;
48
+ theme?: ToastTheme;
42
49
  richColors?: boolean;
43
50
  customIcons?: boolean;
44
51
  closeButton?: boolean;
45
52
  pauseOnHover?: boolean;
46
- reverseOrder?: boolean;
47
53
  visibleToasts?: number;
48
54
  expand?: boolean;
49
55
  gap?: number;
50
56
  offset?: number | string;
51
57
  }
52
- // Default theme configuration
53
- const defaultTheme: ToastTheme = {
54
- success: {
55
- icon: '✅',
56
- borderColor: '#22c55e',
57
- backgroundColor: '#f0fdf4',
58
- textColor: '#166534',
59
- iconColor: '#16a34a',
60
- progressColor: '#22c55e'
61
- },
62
- error: {
63
- icon: '❌',
64
- borderColor: '#ef4444',
65
- backgroundColor: '#fef2f2',
66
- textColor: '#991b1b',
67
- iconColor: '#dc2626',
68
- progressColor: '#ef4444'
69
- },
70
- warning: {
71
- icon: '⚠️',
72
- borderColor: '#f59e0b',
73
- backgroundColor: '#fffbeb',
74
- textColor: '#92400e',
75
- iconColor: '#d97706',
76
- progressColor: '#f59e0b'
77
- },
78
- info: {
79
- icon: 'ℹ️',
80
- borderColor: '#3b82f6',
81
- backgroundColor: '#eff6ff',
82
- textColor: '#1e40af',
83
- iconColor: '#2563eb',
84
- progressColor: '#3b82f6'
85
- },
86
- loading: {
87
- icon: '⏳',
88
- borderColor: '#6b7280',
89
- backgroundColor: '#f9fafb',
90
- textColor: '#374151',
91
- iconColor: '#6b7280',
92
- progressColor: '#6b7280'
93
- }
94
- };
95
58
 
96
59
  let currentDuration = 4000;
97
- let currentTheme: ToastTheme = {};
98
- let currentRichColors = false;
99
-
100
- function buildToastStyle(
101
- theme: Partial<CustomToastOptions>,
102
- options?: CustomToastOptions,
103
- type?: ToastType,
104
- richColors?: boolean
105
- ): string {
106
- if (options?.style) return options.style;
107
-
108
- const baseStyle = `
109
- border: 1px solid ${options?.borderColor || theme.borderColor || '#e5e7eb'};
110
- background: ${options?.backgroundColor || theme.backgroundColor || '#ffffff'};
111
- color: ${options?.textColor || theme.textColor || '#1f2937'};
112
- padding: 12px 16px;
113
- border-radius: 8px;
114
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
115
- font-size: 14px;
116
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
117
- display: flex;
118
- align-items: center;
119
- gap: 8px;
120
- `;
121
-
122
- if (richColors && type && defaultTheme[type]) {
123
- const richTheme = defaultTheme[type]!;
124
- return `
125
- ${baseStyle}
126
- border-color: ${options?.borderColor || richTheme.borderColor}!important;
127
- background: ${options?.backgroundColor || richTheme.backgroundColor}!important;
128
- color: ${options?.textColor || richTheme.textColor}!important;
129
- `;
60
+ let currentFireWithSound = false;
61
+
62
+ function playToastSound() {
63
+ if (!currentFireWithSound || typeof window === 'undefined') return;
64
+
65
+ try {
66
+ const AudioContextClass = window.AudioContext || (window as Window & { webkitAudioContext?: typeof AudioContext }).webkitAudioContext;
67
+ if (!AudioContextClass) return;
68
+
69
+ const context = new AudioContextClass();
70
+ const oscillator = context.createOscillator();
71
+ const gain = context.createGain();
72
+ oscillator.type = 'sine';
73
+ oscillator.frequency.setValueAtTime(880, context.currentTime);
74
+ gain.gain.setValueAtTime(0.0001, context.currentTime);
75
+ gain.gain.exponentialRampToValueAtTime(0.06, context.currentTime + 0.01);
76
+ gain.gain.exponentialRampToValueAtTime(0.0001, context.currentTime + 0.18);
77
+ oscillator.connect(gain);
78
+ gain.connect(context.destination);
79
+ oscillator.start();
80
+ oscillator.stop(context.currentTime + 0.2);
81
+ } catch {
82
+ // Ignore audio errors.
130
83
  }
131
-
132
- return baseStyle;
133
84
  }
134
85
 
135
- export const toast = {
136
- success: (message: string, options?: CustomToastOptions) => {
137
- const themeOptions = currentTheme?.success || defaultTheme.success || {};
138
- const style = buildToastStyle(themeOptions, options, 'success');
139
-
140
- return originalToast.success(message, {
141
- duration: currentDuration,
142
- ...themeOptions,
143
- ...options,
144
- style,
145
- icon: options?.icon || themeOptions.icon
146
- });
147
- },
148
-
149
- error: (message: string, options?: CustomToastOptions) => {
150
- const themeOptions = currentTheme?.error || defaultTheme.error || {};
151
- const style = buildToastStyle(themeOptions, options, 'error');
152
-
153
- return originalToast.error(message, {
154
- duration: currentDuration,
155
- ...themeOptions,
156
- ...options,
157
- style,
158
- icon: options?.icon || themeOptions.icon
159
- });
160
- },
161
-
162
- warning: (message: string, options?: CustomToastOptions) => {
163
- const themeOptions = currentTheme?.warning || defaultTheme.warning || {};
164
- const style = buildToastStyle(themeOptions, options, 'warning');
165
-
166
- return originalToast(message, {
167
- duration: currentDuration,
168
- ...themeOptions,
169
- ...options,
170
- style,
171
- icon: options?.icon || themeOptions.icon
172
- });
173
- },
174
-
175
- info: (message: string, options?: CustomToastOptions) => {
176
- const themeOptions = currentTheme?.info || defaultTheme.info || {};
177
- const style = buildToastStyle(themeOptions, options, 'info');
178
-
179
- return originalToast(message, {
180
- duration: currentDuration,
181
- ...themeOptions,
182
- ...options,
183
- style,
184
- icon: options?.icon || themeOptions.icon
185
- });
186
- },
187
-
188
- loading: (message: string, options?: CustomToastOptions) => {
189
- const themeOptions = currentTheme?.loading || defaultTheme.loading || {};
190
- const style = buildToastStyle(themeOptions, options, 'loading');
191
-
192
- return originalToast.loading(message, {
193
- duration: currentDuration,
194
- ...themeOptions,
195
- ...options,
196
- style,
197
- icon: options?.icon || themeOptions.icon
198
- });
199
- },
200
-
201
- promise: <T,>(
202
- promise: Promise<T>,
203
- messages: { loading: string; success: string; error: string },
204
- options?: {
205
- loading?: CustomToastOptions;
206
- success?: CustomToastOptions;
207
- error?: CustomToastOptions;
208
- }
209
- ) => {
210
- const loadingTheme = currentTheme?.loading || defaultTheme.loading || {};
211
- const successTheme = currentTheme?.success || defaultTheme.success || {};
212
- const errorTheme = currentTheme?.error || defaultTheme.error || {};
213
-
214
- return originalToast.promise(promise, messages, {
215
- loading: {
216
- ...loadingTheme,
217
- ...options?.loading,
218
- style: buildToastStyle(loadingTheme, options?.loading, 'loading'),
219
- icon: options?.loading?.icon || loadingTheme.icon
220
- },
221
- success: {
222
- ...successTheme,
223
- ...options?.success,
224
- style: buildToastStyle(successTheme, options?.success, 'success'),
225
- icon: options?.success?.icon || successTheme.icon
226
- },
227
- error: {
228
- ...errorTheme,
229
- ...options?.error,
230
- style: buildToastStyle(errorTheme, options?.error, 'error'),
231
- icon: options?.error?.icon || errorTheme.icon
232
- }
233
- });
234
- },
235
-
236
- // Custom toast with complete control
237
- custom: (message: string, type: ToastType = 'info', options?: CustomToastOptions) => {
238
- const themeOptions = currentTheme?.[type] || defaultTheme[type] || defaultTheme.info || {};
239
- const style = buildToastStyle(themeOptions, options, type);
240
-
241
- return originalToast(message, {
242
- duration: currentDuration,
243
- ...themeOptions,
244
- ...options,
245
- style,
246
- icon: options?.icon || themeOptions.icon
247
- });
248
- },
249
-
250
- // Action toast with button
251
- action: (
252
- message: string,
253
- action: { label: string; onClick: () => void },
254
- options?: CustomToastOptions
255
- ) => {
256
- const themeOptions = currentTheme?.info || defaultTheme.info || {};
257
- const style = buildToastStyle(themeOptions, options, 'info');
258
-
259
- return originalToast(message, {
260
- duration: currentDuration,
261
- ...themeOptions,
262
- ...options,
263
- style,
264
- icon: options?.icon || themeOptions.icon,
265
- action: {
266
- label: action.label,
267
- onClick: action.onClick,
268
- buttonStyle:
269
- options?.action?.buttonStyle ||
270
- 'background: #3b82f6; color: white; border: none; padding: 4px 12px; border-radius: 4px; cursor: pointer;'
271
- }
272
- });
273
- },
274
-
275
- // Dismiss specific toast or all toasts
276
- dismiss: (toastId?: string) => {
277
- return originalToast.dismiss(toastId);
278
- },
279
-
280
- // Remove specific toast
281
- remove: (toastId?: string) => {
282
- return originalToast.remove(toastId);
283
- }
284
- };
285
-
286
86
  export function updateToastConfig(config: {
287
87
  duration?: number;
88
+ fireWithSound?: boolean;
288
89
  theme?: ToastTheme;
289
90
  richColors?: boolean;
290
91
  }) {
291
92
  if (config.duration !== undefined) currentDuration = config.duration;
292
- if (config.theme !== undefined) currentTheme = config.theme;
293
- if (config.richColors !== undefined) currentRichColors = config.richColors;
93
+ if (config.fireWithSound !== undefined) currentFireWithSound = config.fireWithSound;
294
94
  }
295
95
 
96
+ export const toast = Object.assign(
97
+ (message: Renderable, options?: ToastOptions) => {
98
+ playToastSound();
99
+ return originalToast(message, { duration: currentDuration, ...options });
100
+ },
101
+ {
102
+ success: (message: Renderable, options?: ToastOptions) => {
103
+ playToastSound();
104
+ return originalToast.success(message, { duration: currentDuration, ...options });
105
+ },
106
+ error: (message: Renderable, options?: ToastOptions) => {
107
+ playToastSound();
108
+ return originalToast.error(message, { duration: currentDuration, ...options });
109
+ },
110
+ loading: (message: Renderable, options?: ToastOptions) => {
111
+ playToastSound();
112
+ return originalToast.loading(message, { duration: currentDuration, ...options });
113
+ },
114
+ promise: <T,>(
115
+ promise: Promise<T>,
116
+ msgs: {
117
+ loading: Renderable;
118
+ success: ValueOrFunction<Renderable, T>;
119
+ error: ValueOrFunction<Renderable, any>;
120
+ },
121
+ opts?: DefaultToastOptions
122
+ ) => {
123
+ playToastSound();
124
+ return originalToast.promise(promise, msgs, opts);
125
+ },
126
+ dismiss: originalToast.dismiss.bind(originalToast),
127
+ remove: originalToast.remove.bind(originalToast),
128
+ custom: originalToast.custom.bind(originalToast)
129
+ }
130
+ );
131
+
296
132
  export { originalToast };
297
133
  export type { ToastOptions };
298
134
  </script>
299
135
 
300
136
  <script lang="ts">
301
- import { Toaster, toast as originalToast, type ToastOptions } from 'svelte-french-toast';
137
+ import { Toaster } from 'svelte-french-toast';
302
138
 
303
139
  let {
304
140
  position = 'top-center',
305
141
  duration = 4000,
306
- theme = {},
307
- className = '',
308
142
  toastOptions = {},
143
+ reverseOrder = false,
144
+ gutter = 8,
145
+ containerStyle,
146
+ containerClassName,
147
+ className = '',
148
+ theme = {},
309
149
  richColors = false,
310
150
  customIcons = true,
311
151
  closeButton = true,
312
152
  pauseOnHover = true,
313
- reverseOrder = false,
314
153
  visibleToasts = 3,
315
154
  expand = false,
316
155
  gap = 8,
317
- offset = '32px'
156
+ offset = '32px',
157
+ fireWithSound = false
318
158
  }: ToasterProps = $props();
319
159
 
320
160
  $effect(() => {
321
- updateToastConfig({ duration, theme, richColors });
161
+ // theme/richColors/customIcons are intentionally ignored in wrapper mode.
162
+ void theme;
163
+ void richColors;
164
+ void customIcons;
165
+ updateToastConfig({ duration, fireWithSound });
322
166
  });
323
167
  </script>
324
168
 
325
169
  <Toaster
326
170
  {position}
327
- {duration}
328
- {className}
329
171
  {toastOptions}
330
- {closeButton}
331
- {pauseOnHover}
332
172
  {reverseOrder}
333
- {visibleToasts}
334
- {expand}
335
- {gap}
336
- {offset}
173
+ {gutter}
174
+ {containerStyle}
175
+ containerClassName={containerClassName || className}
337
176
  />
@@ -1,75 +1,50 @@
1
- export type ToastType = 'success' | 'error' | 'warning' | 'info' | 'loading' | 'custom';
2
- export type ToastPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
3
- export interface CustomToastOptions extends ToastOptions {
4
- icon?: string;
5
- showProgress?: boolean;
6
- progressColor?: string;
7
- borderColor?: string;
8
- backgroundColor?: string;
9
- textColor?: string;
10
- iconColor?: string;
11
- style?: any;
12
- action?: {
13
- label: string | boolean;
14
- onClick: () => void;
15
- buttonStyle?: string;
16
- };
17
- }
18
- export interface ToastTheme {
19
- success?: Partial<CustomToastOptions>;
20
- error?: Partial<CustomToastOptions>;
21
- warning?: Partial<CustomToastOptions>;
22
- info?: Partial<CustomToastOptions>;
23
- loading?: Partial<CustomToastOptions>;
24
- custom?: Partial<CustomToastOptions>;
25
- }
1
+ import { toast as originalToast, type DefaultToastOptions, type Renderable, resolveValue, type ToastOptions, type ToastPosition, type ValueOrFunction } from 'svelte-french-toast';
2
+ export { CheckmarkIcon, ErrorIcon, LoaderIcon, ToastBar, ToastIcon, useToaster, useToasterStore } from 'svelte-french-toast';
3
+ export { resolveValue };
4
+ export type { DefaultToastOptions, IconTheme, Toast, ToastOptions, ToastPosition, ToastType, Renderable, ValueFunction, ValueOrFunction } from 'svelte-french-toast';
5
+ export type CustomToastOptions = ToastOptions;
6
+ export type ToastTheme = Record<string, never>;
26
7
  export interface ToasterProps {
27
8
  position?: ToastPosition;
28
9
  duration?: number;
29
- theme?: ToastTheme;
10
+ toastOptions?: DefaultToastOptions;
11
+ reverseOrder?: boolean;
12
+ gutter?: number;
13
+ containerStyle?: string;
14
+ containerClassName?: string;
15
+ fireWithSound?: boolean;
30
16
  className?: string;
31
- toastOptions?: ToastOptions;
17
+ theme?: ToastTheme;
32
18
  richColors?: boolean;
33
19
  customIcons?: boolean;
34
20
  closeButton?: boolean;
35
21
  pauseOnHover?: boolean;
36
- reverseOrder?: boolean;
37
22
  visibleToasts?: number;
38
23
  expand?: boolean;
39
24
  gap?: number;
40
25
  offset?: number | string;
41
26
  }
42
- export declare const toast: {
43
- success: (message: string, options?: CustomToastOptions) => string;
44
- error: (message: string, options?: CustomToastOptions) => string;
45
- warning: (message: string, options?: CustomToastOptions) => string;
46
- info: (message: string, options?: CustomToastOptions) => string;
47
- loading: (message: string, options?: CustomToastOptions) => string;
48
- promise: <T>(promise: Promise<T>, messages: {
49
- loading: string;
50
- success: string;
51
- error: string;
52
- }, options?: {
53
- loading?: CustomToastOptions;
54
- success?: CustomToastOptions;
55
- error?: CustomToastOptions;
56
- }) => Promise<T>;
57
- custom: (message: string, type?: ToastType, options?: CustomToastOptions) => string;
58
- action: (message: string, action: {
59
- label: string;
60
- onClick: () => void;
61
- }, options?: CustomToastOptions) => string;
62
- dismiss: (toastId?: string) => void;
63
- remove: (toastId?: string) => void;
64
- };
65
27
  export declare function updateToastConfig(config: {
66
28
  duration?: number;
29
+ fireWithSound?: boolean;
67
30
  theme?: ToastTheme;
68
31
  richColors?: boolean;
69
32
  }): void;
33
+ export declare const toast: ((message: Renderable, options?: ToastOptions) => string) & {
34
+ success: (message: Renderable, options?: ToastOptions) => string;
35
+ error: (message: Renderable, options?: ToastOptions) => string;
36
+ loading: (message: Renderable, options?: ToastOptions) => string;
37
+ promise: <T>(promise: Promise<T>, msgs: {
38
+ loading: Renderable;
39
+ success: ValueOrFunction<Renderable, T>;
40
+ error: ValueOrFunction<Renderable, any>;
41
+ }, opts?: DefaultToastOptions) => Promise<T>;
42
+ dismiss: (toastId?: string) => void;
43
+ remove: (toastId?: string) => void;
44
+ custom: (message: Renderable, options?: ToastOptions) => string;
45
+ };
70
46
  export { originalToast };
71
47
  export type { ToastOptions };
72
- import { toast as originalToast, type ToastOptions } from 'svelte-french-toast';
73
48
  declare const Toast: import("svelte").Component<ToasterProps, {}, "">;
74
49
  type Toast = ReturnType<typeof Toast>;
75
50
  export default Toast;
@@ -1 +1,2 @@
1
- export * from 'svelte-french-toast';
1
+ export { default as Toaster, toast, originalToast, updateToastConfig } from './Toast.svelte';
2
+ export type { ToasterProps, ToastType, CustomToastOptions, ToastTheme, ToastOptions } from './Toast.svelte';
@@ -1,3 +1 @@
1
- // export { default as Toaster, toast } from './Toast.svelte';
2
- // export type { ToasterProps, ToastType, CustomToastOptions, ToastTheme } from './Toast.svelte';
3
- export * from 'svelte-french-toast';
1
+ export { default as Toaster, toast, originalToast, updateToastConfig } from './Toast.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rkosafo/cai.components",
3
- "version": "0.0.79",
3
+ "version": "0.0.81",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",
@@ -1 +0,0 @@
1
- export { default as FormSelect } from './FormSelect.svelte';
@@ -1 +0,0 @@
1
- export { default as FormSelect } from './FormSelect.svelte';
@@ -1,4 +0,0 @@
1
- import type { SizeType } from '../../index.js';
2
- export { default as Input } from './Input.svelte';
3
- export { input } from './theme.js';
4
- export declare function clampSize(s: SizeType): "md" | "sm" | "lg";
@@ -1,5 +0,0 @@
1
- export { default as Input } from './Input.svelte';
2
- export { input } from './theme.js';
3
- export function clampSize(s) {
4
- return s && s === 'xs' ? 'sm' : s === 'xl' ? 'lg' : s;
5
- }