UNPKG

@motion-core/motion-gpu

Version:

Framework-agnostic WebGPU runtime for fullscreen WGSL shaders with explicit Svelte, React, and Vue adapter entrypoints.

34 lines (33 loc) 1.05 kB
import { createPointerController } from "../core/pointer.js"; import { useMotionGPU } from "./motiongpu-context.js"; import { onBeforeUnmount, onMounted, watchEffect } from "vue"; //#region src/lib/vue/use-pointer.ts function resolveOptions(source) { return typeof source === "function" ? source() : source; } /** * Tracks normalized pointer coordinates and click/tap snapshots for the active `FragCanvas`. */ function usePointer(options = {}) { const motiongpu = useMotionGPU(); const controller = createPointerController({ getRenderMode: () => motiongpu.renderMode.current, invalidate: motiongpu.invalidate, advance: motiongpu.advance }, resolveOptions(options)); const stopOptionsWatch = watchEffect(() => { controller.updateOptions(resolveOptions(options)); }); onMounted(() => { const canvas = motiongpu.canvas; if (canvas) controller.mount(canvas); }); onBeforeUnmount(() => { stopOptionsWatch(); controller.destroy(); }); return controller; } //#endregion export { usePointer }; //# sourceMappingURL=use-pointer.js.map