@maas/vue-equipment 0.3.1 → 0.4.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/dist/nuxt/module.json +1 -1
- package/dist/plugins/MagicModal/src/components/MagicModal.vue +0 -5
- package/dist/plugins/MagicScroll/src/components/MagicScrollCollision.vue +4 -6
- package/dist/plugins/MagicScroll/src/components/MagicScrollProvider.vue +19 -18
- package/dist/plugins/MagicScroll/src/components/MagicScrollProvider.vue.d.ts +9 -3
- package/dist/plugins/MagicScroll/src/components/MagicScrollScene.vue +12 -12
- package/dist/plugins/MagicScroll/src/composables/useCollisionDetect.d.ts +2 -2
- package/dist/plugins/MagicScroll/src/composables/useCollisionDetect.mjs +5 -4
- package/dist/plugins/MagicScroll/src/composables/useProgress.d.ts +9 -2
- package/dist/plugins/MagicScroll/src/composables/useProgress.mjs +33 -19
- package/dist/plugins/MagicScroll/src/types/index.d.ts +4 -4
- package/dist/plugins/MagicScroll/src/types/injectionKeys.d.ts +21 -7
- package/dist/plugins/MagicScroll/src/types/injectionKeys.mjs +3 -3
- package/package.json +1 -1
- package/dist/plugins/MagicModal/src/composables/store/modals.d.ts +0 -4
- package/dist/plugins/MagicModal/src/composables/store/modals.mjs +0 -9
package/dist/nuxt/module.json
CHANGED
|
@@ -184,11 +184,6 @@ watch(isActive, async (value) => {
|
|
|
184
184
|
border: none;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
.magic-modal * {
|
|
188
|
-
transition-duration: 0s;
|
|
189
|
-
animation-duration: 0s;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
187
|
.magic-modal__content {
|
|
193
188
|
-webkit-overflow-scrolling: touch;
|
|
194
189
|
scroll-behavior: smooth;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { ref, inject, computed, onMounted } from 'vue'
|
|
9
9
|
import { toValue } from '@vueuse/shared'
|
|
10
10
|
import { useCollisionDetect } from '../composables/useCollisionDetect'
|
|
11
|
-
import {
|
|
11
|
+
import { ScrollPositionKey } from '../types'
|
|
12
12
|
|
|
13
13
|
import type { CollisionEntry } from '../types'
|
|
14
14
|
|
|
@@ -20,16 +20,14 @@ const props = defineProps<Props>()
|
|
|
20
20
|
const targetRef = ref<HTMLElement | undefined>(undefined)
|
|
21
21
|
const colDetect = ref()
|
|
22
22
|
|
|
23
|
-
const scrollPosition = inject(
|
|
24
|
-
const
|
|
25
|
-
const pageYOffset = computed(() => scrollPosition.y)
|
|
23
|
+
const scrollPosition = inject(ScrollPositionKey, undefined)
|
|
24
|
+
const pageYOffset = computed(() => toValue(scrollPosition?.y) || 0)
|
|
26
25
|
|
|
27
26
|
onMounted(() => {
|
|
28
27
|
colDetect.value = useCollisionDetect(
|
|
29
28
|
pageYOffset,
|
|
30
|
-
windowDimensions,
|
|
31
29
|
props.collisionEntries,
|
|
32
|
-
toValue(targetRef.value)
|
|
30
|
+
toValue(targetRef.value),
|
|
33
31
|
)
|
|
34
32
|
})
|
|
35
33
|
</script>
|
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div
|
|
2
|
+
<div class="magic-scroll-provider">
|
|
3
3
|
<slot />
|
|
4
4
|
</div>
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script setup lang="ts">
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { provide, computed } from 'vue'
|
|
9
|
+
import { useScroll } from '@vueuse/core'
|
|
10
|
+
import { ScrollPositionKey, ScrollParentKey } from '../types'
|
|
11
11
|
|
|
12
12
|
interface Props {
|
|
13
|
-
|
|
13
|
+
active?: Boolean
|
|
14
|
+
el?: HTMLElement
|
|
14
15
|
}
|
|
15
16
|
const props = withDefaults(defineProps<Props>(), {
|
|
16
|
-
|
|
17
|
+
active: () => true,
|
|
17
18
|
})
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const { width, height } = useWindowSize()
|
|
20
|
+
// computed is used to avoid reactivity issues
|
|
21
|
+
const mappedEl = computed(() => {
|
|
22
|
+
if (props.el) return props.el
|
|
23
|
+
return window
|
|
24
|
+
})
|
|
25
25
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
vh: toValue(height),
|
|
26
|
+
const mappedParent = computed(() => {
|
|
27
|
+
if (props.el) return props.el
|
|
28
|
+
return undefined
|
|
30
29
|
})
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
const scrollPosition = useScroll(mappedEl)
|
|
32
|
+
|
|
33
|
+
provide(ScrollPositionKey, scrollPosition)
|
|
34
|
+
provide(ScrollParentKey, mappedParent)
|
|
34
35
|
</script>
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
2
|
-
|
|
2
|
+
el: {
|
|
3
|
+
type: import("vue").PropType<HTMLElement>;
|
|
4
|
+
};
|
|
5
|
+
active: {
|
|
3
6
|
type: import("vue").PropType<Boolean>;
|
|
4
7
|
default: () => true;
|
|
5
8
|
};
|
|
6
9
|
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
7
|
-
|
|
10
|
+
el: {
|
|
11
|
+
type: import("vue").PropType<HTMLElement>;
|
|
12
|
+
};
|
|
13
|
+
active: {
|
|
8
14
|
type: import("vue").PropType<Boolean>;
|
|
9
15
|
default: () => true;
|
|
10
16
|
};
|
|
11
17
|
}>>, {
|
|
12
|
-
|
|
18
|
+
active: Boolean;
|
|
13
19
|
}, {}>, {
|
|
14
20
|
default?(_: {}): any;
|
|
15
21
|
}>;
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
ref,
|
|
10
10
|
provide,
|
|
11
11
|
inject,
|
|
12
|
-
computed,
|
|
13
12
|
onMounted,
|
|
14
13
|
watch,
|
|
15
14
|
nextTick,
|
|
@@ -19,7 +18,7 @@ import {
|
|
|
19
18
|
import { useIntersectionObserver } from '@vueuse/core'
|
|
20
19
|
import { mapValue } from '../utils'
|
|
21
20
|
import { useProgress } from '../composables/useProgress'
|
|
22
|
-
import {
|
|
21
|
+
import { ScrollPositionKey, ScrollParentKey, ScrollProgressKey } from '../types'
|
|
23
22
|
|
|
24
23
|
import type { FromTo } from '../types'
|
|
25
24
|
|
|
@@ -33,17 +32,18 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
33
32
|
to: 'bottom-top',
|
|
34
33
|
})
|
|
35
34
|
|
|
36
|
-
const scrollPosition = inject(
|
|
37
|
-
const
|
|
35
|
+
const scrollPosition = inject(ScrollPositionKey, undefined)
|
|
36
|
+
const scrollParent = inject(ScrollParentKey)
|
|
38
37
|
|
|
39
38
|
const sceneRef = ref<HTMLElement | undefined>(undefined)
|
|
40
39
|
const progress = ref(0)
|
|
41
40
|
|
|
42
|
-
const { getCalculations, getProgress } = useProgress(
|
|
43
|
-
sceneRef,
|
|
44
|
-
|
|
45
|
-
props.
|
|
46
|
-
|
|
41
|
+
const { getCalculations, getProgress } = useProgress({
|
|
42
|
+
child: sceneRef,
|
|
43
|
+
parent: scrollParent,
|
|
44
|
+
from: props.from,
|
|
45
|
+
to: props.to,
|
|
46
|
+
})
|
|
47
47
|
|
|
48
48
|
const calculate = () => {
|
|
49
49
|
getCalculations()
|
|
@@ -57,12 +57,12 @@ onMounted(() => {
|
|
|
57
57
|
})
|
|
58
58
|
|
|
59
59
|
watch(
|
|
60
|
-
() =>
|
|
60
|
+
() => scrollPosition?.y.value,
|
|
61
61
|
() => {
|
|
62
62
|
if (intersecting.value) {
|
|
63
63
|
calculate()
|
|
64
64
|
}
|
|
65
|
-
}
|
|
65
|
+
},
|
|
66
66
|
)
|
|
67
67
|
|
|
68
68
|
const intersecting = ref()
|
|
@@ -72,7 +72,7 @@ useIntersectionObserver(
|
|
|
72
72
|
([{ isIntersecting }]) => {
|
|
73
73
|
intersecting.value = isIntersecting
|
|
74
74
|
},
|
|
75
|
-
{ rootMargin: '150% 0px 150% 0px' }
|
|
75
|
+
{ rootMargin: '150% 0px 150% 0px' },
|
|
76
76
|
)
|
|
77
77
|
|
|
78
78
|
provide('mapValue', mapValue)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ComputedRef, Ref } from 'vue';
|
|
2
|
-
import type { CollisionEntry, CollisionMappedEntry
|
|
3
|
-
export declare function useCollisionDetect(pageYOffset: ComputedRef<number>,
|
|
2
|
+
import type { CollisionEntry, CollisionMappedEntry } from '../types.js';
|
|
3
|
+
export declare function useCollisionDetect(pageYOffset: ComputedRef<number>, collisionEntries: CollisionEntry[], parent: HTMLElement | undefined): {
|
|
4
4
|
collisionMappedEntries: Ref<CollisionMappedEntry[]>;
|
|
5
5
|
};
|
|
6
6
|
export type UseCollisionDetectReturn = ReturnType<typeof useCollisionDetect>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ref, watch, unref, computed } from "vue";
|
|
2
|
-
import { useIntersectionObserver } from "@vueuse/core";
|
|
2
|
+
import { useIntersectionObserver, useWindowSize } from "@vueuse/core";
|
|
3
3
|
import { useCollisionEmitter } from "./useCollisionEmitter.mjs";
|
|
4
|
-
export function useCollisionDetect(pageYOffset,
|
|
4
|
+
export function useCollisionDetect(pageYOffset, collisionEntries, parent) {
|
|
5
5
|
const scrolled = ref(0);
|
|
6
6
|
const intersecting = ref();
|
|
7
7
|
const scrollDirection = ref();
|
|
@@ -9,10 +9,11 @@ export function useCollisionDetect(pageYOffset, windowDimensions, collisionEntri
|
|
|
9
9
|
const oppositeScrollDirection = computed(
|
|
10
10
|
() => scrollDirection.value === "up" ? "down" : "up"
|
|
11
11
|
);
|
|
12
|
+
const windowDimensions = useWindowSize();
|
|
12
13
|
function getOffset(value) {
|
|
13
14
|
return typeof value === "function" ? value({
|
|
14
|
-
vh: unref(windowDimensions.
|
|
15
|
-
vw: unref(windowDimensions.
|
|
15
|
+
vh: unref(windowDimensions.height),
|
|
16
|
+
vw: unref(windowDimensions.width)
|
|
16
17
|
}) : value || 0;
|
|
17
18
|
}
|
|
18
19
|
function initialize() {
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import type { MaybeRef } from '@vueuse/shared';
|
|
1
|
+
import type { MaybeRef, MaybeRefOrGetter } from '@vueuse/shared';
|
|
2
2
|
import type { FromTo } from '../types.js';
|
|
3
|
-
|
|
3
|
+
type UseProgressParams = {
|
|
4
|
+
child: MaybeRef<HTMLElement | null | undefined>;
|
|
5
|
+
parent: MaybeRefOrGetter<HTMLElement | null | undefined>;
|
|
6
|
+
from: FromTo;
|
|
7
|
+
to: FromTo;
|
|
8
|
+
};
|
|
9
|
+
export declare function useProgress(params: UseProgressParams): {
|
|
4
10
|
getCalculations: () => void;
|
|
5
11
|
getProgress: () => number;
|
|
6
12
|
};
|
|
7
13
|
export type UseProgressReturn = ReturnType<typeof useProgress>;
|
|
14
|
+
export {};
|
|
@@ -1,58 +1,72 @@
|
|
|
1
1
|
import { ref, inject } from "vue";
|
|
2
|
+
import { useElementBounding, useWindowSize } from "@vueuse/core";
|
|
2
3
|
import { toValue } from "@vueuse/shared";
|
|
3
|
-
import {
|
|
4
|
+
import { ScrollPositionKey } from "../types/index.mjs";
|
|
4
5
|
import { clampValue } from "../utils/index.mjs";
|
|
5
|
-
export function useProgress(
|
|
6
|
-
const
|
|
7
|
-
const scrollPosition = inject(
|
|
8
|
-
const
|
|
6
|
+
export function useProgress(params) {
|
|
7
|
+
const { child, parent, from, to } = params;
|
|
8
|
+
const scrollPosition = inject(ScrollPositionKey, void 0);
|
|
9
|
+
const childRect = ref();
|
|
10
|
+
const parentRect = ref();
|
|
9
11
|
const start = ref(0);
|
|
10
12
|
const end = ref(0);
|
|
11
13
|
const splitLocation = (location) => {
|
|
12
14
|
return {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
child: location.match(/^[a-z]+/)[0],
|
|
16
|
+
parent: location.match(/[a-z]+$/)[0]
|
|
15
17
|
};
|
|
16
18
|
};
|
|
17
19
|
const getOffsetTop = (points) => {
|
|
18
20
|
let y = 0;
|
|
19
|
-
if (!
|
|
21
|
+
if (!childRect.value)
|
|
20
22
|
return y;
|
|
21
|
-
|
|
23
|
+
const scrollY = toValue(scrollPosition?.y) || 0;
|
|
24
|
+
if (parent)
|
|
25
|
+
console.log("scrollY:", scrollY);
|
|
26
|
+
switch (points.child) {
|
|
22
27
|
case "top":
|
|
23
|
-
y +=
|
|
28
|
+
y += childRect.value.top + scrollY;
|
|
24
29
|
break;
|
|
25
30
|
case "center":
|
|
26
|
-
y +=
|
|
31
|
+
y += childRect.value.top + childRect.value.height / 2 + scrollY;
|
|
27
32
|
break;
|
|
28
33
|
case "bottom":
|
|
29
|
-
y +=
|
|
34
|
+
y += childRect.value.top + childRect.value.height + scrollY;
|
|
30
35
|
break;
|
|
31
36
|
}
|
|
32
|
-
|
|
37
|
+
if (!parentRect.value)
|
|
38
|
+
return y;
|
|
39
|
+
const dimensions = {
|
|
40
|
+
width: toValue(parentRect.value.width),
|
|
41
|
+
height: toValue(parentRect.value.height),
|
|
42
|
+
top: toValue(parentRect.value.top)
|
|
43
|
+
};
|
|
44
|
+
switch (points.parent) {
|
|
33
45
|
case "top":
|
|
34
|
-
y -=
|
|
46
|
+
y -= dimensions.top;
|
|
35
47
|
break;
|
|
36
48
|
case "center":
|
|
37
|
-
y -= dimensions.
|
|
49
|
+
y -= dimensions.top + dimensions.height / 2;
|
|
38
50
|
break;
|
|
39
51
|
case "bottom":
|
|
40
|
-
y -= dimensions.
|
|
52
|
+
y -= dimensions.top + dimensions.height;
|
|
41
53
|
break;
|
|
42
54
|
case "initial":
|
|
43
|
-
y -=
|
|
55
|
+
y -= childRect.value.top + scrollY;
|
|
44
56
|
break;
|
|
45
57
|
}
|
|
46
58
|
return y;
|
|
47
59
|
};
|
|
48
60
|
const getCalculations = () => {
|
|
49
|
-
|
|
61
|
+
childRect.value = toValue(child)?.getBoundingClientRect();
|
|
62
|
+
parentRect.value = toValue(parent) ? useElementBounding(parent) : { ...useWindowSize(), top: 0 };
|
|
50
63
|
start.value = getOffsetTop(splitLocation(from));
|
|
51
64
|
end.value = getOffsetTop(splitLocation(to));
|
|
52
65
|
};
|
|
53
66
|
const getProgress = () => {
|
|
67
|
+
const scrollY = toValue(scrollPosition?.y) || 0;
|
|
54
68
|
const total = Math.abs(end.value - start.value);
|
|
55
|
-
const current =
|
|
69
|
+
const current = scrollY - start.value;
|
|
56
70
|
return clampValue(current / total, 0, 1);
|
|
57
71
|
};
|
|
58
72
|
return { getCalculations, getProgress };
|
|
@@ -25,10 +25,10 @@ interface CollisionMappedEntry extends Omit<CollisionEntry, 'element'> {
|
|
|
25
25
|
};
|
|
26
26
|
element: HTMLElement;
|
|
27
27
|
}
|
|
28
|
-
type
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
type Dimensions = {
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
31
|
};
|
|
32
32
|
type FromTo = 'top-top' | 'top-center' | 'top-bottom' | 'center-top' | 'center-center' | 'center-bottom' | 'bottom-top' | 'bottom-center' | 'bottom-bottom';
|
|
33
33
|
export * from './injectionKeys.js';
|
|
34
|
-
export type { FromTo, CollisionEvents, CollisionEntry, CollisionMappedEntry,
|
|
34
|
+
export type { FromTo, CollisionEvents, CollisionEntry, CollisionMappedEntry, Dimensions, };
|
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
import type { InjectionKey, Ref } from 'vue';
|
|
2
|
-
import type {
|
|
3
|
-
declare const
|
|
4
|
-
declare const
|
|
5
|
-
x: number
|
|
6
|
-
y: number
|
|
7
|
-
|
|
2
|
+
import type { MaybeRefOrGetter } from '@vueuse/shared';
|
|
3
|
+
declare const ScrollParentKey: InjectionKey<MaybeRefOrGetter<HTMLElement | undefined>>;
|
|
4
|
+
declare const ScrollPositionKey: InjectionKey<{
|
|
5
|
+
x: import("vue").WritableComputedRef<number>;
|
|
6
|
+
y: import("vue").WritableComputedRef<number>;
|
|
7
|
+
isScrolling: Ref<boolean>;
|
|
8
|
+
arrivedState: {
|
|
9
|
+
left: boolean;
|
|
10
|
+
right: boolean;
|
|
11
|
+
top: boolean;
|
|
12
|
+
bottom: boolean;
|
|
13
|
+
};
|
|
14
|
+
directions: {
|
|
15
|
+
left: boolean;
|
|
16
|
+
right: boolean;
|
|
17
|
+
top: boolean;
|
|
18
|
+
bottom: boolean;
|
|
19
|
+
};
|
|
20
|
+
measure(): void;
|
|
21
|
+
} | undefined>;
|
|
8
22
|
declare const ScrollProgressKey: InjectionKey<Ref<number>>;
|
|
9
23
|
declare const StoreKey: InjectionKey<{
|
|
10
24
|
isNavigating: boolean;
|
|
11
25
|
}>;
|
|
12
|
-
export {
|
|
26
|
+
export { ScrollParentKey, ScrollPositionKey, ScrollProgressKey, StoreKey };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const ScrollParentKey = Symbol();
|
|
2
|
+
const ScrollPositionKey = Symbol();
|
|
3
3
|
const ScrollProgressKey = Symbol();
|
|
4
4
|
const StoreKey = Symbol();
|
|
5
|
-
export {
|
|
5
|
+
export { ScrollParentKey, ScrollPositionKey, ScrollProgressKey, StoreKey };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maas/vue-equipment",
|
|
3
3
|
"description": "A magic collection of Vue composables, plugins, components and directives",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"author": "Robin Scholz <https://github.com/robinscholz>, Christoph Jeworutzki <https://github.com/ChristophJeworutzki>",
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@antfu/ni": "^0.21.5",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { shallowReactive } from "vue";
|
|
2
|
-
let modalsStore = shallowReactive([]);
|
|
3
|
-
function addIdToStore(id) {
|
|
4
|
-
modalsStore.push(id);
|
|
5
|
-
}
|
|
6
|
-
function removeIdFromStore(id) {
|
|
7
|
-
modalsStore = modalsStore.filter((x) => x !== id);
|
|
8
|
-
}
|
|
9
|
-
export { modalsStore, addIdToStore, removeIdFromStore };
|