@motion-core/motion-gpu
Version:
Framework-agnostic WebGPU runtime for fullscreen WGSL shaders with explicit Svelte, React, and Vue adapter entrypoints.
32 lines (31 loc) • 1.19 kB
JavaScript
import { createFrameRegistry } from "../core/frame-registry.js";
import { getContext, onDestroy, setContext } from "svelte";
//#region src/lib/svelte/frame-context.ts
/**
* Svelte context key for the active frame registry.
*/
var FRAME_CONTEXT_KEY = Symbol("motiongpu.frame-context");
/**
* Provides a frame registry through Svelte context.
*/
function provideFrameRegistry(registry) {
setContext(FRAME_CONTEXT_KEY, registry);
}
/**
* Registers a callback in the active frame registry and auto-unsubscribes on destroy.
*/
function useFrame(keyOrCallback, callbackOrOptions, maybeOptions) {
const registry = getContext(FRAME_CONTEXT_KEY);
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);
onDestroy(registration.unsubscribe);
return {
task: registration.task,
start: registration.start,
stop: registration.stop,
started: registration.started
};
}
//#endregion
export { createFrameRegistry, provideFrameRegistry, useFrame };
//# sourceMappingURL=frame-context.js.map