33 lines
689 B
TypeScript
33 lines
689 B
TypeScript
|
|
import Lenis from 'lenis';
|
||
|
|
import {
|
||
|
|
getContext,
|
||
|
|
setContext,
|
||
|
|
} from 'svelte';
|
||
|
|
|
||
|
|
const LENIS_KEY = Symbol('lenis');
|
||
|
|
|
||
|
|
export function createLenisContext() {
|
||
|
|
let lenis = $state<Lenis | null>(null);
|
||
|
|
|
||
|
|
return {
|
||
|
|
get lenis() {
|
||
|
|
return lenis;
|
||
|
|
},
|
||
|
|
setLenis(instance: Lenis) {
|
||
|
|
lenis = instance;
|
||
|
|
},
|
||
|
|
destroyLenis() {
|
||
|
|
lenis?.destroy();
|
||
|
|
lenis = null;
|
||
|
|
},
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
export function setLenisContext(context: ReturnType<typeof createLenisContext>) {
|
||
|
|
setContext(LENIS_KEY, context);
|
||
|
|
}
|
||
|
|
|
||
|
|
export function getLenisContext() {
|
||
|
|
return getContext<ReturnType<typeof createLenisContext>>(LENIS_KEY);
|
||
|
|
}
|