summaryrefslogtreecommitdiff
path: root/apps/web/src/lib/commands/timeline/element/masks/delete-custom-mask-points.ts
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2026-04-20 11:31:17 +0200
committerMaze Winther <mazewinther@gmail.com>2026-04-20 11:31:17 +0200
commit3e89d2998588f8e35c524e523ba2ee853f0f6475 (patch)
tree57221f96c1259b3b07e3ddf8c1adefc502b9d8eb /apps/web/src/lib/commands/timeline/element/masks/delete-custom-mask-points.ts
parent729d10592f4e802f91c555c309ff3ba4b119f843 (diff)
downloadopencut-3e89d2998588f8e35c524e523ba2ee853f0f6475.tar.gz
refactor: restructure files to their domains, new preview overlay system, and dep graph
Diffstat (limited to 'apps/web/src/lib/commands/timeline/element/masks/delete-custom-mask-points.ts')
-rw-r--r--apps/web/src/lib/commands/timeline/element/masks/delete-custom-mask-points.ts131
1 files changed, 0 insertions, 131 deletions
diff --git a/apps/web/src/lib/commands/timeline/element/masks/delete-custom-mask-points.ts b/apps/web/src/lib/commands/timeline/element/masks/delete-custom-mask-points.ts
deleted file mode 100644
index 346eb8d9..00000000
--- a/apps/web/src/lib/commands/timeline/element/masks/delete-custom-mask-points.ts
+++ /dev/null
@@ -1,131 +0,0 @@
-import { EditorCore } from "@/core";
-import { Command, type CommandResult } from "@/lib/commands/base-command";
-import {
- getCustomMaskClosedStateAfterPointRemoval,
- removeCustomMaskPoints,
-} from "@/lib/masks/custom-path";
-import type { CustomMask } from "@/lib/masks/types";
-import { isMaskableElement, updateElementInSceneTracks } from "@/lib/timeline";
-import type { MaskableElement, SceneTracks } from "@/lib/timeline";
-
-function deletePointsFromCustomMask({
- mask,
- pointIds,
-}: {
- mask: CustomMask;
- pointIds: string[];
-}): CustomMask {
- const points = mask.params.path;
- const nextPoints = removeCustomMaskPoints({ points, pointIds });
- if (nextPoints.length === points.length) {
- return mask;
- }
-
- return {
- ...mask,
- params: {
- ...mask.params,
- path: nextPoints,
- closed: getCustomMaskClosedStateAfterPointRemoval({
- wasClosed: mask.params.closed,
- remainingPointCount: nextPoints.length,
- }),
- },
- };
-}
-
-function deletePointsFromElementMask({
- element,
- maskId,
- pointIds,
-}: {
- element: MaskableElement;
- maskId: string;
- pointIds: string[];
-}): { element: MaskableElement; didDeletePoints: boolean } {
- const currentMasks = element.masks ?? [];
- let didDeletePoints = false;
- const nextMasks = currentMasks.map((mask) => {
- if (mask.id !== maskId || mask.type !== "custom") {
- return mask;
- }
-
- const nextMask = deletePointsFromCustomMask({
- mask,
- pointIds,
- });
- didDeletePoints ||= nextMask !== mask;
- return nextMask;
- });
-
- return {
- element: didDeletePoints ? { ...element, masks: nextMasks } : element,
- didDeletePoints,
- };
-}
-
-export class DeleteCustomMaskPointsCommand extends Command {
- private savedState: SceneTracks | null = null;
- private readonly trackId: string;
- private readonly elementId: string;
- private readonly maskId: string;
- private readonly pointIds: string[];
-
- constructor({
- trackId,
- elementId,
- maskId,
- pointIds,
- }: {
- trackId: string;
- elementId: string;
- maskId: string;
- pointIds: string[];
- }) {
- super();
- this.trackId = trackId;
- this.elementId = elementId;
- this.maskId = maskId;
- this.pointIds = pointIds;
- }
-
- execute(): CommandResult | undefined {
- const editor = EditorCore.getInstance();
- this.savedState = editor.scenes.getActiveScene().tracks;
-
- let didDeletePoints = false;
- const updatedTracks = updateElementInSceneTracks({
- tracks: this.savedState,
- trackId: this.trackId,
- elementId: this.elementId,
- elementPredicate: isMaskableElement,
- update: (element) => {
- const result = deletePointsFromElementMask({
- element: element as MaskableElement,
- maskId: this.maskId,
- pointIds: this.pointIds,
- });
- didDeletePoints ||= result.didDeletePoints;
- return result.element;
- },
- });
-
- if (didDeletePoints) {
- editor.timeline.updateTracks(updatedTracks);
- return {
- selection: {
- selectedMaskPoints: null,
- },
- };
- }
-
- return undefined;
- }
-
- undo(): void {
- if (this.savedState) {
- const editor = EditorCore.getInstance();
- editor.timeline.updateTracks(this.savedState);
- }
- }
-}