diff options
| author | kj_sh604 | 2026-03-15 16:19:35 -0400 |
|---|---|---|
| committer | kj_sh604 | 2026-03-15 16:19:35 -0400 |
| commit | 6ec259a0e71174651bae95d4628138bf6fd68742 (patch) | |
| tree | 5e33c6a5ec091ecabfcb257fdc7b6a88ed8754ac /packages/excalidraw/scene/types.ts | |
| parent | 16c8578b15c727f22921f8a80a56ee4d4e7f2272 (diff) | |
refactor: packages/
Diffstat (limited to 'packages/excalidraw/scene/types.ts')
| -rw-r--r-- | packages/excalidraw/scene/types.ts | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/packages/excalidraw/scene/types.ts b/packages/excalidraw/scene/types.ts new file mode 100644 index 0000000..c0bfd1b --- /dev/null +++ b/packages/excalidraw/scene/types.ts @@ -0,0 +1,155 @@ +import type { RoughCanvas } from "roughjs/bin/canvas"; +import type { Drawable } from "roughjs/bin/core"; +import type { + ExcalidrawElement, + NonDeletedElementsMap, + NonDeletedExcalidrawElement, + NonDeletedSceneElementsMap, +} from "../element/types"; +import type { + AppClassProperties, + AppState, + EmbedsValidationStatus, + ElementsPendingErasure, + InteractiveCanvasAppState, + StaticCanvasAppState, + SocketId, + Device, + PendingExcalidrawElements, +} from "../types"; +import type { MakeBrand } from "../utility-types"; +import type { UserIdleState } from "../constants"; + +export type RenderableElementsMap = NonDeletedElementsMap & + MakeBrand<"RenderableElementsMap">; + +export type StaticCanvasRenderConfig = { + canvasBackgroundColor: AppState["viewBackgroundColor"]; + // extra options passed to the renderer + // --------------------------------------------------------------------------- + imageCache: AppClassProperties["imageCache"]; + renderGrid: boolean; + /** when exporting the behavior is slightly different (e.g. we can't use + CSS filters), and we disable render optimizations for best output */ + isExporting: boolean; + embedsValidationStatus: EmbedsValidationStatus; + elementsPendingErasure: ElementsPendingErasure; + pendingFlowchartNodes: PendingExcalidrawElements | null; +}; + +export type SVGRenderConfig = { + offsetX: number; + offsetY: number; + isExporting: boolean; + exportWithDarkMode: boolean; + renderEmbeddables: boolean; + frameRendering: AppState["frameRendering"]; + canvasBackgroundColor: AppState["viewBackgroundColor"]; + embedsValidationStatus: EmbedsValidationStatus; + /** + * whether to attempt to reuse images as much as possible through symbols + * (reduces SVG size, but may be incompoatible with some SVG renderers) + * + * @default true + */ + reuseImages: boolean; +}; + +export type InteractiveCanvasRenderConfig = { + // collab-related state + // --------------------------------------------------------------------------- + remoteSelectedElementIds: Map<ExcalidrawElement["id"], SocketId[]>; + remotePointerViewportCoords: Map<SocketId, { x: number; y: number }>; + remotePointerUserStates: Map<SocketId, UserIdleState>; + remotePointerUsernames: Map<SocketId, string>; + remotePointerButton: Map<SocketId, string | undefined>; + selectionColor: string; + // extra options passed to the renderer + // --------------------------------------------------------------------------- + renderScrollbars?: boolean; +}; + +export type RenderInteractiveSceneCallback = { + atLeastOneVisibleElement: boolean; + elementsMap: RenderableElementsMap; + scrollBars?: ScrollBars; +}; + +export type StaticSceneRenderConfig = { + canvas: HTMLCanvasElement; + rc: RoughCanvas; + elementsMap: RenderableElementsMap; + allElementsMap: NonDeletedSceneElementsMap; + visibleElements: readonly NonDeletedExcalidrawElement[]; + scale: number; + appState: StaticCanvasAppState; + renderConfig: StaticCanvasRenderConfig; +}; + +export type InteractiveSceneRenderConfig = { + canvas: HTMLCanvasElement | null; + elementsMap: RenderableElementsMap; + visibleElements: readonly NonDeletedExcalidrawElement[]; + selectedElements: readonly NonDeletedExcalidrawElement[]; + allElementsMap: NonDeletedSceneElementsMap; + scale: number; + appState: InteractiveCanvasAppState; + renderConfig: InteractiveCanvasRenderConfig; + device: Device; + callback: (data: RenderInteractiveSceneCallback) => void; +}; + +export type NewElementSceneRenderConfig = { + canvas: HTMLCanvasElement | null; + rc: RoughCanvas; + newElement: ExcalidrawElement | null; + elementsMap: RenderableElementsMap; + allElementsMap: NonDeletedSceneElementsMap; + scale: number; + appState: AppState; + renderConfig: StaticCanvasRenderConfig; +}; + +export type SceneScroll = { + scrollX: number; + scrollY: number; +}; + +export type ExportType = + | "png" + | "clipboard" + | "clipboard-svg" + | "backend" + | "svg"; + +export type ScrollBars = { + horizontal: { + x: number; + y: number; + width: number; + height: number; + } | null; + vertical: { + x: number; + y: number; + width: number; + height: number; + } | null; +}; + +export type ElementShape = Drawable | Drawable[] | null; + +export type ElementShapes = { + rectangle: Drawable; + ellipse: Drawable; + diamond: Drawable; + iframe: Drawable; + embeddable: Drawable; + freedraw: Drawable | null; + arrow: Drawable[]; + line: Drawable[]; + text: null; + image: null; + frame: null; + magicframe: null; +}; |
