sileo-sveltekit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present Cairo Studio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,490 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/shehabwaleedd/sileo-sveltekit/main/.github/logo.svg" alt="sileo-sveltekit" width="120" />
3
+ </p>
4
+
5
+ <h1 align="center">sileo-sveltekit</h1>
6
+
7
+ <p align="center">
8
+ <strong>A physics-based toast notification library for SvelteKit</strong>
9
+ </p>
10
+
11
+ <p align="center">
12
+ Beautiful, animated toast notifications with spring physics, SVG morphing, and a delightful user experience.
13
+ </p>
14
+
15
+ <p align="center">
16
+ <a href="https://www.npmjs.com/package/sileo-sveltekit">
17
+ <img src="https://img.shields.io/npm/v/sileo-sveltekit?style=flat-square&color=ff4b26" alt="npm version" />
18
+ </a>
19
+ <a href="https://www.npmjs.com/package/sileo-sveltekit">
20
+ <img src="https://img.shields.io/npm/dm/sileo-sveltekit?style=flat-square&color=ff4b26" alt="npm downloads" />
21
+ </a>
22
+ <a href="https://github.com/shehabwaleedd/sileo-sveltekit/blob/main/LICENSE">
23
+ <img src="https://img.shields.io/npm/l/sileo-sveltekit?style=flat-square&color=ff4b26" alt="license" />
24
+ </a>
25
+ <a href="https://kit.svelte.dev">
26
+ <img src="https://img.shields.io/badge/SvelteKit-5.0+-ff4b26?style=flat-square" alt="SvelteKit 5+" />
27
+ </a>
28
+ </p>
29
+
30
+ <p align="center">
31
+ <a href="#installation">Installation</a> •
32
+ <a href="#quick-start">Quick Start</a> •
33
+ <a href="#api-reference">API</a> •
34
+ <a href="#customization">Customization</a> •
35
+ <a href="#examples">Examples</a>
36
+ </p>
37
+
38
+ ---
39
+
40
+ ## ✨ Features
41
+
42
+ - **🎯 Physics-Based Animations** — Smooth spring animations powered by Svelte's motion stores
43
+ - **🫧 SVG Gooey Morphing** — Organic blob-like shape transitions using SVG filters
44
+ - **📍 6 Positions** — Place toasts anywhere: top/bottom + left/center/right
45
+ - **🎨 5 States** — Success, error, warning, info, and action states (plus loading)
46
+ - **🔄 Auto Expand/Collapse** — Toasts expand on hover to reveal descriptions
47
+ - **👆 Swipe to Dismiss** — Touch-friendly gesture support
48
+ - **📚 Stacking Animations** — New toasts push existing ones naturally
49
+ - **♿ Accessible** — ARIA live regions for screen readers
50
+ - **🎛️ Fully Customizable** — CSS variables for complete control
51
+ - **📦 Tiny Bundle** — No external dependencies beyond Svelte
52
+ - **💪 TypeScript** — Full type safety out of the box
53
+
54
+ ---
55
+
56
+ ## 📦 Installation
57
+
58
+ ```bash
59
+ # npm
60
+ npm install sileo-sveltekit
61
+
62
+ # pnpm
63
+ pnpm add sileo-sveltekit
64
+
65
+ # yarn
66
+ yarn add sileo-sveltekit
67
+
68
+ # bun
69
+ bun add sileo-sveltekit
70
+ ```
71
+
72
+ ### Requirements
73
+
74
+ - **Svelte 5.0+**
75
+ - **SvelteKit 2.0+**
76
+
77
+ ---
78
+
79
+ ## 🚀 Quick Start
80
+
81
+ ### 1. Add the Toaster to your layout
82
+
83
+ Add the `Toaster` component to your root layout. This renders the toast container and sets up the global toast API.
84
+
85
+ ```svelte
86
+ <!-- src/routes/+layout.svelte -->
87
+ <script>
88
+ import { Toaster } from 'sileo-sveltekit';
89
+ </script>
90
+
91
+ <Toaster />
92
+
93
+ <slot />
94
+ ```
95
+
96
+ ### 2. Show toasts from anywhere
97
+
98
+ Use the global `window.toast` API to show notifications from any component:
99
+
100
+ ```svelte
101
+ <script>
102
+ function handleClick() {
103
+ window.toast.success('Saved!', 'Your changes have been saved successfully.');
104
+ }
105
+ </script>
106
+
107
+ <button on:click={handleClick}>
108
+ Save Changes
109
+ </button>
110
+ ```
111
+
112
+ That's it! You're ready to show beautiful toast notifications.
113
+
114
+ ---
115
+
116
+ ## 📖 API Reference
117
+
118
+ ### Toaster Component
119
+
120
+ The main component that renders the toast container.
121
+
122
+ ```svelte
123
+ <Toaster position="bottom-right" />
124
+ ```
125
+
126
+ #### Props
127
+
128
+ | Prop | Type | Default | Description |
129
+ |------|------|---------|-------------|
130
+ | `position` | `SileoPosition` | `'bottom-right'` | Default position for all toasts |
131
+
132
+ #### Position Options
133
+
134
+ | Value | Description |
135
+ |-------|-------------|
136
+ | `'top-left'` | Top left corner |
137
+ | `'top-center'` | Top center |
138
+ | `'top-right'` | Top right corner |
139
+ | `'bottom-left'` | Bottom left corner |
140
+ | `'bottom-center'` | Bottom center |
141
+ | `'bottom-right'` | Bottom right corner |
142
+
143
+ ---
144
+
145
+ ### Toast API
146
+
147
+ The toast API is available globally via `window.toast`.
148
+
149
+ #### Quick Methods
150
+
151
+ ```typescript
152
+ // Success toast
153
+ window.toast.success(title: string, description?: string, duration?: number): string
154
+
155
+ // Error toast
156
+ window.toast.error(title: string, description?: string, duration?: number): string
157
+
158
+ // Warning toast
159
+ window.toast.warning(title: string, description?: string, duration?: number): string
160
+
161
+ // Info toast
162
+ window.toast.info(title: string, description?: string, duration?: number): string
163
+
164
+ // Action toast
165
+ window.toast.action(title: string, description?: string, duration?: number): string
166
+ ```
167
+
168
+ **Returns:** Toast ID (string) — useful for programmatic dismissal
169
+
170
+ #### Show with Options
171
+
172
+ For full control, use `toast.show()` with an options object:
173
+
174
+ ```typescript
175
+ window.toast.show({
176
+ title: 'Custom Toast',
177
+ description: 'With all the options',
178
+ position: 'top-center',
179
+ duration: 5000,
180
+ fill: '#1a1a1a',
181
+ roundness: 20,
182
+ autopilot: true
183
+ }): string
184
+ ```
185
+
186
+ #### Options Object
187
+
188
+ | Property | Type | Default | Description |
189
+ |----------|------|---------|-------------|
190
+ | `title` | `string` | — | Toast title (required) |
191
+ | `description` | `string` | — | Optional description text |
192
+ | `position` | `SileoPosition` | Toaster default | Override position for this toast |
193
+ | `duration` | `number \| null` | `6000` | Auto-dismiss delay in ms. Use `null` for persistent |
194
+ | `fill` | `string` | `'#fff'` | Background color (CSS color value) |
195
+ | `roundness` | `number` | `16` | Border radius in pixels |
196
+ | `autopilot` | `boolean \| object` | `true` | Auto expand/collapse behavior |
197
+
198
+ #### Autopilot Options
199
+
200
+ Control automatic expand/collapse timing:
201
+
202
+ ```typescript
203
+ window.toast.show({
204
+ title: 'Custom timing',
205
+ description: 'This toast has custom autopilot',
206
+ autopilot: {
207
+ expand: 500, // Expand after 500ms
208
+ collapse: 3000 // Collapse after 3000ms
209
+ }
210
+ })
211
+ ```
212
+
213
+ Set `autopilot: false` to disable auto expand/collapse entirely.
214
+
215
+ #### Dismiss Methods
216
+
217
+ ```typescript
218
+ // Dismiss a specific toast by ID
219
+ window.toast.dismiss(id: string): void
220
+
221
+ // Clear all toasts
222
+ window.toast.clear(): void
223
+
224
+ // Clear toasts at a specific position
225
+ window.toast.clear('top-right'): void
226
+ ```
227
+
228
+ ---
229
+
230
+ ## 🎨 Customization
231
+
232
+ ### CSS Variables
233
+
234
+ Customize the appearance by overriding CSS variables in your global styles:
235
+
236
+ ```css
237
+ :root {
238
+ /* Dimensions */
239
+ --sileo-height: 40px;
240
+ --sileo-width: 350px;
241
+
242
+ /* Animation */
243
+ --sileo-duration: 600ms;
244
+
245
+ /* Default colors */
246
+ --sileo-fill: #ffffff;
247
+ --sileo-text: currentColor;
248
+
249
+ /* State colors (using oklch for vibrant colors) */
250
+ --sileo-state-success: oklch(0.723 0.219 142.136);
251
+ --sileo-state-error: oklch(0.637 0.237 25.331);
252
+ --sileo-state-warning: oklch(0.795 0.184 86.047);
253
+ --sileo-state-info: oklch(0.685 0.169 237.323);
254
+ --sileo-state-action: oklch(0.623 0.214 259.815);
255
+ --sileo-state-loading: oklch(0.556 0 0);
256
+ }
257
+ ```
258
+
259
+ ### Dark Mode
260
+
261
+ Sileo automatically adapts to your color scheme. Override the fill color for dark mode:
262
+
263
+ ```css
264
+ :root.dark {
265
+ --sileo-fill: #1a1a1a;
266
+ --sileo-text: #ffffff;
267
+ }
268
+ ```
269
+
270
+ Or set the fill per-toast:
271
+
272
+ ```typescript
273
+ window.toast.success('Dark toast', 'With custom background', {
274
+ fill: '#1a1a1a'
275
+ })
276
+ ```
277
+
278
+ ### Custom State Colors
279
+
280
+ Change the colors for each toast state:
281
+
282
+ ```css
283
+ :root {
284
+ /* Use your brand colors */
285
+ --sileo-state-success: #10b981;
286
+ --sileo-state-error: #ef4444;
287
+ --sileo-state-warning: #f59e0b;
288
+ --sileo-state-info: #3b82f6;
289
+ --sileo-state-action: #8b5cf6;
290
+ }
291
+ ```
292
+
293
+ ---
294
+
295
+ ## 💡 Examples
296
+
297
+ ### Basic Usage
298
+
299
+ ```svelte
300
+ <script>
301
+ function showToasts() {
302
+ window.toast.success('Success!', 'Operation completed');
303
+ window.toast.error('Error!', 'Something went wrong');
304
+ window.toast.warning('Warning!', 'Please check this');
305
+ window.toast.info('Info', 'Here is some information');
306
+ }
307
+ </script>
308
+
309
+ <button on:click={showToasts}>Show All Types</button>
310
+ ```
311
+
312
+ ### Persistent Toast
313
+
314
+ ```svelte
315
+ <script>
316
+ let toastId;
317
+
318
+ function showPersistent() {
319
+ toastId = window.toast.show({
320
+ title: 'Uploading...',
321
+ description: 'Please wait while we upload your file',
322
+ duration: null // Never auto-dismiss
323
+ });
324
+ }
325
+
326
+ function dismiss() {
327
+ window.toast.dismiss(toastId);
328
+ }
329
+ </script>
330
+
331
+ <button on:click={showPersistent}>Start Upload</button>
332
+ <button on:click={dismiss}>Cancel</button>
333
+ ```
334
+
335
+ ### Promise Pattern
336
+
337
+ ```svelte
338
+ <script>
339
+ async function saveData() {
340
+ const id = window.toast.show({
341
+ title: 'Saving...',
342
+ description: 'Please wait',
343
+ duration: null
344
+ });
345
+
346
+ try {
347
+ await fetch('/api/save', { method: 'POST' });
348
+ window.toast.dismiss(id);
349
+ window.toast.success('Saved!', 'Your data has been saved');
350
+ } catch (error) {
351
+ window.toast.dismiss(id);
352
+ window.toast.error('Failed', 'Could not save your data');
353
+ }
354
+ }
355
+ </script>
356
+ ```
357
+
358
+ ### Different Positions
359
+
360
+ ```svelte
361
+ <script>
362
+ function topLeft() {
363
+ window.toast.show({
364
+ title: 'Top Left',
365
+ position: 'top-left'
366
+ });
367
+ }
368
+
369
+ function bottomCenter() {
370
+ window.toast.show({
371
+ title: 'Bottom Center',
372
+ position: 'bottom-center'
373
+ });
374
+ }
375
+ </script>
376
+
377
+ <button on:click={topLeft}>Top Left</button>
378
+ <button on:click={bottomCenter}>Bottom Center</button>
379
+ ```
380
+
381
+ ### Custom Styling
382
+
383
+ ```svelte
384
+ <script>
385
+ function customToast() {
386
+ window.toast.show({
387
+ title: 'Custom Toast',
388
+ description: 'With brand colors and rounded corners',
389
+ fill: '#ff4b26',
390
+ roundness: 24
391
+ });
392
+ }
393
+ </script>
394
+ ```
395
+
396
+ ---
397
+
398
+ ## 📘 TypeScript
399
+
400
+ Full TypeScript support with exported types:
401
+
402
+ ```typescript
403
+ import type {
404
+ SileoState, // 'success' | 'error' | 'warning' | 'info' | 'action' | 'loading'
405
+ SileoPosition, // 'top-left' | 'top-center' | ... | 'bottom-right'
406
+ SileoOptions, // Options for toast.show()
407
+ SileoToastAPI // Type for window.toast
408
+ } from 'sileo-sveltekit';
409
+ ```
410
+
411
+ ### Type-Safe Global Toast
412
+
413
+ Add type safety to `window.toast`:
414
+
415
+ ```typescript
416
+ // src/app.d.ts
417
+ import type { SileoToastAPI } from 'sileo-sveltekit';
418
+
419
+ declare global {
420
+ interface Window {
421
+ toast: SileoToastAPI;
422
+ }
423
+ }
424
+
425
+ export {};
426
+ ```
427
+
428
+ ---
429
+
430
+ ## 🔧 Advanced Configuration
431
+
432
+ ### Multiple Toaster Instances
433
+
434
+ While one Toaster handles all positions, you can customize behavior:
435
+
436
+ ```svelte
437
+ <script>
438
+ import { Toaster } from 'sileo-sveltekit';
439
+ </script>
440
+
441
+ <!-- Primary toaster for most notifications -->
442
+ <Toaster position="bottom-right" />
443
+ ```
444
+
445
+ ### Disable Autopilot
446
+
447
+ Prevent toasts from auto-expanding:
448
+
449
+ ```typescript
450
+ window.toast.show({
451
+ title: 'Manual Only',
452
+ description: 'This only expands on hover',
453
+ autopilot: false
454
+ });
455
+ ```
456
+
457
+ ### Reduced Motion
458
+
459
+ Sileo respects `prefers-reduced-motion`. When enabled, animations are minimized for accessibility.
460
+
461
+ ---
462
+
463
+ ## 🤝 Contributing
464
+
465
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
466
+
467
+ 1. Fork the repository
468
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
469
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
470
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
471
+ 5. Open a Pull Request
472
+
473
+ ---
474
+
475
+ ## 📄 License
476
+
477
+ MIT License - see the [LICENSE](LICENSE) file for details.
478
+
479
+ ---
480
+
481
+ ## 🙏 Credits
482
+
483
+ - Original [sileo](https://github.com/hiaaryan/sileo) by [@hiaaryan](https://github.com/hiaaryan)
484
+ - SvelteKit port by [Cairo Studio](https://cairostudio.com)
485
+
486
+ ---
487
+
488
+ <p align="center">
489
+ Made with ❤️ for the Svelte community
490
+ </p>