feat(utils.ts): add loadGsap and loadSwiper function to asynchronously load library

This commit is contained in:
Sped0n
2023-11-03 08:58:10 +08:00
parent 98f2012e9d
commit 7df382ee1f

View File

@@ -1,3 +1,6 @@
import { type Power3, type gsap } from 'gsap'
import { type Swiper } from 'swiper'
/**
* custom helpers
*/
@@ -36,6 +39,16 @@ export function onVisible<T extends Element>(
}).observe(element)
}
export async function loadGsap(): Promise<[typeof gsap, typeof Power3]> {
const g = await import('gsap')
return [g.gsap, g.Power3]
}
export async function loadSwiper(): Promise<typeof Swiper> {
const s = await import('swiper')
return s.Swiper
}
/**
* custom types
*/