Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

refactor(webv2): move canvas capability types to the capabilities module

joshistoast30eab2a83adb
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/capabilities.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/capabilities.ts
index d8c4e51134..d4bef2b975 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/capabilities.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/capabilities.ts
@@ -38,9 +38,21 @@ export interface LayerExportGuard {
readonly documentGeneration: number;
}
+/**
+ * Why a guarded layer mutation declined to touch the document. Every commit
+ * that captures a permit, does async work, then re-checks before publishing
+ * reports refusal with exactly these reasons — one shared vocabulary so callers
+ * can handle them uniformly and new commits can't invent near-miss variants.
+ *
+ * `busy` — another edit owns the document, or a gesture started mid-flight.
+ * `stale` — the guarded pixels no longer match the live layer.
+ * `aborted` — the caller's signal fired.
+ */
+export type GuardedMutationRefusal = 'aborted' | 'busy' | 'locked' | 'missing' | 'stale' | 'unsupported';
+
export type CommitRasterFilterResult =
| { status: 'committed'; layerId: string }
- | { status: 'missing' | 'locked' | 'stale' | 'unsupported' | 'busy' | 'aborted' }
+ | { status: GuardedMutationRefusal }
| { status: 'failed'; message: string };
export interface RasterFilterSettings {
type: string;
@@ -65,9 +77,7 @@ export interface CommitMaskImageResultOptions {
target: MaskImageResultTarget;
signal?: AbortSignal;
}
-export type CommitMaskImageResult =
- | { status: 'committed'; layerId: string }
- | { status: 'aborted' | 'missing' | 'locked' | 'stale' | 'unsupported' | 'busy' };
+export type CommitMaskImageResult = { status: 'committed'; layerId: string } | { status: GuardedMutationRefusal };
export interface CanvasInteractionState {
activeTool: ToolId;
@@ -216,7 +226,7 @@ export type { NewRasterLayerResult };
export type ReplaceSelectionFromImageResult =
| { status: 'selected' }
- | { status: 'aborted' | 'missing' | 'locked' | 'stale' | 'unsupported' | 'busy' }
+ | { status: GuardedMutationRefusal }
| { status: 'failed'; message: string };
export interface CanvasLayerCapability {
@@ -251,7 +261,7 @@ export interface CommitGeneratedImageOptions {
export type CommitGeneratedImageResult =
| { status: 'committed'; layerId: string }
- | { status: 'missing' | 'locked' | 'stale' | 'unsupported' | 'busy' | 'aborted' }
+ | { status: GuardedMutationRefusal }
| { status: 'failed'; message: string };
export type CanvasLifecycleState = 'active' | 'cooling' | 'cool' | 'disposed';
@@ -266,12 +276,23 @@ export interface CanvasLifecycleCapability {
export type CanvasEditCapability = CanvasEditGate;
+/**
+ * The input to {@link CanvasEnginePreviewCapability.setGuardedFilterPreview}: a
+ * persisted filter result (decoded via the engine's `imageResolver`) and the
+ * document-space rect it occupies, tagged with the filter that produced it.
+ */
export interface FilterPreviewInput {
imageName: string;
rect: Rect;
filterType?: string;
}
+/**
+ * Result of {@link CanvasEngineLayerCapability.mergeVisibleRasterLayers}: `'merged'` when a new
+ * composite layer was inserted, `'not-ready'` when a contributor could not be
+ * rasterized consistently, `'busy'` when another edit owns the document, and
+ * `'nothing'` when fewer than two visible rasters have content.
+ */
export type MergeVisibleResult = 'merged' | 'not-ready' | 'busy' | 'nothing';
export type BooleanRasterResult = 'merged' | 'missing' | 'unsupported' | 'not-ready' | 'busy' | 'empty';
export type ExtractMaskedAreaResult =
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/booleanMergeController.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/booleanMergeController.ts
index 723671fcd1..9d940f847f 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/booleanMergeController.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/booleanMergeController.ts
@@ -16,13 +16,13 @@ type ExportResult =
| { status: 'ok'; surface: RasterSurface; rect: Rect; guard: LayerExportGuard; release(): void }
| { status: 'missing' | 'disabled' | 'unsupported' | 'empty' | 'not-ready' | 'over-budget' };
-export interface BooleanMergeControllerOptions {
+export interface BooleanMergeControllerOptions<Permit> {
readonly backend: RasterBackend;
readonly history: History;
readonly getDocument: () => CanvasDocumentContractV2 | null;
readonly getReducerDocument: () => CanvasDocumentContractV2 | null;
- readonly capturePermit: () => object | null;
- readonly isPermitCurrent: (permit: object) => boolean;
+ readonly capturePermit: () => Permit | null;
+ readonly isPermitCurrent: (permit: Permit) => boolean;
readonly isGestureActive: () => boolean;
readonly endBurst: () => void;
readonly isCacheReady: (layer: CanvasLayerContract, document: CanvasDocumentContractV2) => boolean;
@@ -46,10 +46,10 @@ const modes: Record<BooleanRasterOperation, GlobalCompositeOperation> = {
};
/** Owns guarded two-layer boolean compositing and atomic stack history. */
-export class BooleanMergeController {
+export class BooleanMergeController<Permit> {
private disposed = false;
- constructor(private readonly deps: BooleanMergeControllerOptions) {}
+ constructor(private readonly deps: BooleanMergeControllerOptions<Permit>) {}
async merge(upperLayerId: string, operation: BooleanRasterOperation): Promise<BooleanRasterResult> {
const permit = this.deps.capturePermit();
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/copyLayerController.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/copyLayerController.ts
index 06449516c1..fe24bb25b9 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/copyLayerController.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/copyLayerController.ts
@@ -10,12 +10,12 @@ type ExportResult =
| { status: 'ok'; surface: RasterSurface; rect: Rect; guard: LayerExportGuard; release(): void }
| { status: 'missing' | 'disabled' | 'unsupported' | 'empty' | 'not-ready' | 'over-budget' };
-export interface CopyLayerControllerOptions {
+export interface CopyLayerControllerOptions<Permit> {
readonly history: History;
readonly getDocument: () => CanvasDocumentContractV2 | null;
readonly getReducerDocument: () => CanvasDocumentContractV2 | null;
- readonly capturePermit: () => object | null;
- readonly isPermitCurrent: (permit: object) => boolean;
+ readonly capturePermit: () => Permit | null;
+ readonly isPermitCurrent: (permit: Permit) => boolean;
readonly isGestureActive: () => boolean;
readonly endBurst: () => void;
readonly exportBaked: (layerId: string) => Promise<ExportResult>;
@@ -31,9 +31,9 @@ export interface CopyLayerControllerOptions {
}
/** Owns guarded baked copies into new raster paint layers. */
-export class CopyLayerController {
+export class CopyLayerController<Permit> {
private disposed = false;
- constructor(private readonly deps: CopyLayerControllerOptions) {}
+ constructor(private readonly deps: CopyLayerControllerOptions<Permit>) {}
async copyToRaster(layerId: string): Promise<string | null> {
const permit = this.deps.capturePermit();
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/cropLayerController.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/cropLayerController.ts
index f7919a8840..230afb3d93 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/cropLayerController.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/cropLayerController.ts
@@ -27,13 +27,13 @@ interface PixelSnapshot {
rect: Rect;
}
-export interface CropLayerControllerOptions {
+export interface CropLayerControllerOptions<Permit> {
readonly backend: RasterBackend;
readonly history: History;
readonly getDocument: () => CanvasDocumentContractV2 | null;
readonly getReducerDocument: () => CanvasDocumentContractV2 | null;
- readonly capturePermit: () => object | null;
- readonly isPermitCurrent: (permit: object) => boolean;
+ readonly capturePermit: () => Permit | null;
+ readonly isPermitCurrent: (permit: Permit) => boolean;
readonly isGestureActive: () => boolean;
readonly endBurst: () => void;
readonly isSupportedSource: (source: CanvasLayerSourceContract) => boolean;
@@ -54,9 +54,9 @@ export interface CropLayerControllerOptions {
}
/** Owns guarded crop-to-bbox conversion and replayable pixel snapshots. */
-export class CropLayerController {
+export class CropLayerController<Permit> {
private disposed = false;
- constructor(private readonly deps: CropLayerControllerOptions) {}
+ constructor(private readonly deps: CropLayerControllerOptions<Permit>) {}
async crop(layerId: string): Promise<CropLayerResult> {
const permit = this.deps.capturePermit();
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/extractMaskedAreaController.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/extractMaskedAreaController.ts
index 13a64d36a3..8b697ad8f5 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/extractMaskedAreaController.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/extractMaskedAreaController.ts
@@ -24,7 +24,7 @@ type ExportResult =
| { status: 'ok'; surface: RasterSurface; rect: Rect; guard: LayerExportGuard; release(): void }
| { status: 'missing' | 'disabled' | 'unsupported' | 'empty' | 'not-ready' | 'over-budget' };
-export interface ExtractMaskedAreaControllerOptions {
+export interface ExtractMaskedAreaControllerOptions<Permit> {
readonly backend: RasterBackend;
readonly layers: LayerCacheStore;
readonly derived: DerivedSurfaceCache;
@@ -32,8 +32,8 @@ export interface ExtractMaskedAreaControllerOptions {
readonly history: History;
readonly getDocument: () => CanvasDocumentContractV2 | null;
readonly getReducerDocument: () => CanvasDocumentContractV2 | null;
- readonly capturePermit: () => object | null;
- readonly isPermitCurrent: (permit: object) => boolean;
+ readonly capturePermit: () => Permit | null;
+ readonly isPermitCurrent: (permit: Permit) => boolean;
readonly isGestureActive: () => boolean;
readonly endBurst: () => void;
readonly isCacheReady: (layer: CanvasLayerContract, document: CanvasDocumentContractV2) => boolean;
@@ -54,9 +54,9 @@ export interface ExtractMaskedAreaControllerOptions {
}
/** Owns guarded extraction of raster content through an inpaint mask. */
-export class ExtractMaskedAreaController {
+export class ExtractMaskedAreaController<Permit> {
private disposed = false;
- constructor(private readonly deps: ExtractMaskedAreaControllerOptions) {}
+ constructor(private readonly deps: ExtractMaskedAreaControllerOptions<Permit>) {}
async extract(maskLayerId: string): Promise<ExtractMaskedAreaResult> {
const permit = this.deps.capturePermit();
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/layerController.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/layerController.ts
index bae210d218..0cc5022fc4 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/layerController.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/layerController.ts
@@ -13,7 +13,7 @@ import { NewRasterLayerController, type NewRasterLayerControllerOptions } from '
import { RasterizeLayerController, type RasterizeLayerControllerOptions } from './rasterizeLayerController';
import { ThumbnailController, type ThumbnailControllerOptions } from './thumbnailController';
-export type LayerControllerDeps = Omit<
+export type LayerControllerDeps<Permit> = Omit<
CanvasLayerCapability,
'applyStructuralPreview' | 'canCommitStructural' | 'commitStagedImage' | 'commitStructural' | 'invertMask'
> &
@@ -23,15 +23,15 @@ export type LayerControllerDeps = Omit<
structural: StructuralLayerController;
rasterize: RasterizeLayerControllerOptions;
merge: MergeLayerControllerOptions;
- booleanMerge: BooleanMergeControllerOptions;
- extractMaskedArea: ExtractMaskedAreaControllerOptions;
- crop: CropLayerControllerOptions;
- copy: CopyLayerControllerOptions;
- newRasterLayer: NewRasterLayerControllerOptions;
+ booleanMerge: BooleanMergeControllerOptions<Permit>;
+ extractMaskedArea: ExtractMaskedAreaControllerOptions<Permit>;
+ crop: CropLayerControllerOptions<Permit>;
+ copy: CopyLayerControllerOptions<Permit>;
+ newRasterLayer: NewRasterLayerControllerOptions<Permit>;
};
/** Public layer-operation boundary. Implementations are injected by the composition root. */
-export class LayerController {
+export class LayerController<Permit> {
readonly layers: Omit<CanvasLayerCapability, 'commitStagedImage'>;
readonly previews: CanvasPreviewCapability;
readonly mask: MaskLayerController;
@@ -39,14 +39,14 @@ export class LayerController {
readonly structural: StructuralLayerController;
readonly rasterize: RasterizeLayerController;
readonly merge: MergeLayerController;
- readonly booleanMerge: BooleanMergeController;
- readonly extractMaskedArea: ExtractMaskedAreaController;
- readonly crop: CropLayerController;
- readonly copy: CopyLayerController;
- readonly newRasterLayer: NewRasterLayerController;
+ readonly booleanMerge: BooleanMergeController<Permit>;
+ readonly extractMaskedArea: ExtractMaskedAreaController<Permit>;
+ readonly crop: CropLayerController<Permit>;
+ readonly copy: CopyLayerController<Permit>;
+ readonly newRasterLayer: NewRasterLayerController<Permit>;
private disposed = false;
- constructor(deps: LayerControllerDeps) {
+ constructor(deps: LayerControllerDeps<Permit>) {
this.mask = new MaskLayerController(deps.mask);
this.thumbnail = new ThumbnailController(deps.thumbnail);
this.structural = deps.structural;
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/newRasterLayerController.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/newRasterLayerController.ts
index 091b2e4e20..5d89ff3662 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/newRasterLayerController.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/controllers/newRasterLayerController.ts
@@ -12,15 +12,15 @@ import { layerMatrix } from '@workbench/canvas-engine/tools/moveHitTest';
export type NewRasterLayerResult = { status: 'created'; layerId: string } | { status: 'busy' | 'empty' | 'missing' };
-export interface NewRasterLayerControllerOptions {
+export interface NewRasterLayerControllerOptions<Permit> {
readonly backend: RasterBackend;
readonly layers: LayerCacheStore;
readonly selection: SelectionState;
readonly history: History;
readonly getDocument: () => CanvasDocumentContractV2 | null;
readonly getReducerDocument: () => CanvasDocumentContractV2 | null;
- readonly capturePermit: () => object | null;
- readonly isPermitCurrent: (permit: object) => boolean;
+ readonly capturePermit: () => Permit | null;
+ readonly isPermitCurrent: (permit: Permit) => boolean;
readonly isGestureActive: () => boolean;
readonly endBurst: () => void;
readonly createLayerId: () => string;
@@ -47,10 +47,10 @@ export interface NewRasterLayerControllerOptions {
* The new layer is inserted directly above the active one, which is where the
* user is looking, and becomes the selection.
*/
-export class NewRasterLayerController {
+export class NewRasterLayerController<Permit> {
private disposed = false;
- constructor(private readonly deps: NewRasterLayerControllerOptions) {}
+ constructor(private readonly deps: NewRasterLayerControllerOptions<Permit>) {}
/**
* Inserts `pixels` as a new paint layer covering `rect` (document space).
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts
index 11338a2ea7..cc1ef67b6f 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts
@@ -27,23 +27,29 @@
import type {
CanvasHistoryCapability,
+ CanvasDiagnosticsCapability,
CanvasEngine,
+ CanvasEngineExportCapability,
+ CanvasEngineLayerCapability,
+ CanvasEnginePreviewCapability,
+ CanvasEngineToolCapability,
CanvasInteractionState,
CanvasInteractionStateCapability,
CanvasDocumentCapability,
CanvasDocumentSnapshot,
- CanvasExportCapability,
CanvasLifecycleCapability,
- CanvasLayerCapability,
- CanvasPreviewCapability,
CanvasSelectionCapability,
CanvasSurfaceCapability,
- CanvasToolCapability,
CanvasViewportCapability,
BooleanRasterOperation,
+ BooleanRasterResult,
+ CropLayerResult,
ExportBakedLayerPixelsOptions,
ExportLayerPixelsOptions,
+ ExtractMaskedAreaResult,
+ FilterPreviewInput,
LayerExportGuard,
+ MergeVisibleResult,
NewRasterLayerResult,
PsdExportResult,
StagedPreviewInput,
@@ -55,17 +61,27 @@ import type {
CaptureRasterSnapshotResult,
} from '@workbench/canvas-engine/rasterTransactions';
export type {
+ BooleanRasterResult,
+ CanvasDiagnosticsCapability,
CanvasEngine,
+ CanvasEngineExportCapability,
+ CanvasEngineLayerCapability,
+ CanvasEnginePreviewCapability,
+ CanvasEngineToolCapability,
CommitGeneratedImageOptions,
CommitGeneratedImageResult,
CommitStagedImageOptions,
CommitStagedImageResult,
+ CropLayerResult,
ExportBakedLayerBlobResult,
ExportBakedLayerPixelsOptions,
ExportLayerPixelsOptions,
+ ExtractMaskedAreaResult,
+ FilterPreviewInput,
GeneratedImageTarget,
LayerExportGuard,
LayerThumbnailRequestResult,
+ MergeVisibleResult,
PsdExportResult,
ReplaceSelectionFromImageResult,
} from '@workbench/canvas-engine/capabilities';
@@ -97,21 +113,13 @@ import type { CanvasProjectMutation } from '@workbench/canvasProjectMutations';
import { ControlPixelController } from '@workbench/canvas-engine/controllers/controlPixelController';
import { EditingController } from '@workbench/canvas-engine/controllers/editingController';
-import {
- FilterResultController,
- type CommitRasterFilterOptions,
- type CommitRasterFilterResult,
-} from '@workbench/canvas-engine/controllers/filterResultController';
+import { FilterResultController } from '@workbench/canvas-engine/controllers/filterResultController';
import { GeneratedResultController } from '@workbench/canvas-engine/controllers/generatedResultController';
import { HistoryController } from '@workbench/canvas-engine/controllers/historyController';
import { InteractionController } from '@workbench/canvas-engine/controllers/interactionController';
import { LayerController } from '@workbench/canvas-engine/controllers/layerController';
import { LayerMutationController } from '@workbench/canvas-engine/controllers/layerMutationController';
-import {
- MaskResultController,
- type CommitMaskImageResult,
- type CommitMaskImageResultOptions,
-} from '@workbench/canvas-engine/controllers/maskResultController';
+import { MaskResultController } from '@workbench/canvas-engine/controllers/maskResultController';
import {
createCanvasMutationContext,
type DocumentEditPermit,
@@ -123,7 +131,7 @@ import { RasterExportController } from '@workbench/canvas-engine/controllers/ras
import { RenderController } from '@workbench/canvas-engine/controllers/renderController';
import { StagedResultController } from '@workbench/canvas-engine/controllers/stagedResultController';
import { StructuralLayerController } from '@workbench/canvas-engine/controllers/structuralLayerController';
-import { createCanvasDiagnostics, type CanvasDiagnosticsSnapshot } from '@workbench/canvas-engine/diagnostics';
+import { createCanvasDiagnostics } from '@workbench/canvas-engine/diagnostics';
import {
createEngineStores,
type EngineStores,
@@ -192,38 +200,6 @@ import { getSourceBounds, getSourceContentRect, isRenderableLayer, renderableSou
import { createImagePatchEntry, type ImagePatchApply } from './history/imagePatch';
import { createViewTool } from './tools/viewTool';
-/**
- * The input to {@link CanvasEnginePreviewCapability.setStagedPreview}: either a persisted image
- * (decoded via the engine's `imageResolver`, sized to the decoded pixels — the
- * final staged candidate, optionally with candidate-specific placement) or an
- * inline data-URL with explicit document-space dimensions (a live
- * denoise-progress frame, scaled to fill those dims at the current bbox).
- */
-export interface FilterPreviewInput {
- imageName: string;
- rect: Rect;
- filterType?: string;
-}
-
-/**
- * Result of {@link CanvasEngineLayerCapability.mergeVisibleRasterLayers}: `'merged'` when a new
- * composite layer was inserted, `'not-ready'` when a contributor could not be
- * rasterized consistently, `'busy'` when another edit owns the document, and
- * `'nothing'` when fewer than two visible rasters have content.
- */
-export type MergeVisibleResult = 'merged' | 'not-ready' | 'busy' | 'nothing';
-
-export type BooleanRasterResult = 'merged' | 'missing' | 'unsupported' | 'not-ready' | 'busy' | 'empty';
-
-export type ExtractMaskedAreaResult =
- | { status: 'extracted'; layerId: string }
- | { status: 'missing' | 'unsupported' | 'not-ready' | 'busy' | 'empty' };
-
-export type CropLayerResult =
- | { status: 'cropped' }
- | { status: 'missing' | 'locked' | 'unsupported' | 'empty' | 'not-ready' | 'over-budget' | 'busy' }
- | { status: 'failed'; message: string };
-
/**
* Result of {@link CanvasEngineExportCapability.exportRasterLayersToPsd}: `'exported'` on
* success, `'nothing'` when there are no raster layers with content, `'too-large'`
@@ -329,39 +305,19 @@ export interface CanvasEngineOptions {
enableDiagnostics?: boolean;
}
-export interface CanvasEngineToolCapability extends CanvasToolCapability {
- canTargetLayerFromContextMenu(): boolean;
- handleEscapePriority(options: { gestureWasActive: boolean }): void;
- onStrokeCommitted(listener: (event: StrokeCommittedEvent) => void): () => void;
- setInteractionLocked(locked: boolean): void;
-}
-
-export interface CanvasEngineLayerCapability extends CanvasLayerCapability {
- applyTransform(): void;
- booleanMergeRasterLayers(upperLayerId: string, operation: BooleanRasterOperation): Promise<BooleanRasterResult>;
- cancelTextEdit(): void;
- cancelTransform(): void;
- clearMask(layerId: string): boolean;
- commitLayerConversion(label: string, expectedLiveLayer: CanvasLayerContract, after: CanvasLayerContract): boolean;
- commitLayerCopy(label: string, sourceLayerId: string, layer: CanvasLayerContract, index: number): boolean;
- commitMaskImageResult(options: CommitMaskImageResultOptions): Promise<CommitMaskImageResult>;
- commitOpenTextSession(): boolean;
- commitRasterFilterResult(options: CommitRasterFilterOptions): Promise<CommitRasterFilterResult>;
- commitTextEdit(content: string, styleChanges?: Partial<TextToolOptions>): void;
- copyLayerToRaster(layerId: string): Promise<string | null>;
- cropLayerToBbox(layerId: string): Promise<CropLayerResult>;
- mergeLayerDown(upperLayerId: string): boolean;
- mergeVisibleRasterLayers(): Promise<MergeVisibleResult>;
- nudgeSelectedLayer(dx: number, dy: number): void;
- openTextCreate(docPoint: Vec2): void;
- openTextEdit(layerId: string): void;
- rasterizeLayer(layerId: string): boolean;
- setTextEditContentReader(reader: (() => string) | null): void;
- updateTextEditStyle(patch: Partial<TextToolOptions>): void;
- updateTransformSession(transform: LayerTransform): void;
-}
+export interface CanvasEngineSelectionCapability extends CanvasSelectionCapability {}
-export interface CanvasEngineExportCapability extends CanvasExportCapability {
+/**
+ * The export surface the engine actually builds. It widens the public
+ * {@link CanvasEngineExportCapability} with members that stay inside the Canvas
+ * module — raster snapshots, layer-pixel exports, and the composite executor
+ * deps are consumed by `canvas-operations`, never by `api.ts` callers.
+ *
+ * Declared as an `extends` rather than a parallel copy so the two can never
+ * silently diverge: anything added to the public capability must be implemented
+ * here, and anything added here is visibly internal.
+ */
+export interface CanvasEngineInternalExportCapability extends CanvasEngineExportCapability {
captureRasterSnapshot(
documentSnapshot: CanvasDocumentSnapshot,
layerIds: readonly string[],
@@ -372,31 +328,12 @@ export interface CanvasEngineExportCapability extends CanvasExportCapability {
options?: ExportBakedLayerPixelsOptions
): Promise<ExportBakedLayerPixelsResult>;
exportLayerPixels(layerId: string, options?: ExportLayerPixelsOptions): Promise<ExportLayerPixelsResult>;
- exportRasterLayersToPsd(fileName: string): Promise<PsdExportResult>;
- extractMaskedArea(maskLayerId: string): Promise<ExtractMaskedAreaResult>;
getCompositeExecutorDeps(): CanvasCompositeExecutorDeps;
}
-export interface CanvasEngineSelectionCapability extends CanvasSelectionCapability {}
-
-export interface CanvasEnginePreviewCapability extends CanvasPreviewCapability {
- setGuardedFilterPreview(
- layerId: string,
- input: FilterPreviewInput,
- guard: LayerExportGuard
- ): Promise<'shown' | 'missing' | 'stale'>;
- setStagedPreview(input: StagedPreviewInput | null): void;
-}
-
-export interface CanvasDiagnosticsCapability {
- clearCaches(): Promise<void>;
- getDiagnostics(): Readonly<CanvasDiagnosticsSnapshot>;
- logDebugInfo(): void;
-}
-
/** Private engine composition shape used only inside the Canvas implementation and its tests. */
export interface CanvasEngineImplementation extends CanvasEngine {
- readonly exports: CanvasEngineExportCapability;
+ readonly exports: CanvasEngineInternalExportCapability;
readonly stores: EngineStores;
}
@@ -942,7 +879,7 @@ export const createCanvasEngine = (opts: CanvasEngineOptions): CanvasEngineCoreC
getDocument: () => mirror.getDocument(),
isGestureActive: () => pipeline.isGestureActive(),
isGuardCurrent: (guard) => isLayerExportGuardCurrent(guard),
- isPermitCurrent: (permit) => isDocumentEditPermitCurrent(permit as DocumentEditPermit),
+ isPermitCurrent: (permit) => isDocumentEditPermitCurrent(permit),
},
text: {
canEdit: () => canEditDocument(),
@@ -2741,7 +2678,7 @@ export const createCanvasEngine = (opts: CanvasEngineOptions): CanvasEngineCoreC
getDocument: () => mirror.getDocument(),
history,
isGestureActive: () => pipeline.isGestureActive(),
- isPermitCurrent: (permit) => isDocumentEditPermitCurrent(permit as DocumentEditPermit),
+ isPermitCurrent: (permit) => isDocumentEditPermitCurrent(permit),
now: () => new Date().toISOString(),
});
const commitStagedImage = stagedResultController.commit.bind(stagedResultController);
@@ -3108,7 +3045,7 @@ export const createCanvasEngine = (opts: CanvasEngineOptions): CanvasEngineCoreC
isCacheReady: isLayerCacheReadyForOp,
isGestureActive: () => pipeline.isGestureActive(),
isGuardCurrent: isLayerExportGuardCurrent,
- isPermitCurrent: (permit) => isDocumentEditPermitCurrent(permit as DocumentEditPermit),
+ isPermitCurrent: (permit) => isDocumentEditPermitCurrent(permit),
preparePixels: prepareGeneratedPaintCache,
},
crop: {
@@ -3125,7 +3062,7 @@ export const createCanvasEngine = (opts: CanvasEngineOptions): CanvasEngineCoreC
installPrepared: (prepared) => installGeneratedPaintCache(prepared),
isGestureActive: () => pipeline.isGestureActive(),
isGuardCurrent: isLayerExportGuardCurrent,
- isPermitCurrent: (permit) => isDocumentEditPermitCurrent(permit as DocumentEditPermit),
+ isPermitCurrent: (permit) => isDocumentEditPermitCurrent(permit),
isSupportedSource: isSupportedExportSource,
preparePixels: prepareGeneratedPaintCache,
},
@@ -3141,7 +3078,7 @@ export const createCanvasEngine = (opts: CanvasEngineOptions): CanvasEngineCoreC
installPrepared: (prepared) => installGeneratedPaintCache(prepared),
isGestureActive: () => pipeline.isGestureActive(),
isGuardCurrent: isLayerExportGuardCurrent,
- isPermitCurrent: (permit) => isDocumentEditPermitCurrent(permit as DocumentEditPermit),
+ isPermitCurrent: (permit) => isDocumentEditPermitCurrent(permit),
preparePixels: prepareGeneratedPaintCache,
},
extractMaskedArea: {
@@ -3163,7 +3100,7 @@ export const createCanvasEngine = (opts: CanvasEngineOptions): CanvasEngineCoreC
isCacheReady: isLayerCacheReadyForOp,
isGestureActive: () => pipeline.isGestureActive(),
isGuardCurrent: isLayerExportGuardCurrent,
- isPermitCurrent: (permit) => isDocumentEditPermitCurrent(permit as DocumentEditPermit),
+ isPermitCurrent: (permit) => isDocumentEditPermitCurrent(permit),
layers: layerCache,
preparePixels: prepareGeneratedPaintCache,
rasterize: (layerId) => rasterizeLayerPixelsForStructural(layerId),
@@ -3180,7 +3117,7 @@ export const createCanvasEngine = (opts: CanvasEngineOptions): CanvasEngineCoreC
history,
installPrepared: (prepared) => installGeneratedPaintCache(prepared),
isGestureActive: () => pipeline.isGestureActive(),
- isPermitCurrent: (permit) => isDocumentEditPermitCurrent(permit as DocumentEditPermit),
+ isPermitCurrent: (permit) => isDocumentEditPermitCurrent(permit),
layers: layerCache,
preparePixels: prepareGeneratedPaintCache,
selection: editingController.selection,
@@ -3435,7 +3372,7 @@ export const createCanvasEngine = (opts: CanvasEngineOptions): CanvasEngineCoreC
}
}
};
- const exportCapability: CanvasEngineExportCapability = {
+ const exportCapability: CanvasEngineInternalExportCapability = {
captureLayerExportGuard: captureCurrentLayerExportGuard,
captureRasterSnapshot,
exportBakedLayerBlob,