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.

feat(webv2): separate hiding overlay layers from disabling them

joshistoastba79d2293a4f
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index a6a91a2cb3..bbde8df8df 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -1225,6 +1225,7 @@
"selectTextTool": "Select text tool",
"selectTransformTool": "Select transform tool",
"selectViewTool": "Select view tool",
+ "toggleNonRasterLayers": "Hide control, guidance and mask layers",
"undo": "Undo canvas edit"
},
"contextMenu": {
@@ -1512,6 +1513,7 @@
"selectObject": "Select object",
"show": "Show layer",
"toggleAutoNegative": "Toggle auto-negative",
+ "toggleHidden": "Show/hide on canvas",
"toggleLock": "Toggle lock",
"toggleTransparencyEffect": "Toggle transparency effect",
"toggleVisibility": "Toggle visibility",
@@ -1799,7 +1801,8 @@
"mergeVisible": "Merge visible",
"new": "New layer",
"showAll": "Show all",
- "toggleVisibility": "Toggle group visibility"
+ "toggleVisibility": "Toggle group visibility",
+ "toggleHidden": "Show/hide all on canvas"
},
"groups": {
"control": "Control Layers",
diff --git a/invokeai/frontend/webv2/src/workbench/autoRoutePolicy.ts b/invokeai/frontend/webv2/src/workbench/autoRoutePolicy.ts
index 94e4330604..2fce8c0e20 100644
--- a/invokeai/frontend/webv2/src/workbench/autoRoutePolicy.ts
+++ b/invokeai/frontend/webv2/src/workbench/autoRoutePolicy.ts
@@ -114,6 +114,9 @@ const CANVAS_EDIT_CONFIDENCE = {
saveCanvasSnapshot: 'none',
setCanvasBbox: 'high',
setCanvasLayersEnabled: 'conditional',
+ // Display-only: hiding an overlay changes nothing about the generated image,
+ // so it must never re-route the invoke target.
+ setCanvasLayersHidden: 'none',
setCanvasSelectedLayer: 'none',
setCanvasStagingAutoSwitch: 'none',
setStagedImageIndex: 'none',
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/capabilities.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/capabilities.ts
index 74c09f828a..09cd42b0cc 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/capabilities.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/capabilities.ts
@@ -432,6 +432,7 @@ export { bboxEquals, constrainBboxToRatio, roundBbox } from './tools/bboxHitTest
export { isEmpty, union } from './math/rect';
export { ZOOM_SNAP_CANDIDATES } from './math/snapping';
export { isLayerPixelEditEligible } from './editing/controlPixelEdit';
+export { type HideableLayer, isHideableLayer, isLayerHidden } from './document/sources';
export {
getLayerThumbnailFallbackRenderState,
nextLayerThumbnailFallbackStage,
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/contracts.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/contracts.ts
index 02071a1ae2..a57d05f11b 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/contracts.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/contracts.ts
@@ -233,6 +233,18 @@ export interface CanvasControlLayerContract extends CanvasLayerBaseContract {
adapter: CanvasControlAdapterContract;
withTransparencyEffect: boolean;
filter?: { type: string; settings: Record<string, unknown> };
+ /**
+ * Whether this layer's on-canvas preview is suppressed. DISPLAY ONLY — a
+ * hidden layer still affects generation exactly as it would if visible, which
+ * is the whole point: you can get a control map or mask overlay out of the way
+ * without changing the image it produces. Absent ⇒ not hidden.
+ *
+ * Only these three types carry it. For a raster layer, visibility and
+ * participation are the SAME fact — the raster stack IS the generation
+ * input — so `isEnabled` alone says everything, and a hidden-but-contributing
+ * raster layer is deliberately not representable.
+ */
+ isHidden?: boolean;
}
export interface CanvasRegionalGuidanceLayerContract extends CanvasLayerBaseContract {
@@ -242,6 +254,18 @@ export interface CanvasRegionalGuidanceLayerContract extends CanvasLayerBaseCont
negativePrompt: string | null;
autoNegative: boolean;
referenceImages: RegionalGuidanceReferenceImage[];
+ /**
+ * Whether this layer's on-canvas preview is suppressed. DISPLAY ONLY — a
+ * hidden layer still affects generation exactly as it would if visible, which
+ * is the whole point: you can get a control map or mask overlay out of the way
+ * without changing the image it produces. Absent ⇒ not hidden.
+ *
+ * Only these three types carry it. For a raster layer, visibility and
+ * participation are the SAME fact — the raster stack IS the generation
+ * input — so `isEnabled` alone says everything, and a hidden-but-contributing
+ * raster layer is deliberately not representable.
+ */
+ isHidden?: boolean;
}
export interface CanvasInpaintMaskLayerContract extends CanvasLayerBaseContract {
@@ -249,6 +273,18 @@ export interface CanvasInpaintMaskLayerContract extends CanvasLayerBaseContract
mask: CanvasMaskContract;
noiseLevel?: number;
denoiseLimit?: number;
+ /**
+ * Whether this layer's on-canvas preview is suppressed. DISPLAY ONLY — a
+ * hidden layer still affects generation exactly as it would if visible, which
+ * is the whole point: you can get a control map or mask overlay out of the way
+ * without changing the image it produces. Absent ⇒ not hidden.
+ *
+ * Only these three types carry it. For a raster layer, visibility and
+ * participation are the SAME fact — the raster stack IS the generation
+ * input — so `isEnabled` alone says everything, and a hidden-but-contributing
+ * raster layer is deliberately not representable.
+ */
+ isHidden?: boolean;
}
export type CanvasLayerContract =
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/document/sources.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/document/sources.test.ts
index 20a204bce8..7910ba43cf 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/document/sources.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/document/sources.test.ts
@@ -10,6 +10,8 @@ import {
getSourceBounds,
getSourceContentRect,
getSourcePixelSize,
+ isHideableLayer,
+ isLayerHidden,
isMaskLayer,
isRenderableLayer,
maskAsPaintSource,
@@ -131,3 +133,72 @@ describe('getSourceBounds — parametric sources', () => {
expect(getSourceBounds(rasterLayer(gradient), doc)).toEqual({ height: 200, width: 300, x: 0, y: 0 });
});
});
+
+describe('hide vs disable', () => {
+ const control = (isHidden?: boolean): CanvasLayerContract => ({
+ adapter: { beginEndStepPct: [0, 1], controlMode: 'balanced', kind: 'controlnet', model: null, weight: 1 },
+ blendMode: 'normal',
+ id: 'c',
+ isEnabled: true,
+ isHidden,
+ isLocked: false,
+ name: 'c',
+ opacity: 1,
+ source: { image: { height: 10, imageName: 'c', width: 10 }, type: 'image' },
+ transform: { rotation: 0, scaleX: 1, scaleY: 1, x: 0, y: 0 },
+ type: 'control',
+ withTransparencyEffect: false,
+ });
+
+ const inpaintMask = (isHidden?: boolean): CanvasLayerContract => ({
+ blendMode: 'normal',
+ id: 'm',
+ isEnabled: true,
+ isHidden,
+ isLocked: false,
+ mask: { bitmap: null, fill: { color: '#f00', style: 'solid' } },
+ name: 'm',
+ opacity: 1,
+ transform: { rotation: 0, scaleX: 1, scaleY: 1, x: 0, y: 0 },
+ type: 'inpaint_mask',
+ });
+
+ const raster = (): CanvasLayerContract => ({
+ blendMode: 'normal',
+ id: 'r',
+ isEnabled: true,
+ isLocked: false,
+ name: 'r',
+ opacity: 1,
+ source: { bitmap: null, offset: { x: 0, y: 0 }, type: 'paint' },
+ transform: { rotation: 0, scaleX: 1, scaleY: 1, x: 0, y: 0 },
+ type: 'raster',
+ });
+
+ it('marks the three overlay types as hideable', () => {
+ expect(isHideableLayer(control())).toBe(true);
+ expect(isHideableLayer(inpaintMask())).toBe(true);
+ });
+
+ it('does not mark raster layers hideable — visibility IS participation for them', () => {
+ expect(isHideableLayer(raster())).toBe(false);
+ expect(isLayerHidden(raster())).toBe(false);
+ });
+
+ it('treats an absent flag as not hidden, so older documents load unchanged', () => {
+ expect(isLayerHidden(control(undefined))).toBe(false);
+ expect(isLayerHidden(inpaintMask(undefined))).toBe(false);
+ });
+
+ it('reports hidden only when the flag is explicitly set', () => {
+ expect(isLayerHidden(control(true))).toBe(true);
+ expect(isLayerHidden(control(false))).toBe(false);
+ });
+
+ it('leaves a hidden layer renderable — hiding is display-only, not disabling', () => {
+ // `isRenderableLayer` gates rasterization and generation eligibility; only
+ // `isEnabled` may switch it off.
+ expect(isRenderableLayer(control(true))).toBe(true);
+ expect(isRenderableLayer({ ...control(true), isEnabled: false })).toBe(false);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/document/sources.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/document/sources.ts
index 57657d6eeb..9d3e638948 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/document/sources.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/document/sources.ts
@@ -37,6 +37,27 @@ const hasSource = (layer: CanvasLayerContract): layer is SourceLayer =>
export const isMaskLayer = (layer: CanvasLayerContract): layer is MaskLayer =>
layer.type === 'inpaint_mask' || layer.type === 'regional_guidance';
+/**
+ * The layer types that can be hidden without being disabled — everything drawn
+ * on canvas purely to SHOW you where an effect applies.
+ *
+ * Raster layers are excluded on purpose: the raster stack is the generation
+ * input, so hiding one and still generating from it is not a state that can be
+ * explained to a user. Their contracts have no `isHidden` field at all.
+ */
+export type HideableLayer = Extract<CanvasLayerContract, { type: 'control' | 'inpaint_mask' | 'regional_guidance' }>;
+
+/** True when `layer` supports being hidden independently of being enabled. */
+export const isHideableLayer = (layer: CanvasLayerContract): layer is HideableLayer =>
+ layer.type === 'control' || isMaskLayer(layer);
+
+/**
+ * True when `layer`'s on-canvas preview is suppressed. DISPLAY ONLY — callers
+ * that decide what the image contains (generation, export) must NOT consult it;
+ * that is `isEnabled`'s job.
+ */
+export const isLayerHidden = (layer: CanvasLayerContract): boolean => isHideableLayer(layer) && layer.isHidden === true;
+
/** The number of strict composite groups (see {@link layerGroupRank}). */
export const LAYER_GROUP_COUNT = 4;
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/compositor.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/compositor.test.ts
index 3732fa48a7..03817c3b2b 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/compositor.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/compositor.test.ts
@@ -4,6 +4,7 @@ import type {
CanvasImageRef,
CanvasLayerContract,
CanvasRasterLayerContractV2,
+ CanvasRegionalGuidanceLayerContract,
} from '@workbench/canvas-engine/contracts';
import type { Mat2d } from '@workbench/canvas-engine/types';
@@ -690,3 +691,52 @@ describe('compositeDocument — floating selection', () => {
expect(drawn).toEqual([cache.surface.canvas]);
});
});
+
+describe('compositeDocument — hidden layers', () => {
+ // Typed to the guidance member: `isHidden` exists only on the three overlay
+ // contracts, so a bare spread of the union does not accept it — which is the
+ // invariant this design is built on.
+ const hiddenMask = (id: string): CanvasLayerContract => ({
+ ...(maskLayer(id) as CanvasRegionalGuidanceLayerContract),
+ isHidden: true,
+ });
+
+ it('does not draw a hidden overlay layer', () => {
+ const backend = createTestStubRasterBackend();
+ const caches = createLayerCacheStore(backend);
+ caches.getOrCreate('m', 10, 10);
+ const rasterCache = caches.getOrCreate('r', 10, 10);
+ const target = backend.createSurface(200, 200);
+
+ compositeDocument(target, makeDoc([hiddenMask('m'), rasterLayer('r')]), caches, VIEW, { backend });
+
+ const drawn = target.callLog.filter((e) => e.op === 'drawImage').map((e) => e.args[0]);
+ expect(drawn).toEqual([rasterCache.surface.canvas]);
+ });
+
+ it('draws it again once unhidden — hiding never touches its pixels', () => {
+ const backend = createTestStubRasterBackend();
+ const caches = createLayerCacheStore(backend);
+ const maskCache = caches.getOrCreate('m', 10, 10);
+ const target = backend.createSurface(200, 200);
+
+ compositeDocument(target, makeDoc([maskLayer('m')]), caches, VIEW, { backend });
+
+ const drawn = target.callLog.filter((e) => e.op === 'drawImage').map((e) => e.args[0]);
+ expect(drawn.length).toBeGreaterThan(0);
+ expect(maskCache.surface.width).toBe(10);
+ });
+
+ it('still draws a hidden layer while it is the isolated operation target', () => {
+ // An operation preview acts ON that layer; suppressing it would leave the
+ // user editing something they cannot see.
+ const backend = createTestStubRasterBackend();
+ const caches = createLayerCacheStore(backend);
+ caches.getOrCreate('m', 10, 10);
+ const target = backend.createSurface(200, 200);
+
+ compositeDocument(target, makeDoc([hiddenMask('m')]), caches, VIEW, { backend, onlyLayerId: 'm' });
+
+ expect(target.callLog.some((e) => e.op === 'drawImage')).toBe(true);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/compositor.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/compositor.ts
index d378fd9e67..81a3c52bc7 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/compositor.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/compositor.ts
@@ -21,7 +21,7 @@ import type {
import type { CanvasDiagnostics } from '@workbench/canvas-engine/diagnostics';
import type { Mat2d, Rect, Vec2 } from '@workbench/canvas-engine/types';
-import { LAYER_GROUP_COUNT, layerGroupRank } from '@workbench/canvas-engine/document/sources';
+import { isLayerHidden, LAYER_GROUP_COUNT, layerGroupRank } from '@workbench/canvas-engine/document/sources';
import { fromTRS, multiply } from '@workbench/canvas-engine/math/mat2d';
import { intersect, transformBounds } from '@workbench/canvas-engine/math/rect';
@@ -452,7 +452,9 @@ export const compositeDocument = (
const layer = doc.layers[i];
if (
!layer ||
- (!layer.isEnabled && layer.id !== opts.onlyLayerId) ||
+ // Disabled OR hidden: neither draws. `onlyLayerId` (an isolated
+ // operation preview) overrides both — the user is acting on that layer.
+ ((!layer.isEnabled || isLayerHidden(layer)) && layer.id !== opts.onlyLayerId) ||
layer.id === opts.skipLayerId ||
(opts.onlyLayerId && layer.id !== opts.onlyLayerId) ||
layerGroupRank(layer) !== rank
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/frameDemand.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/frameDemand.ts
index 85f9757aef..09a4be964e 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/frameDemand.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/frameDemand.ts
@@ -1,7 +1,7 @@
import type { CanvasDocumentContractV2 } from '@workbench/canvas-engine/contracts';
import type { Rect } from '@workbench/canvas-engine/types';
-import { getSourceContentRect, renderableSourceOf } from '@workbench/canvas-engine/document/sources';
+import { getSourceContentRect, isLayerHidden, renderableSourceOf } from '@workbench/canvas-engine/document/sources';
import { fromTRS } from '@workbench/canvas-engine/math/mat2d';
import { intersect, isEmpty, transformBounds, union } from '@workbench/canvas-engine/math/rect';
@@ -26,7 +26,14 @@ export const calculateActiveFrameLayerIds = ({
}: FrameDemandInput): Set<string> => {
const active = new Set<string>();
for (const layer of document.layers) {
- if (!layer.isEnabled || !renderableSourceOf(layer) || (isolationLayerIds && !isolationLayerIds.has(layer.id))) {
+ // A hidden layer draws nothing this frame, so it needs no cache allocated —
+ // but an isolated operation preview still targets it.
+ if (
+ !layer.isEnabled ||
+ (isLayerHidden(layer) && !isolationLayerIds?.has(layer.id)) ||
+ !renderableSourceOf(layer) ||
+ (isolationLayerIds && !isolationLayerIds.has(layer.id))
+ ) {
continue;
}
const sourceRect = getSourceContentRect(layer, document);
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-operations/generationCompositePlan.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-operations/generationCompositePlan.test.ts
index fd137e2da3..1c2fcc5b55 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-operations/generationCompositePlan.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-operations/generationCompositePlan.test.ts
@@ -221,6 +221,7 @@ const inpaintMask = (
noiseLevel: number;
denoiseLimit: number;
isEnabled: boolean;
+ isHidden: boolean;
offset: { x: number; y: number };
}> = {}
): CanvasLayerContract => ({
@@ -228,6 +229,7 @@ const inpaintMask = (
denoiseLimit: overrides.denoiseLimit,
id,
isEnabled: overrides.isEnabled ?? true,
+ isHidden: overrides.isHidden,
isLocked: false,
mask: {
bitmap: 'bitmap' in overrides ? overrides.bitmap! : imageRef(`${id}-bmp`, 100, 80),
@@ -268,6 +270,12 @@ describe('planComposites — inpaint-mask entries', () => {
expect(entry!.maskLayers!.map((l) => l.id)).toEqual(['on']);
});
+ it('INCLUDES hidden masks — hiding is display-only and must not change the image', () => {
+ const doc = makeDoc([inpaintMask('shown'), inpaintMask('hidden', { isHidden: true })]);
+ const entry = entryOfKind(doc, 'inpaint-mask');
+ expect(entry!.maskLayers!.map((l) => l.id)).toEqual(['shown', 'hidden']);
+ });
+
it('resolves an undefined denoiseLimit to the legacy default (1.0)', () => {
const entry = entryOfKind(makeDoc([inpaintMask('m1')]), 'inpaint-mask');
expect(entry!.maskLayers![0]!.attributeValue).toBe(1);
@@ -333,6 +341,7 @@ const controlLayer = (
overrides: Partial<{
source: CanvasControlLayerContract['source'];
isEnabled: boolean;
+ isHidden: boolean;
withTransparencyEffect: boolean;
opacity: number;
blendMode: CanvasLayerContract['blendMode'];
@@ -342,6 +351,7 @@ const controlLayer = (
blendMode: overrides.blendMode ?? 'normal',
id,
isEnabled: overrides.isEnabled ?? true,
+ isHidden: overrides.isHidden,
isLocked: false,
name: id,
opacity: overrides.opacity ?? 1,
@@ -351,6 +361,15 @@ const controlLayer = (
withTransparencyEffect: overrides.withTransparencyEffect ?? false,
});
+describe('planComposites — hidden layers still generate', () => {
+ it('keeps a hidden control layer in the plan', () => {
+ const shown = planControlComposites(makeDoc([controlLayer('c')]), BBOX);
+ const hidden = planControlComposites(makeDoc([controlLayer('c', { isHidden: true })]), BBOX);
+ expect(hidden.length).toBe(shown.length);
+ expect(hidden.length).toBeGreaterThan(0);
+ });
+});
+
describe('planComposites — control-layer exclusion', () => {
it('never includes control layers in the base-raster entry', () => {
const plan = planComposites(makeDoc([rasterLayer('r'), controlLayer('c')]), BBOX);
diff --git a/invokeai/frontend/webv2/src/workbench/canvasMigration.ts b/invokeai/frontend/webv2/src/workbench/canvasMigration.ts
index 69cf6a378a..8fbe2dbca4 100644
--- a/invokeai/frontend/webv2/src/workbench/canvasMigration.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvasMigration.ts
@@ -177,12 +177,16 @@ const zCanvasLayer = z.discriminatedUnion('type', [
zLayerBase.extend({
adapter: zControlAdapter,
filter: zFilter.optional(),
+ // Display-only visibility; absent ⇒ not hidden, so older documents load
+ // unchanged. Only the three overlay types carry it — see `contracts.ts`.
+ isHidden: z.boolean().optional(),
source: zLayerSource,
type: z.literal('control'),
withTransparencyEffect: z.boolean(),
}),
zLayerBase.extend({
autoNegative: z.boolean(),
+ isHidden: z.boolean().optional(),
mask: zMask,
negativePrompt: z.string().nullable(),
positivePrompt: z.string().nullable(),
@@ -191,6 +195,7 @@ const zCanvasLayer = z.discriminatedUnion('type', [
}),
zLayerBase.extend({
denoiseLimit: zFiniteNumber.optional(),
+ isHidden: z.boolean().optional(),
mask: zMask,
noiseLevel: zFiniteNumber.optional(),
type: z.literal('inpaint_mask'),
diff --git a/invokeai/frontend/webv2/src/workbench/canvasProjectMutations.ts b/invokeai/frontend/webv2/src/workbench/canvasProjectMutations.ts
index d111849a9d..5f56a4c901 100644
--- a/invokeai/frontend/webv2/src/workbench/canvasProjectMutations.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvasProjectMutations.ts
@@ -14,6 +14,8 @@ import type {
} from '@workbench/canvas-engine/api';
import type { ProjectEvent, Project } from '@workbench/projectContracts';
+import { isHideableLayer } from '@workbench/canvas-engine/api';
+
import { normalizeCanvasDocumentControlAdapters } from './canvasMigration';
import {
getCanvasStagingCandidateFingerprint,
@@ -84,6 +86,7 @@ export type CanvasProjectMutation =
| { type: 'updateCanvasLayer'; id: string; patch: CanvasLayerBasePatch }
| { type: 'replaceCanvasLayer'; layerId: string; layer: CanvasLayerContract }
| { type: 'setCanvasLayersEnabled'; updates: readonly { id: string; isEnabled: boolean }[] }
+ | { type: 'setCanvasLayersHidden'; updates: readonly { id: string; isHidden: boolean }[] }
| { type: 'updateCanvasLayerSource'; id: string; source: CanvasLayerSourceContract }
| { type: 'updateCanvasLayerConfig'; id: string; config: CanvasLayerConfigPatch }
| { type: 'convertCanvasLayer'; id: string; targetType: CanvasLayerContract['type']; layer: CanvasLayerContract }
@@ -123,6 +126,7 @@ const CANVAS_PROJECT_MUTATION_TYPES: ReadonlySet<string> = new Set<CanvasProject
'saveCanvasSnapshot',
'setCanvasBbox',
'setCanvasLayersEnabled',
+ 'setCanvasLayersHidden',
'setCanvasSelectedLayer',
'setCanvasStagingAutoSwitch',
'setStagedImageIndex',
@@ -210,6 +214,28 @@ const setCanvasLayersEnabled = (
return changed ? { ...document, layers } : document;
};
+/**
+ * Bulk display-visibility update. Layers that cannot be hidden (raster) are
+ * skipped rather than silently gaining a meaningless field: for them visibility
+ * and participation are the same fact, which `isEnabled` already carries.
+ */
+const setCanvasLayersHidden = (
+ document: CanvasDocumentContractV2,
+ updates: readonly { id: string; isHidden: boolean }[]
+): CanvasDocumentContractV2 => {
+ const targets = new Map(updates.map((update) => [update.id, update.isHidden]));
+ let changed = false;
+ const layers = document.layers.map((layer) => {
+ const isHidden = targets.get(layer.id);
+ if (isHidden === undefined || !isHideableLayer(layer) || isHidden === (layer.isHidden === true)) {
+ return layer;
+ }
+ changed = true;
+ return { ...layer, isHidden };
+ });
+ return changed ? { ...document, layers } : document;
+};
+
const applyLayerStackMutation = (
document: CanvasDocumentContractV2,
mutation: Extract<CanvasProjectMutation, { type: 'applyCanvasLayerStackMutation' }>
@@ -591,6 +617,8 @@ export const applyCanvasProjectMutation = (project: Project, mutation: CanvasPro
);
case 'setCanvasLayersEnabled':
return updateCanvasDocument(project, (document) => setCanvasLayersEnabled(document, mutation.updates));
+ case 'setCanvasLayersHidden':
+ return updateCanvasDocument(project, (document) => setCanvasLayersHidden(document, mutation.updates));
case 'updateCanvasLayerSource':
return updateCanvasDocument(project, (document) =>
mapCanvasLayer(document, mutation.id, (layer) =>
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasWidgetView.tsx
index 4abe925d3d..22f59e5705 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasWidgetView.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasWidgetView.tsx
@@ -4,6 +4,7 @@ import type { MouseEvent as ReactMouseEvent } from 'react';
import { Box } from '@chakra-ui/react';
import { useDndMonitor, type DragEndEvent } from '@dnd-kit/core';
import { useQueueItemProgressImage } from '@features/queue/react';
+import { isHideableLayer, isLayerHidden } from '@workbench/canvas-engine/api';
import { getCanvasImportNotice } from '@workbench/canvas-operations/api';
import {
createLayerId,
@@ -432,6 +433,24 @@ export const CanvasWidgetView = ({ runtime }: WidgetViewProps) => {
copySelection(commandId === 'canvas.cutSelection');
} else if (commandId === 'canvas.pasteImage') {
pasteFromClipboard();
+ } else if (commandId === 'canvas.toggleNonRasterLayers') {
+ // Hide, never disable: this is the "get the overlays out of my way"
+ // shortcut, and it must leave the generated image untouched.
+ const hideable = layers.filter(isHideableLayer);
+ if (engine && hideable.length > 0) {
+ const nextHidden = hideable.every((layer) => !isLayerHidden(layer));
+ engine.layers.commitStructural(
+ t('widgets.canvas.commands.toggleNonRasterLayers'),
+ {
+ type: 'setCanvasLayersHidden',
+ updates: hideable.map((layer) => ({ id: layer.id, isHidden: nextHidden })),
+ },
+ {
+ type: 'setCanvasLayersHidden',
+ updates: hideable.map((layer) => ({ id: layer.id, isHidden: isLayerHidden(layer) })),
+ }
+ );
+ }
} else if (commandId === 'canvas.resetSelected') {
if (engine && selectedLayer) {
engine.layers.clearMask(selectedLayer.id);
@@ -544,6 +563,7 @@ export const CanvasWidgetView = ({ runtime }: WidgetViewProps) => {
['canvas.tool.eraser', t('widgets.canvas.commands.selectEraserTool'), ['e']],
['canvas.tool.lasso', t('widgets.canvas.commands.selectLassoTool'), ['l']],
['canvas.tool.marquee', t('widgets.canvas.commands.selectMarqueeTool'), ['u']],
+ ['canvas.toggleNonRasterLayers', t('widgets.canvas.commands.toggleNonRasterLayers'), ['shift+h']],
['canvas.copySelection', t('widgets.canvas.commands.copySelection'), ['mod+c']],
['canvas.cutSelection', t('widgets.canvas.commands.cutSelection'), ['mod+x']],
['canvas.pasteImage', t('widgets.canvas.commands.pasteImage'), ['mod+v']],
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerGroupSection.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerGroupSection.tsx
index eb4435900d..4d520e682c 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerGroupSection.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerGroupSection.tsx
@@ -21,7 +21,14 @@ import type { LayerGroupKey } from './layerGroups';
import { groupAddItemId } from './addLayerMenu';
import { LAYER_KEYBOARD_SENSOR_OPTIONS } from './layerDndConfig';
-import { canExportRasterPsd, getGroupActions, isGroupAllVisible, planGroupVisibilityToggle } from './layerGroupActions';
+import {
+ canExportRasterPsd,
+ getGroupActions,
+ groupVisibilityAxis,
+ isGroupAllVisible,
+ planGroupHiddenToggle,
+ planGroupVisibilityToggle,
+} from './layerGroupActions';
import { reorderWithinGroup } from './layerGroups';
import { LayerListItem, type LayerListItemEngine } from './LayerListItem';
import { applyStructural } from './layerOps';
@@ -201,7 +208,7 @@ const GroupActions = ({
const { t } = useTranslation();
const addLayer = useAddLayer();
const projectName = useActiveProjectName();
- const allVisible = isGroupAllVisible(groupLayers);
+ const allVisible = isGroupAllVisible(groupLayers, groupVisibilityAxis(groupKey));
// Enablement and execution share the same contributor selector and the
// engine's live-content predicate, so empty paint layers do not enable an op.
const canMerge =
@@ -214,6 +221,23 @@ const GroupActions = ({
const handleNew = useCallback(() => addLayer(groupAddItemId(groupKey)), [addLayer, groupKey]);
const handleToggleVisibility = useCallback(() => {
+ // Overlay groups toggle the DISPLAY axis — "get these out of my way" must
+ // not change the generated image. The raster group has no display axis, so
+ // it keeps toggling enablement.
+ if (groupVisibilityAxis(groupKey) === 'hidden') {
+ const { forward, inverse } = planGroupHiddenToggle(groupLayers);
+ if (forward.length === 0) {
+ return;
+ }
+ applyStructural(
+ engine,
+ dispatch,
+ t('widgets.layers.groupActions.toggleHidden'),
+ { type: 'setCanvasLayersHidden', updates: forward },
+ { type: 'setCanvasLayersHidden', updates: inverse }
+ );
+ return;
+ }
const { forward, inverse } = planGroupVisibilityToggle(groupLayers);
applyStructural(
engine,
@@ -222,7 +246,7 @@ const GroupActions = ({
{ type: 'setCanvasLayersEnabled', updates: forward },
{ type: 'setCanvasLayersEnabled', updates: inverse }
);
- }, [dispatch, engine, groupLayers, t]);
+ }, [dispatch, engine, groupKey, groupLayers, t]);
const handleMergeVisible = useCallback(() => {
if (!engine) {
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerListItem.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerListItem.tsx
index 6d43ee0930..da0fb99412 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerListItem.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerListItem.tsx
@@ -7,7 +7,8 @@ import { Badge, Box, HStack, Input, Stack, Text } from '@chakra-ui/react';
import { useSortable } from '@dnd-kit/sortable';
import { CSS } from '@dnd-kit/utilities';
import { IconButton, Row, ToggleDot } from '@platform/ui';
-import { LockIcon, LockOpenIcon } from 'lucide-react';
+import { isHideableLayer, isLayerHidden } from '@workbench/canvas-engine/api';
+import { EyeIcon, EyeOffIcon, LockIcon, LockOpenIcon } from 'lucide-react';
import { useCallback, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
@@ -115,6 +116,27 @@ export const LayerListItem = ({
[layer.isEnabled, patchBase, t]
);
+ /**
+ * Hide is a DISPLAY-only axis, orthogonal to enabled: a hidden control map or
+ * mask still conditions generation exactly as it would if visible. Only the
+ * three overlay types have it — for a raster layer, visibility and
+ * participation are the same fact.
+ */
+ const handleToggleHidden = useCallback(
+ (event: { stopPropagation: () => void }) => {
+ event.stopPropagation();
+ const isHidden = !isLayerHidden(layer);
+ applyStructural(
+ engine,
+ dispatch,
+ t('widgets.layers.actions.toggleHidden'),
+ { type: 'setCanvasLayersHidden', updates: [{ id: layer.id, isHidden }] },
+ { type: 'setCanvasLayersHidden', updates: [{ id: layer.id, isHidden: !isHidden }] }
+ );
+ },
+ [dispatch, engine, layer, t]
+ );
+
const handleToggleLock = useCallback(
(event: { stopPropagation: () => void }) => {
event.stopPropagation();
@@ -209,6 +231,20 @@ export const LayerListItem = ({
<ControlLayerWarningIcon layer={layer} />
</HStack>
</Stack>
+ {isHideableLayer(layer) ? (
+ <IconButton
+ aria-label={t('widgets.layers.actions.toggleHidden')}
+ aria-pressed={!isLayerHidden(layer)}
+ color={isLayerHidden(layer) ? 'fg.subtle' : 'fg'}
+ disabled={!interaction.canToggleVisibility}
+ size="2xs"
+ variant="ghost"
+ onClick={handleToggleHidden}
+ onPointerDown={stopPropagation}
+ >
+ {isLayerHidden(layer) ? <EyeOffIcon /> : <EyeIcon />}
+ </IconButton>
+ ) : null}
<Box flexShrink="0" onClick={stopPropagation} onPointerDown={stopPropagation}>
<ToggleDot
checked={layer.isEnabled}
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerGroupActions.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerGroupActions.test.ts
index 9ff001c918..cf15f1fa50 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerGroupActions.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerGroupActions.test.ts
@@ -1,12 +1,20 @@
import type {
CanvasInpaintMaskLayerContract,
+ CanvasLayerContract,
CanvasLayerSourceContract,
CanvasRasterLayerContractV2,
} from '@workbench/canvas-engine/contracts';
import { describe, expect, it } from 'vitest';
-import { canExportRasterPsd, getGroupActions, isGroupAllVisible, planGroupVisibilityToggle } from './layerGroupActions';
+import {
+ canExportRasterPsd,
+ getGroupActions,
+ groupVisibilityAxis,
+ isGroupAllVisible,
+ planGroupHiddenToggle,
+ planGroupVisibilityToggle,
+} from './layerGroupActions';
const raster = (source: CanvasLayerSourceContract, id = 'r'): CanvasRasterLayerContractV2 => ({
blendMode: 'normal',
@@ -119,3 +127,79 @@ describe('planGroupVisibilityToggle', () => {
// Merge-visible contributor selection is tested where it lives:
// `canvas-engine/document/mergeVisible.test.ts` (the selector the engine op runs).
+
+describe('planGroupHiddenToggle', () => {
+ const control = (id: string, isHidden?: boolean): CanvasLayerContract => ({
+ adapter: { beginEndStepPct: [0, 1], controlMode: 'balanced', kind: 'controlnet', model: null, weight: 1 },
+ blendMode: 'normal',
+ id,
+ isEnabled: true,
+ isHidden,
+ isLocked: false,
+ name: id,
+ opacity: 1,
+ source: { image: { height: 10, imageName: id, width: 10 }, type: 'image' },
+ transform: { rotation: 0, scaleX: 1, scaleY: 1, x: 0, y: 0 },
+ type: 'control',
+ withTransparencyEffect: false,
+ });
+
+ it('hides every layer when all are currently shown', () => {
+ const plan = planGroupHiddenToggle([control('a'), control('b')]);
+ expect(plan.nextVisible).toBe(false);
+ expect(plan.forward).toEqual([
+ { id: 'a', isHidden: true },
+ { id: 'b', isHidden: true },
+ ]);
+ });
+
+ it('shows every layer when any is currently hidden', () => {
+ const plan = planGroupHiddenToggle([control('a', true), control('b')]);
+ expect(plan.nextVisible).toBe(true);
+ expect(plan.forward).toEqual([
+ { id: 'a', isHidden: false },
+ { id: 'b', isHidden: false },
+ ]);
+ });
+
+ it('restores each layer prior state verbatim, so undo is one entry', () => {
+ const plan = planGroupHiddenToggle([control('a', true), control('b')]);
+ expect(plan.inverse).toEqual([
+ { id: 'a', isHidden: true },
+ { id: 'b', isHidden: false },
+ ]);
+ });
+
+ it('never touches enablement — hiding must not change the generated image', () => {
+ const plan = planGroupHiddenToggle([control('a')]);
+ expect(JSON.stringify(plan)).not.toContain('isEnabled');
+ });
+
+ it('skips layers that cannot be hidden', () => {
+ const raster: CanvasLayerContract = {
+ blendMode: 'normal',
+ id: 'r',
+ isEnabled: true,
+ isLocked: false,
+ name: 'r',
+ opacity: 1,
+ source: { bitmap: null, offset: { x: 0, y: 0 }, type: 'paint' },
+ transform: { rotation: 0, scaleX: 1, scaleY: 1, x: 0, y: 0 },
+ type: 'raster',
+ };
+ const plan = planGroupHiddenToggle([raster, control('a')]);
+ expect(plan.forward.map((update) => update.id)).toEqual(['a']);
+ });
+});
+
+describe('groupVisibilityAxis', () => {
+ it('drives display visibility for the overlay groups', () => {
+ expect(groupVisibilityAxis('control')).toBe('hidden');
+ expect(groupVisibilityAxis('regional_guidance')).toBe('hidden');
+ expect(groupVisibilityAxis('inpaint_mask')).toBe('hidden');
+ });
+
+ it('drives enablement for the raster group, which has no display axis', () => {
+ expect(groupVisibilityAxis('raster')).toBe('enabled');
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerGroupActions.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerGroupActions.ts
index 6c91dbd338..a1717c5aeb 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerGroupActions.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerGroupActions.ts
@@ -1,5 +1,7 @@
import type { CanvasLayerContract } from '@workbench/canvas-engine/api';
+import { isHideableLayer, isLayerHidden } from '@workbench/canvas-engine/api';
+
import type { LayerGroupKey } from './layerGroups';
/** A group-header action id. Extend this + `getGroupActions` to add a new action. */
@@ -49,21 +51,45 @@ const hasExportableRasterContent = (layer: CanvasLayerContract): boolean => {
export const canExportRasterPsd = (layers: readonly CanvasLayerContract[]): boolean =>
layers.some(hasExportableRasterContent);
-/** A single layer's target visibility, for the bulk `setCanvasLayersEnabled` action. */
+/** A single layer's target enablement, for the bulk `setCanvasLayersEnabled` action. */
export interface LayerVisibilityUpdate {
id: string;
isEnabled: boolean;
}
-/** True when every layer in the group is currently visible (enabled). Empty ⇒ true. */
-export const isGroupAllVisible = (groupLayers: readonly CanvasLayerContract[]): boolean =>
- groupLayers.every((layer) => layer.isEnabled);
+/** A single layer's target display visibility, for the bulk `setCanvasLayersHidden` action. */
+export interface LayerHiddenUpdate {
+ id: string;
+ isHidden: boolean;
+}
+
+/**
+ * Which axis a group's show/hide-all button drives.
+ *
+ * The three overlay groups drive the DISPLAY axis: their layers are drawn to
+ * show you where an effect applies, so getting them out of the way must not
+ * change the image. The raster group has no display axis — the raster stack IS
+ * the generation input, so hiding a raster layer and disabling it are the same
+ * act — and drives enablement.
+ */
+export const groupVisibilityAxis = (groupKey: LayerGroupKey): 'enabled' | 'hidden' =>
+ groupKey === 'raster' ? 'enabled' : 'hidden';
+
+/** True when every layer in the group is currently visible on the group's own axis. Empty ⇒ true. */
+export const isGroupAllVisible = (
+ groupLayers: readonly CanvasLayerContract[],
+ axis: 'enabled' | 'hidden' = 'enabled'
+): boolean =>
+ axis === 'hidden'
+ ? groupLayers.every((layer) => !isLayerHidden(layer))
+ : groupLayers.every((layer) => layer.isEnabled);
/**
- * Plans a group hide/show-all toggle as ONE reversible bulk action: if every layer
- * is visible, hide them all; otherwise show them all (legacy `CanvasEntityType`
- * toggle semantics). `forward` sets the shared target; `inverse` restores each
- * layer's prior visibility verbatim, so undo is a single history entry.
+ * Plans a group show/hide-all toggle as ONE reversible bulk action: if every
+ * layer is currently visible, hide them all; otherwise show them all (legacy
+ * `CanvasEntityType` toggle semantics). `forward` sets the shared target;
+ * `inverse` restores each layer's prior state verbatim, so undo is a single
+ * history entry.
*/
export const planGroupVisibilityToggle = (
groupLayers: readonly CanvasLayerContract[]
@@ -76,5 +102,18 @@ export const planGroupVisibilityToggle = (
};
};
+/** The display-axis counterpart of {@link planGroupVisibilityToggle}. */
+export const planGroupHiddenToggle = (
+ groupLayers: readonly CanvasLayerContract[]
+): { forward: LayerHiddenUpdate[]; inverse: LayerHiddenUpdate[]; nextVisible: boolean } => {
+ const hideable = groupLayers.filter(isHideableLayer);
+ const nextVisible = !isGroupAllVisible(hideable, 'hidden');
+ return {
+ forward: hideable.map((layer) => ({ id: layer.id, isHidden: !nextVisible })),
+ inverse: hideable.map((layer) => ({ id: layer.id, isHidden: isLayerHidden(layer) })),
+ nextVisible,
+ };
+};
+
// Merge-visible contributor selection lives in the engine's document layer
// Canvas execution uses the same legacy-parity eligibility rules.
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
index ef4368af6c..8b05a821a9 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
@@ -50,6 +50,7 @@ const CANVAS_MUTATION_TYPES = new Set<CanvasProjectMutation['type']>([
'saveCanvasSnapshot',
'setCanvasBbox',
'setCanvasLayersEnabled',
+ 'setCanvasLayersHidden',
'setCanvasSelectedLayer',
'setCanvasStagingAutoSwitch',
'setStagedImageIndex',
@@ -2347,6 +2348,40 @@ describe('workbenchReducer canvas v2 layer reducers', () => {
expect(getCanvas(state).document.selectedLayerId).toBeNull();
});
+ it('hides overlay layers without disabling them, so generation is untouched', () => {
+ let state = withCanvasLayers(createInitialWorkbenchState(), [createInpaintMaskLayer('m'), createRasterLayer('r')]);
+
+ state = workbenchReducer(state, {
+ type: 'setCanvasLayersHidden',
+ updates: [
+ { id: 'm', isHidden: true },
+ { id: 'r', isHidden: true },
+ ],
+ });
+
+ const layers = getCanvas(state).document.layers;
+ const mask = layers.find((layer) => layer.id === 'm')!;
+ const raster = layers.find((layer) => layer.id === 'r')!;
+
+ expect(mask).toMatchObject({ isEnabled: true, isHidden: true });
+ // Raster layers have no display axis; the update is skipped rather than
+ // silently giving them a meaningless field.
+ expect(raster).not.toHaveProperty('isHidden');
+ expect(raster.isEnabled).toBe(true);
+ });
+
+ it('leaves the document untouched when a hide update changes nothing', () => {
+ const state = withCanvasLayers(createInitialWorkbenchState(), [createInpaintMaskLayer('m')]);
+ const before = getCanvas(state).document;
+
+ const next = workbenchReducer(state, {
+ type: 'setCanvasLayersHidden',
+ updates: [{ id: 'm', isHidden: false }],
+ });
+
+ expect(getCanvas(next).document).toBe(before);
+ });
+
it('sets many layers visibility in one bulk action, preserving unlisted layers by identity', () => {
let state = withCanvasLayers(createInitialWorkbenchState(), [
createRasterLayer('a'),