feat: unify AI edit workflow
This commit is contained in:
@@ -6,7 +6,7 @@ import type { GenerateSettings } from "@editor/tools";
|
||||
|
||||
export type GenerationPrecondition =
|
||||
| { ready: true }
|
||||
| { ready: false; message: string };
|
||||
| { ready: false; message: string; repair?: "add-mask" | "set-outpaint-padding" };
|
||||
|
||||
export function checkGenerationPreconditions(
|
||||
document: ImageDocument,
|
||||
@@ -38,14 +38,14 @@ export function checkGenerationPreconditions(
|
||||
if (settings.mode === "outpaint") {
|
||||
const padding = settings.outpaint;
|
||||
if (padding.left + padding.top + padding.right + padding.bottom <= 0) {
|
||||
return missing("Add outpaint padding on at least one side.");
|
||||
return missing("Add outpaint padding on at least one side.", "set-outpaint-padding");
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.mode !== "inpaint") return { ready: true };
|
||||
|
||||
const layerMask = getLayerMask(layerInfo.layer);
|
||||
if (!layerMask?.enabled) return missing("Add and enable a layer mask on the selected image before inpainting.");
|
||||
if (!layerMask?.enabled) return missing("Paint a mask over the area you want AI to replace.", "add-mask");
|
||||
const maskLayer = index.layerById.get(layerMask.maskLayerId);
|
||||
if (!maskLayer || maskLayer.type === "group") return missing("The selected layer mask is missing.");
|
||||
const maskAsset = index.assetById.get(maskLayer.assetId);
|
||||
@@ -69,8 +69,8 @@ function modeSelectionMessage(mode: GenerateSettings["mode"]): string {
|
||||
return "Select exactly one image or raster layer to outpaint.";
|
||||
}
|
||||
|
||||
function missing(message: string): GenerationPrecondition {
|
||||
return { ready: false, message };
|
||||
function missing(message: string, repair?: Extract<GenerationPrecondition, { ready: false }>["repair"]): GenerationPrecondition {
|
||||
return { ready: false, message, ...(repair ? { repair } : {}) };
|
||||
}
|
||||
|
||||
function rectsAligned(a: { x: number; y: number; w: number; h: number }, b: { x: number; y: number; w: number; h: number }): boolean {
|
||||
|
||||
Reference in New Issue
Block a user