UNPKG

sone

Version:

A declarative Canvas layout engine for JavaScript with advanced rich text support.

109 lines (105 loc) 4.68 kB
import { Buffer } from 'node:buffer'; import skia, { ExportOptions } from 'skia-canvas'; import { SoneRenderer, SoneNode, SoneRenderConfig } from './browser.mjs'; export { AlignContent, AlignItems, ColorValue, Column, ColumnNode, DEFAULT_TEXT_PROPS, DefaultTextProps, FlexDirection, FontValue, JustifyContent, LayoutPositionType, LayoutProps, Path, PathNode, PathProps, PathPropsBuilder, Photo, PhotoNode, PhotoProps, PhotoPropsBuilder, Required, RequiredNonNullValues, Row, RowNode, SoneCompileContext, SoneDebugConfig, SoneImage, Span, SpanNode, SpanProps, SpanPropsBuilder, Table, TableCell, TableCellNode, TableCellProps, TableCellPropsBuilder, TableNode, TableProps, TablePropsBuilder, TableRow, TableRowNode, TableRowProps, TableRowPropsBuilder, Text, TextDefault, TextDefaultNode, TextDefaultProps, TextDefaultPropsBuilder, TextNode, TextProps, TextPropsBuilder, compile, createLayoutNode, drawLayoutNode, findFonts, pathPropsBuilder, qrcode, render } from './browser.mjs'; import 'gradient-parser'; import 'uqr'; import 'yoga-layout/load'; /** * Node.js platform implementation using skia-canvas for server-side rendering */ /** * Node.js renderer implementation using skia-canvas */ declare const renderer: SoneRenderer; /** * Creates a Sone renderer with multiple export format options * @param node - The SoneNode to render * @param config - Optional rendering configuration * @returns Object with methods for exporting in different formats */ declare function sone(node: SoneNode, config?: SoneRenderConfig): { /** * Export as JPEG image * @param quality - JPEG quality from 0.0 to 1.0 (default: 1.0) * @returns Promise<Buffer> - JPEG image buffer */ jpg: (quality?: number) => Promise<Buffer<ArrayBufferLike>>; /** * Export as PNG image * @returns Promise<Buffer> - PNG image buffer */ png: () => Promise<Buffer<ArrayBufferLike>>; /** * Export as SVG vector graphic * @param outline - Whether to include outline information (default: true) * @returns Promise<Buffer> - SVG image buffer */ svg: (outline?: boolean) => Promise<Buffer<ArrayBufferLike>>; /** * Export as PDF document * @param options - Optional PDF export settings * @returns Promise<Buffer> - PDF document buffer */ pdf: (options?: ExportOptions) => Promise<Buffer<ArrayBufferLike>>; /** * Export as WebP image * @param options - Optional WebP export settings * @returns Promise<Buffer> - WebP image buffer */ webp: (options?: ExportOptions) => Promise<Buffer<ArrayBufferLike>>; /** * Export as raw buffer data * @returns Promise<Buffer> - Raw image data buffer */ raw: () => Promise<Buffer<ArrayBufferLike>>; /** * Get the rendered Canvas object directly * @returns Promise<Canvas> - The rendered Canvas instance */ canvas: () => Promise<skia.Canvas>; }; /** * Font management utility for handling font loading, unloading, and checking availability. * This module provides a clean interface to interact with the underlying renderer's font system. */ declare const Font: { /** * Loads a font and registers it with the renderer for use in rendering operations. * * @param name - The name identifier for the font (used to reference it later) * @param source - The source path, URL, or data for the font file * @returns Promise that resolves when the font is successfully loaded and registered * * @example * await Font.load('MyCustomFont', '/assets/fonts/custom-font.ttf'); * await Font.load('MyCustomFont', ['/assets/fonts/custom-font.ttf']); */ load(name: string, source: string | string[]): Promise<void>; /** * Unloads a previously loaded font and removes it from the renderer. * This frees up memory and removes the font from the available font list. * * @param name - The name identifier of the font to unload * @returns Promise that resolves when the font is successfully unloaded * * @example * await Font.unload('MyCustomFont'); */ unload(name: string): Promise<void>; /** * Checks if a font with the given name is currently loaded and available. * * @param name - The name identifier of the font to check * @returns true if the font is loaded and available, false otherwise * * @example * if (Font.has('MyCustomFont')) { * // Use the font in rendering * } else { * // Load the font first or use a fallback * } */ has(name: string): boolean; }; export { Font, SoneNode, SoneRenderConfig, SoneRenderer, renderer, sone };