Ev werger bi alîkariya AI hatiye amadekirin û divê axêverekî zikmakî lê binêre.
@0xdolan/deq-core
Ev naverok hêj bi zimanê te tune.
The reference renderer for Deq shapes. Pure ESM, no DOM, no I/O.
import { render, listShapes, compose } from "@0xdolan/deq-core";const svg = render("roj-half-sun", { size: 48, color: "#ED2024" });Source: packages/core. Install with npm install @0xdolan/deq-core.
Functions
compose
function compose(parts: readonly CompositionPart[], options?: RenderOptions): stringRender several catalog shapes placed on one 24 x 24 canvas. Stroke widths and dot radii
are not scaled. options.params is not used (give each part its own params).
@throws {DeqError} INVALID_OPTIONS, UNKNOWN_SHAPE or INVALID_PARAMETER.
composeShape
function composeShape(parts: readonly CompositionPart[]): ShapeDataBuild the shape description of a composition: one use primitive per part, each on its
own layer. The result can be passed to prepare or saved as a shape spec.
@throws {DeqError} INVALID_OPTIONS or UNKNOWN_SHAPE.
cosSin
function cosSin(deg: number): VecCosine and sine of deg degrees, exact at multiples of 90.
element
function element(item: Flat, o: ResolvedOptions): stringOne SVG element; stroke attributes are inherited from the root.
escapeXml
function escapeXml(s: string): stringEscape text for XML character data and double-quoted attributes; drop invalid characters.
expand
function expand(id: string, params?: Readonly<Record<string, ParamValue>>): Flat[]Expand the catalog shape id into flat geometry.
expandShape
function expandShape(shape: ShapeData, params?: Readonly<Record<string, ParamValue>>): Flat[]Expand shape into flat geometry with the given parameter values.
flagSize
function flagSize(variant: FlagVariant, width: number): [number, number]The pixel size of the flag at width px for a variant.
getShape
function getShape(id: string): ShapeDataThe shape with this id. Throws DeqError (UNKNOWN_SHAPE) with suggestions otherwise.
hasShape
function hasShape(id: string): booleanTrue when a shape with this id exists.
listCategories
function listCategories(): readonly string[]Category ids in catalog order.
listFlagVariants
function listFlagVariants(): readonly string[]Variant ids in spec order.
listShapes
function listShapes(category?: string | undefined): readonly ShapeData[]Every shape, in catalog order, optionally only one category.
num
function num(x: number): stringFormat a number with at most 3 decimals: roundHalfEven(x * 1000) thousandths, printed
without trailing zeros, without a leading +, and with -0 as 0.
prepare
function prepare(shape: ShapeData, options?: RenderOptions): PreparedValidate options for shape and expand its geometry, ready for svgDocument
or another output format.
@throws {DeqError} INVALID_OPTIONS, INVALID_PARAMETER or LIMIT_EXCEEDED.
render
function render(id: string, options?: RenderOptions): stringRender the catalog shape id as a standalone SVG string.
render("roj-half-sun", { size: 48, strokeWidth: 1.5, color: "#ED2024", params: { rays: 9 } });@throws {DeqError} UNKNOWN_SHAPE, INVALID_OPTIONS or INVALID_PARAMETER.
renderFlag
function renderFlag(options?: FlagOptions): stringRender the Kurdish flag as a standalone SVG string.
renderFlag({ variant: "outline", width: 300 });@throws {DeqError} INVALID_OPTIONS for an unknown variant or a bad width.
renderShapeData
function renderShapeData(shape: ShapeData, options?: RenderOptions): stringRender a shape description (already validated) to an SVG string.
resolveOptions
function resolveOptions(options?: unknown): ResolvedOptionsValidate options and fill in defaults. Throws DeqError (INVALID_OPTIONS).
resolveParams
function resolveParams(shape: ShapeData, overrides?: Readonly<Record<string, ParamValue>>): Record<string, ParamValue>Parameter defaults merged with overrides, type- and range-checked.
roundHalfEven
function roundHalfEven(v: number): numberRound half to even (banker’s rounding) on a finite double.
svgDocument
function svgDocument(p: Prepared, hooks?: SvgHooks): stringBuild the SVG document for prepared geometry. With no hooks this is exactly what
render returns.
svgRoot
function svgRoot(o: ResolvedOptions, defaultTitle: string, hooks?: SvgHooks, width?: number, height?: number): stringThe opening <svg> tag with its title and background, for a canvas of width x
height grid units (24 x 24 for a shape). o.size is the pixel size of the padded
24-unit box, so wider canvases keep the same scale. Used by svgDocument and by
scenes made of several shapes, such as Deq Leet text.
Classes
DeqError
class DeqErrorThe only error type the library throws. code is stable; message is for people.
name: 'DeqError'code: DeqErrorCodeissues: readonly string[]: Validation problems, one line each (forINVALID_OPTIONS).
Constants
CANVAS
const CANVAS: 24Canvas size in grid units.
DEFAULT_OPTIONS
const DEFAULT_OPTIONS: ResolvedOptionsThe documented default of every option (used by “reset” controls).
FLAG
const FLAG: FlagDataThe render-relevant part of spec/flag.json, paint resolved to colours.
MAX_DEPTH
const MAX_DEPTH: 6Deepest nesting of generators and references.
MAX_FLAT
const MAX_FLAT: 2000Most flat items one render may produce.
packageName
const packageName: '@0xdolan/deq-core'The npm package name.
Interfaces
ArcPrimitive
interface ArcPrimitivetype: 'arc'cx: numbercy: numberr: numberstart: number: Degrees, clockwise on screen from the positive x axis.end: numberid?: stringlayer?: stringwhen?: Readonly<Record<string, ParamValue | readonly (string | number)[]>>: Draw only when every listed parameter has the value (or one of the values).
CirclePrimitive
interface CirclePrimitivetype: 'circle'cx: numbercy: numberr: numberpaint?: Paintid?: stringlayer?: stringwhen?: Readonly<Record<string, ParamValue | readonly (string | number)[]>>: Draw only when every listed parameter has the value (or one of the values).
CompositionPart
interface CompositionPartOne shape placed in a composition.
shape: string: Catalog shape id.params?: Readonly<Record<string, ParamValue>> | undefined: Parameter values of that shape.transform?: UseTransform | undefined: Placement:p' = R(rotate) * (scale * (p - origin)) + origin + translate.layer?: string: Layer id for this part. Default: the shape id.
ConcentricPrimitive
interface ConcentricPrimitivetype: 'concentric'count: Countcenter: VecscaleStep: numberelement: Primitiveid?: stringlayer?: stringwhen?: Readonly<Record<string, ParamValue | readonly (string | number)[]>>: Draw only when every listed parameter has the value (or one of the values).
DotPrimitive
interface DotPrimitivetype: 'dot'cx: numbercy: numberr?: numberid?: stringlayer?: stringwhen?: Readonly<Record<string, ParamValue | readonly (string | number)[]>>: Draw only when every listed parameter has the value (or one of the values).
EllipsePrimitive
interface EllipsePrimitivetype: 'ellipse'cx: numbercy: numberrx: numberry: numberpaint?: Paintid?: stringlayer?: stringwhen?: Readonly<Record<string, ParamValue | readonly (string | number)[]>>: Draw only when every listed parameter has the value (or one of the values).
FlagData
interface FlagDataThe render-relevant part of spec/flag.json.
name: stringviewBox: readonly [number, number]bands: readonly { readonly y: number; readonly height: number; readonly color: string; }[]sun: { readonly rays: number; readonly rotation: number; readonly center: readonly [number, number]; readonly outerRadius: number; readonly innerRadius: number; }variants: readonly FlagVariant[]
FlagOptions
interface FlagOptionsOptions of renderFlag.
variant?: string: Variant id fromspec/flag.json. Defaultfull-color.width?: number: Output width in px (an integer); the height follows the aspect ratio. Default 900.title?: string: Accessible title. Default “Flag of Kurdistan”.""marks the image decorative.
FlagVariant
interface FlagVariantOne flag variant with its paint resolved to colours (null = not drawn).
id: stringdescription: stringcrop: readonly [number, number]: Visible part of the 900 x 600 field: left edge and width.field: string | nullbands: boolean: Paint the red, white and green bands.dividers: string | nullframe: string | nullsun: string | nullsunOutline: string | nullstrokeWidth: number: Width of frame, divider and outline strokes, in field units.
FlatArc
interface FlatArckind: 'arc'cx: numbercy: numberr: numberstart: numberend: numberlayer: stringpaint: Paint
FlatCircle
interface FlatCircleA circle; dot circles are filled and keep their radius under scaling.
kind: 'circle'cx: numbercy: numberr: numberlayer: stringpaint: Paintdot: boolean
FlatEllipse
interface FlatEllipsekind: 'ellipse'cx: numbercy: numberrx: numberry: numberrotation: numberlayer: stringpaint: Paint
FlatPath
interface FlatPathkind: 'path'segments: readonly Segment[]layer: stringpaint: Paint
FlatPoly
interface FlatPolyA line, polyline or polygon.
kind: 'poly'points: readonly Vec[]closed: booleanlayer: stringpaint: Paint
KurdishName
interface KurdishNameA Kurdish name. text is null until a native speaker has reviewed it.
text: string | nullstatus: string
LinePrimitive
interface LinePrimitivetype: 'line'x1: numbery1: numberx2: numbery2: numberid?: stringlayer?: stringwhen?: Readonly<Record<string, ParamValue | readonly (string | number)[]>>: Draw only when every listed parameter has the value (or one of the values).
PathPrimitive
interface PathPrimitivetype: 'path'd: stringpaint?: Paintid?: stringlayer?: stringwhen?: Readonly<Record<string, ParamValue | readonly (string | number)[]>>: Draw only when every listed parameter has the value (or one of the values).
PolygonPrimitive
interface PolygonPrimitivetype: 'polygon'points: readonly Vec[]paint?: Paintid?: stringlayer?: stringwhen?: Readonly<Record<string, ParamValue | readonly (string | number)[]>>: Draw only when every listed parameter has the value (or one of the values).
PolylinePrimitive
interface PolylinePrimitivetype: 'polyline'points: readonly Vec[]id?: stringlayer?: stringwhen?: Readonly<Record<string, ParamValue | readonly (string | number)[]>>: Draw only when every listed parameter has the value (or one of the values).
Prepared
interface PreparedA shape ready to draw: resolved options and flat geometry in canvas units.
options: ResolvedOptions: The validated options with every default filled in.items: readonly Flat[]: The geometry, in drawing order.layers: readonly string[]: The layer ids of the shape, in declaration order.defaultTitle: string: The title used whenoptions.titleis not set (the English name).width?: number: Canvas width in grid units when it is not 24 (scenes). Default: 24.height?: number: Canvas height in grid units when it is not 24 (scenes). Default: 24.
RadialPrimitive
interface RadialPrimitivetype: 'radial'count: Countcenter: Vecstart: numbersweep: numberelement: Primitiveid?: stringlayer?: stringwhen?: Readonly<Record<string, ParamValue | readonly (string | number)[]>>: Draw only when every listed parameter has the value (or one of the values).
RectPrimitive
interface RectPrimitivetype: 'rect'x: numbery: numberwidth: numberheight: numberpaint?: Paintid?: stringlayer?: stringwhen?: Readonly<Record<string, ParamValue | readonly (string | number)[]>>: Draw only when every listed parameter has the value (or one of the values).
RenderOptions
interface RenderOptionsOptions accepted by render and compose. Every option is optional; see
DEFAULT_OPTIONS for the defaults.
size?: number: Output width and height in px. Default 24.color?: string: Stroke and dot colour (CSS colour). DefaultcurrentColor.strokeWidth?: number: Stroke width in grid units. Default 2.absoluteStrokeWidth?: boolean: Keep the strokestrokeWidthpx wide at anysize. Default false.fill?: string: Fill for closed outlines (circles, polygons, closed paths). Defaultnone.fillOpacity?: number: Opacity offill, 0 to 1. Default 1.strokeOpacity?: number: Opacity of the ink (strokes and dots), 0 to 1. Default 1.linecap?: 'round' | 'butt' | 'square': Defaultround.linejoin?: 'round' | 'miter' | 'bevel': Defaultround.dotScale?: number: Multiplies every dot radius. Default 1.rotation?: number: Degrees clockwise about the canvas centre. Default 0.flipX?: boolean: Mirror left to right. Default false.flipY?: boolean: Mirror top to bottom. Default false.padding?: number: Extra space around the 24 x 24 canvas, in grid units. Default 0.background?: string: Background colour painted behind the shape, ornone. Defaultnone.layerColors?: Readonly<Record<string, string>>: Colour per layer id, overridingcolorfor that layer.title?: string: Accessible title. Default: the shape’s English name.""marks the image decorative.ariaLabel?: string: Accessible label. Default: the title.params?: Readonly<Record<string, ParamValue>>: Shape parameter values, for example{ rays: 9 }. Default: each parameter’s default.
RepeatPrimitive
interface RepeatPrimitivetype: 'repeat'count: Countstep?: Vecspread?: Vecalign?: 'start' | 'center'element: Primitiveid?: stringlayer?: stringwhen?: Readonly<Record<string, ParamValue | readonly (string | number)[]>>: Draw only when every listed parameter has the value (or one of the values).
ResolvedOptions
interface ResolvedOptionsOptions after validation, with every default filled in.
size: numbercolor: stringstrokeWidth: numberabsoluteStrokeWidth: booleanfill: stringfillOpacity: numberstrokeOpacity: numberlinecap: 'round' | 'butt' | 'square'linejoin: 'round' | 'miter' | 'bevel'dotScale: numberrotation: numberflipX: booleanflipY: booleanpadding: numberbackground: stringlayerColors: Readonly<Record<string, string>>title: string | undefinedariaLabel: string | undefinedparams: Readonly<Record<string, ParamValue>>
ShapeData
interface ShapeDataA shape as shipped with the library.
id: stringversion: numbercategory: stringnames: { readonly en: string; readonly ckb: KurdishName; readonly kmr: KurdishName; }aliases: readonly string[]tags: readonly string[]layers: readonly string[]symmetry: stringparameters: Readonly<Record<string, ParameterDecl>>primitives: readonly Primitive[]
StarPrimitive
interface StarPrimitivetype: 'star'cx: numbercy: numberpoints: CountouterRadius: numberinnerRadius: numberrotation: numberpaint?: Paintid?: stringlayer?: stringwhen?: Readonly<Record<string, ParamValue | readonly (string | number)[]>>: Draw only when every listed parameter has the value (or one of the values).
SvgHooks
interface SvgHooksHooks for svgDocument; used by exporters that need named layer groups.
rootAttrs?: string: Extra attributes on the root<svg>, starting with a space.layerAttrs?: (layer: string) => string: Extra attributes for the group oflayer, starting with a space. When given, every layer gets its own group and the rotation/flip transform moves onto each group.
UsePrimitive
interface UsePrimitivetype: 'use'shape: stringparams?: Readonly<Record<string, ParamValue>>transform?: UseTransformid?: stringlayer?: stringwhen?: Readonly<Record<string, ParamValue | readonly (string | number)[]>>: Draw only when every listed parameter has the value (or one of the values).
UseTransform
interface UseTransformPlacement of a referenced shape: p' = R(rotate) * (scale * (p - origin)) + origin + translate.
translate?: Vecscale?: numberrotate?: numberorigin?: Vec
Types
Count
type Count = number | { readonly param: string }A count, either fixed or read from a parameter.
DeqErrorCode
type DeqErrorCode = "UNKNOWN_SHAPE" | "INVALID_OPTIONS" | "INVALID_PARAMETER" | "INVALID_SHAPE" | "LIMIT_EXCEEDED"Why an operation failed.
Flat
type Flat = FlatPoly | FlatCircle | FlatArc | FlatEllipse | FlatPathOne drawable item in canvas units.
Paint
type Paint = "stroke" | "fill"How a closed primitive is painted.
ParamValue
type ParamValue = number | boolean | stringA shape parameter value.
ParameterDecl
type ParameterDecl = | { readonly type: "integer"; readonly min: number; readonly max: number; readonly default: number; readonly description: string; } | { readonly type: "boolean"; readonly default: boolean; readonly description: string } | { readonly type: "enum"; readonly values: readonly string[]; readonly default: string; readonly description: string; }A shape-specific parameter declaration.
Params
type Params = Readonly<Record<string, ParamValue>>Parameter values by name.
Primitive
type Primitive = | LinePrimitive | PolylinePrimitive | PolygonPrimitive | PathPrimitive | CirclePrimitive | DotPrimitive | ArcPrimitive | EllipsePrimitive | RectPrimitive | StarPrimitive | RadialPrimitive | RepeatPrimitive | ConcentricPrimitive | UsePrimitiveOne typed element of a shape.
Segment
type Segment = | readonly ["M", Vec] | readonly ["L", Vec] | readonly ["Q", Vec, Vec] | readonly ["C", Vec, Vec, Vec] | readonly ["Z"]A path segment with absolute points.
Vec
type Vec = readonly [number, number]A point or vector in grid units.
Guhertoyeke nû ya vê malperê heye.