@filekit-studio/diagram 0.0.0-stage → 1.0.1

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.
@@ -0,0 +1,597 @@
1
+ import React from 'react';
2
+ import { GridStyle, SketchUIConfig, ThemeMode, PanelVariant, SketchDocument, SketchController } from '@filekit-studio/sketch';
3
+ export { GridStyle, PanelVariant, SketchBoardElement, SketchController, SketchDocument, SketchUIConfig, ThemeMode } from '@filekit-studio/sketch';
4
+
5
+ /**
6
+ * @filekit-studio/diagram
7
+ * Declarative diagram schemas, types, and configuration options.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+
12
+ /**
13
+ * Diagram flow direction for automatic DAG / hierarchical layout.
14
+ * - 'TB': Top-to-Bottom (vertical waterfall / tree)
15
+ * - 'BT': Bottom-to-Top (bottom-up hierarchy)
16
+ * - 'LR': Left-to-Right (horizontal pipeline / sequence)
17
+ * - 'RL': Right-to-Left (reverse horizontal pipeline)
18
+ */
19
+ type DiagramDirection = 'TB' | 'BT' | 'LR' | 'RL';
20
+ /**
21
+ * Supported geometric shapes for diagram nodes.
22
+ */
23
+ type DiagramNodeShape = 'rectangle' | 'rounded' | 'diamond' | 'ellipse' | 'circle' | 'cylinder' | 'database' | 'cloud' | 'sticky' | 'table';
24
+ /**
25
+ * Semantic preset color themes for diagram nodes and clusters.
26
+ */
27
+ type DiagramNodeTheme = 'indigo' | 'blue' | 'emerald' | 'green' | 'amber' | 'yellow' | 'rose' | 'red' | 'purple' | 'violet' | 'slate' | 'neutral' | 'sky' | 'cyan' | 'teal' | 'orange';
28
+ /**
29
+ * Fill pattern styles applied to rough-sketch nodes.
30
+ */
31
+ type DiagramFillStyle = 'solid' | 'hachure' | 'cross-hatch' | 'dots' | 'none';
32
+ /**
33
+ * Connector line dash styles.
34
+ */
35
+ type DiagramLineStyle = 'solid' | 'dashed' | 'dotted';
36
+ /**
37
+ * Declarative node specification inside a diagram graph.
38
+ */
39
+ interface DiagramNode {
40
+ /**
41
+ * Unique identifier for the node.
42
+ * Edges reference this identifier via `from` and `to`.
43
+ */
44
+ id: string;
45
+ /**
46
+ * Primary text label displayed on the node.
47
+ * Supports multi-line strings separated by newline characters (`\n`).
48
+ */
49
+ label: string;
50
+ /**
51
+ * Secondary description or subtitle rendered below the main label.
52
+ */
53
+ description?: string;
54
+ /**
55
+ * Visual geometric shape. Default: 'rounded'.
56
+ */
57
+ shape?: DiagramNodeShape;
58
+ /**
59
+ * Semantic theme palette or hex color string (e.g. 'indigo', 'emerald', '#6366f1').
60
+ */
61
+ color?: DiagramNodeTheme | string;
62
+ /**
63
+ * Custom border stroke color hex override.
64
+ */
65
+ strokeColor?: string;
66
+ /**
67
+ * Custom background fill color hex override.
68
+ */
69
+ fillColor?: string;
70
+ /**
71
+ * Custom text color hex override.
72
+ */
73
+ textColor?: string;
74
+ /**
75
+ * Rough-sketch shading fill pattern. Default: 'hachure'.
76
+ */
77
+ fillStyle?: DiagramFillStyle;
78
+ /**
79
+ * Border stroke line thickness in pixels. Default: 2.
80
+ */
81
+ strokeWidth?: number;
82
+ /**
83
+ * Border stroke dash style: 'solid' | 'dashed' | 'dotted'. Default: 'solid'.
84
+ */
85
+ strokeStyle?: DiagramLineStyle;
86
+ /**
87
+ * Hand-drawn roughness intensity (0 = crisp geometric, 2 = rough sketchy). Default: 1.
88
+ */
89
+ roughness?: number;
90
+ /**
91
+ * Node opacity between 0 and 1. Default: 1.
92
+ */
93
+ opacity?: number;
94
+ /**
95
+ * Optional tech stencil or brand icon name (e.g. 'aws', 'docker', 'k8s', 'postgres', 'react', 'redis').
96
+ */
97
+ icon?: string;
98
+ /**
99
+ * Fixed node width in pixels. If omitted, automatically sized based on label content.
100
+ */
101
+ width?: number;
102
+ /**
103
+ * Fixed node height in pixels. If omitted, automatically sized based on label content.
104
+ */
105
+ height?: number;
106
+ /**
107
+ * Explicit X canvas coordinate override. Bypasses auto-layout if provided.
108
+ */
109
+ x?: number;
110
+ /**
111
+ * Explicit Y canvas coordinate override. Bypasses auto-layout if provided.
112
+ */
113
+ y?: number;
114
+ /**
115
+ * Typography font size in pixels. Default: 16.
116
+ */
117
+ fontSize?: number;
118
+ /**
119
+ * Typography font family: 'sans' | 'serif' | 'mono' | 'comic'. Default: 'sans'.
120
+ */
121
+ fontFamily?: 'sans' | 'serif' | 'mono' | 'comic';
122
+ /**
123
+ * Text alignment: 'left' | 'center' | 'right'. Default: 'center'.
124
+ */
125
+ textAlign?: 'left' | 'center' | 'right';
126
+ /**
127
+ * Optional badge pill displayed in the top-right corner of the node (e.g. 'v2', 'PROD', 'REST').
128
+ */
129
+ badge?: string;
130
+ /**
131
+ * Arbitrary custom user metadata attached to the node.
132
+ */
133
+ metadata?: Record<string, unknown>;
134
+ }
135
+ /**
136
+ * Declarative directional edge connecting two nodes.
137
+ */
138
+ interface DiagramEdge {
139
+ /**
140
+ * Optional unique edge identifier.
141
+ */
142
+ id?: string;
143
+ /**
144
+ * Identifier of the source node where the connector originates.
145
+ */
146
+ from: string;
147
+ /**
148
+ * Identifier of the destination node where the connector terminates.
149
+ */
150
+ to: string;
151
+ /**
152
+ * Optional label text rendered along the connector line.
153
+ */
154
+ label?: string;
155
+ /**
156
+ * Connector line dash style: 'solid' | 'dashed' | 'dotted'. Default: 'solid'.
157
+ */
158
+ style?: DiagramLineStyle;
159
+ /**
160
+ * Line stroke color hex. Default: '#475569'.
161
+ */
162
+ color?: string;
163
+ /**
164
+ * Line thickness in pixels. Default: 2.
165
+ */
166
+ strokeWidth?: number;
167
+ /**
168
+ * Render arrowhead at the destination node. Default: true.
169
+ */
170
+ arrowEnd?: boolean;
171
+ /**
172
+ * Render arrowhead at the source node. Default: false.
173
+ */
174
+ arrowStart?: boolean;
175
+ /**
176
+ * Hand-drawn roughness for the connector line. Default: 1.
177
+ */
178
+ roughness?: number;
179
+ /**
180
+ * Connector routing algorithm style: 'straight' | 'curved' | 'elbow'. Default inherits layoutOptions.edgeRouting.
181
+ */
182
+ routing?: 'straight' | 'curved' | 'elbow';
183
+ /**
184
+ * Explicit anchor attachment position on the source node.
185
+ */
186
+ startAnchor?: 'top' | 'bottom' | 'left' | 'right';
187
+ /**
188
+ * Explicit anchor attachment position on the destination node.
189
+ */
190
+ endAnchor?: 'top' | 'bottom' | 'left' | 'right';
191
+ /**
192
+ * Enable/disable submerged tunneling through intermediate shapes for this edge.
193
+ */
194
+ tunneling?: boolean;
195
+ }
196
+ /**
197
+ * Declarative bounding group container wrapping multiple nodes.
198
+ */
199
+ interface DiagramGroup {
200
+ /**
201
+ * Unique group identifier.
202
+ */
203
+ id: string;
204
+ /**
205
+ * Label title displayed on the group frame badge (e.g. 'VPC Subnet', 'Auth Service Cluster').
206
+ */
207
+ label: string;
208
+ /**
209
+ * List of node IDs contained inside this group container.
210
+ */
211
+ nodeIds: string[];
212
+ /**
213
+ * Semantic theme palette or border color hex.
214
+ */
215
+ color?: DiagramNodeTheme | string;
216
+ /**
217
+ * Background fill color hex tint for the container area.
218
+ */
219
+ backgroundColor?: string;
220
+ /**
221
+ * Border outline style: 'solid' | 'dashed'. Default: 'dashed'.
222
+ */
223
+ borderStyle?: 'solid' | 'dashed';
224
+ }
225
+ /**
226
+ * Complete declarative diagram graph specification.
227
+ */
228
+ interface DiagramData {
229
+ /**
230
+ * Diagram title / document name. Default: 'System Architecture'.
231
+ */
232
+ title?: string;
233
+ /**
234
+ * Flow layout direction: 'TB' | 'BT' | 'LR' | 'RL'. Default: 'LR'.
235
+ */
236
+ direction?: DiagramDirection;
237
+ /**
238
+ * Fine-tuning layout configuration and spacing options embedded directly in JSON.
239
+ */
240
+ layout?: DiagramLayoutOptions;
241
+ /**
242
+ * Collection of graph nodes.
243
+ */
244
+ nodes: DiagramNode[];
245
+ /**
246
+ * Collection of directional connector edges.
247
+ */
248
+ edges?: DiagramEdge[];
249
+ /**
250
+ * Optional cluster/group container frames wrapping subsets of nodes.
251
+ */
252
+ groups?: DiagramGroup[];
253
+ /**
254
+ * Canvas background color hex. Default: '#f0f4f8'.
255
+ */
256
+ canvasBackground?: string;
257
+ /**
258
+ * Canvas grid pattern style: 'grid' | 'dots' | 'cross' | 'none'. Default: 'dots'.
259
+ */
260
+ gridStyle?: GridStyle;
261
+ }
262
+ /**
263
+ * Fine-tuning configuration options for the automatic layout engine.
264
+ */
265
+ interface DiagramLayoutOptions {
266
+ /**
267
+ * Flow layout direction override.
268
+ */
269
+ direction?: DiagramDirection;
270
+ /**
271
+ * Perpendicular spacing between parallel sibling nodes on the same rank. Default: 60.
272
+ */
273
+ nodeSpacing?: number;
274
+ /**
275
+ * Longitudinal spacing between successive ranks / layers. Default: 120.
276
+ */
277
+ rankSpacing?: number;
278
+ /**
279
+ * Outer margin padding in pixels around the entire diagram. Default: 60.
280
+ */
281
+ padding?: number;
282
+ /**
283
+ * Internal padding in pixels around nodes inside group container frames. Default: 48.
284
+ */
285
+ groupPadding?: number;
286
+ /**
287
+ * Spacing between group clusters and compound frames. Default: 180.
288
+ */
289
+ clusterSpacing?: number;
290
+ /**
291
+ * Spacing between columns/ranks inside group container frames. Default: 120.
292
+ */
293
+ intraRankSpacing?: number;
294
+ /**
295
+ * Global default edge routing algorithm: 'straight' | 'curved' | 'elbow'. Default: 'straight'.
296
+ */
297
+ edgeRouting?: 'straight' | 'curved' | 'elbow';
298
+ /**
299
+ * Submerged passthrough tunneling: automatically dims to 35% opacity and dots connector segments passing through shapes. Default: true.
300
+ */
301
+ tunneling?: boolean;
302
+ /**
303
+ * Opacity of connector segments passing through intermediate shapes (0.1 - 0.6). Default: 0.35.
304
+ */
305
+ passthroughOpacity?: number;
306
+ /**
307
+ * Stroke style of connector segments passing through intermediate shapes: 'dotted' | 'dashed'. Default: 'dotted'.
308
+ */
309
+ passthroughStyle?: 'dotted' | 'dashed';
310
+ /**
311
+ * Default node width in pixels if not explicitly specified on the node. Default: 180.
312
+ */
313
+ defaultNodeWidth?: number;
314
+ /**
315
+ * Default node height in pixels if not explicitly specified on the node. Default: 80.
316
+ */
317
+ defaultNodeHeight?: number;
318
+ }
319
+ /**
320
+ * Result of executing the automatic layout engine on a diagram graph.
321
+ */
322
+ interface DiagramLayoutResult {
323
+ /**
324
+ * Positioned nodes with calculated x, y, width, and height.
325
+ */
326
+ nodes: (DiagramNode & {
327
+ x: number;
328
+ y: number;
329
+ width: number;
330
+ height: number;
331
+ })[];
332
+ /**
333
+ * Connecting edges with calculated start, control, and end points.
334
+ */
335
+ edges: DiagramEdge[];
336
+ /**
337
+ * Positioned groups with calculated bounding boxes (x, y, width, height).
338
+ */
339
+ groups: (DiagramGroup & {
340
+ x: number;
341
+ y: number;
342
+ width: number;
343
+ height: number;
344
+ })[];
345
+ /**
346
+ * Overall bounding box encompassing all positioned elements.
347
+ */
348
+ bounds: {
349
+ minX: number;
350
+ minY: number;
351
+ maxX: number;
352
+ maxY: number;
353
+ width: number;
354
+ height: number;
355
+ };
356
+ }
357
+ /**
358
+ * Props accepted by the `<Diagram />` and `<SketchDiagram />` React components.
359
+ */
360
+ interface DiagramProps {
361
+ /**
362
+ * Declarative diagram specification (JSON object, parsed DiagramData, or JSON string).
363
+ */
364
+ data: DiagramData | string;
365
+ /**
366
+ * Rendering display mode:
367
+ * - 'viewer': Clean, embeddable documentation viewer with zero editing chrome (uses `<SketchViewer />`).
368
+ * - 'editor': Full interactive studio whiteboard with editing palettes and canvas tools (uses `<SketchEditor />`).
369
+ * Default: 'viewer'.
370
+ */
371
+ mode?: 'viewer' | 'editor';
372
+ /**
373
+ * Fine-tuning layout configuration options (spacing, padding, direction).
374
+ */
375
+ layoutOptions?: DiagramLayoutOptions;
376
+ /**
377
+ * Granular visibility configuration for all 54 UI controls and menus.
378
+ */
379
+ uiConfig?: SketchUIConfig;
380
+ /**
381
+ * Theme mode: 'light', 'dark', or 'system'. Default: 'system'.
382
+ */
383
+ theme?: ThemeMode;
384
+ /**
385
+ * Canvas background color hex override (e.g. '#ffffff', '#121316', '#f0f4f8').
386
+ */
387
+ canvasBackground?: string;
388
+ /**
389
+ * Canvas grid pattern style: 'grid' | 'dots' | 'cross' | 'none'. Default: 'dots'.
390
+ */
391
+ gridStyle?: GridStyle;
392
+ /**
393
+ * Enable mouse wheel zooming and click-and-drag panning in viewer mode. Default: true.
394
+ */
395
+ interactive?: boolean;
396
+ /**
397
+ * Automatically scale and center the diagram to comfortably fit within its container. Default: true.
398
+ */
399
+ autoFit?: boolean;
400
+ /**
401
+ * Display 1-click clipboard PNG image copy button in the top-right corner of viewer mode. Default: true.
402
+ */
403
+ showCopyButton?: boolean;
404
+ /**
405
+ * Display minimal zoom level percentage and +/- controls in the bottom-left corner of viewer mode. Default: false.
406
+ */
407
+ showZoomControls?: boolean;
408
+ /**
409
+ * Title badge displayed on the diagram. Overrides `data.title` if provided.
410
+ */
411
+ title?: string;
412
+ /**
413
+ * Panel aesthetic variant in editor mode: 'classic' | 'neumorphic'. Default: 'classic'.
414
+ */
415
+ panelVariant?: PanelVariant;
416
+ /**
417
+ * Local storage key used for auto-saving modifications in editor mode.
418
+ */
419
+ storageKey?: string | null;
420
+ /**
421
+ * Callback invoked when user clicks the Exit button.
422
+ */
423
+ onExit?: () => void;
424
+ /**
425
+ * Target URL opened when clicking the Guide button.
426
+ */
427
+ guideHref?: string;
428
+ /**
429
+ * Callback invoked when user clicks the Guide button.
430
+ */
431
+ onOpenGuide?: () => void;
432
+ /**
433
+ * Callback invoked whenever diagram elements change in editor mode.
434
+ */
435
+ onChange?: (document: SketchDocument) => void;
436
+ /**
437
+ * Ref to receive imperative SketchController controls (zoomToFit, exportToPng, etc.).
438
+ */
439
+ controllerRef?: React.Ref<SketchController>;
440
+ /**
441
+ * Custom CSS class name for the root container.
442
+ */
443
+ className?: string;
444
+ /**
445
+ * Custom inline styles for the root container.
446
+ */
447
+ style?: React.CSSProperties;
448
+ }
449
+
450
+ /**
451
+ * @filekit-studio/diagram
452
+ * Declarative <Diagram /> and <SketchDiagram /> React components.
453
+ *
454
+ * Automatically compiles graph JSON specifications into Sketch documents
455
+ * and renders them via <SketchViewer /> (viewer mode) or <SketchEditor /> (studio mode).
456
+ *
457
+ * @packageDocumentation
458
+ */
459
+
460
+ /**
461
+ * <Diagram />
462
+ *
463
+ * Declarative Diagram-as-Code React component. Accepts a graph JSON specification
464
+ * or JSON string, runs automatic DAG layout, and renders it in browser.
465
+ */
466
+ declare const Diagram: React.ForwardRefExoticComponent<DiagramProps & React.RefAttributes<SketchController>>;
467
+ /**
468
+ * Alias for <Diagram /> with explicit Sketch prefix.
469
+ */
470
+ declare const SketchDiagram: React.ForwardRefExoticComponent<DiagramProps & React.RefAttributes<SketchController>>;
471
+
472
+ /**
473
+ * @filekit-studio/diagram
474
+ * Declarative Graph JSON to SketchDocument compiler.
475
+ *
476
+ * Compiles high-level graph specifications (nodes, edges, groups, directions)
477
+ * into fully-formed SketchBoardElement arrays ready for rendering.
478
+ *
479
+ * @packageDocumentation
480
+ */
481
+
482
+ /**
483
+ * Safely parses input data which may be a raw JSON string or structured DiagramData object.
484
+ */
485
+ declare function parseDiagramData(input: DiagramData | string): DiagramData;
486
+ /**
487
+ * Converts a declarative DiagramData graph into a full SketchDocument.
488
+ */
489
+ declare function diagramToSketch(input: DiagramData | string, options?: DiagramLayoutOptions): SketchDocument;
490
+
491
+ /**
492
+ * @filekit-studio/diagram
493
+ * Excalidraw JSON to SketchDocument converter.
494
+ *
495
+ * Imports .excalidraw schema files and element arrays into SketchDocument format.
496
+ *
497
+ * @packageDocumentation
498
+ */
499
+
500
+ /**
501
+ * Shape of an individual element in Excalidraw JSON schemas.
502
+ */
503
+ interface ExcalidrawRawElement {
504
+ id: string;
505
+ type: string;
506
+ x: number;
507
+ y: number;
508
+ width: number;
509
+ height: number;
510
+ angle?: number;
511
+ strokeColor?: string;
512
+ backgroundColor?: string;
513
+ fillStyle?: string;
514
+ strokeWidth?: number;
515
+ strokeStyle?: string;
516
+ roughness?: number;
517
+ opacity?: number;
518
+ text?: string;
519
+ fontSize?: number;
520
+ fontFamily?: number;
521
+ textAlign?: string;
522
+ startBinding?: {
523
+ elementId: string;
524
+ focus?: number;
525
+ gap?: number;
526
+ } | null;
527
+ endBinding?: {
528
+ elementId: string;
529
+ focus?: number;
530
+ gap?: number;
531
+ } | null;
532
+ startArrowhead?: string | null;
533
+ endArrowhead?: string | null;
534
+ points?: [number, number][];
535
+ groupIds?: string[];
536
+ isDeleted?: boolean;
537
+ }
538
+ /**
539
+ * Shape of an Excalidraw file JSON document.
540
+ */
541
+ interface ExcalidrawDocument {
542
+ type?: string;
543
+ version?: number;
544
+ source?: string;
545
+ elements?: ExcalidrawRawElement[];
546
+ appState?: {
547
+ viewBackgroundColor?: string;
548
+ gridSize?: number | null;
549
+ };
550
+ }
551
+ /**
552
+ * Converts Excalidraw JSON document or element array into a native SketchDocument.
553
+ */
554
+ declare function excalidrawToSketch(input: ExcalidrawDocument | ExcalidrawRawElement[] | string, documentName?: string): SketchDocument;
555
+
556
+ /**
557
+ * @filekit-studio/diagram
558
+ * Preset theme color palettes for diagram nodes and group frames.
559
+ *
560
+ * @packageDocumentation
561
+ */
562
+
563
+ interface ColorPalette {
564
+ stroke: string;
565
+ fill: string;
566
+ text: string;
567
+ borderStyle?: 'solid' | 'dashed';
568
+ }
569
+ declare const THEME_PALETTES: Record<string, ColorPalette>;
570
+ /**
571
+ * Resolves color palette tokens or hex strings into stroke, fill, and text colors.
572
+ */
573
+ declare function resolveNodeColors(color?: DiagramNodeTheme | string, customStroke?: string, customFill?: string): ColorPalette;
574
+
575
+ /**
576
+ * @filekit-studio/diagram
577
+ * Deterministic Hierarchical DAG & Compound Group Layout Engine.
578
+ *
579
+ * Implements shape-aware node measurement, intra-cluster DAG ranking,
580
+ * and inter-cluster clearance so groups never collide or overlap.
581
+ *
582
+ * @packageDocumentation
583
+ */
584
+
585
+ /**
586
+ * Estimates optimal node width and height based on label length, lines, and shape.
587
+ */
588
+ declare function estimateNodeDimensions(node: DiagramNode, defaultWidth?: number, defaultHeight?: number): {
589
+ width: number;
590
+ height: number;
591
+ };
592
+ /**
593
+ * Computes deterministic coordinates with Compound Cluster layout.
594
+ */
595
+ declare function layoutDiagram(data: DiagramData, options?: DiagramLayoutOptions): DiagramLayoutResult;
596
+
597
+ export { type ColorPalette, Diagram, type DiagramData, type DiagramDirection, type DiagramEdge, type DiagramFillStyle, type DiagramGroup, type DiagramLayoutOptions, type DiagramLayoutResult, type DiagramLineStyle, type DiagramNode, type DiagramNodeShape, type DiagramNodeTheme, type DiagramProps, type ExcalidrawDocument, type ExcalidrawRawElement, SketchDiagram, THEME_PALETTES, diagramToSketch, estimateNodeDimensions, excalidrawToSketch, layoutDiagram, parseDiagramData, resolveNodeColors };