Biçe naverokê

Ev werger bi alîkariya AI hatiye amadekirin û divê axêverekî zikmakî lê binêre.

@0xdolan/deq-generator

Ev naverok hêj bi zimanê te tune.

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

Read 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): Script

Pick the script of text: Sorani when it has Arabic-script letters, else Latin.

entryOf

function entryOf(script: Script, char: string): LeetEntry | undefined

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

The inner markup of a glyph’s group, as written by sceneSvg.

glyphShape

function glyphShape(glyph: Glyph): ShapeData

The shape description of a glyph: one use primitive per part.

leet

function leet(text: string, options?: LeetOptions): LeetResult

Write 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): LeetTable

The table of script.

normalize

function normalize(input: string, script: Script): Normalized

Normalise 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): PatternResult

Generate 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): Prepared

Prepare 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): ResolvedSceneOptions

Validate scene options.

@throws {DeqError} INVALID_OPTIONS.

sceneSvg

function sceneSvg(scene: Scene, options?: SceneOptions, title?: string, rootAttrs?: string): string

Write 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 Random

A deterministic stream of unsigned 32-bit integers.

  • #state: number
  • next: () => number: The next unsigned 32-bit integer.
  • below: (n: number) => number: An integer in 0 .. 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: number

Largest SVG decodeLeet reads, in UTF-16 code units.

MAX_GLYPHS

const MAX_GLYPHS: 256

The most glyphs one text may draw.

MAX_INPUT

const MAX_INPUT: 1024

The longest input accepted, in UTF-16 code units.

MAX_LINES

const MAX_LINES: 32

The most lines one text may have.

MAX_SCENE_ITEMS

const MAX_SCENE_ITEMS: 20000

The most drawing elements one scene may expand to.

MAX_SEED

const MAX_SEED: 4294967295

Largest seed; seeds are unsigned 32-bit integers.

packageName

const packageName: '@0xdolan/deq-generator'

The npm package name.

Interfaces

Cell

interface Cell

One glyph placed in a scene; the glyph’s 24 x 24 cell has its top left at (x, y).

  • x: number
  • y: number
  • glyph: Glyph

DecodedLeet

interface DecodedLeet

The result of decodeLeet.

  • text: string: The text; glyphs that are not basic glyphs read as U+FFFD.
  • script: Script
  • unmatched: number: How many glyph groups were not basic glyphs of the table.

GlyphPart

interface GlyphPart

One shape placed in a 24 x 24 glyph cell, about the centre [12, 12].

  • shape: string
  • params?: Readonly<Record<string, ParamValue>>
  • transform?: { readonly translate?: readonly [number, number]; readonly scale?: number; readonly rotate?: number; }

LeetEntry

interface LeetEntry

One character of a table with its glyph at each level.

  • char: string
  • fit: 'good' | 'fair' | 'rough' | 'count': How well the basic glyph reads as the character; count marks dot-count digits.
  • basic: Glyph
  • advanced: readonly Glyph[]: Alternatives for the advanced level; empty means the basic glyph.
  • full: Glyph

LeetResult

interface LeetResult

The 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: Script
  • level: LeetLevel
  • unknown: readonly string[]: Input characters with no glyph, in first-seen order (they are left out).
  • scene: Scene: The placed glyphs.

LeetTable

interface LeetTable

The mapping table of one script.

  • version: number
  • script: Script
  • direction: 'ltr' | 'rtl'
  • aliases: Readonly<Record<string, string>>: Characters read as another character of the table (after case folding).
  • glyphs: readonly LeetEntry[]

Normalized

interface Normalized

The result of normalize.

  • lines: readonly (readonly Token[])[]: Lines of tokens, without leading or trailing spaces or empty lines.
  • text: string: The normalised text (what decoding basic output gives back).
  • unknown: readonly string[]: Characters with no glyph in the table, in first-seen order.

PatternResult

interface PatternResult

The 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 ResolvedSceneOptions

Validated scene options.

  • render: ResolvedOptions
  • colors: readonly string[]

Scene

interface Scene

Glyphs on a width x height canvas in grid units.

  • width: number
  • height: number
  • cells: 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.