likec4 1.55.1 → 1.56.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.
- package/__app__/chunks/ColorSchemeToggle.mjs +1 -0
- package/__app__/chunks/DiagramActorProvider.mjs +10 -0
- package/__app__/chunks/Fallback.mjs +1 -0
- package/__app__/chunks/Header.mjs +13 -0
- package/__app__/chunks/IconRenderer.mjs +1 -0
- package/__app__/chunks/LikeC4Diagram.mjs +19 -0
- package/__app__/chunks/LikeC4ModelContext.mjs +1 -0
- package/__app__/chunks/LikeC4ModelContext2.mjs +1 -0
- package/__app__/chunks/LikeC4Styles.mjs +48 -0
- package/__app__/chunks/NavigationPanel.mjs +1 -0
- package/__app__/chunks/StaticLikeC4Diagram.mjs +1 -0
- package/__app__/chunks/ViewReact.mjs +1 -0
- package/__app__/chunks/__root.mjs +1 -0
- package/__app__/chunks/adhoc-editor.mjs +1 -0
- package/__app__/chunks/hooks.mjs +1 -0
- package/__app__/chunks/libs/@dagrejs/dagre.mjs +1 -0
- package/__app__/chunks/libs/@floating-ui/core.mjs +1 -0
- package/__app__/chunks/libs/@floating-ui/dom.mjs +1 -0
- package/__app__/chunks/libs/@floating-ui/react.mjs +1 -0
- package/__app__/chunks/libs/@mantine/core.mjs +41 -0
- package/__app__/chunks/libs/@mantine/hooks.mjs +1 -0
- package/__app__/chunks/libs/@nanostores/react.mjs +1 -0
- package/__app__/chunks/libs/@react-hookz/web.mjs +1 -0
- package/__app__/chunks/libs/@tabler/icons-react.mjs +15 -0
- package/__app__/chunks/libs/@tanstack/history.mjs +1 -0
- package/__app__/chunks/libs/@tanstack/react-router.mjs +3 -0
- package/__app__/chunks/libs/@tanstack/router-core.mjs +1 -0
- package/__app__/chunks/libs/@xstate/react.mjs +1 -0
- package/__app__/chunks/libs/@xstate/store.mjs +1 -0
- package/__app__/chunks/libs/@xyflow/react.mjs +7 -0
- package/__app__/chunks/libs/@zag-js/anatomy.mjs +1 -0
- package/__app__/chunks/libs/@zag-js/collection.mjs +1 -0
- package/__app__/chunks/libs/@zag-js/core.mjs +1 -0
- package/__app__/chunks/libs/@zag-js/react.mjs +1 -0
- package/__app__/chunks/libs/@zag-js/tree-view.mjs +1 -0
- package/__app__/chunks/libs/bezier-js.mjs +1 -0
- package/__app__/chunks/libs/d3-path.mjs +1 -0
- package/__app__/chunks/libs/d3-shape.mjs +1 -0
- package/__app__/chunks/libs/fast-equals.mjs +1 -0
- package/__app__/chunks/libs/framer-motion.mjs +9 -0
- package/__app__/chunks/libs/html-to-image.mjs +2 -0
- package/__app__/chunks/libs/motion-dom.mjs +1 -0
- package/__app__/chunks/libs/motion.mjs +1 -0
- package/__app__/chunks/libs/nanostores.mjs +1 -0
- package/__app__/chunks/libs/react-error-boundary.mjs +1 -0
- package/__app__/chunks/libs/react-resizable-panels.mjs +1 -0
- package/__app__/chunks/libs/remeda.mjs +1 -0
- package/__app__/chunks/libs/xstate.mjs +1 -0
- package/__app__/chunks/libs/zod.mjs +39 -0
- package/__app__/chunks/rolldown-runtime.mjs +1 -0
- package/__app__/chunks/safeCtx.mjs +1 -0
- package/__app__/chunks/searchParams.mjs +1 -0
- package/__app__/chunks/single-index.mjs +1 -0
- package/__app__/chunks/styled-system.mjs +1 -0
- package/__app__/chunks/styles.css.mjs +1 -0
- package/__app__/chunks/useLikeC4Project.mjs +1 -0
- package/__app__/chunks/useUpdateEffect.mjs +1 -0
- package/__app__/codegen/react.mjs +11 -0
- package/__app__/codegen/webcomponent.mjs +790 -0
- package/__app__/src/fonts.css +1 -1
- package/__app__/src/main.mjs +1 -0
- package/__app__/src/pages/AdHocViewEditor.mjs +1 -0
- package/__app__/src/pages/EmbedPage.mjs +1 -0
- package/__app__/src/pages/ExportPage.mjs +1 -0
- package/__app__/src/pages/ProjectsOverview.mjs +1 -0
- package/__app__/src/pages/ViewAsD2.mjs +1 -0
- package/__app__/src/pages/ViewAsDot.mjs +1 -0
- package/__app__/src/pages/ViewAsMmd.mjs +1 -0
- package/__app__/src/pages/ViewAsPuml.mjs +1 -0
- package/__app__/src/pages/ViewEditor.mjs +1 -0
- package/__app__/src/pages/ViewReact.mjs +1 -0
- package/__app__/src/routeTree.gen.mjs +1 -0
- package/__app__/src/routes/__root.mjs +1 -0
- package/__app__/src/routes/_single/adhoc.mjs +1 -0
- package/__app__/src/routes/_single/embed._viewId.mjs +1 -0
- package/__app__/src/routes/_single/export._viewId.mjs +1 -0
- package/__app__/src/routes/_single/route.mjs +1 -0
- package/__app__/src/routes/_single/single-index.mjs +1 -0
- package/__app__/src/routes/_single/view._viewId.d2.mjs +1 -0
- package/__app__/src/routes/_single/view._viewId.dot.mjs +1 -0
- package/__app__/src/routes/_single/view._viewId.index.mjs +1 -0
- package/__app__/src/routes/_single/view._viewId.mjs +1 -0
- package/__app__/src/routes/_single/view._viewId.mmd.mjs +1 -0
- package/__app__/src/routes/_single/view._viewId.puml.mjs +1 -0
- package/__app__/src/routes/_single/webcomponent._.mjs +33 -0
- package/__app__/src/routes/index.mjs +1 -0
- package/__app__/src/routes/project._projectId/-components.mjs +1 -0
- package/__app__/src/routes/project._projectId/adhoc.mjs +1 -0
- package/__app__/src/routes/project._projectId/embed._viewId.mjs +1 -0
- package/__app__/src/routes/project._projectId/export._viewId.mjs +1 -0
- package/__app__/src/routes/project._projectId/index.mjs +1 -0
- package/__app__/src/routes/project._projectId/route.mjs +1 -0
- package/__app__/src/routes/project._projectId/view._viewId.d2.mjs +1 -0
- package/__app__/src/routes/project._projectId/view._viewId.dot.mjs +1 -0
- package/__app__/src/routes/project._projectId/view._viewId.index.mjs +1 -0
- package/__app__/src/routes/project._projectId/view._viewId.mjs +1 -0
- package/__app__/src/routes/project._projectId/view._viewId.mmd.mjs +1 -0
- package/__app__/src/routes/project._projectId/view._viewId.puml.mjs +1 -0
- package/__app__/src/routes/projects.mjs +1 -0
- package/__app__/src/style.css +1 -1
- package/dist/chunks/filenames.mjs +17 -0
- package/dist/{_chunks → chunks}/index.d.mts +2 -1
- package/dist/{_chunks → chunks}/index2.d.mts +70 -11
- package/dist/chunks/libs/@chevrotain/gast.mjs +1 -0
- package/dist/chunks/libs/@chevrotain/regexp-to-ast.mjs +9 -0
- package/dist/chunks/libs/@chevrotain/utils.mjs +1 -0
- package/dist/chunks/libs/@hono/mcp.mjs +45 -0
- package/dist/chunks/libs/@hono/node-server.mjs +1 -0
- package/dist/{_chunks → chunks}/libs/@logtape/logtape.d.mts +2 -0
- package/dist/chunks/libs/@logtape/logtape.mjs +4 -0
- package/dist/chunks/libs/@lume/kiwi.mjs +1 -0
- package/dist/chunks/libs/@modelcontextprotocol/sdk.mjs +12 -0
- package/dist/chunks/libs/ajv.mjs +1 -0
- package/dist/chunks/libs/ansi-align.mjs +2 -0
- package/dist/chunks/libs/ansi-regex.mjs +1 -0
- package/dist/chunks/libs/ansi-styles.mjs +1 -0
- package/dist/chunks/libs/atomically.mjs +1 -0
- package/dist/chunks/libs/birpc.mjs +1 -0
- package/dist/chunks/libs/boxen.mjs +22 -0
- package/dist/chunks/libs/chevrotain-allstar.mjs +2 -0
- package/dist/chunks/libs/chevrotain.mjs +58 -0
- package/dist/chunks/libs/conf.mjs +1 -0
- package/dist/chunks/libs/defu.mjs +1 -0
- package/dist/chunks/libs/destr.mjs +1 -0
- package/dist/chunks/libs/eventemitter3.mjs +1 -0
- package/dist/chunks/libs/find-up-simple.mjs +1 -0
- package/dist/chunks/libs/get-port.mjs +1 -0
- package/dist/chunks/libs/hono.mjs +1 -0
- package/dist/chunks/libs/is-docker.mjs +1 -0
- package/dist/chunks/libs/is-error-instance.mjs +1 -0
- package/dist/chunks/libs/is-inside-container.mjs +1 -0
- package/dist/chunks/libs/is-plain-obj.mjs +1 -0
- package/dist/chunks/libs/isexe.mjs +1 -0
- package/dist/chunks/libs/json5.mjs +14 -0
- package/dist/chunks/libs/khroma.mjs +1 -0
- package/dist/chunks/libs/ky.mjs +3 -0
- package/dist/{_chunks → chunks}/libs/langium.d.mts +4 -4
- package/dist/chunks/libs/langium.mjs +32 -0
- package/dist/chunks/libs/merge-error-cause.mjs +2 -0
- package/dist/chunks/libs/p-debounce.mjs +1 -0
- package/dist/chunks/libs/p-limit.mjs +1 -0
- package/dist/chunks/libs/p-queue.mjs +1 -0
- package/dist/chunks/libs/p-timeout.mjs +1 -0
- package/dist/chunks/libs/package-manager-detector.mjs +1 -0
- package/dist/chunks/libs/package-up.mjs +1 -0
- package/dist/chunks/libs/pako.mjs +1 -0
- package/dist/chunks/libs/parse-ms.mjs +1 -0
- package/dist/chunks/libs/pathe.mjs +1 -0
- package/dist/chunks/libs/picomatch.mjs +1 -0
- package/dist/chunks/libs/pretty-ms.mjs +1 -0
- package/dist/chunks/libs/remeda.mjs +1 -0
- package/dist/chunks/libs/safe-stringify.mjs +1 -0
- package/dist/chunks/libs/strip-indent.mjs +1 -0
- package/dist/chunks/libs/tinyrainbow.mjs +1 -0
- package/dist/{_chunks → chunks}/libs/ts-graphviz.d.mts +2 -0
- package/dist/chunks/libs/ts-graphviz.mjs +4 -0
- package/dist/chunks/libs/ufo.mjs +1 -0
- package/dist/chunks/libs/unstorage.mjs +1 -0
- package/dist/chunks/libs/which.mjs +1 -0
- package/dist/chunks/libs/word-wrap.mjs +12 -0
- package/dist/{_chunks → chunks}/libs/zod.d.mts +2 -0
- package/dist/chunks/node.mjs +76 -0
- package/dist/chunks/plugin.mjs +400 -0
- package/dist/chunks/rolldown-runtime.mjs +1 -0
- package/dist/chunks/sequence-view.mjs +1 -0
- package/dist/cli/index.mjs +262 -136
- package/dist/config/index.d.mts +1 -2
- package/dist/config/index.mjs +1 -1
- package/dist/index.d.mts +4 -8
- package/dist/index.mjs +1 -1
- package/dist/model/index.d.mts +2 -1
- package/dist/model/index.mjs +1 -1
- package/dist/vite-plugin/index.d.mts +38 -8
- package/dist/vite-plugin/index.mjs +1 -1
- package/dist/{_chunks → vite-plugin/internal/chunks}/libs/@nanostores/react.d.mts +2 -56
- package/dist/vite-plugin/internal/chunks/libs/@nanostores/react.mjs +1 -0
- package/dist/vite-plugin/internal/chunks/libs/birpc.mjs +1 -0
- package/dist/vite-plugin/internal/chunks/libs/fast-equals.mjs +1 -0
- package/dist/vite-plugin/internal/chunks/libs/nanostores.d.mts +59 -0
- package/dist/vite-plugin/internal/chunks/libs/nanostores.mjs +1 -0
- package/dist/vite-plugin/internal/chunks/libs/remeda.mjs +1 -0
- package/dist/vite-plugin/internal/chunks/rolldown-runtime.mjs +1 -0
- package/dist/vite-plugin/{internal.d.mts → internal/index.d.mts} +12 -3
- package/dist/vite-plugin/internal/index.mjs +1 -0
- package/package.json +35 -55
- package/react/index.d.mts +2 -28
- package/react/index.mjs +50520 -53863
- package/vite-plugin/internal/package.json +2 -2
- package/vite-plugin-modules.d.ts +14 -0
- package/__app__/react/likec4.tsx +0 -25
- package/__app__/src/ProjectsOverview.js +0 -16
- package/__app__/src/const.js +0 -19
- package/__app__/src/likec4.js +0 -21254
- package/__app__/src/main.js +0 -7
- package/__app__/src/routes/index.js +0 -324
- package/__app__/src/routes/projects.js +0 -193
- package/__app__/src/routes/single.js +0 -1983
- package/__app__/src/vendors.js +0 -52683
- package/__app__/src/webcomponent.js +0 -68
- package/dist/THIRD-PARTY-LICENSES.md +0 -1609
- package/dist/_chunks/libs/@chevrotain/cst-dts-gen.mjs +0 -30
- package/dist/_chunks/libs/@chevrotain/regexp-to-ast.mjs +0 -9
- package/dist/_chunks/libs/@chevrotain/types.d.mts +0 -1
- package/dist/_chunks/libs/@chevrotain/utils.mjs +0 -1
- package/dist/_chunks/libs/@hono/mcp.mjs +0 -45
- package/dist/_chunks/libs/@hono/node-server.mjs +0 -1
- package/dist/_chunks/libs/@logtape/logtape.mjs +0 -4
- package/dist/_chunks/libs/@lume/kiwi.mjs +0 -1
- package/dist/_chunks/libs/@modelcontextprotocol/sdk.mjs +0 -12
- package/dist/_chunks/libs/@nanostores/react.mjs +0 -1
- package/dist/_chunks/libs/ajv.mjs +0 -1
- package/dist/_chunks/libs/ansi-align.mjs +0 -2
- package/dist/_chunks/libs/ansi-regex.mjs +0 -1
- package/dist/_chunks/libs/ansi-styles.mjs +0 -1
- package/dist/_chunks/libs/atomically.mjs +0 -1
- package/dist/_chunks/libs/birpc.mjs +0 -1
- package/dist/_chunks/libs/boxen.mjs +0 -22
- package/dist/_chunks/libs/chevrotain-allstar.mjs +0 -2
- package/dist/_chunks/libs/chevrotain.mjs +0 -58
- package/dist/_chunks/libs/conf.mjs +0 -1
- package/dist/_chunks/libs/defu.mjs +0 -1
- package/dist/_chunks/libs/destr.mjs +0 -1
- package/dist/_chunks/libs/esm-env.mjs +0 -1
- package/dist/_chunks/libs/eventemitter3.mjs +0 -1
- package/dist/_chunks/libs/fast-equals.mjs +0 -1
- package/dist/_chunks/libs/find-up-simple.mjs +0 -1
- package/dist/_chunks/libs/get-port.mjs +0 -1
- package/dist/_chunks/libs/is-docker.mjs +0 -1
- package/dist/_chunks/libs/is-error-instance.mjs +0 -1
- package/dist/_chunks/libs/is-inside-container.mjs +0 -1
- package/dist/_chunks/libs/is-plain-obj.mjs +0 -1
- package/dist/_chunks/libs/isexe.mjs +0 -1
- package/dist/_chunks/libs/json5.mjs +0 -14
- package/dist/_chunks/libs/khroma.mjs +0 -1
- package/dist/_chunks/libs/ky.mjs +0 -3
- package/dist/_chunks/libs/langium.mjs +0 -33
- package/dist/_chunks/libs/merge-error-cause.mjs +0 -2
- package/dist/_chunks/libs/p-limit.mjs +0 -1
- package/dist/_chunks/libs/p-queue.mjs +0 -1
- package/dist/_chunks/libs/p-timeout.mjs +0 -1
- package/dist/_chunks/libs/package-manager-detector.mjs +0 -1
- package/dist/_chunks/libs/package-up.mjs +0 -1
- package/dist/_chunks/libs/pako.mjs +0 -1
- package/dist/_chunks/libs/parse-ms.mjs +0 -1
- package/dist/_chunks/libs/pathe.mjs +0 -1
- package/dist/_chunks/libs/picomatch.mjs +0 -1
- package/dist/_chunks/libs/pretty-ms.mjs +0 -1
- package/dist/_chunks/libs/remeda.mjs +0 -2
- package/dist/_chunks/libs/safe-stringify.mjs +0 -1
- package/dist/_chunks/libs/strip-indent.mjs +0 -1
- package/dist/_chunks/libs/tinyrainbow.mjs +0 -1
- package/dist/_chunks/libs/ts-graphviz.mjs +0 -4
- package/dist/_chunks/libs/ufo.mjs +0 -1
- package/dist/_chunks/libs/unstorage.mjs +0 -1
- package/dist/_chunks/libs/which.mjs +0 -1
- package/dist/_chunks/libs/word-wrap.mjs +0 -12
- package/dist/_chunks/node.mjs +0 -76
- package/dist/_chunks/rolldown-runtime.mjs +0 -1
- package/dist/_chunks/sequence.mjs +0 -1
- package/dist/_chunks/src.mjs +0 -17
- package/dist/_chunks/src2.mjs +0 -499
- package/dist/vite-plugin/internal.mjs +0 -1
- /package/dist/{_chunks → chunks}/libs/vscode-languageserver.mjs +0 -0
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import{i as e}from"./rolldown-runtime.mjs";import{c as t,f as n,n as r}from"./node.mjs";import{a as i,i as a,n as o,r as s,t as c}from"./libs/langium.mjs";import{t as l}from"./libs/tinyrainbow.mjs";import{o as u}from"./libs/ufo.mjs";import{t as d}from"./libs/json5.mjs";import{A as f,C as p,D as m,G as h,J as g,L as _,Q as v,U as y,X as b,o as x,r as S,t as C,v as w,y as T}from"./libs/remeda.mjs";import{t as E}from"./libs/p-debounce.mjs";import{t as D}from"./libs/birpc.mjs";import{t as O}from"./libs/pako.mjs";import{createRequire as k}from"node:module";import{DefaultMap as A,LikeC4Styles as j,invariant as ee,isNonEmptyArray as M,nonexhaustive as N}from"@likec4/core";import{resolve as P}from"node:path";import{RichText as F,flattenMarkdownOrString as I}from"@likec4/core/types";import{compareNatural as L}from"@likec4/core/utils";import"@likec4/core/model";import{existsSync as R}from"node:fs";import{mkdir as z,readFile as B,writeFile as te}from"node:fs/promises";import{cwd as ne}from"node:process";function isJsonStringifyOutput(e){if(e.length===0)return!1;try{return JSON.parse(e),!0}catch{return!1}}function hardenJsonStringLiteralForEmbeddedScript(e){if(typeof e!=`string`)throw TypeError(`hardenJsonStringLiteralForEmbeddedScript: expected JSON.stringify(...) output as a string`);if(!isJsonStringifyOutput(e))throw TypeError(`hardenJsonStringLiteralForEmbeddedScript: expected JSON.stringify(...) output (string, object, array, number, boolean, or null)`);return e.replaceAll(`<`,`\\u003C`).replaceAll(`>`,`\\u003E`).replaceAll(`/`,`\\u002F`).replaceAll(`\u2028`,`\\u2028`).replaceAll(`\u2029`,`\\u2029`)}function generateMatches(e,t=`.js`){return{matches:n=>{let{module:r,projectId:i}=n.match(/likec4:plugin\/(?<projectId>.+)\/(?<module>.+)$/)?.groups??n.match(/likec4:(?<module>.+)\/(?<projectId>.+)$/)?.groups??{};return!r||!i?null:(r.endsWith(t)&&(r=r.slice(0,-t.length)),r===e?i:null)},virtualId:n=>u(`likec4:plugin`,n,e)+t}}function generateCombinedProjects(e,t){return{id:`likec4:${e}`,virtualId:`likec4:plugin/`+e+`.js`,async load({projects:n}){return logGenerating(e),{code:`
|
|
2
|
+
export let ${t}Fn = {
|
|
3
|
+
${n.map(({id:t})=>`${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(t))}: async () => await import(${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(u(`likec4:${e}`,t)))})`).join(`,
|
|
4
|
+
`)}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export async function ${t}(projectId) {
|
|
8
|
+
let fn = ${t}Fn[projectId]
|
|
9
|
+
if (!fn) {
|
|
10
|
+
const projects = Object.keys(${t}Fn)
|
|
11
|
+
console.error('Unknown projectId: ' + projectId + ' (available: ' + projects + ')')
|
|
12
|
+
if (projects.length === 0) {
|
|
13
|
+
throw new Error('No projects found, invalid state')
|
|
14
|
+
}
|
|
15
|
+
projectId = projects[0]
|
|
16
|
+
console.warn('Falling back to project: ' + projectId)
|
|
17
|
+
fn = ${t}Fn[projectId]
|
|
18
|
+
}
|
|
19
|
+
return await fn()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (import.meta.hot) {
|
|
23
|
+
import.meta.hot.accept(md => {
|
|
24
|
+
if (!import.meta.hot.data.$update) {
|
|
25
|
+
import.meta.hot.data.$update = ${t}Fn
|
|
26
|
+
}
|
|
27
|
+
const update = md.${t}Fn
|
|
28
|
+
if (update) {
|
|
29
|
+
for (const [id, fn] of Object.entries(update)) {
|
|
30
|
+
import.meta.hot.data.$update[id] ??= fn
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
import.meta.hot.invalidate()
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
`,moduleType:`js`}}}}const V=t.getChild(`vite`);function logGenerating(e,t){t?V.info(l.dim(`generating `)+l.magenta(`likec4:${e}/`)+l.magentaBright(t)):V.info(l.dim(`generating `)+l.magenta(`likec4:${e}`))}const H=V.getChild(`icons`);function iconBundlePlugin(e){let t=ne(),n=[t];e.workspace&&n.unshift(e.workspace);let r=k(t),i,resolveIcon=async(e,t)=>{try{let i=r.resolve(`@likec4/icons/${e}/${t}`,{paths:n});return H.trace(l.dim(`found in package `)+i),await B(i,`utf-8`)}catch{return}},readFromCache=async(e,t)=>{if(i)try{let n=P(i,e,`${t}.js`);if(R(n))return H.trace(l.dim(`read cached `)+`${e}/${t}.js`),await B(n,`utf-8`)}catch{}},writeToCache=async(e,t,n)=>{if(i)try{let r=P(i,e);R(r)||await z(r,{recursive:!0});let a=P(r,`${t}.js`);await te(a,n),H.trace(l.dim(`written to cache `)+a)}catch(n){H.error(l.dim(`failed to write to cache `)+`${e}/${t}.js`,{error:n})}},fetchFromRemote=async(e,t)=>{let n=u(`https://icons.like-c4.dev`,e,`${t}.js`);H.trace(l.dim(`fetching `)+n);let r=await fetch(n);if(!r.ok)throw Error(`Failed to fetch icon: ${r.status} ${r.statusText}`);return await r.text()},a=new A(async e=>{try{let[t,n]=e.split(`:`);(n.endsWith(`.jsx`)||n.endsWith(`.js`))&&(n=n.slice(0,n.lastIndexOf(`.`))),H.debug(l.dim(`resolving `)+l.green(`${t}:${n}`));let r=await readFromCache(t,n);return r??=await resolveIcon(t,n),r||(r=await fetchFromRemote(t,n),await writeToCache(t,n,r),r)}catch(t){return H.error(l.dim(`failed to resolve icon `)+l.red(e),{error:t}),`
|
|
38
|
+
export default function NotFoundIcon() {
|
|
39
|
+
return null
|
|
40
|
+
}
|
|
41
|
+
`}});return{name:`likec4:icon-bundle`,applyToEnvironment(t){return e.environments?e.environments.includes(t.name):!0},configResolved({root:e,...t}){n.unshift(e),t.cacheDir&&(i=P(t.cacheDir,`likec4-icons`))},resolveId:{filter:{id:/likec4:icon-bundle/},handler(e){return{id:e,moduleSideEffects:!1}}},load:{filter:{id:/likec4:icon-bundle/},async handler(e){let t=e.split(`/`).slice(-2);if(!b(t,2))return null;let[n,r]=t;return{moduleType:`jsx`,code:await a.get(`${n}:${r}`)}}}}}async function calcAdhocView({logger:e,likec4:t},n){e.info([l.green(`adhoc:view`),l.dim(`project:`),n.projectId].join(` `));let r=await t.views.adhocView(n.predicates,n.projectId);return e.info([l.green(`adhoc:view`),`✅`].join(` `)),r}function splitErrorMessage(e){let t=e.split(`
|
|
42
|
+
`),n=/^\s+at\s+/,r=t.findIndex(e=>n.test(e));return r===-1&&(r=1),{message:t.slice(0,r).join(`
|
|
43
|
+
`),stack:t.slice(r).join(`
|
|
44
|
+
`)}}function sendError(e,{name:t,error:n}){e.hot.send({type:`error`,err:{...splitErrorMessage(n),name:t??`LikeC4PluginError`,plugin:`vite-plugin-likec4`}})}async function updateView({logger:e,likec4:t},n){e.info([l.green(`view:onChange`),l.dim(`project`),n.projectId,l.dim(`view`),n.viewId,l.dim(`change`),n.change.op].join(` `));let r=await t.editor.applyChange(n);if(!r.success){e.error(`Failed to apply view change:\n${r.error}`);let t=Error(r.error);throw t.stack=r.error,t}e.info([l.green(`view:onChange`),`✅`].join(` `))}function enablePluginRPC(e){let t=null,n=e.server;D({updateView:t=>updateView(e,t),calcAdhocView:t=>calcAdhocView(e,t)},{on:e=>n.hot.on(`likec4:rpc`,e),post:e=>n.hot.send(`likec4:rpc`,e),onFunctionError:(r,i)=>{e.logger.error(`RPC error in ${i}`,{error:r});let a=r.stack??r.message;try{t!==a&&(t=a,sendError(n,{name:r.name,error:a}))}catch(t){e.logger.error(`Failed to send error to client`,{error:t})}}})}function createAppConfigModule(e){let{webcomponentPrefix:t=`likec4`,pageTitle:n=`LikeC4`,useHashHistory:r=!1,theme:i=`auto`}=e||{};return{id:`likec4:app-config`,virtualId:`likec4:plugin/app-config.js`,async load(){return logGenerating(`app-config`),`
|
|
45
|
+
export let ComponentName = {
|
|
46
|
+
View: ${JSON.stringify(t+`-view`)},
|
|
47
|
+
Browser: ${JSON.stringify(t+`-browser`)},
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let BASE = import.meta.env.BASE_URL
|
|
51
|
+
if (!BASE.endsWith('/')) {
|
|
52
|
+
BASE = BASE + '/'
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export let pageTitle = ${JSON.stringify(n)}
|
|
56
|
+
export let useHashHistory = ${r}
|
|
57
|
+
|
|
58
|
+
export let basepath = useHashHistory ? '/' : BASE
|
|
59
|
+
|
|
60
|
+
export let isDevelopment = import.meta.env.DEV
|
|
61
|
+
|
|
62
|
+
export let defaultTheme = ${JSON.stringify(i)}
|
|
63
|
+
|
|
64
|
+
export let krokiD2SvgUrl = import.meta.env.VITE_KROKI_D2_SVG_URL || 'https://kroki.io/d2/svg'
|
|
65
|
+
export let krokiPumlSvgUrl = import.meta.env.VITE_KROKI_D2_SVG_URL || 'https://kroki.io/plantuml/svg'
|
|
66
|
+
|
|
67
|
+
`}}}const re=e(e=>e.charAt(0).toLocaleUpperCase()+e.slice(1),`capitalizeFirstLetter`),ie=e(e=>e.split(`.`).map(re).join(``),`fqnName`),ae=e(e=>ie(e.parent?e.id.slice(e.parent.length+1):e.id),`nodeName`),d2direction=({autoLayout:e})=>{switch(e.direction){case`TB`:return`down`;case`BT`:return`up`;case`LR`:return`right`;case`RL`:return`left`}},d2shape=({shape:e})=>{switch(e){case`queue`:case`cylinder`:case`rectangle`:case`document`:return e;case`person`:return`c4-person`;case`storage`:return`stored_data`;case`component`:case`bucket`:case`mobile`:case`browser`:return`rectangle`}};function generateD2(e){let t=e.$view,{nodes:n,edges:r}=t,i=new Map,printNode=(e,t)=>{let r=ae(e),a=(t?t+`.`:``)+r;i.set(e.id,a);let l=JSON.stringify(e.title),u=d2shape(e);return new o().append(r,`: {`,s).indent({indentedChildren:t=>t.append(`label: `,l,s).appendIf(u!==`rectangle`,`shape: `,u,s).appendIf(e.children.length>0,s,c(n.filter(t=>t.parent===e.id),e=>printNode(e,a))),indentation:2}).append(`}`,s)},printEdge=e=>new o().append(i.get(e.source),` -> `,i.get(e.target)).append(t=>e.label&&t.append(`: `,JSON.stringify(e.label)));return a(new o().append(`direction: `,d2direction(t),s,s).append(c(n.filter(e=>m(e.parent)),e=>printNode(e),{appendNewLineIfNotEmpty:!0})).appendIf(r.length>0,s,c(r,e=>printEdge(e),{appendNewLineIfNotEmpty:!0})))}const U=`data:page/id,likec4-`,oe=`diagrams.drawio`;function escapeXml(e){return e.replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`).replaceAll(`"`,`"`).replaceAll(`'`,`'`)}function parseDrawioRoundtripComments(e){let t=e.split(/\r?\n/),n={},r={},i={},a={},o=!1,s=0;for(;s<t.length;){let e=t[s];if(e==null){s+=1;continue}if(e.trim()===`// <likec4.layout.drawio>`){o=!0,s+=1;let e=[];for(;s<t.length&&t[s]?.trim()!==`// </likec4.layout.drawio>`;){let n=t[s]?.trim();n?.startsWith(`// `)&&e.push(n.slice(3)),s+=1}if(e.length>0)try{let t=e.join(`
|
|
68
|
+
`);n=JSON.parse(t)}catch{}s+=1;continue}if(e.trim()===`// <likec4.strokeColor.vertices>`){for(o=!0,s+=1;s<t.length&&t[s]?.trim()!==`// </likec4.strokeColor.vertices>`;){let e=t[s]?.trim();if(e?.startsWith(`// `)&&e.includes(`=`)){let t=e.slice(3).trim(),n=t.indexOf(`=`);if(n>0){let e=t.slice(0,n).trim(),i=t.slice(n+1).trim();e&&i&&(r[e]=i)}}s+=1}s+=1;continue}if(e.trim()===`// <likec4.strokeWidth.vertices>`){for(o=!0,s+=1;s<t.length&&t[s]?.trim()!==`// </likec4.strokeWidth.vertices>`;){let e=t[s]?.trim();if(e?.startsWith(`// `)&&e.includes(`=`)){let t=e.slice(3).trim(),n=t.indexOf(`=`);if(n>0){let e=t.slice(0,n).trim(),r=t.slice(n+1).trim();e&&r!==``&&(i[e]=r)}}s+=1}s+=1;continue}if(e.trim()===`// <likec4.edge.waypoints>`){for(o=!0,s+=1;s<t.length&&t[s]?.trim()!==`// </likec4.edge.waypoints>`;){let e=t[s]?.trim();if(e?.startsWith(`// `)){let t=e.slice(3).trim(),n=t.indexOf(` `);if(n>0){let e=t.slice(0,n).trim(),r=t.slice(n+1).trim();if(e&&r)try{let t=JSON.parse(r);Array.isArray(t)&&(a[e]=t)}catch{}}}s+=1}s+=1;continue}s+=1}return o?{layoutByView:n,strokeColorByFqn:r,strokeWidthByFqn:i,edgeWaypoints:a}:null}function compressDrawioDiagramXml(e){let t=encodeURIComponent(e),n=new TextEncoder().encode(t);return uint8ArrayToBase64(O.deflateRaw(n))}function uint8ArrayToBase64(e){if(typeof Buffer<`u`)return Buffer.from(e).toString(`base64`);let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}const W={getNotes(e){return e.notes},getSummary(e){return e.summary},getTags(e){return e.tags},getNavigateTo(e){return e.navigateTo},getIcon(e){return e.icon},getLinks(e){return e.links},getNotation(e){return e.notation},getCustomData(e){return e.customData},getChildren(e){return e.children}},G={getKind(e){return e.kind},getNotation(e){return e.notation},getLinks(e){return e.links},getMetadata(e){return e.metadata},getCustomData(e){return e.customData}};function getEffectiveStyles(e){return e.$styles??j.DEFAULT}function escapeHtml(e){return e.replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`).replaceAll(`"`,`"`)}function toNonEmptyString(e){if(e==null)return``;let t=typeof e;if(t===`string`){let t=e;return t.trim()===``?``:t}return t===`number`||t===`boolean`?String(e):``}function getContainerDashedStyle(e,t){return e&&t!==`none`||t===`dashed`?`dashed=1;`:``}function getDefaultStrokeWidth(e,t){return e===`none`?`0`:t||e?`1`:``}function applyStrokeColorOverride(e,t){return{fill:e?.fill??`#dae8fc`,stroke:t,font:e?.font??t}}function resolveThemeColor(e,t,n){return t&&t in e.theme.colors?t:n}function getThemeColorValues(e,t,n){let r=getEffectiveStyles(e),i=resolveThemeColor(r,t??n,n);try{return r.colors(i)}catch{return j.DEFAULT.colors(n)}}function drawioShape(e){let t=`shape=rectangle;rounded=1;arcSize=12;`;switch(e){case`person`:return`shape=actor;`;case`rectangle`:case`browser`:case`mobile`:case`bucket`:return t;case`cylinder`:case`queue`:case`storage`:return`shape=cylinder3;whiteSpace=wrap;boundedLbl=1;backgroundOutline=1;size=15;`;case`document`:return`shape=document;whiteSpace=wrap;html=1;boundedLbl=1;`;case`component`:return`shape=component;`;default:return t}}function getElementColors(e,t){let n=getThemeColorValues(e,t,`primary`).elements;return{fill:String(n.fill??`#dae8fc`),stroke:String(n.stroke??`#2563eb`),font:String(n.hiContrast??n.stroke??`#1e40af`)}}function getEdgeStrokeColor(e,t){let n=getThemeColorValues(e,t??`gray`,`gray`);return String(n.relationships?.line??`#1e40af`)}function getEdgeLabelColors(e,t){let n=getThemeColorValues(e,t??`gray`,`gray`).relationships;return{font:String(n?.label??n?.line??`#1e40af`),background:String(n?.labelBg??`#ffffff`)}}function edgeAnchors(e,t){let n=e.x+e.width/2,r=e.y+e.height/2,i=t.x+t.width/2,a=t.y+t.height/2,o=i-n,s=a-r,c=Math.abs(o)>=Math.abs(s);return{exitX:c?+(o>=0):.5,exitY:c?.5:+(s>=0),entryX:c?o>=0?0:1:.5,entryY:c?.5:s>=0?0:1}}function normalizeEdgePoint(e){if(Array.isArray(e)&&e.length>=2&&typeof e[0]==`number`&&typeof e[1]==`number`)return[[e[0],e[1]]];let t=e;return typeof t.x==`number`&&typeof t.y==`number`?[[t.x,t.y]]:[]}function buildNodeValueHtml(e,t,n,r,i,a){return n?``:t===``?`<div style="box-sizing:border-box;width:100%;min-height:100%;display:flex;align-items:center;justify-content:center;text-align:center;color:${r};font-family:${i};"><b style="font-size:${a}px;">${escapeHtml(e)}</b></div>`:`<div style="box-sizing:border-box;width:100%;min-height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;color:${r};font-family:${i};"><b style="font-size:${a}px;">${escapeHtml(e)}</b><br/><span style="font-weight:normal;font-size:${a}px;">${escapeHtml(t)}</span></div>`}function pushStylePart(e,t,n){n!=null&&n!==``&&e.push(`${t}=${encodeURIComponent(n)}`)}function pushStylePartNum(e,t,n){n!=null&&e.push(`${t}=${n}`)}function buildNavLinkStyle(e){return e===``?``:`link=${encodeURIComponent(`${U}${e}`)};`}function toExportString(e){let t=e==null?null:I(e);return t!=null&&!f(t)?t.trim():``}function linksToStyleJson(e){return!Array.isArray(e)||e.length===0?``:encodeURIComponent(JSON.stringify(e.map(e=>({url:e.url,title:e.title}))))}function metadataToStyleJson(e){return typeof e!=`object`||!e||Array.isArray(e)||Object.keys(e).length===0?``:encodeURIComponent(JSON.stringify(e))}const se=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{4}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/;function buildLikec4StyleForNode(e){let t=[];return pushStylePart(t,`likec4Description`,e.desc),pushStylePart(t,`likec4Technology`,e.tech),pushStylePart(t,`likec4Notes`,e.notes),pushStylePart(t,`likec4Tags`,e.tagList),pushStylePart(t,`likec4NavigateTo`,e.navTo),pushStylePart(t,`likec4Icon`,e.iconName),pushStylePart(t,`likec4Summary`,e.summaryStr),e.linksJson!==``&&t.push(`likec4Links=${e.linksJson}`),pushStylePart(t,`likec4Border`,e.borderVal),pushStylePartNum(t,`likec4Opacity`,e.containerOpacityNum),pushStylePart(t,`likec4StrokeWidth`,e.strokeWidth),e.colorNameForRoundtrip!==``&&t.push(`likec4ColorName=${e.colorNameForRoundtrip}`),pushStylePart(t,`likec4Size`,e.nodeStyle?.size),pushStylePart(t,`likec4Padding`,e.nodeStyle?.padding),pushStylePart(t,`likec4TextSize`,e.nodeStyle?.textSize),pushStylePart(t,`likec4IconPosition`,e.nodeStyle?.iconPosition),e.strokeHex&&se.test(e.strokeHex)&&pushStylePart(t,`likec4StrokeColor`,e.strokeHex),pushStylePart(t,`likec4Notation`,e.nodeNotation??void 0),t.length>0?t.join(`;`)+`;`:``}function buildBridgeManagedStyleForNode(e,t,n,r){if(r?.profile!==`leanix`)return``;let i=[`bridgeManaged=true`,`likec4Id=${encodeURIComponent(e)}`,`likec4Kind=${encodeURIComponent(t)}`,`likec4ViewId=${encodeURIComponent(n)}`];r.projectId!=null&&r.projectId!==``&&i.push(`likec4ProjectId=${encodeURIComponent(r.projectId)}`);let a=r.leanixFactSheetTypeByKind?.[t];return a!=null&&a!==``&&i.push(`leanixFactSheetType=${encodeURIComponent(a)}`),i.join(`;`)+`;`}function buildBridgeManagedStyleForEdge(e,t){return t?.profile===`leanix`?`bridgeManaged=true;likec4RelationId=${encodeURIComponent(e)};`:``}function buildMxUserObjectXml(e){return!e||typeof e!=`object`||Array.isArray(e)||Object.keys(e).length===0?``:`
|
|
69
|
+
<mxUserObject>`+Object.entries(e).map(([e,t])=>{let n=typeof t==`string`?t:t==null?``:String(t);return`<data key="${escapeXml(e)}">${escapeXml(n)}</data>`}).join(``)+`</mxUserObject>`}function buildLikec4StyleForEdge(e){let t=[];return pushStylePart(t,`likec4Description`,e.edgeDesc),pushStylePart(t,`likec4Technology`,e.edgeTech),pushStylePart(t,`likec4Notes`,e.edgeNotes),pushStylePart(t,`likec4NavigateTo`,e.edgeNavTo),pushStylePart(t,`likec4RelationshipKind`,e.edgeKind??void 0),pushStylePart(t,`likec4Notation`,e.edgeNotation??void 0),e.edgeLinksJson!==``&&t.push(`likec4Links=${e.edgeLinksJson}`),e.edgeMetadataJson!==``&&t.push(`likec4Metadata=${e.edgeMetadataJson}`),t.length>0?t.join(`;`)+`;`:``}function buildEdgeLabelValue(e){return e.label?escapeXml(e.label):``}function buildEdgeGeometryXml(e,t){let n=t?.[`${e.source}|${e.target}|${e.id}`]??t?.[`${e.source}|${e.target}`],r=Array.isArray(n)?n.flatMap(normalizeEdgePoint):[];return r.length>0?`<mxGeometry relative="1" as="geometry">${`<Array as="points">`+r.map(([e,t])=>`<mxPoint x="${Math.round(e)}" y="${Math.round(t)}"/>`).join(``)+`</Array>`}</mxGeometry>`:`<mxGeometry relative="1" as="geometry" />`}function buildEdgeStyleString(e,t,n,r,i){let{bboxes:a,fontFamily:o}=t,s=a.get(e.source),c=a.get(e.target),l=s&&c?edgeAnchors(s,c):{exitX:1,exitY:.5,entryX:0,entryY:.5},u=`exitX=${l.exitX};exitY=${l.exitY};entryX=${l.entryX};entryY=${l.entryY};`,d=getEdgeStrokeColor(n,e.color),f=e.line===`dashed`?`dashed=1;`:e.line===`dotted`?`dashed=1;dashPattern=1 1;`:``,p=drawioArrow(e.head),m=e.tail==null||e.tail===`none`?`none`:drawioArrow(e.tail),h=buildLikec4StyleForEdge({edgeDesc:toExportString(e.description),edgeTech:toExportString(e.technology),edgeNotes:toExportString(e.notes),edgeNavTo:toNonEmptyString(e.navigateTo),edgeKind:G.getKind(e),edgeNotation:G.getNotation(e),edgeLinksJson:linksToStyleJson(G.getLinks(e)),edgeMetadataJson:metadataToStyleJson(G.getMetadata(e))}),g=buildBridgeManagedStyleForEdge(e.id,i),_=getEdgeLabelColors(n,e.color);return`endArrow=${p};startArrow=${m};html=1;rounded=0;${u}strokeColor=${d};strokeWidth=2;${f}${r===``?``:`fontColor=${_.font};fontSize=12;align=center;verticalAlign=middle;labelBackgroundColor=none;fontFamily=${encodeURIComponent(o)};`}${h}${g}`}function buildEdgeCellXml(e,t,n,r,i,a){let{defaultParentId:o}=t,s=i(e.source),c=i(e.target),l=buildEdgeLabelValue(e),u=buildEdgeGeometryXml(e,n?.edgeWaypoints);return`<mxCell id="${a}" value="${l}" style="${buildEdgeStyleString(e,t,r,l,n)}" edge="1" parent="${o}" source="${s}" target="${c}">
|
|
70
|
+
${u}${buildMxUserObjectXml(G.getCustomData(e))}
|
|
71
|
+
</mxCell>`}function computeNodeGeometry(e,t,n){let{bboxes:r,defaultParentId:i,nodeIdsInView:a}=t,o=n(e.id),s=r.get(e.id),{width:c,height:l}=s,u=e.parent!=null&&a.has(e.parent)?n(e.parent):i,d=e.parent==null?void 0:r.get(e.parent);return{id:o,parentId:u,x:d==null?s.x+t.offsetX:s.x-d.x,y:d==null?s.y+t.offsetY:s.y-d.y,width:c,height:l}}function computeNodeStylePartsAndValue(e,t,n,r){let{containerNodeIds:i,effectiveStyles:a,fontFamily:o,containerTitleFontSizePx:s,containerTitleColor:c}=t,l=n?.strokeColorByNodeId,u=n?.strokeWidthByNodeId,d=i.has(e.id),f=e.kind??``,p=e.title,m=toExportString(e.description),h=toExportString(e.technology),g=toExportString(W.getNotes(e)),_=W.getTags(e),v=Array.isArray(_)&&_.length>0?_.join(`,`):``,y=toNonEmptyString(W.getNavigateTo(e)),b=toNonEmptyString(W.getIcon(e)),x=f===`actor`||e.shape===`person`,S=d?`shape=rectangle;rounded=0;container=1;collapsible=0;startSize=0;`:x?`shape=actor;`:drawioShape(e.shape),C=l?.[e.id],w=u?.[e.id],T=C?applyStrokeColorOverride(getElementColors(r,e.color),C):getElementColors(r,e.color),E=T?.fill??`#dae8fc`,D=T?.stroke??`#2563eb`,O=T?.font??T?.stroke??`#1e40af`,k=`fillColor=${E};strokeColor=${D};fontColor=${O};`,A=e.style,j=a.fontSize(A?.textSize),ee=escapeXml(buildNodeValueHtml(p,m,d,O,o,j)),M=A?.border,N=w??getDefaultStrokeWidth(M,d),P=N===``?``:`strokeWidth=${N};`,F=getContainerDashedStyle(d,M),I=d===!0?A?.opacity??15:void 0,L=I!=null&&d===!0?`fillOpacity=${Math.min(100,Math.max(0,I))};`:``,R=buildLikec4StyleForNode({desc:m,tech:h,notes:g,tagList:v,navTo:y,iconName:b,summaryStr:toExportString(W.getSummary(e)),linksJson:linksToStyleJson(W.getLinks(e)),borderVal:M,containerOpacityNum:I,strokeWidth:N,colorNameForRoundtrip:e.color?encodeURIComponent(String(e.color)):``,nodeStyle:A,strokeHex:D,nodeNotation:W.getNotation(e)})+buildBridgeManagedStyleForNode(e.id,f,t.view.id,n),z=buildMxUserObjectXml(W.getCustomData(e)),B=buildNavLinkStyle(y);return{value:ee,styleStr:`${d?`align=left;verticalAlign=top;overflow=fill;whiteSpace=wrap;html=1;`:`align=center;verticalAlign=middle;verticalLabelPosition=middle;labelPosition=center;fontSize=${j};fontStyle=1;spacingTop=4;spacingLeft=2;spacingRight=2;spacingBottom=2;overflow=fill;whiteSpace=wrap;html=1;fontFamily=${encodeURIComponent(o)};`}${S}${k}${P}${F}${L}${B}${R}`,userObjectXml:z,navTo:y,isContainer:d,title:p,fontFamily:o,containerTitleFontSizePx:s,containerTitleColor:c}}function computeNodeCellExportData(e,t,n,r,i,a){let o=computeNodeGeometry(e,t,i),s=computeNodeStylePartsAndValue(e,t,n,r);return{...o,value:s.value,styleStr:s.styleStr,userObjectXml:s.userObjectXml,navTo:s.navTo,isContainer:s.isContainer,fontFamily:s.fontFamily,...s.isContainer&&{title:s.title??``,titleCellId:String(a),containerTitleFontSizePx:s.containerTitleFontSizePx,containerTitleColor:s.containerTitleColor}}}function buildNodeCellXml(e){let t=`<mxGeometry height="${Math.round(e.height)}" width="${Math.round(e.width)}" x="${Math.round(e.x)}" y="${Math.round(e.y)}" as="geometry" />`,n=e.userObjectXml===``?`\n ${t}`:`${e.userObjectXml}\n ${t}`,r=e.isContainer&&e.title!=null?escapeXml(e.title):e.value,i=e.navTo===``?`<mxCell id="${e.id}" value="${e.value}" style="${e.styleStr}" vertex="1" parent="${e.parentId}">\n ${n}\n</mxCell>`:`<UserObject label="${r}" link="${U}${escapeXml(e.navTo)}" id="${e.id}">\n <mxCell parent="${e.parentId}" style="${e.styleStr}" value="${e.value}" vertex="1">\n ${n}\n</mxCell>\n</UserObject>`;return e.isContainer?{vertexXml:i,titleCellXml:buildContainerTitleCellXml(e.title??``,e.titleCellId??e.id,e.navTo,e.id,e.fontFamily,e.containerTitleFontSizePx??12,e.containerTitleColor??`#74c0fc`),isContainer:!0}:{vertexXml:i,isContainer:!1}}function buildContainerTitleCellXml(e,t,n,r,i,a,o){let s=escapeXml(e),c=Math.max(60,Math.min(260,e.length*8)),l=buildNavLinkStyle(n),u=`shape=text;html=1;fillColor=none;strokeColor=none;align=left;verticalAlign=top;fontSize=${a};fontStyle=1;fontColor=${o};fontFamily=${encodeURIComponent(i)};${l}`;if(n===``)return`<mxCell id="${t}" value="${s}" style="${u}" vertex="1" parent="${r}">\n <mxGeometry x="8" y="8" width="${c}" height="18" as="geometry" />\n</mxCell>`;let d=`<mxCell parent="${r}" style="${u}" value="${s}" vertex="1">\n <mxGeometry x="8" y="8" width="${c}" height="18" as="geometry" />\n</mxCell>`;return`<UserObject label="${escapeXml(e)}" link="${U}${escapeXml(n)}" id="${t}">\n ${d}\n</UserObject>`}function getViewTitle(e){return typeof e.title==`string`?e.title:null}function getViewDescriptionString(e){let t=e.description;return typeof t==`object`&&t&&`txt`in t?String(t.txt):typeof t==`object`&&t&&`md`in t?String(t.md):typeof t==`string`?t:``}function getLeanixRootStyleParts(e,t){let n=[`bridgeManaged=true;`,`likec4ViewId=${encodeURIComponent(e.id)};`];return t.projectId!=null&&t.projectId!==``&&n.push(`likec4ProjectId=${encodeURIComponent(t.projectId)};`),n}function buildRootCellStyle(e,t){let n=getViewTitle(e),r=getViewDescriptionString(e),i=r.trim()===``?``:encodeURIComponent(r.trim()),a=e.notation,o=typeof a==`string`&&a!==``?a:void 0,s=o==null?``:encodeURIComponent(o),c=[`rounded=1;whiteSpace=wrap;html=1;fillColor=none;strokeColor=none;`,`likec4ViewTitle=${encodeURIComponent(n??e.id)};`,i===``?``:`likec4ViewDescription=${i};`,s===``?``:`likec4ViewNotation=${s};`];return t?.profile===`leanix`&&c.push(...getLeanixRootStyleParts(e,t)),c.join(``)}function drawioArrow(e){switch(e){case`none`:return`none`;case`open`:case`onormal`:case`vee`:return`open`;case`diamond`:case`odiamond`:return`diamond`;case`dot`:case`odot`:return`oval`;case`crow`:return`block`;default:return`block`}}const K={x:0,y:0,width:120,height:60};function isDefaultBbox(e){return e.x===K.x&&e.y===K.y&&e.width===K.width&&e.height===K.height}function spreadUnlaidNodesOverVertical(e,t,n){let bboxKey=e=>`${e.x},${e.y},${e.width},${e.height}`,r=t.filter(e=>!n.has(e.id)),i=new Map;for(let t of r){let n=e.get(t.id);if(!n)continue;let r=bboxKey(n),a=i.get(r)??[];a.push(t),i.set(r,a)}for(let t of i.values()){if(t.length<=1)continue;let n=t[0],r=n?e.get(n.id):void 0;r&&isDefaultBbox(r)&&t.forEach((t,n)=>{e.set(t.id,{...r,x:r.x,y:r.y+n*(r.height+24)})})}}function computeContainerBboxesFromChildren(e,t,n,r,i,a){let o=[...n].filter(e=>t.has(e.id)).sort((e,t)=>(t.level??0)-(e.level??0));for(let t of o){let n=(W.getChildren(t)??[]).filter(e=>r.has(e));if(n.length===0||!isDefaultBbox(e.get(t.id)))continue;let o=1/0,s=1/0,c=-1/0,l=-1/0;for(let t of n){let n=e.get(t);n&&(o=Math.min(o,n.x),s=Math.min(s,n.y),c=Math.max(c,n.x+n.width),l=Math.max(l,n.y+n.height))}o!==1/0&&e.set(t.id,{x:o-i,y:s-a,width:c-o+2*i,height:l-s+2*a})}}function computeContentBoundsAndOffsets(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e.values())t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x+a.width),i=Math.max(i,a.y+a.height);t===1/0&&(t=0),n===1/0&&(n=0),r===-1/0&&(r=t+800),i===-1/0&&(i=n+600);let a=t+(r-t)/2,o=n+(i-n)/2;return{offsetX:800/2-a,offsetY:600/2-o,canvasWidth:800,canvasHeight:600}}function computeDiagramLayout(e,t){let n=e.$view,{nodes:r}=n,i=t?.layoutOverride,a=[...r].sort((e,t)=>m(e.parent)&&m(t.parent)?0:m(e.parent)?-1:m(t.parent)?1:e.parent===t.parent?0:e.id.startsWith(t.id+`.`)?1:t.id.startsWith(e.id+`.`)?-1:0),getBBox=e=>{let t=i?.[e.id];if(t)return t;let n=e;return{x:typeof n.x==`number`?n.x:Array.isArray(n.position)?n.position[0]:0,y:typeof n.y==`number`?n.y:Array.isArray(n.position)?n.position[1]:0,width:typeof n.width==`number`?n.width:n.size?.width??120,height:typeof n.height==`number`?n.height:n.size?.height??60}},o=new Map;for(let e of a)o.set(e.id,getBBox(e));let s=new Set(r.map(e=>e.id)),c=new Set(r.filter(e=>{let t=W.getChildren(e);return Array.isArray(t)&&t.some(e=>s.has(e))}).map(e=>e.id));spreadUnlaidNodesOverVertical(o,a,c);let l=getEffectiveStyles(e),u=l.theme.spacing.xl;computeContainerBboxesFromChildren(o,c,a,s,u,l.theme.spacing.xl+l.theme.spacing.md);let{offsetX:d,offsetY:f,canvasWidth:p,canvasHeight:h}=computeContentBoundsAndOffsets(o);return{view:n,bboxes:o,containerNodeIds:c,sortedNodes:a,offsetX:d,offsetY:f,canvasWidth:p,canvasHeight:h,defaultParentId:`1`,rootId:`0`,effectiveStyles:l,fontFamily:`'IBM Plex Sans Variable',ui-sans-serif,system-ui,sans-serif`,containerTitleFontSizePx:Math.round(l.theme.textSizes.xs),containerTitleColor:`#74c0fc`,nodeIdsInView:s}}function generateDiagramContent(e,t){let n=e.$view,{edges:r}=n,i=t?.compressed!==!1,a=computeDiagramLayout(e,t),{sortedNodes:o,defaultParentId:s,rootId:c,canvasWidth:l,canvasHeight:u}=a,d=new Map,f=2,getCellId=e=>{let t=d.get(e);if(!t){if(f>=1e4)throw Error(`DrawIO cell ID range exhausted`);t=String(f++),d.set(e,t)}return t},p=[],m=[],h=[],g=1e4;for(let n of o){let r=buildNodeCellXml(computeNodeCellExportData(n,a,t,e,getCellId,g));r.isContainer?(p.push(r.vertexXml),r.titleCellXml&&p.push(r.titleCellXml),g++):m.push(r.vertexXml)}for(let n of r){if(f>=1e4)throw Error(`DrawIO cell ID range exhausted`);let r=String(f++);h.push(buildEdgeCellXml(n,a,t,e,getCellId,r))}let _=[`<mxCell id="${s}" value="" style="${buildRootCellStyle(n,t)}" vertex="1" parent="${c}">
|
|
72
|
+
<mxGeometry x="0" y="0" width="${l}" height="${u}" as="geometry" />
|
|
73
|
+
</mxCell>`,...p,...m,...h].join(`
|
|
74
|
+
`),v=(getViewTitle(n)??n.id).trim()||n.id,y=`<mxGraphModel dx="800" dy="800" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
|
75
|
+
<root>
|
|
76
|
+
<mxCell id="${c}" />
|
|
77
|
+
${_}
|
|
78
|
+
</root>
|
|
79
|
+
</mxGraphModel>`,b=i?compressDrawioDiagramXml(y):y;return{name:v,id:n.id,content:b}}function wrapInMxFile(e,t){let n=escapeXml(t??new Date().toISOString());return e.length===0?`<?xml version="1.0" encoding="UTF-8"?>
|
|
80
|
+
<mxfile host="LikeC4" modified="${n}" agent="LikeC4" version="1.0" etag="" type="device">
|
|
81
|
+
</mxfile>
|
|
82
|
+
`:`<?xml version="1.0" encoding="UTF-8"?>
|
|
83
|
+
<mxfile host="LikeC4" modified="${n}" agent="LikeC4" version="1.0" etag="" type="device"${e.length>1?` pages="${e.length}"`:``}>
|
|
84
|
+
${e.map(e=>` <diagram name="${escapeXml(e.name)}" id="likec4-${escapeXml(e.id)}">${e.content}</diagram>`).join(`
|
|
85
|
+
`)}
|
|
86
|
+
</mxfile>
|
|
87
|
+
`}function generateDrawio(e,t){return wrapInMxFile([generateDiagramContent(e,t)],t?.modified)}function generateDrawioMulti(e,t,n){return wrapInMxFile(e.map(e=>generateDiagramContent(e,t?.[e.$view.id])),n)}function buildOptionsFromRoundtrip(e,t,n){let r={compressed:!1,...n};if(!t)return r;let i=t.layoutByView[e]?.nodes;return i!=null&&(r.layoutOverride=i),Object.keys(t.strokeColorByFqn).length>0&&(r.strokeColorByNodeId=t.strokeColorByFqn),Object.keys(t.strokeWidthByFqn).length>0&&(r.strokeWidthByNodeId=t.strokeWidthByFqn),Object.keys(t.edgeWaypoints).length>0&&(r.edgeWaypoints=t.edgeWaypoints),r}function buildDrawioExportOptionsForViews(e,t,n){let r=t?parseDrawioRoundtripComments(t):null;return Object.fromEntries(e.map(e=>[e,buildOptionsFromRoundtrip(e,r,n)]))}function generateDrawioEditUrl(e){let t=compressDrawioDiagramXml(e),n=JSON.stringify({type:`xml`,compressed:!0,data:t});return`https://app.diagrams.net/#create=`+encodeURIComponent(n)}const ce=e(e=>e.charAt(0).toLocaleUpperCase()+e.slice(1),`capitalizeFirstLetter`),le=e(e=>e.split(`.`).map(ce).join(``),`fqnName`),ue=e(e=>le(e.parent?e.id.slice(e.parent.length+1):e.id),`nodeName`),toSingleQuotes=e=>e.replace(/\\?"/g,`'`),mmdshape=({shape:e,title:t})=>{let n=`label: ${JSON.stringify(t)}`;switch(e){case`queue`:return`@{ shape: horizontal-cylinder, ${n} }`;case`person`:return`@{ icon: "fa:user", shape: rounded, ${n} }`;case`storage`:return`@{ shape: disk, ${n} }`;case`cylinder`:return`@{ shape: cylinder, ${n} }`;case`mobile`:case`browser`:return`@{ shape: rounded, ${n} }`;case`bucket`:return`@{ shape: trap-t, ${n} }`;case`rectangle`:return`@{ shape: rectangle, ${n} }`;case`document`:return`@{ shape: doc, ${n} }`;case`component`:return`@{ shape: rectangle, ${n} }`;default:N(e)}};function generateMermaid(e){let t=e.$view,{nodes:n,edges:r}=t,i=new Map,printNode=(e,t)=>{let r=ue(e),a=(t?t+`.`:``)+r;i.set(e.id,a);let l=new o;if(e.children.length>0){let t=toSingleQuotes(e.title);l.append(`subgraph `,a,'["`',t,'`"]',s).indent({indentedChildren:[c(n.filter(t=>t.parent===e.id),e=>printNode(e,a),{appendNewLineIfNotEmpty:!0})],indentation:2}).append(`end`,s)}else l.append(a,mmdshape(e));return l},printEdge=e=>new o().append(i.get(e.source),` -.`,e.label?' "`'+toSingleQuotes(e.label)+'`" .-':`-`,`> `,i.get(e.target));return a(new o().append(`---`,s,`title: ${JSON.stringify(toSingleQuotes(e.titleOrId))}`,s,`---`,s).append(`graph `,t.autoLayout.direction,s).indent({indentedChildren:e=>{e.append(c(n.filter(e=>m(e.parent)),e=>printNode(e),{appendNewLineIfNotEmpty:!0})).appendIf(r.length>0,c(r,e=>printEdge(e),{appendNewLineIfNotEmpty:!0}))},indentation:2}))}const capitalizeFirstLetter=e=>e.charAt(0).toLocaleUpperCase()+e.slice(1),fqnName=e=>e.split(/[.-]/).map(capitalizeFirstLetter).join(``),nodeName=e=>fqnName(e.parent?e.id.slice(e.parent.length+1):e.id),pumlColor=(e,t,n=`#3b82f6`)=>e?t(e)??n:n,pumlDirection=({autoLayout:e})=>{switch(e.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:e})=>{switch(e){case`queue`:case`rectangle`:case`person`:return e;case`storage`:case`cylinder`:return`database`;case`component`:return`component`;case`document`:case`mobile`:case`bucket`:case`browser`:return`rectangle`;default:N(e)}},escapeLabel=e=>f(e)?null:JSON.stringify(e).slice(1,-1).replace(/\\"/g,`"`);function generatePuml(e){let t=e.$view,n=e.$model.$styles.theme.colors,{nodes:r,edges:i}=t,elementColorProvider=e=>t=>t in n?n[t].elements[e]:void 0,relationshipsColorProvider=e=>t=>t in n?n[t].relationships[e]:void 0,l=new Map,printHeader=()=>new o().append(`title "`,e.titleOrId,`"`,s).append(pumlDirection(t),` direction`,s),printTheme=()=>new o().append(`hide stereotype`,s).append(`skinparam ranksep `,`60`,s).append(`skinparam nodesep `,`30`,s).append(`skinparam {`,s).indent({indentedChildren:e=>e.append(`arrowFontSize `,`10`,s).append(`defaultTextAlignment `,`center`,s).append(`wrapWidth `,`200`,s).append(`maxMessageSize `,`100`,s).append(`shadowing `,`false`,s),indentation:2}).append(`}`,s),printStereotypes=e=>{let t=pumlShape(e),n=fqnName(e.id);return new o().append(`skinparam `,t,`<<`,n,`>>`,`{`,s).indent({indentedChildren:t=>t.append(`BackgroundColor `,pumlColor(e.color,elementColorProvider(`fill`)),s).append(`FontColor `,pumlColor(e.color,elementColorProvider(`hiContrast`),`#FFFFFF`),s).append(`BorderColor `,pumlColor(e.color,elementColorProvider(`stroke`)),s),indentation:2}).append(`}`,s)},printNode=e=>{let t=pumlShape(e),n=fqnName(e.id),r=escapeLabel(e.title)||nodeName(e),i=escapeLabel(e.technology);l.set(e.id,n);let a=F.from(e.description);return new o().append(t,` `).append(`"`).append(`==`,r).appendIf(!!i,`\\n<size:10>[`,i,`]</size>`).appendIf(a.nonEmpty,`\\n\\n`,escapeLabel(a.text)).append(`"`,` <<`,n,`>> `,`as `,n,s)},printBoundary=e=>{let t=escapeLabel(e.title)||nodeName(e),n=fqnName(e.id);return l.set(e.id,n),new o().append(`rectangle "`,t,`" <<`,n,`>> as `,n,` {`,s).indent({indentedChildren:t=>t.append(`skinparam `,`RectangleBorderColor<<`,n,`>> `,pumlColor(e.color,elementColorProvider(`fill`)),s).append(`skinparam `,`RectangleFontColor<<`,n,`>> `,pumlColor(e.color,elementColorProvider(`fill`)),s).append(`skinparam `,`RectangleBorderStyle<<`,n,`>> `,`dashed`,s,s).append(c(r.filter(t=>t.parent===e.id),e=>e.children.length>0?printBoundary(e):printNode(e))),indentation:2}).append(`}`,s)},printEdge=e=>{let t=e.technology||``,n=e.label||t,r=pumlColor(e.color,relationshipsColorProvider(`line`),`#777777`),withColor=e=>`<color:${r}>${e.replaceAll(`"`,`'`)}`,i=new o().append(l.get(e.source),` .[`,r,`,thickness=2].> `,l.get(e.target));return(n||t)&&(i.append(` : `,n.split(`
|
|
88
|
+
`).map(e=>f(e)?e:withColor(e)).join(`\\n`)),t&&t!==n&&i.append(`\\n<size:8>[`,withColor(t),`]</size>`)),i.append(s)};return a(new o().append(`@startuml`,s).append(printHeader(),s).append(printTheme(),s).append(c(r.filter(e=>e.children.length==0),e=>printStereotypes(e),{appendNewLineIfNotEmpty:!0})).append(c(r.filter(e=>m(e.parent)),e=>e.children.length>0?printBoundary(e):printNode(e),{appendNewLineIfNotEmpty:!0})).appendIf(i.length>0,s,c(i,e=>printEdge(e),{appendNewLineIfNotEmpty:!0})).append(`@enduml`,s))}function code$9(e){let t=new o;return t.appendTemplate`
|
|
89
|
+
/******************************************************************************
|
|
90
|
+
* This file was generated
|
|
91
|
+
* DO NOT EDIT MANUALLY!
|
|
92
|
+
******************************************************************************/
|
|
93
|
+
/* eslint-disable */
|
|
94
|
+
|
|
95
|
+
export let d2Source = (viewId) => {
|
|
96
|
+
switch (viewId) {
|
|
97
|
+
`.appendNewLine().indent({indentation:4,indentedChildren(t){t.append(c([...e.views()],e=>i`
|
|
98
|
+
case ${JSON.stringify(e.id)}: {
|
|
99
|
+
return ${JSON.stringify(generateD2(e))}
|
|
100
|
+
}
|
|
101
|
+
`,{appendNewLineIfNotEmpty:!0})).appendTemplate`
|
|
102
|
+
default: {
|
|
103
|
+
throw new Error('Unknown viewId: ' + viewId)
|
|
104
|
+
}
|
|
105
|
+
`}}).append(s,` }`,s).appendTemplate`
|
|
106
|
+
}
|
|
107
|
+
`.append(s,s),a(t)}e(code$9,`code`);const de={...generateMatches(`d2`),async load({likec4:e,project:t}){return logGenerating(`d2`,t.id),{code:code$9(await e.computedModel(t.id)),moduleType:`js`}}},fe=generateCombinedProjects(`d2`,`loadD2Sources`);function code$8(e){let t=new o;return t.appendTemplate`
|
|
108
|
+
/******************************************************************************
|
|
109
|
+
* This file was generated
|
|
110
|
+
* DO NOT EDIT MANUALLY!
|
|
111
|
+
******************************************************************************/
|
|
112
|
+
/* eslint-disable */
|
|
113
|
+
|
|
114
|
+
export let dotSource = (viewId) => {
|
|
115
|
+
switch (viewId) {
|
|
116
|
+
`.appendNewLine().indent({indentation:4,indentedChildren(t){t.append(c(Object.keys(e),t=>i`
|
|
117
|
+
case ${JSON.stringify(t)}: {
|
|
118
|
+
return ${JSON.stringify(e[t].dot)}
|
|
119
|
+
}
|
|
120
|
+
`,{appendNewLineIfNotEmpty:!0})).appendTemplate`
|
|
121
|
+
default: {
|
|
122
|
+
throw new Error('Unknown viewId: ' + viewId)
|
|
123
|
+
}
|
|
124
|
+
`}}).append(s,` }`,s).appendTemplate`
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export let svgSource = (viewId) => {
|
|
128
|
+
switch (viewId) {
|
|
129
|
+
`.appendNewLine().indent({indentation:4,indentedChildren(t){t.append(c(Object.keys(e),t=>i`
|
|
130
|
+
case ${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(t))}: {
|
|
131
|
+
return ${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(e[t].svg))}
|
|
132
|
+
}
|
|
133
|
+
`,{appendNewLineIfNotEmpty:!0})).appendTemplate`
|
|
134
|
+
default: {
|
|
135
|
+
throw new Error('Unknown viewId: ' + viewId)
|
|
136
|
+
}
|
|
137
|
+
`}}).append(s,` }`,s,`}`,s,s),a(t)}e(code$8,`code`);const pe={...generateMatches(`dot`),async load({likec4:e,project:t}){return logGenerating(`dot`,t.id),{code:code$8(w(await e.views.viewsAsGraphvizOut(t.id),({id:e,svg:t,dot:n})=>[e,{dot:n,svg:t}])),moduleType:`js`}}},me=generateCombinedProjects(`dot`,`loadDotSources`);function code$7(e){let t=new o;return t.appendTemplate`
|
|
138
|
+
/******************************************************************************
|
|
139
|
+
* This file was generated
|
|
140
|
+
* DO NOT EDIT MANUALLY!
|
|
141
|
+
******************************************************************************/
|
|
142
|
+
/* eslint-disable */
|
|
143
|
+
|
|
144
|
+
export function drawioEditUrl(viewId) {
|
|
145
|
+
switch (viewId) {
|
|
146
|
+
`.appendNewLine().indent({indentation:4,indentedChildren(t){t.append(c([...e.views()],e=>i`
|
|
147
|
+
case ${JSON.stringify(e.id)}: {
|
|
148
|
+
return ${JSON.stringify(generateDrawioEditUrl(generateDrawio(e)))}
|
|
149
|
+
}
|
|
150
|
+
`,{appendNewLineIfNotEmpty:!0})).appendTemplate`
|
|
151
|
+
default: {
|
|
152
|
+
throw new Error('Unknown viewId: ' + viewId)
|
|
153
|
+
}
|
|
154
|
+
`}}).append(s,` }`,s).appendTemplate`
|
|
155
|
+
}
|
|
156
|
+
`.append(s,s),a(t)}e(code$7,`code`);const he={...generateMatches(`drawio`),async load({likec4:e,project:t}){return logGenerating(`drawio`,t.id),{code:code$7(await e.layoutedModel(t.id)),moduleType:`js`}}},ge=generateCombinedProjects(`drawio`,`loadDrawioSources`),_e=/^(https?:)?\/\//i;function code$6(e){let{imports:t,cases:n}=v(e,y(e=>e.nodes),T(e=>e.icon??void 0),g(e=>p(e)&&!_e.test(e)),S(),x(L)).reduce((e,t,n)=>{let r=t.startsWith(`file:`),i=`Icon`+n.toString().padStart(2,`0`);if(r)return e.imports.push(`import ${i} from '${t}?inline'`),e.cases.push(` '${t}': () => jsx('img', { src: ${i} })`),e;let[a,o]=t.split(`:`),s=`likec4:icon-bundle/${a}/${o}.jsx`;return e.imports.push(`import ${i} from '${s}'`),e.cases.push(` '${a}:${o}': ${i}`),e},{imports:[],cases:[]});return`
|
|
157
|
+
import { jsx } from 'react/jsx-runtime'
|
|
158
|
+
${t.join(`
|
|
159
|
+
`)}
|
|
160
|
+
|
|
161
|
+
const Icons = {
|
|
162
|
+
${n.join(`,
|
|
163
|
+
`)}
|
|
164
|
+
}
|
|
165
|
+
export function IconRenderer({ node, ...props }) {
|
|
166
|
+
const IconComponent = Icons[node.icon ?? '']
|
|
167
|
+
if (!IconComponent) {
|
|
168
|
+
return null
|
|
169
|
+
}
|
|
170
|
+
return jsx(IconComponent, props)
|
|
171
|
+
}
|
|
172
|
+
`}e(code$6,`code`);const ve={...generateMatches(`icons`,`.jsx`),async load({likec4:e,project:t}){logGenerating(`icons`,t.id);let n=await e.computedModel(t.id);return{moduleType:`jsx`,code:code$6([...C(n.$data.views),...C(n.$data.manualLayouts??{})])}}},q=/^[a-zA-Z0-9_.-]+$/;function embedProjectIdAsJsString(e){if(!q.test(e))throw Error(`Unsafe value for code generation: ${e}`);return JSON.stringify(e)}function embedUrlAsJsString(e){return JSON.stringify(e)}const J={id:`likec4:icons`,virtualId:`likec4:plugin/icons.jsx`,async load({projects:e,logger:t}){logGenerating(`icons`);let{imports:n,cases:r}=e.filter(e=>q.test(e.id)?!0:(t.warn(l.yellow(`Skipping project with unsafe id for icons registry: ${e.id}`)),!1)).reduce((e,t,n)=>{let r=`Project`+n.toString().padStart(2,`0`),i=hardenJsonStringLiteralForEmbeddedScript(embedProjectIdAsJsString(t.id)),a=hardenJsonStringLiteralForEmbeddedScript(embedUrlAsJsString(u(`likec4:icons`,t.id)));return e.imports.push(`import {IconRenderer as ${r}} from ${a}`),e.cases.push(` ${i}: ${r}`),e},{imports:[],cases:[]});return{code:`
|
|
173
|
+
import { jsx } from 'react/jsx-runtime'
|
|
174
|
+
${n.join(`
|
|
175
|
+
`)}
|
|
176
|
+
|
|
177
|
+
export let ProjectIconsRegistry = {
|
|
178
|
+
${r.join(`,
|
|
179
|
+
`)}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function getProjectIcons(projectId) {
|
|
183
|
+
return (props) => {
|
|
184
|
+
let Renderer = ProjectIconsRegistry[projectId]
|
|
185
|
+
if (!Renderer) {
|
|
186
|
+
const projects = Object.keys(ProjectIconsRegistry)
|
|
187
|
+
console.error('Unknown projectId: ' + projectId + ' (available: ' + projects + ')')
|
|
188
|
+
if (projects.length === 0) {
|
|
189
|
+
throw new Error('No projects found, invalid state')
|
|
190
|
+
}
|
|
191
|
+
projectId = projects[0]
|
|
192
|
+
console.warn('Falling back to project: ' + projectId)
|
|
193
|
+
Renderer = ProjectIconsRegistry[projectId]
|
|
194
|
+
}
|
|
195
|
+
return jsx(Renderer, props)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (import.meta.hot) {
|
|
200
|
+
import.meta.hot.accept(md => {
|
|
201
|
+
if (!import.meta.hot.data.$update) {
|
|
202
|
+
import.meta.hot.data.$update = ProjectIconsRegistry
|
|
203
|
+
}
|
|
204
|
+
const update = md.ProjectIconsRegistry
|
|
205
|
+
if (update) {
|
|
206
|
+
Object.assign(import.meta.hot.data.$update, update)
|
|
207
|
+
} else {
|
|
208
|
+
import.meta.hot.invalidate()
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
}
|
|
212
|
+
`,moduleType:`jsx`}}};function code$5(e){let t=new o;return t.appendTemplate`
|
|
213
|
+
/******************************************************************************
|
|
214
|
+
* This file was generated
|
|
215
|
+
* DO NOT EDIT MANUALLY!
|
|
216
|
+
******************************************************************************/
|
|
217
|
+
/* eslint-disable */
|
|
218
|
+
|
|
219
|
+
export let mmdSource = (viewId) => {
|
|
220
|
+
switch (viewId) {
|
|
221
|
+
`.appendNewLine().indent({indentation:4,indentedChildren(t){t.append(c([...e.views()],e=>i`
|
|
222
|
+
case ${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(e.id))}: {
|
|
223
|
+
return ${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(generateMermaid(e)))}
|
|
224
|
+
}
|
|
225
|
+
`,{appendNewLineIfNotEmpty:!0})).appendTemplate`
|
|
226
|
+
default: {
|
|
227
|
+
throw new Error('Unknown viewId: ' + viewId)
|
|
228
|
+
}
|
|
229
|
+
`}}).append(s,` }`,s).appendTemplate`
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
`.append(s,s),a(t)}e(code$5,`code`);const ye={...generateMatches(`mmd`),async load({likec4:e,project:t}){return logGenerating(`mmd`,t.id),{code:code$5(await e.computedModel(t.id)),moduleType:`js`}}},be=generateCombinedProjects(`mmd`,`loadMmdSources`),projectModelCode=e=>`
|
|
233
|
+
import { createHooksForModel, atom } from 'likec4/vite-plugin/internal'
|
|
234
|
+
|
|
235
|
+
export let $likec4data = atom(${d.stringify(e.$data)})
|
|
236
|
+
|
|
237
|
+
export let {
|
|
238
|
+
updateModel,
|
|
239
|
+
$likec4model,
|
|
240
|
+
useLikeC4Model,
|
|
241
|
+
useLikeC4Views,
|
|
242
|
+
useLikeC4View
|
|
243
|
+
} = createHooksForModel($likec4data)
|
|
244
|
+
|
|
245
|
+
if (import.meta.hot) {
|
|
246
|
+
import.meta.hot.accept(md => {
|
|
247
|
+
if (!import.meta.hot.data.$update) {
|
|
248
|
+
import.meta.hot.data.$update = updateModel
|
|
249
|
+
}
|
|
250
|
+
const update = md.$likec4data?.get()
|
|
251
|
+
if (update) {
|
|
252
|
+
import.meta.hot.data.$update(update)
|
|
253
|
+
} else {
|
|
254
|
+
import.meta.hot.invalidate()
|
|
255
|
+
}
|
|
256
|
+
})
|
|
257
|
+
}
|
|
258
|
+
`,xe={...generateMatches(`model`),async load({likec4:e,project:t}){return logGenerating(`model`,t.id),{code:projectModelCode(await e.layoutedModel(t.id)),moduleType:`js`}}},Y=generateCombinedProjects(`model`,`loadModel`),Se=e(e=>`
|
|
259
|
+
import { atom, useStore } from 'likec4/vite-plugin/internal'
|
|
260
|
+
|
|
261
|
+
export const isSingleProject = ${e.length===1};
|
|
262
|
+
export const projects = ${d.stringify(e,null,2)};
|
|
263
|
+
|
|
264
|
+
export const $projects = atom([...projects])
|
|
265
|
+
|
|
266
|
+
export function useLikeC4Projects() {
|
|
267
|
+
return useStore($projects)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (import.meta.hot) {
|
|
271
|
+
import.meta.hot.accept(md => {
|
|
272
|
+
if (!import.meta.hot.data.$projects) {
|
|
273
|
+
import.meta.hot.data.$projects = $projects
|
|
274
|
+
}
|
|
275
|
+
if (!import.meta.hot.data.projects) {
|
|
276
|
+
import.meta.hot.data.projects = projects
|
|
277
|
+
}
|
|
278
|
+
const update = md.projects
|
|
279
|
+
if (update) {
|
|
280
|
+
import.meta.hot.data.projects.length = 0
|
|
281
|
+
import.meta.hot.data.projects.push(...update)
|
|
282
|
+
import.meta.hot.data.$projects.set(update)
|
|
283
|
+
} else {
|
|
284
|
+
import.meta.hot.invalidate()
|
|
285
|
+
}
|
|
286
|
+
})
|
|
287
|
+
}
|
|
288
|
+
`,`code`),X={id:`likec4:projects`,virtualId:`likec4:plugin/projects.js`,async load({projects:e}){return logGenerating(`projects`),{code:Se(T(e,e=>({id:e.id,title:e.title,landingPage:e.config.landingPage}))),moduleType:`js`}}},Ce=e(e=>`
|
|
289
|
+
import { atom, useStore } from 'likec4/vite-plugin/internal'
|
|
290
|
+
|
|
291
|
+
export const $viewdata = atom(${d.stringify(e)})
|
|
292
|
+
|
|
293
|
+
export function useLikeC4ProjectsOverview() {
|
|
294
|
+
return useStore($viewdata)
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (import.meta.hot) {
|
|
298
|
+
import.meta.hot.accept(md => {
|
|
299
|
+
if (!import.meta.hot.data.$viewdata) {
|
|
300
|
+
import.meta.hot.data.$viewdata = $viewdata
|
|
301
|
+
}
|
|
302
|
+
const update = md.$viewdata?.value
|
|
303
|
+
if (update) {
|
|
304
|
+
import.meta.hot.data.$viewdata.set(update)
|
|
305
|
+
} else {
|
|
306
|
+
import.meta.hot.invalidate()
|
|
307
|
+
}
|
|
308
|
+
})
|
|
309
|
+
}
|
|
310
|
+
`,`code`),noProjects=()=>`
|
|
311
|
+
export function useLikeC4ProjectsOverview() {
|
|
312
|
+
throw new Error('No projects overview available for this workspace: single project mode is enabled')
|
|
313
|
+
}
|
|
314
|
+
`,Z={id:`likec4:projects-overview`,virtualId:`likec4:plugin/projects-overview.js`,async load({projects:e,likec4:t}){return e.length<2?noProjects():(logGenerating(`projects-overview`),{code:Ce(await t.projectsOverview()),moduleType:`js`})}};function code$2(e){let t=new o;return t.appendTemplate`
|
|
315
|
+
/******************************************************************************
|
|
316
|
+
* This file was generated
|
|
317
|
+
* DO NOT EDIT MANUALLY!
|
|
318
|
+
******************************************************************************/
|
|
319
|
+
/* eslint-disable */
|
|
320
|
+
|
|
321
|
+
export let pumlSource = (viewId) => {
|
|
322
|
+
switch (viewId) {
|
|
323
|
+
`.appendNewLine().indent({indentation:4,indentedChildren(t){t.append(c([...e.views()],e=>i`
|
|
324
|
+
case ${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(e.id))}: {
|
|
325
|
+
return ${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(generatePuml(e)))}
|
|
326
|
+
}
|
|
327
|
+
`,{appendNewLineIfNotEmpty:!0})).appendTemplate`
|
|
328
|
+
default: {
|
|
329
|
+
throw new Error('Unknown viewId: ' + viewId)
|
|
330
|
+
}
|
|
331
|
+
`}}).append(s,` }`,s).appendTemplate`
|
|
332
|
+
}
|
|
333
|
+
`.append(s,s),a(t)}e(code$2,`code`);const we={...generateMatches(`puml`),async load({likec4:e,project:t}){return logGenerating(`puml`,t.id),{code:code$2(await e.computedModel(t.id)),moduleType:`js`}}},Te=generateCombinedProjects(`puml`,`loadPumlSources`),projectCode=e=>`
|
|
334
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
335
|
+
import { LikeC4ModelProvider as Provider, LikeC4View as GenericView, ReactLikeC4 as GenericReactLikeC4 } from 'likec4/react';
|
|
336
|
+
import { IconRenderer } from 'likec4:icons/${e}'
|
|
337
|
+
|
|
338
|
+
import { useLikeC4Model, useLikeC4Views, useLikeC4View } from 'likec4:model/${e}'
|
|
339
|
+
|
|
340
|
+
export function LikeC4ModelProvider({ children }) {
|
|
341
|
+
const likeC4Model = useLikeC4Model()
|
|
342
|
+
return (_jsx(Provider, { likec4model: likeC4Model, children: children }));
|
|
343
|
+
}
|
|
344
|
+
export function LikeC4View(props) {
|
|
345
|
+
return (_jsx(LikeC4ModelProvider, { children: _jsx(GenericView, { renderIcon: IconRenderer, ...props }) }));
|
|
346
|
+
}
|
|
347
|
+
export function ReactLikeC4(props) {
|
|
348
|
+
return (_jsx(LikeC4ModelProvider, { children: _jsx(GenericReactLikeC4, { renderIcon: IconRenderer, ...props }) }));
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export {
|
|
352
|
+
useLikeC4Model,
|
|
353
|
+
useLikeC4View,
|
|
354
|
+
useLikeC4Views
|
|
355
|
+
}
|
|
356
|
+
`,Ee={...generateMatches(`react`),async load({project:e}){return logGenerating(`react`,e.id),{code:projectCode(e.id),moduleType:`js`}}},De={id:`likec4:react`,virtualId:`likec4:plugin/react.js`,async load({projects:e}){let t=h(e);return logGenerating(`react-default-project`),{code:`export {
|
|
357
|
+
useLikeC4Model,
|
|
358
|
+
useLikeC4View,
|
|
359
|
+
useLikeC4Views,
|
|
360
|
+
LikeC4ModelProvider,
|
|
361
|
+
LikeC4View,
|
|
362
|
+
ReactLikeC4
|
|
363
|
+
} from 'likec4:react/${t.id}'`,moduleType:`js`}}},Oe={id:`likec4:rpc`,virtualId:`likec4:plugin/rpc.js`,async load(){return logGenerating(`rpc`),{code:`
|
|
364
|
+
import { createRpc } from 'likec4/vite-plugin/internal'
|
|
365
|
+
|
|
366
|
+
export const isRpcAvailable = !!import.meta.hot
|
|
367
|
+
|
|
368
|
+
let rpc
|
|
369
|
+
if (import.meta.hot) {
|
|
370
|
+
rpc = createRpc({
|
|
371
|
+
send: (event, data) => {
|
|
372
|
+
import.meta.hot.send(event, data)
|
|
373
|
+
},
|
|
374
|
+
on: (event, fn) => {
|
|
375
|
+
import.meta.hot.on(event, fn)
|
|
376
|
+
}
|
|
377
|
+
})
|
|
378
|
+
|
|
379
|
+
import.meta.hot.accept()
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export const likec4rpc = rpc ?? {
|
|
383
|
+
updateView: () => {
|
|
384
|
+
throw new Error('likec4rpc.updateView is not available in production')
|
|
385
|
+
},
|
|
386
|
+
calcAdhocView: () => {
|
|
387
|
+
throw new Error('likec4rpc.calcAdhocView is not available in production')
|
|
388
|
+
},
|
|
389
|
+
}
|
|
390
|
+
`,moduleType:`js`,moduleSideEffects:!1}}},code=e=>`
|
|
391
|
+
export { IconRenderer } from 'likec4:icons/${e}'
|
|
392
|
+
export {
|
|
393
|
+
$likec4data,
|
|
394
|
+
$likec4model,
|
|
395
|
+
useLikeC4Model,
|
|
396
|
+
useLikeC4Views,
|
|
397
|
+
useLikeC4View
|
|
398
|
+
} from 'likec4:model/${e}'
|
|
399
|
+
export const projectId = ${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(e))}
|
|
400
|
+
`,ke={id:`likec4:single-project`,virtualId:`likec4:plugin/single-project.js`,async load({projects:e}){let t=h(e);return logGenerating(`single-project`,t.id),code(t.id)}},Q=[xe,ve,de,pe,ye,we,he],$=[...Q,Ee],Ae=[X,Y,Z,ke,De,fe,me,be,Te,ge,J,Oe];function LikeC4VitePlugin({environments:e,appConfig:t,...i}){let a,o,s=i.watch??!1,c=[...Ae,createAppConfigModule(t)],projectsChangeDetector=e=>{let t=T(e=>({id:e.id,title:e.title,folder:e.folder.toString(),landingPage:e.config.landingPage})),n=t(e);return e=>{let r=t(e);return _(n,r)?!1:(n=r,!0)}};return[iconBundlePlugin({environments:e?[e].flat():void 0,workspace:i.workspace??i.languageServices?.workspacePath}),{name:`vite-plugin-likec4`,applyToEnvironment(t){return e?e.includes(t.name):!0},async configResolved(e){if(i.languageServices)a=i.languageServices;else{let t=e.mode===`development`,n=s=i.watch??t;a=(await r(i.workspace??e.root,{graphviz:i.graphviz??`wasm`,configureLogger:`console`,logLevel:i.logLevel??`warning`,printErrors:i.printErrors??!0,throwIfInvalid:i.throwIfInvalid??!1,watch:n})).languageServices}o=a.workspaceUri.fsPath},resolveId:{filter:{id:/^likec4:/},handler(e){for(let t of $){let n=t.matches(e);if(n)return t.virtualId(n)}for(let t of c)if(t.id===e)return t.virtualId;return null}},load:{filter:{id:/likec4:plugin/},async handler(e){for(let t of $){let n=t.matches(e);if(n){let e=a.project(n);return await t.load.call(this,{logger:V,likec4:a,project:e,assetsDir:o})}}for(let t of c)if(t.virtualId===e){let e=a.projects();return ee(M(e)),await t.load.call(this,{logger:V,likec4:a,projects:e,assetsDir:o})}return null}},configureServer(e){let t=e.hot;enablePluginRPC.call(this,{logger:V,likec4:a,server:e});let r=projectsChangeDetector(a.projects()),reloadModule=async t=>{let r=e.moduleGraph.getModuleById(t);if(!(!r||r.importers.size===0))try{await e.reloadModule(r)}catch(e){V.error(n(e))}};a.builder.onModelParsed(E(async()=>{let[e]=a.getErrors();if(e){t.send({type:`error`,err:{name:`LikeC4ValidationError`,...splitErrorMessage(e.message),plugin:`vite-plugin-likec4`,loc:{file:e.sourceFsPath,line:e.line,column:e.range.start.character+1}}});return}let n=a.projects();if(r(n)){await reloadModule(X.virtualId),await reloadModule(J.virtualId),await reloadModule(Y.virtualId),n.length>1&&await reloadModule(Z.virtualId);return}for(let e of n)for(let t of Q)await reloadModule(t.virtualId(e.id))},100))},async buildEnd(){s&&await a.dispose()}}]}export{generateDrawio as a,generateD2 as c,buildDrawioExportOptionsForViews as i,generatePuml as n,generateDrawioMulti as o,generateMermaid as r,oe as s,LikeC4VitePlugin as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRequire as e}from"node:module";var t=Object.create,n=Object.defineProperty,__name=(e,t)=>n(e,`name`,{value:t,configurable:!0}),r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,__esmMin=(e,t)=>()=>(e&&(t=e(e=0)),t),__commonJSMin=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),__exportAll=(e,t)=>{let r={};for(var i in e)n(r,i,{get:e[i],enumerable:!0});return t||n(r,Symbol.toStringTag,{value:`Module`}),r},__copyProps=(e,t,a,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=i(t),l=0,u=c.length,d;l<u;l++)d=c[l],!o.call(e,d)&&d!==a&&n(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(s=r(t,d))||s.enumerable});return e},__reExport=(e,t,n)=>(__copyProps(e,t,`default`),n&&__copyProps(n,t,`default`)),__toESM=(e,r,i)=>(i=e==null?{}:t(a(e)),__copyProps(r||!e||!e.__esModule?n(i,`default`,{value:e,enumerable:!0}):i,e)),__toCommonJS=e=>o.call(e,`module.exports`)?e[`module.exports`]:__copyProps(n({},`__esModule`,{value:!0}),e),s=e(import.meta.url);export{__reExport as a,__toESM as c,__name as i,__esmMin as n,s as o,__exportAll as r,__toCommonJS as s,__commonJSMin as t};
|
|
@@ -0,0 +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};
|