@likec4/generators 1.48.0 → 1.50.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/dist/index.d.mts CHANGED
@@ -1,10 +1,138 @@
1
- import { DiagramView } from "@likec4/core";
2
- import { aux } from "@likec4/core/types";
1
+ import { BBox, DiagramView, LikeC4Styles } from "@likec4/core";
2
+ import { ProcessedView, aux } from "@likec4/core/types";
3
3
  import { AnyLikeC4Model, LikeC4Model, LikeC4ViewModel } from "@likec4/core/model";
4
4
 
5
5
  //#region src/d2/generate-d2.d.ts
6
6
  declare function generateD2(viewmodel: LikeC4ViewModel<aux.Unknown>): string;
7
7
  //#endregion
8
+ //#region src/drawio/constants.d.ts
9
+ /** Default filename when exporting all views into one .drawio file (CLI and playground). */
10
+ declare const DEFAULT_DRAWIO_ALL_FILENAME = "diagrams.drawio";
11
+ //#endregion
12
+ //#region src/drawio/generate-drawio.d.ts
13
+ /** Minimal view model shape for generateDrawio / generateDrawioMulti (single source of truth for call sites). */
14
+ type DrawioViewModelLike = {
15
+ $view: ProcessedView<aux.Unknown>;
16
+ readonly $styles?: LikeC4Styles | null;
17
+ };
18
+ /** Optional overrides for round-trip (e.g. from parsed comment blocks). Keys are node/edge ids from the view. */
19
+ type GenerateDrawioOptions = {
20
+ /** Node id -> bbox to use instead of viewmodel layout */layoutOverride?: Record<string, BBox>; /** Node id -> stroke color hex (e.g. from likec4.strokeColor.vertices comment) */
21
+ strokeColorByNodeId?: Record<string, string>; /** Node id -> stroke width (e.g. from likec4.strokeWidth.vertices comment) */
22
+ strokeWidthByNodeId?: Record<string, string>; /** Edge waypoints: key "source|target" or "source|target|edgeId" (FQN, optional id for parallel edges), value = [x,y][] (e.g. from likec4.edge.waypoints comment) */
23
+ edgeWaypoints?: Record<string, number[][]>;
24
+ /**
25
+ * If false, embed raw mxGraphModel XML inside <diagram> (no base64/deflate). Draw.io accepts both.
26
+ * generateDrawio/generateDiagramContent default to compressed when options omitted; buildDrawioExportOptionsFromSource defaults compressed: false so CLI/playground get readable XML unless overridden.
27
+ */
28
+ compressed?: boolean;
29
+ /**
30
+ * ISO timestamp for mxfile modified attribute. When omitted, uses current time (output non-deterministic).
31
+ * Set for deterministic output (e.g. tests, content-addressable storage).
32
+ */
33
+ modified?: string;
34
+ };
35
+ /**
36
+ * Generate a single DrawIO file from one view.
37
+ *
38
+ * @param viewmodel - Layouted LikeC4 view model (from model.view(id))
39
+ * @param options - Optional overrides for layout/colors (round-trip from comment blocks)
40
+ * @returns DrawIO .drawio XML string
41
+ */
42
+ declare function generateDrawio(viewmodel: DrawioViewModelLike, options?: GenerateDrawioOptions): string;
43
+ /**
44
+ * Generate a single DrawIO file with multiple diagrams (tabs).
45
+ * Each view becomes one tab in draw.io. Use this when exporting a project
46
+ * so all views open in one file with one tab per view.
47
+ *
48
+ * @param viewmodels - Layouted view models (e.g. from model.views())
49
+ * @param optionsByViewId - Optional per-view options (e.g. compressed: false for each tab)
50
+ * @param modified - Optional ISO timestamp for mxfile modified attribute (for deterministic output)
51
+ * @returns DrawIO .drawio XML string with multiple <diagram> elements
52
+ */
53
+ declare function generateDrawioMulti(viewmodels: Array<DrawioViewModelLike>, optionsByViewId?: Record<string, GenerateDrawioOptions>, modified?: string): string;
54
+ /**
55
+ * Build export options for one view from .c4 source (parses source once).
56
+ *
57
+ * @param viewId - View id for layoutOverride lookup.
58
+ * @param sourceContent - Full .c4 source (e.g. joined workspace files).
59
+ * @param overrides - Optional overrides (e.g. compressed: false).
60
+ * @returns GenerateDrawioOptions for this view.
61
+ */
62
+ declare function buildDrawioExportOptionsFromSource(viewId: string, sourceContent: string | undefined, overrides?: Partial<GenerateDrawioOptions>): GenerateDrawioOptions;
63
+ /**
64
+ * Build export options per view id from .c4 source (parses source once for all views).
65
+ *
66
+ * @param viewIds - View ids to build options for.
67
+ * @param sourceContent - Full .c4 source (e.g. joined workspace files).
68
+ * @param overrides - Optional overrides (e.g. compressed: false).
69
+ * @returns Record of viewId → GenerateDrawioOptions.
70
+ */
71
+ declare function buildDrawioExportOptionsForViews(viewIds: string[], sourceContent: string | undefined, overrides?: Partial<GenerateDrawioOptions>): Record<string, GenerateDrawioOptions>;
72
+ /**
73
+ * Generate a draw.io editor URL that opens the given drawio XML pre-loaded.
74
+ * Uses the `#create=` fragment with compressed XML data.
75
+ *
76
+ * @param xml - A .drawio XML string (output of generateDrawio / generateDrawioMulti).
77
+ * @returns URL string like "https://app.diagrams.net/#create=..."
78
+ */
79
+ declare function generateDrawioEditUrl(xml: string): string;
80
+ //#endregion
81
+ //#region src/drawio/parse-drawio.d.ts
82
+ /**
83
+ * One diagram's name, id and raw or compressed content from mxfile (single-tab or one tab in multi-tab).
84
+ * content is decompressed mxGraphModel XML when the source was compressed.
85
+ */
86
+ interface DiagramInfo {
87
+ name: string;
88
+ id: string;
89
+ content: string;
90
+ }
91
+ /**
92
+ * Extract all diagram name, id and content from mxfile (for multi-tab .drawio).
93
+ * Uses indexOf-based extraction instead of regex to avoid S5852 (super-linear backtracking DoS).
94
+ * @param fullXml - Full .drawio mxfile XML string.
95
+ * @returns Array of DiagramInfo (one per <diagram>); content decompressed when needed.
96
+ */
97
+ declare function getAllDiagrams(fullXml: string): DiagramInfo[];
98
+ /**
99
+ * Convert DrawIO XML to LikeC4 source (.c4) string.
100
+ * Vertices → model elements (actor/container); edges → relations (->). Uses first diagram only.
101
+ * @param xml - Full .drawio mxfile XML (single or multi-tab).
102
+ * @returns LikeC4 .c4 source string (model + views + round-trip comments).
103
+ */
104
+ declare function parseDrawioToLikeC4(xml: string): string;
105
+ /**
106
+ * Convert DrawIO XML to LikeC4 source when file has multiple diagrams (tabs).
107
+ * Merges elements by FQN and relations by (source, target); one view per diagram.
108
+ * @param xml - Full .drawio mxfile XML with multiple <diagram> elements.
109
+ * @returns LikeC4 .c4 source string (model + views + round-trip comments).
110
+ */
111
+ declare function parseDrawioToLikeC4Multi(xml: string): string;
112
+ /** Data extracted from DrawIO round-trip comment blocks in .c4 source (for re-export). */
113
+ type DrawioRoundtripData = {
114
+ layoutByView: Record<string, {
115
+ nodes: Record<string, {
116
+ x: number;
117
+ y: number;
118
+ width: number;
119
+ height: number;
120
+ }>;
121
+ }>;
122
+ strokeColorByFqn: Record<string, string>;
123
+ strokeWidthByFqn: Record<string, string>; /** Key = "src|tgt" or "src|tgt|edgeId" (FQN, optional edge id for parallel edges), value = array of [x, y] waypoints */
124
+ edgeWaypoints: Record<string, number[][]>;
125
+ };
126
+ /**
127
+ * Parse DrawIO round-trip comment blocks from .c4 source (layout, strokeColor, strokeWidth, waypoints).
128
+ * Used to build GenerateDrawioOptions for re-export after editing in draw.io.
129
+ * TODO: the four section parsers (layout, strokeColor, strokeWidth, waypoints) repeat the same
130
+ * "parse block between markers" pattern; consider a small helper to reduce duplication.
131
+ * @param c4Source - Full .c4 source string (e.g. concatenated workspace files).
132
+ * @returns DrawioRoundtripData or null if no likec4.* comment blocks found.
133
+ */
134
+ declare function parseDrawioRoundtripComments(c4Source: string): DrawioRoundtripData | null;
135
+ //#endregion
8
136
  //#region src/mmd/generate-mmd.d.ts
9
137
  declare function generateMermaid(viewmodel: LikeC4ViewModel<aux.Unknown>): string;
10
138
  //#endregion
@@ -56,4 +184,4 @@ declare function generateViewsDataTs(diagrams: Iterable<DiagramView>): string;
56
184
  */
57
185
  declare function generateViewsDataDTs(diagrams: Iterable<DiagramView>): string;
58
186
  //#endregion
59
- export { generateD2, generateLikeC4Model, generateMermaid, generatePuml, generateReactNext, generateReactTypes, generateViewsDataDTs, generateViewsDataJs, generateViewsDataTs };
187
+ export { DEFAULT_DRAWIO_ALL_FILENAME, type DrawioViewModelLike, type GenerateDrawioOptions, buildDrawioExportOptionsForViews, buildDrawioExportOptionsFromSource, generateD2, generateDrawio, generateDrawioEditUrl, generateDrawioMulti, generateLikeC4Model, generateMermaid, generatePuml, generateReactNext, generateReactTypes, generateViewsDataDTs, generateViewsDataJs, generateViewsDataTs, getAllDiagrams, parseDrawioRoundtripComments, parseDrawioToLikeC4, parseDrawioToLikeC4Multi };