UNPKG

sone

Version:

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

109 lines (106 loc) 5.42 kB
import { S as SoneRenderer, a as SoneNode, b as SoneRenderConfig, c as SoneMetadata } from './browser-DRavyow_.mjs'; export { A as AlignContent, e as AlignItems, C as ColorValue, y as Column, u as ColumnNode, a3 as DEFAULT_TEXT_PROPS, D as DefaultTextProps, F as FlexDirection, j as FontValue, J as JustifyContent, L as LayoutPositionType, g as LayoutProps, K as Path, H as PathNode, E as PathProps, G as PathPropsBuilder, B as Photo, i as PhotoNode, P as PhotoProps, h as PhotoPropsBuilder, R as Required, l as RequiredNonNullValues, z as Row, t as RowNode, a6 as SoneCompileContext, a4 as SoneDebugConfig, a5 as SoneImage, v as Span, n as SpanNode, k as SpanProps, m as SpanPropsBuilder, W as Table, $ as TableCell, _ as TableCellNode, Y as TableCellProps, Z as TableCellPropsBuilder, O as TableNode, M as TableProps, N as TablePropsBuilder, X as TableRow, V as TableRowNode, Q as TableRowProps, U as TableRowPropsBuilder, x as Text, w as TextDefault, s as TextDefaultNode, q as TextDefaultProps, r as TextDefaultPropsBuilder, p as TextNode, T as TextProps, o as TextPropsBuilder, d as applySpanProps, aa as calculateLayout, a7 as compile, a9 as createLayoutNode, ad as createMetadata, a0 as defaultLineBreakerIterator, ah as drawDebugBBox, af as drawLayoutNode, ac as drawOnCanvas, ai as drawPathNode, aj as drawTableNode, a8 as findFonts, f as fontBuilder, a2 as getYogaLayout, ag as makeTransforms, I as pathPropsBuilder, a1 as qrcode, ae as render, ab as renderWithMetadata } from './browser-DRavyow_.mjs'; import { Buffer } from 'node:buffer'; import skia, { ExportOptions } from 'skia-canvas'; import 'gradient-parser'; import 'uqr'; import 'yoga-layout/load'; /** * 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, options?: ExportOptions) => Promise<Buffer<ArrayBufferLike>>; /** * Export as PNG image * @returns Promise<Buffer> - PNG image buffer */ png: (options?: ExportOptions) => Promise<Buffer<ArrayBufferLike>>; /** * Export as SVG vector graphic * @param outline - Whether to include outline information (default: true) * @returns Promise<Buffer> - SVG image buffer */ svg: (options?: ExportOptions) => 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: (options?: ExportOptions) => Promise<Buffer<ArrayBufferLike>>; /** * Get the rendered Canvas object directly * @returns Promise<Canvas> - The rendered Canvas instance */ canvas: () => Promise<skia.Canvas>; canvasWithMetadata: () => Promise<{ canvas: HTMLCanvasElement; metadata: SoneMetadata | undefined; }>; }; /** * 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 };