chunk-5CZSE4TR.mjs 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284
  1. import {
  2. getLineFunctionsWithOffset,
  3. getSubGraphTitleMargins
  4. } from "./chunk-TINLTEC2.mjs";
  5. import {
  6. createText
  7. } from "./chunk-OERGPBFJ.mjs";
  8. import {
  9. decodeEntities,
  10. utils_default
  11. } from "./chunk-VKXSJROQ.mjs";
  12. import {
  13. __name,
  14. common_default,
  15. evaluate,
  16. getConfig2 as getConfig,
  17. hasKatex,
  18. log,
  19. renderKatex,
  20. sanitizeText
  21. } from "./chunk-O2AGWWWV.mjs";
  22. // src/rendering-util/rendering-elements/clusters.js
  23. import { select as select2 } from "d3";
  24. import rough from "roughjs";
  25. // src/rendering-util/rendering-elements/intersect/intersect-rect.js
  26. var intersectRect = /* @__PURE__ */ __name((node, point2) => {
  27. var x = node.x;
  28. var y = node.y;
  29. var dx = point2.x - x;
  30. var dy = point2.y - y;
  31. var w = node.width / 2;
  32. var h = node.height / 2;
  33. var sx, sy;
  34. if (Math.abs(dy) * w > Math.abs(dx) * h) {
  35. if (dy < 0) {
  36. h = -h;
  37. }
  38. sx = dy === 0 ? 0 : h * dx / dy;
  39. sy = h;
  40. } else {
  41. if (dx < 0) {
  42. w = -w;
  43. }
  44. sx = w;
  45. sy = dx === 0 ? 0 : w * dy / dx;
  46. }
  47. return { x: x + sx, y: y + sy };
  48. }, "intersectRect");
  49. var intersect_rect_default = intersectRect;
  50. // src/rendering-util/rendering-elements/createLabel.js
  51. import { select } from "d3";
  52. function applyStyle(dom, styleFn) {
  53. if (styleFn) {
  54. dom.attr("style", styleFn);
  55. }
  56. }
  57. __name(applyStyle, "applyStyle");
  58. async function addHtmlLabel(node) {
  59. const fo = select(document.createElementNS("http://www.w3.org/2000/svg", "foreignObject"));
  60. const div = fo.append("xhtml:div");
  61. let label = node.label;
  62. if (node.label && hasKatex(node.label)) {
  63. label = await renderKatex(node.label.replace(common_default.lineBreakRegex, "\n"), getConfig());
  64. }
  65. const labelClass = node.isNode ? "nodeLabel" : "edgeLabel";
  66. div.html(
  67. '<span class="' + labelClass + '" ' + (node.labelStyle ? 'style="' + node.labelStyle + '"' : "") + // codeql [js/html-constructed-from-input] : false positive
  68. ">" + label + "</span>"
  69. );
  70. applyStyle(div, node.labelStyle);
  71. div.style("display", "inline-block");
  72. div.style("padding-right", "1px");
  73. div.style("white-space", "nowrap");
  74. div.attr("xmlns", "http://www.w3.org/1999/xhtml");
  75. return fo.node();
  76. }
  77. __name(addHtmlLabel, "addHtmlLabel");
  78. var createLabel = /* @__PURE__ */ __name(async (_vertexText, style, isTitle, isNode) => {
  79. let vertexText = _vertexText || "";
  80. if (typeof vertexText === "object") {
  81. vertexText = vertexText[0];
  82. }
  83. if (evaluate(getConfig().flowchart.htmlLabels)) {
  84. vertexText = vertexText.replace(/\\n|\n/g, "<br />");
  85. log.info("vertexText" + vertexText);
  86. const node = {
  87. isNode,
  88. label: decodeEntities(vertexText).replace(
  89. /fa[blrs]?:fa-[\w-]+/g,
  90. (s) => `<i class='${s.replace(":", " ")}'></i>`
  91. ),
  92. labelStyle: style ? style.replace("fill:", "color:") : style
  93. };
  94. let vertexNode = await addHtmlLabel(node);
  95. return vertexNode;
  96. } else {
  97. const svgLabel = document.createElementNS("http://www.w3.org/2000/svg", "text");
  98. svgLabel.setAttribute("style", style.replace("color:", "fill:"));
  99. let rows = [];
  100. if (typeof vertexText === "string") {
  101. rows = vertexText.split(/\\n|\n|<br\s*\/?>/gi);
  102. } else if (Array.isArray(vertexText)) {
  103. rows = vertexText;
  104. } else {
  105. rows = [];
  106. }
  107. for (const row of rows) {
  108. const tspan = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
  109. tspan.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:space", "preserve");
  110. tspan.setAttribute("dy", "1em");
  111. tspan.setAttribute("x", "0");
  112. if (isTitle) {
  113. tspan.setAttribute("class", "title-row");
  114. } else {
  115. tspan.setAttribute("class", "row");
  116. }
  117. tspan.textContent = row.trim();
  118. svgLabel.appendChild(tspan);
  119. }
  120. return svgLabel;
  121. }
  122. }, "createLabel");
  123. var createLabel_default = createLabel;
  124. // src/rendering-util/rendering-elements/shapes/roundedRectPath.ts
  125. var createRoundedRectPathD = /* @__PURE__ */ __name((x, y, totalWidth, totalHeight, radius) => [
  126. "M",
  127. x + radius,
  128. y,
  129. // Move to the first point
  130. "H",
  131. x + totalWidth - radius,
  132. // Draw horizontal line to the beginning of the right corner
  133. "A",
  134. radius,
  135. radius,
  136. 0,
  137. 0,
  138. 1,
  139. x + totalWidth,
  140. y + radius,
  141. // Draw arc to the right top corner
  142. "V",
  143. y + totalHeight - radius,
  144. // Draw vertical line down to the beginning of the right bottom corner
  145. "A",
  146. radius,
  147. radius,
  148. 0,
  149. 0,
  150. 1,
  151. x + totalWidth - radius,
  152. y + totalHeight,
  153. // Draw arc to the right bottom corner
  154. "H",
  155. x + radius,
  156. // Draw horizontal line to the beginning of the left bottom corner
  157. "A",
  158. radius,
  159. radius,
  160. 0,
  161. 0,
  162. 1,
  163. x,
  164. y + totalHeight - radius,
  165. // Draw arc to the left bottom corner
  166. "V",
  167. y + radius,
  168. // Draw vertical line up to the beginning of the left top corner
  169. "A",
  170. radius,
  171. radius,
  172. 0,
  173. 0,
  174. 1,
  175. x + radius,
  176. y,
  177. // Draw arc to the left top corner
  178. "Z"
  179. // Close the path
  180. ].join(" "), "createRoundedRectPathD");
  181. // src/rendering-util/rendering-elements/shapes/handDrawnShapeStyles.ts
  182. var solidStateFill = /* @__PURE__ */ __name((color) => {
  183. const { handDrawnSeed } = getConfig();
  184. return {
  185. fill: color,
  186. hachureAngle: 120,
  187. // angle of hachure,
  188. hachureGap: 4,
  189. fillWeight: 2,
  190. roughness: 0.7,
  191. stroke: color,
  192. seed: handDrawnSeed
  193. };
  194. }, "solidStateFill");
  195. var compileStyles = /* @__PURE__ */ __name((node) => {
  196. const stylesMap = styles2Map([...node.cssCompiledStyles || [], ...node.cssStyles || []]);
  197. return { stylesMap, stylesArray: [...stylesMap] };
  198. }, "compileStyles");
  199. var styles2Map = /* @__PURE__ */ __name((styles) => {
  200. const styleMap = /* @__PURE__ */ new Map();
  201. styles.forEach((style) => {
  202. const [key, value] = style.split(":");
  203. styleMap.set(key.trim(), value?.trim());
  204. });
  205. return styleMap;
  206. }, "styles2Map");
  207. var styles2String = /* @__PURE__ */ __name((node) => {
  208. const { stylesArray } = compileStyles(node);
  209. const labelStyles = [];
  210. const nodeStyles = [];
  211. const borderStyles = [];
  212. const backgroundStyles = [];
  213. stylesArray.forEach((style) => {
  214. const key = style[0];
  215. if (key === "color" || key === "font-size" || key === "font-family" || key === "font-weight" || key === "font-style" || key === "text-decoration" || key === "text-align" || key === "text-transform" || key === "line-height" || key === "letter-spacing" || key === "word-spacing" || key === "text-shadow" || key === "text-overflow" || key === "white-space" || key === "word-wrap" || key === "word-break" || key === "overflow-wrap" || key === "hyphens") {
  216. labelStyles.push(style.join(":") + " !important");
  217. } else {
  218. nodeStyles.push(style.join(":") + " !important");
  219. if (key.includes("stroke")) {
  220. borderStyles.push(style.join(":") + " !important");
  221. }
  222. if (key === "fill") {
  223. backgroundStyles.push(style.join(":") + " !important");
  224. }
  225. }
  226. });
  227. return {
  228. labelStyles: labelStyles.join(";"),
  229. nodeStyles: nodeStyles.join(";"),
  230. stylesArray,
  231. borderStyles,
  232. backgroundStyles
  233. };
  234. }, "styles2String");
  235. var userNodeOverrides = /* @__PURE__ */ __name((node, options) => {
  236. const { themeVariables, handDrawnSeed } = getConfig();
  237. const { nodeBorder, mainBkg } = themeVariables;
  238. const { stylesMap } = compileStyles(node);
  239. const result = Object.assign(
  240. {
  241. roughness: 0.7,
  242. fill: stylesMap.get("fill") || mainBkg,
  243. fillStyle: "hachure",
  244. // solid fill
  245. fillWeight: 4,
  246. stroke: stylesMap.get("stroke") || nodeBorder,
  247. seed: handDrawnSeed,
  248. strokeWidth: 1.3
  249. },
  250. options
  251. );
  252. return result;
  253. }, "userNodeOverrides");
  254. // src/rendering-util/rendering-elements/clusters.js
  255. var rect = /* @__PURE__ */ __name(async (parent, node) => {
  256. log.info("Creating subgraph rect for ", node.id, node);
  257. const siteConfig = getConfig();
  258. const { themeVariables, handDrawnSeed } = siteConfig;
  259. const { clusterBkg, clusterBorder } = themeVariables;
  260. const { labelStyles, nodeStyles, borderStyles, backgroundStyles } = styles2String(node);
  261. const shapeSvg = parent.insert("g").attr("class", "cluster " + node.cssClasses).attr("id", node.id).attr("data-look", node.look);
  262. const useHtmlLabels = evaluate(siteConfig.flowchart.htmlLabels);
  263. const labelEl = shapeSvg.insert("g").attr("class", "cluster-label ");
  264. const text = await createText(labelEl, node.label, {
  265. style: node.labelStyle,
  266. useHtmlLabels,
  267. isNode: true
  268. });
  269. let bbox = text.getBBox();
  270. if (evaluate(siteConfig.flowchart.htmlLabels)) {
  271. const div = text.children[0];
  272. const dv = select2(text);
  273. bbox = div.getBoundingClientRect();
  274. dv.attr("width", bbox.width);
  275. dv.attr("height", bbox.height);
  276. }
  277. const width = node.width <= bbox.width + node.padding ? bbox.width + node.padding : node.width;
  278. if (node.width <= bbox.width + node.padding) {
  279. node.diff = (width - node.width) / 2 - node.padding;
  280. } else {
  281. node.diff = -node.padding;
  282. }
  283. const height = node.height;
  284. const x = node.x - width / 2;
  285. const y = node.y - height / 2;
  286. log.trace("Data ", node, JSON.stringify(node));
  287. let rect2;
  288. if (node.look === "handDrawn") {
  289. const rc = rough.svg(shapeSvg);
  290. const options = userNodeOverrides(node, {
  291. roughness: 0.7,
  292. fill: clusterBkg,
  293. // fill: 'red',
  294. stroke: clusterBorder,
  295. fillWeight: 3,
  296. seed: handDrawnSeed
  297. });
  298. const roughNode = rc.path(createRoundedRectPathD(x, y, width, height, 0), options);
  299. rect2 = shapeSvg.insert(() => {
  300. log.debug("Rough node insert CXC", roughNode);
  301. return roughNode;
  302. }, ":first-child");
  303. rect2.select("path:nth-child(2)").attr("style", borderStyles.join(";"));
  304. rect2.select("path").attr("style", backgroundStyles.join(";").replace("fill", "stroke"));
  305. } else {
  306. rect2 = shapeSvg.insert("rect", ":first-child");
  307. rect2.attr("style", nodeStyles).attr("rx", node.rx).attr("ry", node.ry).attr("x", x).attr("y", y).attr("width", width).attr("height", height);
  308. }
  309. const { subGraphTitleTopMargin } = getSubGraphTitleMargins(siteConfig);
  310. labelEl.attr(
  311. "transform",
  312. // This puts the label on top of the box instead of inside it
  313. `translate(${node.x - bbox.width / 2}, ${node.y - node.height / 2 + subGraphTitleTopMargin})`
  314. );
  315. if (labelStyles) {
  316. const span = labelEl.select("span");
  317. if (span) {
  318. span.attr("style", labelStyles);
  319. }
  320. }
  321. const rectBox = rect2.node().getBBox();
  322. node.offsetX = 0;
  323. node.width = rectBox.width;
  324. node.height = rectBox.height;
  325. node.offsetY = bbox.height - node.padding / 2;
  326. node.intersect = function(point2) {
  327. return intersect_rect_default(node, point2);
  328. };
  329. return { cluster: shapeSvg, labelBBox: bbox };
  330. }, "rect");
  331. var noteGroup = /* @__PURE__ */ __name((parent, node) => {
  332. const shapeSvg = parent.insert("g").attr("class", "note-cluster").attr("id", node.id);
  333. const rect2 = shapeSvg.insert("rect", ":first-child");
  334. const padding = 0 * node.padding;
  335. const halfPadding = padding / 2;
  336. rect2.attr("rx", node.rx).attr("ry", node.ry).attr("x", node.x - node.width / 2 - halfPadding).attr("y", node.y - node.height / 2 - halfPadding).attr("width", node.width + padding).attr("height", node.height + padding).attr("fill", "none");
  337. const rectBox = rect2.node().getBBox();
  338. node.width = rectBox.width;
  339. node.height = rectBox.height;
  340. node.intersect = function(point2) {
  341. return intersect_rect_default(node, point2);
  342. };
  343. return { cluster: shapeSvg, labelBBox: { width: 0, height: 0 } };
  344. }, "noteGroup");
  345. var roundedWithTitle = /* @__PURE__ */ __name(async (parent, node) => {
  346. const siteConfig = getConfig();
  347. const { themeVariables, handDrawnSeed } = siteConfig;
  348. const { altBackground, compositeBackground, compositeTitleBackground, nodeBorder } = themeVariables;
  349. const shapeSvg = parent.insert("g").attr("class", node.cssClasses).attr("id", node.id).attr("data-id", node.id).attr("data-look", node.look);
  350. const outerRectG = shapeSvg.insert("g", ":first-child");
  351. const label = shapeSvg.insert("g").attr("class", "cluster-label");
  352. let innerRect = shapeSvg.append("rect");
  353. const text = label.node().appendChild(await createLabel_default(node.label, node.labelStyle, void 0, true));
  354. let bbox = text.getBBox();
  355. if (evaluate(siteConfig.flowchart.htmlLabels)) {
  356. const div = text.children[0];
  357. const dv = select2(text);
  358. bbox = div.getBoundingClientRect();
  359. dv.attr("width", bbox.width);
  360. dv.attr("height", bbox.height);
  361. }
  362. const padding = 0 * node.padding;
  363. const halfPadding = padding / 2;
  364. const width = (node.width <= bbox.width + node.padding ? bbox.width + node.padding : node.width) + padding;
  365. if (node.width <= bbox.width + node.padding) {
  366. node.diff = (width - node.width) / 2 - node.padding;
  367. } else {
  368. node.diff = -node.padding;
  369. }
  370. const height = node.height + padding;
  371. const innerHeight = node.height + padding - bbox.height - 6;
  372. const x = node.x - width / 2;
  373. const y = node.y - height / 2;
  374. node.width = width;
  375. const innerY = node.y - node.height / 2 - halfPadding + bbox.height + 2;
  376. let rect2;
  377. if (node.look === "handDrawn") {
  378. const isAlt = node.cssClasses.includes("statediagram-cluster-alt");
  379. const rc = rough.svg(shapeSvg);
  380. const roughOuterNode = node.rx || node.ry ? rc.path(createRoundedRectPathD(x, y, width, height, 10), {
  381. roughness: 0.7,
  382. fill: compositeTitleBackground,
  383. fillStyle: "solid",
  384. stroke: nodeBorder,
  385. seed: handDrawnSeed
  386. }) : rc.rectangle(x, y, width, height, { seed: handDrawnSeed });
  387. rect2 = shapeSvg.insert(() => roughOuterNode, ":first-child");
  388. const roughInnerNode = rc.rectangle(x, innerY, width, innerHeight, {
  389. fill: isAlt ? altBackground : compositeBackground,
  390. fillStyle: isAlt ? "hachure" : "solid",
  391. stroke: nodeBorder,
  392. seed: handDrawnSeed
  393. });
  394. rect2 = shapeSvg.insert(() => roughOuterNode, ":first-child");
  395. innerRect = shapeSvg.insert(() => roughInnerNode);
  396. } else {
  397. rect2 = outerRectG.insert("rect", ":first-child");
  398. const outerRectClass = "outer";
  399. rect2.attr("class", outerRectClass).attr("x", x).attr("y", y).attr("width", width).attr("height", height).attr("data-look", node.look);
  400. innerRect.attr("class", "inner").attr("x", x).attr("y", innerY).attr("width", width).attr("height", innerHeight);
  401. }
  402. label.attr(
  403. "transform",
  404. `translate(${node.x - bbox.width / 2}, ${y + 1 - (evaluate(siteConfig.flowchart.htmlLabels) ? 0 : 3)})`
  405. );
  406. const rectBox = rect2.node().getBBox();
  407. node.height = rectBox.height;
  408. node.offsetX = 0;
  409. node.offsetY = bbox.height - node.padding / 2;
  410. node.labelBBox = bbox;
  411. node.intersect = function(point2) {
  412. return intersect_rect_default(node, point2);
  413. };
  414. return { cluster: shapeSvg, labelBBox: bbox };
  415. }, "roundedWithTitle");
  416. var divider = /* @__PURE__ */ __name((parent, node) => {
  417. const siteConfig = getConfig();
  418. const { themeVariables, handDrawnSeed } = siteConfig;
  419. const { nodeBorder } = themeVariables;
  420. const shapeSvg = parent.insert("g").attr("class", node.cssClasses).attr("id", node.id).attr("data-look", node.look);
  421. const outerRectG = shapeSvg.insert("g", ":first-child");
  422. const padding = 0 * node.padding;
  423. const width = node.width + padding;
  424. node.diff = -node.padding;
  425. const height = node.height + padding;
  426. const x = node.x - width / 2;
  427. const y = node.y - height / 2;
  428. node.width = width;
  429. let rect2;
  430. if (node.look === "handDrawn") {
  431. const rc = rough.svg(shapeSvg);
  432. const roughOuterNode = rc.rectangle(x, y, width, height, {
  433. fill: "lightgrey",
  434. roughness: 0.5,
  435. strokeLineDash: [5],
  436. stroke: nodeBorder,
  437. seed: handDrawnSeed
  438. });
  439. rect2 = shapeSvg.insert(() => roughOuterNode, ":first-child");
  440. } else {
  441. rect2 = outerRectG.insert("rect", ":first-child");
  442. const outerRectClass = "divider";
  443. rect2.attr("class", outerRectClass).attr("x", x).attr("y", y).attr("width", width).attr("height", height).attr("data-look", node.look);
  444. }
  445. const rectBox = rect2.node().getBBox();
  446. node.height = rectBox.height;
  447. node.offsetX = 0;
  448. node.offsetY = 0;
  449. node.intersect = function(point2) {
  450. return intersect_rect_default(node, point2);
  451. };
  452. return { cluster: shapeSvg, labelBBox: {} };
  453. }, "divider");
  454. var squareRect = rect;
  455. var shapes = {
  456. rect,
  457. squareRect,
  458. roundedWithTitle,
  459. noteGroup,
  460. divider
  461. };
  462. var clusterElems = /* @__PURE__ */ new Map();
  463. var insertCluster = /* @__PURE__ */ __name(async (elem, node) => {
  464. const shape = node.shape || "rect";
  465. const cluster = await shapes[shape](elem, node);
  466. clusterElems.set(node.id, cluster);
  467. return cluster;
  468. }, "insertCluster");
  469. var clear = /* @__PURE__ */ __name(() => {
  470. clusterElems = /* @__PURE__ */ new Map();
  471. }, "clear");
  472. // src/rendering-util/rendering-elements/edges.js
  473. import { curveBasis, line, select as select3 } from "d3";
  474. import rough2 from "roughjs";
  475. // src/rendering-util/rendering-elements/edgeMarker.ts
  476. var addEdgeMarkers = /* @__PURE__ */ __name((svgPath, edge, url, id, diagramType) => {
  477. if (edge.arrowTypeStart) {
  478. addEdgeMarker(svgPath, "start", edge.arrowTypeStart, url, id, diagramType);
  479. }
  480. if (edge.arrowTypeEnd) {
  481. addEdgeMarker(svgPath, "end", edge.arrowTypeEnd, url, id, diagramType);
  482. }
  483. }, "addEdgeMarkers");
  484. var arrowTypesMap = {
  485. arrow_cross: "cross",
  486. arrow_point: "point",
  487. arrow_barb: "barb",
  488. arrow_circle: "circle",
  489. aggregation: "aggregation",
  490. extension: "extension",
  491. composition: "composition",
  492. dependency: "dependency",
  493. lollipop: "lollipop"
  494. };
  495. var addEdgeMarker = /* @__PURE__ */ __name((svgPath, position, arrowType, url, id, diagramType) => {
  496. const endMarkerType = arrowTypesMap[arrowType];
  497. if (!endMarkerType) {
  498. log.warn(`Unknown arrow type: ${arrowType}`);
  499. return;
  500. }
  501. const suffix = position === "start" ? "Start" : "End";
  502. svgPath.attr(`marker-${position}`, `url(${url}#${id}_${diagramType}-${endMarkerType}${suffix})`);
  503. }, "addEdgeMarker");
  504. // src/rendering-util/rendering-elements/edges.js
  505. var edgeLabels = /* @__PURE__ */ new Map();
  506. var terminalLabels = /* @__PURE__ */ new Map();
  507. var clear2 = /* @__PURE__ */ __name(() => {
  508. edgeLabels.clear();
  509. terminalLabels.clear();
  510. }, "clear");
  511. var getLabelStyles = /* @__PURE__ */ __name((styleArray) => {
  512. let styles = styleArray ? styleArray.reduce((acc, style) => acc + ";" + style, "") : "";
  513. return styles;
  514. }, "getLabelStyles");
  515. var insertEdgeLabel = /* @__PURE__ */ __name(async (elem, edge) => {
  516. let useHtmlLabels = evaluate(getConfig().flowchart.htmlLabels);
  517. const labelElement = await createText(elem, edge.label, {
  518. style: getLabelStyles(edge.labelStyle),
  519. useHtmlLabels,
  520. addSvgBackground: true,
  521. isNode: false
  522. });
  523. log.info("abc82", edge, edge.labelType);
  524. const edgeLabel = elem.insert("g").attr("class", "edgeLabel");
  525. const label = edgeLabel.insert("g").attr("class", "label");
  526. label.node().appendChild(labelElement);
  527. let bbox = labelElement.getBBox();
  528. if (useHtmlLabels) {
  529. const div = labelElement.children[0];
  530. const dv = select3(labelElement);
  531. bbox = div.getBoundingClientRect();
  532. dv.attr("width", bbox.width);
  533. dv.attr("height", bbox.height);
  534. }
  535. label.attr("transform", "translate(" + -bbox.width / 2 + ", " + -bbox.height / 2 + ")");
  536. edgeLabels.set(edge.id, edgeLabel);
  537. edge.width = bbox.width;
  538. edge.height = bbox.height;
  539. let fo;
  540. if (edge.startLabelLeft) {
  541. const startLabelElement = await createLabel_default(
  542. edge.startLabelLeft,
  543. getLabelStyles(edge.labelStyle)
  544. );
  545. const startEdgeLabelLeft = elem.insert("g").attr("class", "edgeTerminals");
  546. const inner = startEdgeLabelLeft.insert("g").attr("class", "inner");
  547. fo = inner.node().appendChild(startLabelElement);
  548. const slBox = startLabelElement.getBBox();
  549. inner.attr("transform", "translate(" + -slBox.width / 2 + ", " + -slBox.height / 2 + ")");
  550. if (!terminalLabels.get(edge.id)) {
  551. terminalLabels.set(edge.id, {});
  552. }
  553. terminalLabels.get(edge.id).startLeft = startEdgeLabelLeft;
  554. setTerminalWidth(fo, edge.startLabelLeft);
  555. }
  556. if (edge.startLabelRight) {
  557. const startLabelElement = await createLabel_default(
  558. edge.startLabelRight,
  559. getLabelStyles(edge.labelStyle)
  560. );
  561. const startEdgeLabelRight = elem.insert("g").attr("class", "edgeTerminals");
  562. const inner = startEdgeLabelRight.insert("g").attr("class", "inner");
  563. fo = startEdgeLabelRight.node().appendChild(startLabelElement);
  564. inner.node().appendChild(startLabelElement);
  565. const slBox = startLabelElement.getBBox();
  566. inner.attr("transform", "translate(" + -slBox.width / 2 + ", " + -slBox.height / 2 + ")");
  567. if (!terminalLabels.get(edge.id)) {
  568. terminalLabels.set(edge.id, {});
  569. }
  570. terminalLabels.get(edge.id).startRight = startEdgeLabelRight;
  571. setTerminalWidth(fo, edge.startLabelRight);
  572. }
  573. if (edge.endLabelLeft) {
  574. const endLabelElement = await createLabel_default(edge.endLabelLeft, getLabelStyles(edge.labelStyle));
  575. const endEdgeLabelLeft = elem.insert("g").attr("class", "edgeTerminals");
  576. const inner = endEdgeLabelLeft.insert("g").attr("class", "inner");
  577. fo = inner.node().appendChild(endLabelElement);
  578. const slBox = endLabelElement.getBBox();
  579. inner.attr("transform", "translate(" + -slBox.width / 2 + ", " + -slBox.height / 2 + ")");
  580. endEdgeLabelLeft.node().appendChild(endLabelElement);
  581. if (!terminalLabels.get(edge.id)) {
  582. terminalLabels.set(edge.id, {});
  583. }
  584. terminalLabels.get(edge.id).endLeft = endEdgeLabelLeft;
  585. setTerminalWidth(fo, edge.endLabelLeft);
  586. }
  587. if (edge.endLabelRight) {
  588. const endLabelElement = await createLabel_default(edge.endLabelRight, getLabelStyles(edge.labelStyle));
  589. const endEdgeLabelRight = elem.insert("g").attr("class", "edgeTerminals");
  590. const inner = endEdgeLabelRight.insert("g").attr("class", "inner");
  591. fo = inner.node().appendChild(endLabelElement);
  592. const slBox = endLabelElement.getBBox();
  593. inner.attr("transform", "translate(" + -slBox.width / 2 + ", " + -slBox.height / 2 + ")");
  594. endEdgeLabelRight.node().appendChild(endLabelElement);
  595. if (!terminalLabels.get(edge.id)) {
  596. terminalLabels.set(edge.id, {});
  597. }
  598. terminalLabels.get(edge.id).endRight = endEdgeLabelRight;
  599. setTerminalWidth(fo, edge.endLabelRight);
  600. }
  601. return labelElement;
  602. }, "insertEdgeLabel");
  603. function setTerminalWidth(fo, value) {
  604. if (getConfig().flowchart.htmlLabels && fo) {
  605. fo.style.width = value.length * 9 + "px";
  606. fo.style.height = "12px";
  607. }
  608. }
  609. __name(setTerminalWidth, "setTerminalWidth");
  610. var positionEdgeLabel = /* @__PURE__ */ __name((edge, paths) => {
  611. log.debug("Moving label abc88 ", edge.id, edge.label, edgeLabels.get(edge.id), paths);
  612. let path = paths.updatedPath ? paths.updatedPath : paths.originalPath;
  613. const siteConfig = getConfig();
  614. const { subGraphTitleTotalMargin } = getSubGraphTitleMargins(siteConfig);
  615. if (edge.label) {
  616. const el = edgeLabels.get(edge.id);
  617. let x = edge.x;
  618. let y = edge.y;
  619. if (path) {
  620. const pos = utils_default.calcLabelPosition(path);
  621. log.debug(
  622. "Moving label " + edge.label + " from (",
  623. x,
  624. ",",
  625. y,
  626. ") to (",
  627. pos.x,
  628. ",",
  629. pos.y,
  630. ") abc88"
  631. );
  632. if (paths.updatedPath) {
  633. x = pos.x;
  634. y = pos.y;
  635. }
  636. }
  637. el.attr("transform", `translate(${x}, ${y + subGraphTitleTotalMargin / 2})`);
  638. }
  639. if (edge.startLabelLeft) {
  640. const el = terminalLabels.get(edge.id).startLeft;
  641. let x = edge.x;
  642. let y = edge.y;
  643. if (path) {
  644. const pos = utils_default.calcTerminalLabelPosition(edge.arrowTypeStart ? 10 : 0, "start_left", path);
  645. x = pos.x;
  646. y = pos.y;
  647. }
  648. el.attr("transform", `translate(${x}, ${y})`);
  649. }
  650. if (edge.startLabelRight) {
  651. const el = terminalLabels.get(edge.id).startRight;
  652. let x = edge.x;
  653. let y = edge.y;
  654. if (path) {
  655. const pos = utils_default.calcTerminalLabelPosition(
  656. edge.arrowTypeStart ? 10 : 0,
  657. "start_right",
  658. path
  659. );
  660. x = pos.x;
  661. y = pos.y;
  662. }
  663. el.attr("transform", `translate(${x}, ${y})`);
  664. }
  665. if (edge.endLabelLeft) {
  666. const el = terminalLabels.get(edge.id).endLeft;
  667. let x = edge.x;
  668. let y = edge.y;
  669. if (path) {
  670. const pos = utils_default.calcTerminalLabelPosition(edge.arrowTypeEnd ? 10 : 0, "end_left", path);
  671. x = pos.x;
  672. y = pos.y;
  673. }
  674. el.attr("transform", `translate(${x}, ${y})`);
  675. }
  676. if (edge.endLabelRight) {
  677. const el = terminalLabels.get(edge.id).endRight;
  678. let x = edge.x;
  679. let y = edge.y;
  680. if (path) {
  681. const pos = utils_default.calcTerminalLabelPosition(edge.arrowTypeEnd ? 10 : 0, "end_right", path);
  682. x = pos.x;
  683. y = pos.y;
  684. }
  685. el.attr("transform", `translate(${x}, ${y})`);
  686. }
  687. }, "positionEdgeLabel");
  688. var outsideNode = /* @__PURE__ */ __name((node, point2) => {
  689. const x = node.x;
  690. const y = node.y;
  691. const dx = Math.abs(point2.x - x);
  692. const dy = Math.abs(point2.y - y);
  693. const w = node.width / 2;
  694. const h = node.height / 2;
  695. return dx >= w || dy >= h;
  696. }, "outsideNode");
  697. var intersection = /* @__PURE__ */ __name((node, outsidePoint, insidePoint) => {
  698. log.debug(`intersection calc abc89:
  699. outsidePoint: ${JSON.stringify(outsidePoint)}
  700. insidePoint : ${JSON.stringify(insidePoint)}
  701. node : x:${node.x} y:${node.y} w:${node.width} h:${node.height}`);
  702. const x = node.x;
  703. const y = node.y;
  704. const dx = Math.abs(x - insidePoint.x);
  705. const w = node.width / 2;
  706. let r = insidePoint.x < outsidePoint.x ? w - dx : w + dx;
  707. const h = node.height / 2;
  708. const Q = Math.abs(outsidePoint.y - insidePoint.y);
  709. const R = Math.abs(outsidePoint.x - insidePoint.x);
  710. if (Math.abs(y - outsidePoint.y) * w > Math.abs(x - outsidePoint.x) * h) {
  711. let q = insidePoint.y < outsidePoint.y ? outsidePoint.y - h - y : y - h - outsidePoint.y;
  712. r = R * q / Q;
  713. const res = {
  714. x: insidePoint.x < outsidePoint.x ? insidePoint.x + r : insidePoint.x - R + r,
  715. y: insidePoint.y < outsidePoint.y ? insidePoint.y + Q - q : insidePoint.y - Q + q
  716. };
  717. if (r === 0) {
  718. res.x = outsidePoint.x;
  719. res.y = outsidePoint.y;
  720. }
  721. if (R === 0) {
  722. res.x = outsidePoint.x;
  723. }
  724. if (Q === 0) {
  725. res.y = outsidePoint.y;
  726. }
  727. log.debug(`abc89 top/bottom calc, Q ${Q}, q ${q}, R ${R}, r ${r}`, res);
  728. return res;
  729. } else {
  730. if (insidePoint.x < outsidePoint.x) {
  731. r = outsidePoint.x - w - x;
  732. } else {
  733. r = x - w - outsidePoint.x;
  734. }
  735. let q = Q * r / R;
  736. let _x = insidePoint.x < outsidePoint.x ? insidePoint.x + R - r : insidePoint.x - R + r;
  737. let _y = insidePoint.y < outsidePoint.y ? insidePoint.y + q : insidePoint.y - q;
  738. log.debug(`sides calc abc89, Q ${Q}, q ${q}, R ${R}, r ${r}`, { _x, _y });
  739. if (r === 0) {
  740. _x = outsidePoint.x;
  741. _y = outsidePoint.y;
  742. }
  743. if (R === 0) {
  744. _x = outsidePoint.x;
  745. }
  746. if (Q === 0) {
  747. _y = outsidePoint.y;
  748. }
  749. return { x: _x, y: _y };
  750. }
  751. }, "intersection");
  752. var cutPathAtIntersect = /* @__PURE__ */ __name((_points, boundaryNode) => {
  753. log.warn("abc88 cutPathAtIntersect", _points, boundaryNode);
  754. let points = [];
  755. let lastPointOutside = _points[0];
  756. let isInside = false;
  757. _points.forEach((point2) => {
  758. log.info("abc88 checking point", point2, boundaryNode);
  759. if (!outsideNode(boundaryNode, point2) && !isInside) {
  760. const inter = intersection(boundaryNode, lastPointOutside, point2);
  761. log.debug("abc88 inside", point2, lastPointOutside, inter);
  762. log.debug("abc88 intersection", inter, boundaryNode);
  763. let pointPresent = false;
  764. points.forEach((p) => {
  765. pointPresent = pointPresent || p.x === inter.x && p.y === inter.y;
  766. });
  767. if (!points.some((e) => e.x === inter.x && e.y === inter.y)) {
  768. points.push(inter);
  769. } else {
  770. log.warn("abc88 no intersect", inter, points);
  771. }
  772. isInside = true;
  773. } else {
  774. log.warn("abc88 outside", point2, lastPointOutside);
  775. lastPointOutside = point2;
  776. if (!isInside) {
  777. points.push(point2);
  778. }
  779. }
  780. });
  781. log.debug("returning points", points);
  782. return points;
  783. }, "cutPathAtIntersect");
  784. function extractCornerPoints(points) {
  785. const cornerPoints = [];
  786. const cornerPointPositions = [];
  787. for (let i = 1; i < points.length - 1; i++) {
  788. const prev = points[i - 1];
  789. const curr = points[i];
  790. const next = points[i + 1];
  791. if (prev.x === curr.x && curr.y === next.y && Math.abs(curr.x - next.x) > 5 && Math.abs(curr.y - prev.y) > 5) {
  792. cornerPoints.push(curr);
  793. cornerPointPositions.push(i);
  794. } else if (prev.y === curr.y && curr.x === next.x && Math.abs(curr.x - prev.x) > 5 && Math.abs(curr.y - next.y) > 5) {
  795. cornerPoints.push(curr);
  796. cornerPointPositions.push(i);
  797. }
  798. }
  799. return { cornerPoints, cornerPointPositions };
  800. }
  801. __name(extractCornerPoints, "extractCornerPoints");
  802. var findAdjacentPoint = /* @__PURE__ */ __name(function(pointA, pointB, distance) {
  803. const xDiff = pointB.x - pointA.x;
  804. const yDiff = pointB.y - pointA.y;
  805. const length = Math.sqrt(xDiff * xDiff + yDiff * yDiff);
  806. const ratio = distance / length;
  807. return { x: pointB.x - ratio * xDiff, y: pointB.y - ratio * yDiff };
  808. }, "findAdjacentPoint");
  809. var fixCorners = /* @__PURE__ */ __name(function(lineData) {
  810. const { cornerPointPositions } = extractCornerPoints(lineData);
  811. const newLineData = [];
  812. for (let i = 0; i < lineData.length; i++) {
  813. if (cornerPointPositions.includes(i)) {
  814. const prevPoint = lineData[i - 1];
  815. const nextPoint = lineData[i + 1];
  816. const cornerPoint = lineData[i];
  817. const newPrevPoint = findAdjacentPoint(prevPoint, cornerPoint, 5);
  818. const newNextPoint = findAdjacentPoint(nextPoint, cornerPoint, 5);
  819. const xDiff = newNextPoint.x - newPrevPoint.x;
  820. const yDiff = newNextPoint.y - newPrevPoint.y;
  821. newLineData.push(newPrevPoint);
  822. const a = Math.sqrt(2) * 2;
  823. let newCornerPoint = { x: cornerPoint.x, y: cornerPoint.y };
  824. if (Math.abs(nextPoint.x - prevPoint.x) > 10 && Math.abs(nextPoint.y - prevPoint.y) >= 10) {
  825. log.debug(
  826. "Corner point fixing",
  827. Math.abs(nextPoint.x - prevPoint.x),
  828. Math.abs(nextPoint.y - prevPoint.y)
  829. );
  830. const r = 5;
  831. if (cornerPoint.x === newPrevPoint.x) {
  832. newCornerPoint = {
  833. x: xDiff < 0 ? newPrevPoint.x - r + a : newPrevPoint.x + r - a,
  834. y: yDiff < 0 ? newPrevPoint.y - a : newPrevPoint.y + a
  835. };
  836. } else {
  837. newCornerPoint = {
  838. x: xDiff < 0 ? newPrevPoint.x - a : newPrevPoint.x + a,
  839. y: yDiff < 0 ? newPrevPoint.y - r + a : newPrevPoint.y + r - a
  840. };
  841. }
  842. } else {
  843. log.debug(
  844. "Corner point skipping fixing",
  845. Math.abs(nextPoint.x - prevPoint.x),
  846. Math.abs(nextPoint.y - prevPoint.y)
  847. );
  848. }
  849. newLineData.push(newCornerPoint, newNextPoint);
  850. } else {
  851. newLineData.push(lineData[i]);
  852. }
  853. }
  854. return newLineData;
  855. }, "fixCorners");
  856. var insertEdge = /* @__PURE__ */ __name(function(elem, edge, clusterDb, diagramType, startNode, endNode, id) {
  857. const { handDrawnSeed } = getConfig();
  858. let points = edge.points;
  859. let pointsHasChanged = false;
  860. const tail = startNode;
  861. var head = endNode;
  862. if (head.intersect && tail.intersect) {
  863. points = points.slice(1, edge.points.length - 1);
  864. points.unshift(tail.intersect(points[0]));
  865. log.debug(
  866. "Last point APA12",
  867. edge.start,
  868. "-->",
  869. edge.end,
  870. points[points.length - 1],
  871. head,
  872. head.intersect(points[points.length - 1])
  873. );
  874. points.push(head.intersect(points[points.length - 1]));
  875. }
  876. if (edge.toCluster) {
  877. log.info("to cluster abc88", clusterDb.get(edge.toCluster));
  878. points = cutPathAtIntersect(edge.points, clusterDb.get(edge.toCluster).node);
  879. pointsHasChanged = true;
  880. }
  881. if (edge.fromCluster) {
  882. log.debug(
  883. "from cluster abc88",
  884. clusterDb.get(edge.fromCluster),
  885. JSON.stringify(points, null, 2)
  886. );
  887. points = cutPathAtIntersect(points.reverse(), clusterDb.get(edge.fromCluster).node).reverse();
  888. pointsHasChanged = true;
  889. }
  890. let lineData = points.filter((p) => !Number.isNaN(p.y));
  891. lineData = fixCorners(lineData);
  892. let lastPoint = lineData[lineData.length - 1];
  893. if (lineData.length > 1) {
  894. lastPoint = lineData[lineData.length - 1];
  895. const secondLastPoint = lineData[lineData.length - 2];
  896. const diffX = (lastPoint.x - secondLastPoint.x) / 2;
  897. const diffY = (lastPoint.y - secondLastPoint.y) / 2;
  898. const midPoint = { x: secondLastPoint.x + diffX, y: secondLastPoint.y + diffY };
  899. lineData.splice(-1, 0, midPoint);
  900. }
  901. let curve = curveBasis;
  902. if (edge.curve) {
  903. curve = edge.curve;
  904. }
  905. const { x, y } = getLineFunctionsWithOffset(edge);
  906. const lineFunction = line().x(x).y(y).curve(curve);
  907. let strokeClasses;
  908. switch (edge.thickness) {
  909. case "normal":
  910. strokeClasses = "edge-thickness-normal";
  911. break;
  912. case "thick":
  913. strokeClasses = "edge-thickness-thick";
  914. break;
  915. case "invisible":
  916. strokeClasses = "edge-thickness-invisible";
  917. break;
  918. default:
  919. strokeClasses = "edge-thickness-normal";
  920. }
  921. switch (edge.pattern) {
  922. case "solid":
  923. strokeClasses += " edge-pattern-solid";
  924. break;
  925. case "dotted":
  926. strokeClasses += " edge-pattern-dotted";
  927. break;
  928. case "dashed":
  929. strokeClasses += " edge-pattern-dashed";
  930. break;
  931. default:
  932. strokeClasses += " edge-pattern-solid";
  933. }
  934. let svgPath;
  935. let linePath = lineFunction(lineData);
  936. const edgeStyles = Array.isArray(edge.style) ? edge.style : [edge.style];
  937. if (edge.look === "handDrawn") {
  938. const rc = rough2.svg(elem);
  939. Object.assign([], lineData);
  940. const svgPathNode = rc.path(linePath, {
  941. roughness: 0.3,
  942. seed: handDrawnSeed
  943. });
  944. strokeClasses += " transition";
  945. svgPath = select3(svgPathNode).select("path").attr("id", edge.id).attr("class", " " + strokeClasses + (edge.classes ? " " + edge.classes : "")).attr("style", edgeStyles ? edgeStyles.reduce((acc, style) => acc + ";" + style, "") : "");
  946. let d = svgPath.attr("d");
  947. svgPath.attr("d", d);
  948. elem.node().appendChild(svgPath.node());
  949. } else {
  950. svgPath = elem.append("path").attr("d", linePath).attr("id", edge.id).attr("class", " " + strokeClasses + (edge.classes ? " " + edge.classes : "")).attr("style", edgeStyles ? edgeStyles.reduce((acc, style) => acc + ";" + style, "") : "");
  951. }
  952. let url = "";
  953. if (getConfig().flowchart.arrowMarkerAbsolute || getConfig().state.arrowMarkerAbsolute) {
  954. url = window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.search;
  955. url = url.replace(/\(/g, "\\(").replace(/\)/g, "\\)");
  956. }
  957. log.info("arrowTypeStart", edge.arrowTypeStart);
  958. log.info("arrowTypeEnd", edge.arrowTypeEnd);
  959. addEdgeMarkers(svgPath, edge, url, id, diagramType);
  960. let paths = {};
  961. if (pointsHasChanged) {
  962. paths.updatedPath = points;
  963. }
  964. paths.originalPath = edge.points;
  965. return paths;
  966. }, "insertEdge");
  967. // src/rendering-util/rendering-elements/markers.js
  968. var insertMarkers = /* @__PURE__ */ __name((elem, markerArray, type, id) => {
  969. markerArray.forEach((markerName) => {
  970. markers[markerName](elem, type, id);
  971. });
  972. }, "insertMarkers");
  973. var extension = /* @__PURE__ */ __name((elem, type, id) => {
  974. log.trace("Making markers for ", id);
  975. elem.append("defs").append("marker").attr("id", id + "_" + type + "-extensionStart").attr("class", "marker extension " + type).attr("refX", 18).attr("refY", 7).attr("markerWidth", 190).attr("markerHeight", 240).attr("orient", "auto").append("path").attr("d", "M 1,7 L18,13 V 1 Z");
  976. elem.append("defs").append("marker").attr("id", id + "_" + type + "-extensionEnd").attr("class", "marker extension " + type).attr("refX", 1).attr("refY", 7).attr("markerWidth", 20).attr("markerHeight", 28).attr("orient", "auto").append("path").attr("d", "M 1,1 V 13 L18,7 Z");
  977. }, "extension");
  978. var composition = /* @__PURE__ */ __name((elem, type, id) => {
  979. elem.append("defs").append("marker").attr("id", id + "_" + type + "-compositionStart").attr("class", "marker composition " + type).attr("refX", 18).attr("refY", 7).attr("markerWidth", 190).attr("markerHeight", 240).attr("orient", "auto").append("path").attr("d", "M 18,7 L9,13 L1,7 L9,1 Z");
  980. elem.append("defs").append("marker").attr("id", id + "_" + type + "-compositionEnd").attr("class", "marker composition " + type).attr("refX", 1).attr("refY", 7).attr("markerWidth", 20).attr("markerHeight", 28).attr("orient", "auto").append("path").attr("d", "M 18,7 L9,13 L1,7 L9,1 Z");
  981. }, "composition");
  982. var aggregation = /* @__PURE__ */ __name((elem, type, id) => {
  983. elem.append("defs").append("marker").attr("id", id + "_" + type + "-aggregationStart").attr("class", "marker aggregation " + type).attr("refX", 18).attr("refY", 7).attr("markerWidth", 190).attr("markerHeight", 240).attr("orient", "auto").append("path").attr("d", "M 18,7 L9,13 L1,7 L9,1 Z");
  984. elem.append("defs").append("marker").attr("id", id + "_" + type + "-aggregationEnd").attr("class", "marker aggregation " + type).attr("refX", 1).attr("refY", 7).attr("markerWidth", 20).attr("markerHeight", 28).attr("orient", "auto").append("path").attr("d", "M 18,7 L9,13 L1,7 L9,1 Z");
  985. }, "aggregation");
  986. var dependency = /* @__PURE__ */ __name((elem, type, id) => {
  987. elem.append("defs").append("marker").attr("id", id + "_" + type + "-dependencyStart").attr("class", "marker dependency " + type).attr("refX", 6).attr("refY", 7).attr("markerWidth", 190).attr("markerHeight", 240).attr("orient", "auto").append("path").attr("d", "M 5,7 L9,13 L1,7 L9,1 Z");
  988. elem.append("defs").append("marker").attr("id", id + "_" + type + "-dependencyEnd").attr("class", "marker dependency " + type).attr("refX", 13).attr("refY", 7).attr("markerWidth", 20).attr("markerHeight", 28).attr("orient", "auto").append("path").attr("d", "M 18,7 L9,13 L14,7 L9,1 Z");
  989. }, "dependency");
  990. var lollipop = /* @__PURE__ */ __name((elem, type, id) => {
  991. elem.append("defs").append("marker").attr("id", id + "_" + type + "-lollipopStart").attr("class", "marker lollipop " + type).attr("refX", 13).attr("refY", 7).attr("markerWidth", 190).attr("markerHeight", 240).attr("orient", "auto").append("circle").attr("stroke", "black").attr("fill", "transparent").attr("cx", 7).attr("cy", 7).attr("r", 6);
  992. elem.append("defs").append("marker").attr("id", id + "_" + type + "-lollipopEnd").attr("class", "marker lollipop " + type).attr("refX", 1).attr("refY", 7).attr("markerWidth", 190).attr("markerHeight", 240).attr("orient", "auto").append("circle").attr("stroke", "black").attr("fill", "transparent").attr("cx", 7).attr("cy", 7).attr("r", 6);
  993. }, "lollipop");
  994. var point = /* @__PURE__ */ __name((elem, type, id) => {
  995. elem.append("marker").attr("id", id + "_" + type + "-pointEnd").attr("class", "marker " + type).attr("viewBox", "0 0 10 10").attr("refX", 5).attr("refY", 5).attr("markerUnits", "userSpaceOnUse").attr("markerWidth", 8).attr("markerHeight", 8).attr("orient", "auto").append("path").attr("d", "M 0 0 L 10 5 L 0 10 z").attr("class", "arrowMarkerPath").style("stroke-width", 1).style("stroke-dasharray", "1,0");
  996. elem.append("marker").attr("id", id + "_" + type + "-pointStart").attr("class", "marker " + type).attr("viewBox", "0 0 10 10").attr("refX", 4.5).attr("refY", 5).attr("markerUnits", "userSpaceOnUse").attr("markerWidth", 8).attr("markerHeight", 8).attr("orient", "auto").append("path").attr("d", "M 0 5 L 10 10 L 10 0 z").attr("class", "arrowMarkerPath").style("stroke-width", 1).style("stroke-dasharray", "1,0");
  997. }, "point");
  998. var circle = /* @__PURE__ */ __name((elem, type, id) => {
  999. elem.append("marker").attr("id", id + "_" + type + "-circleEnd").attr("class", "marker " + type).attr("viewBox", "0 0 10 10").attr("refX", 11).attr("refY", 5).attr("markerUnits", "userSpaceOnUse").attr("markerWidth", 11).attr("markerHeight", 11).attr("orient", "auto").append("circle").attr("cx", "5").attr("cy", "5").attr("r", "5").attr("class", "arrowMarkerPath").style("stroke-width", 1).style("stroke-dasharray", "1,0");
  1000. elem.append("marker").attr("id", id + "_" + type + "-circleStart").attr("class", "marker " + type).attr("viewBox", "0 0 10 10").attr("refX", -1).attr("refY", 5).attr("markerUnits", "userSpaceOnUse").attr("markerWidth", 11).attr("markerHeight", 11).attr("orient", "auto").append("circle").attr("cx", "5").attr("cy", "5").attr("r", "5").attr("class", "arrowMarkerPath").style("stroke-width", 1).style("stroke-dasharray", "1,0");
  1001. }, "circle");
  1002. var cross = /* @__PURE__ */ __name((elem, type, id) => {
  1003. elem.append("marker").attr("id", id + "_" + type + "-crossEnd").attr("class", "marker cross " + type).attr("viewBox", "0 0 11 11").attr("refX", 12).attr("refY", 5.2).attr("markerUnits", "userSpaceOnUse").attr("markerWidth", 11).attr("markerHeight", 11).attr("orient", "auto").append("path").attr("d", "M 1,1 l 9,9 M 10,1 l -9,9").attr("class", "arrowMarkerPath").style("stroke-width", 2).style("stroke-dasharray", "1,0");
  1004. elem.append("marker").attr("id", id + "_" + type + "-crossStart").attr("class", "marker cross " + type).attr("viewBox", "0 0 11 11").attr("refX", -1).attr("refY", 5.2).attr("markerUnits", "userSpaceOnUse").attr("markerWidth", 11).attr("markerHeight", 11).attr("orient", "auto").append("path").attr("d", "M 1,1 l 9,9 M 10,1 l -9,9").attr("class", "arrowMarkerPath").style("stroke-width", 2).style("stroke-dasharray", "1,0");
  1005. }, "cross");
  1006. var barb = /* @__PURE__ */ __name((elem, type, id) => {
  1007. elem.append("defs").append("marker").attr("id", id + "_" + type + "-barbEnd").attr("refX", 19).attr("refY", 7).attr("markerWidth", 20).attr("markerHeight", 14).attr("markerUnits", "userSpaceOnUse").attr("orient", "auto").append("path").attr("d", "M 19,7 L9,13 L14,7 L9,1 Z");
  1008. }, "barb");
  1009. var markers = {
  1010. extension,
  1011. composition,
  1012. aggregation,
  1013. dependency,
  1014. lollipop,
  1015. point,
  1016. circle,
  1017. cross,
  1018. barb
  1019. };
  1020. var markers_default = insertMarkers;
  1021. // src/rendering-util/rendering-elements/shapes/util.js
  1022. import { select as select4 } from "d3";
  1023. var labelHelper = /* @__PURE__ */ __name(async (parent, node, _classes) => {
  1024. let cssClasses;
  1025. const useHtmlLabels = node.useHtmlLabels || evaluate(getConfig().flowchart.htmlLabels);
  1026. if (!_classes) {
  1027. cssClasses = "node default";
  1028. } else {
  1029. cssClasses = _classes;
  1030. }
  1031. const shapeSvg = parent.insert("g").attr("class", cssClasses).attr("id", node.domId || node.id);
  1032. const labelEl = shapeSvg.insert("g").attr("class", "label").attr("style", node.labelStyle);
  1033. let label;
  1034. if (node.label === void 0) {
  1035. label = "";
  1036. } else {
  1037. label = typeof node.label === "string" ? node.label : node.label[0];
  1038. }
  1039. let text;
  1040. text = await createText(labelEl, sanitizeText(decodeEntities(label), getConfig()), {
  1041. useHtmlLabels,
  1042. width: node.width || getConfig().flowchart.wrappingWidth,
  1043. cssClasses: "markdown-node-label",
  1044. style: node.labelStyle
  1045. });
  1046. let bbox = text.getBBox();
  1047. const halfPadding = node.padding / 2;
  1048. if (evaluate(getConfig().flowchart.htmlLabels)) {
  1049. const div = text.children[0];
  1050. const dv = select4(text);
  1051. const images = div.getElementsByTagName("img");
  1052. if (images) {
  1053. const noImgText = label.replace(/<img[^>]*>/g, "").trim() === "";
  1054. await Promise.all(
  1055. [...images].map(
  1056. (img) => new Promise((res) => {
  1057. function setupImage() {
  1058. img.style.display = "flex";
  1059. img.style.flexDirection = "column";
  1060. if (noImgText) {
  1061. const bodyFontSize = getConfig().fontSize ? getConfig().fontSize : window.getComputedStyle(document.body).fontSize;
  1062. const enlargingFactor = 5;
  1063. const width = parseInt(bodyFontSize, 10) * enlargingFactor + "px";
  1064. img.style.minWidth = width;
  1065. img.style.maxWidth = width;
  1066. } else {
  1067. img.style.width = "100%";
  1068. }
  1069. res(img);
  1070. }
  1071. __name(setupImage, "setupImage");
  1072. setTimeout(() => {
  1073. if (img.complete) {
  1074. setupImage();
  1075. }
  1076. });
  1077. img.addEventListener("error", setupImage);
  1078. img.addEventListener("load", setupImage);
  1079. })
  1080. )
  1081. );
  1082. }
  1083. bbox = div.getBoundingClientRect();
  1084. dv.attr("width", bbox.width);
  1085. dv.attr("height", bbox.height);
  1086. }
  1087. if (useHtmlLabels) {
  1088. labelEl.attr("transform", "translate(" + -bbox.width / 2 + ", " + -bbox.height / 2 + ")");
  1089. } else {
  1090. labelEl.attr("transform", "translate(0, " + -bbox.height / 2 + ")");
  1091. }
  1092. if (node.centerLabel) {
  1093. labelEl.attr("transform", "translate(" + -bbox.width / 2 + ", " + -bbox.height / 2 + ")");
  1094. }
  1095. labelEl.insert("rect", ":first-child");
  1096. return { shapeSvg, bbox, halfPadding, label: labelEl };
  1097. }, "labelHelper");
  1098. var updateNodeBounds = /* @__PURE__ */ __name((node, element) => {
  1099. const bbox = element.node().getBBox();
  1100. node.width = bbox.width;
  1101. node.height = bbox.height;
  1102. }, "updateNodeBounds");
  1103. var getNodeClasses = /* @__PURE__ */ __name((node, extra) => (node.look === "handDrawn" ? "rough-node" : "node") + " " + node.cssClasses + " " + (extra || ""), "getNodeClasses");
  1104. // src/rendering-util/rendering-elements/intersect/intersect-node.js
  1105. function intersectNode(node, point2) {
  1106. return node.intersect(point2);
  1107. }
  1108. __name(intersectNode, "intersectNode");
  1109. var intersect_node_default = intersectNode;
  1110. // src/rendering-util/rendering-elements/intersect/intersect-ellipse.js
  1111. function intersectEllipse(node, rx, ry, point2) {
  1112. var cx = node.x;
  1113. var cy = node.y;
  1114. var px = cx - point2.x;
  1115. var py = cy - point2.y;
  1116. var det = Math.sqrt(rx * rx * py * py + ry * ry * px * px);
  1117. var dx = Math.abs(rx * ry * px / det);
  1118. if (point2.x < cx) {
  1119. dx = -dx;
  1120. }
  1121. var dy = Math.abs(rx * ry * py / det);
  1122. if (point2.y < cy) {
  1123. dy = -dy;
  1124. }
  1125. return { x: cx + dx, y: cy + dy };
  1126. }
  1127. __name(intersectEllipse, "intersectEllipse");
  1128. var intersect_ellipse_default = intersectEllipse;
  1129. // src/rendering-util/rendering-elements/intersect/intersect-circle.js
  1130. function intersectCircle(node, rx, point2) {
  1131. return intersect_ellipse_default(node, rx, rx, point2);
  1132. }
  1133. __name(intersectCircle, "intersectCircle");
  1134. var intersect_circle_default = intersectCircle;
  1135. // src/rendering-util/rendering-elements/intersect/intersect-line.js
  1136. function intersectLine(p1, p2, q1, q2) {
  1137. var a1, a2, b1, b2, c1, c2;
  1138. var r1, r2, r3, r4;
  1139. var denom, offset, num;
  1140. var x, y;
  1141. a1 = p2.y - p1.y;
  1142. b1 = p1.x - p2.x;
  1143. c1 = p2.x * p1.y - p1.x * p2.y;
  1144. r3 = a1 * q1.x + b1 * q1.y + c1;
  1145. r4 = a1 * q2.x + b1 * q2.y + c1;
  1146. if (r3 !== 0 && r4 !== 0 && sameSign(r3, r4)) {
  1147. return;
  1148. }
  1149. a2 = q2.y - q1.y;
  1150. b2 = q1.x - q2.x;
  1151. c2 = q2.x * q1.y - q1.x * q2.y;
  1152. r1 = a2 * p1.x + b2 * p1.y + c2;
  1153. r2 = a2 * p2.x + b2 * p2.y + c2;
  1154. if (r1 !== 0 && r2 !== 0 && sameSign(r1, r2)) {
  1155. return;
  1156. }
  1157. denom = a1 * b2 - a2 * b1;
  1158. if (denom === 0) {
  1159. return;
  1160. }
  1161. offset = Math.abs(denom / 2);
  1162. num = b1 * c2 - b2 * c1;
  1163. x = num < 0 ? (num - offset) / denom : (num + offset) / denom;
  1164. num = a2 * c1 - a1 * c2;
  1165. y = num < 0 ? (num - offset) / denom : (num + offset) / denom;
  1166. return { x, y };
  1167. }
  1168. __name(intersectLine, "intersectLine");
  1169. function sameSign(r1, r2) {
  1170. return r1 * r2 > 0;
  1171. }
  1172. __name(sameSign, "sameSign");
  1173. var intersect_line_default = intersectLine;
  1174. // src/rendering-util/rendering-elements/intersect/intersect-polygon.js
  1175. function intersectPolygon(node, polyPoints, point2) {
  1176. let x1 = node.x;
  1177. let y1 = node.y;
  1178. let intersections = [];
  1179. let minX = Number.POSITIVE_INFINITY;
  1180. let minY = Number.POSITIVE_INFINITY;
  1181. if (typeof polyPoints.forEach === "function") {
  1182. polyPoints.forEach(function(entry) {
  1183. minX = Math.min(minX, entry.x);
  1184. minY = Math.min(minY, entry.y);
  1185. });
  1186. } else {
  1187. minX = Math.min(minX, polyPoints.x);
  1188. minY = Math.min(minY, polyPoints.y);
  1189. }
  1190. let left = x1 - node.width / 2 - minX;
  1191. let top = y1 - node.height / 2 - minY;
  1192. for (let i = 0; i < polyPoints.length; i++) {
  1193. let p1 = polyPoints[i];
  1194. let p2 = polyPoints[i < polyPoints.length - 1 ? i + 1 : 0];
  1195. let intersect = intersect_line_default(
  1196. node,
  1197. point2,
  1198. { x: left + p1.x, y: top + p1.y },
  1199. { x: left + p2.x, y: top + p2.y }
  1200. );
  1201. if (intersect) {
  1202. intersections.push(intersect);
  1203. }
  1204. }
  1205. if (!intersections.length) {
  1206. return node;
  1207. }
  1208. if (intersections.length > 1) {
  1209. intersections.sort(function(p, q) {
  1210. let pdx = p.x - point2.x;
  1211. let pdy = p.y - point2.y;
  1212. let distp = Math.sqrt(pdx * pdx + pdy * pdy);
  1213. let qdx = q.x - point2.x;
  1214. let qdy = q.y - point2.y;
  1215. let distq = Math.sqrt(qdx * qdx + qdy * qdy);
  1216. return distp < distq ? -1 : distp === distq ? 0 : 1;
  1217. });
  1218. }
  1219. return intersections[0];
  1220. }
  1221. __name(intersectPolygon, "intersectPolygon");
  1222. var intersect_polygon_default = intersectPolygon;
  1223. // src/rendering-util/rendering-elements/intersect/index.js
  1224. var intersect_default = {
  1225. node: intersect_node_default,
  1226. circle: intersect_circle_default,
  1227. ellipse: intersect_ellipse_default,
  1228. polygon: intersect_polygon_default,
  1229. rect: intersect_rect_default
  1230. };
  1231. // src/rendering-util/rendering-elements/shapes/drawRect.ts
  1232. import rough3 from "roughjs";
  1233. var drawRect = /* @__PURE__ */ __name(async (parent, node, options) => {
  1234. const { labelStyles, nodeStyles } = styles2String(node);
  1235. node.labelStyle = labelStyles;
  1236. const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node));
  1237. const totalWidth = Math.max(bbox.width + options.labelPaddingX * 2, node?.width || 0);
  1238. const totalHeight = Math.max(bbox.height + options.labelPaddingY * 2, node?.height || 0);
  1239. const x = -totalWidth / 2;
  1240. const y = -totalHeight / 2;
  1241. let rect2;
  1242. let { rx, ry } = node;
  1243. const { cssStyles } = node;
  1244. if (options?.rx && options.ry) {
  1245. rx = options.rx;
  1246. ry = options.ry;
  1247. }
  1248. if (node.look === "handDrawn") {
  1249. const rc = rough3.svg(shapeSvg);
  1250. const options2 = userNodeOverrides(node, {});
  1251. const roughNode = rx || ry ? rc.path(createRoundedRectPathD(x, y, totalWidth, totalHeight, rx || 0), options2) : rc.rectangle(x, y, totalWidth, totalHeight, options2);
  1252. rect2 = shapeSvg.insert(() => roughNode, ":first-child");
  1253. rect2.attr("class", "basic label-container").attr("style", cssStyles);
  1254. } else {
  1255. rect2 = shapeSvg.insert("rect", ":first-child");
  1256. rect2.attr("class", "basic label-container").attr("style", nodeStyles).attr("rx", rx).attr("data-id", "abc").attr("data-et", "node").attr("ry", ry).attr("x", x).attr("y", y).attr("width", totalWidth).attr("height", totalHeight);
  1257. }
  1258. updateNodeBounds(node, rect2);
  1259. node.intersect = function(point2) {
  1260. return intersect_default.rect(node, point2);
  1261. };
  1262. return shapeSvg;
  1263. }, "drawRect");
  1264. // src/rendering-util/rendering-elements/shapes/state.ts
  1265. var state = /* @__PURE__ */ __name(async (parent, node) => {
  1266. const options = {
  1267. rx: 5,
  1268. ry: 5,
  1269. classes: "flowchart-node"
  1270. };
  1271. return drawRect(parent, node, options);
  1272. }, "state");
  1273. // src/rendering-util/rendering-elements/shapes/roundedRect.ts
  1274. var roundedRect = /* @__PURE__ */ __name(async (parent, node) => {
  1275. const options = {
  1276. rx: 5,
  1277. ry: 5,
  1278. classes: "",
  1279. labelPaddingX: (node?.padding || 0) * 1,
  1280. labelPaddingY: (node?.padding || 0) * 1
  1281. };
  1282. return drawRect(parent, node, options);
  1283. }, "roundedRect");
  1284. // src/rendering-util/rendering-elements/shapes/squareRect.ts
  1285. var squareRect2 = /* @__PURE__ */ __name(async (parent, node) => {
  1286. const options = {
  1287. rx: 0,
  1288. ry: 0,
  1289. classes: "",
  1290. labelPaddingX: (node?.padding || 0) * 2,
  1291. labelPaddingY: (node?.padding || 0) * 1
  1292. };
  1293. return drawRect(parent, node, options);
  1294. }, "squareRect");
  1295. // src/rendering-util/rendering-elements/shapes/stateStart.ts
  1296. import rough4 from "roughjs";
  1297. var stateStart = /* @__PURE__ */ __name((parent, node) => {
  1298. const { themeVariables } = getConfig();
  1299. const { lineColor } = themeVariables;
  1300. const shapeSvg = parent.insert("g").attr("class", "node default").attr("id", node.domId || node.id);
  1301. let circle3;
  1302. if (node.look === "handDrawn") {
  1303. const rc = rough4.svg(shapeSvg);
  1304. const roughNode = rc.circle(0, 0, 14, solidStateFill(lineColor));
  1305. circle3 = shapeSvg.insert(() => roughNode);
  1306. } else {
  1307. circle3 = shapeSvg.insert("circle", ":first-child");
  1308. }
  1309. circle3.attr("class", "state-start").attr("r", 7).attr("width", 14).attr("height", 14);
  1310. updateNodeBounds(node, circle3);
  1311. node.intersect = function(point2) {
  1312. return intersect_default.circle(node, 7, point2);
  1313. };
  1314. return shapeSvg;
  1315. }, "stateStart");
  1316. // src/rendering-util/rendering-elements/shapes/stateEnd.ts
  1317. import rough5 from "roughjs";
  1318. var stateEnd = /* @__PURE__ */ __name((parent, node) => {
  1319. const { themeVariables } = getConfig();
  1320. const { lineColor } = themeVariables;
  1321. const shapeSvg = parent.insert("g").attr("class", "node default").attr("id", node.domId || node.id);
  1322. let circle3;
  1323. let innerCircle;
  1324. if (node.look === "handDrawn") {
  1325. const rc = rough5.svg(shapeSvg);
  1326. const roughNode = rc.circle(0, 0, 14, { ...solidStateFill(lineColor), roughness: 0.5 });
  1327. const roughInnerNode = rc.circle(0, 0, 5, { ...solidStateFill(lineColor), fillStyle: "solid" });
  1328. circle3 = shapeSvg.insert(() => roughNode);
  1329. innerCircle = shapeSvg.insert(() => roughInnerNode);
  1330. } else {
  1331. innerCircle = shapeSvg.insert("circle", ":first-child");
  1332. circle3 = shapeSvg.insert("circle", ":first-child");
  1333. circle3.attr("class", "state-start").attr("r", 7).attr("width", 14).attr("height", 14);
  1334. innerCircle.attr("class", "state-end").attr("r", 5).attr("width", 10).attr("height", 10);
  1335. }
  1336. updateNodeBounds(node, circle3);
  1337. node.intersect = function(point2) {
  1338. return intersect_default.circle(node, 7, point2);
  1339. };
  1340. return shapeSvg;
  1341. }, "stateEnd");
  1342. // src/rendering-util/rendering-elements/shapes/forkJoin.ts
  1343. import rough6 from "roughjs";
  1344. var forkJoin = /* @__PURE__ */ __name((parent, node, dir) => {
  1345. const { themeVariables } = getConfig();
  1346. const { lineColor } = themeVariables;
  1347. const shapeSvg = parent.insert("g").attr("class", "node default").attr("id", node.domId || node.id);
  1348. let width = 70;
  1349. let height = 10;
  1350. if (dir === "LR") {
  1351. width = 10;
  1352. height = 70;
  1353. }
  1354. const x = -1 * width / 2;
  1355. const y = -1 * height / 2;
  1356. let shape;
  1357. if (node.look === "handDrawn") {
  1358. const rc = rough6.svg(shapeSvg);
  1359. const roughNode = rc.rectangle(x, y, width, height, solidStateFill(lineColor));
  1360. shape = shapeSvg.insert(() => roughNode);
  1361. } else {
  1362. shape = shapeSvg.append("rect").attr("x", x).attr("y", y).attr("width", width).attr("height", height).attr("class", "fork-join");
  1363. }
  1364. updateNodeBounds(node, shape);
  1365. let nodeHeight = 0;
  1366. let nodeWidth = 0;
  1367. let nodePadding = 10;
  1368. if (node.height) {
  1369. nodeHeight = node.height;
  1370. }
  1371. if (node.width) {
  1372. nodeWidth = node.width;
  1373. }
  1374. if (node.padding) {
  1375. nodePadding = node.padding;
  1376. }
  1377. node.height = nodeHeight + nodePadding / 2;
  1378. node.width = nodeWidth + nodePadding / 2;
  1379. node.intersect = function(point2) {
  1380. return intersect_default.rect(node, point2);
  1381. };
  1382. return shapeSvg;
  1383. }, "forkJoin");
  1384. // src/rendering-util/rendering-elements/shapes/choice.ts
  1385. import rough7 from "roughjs";
  1386. var choice = /* @__PURE__ */ __name((parent, node) => {
  1387. const { labelStyles, nodeStyles } = styles2String(node);
  1388. node.labelStyle = labelStyles;
  1389. const { themeVariables } = getConfig();
  1390. const { lineColor } = themeVariables;
  1391. const shapeSvg = parent.insert("g").attr("class", "node default").attr("id", node.domId || node.id);
  1392. const s = 28;
  1393. const points = [
  1394. { x: 0, y: s / 2 },
  1395. { x: s / 2, y: 0 },
  1396. { x: 0, y: -s / 2 },
  1397. { x: -s / 2, y: 0 }
  1398. ];
  1399. let choice2;
  1400. if (node.look === "handDrawn") {
  1401. const rc = rough7.svg(shapeSvg);
  1402. const pointArr = points.map(function(d) {
  1403. return [d.x, d.y];
  1404. });
  1405. const roughNode = rc.polygon(pointArr, solidStateFill(lineColor));
  1406. choice2 = shapeSvg.insert(() => roughNode);
  1407. } else {
  1408. choice2 = shapeSvg.insert("polygon", ":first-child").attr(
  1409. "points",
  1410. points.map(function(d) {
  1411. return d.x + "," + d.y;
  1412. }).join(" ")
  1413. );
  1414. }
  1415. choice2.attr("class", "state-start").attr("r", 7).attr("width", 28).attr("height", 28).attr("style", nodeStyles);
  1416. node.width = 28;
  1417. node.height = 28;
  1418. node.intersect = function(point2) {
  1419. return intersect_default.circle(node, 14, point2);
  1420. };
  1421. return shapeSvg;
  1422. }, "choice");
  1423. // src/rendering-util/rendering-elements/shapes/note.ts
  1424. import rough8 from "roughjs";
  1425. var note = /* @__PURE__ */ __name(async (parent, node) => {
  1426. const { themeVariables, handDrawnSeed } = getConfig();
  1427. const { noteBorderColor, noteBkgColor } = themeVariables;
  1428. const useHtmlLabels = node.useHtmlLabels;
  1429. if (!useHtmlLabels) {
  1430. node.centerLabel = true;
  1431. }
  1432. const { shapeSvg, bbox } = await labelHelper(parent, node, "node " + node.cssClasses);
  1433. log.info("Classes = ", node.cssClasses);
  1434. const { cssStyles } = node;
  1435. let rect2;
  1436. const totalWidth = bbox.width + node.padding;
  1437. const totalHeight = bbox.height + node.padding;
  1438. const x = -totalWidth / 2;
  1439. const y = -totalHeight / 2;
  1440. if (node.look === "handDrawn") {
  1441. const rc = rough8.svg(shapeSvg);
  1442. const roughNode = rc.rectangle(x, y, totalWidth, totalHeight, {
  1443. roughness: 0.7,
  1444. fill: noteBkgColor,
  1445. fillWeight: 3,
  1446. seed: handDrawnSeed,
  1447. // fillStyle: 'solid', // solid fill'
  1448. stroke: noteBorderColor
  1449. });
  1450. rect2 = shapeSvg.insert(() => roughNode, ":first-child");
  1451. rect2.attr("class", "basic label-container").attr("style", cssStyles);
  1452. } else {
  1453. rect2 = shapeSvg.insert("rect", ":first-child");
  1454. rect2.attr("rx", node.rx).attr("ry", node.ry).attr("x", x).attr("y", y).attr("width", totalWidth).attr("height", totalHeight);
  1455. }
  1456. updateNodeBounds(node, rect2);
  1457. node.intersect = function(point2) {
  1458. return intersect_default.rect(node, point2);
  1459. };
  1460. return shapeSvg;
  1461. }, "note");
  1462. // src/rendering-util/rendering-elements/shapes/stadium.ts
  1463. import rough9 from "roughjs";
  1464. var stadium = /* @__PURE__ */ __name(async (parent, node) => {
  1465. const { labelStyles, nodeStyles } = styles2String(node);
  1466. node.labelStyle = labelStyles;
  1467. const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node));
  1468. const h = bbox.height + node.padding;
  1469. const w = bbox.width + h / 4 + node.padding;
  1470. let rect2;
  1471. const { cssStyles } = node;
  1472. if (node.look === "handDrawn") {
  1473. const rc = rough9.svg(shapeSvg);
  1474. const options = userNodeOverrides(node, {});
  1475. const pathData = createRoundedRectPathD(-w / 2, -h / 2, w, h, h / 2);
  1476. const roughNode = rc.path(pathData, options);
  1477. rect2 = shapeSvg.insert(() => roughNode, ":first-child");
  1478. rect2.attr("class", "basic label-container").attr("style", cssStyles);
  1479. } else {
  1480. rect2 = shapeSvg.insert("rect", ":first-child");
  1481. rect2.attr("class", "basic label-container").attr("style", nodeStyles).attr("rx", h / 2).attr("ry", h / 2).attr("x", -w / 2).attr("y", -h / 2).attr("width", w).attr("height", h);
  1482. }
  1483. updateNodeBounds(node, rect2);
  1484. node.intersect = function(point2) {
  1485. return intersect_default.rect(node, point2);
  1486. };
  1487. return shapeSvg;
  1488. }, "stadium");
  1489. // src/rendering-util/rendering-elements/shapes/rectWithTitle.ts
  1490. import { select as select5 } from "d3";
  1491. import rough10 from "roughjs";
  1492. var rectWithTitle = /* @__PURE__ */ __name(async (parent, node) => {
  1493. const { labelStyles, nodeStyles } = styles2String(node);
  1494. node.labelStyle = labelStyles;
  1495. let classes;
  1496. if (!node.cssClasses) {
  1497. classes = "node default";
  1498. } else {
  1499. classes = "node " + node.cssClasses;
  1500. }
  1501. const shapeSvg = parent.insert("g").attr("class", classes).attr("id", node.domId || node.id);
  1502. const g = shapeSvg.insert("g");
  1503. const label = shapeSvg.insert("g").attr("class", "label").attr("style", nodeStyles);
  1504. const description = node.description;
  1505. const title = node.label;
  1506. const text = label.node().appendChild(await createLabel_default(title, node.labelStyle, true, true));
  1507. let bbox = { width: 0, height: 0 };
  1508. if (evaluate(getConfig()?.flowchart?.htmlLabels)) {
  1509. const div2 = text.children[0];
  1510. const dv2 = select5(text);
  1511. bbox = div2.getBoundingClientRect();
  1512. dv2.attr("width", bbox.width);
  1513. dv2.attr("height", bbox.height);
  1514. }
  1515. log.info("Text 2", description);
  1516. const textRows = description || [];
  1517. const titleBox = text.getBBox();
  1518. const descr = label.node().appendChild(
  1519. await createLabel_default(
  1520. textRows.join ? textRows.join("<br/>") : textRows,
  1521. node.labelStyle,
  1522. true,
  1523. true
  1524. )
  1525. );
  1526. const div = descr.children[0];
  1527. const dv = select5(descr);
  1528. bbox = div.getBoundingClientRect();
  1529. dv.attr("width", bbox.width);
  1530. dv.attr("height", bbox.height);
  1531. const halfPadding = (node.padding || 0) / 2;
  1532. select5(descr).attr(
  1533. "transform",
  1534. "translate( " + (bbox.width > titleBox.width ? 0 : (titleBox.width - bbox.width) / 2) + ", " + (titleBox.height + halfPadding + 5) + ")"
  1535. );
  1536. select5(text).attr(
  1537. "transform",
  1538. "translate( " + (bbox.width < titleBox.width ? 0 : -(titleBox.width - bbox.width) / 2) + ", 0)"
  1539. );
  1540. bbox = label.node().getBBox();
  1541. label.attr(
  1542. "transform",
  1543. "translate(" + -bbox.width / 2 + ", " + (-bbox.height / 2 - halfPadding + 3) + ")"
  1544. );
  1545. const totalWidth = bbox.width + (node.padding || 0);
  1546. const totalHeight = bbox.height + (node.padding || 0);
  1547. const x = -bbox.width / 2 - halfPadding;
  1548. const y = -bbox.height / 2 - halfPadding;
  1549. let rect2;
  1550. let innerLine;
  1551. if (node.look === "handDrawn") {
  1552. const rc = rough10.svg(shapeSvg);
  1553. const options = userNodeOverrides(node, {});
  1554. const roughNode = rc.path(
  1555. createRoundedRectPathD(x, y, totalWidth, totalHeight, node.rx || 0),
  1556. options
  1557. );
  1558. const roughLine = rc.line(
  1559. -bbox.width / 2 - halfPadding,
  1560. -bbox.height / 2 - halfPadding + titleBox.height + halfPadding,
  1561. bbox.width / 2 + halfPadding,
  1562. -bbox.height / 2 - halfPadding + titleBox.height + halfPadding,
  1563. options
  1564. );
  1565. innerLine = shapeSvg.insert(() => {
  1566. log.debug("Rough node insert CXC", roughNode);
  1567. return roughLine;
  1568. }, ":first-child");
  1569. rect2 = shapeSvg.insert(() => {
  1570. log.debug("Rough node insert CXC", roughNode);
  1571. return roughNode;
  1572. }, ":first-child");
  1573. } else {
  1574. rect2 = g.insert("rect", ":first-child");
  1575. innerLine = g.insert("line");
  1576. rect2.attr("class", "outer title-state").attr("style", nodeStyles).attr("x", -bbox.width / 2 - halfPadding).attr("y", -bbox.height / 2 - halfPadding).attr("width", bbox.width + (node.padding || 0)).attr("height", bbox.height + (node.padding || 0));
  1577. innerLine.attr("class", "divider").attr("x1", -bbox.width / 2 - halfPadding).attr("x2", bbox.width / 2 + halfPadding).attr("y1", -bbox.height / 2 - halfPadding + titleBox.height + halfPadding).attr("y2", -bbox.height / 2 - halfPadding + titleBox.height + halfPadding);
  1578. }
  1579. updateNodeBounds(node, rect2);
  1580. node.intersect = function(point2) {
  1581. return intersect_default.rect(node, point2);
  1582. };
  1583. return shapeSvg;
  1584. }, "rectWithTitle");
  1585. // src/rendering-util/rendering-elements/shapes/subroutine.ts
  1586. import rough11 from "roughjs";
  1587. // src/rendering-util/rendering-elements/shapes/insertPolygonShape.ts
  1588. function insertPolygonShape(parent, w, h, points) {
  1589. return parent.insert("polygon", ":first-child").attr(
  1590. "points",
  1591. points.map(function(d) {
  1592. return d.x + "," + d.y;
  1593. }).join(" ")
  1594. ).attr("class", "label-container").attr("transform", "translate(" + -w / 2 + "," + h / 2 + ")");
  1595. }
  1596. __name(insertPolygonShape, "insertPolygonShape");
  1597. // src/rendering-util/rendering-elements/shapes/subroutine.ts
  1598. var subroutine = /* @__PURE__ */ __name(async (parent, node) => {
  1599. const { labelStyles, nodeStyles } = styles2String(node);
  1600. node.labelStyle = labelStyles;
  1601. const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node));
  1602. const halfPadding = (node?.padding || 0) / 2;
  1603. const w = bbox.width + node.padding;
  1604. const h = bbox.height + node.padding;
  1605. const x = -bbox.width / 2 - halfPadding;
  1606. const y = -bbox.height / 2 - halfPadding;
  1607. const points = [
  1608. { x: 0, y: 0 },
  1609. { x: w, y: 0 },
  1610. { x: w, y: -h },
  1611. { x: 0, y: -h },
  1612. { x: 0, y: 0 },
  1613. { x: -8, y: 0 },
  1614. { x: w + 8, y: 0 },
  1615. { x: w + 8, y: -h },
  1616. { x: -8, y: -h },
  1617. { x: -8, y: 0 }
  1618. ];
  1619. if (node.look === "handDrawn") {
  1620. const rc = rough11.svg(shapeSvg);
  1621. const options = userNodeOverrides(node, {});
  1622. const roughNode = rc.rectangle(x - 8, y, w + 16, h, options);
  1623. const l1 = rc.line(x, y, x, y + h, options);
  1624. const l2 = rc.line(x + w, y, x + w, y + h, options);
  1625. shapeSvg.insert(() => l1, ":first-child");
  1626. shapeSvg.insert(() => l2, ":first-child");
  1627. const rect2 = shapeSvg.insert(() => roughNode, ":first-child");
  1628. const { cssStyles } = node;
  1629. rect2.attr("class", "basic label-container").attr("style", cssStyles);
  1630. updateNodeBounds(node, rect2);
  1631. } else {
  1632. const el = insertPolygonShape(shapeSvg, w, h, points);
  1633. if (nodeStyles) {
  1634. el.attr("style", nodeStyles);
  1635. }
  1636. updateNodeBounds(node, el);
  1637. }
  1638. node.intersect = function(point2) {
  1639. return intersect_default.polygon(node, points, point2);
  1640. };
  1641. return shapeSvg;
  1642. }, "subroutine");
  1643. // src/rendering-util/rendering-elements/shapes/cylinder.ts
  1644. import rough12 from "roughjs";
  1645. var createCylinderPathD = /* @__PURE__ */ __name((x, y, width, height, rx, ry) => {
  1646. return [
  1647. `M${x},${y + ry}`,
  1648. `a${rx},${ry} 0,0,0 ${width},0`,
  1649. `a${rx},${ry} 0,0,0 ${-width},0`,
  1650. `l0,${height}`,
  1651. `a${rx},${ry} 0,0,0 ${width},0`,
  1652. `l0,${-height}`
  1653. ].join(" ");
  1654. }, "createCylinderPathD");
  1655. var createOuterCylinderPathD = /* @__PURE__ */ __name((x, y, width, height, rx, ry) => {
  1656. return [
  1657. `M${x},${y + ry}`,
  1658. `M${x + width},${y + ry}`,
  1659. `a${rx},${ry} 0,0,0 ${-width},0`,
  1660. `l0,${height}`,
  1661. `a${rx},${ry} 0,0,0 ${width},0`,
  1662. `l0,${-height}`
  1663. ].join(" ");
  1664. }, "createOuterCylinderPathD");
  1665. var createInnerCylinderPathD = /* @__PURE__ */ __name((x, y, width, height, rx, ry) => {
  1666. return [`M${x - width / 2},${-height / 2}`, `a${rx},${ry} 0,0,0 ${width},0`].join(" ");
  1667. }, "createInnerCylinderPathD");
  1668. var cylinder = /* @__PURE__ */ __name(async (parent, node) => {
  1669. const { labelStyles, nodeStyles } = styles2String(node);
  1670. node.labelStyle = labelStyles;
  1671. const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node));
  1672. const w = bbox.width + node.padding;
  1673. const rx = w / 2;
  1674. const ry = rx / (2.5 + w / 50);
  1675. const h = bbox.height + ry + node.padding;
  1676. let cylinder2;
  1677. const { cssStyles } = node;
  1678. if (node.look === "handDrawn") {
  1679. const rc = rough12.svg(shapeSvg);
  1680. const outerPathData = createOuterCylinderPathD(0, 0, w, h, rx, ry);
  1681. const innerPathData = createInnerCylinderPathD(0, ry, w, h, rx, ry);
  1682. const outerNode = rc.path(outerPathData, userNodeOverrides(node, {}));
  1683. const innerLine = rc.path(innerPathData, userNodeOverrides(node, { fill: "none" }));
  1684. cylinder2 = shapeSvg.insert(() => innerLine, ":first-child");
  1685. cylinder2 = shapeSvg.insert(() => outerNode, ":first-child");
  1686. cylinder2.attr("class", "basic label-container");
  1687. if (cssStyles) {
  1688. cylinder2.attr("style", cssStyles);
  1689. }
  1690. } else {
  1691. const pathData = createCylinderPathD(0, 0, w, h, rx, ry);
  1692. cylinder2 = shapeSvg.insert("path", ":first-child").attr("d", pathData).attr("class", "basic label-container").attr("style", cssStyles).attr("style", nodeStyles);
  1693. }
  1694. cylinder2.attr("label-offset-y", ry);
  1695. cylinder2.attr("transform", `translate(${-w / 2}, ${-(h / 2 + ry)})`);
  1696. updateNodeBounds(node, cylinder2);
  1697. node.intersect = function(point2) {
  1698. const pos = intersect_default.rect(node, point2);
  1699. const x = pos.x - (node.x ?? 0);
  1700. if (rx != 0 && (Math.abs(x) < (node.width ?? 0) / 2 || Math.abs(x) == (node.width ?? 0) / 2 && Math.abs(pos.y - (node.y ?? 0)) > (node.height ?? 0) / 2 - ry)) {
  1701. let y = ry * ry * (1 - x * x / (rx * rx));
  1702. if (y > 0) {
  1703. y = Math.sqrt(y);
  1704. }
  1705. y = ry - y;
  1706. if (point2.y - (node.y ?? 0) > 0) {
  1707. y = -y;
  1708. }
  1709. pos.y += y;
  1710. }
  1711. return pos;
  1712. };
  1713. return shapeSvg;
  1714. }, "cylinder");
  1715. // src/rendering-util/rendering-elements/shapes/circle.ts
  1716. import rough13 from "roughjs";
  1717. var circle2 = /* @__PURE__ */ __name(async (parent, node) => {
  1718. const { labelStyles, nodeStyles } = styles2String(node);
  1719. node.labelStyle = labelStyles;
  1720. const { shapeSvg, bbox, halfPadding } = await labelHelper(parent, node, getNodeClasses(node));
  1721. const radius = bbox.width / 2 + halfPadding;
  1722. let circleElem;
  1723. const { cssStyles } = node;
  1724. if (node.look === "handDrawn") {
  1725. const rc = rough13.svg(shapeSvg);
  1726. const options = userNodeOverrides(node, {});
  1727. const roughNode = rc.circle(0, 0, radius * 2, options);
  1728. circleElem = shapeSvg.insert(() => roughNode, ":first-child");
  1729. circleElem.attr("class", "basic label-container").attr("style", cssStyles);
  1730. } else {
  1731. circleElem = shapeSvg.insert("circle", ":first-child").attr("class", "basic label-container").attr("style", nodeStyles).attr("r", radius).attr("cx", 0).attr("cy", 0);
  1732. }
  1733. updateNodeBounds(node, circleElem);
  1734. node.intersect = function(point2) {
  1735. log.info("Circle intersect", node, radius, point2);
  1736. return intersect_default.circle(node, radius, point2);
  1737. };
  1738. return shapeSvg;
  1739. }, "circle");
  1740. // src/rendering-util/rendering-elements/shapes/doubleCircle.ts
  1741. import rough14 from "roughjs";
  1742. var doublecircle = /* @__PURE__ */ __name(async (parent, node) => {
  1743. const { labelStyles, nodeStyles } = styles2String(node);
  1744. node.labelStyle = labelStyles;
  1745. const { shapeSvg, bbox, halfPadding } = await labelHelper(parent, node, getNodeClasses(node));
  1746. const gap = 5;
  1747. const outerRadius = bbox.width / 2 + halfPadding + gap;
  1748. const innerRadius = bbox.width / 2 + halfPadding;
  1749. let circleGroup;
  1750. const { cssStyles } = node;
  1751. if (node.look === "handDrawn") {
  1752. const rc = rough14.svg(shapeSvg);
  1753. const outerOptions = userNodeOverrides(node, { roughness: 0.2, strokeWidth: 2.5 });
  1754. const innerOptions = userNodeOverrides(node, { roughness: 0.2, strokeWidth: 1.5 });
  1755. const outerRoughNode = rc.circle(0, 0, outerRadius * 2, outerOptions);
  1756. const innerRoughNode = rc.circle(0, 0, innerRadius * 2, innerOptions);
  1757. circleGroup = shapeSvg.insert("g", ":first-child");
  1758. circleGroup.attr("class", node.cssClasses).attr("style", cssStyles);
  1759. circleGroup.node()?.appendChild(outerRoughNode);
  1760. circleGroup.node()?.appendChild(innerRoughNode);
  1761. } else {
  1762. circleGroup = shapeSvg.insert("g", ":first-child");
  1763. const outerCircle = circleGroup.insert("circle", ":first-child");
  1764. const innerCircle = circleGroup.insert("circle");
  1765. circleGroup.attr("class", "basic label-container").attr("style", nodeStyles);
  1766. outerCircle.attr("class", "outer-circle").attr("style", nodeStyles).attr("r", outerRadius).attr("cx", 0).attr("cy", 0);
  1767. innerCircle.attr("class", "inner-circle").attr("style", nodeStyles).attr("r", innerRadius).attr("cx", 0).attr("cy", 0);
  1768. }
  1769. updateNodeBounds(node, circleGroup);
  1770. node.intersect = function(point2) {
  1771. log.info("DoubleCircle intersect", node, outerRadius, point2);
  1772. return intersect_default.circle(node, outerRadius, point2);
  1773. };
  1774. return shapeSvg;
  1775. }, "doublecircle");
  1776. // src/rendering-util/rendering-elements/shapes/rectLeftInvArrow.ts
  1777. import rough15 from "roughjs";
  1778. var createPolygonPathD = /* @__PURE__ */ __name((x, y, width, height) => {
  1779. return [
  1780. `M${x - height / 2},${y}`,
  1781. `L${x + width},${y}`,
  1782. `L${x + width},${y - height}`,
  1783. `L${x - height / 2},${y - height}`,
  1784. `L${x},${y - height / 2}`,
  1785. "Z"
  1786. ].join(" ");
  1787. }, "createPolygonPathD");
  1788. var rect_left_inv_arrow = /* @__PURE__ */ __name(async (parent, node) => {
  1789. const { labelStyles, nodeStyles } = styles2String(node);
  1790. node.labelStyle = labelStyles;
  1791. const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node));
  1792. const w = bbox.width + node.padding;
  1793. const h = bbox.height + node.padding;
  1794. const points = [
  1795. { x: -h / 2, y: 0 },
  1796. { x: w, y: 0 },
  1797. { x: w, y: -h },
  1798. { x: -h / 2, y: -h },
  1799. { x: 0, y: -h / 2 }
  1800. ];
  1801. let polygon;
  1802. const { cssStyles } = node;
  1803. if (node.look === "handDrawn") {
  1804. const rc = rough15.svg(shapeSvg);
  1805. const options = userNodeOverrides(node, {});
  1806. const pathData = createPolygonPathD(0, 0, w, h);
  1807. const roughNode = rc.path(pathData, options);
  1808. polygon = shapeSvg.insert(() => roughNode, ":first-child").attr("transform", `translate(${-w / 2}, ${h / 2})`);
  1809. if (cssStyles) {
  1810. polygon.attr("style", cssStyles);
  1811. }
  1812. } else {
  1813. polygon = insertPolygonShape(shapeSvg, w, h, points);
  1814. }
  1815. if (nodeStyles) {
  1816. polygon.attr("style", nodeStyles);
  1817. }
  1818. node.width = w + h;
  1819. node.height = h;
  1820. updateNodeBounds(node, polygon);
  1821. node.intersect = function(point2) {
  1822. return intersect_default.polygon(node, points, point2);
  1823. };
  1824. return shapeSvg;
  1825. }, "rect_left_inv_arrow");
  1826. // src/rendering-util/rendering-elements/shapes/question.ts
  1827. import rough16 from "roughjs";
  1828. var createDecisionBoxPathD = /* @__PURE__ */ __name((x, y, size) => {
  1829. return [
  1830. `M${x + size / 2},${y}`,
  1831. `L${x + size},${y - size / 2}`,
  1832. `L${x + size / 2},${y - size}`,
  1833. `L${x},${y - size / 2}`,
  1834. "Z"
  1835. ].join(" ");
  1836. }, "createDecisionBoxPathD");
  1837. var question = /* @__PURE__ */ __name(async (parent, node) => {
  1838. const { labelStyles, nodeStyles } = styles2String(node);
  1839. node.labelStyle = labelStyles;
  1840. const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node));
  1841. const w = bbox.width + node.padding;
  1842. const h = bbox.height + node.padding;
  1843. const s = w + h;
  1844. const points = [
  1845. { x: s / 2, y: 0 },
  1846. { x: s, y: -s / 2 },
  1847. { x: s / 2, y: -s },
  1848. { x: 0, y: -s / 2 }
  1849. ];
  1850. let polygon;
  1851. const { cssStyles } = node;
  1852. if (node.look === "handDrawn") {
  1853. const rc = rough16.svg(shapeSvg);
  1854. const options = userNodeOverrides(node, {});
  1855. const pathData = createDecisionBoxPathD(0, 0, s);
  1856. const roughNode = rc.path(pathData, options);
  1857. polygon = shapeSvg.insert(() => roughNode, ":first-child").attr("transform", `translate(${-s / 2}, ${s / 2})`);
  1858. if (cssStyles) {
  1859. polygon.attr("style", cssStyles);
  1860. }
  1861. } else {
  1862. polygon = insertPolygonShape(shapeSvg, s, s, points);
  1863. }
  1864. if (nodeStyles) {
  1865. polygon.attr("style", nodeStyles);
  1866. }
  1867. updateNodeBounds(node, polygon);
  1868. node.intersect = function(point2) {
  1869. log.debug(
  1870. "APA12 Intersect called SPLIT\npoint:",
  1871. point2,
  1872. "\nnode:\n",
  1873. node,
  1874. "\nres:",
  1875. intersect_default.polygon(node, points, point2)
  1876. );
  1877. return intersect_default.polygon(node, points, point2);
  1878. };
  1879. return shapeSvg;
  1880. }, "question");
  1881. // src/rendering-util/rendering-elements/shapes/hexagon.ts
  1882. import rough17 from "roughjs";
  1883. var createHexagonPathD = /* @__PURE__ */ __name((x, y, width, height, m) => {
  1884. return [
  1885. `M${x + m},${y}`,
  1886. `L${x + width - m},${y}`,
  1887. `L${x + width},${y - height / 2}`,
  1888. `L${x + width - m},${y - height}`,
  1889. `L${x + m},${y - height}`,
  1890. `L${x},${y - height / 2}`,
  1891. "Z"
  1892. ].join(" ");
  1893. }, "createHexagonPathD");
  1894. var hexagon = /* @__PURE__ */ __name(async (parent, node) => {
  1895. const { labelStyles, nodeStyles } = styles2String(node);
  1896. node.labelStyle = labelStyles;
  1897. const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node));
  1898. const f = 4;
  1899. const h = bbox.height + node.padding;
  1900. const m = h / f;
  1901. const w = bbox.width + 2 * m + node.padding;
  1902. const points = [
  1903. { x: m, y: 0 },
  1904. { x: w - m, y: 0 },
  1905. { x: w, y: -h / 2 },
  1906. { x: w - m, y: -h },
  1907. { x: m, y: -h },
  1908. { x: 0, y: -h / 2 }
  1909. ];
  1910. let polygon;
  1911. const { cssStyles } = node;
  1912. if (node.look === "handDrawn") {
  1913. const rc = rough17.svg(shapeSvg);
  1914. const options = userNodeOverrides(node, {});
  1915. const pathData = createHexagonPathD(0, 0, w, h, m);
  1916. const roughNode = rc.path(pathData, options);
  1917. polygon = shapeSvg.insert(() => roughNode, ":first-child").attr("transform", `translate(${-w / 2}, ${h / 2})`);
  1918. if (cssStyles) {
  1919. polygon.attr("style", cssStyles);
  1920. }
  1921. } else {
  1922. polygon = insertPolygonShape(shapeSvg, w, h, points);
  1923. }
  1924. if (nodeStyles) {
  1925. polygon.attr("style", nodeStyles);
  1926. }
  1927. node.width = w;
  1928. node.height = h;
  1929. updateNodeBounds(node, polygon);
  1930. node.intersect = function(point2) {
  1931. return intersect_default.polygon(node, points, point2);
  1932. };
  1933. return shapeSvg;
  1934. }, "hexagon");
  1935. // src/rendering-util/rendering-elements/shapes/leanRight.ts
  1936. import rough18 from "roughjs";
  1937. var createLeanRightPathD = /* @__PURE__ */ __name((x, y, width, height) => {
  1938. return [
  1939. `M${x - 2 * height / 6},${y}`,
  1940. `L${x + width - height / 6},${y}`,
  1941. `L${x + width + 2 * height / 6},${y - height}`,
  1942. `L${x + height / 6},${y - height}`,
  1943. "Z"
  1944. ].join(" ");
  1945. }, "createLeanRightPathD");
  1946. var lean_right = /* @__PURE__ */ __name(async (parent, node) => {
  1947. const { labelStyles, nodeStyles } = styles2String(node);
  1948. node.labelStyle = labelStyles;
  1949. const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node));
  1950. const w = bbox.width + node.padding;
  1951. const h = bbox.height + node.padding;
  1952. const points = [
  1953. { x: -2 * h / 6, y: 0 },
  1954. { x: w - h / 6, y: 0 },
  1955. { x: w + 2 * h / 6, y: -h },
  1956. { x: h / 6, y: -h }
  1957. ];
  1958. let polygon;
  1959. const { cssStyles } = node;
  1960. if (node.look === "handDrawn") {
  1961. const rc = rough18.svg(shapeSvg);
  1962. const options = userNodeOverrides(node, {});
  1963. const pathData = createLeanRightPathD(0, 0, w, h);
  1964. const roughNode = rc.path(pathData, options);
  1965. polygon = shapeSvg.insert(() => roughNode, ":first-child").attr("transform", `translate(${-w / 2}, ${h / 2})`);
  1966. if (cssStyles) {
  1967. polygon.attr("style", cssStyles);
  1968. }
  1969. } else {
  1970. polygon = insertPolygonShape(shapeSvg, w, h, points);
  1971. }
  1972. if (nodeStyles) {
  1973. polygon.attr("style", nodeStyles);
  1974. }
  1975. node.width = w;
  1976. node.height = h;
  1977. updateNodeBounds(node, polygon);
  1978. node.intersect = function(point2) {
  1979. return intersect_default.polygon(node, points, point2);
  1980. };
  1981. return shapeSvg;
  1982. }, "lean_right");
  1983. // src/rendering-util/rendering-elements/shapes/leanLeft.ts
  1984. import rough19 from "roughjs";
  1985. var createLeanLeftPathD = /* @__PURE__ */ __name((x, y, width, height) => {
  1986. return [
  1987. `M${x + 2 * height / 6},${y}`,
  1988. `L${x + width + height / 6},${y}`,
  1989. `L${x + width - 2 * height / 6},${y - height}`,
  1990. `L${x - height / 6},${y - height}`,
  1991. "Z"
  1992. ].join(" ");
  1993. }, "createLeanLeftPathD");
  1994. var lean_left = /* @__PURE__ */ __name(async (parent, node) => {
  1995. const { labelStyles, nodeStyles } = styles2String(node);
  1996. node.labelStyle = labelStyles;
  1997. const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node));
  1998. const w = bbox.width + node.padding;
  1999. const h = bbox.height + node.padding;
  2000. const points = [
  2001. { x: 2 * h / 6, y: 0 },
  2002. { x: w + h / 6, y: 0 },
  2003. { x: w - 2 * h / 6, y: -h },
  2004. { x: -h / 6, y: -h }
  2005. ];
  2006. let polygon;
  2007. const { cssStyles } = node;
  2008. if (node.look === "handDrawn") {
  2009. const rc = rough19.svg(shapeSvg);
  2010. const options = userNodeOverrides(node, {});
  2011. const pathData = createLeanLeftPathD(0, 0, w, h);
  2012. const roughNode = rc.path(pathData, options);
  2013. polygon = shapeSvg.insert(() => roughNode, ":first-child").attr("transform", `translate(${-w / 2}, ${h / 2})`);
  2014. if (cssStyles) {
  2015. polygon.attr("style", cssStyles);
  2016. }
  2017. } else {
  2018. polygon = insertPolygonShape(shapeSvg, w, h, points);
  2019. }
  2020. if (nodeStyles) {
  2021. polygon.attr("style", nodeStyles);
  2022. }
  2023. node.width = w;
  2024. node.height = h;
  2025. updateNodeBounds(node, polygon);
  2026. node.intersect = function(point2) {
  2027. return intersect_default.polygon(node, points, point2);
  2028. };
  2029. return shapeSvg;
  2030. }, "lean_left");
  2031. // src/rendering-util/rendering-elements/shapes/trapezoid.ts
  2032. import rough20 from "roughjs";
  2033. var createTrapezoidPathD = /* @__PURE__ */ __name((x, y, width, height) => {
  2034. return [
  2035. `M${x - 2 * height / 6},${y}`,
  2036. `L${x + width + 2 * height / 6},${y}`,
  2037. `L${x + width - height / 6},${y - height}`,
  2038. `L${x + height / 6},${y - height}`,
  2039. "Z"
  2040. ].join(" ");
  2041. }, "createTrapezoidPathD");
  2042. var trapezoid = /* @__PURE__ */ __name(async (parent, node) => {
  2043. const { labelStyles, nodeStyles } = styles2String(node);
  2044. node.labelStyle = labelStyles;
  2045. const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node));
  2046. const w = bbox.width + node.padding;
  2047. const h = bbox.height + node.padding;
  2048. const points = [
  2049. { x: -2 * h / 6, y: 0 },
  2050. { x: w + 2 * h / 6, y: 0 },
  2051. { x: w - h / 6, y: -h },
  2052. { x: h / 6, y: -h }
  2053. ];
  2054. let polygon;
  2055. const { cssStyles } = node;
  2056. if (node.look === "handDrawn") {
  2057. const rc = rough20.svg(shapeSvg);
  2058. const options = userNodeOverrides(node, {});
  2059. const pathData = createTrapezoidPathD(0, 0, w, h);
  2060. const roughNode = rc.path(pathData, options);
  2061. polygon = shapeSvg.insert(() => roughNode, ":first-child").attr("transform", `translate(${-w / 2}, ${h / 2})`);
  2062. if (cssStyles) {
  2063. polygon.attr("style", cssStyles);
  2064. }
  2065. } else {
  2066. polygon = insertPolygonShape(shapeSvg, w, h, points);
  2067. }
  2068. if (nodeStyles) {
  2069. polygon.attr("style", nodeStyles);
  2070. }
  2071. node.width = w;
  2072. node.height = h;
  2073. updateNodeBounds(node, polygon);
  2074. node.intersect = function(point2) {
  2075. return intersect_default.polygon(node, points, point2);
  2076. };
  2077. return shapeSvg;
  2078. }, "trapezoid");
  2079. // src/rendering-util/rendering-elements/shapes/invertedTrapezoid.ts
  2080. import rough21 from "roughjs";
  2081. var createInvertedTrapezoidPathD = /* @__PURE__ */ __name((x, y, width, height) => {
  2082. return [
  2083. `M${x + height / 6},${y}`,
  2084. `L${x + width - height / 6},${y}`,
  2085. `L${x + width + 2 * height / 6},${y - height}`,
  2086. `L${x - 2 * height / 6},${y - height}`,
  2087. "Z"
  2088. ].join(" ");
  2089. }, "createInvertedTrapezoidPathD");
  2090. var inv_trapezoid = /* @__PURE__ */ __name(async (parent, node) => {
  2091. const { labelStyles, nodeStyles } = styles2String(node);
  2092. node.labelStyle = labelStyles;
  2093. const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node));
  2094. const w = bbox.width + node.padding;
  2095. const h = bbox.height + node.padding;
  2096. const points = [
  2097. { x: h / 6, y: 0 },
  2098. { x: w - h / 6, y: 0 },
  2099. { x: w + 2 * h / 6, y: -h },
  2100. { x: -2 * h / 6, y: -h }
  2101. ];
  2102. let polygon;
  2103. const { cssStyles } = node;
  2104. if (node.look === "handDrawn") {
  2105. const rc = rough21.svg(shapeSvg);
  2106. const options = userNodeOverrides(node, {});
  2107. const pathData = createInvertedTrapezoidPathD(0, 0, w, h);
  2108. const roughNode = rc.path(pathData, options);
  2109. polygon = shapeSvg.insert(() => roughNode, ":first-child").attr("transform", `translate(${-w / 2}, ${h / 2})`);
  2110. if (cssStyles) {
  2111. polygon.attr("style", cssStyles);
  2112. }
  2113. } else {
  2114. polygon = insertPolygonShape(shapeSvg, w, h, points);
  2115. }
  2116. if (nodeStyles) {
  2117. polygon.attr("style", nodeStyles);
  2118. }
  2119. node.width = w;
  2120. node.height = h;
  2121. updateNodeBounds(node, polygon);
  2122. node.intersect = function(point2) {
  2123. return intersect_default.polygon(node, points, point2);
  2124. };
  2125. return shapeSvg;
  2126. }, "inv_trapezoid");
  2127. // src/rendering-util/rendering-elements/shapes/labelRect.ts
  2128. var labelRect = /* @__PURE__ */ __name(async (parent, node) => {
  2129. const { shapeSvg } = await labelHelper(parent, node, "label");
  2130. const rect2 = shapeSvg.insert("rect", ":first-child");
  2131. const totalWidth = 0.1;
  2132. const totalHeight = 0.1;
  2133. rect2.attr("width", totalWidth).attr("height", totalHeight);
  2134. shapeSvg.attr("class", "label edgeLabel");
  2135. updateNodeBounds(node, rect2);
  2136. node.intersect = function(point2) {
  2137. return intersect_default.rect(node, point2);
  2138. };
  2139. return shapeSvg;
  2140. }, "labelRect");
  2141. // src/rendering-util/rendering-elements/nodes.js
  2142. var shapes2 = {
  2143. state,
  2144. stateStart,
  2145. stateEnd,
  2146. fork: forkJoin,
  2147. join: forkJoin,
  2148. choice,
  2149. note,
  2150. roundedRect,
  2151. rectWithTitle,
  2152. squareRect: squareRect2,
  2153. stadium,
  2154. subroutine,
  2155. cylinder,
  2156. circle: circle2,
  2157. doublecircle,
  2158. odd: rect_left_inv_arrow,
  2159. diamond: question,
  2160. hexagon,
  2161. lean_right,
  2162. lean_left,
  2163. trapezoid,
  2164. inv_trapezoid,
  2165. labelRect
  2166. };
  2167. var nodeElems = /* @__PURE__ */ new Map();
  2168. var insertNode = /* @__PURE__ */ __name(async (elem, node, dir) => {
  2169. let newEl;
  2170. let el;
  2171. if (node.shape === "rect") {
  2172. if (node.rx && node.ry) {
  2173. node.shape = "roundedRect";
  2174. } else {
  2175. node.shape = "squareRect";
  2176. }
  2177. }
  2178. if (node.link) {
  2179. let target;
  2180. if (getConfig().securityLevel === "sandbox") {
  2181. target = "_top";
  2182. } else if (node.linkTarget) {
  2183. target = node.linkTarget || "_blank";
  2184. }
  2185. newEl = elem.insert("svg:a").attr("xlink:href", node.link).attr("target", target);
  2186. el = await shapes2[node.shape](newEl, node, dir);
  2187. } else {
  2188. el = await shapes2[node.shape](elem, node, dir);
  2189. newEl = el;
  2190. }
  2191. if (node.tooltip) {
  2192. el.attr("title", node.tooltip);
  2193. }
  2194. nodeElems.set(node.id, newEl);
  2195. if (node.haveCallback) {
  2196. nodeElems.get(node.id).attr("class", nodeElems.get(node.id).attr("class") + " clickable");
  2197. }
  2198. return newEl;
  2199. }, "insertNode");
  2200. var setNodeElem = /* @__PURE__ */ __name((elem, node) => {
  2201. nodeElems.set(node.id, elem);
  2202. }, "setNodeElem");
  2203. var clear3 = /* @__PURE__ */ __name(() => {
  2204. nodeElems.clear();
  2205. }, "clear");
  2206. var positionNode = /* @__PURE__ */ __name((node) => {
  2207. const el = nodeElems.get(node.id);
  2208. log.trace(
  2209. "Transforming node",
  2210. node.diff,
  2211. node,
  2212. "translate(" + (node.x - node.width / 2 - 5) + ", " + node.width / 2 + ")"
  2213. );
  2214. const padding = 8;
  2215. const diff = node.diff || 0;
  2216. if (node.clusterNode) {
  2217. el.attr(
  2218. "transform",
  2219. "translate(" + (node.x + diff - node.width / 2) + ", " + (node.y - node.height / 2 - padding) + ")"
  2220. );
  2221. } else {
  2222. el.attr("transform", "translate(" + node.x + ", " + node.y + ")");
  2223. }
  2224. return diff;
  2225. }, "positionNode");
  2226. export {
  2227. insertCluster,
  2228. clear,
  2229. clear2,
  2230. insertEdgeLabel,
  2231. positionEdgeLabel,
  2232. insertEdge,
  2233. markers_default,
  2234. labelHelper,
  2235. updateNodeBounds,
  2236. insertNode,
  2237. setNodeElem,
  2238. clear3,
  2239. positionNode
  2240. };