@cf-wasm/og
Version:
Generate Open Graph Images dynamically from HTML/CSS without a browser.
109 lines • 3.27 kB
TypeScript
import { MayBePromise, StringWithSuggestions } from "./types.js";
import { EmojiType } from "./emoji.js";
import { Font as Font$1, SatoriOptions, VNode } from "./satori.js";
import { FontBuffer } from "./font.js";
import { ResvgRenderOptions } from "./resvg.js";
import { ReactNode } from "react";
//#region src/core/render.d.ts
/** Represents a png result of rendered image */
interface PngResult {
pixels: Uint8Array<ArrayBuffer>;
image: Uint8Array<ArrayBuffer>;
/** The width of the image */
width: number;
/** The height of the image */
height: number;
/** The mime type of the image */
type: string;
}
/** Represents a svg result of rendered image */
interface SvgResult {
/** The svg image as string */
image: string;
/** The width of the image */
width: number;
/** The height of the image */
height: number;
/** The mime type of the image */
type: string;
}
interface RenderSatoriOptions extends Omit<SatoriOptions, 'width' | 'height' | 'fonts' | 'loadAdditionalAsset' | 'debug'> {}
interface RenderResvgOptions extends Omit<ResvgRenderOptions, 'fitTo'> {}
type Font = Omit<Font$1, 'data'> & FontBuffer;
/** An interface representing options for {@link render} function */
interface RenderOptions {
/**
* The width of the image.
*
* @default 1200
*/
width?: number;
/**
* The height of the image.
*
* @default 630
*/
height?: number;
/**
* Display debug information on the image.
*
* @default false
*/
debug?: boolean;
/** The default font to use */
defaultFont?: FontBuffer;
/**
* A list of fonts to use.
*
* @default Noto Sans Latin Regular.
*/
fonts?: Font[];
/**
* A callback function for loading dynamic assets requested by satori
*
* @param languageCode
* The detected language codes separated using `|` (i.e: `ja-JP|zh-CN|zh-TW|zh-HK`, `devanagari`, etc.)
*
* `emoji` if it's an Emoji
*
* `unknown` if not able to tell.
*
* @param segment Content to render.
* @param next A function which when called returns a Promise resolves to the next result
*/
loadAdditionalAsset?: (languageCode: StringWithSuggestions<'emoji' | 'unknown'>, segment: string, next: () => Promise<string | Font[]>) => MayBePromise<undefined | string | Font[]>;
/**
* Using a specific Emoji style. Defaults to `twemoji`.
*
* @default 'twemoji'
*/
emoji?: EmojiType;
/**
* The format of response, can be one of `svg` or `png`
*/
format?: 'svg' | 'png';
/**
* Passes {@link RenderSatoriOptions} to satori
*/
satoriOptions?: RenderSatoriOptions;
/**
* Passes {@link RenderResvgOptions} to resvg
*/
resvgOptions?: RenderResvgOptions;
}
interface RenderResult {
asSvg(): Promise<SvgResult>;
asPng(): Promise<PngResult>;
}
/**
* Renders {@link ReactNode} to image
*
* @param element The {@link ReactNode}
* @param options The {@link RenderOptions}
*
* @returns An object containing methods for rendering the input element to image
*/
declare function render(element: ReactNode | VNode, options?: RenderOptions): RenderResult;
//#endregion
export { Font, PngResult, RenderOptions, RenderResult, RenderResvgOptions, RenderSatoriOptions, SvgResult, render };
//# sourceMappingURL=render.d.ts.map