@samatawy/diagrams 0.1.0
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 +15 -0
- package/README.md +107 -0
- package/dist/index.cjs +11163 -0
- package/dist/index.d.cts +4240 -0
- package/dist/index.d.ts +4240 -0
- package/dist/index.js +11130 -0
- package/package.json +64 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single point in 2D space, defined by its x and y coordinates.
|
|
3
|
+
*/
|
|
4
|
+
interface IPoint {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A single point in 2D space that serves as an anchor for connections, defined by its ID and coordinates.
|
|
10
|
+
*/
|
|
11
|
+
interface AnchorPoint extends IPoint {
|
|
12
|
+
id: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A rectangle defined by its left and top coordinates, as well as its width and height.
|
|
16
|
+
* This is commonly used for bounding boxes and layout calculations.
|
|
17
|
+
*/
|
|
18
|
+
interface IRect {
|
|
19
|
+
left: number;
|
|
20
|
+
top: number;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Text alignment options for nodes, which determine how the text is aligned horizontally within the node's bounding box.
|
|
26
|
+
* - left: Aligns text to the left edge of the node.
|
|
27
|
+
* - center: Centers text horizontally within the node.
|
|
28
|
+
* - right: Aligns text to the right edge of the node.
|
|
29
|
+
*/
|
|
30
|
+
type ITextAlign = 'left' | 'center' | 'right';
|
|
31
|
+
/**
|
|
32
|
+
* Text baseline options for nodes, which determine how the text is aligned vertically within the node's bounding box.
|
|
33
|
+
* - top: Aligns text to the top edge of the node.
|
|
34
|
+
* - middle: Centers text vertically within the node.
|
|
35
|
+
* - bottom: Aligns text to the bottom edge of the node.
|
|
36
|
+
*/
|
|
37
|
+
type ITextBaseline = 'top' | 'middle' | 'bottom';
|
|
38
|
+
/**
|
|
39
|
+
* NodeHandle represents the different types of handles that can be used for manipulating nodes in the diagram.
|
|
40
|
+
* - MOVE: A handle for moving the entire node.
|
|
41
|
+
* - POINT: A handle for manipulating individual points of a node (e.g., for a polyline).
|
|
42
|
+
* - ROTATE: A handle for rotating the node.
|
|
43
|
+
* - N, S, E, W: Handles for resizing the node from the north, south, east, and west sides, respectively.
|
|
44
|
+
* - NE, NW, SE, SW: Handles for resizing the node from the northeast, northwest, southeast, and southwest corners, respectively.
|
|
45
|
+
* - NONE: Indicates that no handle is active or selected.
|
|
46
|
+
* These handles are used to determine how user interactions affect the node, such as dragging to move, resize, or rotate the node based on the active handle.
|
|
47
|
+
* The specific behavior of each handle is defined in the node's interaction logic and rendering code.
|
|
48
|
+
* For example, dragging the MOVE handle would translate the node's position, while dragging a corner handle like NE would resize the node while maintaining its aspect ratio.
|
|
49
|
+
*/
|
|
50
|
+
declare enum NodeHandle {
|
|
51
|
+
MOVE = "move",
|
|
52
|
+
POINT = "point",
|
|
53
|
+
ROTATE = "rotate",
|
|
54
|
+
N = "n",
|
|
55
|
+
S = "s",
|
|
56
|
+
E = "e",
|
|
57
|
+
W = "w",
|
|
58
|
+
NE = "ne",
|
|
59
|
+
NW = "nw",
|
|
60
|
+
SE = "se",
|
|
61
|
+
SW = "sw",
|
|
62
|
+
NONE = "none"
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* An ISerializer defines the methods for serializing and deserializing data, allowing objects to be converted to and from a string representation.
|
|
67
|
+
*/
|
|
68
|
+
interface ISerializer {
|
|
69
|
+
write(data: unknown): string;
|
|
70
|
+
read<T>(data: string): Promise<T>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The Serializable interface defines the contract for objects that can be serialized and deserialized using an ISerializer.
|
|
74
|
+
* It requires implementing a write method that converts the object to a serializable format, and a read method that reconstructs the object from its serialized representation.
|
|
75
|
+
*/
|
|
76
|
+
interface Serializable {
|
|
77
|
+
write(serializer: ISerializer): any;
|
|
78
|
+
read(json: any, serializer: ISerializer): Promise<this>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Serialized representation of a connection anchor, where the 'node' property is represented by the node's identifier instead of a reference to the node object.
|
|
82
|
+
* This format is suitable for JSON serialization and deserialization.
|
|
83
|
+
*/
|
|
84
|
+
interface ISerializedConnectionAnchor extends Omit<IConnectionAnchor, 'node'> {
|
|
85
|
+
node: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Serialized representation of a node, suitable for JSON serialization.
|
|
89
|
+
* The 'owner' property is not serialized, and connection anchors are represented with their own serialized format.
|
|
90
|
+
*/
|
|
91
|
+
interface ISerializedNode extends Omit<INode, 'owner'> {
|
|
92
|
+
from?: ISerializedConnectionAnchor;
|
|
93
|
+
to?: ISerializedConnectionAnchor;
|
|
94
|
+
startArrow?: boolean;
|
|
95
|
+
endArrow?: boolean;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Serialized representation of a layer, containing its identifier, name, visibility status, and the identifiers of the nodes it contains.
|
|
99
|
+
*/
|
|
100
|
+
interface ISerializedLayer {
|
|
101
|
+
id: string;
|
|
102
|
+
name: string;
|
|
103
|
+
visible: boolean;
|
|
104
|
+
nodes: string[];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Serialized representation of a diagram, containing its identifier, nodes, layers, metadata, and optional grid settings.
|
|
108
|
+
*/
|
|
109
|
+
interface ISerializedDiagram {
|
|
110
|
+
id: string;
|
|
111
|
+
nodes: ISerializedNode[];
|
|
112
|
+
layers: ISerializedLayer[];
|
|
113
|
+
grid?: Partial<IGrid>;
|
|
114
|
+
meta?: Record<string, unknown>;
|
|
115
|
+
image_assets?: Record<string, string>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
type ArrowDirection = 'start' | 'end' | 'both' | 'none';
|
|
119
|
+
/**
|
|
120
|
+
* ShadowStyle defines the properties of a shadow effect that can be applied to nodes in the diagram.
|
|
121
|
+
*/
|
|
122
|
+
interface ShadowStyle {
|
|
123
|
+
/**
|
|
124
|
+
* The name of the shadow style, used for display purposes in the UI when selecting a shadow effect.
|
|
125
|
+
*/
|
|
126
|
+
name: string;
|
|
127
|
+
/**
|
|
128
|
+
* The color of the shadow, which can be a CSS color string (e.g., '#000000' for black) or undefined for a default color.
|
|
129
|
+
* If the color is undefined, the rendering logic may choose a default shadow color based on the node's properties or theme.
|
|
130
|
+
*/
|
|
131
|
+
color?: string;
|
|
132
|
+
/**
|
|
133
|
+
* The blur radius of the shadow, which determines how blurry the shadow appears.
|
|
134
|
+
* A higher value results in a softer, more diffuse shadow, while a value of 0 creates a sharp shadow with no blur.
|
|
135
|
+
*/
|
|
136
|
+
blur: number;
|
|
137
|
+
/**
|
|
138
|
+
* The offset of the shadow, which determines the horizontal and vertical displacement of the shadow relative to the node.
|
|
139
|
+
* Positive values move the shadow right and down, while negative values move it left and up.
|
|
140
|
+
* The offset has an x component for horizontal displacement and a y component for vertical displacement, allowing for directional shadows
|
|
141
|
+
* (e.g., a shadow that appears to the right and below the node).
|
|
142
|
+
*/
|
|
143
|
+
offset: IPoint;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* An array of predefined shadow styles that can be applied to nodes in the diagram.
|
|
147
|
+
*/
|
|
148
|
+
declare const shadowStyles: ShadowStyle[];
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* INode defines the properties of a node in the diagram, including its ID, type, geometry (points), text properties, styling options, and its relationship to the diagram it belongs to.
|
|
152
|
+
* Nodes are the fundamental building blocks of the diagram, representing entities that can be connected and manipulated.
|
|
153
|
+
*/
|
|
154
|
+
interface INode {
|
|
155
|
+
/**
|
|
156
|
+
* The unique identifier of the node, which is used to reference the node within the diagram and for serialization purposes.
|
|
157
|
+
*/
|
|
158
|
+
id: string;
|
|
159
|
+
/**
|
|
160
|
+
* The type of the node, which can be used to determine how the node is rendered and interacted with.
|
|
161
|
+
*/
|
|
162
|
+
type: string;
|
|
163
|
+
/**
|
|
164
|
+
* A reference to the diagram that owns this node, which allows the node to access diagram-level information and functionality.
|
|
165
|
+
* This is typically set when the node is added to a diagram but not serialized.
|
|
166
|
+
*/
|
|
167
|
+
owner: IDiagram;
|
|
168
|
+
/**
|
|
169
|
+
* The points that define the geometry of the node, which can be used for rendering and for determining how connections attach to the node.
|
|
170
|
+
*/
|
|
171
|
+
points: IPoint[];
|
|
172
|
+
/**
|
|
173
|
+
* The text content of the node, which can be displayed within the node's bounding box.
|
|
174
|
+
*/
|
|
175
|
+
text?: string;
|
|
176
|
+
/**
|
|
177
|
+
* The horizontal alignment of the text within the node, which can be left-aligned, centered, or right-aligned.
|
|
178
|
+
*/
|
|
179
|
+
textAlign?: ITextAlign;
|
|
180
|
+
/**
|
|
181
|
+
* The vertical alignment of the text within the node, which can be top-aligned, middle-aligned, or bottom-aligned.
|
|
182
|
+
*/
|
|
183
|
+
textBaseline?: ITextBaseline;
|
|
184
|
+
/**
|
|
185
|
+
* The font used for the node's text, which can include font family, size, weight, and other CSS font properties.
|
|
186
|
+
*/
|
|
187
|
+
font?: string;
|
|
188
|
+
/**
|
|
189
|
+
* The ID of the image source stored in the diagram-level image_assets dictionary.
|
|
190
|
+
*/
|
|
191
|
+
image_id?: string;
|
|
192
|
+
/**
|
|
193
|
+
* The mode for rendering the image within the node, which can be:
|
|
194
|
+
* - 'pattern' to fill the node with a repeating pattern of the image,
|
|
195
|
+
* - 'frame' to draw the image once within the node's bounding box, or
|
|
196
|
+
* - 'none' to not render the image at all.
|
|
197
|
+
*/
|
|
198
|
+
img_mode?: 'pattern' | 'frame' | 'none';
|
|
199
|
+
/**
|
|
200
|
+
* Indicates whether the node is ready to be rendered, which can be used to control the creation process
|
|
201
|
+
* and ensure that all necessary information is available before finalizing creation.
|
|
202
|
+
*/
|
|
203
|
+
ready?: boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Indicates whether the whole area of the node is selectable or only its border.
|
|
206
|
+
*/
|
|
207
|
+
hollow?: boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Indicates whether the node is transparent, which can be used to control the rendering style of the node.
|
|
210
|
+
*/
|
|
211
|
+
transparent?: boolean;
|
|
212
|
+
/**
|
|
213
|
+
* The stroke style of the node, which can be used to control the color and pattern of the node's border.
|
|
214
|
+
*/
|
|
215
|
+
strokeStyle: string;
|
|
216
|
+
/**
|
|
217
|
+
* The fill style of the node, which can be used to control the color and pattern of the node's interior.
|
|
218
|
+
*/
|
|
219
|
+
fillStyle?: string;
|
|
220
|
+
/**
|
|
221
|
+
* The text color of the node, which can be used to control the color of the text displayed within the node.
|
|
222
|
+
*/
|
|
223
|
+
textColor?: string;
|
|
224
|
+
/**
|
|
225
|
+
* The line width of the node's border, which can be used to control the thickness of the node's outline.
|
|
226
|
+
*/
|
|
227
|
+
lineWidth?: number;
|
|
228
|
+
arrow?: 'forward' | 'backward' | 'both' | 'none';
|
|
229
|
+
/**
|
|
230
|
+
* The shadow style of the node, which can be used to apply a shadow effect to the node.
|
|
231
|
+
*/
|
|
232
|
+
shadowStyle?: ShadowStyle;
|
|
233
|
+
/**
|
|
234
|
+
* The rotation angle of the node, which can be used to rotate the node around its center.
|
|
235
|
+
*/
|
|
236
|
+
angle?: number;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* IConnectionAnchor defines the properties of an anchor point for a connection, including the node it is attached to, the handle of the node,
|
|
240
|
+
* and optional properties for specifying the exact point on the node where the connection should attach (such as a specific point index or offsets).
|
|
241
|
+
* This interface is used to determine how connections are anchored to nodes in the diagram,
|
|
242
|
+
* allowing for flexible connection points based on the node's geometry and the desired connection style.
|
|
243
|
+
*/
|
|
244
|
+
interface IConnectionAnchor {
|
|
245
|
+
/**
|
|
246
|
+
* The node to which the connection anchor is attached, specified by either the node's ID or a reference to the INode object.
|
|
247
|
+
*/
|
|
248
|
+
node: string | INode;
|
|
249
|
+
/**
|
|
250
|
+
* The handle of the node that the connection is anchored to, which indicates the specific part of the node (e.g., 'n', 's', 'e', 'w', etc.) where the connection should attach.
|
|
251
|
+
*/
|
|
252
|
+
handle: NodeHandle;
|
|
253
|
+
/**
|
|
254
|
+
* An optional index specifying a particular point on the node's geometry to anchor to, allowing for more precise connection points beyond just the handles.
|
|
255
|
+
*/
|
|
256
|
+
point?: number;
|
|
257
|
+
/**
|
|
258
|
+
* Optional pixel offsets that can be applied to the anchor point, providing additional control over the exact position of the connection attachment on the node.
|
|
259
|
+
*/
|
|
260
|
+
xOffset?: number;
|
|
261
|
+
/**
|
|
262
|
+
* Optional pixel offsets that can be applied to the anchor point, providing additional control over the exact position of the connection attachment on the node.
|
|
263
|
+
*/
|
|
264
|
+
yOffset?: number;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* The IConnection interface defines the properties of a connection between nodes in the diagram, including the source and target anchors, arrow styles, and readiness state.
|
|
268
|
+
* It represents the relationships between nodes and is used to determine how nodes are connected and rendered in the diagram.
|
|
269
|
+
*/
|
|
270
|
+
interface IConnection {
|
|
271
|
+
/**
|
|
272
|
+
* The source anchor of the connection, which specifies where the connection starts on the source node. It includes information about the node, handle, and optional offsets.
|
|
273
|
+
*/
|
|
274
|
+
from?: IConnectionAnchor;
|
|
275
|
+
/**
|
|
276
|
+
* The target anchor of the connection, which specifies where the connection ends on the target node. It includes information about the node, handle, and optional offsets.
|
|
277
|
+
*/
|
|
278
|
+
to?: IConnectionAnchor;
|
|
279
|
+
/**
|
|
280
|
+
* An optional boolean indicating whether the connection should have an arrow at the starting point, which can be used to indicate directionality of the connection.
|
|
281
|
+
*/
|
|
282
|
+
startArrow?: boolean;
|
|
283
|
+
/**
|
|
284
|
+
* An optional boolean indicating whether the connection should have an arrow at the ending point, which can be used to indicate directionality of the connection.
|
|
285
|
+
*/
|
|
286
|
+
endArrow?: boolean;
|
|
287
|
+
/**
|
|
288
|
+
* An optional boolean indicating whether the connection is ready to be rendered, which can be used to control the rendering process
|
|
289
|
+
* and ensure that all necessary information is available before drawing the connection.
|
|
290
|
+
*/
|
|
291
|
+
ready?: boolean;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* The ILayer interface defines the properties of a layer in the diagram, including its ID, name, visibility, and the nodes it contains.
|
|
295
|
+
*/
|
|
296
|
+
interface ILayer {
|
|
297
|
+
/**
|
|
298
|
+
* The unique identifier of the layer.
|
|
299
|
+
*/
|
|
300
|
+
id: string;
|
|
301
|
+
/**
|
|
302
|
+
* The name of the layer.
|
|
303
|
+
*/
|
|
304
|
+
name: string;
|
|
305
|
+
/**
|
|
306
|
+
* A boolean indicating whether the layer is visible.
|
|
307
|
+
*/
|
|
308
|
+
visible: boolean;
|
|
309
|
+
/**
|
|
310
|
+
* An array of node IDs that belong to this layer.
|
|
311
|
+
*/
|
|
312
|
+
nodes: string[];
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* The IGrid interface defines the properties of the grid used in the diagram.
|
|
316
|
+
* It includes options for forcing nodes to snap to the grid, toggling grid visibility, and customizing the grid's color and cell size.
|
|
317
|
+
*/
|
|
318
|
+
interface IGrid {
|
|
319
|
+
/**
|
|
320
|
+
* A boolean indicating whether nodes should be forced to snap to the grid, which can help maintain alignment and consistency in the diagram layout.
|
|
321
|
+
*/
|
|
322
|
+
forced: boolean;
|
|
323
|
+
/**
|
|
324
|
+
* A boolean indicating whether the grid should be visible, which can assist users in aligning nodes and understanding the spatial relationships in the diagram.
|
|
325
|
+
*/
|
|
326
|
+
visible: boolean;
|
|
327
|
+
/**
|
|
328
|
+
* The color of the grid lines, which can be customized to improve visibility or match the overall design of the diagram.
|
|
329
|
+
*/
|
|
330
|
+
color: string;
|
|
331
|
+
/**
|
|
332
|
+
* The size of the grid cells in pixels, which determines the spacing of the grid lines and can affect how nodes snap to the grid.
|
|
333
|
+
*/
|
|
334
|
+
/**
|
|
335
|
+
* The width of the grid cell in pixels.
|
|
336
|
+
*/
|
|
337
|
+
width: number;
|
|
338
|
+
/**
|
|
339
|
+
* The height of the grid cell in pixels.
|
|
340
|
+
*/
|
|
341
|
+
height: number;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* IDiagram defines the main interface for a diagram, which includes nodes, layers, and a grid.
|
|
345
|
+
* It also includes methods for managing nodes and layers, as well as serialization and deserialization of the diagram.
|
|
346
|
+
* The diagram serves as the central data structure that holds all the information about the nodes, layers, and their relationships.
|
|
347
|
+
*/
|
|
348
|
+
interface IDiagram extends Serializable {
|
|
349
|
+
id: string;
|
|
350
|
+
nodes: INode[];
|
|
351
|
+
layers: ILayer[];
|
|
352
|
+
meta?: Record<string, unknown>;
|
|
353
|
+
grid: IGrid;
|
|
354
|
+
node(id: string): INode | undefined;
|
|
355
|
+
upsertNode(node: INode): INode;
|
|
356
|
+
deleteNode(id: string): void;
|
|
357
|
+
layer(id: string): ILayer | undefined;
|
|
358
|
+
upsertLayer(layer: string | ILayer): ILayer;
|
|
359
|
+
deleteLayer(id: string): void;
|
|
360
|
+
setNodeImageSource(node: string | INode, imageSrc: string, mode?: 'pattern' | 'frame', imageId?: string): INode | undefined;
|
|
361
|
+
setNodeSvgSource(node: string | INode, svgOrSrc: string, mode?: 'pattern' | 'frame', imageId?: string): INode | undefined;
|
|
362
|
+
clearNodeImageSource(node: string | INode): INode | undefined;
|
|
363
|
+
resolveNodeImageSource(node: string | INode): string | undefined;
|
|
364
|
+
destroy(): void;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Payload for selection change events, which includes the currently selected nodes and their IDs.
|
|
368
|
+
*/
|
|
369
|
+
interface HasSelection {
|
|
370
|
+
selection(): INode[];
|
|
371
|
+
isSelected(node: INode): boolean;
|
|
372
|
+
select(node: INode): void;
|
|
373
|
+
deselect(node: INode): void;
|
|
374
|
+
clearSelection(): void;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
type DiagramExportFormat = 'json' | 'bytes' | 'blob';
|
|
378
|
+
interface DiagramSaveOptions {
|
|
379
|
+
path?: string;
|
|
380
|
+
fileName?: string;
|
|
381
|
+
serializer?: ISerializer;
|
|
382
|
+
pretty?: boolean;
|
|
383
|
+
mimeType?: string;
|
|
384
|
+
}
|
|
385
|
+
type BrowserImageMimeType = 'image/png' | 'image/jpeg' | 'image/webp' | 'image/avif';
|
|
386
|
+
type BrowserImageSource = HTMLCanvasElement | {
|
|
387
|
+
canvas: HTMLCanvasElement;
|
|
388
|
+
};
|
|
389
|
+
interface ImageWriteOptions {
|
|
390
|
+
mimeType?: BrowserImageMimeType;
|
|
391
|
+
quality?: number;
|
|
392
|
+
padding?: number;
|
|
393
|
+
}
|
|
394
|
+
interface ImageSaveOptions extends ImageWriteOptions {
|
|
395
|
+
path?: string;
|
|
396
|
+
fileName?: string;
|
|
397
|
+
}
|
|
398
|
+
interface ImageSerializer {
|
|
399
|
+
write(source: BrowserImageSource, options?: ImageWriteOptions): Promise<Blob>;
|
|
400
|
+
}
|
|
401
|
+
type DiagramOpenSource = string | ISerializedDiagram | Diagram;
|
|
402
|
+
interface DiagramOpenOptions {
|
|
403
|
+
source?: DiagramOpenSource;
|
|
404
|
+
}
|
|
405
|
+
interface DiagramOpenResult {
|
|
406
|
+
source: DiagramOpenSource;
|
|
407
|
+
handle?: FileSystemFileHandle;
|
|
408
|
+
}
|
|
409
|
+
interface DiagramSaveResult extends DiagramSaveOptions {
|
|
410
|
+
handle?: FileSystemFileHandle;
|
|
411
|
+
}
|
|
412
|
+
interface DiagramExportOptions {
|
|
413
|
+
format?: DiagramExportFormat;
|
|
414
|
+
pretty?: boolean;
|
|
415
|
+
serializer?: ISerializer;
|
|
416
|
+
fileName?: string;
|
|
417
|
+
mimeType?: string;
|
|
418
|
+
}
|
|
419
|
+
interface DiagramExportResult extends DiagramExportOptions {
|
|
420
|
+
handle?: FileSystemFileHandle;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* A diagram is the core data structure that holds all nodes, layers, and metadata.
|
|
425
|
+
* It provides methods for managing these elements and supports serialization and deserialization for persistence and data exchange.
|
|
426
|
+
*
|
|
427
|
+
* It does not support viewing. For that, use DiagramView which extends this base model and adds rendering, selection, and interaction capabilities.
|
|
428
|
+
* It does not support editing. For that, use DiagramController which manages user interactions and updates the Diagram model accordingly.
|
|
429
|
+
*/
|
|
430
|
+
declare class Diagram implements IDiagram {
|
|
431
|
+
id: string;
|
|
432
|
+
nodes: INode[];
|
|
433
|
+
layers: ILayer[];
|
|
434
|
+
meta?: Record<string, any>;
|
|
435
|
+
grid: IGrid;
|
|
436
|
+
private readonly assetStore;
|
|
437
|
+
get image_assets(): Record<string, string>;
|
|
438
|
+
constructor(id: string, initial?: Partial<Omit<Diagram, 'id'>>);
|
|
439
|
+
/**
|
|
440
|
+
* Releases model-managed resources.
|
|
441
|
+
*/
|
|
442
|
+
destroy(): void;
|
|
443
|
+
/**
|
|
444
|
+
* Retrieves a node by its ID.
|
|
445
|
+
* @param id The ID of the node to retrieve.
|
|
446
|
+
* @returns The node with the specified ID, or undefined if not found.
|
|
447
|
+
*/
|
|
448
|
+
node(id: string): INode | undefined;
|
|
449
|
+
/**
|
|
450
|
+
* Retrieves a layer by its ID.
|
|
451
|
+
* @param id The ID of the layer to retrieve.
|
|
452
|
+
* @returns The layer with the specified ID, or undefined if not found.
|
|
453
|
+
*/
|
|
454
|
+
layer(id: string): ILayer | undefined;
|
|
455
|
+
/**
|
|
456
|
+
* Inserts a new node or updates an existing node in the diagram.
|
|
457
|
+
* @param node The node to upsert.
|
|
458
|
+
* @returns The upserted node.
|
|
459
|
+
*/
|
|
460
|
+
upsertNode(node: INode): INode;
|
|
461
|
+
/**
|
|
462
|
+
* Inserts a new layer or updates an existing layer in the diagram.
|
|
463
|
+
* @param layer The layer to upsert, or the ID of the layer to create.
|
|
464
|
+
* @returns The upserted layer.
|
|
465
|
+
*/
|
|
466
|
+
upsertLayer(layer: string | ILayer): ILayer;
|
|
467
|
+
/**
|
|
468
|
+
* Deletes a node from the diagram.
|
|
469
|
+
* @param nodeId The ID of the node to delete.
|
|
470
|
+
*/
|
|
471
|
+
deleteNode(nodeId: string): void;
|
|
472
|
+
/**
|
|
473
|
+
* Deletes a layer from the diagram.
|
|
474
|
+
* @param layerId The ID of the layer to delete.
|
|
475
|
+
*/
|
|
476
|
+
deleteLayer(layerId: string): void;
|
|
477
|
+
/**
|
|
478
|
+
* Assigns an image source to a node for background/content rendering.
|
|
479
|
+
*/
|
|
480
|
+
setNodeImageSource(node: string | INode, imageSrc: string, mode?: 'pattern' | 'frame', imageId?: string): INode | undefined;
|
|
481
|
+
/**
|
|
482
|
+
* Assigns SVG markup or SVG source URL/data URL to a node.
|
|
483
|
+
* Raw SVG markup is converted to a data URL.
|
|
484
|
+
*/
|
|
485
|
+
setNodeSvgSource(node: string | INode, svgOrSrc: string, mode?: 'pattern' | 'frame', imageId?: string): INode | undefined;
|
|
486
|
+
/**
|
|
487
|
+
* Removes image source and rendering mode from a node.
|
|
488
|
+
*/
|
|
489
|
+
clearNodeImageSource(node: string | INode): INode | undefined;
|
|
490
|
+
/**
|
|
491
|
+
* Resolves the concrete image source for a node image reference.
|
|
492
|
+
*/
|
|
493
|
+
resolveNodeImageSource(node: string | INode): string | undefined;
|
|
494
|
+
/**
|
|
495
|
+
* Clears all in-memory image assets. Intended for teardown paths.
|
|
496
|
+
*/
|
|
497
|
+
clearImageAssets(): void;
|
|
498
|
+
/**
|
|
499
|
+
* Clears all nodes, layers, metadata, and assets from the diagram, effectively resetting it to an empty state while retaining the same ID.
|
|
500
|
+
* Intended for reuse scenarios where the diagram instance should be preserved but its content should be cleared.
|
|
501
|
+
*/
|
|
502
|
+
clear(): void;
|
|
503
|
+
/**
|
|
504
|
+
* Loads the diagram data from a serialized JSON object.
|
|
505
|
+
* @param source The serialized diagram data.
|
|
506
|
+
* @param serializer The serializer to use for reading the data (optional if source is already an object).
|
|
507
|
+
* @returns The diagram instance.
|
|
508
|
+
* @throws An error if the input is an invalid JSON string or if the parsed JSON is null or undefined.
|
|
509
|
+
*/
|
|
510
|
+
read(source: string | ISerializedDiagram, serializer?: ISerializer): Promise<this>;
|
|
511
|
+
/**
|
|
512
|
+
* Writes the diagram data to the specified serializer.
|
|
513
|
+
* @param serializer The serializer to use for writing the data.
|
|
514
|
+
* @returns The serialized diagram data.
|
|
515
|
+
*/
|
|
516
|
+
write(serializer: ISerializer): any;
|
|
517
|
+
/**
|
|
518
|
+
* Exports the current diagram in a native format.
|
|
519
|
+
* Supported formats are JSON text, UTF-8 bytes, and Blob (browser runtime).
|
|
520
|
+
* @param format The format to export the diagram in ('json', 'bytes', or 'blob'). (defaults to 'json')
|
|
521
|
+
* @param pretty Whether to pretty-print the output (applicable to JSON format). (defaults to true)
|
|
522
|
+
* @param serializer The serializer to use for exporting the diagram. (optional)
|
|
523
|
+
* @returns The exported diagram data in the specified format.
|
|
524
|
+
*/
|
|
525
|
+
export(format?: DiagramExportFormat, pretty?: boolean, serializer?: ISerializer): string | Uint8Array | Blob;
|
|
526
|
+
/**
|
|
527
|
+
* Saves the current diagram directly from the model.
|
|
528
|
+
* In Node.js this writes to the file system; in browsers this triggers a file download.
|
|
529
|
+
* @param options The options for saving the diagram, including path, file name, serializer, pretty-printing, and MIME type.
|
|
530
|
+
* @returns A promise that resolves to the path or download URL of the saved file.
|
|
531
|
+
*/
|
|
532
|
+
save(options?: DiagramSaveOptions): Promise<string>;
|
|
533
|
+
private toJsonString;
|
|
534
|
+
private resolveNode;
|
|
535
|
+
private toSvgSource;
|
|
536
|
+
protected applyNodeImageSource(target: INode, imageSrc: string, mode?: 'pattern' | 'frame', imageId?: string): void;
|
|
537
|
+
/**
|
|
538
|
+
* Returns all nodes within the specified layer.
|
|
539
|
+
* @param layer The layer whose nodes should be returned.
|
|
540
|
+
* @returns An array of nodes within the specified layer.
|
|
541
|
+
*/
|
|
542
|
+
protected layerNodes(layer: ILayer): INode[];
|
|
543
|
+
protected serializeNode(node: INode): ISerializedNode;
|
|
544
|
+
private hydrateNode;
|
|
545
|
+
private hydrateLayer;
|
|
546
|
+
/**
|
|
547
|
+
* Creates a new layer with the specified properties.
|
|
548
|
+
* @param id The ID of the layer.
|
|
549
|
+
* @param name The name of the layer.
|
|
550
|
+
* @param visible Whether the layer is visible.
|
|
551
|
+
* @param nodes The nodes within the layer.
|
|
552
|
+
* @returns The created layer.
|
|
553
|
+
*/
|
|
554
|
+
protected createLayer(id: string, name?: string, visible?: boolean, nodes?: string[]): ILayer;
|
|
555
|
+
private serializeAnchor;
|
|
556
|
+
private hydrateAnchor;
|
|
557
|
+
private anchorTargetsNode;
|
|
558
|
+
private pruneMissingLayerNodes;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Detects whether browser globals are available.
|
|
563
|
+
* @returns True when running in a browser-like runtime.
|
|
564
|
+
*/
|
|
565
|
+
declare function isBrowserRuntime(): boolean;
|
|
566
|
+
/**
|
|
567
|
+
* Creates an offscreen 2D canvas with safe minimum dimensions.
|
|
568
|
+
* @param width Requested width.
|
|
569
|
+
* @param height Requested height.
|
|
570
|
+
* @returns A canvas/context pair.
|
|
571
|
+
*/
|
|
572
|
+
declare function createCanvas2D(width: number, height: number): {
|
|
573
|
+
canvas: HTMLCanvasElement;
|
|
574
|
+
context: CanvasRenderingContext2D;
|
|
575
|
+
};
|
|
576
|
+
/**
|
|
577
|
+
* Resolves a canvas from either a raw canvas or an object containing one.
|
|
578
|
+
* @param source Canvas source value.
|
|
579
|
+
* @returns The underlying HTMLCanvasElement.
|
|
580
|
+
*/
|
|
581
|
+
declare function unwrapCanvas(source: HTMLCanvasElement | {
|
|
582
|
+
canvas: HTMLCanvasElement;
|
|
583
|
+
}): HTMLCanvasElement;
|
|
584
|
+
/**
|
|
585
|
+
* Checks whether a canvas encoder supports a given MIME type.
|
|
586
|
+
* @param canvas Source canvas.
|
|
587
|
+
* @param mimeType MIME type to test.
|
|
588
|
+
* @returns True when the MIME type is supported.
|
|
589
|
+
*/
|
|
590
|
+
declare function supportsCanvasMimeType(canvas: HTMLCanvasElement, mimeType: string): boolean;
|
|
591
|
+
/**
|
|
592
|
+
* Lists supported export MIME types for a canvas.
|
|
593
|
+
* @param canvas Source canvas.
|
|
594
|
+
* @returns Supported MIME types.
|
|
595
|
+
*/
|
|
596
|
+
declare function supportedCanvasMimeTypes(canvas: HTMLCanvasElement): string[];
|
|
597
|
+
/**
|
|
598
|
+
* Exports a canvas to a data URL.
|
|
599
|
+
* @param canvas Source canvas.
|
|
600
|
+
* @param mimeType Target MIME type.
|
|
601
|
+
* @param quality Optional quality for lossy formats.
|
|
602
|
+
* @returns Encoded data URL.
|
|
603
|
+
*/
|
|
604
|
+
declare function canvasToDataUrl(canvas: HTMLCanvasElement, mimeType: string, quality?: number): string;
|
|
605
|
+
/**
|
|
606
|
+
* Exports a canvas to a Blob.
|
|
607
|
+
* @param canvas Source canvas.
|
|
608
|
+
* @param mimeType Target MIME type.
|
|
609
|
+
* @param quality Optional quality for lossy formats.
|
|
610
|
+
* @returns A Blob containing the encoded image.
|
|
611
|
+
*/
|
|
612
|
+
declare function canvasToBlob(canvas: HTMLCanvasElement, mimeType: string, quality?: number): Promise<Blob>;
|
|
613
|
+
/**
|
|
614
|
+
* Creates a text blob for export/download operations.
|
|
615
|
+
* @param content Text content.
|
|
616
|
+
* @param mimeType Blob MIME type.
|
|
617
|
+
* @returns The generated Blob.
|
|
618
|
+
*/
|
|
619
|
+
declare function exportTextBlob(content: string, mimeType?: string): Blob;
|
|
620
|
+
/**
|
|
621
|
+
* Downloads text content as a file in browser runtimes.
|
|
622
|
+
* @param content File content.
|
|
623
|
+
* @param fileName Download file name.
|
|
624
|
+
* @param mimeType File MIME type.
|
|
625
|
+
* @returns The file name used for download.
|
|
626
|
+
*/
|
|
627
|
+
declare function downloadTextFile(content: string, fileName: string, mimeType?: string): string;
|
|
628
|
+
/**
|
|
629
|
+
* Downloads an existing blob as a file in browser runtimes.
|
|
630
|
+
* @param blob Blob to download.
|
|
631
|
+
* @param fileName Download file name.
|
|
632
|
+
* @returns The file name used for download.
|
|
633
|
+
*/
|
|
634
|
+
declare function downloadBlob(blob: Blob, fileName: string): string;
|
|
635
|
+
/**
|
|
636
|
+
* Writes a blob to a browser file-system access handle.
|
|
637
|
+
* @param handle Target browser file handle.
|
|
638
|
+
* @param blob Blob payload to write.
|
|
639
|
+
* @returns The written file name.
|
|
640
|
+
*/
|
|
641
|
+
declare function writeBlobToFileHandle(handle: FileSystemFileHandle, blob: Blob): Promise<string>;
|
|
642
|
+
/**
|
|
643
|
+
* Writes text content to a browser file-system access handle.
|
|
644
|
+
* @param handle Target browser file handle.
|
|
645
|
+
* @param content Text payload to write.
|
|
646
|
+
* @param mimeType Optional MIME type.
|
|
647
|
+
* @returns The written file name.
|
|
648
|
+
*/
|
|
649
|
+
declare function writeTextToFileHandle(handle: FileSystemFileHandle, content: string, mimeType?: string): Promise<string>;
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Detects whether the current runtime is Node.js.
|
|
653
|
+
* @returns True when Node.js APIs are available.
|
|
654
|
+
*/
|
|
655
|
+
declare function isNodeRuntime(): boolean;
|
|
656
|
+
/**
|
|
657
|
+
* Writes UTF-8 text content to a file path.
|
|
658
|
+
* @param path Destination path.
|
|
659
|
+
* @param content Text content.
|
|
660
|
+
* @returns The written path.
|
|
661
|
+
*/
|
|
662
|
+
declare function writeTextFile(path: string, content: string): Promise<string>;
|
|
663
|
+
/**
|
|
664
|
+
* Writes binary content to a file path.
|
|
665
|
+
* @param path Destination path.
|
|
666
|
+
* @param content Binary payload.
|
|
667
|
+
* @returns The written path.
|
|
668
|
+
*/
|
|
669
|
+
declare function writeBinaryFile(path: string, content: Uint8Array): Promise<string>;
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Serializes browser canvas content to raster image blobs.
|
|
673
|
+
* Supports PNG/JPEG/WebP/AVIF and falls back to PNG if the requested format is unsupported.
|
|
674
|
+
*/
|
|
675
|
+
declare class CanvasImageSerializer implements ImageSerializer {
|
|
676
|
+
/**
|
|
677
|
+
* Serializes the given canvas or canvas wrapper to a Blob.
|
|
678
|
+
* @param source The source canvas or an object containing a canvas.
|
|
679
|
+
* @param options Optional image write options, including MIME type and quality.
|
|
680
|
+
* @returns A promise that resolves to a Blob representing the serialized image.
|
|
681
|
+
*/
|
|
682
|
+
write(source: HTMLCanvasElement | {
|
|
683
|
+
canvas: HTMLCanvasElement;
|
|
684
|
+
}, options?: ImageWriteOptions): Promise<Blob>;
|
|
685
|
+
private resolveMimeType;
|
|
686
|
+
private normalizeQuality;
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Convenience PNG-only serializer.
|
|
690
|
+
*/
|
|
691
|
+
declare class PngSerializer extends CanvasImageSerializer {
|
|
692
|
+
write(source: HTMLCanvasElement | {
|
|
693
|
+
canvas: HTMLCanvasElement;
|
|
694
|
+
}): Promise<Blob>;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
type DiagramOpenHandler = (options?: DiagramOpenOptions) => Promise<DiagramOpenResult | undefined> | DiagramOpenResult | undefined;
|
|
698
|
+
type DiagramSaveHandler = (options?: DiagramSaveOptions) => Promise<DiagramSaveResult | undefined> | DiagramSaveResult | undefined;
|
|
699
|
+
type DiagramExportHandler = (options?: DiagramExportOptions) => Promise<DiagramExportResult | undefined> | DiagramExportResult | undefined;
|
|
700
|
+
declare class DiagramFileDialogs {
|
|
701
|
+
onOpenDiagram?: DiagramOpenHandler;
|
|
702
|
+
onSaveDiagram?: DiagramSaveHandler;
|
|
703
|
+
onExportDiagram?: DiagramExportHandler;
|
|
704
|
+
openDiagram(options?: DiagramOpenOptions): Promise<DiagramOpenResult | undefined>;
|
|
705
|
+
saveDiagram(options?: DiagramSaveOptions): Promise<DiagramSaveResult | undefined>;
|
|
706
|
+
exportDiagram(options?: DiagramExportOptions): Promise<DiagramExportResult | undefined>;
|
|
707
|
+
openDiagramDefault(): Promise<DiagramOpenResult | undefined>;
|
|
708
|
+
saveDiagramDefault(options?: DiagramSaveOptions): Promise<DiagramSaveResult | undefined>;
|
|
709
|
+
exportDiagramDefault(options?: DiagramExportOptions): Promise<DiagramExportResult | undefined>;
|
|
710
|
+
private openFromBrowserDialog;
|
|
711
|
+
private resolveSaveTarget;
|
|
712
|
+
private extensionFor;
|
|
713
|
+
private defaultExportFileName;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
/**
|
|
717
|
+
* Serializes and deserializes data to and from JSON format.
|
|
718
|
+
*/
|
|
719
|
+
declare class JsonSerializer implements ISerializer {
|
|
720
|
+
/**
|
|
721
|
+
* Serializes the given data to a JSON string.
|
|
722
|
+
* @param data The data to serialize.
|
|
723
|
+
* @returns A JSON string representing the serialized data.
|
|
724
|
+
*/
|
|
725
|
+
write(data: unknown): string;
|
|
726
|
+
/**
|
|
727
|
+
* Deserializes the given JSON string to an object of type T.
|
|
728
|
+
* @param json The JSON string to deserialize.
|
|
729
|
+
* @returns A promise that resolves to an object of type T.
|
|
730
|
+
*/
|
|
731
|
+
read<T>(json: string): Promise<T>;
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* The default JSON serializer instance for use in the application.
|
|
735
|
+
* This can be imported conveniently and used wherever JSON serialization or deserialization is needed.
|
|
736
|
+
*/
|
|
737
|
+
declare const jsonSerializer: JsonSerializer;
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* View events.
|
|
741
|
+
*/
|
|
742
|
+
declare const DIAGRAM_SELECTION_EVENT = "selection";
|
|
743
|
+
declare const DIAGRAM_NODE_CLICK_EVENT = "node-click";
|
|
744
|
+
declare const DIAGRAM_BACKGROUND_CLICK_EVENT = "background-click";
|
|
745
|
+
declare const DIAGRAM_VIEWPORT_EVENT = "viewport-change";
|
|
746
|
+
/**
|
|
747
|
+
* EditView events.
|
|
748
|
+
*/
|
|
749
|
+
declare const DIAGRAM_DELETE_REQUEST_EVENT = "delete-request";
|
|
750
|
+
declare const DIAGRAM_NODE_ADDED_EVENT = "node-added";
|
|
751
|
+
declare const DIAGRAM_NODE_DELETED_EVENT = "node-deleted";
|
|
752
|
+
declare const DIAGRAM_NODE_MOVED_EVENT = "node-moved";
|
|
753
|
+
declare const DIAGRAM_NODE_RESIZED_EVENT = "node-resized";
|
|
754
|
+
declare const DIAGRAM_NODE_POINTS_CHANGED_EVENT = "node-points-changed";
|
|
755
|
+
declare const DIAGRAM_CONNECTION_CONNECTED_EVENT = "connection-connected";
|
|
756
|
+
declare const DIAGRAM_CONNECTION_DISCONNECTED_EVENT = "connection-disconnected";
|
|
757
|
+
declare const DIAGRAM_EDIT_CONTEXT_MENU_EVENT = "diagram-edit-contextmenu";
|
|
758
|
+
declare const DIAGRAM_TOOL_CHANGED_EVENT = "tool-changed";
|
|
759
|
+
declare const DIAGRAM_CLIPBOARD_EVENT = "clipboard-change";
|
|
760
|
+
/**
|
|
761
|
+
* Broad compatibility event.
|
|
762
|
+
*/
|
|
763
|
+
declare const DIAGRAM_CHANGED_EVENT = "diagram-changed";
|
|
764
|
+
/**
|
|
765
|
+
* Defines the scope of a diagram change, which can be related to the model, view, or style of the diagram.
|
|
766
|
+
* This categorization allows for more specific handling of changes and updates within the diagram system,
|
|
767
|
+
* enabling developers to optimize performance and user experience by responding appropriately to different types of changes.
|
|
768
|
+
*/
|
|
769
|
+
type DiagramChangeScope = 'model' | 'view' | 'style';
|
|
770
|
+
/**
|
|
771
|
+
* Represents a change in the diagram, including the scope of the change and the source event that triggered it.
|
|
772
|
+
* This interface can be used to provide detailed information about changes occurring in the diagram, allowing for more granular handling of updates and interactions.
|
|
773
|
+
*/
|
|
774
|
+
interface DiagramChanged {
|
|
775
|
+
scope: DiagramChangeScope;
|
|
776
|
+
sourceEvent: string;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Defines the structure of a diagram selection change event, which includes information about the selected nodes and their IDs.
|
|
780
|
+
* This interface can be used to provide detailed information about selection changes in the diagram, allowing for more specific handling of selection-related interactions and updates.
|
|
781
|
+
*/
|
|
782
|
+
interface DiagramSelectionChange {
|
|
783
|
+
/**
|
|
784
|
+
* The node that is currently selected, if any. This property may be undefined if no single node is selected or if multiple nodes are selected.
|
|
785
|
+
*/
|
|
786
|
+
node?: INode;
|
|
787
|
+
/**
|
|
788
|
+
* The ID of the node that is currently selected, if any. This property may be undefined if no single node is selected or if multiple nodes are selected.
|
|
789
|
+
*/
|
|
790
|
+
nodeId?: string;
|
|
791
|
+
/**
|
|
792
|
+
* The nodes that are currently selected. This array may be empty if no nodes are selected.
|
|
793
|
+
*/
|
|
794
|
+
nodes: INode[];
|
|
795
|
+
/**
|
|
796
|
+
* The IDs of the nodes that are currently selected. This array may be empty if no nodes are selected.
|
|
797
|
+
*/
|
|
798
|
+
nodeIds: string[];
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* Defines the structure of a diagram background click event, which includes the coordinates of the click in both canvas and world space.
|
|
802
|
+
* This interface can be used to provide detailed information about background click interactions in the diagram,
|
|
803
|
+
* allowing for more specific handling of such events, such as deselecting nodes or opening context menus.
|
|
804
|
+
*/
|
|
805
|
+
interface DiagramBackgroundClick {
|
|
806
|
+
/**
|
|
807
|
+
* The coordinates of the click in canvas space, which represents the position of the click relative to the diagram's viewport.
|
|
808
|
+
*/
|
|
809
|
+
canvas: IPoint;
|
|
810
|
+
/**
|
|
811
|
+
* The coordinates of the click in world space, which represents the position of the click in the diagram's coordinate system,
|
|
812
|
+
* taking into account any transformations such as panning and zooming.
|
|
813
|
+
*/
|
|
814
|
+
world: IPoint;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Defines the structure of a diagram viewport change event, which includes information about the pan and zoom levels of the diagram's viewport.
|
|
818
|
+
* This interface can be used to provide detailed information about changes to the diagram's viewport, allowing for more specific handling of such events,
|
|
819
|
+
* such as updating the display or synchronizing with other components.
|
|
820
|
+
*/
|
|
821
|
+
interface DiagramViewportChange {
|
|
822
|
+
/**
|
|
823
|
+
* The pan offset of the diagram's viewport, represented as an object with x and y properties.
|
|
824
|
+
* This indicates how much the viewport has been panned from its original position.
|
|
825
|
+
*/
|
|
826
|
+
pan: IPoint;
|
|
827
|
+
/**
|
|
828
|
+
* The zoom level of the diagram's viewport, represented as a number.
|
|
829
|
+
* This indicates how much the viewport has been zoomed in or out from its original scale.
|
|
830
|
+
* A zoom level of 1 typically represents the original scale, while values greater than 1 indicate zooming in and values less than 1 indicate zooming out.
|
|
831
|
+
*/
|
|
832
|
+
zoom: number;
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* Defines the structure of a diagram node change event, which includes information about the node that has changed and its ID.
|
|
836
|
+
* This interface can be used to provide detailed information about changes to nodes in the diagram, allowing for more specific handling of such events,
|
|
837
|
+
* such as updating the display or synchronizing with other components.
|
|
838
|
+
*/
|
|
839
|
+
interface DiagramNodeChange {
|
|
840
|
+
/**
|
|
841
|
+
* The node that has changed. This property may be undefined if the change is not related to a specific node or if the node information is not available.
|
|
842
|
+
*/
|
|
843
|
+
node: INode;
|
|
844
|
+
/**
|
|
845
|
+
* The ID of the node that has changed. This property may be undefined if the change is not related to a specific node or if the node information is not available.
|
|
846
|
+
*/
|
|
847
|
+
nodeId: string;
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Defines the structure of a diagram delete request event, which extends the diagram selection change event
|
|
851
|
+
* and includes an optional trigger property that represents the keyboard event that initiated the delete request.
|
|
852
|
+
* This interface can be used to provide detailed information about delete requests in the diagram, allowing for more specific handling of such events,
|
|
853
|
+
* such as confirming the delete action or performing additional cleanup.
|
|
854
|
+
*/
|
|
855
|
+
interface DiagramDeleteRequest extends DiagramSelectionChange {
|
|
856
|
+
/**
|
|
857
|
+
* The keyboard event that triggered the delete request, if applicable.
|
|
858
|
+
* This property may be undefined if the delete request was not initiated by a keyboard event or if the event information is not available.
|
|
859
|
+
*/
|
|
860
|
+
trigger?: KeyboardEvent;
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Defines the structure of a diagram connection change event, which extends the diagram node change event and includes information about the connection's endpoints.
|
|
864
|
+
* This interface can be used to provide detailed information about changes to connections in the diagram, allowing for more specific handling of such events,
|
|
865
|
+
* such as updating the display or synchronizing with other components.
|
|
866
|
+
*/
|
|
867
|
+
interface DiagramConnectionChange extends DiagramNodeChange {
|
|
868
|
+
/**
|
|
869
|
+
* The source anchor of the connection, if applicable.
|
|
870
|
+
* This property may be undefined if the change is not related to a connection or if the anchor information is not available.
|
|
871
|
+
*/
|
|
872
|
+
from?: IConnection["from"];
|
|
873
|
+
/**
|
|
874
|
+
* The target anchor of the connection, if applicable.
|
|
875
|
+
* This property may be undefined if the change is not related to a connection or if the anchor information is not available.
|
|
876
|
+
*/
|
|
877
|
+
to?: IConnection["to"];
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Defines the structure of a diagram edit context menu event, which extends the diagram background click event and includes information about the node(s)
|
|
881
|
+
* involved in the context menu interaction.
|
|
882
|
+
*/
|
|
883
|
+
interface DiagramEditContextMenu extends DiagramBackgroundClick {
|
|
884
|
+
/**
|
|
885
|
+
* The pointer event that triggered the context menu interaction.
|
|
886
|
+
* This property provides access to the original pointer event, allowing for more specific handling of the context menu interaction,
|
|
887
|
+
*/
|
|
888
|
+
event: PointerEvent;
|
|
889
|
+
/**
|
|
890
|
+
* The node that is the target of the context menu interaction, if applicable.
|
|
891
|
+
* This property may be undefined if the context menu was triggered on the background or if the node information is not available.
|
|
892
|
+
*/
|
|
893
|
+
node?: INode;
|
|
894
|
+
/**
|
|
895
|
+
* The ID of the node that is the target of the context menu interaction, if applicable.
|
|
896
|
+
* This property may be undefined if the context menu was triggered on the background or if the node information is not available.
|
|
897
|
+
*/
|
|
898
|
+
nodeId?: string;
|
|
899
|
+
/**
|
|
900
|
+
* The nodes that are involved in the context menu interaction, if applicable.
|
|
901
|
+
* This array may be empty if the context menu was triggered on the background or if the node information is not available.
|
|
902
|
+
*/
|
|
903
|
+
nodes: INode[];
|
|
904
|
+
/**
|
|
905
|
+
* The IDs of the nodes that are involved in the context menu interaction, if applicable.
|
|
906
|
+
* This array may be empty if the context menu was triggered on the background or if the node information is not available.
|
|
907
|
+
*/
|
|
908
|
+
nodeIds: string[];
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Defines the structure of a diagram tool change event, which includes information about the new tool and the previous tool.
|
|
912
|
+
* This interface can be used to provide detailed information about tool changes in the diagram, allowing for more specific handling of such events,
|
|
913
|
+
* such as updating the display or synchronizing with other components.
|
|
914
|
+
*/
|
|
915
|
+
interface DiagramToolChange {
|
|
916
|
+
/**
|
|
917
|
+
* The new tool that has been selected or activated in the diagram.
|
|
918
|
+
* This property represents the current tool that is being used for interactions in the diagram.
|
|
919
|
+
*/
|
|
920
|
+
tool: string;
|
|
921
|
+
/**
|
|
922
|
+
* The previous tool that was active in the diagram.
|
|
923
|
+
* This property represents the tool that was being used before the current tool was selected or activated.
|
|
924
|
+
*/
|
|
925
|
+
previousTool: string;
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Clipboard operations emitted by the editor.
|
|
929
|
+
*/
|
|
930
|
+
type DiagramClipboardOperation = 'copy' | 'cut' | 'paste';
|
|
931
|
+
/**
|
|
932
|
+
* Defines the structure of a diagram clipboard event.
|
|
933
|
+
*/
|
|
934
|
+
interface DiagramClipboardEventDetail {
|
|
935
|
+
/**
|
|
936
|
+
* The clipboard operation that produced this event.
|
|
937
|
+
* Can be one of "copy", "cut", or "paste".
|
|
938
|
+
*/
|
|
939
|
+
operation: DiagramClipboardOperation;
|
|
940
|
+
/**
|
|
941
|
+
* Whether a paste action is currently possible.
|
|
942
|
+
*/
|
|
943
|
+
canPaste: boolean;
|
|
944
|
+
/**
|
|
945
|
+
* The first node involved in the operation, if any.
|
|
946
|
+
*/
|
|
947
|
+
node?: INode;
|
|
948
|
+
/**
|
|
949
|
+
* The ID of the first node involved in the operation, if any.
|
|
950
|
+
*/
|
|
951
|
+
nodeId?: string;
|
|
952
|
+
/**
|
|
953
|
+
* All nodes involved in the operation.
|
|
954
|
+
*/
|
|
955
|
+
nodes: INode[];
|
|
956
|
+
/**
|
|
957
|
+
* IDs of nodes involved in the operation.
|
|
958
|
+
*/
|
|
959
|
+
nodeIds: string[];
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* Dispatches typed diagram events from a host element and emits a companion
|
|
964
|
+
* diagram-changed event for high-level change tracking.
|
|
965
|
+
*/
|
|
966
|
+
declare class EventDispatcher {
|
|
967
|
+
private readonly host;
|
|
968
|
+
/**
|
|
969
|
+
* Creates an EventDispatcher bound to a host element.
|
|
970
|
+
* @param host The element that will emit diagram events.
|
|
971
|
+
*/
|
|
972
|
+
constructor(host: HTMLElement);
|
|
973
|
+
/**
|
|
974
|
+
* Emits the diagram selection change event.
|
|
975
|
+
* @param detail Selection payload.
|
|
976
|
+
*/
|
|
977
|
+
selectionChanged(detail: DiagramSelectionChange): void;
|
|
978
|
+
/**
|
|
979
|
+
* Emits the node-click event.
|
|
980
|
+
* @param detail Node-click payload.
|
|
981
|
+
*/
|
|
982
|
+
nodeClicked(detail: DiagramSelectionChange): void;
|
|
983
|
+
/**
|
|
984
|
+
* Emits the background-click event.
|
|
985
|
+
* @param detail Background-click payload.
|
|
986
|
+
*/
|
|
987
|
+
backgroundClicked(detail: DiagramBackgroundClick): void;
|
|
988
|
+
/**
|
|
989
|
+
* Emits the viewport-change event.
|
|
990
|
+
* @param detail Viewport payload.
|
|
991
|
+
*/
|
|
992
|
+
viewportChanged(detail: DiagramViewportChange): void;
|
|
993
|
+
/**
|
|
994
|
+
* Emits the delete-request event as cancelable.
|
|
995
|
+
* @param detail Delete-request payload.
|
|
996
|
+
* @returns True when the request was not canceled.
|
|
997
|
+
*/
|
|
998
|
+
deleteRequested(detail: DiagramDeleteRequest): boolean;
|
|
999
|
+
/**
|
|
1000
|
+
* Emits the node-added event.
|
|
1001
|
+
* @param detail Node change payload.
|
|
1002
|
+
*/
|
|
1003
|
+
nodeAdded(detail: DiagramNodeChange): void;
|
|
1004
|
+
/**
|
|
1005
|
+
* Emits the node-deleted event.
|
|
1006
|
+
* @param detail Node change payload.
|
|
1007
|
+
*/
|
|
1008
|
+
nodeDeleted(detail: DiagramNodeChange): void;
|
|
1009
|
+
/**
|
|
1010
|
+
* Emits the node-moved event.
|
|
1011
|
+
* @param detail Node change payload.
|
|
1012
|
+
*/
|
|
1013
|
+
nodeMoved(detail: DiagramNodeChange): void;
|
|
1014
|
+
/**
|
|
1015
|
+
* Emits the node-resized event.
|
|
1016
|
+
* @param detail Node change payload.
|
|
1017
|
+
*/
|
|
1018
|
+
nodeResized(detail: DiagramNodeChange): void;
|
|
1019
|
+
/**
|
|
1020
|
+
* Emits the node-points-changed event.
|
|
1021
|
+
* @param detail Node change payload.
|
|
1022
|
+
*/
|
|
1023
|
+
nodePointsChanged(detail: DiagramNodeChange): void;
|
|
1024
|
+
/**
|
|
1025
|
+
* Emits the connection-connected event.
|
|
1026
|
+
* @param detail Connection change payload.
|
|
1027
|
+
*/
|
|
1028
|
+
connectionConnected(detail: DiagramConnectionChange): void;
|
|
1029
|
+
/**
|
|
1030
|
+
* Emits the connection-disconnected event.
|
|
1031
|
+
* @param detail Connection change payload.
|
|
1032
|
+
*/
|
|
1033
|
+
connectionDisconnected(detail: DiagramConnectionChange): void;
|
|
1034
|
+
/**
|
|
1035
|
+
* Emits the diagram edit context-menu event.
|
|
1036
|
+
* @param detail Context-menu payload.
|
|
1037
|
+
*/
|
|
1038
|
+
editContextMenu(detail: DiagramEditContextMenu): void;
|
|
1039
|
+
/**
|
|
1040
|
+
* Emits the tool-changed event.
|
|
1041
|
+
* @param detail Tool-change payload.
|
|
1042
|
+
*/
|
|
1043
|
+
toolChanged(detail: DiagramToolChange): void;
|
|
1044
|
+
/**
|
|
1045
|
+
* Emits the clipboard-change event.
|
|
1046
|
+
* @param detail Clipboard payload.
|
|
1047
|
+
*/
|
|
1048
|
+
clipboardChanged(detail: DiagramClipboardEventDetail): void;
|
|
1049
|
+
private dispatchInternal;
|
|
1050
|
+
private resolveDiagramChangeScope;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
/**
|
|
1054
|
+
* Provides basic operations for manipulating nodes, such as moving, resizing, rotating, and checking for overlaps or containment.
|
|
1055
|
+
* These utilities are designed to work with nodes in a diagram editor, allowing for transformations and hit testing based on the node's geometry and the diagram's coordinate system.
|
|
1056
|
+
* The methods take into account the node's points, angle, and bounding rectangle to perform accurate calculations for movement, resizing, and selection.
|
|
1057
|
+
* This class can be used as a foundation for implementing more complex node behaviors in a diagram editing application.
|
|
1058
|
+
*/
|
|
1059
|
+
declare class NodeBasics {
|
|
1060
|
+
/**
|
|
1061
|
+
* Moves a node by the specified deltas.
|
|
1062
|
+
* @param node The node to move.
|
|
1063
|
+
* @param byX The horizontal delta.
|
|
1064
|
+
* @param byY The vertical delta.
|
|
1065
|
+
* @param flags Optional flags for movement behavior.
|
|
1066
|
+
*/
|
|
1067
|
+
static moveBy(node: INode, byX: number, byY: number, flags?: null | 'ignore_scale'): void;
|
|
1068
|
+
/**
|
|
1069
|
+
* Resizes a node by the specified deltas.
|
|
1070
|
+
* @param node The node to resize.
|
|
1071
|
+
* @param byX The horizontal delta.
|
|
1072
|
+
* @param byY The vertical delta.
|
|
1073
|
+
* @param preserveAspect Whether to preserve the aspect ratio.
|
|
1074
|
+
*/
|
|
1075
|
+
static resizeBy(node: INode, byX: number, byY: number, preserveAspect?: boolean): void;
|
|
1076
|
+
/**
|
|
1077
|
+
* Resizes a node based on the specified handle and movement deltas.
|
|
1078
|
+
* @param node The node to resize.
|
|
1079
|
+
* @param handle The handle being used for resizing.
|
|
1080
|
+
* @param byX The horizontal movement delta.
|
|
1081
|
+
* @param byY The vertical movement delta.
|
|
1082
|
+
* @param preserveAspect Whether to preserve the aspect ratio during resizing.
|
|
1083
|
+
*/
|
|
1084
|
+
static resizeHandle(node: INode, handle: NodeHandle, byX: number, byY: number, preserveAspect?: boolean): void;
|
|
1085
|
+
/**
|
|
1086
|
+
* Rotates a node to the specified angle.
|
|
1087
|
+
* @param node The node to rotate.
|
|
1088
|
+
* @param degrees The angle to rotate the node to.
|
|
1089
|
+
* @param kind The unit of the angle, either 'degrees' or 'radians'.
|
|
1090
|
+
*/
|
|
1091
|
+
static rotateTo(node: INode, degrees: number, kind?: 'degrees' | 'radians'): void;
|
|
1092
|
+
/**
|
|
1093
|
+
* Checks if a node overlaps with a target rectangle or another node's bounding rectangle.
|
|
1094
|
+
* @param node The node to check.
|
|
1095
|
+
* @param target The target rectangle or node to check against.
|
|
1096
|
+
* @returns True if the node overlaps with the target, false otherwise.
|
|
1097
|
+
*/
|
|
1098
|
+
static overlaps(node: INode, target: IRect | INode): boolean;
|
|
1099
|
+
/**
|
|
1100
|
+
* Checks if a node is fully inside a target rectangle or another node's bounding rectangle.
|
|
1101
|
+
* @param node The node to check.
|
|
1102
|
+
* @param target The target rectangle or node to check against.
|
|
1103
|
+
* @returns True if the node is fully inside the target, false otherwise.
|
|
1104
|
+
*/
|
|
1105
|
+
static inside(node: INode, target: IRect | INode): boolean;
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
/**
|
|
1109
|
+
* Provides basic utilities for handling connections between nodes in a diagram.
|
|
1110
|
+
* This includes logic for reconnecting and disconnecting endpoints of connections, inserting and removing intermediate points on connections,
|
|
1111
|
+
* synchronizing connection endpoints with their attached nodes, and rendering arrowheads on connections.
|
|
1112
|
+
* The methods in this class are designed to work with the diagram's coordinate system and node structure to ensure accurate manipulation of connections within the diagram editor.
|
|
1113
|
+
*/
|
|
1114
|
+
declare class ConnectionBasics {
|
|
1115
|
+
/**
|
|
1116
|
+
* Determines if a node supports mutable points, which allows for dynamic modification of its points.
|
|
1117
|
+
* @param node The node to check.
|
|
1118
|
+
* @returns True if the node supports mutable points, false otherwise.
|
|
1119
|
+
*/
|
|
1120
|
+
static supportsMutablePoints(node: INode): boolean;
|
|
1121
|
+
/**
|
|
1122
|
+
* Reconnects a connection node to a new target based on the specified coordinates.
|
|
1123
|
+
* @param node The connection node to reconnect.
|
|
1124
|
+
* @param x The x-coordinate of the new target.
|
|
1125
|
+
* @param y The y-coordinate of the new target.
|
|
1126
|
+
*/
|
|
1127
|
+
static reconnect(node: INode & IConnection, x: number, y: number): void;
|
|
1128
|
+
/**
|
|
1129
|
+
* Disconnects a connection node from its target based on the specified coordinates.
|
|
1130
|
+
* @param node The connection node to disconnect.
|
|
1131
|
+
* @param x The x-coordinate of the target to disconnect from.
|
|
1132
|
+
* @param y The y-coordinate of the target to disconnect from.
|
|
1133
|
+
*/
|
|
1134
|
+
static disconnect(node: INode & IConnection, x: number, y: number): void;
|
|
1135
|
+
/**
|
|
1136
|
+
* Inserts a new point into a connection node at the specified coordinates.
|
|
1137
|
+
* @param node The connection node to modify.
|
|
1138
|
+
* @param x The x-coordinate of the new point.
|
|
1139
|
+
* @param y The y-coordinate of the new point.
|
|
1140
|
+
*/
|
|
1141
|
+
static insertPoint(node: INode, x: number, y: number): void;
|
|
1142
|
+
/**
|
|
1143
|
+
* Removes a point from a connection node at the specified coordinates.
|
|
1144
|
+
* @param node The connection node to modify.
|
|
1145
|
+
* @param x The x-coordinate of the point to remove.
|
|
1146
|
+
* @param y The y-coordinate of the point to remove.
|
|
1147
|
+
*/
|
|
1148
|
+
static removePoint(node: INode, x: number, y: number): void;
|
|
1149
|
+
/**
|
|
1150
|
+
* Synchronizes the endpoints of a connection node with its anchors.
|
|
1151
|
+
* @param node The connection node to synchronize.
|
|
1152
|
+
*/
|
|
1153
|
+
static syncEndpoints(node: INode & IConnection): void;
|
|
1154
|
+
/**
|
|
1155
|
+
* Renders the arrows for a connection node.
|
|
1156
|
+
* @param node The connection node to render arrows for.
|
|
1157
|
+
* @param context The canvas rendering context.
|
|
1158
|
+
*/
|
|
1159
|
+
static renderArrows(node: INode & IConnection, context: CanvasRenderingContext2D): void;
|
|
1160
|
+
/**
|
|
1161
|
+
* Gets the anchor point for a connection node.
|
|
1162
|
+
* @param node The connection node.
|
|
1163
|
+
* @param anchor The connection anchor.
|
|
1164
|
+
* @returns The anchor point or undefined if not found.
|
|
1165
|
+
*/
|
|
1166
|
+
static getAnchorPoint(node: INode, anchor: IConnectionAnchor): IPoint | undefined;
|
|
1167
|
+
private static resolveAnchorNode;
|
|
1168
|
+
private static getInteractiveDiagram;
|
|
1169
|
+
private static getMouseAnchor;
|
|
1170
|
+
private static getPointIndex;
|
|
1171
|
+
private static handlePoint;
|
|
1172
|
+
private static renderArrow;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
type IconSource = {
|
|
1176
|
+
type: 'svg';
|
|
1177
|
+
markup: string;
|
|
1178
|
+
} | {
|
|
1179
|
+
type: 'url';
|
|
1180
|
+
src: string;
|
|
1181
|
+
};
|
|
1182
|
+
/**
|
|
1183
|
+
* Registry of icon sources used by editor and toolbar components.
|
|
1184
|
+
*/
|
|
1185
|
+
declare class IconRegistry {
|
|
1186
|
+
private static readonly icons;
|
|
1187
|
+
/**
|
|
1188
|
+
* Register an icon by a short key, without the 'icon-' prefix.
|
|
1189
|
+
* @param id The icon identifier.
|
|
1190
|
+
* @param source The icon source.
|
|
1191
|
+
*/
|
|
1192
|
+
static register(id: string, source: IconSource): void;
|
|
1193
|
+
/**
|
|
1194
|
+
* Register a symbol-defined icon. The symbol markup is converted to an
|
|
1195
|
+
* inline SVG so no sprite injection is needed.
|
|
1196
|
+
* @param id The icon identifier.
|
|
1197
|
+
* @param _symbolId The symbol identifier (unused).
|
|
1198
|
+
* @param symbolMarkup The SVG symbol markup.
|
|
1199
|
+
*/
|
|
1200
|
+
static registerSymbol(id: string, _symbolId: string, symbolMarkup: string): void;
|
|
1201
|
+
/**
|
|
1202
|
+
* Register a standalone SVG string as an icon.
|
|
1203
|
+
* @param id The icon identifier.
|
|
1204
|
+
* @param markup The SVG markup string.
|
|
1205
|
+
*/
|
|
1206
|
+
static registerSvg(id: string, markup: string): void;
|
|
1207
|
+
/**
|
|
1208
|
+
* Register an external URL as an icon.
|
|
1209
|
+
* @param id The icon identifier.
|
|
1210
|
+
* @param src The URL of the icon.
|
|
1211
|
+
*/
|
|
1212
|
+
static registerUrl(id: string, src: string): void;
|
|
1213
|
+
/**
|
|
1214
|
+
* Checks if an icon with the given identifier is registered.
|
|
1215
|
+
* @param id The icon identifier.
|
|
1216
|
+
* @returns True if the icon is registered, false otherwise.
|
|
1217
|
+
*/
|
|
1218
|
+
static has(id: string): boolean;
|
|
1219
|
+
/**
|
|
1220
|
+
* Retrieves the icon source for the given identifier.
|
|
1221
|
+
* @param id The icon identifier.
|
|
1222
|
+
* @returns The icon source if found, undefined otherwise.
|
|
1223
|
+
*/
|
|
1224
|
+
static get(id: string): IconSource | undefined;
|
|
1225
|
+
/**
|
|
1226
|
+
* Returns an Element rendering the icon inline, or null if not found.
|
|
1227
|
+
* @param id The icon identifier.
|
|
1228
|
+
* @param size The desired size of the icon in pixels.
|
|
1229
|
+
* @returns An Element representing the icon, or null if not found.
|
|
1230
|
+
*/
|
|
1231
|
+
static createElement(id: string, size?: number): Element | null;
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
type HollowMode = 'always' | 'never' | 'if_transparent';
|
|
1235
|
+
type TextOverflowMode = 'visible' | 'hidden' | 'ellipsis';
|
|
1236
|
+
/**
|
|
1237
|
+
* INodeAdapter defines the interface for handling different types of nodes in the diagram.
|
|
1238
|
+
* It includes methods for hit testing, rendering, and serialization/deserialization of nodes.
|
|
1239
|
+
*/
|
|
1240
|
+
interface INodeAdapter {
|
|
1241
|
+
/**
|
|
1242
|
+
* The unique name of the adapter, which is used to associate it with nodes of a specific type.
|
|
1243
|
+
* This name is typically registered with the NodeRegistry to enable the diagram control to find the appropriate adapter for each node.
|
|
1244
|
+
*/
|
|
1245
|
+
name: string;
|
|
1246
|
+
/**
|
|
1247
|
+
* Optional icon for this tool shown in the tool palette and any icon-aware UI.
|
|
1248
|
+
*
|
|
1249
|
+
* Two formats are supported:
|
|
1250
|
+
*
|
|
1251
|
+
* - **SVG string** — provide the full `<svg>` markup for the icon:
|
|
1252
|
+
* ```ts
|
|
1253
|
+
* icon: {
|
|
1254
|
+
* type: 'svg',
|
|
1255
|
+
* markup: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">...</svg>',
|
|
1256
|
+
* }
|
|
1257
|
+
* ```
|
|
1258
|
+
*
|
|
1259
|
+
* - **Image URL** — provide any resolvable URL (data URL, CDN, relative path):
|
|
1260
|
+
* ```ts
|
|
1261
|
+
* icon: { type: 'url', src: 'https://example.com/my-tool.svg' }
|
|
1262
|
+
* ```
|
|
1263
|
+
*
|
|
1264
|
+
* When omitted the palette falls back to the built-in `IconRegistry` entry
|
|
1265
|
+
* matching this adapter's `name`, then to a text label.
|
|
1266
|
+
*/
|
|
1267
|
+
icon?: IconSource;
|
|
1268
|
+
/**
|
|
1269
|
+
* Indicates whether the adapter is for a connector node, which may require special handling for rendering and hit testing.
|
|
1270
|
+
*/
|
|
1271
|
+
is_connector: boolean;
|
|
1272
|
+
/**
|
|
1273
|
+
* Indicates whether the node creation process involves multiple steps, such as defining multiple points for a polyline or curve.
|
|
1274
|
+
* If true, the diagram control may need to handle additional user interactions during node creation.
|
|
1275
|
+
*/
|
|
1276
|
+
multistep_create?: boolean;
|
|
1277
|
+
/**
|
|
1278
|
+
* The hollow mode determines how the node's hollow property is calculated based on its fill style.
|
|
1279
|
+
* - 'always': The node is always hollow regardless of its fill style.
|
|
1280
|
+
* - 'never': The node is never hollow regardless of its fill style.
|
|
1281
|
+
* - 'if_transparent': The node is hollow if its fill style is 'transparent', otherwise it is not hollow.
|
|
1282
|
+
*/
|
|
1283
|
+
hollow_mode: HollowMode;
|
|
1284
|
+
/**
|
|
1285
|
+
* Indicates whether the adapter supports rendering text within the node, which may affect how the node is rendered and whether text-related interactions are enabled.
|
|
1286
|
+
*/
|
|
1287
|
+
has_text: boolean;
|
|
1288
|
+
text_overflow: TextOverflowMode;
|
|
1289
|
+
/**
|
|
1290
|
+
* Updates the draft node's points while the user is dragging during creation.
|
|
1291
|
+
* Called on every pointermove while a draft is active.
|
|
1292
|
+
* @param node The draft node being created.
|
|
1293
|
+
* @param point The current world-space cursor position.
|
|
1294
|
+
*/
|
|
1295
|
+
onCreateMove(node: INode, point: IPoint): void;
|
|
1296
|
+
/**
|
|
1297
|
+
* Performs a hit test on the given node with the specified point.
|
|
1298
|
+
* @param node The node to test.
|
|
1299
|
+
* @param point The point to test against the node.
|
|
1300
|
+
* @returns The handle of the node that was hit, or undefined if no hit occurred.
|
|
1301
|
+
*/
|
|
1302
|
+
hitTest(node: INode, point: IPoint): NodeHandle | undefined;
|
|
1303
|
+
/**
|
|
1304
|
+
* Snaps the given node to the specified grid by modifying its points.
|
|
1305
|
+
* @param node The node to snap.
|
|
1306
|
+
* @param grid The grid to snap the node to.
|
|
1307
|
+
*/
|
|
1308
|
+
snapToGrid(node: INode, grid: IGrid): void;
|
|
1309
|
+
/**
|
|
1310
|
+
* Renders the given node on the specified canvas context.
|
|
1311
|
+
* @param node The node to render.
|
|
1312
|
+
* @param ctx The canvas rendering context to draw on.
|
|
1313
|
+
*/
|
|
1314
|
+
render(node: INode, ctx: CanvasRenderingContext2D): void;
|
|
1315
|
+
/**
|
|
1316
|
+
* Renders the selection state of the given node on the specified canvas context.
|
|
1317
|
+
* @param node The node whose selection state to render.
|
|
1318
|
+
* @param ctx The canvas rendering context to draw on.
|
|
1319
|
+
*/
|
|
1320
|
+
renderSelection(node: INode, ctx: CanvasRenderingContext2D): void;
|
|
1321
|
+
/**
|
|
1322
|
+
* Writes the given node to a JSON-serializable format using the provided serializer.
|
|
1323
|
+
* @param node The node to serialize.
|
|
1324
|
+
* @param serializer The serializer to use for converting the node to JSON.
|
|
1325
|
+
* @returns The JSON-serializable representation of the node.
|
|
1326
|
+
*/
|
|
1327
|
+
write(node: INode, serializer: any): any;
|
|
1328
|
+
/**
|
|
1329
|
+
* Reads a node from the given JSON data using the provided serializer.
|
|
1330
|
+
* @param json The JSON data to read the node from.
|
|
1331
|
+
* @param serializer The serializer to use for converting the JSON data to a node.
|
|
1332
|
+
* @returns A promise that resolves to the deserialized node.
|
|
1333
|
+
*/
|
|
1334
|
+
read(json: any, serializer: any): Promise<INode>;
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
interface TextOptions {
|
|
1338
|
+
overflow: TextOverflowMode;
|
|
1339
|
+
path?: Path2D;
|
|
1340
|
+
}
|
|
1341
|
+
/**
|
|
1342
|
+
* Provides basic rendering utilities for diagram nodes, including preparation of the canvas context for drawing nodes and their text.
|
|
1343
|
+
* It handles setting up styles, shadows, and transformations based on node properties such as angle and transparency.
|
|
1344
|
+
* The class also includes logic for rendering multi-line text within nodes, taking into account text alignment and baseline settings.
|
|
1345
|
+
*/
|
|
1346
|
+
declare class RenderBasics {
|
|
1347
|
+
/**
|
|
1348
|
+
* Prepares the canvas context for rendering a node, including setting styles, shadows, and transformations.
|
|
1349
|
+
* @param node The node to prepare for rendering.
|
|
1350
|
+
* @param context The canvas rendering context.
|
|
1351
|
+
*/
|
|
1352
|
+
static prepare(node: INode, context: CanvasRenderingContext2D): void;
|
|
1353
|
+
private static ensureImage;
|
|
1354
|
+
/**
|
|
1355
|
+
* Skips shadow for subsequent draw calls on the context.
|
|
1356
|
+
* Call this after fill and before stroke when shadow should not apply to the stroke.
|
|
1357
|
+
*/
|
|
1358
|
+
static skipShadow(context: CanvasRenderingContext2D): void;
|
|
1359
|
+
/**
|
|
1360
|
+
* Prepares the canvas context for rendering node handles, including setting styles and transformations based on node properties.
|
|
1361
|
+
* @param node The node for which to prepare handles.
|
|
1362
|
+
* @param context The canvas rendering context.
|
|
1363
|
+
*/
|
|
1364
|
+
static prepareHandles(node: INode, context: CanvasRenderingContext2D): void;
|
|
1365
|
+
/**
|
|
1366
|
+
* Renders the text for a node, taking into account text alignment, overflow, and clipping options.
|
|
1367
|
+
* @param node The node for which to render text.
|
|
1368
|
+
* @param context The canvas rendering context.
|
|
1369
|
+
* @param options Options for text rendering, including overflow and clipping path.
|
|
1370
|
+
*/
|
|
1371
|
+
static renderText(node: INode, context: CanvasRenderingContext2D, options: TextOptions): void;
|
|
1372
|
+
private static renderLines;
|
|
1373
|
+
private static getTextLayout;
|
|
1374
|
+
private static getLines;
|
|
1375
|
+
private static resolveShadowColor;
|
|
1376
|
+
private static toAlphaColor;
|
|
1377
|
+
/**
|
|
1378
|
+
* Returns a Path2D object representing the hit area for the text of a node, including optional padding.
|
|
1379
|
+
* @param node The node for which to get the text hit path.
|
|
1380
|
+
* @param context The canvas rendering context.
|
|
1381
|
+
* @param padding The padding to apply around the text hit area.
|
|
1382
|
+
* @returns A Path2D object representing the text hit area, or undefined if the node has insufficient points.
|
|
1383
|
+
*/
|
|
1384
|
+
static getTextHitPath(node: INode, context: CanvasRenderingContext2D, padding?: number): Path2D | undefined;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
/**
|
|
1388
|
+
* CoordinateSystem is a utility class that manages the transformation between diagram coordinates and canvas coordinates, including handling zooming, panning, and grid snapping.
|
|
1389
|
+
* It provides methods to convert points between the diagram's coordinate system and the canvas coordinate system, as well as methods to apply the current viewport transformation to a canvas context.
|
|
1390
|
+
* The class also includes functionality to snap points to a grid if the grid is forced, and to calculate bounding rectangles for nodes based on their geometry and rotation.
|
|
1391
|
+
*/
|
|
1392
|
+
declare class CoordinateSystem {
|
|
1393
|
+
private diagram?;
|
|
1394
|
+
private context;
|
|
1395
|
+
private origin;
|
|
1396
|
+
private zoom_factor;
|
|
1397
|
+
/**
|
|
1398
|
+
* Creates an instance of CoordinateSystem and attaches it to a canvas rendering context.
|
|
1399
|
+
* The CoordinateSystem will use this context to apply transformations and perform hit testing.
|
|
1400
|
+
* @param context the CanvasRenderingContext2D to attach to the CoordinateSystem
|
|
1401
|
+
*/
|
|
1402
|
+
constructor(context: CanvasRenderingContext2D);
|
|
1403
|
+
/**
|
|
1404
|
+
* Attaches a diagram to the CoordinateSystem, allowing it to access diagram-level information such as the grid.
|
|
1405
|
+
* @param diagram the IDiagram to attach to the CoordinateSystem
|
|
1406
|
+
*/
|
|
1407
|
+
attach(diagram: IDiagram): void;
|
|
1408
|
+
get zoom(): number;
|
|
1409
|
+
set zoom(value: number);
|
|
1410
|
+
get pan(): IPoint;
|
|
1411
|
+
set pan(value: IPoint);
|
|
1412
|
+
/**
|
|
1413
|
+
* Applies the current viewport transformation to the specified canvas context, including zooming and panning.
|
|
1414
|
+
* @param context the CanvasRenderingContext2D to apply the transformation to
|
|
1415
|
+
*/
|
|
1416
|
+
applyViewportTransform(context?: CanvasRenderingContext2D): void;
|
|
1417
|
+
/**
|
|
1418
|
+
* Resets the transformation of the specified canvas context to the identity matrix, effectively removing any zooming or panning.
|
|
1419
|
+
* @param context the CanvasRenderingContext2D to reset the transformation for
|
|
1420
|
+
*/
|
|
1421
|
+
resetTransform(context?: CanvasRenderingContext2D): void;
|
|
1422
|
+
/**
|
|
1423
|
+
* Converts the specified coordinates to the nearest grid point, if a grid is defined and forced.
|
|
1424
|
+
* @param x the x-coordinate to convert
|
|
1425
|
+
* @param y the y-coordinate to convert
|
|
1426
|
+
* @param grid an optional grid to use for snapping, defaults to the diagram's grid if not provided
|
|
1427
|
+
* @returns the nearest grid point
|
|
1428
|
+
*/
|
|
1429
|
+
getGridPoint(x: number, y: number, grid?: IGrid): IPoint;
|
|
1430
|
+
/**
|
|
1431
|
+
* Converts the specified canvas coordinates to diagram coordinates, applying the current zoom and pan transformations, and optionally snapping to the grid.
|
|
1432
|
+
* @param x the x-coordinate in canvas space
|
|
1433
|
+
* @param y the y-coordinate in canvas space
|
|
1434
|
+
* @param grid an optional grid to use for snapping, defaults to the diagram's grid if not provided
|
|
1435
|
+
* @returns the corresponding point in diagram coordinates
|
|
1436
|
+
*/
|
|
1437
|
+
getPoint(x: number, y: number, grid?: IGrid | 'ignore_grid'): IPoint;
|
|
1438
|
+
/**
|
|
1439
|
+
* Converts the specified pointer event coordinates to diagram coordinates, applying the current zoom and pan transformations, and optionally snapping to the grid.
|
|
1440
|
+
* @param event the PointerEvent to convert
|
|
1441
|
+
* @param grid an optional grid to use for snapping, defaults to the diagram's grid if not provided
|
|
1442
|
+
* @returns the corresponding point in diagram coordinates
|
|
1443
|
+
*/
|
|
1444
|
+
getPointFromEvent(event: PointerEvent, grid?: IGrid | 'ignore_grid'): IPoint;
|
|
1445
|
+
/**
|
|
1446
|
+
* Converts the specified point from canvas coordinates to diagram coordinates, applying the current zoom and pan transformations, and optionally snapping to the grid.
|
|
1447
|
+
* @param pt the point in canvas coordinates to convert
|
|
1448
|
+
* @param rect the bounding rectangle of the shape
|
|
1449
|
+
* @param angle the rotation angle of the shape
|
|
1450
|
+
* @param cos optional precomputed cosine of the angle
|
|
1451
|
+
* @param sin optional precomputed sine of the angle
|
|
1452
|
+
* @returns the corresponding point in diagram coordinates
|
|
1453
|
+
*/
|
|
1454
|
+
getHitPoint(pt: IPoint, rect: IRect, angle: number, cos?: number, sin?: number): IPoint;
|
|
1455
|
+
/**
|
|
1456
|
+
* Converts the specified point from diagram coordinates to canvas coordinates, applying the current zoom and pan transformations.
|
|
1457
|
+
* @param pt the point in diagram coordinates to convert
|
|
1458
|
+
* @param rect the bounding rectangle of the shape
|
|
1459
|
+
* @param angle the rotation angle of the shape
|
|
1460
|
+
* @param cos optional precomputed cosine of the angle
|
|
1461
|
+
* @param sin optional precomputed sine of the angle
|
|
1462
|
+
* @returns the corresponding point in canvas coordinates
|
|
1463
|
+
*/
|
|
1464
|
+
getRenderPoint(pt: IPoint, rect: IRect, angle: number, cos?: number, sin?: number): IPoint;
|
|
1465
|
+
/**
|
|
1466
|
+
* Calculates the bounding rectangle for a given node, taking into account its geometry and rotation.
|
|
1467
|
+
* If the node has multiple points, it calculates the bounding rectangle defined by the top-left and bottom-right points.
|
|
1468
|
+
* If the node is rotated, it calculates the bounding rectangle after rotation to ensure that it encompasses the entire shape.
|
|
1469
|
+
* @param node the INode for which to calculate the bounding rectangle
|
|
1470
|
+
* @param withAngle whether to take the node's rotation angle into account when calculating the bounding rectangle.
|
|
1471
|
+
* @returns the calculated bounding rectangle
|
|
1472
|
+
*/
|
|
1473
|
+
getBoundingRect(node: INode, withAngle?: boolean): IRect;
|
|
1474
|
+
/**
|
|
1475
|
+
* Detects whether a given point (x, y) is within the stroke of a specified path, taking into account an optional line width.
|
|
1476
|
+
* This method is useful for hit testing when determining if a user interaction (like a mouse click) occurred on the border of a shape.
|
|
1477
|
+
* @param path the Path2D object representing the shape's stroke
|
|
1478
|
+
* @param x the x-coordinate of the point to test
|
|
1479
|
+
* @param y the y-coordinate of the point to test
|
|
1480
|
+
* @param lineWidth optional line width to consider for the stroke
|
|
1481
|
+
* @returns true if the point is within the stroke, false otherwise
|
|
1482
|
+
*/
|
|
1483
|
+
isPointInStroke(path: Path2D, x: number, y: number, lineWidth?: number): boolean;
|
|
1484
|
+
/**
|
|
1485
|
+
* Detects whether a given point (x, y) is within the path of a specified shape.
|
|
1486
|
+
* This method is useful for hit testing when determining if a user interaction (like a mouse click) occurred inside a shape.
|
|
1487
|
+
* @param path the Path2D object representing the shape's path
|
|
1488
|
+
* @param x the x-coordinate of the point to test
|
|
1489
|
+
* @param y the y-coordinate of the point to test
|
|
1490
|
+
* @returns true if the point is within the path, false otherwise
|
|
1491
|
+
*/
|
|
1492
|
+
isPointInPath(path: Path2D, x: number, y: number): boolean;
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
type SelectionDiagram = {
|
|
1496
|
+
layers: ILayer[];
|
|
1497
|
+
grid: IGrid;
|
|
1498
|
+
node(id: string): INode | undefined;
|
|
1499
|
+
hitNodes(x: number, y: number): INode[];
|
|
1500
|
+
getCoordinates(): CoordinateSystem;
|
|
1501
|
+
};
|
|
1502
|
+
/**
|
|
1503
|
+
* Provides basic selection logic for determining which nodes are selected based on a rectangular selection area.
|
|
1504
|
+
* It supports both "include" mode (nodes fully inside the rectangle) and "touch" mode (nodes that intersect or are touched by the rectangle).
|
|
1505
|
+
* The selection process takes into account the visibility of layers and samples points within the rectangle to find nodes that may be partially covered.
|
|
1506
|
+
* This utility can be used in diagram editors to implement selection tools that allow users to select multiple nodes by dragging a selection box.
|
|
1507
|
+
* The methods are designed to work with the diagram's coordinate system and grid to ensure accurate selection behavior.
|
|
1508
|
+
*/
|
|
1509
|
+
declare class SelectionBasics {
|
|
1510
|
+
/**
|
|
1511
|
+
* Returns the nodes within or touched by the specified rectangular area based on the selection mode.
|
|
1512
|
+
* @param diagram The diagram containing the nodes and layers.
|
|
1513
|
+
* @param rect The rectangular area to check for node selection.
|
|
1514
|
+
* @param mode The selection mode, either 'include' (nodes fully inside) or 'touch' (nodes intersecting).
|
|
1515
|
+
* @returns An array of nodes that match the selection criteria.
|
|
1516
|
+
*/
|
|
1517
|
+
static nodesForRect(diagram: SelectionDiagram, rect: IRect, mode: 'include' | 'touch'): INode[];
|
|
1518
|
+
/**
|
|
1519
|
+
* Returns the nodes that are fully inside the specified rectangular area.
|
|
1520
|
+
* @param diagram The diagram containing the nodes and layers.
|
|
1521
|
+
* @param rect The rectangular area to check for node selection.
|
|
1522
|
+
* @returns An array of nodes that are fully inside the rectangle.
|
|
1523
|
+
*/
|
|
1524
|
+
static nodesInsideRect(diagram: SelectionDiagram, rect: IRect): INode[];
|
|
1525
|
+
/**
|
|
1526
|
+
* Returns the nodes that are inside or touching the specified rectangular area.
|
|
1527
|
+
* @param diagram The diagram containing the nodes and layers.
|
|
1528
|
+
* @param rect The rectangular area to check for node selection.
|
|
1529
|
+
* @returns An array of nodes that are inside or touching the rectangle.
|
|
1530
|
+
*/
|
|
1531
|
+
static nodesTouchingRect(diagram: SelectionDiagram, rect: IRect): INode[];
|
|
1532
|
+
private static visibleNodes;
|
|
1533
|
+
private static samplePoints;
|
|
1534
|
+
private static axisSamples;
|
|
1535
|
+
private static toCanvasPoint;
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
/**
|
|
1539
|
+
* RectangleAdapter is a node adapter responsible for rendering rectangle nodes in the diagram.
|
|
1540
|
+
* It provides basic rectangle rendering capabilities and hit testing logic.
|
|
1541
|
+
* Registers with the NodeRegistry under the name 'rectangle'.
|
|
1542
|
+
*/
|
|
1543
|
+
declare class RectangleAdapter implements INodeAdapter {
|
|
1544
|
+
static NAME: string;
|
|
1545
|
+
get name(): string;
|
|
1546
|
+
hollow_mode: HollowMode;
|
|
1547
|
+
is_connector: boolean;
|
|
1548
|
+
multistep_create: boolean;
|
|
1549
|
+
has_text: boolean;
|
|
1550
|
+
text_overflow: TextOverflowMode;
|
|
1551
|
+
/**
|
|
1552
|
+
* Registers the RectangleAdapter with the NodeRegistry.
|
|
1553
|
+
*/
|
|
1554
|
+
static register(): void;
|
|
1555
|
+
/**
|
|
1556
|
+
* Registers the RectangleAdapter instance with the NodeRegistry.
|
|
1557
|
+
*/
|
|
1558
|
+
register(): void;
|
|
1559
|
+
hitTest(node: INode, point: IPoint): NodeHandle | undefined;
|
|
1560
|
+
onCreateMove(node: INode, point: IPoint): void;
|
|
1561
|
+
snapToGrid(node: INode, grid: IGrid): void;
|
|
1562
|
+
render(node: INode, context: CanvasRenderingContext2D): void;
|
|
1563
|
+
renderSelection(node: INode, context: CanvasRenderingContext2D): void;
|
|
1564
|
+
write(node: INode, serializer: any): any;
|
|
1565
|
+
read(json: any, serializer: any): Promise<INode>;
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
/**
|
|
1569
|
+
* RoundRectangleAdapter is a node adapter responsible for rendering rounded rectangle nodes in the diagram.
|
|
1570
|
+
* It extends the RectangleAdapter to leverage basic rectangle rendering capabilities while adding specific logic for handling rounded corners and hit testing.
|
|
1571
|
+
* Registers with the NodeRegistry under the name 'round_rectangle'.
|
|
1572
|
+
*/
|
|
1573
|
+
declare class RoundRectangleAdapter extends RectangleAdapter {
|
|
1574
|
+
static NAME: string;
|
|
1575
|
+
render(node: INode, context: CanvasRenderingContext2D): void;
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
/**
|
|
1579
|
+
* EllipseAdapter is a node adapter responsible for rendering ellipse nodes in the diagram.
|
|
1580
|
+
* It extends the RectangleAdapter to leverage basic rectangle rendering capabilities while adding specific logic for handling elliptical shapes and hit testing.
|
|
1581
|
+
* Registers with the NodeRegistry under the name 'ellipse'.
|
|
1582
|
+
*/
|
|
1583
|
+
declare class EllipseAdapter extends RectangleAdapter {
|
|
1584
|
+
static NAME: string;
|
|
1585
|
+
render(node: INode, context: CanvasRenderingContext2D): void;
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
/**
|
|
1589
|
+
* RhombusAdapter is a node adapter responsible for rendering rhombus nodes in the diagram.
|
|
1590
|
+
* It extends the RectangleAdapter to leverage basic rectangle rendering capabilities while adding specific logic for handling rhombus shapes and hit testing.
|
|
1591
|
+
* Registers with the NodeRegistry under the name 'rhombus'.
|
|
1592
|
+
*/
|
|
1593
|
+
declare class RhombusAdapter extends RectangleAdapter {
|
|
1594
|
+
static NAME: string;
|
|
1595
|
+
render(node: INode, context: CanvasRenderingContext2D): void;
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
/**
|
|
1599
|
+
* TextAdapter is a node adapter responsible for rendering text nodes in the diagram.
|
|
1600
|
+
* It extends the RectangleAdapter to leverage basic rectangle rendering capabilities while adding specific logic for handling text content and hit testing.
|
|
1601
|
+
* Registers with the NodeRegistry under the name 'text'.
|
|
1602
|
+
*/
|
|
1603
|
+
declare class TextAdapter extends RectangleAdapter {
|
|
1604
|
+
static NAME: string;
|
|
1605
|
+
hollow_mode: HollowMode;
|
|
1606
|
+
text_overflow: TextOverflowMode;
|
|
1607
|
+
render(node: INode, context: CanvasRenderingContext2D): void;
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
/**
|
|
1611
|
+
* SvgAdapter is a node adapter responsible for rendering SVG nodes in the diagram.
|
|
1612
|
+
* It extends the RectangleAdapter to leverage basic rectangle rendering capabilities while adding specific logic for handling SVG content and hit testing.
|
|
1613
|
+
* Registers with the NodeRegistry under the name 'svg'.
|
|
1614
|
+
*/
|
|
1615
|
+
declare class SvgAdapter extends RectangleAdapter {
|
|
1616
|
+
static NAME: string;
|
|
1617
|
+
hollow_mode: HollowMode;
|
|
1618
|
+
render(node: INode, context: CanvasRenderingContext2D): void;
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
/**
|
|
1622
|
+
* PolylineAdapter is a node adapter responsible for rendering polyline nodes in the diagram.
|
|
1623
|
+
* It provides rendering capabilities for polylines and hit testing logic specific to polylines.
|
|
1624
|
+
* Registers with the NodeRegistry under the name 'polyline'.
|
|
1625
|
+
*/
|
|
1626
|
+
declare class PolylineAdapter implements INodeAdapter {
|
|
1627
|
+
static NAME: string;
|
|
1628
|
+
/**
|
|
1629
|
+
* Gets the registry name for this adapter.
|
|
1630
|
+
*/
|
|
1631
|
+
get name(): string;
|
|
1632
|
+
hollow_mode: HollowMode;
|
|
1633
|
+
is_connector: boolean;
|
|
1634
|
+
multistep_create: boolean;
|
|
1635
|
+
has_text: boolean;
|
|
1636
|
+
text_overflow: TextOverflowMode;
|
|
1637
|
+
/**
|
|
1638
|
+
* Registers the PolylineAdapter with the NodeRegistry.
|
|
1639
|
+
*/
|
|
1640
|
+
static register(): void;
|
|
1641
|
+
/**
|
|
1642
|
+
* Registers the PolylineAdapter instance with the NodeRegistry.
|
|
1643
|
+
*/
|
|
1644
|
+
register(): void;
|
|
1645
|
+
hitTest(node: INode, point: IPoint): NodeHandle | undefined;
|
|
1646
|
+
snapToGrid(node: INode, grid: IGrid): void;
|
|
1647
|
+
render(node: INode, context: CanvasRenderingContext2D): void;
|
|
1648
|
+
renderSelection(node: INode, context: CanvasRenderingContext2D): void;
|
|
1649
|
+
write(node: INode, serializer: any): any;
|
|
1650
|
+
onCreateMove(node: INode, point: IPoint): void;
|
|
1651
|
+
read(json: any, serializer: any): Promise<INode>;
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
/**
|
|
1655
|
+
* PolygonAdapter is a node adapter responsible for rendering polygon nodes in the diagram.
|
|
1656
|
+
* It extends the PolylineAdapter to leverage basic polyline rendering capabilities while adding specific logic for handling closed shapes and hit testing.
|
|
1657
|
+
* Registers with the NodeRegistry under the name 'polygon'.
|
|
1658
|
+
*/
|
|
1659
|
+
declare class PolygonAdapter extends PolylineAdapter {
|
|
1660
|
+
static NAME: string;
|
|
1661
|
+
hollow_mode: HollowMode;
|
|
1662
|
+
text_overflow: TextOverflowMode;
|
|
1663
|
+
render(node: INode, context: CanvasRenderingContext2D): void;
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
/**
|
|
1667
|
+
* CurveAdapter is a node adapter responsible for rendering curve nodes in the diagram.
|
|
1668
|
+
* It extends the PolylineAdapter to leverage basic polyline rendering capabilities while adding specific logic for handling curved shapes and hit testing.
|
|
1669
|
+
* Registers with the NodeRegistry under the name 'curve'.
|
|
1670
|
+
* The curve is rendered using quadratic Bezier curves between points, providing a smooth appearance.
|
|
1671
|
+
* Hit testing is performed by checking proximity to control points and the curve path itself, allowing for intuitive interaction with the curve nodes.
|
|
1672
|
+
* The adapter also handles rendering of arrows for connection nodes, ensuring that directional indicators are properly displayed on curves.
|
|
1673
|
+
*/
|
|
1674
|
+
declare class CurveAdapter extends PolylineAdapter {
|
|
1675
|
+
static NAME: string;
|
|
1676
|
+
render(node: INode, context: CanvasRenderingContext2D): void;
|
|
1677
|
+
onCreateMove(node: INode, point: IPoint): void;
|
|
1678
|
+
private renderCurve;
|
|
1679
|
+
private gradient;
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
/**
|
|
1683
|
+
* LineAdapter is a node adapter responsible for rendering line nodes in the diagram.
|
|
1684
|
+
* It extends the PolylineAdapter to leverage basic polyline rendering capabilities while adding specific logic for handling straight lines and hit testing.
|
|
1685
|
+
* Registers with the NodeRegistry under the name 'line'.
|
|
1686
|
+
*/
|
|
1687
|
+
declare class LineAdapter extends PolylineAdapter {
|
|
1688
|
+
static NAME: string;
|
|
1689
|
+
hollow_mode: HollowMode;
|
|
1690
|
+
multistep_create: boolean;
|
|
1691
|
+
render(node: INode, context: CanvasRenderingContext2D): void;
|
|
1692
|
+
renderSelection(node: INode, context: CanvasRenderingContext2D): void;
|
|
1693
|
+
private renderLine;
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
/**
|
|
1697
|
+
* NodeRegistry is a central registry for managing different types of node handlers.
|
|
1698
|
+
* It allows for registering, retrieving, and unregistering node handlers based on their type.
|
|
1699
|
+
* This enables the diagram system to support various node types and their associated behaviors in a modular way.
|
|
1700
|
+
*
|
|
1701
|
+
* Handlers should be registered with a unique type string that identifies the kind of node they handle.
|
|
1702
|
+
* The registry can then be queried to retrieve the appropriate handler for a given node type when needed.
|
|
1703
|
+
* This design promotes extensibility and separation of concerns within the diagram system.
|
|
1704
|
+
*
|
|
1705
|
+
* Example usage:
|
|
1706
|
+
* const rectangleHandler = new RectangleHandler();
|
|
1707
|
+
* rectangleHandler.register(); // Registers the handler with the NodeRegistry
|
|
1708
|
+
*
|
|
1709
|
+
* const handler = NodeRegistry.get('rectangle'); // Retrieves the handler for 'rectangle' nodes
|
|
1710
|
+
* if (handler) {
|
|
1711
|
+
* handler.render(node, context); // Uses the handler to render a node
|
|
1712
|
+
* }
|
|
1713
|
+
*/
|
|
1714
|
+
declare class NodeRegistry {
|
|
1715
|
+
private static _nodes;
|
|
1716
|
+
/**
|
|
1717
|
+
* Registers a node handler for a specific type.
|
|
1718
|
+
* @param type The type of the node.
|
|
1719
|
+
* @param handler The handler responsible for managing the node type.
|
|
1720
|
+
*/
|
|
1721
|
+
static register(type: string, handler: INodeAdapter | (new () => INodeAdapter)): void;
|
|
1722
|
+
/**
|
|
1723
|
+
* Retrieves the node handler for a given type.
|
|
1724
|
+
* @param type The type of the node to retrieve the handler for.
|
|
1725
|
+
* @returns The node handler for the specified type, or undefined if no handler is registered for that type.
|
|
1726
|
+
*/
|
|
1727
|
+
static adapter(type: string): INodeAdapter | undefined;
|
|
1728
|
+
/**
|
|
1729
|
+
* Unregisters a node handler for a specific type.
|
|
1730
|
+
* @param type The type of the node to unregister the handler for.
|
|
1731
|
+
*/
|
|
1732
|
+
static unregister(type: string): void;
|
|
1733
|
+
/**
|
|
1734
|
+
* Retrieves a list of all registered node types in the registry.
|
|
1735
|
+
* @returns An array of strings representing the registered node types.
|
|
1736
|
+
*/
|
|
1737
|
+
static registeredTypes(): string[];
|
|
1738
|
+
/**
|
|
1739
|
+
* Checks if the node type represents a connection.
|
|
1740
|
+
* @param type The type of the node.
|
|
1741
|
+
* @returns True if the node type is a connection, false otherwise.
|
|
1742
|
+
*/
|
|
1743
|
+
static isConnection(type: string): boolean;
|
|
1744
|
+
/**
|
|
1745
|
+
* Checks if the node type has text.
|
|
1746
|
+
* @param type The type of the node.
|
|
1747
|
+
* @returns True if the node type has text, false otherwise.
|
|
1748
|
+
*/
|
|
1749
|
+
static hasText(type: string): boolean;
|
|
1750
|
+
/**
|
|
1751
|
+
* Checks if the node type requires a multistep creation process.
|
|
1752
|
+
* @param type The type of the node.
|
|
1753
|
+
* @returns True if the node type requires multistep creation, false otherwise.
|
|
1754
|
+
*/
|
|
1755
|
+
static isMultistepCreate(type: string): boolean;
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
interface HistoryState {
|
|
1759
|
+
document: string;
|
|
1760
|
+
selection: string[];
|
|
1761
|
+
}
|
|
1762
|
+
/**
|
|
1763
|
+
* A class that manages the history of changes to a diagram, allowing for undo and redo functionality.
|
|
1764
|
+
* It tracks the state of the diagram at various points in time and provides methods to restore previous states.
|
|
1765
|
+
*/
|
|
1766
|
+
declare class HistoryStack {
|
|
1767
|
+
private diagram;
|
|
1768
|
+
private undoList;
|
|
1769
|
+
private redoList;
|
|
1770
|
+
private readonly historySerializer;
|
|
1771
|
+
/**
|
|
1772
|
+
* Creates an instance of HistoryStack and attaches it to a diagram model that supports selection.
|
|
1773
|
+
* The HistoryStack will use the model's serialization and selection capabilities to manage history states.
|
|
1774
|
+
* @param diagram The diagram model to attach to the history stack.
|
|
1775
|
+
*/
|
|
1776
|
+
constructor(diagram: IDiagram & HasSelection);
|
|
1777
|
+
/**
|
|
1778
|
+
* Retrieves the current state of the diagram, including its serialized document and selected nodes.
|
|
1779
|
+
* @returns the current history state or undefined if the diagram is not available.
|
|
1780
|
+
*/
|
|
1781
|
+
getState(): HistoryState | undefined;
|
|
1782
|
+
/**
|
|
1783
|
+
* Restores the diagram to a previous state.
|
|
1784
|
+
* @param state The history state to restore.
|
|
1785
|
+
* @returns A promise that resolves to true if the state was successfully restored, false otherwise.
|
|
1786
|
+
*/
|
|
1787
|
+
restoreState(state: HistoryState): Promise<boolean>;
|
|
1788
|
+
/**
|
|
1789
|
+
* Indicates whether there are any states in the undo stack that can be undone. Returns true if there is at least one state in the undo stack, false otherwise.
|
|
1790
|
+
* @returns true if undo is possible, false otherwise.
|
|
1791
|
+
*/
|
|
1792
|
+
get canUndo(): boolean;
|
|
1793
|
+
/**
|
|
1794
|
+
* Indicates whether there are any states in the redo stack that can be redone. Returns true if there is at least one state in the redo stack, false otherwise.
|
|
1795
|
+
* @returns true if redo is possible, false otherwise.
|
|
1796
|
+
*/
|
|
1797
|
+
get canRedo(): boolean;
|
|
1798
|
+
/**
|
|
1799
|
+
* Clears the history stacks for both undo and redo, effectively resetting the history of changes.
|
|
1800
|
+
*/
|
|
1801
|
+
clear(): void;
|
|
1802
|
+
/**
|
|
1803
|
+
* Adds the current state of the diagram to the undo stack.
|
|
1804
|
+
* This should be called whenever a change is made to the diagram that should be undoable.
|
|
1805
|
+
*/
|
|
1806
|
+
addUndo(): void;
|
|
1807
|
+
/**
|
|
1808
|
+
* Undoes the last change made to the diagram by restoring the previous state from the undo stack.
|
|
1809
|
+
* The current state is pushed onto the redo stack to allow for redo operations.
|
|
1810
|
+
* @returns A promise that resolves to true if the undo operation was successful, false otherwise.
|
|
1811
|
+
*/
|
|
1812
|
+
undo(): Promise<boolean>;
|
|
1813
|
+
/**
|
|
1814
|
+
* Redoes the last undone change by restoring the state from the redo stack.
|
|
1815
|
+
* The current state is pushed onto the undo stack to allow for undo operations.
|
|
1816
|
+
* @returns A promise that resolves to true if the redo operation was successful, false otherwise.
|
|
1817
|
+
*/
|
|
1818
|
+
redo(): Promise<boolean>;
|
|
1819
|
+
private isSameState;
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
/**
|
|
1823
|
+
* A class that manages colors frequently used in a diagram.
|
|
1824
|
+
* It can be used to support building adaptive editor UIs.
|
|
1825
|
+
*/
|
|
1826
|
+
declare class ColorPalette {
|
|
1827
|
+
private diagram;
|
|
1828
|
+
private colors_used;
|
|
1829
|
+
/**
|
|
1830
|
+
* Creates an instance of ColorPalette and attaches it to a diagram model.
|
|
1831
|
+
* The ColorPalettte will be based on colors used in the given Diagram.
|
|
1832
|
+
* @param diagram The diagram model to read colors from.
|
|
1833
|
+
*/
|
|
1834
|
+
constructor(diagram: Diagram);
|
|
1835
|
+
/**
|
|
1836
|
+
* List colors in descending order of their frequency.
|
|
1837
|
+
* @returns An array of color strings sorted by their usage frequency.
|
|
1838
|
+
*/
|
|
1839
|
+
frequentColors(): string[];
|
|
1840
|
+
/**
|
|
1841
|
+
* Refreshes the color palette by scanning the diagram for all colors currently in use.
|
|
1842
|
+
* This method should be called whenever there are changes to the diagram that may affect color usage.
|
|
1843
|
+
* It updates the internal count of colors used in the diagram, which can then be retrieved using `frequentColors()`.
|
|
1844
|
+
*/
|
|
1845
|
+
refresh(): void;
|
|
1846
|
+
/**
|
|
1847
|
+
* Manually adds a color to the palette's tracking.
|
|
1848
|
+
* This can be used to populate the palette with known colors.
|
|
1849
|
+
* @param style The color string to add to the palette.
|
|
1850
|
+
*/
|
|
1851
|
+
addColor(style: string): void;
|
|
1852
|
+
private isColor;
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
/**
|
|
1856
|
+
* Horizontal alignment options for fit-to-view operations.
|
|
1857
|
+
*/
|
|
1858
|
+
type HorizontalAlign = "left" | "center" | "right";
|
|
1859
|
+
/**
|
|
1860
|
+
* Vertical alignment options for fit-to-view operations.
|
|
1861
|
+
*/
|
|
1862
|
+
type VerticalAlign = "top" | "center" | "bottom";
|
|
1863
|
+
/**
|
|
1864
|
+
* Alignment options used by fit-to-width and fit-to-nodes operations.
|
|
1865
|
+
*/
|
|
1866
|
+
interface FitAlign {
|
|
1867
|
+
horizontal?: HorizontalAlign;
|
|
1868
|
+
vertical?: VerticalAlign;
|
|
1869
|
+
}
|
|
1870
|
+
/**
|
|
1871
|
+
* Initial view modes for DiagramView. Determines how the viewport is set when the diagram is first loaded.
|
|
1872
|
+
*/
|
|
1873
|
+
type InitialViewMode = "saved" | "fit-width" | "fit-all";
|
|
1874
|
+
/**
|
|
1875
|
+
* Selection options to define how selection works in the diagram view.
|
|
1876
|
+
*/
|
|
1877
|
+
interface DiagramSelectionOptions {
|
|
1878
|
+
enable_select: boolean;
|
|
1879
|
+
enable_multi: boolean;
|
|
1880
|
+
enable_rect: boolean;
|
|
1881
|
+
rect_mode: "include" | "touch";
|
|
1882
|
+
}
|
|
1883
|
+
/**
|
|
1884
|
+
* Initial viewport settings for a diagram view.
|
|
1885
|
+
*/
|
|
1886
|
+
interface DiagramInitialView {
|
|
1887
|
+
mode?: InitialViewMode;
|
|
1888
|
+
pan?: IPoint;
|
|
1889
|
+
zoom?: number;
|
|
1890
|
+
padding?: number;
|
|
1891
|
+
alignment?: FitAlign;
|
|
1892
|
+
}
|
|
1893
|
+
/**
|
|
1894
|
+
* Construction options for DiagramView and subclasses.
|
|
1895
|
+
*/
|
|
1896
|
+
interface DiagramViewOptions {
|
|
1897
|
+
initialView?: DiagramInitialView;
|
|
1898
|
+
selectedNodeId?: string;
|
|
1899
|
+
selectedNodeIds?: string[];
|
|
1900
|
+
selection?: DiagramSelectionOptions;
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
/**
|
|
1904
|
+
* FitViewport is a utility class that provides methods to adjust the viewport of a DiagramView to fit its content (nodes) within the visible area.
|
|
1905
|
+
* It calculates the appropriate zoom level and pan offset based on the dimensions of the nodes and the canvas,
|
|
1906
|
+
* allowing for different alignment options (center, left, right, top, bottom).
|
|
1907
|
+
* The class also includes methods to clamp the zoom level within specified minimum and maximum values.
|
|
1908
|
+
*/
|
|
1909
|
+
declare class FitViewport {
|
|
1910
|
+
private diagram;
|
|
1911
|
+
private minZoom;
|
|
1912
|
+
private maxZoom;
|
|
1913
|
+
/**
|
|
1914
|
+
* Creates an instance of FitViewport and attaches it to a DiagramView.
|
|
1915
|
+
* This allows the FitViewport to manipulate the viewport of the DiagramView when fitting content.
|
|
1916
|
+
* @param diagram the DiagramView instance to attach to
|
|
1917
|
+
* @param options optional configuration for minimum and maximum zoom levels
|
|
1918
|
+
*/
|
|
1919
|
+
constructor(diagram: DiagramView, options?: {
|
|
1920
|
+
minZoom?: number;
|
|
1921
|
+
maxZoom?: number;
|
|
1922
|
+
});
|
|
1923
|
+
/**
|
|
1924
|
+
* Adjusts the viewport to fit the width of the nodes within the visible area of the canvas.
|
|
1925
|
+
* @param padding The padding to apply around the content.
|
|
1926
|
+
* @param alignment The alignment options for fitting the content.
|
|
1927
|
+
*/
|
|
1928
|
+
fitToWidth(options?: {
|
|
1929
|
+
padding?: number;
|
|
1930
|
+
alignment?: FitAlign;
|
|
1931
|
+
}): void;
|
|
1932
|
+
/**
|
|
1933
|
+
* Adjusts the viewport to fit all nodes within the visible area of the canvas.
|
|
1934
|
+
* @param padding The padding to apply around the content.
|
|
1935
|
+
* @param alignment The alignment options for fitting the content.
|
|
1936
|
+
*/
|
|
1937
|
+
fitToNodes(options?: {
|
|
1938
|
+
padding?: number;
|
|
1939
|
+
alignment?: FitAlign;
|
|
1940
|
+
}): void;
|
|
1941
|
+
/**
|
|
1942
|
+
* Applies the calculated viewport settings (zoom and pan) to the diagram based on the provided bounds.
|
|
1943
|
+
* This method applies a transform to the diagram's canvas and coordinate system.
|
|
1944
|
+
* @param bounds The bounding rectangle of the content to fit.
|
|
1945
|
+
* @param zoom The zoom level to apply.
|
|
1946
|
+
* @param padding The padding to apply around the content.
|
|
1947
|
+
* @param alignment The alignment options for fitting the content.
|
|
1948
|
+
*/
|
|
1949
|
+
protected applyViewportForBounds(bounds: IRect, zoom: number, padding: number, alignment?: FitAlign): void;
|
|
1950
|
+
/**
|
|
1951
|
+
* Clamps the zoom value to the allowed range defined by `minZoom` and `maxZoom`.
|
|
1952
|
+
* @param value The zoom value to clamp.
|
|
1953
|
+
* @returns The clamped zoom value.
|
|
1954
|
+
*/
|
|
1955
|
+
clampZoom(value: number): number;
|
|
1956
|
+
private getHorizontalOffset;
|
|
1957
|
+
private getVerticalOffset;
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
type Cacheable = INode | ILayer;
|
|
1961
|
+
/**
|
|
1962
|
+
* Cached properties for nodes and layers.
|
|
1963
|
+
*/
|
|
1964
|
+
interface INodeCached {
|
|
1965
|
+
cos?: number;
|
|
1966
|
+
sin?: number;
|
|
1967
|
+
path?: Path2D;
|
|
1968
|
+
text_path?: Path2D;
|
|
1969
|
+
img?: HTMLImageElement;
|
|
1970
|
+
pattern?: CanvasPattern;
|
|
1971
|
+
image_loading?: boolean;
|
|
1972
|
+
}
|
|
1973
|
+
interface ILayerCached {
|
|
1974
|
+
context?: CanvasRenderingContext2D;
|
|
1975
|
+
}
|
|
1976
|
+
/**
|
|
1977
|
+
* Helper class for caching computed properties of nodes and layers to optimize rendering performance.
|
|
1978
|
+
* It uses WeakMaps to associate cached data with nodes and layers without preventing garbage collection.
|
|
1979
|
+
*/
|
|
1980
|
+
declare class ViewCache {
|
|
1981
|
+
private node_cache;
|
|
1982
|
+
private layer_cache;
|
|
1983
|
+
/**
|
|
1984
|
+
* Gets cached render data for a node.
|
|
1985
|
+
* @param node Target node.
|
|
1986
|
+
* @returns Cached node data when present.
|
|
1987
|
+
*/
|
|
1988
|
+
getNode(node: INode): INodeCached | undefined;
|
|
1989
|
+
/**
|
|
1990
|
+
* Stores cached render data for a node.
|
|
1991
|
+
* @param node Target node.
|
|
1992
|
+
* @param cached Cached node data.
|
|
1993
|
+
*/
|
|
1994
|
+
setNode(node: INode, cached: INodeCached): void;
|
|
1995
|
+
/**
|
|
1996
|
+
* Removes cached render data for a node.
|
|
1997
|
+
* @param node Target node.
|
|
1998
|
+
*/
|
|
1999
|
+
deleteNode(node: INode): void;
|
|
2000
|
+
/**
|
|
2001
|
+
* Gets cached render data for a layer.
|
|
2002
|
+
* @param layer Target layer.
|
|
2003
|
+
* @returns Cached layer data when present.
|
|
2004
|
+
*/
|
|
2005
|
+
getLayer(layer: ILayer): ILayerCached | undefined;
|
|
2006
|
+
/**
|
|
2007
|
+
* Stores cached render data for a layer.
|
|
2008
|
+
* @param layer Target layer.
|
|
2009
|
+
* @param cached Cached layer data.
|
|
2010
|
+
*/
|
|
2011
|
+
setLayer(layer: ILayer, cached: ILayerCached): void;
|
|
2012
|
+
/**
|
|
2013
|
+
* Removes cached render data for a layer.
|
|
2014
|
+
* @param layer Target layer.
|
|
2015
|
+
*/
|
|
2016
|
+
deleteLayer(layer: ILayer): void;
|
|
2017
|
+
/**
|
|
2018
|
+
* Clears all node and layer cache entries.
|
|
2019
|
+
*/
|
|
2020
|
+
clear(): void;
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
/**
|
|
2024
|
+
* A class representing a diagram in 'view' mode.
|
|
2025
|
+
* This class extends the base Diagram model and adds properties and methods specific to rendering and interacting with the diagram.
|
|
2026
|
+
*
|
|
2027
|
+
* It includes a coordinate system for managing transformations
|
|
2028
|
+
* and a cache for storing precomputed values related to nodes for efficient rendering.
|
|
2029
|
+
*/
|
|
2030
|
+
declare class DiagramView extends Diagram implements HasSelection {
|
|
2031
|
+
protected readonly ownsCanvas: boolean;
|
|
2032
|
+
protected coordinates: CoordinateSystem;
|
|
2033
|
+
protected cache: ViewCache;
|
|
2034
|
+
protected host: HTMLElement;
|
|
2035
|
+
protected canvas: HTMLCanvasElement;
|
|
2036
|
+
protected context: CanvasRenderingContext2D;
|
|
2037
|
+
protected readonly eventDispatcher: EventDispatcher;
|
|
2038
|
+
protected resizeObserver?: ResizeObserver;
|
|
2039
|
+
protected selected_nodes: INode[];
|
|
2040
|
+
protected selectionOptions: DiagramSelectionOptions;
|
|
2041
|
+
protected fitViewport: FitViewport;
|
|
2042
|
+
protected isSpacePanning: boolean;
|
|
2043
|
+
protected dragStartOnNode: boolean;
|
|
2044
|
+
protected dragPanningWithSpace: boolean;
|
|
2045
|
+
protected readonly handlePointerDown: (event: PointerEvent) => void;
|
|
2046
|
+
protected readonly handlePointerMove: (event: PointerEvent) => void;
|
|
2047
|
+
protected readonly handlePointerUp: (event: PointerEvent) => void;
|
|
2048
|
+
protected readonly handlePointerLeave: (event: PointerEvent) => void;
|
|
2049
|
+
protected readonly handleWheel: (event: WheelEvent) => void;
|
|
2050
|
+
protected readonly handleKeyDown: (event: KeyboardEvent) => void;
|
|
2051
|
+
protected readonly handleKeyUp: (event: KeyboardEvent) => void;
|
|
2052
|
+
protected readonly handleContextMenu: (event: PointerEvent) => void;
|
|
2053
|
+
/**
|
|
2054
|
+
* Creates a new DiagramView instance.
|
|
2055
|
+
* @param id The unique identifier for the diagram.
|
|
2056
|
+
* @param target The HTML element or canvas where the diagram will be rendered.
|
|
2057
|
+
* @param initial Initial properties for the diagram.
|
|
2058
|
+
* @param options Configuration options for the diagram view.
|
|
2059
|
+
*/
|
|
2060
|
+
constructor(id: string, target: HTMLElement | HTMLCanvasElement, initial?: Partial<Omit<Diagram, 'id'>>, options?: DiagramViewOptions);
|
|
2061
|
+
/**
|
|
2062
|
+
* Cleans up resources used by the DiagramView, including event listeners and the canvas element if it was created by the view.
|
|
2063
|
+
*/
|
|
2064
|
+
destroy(): void;
|
|
2065
|
+
clear(): void;
|
|
2066
|
+
/**
|
|
2067
|
+
* Indicates the rendering mode of this diagram instance.
|
|
2068
|
+
*/
|
|
2069
|
+
get render_mode(): 'view' | 'editing';
|
|
2070
|
+
/**
|
|
2071
|
+
* Returns the cache used by the DiagramView.
|
|
2072
|
+
*/
|
|
2073
|
+
getCache(): ViewCache;
|
|
2074
|
+
/**
|
|
2075
|
+
* Returns the coordinate system used by the DiagramView.
|
|
2076
|
+
*/
|
|
2077
|
+
getCoordinates(): CoordinateSystem;
|
|
2078
|
+
/**
|
|
2079
|
+
* Returns the canvas element used by the DiagramView.
|
|
2080
|
+
*/
|
|
2081
|
+
getCanvas(): HTMLCanvasElement;
|
|
2082
|
+
/**
|
|
2083
|
+
* Selects a node by its ID or node object.
|
|
2084
|
+
* @param node The ID of the node or the node object to select.
|
|
2085
|
+
* @returns The selected node, if any.
|
|
2086
|
+
*/
|
|
2087
|
+
selectNode(node: string | INode): INode | undefined;
|
|
2088
|
+
/**
|
|
2089
|
+
* Returns the currently selected nodes.
|
|
2090
|
+
* @returns An array of selected nodes.
|
|
2091
|
+
*/
|
|
2092
|
+
selection(): INode[];
|
|
2093
|
+
/**
|
|
2094
|
+
* Checks if a node is currently selected.
|
|
2095
|
+
* @param node The node to check.
|
|
2096
|
+
* @returns True if the node is selected, false otherwise.
|
|
2097
|
+
*/
|
|
2098
|
+
isSelected(node: INode): boolean;
|
|
2099
|
+
/**
|
|
2100
|
+
* Selects a node.
|
|
2101
|
+
* @param node The node to select.
|
|
2102
|
+
*/
|
|
2103
|
+
select(node: INode): void;
|
|
2104
|
+
/**
|
|
2105
|
+
* Deselects a node.
|
|
2106
|
+
* @param node The node to deselect.
|
|
2107
|
+
*/
|
|
2108
|
+
deselect(node: INode): void;
|
|
2109
|
+
/**
|
|
2110
|
+
* Clears the selection of all nodes.
|
|
2111
|
+
*/
|
|
2112
|
+
clearSelection(): void;
|
|
2113
|
+
/**
|
|
2114
|
+
* Selects all nodes in the diagram. Honors the `enable_multi` selection option to determine whether multiple nodes can be selected at once.
|
|
2115
|
+
*/
|
|
2116
|
+
selectAll(): void;
|
|
2117
|
+
/**
|
|
2118
|
+
* Sets the selection of nodes.
|
|
2119
|
+
* @param nodes The nodes to select.
|
|
2120
|
+
*/
|
|
2121
|
+
setSelection(nodes: INode[]): void;
|
|
2122
|
+
/**
|
|
2123
|
+
* Toggles the selection state of a node.
|
|
2124
|
+
* @param node The node to toggle.
|
|
2125
|
+
* @returns void
|
|
2126
|
+
*/
|
|
2127
|
+
toggleSelection(node: INode): void;
|
|
2128
|
+
/**
|
|
2129
|
+
* Sets the viewport of the diagram with a given pan and/or zoom.
|
|
2130
|
+
* @param viewport The viewport changes to apply.
|
|
2131
|
+
*/
|
|
2132
|
+
setViewport(viewport: Partial<DiagramViewportChange>): void;
|
|
2133
|
+
/**
|
|
2134
|
+
* Fits the diagram content to the width of the viewport, with optional padding and alignment.
|
|
2135
|
+
* @param padding The padding to apply around the content.
|
|
2136
|
+
* @param alignment The alignment of the content within the viewport.
|
|
2137
|
+
*/
|
|
2138
|
+
fitToWidth(options?: {
|
|
2139
|
+
padding?: number;
|
|
2140
|
+
alignment?: FitAlign;
|
|
2141
|
+
}): void;
|
|
2142
|
+
/**
|
|
2143
|
+
* Fits the diagram content to the viewport, with optional padding and alignment.
|
|
2144
|
+
* @param padding The padding to apply around the content.
|
|
2145
|
+
* @param alignment The alignment of the content within the viewport.
|
|
2146
|
+
*/
|
|
2147
|
+
fitToNodes(options?: {
|
|
2148
|
+
padding?: number;
|
|
2149
|
+
alignment?: FitAlign;
|
|
2150
|
+
}): void;
|
|
2151
|
+
/**
|
|
2152
|
+
* Set the zoom level directly, optionally around a canvas-space center point.
|
|
2153
|
+
* @param zoom The desired zoom level.
|
|
2154
|
+
* @param centerX The x coordinate (canvas space) to keep visually stable during zoom.
|
|
2155
|
+
* @param centerY The y coordinate (canvas space) to keep visually stable during zoom.
|
|
2156
|
+
*/
|
|
2157
|
+
zoomTo(zoom: number, centerX?: number, centerY?: number): void;
|
|
2158
|
+
/**
|
|
2159
|
+
* Zoom the diagram by multiplying current zoom by a factor, optionally around a canvas-space center point.
|
|
2160
|
+
* @param factor The zoom multiplier. Values greater than 1 zoom in and values between 0 and 1 zoom out.
|
|
2161
|
+
* @param centerX The x coordinate (canvas space) to keep visually stable during zoom.
|
|
2162
|
+
* @param centerY The y coordinate (canvas space) to keep visually stable during zoom.
|
|
2163
|
+
*/
|
|
2164
|
+
zoomBy(factor: number, centerX?: number, centerY?: number): void;
|
|
2165
|
+
/**
|
|
2166
|
+
* Pan the diagram by the specified delta values.
|
|
2167
|
+
* @param deltaX The amount to pan in the x direction.
|
|
2168
|
+
* @param deltaY The amount to pan in the y direction.
|
|
2169
|
+
*/
|
|
2170
|
+
panBy(deltaX: number, deltaY: number): void;
|
|
2171
|
+
upsertNode(node: INode): INode;
|
|
2172
|
+
upsertLayer(layer: string | ILayer): ILayer;
|
|
2173
|
+
deleteNode(nodeId: string): void;
|
|
2174
|
+
deleteLayer(layerId: string): void;
|
|
2175
|
+
setNodeImageSource(node: string | INode, imageSrc: string, mode?: 'pattern' | 'frame', imageId?: string): INode | undefined;
|
|
2176
|
+
setNodeSvgSource(node: string | INode, svgOrSrc: string, mode?: 'pattern' | 'frame', imageId?: string): INode | undefined;
|
|
2177
|
+
clearNodeImageSource(node: string | INode): INode | undefined;
|
|
2178
|
+
/**
|
|
2179
|
+
* Renders the diagram onto the canvas, including any selection markers.
|
|
2180
|
+
* By default, both nodes and selection markers are rendered, but this can be controlled with the `what` parameter.
|
|
2181
|
+
* @param what A string indicating what to render: 'nodes' to render only nodes, 'selection' to render only selection markers, 'grid' to render only the grid, or 'all' to render everything.
|
|
2182
|
+
*/
|
|
2183
|
+
render(what?: 'nodes' | 'selection' | 'grid' | 'all'): void;
|
|
2184
|
+
private renderGrid;
|
|
2185
|
+
/**
|
|
2186
|
+
* Resets the viewport to the default position and zoom level, and clears the selection.
|
|
2187
|
+
*/
|
|
2188
|
+
resetView(): void;
|
|
2189
|
+
/**
|
|
2190
|
+
* Exports the full visible diagram content as an image blob.
|
|
2191
|
+
* This export is uncropped and ignores the current viewport pan/zoom.
|
|
2192
|
+
* The exported image will be sized to fit the bounds of all visible nodes, plus optional padding.
|
|
2193
|
+
* @param options The options for writing the image, including padding and MIME type.
|
|
2194
|
+
* @param serializer The serializer to use for writing the image.
|
|
2195
|
+
* @returns A promise that resolves to a Blob containing the exported image.
|
|
2196
|
+
*/
|
|
2197
|
+
exportImage(options?: ImageWriteOptions, serializer?: ImageSerializer): Promise<Blob>;
|
|
2198
|
+
/**
|
|
2199
|
+
* Exports and saves the full visible diagram content as an image file.
|
|
2200
|
+
* In Node.js this writes to the file system; in browsers this triggers a download.
|
|
2201
|
+
*/
|
|
2202
|
+
saveImage(options?: ImageSaveOptions, serializer?: ImageSerializer): Promise<string>;
|
|
2203
|
+
private createExportCanvas;
|
|
2204
|
+
private renderContentToContext;
|
|
2205
|
+
private getImageExtension;
|
|
2206
|
+
/**
|
|
2207
|
+
* Calculate the bounding rectangle that encompasses all visible nodes in the diagram.
|
|
2208
|
+
* @returns The bounding rectangle of all visible nodes, or `undefined` if there are no visible nodes.
|
|
2209
|
+
*/
|
|
2210
|
+
getNodeBounds(): IRect | undefined;
|
|
2211
|
+
/**
|
|
2212
|
+
* Returns the first node found at the specified coordinates, if any.
|
|
2213
|
+
* @param x The x-coordinate to test.
|
|
2214
|
+
* @param y The y-coordinate to test.
|
|
2215
|
+
*/
|
|
2216
|
+
protected hitNode(x: number, y: number): INode | undefined;
|
|
2217
|
+
/**
|
|
2218
|
+
* Returns all nodes at the specified coordinates.
|
|
2219
|
+
* @param x The x-coordinate to test.
|
|
2220
|
+
* @param y The y-coordinate to test.
|
|
2221
|
+
* @returns An array of nodes at the specified coordinates.
|
|
2222
|
+
*/
|
|
2223
|
+
protected hitNodes(x: number, y: number): INode[];
|
|
2224
|
+
/**
|
|
2225
|
+
* Returns the handle at the specified coordinates, if any.
|
|
2226
|
+
* @param x The x-coordinate to test.
|
|
2227
|
+
* @param y The y-coordinate to test.
|
|
2228
|
+
* @param target The target node to test, if any.
|
|
2229
|
+
* @returns The handle at the specified coordinates, or `NodeHandle.NONE` if none is found.
|
|
2230
|
+
*/
|
|
2231
|
+
protected hitHandle(x: number, y: number, target?: INode): NodeHandle;
|
|
2232
|
+
/**
|
|
2233
|
+
* Select the cursor style reflecting a node handle.
|
|
2234
|
+
* @param handle The node handle to determine the cursor style for.
|
|
2235
|
+
* @returns The CSS cursor style for the specified node handle.
|
|
2236
|
+
*/
|
|
2237
|
+
protected getCursor(handle: NodeHandle): string | undefined;
|
|
2238
|
+
/**
|
|
2239
|
+
* Respond to pointer down events on the canvas, handling selection and panning based on the event properties and current selection options.
|
|
2240
|
+
* @param event The pointer event.
|
|
2241
|
+
*/
|
|
2242
|
+
protected pointerDown(event: PointerEvent): void;
|
|
2243
|
+
/**
|
|
2244
|
+
* Respond to pointer move events on the canvas, updating the cursor style based on hit testing and handling panning if the primary button is pressed.
|
|
2245
|
+
* @param event The pointer event.
|
|
2246
|
+
*/
|
|
2247
|
+
protected pointerMove(event: PointerEvent): void;
|
|
2248
|
+
/**
|
|
2249
|
+
* Respond to pointer up events on the canvas, releasing pointer capture and re-rendering the diagram if necessary.
|
|
2250
|
+
* @param event The pointer event.
|
|
2251
|
+
*/
|
|
2252
|
+
protected pointerUp(event: PointerEvent): void;
|
|
2253
|
+
/**
|
|
2254
|
+
* Respond to wheel events on the canvas, handling zooming when the Ctrl or Meta key is pressed and panning otherwise.
|
|
2255
|
+
* @param event The wheel event.
|
|
2256
|
+
*/
|
|
2257
|
+
protected wheel(event: WheelEvent): void;
|
|
2258
|
+
/**
|
|
2259
|
+
* Respond to keydown events on the window, currently does nothing but can be used for keyboard shortcuts in the future.
|
|
2260
|
+
* @param event The keyboard event.
|
|
2261
|
+
*/
|
|
2262
|
+
protected keydown(event: KeyboardEvent): void;
|
|
2263
|
+
/**
|
|
2264
|
+
* Respond to keyup events on the window.
|
|
2265
|
+
* @param event The keyboard event.
|
|
2266
|
+
*/
|
|
2267
|
+
protected keyup(event: KeyboardEvent): void;
|
|
2268
|
+
/**
|
|
2269
|
+
* Respond to context menu events on the canvas, preventing the default context menu from appearing.
|
|
2270
|
+
* @param event The pointer event.
|
|
2271
|
+
*/
|
|
2272
|
+
protected contextmenu(event: PointerEvent): void;
|
|
2273
|
+
private createCanvas;
|
|
2274
|
+
private syncCanvasSize;
|
|
2275
|
+
private bindResizeObserver;
|
|
2276
|
+
private bindCanvasEvents;
|
|
2277
|
+
private emitSelectionChange;
|
|
2278
|
+
private emitNodeClick;
|
|
2279
|
+
private emitBackgroundClick;
|
|
2280
|
+
private emitViewportEvents;
|
|
2281
|
+
private applyInitialView;
|
|
2282
|
+
private initializeSelection;
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2285
|
+
type DiagramEditViewUnsavedAction = 'save' | 'discard' | 'cancel';
|
|
2286
|
+
type DiagramEditViewPromptReason = 'new' | 'open' | 'load';
|
|
2287
|
+
type DiagramEditViewPrompts = {
|
|
2288
|
+
onUnsavedChanges?: (context: {
|
|
2289
|
+
reason: DiagramEditViewPromptReason;
|
|
2290
|
+
}) => DiagramEditViewUnsavedAction | Promise<DiagramEditViewUnsavedAction>;
|
|
2291
|
+
onNoChangesSave?: () => boolean | Promise<boolean>;
|
|
2292
|
+
};
|
|
2293
|
+
/**
|
|
2294
|
+
* A class representing a diagram in edit mode.
|
|
2295
|
+
* It provides tools for selection of nodes as well as mutation of the diagram's structure by user actions.
|
|
2296
|
+
*/
|
|
2297
|
+
declare class DiagramEditView extends DiagramView {
|
|
2298
|
+
protected history: HistoryStack;
|
|
2299
|
+
private zOrder;
|
|
2300
|
+
private color_palette;
|
|
2301
|
+
private zOrderHost;
|
|
2302
|
+
protected current: {
|
|
2303
|
+
layer?: ILayer;
|
|
2304
|
+
tool?: string;
|
|
2305
|
+
toolOptions?: {
|
|
2306
|
+
url?: string;
|
|
2307
|
+
};
|
|
2308
|
+
draft?: INode;
|
|
2309
|
+
zoom_factor: number;
|
|
2310
|
+
};
|
|
2311
|
+
protected settings: {
|
|
2312
|
+
lineWidth: number;
|
|
2313
|
+
startArrow: boolean;
|
|
2314
|
+
endArrow: boolean;
|
|
2315
|
+
strokeColor: string;
|
|
2316
|
+
fillColor: string;
|
|
2317
|
+
shadowStyle: ShadowStyle;
|
|
2318
|
+
fontFace: string;
|
|
2319
|
+
fontSize: number;
|
|
2320
|
+
textColor: string;
|
|
2321
|
+
textAlign: ITextAlign;
|
|
2322
|
+
textBaseline: ITextBaseline;
|
|
2323
|
+
nodeText?: string;
|
|
2324
|
+
};
|
|
2325
|
+
protected palette_mode: 'stroke' | 'fill';
|
|
2326
|
+
protected modified: boolean;
|
|
2327
|
+
protected can_paste: boolean;
|
|
2328
|
+
private clipboardSnapshot;
|
|
2329
|
+
private movedNodes;
|
|
2330
|
+
private resizedNodes;
|
|
2331
|
+
private pointChangedNodes;
|
|
2332
|
+
private connectionBeforeEdit?;
|
|
2333
|
+
protected activeTextEditor?: {
|
|
2334
|
+
element: HTMLTextAreaElement;
|
|
2335
|
+
nodeId: string;
|
|
2336
|
+
originalText: string;
|
|
2337
|
+
};
|
|
2338
|
+
fileDialogs?: DiagramFileDialogs;
|
|
2339
|
+
prompts?: DiagramEditViewPrompts;
|
|
2340
|
+
/**
|
|
2341
|
+
* Creates an instance of DiagramEditView.
|
|
2342
|
+
* @param id The unique identifier for the diagram.
|
|
2343
|
+
* @param target The HTML element or canvas where the diagram will be rendered.
|
|
2344
|
+
* @param initial Optional initial properties for the diagram.
|
|
2345
|
+
*/
|
|
2346
|
+
constructor(id: string, target: HTMLElement | HTMLCanvasElement, initial?: Partial<Omit<Diagram, 'id'>>);
|
|
2347
|
+
/**
|
|
2348
|
+
* Cleans up resources used by the diagram, such as event listeners and active text editors.
|
|
2349
|
+
*/
|
|
2350
|
+
destroy(): void;
|
|
2351
|
+
clear(): void;
|
|
2352
|
+
get canOpenDiagram(): boolean;
|
|
2353
|
+
/**
|
|
2354
|
+
* Clears the current diagram after resolving any unsaved-change prompt.
|
|
2355
|
+
* A prompt will be shown if the diagram has unsaved changes.
|
|
2356
|
+
* @returns True when a new empty diagram was created; otherwise false.
|
|
2357
|
+
*/
|
|
2358
|
+
newDiagram(): Promise<boolean>;
|
|
2359
|
+
/**
|
|
2360
|
+
* Loads a diagram from a live diagram instance, a serialized JSON string, or a deserialized payload.
|
|
2361
|
+
* A prompt will be shown if the diagram has unsaved changes.
|
|
2362
|
+
* @param source The diagram source to load.
|
|
2363
|
+
* @returns True when the source was loaded; otherwise false when loading was canceled.
|
|
2364
|
+
*/
|
|
2365
|
+
loadDiagram(source: DiagramOpenSource): Promise<boolean>;
|
|
2366
|
+
/**
|
|
2367
|
+
* Opens a diagram using configured file dialog behavior after resolving unsaved-change prompts.
|
|
2368
|
+
* @param options Optional open options or source overrides.
|
|
2369
|
+
* @returns True when a diagram was opened; otherwise false.
|
|
2370
|
+
*/
|
|
2371
|
+
openDiagram(options?: DiagramOpenOptions): Promise<boolean>;
|
|
2372
|
+
saveDiagram(options?: DiagramSaveOptions): Promise<string | undefined>;
|
|
2373
|
+
exportDiagram(options?: DiagramExportOptions): Promise<string | Uint8Array | Blob | undefined>;
|
|
2374
|
+
private applyDiagramSource;
|
|
2375
|
+
private confirmReplaceIfNeeded;
|
|
2376
|
+
private confirmSaveWithoutChangesIfNeeded;
|
|
2377
|
+
/**
|
|
2378
|
+
* Gets the active render mode for this view.
|
|
2379
|
+
*/
|
|
2380
|
+
get render_mode(): 'view' | 'editing';
|
|
2381
|
+
/**
|
|
2382
|
+
* Gets the current default line width for borders and connections.
|
|
2383
|
+
*/
|
|
2384
|
+
get lineWidth(): number;
|
|
2385
|
+
/**
|
|
2386
|
+
* Sets the default line width and applies it to current selection.
|
|
2387
|
+
* @param value Line width value.
|
|
2388
|
+
*/
|
|
2389
|
+
set lineWidth(value: number);
|
|
2390
|
+
/**
|
|
2391
|
+
* Sets the default arrow direction and applies it to current selection.
|
|
2392
|
+
* @param value Arrow direction value.
|
|
2393
|
+
*/
|
|
2394
|
+
set arrow(value: ArrowDirection);
|
|
2395
|
+
/**
|
|
2396
|
+
* Gets the current default stroke color.
|
|
2397
|
+
*/
|
|
2398
|
+
get strokeColor(): string;
|
|
2399
|
+
/**
|
|
2400
|
+
* Sets the default stroke color and applies it to current selection.
|
|
2401
|
+
* @param value Stroke color value.
|
|
2402
|
+
*/
|
|
2403
|
+
set strokeColor(value: string);
|
|
2404
|
+
/**
|
|
2405
|
+
* Gets the current default fill color.
|
|
2406
|
+
*/
|
|
2407
|
+
get fillColor(): string;
|
|
2408
|
+
/**
|
|
2409
|
+
* Sets the default fill color and applies it to current selection.
|
|
2410
|
+
* @param value Fill color value.
|
|
2411
|
+
*/
|
|
2412
|
+
set fillColor(value: string);
|
|
2413
|
+
/**
|
|
2414
|
+
* Gets the current default text color.
|
|
2415
|
+
*/
|
|
2416
|
+
get textColor(): string;
|
|
2417
|
+
/**
|
|
2418
|
+
* Sets the default text color and applies it to current selection.
|
|
2419
|
+
* @param value Text color value.
|
|
2420
|
+
*/
|
|
2421
|
+
set textColor(value: string);
|
|
2422
|
+
/**
|
|
2423
|
+
* Gets the current default shadow style.
|
|
2424
|
+
*/
|
|
2425
|
+
get shadowStyle(): ShadowStyle;
|
|
2426
|
+
/**
|
|
2427
|
+
* Sets the default shadow style and applies it to current selection.
|
|
2428
|
+
* @param value Shadow style value.
|
|
2429
|
+
*/
|
|
2430
|
+
set shadowStyle(value: ShadowStyle);
|
|
2431
|
+
/**
|
|
2432
|
+
* Gets the current default font family.
|
|
2433
|
+
*/
|
|
2434
|
+
get fontFace(): string;
|
|
2435
|
+
/**
|
|
2436
|
+
* Sets the default font family and applies it to current selection.
|
|
2437
|
+
* @param value Font family value.
|
|
2438
|
+
*/
|
|
2439
|
+
set fontFace(value: string);
|
|
2440
|
+
/**
|
|
2441
|
+
* Gets the current default font size.
|
|
2442
|
+
*/
|
|
2443
|
+
get fontSize(): number;
|
|
2444
|
+
/**
|
|
2445
|
+
* Sets the default font size and applies it to current selection.
|
|
2446
|
+
* @param value Font size value.
|
|
2447
|
+
*/
|
|
2448
|
+
set fontSize(value: number);
|
|
2449
|
+
/**
|
|
2450
|
+
* Gets the current default horizontal text alignment.
|
|
2451
|
+
*/
|
|
2452
|
+
get textAlign(): ITextAlign;
|
|
2453
|
+
/**
|
|
2454
|
+
* Sets the default horizontal text alignment and applies it to current selection.
|
|
2455
|
+
* @param value Text alignment value.
|
|
2456
|
+
*/
|
|
2457
|
+
set textAlign(value: ITextAlign);
|
|
2458
|
+
/**
|
|
2459
|
+
* Gets the current default vertical text baseline.
|
|
2460
|
+
*/
|
|
2461
|
+
get textBaseline(): ITextBaseline;
|
|
2462
|
+
/**
|
|
2463
|
+
* Sets the default vertical text baseline and applies it to current selection.
|
|
2464
|
+
* @param value Text baseline value.
|
|
2465
|
+
*/
|
|
2466
|
+
set textBaseline(value: ITextBaseline);
|
|
2467
|
+
/**
|
|
2468
|
+
* Gets the default node text for newly created text-capable nodes.
|
|
2469
|
+
*/
|
|
2470
|
+
get nodeText(): string | undefined;
|
|
2471
|
+
/**
|
|
2472
|
+
* Sets the default node text for newly created text-capable nodes.
|
|
2473
|
+
* @param value Text value.
|
|
2474
|
+
*/
|
|
2475
|
+
set nodeText(value: string | undefined);
|
|
2476
|
+
/**
|
|
2477
|
+
* Gets the currently active tool identifier.
|
|
2478
|
+
*/
|
|
2479
|
+
get currentTool(): string;
|
|
2480
|
+
get canPaste(): boolean;
|
|
2481
|
+
/**
|
|
2482
|
+
* Sets the current tool for the diagram.
|
|
2483
|
+
* The default tool is 'select', which allows for selection and manipulation of existing nodes.
|
|
2484
|
+
* @param tool The name of the tool to set.
|
|
2485
|
+
* @param options Optional parameters for the tool.
|
|
2486
|
+
* @returns A promise that resolves when the tool is set.
|
|
2487
|
+
*/
|
|
2488
|
+
setTool(tool: string, options?: any): Promise<void>;
|
|
2489
|
+
/**
|
|
2490
|
+
* Sets the stroke color for the selected nodes and new nodes to be created.
|
|
2491
|
+
* @param color The stroke color to set.
|
|
2492
|
+
*/
|
|
2493
|
+
setStrokeColor(color: string): void;
|
|
2494
|
+
/**
|
|
2495
|
+
* Sets the fill color for the selected nodes and new nodes to be created.
|
|
2496
|
+
* @param color The fill color to set.
|
|
2497
|
+
*/
|
|
2498
|
+
setFillColor(color: string): void;
|
|
2499
|
+
/**
|
|
2500
|
+
* Sets the text color for the selected nodes and default style state.
|
|
2501
|
+
* @param color The text color to apply.
|
|
2502
|
+
*/
|
|
2503
|
+
setTextColor(color: string): void;
|
|
2504
|
+
/**
|
|
2505
|
+
* Sets the line width for the selected nodes and new nodes to be created.
|
|
2506
|
+
* @param width The line width to set.
|
|
2507
|
+
*/
|
|
2508
|
+
setLineWidth(width: number): void;
|
|
2509
|
+
/**
|
|
2510
|
+
* Sets the arrow direction for the selected nodes and new nodes to be created.
|
|
2511
|
+
* @param arrow The arrow direction to set.
|
|
2512
|
+
*/
|
|
2513
|
+
setArrow(arrow: ArrowDirection): void;
|
|
2514
|
+
/**
|
|
2515
|
+
* Sets the shadow style for the selected nodes and new nodes to be created.
|
|
2516
|
+
* @param style The shadow style to set.
|
|
2517
|
+
*/
|
|
2518
|
+
setShadowStyle(style: ShadowStyle): void;
|
|
2519
|
+
/**
|
|
2520
|
+
* Sets the font face for the selected nodes and new nodes to be created.
|
|
2521
|
+
* @param face The font face to set.
|
|
2522
|
+
*/
|
|
2523
|
+
setFontFace(face: string): void;
|
|
2524
|
+
/**
|
|
2525
|
+
* Sets the font size for the selected nodes and new nodes to be created.
|
|
2526
|
+
* @param size The font size to set.
|
|
2527
|
+
*/
|
|
2528
|
+
setFontSize(size: number): void;
|
|
2529
|
+
/**
|
|
2530
|
+
* Sets the text alignment for the selected nodes and new nodes to be created.
|
|
2531
|
+
* @param align The text alignment to set.
|
|
2532
|
+
*/
|
|
2533
|
+
setTextAlign(align: ITextAlign | string): void;
|
|
2534
|
+
/**
|
|
2535
|
+
* Sets the text baseline for the selected nodes and new nodes to be created.
|
|
2536
|
+
* @param align The text baseline to set.
|
|
2537
|
+
*/
|
|
2538
|
+
setTextBaseline(align: ITextBaseline | string): void;
|
|
2539
|
+
/**
|
|
2540
|
+
* Sets the text for the selected nodes and new nodes to be created.
|
|
2541
|
+
* @param text The text to set.
|
|
2542
|
+
*/
|
|
2543
|
+
setNodeText(text: string): void;
|
|
2544
|
+
/**
|
|
2545
|
+
* Updates the grid settings for the diagram and re-renders it to reflect the changes.
|
|
2546
|
+
* @param json A partial object containing the grid properties to update. Only the provided properties will be updated, while the others will remain unchanged.
|
|
2547
|
+
*/
|
|
2548
|
+
updateGrid(json: Partial<IGrid>): void;
|
|
2549
|
+
/**
|
|
2550
|
+
* List colors used in this diagram in descening order of their usage frequency.
|
|
2551
|
+
* @returns Colors as an array of strings.
|
|
2552
|
+
*/
|
|
2553
|
+
getFrequentColors(): string[];
|
|
2554
|
+
/**
|
|
2555
|
+
* Indicates whether the diagram contains unsaved modifications.
|
|
2556
|
+
*/
|
|
2557
|
+
isModified(): boolean;
|
|
2558
|
+
/**
|
|
2559
|
+
* Take a snapshot of the current diagram state and push it onto the undo stack.
|
|
2560
|
+
* This should be called before making any changes to the diagram that should be undoable.
|
|
2561
|
+
* After calling this method, the `canUndo` property will return true, indicating that there is now an action in the undo stack that can be undone.
|
|
2562
|
+
*/
|
|
2563
|
+
protected addUndo(): void;
|
|
2564
|
+
/**
|
|
2565
|
+
* Returns true if there are actions in the undo stack that can be undone, false otherwise.
|
|
2566
|
+
* @returns A boolean indicating whether an undo operation can be performed.
|
|
2567
|
+
*/
|
|
2568
|
+
get canUndo(): boolean;
|
|
2569
|
+
/**
|
|
2570
|
+
* Returns true if there are actions in the redo stack that can be redone, false otherwise.
|
|
2571
|
+
* @returns A boolean indicating whether a redo operation can be performed.
|
|
2572
|
+
*/
|
|
2573
|
+
get canRedo(): boolean;
|
|
2574
|
+
/**
|
|
2575
|
+
* Undoes the last action performed on the diagram, reverting it to the previous state.
|
|
2576
|
+
*/
|
|
2577
|
+
undo(): Promise<void>;
|
|
2578
|
+
/**
|
|
2579
|
+
* Redoes the last undone action on the diagram, restoring it to the state before the undo was performed.
|
|
2580
|
+
*/
|
|
2581
|
+
redo(): Promise<void>;
|
|
2582
|
+
/**
|
|
2583
|
+
* Cuts the selected nodes, copying them to the clipboard and then deleting them from the diagram.
|
|
2584
|
+
*/
|
|
2585
|
+
cutSelected(): void;
|
|
2586
|
+
/**
|
|
2587
|
+
* Copies the selected nodes to the clipboard in JSON format.
|
|
2588
|
+
* The copied data includes all properties of the nodes, allowing for accurate reconstruction when pasted.
|
|
2589
|
+
* After copying, the `canPaste` flag is set to true, indicating that there is data available in the clipboard that can be pasted into the diagram.
|
|
2590
|
+
*/
|
|
2591
|
+
copySelected(operation?: DiagramClipboardOperation): void;
|
|
2592
|
+
/**
|
|
2593
|
+
* Pastes nodes from the clipboard into the diagram.
|
|
2594
|
+
*/
|
|
2595
|
+
pasteNodes(): void;
|
|
2596
|
+
/**
|
|
2597
|
+
* Checks if the clipboard contains nodes that can be pasted into the diagram.
|
|
2598
|
+
*/
|
|
2599
|
+
clipboardHasNodes(): void;
|
|
2600
|
+
private writeClipboardText;
|
|
2601
|
+
private readClipboardText;
|
|
2602
|
+
private emitClipboardChange;
|
|
2603
|
+
private parseClipboardNodes;
|
|
2604
|
+
/**
|
|
2605
|
+
* Select a layer to be the target for new nodes and operations.
|
|
2606
|
+
* @param layer The layer to set as the current layer.
|
|
2607
|
+
*/
|
|
2608
|
+
setCurrentLayer(layer: ILayer): void;
|
|
2609
|
+
/**
|
|
2610
|
+
* Adds a new layer to the diagram at the specified position.
|
|
2611
|
+
* @param id The layer ID.
|
|
2612
|
+
* @param place The position to add the new layer ('top' or 'bottom').
|
|
2613
|
+
*/
|
|
2614
|
+
addLayer(id: string, place?: 'top' | 'bottom'): void;
|
|
2615
|
+
/**
|
|
2616
|
+
* Moves the selected nodes to a new layer.
|
|
2617
|
+
*/
|
|
2618
|
+
moveToNewLayer(): void;
|
|
2619
|
+
/**
|
|
2620
|
+
* Selects all nodes within the specified layer.
|
|
2621
|
+
* @param layer The layer whose nodes should be selected.
|
|
2622
|
+
*/
|
|
2623
|
+
selectLayer(layer: ILayer): void;
|
|
2624
|
+
/**
|
|
2625
|
+
* Shows the specified layer, making it visible in the diagram.
|
|
2626
|
+
* @param layer The layer to show.
|
|
2627
|
+
*/
|
|
2628
|
+
showLayer(layer: ILayer): void;
|
|
2629
|
+
/**
|
|
2630
|
+
* Hides the specified layer, making it invisible in the diagram.
|
|
2631
|
+
* Hidden layers are not rendered and their nodes cannot be interacted with until they are shown again.
|
|
2632
|
+
* @param layer The layer to hide.
|
|
2633
|
+
*/
|
|
2634
|
+
hideLayer(layer: ILayer): void;
|
|
2635
|
+
/**
|
|
2636
|
+
* Deletes the specified layer from the diagram.
|
|
2637
|
+
* @param layerId The ID of the layer to delete.
|
|
2638
|
+
*/
|
|
2639
|
+
deleteLayer(layerId: string): void;
|
|
2640
|
+
/**
|
|
2641
|
+
* Moves selected nodes one step toward the front, confined within their layers.
|
|
2642
|
+
*/
|
|
2643
|
+
bringSelectionForward(): void;
|
|
2644
|
+
/**
|
|
2645
|
+
* Moves selected nodes one step toward the back, confined within their layers.
|
|
2646
|
+
*/
|
|
2647
|
+
sendSelectionBackward(): void;
|
|
2648
|
+
/**
|
|
2649
|
+
* Moves selected nodes to the front, confined within their layers.
|
|
2650
|
+
*/
|
|
2651
|
+
bringSelectionToFront(): void;
|
|
2652
|
+
/**
|
|
2653
|
+
* Moves selected nodes to the back, confined within their layers.
|
|
2654
|
+
*/
|
|
2655
|
+
sendSelectionToBack(): void;
|
|
2656
|
+
/**
|
|
2657
|
+
* Moves a node one step toward the front, confined within its layer.
|
|
2658
|
+
* @param node The target node or node ID.
|
|
2659
|
+
*/
|
|
2660
|
+
bringNodeForward(node: string | INode): void;
|
|
2661
|
+
/**
|
|
2662
|
+
* Moves a node one step toward the back, confined within its layer.
|
|
2663
|
+
* @param node The target node or node ID.
|
|
2664
|
+
*/
|
|
2665
|
+
sendNodeBackward(node: string | INode): void;
|
|
2666
|
+
/**
|
|
2667
|
+
* Moves a node to the front, confined within its layer.
|
|
2668
|
+
* @param node The target node or node ID.
|
|
2669
|
+
*/
|
|
2670
|
+
bringNodeToFront(node: string | INode): void;
|
|
2671
|
+
/**
|
|
2672
|
+
* Moves a node to the back, confined within its layer.
|
|
2673
|
+
* @param node The target node or node ID.
|
|
2674
|
+
*/
|
|
2675
|
+
sendNodeToBack(node: string | INode): void;
|
|
2676
|
+
/**
|
|
2677
|
+
* Moves a layer one step toward the front.
|
|
2678
|
+
* @param layer The target layer or layer ID.
|
|
2679
|
+
*/
|
|
2680
|
+
bringLayerForward(layer: string | ILayer): void;
|
|
2681
|
+
/**
|
|
2682
|
+
* Moves a layer one step toward the back.
|
|
2683
|
+
* @param layer The target layer or layer ID.
|
|
2684
|
+
*/
|
|
2685
|
+
sendLayerBackward(layer: string | ILayer): void;
|
|
2686
|
+
/**
|
|
2687
|
+
* Moves a layer to the front.
|
|
2688
|
+
* @param layer The target layer or layer ID.
|
|
2689
|
+
*/
|
|
2690
|
+
bringLayerToFront(layer: string | ILayer): void;
|
|
2691
|
+
/**
|
|
2692
|
+
* Moves a layer to the back.
|
|
2693
|
+
* @param layer The target layer or layer ID.
|
|
2694
|
+
*/
|
|
2695
|
+
sendLayerToBack(layer: string | ILayer): void;
|
|
2696
|
+
/**
|
|
2697
|
+
* Deletes the currently selected nodes from the diagram.
|
|
2698
|
+
*/
|
|
2699
|
+
deleteSelected(): void;
|
|
2700
|
+
/**
|
|
2701
|
+
* Clones the currently selected nodes in the diagram.
|
|
2702
|
+
* The cloned nodes are offset by 24 pixels in both x and y directions.
|
|
2703
|
+
*/
|
|
2704
|
+
cloneSelected(): Promise<void>;
|
|
2705
|
+
protected cloneNode(node: INode | ISerializedNode, id?: string): INode;
|
|
2706
|
+
/**
|
|
2707
|
+
* Sets the arrow type for the currently selected connection.
|
|
2708
|
+
* @param where Specifies which end(s) of the connection should have arrows.
|
|
2709
|
+
*/
|
|
2710
|
+
pickArrow(where: 'start' | 'end' | 'both' | 'none'): void;
|
|
2711
|
+
/**
|
|
2712
|
+
* Changes the type of the specified node.
|
|
2713
|
+
* @param node The node or node ID to change the type of.
|
|
2714
|
+
* @param type The new type to assign to the node.
|
|
2715
|
+
*/
|
|
2716
|
+
changeType(node: string | INode, type: string): void;
|
|
2717
|
+
/**
|
|
2718
|
+
* Aligns the currently selected nodes in the specified direction.
|
|
2719
|
+
* @param dir The direction to align the nodes ('left', 'right', 'center', 'top', 'bottom', 'middle').
|
|
2720
|
+
*/
|
|
2721
|
+
alignSelected(dir: 'left' | 'right' | 'center' | 'top' | 'bottom' | 'middle'): void;
|
|
2722
|
+
/**
|
|
2723
|
+
* Spreads the currently selected nodes evenly in the specified direction.
|
|
2724
|
+
* @param dir The direction to spread the nodes ('row' or 'column').
|
|
2725
|
+
*/
|
|
2726
|
+
spreadSelected(dir: 'row' | 'column'): void;
|
|
2727
|
+
render(what?: 'nodes' | 'selection' | 'all'): void;
|
|
2728
|
+
/**
|
|
2729
|
+
* Renders the selection markers for the specified node or all selected nodes if no node is specified.
|
|
2730
|
+
* @param node The node to render selection markers for. If not provided, all selected nodes are rendered.
|
|
2731
|
+
*/
|
|
2732
|
+
renderSelection(node?: INode): void;
|
|
2733
|
+
/**
|
|
2734
|
+
* Respond to pointer down events on the canvas, handling selection, panning, creation, and modification based on the event properties and current selection options.
|
|
2735
|
+
* @param event The pointer event.
|
|
2736
|
+
*/
|
|
2737
|
+
protected pointerDown(event: PointerEvent): void;
|
|
2738
|
+
/**
|
|
2739
|
+
* Respond to pointer move events on the canvas, handling selection, panning, creation, and modification based on the event properties and current selection options.
|
|
2740
|
+
* @param event The pointer event.
|
|
2741
|
+
*/
|
|
2742
|
+
protected pointerMove(event: PointerEvent): void;
|
|
2743
|
+
/**
|
|
2744
|
+
* Respond to pointer up events on the canvas, handling selection, panning, creation, and modification based on the event properties and current selection options.
|
|
2745
|
+
* @param event The pointer event.
|
|
2746
|
+
*/
|
|
2747
|
+
protected pointerUp(event: PointerEvent): void;
|
|
2748
|
+
/**
|
|
2749
|
+
* Respond to key down events, handling deletion, copying, pasting, cutting, undoing, and exiting drawing mode based on the event properties and current selection state.
|
|
2750
|
+
* @param event The keyboard event.
|
|
2751
|
+
*/
|
|
2752
|
+
protected keydown(event: KeyboardEvent): void;
|
|
2753
|
+
protected keyup(event: KeyboardEvent): void;
|
|
2754
|
+
/**
|
|
2755
|
+
* Respond to context menu events on the canvas, preventing the default context menu from appearing.
|
|
2756
|
+
* @param event The pointer event.
|
|
2757
|
+
*/
|
|
2758
|
+
protected contextmenu(event: PointerEvent): void;
|
|
2759
|
+
downPos?: IPoint;
|
|
2760
|
+
downShape?: INode;
|
|
2761
|
+
downHandle?: NodeHandle;
|
|
2762
|
+
downRect?: IRect;
|
|
2763
|
+
private selectDown;
|
|
2764
|
+
private selectMove;
|
|
2765
|
+
private selectUp;
|
|
2766
|
+
private createDown;
|
|
2767
|
+
private createMove;
|
|
2768
|
+
private createUp;
|
|
2769
|
+
private hasCreateTool;
|
|
2770
|
+
private isMultistepCreate;
|
|
2771
|
+
private isConnectorType;
|
|
2772
|
+
private hasTextInput;
|
|
2773
|
+
private updateConnectorDraftReadiness;
|
|
2774
|
+
private resolveAnchorNode;
|
|
2775
|
+
private renderConnectorTargets;
|
|
2776
|
+
private previewConnectorTargets;
|
|
2777
|
+
private createDraftFromCurrent;
|
|
2778
|
+
private finishDraftIfReady;
|
|
2779
|
+
init(): Promise<void>;
|
|
2780
|
+
/**
|
|
2781
|
+
* Renders preview output for the provided layer.
|
|
2782
|
+
* @param layer Optional layer to preview.
|
|
2783
|
+
*/
|
|
2784
|
+
renderPreview(layer?: ILayer): void;
|
|
2785
|
+
private applyText;
|
|
2786
|
+
private createLayerAt;
|
|
2787
|
+
private ensureCurrentLayer;
|
|
2788
|
+
private generateLayerId;
|
|
2789
|
+
private exitDrawing;
|
|
2790
|
+
private editText;
|
|
2791
|
+
private closeTextEditor;
|
|
2792
|
+
private normalizeRect;
|
|
2793
|
+
private renderSelectionRect;
|
|
2794
|
+
private applyRectSelection;
|
|
2795
|
+
private selectionAdapter;
|
|
2796
|
+
private moveSelected;
|
|
2797
|
+
private resizeSelected;
|
|
2798
|
+
private moveSelectedPoint;
|
|
2799
|
+
private emitPendingMutationEvents;
|
|
2800
|
+
private emitNodeAdded;
|
|
2801
|
+
private emitNodeDeleted;
|
|
2802
|
+
private emitNodeMoved;
|
|
2803
|
+
private emitNodeResized;
|
|
2804
|
+
private emitNodePointsChanged;
|
|
2805
|
+
private emitConnectionConnected;
|
|
2806
|
+
private emitConnectionDisconnected;
|
|
2807
|
+
private emitConnectionChanges;
|
|
2808
|
+
private captureConnectionState;
|
|
2809
|
+
private anchorSignature;
|
|
2810
|
+
private connectionTargetsNode;
|
|
2811
|
+
private reflectStyles;
|
|
2812
|
+
/**
|
|
2813
|
+
* Opens SVG tool/image selection workflow.
|
|
2814
|
+
*/
|
|
2815
|
+
pickSVG(): void;
|
|
2816
|
+
/**
|
|
2817
|
+
* Opens image selection workflow for the current node selection.
|
|
2818
|
+
*/
|
|
2819
|
+
pickNodeImage(): void;
|
|
2820
|
+
/**
|
|
2821
|
+
* Applies a selected image file to the current node selection.
|
|
2822
|
+
* @param event File input event or undefined to trigger picker flow.
|
|
2823
|
+
*/
|
|
2824
|
+
setNodeImage(event?: any): void;
|
|
2825
|
+
/**
|
|
2826
|
+
* Applies an image source to all currently selected nodes.
|
|
2827
|
+
*/
|
|
2828
|
+
setSelectedNodeImageSource(imageSrc: string, mode?: 'pattern' | 'frame', imageId?: string): void;
|
|
2829
|
+
/**
|
|
2830
|
+
* Applies SVG markup or source URL/data URL to all currently selected nodes.
|
|
2831
|
+
*/
|
|
2832
|
+
setSelectedNodeSvgSource(svgOrSrc: string, mode?: 'pattern' | 'frame', imageId?: string): void;
|
|
2833
|
+
/**
|
|
2834
|
+
* Clears image source configuration from all currently selected nodes.
|
|
2835
|
+
*/
|
|
2836
|
+
clearSelectedNodeImageSource(): void;
|
|
2837
|
+
showActions(): void;
|
|
2838
|
+
}
|
|
2839
|
+
|
|
2840
|
+
type ZOrderAction = 'bringForward' | 'bringToFront' | 'sendBackward' | 'sendToBack';
|
|
2841
|
+
interface ZOrderHost {
|
|
2842
|
+
layers: ILayer[];
|
|
2843
|
+
selection(): INode[];
|
|
2844
|
+
layer(id: string): ILayer | undefined;
|
|
2845
|
+
addUndo(): void;
|
|
2846
|
+
render(what?: 'nodes' | 'selection' | 'all'): void;
|
|
2847
|
+
renderPreview(layer?: ILayer): void;
|
|
2848
|
+
}
|
|
2849
|
+
/**
|
|
2850
|
+
* Handles z-ordering of nodes and layers in the diagram. This class is used by DiagramEditView to implement the z-ordering methods.
|
|
2851
|
+
* The ZOrder class provides methods to reorder nodes and layers based on a specified action (bring forward, send backward, bring to front, send to back).
|
|
2852
|
+
* It operates on the current selection of nodes or a specific layer/node as needed.
|
|
2853
|
+
* The class ensures that any changes to the z-ordering are properly tracked for undo functionality and that the diagram is re-rendered to reflect the changes.
|
|
2854
|
+
*/
|
|
2855
|
+
declare class ZOrder {
|
|
2856
|
+
private host;
|
|
2857
|
+
/**
|
|
2858
|
+
* Creates an instance of ZOrder and attaches it to a ZOrderHost (e.g., DiagramEditView).
|
|
2859
|
+
* This allows the ZOrder instance to manipulate the layers and nodes of the host diagram when reordering.
|
|
2860
|
+
* @param host The ZOrderHost instance to attach to, which provides access to the diagram's layers, selection, and rendering methods.
|
|
2861
|
+
*/
|
|
2862
|
+
constructor(host: ZOrderHost);
|
|
2863
|
+
/**
|
|
2864
|
+
* Reorders the currently selected nodes based on the specified action.
|
|
2865
|
+
* Changes are made to the attached host's layers and nodes, and the diagram is re-rendered to reflect the new z-ordering.
|
|
2866
|
+
* @param action The z-order action to perform (bring forward, send backward, bring to front, send to back).
|
|
2867
|
+
*/
|
|
2868
|
+
reorderSelection(action: ZOrderAction): void;
|
|
2869
|
+
/**
|
|
2870
|
+
* Reorders the specified layer based on the given action.
|
|
2871
|
+
* Changes are made to the attached host's layers, and the diagram is re-rendered to reflect the new z-ordering.
|
|
2872
|
+
* @param layer The target layer or layer ID to reorder.
|
|
2873
|
+
* @param action The z-order action to perform (bring forward, send backward, bring to front, send to back).
|
|
2874
|
+
*/
|
|
2875
|
+
reorderLayer(layer: string | ILayer, action: ZOrderAction): void;
|
|
2876
|
+
/**
|
|
2877
|
+
* Reorders the specified node based on the given action, confined within its layer.
|
|
2878
|
+
* Changes are made to the attached host's layers, and the diagram is re-rendered to reflect the new z-ordering.
|
|
2879
|
+
* @param node The target node or node ID to reorder.
|
|
2880
|
+
* @param action The z-order action to perform (bring forward, send backward, bring to front, send to back).
|
|
2881
|
+
*/
|
|
2882
|
+
reorderNode(node: string | INode, action: ZOrderAction): void;
|
|
2883
|
+
private reorderSelected;
|
|
2884
|
+
private hasChanged;
|
|
2885
|
+
}
|
|
2886
|
+
|
|
2887
|
+
/**
|
|
2888
|
+
* Stores image asset sources and stable asset identifiers for diagram nodes.
|
|
2889
|
+
*
|
|
2890
|
+
* This cache supports registration, lookup by id, bulk load/snapshot,
|
|
2891
|
+
* and deterministic id generation for non-URL sources.
|
|
2892
|
+
*/
|
|
2893
|
+
declare class AssetStore {
|
|
2894
|
+
private assetsById;
|
|
2895
|
+
private assetIdBySource;
|
|
2896
|
+
/**
|
|
2897
|
+
* Registers an asset source and returns its asset id.
|
|
2898
|
+
* @param source Asset source URL or serialized value.
|
|
2899
|
+
* @param preferredId Optional preferred id if it is available.
|
|
2900
|
+
* @returns The assigned asset id, or an empty string for blank input.
|
|
2901
|
+
*/
|
|
2902
|
+
register(source: string, preferredId?: string): string;
|
|
2903
|
+
/**
|
|
2904
|
+
* Resolves an asset id to its source value.
|
|
2905
|
+
* @param imageId Asset id to resolve.
|
|
2906
|
+
* @returns Asset source when present; otherwise undefined.
|
|
2907
|
+
*/
|
|
2908
|
+
resolve(imageId?: string): string | undefined;
|
|
2909
|
+
/**
|
|
2910
|
+
* Replaces the store contents from a serialized asset map.
|
|
2911
|
+
* @param assets Serialized assets keyed by id.
|
|
2912
|
+
*/
|
|
2913
|
+
load(assets?: Record<string, string>): void;
|
|
2914
|
+
/**
|
|
2915
|
+
* Creates a serializable snapshot of the current asset map.
|
|
2916
|
+
* @returns Asset map when non-empty; otherwise undefined.
|
|
2917
|
+
*/
|
|
2918
|
+
snapshot(): Record<string, string> | undefined;
|
|
2919
|
+
/**
|
|
2920
|
+
* Clears all cached asset mappings.
|
|
2921
|
+
*/
|
|
2922
|
+
clear(): void;
|
|
2923
|
+
/**
|
|
2924
|
+
* Releases store resources.
|
|
2925
|
+
*/
|
|
2926
|
+
destroy(): void;
|
|
2927
|
+
private createHashedAssetId;
|
|
2928
|
+
private hashString;
|
|
2929
|
+
private looksLikeRemoteUrl;
|
|
2930
|
+
}
|
|
2931
|
+
|
|
2932
|
+
/** Default custom element tag name for the view-only diagram host. */
|
|
2933
|
+
declare const DIAGRAM_VIEW_TAG = "pz-diagram-view";
|
|
2934
|
+
/**
|
|
2935
|
+
* Custom element wrapper that hosts a {@link DiagramView} instance.
|
|
2936
|
+
*
|
|
2937
|
+
* The element recreates its internal view when input properties change,
|
|
2938
|
+
* allowing declarative usage through attributes/properties.
|
|
2939
|
+
*/
|
|
2940
|
+
declare class DiagramViewElement extends HTMLElement {
|
|
2941
|
+
/** Attributes observed by the custom element runtime. */
|
|
2942
|
+
static get observedAttributes(): string[];
|
|
2943
|
+
private viewInstance?;
|
|
2944
|
+
private viewId;
|
|
2945
|
+
private initialState?;
|
|
2946
|
+
private initialOptions?;
|
|
2947
|
+
/** Returns the current DiagramView instance when initialized. */
|
|
2948
|
+
get view(): DiagramView | undefined;
|
|
2949
|
+
/** Gets the diagram identifier used to initialize the internal view. */
|
|
2950
|
+
get diagramId(): string;
|
|
2951
|
+
/**
|
|
2952
|
+
* Sets the diagram identifier and recreates the internal view when changed.
|
|
2953
|
+
* @param value New diagram id.
|
|
2954
|
+
*/
|
|
2955
|
+
set diagramId(value: string);
|
|
2956
|
+
/** Gets the initial diagram state used when creating the internal view. */
|
|
2957
|
+
get diagram(): Partial<Omit<Diagram, 'id'>> | undefined;
|
|
2958
|
+
/**
|
|
2959
|
+
* Sets initial diagram data and recreates the internal view when connected.
|
|
2960
|
+
* @param value Initial diagram state.
|
|
2961
|
+
*/
|
|
2962
|
+
set diagram(value: Partial<Omit<Diagram, 'id'>> | undefined);
|
|
2963
|
+
/** Gets initial view options used when creating the internal view. */
|
|
2964
|
+
get options(): DiagramViewOptions | undefined;
|
|
2965
|
+
/**
|
|
2966
|
+
* Sets view options and recreates the internal view when connected.
|
|
2967
|
+
* @param value Initial view options.
|
|
2968
|
+
*/
|
|
2969
|
+
set options(value: DiagramViewOptions | undefined);
|
|
2970
|
+
/**
|
|
2971
|
+
* Lifecycle callback fired when the element is attached to the DOM.
|
|
2972
|
+
*/
|
|
2973
|
+
connectedCallback(): void;
|
|
2974
|
+
/**
|
|
2975
|
+
* Lifecycle callback fired when the element is detached from the DOM.
|
|
2976
|
+
*/
|
|
2977
|
+
disconnectedCallback(): void;
|
|
2978
|
+
/**
|
|
2979
|
+
* Reacts to observed attribute changes.
|
|
2980
|
+
* @param name Attribute name.
|
|
2981
|
+
* @param _oldValue Previous attribute value.
|
|
2982
|
+
* @param newValue New attribute value.
|
|
2983
|
+
*/
|
|
2984
|
+
attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
|
|
2985
|
+
/** Recreates the internal view when the element is connected. */
|
|
2986
|
+
private recreateView;
|
|
2987
|
+
/** Creates the internal view if it does not yet exist. */
|
|
2988
|
+
private ensureView;
|
|
2989
|
+
/** Destroys and clears the internal view instance. */
|
|
2990
|
+
private destroyView;
|
|
2991
|
+
}
|
|
2992
|
+
/**
|
|
2993
|
+
* Registers the diagram view custom element if not already registered.
|
|
2994
|
+
* @param tagName The custom element tag name to register.
|
|
2995
|
+
* @returns The DiagramViewElement constructor.
|
|
2996
|
+
*/
|
|
2997
|
+
declare function registerDiagramViewElement(tagName?: string): typeof DiagramViewElement;
|
|
2998
|
+
|
|
2999
|
+
/** Default custom element tag name for the editable diagram host. */
|
|
3000
|
+
declare const DIAGRAM_EDIT_TAG = "pz-diagram-edit";
|
|
3001
|
+
/**
|
|
3002
|
+
* Custom element wrapper that hosts a {@link DiagramEditView} instance.
|
|
3003
|
+
*
|
|
3004
|
+
* The element recreates its internal view when input properties change,
|
|
3005
|
+
* allowing declarative usage through attributes/properties.
|
|
3006
|
+
*/
|
|
3007
|
+
declare class DiagramEditElement extends HTMLElement {
|
|
3008
|
+
/** Attributes observed by the custom element runtime. */
|
|
3009
|
+
static get observedAttributes(): string[];
|
|
3010
|
+
private editInstance?;
|
|
3011
|
+
private editId;
|
|
3012
|
+
private initialState?;
|
|
3013
|
+
/** Returns the current DiagramEditView instance when initialized. */
|
|
3014
|
+
get edit(): DiagramEditView | undefined;
|
|
3015
|
+
/** Gets the diagram identifier used to initialize the internal edit view. */
|
|
3016
|
+
get diagramId(): string;
|
|
3017
|
+
/**
|
|
3018
|
+
* Sets the diagram identifier and recreates the internal view when changed.
|
|
3019
|
+
* @param value New diagram id.
|
|
3020
|
+
*/
|
|
3021
|
+
set diagramId(value: string);
|
|
3022
|
+
/** Gets the initial diagram state used when creating the internal view. */
|
|
3023
|
+
get diagram(): Partial<Omit<Diagram, 'id'>> | undefined;
|
|
3024
|
+
/**
|
|
3025
|
+
* Sets initial diagram data and recreates the internal view when connected.
|
|
3026
|
+
* @param value Initial diagram state.
|
|
3027
|
+
*/
|
|
3028
|
+
set diagram(value: Partial<Omit<Diagram, 'id'>> | undefined);
|
|
3029
|
+
/**
|
|
3030
|
+
* Lifecycle callback fired when the element is attached to the DOM.
|
|
3031
|
+
*/
|
|
3032
|
+
connectedCallback(): void;
|
|
3033
|
+
/**
|
|
3034
|
+
* Lifecycle callback fired when the element is detached from the DOM.
|
|
3035
|
+
*/
|
|
3036
|
+
disconnectedCallback(): void;
|
|
3037
|
+
/**
|
|
3038
|
+
* Reacts to observed attribute changes.
|
|
3039
|
+
* @param name Attribute name.
|
|
3040
|
+
* @param _oldValue Previous attribute value.
|
|
3041
|
+
* @param newValue New attribute value.
|
|
3042
|
+
*/
|
|
3043
|
+
attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
|
|
3044
|
+
/** Recreates the internal edit view when the element is connected. */
|
|
3045
|
+
private recreateEdit;
|
|
3046
|
+
/** Creates the internal edit view if it does not yet exist. */
|
|
3047
|
+
private ensureEdit;
|
|
3048
|
+
/** Destroys and clears the internal edit view instance. */
|
|
3049
|
+
private destroyEdit;
|
|
3050
|
+
}
|
|
3051
|
+
/**
|
|
3052
|
+
* Registers the diagram edit custom element if not already registered.
|
|
3053
|
+
* @param tagName The custom element tag name to register.
|
|
3054
|
+
* @returns The DiagramEditElement constructor.
|
|
3055
|
+
*/
|
|
3056
|
+
declare function registerDiagramEditElement(tagName?: string): typeof DiagramEditElement;
|
|
3057
|
+
|
|
3058
|
+
/**
|
|
3059
|
+
* Configuration options for the ColorSelect control.
|
|
3060
|
+
* Provide only the properties you want to override; defaults will be used for the rest.
|
|
3061
|
+
*/
|
|
3062
|
+
interface ColorSelectConfig {
|
|
3063
|
+
/**
|
|
3064
|
+
* Whether to show a color swatch in the trigger button. Default is true.
|
|
3065
|
+
*/
|
|
3066
|
+
showSwatch?: boolean;
|
|
3067
|
+
/**
|
|
3068
|
+
* Whether to show a color label in the trigger button. Default is true.
|
|
3069
|
+
* The label will display the color value or 'clear' for transparent.
|
|
3070
|
+
*/
|
|
3071
|
+
showLabel?: boolean;
|
|
3072
|
+
/**
|
|
3073
|
+
* Whether to show the native color input. Default is 'option'.
|
|
3074
|
+
* 'start' - show at the start of the trigger button
|
|
3075
|
+
* 'end' - show at the end of the trigger button
|
|
3076
|
+
* 'option' - show as an option in the menu
|
|
3077
|
+
* 'none' - do not show
|
|
3078
|
+
*/
|
|
3079
|
+
showNativeInput?: 'start' | 'end' | 'option' | 'none';
|
|
3080
|
+
/**
|
|
3081
|
+
* Aria label for the native color input. Default is 'Custom color'.
|
|
3082
|
+
*/
|
|
3083
|
+
nativeInputAriaLabel?: string;
|
|
3084
|
+
/**
|
|
3085
|
+
* Optional class name for the host element.
|
|
3086
|
+
*/
|
|
3087
|
+
hostClassName?: string;
|
|
3088
|
+
/**
|
|
3089
|
+
* Optional class name for the trigger button.
|
|
3090
|
+
*/
|
|
3091
|
+
triggerClassName?: string;
|
|
3092
|
+
/**
|
|
3093
|
+
* Optional class name for the menu element.
|
|
3094
|
+
*/
|
|
3095
|
+
menuClassName?: string;
|
|
3096
|
+
/**
|
|
3097
|
+
* Optional class name for the option elements.
|
|
3098
|
+
*/
|
|
3099
|
+
optionClassName?: string;
|
|
3100
|
+
/**
|
|
3101
|
+
* Optional class name for the color swatch elements.
|
|
3102
|
+
*/
|
|
3103
|
+
swatchClassName?: string;
|
|
3104
|
+
/**
|
|
3105
|
+
* Optional class name for the label elements.
|
|
3106
|
+
*/
|
|
3107
|
+
labelClassName?: string;
|
|
3108
|
+
/**
|
|
3109
|
+
* Optional class name for the native input element.
|
|
3110
|
+
*/
|
|
3111
|
+
nativeInputClassName?: string;
|
|
3112
|
+
/**
|
|
3113
|
+
* Optional class name for the selected state.
|
|
3114
|
+
*/
|
|
3115
|
+
selectedClassName?: string;
|
|
3116
|
+
/**
|
|
3117
|
+
* Optional class name for the open state.
|
|
3118
|
+
*/
|
|
3119
|
+
openClassName?: string;
|
|
3120
|
+
}
|
|
3121
|
+
/**
|
|
3122
|
+
* Input shape for adding a color option with an optional display label.
|
|
3123
|
+
*/
|
|
3124
|
+
interface ColorOptionInput {
|
|
3125
|
+
/**
|
|
3126
|
+
* The color value to display. Can be any valid CSS color string.
|
|
3127
|
+
*/
|
|
3128
|
+
color: string;
|
|
3129
|
+
/**
|
|
3130
|
+
* Optional label to display for the color option. If not provided, the color value will be used.
|
|
3131
|
+
*/
|
|
3132
|
+
label?: string;
|
|
3133
|
+
}
|
|
3134
|
+
/**
|
|
3135
|
+
* A color selection control that supports predefined options and an optional native color picker input.
|
|
3136
|
+
* The control can be configured to show color swatches, labels, and the native input in different arrangements.
|
|
3137
|
+
* It dispatches a 'colorchange' event with the selected color whenever the selection changes.
|
|
3138
|
+
*/
|
|
3139
|
+
declare class ColorSelect {
|
|
3140
|
+
protected host: HTMLElement;
|
|
3141
|
+
protected selected: string;
|
|
3142
|
+
protected config: Required<ColorSelectConfig>;
|
|
3143
|
+
protected trigger: HTMLButtonElement;
|
|
3144
|
+
protected triggerSwatch?: HTMLDivElement;
|
|
3145
|
+
protected triggerLabel?: HTMLSpanElement;
|
|
3146
|
+
protected nativeInput?: HTMLInputElement;
|
|
3147
|
+
protected customInput?: HTMLInputElement;
|
|
3148
|
+
protected customOption?: HTMLButtonElement;
|
|
3149
|
+
protected nativeInputMode: 'start' | 'end' | 'option' | 'none';
|
|
3150
|
+
protected menu: HTMLDivElement;
|
|
3151
|
+
constructor(target: HTMLElement, config?: ColorSelectConfig);
|
|
3152
|
+
/**
|
|
3153
|
+
* Releases DOM/event resources owned by the control.
|
|
3154
|
+
*/
|
|
3155
|
+
destroy(): void;
|
|
3156
|
+
/**
|
|
3157
|
+
* Gets the currently selected color value.
|
|
3158
|
+
*/
|
|
3159
|
+
get value(): string;
|
|
3160
|
+
/**
|
|
3161
|
+
* Sets the selected color value.
|
|
3162
|
+
*/
|
|
3163
|
+
set value(color: string);
|
|
3164
|
+
/**
|
|
3165
|
+
* Manually adds a color option to the menu. This is useful when the color options are dynamic or not known upfront.
|
|
3166
|
+
* @param color The color value to add. Any web color or hexadecimal value including alpha channel.
|
|
3167
|
+
* @param label An optional label for the color option.
|
|
3168
|
+
*/
|
|
3169
|
+
addOption(color: string, label?: string): void;
|
|
3170
|
+
/**
|
|
3171
|
+
* Manually adds multiple color options to the menu. This is useful when the color options are dynamic or not known upfront.
|
|
3172
|
+
* @param colors An array of color values or objects containing color and optional label.
|
|
3173
|
+
*/
|
|
3174
|
+
addOptions(colors: (string | ColorOptionInput)[]): void;
|
|
3175
|
+
/**
|
|
3176
|
+
* Removes all color options from the menu, including the transparent 'clear' and custom options if present.
|
|
3177
|
+
* The menu will be left empty and the custom option will need to be re-added manually if desired.
|
|
3178
|
+
*/
|
|
3179
|
+
clearOptions(): void;
|
|
3180
|
+
/**
|
|
3181
|
+
* Handles the click event on the trigger element. Opens or closes the menu based on its current state.
|
|
3182
|
+
*/
|
|
3183
|
+
protected readonly onTriggerClick: () => void;
|
|
3184
|
+
/**
|
|
3185
|
+
* Handles the click event on the document. Closes the menu if the click is outside the host element.
|
|
3186
|
+
*/
|
|
3187
|
+
protected readonly onDocumentClick: (event: Event) => void;
|
|
3188
|
+
/**
|
|
3189
|
+
* Handles the click event on a color option. Selects the color and closes the menu.
|
|
3190
|
+
*/
|
|
3191
|
+
protected readonly onOptionClick: (event: Event) => void;
|
|
3192
|
+
/**
|
|
3193
|
+
* Handles the input event on the native color input. Selects the color without closing the menu.
|
|
3194
|
+
*/
|
|
3195
|
+
protected readonly onNativeInput: () => void;
|
|
3196
|
+
/**
|
|
3197
|
+
* Handles the input event on the custom color input. Selects the color and closes the menu.
|
|
3198
|
+
*/
|
|
3199
|
+
protected readonly onCustomInput: () => void;
|
|
3200
|
+
/**
|
|
3201
|
+
* Selects a color and updates the UI accordingly.
|
|
3202
|
+
* @param color The color to select.
|
|
3203
|
+
*/
|
|
3204
|
+
protected selectColor(color: string): void;
|
|
3205
|
+
protected buildOption(color: string, label?: string): HTMLButtonElement;
|
|
3206
|
+
protected buildCustomOption(): HTMLButtonElement;
|
|
3207
|
+
protected createSwatch(color: string): HTMLDivElement;
|
|
3208
|
+
protected createCustomSwatch(): HTMLDivElement;
|
|
3209
|
+
protected colorStyleForSwatch(color: string): string;
|
|
3210
|
+
protected syncTrigger(): void;
|
|
3211
|
+
protected displayColorLabel(color: string): string;
|
|
3212
|
+
protected nativeInputValue(color: string): string;
|
|
3213
|
+
protected resolveNativeInputMode(value: ColorSelectConfig['showNativeInput']): 'start' | 'end' | 'option' | 'none';
|
|
3214
|
+
protected customInputOpen(): void;
|
|
3215
|
+
protected placeCustomOption(): void;
|
|
3216
|
+
protected placeTransparentOption(): void;
|
|
3217
|
+
protected hasOption(color: string): boolean;
|
|
3218
|
+
protected normalizeComparableColor(color: string): string;
|
|
3219
|
+
protected syncSelectedOption(): void;
|
|
3220
|
+
protected openMenu(): void;
|
|
3221
|
+
protected closeMenu(): void;
|
|
3222
|
+
}
|
|
3223
|
+
|
|
3224
|
+
/**
|
|
3225
|
+
* Configuration options for the WidthSelect component.
|
|
3226
|
+
*/
|
|
3227
|
+
interface WidthSelectConfig {
|
|
3228
|
+
/**
|
|
3229
|
+
* An array of predefined widths to display in the dropdown. Each width should be a positive number.
|
|
3230
|
+
* If not provided, a default set of widths will be used.
|
|
3231
|
+
*/
|
|
3232
|
+
widths?: number[];
|
|
3233
|
+
/**
|
|
3234
|
+
* The stroke color to use for the width swatch in the dropdown and trigger button.
|
|
3235
|
+
*/
|
|
3236
|
+
strokeColor?: string;
|
|
3237
|
+
/**
|
|
3238
|
+
* Indicates whether to show the width label (e.g., "1px", "2px") next to the swatch in the trigger button and options.
|
|
3239
|
+
*/
|
|
3240
|
+
showLabel?: boolean;
|
|
3241
|
+
/**
|
|
3242
|
+
* Optional CSS class name to apply to the host element of the WidthSelect component. This allows for custom styling of the component.
|
|
3243
|
+
*/
|
|
3244
|
+
hostClassName?: string;
|
|
3245
|
+
/**
|
|
3246
|
+
* Optional CSS class name to apply to the trigger button of the WidthSelect component. This allows for custom styling of the trigger button.
|
|
3247
|
+
*/
|
|
3248
|
+
triggerClassName?: string;
|
|
3249
|
+
/**
|
|
3250
|
+
* Optional CSS class name to apply to the dropdown menu of the WidthSelect component. This allows for custom styling of the dropdown menu.
|
|
3251
|
+
*/
|
|
3252
|
+
menuClassName?: string;
|
|
3253
|
+
/**
|
|
3254
|
+
* Optional CSS class name to apply to each option in the dropdown menu. This allows for custom styling of the options.
|
|
3255
|
+
*/
|
|
3256
|
+
optionClassName?: string;
|
|
3257
|
+
/**
|
|
3258
|
+
* Optional CSS class name to apply to the swatch element of the WidthSelect component. This allows for custom styling of the swatch.
|
|
3259
|
+
*/
|
|
3260
|
+
swatchClassName?: string;
|
|
3261
|
+
/**
|
|
3262
|
+
* Optional CSS class name to apply to the label element of the WidthSelect component. This allows for custom styling of the label.
|
|
3263
|
+
*/
|
|
3264
|
+
labelClassName?: string;
|
|
3265
|
+
/**
|
|
3266
|
+
* Optional CSS class name to apply to the selected option of the WidthSelect component. This allows for custom styling of the selected option.
|
|
3267
|
+
*/
|
|
3268
|
+
selectedClassName?: string;
|
|
3269
|
+
/**
|
|
3270
|
+
* Optional CSS class name to apply when the WidthSelect component is open. This allows for custom styling when the component is open.
|
|
3271
|
+
*/
|
|
3272
|
+
openClassName?: string;
|
|
3273
|
+
}
|
|
3274
|
+
/**
|
|
3275
|
+
* A dropdown component for selecting line widths.
|
|
3276
|
+
* It displays a list of predefined widths and allows the user to select one.
|
|
3277
|
+
* The selected width is reflected in the trigger button and can be accessed via the `value` property.
|
|
3278
|
+
* The component emits a 'widthchange' event when the selected width changes.
|
|
3279
|
+
*/
|
|
3280
|
+
declare class WidthSelect {
|
|
3281
|
+
protected host: HTMLElement;
|
|
3282
|
+
protected config: Required<Omit<WidthSelectConfig, 'widths'>> & {
|
|
3283
|
+
widths: number[];
|
|
3284
|
+
};
|
|
3285
|
+
protected selected: number;
|
|
3286
|
+
protected trigger: HTMLButtonElement;
|
|
3287
|
+
protected triggerSwatch: HTMLDivElement;
|
|
3288
|
+
protected triggerLabel?: HTMLSpanElement;
|
|
3289
|
+
protected menu: HTMLDivElement;
|
|
3290
|
+
constructor(target: HTMLElement, config?: WidthSelectConfig);
|
|
3291
|
+
/**
|
|
3292
|
+
* Releases DOM/event resources owned by the control.
|
|
3293
|
+
*/
|
|
3294
|
+
destroy(): void;
|
|
3295
|
+
/**
|
|
3296
|
+
* Gets the currently selected width value.
|
|
3297
|
+
*/
|
|
3298
|
+
get value(): number;
|
|
3299
|
+
/**
|
|
3300
|
+
* Sets the currently selected width value.
|
|
3301
|
+
*/
|
|
3302
|
+
set value(width: number);
|
|
3303
|
+
/**
|
|
3304
|
+
* Sets the available width options and optionally selects a width.
|
|
3305
|
+
* @param widths - An array of widths.
|
|
3306
|
+
* @param selectedWidth - The width to select. Defaults to the first width in the array.
|
|
3307
|
+
*/
|
|
3308
|
+
setOptions(widths: number[], selectedWidth?: number): void;
|
|
3309
|
+
/**
|
|
3310
|
+
* Handles the click event on the trigger button. Toggles the open/closed state of the dropdown menu.
|
|
3311
|
+
*/
|
|
3312
|
+
protected readonly onTriggerClick: () => void;
|
|
3313
|
+
/**
|
|
3314
|
+
* Handles the click event on the document. Closes the dropdown menu if the click is outside the host element.
|
|
3315
|
+
* @param event - The click event.
|
|
3316
|
+
*/
|
|
3317
|
+
protected readonly onDocumentClick: (event: Event) => void;
|
|
3318
|
+
/**
|
|
3319
|
+
* Handles the click event on an option. Selects the clicked width and closes the dropdown menu.
|
|
3320
|
+
* @param event - The click event.
|
|
3321
|
+
*/
|
|
3322
|
+
protected readonly onOptionClick: (event: Event) => void;
|
|
3323
|
+
protected rebuildOptions(widths: number[]): void;
|
|
3324
|
+
protected buildOption(width: number): HTMLButtonElement;
|
|
3325
|
+
protected createWidthSvg(width: number): SVGElement;
|
|
3326
|
+
protected selectWidth(width: number, emit?: boolean): void;
|
|
3327
|
+
protected syncTrigger(): void;
|
|
3328
|
+
protected syncSelectedOption(): void;
|
|
3329
|
+
protected openMenu(): void;
|
|
3330
|
+
protected closeMenu(): void;
|
|
3331
|
+
}
|
|
3332
|
+
|
|
3333
|
+
/**
|
|
3334
|
+
* Configuration options for the font select control.
|
|
3335
|
+
* Provide only the properties you want to customize. All other properties will use default values.
|
|
3336
|
+
*/
|
|
3337
|
+
interface FontSelectConfig {
|
|
3338
|
+
/**
|
|
3339
|
+
* Optional array of font family names to display in the dropdown. If not provided, a default set of common fonts will be used.
|
|
3340
|
+
* If an empty array is provided, the default fonts will be used.
|
|
3341
|
+
*/
|
|
3342
|
+
fonts?: string[];
|
|
3343
|
+
/**
|
|
3344
|
+
* Whether to show a preview of the selected font in the trigger button.
|
|
3345
|
+
*/
|
|
3346
|
+
showPreview?: boolean;
|
|
3347
|
+
/**
|
|
3348
|
+
* Custom class name for the host element.
|
|
3349
|
+
*/
|
|
3350
|
+
hostClassName?: string;
|
|
3351
|
+
/**
|
|
3352
|
+
* Custom class name for the trigger button.
|
|
3353
|
+
*/
|
|
3354
|
+
triggerClassName?: string;
|
|
3355
|
+
/**
|
|
3356
|
+
* Custom class name for the dropdown menu.
|
|
3357
|
+
*/
|
|
3358
|
+
menuClassName?: string;
|
|
3359
|
+
/**
|
|
3360
|
+
* Custom class name for each option in the dropdown.
|
|
3361
|
+
*/
|
|
3362
|
+
optionClassName?: string;
|
|
3363
|
+
/**
|
|
3364
|
+
* Custom class name for the font preview element.
|
|
3365
|
+
*/
|
|
3366
|
+
previewClassName?: string;
|
|
3367
|
+
/**
|
|
3368
|
+
* Custom class name for the label element.
|
|
3369
|
+
*/
|
|
3370
|
+
labelClassName?: string;
|
|
3371
|
+
/**
|
|
3372
|
+
* Custom class name for the selected option.
|
|
3373
|
+
*/
|
|
3374
|
+
selectedClassName?: string;
|
|
3375
|
+
/**
|
|
3376
|
+
* Custom class name for the open state.
|
|
3377
|
+
*/
|
|
3378
|
+
openClassName?: string;
|
|
3379
|
+
}
|
|
3380
|
+
declare const DEFAULT_FONTS: string[];
|
|
3381
|
+
/**
|
|
3382
|
+
* A dropdown control for selecting font families.
|
|
3383
|
+
* Emits a 'fontchange' event when the selected font changes.
|
|
3384
|
+
* Example usage:
|
|
3385
|
+
*
|
|
3386
|
+
* const fontSelect = new FontSelect(document.getElementById('font-select'), {
|
|
3387
|
+
* fonts: ['Arial', 'Verdana', 'Tahoma'],
|
|
3388
|
+
* showPreview: true,
|
|
3389
|
+
* });
|
|
3390
|
+
*/
|
|
3391
|
+
declare class FontSelect {
|
|
3392
|
+
protected host: HTMLElement;
|
|
3393
|
+
protected config: Required<Omit<FontSelectConfig, 'fonts'>> & {
|
|
3394
|
+
fonts: string[];
|
|
3395
|
+
};
|
|
3396
|
+
protected selected: string;
|
|
3397
|
+
protected trigger: HTMLButtonElement;
|
|
3398
|
+
protected triggerPreview: HTMLSpanElement;
|
|
3399
|
+
protected menu: HTMLDivElement;
|
|
3400
|
+
constructor(target: HTMLElement, config?: FontSelectConfig);
|
|
3401
|
+
/**
|
|
3402
|
+
* Releases DOM/event resources owned by the control.
|
|
3403
|
+
*/
|
|
3404
|
+
destroy(): void;
|
|
3405
|
+
/**
|
|
3406
|
+
* Gets the currently selected font family.
|
|
3407
|
+
*/
|
|
3408
|
+
get value(): string;
|
|
3409
|
+
/**
|
|
3410
|
+
* Sets the currently selected font family.
|
|
3411
|
+
*/
|
|
3412
|
+
set value(font: string);
|
|
3413
|
+
/**
|
|
3414
|
+
* Sets the available font options and optionally selects a font.
|
|
3415
|
+
* @param fonts - An array of font family names.
|
|
3416
|
+
* @param selectedFont - The font to select. Defaults to the first font in the array.
|
|
3417
|
+
*/
|
|
3418
|
+
setOptions(fonts: string[], selectedFont?: string): void;
|
|
3419
|
+
/**
|
|
3420
|
+
* Handles the click event on the trigger button.
|
|
3421
|
+
* Toggles the open/closed state of the dropdown menu.
|
|
3422
|
+
*/
|
|
3423
|
+
protected readonly onTriggerClick: () => void;
|
|
3424
|
+
/**
|
|
3425
|
+
* Handles the click event on the document to close the menu when clicking outside.
|
|
3426
|
+
*/
|
|
3427
|
+
protected readonly onDocumentClick: (event: Event) => void;
|
|
3428
|
+
/**
|
|
3429
|
+
* Handles the click event on a font option.
|
|
3430
|
+
* Selects the clicked font and closes the menu.
|
|
3431
|
+
* @param event - The click event.
|
|
3432
|
+
*/
|
|
3433
|
+
protected readonly onOptionClick: (event: Event) => void;
|
|
3434
|
+
protected rebuildOptions(fonts: string[]): void;
|
|
3435
|
+
protected buildOption(font: string): HTMLButtonElement;
|
|
3436
|
+
protected selectFont(font: string, emit?: boolean): void;
|
|
3437
|
+
protected syncTrigger(): void;
|
|
3438
|
+
protected syncSelectedOption(): void;
|
|
3439
|
+
protected openMenu(): void;
|
|
3440
|
+
protected closeMenu(): void;
|
|
3441
|
+
}
|
|
3442
|
+
|
|
3443
|
+
/**
|
|
3444
|
+
* Configuration options for the SizeSelect control.
|
|
3445
|
+
* Provide only the properties you want to customize. All other properties will use default values.
|
|
3446
|
+
*/
|
|
3447
|
+
interface SizeSelectConfig {
|
|
3448
|
+
/**
|
|
3449
|
+
* Optional array of sizes to display in the dropdown. If not provided, a default set of sizes will be used.
|
|
3450
|
+
*/
|
|
3451
|
+
sizes?: number[];
|
|
3452
|
+
/**
|
|
3453
|
+
* Optional unit to display next to the size values (e.g., 'px', 'pt'). Defaults to 'px'.
|
|
3454
|
+
*/
|
|
3455
|
+
unit?: string;
|
|
3456
|
+
/**
|
|
3457
|
+
* Whether to show the unit label next to the size values. Defaults to true.
|
|
3458
|
+
*/
|
|
3459
|
+
showLabel?: boolean;
|
|
3460
|
+
/**
|
|
3461
|
+
* Optional CSS class name to apply to the host element of the SizeSelect control. This allows for custom styling.
|
|
3462
|
+
*/
|
|
3463
|
+
hostClassName?: string;
|
|
3464
|
+
/**
|
|
3465
|
+
* Optional CSS class name to apply to the trigger button of the SizeSelect control. This allows for custom styling.
|
|
3466
|
+
*/
|
|
3467
|
+
triggerClassName?: string;
|
|
3468
|
+
/**
|
|
3469
|
+
* Optional CSS class name to apply to the dropdown menu of the SizeSelect control. This allows for custom styling.
|
|
3470
|
+
*/
|
|
3471
|
+
menuClassName?: string;
|
|
3472
|
+
/**
|
|
3473
|
+
* Optional CSS class name to apply to each option in the dropdown menu. This allows for custom styling.
|
|
3474
|
+
*/
|
|
3475
|
+
optionClassName?: string;
|
|
3476
|
+
/**
|
|
3477
|
+
* Optional CSS class name to apply to the preview element that shows the selected size. This allows for custom styling.
|
|
3478
|
+
*/
|
|
3479
|
+
previewClassName?: string;
|
|
3480
|
+
/**
|
|
3481
|
+
* Optional CSS class name to apply to the label element that shows the unit. This allows for custom styling.
|
|
3482
|
+
*/
|
|
3483
|
+
labelClassName?: string;
|
|
3484
|
+
/**
|
|
3485
|
+
* Optional CSS class name to apply to the selected option. This allows for custom styling.
|
|
3486
|
+
*/
|
|
3487
|
+
selectedClassName?: string;
|
|
3488
|
+
/**
|
|
3489
|
+
* Optional CSS class name to apply when the dropdown is open. This allows for custom styling.
|
|
3490
|
+
*/
|
|
3491
|
+
openClassName?: string;
|
|
3492
|
+
}
|
|
3493
|
+
declare const DEFAULT_SIZES: number[];
|
|
3494
|
+
/**
|
|
3495
|
+
* A dropdown control for selecting sizes (e.g., font sizes, line widths).
|
|
3496
|
+
* Emits a 'sizechange' event when the selected size changes.
|
|
3497
|
+
* Example usage:
|
|
3498
|
+
*
|
|
3499
|
+
* const sizeSelect = new SizeSelect(document.getElementById('size-select'), {
|
|
3500
|
+
* sizes: [8, 10, 12, 14, 16, 18, 20],
|
|
3501
|
+
* unit: 'px',
|
|
3502
|
+
* showLabel: true,
|
|
3503
|
+
* });
|
|
3504
|
+
*/
|
|
3505
|
+
declare class SizeSelect {
|
|
3506
|
+
protected host: HTMLElement;
|
|
3507
|
+
protected config: Required<Omit<SizeSelectConfig, 'sizes'>> & {
|
|
3508
|
+
sizes: number[];
|
|
3509
|
+
};
|
|
3510
|
+
protected selected: number;
|
|
3511
|
+
protected trigger: HTMLButtonElement;
|
|
3512
|
+
protected triggerPreview: HTMLSpanElement;
|
|
3513
|
+
protected menu: HTMLDivElement;
|
|
3514
|
+
constructor(target: HTMLElement, config?: SizeSelectConfig);
|
|
3515
|
+
/**
|
|
3516
|
+
* Releases DOM/event resources owned by the control.
|
|
3517
|
+
*/
|
|
3518
|
+
destroy(): void;
|
|
3519
|
+
/**
|
|
3520
|
+
* Gets the currently selected size value.
|
|
3521
|
+
*/
|
|
3522
|
+
get value(): number;
|
|
3523
|
+
/**
|
|
3524
|
+
* Sets the currently selected size value.
|
|
3525
|
+
*/
|
|
3526
|
+
set value(size: number);
|
|
3527
|
+
/**
|
|
3528
|
+
* Sets the available size options and optionally selects a size.
|
|
3529
|
+
* @param sizes - An array of sizes.
|
|
3530
|
+
* @param selectedSize - The size to select. Defaults to the first size in the array.
|
|
3531
|
+
*/
|
|
3532
|
+
setOptions(sizes: number[], selectedSize?: number): void;
|
|
3533
|
+
/**
|
|
3534
|
+
* Handles the click event on the trigger button. Toggles the open/closed state of the dropdown menu.
|
|
3535
|
+
*/
|
|
3536
|
+
protected readonly onTriggerClick: () => void;
|
|
3537
|
+
/**
|
|
3538
|
+
* Handles the click event on the document. Closes the dropdown menu if the click is outside the host element.
|
|
3539
|
+
* @param event - The click event.
|
|
3540
|
+
*/
|
|
3541
|
+
protected readonly onDocumentClick: (event: Event) => void;
|
|
3542
|
+
/**
|
|
3543
|
+
* Handles the click event on an option. Selects the clicked size and closes the dropdown menu.
|
|
3544
|
+
* @param event - The click event.
|
|
3545
|
+
*/
|
|
3546
|
+
protected readonly onOptionClick: (event: Event) => void;
|
|
3547
|
+
protected rebuildOptions(sizes: number[]): void;
|
|
3548
|
+
protected buildOption(size: number): HTMLButtonElement;
|
|
3549
|
+
protected selectSize(size: number, emit?: boolean): void;
|
|
3550
|
+
protected syncTrigger(): void;
|
|
3551
|
+
protected syncSelectedOption(): void;
|
|
3552
|
+
protected openMenu(): void;
|
|
3553
|
+
protected closeMenu(): void;
|
|
3554
|
+
}
|
|
3555
|
+
|
|
3556
|
+
/**
|
|
3557
|
+
* Configuration options for the IntegerRangeSelect control.
|
|
3558
|
+
*/
|
|
3559
|
+
interface IntegerRangeSelectConfig {
|
|
3560
|
+
min?: number;
|
|
3561
|
+
max?: number;
|
|
3562
|
+
step?: number;
|
|
3563
|
+
value?: number;
|
|
3564
|
+
unit?: string;
|
|
3565
|
+
hostClassName?: string;
|
|
3566
|
+
trackClassName?: string;
|
|
3567
|
+
valueClassName?: string;
|
|
3568
|
+
}
|
|
3569
|
+
/**
|
|
3570
|
+
* A compact integer range selector based on native input[type=range].
|
|
3571
|
+
* Emits a 'valuechange' event when the slider change is committed.
|
|
3572
|
+
*/
|
|
3573
|
+
declare class IntegerRangeSelect {
|
|
3574
|
+
protected host: HTMLElement;
|
|
3575
|
+
protected config: Required<IntegerRangeSelectConfig>;
|
|
3576
|
+
protected input: HTMLInputElement;
|
|
3577
|
+
protected valueText: HTMLSpanElement;
|
|
3578
|
+
protected selected: number;
|
|
3579
|
+
constructor(target: HTMLElement, config?: IntegerRangeSelectConfig);
|
|
3580
|
+
/**
|
|
3581
|
+
* Releases DOM/event resources owned by the control.
|
|
3582
|
+
*/
|
|
3583
|
+
destroy(): void;
|
|
3584
|
+
/**
|
|
3585
|
+
* Gets the currently selected integer value.
|
|
3586
|
+
*/
|
|
3587
|
+
get value(): number;
|
|
3588
|
+
/**
|
|
3589
|
+
* Sets the currently selected integer value.
|
|
3590
|
+
*/
|
|
3591
|
+
set value(value: number);
|
|
3592
|
+
/**
|
|
3593
|
+
* Gets whether the control is disabled.
|
|
3594
|
+
*/
|
|
3595
|
+
get disabled(): boolean;
|
|
3596
|
+
/**
|
|
3597
|
+
* Disables or enables the control.
|
|
3598
|
+
*/
|
|
3599
|
+
set disabled(value: boolean);
|
|
3600
|
+
/**
|
|
3601
|
+
* Updates the selectable range and optional current value.
|
|
3602
|
+
*/
|
|
3603
|
+
setRange(min: number, max: number, step?: number, value?: number): void;
|
|
3604
|
+
protected readonly onInput: () => void;
|
|
3605
|
+
protected readonly onChange: () => void;
|
|
3606
|
+
protected syncDisplay(): void;
|
|
3607
|
+
protected clamp(value: number): number;
|
|
3608
|
+
}
|
|
3609
|
+
|
|
3610
|
+
/**
|
|
3611
|
+
* Configuration options for the ArrowSelect component.
|
|
3612
|
+
*/
|
|
3613
|
+
interface ArrowSelectConfig {
|
|
3614
|
+
/**
|
|
3615
|
+
* An array of arrow types to display in the dropdown. Each type is represented as a string.
|
|
3616
|
+
* The default arrow types are: 'start', 'end', 'both', and 'none'.
|
|
3617
|
+
* You can change their order but not add new types without updating the component logic.
|
|
3618
|
+
*/
|
|
3619
|
+
arrows?: ArrowDirection[];
|
|
3620
|
+
/**
|
|
3621
|
+
* The stroke color to use for the width swatch in the dropdown and trigger button.
|
|
3622
|
+
*/
|
|
3623
|
+
strokeColor?: string;
|
|
3624
|
+
/**
|
|
3625
|
+
* Optional CSS class name to apply to the host element of the ArrowSelect component. This allows for custom styling of the component.
|
|
3626
|
+
*/
|
|
3627
|
+
hostClassName?: string;
|
|
3628
|
+
/**
|
|
3629
|
+
* Optional CSS class name to apply to the trigger button of the ArrowSelect component. This allows for custom styling of the trigger button.
|
|
3630
|
+
*/
|
|
3631
|
+
triggerClassName?: string;
|
|
3632
|
+
/**
|
|
3633
|
+
* Optional CSS class name to apply to the dropdown menu of the ArrowSelect component. This allows for custom styling of the dropdown menu.
|
|
3634
|
+
*/
|
|
3635
|
+
menuClassName?: string;
|
|
3636
|
+
/**
|
|
3637
|
+
* Optional CSS class name to apply to each option in the dropdown menu. This allows for custom styling of the options.
|
|
3638
|
+
*/
|
|
3639
|
+
optionClassName?: string;
|
|
3640
|
+
/**
|
|
3641
|
+
* Optional CSS class name to apply to the swatch element of the ArrowSelect component. This allows for custom styling of the swatch.
|
|
3642
|
+
*/
|
|
3643
|
+
swatchClassName?: string;
|
|
3644
|
+
/**
|
|
3645
|
+
* Optional CSS class name to apply to the selected option of the ArrowSelect component. This allows for custom styling of the selected option.
|
|
3646
|
+
*/
|
|
3647
|
+
selectedClassName?: string;
|
|
3648
|
+
/**
|
|
3649
|
+
* Optional CSS class name to apply when the ArrowSelect component is open. This allows for custom styling when the component is open.
|
|
3650
|
+
*/
|
|
3651
|
+
openClassName?: string;
|
|
3652
|
+
}
|
|
3653
|
+
|
|
3654
|
+
/**
|
|
3655
|
+
* A dropdown component for selecting line widths.
|
|
3656
|
+
* It displays a list of predefined widths and allows the user to select one.
|
|
3657
|
+
* The selected width is reflected in the trigger button and can be accessed via the `value` property.
|
|
3658
|
+
* The component emits a 'widthchange' event when the selected width changes.
|
|
3659
|
+
*/
|
|
3660
|
+
declare class ArrowSelect {
|
|
3661
|
+
protected host: HTMLElement;
|
|
3662
|
+
protected config: Required<Omit<ArrowSelectConfig, 'arrows'>> & {
|
|
3663
|
+
arrows: ArrowDirection[];
|
|
3664
|
+
};
|
|
3665
|
+
protected selected: ArrowDirection;
|
|
3666
|
+
protected trigger: HTMLButtonElement;
|
|
3667
|
+
protected triggerSwatch: HTMLDivElement;
|
|
3668
|
+
protected triggerLabel?: HTMLSpanElement;
|
|
3669
|
+
protected menu: HTMLDivElement;
|
|
3670
|
+
constructor(target: HTMLElement, config?: ArrowSelectConfig);
|
|
3671
|
+
/**
|
|
3672
|
+
* Releases DOM/event resources owned by the control.
|
|
3673
|
+
*/
|
|
3674
|
+
destroy(): void;
|
|
3675
|
+
/**
|
|
3676
|
+
* Gets the currently selected width value.
|
|
3677
|
+
*/
|
|
3678
|
+
get value(): string;
|
|
3679
|
+
/**
|
|
3680
|
+
* Sets the currently selected width value.
|
|
3681
|
+
*/
|
|
3682
|
+
set value(arrow: ArrowDirection);
|
|
3683
|
+
/**
|
|
3684
|
+
* Sets the available arrow options and optionally selects one.
|
|
3685
|
+
* @param arrows - An array of arrow directions.
|
|
3686
|
+
* @param selectedArrow - The arrow direction to select. Defaults to the first option.
|
|
3687
|
+
*/
|
|
3688
|
+
setOptions(arrows: ArrowDirection[], selectedArrow?: ArrowDirection): void;
|
|
3689
|
+
/**
|
|
3690
|
+
* Handles the click event on the trigger button. Toggles the open/closed state of the dropdown menu.
|
|
3691
|
+
*/
|
|
3692
|
+
protected readonly onTriggerClick: () => void;
|
|
3693
|
+
/**
|
|
3694
|
+
* Handles the click event on the document. Closes the dropdown menu if the click is outside the host element.
|
|
3695
|
+
* @param event - The click event.
|
|
3696
|
+
*/
|
|
3697
|
+
protected readonly onDocumentClick: (event: Event) => void;
|
|
3698
|
+
/**
|
|
3699
|
+
* Handles the click event on an option. Selects the clicked width and closes the dropdown menu.
|
|
3700
|
+
* @param event - The click event.
|
|
3701
|
+
*/
|
|
3702
|
+
protected readonly onOptionClick: (event: Event) => void;
|
|
3703
|
+
protected rebuildOptions(arrows: ArrowDirection[]): void;
|
|
3704
|
+
protected buildOption(arrow: ArrowDirection): HTMLButtonElement;
|
|
3705
|
+
protected createArrowSvg(arrow: ArrowDirection): SVGElement;
|
|
3706
|
+
protected createArrowHead(x: number, y: number, direction: 'forward' | 'backward'): SVGPolygonElement;
|
|
3707
|
+
protected normalizeArrow(arrow: ArrowDirection | string | undefined): ArrowDirection;
|
|
3708
|
+
protected selectArrow(arrow: ArrowDirection, emit?: boolean): void;
|
|
3709
|
+
protected syncTrigger(): void;
|
|
3710
|
+
protected syncSelectedOption(): void;
|
|
3711
|
+
protected openMenu(): void;
|
|
3712
|
+
protected closeMenu(): void;
|
|
3713
|
+
}
|
|
3714
|
+
|
|
3715
|
+
/**
|
|
3716
|
+
* A single action in a prompt dialog, consisting of a value, label, and optional primary flag.
|
|
3717
|
+
*/
|
|
3718
|
+
type PromptDialogAction<T extends string> = {
|
|
3719
|
+
/**
|
|
3720
|
+
* The value associated with this action. This value will be returned when the action is selected.
|
|
3721
|
+
*/
|
|
3722
|
+
value: T;
|
|
3723
|
+
/**
|
|
3724
|
+
* The label displayed on the button for this action.
|
|
3725
|
+
*/
|
|
3726
|
+
label: string;
|
|
3727
|
+
/**
|
|
3728
|
+
* Whether this action is the primary action. Primary actions are typically highlighted.
|
|
3729
|
+
*/
|
|
3730
|
+
primary?: boolean;
|
|
3731
|
+
};
|
|
3732
|
+
/**
|
|
3733
|
+
* Options for configuring a prompt dialog, including title, prompt message, optional icon, and a list of actions.
|
|
3734
|
+
*/
|
|
3735
|
+
type PromptDialogOptions<T extends string> = {
|
|
3736
|
+
/**
|
|
3737
|
+
* The title of the prompt dialog.
|
|
3738
|
+
*/
|
|
3739
|
+
title?: string;
|
|
3740
|
+
/**
|
|
3741
|
+
* The message or question to display in the prompt dialog.
|
|
3742
|
+
*/
|
|
3743
|
+
prompt: string;
|
|
3744
|
+
/**
|
|
3745
|
+
* An optional icon to display in the prompt dialog.
|
|
3746
|
+
*/
|
|
3747
|
+
icon?: string;
|
|
3748
|
+
/**
|
|
3749
|
+
* The list of actions available in the prompt dialog.
|
|
3750
|
+
*/
|
|
3751
|
+
actions: PromptDialogAction<T>[];
|
|
3752
|
+
};
|
|
3753
|
+
/**
|
|
3754
|
+
* A simple prompt dialog component that can be used to display a message and a set of actions to the user.
|
|
3755
|
+
* It uses the native HTML <dialog> element if available, and falls back to a confirm dialog if not.
|
|
3756
|
+
* The component returns a promise that resolves with the value of the selected action.
|
|
3757
|
+
*/
|
|
3758
|
+
declare class PromptDialog {
|
|
3759
|
+
/**
|
|
3760
|
+
* Displays a prompt dialog with the specified options.
|
|
3761
|
+
* @param input The options for configuring the prompt dialog.
|
|
3762
|
+
* @returns A promise that resolves with the value of the selected action.
|
|
3763
|
+
*/
|
|
3764
|
+
static show<T extends string>(input: PromptDialogOptions<T>): Promise<T>;
|
|
3765
|
+
private static fallback;
|
|
3766
|
+
private static buildDialog;
|
|
3767
|
+
private static buildHead;
|
|
3768
|
+
private static buildActions;
|
|
3769
|
+
private static supportsDialog;
|
|
3770
|
+
private static ensureStyles;
|
|
3771
|
+
}
|
|
3772
|
+
|
|
3773
|
+
declare const TOOL_PALETTE_TOOL_SELECTED_EVENT = "tool-selected";
|
|
3774
|
+
type ToolPaletteLayoutItem = string | '*';
|
|
3775
|
+
/**
|
|
3776
|
+
* Configuration options for the ToolPalette component.
|
|
3777
|
+
* Provide only the properties you want to customize. All other properties will use default values.
|
|
3778
|
+
*/
|
|
3779
|
+
interface ToolPaletteConfig {
|
|
3780
|
+
/**
|
|
3781
|
+
* Ordered layout of tools in the palette. '*' means insert all remaining tools at this position.
|
|
3782
|
+
*/
|
|
3783
|
+
layout?: ToolPaletteLayoutItem[];
|
|
3784
|
+
/**
|
|
3785
|
+
* Optional CSS class name to apply to the host element of the tool palette. This allows for custom styling of the entire palette.
|
|
3786
|
+
*/
|
|
3787
|
+
hostClassName?: string;
|
|
3788
|
+
}
|
|
3789
|
+
declare const DEFAULT_TOOL_LAYOUT: ToolPaletteLayoutItem[];
|
|
3790
|
+
/**
|
|
3791
|
+
* A toolbar component that displays a list of tools for the diagram editor.
|
|
3792
|
+
* It allows users to select a tool, and the selected tool is highlighted.
|
|
3793
|
+
* The component emits a 'tool-selected' event when a tool is selected.
|
|
3794
|
+
* The layout of the tools can be customized via the configuration options.
|
|
3795
|
+
*/
|
|
3796
|
+
declare class ToolPalette {
|
|
3797
|
+
protected host: HTMLElement;
|
|
3798
|
+
protected diagram: DiagramEditView;
|
|
3799
|
+
protected config: ToolPaletteConfig;
|
|
3800
|
+
protected manualTools: Map<string, string>;
|
|
3801
|
+
protected renderedTools: string[];
|
|
3802
|
+
constructor(host: HTMLElement, diagram: DiagramEditView, config?: ToolPaletteConfig);
|
|
3803
|
+
/**
|
|
3804
|
+
* Cleans up the palette and detaches diagram listeners.
|
|
3805
|
+
*/
|
|
3806
|
+
destroy(): void;
|
|
3807
|
+
/**
|
|
3808
|
+
* Rebuilds and re-renders the tool list from the current registry and layout.
|
|
3809
|
+
*/
|
|
3810
|
+
refresh(): void;
|
|
3811
|
+
/** Adds a tool entry manually (useful for custom/non-registered tools). */
|
|
3812
|
+
addTool(tool: string, label?: string): void;
|
|
3813
|
+
/**
|
|
3814
|
+
* Removes all manually added tools and clears the rendered palette.
|
|
3815
|
+
*/
|
|
3816
|
+
clearTools(): void;
|
|
3817
|
+
/** Swap the underlying diagram view (e.g. after remounting). */
|
|
3818
|
+
setDiagramView(diagram: DiagramEditView): void;
|
|
3819
|
+
/**
|
|
3820
|
+
* Handles the diagram tool change event.
|
|
3821
|
+
* @param event The event object containing the tool change details.
|
|
3822
|
+
*/
|
|
3823
|
+
protected readonly onDiagramToolChanged: (event: Event) => void;
|
|
3824
|
+
protected bindDiagramEvents(): void;
|
|
3825
|
+
protected unbindDiagramEvents(): void;
|
|
3826
|
+
protected resolveLayout(allTools: string[]): string[];
|
|
3827
|
+
protected renderTool(tool: string, label: string): void;
|
|
3828
|
+
protected highlight(tool: string): void;
|
|
3829
|
+
}
|
|
3830
|
+
|
|
3831
|
+
/**
|
|
3832
|
+
* Configuration options for the toolbar.
|
|
3833
|
+
* Provide only the properties you want to customize. All other properties will use default values.
|
|
3834
|
+
*/
|
|
3835
|
+
interface ToolBarConfig {
|
|
3836
|
+
/**
|
|
3837
|
+
* Optional CSS class name to apply to the toolbar host element. This allows for custom styling of the toolbar.
|
|
3838
|
+
*/
|
|
3839
|
+
hostClassName?: string;
|
|
3840
|
+
/**
|
|
3841
|
+
* Optional CSS class name to apply to toolbar buttons. This allows for custom styling of the buttons.
|
|
3842
|
+
*/
|
|
3843
|
+
buttonClassName?: string;
|
|
3844
|
+
/**
|
|
3845
|
+
* Optional CSS class name to apply to active toolbar buttons. This allows for custom styling of active buttons.
|
|
3846
|
+
*/
|
|
3847
|
+
activeClassName?: string;
|
|
3848
|
+
/**
|
|
3849
|
+
* Optional CSS class name to apply to disabled toolbar buttons. This allows for custom styling of disabled buttons.
|
|
3850
|
+
*/
|
|
3851
|
+
disabledClassName?: string;
|
|
3852
|
+
/**
|
|
3853
|
+
* Optional CSS class name to apply to toolbar separators. This allows for custom styling of separators.
|
|
3854
|
+
*/
|
|
3855
|
+
separatorClassName?: string;
|
|
3856
|
+
/**
|
|
3857
|
+
* Optional attribute name to use for tooltips. This allows for custom tooltip behavior.
|
|
3858
|
+
*/
|
|
3859
|
+
tooltipAttribute?: string;
|
|
3860
|
+
}
|
|
3861
|
+
/**
|
|
3862
|
+
* Definition of a toolbar button.
|
|
3863
|
+
* Provide only the properties you want to customize. All other properties will use default values.
|
|
3864
|
+
*/
|
|
3865
|
+
interface ToolButtonDef {
|
|
3866
|
+
/**
|
|
3867
|
+
* Unique identifier for the button. This is used to reference the button in the toolbar.
|
|
3868
|
+
*/
|
|
3869
|
+
id: string;
|
|
3870
|
+
/**
|
|
3871
|
+
* SVG use href (e.g. '#icon-undo'), URL string, or an Element
|
|
3872
|
+
*/
|
|
3873
|
+
icon?: string | Element;
|
|
3874
|
+
/**
|
|
3875
|
+
* Optional label for the button. This is used for accessibility and tooltips.
|
|
3876
|
+
*/
|
|
3877
|
+
label?: string;
|
|
3878
|
+
/**
|
|
3879
|
+
* Optional tooltip text for the button. This is displayed on hover.
|
|
3880
|
+
*/
|
|
3881
|
+
tooltip?: string;
|
|
3882
|
+
/**
|
|
3883
|
+
* Indicates if the button is a toggle button.
|
|
3884
|
+
*/
|
|
3885
|
+
toggle?: boolean;
|
|
3886
|
+
/**
|
|
3887
|
+
* Indicates if the button is disabled.
|
|
3888
|
+
*/
|
|
3889
|
+
disabled?: boolean;
|
|
3890
|
+
/**
|
|
3891
|
+
* Click event handler for the button.
|
|
3892
|
+
*/
|
|
3893
|
+
onClick: (event: MouseEvent) => void | Promise<void>;
|
|
3894
|
+
}
|
|
3895
|
+
/**
|
|
3896
|
+
* A simple toolbar component that can be used to create a toolbar with buttons and separators.
|
|
3897
|
+
* The toolbar can be customized with CSS classes and tooltip attributes.
|
|
3898
|
+
* Buttons can be added with icons, labels, tooltips, and click event handlers.
|
|
3899
|
+
* Buttons can also be toggled on/off and enabled/disabled.
|
|
3900
|
+
*/
|
|
3901
|
+
declare class ToolBar {
|
|
3902
|
+
protected host: HTMLElement;
|
|
3903
|
+
protected config: Required<ToolBarConfig>;
|
|
3904
|
+
protected buttons: Map<string, HTMLButtonElement>;
|
|
3905
|
+
constructor(target: HTMLElement, config?: ToolBarConfig);
|
|
3906
|
+
/**
|
|
3907
|
+
* Clears toolbar DOM and internal button references.
|
|
3908
|
+
*/
|
|
3909
|
+
destroy(): void;
|
|
3910
|
+
/**
|
|
3911
|
+
* Manually adds a button to the toolbar. This is useful for dynamically adding buttons after the toolbar has been created.
|
|
3912
|
+
* @param def The definition of the button to add.
|
|
3913
|
+
* @returns The HTMLButtonElement that was created and added to the toolbar.
|
|
3914
|
+
*/
|
|
3915
|
+
addButton(def: ToolButtonDef): HTMLButtonElement;
|
|
3916
|
+
/**
|
|
3917
|
+
* Manually adds a separator to the toolbar. This is useful for dynamically adding separators after the toolbar has been created.
|
|
3918
|
+
* @returns The HTMLDivElement that was created and added to the toolbar.
|
|
3919
|
+
*/
|
|
3920
|
+
addSeparator(): HTMLDivElement;
|
|
3921
|
+
/**
|
|
3922
|
+
* Sets the active state of a button.
|
|
3923
|
+
* @param id The ID of the button.
|
|
3924
|
+
* @param active Whether the button should be active.
|
|
3925
|
+
*/
|
|
3926
|
+
setActive(id: string, active: boolean): void;
|
|
3927
|
+
/**
|
|
3928
|
+
* Sets the enabled state of a button.
|
|
3929
|
+
* @param id The ID of the button.
|
|
3930
|
+
* @param enabled Whether the button should be enabled.
|
|
3931
|
+
*/
|
|
3932
|
+
setEnabled(id: string, enabled: boolean): void;
|
|
3933
|
+
/**
|
|
3934
|
+
* Gets a button by its ID.
|
|
3935
|
+
* @param id The ID of the button.
|
|
3936
|
+
* @returns The HTMLButtonElement if found, otherwise undefined.
|
|
3937
|
+
*/
|
|
3938
|
+
getButton(id: string): HTMLButtonElement | undefined;
|
|
3939
|
+
protected buildButton(def: ToolButtonDef): HTMLButtonElement;
|
|
3940
|
+
protected resolveIcon(icon?: string | Element): Element | null;
|
|
3941
|
+
}
|
|
3942
|
+
|
|
3943
|
+
/**
|
|
3944
|
+
* Configuration options for the diagram toolbar.
|
|
3945
|
+
* Provide only the properties you want to customize. All other properties will use default values.
|
|
3946
|
+
*/
|
|
3947
|
+
interface DiagramAction {
|
|
3948
|
+
/**
|
|
3949
|
+
* Unique identifier for the action. This is used to reference the action in the toolbar.
|
|
3950
|
+
*/
|
|
3951
|
+
id: DiagramToolBarLayoutItem;
|
|
3952
|
+
/**
|
|
3953
|
+
* Optional label for the action. This is used for accessibility and tooltips.
|
|
3954
|
+
*/
|
|
3955
|
+
label: string;
|
|
3956
|
+
/**
|
|
3957
|
+
* Optional tooltip text for the action. This is displayed on hover.
|
|
3958
|
+
*/
|
|
3959
|
+
tooltip?: string;
|
|
3960
|
+
/**
|
|
3961
|
+
* Optional icon for the action. This can be an SVG use href (e.g. '#icon-undo'), a URL string, or an Element.
|
|
3962
|
+
*/
|
|
3963
|
+
icon?: string | Element;
|
|
3964
|
+
/**
|
|
3965
|
+
* Whether the action is a toggle action. Toggle actions can be in an active or inactive state.
|
|
3966
|
+
*/
|
|
3967
|
+
toggle?: boolean;
|
|
3968
|
+
/**
|
|
3969
|
+
* Called when the button is clicked; receives the diagram view.
|
|
3970
|
+
*/
|
|
3971
|
+
execute: (diagram: DiagramEditView) => void | Promise<void>;
|
|
3972
|
+
/**
|
|
3973
|
+
* Returns true when the button should be enabled; defaults to always enabled.
|
|
3974
|
+
*/
|
|
3975
|
+
isEnabled?: (diagram: DiagramEditView) => boolean;
|
|
3976
|
+
/**
|
|
3977
|
+
* Returns true when the button should appear active/pressed.
|
|
3978
|
+
*/
|
|
3979
|
+
isActive?: (diagram: DiagramEditView) => boolean;
|
|
3980
|
+
}
|
|
3981
|
+
/**
|
|
3982
|
+
* Configuration options for the diagram toolbar.
|
|
3983
|
+
* Provide only the properties you want to customize. All other properties will use default values.
|
|
3984
|
+
*/
|
|
3985
|
+
interface DiagramToolBarConfig extends ToolBarConfig {
|
|
3986
|
+
/**
|
|
3987
|
+
* Ordered toolbar layout mixing action IDs and separators.
|
|
3988
|
+
* Example: ['undo', 'redo', '|', 'delete', 'copy', 'paste']
|
|
3989
|
+
* A default layout will be used if none is provided.
|
|
3990
|
+
*/
|
|
3991
|
+
layout?: DiagramToolBarLayoutItem[];
|
|
3992
|
+
}
|
|
3993
|
+
/**
|
|
3994
|
+
* Available built-in diagram actions. These can be used in the toolbar layout.
|
|
3995
|
+
*/
|
|
3996
|
+
type DiagramToolBarLayoutItem = '|' | 'new' | 'open' | 'save' | 'export' | 'undo' | 'redo' | 'front' | 'back' | 'delete' | 'duplicate' | 'cut' | 'copy' | 'paste' | 'align-left' | 'align-center' | 'align-right' | 'align-top' | 'align-middle' | 'align-bottom' | 'distribute-h' | 'distribute-v' | 'zoom-in' | 'zoom-out' | 'fit-width' | 'fit-all' | 'show-grid' | 'snap-grid';
|
|
3997
|
+
declare const DEFAULT_LAYOUT: DiagramToolBarLayoutItem[];
|
|
3998
|
+
/**
|
|
3999
|
+
* Full catalogue of built-in diagram actions.
|
|
4000
|
+
*/
|
|
4001
|
+
declare const DIAGRAM_ACTIONS: DiagramAction[];
|
|
4002
|
+
/**
|
|
4003
|
+
* DiagramToolBar is a specialized toolbar for diagram editing, providing buttons for common actions like undo, redo, copy, paste, alignment, and zooming.
|
|
4004
|
+
* It automatically updates the enabled and active state of buttons based on the current state of the associated DiagramEditView.
|
|
4005
|
+
* The toolbar can be configured with a custom layout and styling options.
|
|
4006
|
+
*
|
|
4007
|
+
* Example usage:
|
|
4008
|
+
* ```ts
|
|
4009
|
+
* const toolbar = new DiagramToolBar(toolbarContainer, diagramView, {
|
|
4010
|
+
* layout: ['undo', 'redo', '|', 'copy', 'paste'],
|
|
4011
|
+
* hostClassName: 'my-toolbar',
|
|
4012
|
+
* });
|
|
4013
|
+
* ```
|
|
4014
|
+
*/
|
|
4015
|
+
declare class DiagramToolBar extends ToolBar {
|
|
4016
|
+
protected diagram: DiagramEditView;
|
|
4017
|
+
protected actions: DiagramAction[];
|
|
4018
|
+
protected readonly onDiagramChanged: () => void;
|
|
4019
|
+
protected readonly onClipboardChanged: () => void;
|
|
4020
|
+
constructor(target: HTMLElement, diagram: DiagramEditView, config?: DiagramToolBarConfig);
|
|
4021
|
+
/**
|
|
4022
|
+
* Cleans up toolbar resources and detaches diagram listeners.
|
|
4023
|
+
*/
|
|
4024
|
+
destroy(): void;
|
|
4025
|
+
/**
|
|
4026
|
+
* Re-evaluates enabled and active state for all registered actions.
|
|
4027
|
+
*/
|
|
4028
|
+
refresh(): void;
|
|
4029
|
+
/**
|
|
4030
|
+
* Swap the underlying diagram view (e.g. after remounting).
|
|
4031
|
+
*/
|
|
4032
|
+
setDiagramView(diagram: DiagramEditView): void;
|
|
4033
|
+
protected bindDiagramEvents(): void;
|
|
4034
|
+
protected unbindDiagramEvents(): void;
|
|
4035
|
+
protected build(config: DiagramToolBarConfig): void;
|
|
4036
|
+
protected resolveLayout(config: DiagramToolBarConfig): DiagramToolBarLayoutItem[];
|
|
4037
|
+
}
|
|
4038
|
+
|
|
4039
|
+
type DiagramEditorUnsavedAction = 'save' | 'discard' | 'cancel';
|
|
4040
|
+
type DiagramEditorPromptReason = 'new' | 'load' | 'close';
|
|
4041
|
+
type DiagramEditorPrompts = {
|
|
4042
|
+
onUnsavedChanges?: (context: {
|
|
4043
|
+
reason: DiagramEditorPromptReason;
|
|
4044
|
+
}) => DiagramEditorUnsavedAction | Promise<DiagramEditorUnsavedAction>;
|
|
4045
|
+
onNoChangesSave?: () => boolean | Promise<boolean>;
|
|
4046
|
+
};
|
|
4047
|
+
type DiagramEditorFileDialogsConfig = {
|
|
4048
|
+
onOpenDiagram?: DiagramOpenHandler;
|
|
4049
|
+
onSaveDiagram?: DiagramSaveHandler;
|
|
4050
|
+
onExportDiagram?: DiagramExportHandler;
|
|
4051
|
+
};
|
|
4052
|
+
type DiagramEditorConfig = {
|
|
4053
|
+
hostClassName?: string;
|
|
4054
|
+
toolPalette?: ToolPaletteConfig;
|
|
4055
|
+
toolbars?: DiagramToolBarConfig[];
|
|
4056
|
+
prompts?: DiagramEditorPrompts;
|
|
4057
|
+
fontSelect?: FontSelectConfig;
|
|
4058
|
+
fontSizeSelect?: SizeSelectConfig;
|
|
4059
|
+
textColor?: ColorSelectConfig;
|
|
4060
|
+
strokeColor?: ColorSelectConfig;
|
|
4061
|
+
strokeWidth?: WidthSelectConfig;
|
|
4062
|
+
arrowSelect?: ArrowSelectConfig;
|
|
4063
|
+
shadowOffsetX?: IntegerRangeSelectConfig;
|
|
4064
|
+
shadowOffsetY?: IntegerRangeSelectConfig;
|
|
4065
|
+
shadowBlur?: IntegerRangeSelectConfig;
|
|
4066
|
+
fillColor?: ColorSelectConfig;
|
|
4067
|
+
fileDialogs?: DiagramEditorFileDialogsConfig;
|
|
4068
|
+
};
|
|
4069
|
+
/**
|
|
4070
|
+
* A composed diagram editing component that wires a {@link DiagramEditView} together with
|
|
4071
|
+
* a tool palette, action toolbars, and style controls.
|
|
4072
|
+
* It provides a ready-to-mount editor surface with optional prompts for unsaved-change flows.
|
|
4073
|
+
*/
|
|
4074
|
+
declare class DiagramEditor {
|
|
4075
|
+
protected host: HTMLElement;
|
|
4076
|
+
protected config: DiagramEditorConfig;
|
|
4077
|
+
protected diagram: DiagramEditView;
|
|
4078
|
+
protected headerHost?: HTMLElement;
|
|
4079
|
+
protected stageHost?: HTMLElement;
|
|
4080
|
+
protected toolbarsHost?: HTMLElement;
|
|
4081
|
+
protected toolbars: DiagramToolBar[];
|
|
4082
|
+
protected toolboxHost?: HTMLElement;
|
|
4083
|
+
protected toolbox?: ToolPalette;
|
|
4084
|
+
protected fontToolbar?: HTMLElement;
|
|
4085
|
+
protected fontSelectHost?: HTMLElement;
|
|
4086
|
+
protected fontSizeSelectHost?: HTMLElement;
|
|
4087
|
+
protected textColorSelectHost?: HTMLElement;
|
|
4088
|
+
protected fontSelect?: FontSelect;
|
|
4089
|
+
protected fontSizeSelect?: SizeSelect;
|
|
4090
|
+
protected textColorSelect?: ColorSelect;
|
|
4091
|
+
protected strokeToolbar?: HTMLElement;
|
|
4092
|
+
protected strokeColorSelectHost?: HTMLElement;
|
|
4093
|
+
protected strokeWidthSelectHost?: HTMLElement;
|
|
4094
|
+
protected arrowSelectHost?: HTMLElement;
|
|
4095
|
+
protected strokeColorSelect?: ColorSelect;
|
|
4096
|
+
protected strokeWidthSelect?: WidthSelect;
|
|
4097
|
+
protected arrowSelect?: ArrowSelect;
|
|
4098
|
+
protected shadowToolbar?: HTMLElement;
|
|
4099
|
+
protected shadowEnableCheckbox?: HTMLInputElement;
|
|
4100
|
+
protected shadowOffsetXHost?: HTMLElement;
|
|
4101
|
+
protected shadowOffsetYHost?: HTMLElement;
|
|
4102
|
+
protected shadowBlurHost?: HTMLElement;
|
|
4103
|
+
protected shadowOffsetXSelect?: IntegerRangeSelect;
|
|
4104
|
+
protected shadowOffsetYSelect?: IntegerRangeSelect;
|
|
4105
|
+
protected shadowBlurSelect?: IntegerRangeSelect;
|
|
4106
|
+
protected fillToolbar?: HTMLElement;
|
|
4107
|
+
protected fillStyleSelectHost?: HTMLElement;
|
|
4108
|
+
protected fillStyleSelect?: ColorSelect;
|
|
4109
|
+
protected listenerDisposers: Array<() => void>;
|
|
4110
|
+
protected syncingControls: boolean;
|
|
4111
|
+
/**
|
|
4112
|
+
* Creates an instance of DiagramEditor.
|
|
4113
|
+
* @param host The container element that will receive the editor layout.
|
|
4114
|
+
* @param config Optional configuration for layout, controls, toolbars, and prompts.
|
|
4115
|
+
* @param diagram Optional initial diagram to load into the editor.
|
|
4116
|
+
*/
|
|
4117
|
+
constructor(host: HTMLElement, config?: DiagramEditorConfig, diagram?: Diagram);
|
|
4118
|
+
/**
|
|
4119
|
+
* Cleans up the editor and all owned child controls.
|
|
4120
|
+
*/
|
|
4121
|
+
destroy(): void;
|
|
4122
|
+
/**
|
|
4123
|
+
* Clears the current diagram after resolving any unsaved-change prompt.
|
|
4124
|
+
* A prompt will be shown if the diagram has unsaved changes.
|
|
4125
|
+
* @returns True when a new empty diagram was created; otherwise false.
|
|
4126
|
+
*/
|
|
4127
|
+
newDiagram(): Promise<boolean>;
|
|
4128
|
+
/**
|
|
4129
|
+
* Loads a diagram from a live diagram instance, a serialized JSON string, or a deserialized payload.
|
|
4130
|
+
* A prompt will be shown if the diagram has unsaved changes.
|
|
4131
|
+
* @param source The diagram source to load.
|
|
4132
|
+
* @returns True when the source was loaded; otherwise false when loading was canceled.
|
|
4133
|
+
*/
|
|
4134
|
+
loadDiagram(source: string | ISerializedDiagram | Diagram): Promise<boolean>;
|
|
4135
|
+
/**
|
|
4136
|
+
* Opens a diagram using configured file dialog behavior after resolving unsaved-change prompts.
|
|
4137
|
+
* @param options Optional open options or source overrides.
|
|
4138
|
+
* @returns True when a diagram was opened; otherwise false.
|
|
4139
|
+
*/
|
|
4140
|
+
openDiagram(options?: DiagramOpenOptions): Promise<boolean>;
|
|
4141
|
+
/**
|
|
4142
|
+
* Saves the current diagram using the underlying {@link DiagramEditView}.
|
|
4143
|
+
* A prompt will be shown if the diagram has no changes to save.
|
|
4144
|
+
* @param options Optional serialization settings.
|
|
4145
|
+
* @returns The serialized diagram string, or undefined when saving was canceled.
|
|
4146
|
+
*/
|
|
4147
|
+
saveDiagram(options?: DiagramSaveOptions): Promise<string | undefined>;
|
|
4148
|
+
/**
|
|
4149
|
+
* Exports the current diagram using the underlying {@link DiagramEditView}.
|
|
4150
|
+
* @param options Optional export settings.
|
|
4151
|
+
* @returns The export result, or undefined when export was canceled.
|
|
4152
|
+
*/
|
|
4153
|
+
exportDiagram(options?: DiagramExportOptions): Promise<string | Uint8Array | Blob | undefined>;
|
|
4154
|
+
/**
|
|
4155
|
+
* Closes the current diagram after resolving any unsaved-change prompt.
|
|
4156
|
+
* A prompt will be shown if the diagram has unsaved changes.
|
|
4157
|
+
* @returns True when the diagram was closed; otherwise false.
|
|
4158
|
+
*/
|
|
4159
|
+
close(): Promise<boolean>;
|
|
4160
|
+
/**
|
|
4161
|
+
* Returns the owned diagram editing view.
|
|
4162
|
+
*/
|
|
4163
|
+
getDiagramView(): DiagramEditView;
|
|
4164
|
+
/**
|
|
4165
|
+
* Returns the action toolbars created for this editor.
|
|
4166
|
+
*/
|
|
4167
|
+
getToolbars(): DiagramToolBar[];
|
|
4168
|
+
/**
|
|
4169
|
+
* Returns the tool palette instance when available.
|
|
4170
|
+
*/
|
|
4171
|
+
getToolbox(): ToolPalette | undefined;
|
|
4172
|
+
/**
|
|
4173
|
+
* Returns the font family selector control when available.
|
|
4174
|
+
*/
|
|
4175
|
+
getFontSelect(): FontSelect | undefined;
|
|
4176
|
+
/**
|
|
4177
|
+
* Returns the font size selector control when available.
|
|
4178
|
+
*/
|
|
4179
|
+
getFontSizeSelect(): SizeSelect | undefined;
|
|
4180
|
+
/**
|
|
4181
|
+
* Returns the text color selector control when available.
|
|
4182
|
+
*/
|
|
4183
|
+
getTextColorSelect(): ColorSelect | undefined;
|
|
4184
|
+
/**
|
|
4185
|
+
* Returns the stroke color selector control when available.
|
|
4186
|
+
*/
|
|
4187
|
+
getStrokeColorSelect(): ColorSelect | undefined;
|
|
4188
|
+
/**
|
|
4189
|
+
* Returns the stroke width selector control when available.
|
|
4190
|
+
*/
|
|
4191
|
+
getStrokeWidthSelect(): WidthSelect | undefined;
|
|
4192
|
+
/**
|
|
4193
|
+
* Returns the arrow selector control when available.
|
|
4194
|
+
*/
|
|
4195
|
+
getArrowSelect(): ArrowSelect | undefined;
|
|
4196
|
+
/**
|
|
4197
|
+
* Returns the fill color selector control when available.
|
|
4198
|
+
*/
|
|
4199
|
+
getFillStyleSelect(): ColorSelect | undefined;
|
|
4200
|
+
/**
|
|
4201
|
+
* Builds the editor layout and initializes all owned controls.
|
|
4202
|
+
* @param host The editor host element.
|
|
4203
|
+
* @param config The editor configuration.
|
|
4204
|
+
* @param diagram Optional initial diagram to load.
|
|
4205
|
+
*/
|
|
4206
|
+
protected initialize(host: HTMLElement, config: DiagramEditorConfig, diagram?: Diagram): void;
|
|
4207
|
+
/**
|
|
4208
|
+
* Connects editor controls to the underlying diagram view and change events.
|
|
4209
|
+
*/
|
|
4210
|
+
protected attachListeners(): void;
|
|
4211
|
+
/**
|
|
4212
|
+
* Removes all event listeners previously registered by the editor.
|
|
4213
|
+
*/
|
|
4214
|
+
protected detachListeners(): void;
|
|
4215
|
+
/**
|
|
4216
|
+
* Synchronizes the style controls with the current style state of the diagram.
|
|
4217
|
+
*/
|
|
4218
|
+
protected reflectStyles(): void;
|
|
4219
|
+
private createToolbar;
|
|
4220
|
+
private createControlHost;
|
|
4221
|
+
private applyShadowEnabledState;
|
|
4222
|
+
private addManagedListener;
|
|
4223
|
+
private addManagedEventListener;
|
|
4224
|
+
private createFileDialogs;
|
|
4225
|
+
private createDiagramPrompts;
|
|
4226
|
+
private confirmCloseIfNeeded;
|
|
4227
|
+
/**
|
|
4228
|
+
* Shows the default prompt used when a save is requested without any pending changes.
|
|
4229
|
+
* @returns True when saving should continue; otherwise false.
|
|
4230
|
+
*/
|
|
4231
|
+
protected promptNoChangesSave(): Promise<boolean>;
|
|
4232
|
+
/**
|
|
4233
|
+
* Shows the default unsaved-changes prompt for the requested action.
|
|
4234
|
+
* @param reason The operation that triggered the prompt.
|
|
4235
|
+
* @returns The action selected by the user.
|
|
4236
|
+
*/
|
|
4237
|
+
protected promptUnsavedChanges(reason: DiagramEditorPromptReason): Promise<DiagramEditorUnsavedAction>;
|
|
4238
|
+
}
|
|
4239
|
+
|
|
4240
|
+
export { type AnchorPoint, type ArrowDirection, ArrowSelect, type ArrowSelectConfig, AssetStore, type BrowserImageMimeType, type BrowserImageSource, type Cacheable, CanvasImageSerializer, type ColorOptionInput, ColorPalette, ColorSelect, type ColorSelectConfig, ConnectionBasics, CoordinateSystem, CurveAdapter, DEFAULT_FONTS, DEFAULT_LAYOUT, DEFAULT_SIZES, DEFAULT_TOOL_LAYOUT, DIAGRAM_ACTIONS, DIAGRAM_BACKGROUND_CLICK_EVENT, DIAGRAM_CHANGED_EVENT, DIAGRAM_CLIPBOARD_EVENT, DIAGRAM_CONNECTION_CONNECTED_EVENT, DIAGRAM_CONNECTION_DISCONNECTED_EVENT, DIAGRAM_DELETE_REQUEST_EVENT, DIAGRAM_EDIT_CONTEXT_MENU_EVENT, DIAGRAM_EDIT_TAG, DIAGRAM_NODE_ADDED_EVENT, DIAGRAM_NODE_CLICK_EVENT, DIAGRAM_NODE_DELETED_EVENT, DIAGRAM_NODE_MOVED_EVENT, DIAGRAM_NODE_POINTS_CHANGED_EVENT, DIAGRAM_NODE_RESIZED_EVENT, DIAGRAM_SELECTION_EVENT, DIAGRAM_TOOL_CHANGED_EVENT, DIAGRAM_VIEWPORT_EVENT, DIAGRAM_VIEW_TAG, Diagram, type DiagramAction, type DiagramBackgroundClick, type DiagramChangeScope, type DiagramChanged, type DiagramClipboardEventDetail, type DiagramClipboardOperation, type DiagramConnectionChange, type DiagramDeleteRequest, type DiagramEditContextMenu, DiagramEditElement, DiagramEditView, type DiagramEditViewPromptReason, type DiagramEditViewPrompts, type DiagramEditViewUnsavedAction, DiagramEditor, type DiagramEditorConfig, type DiagramEditorFileDialogsConfig, type DiagramEditorPromptReason, type DiagramEditorPrompts, type DiagramEditorUnsavedAction, type DiagramExportFormat, type DiagramExportHandler, type DiagramExportOptions, type DiagramExportResult, DiagramFileDialogs, type DiagramInitialView, type DiagramNodeChange, type DiagramOpenHandler, type DiagramOpenOptions, type DiagramOpenResult, type DiagramOpenSource, type DiagramSaveHandler, type DiagramSaveOptions, type DiagramSaveResult, type DiagramSelectionChange, type DiagramSelectionOptions, DiagramToolBar, type DiagramToolBarConfig, type DiagramToolBarLayoutItem, type DiagramToolChange, DiagramView, DiagramViewElement, type DiagramViewOptions, type DiagramViewportChange, EllipseAdapter, EventDispatcher, type FitAlign, FitViewport, FontSelect, type FontSelectConfig, type HasSelection, HistoryStack, type HistoryState, type HollowMode, type HorizontalAlign, type IConnection, type IConnectionAnchor, type IDiagram, type IGrid, type ILayer, type ILayerCached, type INode, type INodeAdapter, type INodeCached, type IPoint, type IRect, type ISerializedConnectionAnchor, type ISerializedDiagram, type ISerializedLayer, type ISerializedNode, type ISerializer, type ITextAlign, type ITextBaseline, IconRegistry, type IconSource, type ImageSaveOptions, type ImageSerializer, type ImageWriteOptions, type InitialViewMode, IntegerRangeSelect, type IntegerRangeSelectConfig, JsonSerializer, LineAdapter, NodeBasics, NodeHandle, NodeRegistry, PngSerializer, PolygonAdapter, PolylineAdapter, PromptDialog, type PromptDialogAction, type PromptDialogOptions, RectangleAdapter, RenderBasics, RhombusAdapter, RoundRectangleAdapter, SelectionBasics, type SelectionDiagram, type Serializable, type ShadowStyle, SizeSelect, type SizeSelectConfig, SvgAdapter, TOOL_PALETTE_TOOL_SELECTED_EVENT, TextAdapter, type TextOptions, type TextOverflowMode, ToolBar, type ToolBarConfig, type ToolButtonDef, ToolPalette, type ToolPaletteConfig, type ToolPaletteLayoutItem, type VerticalAlign, ViewCache, WidthSelect, type WidthSelectConfig, ZOrder, type ZOrderAction, type ZOrderHost, canvasToBlob, canvasToDataUrl, createCanvas2D, downloadBlob, downloadTextFile, exportTextBlob, isBrowserRuntime, isNodeRuntime, jsonSerializer, registerDiagramEditElement, registerDiagramViewElement, shadowStyles, supportedCanvasMimeTypes, supportsCanvasMimeType, unwrapCanvas, writeBinaryFile, writeBlobToFileHandle, writeTextFile, writeTextToFileHandle };
|