likec4 1.56.0 → 1.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/__app__/codegen/react.mjs +7 -8
  2. package/__app__/codegen/webcomponent.mjs +77 -736
  3. package/__app__/src/aichat/index.mjs +8 -0
  4. package/__app__/src/chunks/AIChat.mjs +959 -0
  5. package/__app__/src/chunks/DiagramActorProvider.mjs +7638 -0
  6. package/__app__/src/chunks/LikeC4Styles.mjs +1866 -0
  7. package/__app__/src/chunks/Markdown.mjs +146 -0
  8. package/__app__/src/chunks/NavigationPanel.mjs +61 -0
  9. package/__app__/src/chunks/ProjectsOverview.mjs +540 -0
  10. package/__app__/src/chunks/adhoc-editor.mjs +3386 -0
  11. package/__app__/src/chunks/es.mjs +439 -0
  12. package/__app__/src/chunks/hooks.mjs +145 -0
  13. package/__app__/src/chunks/libs/@dagrejs/dagre.mjs +1894 -0
  14. package/__app__/src/chunks/libs/@floating-ui.mjs +2218 -0
  15. package/__app__/src/chunks/libs/@mantine.mjs +12070 -0
  16. package/__app__/src/chunks/libs/@tabler/icons-react.mjs +252 -0
  17. package/__app__/src/chunks/libs/@tanstack-ai.mjs +1768 -0
  18. package/__app__/src/chunks/libs/@tanstack.mjs +2718 -0
  19. package/__app__/src/chunks/libs/@xstate/react.mjs +1982 -0
  20. package/__app__/src/chunks/libs/@xyflow/react.mjs +5256 -0
  21. package/__app__/src/chunks/libs/bezier-js.mjs +1003 -0
  22. package/__app__/src/chunks/libs/d3.mjs +2842 -0
  23. package/__app__/src/chunks/libs/fast-equals.mjs +268 -0
  24. package/__app__/src/chunks/libs/framer.mjs +5872 -0
  25. package/__app__/src/chunks/libs/remeda.mjs +642 -0
  26. package/__app__/src/chunks/libs/zod.mjs +3170 -0
  27. package/__app__/src/chunks/rolldown-runtime.mjs +23 -0
  28. package/__app__/src/chunks/styled-system.mjs +1040 -0
  29. package/__app__/src/fonts.css +1 -1
  30. package/__app__/src/main.mjs +14847 -1
  31. package/__app__/src/style.css +1 -1
  32. package/config/schema.json +14 -41
  33. package/dist/chunks/enableServer.mjs +1 -0
  34. package/dist/chunks/filenames.mjs +2 -2
  35. package/dist/chunks/index2.d.mts +2057 -722
  36. package/dist/chunks/libs/@chevrotain/gast.mjs +1 -1
  37. package/dist/chunks/libs/@logtape/logtape.mjs +4 -3
  38. package/dist/chunks/libs/@ts-graphviz/ast.mjs +3 -0
  39. package/dist/chunks/libs/@ts-graphviz/common.d.mts +9 -0
  40. package/dist/chunks/libs/@ts-graphviz/core.mjs +1 -0
  41. package/dist/chunks/libs/chevrotain-allstar.mjs +2 -2
  42. package/dist/chunks/libs/chevrotain.mjs +26 -26
  43. package/dist/chunks/libs/langium.d.mts +5 -5
  44. package/dist/chunks/libs/langium.mjs +10 -10
  45. package/dist/chunks/libs/merge-error-cause.mjs +1 -1
  46. package/dist/chunks/libs/pako.mjs +3 -1
  47. package/dist/chunks/libs/pretty-ms.mjs +1 -1
  48. package/dist/chunks/libs/remeda.mjs +1 -1
  49. package/dist/chunks/libs/ufo.mjs +1 -1
  50. package/dist/chunks/libs/unstorage.mjs +1 -1
  51. package/dist/chunks/libs/which.mjs +1 -1
  52. package/dist/chunks/libs/zod.d.mts +60 -25
  53. package/dist/chunks/libs/zod.mjs +65 -0
  54. package/dist/chunks/node.mjs +84 -56
  55. package/dist/chunks/sequence-view.mjs +1 -1
  56. package/dist/chunks/vite-plugin.mjs +593 -0
  57. package/dist/cli/index.mjs +184 -141
  58. package/dist/index.d.mts +2 -131
  59. package/dist/index.mjs +1 -1
  60. package/dist/model/index.d.mts +2 -2
  61. package/dist/vite-plugin/index.d.mts +53 -2
  62. package/dist/vite-plugin/index.mjs +1 -1
  63. package/dist/vite-plugin/internal/index.d.mts +327 -4
  64. package/dist/vite-plugin/internal/index.mjs +946 -1
  65. package/package.json +85 -72
  66. package/react/index.d.mts +174 -73
  67. package/react/index.mjs +42468 -38926
  68. package/vite-plugin-modules.d.ts +4 -0
  69. package/__app__/chunks/ColorSchemeToggle.mjs +0 -1
  70. package/__app__/chunks/DiagramActorProvider.mjs +0 -10
  71. package/__app__/chunks/Fallback.mjs +0 -1
  72. package/__app__/chunks/Header.mjs +0 -13
  73. package/__app__/chunks/IconRenderer.mjs +0 -1
  74. package/__app__/chunks/LikeC4Diagram.mjs +0 -19
  75. package/__app__/chunks/LikeC4ModelContext.mjs +0 -1
  76. package/__app__/chunks/LikeC4ModelContext2.mjs +0 -1
  77. package/__app__/chunks/LikeC4Styles.mjs +0 -48
  78. package/__app__/chunks/NavigationPanel.mjs +0 -1
  79. package/__app__/chunks/StaticLikeC4Diagram.mjs +0 -1
  80. package/__app__/chunks/ViewReact.mjs +0 -1
  81. package/__app__/chunks/__root.mjs +0 -1
  82. package/__app__/chunks/adhoc-editor.mjs +0 -1
  83. package/__app__/chunks/hooks.mjs +0 -1
  84. package/__app__/chunks/libs/@dagrejs/dagre.mjs +0 -1
  85. package/__app__/chunks/libs/@floating-ui/core.mjs +0 -1
  86. package/__app__/chunks/libs/@floating-ui/dom.mjs +0 -1
  87. package/__app__/chunks/libs/@floating-ui/react.mjs +0 -1
  88. package/__app__/chunks/libs/@mantine/core.mjs +0 -41
  89. package/__app__/chunks/libs/@mantine/hooks.mjs +0 -1
  90. package/__app__/chunks/libs/@nanostores/react.mjs +0 -1
  91. package/__app__/chunks/libs/@react-hookz/web.mjs +0 -1
  92. package/__app__/chunks/libs/@tabler/icons-react.mjs +0 -15
  93. package/__app__/chunks/libs/@tanstack/history.mjs +0 -1
  94. package/__app__/chunks/libs/@tanstack/react-router.mjs +0 -3
  95. package/__app__/chunks/libs/@tanstack/router-core.mjs +0 -1
  96. package/__app__/chunks/libs/@xstate/react.mjs +0 -1
  97. package/__app__/chunks/libs/@xstate/store.mjs +0 -1
  98. package/__app__/chunks/libs/@xyflow/react.mjs +0 -7
  99. package/__app__/chunks/libs/@zag-js/anatomy.mjs +0 -1
  100. package/__app__/chunks/libs/@zag-js/collection.mjs +0 -1
  101. package/__app__/chunks/libs/@zag-js/core.mjs +0 -1
  102. package/__app__/chunks/libs/@zag-js/react.mjs +0 -1
  103. package/__app__/chunks/libs/@zag-js/tree-view.mjs +0 -1
  104. package/__app__/chunks/libs/bezier-js.mjs +0 -1
  105. package/__app__/chunks/libs/d3-path.mjs +0 -1
  106. package/__app__/chunks/libs/d3-shape.mjs +0 -1
  107. package/__app__/chunks/libs/fast-equals.mjs +0 -1
  108. package/__app__/chunks/libs/framer-motion.mjs +0 -9
  109. package/__app__/chunks/libs/html-to-image.mjs +0 -2
  110. package/__app__/chunks/libs/motion-dom.mjs +0 -1
  111. package/__app__/chunks/libs/motion.mjs +0 -1
  112. package/__app__/chunks/libs/nanostores.mjs +0 -1
  113. package/__app__/chunks/libs/react-error-boundary.mjs +0 -1
  114. package/__app__/chunks/libs/react-resizable-panels.mjs +0 -1
  115. package/__app__/chunks/libs/remeda.mjs +0 -1
  116. package/__app__/chunks/libs/xstate.mjs +0 -1
  117. package/__app__/chunks/libs/zod.mjs +0 -39
  118. package/__app__/chunks/rolldown-runtime.mjs +0 -1
  119. package/__app__/chunks/safeCtx.mjs +0 -1
  120. package/__app__/chunks/searchParams.mjs +0 -1
  121. package/__app__/chunks/single-index.mjs +0 -1
  122. package/__app__/chunks/styled-system.mjs +0 -1
  123. package/__app__/chunks/styles.css.mjs +0 -1
  124. package/__app__/chunks/useLikeC4Project.mjs +0 -1
  125. package/__app__/chunks/useUpdateEffect.mjs +0 -1
  126. package/__app__/src/pages/AdHocViewEditor.mjs +0 -1
  127. package/__app__/src/pages/EmbedPage.mjs +0 -1
  128. package/__app__/src/pages/ExportPage.mjs +0 -1
  129. package/__app__/src/pages/ProjectsOverview.mjs +0 -1
  130. package/__app__/src/pages/ViewAsD2.mjs +0 -1
  131. package/__app__/src/pages/ViewAsDot.mjs +0 -1
  132. package/__app__/src/pages/ViewAsMmd.mjs +0 -1
  133. package/__app__/src/pages/ViewAsPuml.mjs +0 -1
  134. package/__app__/src/pages/ViewEditor.mjs +0 -1
  135. package/__app__/src/pages/ViewReact.mjs +0 -1
  136. package/__app__/src/routeTree.gen.mjs +0 -1
  137. package/__app__/src/routes/__root.mjs +0 -1
  138. package/__app__/src/routes/_single/adhoc.mjs +0 -1
  139. package/__app__/src/routes/_single/embed._viewId.mjs +0 -1
  140. package/__app__/src/routes/_single/export._viewId.mjs +0 -1
  141. package/__app__/src/routes/_single/route.mjs +0 -1
  142. package/__app__/src/routes/_single/single-index.mjs +0 -1
  143. package/__app__/src/routes/_single/view._viewId.d2.mjs +0 -1
  144. package/__app__/src/routes/_single/view._viewId.dot.mjs +0 -1
  145. package/__app__/src/routes/_single/view._viewId.index.mjs +0 -1
  146. package/__app__/src/routes/_single/view._viewId.mjs +0 -1
  147. package/__app__/src/routes/_single/view._viewId.mmd.mjs +0 -1
  148. package/__app__/src/routes/_single/view._viewId.puml.mjs +0 -1
  149. package/__app__/src/routes/_single/webcomponent._.mjs +0 -33
  150. package/__app__/src/routes/index.mjs +0 -1
  151. package/__app__/src/routes/project._projectId/-components.mjs +0 -1
  152. package/__app__/src/routes/project._projectId/adhoc.mjs +0 -1
  153. package/__app__/src/routes/project._projectId/embed._viewId.mjs +0 -1
  154. package/__app__/src/routes/project._projectId/export._viewId.mjs +0 -1
  155. package/__app__/src/routes/project._projectId/index.mjs +0 -1
  156. package/__app__/src/routes/project._projectId/route.mjs +0 -1
  157. package/__app__/src/routes/project._projectId/view._viewId.d2.mjs +0 -1
  158. package/__app__/src/routes/project._projectId/view._viewId.dot.mjs +0 -1
  159. package/__app__/src/routes/project._projectId/view._viewId.index.mjs +0 -1
  160. package/__app__/src/routes/project._projectId/view._viewId.mjs +0 -1
  161. package/__app__/src/routes/project._projectId/view._viewId.mmd.mjs +0 -1
  162. package/__app__/src/routes/project._projectId/view._viewId.puml.mjs +0 -1
  163. package/__app__/src/routes/projects.mjs +0 -1
  164. package/dist/chunks/libs/@chevrotain/utils.mjs +0 -1
  165. package/dist/chunks/libs/@hono/mcp.mjs +0 -45
  166. package/dist/chunks/libs/@hono/node-server.mjs +0 -1
  167. package/dist/chunks/libs/@logtape/logtape.d.mts +0 -1023
  168. package/dist/chunks/libs/@modelcontextprotocol/sdk.mjs +0 -12
  169. package/dist/chunks/libs/ajv.mjs +0 -1
  170. package/dist/chunks/libs/ansi-align.mjs +0 -2
  171. package/dist/chunks/libs/ansi-regex.mjs +0 -1
  172. package/dist/chunks/libs/ansi-styles.mjs +0 -1
  173. package/dist/chunks/libs/atomically.mjs +0 -1
  174. package/dist/chunks/libs/boxen.mjs +0 -22
  175. package/dist/chunks/libs/conf.mjs +0 -1
  176. package/dist/chunks/libs/defu.mjs +0 -1
  177. package/dist/chunks/libs/destr.mjs +0 -1
  178. package/dist/chunks/libs/find-up-simple.mjs +0 -1
  179. package/dist/chunks/libs/get-port.mjs +0 -1
  180. package/dist/chunks/libs/hono.mjs +0 -1
  181. package/dist/chunks/libs/is-docker.mjs +0 -1
  182. package/dist/chunks/libs/is-error-instance.mjs +0 -1
  183. package/dist/chunks/libs/is-inside-container.mjs +0 -1
  184. package/dist/chunks/libs/is-plain-obj.mjs +0 -1
  185. package/dist/chunks/libs/isexe.mjs +0 -1
  186. package/dist/chunks/libs/ky.mjs +0 -3
  187. package/dist/chunks/libs/p-debounce.mjs +0 -1
  188. package/dist/chunks/libs/p-limit.mjs +0 -1
  189. package/dist/chunks/libs/p-timeout.mjs +0 -1
  190. package/dist/chunks/libs/package-up.mjs +0 -1
  191. package/dist/chunks/libs/parse-ms.mjs +0 -1
  192. package/dist/chunks/libs/safe-stringify.mjs +0 -1
  193. package/dist/chunks/libs/strip-indent.mjs +0 -1
  194. package/dist/chunks/libs/tinyrainbow.mjs +0 -1
  195. package/dist/chunks/libs/ts-graphviz.d.mts +0 -12
  196. package/dist/chunks/libs/ts-graphviz.mjs +0 -4
  197. package/dist/chunks/libs/vscode-languageserver.mjs +0 -1
  198. package/dist/chunks/libs/word-wrap.mjs +0 -12
  199. package/dist/chunks/plugin.mjs +0 -400
  200. package/dist/vite-plugin/internal/chunks/libs/@nanostores/react.d.mts +0 -269
  201. package/dist/vite-plugin/internal/chunks/libs/@nanostores/react.mjs +0 -1
  202. package/dist/vite-plugin/internal/chunks/libs/birpc.mjs +0 -1
  203. package/dist/vite-plugin/internal/chunks/libs/fast-equals.mjs +0 -1
  204. package/dist/vite-plugin/internal/chunks/libs/nanostores.d.mts +0 -59
  205. package/dist/vite-plugin/internal/chunks/libs/nanostores.mjs +0 -1
  206. package/dist/vite-plugin/internal/chunks/libs/remeda.mjs +0 -1
  207. package/dist/vite-plugin/internal/chunks/rolldown-runtime.mjs +0 -1
@@ -1 +1 @@
1
- import"./rolldown-runtime.mjs";import{Q as e,R as t,W as n,X as r,_ as i,b as a,p as o,t as s,y as c,z as l}from"./libs/remeda.mjs";import{a as u,i as d,n as f,r as p,t as m}from"./libs/@lume/kiwi.mjs";import{getParallelStepsPrefix as h,isStepEdgeId as g}from"@likec4/core/types";import{DefaultMap as _,Stack as v,invariant as y,isAncestor as b,nonNullable as x,nonexhaustive as S}from"@likec4/core/utils";function findParallelRects(t){return e(t,l(e=>e.parallelPrefix??void 0),i((e,t)=>e.reduce((e,t)=>(e.min.column=Math.min(e.min.column,t.from.column,t.to.column),e.min.row=Math.min(e.min.row,t.from.row,t.to.row),e.max.column=Math.max(e.max.column,t.from.column,t.to.column),e.max.row=Math.max(e.max.row,t.from.row,t.to.row),e),{parallelPrefix:t,min:{column:1/0,row:1/0},max:{column:-1/0,row:-1/0}})),s())}function buildCompounds(e,t){if(e.length===0||e.length===t.length)return[];let getNode=e=>x(t.find(t=>t.id===e));function parentsLookup(e){let t=e.parent?getNode(e.parent):null;return t?[t,...parentsLookup(t)]:[]}let n=new v,r=[];return e.forEach(e=>{let t=parentsLookup(e);if(t.length===0){n.clear();return}let i=v.from(t),a,o;for(;a=n.peek()?.node,o=i.peek(),!(!o||!a);){if(b(o.id,a.id)||o.id===a.id){i.pop();continue}if(!b(a.id,o.id)){n.pop();continue}break}for(;o=i.pop();){let t={node:o,from:e,to:e,nested:[]},i=n.peek();i?i.nested.push(t):r.push(t),n.push(t)}n.forEach(t=>t.to=e)}),r}var SequenceViewLayouter=class{#e=new m;#t;#n=[];#r;#i;#a;#o=[];#s=[];constructor({actors:e,steps:t,compounds:n}){this.#a=this.newVar(30),this.#r=this.newVar(0),this.#i=this.newVar(0),this.#t=this.addActors(e);for(let e of n){let t=this.addCompound(e),n=t[0];this.constraint(n.y1,`==`,0,d.strong),this.put(this.#i).after(n.bottom),this.put(this.#a).after(n.y2),this.#n.push(...t)}for(let e of t)this.addStep(e);for(let e of findParallelRects(t))this.addParallelRect(e);let r=this.#t[0];this.constraint(r.offset.left,`==`,0,d.strong);let i=this.#t.reduce((e,t)=>(this.put(t.x).after(e.right,60),this.put(t.offset.left,d.strong).after(e.offset.right,32),this.constraint(t.centerY,`==`,e.centerY,d.strong),this.put(this.#a).after(t.offset.bottom),t));if(this.put(this.#r).after(i.offset.right),this.put(this.#i).after(a(this.#o)?.bottom??this.#a),n.length>0)for(let e of this.#n){let t=e.from.column,n=e.to.column,r=Math.max(e.from.maxRow,e.to.maxRow);for(let e=t+1;e<n;e++){let t=this.actorBox(e);r=Math.max(r,t.maxRow)}let i=x(this.#o[r],`row ${r} not found`);this.put(e.bottom).after(i.bottom,16),this.put(this.#i).after(e.bottom)}this.#e.updateVariables()}getParallelBoxes(){return this.#s.map(({parallelPrefix:e,x1:t,y1:n,x2:r,y2:i})=>({parallelPrefix:e,x:t.value(),y:n.value(),width:r.value()-t.value(),height:i.value()-n.value()}))}getActorBox(e){let t=this.actorBox(e);return{x:t.x.value(),y:t.y.value(),width:t.width,height:t.height}}getCompoundBoxes(){return this.#n.map(({node:e,depth:t,x1:n,y1:r,x2:i,bottom:a})=>({node:e,depth:t,x:n.value(),y:r.value(),width:i.value()-n.value(),height:a.value()-r.value()}))}getPortCenter(e,t){let{column:n,row:r}=t===`source`?e.from:e.to,i=this.actorBox(n).centerX,{y:a}=x(this.#o[r]);return{cx:i.value(),cy:a.value()+32/2+e.offset,height:t===`source`?40:24}}getViewBounds(){return{x:0,y:0,width:this.#r.value(),height:this.#i.value()}}actorBox(e){if(typeof e!=`number`){let t=typeof e==`string`?e:e.id;e=this.#t.findIndex(e=>e.actor.id===t),y(e>=0,`actor ${t} not found`)}return x(this.#t[e],`actor at index ${e} not found`)}addActors(e){let t=0;return c(e,(e,n)=>{let r=this.newVar(t);t+=e.width+60;let i=this.newVar(0),a={column:n,actor:e,x:r,y:i,centerX:r.plus(Math.round(e.width/2)),centerY:i.plus(Math.round(e.height/2)),width:e.width,height:e.height,right:r.plus(e.width),bottom:i.plus(e.height),minRow:1/0,maxRow:-1/0},o=this.newVar(0),s=this.newVar(0),c=this.newVar(0),l=this.newVar(0);return this.put(o,d.strong).before(i),this.put(s,d.strong).before(r),this.put(c,d.strong).after(a.right),this.put(l,d.strong).after(a.bottom),{...a,offset:{top:o,left:s,right:c,bottom:l}}})}addStep(e){let t=this.actorBox(e.source),n=this.actorBox(e.target);t.minRow=Math.min(t.minRow,e.from.row),t.maxRow=Math.max(t.maxRow,e.from.row),n.minRow=Math.min(n.minRow,e.to.row),n.maxRow=Math.max(n.maxRow,e.to.row);let[r,i]=t.column<=n.column?[t,n]:[n,t],a=(e.label?.width??100)+50;r===i?this.constraint(r.centerX.plus(a),`<=`,r.offset.right):this.constraint(r.centerX.plus(a),`<=`,i.centerX);let o=e.label?.height?e.label.height+50+32/2:80;return o=Math.max(o,80)+e.offset,this.ensureRow(e.from.row,o),e.isSelfLoop&&this.ensureRow(e.to.row,80),this}addParallelRect({parallelPrefix:e,min:t,max:n}){let r=this.actorBox(t.column).centerX.minus(30),i=this.actorBox(n.column).centerX.plus(30),a=this.#o[t.row],o=this.#o[n.row];y(a&&o,`parallel box invalid minRow=${t.row} maxRow=${n.row}`);let s=this.newVar(0);this.put(s).before(a.y,40);let c=o.bottom,l=t.row>0&&this.#o[t.row-1];l&&this.put(s).after(l.bottom,16);let u=n.row<this.#o.length-1&&this.#o[n.row+1];u&&this.put(c).before(u.y,16),this.#s.push({parallelPrefix:e,x1:r,y1:s,x2:i,y2:c})}addCompound(e){let t=[],n=e.nested.flatMap(e=>{let n=this.addCompound(e);return t.push(n[0]),n}),r=Math.max(...n.map(e=>e.depth+1),0),i=this.actorBox(e.from),a=this.actorBox(e.to),s=i.offset.left.minus(32);i.offset.left=s;let c=a.offset.right.plus(32);a.offset.right=c;let l=this.newVar(0),u=o(t),d,f;switch(!0){case!!u:d=u.y1.minus(40),f=u.y2.plus(32),this.put(l).after(u.bottom,32);break;case a===i:d=this.newVar(0),f=this.newVar(0),this.put(d).before(i.offset.top,52),this.put(f).after(i.offset.bottom,32),this.put(l).after(f);break;case t.length>0:d=this.newVar(0),f=this.newVar(0);for(let e of t)this.put(d).before(e.y1,32),this.put(f).after(e.y2,32),this.put(l).after(e.bottom,32);break;default:d=this.newVar(0),f=this.newVar(0);for(var p=i.column;p<=a.column;p++){let e=this.actorBox(p).offset;this.put(d).before(e.top,52),this.put(f).after(e.bottom,32)}this.put(l).after(f);break}for(var p=i.column;p<=a.column;p++){let e=this.actorBox(p).offset;e.top=d,e.bottom=f}return[{node:e.node,depth:r,from:i,to:a,x1:s,y1:d,x2:c,y2:f,bottom:l},...n]}ensureRow(e,t){for(;e>=this.#o.length;){let e=this.#o.length>0&&this.#o[this.#o.length-1]?.bottom||this.#a.plus(30),t=this.newVar(this.#o.length*80);this.put(t).after(e);let n=this.newVar(80);this.require(n,`>=`,80),this.#o.push({y:t,height:n,bottom:t.plus(n),lastHeight:80})}let n=x(this.#o[e]);t>n.lastHeight&&(n.lastHeight=t,this.require(n.height,`>=`,t),this.#e.suggestValue(n.height,t))}newVar(e){let t=new u;return this.#e.addEditVariable(t,d.weak),typeof e==`number`&&(this.#e.suggestValue(t,e),this.constraint(t,`>=`,0,d.strong)),t}require(e,t,n=void 0){switch(this.constraint(e,t,n,d.required),t){case`<=`:case`>=`:this.constraint(e,`==`,n,d.weak);break;case`<= 0`:case`>= 0`:this.constraint(e,`== 0`,void 0,d.weak);break}}constraint(e,t,n=void 0,r=d.medium){let i;switch(t){case`==`:i=p.Eq;break;case`>=`:i=p.Ge;break;case`<=`:i=p.Le;break;case`== 0`:i=p.Eq,n=0;break;case`>= 0`:i=p.Ge,n=0;break;case`<= 0`:i=p.Le,n=0;break;default:S(t)}this.#e.addConstraint(new f(e,i,n??0,r))}put(e,t=d.required){let n=t===d.required?d.medium:d.weak;return{before:(r,i)=>{i&&(r=r.minus(i)),this.constraint(e,`<=`,r,t),this.constraint(e,`==`,r,n)},after:(r,i)=>{i&&(r=r.plus(i)),this.constraint(e,`>=`,r,t),this.constraint(e,`==`,r,n)}}}};function calcSequenceLayout(a){let o=new Set,getNode=e=>x(a.nodes.find(t=>t.id===e)),l=[];for(let e of a.edges.filter(e=>g(e.id))){let t=getNode(e.source),n=getNode(e.target);if(t.children.length||n.children.length){console.error(`Sequence view does not support nested actors`);continue}o.add(t),o.add(n),l.push({edge:e,source:t,target:n})}let u=a.nodes.filter(e=>o.has(e));y(r(u,1),`actors array must not be empty`);let d=new _(()=>[]),f=[],p=0;for(let{edge:e,source:t,target:n}of l){let r=f.at(-1),i=u.indexOf(t),a=u.indexOf(n),o=t===n,s=i>a,c=h(e.id),l=!1;r&&r.target==t&&r.parallelPrefix===c&&(l=r.isSelfLoop!==o||r.isBack===s),l||p++;let m={id:e.id,from:{column:i,row:p},to:{column:a,row:o?++p:p},edge:e,isSelfLoop:o,isBack:s,parallelPrefix:c,offset:l?(r?.offset??0)+22:0,source:t,target:n,label:e.labelBBox?{height:e.labelBBox.height+8+(e.navigateTo?20:0),width:e.labelBBox.width+16,text:e.label}:null};f.push(m),d.get(t).push({step:m,row:p,type:`source`,position:s&&!o?`left`:`right`}),d.get(n).push({step:m,row:p,type:`target`,position:s||o?`right`:`left`})}let m=new SequenceViewLayouter({actors:u,steps:f,compounds:buildCompounds(u,a.nodes)}),v=m.getViewBounds(),b=e(m.getCompoundBoxes(),c(({node:e,...t})=>({...t,id:e.id,origin:e.id})),t(`id`),i((e,t)=>r(e,2)?c(e,(e,n)=>({...e,id:`${t}-${n+1}`})):e),s(),n());return{actors:u.map(e=>toSeqActor({actor:e,ports:d.get(e),layout:m})),compounds:b,steps:c(f,e=>({id:e.id,sourceHandle:e.id+`_source`,targetHandle:e.id+`_target`,...e.label&&{labelBBox:{width:e.label.width,height:e.label.height}}})),parallelAreas:m.getParallelBoxes(),bounds:v}}function toSeqActor({actor:e,ports:t,layout:n}){let{x:r,y:i,width:a,height:o}=n.getActorBox(e);return{id:e.id,x:r,y:i,width:a,height:o,ports:t.map(e=>{let t=n.getPortCenter(e.step,e.type);return{id:`${e.step.id}_${e.type}`,cx:t.cx-r,cy:t.cy-i,height:t.height,type:e.type,position:e.position}})}}export{calcSequenceLayout as t};
1
+ import"./rolldown-runtime.mjs";import{B as e,K as t,Q as n,V as r,_ as i,b as a,et as o,p as s,t as c,y as l}from"./libs/remeda.mjs";import{a as u,i as d,n as f,r as p,t as m}from"./libs/@lume/kiwi.mjs";import{getParallelStepsPrefix as h,isStepEdgeId as g}from"@likec4/core/types";import{DefaultMap as _,Stack as v,invariant as y,isAncestor as b,nonNullable as x,nonexhaustive as S}from"@likec4/core/utils";function findParallelRects(e){return o(e,r(e=>e.parallelPrefix??void 0),i((e,t)=>e.reduce((e,t)=>(e.min.column=Math.min(e.min.column,t.from.column,t.to.column),e.min.row=Math.min(e.min.row,t.from.row,t.to.row),e.max.column=Math.max(e.max.column,t.from.column,t.to.column),e.max.row=Math.max(e.max.row,t.from.row,t.to.row),e),{parallelPrefix:t,min:{column:1/0,row:1/0},max:{column:-1/0,row:-1/0}})),c())}function buildCompounds(e,t){if(e.length===0||e.length===t.length)return[];let getNode=e=>x(t.find(t=>t.id===e));function parentsLookup(e){let t=e.parent?getNode(e.parent):null;return t?[t,...parentsLookup(t)]:[]}let n=new v,r=[];return e.forEach(e=>{let t=parentsLookup(e);if(t.length===0){n.clear();return}let i=v.from(t),a,o;for(;a=n.peek()?.node,o=i.peek(),!(!o||!a);){if(b(o.id,a.id)||o.id===a.id){i.pop();continue}if(!b(a.id,o.id)){n.pop();continue}break}for(;o=i.pop();){let t={node:o,from:e,to:e,nested:[]},i=n.peek();i?i.nested.push(t):r.push(t),n.push(t)}n.forEach(t=>t.to=e)}),r}var SequenceViewLayouter=class{#e=new m;#t;#n=[];#r;#i;#a;#o=[];#s=[];constructor({actors:e,steps:t,compounds:n}){this.#a=this.newVar(30),this.#r=this.newVar(0),this.#i=this.newVar(0),this.#t=this.addActors(e);for(let e of n){let t=this.addCompound(e),n=t[0];this.constraint(n.y1,`==`,0,d.strong),this.put(this.#i).after(n.bottom),this.put(this.#a).after(n.y2),this.#n.push(...t)}for(let e of t)this.addStep(e);for(let e of findParallelRects(t))this.addParallelRect(e);let r=this.#t[0];this.constraint(r.offset.left,`==`,0,d.strong);let i=this.#t.reduce((e,t)=>(this.put(t.x).after(e.right,60),this.put(t.offset.left,d.strong).after(e.offset.right,32),this.constraint(t.centerY,`==`,e.centerY,d.strong),this.put(this.#a).after(t.offset.bottom),t));if(this.put(this.#r).after(i.offset.right),this.put(this.#i).after(a(this.#o)?.bottom??this.#a),n.length>0)for(let e of this.#n){let t=e.from.column,n=e.to.column,r=Math.max(e.from.maxRow,e.to.maxRow);for(let e=t+1;e<n;e++){let t=this.actorBox(e);r=Math.max(r,t.maxRow)}let i=x(this.#o[r],`row ${r} not found`);this.put(e.bottom).after(i.bottom,16),this.put(this.#i).after(e.bottom)}this.#e.updateVariables()}getParallelBoxes(){return this.#s.map(({parallelPrefix:e,x1:t,y1:n,x2:r,y2:i})=>({parallelPrefix:e,x:t.value(),y:n.value(),width:r.value()-t.value(),height:i.value()-n.value()}))}getActorBox(e){let t=this.actorBox(e);return{x:t.x.value(),y:t.y.value(),width:t.width,height:t.height}}getCompoundBoxes(){return this.#n.map(({node:e,depth:t,x1:n,y1:r,x2:i,bottom:a})=>({node:e,depth:t,x:n.value(),y:r.value(),width:i.value()-n.value(),height:a.value()-r.value()}))}getPortCenter(e,t){let{column:n,row:r}=t===`source`?e.from:e.to,i=this.actorBox(n).centerX,{y:a}=x(this.#o[r]);return{cx:i.value(),cy:a.value()+32/2+e.offset,height:t===`source`?40:24}}getViewBounds(){return{x:0,y:0,width:this.#r.value(),height:this.#i.value()}}actorBox(e){if(typeof e!=`number`){let t=typeof e==`string`?e:e.id;e=this.#t.findIndex(e=>e.actor.id===t),y(e>=0,`actor ${t} not found`)}return x(this.#t[e],`actor at index ${e} not found`)}addActors(e){let t=0;return l(e,(e,n)=>{let r=this.newVar(t);t+=e.width+60;let i=this.newVar(0),a={column:n,actor:e,x:r,y:i,centerX:r.plus(Math.round(e.width/2)),centerY:i.plus(Math.round(e.height/2)),width:e.width,height:e.height,right:r.plus(e.width),bottom:i.plus(e.height),minRow:1/0,maxRow:-1/0},o=this.newVar(0),s=this.newVar(0),c=this.newVar(0),l=this.newVar(0);return this.put(o,d.strong).before(i),this.put(s,d.strong).before(r),this.put(c,d.strong).after(a.right),this.put(l,d.strong).after(a.bottom),{...a,offset:{top:o,left:s,right:c,bottom:l}}})}addStep(e){let t=this.actorBox(e.source),n=this.actorBox(e.target);t.minRow=Math.min(t.minRow,e.from.row),t.maxRow=Math.max(t.maxRow,e.from.row),n.minRow=Math.min(n.minRow,e.to.row),n.maxRow=Math.max(n.maxRow,e.to.row);let[r,i]=t.column<=n.column?[t,n]:[n,t],a=(e.label?.width??100)+50;r===i?this.constraint(r.centerX.plus(a),`<=`,r.offset.right):this.constraint(r.centerX.plus(a),`<=`,i.centerX);let o=e.label?.height?e.label.height+50+32/2:80;return o=Math.max(o,80)+e.offset,this.ensureRow(e.from.row,o),e.isSelfLoop&&this.ensureRow(e.to.row,80),this}addParallelRect({parallelPrefix:e,min:t,max:n}){let r=this.actorBox(t.column).centerX.minus(30),i=this.actorBox(n.column).centerX.plus(30),a=this.#o[t.row],o=this.#o[n.row];y(a&&o,`parallel box invalid minRow=${t.row} maxRow=${n.row}`);let s=this.newVar(0);this.put(s).before(a.y,40);let c=o.bottom,l=t.row>0&&this.#o[t.row-1];l&&this.put(s).after(l.bottom,16);let u=n.row<this.#o.length-1&&this.#o[n.row+1];u&&this.put(c).before(u.y,16),this.#s.push({parallelPrefix:e,x1:r,y1:s,x2:i,y2:c})}addCompound(e){let t=[],n=e.nested.flatMap(e=>{let n=this.addCompound(e);return t.push(n[0]),n}),r=Math.max(...n.map(e=>e.depth+1),0),i=this.actorBox(e.from),a=this.actorBox(e.to),o=i.offset.left.minus(32);i.offset.left=o;let c=a.offset.right.plus(32);a.offset.right=c;let l=this.newVar(0),u=s(t),d,f;switch(!0){case!!u:d=u.y1.minus(40),f=u.y2.plus(32),this.put(l).after(u.bottom,32);break;case a===i:d=this.newVar(0),f=this.newVar(0),this.put(d).before(i.offset.top,52),this.put(f).after(i.offset.bottom,32),this.put(l).after(f);break;case t.length>0:d=this.newVar(0),f=this.newVar(0);for(let e of t)this.put(d).before(e.y1,32),this.put(f).after(e.y2,32),this.put(l).after(e.bottom,32);break;default:d=this.newVar(0),f=this.newVar(0);for(var p=i.column;p<=a.column;p++){let e=this.actorBox(p).offset;this.put(d).before(e.top,52),this.put(f).after(e.bottom,32)}this.put(l).after(f);break}for(var p=i.column;p<=a.column;p++){let e=this.actorBox(p).offset;e.top=d,e.bottom=f}return[{node:e.node,depth:r,from:i,to:a,x1:o,y1:d,x2:c,y2:f,bottom:l},...n]}ensureRow(e,t){for(;e>=this.#o.length;){let e=this.#o.length>0&&this.#o[this.#o.length-1]?.bottom||this.#a.plus(30),t=this.newVar(this.#o.length*80);this.put(t).after(e);let n=this.newVar(80);this.require(n,`>=`,80),this.#o.push({y:t,height:n,bottom:t.plus(n),lastHeight:80})}let n=x(this.#o[e]);t>n.lastHeight&&(n.lastHeight=t,this.require(n.height,`>=`,t),this.#e.suggestValue(n.height,t))}newVar(e){let t=new u;return this.#e.addEditVariable(t,d.weak),typeof e==`number`&&(this.#e.suggestValue(t,e),this.constraint(t,`>=`,0,d.strong)),t}require(e,t,n=void 0){switch(this.constraint(e,t,n,d.required),t){case`<=`:case`>=`:this.constraint(e,`==`,n,d.weak);break;case`<= 0`:case`>= 0`:this.constraint(e,`== 0`,void 0,d.weak);break}}constraint(e,t,n=void 0,r=d.medium){let i;switch(t){case`==`:i=p.Eq;break;case`>=`:i=p.Ge;break;case`<=`:i=p.Le;break;case`== 0`:i=p.Eq,n=0;break;case`>= 0`:i=p.Ge,n=0;break;case`<= 0`:i=p.Le,n=0;break;default:S(t)}this.#e.addConstraint(new f(e,i,n??0,r))}put(e,t=d.required){let n=t===d.required?d.medium:d.weak;return{before:(r,i)=>{i&&(r=r.minus(i)),this.constraint(e,`<=`,r,t),this.constraint(e,`==`,r,n)},after:(r,i)=>{i&&(r=r.plus(i)),this.constraint(e,`>=`,r,t),this.constraint(e,`==`,r,n)}}}};function calcSequenceLayout(r){let a=new Set,getNode=e=>x(r.nodes.find(t=>t.id===e)),s=[];for(let e of r.edges.filter(e=>g(e.id))){let t=getNode(e.source),n=getNode(e.target);if(t.children.length||n.children.length){console.error(`Sequence view does not support nested actors`);continue}a.add(t),a.add(n),s.push({edge:e,source:t,target:n})}let u=r.nodes.filter(e=>a.has(e));y(n(u,1),`actors array must not be empty`);let d=new _(()=>[]),f=[],p=0;for(let{edge:e,source:t,target:n}of s){let r=f.at(-1),i=u.indexOf(t),a=u.indexOf(n),o=t===n,s=i>a,c=h(e.id),l=!1;r&&r.target==t&&r.parallelPrefix===c&&(l=r.isSelfLoop!==o||r.isBack===s),l||p++;let m={id:e.id,from:{column:i,row:p},to:{column:a,row:o?++p:p},edge:e,isSelfLoop:o,isBack:s,parallelPrefix:c,offset:l?(r?.offset??0)+22:0,source:t,target:n,label:e.labelBBox?{height:e.labelBBox.height+8+(e.navigateTo?20:0),width:e.labelBBox.width+16,text:e.label}:null};f.push(m),d.get(t).push({step:m,row:p,type:`source`,position:s&&!o?`left`:`right`}),d.get(n).push({step:m,row:p,type:`target`,position:s||o?`right`:`left`})}let m=new SequenceViewLayouter({actors:u,steps:f,compounds:buildCompounds(u,r.nodes)}),v=m.getViewBounds(),b=o(m.getCompoundBoxes(),l(({node:e,...t})=>({...t,id:e.id,origin:e.id})),e(`id`),i((e,t)=>n(e,2)?l(e,(e,n)=>({...e,id:`${t}-${n+1}`})):e),c(),t());return{actors:u.map(e=>toSeqActor({actor:e,ports:d.get(e),layout:m})),compounds:b,steps:l(f,e=>({id:e.id,sourceHandle:e.id+`_source`,targetHandle:e.id+`_target`,...e.label&&{labelBBox:{width:e.label.width,height:e.label.height}}})),parallelAreas:m.getParallelBoxes(),bounds:v}}function toSeqActor({actor:e,ports:t,layout:n}){let{x:r,y:i,width:a,height:o}=n.getActorBox(e);return{id:e.id,x:r,y:i,width:a,height:o,ports:t.map(e=>{let t=n.getPortCenter(e.step,e.type);return{id:`${e.step.id}_${e.type}`,cx:t.cx-r,cy:t.cy-i,height:t.height,type:e.type,position:e.position}})}}export{calcSequenceLayout as t};