@getartisanflow/alpineflow 0.1.0-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88 -0
  3. package/dist/alpineflow-collab.esm.js +465 -0
  4. package/dist/alpineflow-collab.esm.js.map +1 -0
  5. package/dist/alpineflow-collab.js +247 -0
  6. package/dist/alpineflow-collab.js.map +1 -0
  7. package/dist/alpineflow-dagre.esm.js +1661 -0
  8. package/dist/alpineflow-dagre.esm.js.map +1 -0
  9. package/dist/alpineflow-dagre.js +1655 -0
  10. package/dist/alpineflow-dagre.js.map +1 -0
  11. package/dist/alpineflow-elk.esm.js +47378 -0
  12. package/dist/alpineflow-elk.esm.js.map +1 -0
  13. package/dist/alpineflow-elk.js +47373 -0
  14. package/dist/alpineflow-elk.js.map +1 -0
  15. package/dist/alpineflow-force.esm.js +599 -0
  16. package/dist/alpineflow-force.esm.js.map +1 -0
  17. package/dist/alpineflow-force.js +477 -0
  18. package/dist/alpineflow-force.js.map +1 -0
  19. package/dist/alpineflow-hierarchy.esm.js +398 -0
  20. package/dist/alpineflow-hierarchy.esm.js.map +1 -0
  21. package/dist/alpineflow-hierarchy.js +393 -0
  22. package/dist/alpineflow-hierarchy.js.map +1 -0
  23. package/dist/alpineflow-theme.css +473 -0
  24. package/dist/alpineflow-whiteboard.esm.js +922 -0
  25. package/dist/alpineflow-whiteboard.esm.js.map +1 -0
  26. package/dist/alpineflow-whiteboard.js +922 -0
  27. package/dist/alpineflow-whiteboard.js.map +1 -0
  28. package/dist/alpineflow.bundle.esm.js +12604 -0
  29. package/dist/alpineflow.bundle.esm.js.map +1 -0
  30. package/dist/alpineflow.css +1415 -0
  31. package/dist/alpineflow.esm.js +158 -0
  32. package/dist/alpineflow.esm.js.map +1 -0
  33. package/dist/alpineflow.js +5 -0
  34. package/dist/alpineflow.js.map +1 -0
  35. package/dist/export-DjmXOnKD.js +76 -0
  36. package/dist/export-DjmXOnKD.js.map +1 -0
  37. package/dist/geometry-DZSZoYHE.js +82 -0
  38. package/dist/geometry-DZSZoYHE.js.map +1 -0
  39. package/dist/index-C0N1DL3G.js +11728 -0
  40. package/dist/index-C0N1DL3G.js.map +1 -0
  41. package/dist/index-L3Zm-CoX.js +513 -0
  42. package/dist/index-L3Zm-CoX.js.map +1 -0
  43. package/dist/registry-CChkuoVJ.js +15 -0
  44. package/dist/registry-CChkuoVJ.js.map +1 -0
  45. package/dist/store-CaFAFEdD.js +9 -0
  46. package/dist/store-CaFAFEdD.js.map +1 -0
  47. package/dist/timer-B39XOBYL.js +124 -0
  48. package/dist/timer-B39XOBYL.js.map +1 -0
  49. package/dist/types/lib/collab.cdn.d.ts +1 -0
  50. package/dist/types/lib/collab.d.ts +2 -0
  51. package/dist/types/lib/core.cdn.d.ts +1 -0
  52. package/dist/types/lib/core.d.ts +2 -0
  53. package/dist/types/lib/dagre.cdn.d.ts +1 -0
  54. package/dist/types/lib/dagre.d.ts +1 -0
  55. package/dist/types/lib/elk.cdn.d.ts +1 -0
  56. package/dist/types/lib/elk.d.ts +1 -0
  57. package/dist/types/lib/force.cdn.d.ts +1 -0
  58. package/dist/types/lib/force.d.ts +1 -0
  59. package/dist/types/lib/hierarchy.cdn.d.ts +1 -0
  60. package/dist/types/lib/hierarchy.d.ts +1 -0
  61. package/dist/types/lib/whiteboard.cdn.d.ts +1 -0
  62. package/dist/types/lib/whiteboard.d.ts +1 -0
  63. package/dist/types/src/animate/animator.d.ts +57 -0
  64. package/dist/types/src/animate/easing.d.ts +4 -0
  65. package/dist/types/src/animate/edge-transitions.d.ts +22 -0
  66. package/dist/types/src/animate/engine.d.ts +37 -0
  67. package/dist/types/src/animate/index.d.ts +10 -0
  68. package/dist/types/src/animate/interpolators.d.ts +14 -0
  69. package/dist/types/src/animate/paths.d.ts +64 -0
  70. package/dist/types/src/animate/timeline.d.ts +149 -0
  71. package/dist/types/src/collab/awareness.d.ts +40 -0
  72. package/dist/types/src/collab/bridge.d.ts +36 -0
  73. package/dist/types/src/collab/directives/flow-cursors.d.ts +16 -0
  74. package/dist/types/src/collab/index.d.ts +19 -0
  75. package/dist/types/src/collab/providers/in-memory.d.ts +41 -0
  76. package/dist/types/src/collab/providers/reverb.d.ts +59 -0
  77. package/dist/types/src/collab/providers/websocket.d.ts +33 -0
  78. package/dist/types/src/collab/store.d.ts +22 -0
  79. package/dist/types/src/collab/types.d.ts +55 -0
  80. package/dist/types/src/core/__fixtures__/nodes.d.ts +42 -0
  81. package/dist/types/src/core/announcer.d.ts +21 -0
  82. package/dist/types/src/core/auto-pan.d.ts +37 -0
  83. package/dist/types/src/core/child-layout.d.ts +18 -0
  84. package/dist/types/src/core/child-validation.d.ts +23 -0
  85. package/dist/types/src/core/clipboard.d.ts +29 -0
  86. package/dist/types/src/core/collapse.d.ts +54 -0
  87. package/dist/types/src/core/color-mode.d.ts +11 -0
  88. package/dist/types/src/core/compute.d.ts +33 -0
  89. package/dist/types/src/core/connections.d.ts +32 -0
  90. package/dist/types/src/core/constants.d.ts +18 -0
  91. package/dist/types/src/core/controls-panel.d.ts +23 -0
  92. package/dist/types/src/core/debug.d.ts +10 -0
  93. package/dist/types/src/core/deep-merge.d.ts +10 -0
  94. package/dist/types/src/core/drag.d.ts +63 -0
  95. package/dist/types/src/core/edge-paths/avoidant.d.ts +25 -0
  96. package/dist/types/src/core/edge-paths/bezier.d.ts +26 -0
  97. package/dist/types/src/core/edge-paths/editable.d.ts +22 -0
  98. package/dist/types/src/core/edge-paths/index.d.ts +7 -0
  99. package/dist/types/src/core/edge-paths/orthogonal.d.ts +27 -0
  100. package/dist/types/src/core/edge-paths/smoothstep.d.ts +22 -0
  101. package/dist/types/src/core/edge-paths/straight.d.ts +12 -0
  102. package/dist/types/src/core/edge-paths/utils.d.ts +30 -0
  103. package/dist/types/src/core/edge-utils.d.ts +57 -0
  104. package/dist/types/src/core/export.d.ts +12 -0
  105. package/dist/types/src/core/floating-edge.d.ts +33 -0
  106. package/dist/types/src/core/geometry.d.ts +79 -0
  107. package/dist/types/src/core/gradients.d.ts +30 -0
  108. package/dist/types/src/core/graph.d.ts +38 -0
  109. package/dist/types/src/core/helper-lines.d.ts +32 -0
  110. package/dist/types/src/core/history.d.ts +19 -0
  111. package/dist/types/src/core/index.d.ts +17 -0
  112. package/dist/types/src/core/intersection.d.ts +30 -0
  113. package/dist/types/src/core/keyboard-shortcuts.d.ts +45 -0
  114. package/dist/types/src/core/lasso-hit-test.d.ts +25 -0
  115. package/dist/types/src/core/lasso.d.ts +10 -0
  116. package/dist/types/src/core/layout/dagre.d.ts +11 -0
  117. package/dist/types/src/core/layout/elk.d.ts +13 -0
  118. package/dist/types/src/core/layout/force.d.ts +15 -0
  119. package/dist/types/src/core/layout/hierarchy.d.ts +13 -0
  120. package/dist/types/src/core/long-press.d.ts +11 -0
  121. package/dist/types/src/core/markers.d.ts +49 -0
  122. package/dist/types/src/core/minimap.d.ts +18 -0
  123. package/dist/types/src/core/node-flags.d.ts +19 -0
  124. package/dist/types/src/core/pan-zoom.d.ts +62 -0
  125. package/dist/types/src/core/proximity-connect.d.ts +25 -0
  126. package/dist/types/src/core/registry.d.ts +16 -0
  127. package/dist/types/src/core/render-plan.d.ts +52 -0
  128. package/dist/types/src/core/resize.d.ts +31 -0
  129. package/dist/types/src/core/rotation.d.ts +8 -0
  130. package/dist/types/src/core/selection-box.d.ts +14 -0
  131. package/dist/types/src/core/shapes.d.ts +10 -0
  132. package/dist/types/src/core/sub-flow.d.ts +61 -0
  133. package/dist/types/src/core/svg-path.d.ts +5 -0
  134. package/dist/types/src/core/types.d.ts +1238 -0
  135. package/dist/types/src/core/wire-bridge.d.ts +36 -0
  136. package/dist/types/src/index.d.ts +43 -0
  137. package/dist/types/src/layout/dagre.d.ts +2 -0
  138. package/dist/types/src/layout/elk.d.ts +2 -0
  139. package/dist/types/src/layout/force.d.ts +2 -0
  140. package/dist/types/src/layout/hierarchy.d.ts +2 -0
  141. package/dist/types/src/plugin/connection-utils.d.ts +54 -0
  142. package/dist/types/src/plugin/data/__test-utils.d.ts +9 -0
  143. package/dist/types/src/plugin/data/canvas-animation.d.ts +62 -0
  144. package/dist/types/src/plugin/data/canvas-collapse.d.ts +35 -0
  145. package/dist/types/src/plugin/data/canvas-compute.d.ts +6 -0
  146. package/dist/types/src/plugin/data/canvas-condense.d.ts +19 -0
  147. package/dist/types/src/plugin/data/canvas-config.d.ts +4 -0
  148. package/dist/types/src/plugin/data/canvas-context.d.ts +570 -0
  149. package/dist/types/src/plugin/data/canvas-dom.d.ts +13 -0
  150. package/dist/types/src/plugin/data/canvas-edges.d.ts +37 -0
  151. package/dist/types/src/plugin/data/canvas-history.d.ts +53 -0
  152. package/dist/types/src/plugin/data/canvas-layout.d.ts +151 -0
  153. package/dist/types/src/plugin/data/canvas-nodes.d.ts +73 -0
  154. package/dist/types/src/plugin/data/canvas-rows.d.ts +13 -0
  155. package/dist/types/src/plugin/data/canvas-selection.d.ts +45 -0
  156. package/dist/types/src/plugin/data/canvas-validation.d.ts +21 -0
  157. package/dist/types/src/plugin/data/canvas-viewport.d.ts +111 -0
  158. package/dist/types/src/plugin/data/flow-canvas.d.ts +2 -0
  159. package/dist/types/src/plugin/directives/flow-action.d.ts +12 -0
  160. package/dist/types/src/plugin/directives/flow-animate.d.ts +2 -0
  161. package/dist/types/src/plugin/directives/flow-arrow-draw.d.ts +2 -0
  162. package/dist/types/src/plugin/directives/flow-circle-draw.d.ts +2 -0
  163. package/dist/types/src/plugin/directives/flow-collapse.d.ts +2 -0
  164. package/dist/types/src/plugin/directives/flow-condense.d.ts +2 -0
  165. package/dist/types/src/plugin/directives/flow-context-menu.d.ts +2 -0
  166. package/dist/types/src/plugin/directives/flow-detail.d.ts +2 -0
  167. package/dist/types/src/plugin/directives/flow-devtools.d.ts +2 -0
  168. package/dist/types/src/plugin/directives/flow-drag-handle.d.ts +2 -0
  169. package/dist/types/src/plugin/directives/flow-draggable.d.ts +2 -0
  170. package/dist/types/src/plugin/directives/flow-edge-toolbar.d.ts +2 -0
  171. package/dist/types/src/plugin/directives/flow-edge.d.ts +7 -0
  172. package/dist/types/src/plugin/directives/flow-eraser.d.ts +2 -0
  173. package/dist/types/src/plugin/directives/flow-filter.d.ts +9 -0
  174. package/dist/types/src/plugin/directives/flow-follow.d.ts +9 -0
  175. package/dist/types/src/plugin/directives/flow-freehand.d.ts +2 -0
  176. package/dist/types/src/plugin/directives/flow-handle-connectable.d.ts +12 -0
  177. package/dist/types/src/plugin/directives/flow-handle-limit.d.ts +9 -0
  178. package/dist/types/src/plugin/directives/flow-handle-validate.d.ts +10 -0
  179. package/dist/types/src/plugin/directives/flow-handle.d.ts +29 -0
  180. package/dist/types/src/plugin/directives/flow-highlighter.d.ts +2 -0
  181. package/dist/types/src/plugin/directives/flow-loading.d.ts +2 -0
  182. package/dist/types/src/plugin/directives/flow-node-toolbar.d.ts +2 -0
  183. package/dist/types/src/plugin/directives/flow-node.d.ts +10 -0
  184. package/dist/types/src/plugin/directives/flow-panel.d.ts +2 -0
  185. package/dist/types/src/plugin/directives/flow-rectangle-draw.d.ts +2 -0
  186. package/dist/types/src/plugin/directives/flow-resizer.d.ts +2 -0
  187. package/dist/types/src/plugin/directives/flow-rotate.d.ts +11 -0
  188. package/dist/types/src/plugin/directives/flow-row-select.d.ts +2 -0
  189. package/dist/types/src/plugin/directives/flow-snapshot.d.ts +14 -0
  190. package/dist/types/src/plugin/directives/flow-text-tool.d.ts +2 -0
  191. package/dist/types/src/plugin/directives/flow-timeline.d.ts +2 -0
  192. package/dist/types/src/plugin/directives/flow-viewport.d.ts +2 -0
  193. package/dist/types/src/plugin/magics/flow.d.ts +2 -0
  194. package/dist/types/src/plugin/store.d.ts +2 -0
  195. package/dist/types/src/whiteboard/index.d.ts +2 -0
  196. package/package.json +153 -0
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Deep-merge `source` into `target` in place.
3
+ *
4
+ * Rules:
5
+ * - Objects are recursively merged (keys added/overwritten, unmentioned keys preserved).
6
+ * - Arrays are replaced, not merged.
7
+ * - `null` explicitly removes a key.
8
+ * - `undefined` values are ignored (key is not touched).
9
+ */
10
+ export declare function deepMerge<T extends Record<string, any>>(target: T, source: Record<string, any>): T;
@@ -0,0 +1,63 @@
1
+ import type { XYPosition, Viewport } from './types';
2
+ export interface DragOptions {
3
+ /** Called when a drag gesture starts */
4
+ onDragStart?: (event: DragStartEvent) => void;
5
+ /** Called during dragging with the new position */
6
+ onDrag?: (event: DragMoveEvent) => void;
7
+ /** Called when a drag gesture ends */
8
+ onDragEnd?: (event: DragEndEvent) => void;
9
+ /** Get the current viewport for coordinate conversion */
10
+ getViewport: () => Viewport;
11
+ /** Get the current node position in flow coordinates (for offset-preserving drag) */
12
+ getNodePosition: () => XYPosition;
13
+ /** Snap to grid: false or [gridX, gridY] */
14
+ snapToGrid?: false | [number, number];
15
+ /** CSS selector to restrict drag initiation. At event time, the dragged
16
+ * element is queried for a descendant matching this selector; if found,
17
+ * only pointer events originating within that descendant start a drag.
18
+ * When no match exists the drag is unrestricted (whole element). */
19
+ filterSelector?: string;
20
+ /** Fixed container for d3 pointer coordinates (prevents viewport transform from affecting drag) */
21
+ container?: HTMLElement;
22
+ /** Return true to block drag initiation (e.g. during animation lock). */
23
+ isLocked?: () => boolean;
24
+ /** CSS class name that prevents drag when on or inside event target. */
25
+ noDragClassName?: string;
26
+ /** Minimum pixel distance before drag starts. Default: 0 */
27
+ dragThreshold?: number;
28
+ }
29
+ export interface DragStartEvent {
30
+ nodeId: string;
31
+ position: XYPosition;
32
+ sourceEvent: MouseEvent | TouchEvent;
33
+ }
34
+ export interface DragMoveEvent {
35
+ nodeId: string;
36
+ position: XYPosition;
37
+ delta: XYPosition;
38
+ sourceEvent: MouseEvent | TouchEvent;
39
+ }
40
+ export interface DragEndEvent {
41
+ nodeId: string;
42
+ position: XYPosition;
43
+ sourceEvent: MouseEvent | TouchEvent;
44
+ }
45
+ export interface DragInstance {
46
+ /** Clean up d3 drag listeners */
47
+ destroy(): void;
48
+ }
49
+ /**
50
+ * Make a node element draggable.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * const dragger = createDrag(nodeEl, 'node-1', {
55
+ * getViewport: () => canvas.viewport,
56
+ * getNodePosition: () => canvas.getNode('node-1').position,
57
+ * onDrag: ({ nodeId, position }) => {
58
+ * canvas.getNode(nodeId).position = position;
59
+ * },
60
+ * });
61
+ * ```
62
+ */
63
+ export declare function createDrag(element: HTMLElement, nodeId: string, options: DragOptions): DragInstance;
@@ -0,0 +1,25 @@
1
+ import type { HandlePosition, Rect } from '../types';
2
+ import type { EdgePathResult } from './utils';
3
+ import { type RoutePoint } from './orthogonal';
4
+ export interface AvoidantPathParams {
5
+ sourceX: number;
6
+ sourceY: number;
7
+ sourcePosition?: HandlePosition;
8
+ targetX: number;
9
+ targetY: number;
10
+ targetPosition?: HandlePosition;
11
+ obstacles?: Rect[];
12
+ }
13
+ /**
14
+ * Convert waypoints into a smooth SVG path using Catmull-Rom spline
15
+ * interpolation, rendered as a series of cubic bezier (C) commands.
16
+ *
17
+ * Each segment from P[i] to P[i+1] uses neighboring points P[i-1] and P[i+2]
18
+ * to compute tangent-based control points:
19
+ * CP1 = P[i] + (P[i+1] - P[i-1]) / 6
20
+ * CP2 = P[i+1] - (P[i+2] - P[i]) / 6
21
+ *
22
+ * For endpoints, the missing neighbor is mirrored from the nearest available.
23
+ */
24
+ export declare function buildCatmullRomPath(waypoints: RoutePoint[]): string;
25
+ export declare function getAvoidantPath({ sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition, obstacles, }: AvoidantPathParams): EdgePathResult;
@@ -0,0 +1,26 @@
1
+ import type { HandlePosition } from '../types';
2
+ import { type EdgePathResult } from './utils';
3
+ interface BezierPathParams {
4
+ sourceX: number;
5
+ sourceY: number;
6
+ sourcePosition?: HandlePosition;
7
+ targetX: number;
8
+ targetY: number;
9
+ targetPosition?: HandlePosition;
10
+ curvature?: number;
11
+ }
12
+ /**
13
+ * Generate a cubic bezier edge path with handle-aware control points.
14
+ */
15
+ export declare function getBezierPath(params: BezierPathParams): EdgePathResult;
16
+ /**
17
+ * Generate a simple cubic bezier where control points are always at the
18
+ * midpoint between source and target (no handle-position awareness).
19
+ */
20
+ export declare function getSimpleBezierPath({ sourceX, sourceY, targetX, targetY, }: {
21
+ sourceX: number;
22
+ sourceY: number;
23
+ targetX: number;
24
+ targetY: number;
25
+ }): EdgePathResult;
26
+ export {};
@@ -0,0 +1,22 @@
1
+ import type { HandlePosition } from '../types';
2
+ import { type EdgePathResult } from './utils';
3
+ export type EditablePathStyle = 'linear' | 'step' | 'smoothstep' | 'catmull-rom' | 'bezier';
4
+ export interface EditablePathParams {
5
+ sourceX: number;
6
+ sourceY: number;
7
+ sourcePosition?: HandlePosition;
8
+ targetX: number;
9
+ targetY: number;
10
+ targetPosition?: HandlePosition;
11
+ controlPoints?: {
12
+ x: number;
13
+ y: number;
14
+ }[];
15
+ pathStyle?: EditablePathStyle;
16
+ borderRadius?: number;
17
+ }
18
+ /**
19
+ * Build an SVG path through [source, ...controlPoints, target]
20
+ * using the chosen interpolation style.
21
+ */
22
+ export declare function getEditablePath(params: EditablePathParams): EdgePathResult;
@@ -0,0 +1,7 @@
1
+ export { getAvoidantPath, buildCatmullRomPath } from './avoidant';
2
+ export { getBezierPath, getSimpleBezierPath } from './bezier';
3
+ export { getOrthogonalPath } from './orthogonal';
4
+ export { getSmoothStepPath, getStepPath } from './smoothstep';
5
+ export { getStraightPath } from './straight';
6
+ export { getEditablePath, type EditablePathStyle } from './editable';
7
+ export { getEdgeCenter, type EdgePathResult } from './utils';
@@ -0,0 +1,27 @@
1
+ import type { HandlePosition, Rect } from '../types';
2
+ import { type EdgePathResult } from './utils';
3
+ export declare const OBSTACLE_PADDING = 20;
4
+ export interface OrthogonalPathParams {
5
+ sourceX: number;
6
+ sourceY: number;
7
+ sourcePosition?: HandlePosition;
8
+ targetX: number;
9
+ targetY: number;
10
+ targetPosition?: HandlePosition;
11
+ obstacles?: Rect[];
12
+ borderRadius?: number;
13
+ }
14
+ export interface RoutePoint {
15
+ x: number;
16
+ y: number;
17
+ index: number;
18
+ }
19
+ /**
20
+ * Find an obstacle-free route from source to target using handle-aware offsets,
21
+ * a visibility graph, and Dijkstra pathfinding.
22
+ *
23
+ * Returns simplified waypoints (including actual source/target endpoints) or
24
+ * null if no route can be found.
25
+ */
26
+ export declare function findRoute(sourceX: number, sourceY: number, sourcePosition: HandlePosition, targetX: number, targetY: number, targetPosition: HandlePosition, obstacles: Rect[]): RoutePoint[] | null;
27
+ export declare function getOrthogonalPath({ sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition, obstacles, borderRadius, }: OrthogonalPathParams): EdgePathResult;
@@ -0,0 +1,22 @@
1
+ import type { HandlePosition } from '../types';
2
+ import { type EdgePathResult } from './utils';
3
+ interface SmoothStepPathParams {
4
+ sourceX: number;
5
+ sourceY: number;
6
+ sourcePosition?: HandlePosition;
7
+ targetX: number;
8
+ targetY: number;
9
+ targetPosition?: HandlePosition;
10
+ borderRadius?: number;
11
+ /** Minimum offset from node before the first bend */
12
+ offset?: number;
13
+ }
14
+ /**
15
+ * Generate a smoothstep (rounded right-angle) edge path.
16
+ */
17
+ export declare function getSmoothStepPath({ sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition, borderRadius, offset, }: SmoothStepPathParams): EdgePathResult;
18
+ /**
19
+ * Generate a step (non-rounded right-angle) edge path.
20
+ */
21
+ export declare function getStepPath(params: Omit<SmoothStepPathParams, 'borderRadius'>): EdgePathResult;
22
+ export {};
@@ -0,0 +1,12 @@
1
+ import { type EdgePathResult } from './utils';
2
+ interface StraightPathParams {
3
+ sourceX: number;
4
+ sourceY: number;
5
+ targetX: number;
6
+ targetY: number;
7
+ }
8
+ /**
9
+ * Generate a straight line edge path.
10
+ */
11
+ export declare function getStraightPath({ sourceX, sourceY, targetX, targetY, }: StraightPathParams): EdgePathResult;
12
+ export {};
@@ -0,0 +1,30 @@
1
+ import type { XYPosition } from '../types';
2
+ export interface EdgePathResult {
3
+ /** SVG path `d` attribute */
4
+ path: string;
5
+ /** Suggested position for a label at the midpoint */
6
+ labelPosition: XYPosition;
7
+ /** X offset for centering a label */
8
+ labelOffsetX: number;
9
+ /** Y offset for centering a label */
10
+ labelOffsetY: number;
11
+ }
12
+ /**
13
+ * Build a rounded SVG bend through three consecutive waypoints.
14
+ * Returns an `L…Q…` fragment (or just `L` if the points are collinear).
15
+ */
16
+ export declare function getBend(ax: number, ay: number, bx: number, by: number, cx: number, cy: number, radius: number): string;
17
+ /**
18
+ * Calculate the center point of an edge for label placement.
19
+ */
20
+ export declare function getEdgeCenter({ sourceX, sourceY, targetX, targetY, }: {
21
+ sourceX: number;
22
+ sourceY: number;
23
+ targetX: number;
24
+ targetY: number;
25
+ }): {
26
+ x: number;
27
+ y: number;
28
+ offsetX: number;
29
+ offsetY: number;
30
+ };
@@ -0,0 +1,57 @@
1
+ import type { FlowEdge, FlowNode, HandlePosition, Rect, ShapeDefinition } from './types';
2
+ import type { MarkerType, MarkerConfig } from './markers';
3
+ import type { EdgePathResult } from './edge-paths/utils';
4
+ /**
5
+ * Compute the x,y coordinates where an edge connects to a node based on
6
+ * the handle's position (top/right/bottom/left + corners).
7
+ * When the node has a shape, uses the shape's perimeter function for
8
+ * accurate connection points.
9
+ */
10
+ export declare function getHandleCoords(node: FlowNode, position: HandlePosition, shapeRegistry?: Record<string, ShapeDefinition>, globalOrigin?: [number, number]): {
11
+ x: number;
12
+ y: number;
13
+ };
14
+ /**
15
+ * Normalize corner positions to the nearest cardinal direction for
16
+ * path generators that only understand top/right/bottom/left.
17
+ */
18
+ export declare function toCardinalPosition(pos: HandlePosition): 'top' | 'right' | 'bottom' | 'left';
19
+ /**
20
+ * Return a unit vector pointing outward from the node for a given handle position.
21
+ */
22
+ export declare function getHandleOutwardDirection(position: HandlePosition): {
23
+ x: number;
24
+ y: number;
25
+ };
26
+ /**
27
+ * Shorten an edge endpoint away from the handle center so the marker tip
28
+ * sits just outside the handle's visible boundary.
29
+ */
30
+ export declare function shortenEndpoint(coords: {
31
+ x: number;
32
+ y: number;
33
+ }, position: HandlePosition, measurement: {
34
+ handleWidth: number;
35
+ handleHeight: number;
36
+ } | null, marker: MarkerType | MarkerConfig | undefined): {
37
+ x: number;
38
+ y: number;
39
+ };
40
+ /**
41
+ * Compute the SVG path for an edge given source/target nodes and handle positions.
42
+ * Dispatches to the appropriate path generator based on edge type.
43
+ */
44
+ export declare function getEdgePath(edge: FlowEdge, sourceNode: FlowNode, targetNode: FlowNode, sourcePosition?: HandlePosition, targetPosition?: HandlePosition, sourceCoords?: {
45
+ x: number;
46
+ y: number;
47
+ }, targetCoords?: {
48
+ x: number;
49
+ y: number;
50
+ }, edgeTypes?: Record<string, (params: {
51
+ sourceX: number;
52
+ sourceY: number;
53
+ sourcePosition: 'top' | 'right' | 'bottom' | 'left';
54
+ targetX: number;
55
+ targetY: number;
56
+ targetPosition: 'top' | 'right' | 'bottom' | 'left';
57
+ }) => EdgePathResult>, obstacles?: Rect[], shapeRegistry?: Record<string, ShapeDefinition>, globalOrigin?: [number, number]): EdgePathResult;
@@ -0,0 +1,12 @@
1
+ import type { FlowNode, Viewport, ToImageOptions } from './types';
2
+ /**
3
+ * Capture the flow canvas as a PNG data URL.
4
+ *
5
+ * @param container The .flow-container element
6
+ * @param viewportEl The .flow-viewport element
7
+ * @param nodes All non-hidden nodes (for bounds calculation)
8
+ * @param viewport Current viewport state
9
+ * @param options Export options
10
+ * @returns data:image/png;base64,... string
11
+ */
12
+ export declare function captureFlowImage(container: HTMLElement, viewportEl: HTMLElement, nodes: FlowNode[], viewport: Viewport, options?: ToImageOptions): Promise<string>;
@@ -0,0 +1,33 @@
1
+ import type { XYPosition, FlowNode, HandlePosition } from './types';
2
+ /**
3
+ * Compute the intersection point where a line from a node's center toward
4
+ * a target point crosses the node's rectangular boundary.
5
+ *
6
+ * Uses L1-norm (Manhattan) scaling to find exact border intersection.
7
+ */
8
+ export declare function getNodeIntersection(node: FlowNode, targetCenter: XYPosition): XYPosition;
9
+ /**
10
+ * Classify an intersection point on a node's border to a cardinal HandlePosition.
11
+ * Uses 1px tolerance for corner cases.
12
+ */
13
+ export declare function getEdgePosition(node: FlowNode, intersectionPoint: XYPosition): HandlePosition;
14
+ /**
15
+ * Compute floating edge parameters for both source and target nodes.
16
+ * Returns the intersection points and their cardinal positions.
17
+ */
18
+ export declare function getFloatingEdgeParams(sourceNode: FlowNode, targetNode: FlowNode): {
19
+ sx: number;
20
+ sy: number;
21
+ tx: number;
22
+ ty: number;
23
+ sourcePos: HandlePosition;
24
+ targetPos: HandlePosition;
25
+ };
26
+ /**
27
+ * Simpler alternative that returns cardinal positions based on center-to-center direction.
28
+ * Useful for advanced users who compute their own intersection points.
29
+ */
30
+ export declare function getSimpleFloatingPosition(sourceCenter: XYPosition, targetCenter: XYPosition): {
31
+ sourcePos: HandlePosition;
32
+ targetPos: HandlePosition;
33
+ };
@@ -0,0 +1,79 @@
1
+ import type { XYPosition, Viewport, Rect, FlowNode } from './types';
2
+ /**
3
+ * Convert screen (client) coordinates to flow coordinates.
4
+ */
5
+ export declare function screenToFlowPosition(screenX: number, screenY: number, viewport: Viewport, containerRect: DOMRect): XYPosition;
6
+ /**
7
+ * Convert flow coordinates to screen (client) coordinates.
8
+ */
9
+ export declare function flowToScreenPosition(flowX: number, flowY: number, viewport: Viewport, containerRect: DOMRect): XYPosition;
10
+ /**
11
+ * Calculate the bounding box that contains all given nodes.
12
+ */
13
+ export declare const DEFAULT_NODE_WIDTH = 150;
14
+ export declare const DEFAULT_NODE_HEIGHT = 50;
15
+ /**
16
+ * Compute the axis-aligned bounding box of a rectangle rotated around its center.
17
+ * Returns the expanded AABB in the same coordinate space as the input.
18
+ */
19
+ export declare function getRotatedBounds(x: number, y: number, w: number, h: number, rotation: number): Rect;
20
+ export declare function getNodesBounds(nodes: FlowNode[], globalOrigin?: [number, number]): Rect;
21
+ /**
22
+ * Return all nodes whose bounding box intersects the given rectangle.
23
+ * Uses AABB intersection with DEFAULT_NODE_WIDTH/HEIGHT fallback.
24
+ */
25
+ export declare function getNodesInRect(nodes: FlowNode[], rect: Rect, globalOrigin?: [number, number]): FlowNode[];
26
+ /**
27
+ * Return all nodes whose bounding box is fully contained within the given rectangle.
28
+ * Uses DEFAULT_NODE_WIDTH/HEIGHT fallback for nodes without measured dimensions.
29
+ */
30
+ export declare function getNodesFullyInRect(nodes: FlowNode[], rect: Rect, globalOrigin?: [number, number]): FlowNode[];
31
+ /**
32
+ * Calculate the viewport transform needed to fit a rect into a container.
33
+ */
34
+ export declare function getViewportForBounds(bounds: Rect, containerWidth: number, containerHeight: number, minZoom: number, maxZoom: number, padding?: number): Viewport;
35
+ /** Axis-aligned bounds (min/max form, not x/y/width/height) */
36
+ export interface Bounds {
37
+ minX: number;
38
+ minY: number;
39
+ maxX: number;
40
+ maxY: number;
41
+ }
42
+ /**
43
+ * Compute the visible bounds in flow coordinates given viewport state,
44
+ * container dimensions, and a buffer margin.
45
+ */
46
+ export declare function getVisibleBounds(viewport: Viewport, containerWidth: number, containerHeight: number, buffer: number): Bounds;
47
+ /**
48
+ * Grid-based spatial index for fast viewport queries.
49
+ *
50
+ * Flow space is divided into cells of `cellSize` pixels.
51
+ * Each cell holds a Set of node IDs whose bounding boxes overlap that cell.
52
+ * Viewport queries find all cells overlapping the query bounds, then
53
+ * union their node sets — O(cells) instead of O(nodes).
54
+ */
55
+ export declare class SpatialGrid {
56
+ private _cellSize;
57
+ private _cells;
58
+ private _nodeCells;
59
+ constructor(cellSize?: number);
60
+ private _cellKey;
61
+ private _getCellRange;
62
+ insert(id: string, x: number, y: number, w: number, h: number): void;
63
+ remove(id: string): void;
64
+ update(id: string, x: number, y: number, w: number, h: number): void;
65
+ query(bounds: Bounds): Set<string>;
66
+ clear(): void;
67
+ get size(): number;
68
+ }
69
+ /**
70
+ * Compute the pixel offset from a node's anchor point to its visual top-left corner.
71
+ * Returns {x: 0, y: 0} for the default [0, 0] origin.
72
+ */
73
+ export declare function getOriginOffset(origin: [number, number] | undefined, width: number, height: number): XYPosition;
74
+ /**
75
+ * Get the visual top-left position of a node, accounting for nodeOrigin.
76
+ * The node's `position` is its anchor point; this returns where the DOM
77
+ * element's top-left corner should be placed.
78
+ */
79
+ export declare function getNodeVisualPosition(node: FlowNode, globalOrigin?: [number, number]): XYPosition;
@@ -0,0 +1,30 @@
1
+ import type { EdgeGradient } from './types';
2
+ /**
3
+ * Type guard: is this color value a gradient object?
4
+ */
5
+ export declare function isGradient(color: string | EdgeGradient | undefined): color is EdgeGradient;
6
+ /**
7
+ * Generate a unique gradient def ID for an edge.
8
+ * Format: {flowId}__grad__{edgeId}
9
+ */
10
+ export declare function getGradientId(flowId: string, edgeId: string): string;
11
+ /**
12
+ * Extract a single solid color from any color value.
13
+ * For gradients, returns the `from` color (used as fallback for selection highlight, etc.).
14
+ */
15
+ export declare function resolveStrokeColor(color: string | EdgeGradient | undefined): string | null;
16
+ /**
17
+ * Create or update an SVG <linearGradient> element in a <defs> container.
18
+ * Uses gradientUnits="userSpaceOnUse" so coordinates are in SVG canvas space.
19
+ *
20
+ * @returns The gradient element.
21
+ *
22
+ * // TODO(future): Support radial gradients via <radialGradient>
23
+ * // TODO(future): Support multi-stop gradients (3+ color stops)
24
+ * // TODO(future): Support path-following gradients via <pattern>
25
+ */
26
+ export declare function upsertGradientDef(defsEl: Element, id: string, gradient: EdgeGradient, x1: number, y1: number, x2: number, y2: number): SVGLinearGradientElement;
27
+ /**
28
+ * Remove a gradient def by ID from a <defs> container.
29
+ */
30
+ export declare function removeGradientDef(defsEl: Element, id: string): void;
@@ -0,0 +1,38 @@
1
+ import type { FlowNode, FlowEdge } from './types';
2
+ /**
3
+ * Get all edges connected to a node (incoming and outgoing).
4
+ */
5
+ export declare function getConnectedEdges(nodeId: string, edges: FlowEdge[]): FlowEdge[];
6
+ /**
7
+ * Get all edges connected to any of the given nodes.
8
+ */
9
+ export declare function getConnectedEdgesForNodes(nodeIds: string[], edges: FlowEdge[]): FlowEdge[];
10
+ /**
11
+ * Get all nodes that a given node connects to (outgoing edges).
12
+ */
13
+ export declare function getOutgoers(nodeId: string, nodes: FlowNode[], edges: FlowEdge[]): FlowNode[];
14
+ /**
15
+ * Get all nodes that connect to a given node (incoming edges).
16
+ */
17
+ export declare function getIncomers(nodeId: string, nodes: FlowNode[], edges: FlowEdge[]): FlowNode[];
18
+ /**
19
+ * Check whether adding an edge from `source` to `target` would create a cycle
20
+ * in the directed graph defined by `edges`. Uses iterative DFS from `target`
21
+ * following outgoing edges — if `source` is reachable, the new edge would
22
+ * close a loop.
23
+ */
24
+ export declare function wouldCreateCycle(source: string, target: string, edges: {
25
+ source: string;
26
+ target: string;
27
+ }[]): boolean;
28
+ /**
29
+ * Check if two nodes are directly connected by an edge.
30
+ */
31
+ export declare function areNodesConnected(nodeA: string, nodeB: string, edges: FlowEdge[], directed?: boolean): boolean;
32
+ /**
33
+ * Compute bridge edges that reconnect predecessors to successors
34
+ * when middle nodes are deleted. For each deleted node that has both
35
+ * incoming and outgoing edges (to/from non-deleted nodes), creates
36
+ * edges from each predecessor to each successor.
37
+ */
38
+ export declare function computeReconnectionEdges(deletionIds: Set<string>, nodes: FlowNode[], edges: FlowEdge[]): FlowEdge[];
@@ -0,0 +1,32 @@
1
+ import type { FlowNode } from './types';
2
+ export interface NodeBox {
3
+ id: string;
4
+ x: number;
5
+ y: number;
6
+ width: number;
7
+ height: number;
8
+ }
9
+ export interface HelperLineResult {
10
+ /** Horizontal guide Y positions */
11
+ horizontal: number[];
12
+ /** Vertical guide X positions */
13
+ vertical: number[];
14
+ /** Snap offset to apply to dragged position */
15
+ snapOffset: {
16
+ x: number;
17
+ y: number;
18
+ };
19
+ }
20
+ /**
21
+ * Get bounding box for a node.
22
+ */
23
+ export declare function nodeToBox(node: FlowNode, globalOrigin?: [number, number]): NodeBox;
24
+ /**
25
+ * Compute alignment guides between a dragged box and other boxes.
26
+ *
27
+ * Checks 5 horizontal alignments (top-top, bottom-bottom, center-center, top-bottom, bottom-top)
28
+ * and 5 vertical alignments (left-left, right-right, center-center, left-right, right-left).
29
+ *
30
+ * Returns deduplicated guide positions and the snap offset for the closest alignment per axis.
31
+ */
32
+ export declare function computeHelperLines(dragged: NodeBox, others: NodeBox[], threshold: number): HelperLineResult;
@@ -0,0 +1,19 @@
1
+ import type { FlowNode, FlowEdge } from './types';
2
+ export interface HistorySnapshot {
3
+ nodes: FlowNode[];
4
+ edges: FlowEdge[];
5
+ }
6
+ export declare class FlowHistory {
7
+ private past;
8
+ private future;
9
+ private maxSize;
10
+ private _suspendDepth;
11
+ constructor(maxSize?: number);
12
+ suspend(): void;
13
+ resume(): void;
14
+ capture(current: HistorySnapshot): void;
15
+ undo(current: HistorySnapshot): HistorySnapshot | null;
16
+ redo(current: HistorySnapshot): HistorySnapshot | null;
17
+ get canUndo(): boolean;
18
+ get canRedo(): boolean;
19
+ }
@@ -0,0 +1,17 @@
1
+ export type { XYPosition, Viewport, Rect, Dimensions, CoordinateExtent, FlowNode, FlowEdge, EdgeType, HandleType, HandlePosition, HandleConfig, Connection, PendingConnection, FlowEvents, FlowCanvasConfig, FlowInstance, } from './types';
2
+ export { isNode, isEdge } from './types';
3
+ export { getBezierPath, getSimpleBezierPath, getSmoothStepPath, getStepPath, getStraightPath, getEdgeCenter, type EdgePathResult, } from './edge-paths';
4
+ export { createPanZoom, type PanZoomOptions, type PanZoomInstance } from './pan-zoom';
5
+ export { createDrag, type DragOptions, type DragInstance } from './drag';
6
+ export { isPointInHandle, findClosestHandle, isValidConnection, type HandleBounds } from './connections';
7
+ export { getConnectedEdges, getConnectedEdgesForNodes, getOutgoers, getIncomers, areNodesConnected, wouldCreateCycle, } from './graph';
8
+ export { screenToFlowPosition, flowToScreenPosition, getNodesBounds, getViewportForBounds, } from './geometry';
9
+ export { computeResize, DEFAULT_RESIZE_CONSTRAINTS, type ResizeDirection, type ResizeConstraints, type ResizeResult, } from './resize';
10
+ export { getNodeIntersection, getEdgePosition, getFloatingEdgeParams, getSimpleFloatingPosition, } from './floating-edge';
11
+ export { buildNodeMap, getAbsolutePosition, toAbsoluteNode, toAbsoluteNodes, getDescendantIds, sortNodesTopological, computeZIndex, clampToExtent, clampToParent, expandParentToFitChild, } from './sub-flow';
12
+ export { FlowHistory, type HistorySnapshot } from './history';
13
+ export { getNodeRect, rectsIntersect, getIntersectingNodes, isNodeIntersecting, clampToAvoidOverlap, } from './intersection';
14
+ export { createColorMode } from './color-mode';
15
+ export type { ColorMode, ColorModeHandle } from './color-mode';
16
+ export { debug, setDebugEnabled, isDebugEnabled } from './debug';
17
+ export { normalizeMarker, getMarkerId, getMarkerSvg, registerMarker, type MarkerType, type MarkerConfig, type CustomMarkerRenderer, } from './markers';
@@ -0,0 +1,30 @@
1
+ import type { FlowNode, Rect } from './types';
2
+ /** Get the bounding rect of a node (uses measured or default dimensions). */
3
+ export declare function getNodeRect(node: FlowNode, globalOrigin?: [number, number]): Rect;
4
+ /** AABB overlap test between two rectangles. */
5
+ export declare function rectsIntersect(a: Rect, b: Rect): boolean;
6
+ /**
7
+ * Return all nodes whose bounding rect overlaps the given node.
8
+ * `partially` (default true) — any overlap counts. If false, only full containment.
9
+ */
10
+ export declare function getIntersectingNodes(node: FlowNode, candidates: FlowNode[], partially?: boolean): FlowNode[];
11
+ /**
12
+ * Check if a specific node intersects with the given node.
13
+ * `partially` (default true) — any overlap counts. If false, only full containment.
14
+ */
15
+ export declare function isNodeIntersecting(node: FlowNode, target: FlowNode, partially?: boolean): boolean;
16
+ /**
17
+ * Clamp a position to avoid overlap with other node rects.
18
+ * Returns the nearest non-overlapping position (pushes out along shortest axis).
19
+ *
20
+ * Note: Uses a single pass — chain overlaps (A pushed into B pushed into C)
21
+ * may not be fully resolved. This is intentional: a single pass is fast enough
22
+ * for real-time drag interactions where the user repositions continuously.
23
+ */
24
+ export declare function clampToAvoidOverlap(position: {
25
+ x: number;
26
+ y: number;
27
+ }, nodeWidth: number, nodeHeight: number, otherRects: Rect[], gap?: number): {
28
+ x: number;
29
+ y: number;
30
+ };
@@ -0,0 +1,45 @@
1
+ export type KeyCode = string;
2
+ export interface KeyboardShortcuts {
3
+ /** Key(s) for deleting selected elements. Default: ['Delete', 'Backspace'] */
4
+ delete?: KeyCode | KeyCode[] | null;
5
+ /** Modifier key to activate selection box (rubber-band). Default: 'Shift' */
6
+ selectionBox?: KeyCode | null;
7
+ /** Modifier key for multi-select (click to add). Default: 'Shift' */
8
+ multiSelect?: KeyCode | null;
9
+ /** Key(s) for arrow-key node movement. Default: ['ArrowUp','ArrowDown','ArrowLeft','ArrowRight'] */
10
+ moveNodes?: KeyCode | KeyCode[] | null;
11
+ /** Base movement step in pixels. Default: 5 */
12
+ moveStep?: number;
13
+ /** Modifier key that multiplies movement step. Default: 'Shift' */
14
+ moveStepModifier?: KeyCode | null;
15
+ /** Multiplier applied when moveStepModifier is held. Default: 4 */
16
+ moveStepMultiplier?: number;
17
+ /** Key for copy (with Ctrl/Cmd). Default: 'c' */
18
+ copy?: KeyCode | null;
19
+ /** Key for paste (with Ctrl/Cmd). Default: 'v' */
20
+ paste?: KeyCode | null;
21
+ /** Key for cut (with Ctrl/Cmd). Default: 'x' */
22
+ cut?: KeyCode | null;
23
+ /** Key for undo (with Ctrl/Cmd). Default: 'z' */
24
+ undo?: KeyCode | null;
25
+ /** Key for redo (with Ctrl/Cmd+Shift). Default: 'z' */
26
+ redo?: KeyCode | null;
27
+ /** Key for escape/cancel. Default: 'Escape' */
28
+ escape?: KeyCode | null;
29
+ /** Modifier key to temporarily toggle selection mode during a drag. Default: 'Alt' */
30
+ selectionModeToggle?: KeyCode | null;
31
+ /** Key to toggle between box and lasso selection tools. Default: 'l' */
32
+ selectionToolToggle?: KeyCode | null;
33
+ }
34
+ export declare const SHORTCUT_DEFAULTS: Readonly<Required<KeyboardShortcuts>>;
35
+ /** Merge user-provided shortcuts with defaults. `null` = disabled, `undefined`/missing = use default. */
36
+ export declare function resolveShortcuts(user?: Partial<KeyboardShortcuts>): Required<KeyboardShortcuts>;
37
+ /** Check if a keyboard event's key matches a configured shortcut. Case-insensitive for single characters (Shift changes 'w' to 'W'). */
38
+ export declare function matchesKey(eventKey: string, configured: KeyCode | KeyCode[] | null | undefined): boolean;
39
+ /** Check if a modifier key is held on an event. Maps 'Shift'→shiftKey, 'Control'→ctrlKey, etc. */
40
+ export declare function matchesModifier(event: {
41
+ shiftKey: boolean;
42
+ ctrlKey: boolean;
43
+ metaKey: boolean;
44
+ altKey: boolean;
45
+ }, configured: KeyCode | null | undefined): boolean;