refactor(transform): resolve target bounds

This commit is contained in:
syntaxbullet
2026-07-03 16:12:26 +02:00
parent ff5bb43382
commit a3b4a4a1b0
8 changed files with 151 additions and 39 deletions

View File

@@ -3,6 +3,7 @@ import type { Dispatch } from "@commands/dispatcher";
import type { ImageDocument } from "@core/document";
import type { Rect, Vec2D } from "@core/geometry";
import type { EditorState } from "@editor/state";
import { resolveTransformTargetBounds, selectedTransformTarget } from "@editor/transform-targets";
import type { TransformHandle } from "@editor/transform";
import type { PointerInputEvent } from "./pointer";
@@ -22,20 +23,23 @@ export function createTransformControlsInputController(options: {
if (event.pointerType !== "mouse" || (event.buttons & 1) !== 1) return false;
const editor = options.getEditor();
const artboardId = editor.selection.artboardId;
if (!artboardId || editor.tools.activeTool !== "select") return false;
if (editor.tools.activeTool !== "select") return false;
const artboard = options.getDocument().artboards.find((candidate) => candidate.id === artboardId);
if (!artboard) return false;
const document = options.getDocument();
const target = selectedTransformTarget(document, editor.selection);
if (!target) return false;
const handle = hitTestArtboardTransformHandle(event.position, artboard.bounds, editor.viewport);
const bounds = resolveTransformTargetBounds(document, target);
if (!bounds) return false;
const handle = hitTestArtboardTransformHandle(event.position, bounds, editor.viewport);
if (!handle) return false;
options.dispatch(commandIds.transformBegin, {
target: { type: "artboard", id: artboard.id },
target,
handle,
point: viewportPointToDocumentPoint(event.position, editor.viewport),
initialBounds: artboard.bounds,
initialBounds: bounds,
});
return true;
},