@diagrammo/dgmo 0.46.0 → 0.47.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.
Files changed (232) hide show
  1. package/dist/advanced.d.cts +3 -855
  2. package/dist/advanced.d.ts +3 -855
  3. package/dist/advanced.js +541 -70107
  4. package/dist/analyzer-UYKBXAKR.js +15 -0
  5. package/dist/auto.cjs +1 -1
  6. package/dist/auto.js +1 -1
  7. package/dist/auto.mjs +1 -1
  8. package/dist/block.js +83 -69417
  9. package/dist/calculator-LDYQCDDY.js +11 -0
  10. package/dist/charts-d3-QOZHKTCT.js +25 -0
  11. package/dist/chunk-2DXMZRWJ.js +800 -0
  12. package/dist/chunk-2LACINWN.js +786 -0
  13. package/dist/chunk-33LCUH4H.js +893 -0
  14. package/dist/chunk-3CIOJ5YJ.js +35 -0
  15. package/dist/chunk-3HDBAXF5.js +86 -0
  16. package/dist/chunk-3JLKYGBQ.js +290 -0
  17. package/dist/chunk-3MQQNXPD.js +415 -0
  18. package/dist/chunk-3R5POCTZ.js +967 -0
  19. package/dist/chunk-3SMGIJDD.js +112 -0
  20. package/dist/chunk-44CM72SQ.js +409 -0
  21. package/dist/chunk-4GRI7MEB.js +1604 -0
  22. package/dist/chunk-4OHACBGX.js +606 -0
  23. package/dist/chunk-5DH3KYFH.js +21 -0
  24. package/dist/chunk-5MLYVTYM.js +76 -0
  25. package/dist/chunk-5QXL4NYS.js +553 -0
  26. package/dist/chunk-5WRI5ZAA.js +31 -0
  27. package/dist/chunk-6EK55ART.js +117 -0
  28. package/dist/chunk-6FZYCKXB.js +2065 -0
  29. package/dist/chunk-6HO5ZTXK.js +277 -0
  30. package/dist/chunk-6KFWC4CO.js +7 -0
  31. package/dist/chunk-6MTWIQVO.js +121 -0
  32. package/dist/chunk-6NYWYNBI.js +329 -0
  33. package/dist/chunk-6SM5NJQH.js +620 -0
  34. package/dist/chunk-725LDASD.js +422 -0
  35. package/dist/chunk-76OWZ3BA.js +130 -0
  36. package/dist/chunk-7JEGTRLD.js +338 -0
  37. package/dist/chunk-A44USUV7.js +923 -0
  38. package/dist/chunk-A4GOY3PE.js +25 -0
  39. package/dist/chunk-A4VFQH5G.js +251 -0
  40. package/dist/chunk-AELOBFW5.js +375 -0
  41. package/dist/chunk-AN2MOO5T.js +522 -0
  42. package/dist/chunk-BMR4CIEO.js +41 -0
  43. package/dist/chunk-BS7SV7C3.js +51 -0
  44. package/dist/chunk-BUPDIHML.js +613 -0
  45. package/dist/chunk-BUVJFRPY.js +887 -0
  46. package/dist/chunk-C3Z4DX3V.js +112 -0
  47. package/dist/chunk-CI2G3OEB.js +1818 -0
  48. package/dist/chunk-CKNVO24D.js +54 -0
  49. package/dist/chunk-CUVHQHZ7.js +391 -0
  50. package/dist/chunk-CXK4DZH3.js +114 -0
  51. package/dist/chunk-DKEPS5LH.js +315 -0
  52. package/dist/chunk-DU7W62N5.js +487 -0
  53. package/dist/chunk-DZAQBW35.js +751 -0
  54. package/dist/chunk-EB6FPQUP.js +316 -0
  55. package/dist/chunk-EMS2SK26.js +376 -0
  56. package/dist/chunk-ERLBPDGU.js +510 -0
  57. package/dist/chunk-EVCVDTXE.js +732 -0
  58. package/dist/chunk-FCIIHT24.js +384 -0
  59. package/dist/chunk-FFUN5D66.js +97 -0
  60. package/dist/chunk-FITOLXSX.js +714 -0
  61. package/dist/chunk-FMDSF3OV.js +68 -0
  62. package/dist/chunk-FNB3PNGF.js +410 -0
  63. package/dist/chunk-G2H74XJZ.js +2104 -0
  64. package/dist/chunk-GMR5MFHJ.js +339 -0
  65. package/dist/chunk-H6PI3KJT.js +305 -0
  66. package/dist/chunk-I46X5VUA.js +59 -0
  67. package/dist/chunk-I5IGB56C.js +255 -0
  68. package/dist/chunk-IH6ZMVQ5.js +3950 -0
  69. package/dist/chunk-IJZFN3HM.js +463 -0
  70. package/dist/chunk-IPWPWM6R.js +3079 -0
  71. package/dist/chunk-IYULMRBE.js +23 -0
  72. package/dist/chunk-IZMRON6C.js +167 -0
  73. package/dist/chunk-J5FIXQRT.js +813 -0
  74. package/dist/chunk-JED6ZDEE.js +73 -0
  75. package/dist/chunk-JEUJOX5X.js +136 -0
  76. package/dist/chunk-JM4LEPY3.js +436 -0
  77. package/dist/chunk-L3UHP6TD.js +101 -0
  78. package/dist/chunk-L66GEFB6.js +524 -0
  79. package/dist/chunk-LIOHW36Z.js +469 -0
  80. package/dist/chunk-LP7EC4MI.js +16 -0
  81. package/dist/chunk-MITI6NOL.js +548 -0
  82. package/dist/chunk-MO5YHHMQ.js +168 -0
  83. package/dist/chunk-MZSBFAPJ.js +885 -0
  84. package/dist/chunk-NNAAJVBU.js +9 -0
  85. package/dist/chunk-NOTA6TEI.js +47 -0
  86. package/dist/chunk-NURGB5Z4.js +335 -0
  87. package/dist/chunk-NX4EQS3U.js +1062 -0
  88. package/dist/chunk-NXMESY4J.js +1 -0
  89. package/dist/chunk-OJR3MQYV.js +1458 -0
  90. package/dist/chunk-OURHMODR.js +454 -0
  91. package/dist/chunk-P235SVAH.js +1057 -0
  92. package/dist/chunk-P4RH4OSP.js +1038 -0
  93. package/dist/chunk-P6T66CCZ.js +226 -0
  94. package/dist/chunk-PBAHEPLQ.js +223 -0
  95. package/dist/chunk-PBHE5UG6.js +1530 -0
  96. package/dist/chunk-PDKUANDZ.js +35 -0
  97. package/dist/chunk-PWIHZ6NJ.js +296 -0
  98. package/dist/chunk-QEBUY5NY.js +1685 -0
  99. package/dist/chunk-QLCCJEJI.js +253 -0
  100. package/dist/chunk-QOOUC2J5.js +52 -0
  101. package/dist/chunk-QYTPPDAO.js +402 -0
  102. package/dist/chunk-R3XI2VC7.js +801 -0
  103. package/dist/chunk-RCERWOJR.js +154 -0
  104. package/dist/chunk-RJE5JTVK.js +362 -0
  105. package/dist/chunk-RTLBSQ3G.js +1155 -0
  106. package/dist/chunk-RUNNI6VE.js +448 -0
  107. package/dist/chunk-RVMRZAPB.js +354 -0
  108. package/dist/chunk-RYEGFMUO.js +955 -0
  109. package/dist/chunk-RZCF2VVM.js +528 -0
  110. package/dist/chunk-SML67VPV.js +1025 -0
  111. package/dist/chunk-SQ7IY53Q.js +44 -0
  112. package/dist/chunk-SQAG3UXH.js +161 -0
  113. package/dist/chunk-SRTU6HMQ.js +1851 -0
  114. package/dist/chunk-T2OE3YQB.js +550 -0
  115. package/dist/chunk-T3UBLACL.js +299 -0
  116. package/dist/chunk-TLVIHFRO.js +296 -0
  117. package/dist/chunk-TYS6CSS5.js +52 -0
  118. package/dist/chunk-U6EQI3U6.js +130 -0
  119. package/dist/chunk-UJ4FJLBF.js +86 -0
  120. package/dist/chunk-ULOEATBZ.js +347 -0
  121. package/dist/chunk-UNCCZ3NU.js +127 -0
  122. package/dist/chunk-USZW2HHU.js +197 -0
  123. package/dist/chunk-UWN33VNX.js +1610 -0
  124. package/dist/chunk-UZ7EZW3B.js +40 -0
  125. package/dist/chunk-VOKGH627.js +37 -0
  126. package/dist/chunk-WBRZJOEC.js +204 -0
  127. package/dist/chunk-WCSOJFU3.js +380 -0
  128. package/dist/chunk-WCT3NYCV.js +160 -0
  129. package/dist/chunk-WVAJFAIA.js +529 -0
  130. package/dist/chunk-X5LCYCL5.js +394 -0
  131. package/dist/chunk-XAKEUMEJ.js +1256 -0
  132. package/dist/chunk-Y2ZE3MSG.js +590 -0
  133. package/dist/chunk-Y3J7VR52.js +646 -0
  134. package/dist/chunk-Y5QGVTVC.js +33 -0
  135. package/dist/chunk-YAA6IID3.js +548 -0
  136. package/dist/chunk-YGJTDXVR.js +692 -0
  137. package/dist/chunk-YRYKTYMQ.js +186 -0
  138. package/dist/chunk-YYVTBZZC.js +61 -0
  139. package/dist/chunk-Z5CGSFJB.js +647 -0
  140. package/dist/chunk-Z72XRXD4.js +787 -0
  141. package/dist/chunk-ZGR7ULFJ.js +978 -0
  142. package/dist/chunk-ZJEL4H2R.js +851 -0
  143. package/dist/chunk-ZO27FGJS.js +554 -0
  144. package/dist/collapse-CLPJD2RL.js +11 -0
  145. package/dist/collapse-SLINJQW6.js +9 -0
  146. package/dist/collapse-ZWUFFCK2.js +9 -0
  147. package/dist/compute-G55RG53N.js +8 -0
  148. package/dist/dgmo-router-DZCIDUO5.js +73 -0
  149. package/dist/dimensions-J3FHIMJ6.js +22 -0
  150. package/dist/element.cjs +1 -1
  151. package/dist/element.js +1 -1
  152. package/dist/element.mjs +1 -1
  153. package/dist/flowchart-parser-ZNSKIBVR.js +21 -0
  154. package/dist/flowchart-renderer-ZAEOL4DX.js +35 -0
  155. package/dist/index.cjs +3 -3
  156. package/dist/index.d.cts +3 -469
  157. package/dist/index.d.ts +3 -469
  158. package/dist/index.js +137 -69685
  159. package/dist/layout-46N4JJYK.js +17 -0
  160. package/dist/layout-5RA6QWR6.js +26 -0
  161. package/dist/layout-5T6RH5M6.js +14 -0
  162. package/dist/layout-7QXCNOVS.js +13 -0
  163. package/dist/layout-EE6GE46Y.js +17 -0
  164. package/dist/layout-G23F7LDH.js +9 -0
  165. package/dist/layout-HRBZPFCN.js +23 -0
  166. package/dist/layout-HWDSRX5E.js +20 -0
  167. package/dist/layout-HYZPWAK5.js +18 -0
  168. package/dist/layout-N76NR4ZO.js +19 -0
  169. package/dist/layout-OB3RI63S.js +14 -0
  170. package/dist/layout-S2QBYSK2.js +15 -0
  171. package/dist/layout-UM5F4DJB.js +15 -0
  172. package/dist/layout-search-OYV77HHS.js +1655 -0
  173. package/dist/load-data-EHDDZ5ZS.js +8 -0
  174. package/dist/palettes-PRJ2RI6D.js +56 -0
  175. package/dist/parser-2MFP2H2E.js +11 -0
  176. package/dist/parser-3STE62GB.js +21 -0
  177. package/dist/parser-4FL2CMDG.js +18 -0
  178. package/dist/parser-4OGOBJJ4.js +13 -0
  179. package/dist/parser-6BTRLKRZ.js +15 -0
  180. package/dist/parser-AQETEVRW.js +21 -0
  181. package/dist/parser-CFZD5IBL.js +12 -0
  182. package/dist/parser-FUSKFGZN.js +16 -0
  183. package/dist/parser-I6KXEYFK.js +13 -0
  184. package/dist/parser-IXSZZQHY.js +18 -0
  185. package/dist/parser-JAL2HD4I.js +13 -0
  186. package/dist/parser-KNSQSKQO.js +20 -0
  187. package/dist/parser-N5O4IHUN.js +13 -0
  188. package/dist/parser-NGU3ETO6.js +16 -0
  189. package/dist/parser-NRAI6O25.js +19 -0
  190. package/dist/parser-O5J4VBII.js +11 -0
  191. package/dist/parser-OV7NOBW6.js +21 -0
  192. package/dist/parser-PQ3POX45.js +23 -0
  193. package/dist/parser-TFZFBVWN.js +11 -0
  194. package/dist/parser-TRTHDFPP.js +18 -0
  195. package/dist/parser-VQP2UJ6W.js +11 -0
  196. package/dist/parser-XDVELHRK.js +13 -0
  197. package/dist/parser-XKRP7QKP.js +11 -0
  198. package/dist/parser-Y6WTBU76.js +14 -0
  199. package/dist/parser-ZSDPZYQP.js +12 -0
  200. package/dist/renderer-2XQQQ6QR.js +28 -0
  201. package/dist/renderer-5NDVNDAZ.js +26 -0
  202. package/dist/renderer-6EEZHMH4.js +26 -0
  203. package/dist/renderer-6W5462RB.js +43 -0
  204. package/dist/renderer-7MVLWWQD.js +22 -0
  205. package/dist/renderer-AWWAF6XD.js +33 -0
  206. package/dist/renderer-BYCNMBF7.js +34 -0
  207. package/dist/renderer-CLJHQPBJ.js +29 -0
  208. package/dist/renderer-GHPZMFU2.js +15 -0
  209. package/dist/renderer-JGBKUCZD.js +16 -0
  210. package/dist/renderer-KQB7UGDS.js +19 -0
  211. package/dist/renderer-PGX2TKVS.js +24 -0
  212. package/dist/renderer-QIWVHWZO.js +15 -0
  213. package/dist/renderer-RPOA5YPZ.js +35 -0
  214. package/dist/renderer-SMIBCRVB.js +24 -0
  215. package/dist/renderer-T7YKC5VP.js +28 -0
  216. package/dist/renderer-TOCOVLHS.js +37 -0
  217. package/dist/renderer-UWA5XS74.js +39 -0
  218. package/dist/renderer-VACVQYML.js +25 -0
  219. package/dist/renderer-W4M6QLIJ.js +37 -0
  220. package/dist/renderer-WZRREQ2P.js +23 -0
  221. package/dist/renderer-YY2OSF6E.js +27 -0
  222. package/dist/renderer-Z7I3W2PP.js +24 -0
  223. package/dist/renderer-ZGNTUWC4.js +22 -0
  224. package/dist/renderer-ZTR3DER3.js +19 -0
  225. package/dist/renderer-radial-C32GPJQ7.js +21 -0
  226. package/dist/resolver-NOAA7ID7.js +13 -0
  227. package/dist/state-collapse-HCGD6IVJ.js +8 -0
  228. package/dist/state-parser-Z2V23ATR.js +18 -0
  229. package/dist/state-renderer-RFYHSP4K.js +34 -0
  230. package/dist/themes-1-CuKpeH.d.cts +908 -0
  231. package/dist/themes-1-CuKpeH.d.ts +908 -0
  232. package/package.json +1 -1
@@ -0,0 +1,967 @@
1
+ import {
2
+ renderInlineText
3
+ } from "./chunk-3HDBAXF5.js";
4
+ import {
5
+ wrapDescriptionLines
6
+ } from "./chunk-BMR4CIEO.js";
7
+ import {
8
+ renderIntegratedLegend
9
+ } from "./chunk-PWIHZ6NJ.js";
10
+ import {
11
+ ScaleContext
12
+ } from "./chunk-YYVTBZZC.js";
13
+ import {
14
+ TITLE_FONT_SIZE,
15
+ TITLE_FONT_WEIGHT,
16
+ TITLE_Y
17
+ } from "./chunk-A4GOY3PE.js";
18
+ import {
19
+ FONT_FAMILY
20
+ } from "./chunk-6KFWC4CO.js";
21
+ import {
22
+ LEGEND_HEIGHT
23
+ } from "./chunk-QOOUC2J5.js";
24
+ import {
25
+ measureText,
26
+ wrapTextToWidth
27
+ } from "./chunk-WCT3NYCV.js";
28
+ import {
29
+ contrastText,
30
+ shapeFill
31
+ } from "./chunk-P6T66CCZ.js";
32
+ import {
33
+ resolveColor
34
+ } from "./chunk-TLVIHFRO.js";
35
+
36
+ // src/cycle/renderer.ts
37
+ import * as d3Selection from "d3-selection";
38
+
39
+ // src/cycle/types.ts
40
+ var DEFAULT_EDGE_WIDTH = 3;
41
+ var MIN_EDGE_WIDTH = 2;
42
+ var BASE_ARROW_SIZE = 8;
43
+ var ARROW_SCALE = 6;
44
+ function arrowHeadLength(strokeWidth) {
45
+ return BASE_ARROW_SIZE + ARROW_SCALE * Math.sqrt(strokeWidth);
46
+ }
47
+
48
+ // src/cycle/layout.ts
49
+ var MIN_ARC_ANGLE = 15 * Math.PI / 180;
50
+ var LABEL_FONT_SIZE = 13;
51
+ var CIRCLE_LABEL_FONT_SIZE = 16;
52
+ var DESC_FONT_SIZE = 11;
53
+ var EDGE_LABEL_FONT_SIZE = 11;
54
+ var MIN_NODE_WIDTH = 70;
55
+ var MAX_NODE_WIDTH = 260;
56
+ var DESC_MIN_WIDTH = 140;
57
+ var DESC_WIDTH_STEP = 20;
58
+ var DESC_TARGET_RATIO = 1.6;
59
+ var PLAIN_NODE_HEIGHT = 50;
60
+ var HEADER_HEIGHT = 36;
61
+ var DESC_LINE_HEIGHT = 16;
62
+ var DESC_PAD_Y = 14;
63
+ var NODE_PAD_X = 20;
64
+ var MIN_CIRCLE_RADIUS = 35;
65
+ var CIRCLE_PAD = 14;
66
+ function computeCycleLayout(parsed, options) {
67
+ const width = options?.width ?? 800;
68
+ const height = options?.height ?? 600;
69
+ const hideDescriptions = options?.hideDescriptions ?? false;
70
+ if (parsed.nodes.length === 0) {
71
+ return {
72
+ nodes: [],
73
+ edges: [],
74
+ cx: width / 2,
75
+ cy: height / 2,
76
+ radius: 0,
77
+ width,
78
+ height,
79
+ scale: 1
80
+ };
81
+ }
82
+ const nodeCount = parsed.nodes.length;
83
+ const cx = width / 2;
84
+ const cy = height / 2;
85
+ const circleNodes = parsed.options["circle-nodes"] === "true";
86
+ const nodeDims = parsed.nodes.map((node) => {
87
+ const hasDesc = !hideDescriptions && node.description.length > 0;
88
+ const labelWidth = Math.max(
89
+ MIN_NODE_WIDTH,
90
+ measureText(node.label, LABEL_FONT_SIZE) + NODE_PAD_X * 2
91
+ );
92
+ if (circleNodes) {
93
+ return computeCircleNodeDims(node, hasDesc);
94
+ }
95
+ if (!hasDesc) {
96
+ return {
97
+ width: Math.min(MAX_NODE_WIDTH, labelWidth),
98
+ height: PLAIN_NODE_HEIGHT,
99
+ wrappedDesc: []
100
+ };
101
+ }
102
+ return chooseDescribedRectDims(node.description, labelWidth);
103
+ });
104
+ if (circleNodes) {
105
+ const maxDiam = Math.max(...nodeDims.map((d) => d.width));
106
+ for (const d of nodeDims) {
107
+ d.width = maxDiam;
108
+ d.height = maxDiam;
109
+ const nodeIdx = nodeDims.indexOf(d);
110
+ const node = parsed.nodes[nodeIdx];
111
+ const hasDesc = !hideDescriptions && node.description.length > 0;
112
+ if (hasDesc) {
113
+ d.wrappedDesc = wrapLinesForCircle(node.description, maxDiam / 2).map(
114
+ (text) => ({ text, kind: "plain" })
115
+ );
116
+ }
117
+ }
118
+ }
119
+ const totalSpan = parsed.nodes.reduce((sum, n) => sum + n.span, 0);
120
+ let rawAngles = parsed.nodes.map((n) => n.span / totalSpan * 2 * Math.PI);
121
+ const tooSmall = rawAngles.filter((a) => a < MIN_ARC_ANGLE);
122
+ if (tooSmall.length > 0 && tooSmall.length < nodeCount) {
123
+ const deficit = tooSmall.reduce((sum, a) => sum + (MIN_ARC_ANGLE - a), 0);
124
+ const largeTotal = rawAngles.filter((a) => a >= MIN_ARC_ANGLE).reduce((sum, a) => sum + a, 0);
125
+ rawAngles = rawAngles.map((a) => {
126
+ if (a < MIN_ARC_ANGLE) return MIN_ARC_ANGLE;
127
+ return a - a / largeTotal * deficit;
128
+ });
129
+ }
130
+ const isClockwise = parsed.direction === "clockwise";
131
+ const GAP = 20;
132
+ let minRadiusForNodes = 0;
133
+ for (let i = 0; i < nodeCount; i++) {
134
+ const j = (i + 1) % nodeCount;
135
+ const diA = Math.sqrt(nodeDims[i].width ** 2 + nodeDims[i].height ** 2) / 2;
136
+ const diB = Math.sqrt(nodeDims[j].width ** 2 + nodeDims[j].height ** 2) / 2;
137
+ const neededChord = diA + diB + GAP;
138
+ const halfAngle = rawAngles[i] / 2;
139
+ if (halfAngle > 1e-3) {
140
+ const r = neededChord / (2 * Math.sin(halfAngle));
141
+ minRadiusForNodes = Math.max(minRadiusForNodes, r);
142
+ }
143
+ }
144
+ const maxNodeHalf = Math.max(
145
+ ...nodeDims.map((d) => Math.max(d.width, d.height) / 2)
146
+ );
147
+ const maxRadius = Math.min(cx, cy) - maxNodeHalf - 10;
148
+ let radius;
149
+ let scale = 1;
150
+ if (minRadiusForNodes <= maxRadius) {
151
+ radius = Math.max(100, maxRadius);
152
+ } else {
153
+ radius = Math.max(80, maxRadius);
154
+ scale = radius / minRadiusForNodes;
155
+ for (let i = 0; i < nodeDims.length; i++) {
156
+ const d = nodeDims[i];
157
+ const node = parsed.nodes[i];
158
+ const hasDesc = !hideDescriptions && node.description.length > 0;
159
+ const newW = Math.max(50, d.width * scale);
160
+ if (circleNodes) {
161
+ d.width = newW;
162
+ d.height = newW;
163
+ if (hasDesc) {
164
+ d.wrappedDesc = wrapLinesForCircle(node.description, newW / 2).map(
165
+ (text) => ({ text, kind: "plain" })
166
+ );
167
+ }
168
+ } else if (hasDesc) {
169
+ d.width = newW;
170
+ const layoutWidth = newW / scale;
171
+ d.wrappedDesc = wrapDescForWidth(node.description, layoutWidth);
172
+ d.height = renderedDescNodeHeight(d.wrappedDesc.length, scale);
173
+ } else {
174
+ d.width = newW;
175
+ d.height = Math.max(30, d.height * scale);
176
+ }
177
+ }
178
+ }
179
+ const nodeAngles = new Array(nodeCount);
180
+ for (let i = 0; i < nodeCount; i++) {
181
+ nodeAngles[i] = -Math.PI / 2 + i * (2 * Math.PI / nodeCount) * (isClockwise ? 1 : -1);
182
+ }
183
+ const ITERATIONS = 3;
184
+ const footprints = new Array(nodeCount);
185
+ for (let iter = 0; iter < ITERATIONS; iter++) {
186
+ for (let i = 0; i < nodeCount; i++) {
187
+ const theta = nodeAngles[i];
188
+ const approxX = cx + radius * Math.cos(theta);
189
+ const approxY = cy + radius * Math.sin(theta);
190
+ const hw = nodeDims[i].width / 2;
191
+ const hh = nodeDims[i].height / 2;
192
+ let exitCW, exitCCW;
193
+ if (circleNodes) {
194
+ const nodeR = hw;
195
+ exitCW = circleNodeExitAngle(nodeR, radius, theta, 1);
196
+ exitCCW = circleNodeExitAngle(nodeR, radius, theta, -1);
197
+ } else {
198
+ exitCW = circleRectExitAngle(
199
+ approxX,
200
+ approxY,
201
+ hw,
202
+ hh,
203
+ cx,
204
+ cy,
205
+ radius,
206
+ theta,
207
+ 1
208
+ );
209
+ exitCCW = circleRectExitAngle(
210
+ approxX,
211
+ approxY,
212
+ hw,
213
+ hh,
214
+ cx,
215
+ cy,
216
+ radius,
217
+ theta,
218
+ -1
219
+ );
220
+ }
221
+ footprints[i] = Math.abs(exitCW - exitCCW);
222
+ }
223
+ const totalFootprint = footprints.reduce(
224
+ (s, f) => s + f,
225
+ 0
226
+ );
227
+ const totalGapAngle = Math.max(0, 2 * Math.PI - totalFootprint);
228
+ const gapAngles = parsed.nodes.map(
229
+ (n) => n.span / totalSpan * totalGapAngle
230
+ );
231
+ let cumAngle = -Math.PI / 2;
232
+ for (let i = 0; i < nodeCount; i++) {
233
+ nodeAngles[i] = cumAngle;
234
+ const nextIdx = (i + 1) % nodeCount;
235
+ const advance = footprints[i] / 2 + gapAngles[i] + footprints[nextIdx] / 2;
236
+ cumAngle += isClockwise ? advance : -advance;
237
+ }
238
+ }
239
+ const layoutNodes = [];
240
+ for (let i = 0; i < nodeCount; i++) {
241
+ const angle = nodeAngles[i];
242
+ layoutNodes.push({
243
+ label: parsed.nodes[i].label,
244
+ x: cx + radius * Math.cos(angle),
245
+ y: cy + radius * Math.sin(angle),
246
+ angle,
247
+ width: nodeDims[i].width,
248
+ height: nodeDims[i].height,
249
+ wrappedDesc: nodeDims[i].wrappedDesc,
250
+ isCircle: circleNodes
251
+ });
252
+ }
253
+ let layoutEdges = computeEdgePaths(
254
+ layoutNodes,
255
+ parsed,
256
+ cx,
257
+ cy,
258
+ radius,
259
+ isClockwise
260
+ );
261
+ const fitResult = fitToCanvas(
262
+ layoutNodes,
263
+ layoutEdges,
264
+ parsed,
265
+ cx,
266
+ cy,
267
+ radius,
268
+ width,
269
+ height,
270
+ isClockwise
271
+ );
272
+ if (fitResult) {
273
+ radius = fitResult.radius;
274
+ for (let i = 0; i < nodeCount; i++) {
275
+ layoutNodes[i].x = cx + radius * Math.cos(nodeAngles[i]);
276
+ layoutNodes[i].y = cy + radius * Math.sin(nodeAngles[i]);
277
+ }
278
+ layoutEdges = computeEdgePaths(
279
+ layoutNodes,
280
+ parsed,
281
+ cx,
282
+ cy,
283
+ radius,
284
+ isClockwise
285
+ );
286
+ }
287
+ return {
288
+ nodes: layoutNodes,
289
+ edges: layoutEdges,
290
+ cx,
291
+ cy,
292
+ radius,
293
+ width,
294
+ height,
295
+ scale
296
+ };
297
+ }
298
+ function chooseDescribedRectDims(description, labelWidth) {
299
+ const minW = Math.min(
300
+ MAX_NODE_WIDTH,
301
+ Math.max(MIN_NODE_WIDTH, labelWidth, DESC_MIN_WIDTH)
302
+ );
303
+ let best = null;
304
+ let bestScore = Infinity;
305
+ for (let w = minW; w <= MAX_NODE_WIDTH; w += DESC_WIDTH_STEP) {
306
+ const wrapped2 = wrapDescForWidth(description, w);
307
+ const h = HEADER_HEIGHT + wrapped2.length * DESC_LINE_HEIGHT + DESC_PAD_Y;
308
+ const ratio = w / h;
309
+ const score = Math.abs(Math.log(ratio / DESC_TARGET_RATIO));
310
+ if (score < bestScore) {
311
+ bestScore = score;
312
+ best = { width: w, height: h, wrappedDesc: wrapped2 };
313
+ }
314
+ }
315
+ if (best) return best;
316
+ const wrapped = wrapDescForWidth(description, minW);
317
+ return {
318
+ width: minW,
319
+ height: HEADER_HEIGHT + wrapped.length * DESC_LINE_HEIGHT + DESC_PAD_Y,
320
+ wrappedDesc: wrapped
321
+ };
322
+ }
323
+ function wrapDescForWidth(description, nodeWidth) {
324
+ const textWidth = Math.max(40, nodeWidth - NODE_PAD_X * 2);
325
+ return wrapDescriptionLines(
326
+ [...description],
327
+ textWidth,
328
+ (s) => measureText(s, DESC_FONT_SIZE)
329
+ );
330
+ }
331
+ var RENDERER_DESC_FONT = 11;
332
+ var RENDERER_DESC_FONT_MIN = 8;
333
+ var RENDERER_DESC_LINE_H = 15;
334
+ var RENDERER_DESC_LINE_H_MIN = 11;
335
+ function renderedDescNodeHeight(numLines, scale) {
336
+ const headerH = HEADER_HEIGHT * scale;
337
+ const descFont = Math.max(
338
+ RENDERER_DESC_FONT_MIN,
339
+ Math.round(RENDERER_DESC_FONT * scale)
340
+ );
341
+ const descLineH = Math.max(
342
+ RENDERER_DESC_LINE_H_MIN,
343
+ Math.round(RENDERER_DESC_LINE_H * scale)
344
+ );
345
+ const textBlockH = 4 + descFont + (numLines - 1) * descLineH;
346
+ const bottomPad = 8;
347
+ return headerH + textBlockH + bottomPad;
348
+ }
349
+ var EDGE_LABEL_MAX_WIDTH = 197;
350
+ function wrapEdgeLabelText(label, description, maxWidth = EDGE_LABEL_MAX_WIDTH) {
351
+ const labelLines = label ? wrapTextToWidth(label, EDGE_LABEL_FONT_SIZE, maxWidth) : [];
352
+ const descLines = [];
353
+ for (const d of description) {
354
+ descLines.push(...wrapTextToWidth(d, EDGE_LABEL_FONT_SIZE, maxWidth));
355
+ }
356
+ return { labelLines, descLines };
357
+ }
358
+ function computeCircleNodeDims(node, hasDesc) {
359
+ if (!hasDesc) {
360
+ const textW = measureText(node.label, CIRCLE_LABEL_FONT_SIZE);
361
+ const r2 = Math.max(MIN_CIRCLE_RADIUS, textW / 2 + CIRCLE_PAD);
362
+ return { width: r2 * 2, height: r2 * 2, wrappedDesc: [] };
363
+ }
364
+ let r = MIN_CIRCLE_RADIUS;
365
+ for (let attempt = 0; attempt < 10; attempt++) {
366
+ const wrappedDesc2 = wrapLinesForCircle(node.description, r);
367
+ const totalLines = 1 + wrappedDesc2.length;
368
+ const textBlockH = totalLines * DESC_LINE_HEIGHT + CIRCLE_PAD;
369
+ if (textBlockH / 2 <= r * 0.85) {
370
+ const labelW = measureText(node.label, CIRCLE_LABEL_FONT_SIZE);
371
+ const labelY = -textBlockH / 2 + DESC_LINE_HEIGHT;
372
+ const availW = 2 * Math.sqrt(Math.max(0, r * r - labelY * labelY));
373
+ if (labelW <= availW - CIRCLE_PAD) {
374
+ return {
375
+ width: r * 2,
376
+ height: r * 2,
377
+ wrappedDesc: wrappedDesc2.map((text) => ({
378
+ text,
379
+ kind: "plain"
380
+ }))
381
+ };
382
+ }
383
+ }
384
+ r += 10;
385
+ }
386
+ const wrappedDesc = wrapLinesForCircle(node.description, r);
387
+ return {
388
+ width: r * 2,
389
+ height: r * 2,
390
+ wrappedDesc: wrappedDesc.map((text) => ({ text, kind: "plain" }))
391
+ };
392
+ }
393
+ function wrapLinesForCircle(descriptions, radius) {
394
+ const centerWidth = radius * 2 * 0.75;
395
+ const roughWrapped = descriptions.flatMap(
396
+ (d) => wrapTextToWidth(d, DESC_FONT_SIZE, centerWidth)
397
+ );
398
+ const totalLines = 1 + roughWrapped.length;
399
+ const blockH = totalLines * DESC_LINE_HEIGHT;
400
+ const result = [];
401
+ let lineIdx = 1;
402
+ for (const srcLine of descriptions) {
403
+ const words = srcLine.split(/\s+/).filter((w) => w.length > 0);
404
+ let current = "";
405
+ for (const word of words) {
406
+ const y = -blockH / 2 + (lineIdx + 0.5) * DESC_LINE_HEIGHT;
407
+ const rSq = radius * radius;
408
+ const availPx = Math.max(
409
+ 20,
410
+ y * y < rSq ? 2 * Math.sqrt(rSq - y * y) - CIRCLE_PAD * 2 : centerWidth
411
+ );
412
+ const test = current ? `${current} ${word}` : word;
413
+ if (measureText(test, DESC_FONT_SIZE) > availPx && current) {
414
+ result.push(current);
415
+ lineIdx++;
416
+ current = word;
417
+ } else {
418
+ current = test;
419
+ }
420
+ }
421
+ if (current) {
422
+ result.push(current);
423
+ lineIdx++;
424
+ }
425
+ }
426
+ return result;
427
+ }
428
+ function circleNodeExitAngle(nodeR, cycleR, nodeAngle, direction) {
429
+ const cosAlpha = Math.max(
430
+ -1,
431
+ Math.min(1, 1 - nodeR * nodeR / (2 * cycleR * cycleR))
432
+ );
433
+ const halfAngle = Math.acos(cosAlpha);
434
+ return nodeAngle + direction * halfAngle;
435
+ }
436
+ function insideRect(px, py, rx, ry, hw, hh) {
437
+ return Math.abs(px - rx) < hw && Math.abs(py - ry) < hh;
438
+ }
439
+ function circleRectExitAngle(nodeCx, nodeCy, halfW, halfH, circleCx, circleCy, radius, nodeAngle, direction) {
440
+ const steps = 90;
441
+ const maxSweep = Math.PI;
442
+ const step = maxSweep / steps;
443
+ let insideAngle = nodeAngle;
444
+ let outsideAngle = nodeAngle + direction * step;
445
+ for (let i = 1; i <= steps; i++) {
446
+ const angle = nodeAngle + direction * step * i;
447
+ const px = circleCx + radius * Math.cos(angle);
448
+ const py = circleCy + radius * Math.sin(angle);
449
+ if (!insideRect(px, py, nodeCx, nodeCy, halfW, halfH)) {
450
+ outsideAngle = angle;
451
+ insideAngle = nodeAngle + direction * step * (i - 1);
452
+ break;
453
+ }
454
+ }
455
+ for (let i = 0; i < 16; i++) {
456
+ const mid = (insideAngle + outsideAngle) / 2;
457
+ const px = circleCx + radius * Math.cos(mid);
458
+ const py = circleCy + radius * Math.sin(mid);
459
+ if (insideRect(px, py, nodeCx, nodeCy, halfW, halfH)) {
460
+ insideAngle = mid;
461
+ } else {
462
+ outsideAngle = mid;
463
+ }
464
+ }
465
+ return (insideAngle + outsideAngle) / 2;
466
+ }
467
+ function computeEdgePaths(layoutNodes, parsed, cx, cy, radius, isClockwise) {
468
+ return parsed.edges.map((edge) => {
469
+ const src = layoutNodes[edge.sourceIndex];
470
+ const tgt = layoutNodes[edge.targetIndex];
471
+ const strokeWidth = Math.max(
472
+ edge.width ?? DEFAULT_EDGE_WIDTH,
473
+ MIN_EDGE_WIDTH
474
+ );
475
+ const arrowLen = arrowHeadLength(strokeWidth) * 0.9;
476
+ const { path, midAngle } = buildEdgeArc(
477
+ src,
478
+ tgt,
479
+ cx,
480
+ cy,
481
+ radius,
482
+ isClockwise,
483
+ arrowLen
484
+ );
485
+ const { labelLines, descLines } = wrapEdgeLabelText(
486
+ edge.label,
487
+ edge.description
488
+ );
489
+ const lineCount = labelLines.length + descLines.length;
490
+ let labelPxW = 0;
491
+ for (const l of labelLines)
492
+ labelPxW = Math.max(labelPxW, measureText(l, EDGE_LABEL_FONT_SIZE));
493
+ for (const l of descLines)
494
+ labelPxW = Math.max(labelPxW, measureText(l, EDGE_LABEL_FONT_SIZE));
495
+ const { labelX, labelY, labelAngle } = computeEdgeLabelPosition(
496
+ midAngle,
497
+ radius,
498
+ cx,
499
+ cy,
500
+ lineCount,
501
+ labelPxW,
502
+ layoutNodes
503
+ );
504
+ const layoutEdge = {
505
+ sourceIndex: edge.sourceIndex,
506
+ targetIndex: edge.targetIndex,
507
+ path,
508
+ labelX,
509
+ labelY,
510
+ labelAngle,
511
+ ...edge.label !== void 0 && { label: edge.label }
512
+ };
513
+ return layoutEdge;
514
+ });
515
+ }
516
+ function computeEdgeLabelPosition(midAngle, radius, cx, cy, lineCount, labelPxW, layoutNodes) {
517
+ if (lineCount === 0 || labelPxW === 0) {
518
+ return {
519
+ labelX: cx + radius * Math.cos(midAngle),
520
+ labelY: cy + radius * Math.sin(midAngle),
521
+ labelAngle: midAngle
522
+ };
523
+ }
524
+ const EDGE_LABEL_CORNER_OFFSET = 10;
525
+ const labelW = labelPxW;
526
+ const labelH = lineCount * 15;
527
+ const cosT = Math.cos(midAngle);
528
+ const sinT = Math.sin(midAngle);
529
+ function place(sign) {
530
+ const cornerX = cx + (radius + sign * EDGE_LABEL_CORNER_OFFSET) * cosT;
531
+ const cornerY = cy + (radius + sign * EDGE_LABEL_CORNER_OFFSET) * sinT;
532
+ const ROUND_THRESH = 0.3;
533
+ const radialX = sign * cosT;
534
+ const radialY = sign * sinT;
535
+ const sx = Math.abs(radialX) < ROUND_THRESH ? 0 : Math.sign(radialX);
536
+ const sy = Math.abs(radialY) < ROUND_THRESH ? 0 : Math.sign(radialY);
537
+ const bboxCx = cornerX + sx * labelW / 2;
538
+ const bboxCy = cornerY + sy * labelH / 2;
539
+ let labelX;
540
+ if (sx > 0) labelX = bboxCx - labelW / 2;
541
+ else if (sx < 0) labelX = bboxCx + labelW / 2;
542
+ else labelX = bboxCx;
543
+ const labelY = bboxCy - labelH / 2 + 12;
544
+ const bbX1 = bboxCx - labelW / 2;
545
+ const bbX2 = bboxCx + labelW / 2;
546
+ const bbY1 = bboxCy - labelH / 2;
547
+ const bbY2 = bboxCy + labelH / 2;
548
+ let overlap = 0;
549
+ for (const n of layoutNodes) {
550
+ const nx1 = n.x - n.width / 2;
551
+ const nx2 = n.x + n.width / 2;
552
+ const ny1 = n.y - n.height / 2;
553
+ const ny2 = n.y + n.height / 2;
554
+ const ox = Math.max(0, Math.min(bbX2, nx2) - Math.max(bbX1, nx1));
555
+ const oy = Math.max(0, Math.min(bbY2, ny2) - Math.max(bbY1, ny1));
556
+ overlap += ox * oy;
557
+ }
558
+ const labelAngle = sign === 1 ? midAngle : midAngle + Math.PI;
559
+ return { labelX, labelY, labelAngle, bbX1, bbX2, bbY1, bbY2, overlap };
560
+ }
561
+ const outward = place(1);
562
+ if (outward.overlap === 0) {
563
+ return {
564
+ labelX: outward.labelX,
565
+ labelY: outward.labelY,
566
+ labelAngle: outward.labelAngle
567
+ };
568
+ }
569
+ const inward = place(-1);
570
+ const best = inward.overlap < outward.overlap ? inward : outward;
571
+ return {
572
+ labelX: best.labelX,
573
+ labelY: best.labelY,
574
+ labelAngle: best.labelAngle
575
+ };
576
+ }
577
+ function fitToCanvas(nodes, edges, parsed, _cx, _cy, radius, width, height, _isClockwise) {
578
+ const PADDING = 30;
579
+ let contentMinX = Infinity, contentMaxX = -Infinity;
580
+ let contentMinY = Infinity, contentMaxY = -Infinity;
581
+ for (const n of nodes) {
582
+ contentMinX = Math.min(contentMinX, n.x - n.width / 2);
583
+ contentMaxX = Math.max(contentMaxX, n.x + n.width / 2);
584
+ contentMinY = Math.min(contentMinY, n.y - n.height / 2);
585
+ contentMaxY = Math.max(contentMaxY, n.y + n.height / 2);
586
+ }
587
+ for (let i = 0; i < edges.length; i++) {
588
+ const le = edges[i];
589
+ const edge = parsed.edges[i];
590
+ const { labelLines, descLines } = wrapEdgeLabelText(
591
+ le.label,
592
+ edge.description
593
+ );
594
+ let textWidth = 0;
595
+ for (const l of labelLines)
596
+ textWidth = Math.max(textWidth, measureText(l, EDGE_LABEL_FONT_SIZE));
597
+ for (const l of descLines)
598
+ textWidth = Math.max(textWidth, measureText(l, EDGE_LABEL_FONT_SIZE));
599
+ if (textWidth === 0) continue;
600
+ const normAngle = (le.labelAngle % (2 * Math.PI) + 2 * Math.PI) % (2 * Math.PI);
601
+ const isRight = normAngle < Math.PI * 0.4 || normAngle > Math.PI * 1.6;
602
+ const isLeft = normAngle > Math.PI * 0.6 && normAngle < Math.PI * 1.4;
603
+ let labelLeft, labelRight;
604
+ if (isRight) {
605
+ labelLeft = le.labelX;
606
+ labelRight = le.labelX + textWidth;
607
+ } else if (isLeft) {
608
+ labelLeft = le.labelX - textWidth;
609
+ labelRight = le.labelX;
610
+ } else {
611
+ labelLeft = le.labelX - textWidth / 2;
612
+ labelRight = le.labelX + textWidth / 2;
613
+ }
614
+ contentMinX = Math.min(contentMinX, labelLeft);
615
+ contentMaxX = Math.max(contentMaxX, labelRight);
616
+ const lineCount = labelLines.length + descLines.length;
617
+ contentMinY = Math.min(contentMinY, le.labelY - 12);
618
+ contentMaxY = Math.max(contentMaxY, le.labelY + (lineCount - 1) * 15);
619
+ }
620
+ const overflowX = Math.max(0, PADDING - contentMinX) + Math.max(0, contentMaxX - (width - PADDING));
621
+ const overflowY = Math.max(0, PADDING - contentMinY) + Math.max(0, contentMaxY - (height - PADDING));
622
+ if (overflowX <= 0 && overflowY <= 0) return null;
623
+ const contentW = contentMaxX - contentMinX;
624
+ const contentH = contentMaxY - contentMinY;
625
+ const availW = width - 2 * PADDING;
626
+ const availH = height - 2 * PADDING;
627
+ const shrink = Math.min(availW / contentW, availH / contentH);
628
+ const newRadius = Math.max(80, radius * shrink);
629
+ return { radius: newRadius };
630
+ }
631
+ function buildEdgeArc(src, tgt, cx, cy, radius, isClockwise, arrowLength = 0) {
632
+ const dir = isClockwise ? 1 : -1;
633
+ const startAngle = src.angle;
634
+ const srcExitAngle = src.isCircle ? circleNodeExitAngle(src.width / 2, radius, src.angle, dir) : circleRectExitAngle(
635
+ src.x,
636
+ src.y,
637
+ src.width / 2,
638
+ src.height / 2,
639
+ cx,
640
+ cy,
641
+ radius,
642
+ src.angle,
643
+ dir
644
+ );
645
+ const nodeEndAngle = tgt.isCircle ? circleNodeExitAngle(tgt.width / 2, radius, tgt.angle, -dir) : circleRectExitAngle(
646
+ tgt.x,
647
+ tgt.y,
648
+ tgt.width / 2,
649
+ tgt.height / 2,
650
+ cx,
651
+ cy,
652
+ radius,
653
+ tgt.angle,
654
+ -dir
655
+ );
656
+ const arrowPullback = arrowLength > 0 ? arrowLength / radius : 0;
657
+ const endAngle = nodeEndAngle - dir * arrowPullback;
658
+ const startX = cx + radius * Math.cos(startAngle);
659
+ const startY = cy + radius * Math.sin(startAngle);
660
+ const endX = cx + radius * Math.cos(endAngle);
661
+ const endY = cy + radius * Math.sin(endAngle);
662
+ let effectiveSweep = (endAngle - startAngle) * dir;
663
+ if (effectiveSweep <= 0) effectiveSweep += 2 * Math.PI;
664
+ const largeArc = effectiveSweep > Math.PI ? 1 : 0;
665
+ const sweepFlag = isClockwise ? 1 : 0;
666
+ const path = `M ${startX} ${startY} A ${radius} ${radius} 0 ${largeArc} ${sweepFlag} ${endX} ${endY}`;
667
+ let visibleSweep = (nodeEndAngle - srcExitAngle) * dir;
668
+ if (visibleSweep <= 0) visibleSweep += 2 * Math.PI;
669
+ const midAngle = srcExitAngle + dir * visibleSweep / 2;
670
+ return { path, midAngle };
671
+ }
672
+
673
+ // src/cycle/renderer.ts
674
+ var NODE_FONT_SIZE = 13;
675
+ var DESC_FONT_SIZE2 = 11;
676
+ var EDGE_LABEL_FONT_SIZE2 = 11;
677
+ var DESC_LINE_HEIGHT2 = 15;
678
+ var TITLE_AREA_HEIGHT = 50;
679
+ function renderCycle(container, parsed, palette, isDark, onClickItem, exportDims, viewState, renderOptions) {
680
+ if (parsed.nodes.length === 0) return;
681
+ const solid = parsed.options?.["solid-fill"] === "on";
682
+ d3Selection.select(container).selectAll(":not([data-d3-tooltip])").remove();
683
+ const width = exportDims?.width ?? container.clientWidth;
684
+ const height = exportDims?.height ?? container.clientHeight;
685
+ if (width <= 0 || height <= 0) return;
686
+ const idealWidth = width;
687
+ const sctx = exportDims ? ScaleContext.identity() : ScaleContext.from(width, idealWidth);
688
+ const sTitleFontSize = sctx.text(TITLE_FONT_SIZE);
689
+ const sTitleY = sctx.structural(TITLE_Y);
690
+ const sTitleAreaHeight = sctx.structural(TITLE_AREA_HEIGHT);
691
+ const sLegendHeight = sctx.structural(LEGEND_HEIGHT);
692
+ const hideDescriptions = (renderOptions?.hideDescriptions ?? false) || parsed.options["no-descriptions"] === "true" || viewState?.hd === true;
693
+ const showDescriptions = !hideDescriptions;
694
+ const hasDescriptions = parsed.nodes.some((n) => n.description.length > 0) || parsed.edges.some((e) => e.description.length > 0);
695
+ const appHostedControls = renderOptions?.controlsHost === "app";
696
+ const hasLegend = !appHostedControls && hasDescriptions && !!renderOptions?.onToggleDescriptions;
697
+ const showTitle = !!parsed.title && parsed.options["no-title"] !== "on";
698
+ const legendOffset = hasLegend ? sLegendHeight : 0;
699
+ const layoutHeight = height - (showTitle ? sTitleAreaHeight : 0) - legendOffset;
700
+ const layout = computeCycleLayout(parsed, {
701
+ width,
702
+ height: layoutHeight,
703
+ hideDescriptions
704
+ });
705
+ const svg = d3Selection.select(container).append("svg").attr("width", width).attr("height", height).attr("viewBox", `0 0 ${width} ${height}`).attr("preserveAspectRatio", "xMidYMid meet").attr("xmlns", "http://www.w3.org/2000/svg").style("font-family", FONT_FAMILY);
706
+ if (sctx.isBelowFloor) {
707
+ svg.attr("width", "100%");
708
+ }
709
+ svg.append("rect").attr("width", width).attr("height", height).attr("fill", palette.bg);
710
+ if (showTitle) {
711
+ const titleText = svg.append("text").attr("x", width / 2).attr("y", sTitleY).attr("text-anchor", "middle").attr("fill", palette.text).attr("font-family", FONT_FAMILY).attr("font-size", sTitleFontSize).attr("font-weight", TITLE_FONT_WEIGHT).attr("data-line-number", parsed.titleLineNumber).text(parsed.title).style("cursor", onClickItem ? "pointer" : "default");
712
+ if (onClickItem) {
713
+ titleText.on("click", () => onClickItem(parsed.titleLineNumber));
714
+ }
715
+ }
716
+ if (hasLegend) {
717
+ const controlsGroup = {
718
+ toggles: [
719
+ {
720
+ id: "descriptions",
721
+ type: "toggle",
722
+ label: "Descriptions",
723
+ active: !hideDescriptions,
724
+ onToggle: () => {
725
+ }
726
+ }
727
+ ]
728
+ };
729
+ const legendCallbacks = {
730
+ ...renderOptions?.onToggleControlsExpand !== void 0 && {
731
+ onControlsExpand: renderOptions.onToggleControlsExpand
732
+ },
733
+ onControlsToggle: (toggleId, active) => {
734
+ if (toggleId === "descriptions" && renderOptions?.onToggleDescriptions) {
735
+ renderOptions.onToggleDescriptions(active);
736
+ }
737
+ }
738
+ };
739
+ const titleOffsetForLegend = showTitle ? sTitleAreaHeight : 0;
740
+ const legendG = svg.append("g").attr("transform", `translate(0, ${titleOffsetForLegend + 4})`);
741
+ renderIntegratedLegend(legendG, {
742
+ groups: [],
743
+ activeGroup: null,
744
+ mode: renderOptions?.exportMode ? "export" : "preview",
745
+ controlsGroup,
746
+ ...renderOptions?.controlsHost !== void 0 && {
747
+ controlsHost: renderOptions.controlsHost
748
+ },
749
+ ...renderOptions?.controlsExpanded !== void 0 && {
750
+ controlsExpanded: renderOptions.controlsExpanded
751
+ },
752
+ callbacks: legendCallbacks,
753
+ palette,
754
+ isDark,
755
+ width
756
+ });
757
+ }
758
+ const diagramTop = (showTitle ? sTitleAreaHeight : 0) + legendOffset;
759
+ const g = svg.append("g").attr("transform", `translate(0, ${diagramTop})`);
760
+ const defs = svg.append("defs");
761
+ const defaultNodeColor = palette.primary;
762
+ const markerKeys = /* @__PURE__ */ new Set();
763
+ for (const edge of parsed.edges) {
764
+ const color = resolveEdgeColor(edge, parsed, palette, defaultNodeColor);
765
+ const sw = Math.max(edge.width ?? DEFAULT_EDGE_WIDTH, MIN_EDGE_WIDTH);
766
+ const key = `${color}|${sw}`;
767
+ if (!markerKeys.has(key)) {
768
+ markerKeys.add(key);
769
+ ensureArrowMarker(defs, color, sw);
770
+ }
771
+ }
772
+ const edgeLabelInfo = [];
773
+ for (let i = 0; i < layout.edges.length; i++) {
774
+ const le = layout.edges[i];
775
+ const edge = parsed.edges[i];
776
+ const color = resolveEdgeColor(edge, parsed, palette, defaultNodeColor);
777
+ const strokeWidth = Math.max(
778
+ edge.width ?? DEFAULT_EDGE_WIDTH,
779
+ MIN_EDGE_WIDTH
780
+ );
781
+ const markerId = arrowMarkerId(color, strokeWidth);
782
+ const edgeG = g.append("g").attr("class", "cycle-edge");
783
+ if (edge.lineNumber) {
784
+ edgeG.attr("data-line-number", edge.lineNumber);
785
+ }
786
+ edgeG.attr("data-from", String(edge.sourceIndex)).attr("data-to", String(edge.targetIndex));
787
+ const pathEl = edgeG.append("path").attr("d", le.path).attr("fill", "none").attr("stroke", color).attr("stroke-width", strokeWidth).attr("marker-end", `url(#${markerId})`);
788
+ if (onClickItem && edge.lineNumber) {
789
+ const ln = edge.lineNumber;
790
+ pathEl.style("cursor", "pointer").on("click", () => onClickItem(ln));
791
+ }
792
+ edgeLabelInfo.push({ le, edge });
793
+ }
794
+ const HEADER_H = 36 * layout.scale;
795
+ const scaledNodeFont = Math.max(6, Math.round(NODE_FONT_SIZE * layout.scale));
796
+ const scaledEdgeLabelFont = Math.max(
797
+ 6,
798
+ Math.round(EDGE_LABEL_FONT_SIZE2 * layout.scale)
799
+ );
800
+ const CIRCLE_LABEL_FONT_SIZE2 = 16;
801
+ const scaledCircleLabelFont = Math.max(
802
+ 8,
803
+ Math.round(CIRCLE_LABEL_FONT_SIZE2 * layout.scale)
804
+ );
805
+ const scaledDescFont = Math.max(5, Math.round(DESC_FONT_SIZE2 * layout.scale));
806
+ const scaledDescLineH = Math.max(
807
+ 7,
808
+ Math.round(DESC_LINE_HEIGHT2 * layout.scale)
809
+ );
810
+ const scaledEdgeLineH = Math.max(
811
+ 8,
812
+ Math.round(DESC_LINE_HEIGHT2 * layout.scale)
813
+ );
814
+ for (let i = 0; i < layout.nodes.length; i++) {
815
+ const ln = layout.nodes[i];
816
+ const node = parsed.nodes[i];
817
+ const solidColor = resolveNodeColor(node.color, palette, defaultNodeColor);
818
+ const fillColor = shapeFill(palette, solidColor, isDark, { solid });
819
+ const textColor = contrastText(
820
+ fillColor,
821
+ palette.textOnFillLight,
822
+ palette.textOnFillDark
823
+ );
824
+ const descColor = textColor;
825
+ const nodeW = ln.width;
826
+ const nodeH = ln.height;
827
+ const wrappedDesc = ln.wrappedDesc;
828
+ const hasDesc = showDescriptions && wrappedDesc.length > 0;
829
+ const nodeG = g.append("g").attr("class", "cycle-node").attr("data-line-number", node.lineNumber).attr("data-node-index", String(i)).style("cursor", onClickItem ? "pointer" : "default");
830
+ if (onClickItem) {
831
+ const lineNum = node.lineNumber;
832
+ nodeG.on("click", () => onClickItem(lineNum));
833
+ }
834
+ if (ln.isCircle) {
835
+ const r = nodeW / 2;
836
+ nodeG.append("circle").attr("cx", ln.x).attr("cy", ln.y).attr("r", r).attr("fill", fillColor).attr("stroke", solidColor).attr("stroke-width", 2);
837
+ if (hasDesc) {
838
+ const labelFont = scaledCircleLabelFont;
839
+ const blockH = labelFont + 4 + wrappedDesc.length * scaledDescLineH;
840
+ const startY = ln.y - blockH / 2 + labelFont;
841
+ const labelText = nodeG.append("text").attr("x", ln.x).attr("y", startY).attr("text-anchor", "middle").attr("fill", textColor).attr("font-family", FONT_FAMILY).attr("font-size", labelFont).attr("font-weight", "600");
842
+ renderInlineText(labelText, node.label, palette, labelFont);
843
+ let descY = startY + scaledDescLineH + 4;
844
+ wrappedDesc.forEach((line) => {
845
+ const descText = nodeG.append("text").attr("x", ln.x).attr("y", descY).attr("text-anchor", "middle").attr("fill", descColor).attr("font-family", FONT_FAMILY).attr("font-size", scaledDescFont);
846
+ renderInlineText(descText, line.text, palette, DESC_FONT_SIZE2);
847
+ descY += scaledDescLineH;
848
+ });
849
+ } else {
850
+ const labelFont = scaledCircleLabelFont;
851
+ const labelText = nodeG.append("text").attr("x", ln.x).attr("y", ln.y + labelFont / 3).attr("text-anchor", "middle").attr("fill", textColor).attr("font-family", FONT_FAMILY).attr("font-size", labelFont).attr("font-weight", "600");
852
+ renderInlineText(labelText, node.label, palette, labelFont);
853
+ }
854
+ } else {
855
+ const rx = 6;
856
+ nodeG.append("rect").attr("x", ln.x - nodeW / 2).attr("y", ln.y - nodeH / 2).attr("width", nodeW).attr("height", nodeH).attr("rx", rx).attr("ry", rx).attr("fill", fillColor).attr("stroke", solidColor).attr("stroke-width", 2);
857
+ if (hasDesc) {
858
+ const headerCenterY = ln.y - nodeH / 2 + HEADER_H / 2;
859
+ const labelText = nodeG.append("text").attr("x", ln.x).attr("y", headerCenterY + scaledNodeFont / 3).attr("text-anchor", "middle").attr("fill", textColor).attr("font-family", FONT_FAMILY).attr("font-size", scaledNodeFont).attr("font-weight", "600");
860
+ renderInlineText(labelText, node.label, palette, scaledNodeFont);
861
+ const sepY = ln.y - nodeH / 2 + HEADER_H;
862
+ nodeG.append("line").attr("x1", ln.x - nodeW / 2).attr("y1", sepY).attr("x2", ln.x + nodeW / 2).attr("y2", sepY).attr("stroke", solid ? descColor : solidColor).attr("stroke-opacity", 0.3).attr("stroke-width", 1);
863
+ const descStartY = sepY + 4 + scaledDescFont;
864
+ const descPadX = Math.max(8, 12 * layout.scale);
865
+ const descX = ln.x - nodeW / 2 + descPadX;
866
+ const bulletBodyX = descX + Math.max(8, 12 * layout.scale);
867
+ wrappedDesc.forEach((line, li) => {
868
+ const lineY = descStartY + li * scaledDescLineH;
869
+ if (line.kind === "bullet-first") {
870
+ nodeG.append("text").attr("x", descX).attr("y", lineY).attr("text-anchor", "start").attr("fill", descColor).attr("font-family", FONT_FAMILY).attr("font-size", scaledDescFont).text("\u2022");
871
+ const bodyText = nodeG.append("text").attr("x", bulletBodyX).attr("y", lineY).attr("text-anchor", "start").attr("fill", descColor).attr("font-family", FONT_FAMILY).attr("font-size", scaledDescFont);
872
+ renderInlineText(bodyText, line.text, palette, DESC_FONT_SIZE2);
873
+ } else {
874
+ const x = line.kind === "bullet-cont" ? bulletBodyX : descX;
875
+ const descText = nodeG.append("text").attr("x", x).attr("y", lineY).attr("text-anchor", "start").attr("fill", descColor).attr("font-family", FONT_FAMILY).attr("font-size", scaledDescFont);
876
+ renderInlineText(descText, line.text, palette, DESC_FONT_SIZE2);
877
+ }
878
+ });
879
+ } else {
880
+ const labelText = nodeG.append("text").attr("x", ln.x).attr("y", ln.y + scaledNodeFont / 3).attr("text-anchor", "middle").attr("fill", textColor).attr("font-family", FONT_FAMILY).attr("font-size", scaledNodeFont).attr("font-weight", "600");
881
+ renderInlineText(labelText, node.label, palette, scaledNodeFont);
882
+ }
883
+ }
884
+ }
885
+ const labelLayer = g.append("g").attr("class", "cycle-edge-labels");
886
+ for (const { le, edge } of edgeLabelInfo) {
887
+ const hasEdgeLabel = !!le.label;
888
+ const hasEdgeDesc = showDescriptions && edge.description.length > 0;
889
+ const { labelLines, descLines } = wrapEdgeLabelText(
890
+ hasEdgeLabel ? le.label : void 0,
891
+ hasEdgeDesc ? edge.description : []
892
+ );
893
+ if (labelLines.length === 0 && descLines.length === 0) continue;
894
+ const edgeG = labelLayer.append("g").attr("class", "cycle-edge");
895
+ if (edge.lineNumber) {
896
+ edgeG.attr("data-line-number", edge.lineNumber);
897
+ }
898
+ const normAngle = (le.labelAngle % (2 * Math.PI) + 2 * Math.PI) % (2 * Math.PI);
899
+ const isRight = normAngle < Math.PI * 0.4 || normAngle > Math.PI * 1.6;
900
+ const isLeft = normAngle > Math.PI * 0.6 && normAngle < Math.PI * 1.4;
901
+ const anchor = isRight ? "start" : isLeft ? "end" : "middle";
902
+ const lineCount = labelLines.length + descLines.length;
903
+ let maxLineW = 0;
904
+ for (const l of labelLines)
905
+ maxLineW = Math.max(maxLineW, measureText(l, scaledEdgeLabelFont));
906
+ for (const l of descLines)
907
+ maxLineW = Math.max(maxLineW, measureText(l, scaledDescFont));
908
+ const bgW = maxLineW + 12;
909
+ const bgH = lineCount * scaledEdgeLineH + 6;
910
+ const bgX = isRight ? le.labelX - 4 : isLeft ? le.labelX - bgW + 4 : le.labelX - bgW / 2;
911
+ const bgY = le.labelY - scaledEdgeLabelFont - 2;
912
+ edgeG.append("rect").attr("x", bgX).attr("y", bgY).attr("width", bgW).attr("height", bgH).attr("rx", 3).attr("fill", palette.bg).attr("fill-opacity", 0.85);
913
+ let textY = le.labelY;
914
+ for (const line of labelLines) {
915
+ const labelText = edgeG.append("text").attr("x", le.labelX).attr("y", textY).attr("text-anchor", anchor).attr("fill", palette.text).attr("font-family", FONT_FAMILY).attr("font-size", scaledEdgeLabelFont).attr("font-weight", "600");
916
+ renderInlineText(labelText, line, palette, scaledEdgeLabelFont);
917
+ textY += scaledEdgeLineH;
918
+ }
919
+ for (const line of descLines) {
920
+ const descText = edgeG.append("text").attr("x", le.labelX).attr("y", textY).attr("text-anchor", anchor).attr("fill", palette.textMuted).attr("font-family", FONT_FAMILY).attr("font-size", scaledDescFont);
921
+ renderInlineText(descText, line, palette, scaledDescFont);
922
+ textY += scaledEdgeLineH;
923
+ }
924
+ }
925
+ }
926
+ function renderCycleForExport(container, parsed, palette, isDark, exportDims, viewState, exportMode) {
927
+ renderCycle(
928
+ container,
929
+ parsed,
930
+ palette,
931
+ isDark,
932
+ void 0,
933
+ exportDims,
934
+ viewState,
935
+ { ...exportMode !== void 0 && { exportMode } }
936
+ );
937
+ }
938
+ function resolveNodeColor(color, palette, defaultColor) {
939
+ if (!color) return defaultColor;
940
+ return resolveColor(color, palette) ?? defaultColor;
941
+ }
942
+ function resolveEdgeColor(edge, parsed, palette, defaultNodeColor) {
943
+ if (edge.color) {
944
+ return resolveColor(edge.color, palette) ?? defaultNodeColor;
945
+ }
946
+ const sourceNode = parsed.nodes[edge.sourceIndex];
947
+ if (sourceNode?.color) {
948
+ return resolveColor(sourceNode.color, palette) ?? defaultNodeColor;
949
+ }
950
+ return defaultNodeColor;
951
+ }
952
+ function arrowMarkerId(color, strokeWidth) {
953
+ return `cycle-arrow-${color.replace("#", "")}-w${strokeWidth}`;
954
+ }
955
+ function ensureArrowMarker(defs, color, strokeWidth) {
956
+ const id = arrowMarkerId(color, strokeWidth);
957
+ const mw = arrowHeadLength(strokeWidth) / strokeWidth;
958
+ const mh = Math.max(1.5, mw * 0.5);
959
+ defs.append("marker").attr("id", id).attr("viewBox", `0 0 ${mw} ${mh}`).attr("refX", mw * 0.1).attr("refY", mh / 2).attr("markerWidth", mw).attr("markerHeight", mh).attr("orient", "auto").append("polygon").attr("points", `0,0 ${mw},${mh / 2} 0,${mh}`).attr("fill", color);
960
+ }
961
+
962
+ export {
963
+ computeCycleLayout,
964
+ renderCycle,
965
+ renderCycleForExport
966
+ };
967
+ //# sourceMappingURL=chunk-3R5POCTZ.js.map