likec4 1.58.0 → 1.59.1
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__/codegen/webcomponent.mjs +14 -14
- package/__app__/src/chunks/AIChat.mjs +153 -156
- package/__app__/src/chunks/LikeC4Styles.mjs +1553 -1255
- package/__app__/src/chunks/ProjectsOverview.mjs +127 -130
- package/__app__/src/chunks/hooks.mjs +419 -106
- package/__app__/src/chunks/libs/@floating-ui.mjs +8 -8
- package/__app__/src/chunks/libs/@mantine.mjs +3039 -2135
- package/__app__/src/chunks/libs/@tanstack-ai.mjs +4 -4
- package/__app__/src/chunks/libs/@tanstack.mjs +93 -118
- package/__app__/src/chunks/libs/@xstate/react.mjs +30 -16
- package/__app__/src/chunks/libs/@xyflow/react.mjs +50 -26
- package/__app__/src/chunks/libs/bezier-js.mjs +11 -8
- package/__app__/src/chunks/libs/framer.mjs +1188 -1155
- package/__app__/src/chunks/libs/zod.mjs +191 -188
- package/__app__/src/chunks/rolldown-runtime.mjs +8 -1
- package/__app__/src/chunks/styled-system.mjs +23 -16
- package/__app__/src/main.mjs +23331 -10467
- package/__app__/src/style.css +1 -1
- package/dist/chunks/dist.mjs +10 -0
- package/dist/chunks/enableServer.mjs +1 -1
- package/dist/chunks/index.d.mts +9 -9
- package/dist/chunks/index2.d.mts +386 -229
- package/dist/chunks/libs/@chevrotain/gast.mjs +1 -1
- package/dist/chunks/libs/@chevrotain/regexp-to-ast.mjs +1 -1
- package/dist/chunks/libs/@logtape/logtape.mjs +3 -3
- package/dist/chunks/libs/@ts-graphviz/common.d.mts +1 -2
- package/dist/chunks/libs/@ts-graphviz/core.mjs +1 -1
- package/dist/chunks/libs/chevrotain-allstar.mjs +1 -1
- package/dist/chunks/libs/chevrotain.mjs +4 -4
- package/dist/chunks/libs/json5.mjs +1 -1
- package/dist/chunks/libs/langium.d.mts +2940 -2914
- package/dist/chunks/libs/langium.mjs +9 -9
- package/dist/chunks/libs/merge-error-cause.mjs +1 -1
- package/dist/chunks/libs/p-queue.mjs +1 -1
- package/dist/chunks/libs/package-manager-detector.mjs +1 -1
- package/dist/chunks/libs/pako.mjs +1 -1
- package/dist/chunks/libs/picomatch.mjs +1 -1
- package/dist/chunks/libs/remeda.mjs +1 -1
- package/dist/chunks/libs/ufo.mjs +1 -1
- package/dist/chunks/libs/unstorage.d.mts +1 -0
- package/dist/chunks/libs/which.mjs +1 -1
- package/dist/chunks/libs/zod.d.mts +48 -36
- package/dist/chunks/libs/zod.mjs +4 -4
- package/dist/chunks/logger.mjs +1 -0
- package/dist/chunks/node.mjs +57 -66
- package/dist/chunks/rolldown-runtime.mjs +1 -1
- package/dist/chunks/sequence-view.mjs +1 -1
- package/dist/chunks/vite-plugin.mjs +43 -43
- package/dist/cli/index.mjs +159 -157
- package/dist/index.d.mts +2 -3
- package/dist/index.mjs +1 -1
- package/dist/model/index.d.mts +5 -4
- package/dist/vite-plugin/index.d.mts +6 -9
- package/dist/vite-plugin/internal/index.d.mts +15 -10
- package/package.json +38 -38
- package/react/index.d.mts +761 -111
- package/react/index.mjs +13997 -10234
- package/__app__/src/chunks/DiagramActorProvider.mjs +0 -7638
- package/__app__/src/chunks/Markdown.mjs +0 -146
- package/__app__/src/chunks/NavigationPanel.mjs +0 -61
- package/__app__/src/chunks/adhoc-editor.mjs +0 -3386
- package/__app__/src/chunks/libs/@dagrejs/dagre.mjs +0 -1894
- package/__app__/src/chunks/libs/@tabler/icons-react.mjs +0 -252
- package/__app__/src/chunks/libs/remeda.mjs +0 -642
|
@@ -1 +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};
|
|
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,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},__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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./rolldown-runtime.mjs";import{B as e,K as t,Q as n,V as r,_ as i,b as a,et as o,p as s,t as c,y as l}from"./libs/remeda.mjs";import{a as u,i as d,n as f,r as p,t as m}from"./libs/@lume/kiwi.mjs";import{getParallelStepsPrefix as h,isStepEdgeId as g}from"@likec4/core/types";import{DefaultMap as _,Stack as v,invariant as y,isAncestor as b,nonNullable as x,nonexhaustive as S}from"@likec4/core/utils";function findParallelRects(e){return o(e,r(e=>e.parallelPrefix??void 0),i((e,t)=>e.reduce((e,t)=>(e.min.column=Math.min(e.min.column,t.from.column,t.to.column),e.min.row=Math.min(e.min.row,t.from.row,t.to.row),e.max.column=Math.max(e.max.column,t.from.column,t.to.column),e.max.row=Math.max(e.max.row,t.from.row,t.to.row),e),{parallelPrefix:t,min:{column:1/0,row:1/0},max:{column:-1/0,row:-1/0}})),c())}function buildCompounds(e,t){if(e.length===0||e.length===t.length)return[];let getNode=e=>x(t.find(t=>t.id===e));function parentsLookup(e){let t=e.parent?getNode(e.parent):null;return t?[t,...parentsLookup(t)]:[]}let n=new v,r=[];return e.forEach(e=>{let t=parentsLookup(e);if(t.length===0){n.clear();return}let i=v.from(t),a,o;for(;a=n.peek()?.node,o=i.peek(),!(!o||!a);){if(b(o.id,a.id)||o.id===a.id){i.pop();continue}if(!b(a.id,o.id)){n.pop();continue}break}for(;o=i.pop();){let t={node:o,from:e,to:e,nested:[]},i=n.peek();i?i.nested.push(t):r.push(t),n.push(t)}n.forEach(t=>t.to=e)}),r}var SequenceViewLayouter=class{#e=new m;#t;#n=[];#r;#i;#a;#o=[];#s=[];constructor({actors:e,steps:t,compounds:n}){this.#a=this.newVar(30),this.#r=this.newVar(0),this.#i=this.newVar(0),this.#t=this.addActors(e);for(let e of n){let t=this.addCompound(e),n=t[0];this.constraint(n.y1,`==`,0,d.strong),this.put(this.#i).after(n.bottom),this.put(this.#a).after(n.y2),this.#n.push(...t)}for(let e of t)this.addStep(e);for(let e of findParallelRects(t))this.addParallelRect(e);let r=this.#t[0];this.constraint(r.offset.left,`==`,0,d.strong);let i=this.#t.reduce((e,t)=>(this.put(t.x).after(e.right,60),this.put(t.offset.left,d.strong).after(e.offset.right,32),this.constraint(t.centerY,`==`,e.centerY,d.strong),this.put(this.#a).after(t.offset.bottom),t));if(this.put(this.#r).after(i.offset.right),this.put(this.#i).after(a(this.#o)?.bottom??this.#a),n.length>0)for(let e of this.#n){let t=e.from.column,n=e.to.column,r=Math.max(e.from.maxRow,e.to.maxRow);for(let e=t+1;e<n;e++){let t=this.actorBox(e);r=Math.max(r,t.maxRow)}let i=x(this.#o[r],`row ${r} not found`);this.put(e.bottom).after(i.bottom,16),this.put(this.#i).after(e.bottom)}this.#e.updateVariables()}getParallelBoxes(){return this.#s.map(({parallelPrefix:e,x1:t,y1:n,x2:r,y2:i})=>({parallelPrefix:e,x:t.value(),y:n.value(),width:r.value()-t.value(),height:i.value()-n.value()}))}getActorBox(e){let t=this.actorBox(e);return{x:t.x.value(),y:t.y.value(),width:t.width,height:t.height}}getCompoundBoxes(){return this.#n.map(({node:e,depth:t,x1:n,y1:r,x2:i,bottom:a})=>({node:e,depth:t,x:n.value(),y:r.value(),width:i.value()-n.value(),height:a.value()-r.value()}))}getPortCenter(e,t){let{column:n,row:r}=t===`source`?e.from:e.to,i=this.actorBox(n).centerX,{y:a}=x(this.#o[r]);return{cx:i.value(),cy:a.value()+32/2+e.offset,height:t===`source`?40:24}}getViewBounds(){return{x:0,y:0,width:this.#r.value(),height:this.#i.value()}}actorBox(e){if(typeof e!=`number`){let t=typeof e==`string`?e:e.id;e=this.#t.findIndex(e=>e.actor.id===t),y(e>=0,`actor ${t} not found`)}return x(this.#t[e],`actor at index ${e} not found`)}addActors(e){let t=0;return l(e,(e,n)=>{let r=this.newVar(t);t+=e.width+60;let i=this.newVar(0),a={column:n,actor:e,x:r,y:i,centerX:r.plus(Math.round(e.width/2)),centerY:i.plus(Math.round(e.height/2)),width:e.width,height:e.height,right:r.plus(e.width),bottom:i.plus(e.height),minRow:1/0,maxRow:-1/0},o=this.newVar(0),s=this.newVar(0),c=this.newVar(0),l=this.newVar(0);return this.put(o,d.strong).before(i),this.put(s,d.strong).before(r),this.put(c,d.strong).after(a.right),this.put(l,d.strong).after(a.bottom),{...a,offset:{top:o,left:s,right:c,bottom:l}}})}addStep(e){let t=this.actorBox(e.source),n=this.actorBox(e.target);t.minRow=Math.min(t.minRow,e.from.row),t.maxRow=Math.max(t.maxRow,e.from.row),n.minRow=Math.min(n.minRow,e.to.row),n.maxRow=Math.max(n.maxRow,e.to.row);let[r,i]=t.column<=n.column?[t,n]:[n,t],a=(e.label?.width??100)+50;r===i?this.constraint(r.centerX.plus(a),`<=`,r.offset.right):this.constraint(r.centerX.plus(a),`<=`,i.centerX);let o=e.label?.height?e.label.height+50+32/2:80;return o=Math.max(o,80)+e.offset,this.ensureRow(e.from.row,o),e.isSelfLoop&&this.ensureRow(e.to.row,80),this}addParallelRect({parallelPrefix:e,min:t,max:n}){let r=this.actorBox(t.column).centerX.minus(30),i=this.actorBox(n.column).centerX.plus(30),a=this.#o[t.row],o=this.#o[n.row];y(a&&o,`parallel box invalid minRow=${t.row} maxRow=${n.row}`);let s=this.newVar(0);this.put(s).before(a.y,40);let c=o.bottom,l=t.row>0&&this.#o[t.row-1];l&&this.put(s).after(l.bottom,16);let u=n.row<this.#o.length-1&&this.#o[n.row+1];u&&this.put(c).before(u.y,16),this.#s.push({parallelPrefix:e,x1:r,y1:s,x2:i,y2:c})}addCompound(e){let t=[],n=e.nested.flatMap(e=>{let n=this.addCompound(e);return t.push(n[0]),n}),r=Math.max(...n.map(e=>e.depth+1),0),i=this.actorBox(e.from),a=this.actorBox(e.to),o=i.offset.left.minus(32);i.offset.left=o;let c=a.offset.right.plus(32);a.offset.right=c;let l=this.newVar(0),u=s(t),d,f;switch(!0){case!!u:d=u.y1.minus(40),f=u.y2.plus(32),this.put(l).after(u.bottom,32);break;case a===i:d=this.newVar(0),f=this.newVar(0),this.put(d).before(i.offset.top,52),this.put(f).after(i.offset.bottom,32),this.put(l).after(f);break;case t.length>0:d=this.newVar(0),f=this.newVar(0);for(let e of t)this.put(d).before(e.y1,32),this.put(f).after(e.y2,32),this.put(l).after(e.bottom,32);break;default:d=this.newVar(0),f=this.newVar(0);for(var p=i.column;p<=a.column;p++){let e=this.actorBox(p).offset;this.put(d).before(e.top,52),this.put(f).after(e.bottom,32)}this.put(l).after(f);break}for(var p=i.column;p<=a.column;p++){let e=this.actorBox(p).offset;e.top=d,e.bottom=f}return[{node:e.node,depth:r,from:i,to:a,x1:o,y1:d,x2:c,y2:f,bottom:l},...n]}ensureRow(e,t){for(;e>=this.#o.length;){let e=this.#o.length>0&&this.#o[this.#o.length-1]?.bottom||this.#a.plus(30),t=this.newVar(this.#o.length*80);this.put(t).after(e);let n=this.newVar(80);this.require(n,`>=`,80),this.#o.push({y:t,height:n,bottom:t.plus(n),lastHeight:80})}let n=x(this.#o[e]);t>n.lastHeight&&(n.lastHeight=t,this.require(n.height,`>=`,t),this.#e.suggestValue(n.height,t))}newVar(e){let t=new u;return this.#e.addEditVariable(t,d.weak),typeof e==`number`&&(this.#e.suggestValue(t,e),this.constraint(t,`>=`,0,d.strong)),t}require(e,t,n=void 0){switch(this.constraint(e,t,n,d.required),t){case`<=`:case`>=`:this.constraint(e,`==`,n,d.weak);break;case`<= 0`:case`>= 0`:this.constraint(e,`== 0`,void 0,d.weak);break}}constraint(e,t,n=void 0,r=d.medium){let i;switch(t){case`==`:i=p.Eq;break;case`>=`:i=p.Ge;break;case`<=`:i=p.Le;break;case`== 0`:i=p.Eq,n=0;break;case`>= 0`:i=p.Ge,n=0;break;case`<= 0`:i=p.Le,n=0;break;default:S(t)}this.#e.addConstraint(new f(e,i,n??0,r))}put(e,t=d.required){let n=t===d.required?d.medium:d.weak;return{before:(r,i)=>{i&&(r=r.minus(i)),this.constraint(e,`<=`,r,t),this.constraint(e,`==`,r,n)},after:(r,i)=>{i&&(r=r.plus(i)),this.constraint(e,`>=`,r,t),this.constraint(e,`==`,r,n)}}}};function calcSequenceLayout(r){let a=new Set,getNode=e=>x(r.nodes.find(t=>t.id===e)),s=[];for(let e of r.edges.filter(e=>g(e.id))){let t=getNode(e.source),n=getNode(e.target);if(t.children.length||n.children.length){console.error(`Sequence view does not support nested actors`);continue}a.add(t),a.add(n),s.push({edge:e,source:t,target:n})}let u=r.nodes.filter(e=>a.has(e));y(n(u,1),`actors array must not be empty`);let d=new _(()=>[]),f=[],p=0;for(let{edge:e,source:t,target:n}of s){let r=f.at(-1),i=u.indexOf(t),a=u.indexOf(n),o=t===n,s=i>a,c=h(e.id),l=!1;r&&r.target==t&&r.parallelPrefix===c&&(l=r.isSelfLoop!==o||r.isBack===s),l||p++;let m={id:e.id,from:{column:i,row:p},to:{column:a,row:o?++p:p},edge:e,isSelfLoop:o,isBack:s,parallelPrefix:c,offset:l?(r?.offset??0)+22:0,source:t,target:n,label:e.labelBBox?{height:e.labelBBox.height+8+(e.navigateTo?20:0),width:e.labelBBox.width+16,text:e.label}:null};f.push(m),d.get(t).push({step:m,row:p,type:`source`,position:s&&!o?`left`:`right`}),d.get(n).push({step:m,row:p,type:`target`,position:s||o?`right`:`left`})}let m=new SequenceViewLayouter({actors:u,steps:f,compounds:buildCompounds(u,r.nodes)}),v=m.getViewBounds(),b=o(m.getCompoundBoxes(),l(({node:e,...t})=>({...t,id:e.id,origin:e.id})),e(`id`),i((e,t)=>n(e,2)?l(e,(e,n)=>({...e,id:`${t}-${n+1}`})):e),c(),t());return{actors:u.map(e=>toSeqActor({actor:e,ports:d.get(e),layout:m})),compounds:b,steps:l(f,e=>({id:e.id,sourceHandle:e.id+`_source`,targetHandle:e.id+`_target`,...e.label&&{labelBBox:{width:e.label.width,height:e.label.height}}})),parallelAreas:m.getParallelBoxes(),bounds:v}}function toSeqActor({actor:e,ports:t,layout:n}){let{x:r,y:i,width:a,height:o}=n.getActorBox(e);return{id:e.id,x:r,y:i,width:a,height:o,ports:t.map(e=>{let t=n.getPortCenter(e.step,e.type);return{id:`${e.step.id}_${e.type}`,cx:t.cx-r,cy:t.cy-i,height:t.height,type:e.type,position:e.position}})}}export{calcSequenceLayout as t};
|
|
1
|
+
import"./rolldown-runtime.mjs";import{$ as e,J as t,K as n,V as r,Z as i,b as a,m as o,q as s,t as c,tt as l,v as u,x as d}from"./libs/remeda.mjs";import{a as f,i as p,n as m,r as h,t as g}from"./libs/@lume/kiwi.mjs";import{dynamicViewFlow as _,flowGuards as v,parentFlow as y}from"@likec4/core/types";import{DefaultMap as b,Stack as x,invariant as S,isAncestor as C,nonNullable as w,nonexhaustive as T}from"@likec4/core/utils";function isPlainObject(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t!==null&&t!==Object.prototype&&Object.getPrototypeOf(t)!==null||Symbol.iterator in e?!1:Symbol.toStringTag in e?Object.prototype.toString.call(e)===`[object Module]`:!0}function _defu(e,t,n=`.`,r){if(!isPlainObject(t))return _defu(e,{},n,r);let i={...t};for(let t of Object.keys(e)){if(t===`__proto__`||t===`constructor`)continue;let a=e[t];a!=null&&(r&&r(i,t,a,n)||(Array.isArray(a)&&Array.isArray(i[t])?i[t]=[...a,...i[t]]:isPlainObject(a)&&isPlainObject(i[t])?i[t]=_defu(a,i[t],(n?`${n}.`:``)+t.toString(),r):i[t]=a))}return i}function createDefu(e){return(...t)=>t.reduce((t,n)=>_defu(t,n,``,e),{})}const E=createDefu(),paddingFromNumber=e=>({left:e,right:e,top:e,bottom:e});function normalizeSpacing(e=16){return typeof e==`number`?paddingFromNumber(e):{left:e?.left??e?.x??0,right:e?.right??e?.x??0,top:e?.top??e?.y??0,bottom:e?.bottom??e?.y??0}}function rectFromSteps(e){return S(e.length>0),e.reduce((e,t)=>{let n=[t.from.column,t.to.column],r=[t.from.row,t.to.row];return e.min.column=Math.min(e.min.column,...n),e.min.row=Math.min(e.min.row,...r),e.max.column=Math.max(e.max.column,...n),e.max.row=Math.max(e.max.row,...r),e},{min:{column:1/0,row:1/0},max:{column:-1/0,row:-1/0}})}function buildCompounds(e,t){if(e.length===0||e.length===t.length)return[];let getNode=e=>t.find(t=>t.id===e);function parentsLookup(e){let t=e.parent&&getNode(e.parent);return t?[t,...parentsLookup(t)]:[]}let n=new x,r=[];return e.forEach(e=>{let t=parentsLookup(e);if(t.length===0){n.clear();return}let i,a=t[0];for(;i=n.peek()?.node;){if(!a||i.id===a.id){t.length=0;break}if(!C(i.id,a.id)){n.pop();continue}break}for(;i=t.pop();){let t=n.peek();if(t&&(C(i.id,t.node.id)||i.id===t.node.id))continue;let a={node:i,from:e,to:e,nested:[]};t?t.nested.push(a):r.push(a),n.push(a)}n.forEach(t=>t.to=e)}),r}const D={required:p.required,strong:p.strong,medium:p.medium,soft:p.create(0,.8,1),weak:p.weak};var SequenceViewLayouter=class{#e;#t=new g;#n;#r=[];#i;#a;#o;#s=[];#c=new Map;constructor({actors:e,steps:t,compounds:n,flow:r,collapsedFlows:i}){this.#t.maxIterations=2e3,this.#e=r;let a=Math.max(...e.map(e=>e.height))+30;this.#o=this.newVar(a),this.constraint(this.#o,`==`,a,D.soft),this.constraint(this.#o,`>=`,a,D.weak),this.#i=this.newVar(0),this.#a=this.newVar(0),this.#n=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.#o,D.strong).after(n.y2),this.#r.push(...t)}let[o,...s]=this.#n;this.constraint(o.offset.left,`==`,0,D.strong);let c=s.reduce((e,t)=>(this.put(t.x).after(e.right,80),this.put(e.offset.right,D.strong).before(t.offset.left,50),this.constraint(t.centerY,`==`,e.centerY,D.strong),t),o);for(let e of t)this.addStep(e);this.createSubflowAreas(t,new Set(i)),this.constraint(this.#i,`==`,c.offset.right);let l=d(this.#s)?.inner.bottom??this.#o;if(this.put(this.#a,D.strong).after(l,16),n.length>0)for(let e of this.#r){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=w(this.#s[r],`row ${r} not found`);this.put(e.bottom,D.strong).after(i.inner.bottom,10)}this.#t.updateVariables()}getSubflowAreas(){return[...this.#c.entries()].map(([e,{x1:t,y1:n,x2:r,y2:i}])=>({id: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.#r.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,{rowTop:a}=w(this.#s[r]);return e.isSelfLoop&&t===`target`?{cx:i.value(),cy:a.value(),height:24}:{cx:i.value(),cy:a.value()+40+e.offset,height:t===`source`?40:24}}isStepCollapsed(e){if(e.from.row===e.to.row)return this.#s[e.from.row]?.collapsed??!1;let t=Math.min(e.from.row,e.to.row),n=Math.min(e.from.row,e.to.row),r=!0;for(let e=t;e<=n&&(r&&=this.#s[e]?.collapsed??!1,r);e++);return r}getViewBounds(){return{x:0,y:0,width:this.#i.value(),height:this.#a.value()}}actorBox(e){if(typeof e!=`number`){let t=typeof e==`string`?e:e.id;e=this.#n.findIndex(e=>e.actor.id===t),S(e>=0,`actor ${t} not found`)}return w(this.#n[e],`actor at index ${e} not found`)}addActors(e){let t=0;return a(e,(e,n)=>{let r=this.newVar(t);t+=e.width+80;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(i,D.strong).after(o),this.put(r,D.strong).after(s),this.put(a.right,D.strong).before(c),this.put(a.bottom,D.strong).before(l),{...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;Math.abs(n.column-t.column)<=1&&(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+24:100;return o=Math.max(o,100)+e.offset,this.ensureRow(e.from.row,o),e.to.row!==e.from.row&&this.ensureRow(e.to.row,24),this}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(u.bottom).before(l,32);break;case a===i:d=this.newVar(0),f=this.newVar(0),this.put(d).before(i.offset.top,52),this.put(i.offset.bottom).before(f,32),this.put(f).before(l);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(e.y2).before(f,32),this.put(e.bottom).before(l,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(e.bottom).before(f,32)}this.put(f).before(l);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.#s.length;){let n=d(this.#s)?.outer.bottom||this.#o,r=this.newVar(n.value());this.put(r).after(n);let i=t;e!==this.#s.length&&(i=100);let a=new f;a.setValue(i),this.#t.addEditVariable(a,D.strong),this.#t.suggestValue(a,i);let o=this.newVar(r.value()+i);this.require(o).after(r),this.constraint(o.minus(r),`==`,a,D.strong);let s=this.newVar(o.value());this.put(s).after(o),this.#s.push({inner:{top:r,bottom:o},rowTop:r,outer:{top:n,bottom:s},height:a})}let n=w(this.#s[e]);return t>n.height.value()&&(n.height.setValue(t),this.#t.suggestValue(n.height,t)),n}collapseRect({min:e,max:t}){for(let n=e.row;n<=t.row;n++){let e=w(this.#s[n],`Row ${n} not found`);e.collapsed=!0,e.height.setValue(0),this.#t.suggestValue(e.height,0)}}getRectBounds({min:e,max:t}){let n=this.#s[e.row],r=this.#s[t.row];return S(n&&r,`Subflow box invalid minRow=${e.row} maxRow=${t.row}`),{x1:this.actorBox(e.column).centerX,x2:this.actorBox(t.column).centerX,get top(){return n.inner.top},set top(e){n.inner.top=e},get bottom(){return r.inner.bottom},set bottom(e){r.inner.bottom=e},minY:n.outer.top,maxY:r.outer.bottom}}wrapAroundRect(e,t){let n=normalizeSpacing(t??16),r=this.getRectBounds(e),i=this.newVar(0);this.put(i).before(r.x1,n.left);let a=this.newVar(0);this.put(a).after(r.x2,n.right);let o=this.newVar(r.minY.value());this.require(o).after(r.minY),this.put(o).before(r.top,n.top);let s=this.newVar(r.maxY.value());return this.put(s).after(r.bottom,n.bottom),this.require(s).before(r.maxY),r.top=o,r.bottom=s,{x1:i,y1:o,x2:a,y2:s}}createSubflowAreas(r,a){let selectSteps=e=>i(r,t=>t.id.startsWith(e)),o={top:30,right:40,bottom:10,left:90},fitSubflows=({area:r,visited:a,stretch:s=!1,padding:c})=>{let u=l(a,i(v.isSubFlow),n(e=>this.#c.get(e.id)??[]));if(!e(u,1))return;let f=E(c,o),p=t(u),m=d(u);p.min.row==r.min.row&&this.require(r.y1).before(p.y1,f.top),m.max.row==r.max.row&&this.require(m.y2).before(r.y2,f.bottom);for(let e of u)this.require(e.x1).after(r.x1,f.left),this.require(e.x2).before(r.x2,f.right),s&&(e.x1=f.left>0?r.x1.plus(f.left):r.x1,e.x2=f.right>0?r.x2.minus(f.right):r.x2)},createSubflowArea=e=>{let t=rectFromSteps(selectSteps(e.id)),n;switch(!0){case v.isAltOrTry(e):n=0;break;case a.has(e.id)&&v.isAltOrTryBranch(e):n={...o,top:36,bottom:0};break;case a.has(e.id):n={...o,top:24,bottom:0};break;default:n=o;break}let r={...this.wrapAroundRect(t,n),...t};return this.#c.set(e.id,r),r};this.#e.walk({subflow:({subflow:e,previous:t,parent:n})=>({next:a.has(e.id)?[]:e.flow,onLeave:({visited:r})=>{let i=createSubflowArea(e),o=v.isSubFlow(t)&&this.#c.get(t.id);switch(!v.isAltOrTryBranch(e)&&o&&this.put(o.y2).before(i.y1,32),!n&&i.min.column>0&&this.require(this.actorBox(i.min.column-1).centerX).before(i.x1,100),!0){case a.has(e.id):this.collapseRect(i);return;case v.isAltOrTry(e):return fitSubflows({area:i,visited:r,padding:{top:30,left:0,right:0},stretch:!0});case v.isAltOrTryBranch(e):return fitSubflows({area:i,visited:r,padding:{top:50,left:32,bottom:32,right:32}});default:return fitSubflows({area:i,visited:r,padding:{top:40,bottom:12,left:32,right:16}})}}})})}newVar(e){let t=new f;return this.#t.addEditVariable(t,D.weak),typeof e==`number`&&(t.setValue(e),this.#t.suggestValue(t,e)),t}require(...e){if(e.length==1){let[t]=e;return{before:(e,n=0)=>{let r=n?e.minus(n):e;return this.constraint(t,`<=`,r,D.required)},after:(e,n=0)=>{let r=n?e.plus(n):e;return this.constraint(t,`>=`,r,D.required)}}}let[t,n,r]=e,i=this.constraint(t,n,r,D.required);switch(n){case`<=`:case`>=`:this.constraint(t,`==`,r,D.weak);break;case`<= 0`:case`>= 0`:this.constraint(t,`== 0`,void 0,D.weak);break}return i}constraint(e,t,n=void 0,r=D.medium){let i;switch(t){case`==`:i=h.Eq;break;case`>=`:i=h.Ge;break;case`<=`:i=h.Le;break;case`== 0`:i=h.Eq,n=0;break;case`>= 0`:i=h.Ge,n=0;break;case`<= 0`:i=h.Le,n=0;break;default:T(t)}let a=new m(e,i,n??0,r);return this.#t.addConstraint(a),a}put(e,t=D.required){let n=t===D.required?D.soft: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(t){let n=_(t),i=new Set,getNode=e=>w(t.nodes.find(t=>t.id===e)),o=[];for(let e of t.edges){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}i.add(t),i.add(n),o.push({edge:e,source:t,target:n})}let d=t.nodes.filter(e=>i.has(e));S(e(d,1),`actors array must not be empty`);let f=new b(()=>[]),p=[],m=0,h;for(let{edge:e,source:t,target:n}of o){let r=d.indexOf(t),i=d.indexOf(n),a=t===n,o=r>i,s=y(e.id),c=!1;h&&h.target==t&&h.parent===s&&(c=h.isSelfLoop!==a||h.isBack===o),!c&&h&&m++;let l={id:e.id,from:{column:r,row:m},to:{column:i,row:a?++m:m},edge:e,isSelfLoop:a,isBack:o,parent:s,offset:c?(h?.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};p.push(l),f.get(t).push({step:l,row:m,type:`source`,position:o&&!a?`left`:`right`}),f.get(n).push({step:l,row:m,type:`target`,position:o||a?`right`:`left`}),h=l}let g=new SequenceViewLayouter({actors:d,steps:p,compounds:buildCompounds(d,t.nodes),flow:n,collapsedFlows:[]}),v=g.getViewBounds(),x=l(g.getCompoundBoxes(),a(({node:e,...t})=>({...t,id:e.id,origin:e.id})),r(`id`),u((t,n)=>e(t,2)?a(t,(e,t)=>({...e,id:`${n}-${t+1}`})):t),c(),s());return{actors:d.map(e=>toSeqActor({actor:e,ports:f.get(e),layout:g})),compounds:x,steps:a(p,e=>({id:e.id,sourceHandle:e.id+`_source`,targetHandle:e.id+`_target`,...e.label&&{labelBBox:{width:e.label.width,height:e.label.height}}})),parallelAreas:[],subflows:g.getSubflowAreas(),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{E as n,calcSequenceLayout as t};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime.mjs";import{
|
|
1
|
+
import{i as e}from"./rolldown-runtime.mjs";import{f as t,r as n,t as r}from"./dist.mjs";import{_ as i,b as a,g as o,h as s,y as c}from"./libs/langium.mjs";import{o as l}from"./libs/ufo.mjs";import{t as u}from"./libs/json5.mjs";import{R as d,S as f,a as p,c as m,n as h,w as g,y as _}from"./libs/zod.mjs";import{$ as v,B as y,F as b,H as ee,I as te,J as x,K as ne,N as S,Q as C,U as w,Z as T,b as E,c as D,h as O,k,o as A,r as j,t as M,tt as N,v as P,w as F,y as re}from"./libs/remeda.mjs";import{n as ie}from"./node.mjs";import{n as ae,t as oe}from"./libs/package-manager-detector.mjs";import{n as I,t as L}from"./logger.mjs";import{t as se}from"./libs/birpc.mjs";import{t as ce}from"./libs/pako.mjs";import{createRequire as le}from"node:module";import{mkdir as ue,readFile as de,writeFile as fe}from"node:fs/promises";import{resolve as R}from"node:path";import{RichText as pe,exact as me,flattenMarkdownOrString as z}from"@likec4/core/types";import{DefaultMap as B,LikeC4Styles as he,exact as V,invariant as ge,nonexhaustive as _e}from"@likec4/core";import{compareNatural as ve,nonNullable as ye}from"@likec4/core/utils";import"@likec4/core/model";import be from"nano-spawn";import{existsSync as xe}from"node:fs";import{env as H}from"std-env";import U,{cwd as Se}from"node:process";const pDebounce=(e,t,n={})=>{if(!Number.isFinite(t))throw TypeError("Expected `wait` to be a finite number");let r,i,a=[],onAbort=()=>{clearTimeout(i),i=void 0;try{n.signal?.throwIfAborted()}catch(e){for(let{reject:t}of a)t(e);a=[]}};return function(...o){return new Promise((s,c)=>{try{n.signal?.throwIfAborted()}catch(e){c(e);return}let l=n.before&&!i;clearTimeout(i),i=setTimeout(async()=>{i=void 0;let t=a;a=[];try{let i=n.before?r:await e.apply(this,o);for(let{resolve:e}of t)e(i)}catch(e){for(let{reject:n}of t)n(e)}r=void 0,n.signal?.removeEventListener(`abort`,onAbort)},t),l?(async()=>{try{r=await e.apply(this,o),s(r)}catch(e){c(e)}})():(a.push({resolve:s,reject:c}),n.signal&&a.length===1&&n.signal.addEventListener(`abort`,onAbort,{once:!0}))})}};pDebounce.promise=(e,t={})=>{let n,r;return async function(...i){if(n)return t.after?(r??={resolvers:[]},r.arguments=i,r.context=this,new Promise((e,t)=>{r.resolvers.push({resolve:e,reject:t})})):n;n=(async()=>{let t,n;try{t=await e.apply(this,i)}catch(e){n=e}for(;r;){let t=r;r=void 0;try{let n=await e.apply(t.context,t.arguments);for(let{resolve:e}of t.resolvers)e(n)}catch(e){for(let{reject:n}of t.resolvers)n(e)}}if(n)throw n;return t})();try{return await n}finally{n=void 0}}};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=>l(`likec4:plugin`,n,e)+t}}function generateCombinedProjects(e,t){return{id:`likec4:${e}`,virtualId:`likec4:plugin/`+e+`.js`,async load({projects:n}){return L(e),{code:`
|
|
2
2
|
export let ${t}Fn = {
|
|
3
|
-
${n.map(({id:t})=>`${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(t))}: async () => await import(${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(
|
|
3
|
+
${n.map(({id:t})=>`${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(t))}: async () => await import(${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(l(`likec4:${e}`,t)))})`).join(`,
|
|
4
4
|
`)}
|
|
5
5
|
}
|
|
6
6
|
|
|
@@ -34,13 +34,13 @@ if (import.meta.hot) {
|
|
|
34
34
|
}
|
|
35
35
|
})
|
|
36
36
|
}
|
|
37
|
-
`,moduleType:`js`}}}}
|
|
37
|
+
`,moduleType:`js`}}}}function isInstalled(e){try{return!!import.meta.resolve(e,U.cwd())}catch(e){return I.trace(t(e)),!1}}async function ensurePackage(e){let n=I.getChild(`pkg`);if(isInstalled(e)){n.trace`${e} installed`;return}n.warn(r.dim(`not found `)+r.green(e));let{command:i,args:a}=ye(ae(ye(await oe(),()=>{n.error`Package manager not detected, install ${e} manually`,U.exit(1)}).agent,`add`,[e]),()=>{n.error`Install package ${e} manually`,U.exit(1)});n.info(r.dim(`installing `)+r.green(e));try{await be(i,a)}catch(r){n.debug(t(r)),n.error`Install package ${e} manually`,U.exit(1)}}const W=I.getChild(`ai`);function chooseModel(e,t){let n=H[e];return n||=(W.info(`I will use `+r.green(t)+` model `+r.dim(`you can override with `)+r.yellow(e)+r.dim(` env var`)),t),n}const G=16e3;async function loadOpenAI(){W.info(`Found `+r.yellow(`OPENAI_API_KEY`)+r.dim(`, loading @tanstack/ai-openai`)),await ensurePackage(`@tanstack/ai-openai`);let{openaiText:e}=await import(`@tanstack/ai-openai`);return{adapter:e(chooseModel(`OPENAI_CHAT_MODEL`,`gpt-5.2`)),modelOptions:{reasoning:{effort:`medium`}},maxTokens:G}}async function loadOpenRouter(){W.info(`Found `+r.yellow(`OPENROUTER_API_KEY`)+r.dim(`, loading @tanstack/ai-openrouter`)),await ensurePackage(`@tanstack/ai-openrouter`);let{openRouterText:e}=await import(`@tanstack/ai-openrouter`);return{adapter:e(chooseModel(`OPENROUTER_CHAT_MODEL`,`openai/gpt-5.4`)),maxTokens:G}}async function loadAnthropic(){W.info(`Found `+r.yellow(`ANTHROPIC_API_KEY`)+r.dim(`, loading @tanstack/ai-anthropic`)),await ensurePackage(`@tanstack/ai-anthropic`);let{anthropicText:e}=await import(`@tanstack/ai-anthropic`);return{adapter:e(chooseModel(`ANTHROPIC_CHAT_MODEL`,`claude-sonnet-4-6`)),maxTokens:G}}async function loadGemini(){W.info(`Found `+r.yellow(`GEMINI_API_KEY`)+r.dim(`, loading @tanstack/ai-gemini`)),await ensurePackage(`@tanstack/ai-gemini`);let{geminiText:e}=await import(`@tanstack/ai-gemini`);return{adapter:e(chooseModel(`GEMINI_CHAT_MODEL`,`gemini-2.5-pro`)),maxTokens:G}}async function loadOllama(){W.info(`Found `+r.yellow(`OLLAMA_HOST`)+r.dim(`, loading @tanstack/ai-ollama`)),await ensurePackage(`@tanstack/ai-ollama`);let{ollamaText:e}=await import(`@tanstack/ai-ollama`),t=chooseModel(`OLLAMA_CHAT_MODEL`,`qwen3`);return{adapter:e(t),modelOptions:{model:t,think:`low`},maxTokens:G}}function pickLoader(){if(F(H.OPENAI_API_KEY))return loadOpenAI;if(F(H.OPENROUTER_API_KEY))return loadOpenRouter;if(F(H.ANTHROPIC_API_KEY))return loadAnthropic;if(F(H.GEMINI_API_KEY))return loadGemini;if(F(H.OLLAMA_HOST))return loadOllama}const Ce=O(async()=>{let e=pickLoader();if(e){await ensurePackage(`@tanstack/ai`);let t=await e();return W.info([`AI configured with`,r.green(t.adapter.name),`adapter`,r.dim(`you can disable it in plugin options`)].join(` `)),t}}),K=I.getChild(`icons`);function iconBundlePlugin(e){let t=Se(),n=[t];e.workspace&&n.unshift(e.workspace);let i=le(t),a,resolveIcon=async(e,t)=>{try{let a=i.resolve(`@likec4/icons/${e}/${t}`,{paths:n});return K.trace(r.dim(`found in package `)+a),await de(a,`utf-8`)}catch{return}},readFromCache=async(e,t)=>{if(a)try{let n=R(a,e,`${t}.js`);if(xe(n))return K.trace(r.dim(`read cached `)+`${e}/${t}.js`),await de(n,`utf-8`)}catch{}},writeToCache=async(e,t,n)=>{if(a)try{let i=R(a,e);xe(i)||await ue(i,{recursive:!0});let o=R(i,`${t}.js`);await fe(o,n),K.trace(r.dim(`written to cache `)+o)}catch(n){K.error(r.dim(`failed to write to cache `)+`${e}/${t}.js`,{error:n})}},fetchFromRemote=async(e,t)=>{let n=l(`https://icons.like-c4.dev`,e,`${t}.js`);K.trace(r.dim(`fetching `)+n);let i=await fetch(n);if(!i.ok)throw Error(`Failed to fetch icon: ${i.status} ${i.statusText}`);return await i.text()},o=new B(async e=>{try{let[t,n]=e.split(`:`);(n.endsWith(`.jsx`)||n.endsWith(`.js`))&&(n=n.slice(0,n.lastIndexOf(`.`))),K.debug(r.dim(`resolving `)+r.green(`${t}:${n}`));let i=await readFromCache(t,n);return i??=await resolveIcon(t,n),i||(i=await fetchFromRemote(t,n),await writeToCache(t,n,i),i)}catch(t){return K.error(r.dim(`failed to resolve icon `)+r.red(e),{error:t}),`
|
|
38
38
|
export default function NotFoundIcon() {
|
|
39
39
|
return null
|
|
40
40
|
}
|
|
41
|
-
`}});return{name:`likec4:icon-bundle`,sharedDuringBuild:!0,applyToEnvironment(t){return
|
|
42
|
-
`+
|
|
43
|
-
{response}`,{error:t,response:e});return}}function restoreIdsAndMapToHints(e,t){let{mapping:n}=t,nodeId=e=>{let t=n.nodes[e]?.id;return t||
|
|
41
|
+
`}});return{name:`likec4:icon-bundle`,sharedDuringBuild:!0,applyToEnvironment(t){return!e.environments||e.environments.includes(t.name)},configResolved({root:e,...t}){n.unshift(e),t.cacheDir&&(a=R(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(!v(t,2))return null;let[n,r]=t;return{moduleType:`jsx`,code:await o.get(`${n}:${r}`)}}}}}const q=n(`ai-layout`);function truncate(e,t=100){return e=e.replaceAll(/\n/g,` `).trim(),e.length<=t?e:e.slice(0,t-1)+`…`}function mappedEntries(e){let t={};for(let[n,r]of e.entries())t[r]=n;return t}function edgeLabel(e){let t=e.label&&e.label!==`[...]`?e.label:void 0,n=z(e.description);return n&&(t=t?`${t}\n${n}`:n),t??=e.technology??void 0,t?truncate(t):void 0}function prepareLLMInput(e){let t=1,n=1,r=new B(e=>e.children.length===0?`n${n++}`:`c${t++}`),findNodeById=t=>e.nodes.find(e=>e.id===t),nodeId=e=>r.get(findNodeById(e)),i=new Set;e.nodes.forEach(e=>{r.get(e),e.children.length===0&&i.add(e.id)});let a=e.edges.find(e=>!i.has(e.source)||!i.has(e.target));if(a)throw q.error(`Non-leaf edge found in view`,{view:e.id,edge:{source:a.source,target:a.target}}),Error(`Non-leaf edge found in view, this is not supported by the current implementation`);let o=1,s=new B(e=>`e${o++}`),c=e.edges.map(e=>{let t=nodeId(e.source),n=nodeId(e.target),r=e.parent?nodeId(e.parent):null;e.dir===`back`&&([t,n]=[n,t]);let i=edgeLabel(e);return{id:s.get(e),...i&&{label:i},...r&&{parent:r},source:t,target:n}}),reduceNodes=(e,t)=>{let{level:n,kind:i,...a}=t,o=r.get(t),s=a.children.length>0,c=a.parent?nodeId(a.parent):void 0,l=truncate(a.title);if(s)return e.compounds.push(me({id:o,title:l,parent:c,children:a.children.map(nodeId),level:n})),e;let u=a.description?truncate(z(a.description),200):void 0;return e.nodes.push(me({id:o,kind:i,title:l,description:u,parent:c,level:n})),e};return{serialized:e.nodes.reduce(reduceNodes,{direction:e.autoLayout.direction,compounds:[],nodes:[],edges:c}),mapping:{nodes:mappedEntries(r),edges:mappedEntries(s)}}}const we=p([`TB`,`BT`,`LR`,`RL`]),J=g().nonempty().brand(),Te=_({rank:p([`same`,`source`,`sink`,`min`,`max`]),nodes:m(J)}),Y={id:g().nonempty().brand(),weight:h().int().min(0).max(20),minlen:h().int().min(0).max(4)},Ee=_({source:J,target:J,weight:Y.weight.optional(),minlen:Y.minlen.optional()}),De=_({direction:we.optional(),ranks:m(Te).default([]),edgeWeight:f(Y.id,Y.weight).default({}),edgeMinlen:f(Y.id,Y.minlen).default({}),reverseRank:m(Y.id).default([]),excludeFromRanking:m(Y.id).default([]),edgeOrder:m(Y.id).default([]),nodeOrder:m(J).default([]),invisibleEdges:m(Ee).default([]),reasoning:g().default(``)}),Oe=/```(?:json)?\s*\n?([\s\S]*?)\n?\s*```/;function extractJson(e){let t=Oe.exec(e);if(t&&t[1])return t[1];let n=e.indexOf(`{`),r=e.lastIndexOf(`}`);return n!==-1&&r!==-1&&r>n?e.slice(n,r+1):e.trim()}function parseOutput(e,t){try{let n=extractJson(e),r=u.parse(n),i=De.safeParse(r);if(!i.success){q.warn(`Failed to validate LLM response
|
|
42
|
+
`+d(i.error));return}return restoreIdsAndMapToHints(i.data,t)}catch(t){q.warn(`Failed to parse LLM response
|
|
43
|
+
{response}`,{error:t,response:e});return}}function restoreIdsAndMapToHints(e,t){let{mapping:n}=t,nodeId=e=>{let t=n.nodes[e]?.id;return t||q.warn`Unknown node ID ${e} in LLM output, skipping`,t},mapToNodeId=e=>N(e,E(nodeId),T(b)),edgeId=e=>{let t=n.edges[e]?.id;return t||q.warn`Unknown edge ID ${e} in LLM output, skipping`,t},mapToNonEmpty=(e,t)=>{let n=e.map(t).filter(b);return v(n,1)?n:void 0},r=N(e.excludeFromRanking,E(edgeId),T(b),j(),e=>v(e,1)?e:void 0),i=N(e.reverseRank,E(edgeId),T(b),j(),e=>v(e,1)?e:void 0),a=(()=>{let e=new Set;return t=>t.filter(t=>e.has(t)?!1:(e.add(t),!0))})(),o=N(e.ranks,E(e=>{let t=a(mapToNodeId(e.nodes));return v(t,1)?{rank:e.rank,nodes:t}:null}),T(F)),s=N(e.invisibleEdges,E(({source:e,target:t,minlen:n=1,weight:r=1})=>{let i=nodeId(e),a=nodeId(t);if(!(!i||!a))return V({weight:r===1?void 0:r,minlen:n===1?void 0:n,source:i,target:a})}),T(b),ee(e=>`${e.source}->${e.target}`),P(([e,...t])=>N(t,D((e,t)=>V({...e,...t,weight:e.weight&&t.weight?Math.max(e.weight,t.weight):e.weight||t.weight,minlen:e.minlen&&t.minlen?Math.max(e.minlen,t.minlen):e.minlen||t.minlen}),e))),M(),e=>v(e,1)?e:void 0),c=e.reasoning;c&&(c=c.replaceAll(`][`,`] [`),C(t.mapping.nodes).forEach(([e,t])=>{c=c.replaceAll(RegExp(`\\[${e}\\]`,`g`),"`"+t.id+"`")}),C(t.mapping.edges).forEach(([e,t])=>{c=c.replaceAll(RegExp(`\\[${e}\\]`,`g`),"`"+t.source+` -> `+t.target+"`")}));let safeMapEdgeKeys=e=>{let t={};for(let[n,r]of C(e)){let e=edgeId(n);e&&(t[e]=r)}return t};return V({direction:e.direction,ranks:o,edgeWeight:safeMapEdgeKeys(e.edgeWeight),edgeMinlen:safeMapEdgeKeys(e.edgeMinlen),excludeFromRanking:r,reverseRank:i,edgeOrder:mapToNonEmpty(e.edgeOrder,edgeId),nodeOrder:mapToNonEmpty(e.nodeOrder,nodeId),invisibleEdges:s,reasoning:c})}const ke={systemPrompt:`You are an advisor specializing in software architecture diagrams and graphviz (DOT) layout optimizations.
|
|
44
44
|
You receive a JSON of Diagram data with:
|
|
45
45
|
- nodes (architectural elements, rendered as leaf boxes)
|
|
46
46
|
- compounds (group of nodes or other compounds, define hierarchy and rendered as boxes around children)
|
|
@@ -226,10 +226,10 @@ OUTPUT:
|
|
|
226
226
|
"reasoning": "I reversed [e4] as it moves [n4] to the top, pushes [n3] to the next row and balances layout, [e5] \`minlen=0\` to keep [n2][n3] on same rank"
|
|
227
227
|
}
|
|
228
228
|
\`\`\`
|
|
229
|
-
</example>`,userPrompt:`Analyze semantics and suggest layout hints for the following diagram. Return only JSON object without any additional text or markdown formatting.`};async function enhanceLayoutWithAI(e,t,n){try{
|
|
229
|
+
</example>`,userPrompt:`Analyze semantics and suggest layout hints for the following diagram. Return only JSON object without any additional text or markdown formatting.`};async function enhanceLayoutWithAI(e,t,n){try{q.debug`generating AI layout hints for ${e.id} using ${t.name}`;let{serialized:r,mapping:i}=prepareLLMInput(e);return parseOutput(await t.sendRequest({...ke,view:e,mapping:i,diagram:JSON.stringify(r)},n),{mapping:i,view:e})}catch(e){q.warn(`AI layout enhancement failed`,{error:e});return}}async function applySemanticLayout({logger:e,ai:t,likec4:n,server:i},a){ge(t,`AI is not configured`),e.info([r.green(`semantic:layout`),r.dim(`project:`),a.projectId,r.dim(`view:`),a.viewId].join(` `));let o={started:()=>i.hot.send(`likec4:apply-semantic-layout`,{type:`started`}),completed:()=>i.hot.send(`likec4:apply-semantic-layout`,{type:`completed`}),log:e=>i.hot.send(`likec4:apply-semantic-layout`,{log:e})},{chat:s,EventType:c}=await import(`@tanstack/ai`),l=(await n.computedModel(a.projectId)).findView(a.viewId);ge(l,`View ${a.viewId} not found in project ${a.projectId}`),e.info([r.green(`semantic:layout`),r.dim(`call`),t.adapter.name].join(` `));let u=await enhanceLayoutWithAI(l.$view,{name:t.adapter.name,async sendRequest({systemPrompt:e,userPrompt:n,diagram:r}){o.started();let i=s({...t,systemPrompts:[e],stream:!0,messages:[{role:`user`,content:[{type:`text`,content:e},{type:`text`,content:n},{type:`text`,content:r}]}]}),a=``;for await(let e of i)switch(e.type){case c.TEXT_MESSAGE_CONTENT:o.log(e.delta),a+=e.delta;break;case c.REASONING_MESSAGE_CONTENT:o.log(e.delta);break}return a}});if(o.completed(),!u){e.warn([r.yellow(`semantic:layout`),`No semantic layout generated`].join(` `));return}e.info([r.green(`semantic:layout`),r.dim(`apply ai hints to layout`)].join(` `));let d=await n.views.layoutView({viewId:a.viewId,projectId:a.projectId,layoutHints:u});if(!d){e.error([r.red(`semantic:layout`),`layout hints failed`].join(` `));return}e.info([r.green(`semantic:layout`),r.dim(`save view snapshot`)].join(` `));let f=await n.editor.applyChange({viewId:a.viewId,projectId:a.projectId,change:{op:`save-view-snapshot`,layout:d.diagram}});if(!f.success){e.error([r.red(`semantic:layout`),`apply change failed`,f.error].join(` `));let t=Error(f.error);throw t.stack=f.error,t}e.info([r.green(`semantic:layout`),r.dim(`project:`),a.projectId,r.dim(`view:`),a.viewId,`✅`].join(` `))}async function calcAdhocView({logger:e,likec4:t},n){e.info([r.green(`adhoc:view`),r.dim(`project:`),n.projectId].join(` `));let i=await t.views.adhocView(n.predicates,n.projectId);return e.info([r.green(`adhoc:view`),`✅`].join(` `)),i}async function updateView({logger:e,likec4:t},n){e.info([r.green(`view:onChange`),r.dim(`project`),n.projectId,r.dim(`view`),n.viewId,r.dim(`change`),n.change.op].join(` `));let i=await t.editor.applyChange(n);if(!i.success){e.error(`Failed to apply view change:\n${i.error}`);let t=Error(i.error);throw t.stack=i.error,t}e.info([r.green(`view:onChange`),`✅`].join(` `))}function splitErrorMessage(e){let t=e.split(`
|
|
230
230
|
`),n=/^\s+at\s+/,r=t.findIndex(e=>n.test(e));return r===-1&&(r=1),{message:t.slice(0,r).join(`
|
|
231
231
|
`),stack:t.slice(r).join(`
|
|
232
|
-
`)}}function sendError(e,{name:t,error:n}){e.hot.send({type:`error`,err:{...splitErrorMessage(n),name:t??`LikeC4PluginError`,plugin:`vite-plugin-likec4`}})}function enablePluginRPC(e){let t=null,n=e.server;
|
|
232
|
+
`)}}function sendError(e,{name:t,error:n}){e.hot.send({type:`error`,err:{...splitErrorMessage(n),name:t??`LikeC4PluginError`,plugin:`vite-plugin-likec4`}})}function enablePluginRPC(e){let t=null,n=e.server;se({updateView:t=>updateView(e,t),calcAdhocView:t=>calcAdhocView(e,t),applySemanticLayout:t=>applySemanticLayout(e,t)},{on:e=>n.hot.on(`likec4:rpc`,e),post:e=>n.hot.send(`likec4:rpc`,e),onTimeoutError(e){return e===`applySemanticLayout`},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 L(`app-config`),`
|
|
233
233
|
export let ComponentName = {
|
|
234
234
|
View: ${JSON.stringify(t+`-view`)},
|
|
235
235
|
Browser: ${JSON.stringify(t+`-browser`)},
|
|
@@ -252,11 +252,11 @@ export let defaultTheme = ${JSON.stringify(i)}
|
|
|
252
252
|
export let krokiD2SvgUrl = import.meta.env.VITE_KROKI_D2_SVG_URL || 'https://kroki.io/d2/svg'
|
|
253
253
|
export let krokiPumlSvgUrl = import.meta.env.VITE_KROKI_D2_SVG_URL || 'https://kroki.io/plantuml/svg'
|
|
254
254
|
|
|
255
|
-
`}}}const
|
|
256
|
-
`);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(
|
|
257
|
-
<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:
|
|
258
|
-
${u}${buildMxUserObjectXml(
|
|
259
|
-
</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(
|
|
255
|
+
`}}}const Ae=e(e=>e.charAt(0).toLocaleUpperCase()+e.slice(1),`capitalizeFirstLetter`),je=e(e=>e.split(`.`).map(Ae).join(``),`fqnName`),Me=e(e=>je(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,a=new Map,printNode=(e,t)=>{let r=Me(e),c=(t?t+`.`:``)+r;a.set(e.id,c);let l=JSON.stringify(e.title),u=d2shape(e);return new o().append(r,`: {`,i).indent({indentedChildren:t=>t.append(`label: `,l,i).appendIf(u!==`rectangle`,`shape: `,u,i).appendIf(e.children.length>0,i,s(n.filter(t=>t.parent===e.id),e=>printNode(e,c))),indentation:2}).append(`}`,i)},printEdge=e=>new o().append(a.get(e.source),` -> `,a.get(e.target)).append(t=>e.label&&t.append(`: `,JSON.stringify(e.label)));return c(new o().append(`direction: `,d2direction(t),i,i).append(s(n.filter(e=>k(e.parent)),e=>printNode(e),{appendNewLineIfNotEmpty:!0})).appendIf(r.length>0,i,s(r,e=>printEdge(e),{appendNewLineIfNotEmpty:!0})))}const X=`data:page/id,likec4-`,Ne=`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(`
|
|
256
|
+
`);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(ce.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 Z={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}},Q={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??he.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 he.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(`${X}${e}`)};`}function toExportString(e){let t=e==null?null:z(e);return t!=null&&!S(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 Pe=/^#([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&&Pe.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?``:`
|
|
257
|
+
<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:Q.getKind(e),edgeNotation:Q.getNotation(e),edgeLinksJson:linksToStyleJson(Q.getLinks(e)),edgeMetadataJson:metadataToStyleJson(Q.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}">
|
|
258
|
+
${u}${buildMxUserObjectXml(Q.getCustomData(e))}
|
|
259
|
+
</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(Z.getNotes(e)),_=Z.getTags(e),v=Array.isArray(_)&&_.length>0?_.join(`,`):``,y=toNonEmptyString(Z.getNavigateTo(e)),b=toNonEmptyString(Z.getIcon(e)),ee=f===`actor`||e.shape===`person`,te=d?`shape=rectangle;rounded=0;container=1;collapsible=0;startSize=0;`:ee?`shape=actor;`:drawioShape(e.shape),x=l?.[e.id],ne=u?.[e.id],S=x?applyStrokeColorOverride(getElementColors(r,e.color),x):getElementColors(r,e.color),C=S?.fill??`#dae8fc`,w=S?.stroke??`#2563eb`,T=S?.font??S?.stroke??`#1e40af`,E=`fillColor=${C};strokeColor=${w};fontColor=${T};`,D=e.style,O=a.fontSize(D?.textSize),k=escapeXml(buildNodeValueHtml(p,m,d,T,o,O)),A=D?.border,j=ne??getDefaultStrokeWidth(A,d),M=j===``?``:`strokeWidth=${j};`,N=getContainerDashedStyle(d,A),P=d===!0?D?.opacity??15:void 0,F=P!=null&&d===!0?`fillOpacity=${Math.min(100,Math.max(0,P))};`:``,re=buildLikec4StyleForNode({desc:m,tech:h,notes:g,tagList:v,navTo:y,iconName:b,summaryStr:toExportString(Z.getSummary(e)),linksJson:linksToStyleJson(Z.getLinks(e)),borderVal:A,containerOpacityNum:P,strokeWidth:j,colorNameForRoundtrip:e.color?encodeURIComponent(String(e.color)):``,nodeStyle:D,strokeHex:w,nodeNotation:Z.getNotation(e)})+buildBridgeManagedStyleForNode(e.id,f,t.view.id,n),ie=buildMxUserObjectXml(Z.getCustomData(e)),ae=buildNavLinkStyle(y);return{value:k,styleStr:`${d?`align=left;verticalAlign=top;overflow=fill;whiteSpace=wrap;html=1;`:`align=center;verticalAlign=middle;verticalLabelPosition=middle;labelPosition=center;fontSize=${O};fontStyle=1;spacingTop=4;spacingLeft=2;spacingRight=2;spacingBottom=2;overflow=fill;whiteSpace=wrap;html=1;fontFamily=${encodeURIComponent(o)};`}${te}${E}${M}${N}${F}${ae}${re}`,userObjectXml:ie,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="${X}${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="${X}${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 $={x:0,y:0,width:120,height:60};function isDefaultBbox(e){return e.x===$.x&&e.y===$.y&&e.width===$.width&&e.height===$.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=(Z.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)=>k(e.parent)&&k(t.parent)?0:k(e.parent)?-1:k(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=Z.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:m}=computeContentBoundsAndOffsets(o);return{view:n,bboxes:o,containerNodeIds:c,sortedNodes:a,offsetX:d,offsetY:f,canvasWidth:p,canvasHeight:m,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}">
|
|
260
260
|
<mxGeometry x="0" y="0" width="${l}" height="${u}" as="geometry" />
|
|
261
261
|
</mxCell>`,...p,...m,...h].join(`
|
|
262
262
|
`),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">
|
|
@@ -272,8 +272,8 @@ export let krokiPumlSvgUrl = import.meta.env.VITE_KROKI_D2_SVG_URL || 'https://k
|
|
|
272
272
|
${e.map(e=>` <diagram name="${escapeXml(e.name)}" id="likec4-${escapeXml(e.id)}">${e.content}</diagram>`).join(`
|
|
273
273
|
`)}
|
|
274
274
|
</mxfile>
|
|
275
|
-
`}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
|
|
276
|
-
`).map(e=>S(e)?e:withColor(e)).join(`\\n`)),t&&t!==n&&
|
|
275
|
+
`}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 Fe=e(e=>e.charAt(0).toLocaleUpperCase()+e.slice(1),`capitalizeFirstLetter`),Ie=e(e=>e.split(`.`).map(Fe).join(``),`fqnName`),Le=e(e=>Ie(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:_e(e)}};function generateMermaid(e){let t=e.$view,{nodes:n,edges:r}=t,a=new Map,printNode=(e,t)=>{let r=Le(e),c=(t?t+`.`:``)+r;a.set(e.id,c);let l=new o;if(e.children.length>0){let t=toSingleQuotes(e.title);l.append(`subgraph `,c,'["`',t,'`"]',i).indent({indentedChildren:[s(n.filter(t=>t.parent===e.id),e=>printNode(e,c),{appendNewLineIfNotEmpty:!0})],indentation:2}).append(`end`,i)}else l.append(c,mmdshape(e));return l},printEdge=e=>new o().append(a.get(e.source),` -.`,e.label?' "`'+toSingleQuotes(e.label)+'`" .-':`-`,`> `,a.get(e.target));return c(new o().append(`---`,i,`title: ${JSON.stringify(toSingleQuotes(e.titleOrId))}`,i,`---`,i).append(`graph `,t.autoLayout.direction,i).indent({indentedChildren:e=>{e.append(s(n.filter(e=>k(e.parent)),e=>printNode(e),{appendNewLineIfNotEmpty:!0})).appendIf(r.length>0,s(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:_e(e)}},escapeLabel=e=>S(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:a}=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,`"`,i).append(pumlDirection(t),` direction`,i),printTheme=()=>new o().append(`hide stereotype`,i).append(`skinparam ranksep `,`60`,i).append(`skinparam nodesep `,`30`,i).append(`skinparam {`,i).indent({indentedChildren:e=>e.append(`arrowFontSize `,`10`,i).append(`defaultTextAlignment `,`center`,i).append(`wrapWidth `,`200`,i).append(`maxMessageSize `,`100`,i).append(`shadowing `,`false`,i),indentation:2}).append(`}`,i),printStereotypes=e=>{let t=pumlShape(e),n=fqnName(e.id);return new o().append(`skinparam `,t,`<<`,n,`>>`,`{`,i).indent({indentedChildren:t=>t.append(`BackgroundColor `,pumlColor(e.color,elementColorProvider(`fill`)),i).append(`FontColor `,pumlColor(e.color,elementColorProvider(`hiContrast`),`#FFFFFF`),i).append(`BorderColor `,pumlColor(e.color,elementColorProvider(`stroke`)),i),indentation:2}).append(`}`,i)},printNode=e=>{let t=pumlShape(e),n=fqnName(e.id),r=escapeLabel(e.title)||nodeName(e),a=escapeLabel(e.technology);l.set(e.id,n);let s=pe.from(e.description);return new o().append(t,` `).append(`"`).append(`==`,r).appendIf(!!a,`\\n<size:10>[`,a,`]</size>`).appendIf(s.nonEmpty,`\\n\\n`,escapeLabel(s.text)).append(`"`,` <<`,n,`>> `,`as `,n,i)},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,` {`,i).indent({indentedChildren:t=>t.append(`skinparam `,`RectangleBorderColor<<`,n,`>> `,pumlColor(e.color,elementColorProvider(`fill`)),i).append(`skinparam `,`RectangleFontColor<<`,n,`>> `,pumlColor(e.color,elementColorProvider(`fill`)),i).append(`skinparam `,`RectangleBorderStyle<<`,n,`>> `,`dashed`,i,i).append(s(r.filter(t=>t.parent===e.id),e=>e.children.length>0?printBoundary(e):printNode(e))),indentation:2}).append(`}`,i)},printEdge=e=>{let t=e.technology||``,n=e.label||t,r=pumlColor(e.color,relationshipsColorProvider(`line`),`#777777`),withColor=e=>`<color:${r}>${e.replaceAll(`"`,`'`)}`,a=new o().append(l.get(e.source),` .[`,r,`,thickness=2].> `,l.get(e.target));return(n||t)&&(a.append(` : `,n.split(`
|
|
276
|
+
`).map(e=>S(e)?e:withColor(e)).join(`\\n`)),t&&t!==n&&a.append(`\\n<size:8>[`,withColor(t),`]</size>`)),a.append(i)};return c(new o().append(`@startuml`,i).append(printHeader(),i).append(printTheme(),i).append(s(r.filter(e=>e.children.length==0),e=>printStereotypes(e),{appendNewLineIfNotEmpty:!0})).append(s(r.filter(e=>k(e.parent)),e=>e.children.length>0?printBoundary(e):printNode(e),{appendNewLineIfNotEmpty:!0})).appendIf(a.length>0,i,s(a,e=>printEdge(e),{appendNewLineIfNotEmpty:!0})).append(`@enduml`,i))}function code$9(e){let t=new o;return t.appendTemplate`
|
|
277
277
|
/******************************************************************************
|
|
278
278
|
* This file was generated
|
|
279
279
|
* DO NOT EDIT MANUALLY!
|
|
@@ -282,7 +282,7 @@ ${e.map(e=>` <diagram name="${escapeXml(e.name)}" id="likec4-${escapeXml(e.id)}
|
|
|
282
282
|
|
|
283
283
|
export let d2Source = (viewId) => {
|
|
284
284
|
switch (viewId) {
|
|
285
|
-
`.appendNewLine().indent({indentation:4,indentedChildren(t){t.append(
|
|
285
|
+
`.appendNewLine().indent({indentation:4,indentedChildren(t){t.append(s([...e.views()],e=>a`
|
|
286
286
|
case ${JSON.stringify(e.id)}: {
|
|
287
287
|
return ${JSON.stringify(generateD2(e))}
|
|
288
288
|
}
|
|
@@ -290,9 +290,9 @@ ${e.map(e=>` <diagram name="${escapeXml(e.name)}" id="likec4-${escapeXml(e.id)}
|
|
|
290
290
|
default: {
|
|
291
291
|
throw new Error('Unknown viewId: ' + viewId)
|
|
292
292
|
}
|
|
293
|
-
`}}).append(
|
|
293
|
+
`}}).append(i,` }`,i).appendTemplate`
|
|
294
294
|
}
|
|
295
|
-
`.append(
|
|
295
|
+
`.append(i,i),c(t)}e(code$9,`code`);const Re={...generateMatches(`d2`),async load({likec4:e,project:t}){return L(`d2`,t.id),{code:code$9(await e.computedModel(t.id)),moduleType:`js`}}},ze=generateCombinedProjects(`d2`,`loadD2Sources`);function code$8(e){let t=new o;return t.appendTemplate`
|
|
296
296
|
/******************************************************************************
|
|
297
297
|
* This file was generated
|
|
298
298
|
* DO NOT EDIT MANUALLY!
|
|
@@ -301,7 +301,7 @@ ${e.map(e=>` <diagram name="${escapeXml(e.name)}" id="likec4-${escapeXml(e.id)}
|
|
|
301
301
|
|
|
302
302
|
export let dotSource = (viewId) => {
|
|
303
303
|
switch (viewId) {
|
|
304
|
-
`.appendNewLine().indent({indentation:4,indentedChildren(t){t.append(
|
|
304
|
+
`.appendNewLine().indent({indentation:4,indentedChildren(t){t.append(s(Object.keys(e),t=>a`
|
|
305
305
|
case ${JSON.stringify(t)}: {
|
|
306
306
|
return ${JSON.stringify(e[t].dot)}
|
|
307
307
|
}
|
|
@@ -309,12 +309,12 @@ ${e.map(e=>` <diagram name="${escapeXml(e.name)}" id="likec4-${escapeXml(e.id)}
|
|
|
309
309
|
default: {
|
|
310
310
|
throw new Error('Unknown viewId: ' + viewId)
|
|
311
311
|
}
|
|
312
|
-
`}}).append(
|
|
312
|
+
`}}).append(i,` }`,i).appendTemplate`
|
|
313
313
|
}
|
|
314
314
|
|
|
315
315
|
export let svgSource = (viewId) => {
|
|
316
316
|
switch (viewId) {
|
|
317
|
-
`.appendNewLine().indent({indentation:4,indentedChildren(t){t.append(
|
|
317
|
+
`.appendNewLine().indent({indentation:4,indentedChildren(t){t.append(s(Object.keys(e),t=>a`
|
|
318
318
|
case ${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(t))}: {
|
|
319
319
|
return ${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(e[t].svg))}
|
|
320
320
|
}
|
|
@@ -322,7 +322,7 @@ ${e.map(e=>` <diagram name="${escapeXml(e.name)}" id="likec4-${escapeXml(e.id)}
|
|
|
322
322
|
default: {
|
|
323
323
|
throw new Error('Unknown viewId: ' + viewId)
|
|
324
324
|
}
|
|
325
|
-
`}}).append(
|
|
325
|
+
`}}).append(i,` }`,i,`}`,i,i),c(t)}e(code$8,`code`);const Be={...generateMatches(`dot`),async load({likec4:e,project:t}){return L(`dot`,t.id),{code:code$8(re(await e.views.viewsAsGraphvizOut(t.id),({id:e,svg:t,dot:n})=>[e,{dot:n,svg:t}])),moduleType:`js`}}},Ve=generateCombinedProjects(`dot`,`loadDotSources`);function code$7(e){let t=new o;return t.appendTemplate`
|
|
326
326
|
/******************************************************************************
|
|
327
327
|
* This file was generated
|
|
328
328
|
* DO NOT EDIT MANUALLY!
|
|
@@ -331,7 +331,7 @@ ${e.map(e=>` <diagram name="${escapeXml(e.name)}" id="likec4-${escapeXml(e.id)}
|
|
|
331
331
|
|
|
332
332
|
export function drawioEditUrl(viewId) {
|
|
333
333
|
switch (viewId) {
|
|
334
|
-
`.appendNewLine().indent({indentation:4,indentedChildren(t){t.append(
|
|
334
|
+
`.appendNewLine().indent({indentation:4,indentedChildren(t){t.append(s([...e.views()],e=>a`
|
|
335
335
|
case ${JSON.stringify(e.id)}: {
|
|
336
336
|
return ${JSON.stringify(generateDrawioEditUrl(generateDrawio(e)))}
|
|
337
337
|
}
|
|
@@ -339,9 +339,9 @@ ${e.map(e=>` <diagram name="${escapeXml(e.name)}" id="likec4-${escapeXml(e.id)}
|
|
|
339
339
|
default: {
|
|
340
340
|
throw new Error('Unknown viewId: ' + viewId)
|
|
341
341
|
}
|
|
342
|
-
`}}).append(
|
|
342
|
+
`}}).append(i,` }`,i).appendTemplate`
|
|
343
343
|
}
|
|
344
|
-
`.append(
|
|
344
|
+
`.append(i,i),c(t)}e(code$7,`code`);const He={...generateMatches(`drawio`),async load({likec4:e,project:t}){return L(`drawio`,t.id),{code:code$7(await e.layoutedModel(t.id)),moduleType:`js`}}},Ue=generateCombinedProjects(`drawio`,`loadDrawioSources`),We=/^(https?:)?\/\//i;function code$6(e){let{imports:t,cases:n}=N(e,ne(e=>e.nodes),E(e=>e.icon??void 0),T(e=>F(e)&&!We.test(e)),j(),A(ve)).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`
|
|
345
345
|
import { jsx } from 'react/jsx-runtime'
|
|
346
346
|
${t.join(`
|
|
347
347
|
`)}
|
|
@@ -357,9 +357,9 @@ export function IconRenderer({ node, ...props }) {
|
|
|
357
357
|
}
|
|
358
358
|
return jsx(IconComponent, props)
|
|
359
359
|
}
|
|
360
|
-
`}e(code$6,`code`);const
|
|
360
|
+
`}e(code$6,`code`);const Ge={...generateMatches(`icons`,`.jsx`),async load({likec4:e,project:t}){L(`icons`,t.id);let n=await e.computedModel(t.id);return{moduleType:`jsx`,code:code$6([...M(n.$data.views),...M(n.$data.manualLayouts??{})])}}},Ke=/^[a-zA-Z0-9_.-]+$/;function embedProjectIdAsJsString(e){if(!Ke.test(e))throw Error(`Unsafe value for code generation: ${e}`);return JSON.stringify(e)}function embedUrlAsJsString(e){return JSON.stringify(e)}const qe={id:`likec4:icons`,virtualId:`likec4:plugin/icons.jsx`,async load({projects:e,logger:t}){L(`icons`);let{imports:n,cases:i}=e.filter(e=>Ke.test(e.id)?!0:(t.warn(r.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(l(`likec4:icons`,t.id)));return e.imports.push(`import {IconRenderer as ${r}} from ${a}`),e.cases.push(` ${i}: ${r}`),e},{imports:[],cases:[]});return{code:`
|
|
361
361
|
import { jsx } from 'react/jsx-runtime'
|
|
362
|
-
${
|
|
362
|
+
${n.join(`
|
|
363
363
|
`)}
|
|
364
364
|
|
|
365
365
|
export let ProjectIconsRegistry = {
|
|
@@ -397,7 +397,7 @@ if (import.meta.hot) {
|
|
|
397
397
|
}
|
|
398
398
|
})
|
|
399
399
|
}
|
|
400
|
-
`,moduleType:`jsx`}}};function code$5(e){let t=new
|
|
400
|
+
`,moduleType:`jsx`}}};function code$5(e){let t=new o;return t.appendTemplate`
|
|
401
401
|
/******************************************************************************
|
|
402
402
|
* This file was generated
|
|
403
403
|
* DO NOT EDIT MANUALLY!
|
|
@@ -406,7 +406,7 @@ if (import.meta.hot) {
|
|
|
406
406
|
|
|
407
407
|
export let mmdSource = (viewId) => {
|
|
408
408
|
switch (viewId) {
|
|
409
|
-
`.appendNewLine().indent({indentation:4,indentedChildren(t){t.append(
|
|
409
|
+
`.appendNewLine().indent({indentation:4,indentedChildren(t){t.append(s([...e.views()],e=>a`
|
|
410
410
|
case ${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(e.id))}: {
|
|
411
411
|
return ${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(generateMermaid(e)))}
|
|
412
412
|
}
|
|
@@ -414,13 +414,13 @@ if (import.meta.hot) {
|
|
|
414
414
|
default: {
|
|
415
415
|
throw new Error('Unknown viewId: ' + viewId)
|
|
416
416
|
}
|
|
417
|
-
`}}).append(
|
|
417
|
+
`}}).append(i,` }`,i).appendTemplate`
|
|
418
418
|
}
|
|
419
419
|
|
|
420
|
-
`.append(
|
|
420
|
+
`.append(i,i),c(t)}e(code$5,`code`);const Je={...generateMatches(`mmd`),async load({likec4:e,project:t}){return L(`mmd`,t.id),{code:code$5(await e.computedModel(t.id)),moduleType:`js`}}},Ye=generateCombinedProjects(`mmd`,`loadMmdSources`),projectModelCode=e=>`
|
|
421
421
|
import { createHooksForModel, atom } from 'likec4/vite-plugin/internal'
|
|
422
422
|
|
|
423
|
-
export let $likec4data = atom(${
|
|
423
|
+
export let $likec4data = atom(${u.stringify(e.$data)})
|
|
424
424
|
|
|
425
425
|
export let {
|
|
426
426
|
updateModel,
|
|
@@ -443,11 +443,11 @@ if (import.meta.hot) {
|
|
|
443
443
|
}
|
|
444
444
|
})
|
|
445
445
|
}
|
|
446
|
-
`,
|
|
446
|
+
`,Xe={...generateMatches(`model`),async load({likec4:e,project:t}){L(`model`,t.id);let n=await e.layoutedModel(t.id);return{code:projectModelCode(n),moduleType:`js`}}},Ze=generateCombinedProjects(`model`,`loadModel`),Qe=e(e=>`
|
|
447
447
|
import { atom, useStore } from 'likec4/vite-plugin/internal'
|
|
448
448
|
|
|
449
449
|
export const isSingleProject = ${e.length===1};
|
|
450
|
-
export const projects = ${
|
|
450
|
+
export const projects = ${u.stringify(e,null,2)};
|
|
451
451
|
|
|
452
452
|
export const $projects = atom([...projects])
|
|
453
453
|
|
|
@@ -473,10 +473,10 @@ if (import.meta.hot) {
|
|
|
473
473
|
}
|
|
474
474
|
})
|
|
475
475
|
}
|
|
476
|
-
`,`code`),$e={id:`likec4:projects`,virtualId:`likec4:plugin/projects.js`,async load({projects:e}){return
|
|
476
|
+
`,`code`),$e={id:`likec4:projects`,virtualId:`likec4:plugin/projects.js`,async load({projects:e}){return L(`projects`),{code:Qe(E(e,e=>({id:e.id,title:e.title,landingPage:e.config.landingPage}))),moduleType:`js`}}},et=e(e=>`
|
|
477
477
|
import { atom, useStore } from 'likec4/vite-plugin/internal'
|
|
478
478
|
|
|
479
|
-
export const $viewdata = atom(${
|
|
479
|
+
export const $viewdata = atom(${u.stringify(e)})
|
|
480
480
|
|
|
481
481
|
export function useLikeC4ProjectsOverview() {
|
|
482
482
|
return useStore($viewdata)
|
|
@@ -499,7 +499,7 @@ if (import.meta.hot) {
|
|
|
499
499
|
export function useLikeC4ProjectsOverview() {
|
|
500
500
|
throw new Error('No projects overview available for this workspace: single project mode is enabled')
|
|
501
501
|
}
|
|
502
|
-
`,tt={id:`likec4:projects-overview`,virtualId:`likec4:plugin/projects-overview.js`,async load({projects:e,likec4:t}){
|
|
502
|
+
`,tt={id:`likec4:projects-overview`,virtualId:`likec4:plugin/projects-overview.js`,async load({projects:e,likec4:t}){if(e.length<2)return noProjects();L(`projects-overview`);let n=await t.projectsOverview();return{code:et(n),moduleType:`js`}}};function code$2(e){let t=new o;return t.appendTemplate`
|
|
503
503
|
/******************************************************************************
|
|
504
504
|
* This file was generated
|
|
505
505
|
* DO NOT EDIT MANUALLY!
|
|
@@ -508,7 +508,7 @@ export function useLikeC4ProjectsOverview() {
|
|
|
508
508
|
|
|
509
509
|
export let pumlSource = (viewId) => {
|
|
510
510
|
switch (viewId) {
|
|
511
|
-
`.appendNewLine().indent({indentation:4,indentedChildren(t){t.append(
|
|
511
|
+
`.appendNewLine().indent({indentation:4,indentedChildren(t){t.append(s([...e.views()],e=>a`
|
|
512
512
|
case ${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(e.id))}: {
|
|
513
513
|
return ${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(generatePuml(e)))}
|
|
514
514
|
}
|
|
@@ -516,9 +516,9 @@ export function useLikeC4ProjectsOverview() {
|
|
|
516
516
|
default: {
|
|
517
517
|
throw new Error('Unknown viewId: ' + viewId)
|
|
518
518
|
}
|
|
519
|
-
`}}).append(
|
|
519
|
+
`}}).append(i,` }`,i).appendTemplate`
|
|
520
520
|
}
|
|
521
|
-
`.append(
|
|
521
|
+
`.append(i,i),c(t)}e(code$2,`code`);const nt={...generateMatches(`puml`),async load({likec4:e,project:t}){return L(`puml`,t.id),{code:code$2(await e.computedModel(t.id)),moduleType:`js`}}},rt=generateCombinedProjects(`puml`,`loadPumlSources`),projectCode=e=>`
|
|
522
522
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
523
523
|
import { LikeC4ModelProvider as Provider, LikeC4View as GenericView, ReactLikeC4 as GenericReactLikeC4 } from 'likec4/react';
|
|
524
524
|
import { IconRenderer } from 'likec4:icons/${e}'
|
|
@@ -541,7 +541,7 @@ export {
|
|
|
541
541
|
useLikeC4View,
|
|
542
542
|
useLikeC4Views
|
|
543
543
|
}
|
|
544
|
-
`,it={...generateMatches(`react`),async load({project:e}){return
|
|
544
|
+
`,it={...generateMatches(`react`),async load({project:e}){return L(`react`,e.id),{code:projectCode(e.id),moduleType:`js`}}},at={id:`likec4:react`,virtualId:`likec4:plugin/react.js`,async load({projects:e}){let t=x(e);return L(`react-default-project`),{code:`export {
|
|
545
545
|
useLikeC4Model,
|
|
546
546
|
useLikeC4View,
|
|
547
547
|
useLikeC4Views,
|
|
@@ -580,7 +580,7 @@ export const likec4rpc = rpc ?? {
|
|
|
580
580
|
throw new Error('likec4rpc.calcAdhocView is not available in production')
|
|
581
581
|
},
|
|
582
582
|
}
|
|
583
|
-
`,`code`),st={id:`likec4:rpc`,virtualId:`likec4:plugin/rpc.js`,async load(e){return
|
|
583
|
+
`,`code`),st={id:`likec4:rpc`,virtualId:`likec4:plugin/rpc.js`,async load(e){return L(`rpc`),{code:ot(e),moduleType:`js`,moduleSideEffects:!1}}},code=e=>`
|
|
584
584
|
export { IconRenderer } from 'likec4:icons/${e}'
|
|
585
585
|
export {
|
|
586
586
|
$likec4data,
|
|
@@ -590,4 +590,4 @@ export {
|
|
|
590
590
|
useLikeC4View
|
|
591
591
|
} from 'likec4:model/${e}'
|
|
592
592
|
export const projectId = ${hardenJsonStringLiteralForEmbeddedScript(JSON.stringify(e))}
|
|
593
|
-
`,ct={id:`likec4:single-project`,virtualId:`likec4:plugin/single-project.js`,async load({projects:e}){let t=
|
|
593
|
+
`,ct={id:`likec4:single-project`,virtualId:`likec4:plugin/single-project.js`,async load({projects:e}){let t=x(e);return L(`single-project`,t.id),code(t.id)}},lt=[Xe,Ge,Re,Be,Je,nt,He],ut=[...lt,it],dt=[$e,Ze,tt,ct,at,ze,Ve,Ye,rt,Ue,qe,st];function LikeC4VitePlugin({environments:e,appConfig:n,ai:i=`auto`,...a}){let o,s,c=!1,l,u=a.watch??!1,d=[...dt,createAppConfigModule(n)],initAI=async()=>{if(te(i))throw Error(`Invalid AI configuration: true is not allowed, use an object with adapter configuration or false to disable AI`);if(i!==`disabled`)return i===`auto`?await Ce():i};function moduleopts(e){return{rpcEnabled:c,isAIAvailable:!!l,ai:l,assetsDir:s,likec4:o,logger:I,...e}}let projectsChangeDetector=()=>{let e=E(e=>({id:e.id,title:e.title,folder:e.folder.toString(),landingPage:e.config.landingPage})),t;return n=>{let r=e(n);return t??=r,y(t,r)?!1:(t=r,!0)}};return[iconBundlePlugin({environments:e?[e].flat():void 0,workspace:a.workspace??a.languageServices?.workspacePath}),{name:`vite-plugin-likec4`,sharedDuringBuild:!0,applyToEnvironment(t){return!e||e.includes(t.name)},async configResolved(e){let t=c=e.command===`serve`;if(a.languageServices)o=a.languageServices;else{let n=u=t&&(a.watch??!0);o=(await ie(a.workspace??e.root,{manualLayouts:!0,graphviz:a.graphviz??`wasm`,configureLogger:`console`,logLevel:a.logLevel??`warning`,printErrors:a.printErrors??!0,throwIfInvalid:a.throwIfInvalid??!1,watch:n})).languageServices}s=o.workspaceUri.fsPath,c&&(l=await initAI())},resolveId:{filter:{id:/^likec4:/},handler(e){for(let t of ut){let n=t.matches(e);if(n)return t.virtualId(n)}for(let t of d)if(t.id===e)return t.virtualId;return null}},load:{filter:{id:/likec4:plugin/},async handler(e){for(let t of ut){let n=t.matches(e);if(n){let e=o.project(n);return await t.load.call(this,moduleopts({project:e}))}}for(let t of d)if(t.virtualId===e){let e=o.projects();return v(e,1)?await t.load.call(this,moduleopts({projects:e})):null}return null}},async configureServer(e){if(c){if(enablePluginRPC.call(this,moduleopts({server:e})),l){I.info(r.dim(`enabling`)+` `+r.magenta(`AI Chat`));let{enableAIServer:t}=await import(`./enableServer.mjs`);t.call(this,moduleopts({server:e}))}return()=>{let n=e.hot,i=projectsChangeDetector(),reloadModule=async n=>{let r=e.moduleGraph.getModuleById(n);if(!r||r.importers.size===0)return!1;try{return await e.reloadModule(r),!0}catch(e){return I.error(t(e)),!1}},hasErrors=()=>{let[e]=o.getErrors();if(!e)return!1;try{n.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}}}),I.trace(r.dim(`sent LikeC4ValidationError`))}catch(e){I.error(t(e))}return!0},reloadProjects=async()=>{let e=o.projects();i(e)?(I.trace(r.dim(`onProjectsUpdate - change detected`)),await reloadModule($e.virtualId),await reloadModule(qe.virtualId),await reloadModule(Ze.virtualId),e.length>1&&await reloadModule(tt.virtualId)):I.trace(r.dim(`onProjectsUpdate - no change`))};o.projectsManager.onProjectsUpdate(pDebounce(reloadProjects,100)),o.builder.onModelParsed(onModelParsedBatched(async e=>{if(!hasErrors())for(let t of e){I.trace(r.dim(`onModelParsed project`)+` `+r.cyan(t));for(let e of lt)await reloadModule(e.virtualId(t))}}))}}},async buildEnd(){u&&await o.dispose()}}]}function onModelParsedBatched(e){return w(n=>{e(n).catch(e=>{I.error(t(e))})},{reducer:(e,t)=>(e??=new Set,e.add(t),e),triggerAt:`end`,minQuietPeriodMs:130,maxBurstDurationMs:500}).call}export{generateDrawio as a,generateD2 as c,buildDrawioExportOptionsForViews as i,enhanceLayoutWithAI as l,generatePuml as n,generateDrawioMulti as o,generateMermaid as r,Ne as s,LikeC4VitePlugin as t};
|