import { type Frame, type Texture } from "vgpu"; import type { ShaderName, ShaderParams } from "./registry.js"; import type { Stage } from "./stage.js"; /** Anything the browser can copy straight into a texture. */ export type ShaderSourceImage = ImageBitmap | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas; /** Another shadertown shader, rendered offscreen and used as the layer below. */ export interface ShaderSourceLayer { readonly shader: ShaderName; readonly params?: ShaderParams; } /** * A line of text, rendered once to an offscreen canvas and read as a layer. * * This is what makes text a first-class source: `source={{ text: "OPEN" }}` * hands a source shader something to bend into a sign, dissolve into glyphs * or melt, with no canvas plumbing on the caller's side. Newlines break * lines; everything else is one CSS font string. */ export interface ShaderSourceText { readonly text: string; /** A CSS font shorthand. The default is a heavy system sans at 256px. */ readonly font?: string; readonly color?: string; readonly background?: string; } /** * An SVG, rasterised once at a size you choose and read as a layer. * * A browser will decode an SVG straight into a bitmap, but only at the size * the file declares, only when it declares one, and not in every browser. * Drawing it through an `` onto a canvas sidesteps all three, and lets * the layer be as sharp as the canvas it lands on. By default every opaque * pixel is filled with one colour, so a coloured logo arrives as the bright * silhouette the text source also produces — which is what a shader that * traces, measures or outlines the ink expects. */ export interface ShaderSourceSvg { /** SVG markup, or the URL of an `.svg` file. Markup starts with `<`. */ readonly svg: string; /** Pixel width of the rendered drawing. The height follows the viewBox. Default 1024. */ readonly width?: number; /** * The colour every opaque pixel is filled with. Default white; `null` keeps * the drawing's own colours. */ readonly color?: string | null; readonly background?: string; } /** * What a source shader reads. * * A URL is fetched, an image-like is uploaded once, and a `{ shader }` is * rendered every frame into an offscreen target — which is how a source shader * stacks on top of a generative one. */ export type ShaderSourceInput = string | ShaderSourceImage | ShaderSourceLayer | ShaderSourceText | ShaderSourceSvg; /** The uniform block the source prelude declares. */ export interface SourceUniforms { size: [number, number]; fit: number; } export declare function isSourceLayer(input: ShaderSourceInput): input is ShaderSourceLayer; export declare function isSourceText(input: ShaderSourceInput): input is ShaderSourceText; export declare function isSourceSvg(input: ShaderSourceInput): input is ShaderSourceSvg; /** A 2D canvas the GPU can copy from, offscreen where the browser has one. */ export declare function blankCanvas(width: number, height: number): OffscreenCanvas | HTMLCanvasElement; /** * The bound layer, whichever form it came in. * * `size` and `fit` travel with the texture because the shader needs them to fit * a source of one shape onto a canvas of another. */ export interface SourceLayer { readonly texture: Texture; readonly size: [number, number]; /** 0 stretches to the canvas, 1 covers it and crops. */ readonly fit: number; /** Called when the texture object itself is replaced, not just its contents. */ onRecreate(cb: () => void): () => void; /** Draws whatever has to exist before the main pass reads this layer. */ prepare(frame: Frame, deltaTime: number): void; resize(width: number, height: number): void; destroy(): void; } /** Linear and clamped: a source shader reads between texels and off the edge. */ export declare function sourceSampler(stage: Stage): GPUSampler; /** * Builds the layer a source shader reads. * * `startTime` only matters for a shader backdrop: it keeps a stacked pair in * step with the grid offset the card was given. */ export declare function createSourceLayer(stage: Stage, input: ShaderSourceInput, canvas: { width: number; height: number; startTime: number; }): Promise; /** An image-like uploaded once into a texture of its own size. */ export declare function createImageTexture(stage: Stage, image: ShaderSourceImage, label: string): Texture; //# sourceMappingURL=source.d.ts.map