بازدان بۆ ناوەڕۆک

ئەم وەرگێڕانە بە یارمەتیی AI نووسراوە و پێویستی بە پێداچوونەوەی کەسێکی زمانزان هەیە.

@0xdolan/deq-exporters

ئەم ناوەڕۆکە هێشتا بە زمانەکەت بەردەست نییە.

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): Drawing

Build 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): string

PascalCase 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): string

A 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): Rgba

Parse 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): Resolved

Resolve 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): SvgParts

Splits 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): string

A 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): string

A 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): string

A 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): string

A 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): string

SVG 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): string

An 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): string

Layered 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): string

A React component. With typescript, a .tsx file with a typed props interface.

toSpecJson

function toSpecJson(r: Resolved): string

Pretty-printed spec JSON with a trailing newline.

toSpecShape

function toSpecShape(r: Resolved): ShapeData

The 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): string

An 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): string

A Svelte 5 component (runes, lang="ts").

toSvg

function toSvg(item: Resolved | ExportItem): string

Optimised SVG: core’s minimal, deterministic output (currentColor by default). For a scene, the generator’s SVG.

toVue

function toVue(r: Resolved): string

A Vue 3 single-file component (<script setup lang="ts">).

writeEps

function writeEps(d: Drawing, options?: EpsOptions): string

Write 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: Rgba

Opaque 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: 512

Most items one export call accepts.

MAX_RASTER

const MAX_RASTER: 8192

Largest 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 Bitmap

A rendered bitmap: straight (not premultiplied) RGBA.

  • width: number
  • height: number
  • data: Uint8ClampedArray<ArrayBuffer>

CompositionItem

interface CompositionItem

Several catalog shapes on one canvas, one layer per part (see compose in core).

  • parts: readonly CompositionPart[]
  • options?: RenderOptions
  • name?: string: Base file name (kebab case). Default: composition.

DataItem

interface DataItem

A 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: ShapeData
  • params?: Readonly<Record<string, ParamValue>>: Shape parameter values; merged over options.params.
  • options?: RenderOptions
  • name?: string: Base file name (kebab case). Default: the shape’s id.

DrawOp

interface DrawOp

One painted path. Colours carry the final alpha (colour alpha × opacity).

  • path: readonly PathCmd[]
  • fill?: Rgba
  • stroke?: Rgba

Drawing

interface Drawing
  • width: number: Page width and height in points (1 px = 0.75 pt).
  • height: number
  • base: 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: number
  • linecap: 0 | 1 | 2
  • linejoin: 0 | 1 | 2
  • background?: DrawOp
  • layers: readonly { readonly id: string; readonly ops: readonly DrawOp[]; }[]: Layers in first-use (bottom to top) order.
  • title: string

EncodeOptions

interface EncodeOptions
  • quality?: 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 EpsOptions
  • colorSpace?: ColorSpace

ExportFile

interface ExportFile

One output file. Text formats return a string, binary formats a Uint8Array.

  • name: string: File name with extension, for example kurdish-sun.pdf. Never contains a path.
  • mediaType: string: IANA media type.
  • data: string | Uint8Array<ArrayBufferLike>

ExportOptions

interface ExportOptions

Options for exportShapes. Options a format does not use are ignored.

  • render?: RenderOptions: Render options for every item (an item’s own options win).
  • currentColor?: string: What currentColor means where nothing inherits it (PDF, AI, EPS, raster, PSD, Figma). Default black.
  • scales?: readonly number[]: Raster and PSD scale factors: 1 gives size px, 2 gives name@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. Default rgb.
  • layers?: boolean: PDF and AI: one Optional Content Group per layer. Default true.
  • prefix?: string: Sprite symbol id prefix. Default deq-.
  • 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 FaviconOptions
  • name?: string: App name in site.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.svg only). Default white.
  • background?: string: Opaque background of the Apple touch and maskable icons. Default white.
  • themeColor?: string: theme_color in the manifest. Default: background.

LeetItem

interface LeetItem

Deq 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: string
  • options?: LeetOptions
  • name?: string: Base file name (kebab case). Default: deq-leet.

PatternItem

interface PatternItem

A seeded pattern of motifs as one scene with one layer per motif (see pattern).

  • pattern: PatternOptions
  • name?: string: Base file name (kebab case). Default: deq-<kind> (deq-band without a kind).

PdfOptions

interface PdfOptions
  • colorSpace?: 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: /Creator in the document info.

RasterWasm

interface RasterWasm

WASM sources for browsers and bundlers. Node finds the packaged files by itself.

  • resvg?: unknown: The @resvg/resvg-wasm/index_bg.wasm file as a URL, a Response, its bytes or a compiled WebAssembly.Module (or a promise of one of these).

Resolved

interface Resolved

An item resolved into a shape description, its render options and its geometry.

  • name: string: Safe base file name.
  • shape: ShapeData
  • options: RenderOptions: The merged render options (unresolved, so a format can override some of them).
  • prepared: Prepared
  • scene?: string: For scenes (Leet and patterns): the generator’s own SVG, which SVG-based formats return unchanged so the output stays decodable. prepared has the same geometry, one layer per cell, for the other formats.

SceneItem

interface SceneItem

A 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: Scene
  • options?: SceneOptions
  • title?: 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 ShapeItem

One catalog shape, with optional parameters and render options.

  • shape: string: Catalog shape id, for example roj-half-sun.
  • params?: Readonly<Record<string, ParamValue>>: Shape parameter values; merged over options.params.
  • options?: RenderOptions: Render options for this item; merged over the exporter’s render options.
  • name?: string: Base file name (kebab case). Default: the shape id.

SvgParts

interface SvgParts

A 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 | SceneItem

What 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).