55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
export const availableToolIds = ["select", "brush", "eraser", "chromaKey", "magicWand", "pan"] as const;
|
|
|
|
export type ToolId = (typeof availableToolIds)[number];
|
|
|
|
export type InteractionMode =
|
|
| { type: "tool"; tool: ToolId }
|
|
| { type: "temporary-pan"; previousTool: ToolId };
|
|
|
|
export type BrushSettings = {
|
|
color: string;
|
|
size: number;
|
|
hardness: number;
|
|
};
|
|
|
|
export type ChromaKeySettings = {
|
|
color: string;
|
|
tolerance: number;
|
|
softness: number;
|
|
feather: number;
|
|
choke: number;
|
|
despeckle: number;
|
|
spill: number;
|
|
};
|
|
|
|
export type MagicWandMode = "replace" | "add" | "subtract";
|
|
|
|
export type MagicWandSettings = {
|
|
tolerance: number;
|
|
feather: number;
|
|
choke: number;
|
|
despeckle: number;
|
|
contiguous: boolean;
|
|
mode: MagicWandMode;
|
|
};
|
|
|
|
export type ToolState = {
|
|
activeTool: ToolId;
|
|
interactionMode: InteractionMode;
|
|
brush: BrushSettings;
|
|
chromaKey: ChromaKeySettings;
|
|
magicWand: MagicWandSettings;
|
|
};
|
|
|
|
export const initialToolState: ToolState = {
|
|
activeTool: "select",
|
|
interactionMode: { type: "tool", tool: "select" },
|
|
brush: { color: "#111827", size: 8, hardness: 100 },
|
|
chromaKey: { color: "#00ff00", tolerance: 32, softness: 24, feather: 0, choke: 0, despeckle: 0, spill: 50 },
|
|
magicWand: { tolerance: 32, feather: 0, choke: 0, despeckle: 0, contiguous: true, mode: "replace" },
|
|
};
|
|
|
|
export function isPanInteractionMode(interactionMode: InteractionMode): boolean {
|
|
return interactionMode.type === "temporary-pan" || (interactionMode.type === "tool" && interactionMode.tool === "pan");
|
|
}
|