import type { BpmnDefinitions } from "@bpmnkit/core"; import { OverlayManager } from "./overlays.js"; import type { CanvasEvents, CanvasOptions, ImportWarnings, LoadOptions, PlaneInfo, RenderedEdge, RenderedShape, ScreenBox, Theme, Viewbox, ViewportState } from "./types.js"; /** * BpmnCanvas — a high-performance, accessible BPMN 2.0 diagram viewer. * * ## Quick start * ```typescript * import { BpmnCanvas } from "@bpmnkit/canvas"; * * const canvas = new BpmnCanvas({ * container: document.getElementById("app")!, * xml: myBpmnXml, * theme: "auto", * }); * ``` * * ## Framework integration * The canvas is framework-agnostic and mounts into any `HTMLElement`. * * ### React * ```tsx * const ref = useRef(null); * useEffect(() => { * const canvas = new BpmnCanvas({ container: ref.current!, xml }); * return () => canvas.destroy(); * }, [xml]); * return
; * ``` * * ### Vue * ```vue * * * ``` * * ## Plugin system * Extend the canvas with custom behaviour by passing plugins to the constructor: * ```typescript * const canvas = new BpmnCanvas({ * container, * plugins: [tooltipPlugin, editModePlugin], * }); * ``` * See {@link CanvasPlugin} for the plugin contract. */ export declare class BpmnCanvas { private readonly _id; private readonly _host; private readonly _svg; private readonly _viewportG; private readonly _containersG; private readonly _edgesG; private readonly _shapesG; private readonly _labelsG; private _gridPattern; private _markerId; private _breadcrumb; private readonly _viewport; /** * Suppresses the fit the next render would otherwise schedule. * * The fit is deferred a frame so the SVG has been laid out, which means a * caller cannot simply restore the viewport afterwards — its own call would * land first and be overwritten a frame later. */ private _skipNextFit; private readonly _keyboard; private readonly _overlays; private readonly _scene; private readonly _plugins; private _shapes; private _edges; private _currentDefs; private _theme; private _fit; private _layoutMissingDi; /** Elements from the last load that had no diagram interchange. */ private _importWarnings; /** The DI plane currently rendered. */ private _currentPlane; /** Element ids (this document) that own a plane and can be drilled into. */ private _planeElementIds; /** Breadcrumb path from the root plane to the current one. */ private _planeStack; /** CSS classes applied via {@link addMarker}, keyed by element id. */ private _markers; /** Element id currently under the pointer (for hover enter/leave events). */ private _hoverId; /** * Set once the user pans/zooms so a container resize preserves their * viewport instead of force-fitting the diagram. */ private _userMovedViewport; private _listeners; constructor(options: CanvasOptions); private _ro; /** * Parses and renders a BPMN 2.0 XML string. * * @throws {Error} If the XML cannot be parsed. */ load(xml: string, options?: LoadOptions): void; /** * Renders an already-parsed `BpmnDefinitions` model. * Use this when you already have the parsed model from `@bpmnkit/core`. */ loadDefinitions(defs: BpmnDefinitions, options?: LoadOptions): void; /** * Returns the elements from the last {@link load}/{@link loadDefinitions} * that had no diagram interchange (and so were auto-laid-out or skipped). */ getImportWarnings(): ImportWarnings; /** * Lists every DI plane in the current document (the primary plane plus any * collapsed sub-processes that carry their own layout). */ getPlanes(): PlaneInfo[]; /** * Shows the plane identified by a DI plane `bpmnElement` (a process/ * collaboration id or a collapsed sub-process id). Drilling into a * sub-process extends the breadcrumb; navigating to an ancestor trims it. * No-op if the id has no plane. Fires `plane:change`. */ showPlane(planeElementId: string): void; /** Renders a specific plane into the (cleared) layers and refits. */ private _renderPlane; /** Clears the canvas and fires `diagram:clear`. */ clear(): void; /** * Scales and pans the viewport to make the entire diagram visible. * @param padding — pixels of whitespace around the diagram. Default: 40. */ fitView(padding?: number): void; /** Sets the color theme. Pass `"auto"` to follow the OS preference. */ setTheme(theme: Theme): void; /** * HTML overlays anchored to diagram elements (badges, tooltips, panels). * @example * ```typescript * canvas.overlays.add("Task_1", { * position: { top: -8, right: -8 }, * html: `!`, * }); * ``` */ get overlays(): OverlayManager; /** Returns the rendered shape or edge for a BPMN id, or `undefined` (O(1)). */ getElement(id: string): RenderedShape | RenderedEdge | undefined; /** Returns the `` graphics element for a BPMN id, or `undefined` (O(1)). */ getGraphics(id: string): SVGGElement | undefined; /** Iterates every rendered element (shapes and edges). */ forEachElement(fn: (el: RenderedShape | RenderedEdge) => void): void; /** * Re-renders a single element's `` in place from the current model, * preserving markers/selection classes — the incremental-update path used * for cheap edits. No-op for an unknown id. */ updateElement(id: string): void; /** Zooms in by 25% centred on the canvas. */ zoomIn(): void; /** Zooms out by 25% centred on the canvas. */ zoomOut(): void; /** Resets to 100% zoom, centred on the canvas. */ resetZoom(): void; /** * Adjusts the zoom. Pass `"fit"` (or no argument) to fit the whole diagram; * pass a number for an absolute scale, optionally keeping `center` * (screen-space pixels relative to the host) fixed. */ zoom(scaleOrFit?: number | "fit", center?: { x: number; y: number; }): void; /** * The raw pan and zoom, for restoring it later. * * `viewbox()` describes what is visible, which depends on the element's size; * this is the transform itself, so handing it back to {@link setViewport} * reproduces the view exactly — including across a swap from one canvas to * another, where a re-fit would jump. */ getViewport(): ViewportState; /** Restores a viewport captured by {@link getViewport}. */ setViewport(state: Partial): void; /** Returns the visible region in diagram coordinates plus the zoom scale. */ viewbox(): Viewbox; /** Pans (without changing zoom) so the element with the given id is centred. */ scrollToElement(id: string): void; /** * Returns the element's bounding box in screen pixels relative to the host, * or `null` if the element is not found. */ getAbsoluteBBox(id: string): ScreenBox | null; /** * Serializes the current diagram to a standalone SVG string with theme * colours inlined, so it renders correctly outside the page. * @param opts.bounds `"diagram"` (default) exports the whole diagram; * `"viewport"` exports only the currently visible region. */ exportSvg(opts?: { bounds?: "diagram" | "viewport"; }): string; /** * Rasterizes the current diagram to a PNG data URL at `scale`× the diagram * size. Browser-only (requires `Image`/``). */ exportPng(scale?: number): Promise; /** Adds a CSS class to the element with the given BPMN id. No-op if not found. */ addMarker(id: string, cls: string): void; /** Removes a CSS class from the element with the given BPMN id. */ removeMarker(id: string, cls: string): void; /** Returns whether the element with the given id currently has the CSS class. */ hasMarker(id: string, cls: string): boolean; /** Toggles a CSS class on the element with the given id. */ toggleMarker(id: string, cls: string): void; /** * Subscribes to a canvas event. Returns an unsubscribe function. * * @example * ```typescript * const off = canvas.on("element:click", (id) => console.log(id)); * off(); // unsubscribe * ``` */ on(event: K, handler: CanvasEvents[K]): () => void; /** * Highlights a set of elements by ID with a coloured outline. * * - `"changed"` — amber outline, for elements modified by AI * - `"new"` — green fill + outline, for elements added by AI * * Call {@link clearHighlights} to remove all highlights. * Highlights are cleared automatically on the next {@link load} / {@link loadDefinitions} call. */ highlight(ids: string[], variant: "changed" | "new"): void; /** Removes all highlight classes added by {@link highlight}. */ clearHighlights(): void; /** Destroys the canvas, removing all DOM nodes and event listeners. */ destroy(): void; /** Finds the SVG group for a shape or edge by BPMN id. */ private _findElement; /** Design tokens to resolve from the live host for a self-contained export. */ private static readonly _EXPORT_TOKENS; /** Stylesheet for the exported SVG: resolved theme tokens + the canvas CSS. */ private _exportStyles; /** A human-readable label for a plane's `bpmnElement` (name, or a fallback). */ private _planeName; /** Recursively finds a flow element by id across all processes/sub-processes. */ private _findFlowElementById; /** Rebuilds the breadcrumb bar from the current plane stack. */ private _updateBreadcrumb; /** * Resolves the BPMN element id under a pointer/mouse event, or `null`. * The event target answers directly for most moves; `elementFromPoint` * (which forces a layout and hit-test flush) is only consulted when native * SVG hit-testing handed us the root ``, as it does in some flex/scroll * containers. */ private _elementIdForEvent; /** Diagram-coordinate bounds of a shape (from DI) or edge (waypoint bbox). */ private _diagramBounds; private _applyTheme; private _installPlugin; private _emit; } //# sourceMappingURL=canvas.d.ts.map