/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** A point on the surface, in its px. */ export interface CanvasPoint { readonly x: number; readonly y: number; } /** * What links draw in: the colours and the caption's font the page computes for * the shared part's elements (`linkRibbons`), each a CSS colour the context * takes. */ export interface CanvasLinkLook { /** The paper under a link's ink and its head: its casing. */ readonly casing: string; /** The muted ink every link draws in. */ readonly ink: string; /** The strong ink a lit or a selected link draws in. */ readonly strong: string; /** The ring round the ends a lit or a selected link joins. */ readonly ring: string; /** The ring's width (px). */ readonly ringWidth: number; /** The paper a caption sits on. */ readonly knockout: string; /** A selected link's caption's outline. */ readonly outline: string; /** A caption's ink. */ readonly caption: string; /** A caption's font, as `ctx.font` takes it. */ readonly captionFont: string; } /** One run of a link's line: its points, its weight, and what it draws in over its link's. */ export interface CanvasStroke { /** Its points, in order. */ readonly points: readonly CanvasPoint[]; /** Its weight: its stroke's width (px). */ readonly width: number; /** The radius its corners turn at, before their clamp; 0 turns none. */ readonly corner: number; /** Its alpha over its link's: a net's leg to an item drawn as context fades with it. */ readonly alpha?: number | undefined; /** Its ink over its link's: a leg drained of its colour with the item it joins. */ readonly ink?: string | undefined; /** Whether it draws in the strong ink, its link lit or not: a net's selected leg. */ readonly strong?: boolean | undefined; } /** A head: its tip where its link arrives, its base on its line, how far it reaches either side, and what it draws in over its link's. */ export interface CanvasHead { /** Its tip, where its link arrives. */ readonly tip: CanvasPoint; /** Its base's middle, on its link's line. */ readonly base: CanvasPoint; /** How far it reaches either side of its line (px). */ readonly half: number; /** Its alpha over its link's. */ readonly alpha?: number | undefined; /** Its ink over its link's. */ readonly ink?: string | undefined; /** Whether it draws in the strong ink, its link lit or not. */ readonly strong?: boolean | undefined; } /** An end a link joins, which its ring goes round while it is lit or selected: a box, or a circle. */ export type CanvasEnd = { readonly kind: "box"; readonly left: number; readonly top: number; readonly right: number; readonly bottom: number; } | { readonly kind: "circle"; readonly x: number; readonly y: number; readonly r: number; }; /** A link's caption: its text, centred across `x`, its baseline at `y`. */ export interface CanvasCaption { readonly text: string; readonly x: number; readonly y: number; } /** One link as the painter draws it: its runs, its heads and its joins, how it draws, the ends it joins and its caption. */ export interface CanvasLink { /** Its identity among the links. */ readonly id: string; /** Its runs: a link's one, a net's trunk, bars and legs. */ readonly strokes: readonly CanvasStroke[]; /** Its heads, each where it arrives. */ readonly heads: readonly CanvasHead[]; /** Where its runs join — a net's junctions — each a dot of its radius, in its ink. */ readonly dots: readonly { readonly x: number; readonly y: number; readonly r: number; }[]; /** Its dash; empty for a solid line. */ readonly dash: readonly number[]; /** Its ink — its tone's — or, `undefined`, the look's muted ink. */ readonly ink: string | undefined; /** Its alpha: faded, as context. */ readonly alpha: number; /** Whether it is the one under the pointer. */ readonly lit: boolean; /** Whether it is selected. */ readonly selected: boolean; /** The ends it joins, ringed while it is lit or selected. */ readonly ends: readonly CanvasEnd[]; /** Its caption; `undefined` for none. */ readonly caption: CanvasCaption | undefined; } /** * Traces a route into the context's path: straight runs between its points, * each corner turned on a circle of `corner`'s radius, clamped so the turn * takes at most half of each run beside it — the canvas's trace of what * `geometry.ts`' `rounded` writes as path data, at any angle. A point that turns * nothing, or turns back on itself, is passed straight through. The caller * begins the path and strokes it. * * @param ctx - The context * @param points - The route's points, in order * @param corner - The corners' radius, before their clamp; 0 turns none */ export declare function traceRoute(ctx: CanvasRenderingContext2D, points: readonly CanvasPoint[], corner: number): void; /** * Traces a head into the context's path: a triangle, its base across its line * at `base`, `half` either side, its tip at `tip`. The caller begins the path * and fills it. * * @param ctx - The context * @param head - The head */ export declare function traceHead(ctx: CanvasRenderingContext2D, head: CanvasHead): void; /** * Where a route arrives: its line, to the head's base, and its head, 8 back * along it from its last point — its tip there — max(8, 2 × weight) wide. A * route shorter than a head is all head. * * @param points - The route's points, its last where it arrives * @param weight - Its weight: its stroke's width (px) * @returns Its line, and its head; `undefined` for a route of no length */ export declare function arrive(points: readonly CanvasPoint[], weight: number): { readonly line: CanvasPoint[]; readonly head: CanvasHead; } | undefined; /** * A text as a canvas draws it and measures it, its letters unjoined: a * zero-width non-joiner after each f that meets an f, an i or an l, so a pair * the font would join — Chivo Mono's ff, fi, fl, ffi and ffl, each in one cell — * stays two letters, each in a cell of its own, as the page draws it. * `textRendering` turns the joins off where a canvas has it; Safari's has not, * and the non-joiner keeps the pair apart there too. It takes no room and draws * nothing, so a text measured through it measures what is drawn through it. * * @param text - The text * @returns The text, every pair the font would join kept apart */ export declare function unjoined(text: string): string; /** * Paints links in the shared look (see the module docs): every link's casing * under every link's ink, the selected links and then the lit one last, each * its casing, its ink and the rings round its ends, and every caption over them * all. * * @param ctx - The context * @param links - The links, in drawing order * @param look - What they draw in: the shared part's colours and caption font */ export declare function paintLinks(ctx: CanvasRenderingContext2D, links: readonly CanvasLink[], look: CanvasLinkLook): void; //# sourceMappingURL=canvas.d.ts.map