likec4 1.49.0 → 1.51.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 (99) hide show
  1. package/__app__/src/likec4.js +33 -62
  2. package/__app__/src/main.js +2 -56
  3. package/__app__/src/routes/index.js +81 -16
  4. package/__app__/src/routes/single.js +43 -23
  5. package/__app__/src/style.css +1 -1
  6. package/__app__/src/vendors.js +17891 -17752
  7. package/config/schema.json +16 -0
  8. package/dist/THIRD-PARTY-LICENSES.md +192 -62
  9. package/dist/_chunks/LikeC4.mjs +1 -0
  10. package/dist/_chunks/filesystem.mjs +1230 -0
  11. package/dist/_chunks/index.d.mts +11 -12
  12. package/dist/_chunks/index2.d.mts +173 -84
  13. package/dist/_chunks/libs/@chevrotain/cst-dts-gen.mjs +30 -0
  14. package/dist/_chunks/libs/@chevrotain/regexp-to-ast.mjs +8 -8
  15. package/dist/_chunks/libs/@chevrotain/types.d.mts +1 -0
  16. package/dist/_chunks/libs/@chevrotain/utils.mjs +1 -1
  17. package/dist/_chunks/libs/@hono/mcp.mjs +8 -8
  18. package/dist/_chunks/libs/@hono/node-server.mjs +1 -1
  19. package/dist/_chunks/libs/@logtape/logtape.mjs +3 -3
  20. package/dist/_chunks/libs/@lume/kiwi.mjs +1 -1
  21. package/dist/_chunks/libs/@modelcontextprotocol/sdk.d.mts +114 -14
  22. package/dist/_chunks/libs/@modelcontextprotocol/sdk.mjs +7 -7
  23. package/dist/_chunks/libs/@msgpack/msgpack.mjs +1 -1
  24. package/dist/_chunks/libs/@nanostores/react.d.mts +61 -1
  25. package/dist/_chunks/libs/@nanostores/react.mjs +1 -1
  26. package/dist/_chunks/libs/@smithy/is-array-buffer.mjs +1 -0
  27. package/dist/_chunks/libs/@smithy/util-base64.mjs +1 -1
  28. package/dist/_chunks/libs/ajv.mjs +1 -1
  29. package/dist/_chunks/libs/ansi-align.mjs +2 -0
  30. package/dist/_chunks/libs/ansi-regex.mjs +1 -0
  31. package/dist/_chunks/libs/ansi-styles.mjs +1 -0
  32. package/dist/_chunks/libs/atomically.mjs +1 -1
  33. package/dist/_chunks/libs/birpc.mjs +1 -1
  34. package/dist/_chunks/libs/boxen.d.mts +1 -0
  35. package/dist/_chunks/libs/boxen.mjs +22 -0
  36. package/dist/_chunks/libs/chevrotain-allstar.mjs +2 -2
  37. package/dist/_chunks/libs/chevrotain.mjs +35 -35
  38. package/dist/_chunks/libs/conf.mjs +1 -1
  39. package/dist/_chunks/libs/defu.mjs +1 -1
  40. package/dist/_chunks/libs/esm-env.mjs +1 -1
  41. package/dist/_chunks/libs/eventemitter3.mjs +1 -1
  42. package/dist/_chunks/libs/fast-equals.mjs +1 -1
  43. package/dist/_chunks/libs/find-up-simple.mjs +1 -1
  44. package/dist/_chunks/libs/get-port.mjs +1 -1
  45. package/dist/_chunks/libs/is-docker.mjs +1 -1
  46. package/dist/_chunks/libs/is-error-instance.mjs +1 -1
  47. package/dist/_chunks/libs/is-inside-container.mjs +1 -1
  48. package/dist/_chunks/libs/is-plain-obj.mjs +1 -1
  49. package/dist/_chunks/libs/isexe.mjs +1 -1
  50. package/dist/_chunks/libs/json5.mjs +10 -10
  51. package/dist/_chunks/libs/khroma.mjs +1 -1
  52. package/dist/_chunks/libs/ky.mjs +2 -2
  53. package/dist/_chunks/libs/langium.d.mts +5 -4
  54. package/dist/_chunks/libs/langium.mjs +20 -19
  55. package/dist/_chunks/libs/merge-error-cause.mjs +2 -2
  56. package/dist/_chunks/libs/p-limit.mjs +1 -1
  57. package/dist/_chunks/libs/p-queue.mjs +1 -1
  58. package/dist/_chunks/libs/package-manager-detector.mjs +1 -1
  59. package/dist/_chunks/libs/package-up.mjs +1 -1
  60. package/dist/_chunks/libs/pako.mjs +1 -0
  61. package/dist/_chunks/libs/parse-ms.mjs +1 -1
  62. package/dist/_chunks/libs/pathe.mjs +1 -1
  63. package/dist/_chunks/libs/picomatch.mjs +1 -1
  64. package/dist/_chunks/libs/pretty-ms.mjs +1 -1
  65. package/dist/_chunks/libs/remeda.mjs +2 -1
  66. package/dist/_chunks/libs/safe-stringify.mjs +1 -1
  67. package/dist/_chunks/libs/strip-indent.mjs +1 -1
  68. package/dist/_chunks/libs/tinyrainbow.mjs +1 -1
  69. package/dist/_chunks/libs/ts-graphviz.mjs +3 -3
  70. package/dist/_chunks/libs/ufo.mjs +1 -1
  71. package/dist/_chunks/libs/vscode-languageserver.mjs +1 -0
  72. package/dist/_chunks/libs/which.mjs +1 -1
  73. package/dist/_chunks/libs/word-wrap.mjs +2 -2
  74. package/dist/_chunks/rolldown-runtime.mjs +1 -1
  75. package/dist/_chunks/sequence.mjs +1 -0
  76. package/dist/_chunks/src.mjs +15 -0
  77. package/dist/_chunks/src2.mjs +499 -0
  78. package/dist/cli/index.mjs +84 -231
  79. package/dist/config/index.mjs +1 -1
  80. package/dist/index.d.mts +810 -4
  81. package/dist/index.mjs +1 -1
  82. package/dist/model/index.mjs +1 -1
  83. package/dist/vite-plugin/index.d.mts +3 -0
  84. package/dist/vite-plugin/index.mjs +1 -1
  85. package/dist/vite-plugin/internal.d.mts +1 -2
  86. package/dist/vite-plugin/internal.mjs +1 -1
  87. package/package.json +28 -29
  88. package/react/index.d.mts +2 -2
  89. package/react/index.mjs +52 -76
  90. package/vite-plugin-modules.d.ts +5 -0
  91. package/dist/_chunks/GraphvizBinaryAdapter.mjs +0 -72
  92. package/dist/_chunks/filenames.mjs +0 -14
  93. package/dist/_chunks/libs/@chevrotain/gast.mjs +0 -1
  94. package/dist/_chunks/libs/@logtape/logtape.d.mts +0 -741
  95. package/dist/_chunks/libs/nanostores.d.mts +0 -63
  96. package/dist/_chunks/libs/nanostores.mjs +0 -1
  97. package/dist/_chunks/node.mjs +0 -481
  98. package/dist/_chunks/plugin.mjs +0 -322
  99. package/dist/_chunks/sequence-view.mjs +0 -1
@@ -1,322 +0,0 @@
1
- import{t as createBirpc}from"./libs/birpc.mjs";import{E as e,F as t$5,K as n,O as e$1,S as e$2,U as n$2,X as t$1,d as t$4,o as t$2,r as n$1,v as t,y as t$3}from"./libs/remeda.mjs";import{a as GraphvizWasmAdapter,f as handleInitOptions,i as QueueGraphvizLayoter,l as NoFileSystem,m as logger$1,n as createLanguageServices$1,o as WithFileSystem,s as WithLikeC4ManualLayouts,t as GraphvizBinaryAdapter,u as NoLikeC4ManualLayouts,y as loggable}from"./GraphvizBinaryAdapter.mjs";import{t as defu}from"./libs/defu.mjs";import{r as resolve,t as basename}from"./libs/pathe.mjs";import{t as u}from"./libs/tinyrainbow.mjs";import{t as lib}from"./libs/json5.mjs";import{a as expandToNode,i as toString,n as CompositeGeneratorNode,r as NL,t as joinToNode}from"./libs/langium.mjs";import{o as joinURL}from"./libs/ufo.mjs";import{LikeC4Model}from"@likec4/core/model";import{invariant,isNonEmptyArray,memoizeProp,nonexhaustive}from"@likec4/core";import{pathToFileURL}from"url";import{RichText as RichText$1}from"@likec4/core/types";import{compareNatural}from"@likec4/core/utils";function createLanguageServices(r){let i=logger$1.getChild(`lang`),a=defu(r,{useFileSystem:!0,manualLayouts:!0,watch:!1,graphviz:`wasm`}),o=a.graphviz===`binary`;return i.info(`${u.dim(`layout`)} ${o?`binary`:`wasm`}`),createLanguageServices$1({...a.useFileSystem?{...WithFileSystem(a.watch),...a.manualLayouts?WithLikeC4ManualLayouts:NoLikeC4ManualLayouts}:{...NoFileSystem,...NoLikeC4ManualLayouts}},{likec4:{Layouter:()=>new QueueGraphvizLayoter({graphviz:o?new GraphvizBinaryAdapter:new GraphvizWasmAdapter})}})}async function fromWorkspace(r,i){let a=resolve(r);return memoizeProp(globalThis,`likec4:`+a,async()=>{let r=logger$1.getChild(`lang`),o=defu(i,{useFileSystem:!0,manualLayouts:!0,watch:!1});if(o.mcp)throw Error(`MCP server is not supported in this build`);let s=createLanguageServices(o),c={name:basename(a),uri:pathToFileURL(a).toString()},l=s.shared.workspace.WorkspaceManager;r.info(`${u.dim(`workspace:`)} ${a}`),l.initialize({capabilities:{},processId:null,rootUri:null,workspaceFolders:[c]}),await l.initializeWorkspace([c]);let d=s.shared.workspace.LangiumDocuments.userDocuments.toArray();if(d.length===0)throw r.error(`no LikeC4 sources found`),Error(`no LikeC4 sources found`);return r.info(`${u.dim(`workspace:`)} found ${d.length} source files`),handleInitOptions(s,logger$1,i)})}const logger=logger$1.getChild(`vite`);async function calcAdhocView({logger:r,likec4:i},a){r.info([u.green(`adhoc:view`),u.dim(`project:`),a.projectId].join(` `));let o=await i.views.adhocView(a.predicates,a.projectId);return r.info([u.green(`adhoc:view`),`✅`].join(` `)),o}function splitErrorMessage(r){let i=r.split(`
2
- `),a=/^\s+at\s+/,o=i.findIndex(r=>a.test(r));return o===-1&&(o=1),{message:i.slice(0,o).join(`
3
- `),stack:i.slice(o).join(`
4
- `)}}function sendError(r,{name:i,error:a}){r.hot.send({type:`error`,err:{...splitErrorMessage(a),name:i??`LikeC4PluginError`,plugin:`vite-plugin-likec4`}})}async function updateView({logger:r,likec4:i},a){r.info([u.green(`view:onChange`),u.dim(`project`)+`:`,a.projectId,u.dim(`view`)+`:`,a.viewId,u.dim(`change`)+`:`,a.change.op].join(` `));let o=await i.editor.applyChange(a);if(!o.success){r.error(`Failed to apply view change:\n${o.error}`);let i=Error(o.error);throw i.stack=o.error,i}r.info([u.green(`view:onChange`),`✅`].join(` `))}function enablePluginRPC(i){let a=null,o=i.server;createBirpc({updateView:r=>updateView(i,r),calcAdhocView:r=>calcAdhocView(i,r)},{on:r=>o.hot.on(`likec4:rpc`,r),post:r=>o.hot.send(`likec4:rpc`,r),onFunctionError:(r,s)=>{i.logger.error(`RPC error in ${s}`,{error:r});let c=r.stack??r.message;try{a!==c&&(a=c,sendError(o,{name:r.name,error:c}))}catch(r){i.logger.error(`Failed to send error to client`,{error:r})}}})}const capitalizeFirstLetter$2=r=>r.charAt(0).toLocaleUpperCase()+r.slice(1),fqnName$2=r=>r.split(`.`).map(capitalizeFirstLetter$2).join(``),nodeName$2=r=>fqnName$2(r.parent?r.id.slice(r.parent.length+1):r.id),d2direction=({autoLayout:r})=>{switch(r.direction){case`TB`:return`down`;case`BT`:return`up`;case`LR`:return`right`;case`RL`:return`left`}},d2shape=({shape:r})=>{switch(r){case`queue`:case`cylinder`:case`rectangle`:case`document`:return r;case`person`:return`c4-person`;case`storage`:return`stored_data`;case`component`:case`bucket`:case`mobile`:case`browser`:return`rectangle`}};function generateD2(r){let a=r.$view,{nodes:o,edges:s}=a,c=new Map,l=(r,i)=>{let a=nodeName$2(r),s=(i?i+`.`:``)+a;c.set(r.id,s);let d=JSON.stringify(r.title),f=d2shape(r);return new CompositeGeneratorNode().append(a,`: {`,NL).indent({indentedChildren:i=>i.append(`label: `,d,NL).appendIf(f!==`rectangle`,`shape: `,f,NL).appendIf(r.children.length>0,NL,joinToNode(o.filter(i=>i.parent===r.id),r=>l(r,s))),indentation:2}).append(`}`,NL)},d=r=>new CompositeGeneratorNode().append(c.get(r.source),` -> `,c.get(r.target)).append(i=>r.label&&i.append(`: `,JSON.stringify(r.label)));return toString(new CompositeGeneratorNode().append(`direction: `,d2direction(a),NL,NL).append(joinToNode(o.filter(r=>e(r.parent)),r=>l(r),{appendNewLineIfNotEmpty:!0})).appendIf(s.length>0,NL,joinToNode(s,r=>d(r),{appendNewLineIfNotEmpty:!0})))}const capitalizeFirstLetter$1=r=>r.charAt(0).toLocaleUpperCase()+r.slice(1),fqnName$1=r=>r.split(`.`).map(capitalizeFirstLetter$1).join(``),nodeName$1=r=>fqnName$1(r.parent?r.id.slice(r.parent.length+1):r.id),toSingleQuotes=r=>r.replace(/\\?"/g,`'`),mmdshape=({shape:r,title:i})=>{let a=`label: ${JSON.stringify(i)}`;switch(r){case`queue`:return`@{ shape: horizontal-cylinder, ${a} }`;case`person`:return`@{ icon: "fa:user", shape: rounded, ${a} }`;case`storage`:return`@{ shape: disk, ${a} }`;case`cylinder`:return`@{ shape: cylinder, ${a} }`;case`mobile`:case`browser`:return`@{ shape: rounded, ${a} }`;case`bucket`:return`@{ shape: trap-t, ${a} }`;case`rectangle`:return`@{ shape: rectangle, ${a} }`;case`document`:return`@{ shape: doc, ${a} }`;case`component`:return`@{ shape: rectangle, ${a} }`;default:nonexhaustive(r)}};function generateMermaid(r){let a=r.$view,{nodes:o,edges:s}=a,c=new Map,l=(r,i)=>{let a=nodeName$1(r),s=(i?i+`.`:``)+a;c.set(r.id,s);let d=new CompositeGeneratorNode;if(r.children.length>0){let i=toSingleQuotes(r.title);d.append(`subgraph `,s,'["`',i,'`"]',NL).indent({indentedChildren:[joinToNode(o.filter(i=>i.parent===r.id),r=>l(r,s),{appendNewLineIfNotEmpty:!0})],indentation:2}).append(`end`,NL)}else d.append(s,mmdshape(r));return d},d=r=>new CompositeGeneratorNode().append(c.get(r.source),` -.`,r.label?' "`'+toSingleQuotes(r.label)+'`" .-':`-`,`> `,c.get(r.target));return toString(new CompositeGeneratorNode().append(`---`,NL,`title: ${JSON.stringify(toSingleQuotes(r.titleOrId))}`,NL,`---`,NL).append(`graph `,a.autoLayout.direction,NL).indent({indentedChildren:r=>{r.append(joinToNode(o.filter(r=>e(r.parent)),r=>l(r),{appendNewLineIfNotEmpty:!0})).appendIf(s.length>0,joinToNode(s,r=>d(r),{appendNewLineIfNotEmpty:!0}))},indentation:2}))}const capitalizeFirstLetter=r=>r.charAt(0).toLocaleUpperCase()+r.slice(1),fqnName=r=>r.split(/[.-]/).map(capitalizeFirstLetter).join(``),nodeName=r=>fqnName(r.parent?r.id.slice(r.parent.length+1):r.id),pumlColor=(r,i,a=`#3b82f6`)=>r?i(r)??a:a,pumlDirection=({autoLayout:r})=>{switch(r.direction){case`TB`:return`top to bottom`;case`BT`:return console.warn(`Bottom to top direction is not supported. Defaulting to top to bottom.`),`top to bottom`;case`LR`:return`left to right`;case`RL`:return console.warn(`Right to left direction is not supported. Defaulting to left to right.`),`left to right`}},pumlShape=({shape:r})=>{switch(r){case`queue`:case`rectangle`:case`person`:return r;case`storage`:case`cylinder`:return`database`;case`component`:return`component`;case`document`:case`mobile`:case`bucket`:case`browser`:return`rectangle`;default:nonexhaustive(r)}},escapeLabel=r=>e$1(r)?null:JSON.stringify(r).slice(1,-1).replace(/\\"/g,`"`);function generatePuml(r){let a=r.$view,o=r.$model.$styles.theme.colors,{nodes:c,edges:l}=a,d=r=>i=>i in o?o[i].elements[r]:void 0,f=r=>i=>i in o?o[i].relationships[r]:void 0,p=new Map,m=()=>new CompositeGeneratorNode().append(`title "`,r.titleOrId,`"`,NL).append(pumlDirection(a),` direction`,NL),h=()=>new CompositeGeneratorNode().append(`hide stereotype`,NL).append(`skinparam ranksep `,`60`,NL).append(`skinparam nodesep `,`30`,NL).append(`skinparam {`,NL).indent({indentedChildren:r=>r.append(`arrowFontSize `,`10`,NL).append(`defaultTextAlignment `,`center`,NL).append(`wrapWidth `,`200`,NL).append(`maxMessageSize `,`100`,NL).append(`shadowing `,`false`,NL),indentation:2}).append(`}`,NL),g=r=>{let i=pumlShape(r),a=fqnName(r.id);return new CompositeGeneratorNode().append(`skinparam `,i,`<<`,a,`>>`,`{`,NL).indent({indentedChildren:i=>i.append(`BackgroundColor `,pumlColor(r.color,d(`fill`)),NL).append(`FontColor `,pumlColor(r.color,d(`hiContrast`),`#FFFFFF`),NL).append(`BorderColor `,pumlColor(r.color,d(`stroke`)),NL),indentation:2}).append(`}`,NL)},_=r=>{let i=pumlShape(r),a=fqnName(r.id),o=escapeLabel(r.title)||nodeName(r),s=escapeLabel(r.technology);p.set(r.id,a);let c=RichText$1.from(r.description);return new CompositeGeneratorNode().append(i,` `).append(`"`).append(`==`,o).appendIf(!!s,`\\n<size:10>[`,s,`]</size>`).appendIf(c.nonEmpty,`\\n\\n`,escapeLabel(c.text)).append(`"`,` <<`,a,`>> `,`as `,a,NL)},v=r=>{let i=escapeLabel(r.title)||nodeName(r),a=fqnName(r.id);return p.set(r.id,a),new CompositeGeneratorNode().append(`rectangle "`,i,`" <<`,a,`>> as `,a,` {`,NL).indent({indentedChildren:i=>i.append(`skinparam `,`RectangleBorderColor<<`,a,`>> `,pumlColor(r.color,d(`fill`)),NL).append(`skinparam `,`RectangleFontColor<<`,a,`>> `,pumlColor(r.color,d(`fill`)),NL).append(`skinparam `,`RectangleBorderStyle<<`,a,`>> `,`dashed`,NL,NL).append(joinToNode(c.filter(i=>i.parent===r.id),r=>r.children.length>0?v(r):_(r))),indentation:2}).append(`}`,NL)},y=r=>{let i=r.technology||``,a=r.label||i,o=pumlColor(r.color,f(`line`),`#777777`),c=r=>`<color:${o}>${r.replaceAll(`"`,`'`)}`,l=new CompositeGeneratorNode().append(p.get(r.source),` .[`,o,`,thickness=2].> `,p.get(r.target));return(a||i)&&(l.append(` : `,a.split(`
5
- `).map(r=>e$1(r)?r:c(r)).join(`\\n`)),i&&i!==a&&l.append(`\\n<size:8>[`,c(i),`]</size>`)),l.append(NL)};return toString(new CompositeGeneratorNode().append(`@startuml`,NL).append(m(),NL).append(h(),NL).append(joinToNode(c.filter(r=>r.children.length==0),r=>g(r),{appendNewLineIfNotEmpty:!0})).append(joinToNode(c.filter(r=>e(r.parent)),r=>r.children.length>0?v(r):_(r),{appendNewLineIfNotEmpty:!0})).appendIf(l.length>0,NL,joinToNode(l,r=>y(r),{appendNewLineIfNotEmpty:!0})).append(`@enduml`,NL))}function generateMatches(r,i=`.js`){return{matches:a=>{let{module:o,projectId:s}=a.match(/^likec4:plugin\/(?<projectId>.+)\/(?<module>.+)$/)?.groups??a.match(/^likec4:(?<module>.+)\/(?<projectId>.+)$/)?.groups??{};return!o||!s?null:(o.endsWith(i)&&(o=o.slice(0,-i.length)),o===r?s:null)},virtualId:a=>joinURL(`likec4:plugin`,a,r)+i}}const charMap={"<":`\\u003C`,">":`\\u003E`,"/":`\\u002F`,"\\":`\\\\`,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`,"\0":`\\0`,"\u2028":`\\u2028`,"\u2029":`\\u2029`};function escapeUnsafeChars(r){return r.replace(/[<>\b\f\n\r\t\0\u2028\u2029\\]/g,r=>charMap[r])}function generateCombinedProjects(r,i){return{id:`likec4:${r}`,virtualId:`likec4:plugin/${r}.js`,async load({logger:a,projects:o}){return a.info(u.dim(`generating likec4:${r}`)),`
6
- export let ${i}Fn = {
7
- ${o.map(({id:i})=>{let a=escapeUnsafeChars(JSON.stringify(joinURL(`likec4:${r}`,i)));return`${JSON.stringify(i)}: () => import(${a})`}).join(`,
8
- `)}
9
- }
10
-
11
- export async function ${i}(projectId) {
12
- let fn = ${i}Fn[projectId]
13
- if (!fn) {
14
- const projects = Object.keys(${i}Fn)
15
- console.error('Unknown projectId: ' + projectId + ' (available: ' + projects + ')')
16
- if (projects.length === 0) {
17
- throw new Error('No projects found, invalid state')
18
- }
19
- projectId = projects[0]
20
- console.warn('Falling back to project: ' + projectId)
21
- fn = ${i}Fn[projectId]
22
- }
23
- return await fn()
24
- }
25
-
26
- if (import.meta.hot) {
27
- import.meta.hot.accept(md => {
28
- if (!import.meta.hot.data.$update) {
29
- import.meta.hot.data.$update = ${i}Fn
30
- }
31
- const update = md.${i}Fn
32
- if (update) {
33
- Object.assign(import.meta.hot.data.$update, update)
34
- } else {
35
- import.meta.hot.invalidate()
36
- }
37
- })
38
- }
39
- `}}}function code$8(r){let i=new CompositeGeneratorNode;return i.appendTemplate`
40
- /******************************************************************************
41
- * This file was generated
42
- * DO NOT EDIT MANUALLY!
43
- ******************************************************************************/
44
- /* eslint-disable */
45
-
46
- export function d2Source(viewId) {
47
- switch (viewId) {
48
- `.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(joinToNode([...r.views()],r=>expandToNode`
49
- case ${JSON.stringify(r.id)}: {
50
- return ${JSON.stringify(generateD2(r))}
51
- }
52
- `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
53
- default: {
54
- throw new Error('Unknown viewId: ' + viewId)
55
- }
56
- `}}).append(NL,` }`,NL).appendTemplate`
57
- }
58
- `.append(NL,NL),toString(i)}const projectD2Module={...generateMatches(`d2`),async load({likec4:r,project:i,logger:a}){return a.info(u.dim(`generating likec4:d2/${i.id}`)),code$8(await r.computedModel(i.id))}},d2Module=generateCombinedProjects(`d2`,`loadD2Sources`);function code$7(r){let i=new CompositeGeneratorNode;return i.appendTemplate`
59
- /******************************************************************************
60
- * This file was generated
61
- * DO NOT EDIT MANUALLY!
62
- ******************************************************************************/
63
- /* eslint-disable */
64
-
65
- export function dotSource(viewId) {
66
- switch (viewId) {
67
- `.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(joinToNode(Object.keys(r),i=>expandToNode`
68
- case ${JSON.stringify(i)}: {
69
- return ${JSON.stringify(r[i].dot)}
70
- }
71
- `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
72
- default: {
73
- throw new Error('Unknown viewId: ' + viewId)
74
- }
75
- `}}).append(NL,` }`,NL).appendTemplate`
76
- }
77
-
78
- export function svgSource(viewId) {
79
- switch (viewId) {
80
- `.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(joinToNode(Object.keys(r),i=>expandToNode`
81
- case ${JSON.stringify(i)}: {
82
- return ${JSON.stringify(r[i].svg)}
83
- }
84
- `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
85
- default: {
86
- throw new Error('Unknown viewId: ' + viewId)
87
- }
88
- `}}).append(NL,` }`,NL,`}`,NL,NL),toString(i)}const projectDotSourcesModule={...generateMatches(`dot`),async load({likec4:r,project:i,logger:a}){return a.info(u.dim(`generating likec4:dot/${i.id}`)),code$7(t(await r.views.viewsAsGraphvizOut(i.id),({id:r,svg:i,dot:a})=>[r,{dot:a,svg:i}]))}},dotModule=generateCombinedProjects(`dot`,`loadDotSources`);function code$6(r){let{imports:i,cases:a}=t$1(r.flatMap(r=>r.nodes.map(r=>r.icon)),n(r=>e$2(r)&&!(r.toLowerCase().startsWith(`http:`)||r.toLowerCase().startsWith(`https:`))),n$1(),t$2(compareNatural)).reduce((r,i,a)=>{let o=i.startsWith(`file:`),s=`Icon`+a.toString().padStart(2,`0`);if(o)return r.imports.push(`import ${s} from '${i}?inline'`),r.cases.push(` '${i}': () => jsx('img', { src: ${s} })`),r;let[c,l]=i.split(`:`);return r.imports.push(`import ${s} from '@likec4/icons/${c}/${l}'`),r.cases.push(` '${c}:${l}': ${s}`),r},{imports:[],cases:[]});return`
89
- import { jsx } from 'react/jsx-runtime'
90
- ${i.join(`
91
- `)}
92
-
93
- const Icons = {
94
- ${a.join(`,
95
- `)}
96
- }
97
- export function IconRenderer({ node, ...props }) {
98
- const IconComponent = Icons[node.icon ?? '']
99
- if (!IconComponent) {
100
- return null
101
- }
102
- return jsx(IconComponent, props)
103
- }
104
- `}const projectIconsModule={...generateMatches(`icons`,`.jsx`),async load({likec4:r,project:i,logger:a}){return a.info(u.dim(`generating likec4:icons/${i.id}`)),code$6(await r.views.computedViews(i.id))}},iconsModule={id:`likec4:icons`,virtualId:`likec4:plugin/icons.jsx`,async load({projects:r,logger:i}){return i.info(u.dim(`generating likec4:icons`)),`
105
- import { jsx } from 'react/jsx-runtime'
106
- import { lazy, Suspense } from 'react'
107
- export let ProjectIconsRegistry = {
108
- ${r.map(r=>({id:JSON.stringify(r.id),pkg:JSON.stringify(joinURL(`likec4:icons`,r.id))})).map(({id:r,pkg:i})=>`${r}: lazy(() => import(${i}).then(m => ({default: m.IconRenderer})))`).join(`,
109
- `)}
110
- }
111
-
112
-
113
- export function getProjectIcons(projectId) {
114
- let fn = ProjectIconsRegistry[projectId]
115
- if (!fn) {
116
- const projects = Object.keys(ProjectIconsRegistry)
117
- console.error('Unknown projectId: ' + projectId + ' (available: ' + projects + ')')
118
- if (projects.length === 0) {
119
- throw new Error('No projects found, invalid state')
120
- }
121
- projectId = projects[0]
122
- console.warn('Falling back to project: ' + projectId)
123
- fn = ProjectIconsRegistry[projectId]
124
- }
125
- return (props) => jsx(Suspense, { children: jsx(fn, props) })
126
- }
127
-
128
- if (import.meta.hot) {
129
- import.meta.hot.accept(md => {
130
- if (!import.meta.hot.data.$update) {
131
- import.meta.hot.data.$update = ProjectIconsRegistry
132
- }
133
- const update = md.ProjectIconsRegistry
134
- if (update) {
135
- Object.assign(import.meta.hot.data.$update, update)
136
- } else {
137
- import.meta.hot.invalidate()
138
- }
139
- })
140
- }
141
- `}};function code$5(r){let i=new CompositeGeneratorNode;return i.appendTemplate`
142
- /******************************************************************************
143
- * This file was generated
144
- * DO NOT EDIT MANUALLY!
145
- ******************************************************************************/
146
- /* eslint-disable */
147
-
148
- export function mmdSource(viewId) {
149
- switch (viewId) {
150
- `.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(joinToNode([...r.views()],r=>expandToNode`
151
- case ${JSON.stringify(r.id)}: {
152
- return ${JSON.stringify(generateMermaid(r))}
153
- }
154
- `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
155
- default: {
156
- throw new Error('Unknown viewId: ' + viewId)
157
- }
158
- `}}).append(NL,` }`,NL).appendTemplate`
159
- }
160
-
161
- `.append(NL,NL),toString(i)}const projectMmdSourcesModule={...generateMatches(`mmd`),async load({likec4:r,project:i,logger:a}){return a.info(u.dim(`generating virtual:likec4/mmd/${i.id}`)),code$5(await r.computedModel(i.id))}},mmdModule=generateCombinedProjects(`mmd`,`loadMmdSources`),projectModelCode=r=>`
162
- import { createHooksForModel, atom } from 'likec4/vite-plugin/internal'
163
-
164
- export const $likec4data = atom(${lib.stringify(r.$data)})
165
-
166
- export const {
167
- updateModel,
168
- $likec4model,
169
- useLikeC4Model,
170
- useLikeC4Views,
171
- useLikeC4View
172
- } = createHooksForModel($likec4data)
173
-
174
- if (import.meta.hot) {
175
- import.meta.hot.accept(md => {
176
- if (!import.meta.hot.data.$update) {
177
- import.meta.hot.data.$update = updateModel
178
- }
179
- const update = md.$likec4data?.get()
180
- if (update) {
181
- import.meta.hot.data.$update(update)
182
- } else {
183
- import.meta.hot.invalidate()
184
- }
185
- })
186
- }
187
- `,projectModelModule={...generateMatches(`model`),async load({likec4:r,project:i,logger:a}){return a.info(u.dim(`generating likec4:model/${i.id}`)),projectModelCode(await r.layoutedModel(i.id))}},modelModule=generateCombinedProjects(`model`,`loadModel`),code$4=r=>`
188
- import { atom, useStore } from 'likec4/vite-plugin/internal'
189
-
190
- export const isSingleProject = ${r.length===1};
191
- export const projects = ${lib.stringify(r,null,2)};
192
-
193
- export const $projects = atom([...projects])
194
-
195
- export function useLikeC4Projects() {
196
- return useStore($projects)
197
- }
198
-
199
- if (import.meta.hot) {
200
- import.meta.hot.accept(md => {
201
- if (!import.meta.hot.data.$projects) {
202
- import.meta.hot.data.$projects = $projects
203
- }
204
- if (!import.meta.hot.data.projects) {
205
- import.meta.hot.data.projects = projects
206
- }
207
- const update = md.projects
208
- if (update) {
209
- import.meta.hot.data.projects.length = 0
210
- import.meta.hot.data.projects.push(...update)
211
- import.meta.hot.data.$projects.set(update)
212
- } else {
213
- import.meta.hot.invalidate()
214
- }
215
- })
216
- }
217
- `,projectsModule={id:`likec4:projects`,virtualId:`likec4:plugin/projects.js`,async load({logger:r,projects:i}){return r.info(u.dim(`generating likec4:projects`)),code$4(t$3(i,t$4([`id`,`title`])))}},code$3=r=>`
218
- import { atom, useStore } from 'likec4/vite-plugin/internal'
219
-
220
- export const $viewdata = atom(${lib.stringify(r)})
221
-
222
- export function useLikeC4ProjectsOverview() {
223
- return useStore($viewdata)
224
- }
225
-
226
- if (import.meta.hot) {
227
- import.meta.hot.accept(md => {
228
- if (!import.meta.hot.data.$viewdata) {
229
- import.meta.hot.data.$viewdata = $viewdata
230
- }
231
- const update = md.$viewdata?.value
232
- if (update) {
233
- import.meta.hot.data.$viewdata.set(update)
234
- } else {
235
- import.meta.hot.invalidate()
236
- }
237
- })
238
- }
239
- `,noProjects=()=>`
240
- export function useLikeC4ProjectsOverview() {
241
- throw new Error('No projects overview available for this workspace: single project mode is enabled')
242
- }
243
- `,projectsOverviewModule={id:`likec4:projects-overview`,virtualId:`likec4:plugin/projects-overview.js`,async load({logger:r,projects:i,likec4:a}){return i.length<2?noProjects():(r.info(u.dim(`generating likec4:projects-overview`)),code$3(await a.projectsOverview()))}};function code$2(r){let i=new CompositeGeneratorNode;return i.appendTemplate`
244
- /******************************************************************************
245
- * This file was generated
246
- * DO NOT EDIT MANUALLY!
247
- ******************************************************************************/
248
- /* eslint-disable */
249
-
250
- export function pumlSource(viewId) {
251
- switch (viewId) {
252
- `.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(joinToNode([...r.views()],r=>expandToNode`
253
- case ${JSON.stringify(r.id)}: {
254
- return ${JSON.stringify(generatePuml(r))}
255
- }
256
- `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
257
- default: {
258
- throw new Error('Unknown viewId: ' + viewId)
259
- }
260
- `}}).append(NL,` }`,NL).appendTemplate`
261
- }
262
- `.append(NL,NL),toString(i)}const projectPumlModule={...generateMatches(`puml`),async load({likec4:r,project:i,logger:a}){return a.info(u.dim(`generating likec4:puml/${i.id}`)),code$2(await r.computedModel(i.id))}},pumlModule=generateCombinedProjects(`puml`,`loadPumlSources`),projectCode=r=>`
263
- import { jsx as _jsx } from "react/jsx-runtime";
264
- import { LikeC4ModelProvider as Provider, LikeC4View as GenericView, ReactLikeC4 as GenericReactLikeC4 } from 'likec4/react';
265
- import { IconRenderer } from 'likec4:icons/${r}'
266
-
267
- import { useLikeC4Model, useLikeC4Views, useLikeC4View } from 'likec4:model/${r}'
268
-
269
- export function LikeC4ModelProvider({ children }) {
270
- const likeC4Model = useLikeC4Model()
271
- return (_jsx(Provider, { likec4model: likeC4Model, children: children }));
272
- }
273
- export function LikeC4View(props) {
274
- return (_jsx(LikeC4ModelProvider, { children: _jsx(GenericView, { renderIcon: IconRenderer, ...props }) }));
275
- }
276
- export function ReactLikeC4(props) {
277
- return (_jsx(LikeC4ModelProvider, { children: _jsx(GenericReactLikeC4, { renderIcon: IconRenderer, ...props }) }));
278
- }
279
-
280
- export {
281
- useLikeC4Model,
282
- useLikeC4View,
283
- useLikeC4Views
284
- }
285
- `,projectReactModule={...generateMatches(`react`),async load({project:r,logger:i}){return i.info(u.dim(`generating likec4:react/${r.id}`)),projectCode(r.id)}},singleProjectReactModule={id:`likec4:react`,virtualId:`likec4:plugin/react.js`,async load({logger:r,projects:i}){let a=n$2(i);return r.info(u.dim(`generating likec4:react for`)+` `+a.id),projectCode(a.id)}},rpcModule={id:`likec4:rpc`,virtualId:`likec4:plugin/rpc.js`,async load({logger:r}){return r.info(u.dim(`generating likec4:rpc`)),`
286
- import { createRpc } from 'likec4/vite-plugin/internal'
287
-
288
- export const isRpcAvailable = !!import.meta.hot
289
-
290
- let rpc
291
- if (import.meta.hot) {
292
- rpc = createRpc({
293
- send: (event, data) => {
294
- import.meta.hot.send(event, data)
295
- },
296
- on: (event, fn) => {
297
- import.meta.hot.on(event, fn)
298
- }
299
- })
300
-
301
- import.meta.hot.accept()
302
- }
303
-
304
- export const likec4rpc = rpc ?? {
305
- updateView: () => {
306
- throw new Error('likec4rpc.updateView is not available in production')
307
- },
308
- calcAdhocView: () => {
309
- throw new Error('likec4rpc.calcAdhocView is not available in production')
310
- },
311
- }
312
- `}},code=r=>`
313
- export { IconRenderer } from 'likec4:icons/${r}'
314
- export {
315
- $likec4data,
316
- $likec4model,
317
- useLikeC4Model,
318
- useLikeC4Views,
319
- useLikeC4View
320
- } from 'likec4:model/${r}'
321
- export const projectId = ${JSON.stringify(r)}
322
- `,singleProjectModule={id:`likec4:single-project`,virtualId:`likec4:plugin/single-project.js`,async load({logger:r,projects:i}){let a=n$2(i);return r.info(u.dim(`generating likec4:single-project for`)+` `+a.id),code(a.id)}},hmrProjectVirtuals=[projectModelModule,projectIconsModule,projectD2Module,projectDotSourcesModule,projectMmdSourcesModule,projectPumlModule],projectVirtuals=[...hmrProjectVirtuals,projectReactModule],virtuals=[projectsModule,modelModule,projectsOverviewModule,singleProjectModule,singleProjectReactModule,d2Module,dotModule,mmdModule,pumlModule,iconsModule,rpcModule];function LikeC4VitePlugin({environments:r,...i}){let o,s,c=i.watch??!1;return{name:`vite-plugin-likec4`,applyToEnvironment(i){return r?r.includes(i.name):!0},async configResolved(r){if(i.languageServices)o=i.languageServices;else{let a=c=i.watch??r.mode===`development`;o=(await fromWorkspace(i.workspace??r.root,{graphviz:i.graphviz??`wasm`,watch:a})).languageServices}s=o.workspaceUri.fsPath},resolveId(r){for(let i of projectVirtuals){let a=i.matches(r);if(a)return i.virtualId(a)}for(let i of virtuals)if(i.id===r)return i.virtualId;return null},async load(r){for(let i of projectVirtuals){let a=i.matches(r);if(a){let r=o.project(a);return await i.load({logger,likec4:o,project:r,assetsDir:s})}}for(let i of virtuals)if(i.virtualId===r){let r=o.projects();return invariant(isNonEmptyArray(r)),await i.load({logger,likec4:o,projects:r,assetsDir:s})}return null},configureServer(r){let i=r.hot;enablePluginRPC.call(this,{logger,likec4:o,server:r});let s=()=>t$3(o.projects(),r=>({id:r.id,title:r.title,folder:r.folder.toString()})),c=s(),l=async i=>{let a=r.moduleGraph.getModuleById(i);if(a&&a.importers.size>0)try{await r.reloadModule(a)}catch(r){logger.error(loggable(r))}};o.builder.onModelParsed(async()=>{let[r]=o.getErrors();if(r){i.send({type:`error`,err:{name:`LikeC4ValidationError`,...splitErrorMessage(r.message),plugin:`vite-plugin-likec4`,loc:{file:r.sourceFsPath,line:r.line,column:r.range.start.character+1}}});return}let d=s();if(!t$5(d,c)){c=d,await l(projectsModule.virtualId),await l(iconsModule.virtualId),await l(modelModule.virtualId),c.length>1&&await l(projectsOverviewModule.virtualId);return}for(let r of d)for(let i of hmrProjectVirtuals)await l(i.virtualId(r.id))})},async buildEnd(){c&&await o.dispose()}}}export{fromWorkspace as a,generateD2 as i,generatePuml as n,generateMermaid as r,LikeC4VitePlugin as t};
@@ -1 +0,0 @@
1
- import{H as n,I as t$8,J as t$7,L as t$1,X as t,_ as t$2,b as t$4,p as t$6,t as t$3,y as t$5}from"./libs/remeda.mjs";import{a as Variable,i as Strength,n as Constraint,r as Operator,t as Solver}from"./libs/@lume/kiwi.mjs";import{getParallelStepsPrefix,isStepEdgeId}from"@likec4/core/types";import{DefaultMap,Stack,invariant,isAncestor,nonNullable,nonexhaustive}from"@likec4/core/utils";function findParallelRects(e){return t(e,t$1(e=>e.parallelPrefix??void 0),t$2((e,r)=>e.reduce((e,r)=>(e.min.column=Math.min(e.min.column,r.from.column,r.to.column),e.min.row=Math.min(e.min.row,r.from.row,r.to.row),e.max.column=Math.max(e.max.column,r.from.column,r.to.column),e.max.row=Math.max(e.max.row,r.from.row,r.to.row),e),{parallelPrefix:r,min:{column:1/0,row:1/0},max:{column:-1/0,row:-1/0}})),t$3())}function buildCompounds(e,r){if(e.length===0||e.length===r.length)return[];let i=e=>nonNullable(r.find(r=>r.id===e));function a(e){let r=e.parent?i(e.parent):null;return r?[r,...a(r)]:[]}let o=new Stack,s=[];return e.forEach(e=>{let r=a(e);if(r.length===0){o.clear();return}let i=Stack.from(r),c,l;for(;c=o.peek()?.node,l=i.peek(),!(!l||!c);){if(isAncestor(l.id,c.id)||l.id===c.id){i.pop();continue}if(!isAncestor(c.id,l.id)){o.pop();continue}break}for(;l=i.pop();){let r={node:l,from:e,to:e,nested:[]},i=o.peek();i?i.nested.push(r):s.push(r),o.push(r)}o.forEach(r=>r.to=e)}),s}var SequenceViewLayouter=class{#e=new Solver;#t;#n=[];#r;#i;#a;#o=[];#s=[];constructor({actors:e,steps:r,compounds:i}){this.#a=this.newVar(30),this.#r=this.newVar(0),this.#i=this.newVar(0),this.#t=this.addActors(e);for(let e of i){let r=this.addCompound(e),i=r[0];this.constraint(i.y1,`==`,0,Strength.strong),this.put(this.#i).after(i.bottom),this.put(this.#a).after(i.y2),this.#n.push(...r)}for(let e of r)this.addStep(e);for(let e of findParallelRects(r))this.addParallelRect(e);let a=this.#t[0];this.constraint(a.offset.left,`==`,0,Strength.strong);let o=this.#t.reduce((e,r)=>(this.put(r.x).after(e.right,60),this.put(r.offset.left,Strength.strong).after(e.offset.right,32),this.constraint(r.centerY,`==`,e.centerY,Strength.strong),this.put(this.#a).after(r.offset.bottom),r));if(this.put(this.#r).after(o.offset.right),this.put(this.#i).after(t$4(this.#o)?.bottom??this.#a),i.length>0)for(let e of this.#n){let r=e.from.column,i=e.to.column,a=Math.max(e.from.maxRow,e.to.maxRow);for(let e=r+1;e<i;e++){let r=this.actorBox(e);a=Math.max(a,r.maxRow)}let o=nonNullable(this.#o[a],`row ${a} not found`);this.put(e.bottom).after(o.bottom,16),this.put(this.#i).after(e.bottom)}this.#e.updateVariables()}getParallelBoxes(){return this.#s.map(({parallelPrefix:e,x1:r,y1:i,x2:a,y2:o})=>({parallelPrefix:e,x:r.value(),y:i.value(),width:a.value()-r.value(),height:o.value()-i.value()}))}getActorBox(e){let r=this.actorBox(e);return{x:r.x.value(),y:r.y.value(),width:r.width,height:r.height}}getCompoundBoxes(){return this.#n.map(({node:e,depth:r,x1:i,y1:a,x2:o,bottom:s})=>({node:e,depth:r,x:i.value(),y:a.value(),width:o.value()-i.value(),height:s.value()-a.value()}))}getPortCenter(e,r){let{column:i,row:a}=r===`source`?e.from:e.to,o=this.actorBox(i).centerX,{y:s}=nonNullable(this.#o[a]);return{cx:o.value(),cy:s.value()+32/2+e.offset,height:r===`source`?40:24}}getViewBounds(){return{x:0,y:0,width:this.#r.value(),height:this.#i.value()}}actorBox(e){if(typeof e!=`number`){let r=typeof e==`string`?e:e.id;e=this.#t.findIndex(e=>e.actor.id===r),invariant(e>=0,`actor ${r} not found`)}return nonNullable(this.#t[e],`actor at index ${e} not found`)}addActors(e){let r=0;return t$5(e,(e,i)=>{let a=this.newVar(r);r+=e.width+60;let o=this.newVar(0),s={column:i,actor:e,x:a,y:o,centerX:a.plus(Math.round(e.width/2)),centerY:o.plus(Math.round(e.height/2)),width:e.width,height:e.height,right:a.plus(e.width),bottom:o.plus(e.height),minRow:1/0,maxRow:-1/0},c=this.newVar(0),l=this.newVar(0),u=this.newVar(0),d=this.newVar(0);return this.put(c,Strength.strong).before(o),this.put(l,Strength.strong).before(a),this.put(u,Strength.strong).after(s.right),this.put(d,Strength.strong).after(s.bottom),{...s,offset:{top:c,left:l,right:u,bottom:d}}})}addStep(e){let r=this.actorBox(e.source),i=this.actorBox(e.target);r.minRow=Math.min(r.minRow,e.from.row),r.maxRow=Math.max(r.maxRow,e.from.row),i.minRow=Math.min(i.minRow,e.to.row),i.maxRow=Math.max(i.maxRow,e.to.row);let[a,o]=r.column<=i.column?[r,i]:[i,r],s=(e.label?.width??100)+50;a===o?this.constraint(a.centerX.plus(s),`<=`,a.offset.right):this.constraint(a.centerX.plus(s),`<=`,o.centerX);let c=e.label?.height?e.label.height+50+32/2:80;return c=Math.max(c,80)+e.offset,this.ensureRow(e.from.row,c),e.isSelfLoop&&this.ensureRow(e.to.row,80),this}addParallelRect({parallelPrefix:e,min:r,max:i}){let a=this.actorBox(r.column).centerX.minus(30),o=this.actorBox(i.column).centerX.plus(30),s=this.#o[r.row],c=this.#o[i.row];invariant(s&&c,`parallel box invalid minRow=${r.row} maxRow=${i.row}`);let l=this.newVar(0);this.put(l).before(s.y,40);let u=c.bottom,d=r.row>0&&this.#o[r.row-1];d&&this.put(l).after(d.bottom,16);let f=i.row<this.#o.length-1&&this.#o[i.row+1];f&&this.put(u).before(f.y,16),this.#s.push({parallelPrefix:e,x1:a,y1:l,x2:o,y2:u})}addCompound(e){let r=[],i=e.nested.flatMap(e=>{let i=this.addCompound(e);return r.push(i[0]),i}),a=Math.max(...i.map(e=>e.depth+1),0),o=this.actorBox(e.from),s=this.actorBox(e.to),c=o.offset.left.minus(32);o.offset.left=c;let u=s.offset.right.plus(32);s.offset.right=u;let d=this.newVar(0),f=t$6(r),p,m;switch(!0){case!!f:p=f.y1.minus(40),m=f.y2.plus(32),this.put(d).after(f.bottom,32);break;case s===o:p=this.newVar(0),m=this.newVar(0),this.put(p).before(o.offset.top,52),this.put(m).after(o.offset.bottom,32),this.put(d).after(m);break;case r.length>0:p=this.newVar(0),m=this.newVar(0);for(let e of r)this.put(p).before(e.y1,32),this.put(m).after(e.y2,32),this.put(d).after(e.bottom,32);break;default:p=this.newVar(0),m=this.newVar(0);for(var h=o.column;h<=s.column;h++){let e=this.actorBox(h).offset;this.put(p).before(e.top,52),this.put(m).after(e.bottom,32)}this.put(d).after(m);break}for(var h=o.column;h<=s.column;h++){let e=this.actorBox(h).offset;e.top=p,e.bottom=m}return[{node:e.node,depth:a,from:o,to:s,x1:c,y1:p,x2:u,y2:m,bottom:d},...i]}ensureRow(e,r){for(;e>=this.#o.length;){let e=this.#o.length>0&&this.#o[this.#o.length-1]?.bottom||this.#a.plus(30),r=this.newVar(this.#o.length*80);this.put(r).after(e);let i=this.newVar(80);this.require(i,`>=`,80),this.#o.push({y:r,height:i,bottom:r.plus(i),lastHeight:80})}let i=nonNullable(this.#o[e]);r>i.lastHeight&&(i.lastHeight=r,this.require(i.height,`>=`,r),this.#e.suggestValue(i.height,r))}newVar(e){let r=new Variable;return this.#e.addEditVariable(r,Strength.weak),typeof e==`number`&&(this.#e.suggestValue(r,e),this.constraint(r,`>=`,0,Strength.strong)),r}require(e,r,i=void 0){switch(this.constraint(e,r,i,Strength.required),r){case`<=`:case`>=`:this.constraint(e,`==`,i,Strength.weak);break;case`<= 0`:case`>= 0`:this.constraint(e,`== 0`,void 0,Strength.weak);break}}constraint(e,r,i=void 0,a=Strength.medium){let o;switch(r){case`==`:o=Operator.Eq;break;case`>=`:o=Operator.Ge;break;case`<=`:o=Operator.Le;break;case`== 0`:o=Operator.Eq,i=0;break;case`>= 0`:o=Operator.Ge,i=0;break;case`<= 0`:o=Operator.Le,i=0;break;default:nonexhaustive(r)}this.#e.addConstraint(new Constraint(e,o,i??0,a))}put(e,r=Strength.required){let i=r===Strength.required?Strength.medium:Strength.weak;return{before:(a,o)=>{o&&(a=a.minus(o)),this.constraint(e,`<=`,a,r),this.constraint(e,`==`,a,i)},after:(a,o)=>{o&&(a=a.plus(o)),this.constraint(e,`>=`,a,r),this.constraint(e,`==`,a,i)}}}};function calcSequenceLayout(a){let c=new Set,l=e=>nonNullable(a.nodes.find(r=>r.id===e)),f=[];for(let e of a.edges.filter(e=>isStepEdgeId(e.id))){let r=l(e.source),i=l(e.target);if(r.children.length||i.children.length){console.error(`Sequence view does not support nested actors`);continue}c.add(r),c.add(i),f.push({edge:e,source:r,target:i})}let p=a.nodes.filter(e=>c.has(e));invariant(t$7(p,1),`actors array must not be empty`);let m=new DefaultMap(()=>[]),h=[],g=0;for(let{edge:e,source:r,target:i}of f){let a=h.at(-1),o=p.indexOf(r),s=p.indexOf(i),c=r===i,l=o>s,u=getParallelStepsPrefix(e.id),d=!1;a&&a.target==r&&a.parallelPrefix===u&&(d=a.isSelfLoop!==c||a.isBack===l),d||g++;let f={id:e.id,from:{column:o,row:g},to:{column:s,row:c?++g:g},edge:e,isSelfLoop:c,isBack:l,parallelPrefix:u,offset:d?(a?.offset??0)+22:0,source:r,target:i,label:e.labelBBox?{height:e.labelBBox.height+8+(e.navigateTo?20:0),width:e.labelBBox.width+16,text:e.label}:null};h.push(f),m.get(r).push({step:f,row:g,type:`source`,position:l&&!c?`left`:`right`}),m.get(i).push({step:f,row:g,type:`target`,position:l||c?`right`:`left`})}let _=new SequenceViewLayouter({actors:p,steps:h,compounds:buildCompounds(p,a.nodes)}),v=_.getViewBounds(),y=t(_.getCompoundBoxes(),t$5(({node:e,...r})=>({...r,id:e.id,origin:e.id})),t$8(`id`),t$2((e,r)=>t$7(e,2)?t$5(e,(e,i)=>({...e,id:`${r}-${i+1}`})):e),t$3(),n());return{actors:p.map(e=>toSeqActor({actor:e,ports:m.get(e),layout:_})),compounds:y,steps:t$5(h,e=>({id:e.id,sourceHandle:e.id+`_source`,targetHandle:e.id+`_target`,...e.label&&{labelBBox:{width:e.label.width,height:e.label.height}}})),parallelAreas:_.getParallelBoxes(),bounds:v}}function toSeqActor({actor:e,ports:r,layout:i}){let{x:a,y:o,width:s,height:c}=i.getActorBox(e);return{id:e.id,x:a,y:o,width:s,height:c,ports:r.map(e=>{let r=i.getPortCenter(e.step,e.type);return{id:`${e.step.id}_${e.type}`,cx:r.cx-a,cy:r.cy-o,height:r.height,type:e.type,position:e.position}})}}export{calcSequenceLayout as t};