import { CompassDirection, Point, Rect, compassDirections, getCompassDirectionAnchor, } from "@noya-app/noya-geometry"; import { PointData } from "../plugins/pointPlugin"; import { ScaleData } from "../plugins/scalePlugin"; import { IdentifiablePoint } from "./pointUtils"; export type DragHandle = { rect: Rect; compassDirection: CompassDirection; offset: Point; strokeWidth: number; }; export function getDragHandles({ selectionRect, data: { zoom, dragHandleSize }, }: { selectionRect: Rect; data: Pick; }): DragHandle[] { const handleSize = dragHandleSize / zoom; return compassDirections.map((compassDirection) => { const anchor = getCompassDirectionAnchor(compassDirection, selectionRect); return { rect: { x: anchor.x - handleSize / 2, y: anchor.y - handleSize / 2, width: handleSize, height: handleSize, }, compassDirection, offset: anchor, strokeWidth: 1 / zoom, }; }); } type PointHandle = { rect: Rect; strokeWidth: number; id: string; }; export function getPointHandles({ points, data: { zoom, pointHandleSize }, }: { points: IdentifiablePoint[]; data: Pick; }): PointHandle[] { const handleSize = pointHandleSize / zoom; return points.map((point) => { return { rect: { x: point.x - handleSize / 2, y: point.y - handleSize / 2, width: handleSize, height: handleSize, }, strokeWidth: 1 / zoom, id: point.id, }; }); }