summaryrefslogtreecommitdiff
path: root/apps/web/src/masks/custom-path.ts
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2026-04-29 18:31:24 +0200
committerMaze Winther <mazewinther@gmail.com>2026-05-02 03:27:23 +0200
commit97f8d1968f186028e41f83b04c0897130e6c69f4 (patch)
treecb951cbfcfa004f53ab3d7a06021fc43942ac04b /apps/web/src/masks/custom-path.ts
parentae1292a14bf5c29544a5f7a49e65b994410f87de (diff)
downloadopencut-97f8d1968f186028e41f83b04c0897130e6c69f4.tar.gz
refactor: type mask handle identifiers
Made-with: Cursor
Diffstat (limited to 'apps/web/src/masks/custom-path.ts')
-rw-r--r--apps/web/src/masks/custom-path.ts55
1 files changed, 14 insertions, 41 deletions
diff --git a/apps/web/src/masks/custom-path.ts b/apps/web/src/masks/custom-path.ts
index b35702f6..363bb3bd 100644
--- a/apps/web/src/masks/custom-path.ts
+++ b/apps/web/src/masks/custom-path.ts
@@ -10,56 +10,29 @@ export interface CustomMaskPathPoint {
outY: number;
}
-export type CustomMaskHandlePart = "anchor" | "in" | "out";
-
function isCustomMaskPathPoint(value: unknown): value is CustomMaskPathPoint {
if (!value || typeof value !== "object") {
return false;
}
- const candidate = value as Record<string, unknown>;
return (
- typeof candidate.id === "string" &&
- typeof candidate.x === "number" &&
- typeof candidate.y === "number" &&
- typeof candidate.inX === "number" &&
- typeof candidate.inY === "number" &&
- typeof candidate.outX === "number" &&
- typeof candidate.outY === "number"
+ "id" in value &&
+ typeof value.id === "string" &&
+ "x" in value &&
+ typeof value.x === "number" &&
+ "y" in value &&
+ typeof value.y === "number" &&
+ "inX" in value &&
+ typeof value.inX === "number" &&
+ "inY" in value &&
+ typeof value.inY === "number" &&
+ "outX" in value &&
+ typeof value.outX === "number" &&
+ "outY" in value &&
+ typeof value.outY === "number"
);
}
-export function parseCustomMaskHandleId({
- handleId,
-}: {
- handleId: string;
-}): { pointId: string; part: CustomMaskHandlePart } | null {
- const match = /^point:(.+):(anchor|in|out)$/.exec(handleId);
- if (!match) {
- return null;
- }
-
- return {
- pointId: match[1],
- part: match[2] as CustomMaskHandlePart,
- };
-}
-
-export function parseCustomMaskSegmentHandleId({
- handleId,
-}: {
- handleId: string;
-}): { segmentIndex: number } | null {
- const match = /^segment:(\d+)$/.exec(handleId);
- if (!match) {
- return null;
- }
-
- return {
- segmentIndex: Number.parseInt(match[1], 10),
- };
-}
-
export function parseCustomMaskPath({
path,
}: {