UNPKG

@gravity-ui/graph

Version:

Modern graph editor component

56 lines (55 loc) 3.46 kB
import { GraphComponent } from "../../components/canvas/GraphComponent"; import { Block, TBlock } from "../../components/canvas/blocks/Block"; import { ECanDrag } from "../../store/settings"; import { TRect } from "../types/shapes"; export { parseClassNames } from "./classNames"; export declare function noop(...args: unknown[]): void; export declare function isTouchEvent(event: Event): event is TouchEvent; export declare function getXY(root: HTMLElement, event: Event | WheelEvent | MouseEvent): [number, number]; export declare function getCoord(event: TouchEvent | MouseEvent, coord: string): any; export declare function getEventDelta(e1: TouchEvent | MouseEvent, e2: TouchEvent | MouseEvent): number; export declare function isMetaKeyEvent(event: MouseEvent | KeyboardEvent): boolean; export declare function isShiftKeyEvent(event: MouseEvent | KeyboardEvent): boolean; export declare function isAltKeyEvent(event: MouseEvent | KeyboardEvent): boolean; export declare function getEventSelectionAction(event: MouseEvent): number; export declare function isBlock(component: unknown): component is Block; export declare function createObject(simpleObject: object, forDefineProperties: PropertyDescriptorMap): object; export declare function addEventListeners(instance: EventTarget, mapEventsToFn?: Record<string, (event: CustomEvent | MouseEvent) => void>): () => void; /** * Check if drag is allowed based on canDrag setting and component selection state. * @param canDrag - The canDrag setting value * @param isSelected - Whether the component is currently selected * @returns true if the component can be dragged */ export declare function isAllowDrag(canDrag: ECanDrag, isSelected: boolean): boolean; /** * Gets the usable rectangle that encompasses the specified blocks. * If no blocks are provided or the blocks array is empty, returns a default rectangle (0,0,0,0) * to prevent camera state issues with Infinity values. * * @param blocks - Array of blocks to calculate bounding box for * @returns TRect representing the bounding box of the blocks, or a default rect (0,0,0,0) if no blocks or invalid geometry */ export declare function getBlocksRect(blocks: TBlock[]): TRect; export declare function getElementsRect<T extends GraphComponent = GraphComponent>(elements: T[]): TRect; export declare function isGeometryHaveInfinity(geometry: TRect): boolean; export declare function startAnimation(duration: number, draw: (progress: number) => void): void; /** * Calculates a "nice" number approximately equal to the range. * Useful for determining tick spacing on axes or rulers. * Algorithm adapted from "Nice Numbers for Graph Labels" by Paul Heckbert * @param range The desired approximate range or step. * @param round Whether to round the result (usually false for step calculation). * @returns A nice number (e.g., 1, 2, 5, 10, 20, 50, ...). */ export declare function calculateNiceNumber(range: number, round?: boolean): number; /** * Aligns a coordinate value to the device's physical pixel grid for sharper rendering. * @param value The coordinate value (e.g., x or y). * @param dpr The device pixel ratio. * @returns The aligned coordinate value. */ export declare function alignToPixelGrid(value: number, dpr: number): number; export declare function computeCssVariable(name: string): string; export { schedule, debounce, throttle } from "../utils/schedule"; export { isTrackpadWheelEvent } from "./isTrackpadDetector";