@maas/vue-equipment 0.5.0 → 0.6.1
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/dist/composables/index.d.mts +23 -1
- package/dist/composables/index.d.ts +23 -1
- package/dist/composables/index.js +118 -8
- package/dist/composables/index.js.map +1 -1
- package/dist/composables/index.mjs +111 -2
- package/dist/composables/index.mjs.map +1 -1
- package/dist/nuxt/module.json +1 -1
- package/dist/nuxt/module.mjs +16 -2
- package/dist/plugins/MagicMarquee/src/components/MagicMarquee.vue +3 -3
- package/dist/plugins/MagicMarquee/src/composables/{useMarquee.d.ts → useMarqueeApi.d.ts} +2 -2
- package/dist/plugins/MagicMarquee/src/composables/{useMarquee.mjs → useMarqueeApi.mjs} +1 -1
- package/dist/plugins/MagicModal/src/components/MagicModal.vue +39 -59
- package/dist/plugins/MagicModal/src/components/MagicModal.vue.d.ts +15 -15
- package/dist/plugins/MagicModal/src/composables/private/useModalCallback.d.ts +22 -0
- package/dist/plugins/MagicModal/src/composables/private/useModalCallback.mjs +60 -0
- package/dist/plugins/MagicModal/src/composables/useModalApi.d.ts +4 -3
- package/dist/plugins/MagicModal/src/composables/useModalApi.mjs +5 -4
- package/dist/plugins/MagicModal/src/types/index.d.ts +7 -5
- package/dist/plugins/MagicModal/src/utils/defaultOptions.d.ts +2 -2
- package/dist/plugins/MagicPlayer/src/composables/useControlsApi.mjs +1 -2
- package/dist/plugins/MagicPlayer/src/composables/useMediaApi.d.ts +1 -1
- package/dist/plugins/MagicPlayer/src/composables/useMediaApi.mjs +2 -2
- package/dist/plugins/MagicPlayer/src/composables/useRuntimeSourceProvider.mjs +1 -2
- package/dist/plugins/MagicPlayer/src/types/index.d.ts +1 -1
- package/dist/plugins/MagicScroll/index.d.ts +2 -2
- package/dist/plugins/MagicScroll/index.mjs +4 -2
- package/dist/plugins/MagicScroll/src/components/MagicScrollMotion.vue +58 -0
- package/dist/plugins/MagicScroll/src/components/MagicScrollMotion.vue.d.ts +42 -0
- package/dist/plugins/MagicScroll/src/components/MagicScrollScene.vue +2 -2
- package/dist/plugins/MagicScroll/src/components/MagicScrollTransform.vue.d.ts +9 -9
- package/dist/plugins/MagicScroll/src/composables/{useProgress.d.ts → useScrollApi.d.ts} +4 -4
- package/dist/plugins/MagicScroll/src/composables/{useProgress.mjs → useScrollApi.mjs} +2 -3
- package/dist/plugins/MagicScroll/src/types/injectionKeys.d.ts +1 -2
- package/dist/plugins/MagicToast/demo/DemoToast.vue +22 -0
- package/dist/plugins/MagicToast/demo/DemoToast.vue.d.ts +14 -0
- package/dist/plugins/MagicToast/index.d.ts +5 -0
- package/dist/plugins/MagicToast/index.mjs +9 -0
- package/dist/plugins/MagicToast/nuxt.d.ts +2 -0
- package/dist/plugins/MagicToast/nuxt.mjs +5 -0
- package/dist/plugins/MagicToast/src/components/MagicToast.vue +230 -0
- package/dist/plugins/MagicToast/src/components/MagicToast.vue.d.ts +28 -0
- package/dist/plugins/MagicToast/src/components/MagicToastComponent.vue +101 -0
- package/dist/plugins/MagicToast/src/components/MagicToastComponent.vue.d.ts +48 -0
- package/dist/plugins/MagicToast/src/composables/private/useToastCallback.d.ts +21 -0
- package/dist/plugins/MagicToast/src/composables/private/useToastCallback.mjs +43 -0
- package/dist/plugins/MagicToast/src/composables/private/useToastInternalApi.d.ts +4 -0
- package/dist/plugins/MagicToast/src/composables/private/useToastInternalApi.mjs +26 -0
- package/dist/plugins/MagicToast/src/composables/private/useToastStore.d.ts +17 -0
- package/dist/plugins/MagicToast/src/composables/private/useToastStore.mjs +41 -0
- package/dist/plugins/MagicToast/src/composables/useToastApi.d.ts +11 -0
- package/dist/plugins/MagicToast/src/composables/useToastApi.mjs +60 -0
- package/dist/plugins/MagicToast/src/composables/useToastEmitter.d.ts +15 -0
- package/dist/plugins/MagicToast/src/composables/useToastEmitter.mjs +9 -0
- package/dist/plugins/MagicToast/src/types/index.d.ts +42 -0
- package/dist/plugins/MagicToast/src/types/index.mjs +0 -0
- package/dist/plugins/MagicToast/src/utils/defaultOptions.d.ts +3 -0
- package/dist/plugins/MagicToast/src/utils/defaultOptions.mjs +14 -0
- package/dist/plugins/index.d.ts +2 -1
- package/dist/plugins/index.mjs +2 -1
- package/package.json +13 -1
- /package/dist/plugins/MagicModal/src/composables/{useModalStore.d.ts → private/useModalStore.d.ts} +0 -0
- /package/dist/plugins/MagicModal/src/composables/{useModalStore.mjs → private/useModalStore.mjs} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type MaybeRef } from '@vueuse/core';
|
|
2
|
-
export type
|
|
2
|
+
export type UseMarqueeApiParams = {
|
|
3
3
|
child: MaybeRef<HTMLElement | null | undefined>;
|
|
4
4
|
parent: MaybeRef<HTMLElement | null | undefined>;
|
|
5
5
|
options?: {
|
|
@@ -7,7 +7,7 @@ export type UseMarqueeParams = {
|
|
|
7
7
|
direction?: MaybeRef<'reverse' | 'normal'>;
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function useMarqueeApi({ child, parent, options }: UseMarqueeApiParams): {
|
|
11
11
|
duplicates: import("vue").Ref<number>;
|
|
12
12
|
playing: import("vue").Ref<boolean>;
|
|
13
13
|
play: () => void;
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
useResizeObserver,
|
|
5
5
|
toValue
|
|
6
6
|
} from "@vueuse/core";
|
|
7
|
-
export function
|
|
7
|
+
export function useMarqueeApi({ child, parent, options }) {
|
|
8
8
|
const duplicates = ref(1);
|
|
9
9
|
const childRect = useElementBounding(child);
|
|
10
10
|
const parentRect = useElementBounding(parent);
|
|
@@ -25,8 +25,10 @@
|
|
|
25
25
|
<transition
|
|
26
26
|
:name="mappedOptions.transitions?.content"
|
|
27
27
|
@before-leave="onBeforeLeave"
|
|
28
|
+
@leave="onLeave"
|
|
28
29
|
@after-leave="onAfterLeave"
|
|
29
30
|
@before-enter="onBeforeEnter"
|
|
31
|
+
@enter="onEnter"
|
|
30
32
|
@after-enter="onAfterEnter"
|
|
31
33
|
>
|
|
32
34
|
<div
|
|
@@ -36,7 +38,7 @@
|
|
|
36
38
|
>
|
|
37
39
|
<component
|
|
38
40
|
v-if="component"
|
|
39
|
-
v-bind="
|
|
41
|
+
v-bind="props"
|
|
40
42
|
:is="component"
|
|
41
43
|
@close="close"
|
|
42
44
|
/>
|
|
@@ -49,20 +51,27 @@
|
|
|
49
51
|
</template>
|
|
50
52
|
|
|
51
53
|
<script setup lang="ts">
|
|
52
|
-
import {
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
import {
|
|
55
|
+
ref,
|
|
56
|
+
watch,
|
|
57
|
+
nextTick,
|
|
58
|
+
toValue,
|
|
59
|
+
type Component,
|
|
60
|
+
type MaybeRef,
|
|
61
|
+
} from 'vue'
|
|
62
|
+
import { onKeyStroke } from '@vueuse/core'
|
|
63
|
+
import { defu } from 'defu'
|
|
55
64
|
import { defaultOptions } from './../utils/defaultOptions'
|
|
56
|
-
import {
|
|
65
|
+
import { useModalApi } from './../composables/useModalApi'
|
|
66
|
+
import { useModalCallback } from '../composables/private/useModalCallback'
|
|
57
67
|
|
|
58
|
-
import type {
|
|
59
|
-
import type { DefaultOptions } from './../types/index'
|
|
68
|
+
import type { Options } from './../types/index'
|
|
60
69
|
|
|
61
70
|
interface MagicModalProps {
|
|
62
71
|
id: MaybeRef<string>
|
|
63
|
-
component?:
|
|
64
|
-
|
|
65
|
-
options?:
|
|
72
|
+
component?: Component
|
|
73
|
+
props?: Record<string, unknown>
|
|
74
|
+
options?: Options
|
|
66
75
|
}
|
|
67
76
|
|
|
68
77
|
const props = withDefaults(defineProps<MagicModalProps>(), {
|
|
@@ -71,13 +80,7 @@ const props = withDefaults(defineProps<MagicModalProps>(), {
|
|
|
71
80
|
|
|
72
81
|
const modal = ref<HTMLElement | undefined>(undefined)
|
|
73
82
|
const modalApi = useModalApi(props.id, { focusTarget: modal })
|
|
74
|
-
|
|
75
|
-
const mappedOptions = {
|
|
76
|
-
...defaultOptions,
|
|
77
|
-
...props.options,
|
|
78
|
-
teleport: { ...defaultOptions.teleport, ...props.options.teleport },
|
|
79
|
-
transitions: { ...defaultOptions.transitions, ...props.options.transitions },
|
|
80
|
-
}
|
|
83
|
+
const mappedOptions = defu(props.options, defaultOptions)
|
|
81
84
|
|
|
82
85
|
const {
|
|
83
86
|
isActive,
|
|
@@ -94,6 +97,25 @@ const {
|
|
|
94
97
|
const innerActive = ref(false)
|
|
95
98
|
const wrapperActive = ref(false)
|
|
96
99
|
|
|
100
|
+
const {
|
|
101
|
+
onBeforeEnter,
|
|
102
|
+
onEnter,
|
|
103
|
+
onAfterEnter,
|
|
104
|
+
onBeforeLeave,
|
|
105
|
+
onLeave,
|
|
106
|
+
onAfterLeave,
|
|
107
|
+
} = useModalCallback({
|
|
108
|
+
id: props.id,
|
|
109
|
+
mappedOptions,
|
|
110
|
+
addScrollLockPadding,
|
|
111
|
+
removeScrollLockPadding,
|
|
112
|
+
lockScroll,
|
|
113
|
+
unlockScroll,
|
|
114
|
+
trapFocus,
|
|
115
|
+
releaseFocus,
|
|
116
|
+
wrapperActive,
|
|
117
|
+
})
|
|
118
|
+
|
|
97
119
|
// Handle state
|
|
98
120
|
async function onOpen() {
|
|
99
121
|
wrapperActive.value = true
|
|
@@ -105,48 +127,6 @@ function onClose() {
|
|
|
105
127
|
innerActive.value = false
|
|
106
128
|
}
|
|
107
129
|
|
|
108
|
-
// Transition Callbacks
|
|
109
|
-
function onBeforeEnter() {
|
|
110
|
-
useModalEmitter().emit('beforeEnter', toValue(props.id))
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async function onAfterEnter() {
|
|
114
|
-
if (mappedOptions.scrollLock) {
|
|
115
|
-
if (mappedOptions.scrollLockPadding) {
|
|
116
|
-
addScrollLockPadding()
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
lockScroll()
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (mappedOptions.focusTrap) {
|
|
123
|
-
await nextTick()
|
|
124
|
-
trapFocus()
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
useModalEmitter().emit('afterEnter', toValue(props.id))
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function onBeforeLeave() {
|
|
131
|
-
useModalEmitter().emit('beforeLeave', toValue(props.id))
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function onAfterLeave() {
|
|
135
|
-
if (mappedOptions.scrollLock) {
|
|
136
|
-
unlockScroll()
|
|
137
|
-
if (mappedOptions.scrollLockPadding) {
|
|
138
|
-
removeScrollLockPadding()
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (mappedOptions.focusTrap) {
|
|
143
|
-
releaseFocus()
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
wrapperActive.value = false
|
|
147
|
-
useModalEmitter().emit('afterLeave', toValue(props.id))
|
|
148
|
-
}
|
|
149
|
-
|
|
150
130
|
onKeyStroke('Escape', (e) => {
|
|
151
131
|
e.preventDefault()
|
|
152
132
|
close()
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type {
|
|
1
|
+
import { type Component, type MaybeRef } from 'vue';
|
|
2
|
+
import type { Options } from './../types/index';
|
|
3
3
|
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
4
|
+
props: {
|
|
5
|
+
type: import("vue").PropType<Record<string, unknown>>;
|
|
6
|
+
};
|
|
4
7
|
id: {
|
|
5
8
|
type: import("vue").PropType<MaybeRef<string>>;
|
|
6
9
|
required: true;
|
|
7
10
|
};
|
|
8
11
|
component: {
|
|
9
|
-
type: import("vue").PropType<
|
|
10
|
-
};
|
|
11
|
-
componentProps: {
|
|
12
|
-
type: import("vue").PropType<Record<string, unknown>>;
|
|
12
|
+
type: import("vue").PropType<Component>;
|
|
13
13
|
};
|
|
14
14
|
options: {
|
|
15
|
-
type: import("vue").PropType<
|
|
16
|
-
default: () =>
|
|
15
|
+
type: import("vue").PropType<Options>;
|
|
16
|
+
default: () => Options;
|
|
17
17
|
};
|
|
18
18
|
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
19
|
+
props: {
|
|
20
|
+
type: import("vue").PropType<Record<string, unknown>>;
|
|
21
|
+
};
|
|
19
22
|
id: {
|
|
20
23
|
type: import("vue").PropType<MaybeRef<string>>;
|
|
21
24
|
required: true;
|
|
22
25
|
};
|
|
23
26
|
component: {
|
|
24
|
-
type: import("vue").PropType<
|
|
25
|
-
};
|
|
26
|
-
componentProps: {
|
|
27
|
-
type: import("vue").PropType<Record<string, unknown>>;
|
|
27
|
+
type: import("vue").PropType<Component>;
|
|
28
28
|
};
|
|
29
29
|
options: {
|
|
30
|
-
type: import("vue").PropType<
|
|
31
|
-
default: () =>
|
|
30
|
+
type: import("vue").PropType<Options>;
|
|
31
|
+
default: () => Options;
|
|
32
32
|
};
|
|
33
33
|
}>>, {
|
|
34
|
-
options:
|
|
34
|
+
options: Options;
|
|
35
35
|
}, {}>, {
|
|
36
36
|
default?(_: {}): any;
|
|
37
37
|
}>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Ref, type MaybeRef } from 'vue';
|
|
2
|
+
import type { Options } from '../../types.js';
|
|
3
|
+
type Args = {
|
|
4
|
+
id: MaybeRef<string>;
|
|
5
|
+
mappedOptions: Options;
|
|
6
|
+
addScrollLockPadding: () => void;
|
|
7
|
+
removeScrollLockPadding: () => void;
|
|
8
|
+
lockScroll: () => void;
|
|
9
|
+
unlockScroll: () => void;
|
|
10
|
+
trapFocus: () => void;
|
|
11
|
+
releaseFocus: () => void;
|
|
12
|
+
wrapperActive: Ref<boolean>;
|
|
13
|
+
};
|
|
14
|
+
export declare function useModalCallback({ id, mappedOptions, addScrollLockPadding, removeScrollLockPadding, lockScroll, unlockScroll, trapFocus, releaseFocus, wrapperActive, }: Args): {
|
|
15
|
+
onBeforeEnter: (_el: Element) => void;
|
|
16
|
+
onEnter: (_el: Element) => void;
|
|
17
|
+
onAfterEnter: (el: Element) => Promise<void>;
|
|
18
|
+
onBeforeLeave: (_el: Element) => void;
|
|
19
|
+
onLeave: (el: Element) => void;
|
|
20
|
+
onAfterLeave: (_el: Element) => void;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { toValue, nextTick } from "vue";
|
|
2
|
+
import { useModalEmitter } from "./../useModalEmitter.mjs";
|
|
3
|
+
export function useModalCallback({
|
|
4
|
+
id,
|
|
5
|
+
mappedOptions,
|
|
6
|
+
addScrollLockPadding,
|
|
7
|
+
removeScrollLockPadding,
|
|
8
|
+
lockScroll,
|
|
9
|
+
unlockScroll,
|
|
10
|
+
trapFocus,
|
|
11
|
+
releaseFocus,
|
|
12
|
+
wrapperActive
|
|
13
|
+
}) {
|
|
14
|
+
function onBeforeEnter(_el) {
|
|
15
|
+
useModalEmitter().emit("beforeEnter", toValue(id));
|
|
16
|
+
}
|
|
17
|
+
function onEnter(_el) {
|
|
18
|
+
useModalEmitter().emit("enter", toValue(id));
|
|
19
|
+
}
|
|
20
|
+
async function onAfterEnter(el) {
|
|
21
|
+
useModalEmitter().emit("afterEnter", toValue(id));
|
|
22
|
+
if (mappedOptions.scrollLock) {
|
|
23
|
+
if (mappedOptions.scrollLockPadding) {
|
|
24
|
+
addScrollLockPadding();
|
|
25
|
+
}
|
|
26
|
+
lockScroll();
|
|
27
|
+
}
|
|
28
|
+
if (mappedOptions.focusTrap) {
|
|
29
|
+
await nextTick();
|
|
30
|
+
trapFocus();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function onBeforeLeave(_el) {
|
|
34
|
+
useModalEmitter().emit("beforeLeave", toValue(id));
|
|
35
|
+
}
|
|
36
|
+
function onLeave(el) {
|
|
37
|
+
useModalEmitter().emit("leave", toValue(id));
|
|
38
|
+
}
|
|
39
|
+
function onAfterLeave(_el) {
|
|
40
|
+
useModalEmitter().emit("afterLeave", toValue(id));
|
|
41
|
+
if (mappedOptions.scrollLock) {
|
|
42
|
+
unlockScroll();
|
|
43
|
+
if (mappedOptions.scrollLockPadding) {
|
|
44
|
+
removeScrollLockPadding();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (mappedOptions.focusTrap) {
|
|
48
|
+
releaseFocus();
|
|
49
|
+
}
|
|
50
|
+
wrapperActive.value = false;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
onBeforeEnter,
|
|
54
|
+
onEnter,
|
|
55
|
+
onAfterEnter,
|
|
56
|
+
onBeforeLeave,
|
|
57
|
+
onLeave,
|
|
58
|
+
onAfterLeave
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type {
|
|
3
|
-
|
|
1
|
+
import { type MaybeRef } from 'vue';
|
|
2
|
+
import type { Options } from '../types/index.js';
|
|
3
|
+
import type { MaybeElementRef } from '@vueuse/core';
|
|
4
|
+
export type useModalApiOptions = Pick<Options, 'scrollLock'> & {
|
|
4
5
|
focusTarget: MaybeElementRef;
|
|
5
6
|
};
|
|
6
7
|
export declare function useModalApi(id?: MaybeRef<string>, options?: useModalApiOptions): {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { ref, computed } from "vue";
|
|
1
|
+
import { ref, computed, toValue } from "vue";
|
|
2
|
+
import { defu } from "defu";
|
|
2
3
|
import { v4 as uuidv4 } from "uuid";
|
|
3
|
-
import {
|
|
4
|
+
import { useScrollLock } from "@vueuse/core";
|
|
4
5
|
import { useFocusTrap } from "@vueuse/integrations/useFocusTrap";
|
|
5
|
-
import { useModalStore } from "./useModalStore.mjs";
|
|
6
|
+
import { useModalStore } from "./private/useModalStore.mjs";
|
|
6
7
|
const defaultOptions = {
|
|
7
8
|
focusTarget: void 0,
|
|
8
9
|
scrollLock: true
|
|
@@ -10,7 +11,7 @@ const defaultOptions = {
|
|
|
10
11
|
export function useModalApi(id, options) {
|
|
11
12
|
const positionFixedElements = ref([]);
|
|
12
13
|
const mappedId = computed(() => toValue(id) || uuidv4());
|
|
13
|
-
const mappedOptions =
|
|
14
|
+
const mappedOptions = defu(options, defaultOptions);
|
|
14
15
|
const focusTrap = mappedOptions.focusTarget ? useFocusTrap(mappedOptions.focusTarget) : void 0;
|
|
15
16
|
const scrollLock = mappedOptions.scrollLock && typeof window !== "undefined" ? useScrollLock(document.body) : ref(false);
|
|
16
17
|
const { modalStore, addIdToStore, removeIdFromStore } = useModalStore();
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
type
|
|
1
|
+
type Options = {
|
|
2
2
|
backdrop?: boolean;
|
|
3
3
|
focusTrap?: boolean;
|
|
4
4
|
scrollLock?: boolean;
|
|
5
5
|
scrollLockPadding?: boolean;
|
|
6
6
|
teleport?: {
|
|
7
|
-
target
|
|
7
|
+
target?: string;
|
|
8
8
|
disabled?: boolean;
|
|
9
9
|
};
|
|
10
10
|
transitions?: {
|
|
@@ -13,9 +13,11 @@ type DefaultOptions = {
|
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
15
|
type ModalEvents = {
|
|
16
|
-
afterEnter: string;
|
|
17
|
-
afterLeave: string;
|
|
18
16
|
beforeEnter: string;
|
|
17
|
+
enter: string;
|
|
18
|
+
afterEnter: string;
|
|
19
19
|
beforeLeave: string;
|
|
20
|
+
leave: string;
|
|
21
|
+
afterLeave: string;
|
|
20
22
|
};
|
|
21
|
-
export type {
|
|
23
|
+
export type { Options, ModalEvents };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
declare const defaultOptions:
|
|
1
|
+
import type { Options } from '../types/index.js';
|
|
2
|
+
declare const defaultOptions: Options;
|
|
3
3
|
export { defaultOptions };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ref, watch, unref } from "vue";
|
|
2
|
-
import { useEventListener,
|
|
1
|
+
import { ref, watch, unref, toValue } from "vue";
|
|
2
|
+
import { useEventListener, watchIgnorable } from "@vueuse/core";
|
|
3
3
|
export function useMediaApi(target) {
|
|
4
4
|
const currentTime = ref(0);
|
|
5
5
|
const duration = ref(0);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCollisionEmitter } from './src/composables/useCollisionEmitter.js';
|
|
2
|
-
import {
|
|
2
|
+
import { useScrollApi } from './src/composables/useScrollApi.js';
|
|
3
3
|
import { useCollisionDetect } from './src/composables/useCollisionDetect.js';
|
|
4
4
|
import type { Plugin } from 'vue';
|
|
5
5
|
export type * from './src/types';
|
|
6
6
|
declare const MagicScroll: Plugin;
|
|
7
|
-
export { MagicScroll, useCollisionEmitter,
|
|
7
|
+
export { MagicScroll, useCollisionEmitter, useScrollApi, useCollisionDetect };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import MagicScrollProvider from "./src/components/MagicScrollProvider.vue";
|
|
2
2
|
import MagicScrollScene from "./src/components/MagicScrollScene.vue";
|
|
3
3
|
import MagicScrollTransform from "./src/components/MagicScrollTransform.vue";
|
|
4
|
+
import MagicScrollMotion from "./src/components/MagicScrollMotion.vue";
|
|
4
5
|
import MagicScrollCollision from "./src/components/MagicScrollCollision.vue";
|
|
5
6
|
import { magicScrollStore } from "./src/store/index.mjs";
|
|
6
7
|
import { useCollisionEmitter } from "./src/composables/useCollisionEmitter.mjs";
|
|
7
|
-
import {
|
|
8
|
+
import { useScrollApi } from "./src/composables/useScrollApi.mjs";
|
|
8
9
|
import { useCollisionDetect } from "./src/composables/useCollisionDetect.mjs";
|
|
9
10
|
import { StoreKey } from "./src/types/index.mjs";
|
|
10
11
|
const MagicScroll = {
|
|
@@ -12,8 +13,9 @@ const MagicScroll = {
|
|
|
12
13
|
app.component("MagicScrollProvider", MagicScrollProvider);
|
|
13
14
|
app.component("MagicScrollScene", MagicScrollScene);
|
|
14
15
|
app.component("MagicScrollTransform", MagicScrollTransform);
|
|
16
|
+
app.component("MagicScrollMotion", MagicScrollMotion);
|
|
15
17
|
app.component("MagicScrollCollision", MagicScrollCollision);
|
|
16
18
|
app.provide(StoreKey, magicScrollStore);
|
|
17
19
|
}
|
|
18
20
|
};
|
|
19
|
-
export { MagicScroll, useCollisionEmitter,
|
|
21
|
+
export { MagicScroll, useCollisionEmitter, useScrollApi, useCollisionDetect };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div ref="el" class="m-scroll-motion">
|
|
3
|
+
<slot />
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
import { ref, inject, computed, onMounted, toRaw, watch } from 'vue'
|
|
9
|
+
import { animate, type Easing } from 'motion'
|
|
10
|
+
import { ScrollProgressKey } from '../types'
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
keyframes: Record<string, any> | null | undefined
|
|
14
|
+
offset?: number[] | undefined
|
|
15
|
+
easing?: Easing
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
19
|
+
keyframes: undefined,
|
|
20
|
+
offset: undefined,
|
|
21
|
+
easing: 'linear',
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const animation = ref()
|
|
25
|
+
const el = ref()
|
|
26
|
+
|
|
27
|
+
const progress = inject(
|
|
28
|
+
ScrollProgressKey,
|
|
29
|
+
computed(() => 0),
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
function createAnimation(currentTime: number = 0) {
|
|
33
|
+
if (!props.keyframes) return
|
|
34
|
+
animation.value = animate(toRaw(el.value), props.keyframes, {
|
|
35
|
+
duration: 1,
|
|
36
|
+
easing: props.easing || 'linear',
|
|
37
|
+
offset: props.offset,
|
|
38
|
+
})
|
|
39
|
+
animation.value.stop()
|
|
40
|
+
animation.value.currentTime = currentTime
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
onMounted(() => {
|
|
44
|
+
createAnimation()
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
watch(progress, (value) => {
|
|
48
|
+
if (!animation.value || !props.keyframes) return
|
|
49
|
+
animation.value.currentTime = value
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
watch(
|
|
53
|
+
() => props.keyframes,
|
|
54
|
+
() => {
|
|
55
|
+
createAnimation(progress.value)
|
|
56
|
+
},
|
|
57
|
+
)
|
|
58
|
+
</script>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Easing } from 'motion';
|
|
2
|
+
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
3
|
+
offset: {
|
|
4
|
+
type: import("vue").PropType<number[]>;
|
|
5
|
+
default: undefined;
|
|
6
|
+
};
|
|
7
|
+
keyframes: {
|
|
8
|
+
type: import("vue").PropType<Record<string, any> | null | undefined>;
|
|
9
|
+
required: true;
|
|
10
|
+
default: undefined;
|
|
11
|
+
};
|
|
12
|
+
easing: {
|
|
13
|
+
type: import("vue").PropType<Easing>;
|
|
14
|
+
default: string;
|
|
15
|
+
};
|
|
16
|
+
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
17
|
+
offset: {
|
|
18
|
+
type: import("vue").PropType<number[]>;
|
|
19
|
+
default: undefined;
|
|
20
|
+
};
|
|
21
|
+
keyframes: {
|
|
22
|
+
type: import("vue").PropType<Record<string, any> | null | undefined>;
|
|
23
|
+
required: true;
|
|
24
|
+
default: undefined;
|
|
25
|
+
};
|
|
26
|
+
easing: {
|
|
27
|
+
type: import("vue").PropType<Easing>;
|
|
28
|
+
default: string;
|
|
29
|
+
};
|
|
30
|
+
}>>, {
|
|
31
|
+
offset: number[];
|
|
32
|
+
keyframes: Record<string, any> | null | undefined;
|
|
33
|
+
easing: Easing;
|
|
34
|
+
}, {}>, {
|
|
35
|
+
default?(_: {}): any;
|
|
36
|
+
}>;
|
|
37
|
+
export default _default;
|
|
38
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
39
|
+
new (): {
|
|
40
|
+
$slots: S;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
} from 'vue'
|
|
18
18
|
import { useIntersectionObserver } from '@vueuse/core'
|
|
19
19
|
import { mapValue } from '../utils'
|
|
20
|
-
import {
|
|
20
|
+
import { useScrollApi } from '../composables/useScrollApi'
|
|
21
21
|
import { ScrollPositionKey, ScrollParentKey, ScrollProgressKey } from '../types'
|
|
22
22
|
|
|
23
23
|
import type { FromTo } from '../types'
|
|
@@ -38,7 +38,7 @@ const scrollParent = inject(ScrollParentKey)
|
|
|
38
38
|
const sceneRef = ref<HTMLElement | undefined>(undefined)
|
|
39
39
|
const progress = ref(0)
|
|
40
40
|
|
|
41
|
-
const { getCalculations, getProgress } =
|
|
41
|
+
const { getCalculations, getProgress } = useScrollApi({
|
|
42
42
|
child: sceneRef,
|
|
43
43
|
parent: scrollParent,
|
|
44
44
|
from: props.from,
|
|
@@ -3,10 +3,6 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
3
3
|
type: import("vue").PropType<number>;
|
|
4
4
|
default: number;
|
|
5
5
|
};
|
|
6
|
-
as: {
|
|
7
|
-
type: import("vue").PropType<string>;
|
|
8
|
-
default: string;
|
|
9
|
-
};
|
|
10
6
|
scaleX: {
|
|
11
7
|
type: import("vue").PropType<number>;
|
|
12
8
|
default: number;
|
|
@@ -23,6 +19,10 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
23
19
|
type: import("vue").PropType<number>;
|
|
24
20
|
default: number;
|
|
25
21
|
};
|
|
22
|
+
as: {
|
|
23
|
+
type: import("vue").PropType<string>;
|
|
24
|
+
default: string;
|
|
25
|
+
};
|
|
26
26
|
translateX: {
|
|
27
27
|
type: import("vue").PropType<number>;
|
|
28
28
|
default: number;
|
|
@@ -36,10 +36,6 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
36
36
|
type: import("vue").PropType<number>;
|
|
37
37
|
default: number;
|
|
38
38
|
};
|
|
39
|
-
as: {
|
|
40
|
-
type: import("vue").PropType<string>;
|
|
41
|
-
default: string;
|
|
42
|
-
};
|
|
43
39
|
scaleX: {
|
|
44
40
|
type: import("vue").PropType<number>;
|
|
45
41
|
default: number;
|
|
@@ -56,6 +52,10 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
56
52
|
type: import("vue").PropType<number>;
|
|
57
53
|
default: number;
|
|
58
54
|
};
|
|
55
|
+
as: {
|
|
56
|
+
type: import("vue").PropType<string>;
|
|
57
|
+
default: string;
|
|
58
|
+
};
|
|
59
59
|
translateX: {
|
|
60
60
|
type: import("vue").PropType<number>;
|
|
61
61
|
default: number;
|
|
@@ -66,11 +66,11 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
66
66
|
};
|
|
67
67
|
}>>, {
|
|
68
68
|
scale: number;
|
|
69
|
-
as: string;
|
|
70
69
|
scaleX: number;
|
|
71
70
|
scaleY: number;
|
|
72
71
|
skewX: number;
|
|
73
72
|
skewY: number;
|
|
73
|
+
as: string;
|
|
74
74
|
translateX: number;
|
|
75
75
|
translateY: number;
|
|
76
76
|
}, {}>, {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type MaybeRef, type MaybeRefOrGetter } from 'vue';
|
|
2
2
|
import type { FromTo } from '../types.js';
|
|
3
|
-
type
|
|
3
|
+
type UseScrollApiParams = {
|
|
4
4
|
child: MaybeRef<HTMLElement | null | undefined>;
|
|
5
5
|
parent: MaybeRefOrGetter<HTMLElement | null | undefined>;
|
|
6
6
|
from: FromTo;
|
|
7
7
|
to: FromTo;
|
|
8
8
|
};
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function useScrollApi(params: UseScrollApiParams): {
|
|
10
10
|
getCalculations: () => void;
|
|
11
11
|
getProgress: () => number;
|
|
12
12
|
};
|
|
13
|
-
export type
|
|
13
|
+
export type UseScrollApiReturn = ReturnType<typeof useScrollApi>;
|
|
14
14
|
export {};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { ref, inject } from "vue";
|
|
1
|
+
import { ref, inject, toValue } from "vue";
|
|
2
2
|
import { useElementBounding, useWindowSize } from "@vueuse/core";
|
|
3
|
-
import { toValue } from "@vueuse/core";
|
|
4
3
|
import { ScrollPositionKey } from "../types/index.mjs";
|
|
5
4
|
import { clampValue } from "../utils/index.mjs";
|
|
6
|
-
export function
|
|
5
|
+
export function useScrollApi(params) {
|
|
7
6
|
const { child, parent, from, to } = params;
|
|
8
7
|
const scrollPosition = inject(ScrollPositionKey, void 0);
|
|
9
8
|
const childRect = ref();
|