import "@takumi-rs/helpers/renderer"; import { CacheKindStats, CacheMemoryStats, CacheMode, CacheMode as CacheMode$1, CacheOptions, CacheStats, ContainerNode, CssInput, FetchOptions, GenericFontFamily, ImageFetchCache, ImageNode, Node, Node as Node$1, NodeMetadata, RendererOptions, RgbaImage, TextNode } from "@takumi-rs/helpers"; import { Properties } from "csstype"; export type ByteBuf = Uint8Array | ArrayBuffer | Buffer; /** @deprecated Use a `{ keyframes, steps }` entry in `css` instead. Will be removed in v3. */ export type KeyframesMap = Record>; /** @deprecated Use a `{ keyframes, steps }` entry in `css` instead. Will be removed in v3. */ export type KeyframesRuleList = { name: string; keyframes: { offsets: number[]; declarations: Record; }[]; }[]; /** @deprecated Use a `{ keyframes, steps }` entry in `css` instead. Will be removed in v3. */ export type Keyframes = KeyframesMap | KeyframesRuleList; /** Output format for static images. */ export type OutputFormat = "png" | "jpeg" | "webp" | "ico" | "raw"; /** Output format for animated images. */ export type AnimationOutputFormat = "webp" | "apng" | "gif"; /** * Gradient dithering algorithm. * * `"floyd-steinberg"` is a deprecated alias of `"ordered-bayer"`; it will be * removed in v3. */ export type DitheringAlgorithm = "none" | "ordered-bayer" | "floyd-steinberg"; /** Cache policy for a decoded image. Defaults to `"auto"`. */ export type ImageCacheMode = "auto" | "none"; /** @internal The fonts one render sees, by the keys of its `fonts` list in order and the `@font-face` files and optional fonts that failed to load. */ type FontScope = { listed?: string[]; failed?: string[]; }; type RenderOptions$1 = { /** * The width of the image. If not provided, the width will be automatically calculated based on the content. */ width?: number; /** * The height of the image. If not provided, the height will be automatically calculated based on the content. */ height?: number; /** * The format of the image. * @default "png" */ format?: OutputFormat; /** * The quality of lossy formats (0-100). For JPEG; on wasm, WebP is always * lossless so this is ignored for WebP. */ quality?: number; /** * Encode WebP losslessly. On wasm, WebP is always lossless, so this is * accepted for parity with the native backend but has no effect. */ lossless?: boolean; /** * Images keyed by `src`, each carrying raw bytes. Provided up front and used * in place of fetching external `src` URLs during rendering. */ images?: ImageSource[]; /** * CSS to apply before rendering: stylesheet text, or a rule written as an * object. */ css?: CssInput[]; /** * @deprecated Use `css` instead. Will be removed in v3. */ stylesheets?: string[]; /** * @deprecated Use a `{ keyframes, steps }` entry in `css` instead. Will be removed in v3. */ keyframes?: Keyframes; /** * Whether to draw debug borders. */ drawDebugBorder?: boolean; /** * Defines the ratio resolution of the image to the physical pixels. * @default 1.0 */ devicePixelRatio?: number; /** * The animation timeline time in milliseconds. */ timeMs?: number; /** * Dithers gradient fills before they quantize to 8-bit. * @default "none" */ dithering?: DitheringAlgorithm; /** * Per-render font stack: ordered family names used as the fallback chain. * Defaults to all registered families in registration order. */ fontFamilies?: string[]; /** @internal The fonts the render lists and the ones that failed to load. */ fontScope?: FontScope; /** Default BCP-47 language applied to the root, inherited by nodes without their own lang. */ lang?: string; }; /** * SVG is a vector format, so the raster-only knobs do not apply. */ type SvgRenderOptions$1 = Omit; type RenderAnimationOptions$1 = { scenes: AnimationScene[]; width: number; height: number; format?: AnimationOutputFormat; /** * The quality of lossy WebP (0-100). Ignored for APNG and GIF; on wasm, WebP * is always lossless so this is ignored for WebP too. */ quality?: number; /** * Encode WebP losslessly. On wasm, animated WebP is always lossless, so this * is accepted for parity with the native backend but has no effect. */ lossless?: boolean; /** * Images keyed by `src`, each carrying raw bytes. Provided up front and used * in place of fetching external `src` URLs during rendering. */ images?: ImageSource[]; drawDebugBorder?: boolean; /** * CSS to apply before rendering: stylesheet text, or a rule written as an * object. */ css?: CssInput[]; /** * @deprecated Use `css` instead. Will be removed in v3. */ stylesheets?: string[]; /** * @deprecated Use a `{ keyframes, steps }` entry in `css` instead. Will be removed in v3. */ keyframes?: Keyframes; /** * Defines the ratio resolution of the image to the physical pixels. * @default 1.0 */ devicePixelRatio?: number; /** * Frames per second for timeline sampling. */ fps: number; /** * Per-render font stack: ordered family names used as the fallback chain. * Defaults to all registered families in registration order. */ fontFamilies?: string[]; /** @internal The fonts the render lists and the ones that failed to load. */ fontScope?: FontScope; /** Default BCP-47 language applied to the root, inherited by nodes without their own lang. */ lang?: string; }; export type FontDetails = { name?: string; data: ByteBuf; weight?: number; style?: "normal" | "italic" | "oblique" | `oblique ${number}deg` | (string & {}); /** * Inclusive codepoint ranges the font serves, as `@font-face` `unicode-range`. Register each * subset of a family under the same `name` with its own ranges. */ unicodeRange?: [number, number][]; /** @deprecated Register under `name` with `unicodeRange` instead. */ subsetOf?: string; /** @deprecated Ignored; `unicodeRange` decides which subset serves a codepoint. */ subsetRank?: number; /** * CSS generic family keyword this font resolves for, so stacks ending in e.g. * `monospace` reach it without naming the family. */ generic?: "serif" | "sans-serif" | "monospace" | "cursive" | "fantasy" | "system-ui" | "ui-serif" | "ui-sans-serif" | "ui-monospace" | "ui-rounded" | "emoji" | "math" | "fangsong"; }; export type ImageSource = { src: string; data: ByteBuf; /** Cache policy for the decoded image. Defaults to `"auto"`. */ cache?: ImageCacheMode; }; export type KeyframeRule = { offsets: number[]; declarations: Record; }; export type KeyframesRule = { name: string; keyframes: KeyframeRule[]; }; export type Font = FontDetails | ByteBuf; export type RegisteredFace = { weight: number; style: string; width: number; index: number; }; export type RegisteredFamily = { name: string; faces: RegisteredFace[]; }; export type MeasuredTextRun = { text: string; x: number; y: number; width: number; height: number; }; export type MeasuredNode = { width: number; height: number; transform: [number, number, number, number, number, number]; children: MeasuredNode[]; runs: MeasuredTextRun[]; }; /** The images a node tree looks up by URL and the listed fonts the render loads, read after the cascade. */ export type RenderNeeds = { /** The URLs of image elements and computed background, mask, and list marker images, except `data:` URIs and inline SVG, sorted. */ images: string[]; /** The ids of the listed fonts the render loads, sorted. */ fonts: number[]; /** The `@font-face` file URLs the render loads, sorted. */ fontFiles: string[]; /** The URLs of the loaded `@font-face` files the render draws with, sorted. */ loadedFontFiles: string[]; /** The characters no font in their fallback chain draws, each once in document order. */ missingCharacters: string[]; /** The families `font-family` or `fontFamilies` names that no font provides, each once. */ unresolvedFamilies: string[]; /** The declarations and at-rules the style parser dropped, each once. */ ignoredDeclarations: IgnoredDeclaration[]; }; /** A declaration or at-rule the style parser dropped. */ export type IgnoredDeclaration = { /** The property as written, or the at-rule's name with its `@`. */ property: string; /** The value as written, or the at-rule's prelude. */ value: string; /** Why it was dropped. */ reason: "unknown-property" | "invalid-value" | "unknown-at-rule"; /** Where it was written. */ origin: "style-attribute" | "style-sheet" | "style-object"; }; export type AnimationScene = { node: Node$1 | string | { json: string; }; durationMs: number; }; /** * Keeps no glyphs in each `Renderer` created after this call when `bytes` is `0`, and glyphs again * otherwise. Glyphs share the renderer's `cache.maxBytes` with every other kind of data. * * @deprecated Use `new Renderer({ cache: { glyphs: "none" } })`. */ export declare function setGlyphCacheMaxBytes(bytes: number): void; export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; export interface InitOutput { readonly memory: WebAssembly.Memory; readonly __wbg_renderer_free: (a: number, b: number) => void; readonly renderer_animationNeeds: (a: number, b: any, c: number) => [number, number, number]; readonly renderer_cacheFont: (a: number, b: any, c: number, d: number, e: number) => [number, number, number]; readonly renderer_cacheFontFile: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number]; readonly renderer_cacheStats: (a: number) => [number, number, number]; readonly renderer_cachedFontFile: (a: number, b: number, c: number, d: number) => number; readonly renderer_cachedFonts: (a: number, b: number, c: number, d: number, e: number) => [number, number, number]; readonly renderer_clearFonts: (a: number) => [number, number]; readonly renderer_dropFonts: (a: number, b: number, c: number) => [number, number]; readonly renderer_leaseFonts: (a: number) => number; readonly renderer_measure: (a: number, b: any, c: number) => [number, number, number]; readonly renderer_needs: (a: number, b: any, c: number, d: number) => [number, number, number]; readonly renderer_new: (a: number) => [number, number, number]; readonly renderer_registerFont: (a: number, b: any, c: number, d: number) => [number, number, number]; readonly renderer_releaseFonts: (a: number, b: number) => void; readonly renderer_render: (a: number, b: any, c: number) => [number, number, number, number]; readonly renderer_renderAnimation: (a: number, b: any) => [number, number, number, number]; readonly renderer_renderAsDataUrl: (a: number, b: any, c: any) => [number, number, number, number]; readonly renderer_renderSvg: (a: number, b: any, c: number) => [number, number, number, number]; readonly renderer_unregisterFont: (a: number, b: number, c: number) => number; readonly setGlyphCacheMaxBytes: (a: number) => void; readonly __wbindgen_malloc: (a: number, b: number) => number; readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number; readonly __wbindgen_free: (a: number, b: number, c: number) => void; readonly __wbindgen_exn_store: (a: number) => void; readonly __externref_table_alloc: () => number; readonly __wbindgen_externrefs: WebAssembly.Table; readonly __externref_table_dealloc: (a: number) => void; readonly __externref_drop_slice: (a: number, b: number) => void; readonly __wbindgen_start: () => void; } export type SyncInitInput = BufferSource | WebAssembly.Module; /** * Instantiates the given `module`, which can either be bytes or * a precompiled `WebAssembly.Module`. * * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated. * * @returns {InitOutput} */ export declare function initSync(module: { module: SyncInitInput; } | SyncInitInput): InitOutput; /** * If `module_or_path` is {RequestInfo} or {URL}, makes a request and * for everything else, calls `WebAssembly.instantiate` directly. * * @param {{ module_or_path: InitInput | Promise }} module_or_path - Passing `InitInput` directly is deprecated. * * @returns {Promise} */ export default function __wbg_init(module_or_path?: { module_or_path: InitInput | Promise; } | InitInput | Promise): Promise; /** * JSON text a binding reads in place of a node tree, faster than the tree, and off the main thread in napi. * * @internal */ type JsonSource = { json: string; }; /** * Font byte payloads accepted across environments. * * @internal */ type ByteBuf$1 = Uint8Array | ArrayBuffer | Buffer; /** A font descriptor, matching each backend's generated `FontDetails`. */ type FontDetails$1 = { name?: string; data: ByteBuf$1; weight?: number; style?: "normal" | "italic" | "oblique" | `oblique ${number}deg` | (string & {}); /** * Inclusive codepoint ranges the font serves, as `@font-face` `unicode-range`. Register each * subset of a family under the same `name` with its own ranges. */ unicodeRange?: [number, number][]; /** @deprecated Register under `name` with `unicodeRange` instead. */ subsetOf?: string; /** @deprecated Ignored; `unicodeRange` decides which subset serves a codepoint. */ subsetRank?: number; /** * CSS generic family keyword this font resolves for, so stacks ending in e.g. * `monospace` reach it without naming the family. */ generic?: GenericFontFamily; }; /** An image source with its URL and raw bytes, matching each backend's generated `ImageSource`. */ type ImageSource$1 = { src: string; data: ByteBuf$1; cache?: CacheMode$1; }; /** * A font family produced by `registerFont`. Only `name` is read here; backends keep the full type. * * @internal */ type RegisteredFamilyLike = { name: string; }; /** How a render treats a font of its `fonts` list. */ type FontPolicy = { /** * `"none"` lets the font go once the render that loaded it settles, though a render still uses * one the renderer already holds. `registerFont` keeps a font whatever this says. * @default "auto" */ cache?: CacheMode$1; /** * Lets the render go on without the font when it fails to download or decode, as `@font-face` * moves on past a failed `src`. `registerFont` rejects whatever this says. * @default false */ optional?: boolean; }; /** * A font to register. Either a URL string (fetched on demand, with name/weight/style read from the * file), raw bytes, or a descriptor with a lazy `data()` loader. */ type FontLoader = string | ByteBuf$1 | (FontDetails$1 & FontPolicy) | (Omit & FontPolicy & { data: () => Promise | FontDetails$1["data"]; /** @deprecated Use `unicodeRange`. */ ranges?: [number, number][]; } & ({ key: string; } | { name: string; })); /** @internal */ type ImageLoader = Omit & { data: ImageSource$1["data"] | (() => ImageSource$1["data"] | Promise); }; /** Images for a render: pre-fetched entries, or a group with a decode-cache default. */ type ImagesInput = ImageLoader[] | { /** Pre-fetched entries, same as the array form. */ sources?: ImageLoader[]; /** Decode-cache default for every image this render; a source's own `cache` wins. */ cache?: NonNullable; }; /** * Output format. Format-specific options live on the variant that supports them, so `quality` * cannot be paired with PNG/ICO/raw, and `lossless` is WebP-only. On native (`@takumi-rs/core`), * WebP honors both — `lossless` takes precedence over `quality`, and omitting both encodes * losslessly. On wasm (`@takumi-rs/wasm`) WebP is always lossless: `lossless` is effectively always * on and `quality` is ignored for WebP (lossy WebP is native-only). * @internal */ type OutputFormatOptions = { format?: "png"; } | { format: "jpeg"; quality?: number; } | { format: "webp"; quality?: number; lossless?: boolean; } | { format: "ico"; } | { format: "raw"; }; /** * Animation output format. `quality` and `lossless` are WebP-only. On native, `lossless` takes * precedence over `quality` and omitting both encodes losslessly; on wasm animated WebP is always * lossless and `quality` is ignored. * @internal */ type AnimationOutputFormatOptions = { format?: "webp"; quality?: number; lossless?: boolean; } | { format: "apng"; } | { format: "gif"; }; /** The wrapper-managed extras every render entry point accepts on top of the binding options. */ type RenderExtras = { fonts?: FontLoader[] | Promise; signal?: AbortSignal; images?: ImagesInput; loadFallbackFonts?: FallbackFontsLoader; }; /** * The binding options the wrapper sets for a render, which its public options leave out. * * @internal */ type WrapperOptions = "images" | "fontScope"; /** * Public `render`/`measure` options for a backend whose binding options are {@link TInternal}. * * @internal */ type BackendRenderOptions = Omit & OutputFormatOptions & RenderExtras; /** An animation's scenes and options, besides what a render loads, for a backend whose binding options are {@link TInternal}. */ type AnimationLayout = Omit & { /** The scenes to render in order, each a node tree or HTML markup. */ scenes: (Omit & { node: Exclude; })[]; } & AnimationOutputFormatOptions; /** * Public `renderAnimation` options for a backend whose binding options are {@link TInternal}. * * @internal */ type BackendAnimationOptions = AnimationLayout & RenderExtras; /** * Public `prepareAnimation` options for a backend whose binding options are {@link TInternal}. * * @internal */ type BackendPrepareAnimationOptions = AnimationLayout & PrepareExtras; /** * Public `renderSvg` options for a backend whose binding options are {@link TInternal}. * * @internal */ type BackendSvgOptions = Omit & RenderExtras; type Awaitable = T | Promise; /** The binding options that only change how a laid-out page is encoded. */ type OutputOnly = "format" | "quality" | "lossless" | "dithering" | "drawDebugBorder"; /** * Images for {@link Prepared}: entries to use as they are, and how to fetch the rest. * * @internal */ type PrepareImagesInput = ImageLoader[] | (Omit & { /** Entries to use as they are; their URLs are not fetched. */ sources?: ImageLoader[]; /** @deprecated A render without its own `fetch` keeps its downloads in a store the renderers share. When set, it keeps the images and `@font-face` files this render downloads instead. */ fetchCache?: ImageFetchCache; /** Decode-cache default for every image; a source's own `cache` wins. */ cache?: NonNullable; /** Throw on any fetch failure; if `false`, failed images are left out. @default true */ throwOnError?: boolean; }); /** * What `prepare` takes on top of the layout options. * * @internal */ type PrepareExtras = { fonts?: FontLoader[] | Promise; images?: PrepareImagesInput; signal?: AbortSignal; loadFallbackFonts?: FallbackFontsLoader; }; /** Returns fonts for the characters no font of a render draws, which then load as part of its `fonts`. */ type FallbackFontsLoader = (characters: string[]) => Awaitable; /** * Public `prepare` options for a backend whose binding options are {@link TInternal}. * * @internal */ type BackendPrepareOptions = Omit & PrepareExtras; /** * Public options for rendering a {@link Prepared} on a backend whose binding options are {@link TInternal}. * * @internal */ type BackendPreparedRenderOptions = Pick> & OutputFormatOptions & { signal?: AbortSignal; }; /** A source with its layout options, the font subsets its text uses, and the images it draws, fetched. */ export declare class Prepared { #private; private constructor(); } export type RenderOptions = BackendRenderOptions; export type RenderAnimationOptions = BackendAnimationOptions; export type SvgRenderOptions = BackendSvgOptions; export type PrepareOptions = BackendPrepareOptions; export type PreparedRenderOptions = BackendPreparedRenderOptions; export type PrepareAnimationOptions = BackendPrepareAnimationOptions; /** A source {@link Renderer.prepare} readied, with its fonts and images loaded. */ export type PreparedSource = Prepared>; /** An animation {@link Renderer.prepareAnimation} readied, with its fonts and images loaded. */ export type PreparedAnimation = Prepared>; export declare class Renderer { private inner; private fonts; constructor(options?: RendererOptions); /** Reads what `source` needs under `options`, then loads its font subsets and fetches its images. */ prepare(source: Node | string, options?: PrepareOptions): Promise; render(source: PreparedSource, options?: PreparedRenderOptions): Promise>; render(source: Node | string, options?: RenderOptions): Promise>; renderAsDataUrl(source: PreparedSource, options?: PreparedRenderOptions): Promise; renderAsDataUrl(source: Node | string, options?: RenderOptions): Promise; renderSvg(source: PreparedSource, options?: { signal?: AbortSignal; }): Promise; renderSvg(source: Node | string, options?: SvgRenderOptions): Promise; measure(source: PreparedSource, options?: { signal?: AbortSignal; }): Promise; measure(source: Node | string, options?: RenderOptions): Promise; /** `source` read under `options` without fetching, for {@link render} and its siblings. */ private read; /** Reads what every scene needs under `options`, then loads their font subsets and fetches their images. */ prepareAnimation(options: PrepareAnimationOptions): Promise; renderAnimation(source: PreparedAnimation, options?: { signal?: AbortSignal; }): Promise>; renderAnimation(options: RenderAnimationOptions): Promise>; /** The scenes of `options` read with `collect`, which fetches their images when it prepares them. */ private readAnimation; registerFont(font: FontLoader): Promise; /** * Removes every face registered under the family `name`, from any `registerFont` call and each * `unicodeRange` subset alike; returns whether it had any. Takes a family `registerFont` returned * as well. A later render that lists one of its fonts registers it again. */ unregisterFont(family: RegisteredFamilyLike): boolean; /** What the renderer's caches hold and how their lookups went since it was created. */ cacheStats(): CacheStats; /** Removes every registered font, leaving the bundled fallback font. */ clearFonts(): void; /** Releases the underlying wasm renderer's memory. */ free(): void; /** Releases the underlying wasm renderer's memory at the end of a `using` block. */ [Symbol.dispose](): void; } export { type AnimationOutputFormatOptions, type CacheKindStats, type CacheMemoryStats, type CacheMode, type CacheOptions, type CacheStats, ContainerNode, type CssInput, type FallbackFontsLoader, type FontLoader, type ImageLoader, ImageNode, type ImagesInput, type Node, NodeMetadata, type OutputFormatOptions, type PrepareImagesInput, type RendererOptions, RgbaImage, TextNode, __wbg_init as init };