/** * Drawing surface that produces Excalidraw elements. Diagram modules draw * exclusively through this API; they never touch Excalidraw fields directly. * @module draw/canvas */ /** Excalidraw font family id for Excalifont. */ export declare const FONT_EXCALIFONT = 5; /** Excalidraw font family id for the monospace font (Comic Shanns). */ export declare const FONT_MONO = 8; /** * Arrowheads understood by Excalidraw itself. * @type {ReadonlySet} */ export declare const NATIVE_HEADS: ReadonlySet; export type Style = { stroke?: string; fill?: string; strokeWidth?: number; strokeStyle?: "solid" | "dashed" | "dotted"; roughness?: number; fillStyle?: "solid" | "hachure" | "cross-hatch"; /** * 0–100 */ opacity?: number; rounded?: boolean; link?: string | null; }; export type Head = string | null; export type Point = [number, number]; export type Hook = import("../syntax/hooks.mjs").Hook; export type Tooltip = import("../syntax/hooks.mjs").Tooltip; export type HookOwner = { parent: HookOwner | null; }; export type SceneHook = Pick & { classes?: string[]; parent?: string; }; export type BoundHook = { hook: Hook; data: SceneHook; owner?: HookOwner; }; /** @public */ export declare class Canvas { #private; theme: import("./theme.mjs").Theme; random: () => number; nextId: () => string; maxElements: number; /** @type {any[]} */ elements: any[]; /** @type {string[]} */ groupStack: string[]; /** @type {Map} */ byId: Map; /** @type {Map} */ interactionAliases: Map; /** @type {Set} */ hookElementTargets: Set; /** @type {Map} */ hookOwners: Map; /** * @param {{ seed: number, theme: import("./theme.mjs").Theme, maxElements?: number, hooks?: Hook[], tooltips?: Tooltip[] }} options */ constructor(options: { seed: number; theme: import("./theme.mjs").Theme; maxElements?: number; hooks?: Hook[]; tooltips?: Tooltip[]; }); /** @returns {number} */ seed(): number; /** * Run `fn` with all created elements sharing a new group. * @template T * @param {() => T} fn * @returns {T} */ group(fn: () => T): T; /** * Associate a logical diagram element with the primitives it draws. * @template T * @param {string} alias * @param {() => T} draw * @param {HookOwner} [owner] Logical node that owns these primitives. * @returns {T} */ withHookAlias(alias: string, draw: () => T, owner?: HookOwner): T; /** * Attach plain-text tooltips to the primitives of each target. * @param {Tooltip[]} tooltips * @param {(line: number, message: string) => void} reportError */ applyTooltips(tooltips: Tooltip[], reportError: (line: number, message: string) => void): void; /** * Attach a hook to existing drawing primitives in a custom diagram module. * @param {Hook} hook * @returns {string | null} A diagnostic when the binding cannot be applied. */ applyHook(hook: Hook): string | null; /** * Attach interaction metadata and resolve relationships between bound hooks. * @param {Hook[]} hooks * @param {(line: number, message: string) => void} reportError */ applyHooks(hooks: Hook[], reportError: (line: number, message: string) => void): void; /** * @param {string} type * @param {number} x * @param {number} y * @param {number} w * @param {number} h * @param {Style} style */ base(type: string, x: number, y: number, w: number, h: number, style: Style): { id: string; type: string; x: number; y: number; width: number; height: number; angle: number; strokeColor: string; backgroundColor: string; fillStyle: "cross-hatch" | "hachure" | "solid"; strokeWidth: number; strokeStyle: "dashed" | "dotted" | "solid"; roughness: number; opacity: number; groupIds: string[]; frameId: any; roundness: any; seed: number; version: number; versionNonce: number; isDeleted: boolean; boundElements: any; updated: number; link: string; locked: boolean; }; /** * @param {number} x * @param {number} y * @param {number} w * @param {number} h * @param {Style} [style] * @returns {string} Element id. */ rect(x: number, y: number, w: number, h: number, style?: Style): string; /** * @param {number} x * @param {number} y * @param {number} w * @param {number} h * @param {Style} [style] */ ellipse(x: number, y: number, w: number, h: number, style?: Style): string; /** * @param {number} x * @param {number} y * @param {number} w * @param {number} h * @param {Style} [style] */ diamond(x: number, y: number, w: number, h: number, style?: Style): string; /** * Open or closed polyline. Closed polylines with a fill render as polygons. * @param {Point[]} points Absolute points. * @param {Style & { closed?: boolean, curved?: boolean }} [style] */ line(points: Point[], style?: Style & { closed?: boolean; curved?: boolean; }): string; /** * @param {"line" | "arrow"} type * @param {Point[]} points * @param {Style & { curved?: boolean }} style */ linear(type: "line" | "arrow", points: Point[], style: Style & { curved?: boolean; }): { id: string; type: string; x: number; y: number; width: number; height: number; angle: number; strokeColor: string; backgroundColor: string; fillStyle: "cross-hatch" | "hachure" | "solid"; strokeWidth: number; strokeStyle: "dashed" | "dotted" | "solid"; roughness: number; opacity: number; groupIds: string[]; frameId: any; roundness: any; seed: number; version: number; versionNonce: number; isDeleted: boolean; boundElements: any; updated: number; link: string; locked: boolean; }; /** * Arrow along a polyline with optional heads and bindings. * @param {Point[]} points * @param {Style & { start?: Head, end?: Head, curved?: boolean, from?: string | null, to?: string | null }} [style] */ arrow(points: Point[], style?: Style & { start?: Head; end?: Head; curved?: boolean; from?: string | null; to?: string | null; }): string; /** * Translate a head name; non-native heads are drawn as decorations. * @param {Head} head * @param {Point} from Point before the tip. * @param {Point} tip * @param {any} el Arrow element. * @param {number} sw * @returns {string | null} */ head(head: Head, from: Point, tip: Point, el: any, sw: number): string | null; /** * @param {any} arrow * @param {"startBinding" | "endBinding"} which * @param {string} targetId */ bind(arrow: any, which: "startBinding" | "endBinding", targetId: string): void; /** * Single-style text element. `x`/`y` is the top-left corner unless `align` * shifts the anchor. * @param {string} text * @param {number} x Anchor x (left/center/right depending on align). * @param {number} y Top y. * @param {{ size?: number, color?: string, align?: "left" | "center" | "right", width?: number, mono?: boolean, bold?: boolean, italic?: boolean, link?: string | null, opacity?: number }} [opts] */ text(text: string, x: number, y: number, opts?: { size?: number; color?: string; align?: "left" | "center" | "right"; width?: number; mono?: boolean; bold?: boolean; italic?: boolean; link?: string | null; opacity?: number; }): string; /** * Draw a laid-out rich text block (see {@link layoutText}) at `x, y` * (top-left of the block). * @param {import("../layout/measure.mjs").RichLayout} laid * @param {number} x * @param {number} y * @param {{ color?: string, align?: "left" | "center" | "right" }} [opts] */ richText(laid: import("../layout/measure.mjs").RichLayout, x: number, y: number, opts?: { color?: string; align?: "left" | "center" | "right"; }): void; /** * Bounding box of all elements (or a subset). * @param {any[]} [elements] * @returns {{ x: number, y: number, w: number, h: number }} */ bounds(elements?: any[]): { x: number; y: number; w: number; h: number; }; /** * Move every element by `dx, dy`. * @param {number} dx * @param {number} dy */ translate(dx: number, dy: number): void; } /** @param {number} n */ export declare function round(n: number): number; /** * Unit vector from a to b. * @param {Point} a * @param {Point} b * @returns {Point} */ export declare function unit(a: Point, b: Point): Point;