import type { AddTransitionOpts, Transition, TransitionClass, TransitionHandle } from "./transition/types.js"; import { type Effect, type VFXOpts, type VFXProps } from "./types.js"; /** * The main interface of VFX-JS. */ export declare class VFX { #private; /** * Create a VFX instance if WebGL is available, or return `null`. */ static init(options?: VFXOpts): VFX | null; /** * Creates VFX instance and start playing immediately. * When the user prefers reduced motion, it renders nothing: * elements stay plain HTML and transitions cut to the new content. * @throws When WebGL is not available in the current environment. */ constructor(options?: VFXOpts); /** * Register an element to track the position and render visual effects in the area. */ add(element: HTMLElement, opts: VFXProps, initialCapture?: OffscreenCanvas): Promise; /** * Update the HIC texture for an html-in-canvas wrapper canvas. * @internal Used by VFXCanvas (@vfx-js/react). */ updateHICTexture(canvas: HTMLCanvasElement, offscreen: OffscreenCanvas): void; /** * True when the user prefers reduced motion, checked once at creation. * @internal Used by transitions. */ get reducedMotion(): boolean; get maxTextureSize(): number; /** The output canvas VFX renders into. */ get canvas(): HTMLCanvasElement; /** * Register an element using html-in-canvas API. * Wraps the element in a `` and captures via drawElementImage. * Falls back to `add()` if html-in-canvas is not supported. */ addHTML(element: HTMLElement, opts: VFXProps): Promise; /** * Like `addHTML`, and a still copy covers the frame before the first capture. * @internal Used by transitions. */ addHTMLWithStill(element: HTMLElement, opts: VFXProps): Promise; /** * Animate an element from its old content to its new content with a * shader. The element is wrapped only while a run is in flight, * unless `keepWrapped` is set. * * ```ts * const t = vfx.addTransition(main, { duration: 0.6 }); * await t.run(() => renderNextPage()); * ``` */ addTransition(element: HTMLElement, opts?: AddTransitionOpts): TransitionHandle; /** * Stop rendering VFX elements inside `root` and show their plain * content. Returns a function that undoes it. * @internal Used by transitions. */ freezeInside(root: HTMLElement): () => void; /** * Pin the size of the element's html-in-canvas wrapper. * Returns a function that undoes it. No-op for other elements. * @internal Used by transitions. */ lockSize(element: HTMLElement): () => void; /** * Keep rendering the element while it is off screen. * Returns a function that undoes it. * @internal Used by transitions. */ forceRender(element: HTMLElement): () => void; /** * Remove the element from VFX and stop rendering the shader. */ remove(element: HTMLElement): void; /** * Replace the effect chain on an already-registered effect-path * element in-place. Effects whose reference is unchanged keep their * init state and GPU resources; only added/removed effects run * `init` / `dispose`. The element's source texture is preserved. * * Useful for live UIs that reorder or toggle effects without paying * the cost of `vfx.remove` + `vfx.add` (which reloads the source). */ updateEffects(element: HTMLElement, effect: Effect | readonly Effect[]): Promise; /** * Update the texture for the given element. * * For an `HTMLImageElement`, reloads its currently selected image URL * — call this after changing `img.src` or when responsive image * selection changes. Videos refresh automatically (no-op). * Otherwise re-snapshots the element's DOM subtree. * For html-in-canvas elements, resolves once the new capture is in * the texture, or after a short timeout. * * Useful for elements whose contents change (input, textarea, or an * `` whose selected source swaps). */ update(element: HTMLElement): Promise; /** * Like `update`, and resolves to false when an html-in-canvas capture timed out. * @internal Used by transitions. */ updateInTime(element: HTMLElement): Promise; /** * Start rendering VFX. */ play(): void; /** * Stop rendering VFX. * You can restart rendering by calling `VFX.play()` later. */ stop(): void; /** * Render the whole scene once, manually. * This is useful when you want to control the rendering timings manually by combining with `autoplay: false`. */ render(): void; /** * Current virtual animation time in seconds (the value behind the * `time` uniform). */ get time(): number; /** * Pin the animation clock to an absolute time in seconds. * * The next `render()` uses the value verbatim, so `setTime(t); render()` * produces a deterministic frame — handy for scrubbing a timeline or * capturing stable snapshots (e.g. visual regression tests): * * ```ts * const vfx = new VFX({ autoplay: false }); * await vfx.add(img, { effect }); * vfx.setTime(1.5); * vfx.render(); * ``` * * Note: this drives `deltaTime` too, so a jump produces one large * `deltaTime` on the next frame. Time-only effects are unaffected, but * effects that integrate motion over `deltaTime` (particles, fluid, * datamosh) may jump — pause first (`timeScale = 0`) when scrubbing them. */ setTime(time: number): void; /** * Playback rate of the animation clock. * * `1` is realtime, `0` pauses (frames still render), and negative * values run time backwards. Can be changed at any time. * * Note: `deltaTime` follows this rate, so it goes negative while * rewinding. Time-only effects handle that fine; effects that integrate * motion over `deltaTime` (particles, fluid, datamosh) are not designed * to run backwards and may behave unexpectedly. */ get timeScale(): number; set timeScale(scale: number); /** * Destroy VFX and stop rendering. */ destroy(): void; }