varsel 0.1.1 → 0.2.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 (48) hide show
  1. package/dist/VarselItem.svelte +228 -229
  2. package/dist/VarselItem.svelte.d.ts +19 -23
  3. package/dist/VarselItem.svelte.d.ts.map +1 -1
  4. package/dist/VarselManager.svelte +58 -37
  5. package/dist/VarselManager.svelte.d.ts +7 -18
  6. package/dist/VarselManager.svelte.d.ts.map +1 -1
  7. package/dist/VarselToaster.svelte +22 -5
  8. package/dist/VarselToaster.svelte.d.ts +12 -19
  9. package/dist/VarselToaster.svelte.d.ts.map +1 -1
  10. package/dist/core/accessibility.d.ts +4 -0
  11. package/dist/core/accessibility.d.ts.map +1 -1
  12. package/dist/core/accessibility.js +4 -0
  13. package/dist/core/animations.d.ts +15 -0
  14. package/dist/core/animations.d.ts.map +1 -1
  15. package/dist/core/animations.js +15 -0
  16. package/dist/core/positions.d.ts +7 -0
  17. package/dist/core/positions.d.ts.map +1 -1
  18. package/dist/core/positions.js +4 -0
  19. package/dist/core/swipe.d.ts +12 -0
  20. package/dist/core/swipe.d.ts.map +1 -1
  21. package/dist/core/swipe.js +10 -0
  22. package/dist/core/toast-factory.d.ts.map +1 -1
  23. package/dist/core/toast-factory.js +38 -0
  24. package/dist/core/toast-state.d.ts +32 -0
  25. package/dist/core/toast-state.d.ts.map +1 -1
  26. package/dist/core/toast-state.js +33 -0
  27. package/dist/core/toaster-instances.d.ts +17 -0
  28. package/dist/core/toaster-instances.d.ts.map +1 -1
  29. package/dist/core/toaster-instances.js +17 -0
  30. package/dist/core/types.d.ts +70 -0
  31. package/dist/core/types.d.ts.map +1 -1
  32. package/dist/core/utils.d.ts +8 -0
  33. package/dist/core/utils.d.ts.map +1 -1
  34. package/dist/core/utils.js +8 -0
  35. package/dist/core/variants.d.ts +10 -0
  36. package/dist/core/variants.d.ts.map +1 -1
  37. package/dist/core/variants.js +16 -0
  38. package/dist/index.d.ts +6 -0
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +6 -0
  41. package/dist/internals.d.ts +5 -0
  42. package/dist/internals.d.ts.map +1 -1
  43. package/dist/internals.js +5 -0
  44. package/dist/styles.css +1 -765
  45. package/dist/variant-icons.d.ts +9 -0
  46. package/dist/variant-icons.d.ts.map +1 -1
  47. package/dist/variant-icons.js +5 -0
  48. package/package.json +10 -4
@@ -1,5 +1,11 @@
1
1
  <script lang="ts">
2
- import { onMount } from "svelte";
2
+ /**
3
+ * @component
4
+ * @description
5
+ * Internal component responsible for grouping toasts by position and calculating
6
+ * their stacking offsets (both collapsed and expanded).
7
+ * It handles the "hover to expand" logic and manages the lifecycle of toast groups.
8
+ */
3
9
  import VarselItem from "./VarselItem.svelte";
4
10
  import {
5
11
  ANIMATION_CONFIG,
@@ -8,9 +14,18 @@ import {
8
14
  type ToastPosition,
9
15
  } from "./internals";
10
16
 
11
- export let toasts: ToastData[] = [];
12
- export let onRemove: (id: string) => void;
13
- export let expandedGap: number = ANIMATION_CONFIG.EXPANDED_GAP;
17
+ let {
18
+ toasts = [],
19
+ onRemove,
20
+ expandedGap = ANIMATION_CONFIG.EXPANDED_GAP,
21
+ }: {
22
+ /** The list of all active toasts from the global state. */
23
+ toasts?: ToastData[];
24
+ /** Callback to remove a toast from the state. */
25
+ onRemove: (id: string) => void;
26
+ /** The gap in pixels between toasts when expanded. */
27
+ expandedGap?: number;
28
+ } = $props();
14
29
 
15
30
  const createPositionMap = <T>(value: () => T): Record<ToastPosition, T> => ({
16
31
  "top-left": value(),
@@ -21,31 +36,38 @@ const createPositionMap = <T>(value: () => T): Record<ToastPosition, T> => ({
21
36
  "bottom-right": value(),
22
37
  });
23
38
 
24
- let heights: Record<string, number> = {};
25
- let hovered: Record<ToastPosition, boolean> = createPositionMap(() => false);
26
- let heldToasts: Record<ToastPosition, Set<string>> = createPositionMap(
27
- () => new Set<string>(),
39
+ let heights = $state<Record<string, number>>({});
40
+ let hovered = $state<Record<ToastPosition, boolean>>(
41
+ createPositionMap(() => false),
28
42
  );
43
+ let heldToasts = $state<Record<ToastPosition, Set<string>>>(
44
+ createPositionMap(() => new Set<string>()),
45
+ );
46
+
47
+ // Non-reactive internal state for "previous" values (mimicking legacy behavior)
29
48
  let previousStackIndex: Record<string, number> = {};
30
49
  let previousCollapsedOffsets: Record<string, number> = {};
31
50
  let previousExpandedOffsets: Record<string, number> = {};
32
- let toastsByPosition: Record<ToastPosition, PositionedToast[]> =
33
- createPositionMap<PositionedToast[]>(() => []);
34
- let positionEntries: [ToastPosition, PositionedToast[]][] = [];
35
- let collapsedOffsetData: {
51
+
52
+ let toastsByPosition = $state<Record<ToastPosition, PositionedToast[]>>(
53
+ createPositionMap<PositionedToast[]>(() => []),
54
+ );
55
+
56
+ let collapsedOffsetData = $state<{
36
57
  byPosition: Record<ToastPosition, number[]>;
37
58
  byId: Record<string, number>;
38
- } = { byPosition: createPositionMap<number[]>(() => []), byId: {} };
39
- let expandedOffsetData: {
59
+ }>({ byPosition: createPositionMap<number[]>(() => []), byId: {} });
60
+
61
+ let expandedOffsetData = $state<{
40
62
  byPosition: Record<ToastPosition, number[]>;
41
63
  byId: Record<string, number>;
42
- } = { byPosition: createPositionMap<number[]>(() => []), byId: {} };
43
-
44
- let latestPositionEntries: [ToastPosition, PositionedToast[]][] = [];
45
- let latestHovered: Record<ToastPosition, boolean> = hovered;
64
+ }>({ byPosition: createPositionMap<number[]>(() => []), byId: {} });
46
65
 
47
- $: latestPositionEntries = positionEntries;
48
- $: latestHovered = hovered;
66
+ let positionEntries = $derived(
67
+ Object.entries(toastsByPosition) as [ToastPosition, PositionedToast[]][],
68
+ );
69
+ let latestPositionEntries = $derived(positionEntries);
70
+ let latestHovered = $derived(hovered);
49
71
 
50
72
  const updateHoldState = (
51
73
  position: ToastPosition,
@@ -64,7 +86,8 @@ const updateHoldState = (
64
86
  }
65
87
  };
66
88
 
67
- $: {
89
+ // Calculate toastsByPosition based on toasts
90
+ $effect(() => {
68
91
  const grouped = createPositionMap<ToastData[]>(() => []);
69
92
  for (const toast of toasts) {
70
93
  const pos = toast.position || "bottom-center";
@@ -104,9 +127,10 @@ $: {
104
127
 
105
128
  previousStackIndex = nextStackIndices;
106
129
  toastsByPosition = positioned;
107
- }
130
+ });
108
131
 
109
- $: {
132
+ // Update hovered state based on empty groups
133
+ $effect(() => {
110
134
  const next = { ...hovered };
111
135
  let changed = false;
112
136
  for (const pos of Object.keys(hovered) as ToastPosition[]) {
@@ -119,14 +143,10 @@ $: {
119
143
  if (changed) {
120
144
  hovered = next;
121
145
  }
122
- }
123
-
124
- $: positionEntries = Object.entries(toastsByPosition) as [
125
- ToastPosition,
126
- PositionedToast[],
127
- ][];
146
+ });
128
147
 
129
- $: collapsedOffsetData = (() => {
148
+ // Calculate collapsedOffsetData
149
+ $effect(() => {
130
150
  const byPosition = createPositionMap<number[]>(() => []);
131
151
  const byId: Record<string, number> = {};
132
152
 
@@ -200,10 +220,11 @@ $: collapsedOffsetData = (() => {
200
220
  }
201
221
 
202
222
  previousCollapsedOffsets = byId;
203
- return { byPosition, byId };
204
- })();
223
+ collapsedOffsetData = { byPosition, byId };
224
+ });
205
225
 
206
- $: expandedOffsetData = (() => {
226
+ // Calculate expandedOffsetData
227
+ $effect(() => {
207
228
  const byPosition = createPositionMap<number[]>(() => []);
208
229
  const byId: Record<string, number> = {};
209
230
 
@@ -251,10 +272,10 @@ $: expandedOffsetData = (() => {
251
272
  }
252
273
 
253
274
  previousExpandedOffsets = byId;
254
- return { byPosition, byId };
255
- })();
275
+ expandedOffsetData = { byPosition, byId };
276
+ });
256
277
 
257
- onMount(() => {
278
+ $effect(() => {
258
279
  const handleMouseMove = (event: MouseEvent) => {
259
280
  if (latestPositionEntries.length === 0) return;
260
281
  const { clientX: x, clientY: y } = event;
@@ -384,4 +405,4 @@ const handleHeightChange = (id: string, height: number) => {
384
405
  {/each}
385
406
  {/each}
386
407
  </div>
387
- {/if}
408
+ {/if}
@@ -1,24 +1,13 @@
1
1
  import { type ToastData } from "./internals";
2
- interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
3
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
4
- $$bindings?: Bindings;
5
- } & Exports;
6
- (internal: unknown, props: Props & {
7
- $$events?: Events;
8
- $$slots?: Slots;
9
- }): Exports & {
10
- $set?: any;
11
- $on?: any;
12
- };
13
- z_$$bindings?: Bindings;
14
- }
15
- declare const VarselManager: $$__sveltets_2_IsomorphicComponent<{
2
+ type $$ComponentProps = {
3
+ /** The list of all active toasts from the global state. */
16
4
  toasts?: ToastData[];
5
+ /** Callback to remove a toast from the state. */
17
6
  onRemove: (id: string) => void;
7
+ /** The gap in pixels between toasts when expanded. */
18
8
  expandedGap?: number;
19
- }, {
20
- [evt: string]: CustomEvent<any>;
21
- }, {}, {}, string>;
22
- type VarselManager = InstanceType<typeof VarselManager>;
9
+ };
10
+ declare const VarselManager: import("svelte").Component<$$ComponentProps, {}, "">;
11
+ type VarselManager = ReturnType<typeof VarselManager>;
23
12
  export default VarselManager;
24
13
  //# sourceMappingURL=VarselManager.svelte.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"VarselManager.svelte.d.ts","sourceRoot":"","sources":["../src/lib/VarselManager.svelte.ts"],"names":[],"mappings":"AAKA,OAAO,EAGN,KAAK,SAAS,EAEd,MAAM,aAAa,CAAC;AAwXrB,UAAU,kCAAkC,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,OAAO,GAAG,EAAE,EAAE,QAAQ,GAAG,MAAM;IACpM,KAAK,OAAO,EAAE,OAAO,QAAQ,EAAE,2BAA2B,CAAC,KAAK,CAAC,GAAG,OAAO,QAAQ,EAAE,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,QAAQ,CAAA;KAAE,GAAG,OAAO,CAAC;IACjK,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,GAAG;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,KAAK,CAAA;KAAC,GAAG,OAAO,GAAG;QAAE,IAAI,CAAC,EAAE,GAAG,CAAC;QAAC,GAAG,CAAC,EAAE,GAAG,CAAA;KAAE,CAAC;IAC9G,YAAY,CAAC,EAAE,QAAQ,CAAC;CAC3B;AAKD,QAAA,MAAM,aAAa;aAV2E,SAAS,EAAE;cAAY,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI;kBAAgB,MAAM;;;kBAU7D,CAAC;AACjF,KAAK,aAAa,GAAG,YAAY,CAAC,OAAO,aAAa,CAAC,CAAC;AAC1D,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"VarselManager.svelte.d.ts","sourceRoot":"","sources":["../src/lib/VarselManager.svelte.ts"],"names":[],"mappings":"AAWA,OAAO,EAGN,KAAK,SAAS,EAEd,MAAM,aAAa,CAAC;AAEpB,KAAK,gBAAgB,GAAI;IACzB,2DAA2D;IAC3D,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC;IACrB,iDAAiD;IACjD,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,sDAAsD;IACtD,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AA8XF,QAAA,MAAM,aAAa,sDAAwC,CAAC;AAC5D,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACtD,eAAe,aAAa,CAAC"}
@@ -1,4 +1,7 @@
1
- <script lang="ts" context="module">
1
+ <script lang="ts" module>
2
+ /**
3
+ * Main module exports for the Varsel library.
4
+ */
2
5
  export {
3
6
  toast,
4
7
  type ToastData,
@@ -8,7 +11,15 @@ export {
8
11
  </script>
9
12
 
10
13
  <script lang="ts">
11
- import { onMount } from 'svelte';
14
+ /**
15
+ * @component
16
+ * @description
17
+ * The root component for the Varsel notification system.
18
+ * It subscribes to the global toast state and renders the `VarselManager`
19
+ * which handles the positioning and layout of individual toasts.
20
+ *
21
+ * Place this component once in your application's root layout (e.g., `+layout.svelte`).
22
+ */
12
23
  import VarselManager from './VarselManager.svelte';
13
24
  import {
14
25
  toastState,
@@ -16,16 +27,22 @@ export {
16
27
  type ToastData,
17
28
  } from './internals';
18
29
 
19
- export let expandedGap: number | undefined = undefined;
30
+ let { expandedGap = undefined }: {
31
+ /**
32
+ * The gap (in pixels) between expanded toasts when hovering over the stack.
33
+ * If undefined, uses the default value from animation config.
34
+ */
35
+ expandedGap?: number
36
+ } = $props();
20
37
 
21
- let toasts: ToastData[] = [];
38
+ let toasts = $state<ToastData[]>([]);
22
39
  const instanceId = toasterInstanceManager.registerInstance();
23
40
 
24
41
  const handleRemove = (id: string) => {
25
42
  toastState.remove(id);
26
43
  };
27
44
 
28
- onMount(() => {
45
+ $effect(() => {
29
46
  toasts = toastState.getToasts();
30
47
  const unsubscribe = toastState.subscribe((value) => {
31
48
  toasts = value;
@@ -1,22 +1,15 @@
1
+ /**
2
+ * Main module exports for the Varsel library.
3
+ */
1
4
  export { toast, type ToastData, type ToastInvoker, type ToastPosition, } from "./internals";
2
- interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
3
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
4
- $$bindings?: Bindings;
5
- } & Exports;
6
- (internal: unknown, props: Props & {
7
- $$events?: Events;
8
- $$slots?: Slots;
9
- }): Exports & {
10
- $set?: any;
11
- $on?: any;
12
- };
13
- z_$$bindings?: Bindings;
14
- }
15
- declare const VarselToaster: $$__sveltets_2_IsomorphicComponent<{
16
- expandedGap?: number | undefined;
17
- }, {
18
- [evt: string]: CustomEvent<any>;
19
- }, {}, {}, string>;
20
- type VarselToaster = InstanceType<typeof VarselToaster>;
5
+ type $$ComponentProps = {
6
+ /**
7
+ * The gap (in pixels) between expanded toasts when hovering over the stack.
8
+ * If undefined, uses the default value from animation config.
9
+ */
10
+ expandedGap?: number;
11
+ };
12
+ declare const VarselToaster: import("svelte").Component<$$ComponentProps, {}, "">;
13
+ type VarselToaster = ReturnType<typeof VarselToaster>;
21
14
  export default VarselToaster;
22
15
  //# sourceMappingURL=VarselToaster.svelte.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"VarselToaster.svelte.d.ts","sourceRoot":"","sources":["../src/lib/VarselToaster.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,KAAK,EACL,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,aAAa,GAClB,MAAM,aAAa,CAAC;AAiDrB,UAAU,kCAAkC,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,OAAO,GAAG,EAAE,EAAE,QAAQ,GAAG,MAAM;IACpM,KAAK,OAAO,EAAE,OAAO,QAAQ,EAAE,2BAA2B,CAAC,KAAK,CAAC,GAAG,OAAO,QAAQ,EAAE,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,QAAQ,CAAA;KAAE,GAAG,OAAO,CAAC;IACjK,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,GAAG;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,KAAK,CAAA;KAAC,GAAG,OAAO,GAAG;QAAE,IAAI,CAAC,EAAE,GAAG,CAAC;QAAC,GAAG,CAAC,EAAE,GAAG,CAAA;KAAE,CAAC;IAC9G,YAAY,CAAC,EAAE,QAAQ,CAAC;CAC3B;AAKD,QAAA,MAAM,aAAa;kBAV0C,MAAM,GAAG,SAAS;;;kBAUmB,CAAC;AACjF,KAAK,aAAa,GAAG,YAAY,CAAC,OAAO,aAAa,CAAC,CAAC;AAC1D,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"VarselToaster.svelte.d.ts","sourceRoot":"","sources":["../src/lib/VarselToaster.svelte.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,OAAO,EACN,KAAK,EACL,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,aAAa,GAClB,MAAM,aAAa,CAAC;AAmBpB,KAAK,gBAAgB,GAAI;IACxB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACpB,CAAC;AAuCH,QAAA,MAAM,aAAa,sDAAwC,CAAC;AAC5D,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACtD,eAAe,aAAa,CAAC"}
@@ -1,2 +1,6 @@
1
+ /**
2
+ * CSS selectors used to identify focusable elements within a toast.
3
+ * Used for managing keyboard focus when interacting with toasts containing actions.
4
+ */
1
5
  export declare const FOCUSABLE_SELECTORS: string;
2
6
  //# sourceMappingURL=accessibility.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"accessibility.d.ts","sourceRoot":"","sources":["../../src/lib/core/accessibility.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,QAOpB,CAAC"}
1
+ {"version":3,"file":"accessibility.d.ts","sourceRoot":"","sources":["../../src/lib/core/accessibility.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,mBAAmB,QAOpB,CAAC"}
@@ -1,3 +1,7 @@
1
+ /**
2
+ * CSS selectors used to identify focusable elements within a toast.
3
+ * Used for managing keyboard focus when interacting with toasts containing actions.
4
+ */
1
5
  export const FOCUSABLE_SELECTORS = [
2
6
  "button:not([disabled])",
3
7
  "input:not([disabled])",
@@ -1,14 +1,29 @@
1
+ /**
2
+ * Global configuration constants for toast animations and stacking behavior.
3
+ * These values control timing, spacing, scaling, and easing of toast transitions.
4
+ */
1
5
  export declare const ANIMATION_CONFIG: {
6
+ /** Duration of the entry animation in seconds. */
2
7
  readonly ENTER_DURATION: 0.75;
8
+ /** Duration of the exit animation in seconds. */
3
9
  readonly EXIT_DURATION: 0.75;
10
+ /** Duration of the stack reorganization animation in seconds. */
4
11
  readonly STACK_DURATION: 0.75;
12
+ /** Vertical offset (in pixels) between stacked toasts in collapsed state. */
5
13
  readonly STACK_OFFSET: 16;
14
+ /** Vertical gap (in pixels) between toasts in expanded (hover) state. */
6
15
  readonly EXPANDED_GAP: 12;
16
+ /** Scale reduction factor for each subsequent toast in the stack. */
7
17
  readonly SCALE_FACTOR: 0.04;
18
+ /** Minimum scale value for the furthest toast in the stack. */
8
19
  readonly MIN_SCALE: 0.92;
20
+ /** Maximum number of toasts visible in the stack at once. */
9
21
  readonly MAX_VISIBLE_TOASTS: 3;
22
+ /** Base z-index for the toast layer. */
10
23
  readonly Z_INDEX_BASE: 50;
24
+ /** Default cubic-bezier easing function for animations. */
11
25
  readonly EASING_DEFAULT: "var(--ease-vs-toast)";
26
+ /** Easing function for exit animations. */
12
27
  readonly EASING_EXIT: "var(--ease-vs-toast)";
13
28
  };
14
29
  //# sourceMappingURL=animations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"animations.d.ts","sourceRoot":"","sources":["../../src/lib/core/animations.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;CAYnB,CAAC"}
1
+ {"version":3,"file":"animations.d.ts","sourceRoot":"","sources":["../../src/lib/core/animations.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,gBAAgB;IAC5B,kDAAkD;;IAElD,iDAAiD;;IAEjD,iEAAiE;;IAEjE,6EAA6E;;IAE7E,yEAAyE;;IAEzE,qEAAqE;;IAErE,+DAA+D;;IAE/D,6DAA6D;;IAE7D,wCAAwC;;IAExC,2DAA2D;;IAE3D,2CAA2C;;CAElC,CAAC"}
@@ -1,13 +1,28 @@
1
+ /**
2
+ * Global configuration constants for toast animations and stacking behavior.
3
+ * These values control timing, spacing, scaling, and easing of toast transitions.
4
+ */
1
5
  export const ANIMATION_CONFIG = {
6
+ /** Duration of the entry animation in seconds. */
2
7
  ENTER_DURATION: 0.75,
8
+ /** Duration of the exit animation in seconds. */
3
9
  EXIT_DURATION: 0.75,
10
+ /** Duration of the stack reorganization animation in seconds. */
4
11
  STACK_DURATION: 0.75,
12
+ /** Vertical offset (in pixels) between stacked toasts in collapsed state. */
5
13
  STACK_OFFSET: 16,
14
+ /** Vertical gap (in pixels) between toasts in expanded (hover) state. */
6
15
  EXPANDED_GAP: 12,
16
+ /** Scale reduction factor for each subsequent toast in the stack. */
7
17
  SCALE_FACTOR: 0.04,
18
+ /** Minimum scale value for the furthest toast in the stack. */
8
19
  MIN_SCALE: 0.92,
20
+ /** Maximum number of toasts visible in the stack at once. */
9
21
  MAX_VISIBLE_TOASTS: 3,
22
+ /** Base z-index for the toast layer. */
10
23
  Z_INDEX_BASE: 50,
24
+ /** Default cubic-bezier easing function for animations. */
11
25
  EASING_DEFAULT: "var(--ease-vs-toast)",
26
+ /** Easing function for exit animations. */
12
27
  EASING_EXIT: "var(--ease-vs-toast)",
13
28
  };
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Configuration for initial animation states based on toast position.
3
+ * Defines the starting transform values (x, y) for entering and exiting toasts.
4
+ */
1
5
  export declare const POSITION_CONFIGS: {
2
6
  readonly "top-left": {
3
7
  readonly animateIn: {
@@ -60,5 +64,8 @@ export declare const POSITION_CONFIGS: {
60
64
  };
61
65
  };
62
66
  };
67
+ /**
68
+ * Available positions for the toaster on the screen.
69
+ */
63
70
  export type ToastPosition = "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right";
64
71
  //# sourceMappingURL=positions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"positions.d.ts","sourceRoot":"","sources":["../../src/lib/core/positions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyBnB,CAAC;AAEX,MAAM,MAAM,aAAa,GACtB,UAAU,GACV,YAAY,GACZ,WAAW,GACX,aAAa,GACb,eAAe,GACf,cAAc,CAAC"}
1
+ {"version":3,"file":"positions.d.ts","sourceRoot":"","sources":["../../src/lib/core/positions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyBnB,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,aAAa,GACtB,UAAU,GACV,YAAY,GACZ,WAAW,GACX,aAAa,GACb,eAAe,GACf,cAAc,CAAC"}
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Configuration for initial animation states based on toast position.
3
+ * Defines the starting transform values (x, y) for entering and exiting toasts.
4
+ */
1
5
  export const POSITION_CONFIGS = {
2
6
  "top-left": {
3
7
  animateIn: { x: -100, y: -20 },
@@ -1,8 +1,20 @@
1
1
  import type { ToastPosition } from "./positions";
2
+ /** Directions in which a toast can be swiped to dismiss. */
2
3
  export type SwipeDirection = "top" | "bottom" | "left" | "right";
4
+ /** Axes along which swipe gestures are tracked. */
3
5
  export type SwipeAxis = "x" | "y";
6
+ /** Minimum pixel distance required to trigger a swipe dismissal. */
4
7
  export declare const SWIPE_DISMISS_THRESHOLD = 45;
8
+ /** Minimum velocity (pixels/ms) required to trigger a swipe dismissal. */
5
9
  export declare const SWIPE_DISMISS_VELOCITY = 0.11;
10
+ /** Distance in pixels to move the toast during the exit animation after a swipe. */
6
11
  export declare const SWIPE_EXIT_DISTANCE = 600;
12
+ /**
13
+ * Determines the allowed swipe directions based on the toast's position.
14
+ * For example, a "top-right" toast can be swiped "top" or "right".
15
+ *
16
+ * @param position - The toast's position on screen.
17
+ * @returns An array of allowed swipe directions.
18
+ */
7
19
  export declare const getDefaultSwipeDirections: (position?: ToastPosition | null) => SwipeDirection[];
8
20
  //# sourceMappingURL=swipe.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"swipe.d.ts","sourceRoot":"","sources":["../../src/lib/core/swipe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AACjE,MAAM,MAAM,SAAS,GAAG,GAAG,GAAG,GAAG,CAAC;AAElC,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAC3C,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC,eAAO,MAAM,yBAAyB,GACrC,WAAW,aAAa,GAAG,IAAI,KAC7B,cAAc,EAwBhB,CAAC"}
1
+ {"version":3,"file":"swipe.d.ts","sourceRoot":"","sources":["../../src/lib/core/swipe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,4DAA4D;AAC5D,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AACjE,mDAAmD;AACnD,MAAM,MAAM,SAAS,GAAG,GAAG,GAAG,GAAG,CAAC;AAElC,oEAAoE;AACpE,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,0EAA0E;AAC1E,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAC3C,oFAAoF;AACpF,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,GACrC,WAAW,aAAa,GAAG,IAAI,KAC7B,cAAc,EAwBhB,CAAC"}
@@ -1,6 +1,16 @@
1
+ /** Minimum pixel distance required to trigger a swipe dismissal. */
1
2
  export const SWIPE_DISMISS_THRESHOLD = 45;
3
+ /** Minimum velocity (pixels/ms) required to trigger a swipe dismissal. */
2
4
  export const SWIPE_DISMISS_VELOCITY = 0.11;
5
+ /** Distance in pixels to move the toast during the exit animation after a swipe. */
3
6
  export const SWIPE_EXIT_DISTANCE = 600;
7
+ /**
8
+ * Determines the allowed swipe directions based on the toast's position.
9
+ * For example, a "top-right" toast can be swiped "top" or "right".
10
+ *
11
+ * @param position - The toast's position on screen.
12
+ * @returns An array of allowed swipe directions.
13
+ */
4
14
  export const getDefaultSwipeDirections = (position) => {
5
15
  if (!position) {
6
16
  return ["top", "bottom", "left", "right"];
@@ -1 +1 @@
1
- {"version":3,"file":"toast-factory.d.ts","sourceRoot":"","sources":["../../src/lib/core/toast-factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGX,YAAY,EAEZ,MAAM,SAAS,CAAC;AAkGjB,eAAO,MAAM,KAAK,cAAc,CAAC"}
1
+ {"version":3,"file":"toast-factory.d.ts","sourceRoot":"","sources":["../../src/lib/core/toast-factory.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAGX,YAAY,EAEZ,MAAM,SAAS,CAAC;AAoIjB,eAAO,MAAM,KAAK,cAAc,CAAC"}
@@ -1,35 +1,67 @@
1
+ /**
2
+ * Factory module for creating and managing toast notifications.
3
+ * Provides the main `toast` function and its variants (success, error, promise).
4
+ */
1
5
  import { toastState } from "./toast-state";
6
+ /**
7
+ * Helper to normalize string input into a ToastData object.
8
+ */
2
9
  const normalizeToastData = (data) => {
3
10
  if (typeof data === "string") {
4
11
  return { description: data };
5
12
  }
6
13
  return data;
7
14
  };
15
+ /**
16
+ * Resolves the state of a promise-based toast (success or error) into actual toast data.
17
+ */
8
18
  const resolvePromiseState = async (value, state) => {
9
19
  const resolved = typeof state === "function" ? await state(value) : await state;
10
20
  return normalizeToastData(resolved);
11
21
  };
22
+ /**
23
+ * The main entry point for creating toasts.
24
+ * @param data - Toast configuration object or description string.
25
+ * @returns The ID of the created toast.
26
+ */
12
27
  const createToast = ((data) => {
13
28
  return toastState.add(normalizeToastData(data));
14
29
  });
30
+ /**
31
+ * Creates a success variant toast.
32
+ */
15
33
  createToast.success = (data) => {
16
34
  if (typeof data === "string") {
17
35
  return toastState.add({ description: data, variant: "success" });
18
36
  }
19
37
  return toastState.add({ ...data, variant: "success" });
20
38
  };
39
+ /**
40
+ * Creates a warning variant toast.
41
+ */
21
42
  createToast.warning = (data) => {
22
43
  if (typeof data === "string") {
23
44
  return toastState.add({ description: data, variant: "warning" });
24
45
  }
25
46
  return toastState.add({ ...data, variant: "warning" });
26
47
  };
48
+ /**
49
+ * Creates an error (destructive) variant toast.
50
+ */
27
51
  createToast.error = (data) => {
28
52
  if (typeof data === "string") {
29
53
  return toastState.add({ description: data, variant: "destructive" });
30
54
  }
31
55
  return toastState.add({ ...data, variant: "destructive" });
32
56
  };
57
+ /**
58
+ * Creates a toast that tracks a promise's lifecycle.
59
+ * Updates automatically from loading -> success/error.
60
+ *
61
+ * @param promise - The promise to observe.
62
+ * @param options - Configuration for loading, success, and error states.
63
+ * @returns The ID of the toast.
64
+ */
33
65
  createToast.promise = (promise, options) => {
34
66
  const loadingData = normalizeToastData(options.loading);
35
67
  const toastId = toastState.add({
@@ -58,9 +90,15 @@ createToast.promise = (promise, options) => {
58
90
  });
59
91
  return toastId;
60
92
  };
93
+ /**
94
+ * Dismisses a toast by ID.
95
+ */
61
96
  createToast.dismiss = (id) => {
62
97
  toastState.update(id, { shouldClose: true });
63
98
  };
99
+ /**
100
+ * Dismisses all active toasts.
101
+ */
64
102
  createToast.dismissAll = () => {
65
103
  toastState.dismissAll();
66
104
  };
@@ -1,17 +1,49 @@
1
1
  import type { ToastData, ToastSubscriber } from "./types";
2
+ /**
3
+ * Manages the global state of toast notifications.
4
+ * Implements a singleton pattern with a subscription mechanism.
5
+ */
2
6
  declare class ToastState {
3
7
  private toasts;
4
8
  private subscribers;
5
9
  private idCounter;
10
+ /**
11
+ * Subscribes to changes in the toast list.
12
+ * @param callback - Function to be called when the toast list updates.
13
+ * @returns A cleanup function to unsubscribe.
14
+ */
6
15
  subscribe(callback: ToastSubscriber): () => void;
7
16
  private notify;
8
17
  private generateId;
18
+ /**
19
+ * Adds a new toast to the state.
20
+ * @param data - The toast configuration (without ID).
21
+ * @returns The generated ID of the new toast.
22
+ */
9
23
  add(data: Omit<ToastData, "id">): string;
24
+ /**
25
+ * Removes a toast from the state by its ID.
26
+ * @param id - The ID of the toast to remove.
27
+ */
10
28
  remove(id: string): void;
29
+ /**
30
+ * Updates an existing toast's data.
31
+ * @param id - The ID of the toast to update.
32
+ * @param data - Partial data to merge into the existing toast.
33
+ */
11
34
  update(id: string, data: Partial<ToastData>): void;
35
+ /**
36
+ * Marks all active toasts for dismissal.
37
+ * Triggers the closing animation by setting `shouldClose` to true.
38
+ */
12
39
  dismissAll(): void;
40
+ /**
41
+ * Returns the current list of active toasts.
42
+ * @returns A copy of the toast array.
43
+ */
13
44
  getToasts(): ToastData[];
14
45
  }
46
+ /** Global singleton instance of the toast state. */
15
47
  export declare const toastState: ToastState;
16
48
  export { ToastState };
17
49
  //# sourceMappingURL=toast-state.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"toast-state.d.ts","sourceRoot":"","sources":["../../src/lib/core/toast-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1D,cAAM,UAAU;IACf,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,WAAW,CAAmC;IACtD,OAAO,CAAC,SAAS,CAAK;IAEtB,SAAS,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,IAAI;IAOhD,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,UAAU;IAIlB,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,MAAM;IAQxC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAKxB,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI;IAOlD,UAAU,IAAI,IAAI;IASlB,SAAS,IAAI,SAAS,EAAE;CAGxB;AAED,eAAO,MAAM,UAAU,YAAmB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"toast-state.d.ts","sourceRoot":"","sources":["../../src/lib/core/toast-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1D;;;GAGG;AACH,cAAM,UAAU;IACf,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,WAAW,CAAmC;IACtD,OAAO,CAAC,SAAS,CAAK;IAEtB;;;;OAIG;IACH,SAAS,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,IAAI;IAOhD,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,UAAU;IAIlB;;;;OAIG;IACH,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,MAAM;IASxC;;;OAGG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAKxB;;;;OAIG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI;IAOlD;;;OAGG;IACH,UAAU,IAAI,IAAI;IASlB;;;OAGG;IACH,SAAS,IAAI,SAAS,EAAE;CAGxB;AAED,oDAAoD;AACpD,eAAO,MAAM,UAAU,YAAmB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,CAAC"}