/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * Flowchart layout — pure geometry. No React imports. * * Implements the spec's link-geometry contract: * - H/V segments only — never diagonal, never bezier. * - Corners are quarter-arcs r 8; in tight channels r may shrink to 4, * never to a sharp corner. * - ≥ 12px straight leaving a handle before the first corner, ≥ 12px * between consecutive corners, ≥ 12px straight entry before the * arrowhead. * - Parallel runs sit ≥ 16px apart (per-gap channel assignment). * - One fixed handle per side (centre of each edge). A link joins the * CLOSEST FACING pair of handles on its two nodes — the router picks * the nearest pair and routes H/V between them. Links converge at the * handle; paths start and end at the 7px handle RING's edge so the * fixed 12px arrowhead tip butts the ring, never past or before it. * TD swaps the axes via a logical-space transpose (cards stay upright). * - Cards are as big as what they show (R22): 116 × 40, or — where the * details draw on them — the card's width and each its own height. Left * to right each row is as tall as its tallest card, its cards centred in * it; top down the lanes are as tall as the tallest card. Two cards side * by side keep room for the widest label between them (R24). * - A link's sides are chosen over a box of the card's width and 40, * centred on its card, so they are today's whatever the card's height, * and its route meets the card's own sides (R23). A route keeps its * sides and never crosses a card: where its straight line would, it * turns into the gutter between rows, or the gap beside a lane, and back. * - The decision diamond anchors to the midpoint of the longest straight * segment; labels place collision-aware over their boxes (R32): today's * places, then steps off each segment, and where none is clear, the * place tried that covers least of the cards, then of the labels. */ import type { FlowchartModel } from "./model.js"; export declare const NODE_W = 116; export declare const NODE_H = 40; export declare const CORNER_R = 8; export declare const CORNER_R_MIN = 4; export declare const MIN_STRAIGHT = 12; export declare const CHANNEL_GAP = 16; export declare const LANE_MIN_W = 166; export declare const LANE_HEADER_H = 40; export declare const ROW_PITCH = 96; export declare const CANVAS_PAD_BOTTOM = 48; export declare const LANE_TAIL_W = 78; /** Handle ring radius — paths stop at the ring edge. */ export declare const RING_R = 3.5; /** A label's box height with one line: its evidence. */ export declare const BADGE_H = 18; /** A label's line past its first (§4). */ export declare const LABEL_LINE_H = 13; export interface Pt { x: number; y: number; } export interface NodeRect { key: string; x: number; y: number; w: number; h: number; cx: number; cy: number; /** Fixed handle points (centre of each edge). */ left: Pt; right: Pt; top: Pt; bottom: Pt; } export type HandleSide = "left" | "right" | "top" | "bottom"; /** One occupied connection point on a node border. */ export interface HandleInfo { side: HandleSide; pt: Pt; /** Keys of the links converging at this handle. */ links: string[]; } export interface RouteSeg { a: Pt; b: Pt; } export interface LinkRoute { key: string; /** SVG path data (H/V runs joined by quarter-arc corners), trimmed to * the handle-ring edges at both ends. */ d: string; /** The in-handle the arrow terminates on (ring centre). */ end: Pt; /** Straight segments (untrimmed; for anchors + hit testing). */ segs: RouteSeg[]; /** Midpoint of the longest straight run — diamond anchor. */ mid: Pt; /** Handle-ring centres this route touches (out + in). */ ports: [Pt, Pt]; /** Its label's box, collision-resolved (R32); absent, it draws none. */ label?: LabelPlace; } /** A transition label's size (§4): its evidence line and its details' lines. */ export interface LabelBox { readonly w: number; readonly h: number; } /** Where a transition's label stands: its box. */ export interface LabelPlace { x: number; y: number; w: number; h: number; } /** One row states stand in, along the stacking axis — LR's y, TD's x. */ export interface LayoutRow { /** Where it starts. */ readonly start: number; /** How far it reaches: left to right, as tall as its tallest card; top down, the card's width. */ readonly size: number; } export interface LaneBand { key: string; label: string; x: number; y: number; w: number; h: number; /** Alternating paper-2 tint per the spec. */ tinted: boolean; /** Header anchor along the lane axis (LR: band centre x; TD: band top y). */ cx: number; } export interface FlowchartLayout { width: number; height: number; orientation: "LR" | "TD"; lanes: LaneBand[]; nodes: Map; routes: LinkRoute[]; /** Occupied connection points per node (idle handles are hidden). */ handles: Map; /** "+ STATE" ghost cell per lane — the exact grid cell one row below * that lane's last node (nothing shifts on commit). */ laneGhosts: Map; /** The dashed "+ LANE" affordance rect at the tail (full lane height, * 14px insets) — drawn where the flowchart edits (#1247). */ laneTail: { x: number; y: number; w: number; h: number; }; /** The rows states stand in along the stacking axis — LR's y, TD's x — * then the row past the last, where a lane's "+ STATE" ghost stands after * its last state: each row's start and size. A dropped state lands in one * (#1249). */ rows: readonly LayoutRow[]; /** How far a row's cell reaches across its lane — left to right the card's * width, top down the tallest card's height: what a state standing there * takes. */ cellAcross: number; } /** * The cell a state stands in, at a row of a lane's band: the row's span, * across the lane's cards — what a state drawn there, or dropped there * (#1249), takes. * * @param layout - The laid-out flow * @param lane - The lane's band * @param row - The row, from the band's first * @returns The cell, in the canvas's px */ export declare function rowCell(layout: FlowchartLayout, lane: LaneBand, row: number): { x: number; y: number; w: number; h: number; }; /** * Where the landing line runs for a state dropped at a row of a lane's band * (#1249): across the node's footprint, in the middle of the gap before that * row — the 16px under the lane's header before the first row, half the gap * between two rows before any other — between the state above it and the one * it lands before. Its thickness is the recipe's. * * @param layout - The laid-out flow * @param lane - The lane's band * @param row - The row the state lands in * @returns The line's start, and its length across the band — `w` in LR, `h` in TD; the other is 0 */ export declare function landingSeam(layout: FlowchartLayout, lane: LaneBand, row: number): { x: number; y: number; w: number; h: number; }; /** * Builds an H/V path with quarter-arc corners from an orthogonal point * run. Consecutive points must differ in exactly one axis. The corner * radius shrinks (to ≥ CORNER_R_MIN) when adjacent runs are short — * never to a sharp corner. */ export declare function roundedPath(points: Pt[]): { d: string; segs: RouteSeg[]; }; /** Midpoint of the longest straight run. */ export declare function longestRunMid(segs: readonly RouteSeg[]): Pt; /** The CLOSEST FACING pair of handles between two node rects. */ export declare function selectPair(a: NodeRect, b: NodeRect): { sa: HandleSide; sb: HandleSide; }; /** The orthogonal point run between a chosen handle pair (no channel * staggering — computeLayout overrides the mid run for that). */ export declare function pairPoints(a: NodeRect, b: NodeRect, sa: HandleSide, sb: HandleSide, mx?: number): Pt[]; /** Spec-compliant DRAG PREVIEW between two nodes — the exact H/V route * (r 8 corners, ring-trimmed) the committed link would take. */ export declare function previewLinkPath(a: NodeRect, b: NodeRect): string; /** * A transition label's box (§4): 18 high, and 13 for each line past its * first; as wide as its longest line, 5.8 a character and 14. * * @param lines - Its lines: its evidence line, then its details' (R32) * @returns Its size */ export declare function labelBox(lines: readonly string[]): LabelBox; /** Spec-compliant DRAG PREVIEW from a handle to a free cursor point — * an orthogonal Z/L run instead of a diagonal rubber band. */ export declare function previewCursorPath(a: NodeRect, side: HandleSide, c: Pt): string; /** A box on the canvas: a card's, a label's, or one a label keeps off. */ export interface Rect { x: number; y: number; w: number; h: number; } /** * Where a transition's label stands (R32): today's places — each segment, * longest first, at its middle, a third and two thirds, on a vertical segment * on the line and on a horizontal one above it — then the steps across each * segment off its middle, the longest first: the first clear of the cards, * the keep-outs and the labels placed. Where none is, the place tried that * covers least of the cards, then of the labels, then of the keep-outs. * * @param segs - The route's straight segments * @param size - The label's size * @param cards - The cards * @param keepOut - What else a label stays off: the lanes' headers, the handle rings and the diamonds * @param labels - The labels placed * @returns Its box */ export declare function placeLabel(segs: readonly RouteSeg[], size: LabelBox, cards: readonly Rect[], keepOut: readonly Rect[], labels: readonly Rect[]): LabelPlace; export interface LayoutOptions { /** Available width in px (the canvas grows beyond it if lanes need more). */ width: number; orientation: "LR" | "TD"; /** Extra bottom padding reserving space for the legend overlay. */ legendPad?: number | undefined; /** Minimum canvas height — lanes stretch to fill a pinned frame body. */ minHeight?: number | undefined; /** Each lane's width in px, where a phone's window of lanes sets it; left out, the lanes fill `width`. Left to right only. */ laneWidth?: number | undefined; /** * The width of a phone's window that holds one lane, px, where the details * draw on the cards (R40, D24): each lane at least that wide, so no other * lane's card shows beside its own; a lane wider keeps its width, the * card's and the room for labels. Left to right only. */ laneWindow?: number | undefined; /** * The cards, where the details draw on them (R22): their width, and each * one's height by its state's key — a key left out, a ghost's, is 40. Two * cards side by side then keep the widest label's width and 24 between * them (R24). Left out, every card is today's 116 × 40. */ cards?: { readonly width: number; readonly heights: ReadonlyMap; } | undefined; /** Each label's size, by its transition's key (R32): a transition left out draws none. Left out, each transition with evidence draws its evidence line. */ labels?: ReadonlyMap | undefined; } /** * The layout's own size (R42): what {@link computeLayout} draws at with no * room to fill — no width for its lanes to stretch across or its rows to * widen into, and no height for its lanes to fill. A zoom's Fit scales it * into main. * * @param model - The view model * @param opts - What the layout is computed for, but the room it fills * @returns Its width and its height */ export declare function layoutExtent(model: FlowchartModel, opts: Omit): { readonly width: number; readonly height: number; }; /** * Computes the full layout. The algorithm works in LOGICAL space (lanes * along X, stacking along Y); for TD the finished geometry transposes * (the spec: "TD orientation swaps the axes") — logical right/bottom * out-handles become real bottom/right, cards stay upright. */ export declare function computeLayout(model: FlowchartModel, opts: LayoutOptions): FlowchartLayout; //# sourceMappingURL=layout.d.ts.map