font.d.ts

6.9 kB · typescript · 158 lines

1export { default, initSync } from "./pkg/font/mrlyjs_font.js";23/** An rgba color as four bytes. */4export type Color = [number, number, number, number];5/** A tensor: its shape and its flat data as a typed array of its dtype. */6export interface Tensor {7    shape: number[];8    data: Uint8Array | Uint16Array | Uint32Array | Int32Array;9}10/** A cell: the shape, the type bytes, and the flat rgba colors and the tags when present. */11export interface Cell {12    shape: number[];13    types: Uint8Array | Uint16Array | Uint32Array | Int32Array;14    colors?: Uint8Array;15    tags?: Uint8Array | Uint16Array | Uint32Array | Int32Array;16}17/** A hex cell: a flat cell with its projection, orientation and start row. */18export interface Cell6d {19    cell: Cell;20    projection: "Iso" | "Pro" | "Cut";21    orientation: "Horizontal" | "Vertical";22    start: number;23}24/** A color inside plain data, serde's form. */25export interface ColorData {26    r: number;27    g: number;28    b: number;29    a: number;30}31/** A tensor inside plain data, serde's form. */32export interface TensorData {33    shape: number[];34    data: { U8: number[] } | { U16: number[] } | { U32: number[] } | { I32: number[] };35}36/** A cell inside plain data, serde's form. */37export interface CellData {38    types: TensorData;39    colors?: number[][];40    tags?: TensorData;41}42/** A hex cell inside plain data, serde's form. */43export interface Cell6dData {44    cell: { cell: CellData };45    projection: "Iso" | "Pro" | "Cut";46    orientation: "Horizontal" | "Vertical";47    start: number;48}49/** A seeded random stream, opened from a number or a bigint seed. */50export class Rng {51    constructor(seed: number | bigint | string);52    free(): void;53    /** Draws a float at or above zero and below one. */54    unit(): number;55    /** Draws an integer below n, or zero when n is zero. */56    below(n: number): number;57    /** Draws an integer between lo and hi inclusive, or lo when hi is not above lo. */58    range(lo: number, hi: number): number;59    /** Draws a fair coin flip. */60    boolean(): boolean;61    /** Returns true with probability p. */62    chance(p: number): boolean;63    /** Draws amount distinct indices below length, or every index when amount is larger. */64    sample_indices(length: number, amount: number): Uint32Array;65    /** Draws one item of the array, the same draw as Rust's choice. */66    choice<T>(items: ArrayLike<T>): T;67    /** Shuffles the array in place, the same permutation as Rust's shuffle. */68    shuffle<T>(items: T[]): void;69}70/** Builds every glyph in font order: uppers, lowers, digits, extras, specials. */71export function all(): Glyph[];72/** Writes the text in stroke order, one cell per frame, from an empty padded board to the full raster. */73export function animate(text: string, pad: number): Anim;74/** Chains the write, the merge and their reversals into one loop, resting hold frames after each movement that has any. */75export function cycle(write: Anim, merge: ArrayLike<number>[], hold: number): Anim;76/** Builds the ten digit glyphs. */77export function digits(): Glyph[];78/** Drafts a stroke order for a trimmed bitmap by walking its lit cells: start at a lowest-left free end, keep heading, lift when stuck. */79export function draft(rows: string[]): [number, number][][];80/** Builds the punctuation, symbol and arrow glyphs. */81export function extras(): Glyph[];82/** Returns the least strokes that can write a trimmed bitmap: the minimum cover of its lit cells by 4-adjacent paths, zero for a blank. */83export function floor(rows: string[]): number;84/** Returns an owned copy of the character's glyph, or None outside the font. */85export function glyph(c: string): Glyph | undefined;86/** Blanks the four corner cells of an uppercase bitmap into its rounded lowercase form. */87export function lower(rows: string[]): string[];88/** Builds the twenty-six lowercase glyphs by rounding the uppers' corners. */89export function lowers(): Glyph[];90/** Returns the whole font as a map from character to bitmap rows. */91export function map(): Record<string, string[]>;92/** Folds the written text's glyphs, frame by frame, into one centered stack. */93export function merge(text: string, pad: number): Uint32Array[];94/** Returns the character's Unicode name, or a U+ code point label for a character outside the font. */95export function name_of(c: string): string;96/** Flattens the character's strokes into one cell-by-cell drawing order. */97export function path(c: string): [number, number][];98/** Returns the text as a 0/1 grid, its trimmed glyphs one blank column apart. */99export function raster(text: string): Uint8Array[];100/** Builds the four seven-row glyphs: dollar, at, copyright and registered. */101export function specials(): Glyph[];102/** Returns the character's ordered strokes over its trimmed bitmap, or none for a character outside the font. */103export function strokes(c: string): [number, number][][];104/** Returns every character in the font, in font order. */105export function supported(): string[];106/** Cuts blank edge columns from a bitmap, collapsing an all-blank one to a single '0' column; a row shorter than the cut keeps what it has. */107export function trim(rows: string[]): string[];108/** Builds the twenty-six uppercase glyphs. */109export function uppers(): Glyph[];110/** The playback rate of every animation, in frames per second. */111export function FPS(): number;112/** The default number of frames a cycle rests between movements. */113export function HOLD(): number;114/** A frame-by-frame animation over a fixed board. */115export interface Anim {116    /** The board height in cells. */117    rows: number;118    /** The board width in cells. */119    cols: number;120    /** The playback rate in frames per second. */121    fps: number;122    /** The frames, each a sorted list of lit row-major cell indices. */123    frames: number[][];124}125export interface GlyphData {126    /** The character the glyph draws. */127    char: string;128    /** The bitmap rows of '0' and '1' characters. */129    rows: string[];130}131/** One character's pixel bitmap. */132export class Glyph {133    /** Builds a glyph from its character and rows. */134    constructor(char: string, rows: string[]);135    free(): void;136    /** Reads the Glyph from its plain data. */137    static from(data: GlyphData): Glyph;138    /** Writes the Glyph as plain data. */139    toJSON(): GlyphData;140    /** The character the glyph draws. */141    get char(): string;142    set char(value: string);143    /** The bitmap rows of '0' and '1' characters. */144    get rows(): string[];145    set rows(value: string[]);146    /** Returns the number of rows. */147    height(): number;148    /** Returns the cell width of the first row, or 0 for an empty glyph. */149    width(): number;150}151export declare namespace paths {152    /** Returns the character's hand-penned strokes from the pen tables, or None outside the font. */153    export function penned(c: string): [number, number][][] | undefined;154}155export declare namespace pens {156    /** Returns every pen in font order: uppers, lowers, digits, extras, specials. */157    export function all(): [string, string[]][];158}