@infinilabs/ai-chat 0.0.0 → 0.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.
Files changed (61) hide show
  1. package/README.md +301 -56
  2. package/dist/_baseUniq-BQcAhV7E.js +152 -0
  3. package/dist/arc-2jwvQ2TN.js +131 -0
  4. package/dist/architecture-U656AL7Q-WuSilpZW.js +5 -0
  5. package/dist/architectureDiagram-VXUJARFQ-D6SKNy5z.js +8681 -0
  6. package/dist/blockDiagram-VD42YOAC-Ct2DD8jj.js +3606 -0
  7. package/dist/c4Diagram-YG6GDRKO-B7wBU4mz.js +2481 -0
  8. package/dist/channel-BRREX19f.js +7 -0
  9. package/dist/chunk-4BX2VUAB-BnghU1_v.js +16 -0
  10. package/dist/chunk-55IACEB6-Dduk-DEL.js +13 -0
  11. package/dist/chunk-B4BG7PRW-DeHw-z-x.js +1826 -0
  12. package/dist/chunk-DI55MBZ5-GTHMAr0M.js +1915 -0
  13. package/dist/chunk-FMBD7UC4-Bchh4_3W.js +19 -0
  14. package/dist/chunk-QN33PNHL-H6S-NYp0.js +24 -0
  15. package/dist/chunk-QZHKN3VN-DdcyNnvM.js +17 -0
  16. package/dist/chunk-TZMSLE5B-C7te_j4V.js +108 -0
  17. package/dist/classDiagram-2ON5EDUG-CNkHY_Y7.js +19 -0
  18. package/dist/classDiagram-v2-WZHVMYZB-CNkHY_Y7.js +19 -0
  19. package/dist/clone-DnOD7gQ4.js +8 -0
  20. package/dist/cose-bilkent-S5V4N54A-2EKtTYth.js +4942 -0
  21. package/dist/cytoscape.esm-BfvZ3QT_.js +30239 -0
  22. package/dist/dagre-6UL2VRFP-oJLNDO4O.js +693 -0
  23. package/dist/defaultLocale-DVr69WTU.js +206 -0
  24. package/dist/diagram-PSM6KHXK-DhMgmu9h.js +845 -0
  25. package/dist/diagram-QEK2KX5R-pB1vUeno.js +300 -0
  26. package/dist/diagram-S2PKOQOG-HTooIr24.js +210 -0
  27. package/dist/erDiagram-Q2GNP2WA-CCaN2EHf.js +1158 -0
  28. package/dist/flowDiagram-NV44I4VS-CG0erQtl.js +2331 -0
  29. package/dist/ganttDiagram-JELNMOA3-D3rSLJec.js +3679 -0
  30. package/dist/gitGraph-F6HP7TQM-BDWdXs6A.js +5 -0
  31. package/dist/gitGraphDiagram-NY62KEGX-Ip-PiLDb.js +1203 -0
  32. package/dist/graph-wCViE1vL.js +596 -0
  33. package/dist/index-BQvQI7yA.js +117302 -0
  34. package/dist/index.css +1834 -82
  35. package/dist/index.js +5 -19966
  36. package/dist/info-NVLQJR56-pJlVBPs6.js +5 -0
  37. package/dist/infoDiagram-WHAUD3N6-BbVs4x8y.js +31 -0
  38. package/dist/init-ZxktEp_H.js +16 -0
  39. package/dist/journeyDiagram-XKPGCS4Q-Cz9ox9GA.js +1254 -0
  40. package/dist/kanban-definition-3W4ZIXB7-ChdUHO5f.js +1047 -0
  41. package/dist/katex-ei8sH3Uy.js +14524 -0
  42. package/dist/layout-BaZPdTGN.js +2183 -0
  43. package/dist/linear-D_RX7hM-.js +340 -0
  44. package/dist/mermaid-parser.core-_sn6A3wB.js +18704 -0
  45. package/dist/min-BxeM4Drj.js +41 -0
  46. package/dist/mindmap-definition-VGOIOE7T-BkjJibdi.js +1126 -0
  47. package/dist/ordinal-CxptdPJm.js +76 -0
  48. package/dist/packet-BFZMPI3H-D3RtU0mc.js +5 -0
  49. package/dist/pie-7BOR55EZ-xH--CiaM.js +5 -0
  50. package/dist/pieDiagram-ADFJNKIX-2Yr1gkth.js +237 -0
  51. package/dist/quadrantDiagram-AYHSOK5B-CjicpXRv.js +1335 -0
  52. package/dist/radar-NHE76QYJ-CL0tHnUP.js +5 -0
  53. package/dist/requirementDiagram-UZGBJVZJ-DBnhlfjR.js +1161 -0
  54. package/dist/sankeyDiagram-TZEHDZUN-B2FErKCa.js +1193 -0
  55. package/dist/sequenceDiagram-WL72ISMW-BkNTlRlB.js +3874 -0
  56. package/dist/stateDiagram-FKZM4ZOC-CAAFQtS9.js +447 -0
  57. package/dist/stateDiagram-v2-4FDKWEC3-lF6kUebI.js +19 -0
  58. package/dist/timeline-definition-IT6M3QCI-CQgMFEPA.js +1222 -0
  59. package/dist/treemap-KMMF4GRG-B0Mc-u8X.js +5 -0
  60. package/dist/xychartDiagram-PRI3JC2R-Cee7LdLr.js +1886 -0
  61. package/package.json +6 -7
@@ -0,0 +1,845 @@
1
+ var _a;
2
+ import { _ as __name, D as cleanAndMerge, E as getConfig, H as selectSvgElement, e as configureSvgSize, l as log, bp as styles2String, d as select, b as setAccTitle, a as getAccTitle, p as setDiagramTitle, q as getDiagramTitle, g as getAccDescription, s as setAccDescription, F as defaultConfig_default, bq as isLabelStyle, y as clear } from "./index-BQvQI7yA.js";
3
+ import { s as setupViewPortForSVG } from "./chunk-QN33PNHL-H6S-NYp0.js";
4
+ import { p as populateCommonDb } from "./chunk-4BX2VUAB-BnghU1_v.js";
5
+ import { p as parse } from "./mermaid-parser.core-_sn6A3wB.js";
6
+ import { b as format } from "./defaultLocale-DVr69WTU.js";
7
+ import { o as ordinal } from "./ordinal-CxptdPJm.js";
8
+ function count(node) {
9
+ var sum = 0, children = node.children, i = children && children.length;
10
+ if (!i) sum = 1;
11
+ else while (--i >= 0) sum += children[i].value;
12
+ node.value = sum;
13
+ }
14
+ function node_count() {
15
+ return this.eachAfter(count);
16
+ }
17
+ function node_each(callback, that) {
18
+ let index = -1;
19
+ for (const node of this) {
20
+ callback.call(that, node, ++index, this);
21
+ }
22
+ return this;
23
+ }
24
+ function node_eachBefore(callback, that) {
25
+ var node = this, nodes = [node], children, i, index = -1;
26
+ while (node = nodes.pop()) {
27
+ callback.call(that, node, ++index, this);
28
+ if (children = node.children) {
29
+ for (i = children.length - 1; i >= 0; --i) {
30
+ nodes.push(children[i]);
31
+ }
32
+ }
33
+ }
34
+ return this;
35
+ }
36
+ function node_eachAfter(callback, that) {
37
+ var node = this, nodes = [node], next = [], children, i, n, index = -1;
38
+ while (node = nodes.pop()) {
39
+ next.push(node);
40
+ if (children = node.children) {
41
+ for (i = 0, n = children.length; i < n; ++i) {
42
+ nodes.push(children[i]);
43
+ }
44
+ }
45
+ }
46
+ while (node = next.pop()) {
47
+ callback.call(that, node, ++index, this);
48
+ }
49
+ return this;
50
+ }
51
+ function node_find(callback, that) {
52
+ let index = -1;
53
+ for (const node of this) {
54
+ if (callback.call(that, node, ++index, this)) {
55
+ return node;
56
+ }
57
+ }
58
+ }
59
+ function node_sum(value) {
60
+ return this.eachAfter(function(node) {
61
+ var sum = +value(node.data) || 0, children = node.children, i = children && children.length;
62
+ while (--i >= 0) sum += children[i].value;
63
+ node.value = sum;
64
+ });
65
+ }
66
+ function node_sort(compare) {
67
+ return this.eachBefore(function(node) {
68
+ if (node.children) {
69
+ node.children.sort(compare);
70
+ }
71
+ });
72
+ }
73
+ function node_path(end) {
74
+ var start = this, ancestor = leastCommonAncestor(start, end), nodes = [start];
75
+ while (start !== ancestor) {
76
+ start = start.parent;
77
+ nodes.push(start);
78
+ }
79
+ var k = nodes.length;
80
+ while (end !== ancestor) {
81
+ nodes.splice(k, 0, end);
82
+ end = end.parent;
83
+ }
84
+ return nodes;
85
+ }
86
+ function leastCommonAncestor(a, b) {
87
+ if (a === b) return a;
88
+ var aNodes = a.ancestors(), bNodes = b.ancestors(), c = null;
89
+ a = aNodes.pop();
90
+ b = bNodes.pop();
91
+ while (a === b) {
92
+ c = a;
93
+ a = aNodes.pop();
94
+ b = bNodes.pop();
95
+ }
96
+ return c;
97
+ }
98
+ function node_ancestors() {
99
+ var node = this, nodes = [node];
100
+ while (node = node.parent) {
101
+ nodes.push(node);
102
+ }
103
+ return nodes;
104
+ }
105
+ function node_descendants() {
106
+ return Array.from(this);
107
+ }
108
+ function node_leaves() {
109
+ var leaves = [];
110
+ this.eachBefore(function(node) {
111
+ if (!node.children) {
112
+ leaves.push(node);
113
+ }
114
+ });
115
+ return leaves;
116
+ }
117
+ function node_links() {
118
+ var root = this, links = [];
119
+ root.each(function(node) {
120
+ if (node !== root) {
121
+ links.push({ source: node.parent, target: node });
122
+ }
123
+ });
124
+ return links;
125
+ }
126
+ function* node_iterator() {
127
+ var node = this, current, next = [node], children, i, n;
128
+ do {
129
+ current = next.reverse(), next = [];
130
+ while (node = current.pop()) {
131
+ yield node;
132
+ if (children = node.children) {
133
+ for (i = 0, n = children.length; i < n; ++i) {
134
+ next.push(children[i]);
135
+ }
136
+ }
137
+ }
138
+ } while (next.length);
139
+ }
140
+ function hierarchy(data, children) {
141
+ if (data instanceof Map) {
142
+ data = [void 0, data];
143
+ if (children === void 0) children = mapChildren;
144
+ } else if (children === void 0) {
145
+ children = objectChildren;
146
+ }
147
+ var root = new Node(data), node, nodes = [root], child, childs, i, n;
148
+ while (node = nodes.pop()) {
149
+ if ((childs = children(node.data)) && (n = (childs = Array.from(childs)).length)) {
150
+ node.children = childs;
151
+ for (i = n - 1; i >= 0; --i) {
152
+ nodes.push(child = childs[i] = new Node(childs[i]));
153
+ child.parent = node;
154
+ child.depth = node.depth + 1;
155
+ }
156
+ }
157
+ }
158
+ return root.eachBefore(computeHeight);
159
+ }
160
+ function node_copy() {
161
+ return hierarchy(this).eachBefore(copyData);
162
+ }
163
+ function objectChildren(d) {
164
+ return d.children;
165
+ }
166
+ function mapChildren(d) {
167
+ return Array.isArray(d) ? d[1] : null;
168
+ }
169
+ function copyData(node) {
170
+ if (node.data.value !== void 0) node.value = node.data.value;
171
+ node.data = node.data.data;
172
+ }
173
+ function computeHeight(node) {
174
+ var height = 0;
175
+ do
176
+ node.height = height;
177
+ while ((node = node.parent) && node.height < ++height);
178
+ }
179
+ function Node(data) {
180
+ this.data = data;
181
+ this.depth = this.height = 0;
182
+ this.parent = null;
183
+ }
184
+ Node.prototype = hierarchy.prototype = {
185
+ constructor: Node,
186
+ count: node_count,
187
+ each: node_each,
188
+ eachAfter: node_eachAfter,
189
+ eachBefore: node_eachBefore,
190
+ find: node_find,
191
+ sum: node_sum,
192
+ sort: node_sort,
193
+ path: node_path,
194
+ ancestors: node_ancestors,
195
+ descendants: node_descendants,
196
+ leaves: node_leaves,
197
+ links: node_links,
198
+ copy: node_copy,
199
+ [Symbol.iterator]: node_iterator
200
+ };
201
+ function required(f) {
202
+ if (typeof f !== "function") throw new Error();
203
+ return f;
204
+ }
205
+ function constantZero() {
206
+ return 0;
207
+ }
208
+ function constant(x) {
209
+ return function() {
210
+ return x;
211
+ };
212
+ }
213
+ function roundNode(node) {
214
+ node.x0 = Math.round(node.x0);
215
+ node.y0 = Math.round(node.y0);
216
+ node.x1 = Math.round(node.x1);
217
+ node.y1 = Math.round(node.y1);
218
+ }
219
+ function treemapDice(parent, x0, y0, x1, y1) {
220
+ var nodes = parent.children, node, i = -1, n = nodes.length, k = parent.value && (x1 - x0) / parent.value;
221
+ while (++i < n) {
222
+ node = nodes[i], node.y0 = y0, node.y1 = y1;
223
+ node.x0 = x0, node.x1 = x0 += node.value * k;
224
+ }
225
+ }
226
+ function treemapSlice(parent, x0, y0, x1, y1) {
227
+ var nodes = parent.children, node, i = -1, n = nodes.length, k = parent.value && (y1 - y0) / parent.value;
228
+ while (++i < n) {
229
+ node = nodes[i], node.x0 = x0, node.x1 = x1;
230
+ node.y0 = y0, node.y1 = y0 += node.value * k;
231
+ }
232
+ }
233
+ var phi = (1 + Math.sqrt(5)) / 2;
234
+ function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
235
+ var rows = [], nodes = parent.children, row, nodeValue, i0 = 0, i1 = 0, n = nodes.length, dx, dy, value = parent.value, sumValue, minValue, maxValue, newRatio, minRatio, alpha, beta;
236
+ while (i0 < n) {
237
+ dx = x1 - x0, dy = y1 - y0;
238
+ do
239
+ sumValue = nodes[i1++].value;
240
+ while (!sumValue && i1 < n);
241
+ minValue = maxValue = sumValue;
242
+ alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
243
+ beta = sumValue * sumValue * alpha;
244
+ minRatio = Math.max(maxValue / beta, beta / minValue);
245
+ for (; i1 < n; ++i1) {
246
+ sumValue += nodeValue = nodes[i1].value;
247
+ if (nodeValue < minValue) minValue = nodeValue;
248
+ if (nodeValue > maxValue) maxValue = nodeValue;
249
+ beta = sumValue * sumValue * alpha;
250
+ newRatio = Math.max(maxValue / beta, beta / minValue);
251
+ if (newRatio > minRatio) {
252
+ sumValue -= nodeValue;
253
+ break;
254
+ }
255
+ minRatio = newRatio;
256
+ }
257
+ rows.push(row = { value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1) });
258
+ if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
259
+ else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
260
+ value -= sumValue, i0 = i1;
261
+ }
262
+ return rows;
263
+ }
264
+ const squarify = (function custom(ratio) {
265
+ function squarify2(parent, x0, y0, x1, y1) {
266
+ squarifyRatio(ratio, parent, x0, y0, x1, y1);
267
+ }
268
+ squarify2.ratio = function(x) {
269
+ return custom((x = +x) > 1 ? x : 1);
270
+ };
271
+ return squarify2;
272
+ })(phi);
273
+ function treemap() {
274
+ var tile = squarify, round = false, dx = 1, dy = 1, paddingStack = [0], paddingInner = constantZero, paddingTop = constantZero, paddingRight = constantZero, paddingBottom = constantZero, paddingLeft = constantZero;
275
+ function treemap2(root) {
276
+ root.x0 = root.y0 = 0;
277
+ root.x1 = dx;
278
+ root.y1 = dy;
279
+ root.eachBefore(positionNode);
280
+ paddingStack = [0];
281
+ if (round) root.eachBefore(roundNode);
282
+ return root;
283
+ }
284
+ function positionNode(node) {
285
+ var p = paddingStack[node.depth], x0 = node.x0 + p, y0 = node.y0 + p, x1 = node.x1 - p, y1 = node.y1 - p;
286
+ if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
287
+ if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
288
+ node.x0 = x0;
289
+ node.y0 = y0;
290
+ node.x1 = x1;
291
+ node.y1 = y1;
292
+ if (node.children) {
293
+ p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
294
+ x0 += paddingLeft(node) - p;
295
+ y0 += paddingTop(node) - p;
296
+ x1 -= paddingRight(node) - p;
297
+ y1 -= paddingBottom(node) - p;
298
+ if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
299
+ if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
300
+ tile(node, x0, y0, x1, y1);
301
+ }
302
+ }
303
+ treemap2.round = function(x) {
304
+ return arguments.length ? (round = !!x, treemap2) : round;
305
+ };
306
+ treemap2.size = function(x) {
307
+ return arguments.length ? (dx = +x[0], dy = +x[1], treemap2) : [dx, dy];
308
+ };
309
+ treemap2.tile = function(x) {
310
+ return arguments.length ? (tile = required(x), treemap2) : tile;
311
+ };
312
+ treemap2.padding = function(x) {
313
+ return arguments.length ? treemap2.paddingInner(x).paddingOuter(x) : treemap2.paddingInner();
314
+ };
315
+ treemap2.paddingInner = function(x) {
316
+ return arguments.length ? (paddingInner = typeof x === "function" ? x : constant(+x), treemap2) : paddingInner;
317
+ };
318
+ treemap2.paddingOuter = function(x) {
319
+ return arguments.length ? treemap2.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap2.paddingTop();
320
+ };
321
+ treemap2.paddingTop = function(x) {
322
+ return arguments.length ? (paddingTop = typeof x === "function" ? x : constant(+x), treemap2) : paddingTop;
323
+ };
324
+ treemap2.paddingRight = function(x) {
325
+ return arguments.length ? (paddingRight = typeof x === "function" ? x : constant(+x), treemap2) : paddingRight;
326
+ };
327
+ treemap2.paddingBottom = function(x) {
328
+ return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant(+x), treemap2) : paddingBottom;
329
+ };
330
+ treemap2.paddingLeft = function(x) {
331
+ return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant(+x), treemap2) : paddingLeft;
332
+ };
333
+ return treemap2;
334
+ }
335
+ var TreeMapDB = (_a = class {
336
+ constructor() {
337
+ this.nodes = [];
338
+ this.levels = /* @__PURE__ */ new Map();
339
+ this.outerNodes = [];
340
+ this.classes = /* @__PURE__ */ new Map();
341
+ this.setAccTitle = setAccTitle;
342
+ this.getAccTitle = getAccTitle;
343
+ this.setDiagramTitle = setDiagramTitle;
344
+ this.getDiagramTitle = getDiagramTitle;
345
+ this.getAccDescription = getAccDescription;
346
+ this.setAccDescription = setAccDescription;
347
+ }
348
+ getNodes() {
349
+ return this.nodes;
350
+ }
351
+ getConfig() {
352
+ const defaultConfig = defaultConfig_default;
353
+ const userConfig = getConfig();
354
+ return cleanAndMerge({
355
+ ...defaultConfig.treemap,
356
+ ...userConfig.treemap ?? {}
357
+ });
358
+ }
359
+ addNode(node, level) {
360
+ this.nodes.push(node);
361
+ this.levels.set(node, level);
362
+ if (level === 0) {
363
+ this.outerNodes.push(node);
364
+ this.root ??= node;
365
+ }
366
+ }
367
+ getRoot() {
368
+ return { name: "", children: this.outerNodes };
369
+ }
370
+ addClass(id, _style) {
371
+ const styleClass = this.classes.get(id) ?? { id, styles: [], textStyles: [] };
372
+ const styles = _style.replace(/\\,/g, "§§§").replace(/,/g, ";").replace(/§§§/g, ",").split(";");
373
+ if (styles) {
374
+ styles.forEach((s) => {
375
+ if (isLabelStyle(s)) {
376
+ if (styleClass?.textStyles) {
377
+ styleClass.textStyles.push(s);
378
+ } else {
379
+ styleClass.textStyles = [s];
380
+ }
381
+ }
382
+ if (styleClass?.styles) {
383
+ styleClass.styles.push(s);
384
+ } else {
385
+ styleClass.styles = [s];
386
+ }
387
+ });
388
+ }
389
+ this.classes.set(id, styleClass);
390
+ }
391
+ getClasses() {
392
+ return this.classes;
393
+ }
394
+ getStylesForClass(classSelector) {
395
+ return this.classes.get(classSelector)?.styles ?? [];
396
+ }
397
+ clear() {
398
+ clear();
399
+ this.nodes = [];
400
+ this.levels = /* @__PURE__ */ new Map();
401
+ this.outerNodes = [];
402
+ this.classes = /* @__PURE__ */ new Map();
403
+ this.root = void 0;
404
+ }
405
+ }, __name(_a, "TreeMapDB"), _a);
406
+ function buildHierarchy(items) {
407
+ if (!items.length) {
408
+ return [];
409
+ }
410
+ const root = [];
411
+ const stack = [];
412
+ items.forEach((item) => {
413
+ const node = {
414
+ name: item.name,
415
+ children: item.type === "Leaf" ? void 0 : []
416
+ };
417
+ node.classSelector = item?.classSelector;
418
+ if (item?.cssCompiledStyles) {
419
+ node.cssCompiledStyles = [item.cssCompiledStyles];
420
+ }
421
+ if (item.type === "Leaf" && item.value !== void 0) {
422
+ node.value = item.value;
423
+ }
424
+ while (stack.length > 0 && stack[stack.length - 1].level >= item.level) {
425
+ stack.pop();
426
+ }
427
+ if (stack.length === 0) {
428
+ root.push(node);
429
+ } else {
430
+ const parent = stack[stack.length - 1].node;
431
+ if (parent.children) {
432
+ parent.children.push(node);
433
+ } else {
434
+ parent.children = [node];
435
+ }
436
+ }
437
+ if (item.type !== "Leaf") {
438
+ stack.push({ node, level: item.level });
439
+ }
440
+ });
441
+ return root;
442
+ }
443
+ __name(buildHierarchy, "buildHierarchy");
444
+ var populate = /* @__PURE__ */ __name((ast, db) => {
445
+ populateCommonDb(ast, db);
446
+ const items = [];
447
+ for (const row of ast.TreemapRows ?? []) {
448
+ if (row.$type === "ClassDefStatement") {
449
+ db.addClass(row.className ?? "", row.styleText ?? "");
450
+ }
451
+ }
452
+ for (const row of ast.TreemapRows ?? []) {
453
+ const item = row.item;
454
+ if (!item) {
455
+ continue;
456
+ }
457
+ const level = row.indent ? parseInt(row.indent) : 0;
458
+ const name = getItemName(item);
459
+ const styles = item.classSelector ? db.getStylesForClass(item.classSelector) : [];
460
+ const cssCompiledStyles = styles.length > 0 ? styles.join(";") : void 0;
461
+ const itemData = {
462
+ level,
463
+ name,
464
+ type: item.$type,
465
+ value: item.value,
466
+ classSelector: item.classSelector,
467
+ cssCompiledStyles
468
+ };
469
+ items.push(itemData);
470
+ }
471
+ const hierarchyNodes = buildHierarchy(items);
472
+ const addNodesRecursively = /* @__PURE__ */ __name((nodes, level) => {
473
+ for (const node of nodes) {
474
+ db.addNode(node, level);
475
+ if (node.children && node.children.length > 0) {
476
+ addNodesRecursively(node.children, level + 1);
477
+ }
478
+ }
479
+ }, "addNodesRecursively");
480
+ addNodesRecursively(hierarchyNodes, 0);
481
+ }, "populate");
482
+ var getItemName = /* @__PURE__ */ __name((item) => {
483
+ return item.name ? String(item.name) : "";
484
+ }, "getItemName");
485
+ var parser = {
486
+ // @ts-expect-error - TreeMapDB is not assignable to DiagramDB
487
+ parser: { yy: void 0 },
488
+ parse: /* @__PURE__ */ __name(async (text) => {
489
+ try {
490
+ const parseFunc = parse;
491
+ const ast = await parseFunc("treemap", text);
492
+ log.debug("Treemap AST:", ast);
493
+ const db = parser.parser?.yy;
494
+ if (!(db instanceof TreeMapDB)) {
495
+ throw new Error(
496
+ "parser.parser?.yy was not a TreemapDB. This is due to a bug within Mermaid, please report this issue at https://github.com/mermaid-js/mermaid/issues."
497
+ );
498
+ }
499
+ populate(ast, db);
500
+ } catch (error) {
501
+ log.error("Error parsing treemap:", error);
502
+ throw error;
503
+ }
504
+ }, "parse")
505
+ };
506
+ var DEFAULT_INNER_PADDING = 10;
507
+ var SECTION_INNER_PADDING = 10;
508
+ var SECTION_HEADER_HEIGHT = 25;
509
+ var draw = /* @__PURE__ */ __name((_text, id, _version, diagram2) => {
510
+ const treemapDb = diagram2.db;
511
+ const config = treemapDb.getConfig();
512
+ const treemapInnerPadding = config.padding ?? DEFAULT_INNER_PADDING;
513
+ const title = treemapDb.getDiagramTitle();
514
+ const root = treemapDb.getRoot();
515
+ const { themeVariables } = getConfig();
516
+ if (!root) {
517
+ return;
518
+ }
519
+ const titleHeight = title ? 30 : 0;
520
+ const svg = selectSvgElement(id);
521
+ const width = config.nodeWidth ? config.nodeWidth * SECTION_INNER_PADDING : 960;
522
+ const height = config.nodeHeight ? config.nodeHeight * SECTION_INNER_PADDING : 500;
523
+ const svgWidth = width;
524
+ const svgHeight = height + titleHeight;
525
+ svg.attr("viewBox", `0 0 ${svgWidth} ${svgHeight}`);
526
+ configureSvgSize(svg, svgHeight, svgWidth, config.useMaxWidth);
527
+ let valueFormat;
528
+ try {
529
+ const formatStr = config.valueFormat || ",";
530
+ if (formatStr === "$0,0") {
531
+ valueFormat = /* @__PURE__ */ __name((value) => "$" + format(",")(value), "valueFormat");
532
+ } else if (formatStr.startsWith("$") && formatStr.includes(",")) {
533
+ const precision = /\.\d+/.exec(formatStr);
534
+ const precisionStr = precision ? precision[0] : "";
535
+ valueFormat = /* @__PURE__ */ __name((value) => "$" + format("," + precisionStr)(value), "valueFormat");
536
+ } else if (formatStr.startsWith("$")) {
537
+ const restOfFormat = formatStr.substring(1);
538
+ valueFormat = /* @__PURE__ */ __name((value) => "$" + format(restOfFormat || "")(value), "valueFormat");
539
+ } else {
540
+ valueFormat = format(formatStr);
541
+ }
542
+ } catch (error) {
543
+ log.error("Error creating format function:", error);
544
+ valueFormat = format(",");
545
+ }
546
+ const colorScale = ordinal().range([
547
+ "transparent",
548
+ themeVariables.cScale0,
549
+ themeVariables.cScale1,
550
+ themeVariables.cScale2,
551
+ themeVariables.cScale3,
552
+ themeVariables.cScale4,
553
+ themeVariables.cScale5,
554
+ themeVariables.cScale6,
555
+ themeVariables.cScale7,
556
+ themeVariables.cScale8,
557
+ themeVariables.cScale9,
558
+ themeVariables.cScale10,
559
+ themeVariables.cScale11
560
+ ]);
561
+ const colorScalePeer = ordinal().range([
562
+ "transparent",
563
+ themeVariables.cScalePeer0,
564
+ themeVariables.cScalePeer1,
565
+ themeVariables.cScalePeer2,
566
+ themeVariables.cScalePeer3,
567
+ themeVariables.cScalePeer4,
568
+ themeVariables.cScalePeer5,
569
+ themeVariables.cScalePeer6,
570
+ themeVariables.cScalePeer7,
571
+ themeVariables.cScalePeer8,
572
+ themeVariables.cScalePeer9,
573
+ themeVariables.cScalePeer10,
574
+ themeVariables.cScalePeer11
575
+ ]);
576
+ const colorScaleLabel = ordinal().range([
577
+ themeVariables.cScaleLabel0,
578
+ themeVariables.cScaleLabel1,
579
+ themeVariables.cScaleLabel2,
580
+ themeVariables.cScaleLabel3,
581
+ themeVariables.cScaleLabel4,
582
+ themeVariables.cScaleLabel5,
583
+ themeVariables.cScaleLabel6,
584
+ themeVariables.cScaleLabel7,
585
+ themeVariables.cScaleLabel8,
586
+ themeVariables.cScaleLabel9,
587
+ themeVariables.cScaleLabel10,
588
+ themeVariables.cScaleLabel11
589
+ ]);
590
+ if (title) {
591
+ svg.append("text").attr("x", svgWidth / 2).attr("y", titleHeight / 2).attr("class", "treemapTitle").attr("text-anchor", "middle").attr("dominant-baseline", "middle").text(title);
592
+ }
593
+ const g = svg.append("g").attr("transform", `translate(0, ${titleHeight})`).attr("class", "treemapContainer");
594
+ const hierarchyRoot = hierarchy(root).sum((d) => d.value ?? 0).sort((a, b) => (b.value ?? 0) - (a.value ?? 0));
595
+ const treemapLayout = treemap().size([width, height]).paddingTop(
596
+ (d) => d.children && d.children.length > 0 ? SECTION_HEADER_HEIGHT + SECTION_INNER_PADDING : 0
597
+ ).paddingInner(treemapInnerPadding).paddingLeft((d) => d.children && d.children.length > 0 ? SECTION_INNER_PADDING : 0).paddingRight((d) => d.children && d.children.length > 0 ? SECTION_INNER_PADDING : 0).paddingBottom((d) => d.children && d.children.length > 0 ? SECTION_INNER_PADDING : 0).round(true);
598
+ const treemapData = treemapLayout(hierarchyRoot);
599
+ const branchNodes = treemapData.descendants().filter((d) => d.children && d.children.length > 0);
600
+ const sections = g.selectAll(".treemapSection").data(branchNodes).enter().append("g").attr("class", "treemapSection").attr("transform", (d) => `translate(${d.x0},${d.y0})`);
601
+ sections.append("rect").attr("width", (d) => d.x1 - d.x0).attr("height", SECTION_HEADER_HEIGHT).attr("class", "treemapSectionHeader").attr("fill", "none").attr("fill-opacity", 0.6).attr("stroke-width", 0.6).attr("style", (d) => {
602
+ if (d.depth === 0) {
603
+ return "display: none;";
604
+ }
605
+ return "";
606
+ });
607
+ sections.append("clipPath").attr("id", (_d, i) => `clip-section-${id}-${i}`).append("rect").attr("width", (d) => Math.max(0, d.x1 - d.x0 - 12)).attr("height", SECTION_HEADER_HEIGHT);
608
+ sections.append("rect").attr("width", (d) => d.x1 - d.x0).attr("height", (d) => d.y1 - d.y0).attr("class", (_d, i) => {
609
+ return `treemapSection section${i}`;
610
+ }).attr("fill", (d) => colorScale(d.data.name)).attr("fill-opacity", 0.6).attr("stroke", (d) => colorScalePeer(d.data.name)).attr("stroke-width", 2).attr("stroke-opacity", 0.4).attr("style", (d) => {
611
+ if (d.depth === 0) {
612
+ return "display: none;";
613
+ }
614
+ const styles = styles2String({ cssCompiledStyles: d.data.cssCompiledStyles });
615
+ return styles.nodeStyles + ";" + styles.borderStyles.join(";");
616
+ });
617
+ sections.append("text").attr("class", "treemapSectionLabel").attr("x", 6).attr("y", SECTION_HEADER_HEIGHT / 2).attr("dominant-baseline", "middle").text((d) => d.depth === 0 ? "" : d.data.name).attr("font-weight", "bold").attr("style", (d) => {
618
+ if (d.depth === 0) {
619
+ return "display: none;";
620
+ }
621
+ const labelStyles = "dominant-baseline: middle; font-size: 12px; fill:" + colorScaleLabel(d.data.name) + "; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;";
622
+ const styles = styles2String({ cssCompiledStyles: d.data.cssCompiledStyles });
623
+ return labelStyles + styles.labelStyles.replace("color:", "fill:");
624
+ }).each(function(d) {
625
+ if (d.depth === 0) {
626
+ return;
627
+ }
628
+ const self = select(this);
629
+ const originalText = d.data.name;
630
+ self.text(originalText);
631
+ const totalHeaderWidth = d.x1 - d.x0;
632
+ const labelXPosition = 6;
633
+ let spaceForTextContent;
634
+ if (config.showValues !== false && d.value) {
635
+ const valueEndsAtXRelative = totalHeaderWidth - 10;
636
+ const estimatedValueTextActualWidth = 30;
637
+ const gapBetweenLabelAndValue = 10;
638
+ const labelMustEndBeforeX = valueEndsAtXRelative - estimatedValueTextActualWidth - gapBetweenLabelAndValue;
639
+ spaceForTextContent = labelMustEndBeforeX - labelXPosition;
640
+ } else {
641
+ const labelOwnRightPadding = 6;
642
+ spaceForTextContent = totalHeaderWidth - labelXPosition - labelOwnRightPadding;
643
+ }
644
+ const minimumWidthToDisplay = 15;
645
+ const actualAvailableWidth = Math.max(minimumWidthToDisplay, spaceForTextContent);
646
+ const textNode = self.node();
647
+ const currentTextContentLength = textNode.getComputedTextLength();
648
+ if (currentTextContentLength > actualAvailableWidth) {
649
+ const ellipsis = "...";
650
+ let currentTruncatedText = originalText;
651
+ while (currentTruncatedText.length > 0) {
652
+ currentTruncatedText = originalText.substring(0, currentTruncatedText.length - 1);
653
+ if (currentTruncatedText.length === 0) {
654
+ self.text(ellipsis);
655
+ if (textNode.getComputedTextLength() > actualAvailableWidth) {
656
+ self.text("");
657
+ }
658
+ break;
659
+ }
660
+ self.text(currentTruncatedText + ellipsis);
661
+ if (textNode.getComputedTextLength() <= actualAvailableWidth) {
662
+ break;
663
+ }
664
+ }
665
+ }
666
+ });
667
+ if (config.showValues !== false) {
668
+ sections.append("text").attr("class", "treemapSectionValue").attr("x", (d) => d.x1 - d.x0 - 10).attr("y", SECTION_HEADER_HEIGHT / 2).attr("text-anchor", "end").attr("dominant-baseline", "middle").text((d) => d.value ? valueFormat(d.value) : "").attr("font-style", "italic").attr("style", (d) => {
669
+ if (d.depth === 0) {
670
+ return "display: none;";
671
+ }
672
+ const labelStyles = "text-anchor: end; dominant-baseline: middle; font-size: 10px; fill:" + colorScaleLabel(d.data.name) + "; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;";
673
+ const styles = styles2String({ cssCompiledStyles: d.data.cssCompiledStyles });
674
+ return labelStyles + styles.labelStyles.replace("color:", "fill:");
675
+ });
676
+ }
677
+ const leafNodes = treemapData.leaves();
678
+ const cell = g.selectAll(".treemapLeafGroup").data(leafNodes).enter().append("g").attr("class", (d, i) => {
679
+ return `treemapNode treemapLeafGroup leaf${i}${d.data.classSelector ? ` ${d.data.classSelector}` : ""}x`;
680
+ }).attr("transform", (d) => `translate(${d.x0},${d.y0})`);
681
+ cell.append("rect").attr("width", (d) => d.x1 - d.x0).attr("height", (d) => d.y1 - d.y0).attr("class", "treemapLeaf").attr("fill", (d) => {
682
+ return d.parent ? colorScale(d.parent.data.name) : colorScale(d.data.name);
683
+ }).attr("style", (d) => {
684
+ const styles = styles2String({ cssCompiledStyles: d.data.cssCompiledStyles });
685
+ return styles.nodeStyles;
686
+ }).attr("fill-opacity", 0.3).attr("stroke", (d) => {
687
+ return d.parent ? colorScale(d.parent.data.name) : colorScale(d.data.name);
688
+ }).attr("stroke-width", 3);
689
+ cell.append("clipPath").attr("id", (_d, i) => `clip-${id}-${i}`).append("rect").attr("width", (d) => Math.max(0, d.x1 - d.x0 - 4)).attr("height", (d) => Math.max(0, d.y1 - d.y0 - 4));
690
+ const leafLabels = cell.append("text").attr("class", "treemapLabel").attr("x", (d) => (d.x1 - d.x0) / 2).attr("y", (d) => (d.y1 - d.y0) / 2).attr("style", (d) => {
691
+ const labelStyles = "text-anchor: middle; dominant-baseline: middle; font-size: 38px;fill:" + colorScaleLabel(d.data.name) + ";";
692
+ const styles = styles2String({ cssCompiledStyles: d.data.cssCompiledStyles });
693
+ return labelStyles + styles.labelStyles.replace("color:", "fill:");
694
+ }).attr("clip-path", (_d, i) => `url(#clip-${id}-${i})`).text((d) => d.data.name);
695
+ leafLabels.each(function(d) {
696
+ const self = select(this);
697
+ const nodeWidth = d.x1 - d.x0;
698
+ const nodeHeight = d.y1 - d.y0;
699
+ const textNode = self.node();
700
+ const padding = 4;
701
+ const availableWidth = nodeWidth - 2 * padding;
702
+ const availableHeight = nodeHeight - 2 * padding;
703
+ if (availableWidth < 10 || availableHeight < 10) {
704
+ self.style("display", "none");
705
+ return;
706
+ }
707
+ let currentLabelFontSize = parseInt(self.style("font-size"), 10);
708
+ const minLabelFontSize = 8;
709
+ const originalValueRelFontSize = 28;
710
+ const valueScaleFactor = 0.6;
711
+ const minValueFontSize = 6;
712
+ const spacingBetweenLabelAndValue = 2;
713
+ while (textNode.getComputedTextLength() > availableWidth && currentLabelFontSize > minLabelFontSize) {
714
+ currentLabelFontSize--;
715
+ self.style("font-size", `${currentLabelFontSize}px`);
716
+ }
717
+ let prospectiveValueFontSize = Math.max(
718
+ minValueFontSize,
719
+ Math.min(originalValueRelFontSize, Math.round(currentLabelFontSize * valueScaleFactor))
720
+ );
721
+ let combinedHeight = currentLabelFontSize + spacingBetweenLabelAndValue + prospectiveValueFontSize;
722
+ while (combinedHeight > availableHeight && currentLabelFontSize > minLabelFontSize) {
723
+ currentLabelFontSize--;
724
+ prospectiveValueFontSize = Math.max(
725
+ minValueFontSize,
726
+ Math.min(originalValueRelFontSize, Math.round(currentLabelFontSize * valueScaleFactor))
727
+ );
728
+ if (prospectiveValueFontSize < minValueFontSize && currentLabelFontSize === minLabelFontSize) {
729
+ break;
730
+ }
731
+ self.style("font-size", `${currentLabelFontSize}px`);
732
+ combinedHeight = currentLabelFontSize + spacingBetweenLabelAndValue + prospectiveValueFontSize;
733
+ }
734
+ self.style("font-size", `${currentLabelFontSize}px`);
735
+ if (textNode.getComputedTextLength() > availableWidth || currentLabelFontSize < minLabelFontSize || availableHeight < currentLabelFontSize) {
736
+ self.style("display", "none");
737
+ }
738
+ });
739
+ if (config.showValues !== false) {
740
+ const leafValues = cell.append("text").attr("class", "treemapValue").attr("x", (d) => (d.x1 - d.x0) / 2).attr("y", function(d) {
741
+ return (d.y1 - d.y0) / 2;
742
+ }).attr("style", (d) => {
743
+ const labelStyles = "text-anchor: middle; dominant-baseline: hanging; font-size: 28px;fill:" + colorScaleLabel(d.data.name) + ";";
744
+ const styles = styles2String({ cssCompiledStyles: d.data.cssCompiledStyles });
745
+ return labelStyles + styles.labelStyles.replace("color:", "fill:");
746
+ }).attr("clip-path", (_d, i) => `url(#clip-${id}-${i})`).text((d) => d.value ? valueFormat(d.value) : "");
747
+ leafValues.each(function(d) {
748
+ const valueTextElement = select(this);
749
+ const parentCellNode = this.parentNode;
750
+ if (!parentCellNode) {
751
+ valueTextElement.style("display", "none");
752
+ return;
753
+ }
754
+ const labelElement = select(parentCellNode).select(".treemapLabel");
755
+ if (labelElement.empty() || labelElement.style("display") === "none") {
756
+ valueTextElement.style("display", "none");
757
+ return;
758
+ }
759
+ const finalLabelFontSize = parseFloat(labelElement.style("font-size"));
760
+ const originalValueFontSize = 28;
761
+ const valueScaleFactor = 0.6;
762
+ const minValueFontSize = 6;
763
+ const spacingBetweenLabelAndValue = 2;
764
+ const actualValueFontSize = Math.max(
765
+ minValueFontSize,
766
+ Math.min(originalValueFontSize, Math.round(finalLabelFontSize * valueScaleFactor))
767
+ );
768
+ valueTextElement.style("font-size", `${actualValueFontSize}px`);
769
+ const labelCenterY = (d.y1 - d.y0) / 2;
770
+ const valueTopActualY = labelCenterY + finalLabelFontSize / 2 + spacingBetweenLabelAndValue;
771
+ valueTextElement.attr("y", valueTopActualY);
772
+ const nodeWidth = d.x1 - d.x0;
773
+ const nodeTotalHeight = d.y1 - d.y0;
774
+ const cellBottomPadding = 4;
775
+ const maxValueBottomY = nodeTotalHeight - cellBottomPadding;
776
+ const availableWidthForValue = nodeWidth - 2 * 4;
777
+ if (valueTextElement.node().getComputedTextLength() > availableWidthForValue || valueTopActualY + actualValueFontSize > maxValueBottomY || actualValueFontSize < minValueFontSize) {
778
+ valueTextElement.style("display", "none");
779
+ } else {
780
+ valueTextElement.style("display", null);
781
+ }
782
+ });
783
+ }
784
+ const diagramPadding = config.diagramPadding ?? 8;
785
+ setupViewPortForSVG(svg, diagramPadding, "flowchart", config?.useMaxWidth || false);
786
+ }, "draw");
787
+ var getClasses = /* @__PURE__ */ __name(function(_text, diagramObj) {
788
+ return diagramObj.db.getClasses();
789
+ }, "getClasses");
790
+ var renderer = { draw, getClasses };
791
+ var defaultTreemapStyleOptions = {
792
+ sectionStrokeColor: "black",
793
+ sectionStrokeWidth: "1",
794
+ sectionFillColor: "#efefef",
795
+ leafStrokeColor: "black",
796
+ leafStrokeWidth: "1",
797
+ leafFillColor: "#efefef",
798
+ labelColor: "black",
799
+ labelFontSize: "12px",
800
+ valueFontSize: "10px",
801
+ valueColor: "black",
802
+ titleColor: "black",
803
+ titleFontSize: "14px"
804
+ };
805
+ var getStyles = /* @__PURE__ */ __name(({
806
+ treemap: treemap2
807
+ } = {}) => {
808
+ const options = cleanAndMerge(defaultTreemapStyleOptions, treemap2);
809
+ return `
810
+ .treemapNode.section {
811
+ stroke: ${options.sectionStrokeColor};
812
+ stroke-width: ${options.sectionStrokeWidth};
813
+ fill: ${options.sectionFillColor};
814
+ }
815
+ .treemapNode.leaf {
816
+ stroke: ${options.leafStrokeColor};
817
+ stroke-width: ${options.leafStrokeWidth};
818
+ fill: ${options.leafFillColor};
819
+ }
820
+ .treemapLabel {
821
+ fill: ${options.labelColor};
822
+ font-size: ${options.labelFontSize};
823
+ }
824
+ .treemapValue {
825
+ fill: ${options.valueColor};
826
+ font-size: ${options.valueFontSize};
827
+ }
828
+ .treemapTitle {
829
+ fill: ${options.titleColor};
830
+ font-size: ${options.titleFontSize};
831
+ }
832
+ `;
833
+ }, "getStyles");
834
+ var styles_default = getStyles;
835
+ var diagram = {
836
+ parser,
837
+ get db() {
838
+ return new TreeMapDB();
839
+ },
840
+ renderer,
841
+ styles: styles_default
842
+ };
843
+ export {
844
+ diagram
845
+ };