import { Entity } from '@lastolivegames/becsy'; import { IPointData } from '@pixi/math'; import { mat3 } from 'gl-matrix'; import { CaptureUpdateActionType } from './history/Store'; import { Commands, EntityCommands } from './commands'; import { AppState } from './context'; import { BitmapFont } from './utils'; import type { SerializedNode } from './types/serialized-node'; import { AABB, Canvas, ComputedCamera, Landmark, LandmarkAnimationEffectTiming, OBB, VectorNetwork } from './components'; export interface StateManagement { getAppState: () => AppState; setAppState: (appState: AppState) => void; getNodes: () => SerializedNode[]; setNodes: (nodes: SerializedNode[]) => void; onChange: (snapshot: { appState: AppState; nodes: SerializedNode[]; }) => void; } export declare enum ExportFormat { SVG = "svg", PNG = "png", JPEG = "jpeg" } export declare class DefaultStateManagement implements StateManagement { #private; getAppState(): AppState; setAppState(appState: AppState): void; getNodes(): SerializedNode[]; setNodes(nodes: SerializedNode[]): void; onChange(snapshot: { appState: AppState; nodes: SerializedNode[]; }): void; } export declare const mapToArray: (map: Map) => T[]; /** * Transforms array of objects containing `id` attribute, * or array of ids (strings), into a Map, keyd by `id`. */ export declare const arrayToMap: (items: readonly T[] | Map) => Map; export declare const pendingAPICallings: (() => any)[]; /** * Expose the API to the outside world. * * @see https://docs.excalidraw.com/docs/@excalidraw/excalidraw/api/props/excalidraw-api */ export declare class API { #private; private readonly stateManagement; private readonly commands; onchange: (snapshot: { appState: AppState; nodes: SerializedNode[]; }) => void; onNodesChange: (nodes: SerializedNode[]) => void; onAppStateChange: (appState: AppState) => void; constructor(stateManagement: StateManagement, commands: Commands); getAppState(): AppState; setAppState(appState: Partial): void; getNodes(): SerializedNode[]; setNodes(nodes: SerializedNode[]): void; getEntityCommands(): Map; getEntity(node: SerializedNode): Entity; getNodeById(id: string): SerializedNode; getNodeByEntity(entity: Entity): SerializedNode; getParentTransform(entity: Entity): mat3; getTransform(entity: Entity | SerializedNode): mat3; getAbsoluteTransformAndSize(node: SerializedNode): { id: string; x: number; y: number; width: number; height: number; rotation: number; scaleX: any; scaleY: any; }; getCanvas(): Entity; getCamera(): Entity; getCanvasElement(): HTMLCanvasElement; getHtmlLayer(): HTMLDivElement; getSvgLayer(): HTMLDivElement; /** * Create a new canvas. */ createCanvas(canvasProps: Partial): Entity; /** * Create a new camera. */ createCamera(cameraProps: Partial): Entity; /** * Should account for CSS Transform applied on container. * @see https://github.com/antvis/G/issues/1161 * @see https://github.com/antvis/G/issues/1677 * @see https://developer.mozilla.org/zh-CN/docs/Web/API/MouseEvent/offsetX */ client2Viewport({ x, y }: IPointData): IPointData; viewport2Client({ x, y }: IPointData): IPointData; viewport2Canvas({ x, y }: IPointData, viewProjectionMatrixInv?: mat3): IPointData; canvas2Viewport({ x, y }: IPointData, viewProjectionMatrix?: mat3): IPointData; /** * Calculate anchor's position in canvas coordinate, account for transformer's transform. */ transformer2Canvas(point: IPointData, mask: Entity): { x: number; y: number; }; canvas2Transformer(point: IPointData, mask: Entity): { x: number; y: number; }; /** * Search entites within a bounding box. Use rbush under the hood to accelerate the search. */ elementsFromBBox(minX: number, minY: number, maxX: number, maxY: number, shouldFilterLocked?: boolean): Entity[]; getViewportBounds(): { minX: number; minY: number; maxX: number; maxY: number; }; /** * Create a new landmark. */ createLandmark(params?: Partial): Partial; /** * Go to a landmark. * @see https://infinitecanvas.cc/guide/lesson-004#camera-animation */ gotoLandmark(landmark: Partial, options?: Partial): void; private applyLandmark; cancelLandmarkAnimation(): void; private getSceneGraphBounds; zoomTo(zoom: number, effectTiming?: Partial): void; private zoomToFit; fitToScreen(effectTiming?: Partial): void; fillScreen(effectTiming?: Partial): void; /** * Resize the canvas. * @see https://infinitecanvas.cc/guide/lesson-001 */ resizeCanvas(width: number, height: number): void; /** * @see https://docs.excalidraw.com/docs/@excalidraw/excalidraw/api/props/excalidraw-api#setcursor */ setCursor(cursor: string): void; /** * Select nodes. */ selectNodes(nodes: SerializedNode[], preserveSelection?: boolean, updateAppState?: boolean): void; deselectNodes(nodes: SerializedNode[]): void; highlightNodes(nodes: SerializedNode[], preserveSelection?: boolean, updateAppState?: boolean): void; unhighlightNodes(nodes: SerializedNode[]): void; applyCrop(): void; cancelCrop(): void; cancelLasso(): void; /** * If diff is provided, no need to calculate diffs. */ updateNode(node: SerializedNode, diff?: Partial, updateAppState?: boolean, skipOverrideKeys?: string[]): void; /** * Update the scene with new nodes. * It will calculate diffs and only update the changed nodes. * * @see https://docs.excalidraw.com/docs/@excalidraw/excalidraw/api/props/excalidraw-api#updatescene */ updateNodes(nodes: SerializedNode[], updateAppState?: boolean): void; updateNodeVectorNetwork(node: SerializedNode, vectorNetwork: VectorNetwork): void; updateNodeOBB(node: SerializedNode, obb: Partial, lockAspectRatio?: boolean, delta?: mat3, oldNode?: SerializedNode): void; /** * Get the bounds of the nodes. */ getBounds(nodes: SerializedNode[]): AABB; getGeometryBounds(nodes: SerializedNode[]): AABB; deleteNodesById(ids: SerializedNode['id'][]): SerializedNode[]; getSiblings(node: SerializedNode): Entity[]; getParent(node: SerializedNode): Entity; getChildren(node: SerializedNode): Entity[]; getChildrenRecursively(node: SerializedNode): SerializedNode[]; reparentNode(node: SerializedNode, parent: SerializedNode): void; /** * Bring current node to the front in its context. * The context is the parent of the node. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/z-index */ bringToFront(node: SerializedNode): void; bringForward(node: SerializedNode): void; sendBackward(node: SerializedNode): void; /** * Send current node to the back in its context. */ sendToBack(node: SerializedNode): void; /** * Record the current state of the canvas. * @param captureUpdateAction Record the changes immediately or never. */ record(captureUpdateAction?: CaptureUpdateActionType): void; undo(): void; redo(): void; isUndoStackEmpty(): boolean; isRedoStackEmpty(): boolean; clearHistory(): void; export(format: ExportFormat, download?: boolean, nodes?: SerializedNode[]): void; /** * Render nodes or the whole scene to SVG. */ renderToSVG(nodes: SerializedNode[], options?: Partial<{ grid: boolean; padding?: number; }>): Promise; renderToCanvas(node: SerializedNode, options?: { canvas?: HTMLCanvasElement; width?: number; height?: number; }): Promise; /** * Delete Canvas component */ destroy(): void; loadBitmapFont(bitmapFont: BitmapFont): void; copyToClipboard(selectedNodes: SerializedNode[], clipboardEvent?: ClipboardEvent): Promise; runAtNextTick(fn: () => any): void; /** * Create or edit an image with a prompt. */ createOrEditImage(isEdit: boolean, prompt: string, image_urls: string[]): Promise<{ images: Image[]; description: string; }>; /** * Upload the file to CDN and return an URL. */ upload: (file: File) => Promise; /** * Encode image before segmenting. */ encodeImage(image_url: string): Promise; /** * Segment the image into a mask. */ segmentImage(input: { image_url: string; prompt?: string; point_prompts?: PointPrompt[]; box_prompts?: BoxPrompt[]; }): Promise<{ /** * Primary segmented mask preview */ image: Image; }>; /** * Split the image into multiple layers. */ decomposeImage(input: { image_url: string; num_layers?: number; }): Promise<{ images: Image[]; }>; /** * Upscale the image. */ upscaleImage(input: { image_url: string; scale_factor?: number; }): Promise; removeByMask(input: { image_url: string; mask: HTMLCanvasElement; }): Promise; } export interface Image { /** * The URL where the file can be downloaded from. */ url?: string; /** * HTMLCanvasElement object. */ canvas?: HTMLCanvasElement; } export interface PointPrompt { x: number; y: number; /** * 1 for foreground, 0 for background */ label: number; } export interface BoxPrompt { x_min: number; y_min: number; x_max: number; y_max: number; }