/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * The Flowchart's model (#1502, `Flowchart Records Spec.md` R6, R7, D4, D12) — * pure and React-free: what the canvas, the inspector, Issues and the footer * draw from, made from the four records' rows with the drafts in place. * * - **The lanes** stand in their `order`, else by key (D4). A state whose lane * names no lane stands in a last band, *No lane* (D12); with no lanes given, * one band holds every state. * - **Each lane's states** stand in their `order`, else by key: the order e3 * returns a record in, kept under every index the rail picks, though a page * of a source comes in its index's order (R7). * - **By key** is at the kind's record's key type (#1549): Integer keys stand * `2`, `9`, `10`, never as their text would, each text read back once * (`kind-keys.ts`). * - **An end no state is keyed by** is a ghost, *No state row*, beside its * other end's lane, and its transition's line is unresolved. A transition * from a state to itself folds into the state's `↻ n`. * - **A row the narrowing leaves out**, under `"dim"`, draws faded: `dimmed`, * selected by no path and counted nowhere (R6). * * Stroke weights, the evidence badge and the planned · observed · unresolved * split are derived, never authored. * * @packageDocumentation */ import { type ValueTypeOf } from "@elaraai/east"; import type { Flowchart } from "@elaraai/e3-ui/internal"; import { type Formatters } from "@elaraai/east-ui-components"; import { type KindKeys } from "../shared/schedule/kind-keys.js"; import type { FlowchartWords } from "./messages.js"; /** The decoded Flowchart payload — what `` hands the renderer. */ export type FlowchartValue = ValueTypeOf; /** The decoded canvas: what the flowchart draws with besides its kinds. */ export type FlowchartCanvasValue = ValueTypeOf; /** A state's roles, as its kind reads them from the app's row. */ export type FlowchartStateRoles = ValueTypeOf; /** A transition's roles. */ export type FlowchartTransitionRoles = ValueTypeOf; /** A lane's roles. */ export type FlowchartLaneRoles = ValueTypeOf; /** A decision's roles. */ export type FlowchartDecisionRoles = ValueTypeOf; /** A transition's evidence, decoded. */ export type FlowchartEvidenceValue = ValueTypeOf; /** One row of a record as the model takes it: its key, its roles and whether the narrowing leaves it out, drawn as context. */ export interface FlowchartRow { /** Its key in its record. */ readonly key: string; /** Its roles, as its kind reads them — its draft's, where it has one. */ readonly roles: R; /** Whether the narrowing leaves it out, under `"dim"`: drawn faded, selected by no path. */ readonly dimmed: boolean; } /** Each kind's keys (#1549): each key's text, read back at its record's key type, and the keys' order by it. */ export interface FlowchartKindKeys { /** The states'. */ readonly states: KindKeys; /** The transitions'. */ readonly transitions: KindKeys; /** The lanes'. */ readonly lanes: KindKeys; /** The decisions'. */ readonly decisions: KindKeys; } /** Every kind's keys, each record keyed by String. */ export declare const STRING_KIND_KEYS: FlowchartKindKeys; /** * Each of a Flowchart's kinds' keys, as its payload says each record is keyed (#1549). * * @param value - The payload * @returns Each kind's keys: a kind the Flowchart is not given, by String */ export declare function flowchartKindKeys(value: FlowchartValue): FlowchartKindKeys; /** The four records' rows, the drafts in place: what the model is made from. */ export interface FlowchartRows { /** The states. */ readonly states: readonly FlowchartRow[]; /** The transitions; none for a flowchart given none. */ readonly transitions: readonly FlowchartRow[]; /** The lanes; `undefined` for a flowchart given none, whose one band holds every state. */ readonly lanes: readonly FlowchartRow[] | undefined; /** The decisions; none for a flowchart given none. */ readonly decisions: readonly FlowchartRow[]; /** Each kind's keys: what each kind's rows are ordered by, by key. */ readonly keys: FlowchartKindKeys; } /** Spec line classes (unresolved is derived, never authored). */ export type LinkClass = "planned" | "observed" | "unresolved"; /** One node in the view model — a state, or a ghost standing for an end no state is keyed by. */ export interface ModelNode { /** Its key: the state's, or the end's a ghost stands for. */ readonly key: string; /** Its card's name; `undefined` for an empty label. */ readonly label: string | undefined; /** Its band's place among the model's lanes. */ readonly laneIndex: number; /** Its place in its band, from the first. */ readonly laneOrder: number; /** The lane its row names, by key; `undefined` for none. */ readonly lane: string | undefined; /** Its place in its lane, as its `order` gives it; `undefined` for a kind with no `order`. */ readonly order: number | undefined; /** State-class member count (the ×N badge). */ readonly members: bigint | undefined; /** * In-place transitions (self-loops) drawn as themselves, by key, in key * order — the `↻ n` badge, their selection surface: they have no route to * click. One the narrowing leaves out draws nowhere. */ readonly inPlaceKeys: string[]; /** True for the derived "No state row" ghost. */ readonly ghost: boolean; /** Whether the narrowing leaves it out, drawn faded (R6); a ghost is, when every transition naming it is. */ readonly dimmed: boolean; } /** One routed transition in the view model (in-place ones fold into their state's `↻ n` badge). */ export interface ModelLink { /** Its key in its record: never drawn — a transition is named by its ends. */ readonly key: string; /** The state it leaves. */ readonly from: string; /** The state it enters. */ readonly to: string; /** How its line draws. */ readonly cls: LinkClass; /** The decision it names, by key — the lettered diamond, drawn while the decisions hold it. */ readonly trigger: string | undefined; /** Its evidence. */ readonly evidence: FlowchartEvidenceValue | undefined; /** Stroke weight from evidence volume — log scale 1.6 / 2 / 2.5, floor 1.4. */ readonly weight: number; /** Pre-formatted evidence badge ("17,350 parcels · 386"); undefined ⇒ no badge. */ readonly badgeText: string | undefined; /** Whether the narrowing leaves it out, drawn faded (R6). */ readonly dimmed: boolean; } /** A band of the canvas: a lane of the app's, the last band of states naming no lane, or the one band of a flowchart given no lanes. */ export type ModelBand = "lane" | "noLane" | "all"; /** One band of the canvas. */ export interface ModelLane { /** Its key: the lane's; {@link NO_LANE_KEY} or {@link ALL_LANE_KEY} for a band of no lane. */ readonly key: string; /** Its header. */ readonly label: string; /** Its place among the lanes, as its `order` gives it; `undefined` for a band of no lane, or a kind with no `order`. */ readonly order: number | undefined; /** What the band is: only a lane of the app's takes a gesture of its own — a rename, its ×, "+ STATE". */ readonly band: ModelBand; } /** One decision in the view model. */ export interface ModelTrigger { /** Its key. */ readonly key: string; /** Its name. */ readonly label: string; /** Its diamond's letter. */ readonly letter: string; /** Who owns it. */ readonly owner: string | undefined; /** The states queued at it, by key. */ readonly queue: ReadonlyArray; /** Its outcomes' summary line. */ readonly outcomes: string | undefined; /** The routed transitions it governs, by key. */ readonly governs: ReadonlyArray; } /** What the flowchart holds, counted: what the narrowing leaves out counts nowhere. */ export interface ModelCounts { /** Its routed transitions. */ readonly total: number; /** Of them, planned. */ readonly planned: number; /** Of them, observed. */ readonly observed: number; /** Of them, with an end no state is keyed by. */ readonly unresolved: number; /** Its lanes. */ readonly lanes: number; /** Its states. */ readonly states: number; /** Its transitions, in-place ones among them. */ readonly transitions: number; /** Its decisions. */ readonly decisions: number; } /** The view model. */ export interface FlowchartModel { /** The bands, in their order: the lanes, then *No lane* when a state names no lane; one band with no lanes given. */ readonly lanes: ReadonlyArray; /** The states in their order — by `order`, else by key — then the ghosts: each knows its band, and its place in it. */ readonly nodes: ReadonlyArray; /** The nodes, by key. */ readonly nodesByKey: ReadonlyMap; /** The routed transitions, in key order. */ readonly links: ReadonlyArray; /** The decisions, by key. */ readonly triggers: ReadonlyMap; /** What it holds, counted. */ readonly counts: ModelCounts; /** It holds no lane, no state and no transition: there is nothing to draw. */ readonly blank: boolean; /** How many states each lane holds, by its key — every state the flowchart holds naming it: a lane holding states is not deleted (R8). */ readonly laneStates: ReadonlyMap; /** No lanes are given: `lanes` is one band holding every state, which no gesture renames or deletes. */ readonly standIn: boolean; /** The states naming no lane the flowchart holds, by key, in their band's order: they stand in *No lane*, and Issues lists each (D12). */ readonly noLane: ReadonlyArray; /** Whether the states carry an `order`: a move within a lane, and a drop between two cards, write the middle of theirs (D4). */ readonly ordered: boolean; /** Each kind's keys, as the rows gave them: what every list of a kind's rows orders them by, by key (#1549). */ readonly keys: FlowchartKindKeys; } /** The key of the last band, *No lane*: a key no lane of the app's is given — an East String holds no lone NUL as a key's text. */ export declare const NO_LANE_KEY = "\0no-lane"; /** The key of the one band of a flowchart given no lanes. */ export declare const ALL_LANE_KEY = ""; /** * Stroke weight from evidence volume — the spec's log ladder: * 1.6 / 2 / 2.5 px, floor 1.4 for links without volume. Normalised * min→max in log space so the observed range spreads across the tiers. * * @param volume - The transition's volume * @param minVolume - The smallest volume drawn * @param maxVolume - The largest volume drawn * @returns The stroke weight, in px */ export declare function evidenceWeight(volume: number | undefined, minVolume: number, maxVolume: number): number; /** * Compact volume formatting for badges, in the app's locale (#850). * * @param v - The volume * @param words - The formatters * @returns The volume, printed */ export declare function fmtVolume(v: number, words: Formatters): string; /** * Grouped count formatting for badges, in the app's locale (#850). * * @param n - The count * @param words - The formatters * @returns The count, printed */ export declare function fmtCount(n: bigint, words: Formatters): string; /** * A transition's evidence badge, in the app's locale (#850) — `17,350 parcels * · 386`: its volume with its unit, and its count; none without a volume. * * @param evidence - The transition's evidence * @param words - The formatters * @returns The badge; `undefined` for none */ export declare function evidenceBadge(evidence: FlowchartEvidenceValue | undefined, words: Formatters): string | undefined; /** * Builds the view model (see the module docs). Pure; unit-testable. * * @param rows - The four records' rows, the drafts in place * @param words - The flowchart's words: the badges' numbers in the app's locale, and the ghost's and *No lane*'s names * @returns The view model */ export declare function buildModel(rows: FlowchartRows, words: FlowchartWords): FlowchartModel; //# sourceMappingURL=model.d.ts.map