Files
image-studio/commands/selection.ts
syntaxbullet 4ad0bb8b2c feat: enhance layer masking functionality and brush controls
- Refactor LayersSheet component to support mask editing state and improve layer visibility handling.
- Introduce functions to collect mask layer IDs and count display layers excluding masks.
- Update BrushControls to include mask view mode options and a Done button for exiting mask editing.
- Modify brush session handling to support brush previews when editing masks.
- Implement a new BrushPreviewRenderer for rendering brush strokes with visual feedback.
- Add document geometry utilities for transforming points and resolving layer bounds.
- Ensure proper cleanup of brush preview on pointer leave and other interactions.
2026-07-03 20:49:29 +02:00

76 lines
1.9 KiB
TypeScript

import type { ArtboardId, LayerId } from "@core/id";
import type { Command } from "./command";
import { commandIds } from "./ids";
export type SelectionSetPayload = {
artboardId?: ArtboardId;
layerIds: LayerId[];
};
export type SelectionAddLayerPayload = {
layerId: LayerId;
};
export const selectionSetCommand: Command<SelectionSetPayload> = {
id: commandIds.selectionSet,
name: "Set selection",
execute({ state }, payload) {
const selection = {
artboardId: payload.artboardId,
layerIds: [...payload.layerIds],
};
return {
...state,
editor: {
...state.editor,
selection,
maskEdit: selection.layerIds.length === 1 && selection.layerIds[0] === state.editor.maskEdit?.targetLayerId ? state.editor.maskEdit : undefined,
brushPreview: undefined,
brushStrokePreview: undefined,
},
};
},
};
export const selectionClearCommand: Command = {
id: commandIds.selectionClear,
name: "Clear selection",
execute({ state }) {
return {
...state,
editor: {
...state.editor,
selection: { layerIds: [] },
maskEdit: undefined,
brushPreview: undefined,
brushStrokePreview: undefined,
},
};
},
};
export const selectionAddLayerCommand: Command<SelectionAddLayerPayload> = {
id: commandIds.selectionAddLayer,
name: "Add layer to selection",
execute({ state }, payload) {
if (state.editor.selection.layerIds.includes(payload.layerId)) return state;
return {
...state,
editor: {
...state.editor,
selection: {
...state.editor.selection,
layerIds: [...state.editor.selection.layerIds, payload.layerId],
},
maskEdit: undefined,
brushPreview: undefined,
brushStrokePreview: undefined,
},
};
},
};
export const selectionCommands = [selectionSetCommand, selectionClearCommand, selectionAddLayerCommand] satisfies Command<unknown>[];