feat: add inpaint region functionality and related tools

- Enhanced cursor behavior for new tools: semantic select, mask lasso, and mask rectangle.
- Updated mask edit state to include mask asset ID and kind.
- Implemented inpaint region commands for adding, applying, and removing inpaint regions.
- Introduced new operations for lasso and semantic selection tools.
- Created UI components for candidate review and inpaint region management.
- Added tests for inpaint region commands to ensure functionality.
- Updated various components to support new inpaint features and improve user experience.
This commit is contained in:
syntaxbullet
2026-07-11 16:41:22 +02:00
parent f4e13b80e7
commit ff762b8f17
78 changed files with 1632 additions and 301 deletions

View File

@@ -4,7 +4,7 @@ import type { Rect } from "@core/geometry";
import { isValidTextStyle, type TextStyle } from "@core/text-layer";
export const PROJECT_FORMAT = "image-studio-project";
export const CURRENT_PROJECT_VERSION = 1;
export const CURRENT_PROJECT_VERSION = 2;
export type ProjectFile = {
format: typeof PROJECT_FORMAT;
@@ -41,6 +41,14 @@ function migrateProject(value: unknown): ProjectFile {
if (!isRecord(value)) throw new Error("The project file must contain an object.");
if (value.format === PROJECT_FORMAT) {
if (value.version === 1 && isRecord(value.document)) {
return {
format: PROJECT_FORMAT,
version: CURRENT_PROJECT_VERSION,
savedAt: typeof value.savedAt === "string" ? value.savedAt : new Date(0).toISOString(),
document: { ...value.document, inpaintRegions: [] } as unknown as ImageDocument,
};
}
if (value.version !== CURRENT_PROJECT_VERSION) {
throw new Error(`Unsupported project version: ${String(value.version)}.`);
}
@@ -48,13 +56,13 @@ function migrateProject(value: unknown): ProjectFile {
return value as ProjectFile;
}
// Legacy exports stored ImageDocument directly. Loading upgrades them to v1.
// Legacy exports stored ImageDocument directly. Loading upgrades them to the current format.
if (looksLikeDocument(value)) {
return {
format: PROJECT_FORMAT,
version: CURRENT_PROJECT_VERSION,
savedAt: new Date(0).toISOString(),
document: value as ImageDocument,
document: { ...value, inpaintRegions: Array.isArray(value.inpaintRegions) ? value.inpaintRegions : [] } as ImageDocument,
};
}
@@ -65,7 +73,7 @@ function assertImageDocument(value: unknown): asserts value is ImageDocument {
if (!isRecord(value) || typeof value.id !== "string" || typeof value.name !== "string" || typeof value.version !== "number") {
throw new Error("The project contains an invalid document.");
}
if (!Array.isArray(value.artboards) || !Array.isArray(value.assets)) throw new Error("The project document is incomplete.");
if (!Array.isArray(value.artboards) || !Array.isArray(value.assets) || !Array.isArray(value.inpaintRegions)) throw new Error("The project document is incomplete.");
for (const asset of value.assets) {
if (!isRecord(asset) || typeof asset.id !== "string" || typeof asset.name !== "string" || typeof asset.mimeType !== "string" || typeof asset.source !== "string" || !isSize(asset.intrinsicSize)) {
@@ -78,6 +86,11 @@ function assertImageDocument(value: unknown): asserts value is ImageDocument {
}
assertLayers(artboard.layers, false);
}
for (const region of value.inpaintRegions) {
if (!isRecord(region) || typeof region.id !== "string" || typeof region.name !== "string" || typeof region.targetLayerId !== "string" || typeof region.maskAssetId !== "string" || typeof region.enabled !== "boolean") {
throw new Error("The project contains an invalid inpaint region.");
}
}
}
export function assertDocumentAssetOwnership(document: ImageDocument): void {
@@ -98,6 +111,10 @@ export function assertDocumentAssetOwnership(document: ImageDocument): void {
}
});
}
for (const region of document.inpaintRegions) {
if (!assetIds.has(region.maskAssetId)) throw new Error(`Inpaint region ${region.name} references missing mask asset ${region.maskAssetId}.`);
if (!layerIds.has(region.targetLayerId)) throw new Error(`Inpaint region ${region.name} references missing target layer ${region.targetLayerId}.`);
}
}
function isOwnedAssetSource(source: string): boolean {