Ev werger bi alîkariya AI hatiye amadekirin û divê axêverekî zikmakî lê binêre.
@0xdolan/deq-exporters
Ev naverok hêj bi zimanê te tune.
Export Deq shapes to SVG, PDF, AI, EPS, PSD, PNG, JPG, WebP, AVIF, ICO, a favicon pack, React, Vue, Svelte, CSS, Figma and spec JSON.
Every format goes through exportShapes; the per-format functions are exported
too for callers that want one string or byte array.
Source: packages/exporters. Install with npm install @0xdolan/deq-exporters.
Functions
buildDrawing
function buildDrawing(p: Prepared, currentColor?: Rgba): DrawingBuild the drawing for prepared geometry.
canvasPixels
function canvasPixels(p: Prepared): { readonly width: number; readonly height: number; }The size in pixels of prepared geometry, as core writes it on the root <svg>: size
for each 24-unit side, more for the long side of a scene.
componentName
function componentName(name: string): stringPascalCase component name from a kebab-case file name: roj-half-sun → RojHalfSun.
copyToClipboard
function copyToClipboard(text: string): Promise<boolean>Copy text (for example toFigmaSvg output) to the clipboard in a browser. Figma
pastes SVG markup as editable vectors.
cssClass
function cssClass(r: Resolved, className?: string | undefined): stringA CSS class name for r, checked so it cannot break out of the rule.
encodeSvg
function encodeSvg(svg: string, width: number, format: RasterFormat, options?: EncodeOptions): Promise<Uint8Array<ArrayBufferLike>>Render an SVG and encode it.
exportShapes
function exportShapes(format: 'svg' | 'svg-layered' | 'svg-sprite' | 'html' | 'jsx' | 'tsx' | 'vue' | 'svelte' | 'data-uri' | 'css-background' | 'css-mask' | 'pdf' | 'ai' | 'eps' | 'png' | 'jpg' | 'webp' | 'avif' | 'ico' | 'favicon' | 'psd' | 'figma' | 'spec-json', items: readonly ExportItem[], options?: ExportOptions): Promise<ExportFile[]>Export items to a format. Returns one or more files; their names are unique and never contain a path.
@throws {DeqError} INVALID_OPTIONS, UNKNOWN_SHAPE, INVALID_PARAMETER or LIMIT_EXCEEDED.
initRaster
function initRaster(wasm?: RasterWasm): Promise<void>Load the resvg WASM renderer once. Node loads the packaged file; browsers must pass
wasm.resvg (for example new URL("@resvg/resvg-wasm/index_bg.wasm", import.meta.url))
before the first raster export. Later calls reuse the first result.
packIco
function packIco(images: readonly { readonly size: number; readonly png: Uint8Array<ArrayBufferLike>; }[]): Uint8Array<ArrayBufferLike>Pack PNG images into an ICO container (Windows Vista+ PNG entries).
parseColor
function parseColor(input: string, current?: Rgba): RgbaParse a CSS colour. currentColor resolves to current.
@throws {DeqError} INVALID_OPTIONS when the colour cannot be converted.
rasterize
function rasterize(svg: string, width: number): Promise<Bitmap>Render an SVG to straight RGBA pixels.
resolveItem
function resolveItem(item: ExportItem, defaults?: RenderOptions): ResolvedResolve one item. defaults are the exporter’s render options; the item’s own options
and parameters win.
@throws {DeqError} for unknown shapes, bad names, options or parameters.
resolveItems
function resolveItems(items: readonly ExportItem[], defaults?: RenderOptions): Resolved[]Resolve a list of items, rejecting empty lists, more than MAX_ITEMS items and
duplicate file names.
splitSvg
function splitSvg(svg: string): SvgPartsSplits a Deq SVG document into its root attributes and inner markup.
@throws Error when the text is not a single <svg> element.
svgDataUri
function svgDataUri(svg: string, base64?: boolean): stringA data:image/svg+xml URI. Double quotes become single quotes (core escapes ' in
values), so the result can sit inside url("...") or an HTML attribute.
toCmyk
function toCmyk([r, g, b]: Rgba): [number, number, number, number]Naive device CMYK (no ICC profile): k = 1 - max(r, g, b).
toCssBackground
function toCssBackground(item: Resolved | ExportItem, className?: string | undefined): stringA CSS rule that paints the shape as a background image. Images cannot inherit
currentColor, so set options.color (default black).
toCssMask
function toCssMask(item: Resolved | ExportItem, className?: string | undefined): stringA CSS rule that uses the shape as a mask over currentColor, so it follows the text
colour like an icon font.
toDataUri
function toDataUri(item: Resolved | ExportItem, base64?: boolean): stringA data URI of the optimised SVG.
toFaviconPack
function toFaviconPack(r: Resolved, options?: FaviconOptions): Promise<ExportFile[]>The favicon pack: favicon.ico (16, 32, 48), favicon.svg (follows dark mode),
apple-touch-icon.png (180), icon-192.png, icon-512.png, icon-maskable-512.png
(80% safe zone) and site.webmanifest. All colours are re-serialised as hex.
toFigmaSvg
function toFigmaSvg(item: Resolved | ExportItem, currentColor?: Rgba): stringSVG for pasting into Figma (copy as SVG): every layer is a group whose id Figma shows
as the layer name, and currentColor is replaced by concrete colours.
toHex
function toHex([r, g, b, a]: Rgba): string#rrggbb, or #rrggbbaa when not opaque.
toHtml
function toHtml(item: Resolved | ExportItem): stringAn inline SVG snippet ready to paste into HTML.
toIco
function toIco(r: Resolved, sizes?: readonly number[]): Promise<Uint8Array<ArrayBufferLike>>Render an item at several square sizes into one ICO file.
toLayeredSvg
function toLayeredSvg(item: Resolved | ExportItem): stringLayered SVG: each shape layer is an Inkscape layer (inkscape:groupmode="layer"), which
Inkscape, Illustrator and Figma show as named layers.
toReact
function toReact(r: Resolved, typescript: boolean): stringA React component. With typescript, a .tsx file with a typed props interface.
toSpecJson
function toSpecJson(r: Resolved): stringPretty-printed spec JSON with a trailing newline.
toSpecShape
function toSpecShape(r: Resolved): ShapeDataThe shape behind an exported item. A catalog shape with its default parameters is
returned as is. With custom parameters it becomes a copy (named after the item) whose
parameter defaults are those values, so every layer survives. A composition keeps its
use primitives. Render options (colour, size and so on) are not part of a shape.
toSprite
function toSprite(items: readonly Resolved[], prefix?: string): stringAn SVG sprite: one <symbol id="<prefix><name>"> per item, used with
<svg><use href="sprite.svg#deq-kurdish-sun"/></svg>.
toSvelte
function toSvelte(r: Resolved): stringA Svelte 5 component (runes, lang="ts").
toSvg
function toSvg(item: Resolved | ExportItem): stringOptimised SVG: core’s minimal, deterministic output (currentColor by default). For a
scene, the generator’s SVG.
toVue
function toVue(r: Resolved): stringA Vue 3 single-file component (<script setup lang="ts">).
writeEps
function writeEps(d: Drawing, options?: EpsOptions): stringWrite an EPS file for a drawing.
writePdf
function writePdf(d: Drawing, options?: PdfOptions): Uint8Array<ArrayBufferLike>Write a one-page PDF for a drawing.
writePsd
function writePsd(p: Prepared, width: number): Promise<Uint8Array<ArrayBufferLike>>Write a PSD at width pixels. Each layer is rendered on its own, so overlaps between
layers blend in Photoshop exactly as in the composite (normal blending).
Constants
BLACK
const BLACK: RgbaOpaque black, the default for currentColor outside a browser.
FORMATS
const FORMATS: readonly ['svg', 'svg-layered', 'svg-sprite', 'html', 'jsx', 'tsx', 'vue', 'svelte', 'data-uri', 'css-background', 'css-mask', 'pdf', 'ai', 'eps', 'png', 'jpg', 'webp', 'avif', 'ico', 'favicon', 'psd', 'figma', 'spec-json']Every export format.
ICO_SIZES
const ICO_SIZES: readonly [16, 32, 48]Sizes in favicon.ico.
MAX_ITEMS
const MAX_ITEMS: 512Most items one export call accepts.
MAX_RASTER
const MAX_RASTER: 8192Largest width or height of a raster export, in pixels.
SCENE_UNSUPPORTED
const SCENE_UNSUPPORTED: readonly ['svg-sprite', 'ico', 'favicon', 'figma', 'spec-json']Formats that need a square, single-shape canvas and refuse scenes.
packageName
const packageName: '@0xdolan/deq-exporters'The package name.
Interfaces
Bitmap
interface BitmapA rendered bitmap: straight (not premultiplied) RGBA.
width: numberheight: numberdata: Uint8ClampedArray<ArrayBuffer>
CompositionItem
interface CompositionItemSeveral catalog shapes on one canvas, one layer per part (see compose in core).
parts: readonly CompositionPart[]options?: RenderOptionsname?: string: Base file name (kebab case). Default:composition.
DataItem
interface DataItemA shape given as data instead of a catalog id: a custom shape in the spec format, as
core’s renderShapeData reads it. Its primitives may use catalog shapes. The top level
is checked against the full primitive schema first (see checkShapeData), and core
enforces its expansion limits while rendering.
data: ShapeDataparams?: Readonly<Record<string, ParamValue>>: Shape parameter values; merged overoptions.params.options?: RenderOptionsname?: string: Base file name (kebab case). Default: the shape’s id.
DrawOp
interface DrawOpOne painted path. Colours carry the final alpha (colour alpha × opacity).
path: readonly PathCmd[]fill?: Rgbastroke?: Rgba
Drawing
interface Drawingwidth: number: Page width and height in points (1 px = 0.75 pt).height: numberbase: Matrix: Canvas units to page points, with the y axis flipped.transforms: readonly Matrix[]: The rotation/flip transforms, outermost first (as in core’s SVG).lineWidth: numberlinecap: 0 | 1 | 2linejoin: 0 | 1 | 2background?: DrawOplayers: readonly { readonly id: string; readonly ops: readonly DrawOp[]; }[]: Layers in first-use (bottom to top) order.title: string
EncodeOptions
interface EncodeOptionsquality?: number: Quality 0 to 100 for JPG, WebP and AVIF. Default 90 (JPG, WebP) and 70 (AVIF).matte?: Rgba: JPG has no transparency: transparent pixels are composited onto this colour.
EpsOptions
interface EpsOptionscolorSpace?: ColorSpace
ExportFile
interface ExportFileOne output file. Text formats return a string, binary formats a Uint8Array.
name: string: File name with extension, for examplekurdish-sun.pdf. Never contains a path.mediaType: string: IANA media type.data: string | Uint8Array<ArrayBufferLike>
ExportOptions
interface ExportOptionsOptions for exportShapes. Options a format does not use are ignored.
render?: RenderOptions: Render options for every item (an item’s ownoptionswin).currentColor?: string: WhatcurrentColormeans where nothing inherits it (PDF, AI, EPS, raster, PSD, Figma). Default black.scales?: readonly number[]: Raster and PSD scale factors: 1 givessizepx, 2 givesname@2x.png. Default[1].quality?: number: JPG, WebP and AVIF quality, 0 to 100.matte?: string: JPG background for transparent pixels. Default white.colorSpace?: ColorSpace: PDF, AI and EPS colour space. Defaultrgb.layers?: boolean: PDF and AI: one Optional Content Group per layer. Default true.prefix?: string: Sprite symbol id prefix. Defaultdeq-.base64?: boolean: Data URIs: base64 instead of percent encoding. Default false.icoSizes?: readonly number[]: ICO sizes. Default 16, 32 and 48.favicon?: FaviconOptions: Favicon pack options (one item only).
FaviconOptions
interface FaviconOptionsname?: string: App name insite.webmanifest. Default: the shape’s English name.shortName?: string: Short app name. Default:name.color?: string: Icon colour in light mode and in the PNG icons. Default: the render colour, or black.darkColor?: string: Icon colour when the browser is in dark mode (favicon.svgonly). Default white.background?: string: Opaque background of the Apple touch and maskable icons. Default white.themeColor?: string:theme_colorin the manifest. Default:background.
LeetItem
interface LeetItemDeq Leet text as one wide scene with one layer per character (see leet in
@0xdolan/deq-generator). The exporter’s render options apply except the per-shape
ones (rotation, flipX, flipY, params, layerColors).
leet: stringoptions?: LeetOptionsname?: string: Base file name (kebab case). Default:deq-leet.
PatternItem
interface PatternItemA seeded pattern of motifs as one scene with one layer per motif (see pattern).
pattern: PatternOptionsname?: string: Base file name (kebab case). Default:deq-<kind>(deq-bandwithout a kind).
PdfOptions
interface PdfOptionscolorSpace?: ColorSpace: Device colour space. CMYK uses a naive conversion without an ICC profile.layers?: boolean: Put each shape layer in its own Optional Content Group. Default true.creator?: string:/Creatorin the document info.
RasterWasm
interface RasterWasmWASM sources for browsers and bundlers. Node finds the packaged files by itself.
resvg?: unknown: The@resvg/resvg-wasm/index_bg.wasmfile as a URL, aResponse, its bytes or a compiledWebAssembly.Module(or a promise of one of these).
Resolved
interface ResolvedAn item resolved into a shape description, its render options and its geometry.
name: string: Safe base file name.shape: ShapeDataoptions: RenderOptions: The merged render options (unresolved, so a format can override some of them).prepared: Preparedscene?: string: For scenes (Leet and patterns): the generator’s own SVG, which SVG-based formats return unchanged so the output stays decodable.preparedhas the same geometry, one layer per cell, for the other formats.
SceneItem
interface SceneItemA scene built by the caller from generator output, for example Leet text framed by a pattern in the website. Cells place glyphs of catalog shapes; the scene is checked against a strict schema and core’s expansion limits.
scene: Sceneoptions?: SceneOptionstitle?: string: The default title. Default: empty (the SVG is decorative unless options set one).name?: string: Base file name (kebab case). Default:deq-scene.
ShapeItem
interface ShapeItemOne catalog shape, with optional parameters and render options.
shape: string: Catalog shape id, for exampleroj-half-sun.params?: Readonly<Record<string, ParamValue>>: Shape parameter values; merged overoptions.params.options?: RenderOptions: Render options for this item; merged over the exporter’srenderoptions.name?: string: Base file name (kebab case). Default: the shape id.
SvgParts
interface SvgPartsA Deq SVG document split by splitSvg.
attrs: readonly (readonly [string, string])[]inner: string
Types
ColorSpace
type ColorSpace = "rgb" | "cmyk"PDF/EPS colour model for paints.
ExportFormat
type ExportFormat = (typeof FORMATS)[number]One of the 23 export format ids in FORMATS.
ExportItem
type ExportItem = string | ShapeItem | CompositionItem | DataItem | LeetItem | PatternItem | SceneItemWhat every exporter accepts: a shape id, a ShapeItem, a CompositionItem,
a DataItem, a LeetItem, a PatternItem or a SceneItem.
Matrix
type Matrix = readonly [number, number, number, number, number, number]An affine matrix [a, b, c, d, e, f] (PDF cm and SVG matrix() order).
PathCmd
type PathCmd = | readonly ["m", number, number] | readonly ["l", number, number] | readonly ["c", number, number, number, number, number, number] | readonly ["h"]A path command in canvas units.
RasterFormat
type RasterFormat = "png" | "jpg" | "webp" | "avif"Raster encodings.
Rgba
type Rgba = readonly [number, number, number, number]Red, green, blue and alpha, each 0 to 1 (sRGB, not premultiplied).
Guhertoyeke nû ya vê malperê heye.