gen.d.ts
22.8 kB · typescript · 521 lines
1export { default, initSync } from "./pkg/gen/mrlyjs_gen.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/** Draws one seeded artwork and returns its PNG bytes: a random flat tile under the default recipe */71export function background(seed: number | bigint, width: number, height: number): Uint8Array;72/** Returns the plane's bang code of a classic design, or None for one outside the plane. */73export function classic_code(design: recipe.Design): string | undefined;74/** Returns the bang code of a named design in a dimension, or None where it has no design. */75export function classic_code_nd(design: recipe.Design, dimension: number): string | undefined;76/** Draws a hex key of the given length from the stream. */77export function hex_key(length: number, rng: Rng): string;78/** Draws one of the four flat classics from the stream: carpet, net, vertical tree or void. */79export function random_design(rng: Rng): recipe.Design;80/** Draws a design's turn from the stream: a tree turns 0 or 1, every other design 0 to 3. */81export function random_rotation(design: recipe.Design, rng: Rng): number;82/** Builds the mask of a mosaic tile: the two trees of the side, two where they cross. */83export function tree_mask(n: number): Tensor;84/** The five construction families a tile can belong to. */85export type Group = "General" | "Fractal" | "Magic" | "Special" | "Mosaic";86export const Group: {87 /** Returns every Group in canonical order. */88 all(): Group[];89};90/** The parity filter over candidate sizes. */91export type Parity = "Evens" | "Odds" | "Both";92export const Parity: {93 /** Returns every Parity in canonical order. */94 all(): Parity[];95 /** Returns true when the number passes the filter. */96 keep(parity: Parity, n: number): boolean;97};98export interface TileData {99 /** The construction family. */100 group: Group;101 /** The base factor of the construction. */102 factor: number;103 /** The origin of each layer. */104 sources: recipe.Source[];105 /** The grid size of each source. */106 numbers: number[];107 /** The fractal level of each source. */108 levels: number[];109 /** The quarter-turn rotation of each source. */110 rotations: number[];111 /** Whether the finished tile inverts. */112 invert: boolean;113 /** Whether the finished tile flips. */114 flip: boolean;115 /** The tile's width in cells. */116 width: number;117 /** The tile's height in cells. */118 height: number;119}120/** A complete recipe for one tile. */121export class Tile {122 /** Builds an empty tile in a group. */123 constructor(group: Group);124 free(): void;125 /** Reads the Tile from its plain data. */126 static from(data: TileData): Tile;127 /** Writes the Tile as plain data. */128 toJSON(): TileData;129 /** The construction family. */130 get group(): Group;131 set group(value: Group);132 /** The base factor of the construction. */133 get factor(): number;134 set factor(value: number);135 /** The origin of each layer. */136 get sources(): recipe.Source[];137 set sources(value: recipe.Source[]);138 /** The grid size of each source. */139 get numbers(): Uint32Array;140 set numbers(value: ArrayLike<number>);141 /** The fractal level of each source. */142 get levels(): Uint32Array;143 set levels(value: ArrayLike<number>);144 /** The quarter-turn rotation of each source. */145 get rotations(): Uint32Array;146 set rotations(value: ArrayLike<number>);147 /** Whether the finished tile inverts. */148 get invert(): boolean;149 set invert(value: boolean);150 /** Whether the finished tile flips. */151 get flip(): boolean;152 set flip(value: boolean);153 /** The tile's width in cells. */154 get width(): number;155 set width(value: number);156 /** The tile's height in cells. */157 get height(): number;158 set height(value: number);159 /** Checks that the slots, numbers and sizes agree. */160 check(): void;161 /** Returns whether the recipe is a magic tile of one repeated source at one repeated number, */162 degenerate(): boolean;163 /** Returns the larger of width and height. */164 max_size(): number;165 /** Recomputes the factor and side length the group and numbers imply, zero when they overflow. */166 resize(): void;167 /** Sets the tile's width and height. */168 size(width: number, height: number): Tile;169}170export declare namespace build {171 /** Builds the flat cell the tile describes. */172 export function build_2d(tile: Tile): Cell;173 /** Builds the cube the tile describes. */174 export function build_3d(tile: Tile): Cell;175 /** Builds the tile's cube and flattens it through its projection. */176 export function build_6d(hex: build.HexTile): Cell6d;177 /** Draws a random flat tile from the stream, rotations from the four quarter-turns. */178 export function create_2d(config: draw.ConfigNd, rng: Rng): Tile;179 /** Draws a cube tile from the config with cube orientations drawn from the stream. */180 export function create_3d(config: draw.ConfigNd, rng: Rng): Tile;181 /** Draws a cube tile from the config under a projection drawn from the stream. */182 export function create_6d(config: draw.ConfigNd, rng: Rng): build.HexTile;183 /** Draws a random flat tile up to the given size under the default config. */184 export function random_tile_2d(max_size: number, rng: Rng): Tile;185 /** Draws a random cube tile up to the given size. */186 export function random_tile_3d(max_size: number, rng: Rng): Tile;187 /** Draws a random cube tile up to the given size under a random projection. */188 export function random_tile_6d(max_size: number, rng: Rng): build.HexTile;189 export type Config2d = draw.ConfigNd;190 export const Config2d: {191 /** Returns the default Config2d. */192 default(): draw.ConfigNd;193 };194 export type Config3d = draw.ConfigNd;195 export const Config3d: {196 /** Returns the default Config3d. */197 default(): draw.ConfigNd;198 };199 /** A cube tile paired with the projection that flattens it. */200 export interface HexTile {201 /** The projection that flattens the tile. */202 projection: math.six.Projection;203 /** The cube tile underneath. */204 tile: TileData;205 }206}207export declare namespace core {208 export namespace paint {209 /** The constraints a caller may put on a random paint. */210 export interface Config {211 /** The editions allowed, or None for all seven. */212 editions?: core.paint.Edition[];213 /** The primary inks allowed, or None for black and white. */214 primaries?: core.paint.Ink[];215 /** The forced target, or None for a coin flip. */216 target?: core.paint.Target;217 }218 /** The seven ways a paint distributes its colors over a cell. */219 export type Edition = "Simple" | "Index" | "Layers" | "Neighbors" | "Rows" | "Columns" | "Random";220 /** The fifteen named inks a paint draws from. */221 export type Ink = "Black" | "White" | "Red" | "Orange" | "Yellow" | "Green" | "Mint" | "Teal" | "Cyan" | "Blue" | "Indigo" | "Purple" | "Pink" | "Brown" | "Gray";222 export interface PaintData {223 /** The coloring edition. */224 edition: core.paint.Edition;225 /** The secondary color scheme. */226 scheme: core.paint.Scheme;227 /** The side the primary ink lands on. */228 target: core.paint.Target;229 /** The primary ink. */230 primary: core.paint.Ink;231 /** The secondary inks. */232 secondary: core.paint.Ink[];233 /** The shade indices of a multitone ramp. */234 shades: number[];235 }236 /** A complete coloring recipe for one cell. */237 export class Paint {238 private constructor();239 free(): void;240 /** Reads the Paint from its plain data. */241 static from(data: PaintData): Paint;242 /** Writes the Paint as plain data. */243 toJSON(): PaintData;244 /** The coloring edition. */245 get edition(): core.paint.Edition;246 set edition(value: core.paint.Edition);247 /** The secondary color scheme. */248 get scheme(): core.paint.Scheme;249 set scheme(value: core.paint.Scheme);250 /** The side the primary ink lands on. */251 get target(): core.paint.Target;252 set target(value: core.paint.Target);253 /** The primary ink. */254 get primary(): core.paint.Ink;255 set primary(value: core.paint.Ink);256 /** The secondary inks. */257 get secondary(): core.paint.Ink[];258 set secondary(value: core.paint.Ink[]);259 /** The shade indices of a multitone ramp. */260 get shades(): Uint32Array;261 set shades(value: ArrayLike<number>);262 }263 /** The two ways secondary colors are drawn. */264 export type Scheme = "Multicolor" | "Multitone";265 /** The side of the figure the primary ink lands on. */266 export type Target = "Fill" | "Void";267 }268}269export declare namespace draw {270 /** The constraints a random tile is drawn under. */271 export interface ConfigNd {272 /** The tile groups allowed. */273 groups: Group[];274 /** The catalog the sources are drawn from. */275 catalog: recipe.Catalog;276 /** The smallest allowed side. */277 min_size: number;278 /** The largest allowed side. */279 max_size: number;280 /** The parity the sizes must keep. */281 parity: Parity;282 /** The forced inversion flag, or None to flip a coin. */283 invert?: boolean;284 }285}286export declare namespace math {287 export namespace six {288 /** The three ways a cube flattens to a hexagon. */289 export type Projection = "Iso" | "Pro" | "Cut";290 }291}292export declare namespace name {293 /** One value for every slot of a tile, or one value per slot. */294 export type Slots = number | number[];295 export const Slots: {296 /** Returns the default Slots. */297 default(): name.Slots;298 };299 export interface TileData {300 /** The kind word. */301 kind: string;302 /** The one design of a flat or fractal tile. */303 code?: bigint;304 /** The mask code of a special tile. */305 special?: bigint;306 /** The letters of a magic tile, first letter outermost. */307 magic: bigint[];308 /** The three codes of a mosaic tile. */309 mosaic: bigint[];310 /** The side of the mask of a special or mosaic tile. */311 factor?: number;312 /** The side each slot renders at, one per letter for a magic tile. */313 side: name.Slots;314 /** The power a fractal tile is raised to, absent at one. */315 level?: number;316 /** The quarter turns of each slot, absent when nothing turns. */317 turn: name.Slots;318 /** Whether a special tile flips its mask. */319 flip: boolean;320 /** Whether the finished tile inverts. */321 invert: boolean;322 }323 /** A tile recipe folded to its one canonical object. */324 export class Tile {325 private constructor();326 free(): void;327 /** Reads the Tile from its plain data. */328 static from(data: TileData): Tile;329 /** Writes the Tile as plain data. */330 toJSON(): TileData;331 /** The one design of a flat or fractal tile. */332 get code(): string | undefined;333 set code(value: string | number | bigint | undefined);334 /** The mask code of a special tile. */335 get special(): string | undefined;336 set special(value: string | number | bigint | undefined);337 /** The letters of a magic tile, first letter outermost. */338 get magic(): string[];339 set magic(value: (string | number | bigint)[]);340 /** The three codes of a mosaic tile. */341 get mosaic(): string[];342 set mosaic(value: (string | number | bigint)[]);343 /** The side of the mask of a special or mosaic tile. */344 get factor(): number | undefined;345 set factor(value: number | undefined);346 /** The side each slot renders at, one per letter for a magic tile. */347 get side(): name.Slots;348 set side(value: name.Slots);349 /** The power a fractal tile is raised to, absent at one. */350 get level(): number | undefined;351 set level(value: number | undefined);352 /** The quarter turns of each slot, absent when nothing turns. */353 get turn(): name.Slots;354 set turn(value: name.Slots);355 /** Whether a special tile flips its mask. */356 get flip(): boolean;357 set flip(value: boolean);358 /** Whether the finished tile inverts. */359 get invert(): boolean;360 set invert(value: boolean);361 /** Folds a decoded value to its canonical form, or an error for one outside the kind. */362 checked(): name.Tile;363 /** Reads a filename back into the value, or an error. */364 static from_file(text: string): name.Tile;365 /** Reads a JSON object into its canonical value, or an error naming the broken key. */366 static from_json(text: string): name.Tile;367 /** Reads a path and query string back into the value, or an error. */368 static from_url(text: string): name.Tile;369 /** Folds a recipe to its name. */370 static of(recipe: Tile): name.Tile;371 /** Builds the recipe the name folds, resized and checked. */372 recipe(): Tile;373 /** Prints the kind and the `key=value` pairs joined by underscores, lists in brackets, or an error when the name does not read back. */374 to_file(): string;375 /** Prints the first eight hex digits of the sha256 of the canonical JSON. */376 to_id(): string;377 /** Prints the canonical JSON object. */378 to_json(): string;379 /** Prints the kind and the keys as a line of prose for pages, or an error when the name does not read back. */380 to_mrly(): string;381 /** Prints the kind as a path and the keys as a query string, lists comma-joined, or an error when the name does not read back. */382 to_url(): string;383 }384}385export declare namespace recipe {386 /** Returns the classic designs for a dimension. */387 export function classics(dimension: number): recipe.Design[];388 /** Returns every flat size in the range that passes the parity filter. */389 export function generals(min_size: number, max_size: number, parity: Parity): Uint32Array;390 /** Returns every factor list of depth two and beyond whose product lands in the size range. */391 export function nestings(min_size: number, max_size: number, parity: Parity): Uint32Array[];392 /** Returns every factor and level whose power lands in the size range. */393 export function powers(min_size: number, max_size: number, parity: Parity): [number, number][];394 /** Returns every count-long factor list whose product lands in the size range. */395 export function products(min_size: number, max_size: number, count: number, parity: Parity): Uint32Array[];396 /** Returns the side a factor raised to a level makes, or None when no usize holds it. */397 export function size(number: number | bigint, level: number | bigint): number | undefined;398 /** The five classic designs of the plane. */399 export function CLASSICS_2D(): recipe.Design[];400 /** The six classic designs of the cube. */401 export function CLASSICS_3D(): recipe.Design[];402 /** The deepest fractal level a tile may take. */403 export function MAX_LEVEL(): number;404 /** The largest side, number or factor a tile may take. */405 export function MAX_SIDE(): number;406 /** The most slots a magic tile may take. */407 export function MAX_SLOTS(): number;408 /** The smallest side, number or factor a tile may take. */409 export function MIN_SIDE(): number;410 /** The pool of sources a tile may draw from. */411 export type Catalog = "Classics" | "Universe" | { Codes: bigint[] } | { Designs: recipe.Design[] };412 /** The named designs a source can point at: the four classics and their four antis. */413 export type Design = "Carpet" | "Net" | "Htree" | "Vtree" | "Void" | "Xtree" | "Ytree" | "Ztree" | "Point" | "Dust" | "Hline" | "Vline" | "Star" | "Xline" | "Yline" | "Zline";414 export const Design: {415 /** Returns every Design in canonical order. */416 all(): recipe.Design[];417 };418 /** The origin of one tile layer, a one-field json object. */419 export type Source = { design: recipe.Design } | { code: bigint };420}421export declare namespace variation {422 /** Draws a variation's seed from the stream, then the variation itself on that seed, with a */423 export function create(config: variation.Config, rng: Rng): variation.Variation;424 /** Builds the variation's base cell and draws its paint from the stream, painting the base */425 export function generate(variation: variation.Variation, config: variation.Config, rng: Rng): variation.Variation;426 /** Renders every file of the variation to PNG at the given scale, scattering a Random edition */427 export function render(variation: variation.Variation, scale: number, rng: Rng): variation.Variation;428 /** The settings an artwork is drawn under. */429 export interface Config {430 /** The constraints the tile is drawn under. */431 tile: draw.ConfigNd;432 /** The constraints the paint is drawn under. */433 paint: core.paint.Config;434 /** The width and height repetition pairs to render. */435 files: [number, number][];436 }437 export const Config: {438 /** Returns the default Config. */439 default(): variation.Config;440 };441 export interface FileData {442 /** The count of tile repetitions across. */443 width: number;444 /** The count of tile repetitions down. */445 height: number;446 }447 /** One rendering of an artwork, sized in tile repetitions. */448 export class File {449 /** Builds a file of the given repetition counts with no PNG bytes. */450 constructor(width: number, height: number);451 free(): void;452 /** Reads the File from its plain data. */453 static from(data: FileData): File;454 /** Writes the File as plain data. */455 toJSON(): FileData;456 /** The count of tile repetitions across. */457 get width(): number;458 set width(value: number);459 /** The count of tile repetitions down. */460 get height(): number;461 set height(value: number);462 /** The encoded PNG bytes, empty until rendered and left out of the json. */463 get png(): Uint8Array;464 set png(value: ArrayLike<number>);465 }466 export interface VariationData {467 /** The random hex identifier. */468 key: string;469 /** The seed the variation is drawn under. */470 seed: number;471 /** The paint edition. */472 edition: core.paint.Edition;473 /** The primary inks, when the config fixes them. */474 primaries?: core.paint.Ink[];475 /** The tile recipe. */476 tile: TileData;477 /** The mask tile, present only under the Neighbors edition. */478 mask?: TileData;479 /** The paint, set by generate. */480 paint?: core.paint.PaintData;481 /** The renderings, filled by render. */482 files: variation.FileData[];483 }484 /** One seeded artwork, from tile recipe to rendered files. */485 export class Variation {486 private constructor();487 free(): void;488 /** Reads the Variation from its plain data. */489 static from(data: VariationData): Variation;490 /** Writes the Variation as plain data. */491 toJSON(): VariationData;492 /** The random hex identifier. */493 get key(): string;494 set key(value: string);495 /** The seed the variation is drawn under. */496 get seed(): bigint;497 set seed(value: number | bigint);498 /** The paint edition. */499 get edition(): core.paint.Edition;500 set edition(value: core.paint.Edition);501 /** The primary inks, when the config fixes them. */502 get primaries(): core.paint.Ink[] | undefined;503 set primaries(value: core.paint.Ink[] | undefined);504 /** The tile recipe. */505 get tile(): Tile;506 set tile(value: Tile);507 /** The mask tile, present only under the Neighbors edition. */508 get mask(): Tile | undefined;509 set mask(value: Tile | undefined);510 /** The built base cell, set by generate and left out of the json. */511 get base(): Cell | undefined;512 set base(value: Cell | undefined);513 /** The renderings, filled by render. */514 get files(): variation.File[];515 set files(value: variation.File[]);516 /** Returns whether the edition paints the whole tiled canvas. */517 is_cover(): boolean;518 /** Returns whether the edition paints the base cell before tiling. */519 is_prime(): boolean;520 }521}