@motion-core/motion-gpu
Version:
Framework-agnostic WebGPU runtime for fullscreen WGSL shaders with explicit Svelte, React, and Vue adapter entrypoints.
38 lines (37 loc) • 1.47 kB
JavaScript
import { createFrameRegistry } from "../core/frame-registry.js";
import { getCurrentInstance, inject, onBeforeUnmount, provide } from "vue";
//#region src/lib/vue/frame-context.ts
/**
* Vue injection key used to expose the active frame registry.
*/
var frameRegistryKey = Symbol("motiongpu.frame-registry");
/**
* Provides a frame registry through Vue provide/inject.
*
* @param registry - Frame registry instance to provide to descendants.
*/
function provideFrameRegistry(registry) {
provide(frameRegistryKey, registry);
}
/**
* Registers a callback in the active frame registry and auto-unsubscribes
* when the owning component is unmounted.
*
* @throws {Error} When called outside `<FragCanvas>`.
* @throws {Error} When the callback is missing.
*/
function useFrame(keyOrCallback, callbackOrOptions, maybeOptions) {
const registry = inject(frameRegistryKey, null);
if (!registry) throw new Error("useFrame must be used inside <FragCanvas>");
const registration = typeof keyOrCallback === "function" ? registry.register(keyOrCallback, callbackOrOptions) : registry.register(keyOrCallback, callbackOrOptions, maybeOptions);
if (getCurrentInstance()) onBeforeUnmount(registration.unsubscribe);
return {
task: registration.task,
start: registration.start,
stop: registration.stop,
started: registration.started
};
}
//#endregion
export { createFrameRegistry, frameRegistryKey, provideFrameRegistry, useFrame };
//# sourceMappingURL=frame-context.js.map