|
1 | 1 | import { useState } from "#app"; |
2 | | -import { computed, reactive } from "#imports"; |
3 | | -import { ref, readonly } from "vue"; |
| 2 | +import { computed } from "#imports"; |
| 3 | + |
| 4 | +var lenisVS: Array<Object | Function> = []; |
4 | 5 |
|
5 | | -const lenisVS: Object = {}; |
6 | | -// const scrollState: Object = {}; |
7 | | -const ids: Array<Number> = []; |
8 | 6 | export function useLenis(single: Boolean = true): Object { |
9 | 7 | const scrollState = useState("scrollState", () => []); |
| 8 | + // const lenisVS = useState("lenisVS", () => []); |
| 9 | + const ids = useState("ids", () => []); |
10 | 10 |
|
11 | 11 | const setScrollState = (newScrollState: Object, id: String | Number) => { |
12 | | - // NOTE: This is a workaround because of how useState can't handle classes |
13 | | - scrollState.value[id] = Object.assign( |
14 | | - {}, |
15 | | - { |
16 | | - className: newScrollState?.className, |
17 | | - isHorizontal: newScrollState?.isHorizontal, |
18 | | - isLocked: newScrollState?.isLocked, |
19 | | - isScrolling: newScrollState?.isScrolling, |
20 | | - isSmooth: newScrollState?.isSmooth, |
21 | | - isStopped: newScrollState?.isStopped, |
22 | | - limit: newScrollState?.limit, |
23 | | - progress: newScrollState?.progress, |
24 | | - rootElement: newScrollState?.rootElement, |
25 | | - scroll: newScrollState?.scroll, |
26 | | - direction: newScrollState?.direction, |
27 | | - time: newScrollState?.time, |
28 | | - animatedScroll: newScrollState?.animatedScroll, |
29 | | - velocity: newScrollState?.velocity, |
30 | | - lastVelocity: newScrollState?.lastVelocity, |
31 | | - targetScroll: newScrollState?.targetScroll, |
32 | | - } |
33 | | - ); |
| 12 | + scrollState.value[id] = { |
| 13 | + className: newScrollState?.className, |
| 14 | + isHorizontal: newScrollState?.isHorizontal, |
| 15 | + isLocked: newScrollState?.isLocked, |
| 16 | + isScrolling: newScrollState?.isScrolling, |
| 17 | + isSmooth: newScrollState?.isSmooth, |
| 18 | + isStopped: newScrollState?.isStopped, |
| 19 | + limit: newScrollState?.limit, |
| 20 | + progress: newScrollState?.progress, |
| 21 | + rootElement: newScrollState?.rootElement, |
| 22 | + scroll: newScrollState?.scroll, |
| 23 | + direction: newScrollState?.direction, |
| 24 | + time: newScrollState?.time, |
| 25 | + animatedScroll: newScrollState?.animatedScroll, |
| 26 | + velocity: newScrollState?.velocity, |
| 27 | + lastVelocity: newScrollState?.lastVelocity, |
| 28 | + targetScroll: newScrollState?.targetScroll, |
| 29 | + }; |
34 | 30 | }; |
35 | 31 | const setLenis = (virtualScroll: Object, id: String | Number) => { |
36 | 32 | lenisVS[id] = virtualScroll; |
37 | | - ids.push(id); |
| 33 | + ids.value.push(id); |
38 | 34 | }; |
39 | | - |
40 | 35 | const getScrollState = computed(() => { |
41 | | - return single ? scrollState.value[ids[0]] : scrollState.value; |
| 36 | + return single ? scrollState.value[ids.value[0]] : scrollState.value; |
42 | 37 | }); |
43 | | - |
44 | 38 | const getLenis = computed(() => { |
45 | | - return single ? lenisVS[ids[0]] : lenisVS; |
| 39 | + return single ? lenisVS[ids.value[0]] : lenisVS; |
46 | 40 | }); |
47 | | - |
48 | | - const getLenisInstance = (id) => { |
49 | | - if (!id) return "no id provided"; |
50 | | - return lenisVS[id]; |
51 | | - }; |
52 | | - |
53 | 41 | return { |
54 | | - scrollState: getScrollState, |
55 | | - lenis: getLenis.value, |
56 | | - lenisInstance: getLenisInstance, |
| 42 | + scrollState: single ? getScrollState : getScrollState.value, |
| 43 | + lenis: single ? getLenis : getLenis.value, |
57 | 44 | setScrollState, |
58 | 45 | setLenis, |
59 | 46 | }; |
|
0 commit comments