likec4 1.30.0 → 1.32.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.
@@ -19,31 +19,32 @@ declare module 'likec4:icons' {
19
19
  }
20
20
 
21
21
  declare module 'likec4:model' {
22
- import type { DiagramView, LayoutedLikeC4ModelData, LikeC4Model } from 'likec4/model'
22
+ import type { DiagramView, LayoutedLikeC4ModelData, LikeC4Model, UnknownLayouted } from 'likec4/model'
23
23
  import type { nano } from 'likec4/react'
24
24
 
25
- export type Atom<T> = nano.Atom<T>
25
+ export type Atom<T> = nano.ReadableAtom<T>
26
26
 
27
- export type { DiagramView, LayoutedLikeC4ModelData, LikeC4Model }
27
+ export type { DiagramView, LayoutedLikeC4ModelData, LikeC4Model, UnknownLayouted }
28
28
 
29
29
  export function loadModel(projectId: string): Promise<{
30
- $likec4data: Atom<LayoutedLikeC4ModelData>
31
- $likec4model: Atom<LikeC4Model.Layouted>
32
- useLikeC4Model: () => LikeC4Model.Layouted
33
- useLikeC4Views: () => ReadonlyArray<DiagramView>
34
- useLikeC4View: (viewId: string) => DiagramView | null
30
+ $likec4data: Atom<LayoutedLikeC4ModelData<UnknownLayouted>>
31
+ $likec4model: Atom<LikeC4Model<UnknownLayouted>>
32
+ useLikeC4Model: () => LikeC4Model<UnknownLayouted>
33
+ useLikeC4Views: () => ReadonlyArray<DiagramView<UnknownLayouted>>
34
+ useLikeC4View: (viewId: string) => DiagramView<UnknownLayouted> | null
35
35
  }>
36
36
  }
37
37
 
38
38
  declare module 'likec4:single-project' {
39
+ import type { DiagramView, LayoutedLikeC4ModelData, LikeC4Model, UnknownLayouted } from 'likec4/model'
39
40
  import type { ElementIconRenderer } from 'likec4:icons'
40
- import type { Atom, DiagramView, LayoutedLikeC4ModelData, LikeC4Model } from 'likec4:model'
41
+ import type { Atom } from 'likec4:model'
41
42
 
42
- export const $likec4data: Atom<LayoutedLikeC4ModelData>
43
- export const $likec4model: Atom<LikeC4Model.Layouted>
44
- export function useLikeC4Model(): LikeC4Model.Layouted
45
- export function useLikeC4Views(): ReadonlyArray<DiagramView>
46
- export function useLikeC4View(viewId: string): DiagramView | null
43
+ export const $likec4data: Atom<LayoutedLikeC4ModelData<UnknownLayouted>>
44
+ export const $likec4model: Atom<LikeC4Model<UnknownLayouted>>
45
+ export function useLikeC4Model(): LikeC4Model<UnknownLayouted>
46
+ export function useLikeC4Views(): ReadonlyArray<DiagramView<UnknownLayouted>>
47
+ export function useLikeC4View(viewId: string): DiagramView<UnknownLayouted> | null
47
48
 
48
49
  export const IconRenderer: ElementIconRenderer
49
50
 
@@ -51,23 +52,23 @@ declare module 'likec4:single-project' {
51
52
  }
52
53
 
53
54
  declare module 'likec4:react' {
54
- import type { Aux, DiagramView, LikeC4Model } from 'likec4/model'
55
+ import type { aux, DiagramView, LikeC4Model, UnknownLayouted } from 'likec4/model'
55
56
  import type { LikeC4ViewProps, ReactLikeC4Props } from 'likec4/react'
56
57
  import type { JSX, PropsWithChildren } from 'react'
57
58
 
58
59
  // This will be used later for augmenting the types
59
- interface Types extends Aux<string, string, string, DiagramView> {
60
+ interface Types extends UnknownLayouted {
60
61
  }
61
62
 
62
- export type LikeC4ViewId = Types['View']
63
+ export type LikeC4ViewId = aux.ViewId<Types>
63
64
 
64
65
  export function useLikeC4Model(): LikeC4Model<Types>
65
- export function useLikeC4Views(): ReadonlyArray<DiagramView<LikeC4ViewId>>
66
- export function useLikeC4View(viewId: LikeC4ViewId): DiagramView | null
66
+ export function useLikeC4Views(): ReadonlyArray<DiagramView<Types>>
67
+ export function useLikeC4View(viewId: LikeC4ViewId): DiagramView<Types> | null
67
68
 
68
69
  export function LikeC4ModelProvider(props: PropsWithChildren): JSX.Element
69
- export function LikeC4View({ viewId, ...props }: LikeC4ViewProps<LikeC4ViewId>): JSX.Element
70
- export function ReactLikeC4({ viewId, ...props }: ReactLikeC4Props<LikeC4ViewId>): JSX.Element
70
+ export function LikeC4View({ viewId, ...props }: LikeC4ViewProps<Types>): JSX.Element
71
+ export function ReactLikeC4({ viewId, ...props }: ReactLikeC4Props<Types>): JSX.Element
71
72
  }
72
73
 
73
74
  declare module 'likec4:dot' {
@@ -86,17 +87,29 @@ declare module 'likec4:mmd' {
86
87
  mmdSource(viewId: string): string
87
88
  }>
88
89
  }
90
+ declare module 'likec4:puml' {
91
+ export function loadPumlSources(projectId: string): Promise<{
92
+ pumlSource(viewId: string): string
93
+ }>
94
+ }
89
95
 
90
96
  // Per project
91
97
 
92
98
  declare module 'likec4:model/*' {
93
- import type { Atom, DiagramView, LayoutedLikeC4ModelData, LikeC4Model } from 'likec4:model'
99
+ import type { aux, DiagramView, LayoutedLikeC4ModelData, LikeC4Model, UnknownLayouted } from 'likec4/model'
100
+ import type { Atom } from 'likec4:model'
94
101
 
95
- export const $likec4data: Atom<LayoutedLikeC4ModelData>
96
- export const $likec4model: Atom<LikeC4Model.Layouted>
97
- export function useLikeC4Model(): LikeC4Model.Layouted
98
- export function useLikeC4Views(): ReadonlyArray<DiagramView>
99
- export function useLikeC4View(viewId: string): DiagramView | null
102
+ // This will be used later for augmenting the types
103
+ interface Types extends UnknownLayouted {
104
+ }
105
+
106
+ export type LikeC4ViewId = aux.ViewId<Types>
107
+
108
+ export const $likec4data: Atom<LayoutedLikeC4ModelData<Types>>
109
+ export const $likec4model: Atom<LikeC4Model<Types>>
110
+ export function useLikeC4Model(): LikeC4Model<Types>
111
+ export function useLikeC4Views(): ReadonlyArray<DiagramView<Types>>
112
+ export function useLikeC4View(viewId: LikeC4ViewId): DiagramView<Types> | null
100
113
  }
101
114
 
102
115
  declare module 'likec4:icons/*' {
@@ -112,21 +125,21 @@ declare module 'likec4:icons/*' {
112
125
  }
113
126
 
114
127
  declare module 'likec4:react/*' {
115
- import type { Aux, DiagramView, LikeC4Model } from 'likec4/model'
128
+ import type { aux, DiagramView, LikeC4Model, UnknownLayouted } from 'likec4/model'
116
129
  import type { LikeC4ViewProps, ReactLikeC4Props } from 'likec4/react'
117
130
  import type { JSX, PropsWithChildren } from 'react'
118
131
 
119
132
  // This will be used later for augmenting the types
120
- interface Types extends Aux<string, string, string, DiagramView> {
133
+ interface Types extends UnknownLayouted {
121
134
  }
122
135
 
123
- export type LikeC4ViewId = Types['View']
136
+ export type LikeC4ViewId = aux.ViewId<Types>
124
137
 
125
138
  export function useLikeC4Model(): LikeC4Model<Types>
126
- export function useLikeC4Views(): ReadonlyArray<DiagramView<LikeC4ViewId>>
127
- export function useLikeC4View(viewId: LikeC4ViewId): DiagramView | null
139
+ export function useLikeC4Views(): ReadonlyArray<DiagramView<Types>>
140
+ export function useLikeC4View(viewId: LikeC4ViewId): DiagramView<Types> | null
128
141
 
129
142
  export function LikeC4ModelProvider(props: PropsWithChildren): JSX.Element
130
- export function LikeC4View({ viewId, ...props }: LikeC4ViewProps<LikeC4ViewId>): JSX.Element
131
- export function ReactLikeC4({ viewId, ...props }: ReactLikeC4Props<LikeC4ViewId>): JSX.Element
143
+ export function LikeC4View({ viewId, ...props }: LikeC4ViewProps<Types>): JSX.Element
144
+ export function ReactLikeC4({ viewId, ...props }: ReactLikeC4Props<Types>): JSX.Element
132
145
  }
@@ -1,227 +0,0 @@
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
- [],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
- 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,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
- 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=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
- "u"?`
19
- `:process.platform==="win32"?`\r
20
- `:`
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
- 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: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
- export async function ${e}(projectId) {
34
- switch (projectId) {
35
- ${o.join(`
36
- `)}
37
- default: throw new Error('Unknown projectId: ' + projectId)
38
- }
39
- }
40
- `}}}const We=t=>{const e=new g;return e.appendTemplate`
41
- /******************************************************************************
42
- * This file was generated
43
- * DO NOT EDIT MANUALLY!
44
- ******************************************************************************/
45
- /* eslint-disable */
46
-
47
- export function d2Source(viewId) {
48
- switch (viewId) {
49
- `.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(I(t,n=>w`
50
- case ${JSON.stringify(n.id)}: {
51
- return ${JSON.stringify(Y(n))}
52
- }
53
- `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
54
- default: {
55
- throw new Error('Unknown viewId: ' + viewId)
56
- }
57
- `}}).append(l," }",l).appendTemplate`
58
- }
59
- `.append(l,l),y(e)},Ge={...k("d2"),async load({likec4:t,projectId:e,logger:i}){i.info(m.dim(`generating likec4:d2/${e}`));const n=await t.views.computedViews(e);return We(n)}},Fe=M("d2","loadD2Sources");function ze(t){const e=new g;return e.appendTemplate`
60
- /******************************************************************************
61
- * This file was generated
62
- * DO NOT EDIT MANUALLY!
63
- ******************************************************************************/
64
- /* eslint-disable */
65
-
66
- export function dotSource(viewId) {
67
- switch (viewId) {
68
- `.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(I(Object.keys(t),n=>w`
69
- case ${JSON.stringify(n)}: {
70
- return ${JSON.stringify(t[n].dot)}
71
- }
72
- `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
73
- default: {
74
- throw new Error('Unknown viewId: ' + viewId)
75
- }
76
- `}}).append(l," }",l).appendTemplate`
77
- }
78
-
79
- export function svgSource(viewId) {
80
- switch (viewId) {
81
- `.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(I(Object.keys(t),n=>w`
82
- case ${JSON.stringify(n)}: {
83
- return ${JSON.stringify(t[n].svg)}
84
- }
85
- `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
86
- default: {
87
- throw new Error('Unknown viewId: ' + viewId)
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: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
- import { jsx } from 'react/jsx-runtime'
92
- ${i.join(`
93
- `)}
94
-
95
- export const Icons = {
96
- ${n.join(`,
97
- `)}
98
- }
99
- export function IconRenderer({ node }) {
100
- const IconComponent = Icons[node.icon ?? '']
101
- if (!IconComponent) {
102
- return null
103
- }
104
- return jsx(IconComponent, {node})
105
- }
106
-
107
- if (import.meta.hot) {
108
- import.meta.hot.accept(md => {
109
- const update = md.Icons
110
- if (update) {
111
- if (!import.meta.hot.data.icons) {
112
- import.meta.hot.data.icons = Icons
113
- }
114
- Object.assign(import.meta.hot.data.icons, update)
115
- } else {
116
- import.meta.hot.invalidate()
117
- }
118
- })
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.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
- ${n.join(`
123
- `)}
124
-
125
- export function ProjectIcons(projectId) {
126
- switch (projectId) {
127
- ${r.join(`
128
- `)}
129
- default:
130
- throw new Error('Unknown projectId: ' + projectId)
131
- }
132
- }
133
- `}};function Xe(t){const e=new g;return e.appendTemplate`
134
- /******************************************************************************
135
- * This file was generated
136
- * DO NOT EDIT MANUALLY!
137
- ******************************************************************************/
138
- /* eslint-disable */
139
-
140
- export function mmdSource(viewId) {
141
- switch (viewId) {
142
- `.appendNewLine().indent({indentation:4,indentedChildren(i){i.append(I(t,n=>w`
143
- case ${JSON.stringify(n.id)}: {
144
- return ${JSON.stringify(q(n))}
145
- }
146
- `,{appendNewLineIfNotEmpty:!0})).appendTemplate`
147
- default: {
148
- throw new Error('Unknown viewId: ' + viewId)
149
- }
150
- `}}).append(l," }",l).appendTemplate`
151
- }
152
-
153
- `.append(l,l),y(e)}const Qe={...k("mmd"),async load({likec4:t,projectId:e,logger:i}){i.info(m.dim(`generating virtual:likec4/mmd/${e}`));const n=await t.views.computedViews(e);return Xe(n)}},Ze=M("mmd","loadMmdSources"),et=t=>`
154
- import { nano, createHooksForModel } from 'likec4/react'
155
-
156
- export const $likec4data = nano.atom(${P.stringify(t.$model)})
157
-
158
- export const {
159
- updateModel,
160
- $likec4model,
161
- useLikeC4Model,
162
- useLikeC4Views,
163
- useLikeC4View
164
- }= /* @__PURE__ */ createHooksForModel($likec4data)
165
-
166
- if (import.meta.hot) {
167
- import.meta.hot.accept(md => {
168
- if (!import.meta.hot.data.$update) {
169
- import.meta.hot.data.$update = updateModel
170
- }
171
- const update = md.$likec4data?.value
172
- if (update) {
173
- import.meta.hot.data.$update(update)
174
- } else {
175
- import.meta.hot.invalidate()
176
- }
177
- })
178
- }
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
- export async function loadModel(projectId) {
181
- switch (projectId) {
182
- ${i.map(({id:r})=>{const s=S("likec4:model",r);return` case ${JSON.stringify(r)}: return await import(${JSON.stringify(s)})`}).join(`
183
- `)}
184
- default: throw new Error('Unknown projectId: ' + projectId)
185
- }
186
- }
187
- `}},it=t=>`
188
- export const isSingleProject = ${t.length===1};
189
- export const projects = ${P.stringify(t,null,2)};
190
- `,rt={id:"likec4:projects",virtualId:"likec4:plugin/projects.js",async load({likec4:t,logger:e,projects:i,assetsDir:n}){return e.info(m.dim("generating likec4:projects")),it(de(i,ce("id")))}},H=t=>`
191
- import { jsx as _jsx } from "react/jsx-runtime";
192
- import { LikeC4ModelProvider as Provider, LikeC4View as GenericView, ReactLikeC4 as GenericReactLikeC4 } from 'likec4/react';
193
- import { IconRenderer } from 'likec4:icons/${t}'
194
-
195
- import { useLikeC4Model, useLikeC4Views, useLikeC4View } from 'likec4:model/${t}'
196
-
197
- export function LikeC4ModelProvider({ children }) {
198
- const likeC4Model = useLikeC4Model()
199
- return (_jsx(Provider, { likec4model: likeC4Model, children: children }));
200
- }
201
- export function LikeC4View(props) {
202
- return (_jsx(LikeC4ModelProvider, { children: _jsx(GenericView, { renderIcon: IconRenderer, ...props }) }));
203
- }
204
- export function ReactLikeC4(props) {
205
- return (_jsx(LikeC4ModelProvider, { children: _jsx(GenericReactLikeC4, { renderIcon: IconRenderer, ...props }) }));
206
- }
207
-
208
- export {
209
- useLikeC4Model,
210
- useLikeC4View,
211
- useLikeC4Views
212
- }
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
- export { IconRenderer } from 'likec4:icons/${t}'
215
- export {
216
- $likec4data,
217
- $likec4model,
218
- useLikeC4Model,
219
- useLikeC4Views,
220
- useLikeC4View
221
- } from 'likec4:model/${t}'
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),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};