@likec4/generators 1.59.1 → 1.59.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ import"./rolldown-runtime.mjs";import{NewLineNode as e,toString as t}from"langium/generate";const n=new e(`
2
+ `);function toStringLF(e,n){return t(e,n).replaceAll(`\r
3
+ `,`
4
+ `)}export{toStringLF as n,n as t};
package/dist/index.d.mts CHANGED
@@ -161,6 +161,23 @@ type DrawioRoundtripData = {
161
161
  */
162
162
  declare function parseDrawioRoundtripComments(c4Source: string): DrawioRoundtripData | null;
163
163
  //#endregion
164
+ //#region src/markdown/generate-markdown.d.ts
165
+ type GenerateMarkdownOptions = {
166
+ /**
167
+ * `LikeC4Project` has no description field of its own yet, so callers source this from
168
+ * wherever they keep it (e.g. the project config's `metadata` bag) and pass it through.
169
+ * If a first-class description ever lands on `LikeC4Project`, read it from the model
170
+ * directly instead and drop this option.
171
+ */
172
+ description?: string;
173
+ };
174
+ /**
175
+ * Renders a LikeC4 model as a Markdown document: the project title, an optional
176
+ * description, and every authored view as a Mermaid diagram. Views without a
177
+ * `sourcePath` (e.g. auto-generated index views) are skipped.
178
+ */
179
+ declare function generateMarkdown(model: LikeC4Model<aux.Unknown>, options?: GenerateMarkdownOptions): string;
180
+ //#endregion
164
181
  //#region src/mmd/generate-mmd.d.ts
165
182
  declare function generateMermaid(viewmodel: LikeC4ViewModel<aux.Unknown>): string;
166
183
  //#endregion
@@ -212,4 +229,4 @@ declare function generateViewsDataTs(diagrams: Iterable<DiagramView>): string;
212
229
  */
213
230
  declare function generateViewsDataDTs(diagrams: Iterable<DiagramView>): string;
214
231
  //#endregion
215
- export { DEFAULT_DRAWIO_ALL_FILENAME, type DrawioExportProfile, type DrawioViewModelLike, type GenerateDrawioOptions, buildDrawioExportOptionsForViews, buildDrawioExportOptionsFromSource, decompressDrawioDiagram, generateD2, generateDrawio, generateDrawioEditUrl, generateDrawioMulti, generateLikeC4Model, generateMermaid, generatePuml, generateReactNext, generateReactTypes, generateViewsDataDTs, generateViewsDataJs, generateViewsDataTs, getAllDiagrams, parseDrawioRoundtripComments, parseDrawioToLikeC4, parseDrawioToLikeC4Multi };
232
+ export { DEFAULT_DRAWIO_ALL_FILENAME, type DrawioExportProfile, type DrawioViewModelLike, type GenerateDrawioOptions, buildDrawioExportOptionsForViews, buildDrawioExportOptionsFromSource, decompressDrawioDiagram, generateD2, generateDrawio, generateDrawioEditUrl, generateDrawioMulti, generateLikeC4Model, generateMarkdown, generateMermaid, generatePuml, generateReactNext, generateReactTypes, generateViewsDataDTs, generateViewsDataJs, generateViewsDataTs, getAllDiagrams, parseDrawioRoundtripComments, parseDrawioToLikeC4, parseDrawioToLikeC4Multi };
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import{n as e}from"./chunks/rolldown-runtime.mjs";import{CompositeGeneratorNode as t,NL as n,expandToNode as r,joinToNode as i,toString as a}from"langium/generate";import{filter as o,isEmptyish as s,isNullish as c,isTruthy as l,keys as u,map as d,pipe as f,sort as p,unique as m,values as h}from"remeda";import{LikeC4Styles as g,nonexhaustive as _}from"@likec4/core";import{RichText as v,flattenMarkdownOrString as y}from"@likec4/core/types";import b from"pako";import x from"json5";import{compareNatural as S,invariant as C,sortNaturalByFqn as w}from"@likec4/core/utils";const T=e(e=>e.charAt(0).toLocaleUpperCase()+e.slice(1),`capitalizeFirstLetter`),E=e(e=>e.split(`.`).map(T).join(``),`fqnName`),D=e(e=>E(e.parent?e.id.slice(e.parent.length+1):e.id),`nodeName`),d2direction=({autoLayout:e})=>{switch(e.direction){case`TB`:return`down`;case`BT`:return`up`;case`LR`:return`right`;case`RL`:return`left`}},d2shape=({shape:e})=>{switch(e){case`queue`:case`cylinder`:case`rectangle`:case`document`:return e;case`person`:return`c4-person`;case`storage`:return`stored_data`;case`component`:case`bucket`:case`mobile`:case`browser`:return`rectangle`}};function generateD2(e){let r=e.$view,{nodes:o,edges:s}=r,l=new Map,printNode=(e,r)=>{let a=D(e),s=(r?r+`.`:``)+a;l.set(e.id,s);let c=JSON.stringify(e.title),u=d2shape(e);return new t().append(a,`: {`,n).indent({indentedChildren:t=>t.append(`label: `,c,n).appendIf(u!==`rectangle`,`shape: `,u,n).appendIf(e.children.length>0,n,i(o.filter(t=>t.parent===e.id),e=>printNode(e,s))),indentation:2}).append(`}`,n)},printEdge=e=>new t().append(l.get(e.source),` -> `,l.get(e.target)).append(t=>e.label&&t.append(`: `,JSON.stringify(e.label)));return a(new t().append(`direction: `,d2direction(r),n,n).append(i(o.filter(e=>c(e.parent)),e=>printNode(e),{appendNewLineIfNotEmpty:!0})).appendIf(s.length>0,n,i(s,e=>printEdge(e),{appendNewLineIfNotEmpty:!0})))}const O=`data:page/id,likec4-`,k=`diagrams.drawio`;function escapeXml(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`).replaceAll(`"`,`&quot;`).replaceAll(`'`,`&apos;`)}function decodeXmlEntities(e){return e.replaceAll(`&lt;`,`<`).replaceAll(`&gt;`,`>`).replaceAll(`&quot;`,`"`).replaceAll(`&apos;`,`'`).replaceAll(`&amp;`,`&`)}function toErrorMessage(e){return e instanceof Error?e.message:String(e)}function isEdgeWithEndpoints(e){return e.edge===!0&&typeof e.source==`string`&&typeof e.target==`string`}function isAttrBoundaryChar(e){return e===` `||e===` `||e===`
2
- `||e===`\r`}function getAttr(e,t){let n=`${t}=`,r=e.toLowerCase(),i=n.toLowerCase(),a=0;for(;a<e.length;){let t=r.indexOf(i,a);if(t===-1)return;if(!isAttrBoundaryChar(t===0?` `:e[t-1]??` `)){a=t+1;continue}let o=t+n.length;if(o<e.length&&e[o]===`"`){let t=e.indexOf(`"`,o+1);if(t!==-1)return e.slice(o+1,t)}a=t+1}}function extractStyleFromAttrsFallback(e){let t=e.toLowerCase(),n=t.indexOf(`style`);for(;n!==-1;){if(!isAttrBoundaryChar(n===0?` `:e[n-1]??` `)){n=t.indexOf(`style`,n+1);continue}let r=n+5;for(;r<e.length&&isAttrBoundaryChar(e[r]??``);)r+=1;if(r<e.length&&e[r]===`=`){for(r+=1;r<e.length&&isAttrBoundaryChar(e[r]??``);)r+=1;if(r<e.length&&e[r]===`"`){let t=r+1,n=e.indexOf(`"`,t);if(n!==-1)return e.slice(t,n)}}n=t.indexOf(`style`,n+1)}}function extractStyleFromOpenTag(e){let t=e.indexOf(`>`);if(t!==-1)return getAttr(e.slice(7,t),`style`)??extractStyleFromAttrsFallback(e.slice(7,t))}const A=1e4;function extractStyleFromTagContent(e,t=1500){let n=e.slice(0,t),r=n.toLowerCase().indexOf(`style="`),i=n.toLowerCase().indexOf(`style='`),a=r!==-1&&(i===-1||r<=i),o=a?r:i,s=o===-1?``:a?`"`:`'`;if(o===-1||!s)return;let c=o+7,l=n.indexOf(s,c);return l===-1?void 0:n.slice(c,l)}function styleOrTagIndicatesActor(e,t){let n=e?.toLowerCase()??``;return n.includes(`shape=actor`)||n.includes(`shape=person`)||n.includes(`umlactor`)||t.includes(`shape=actor`)||t.includes(`shape=person`)||t.includes(`umlactor`)}function findOpenTagEnd(e,t){let n=``,r=t;for(;r<e.length;){let t=e[r];if(t===`"`||t===`'`)n===``?n=t:n===t&&(n=``);else if(t===`>`&&n===``)return r;r+=1}return-1}function indexOfTagStart(e,t,n){let r=e.toLowerCase(),i=`<${t.toLowerCase()}`;return r.indexOf(i,n)}function indexOfClosingTag(e,t,n){let r=e.toLowerCase(),i=`</${t.toLowerCase()}>`;return r.indexOf(i,n)}function parseNum(e){if(e===void 0||e===``)return;let t=Number.parseFloat(e);return Number.isNaN(t)?void 0:t}function getDecodedStyle(e,t){let n=e.get(t);if(n!=null&&n!==``)try{return decodeURIComponent(n)}catch{return n}}function parseStyle(e){let t=new Map;if(!e)return t;for(let n of e.split(`;`)){let e=n.indexOf(`=`);if(e>0){let r=n.slice(0,e).trim(),i=n.slice(e+1).trim();r&&i&&t.set(r.toLowerCase(),i)}}return t}const j=new Set([`likec4description`,`likec4technology`]);function parseAllUserData(e){let t={},n=0;for(;;){let r=indexOfTagStart(e,`data`,n);if(r===-1)break;let i=findOpenTagEnd(e,r);if(i===-1)break;let a=getAttr(e.slice(r,i+1),`key`)?.trim(),o=indexOfClosingTag(e,`data`,i+1);if(o===-1)break;let s=e.slice(i+1,o).trim();a&&(t[a]=decodeXmlEntities(s)),n=o+7}return t}function extractMxGeometryOpenTag(e){let t=indexOfTagStart(e,`mxGeometry`,0);if(t===-1)return``;let n=findOpenTagEnd(e,t);return n===-1?``:e.slice(t,n+1)}function extractMxGeometryInner(e){let t=indexOfTagStart(e,`mxGeometry`,0);if(t===-1)return;let n=findOpenTagEnd(e,t);if(n===-1)return;let r=indexOfClosingTag(e,`mxGeometry`,n+1);if(r!==-1)return e.slice(n+1,r)}function parseEdgePoints(e){let t=extractMxGeometryInner(e);if(t===void 0)return;let n=[],r=0;for(;;){let e=indexOfTagStart(t,`mxPoint`,r);if(e===-1)break;let i=findOpenTagEnd(t,e);if(i===-1)break;let a=t.slice(e,i+1),o=parseNum(getAttr(a,`x`)),s=parseNum(getAttr(a,`y`));o!==void 0&&s!==void 0&&n.push([o,s]),r=i+1}if(n.length!==0)return JSON.stringify(n)}function parseUserData(e){let t=parseAllUserData(e),n={};t.likec4Description!=null&&(n.description=t.likec4Description),t.likec4Technology!=null&&(n.technology=t.likec4Technology);let r={};for(let[e,n]of Object.entries(t))!j.has(e.toLowerCase())&&n!=null&&n!==``&&(r[e]=n);return Object.keys(r).length>0&&(n.customData=JSON.stringify(r)),n}function navigateToFromLink(e){if(!(!e||e===``)&&e.toLowerCase().startsWith(`data:page/id,likec4-`))return e.slice(20).trim()}function buildCellOptionalFields(e){let{styleMap:t,userData:n,geomStr:r,fullTag:i,vertex:a,edge:o,navigateTo:s}=e,c=parseNum(getAttr(r,`x`)),l=parseNum(getAttr(r,`y`)),u=parseNum(getAttr(r,`width`)),d=parseNum(getAttr(r,`height`)),f=t.get(`fillcolor`),p=t.get(`strokecolor`),m=n.description??getDecodedStyle(t,`likec4description`),h=n.technology??getDecodedStyle(t,`likec4technology`),g=getDecodedStyle(t,`likec4notes`),_=getDecodedStyle(t,`likec4tags`),v=getDecodedStyle(t,`likec4icon`),y=t.get(`endarrow`),b=t.get(`startarrow`),x=t.get(`dashed`),S=t.get(`dashpattern`),C=getDecodedStyle(t,`likec4summary`),w=getDecodedStyle(t,`likec4links`),T=getDecodedStyle(t,`likec4border`),E=getDecodedStyle(t,`likec4colorname`),D=t.get(`opacity`),O=t.get(`likec4opacity`),k=t.get(`fillopacity`),A=(O!=null&&O!==``?O:void 0)??(D!=null&&D!==``?D:void 0)??(k!=null&&k!==``?k:void 0),j=t.get(`strokewidth`),M=j!=null&&j!==``?j:void 0,N=getDecodedStyle(t,`likec4size`),P=getDecodedStyle(t,`likec4padding`),F=getDecodedStyle(t,`likec4textsize`),I=getDecodedStyle(t,`likec4iconposition`),L=getDecodedStyle(t,`link`),R=getDecodedStyle(t,`likec4relationshipkind`),z=getDecodedStyle(t,`likec4notation`),B=getDecodedStyle(t,`likec4metadata`),V=getDecodedStyle(t,`likec4id`),H=getDecodedStyle(t,`likec4relationid`),U={};e.valueRaw!=null&&e.valueRaw!==``&&(U.value=decodeXmlEntities(e.valueRaw)),e.parent!=null&&e.parent!==``&&(U.parent=e.parent),e.source!=null&&e.source!==``&&(U.source=e.source),e.target!=null&&e.target!==``&&(U.target=e.target),e.style!=null&&e.style!==``?U.style=e.style:e.styleMap.has(`shape`)&&(U.style=`shape=${e.styleMap.get(`shape`)};`),c!==void 0&&(U.x=c),l!==void 0&&(U.y=l),u!==void 0&&(U.width=u),d!==void 0&&(U.height=d),f!==void 0&&(U.fillColor=f),p!==void 0&&(U.strokeColor=p),m!=null&&(U.description=m),h!=null&&(U.technology=h),g!=null&&(U.notes=g),_!=null&&(U.tags=_),s!=null&&(U.navigateTo=s),v!=null&&(U.icon=v),y!=null&&y!==``&&(U.endArrow=y),b!=null&&b!==``&&(U.startArrow=b),x!=null&&x!==``&&(U.dashed=x),S!=null&&S!==``&&(U.dashPattern=S),C!=null&&(U.summary=C),w!=null&&(U.links=w),L!=null&&a&&(U.link=L),T!=null&&(U.border=T),M!=null&&a&&(U.strokeWidth=M),N!=null&&a&&(U.size=N),P!=null&&a&&(U.padding=P),F!=null&&a&&(U.textSize=F),I!=null&&a&&(U.iconPosition=I),E!=null&&(U.colorName=E),A!=null&&(U.opacity=A),R!=null&&(U.relationshipKind=R),z!=null&&(U.notation=z),B!=null&&o&&(U.metadata=B),V!=null&&a&&(U.likec4Id=V),H!=null&&o&&(U.likec4RelationId=H);let W=e.styleMap.get(`shape`)?.trim(),G=e.fullTag.toLowerCase();if((W==null||W===``)&&a&&styleOrTagIndicatesActor(e.style,G)&&(W=`actor`),W!=null&&W!==``&&a&&(U.shapeFromStyle=W),n.customData!=null&&(U.customData=n.customData),o){let e=parseEdgePoints(i);e!=null&&(U.edgePoints=e)}return U}function buildCellFromMxCell(e,t,n,r){let i=r?.id??getAttr(e,`id`);if(!i)return null;let a=getAttr(e,`vertex`)===`1`,o=getAttr(e,`edge`)===`1`,s=getAttr(e,`style`)??extractStyleFromAttrsFallback(e)??extractStyleFromOpenTag(n),c=!s||s.trim()===``,l=n.length<A&&n.toLowerCase().includes(`shape=actor`);if((c||l&&!s?.toLowerCase().includes(`shape=actor`))&&n.length<A){let e=extractStyleFromTagContent(n);e!=null&&(s=e)}let u=extractMxGeometryOpenTag(n),d=parseStyle(s?.trim()||void 0),f=parseUserData(t),p=r?.navigateTo??getDecodedStyle(d,`likec4navigateto`),m=buildCellOptionalFields({valueRaw:getAttr(e,`value`),parent:getAttr(e,`parent`),source:getAttr(e,`source`),target:getAttr(e,`target`),style:s,styleMap:d,userData:f,geomStr:u,fullTag:n,vertex:a,edge:o,navigateTo:p});return{id:i,vertex:a,edge:o,...s!=null&&s!==``?{style:s}:{},...m}}function extractOneMxCell(e,t){let n=findOpenTagEnd(e,t);if(n===-1)return null;let r=e.slice(t+7,n).trim(),i=e.slice(t,n).trimEnd().endsWith(`/`),a=n+1,o,s;if(i)o=``,s=n;else{let t=indexOfClosingTag(e,`mxCell`,a);if(t===-1)return null;o=e.slice(a,t),s=t+9-1}let c=e.slice(t,s+1);return{attrs:r,inner:o,fullTag:c,next:s+1}}function parseDrawioXml(e){let t=[],n=new Set,r=indexOfTagStart(e,`UserObject`,0);for(;r!==-1;){let i=findOpenTagEnd(e,r);if(i===-1)break;let a=e.slice(r,i+1),o=getAttr(a,`id`)?.trim(),s=navigateToFromLink(getAttr(a,`link`)??void 0),c=indexOfClosingTag(e,`UserObject`,i+1);if(c===-1)break;let l=e.slice(i+1,c);if(o){let e=indexOfTagStart(l,`mxCell`,0);if(e!==-1){let r=extractOneMxCell(l,e);if(r){let e=`<mxCell id="${escapeXml(o)}" ${r.attrs}>${l}</mxCell>`,i=buildCellFromMxCell(r.attrs,l,e,s!=null&&s!==``?{id:o,navigateTo:s}:{id:o});i&&(t.push(i),n.add(i.id))}}}r=indexOfTagStart(e,`UserObject`,c+13)}let i=indexOfTagStart(e,`mxCell`,0);for(;i!==-1;){let r=extractOneMxCell(e,i);if(r){let a=getAttr(r.attrs,`id`);if(a&&!n.has(a)){let e=buildCellFromMxCell(r.attrs,r.inner,r.fullTag);e&&(t.push(e),n.add(e.id))}i=indexOfTagStart(e,`mxCell`,r.next)}else i=indexOfTagStart(e,`mxCell`,i+7)}return t}function likec4Arrow(e){if(!(!e||e===``))switch(e.toLowerCase()){case`none`:return`none`;case`block`:return`normal`;case`open`:return`open`;case`diamond`:return`diamond`;case`oval`:return`dot`;default:return`normal`}}function likec4LineType(e,t){if(e===`1`||e===`true`){let e=(t??``).trim();return e===`1 1`||e===`2 2`?`dotted`:`dashed`}}function isActorShapeInStyle(e,t){let n=e?.toLowerCase()??``,r=t?.toLowerCase().trim();return r===`actor`||r===`person`||n.includes(`shape=actor`)||n.includes(`shape=person`)||n.includes(`umlactor`)}function inferKind(e,t,n){let r=e?.toLowerCase()??``;if(isActorShapeInStyle(e,n))return`actor`;switch(!0){case!e&&!n:return t?.style?.toLowerCase().includes(`container=1`)?`component`:`container`;case r.includes(`swimlane`):case r.includes(`container=1`):return`system`;case!!t?.style?.toLowerCase().includes(`container=1`):return`component`;default:return`container`}}function inferShape(e,t){let n=e?.toLowerCase()??``;if(isActorShapeInStyle(e,t))return`person`;if(n.includes(`shape=cylinder`)||n.includes(`cylinder3`))return`cylinder`;if(n.includes(`shape=document`))return`document`;if(n.includes(`shape=rectangle`)&&n.includes(`rounded`))return`rectangle`}function toId(e){return e.trim().replaceAll(/\s+/g,`_`).replaceAll(/[^\w-]/g,``).replace(/^[0-9]/,`_$&`)||`element`}function makeUniqueName(e){return t=>{let n=toId(t||`element`),r=n,i=0;for(;e.has(r);)r=`${n}_${++i}`;return e.add(r),r}}function isValidFqn(e){return e.length!==0&&e.split(`.`).every(e=>/^[a-zA-Z0-9_-]+$/.test(e))}function vertexDepth(e,t,n=new Set){return n.has(e.id)||(n.add(e.id),e.parent==null||!t.has(e.parent))?0:1+vertexDepth(t.get(e.parent),t,n)}function isUsableBridgeId(e,t,n,r,i){if(!isValidFqn(e))return!1;let a=t.parent?n.get(t.parent):void 0;return a===void 0?i(t.parent):e.startsWith(a+`.`)&&e.length>a.length+1}function assignFqnsToElementVertices(e,t,n,r,i,a){let baseName=e=>e.value??n.get(e.id)??e.id,o=new Map(t.map(e=>[e.id,e])),s=[...t].sort((e,t)=>vertexDepth(e,o)-vertexDepth(t,o));for(let t of s){let n=t.likec4Id?.trim();if(n&&isUsableBridgeId(n,t,e,o,r)){e.set(t.id,n);for(let e of n.split(`.`))a.add(e)}}for(let n of t)e.has(n.id)||r(n.parent)&&e.set(n.id,i(baseName(n)));let c=!0;for(;c;){c=!1;for(let n of t){if(e.has(n.id))continue;let t=n.parent?e.get(n.parent):null;t!=null&&(e.set(n.id,`${t}.${i(baseName(n))}`),c=!0)}}for(let n of t)e.has(n.id)||e.set(n.id,i(baseName(n)))}function buildHexToCustomName(e,t){let n=new Map,r=0;for(let t of e){let e=t.fillColor?.trim();if(e&&/^#[0-9A-Fa-f]{3,8}$/.test(e))if(t.colorName?.trim()){let r=t.colorName.trim().replaceAll(/\s+/g,`_`);n.has(e)||n.set(e,r)}else n.has(e)||n.set(e,`drawio_color_${++r}`)}let i=0;for(let e of t){let t=e.strokeColor?.trim();t&&/^#[0-9A-Fa-f]{3,8}$/.test(t)&&!n.has(t)&&n.set(t,`drawio_edge_color_${++i}`)}return n}function computeContainerTitles(e){let t=new Map,n=new Set,r=e.filter(e=>e.style?.toLowerCase().includes(`container=1`)&&e.x!=null&&e.y!=null&&e.width!=null&&e.height!=null);for(let i of r){let r=i.width,a=i.height,o=Math.min(40,a*.5)+2,s=e.find(e=>e.id!==i.id&&e.parent===i.id&&(e.style?.toLowerCase().includes(`shape=text`)||e.style?.toLowerCase().includes(`text;`))&&e.x!=null&&e.y!=null&&e.x>=-2&&e.x<=r+2&&e.y>=-2&&e.y<=o);if(s){let e=(s.value??``).trim();e&&(t.set(i.id,stripHtml(e)),n.add(s.id))}}return{containerIdToTitle:t,titleCellIds:n}}function stripTags(e){let t=``,n=0;for(;n<e.length;){let r=e.indexOf(`<`,n);if(r===-1){t+=e.slice(n);break}t+=e.slice(n,r);let i=e.indexOf(`>`,r);i===-1?(t+=`<`,n=r+1):n=i+1}return t}function stripHtml(e){if(!e||e.trim()===``)return``;let t=decodeXmlEntities(e).split(`
3
- `)[0]??``,n=t.toLowerCase().indexOf(`<br`);return stripTags(n===-1?t:t.slice(0,n)).trim()||``}function escapeLikec4Quotes(e){return e.replaceAll(`'`,`''`)}function decodeRootStyleField(e){if(e==null||e===``)return``;try{return decodeURIComponent(e)}catch{return e}}function buildViewBlockLines(e,t,n){return[`views {`,` view ${e} {`,...t?[` title '${escapeLikec4Quotes(t)}'`]:[],...n?[` description '${escapeLikec4Quotes(n)}'`]:[],` include *`,` }`,`}`,``]}function pushElementHeader(e,t,n,r,i){let a=escapeLikec4Quotes(i);switch(r){case`actor`:e.lines.push(`${t}${n} = actor '${a}'`);break;case`system`:e.lines.push(`${t}${n} = system '${a}'`);break;default:e.lines.push(`${t}${n} = container '${a}'`)}}function pushElementStyleBlock(e,t,n,r){let i=n.border?.trim(),a=n.opacity,o=inferShape(n.style,n.shapeFromStyle),s=n.size?.trim(),c=n.padding?.trim(),l=n.textSize?.trim(),u=n.iconPosition?.trim();if(!r&&!(i&&[`solid`,`dashed`,`dotted`,`none`].includes(i))&&!(a&&/^\d+$/.test(a))&&!o&&!s&&!c&&!l&&!u)return;let d=[];r&&d.push(`color ${r}`),i&&[`solid`,`dashed`,`dotted`,`none`].includes(i)&&d.push(`border ${i}`),a&&/^\d+$/.test(a)&&d.push(`opacity ${a}`),o&&d.push(`shape ${o}`),s&&d.push(`size ${s}`),c&&d.push(`padding ${c}`),l&&d.push(`textSize ${l}`),u&&d.push(`iconPosition ${u}`),d.length>0&&e.lines.push(`${t} style { ${d.join(`, `)} }`)}function formatLinkLines(e,t,n){let r=[];try{let i=e?JSON.parse(e):null;if(Array.isArray(i))for(let e of i)e?.url&&r.push(`${n}link '${escapeLikec4Quotes(String(e.url))}'${e.title?` '${escapeLikec4Quotes(String(e.title))}'`:``}`);r.length===0&&t&&r.push(`${n}link '${escapeLikec4Quotes(t)}'`)}catch{t&&r.push(`${n}link '${escapeLikec4Quotes(t)}'`)}return r}function pushElementLinks(e,t,n,r){let i=`${t} `;for(let t of formatLinkLines(n,r,i))e.lines.push(t)}function elementHasBody(e,t,n,r){return(t?.length??0)>0||!!r.desc||!!r.tech||!!r.notes||!!r.summary||!!r.linksJson||!!r.nativeLink||!!r.notation||r.tagList.length>0||!!n||!!e.border?.trim()||!!e.opacity||!!inferShape(e.style,e.shapeFromStyle)||!!e.size||!!e.padding||!!e.textSize||!!e.iconPosition||!!r.navigateTo||!!r.icon}function pushElementBody(e,t,n,r,i,a,o,s){e.lines.push(`${t}{`),pushElementStyleBlock(e,t,n,o);for(let n of s.tagList)e.lines.push(`${t} #${n.replaceAll(/\s+/g,`_`)}`);if(s.desc&&e.lines.push(`${t} description '${escapeLikec4Quotes(s.desc)}'`),s.tech&&e.lines.push(`${t} technology '${escapeLikec4Quotes(s.tech)}'`),s.summary&&e.lines.push(`${t} summary '${escapeLikec4Quotes(s.summary)}'`),s.notes&&e.lines.push(`${t} notes '${escapeLikec4Quotes(s.notes)}'`),s.notation&&e.lines.push(`${t} notation '${escapeLikec4Quotes(s.notation)}'`),pushElementLinks(e,t,s.linksJson,s.nativeLink),s.navigateTo&&e.lines.push(`${t} navigateTo ${s.navigateTo}`),s.icon&&e.lines.push(`${t} icon '${escapeLikec4Quotes(s.icon)}'`),r&&r.length>0)for(let t of r)M.toLines(e,t.cellId,t.fqn,a+1);e.lines.push(`${t}}`)}function emitElementToLines(e,t,n,r){let i=e.idToCell.get(t);if(!i)return;let a=i.parent?e.byId.get(i.parent):void 0,o=inferKind(i.style,a,i.shapeFromStyle),s=stripHtml(i.value&&i.value.trim()||``)||(e.containerIdToTitle.get(i.id)??e.containerIdToTitle.get(t)??``)||n.split(`.`).pop()||`Element`,c=n.split(`.`).pop(),l=` `.repeat(r),u=i.description?.trim(),d=i.technology?.trim(),f=i.notes?.trim(),p=i.tags?.trim(),m=p?p.split(`,`).map(e=>e.trim()).filter(Boolean):[],h=i.navigateTo?.trim(),g=i.icon?.trim(),_=i.summary?.trim(),v=i.links?.trim(),y=i.link?.trim(),b=i.notation?.trim(),x=i.fillColor&&/^#[0-9A-Fa-f]{3,8}$/.test(i.fillColor.trim())?e.hexToCustomName.get(i.fillColor.trim()):void 0,S=e.children.get(n),C={desc:u,tech:d,notes:f,summary:_,linksJson:v,nativeLink:y,notation:b,tagList:m,navigateTo:h,icon:g},w=elementHasBody(i,S,x,C);pushElementHeader(e,l,c,o,s),w?pushElementBody(e,l,i,S,n,r,x,C):(e.lines.push(`${l}{`),e.lines.push(`${l}}`)),e.lines.push(``)}const M={toLines:emitElementToLines};function emitEdgesToLines(e,t,n){for(let{cell:r,src:i,tgt:a}of t){let t=r.value&&r.value.trim()?escapeLikec4Quotes(r.value.trim()):``,o=r.description?.trim(),s=r.technology?.trim(),c=r.notes?.trim(),l=r.navigateTo?.trim(),u=likec4Arrow(r.endArrow),d=likec4Arrow(r.startArrow),f=likec4LineType(r.dashed,r.dashPattern),p=r.relationshipKind?.trim(),m=r.notation?.trim(),h=r.links?.trim(),g=r.metadata?.trim(),_=r.strokeColor?.trim(),v=!!c||!!l||!!u||!!d||!!f||!!m||!!h||!!g||!!_,y=` ${i}${p&&/^[a-zA-Z0-9_-]+$/.test(p)?` -[${p}]-> `:` -> `}${a}${t?` '${t}'`:o||s?` ''`:``}${o?` '${escapeLikec4Quotes(o)}'`:``}${s?` '${escapeLikec4Quotes(s)}'`:``}`;if(v){let t=[];c&&t.push(` notes '${escapeLikec4Quotes(c)}'`),l&&t.push(` navigateTo ${l}`),m&&t.push(` notation '${escapeLikec4Quotes(m)}'`);for(let e of formatLinkLines(h,void 0,` `))t.push(e);try{let e=g?JSON.parse(g):null;if(typeof e==`object`&&e&&!Array.isArray(e)){let n=[];for(let[t,r]of Object.entries(e)){if(t.trim()===``)continue;let e=/^[a-zA-Z_]\w*$/.test(t)?t:`'${escapeLikec4Quotes(t)}'`;if(Array.isArray(r)){let t=r.map(e=>`'${escapeLikec4Quotes(String(e))}'`);n.push(` ${e} [ ${t.join(`, `)} ];`)}else r!=null&&typeof r==`string`&&n.push(` ${e} '${escapeLikec4Quotes(r)}';`)}n.length>0&&t.push(` metadata {`+n.join(``)+` }`)}}catch{}if(u||d||f||_){let e=[];if(f&&e.push(`line ${f}`),u&&e.push(`head ${u}`),d&&e.push(`tail ${d}`),_&&/^#[0-9A-Fa-f]{3,8}$/.test(_)){let t=n.get(_);t&&e.push(`color ${t}`)}e.length>0&&t.push(` style { ${e.join(`, `)} }`)}e.push(y+` {`,...t,` }`)}else e.push(y)}}function collectRoundtripForState(e,t,n,r){let i={},a=[],o=[],s=[],c=[];for(let[e,r]of t){let t=n.get(e);t?.vertex&&t.x!=null&&t.y!=null&&t.width!=null&&t.height!=null&&(i[r]={x:t.x,y:t.y,width:t.width,height:t.height}),t?.vertex&&(t.strokeColor?.trim()&&/^#[0-9A-Fa-f]{3,8}$/.test(t.strokeColor.trim())&&a.push(`// ${r}=${t.strokeColor.trim()}`),t.strokeWidth!=null&&t.strokeWidth.trim()!==``&&o.push(`// ${r}=${t.strokeWidth.trim()}`)),t?.customData?.trim()&&s.push(`// ${r} ${t.customData.trim()}`)}let l=r.filter(isEdgeWithEndpoints);for(let e of l){let n=t.get(e.source),r=t.get(e.target);n&&r&&(e.customData?.trim()&&s.push(`// ${n}|${r} ${e.customData.trim()}`),e.edgePoints?.trim()&&c.push(`// ${n}|${r}|${e.id} ${e.edgePoints.trim()}`))}return{layoutNodes:i,strokeColorLines:a,strokeWidthLines:o,customDataLines:s,waypointLines:c}}function emitRoundtripCommentsSingle(e,t,n,r,i){let a=collectRoundtripForState(t,n,r,i);Object.keys(a.layoutNodes).length>0&&e.push(`// <likec4.layout.drawio>`,`// `+JSON.stringify({[t]:{nodes:a.layoutNodes}}),`// </likec4.layout.drawio>`),a.strokeColorLines.length>0&&e.push(`// <likec4.strokeColor.vertices>`,...a.strokeColorLines,`// </likec4.strokeColor.vertices>`),a.strokeWidthLines.length>0&&e.push(`// <likec4.strokeWidth.vertices>`,...a.strokeWidthLines,`// </likec4.strokeWidth.vertices>`),a.customDataLines.length>0&&e.push(`// <likec4.customData>`,...a.customDataLines,`// </likec4.customData>`),a.waypointLines.length>0&&e.push(`// <likec4.edge.waypoints>`,...a.waypointLines,`// </likec4.edge.waypoints>`)}function emitRoundtripCommentsMulti(e,t){let n={},r=[],i=[],a=[],o=[];for(let e of t){let t=collectRoundtripForState(e.viewId,e.idToFqn,e.idToCell,e.edges);n[e.viewId]={nodes:t.layoutNodes},r.push(...t.strokeColorLines),i.push(...t.strokeWidthLines),a.push(...t.customDataLines),o.push(...t.waypointLines)}Object.values(n).some(e=>e!=null&&Object.keys(e.nodes).length>0)&&e.push(`// <likec4.layout.drawio>`,`// `+JSON.stringify(n),`// </likec4.layout.drawio>`),r.length>0&&e.push(`// <likec4.strokeColor.vertices>`,...r,`// </likec4.strokeColor.vertices>`),i.length>0&&e.push(`// <likec4.strokeWidth.vertices>`,...i,`// </likec4.strokeWidth.vertices>`),a.length>0&&e.push(`// <likec4.customData>`,...a,`// </likec4.customData>`),o.length>0&&e.push(`// <likec4.edge.waypoints>`,...o,`// </likec4.edge.waypoints>`)}function decompressDrawioDiagram(e){let t=e.trim(),n;try{if(typeof Buffer<`u`)n=new Uint8Array(Buffer.from(t,`base64`));else{let e=atob(t);n=new Uint8Array(e.length);for(let t=0;t<e.length;t++)n[t]=e.charCodeAt(t)&255}}catch(e){throw Error(`DrawIO diagram decompression failed (base64 decode): ${toErrorMessage(e)}`)}let r;try{r=b.inflateRaw(n,{to:`string`})}catch(e){throw Error(`DrawIO diagram decompression failed (inflate): ${toErrorMessage(e)}`)}try{return decodeURIComponent(r)}catch(e){throw Error(`DrawIO diagram decompression failed (URI decode): ${toErrorMessage(e)}`)}}function getFirstDiagram(e){return getAllDiagrams(e)[0]??{name:`index`,id:`likec4-index`,content:``}}function getAllDiagrams(e){let t=[],n=indexOfTagStart(e,`diagram`,0);for(;n!==-1;){let r=findOpenTagEnd(e,n);if(r===-1)break;let i=e.slice(n+8,r).trim(),a=indexOfClosingTag(e,`diagram`,r+1);if(a===-1)break;let o=e.slice(r+1,a),s=getAttr(i,`name`)??(t.length===0?`index`:`diagram_${t.length+1}`),c=getAttr(i,`id`)??`likec4-${s}`,l;if(o.includes(`<mxGraphModel`))l=o;else if(o.trim()===``)l=o;else try{l=decompressDrawioDiagram(o)}catch{l=o}t.push({name:s,id:c,content:l}),n=indexOfTagStart(e,`diagram`,a+10)}return t}function verticesAndEdgesFromCells(e){return{vertices:e.filter(e=>e.vertex&&e.id!==`0`&&e.id!==`1`),edges:e.filter(e=>e.edge&&e.source&&e.target)}}function buildCommonDiagramStateFromCells(e,t){let n=new Map;for(let t of e)n.set(t.id,t);let{vertices:r,edges:i}=verticesAndEdgesFromCells(e),a=new Set([`0`,`1`]),isRootParent=e=>!e||a.has(e),o=new Map,s=new Map;for(let e of r)s.set(e.id,e);let{containerIdToTitle:c,titleCellIds:l}=computeContainerTitles(r),u=r.filter(e=>!l.has(e.id)),d=new Set;assignFqnsToElementVertices(o,u,c,isRootParent,makeUniqueName(d),d);let f=buildHexToCustomName(u,i),p=new Map,m=[];for(let[e,t]of o){let n=s.get(e);if(n)if(isRootParent(n.parent))m.push({cellId:e,fqn:t});else{let r=n.parent==null?void 0:o.get(n.parent);if(r!=null){let n=p.get(r)??[];n.push({cellId:e,fqn:t}),p.set(r,n)}else m.push({cellId:e,fqn:t})}}let h=toId(t?.trim()?t:`index`)||`index`,g=n.get(`1`),_=g?.style?parseStyle(g.style):new Map;return{idToFqn:o,idToCell:s,containerIdToTitle:c,roots:m,children:p,hexToCustomName:f,edges:i,viewId:h,viewTitle:decodeRootStyleField(_.get(`likec4viewtitle`)),viewDesc:decodeRootStyleField(_.get(`likec4viewdescription`)),viewNotation:decodeRootStyleField(_.get(`likec4viewnotation`)),byId:n}}function buildSingleDiagramState(e,t){let n=buildCommonDiagramStateFromCells(e,t),{hexToCustomName:r}=n,i=[];if(r.size>0){i.push(`specification {`);for(let[e,t]of r)i.push(` color ${t} ${e}`);i.push(`}`,``)}return i.push(`model {`,``),{...n,lines:i}}function emitLikeC4SourceFromSingleState(e){let{lines:t,idToCell:n,containerIdToTitle:r,children:i,hexToCustomName:a,byId:o}=e,s={lines:t,idToCell:n,containerIdToTitle:r,children:i,hexToCustomName:a,byId:o};for(let{cellId:t,fqn:n}of e.roots)M.toLines(s,t,n,1);let c=[];for(let t of e.edges.filter(isEdgeWithEndpoints)){let n=e.idToFqn.get(t.source),r=e.idToFqn.get(t.target);n&&r&&c.push({cell:t,src:n,tgt:r})}return emitEdgesToLines(t,c,a),t.push(`}`,``),t.push(...buildViewBlockLines(e.viewId,e.viewTitle,e.viewDesc)),e.viewNotation&&t.push(`// likec4.view.notation ${e.viewId} '${escapeLikec4Quotes(e.viewNotation)}'`),emitRoundtripCommentsSingle(t,e.viewId,e.idToFqn,o,e.edges),t.join(`
4
- `)}function parseDrawioToLikeC4(e){let{name:t,content:n}=getFirstDiagram(e);return emitLikeC4SourceFromSingleState(buildSingleDiagramState(parseDrawioXml(n),t))}function buildDiagramState(e,t){let{byId:n,...r}=buildCommonDiagramStateFromCells(parseDrawioXml(e),t);return r}function mergeDiagramStatesIntoMaps(e){let t=new Map,n=new Map,r=new Map,i=new Map,a=new Map,o=[];for(let s of e){for(let[e,n]of s.idToFqn){let r=s.idToCell.get(e);r&&!t.has(n)&&t.set(n,r)}for(let[e,t]of s.idToCell)n.has(e)||n.set(e,t);for(let[e,t]of s.containerIdToTitle)r.has(e)||r.set(e,t);for(let e of s.edges.filter(isEdgeWithEndpoints)){let t=s.idToFqn.get(e.source),n=s.idToFqn.get(e.target);if(t&&n){let r=`${t}|${n}`;if(i.has(r))continue;i.set(r,{src:t,tgt:n,cell:e})}}for(let[e,t]of s.hexToCustomName)a.has(e)||a.set(e,t);o.push({viewId:s.viewId,viewTitle:s.viewTitle,viewDesc:s.viewDesc,viewNotation:s.viewNotation,fqnSet:new Set(s.idToFqn.values())})}return{fqnToCell:t,byId:n,containerIdToTitle:r,relationKeyToEdge:i,hexToCustomName:a,viewInfos:o}}function buildRootsFromFqnToCell(e){let t=new Map;for(let n of e.keys()){let r=n.includes(`.`)?n.split(`.`).slice(0,-1).join(`.`):``;if(r&&e.has(r)){let e=t.get(r)??[];e.push(n),t.set(r,e)}else{let e=t.get(``)??[];e.push(n),t.set(``,e)}}return{rootsFromMap:t,rootFqns:t.get(``)??[]}}function emitMultiDiagramModel(e,t,n,r){if(t.hexToCustomName.size>0){e.push(`specification {`);for(let[n,r]of t.hexToCustomName)e.push(` color ${r} ${n}`);e.push(`}`,``)}e.push(`model {`,``);let i=new Map;for(let[e,n]of t.fqnToCell)i.set(e,n);let a=new Map;for(let[e,t]of n){if(e===``)continue;let n=t.map(e=>({cellId:e,fqn:e}));n.length>0&&a.set(e,n)}let o={lines:e,idToCell:i,containerIdToTitle:t.containerIdToTitle,children:a,hexToCustomName:t.hexToCustomName,byId:t.byId};for(let e of r)M.toLines(o,e,e,1);let s=[];for(let{src:e,tgt:n,cell:r}of t.relationKeyToEdge.values())s.push({cell:r,src:e,tgt:n});emitEdgesToLines(e,s,t.hexToCustomName),e.push(`}`,``)}function parseDrawioToLikeC4Multi(e){let t=getAllDiagrams(e);if(t.length===0)return`model {
1
+ import{n as e}from"./chunks/rolldown-runtime.mjs";import{n as t,t as n}from"./chunks/newline.mjs";import{CompositeGeneratorNode as r,expandToNode as i,joinToNode as a,toString as o}from"langium/generate";import{filter as s,isEmptyish as c,isNullish as l,isTruthy as u,keys as d,map as f,pipe as p,sort as m,unique as h,values as g}from"remeda";import{LikeC4Styles as _,nonexhaustive as v}from"@likec4/core";import{RichText as y,flattenMarkdownOrString as b}from"@likec4/core/types";import x from"pako";import S from"json5";import{compareNatural as C,invariant as w,sortNaturalByFqn as T}from"@likec4/core/utils";const E=e(e=>e.charAt(0).toLocaleUpperCase()+e.slice(1),`capitalizeFirstLetter`),D=e(e=>e.split(`.`).map(E).join(``),`fqnName`),O=e(e=>D(e.parent?e.id.slice(e.parent.length+1):e.id),`nodeName`),d2direction=({autoLayout:e})=>{switch(e.direction){case`TB`:return`down`;case`BT`:return`up`;case`LR`:return`right`;case`RL`:return`left`}},d2shape=({shape:e})=>{switch(e){case`queue`:case`cylinder`:case`rectangle`:case`document`:return e;case`person`:return`c4-person`;case`storage`:return`stored_data`;case`component`:case`bucket`:case`mobile`:case`browser`:return`rectangle`}};function generateD2(e){let i=e.$view,{nodes:o,edges:s}=i,c=new Map,printNode=(e,t)=>{let i=O(e),s=(t?t+`.`:``)+i;c.set(e.id,s);let l=JSON.stringify(e.title),u=d2shape(e);return new r().append(i,`: {`,n).indent({indentedChildren:t=>t.append(`label: `,l,n).appendIf(u!==`rectangle`,`shape: `,u,n).appendIf(e.children.length>0,n,a(o.filter(t=>t.parent===e.id),e=>printNode(e,s))),indentation:2}).append(`}`,n)},printEdge=e=>new r().append(c.get(e.source),` -> `,c.get(e.target)).append(t=>e.label&&t.append(`: `,JSON.stringify(e.label)));return t(new r().append(`direction: `,d2direction(i),n,n).append(a(o.filter(e=>l(e.parent)),e=>printNode(e),{appendNewLineIfNotEmpty:!0})).appendIf(s.length>0,n,a(s,e=>printEdge(e),{appendNewLineIfNotEmpty:!0})))}const k=`data:page/id,likec4-`,A=`diagrams.drawio`;function escapeXml(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`).replaceAll(`"`,`&quot;`).replaceAll(`'`,`&apos;`)}function decodeXmlEntities(e){return e.replaceAll(`&lt;`,`<`).replaceAll(`&gt;`,`>`).replaceAll(`&quot;`,`"`).replaceAll(`&apos;`,`'`).replaceAll(`&amp;`,`&`)}function toErrorMessage(e){return e instanceof Error?e.message:String(e)}function isEdgeWithEndpoints(e){return e.edge===!0&&typeof e.source==`string`&&typeof e.target==`string`}function isAttrBoundaryChar(e){return e===` `||e===` `||e===`
2
+ `||e===`\r`}function getAttr(e,t){let n=`${t}=`,r=e.toLowerCase(),i=n.toLowerCase(),a=0;for(;a<e.length;){let t=r.indexOf(i,a);if(t===-1)return;if(!isAttrBoundaryChar(t===0?` `:e[t-1]??` `)){a=t+1;continue}let o=t+n.length;if(o<e.length&&e[o]===`"`){let t=e.indexOf(`"`,o+1);if(t!==-1)return e.slice(o+1,t)}a=t+1}}function extractStyleFromAttrsFallback(e){let t=e.toLowerCase(),n=t.indexOf(`style`);for(;n!==-1;){if(!isAttrBoundaryChar(n===0?` `:e[n-1]??` `)){n=t.indexOf(`style`,n+1);continue}let r=n+5;for(;r<e.length&&isAttrBoundaryChar(e[r]??``);)r+=1;if(r<e.length&&e[r]===`=`){for(r+=1;r<e.length&&isAttrBoundaryChar(e[r]??``);)r+=1;if(r<e.length&&e[r]===`"`){let t=r+1,n=e.indexOf(`"`,t);if(n!==-1)return e.slice(t,n)}}n=t.indexOf(`style`,n+1)}}function extractStyleFromOpenTag(e){let t=e.indexOf(`>`);if(t!==-1)return getAttr(e.slice(7,t),`style`)??extractStyleFromAttrsFallback(e.slice(7,t))}const j=1e4;function extractStyleFromTagContent(e,t=1500){let n=e.slice(0,t),r=n.toLowerCase().indexOf(`style="`),i=n.toLowerCase().indexOf(`style='`),a=r!==-1&&(i===-1||r<=i),o=a?r:i,s=o===-1?``:a?`"`:`'`;if(o===-1||!s)return;let c=o+7,l=n.indexOf(s,c);return l===-1?void 0:n.slice(c,l)}function styleOrTagIndicatesActor(e,t){let n=e?.toLowerCase()??``;return n.includes(`shape=actor`)||n.includes(`shape=person`)||n.includes(`umlactor`)||t.includes(`shape=actor`)||t.includes(`shape=person`)||t.includes(`umlactor`)}function findOpenTagEnd(e,t){let n=``,r=t;for(;r<e.length;){let t=e[r];if(t===`"`||t===`'`)n===``?n=t:n===t&&(n=``);else if(t===`>`&&n===``)return r;r+=1}return-1}function indexOfTagStart(e,t,n){let r=e.toLowerCase(),i=`<${t.toLowerCase()}`;return r.indexOf(i,n)}function indexOfClosingTag(e,t,n){let r=e.toLowerCase(),i=`</${t.toLowerCase()}>`;return r.indexOf(i,n)}function parseNum(e){if(e===void 0||e===``)return;let t=Number.parseFloat(e);return Number.isNaN(t)?void 0:t}function getDecodedStyle(e,t){let n=e.get(t);if(n!=null&&n!==``)try{return decodeURIComponent(n)}catch{return n}}function parseStyle(e){let t=new Map;if(!e)return t;for(let n of e.split(`;`)){let e=n.indexOf(`=`);if(e>0){let r=n.slice(0,e).trim(),i=n.slice(e+1).trim();r&&i&&t.set(r.toLowerCase(),i)}}return t}const M=new Set([`likec4description`,`likec4technology`]);function parseAllUserData(e){let t={},n=0;for(;;){let r=indexOfTagStart(e,`data`,n);if(r===-1)break;let i=findOpenTagEnd(e,r);if(i===-1)break;let a=getAttr(e.slice(r,i+1),`key`)?.trim(),o=indexOfClosingTag(e,`data`,i+1);if(o===-1)break;let s=e.slice(i+1,o).trim();a&&(t[a]=decodeXmlEntities(s)),n=o+7}return t}function extractMxGeometryOpenTag(e){let t=indexOfTagStart(e,`mxGeometry`,0);if(t===-1)return``;let n=findOpenTagEnd(e,t);return n===-1?``:e.slice(t,n+1)}function extractMxGeometryInner(e){let t=indexOfTagStart(e,`mxGeometry`,0);if(t===-1)return;let n=findOpenTagEnd(e,t);if(n===-1)return;let r=indexOfClosingTag(e,`mxGeometry`,n+1);if(r!==-1)return e.slice(n+1,r)}function parseEdgePoints(e){let t=extractMxGeometryInner(e);if(t===void 0)return;let n=[],r=0;for(;;){let e=indexOfTagStart(t,`mxPoint`,r);if(e===-1)break;let i=findOpenTagEnd(t,e);if(i===-1)break;let a=t.slice(e,i+1),o=parseNum(getAttr(a,`x`)),s=parseNum(getAttr(a,`y`));o!==void 0&&s!==void 0&&n.push([o,s]),r=i+1}if(n.length!==0)return JSON.stringify(n)}function parseUserData(e){let t=parseAllUserData(e),n={};t.likec4Description!=null&&(n.description=t.likec4Description),t.likec4Technology!=null&&(n.technology=t.likec4Technology);let r={};for(let[e,n]of Object.entries(t))!M.has(e.toLowerCase())&&n!=null&&n!==``&&(r[e]=n);return Object.keys(r).length>0&&(n.customData=JSON.stringify(r)),n}function navigateToFromLink(e){if(!(!e||e===``)&&e.toLowerCase().startsWith(`data:page/id,likec4-`))return e.slice(20).trim()}function buildCellOptionalFields(e){let{styleMap:t,userData:n,geomStr:r,fullTag:i,vertex:a,edge:o,navigateTo:s}=e,c=parseNum(getAttr(r,`x`)),l=parseNum(getAttr(r,`y`)),u=parseNum(getAttr(r,`width`)),d=parseNum(getAttr(r,`height`)),f=t.get(`fillcolor`),p=t.get(`strokecolor`),m=n.description??getDecodedStyle(t,`likec4description`),h=n.technology??getDecodedStyle(t,`likec4technology`),g=getDecodedStyle(t,`likec4notes`),_=getDecodedStyle(t,`likec4tags`),v=getDecodedStyle(t,`likec4icon`),y=t.get(`endarrow`),b=t.get(`startarrow`),x=t.get(`dashed`),S=t.get(`dashpattern`),C=getDecodedStyle(t,`likec4summary`),w=getDecodedStyle(t,`likec4links`),T=getDecodedStyle(t,`likec4border`),E=getDecodedStyle(t,`likec4colorname`),D=t.get(`opacity`),O=t.get(`likec4opacity`),k=t.get(`fillopacity`),A=(O!=null&&O!==``?O:void 0)??(D!=null&&D!==``?D:void 0)??(k!=null&&k!==``?k:void 0),j=t.get(`strokewidth`),M=j!=null&&j!==``?j:void 0,N=getDecodedStyle(t,`likec4size`),P=getDecodedStyle(t,`likec4padding`),F=getDecodedStyle(t,`likec4textsize`),I=getDecodedStyle(t,`likec4iconposition`),L=getDecodedStyle(t,`link`),R=getDecodedStyle(t,`likec4relationshipkind`),z=getDecodedStyle(t,`likec4notation`),B=getDecodedStyle(t,`likec4metadata`),V=getDecodedStyle(t,`likec4id`),H=getDecodedStyle(t,`likec4relationid`),U={};e.valueRaw!=null&&e.valueRaw!==``&&(U.value=decodeXmlEntities(e.valueRaw)),e.parent!=null&&e.parent!==``&&(U.parent=e.parent),e.source!=null&&e.source!==``&&(U.source=e.source),e.target!=null&&e.target!==``&&(U.target=e.target),e.style!=null&&e.style!==``?U.style=e.style:e.styleMap.has(`shape`)&&(U.style=`shape=${e.styleMap.get(`shape`)};`),c!==void 0&&(U.x=c),l!==void 0&&(U.y=l),u!==void 0&&(U.width=u),d!==void 0&&(U.height=d),f!==void 0&&(U.fillColor=f),p!==void 0&&(U.strokeColor=p),m!=null&&(U.description=m),h!=null&&(U.technology=h),g!=null&&(U.notes=g),_!=null&&(U.tags=_),s!=null&&(U.navigateTo=s),v!=null&&(U.icon=v),y!=null&&y!==``&&(U.endArrow=y),b!=null&&b!==``&&(U.startArrow=b),x!=null&&x!==``&&(U.dashed=x),S!=null&&S!==``&&(U.dashPattern=S),C!=null&&(U.summary=C),w!=null&&(U.links=w),L!=null&&a&&(U.link=L),T!=null&&(U.border=T),M!=null&&a&&(U.strokeWidth=M),N!=null&&a&&(U.size=N),P!=null&&a&&(U.padding=P),F!=null&&a&&(U.textSize=F),I!=null&&a&&(U.iconPosition=I),E!=null&&(U.colorName=E),A!=null&&(U.opacity=A),R!=null&&(U.relationshipKind=R),z!=null&&(U.notation=z),B!=null&&o&&(U.metadata=B),V!=null&&a&&(U.likec4Id=V),H!=null&&o&&(U.likec4RelationId=H);let W=e.styleMap.get(`shape`)?.trim(),G=e.fullTag.toLowerCase();if((W==null||W===``)&&a&&styleOrTagIndicatesActor(e.style,G)&&(W=`actor`),W!=null&&W!==``&&a&&(U.shapeFromStyle=W),n.customData!=null&&(U.customData=n.customData),o){let e=parseEdgePoints(i);e!=null&&(U.edgePoints=e)}return U}function buildCellFromMxCell(e,t,n,r){let i=r?.id??getAttr(e,`id`);if(!i)return null;let a=getAttr(e,`vertex`)===`1`,o=getAttr(e,`edge`)===`1`,s=getAttr(e,`style`)??extractStyleFromAttrsFallback(e)??extractStyleFromOpenTag(n),c=!s||s.trim()===``,l=n.length<j&&n.toLowerCase().includes(`shape=actor`);if((c||l&&!s?.toLowerCase().includes(`shape=actor`))&&n.length<j){let e=extractStyleFromTagContent(n);e!=null&&(s=e)}let u=extractMxGeometryOpenTag(n),d=parseStyle(s?.trim()||void 0),f=parseUserData(t),p=r?.navigateTo??getDecodedStyle(d,`likec4navigateto`),m=buildCellOptionalFields({valueRaw:getAttr(e,`value`),parent:getAttr(e,`parent`),source:getAttr(e,`source`),target:getAttr(e,`target`),style:s,styleMap:d,userData:f,geomStr:u,fullTag:n,vertex:a,edge:o,navigateTo:p});return{id:i,vertex:a,edge:o,...s!=null&&s!==``?{style:s}:{},...m}}function extractOneMxCell(e,t){let n=findOpenTagEnd(e,t);if(n===-1)return null;let r=e.slice(t+7,n).trim(),i=e.slice(t,n).trimEnd().endsWith(`/`),a=n+1,o,s;if(i)o=``,s=n;else{let t=indexOfClosingTag(e,`mxCell`,a);if(t===-1)return null;o=e.slice(a,t),s=t+9-1}let c=e.slice(t,s+1);return{attrs:r,inner:o,fullTag:c,next:s+1}}function parseDrawioXml(e){let t=[],n=new Set,r=indexOfTagStart(e,`UserObject`,0);for(;r!==-1;){let i=findOpenTagEnd(e,r);if(i===-1)break;let a=e.slice(r,i+1),o=getAttr(a,`id`)?.trim(),s=navigateToFromLink(getAttr(a,`link`)??void 0),c=indexOfClosingTag(e,`UserObject`,i+1);if(c===-1)break;let l=e.slice(i+1,c);if(o){let e=indexOfTagStart(l,`mxCell`,0);if(e!==-1){let r=extractOneMxCell(l,e);if(r){let e=`<mxCell id="${escapeXml(o)}" ${r.attrs}>${l}</mxCell>`,i=buildCellFromMxCell(r.attrs,l,e,s!=null&&s!==``?{id:o,navigateTo:s}:{id:o});i&&(t.push(i),n.add(i.id))}}}r=indexOfTagStart(e,`UserObject`,c+13)}let i=indexOfTagStart(e,`mxCell`,0);for(;i!==-1;){let r=extractOneMxCell(e,i);if(r){let a=getAttr(r.attrs,`id`);if(a&&!n.has(a)){let e=buildCellFromMxCell(r.attrs,r.inner,r.fullTag);e&&(t.push(e),n.add(e.id))}i=indexOfTagStart(e,`mxCell`,r.next)}else i=indexOfTagStart(e,`mxCell`,i+7)}return t}function likec4Arrow(e){if(!(!e||e===``))switch(e.toLowerCase()){case`none`:return`none`;case`block`:return`normal`;case`open`:return`open`;case`diamond`:return`diamond`;case`oval`:return`dot`;default:return`normal`}}function likec4LineType(e,t){if(e===`1`||e===`true`){let e=(t??``).trim();return e===`1 1`||e===`2 2`?`dotted`:`dashed`}}function isActorShapeInStyle(e,t){let n=e?.toLowerCase()??``,r=t?.toLowerCase().trim();return r===`actor`||r===`person`||n.includes(`shape=actor`)||n.includes(`shape=person`)||n.includes(`umlactor`)}function inferKind(e,t,n){let r=e?.toLowerCase()??``;if(isActorShapeInStyle(e,n))return`actor`;switch(!0){case!e&&!n:return t?.style?.toLowerCase().includes(`container=1`)?`component`:`container`;case r.includes(`swimlane`):case r.includes(`container=1`):return`system`;case!!t?.style?.toLowerCase().includes(`container=1`):return`component`;default:return`container`}}function inferShape(e,t){let n=e?.toLowerCase()??``;if(isActorShapeInStyle(e,t))return`person`;if(n.includes(`shape=cylinder`)||n.includes(`cylinder3`))return`cylinder`;if(n.includes(`shape=document`))return`document`;if(n.includes(`shape=rectangle`)&&n.includes(`rounded`))return`rectangle`}function toId(e){return e.trim().replaceAll(/\s+/g,`_`).replaceAll(/[^\w-]/g,``).replace(/^[0-9]/,`_$&`)||`element`}function makeUniqueName(e){return t=>{let n=toId(t||`element`),r=n,i=0;for(;e.has(r);)r=`${n}_${++i}`;return e.add(r),r}}function isValidFqn(e){return e.length!==0&&e.split(`.`).every(e=>/^[a-zA-Z0-9_-]+$/.test(e))}function vertexDepth(e,t,n=new Set){return n.has(e.id)||(n.add(e.id),e.parent==null||!t.has(e.parent))?0:1+vertexDepth(t.get(e.parent),t,n)}function isUsableBridgeId(e,t,n,r,i){if(!isValidFqn(e))return!1;let a=t.parent?n.get(t.parent):void 0;return a===void 0?i(t.parent):e.startsWith(a+`.`)&&e.length>a.length+1}function assignFqnsToElementVertices(e,t,n,r,i,a){let baseName=e=>e.value??n.get(e.id)??e.id,o=new Map(t.map(e=>[e.id,e])),s=[...t].sort((e,t)=>vertexDepth(e,o)-vertexDepth(t,o));for(let t of s){let n=t.likec4Id?.trim();if(n&&isUsableBridgeId(n,t,e,o,r)){e.set(t.id,n);for(let e of n.split(`.`))a.add(e)}}for(let n of t)e.has(n.id)||r(n.parent)&&e.set(n.id,i(baseName(n)));let c=!0;for(;c;){c=!1;for(let n of t){if(e.has(n.id))continue;let t=n.parent?e.get(n.parent):null;t!=null&&(e.set(n.id,`${t}.${i(baseName(n))}`),c=!0)}}for(let n of t)e.has(n.id)||e.set(n.id,i(baseName(n)))}function buildHexToCustomName(e,t){let n=new Map,r=0;for(let t of e){let e=t.fillColor?.trim();if(e&&/^#[0-9A-Fa-f]{3,8}$/.test(e)){if(t.colorName?.trim()){let r=t.colorName.trim().replaceAll(/\s+/g,`_`);n.has(e)||n.set(e,r)}else n.has(e)||n.set(e,`drawio_color_${++r}`)}}let i=0;for(let e of t){let t=e.strokeColor?.trim();t&&/^#[0-9A-Fa-f]{3,8}$/.test(t)&&!n.has(t)&&n.set(t,`drawio_edge_color_${++i}`)}return n}function computeContainerTitles(e){let t=new Map,n=new Set,r=e.filter(e=>e.style?.toLowerCase().includes(`container=1`)&&e.x!=null&&e.y!=null&&e.width!=null&&e.height!=null);for(let i of r){let r=i.width,a=i.height,o=Math.min(40,a*.5)+2,s=e.find(e=>e.id!==i.id&&e.parent===i.id&&(e.style?.toLowerCase().includes(`shape=text`)||e.style?.toLowerCase().includes(`text;`))&&e.x!=null&&e.y!=null&&e.x>=-2&&e.x<=r+2&&e.y>=-2&&e.y<=o);if(s){let e=(s.value??``).trim();e&&(t.set(i.id,stripHtml(e)),n.add(s.id))}}return{containerIdToTitle:t,titleCellIds:n}}function stripTags(e){let t=``,n=0;for(;n<e.length;){let r=e.indexOf(`<`,n);if(r===-1){t+=e.slice(n);break}t+=e.slice(n,r);let i=e.indexOf(`>`,r);i===-1?(t+=`<`,n=r+1):n=i+1}return t}function stripHtml(e){if(!e||e.trim()===``)return``;let t=decodeXmlEntities(e).split(`
3
+ `)[0]??``,n=t.toLowerCase().indexOf(`<br`);return stripTags(n===-1?t:t.slice(0,n)).trim()||``}function escapeLikec4Quotes(e){return e.replaceAll(`'`,`''`)}function decodeRootStyleField(e){if(e==null||e===``)return``;try{return decodeURIComponent(e)}catch{return e}}function buildViewBlockLines(e,t,n){return[`views {`,` view ${e} {`,...t?[` title '${escapeLikec4Quotes(t)}'`]:[],...n?[` description '${escapeLikec4Quotes(n)}'`]:[],` include *`,` }`,`}`,``]}function pushElementHeader(e,t,n,r,i){let a=escapeLikec4Quotes(i);switch(r){case`actor`:e.lines.push(`${t}${n} = actor '${a}'`);break;case`system`:e.lines.push(`${t}${n} = system '${a}'`);break;default:e.lines.push(`${t}${n} = container '${a}'`)}}function pushElementStyleBlock(e,t,n,r){let i=n.border?.trim(),a=n.opacity,o=inferShape(n.style,n.shapeFromStyle),s=n.size?.trim(),c=n.padding?.trim(),l=n.textSize?.trim(),u=n.iconPosition?.trim();if(!r&&!(i&&[`solid`,`dashed`,`dotted`,`none`].includes(i))&&!(a&&/^\d+$/.test(a))&&!o&&!s&&!c&&!l&&!u)return;let d=[];r&&d.push(`color ${r}`),i&&[`solid`,`dashed`,`dotted`,`none`].includes(i)&&d.push(`border ${i}`),a&&/^\d+$/.test(a)&&d.push(`opacity ${a}`),o&&d.push(`shape ${o}`),s&&d.push(`size ${s}`),c&&d.push(`padding ${c}`),l&&d.push(`textSize ${l}`),u&&d.push(`iconPosition ${u}`),d.length>0&&e.lines.push(`${t} style { ${d.join(`, `)} }`)}function formatLinkLines(e,t,n){let r=[];try{let i=e?JSON.parse(e):null;if(Array.isArray(i))for(let e of i)e?.url&&r.push(`${n}link '${escapeLikec4Quotes(String(e.url))}'${e.title?` '${escapeLikec4Quotes(String(e.title))}'`:``}`);r.length===0&&t&&r.push(`${n}link '${escapeLikec4Quotes(t)}'`)}catch{t&&r.push(`${n}link '${escapeLikec4Quotes(t)}'`)}return r}function pushElementLinks(e,t,n,r){let i=`${t} `;for(let t of formatLinkLines(n,r,i))e.lines.push(t)}function elementHasBody(e,t,n,r){return(t?.length??0)>0||!!r.desc||!!r.tech||!!r.notes||!!r.summary||!!r.linksJson||!!r.nativeLink||!!r.notation||r.tagList.length>0||!!n||!!e.border?.trim()||!!e.opacity||!!inferShape(e.style,e.shapeFromStyle)||!!e.size||!!e.padding||!!e.textSize||!!e.iconPosition||!!r.navigateTo||!!r.icon}function pushElementBody(e,t,n,r,i,a,o,s){e.lines.push(`${t}{`),pushElementStyleBlock(e,t,n,o);for(let n of s.tagList)e.lines.push(`${t} #${n.replaceAll(/\s+/g,`_`)}`);if(s.desc&&e.lines.push(`${t} description '${escapeLikec4Quotes(s.desc)}'`),s.tech&&e.lines.push(`${t} technology '${escapeLikec4Quotes(s.tech)}'`),s.summary&&e.lines.push(`${t} summary '${escapeLikec4Quotes(s.summary)}'`),s.notes&&e.lines.push(`${t} notes '${escapeLikec4Quotes(s.notes)}'`),s.notation&&e.lines.push(`${t} notation '${escapeLikec4Quotes(s.notation)}'`),pushElementLinks(e,t,s.linksJson,s.nativeLink),s.navigateTo&&e.lines.push(`${t} navigateTo ${s.navigateTo}`),s.icon&&e.lines.push(`${t} icon '${escapeLikec4Quotes(s.icon)}'`),r&&r.length>0)for(let t of r)N.toLines(e,t.cellId,t.fqn,a+1);e.lines.push(`${t}}`)}function emitElementToLines(e,t,n,r){let i=e.idToCell.get(t);if(!i)return;let a=i.parent?e.byId.get(i.parent):void 0,o=inferKind(i.style,a,i.shapeFromStyle),s=stripHtml(i.value&&i.value.trim()||``)||(e.containerIdToTitle.get(i.id)??e.containerIdToTitle.get(t)??``)||n.split(`.`).pop()||`Element`,c=n.split(`.`).pop(),l=` `.repeat(r),u=i.description?.trim(),d=i.technology?.trim(),f=i.notes?.trim(),p=i.tags?.trim(),m=p?p.split(`,`).map(e=>e.trim()).filter(Boolean):[],h=i.navigateTo?.trim(),g=i.icon?.trim(),_=i.summary?.trim(),v=i.links?.trim(),y=i.link?.trim(),b=i.notation?.trim(),x=i.fillColor&&/^#[0-9A-Fa-f]{3,8}$/.test(i.fillColor.trim())?e.hexToCustomName.get(i.fillColor.trim()):void 0,S=e.children.get(n),C={desc:u,tech:d,notes:f,summary:_,linksJson:v,nativeLink:y,notation:b,tagList:m,navigateTo:h,icon:g},w=elementHasBody(i,S,x,C);pushElementHeader(e,l,c,o,s),w?pushElementBody(e,l,i,S,n,r,x,C):(e.lines.push(`${l}{`),e.lines.push(`${l}}`)),e.lines.push(``)}const N={toLines:emitElementToLines};function emitEdgesToLines(e,t,n){for(let{cell:r,src:i,tgt:a}of t){let t=r.value&&r.value.trim()?escapeLikec4Quotes(r.value.trim()):``,o=r.description?.trim(),s=r.technology?.trim(),c=r.notes?.trim(),l=r.navigateTo?.trim(),u=likec4Arrow(r.endArrow),d=likec4Arrow(r.startArrow),f=likec4LineType(r.dashed,r.dashPattern),p=r.relationshipKind?.trim(),m=r.notation?.trim(),h=r.links?.trim(),g=r.metadata?.trim(),_=r.strokeColor?.trim(),v=!!c||!!l||!!u||!!d||!!f||!!m||!!h||!!g||!!_,y=` ${i}${p&&/^[a-zA-Z0-9_-]+$/.test(p)?` -[${p}]-> `:` -> `}${a}${t?` '${t}'`:o||s?` ''`:``}${o?` '${escapeLikec4Quotes(o)}'`:``}${s?` '${escapeLikec4Quotes(s)}'`:``}`;if(v){let t=[];c&&t.push(` notes '${escapeLikec4Quotes(c)}'`),l&&t.push(` navigateTo ${l}`),m&&t.push(` notation '${escapeLikec4Quotes(m)}'`);for(let e of formatLinkLines(h,void 0,` `))t.push(e);try{let e=g?JSON.parse(g):null;if(typeof e==`object`&&e&&!Array.isArray(e)){let n=[];for(let[t,r]of Object.entries(e)){if(t.trim()===``)continue;let e=/^[a-zA-Z_]\w*$/.test(t)?t:`'${escapeLikec4Quotes(t)}'`;if(Array.isArray(r)){let t=r.map(e=>`'${escapeLikec4Quotes(String(e))}'`);n.push(` ${e} [ ${t.join(`, `)} ];`)}else r!=null&&typeof r==`string`&&n.push(` ${e} '${escapeLikec4Quotes(r)}';`)}n.length>0&&t.push(` metadata {`+n.join(``)+` }`)}}catch{}if(u||d||f||_){let e=[];if(f&&e.push(`line ${f}`),u&&e.push(`head ${u}`),d&&e.push(`tail ${d}`),_&&/^#[0-9A-Fa-f]{3,8}$/.test(_)){let t=n.get(_);t&&e.push(`color ${t}`)}e.length>0&&t.push(` style { ${e.join(`, `)} }`)}e.push(y+` {`,...t,` }`)}else e.push(y)}}function collectRoundtripForState(e,t,n,r){let i={},a=[],o=[],s=[],c=[];for(let[e,r]of t){let t=n.get(e);t?.vertex&&t.x!=null&&t.y!=null&&t.width!=null&&t.height!=null&&(i[r]={x:t.x,y:t.y,width:t.width,height:t.height}),t?.vertex&&(t.strokeColor?.trim()&&/^#[0-9A-Fa-f]{3,8}$/.test(t.strokeColor.trim())&&a.push(`// ${r}=${t.strokeColor.trim()}`),t.strokeWidth!=null&&t.strokeWidth.trim()!==``&&o.push(`// ${r}=${t.strokeWidth.trim()}`)),t?.customData?.trim()&&s.push(`// ${r} ${t.customData.trim()}`)}let l=r.filter(isEdgeWithEndpoints);for(let e of l){let n=t.get(e.source),r=t.get(e.target);n&&r&&(e.customData?.trim()&&s.push(`// ${n}|${r} ${e.customData.trim()}`),e.edgePoints?.trim()&&c.push(`// ${n}|${r}|${e.id} ${e.edgePoints.trim()}`))}return{layoutNodes:i,strokeColorLines:a,strokeWidthLines:o,customDataLines:s,waypointLines:c}}function emitRoundtripCommentsSingle(e,t,n,r,i){let a=collectRoundtripForState(t,n,r,i);Object.keys(a.layoutNodes).length>0&&e.push(`// <likec4.layout.drawio>`,`// `+JSON.stringify({[t]:{nodes:a.layoutNodes}}),`// </likec4.layout.drawio>`),a.strokeColorLines.length>0&&e.push(`// <likec4.strokeColor.vertices>`,...a.strokeColorLines,`// </likec4.strokeColor.vertices>`),a.strokeWidthLines.length>0&&e.push(`// <likec4.strokeWidth.vertices>`,...a.strokeWidthLines,`// </likec4.strokeWidth.vertices>`),a.customDataLines.length>0&&e.push(`// <likec4.customData>`,...a.customDataLines,`// </likec4.customData>`),a.waypointLines.length>0&&e.push(`// <likec4.edge.waypoints>`,...a.waypointLines,`// </likec4.edge.waypoints>`)}function emitRoundtripCommentsMulti(e,t){let n={},r=[],i=[],a=[],o=[];for(let e of t){let t=collectRoundtripForState(e.viewId,e.idToFqn,e.idToCell,e.edges);n[e.viewId]={nodes:t.layoutNodes},r.push(...t.strokeColorLines),i.push(...t.strokeWidthLines),a.push(...t.customDataLines),o.push(...t.waypointLines)}Object.values(n).some(e=>e!=null&&Object.keys(e.nodes).length>0)&&e.push(`// <likec4.layout.drawio>`,`// `+JSON.stringify(n),`// </likec4.layout.drawio>`),r.length>0&&e.push(`// <likec4.strokeColor.vertices>`,...r,`// </likec4.strokeColor.vertices>`),i.length>0&&e.push(`// <likec4.strokeWidth.vertices>`,...i,`// </likec4.strokeWidth.vertices>`),a.length>0&&e.push(`// <likec4.customData>`,...a,`// </likec4.customData>`),o.length>0&&e.push(`// <likec4.edge.waypoints>`,...o,`// </likec4.edge.waypoints>`)}function decompressDrawioDiagram(e){let t=e.trim(),n;try{if(typeof Buffer<`u`)n=new Uint8Array(Buffer.from(t,`base64`));else{let e=atob(t);n=new Uint8Array(e.length);for(let t=0;t<e.length;t++)n[t]=e.charCodeAt(t)&255}}catch(e){throw Error(`DrawIO diagram decompression failed (base64 decode): ${toErrorMessage(e)}`)}let r;try{r=x.inflateRaw(n,{to:`string`})}catch(e){throw Error(`DrawIO diagram decompression failed (inflate): ${toErrorMessage(e)}`)}try{return decodeURIComponent(r)}catch(e){throw Error(`DrawIO diagram decompression failed (URI decode): ${toErrorMessage(e)}`)}}function getFirstDiagram(e){return getAllDiagrams(e)[0]??{name:`index`,id:`likec4-index`,content:``}}function getAllDiagrams(e){let t=[],n=indexOfTagStart(e,`diagram`,0);for(;n!==-1;){let r=findOpenTagEnd(e,n);if(r===-1)break;let i=e.slice(n+8,r).trim(),a=indexOfClosingTag(e,`diagram`,r+1);if(a===-1)break;let o=e.slice(r+1,a),s=getAttr(i,`name`)??(t.length===0?`index`:`diagram_${t.length+1}`),c=getAttr(i,`id`)??`likec4-${s}`,l;if(o.includes(`<mxGraphModel`))l=o;else if(o.trim()===``)l=o;else try{l=decompressDrawioDiagram(o)}catch{l=o}t.push({name:s,id:c,content:l}),n=indexOfTagStart(e,`diagram`,a+10)}return t}function verticesAndEdgesFromCells(e){return{vertices:e.filter(e=>e.vertex&&e.id!==`0`&&e.id!==`1`),edges:e.filter(e=>e.edge&&e.source&&e.target)}}function buildCommonDiagramStateFromCells(e,t){let n=new Map;for(let t of e)n.set(t.id,t);let{vertices:r,edges:i}=verticesAndEdgesFromCells(e),a=new Set([`0`,`1`]),isRootParent=e=>!e||a.has(e),o=new Map,s=new Map;for(let e of r)s.set(e.id,e);let{containerIdToTitle:c,titleCellIds:l}=computeContainerTitles(r),u=r.filter(e=>!l.has(e.id)),d=new Set;assignFqnsToElementVertices(o,u,c,isRootParent,makeUniqueName(d),d);let f=buildHexToCustomName(u,i),p=new Map,m=[];for(let[e,t]of o){let n=s.get(e);if(n){if(isRootParent(n.parent))m.push({cellId:e,fqn:t});else{let r=n.parent==null?void 0:o.get(n.parent);if(r!=null){let n=p.get(r)??[];n.push({cellId:e,fqn:t}),p.set(r,n)}else m.push({cellId:e,fqn:t})}}}let h=toId(t?.trim()?t:`index`)||`index`,g=n.get(`1`),_=g?.style?parseStyle(g.style):new Map;return{idToFqn:o,idToCell:s,containerIdToTitle:c,roots:m,children:p,hexToCustomName:f,edges:i,viewId:h,viewTitle:decodeRootStyleField(_.get(`likec4viewtitle`)),viewDesc:decodeRootStyleField(_.get(`likec4viewdescription`)),viewNotation:decodeRootStyleField(_.get(`likec4viewnotation`)),byId:n}}function buildSingleDiagramState(e,t){let n=buildCommonDiagramStateFromCells(e,t),{hexToCustomName:r}=n,i=[];if(r.size>0){i.push(`specification {`);for(let[e,t]of r)i.push(` color ${t} ${e}`);i.push(`}`,``)}return i.push(`model {`,``),{...n,lines:i}}function emitLikeC4SourceFromSingleState(e){let{lines:t,idToCell:n,containerIdToTitle:r,children:i,hexToCustomName:a,byId:o}=e,s={lines:t,idToCell:n,containerIdToTitle:r,children:i,hexToCustomName:a,byId:o};for(let{cellId:t,fqn:n}of e.roots)N.toLines(s,t,n,1);let c=[];for(let t of e.edges.filter(isEdgeWithEndpoints)){let n=e.idToFqn.get(t.source),r=e.idToFqn.get(t.target);n&&r&&c.push({cell:t,src:n,tgt:r})}return emitEdgesToLines(t,c,a),t.push(`}`,``),t.push(...buildViewBlockLines(e.viewId,e.viewTitle,e.viewDesc)),e.viewNotation&&t.push(`// likec4.view.notation ${e.viewId} '${escapeLikec4Quotes(e.viewNotation)}'`),emitRoundtripCommentsSingle(t,e.viewId,e.idToFqn,o,e.edges),t.join(`
4
+ `)}function parseDrawioToLikeC4(e){let{name:t,content:n}=getFirstDiagram(e);return emitLikeC4SourceFromSingleState(buildSingleDiagramState(parseDrawioXml(n),t))}function buildDiagramState(e,t){let{byId:n,...r}=buildCommonDiagramStateFromCells(parseDrawioXml(e),t);return r}function mergeDiagramStatesIntoMaps(e){let t=new Map,n=new Map,r=new Map,i=new Map,a=new Map,o=[];for(let s of e){for(let[e,n]of s.idToFqn){let r=s.idToCell.get(e);r&&!t.has(n)&&t.set(n,r)}for(let[e,t]of s.idToCell)n.has(e)||n.set(e,t);for(let[e,t]of s.containerIdToTitle)r.has(e)||r.set(e,t);for(let e of s.edges.filter(isEdgeWithEndpoints)){let t=s.idToFqn.get(e.source),n=s.idToFqn.get(e.target);if(t&&n){let r=`${t}|${n}`;if(i.has(r))continue;i.set(r,{src:t,tgt:n,cell:e})}}for(let[e,t]of s.hexToCustomName)a.has(e)||a.set(e,t);o.push({viewId:s.viewId,viewTitle:s.viewTitle,viewDesc:s.viewDesc,viewNotation:s.viewNotation,fqnSet:new Set(s.idToFqn.values())})}return{fqnToCell:t,byId:n,containerIdToTitle:r,relationKeyToEdge:i,hexToCustomName:a,viewInfos:o}}function buildRootsFromFqnToCell(e){let t=new Map;for(let n of e.keys()){let r=n.includes(`.`)?n.split(`.`).slice(0,-1).join(`.`):``;if(r&&e.has(r)){let e=t.get(r)??[];e.push(n),t.set(r,e)}else{let e=t.get(``)??[];e.push(n),t.set(``,e)}}return{rootsFromMap:t,rootFqns:t.get(``)??[]}}function emitMultiDiagramModel(e,t,n,r){if(t.hexToCustomName.size>0){e.push(`specification {`);for(let[n,r]of t.hexToCustomName)e.push(` color ${r} ${n}`);e.push(`}`,``)}e.push(`model {`,``);let i=new Map;for(let[e,n]of t.fqnToCell)i.set(e,n);let a=new Map;for(let[e,t]of n){if(e===``)continue;let n=t.map(e=>({cellId:e,fqn:e}));n.length>0&&a.set(e,n)}let o={lines:e,idToCell:i,containerIdToTitle:t.containerIdToTitle,children:a,hexToCustomName:t.hexToCustomName,byId:t.byId};for(let e of r)N.toLines(o,e,e,1);let s=[];for(let{src:e,tgt:n,cell:r}of t.relationKeyToEdge.values())s.push({cell:r,src:e,tgt:n});emitEdgesToLines(e,s,t.hexToCustomName),e.push(`}`,``)}function parseDrawioToLikeC4Multi(e){let t=getAllDiagrams(e);if(t.length===0)return`model {
5
5
 
6
6
  }
7
7
  views {
@@ -11,10 +11,10 @@ views {
11
11
  }
12
12
  `;if(t.length===1){let e=t[0];return emitLikeC4SourceFromSingleState(buildSingleDiagramState(parseDrawioXml(e.content),e.name))}let n=[];for(let e of t){let t=buildDiagramState(e.content,e.name);t&&n.push(t)}if(n.length===0)return parseDrawioToLikeC4(e);let r=mergeDiagramStatesIntoMaps(n),{rootsFromMap:i,rootFqns:a}=buildRootsFromFqnToCell(r.fqnToCell),o=[];emitMultiDiagramModel(o,r,i,a),o.push(`views {`);for(let e of r.viewInfos){let t=[...e.fqnSet].sort((e,t)=>e.localeCompare(t));o.push(` view ${e.viewId} {`,...e.viewTitle?[` title '${escapeLikec4Quotes(e.viewTitle)}'`]:[],...e.viewDesc?[` description '${escapeLikec4Quotes(e.viewDesc)}'`]:[],` include ${t.length>0?t.join(`, `):`*`}`,` }`)}o.push(`}`,``);for(let e of r.viewInfos)e.viewNotation&&o.push(`// likec4.view.notation ${e.viewId} '${escapeLikec4Quotes(e.viewNotation)}'`);return emitRoundtripCommentsMulti(o,n),o.join(`
13
13
  `)}function parseDrawioRoundtripComments(e){let t=e.split(/\r?\n/),n={},r={},i={},a={},o=!1,s=0;for(;s<t.length;){let e=t[s];if(e==null){s+=1;continue}if(e.trim()===`// <likec4.layout.drawio>`){o=!0,s+=1;let e=[];for(;s<t.length&&t[s]?.trim()!==`// </likec4.layout.drawio>`;){let n=t[s]?.trim();n?.startsWith(`// `)&&e.push(n.slice(3)),s+=1}if(e.length>0)try{let t=e.join(`
14
- `);n=JSON.parse(t)}catch{}s+=1;continue}if(e.trim()===`// <likec4.strokeColor.vertices>`){for(o=!0,s+=1;s<t.length&&t[s]?.trim()!==`// </likec4.strokeColor.vertices>`;){let e=t[s]?.trim();if(e?.startsWith(`// `)&&e.includes(`=`)){let t=e.slice(3).trim(),n=t.indexOf(`=`);if(n>0){let e=t.slice(0,n).trim(),i=t.slice(n+1).trim();e&&i&&(r[e]=i)}}s+=1}s+=1;continue}if(e.trim()===`// <likec4.strokeWidth.vertices>`){for(o=!0,s+=1;s<t.length&&t[s]?.trim()!==`// </likec4.strokeWidth.vertices>`;){let e=t[s]?.trim();if(e?.startsWith(`// `)&&e.includes(`=`)){let t=e.slice(3).trim(),n=t.indexOf(`=`);if(n>0){let e=t.slice(0,n).trim(),r=t.slice(n+1).trim();e&&r!==``&&(i[e]=r)}}s+=1}s+=1;continue}if(e.trim()===`// <likec4.edge.waypoints>`){for(o=!0,s+=1;s<t.length&&t[s]?.trim()!==`// </likec4.edge.waypoints>`;){let e=t[s]?.trim();if(e?.startsWith(`// `)){let t=e.slice(3).trim(),n=t.indexOf(` `);if(n>0){let e=t.slice(0,n).trim(),r=t.slice(n+1).trim();if(e&&r)try{let t=JSON.parse(r);Array.isArray(t)&&(a[e]=t)}catch{}}}s+=1}s+=1;continue}s+=1}return o?{layoutByView:n,strokeColorByFqn:r,strokeWidthByFqn:i,edgeWaypoints:a}:null}function compressDrawioDiagramXml(e){let t=encodeURIComponent(e),n=new TextEncoder().encode(t);return uint8ArrayToBase64(b.deflateRaw(n))}function uint8ArrayToBase64(e){if(typeof Buffer<`u`)return Buffer.from(e).toString(`base64`);let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}const N={getNotes(e){return e.notes},getSummary(e){return e.summary},getTags(e){return e.tags},getNavigateTo(e){return e.navigateTo},getIcon(e){return e.icon},getLinks(e){return e.links},getNotation(e){return e.notation},getCustomData(e){return e.customData},getChildren(e){return e.children}},P={getKind(e){return e.kind},getNotation(e){return e.notation},getLinks(e){return e.links},getMetadata(e){return e.metadata},getCustomData(e){return e.customData}};function getEffectiveStyles(e){return e.$styles??g.DEFAULT}function escapeHtml(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`).replaceAll(`"`,`&quot;`)}function toNonEmptyString(e){if(e==null)return``;let t=typeof e;if(t===`string`){let t=e;return t.trim()===``?``:t}return t===`number`||t===`boolean`?String(e):``}function getContainerDashedStyle(e,t){return e&&t!==`none`||t===`dashed`?`dashed=1;`:``}function getDefaultStrokeWidth(e,t){return e===`none`?`0`:t||e?`1`:``}function applyStrokeColorOverride(e,t){return{fill:e?.fill??`#dae8fc`,stroke:t,font:e?.font??t}}function resolveThemeColor(e,t,n){return t&&t in e.theme.colors?t:n}function getThemeColorValues(e,t,n){let r=getEffectiveStyles(e),i=resolveThemeColor(r,t??n,n);try{return r.colors(i)}catch{return g.DEFAULT.colors(n)}}function drawioShape(e){let t=`shape=rectangle;rounded=1;arcSize=12;`;switch(e){case`person`:return`shape=actor;`;case`rectangle`:case`browser`:case`mobile`:case`bucket`:return t;case`cylinder`:case`queue`:case`storage`:return`shape=cylinder3;whiteSpace=wrap;boundedLbl=1;backgroundOutline=1;size=15;`;case`document`:return`shape=document;whiteSpace=wrap;html=1;boundedLbl=1;`;case`component`:return`shape=component;`;default:return t}}function getElementColors(e,t){let n=getThemeColorValues(e,t,`primary`).elements;return{fill:String(n.fill??`#dae8fc`),stroke:String(n.stroke??`#2563eb`),font:String(n.hiContrast??n.stroke??`#1e40af`)}}function getEdgeStrokeColor(e,t){let n=getThemeColorValues(e,t??`gray`,`gray`);return String(n.relationships?.line??`#1e40af`)}function getEdgeLabelColors(e,t){let n=getThemeColorValues(e,t??`gray`,`gray`).relationships;return{font:String(n?.label??n?.line??`#1e40af`),background:String(n?.labelBg??`#ffffff`)}}function edgeAnchors(e,t){let n=e.x+e.width/2,r=e.y+e.height/2,i=t.x+t.width/2,a=t.y+t.height/2,o=i-n,s=a-r,c=Math.abs(o)>=Math.abs(s);return{exitX:c?+(o>=0):.5,exitY:c?.5:+(s>=0),entryX:c?o>=0?0:1:.5,entryY:c?.5:s>=0?0:1}}function normalizeEdgePoint(e){if(Array.isArray(e)&&e.length>=2&&typeof e[0]==`number`&&typeof e[1]==`number`)return[[e[0],e[1]]];let t=e;return typeof t.x==`number`&&typeof t.y==`number`?[[t.x,t.y]]:[]}function buildNodeValueHtml(e,t,n,r,i,a){return n?``:t===``?`<div style="box-sizing:border-box;width:100%;min-height:100%;display:flex;align-items:center;justify-content:center;text-align:center;color:${r};font-family:${i};"><b style="font-size:${a}px;">${escapeHtml(e)}</b></div>`:`<div style="box-sizing:border-box;width:100%;min-height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;color:${r};font-family:${i};"><b style="font-size:${a}px;">${escapeHtml(e)}</b><br/><span style="font-weight:normal;font-size:${a}px;">${escapeHtml(t)}</span></div>`}function pushStylePart(e,t,n){n!=null&&n!==``&&e.push(`${t}=${encodeURIComponent(n)}`)}function pushStylePartNum(e,t,n){n!=null&&e.push(`${t}=${n}`)}function buildNavLinkStyle(e){return e===``?``:`link=${encodeURIComponent(`${O}${e}`)};`}function toExportString(e){let t=e==null?null:y(e);return t!=null&&!s(t)?t.trim():``}function linksToStyleJson(e){return!Array.isArray(e)||e.length===0?``:encodeURIComponent(JSON.stringify(e.map(e=>({url:e.url,title:e.title}))))}function metadataToStyleJson(e){return typeof e!=`object`||!e||Array.isArray(e)||Object.keys(e).length===0?``:encodeURIComponent(JSON.stringify(e))}const F=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{4}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/;function buildLikec4StyleForNode(e){let t=[];return pushStylePart(t,`likec4Description`,e.desc),pushStylePart(t,`likec4Technology`,e.tech),pushStylePart(t,`likec4Notes`,e.notes),pushStylePart(t,`likec4Tags`,e.tagList),pushStylePart(t,`likec4NavigateTo`,e.navTo),pushStylePart(t,`likec4Icon`,e.iconName),pushStylePart(t,`likec4Summary`,e.summaryStr),e.linksJson!==``&&t.push(`likec4Links=${e.linksJson}`),pushStylePart(t,`likec4Border`,e.borderVal),pushStylePartNum(t,`likec4Opacity`,e.containerOpacityNum),pushStylePart(t,`likec4StrokeWidth`,e.strokeWidth),e.colorNameForRoundtrip!==``&&t.push(`likec4ColorName=${e.colorNameForRoundtrip}`),pushStylePart(t,`likec4Size`,e.nodeStyle?.size),pushStylePart(t,`likec4Padding`,e.nodeStyle?.padding),pushStylePart(t,`likec4TextSize`,e.nodeStyle?.textSize),pushStylePart(t,`likec4IconPosition`,e.nodeStyle?.iconPosition),e.strokeHex&&F.test(e.strokeHex)&&pushStylePart(t,`likec4StrokeColor`,e.strokeHex),pushStylePart(t,`likec4Notation`,e.nodeNotation??void 0),t.length>0?t.join(`;`)+`;`:``}function buildBridgeManagedStyleForNode(e,t,n,r){if(r?.profile!==`leanix`)return``;let i=[`bridgeManaged=true`,`likec4Id=${encodeURIComponent(e)}`,`likec4Kind=${encodeURIComponent(t)}`,`likec4ViewId=${encodeURIComponent(n)}`];r.projectId!=null&&r.projectId!==``&&i.push(`likec4ProjectId=${encodeURIComponent(r.projectId)}`);let a=r.leanixFactSheetTypeByKind?.[t];return a!=null&&a!==``&&i.push(`leanixFactSheetType=${encodeURIComponent(a)}`),i.join(`;`)+`;`}function buildBridgeManagedStyleForEdge(e,t){return t?.profile===`leanix`?`bridgeManaged=true;likec4RelationId=${encodeURIComponent(e)};`:``}function buildMxUserObjectXml(e){return!e||typeof e!=`object`||Array.isArray(e)||Object.keys(e).length===0?``:`
15
- <mxUserObject>`+Object.entries(e).map(([e,t])=>{let n=typeof t==`string`?t:t==null?``:String(t);return`<data key="${escapeXml(e)}">${escapeXml(n)}</data>`}).join(``)+`</mxUserObject>`}function buildLikec4StyleForEdge(e){let t=[];return pushStylePart(t,`likec4Description`,e.edgeDesc),pushStylePart(t,`likec4Technology`,e.edgeTech),pushStylePart(t,`likec4Notes`,e.edgeNotes),pushStylePart(t,`likec4NavigateTo`,e.edgeNavTo),pushStylePart(t,`likec4RelationshipKind`,e.edgeKind??void 0),pushStylePart(t,`likec4Notation`,e.edgeNotation??void 0),e.edgeLinksJson!==``&&t.push(`likec4Links=${e.edgeLinksJson}`),e.edgeMetadataJson!==``&&t.push(`likec4Metadata=${e.edgeMetadataJson}`),t.length>0?t.join(`;`)+`;`:``}function buildEdgeLabelValue(e){return e.label?escapeXml(e.label):``}function buildEdgeGeometryXml(e,t){let n=t?.[`${e.source}|${e.target}|${e.id}`]??t?.[`${e.source}|${e.target}`],r=Array.isArray(n)?n.flatMap(normalizeEdgePoint):[];return r.length>0?`<mxGeometry relative="1" as="geometry">${`<Array as="points">`+r.map(([e,t])=>`<mxPoint x="${Math.round(e)}" y="${Math.round(t)}"/>`).join(``)+`</Array>`}</mxGeometry>`:`<mxGeometry relative="1" as="geometry" />`}function buildEdgeStyleString(e,t,n,r,i){let{bboxes:a,fontFamily:o}=t,s=a.get(e.source),c=a.get(e.target),l=s&&c?edgeAnchors(s,c):{exitX:1,exitY:.5,entryX:0,entryY:.5},u=`exitX=${l.exitX};exitY=${l.exitY};entryX=${l.entryX};entryY=${l.entryY};`,d=getEdgeStrokeColor(n,e.color),f=e.line===`dashed`?`dashed=1;`:e.line===`dotted`?`dashed=1;dashPattern=1 1;`:``,p=drawioArrow(e.head),m=e.tail==null||e.tail===`none`?`none`:drawioArrow(e.tail),h=buildLikec4StyleForEdge({edgeDesc:toExportString(e.description),edgeTech:toExportString(e.technology),edgeNotes:toExportString(e.notes),edgeNavTo:toNonEmptyString(e.navigateTo),edgeKind:P.getKind(e),edgeNotation:P.getNotation(e),edgeLinksJson:linksToStyleJson(P.getLinks(e)),edgeMetadataJson:metadataToStyleJson(P.getMetadata(e))}),g=buildBridgeManagedStyleForEdge(e.id,i),_=getEdgeLabelColors(n,e.color);return`endArrow=${p};startArrow=${m};html=1;rounded=0;${u}strokeColor=${d};strokeWidth=2;${f}${r===``?``:`fontColor=${_.font};fontSize=12;align=center;verticalAlign=middle;labelBackgroundColor=none;fontFamily=${encodeURIComponent(o)};`}${h}${g}`}function buildEdgeCellXml(e,t,n,r,i,a){let{defaultParentId:o}=t,s=i(e.source),c=i(e.target),l=buildEdgeLabelValue(e),u=buildEdgeGeometryXml(e,n?.edgeWaypoints);return`<mxCell id="${a}" value="${l}" style="${buildEdgeStyleString(e,t,r,l,n)}" edge="1" parent="${o}" source="${s}" target="${c}">
16
- ${u}${buildMxUserObjectXml(P.getCustomData(e))}
17
- </mxCell>`}function computeNodeGeometry(e,t,n){let{bboxes:r,defaultParentId:i,nodeIdsInView:a}=t,o=n(e.id),s=r.get(e.id),{width:c,height:l}=s,u=e.parent!=null&&a.has(e.parent)?n(e.parent):i,d=e.parent==null?void 0:r.get(e.parent);return{id:o,parentId:u,x:d==null?s.x+t.offsetX:s.x-d.x,y:d==null?s.y+t.offsetY:s.y-d.y,width:c,height:l}}function computeNodeStylePartsAndValue(e,t,n,r){let{containerNodeIds:i,effectiveStyles:a,fontFamily:o,containerTitleFontSizePx:s,containerTitleColor:c}=t,l=n?.strokeColorByNodeId,u=n?.strokeWidthByNodeId,d=i.has(e.id),f=e.kind??``,p=e.title,m=toExportString(e.description),h=toExportString(e.technology),g=toExportString(N.getNotes(e)),_=N.getTags(e),v=Array.isArray(_)&&_.length>0?_.join(`,`):``,y=toNonEmptyString(N.getNavigateTo(e)),b=toNonEmptyString(N.getIcon(e)),x=f===`actor`||e.shape===`person`,S=d?`shape=rectangle;rounded=0;container=1;collapsible=0;startSize=0;`:x?`shape=actor;`:drawioShape(e.shape),C=l?.[e.id],w=u?.[e.id],T=C?applyStrokeColorOverride(getElementColors(r,e.color),C):getElementColors(r,e.color),E=T?.fill??`#dae8fc`,D=T?.stroke??`#2563eb`,O=T?.font??T?.stroke??`#1e40af`,k=`fillColor=${E};strokeColor=${D};fontColor=${O};`,A=e.style,j=a.fontSize(A?.textSize),M=escapeXml(buildNodeValueHtml(p,m,d,O,o,j)),P=A?.border,F=w??getDefaultStrokeWidth(P,d),I=F===``?``:`strokeWidth=${F};`,L=getContainerDashedStyle(d,P),R=d===!0?A?.opacity??15:void 0,z=R!=null&&d===!0?`fillOpacity=${Math.min(100,Math.max(0,R))};`:``,B=buildLikec4StyleForNode({desc:m,tech:h,notes:g,tagList:v,navTo:y,iconName:b,summaryStr:toExportString(N.getSummary(e)),linksJson:linksToStyleJson(N.getLinks(e)),borderVal:P,containerOpacityNum:R,strokeWidth:F,colorNameForRoundtrip:e.color?encodeURIComponent(String(e.color)):``,nodeStyle:A,strokeHex:D,nodeNotation:N.getNotation(e)})+buildBridgeManagedStyleForNode(e.id,f,t.view.id,n),V=buildMxUserObjectXml(N.getCustomData(e)),H=buildNavLinkStyle(y);return{value:M,styleStr:`${d?`align=left;verticalAlign=top;overflow=fill;whiteSpace=wrap;html=1;`:`align=center;verticalAlign=middle;verticalLabelPosition=middle;labelPosition=center;fontSize=${j};fontStyle=1;spacingTop=4;spacingLeft=2;spacingRight=2;spacingBottom=2;overflow=fill;whiteSpace=wrap;html=1;fontFamily=${encodeURIComponent(o)};`}${S}${k}${I}${L}${z}${H}${B}`,userObjectXml:V,navTo:y,isContainer:d,title:p,fontFamily:o,containerTitleFontSizePx:s,containerTitleColor:c}}function computeNodeCellExportData(e,t,n,r,i,a){let o=computeNodeGeometry(e,t,i),s=computeNodeStylePartsAndValue(e,t,n,r);return{...o,value:s.value,styleStr:s.styleStr,userObjectXml:s.userObjectXml,navTo:s.navTo,isContainer:s.isContainer,fontFamily:s.fontFamily,...s.isContainer&&{title:s.title??``,titleCellId:String(a),containerTitleFontSizePx:s.containerTitleFontSizePx,containerTitleColor:s.containerTitleColor}}}function buildNodeCellXml(e){let t=`<mxGeometry height="${Math.round(e.height)}" width="${Math.round(e.width)}" x="${Math.round(e.x)}" y="${Math.round(e.y)}" as="geometry" />`,n=e.userObjectXml===``?`\n ${t}`:`${e.userObjectXml}\n ${t}`,r=e.isContainer&&e.title!=null?escapeXml(e.title):e.value,i=e.navTo===``?`<mxCell id="${e.id}" value="${e.value}" style="${e.styleStr}" vertex="1" parent="${e.parentId}">\n ${n}\n</mxCell>`:`<UserObject label="${r}" link="${O}${escapeXml(e.navTo)}" id="${e.id}">\n <mxCell parent="${e.parentId}" style="${e.styleStr}" value="${e.value}" vertex="1">\n ${n}\n</mxCell>\n</UserObject>`;return e.isContainer?{vertexXml:i,titleCellXml:buildContainerTitleCellXml(e.title??``,e.titleCellId??e.id,e.navTo,e.id,e.fontFamily,e.containerTitleFontSizePx??12,e.containerTitleColor??`#74c0fc`),isContainer:!0}:{vertexXml:i,isContainer:!1}}function buildContainerTitleCellXml(e,t,n,r,i,a,o){let s=escapeXml(e),c=Math.max(60,Math.min(260,e.length*8)),l=buildNavLinkStyle(n),u=`shape=text;html=1;fillColor=none;strokeColor=none;align=left;verticalAlign=top;fontSize=${a};fontStyle=1;fontColor=${o};fontFamily=${encodeURIComponent(i)};${l}`;if(n===``)return`<mxCell id="${t}" value="${s}" style="${u}" vertex="1" parent="${r}">\n <mxGeometry x="8" y="8" width="${c}" height="18" as="geometry" />\n</mxCell>`;let d=`<mxCell parent="${r}" style="${u}" value="${s}" vertex="1">\n <mxGeometry x="8" y="8" width="${c}" height="18" as="geometry" />\n</mxCell>`;return`<UserObject label="${escapeXml(e)}" link="${O}${escapeXml(n)}" id="${t}">\n ${d}\n</UserObject>`}function getViewTitle(e){return typeof e.title==`string`?e.title:null}function getViewDescriptionString(e){let t=e.description;return typeof t==`object`&&t&&`txt`in t?String(t.txt):typeof t==`object`&&t&&`md`in t?String(t.md):typeof t==`string`?t:``}function getLeanixRootStyleParts(e,t){let n=[`bridgeManaged=true;`,`likec4ViewId=${encodeURIComponent(e.id)};`];return t.projectId!=null&&t.projectId!==``&&n.push(`likec4ProjectId=${encodeURIComponent(t.projectId)};`),n}function buildRootCellStyle(e,t){let n=getViewTitle(e),r=getViewDescriptionString(e),i=r.trim()===``?``:encodeURIComponent(r.trim()),a=e.notation,o=typeof a==`string`&&a!==``?a:void 0,s=o==null?``:encodeURIComponent(o),c=[`rounded=1;whiteSpace=wrap;html=1;fillColor=none;strokeColor=none;`,`likec4ViewTitle=${encodeURIComponent(n??e.id)};`,i===``?``:`likec4ViewDescription=${i};`,s===``?``:`likec4ViewNotation=${s};`];return t?.profile===`leanix`&&c.push(...getLeanixRootStyleParts(e,t)),c.join(``)}function drawioArrow(e){switch(e){case`none`:return`none`;case`open`:case`onormal`:case`vee`:return`open`;case`diamond`:case`odiamond`:return`diamond`;case`dot`:case`odot`:return`oval`;case`crow`:return`block`;default:return`block`}}const I={x:0,y:0,width:120,height:60};function isDefaultBbox(e){return e.x===I.x&&e.y===I.y&&e.width===I.width&&e.height===I.height}function spreadUnlaidNodesOverVertical(e,t,n){let bboxKey=e=>`${e.x},${e.y},${e.width},${e.height}`,r=t.filter(e=>!n.has(e.id)),i=new Map;for(let t of r){let n=e.get(t.id);if(!n)continue;let r=bboxKey(n),a=i.get(r)??[];a.push(t),i.set(r,a)}for(let t of i.values()){if(t.length<=1)continue;let n=t[0],r=n?e.get(n.id):void 0;r&&isDefaultBbox(r)&&t.forEach((t,n)=>{e.set(t.id,{...r,x:r.x,y:r.y+n*(r.height+24)})})}}function computeContainerBboxesFromChildren(e,t,n,r,i,a){let o=[...n].filter(e=>t.has(e.id)).sort((e,t)=>(t.level??0)-(e.level??0));for(let t of o){let n=(N.getChildren(t)??[]).filter(e=>r.has(e));if(n.length===0||!isDefaultBbox(e.get(t.id)))continue;let o=1/0,s=1/0,c=-1/0,l=-1/0;for(let t of n){let n=e.get(t);n&&(o=Math.min(o,n.x),s=Math.min(s,n.y),c=Math.max(c,n.x+n.width),l=Math.max(l,n.y+n.height))}o!==1/0&&e.set(t.id,{x:o-i,y:s-a,width:c-o+2*i,height:l-s+2*a})}}function computeContentBoundsAndOffsets(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e.values())t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x+a.width),i=Math.max(i,a.y+a.height);t===1/0&&(t=0),n===1/0&&(n=0),r===-1/0&&(r=t+800),i===-1/0&&(i=n+600);let a=t+(r-t)/2,o=n+(i-n)/2;return{offsetX:800/2-a,offsetY:600/2-o,canvasWidth:800,canvasHeight:600}}function computeDiagramLayout(e,t){let n=e.$view,{nodes:r}=n,i=t?.layoutOverride,a=[...r].sort((e,t)=>c(e.parent)&&c(t.parent)?0:c(e.parent)?-1:c(t.parent)?1:e.parent===t.parent?0:e.id.startsWith(t.id+`.`)?1:t.id.startsWith(e.id+`.`)?-1:0),getBBox=e=>{let t=i?.[e.id];if(t)return t;let n=e;return{x:typeof n.x==`number`?n.x:Array.isArray(n.position)?n.position[0]:0,y:typeof n.y==`number`?n.y:Array.isArray(n.position)?n.position[1]:0,width:typeof n.width==`number`?n.width:n.size?.width??120,height:typeof n.height==`number`?n.height:n.size?.height??60}},o=new Map;for(let e of a)o.set(e.id,getBBox(e));let s=new Set(r.map(e=>e.id)),l=new Set(r.filter(e=>{let t=N.getChildren(e);return Array.isArray(t)&&t.some(e=>s.has(e))}).map(e=>e.id));spreadUnlaidNodesOverVertical(o,a,l);let u=getEffectiveStyles(e),d=u.theme.spacing.xl;computeContainerBboxesFromChildren(o,l,a,s,d,u.theme.spacing.xl+u.theme.spacing.md);let{offsetX:f,offsetY:p,canvasWidth:m,canvasHeight:h}=computeContentBoundsAndOffsets(o);return{view:n,bboxes:o,containerNodeIds:l,sortedNodes:a,offsetX:f,offsetY:p,canvasWidth:m,canvasHeight:h,defaultParentId:`1`,rootId:`0`,effectiveStyles:u,fontFamily:`'IBM Plex Sans Variable',ui-sans-serif,system-ui,sans-serif`,containerTitleFontSizePx:Math.round(u.theme.textSizes.xs),containerTitleColor:`#74c0fc`,nodeIdsInView:s}}function generateDiagramContent(e,t){let n=e.$view,{edges:r}=n,i=t?.compressed!==!1,a=computeDiagramLayout(e,t),{sortedNodes:o,defaultParentId:s,rootId:c,canvasWidth:l,canvasHeight:u}=a,d=new Map,f=2,getCellId=e=>{let t=d.get(e);if(!t){if(f>=1e4)throw Error(`DrawIO cell ID range exhausted`);t=String(f++),d.set(e,t)}return t},p=[],m=[],h=[],g=1e4;for(let n of o){let r=buildNodeCellXml(computeNodeCellExportData(n,a,t,e,getCellId,g));r.isContainer?(p.push(r.vertexXml),r.titleCellXml&&p.push(r.titleCellXml),g++):m.push(r.vertexXml)}for(let n of r){if(f>=1e4)throw Error(`DrawIO cell ID range exhausted`);let r=String(f++);h.push(buildEdgeCellXml(n,a,t,e,getCellId,r))}let _=[`<mxCell id="${s}" value="" style="${buildRootCellStyle(n,t)}" vertex="1" parent="${c}">
14
+ `);n=JSON.parse(t)}catch{}s+=1;continue}if(e.trim()===`// <likec4.strokeColor.vertices>`){for(o=!0,s+=1;s<t.length&&t[s]?.trim()!==`// </likec4.strokeColor.vertices>`;){let e=t[s]?.trim();if(e?.startsWith(`// `)&&e.includes(`=`)){let t=e.slice(3).trim(),n=t.indexOf(`=`);if(n>0){let e=t.slice(0,n).trim(),i=t.slice(n+1).trim();e&&i&&(r[e]=i)}}s+=1}s+=1;continue}if(e.trim()===`// <likec4.strokeWidth.vertices>`){for(o=!0,s+=1;s<t.length&&t[s]?.trim()!==`// </likec4.strokeWidth.vertices>`;){let e=t[s]?.trim();if(e?.startsWith(`// `)&&e.includes(`=`)){let t=e.slice(3).trim(),n=t.indexOf(`=`);if(n>0){let e=t.slice(0,n).trim(),r=t.slice(n+1).trim();e&&r!==``&&(i[e]=r)}}s+=1}s+=1;continue}if(e.trim()===`// <likec4.edge.waypoints>`){for(o=!0,s+=1;s<t.length&&t[s]?.trim()!==`// </likec4.edge.waypoints>`;){let e=t[s]?.trim();if(e?.startsWith(`// `)){let t=e.slice(3).trim(),n=t.indexOf(` `);if(n>0){let e=t.slice(0,n).trim(),r=t.slice(n+1).trim();if(e&&r)try{let t=JSON.parse(r);Array.isArray(t)&&(a[e]=t)}catch{}}}s+=1}s+=1;continue}s+=1}return o?{layoutByView:n,strokeColorByFqn:r,strokeWidthByFqn:i,edgeWaypoints:a}:null}function compressDrawioDiagramXml(e){let t=encodeURIComponent(e),n=new TextEncoder().encode(t);return uint8ArrayToBase64(x.deflateRaw(n))}function uint8ArrayToBase64(e){if(typeof Buffer<`u`)return Buffer.from(e).toString(`base64`);let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}const P={getNotes(e){return e.notes},getSummary(e){return e.summary},getTags(e){return e.tags},getNavigateTo(e){return e.navigateTo},getIcon(e){return e.icon},getLinks(e){return e.links},getNotation(e){return e.notation},getCustomData(e){return e.customData},getChildren(e){return e.children}},F={getKind(e){return e.kind},getNotation(e){return e.notation},getLinks(e){return e.links},getMetadata(e){return e.metadata},getCustomData(e){return e.customData}};function getEffectiveStyles(e){return e.$styles??_.DEFAULT}function escapeHtml(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`).replaceAll(`"`,`&quot;`)}function toNonEmptyString(e){if(e==null)return``;let t=typeof e;if(t===`string`){let t=e;return t.trim()===``?``:t}return t===`number`||t===`boolean`?String(e):``}function getContainerDashedStyle(e,t){return e&&t!==`none`||t===`dashed`?`dashed=1;`:``}function getDefaultStrokeWidth(e,t){return e===`none`?`0`:t||e?`1`:``}function applyStrokeColorOverride(e,t){return{fill:e?.fill??`#dae8fc`,stroke:t,font:e?.font??t}}function resolveThemeColor(e,t,n){return t&&t in e.theme.colors?t:n}function getThemeColorValues(e,t,n){let r=getEffectiveStyles(e),i=resolveThemeColor(r,t??n,n);try{return r.colors(i)}catch{return _.DEFAULT.colors(n)}}function drawioShape(e){let t=`shape=rectangle;rounded=1;arcSize=12;`;switch(e){case`person`:return`shape=actor;`;case`rectangle`:case`browser`:case`mobile`:case`bucket`:return t;case`cylinder`:case`queue`:case`storage`:return`shape=cylinder3;whiteSpace=wrap;boundedLbl=1;backgroundOutline=1;size=15;`;case`document`:return`shape=document;whiteSpace=wrap;html=1;boundedLbl=1;`;case`component`:return`shape=component;`;default:return t}}function getElementColors(e,t){let n=getThemeColorValues(e,t,`primary`).elements;return{fill:String(n.fill??`#dae8fc`),stroke:String(n.stroke??`#2563eb`),font:String(n.hiContrast??n.stroke??`#1e40af`)}}function getEdgeStrokeColor(e,t){let n=getThemeColorValues(e,t??`gray`,`gray`);return String(n.relationships?.line??`#1e40af`)}function getEdgeLabelColors(e,t){let n=getThemeColorValues(e,t??`gray`,`gray`).relationships;return{font:String(n?.label??n?.line??`#1e40af`),background:String(n?.labelBg??`#ffffff`)}}function edgeAnchors(e,t){let n=e.x+e.width/2,r=e.y+e.height/2,i=t.x+t.width/2,a=t.y+t.height/2,o=i-n,s=a-r,c=Math.abs(o)>=Math.abs(s);return{exitX:c?+(o>=0):.5,exitY:c?.5:+(s>=0),entryX:c?o>=0?0:1:.5,entryY:c?.5:s>=0?0:1}}function normalizeEdgePoint(e){if(Array.isArray(e)&&e.length>=2&&typeof e[0]==`number`&&typeof e[1]==`number`)return[[e[0],e[1]]];let t=e;return typeof t.x==`number`&&typeof t.y==`number`?[[t.x,t.y]]:[]}function buildNodeValueHtml(e,t,n,r,i,a){return n?``:t===``?`<div style="box-sizing:border-box;width:100%;min-height:100%;display:flex;align-items:center;justify-content:center;text-align:center;color:${r};font-family:${i};"><b style="font-size:${a}px;">${escapeHtml(e)}</b></div>`:`<div style="box-sizing:border-box;width:100%;min-height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;color:${r};font-family:${i};"><b style="font-size:${a}px;">${escapeHtml(e)}</b><br/><span style="font-weight:normal;font-size:${a}px;">${escapeHtml(t)}</span></div>`}function pushStylePart(e,t,n){n!=null&&n!==``&&e.push(`${t}=${encodeURIComponent(n)}`)}function pushStylePartNum(e,t,n){n!=null&&e.push(`${t}=${n}`)}function buildNavLinkStyle(e){return e===``?``:`link=${encodeURIComponent(`${k}${e}`)};`}function toExportString(e){let t=e==null?null:b(e);return t!=null&&!c(t)?t.trim():``}function linksToStyleJson(e){return!Array.isArray(e)||e.length===0?``:encodeURIComponent(JSON.stringify(e.map(e=>({url:e.url,title:e.title}))))}function metadataToStyleJson(e){return typeof e!=`object`||!e||Array.isArray(e)||Object.keys(e).length===0?``:encodeURIComponent(JSON.stringify(e))}const I=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{4}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/;function buildLikec4StyleForNode(e){let t=[];return pushStylePart(t,`likec4Description`,e.desc),pushStylePart(t,`likec4Technology`,e.tech),pushStylePart(t,`likec4Notes`,e.notes),pushStylePart(t,`likec4Tags`,e.tagList),pushStylePart(t,`likec4NavigateTo`,e.navTo),pushStylePart(t,`likec4Icon`,e.iconName),pushStylePart(t,`likec4Summary`,e.summaryStr),e.linksJson!==``&&t.push(`likec4Links=${e.linksJson}`),pushStylePart(t,`likec4Border`,e.borderVal),pushStylePartNum(t,`likec4Opacity`,e.containerOpacityNum),pushStylePart(t,`likec4StrokeWidth`,e.strokeWidth),e.colorNameForRoundtrip!==``&&t.push(`likec4ColorName=${e.colorNameForRoundtrip}`),pushStylePart(t,`likec4Size`,e.nodeStyle?.size),pushStylePart(t,`likec4Padding`,e.nodeStyle?.padding),pushStylePart(t,`likec4TextSize`,e.nodeStyle?.textSize),pushStylePart(t,`likec4IconPosition`,e.nodeStyle?.iconPosition),e.strokeHex&&I.test(e.strokeHex)&&pushStylePart(t,`likec4StrokeColor`,e.strokeHex),pushStylePart(t,`likec4Notation`,e.nodeNotation??void 0),t.length>0?t.join(`;`)+`;`:``}function buildBridgeManagedStyleForNode(e,t,n,r){if(r?.profile!==`leanix`)return``;let i=[`bridgeManaged=true`,`likec4Id=${encodeURIComponent(e)}`,`likec4Kind=${encodeURIComponent(t)}`,`likec4ViewId=${encodeURIComponent(n)}`];r.projectId!=null&&r.projectId!==``&&i.push(`likec4ProjectId=${encodeURIComponent(r.projectId)}`);let a=r.leanixFactSheetTypeByKind?.[t];return a!=null&&a!==``&&i.push(`leanixFactSheetType=${encodeURIComponent(a)}`),i.join(`;`)+`;`}function buildBridgeManagedStyleForEdge(e,t){return t?.profile===`leanix`?`bridgeManaged=true;likec4RelationId=${encodeURIComponent(e)};`:``}function buildMxUserObjectXml(e){return!e||typeof e!=`object`||Array.isArray(e)||Object.keys(e).length===0?``:`
15
+ <mxUserObject>`+Object.entries(e).map(([e,t])=>{let n=typeof t==`string`?t:t==null?``:String(t);return`<data key="${escapeXml(e)}">${escapeXml(n)}</data>`}).join(``)+`</mxUserObject>`}function buildLikec4StyleForEdge(e){let t=[];return pushStylePart(t,`likec4Description`,e.edgeDesc),pushStylePart(t,`likec4Technology`,e.edgeTech),pushStylePart(t,`likec4Notes`,e.edgeNotes),pushStylePart(t,`likec4NavigateTo`,e.edgeNavTo),pushStylePart(t,`likec4RelationshipKind`,e.edgeKind??void 0),pushStylePart(t,`likec4Notation`,e.edgeNotation??void 0),e.edgeLinksJson!==``&&t.push(`likec4Links=${e.edgeLinksJson}`),e.edgeMetadataJson!==``&&t.push(`likec4Metadata=${e.edgeMetadataJson}`),t.length>0?t.join(`;`)+`;`:``}function buildEdgeLabelValue(e){return e.label?escapeXml(e.label):``}function buildEdgeGeometryXml(e,t){let n=t?.[`${e.source}|${e.target}|${e.id}`]??t?.[`${e.source}|${e.target}`],r=Array.isArray(n)?n.flatMap(normalizeEdgePoint):[];return r.length>0?`<mxGeometry relative="1" as="geometry">${`<Array as="points">`+r.map(([e,t])=>`<mxPoint x="${Math.round(e)}" y="${Math.round(t)}"/>`).join(``)+`</Array>`}</mxGeometry>`:`<mxGeometry relative="1" as="geometry" />`}function buildEdgeStyleString(e,t,n,r,i){let{bboxes:a,fontFamily:o}=t,s=a.get(e.source),c=a.get(e.target),l=s&&c?edgeAnchors(s,c):{exitX:1,exitY:.5,entryX:0,entryY:.5},u=`exitX=${l.exitX};exitY=${l.exitY};entryX=${l.entryX};entryY=${l.entryY};`,d=getEdgeStrokeColor(n,e.color),f=e.line===`dashed`?`dashed=1;`:e.line===`dotted`?`dashed=1;dashPattern=1 1;`:``,p=drawioArrow(e.head),m=e.tail==null||e.tail===`none`?`none`:drawioArrow(e.tail),h=buildLikec4StyleForEdge({edgeDesc:toExportString(e.description),edgeTech:toExportString(e.technology),edgeNotes:toExportString(e.notes),edgeNavTo:toNonEmptyString(e.navigateTo),edgeKind:F.getKind(e),edgeNotation:F.getNotation(e),edgeLinksJson:linksToStyleJson(F.getLinks(e)),edgeMetadataJson:metadataToStyleJson(F.getMetadata(e))}),g=buildBridgeManagedStyleForEdge(e.id,i),_=getEdgeLabelColors(n,e.color);return`endArrow=${p};startArrow=${m};html=1;rounded=0;${u}strokeColor=${d};strokeWidth=2;${f}${r===``?``:`fontColor=${_.font};fontSize=12;align=center;verticalAlign=middle;labelBackgroundColor=none;fontFamily=${encodeURIComponent(o)};`}${h}${g}`}function buildEdgeCellXml(e,t,n,r,i,a){let{defaultParentId:o}=t,s=i(e.source),c=i(e.target),l=buildEdgeLabelValue(e),u=buildEdgeGeometryXml(e,n?.edgeWaypoints);return`<mxCell id="${a}" value="${l}" style="${buildEdgeStyleString(e,t,r,l,n)}" edge="1" parent="${o}" source="${s}" target="${c}">
16
+ ${u}${buildMxUserObjectXml(F.getCustomData(e))}
17
+ </mxCell>`}function computeNodeGeometry(e,t,n){let{bboxes:r,defaultParentId:i,nodeIdsInView:a}=t,o=n(e.id),s=r.get(e.id),{width:c,height:l}=s,u=e.parent!=null&&a.has(e.parent)?n(e.parent):i,d=e.parent==null?void 0:r.get(e.parent);return{id:o,parentId:u,x:d==null?s.x+t.offsetX:s.x-d.x,y:d==null?s.y+t.offsetY:s.y-d.y,width:c,height:l}}function computeNodeStylePartsAndValue(e,t,n,r){let{containerNodeIds:i,effectiveStyles:a,fontFamily:o,containerTitleFontSizePx:s,containerTitleColor:c}=t,l=n?.strokeColorByNodeId,u=n?.strokeWidthByNodeId,d=i.has(e.id),f=e.kind??``,p=e.title,m=toExportString(e.description),h=toExportString(e.technology),g=toExportString(P.getNotes(e)),_=P.getTags(e),v=Array.isArray(_)&&_.length>0?_.join(`,`):``,y=toNonEmptyString(P.getNavigateTo(e)),b=toNonEmptyString(P.getIcon(e)),x=f===`actor`||e.shape===`person`,S=d?`shape=rectangle;rounded=0;container=1;collapsible=0;startSize=0;`:x?`shape=actor;`:drawioShape(e.shape),C=l?.[e.id],w=u?.[e.id],T=C?applyStrokeColorOverride(getElementColors(r,e.color),C):getElementColors(r,e.color),E=T?.fill??`#dae8fc`,D=T?.stroke??`#2563eb`,O=T?.font??T?.stroke??`#1e40af`,k=`fillColor=${E};strokeColor=${D};fontColor=${O};`,A=e.style,j=a.fontSize(A?.textSize),M=escapeXml(buildNodeValueHtml(p,m,d,O,o,j)),N=A?.border,F=w??getDefaultStrokeWidth(N,d),I=F===``?``:`strokeWidth=${F};`,L=getContainerDashedStyle(d,N),R=d===!0?A?.opacity??15:void 0,z=R!=null&&d===!0?`fillOpacity=${Math.min(100,Math.max(0,R))};`:``,B=buildLikec4StyleForNode({desc:m,tech:h,notes:g,tagList:v,navTo:y,iconName:b,summaryStr:toExportString(P.getSummary(e)),linksJson:linksToStyleJson(P.getLinks(e)),borderVal:N,containerOpacityNum:R,strokeWidth:F,colorNameForRoundtrip:e.color?encodeURIComponent(String(e.color)):``,nodeStyle:A,strokeHex:D,nodeNotation:P.getNotation(e)})+buildBridgeManagedStyleForNode(e.id,f,t.view.id,n),V=buildMxUserObjectXml(P.getCustomData(e)),H=buildNavLinkStyle(y);return{value:M,styleStr:`${d?`align=left;verticalAlign=top;overflow=fill;whiteSpace=wrap;html=1;`:`align=center;verticalAlign=middle;verticalLabelPosition=middle;labelPosition=center;fontSize=${j};fontStyle=1;spacingTop=4;spacingLeft=2;spacingRight=2;spacingBottom=2;overflow=fill;whiteSpace=wrap;html=1;fontFamily=${encodeURIComponent(o)};`}${S}${k}${I}${L}${z}${H}${B}`,userObjectXml:V,navTo:y,isContainer:d,title:p,fontFamily:o,containerTitleFontSizePx:s,containerTitleColor:c}}function computeNodeCellExportData(e,t,n,r,i,a){let o=computeNodeGeometry(e,t,i),s=computeNodeStylePartsAndValue(e,t,n,r);return{...o,value:s.value,styleStr:s.styleStr,userObjectXml:s.userObjectXml,navTo:s.navTo,isContainer:s.isContainer,fontFamily:s.fontFamily,...s.isContainer&&{title:s.title??``,titleCellId:String(a),containerTitleFontSizePx:s.containerTitleFontSizePx,containerTitleColor:s.containerTitleColor}}}function buildNodeCellXml(e){let t=`<mxGeometry height="${Math.round(e.height)}" width="${Math.round(e.width)}" x="${Math.round(e.x)}" y="${Math.round(e.y)}" as="geometry" />`,n=e.userObjectXml===``?`\n ${t}`:`${e.userObjectXml}\n ${t}`,r=e.isContainer&&e.title!=null?escapeXml(e.title):e.value,i=e.navTo===``?`<mxCell id="${e.id}" value="${e.value}" style="${e.styleStr}" vertex="1" parent="${e.parentId}">\n ${n}\n</mxCell>`:`<UserObject label="${r}" link="${k}${escapeXml(e.navTo)}" id="${e.id}">\n <mxCell parent="${e.parentId}" style="${e.styleStr}" value="${e.value}" vertex="1">\n ${n}\n</mxCell>\n</UserObject>`;return e.isContainer?{vertexXml:i,titleCellXml:buildContainerTitleCellXml(e.title??``,e.titleCellId??e.id,e.navTo,e.id,e.fontFamily,e.containerTitleFontSizePx??12,e.containerTitleColor??`#74c0fc`),isContainer:!0}:{vertexXml:i,isContainer:!1}}function buildContainerTitleCellXml(e,t,n,r,i,a,o){let s=escapeXml(e),c=Math.max(60,Math.min(260,e.length*8)),l=buildNavLinkStyle(n),u=`shape=text;html=1;fillColor=none;strokeColor=none;align=left;verticalAlign=top;fontSize=${a};fontStyle=1;fontColor=${o};fontFamily=${encodeURIComponent(i)};${l}`;if(n===``)return`<mxCell id="${t}" value="${s}" style="${u}" vertex="1" parent="${r}">\n <mxGeometry x="8" y="8" width="${c}" height="18" as="geometry" />\n</mxCell>`;let d=`<mxCell parent="${r}" style="${u}" value="${s}" vertex="1">\n <mxGeometry x="8" y="8" width="${c}" height="18" as="geometry" />\n</mxCell>`;return`<UserObject label="${escapeXml(e)}" link="${k}${escapeXml(n)}" id="${t}">\n ${d}\n</UserObject>`}function getViewTitle(e){return typeof e.title==`string`?e.title:null}function getViewDescriptionString(e){let t=e.description;return typeof t==`object`&&t&&`txt`in t?String(t.txt):typeof t==`object`&&t&&`md`in t?String(t.md):typeof t==`string`?t:``}function getLeanixRootStyleParts(e,t){let n=[`bridgeManaged=true;`,`likec4ViewId=${encodeURIComponent(e.id)};`];return t.projectId!=null&&t.projectId!==``&&n.push(`likec4ProjectId=${encodeURIComponent(t.projectId)};`),n}function buildRootCellStyle(e,t){let n=getViewTitle(e),r=getViewDescriptionString(e),i=r.trim()===``?``:encodeURIComponent(r.trim()),a=e.notation,o=typeof a==`string`&&a!==``?a:void 0,s=o==null?``:encodeURIComponent(o),c=[`rounded=1;whiteSpace=wrap;html=1;fillColor=none;strokeColor=none;`,`likec4ViewTitle=${encodeURIComponent(n??e.id)};`,i===``?``:`likec4ViewDescription=${i};`,s===``?``:`likec4ViewNotation=${s};`];return t?.profile===`leanix`&&c.push(...getLeanixRootStyleParts(e,t)),c.join(``)}function drawioArrow(e){switch(e){case`none`:return`none`;case`open`:case`onormal`:case`vee`:return`open`;case`diamond`:case`odiamond`:return`diamond`;case`dot`:case`odot`:return`oval`;case`crow`:return`block`;default:return`block`}}const L={x:0,y:0,width:120,height:60};function isDefaultBbox(e){return e.x===L.x&&e.y===L.y&&e.width===L.width&&e.height===L.height}function spreadUnlaidNodesOverVertical(e,t,n){let bboxKey=e=>`${e.x},${e.y},${e.width},${e.height}`,r=t.filter(e=>!n.has(e.id)),i=new Map;for(let t of r){let n=e.get(t.id);if(!n)continue;let r=bboxKey(n),a=i.get(r)??[];a.push(t),i.set(r,a)}for(let t of i.values()){if(t.length<=1)continue;let n=t[0],r=n?e.get(n.id):void 0;r&&isDefaultBbox(r)&&t.forEach((t,n)=>{e.set(t.id,{...r,x:r.x,y:r.y+n*(r.height+24)})})}}function computeContainerBboxesFromChildren(e,t,n,r,i,a){let o=[...n].filter(e=>t.has(e.id)).sort((e,t)=>(t.level??0)-(e.level??0));for(let t of o){let n=(P.getChildren(t)??[]).filter(e=>r.has(e));if(n.length===0||!isDefaultBbox(e.get(t.id)))continue;let o=1/0,s=1/0,c=-1/0,l=-1/0;for(let t of n){let n=e.get(t);n&&(o=Math.min(o,n.x),s=Math.min(s,n.y),c=Math.max(c,n.x+n.width),l=Math.max(l,n.y+n.height))}o!==1/0&&e.set(t.id,{x:o-i,y:s-a,width:c-o+2*i,height:l-s+2*a})}}function computeContentBoundsAndOffsets(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e.values())t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x+a.width),i=Math.max(i,a.y+a.height);t===1/0&&(t=0),n===1/0&&(n=0),r===-1/0&&(r=t+800),i===-1/0&&(i=n+600);let a=t+(r-t)/2,o=n+(i-n)/2;return{offsetX:400-a,offsetY:300-o,canvasWidth:800,canvasHeight:600}}function computeDiagramLayout(e,t){let n=e.$view,{nodes:r}=n,i=t?.layoutOverride,a=[...r].sort((e,t)=>l(e.parent)&&l(t.parent)?0:l(e.parent)?-1:l(t.parent)?1:e.parent===t.parent?0:e.id.startsWith(t.id+`.`)?1:t.id.startsWith(e.id+`.`)?-1:0),getBBox=e=>{let t=i?.[e.id];if(t)return t;let n=e;return{x:typeof n.x==`number`?n.x:Array.isArray(n.position)?n.position[0]:0,y:typeof n.y==`number`?n.y:Array.isArray(n.position)?n.position[1]:0,width:typeof n.width==`number`?n.width:n.size?.width??120,height:typeof n.height==`number`?n.height:n.size?.height??60}},o=new Map;for(let e of a)o.set(e.id,getBBox(e));let s=new Set(r.map(e=>e.id)),c=new Set(r.filter(e=>{let t=P.getChildren(e);return Array.isArray(t)&&t.some(e=>s.has(e))}).map(e=>e.id));spreadUnlaidNodesOverVertical(o,a,c);let u=getEffectiveStyles(e),d=u.theme.spacing.xl;computeContainerBboxesFromChildren(o,c,a,s,d,u.theme.spacing.xl+u.theme.spacing.md);let{offsetX:f,offsetY:p,canvasWidth:m,canvasHeight:h}=computeContentBoundsAndOffsets(o);return{view:n,bboxes:o,containerNodeIds:c,sortedNodes:a,offsetX:f,offsetY:p,canvasWidth:m,canvasHeight:h,defaultParentId:`1`,rootId:`0`,effectiveStyles:u,fontFamily:`'IBM Plex Sans Variable',ui-sans-serif,system-ui,sans-serif`,containerTitleFontSizePx:Math.round(u.theme.textSizes.xs),containerTitleColor:`#74c0fc`,nodeIdsInView:s}}function generateDiagramContent(e,t){let n=e.$view,{edges:r}=n,i=t?.compressed!==!1,a=computeDiagramLayout(e,t),{sortedNodes:o,defaultParentId:s,rootId:c,canvasWidth:l,canvasHeight:u}=a,d=new Map,f=2,getCellId=e=>{let t=d.get(e);if(!t){if(f>=1e4)throw Error(`DrawIO cell ID range exhausted`);t=String(f++),d.set(e,t)}return t},p=[],m=[],h=[],g=1e4;for(let n of o){let r=buildNodeCellXml(computeNodeCellExportData(n,a,t,e,getCellId,g));r.isContainer?(p.push(r.vertexXml),r.titleCellXml&&p.push(r.titleCellXml),g++):m.push(r.vertexXml)}for(let n of r){if(f>=1e4)throw Error(`DrawIO cell ID range exhausted`);let r=String(f++);h.push(buildEdgeCellXml(n,a,t,e,getCellId,r))}let _=[`<mxCell id="${s}" value="" style="${buildRootCellStyle(n,t)}" vertex="1" parent="${c}">
18
18
  <mxGeometry x="0" y="0" width="${l}" height="${u}" as="geometry" />
19
19
  </mxCell>`,...p,...m,...h].join(`
20
20
  `),v=(getViewTitle(n)??n.id).trim()||n.id,y=`<mxGraphModel dx="800" dy="800" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
@@ -30,8 +30,8 @@ views {
30
30
  ${e.map(e=>` <diagram name="${escapeXml(e.name)}" id="likec4-${escapeXml(e.id)}">${e.content}</diagram>`).join(`
31
31
  `)}
32
32
  </mxfile>
33
- `}function generateDrawio(e,t){return wrapInMxFile([generateDiagramContent(e,t)],t?.modified)}function generateDrawioMulti(e,t,n){return wrapInMxFile(e.map(e=>generateDiagramContent(e,t?.[e.$view.id])),n)}function buildOptionsFromRoundtrip(e,t,n){let r={compressed:!1,...n};if(!t)return r;let i=t.layoutByView[e]?.nodes;return i!=null&&(r.layoutOverride=i),Object.keys(t.strokeColorByFqn).length>0&&(r.strokeColorByNodeId=t.strokeColorByFqn),Object.keys(t.strokeWidthByFqn).length>0&&(r.strokeWidthByNodeId=t.strokeWidthByFqn),Object.keys(t.edgeWaypoints).length>0&&(r.edgeWaypoints=t.edgeWaypoints),r}function buildDrawioExportOptionsFromSource(e,t,n){return buildOptionsFromRoundtrip(e,t?parseDrawioRoundtripComments(t):null,n)}function buildDrawioExportOptionsForViews(e,t,n){let r=t?parseDrawioRoundtripComments(t):null;return Object.fromEntries(e.map(e=>[e,buildOptionsFromRoundtrip(e,r,n)]))}function generateDrawioEditUrl(e){let t=compressDrawioDiagramXml(e),n=JSON.stringify({type:`xml`,compressed:!0,data:t});return`https://app.diagrams.net/#create=`+encodeURIComponent(n)}const L=e(e=>e.charAt(0).toLocaleUpperCase()+e.slice(1),`capitalizeFirstLetter`),R=e(e=>e.split(`.`).map(L).join(``),`fqnName`),z=e(e=>R(e.parent?e.id.slice(e.parent.length+1):e.id),`nodeName`),toSingleQuotes=e=>e.replace(/\\?"/g,`'`),mmdshape=({shape:e,title:t})=>{let n=`label: ${JSON.stringify(t)}`;switch(e){case`queue`:return`@{ shape: horizontal-cylinder, ${n} }`;case`person`:return`@{ icon: "fa:user", shape: rounded, ${n} }`;case`storage`:return`@{ shape: disk, ${n} }`;case`cylinder`:return`@{ shape: cylinder, ${n} }`;case`mobile`:case`browser`:return`@{ shape: rounded, ${n} }`;case`bucket`:return`@{ shape: trap-t, ${n} }`;case`rectangle`:return`@{ shape: rectangle, ${n} }`;case`document`:return`@{ shape: doc, ${n} }`;case`component`:return`@{ shape: rectangle, ${n} }`;default:_(e)}};function generateMermaid(e){let r=e.$view,{nodes:o,edges:s}=r,l=new Map,printNode=(e,r)=>{let a=z(e),s=(r?r+`.`:``)+a;l.set(e.id,s);let c=new t;if(e.children.length>0){let t=toSingleQuotes(e.title);c.append(`subgraph `,s,'["`',t,'`"]',n).indent({indentedChildren:[i(o.filter(t=>t.parent===e.id),e=>printNode(e,s),{appendNewLineIfNotEmpty:!0})],indentation:2}).append(`end`,n)}else c.append(s,mmdshape(e));return c},printEdge=e=>new t().append(l.get(e.source),` -.`,e.label?' "`'+toSingleQuotes(e.label)+'`" .-':`-`,`> `,l.get(e.target));return a(new t().append(`---`,n,`title: ${JSON.stringify(toSingleQuotes(e.titleOrId))}`,n,`---`,n).append(`graph `,r.autoLayout.direction,n).indent({indentedChildren:e=>{e.append(i(o.filter(e=>c(e.parent)),e=>printNode(e),{appendNewLineIfNotEmpty:!0})).appendIf(s.length>0,i(s,e=>printEdge(e),{appendNewLineIfNotEmpty:!0}))},indentation:2}))}function toUnion(e){return s(e)?`never`:(typeof e==`object`&&!Array.isArray(e)&&(e=u(e)),f(e,m(),p(S),d(e=>` | ${JSON.stringify(e)}`)).join(`
34
- `).trimStart())}function elementIdToUnion(e){let t=f(e,h(),o(e=>!!e&&l(e.id)),w,d(e=>` | ${JSON.stringify(e.id)}`));return t.length===0?`never`:t.join(`
33
+ `}function generateDrawio(e,t){return wrapInMxFile([generateDiagramContent(e,t)],t?.modified)}function generateDrawioMulti(e,t,n){return wrapInMxFile(e.map(e=>generateDiagramContent(e,t?.[e.$view.id])),n)}function buildOptionsFromRoundtrip(e,t,n){let r={compressed:!1,...n};if(!t)return r;let i=t.layoutByView[e]?.nodes;return i!=null&&(r.layoutOverride=i),Object.keys(t.strokeColorByFqn).length>0&&(r.strokeColorByNodeId=t.strokeColorByFqn),Object.keys(t.strokeWidthByFqn).length>0&&(r.strokeWidthByNodeId=t.strokeWidthByFqn),Object.keys(t.edgeWaypoints).length>0&&(r.edgeWaypoints=t.edgeWaypoints),r}function buildDrawioExportOptionsFromSource(e,t,n){return buildOptionsFromRoundtrip(e,t?parseDrawioRoundtripComments(t):null,n)}function buildDrawioExportOptionsForViews(e,t,n){let r=t?parseDrawioRoundtripComments(t):null;return Object.fromEntries(e.map(e=>[e,buildOptionsFromRoundtrip(e,r,n)]))}function generateDrawioEditUrl(e){let t=compressDrawioDiagramXml(e),n=JSON.stringify({type:`xml`,compressed:!0,data:t});return`https://app.diagrams.net/#create=`+encodeURIComponent(n)}const R=e(e=>e.charAt(0).toLocaleUpperCase()+e.slice(1),`capitalizeFirstLetter`),z=e(e=>e.split(`.`).map(R).join(``),`fqnName`),B=e(e=>z(e.parent?e.id.slice(e.parent.length+1):e.id),`nodeName`),toSingleQuotes=e=>e.replace(/\\?"/g,`'`),mmdshape=({shape:e,title:t})=>{let n=`label: ${JSON.stringify(t)}`;switch(e){case`queue`:return`@{ shape: horizontal-cylinder, ${n} }`;case`person`:return`@{ icon: "fa:user", shape: rounded, ${n} }`;case`storage`:return`@{ shape: disk, ${n} }`;case`cylinder`:return`@{ shape: cylinder, ${n} }`;case`mobile`:case`browser`:return`@{ shape: rounded, ${n} }`;case`bucket`:return`@{ shape: trap-t, ${n} }`;case`rectangle`:return`@{ shape: rectangle, ${n} }`;case`document`:return`@{ shape: doc, ${n} }`;case`component`:return`@{ shape: rectangle, ${n} }`;default:v(e)}};function generateMermaid(e){let i=e.$view,{nodes:o,edges:s}=i,c=new Map,printNode=(e,t)=>{let i=B(e),s=(t?t+`.`:``)+i;c.set(e.id,s);let l=new r;if(e.children.length>0){let t=toSingleQuotes(e.title);l.append(`subgraph `,s,'["`',t,'`"]',n).indent({indentedChildren:[a(o.filter(t=>t.parent===e.id),e=>printNode(e,s),{appendNewLineIfNotEmpty:!0})],indentation:2}).append(`end`,n)}else l.append(s,mmdshape(e));return l},printEdge=e=>new r().append(c.get(e.source),` -.`,e.label?' "`'+toSingleQuotes(e.label)+'`" .-':`-`,`> `,c.get(e.target));return t(new r().append(`---`,n,`title: ${JSON.stringify(toSingleQuotes(e.titleOrId))}`,n,`---`,n).append(`graph `,i.autoLayout.direction,n).indent({indentedChildren:e=>{e.append(a(o.filter(e=>l(e.parent)),e=>printNode(e),{appendNewLineIfNotEmpty:!0})).appendIf(s.length>0,a(s,e=>printEdge(e),{appendNewLineIfNotEmpty:!0}))},indentation:2}))}function appendView(e,t){e.append(`### `,t.titleOrId,n,n),t.description.nonEmpty&&e.append(t.description.md,n,n),e.append("```mermaid",n,generateMermaid(t).trimEnd(),n,"```",n,n)}function generateMarkdown(e,i={}){let a=new r;a.append(`# `,e.project.title??e.projectId,n,n),i.description&&a.append(i.description,n,n);for(let t of e.views())t.$view.sourcePath!==void 0&&appendView(a,t);return t(a)}function toUnion(e){return c(e)?`never`:(typeof e==`object`&&!Array.isArray(e)&&(e=d(e)),p(e,h(),m(C),f(e=>` | ${JSON.stringify(e)}`)).join(`
34
+ `).trimStart())}function elementIdToUnion(e){let t=p(e,g(),s(e=>!!e&&u(e.id)),T,f(e=>` | ${JSON.stringify(e.id)}`));return t.length===0?`never`:t.join(`
35
35
  `).trimStart()}function generateAux(e,t={}){let{useCorePackage:n=!1}=t;return`
36
36
  import type { Aux, SpecAux } from '${n?`@likec4/core/types`:`likec4/model`}';
37
37
 
@@ -83,11 +83,11 @@ export type $MetadataKey = $Aux['MetadataKey']
83
83
  import { LikeC4Model } from '${r?`@likec4/core`:`likec4`}/model'
84
84
  ${n}
85
85
 
86
- export const likec4model: LikeC4Model<$Aux> = new LikeC4Model(${x.stringify(e.$data,{space:2,quote:`'`})} as any) as any
86
+ export const likec4model: LikeC4Model<$Aux> = new LikeC4Model(${S.stringify(e.$data,{space:2,quote:`'`})} as any) as any
87
87
 
88
88
  /* prettier-ignore-end */
89
- `.trimStart()}const capitalizeFirstLetter=e=>e.charAt(0).toLocaleUpperCase()+e.slice(1),fqnName=e=>e.split(/[.-]/).map(capitalizeFirstLetter).join(``),nodeName=e=>fqnName(e.parent?e.id.slice(e.parent.length+1):e.id),pumlColor=(e,t,n=`#3b82f6`)=>e?t(e)??n:n,pumlDirection=({autoLayout:e})=>{switch(e.direction){case`TB`:return`top to bottom`;case`BT`:return console.warn(`Bottom to top direction is not supported. Defaulting to top to bottom.`),`top to bottom`;case`LR`:return`left to right`;case`RL`:return console.warn(`Right to left direction is not supported. Defaulting to left to right.`),`left to right`}},pumlShape=({shape:e})=>{switch(e){case`queue`:case`rectangle`:case`person`:return e;case`storage`:case`cylinder`:return`database`;case`component`:return`component`;case`document`:case`mobile`:case`bucket`:case`browser`:return`rectangle`;default:_(e)}},escapeLabel=e=>s(e)?null:JSON.stringify(e).slice(1,-1).replace(/\\"/g,`"`);function generatePuml(e){let r=e.$view,o=e.$model.$styles.theme.colors,{nodes:l,edges:u}=r,elementColorProvider=e=>t=>t in o?o[t].elements[e]:void 0,relationshipsColorProvider=e=>t=>t in o?o[t].relationships[e]:void 0,d=new Map,printHeader=()=>new t().append(`title "`,e.titleOrId,`"`,n).append(pumlDirection(r),` direction`,n),printTheme=()=>new t().append(`hide stereotype`,n).append(`skinparam ranksep `,`60`,n).append(`skinparam nodesep `,`30`,n).append(`skinparam {`,n).indent({indentedChildren:e=>e.append(`arrowFontSize `,`10`,n).append(`defaultTextAlignment `,`center`,n).append(`wrapWidth `,`200`,n).append(`maxMessageSize `,`100`,n).append(`shadowing `,`false`,n),indentation:2}).append(`}`,n),printStereotypes=e=>{let r=pumlShape(e),i=fqnName(e.id);return new t().append(`skinparam `,r,`<<`,i,`>>`,`{`,n).indent({indentedChildren:t=>t.append(`BackgroundColor `,pumlColor(e.color,elementColorProvider(`fill`)),n).append(`FontColor `,pumlColor(e.color,elementColorProvider(`hiContrast`),`#FFFFFF`),n).append(`BorderColor `,pumlColor(e.color,elementColorProvider(`stroke`)),n),indentation:2}).append(`}`,n)},printNode=e=>{let r=pumlShape(e),i=fqnName(e.id),a=escapeLabel(e.title)||nodeName(e),o=escapeLabel(e.technology);d.set(e.id,i);let s=v.from(e.description);return new t().append(r,` `).append(`"`).append(`==`,a).appendIf(!!o,`\\n<size:10>[`,o,`]</size>`).appendIf(s.nonEmpty,`\\n\\n`,escapeLabel(s.text)).append(`"`,` <<`,i,`>> `,`as `,i,n)},printBoundary=e=>{let r=escapeLabel(e.title)||nodeName(e),a=fqnName(e.id);return d.set(e.id,a),new t().append(`rectangle "`,r,`" <<`,a,`>> as `,a,` {`,n).indent({indentedChildren:t=>t.append(`skinparam `,`RectangleBorderColor<<`,a,`>> `,pumlColor(e.color,elementColorProvider(`fill`)),n).append(`skinparam `,`RectangleFontColor<<`,a,`>> `,pumlColor(e.color,elementColorProvider(`fill`)),n).append(`skinparam `,`RectangleBorderStyle<<`,a,`>> `,`dashed`,n,n).append(i(l.filter(t=>t.parent===e.id),e=>e.children.length>0?printBoundary(e):printNode(e))),indentation:2}).append(`}`,n)},printEdge=e=>{let r=e.technology||``,i=e.label||r,a=pumlColor(e.color,relationshipsColorProvider(`line`),`#777777`),withColor=e=>`<color:${a}>${e.replaceAll(`"`,`'`)}`,o=new t().append(d.get(e.source),` .[`,a,`,thickness=2].> `,d.get(e.target));return(i||r)&&(o.append(` : `,i.split(`
90
- `).map(e=>s(e)?e:withColor(e)).join(`\\n`)),r&&r!==i&&o.append(`\\n<size:8>[`,withColor(r),`]</size>`)),o.append(n)};return a(new t().append(`@startuml`,n).append(printHeader(),n).append(printTheme(),n).append(i(l.filter(e=>e.children.length==0),e=>printStereotypes(e),{appendNewLineIfNotEmpty:!0})).append(i(l.filter(e=>c(e.parent)),e=>e.children.length>0?printBoundary(e):printNode(e),{appendNewLineIfNotEmpty:!0})).appendIf(u.length>0,n,i(u,e=>printEdge(e),{appendNewLineIfNotEmpty:!0})).append(`@enduml`,n))}function generateViewId(e){return i(e,e=>r`${x.stringify(e.id)}`,{separator:` | `})}function generateViewsDataJs(e){let o=Array.from(e),s=new t;return s.appendTemplate`
89
+ `.trimStart()}const capitalizeFirstLetter=e=>e.charAt(0).toLocaleUpperCase()+e.slice(1),fqnName=e=>e.split(/[.-]/).map(capitalizeFirstLetter).join(``),nodeName=e=>fqnName(e.parent?e.id.slice(e.parent.length+1):e.id),pumlColor=(e,t,n=`#3b82f6`)=>e?t(e)??n:n,pumlDirection=({autoLayout:e})=>{switch(e.direction){case`TB`:return`top to bottom`;case`BT`:return console.warn(`Bottom to top direction is not supported. Defaulting to top to bottom.`),`top to bottom`;case`LR`:return`left to right`;case`RL`:return console.warn(`Right to left direction is not supported. Defaulting to left to right.`),`left to right`}},pumlShape=({shape:e})=>{switch(e){case`queue`:case`rectangle`:case`person`:return e;case`storage`:case`cylinder`:return`database`;case`component`:return`component`;case`document`:case`mobile`:case`bucket`:case`browser`:return`rectangle`;default:v(e)}},escapeLabel=e=>c(e)?null:JSON.stringify(e).slice(1,-1).replace(/\\"/g,`"`);function generatePuml(e){let i=e.$view,o=e.$model.$styles.theme.colors,{nodes:s,edges:u}=i,elementColorProvider=e=>t=>t in o?o[t].elements[e]:void 0,relationshipsColorProvider=e=>t=>t in o?o[t].relationships[e]:void 0,d=new Map,printHeader=()=>new r().append(`title "`,e.titleOrId,`"`,n).append(pumlDirection(i),` direction`,n),printTheme=()=>new r().append(`hide stereotype`,n).append(`skinparam ranksep `,`60`,n).append(`skinparam nodesep `,`30`,n).append(`skinparam {`,n).indent({indentedChildren:e=>e.append(`arrowFontSize `,`10`,n).append(`defaultTextAlignment `,`center`,n).append(`wrapWidth `,`200`,n).append(`maxMessageSize `,`100`,n).append(`shadowing `,`false`,n),indentation:2}).append(`}`,n),printStereotypes=e=>{let t=pumlShape(e),i=fqnName(e.id);return new r().append(`skinparam `,t,`<<`,i,`>>`,`{`,n).indent({indentedChildren:t=>t.append(`BackgroundColor `,pumlColor(e.color,elementColorProvider(`fill`)),n).append(`FontColor `,pumlColor(e.color,elementColorProvider(`hiContrast`),`#FFFFFF`),n).append(`BorderColor `,pumlColor(e.color,elementColorProvider(`stroke`)),n),indentation:2}).append(`}`,n)},printNode=e=>{let t=pumlShape(e),i=fqnName(e.id),a=escapeLabel(e.title)||nodeName(e),o=escapeLabel(e.technology);d.set(e.id,i);let s=y.from(e.description);return new r().append(t,` `).append(`"`).append(`==`,a).appendIf(!!o,`\\n<size:10>[`,o,`]</size>`).appendIf(s.nonEmpty,`\\n\\n`,escapeLabel(s.text)).append(`"`,` <<`,i,`>> `,`as `,i,n)},printBoundary=e=>{let t=escapeLabel(e.title)||nodeName(e),i=fqnName(e.id);return d.set(e.id,i),new r().append(`rectangle "`,t,`" <<`,i,`>> as `,i,` {`,n).indent({indentedChildren:t=>t.append(`skinparam `,`RectangleBorderColor<<`,i,`>> `,pumlColor(e.color,elementColorProvider(`fill`)),n).append(`skinparam `,`RectangleFontColor<<`,i,`>> `,pumlColor(e.color,elementColorProvider(`fill`)),n).append(`skinparam `,`RectangleBorderStyle<<`,i,`>> `,`dashed`,n,n).append(a(s.filter(t=>t.parent===e.id),e=>e.children.length>0?printBoundary(e):printNode(e))),indentation:2}).append(`}`,n)},printEdge=e=>{let t=e.technology||``,i=e.label||t,a=pumlColor(e.color,relationshipsColorProvider(`line`),`#777777`),withColor=e=>`<color:${a}>${e.replaceAll(`"`,`'`)}`,o=new r().append(d.get(e.source),` .[`,a,`,thickness=2].> `,d.get(e.target));return(i||t)&&(o.append(` : `,i.split(`
90
+ `).map(e=>c(e)?e:withColor(e)).join(`\\n`)),t&&t!==i&&o.append(`\\n<size:8>[`,withColor(t),`]</size>`)),o.append(n)};return t(new r().append(`@startuml`,n).append(printHeader(),n).append(printTheme(),n).append(a(s.filter(e=>e.children.length==0),e=>printStereotypes(e),{appendNewLineIfNotEmpty:!0})).append(a(s.filter(e=>l(e.parent)),e=>e.children.length>0?printBoundary(e):printNode(e),{appendNewLineIfNotEmpty:!0})).appendIf(u.length>0,n,a(u,e=>printEdge(e),{appendNewLineIfNotEmpty:!0})).append(`@enduml`,n))}function generateViewId(e){return a(e,e=>i`${S.stringify(e.id)}`,{separator:` | `})}function generateViewsDataJs(e){let o=Array.from(e),s=new r;return s.appendTemplate`
91
91
  /******************************************************************************
92
92
  * This file was generated
93
93
  * DO NOT EDIT MANUALLY!
@@ -95,9 +95,9 @@ export const likec4model: LikeC4Model<$Aux> = new LikeC4Model(${x.stringify(e.$d
95
95
  /* prettier-ignore-start */
96
96
  /* eslint-disable */
97
97
 
98
- `.append(n,n),o.length==0?(s.append(`export const LikeC4Views = {}`,n),a(s)):(s.appendTemplate`
98
+ `.append(n,n),o.length==0?(s.append(`export const LikeC4Views = {}`,n),t(s)):(s.appendTemplate`
99
99
  export const LikeC4Views = {
100
- `.indent({indentation:2,indentedChildren(e){e.appendNewLineIf(o.length>1).append(i(o,e=>r`${x.stringify(e.id)}: ${x.stringify(e)}`,{separator:`,`,appendNewLineIfNotEmpty:!0}))}}).append(`}`,n,n).appendTemplate`
100
+ `.indent({indentation:2,indentedChildren(e){e.appendNewLineIf(o.length>1).append(a(o,e=>i`${S.stringify(e.id)}: ${S.stringify(e)}`,{separator:`,`,appendNewLineIfNotEmpty:!0}))}}).append(`}`,n,n).appendTemplate`
101
101
 
102
102
  export function isLikeC4ViewId(value) {
103
103
  return (
@@ -108,7 +108,7 @@ export const likec4model: LikeC4Model<$Aux> = new LikeC4Model(${x.stringify(e.$d
108
108
  }
109
109
 
110
110
  /* prettier-ignore-end */
111
- `.append(n),a(s))}function generateViewsDataTs(e){let o=Array.from(e),s=new t;return s.appendTemplate`
111
+ `.append(n),t(s))}function generateViewsDataTs(e){let o=Array.from(e),s=new r;return s.appendTemplate`
112
112
  /******************************************************************************
113
113
  * This file was generated
114
114
  * DO NOT EDIT MANUALLY!
@@ -119,10 +119,10 @@ export const likec4model: LikeC4Model<$Aux> = new LikeC4Model(${x.stringify(e.$d
119
119
  // @ts-nocheck
120
120
 
121
121
  import type { DiagramView } from 'likec4'
122
- `.append(n,n),o.length===0?(s.append(`export {}`,n),a(s)):(s.appendTemplate`
122
+ `.append(n,n),o.length===0?(s.append(`export {}`,n),t(s)):(s.appendTemplate`
123
123
  export type LikeC4ViewId = ${generateViewId(o)};
124
124
  export const LikeC4Views = {
125
- `.indent({indentation:2,indentedChildren(e){e.appendNewLineIf(o.length>1).append(i(o,e=>r`${x.stringify(e.id)}: (${x.stringify(e)} as unknown) as DiagramView`,{separator:`,`,appendNewLineIfNotEmpty:!0}))}}).append(`} as const satisfies Record<LikeC4ViewId, DiagramView>`,n,n).appendTemplate`
125
+ `.indent({indentation:2,indentedChildren(e){e.appendNewLineIf(o.length>1).append(a(o,e=>i`${S.stringify(e.id)}: (${S.stringify(e)} as unknown) as DiagramView`,{separator:`,`,appendNewLineIfNotEmpty:!0}))}}).append(`} as const satisfies Record<LikeC4ViewId, DiagramView>`,n,n).appendTemplate`
126
126
  export type LikeC4Views = typeof LikeC4Views
127
127
 
128
128
  export function isLikeC4ViewId(value: unknown): value is LikeC4ViewId {
@@ -134,7 +134,7 @@ export const likec4model: LikeC4Model<$Aux> = new LikeC4Model(${x.stringify(e.$d
134
134
  }
135
135
 
136
136
  /* prettier-ignore-end */
137
- `.append(n),a(s))}function generateViewsDataDTs(e){let r=Array.from(e),i=new t;return i.appendTemplate`
137
+ `.append(n),t(s))}function generateViewsDataDTs(e){let i=Array.from(e),a=new r;return a.appendTemplate`
138
138
  /******************************************************************************
139
139
  * This file was generated
140
140
  * DO NOT EDIT MANUALLY!
@@ -143,15 +143,15 @@ export const likec4model: LikeC4Model<$Aux> = new LikeC4Model(${x.stringify(e.$d
143
143
  /* eslint-disable */
144
144
 
145
145
  import type { DiagramView } from 'likec4'
146
- `.append(n,n),r.length==0?(i.append(`export {}`,n),a(i)):(i.appendTemplate`
147
- export type LikeC4ViewId = ${generateViewId(r)};
146
+ `.append(n,n),i.length==0?(a.append(`export {}`,n),t(a)):(a.appendTemplate`
147
+ export type LikeC4ViewId = ${generateViewId(i)};
148
148
  export type LikeC4Views = Record<LikeC4ViewId, DiagramView>
149
149
 
150
150
  export declare const LikeC4Views: LikeC4Views
151
151
  export declare function isLikeC4ViewId(value: unknown): value is LikeC4ViewId
152
152
 
153
153
  /* prettier-ignore-end */
154
- `.append(n),a(i))}function generateReactNext(e){return{viewsData:{fileName:`likec4-views-data`,js:generateViewsDataJs(e),dts:generateViewsDataDTs(e)},components:{fileName:`likec4-components`,...generateComponents()},index:generateIndex()}}function generateComponents(){let e=new t().appendTemplate`
154
+ `.append(n),t(a))}function generateReactNext(e){return{viewsData:{fileName:`likec4-views-data`,js:generateViewsDataJs(e),dts:generateViewsDataDTs(e)},components:{fileName:`likec4-components`,...generateComponents()},index:generateIndex()}}function generateComponents(){let e=new r().appendTemplate`
155
155
  /******************************************************************************
156
156
  * This file was generated
157
157
  * DO NOT EDIT MANUALLY!
@@ -172,7 +172,7 @@ export const likec4model: LikeC4Model<$Aux> = new LikeC4Model(${x.stringify(e.$d
172
172
  return createElement(EmbeddedLikeC4Diagram, { viewId: viewId, views: LikeC4Views, ...props });
173
173
  }
174
174
  /* prettier-ignore-end */
175
- `,n=new t().appendTemplate`
175
+ `,t=new r().appendTemplate`
176
176
  /// <reference types="react" />
177
177
  /******************************************************************************
178
178
  * This file was generated
@@ -196,7 +196,7 @@ export const likec4model: LikeC4Model<$Aux> = new LikeC4Model(${x.stringify(e.$d
196
196
 
197
197
  export declare function EmbeddedLikeC4View({ viewId, ...props }: EmbeddedLikeC4ViewProps): JSX.Element;
198
198
  /* prettier-ignore-end */
199
- `;return{js:a(e),dts:a(n)}}function generateIndex(){let e=new t().appendTemplate`
199
+ `;return{js:o(e),dts:o(t)}}function generateIndex(){let e=new r().appendTemplate`
200
200
  /* prettier-ignore-start */
201
201
  /* eslint-disable */
202
202
 
@@ -214,14 +214,14 @@ export const likec4model: LikeC4Model<$Aux> = new LikeC4Model(${x.stringify(e.$d
214
214
  // export const EmbeddedLikeC4View = lazy(async () => await import("./likec4-components").then(m => ({default: m.EmbeddedLikeC4View})));
215
215
 
216
216
  /* prettier-ignore-end */
217
- `,n=new t().appendTemplate`
217
+ `,t=new r().appendTemplate`
218
218
  /* prettier-ignore-start */
219
219
  /* eslint-disable */
220
220
 
221
221
  export * from "./likec4-components";
222
222
 
223
223
  /* prettier-ignore-end */
224
- `;return{js:a(e),dts:a(n)}}function generateReactTypes(e,t={}){let{useCorePackage:n=!1}=t;C(!e.isParsed(),`can not generate react types for parsed model`);let r=generateAux(e,t);return`
224
+ `;return{js:o(e),dts:o(t)}}function generateReactTypes(e,t={}){let{useCorePackage:n=!1}=t;w(!e.isParsed(),`can not generate react types for parsed model`);let r=generateAux(e,t);return`
225
225
  /* prettier-ignore-start */
226
226
  /* eslint-disable */
227
227
 
@@ -277,4 +277,4 @@ export {
277
277
  ReactLikeC4
278
278
  }
279
279
  /* prettier-ignore-end */
280
- `.trimStart()}export{k as DEFAULT_DRAWIO_ALL_FILENAME,buildDrawioExportOptionsForViews,buildDrawioExportOptionsFromSource,decompressDrawioDiagram,generateD2,generateDrawio,generateDrawioEditUrl,generateDrawioMulti,generateLikeC4Model,generateMermaid,generatePuml,generateReactNext,generateReactTypes,generateViewsDataDTs,generateViewsDataJs,generateViewsDataTs,getAllDiagrams,parseDrawioRoundtripComments,parseDrawioToLikeC4,parseDrawioToLikeC4Multi};
280
+ `.trimStart()}export{A as DEFAULT_DRAWIO_ALL_FILENAME,buildDrawioExportOptionsForViews,buildDrawioExportOptionsFromSource,decompressDrawioDiagram,generateD2,generateDrawio,generateDrawioEditUrl,generateDrawioMulti,generateLikeC4Model,generateMarkdown,generateMermaid,generatePuml,generateReactNext,generateReactTypes,generateViewsDataDTs,generateViewsDataJs,generateViewsDataTs,getAllDiagrams,parseDrawioRoundtripComments,parseDrawioToLikeC4,parseDrawioToLikeC4Multi};