diff options
| author | Maze Winther <mazewinther@gmail.com> | 2026-05-02 01:33:32 +0200 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2026-05-02 03:27:23 +0200 |
| commit | 8b8d65b5091f4158af68fbad85cc74936302b07b (patch) | |
| tree | 53c5bb4ee0ec60ed2b9d87585230014229008cea /apps/web/src/masks/index.ts | |
| parent | 23187b0b6a9f179bdb68578fc4bdaa8414b8316d (diff) | |
| download | opencut-8b8d65b5091f4158af68fbad85cc74936302b07b.tar.gz | |
refactor: collapse mask definition registry to a single keyed registry
The freeform mask was assembled on every getMaskDefinition("freeform") call,
re-spreading params and injecting a wrong SquareIcon placeholder, with a type
cast to suppress the structural mismatch. Root cause: MasksRegistry was keyed
on BuiltinMaskType, so freeform had no entry.
- Re-key MasksRegistry from BuiltinMaskType to MaskType
- Register freeform alongside builtins in registerDefaultMasks, with
PenToolAddIcon as its menu icon
- getMaskDefinition and getMaskDefinitionsForMenu become plain registry
lookups with no branching, no manual spreading, no cast
- Rename RegisteredBuiltinMaskDefinition to RegisteredMaskDefinition and
tighten computeParamUpdate return type to Partial<BaseMaskParams>
Co-authored-by: Cursor <cursoragent@cursor.com>
Diffstat (limited to 'apps/web/src/masks/index.ts')
| -rw-r--r-- | apps/web/src/masks/index.ts | 36 |
1 files changed, 7 insertions, 29 deletions
diff --git a/apps/web/src/masks/index.ts b/apps/web/src/masks/index.ts index be5faef7..994f05f2 100644 --- a/apps/web/src/masks/index.ts +++ b/apps/web/src/masks/index.ts @@ -1,15 +1,9 @@ import type { Mask, MaskDefaultContext, MaskType } from "@/masks/types"; -import { - BASE_MASK_PARAM_DEFINITIONS, - builtinMasksRegistry, - type RegisteredBuiltinMaskDefinition, -} from "./registry"; -import { freeformMaskDefinition } from "./freeform/definition"; +import { masksRegistry } from "./registry"; import { generateUUID } from "@/utils/id"; -import { SquareIcon } from "@hugeicons/core-free-icons"; -export { builtinMasksRegistry } from "./registry"; -export { registerBuiltinMasks as registerDefaultMasks } from "./builtin/definitions"; +export { masksRegistry } from "./registry"; +export { registerDefaultMasks } from "./builtin/definitions"; type MaskWithoutId = Mask extends infer TMask ? TMask extends Mask @@ -40,28 +34,12 @@ function withMaskId({ mask, id }: { mask: MaskWithoutId; id: string }): Mask { } } -export function getMaskDefinition(maskType: MaskType): RegisteredBuiltinMaskDefinition { - if (maskType === "freeform") { - return { - ...freeformMaskDefinition, - params: [...freeformMaskDefinition.params, ...BASE_MASK_PARAM_DEFINITIONS], - icon: { icon: SquareIcon }, - } as RegisteredBuiltinMaskDefinition; - } - - return builtinMasksRegistry.get(maskType); +export function getMaskDefinition(maskType: MaskType) { + return masksRegistry.get(maskType); } export function getMaskDefinitionsForMenu() { - return [ - ...builtinMasksRegistry.getAll(), - { - ...freeformMaskDefinition, - name: "Pen tool", - params: [...freeformMaskDefinition.params, ...BASE_MASK_PARAM_DEFINITIONS], - icon: { icon: SquareIcon }, - }, - ]; + return masksRegistry.getAll(); } export function buildDefaultMaskInstance({ @@ -71,7 +49,7 @@ export function buildDefaultMaskInstance({ maskType: MaskType; elementSize?: { width: number; height: number }; }): Mask { - const definition = getMaskDefinition(maskType); + const definition = masksRegistry.get(maskType); const context: MaskDefaultContext = { elementSize }; return withMaskId({ mask: definition.buildDefault(context), |
