/** * A single compiled-and-instantiated `vectojs_core.wasm` shared by every WASM * backend of one Scene. * * Before this, each of the four accelerators (transform, animation, hit-test, * particle) carried its own copy of the same three-way loader and instantiated * the binary independently. A Scene enabling all four therefore compiled the same * module up to four times and held four separate linear memories, plus four sets * of module-level static state. * * Nothing required that: the Rust crate already keeps the transform, anim, hit * and particle stores in distinct statics, so they do not alias inside one * instance. The separate instances bought isolation that was already there, and * paid for it in compile time and memory. * * Two levels of sharing: * * - The compiled {@link WebAssembly.Module} is cached **globally** per source, so * a second Scene (or a re-enable after `destroy()`) skips compilation. * - The {@link WebAssembly.Instance} is created **per runtime**, so two Scenes * never share mutable stores. That isolation is the part that matters. * * Backends stay independently gated: holding a runtime does not mean every * accelerator is active. Each `enableWasm*` still decides whether its workload * clears its own threshold. */ import { WasmTransformBackend } from './backend'; import { AnimBackend } from './anim-backend'; import { HitTestBackend } from './hit-backend'; import { ParticleBackend } from './particle-backend'; /** Anything a core module can be loaded from. Matches the per-backend loaders. */ export type CoreModuleSource = BufferSource | string | URL | Response | Promise; /** * Compile a core module, reusing the global cache when the source is a * URL or path. Returns `null` on any failure (CSP `wasm-unsafe-eval`, 404, * corrupt bytes, unsupported) so callers keep the JS path. */ export declare function loadCoreWasmModule(source: CoreModuleSource): Promise; /** * One instance of the core module, exposing every backend that instance can * serve. All four share its linear memory, which is why they must come from the * same instantiation rather than four independent ones. */ export declare class CoreWasmRuntime { readonly instance: WebAssembly.Instance; private transformBackend; private animBackend; private hitBackend; private particleBackendInstance; constructor(instance: WebAssembly.Instance); /** * Backends are constructed lazily and memoised: each one's constructor calls * into the instance to size its store and build typed-array views, so building * all four up front would pay for accelerators the Scene never enables. */ transform(): WasmTransformBackend; anim(): AnimBackend; hit(): HitTestBackend; particle(): ParticleBackend; } /** * Instantiate a runtime from an already-compiled module. Separated from * {@link loadCoreWasmModule} so several Scenes can share one compile while each * keeps its own mutable stores. */ export declare function createCoreWasmRuntime(module: WebAssembly.Module): CoreWasmRuntime | null; /** * Compile (or reuse) and instantiate in one step. Returns `null` on any failure * so the caller keeps the JS path. */ export declare function loadCoreWasmRuntime(source: CoreModuleSource): Promise; /** * Drop the global compiled-module cache. For tests that need to observe a fresh * compile, and for apps that want to release the memory after teardown. */ export declare function clearCoreWasmModuleCache(): void;