likec4 1.37.0 → 1.38.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,257 @@
1
+ import{invariant as le,isNonEmptyArray as pe}from"@likec4/core";import{relative as ue}from"node:path";import{k as fe}from"./likec4.B7noVoso.mjs";import{f as ge,g as J,T as he,N as V,i as me,n as U,j as _,u as N,l as we,C as Ie,m as Ne,a as ye,b as ve,c as ke,d as G,e as Le,h as W,L as $e}from"./likec4.enfOs0BB.mjs";import{compareNatural as je}from"@likec4/core/utils";import{u as Se}from"./likec4.BeWJWU7_.mjs";import{RichText as Ce}from"@likec4/core/types";function Re(...t){return Se(Te,t)}function Te(t,e){
2
+ let i={};for(let n of e)n in t&&(i[n]=t[n]);return i}function Ee(t){var e,i;if(t){if("astNode"in t)return xe(t);if(Array.isArray(t))return t.reduce(z,void 0);{const n=t,r=be(n)?Me((i=(e=n?.root)===null||e===void 0?void 0:e.astNode)!==null&&i!==void 0?i:n?.astNode):void 0;return C(n,r)}}else return}function be(t){return typeof t<"u"&&"element"in t&&"text"in t}function Me(t){try{return J(t).uri.toString()}catch{return}}function xe(t){var e,i;const{astNode:n,property:r,index:s}=t??{},a=(e=n?.$cstNode)!==
3
+ null&&e!==void 0?e:n?.$textRegion;if(!(n===void 0||a===void 0)){if(r===void 0)return C(a,O(n));{const o=d=>s!==void 0&&s>-1&&Array.isArray(n[r])?s<d.length?d[s]:void 0:d.reduce(z,void 0);if(!((i=a.assignments)===null||i===void 0)&&i[r]){const d=o(a.assignments[r]);return d&&C(d,O(n))}else if(n.$cstNode){const d=o(ge(n.$cstNode,r));return d&&C(d,O(n))}else return}}}function O(t){var e,i,n,r;return t.$cstNode?(i=(e=J(t))===null||e===void 0?void 0:e.uri)===null||i===void 0?void 0:i.toString():t.$textRegion?
4
+ t.$textRegion.documentURI||((r=(n=new he(t,s=>s.$container?[s.$container]:[]).find(s=>{var a;return(a=s.$textRegion)===null||a===void 0?void 0:a.documentURI}))===null||n===void 0?void 0:n.$textRegion)===null||r===void 0?void 0:r.documentURI):void 0}function C(t,e){var i,n;const r={offset:t.offset,end:(i=t.end)!==null&&i!==void 0?i:t.offset+t.length,length:(n=t.length)!==null&&n!==void 0?n:t.end-t.offset};return t.range&&(r.range=t.range),e??(e=t.fileURI),e&&(r.fileURI=e),r}function z(t,e){var i,
5
+ n;if(t){if(!e)return t&&C(t)}else return e&&C(e);const r=(i=t.end)!==null&&i!==void 0?i:t.offset+t.length,s=(n=e.end)!==null&&n!==void 0?n:e.offset+e.length,a=Math.min(t.offset,e.offset),o=Math.max(r,s),d=o-a,u={offset:a,end:o,length:d};if(t.range&&e.range&&(u.range={start:e.range.start.line<t.range.start.line||e.range.start.line===t.range.start.line&&e.range.start.character<t.range.start.character?e.range.start:t.range.start,end:e.range.end.line>t.range.end.line||e.range.end.line===t.range.end.
6
+ line&&e.range.end.character>t.range.end.character?e.range.end:t.range.end}),t.fileURI||e.fileURI){const p=t.fileURI,g=e.fileURI,f=p&&g&&p!==g?`<unmergable text regions of ${p}, ${g}>`:p??g;u.fileURI=f}return u}class Ue{constructor(e){this.defaultIndentation=" ",this.pendingIndent=!0,this.currentIndents=[],this.recentNonImmediateIndents=[],this.traceData=[],this.lines=[[]],this.length=0,typeof e=="string"?this.defaultIndentation=e:typeof e=="number"&&(this.defaultIndentation="".padStart(e))}get content(){
7
+ return this.lines.map(e=>e.join("")).join("")}get contentLength(){return this.length}get currentLineNumber(){return this.lines.length-1}get currentLineContent(){return this.lines[this.currentLineNumber].join("")}get currentPosition(){return{offset:this.contentLength,line:this.currentLineNumber,character:this.currentLineContent.length}}append(e,i){if(e.length>0){const n=i&&this.currentPosition;this.lines[this.currentLineNumber].push(e),this.length+=e.length,n&&this.indentPendingTraceRegions(n)}}indentPendingTraceRegions(e){
8
+ for(let i=this.traceData.length-1;i>=0;i--){const n=this.traceData[i];n.targetStart&&n.targetStart.offset===e.offset&&(n.targetStart=this.currentPosition)}}increaseIndent(e){this.currentIndents.push(e),e.indentImmediately||this.recentNonImmediateIndents.push(e)}decreaseIndent(){this.currentIndents.pop()}get relevantIndents(){return this.currentIndents.filter(e=>!this.recentNonImmediateIndents.includes(e))}resetCurrentLine(){this.length-=this.lines[this.currentLineNumber].join("").length,this.lines[this.
9
+ currentLineNumber]=[],this.pendingIndent=!0,this.recentNonImmediateIndents.length=0}addNewLine(){this.lines.push([]),this.pendingIndent=!0,this.recentNonImmediateIndents.length=0}pushTraceRegion(e){const i=De(e,this.currentPosition,n=>{var r,s;return(s=(r=this.traceData[this.traceData.length-1])===null||r===void 0?void 0:r.children)===null||s===void 0?void 0:s.push(n)});return this.traceData.push(i),i}popTraceRegion(e){const i=this.traceData.pop();return this.assertTrue(i===e,"Trace region misma\
10
+ tch!"),i}getParentTraceSourceFileURI(){var e;for(let i=this.traceData.length-1;i>-1;i--){const n=(e=this.traceData[i].sourceRegion)===null||e===void 0?void 0:e.fileURI;if(n)return n}}assertTrue(e,i){if(!e)throw new Error(i)}}function De(t,e,i){const n={sourceRegion:t,targetRegion:void 0,children:[],targetStart:e,complete:r=>{var s,a;return n.targetRegion={offset:n.targetStart.offset,end:r.offset,length:r.offset-n.targetStart.offset,range:{start:{line:n.targetStart.line,character:n.targetStart.character},
11
+ end:{line:r.line,character:r.character}}},delete n.targetStart,((s=n.children)===null||s===void 0?void 0:s.length)===0&&delete n.children,!((a=n.targetRegion)===null||a===void 0)&&a.length&&i(n),delete n.complete,n}};return n}function Pe(t,e){const i=new Ue(e),n=i.pushTraceRegion(void 0);B(t,i),i.popTraceRegion(n),n.complete&&n.complete(i.currentPosition);const r=n.children&&n.children.length===1?n.children[0]:void 0,s=r?.targetRegion,a=n.targetRegion;return s&&r.sourceRegion&&s.offset===a.offset&&
12
+ s.length===a.length?{text:i.content,trace:r}:{text:i.content,trace:n}}function B(t,e){typeof t=="string"?_e(t,e):t instanceof A?Oe(t,e):t instanceof h?H(t,e):t instanceof b&&Fe(t,e)}function Y(t,e){return typeof t=="string"?t.length!==0:t instanceof h?t.contents.some(i=>Y(i,e)):t instanceof b?!(t.ifNotEmpty&&e.currentLineContent.length===0):!1}function _e(t,e){t&&(q(e,!1),e.append(t))}function q(t,e){var i;if(t.pendingIndent){let n="";for(const r of t.relevantIndents.filter(s=>s.indentEmptyLines||
13
+ !e))n+=(i=r.indentation)!==null&&i!==void 0?i:t.defaultIndentation;t.append(n,!0),t.pendingIndent=!1}}function H(t,e){let i;const n=Ee(t.tracedSource);n&&(i=e.pushTraceRegion(n));for(const r of t.contents)B(r,e);if(i){e.popTraceRegion(i);const r=e.getParentTraceSourceFileURI();r&&n?.fileURI===r&&delete n.fileURI,i.complete&&i.complete(e.currentPosition)}}function Oe(t,e){var i;if(Y(t,e)){t.indentImmediately&&!e.pendingIndent&&e.append((i=t.indentation)!==null&&i!==void 0?i:e.defaultIndentation,!0);
14
+ try{e.increaseIndent(t),H(t,e)}finally{e.decreaseIndent()}}}function Fe(t,e){t.ifNotEmpty&&!Ae(e.currentLineContent)?e.resetCurrentLine():(q(e,!0),e.append(t.lineDelimiter),e.addNewLine())}function Ae(t){return t.trimStart()!==""}Object.freeze("__\xABSKIP^NEW^LINE^IF^EMPTY\xBB__");const Je=/\S|$/;function Ve(t){const e=t.filter(n=>n.length>0).map(n=>n.search(Je)),i=e.length===0?0:Math.min(...e);return Math.max(0,i)}function $(t,...e){const i=We(t),n=ze(t,e,i);return Ye(n)}function Ge(t,e,i){return(n,...r)=>He(
15
+ t,e,i)($(n,...r))}function We(t){const e=t.join("_").split(V),i=e.length>1&&e[0].trim().length===0,n=i&&e.length>1&&e[e.length-1].trim().length===0;if(e.length===1||e.length!==0&&e[0].trim().length!==0||e.length===2&&e[1].trim().length===0)return{indentation:0,omitFirstLine:i,omitLastLine:n,trimLastLine:e.length!==1&&e[e.length-1].trim().length===0};{let r=i?e.slice(1):e;r=n?r.slice(0,r.length-1):r,r=r.filter(a=>a.length!==0);const s=Ve(r);return{indentation:s,omitFirstLine:i,omitLastLine:n&&(e[e.
16
+ length-1].length<s||!e[e.length-1].startsWith(r[0].substring(0,s)))}}}function ze(t,e,{indentation:i,omitFirstLine:n,omitLastLine:r,trimLastLine:s}){const a=[];t.forEach((u,p)=>{a.push(...u.split(V).map((g,f)=>f===0||g.length<i?g:g.substring(i)).reduce(p===0?(g,f,m)=>m===0?n?[]:[f]:m===1&&g.length===0?[f]:g.concat(D,f):(g,f,m)=>m===0?[f]:g.concat(D,f),[]).filter(g=>!(typeof g=="string"&&g.length===0)).concat(E(e[p])?e[p]:e[p]!==void 0?{content:String(e[p])}:p<e.length?K:[]))});const o=a.length,d=o!==
17
+ 0?a[o-1]:void 0;return(r||s)&&typeof d=="string"&&d.trim().length===0?n&&o!==1&&a[o-2]===D?a.slice(0,o-2):a.slice(0,o-1):a}const D={isNewLine:!0},K={isUndefinedSegment:!0},X=t=>t===D,F=t=>t===K,Be=t=>t.content!==void 0;function Ye(t){return t.reduce((i,n,r)=>F(n)?i:X(n)?{node:r!==0&&(F(t[r-1])||E(t[r-1]))||r>1&&typeof t[r-1]=="string"&&(F(t[r-2])||E(t[r-2]))?i.node.appendNewLineIfNotEmpty():i.node.appendNewLine()}:(()=>{var s;const a=(r===0||X(t[r-1]))&&typeof n=="string"&&n.length!==0?"".padStart(
18
+ n.length-n.trimStart().length):"",o=Be(n)?n.content:n;let d;return{node:i.indented?i.node:a.length!==0?i.node.indent({indentation:a,indentImmediately:!1,indentedChildren:u=>d=u.append(o)}):i.node.append(o),indented:d??((s=i.indented)===null||s===void 0?void 0:s.append(o))}})(),{node:new h}).node}const qe=typeof process>"u"?`
19
+ `:process.platform==="win32"?`\r
20
+ `:`
21
+ `;function E(t){return t instanceof h||t instanceof A||t instanceof b}function j(t,e){return E(t)?Pe(t,e).text:String(t)}class h{constructor(...e){this.contents=[],this.append(...e)}isEmpty(){return this.contents.length===0}trace(e,i,n){if(me(e)){if(this.tracedSource={astNode:e,property:i,index:n},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\
22
+ e is assigned to 'index' in 'CompositeGeneratorNode.trace(...)'.")}else this.tracedSource=e;return this}append(...e){for(const i of e)typeof i=="function"?i(this):i&&this.contents.push(i);return this}appendIf(e,...i){return e?this.append(...i):this}appendNewLine(){return this.append(c)}appendNewLineIf(e){return e?this.append(c):this}appendNewLineIfNotEmpty(){return this.append(Ke)}appendNewLineIfNotEmptyIf(e){return e?this.appendNewLineIfNotEmpty():this}appendTemplate(e,...i){return this.append(
23
+ $(e,...i))}appendTemplateIf(e){return e?(i,...n)=>this.appendTemplate(i,...n):()=>this}indent(e){const{indentedChildren:i,indentation:n,indentEmptyLines:r,indentImmediately:s}=Array.isArray(e)||typeof e=="function"?{indentedChildren:e}:typeof e=="object"?e:{},a=new A(n,s,r);return this.contents.push(a),Array.isArray(i)?a.append(...i):i&&a.append(i),this}appendTraced(e,i,n){return r=>this.append(new h().trace(e,i,n).append(r))}appendTracedIf(e,i,n,r){return e?this.appendTraced(typeof i=="function"?
24
+ i():i,n,r):()=>this}appendTracedTemplate(e,i,n){return(r,...s)=>this.append(Ge(e,i,n)(r,...s))}appendTracedTemplateIf(e,i,n,r){return e?this.appendTracedTemplate(typeof i=="function"?i():i,n,r):()=>this}}function He(t,e,i){return n=>n instanceof h&&n.tracedSource===void 0?n.trace(t,e,i):new h().trace(t,e,i).append(n)}class A extends h{constructor(e,i=!0,n=!1){super(),this.indentImmediately=!0,this.indentEmptyLines=!1,typeof e=="string"?this.indentation=e:typeof e=="number"&&(this.indentation="".
25
+ padStart(e)),this.indentImmediately=i,this.indentEmptyLines=n}}class b{constructor(e,i=!1){this.ifNotEmpty=!1,this.lineDelimiter=e??qe,this.ifNotEmpty=i}}const c=new b,Ke=new b(void 0,!0),Q=t=>t===void 0||typeof t=="string"||E(t)?t:String(t);function y(t,e=Q,i={}){const n=typeof e=="function"?e:Q,{filter:r,prefix:s,suffix:a,separator:o,appendNewLineIfNotEmpty:d,skipNewLineAfterLastItem:u}=typeof e=="object"?e:i,p=typeof s=="function"?s:()=>s,g=typeof a=="function"?a:()=>a;return Xe(t,(f,m,v,l)=>{
26
+ if(r&&!r(m,v,l))return f;const w=n(m,v,l);return w===void 0?f:(f??(f=new h)).append(p(m,v,l)).append(w).append(g(m,v,l)).appendIf(!l,o).appendNewLineIfNotEmptyIf(!f.isEmpty()&&!!d&&(!l||!u))})}function Xe(t,e,i){const n=t[Symbol.iterator]();let r=n.next(),s=0,a=i;for(;!r.done;){const o=n.next();a=e(a,r.value,s,!!o.done),r=o,s++}return a}const Qe=t=>t.charAt(0).toLocaleUpperCase()+t.slice(1),Ze=t=>t.split(".").map(Qe).join(""),et=t=>Ze(t.parent?t.id.slice(t.parent.length+1):t.id),tt=({autoLayout:t})=>{
27
+ switch(t.direction){case"TB":return"down";case"BT":return"up";case"LR":return"right";case"RL":return"left"}},nt=({shape:t})=>{switch(t){case"queue":case"cylinder":case"rectangle":case"person":return t;case"storage":return"stored_data";case"mobile":case"browser":return"rectangle"}};function Z(t){const e=t.$view,{nodes:i,edges:n}=e,r=new Map,s=(o,d)=>{const u=et(o),p=(d?d+".":"")+u;r.set(o.id,p);const g=JSON.stringify(o.title),f=nt(o);return new h().append(u,": {",c).indent({indentedChildren:m=>m.
28
+ append("label: ",g,c).appendIf(f!=="rectangle","shape: ",f,c).appendIf(o.children.length>0,c,y(i.filter(v=>v.parent===o.id),v=>s(v,p))),indentation:2}).append("}",c)},a=o=>new h().append(r.get(o.source)," -> ",r.get(o.target)).append(d=>o.label&&d.append(": ",JSON.stringify(o.label)));return j(new h().append("direction: ",tt(e),c,c).append(y(i.filter(o=>U(o.parent)),o=>s(o),{appendNewLineIfNotEmpty:!0})).appendIf(n.length>0,c,y(n,o=>a(o),{appendNewLineIfNotEmpty:!0})))}const it=t=>t.charAt(0).toLocaleUpperCase()+
29
+ t.slice(1),rt=t=>t.split(".").map(it).join(""),ot=t=>rt(t.parent?t.id.slice(t.parent.length+1):t.id),at=({shape:t})=>{switch(t){case"queue":case"cylinder":return["[(",")]"];case"person":return["[fa:fa-user ","]"];case"storage":return["([","])"];case"mobile":case"browser":case"rectangle":return["[","]"]}};function ee(t){const e=t.$view,{nodes:i,edges:n}=e,r=new Map,s=(o,d)=>{const u=ot(o),p=(d?d+".":"")+u;r.set(o.id,p);const g=o.title.replaceAll(`
30
+ `,"\\n"),f=at(o),m=new h;return o.children.length>0?m.append("subgraph ",p,"[",JSON.stringify(o.title),"]",c).indent({indentedChildren:[y(i.filter(v=>v.parent===o.id),v=>s(v,p),{appendNewLineIfNotEmpty:!0})],indentation:2}).append("end",c):m.append(p,f[0],g,f[1]),m},a=o=>new h().append(r.get(o.source)," -.",o.label?' "'+o.label.replaceAll(`
31
+ `,"\\n")+'" .-':"-","> ",r.get(o.target));return j(new h().appendIf(e.title!==null&&e.title.length>0,"---",c,`title: ${JSON.stringify(e.title)}`,c,"---",c).append("graph ",e.autoLayout.direction,c).indent({indentedChildren:o=>{o.append(y(i.filter(d=>U(d.parent)),d=>s(d),{appendNewLineIfNotEmpty:!0})).appendIf(n.length>0,y(n,d=>a(d),{appendNewLineIfNotEmpty:!0}))},indentation:2}))}const st=t=>t.charAt(0).toLocaleUpperCase()+t.slice(1),P=t=>t.split(".").map(st).join(""),te=t=>P(t.parent?t.id.slice(
32
+ t.parent.length+1):t.id),R=(t,e,i="#3b82f6")=>{switch(t){case"blue":case"primary":return"#3b82f6";case"amber":return"#a35829";case"gray":return"#737373";case"green":return"#428a4f";case"indigo":return"#6366f1";case"slate":case"muted":return"#64748b";case"red":return"#ac4d39";case"sky":case"secondary":return"#0284c7";case null:case void 0:return i;default:return e(t)||t}},dt=({autoLayout:t})=>{switch(t.direction){case"TB":return"top to bottom";case"BT":return console.warn("Bottom to top direction\
33
+ 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"}},ne=({shape:t})=>{switch(t){case"queue":case"rectangle":case"person":return t;case"storage":case"cylinder":return"database";case"mobile":case"browser":return"rectangle"}},T=t=>U(t)?null:JSON.stringify(t).slice(1,-1);function ie(t){const e=t.$view,i=t.$model.specification.customColors??
34
+ {},{nodes:n,edges:r}=e,s=new Map(Object.entries(i)),a=l=>w=>s.get(w)?.elements[l],o=l=>w=>s.get(w)?.relationships[l],d=new Map,u=()=>new h().append('title "',e.title||e.id,'"',c).append(dt(e)," direction",c),p=()=>new h().append("hide stereotype",c).append("skinparam ranksep ","60",c).append("skinparam nodesep ","30",c).append("skinparam {",c).indent({indentedChildren:l=>l.append("arrowFontSize ","10",c).append("defaultTextAlignment ","center",c).append("wrapWidth ","200",c).append("maxMessageSi\
35
+ ze ","100",c).append("shadowing ","false",c),indentation:2}).append("}",c),g=l=>{const w=ne(l),I=P(l.id);return new h().append("skinparam ",w,"<<",I,">>","{",c).indent({indentedChildren:L=>L.append("BackgroundColor ",R(l.color,a("fill")),c).append("FontColor ",s.has(l.color)?R(l.color,a("hiContrast")):"#FFFFFF",c).append("BorderColor ",R(l.color,a("stroke")),c),indentation:2}).append("}",c)},f=l=>{const w=ne(l),I=P(l.id),L=T(l.title)||te(l),k=T(l.technology);d.set(l.id,I);const x=Ce.from(l.description);
36
+ return new h().append(w," ").append('"').append("==",L).appendIf(!!k,"\\n","<size:10>[",k,"]</size>").appendIf(x.nonEmpty,"\\n\\n",T(x.text)).append('"'," <<",I,">> ","as ",I,c)},m=l=>{const w=T(l.title)||te(l),I=P(l.id);return d.set(l.id,I),new h().append('rectangle "',w,'" <<',I,">> as ",I," {",c).indent({indentedChildren:L=>L.append("skinparam ","RectangleBorderColor<<",I,">> ",R(l.color,a("fill")),c).append("skinparam ","RectangleFontColor<<",I,">> ",R(l.color,a("fill")),c).append("skinparam\
37
+ ","RectangleBorderStyle<<",I,">> ","dashed",c,c).append(y(n.filter(k=>k.parent===l.id),k=>k.children.length>0?m(k):f(k))),indentation:2}).append("}",c)},v=l=>{const w=T(l.technology)||"",I=T(l.label)||"",L=R(l.color,o("lineColor"),"#777777"),k=x=>`<color:${x}>`;return new h().append(d.get(l.source)," .[",L,",thickness=2].> ",d.get(l.target)).appendIf(!!(I||w),' : "',k(L)).appendIf(!!I,I,k(L)).appendIf(!!(I&&w),"\\n").appendIf(!!w,k(L),"<size:8>[",w,"]</size>").appendIf(!!(I||w),'"').append(c)};
38
+ return j(new h().append("@startuml",c).append(u(),c).append(p(),c).append(y(n.filter(l=>l.children.length==0),l=>g(l),{appendNewLineIfNotEmpty:!0})).append(y(n.filter(l=>U(l.parent)),l=>l.children.length>0?m(l):f(l),{appendNewLineIfNotEmpty:!0})).appendIf(r.length>0,c,y(r,l=>v(l),{appendNewLineIfNotEmpty:!0})).append("@enduml",c))}function S(t){return{matches:e=>{let{module:i,projectId:n}=e.match(/^likec4:plugin\/(?<projectId>.+)\/(?<module>.+)$/)?.groups??e.match(/^likec4:(?<module>.+)\/(?<projectId>.+)$/)?.
39
+ groups??{};return!i||!n?null:(i.endsWith(".js")&&(i=i.slice(0,-3)),i===t?n:null)},virtualId:e=>_("likec4:plugin",e,t)+".js"}}const ct={"<":"\\u003C",">":"\\u003E","/":"\\u002F","\\":"\\\\","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r"," ":"\\t","\0":"\\0","\u2028":"\\u2028","\u2029":"\\u2029"};function lt(t){return t.replace(/[<>\b\f\n\r\t\0\u2028\u2029\\]/g,e=>ct[e])}function M(t,e){return{id:`likec4:${t}`,virtualId:`likec4:plugin/${t}.js`,async load({likec4:i,logger:n,projects:r,assetsDir:s}){n.
40
+ info(N.dim(`generating likec4:${t}`));const a=r.map(({id:o})=>{const d=lt(JSON.stringify(_(`likec4:${t}`,o)));return` ${JSON.stringify(o)}: () => import(${d})`});return`
41
+ export let ${e}Fn = {
42
+ ${a.join(`,
43
+ `)}
44
+ }
45
+
46
+ export async function ${e}(projectId) {
47
+ const fn = ${e}Fn[projectId]
48
+ if (!fn) {
49
+ throw new Error('Unknown projectId: ' + projectId)
50
+ }
51
+ return await fn()
52
+ }
53
+
54
+ if (import.meta.hot) {
55
+ import.meta.hot.accept(md => {
56
+ if (!import.meta.hot.data.$update) {
57
+ import.meta.hot.data.$update = ${e}Fn
58
+ }
59
+ const update = md.${e}Fn
60
+ if (update) {
61
+ Object.assign(import.meta.hot.data.$update, update)
62
+ } else {
63
+ import.meta.hot.invalidate()
64
+ }
65
+ })
66
+ }
67
+ `}}}function pt(t){const e=new h;return e.appendTemplate`
68
+ /******************************************************************************
69
+ * This file was generated
70
+ * DO NOT EDIT MANUALLY!
71
+ ******************************************************************************/
72
+ /* eslint-disable */
73
+
74
+ export function d2Source(viewId) {
75
+ switch (viewId) {
76
+ `.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(y([...t.views()],n=>$`
77
+ case ${JSON.stringify(n.id)}: {
78
+ return ${JSON.stringify(Z(n))}
79
+ }
80
+ `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
81
+ default: {
82
+ throw new Error('Unknown viewId: ' + viewId)
83
+ }
84
+ `}}).append(c," }",c).appendTemplate`
85
+ }
86
+ `.append(c,c),j(e)}const ut={...S("d2"),async load({likec4:t,project:e,logger:i}){i.info(N.dim(`generating likec4:d2/${e.id}`));const n=await t.computedModel(e.id);return pt(n)}},ft=M("d2","loadD2Sources");function gt(t){const e=new h;return e.appendTemplate`
87
+ /******************************************************************************
88
+ * This file was generated
89
+ * DO NOT EDIT MANUALLY!
90
+ ******************************************************************************/
91
+ /* eslint-disable */
92
+
93
+ export function dotSource(viewId) {
94
+ switch (viewId) {
95
+ `.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(y(Object.keys(t),n=>$`
96
+ case ${JSON.stringify(n)}: {
97
+ return ${JSON.stringify(t[n].dot)}
98
+ }
99
+ `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
100
+ default: {
101
+ throw new Error('Unknown viewId: ' + viewId)
102
+ }
103
+ `}}).append(c," }",c).appendTemplate`
104
+ }
105
+
106
+ export function svgSource(viewId) {
107
+ switch (viewId) {
108
+ `.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(y(Object.keys(t),n=>$`
109
+ case ${JSON.stringify(n)}: {
110
+ return ${JSON.stringify(t[n].svg)}
111
+ }
112
+ `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
113
+ default: {
114
+ throw new Error('Unknown viewId: ' + viewId)
115
+ }
116
+ `}}).append(c," }",c,"}",c,c),j(e)}const ht={...S("dot"),async load({likec4:t,project:e,logger:i}){i.info(N.dim(`generating likec4:dot/${e.id}`));const n=await t.views.viewsAsGraphvizOut(e.id),r=we(n,({id:s,svg:a,dot:o})=>[s,{dot:o,svg:a}]);return gt(r)}},mt=M("dot","loadDotSources");function wt(t){const e=Ie(t.flatMap(r=>r.nodes.map(s=>s.icon)),ve(r=>ke(r)&&!(r.toLowerCase().startsWith("http:")||r.toLowerCase().startsWith("https:"))),ye(),Ne(je)),{imports:i,cases:n}=e.reduce((r,s,a)=>{
117
+ const o=s.startsWith("file:"),d="Icon"+a.toString().padStart(2,"0");if(o)return r.imports.push(`import ${d} from '${s}?inline'`),r.cases.push(` '${s}': () => jsx('img', { src: ${d} })`),r;const[u,p]=s.split(":");return r.imports.push(`import ${d} from 'likec4/icons/${u}/${p}'`),r.cases.push(` '${u}:${p}': ${d}`),r},{imports:[],cases:[]});return`
118
+ import { jsx } from 'react/jsx-runtime'
119
+ ${i.join(`
120
+ `)}
121
+
122
+ const Icons = {
123
+ ${n.join(`,
124
+ `)}
125
+ }
126
+ export function IconRenderer(props) {
127
+ const IconComponent = Icons[props.node.icon ?? '']
128
+ if (!IconComponent) {
129
+ return null
130
+ }
131
+ return jsx(IconComponent, props)
132
+ }
133
+ `}const It={...S("icons"),async load({likec4:t,project:e,logger:i}){i.info(N.dim(`generating likec4:icons/${e.id}`));const n=await t.views.computedViews(e.id);return wt(n)}},Nt={id:"likec4:icons",virtualId:"likec4:plugin/icons.jsx",async load({likec4:t,projects:e,logger:i}){i.info(N.dim("generating likec4:icons"));const{imports:n,cases:r}=e.reduce((s,{id:a},o)=>{const d="Icons"+o.toString().padStart(2,"0"),u=_("likec4:icons",a);return s.imports.push(`import { IconRenderer as ${d} } from ${JSON.stringify(
134
+ u)}`),s.cases.push(` case ${JSON.stringify(a)}: return ${d}`),s},{imports:[],cases:[]});return`
135
+ import { jsx } from 'react/jsx-runtime'
136
+ ${n.join(`
137
+ `)}
138
+
139
+ function getProjectIcons(projectId) {
140
+ switch (projectId) {
141
+ ${r.join(`
142
+ `)}
143
+ default:
144
+ throw new Error('Unknown projectId: ' + projectId)
145
+ }
146
+ }
147
+
148
+ export function ProjectIcons({ projectId, ...props }) {
149
+ const IconComponent = getProjectIcons(projectId)
150
+ return jsx(IconComponent, props)
151
+ }
152
+ `}};function yt(t){const e=new h;return e.appendTemplate`
153
+ /******************************************************************************
154
+ * This file was generated
155
+ * DO NOT EDIT MANUALLY!
156
+ ******************************************************************************/
157
+ /* eslint-disable */
158
+
159
+ export function mmdSource(viewId) {
160
+ switch (viewId) {
161
+ `.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(y([...t.views()],n=>$`
162
+ case ${JSON.stringify(n.id)}: {
163
+ return ${JSON.stringify(ee(n))}
164
+ }
165
+ `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
166
+ default: {
167
+ throw new Error('Unknown viewId: ' + viewId)
168
+ }
169
+ `}}).append(c," }",c).appendTemplate`
170
+ }
171
+
172
+ `.append(c,c),j(e)}const vt={...S("mmd"),async load({likec4:t,project:e,logger:i}){i.info(N.dim(`generating virtual:likec4/mmd/${e.id}`));const n=await t.computedModel(e.id);return yt(n)}},kt=M("mmd","loadMmdSources"),Lt=t=>`
173
+ import { createHooksForModel, atom } from 'likec4/vite-plugin/internal'
174
+
175
+ export const $likec4data = atom(${G.stringify(t.$data)})
176
+
177
+ export const {
178
+ updateModel,
179
+ $likec4model,
180
+ useLikeC4Model,
181
+ useLikeC4Views,
182
+ useLikeC4View
183
+ } = createHooksForModel($likec4data)
184
+
185
+ if (import.meta.hot) {
186
+ import.meta.hot.accept(md => {
187
+ if (!import.meta.hot.data.$update) {
188
+ import.meta.hot.data.$update = updateModel
189
+ }
190
+ const update = md.$likec4data?.get()
191
+ if (update) {
192
+ import.meta.hot.data.$update(update)
193
+ } else {
194
+ import.meta.hot.invalidate()
195
+ }
196
+ })
197
+ }
198
+ `,$t={...S("model"),async load({likec4:t,project:e,logger:i,assetsDir:n}){i.info(N.dim(`generating likec4:model/${e.id}`));const r=await t.layoutedModel(e.id);return Lt(r)}},re=M("model","loadModel"),jt=t=>`
199
+ export const isSingleProject = ${t.length===1};
200
+ export const projects = ${G.stringify(t,null,2)};
201
+ `,oe={id:"likec4:projects",virtualId:"likec4:plugin/projects.js",async load({logger:t,projects:e}){return t.info(N.dim("generating likec4:projects")),jt(Le(e,Re(["id","title"])))}};function St(t){const e=new h;return e.appendTemplate`
202
+ /******************************************************************************
203
+ * This file was generated
204
+ * DO NOT EDIT MANUALLY!
205
+ ******************************************************************************/
206
+ /* eslint-disable */
207
+
208
+ export function pumlSource(viewId) {
209
+ switch (viewId) {
210
+ `.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(y([...t.views()],n=>$`
211
+ case ${JSON.stringify(n.id)}: {
212
+ return ${JSON.stringify(ie(n))}
213
+ }
214
+ `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
215
+ default: {
216
+ throw new Error('Unknown viewId: ' + viewId)
217
+ }
218
+ `}}).append(c," }",c).appendTemplate`
219
+ }
220
+ `.append(c,c),j(e)}const Ct={...S("puml"),async load({likec4:t,project:e,logger:i}){i.info(N.dim(`generating likec4:puml/${e.id}`));const n=await t.computedModel(e.id);return St(n)}},Rt=M("puml","loadPumlSources"),ae=t=>`
221
+ import { jsx as _jsx } from "react/jsx-runtime";
222
+ import { LikeC4ModelProvider as Provider, LikeC4View as GenericView, ReactLikeC4 as GenericReactLikeC4 } from 'likec4/react';
223
+ import { IconRenderer } from 'likec4:icons/${t}'
224
+
225
+ import { useLikeC4Model, useLikeC4Views, useLikeC4View } from 'likec4:model/${t}'
226
+
227
+ export function LikeC4ModelProvider({ children }) {
228
+ const likeC4Model = useLikeC4Model()
229
+ return (_jsx(Provider, { likec4model: likeC4Model, children: children }));
230
+ }
231
+ export function LikeC4View(props) {
232
+ return (_jsx(LikeC4ModelProvider, { children: _jsx(GenericView, { renderIcon: IconRenderer, ...props }) }));
233
+ }
234
+ export function ReactLikeC4(props) {
235
+ return (_jsx(LikeC4ModelProvider, { children: _jsx(GenericReactLikeC4, { renderIcon: IconRenderer, ...props }) }));
236
+ }
237
+
238
+ export {
239
+ useLikeC4Model,
240
+ useLikeC4View,
241
+ useLikeC4Views
242
+ }
243
+ `,Tt={...S("react"),async load({project:t,logger:e}){return e.info(N.dim(`generating likec4:react/${t.id}`)),ae(t.id)}},Et={id:"likec4:react",virtualId:"likec4:plugin/react.js",async load({logger:t,projects:e}){const i=W(e);return t.info(N.dim("generating likec4:react for")+" "+i.id),ae(i.id)}},bt=t=>`
244
+ export { IconRenderer } from 'likec4:icons/${t}'
245
+ export {
246
+ $likec4data,
247
+ $likec4model,
248
+ useLikeC4Model,
249
+ useLikeC4Views,
250
+ useLikeC4View
251
+ } from 'likec4:model/${t}'
252
+ export const projectId = ${JSON.stringify(t)}
253
+ `,Mt={id:"likec4:single-project",virtualId:"likec4:plugin/single-project.js",async load({likec4:t,logger:e,projects:i,assetsDir:n}){const r=W(i);return e.info(N.dim("generating likec4:single-project for")+" "+r.id),bt(r.id)}},se=[$t,It,ut,ht,vt,Ct],de=[...se,Tt],ce=[oe,re,Mt,Et,ft,mt,kt,Rt,Nt];function xt({useOverviewGraph:t=!1,...e}){let i,n,r,s;return{name:"vite-plugin-likec4",async configResolved(a){if(i=a.root,n=a.logger,t===!0){const o=a.resolve.alias.find(d=>d.find==="likec4/previews")?.replacement;
254
+ o?(s=o,n.info(N.dim("likec4/previews alias")+" "+N.dim(s))):n.warn("likec4/previews alias not found")}e.languageServices?r=e.languageServices:r=(await $e.fromWorkspace(e.workspace??a.root,{logger:n,graphviz:e.graphviz??"wasm",printErrors:e.printErrors??!0,throwIfInvalid:e.throwIfInvalid??!1,watch:!0})).languageServices,s=r.workspaceUri.fsPath},resolveId(a){for(const o of de){const d=o.matches(a);if(d)return o.virtualId(d)}for(const o of ce)if(o.id===a)return o.virtualId;return null},async load(a){
255
+ for(const o of de){const d=o.matches(a);if(d){const u=r.project(d);return await o.load({logger:n,likec4:r,project:u,assetsDir:s,useOverviewGraph:t})}}for(const o of ce)if(o.virtualId===a){const d=r.projects();return le(pe(d)),await o.load({logger:n,likec4:r,projects:d,assetsDir:s,useOverviewGraph:t})}return null},configureServer(a){let o=r.projects();const d=async u=>{const p=a.moduleGraph.getModuleById(u);if(p&&p.importers.size>0){n.info(`${N.green("reload")} ${N.dim(p.id??p.url)}`);try{await a.
256
+ reloadModule(p)}catch(g){n.error(g)}}};r.builder.onModelParsed(async()=>{const[u]=r.getErrors();if(u){a.ws.send({type:"error",err:{name:"LikeC4ValidationError",message:`Validation failed
257
+ `+u.message.slice(0,500),stack:"",plugin:"vite-plugin-likec4",loc:{file:ue(i,u.sourceFsPath),line:u.range.start.line+1,column:u.range.start.character+1}}});return}const p=r.projects();fe(p,o)||(o=p,await d(oe.virtualId),await d(re.virtualId));for(const g of o)for(const f of se)await d(f.virtualId(g.id))})}}}export{h as C,xt as L,c as N,ee as a,Z as b,$ as e,ie as g,y as j,j as t};