@maas/vue-equipment 0.4.2 → 0.6.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 (60) hide show
  1. package/dist/composables/index.js.map +1 -1
  2. package/dist/composables/index.mjs.map +1 -1
  3. package/dist/nuxt/module.json +1 -1
  4. package/dist/nuxt/module.mjs +23 -2
  5. package/dist/plugins/MagicMarquee/index.d.ts +3 -0
  6. package/dist/plugins/MagicMarquee/index.mjs +7 -0
  7. package/dist/plugins/MagicMarquee/nuxt.d.ts +2 -0
  8. package/dist/plugins/MagicMarquee/nuxt.mjs +5 -0
  9. package/dist/plugins/MagicMarquee/src/components/MagicMarquee.vue +105 -0
  10. package/dist/plugins/MagicMarquee/src/components/MagicMarquee.vue.d.ts +34 -0
  11. package/dist/plugins/MagicMarquee/src/composables/useMarqueeApi.d.ts +15 -0
  12. package/dist/plugins/MagicMarquee/src/composables/useMarqueeApi.mjs +84 -0
  13. package/dist/plugins/MagicModal/src/components/MagicModal.vue +38 -58
  14. package/dist/plugins/MagicModal/src/components/MagicModal.vue.d.ts +15 -15
  15. package/dist/plugins/MagicModal/src/composables/useModalApi.d.ts +4 -3
  16. package/dist/plugins/MagicModal/src/composables/useModalApi.mjs +4 -3
  17. package/dist/plugins/MagicModal/src/composables/useModalCallback.d.ts +22 -0
  18. package/dist/plugins/MagicModal/src/composables/useModalCallback.mjs +60 -0
  19. package/dist/plugins/MagicModal/src/types/index.d.ts +7 -5
  20. package/dist/plugins/MagicModal/src/utils/defaultOptions.d.ts +2 -2
  21. package/dist/plugins/MagicPlayer/src/composables/useControlsApi.mjs +1 -2
  22. package/dist/plugins/MagicPlayer/src/composables/useMediaApi.d.ts +1 -1
  23. package/dist/plugins/MagicPlayer/src/composables/useMediaApi.mjs +2 -3
  24. package/dist/plugins/MagicPlayer/src/composables/useRuntimeSourceProvider.mjs +1 -2
  25. package/dist/plugins/MagicPlayer/src/types/index.d.ts +1 -1
  26. package/dist/plugins/MagicScroll/index.mjs +2 -0
  27. package/dist/plugins/MagicScroll/src/components/MagicScrollCollision.vue +1 -1
  28. package/dist/plugins/MagicScroll/src/components/MagicScrollMotion.vue +58 -0
  29. package/dist/plugins/MagicScroll/src/components/MagicScrollMotion.vue.d.ts +42 -0
  30. package/dist/plugins/MagicScroll/src/components/MagicScrollTransform.vue.d.ts +9 -9
  31. package/dist/plugins/MagicScroll/src/composables/useProgress.d.ts +1 -1
  32. package/dist/plugins/MagicScroll/src/composables/useProgress.mjs +1 -2
  33. package/dist/plugins/MagicScroll/src/types/injectionKeys.d.ts +1 -2
  34. package/dist/plugins/MagicToast/demo/DemoToast.vue +22 -0
  35. package/dist/plugins/MagicToast/demo/DemoToast.vue.d.ts +14 -0
  36. package/dist/plugins/MagicToast/index.d.ts +5 -0
  37. package/dist/plugins/MagicToast/index.mjs +9 -0
  38. package/dist/plugins/MagicToast/nuxt.d.ts +2 -0
  39. package/dist/plugins/MagicToast/nuxt.mjs +5 -0
  40. package/dist/plugins/MagicToast/src/components/MagicToast.vue +229 -0
  41. package/dist/plugins/MagicToast/src/components/MagicToast.vue.d.ts +28 -0
  42. package/dist/plugins/MagicToast/src/components/MagicToastComponent.vue +101 -0
  43. package/dist/plugins/MagicToast/src/components/MagicToastComponent.vue.d.ts +48 -0
  44. package/dist/plugins/MagicToast/src/composables/useToastApi.d.ts +11 -0
  45. package/dist/plugins/MagicToast/src/composables/useToastApi.mjs +60 -0
  46. package/dist/plugins/MagicToast/src/composables/useToastCallback.d.ts +21 -0
  47. package/dist/plugins/MagicToast/src/composables/useToastCallback.mjs +43 -0
  48. package/dist/plugins/MagicToast/src/composables/useToastEmitter.d.ts +15 -0
  49. package/dist/plugins/MagicToast/src/composables/useToastEmitter.mjs +9 -0
  50. package/dist/plugins/MagicToast/src/composables/useToastInternalApi.d.ts +4 -0
  51. package/dist/plugins/MagicToast/src/composables/useToastInternalApi.mjs +26 -0
  52. package/dist/plugins/MagicToast/src/composables/useToastStore.d.ts +17 -0
  53. package/dist/plugins/MagicToast/src/composables/useToastStore.mjs +41 -0
  54. package/dist/plugins/MagicToast/src/types/index.d.ts +42 -0
  55. package/dist/plugins/MagicToast/src/types/index.mjs +0 -0
  56. package/dist/plugins/MagicToast/src/utils/defaultOptions.d.ts +3 -0
  57. package/dist/plugins/MagicToast/src/utils/defaultOptions.mjs +14 -0
  58. package/dist/plugins/index.d.ts +0 -3
  59. package/dist/plugins/index.mjs +0 -3
  60. package/package.json +19 -11
@@ -0,0 +1,229 @@
1
+ <template>
2
+ <Teleport
3
+ :to="mappedOptions.teleport?.target"
4
+ :disabled="mappedOptions.teleport?.disabled"
5
+ >
6
+ <div class="magic-toast" :id="toValue(id)" :class="toValue(props.class)">
7
+ <transition-group
8
+ tag="ol"
9
+ ref="listRef"
10
+ class="magic-toast__inner"
11
+ :name="mappedOptions.transitions!.list"
12
+ :on-before-enter="onBeforeEnter"
13
+ :on-enter="onEnter"
14
+ :on-after-enter="onAfterEnter"
15
+ :on-before-leave="onBeforeLeave"
16
+ :on-leave="onLeave"
17
+ :on-after-leave="onAfterLeave"
18
+ >
19
+ <magic-toast-component
20
+ v-for="(toast, index) in toasts"
21
+ :id="toast.id"
22
+ :key="toast.id"
23
+ :index="index"
24
+ :total="count || 0"
25
+ :siblings="activeElements"
26
+ :class="{
27
+ expanded: isExpanded,
28
+ }"
29
+ @mouseenter="onMouseenter"
30
+ @mouseleave="onMouseleave"
31
+ >
32
+ <component
33
+ :is="toast.component"
34
+ v-bind="toast.props"
35
+ @close="toast.remove"
36
+ @click.self="onClick"
37
+ />
38
+ </magic-toast-component>
39
+ </transition-group>
40
+ </div>
41
+ </Teleport>
42
+ </template>
43
+
44
+ <script setup lang="ts">
45
+ import { defu } from 'defu'
46
+ import { toValue, ref, type MaybeRef } from 'vue'
47
+ import { onClickOutside, type MaybeElement } from '@vueuse/core'
48
+ import { defaultOptions } from './../utils/defaultOptions'
49
+ import { useToastApi } from './../composables/useToastApi'
50
+ import { useToastCallback } from './../composables/useToastCallback'
51
+
52
+ import MagicToastComponent from './MagicToastComponent.vue'
53
+
54
+ import type { Options } from './../types/index'
55
+
56
+ interface MagicToastProps {
57
+ id: MaybeRef<string>
58
+ class: MaybeRef<string>
59
+ options?: Options
60
+ }
61
+
62
+ const props = defineProps<MagicToastProps>()
63
+
64
+ const { toasts, count, oldest } = useToastApi(props.id)
65
+
66
+ const mappedOptions = defu(props.options, defaultOptions)
67
+ const isExpanded = ref(mappedOptions.layout?.expand === true)
68
+ const listRef = ref<MaybeElement>()
69
+
70
+ const {
71
+ onBeforeEnter,
72
+ onEnter,
73
+ onAfterEnter,
74
+ onBeforeLeave,
75
+ onLeave,
76
+ onAfterLeave,
77
+ activeElements,
78
+ } = useToastCallback({ id: props.id, mappedOptions, count, oldest })
79
+
80
+ function onMouseenter() {
81
+ if (mappedOptions.layout?.expand === 'hover') {
82
+ isExpanded.value = true
83
+ }
84
+ }
85
+
86
+ function onMouseleave() {
87
+ if (mappedOptions.layout?.expand === 'hover') {
88
+ isExpanded.value = false
89
+ }
90
+ }
91
+
92
+ function onClick() {
93
+ if (mappedOptions.layout?.expand === 'click') {
94
+ isExpanded.value = true
95
+ }
96
+ }
97
+
98
+ function outsideClickCallback() {
99
+ if (mappedOptions.layout?.expand === 'click') {
100
+ isExpanded.value = false
101
+ }
102
+ }
103
+
104
+ onClickOutside(listRef, outsideClickCallback)
105
+ </script>
106
+
107
+ <style lang="css">
108
+ :root {
109
+ --magic-toast-enter-x: 0;
110
+ --magic-toast-enter-y: 0;
111
+ --magic-toast-scale: 0.1;
112
+ --magic-toast-transform-x: 0;
113
+ --magic-toast-transform-y: 0;
114
+ --magic-toast-transition: transform 300ms ease-out;
115
+ --magic-toast-z-index: 999;
116
+ --magic-toast-gap: 0.75rem;
117
+ --magic-toast-padding: 1rem;
118
+
119
+ --mt-multiplier: 1;
120
+ --mt-transform-x: -50%;
121
+ --mt-transform-y: -50%;
122
+ }
123
+
124
+ .magic-toast {
125
+ position: fixed;
126
+ inset: 0;
127
+ width: 100%;
128
+ height: 100%;
129
+ display: flex;
130
+ flex-direction: column;
131
+ justify-content: center;
132
+ align-items: center;
133
+ z-index: var(--magic-toast-z-index, 999);
134
+ background: transparent;
135
+ color: inherit;
136
+ pointer-events: none;
137
+ }
138
+
139
+ .magic-toast__inner {
140
+ position: relative;
141
+ overflow: scroll;
142
+ max-height: 100%;
143
+ width: 100%;
144
+ height: 100%;
145
+ & .magic-toast-component {
146
+ left: 50%;
147
+ top: 50%;
148
+ transform: translateX(var(--mt-transform-x, -50%))
149
+ translateY(var(--mt-transform-y, -50%));
150
+ }
151
+ }
152
+
153
+ .magic-toast__inner * {
154
+ pointer-events: all;
155
+ }
156
+
157
+ .magic-toast.-top-left,
158
+ .magic-toast.-top-center,
159
+ .magic-toast.-top-right {
160
+ --magic-toast-transform-y: 10;
161
+ --magic-toast-enter-y: -100%;
162
+ --mt-multiplier: 1;
163
+ & .magic-toast-component {
164
+ top: var(--magic-toast-padding, 1rem);
165
+ --mt-transform-y: 0;
166
+ }
167
+ }
168
+
169
+ .magic-toast.-bottom-left,
170
+ .magic-toast.-bottom-center,
171
+ .magic-toast.-bottom-right {
172
+ --magic-toast-transform-y: 10;
173
+ --magic-toast-enter-y: 100%;
174
+ --mt-multiplier: -1;
175
+ & .magic-toast-component {
176
+ top: unset;
177
+ bottom: var(--magic-toast-padding, 1rem);
178
+ --mt-transform-y: 0;
179
+ }
180
+ }
181
+
182
+ .magic-toast.-top-left,
183
+ .magic-toast.-bottom-left {
184
+ & .magic-toast-component {
185
+ left: var(--magic-toast-padding, 1rem);
186
+ --mt-transform-x: 0;
187
+ }
188
+ }
189
+
190
+ .magic-toast.-top-right,
191
+ .magic-toast.-bottom-right {
192
+ & .magic-toast-component {
193
+ left: unset;
194
+ right: var(--magic-toast-padding, 1rem);
195
+ --mt-transform-x: 0;
196
+ }
197
+ }
198
+
199
+ .magic-toast.-from-left {
200
+ --magic-toast-enter-x: -100%;
201
+ --magic-toast-enter-y: 0;
202
+ --magic-toast-transform-y: 0;
203
+ --magic-toast-transform-x: -30;
204
+ }
205
+
206
+ .magic-toast.-from-right {
207
+ --magic-toast-enter-x: 100%;
208
+ --magic-toast-enter-y: 0;
209
+ --magic-toast-transform-y: 0;
210
+ --magic-toast-transform-x: 30;
211
+ }
212
+
213
+ .magic-toast--list-enter-active * {
214
+ transition: all 300ms ease-out;
215
+ }
216
+
217
+ .magic-toast--list-enter-from * {
218
+ transform: translateY(var(--magic-toast-enter-y, 0))
219
+ translateX(var(--magic-toast-enter-x, 0));
220
+ }
221
+
222
+ .magic-toast--list-leave-active {
223
+ transition: all 150ms ease-out;
224
+ }
225
+
226
+ .magic-toast--list-leave-to {
227
+ opacity: 0;
228
+ }
229
+ </style>
@@ -0,0 +1,28 @@
1
+ import { type MaybeRef } from 'vue';
2
+ import type { Options } from './../types/index';
3
+ declare const _default: import("vue").DefineComponent<{
4
+ id: {
5
+ type: import("vue").PropType<MaybeRef<string>>;
6
+ required: true;
7
+ };
8
+ class: {
9
+ type: import("vue").PropType<MaybeRef<string>>;
10
+ required: true;
11
+ };
12
+ options: {
13
+ type: import("vue").PropType<Options>;
14
+ };
15
+ }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
16
+ id: {
17
+ type: import("vue").PropType<MaybeRef<string>>;
18
+ required: true;
19
+ };
20
+ class: {
21
+ type: import("vue").PropType<MaybeRef<string>>;
22
+ required: true;
23
+ };
24
+ options: {
25
+ type: import("vue").PropType<Options>;
26
+ };
27
+ }>>, {}, {}>;
28
+ export default _default;
@@ -0,0 +1,101 @@
1
+ <template>
2
+ <li
3
+ class="magic-toast-component"
4
+ ref="elRef"
5
+ @mouseenter="onMouseenter"
6
+ :id="id"
7
+ >
8
+ <div class="magic-toast-component__inner">
9
+ <slot />
10
+ </div>
11
+ </li>
12
+ </template>
13
+
14
+ <script lang="ts" setup>
15
+ import { ref, computed, onMounted, watchEffect } from 'vue'
16
+ import { type ActiveElement } from './../types'
17
+
18
+ interface Props {
19
+ index: number
20
+ total: number
21
+ id: string
22
+ siblings: ActiveElement[]
23
+ }
24
+
25
+ const props = defineProps<Props>()
26
+ const emit = defineEmits<{
27
+ mouseenter: [event: Event]
28
+ }>()
29
+
30
+ const elRef = ref<HTMLElement | undefined>(undefined)
31
+ const newerSiblings = computed(() => {
32
+ return props.siblings.slice(props.index + 1)
33
+ })
34
+
35
+ function setIndex() {
36
+ const index = (props.total - props.index - 1).toString()
37
+ elRef.value?.style.setProperty('--mt-index', index)
38
+ }
39
+
40
+ function setOffset() {
41
+ const offset = newerSiblings.value.reduce((acc, curr) => {
42
+ return acc + curr.height
43
+ }, 0)
44
+ elRef.value?.style.setProperty('--mt-offset', `${offset}`)
45
+ }
46
+
47
+ function onMouseenter(event: Event) {
48
+ emit('mouseenter', event)
49
+ }
50
+
51
+ onMounted(() => {
52
+ setIndex()
53
+ setOffset()
54
+ })
55
+
56
+ watchEffect(() => {
57
+ setIndex()
58
+ setOffset()
59
+ })
60
+ </script>
61
+
62
+ <style lang="css">
63
+ .magic-toast-component {
64
+ --mt-index: 0;
65
+ --mt-offset: 0;
66
+ --mt-matrix-scale: calc(1 - (var(--magic-toast-scale) * var(--mt-index, 0)));
67
+ --mt-matrix-transform-x: calc(
68
+ var(--magic-toast-transform-x) * var(--mt-index, 0) * var(--mt-multiplier)
69
+ );
70
+ --mt-matrix-transform-y: calc(
71
+ var(--magic-toast-transform-y) * var(--mt-index, 0) * var(--mt-multiplier)
72
+ );
73
+ position: absolute;
74
+ }
75
+
76
+ .magic-toast-component__inner {
77
+ position: relative;
78
+ width: 100%;
79
+ height: 100%;
80
+ transition: var(--magic-toast-transition, transform 300ms ease-out);
81
+ transform: matrix(
82
+ var(--mt-matrix-scale),
83
+ 0,
84
+ 0,
85
+ var(--mt-matrix-scale),
86
+ var(--mt-matrix-transform-x),
87
+ var(--mt-matrix-transform-y)
88
+ );
89
+ }
90
+
91
+ .magic-toast-component.expanded {
92
+ --mt-matrix-scale: 1;
93
+ --mt-matrix-transform-y: calc(((var(--mt-offset)) * var(--mt-multiplier)));
94
+ --mt-matrix-transform-x: 0;
95
+ &:not(:last-child) {
96
+ & .magic-toast-component__inner {
97
+ padding-bottom: calc(var(--magic-toast-gap) * var(--mt-index));
98
+ }
99
+ }
100
+ }
101
+ </style>
@@ -0,0 +1,48 @@
1
+ import { type ActiveElement } from './../types';
2
+ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
3
+ index: {
4
+ type: import("vue").PropType<number>;
5
+ required: true;
6
+ };
7
+ total: {
8
+ type: import("vue").PropType<number>;
9
+ required: true;
10
+ };
11
+ id: {
12
+ type: import("vue").PropType<string>;
13
+ required: true;
14
+ };
15
+ siblings: {
16
+ type: import("vue").PropType<ActiveElement[]>;
17
+ required: true;
18
+ };
19
+ }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
20
+ mouseenter: (event: Event) => void;
21
+ }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
22
+ index: {
23
+ type: import("vue").PropType<number>;
24
+ required: true;
25
+ };
26
+ total: {
27
+ type: import("vue").PropType<number>;
28
+ required: true;
29
+ };
30
+ id: {
31
+ type: import("vue").PropType<string>;
32
+ required: true;
33
+ };
34
+ siblings: {
35
+ type: import("vue").PropType<ActiveElement[]>;
36
+ required: true;
37
+ };
38
+ }>> & {
39
+ onMouseenter?: ((event: Event) => any) | undefined;
40
+ }, {}, {}>, {
41
+ default?(_: {}): any;
42
+ }>;
43
+ export default _default;
44
+ type __VLS_WithTemplateSlots<T, S> = T & {
45
+ new (): {
46
+ $slots: S;
47
+ };
48
+ };
@@ -0,0 +1,11 @@
1
+ import { type MaybeRef, type ComputedRef } from 'vue';
2
+ import type { AddArgs } from './../types.js';
3
+ export declare function useToastApi(id?: MaybeRef<string>): {
4
+ toasts: ComputedRef<import("./../types").Toast[] | undefined>;
5
+ count: ComputedRef<number | undefined>;
6
+ oldest: ComputedRef<import("./../types").Toast | undefined>;
7
+ add: (options: Pick<AddArgs, 'component' | 'props' | 'duration'>) => Promise<string | undefined>;
8
+ remove: (id: string) => void;
9
+ clear: () => void;
10
+ };
11
+ export type UseToastApiReturn = ReturnType<typeof useToastApi>;
@@ -0,0 +1,60 @@
1
+ import {
2
+ computed,
3
+ onUnmounted,
4
+ onBeforeMount,
5
+ toValue,
6
+ markRaw
7
+ } from "vue";
8
+ import { v4 as uuidv4 } from "uuid";
9
+ import { useToastStore } from "./useToastStore.mjs";
10
+ export function useToastApi(id) {
11
+ const { findInstance, addInstance, removeInstance } = useToastStore();
12
+ const mappedId = computed(() => toValue(id) || uuidv4());
13
+ const instance = computed(() => findInstance(toValue(mappedId)));
14
+ function initialize() {
15
+ const id2 = toValue(mappedId);
16
+ if (!findInstance(id2)) {
17
+ return addInstance(id2);
18
+ }
19
+ }
20
+ function destroy(id2) {
21
+ if (!id2)
22
+ return;
23
+ clear();
24
+ removeInstance(toValue(id2));
25
+ }
26
+ const toasts = computed(() => instance.value?.toasts);
27
+ const count = computed(() => toasts.value?.length);
28
+ const oldest = computed(() => toasts.value?.[0]);
29
+ async function add(options) {
30
+ const { component, props, duration } = options;
31
+ const id2 = instance.value?.add({
32
+ props,
33
+ duration,
34
+ component: markRaw(component)
35
+ });
36
+ return id2;
37
+ }
38
+ function remove(id2) {
39
+ instance.value?.remove(id2);
40
+ }
41
+ function clear() {
42
+ if (!instance.value)
43
+ return;
44
+ instance.value.toasts = [];
45
+ }
46
+ onBeforeMount(() => {
47
+ initialize();
48
+ });
49
+ onUnmounted(() => {
50
+ destroy(toValue(mappedId));
51
+ });
52
+ return {
53
+ toasts,
54
+ count,
55
+ oldest,
56
+ add,
57
+ remove,
58
+ clear
59
+ };
60
+ }
@@ -0,0 +1,21 @@
1
+ import { type Ref, type MaybeRef } from 'vue';
2
+ import type { Options, Toast } from './../types/index.js';
3
+ type Args = {
4
+ id: MaybeRef<string>;
5
+ mappedOptions: Options;
6
+ count: Ref<number | undefined>;
7
+ oldest: Ref<Toast | undefined>;
8
+ };
9
+ export declare function useToastCallback({ id, mappedOptions, count, oldest }: Args): {
10
+ onBeforeEnter: (_el: Element) => void;
11
+ onEnter: (_el: Element) => void;
12
+ onAfterEnter: (el: Element) => void;
13
+ onBeforeLeave: (_el: Element) => void;
14
+ onLeave: (el: Element) => void;
15
+ onAfterLeave: (_el: Element) => void;
16
+ activeElements: Ref<{
17
+ id: string;
18
+ height: number;
19
+ }[]>;
20
+ };
21
+ export {};
@@ -0,0 +1,43 @@
1
+ import { ref, toValue } from "vue";
2
+ import { useToastEmitter } from "./useToastEmitter.mjs";
3
+ export function useToastCallback({ id, mappedOptions, count, oldest }) {
4
+ const activeElements = ref([]);
5
+ function onBeforeEnter(_el) {
6
+ useToastEmitter().emit("beforeEnter", toValue(id));
7
+ }
8
+ function onEnter(_el) {
9
+ useToastEmitter().emit("enter", toValue(id));
10
+ if (count.value && mappedOptions.layout?.max && count.value > mappedOptions.layout.max) {
11
+ oldest.value?.remove();
12
+ }
13
+ }
14
+ function onAfterEnter(el) {
15
+ useToastEmitter().emit("afterEnter", toValue(id));
16
+ const mappedEl = el;
17
+ activeElements.value = [
18
+ ...activeElements.value,
19
+ { id: el.id, height: mappedEl.offsetHeight }
20
+ ];
21
+ }
22
+ function onBeforeLeave(_el) {
23
+ useToastEmitter().emit("beforeLeave", toValue(id));
24
+ }
25
+ function onLeave(el) {
26
+ useToastEmitter().emit("leave", toValue(id));
27
+ activeElements.value = activeElements.value.filter(
28
+ (item) => item.id !== el.id
29
+ );
30
+ }
31
+ function onAfterLeave(_el) {
32
+ useToastEmitter().emit("afterLeave", toValue(id));
33
+ }
34
+ return {
35
+ onBeforeEnter,
36
+ onEnter,
37
+ onAfterEnter,
38
+ onBeforeLeave,
39
+ onLeave,
40
+ onAfterLeave,
41
+ activeElements
42
+ };
43
+ }
@@ -0,0 +1,15 @@
1
+ import type { ToastEvents } from '../types.js';
2
+ export declare function useToastEmitter(): {
3
+ on: {
4
+ <Key extends keyof ToastEvents>(type: Key, handler: import("mitt").Handler<ToastEvents[Key]>): void;
5
+ (type: "*", handler: import("mitt").WildcardHandler<ToastEvents>): void;
6
+ };
7
+ off: {
8
+ <Key_1 extends keyof ToastEvents>(type: Key_1, handler?: import("mitt").Handler<ToastEvents[Key_1]> | undefined): void;
9
+ (type: "*", handler: import("mitt").WildcardHandler<ToastEvents>): void;
10
+ };
11
+ emit: {
12
+ <Key_2 extends keyof ToastEvents>(type: Key_2, event: ToastEvents[Key_2]): void;
13
+ <Key_3 extends keyof ToastEvents>(type: undefined extends ToastEvents[Key_3] ? Key_3 : never): void;
14
+ };
15
+ };
@@ -0,0 +1,9 @@
1
+ import mitt from "mitt";
2
+ const emitter = mitt();
3
+ export function useToastEmitter() {
4
+ return {
5
+ on: emitter.on,
6
+ off: emitter.off,
7
+ emit: emitter.emit
8
+ };
9
+ }
@@ -0,0 +1,4 @@
1
+ import type { ToastInstance, AddArgs } from './../types.js';
2
+ export declare function useToastInternalApi(): {
3
+ addToast: (args: AddArgs, ctx: ToastInstance) => string;
4
+ };
@@ -0,0 +1,26 @@
1
+ import { v4 as uuidv4 } from "uuid";
2
+ export function useToastInternalApi() {
3
+ function removeToastAfterTimeout(id, duration, ctx) {
4
+ if (duration > 0) {
5
+ setTimeout(() => {
6
+ ctx.remove(id);
7
+ }, duration);
8
+ }
9
+ }
10
+ function addToast(args, ctx) {
11
+ const id = uuidv4();
12
+ let { component, props, duration = 0 } = args;
13
+ const toast = {
14
+ component,
15
+ props,
16
+ id,
17
+ remove: () => ctx.remove(id)
18
+ };
19
+ ctx.toasts.push(toast);
20
+ removeToastAfterTimeout(id, duration, ctx);
21
+ return id;
22
+ }
23
+ return {
24
+ addToast
25
+ };
26
+ }
@@ -0,0 +1,17 @@
1
+ import type { ToastInstance, AddArgs } from '../types/index.js';
2
+ export declare function useToastStore(): {
3
+ toastStore: import("vue").Ref<{
4
+ id: string;
5
+ toasts: {
6
+ id: string;
7
+ component: Object;
8
+ props?: Record<string, any> | undefined;
9
+ remove: Function;
10
+ }[];
11
+ add: (args: AddArgs) => string;
12
+ remove: (id: string) => void;
13
+ }[]>;
14
+ findInstance: (id: string) => ToastInstance | undefined;
15
+ addInstance: (id: string) => ToastInstance;
16
+ removeInstance: (id: string) => void;
17
+ };
@@ -0,0 +1,41 @@
1
+ import { ref } from "vue";
2
+ import { useToastInternalApi } from "./useToastInternalApi.mjs";
3
+ const toastStore = ref([]);
4
+ export function useToastStore() {
5
+ const { addToast } = useToastInternalApi();
6
+ function createInstance(id) {
7
+ const instance = {
8
+ id,
9
+ toasts: [],
10
+ add: function(args) {
11
+ return addToast(args, this);
12
+ },
13
+ remove: function(id2) {
14
+ this.toasts = this.toasts.filter((toast) => toast.id !== id2);
15
+ }
16
+ };
17
+ return instance;
18
+ }
19
+ function findInstance(id) {
20
+ const instance = toastStore.value.find(
21
+ (instance2) => instance2.id === id
22
+ );
23
+ return instance;
24
+ }
25
+ function addInstance(id) {
26
+ const instance = createInstance(id);
27
+ toastStore.value.push(instance);
28
+ return instance;
29
+ }
30
+ function removeInstance(id) {
31
+ toastStore.value = toastStore.value.filter(
32
+ (instance) => instance.id !== id
33
+ );
34
+ }
35
+ return {
36
+ toastStore,
37
+ findInstance,
38
+ addInstance,
39
+ removeInstance
40
+ };
41
+ }