diff --git a/packages/excalidraw/data/restore.ts b/packages/excalidraw/data/restore.ts index 62652066fa..fc11337bf7 100644 --- a/packages/excalidraw/data/restore.ts +++ b/packages/excalidraw/data/restore.ts @@ -254,6 +254,14 @@ const restoreElement = ( status: element.status || "pending", fileId: element.fileId, scale: element.scale || [1, 1], + crop: element.crop ?? null, + // TODO: restore properly + widthAtCreation: element.widthAtCreation, + heightAtCreation: element.heightAtCreation, + naturalWidth: element.naturalWidth, + naturalHeight: element.naturalHeight, + resizedFactorX: element.resizedFactorX, + resizedFactorY: element.resizedFactorY, }); case "line": // @ts-ignore LEGACY type diff --git a/packages/excalidraw/element/newElement.ts b/packages/excalidraw/element/newElement.ts index a3b259e366..f209532658 100644 --- a/packages/excalidraw/element/newElement.ts +++ b/packages/excalidraw/element/newElement.ts @@ -478,6 +478,7 @@ export const newImageElement = ( status?: ExcalidrawImageElement["status"]; fileId?: ExcalidrawImageElement["fileId"]; scale?: ExcalidrawImageElement["scale"]; + crop?: ExcalidrawImageElement["crop"]; } & ElementConstructorOpts, ): NonDeleted => { return { @@ -488,6 +489,13 @@ export const newImageElement = ( status: opts.status ?? "pending", fileId: opts.fileId ?? null, scale: opts.scale ?? [1, 1], + widthAtCreation: 0, + heightAtCreation: 0, + naturalWidth: 0, + naturalHeight: 0, + crop: opts.crop ?? null, + resizedFactorX: 1, + resizedFactorY: 1, }; }; diff --git a/packages/excalidraw/element/types.ts b/packages/excalidraw/element/types.ts index 9b09254276..967df2bcb0 100644 --- a/packages/excalidraw/element/types.ts +++ b/packages/excalidraw/element/types.ts @@ -140,6 +140,23 @@ export type ExcalidrawImageElement = _ExcalidrawElementBase & status: "pending" | "saved" | "error"; /** X and Y scale factors <-1, 1>, used for image axis flipping */ scale: [number, number]; + + /** the image's dimension after adjustment at creation */ + widthAtCreation: number; + heightAtCreation: number; + /** how much the image has been resized with respect the dimension at creation */ + resizedFactorX: number; + resizedFactorY: number; + + naturalWidth: number; + naturalHeight: number; + + crop: { + x: number; + y: number; + width: number; + height: number; + } | null; }>; export type InitializedExcalidrawImageElement = MarkNonNullable<