-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrainmap.d.ts
More file actions
411 lines (359 loc) · 9.18 KB
/
Copy pathbrainmap.d.ts
File metadata and controls
411 lines (359 loc) · 9.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/**
* TypeScript definitions for brainmap.js
* Version: 1.0.9
*
* A beautiful, interactive, and themeable mindmap library for creating
* hierarchical visualizations with editing capabilities.
*/
declare module 'brainmap.js' {
export default MindMap;
}
/**
* Color configuration for nodes
*/
export interface NodeColors {
/** Fill color for the node */
fill?: string;
/** Stroke/border color for the node */
stroke?: string;
/** Text color for the node */
text?: string;
}
/**
* Color scheme configuration
*/
export interface ColorScheme {
/** Colors for the root node */
root?: NodeColors;
/** Colors for branch nodes */
branch?: NodeColors;
/** Colors for leaf nodes */
leaf?: NodeColors;
/** Color for connecting links */
link?: string;
}
/**
* Configuration options for the MindMap
*/
export interface MindMapConfig {
/** Width of the SVG canvas in pixels (default: 800) */
width?: number;
/** Height of the SVG canvas in pixels (default: 800) */
height?: number;
/** Theme name: 'default', 'dark', or 'compact' (default: 'default') */
theme?: 'default' | 'dark' | 'compact';
/** Distance between radius levels (default: 120) */
radiusStep?: number;
/** Whether the mindmap is editable (default: true) */
editable?: boolean;
/** Whether to show control buttons (default: true) */
showControls?: boolean;
/** Whether to show status bar (default: true) */
showStatus?: boolean;
/** Filename for exported JSON data (default: 'mindmap-data.json') */
exportFilename?: string;
/** Color scheme configuration */
colors?: ColorScheme;
}
/**
* Represents a node in the mindmap tree structure
*/
export interface MindMapNode {
/** Unique identifier for the node */
id: string;
/** Display name/text of the node */
name: string;
/** Child nodes (optional) */
children?: MindMapNode[];
}
/**
* Context menu item definition
*/
export interface ContextMenuItem {
/** Display text for the menu item */
text: string;
/** Action to execute when clicked */
action: () => void;
}
/**
* Touch/gesture state for mobile interactions
*/
interface TouchState {
x: number;
y: number;
ox: number;
oy: number;
zoom?: number;
svgX?: number;
svgY?: number;
}
/**
* Point coordinates
*/
interface Point {
x: number;
y: number;
}
/**
* Main MindMap class for creating interactive mindmaps
*/
export declare class MindMap {
/** The DOM container element */
readonly container: HTMLElement;
/** Current configuration */
readonly config: Required<MindMapConfig>;
/** Current tree data */
treeData: MindMapNode | null;
/** Current zoom level */
zoom: number;
/** X offset for panning */
offsetX: number;
/** Y offset for panning */
offsetY: number;
/** Whether currently dragging/panning */
readonly isDragging: boolean;
/** Whether currently editing a node */
readonly isEditing: boolean;
/** ID of the node being edited */
readonly editingNode: string | null;
/** SVG element */
readonly svg: SVGSVGElement | null;
/** Viewport group element */
readonly viewport: SVGGElement | null;
/** Status element */
readonly statusEl: HTMLElement | null;
/** Controls element */
readonly controlsEl: HTMLElement | null;
/**
* Create a new MindMap instance
* @param container - DOM element or CSS selector for the container
* @param options - Configuration options
*/
constructor(container: string | HTMLElement, options?: MindMapConfig);
/**
* Initialize the mindmap
*/
init(): void;
/**
* Set up the DOM structure
*/
setupDOM(): void;
/**
* Apply custom colors to CSS variables
*/
applyCustomColors(): void;
/**
* Set up event listeners for interactions
*/
setupEventListeners(): void;
/**
* Remove event listeners
*/
removeEventListeners(): void;
/**
* Set the mindmap data
* @param data - Tree data structure
*/
setData(data: MindMapNode): void;
/**
* Get the current mindmap data
* @returns Deep clone of the current tree data
*/
getData(): MindMapNode | null;
/**
* Generate a unique node ID
* @returns Unique identifier string
*/
generateId(): string;
/**
* Set status message
* @param message - Status message to display
*/
setStatus(message: string): void;
/**
* Convert screen coordinates to SVG coordinates
* @param screenX - Screen X coordinate
* @param screenY - Screen Y coordinate
* @returns SVG coordinates
*/
screenToSvg(screenX: number, screenY: number): Point;
/**
* Handle mouse wheel events for zooming
* @param e - Wheel event
*/
handleWheel(e: WheelEvent): void;
/**
* Handle mouse down events for panning
* @param e - Mouse event
*/
handleMouseDown(e: MouseEvent): void;
/**
* Handle mouse move events for panning
* @param e - Mouse event
*/
handleMouseMove(e: MouseEvent): void;
/**
* Handle mouse up events
*/
handleMouseUp(): void;
/**
* Handle mouse leave events
*/
handleMouseLeave(): void;
/**
* Get distance between two touch points
* @param touches - Touch list
* @returns Distance in pixels
*/
getTouchDistance(touches: TouchList): number;
/**
* Get center point between two touches
* @param touches - Touch list
* @returns Center point coordinates
*/
getTouchCenter(touches: TouchList): Point;
/**
* Handle touch start events
* @param e - Touch event
*/
handleTouchStart(e: TouchEvent): void;
/**
* Handle touch move events
* @param e - Touch event
*/
handleTouchMove(e: TouchEvent): void;
/**
* Handle touch end events
* @param e - Touch event
*/
handleTouchEnd(e: TouchEvent): void;
/**
* Update the SVG transform based on current zoom and offset
*/
updateTransform(): void;
/**
* Count leaves in the tree for layout calculations
* @param node - Root node to count from
* @returns Number of leaf nodes
*/
countLeaves(node: MindMapNode): number;
/**
* Calculate layout positions for all nodes
* @param root - Root node to layout
*/
layoutRoot(root: MindMapNode): void;
/**
* Layout nodes in a radial pattern
* @param node - Node to layout
* @param parentX - Parent X coordinate
* @param parentY - Parent Y coordinate
* @param startAngle - Starting angle in radians
* @param endAngle - Ending angle in radians
* @param radius - Distance from parent
*/
layoutNode(
node: MindMapNode,
parentX: number,
parentY: number,
startAngle: number,
endAngle: number,
radius: number
): void;
/**
* Find a node by its ID in the tree
* @param tree - Root node to search from
* @param id - Node ID to find
* @returns Found node or null
*/
findNodeById(tree: MindMapNode, id: string): MindMapNode | null;
/**
* Find parent node by child ID
* @param tree - Root node to search from
* @param childId - Child node ID
* @returns Parent node or null
*/
findParentById(tree: MindMapNode, childId: string): MindMapNode | null;
/**
* Add a child node to a parent
* @param parentId - ID of the parent node
* @param name - Name for the new child node
* @returns Success status
*/
addChild(parentId: string, name?: string): boolean;
/**
* Add a sibling node
* @param nodeId - ID of the node to add sibling to
* @param name - Name for the new sibling node
* @returns Success status
*/
addSibling(nodeId: string, name?: string): boolean;
/**
* Delete a node from the tree
* @param nodeId - ID of the node to delete
* @returns Success status
*/
deleteNode(nodeId: string): boolean;
/**
* Rename a node
* @param nodeId - ID of the node to rename
* @param newName - New name for the node
* @returns Success status
*/
renameNode(nodeId: string, newName: string): boolean;
/**
* Show context menu at specified position
* @param x - X coordinate
* @param y - Y coordinate
* @param nodeId - ID of the node the menu is for
*/
showContextMenu(x: number, y: number, nodeId: string): void;
/**
* Hide the context menu
*/
hideContextMenu(): void;
/**
* Show custom input modal
* @param title - Modal title
* @param placeholder - Input placeholder text
* @param defaultValue - Default input value
* @returns Promise that resolves with the input value
*/
showInputModal(title: string, placeholder?: string, defaultValue?: string): Promise<string>;
/**
* Start editing a node
* @param nodeId - ID of the node to edit
*/
startEdit(nodeId: string): void;
/**
* Stop editing and save changes
* @param save - Whether to save the changes
*/
stopEdit(save?: boolean): void;
/**
* Draw the complete mindmap visualization
* @param root - Root node to draw
*/
draw(root: MindMapNode): void;
/**
* Render the complete mindmap
*/
render(): void;
/**
* Export the mindmap data as JSON file
*/
exportData(): void;
/**
* Reset the view to center and default zoom
*/
resetView(): void;
/**
* Destroy the mindmap and clean up resources
*/
destroy(): void;
/**
* Update the mindmap configuration
* @param newConfig - New configuration options
*/
updateConfig(newConfig: Partial<MindMapConfig>): void;
}
export default MindMap;