diff options
| author | Maze Winther <mazewinther@gmail.com> | 2026-04-29 18:41:15 +0200 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2026-05-02 03:27:23 +0200 |
| commit | 79dcec8a2ec2f5cad9be95e5b52fbfa752fb6ac4 (patch) | |
| tree | 99ff9393c4a550669ebac921c6a0535437a39413 /apps/web/src/masks/index.ts | |
| parent | 97f8d1968f186028e41f83b04c0897130e6c69f4 (diff) | |
| download | opencut-79dcec8a2ec2f5cad9be95e5b52fbfa752fb6ac4.tar.gz | |
refactor: split builtin and freeform masks
Made-with: Cursor
Diffstat (limited to 'apps/web/src/masks/index.ts')
| -rw-r--r-- | apps/web/src/masks/index.ts | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/apps/web/src/masks/index.ts b/apps/web/src/masks/index.ts index df7649e1..be5faef7 100644 --- a/apps/web/src/masks/index.ts +++ b/apps/web/src/masks/index.ts @@ -1,9 +1,15 @@ import type { Mask, MaskDefaultContext, MaskType } from "@/masks/types"; -import { masksRegistry } from "./registry"; +import { + BASE_MASK_PARAM_DEFINITIONS, + builtinMasksRegistry, + type RegisteredBuiltinMaskDefinition, +} from "./registry"; +import { freeformMaskDefinition } from "./freeform/definition"; import { generateUUID } from "@/utils/id"; +import { SquareIcon } from "@hugeicons/core-free-icons"; -export { masksRegistry } from "./registry"; -export { registerDefaultMasks } from "./definitions"; +export { builtinMasksRegistry } from "./registry"; +export { registerBuiltinMasks as registerDefaultMasks } from "./builtin/definitions"; type MaskWithoutId = Mask extends infer TMask ? TMask extends Mask @@ -29,11 +35,35 @@ function withMaskId({ mask, id }: { mask: MaskWithoutId; id: string }): Mask { return { ...mask, id }; case "text": return { ...mask, id }; - case "custom": + case "freeform": return { ...mask, id }; } } +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 getMaskDefinitionsForMenu() { + return [ + ...builtinMasksRegistry.getAll(), + { + ...freeformMaskDefinition, + name: "Pen tool", + params: [...freeformMaskDefinition.params, ...BASE_MASK_PARAM_DEFINITIONS], + icon: { icon: SquareIcon }, + }, + ]; +} + export function buildDefaultMaskInstance({ maskType, elementSize, @@ -41,7 +71,7 @@ export function buildDefaultMaskInstance({ maskType: MaskType; elementSize?: { width: number; height: number }; }): Mask { - const definition = masksRegistry.get(maskType); + const definition = getMaskDefinition(maskType); const context: MaskDefaultContext = { elementSize }; return withMaskId({ mask: definition.buildDefault(context), |
