Files
image-studio/editor/state.ts
syntaxbullet f5c610dac5 feat: implement inpainting functionality with mask handling
- Added `createMaskedPixelReplacementSource` function to handle pixel replacement using inpainting.
- Introduced `buildInpaintBundle` to prepare inpainting data including mask generation and validation.
- Created utility functions for mask operations such as `applyMaskedContentModeToRgba`, `expandRectWithinBounds`, and others for mask manipulation.
- Developed tests for inpainting preparation and mask raster utilities to ensure functionality and correctness.
- Implemented mask raster operations including inversion, feathering, blurring, and more.
2026-07-05 09:35:16 +02:00

113 lines
2.4 KiB
TypeScript

import type { ImageDocument } from "@core/document";
import type { Angle, Rect, Size, Transform, Vec2D } from "@core/geometry";
import type { ArtboardId, AssetId, LayerId } from "@core/id";
import type { GenerateSettings, ToolState } from "./tools";
import type { TransformSession } from "./transform";
export type ViewportState = {
center: Vec2D;
zoom: number;
rotation: Angle;
size: Size;
};
export type SelectionState = {
artboardId?: ArtboardId;
layerIds: LayerId[];
};
export type MaskViewMode = "composite" | "blackWhite" | "alpha" | "overlay";
export type MaskEditState = {
targetLayerId: LayerId;
maskLayerId: LayerId;
viewMode?: MaskViewMode;
};
export type BrushPreviewState = {
position: Vec2D;
};
export type BrushStrokePreviewState = {
layerId: LayerId;
assetId: AssetId;
source: string;
};
export type GenerationCandidate = {
id: string;
source: string;
mimeType: string;
intrinsicSize: Size;
mode: GenerateSettings["mode"];
settings: GenerateSettings;
seed: number;
width: number;
height: number;
inputImage?: string;
maskImage?: string;
placement: {
artboardId: ArtboardId;
layerName: string;
transform: Transform;
};
inpaint?: {
targetLayerId: LayerId;
maskLayerId: LayerId;
sourceAssetId: AssetId;
maskAssetId: AssetId;
inputImage: string;
maskImage: string;
crop: {
assetBounds: Rect;
documentBounds: Rect;
padding: number;
maskedAreaOnly: boolean;
};
mask: {
polarity: GenerateSettings["inpaint"]["maskPolarity"];
activeBounds: Rect;
};
backend: {
growMaskBy: number;
maskedContent: GenerateSettings["inpaint"]["maskedContent"];
maskBlur: number;
maskFeather: number;
maskExpand: number;
cropPadding: number;
};
};
};
export type GenerationState = {
candidates: GenerationCandidate[];
selectedCandidateId?: string;
};
export type EditorState = {
viewport: ViewportState;
selection: SelectionState;
tools: ToolState;
generation: GenerationState;
transformSession?: TransformSession;
maskEdit?: MaskEditState;
brushPreview?: BrushPreviewState;
brushStrokePreview?: BrushStrokePreviewState;
};
export type HistorySnapshot = {
document: ImageDocument;
editor: EditorState;
};
export type HistoryState = {
past: HistorySnapshot[];
future: HistorySnapshot[];
};
export type AppState = {
document: ImageDocument;
editor: EditorState;
history: HistoryState;
};