import type { Point, TransformedLine } from "@hylimo/diagram-common"; import { SharedSettings } from "@hylimo/diagram-protocol"; import { type Matrix } from "transformation-matrix"; import { type HandleMoveResult } from "../../move/moveHandler.js"; import { SnapHandler } from "../../snap/snapHandler.js"; import type { SnapLines } from "../../snap/model.js"; import type { SElement } from "../../../model/sElement.js"; import type { SRoot } from "../../../model/sRoot.js"; import type { SModelElementImpl } from "sprotty"; import { SnapMoveHandler } from "../../snap/snapMoveHandler.js"; /** * Result of a position or distance edit operation * Contains the calculated position, distance, and any snap guide lines to display */ interface LineEditResult { /** * The position on the line * Can be either a single number (absolute position) or a tuple of [segment, relative position] */ pos: number | [number, number]; /** * The distance from the line */ dist: number; /** * Visual guide lines to display for the snap, if any */ snapLines: SnapLines | undefined; } /** * Move handler for line point moves * Expects relative coordinates to the point in the parent canvas coordinate system. * Handles both position editing (moving along the line) and distance editing (moving perpendicular to the line). * Supports snapping to improve precision during editing operations. */ export declare class LineMoveHandler extends SnapMoveHandler { private readonly point; private readonly editPos; private readonly editDist; private readonly line; private readonly settings; private readonly initialPos; private readonly initialDistance; /** * True if the pos is defined relative to a segment */ private readonly hasSegment; /** * Creates a new LineMoveHandler * * @param point the id of the point to move * @param editPos if true, the position of the point can be modified * @param editDist if true, the distance to the line can be modified * @param line the line on which the point is * @param settings the shared settings containing precision values * @param initialPos the initial position of the point on the line * @param initialDistance the current distance of the point to edit * @param elements elements to consider for snapping * @param ignoredElements elements to ignore when snapping * @param root the root element of the diagram * @param originalPoint the original point position before moving * @param snappingEnabled whether snapping is enabled * @param transformMatrix the transformation matrix to apply to obtain the relative position */ constructor(point: string, editPos: boolean, editDist: boolean, line: TransformedLine, settings: SharedSettings, initialPos: number | [number, number], initialDistance: number | undefined, elements: SElement[], ignoredElements: Set, root: SRoot, originalPoint: Point, snappingEnabled: boolean, transformMatrix: Matrix); handleMove(x: number, y: number, event: MouseEvent, target: SModelElementImpl): HandleMoveResult; /** * Handles editing the position of a point * Processes position editing logic, including attempting to snap the position if a snap handler is available * Falls back to direct projection if snapping isn't available or doesn't produce valid results * * @param x the x coordinate * @param y the y coordinate * @param root the root element * @param event the causing mouse event * @returns the position, distance, and snap lines */ private handlePositionEdit; /** * Attempts to snap a position to the grid or other snap targets * Performs projection and proximity checking to determine if snapping should be applied * * @param x the x coordinate of the mouse position * @param y the y coordinate of the mouse position * @param root the root element containing the viewport information * @returns the snapped position data if snapping was successful, undefined otherwise */ private trySnapPosition; /** * Calculates the nearest point on the line to the given coordinates * * @param x the x coordinate * @param y the y coordinate * @returns the projected point data including position, segment, and distance */ private calculateNearestPoint; /** * Handles editing the distance of a point from a line * When position editing is disabled, this allows moving a point perpendicular to the line * Can also apply snapping to the distance value if a snap handler is available * * @param x the x coordinate of the mouse position * @param y the y coordinate of the mouse position * @param root the root element containing the viewport information * @param event the causing mouse event * @returns the position, calculated distance, and any snap guide lines */ private handleDistanceEdit; /** * Creates the edit result from the position, distance, and snap lines * Builds the appropriate edit objects based on the current edit mode and provided values * * @param pos the calculated position (may be undefined if no valid position was found) * @param dist the calculated distance (may be undefined if no valid distance was found) * @param snapLines visual snap guides to display * @returns the handle move result containing the edits to apply */ private createEditResult; } /** * Snap handler specialized for line points * Provides snapping functionality when moving points on a line, handling both position and distance snapping * Works with the overall snapping system to provide consistent behavior across the diagram */ declare class LineSnapHandler extends SnapHandler { private readonly originalPoint; private readonly line; /** * Intitial snap element data for a drag vector (0, 0) */ private readonly snapElementData; /** * Creates a new LineSnapHandler * * @param elements elements to consider for snapping * @param ignoredElements elements to ignore when snapping * @param root the root element of the diagram * @param originalPoint the original point position before moving * @param line the line on which the point is located * @param settings settings containing precision and other configuration values */ constructor(elements: SElement[], ignoredElements: Set, root: SRoot, originalPoint: Point, line: TransformedLine, settings: SharedSettings | undefined); /** * Attempts to snap a point on a line based on the provided parameters * This is the main snapping logic for line points, handling both position and distance snapping * * @param pos the position on the line * @param segment the segment index if using segment-based positioning, undefined otherwise * @param distance the current distance from the line * @param zoom the current zoom level of the viewport * @param editPos whether position editing is enabled * @param editDist whether distance editing is enabled * @returns the snap result if snapping was successful, undefined otherwise */ snap(pos: number, segment: number | undefined, distance: number, zoom: number, editPos: boolean, editDist: boolean): LineEditResult | undefined; /** * Calculates the snap result for the given translation * Configures and calls the snapping system with appropriate parameters for line point snapping * * @param zoom the current zoom level of the viewport * @param translation the translation vector from the original point * @returns the snap result containing snap targets and offset information */ private calculateSnapResult; /** * Handles snapping when editing a point's position * Processes the snapped point, creates appropriate transformations, and verifies the snap is valid * * @param distance the current distance from the line * @param hasSegment whether segment-based positioning is being used * @param editDist whether distance editing is enabled * @param snapResult the snap result from the snapping system * @param snappedPoint the snapped point coordinates * @returns the snap result with position and distance information if valid, undefined otherwise */ private handlePositionSnap; /** * Calculates the transformation for a snapped point * Creates a transformation matrix based on the difference between the snapped point and the original point * * @param nearest the point projection data containing position and distance information * @returns a transformation matrix that would move the original point to the snapped position */ private calculateSnappedTransform; /** * Handles snapping when editing a point's distance from the line * Processes distance snapping logic, computes appropriate transformations, and validates the result * * @param pos the position on the line * @param segment the segment index if using segment-based positioning, undefined otherwise * @param distance the current distance from the line * @param targetPoint the original target point * @param snapResult the snap result from the snapping system * @param snappedPoint the snapped point coordinates * @param zoom the current zoom level of the viewport * @returns the snap result with position and distance information if valid, undefined otherwise */ private handleDistanceSnap; /** * Calculates the snapped distance based on the normal vector and snap result * Projects the snap offset onto the normal vector to determine the appropriate distance value * Handles cases for both x and y axis snapping, choosing the best result * * @param pointOnLine the point on the line at the given position * @param normal the normal vector to the line at the given position * @param distance the current distance from the line * @param snapResult the snap result from the snapping system * @param snappedPoint the snapped point coordinates * @returns the calculated distance value if a valid snap was found, undefined otherwise */ private calculateSnappedDistance; } export {}; //# sourceMappingURL=lineMoveHandler.d.ts.map