likec4 1.32.2 → 1.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__app__/src/const.js +1 -0
- package/__app__/src/fonts.css +1 -1
- package/__app__/src/main.js +728 -470
- package/__app__/src/style.css +1 -1
- package/dist/cli/index.mjs +703 -701
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +2 -2
- package/dist/shared/likec4.BeWJWU7_.mjs +1 -0
- package/dist/shared/{likec4.BaQDJZ_m.d.mts → likec4.C6HFkgux.d.mts} +11437 -1323
- package/dist/shared/likec4.C88_VGwZ.mjs +239 -0
- package/dist/shared/likec4.Dgr2oMAn.mjs +2245 -0
- package/dist/vite-plugin/index.d.mts +1 -1
- package/dist/vite-plugin/index.mjs +2 -2
- package/dist/vite-plugin/internal.d.mts +417 -0
- package/dist/vite-plugin/internal.mjs +9 -0
- package/package.json +39 -33
- package/react/index.d.mts +71 -307
- package/react/index.mjs +30 -30
- package/vite-plugin-modules.d.ts +82 -2
- package/dist/shared/likec4.D6SCXR05.mjs +0 -239
- package/dist/shared/likec4.DDbeRd6k.mjs +0 -2383
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import{relative as de}from"node:path";import{f as ce,g as J,T as le,N as V,i as pe,n as x,j as U,u as N,l as ue,C as fe,m as ge,a as he,b as me,c as we,d as W,e as Ie,p as Ne,h as G,L as ye}from"./likec4.Dgr2oMAn.mjs";import{compareNatural as ve}from"@likec4/core/utils";import{RichText as ke}from"@likec4/core/types";function Le(n){var e,i;if(n){if("astNode"in n)return Se(n);if(Array.isArray(n))return n.reduce(z,void 0);{const t=n,r=$e(t)?je((i=(e=t?.root)===null||e===void 0?void 0:e.astNode)!==null&&
|
|
2
|
+
i!==void 0?i:t?.astNode):void 0;return C(t,r)}}else return}function $e(n){return typeof n<"u"&&"element"in n&&"text"in n}function je(n){try{return J(n).uri.toString()}catch{return}}function Se(n){var e,i;const{astNode:t,property:r,index:a}=n??{},s=(e=t?.$cstNode)!==null&&e!==void 0?e:t?.$textRegion;if(!(t===void 0||s===void 0)){if(r===void 0)return C(s,O(t));{const o=c=>a!==void 0&&a>-1&&Array.isArray(t[r])?a<c.length?c[a]:void 0:c.reduce(z,void 0);if(!((i=s.assignments)===null||i===void 0)&&i[r]){
|
|
3
|
+
const c=o(s.assignments[r]);return c&&C(c,O(t))}else if(t.$cstNode){const c=o(ce(t.$cstNode,r));return c&&C(c,O(t))}else return}}}function O(n){var e,i,t,r;return n.$cstNode?(i=(e=J(n))===null||e===void 0?void 0:e.uri)===null||i===void 0?void 0:i.toString():n.$textRegion?n.$textRegion.documentURI||((r=(t=new le(n,a=>a.$container?[a.$container]:[]).find(a=>{var s;return(s=a.$textRegion)===null||s===void 0?void 0:s.documentURI}))===null||t===void 0?void 0:t.$textRegion)===null||r===void 0?void 0:r.
|
|
4
|
+
documentURI):void 0}function C(n,e){var i,t;const r={offset:n.offset,end:(i=n.end)!==null&&i!==void 0?i:n.offset+n.length,length:(t=n.length)!==null&&t!==void 0?t:n.end-n.offset};return n.range&&(r.range=n.range),e??(e=n.fileURI),e&&(r.fileURI=e),r}function z(n,e){var i,t;if(n){if(!e)return n&&C(n)}else return e&&C(e);const r=(i=n.end)!==null&&i!==void 0?i:n.offset+n.length,a=(t=e.end)!==null&&t!==void 0?t:e.offset+e.length,s=Math.min(n.offset,e.offset),o=Math.max(r,a),c=o-s,p={offset:s,end:o,length:c};
|
|
5
|
+
if(n.range&&e.range&&(p.range={start:e.range.start.line<n.range.start.line||e.range.start.line===n.range.start.line&&e.range.start.character<n.range.start.character?e.range.start:n.range.start,end:e.range.end.line>n.range.end.line||e.range.end.line===n.range.end.line&&e.range.end.character>n.range.end.character?e.range.end:n.range.end}),n.fileURI||e.fileURI){const u=n.fileURI,h=e.fileURI,f=u&&h&&u!==h?`<unmergable text regions of ${u}, ${h}>`:u??h;p.fileURI=f}return p}class Ce{constructor(e){this.
|
|
6
|
+
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(){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(){
|
|
7
|
+
return{offset:this.contentLength,line:this.currentLineNumber,character:this.currentLineContent.length}}append(e,i){if(e.length>0){const t=i&&this.currentPosition;this.lines[this.currentLineNumber].push(e),this.length+=e.length,t&&this.indentPendingTraceRegions(t)}}indentPendingTraceRegions(e){for(let i=this.traceData.length-1;i>=0;i--){const t=this.traceData[i];t.targetStart&&t.targetStart.offset===e.offset&&(t.targetStart=this.currentPosition)}}increaseIndent(e){this.currentIndents.push(e),e.indentImmediately||
|
|
8
|
+
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.currentLineNumber]=[],this.pendingIndent=!0,this.recentNonImmediateIndents.length=0}addNewLine(){this.lines.push([]),this.pendingIndent=!0,this.recentNonImmediateIndents.length=0}pushTraceRegion(e){const i=Re(e,this.
|
|
9
|
+
currentPosition,t=>{var r,a;return(a=(r=this.traceData[this.traceData.length-1])===null||r===void 0?void 0:r.children)===null||a===void 0?void 0:a.push(t)});return this.traceData.push(i),i}popTraceRegion(e){const i=this.traceData.pop();return this.assertTrue(i===e,"Trace region mismatch!"),i}getParentTraceSourceFileURI(){var e;for(let i=this.traceData.length-1;i>-1;i--){const t=(e=this.traceData[i].sourceRegion)===null||e===void 0?void 0:e.fileURI;if(t)return t}}assertTrue(e,i){if(!e)throw new Error(
|
|
10
|
+
i)}}function Re(n,e,i){const t={sourceRegion:n,targetRegion:void 0,children:[],targetStart:e,complete:r=>{var a,s;return t.targetRegion={offset:t.targetStart.offset,end:r.offset,length:r.offset-t.targetStart.offset,range:{start:{line:t.targetStart.line,character:t.targetStart.character},end:{line:r.line,character:r.character}}},delete t.targetStart,((a=t.children)===null||a===void 0?void 0:a.length)===0&&delete t.children,!((s=t.targetRegion)===null||s===void 0)&&s.length&&i(t),delete t.complete,
|
|
11
|
+
t}};return t}function Te(n,e){const i=new Ce(e),t=i.pushTraceRegion(void 0);B(n,i),i.popTraceRegion(t),t.complete&&t.complete(i.currentPosition);const r=t.children&&t.children.length===1?t.children[0]:void 0,a=r?.targetRegion,s=t.targetRegion;return a&&r.sourceRegion&&a.offset===s.offset&&a.length===s.length?{text:i.content,trace:r}:{text:i.content,trace:t}}function B(n,e){typeof n=="string"?Ee(n,e):n instanceof F?Me(n,e):n instanceof g?H(n,e):n instanceof M&&be(n,e)}function Y(n,e){return typeof n==
|
|
12
|
+
"string"?n.length!==0:n instanceof g?n.contents.some(i=>Y(i,e)):n instanceof M?!(n.ifNotEmpty&&e.currentLineContent.length===0):!1}function Ee(n,e){n&&(q(e,!1),e.append(n))}function q(n,e){var i;if(n.pendingIndent){let t="";for(const r of n.relevantIndents.filter(a=>a.indentEmptyLines||!e))t+=(i=r.indentation)!==null&&i!==void 0?i:n.defaultIndentation;n.append(t,!0),n.pendingIndent=!1}}function H(n,e){let i;const t=Le(n.tracedSource);t&&(i=e.pushTraceRegion(t));for(const r of n.contents)B(r,e);if(i){
|
|
13
|
+
e.popTraceRegion(i);const r=e.getParentTraceSourceFileURI();r&&t?.fileURI===r&&delete t.fileURI,i.complete&&i.complete(e.currentPosition)}}function Me(n,e){var i;if(Y(n,e)){n.indentImmediately&&!e.pendingIndent&&e.append((i=n.indentation)!==null&&i!==void 0?i:e.defaultIndentation,!0);try{e.increaseIndent(n),H(n,e)}finally{e.decreaseIndent()}}}function be(n,e){n.ifNotEmpty&&!xe(e.currentLineContent)?e.resetCurrentLine():(q(e,!0),e.append(n.lineDelimiter),e.addNewLine())}function xe(n){return n.trimStart()!==
|
|
14
|
+
""}Object.freeze("__\xABSKIP^NEW^LINE^IF^EMPTY\xBB__");const Ue=/\S|$/;function De(n){const e=n.filter(t=>t.length>0).map(t=>t.search(Ue)),i=e.length===0?0:Math.min(...e);return Math.max(0,i)}function $(n,...e){const i=Pe(n),t=Oe(n,e,i);return Fe(t)}function _e(n,e,i){return(t,...r)=>Ve(n,e,i)($(t,...r))}function Pe(n){const e=n.join("_").split(V),i=e.length>1&&e[0].trim().length===0,t=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===
|
|
15
|
+
2&&e[1].trim().length===0)return{indentation:0,omitFirstLine:i,omitLastLine:t,trimLastLine:e.length!==1&&e[e.length-1].trim().length===0};{let r=i?e.slice(1):e;r=t?r.slice(0,r.length-1):r,r=r.filter(s=>s.length!==0);const a=De(r);return{indentation:a,omitFirstLine:i,omitLastLine:t&&(e[e.length-1].length<a||!e[e.length-1].startsWith(r[0].substring(0,a)))}}}function Oe(n,e,{indentation:i,omitFirstLine:t,omitLastLine:r,trimLastLine:a}){const s=[];n.forEach((p,u)=>{s.push(...p.split(V).map((h,f)=>f===
|
|
16
|
+
0||h.length<i?h:h.substring(i)).reduce(u===0?(h,f,m)=>m===0?t?[]:[f]:m===1&&h.length===0?[f]:h.concat(D,f):(h,f,m)=>m===0?[f]:h.concat(D,f),[]).filter(h=>!(typeof h=="string"&&h.length===0)).concat(E(e[u])?e[u]:e[u]!==void 0?{content:String(e[u])}:u<e.length?K:[]))});const o=s.length,c=o!==0?s[o-1]:void 0;return(r||a)&&typeof c=="string"&&c.trim().length===0?t&&o!==1&&s[o-2]===D?s.slice(0,o-2):s.slice(0,o-1):s}const D={isNewLine:!0},K={isUndefinedSegment:!0},X=n=>n===D,A=n=>n===K,Ae=n=>n.content!==
|
|
17
|
+
void 0;function Fe(n){return n.reduce((i,t,r)=>A(t)?i:X(t)?{node:r!==0&&(A(n[r-1])||E(n[r-1]))||r>1&&typeof n[r-1]=="string"&&(A(n[r-2])||E(n[r-2]))?i.node.appendNewLineIfNotEmpty():i.node.appendNewLine()}:(()=>{var a;const s=(r===0||X(n[r-1]))&&typeof t=="string"&&t.length!==0?"".padStart(t.length-t.trimStart().length):"",o=Ae(t)?t.content:t;let c;return{node:i.indented?i.node:s.length!==0?i.node.indent({indentation:s,indentImmediately:!1,indentedChildren:p=>c=p.append(o)}):i.node.append(o),indented:c??
|
|
18
|
+
((a=i.indented)===null||a===void 0?void 0:a.append(o))}})(),{node:new g}).node}const Je=typeof process>"u"?`
|
|
19
|
+
`:process.platform==="win32"?`\r
|
|
20
|
+
`:`
|
|
21
|
+
`;function E(n){return n instanceof g||n instanceof F||n instanceof M}function j(n,e){return E(n)?Te(n,e).text:String(n)}class g{constructor(...e){this.contents=[],this.append(...e)}isEmpty(){return this.contents.length===0}trace(e,i,t){if(pe(e)){if(this.tracedSource={astNode:e,property:i,index:t},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(d)}appendNewLineIf(e){return e?this.append(d):this}appendNewLineIfNotEmpty(){return this.append(We)}appendNewLineIfNotEmptyIf(e){return e?this.appendNewLineIfNotEmpty():this}appendTemplate(e,...i){return this.append(
|
|
23
|
+
$(e,...i))}appendTemplateIf(e){return e?(i,...t)=>this.appendTemplate(i,...t):()=>this}indent(e){const{indentedChildren:i,indentation:t,indentEmptyLines:r,indentImmediately:a}=Array.isArray(e)||typeof e=="function"?{indentedChildren:e}:typeof e=="object"?e:{},s=new F(t,a,r);return this.contents.push(s),Array.isArray(i)?s.append(...i):i&&s.append(i),this}appendTraced(e,i,t){return r=>this.append(new g().trace(e,i,t).append(r))}appendTracedIf(e,i,t,r){return e?this.appendTraced(typeof i=="function"?
|
|
24
|
+
i():i,t,r):()=>this}appendTracedTemplate(e,i,t){return(r,...a)=>this.append(_e(e,i,t)(r,...a))}appendTracedTemplateIf(e,i,t,r){return e?this.appendTracedTemplate(typeof i=="function"?i():i,t,r):()=>this}}function Ve(n,e,i){return t=>t instanceof g&&t.tracedSource===void 0?t.trace(n,e,i):new g().trace(n,e,i).append(t)}class F extends g{constructor(e,i=!0,t=!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=t}}class M{constructor(e,i=!1){this.ifNotEmpty=!1,this.lineDelimiter=e??Je,this.ifNotEmpty=i}}const d=new M,We=new M(void 0,!0),Q=n=>n===void 0||typeof n=="string"||E(n)?n:String(n);function y(n,e=Q,i={}){const t=typeof e=="function"?e:Q,{filter:r,prefix:a,suffix:s,separator:o,appendNewLineIfNotEmpty:c,skipNewLineAfterLastItem:p}=typeof e=="object"?e:i,u=typeof a=="function"?a:()=>a,h=typeof s=="function"?s:()=>s;return Ge(n,(f,m,v,l)=>{
|
|
26
|
+
if(r&&!r(m,v,l))return f;const w=t(m,v,l);return w===void 0?f:(f??(f=new g)).append(u(m,v,l)).append(w).append(h(m,v,l)).appendIf(!l,o).appendNewLineIfNotEmptyIf(!f.isEmpty()&&!!c&&(!l||!p))})}function Ge(n,e,i){const t=n[Symbol.iterator]();let r=t.next(),a=0,s=i;for(;!r.done;){const o=t.next();s=e(s,r.value,a,!!o.done),r=o,a++}return s}const ze=n=>n.charAt(0).toLocaleUpperCase()+n.slice(1),Be=n=>n.split(".").map(ze).join(""),Ye=n=>Be(n.parent?n.id.slice(n.parent.length+1):n.id),qe=({autoLayout:n})=>{
|
|
27
|
+
switch(n.direction){case"TB":return"down";case"BT":return"up";case"LR":return"right";case"RL":return"left"}},He=({shape:n})=>{switch(n){case"queue":case"cylinder":case"rectangle":case"person":return n;case"storage":return"stored_data";case"mobile":case"browser":return"rectangle"}};function Z(n){const e=n.$view,{nodes:i,edges:t}=e,r=new Map,a=(o,c)=>{const p=Ye(o),u=(c?c+".":"")+p;r.set(o.id,u);const h=JSON.stringify(o.title),f=He(o);return new g().append(p,": {",d).indent({indentedChildren:m=>m.
|
|
28
|
+
append("label: ",h,d).appendIf(f!=="rectangle","shape: ",f,d).appendIf(o.children.length>0,d,y(i.filter(v=>v.parent===o.id),v=>a(v,u))),indentation:2}).append("}",d)},s=o=>new g().append(r.get(o.source)," -> ",r.get(o.target)).append(c=>o.label&&c.append(": ",JSON.stringify(o.label)));return j(new g().append("direction: ",qe(e),d,d).append(y(i.filter(o=>x(o.parent)),o=>a(o),{appendNewLineIfNotEmpty:!0})).appendIf(t.length>0,d,y(t,o=>s(o),{appendNewLineIfNotEmpty:!0})))}const Ke=n=>n.charAt(0).toLocaleUpperCase()+
|
|
29
|
+
n.slice(1),Xe=n=>n.split(".").map(Ke).join(""),Qe=n=>Xe(n.parent?n.id.slice(n.parent.length+1):n.id),Ze=({shape:n})=>{switch(n){case"queue":case"cylinder":return["[(",")]"];case"person":return["[fa:fa-user ","]"];case"storage":return["([","])"];case"mobile":case"browser":case"rectangle":return["[","]"]}};function ee(n){const e=n.$view,{nodes:i,edges:t}=e,r=new Map,a=(o,c)=>{const p=Qe(o),u=(c?c+".":"")+p;r.set(o.id,u);const h=o.title.replaceAll(`
|
|
30
|
+
`,"\\n"),f=Ze(o),m=new g;return o.children.length>0?m.append("subgraph ",u,"[",JSON.stringify(o.title),"]",d).indent({indentedChildren:[y(i.filter(v=>v.parent===o.id),v=>a(v,u),{appendNewLineIfNotEmpty:!0})],indentation:2}).append("end",d):m.append(u,f[0],h,f[1]),m},s=o=>new g().append(r.get(o.source)," -.",o.label?' "'+o.label.replaceAll(`
|
|
31
|
+
`,"\\n")+'" .-':"-","> ",r.get(o.target));return j(new g().appendIf(e.title!==null&&e.title.length>0,"---",d,`title: ${JSON.stringify(e.title)}`,d,"---",d).append("graph ",e.autoLayout.direction,d).indent({indentedChildren:o=>{o.append(y(i.filter(c=>x(c.parent)),c=>a(c),{appendNewLineIfNotEmpty:!0})).appendIf(t.length>0,y(t,c=>s(c),{appendNewLineIfNotEmpty:!0}))},indentation:2}))}const en=n=>n.charAt(0).toLocaleUpperCase()+n.slice(1),_=n=>n.split(".").map(en).join(""),ne=n=>_(n.parent?n.id.slice(
|
|
32
|
+
n.parent.length+1):n.id),R=(n,e,i="#3b82f6")=>{switch(n){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(n)||n}},nn=({autoLayout:n})=>{switch(n.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"}},te=({shape:n})=>{switch(n){case"queue":case"rectangle":case"person":return n;case"storage":case"cylinder":return"database";case"mobile":case"browser":return"rectangle"}},T=n=>x(n)?null:JSON.stringify(n).slice(1,-1);function ie(n){const e=n.$view,i=n.$model.specification.customColors??
|
|
34
|
+
{},{nodes:t,edges:r}=e,a=new Map(Object.entries(i)),s=l=>w=>a.get(w)?.elements[l],o=l=>w=>a.get(w)?.relationships[l],c=new Map,p=()=>new g().append('title "',e.title||e.id,'"',d).append(nn(e)," direction",d),u=()=>new g().append("hide stereotype",d).append("skinparam ranksep ","60",d).append("skinparam nodesep ","30",d).append("skinparam {",d).indent({indentedChildren:l=>l.append("arrowFontSize ","10",d).append("defaultTextAlignment ","center",d).append("wrapWidth ","200",d).append("maxMessageSi\
|
|
35
|
+
ze ","100",d).append("shadowing ","false",d),indentation:2}).append("}",d),h=l=>{const w=te(l),I=_(l.id);return new g().append("skinparam ",w,"<<",I,">>","{",d).indent({indentedChildren:L=>L.append("BackgroundColor ",R(l.color,s("fill")),d).append("FontColor ",a.has(l.color)?R(l.color,s("hiContrast")):"#FFFFFF",d).append("BorderColor ",R(l.color,s("stroke")),d),indentation:2}).append("}",d)},f=l=>{const w=te(l),I=_(l.id),L=T(l.title)||ne(l),k=T(l.technology);c.set(l.id,I);const b=ke.from(l.description);
|
|
36
|
+
return new g().append(w," ").append('"').append("==",L).appendIf(!!k,"\\n","<size:10>[",k,"]</size>").appendIf(b.nonEmpty,"\\n\\n",T(b.text)).append('"'," <<",I,">> ","as ",I,d)},m=l=>{const w=T(l.title)||ne(l),I=_(l.id);return c.set(l.id,I),new g().append('rectangle "',w,'" <<',I,">> as ",I," {",d).indent({indentedChildren:L=>L.append("skinparam ","RectangleBorderColor<<",I,">> ",R(l.color,s("fill")),d).append("skinparam ","RectangleFontColor<<",I,">> ",R(l.color,s("fill")),d).append("skinparam\
|
|
37
|
+
","RectangleBorderStyle<<",I,">> ","dashed",d,d).append(y(t.filter(k=>k.parent===l.id),k=>k.children.length>0?m(k):f(k))),indentation:2}).append("}",d)},v=l=>{const w=T(l.technology)||"",I=T(l.label)||"",L=R(l.color,o("lineColor"),"#777777"),k=b=>`<color:${b}>`;return new g().append(c.get(l.source)," .[",L,",thickness=2].> ",c.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(d)};
|
|
38
|
+
return j(new g().append("@startuml",d).append(p(),d).append(u(),d).append(y(t.filter(l=>l.children.length==0),l=>h(l),{appendNewLineIfNotEmpty:!0})).append(y(t.filter(l=>x(l.parent)),l=>l.children.length>0?m(l):f(l),{appendNewLineIfNotEmpty:!0})).appendIf(r.length>0,d,y(r,l=>v(l),{appendNewLineIfNotEmpty:!0})).append("@enduml",d))}function S(n){return{matches:e=>{let{module:i,projectId:t}=e.match(/^likec4:plugin\/(?<projectId>.+)\/(?<module>.+)$/)?.groups??e.match(/^likec4:(?<module>.+)\/(?<projectId>.+)$/)?.
|
|
39
|
+
groups??{};return!i||!t?null:(i.endsWith(".js")&&(i=i.slice(0,-3)),i===n?t:null)},virtualId:e=>U("likec4:plugin",e,n)+".js"}}function P(n,e){return{id:`likec4:${n}`,virtualId:`likec4:plugin/${n}.js`,async load({likec4:i,logger:t,projects:r,assetsDir:a}){t.info(N.dim(`generating likec4:${n}`));const s=r.map(({id:o})=>{const c=U(`likec4:${n}`,o);return` case ${JSON.stringify(o)}: return await import(${JSON.stringify(c)})`});return`
|
|
40
|
+
export async function ${e}(projectId) {
|
|
41
|
+
switch (projectId) {
|
|
42
|
+
${s.join(`
|
|
43
|
+
`)}
|
|
44
|
+
default: throw new Error('Unknown projectId: ' + projectId)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
`}}}function tn(n){const e=new g;return e.appendTemplate`
|
|
48
|
+
/******************************************************************************
|
|
49
|
+
* This file was generated
|
|
50
|
+
* DO NOT EDIT MANUALLY!
|
|
51
|
+
******************************************************************************/
|
|
52
|
+
/* eslint-disable */
|
|
53
|
+
|
|
54
|
+
export function d2Source(viewId) {
|
|
55
|
+
switch (viewId) {
|
|
56
|
+
`.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(y([...n.views()],t=>$`
|
|
57
|
+
case ${JSON.stringify(t.id)}: {
|
|
58
|
+
return ${JSON.stringify(Z(t))}
|
|
59
|
+
}
|
|
60
|
+
`,{appendNewLineIfNotEmpty:!0})).appendTemplate`
|
|
61
|
+
default: {
|
|
62
|
+
throw new Error('Unknown viewId: ' + viewId)
|
|
63
|
+
}
|
|
64
|
+
`}}).append(d," }",d).appendTemplate`
|
|
65
|
+
}
|
|
66
|
+
`.append(d,d),j(e)}const rn={...S("d2"),async load({likec4:n,projectId:e,logger:i}){i.info(N.dim(`generating likec4:d2/${e}`));const t=await n.computedModel(e);return tn(t)}},on=P("d2","loadD2Sources");function an(n){const e=new g;return e.appendTemplate`
|
|
67
|
+
/******************************************************************************
|
|
68
|
+
* This file was generated
|
|
69
|
+
* DO NOT EDIT MANUALLY!
|
|
70
|
+
******************************************************************************/
|
|
71
|
+
/* eslint-disable */
|
|
72
|
+
|
|
73
|
+
export function dotSource(viewId) {
|
|
74
|
+
switch (viewId) {
|
|
75
|
+
`.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(y(Object.keys(n),t=>$`
|
|
76
|
+
case ${JSON.stringify(t)}: {
|
|
77
|
+
return ${JSON.stringify(n[t].dot)}
|
|
78
|
+
}
|
|
79
|
+
`,{appendNewLineIfNotEmpty:!0})).appendTemplate`
|
|
80
|
+
default: {
|
|
81
|
+
throw new Error('Unknown viewId: ' + viewId)
|
|
82
|
+
}
|
|
83
|
+
`}}).append(d," }",d).appendTemplate`
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function svgSource(viewId) {
|
|
87
|
+
switch (viewId) {
|
|
88
|
+
`.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(y(Object.keys(n),t=>$`
|
|
89
|
+
case ${JSON.stringify(t)}: {
|
|
90
|
+
return ${JSON.stringify(n[t].svg)}
|
|
91
|
+
}
|
|
92
|
+
`,{appendNewLineIfNotEmpty:!0})).appendTemplate`
|
|
93
|
+
default: {
|
|
94
|
+
throw new Error('Unknown viewId: ' + viewId)
|
|
95
|
+
}
|
|
96
|
+
`}}).append(d," }",d,"}",d,d),j(e)}const sn={...S("dot"),async load({likec4:n,projectId:e,logger:i}){i.info(N.dim(`generating likec4:dot/${e}`));const t=await n.views.viewsAsGraphvizOut(e),r=ue(t,({id:a,svg:s,dot:o})=>[a,{dot:o,svg:s}]);return an(r)}},dn=P("dot","loadDotSources");function cn(n){const e=fe(n.flatMap(r=>r.nodes.map(a=>a.icon)),me(r=>we(r)&&!(r.toLowerCase().startsWith("http:")||r.toLowerCase().startsWith("https:"))),he(),ge(ve)),{imports:i,cases:t}=e.reduce((r,a,s)=>{const o=a.
|
|
97
|
+
startsWith("file:"),c="Icon"+s.toString().padStart(2,"0");if(o)return r.imports.push(`import ${c} from '${a}?inline'`),r.cases.push(` '${a}': () => jsx('img', { src: ${c} })`),r;const[p,u]=a.split(":");return r.imports.push(`import ${c} from 'likec4/icons/${p}/${u}'`),r.cases.push(` '${p}:${u}': ${c}`),r},{imports:[],cases:[]});return`
|
|
98
|
+
import { jsx } from 'react/jsx-runtime'
|
|
99
|
+
${i.join(`
|
|
100
|
+
`)}
|
|
101
|
+
|
|
102
|
+
const Icons = {
|
|
103
|
+
${t.join(`,
|
|
104
|
+
`)}
|
|
105
|
+
}
|
|
106
|
+
export function IconRenderer({ node }) {
|
|
107
|
+
const IconComponent = Icons[node.icon ?? '']
|
|
108
|
+
if (!IconComponent) {
|
|
109
|
+
return null
|
|
110
|
+
}
|
|
111
|
+
return jsx(IconComponent, {node})
|
|
112
|
+
}
|
|
113
|
+
`}const ln={...S("icons"),async load({likec4:n,projectId:e,logger:i}){i.info(N.dim(`generating likec4:icons/${e}`));const t=await n.views.computedViews(e);return cn(t)}},pn={id:"likec4:icons",virtualId:"likec4:plugin/icons.jsx",async load({likec4:n,projects:e,logger:i}){i.info(N.dim("generating likec4:icons"));const{imports:t,cases:r}=e.reduce((a,{id:s},o)=>{const c="Icons"+o.toString().padStart(2,"0"),p=U("likec4:icons",s);return a.imports.push(`import { IconRenderer as ${c} } from ${JSON.stringify(
|
|
114
|
+
p)}`),a.cases.push(` case ${JSON.stringify(s)}: return ${c}`),a},{imports:[],cases:[]});return`
|
|
115
|
+
${t.join(`
|
|
116
|
+
`)}
|
|
117
|
+
|
|
118
|
+
export function ProjectIcons(projectId) {
|
|
119
|
+
switch (projectId) {
|
|
120
|
+
${r.join(`
|
|
121
|
+
`)}
|
|
122
|
+
default:
|
|
123
|
+
throw new Error('Unknown projectId: ' + projectId)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
`}};function un(n){const e=new g;return e.appendTemplate`
|
|
127
|
+
/******************************************************************************
|
|
128
|
+
* This file was generated
|
|
129
|
+
* DO NOT EDIT MANUALLY!
|
|
130
|
+
******************************************************************************/
|
|
131
|
+
/* eslint-disable */
|
|
132
|
+
|
|
133
|
+
export function mmdSource(viewId) {
|
|
134
|
+
switch (viewId) {
|
|
135
|
+
`.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(y([...n.views()],t=>$`
|
|
136
|
+
case ${JSON.stringify(t.id)}: {
|
|
137
|
+
return ${JSON.stringify(ee(t))}
|
|
138
|
+
}
|
|
139
|
+
`,{appendNewLineIfNotEmpty:!0})).appendTemplate`
|
|
140
|
+
default: {
|
|
141
|
+
throw new Error('Unknown viewId: ' + viewId)
|
|
142
|
+
}
|
|
143
|
+
`}}).append(d," }",d).appendTemplate`
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
`.append(d,d),j(e)}const fn={...S("mmd"),async load({likec4:n,projectId:e,logger:i}){i.info(N.dim(`generating virtual:likec4/mmd/${e}`));const t=await n.computedModel(e);return un(t)}},gn=P("mmd","loadMmdSources"),hn=n=>`
|
|
147
|
+
import { createHooksForModel, atom } from 'likec4/vite-plugin/internal'
|
|
148
|
+
|
|
149
|
+
export const $likec4data = atom(${W.stringify(n.$data)})
|
|
150
|
+
|
|
151
|
+
export const {
|
|
152
|
+
updateModel,
|
|
153
|
+
$likec4model,
|
|
154
|
+
useLikeC4Model,
|
|
155
|
+
useLikeC4Views,
|
|
156
|
+
useLikeC4View
|
|
157
|
+
}= /* @__PURE__ */ createHooksForModel($likec4data)
|
|
158
|
+
|
|
159
|
+
if (import.meta.hot) {
|
|
160
|
+
import.meta.hot.accept(md => {
|
|
161
|
+
if (!import.meta.hot.data.$update) {
|
|
162
|
+
import.meta.hot.data.$update = updateModel
|
|
163
|
+
}
|
|
164
|
+
const update = md.$likec4data?.value
|
|
165
|
+
if (update) {
|
|
166
|
+
import.meta.hot.data.$update(update)
|
|
167
|
+
} else {
|
|
168
|
+
import.meta.hot.invalidate()
|
|
169
|
+
}
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
`,mn={...S("model"),async load({likec4:n,projectId:e,logger:i,assetsDir:t}){i.info(N.dim(`generating likec4:model/${e}`));const r=await n.layoutedModel(e);return hn(r)}},wn={id:"likec4:model",virtualId:"likec4:plugin/model.js",async load({likec4:n,logger:e,projects:i,assetsDir:t}){return e.info(N.dim("generating likec4:model")),`
|
|
173
|
+
export async function loadModel(projectId) {
|
|
174
|
+
switch (projectId) {
|
|
175
|
+
${i.map(({id:r})=>{const a=U("likec4:model",r);return` case ${JSON.stringify(r)}: return await import(${JSON.stringify(a)})`}).join(`
|
|
176
|
+
`)}
|
|
177
|
+
default: throw new Error('Unknown projectId: ' + projectId)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
`}},In=n=>`
|
|
181
|
+
export const isSingleProject = ${n.length===1};
|
|
182
|
+
export const projects = ${W.stringify(n,null,2)};
|
|
183
|
+
`,Nn={id:"likec4:projects",virtualId:"likec4:plugin/projects.js",async load({likec4:n,logger:e,projects:i,assetsDir:t}){return e.info(N.dim("generating likec4:projects")),In(Ie(i,Ne("id")))}};function yn(n){const e=new g;return e.appendTemplate`
|
|
184
|
+
/******************************************************************************
|
|
185
|
+
* This file was generated
|
|
186
|
+
* DO NOT EDIT MANUALLY!
|
|
187
|
+
******************************************************************************/
|
|
188
|
+
/* eslint-disable */
|
|
189
|
+
|
|
190
|
+
export function pumlSource(viewId) {
|
|
191
|
+
switch (viewId) {
|
|
192
|
+
`.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(y([...n.views()],t=>$`
|
|
193
|
+
case ${JSON.stringify(t.id)}: {
|
|
194
|
+
return ${JSON.stringify(ie(t))}
|
|
195
|
+
}
|
|
196
|
+
`,{appendNewLineIfNotEmpty:!0})).appendTemplate`
|
|
197
|
+
default: {
|
|
198
|
+
throw new Error('Unknown viewId: ' + viewId)
|
|
199
|
+
}
|
|
200
|
+
`}}).append(d," }",d).appendTemplate`
|
|
201
|
+
}
|
|
202
|
+
`.append(d,d),j(e)}const vn={...S("puml"),async load({likec4:n,projectId:e,logger:i}){i.info(N.dim(`generating likec4:puml/${e}`));const t=await n.computedModel(e);return yn(t)}},kn=P("puml","loadPumlSources"),re=n=>`
|
|
203
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
204
|
+
import { LikeC4ModelProvider as Provider, LikeC4View as GenericView, ReactLikeC4 as GenericReactLikeC4 } from 'likec4/react';
|
|
205
|
+
import { IconRenderer } from 'likec4:icons/${n}'
|
|
206
|
+
|
|
207
|
+
import { useLikeC4Model, useLikeC4Views, useLikeC4View } from 'likec4:model/${n}'
|
|
208
|
+
|
|
209
|
+
export function LikeC4ModelProvider({ children }) {
|
|
210
|
+
const likeC4Model = useLikeC4Model()
|
|
211
|
+
return (_jsx(Provider, { likec4model: likeC4Model, children: children }));
|
|
212
|
+
}
|
|
213
|
+
export function LikeC4View(props) {
|
|
214
|
+
return (_jsx(LikeC4ModelProvider, { children: _jsx(GenericView, { renderIcon: IconRenderer, ...props }) }));
|
|
215
|
+
}
|
|
216
|
+
export function ReactLikeC4(props) {
|
|
217
|
+
return (_jsx(LikeC4ModelProvider, { children: _jsx(GenericReactLikeC4, { renderIcon: IconRenderer, ...props }) }));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export {
|
|
221
|
+
useLikeC4Model,
|
|
222
|
+
useLikeC4View,
|
|
223
|
+
useLikeC4Views
|
|
224
|
+
}
|
|
225
|
+
`,Ln={...S("react"),async load({projectId:n,logger:e}){return e.info(N.dim(`generating likec4:react/${n}`)),re(n)}},$n={id:"likec4:react",virtualId:"likec4:plugin/react.js",async load({logger:n,projects:e}){const i=G(e);return n.info(N.dim("generating likec4:react for")+" "+i.id),re(i.id)}},jn=n=>`
|
|
226
|
+
export { IconRenderer } from 'likec4:icons/${n}'
|
|
227
|
+
export {
|
|
228
|
+
$likec4data,
|
|
229
|
+
$likec4model,
|
|
230
|
+
useLikeC4Model,
|
|
231
|
+
useLikeC4Views,
|
|
232
|
+
useLikeC4View
|
|
233
|
+
} from 'likec4:model/${n}'
|
|
234
|
+
export const projectId = ${JSON.stringify(n)}
|
|
235
|
+
`,Sn={id:"likec4:single-project",virtualId:"likec4:plugin/single-project.js",async load({likec4:n,logger:e,projects:i,assetsDir:t}){const r=G(i);return e.info(N.dim("generating likec4:single-project for")+" "+r.id),jn(r.id)}},oe=[mn,ln,rn,sn,fn,vn],ae=[...oe,Ln],se=[Nn,wn,Sn,$n,on,dn,gn,kn,pn],Cn=n=>{const e=n.toLowerCase();return e.endsWith(".c4")||e.endsWith(".likec4")||e.endsWith(".like-c4")};function Rn({useOverviewGraph:n=!1,...e}){let i,t,r,a;return{name:"vite-plugin-likec4",async configResolved(s){
|
|
236
|
+
if(i=s.root,t=s.logger,n===!0){const o=s.resolve.alias.find(c=>c.find==="likec4/previews")?.replacement;o?(a=o,t.info(N.dim("likec4/previews alias")+" "+N.dim(a))):t.warn("likec4/previews alias not found")}e.languageServices?r=e.languageServices:r=(await ye.fromWorkspace(e.workspace??s.root,{logger:t,graphviz:e.graphviz??"wasm",printErrors:e.printErrors??!0,throwIfInvalid:e.throwIfInvalid??!1})).languageServices,a=r.workspaceUri.fsPath},resolveId(s){for(const o of ae){const c=o.matches(s);if(c)return o.
|
|
237
|
+
virtualId(c)}for(const o of se)if(o.id===s)return o.virtualId;return null},async load(s){for(const o of ae){const c=o.matches(s);if(c)return await o.load({logger:t,likec4:r,projectId:c,assetsDir:a,useOverviewGraph:n})}for(const o of se)if(o.virtualId===s){const c=await r.projects();return await o.load({logger:t,likec4:r,projects:c,assetsDir:a,useOverviewGraph:n})}return null},configureServer(s){const o=r.projects().map(({folder:p})=>p.fsPath);for(const p of o)t.info(`${N.dim("watch")} ${p}`);const c=p=>u=>{
|
|
238
|
+
Cn(u)&&r.notifyUpdate({[p]:u})};s.watcher.add(o).on("add",c("changed")).on("change",c("changed")).on("unlink",c("removed")),r.builder.onModelParsed(async()=>{const[p]=r.getErrors();if(p){s.ws.send({type:"error",err:{name:"LikeC4ValidationError",message:`Validation failed
|
|
239
|
+
`+p.message.slice(0,500),stack:"",plugin:"vite-plugin-likec4",loc:{file:de(i,p.sourceFsPath),line:p.range.start.line+1,column:p.range.start.character+1}}});return}for(const u of r.projects())for(const h of oe){const f=s.moduleGraph.getModuleById(h.virtualId(u.id));if(f&&f.importers.size>0){t.info(`${N.green("reload")} ${N.dim(f.id??f.url)}`);try{await s.reloadModule(f)}catch(m){t.error(m)}}}})}}}export{g as C,Rn as L,d as N,ee as a,Z as b,$ as e,ie as g,y as j,j as t};
|