likec4 1.46.4 → 1.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,330 @@
1
+ import{nonexhaustive as z,invariant as me,isNonEmptyArray as he}from"@likec4/core";import{relative as we}from"node:path";import{t as Ie}from"./likec4.DO_7oUns.mjs";import{t as ve,a as G}from"./likec4.CB2-Uaub.mjs";import{f as ye,g as W,T as Ne,N as B,i as je,e as U,j as _,u as I,t as $e,a as ke,n as Le,b as Se,c as Ce,d as Y,L as Re}from"./likec4.CDVXAxDx.mjs";import{compareNatural as be}from"@likec4/core/utils";import{a as D}from"./likec4.CXTvqtC-.mjs";import{t as Te}from"./likec4.DOUP9ptn.mjs";
2
+ import{RichText as Ee}from"@likec4/core/types";function q(e){if(e==null||e==="")return!0;if(typeof e!="object")return!1;if("length"in e&&typeof e.length=="number")return e.length===0;if("size"in e&&typeof e.size=="number")return e.size===0;for(let t in e)return!1;return Object.getOwnPropertySymbols(e).length===0}function Me(...e){return Te(xe,e)}function xe(e,t){let n={};for(let i of t)i in e&&(n[i]=e[i]);return n}function Pe(e){var t,n;if(e){if("astNode"in e)return _e(e);if(Array.isArray(e))return e.
3
+ reduce(H,void 0);{const i=e,r=Oe(i)?Ue((n=(t=i?.root)===null||t===void 0?void 0:t.astNode)!==null&&n!==void 0?n:i?.astNode):void 0;return C(i,r)}}else return}function Oe(e){return typeof e<"u"&&"element"in e&&"text"in e}function Ue(e){try{return W(e).uri.toString()}catch{return}}function _e(e){var t,n;const{astNode:i,property:r,index:o}=e??{},c=(t=i?.$cstNode)!==null&&t!==void 0?t:i?.$textRegion;if(!(i===void 0||c===void 0)){if(r===void 0)return C(c,F(i));{const a=s=>o!==void 0&&o>-1&&Array.isArray(
4
+ i[r])?o<s.length?s[o]:void 0:s.reduce(H,void 0);if(!((n=c.assignments)===null||n===void 0)&&n[r]){const s=a(c.assignments[r]);return s&&C(s,F(i))}else if(i.$cstNode){const s=a(ye(i.$cstNode,r));return s&&C(s,F(i))}else return}}}function F(e){var t,n,i,r;return e.$cstNode?(n=(t=W(e))===null||t===void 0?void 0:t.uri)===null||n===void 0?void 0:n.toString():e.$textRegion?e.$textRegion.documentURI||((r=(i=new Ne(e,o=>o.$container?[o.$container]:[]).find(o=>{var c;return(c=o.$textRegion)===null||c===void 0?
5
+ void 0:c.documentURI}))===null||i===void 0?void 0:i.$textRegion)===null||r===void 0?void 0:r.documentURI):void 0}function C(e,t){var n,i;const r={offset:e.offset,end:(n=e.end)!==null&&n!==void 0?n:e.offset+e.length,length:(i=e.length)!==null&&i!==void 0?i:e.end-e.offset};return e.range&&(r.range=e.range),t??(t=e.fileURI),t&&(r.fileURI=t),r}function H(e,t){var n,i;if(e){if(!t)return e&&C(e)}else return t&&C(t);const r=(n=e.end)!==null&&n!==void 0?n:e.offset+e.length,o=(i=t.end)!==null&&i!==void 0?
6
+ i:t.offset+t.length,c=Math.min(e.offset,t.offset),a=Math.max(r,o),s=a-c,f={offset:c,end:a,length:s};if(e.range&&t.range&&(f.range={start:t.range.start.line<e.range.start.line||t.range.start.line===e.range.start.line&&t.range.start.character<e.range.start.character?t.range.start:e.range.start,end:t.range.end.line>e.range.end.line||t.range.end.line===e.range.end.line&&t.range.end.character>e.range.end.character?t.range.end:e.range.end}),e.fileURI||t.fileURI){const u=e.fileURI,l=t.fileURI,g=u&&l&&u!==
7
+ l?`<unmergable text regions of ${u}, ${l}>`:u??l;f.fileURI=g}return f}class De{constructor(t){this.defaultIndentation=" ",this.pendingIndent=!0,this.currentIndents=[],this.recentNonImmediateIndents=[],this.traceData=[],this.lines=[[]],this.length=0,typeof t=="string"?this.defaultIndentation=t:typeof t=="number"&&(this.defaultIndentation="".padStart(t))}get content(){return this.lines.map(t=>t.join("")).join("")}get contentLength(){return this.length}get currentLineNumber(){return this.lines.length-
8
+ 1}get currentLineContent(){return this.lines[this.currentLineNumber].join("")}get currentPosition(){return{offset:this.contentLength,line:this.currentLineNumber,character:this.currentLineContent.length}}append(t,n){if(t.length>0){const i=n&&this.currentPosition;this.lines[this.currentLineNumber].push(t),this.length+=t.length,i&&this.indentPendingTraceRegions(i)}}indentPendingTraceRegions(t){for(let n=this.traceData.length-1;n>=0;n--){const i=this.traceData[n];i.targetStart&&i.targetStart.offset===
9
+ t.offset&&(i.targetStart=this.currentPosition)}}increaseIndent(t){this.currentIndents.push(t),t.indentImmediately||this.recentNonImmediateIndents.push(t)}decreaseIndent(){this.currentIndents.pop()}get relevantIndents(){return this.currentIndents.filter(t=>!this.recentNonImmediateIndents.includes(t))}resetCurrentLine(){this.length-=this.lines[this.currentLineNumber].join("").length,this.lines[this.currentLineNumber]=[],this.pendingIndent=!0,this.recentNonImmediateIndents.length=0}addNewLine(){this.
10
+ lines.push([]),this.pendingIndent=!0,this.recentNonImmediateIndents.length=0}pushTraceRegion(t){const n=Fe(t,this.currentPosition,i=>{var r,o;return(o=(r=this.traceData[this.traceData.length-1])===null||r===void 0?void 0:r.children)===null||o===void 0?void 0:o.push(i)});return this.traceData.push(n),n}popTraceRegion(t){const n=this.traceData.pop();return this.assertTrue(n===t,"Trace region mismatch!"),n}getParentTraceSourceFileURI(){var t;for(let n=this.traceData.length-1;n>-1;n--){const i=(t=this.
11
+ traceData[n].sourceRegion)===null||t===void 0?void 0:t.fileURI;if(i)return i}}assertTrue(t,n){if(!t)throw new Error(n)}}function Fe(e,t,n){const i={sourceRegion:e,targetRegion:void 0,children:[],targetStart:t,complete:r=>{var o,c;return i.targetRegion={offset:i.targetStart.offset,end:r.offset,length:r.offset-i.targetStart.offset,range:{start:{line:i.targetStart.line,character:i.targetStart.character},end:{line:r.line,character:r.character}}},delete i.targetStart,((o=i.children)===null||o===void 0?
12
+ void 0:o.length)===0&&delete i.children,!((c=i.targetRegion)===null||c===void 0)&&c.length&&n(i),delete i.complete,i}};return i}function Ae(e,t){const n=new De(t),i=n.pushTraceRegion(void 0);K(e,n),n.popTraceRegion(i),i.complete&&i.complete(n.currentPosition);const r=i.children&&i.children.length===1?i.children[0]:void 0,o=r?.targetRegion,c=i.targetRegion;return o&&r.sourceRegion&&o.offset===c.offset&&o.length===c.length?{text:n.content,trace:r}:{text:n.content,trace:i}}function K(e,t){typeof e==
13
+ "string"?Je(e,t):e instanceof J?Ve(e,t):e instanceof m?Z(e,t):e instanceof E&&ze(e,t)}function X(e,t){return typeof e=="string"?e.length!==0:e instanceof m?e.contents.some(n=>X(n,t)):e instanceof E?!(e.ifNotEmpty&&t.currentLineContent.length===0):!1}function Je(e,t){e&&(Q(t,!1),t.append(e))}function Q(e,t){var n;if(e.pendingIndent){let i="";for(const r of e.relevantIndents.filter(o=>o.indentEmptyLines||!t))i+=(n=r.indentation)!==null&&n!==void 0?n:e.defaultIndentation;e.append(i,!0),e.pendingIndent=
14
+ !1}}function Z(e,t){let n;const i=Pe(e.tracedSource);i&&(n=t.pushTraceRegion(i));for(const r of e.contents)K(r,t);if(n){t.popTraceRegion(n);const r=t.getParentTraceSourceFileURI();r&&i?.fileURI===r&&delete i.fileURI,n.complete&&n.complete(t.currentPosition)}}function Ve(e,t){var n;if(X(e,t)){e.indentImmediately&&!t.pendingIndent&&t.append((n=e.indentation)!==null&&n!==void 0?n:t.defaultIndentation,!0);try{t.increaseIndent(e),Z(e,t)}finally{t.decreaseIndent()}}}function ze(e,t){e.ifNotEmpty&&!Ge(
15
+ t.currentLineContent)?t.resetCurrentLine():(Q(t,!0),t.append(e.lineDelimiter),t.addNewLine())}function Ge(e){return e.trimStart()!==""}Object.freeze("__\xABSKIP^NEW^LINE^IF^EMPTY\xBB__");const We=/\S|$/;function Be(e){const t=e.filter(i=>i.length>0).map(i=>i.search(We)),n=t.length===0?0:Math.min(...t);return Math.max(0,n)}function $(e,...t){const n=qe(e),i=He(e,t,n);return Xe(i)}function Ye(e,t,n){return(i,...r)=>Ze(e,t,n)($(i,...r))}function qe(e){const t=e.join("_").split(B),n=t.length>1&&t[0].
16
+ trim().length===0,i=n&&t.length>1&&t[t.length-1].trim().length===0;if(t.length===1||t.length!==0&&t[0].trim().length!==0||t.length===2&&t[1].trim().length===0)return{indentation:0,omitFirstLine:n,omitLastLine:i,trimLastLine:t.length!==1&&t[t.length-1].trim().length===0};{let r=n?t.slice(1):t;r=i?r.slice(0,r.length-1):r,r=r.filter(c=>c.length!==0);const o=Be(r);return{indentation:o,omitFirstLine:n,omitLastLine:i&&(t[t.length-1].length<o||!t[t.length-1].startsWith(r[0].substring(0,o)))}}}function He(e,t,{
17
+ indentation:n,omitFirstLine:i,omitLastLine:r,trimLastLine:o}){const c=[];e.forEach((f,u)=>{c.push(...f.split(B).map((l,g)=>g===0||l.length<n?l:l.substring(n)).reduce(u===0?(l,g,w)=>w===0?i?[]:[g]:w===1&&l.length===0?[g]:l.concat(x,g):(l,g,w)=>w===0?[g]:l.concat(x,g),[]).filter(l=>!(typeof l=="string"&&l.length===0)).concat(T(t[u])?t[u]:t[u]!==void 0?{content:String(t[u])}:u<t.length?ee:[]))});const a=c.length,s=a!==0?c[a-1]:void 0;return(r||o)&&typeof s=="string"&&s.trim().length===0?i&&a!==1&&c[a-
18
+ 2]===x?c.slice(0,a-2):c.slice(0,a-1):c}const x={isNewLine:!0},ee={isUndefinedSegment:!0},te=e=>e===x,A=e=>e===ee,Ke=e=>e.content!==void 0;function Xe(e){return e.reduce((n,i,r)=>A(i)?n:te(i)?{node:r!==0&&(A(e[r-1])||T(e[r-1]))||r>1&&typeof e[r-1]=="string"&&(A(e[r-2])||T(e[r-2]))?n.node.appendNewLineIfNotEmpty():n.node.appendNewLine()}:(()=>{var o;const c=(r===0||te(e[r-1]))&&typeof i=="string"&&i.length!==0?"".padStart(i.length-i.trimStart().length):"",a=Ke(i)?i.content:i;let s;return{node:n.indented?
19
+ n.node:c.length!==0?n.node.indent({indentation:c,indentImmediately:!1,indentedChildren:f=>s=f.append(a)}):n.node.append(a),indented:s??((o=n.indented)===null||o===void 0?void 0:o.append(a))}})(),{node:new m}).node}const Qe=typeof process>"u"?`
20
+ `:process.platform==="win32"?`\r
21
+ `:`
22
+ `;function T(e){return e instanceof m||e instanceof J||e instanceof E}function k(e,t){return T(e)?Ae(e,t).text:String(e)}class m{constructor(...t){this.contents=[],this.append(...t)}isEmpty(){return this.contents.length===0}trace(t,n,i){if(je(t)){if(this.tracedSource={astNode:t,property:n,index:i},this.tracedSource.property===void 0&&this.tracedSource.index!==void 0&&this.tracedSource.index>-1)throw new Error("Generation support: 'property' argument must not be 'undefined' if a non-negative valu\
23
+ e is assigned to 'index' in 'CompositeGeneratorNode.trace(...)'.")}else this.tracedSource=t;return this}append(...t){for(const n of t)typeof n=="function"?n(this):n&&this.contents.push(n);return this}appendIf(t,...n){return t?this.append(...n):this}appendNewLine(){return this.append(d)}appendNewLineIf(t){return t?this.append(d):this}appendNewLineIfNotEmpty(){return this.append(et)}appendNewLineIfNotEmptyIf(t){return t?this.appendNewLineIfNotEmpty():this}appendTemplate(t,...n){return this.append(
24
+ $(t,...n))}appendTemplateIf(t){return t?(n,...i)=>this.appendTemplate(n,...i):()=>this}indent(t){const{indentedChildren:n,indentation:i,indentEmptyLines:r,indentImmediately:o}=Array.isArray(t)||typeof t=="function"?{indentedChildren:t}:typeof t=="object"?t:{},c=new J(i,o,r);return this.contents.push(c),Array.isArray(n)?c.append(...n):n&&c.append(n),this}appendTraced(t,n,i){return r=>this.append(new m().trace(t,n,i).append(r))}appendTracedIf(t,n,i,r){return t?this.appendTraced(typeof n=="function"?
25
+ n():n,i,r):()=>this}appendTracedTemplate(t,n,i){return(r,...o)=>this.append(Ye(t,n,i)(r,...o))}appendTracedTemplateIf(t,n,i,r){return t?this.appendTracedTemplate(typeof n=="function"?n():n,i,r):()=>this}}function Ze(e,t,n){return i=>i instanceof m&&i.tracedSource===void 0?i.trace(e,t,n):new m().trace(e,t,n).append(i)}class J extends m{constructor(t,n=!0,i=!1){super(),this.indentImmediately=!0,this.indentEmptyLines=!1,typeof t=="string"?this.indentation=t:typeof t=="number"&&(this.indentation="".
26
+ padStart(t)),this.indentImmediately=n,this.indentEmptyLines=i}}class E{constructor(t,n=!1){this.ifNotEmpty=!1,this.lineDelimiter=t??Qe,this.ifNotEmpty=n}}const d=new E,et=new E(void 0,!0),ne=e=>e===void 0||typeof e=="string"||T(e)?e:String(e);function y(e,t=ne,n={}){const i=typeof t=="function"?t:ne,{filter:r,prefix:o,suffix:c,separator:a,appendNewLineIfNotEmpty:s,skipNewLineAfterLastItem:f}=typeof t=="object"?t:n,u=typeof o=="function"?o:(()=>o),l=typeof c=="function"?c:(()=>c);return tt(e,(g,w,p,h)=>{
27
+ if(r&&!r(w,p,h))return g;const v=i(w,p,h);return v===void 0?g:(g??(g=new m)).append(u(w,p,h)).append(v).append(l(w,p,h)).appendIf(!h,a).appendNewLineIfNotEmptyIf(!g.isEmpty()&&!!s&&(!h||!f))})}function tt(e,t,n){const i=e[Symbol.iterator]();let r=i.next(),o=0,c=n;for(;!r.done;){const a=i.next();c=t(c,r.value,o,!!a.done),r=a,o++}return c}const nt=e=>e.charAt(0).toLocaleUpperCase()+e.slice(1),it=e=>e.split(".").map(nt).join(""),rt=e=>it(e.parent?e.id.slice(e.parent.length+1):e.id),ot=({autoLayout:e})=>{
28
+ switch(e.direction){case"TB":return"down";case"BT":return"up";case"LR":return"right";case"RL":return"left"}},at=({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"bucket":case"mobile":case"browser":return"rectangle"}};function ie(e){const t=e.$view,{nodes:n,edges:i}=t,r=new Map,o=(a,s)=>{const f=rt(a),u=(s?s+".":"")+f;r.set(a.id,u);const l=JSON.stringify(a.title),g=at(a);return new m().append(
29
+ f,": {",d).indent({indentedChildren:w=>w.append("label: ",l,d).appendIf(g!=="rectangle","shape: ",g,d).appendIf(a.children.length>0,d,y(n.filter(p=>p.parent===a.id),p=>o(p,u))),indentation:2}).append("}",d)},c=a=>new m().append(r.get(a.source)," -> ",r.get(a.target)).append(s=>a.label&&s.append(": ",JSON.stringify(a.label)));return k(new m().append("direction: ",ot(t),d,d).append(y(n.filter(a=>U(a.parent)),a=>o(a),{appendNewLineIfNotEmpty:!0})).appendIf(i.length>0,d,y(i,a=>c(a),{appendNewLineIfNotEmpty:!0})))}
30
+ const st=e=>e.charAt(0).toLocaleUpperCase()+e.slice(1),dt=e=>e.split(".").map(st).join(""),ct=e=>dt(e.parent?e.id.slice(e.parent.length+1):e.id),V=e=>e.replace(/\\?"/g,"'"),pt=({shape:e,title:t})=>{const 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`@{ \
31
+ shape: rounded, ${n} }`;case"bucket":return`@{ shape: trap-t, ${n} }`;case"rectangle":return`@{ shape: rectangle, ${n} }`;case"document":return`@{ shape: doc, ${n} }`;default:z(e)}};function re(e){const t=e.$view,{nodes:n,edges:i}=t,r=new Map,o=(a,s)=>{const f=ct(a),u=(s?s+".":"")+f;r.set(a.id,u);const l=new m;if(a.children.length>0){const g=V(a.title);l.append("subgraph ",u,'["`',g,'`"]',d).indent({indentedChildren:[y(n.filter(w=>w.parent===a.id),w=>o(w,u),{appendNewLineIfNotEmpty:!0})],indentation:2}).
32
+ append("end",d)}else l.append(u,pt(a));return l},c=a=>new m().append(r.get(a.source)," -.",a.label?' "`'+V(a.label)+'`" .-':"-","> ",r.get(a.target));return k(new m().append("---",d,`title: ${JSON.stringify(V(e.titleOrId))}`,d,"---",d).append("graph ",t.autoLayout.direction,d).indent({indentedChildren:a=>{a.append(y(n.filter(s=>U(s.parent)),s=>o(s),{appendNewLineIfNotEmpty:!0})).appendIf(i.length>0,y(i,s=>c(s),{appendNewLineIfNotEmpty:!0}))},indentation:2}))}const lt=e=>e.charAt(0).toLocaleUpperCase()+
33
+ e.slice(1),P=e=>e.split(/[.-]/).map(lt).join(""),oe=e=>P(e.parent?e.id.slice(e.parent.length+1):e.id),R=(e,t,n="#3b82f6")=>e?t(e)??n:n,ut=({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"}},ae=({shape:e})=>{switch(e){case"\
34
+ queue":case"rectangle":case"person":return e;case"storage":case"cylinder":return"database";case"document":case"mobile":case"bucket":case"browser":return"rectangle";default:z(e)}},O=e=>q(e)?null:JSON.stringify(e).slice(1,-1).replace(/\\"/g,'"');function se(e){const t=e.$view,n=e.$model.$styles.theme.colors,{nodes:i,edges:r}=t,o=p=>h=>h in n?n[h].elements[p]:void 0,c=p=>h=>h in n?n[h].relationships[p]:void 0,a=new Map,s=()=>new m().append('title "',e.titleOrId,'"',d).append(ut(t)," direction",d),f=()=>new m().
35
+ append("hide stereotype",d).append("skinparam ranksep ","60",d).append("skinparam nodesep ","30",d).append("skinparam {",d).indent({indentedChildren:p=>p.append("arrowFontSize ","10",d).append("defaultTextAlignment ","center",d).append("wrapWidth ","200",d).append("maxMessageSize ","100",d).append("shadowing ","false",d),indentation:2}).append("}",d),u=p=>{const h=ae(p),v=P(p.id);return new m().append("skinparam ",h,"<<",v,">>","{",d).indent({indentedChildren:j=>j.append("BackgroundColor ",R(p.color,
36
+ o("fill")),d).append("FontColor ",R(p.color,o("hiContrast"),"#FFFFFF"),d).append("BorderColor ",R(p.color,o("stroke")),d),indentation:2}).append("}",d)},l=p=>{const h=ae(p),v=P(p.id),j=O(p.title)||oe(p),N=O(p.technology);a.set(p.id,v);const S=Ee.from(p.description);return new m().append(h," ").append('"').append("==",j).appendIf(!!N,"\\n<size:10>[",N,"]</size>").appendIf(S.nonEmpty,"\\n\\n",O(S.text)).append('"'," <<",v,">> ","as ",v,d)},g=p=>{const h=O(p.title)||oe(p),v=P(p.id);return a.set(p.id,
37
+ v),new m().append('rectangle "',h,'" <<',v,">> as ",v," {",d).indent({indentedChildren:j=>j.append("skinparam ","RectangleBorderColor<<",v,">> ",R(p.color,o("fill")),d).append("skinparam ","RectangleFontColor<<",v,">> ",R(p.color,o("fill")),d).append("skinparam ","RectangleBorderStyle<<",v,">> ","dashed",d,d).append(y(i.filter(N=>N.parent===p.id),N=>N.children.length>0?g(N):l(N))),indentation:2}).append("}",d)},w=p=>{const h=p.technology||"",v=p.label||h,j=R(p.color,c("line"),"#777777"),N=b=>`<c\
38
+ olor:${j}>${b.replaceAll('"',"'")}`,S=new m().append(a.get(p.source)," .[",j,",thickness=2].> ",a.get(p.target));return(v||h)&&(S.append(" : ",v.split(`
39
+ `).map(b=>q(b)?b:N(b)).join("\\n")),h&&h!==v&&S.append("\\n<size:8>[",N(h),"]</size>")),S.append(d)};return k(new m().append("@startuml",d).append(s(),d).append(f(),d).append(y(i.filter(p=>p.children.length==0),p=>u(p),{appendNewLineIfNotEmpty:!0})).append(y(i.filter(p=>U(p.parent)),p=>p.children.length>0?g(p):l(p),{appendNewLineIfNotEmpty:!0})).appendIf(r.length>0,d,y(r,p=>w(p),{appendNewLineIfNotEmpty:!0})).append("@enduml",d))}function L(e){return{matches:t=>{let{module:n,projectId:i}=t.match(
40
+ /^likec4:plugin\/(?<projectId>.+)\/(?<module>.+)$/)?.groups??t.match(/^likec4:(?<module>.+)\/(?<projectId>.+)$/)?.groups??{};return!n||!i?null:(n.endsWith(".js")&&(n=n.slice(0,-3)),n===e?i:null)},virtualId:t=>_("likec4:plugin",t,e)+".js"}}const ft={"<":"\\u003C",">":"\\u003E","/":"\\u002F","\\":"\\\\","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r"," ":"\\t","\0":"\\0","\u2028":"\\u2028","\u2029":"\\u2029"};function gt(e){return e.replace(/[<>\b\f\n\r\t\0\u2028\u2029\\]/g,t=>ft[t])}function M(e,t){return{
41
+ id:`likec4:${e}`,virtualId:`likec4:plugin/${e}.js`,async load({logger:n,projects:i}){n.info(I.dim(`generating likec4:${e}`));const r=i.map(({id:o})=>{const c=gt(JSON.stringify(_(`likec4:${e}`,o)));return` ${JSON.stringify(o)}: () => import(${c})`});return`
42
+ export let ${t}Fn = {
43
+ ${r.join(`,
44
+ `)}
45
+ }
46
+
47
+ export async function ${t}(projectId) {
48
+ let fn = ${t}Fn[projectId]
49
+ if (!fn) {
50
+ const projects = Object.keys(${t}Fn)
51
+ console.error('Unknown projectId: ' + projectId + ' (available: ' + projectIds + ')')
52
+ if (projects.length === 0) {
53
+ throw new Error('No projects found, invalid state')
54
+ }
55
+ projectId = projects[0]
56
+ console.warn('Falling back to project: ' + projectId)
57
+ fn = ${t}Fn[projectId]
58
+ }
59
+ return await fn()
60
+ }
61
+
62
+ if (import.meta.hot) {
63
+ import.meta.hot.accept(md => {
64
+ if (!import.meta.hot.data.$update) {
65
+ import.meta.hot.data.$update = ${t}Fn
66
+ }
67
+ const update = md.${t}Fn
68
+ if (update) {
69
+ Object.assign(import.meta.hot.data.$update, update)
70
+ } else {
71
+ import.meta.hot.invalidate()
72
+ }
73
+ })
74
+ }
75
+ `}}}function mt(e){const t=new m;return t.appendTemplate`
76
+ /******************************************************************************
77
+ * This file was generated
78
+ * DO NOT EDIT MANUALLY!
79
+ ******************************************************************************/
80
+ /* eslint-disable */
81
+
82
+ export function d2Source(viewId) {
83
+ switch (viewId) {
84
+ `.appendNewLine().indent({indentation:4,indentedChildren(n){n.append(y([...e.views()],i=>$`
85
+ case ${JSON.stringify(i.id)}: {
86
+ return ${JSON.stringify(ie(i))}
87
+ }
88
+ `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
89
+ default: {
90
+ throw new Error('Unknown viewId: ' + viewId)
91
+ }
92
+ `}}).append(d," }",d).appendTemplate`
93
+ }
94
+ `.append(d,d),k(t)}const ht={...L("d2"),async load({likec4:e,project:t,logger:n}){n.info(I.dim(`generating likec4:d2/${t.id}`));const i=await e.computedModel(t.id);return mt(i)}},wt=M("d2","loadD2Sources");function It(e){const t=new m;return t.appendTemplate`
95
+ /******************************************************************************
96
+ * This file was generated
97
+ * DO NOT EDIT MANUALLY!
98
+ ******************************************************************************/
99
+ /* eslint-disable */
100
+
101
+ export function dotSource(viewId) {
102
+ switch (viewId) {
103
+ `.appendNewLine().indent({indentation:4,indentedChildren(n){n.append(y(Object.keys(e),i=>$`
104
+ case ${JSON.stringify(i)}: {
105
+ return ${JSON.stringify(e[i].dot)}
106
+ }
107
+ `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
108
+ default: {
109
+ throw new Error('Unknown viewId: ' + viewId)
110
+ }
111
+ `}}).append(d," }",d).appendTemplate`
112
+ }
113
+
114
+ export function svgSource(viewId) {
115
+ switch (viewId) {
116
+ `.appendNewLine().indent({indentation:4,indentedChildren(n){n.append(y(Object.keys(e),i=>$`
117
+ case ${JSON.stringify(i)}: {
118
+ return ${JSON.stringify(e[i].svg)}
119
+ }
120
+ `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
121
+ default: {
122
+ throw new Error('Unknown viewId: ' + viewId)
123
+ }
124
+ `}}).append(d," }",d,"}",d,d),k(t)}const vt={...L("dot"),async load({likec4:e,project:t,logger:n}){n.info(I.dim(`generating likec4:dot/${t.id}`));const i=await e.views.viewsAsGraphvizOut(t.id),r=$e(i,({id:o,svg:c,dot:a})=>[o,{dot:a,svg:c}]);return It(r)}},yt=M("dot","loadDotSources");function Nt(e){const t=ve(e.flatMap(r=>r.nodes.map(o=>o.icon)),Se(r=>Ce(r)&&!(r.toLowerCase().startsWith("http:")||r.toLowerCase().startsWith("https:"))),Le(),ke(be)),{imports:n,cases:i}=t.reduce((r,o,c)=>{
125
+ const a=o.startsWith("file:"),s="Icon"+c.toString().padStart(2,"0");if(a)return r.imports.push(`import ${s} from '${o}?inline'`),r.cases.push(` '${o}': () => jsx('img', { src: ${s} })`),r;const[f,u]=o.split(":");return r.imports.push(`import ${s} from 'likec4/icons/${f}/${u}'`),r.cases.push(` '${f}:${u}': ${s}`),r},{imports:[],cases:[]});return`
126
+ import { jsx } from 'react/jsx-runtime'
127
+ ${n.join(`
128
+ `)}
129
+
130
+ const Icons = {
131
+ ${i.join(`,
132
+ `)}
133
+ }
134
+ export function IconRenderer(props) {
135
+ const IconComponent = Icons[props.node.icon ?? '']
136
+ if (!IconComponent) {
137
+ return null
138
+ }
139
+ return jsx(IconComponent, props)
140
+ }
141
+
142
+ if (import.meta.hot) {
143
+ import.meta.hot.accept()
144
+ }
145
+ `}const jt={...L("icons"),async load({likec4:e,project:t,logger:n}){n.info(I.dim(`generating likec4:icons/${t.id}`));const i=await e.views.computedViews(t.id);return Nt(i)}},$t={id:"likec4:icons",virtualId:"likec4:plugin/icons.jsx",async load({projects:e,logger:t}){t.info(I.dim("generating likec4:icons"));const{imports:n,cases:i}=e.reduce((r,{id:o},c)=>{const a="Icons"+c.toString().padStart(2,"0"),s=_("likec4:icons",o);return r.imports.push(`import { IconRenderer as ${a} } from ${JSON.stringify(
146
+ s)}`),r.cases.push(` case ${JSON.stringify(o)}: return ${a}`),r},{imports:[],cases:[]});return`
147
+ import { jsx } from 'react/jsx-runtime'
148
+ ${n.join(`
149
+ `)}
150
+
151
+ function getProjectIcons(projectId) {
152
+ switch (projectId) {
153
+ ${i.join(`
154
+ `)}
155
+ default:
156
+ throw new Error('Unknown projectId: ' + projectId)
157
+ }
158
+ }
159
+
160
+ export function ProjectIcons({ projectId, ...props }) {
161
+ const IconComponent = getProjectIcons(projectId)
162
+ return jsx(IconComponent, props)
163
+ }
164
+ if (import.meta.hot) {
165
+ import.meta.hot.accept()
166
+ }
167
+ `}};function kt(e){const t=new m;return t.appendTemplate`
168
+ /******************************************************************************
169
+ * This file was generated
170
+ * DO NOT EDIT MANUALLY!
171
+ ******************************************************************************/
172
+ /* eslint-disable */
173
+
174
+ export function mmdSource(viewId) {
175
+ switch (viewId) {
176
+ `.appendNewLine().indent({indentation:4,indentedChildren(n){n.append(y([...e.views()],i=>$`
177
+ case ${JSON.stringify(i.id)}: {
178
+ return ${JSON.stringify(re(i))}
179
+ }
180
+ `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
181
+ default: {
182
+ throw new Error('Unknown viewId: ' + viewId)
183
+ }
184
+ `}}).append(d," }",d).appendTemplate`
185
+ }
186
+
187
+ `.append(d,d),k(t)}const Lt={...L("mmd"),async load({likec4:e,project:t,logger:n}){n.info(I.dim(`generating virtual:likec4/mmd/${t.id}`));const i=await e.computedModel(t.id);return kt(i)}},St=M("mmd","loadMmdSources"),Ct=e=>`
188
+ import { createHooksForModel, atom } from 'likec4/vite-plugin/internal'
189
+
190
+ export const $likec4data = atom(${D.stringify(e.$data)})
191
+
192
+ export const {
193
+ updateModel,
194
+ $likec4model,
195
+ useLikeC4Model,
196
+ useLikeC4Views,
197
+ useLikeC4View
198
+ } = createHooksForModel($likec4data)
199
+
200
+ if (import.meta.hot) {
201
+ import.meta.hot.accept(md => {
202
+ if (!import.meta.hot.data.$update) {
203
+ import.meta.hot.data.$update = updateModel
204
+ }
205
+ const update = md.$likec4data?.get()
206
+ if (update) {
207
+ import.meta.hot.data.$update(update)
208
+ } else {
209
+ import.meta.hot.invalidate()
210
+ }
211
+ })
212
+ }
213
+ `,Rt={...L("model"),async load({likec4:e,project:t,logger:n}){n.info(I.dim(`generating likec4:model/${t.id}`));const i=await e.layoutedModel(t.id);return Ct(i)}},de=M("model","loadModel"),bt=e=>`
214
+ import { atom, useStore } from 'likec4/vite-plugin/internal'
215
+
216
+ export const isSingleProject = ${e.length===1};
217
+ export const projects = ${D.stringify(e,null,2)};
218
+
219
+ export const $projects = atom([...projects])
220
+
221
+ export function useLikeC4Projects() {
222
+ return useStore($projects)
223
+ }
224
+
225
+ if (import.meta.hot) {
226
+ import.meta.hot.accept(md => {
227
+ if (!import.meta.hot.data.$projects) {
228
+ import.meta.hot.data.$projects = $projects
229
+ }
230
+ if (!import.meta.hot.data.projects) {
231
+ import.meta.hot.data.projects = projects
232
+ }
233
+ const update = md.projects
234
+ if (update) {
235
+ import.meta.hot.data.projects.length = 0
236
+ import.meta.hot.data.projects.push(...update)
237
+ import.meta.hot.data.$projects.set(update)
238
+ } else {
239
+ import.meta.hot.invalidate()
240
+ }
241
+ })
242
+ }
243
+ `,ce={id:"likec4:projects",virtualId:"likec4:plugin/projects.js",async load({logger:e,projects:t}){return e.info(I.dim("generating likec4:projects")),bt(G(t,Me(["id","title"])))}},Tt=e=>`
244
+ import { atom, useStore } from 'likec4/vite-plugin/internal'
245
+
246
+ export const $viewdata = atom(${D.stringify(e)})
247
+
248
+ export function useLikeC4ProjectsOverview() {
249
+ return useStore($viewdata)
250
+ }
251
+
252
+ if (import.meta.hot) {
253
+ import.meta.hot.accept(md => {
254
+ if (!import.meta.hot.data.$viewdata) {
255
+ import.meta.hot.data.$viewdata = $viewdata
256
+ }
257
+ const update = md.$viewdata?.get()
258
+ if (update) {
259
+ import.meta.hot.data.$viewdata.set(update)
260
+ } else {
261
+ import.meta.hot.invalidate()
262
+ }
263
+ })
264
+ }
265
+ `,Et=()=>`
266
+ export function useLikeC4ProjectsOverview() {
267
+ throw new Error('No projects overview available for this workspace: single project mode is enabled')
268
+ }
269
+ `,pe={id:"likec4:projects-overview",virtualId:"likec4:plugin/projects-overview.js",async load({logger:e,projects:t,likec4:n}){if(t.length<2)return Et();e.info(I.dim("generating likec4:projects-overview"));const i=await n.projectsOverview();return Tt(i)}};function Mt(e){const t=new m;return t.appendTemplate`
270
+ /******************************************************************************
271
+ * This file was generated
272
+ * DO NOT EDIT MANUALLY!
273
+ ******************************************************************************/
274
+ /* eslint-disable */
275
+
276
+ export function pumlSource(viewId) {
277
+ switch (viewId) {
278
+ `.appendNewLine().indent({indentation:4,indentedChildren(n){n.append(y([...e.views()],i=>$`
279
+ case ${JSON.stringify(i.id)}: {
280
+ return ${JSON.stringify(se(i))}
281
+ }
282
+ `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
283
+ default: {
284
+ throw new Error('Unknown viewId: ' + viewId)
285
+ }
286
+ `}}).append(d," }",d).appendTemplate`
287
+ }
288
+ `.append(d,d),k(t)}const xt={...L("puml"),async load({likec4:e,project:t,logger:n}){n.info(I.dim(`generating likec4:puml/${t.id}`));const i=await e.computedModel(t.id);return Mt(i)}},Pt=M("puml","loadPumlSources"),le=e=>`
289
+ import { jsx as _jsx } from "react/jsx-runtime";
290
+ import { LikeC4ModelProvider as Provider, LikeC4View as GenericView, ReactLikeC4 as GenericReactLikeC4 } from 'likec4/react';
291
+ import { IconRenderer } from 'likec4:icons/${e}'
292
+
293
+ import { useLikeC4Model, useLikeC4Views, useLikeC4View } from 'likec4:model/${e}'
294
+
295
+ export function LikeC4ModelProvider({ children }) {
296
+ const likeC4Model = useLikeC4Model()
297
+ return (_jsx(Provider, { likec4model: likeC4Model, children: children }));
298
+ }
299
+ export function LikeC4View(props) {
300
+ return (_jsx(LikeC4ModelProvider, { children: _jsx(GenericView, { renderIcon: IconRenderer, ...props }) }));
301
+ }
302
+ export function ReactLikeC4(props) {
303
+ return (_jsx(LikeC4ModelProvider, { children: _jsx(GenericReactLikeC4, { renderIcon: IconRenderer, ...props }) }));
304
+ }
305
+
306
+ export {
307
+ useLikeC4Model,
308
+ useLikeC4View,
309
+ useLikeC4Views
310
+ }
311
+ `,Ot={...L("react"),async load({project:e,logger:t}){return t.info(I.dim(`generating likec4:react/${e.id}`)),le(e.id)}},Ut={id:"likec4:react",virtualId:"likec4:plugin/react.js",async load({logger:e,projects:t}){const n=Y(t);return e.info(I.dim("generating likec4:react for")+" "+n.id),le(n.id)}},_t=e=>`
312
+ export { IconRenderer } from 'likec4:icons/${e}'
313
+ export {
314
+ $likec4data,
315
+ $likec4model,
316
+ useLikeC4Model,
317
+ useLikeC4Views,
318
+ useLikeC4View
319
+ } from 'likec4:model/${e}'
320
+ export const projectId = ${JSON.stringify(e)}
321
+ `,Dt={id:"likec4:single-project",virtualId:"likec4:plugin/single-project.js",async load({logger:e,projects:t}){const n=Y(t);return e.info(I.dim("generating likec4:single-project for")+" "+n.id),_t(n.id)}},ue=[Rt,jt,ht,vt,Lt,xt],fe=[...ue,Ot],ge=[ce,de,pe,Dt,Ut,wt,yt,St,Pt,$t];function Ft({useOverviewGraph:e=!1,...t}){let n,i,r,o,c=t.watch??!1;return{name:"vite-plugin-likec4",async configResolved(a){if(n=a.root,i=a.logger,e===!0){const s=a.resolve.alias.find(f=>f.find==="likec4/previews")?.replacement;
322
+ s?(o=s,i.info(I.dim("likec4/previews alias")+" "+I.dim(o))):i.warn("likec4/previews alias not found")}if(t.languageServices)r=t.languageServices;else{const s=c=t.watch??a.mode==="development";r=(await Re.fromWorkspace(t.workspace??a.root,{logger:i,graphviz:t.graphviz??"wasm",printErrors:t.printErrors??!0,throwIfInvalid:t.throwIfInvalid??!1,watch:s})).languageServices}o=r.workspaceUri.fsPath},resolveId(a){for(const s of fe){const f=s.matches(a);if(f)return s.virtualId(f)}for(const s of ge)if(s.id===
323
+ a)return s.virtualId;return null},async load(a){for(const s of fe){const f=s.matches(a);if(f){const u=r.project(f);return await s.load({logger:i,likec4:r,project:u,assetsDir:o,useOverviewGraph:e})}}for(const s of ge)if(s.virtualId===a){const f=r.projects();return me(he(f)),await s.load({logger:i,likec4:r,projects:f,assetsDir:o,useOverviewGraph:e})}return null},configureServer(a){const s=()=>G(r.projects(),l=>({id:l.id,title:l.title,folder:l.folder.fsPath}));let f=s();const u=async l=>{const g=a.
324
+ moduleGraph.getModuleById(l);if(g&&g.importers.size>0)try{await a.reloadModule(g)}catch(w){i.error(w)}};r.builder.onModelParsed(async()=>{const[l]=r.getErrors();if(l){a.ws.send({type:"error",err:{name:"LikeC4ValidationError",message:`Validation failed
325
+ `+l.message.slice(0,500),stack:"",plugin:"vite-plugin-likec4",loc:{file:we(n,l.sourceFsPath),line:l.range.start.line+1,column:l.range.start.character+1}}});return}const g=s();if(!Ie(g,f)){f=g,await u(ce.virtualId),await u(de.virtualId);return}await u(pe.virtualId);for(const w of f)for(const p of ue)await u(p.virtualId(w.id))}),At.call(this,{logger:i,likec4:r,server:a,reloadModule:u})},async buildEnd(){c&&await r.dispose()}}}function At({logger:e,likec4:t,server:n}){n.ws.on("likec4:view:onChange",
326
+ async function(i){try{e.info([I.green("view:onChange"),I.dim("project")+":",i.projectId,I.dim("view")+":",i.viewId,I.dim("change")+":",i.change.op].join(" "));const r=await t.editor.applyChange(i);if(!r.success){e.error(`Failed to apply view change:
327
+ ${r.error}`);const o=r.error.split(`
328
+ `),c=/^\s+at\s+/;let a=o.findIndex(s=>c.test(s));a===-1&&(a=o.length),n.ws.send({type:"error",err:{message:o.slice(0,a).join(`
329
+ `),stack:o.slice(a).join(`
330
+ `),name:"LikeC4ViewChangeError",plugin:"vite-plugin-likec4"}});return}e.info([I.green("view:onChange"),"\u2705"].join(" "))}catch(r){const o=r;e.error("Failed to apply view change",{error:o}),n.ws.send({type:"error",err:{message:o.message,stack:o.stack??"",name:o.name,plugin:"vite-plugin-likec4"}})}})}export{m as C,Ft as L,d as N,re as a,ie as b,$ as e,se as g,y as j,k as t};