likec4 1.29.1 → 1.30.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/main.js +1 -1
- package/dist/cli/index.mjs +423 -422
- package/dist/index.mjs +1 -1
- package/dist/shared/{likec4.KsxCQmkB.mjs → likec4.bAyyEO3Z.mjs} +36 -36
- package/dist/shared/{likec4.CLg3BMaP.mjs → likec4.wnruN9MH.mjs} +106 -105
- package/dist/vite-plugin/index.mjs +1 -1
- package/package.json +11 -11
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"@likec4/core";export{LikeC4DeploymentModel,LikeC4Model,LikeC4ViewModel}from"@likec4/core/model";export{L as LikeC4}from"./shared/likec4.
|
|
1
|
+
import"@likec4/core";export{LikeC4DeploymentModel,LikeC4Model,LikeC4ViewModel}from"@likec4/core/model";export{L as LikeC4}from"./shared/likec4.wnruN9MH.mjs";import"node:fs";import"node:path";import"node:url";import"tty";import"node:util";import"util";import"path";import"os";import"crypto";import"net";import"url";import"fs";import"child_process";import"@likec4/core/types";import"events";import"buffer";import"@hpcc-js/wasm-graphviz";import"@likec4/core/compute-view";import"@likec4/core/utils";import"node:process";
|
|
2
2
|
import"boxen";import"node:child_process";import"node:events";import"node:fs/promises";import"node:stream/promises";import"node:os";import"fs/promises";
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import{relative as Z}from"node:path";import{f as ee,g as x,T as te,N as U,i as ne,n as _,j as S,u as m,l as ie,C as re,a as oe,b as D,c as
|
|
2
|
-
lement"in t&&"text"in t}function fe(t){try{return x(t).uri.toString()}catch{return}}function ge(t){var e,i;const{astNode:n,property:r,index:
|
|
3
|
-
return d&&v(d,T(n))}else return}}}function T(t){var e,i,n,r;return t.$cstNode?(i=(e=x(t))===null||e===void 0?void 0:e.uri)===null||i===void 0?void 0:i.toString():t.$textRegion?t.$textRegion.documentURI||((r=(n=new te(t,
|
|
4
|
-
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 A(t,e){var i,n;if(t){if(!e)return t&&v(t)}else return e&&v(e);const r=(i=t.end)!==null&&i!==void 0?i:t.offset+t.length,
|
|
5
|
-
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.line&&e.range.end.character>t.range.end.character?e.range.end:t.range.end}),t.fileURI||e.fileURI){const
|
|
1
|
+
import{relative as Z}from"node:path";import{f as ee,g as x,T as te,N as U,i as ne,n as _,j as S,u as m,l as ie,C as re,a as oe,b as D,c as se,t as ae,d as P,m as de,p as ce,e as O,L as le}from"./likec4.wnruN9MH.mjs";function pe(t){var e,i;if(t){if("astNode"in t)return ge(t);if(Array.isArray(t))return t.reduce(A,void 0);{const n=t,r=ue(n)?fe((i=(e=n?.root)===null||e===void 0?void 0:e.astNode)!==null&&i!==void 0?i:n?.astNode):void 0;return v(n,r)}}else return}function ue(t){return typeof t<"u"&&"e\
|
|
2
|
+
lement"in t&&"text"in t}function fe(t){try{return x(t).uri.toString()}catch{return}}function ge(t){var e,i;const{astNode:n,property:r,index:s}=t??{},o=(e=n?.$cstNode)!==null&&e!==void 0?e:n?.$textRegion;if(!(n===void 0||o===void 0)){if(r===void 0)return v(o,T(n));{const a=d=>s!==void 0&&s>-1&&Array.isArray(n[r])?s<d.length?d[s]:void 0:d.reduce(A,void 0);if(!((i=o.assignments)===null||i===void 0)&&i[r]){const d=a(o.assignments[r]);return d&&v(d,T(n))}else if(n.$cstNode){const d=a(ee(n.$cstNode,r));
|
|
3
|
+
return d&&v(d,T(n))}else return}}}function T(t){var e,i,n,r;return t.$cstNode?(i=(e=x(t))===null||e===void 0?void 0:e.uri)===null||i===void 0?void 0:i.toString():t.$textRegion?t.$textRegion.documentURI||((r=(n=new te(t,s=>s.$container?[s.$container]:[]).find(s=>{var o;return(o=s.$textRegion)===null||o===void 0?void 0:o.documentURI}))===null||n===void 0?void 0:n.$textRegion)===null||r===void 0?void 0:r.documentURI):void 0}function v(t,e){var i,n;const r={offset:t.offset,end:(i=t.end)!==null&&i!==
|
|
4
|
+
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 A(t,e){var i,n;if(t){if(!e)return t&&v(t)}else return e&&v(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,o=Math.min(t.offset,e.offset),a=Math.max(r,s),d=a-o,c={offset:o,end:a,length:d};if(t.range&&e.range&&(c.range={start:e.range.start.line<t.range.start.line||e.range.start.
|
|
5
|
+
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.line&&e.range.end.character>t.range.end.character?e.range.end:t.range.end}),t.fileURI||e.fileURI){const u=t.fileURI,f=e.fileURI,p=u&&f&&u!==f?`<unmergable text regions of ${u}, ${f}>`:u??f;c.fileURI=p}return c}class he{constructor(e){this.defaultIndentation=" ",this.pendingIndent=!0,this.currentIndents=[],this.recentNonImmediateIndents=
|
|
6
6
|
[],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(){return{offset:this.contentLength,line:this.currentLineNumber,character:this.currentLineContent.
|
|
7
7
|
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){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(){
|
|
8
|
-
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=me(e,this.currentPosition,n=>{var r,
|
|
9
|
-
r.children)===null||
|
|
10
|
-
var
|
|
11
|
-
complete&&n.complete(i.currentPosition);const r=n.children&&n.children.length===1?n.children[0]:void 0,
|
|
12
|
-
length===0):!1}function we(t,e){t&&(W(e,!1),e.append(t))}function W(t,e){var i;if(t.pendingIndent){let n="";for(const r of t.relevantIndents.filter(
|
|
8
|
+
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=me(e,this.currentPosition,n=>{var r,s;return(s=(r=this.traceData[this.traceData.length-1])===null||r===void 0?void 0:
|
|
9
|
+
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 mismatch!"),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 me(t,e,i){const n={sourceRegion:t,targetRegion:void 0,children:[],targetStart:e,complete:r=>{
|
|
10
|
+
var s,o;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},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,!((o=n.targetRegion)===null||o===void 0)&&o.length&&i(n),delete n.complete,n}};return n}function Ie(t,e){const i=new he(e),n=i.pushTraceRegion(void 0);J(t,i),i.popTraceRegion(n),n.
|
|
11
|
+
complete&&n.complete(i.currentPosition);const r=n.children&&n.children.length===1?n.children[0]:void 0,s=r?.targetRegion,o=n.targetRegion;return s&&r.sourceRegion&&s.offset===o.offset&&s.length===o.length?{text:i.content,trace:r}:{text:i.content,trace:n}}function J(t,e){typeof t=="string"?we(t,e):t instanceof E?Ne(t,e):t instanceof g?G(t,e):t instanceof $&&ve(t,e)}function V(t,e){return typeof t=="string"?t.length!==0:t instanceof g?t.contents.some(i=>V(i,e)):t instanceof $?!(t.ifNotEmpty&&e.currentLineContent.
|
|
12
|
+
length===0):!1}function we(t,e){t&&(W(e,!1),e.append(t))}function W(t,e){var i;if(t.pendingIndent){let n="";for(const r of t.relevantIndents.filter(s=>s.indentEmptyLines||!e))n+=(i=r.indentation)!==null&&i!==void 0?i:t.defaultIndentation;t.append(n,!0),t.pendingIndent=!1}}function G(t,e){let i;const n=pe(t.tracedSource);n&&(i=e.pushTraceRegion(n));for(const r of t.contents)J(r,e);if(i){e.popTraceRegion(i);const r=e.getParentTraceSourceFileURI();r&&n?.fileURI===r&&delete n.fileURI,i.complete&&i.complete(
|
|
13
13
|
e.currentPosition)}}function Ne(t,e){var i;if(V(t,e)){t.indentImmediately&&!e.pendingIndent&&e.append((i=t.indentation)!==null&&i!==void 0?i:e.defaultIndentation,!0);try{e.increaseIndent(t),G(t,e)}finally{e.decreaseIndent()}}}function ve(t,e){t.ifNotEmpty&&!ye(e.currentLineContent)?e.resetCurrentLine():(W(e,!0),e.append(t.lineDelimiter),e.addNewLine())}function ye(t){return t.trimStart()!==""}Object.freeze("__\xABSKIP^NEW^LINE^IF^EMPTY\xBB__");const ke=/\S|$/;function Le(t){const e=t.filter(n=>n.
|
|
14
|
-
length>0).map(n=>n.search(ke)),i=e.length===0?0:Math.min(...e);return Math.max(0,i)}function w(t,...e){const i
|
|
15
|
-
length-1].trim().length===0};{let r=i?e.slice(1):e;r=n?r.slice(0,r.length-1):r,r=r.filter(o=>o.length!==0);const
|
|
16
|
-
(
|
|
17
|
-
1]=="string"&&(C(t[r-2])||L(t[r-2]))?i.node.appendNewLineIfNotEmpty():i.node.appendNewLine()}:(()=>{var
|
|
14
|
+
length>0).map(n=>n.search(ke)),i=e.length===0?0:Math.min(...e);return Math.max(0,i)}function w(t,...e){const i=je(t),n=Se(t,e,i);return Te(n)}function $e(t,e,i){return(n,...r)=>Ee(t,e,i)(w(n,...r))}function je(t){const e=t.join("_").split(U),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.
|
|
15
|
+
length-1].trim().length===0};{let r=i?e.slice(1):e;r=n?r.slice(0,r.length-1):r,r=r.filter(o=>o.length!==0);const s=Le(r);return{indentation:s,omitFirstLine:i,omitLastLine:n&&(e[e.length-1].length<s||!e[e.length-1].startsWith(r[0].substring(0,s)))}}}function Se(t,e,{indentation:i,omitFirstLine:n,omitLastLine:r,trimLastLine:s}){const o=[];t.forEach((c,u)=>{o.push(...c.split(U).map((f,p)=>p===0||f.length<i?f:f.substring(i)).reduce(u===0?(f,p,h)=>h===0?n?[]:[p]:h===1&&f.length===0?[p]:f.concat(R,p):
|
|
16
|
+
(f,p,h)=>h===0?[p]:f.concat(R,p),[]).filter(f=>!(typeof f=="string"&&f.length===0)).concat(L(e[u])?e[u]:e[u]!==void 0?{content:String(e[u])}:u<e.length?F:[]))});const a=o.length,d=a!==0?o[a-1]:void 0;return(r||s)&&typeof d=="string"&&d.trim().length===0?n&&a!==1&&o[a-2]===R?o.slice(0,a-2):o.slice(0,a-1):o}const R={isNewLine:!0},F={isUndefinedSegment:!0},z=t=>t===R,C=t=>t===F,Re=t=>t.content!==void 0;function Te(t){return t.reduce((i,n,r)=>C(n)?i:z(n)?{node:r!==0&&(C(t[r-1])||L(t[r-1]))||r>1&&typeof t[r-
|
|
17
|
+
1]=="string"&&(C(t[r-2])||L(t[r-2]))?i.node.appendNewLineIfNotEmpty():i.node.appendNewLine()}:(()=>{var s;const o=(r===0||z(t[r-1]))&&typeof n=="string"&&n.length!==0?"".padStart(n.length-n.trimStart().length):"",a=Re(n)?n.content:n;let d;return{node:i.indented?i.node:o.length!==0?i.node.indent({indentation:o,indentImmediately:!1,indentedChildren:c=>d=c.append(a)}):i.node.append(a),indented:d??((s=i.indented)===null||s===void 0?void 0:s.append(a))}})(),{node:new g}).node}const Ce=typeof process>
|
|
18
18
|
"u"?`
|
|
19
19
|
`:process.platform==="win32"?`\r
|
|
20
20
|
`:`
|
|
21
|
-
`;function L(t){return t instanceof g||t instanceof E||t instanceof
|
|
21
|
+
`;function L(t){return t instanceof g||t instanceof E||t instanceof $}function y(t,e){return L(t)?Ie(t,e).text:String(t)}class g{constructor(...e){this.contents=[],this.append(...e)}isEmpty(){return this.contents.length===0}trace(e,i,n){if(ne(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
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(l)}appendNewLineIf(e){return e?this.append(l):this}appendNewLineIfNotEmpty(){return this.append(Me)}appendNewLineIfNotEmptyIf(e){return e?this.appendNewLineIfNotEmpty():this}appendTemplate(e,...i){return this.append(
|
|
23
|
-
w(e,...i))}appendTemplateIf(e){return e?(i,...n)=>this.appendTemplate(i,...n):()=>this}indent(e){const{indentedChildren:i,indentation:n,indentEmptyLines:r,indentImmediately:
|
|
24
|
-
i():i,n,r):()=>this}appendTracedTemplate(e,i,n){return(r,...
|
|
25
|
-
padStart(e)),this.indentImmediately=i,this.indentEmptyLines=n}}class
|
|
26
|
-
if(r&&!r(h
|
|
27
|
-
switch(t.direction){case"TB":return"down";case"BT":return"up";case"LR":return"right";case"RL":return"left"}},Pe=({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 Y(t){const{nodes:e,edges:i}=t,n=new Map,r=(o,
|
|
28
|
-
el: ",
|
|
29
|
-
t.slice(1),Ae=t=>t.split(".").map(Oe).join(""),Je=t=>Ae(t.parent?t.id.slice(t.parent.length+1):t.id),Ve=({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 q(t){const{nodes:e,edges:i}=t,n=new Map,r=(o,
|
|
30
|
-
`,"\\n"),
|
|
31
|
-
`,"\\n")+'" .-':"-","> ",n.get(o.target));return y(new g().appendIf(t.title!==null&&t.title.length>0,"---",l,`title: ${JSON.stringify(t.title)}`,l,"---",l).append("graph ",t.autoLayout.direction,l).indent({indentedChildren:o=>{o.append(I(e.filter(
|
|
32
|
-
groups??e.match(/^likec4:(?<module>.+)\/(?<projectId>.+)$/)?.groups??{};return!i||!n?null:(i.endsWith(".js")&&(i=i.slice(0,-3)),i===t?n:null)},virtualId:e=>S("likec4:plugin",e,t)+".js"}}function M(t,e){return{id:`likec4:${t}`,virtualId:`likec4:plugin/${t}.js`,async load({likec4:i,logger:n,projects:r,assetsDir:
|
|
23
|
+
w(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:{},o=new E(n,s,r);return this.contents.push(o),Array.isArray(i)?o.append(...i):i&&o.append(i),this}appendTraced(e,i,n){return r=>this.append(new g().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($e(e,i,n)(r,...s))}appendTracedTemplateIf(e,i,n,r){return e?this.appendTracedTemplate(typeof i=="function"?i():i,n,r):()=>this}}function Ee(t,e,i){return n=>n instanceof g&&n.tracedSource===void 0?n.trace(t,e,i):new g().trace(t,e,i).append(n)}class E extends g{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 ${constructor(e,i=!1){this.ifNotEmpty=!1,this.lineDelimiter=e??Ce,this.ifNotEmpty=i}}const l=new $,Me=new $(void 0,!0),B=t=>t===void 0||typeof t=="string"||L(t)?t:String(t);function I(t,e=B,i={}){const n=typeof e=="function"?e:B,{filter:r,prefix:s,suffix:o,separator:a,appendNewLineIfNotEmpty:d,skipNewLineAfterLastItem:c}=typeof e=="object"?e:i,u=typeof s=="function"?s:()=>s,f=typeof o=="function"?o:()=>o;return be(t,(p,h,j,N)=>{
|
|
26
|
+
if(r&&!r(h,j,N))return p;const b=n(h,j,N);return b===void 0?p:(p??(p=new g)).append(u(h,j,N)).append(b).append(f(h,j,N)).appendIf(!N,a).appendNewLineIfNotEmptyIf(!p.isEmpty()&&!!d&&(!N||!c))})}function be(t,e,i){const n=t[Symbol.iterator]();let r=n.next(),s=0,o=i;for(;!r.done;){const a=n.next();o=e(o,r.value,s,!!a.done),r=a,s++}return o}const xe=t=>t.charAt(0).toLocaleUpperCase()+t.slice(1),Ue=t=>t.split(".").map(xe).join(""),_e=t=>Ue(t.parent?t.id.slice(t.parent.length+1):t.id),De=({autoLayout:t})=>{
|
|
27
|
+
switch(t.direction){case"TB":return"down";case"BT":return"up";case"LR":return"right";case"RL":return"left"}},Pe=({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 Y(t){const{nodes:e,edges:i}=t,n=new Map,r=(o,a)=>{const d=_e(o),c=(a?a+".":"")+d;n.set(o.id,c);const u=JSON.stringify(o.title),f=Pe(o);return new g().append(d,": {",l).indent({indentedChildren:p=>p.append("lab\
|
|
28
|
+
el: ",u,l).appendIf(f!=="rectangle","shape: ",f,l).appendIf(o.children.length>0,l,I(e.filter(h=>h.parent===o.id),h=>r(h,c))),indentation:2}).append("}",l)},s=o=>new g().append(n.get(o.source)," -> ",n.get(o.target)).append(a=>o.label&&a.append(": ",JSON.stringify(o.label)));return y(new g().append("direction: ",De(t),l,l).append(I(e.filter(o=>_(o.parent)),o=>r(o),{appendNewLineIfNotEmpty:!0})).appendIf(i.length>0,l,I(i,o=>s(o),{appendNewLineIfNotEmpty:!0})))}const Oe=t=>t.charAt(0).toLocaleUpperCase()+
|
|
29
|
+
t.slice(1),Ae=t=>t.split(".").map(Oe).join(""),Je=t=>Ae(t.parent?t.id.slice(t.parent.length+1):t.id),Ve=({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 q(t){const{nodes:e,edges:i}=t,n=new Map,r=(o,a)=>{const d=Je(o),c=(a?a+".":"")+d;n.set(o.id,c);const u=o.title.replaceAll(`
|
|
30
|
+
`,"\\n"),f=Ve(o),p=new g;return o.children.length>0?p.append("subgraph ",c,"[",JSON.stringify(o.title),"]",l).indent({indentedChildren:[I(e.filter(h=>h.parent===o.id),h=>r(h,c),{appendNewLineIfNotEmpty:!0})],indentation:2}).append("end",l):p.append(c,f[0],u,f[1]),p},s=o=>new g().append(n.get(o.source)," -.",o.label?' "'+o.label.replaceAll(`
|
|
31
|
+
`,"\\n")+'" .-':"-","> ",n.get(o.target));return y(new g().appendIf(t.title!==null&&t.title.length>0,"---",l,`title: ${JSON.stringify(t.title)}`,l,"---",l).append("graph ",t.autoLayout.direction,l).indent({indentedChildren:o=>{o.append(I(e.filter(a=>_(a.parent)),a=>r(a),{appendNewLineIfNotEmpty:!0})).appendIf(i.length>0,I(i,a=>s(a),{appendNewLineIfNotEmpty:!0}))},indentation:2}))}function k(t){return{matches:e=>{let{module:i,projectId:n}=e.match(/^likec4:plugin\/(?<projectId>.+)\/(?<module>.+)$/)?.
|
|
32
|
+
groups??e.match(/^likec4:(?<module>.+)\/(?<projectId>.+)$/)?.groups??{};return!i||!n?null:(i.endsWith(".js")&&(i=i.slice(0,-3)),i===t?n:null)},virtualId:e=>S("likec4:plugin",e,t)+".js"}}function M(t,e){return{id:`likec4:${t}`,virtualId:`likec4:plugin/${t}.js`,async load({likec4:i,logger:n,projects:r,assetsDir:s}){n.info(m.dim(`generating likec4:${t}`));const o=r.map(({id:a})=>{const d=S(`likec4:${t}`,a);return` case ${JSON.stringify(a)}: return await import(${JSON.stringify(d)})`});return`
|
|
33
33
|
export async function ${e}(projectId) {
|
|
34
34
|
switch (projectId) {
|
|
35
35
|
${o.join(`
|
|
@@ -86,8 +86,8 @@ export async function ${e}(projectId) {
|
|
|
86
86
|
default: {
|
|
87
87
|
throw new Error('Unknown viewId: ' + viewId)
|
|
88
88
|
}
|
|
89
|
-
`}}).append(l," }",l,"}",l,l),y(e)}const Be={...k("dot"),async load({likec4:t,projectId:e,logger:i}){i.info(m.dim(`generating likec4:dot/${e}`));const n=await t.views.viewsAsGraphvizOut(e),r=ie(n,({id:
|
|
90
|
-
padStart(2,"0");return r.imports.push(`import ${c} from 'likec4/icons/${
|
|
89
|
+
`}}).append(l," }",l,"}",l,l),y(e)}const Be={...k("dot"),async load({likec4:t,projectId:e,logger:i}){i.info(m.dim(`generating likec4:dot/${e}`));const n=await t.views.viewsAsGraphvizOut(e),r=ie(n,({id:s,svg:o,dot:a})=>[s,{dot:a,svg:o}]);return ze(r)}},Ye=M("dot","loadDotSources");function qe(t){const e=re(t.flatMap(r=>r.nodes.map(s=>s.icon)),D(ae),D(r=>se(r)&&!(r.toLowerCase().startsWith("http:")||r.toLowerCase().startsWith("https:"))),oe()).sort(),{imports:i,cases:n}=e.reduce((r,s,o)=>{
|
|
90
|
+
const a=s.startsWith("file:"),d="Icon"+o.toString().padStart(2,"0");if(a)return r.imports.push(`import ${d} from '${s}?inline'`),r.cases.push(` '${s}': () => jsx('img', { src: ${d} })`),r;const[c,u]=s.split(":");return r.imports.push(`import ${d} from 'likec4/icons/${c}/${u}'`),r.cases.push(` '${c}:${u}': ${d}`),r},{imports:[],cases:[]});return`
|
|
91
91
|
import { jsx } from 'react/jsx-runtime'
|
|
92
92
|
${i.join(`
|
|
93
93
|
`)}
|
|
@@ -117,8 +117,8 @@ if (import.meta.hot) {
|
|
|
117
117
|
}
|
|
118
118
|
})
|
|
119
119
|
}
|
|
120
|
-
`}const He={...k("icons"),async load({likec4:t,projectId:e,logger:i}){i.info(m.dim(`generating likec4:icons/${e}`));const n=await t.views.computedViews(e);return qe(n)}},Ke={id:"likec4:icons",virtualId:"likec4:plugin/icons.
|
|
121
|
-
c)}`),
|
|
120
|
+
`}const He={...k("icons"),async load({likec4:t,projectId:e,logger:i}){i.info(m.dim(`generating likec4:icons/${e}`));const n=await t.views.computedViews(e);return qe(n)}},Ke={id:"likec4:icons",virtualId:"likec4:plugin/icons.jsx",async load({likec4:t,projects:e,logger:i}){i.info(m.dim("generating likec4:icons"));const{imports:n,cases:r}=e.reduce((s,{id:o},a)=>{const d="Icons"+a.toString().padStart(2,"0"),c=S("likec4:icons",o);return s.imports.push(`import { IconRenderer as ${d} } from ${JSON.stringify(
|
|
121
|
+
c)}`),s.cases.push(` case ${JSON.stringify(o)}: return ${d}`),s},{imports:[],cases:[]});return`
|
|
122
122
|
${n.join(`
|
|
123
123
|
`)}
|
|
124
124
|
|
|
@@ -179,7 +179,7 @@ if (import.meta.hot) {
|
|
|
179
179
|
`,tt={...k("model"),async load({likec4:t,projectId:e,logger:i,assetsDir:n}){i.info(m.dim(`generating likec4:model/${e}`));const r=await t.layoutedModel(e);return et(r)}},nt={id:"likec4:model",virtualId:"likec4:plugin/model.js",async load({likec4:t,logger:e,projects:i,assetsDir:n}){return e.info(m.dim("generating likec4:model")),`
|
|
180
180
|
export async function loadModel(projectId) {
|
|
181
181
|
switch (projectId) {
|
|
182
|
-
${i.map(({id:r})=>{const
|
|
182
|
+
${i.map(({id:r})=>{const s=S("likec4:model",r);return` case ${JSON.stringify(r)}: return await import(${JSON.stringify(s)})`}).join(`
|
|
183
183
|
`)}
|
|
184
184
|
default: throw new Error('Unknown projectId: ' + projectId)
|
|
185
185
|
}
|
|
@@ -210,7 +210,7 @@ export {
|
|
|
210
210
|
useLikeC4View,
|
|
211
211
|
useLikeC4Views
|
|
212
212
|
}
|
|
213
|
-
`,ot={...k("react"),async load({projectId:t,logger:e}){return e.info(m.dim(`generating likec4:react/${t}`)),H(t)}},
|
|
213
|
+
`,ot={...k("react"),async load({projectId:t,logger:e}){return e.info(m.dim(`generating likec4:react/${t}`)),H(t)}},st={id:"likec4:react",virtualId:"likec4:plugin/react.js",async load({logger:t,projects:e}){const i=O(e);return t.info(m.dim("generating likec4:react for")+" "+i.id),H(i.id)}},at=t=>`
|
|
214
214
|
export { IconRenderer } from 'likec4:icons/${t}'
|
|
215
215
|
export {
|
|
216
216
|
$likec4data,
|
|
@@ -220,8 +220,8 @@ export {
|
|
|
220
220
|
useLikeC4View
|
|
221
221
|
} from 'likec4:model/${t}'
|
|
222
222
|
export const projectId = ${JSON.stringify(t)}
|
|
223
|
-
`,dt={id:"likec4:single-project",virtualId:"likec4:plugin/single-project.js",async load({likec4:t,logger:e,projects:i,assetsDir:n}){const r=O(i);return e.info(m.dim("generating likec4:single-project for")+" "+r.id),
|
|
224
|
-
if(i=o.root,n=o.logger,t===!0){const
|
|
225
|
-
virtualId(d)}for(const
|
|
226
|
-
ct(
|
|
227
|
-
`+c.message.slice(0,500),stack:"",plugin:"vite-plugin-likec4",loc:{file:Z(i,c.sourceFsPath),line:c.range.start.line+1,column:c.range.start.character+1}}});return}for(const
|
|
223
|
+
`,dt={id:"likec4:single-project",virtualId:"likec4:plugin/single-project.js",async load({likec4:t,logger:e,projects:i,assetsDir:n}){const r=O(i);return e.info(m.dim("generating likec4:single-project for")+" "+r.id),at(r.id)}},K=[tt,He,Ge,Be,Qe],X=[...K,ot],Q=[rt,nt,dt,st,Fe,Ye,Ze,Ke],ct=t=>{const e=t.toLowerCase();return e.endsWith(".c4")||e.endsWith(".likec4")||e.endsWith(".like-c4")};function lt({useOverviewGraph:t=!1,...e}){let i,n,r,s;return{name:"vite-plugin-likec4",async configResolved(o){
|
|
224
|
+
if(i=o.root,n=o.logger,t===!0){const a=o.resolve.alias.find(d=>d.find==="likec4/previews")?.replacement;a?(s=a,n.info(m.dim("likec4/previews alias")+" "+m.dim(s))):n.warn("likec4/previews alias not found")}e.languageServices?r=e.languageServices:r=(await le.fromWorkspace(e.workspace??o.root,{logger:n,graphviz:e.graphviz??"wasm",printErrors:e.printErrors??!0,throwIfInvalid:e.throwIfInvalid??!1})).languageServices,s=r.workspaceUri.fsPath},resolveId(o){for(const a of X){const d=a.matches(o);if(d)return a.
|
|
225
|
+
virtualId(d)}for(const a of Q)if(a.id===o)return a.virtualId;return null},async load(o){for(const a of X){const d=a.matches(o);if(d)return await a.load({logger:n,likec4:r,projectId:d,assetsDir:s,useOverviewGraph:t})}for(const a of Q)if(a.virtualId===o){const d=await r.projects();return await a.load({logger:n,likec4:r,projects:d,assetsDir:s,useOverviewGraph:t})}return null},configureServer(o){const a=r.projects().map(({folder:c})=>c.fsPath);for(const c of a)n.info(`${m.dim("watch")} ${c}`);const d=c=>u=>{
|
|
226
|
+
ct(u)&&r.notifyUpdate({[c]:u})};o.watcher.add(a).on("add",d("changed")).on("change",d("changed")).on("unlink",d("removed")),r.builder.onModelParsed(async()=>{const[c]=r.getErrors();if(c){o.ws.send({type:"error",err:{name:"LikeC4ValidationError",message:`Validation failed
|
|
227
|
+
`+c.message.slice(0,500),stack:"",plugin:"vite-plugin-likec4",loc:{file:Z(i,c.sourceFsPath),line:c.range.start.line+1,column:c.range.start.character+1}}});return}for(const u of r.projects())for(const f of K){const p=o.moduleGraph.getModuleById(f.virtualId(u.id));if(p&&p.importers.size>0){n.info(`${m.green("reload")} ${m.dim(p.id??p.url)}`);try{await o.reloadModule(p)}catch(h){n.error(h)}}}})}}}export{g as C,lt as L,l as N,Y as a,w as e,q as g,I as j,y as t};
|