@0xdolan/deq-generator
Deq Leet text and seeded patterns of Deq motifs (ADR 0015). Pure ESM, no DOM, no I/O.
import { leet, decodeLeet, pattern } from "@0xdolan/deq-generator";const { svg } = leet("Deq", { level: "basic" });decodeLeet(svg).text; // "DEQ"pattern({ kind: "band", seed: 42 }).svg;Source: packages/generator. Install with npm install @0xdolan/deq-generator.
Functions
decodeLeet
function decodeLeet(svg: string, options?: SceneOptions): DecodedLeetRead the text back from Leet SVG written by leet at the basic level. Each
glyph group is matched against the table’s basic glyphs rendered with options, which
must be the render options used to write it (default options by default). The SVG is
treated as text and only matched against what leet writes.
@throws {DeqError} INVALID_OPTIONS when the input is not Deq Leet SVG, or
LIMIT_EXCEEDED (input over MAX_DECODE_INPUT, more than MAX_GLYPHS glyphs).
detectScript
function detectScript(text: string): ScriptPick the script of text: Sorani when it has Arabic-script letters, else Latin.
entryOf
function entryOf(script: Script, char: string): LeetEntry | undefinedThe entry for an already normalised character, if the table has one.
expandGlyph
function expandGlyph(glyph: Glyph): readonly Flat[]The flat geometry of a glyph in its own 24 x 24 cell.
glyphMarkup
function glyphMarkup(glyph: Glyph, o: ResolvedOptions): stringThe inner markup of a glyph’s group, as written by sceneSvg.
glyphShape
function glyphShape(glyph: Glyph): ShapeDataThe shape description of a glyph: one use primitive per part.
leet
function leet(text: string, options?: LeetOptions): LeetResultWrite text with Deq glyphs. The input is plain text: it is length-capped, normalised
(NFC, upper case, aliases) and never parsed as markup. Characters without a glyph are
left out and listed in unknown; Sorani lines run right to left.
leet("Deq", { level: "advanced", seed: 42 }).svg;@throws {DeqError} INVALID_OPTIONS (also when nothing is left to draw) or
LIMIT_EXCEEDED.
leetTable
function leetTable(script: Script): LeetTableThe table of script.
normalize
function normalize(input: string, script: Script): NormalizedNormalise input for script: NFC, line breaks to \n, joiners and tatweel removed,
upper case, then the table’s aliases. Input is plain text and is never parsed as markup.
@throws {DeqError} LIMIT_EXCEEDED for input longer than MAX_INPUT, more than
MAX_GLYPHS glyphs or more than MAX_LINES lines.
pattern
function pattern(options?: PatternOptions): PatternResultGenerate a pattern of Deq motifs. band repeats motifs in a row (alternating or
mirrored), grid lays a checkerboard, rosette rings petals round a centre and
border frames a rectangle with corner and edge motifs.
pattern({ kind: "rosette", seed: 7, petals: 12 }).svg;@throws {DeqError} INVALID_OPTIONS, UNKNOWN_SHAPE or LIMIT_EXCEEDED.
prepareScene
function prepareScene(scene: Scene, options?: SceneOptions, title?: string): PreparedPrepare scene for exporters: the geometry of every cell moved into place, one layer
cN per cell and colors as layer colours, on a width x height canvas. With no
colours the layers stay ungrouped, like a single shape; sceneSvg is the SVG
writer, this is for the other formats.
@throws {DeqError} like sceneSvg.
resolveSceneOptions
function resolveSceneOptions(options?: SceneOptions): ResolvedSceneOptionsValidate scene options.
@throws {DeqError} INVALID_OPTIONS.
sceneSvg
function sceneSvg(scene: Scene, options?: SceneOptions, title?: string, rootAttrs?: string): stringWrite scene as SVG. Each cell is a <g data-layer="cN" transform="translate(x y)">
in cell order, so exporters keep one layer per glyph.
@throws {DeqError} INVALID_OPTIONS, UNKNOWN_SHAPE, INVALID_PARAMETER or
LIMIT_EXCEEDED (more than MAX_SCENE_ITEMS elements).
Classes
Random
class RandomA deterministic stream of unsigned 32-bit integers.
#state: numbernext: () => number: The next unsigned 32-bit integer.below: (n: number) => number: An integer in0 .. n - 1(n≥ 1).pick: <T>(list: readonly T[]) => T: One element of a non-empty list.
Constants
MAX_DECODE_INPUT
const MAX_DECODE_INPUT: numberLargest SVG decodeLeet reads, in UTF-16 code units.
MAX_GLYPHS
const MAX_GLYPHS: 256The most glyphs one text may draw.
MAX_INPUT
const MAX_INPUT: 1024The longest input accepted, in UTF-16 code units.
MAX_LINES
const MAX_LINES: 32The most lines one text may have.
MAX_SCENE_ITEMS
const MAX_SCENE_ITEMS: 20000The most drawing elements one scene may expand to.
MAX_SEED
const MAX_SEED: 4294967295Largest seed; seeds are unsigned 32-bit integers.
packageName
const packageName: '@0xdolan/deq-generator'The npm package name.
Interfaces
Cell
interface CellOne glyph placed in a scene; the glyph’s 24 x 24 cell has its top left at (x, y).
x: numbery: numberglyph: Glyph
DecodedLeet
interface DecodedLeetThe result of decodeLeet.
text: string: The text; glyphs that are not basic glyphs read as U+FFFD.script: Scriptunmatched: number: How many glyph groups were not basic glyphs of the table.
GlyphPart
interface GlyphPartOne shape placed in a 24 x 24 glyph cell, about the centre [12, 12].
shape: stringparams?: Readonly<Record<string, ParamValue>>transform?: { readonly translate?: readonly [number, number]; readonly scale?: number; readonly rotate?: number; }
LeetEntry
interface LeetEntryOne character of a table with its glyph at each level.
char: stringfit: 'good' | 'fair' | 'rough' | 'count': How well the basic glyph reads as the character;countmarks dot-count digits.basic: Glyphadvanced: readonly Glyph[]: Alternatives for the advanced level; empty means the basic glyph.full: Glyph
LeetResult
interface LeetResultThe result of leet.
svg: string: The SVG document, one<g data-layer="cN">per glyph in reading order.text: string: The normalised text that was drawn.script: Scriptlevel: LeetLevelunknown: readonly string[]: Input characters with no glyph, in first-seen order (they are left out).scene: Scene: The placed glyphs.
LeetTable
interface LeetTableThe mapping table of one script.
version: numberscript: Scriptdirection: 'ltr' | 'rtl'aliases: Readonly<Record<string, string>>: Characters read as another character of the table (after case folding).glyphs: readonly LeetEntry[]
Normalized
interface NormalizedThe result of normalize.
lines: readonly (readonly Token[])[]: Lines of tokens, without leading or trailing spaces or empty lines.text: string: The normalised text (what decodingbasicoutput gives back).unknown: readonly string[]: Characters with no glyph in the table, in first-seen order.
PatternResult
interface PatternResultThe result of pattern.
svg: string: The SVG document, one<g data-layer="cN">per motif.motifs: readonly string[]: The motifs chosen, in the order the pattern uses them.scene: Scene
ResolvedSceneOptions
interface ResolvedSceneOptionsValidated scene options.
render: ResolvedOptionscolors: readonly string[]
Scene
interface SceneGlyphs on a width x height canvas in grid units.
width: numberheight: numbercells: readonly Cell[]
Types
Glyph
type Glyph = readonly GlyphPart[]A glyph: one or more shapes on the 24 x 24 grid.
LeetLevel
type LeetLevel = "basic" | "advanced" | "full"How much a text is transformed.
LeetOptions
type LeetOptions = SceneOptions & { /** Default `basic`: one readable glyph per character, which {@link decodeLeet} reads back. */ readonly level?: LeetLevel; /** Default: Sorani when the text has Arabic-script letters, else Latin. */ readonly script?: Script; /** Seed for the alternatives of the `advanced` level (unsigned 32-bit). Default 1. */ readonly seed?: number; /** Space between glyphs in grid units (0..24). Default 2. */ readonly letterSpacing?: number; /** Space between lines in grid units (0..48). Default 6. */ readonly lineSpacing?: number; /** Line alignment; `start` is the left for Latin and the right for Sorani. Default `start`. */ readonly align?: "start" | "center" | "end"; }Options of leet; the render options apply to the whole text.
PatternKind
type PatternKind = "band" | "grid" | "rosette" | "border"The kinds of pattern.
PatternOptions
type PatternOptions = SceneOptions & { /** Default `band`. */ readonly kind?: PatternKind; /** Seed (unsigned 32-bit). The same seed and options give the same pattern. Default 1. */ readonly seed?: number; /** Shapes to choose motifs from (1..64 catalog ids). Default: every catalog shape. */ readonly motifs?: readonly string[]; /** Band: number of cells, odd, 3..63. Default 9. */ readonly count?: number; /** Grid and border: columns, 1..32 (border: 3..32). Default 5 (border: 7). */ readonly cols?: number; /** Grid and border: rows, 1..32 (border: 3..32). Default 5 (border: 3). */ readonly rows?: number; /** Rosette: number of petals, 3..24. Default 8. */ readonly petals?: number; /** Space between cells in grid units (0..24). Default 2. */ readonly spacing?: number; }Options of pattern; the render options apply to the whole pattern.
SceneOptions
type SceneOptions = Omit< RenderOptions, "rotation" | "flipX" | "flipY" | "params" | "layerColors" > & { /** Colours given to the cells in turn (at most 16). Default: every cell uses `color`. */ readonly colors?: readonly string[]; }Options for scene output: the render options of a single shape, except the per-shape
rotation, flipX, flipY, params and layerColors, plus colors.
Script
type Script = "latin" | "sorani"A script with a Leet table.
Token
type Token = | { readonly kind: "char"; readonly char: string; readonly entry: LeetEntry } | { readonly kind: "space" }One unit of normalised text: a table character, a space or a line break.
A new version of this site is available.