@html-graph/html-graph 0.0.43
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.
- package/LICENSE +21 -0
- package/README.md +100 -0
- package/dist/main.d.ts +569 -0
- package/dist/main.js +1308 -0
- package/dist/main.umd.cjs +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Dmitry Marov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
<h1>
|
|
2
|
+
<img src="/media/favicon.png" alt="HTMLGraph" width="25" height="25"/> HTMLGraph
|
|
3
|
+
</h1>
|
|
4
|
+
|
|
5
|
+
## Graph visualization library that enables to customize nodes using HTML
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
Visit <a target="_blank" href="https://html-graph.github.io">live demo</a>
|
|
10
|
+
|
|
11
|
+
<a target="_blank" href="https://html-graph.github.io/">
|
|
12
|
+
<img width="100%" src="https://raw.githubusercontent.com/html-graph/html-graph/master/media/full-demo.gif"/>
|
|
13
|
+
</a>
|
|
14
|
+
|
|
15
|
+
Instead of connecting nodes dirrectly this library uses concept of ports, which provide greater fexibility at managing connections.
|
|
16
|
+
Port is an entity of the node to which connection can be attached to.
|
|
17
|
+
|
|
18
|
+
This library fits for tasks where easy nodes customization and interactiveness are required.
|
|
19
|
+
|
|
20
|
+
## Features:
|
|
21
|
+
|
|
22
|
+
- easy nodes customization using HTML
|
|
23
|
+
- wide configuration options out of the box
|
|
24
|
+
- draggable and scalable canvas with draggable nodes
|
|
25
|
+
- exhaustive set of examples
|
|
26
|
+
- typescript support
|
|
27
|
+
- mobile devices support
|
|
28
|
+
|
|
29
|
+
## Getting started:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
npm i @html-graph/core
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { ApiPortPayload, CanvasBuilder } from "@html-graph/html-graph";
|
|
37
|
+
|
|
38
|
+
const canvas = new CanvasBuilder()
|
|
39
|
+
.options({
|
|
40
|
+
background: { type: "dots" },
|
|
41
|
+
connections: { hasTargetArrow: true },
|
|
42
|
+
})
|
|
43
|
+
.draggableNodes()
|
|
44
|
+
.transformableCanvas()
|
|
45
|
+
.build();
|
|
46
|
+
|
|
47
|
+
function createNode(
|
|
48
|
+
name: string,
|
|
49
|
+
frontPortId: string,
|
|
50
|
+
backPortId: string,
|
|
51
|
+
): [HTMLElement, Record<string, ApiPortPayload>] {
|
|
52
|
+
const node = document.createElement("div");
|
|
53
|
+
node.classList.add("node");
|
|
54
|
+
|
|
55
|
+
const frontPort = document.createElement("div");
|
|
56
|
+
frontPort.classList.add("port");
|
|
57
|
+
node.appendChild(frontPort);
|
|
58
|
+
|
|
59
|
+
const text = document.createElement("div");
|
|
60
|
+
text.innerText = name;
|
|
61
|
+
node.appendChild(text);
|
|
62
|
+
|
|
63
|
+
const backPort = document.createElement("div");
|
|
64
|
+
backPort.classList.add("port");
|
|
65
|
+
node.appendChild(backPort);
|
|
66
|
+
|
|
67
|
+
return [node, { [frontPortId]: frontPort, [backPortId]: backPort }];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const [node1, ports1] = createNode("Node 1", "port-1-1", "port-1-2");
|
|
71
|
+
const [node2, ports2] = createNode("Node 2", "port-2-1", "port-2-2");
|
|
72
|
+
|
|
73
|
+
const canvasElement = document.getElementById("canvas")!;
|
|
74
|
+
|
|
75
|
+
canvas
|
|
76
|
+
.attach(canvasElement)
|
|
77
|
+
.addNode({ element: node1, x: 200, y: 400, ports: ports1 })
|
|
78
|
+
.addNode({ element: node2, x: 600, y: 500, ports: ports2 })
|
|
79
|
+
.addConnection({ from: "port-1-2", to: "port-2-1" });
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Refer to [Examples](examples) for more.
|
|
83
|
+
|
|
84
|
+
## Run examples locally
|
|
85
|
+
|
|
86
|
+
Use node version >= 20
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
npm install
|
|
90
|
+
|
|
91
|
+
npm run start
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
or
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
docker compose up
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Open `http://localhost:3100`
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
export declare interface ApiConnection {
|
|
2
|
+
id?: string;
|
|
3
|
+
from: string;
|
|
4
|
+
to: string;
|
|
5
|
+
options?: ConnectionOptions;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export declare interface ApiContentMoveTransform {
|
|
9
|
+
x?: number;
|
|
10
|
+
y?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export declare interface ApiContentScaleTransform {
|
|
14
|
+
scale: number;
|
|
15
|
+
x?: number;
|
|
16
|
+
y?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export declare interface ApiNode {
|
|
20
|
+
id?: string;
|
|
21
|
+
element: HTMLElement;
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
ports?: Record<string, ApiPortsPayload>;
|
|
25
|
+
centerFn?: CenterFn;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export declare interface ApiPort {
|
|
29
|
+
readonly id?: string;
|
|
30
|
+
readonly element: HTMLElement;
|
|
31
|
+
readonly nodeId: string;
|
|
32
|
+
readonly centerFn?: CenterFn;
|
|
33
|
+
readonly direction?: number | null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export declare type ApiPortsPayload = HTMLElement | {
|
|
37
|
+
readonly element: HTMLElement;
|
|
38
|
+
readonly centerFn?: CenterFn;
|
|
39
|
+
readonly direction?: number | null;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
declare interface ApiTransform {
|
|
43
|
+
scale?: number;
|
|
44
|
+
x?: number;
|
|
45
|
+
y?: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
declare interface ApiUpdateConnection {
|
|
49
|
+
readonly controller?: ConnectionController;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export declare type BackgroundDrawingFn = (ctx: CanvasRenderingContext2D, transformer: PublicViewportTransformer) => void;
|
|
53
|
+
|
|
54
|
+
declare type BackgroundOptions = {
|
|
55
|
+
readonly type: "none";
|
|
56
|
+
} | {
|
|
57
|
+
readonly type: "color";
|
|
58
|
+
readonly color?: string;
|
|
59
|
+
} | {
|
|
60
|
+
readonly type: "dots";
|
|
61
|
+
readonly dotColor?: string;
|
|
62
|
+
readonly dotGap?: number;
|
|
63
|
+
readonly dotRadius?: number;
|
|
64
|
+
readonly color?: string;
|
|
65
|
+
} | {
|
|
66
|
+
readonly type: "custom";
|
|
67
|
+
readonly drawingFn: BackgroundDrawingFn;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export declare class BezierConnectionController implements ConnectionController {
|
|
71
|
+
private readonly color;
|
|
72
|
+
private readonly width;
|
|
73
|
+
private readonly curvature;
|
|
74
|
+
private readonly arrowLength;
|
|
75
|
+
private readonly arrowWidth;
|
|
76
|
+
private readonly hasSourceArrow;
|
|
77
|
+
private readonly hasTargetArrow;
|
|
78
|
+
readonly svg: SVGSVGElement;
|
|
79
|
+
private readonly group;
|
|
80
|
+
private readonly line;
|
|
81
|
+
private readonly sourceArrow;
|
|
82
|
+
private readonly targetArrow;
|
|
83
|
+
constructor(color: string, width: number, curvature: number, arrowLength: number, arrowWidth: number, hasSourceArrow: boolean, hasTargetArrow: boolean);
|
|
84
|
+
update(x: number, y: number, width: number, height: number, from: PortPayload, to: PortPayload): void;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
declare interface BezierConnectionOptions {
|
|
88
|
+
readonly type?: "bezier";
|
|
89
|
+
readonly color?: string;
|
|
90
|
+
readonly width?: number;
|
|
91
|
+
readonly curvature?: number;
|
|
92
|
+
readonly arrowLength?: number;
|
|
93
|
+
readonly arrowWidth?: number;
|
|
94
|
+
readonly hasSourceArrow?: boolean;
|
|
95
|
+
readonly hasTargetArrow?: boolean;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export declare interface Canvas {
|
|
99
|
+
/**
|
|
100
|
+
* provides api for canvas transformation
|
|
101
|
+
*/
|
|
102
|
+
readonly transformation: PublicViewportTransformer;
|
|
103
|
+
/**
|
|
104
|
+
* provides api for graph structure access
|
|
105
|
+
*/
|
|
106
|
+
readonly model: PublicGraphStore;
|
|
107
|
+
/**
|
|
108
|
+
* adds node to graph
|
|
109
|
+
*/
|
|
110
|
+
addNode(node: ApiNode): Canvas;
|
|
111
|
+
/**
|
|
112
|
+
* removes node from graph
|
|
113
|
+
* all the ports of node get unmarked
|
|
114
|
+
* all the connections adjacent to node get removed
|
|
115
|
+
*/
|
|
116
|
+
removeNode(nodeId: string): Canvas;
|
|
117
|
+
/**
|
|
118
|
+
* marks element as port of node
|
|
119
|
+
*/
|
|
120
|
+
markPort(port: ApiPort): Canvas;
|
|
121
|
+
/**
|
|
122
|
+
* updates connections attached to port
|
|
123
|
+
*/
|
|
124
|
+
updatePortConnections(portId: string): Canvas;
|
|
125
|
+
/**
|
|
126
|
+
* ummarks element as port of node
|
|
127
|
+
* all the connections adjacent to port get removed
|
|
128
|
+
*/
|
|
129
|
+
unmarkPort(portId: string): Canvas;
|
|
130
|
+
/**
|
|
131
|
+
* adds connection to graph
|
|
132
|
+
*/
|
|
133
|
+
addConnection(connection: ApiConnection): Canvas;
|
|
134
|
+
/**
|
|
135
|
+
* removes connection from graph
|
|
136
|
+
*/
|
|
137
|
+
removeConnection(connectionId: string): Canvas;
|
|
138
|
+
/**
|
|
139
|
+
* applies transformation for viewport
|
|
140
|
+
*/
|
|
141
|
+
patchViewportTransform(apiTransform: ApiTransform): Canvas;
|
|
142
|
+
/**
|
|
143
|
+
* applies move transformation for content
|
|
144
|
+
*/
|
|
145
|
+
moveContent(apiTransform: ApiContentMoveTransform): Canvas;
|
|
146
|
+
/**
|
|
147
|
+
* applies scale transformation for content
|
|
148
|
+
*/
|
|
149
|
+
scaleContent(apiTransform: ApiContentScaleTransform): Canvas;
|
|
150
|
+
/**
|
|
151
|
+
* applies shift transformation for content
|
|
152
|
+
*/
|
|
153
|
+
moveToNodes(nodeIds: readonly string[]): Canvas;
|
|
154
|
+
/**
|
|
155
|
+
* updates node absolute coordinates
|
|
156
|
+
*/
|
|
157
|
+
updateNodeCoords(nodeId: string, x: number, y: number): Canvas;
|
|
158
|
+
/**
|
|
159
|
+
* updates connection
|
|
160
|
+
*/
|
|
161
|
+
updateConnectionOptions(connectionId: string, options: ApiUpdateConnection): Canvas;
|
|
162
|
+
/**
|
|
163
|
+
* drags node in viewport
|
|
164
|
+
*/
|
|
165
|
+
dragNode(nodeId: string, dx: number, dy: number): Canvas;
|
|
166
|
+
/**
|
|
167
|
+
* moves specified node on top
|
|
168
|
+
*/
|
|
169
|
+
moveNodeOnTop(nodeId: string): Canvas;
|
|
170
|
+
/**
|
|
171
|
+
* attaches canvas to given element
|
|
172
|
+
*/
|
|
173
|
+
attach(element: HTMLElement): Canvas;
|
|
174
|
+
/**
|
|
175
|
+
* detaches canvas from element
|
|
176
|
+
*/
|
|
177
|
+
detach(): Canvas;
|
|
178
|
+
/**
|
|
179
|
+
* clears graph
|
|
180
|
+
* graph gets rolled back to initial state
|
|
181
|
+
* canvas can be reused
|
|
182
|
+
*/
|
|
183
|
+
clear(): Canvas;
|
|
184
|
+
/**
|
|
185
|
+
* destroys canvas
|
|
186
|
+
* canvas element gets rolled back to initial state
|
|
187
|
+
* canvas requires reinitialization in order to be used again
|
|
188
|
+
*/
|
|
189
|
+
destroy(): void;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export declare class CanvasBuilder {
|
|
193
|
+
private coreOptions;
|
|
194
|
+
private transformOptions;
|
|
195
|
+
private isDraggable;
|
|
196
|
+
private isTransformable;
|
|
197
|
+
options(options: CoreOptions): CanvasBuilder;
|
|
198
|
+
draggableNodes(): CanvasBuilder;
|
|
199
|
+
transformableCanvas(options?: TransformOptions): CanvasBuilder;
|
|
200
|
+
build(): Canvas;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Provides core API for acting on graph
|
|
205
|
+
*/
|
|
206
|
+
export declare class CanvasCore implements Canvas {
|
|
207
|
+
private readonly apiOptions?;
|
|
208
|
+
readonly transformation: PublicViewportTransformer;
|
|
209
|
+
readonly model: PublicGraphStore;
|
|
210
|
+
private readonly options;
|
|
211
|
+
private readonly di;
|
|
212
|
+
constructor(apiOptions?: CoreOptions | undefined);
|
|
213
|
+
addNode(node: ApiNode): CanvasCore;
|
|
214
|
+
moveNodeOnTop(nodeId: string): CanvasCore;
|
|
215
|
+
removeNode(nodeId: string): CanvasCore;
|
|
216
|
+
markPort(port: ApiPort): CanvasCore;
|
|
217
|
+
updatePortConnections(portId: string): CanvasCore;
|
|
218
|
+
unmarkPort(portId: string): CanvasCore;
|
|
219
|
+
addConnection(connection: ApiConnection): CanvasCore;
|
|
220
|
+
removeConnection(connectionId: string): CanvasCore;
|
|
221
|
+
patchViewportTransform(apiTransform: ApiTransform): CanvasCore;
|
|
222
|
+
moveContent(apiTransform: ApiContentMoveTransform): CanvasCore;
|
|
223
|
+
scaleContent(apiTransform: ApiContentScaleTransform): CanvasCore;
|
|
224
|
+
moveToNodes(nodeIds: readonly string[]): CanvasCore;
|
|
225
|
+
updateNodeCoords(nodeId: string, x: number, y: number): CanvasCore;
|
|
226
|
+
updateConnectionOptions(connectionId: string, options: ApiUpdateConnection): CanvasCore;
|
|
227
|
+
dragNode(nodeId: string, dx: number, dy: number): CanvasCore;
|
|
228
|
+
clear(): CanvasCore;
|
|
229
|
+
attach(element: HTMLElement): CanvasCore;
|
|
230
|
+
detach(): CanvasCore;
|
|
231
|
+
destroy(): void;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
declare type CenterFn = (width: number, height: number) => [number, number];
|
|
235
|
+
|
|
236
|
+
declare interface ConnectionController {
|
|
237
|
+
readonly svg: SVGSVGElement;
|
|
238
|
+
update(x: number, y: number, width: number, height: number, from: PortPayload, to: PortPayload): void;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
declare type ConnectionControllerFactory = () => ConnectionController;
|
|
242
|
+
|
|
243
|
+
declare type ConnectionOptions = BezierConnectionOptions | StraightConnectionOptions | CustomConnectionOptions;
|
|
244
|
+
|
|
245
|
+
declare interface ConnectionPayload {
|
|
246
|
+
from: string;
|
|
247
|
+
to: string;
|
|
248
|
+
controller: ConnectionController;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export declare class ConnectionUtils {
|
|
252
|
+
static getPortCenter(port: PortPayload): Point;
|
|
253
|
+
static rotate(point: Point, vector: Point, center: Point): Point;
|
|
254
|
+
static getDirectionVector(direction: number | null, flipX: number, flipY: number): Point;
|
|
255
|
+
static getArrowPath(vect: Point, shiftX: number, shiftY: number, arrowLength: number, arrowWidth: number): string;
|
|
256
|
+
static getArrowOffsetPath(vect: Point, shiftX: number, shiftY: number, arrowLength: number, arrowOffset: number): string;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export declare interface CoreOptions {
|
|
260
|
+
/**
|
|
261
|
+
* canvas background settings
|
|
262
|
+
*/
|
|
263
|
+
readonly background?: BackgroundOptions;
|
|
264
|
+
/**
|
|
265
|
+
* nodes related behavior
|
|
266
|
+
*/
|
|
267
|
+
readonly nodes?: {
|
|
268
|
+
/**
|
|
269
|
+
* specifies how to determine center of node
|
|
270
|
+
* center of nodes specified in addNode method by x and y
|
|
271
|
+
*/
|
|
272
|
+
readonly centerFn?: CenterFn;
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* ports related behavior
|
|
276
|
+
*/
|
|
277
|
+
readonly ports?: {
|
|
278
|
+
/**
|
|
279
|
+
* specifies how to determine center of port
|
|
280
|
+
* center of port determines point to which connection attaches
|
|
281
|
+
*/
|
|
282
|
+
readonly centerFn?: CenterFn;
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
*connections related behavior
|
|
286
|
+
*/
|
|
287
|
+
readonly connections?: ConnectionOptions;
|
|
288
|
+
/**
|
|
289
|
+
* layers related behavior
|
|
290
|
+
*/
|
|
291
|
+
readonly layers?: {
|
|
292
|
+
/**
|
|
293
|
+
* sets layers order
|
|
294
|
+
*/
|
|
295
|
+
readonly mode?: LayersMode;
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
declare interface CustomConnectionOptions {
|
|
300
|
+
readonly type: "custom";
|
|
301
|
+
readonly controllerFactory: ConnectionControllerFactory;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export declare class DraggableNodesCanvas implements Canvas {
|
|
305
|
+
private readonly canvas;
|
|
306
|
+
readonly transformation: PublicViewportTransformer;
|
|
307
|
+
readonly model: PublicGraphStore;
|
|
308
|
+
private readonly nodes;
|
|
309
|
+
private grabbedNodeId;
|
|
310
|
+
private readonly nodeIdGenerator;
|
|
311
|
+
private element;
|
|
312
|
+
private readonly onCanvasMouseUp;
|
|
313
|
+
private readonly onCanvasMouseMove;
|
|
314
|
+
private readonly onCanvasTouchStart;
|
|
315
|
+
private readonly onCanvasTouchMove;
|
|
316
|
+
private readonly onCanvasTouchEnd;
|
|
317
|
+
private previousTouchCoords;
|
|
318
|
+
constructor(canvas: Canvas);
|
|
319
|
+
addNode(node: ApiNode): DraggableNodesCanvas;
|
|
320
|
+
removeNode(nodeId: string): DraggableNodesCanvas;
|
|
321
|
+
markPort(port: ApiPort): DraggableNodesCanvas;
|
|
322
|
+
updatePortConnections(portId: string): DraggableNodesCanvas;
|
|
323
|
+
unmarkPort(portId: string): DraggableNodesCanvas;
|
|
324
|
+
addConnection(connection: ApiConnection): DraggableNodesCanvas;
|
|
325
|
+
removeConnection(connectionId: string): DraggableNodesCanvas;
|
|
326
|
+
patchViewportTransform(apiTransform: ApiTransform): DraggableNodesCanvas;
|
|
327
|
+
moveContent(apiTransform: ApiContentMoveTransform): DraggableNodesCanvas;
|
|
328
|
+
scaleContent(apiTransform: ApiContentScaleTransform): DraggableNodesCanvas;
|
|
329
|
+
moveToNodes(nodeIds: readonly string[]): DraggableNodesCanvas;
|
|
330
|
+
updateNodeCoords(nodeId: string, x: number, y: number): DraggableNodesCanvas;
|
|
331
|
+
updateConnectionOptions(connectionId: string, options: ApiUpdateConnection): DraggableNodesCanvas;
|
|
332
|
+
dragNode(nodeId: string, dx: number, dy: number): DraggableNodesCanvas;
|
|
333
|
+
moveNodeOnTop(nodeId: string): DraggableNodesCanvas;
|
|
334
|
+
clear(): DraggableNodesCanvas;
|
|
335
|
+
attach(element: HTMLElement): DraggableNodesCanvas;
|
|
336
|
+
detach(): DraggableNodesCanvas;
|
|
337
|
+
destroy(): void;
|
|
338
|
+
private setCursor;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
declare class GraphStore {
|
|
342
|
+
private nodes;
|
|
343
|
+
private ports;
|
|
344
|
+
private nodePorts;
|
|
345
|
+
private portNodeId;
|
|
346
|
+
private connections;
|
|
347
|
+
private incommingConnections;
|
|
348
|
+
private outcommingConnections;
|
|
349
|
+
private cycleConnections;
|
|
350
|
+
getAllNodes(): readonly string[];
|
|
351
|
+
getAllPorts(): readonly string[];
|
|
352
|
+
getAllConnections(): readonly string[];
|
|
353
|
+
addNode(nodeId: string, element: HTMLElement, x: number, y: number, centerFn: CenterFn): void;
|
|
354
|
+
hasNode(nodeId: string): boolean;
|
|
355
|
+
getNode(nodeId: string): NodePayload;
|
|
356
|
+
updateNodeCoords(nodeId: string, x: number, y: number): void;
|
|
357
|
+
updateConnectionController(connectionId: string, controller: ConnectionController): void;
|
|
358
|
+
removeNode(nodeId: string): void;
|
|
359
|
+
addPort(portId: string, element: HTMLElement, nodeId: string, centerFn: CenterFn, dir: number | null): void;
|
|
360
|
+
getPort(portId: string): PortPayload;
|
|
361
|
+
getPortNode(portId: string): string;
|
|
362
|
+
hasPort(portId: string): boolean;
|
|
363
|
+
removePort(portId: string): void;
|
|
364
|
+
addConnection(connectionId: string, fromPortId: string, toPortId: string, svgController: ConnectionController): void;
|
|
365
|
+
getConnection(connectionId: string): ConnectionPayload;
|
|
366
|
+
hasConnection(connectionId: string): boolean;
|
|
367
|
+
removeConnection(connectionId: string): void;
|
|
368
|
+
getPortIncomingConnections(portId: string): readonly string[];
|
|
369
|
+
getPortOutcomingConnections(portId: string): readonly string[];
|
|
370
|
+
getPortCycleConnections(portId: string): readonly string[];
|
|
371
|
+
getPortAdjacentConnections(portId: string): readonly string[];
|
|
372
|
+
getNodeIncomingConnections(nodeId: string): readonly string[];
|
|
373
|
+
getNodeOutcomingConnections(nodeId: string): readonly string[];
|
|
374
|
+
getNodeCycleConnections(nodeId: string): readonly string[];
|
|
375
|
+
getNodeAdjacentConnections(nodeId: string): readonly string[];
|
|
376
|
+
clear(): void;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
declare type LayersMode = "connections-on-top" | "nodes-on-top" | "connections-follow-node";
|
|
380
|
+
|
|
381
|
+
declare interface NodePayload {
|
|
382
|
+
element: HTMLElement;
|
|
383
|
+
x: number;
|
|
384
|
+
y: number;
|
|
385
|
+
centerFn: CenterFn;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
declare type Point = [number, number];
|
|
389
|
+
|
|
390
|
+
export declare interface PortPayload {
|
|
391
|
+
element: HTMLElement;
|
|
392
|
+
centerFn: CenterFn;
|
|
393
|
+
direction: number | null;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
declare class PublicGraphStore {
|
|
397
|
+
private readonly graphStore;
|
|
398
|
+
constructor(graphStore: GraphStore);
|
|
399
|
+
getNode(nodeId: string): {
|
|
400
|
+
x: number;
|
|
401
|
+
y: number;
|
|
402
|
+
} | null;
|
|
403
|
+
getPort(portId: string): {
|
|
404
|
+
nodeId: string;
|
|
405
|
+
} | null;
|
|
406
|
+
getConnection(connectionId: string): {
|
|
407
|
+
from: string;
|
|
408
|
+
to: string;
|
|
409
|
+
} | null;
|
|
410
|
+
getAllNodes(): readonly string[];
|
|
411
|
+
getAllPorts(): readonly string[];
|
|
412
|
+
getAllConnections(): readonly string[];
|
|
413
|
+
hasNode(nodeId: string): boolean;
|
|
414
|
+
hasPort(portId: string): boolean;
|
|
415
|
+
hasConnection(connectionId: string): boolean;
|
|
416
|
+
getPortIncomingConnections(portId: string): readonly string[];
|
|
417
|
+
getPortOutcomingConnections(portId: string): readonly string[];
|
|
418
|
+
getPortCycleConnections(portId: string): readonly string[];
|
|
419
|
+
getPortAdjacentConnections(portId: string): readonly string[];
|
|
420
|
+
getNodeIncomingConnections(nodeId: string): readonly string[];
|
|
421
|
+
getNodeOutcomingConnections(nodeId: string): readonly string[];
|
|
422
|
+
getNodeCycleConnections(nodeId: string): readonly string[];
|
|
423
|
+
getNodeAdjacentConnections(nodeId: string): readonly string[];
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
export declare class PublicViewportTransformer {
|
|
427
|
+
private readonly transformer;
|
|
428
|
+
constructor(transformer: ViewportTransformer);
|
|
429
|
+
/**
|
|
430
|
+
* for given absolute coordinates returns viewport coordinates
|
|
431
|
+
* viewport coordinated represent actual coordinates on screen for given absolute coordinates
|
|
432
|
+
*/
|
|
433
|
+
getViewCoords(xa: number, ya: number): [number, number];
|
|
434
|
+
/**
|
|
435
|
+
* returns viewport scale
|
|
436
|
+
* it represents scale at which entities on canvas should be scaled to fit current scale
|
|
437
|
+
*/
|
|
438
|
+
getViewScale(): number;
|
|
439
|
+
/**
|
|
440
|
+
* for given viewport coordinates returns absolute coordinates
|
|
441
|
+
* absolute coordinates represent actual coordinates, which stay constant even for transformed canvas
|
|
442
|
+
*/
|
|
443
|
+
getAbsCoords(xv: number, yv: number): [number, number];
|
|
444
|
+
/**
|
|
445
|
+
* returns absolute scale
|
|
446
|
+
* it represents scale at which current viewport was scaled compared to initial state
|
|
447
|
+
*/
|
|
448
|
+
getAbsScale(): number;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export declare class StraightConnectionController implements ConnectionController {
|
|
452
|
+
private readonly color;
|
|
453
|
+
private readonly width;
|
|
454
|
+
private readonly arrowLength;
|
|
455
|
+
private readonly arrowWidth;
|
|
456
|
+
private readonly minPortOffset;
|
|
457
|
+
private readonly hasSourceArrow;
|
|
458
|
+
private readonly hasTargetArrow;
|
|
459
|
+
readonly svg: SVGSVGElement;
|
|
460
|
+
private readonly group;
|
|
461
|
+
private readonly line;
|
|
462
|
+
private readonly sourceArrow;
|
|
463
|
+
private readonly targetArrow;
|
|
464
|
+
constructor(color: string, width: number, arrowLength: number, arrowWidth: number, minPortOffset: number, hasSourceArrow: boolean, hasTargetArrow: boolean);
|
|
465
|
+
update(x: number, y: number, width: number, height: number, from: PortPayload, to: PortPayload): void;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
declare interface StraightConnectionOptions {
|
|
469
|
+
readonly type: "straight";
|
|
470
|
+
readonly color?: string;
|
|
471
|
+
readonly width?: number;
|
|
472
|
+
readonly arrowLength?: number;
|
|
473
|
+
readonly arrowWidth?: number;
|
|
474
|
+
readonly minPortOffset?: number;
|
|
475
|
+
readonly hasSourceArrow?: boolean;
|
|
476
|
+
readonly hasTargetArrow?: boolean;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
export declare class TransformableCanvas implements Canvas {
|
|
480
|
+
private readonly canvas;
|
|
481
|
+
private readonly options?;
|
|
482
|
+
readonly transformation: PublicViewportTransformer;
|
|
483
|
+
readonly model: PublicGraphStore;
|
|
484
|
+
private element;
|
|
485
|
+
private isMoving;
|
|
486
|
+
private prevTouches;
|
|
487
|
+
private readonly isScalable;
|
|
488
|
+
private readonly isShiftable;
|
|
489
|
+
private readonly minContentScale;
|
|
490
|
+
private readonly maxContentScale;
|
|
491
|
+
private readonly wheelSensitivity;
|
|
492
|
+
private readonly onMouseDown;
|
|
493
|
+
private readonly onMouseMove;
|
|
494
|
+
private readonly onMouseUp;
|
|
495
|
+
private readonly onWheelScroll;
|
|
496
|
+
private readonly onTouchStart;
|
|
497
|
+
private readonly onTouchMove;
|
|
498
|
+
private readonly onTouchEnd;
|
|
499
|
+
constructor(canvas: Canvas, options?: TransformOptions | undefined);
|
|
500
|
+
addNode(node: ApiNode): TransformableCanvas;
|
|
501
|
+
removeNode(nodeId: string): TransformableCanvas;
|
|
502
|
+
markPort(port: ApiPort): TransformableCanvas;
|
|
503
|
+
updatePortConnections(portId: string): TransformableCanvas;
|
|
504
|
+
unmarkPort(portId: string): TransformableCanvas;
|
|
505
|
+
addConnection(connection: ApiConnection): TransformableCanvas;
|
|
506
|
+
removeConnection(connectionId: string): TransformableCanvas;
|
|
507
|
+
patchViewportTransform(apiTransform: ApiTransform): TransformableCanvas;
|
|
508
|
+
moveContent(apiTransform: ApiContentMoveTransform): TransformableCanvas;
|
|
509
|
+
scaleContent(apiTransform: ApiContentScaleTransform): TransformableCanvas;
|
|
510
|
+
moveToNodes(nodeIds: readonly string[]): TransformableCanvas;
|
|
511
|
+
updateNodeCoords(nodeId: string, x: number, y: number): TransformableCanvas;
|
|
512
|
+
updateConnectionOptions(connectionId: string, options: ApiUpdateConnection): TransformableCanvas;
|
|
513
|
+
dragNode(nodeId: string, dx: number, dy: number): TransformableCanvas;
|
|
514
|
+
moveNodeOnTop(nodeId: string): TransformableCanvas;
|
|
515
|
+
clear(): TransformableCanvas;
|
|
516
|
+
attach(element: HTMLElement): TransformableCanvas;
|
|
517
|
+
detach(): TransformableCanvas;
|
|
518
|
+
destroy(): void;
|
|
519
|
+
private getAverageTouch;
|
|
520
|
+
private checkNextScaleValid;
|
|
521
|
+
private setCursor;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
export declare interface TransformOptions {
|
|
525
|
+
scale?: {
|
|
526
|
+
enabled?: boolean;
|
|
527
|
+
minContent?: number;
|
|
528
|
+
maxContent?: number;
|
|
529
|
+
wheelSensitivity?: number;
|
|
530
|
+
};
|
|
531
|
+
shift?: {
|
|
532
|
+
enabled?: boolean;
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
declare class ViewportTransformer {
|
|
537
|
+
private state;
|
|
538
|
+
/**
|
|
539
|
+
* dx2 - traslate x
|
|
540
|
+
* dy2 - traslate y
|
|
541
|
+
*
|
|
542
|
+
* direct transform
|
|
543
|
+
* s1 0 dx1 1 0 dx2
|
|
544
|
+
* 0 s1 dy1 0 1 dy2
|
|
545
|
+
* 0 0 1 0 0 1
|
|
546
|
+
*
|
|
547
|
+
* [s, dx, dy] = [s1, s * dx2 + dx1, s * dy2 + dy1]
|
|
548
|
+
*/
|
|
549
|
+
applyShift(dx: number, dy: number): void;
|
|
550
|
+
/**
|
|
551
|
+
* s2 - scale
|
|
552
|
+
* cx - scale pivot x
|
|
553
|
+
* cy - scale pivot y
|
|
554
|
+
*
|
|
555
|
+
* s1 0 dx1 s2 0 (1 - s2) * cx
|
|
556
|
+
* 0 s1 dy1 0 s2 (1 - s2) * cy
|
|
557
|
+
* 0 0 1 0 0 1
|
|
558
|
+
*
|
|
559
|
+
* [s, dx, dy] = [s1 * s2, s1 * (1 - s2) * cx + dx1, s1 * (1 - s2) * cy + dy1]
|
|
560
|
+
*/
|
|
561
|
+
applyScale(s2: number, cx: number, cy: number): void;
|
|
562
|
+
getViewCoords(xa: number, ya: number): [number, number];
|
|
563
|
+
getViewScale(): number;
|
|
564
|
+
getAbsCoords(xv: number, yv: number): [number, number];
|
|
565
|
+
getAbsScale(): number;
|
|
566
|
+
patchState(scale: number | null, x: number | null, y: number | null): void;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
export { }
|