@likec4/core 1.54.0 → 1.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime.mjs";import{B as t,C as n,E as r,G as i,H as a,I as o,J as s,K as c,L as l,M as u,N as d,O as f,P as p,Q as m,R as h,S as g,T as _,V as v,Y as y,Z as ee,_ as te,a as ne,d as re,et as b,g as ie,h as ae,i as oe,k as se,m as ce,n as le,nt as ue,o as de,q as fe,r as pe,rt as x,t as me,tt as he,u as ge,v as _e,w as ve,x as ye,y as S,z as be}from"./libs/remeda.mjs";import{G as C,J as xe,O as w,St as T,U as Se,W as E,Y as D,_t as Ce,b as we,d as Te,dt as Ee,et as De,g as Oe,h as ke,ht as Ae,l as je,lt as Me,n as Ne,o as Pe,p as Fe,q as O,r as Ie,s as Le,tt as Re,u as ze,vt as Be,xt as Ve,y as He}from"./types.mjs";import{$ as k,A as Ue,B as We,D as A,I as j,K as Ge,L as Ke,M as qe,O as M,Q as N,R as Je,U as Ye,V as Xe,Z as Ze,_ as P,a as F,c as I,d as Qe,et as L,g as $e,i as et,j as tt,s as nt,u as R,v as z,w as rt,x as it,y as at}from"./utils.mjs";import{n as ot,t as st}from"./libs/graphology-dag.mjs";import{c as ct,t as B}from"./libs/mnemonist.mjs";import{A as lt,C as ut,D as dt,E as ft,M as V,N as pt,O as mt,T as ht,_ as gt,c as _t,d as vt,f as yt,g as bt,h as xt,j as St,m as Ct,n as wt,o as Tt,p as Et,q as Dt,r as Ot,t as kt,v as At,w as jt,y as Mt}from"./model.mjs";import{r as Nt}from"./manual-layout.mjs";import{t as Pt}from"./libs/graphology.mjs";function Ft(e,t){let n=[],r=e.parent;for(;r;){let e=k(t.get(r),`Parent node ${r} not found`);n.push(e),r=e.parent}return n}function It(e,t){for(let n of t){let t=e.get(n.source),i=e.get(n.target);N(t,`Source node ${n.source} not found`),N(i,`Target node ${n.target} not found`),t.outEdges.push(n.id),i.inEdges.push(n.id);let a=Ft(t,e),o=Ft(i,e),s=a.length>0&&o.length>0?r(Ze(ge(a),ge(o))):null;n.parent=s?s.id:null;for(let e of a){if(e===s)break;e.outEdges.push(n.id)}for(let e of o){if(e===s)break;e.inEdges.push(n.id)}}}var Lt=ot(),Rt=e(st(),1);function zt(e){let t=[],n=[...e],r;for(;r=n.shift();){let e=r.parent;if(e){let r=[];for(;e;){let t=n.findIndex(t=>t.id===e);if(t<0)break;let[i]=n.splice(t,1);if(!i)throw Error(`Invalid state, should not happen`);r.unshift(i),e=i.parent}t.push(...r)}t.push(r)}return t}function Bt(e){return e.forEach(t=>{t.children.length>0&&(t.children=e.reduce((e,n)=>(n.parent===t.id&&e.push(n.id),e),[]))}),e}function Vt(e){let t=zt([...e.nodes.values()]),n=[...e.edges];if(t.length<2||n.length===0)return{nodes:t,edges:n};let r=t=>k(e.nodes.get(t)),a=new Pt({multi:!0,allowSelfLoops:!0,type:`directed`}),[o,s]=_e(b(n,_(e=>{let t=r(e.source),n=r(e.target),i=e.parent?r(e.parent):null;return{id:e.id,edge:e,parent:i,source:t,target:n}})),({source:e,target:t})=>e.children.length===0&&t.children.length===0),c=[],l=e=>{a.mergeNode(e.source),a.mergeNode(e.target),c.push(e),(0,Rt.default)(a,e.source,e.target)||a.mergeDirectedEdge(e.source,e.target)};for(let{edge:t,source:n,target:s}of o)if(l(t),s.parent&&s.parent!==t.parent&&b(Ft(s,e.nodes),ne(e=>e.inEdges.includes(t.id)),i(e=>{a.mergeNode(e.id),(0,Rt.default)(a,t.source,e.id)||a.mergeDirectedEdge(t.source,e.id),(0,Rt.default)(a,e.id,t.target)||a.mergeDirectedEdge(e.id,t.target)})),n.parent){let e=r(n.parent);a.mergeNode(e.id),(0,Rt.default)(a,e.id,n.id)||a.mergeDirectedEdge(e.id,n.id),s.parent&&s.parent!==n.parent&&((0,Rt.default)(a,e.id,s.parent)||a.mergeDirectedEdge(e.id,s.parent))}for(let{edge:e}of s)l(e);N(c.length===n.length,`Not all edges were added to the graph`);let u=(0,Lt.topologicalSort)(a),d=[],f=t.slice();for(let e of u){let t=f.findIndex(t=>t.id===e);N(t>=0,`Node "${e}" not found`),d.push(...f.splice(t,1))}return f.length>0&&d.length>0&&(d=d.flatMap(e=>{if(f.length===0)return e;let n=t.slice(0,t.indexOf(e)).filter(e=>f.includes(e));return n.length>0?(f=f.filter(e=>!n.includes(e)),[...n,e]):e})),d.push(...f),{nodes:Bt(zt(d)),edges:c}}function Ht(e){return e.hash=et({id:e.id,__:e._type??`element`,autoLayout:e.autoLayout,nodes:b(e.nodes,_(e=>({id:e.id,icon:f(e.icon)&&e.icon!==`none`?`Y`:`N`,title:e.title,description:Me(e.description),technology:e.technology??null,shape:e.shape,size:e.style.size??null,iconSize:e.style.iconSize??null,iconPosition:e.style.iconPosition??null,textSize:e.style.textSize??null,padding:e.style.padding??null,children:e.children})),ve(({id:e,...t})=>[e,t])),edges:b(e.edges,_(e=>({source:e.source,target:e.target,label:e.label,description:Me(e.description),technology:e.technology??null,dir:e.dir,head:e.head,tail:e.tail,line:e.line})),ve(({source:e,target:t,...n})=>[`${e}:${t}`,n]))}),e}var Ut=class{get Ctx(){throw Error(`Should not be called in runtime`)}constructor(e){this.state=e}get elements(){return this.state.elements}get explicits(){return this.state.explicits}get final(){return this.state.final}get connections(){return this.state.connections}isEmpty(){return this.elements.size===0&&this.connections.length===0&&this.explicits.size===0&&this.final.size===0}},Wt=class{excluded={elements:new Set,connections:[]};constructor(e,t){this.memory=e,this.expression=t}markedToMoveExplicitToImplicit=!1;_removeElement(e){this.excluded.elements.add(e)}exclude(e){if(!e)return this;if(M(e)){for(let t of e)this._removeElement(t);return this}return this._removeElement(e),this}_removeConnection(e){this.excluded.connections.push(e)}excludeConnections(e,t){if(be(t)&&(N(!this.markedToMoveExplicitToImplicit,`Already marked to move explicits`),this.markedToMoveExplicitToImplicit=t),M(e)){for(let t of e)this._removeConnection(t);return this}return this._removeConnection(e),this}isDirty(){return this.excluded.elements.size>0||this.excluded.connections.length>0}isEmpty(){return!this.isDirty()}filterForMoveToImplicits(e){return this.markedToMoveExplicitToImplicit||this.excluded.elements.size>0?e:new Set}moveDisconnectedExplicitsToImplicits(e){let t=F(new Set(this.memory.connections.flatMap(e=>[e.source,e.target])),new Set(e.connections.flatMap(e=>[e.source,e.target])));return t=I(t,e.elements),t=b(t,A(t=>e.explicits.has(t)&&!at(e.final,Ke(t))),z()),t.size>0&&(t=this.filterForMoveToImplicits(t),e.explicits=F(e.explicits,t),e.final=F(e.final,t)),e}removeElements(e){return e.elements=F(e.elements,this.excluded.elements),e.explicits=F(e.explicits,this.excluded.elements),e.final=F(e.final,this.excluded.elements),e}removeConnections(e){let t=this.excluded.connections.reduce((e,t)=>{let n=e.get(t.id);return n?e.set(t.id,n.mergeWith(t)):e.set(t.id,t),e},new Map),n=new Set;e.connections=e.connections.reduce((e,r)=>{let i=t.get(r.id);if(i){n.add(r.source),n.add(r.target);let t=r.difference(i);t.nonEmpty()&&e.push(t)}else e.push(r);return e},[]);for(let t of e.connections)n.delete(t.source),n.delete(t.target),t.boundary&&e.elements.has(t.boundary)&&n.delete(t.boundary);return n.size===0?e:(n=F(n,e.explicits),e.final=F(e.final,n),e)}precommit(e){return e}postcommit(e){return N(F(e.explicits,e.elements).size===0,`Explicits must be subset of elements`),N(F(e.final,e.elements).size===0,`Final elements must be subset of elements`),e}commit(){let e=this.precommit(this.memory.mutableState());if(this.excluded.elements.size>0){let t=e.connections.filter(e=>this.excluded.elements.has(e.source)||this.excluded.elements.has(e.target)).flatMap(t=>[t,...gt(e.connections,t).map(e=>e.intersect(t))]).filter(e=>e.nonEmpty());this.excludeConnections(t)}return this.excluded.connections.length>0&&(e=this.removeConnections(e)),this.excluded.elements.size>0&&(e=this.removeElements(e)),this.memory.update(this.postcommit(e))}},Gt=class{explicits=new Set;implicits=new Set;_ordered=new Set;_connections=[];constructor(e,t){this.memory=e,this.expression=t}get elements(){return this.explicits}get connections(){return this._connections}mergedConnections(){return dt([...this.memory.connections,...this._connections])}connectWithExisting(e,t){throw Error(`Method not implements, depends on the model`)}_addExplicit(e){this._ordered.add(e),this.explicits.add(e),this.implicits.delete(e)}addExplicit(e){if(!e)return this;if(M(e)){for(let t of e)this._addExplicit(t);return this}return this._addExplicit(e),this}_addImplicit(e){this.explicits.has(e)||(this._ordered.add(e),this.implicits.add(e))}addImplicit(e){if(!e)return this;if(M(e)){for(let t of e)this._addImplicit(t);return this}return this._addImplicit(e),this}_addConnection(e){this._connections.push(e),this._addImplicit(e.source),this._addImplicit(e.target)}addConnections(e){if(M(e)){for(let t of e)this._addConnection(t);return this}return this._addConnection(e),this}isDirty(){return this.explicits.size>0||this.implicits.size>0||this._connections.length>0}isEmpty(){return!this.isDirty()}precommit(e){return e}postcommit(e){return e}processConnections(e){return e}commit(){let e=this.precommit(this.memory.mutableState()),t=new Set;if(this._connections.length>0){let[n,r]=_e(this._connections,t=>e.final.has(t.source));e.connections=this.processConnections(dt([...e.connections,...n,...r])),t=new Set(e.connections.flatMap(e=>[e.source,e.target]))}return e.elements=R(e.elements,this._ordered,this.explicits,t,this.implicits),e.explicits=I(e.elements,R(e.explicits,this.explicits)),e.final=I(e.elements,R(e.final,this.explicits,t)),this.memory.update(this.postcommit(e))}};function Kt(e,t=`final`){let n=Ye(P(t===`final`?e.final:e.elements)),r=new Set(e.connections.flatMap(e=>[e.source,e.target])),i=new Set(n),a=new B.default(()=>null),o=n.reduce((e,t,n,r)=>(e.set(t,r.slice(n+1).filter(e=>j(t,e)).map(e=>(i.delete(e),e)).reduce((e,n)=>(e.some(e=>j(e,n))||(e.push(n),a.set(n,t)),e),[])),e),new B.default(()=>[]));return{root:i,connected:r,hasInOut:t=>e.connections.some(V.isAnyInOut(t.id)),parent:e=>a.get(e),children:e=>o.get(e)}}var qt=class extends Wt{};function H(e){if(E.isCustom(e))return H(e.custom.expr);if(E.isWhere(e)){let t=H(e.where.expr),n=w(e.where.condition);return e=>t(e)&&n(e)}if(E.isElementKindExpr(e))return e.isEqual?t=>t.kind===e.elementKind:t=>t.kind!==e.elementKind;if(E.isElementTagExpr(e))return e.isEqual?({tags:t})=>t.includes(e.elementTag):({tags:t})=>!t.includes(e.elementTag);if(E.isWildcard(e))return()=>!0;if(E.isModelRef(e)){let t=D.flatten(e.ref);if(e.selector===`expanded`)return e=>e.id===t||We(e.id)===t;if(e.selector===`descendants`||e.selector===`children`){let e=t+`.`;return t=>t.id.startsWith(e)}return e=>e.id===t}L(e)}function Jt(e,t,n){let{shape:r,color:a,icon:o,...s}=e.style,c=!l(s);b(n,y(d(Ee)),y(t),i(t=>{t.shape=r??t.shape,t.color=a??t.color,h(o)&&(t.icon=o),h(e.notation)&&(t.notation=e.notation),c&&(t.style={...t.style,...s})}))}function Yt(e,t){for(let n of e)!we(n)||n.targets.length===0||Jt(n,x(n.targets.map(H)),t);return t}var Xt=class e{static kind=De;constructor(e,t,n=null,r=new Set){this.id=e,this.viewRule=t,this.parent=n,this.elements=r}isEmpty(){return this.elements.size===0}update(t){return new e(this.id,this.viewRule,this.parent,t)}clone(){return new e(this.id,this.viewRule,this.parent,new Set(this.elements))}},Zt=class extends Wt{excludeRelations(e){return b(this.memory.connections,y(t=>nt(t.relations,e)),i(t=>{this.excludeConnections(t.update(I(t.relations,e)))})),this}precommit(e){if(this.excluded.elements.size>0){let e=new Set([...this.excluded.elements].flatMap(e=>[...e.incoming(`direct`),...e.outgoing(`direct`)]));this.excludeRelations(e)}return e}postcommit(e){let t=F(this.memory.explicits,e.explicits);for(let n of t)e.explicitFirstSeenIn.delete(n);let n=F(this.memory.elements,e.elements);for(let t of n)e.lastSeenIn.delete(t);return e}},Qt=class extends Zt{constructor(e,t){super(e,t),this.memory=e,this.expression=t}};const{findConnection:$t,findConnectionsBetween:en}=Et;var tn=class extends Gt{connectWithExisting(e,t=`both`){let n=this._connections.length,r=()=>this._connections.length>n;if(!M(e)){if(t===`in`||t===`both`)for(let t of this.memory.elements)this.addConnections($t(t,e,`directed`));return(t===`out`||t===`both`)&&this.addConnections(en(e,this.memory.elements,`directed`)),r()}let i=[...e];if(t===`in`||t===`both`)for(let e of this.memory.elements)this.addConnections(en(e,i,`directed`));if(t===`out`||t===`both`)for(let e of i)this.addConnections(en(e,this.memory.elements,`directed`));return r()}addImplicitWithinScope(e){e&&(!this.memory.scope||j(this.memory.scope,e))&&this.addImplicit(e)}processConnections(e){return Se.isRelationExpr(this.expression)||b(e,i(({source:e,target:t,boundary:n})=>{b(me([...P(e.ancestors()).reverse(),e],[...P(t.ancestors()).reverse(),t]),ee(([e,t])=>e===t),de(1),i(([r,i])=>{if(r===e&&i===t){this.addImplicitWithinScope(n);return}r!==e&&this.addImplicitWithinScope(r),i!==t&&this.addImplicitWithinScope(i)}))})),e}postcommit(e){let t=F(e.explicits,this.memory.explicits);for(let n of t)e.explicitFirstSeenIn.set(n,`@root`);return e}},nn=class extends tn{constructor(e,t){super(e,t),this.memory=e,this.expression=t}postcommit(e){let t=F(e.explicits,this.memory.explicits);for(let n of t)e.explicitFirstSeenIn.set(n,this.memory.activeGroupId);for(let t of[...this.explicits,...this.implicits])e.lastSeenIn.set(t,this.memory.activeGroupId);return e}},rn=class e extends Ut{static empty(t){return new e({elements:new Set,explicits:new Set,final:new Set,connections:[],groups:[],explicitFirstSeenIn:new Map,lastSeenIn:new Map},t)}constructor(e,t){super(e),this.state=e,this.scope=t}get groups(){return this.state.groups}get explicitFirstSeenIn(){return this.state.explicitFirstSeenIn}get lastSeenIn(){return this.state.lastSeenIn}stageInclude(e){return new tn(this,e)}stageExclude(e){return new Zt(this,e)}mutableState(){return{elements:new Set(this.state.elements),explicits:new Set(this.state.explicits),final:new Set(this.state.final),connections:[...this.state.connections],groups:this.state.groups.map(e=>e.clone()),explicitFirstSeenIn:new Map(this.state.explicitFirstSeenIn),lastSeenIn:new Map(this.state.lastSeenIn)}}update(t){return new e({...this.state,...t},this.scope)}},an=class e extends rn{static enter(t,n){let r=`@gr${t.groups.length+1}`;if(t instanceof e){let i=ct.default.from([...t.stack].reverse()),a=t.mutableState();return a.groups.push(new Xt(r,n,t.activeGroupId)),i.push(r),new e(a,t.scope,i)}let i=t.mutableState();i.groups.push(new Xt(r,n,null));let a=ct.default.of(r);return new e(i,t.scope,a)}constructor(e,t,n){super(e,t),this.state=e,this.scope=t,this.stack=n}get activeGroupId(){return k(this.stack.peek(),`Stack must not be empty`)}mutableState(){return{...super.mutableState()}}update(t){return new e({...this.state,...t},this.scope,this.stack)}stageInclude(e){return new nn(this,e)}stageExclude(e){return new Qt(this,e)}leave(){let t=this.mutableState();return this.stack.pop(),this.stack.peek()?new e(t,this.scope,this.stack):new rn(t,this.scope)}};function on(e,t){let n;for(;e.parent&&(n=t.get(e.parent));){let t=n.depth??1;if(n.depth=Math.max(t,(e.depth??0)+1),n.depth===t)break;e=n}}function sn(e){let{id:t,title:n,...r}=g(e.$element,[`summary`,`description`,`metadata`,`style`,`tags`]),{color:i,icon:a,shape:o,...s}=e.style;return T({id:t,title:n,modelRef:t,shape:o,color:i,icon:a,style:s,description:Ve(e.$element),tags:[...e.tags],metadata:e.$element.metadata,...r})}function cn({defaults:e},t,n){let r=new Map,i=new Map;n?.forEach(({id:t,parent:n,viewRule:a,elements:o})=>{n&&k(r.get(n),`Parent group node ${n} not found`).children.push(t),r.set(t,{id:t,parent:n,kind:De,title:a.title??``,color:a.color??e.group.color??e.color,shape:`rectangle`,children:[],inEdges:[],outEdges:[],level:0,depth:0,tags:[],style:T({border:a.border??e.group.border,opacity:a.opacity??e.group.opacity,size:a.size,multiple:a.multiple,padding:a.padding,textSize:a.textSize})});for(let e of o)i.set(e.id,t)}),Array.from(t).sort(qe).forEach(({id:e,...t})=>{let n=We(e),a=0,o;for(;n&&(o=r.get(n),!o);)n=We(n);let s=t.modelRef??e;if(!o&&i.has(s)){let e=k(i.get(s));o=r.get(e),n=e}o&&(o.children.length==0&&(o.depth=1,on(o,r)),o.children.push(e),a=o.level+1);let c=T({id:e,parent:n,level:a,children:[],inEdges:[],outEdges:[],...t});r.set(e,c)});let a=new Map;return n?.forEach(({id:e})=>{a.set(e,k(r.get(e)))}),t.forEach(({id:e})=>{a.set(e,k(r.get(e)))}),a}function ln(e){let{title:t,description:n=null}=e;return{...t&&{title:t,description:n},...te(e,[`color`,`technology`,`head`,`line`,`tail`,`kind`,`navigateTo`])}}function un(e,t){let n=b(e,re((e,t)=>(f(t.title)&&!e.title.includes(t.title)&&e.title.push(t.title),f(t.description)&&!e.description.some(v(t.description))&&e.description.push(t.description),f(t.technology)&&!e.technology.includes(t.technology)&&e.technology.push(t.technology),f(t.kind)&&!e.kind.includes(t.kind)&&e.kind.push(t.kind),f(t.color)&&!e.color.includes(t.color)&&e.color.push(t.color),f(t.line)&&!e.line.includes(t.line)&&e.line.push(t.line),f(t.head)&&!e.head.includes(t.head)&&e.head.push(t.head),f(t.tail)&&!e.tail.includes(t.tail)&&e.tail.push(t.tail),f(t.navigateTo)&&!e.navigateTo.includes(t.navigateTo)&&e.navigateTo.push(t.navigateTo),t.tags&&e.tags.push(...t.tags),e),{title:[],description:[],technology:[],kind:[],head:[],tail:[],color:[],tags:[],line:[],navigateTo:[]})),r=S(n.title)??(n.title.length>1?`[...]`:void 0),i=oe(n.tags),a=T({title:r,description:S(n.description),technology:S(n.technology),kind:S(n.kind),head:S(n.head),tail:S(n.tail),color:S(n.color),line:S(n.line),navigateTo:S(n.navigateTo),...Ge(i)&&{tags:i}});if(t){let e=ln(t);a=ie({...a,...e},f)}return u(a.title)&&f(a.technology)&&(a.title=`[${a.technology}]`,delete a.technology),a}const{findConnection:dn,findConnectionsBetween:U,findConnectionsWithin:fn}=Ct;function W(e,t){let n=e.element(t.ref.deployment);if(n.isDeploymentNode()){if(t.selector===`children`)return[...n.children()];if(t.selector===`expanded`)return[n,...n.children()];if(t.selector===`descendants`)return[...n.descendants()]}return[n]}function pn(e,t){let n=e.$model.element(t.ref.model);return t.selector===`children`?[...n.children()]:t.selector===`expanded`?[n,...n.children()]:t.selector===`descendants`?[...n.descendants()]:[n]}function mn(e){if(O.isWildcard(e))return()=>!0;if(O.isElementTagExpr(e)||O.isElementKindExpr(e))throw Error(`element kind and tag expressions are not supported in deployment view rules`);if(O.isDeploymentRef(e)){let t=e.ref.deployment;if(e.selector===`expanded`){let e=t+`.`;return n=>n.id===t||n.id.startsWith(e)}if(e.selector===`descendants`){let e=t+`.`;return t=>t.id.startsWith(e)}return e.selector===`children`?e=>We(e.id)===t:e=>e.id===t}if(O.isModelRef(e)){let t=e.ref.model;if(e.selector===`expanded`){let e=t+`.`;return n=>{let r=n.modelRef??null;return r?r===t||r.startsWith(e):!0}}if(e.selector===`descendants`){let e=t+`.`;return t=>{let n=t.modelRef??null;return n?n.startsWith(e):!0}}return e.selector===`children`?e=>{let n=e.modelRef??null;return n?We(n)===t:!0}:e=>{let n=e.modelRef??null;return n?n===t:!0}}L(e)}function hn(e){return Ve(e.$instance)??Ve(e.element.$element)}function gn(e){let t=e.id,n=e.onlyOneInstance();return T({id:t,deploymentRef:t,title:e.title,kind:e.kind,technology:e.technology??void 0,links:m(e.links,1)?[...e.links]:void 0,notation:e.$node.notation??void 0,color:e.color,shape:e.shape,modelRef:n?.element.id,icon:e.style.icon,description:Ve(e.$node)??void 0,tags:[...e.tags],style:g(e.style,[`icon`,`shape`,`color`])})}function _n(e){let t=e.$instance,n=e.element,{icon:r,color:i,shape:a,...o}=e.style,s=[...n.links,...t.links??[]];return T({id:e.id,kind:`instance`,title:e.title,description:hn(e)??void 0,technology:e.technology??void 0,tags:[...e.tags],links:m(s,1)?s:void 0,icon:r,color:i,shape:a,style:o,deploymentRef:t.id,modelRef:n.id,notation:t.notation})}function vn(e){return e.isInstance()?_n(e):gn(e)}function yn(e){return e.reduce((e,t)=>{let n=[...t.relations.model,...t.relations.deployment];N(m(n,1),`Edge must have at least one relation`);let r=t.source.$model.$styles.defaults,i=t.source.id,a=t.target.id,{title:o,color:s=r.relationship.color,line:c=r.relationship.line,head:l=r.relationship.arrow,...u}=un(n.map(e=>e.$relationship)),d=T({id:t.id,parent:t.boundary?.id??null,source:i,target:a,label:o??null,relations:n.map(e=>e.id),color:s,line:c,head:l,...u}),f=e.find(e=>e.source===a&&e.target===i);if(f&&d.label===f.label){f.dir=`both`;let n=f.head??d.head??t.source.$model.$styles.defaults.relationship.arrow;return f.head??=n,f.tail??=n,d.color&&(f.color??=d.color),d.line&&(f.line??=d.line),e}return e.push(d),e},[])}function bn(e,t){let n=cn(e.$styles,[...t.final].map(vn));for(let t of n.values()){if(!t.deploymentRef||!t.modelRef||t.children.length>0)continue;let n=e.deployment.element(t.deploymentRef),r=n.isDeploymentNode()&&n.onlyOneInstance();if(!r)continue;t.title===n.name&&(t.title=r.title),t.description??=hn(r)??null,t.technology??=r.technology,l(t.tags)&&(t.tags=[...r.tags]),(!t.links||l(t.links))&&m(r.links,1)&&(t.links=[...r.links]);let i=e.$styles.defaults;t.shape===i.shape&&t.shape!==r.shape&&(t.shape=r.shape,t.notation=null),t.color===i.color&&t.color!==r.color&&(t.color=r.color,t.notation=null),!t.icon&&r.icon&&(t.icon=r.icon)}return n}function xn(e,t){for(let n of e)!we(n)||n.targets.length===0||Jt(n,x(n.targets.map(mn)),t);return t}function Sn(e){let t=new B.default(()=>[]);for(let n of e)for(let e of n.relations.model)t.get(e).push(n);let n=new B.default(()=>new Set);for(let[e,r]of t)m(r,2)&&b(r,c(e=>[{group:`$source-${e.source.id}`,conn:e},{group:`$target-${e.target.id}`,conn:e}]),a(ce(`group`)),pe(),y(m(2)),i(ae(_(ce(`conn`)),mt(`desc`),ee((e,t,n)=>t===0||e.boundary===n[t-1].boundary),i(t=>{n.get(t).add(e)}))));return n}function Cn(e){e=dt(e);let t=Sn(e);for(let n of e){let{source:e,target:r}=n,i=n.relations.model;if(e.isDeploymentNode()!==r.isDeploymentNode()){let r=e.isDeploymentNode()?e:n.target;N(r.isDeploymentNode());let a=I(i,r.internalModelRelationships());for(let e of a)t.get(n).add(e);continue}if(e.isDeploymentNode()&&r.isDeploymentNode()){let i=R(I(n.relations.model,e.internalModelRelationships()),I(n.relations.model,r.internalModelRelationships()));for(let e of i)t.get(n).add(e)}}return b(t.entries(),it(([e,t])=>e.update({model:t,deployment:null})),P())}function wn(e){return bt(e,Cn(e))}function Tn(e){return b(e,dt,re((t,n)=>{let{source:r,target:i,relations:a}=n;if(r.isInstance()&&i.isInstance())return t;let o=Dt.empty();if(r.isDeploymentNode()&&i.isDeploymentNode()){let[e]=dn(i,r,`directed`);e&&(o=a.intersect(e.relations))}for(let t of e)ht(t,n)&&(o=o.union(a.intersect(t.relations)));return o.nonEmpty&&t.push(new lt(r,i,o)),t},[]))}function En(e){return bt(e,Tn(e))}var Dn=class extends Gt{connectWithExisting(e,t=`both`){let n=this._connections.length,r=()=>this._connections.length>n;if(!M(e)){if(t===`in`||t===`both`)for(let t of this.memory.elements)this.addConnections(dn(t,e,`directed`));return(t===`out`||t===`both`)&&this.addConnections(U(e,this.memory.elements,`directed`)),r()}let i=[...e];if(t===`in`||t===`both`)for(let e of this.memory.elements)this.addConnections(U(e,i,`directed`));if(t===`out`||t===`both`)for(let e of i)this.addConnections(U(e,this.memory.elements,`directed`));return r()}processConnections(e){let t=b(e,wn,En);return b(t,i(({source:e,target:t,boundary:n})=>{b(me([...P(e.ancestors()).reverse(),e],[...P(t.ancestors()).reverse(),t]),ee(([e,t])=>e===t),de(1),i(([r,i])=>{if(e===r&&t===i){this.addImplicit(n);return}r!==e&&r.isDeploymentNode()&&!r.onlyOneInstance()&&this.addImplicit(r),i!==t&&i.isDeploymentNode()&&!i.onlyOneInstance()&&this.addImplicit(i)}))})),t}},On=class e extends Ut{static empty(){return new e({elements:new Set,explicits:new Set,final:new Set,connections:[]})}stageInclude(e){return new Dn(this,e)}stageExclude(e){return new qt(this,e)}mutableState(){return{elements:new Set(this.state.elements),explicits:new Set(this.state.explicits),final:new Set(this.state.final),connections:[...this.state.connections]}}update(t){return new e({...this.state,...t})}equals(t){return t instanceof e&&v(this.state,t.state)}diff(e){return{added:{elements:P(F(e.elements,this.elements)),explicits:P(F(e.explicits,this.explicits)),final:P(F(e.final,this.final)),connections:P(bt(e.connections,this.connections))},removed:{elements:P(F(this.elements,e.elements)),explicits:P(F(this.explicits,e.explicits)),final:P(F(this.final,e.final)),connections:bt(this.connections,e.connections)}}}toString(){return[`final:`,...[...this.final].map(e=>` `+e.id),`connections:`,...this.connections.map(e=>` `+e.expression)].join(`
|
|
2
|
-
`)}[St](e,t,n){return this.toString()}};const kn={include:({expr:e,model:t,memory:n,stage:r})=>{let i=w(e.where.condition);return Vn(`include`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})},exclude:({expr:e,model:t,memory:n,stage:r})=>{let i=w(e.where.condition);return Vn(`exclude`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})}},An={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(O.isWildcard(e.incoming)){for(let e of a){if(e.allOutgoing.isEmpty)continue;let t=K(U(e,[...Kn(e)],`directed`),i);r.addConnections(t)}return r}N(O.isDeploymentRef(e.incoming),`Only deployment refs are supported in include`);let o=W(t,e.incoming);for(let e of a){let t=K(U(e,o,`directed`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(O.isElementTagExpr(e.incoming)||O.isElementKindExpr(e.incoming))throw Error(`element kind and tag expressions are not supported in exclude`);if(O.isModelRef(e.incoming))return G(Mn(t,e.incoming),{stage:r,memory:n},i);if(O.isWildcard(e.incoming))return r;let a=jn(W(t,e.incoming)),o=b(n.connections,y(a),K(i));return r.excludeConnections(o),r}};function jn(e){return x(e.map(e=>{let t=t=>t===e||j(e,t);return e=>!t(e.source)&&t(e.target)}))}function Mn(e,t){let n=pn(e,t);return new Set(n.flatMap(e=>[...e.allIncoming]))}const Nn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(O.isWildcard(e.outgoing)){for(let e of a)if(!e.allIncoming.isEmpty)for(let t of Kn(e)){let n=K(dn(t,e,`directed`),i);r.addConnections(n)}return r}N(O.isDeploymentRef(e.outgoing),`Only deployment refs are supported in include`);let o=W(t,e.outgoing);for(let e of o){let t=K(U(e,a,`directed`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(O.isElementTagExpr(e.outgoing)||O.isElementKindExpr(e.outgoing))throw Error(`element kind and tag expressions are not supported in exclude`);if(O.isModelRef(e.outgoing))return G(Fn(t,e.outgoing),{stage:r,memory:n},i);if(O.isWildcard(e.outgoing))return r;let a=Pn(W(t,e.outgoing)),o=b(n.connections,y(a),K(i));return r.excludeConnections(o),r}};function Pn(e){return x(e.map(e=>{let t=t=>t===e||j(e,t);return e=>t(e.source)&&!t(e.target)}))}function Fn(e,t){let n=pn(e,t);return new Set(n.flatMap(e=>[...e.allOutgoing]))}const In={include:({expr:{source:e,target:t,isBidirectional:n=!1},model:r,stage:i,where:a})=>{if(O.isElementTagExpr(e)||O.isElementKindExpr(e)||O.isElementTagExpr(t)||O.isElementKindExpr(t))throw Error(`element kind and tag expressions are not supported in include`);N(!O.isModelRef(e),`Invalid source model ref in direct relation`),N(!O.isModelRef(t),`Invalid target model ref in direct relation`);let o=O.isWildcard(e),s=O.isWildcard(t),l=n?`both`:`directed`,u;switch(!0){case o&&s:u=b(fn(r.instances()),K(a),_(e=>(i.addImplicit(e.boundary),e)));break;case!o&&s:{let t=W(r,e),i=Pn(t),o=i;if(n){let e=jn(t);o=t=>i(t)!==e(t)}u=b(t,c(e=>U(e,Kn(e),l)),y(o),K(a));break}case o&&!s:{let e=W(r,t),i=jn(e),o=i;if(n){let t=Pn(e);o=e=>t(e)!==i(e)}u=b(e,c(e=>[...Kn(e)].flatMap(t=>dn(t,e,l))),y(o),K(a));break}default:{N(!o,`Inference failed - source should be a deployment ref`),N(!s,`Inference failed - target should be a deployment ref`);let n=W(r,e),i=W(r,t),d=Pn(n),f=jn(i);u=b(n,c(e=>U(e,i,l)),y(e=>d(e)&&f(e)),K(a))}}return i.addConnections(u),O.isDeploymentRef(e)&&p(e.selector)&&i.addImplicit(r.element(e.ref.deployment)),O.isDeploymentRef(t)&&p(t.selector)&&i.addImplicit(r.element(t.ref.deployment)),i},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=mn(e.target),o=mn(e.source),s;switch(!0){case O.isWildcard(e.source)&&O.isWildcard(e.target):return r.excludeConnections(K(n.connections,i)),r;case O.isModelRef(e.source)&&O.isModelRef(e.target):return s=Ln({source:e.source,target:e.target,expr:e,model:t}),G(s,{stage:r,memory:n},i);case O.isModelRef(e.source)&&O.isWildcard(e.target):return s=Fn(t,e.source),G(s,{stage:r,memory:n},i);case O.isModelRef(e.source):return s=Fn(t,e.source),G(s,{stage:r,memory:n},i,e=>a(e.target));case O.isModelRef(e.target):return s=Mn(t,e.target),G(s,{stage:r,memory:n},i,e=>o(e.source));default:let c=t=>o(t.source)&&a(t.target)||e.isBidirectional===!0&&o(t.target)&&a(t.source),l=b(n.connections,y(c),K(i));return l.length===0||r.excludeConnections(l),r}}};function Ln({source:e,target:t,expr:n,model:r}){let i=pn(r,e),a=pn(r,t),o=n.isBidirectional?`both`:`directed`,s=[];for(let e of i)s.push(...yt(e,a,o));return new Set(s.flatMap(e=>[...e.relations]))}const Rn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(O.isWildcard(e.inout)){for(let e of a){let t=Un(U(e,[...Kn(e)],`both`),i);r.addConnections(t)}return r}N(O.isDeploymentRef(e.inout),`Only deployment refs are supported in include`);let o=W(t,e.inout);for(let e of a){let t=Un(U(e,o,`both`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(O.isElementTagExpr(e.inout)||O.isElementKindExpr(e.inout))throw Error(`element kind and tag expressions are not supported in exclude`);if(O.isModelRef(e.inout)){let a=pn(t,e.inout);return a.length===0?r:G(R(new Set,...a.flatMap(e=>[e.allIncoming,e.allOutgoing])),{stage:r,memory:n},i)}if(O.isWildcard(e.inout))return r;let a=W(t,e.inout),o=jn(a),s=Pn(a),c=b(n.connections,y(e=>o(e)!==s(e)),K(i));return r.excludeConnections(c),r}},zn={include:({expr:e,model:t,memory:n,stage:r})=>{let i=w(e.where.condition);return Vn(`include`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})},exclude:({expr:e,model:t,memory:n,stage:r})=>{let i=w(e.where.condition);return Vn(`exclude`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})}},Bn={include:({model:e,stage:t,where:n})=>{let r=[],i=b([...e.roots()],q(n),_(e=>(e.onlyOneInstance()||r.push(...e.children()),e)));return t.addExplicit(i),r.length>1&&t.addConnections(fn([...i,...r])),t},exclude:({stage:e,memory:t,where:n})=>{let r=b([...t.elements],q(n));return e.exclude(r),e}};function Vn(e,{expr:t,where:n,...r}){switch(!0){case O.isElementTagExpr(t):case O.isElementKindExpr(t):throw Error(`element kind and tag expressions are not supported in deployment view rules`);case xe.isCustom(t):case O.isCustom(t):case O.isModelRef(t):return;case O.isWhere(t):return kn[e]({...r,expr:t,where:n});case xe.isWhere(t):return zn[e]({...r,expr:t,where:n});case O.isDeploymentRef(t):return qn[e]({...r,expr:t,where:n});case O.isWildcard(t):return Bn[e]({...r,expr:t,where:n});case xe.isDirect(t):return In[e]({...r,expr:t,where:n});case xe.isInOut(t):return Rn[e]({...r,expr:t,where:n});case xe.isOutgoing(t):return Nn[e]({...r,expr:t,where:n});case xe.isIncoming(t):return An[e]({...r,expr:t,where:n});default:L(t)}}function G(e,{stage:t,memory:n},r,i=()=>!0){if(e.size===0)return t;let a=b(n.connections,y(e=>i(e)),y(t=>nt(t.relations.model,e)),_(t=>t.update({deployment:null,model:I(t.relations.model,e)})),K(r),y(e=>e.nonEmpty()));return a.length===0?t:t.excludeConnections(a)}function Hn(e,t){return K(e,t).nonEmpty()}function K(...e){if(e.length===1)return t=>K(t,e[0]);let[n,r]=e;return r===null?n:t(n)?n.map(e=>K(e,r)).filter(e=>e.nonEmpty()):n.update({model:new Set([...n.relations.model.values()].filter(e=>r(Gn(n)(e)))),deployment:new Set([...n.relations.deployment.values()].filter(e=>r(Gn(n)(e))))})}function q(...e){if(e.length===1)return t=>q(t,e[0]);let[n,r]=e;return t(n)?n.filter(e=>q(e,r)):r?.(Wn(n,n))??!0}function Un(e,t){return t?b(e,y(e=>Hn(e,t))):e}function Wn(e,t){if(Tt(e)){let n=wt(t)&&kt(t)?t:null;return{kind:e.kind,tags:[...e.tags,...n?.tags??[]],metadata:e.metadata}}if(_t(e))return te(e.element,[`tags`,`kind`,`metadata`]);if(kt(e))return{kind:e.element.kind,tags:[...e.tags,...e.element.tags],metadata:e.metadata};if(Ot(e))return te(e,[`tags`,`kind`,`metadata`]);L(e)}function Gn(e){return t=>({tags:t.tags,kind:t.kind,metadata:t.metadata,source:Wn(t.source,e.source),target:Wn(t.target,e.target)})}function Kn(e){let t=new Set;for(let n of e.descendingSiblings())t.add(n);return t}const qn={include:e=>{let{expr:t,where:n}=e,r=e.model.element(t.ref.deployment);if(kt(r))return q(r,n)&&(e.stage.addExplicit(r),e.stage.connectWithExisting(r)),e.stage;switch(!0){case t.selector===`expanded`:Yn(r,e);break;case t.selector===`children`:Jn(r,e);break;case t.selector===`descendants`:Xn(r,e);break;default:q(r,n)&&(e.stage.addExplicit(r),e.stage.connectWithExisting(r))}return e.stage},exclude:({expr:e,stage:t,memory:n,where:r})=>{let i=mn(e),a=b([...n.elements],y(i),q(r));return t.exclude(a),t}};function Jn(e,{stage:t,where:n}){let r=q([...e.children()],n);r.length!==0&&(t.addImplicit(e),t.addConnections(fn(r)),t.connectWithExisting(r),t.addExplicit(r))}function Yn(e,{memory:t,stage:n,where:r}){n.addImplicit(e),n.connectWithExisting(e);let i=q([...e.children()],r),a=!1;for(let e of i)if(U(e,t.elements).length>0){a=!0;break}a&&(n.connectWithExisting(i,`in`),n.addConnections(fn(i)),n.connectWithExisting(i,`out`)),n.addImplicit(i),n.connections.length>0&&n.addExplicit(e)}function Xn(e,{stage:t,where:n}){let r=e=>{let i=[];for(let t of e.children())t.isDeploymentNode()&&i.push(...r(t)),q(t,n)&&i.push(t);return t.connectWithExisting(i,`in`),t.addConnections(fn(i)),t.addImplicit(i),i},a=r(e);if(a.length===0)return;t.connectWithExisting(a,`out`);let o=Zn(t);b(a,y(e=>o.has(e)),i(e=>t.addExplicit(e)))}function Zn(e){return b(e.mergedConnections(),wn,En,re((e,t)=>(e.add(t.source),e.add(t.target),e),new Set))}var Qn=class e{static for(t){return new e(t)}constructor(e){this.memory=e}step1CleanConnections(e){if(e.connections.length<2)return e;let t=b(e.connections,wn,En),n=bt(e.connections,t);if(n.length===0)return e;let r=e.stageExclude({});return r.excludeConnections(n,!0),r.commit()}step2ProcessImplicits(e){let t=R(this.memory.elements,e.elements),n=R(e.final,this.memory.explicits),r=new B.default(()=>new Set);for(let t of e.connections)if(t.boundary)for(let e of t.relations.model)r.get(e).add(t.boundary);for(let[e,i]of r)if(!(i.size<2))for(let e of i)t.delete(e)&&n.add(e);let a=new Set(n),o=e=>{for(let t of a)if(e===t||j(e,t))return!0;return!1};return b(F(t,a),A(e=>e.isDeploymentNode()),P(),Xe,i(e=>{let t=[...e.children()].filter(o).length;if(t>=2){n.add(e);return}t===1&&at(e.siblings(),o)&&n.add(e)})),e.update({final:n})}step3ProcessBoundaries(e){let t=new Set;for(let n of e.connections)n.boundary&&t.add(n.boundary);let n=Kt(e,`final`),r=e.stageExclude({}),i=r=>!(t.has(r)||e.explicits.has(r)||n.hasInOut(r)||n.root.has(r)),a=S([...n.root]);a&&!e.explicits.has(a)&&r.exclude(a);for(let t of e.final){let e=S(n.children(t));e&&!n.hasInOut(e)&&i(t)&&r.exclude(t)}return r.isDirty()?r.commit():e}commit(){let e=this.step1CleanConnections(this.memory),t=this.step2ProcessImplicits(e);return this.step3ProcessBoundaries(t)}};function $n(e,t){let n=On.empty();for(let r of t)if(He(r)){let t=`include`in r?`include`:`exclude`,i=r.include??r.exclude;for(let r of i){let i=t===`include`?n.stageInclude(r):n.stageExclude(r);i=Vn(t,{expr:r,model:e,stage:i,memory:n,where:null})??i,n=i.commit()}}return Qn.for(n).commit()}function er(e,{docUri:t,rules:n,...r}){let i=$n(e.deployment,n),a=bn(e,i),o=yn(i.connections);It(a,o);let c=Vt({nodes:a,edges:o}),l=xn(n,c.nodes),u=s(n,je),d=Nt(l);return Ht({...r,[Ce]:`computed`,[Be]:`deployment`,autoLayout:{direction:u?.direction??`TB`,...u?.nodeSep&&{nodeSep:u.nodeSep},...u?.rankSep&&{rankSep:u.rankSep}},edges:c.edges,nodes:_(l,e=>(e.icon===`none`&&delete e.icon,e)),...d.length>0&&{notation:{nodes:d}}})}function tr(e){return t=>Ne(t)?t.groupRules.flatMap(tr(e)):He(t)&&`include`in t?t.include.filter(e):[]}function nr(e,t){let n=e.flatMap(tr(E.isCustom));if(n.length===0)return t;let r=[...t];for(let{custom:{expr:e,...t}}of n){let{border:n,opacity:i,multiple:a,iconColor:s,iconSize:c,iconPosition:l,padding:d,size:f,textSize:p,...m}=ye(t,u),h=T({border:n,opacity:i,multiple:a,iconColor:s,iconSize:c,iconPosition:l,padding:d,size:f,textSize:p}),g=!o(h),_=!o(m),v=H(e);r.forEach((e,t)=>{Ee(e)||!v(e)||(_&&(e={...e,...m,isCustomized:!0}),g&&(e={...e,isCustomized:!0,style:{...e.style,...h}}),r[t]=e)})}return r}function rr(e,t){return e.reduce((e,n)=>{if(ze(n)){let r=t.predicates[n.predicateId];return u(r)?e:e.concat(r)}if(Te(n)){let r=t.styles[n.styleId];return u(r)?e:e.concat(r)}return e.push(n),e},[])}function ir(e,t){return e.reduce((e,n)=>{if(ze(n)){let r=t.dynamicPredicates[n.predicateId];return u(r)?e:e.concat(r)}if(Te(n)){let r=t.styles[n.styleId];return u(r)?e:e.concat(r)}return e.push(n),e},[])}function ar(e,t){let n=new Set;for(let r of t)if(He(r))for(let t of r.include){let r=H(t);for(let t of e.elements())r(t)&&n.add(t)}return n}const or=e=>{if(Pe(e)){let t=[],n=[];for(let r of e.__parallel)if(Le(r)){let[e,...i]=r.__series;t.push(e),n.push(...i)}else t.push(r);return[...t,...n]}return Le(e)?[...e.__series]:e};function sr(e,t){let n=[],r=(...[e,t])=>{if(!n.includes(e)){let r=n.indexOf(t);if(r>0){n.splice(r,0,e);return}else n.push(e)}n.includes(t)||n.push(t)};for(let i of c(t,or)){let t=e.element(i.source),a=e.element(i.target),o=n.indexOf(t),s=n.indexOf(a);o>=0&&s>=0||(i.isBackward?r(a,t):r(t,a))}return new Set(n)}function cr(e,t,n){let r=vt(e,t,`directed`).flatMap(e=>[...e.relations]).sort(Qe);if(!Ge(r))return{};if(r.length===1){let e=r[0];return T({title:e.title??void 0,kind:e.kind??void 0,tags:e.tags,relations:[e.id],navigateTo:e.$relationship.navigateTo,color:e.$relationship.color,line:e.$relationship.line,technology:e.technology??void 0,description:e.$relationship.description??void 0})}let i=b(r,c(e=>e.tags),oe()),a=m(i,1)?i:void 0,o=_(r,e=>e.id),s=fe(r).$relationship.navigateTo;s===n&&(s=void 0),s||=b(r,c(e=>e.$relationship.navigateTo&&e.$relationship.navigateTo!==n?e.$relationship.navigateTo:[]),oe(),S());let l=b(r,re((e,{title:t,technology:n,$relationship:r})=>(f(t)&&e.title.add(t),f(r.color)&&e.color.add(r.color),f(r.line)&&e.line.add(r.line),f(r.kind)&&e.kind.add(r.kind),f(n)&&e.technology.add(n),f(r.description)&&!e.description.some(v(r.description))&&e.description.push(r.description),e),{kind:new Set,color:new Set,line:new Set,title:new Set,technology:new Set,description:[]}));return T({tags:a??void 0,relations:o,navigateTo:s,kind:S([...l.kind]),title:S([...l.title]),color:S([...l.color]),line:S([...l.line]),technology:S([...l.technology]),description:S(l.description)})}var lr=class{steps=[];constructor(e,t){this.model=e,this.view=t}compute(){let{docUri:e,rules:t,steps:n,...r}=this.view,i=ir(t,this.model.globals),a=ar(this.model,i),o=sr(this.model,n),c=b(R(I(a,o),o,a),P(),Ye),l=c.reduce((e,t,n,r)=>{for(let i=n+1;i<r.length;i++){let n=r[i];if(j(t,n)){e.push(t);break}}return e},[]),u=(e,t,n)=>{if(Le(e)){for(let r of e.__series)t=u(r,t,n);return t}let r=n?Ae(n,t):Ae(t),{source:i,target:a,title:o,isBackward:s,navigateTo:d,notation:p,...m}=e,h=this.model.element(i),g=c.indexOf(h);N(g>=0,`Source ${i} not found`);let _=this.model.element(a),v=c.indexOf(_);N(v>=0,`Target ${a} not found`),(l.includes(h)||l.includes(_))&&console.error(`Step ${h.id} -> ${_.id} because it involves a compound`);let{title:y,relations:ee,navigateTo:te,...ne}=cr(h,_,this.view.id),re=f(d)&&d!==this.view.id?d:te,b=e.kind&&!e.technology?this.model.specification.relationships[e.kind]?.technology:void 0;return this.steps.push(T({...ne,...m,...b&&{technology:b},id:r,source:h,target:_,navigateTo:re,title:o??y,relations:ee??[],isBackward:g>v})),t+1},d=1;for(let e of n){if(Pe(e)){let t=1;for(let n of e.__parallel)t=u(n,t,d);d++;continue}d=u(e,d)}let p=cn(this.model.$styles,c.map(sn)),m=this.model.$styles.defaults.relationship,h=this.steps.map(({id:e,source:t,target:n,relations:r,title:i,isBackward:a,tags:o,...s})=>{let c=k(p.get(t.id),`Source node ${t.id} not found`),l=k(p.get(n.id),`Target node ${n.id} not found`),u={id:e,parent:tt(t.id,n.id),source:c.id,target:l.id,label:i??null,relations:r,color:m.color,line:m.line,head:m.arrow,tags:o??[],...s};for(a&&(u.dir=`back`);u.parent&&!p.has(u.parent);)u.parent=We(u.parent);c.outEdges.push(u.id),l.inEdges.push(u.id);for(let e of Ue(u.source)){if(e===u.parent)break;p.get(e)?.outEdges.push(u.id)}for(let e of Ue(u.target)){if(e===u.parent)break;p.get(e)?.inEdges.push(u.id)}return u}),g=nr(i,Yt(i,c.map(e=>k(p.get(e.id))))),v=s(i,je),y=Nt(g);return Ht({...r,[Be]:`dynamic`,[Ce]:`computed`,variant:r.variant??`diagram`,autoLayout:{direction:v?.direction??`LR`,...v?.nodeSep&&{nodeSep:v.nodeSep},...v?.rankSep&&{rankSep:v.rankSep}},nodes:_(g,e=>(e.icon===`none`&&delete e.icon,e)),edges:h,...y.length>0&&{notation:{nodes:y}}})}};function ur(e,t){return new lr(e,t).compute()}function dr(e){switch(!0){case C.isCustom(e):return dr(e.customRelation.expr);case C.isWhere(e):{let t=dr(e.where.expr),n=w(e.where.condition);return e=>t(e)&&n({source:{tags:e.source.tags,kind:e.source.kind,metadata:e.source.metadata},target:{tags:e.target.tags,kind:e.target.kind,metadata:e.target.metadata},...e.tags&&{tags:e.tags},...e.kind&&{kind:e.kind},...e.metadata&&{metadata:e.metadata}})}case C.isDirect(e):{let t=H(e.source),n=H(e.target);return r=>t(r.source)&&n(r.target)||!!e.isBidirectional&&t(r.target)&&n(r.source)}case C.isInOut(e):{let t=H(e.inout);return e=>t(e.source)||t(e.target)}case C.isIncoming(e):{let t=H(e.incoming);return e=>t(e.target)}case C.isOutgoing(e):{let t=H(e.outgoing);return e=>t(e.source)}default:L(e)}}function fr(e,t,n){let r=e.flatMap(tr(C.isCustom)),i=Array.from(n);if(r.length===0||i.length===0)return i;for(let{customRelation:{expr:e,title:n,description:a,notes:o,...s}}of r){let r=a?{description:Re(a)}:{},c=o?{notes:Re(o)}:{},l=ye(s,u),d=dr(e);i.forEach((e,a)=>{let o,s;for(let n of t)if(n.id===e.source&&(o=n),n.id===e.target&&(s=n),o&&s)break;!o||!s||d({source:o,target:s,...te(e,[`kind`,`tags`])})&&(i[a]={...e,...l,...r,...c,label:n??e.label,isCustomized:!0})})}return i}function pr(e){return b([...e],dt,re((e,t,n,r)=>{let i=Mt(r,t),a=R(...i.map(ce(`relations`))),o=I(t.relations,a);if(i.length>0&&(o=R(o,t.directRelations)),At(r,t.reversed())&&(o=R(o,t.directRelations)),o.size<t.relations.size){let e=r.some(ut(t.source)),n=r.some(ut(t.target));e&&(o=R(o,z(A(t.relations,ft(t.source))))),n&&(o=R(o,z(A(t.relations,jt(t.target)))))}return o.size>0&&e.push(t.update(o)),e},[]))}var mr=class e{static for(t){return new e(t)}constructor(e){this.memory=e}step1CleanConnections(e){if(e.connections.length<2)return e;let t=pr(e.connections);if(t.length===0)return e;let n=e.stageExclude({});return n.excludeConnections(t,!0),n.commit()}step2ProcessImplicits(e){let t=R(this.memory.elements,e.elements),n=R(e.final,this.memory.explicits),r=new Set(n),a=e=>{for(let t of r)if(e===t||j(e,t))return!0;return!1};return b(F(t,r),P(),Xe,i(e=>{let t=[...e.children()].filter(a).length;if(t>=2){n.add(e);return}t===1&&at(e.siblings(),a)&&n.add(e)})),e.update({final:n})}step3ProcessBoundaries(e){let t=new Set;for(let n of e.connections)n.boundary&&n.boundary!==n.source&&n.boundary!==n.target&&t.add(n.boundary);let n=Kt(e,`final`),r=e.stageExclude({}),i=r=>!(t.has(r)||e.explicits.has(r)||n.hasInOut(r)||n.root.has(r)),a=S([...n.root]);a&&!e.explicits.has(a)&&r.exclude(a);for(let t of e.final){let e=S(n.children(t));e&&!n.hasInOut(e)&&i(t)&&r.exclude(t)}return r.isDirty()?r.commit():e}commit(){let e=this.step1CleanConnections(this.memory),t=this.step2ProcessImplicits(e);return this.step3ProcessBoundaries(t)}};const{findConnection:hr,findConnectionsBetween:J,findConnectionsWithin:Y}=Et;function X(e,t){switch(!0){case E.isElementKindExpr(t):return[...A(e.elements(),e=>t.isEqual===(e.kind===t.elementKind))];case E.isElementTagExpr(t):return[...A(e.elements(),e=>t.isEqual===e.tags.includes(t.elementTag))];case t.selector===`expanded`:{let n=e.element(D.flatten(t.ref));return[n,...n.children()]}case t.selector===`children`:case t.selector===`descendants`:{let n=e.element(D.flatten(t.ref)),r=t.selector===`children`?P(n.children()):P(n.descendants());return r&&r.length>0?r:[n]}case E.isModelRef(t):return[e.element(D.flatten(t.ref))];default:L(t)}}function gr(e,t){if(t.isEmpty()||e.length===0)return e;let n=x(e.map(e=>Ke(e))),r=P(A(t.elements,t=>!e.includes(t)&&n(t)));return[...e,...r]}function _r(e,{memory:t,model:n}){let r=X(n,e);return E.isModelRef(e)?e.selector===`descendants`?r:gr(r,t):r}const vr={include:({expr:e,model:t,stage:n,where:r})=>{let i=t.element(D.flatten(e.ref));r(i)&&(n.addExplicit(i),n.connectWithExisting(i));let a=[...i.children()].filter(r),o=[];for(let e of a)n.addImplicit(e),n.connectWithExisting(e)&&o.push(e);return n.addConnections(Y(o)),n},exclude:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(X(t,e));return n.exclude(i),n}},yr={include:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(X(t,e));if(i.length!==0)return n.addExplicit(i),n.connectWithExisting(i),n.addConnections(Y(i)),n},exclude:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(X(t,e));return n.exclude(i),n}},br={include:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(X(t,e));if(i.length!==0)return n.addExplicit(i),n.connectWithExisting(i),n.addConnections(Y(i)),n},exclude:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(X(t,e));return n.exclude(i),n}},xr=()=>!0,Sr=e=>e;function Cr(e){return e.reduce((e,t)=>{let n=[...t.relations];N(m(n,1),`Edge must have at least one relation`);let r=t.source.$model.$styles.defaults,i=t.source.id,a=t.target.id,{title:o,color:s=r.relationship.color,line:c=r.relationship.line,head:l=r.relationship.arrow,...u}=un(n.map(e=>e.$relationship),S(y(n,e=>e.source.id===i&&e.target.id===a))?.$relationship),d=T({id:t.id,parent:t.boundary?.id??null,source:i,target:a,label:o??null,relations:n.map(e=>e.id),color:s,line:c,head:l,...u});return e.push(d),e},[])}function wr(e,t){return cn(e.$styles,[...t.final].map(sn),t.groups)}const Z=E.isWildcard,Tr=(e,t)=>e.isAncestorOf(t)||e.isDescendantOf(t),Er={include:({expr:{source:e,target:t,isBidirectional:n=!1},memory:r,model:i,stage:a,where:o,filterWhere:s})=>{let l=Z(e),u=Z(t),d=[];switch(!0){case l&&u&&r.isEmpty()&&o!==xr:{let e=b(i.relationships(),A(o),P(),_(e=>new xt(e.source,e.target,new Set([e]))));return a.addConnections(e),a}case l&&u&&!r.isEmpty()&&o!==xr:d.push(...Y(r.elements));break;case l&&u:d.push(...Y(i.roots()));break;case!l&&u&&o!==xr:{let t=b(X(i,e),c(e=>b(e,le(he(n===!0),{onTrue:e=>R(e.allIncoming,e.allOutgoing),onFalse:e=>e.allOutgoing}),A(o),$e(),P(),_e(t=>t.source===e),([t,n])=>ue(b(t,y(t=>!Tr(e,t.target)),_(t=>new xt(e,t.target,new Set([t])))),b(n,y(t=>!Tr(e,t.source)),_(t=>new xt(t.source,e,new Set([t]))))))));return a.addConnections(t),a}case!l&&u:{let[t,a]=Dr(e,{memory:r,model:i}),o=n?`both`:`directed`;for(let e of t)d.push(...J(e,a,o));break}case l&&!u&&o!==xr:{let e=b(X(i,t),c(e=>b(e,le(he(n===!0),{onTrue:e=>R(e.allIncoming,e.allOutgoing),onFalse:e=>e.allIncoming}),A(o),P(),_e(t=>t.target===e),([t,n])=>ue(b(n,y(t=>!Tr(e,t.target)),_(t=>new xt(e,t.target,new Set([t])))),b(t,y(t=>!Tr(e,t.source)),_(t=>new xt(t.source,e,new Set([t]))))))));return a.addConnections(e),a}case l&&!u:{let[e,a]=Dr(t,{memory:r,model:i}),o=n?`both`:`directed`;for(let t of a)d.push(...J(t,e,o));break}default:{N(!Z(e),`Inference failed - source must be not a wildcard`),N(!Z(t),`Inference failed - target must be not a wildcard`);let a=_r(e,{memory:r,model:i}),o=_r(t,{memory:r,model:i}),s=n?`both`:`directed`;for(let e of a)d.push(...J(e,o,s))}}return a.addConnections(s(d)),a},exclude:({expr:{source:e,target:t,isBidirectional:n},model:r,memory:i,stage:a,where:o})=>{let s=Z(e),l=Z(t),u;switch(!0){case s&&l:u=b(i.connections,c(ae(ce(`relations`),A(o),P())),z());break;case!s&&l:u=b(X(r,e),c(e=>b(e,le(he(n===!0),{onTrue:e=>R(e.allIncoming,e.allOutgoing),onFalse:e=>e.allOutgoing}),A(o),P())),z());break;case s&&!l:u=b(X(r,t),c(e=>b(e,le(he(n===!0),{onTrue:e=>R(e.allIncoming,e.allOutgoing),onFalse:e=>e.allIncoming}),A(o),P())),z());break;default:{N(!Z(e),`Inference failed - source must be not a wildcard`),N(!Z(t),`Inference failed - target must be not a wildcard`);let i=X(r,e),a=X(r,t),s=new Set;for(let e of i)for(let t of a)Je(e,t)||(s=R(s,I(e.allOutgoing,t.allIncoming),n?I(t.allOutgoing,e.allIncoming):new Set));u=z(A(s,o))}}return a.excludeRelations(u),a}};function Dr(e,{memory:t,model:n}){let r=X(n,e);if(!m(r,1))return[[],[]];if(E.isModelRef(e)){let i=P(n.element(D.flatten(e.ref)).ascendingSiblings());return[gr(r,t),gr(i,t)]}return[r,b(r,_(e=>e.ascendingSiblings()),rt(),$e(),P(),e=>gr(e,t))]}const Or={include:({expr:e,scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=e.incoming,s=[];if(E.isWildcard(o)){if(!t)return;for(let e of t.ascendingSiblings())s.push(...hr(e,t,`directed`))}else{let e=_r(o,{memory:r,model:n}),t=[...r.elements];t.length===0&&t.push(...oe(e.flatMap(e=>[...e.ascendingSiblings()])));let i=kr(n,o);for(let n of t)s.push(...J(n,e,`directed`).filter(i))}return i.addConnections(a(s)),i},exclude:({expr:{incoming:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(E.isWildcard(e)){if(!n)return;a.push(...n.allIncoming)}else{let n=X(t,e);a.push(...n.flatMap(e=>[...e.allIncoming]))}return r.excludeRelations(new Set(a.filter(i))),r}};function kr(e,t){switch(!0){case E.isElementKindExpr(t):case E.isElementTagExpr(t):{let e=H(t);return t=>e(t.target)}case E.isModelRef(t)&&t.selector===`children`:{let n=D.flatten(t.ref);return x([...e.children(n)].map(e=>V.isIncoming(e.id)))}case E.isModelRef(t)&&t.selector===`descendants`:{let n=D.flatten(t.ref);return x([V.isInside(n),...[...e.children(n)].map(e=>V.isIncoming(e.id))])}case E.isModelRef(t)&&t.selector===`expanded`:{let e=D.flatten(t.ref);return x([V.isIncoming(e),V.isInside(e)])}case E.isModelRef(t):{let e=D.flatten(t.ref);return V.isIncoming(e)}default:L(t)}}const Ar={include:({expr:{inout:e},scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=[];if(E.isWildcard(e)){if(!t)return;o.push(...J(t,t.ascendingSiblings()))}else{let t=_r(e,{memory:r,model:n}),i=[...r.elements];i.length===0&&(i=oe(t.flatMap(e=>P(e.ascendingSiblings()))));for(let e of t)o.push(...J(e,i))}return i.addConnections(a(o)),i},exclude:({expr:{inout:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(E.isWildcard(e)){if(!n)return;a.push(...n.allOutgoing),a.push(...n.allIncoming)}else{let n=X(t,e);a.push(...n.flatMap(e=>[...e.allOutgoing,...e.allIncoming]))}return r.excludeRelations(z(a.filter(i))),r}},jr={include:({expr:e,scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=e.outgoing,s=[];if(E.isWildcard(o)){if(!t)return;s.push(...J(t,t.ascendingSiblings(),`directed`))}else{let e=_r(o,{memory:r,model:n}),t=[...r.elements];t.length===0&&t.push(...oe(e.flatMap(e=>[...e.ascendingSiblings()])));let i=Mr(n,o);for(let n of e)s.push(...J(n,t,`directed`).filter(i))}return i.addConnections(a(s)),i},exclude:({expr:{outgoing:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(E.isWildcard(e)){if(!n)return;a.push(...n.allOutgoing)}else{let n=X(t,e);a.push(...n.flatMap(e=>[...e.allOutgoing]))}return r.excludeRelations(z(a.filter(i))),r}};function Mr(e,t){switch(!0){case E.isElementKindExpr(t):case E.isElementTagExpr(t):{let e=H(t);return t=>e(t.source)}case E.isModelRef(t)&&t.selector===`children`:{let n=D.flatten(t.ref);return x([...e.children(n)].map(e=>V.isOutgoing(e.id)))}case E.isModelRef(t)&&t.selector===`descendants`:{let n=D.flatten(t.ref);return x([V.isInside(n),...[...e.children(n)].map(e=>V.isOutgoing(e.id))])}case E.isModelRef(t)&&t.selector===`expanded`:{let e=D.flatten(t.ref);return x([V.isOutgoing(e),V.isInside(e)])}case E.isModelRef(t):{let e=D.flatten(t.ref);return V.isOutgoing(e)}default:L(t)}}const Nr={include:({scope:e,model:t,stage:n,memory:r,where:i})=>{if(!e){let e=[...t.roots()].filter(i);if(e.length===0)return;let[r,a]=_e(e,e=>!e.imported);return n.addExplicit(r),n.addImplicit(a),n.addConnections(Y(e)),n.connectWithExisting(e),n}let a=i(e)?e:null,o=P(A(e.children(),i)),s=o.length>0;if(!s)if(a){if(J(a,a.siblings()).length===0){let e=a.parent;e&&i(e)&&n.addExplicit(e)}o.push(a)}else return n;a&&n.addExplicit(a);let c=z([...r.elements,...e.descendingSiblings()]);for(let e of c)n.addConnections(J(e,o,`directed`));s&&(n.addConnections(Y(o)),n.addExplicit(o));for(let e of o)n.addConnections(J(e,c,`directed`));return n},exclude:({scope:e,memory:t,stage:n,where:r})=>r===xr?e?(n.exclude([e,...e.descendants()]),n):rn.empty(t.scope).stageExclude(n.expression):(n.exclude(y([...t.elements],r)),n)};function Pr(e,t,n){switch(!0){case E.isCustom(e):return t===`include`?Pr(e.custom.expr,t,n):n.stage;case E.isWhere(e):{let r=w(e.where.condition),i=e=>y(e,r);return Pr(e.where.expr,t,{...n,where:r,filterWhere:i})}case E.isModelRef(e)&&e.selector===`expanded`:return vr[t]({...n,expr:e})??n.stage;case E.isWildcard(e):return Nr[t]({...n,expr:e})??n.stage;case E.isElementKindExpr(e):case E.isElementTagExpr(e):return yr[t]({...n,expr:e})??n.stage;case E.isModelRef(e):return br[t]({...n,expr:e})??n.stage;default:L(e)}}function Fr(e,t,n){switch(!0){case C.isCustom(e):return t===`include`?Fr(e.customRelation.expr,t,n):n.stage;case C.isWhere(e):{let r=w(e.where.condition),i=e=>new Set(y([...e],r)),a=e=>b(e,_(e=>new xt(e.source,e.target,i(e.relations))),y(e=>e.nonEmpty()));return Fr(e.where.expr,t,{...n,where:r,filterWhere:a})}case C.isInOut(e):return Ar[t]({...n,expr:e})??n.stage;case C.isDirect(e):return Er[t]({...n,expr:e})??n.stage;case C.isOutgoing(e):return jr[t]({...n,expr:e})??n.stage;case C.isIncoming(e):return Or[t]({...n,expr:e})??n.stage;default:L(e)}}function Ir(e,t,n){let r={model:e,scope:t.scope,where:xr,filterWhere:Sr};for(let i of n){if(Ne(i)){t=Ir(e,an.enter(t,i),i.groupRules),N(t instanceof an,`processPredicates must return ActiveGroupMemory`),t=t.leave();continue}if(He(i)){let e=`include`in i?`include`:`exclude`,n=i.include??i.exclude;for(let i of n){let n=e===`include`?t.stageInclude(i):t.stageExclude(i);switch(!0){case Se.isFqnExpr(i):n=Pr(i,e,{...r,stage:n,memory:t})??n;break;case Se.isRelationExpr(i):n=Fr(i,e,{...r,stage:n,memory:t})??n;break;default:L(i)}t=n.commit()}}}return t}function Lr(e,t,n){return t=Ir(e,t,n),mr.for(t).commit()}function Rr(e,{docUri:t,rules:n,...r}){let i=rr(n,e.globals),a=r.viewOf?e.asComputed.element(r.viewOf):null,o=Lr(e,rn.empty(a),i);o.isEmpty()&&a&&(o=o.update({final:new Set([a])})),o=Br(o);let c=wr(e,o),l=Cr(o.connections);It(c,l);let u=Vt({nodes:c,edges:l}),d=nr(i,Yt(i,u.nodes)),f=s(i,je),p=Nt(d),m=zr(i,d);return Ht({...r,_stage:`computed`,autoLayout:{direction:f?.direction??`TB`,...f?.nodeSep&&{nodeSep:f.nodeSep},...f?.rankSep&&{rankSep:f.rankSep}},edges:fr(i,d,u.edges),nodes:_(d,e=>(e.icon===`none`&&delete e.icon,e)),...p.length>0&&{notation:{nodes:p}},...m.length>0&&{ranks:m}})}function zr(e,t){let n=[];for(let r of e){if(!Ie(r)||r.targets.length===0)continue;let e=b(t,y(x(r.targets.map(H))),_(e=>e.id));m(e,1)&&n.push({type:r.rank,nodes:e})}return n}function Br(e){if(e.groups.length===0)return e;let t=new B.default(()=>new Set),n=new Map,r=e=>{for(let r of e.ancestors()){let i=n.get(r);if(i)return n.set(e,i),t.get(i).add(e),!0}return!1},a=e=>{for(let r of e.descendants(`asc`)){let i=n.get(r);if(i)return n.set(e,i),t.get(i).add(e),!0}return!1};if(b(Ye([...e.explicitFirstSeenIn.keys()]),i(i=>{if(!r(i)){let r=k(e.explicitFirstSeenIn.get(i));n.set(i,r),t.get(r).add(i)}})),b(Ye([...e.lastSeenIn.keys()]),y(e=>!n.has(e)),i(i=>{if(r(i)||a(i))return;let o=k(e.lastSeenIn.get(i));n.set(i,o),t.get(o).add(i)})),t.size===0)return e;let o=e.groups.map(e=>{let n=t.get(e.id);return n?e.update(n):e});return e.update({groups:o})}function Vr(e,t){switch(!0){case Oe(e):return Rr(t,e);case Fe(e):return er(t,e);case ke(e):return ur(t,e);default:L(e)}}function Hr(e,t){try{return{isSuccess:!0,view:Vr(e,t)}}catch(e){return{isSuccess:!1,error:e instanceof Error?e:Error(`Unknown error: ${e}`),view:void 0}}}function Ur(e){let t=pt.create(e),{views:r,_stage:i,...a}=e,o=n(r,e=>Vr(e,t));return{[Ce]:`computed`,...a,views:o}}function Wr(e){return pt.create(Ur(e))}const Q=e=>e;function $(e){if(!se(e))return e;if(e===`*`)return Q({wildcard:!0});if(e.startsWith(`->`))return e.endsWith(`->`)?Q({inout:$(e.replace(/->/g,``).trim())}):Q({incoming:$(e.replace(`-> `,``))});if(e.endsWith(` ->`))return Q({outgoing:$(e.replace(` ->`,``))});if(e.includes(` <-> `)){let[t,n]=e.split(` <-> `);return Q({source:$(t),target:$(n),isBidirectional:!0})}if(e.includes(` -> `)){let[t,n]=e.split(` -> `);return Q({source:$(t),target:$(n)})}return e.endsWith(`._`)?Q({ref:{model:e.replace(`._`,``)},selector:`expanded`}):e.endsWith(`.**`)?Q({ref:{model:e.replace(`.**`,``)},selector:`descendants`}):e.endsWith(`.*`)?Q({ref:{model:e.replace(`.*`,``)},selector:`children`}):Q({ref:{model:e}})}export{Vr as a,It as c,Hr as i,Wr as n,Rr as o,Ur as r,Vt as s,$ as t};
|
|
1
|
+
import{r as e}from"./rolldown-runtime.mjs";import{B as t,C as n,E as r,G as i,H as a,I as o,J as s,K as c,L as l,M as u,N as d,O as f,P as p,Q as m,R as h,S as g,T as _,V as v,Y as y,Z as ee,_ as te,a as ne,d as re,et as b,g as ie,h as ae,i as oe,k as se,m as ce,n as le,nt as ue,o as de,q as fe,r as pe,rt as x,t as me,tt as he,u as ge,v as _e,w as ve,x as ye,y as S,z as be}from"./libs/remeda.mjs";import{G as C,J as xe,O as w,St as T,U as Se,W as E,Y as D,_t as Ce,b as we,d as Te,dt as Ee,et as De,g as Oe,h as ke,ht as Ae,l as je,lt as Me,n as Ne,o as Pe,p as Fe,q as O,r as Ie,s as Le,tt as Re,u as ze,vt as Be,xt as Ve,y as He}from"./types.mjs";import{$ as k,A as Ue,B as We,D as A,I as j,K as Ge,L as Ke,M as qe,O as M,Q as N,R as Je,U as Ye,V as Xe,Z as Ze,_ as P,a as F,c as I,d as Qe,et as L,g as $e,i as et,j as tt,s as nt,u as R,v as z,w as rt,x as it,y as at}from"./utils.mjs";import{n as ot,t as st}from"./libs/graphology-dag.mjs";import{c as ct,t as lt}from"./libs/mnemonist.mjs";import{A as ut,C as dt,D as ft,E as pt,M as B,N as mt,O as ht,T as gt,_ as _t,c as vt,d as yt,f as bt,g as xt,h as St,j as Ct,m as wt,n as Tt,o as Et,p as Dt,q as Ot,r as kt,t as At,v as jt,w as Mt,y as Nt}from"./model.mjs";import{r as Pt}from"./manual-layout.mjs";import{t as Ft}from"./libs/graphology.mjs";function It(e,t){let n=[],r=e.parent;for(;r;){let e=k(t.get(r),`Parent node ${r} not found`);n.push(e),r=e.parent}return n}function Lt(e,t){for(let n of t){let t=e.get(n.source),i=e.get(n.target);N(t,`Source node ${n.source} not found`),N(i,`Target node ${n.target} not found`),t.outEdges.push(n.id),i.inEdges.push(n.id);let a=It(t,e),o=It(i,e),s=a.length>0&&o.length>0?r(Ze(ge(a),ge(o))):null;n.parent=s?s.id:null;for(let e of a){if(e===s)break;e.outEdges.push(n.id)}for(let e of o){if(e===s)break;e.inEdges.push(n.id)}}}var Rt=ot(),zt=e(st(),1);function Bt(e){let t=[],n=[...e],r;for(;r=n.shift();){let e=r.parent;if(e){let r=[];for(;e;){let t=n.findIndex(t=>t.id===e);if(t<0)break;let[i]=n.splice(t,1);if(!i)throw Error(`Invalid state, should not happen`);r.unshift(i),e=i.parent}t.push(...r)}t.push(r)}return t}function Vt(e){return e.forEach(t=>{t.children.length>0&&(t.children=e.reduce((e,n)=>(n.parent===t.id&&e.push(n.id),e),[]))}),e}function Ht(e){let t=Bt([...e.nodes.values()]),n=[...e.edges];if(t.length<2||n.length===0)return{nodes:t,edges:n};let r=t=>k(e.nodes.get(t)),a=new Ft({multi:!0,allowSelfLoops:!0,type:`directed`}),[o,s]=_e(b(n,_(e=>{let t=r(e.source),n=r(e.target),i=e.parent?r(e.parent):null;return{id:e.id,edge:e,parent:i,source:t,target:n}})),({source:e,target:t})=>e.children.length===0&&t.children.length===0),c=[],l=e=>{a.mergeNode(e.source),a.mergeNode(e.target),c.push(e),(0,zt.default)(a,e.source,e.target)||a.mergeDirectedEdge(e.source,e.target)};for(let{edge:t,source:n,target:s}of o)if(l(t),s.parent&&s.parent!==t.parent&&b(It(s,e.nodes),ne(e=>e.inEdges.includes(t.id)),i(e=>{a.mergeNode(e.id),(0,zt.default)(a,t.source,e.id)||a.mergeDirectedEdge(t.source,e.id),(0,zt.default)(a,e.id,t.target)||a.mergeDirectedEdge(e.id,t.target)})),n.parent){let e=r(n.parent);a.mergeNode(e.id),(0,zt.default)(a,e.id,n.id)||a.mergeDirectedEdge(e.id,n.id),s.parent&&s.parent!==n.parent&&((0,zt.default)(a,e.id,s.parent)||a.mergeDirectedEdge(e.id,s.parent))}for(let{edge:e}of s)l(e);N(c.length===n.length,`Not all edges were added to the graph`);let u=(0,Rt.topologicalSort)(a),d=[],f=t.slice();for(let e of u){let t=f.findIndex(t=>t.id===e);N(t>=0,`Node "${e}" not found`),d.push(...f.splice(t,1))}return f.length>0&&d.length>0&&(d=d.flatMap(e=>{if(f.length===0)return e;let n=t.slice(0,t.indexOf(e)).filter(e=>f.includes(e));return n.length>0?(f=f.filter(e=>!n.includes(e)),[...n,e]):e})),d.push(...f),{nodes:Vt(Bt(d)),edges:c}}function Ut(e){return e.hash=et({id:e.id,__:e._type??`element`,autoLayout:e.autoLayout,nodes:b(e.nodes,_(e=>({id:e.id,icon:f(e.icon)&&e.icon!==`none`?`Y`:`N`,title:e.title,description:Me(e.description),technology:e.technology??null,shape:e.shape,size:e.style.size??null,iconSize:e.style.iconSize??null,iconPosition:e.style.iconPosition??null,textSize:e.style.textSize??null,padding:e.style.padding??null,children:e.children})),ve(({id:e,...t})=>[e,t])),edges:b(e.edges,_(e=>({source:e.source,target:e.target,label:e.label,description:Me(e.description),technology:e.technology??null,dir:e.dir,head:e.head,tail:e.tail,line:e.line})),ve(({source:e,target:t,...n})=>[`${e}:${t}`,n]))}),e}var Wt=class{get Ctx(){throw Error(`Should not be called in runtime`)}constructor(e){this.state=e}get elements(){return this.state.elements}get explicits(){return this.state.explicits}get final(){return this.state.final}get connections(){return this.state.connections}isEmpty(){return this.elements.size===0&&this.connections.length===0&&this.explicits.size===0&&this.final.size===0}},Gt=class{excluded={elements:new Set,connections:[]};constructor(e,t){this.memory=e,this.expression=t}markedToMoveExplicitToImplicit=!1;_removeElement(e){this.excluded.elements.add(e)}exclude(e){if(!e)return this;if(M(e)){for(let t of e)this._removeElement(t);return this}return this._removeElement(e),this}_removeConnection(e){this.excluded.connections.push(e)}excludeConnections(e,t){if(be(t)&&(N(!this.markedToMoveExplicitToImplicit,`Already marked to move explicits`),this.markedToMoveExplicitToImplicit=t),M(e)){for(let t of e)this._removeConnection(t);return this}return this._removeConnection(e),this}isDirty(){return this.excluded.elements.size>0||this.excluded.connections.length>0}isEmpty(){return!this.isDirty()}filterForMoveToImplicits(e){return this.markedToMoveExplicitToImplicit||this.excluded.elements.size>0?e:new Set}moveDisconnectedExplicitsToImplicits(e){let t=F(new Set(this.memory.connections.flatMap(e=>[e.source,e.target])),new Set(e.connections.flatMap(e=>[e.source,e.target])));return t=I(t,e.elements),t=b(t,A(t=>e.explicits.has(t)&&!at(e.final,Ke(t))),z()),t.size>0&&(t=this.filterForMoveToImplicits(t),e.explicits=F(e.explicits,t),e.final=F(e.final,t)),e}removeElements(e){return e.elements=F(e.elements,this.excluded.elements),e.explicits=F(e.explicits,this.excluded.elements),e.final=F(e.final,this.excluded.elements),e}removeConnections(e){let t=this.excluded.connections.reduce((e,t)=>{let n=e.get(t.id);return n?e.set(t.id,n.mergeWith(t)):e.set(t.id,t),e},new Map),n=new Set;e.connections=e.connections.reduce((e,r)=>{let i=t.get(r.id);if(i){n.add(r.source),n.add(r.target);let t=r.difference(i);t.nonEmpty()&&e.push(t)}else e.push(r);return e},[]);for(let t of e.connections)n.delete(t.source),n.delete(t.target),t.boundary&&e.elements.has(t.boundary)&&n.delete(t.boundary);return n.size===0?e:(n=F(n,e.explicits),e.final=F(e.final,n),e)}precommit(e){return e}postcommit(e){return N(F(e.explicits,e.elements).size===0,`Explicits must be subset of elements`),N(F(e.final,e.elements).size===0,`Final elements must be subset of elements`),e}commit(){let e=this.precommit(this.memory.mutableState());if(this.excluded.elements.size>0){let t=e.connections.filter(e=>this.excluded.elements.has(e.source)||this.excluded.elements.has(e.target)).flatMap(t=>[t,..._t(e.connections,t).map(e=>e.intersect(t))]).filter(e=>e.nonEmpty());this.excludeConnections(t)}return this.excluded.connections.length>0&&(e=this.removeConnections(e)),this.excluded.elements.size>0&&(e=this.removeElements(e)),this.memory.update(this.postcommit(e))}},Kt=class{explicits=new Set;implicits=new Set;_ordered=new Set;_connections=[];constructor(e,t){this.memory=e,this.expression=t}get elements(){return this.explicits}get connections(){return this._connections}mergedConnections(){return ft([...this.memory.connections,...this._connections])}connectWithExisting(e,t){throw Error(`Method not implements, depends on the model`)}_addExplicit(e){this._ordered.add(e),this.explicits.add(e),this.implicits.delete(e)}addExplicit(e){if(!e)return this;if(M(e)){for(let t of e)this._addExplicit(t);return this}return this._addExplicit(e),this}_addImplicit(e){this.explicits.has(e)||(this._ordered.add(e),this.implicits.add(e))}addImplicit(e){if(!e)return this;if(M(e)){for(let t of e)this._addImplicit(t);return this}return this._addImplicit(e),this}_addConnection(e){this._connections.push(e),this._addImplicit(e.source),this._addImplicit(e.target)}addConnections(e){if(M(e)){for(let t of e)this._addConnection(t);return this}return this._addConnection(e),this}isDirty(){return this.explicits.size>0||this.implicits.size>0||this._connections.length>0}isEmpty(){return!this.isDirty()}precommit(e){return e}postcommit(e){return e}processConnections(e){return e}commit(){let e=this.precommit(this.memory.mutableState()),t=new Set;if(this._connections.length>0){let[n,r]=_e(this._connections,t=>e.final.has(t.source));e.connections=this.processConnections(ft([...e.connections,...n,...r])),t=new Set(e.connections.flatMap(e=>[e.source,e.target]))}return e.elements=R(e.elements,this._ordered,this.explicits,t,this.implicits),e.explicits=I(e.elements,R(e.explicits,this.explicits)),e.final=I(e.elements,R(e.final,this.explicits,t)),this.memory.update(this.postcommit(e))}};function qt(e,t=`final`){let n=Ye(P(t===`final`?e.final:e.elements)),r=new Set(e.connections.flatMap(e=>[e.source,e.target])),i=new Set(n),a=new lt.default(()=>null),o=n.reduce((e,t,n,r)=>(e.set(t,r.slice(n+1).filter(e=>j(t,e)).map(e=>(i.delete(e),e)).reduce((e,n)=>(e.some(e=>j(e,n))||(e.push(n),a.set(n,t)),e),[])),e),new lt.default(()=>[]));return{root:i,connected:r,hasInOut:t=>e.connections.some(B.isAnyInOut(t.id)),parent:e=>a.get(e),children:e=>o.get(e)}}var Jt=class extends Gt{};function V(e){if(E.isCustom(e))return V(e.custom.expr);if(E.isWhere(e)){let t=V(e.where.expr),n=w(e.where.condition);return e=>t(e)&&n(e)}if(E.isElementKindExpr(e))return e.isEqual?t=>t.kind===e.elementKind:t=>t.kind!==e.elementKind;if(E.isElementTagExpr(e))return e.isEqual?({tags:t})=>t.includes(e.elementTag):({tags:t})=>!t.includes(e.elementTag);if(E.isWildcard(e))return()=>!0;if(E.isModelRef(e)){let t=D.flatten(e.ref);if(e.selector===`expanded`)return e=>e.id===t||We(e.id)===t;if(e.selector===`descendants`||e.selector===`children`){let e=t+`.`;return t=>t.id.startsWith(e)}return e=>e.id===t}L(e)}function Yt(e,t,n){let{shape:r,color:a,icon:o,...s}=e.style,c=!l(s);b(n,y(d(Ee)),y(t),i(t=>{t.shape=r??t.shape,t.color=a??t.color,h(o)&&(t.icon=o),h(e.notation)&&(t.notation=e.notation),c&&(t.style={...t.style,...s})}))}function Xt(e,t){for(let n of e)!we(n)||n.targets.length===0||Yt(n,x(n.targets.map(V)),t);return t}var Zt=class e{static kind=De;constructor(e,t,n=null,r=new Set){this.id=e,this.viewRule=t,this.parent=n,this.elements=r}isEmpty(){return this.elements.size===0}update(t){return new e(this.id,this.viewRule,this.parent,t)}clone(){return new e(this.id,this.viewRule,this.parent,new Set(this.elements))}},Qt=class extends Gt{excludeRelations(e){return b(this.memory.connections,y(t=>nt(t.relations,e)),i(t=>{this.excludeConnections(t.update(I(t.relations,e)))})),this}precommit(e){if(this.excluded.elements.size>0){let e=new Set([...this.excluded.elements].flatMap(e=>[...e.incoming(`direct`),...e.outgoing(`direct`)]));this.excludeRelations(e)}return e}postcommit(e){let t=F(this.memory.explicits,e.explicits);for(let n of t)e.explicitFirstSeenIn.delete(n);let n=F(this.memory.elements,e.elements);for(let t of n)e.lastSeenIn.delete(t);return e}},$t=class extends Qt{constructor(e,t){super(e,t),this.memory=e,this.expression=t}};const{findConnection:en,findConnectionsBetween:tn}=Dt;var nn=class extends Kt{connectWithExisting(e,t=`both`){let n=this._connections.length,r=()=>this._connections.length>n;if(!M(e)){if(t===`in`||t===`both`)for(let t of this.memory.elements)this.addConnections(en(t,e,`directed`));return(t===`out`||t===`both`)&&this.addConnections(tn(e,this.memory.elements,`directed`)),r()}let i=[...e];if(t===`in`||t===`both`)for(let e of this.memory.elements)this.addConnections(tn(e,i,`directed`));if(t===`out`||t===`both`)for(let e of i)this.addConnections(tn(e,this.memory.elements,`directed`));return r()}addImplicitWithinScope(e){e&&(!this.memory.scope||j(this.memory.scope,e))&&this.addImplicit(e)}processConnections(e){return Se.isRelationExpr(this.expression)||b(e,i(({source:e,target:t,boundary:n})=>{b(me([...P(e.ancestors()).reverse(),e],[...P(t.ancestors()).reverse(),t]),ee(([e,t])=>e===t),de(1),i(([r,i])=>{if(r===e&&i===t){this.addImplicitWithinScope(n);return}r!==e&&this.addImplicitWithinScope(r),i!==t&&this.addImplicitWithinScope(i)}))})),e}postcommit(e){let t=F(e.explicits,this.memory.explicits);for(let n of t)e.explicitFirstSeenIn.set(n,`@root`);return e}},rn=class extends nn{constructor(e,t){super(e,t),this.memory=e,this.expression=t}postcommit(e){let t=F(e.explicits,this.memory.explicits);for(let n of t)e.explicitFirstSeenIn.set(n,this.memory.activeGroupId);for(let t of[...this.explicits,...this.implicits])e.lastSeenIn.set(t,this.memory.activeGroupId);return e}},an=class e extends Wt{static empty(t){return new e({elements:new Set,explicits:new Set,final:new Set,connections:[],groups:[],explicitFirstSeenIn:new Map,lastSeenIn:new Map},t)}constructor(e,t){super(e),this.state=e,this.scope=t}get groups(){return this.state.groups}get explicitFirstSeenIn(){return this.state.explicitFirstSeenIn}get lastSeenIn(){return this.state.lastSeenIn}stageInclude(e){return new nn(this,e)}stageExclude(e){return new Qt(this,e)}mutableState(){return{elements:new Set(this.state.elements),explicits:new Set(this.state.explicits),final:new Set(this.state.final),connections:[...this.state.connections],groups:this.state.groups.map(e=>e.clone()),explicitFirstSeenIn:new Map(this.state.explicitFirstSeenIn),lastSeenIn:new Map(this.state.lastSeenIn)}}update(t){return new e({...this.state,...t},this.scope)}},on=class e extends an{static enter(t,n){let r=`@gr${t.groups.length+1}`;if(t instanceof e){let i=ct.default.from([...t.stack].reverse()),a=t.mutableState();return a.groups.push(new Zt(r,n,t.activeGroupId)),i.push(r),new e(a,t.scope,i)}let i=t.mutableState();i.groups.push(new Zt(r,n,null));let a=ct.default.of(r);return new e(i,t.scope,a)}constructor(e,t,n){super(e,t),this.state=e,this.scope=t,this.stack=n}get activeGroupId(){return k(this.stack.peek(),`Stack must not be empty`)}mutableState(){return{...super.mutableState()}}update(t){return new e({...this.state,...t},this.scope,this.stack)}stageInclude(e){return new rn(this,e)}stageExclude(e){return new $t(this,e)}leave(){let t=this.mutableState();return this.stack.pop(),this.stack.peek()?new e(t,this.scope,this.stack):new an(t,this.scope)}};function sn(e,t){let n;for(;e.parent&&(n=t.get(e.parent));){let t=n.depth??1;if(n.depth=Math.max(t,(e.depth??0)+1),n.depth===t)break;e=n}}function cn(e){let{id:t,title:n,...r}=g(e.$element,[`summary`,`description`,`metadata`,`style`,`tags`]),{color:i,icon:a,shape:o,...s}=e.style;return T({id:t,title:n,modelRef:t,shape:o,color:i,icon:a,style:s,description:Ve(e.$element),tags:[...e.tags],metadata:e.$element.metadata,...r})}function ln({defaults:e},t,n){let r=new Map,i=new Map;n?.forEach(({id:t,parent:n,viewRule:a,elements:o})=>{n&&k(r.get(n),`Parent group node ${n} not found`).children.push(t),r.set(t,{id:t,parent:n,kind:De,title:a.title??``,color:a.color??e.group.color??e.color,shape:`rectangle`,children:[],inEdges:[],outEdges:[],level:0,depth:0,tags:[],style:T({border:a.border??e.group.border,opacity:a.opacity??e.group.opacity,size:a.size,multiple:a.multiple,padding:a.padding,textSize:a.textSize})});for(let e of o)i.set(e.id,t)}),Array.from(t).sort(qe).forEach(({id:e,...t})=>{let n=We(e),a=0,o;for(;n&&(o=r.get(n),!o);)n=We(n);let s=t.modelRef??e;if(!o&&i.has(s)){let e=k(i.get(s));o=r.get(e),n=e}o&&(o.children.length==0&&(o.depth=1,sn(o,r)),o.children.push(e),a=o.level+1);let c=T({id:e,parent:n,level:a,children:[],inEdges:[],outEdges:[],...t});r.set(e,c)});let a=new Map;return n?.forEach(({id:e})=>{a.set(e,k(r.get(e)))}),t.forEach(({id:e})=>{a.set(e,k(r.get(e)))}),a}function un(e){let{title:t,description:n=null}=e;return{...t&&{title:t,description:n},...te(e,[`color`,`technology`,`head`,`line`,`tail`,`kind`,`navigateTo`])}}function dn(e,t){let n=b(e,re((e,t)=>(f(t.title)&&!e.title.includes(t.title)&&e.title.push(t.title),f(t.description)&&!e.description.some(v(t.description))&&e.description.push(t.description),f(t.technology)&&!e.technology.includes(t.technology)&&e.technology.push(t.technology),f(t.kind)&&!e.kind.includes(t.kind)&&e.kind.push(t.kind),f(t.color)&&!e.color.includes(t.color)&&e.color.push(t.color),f(t.line)&&!e.line.includes(t.line)&&e.line.push(t.line),f(t.head)&&!e.head.includes(t.head)&&e.head.push(t.head),f(t.tail)&&!e.tail.includes(t.tail)&&e.tail.push(t.tail),f(t.navigateTo)&&!e.navigateTo.includes(t.navigateTo)&&e.navigateTo.push(t.navigateTo),t.tags&&e.tags.push(...t.tags),e),{title:[],description:[],technology:[],kind:[],head:[],tail:[],color:[],tags:[],line:[],navigateTo:[]})),r=S(n.title)??(n.title.length>1?`[...]`:void 0),i=oe(n.tags),a=T({title:r,description:S(n.description),technology:S(n.technology),kind:S(n.kind),head:S(n.head),tail:S(n.tail),color:S(n.color),line:S(n.line),navigateTo:S(n.navigateTo),...Ge(i)&&{tags:i}});if(t){let e=un(t);a=ie({...a,...e},f)}return u(a.title)&&f(a.technology)&&(a.title=`[${a.technology}]`,delete a.technology),a}const{findConnection:fn,findConnectionsBetween:H,findConnectionsWithin:pn}=wt;function U(e,t){let n=e.element(t.ref.deployment);if(n.isDeploymentNode()){if(t.selector===`children`)return[...n.children()];if(t.selector===`expanded`)return[n,...n.children()];if(t.selector===`descendants`)return[...n.descendants()]}return[n]}function mn(e,t){let n=e.$model.element(t.ref.model);return t.selector===`children`?[...n.children()]:t.selector===`expanded`?[n,...n.children()]:t.selector===`descendants`?[...n.descendants()]:[n]}function hn(e){if(O.isWildcard(e))return()=>!0;if(O.isElementTagExpr(e)||O.isElementKindExpr(e))throw Error(`element kind and tag expressions are not supported in deployment view rules`);if(O.isDeploymentRef(e)){let t=e.ref.deployment;if(e.selector===`expanded`){let e=t+`.`;return n=>n.id===t||n.id.startsWith(e)}if(e.selector===`descendants`){let e=t+`.`;return t=>t.id.startsWith(e)}return e.selector===`children`?e=>We(e.id)===t:e=>e.id===t}if(O.isModelRef(e)){let t=e.ref.model;if(e.selector===`expanded`){let e=t+`.`;return n=>{let r=n.modelRef??null;return r?r===t||r.startsWith(e):!0}}if(e.selector===`descendants`){let e=t+`.`;return t=>{let n=t.modelRef??null;return n?n.startsWith(e):!0}}return e.selector===`children`?e=>{let n=e.modelRef??null;return n?We(n)===t:!0}:e=>{let n=e.modelRef??null;return n?n===t:!0}}L(e)}function gn(e){return Ve(e.$instance)??Ve(e.element.$element)}function _n(e){let t=e.id,n=e.onlyOneInstance();return T({id:t,deploymentRef:t,title:e.title,kind:e.kind,technology:e.technology??void 0,links:m(e.links,1)?[...e.links]:void 0,notation:e.$node.notation??void 0,color:e.color,shape:e.shape,modelRef:n?.element.id,icon:e.style.icon,description:Ve(e.$node)??void 0,tags:[...e.tags],style:g(e.style,[`icon`,`shape`,`color`])})}function vn(e){let t=e.$instance,n=e.element,{icon:r,color:i,shape:a,...o}=e.style,s=[...n.links,...t.links??[]];return T({id:e.id,kind:`instance`,title:e.title,description:gn(e)??void 0,technology:e.technology??void 0,tags:[...e.tags],links:m(s,1)?s:void 0,icon:r,color:i,shape:a,style:o,deploymentRef:t.id,modelRef:n.id,notation:t.notation})}function yn(e){return e.isInstance()?vn(e):_n(e)}function bn(e){return e.reduce((e,t)=>{let n=[...t.relations.model,...t.relations.deployment];N(m(n,1),`Edge must have at least one relation`);let r=t.source.$model.$styles.defaults,i=t.source.id,a=t.target.id,{title:o,color:s=r.relationship.color,line:c=r.relationship.line,head:l=r.relationship.arrow,...u}=dn(n.map(e=>e.$relationship)),d=T({id:t.id,parent:t.boundary?.id??null,source:i,target:a,label:o??null,relations:n.map(e=>e.id),color:s,line:c,head:l,...u}),f=e.find(e=>e.source===a&&e.target===i);if(f&&d.label===f.label){f.dir=`both`;let n=f.head??d.head??t.source.$model.$styles.defaults.relationship.arrow;return f.head??=n,f.tail??=n,d.color&&(f.color??=d.color),d.line&&(f.line??=d.line),e}return e.push(d),e},[])}function xn(e,t){let n=ln(e.$styles,[...t.final].map(yn));for(let t of n.values()){if(!t.deploymentRef||!t.modelRef||t.children.length>0)continue;let n=e.deployment.element(t.deploymentRef),r=n.isDeploymentNode()&&n.onlyOneInstance();if(!r)continue;t.title===n.name&&(t.title=r.title),t.description??=gn(r)??null,t.technology??=r.technology,l(t.tags)&&(t.tags=[...r.tags]),(!t.links||l(t.links))&&m(r.links,1)&&(t.links=[...r.links]);let i=e.$styles.defaults;t.shape===i.shape&&t.shape!==r.shape&&(t.shape=r.shape,t.notation=null),t.color===i.color&&t.color!==r.color&&(t.color=r.color,t.notation=null),!t.icon&&r.icon&&(t.icon=r.icon)}return n}function Sn(e,t){for(let n of e)!we(n)||n.targets.length===0||Yt(n,x(n.targets.map(hn)),t);return t}function Cn(e){let t=new lt.default(()=>[]);for(let n of e)for(let e of n.relations.model)t.get(e).push(n);let n=new lt.default(()=>new Set);for(let[e,r]of t)m(r,2)&&b(r,c(e=>[{group:`$source-${e.source.id}`,conn:e},{group:`$target-${e.target.id}`,conn:e}]),a(ce(`group`)),pe(),y(m(2)),i(ae(_(ce(`conn`)),ht(`desc`),ee((e,t,n)=>t===0||e.boundary===n[t-1].boundary),i(t=>{n.get(t).add(e)}))));return n}function wn(e){e=ft(e);let t=Cn(e);for(let n of e){let{source:e,target:r}=n,i=n.relations.model;if(e.isDeploymentNode()!==r.isDeploymentNode()){let r=e.isDeploymentNode()?e:n.target;N(r.isDeploymentNode());let a=I(i,r.internalModelRelationships());for(let e of a)t.get(n).add(e);continue}if(e.isDeploymentNode()&&r.isDeploymentNode()){let i=R(I(n.relations.model,e.internalModelRelationships()),I(n.relations.model,r.internalModelRelationships()));for(let e of i)t.get(n).add(e)}}return b(t.entries(),it(([e,t])=>e.update({model:t,deployment:null})),P())}function Tn(e){return xt(e,wn(e))}function En(e){return b(e,ft,re((t,n)=>{let{source:r,target:i,relations:a}=n;if(r.isInstance()&&i.isInstance())return t;let o=Ot.empty();if(r.isDeploymentNode()&&i.isDeploymentNode()){let[e]=fn(i,r,`directed`);e&&(o=a.intersect(e.relations))}for(let t of e)gt(t,n)&&(o=o.union(a.intersect(t.relations)));return o.nonEmpty&&t.push(new ut(r,i,o)),t},[]))}function Dn(e){return xt(e,En(e))}var On=class extends Kt{connectWithExisting(e,t=`both`){let n=this._connections.length,r=()=>this._connections.length>n;if(!M(e)){if(t===`in`||t===`both`)for(let t of this.memory.elements)this.addConnections(fn(t,e,`directed`));return(t===`out`||t===`both`)&&this.addConnections(H(e,this.memory.elements,`directed`)),r()}let i=[...e];if(t===`in`||t===`both`)for(let e of this.memory.elements)this.addConnections(H(e,i,`directed`));if(t===`out`||t===`both`)for(let e of i)this.addConnections(H(e,this.memory.elements,`directed`));return r()}processConnections(e){let t=b(e,Tn,Dn);return b(t,i(({source:e,target:t,boundary:n})=>{b(me([...P(e.ancestors()).reverse(),e],[...P(t.ancestors()).reverse(),t]),ee(([e,t])=>e===t),de(1),i(([r,i])=>{if(e===r&&t===i){this.addImplicit(n);return}r!==e&&r.isDeploymentNode()&&!r.onlyOneInstance()&&this.addImplicit(r),i!==t&&i.isDeploymentNode()&&!i.onlyOneInstance()&&this.addImplicit(i)}))})),t}},kn=class e extends Wt{static empty(){return new e({elements:new Set,explicits:new Set,final:new Set,connections:[]})}stageInclude(e){return new On(this,e)}stageExclude(e){return new Jt(this,e)}mutableState(){return{elements:new Set(this.state.elements),explicits:new Set(this.state.explicits),final:new Set(this.state.final),connections:[...this.state.connections]}}update(t){return new e({...this.state,...t})}equals(t){return t instanceof e&&v(this.state,t.state)}diff(e){return{added:{elements:P(F(e.elements,this.elements)),explicits:P(F(e.explicits,this.explicits)),final:P(F(e.final,this.final)),connections:P(xt(e.connections,this.connections))},removed:{elements:P(F(this.elements,e.elements)),explicits:P(F(this.explicits,e.explicits)),final:P(F(this.final,e.final)),connections:xt(this.connections,e.connections)}}}toString(){return[`final:`,...[...this.final].map(e=>` `+e.id),`connections:`,...this.connections.map(e=>` `+e.expression)].join(`
|
|
2
|
+
`)}[Ct](e,t,n){return this.toString()}};const An={include:({expr:e,model:t,memory:n,stage:r})=>{let i=w(e.where.condition);return k(Hn(`include`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i}))},exclude:({expr:e,model:t,memory:n,stage:r})=>{let i=w(e.where.condition);return k(Hn(`exclude`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i}))}},jn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(O.isWildcard(e.incoming)){for(let e of a){if(e.allOutgoing.isEmpty)continue;let t=G(H(e,[...qn(e)],`directed`),i);r.addConnections(t)}return r}N(O.isDeploymentRef(e.incoming),`Only deployment refs are supported in include`);let o=U(t,e.incoming);for(let e of a){let t=G(H(e,o,`directed`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(O.isElementTagExpr(e.incoming)||O.isElementKindExpr(e.incoming))throw Error(`element kind and tag expressions are not supported in exclude`);if(O.isModelRef(e.incoming))return W(Nn(t,e.incoming),{stage:r,memory:n},i);if(O.isWildcard(e.incoming))return r;let a=Mn(U(t,e.incoming)),o=b(n.connections,y(a),G(i));return r.excludeConnections(o),r}};function Mn(e){return x(e.map(e=>{let t=t=>t===e||j(e,t);return e=>!t(e.source)&&t(e.target)}))}function Nn(e,t){let n=mn(e,t);return new Set(n.flatMap(e=>[...e.allIncoming]))}const Pn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(O.isWildcard(e.outgoing)){for(let e of a)if(!e.allIncoming.isEmpty)for(let t of qn(e)){let n=G(fn(t,e,`directed`),i);r.addConnections(n)}return r}N(O.isDeploymentRef(e.outgoing),`Only deployment refs are supported in include`);let o=U(t,e.outgoing);for(let e of o){let t=G(H(e,a,`directed`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(O.isElementTagExpr(e.outgoing)||O.isElementKindExpr(e.outgoing))throw Error(`element kind and tag expressions are not supported in exclude`);if(O.isModelRef(e.outgoing))return W(In(t,e.outgoing),{stage:r,memory:n},i);if(O.isWildcard(e.outgoing))return r;let a=Fn(U(t,e.outgoing)),o=b(n.connections,y(a),G(i));return r.excludeConnections(o),r}};function Fn(e){return x(e.map(e=>{let t=t=>t===e||j(e,t);return e=>t(e.source)&&!t(e.target)}))}function In(e,t){let n=mn(e,t);return new Set(n.flatMap(e=>[...e.allOutgoing]))}const Ln={include:({expr:{source:e,target:t,isBidirectional:n=!1},model:r,stage:i,where:a})=>{if(O.isElementTagExpr(e)||O.isElementKindExpr(e)||O.isElementTagExpr(t)||O.isElementKindExpr(t))throw Error(`element kind and tag expressions are not supported in include`);N(!O.isModelRef(e),`Invalid source model ref in direct relation`),N(!O.isModelRef(t),`Invalid target model ref in direct relation`);let o=O.isWildcard(e),s=O.isWildcard(t),l=n?`both`:`directed`,u;switch(!0){case o&&s:u=b(pn(r.instances()),G(a),_(e=>(i.addImplicit(e.boundary),e)));break;case!o&&s:{let t=U(r,e),i=Fn(t),o=i;if(n){let e=Mn(t);o=t=>i(t)!==e(t)}u=b(t,c(e=>H(e,qn(e),l)),y(o),G(a));break}case o&&!s:{let e=U(r,t),i=Mn(e),o=i;if(n){let t=Fn(e);o=e=>t(e)!==i(e)}u=b(e,c(e=>[...qn(e)].flatMap(t=>fn(t,e,l))),y(o),G(a));break}default:{N(!o,`Inference failed - source should be a deployment ref`),N(!s,`Inference failed - target should be a deployment ref`);let n=U(r,e),i=U(r,t),d=Fn(n),f=Mn(i);u=b(n,c(e=>H(e,i,l)),y(e=>d(e)&&f(e)),G(a))}}return i.addConnections(u),O.isDeploymentRef(e)&&p(e.selector)&&i.addImplicit(r.element(e.ref.deployment)),O.isDeploymentRef(t)&&p(t.selector)&&i.addImplicit(r.element(t.ref.deployment)),i},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=hn(e.target),o=hn(e.source),s;switch(!0){case O.isWildcard(e.source)&&O.isWildcard(e.target):return r.excludeConnections(G(n.connections,i)),r;case O.isModelRef(e.source)&&O.isModelRef(e.target):return s=Rn({source:e.source,target:e.target,expr:e,model:t}),W(s,{stage:r,memory:n},i);case O.isModelRef(e.source)&&O.isWildcard(e.target):return s=In(t,e.source),W(s,{stage:r,memory:n},i);case O.isModelRef(e.source):return s=In(t,e.source),W(s,{stage:r,memory:n},i,e=>a(e.target));case O.isModelRef(e.target):return s=Nn(t,e.target),W(s,{stage:r,memory:n},i,e=>o(e.source));default:let c=t=>o(t.source)&&a(t.target)||e.isBidirectional===!0&&o(t.target)&&a(t.source),l=b(n.connections,y(c),G(i));return l.length===0||r.excludeConnections(l),r}}};function Rn({source:e,target:t,expr:n,model:r}){let i=mn(r,e),a=mn(r,t),o=n.isBidirectional?`both`:`directed`,s=[];for(let e of i)s.push(...bt(e,a,o));return new Set(s.flatMap(e=>[...e.relations]))}const zn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(O.isWildcard(e.inout)){for(let e of a){let t=Wn(H(e,[...qn(e)],`both`),i);r.addConnections(t)}return r}N(O.isDeploymentRef(e.inout),`Only deployment refs are supported in include`);let o=U(t,e.inout);for(let e of a){let t=Wn(H(e,o,`both`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(O.isElementTagExpr(e.inout)||O.isElementKindExpr(e.inout))throw Error(`element kind and tag expressions are not supported in exclude`);if(O.isModelRef(e.inout)){let a=mn(t,e.inout);return a.length===0?r:W(R(new Set,...a.flatMap(e=>[e.allIncoming,e.allOutgoing])),{stage:r,memory:n},i)}if(O.isWildcard(e.inout))return r;let a=U(t,e.inout),o=Mn(a),s=Fn(a),c=b(n.connections,y(e=>o(e)!==s(e)),G(i));return r.excludeConnections(c),r}},Bn={include:({expr:e,model:t,memory:n,stage:r})=>{let i=w(e.where.condition);return Hn(`include`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})},exclude:({expr:e,model:t,memory:n,stage:r})=>{let i=w(e.where.condition);return Hn(`exclude`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})}},Vn={include:({model:e,stage:t,where:n})=>{let r=[],i;return i=n?b([...e.elements()],K(n)):P(it(e.roots(),e=>(e.onlyOneInstance()||r.push(...e.children()),e))),t.addExplicit(i),r.length>1?(t.addConnections(pn([...i,...r])),t.connectWithExisting(r)):t.addConnections(pn(i)),t.connectWithExisting(i),t},exclude:({stage:e,memory:t,where:n})=>{let r=b([...t.elements],K(n));return e.exclude(r),e}};function Hn(e,{expr:t,where:n,...r}){switch(!0){case O.isElementTagExpr(t):case O.isElementKindExpr(t):throw Error(`element kind and tag expressions are not supported in deployment view rules`);case xe.isCustom(t):case O.isCustom(t):case O.isModelRef(t):return;case O.isWhere(t):return An[e]({...r,expr:t,where:n});case xe.isWhere(t):return Bn[e]({...r,expr:t,where:n});case O.isDeploymentRef(t):return Jn[e]({...r,expr:t,where:n});case O.isWildcard(t):return Vn[e]({...r,expr:t,where:n});case xe.isDirect(t):return Ln[e]({...r,expr:t,where:n});case xe.isInOut(t):return zn[e]({...r,expr:t,where:n});case xe.isOutgoing(t):return Pn[e]({...r,expr:t,where:n});case xe.isIncoming(t):return jn[e]({...r,expr:t,where:n});default:L(t)}}function W(e,{stage:t,memory:n},r,i=()=>!0){if(e.size===0)return t;let a=b(n.connections,y(e=>i(e)),y(t=>nt(t.relations.model,e)),_(t=>t.update({deployment:null,model:I(t.relations.model,e)})),G(r),y(e=>e.nonEmpty()));return a.length===0?t:t.excludeConnections(a)}function Un(e,t){return G(e,t).nonEmpty()}function G(...e){if(e.length===1)return t=>G(t,e[0]);let[n,r]=e;return r===null?n:t(n)?n.map(e=>G(e,r)).filter(e=>e.nonEmpty()):n.update({model:new Set([...n.relations.model.values()].filter(e=>r(Kn(n)(e)))),deployment:new Set([...n.relations.deployment.values()].filter(e=>r(Kn(n)(e))))})}function K(...e){if(e.length===1){let t=e[0];return t==null?e=>e:e=>e.filter(e=>t(Gn(e,e)))}let[n,r]=e;return t(n)?r==null?n:n.filter(e=>r(Gn(e,e))):r?.(Gn(n,n))??!0}function Wn(e,t){return t?b(e,y(e=>Un(e,t))):e}function Gn(e,t){if(Et(e)){let n=Tt(t)&&At(t)?t:null;return{kind:e.kind,tags:[...e.tags,...n?.tags??[]],metadata:e.metadata}}if(vt(e))return te(e.element,[`tags`,`kind`,`metadata`]);if(At(e))return{kind:e.element.kind,tags:[...e.tags,...e.element.tags],metadata:e.metadata};if(kt(e))return te(e,[`tags`,`kind`,`metadata`]);L(e)}function Kn(e){return t=>({tags:t.tags,kind:t.kind,metadata:t.metadata,source:Gn(t.source,e.source),target:Gn(t.target,e.target)})}function qn(e){let t=new Set;for(let n of e.descendingSiblings())t.add(n);return t}const Jn={include:e=>{let{expr:t,where:n}=e,r=e.model.element(t.ref.deployment);if(At(r))return K(r,n)&&(e.stage.addExplicit(r),e.stage.connectWithExisting(r)),e.stage;switch(!0){case t.selector===`expanded`:Xn(r,e);break;case t.selector===`children`:Yn(r,e);break;case t.selector===`descendants`:Zn(r,e);break;default:K(r,n)&&(e.stage.addExplicit(r),e.stage.connectWithExisting(r))}return e.stage},exclude:({expr:e,stage:t,memory:n,where:r})=>{let i=hn(e),a=b([...n.elements],y(i),K(r));return t.exclude(a),t}};function Yn(e,{stage:t,where:n}){let r=K([...e.children()],n);r.length!==0&&(t.addImplicit(e),t.addConnections(pn(r)),t.connectWithExisting(r),t.addExplicit(r))}function Xn(e,{memory:t,stage:n,where:r}){n.addImplicit(e),n.connectWithExisting(e);let i=K([...e.children()],r),a=!1;for(let e of i)if(H(e,t.elements).length>0){a=!0;break}a&&(n.connectWithExisting(i,`in`),n.addConnections(pn(i)),n.connectWithExisting(i,`out`)),n.addImplicit(i),n.connections.length>0&&n.addExplicit(e)}function Zn(e,{stage:t,where:n}){let r=e=>{let i=[];for(let t of e.children())t.isDeploymentNode()&&i.push(...r(t)),K(t,n)&&i.push(t);return t.connectWithExisting(i,`in`),t.addConnections(pn(i)),t.addImplicit(i),i},a=r(e);if(a.length===0)return;t.connectWithExisting(a,`out`);let o=Qn(t);b(a,y(e=>o.has(e)),i(e=>t.addExplicit(e)))}function Qn(e){return b(e.mergedConnections(),Tn,Dn,re((e,t)=>(e.add(t.source),e.add(t.target),e),new Set))}var $n=class e{static for(t){return new e(t)}constructor(e){this.memory=e}step1CleanConnections(e){if(e.connections.length<2)return e;let t=b(e.connections,Tn,Dn),n=xt(e.connections,t);if(n.length===0)return e;let r=e.stageExclude({});return r.excludeConnections(n,!0),r.commit()}step2ProcessImplicits(e){let t=R(this.memory.elements,e.elements),n=R(e.final,this.memory.explicits),r=new lt.default(()=>new Set);for(let t of e.connections)if(t.boundary)for(let e of t.relations.model)r.get(e).add(t.boundary);for(let[e,i]of r)if(!(i.size<2))for(let e of i)t.delete(e)&&n.add(e);let a=new Set(n),o=e=>{for(let t of a)if(e===t||j(e,t))return!0;return!1};return b(F(t,a),A(e=>e.isDeploymentNode()),P(),Xe,i(e=>{let t=[...e.children()].filter(o).length;if(t>=2){n.add(e);return}t===1&&at(e.siblings(),o)&&n.add(e)})),e.update({final:n})}step3ProcessBoundaries(e){let t=new Set;for(let n of e.connections)n.boundary&&t.add(n.boundary);let n=qt(e,`final`),r=e.stageExclude({}),i=r=>!(t.has(r)||e.explicits.has(r)||n.hasInOut(r)||n.root.has(r)),a=S([...n.root]);a&&!e.explicits.has(a)&&r.exclude(a);for(let t of e.final){let e=S(n.children(t));e&&!n.hasInOut(e)&&i(t)&&r.exclude(t)}return r.isDirty()?r.commit():e}commit(){let e=this.step1CleanConnections(this.memory),t=this.step2ProcessImplicits(e);return this.step3ProcessBoundaries(t)}};function er(e,t){let n=kn.empty();for(let r of t)if(He(r)){let t=`include`in r?`include`:`exclude`,i=r.include??r.exclude;for(let r of i){let i=t===`include`?n.stageInclude(r):n.stageExclude(r);i=Hn(t,{expr:r,model:e,stage:i,memory:n,where:null})??i,n=i.commit()}}return $n.for(n).commit()}function tr(e,{docUri:t,rules:n,...r}){let i=er(e.deployment,n),a=xn(e,i),o=bn(i.connections);Lt(a,o);let c=Ht({nodes:a,edges:o}),l=Sn(n,c.nodes),u=s(n,je),d=Pt(l);return Ut({...r,[Ce]:`computed`,[Be]:`deployment`,autoLayout:{direction:u?.direction??`TB`,...u?.nodeSep&&{nodeSep:u.nodeSep},...u?.rankSep&&{rankSep:u.rankSep}},edges:c.edges,nodes:_(l,e=>(e.icon===`none`&&delete e.icon,e)),...d.length>0&&{notation:{nodes:d}}})}function nr(e){return t=>Ne(t)?t.groupRules.flatMap(nr(e)):He(t)&&`include`in t?t.include.filter(e):[]}function rr(e,t){let n=e.flatMap(nr(E.isCustom));if(n.length===0)return t;let r=[...t];for(let{custom:{expr:e,...t}}of n){let{border:n,opacity:i,multiple:a,iconColor:s,iconSize:c,iconPosition:l,padding:d,size:f,textSize:p,...m}=ye(t,u),h=T({border:n,opacity:i,multiple:a,iconColor:s,iconSize:c,iconPosition:l,padding:d,size:f,textSize:p}),g=!o(h),_=!o(m),v=V(e);r.forEach((e,t)=>{Ee(e)||!v(e)||(_&&(e={...e,...m,isCustomized:!0}),g&&(e={...e,isCustomized:!0,style:{...e.style,...h}}),r[t]=e)})}return r}function ir(e,t){return e.reduce((e,n)=>{if(ze(n)){let r=t.predicates[n.predicateId];return u(r)?e:e.concat(r)}if(Te(n)){let r=t.styles[n.styleId];return u(r)?e:e.concat(r)}return e.push(n),e},[])}function ar(e,t){return e.reduce((e,n)=>{if(ze(n)){let r=t.dynamicPredicates[n.predicateId];return u(r)?e:e.concat(r)}if(Te(n)){let r=t.styles[n.styleId];return u(r)?e:e.concat(r)}return e.push(n),e},[])}function or(e,t){let n=new Set;for(let r of t)if(He(r))for(let t of r.include){let r=V(t);for(let t of e.elements())r(t)&&n.add(t)}return n}const sr=e=>{if(Pe(e)){let t=[],n=[];for(let r of e.__parallel)if(Le(r)){let[e,...i]=r.__series;t.push(e),n.push(...i)}else t.push(r);return[...t,...n]}return Le(e)?[...e.__series]:e};function cr(e,t){let n=[],r=(...[e,t])=>{if(!n.includes(e)){let r=n.indexOf(t);if(r>0){n.splice(r,0,e);return}else n.push(e)}n.includes(t)||n.push(t)};for(let i of c(t,sr)){let t=e.element(i.source),a=e.element(i.target),o=n.indexOf(t),s=n.indexOf(a);o>=0&&s>=0||(i.isBackward?r(a,t):r(t,a))}return new Set(n)}function lr(e,t,n){let r=yt(e,t,`directed`).flatMap(e=>[...e.relations]).sort(Qe);if(!Ge(r))return{};if(r.length===1){let e=r[0];return T({title:e.title??void 0,kind:e.kind??void 0,tags:e.tags,relations:[e.id],navigateTo:e.$relationship.navigateTo,color:e.$relationship.color,line:e.$relationship.line,technology:e.technology??void 0,description:e.$relationship.description??void 0})}let i=b(r,c(e=>e.tags),oe()),a=m(i,1)?i:void 0,o=_(r,e=>e.id),s=fe(r).$relationship.navigateTo;s===n&&(s=void 0),s||=b(r,c(e=>e.$relationship.navigateTo&&e.$relationship.navigateTo!==n?e.$relationship.navigateTo:[]),oe(),S());let l=b(r,re((e,{title:t,technology:n,$relationship:r})=>(f(t)&&e.title.add(t),f(r.color)&&e.color.add(r.color),f(r.line)&&e.line.add(r.line),f(r.kind)&&e.kind.add(r.kind),f(n)&&e.technology.add(n),f(r.description)&&!e.description.some(v(r.description))&&e.description.push(r.description),e),{kind:new Set,color:new Set,line:new Set,title:new Set,technology:new Set,description:[]}));return T({tags:a??void 0,relations:o,navigateTo:s,kind:S([...l.kind]),title:S([...l.title]),color:S([...l.color]),line:S([...l.line]),technology:S([...l.technology]),description:S(l.description)})}var ur=class{steps=[];constructor(e,t){this.model=e,this.view=t}compute(){let{docUri:e,rules:t,steps:n,...r}=this.view,i=ar(t,this.model.globals),a=or(this.model,i),o=cr(this.model,n),c=b(R(I(a,o),o,a),P(),Ye),l=c.reduce((e,t,n,r)=>{for(let i=n+1;i<r.length;i++){let n=r[i];if(j(t,n)){e.push(t);break}}return e},[]),u=(e,t,n)=>{if(Le(e)){for(let r of e.__series)t=u(r,t,n);return t}let r=n?Ae(n,t):Ae(t),{source:i,target:a,title:o,isBackward:s,navigateTo:d,notation:p,...m}=e,h=this.model.element(i),g=c.indexOf(h);N(g>=0,`Source ${i} not found`);let _=this.model.element(a),v=c.indexOf(_);N(v>=0,`Target ${a} not found`),(l.includes(h)||l.includes(_))&&console.error(`Step ${h.id} -> ${_.id} because it involves a compound`);let{title:y,relations:ee,navigateTo:te,...ne}=lr(h,_,this.view.id),re=f(d)&&d!==this.view.id?d:te,b=e.kind?this.model.specification.relationships[e.kind]:void 0;return this.steps.push(T({...ne,...!e.technology&&!ne.technology&&b?.technology&&{technology:b.technology},...!e.color&&!ne.color&&b?.color&&{color:b.color},...!e.line&&!ne.line&&b?.line&&{line:b.line},...!e.head&&b?.head&&{head:b.head},...!e.tail&&b?.tail&&{tail:b.tail},...m,id:r,source:h,target:_,navigateTo:re,title:o??y,relations:ee??[],isBackward:g>v})),t+1},d=1;for(let e of n){if(Pe(e)){let t=1;for(let n of e.__parallel)t=u(n,t,d);d++;continue}d=u(e,d)}let p=ln(this.model.$styles,c.map(cn)),m=this.model.$styles.defaults.relationship,h=this.steps.map(({id:e,source:t,target:n,relations:r,title:i,isBackward:a,tags:o,...s})=>{let c=k(p.get(t.id),`Source node ${t.id} not found`),l=k(p.get(n.id),`Target node ${n.id} not found`),u={id:e,parent:tt(t.id,n.id),source:c.id,target:l.id,label:i??null,relations:r,color:m.color,line:m.line,head:m.arrow,tags:o??[],...s};for(a&&(u.dir=`back`);u.parent&&!p.has(u.parent);)u.parent=We(u.parent);c.outEdges.push(u.id),l.inEdges.push(u.id);for(let e of Ue(u.source)){if(e===u.parent)break;p.get(e)?.outEdges.push(u.id)}for(let e of Ue(u.target)){if(e===u.parent)break;p.get(e)?.inEdges.push(u.id)}return u}),g=rr(i,Xt(i,c.map(e=>k(p.get(e.id))))),v=s(i,je),y=Pt(g);return Ut({...r,[Be]:`dynamic`,[Ce]:`computed`,variant:r.variant??`diagram`,autoLayout:{direction:v?.direction??`LR`,...v?.nodeSep&&{nodeSep:v.nodeSep},...v?.rankSep&&{rankSep:v.rankSep}},nodes:_(g,e=>(e.icon===`none`&&delete e.icon,e)),edges:h,...y.length>0&&{notation:{nodes:y}}})}};function dr(e,t){return new ur(e,t).compute()}function fr(e){switch(!0){case C.isCustom(e):return fr(e.customRelation.expr);case C.isWhere(e):{let t=fr(e.where.expr),n=w(e.where.condition);return e=>t(e)&&n({source:{tags:e.source.tags,kind:e.source.kind,metadata:e.source.metadata},target:{tags:e.target.tags,kind:e.target.kind,metadata:e.target.metadata},...e.tags&&{tags:e.tags},...e.kind&&{kind:e.kind},...e.metadata&&{metadata:e.metadata}})}case C.isDirect(e):{let t=V(e.source),n=V(e.target);return r=>t(r.source)&&n(r.target)||!!e.isBidirectional&&t(r.target)&&n(r.source)}case C.isInOut(e):{let t=V(e.inout);return e=>t(e.source)||t(e.target)}case C.isIncoming(e):{let t=V(e.incoming);return e=>t(e.target)}case C.isOutgoing(e):{let t=V(e.outgoing);return e=>t(e.source)}default:L(e)}}function pr(e,t,n){let r=e.flatMap(nr(C.isCustom)),i=Array.from(n);if(r.length===0||i.length===0)return i;for(let{customRelation:{expr:e,title:n,description:a,notes:o,...s}}of r){let r=a?{description:Re(a)}:{},c=o?{notes:Re(o)}:{},l=ye(s,u),d=fr(e);i.forEach((e,a)=>{let o,s;for(let n of t)if(n.id===e.source&&(o=n),n.id===e.target&&(s=n),o&&s)break;!o||!s||d({source:o,target:s,...te(e,[`kind`,`tags`])})&&(i[a]={...e,...l,...r,...c,label:n??e.label,isCustomized:!0})})}return i}function mr(e){return b([...e],ft,re((e,t,n,r)=>{let i=Nt(r,t),a=R(...i.map(ce(`relations`))),o=I(t.relations,a);if(i.length>0&&(o=R(o,t.directRelations)),jt(r,t.reversed())&&(o=R(o,t.directRelations)),o.size<t.relations.size){let e=r.some(dt(t.source)),n=r.some(dt(t.target));e&&(o=R(o,z(A(t.relations,pt(t.source))))),n&&(o=R(o,z(A(t.relations,Mt(t.target)))))}return o.size>0&&e.push(t.update(o)),e},[]))}var hr=class e{static for(t){return new e(t)}constructor(e){this.memory=e}step1CleanConnections(e){if(e.connections.length<2)return e;let t=mr(e.connections);if(t.length===0)return e;let n=e.stageExclude({});return n.excludeConnections(t,!0),n.commit()}step2ProcessImplicits(e){let t=R(this.memory.elements,e.elements),n=R(e.final,this.memory.explicits),r=new Set(n),a=e=>{for(let t of r)if(e===t||j(e,t))return!0;return!1};return b(F(t,r),P(),Xe,i(e=>{let t=[...e.children()].filter(a).length;if(t>=2){n.add(e);return}t===1&&at(e.siblings(),a)&&n.add(e)})),e.update({final:n})}step3ProcessBoundaries(e){let t=new Set;for(let n of e.connections)n.boundary&&n.boundary!==n.source&&n.boundary!==n.target&&t.add(n.boundary);let n=qt(e,`final`),r=e.stageExclude({}),i=r=>!(t.has(r)||e.explicits.has(r)||n.hasInOut(r)||n.root.has(r)),a=S([...n.root]);a&&!e.explicits.has(a)&&r.exclude(a);for(let t of e.final){let e=S(n.children(t));e&&!n.hasInOut(e)&&i(t)&&r.exclude(t)}return r.isDirty()?r.commit():e}commit(){let e=this.step1CleanConnections(this.memory),t=this.step2ProcessImplicits(e);return this.step3ProcessBoundaries(t)}};const{findConnection:gr,findConnectionsBetween:q,findConnectionsWithin:J}=Dt;function Y(e,t){switch(!0){case E.isElementKindExpr(t):return[...A(e.elements(),e=>t.isEqual===(e.kind===t.elementKind))];case E.isElementTagExpr(t):return[...A(e.elements(),e=>t.isEqual===e.tags.includes(t.elementTag))];case t.selector===`expanded`:{let n=e.element(D.flatten(t.ref));return[n,...n.children()]}case t.selector===`children`:case t.selector===`descendants`:{let n=e.element(D.flatten(t.ref)),r=t.selector===`children`?P(n.children()):P(n.descendants());return r&&r.length>0?r:[n]}case E.isModelRef(t):return[e.element(D.flatten(t.ref))];default:L(t)}}function _r(e,t){if(t.isEmpty()||e.length===0)return e;let n=x(e.map(e=>Ke(e))),r=P(A(t.elements,t=>!e.includes(t)&&n(t)));return[...e,...r]}function vr(e,{memory:t,model:n}){let r=Y(n,e);return E.isModelRef(e)?e.selector===`descendants`?r:_r(r,t):r}const yr={include:({expr:e,model:t,stage:n,where:r})=>{let i=t.element(D.flatten(e.ref));r(i)&&(n.addExplicit(i),n.connectWithExisting(i));let a=[...i.children()].filter(r),o=[];for(let e of a)n.addImplicit(e),n.connectWithExisting(e)&&o.push(e);return n.addConnections(J(o)),n},exclude:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(Y(t,e));return n.exclude(i),n}},br={include:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(Y(t,e));if(i.length!==0)return n.addExplicit(i),n.connectWithExisting(i),n.addConnections(J(i)),n},exclude:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(Y(t,e));return n.exclude(i),n}},xr={include:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(Y(t,e));if(i.length!==0)return n.addExplicit(i),n.connectWithExisting(i),n.addConnections(J(i)),n},exclude:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(Y(t,e));return n.exclude(i),n}},X=()=>!0,Sr=e=>e;function Cr(e){return e.reduce((e,t)=>{let n=[...t.relations];N(m(n,1),`Edge must have at least one relation`);let r=t.source.$model.$styles.defaults,i=t.source.id,a=t.target.id,{title:o,color:s=r.relationship.color,line:c=r.relationship.line,head:l=r.relationship.arrow,...u}=dn(n.map(e=>e.$relationship),S(y(n,e=>e.source.id===i&&e.target.id===a))?.$relationship),d=T({id:t.id,parent:t.boundary?.id??null,source:i,target:a,label:o??null,relations:n.map(e=>e.id),color:s,line:c,head:l,...u});return e.push(d),e},[])}function wr(e,t){return ln(e.$styles,[...t.final].map(cn),t.groups)}const Z=E.isWildcard,Tr=(e,t)=>e.isAncestorOf(t)||e.isDescendantOf(t),Er={include:({expr:{source:e,target:t,isBidirectional:n=!1},memory:r,model:i,stage:a,where:o,filterWhere:s})=>{let l=Z(e),u=Z(t),d=[];switch(!0){case l&&u&&r.isEmpty()&&o!==X:{let e=b(i.relationships(),A(o),P(),_(e=>new St(e.source,e.target,new Set([e]))));return a.addConnections(e),a}case l&&u&&!r.isEmpty()&&o!==X:d.push(...J(r.elements));break;case l&&u:d.push(...J(i.roots()));break;case!l&&u&&o!==X:{let t=b(Y(i,e),c(e=>b(e,le(he(n===!0),{onTrue:e=>R(e.allIncoming,e.allOutgoing),onFalse:e=>e.allOutgoing}),A(o),$e(),P(),_e(t=>t.source===e),([t,n])=>ue(b(t,y(t=>!Tr(e,t.target)),_(t=>new St(e,t.target,new Set([t])))),b(n,y(t=>!Tr(e,t.source)),_(t=>new St(t.source,e,new Set([t]))))))));return a.addConnections(t),a}case!l&&u:{let[t,a]=Dr(e,{memory:r,model:i}),o=n?`both`:`directed`;for(let e of t)d.push(...q(e,a,o));break}case l&&!u&&o!==X:{let e=b(Y(i,t),c(e=>b(e,le(he(n===!0),{onTrue:e=>R(e.allIncoming,e.allOutgoing),onFalse:e=>e.allIncoming}),A(o),P(),_e(t=>t.target===e),([t,n])=>ue(b(n,y(t=>!Tr(e,t.target)),_(t=>new St(e,t.target,new Set([t])))),b(t,y(t=>!Tr(e,t.source)),_(t=>new St(t.source,e,new Set([t]))))))));return a.addConnections(e),a}case l&&!u:{let[e,a]=Dr(t,{memory:r,model:i}),o=n?`both`:`directed`;for(let t of a)d.push(...q(t,e,o));break}default:{N(!Z(e),`Inference failed - source must be not a wildcard`),N(!Z(t),`Inference failed - target must be not a wildcard`);let a=vr(e,{memory:r,model:i}),o=vr(t,{memory:r,model:i}),s=n?`both`:`directed`;for(let e of a)d.push(...q(e,o,s))}}return a.addConnections(s(d)),a},exclude:({expr:{source:e,target:t,isBidirectional:n},model:r,memory:i,stage:a,where:o})=>{let s=Z(e),l=Z(t),u;switch(!0){case s&&l:u=b(i.connections,c(ae(ce(`relations`),A(o),P())),z());break;case!s&&l:u=b(Y(r,e),c(e=>b(e,le(he(n===!0),{onTrue:e=>R(e.allIncoming,e.allOutgoing),onFalse:e=>e.allOutgoing}),A(o),P())),z());break;case s&&!l:u=b(Y(r,t),c(e=>b(e,le(he(n===!0),{onTrue:e=>R(e.allIncoming,e.allOutgoing),onFalse:e=>e.allIncoming}),A(o),P())),z());break;default:{N(!Z(e),`Inference failed - source must be not a wildcard`),N(!Z(t),`Inference failed - target must be not a wildcard`);let i=Y(r,e),a=Y(r,t),s=new Set;for(let e of i)for(let t of a)Je(e,t)||(s=R(s,I(e.allOutgoing,t.allIncoming),n?I(t.allOutgoing,e.allIncoming):new Set));u=z(A(s,o))}}return a.excludeRelations(u),a}};function Dr(e,{memory:t,model:n}){let r=Y(n,e);if(!m(r,1))return[[],[]];if(E.isModelRef(e)){let i=P(n.element(D.flatten(e.ref)).ascendingSiblings());return[_r(r,t),_r(i,t)]}return[r,b(r,_(e=>e.ascendingSiblings()),rt(),$e(),P(),e=>_r(e,t))]}const Or={include:({expr:e,scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=e.incoming,s=[];if(E.isWildcard(o)){if(!t)return;for(let e of t.ascendingSiblings())s.push(...gr(e,t,`directed`))}else{let e=vr(o,{memory:r,model:n}),t=[...r.elements];t.length===0&&t.push(...oe(e.flatMap(e=>[...e.ascendingSiblings()])));let i=kr(n,o);for(let n of t)s.push(...q(n,e,`directed`).filter(i))}return i.addConnections(a(s)),i},exclude:({expr:{incoming:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(E.isWildcard(e)){if(!n)return;a.push(...n.allIncoming)}else{let n=Y(t,e);a.push(...n.flatMap(e=>[...e.allIncoming]))}return r.excludeRelations(new Set(a.filter(i))),r}};function kr(e,t){switch(!0){case E.isElementKindExpr(t):case E.isElementTagExpr(t):{let e=V(t);return t=>e(t.target)}case E.isModelRef(t)&&t.selector===`children`:{let n=D.flatten(t.ref);return x([...e.children(n)].map(e=>B.isIncoming(e.id)))}case E.isModelRef(t)&&t.selector===`descendants`:{let n=D.flatten(t.ref);return x([B.isInside(n),...[...e.children(n)].map(e=>B.isIncoming(e.id))])}case E.isModelRef(t)&&t.selector===`expanded`:{let e=D.flatten(t.ref);return x([B.isIncoming(e),B.isInside(e)])}case E.isModelRef(t):{let e=D.flatten(t.ref);return B.isIncoming(e)}default:L(t)}}const Ar={include:({expr:{inout:e},scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=[];if(E.isWildcard(e)){if(!t)return;o.push(...q(t,t.ascendingSiblings()))}else{let t=vr(e,{memory:r,model:n}),i=[...r.elements];i.length===0&&(i=oe(t.flatMap(e=>P(e.ascendingSiblings()))));for(let e of t)o.push(...q(e,i))}return i.addConnections(a(o)),i},exclude:({expr:{inout:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(E.isWildcard(e)){if(!n)return;a.push(...n.allOutgoing),a.push(...n.allIncoming)}else{let n=Y(t,e);a.push(...n.flatMap(e=>[...e.allOutgoing,...e.allIncoming]))}return r.excludeRelations(z(a.filter(i))),r}},jr={include:({expr:e,scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=e.outgoing,s=[];if(E.isWildcard(o)){if(!t)return;s.push(...q(t,t.ascendingSiblings(),`directed`))}else{let e=vr(o,{memory:r,model:n}),t=[...r.elements];t.length===0&&t.push(...oe(e.flatMap(e=>[...e.ascendingSiblings()])));let i=Mr(n,o);for(let n of e)s.push(...q(n,t,`directed`).filter(i))}return i.addConnections(a(s)),i},exclude:({expr:{outgoing:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(E.isWildcard(e)){if(!n)return;a.push(...n.allOutgoing)}else{let n=Y(t,e);a.push(...n.flatMap(e=>[...e.allOutgoing]))}return r.excludeRelations(z(a.filter(i))),r}};function Mr(e,t){switch(!0){case E.isElementKindExpr(t):case E.isElementTagExpr(t):{let e=V(t);return t=>e(t.source)}case E.isModelRef(t)&&t.selector===`children`:{let n=D.flatten(t.ref);return x([...e.children(n)].map(e=>B.isOutgoing(e.id)))}case E.isModelRef(t)&&t.selector===`descendants`:{let n=D.flatten(t.ref);return x([B.isInside(n),...[...e.children(n)].map(e=>B.isOutgoing(e.id))])}case E.isModelRef(t)&&t.selector===`expanded`:{let e=D.flatten(t.ref);return x([B.isOutgoing(e),B.isInside(e)])}case E.isModelRef(t):{let e=D.flatten(t.ref);return B.isOutgoing(e)}default:L(t)}}const Nr={include:({scope:e,model:t,stage:n,memory:r,where:i})=>{if(!e){let e=i===X?[...t.roots()]:P(A(t.elements(),i));if(e.length===0)return;let[r,a]=_e(e,e=>!e.imported);return n.addExplicit(r),n.addImplicit(a),n.addConnections(J(e)),n.connectWithExisting(e),n}let a=P(A(e.children(),i)),o=a.length>0;if(!o){let t=q(e,e.siblings()),r=e.parent;t.length===0&&r&&n.addExplicit(r),a.push(e)}n.addExplicit(e);let s=z([...r.elements,...e.descendingSiblings()]);for(let e of s)n.addConnections(q(e,a,`directed`));o&&(n.addConnections(J(a)),n.addExplicit(a));for(let e of a)n.addConnections(q(e,s,`directed`));return n},exclude:({scope:e,memory:t,stage:n,where:r})=>r===X?e?(n.exclude([e,...e.descendants()]),n):an.empty(t.scope).stageExclude(n.expression):(n.exclude(y([...t.elements],r)),n)};function Pr(e,t,n){switch(!0){case E.isCustom(e):return t===`include`?Pr(e.custom.expr,t,n):n.stage;case E.isWhere(e):{let r=w(e.where.condition),i=e=>y(e,r);return Pr(e.where.expr,t,{...n,where:r,filterWhere:i})}case E.isModelRef(e)&&e.selector===`expanded`:return yr[t]({...n,expr:e})??n.stage;case E.isWildcard(e):return Nr[t]({...n,expr:e})??n.stage;case E.isElementKindExpr(e):case E.isElementTagExpr(e):return br[t]({...n,expr:e})??n.stage;case E.isModelRef(e):return xr[t]({...n,expr:e})??n.stage;default:L(e)}}function Fr(e,t,n){switch(!0){case C.isCustom(e):return t===`include`?Fr(e.customRelation.expr,t,n):n.stage;case C.isWhere(e):{let r=w(e.where.condition),i=e=>new Set(y([...e],r)),a=e=>b(e,_(e=>new St(e.source,e.target,i(e.relations))),y(e=>e.nonEmpty()));return Fr(e.where.expr,t,{...n,where:r,filterWhere:a})}case C.isInOut(e):return Ar[t]({...n,expr:e})??n.stage;case C.isDirect(e):return Er[t]({...n,expr:e})??n.stage;case C.isOutgoing(e):return jr[t]({...n,expr:e})??n.stage;case C.isIncoming(e):return Or[t]({...n,expr:e})??n.stage;default:L(e)}}function Ir(e,t,n){let r={model:e,scope:t.scope,where:X,filterWhere:Sr};for(let i of n){if(Ne(i)){t=Ir(e,on.enter(t,i),i.groupRules),N(t instanceof on,`processPredicates must return ActiveGroupMemory`),t=t.leave();continue}if(He(i)){let e=`include`in i?`include`:`exclude`,n=i.include??i.exclude;for(let i of n){let n=e===`include`?t.stageInclude(i):t.stageExclude(i);switch(!0){case Se.isFqnExpr(i):n=Pr(i,e,{...r,stage:n,memory:t})??n;break;case Se.isRelationExpr(i):n=Fr(i,e,{...r,stage:n,memory:t})??n;break;default:L(i)}t=n.commit()}}}return t}function Lr(e,t,n){return t=Ir(e,t,n),hr.for(t).commit()}function Rr(e,{docUri:t,rules:n,...r}){let i=ir(n,e.globals),a=r.viewOf?e.asComputed.element(r.viewOf):null,o=Lr(e,an.empty(a),i);o.isEmpty()&&a&&(o=o.update({final:new Set([a])})),o=Br(o);let c=wr(e,o),l=Cr(o.connections);Lt(c,l);let u=Ht({nodes:c,edges:l}),d=rr(i,Xt(i,u.nodes)),f=s(i,je),p=Pt(d),m=zr(i,d);return Ut({...r,_stage:`computed`,autoLayout:{direction:f?.direction??`TB`,...f?.nodeSep&&{nodeSep:f.nodeSep},...f?.rankSep&&{rankSep:f.rankSep}},edges:pr(i,d,u.edges),nodes:_(d,e=>(e.icon===`none`&&delete e.icon,e)),...p.length>0&&{notation:{nodes:p}},...m.length>0&&{ranks:m}})}function zr(e,t){let n=[];for(let r of e){if(!Ie(r)||r.targets.length===0)continue;let e=b(t,y(x(r.targets.map(V))),_(e=>e.id));m(e,1)&&n.push({type:r.rank,nodes:e})}return n}function Br(e){if(e.groups.length===0)return e;let t=new lt.default(()=>new Set),n=new Map,r=e=>{for(let r of e.ancestors()){let i=n.get(r);if(i)return n.set(e,i),t.get(i).add(e),!0}return!1},a=e=>{for(let r of e.descendants(`asc`)){let i=n.get(r);if(i)return n.set(e,i),t.get(i).add(e),!0}return!1};if(b(Ye([...e.explicitFirstSeenIn.keys()]),i(i=>{if(!r(i)){let r=k(e.explicitFirstSeenIn.get(i));n.set(i,r),t.get(r).add(i)}})),b(Ye([...e.lastSeenIn.keys()]),y(e=>!n.has(e)),i(i=>{if(r(i)||a(i))return;let o=k(e.lastSeenIn.get(i));n.set(i,o),t.get(o).add(i)})),t.size===0)return e;let o=e.groups.map(e=>{let n=t.get(e.id);return n?e.update(n):e});return e.update({groups:o})}function Vr(e,t){switch(!0){case Oe(e):return Rr(t,e);case Fe(e):return tr(t,e);case ke(e):return dr(t,e);default:L(e)}}function Hr(e,t){try{return{isSuccess:!0,view:Vr(e,t)}}catch(e){return{isSuccess:!1,error:e instanceof Error?e:Error(`Unknown error: ${e}`),view:void 0}}}function Ur(e){let t=mt.create(e),{views:r,_stage:i,...a}=e,o=n(r,e=>Vr(e,t));return{[Ce]:`computed`,...a,views:o}}function Wr(e){return mt.create(Ur(e))}const Q=e=>e;function $(e){if(!se(e))return e;if(e===`*`)return Q({wildcard:!0});if(e.startsWith(`->`))return e.endsWith(`->`)?Q({inout:$(e.replace(/->/g,``).trim())}):Q({incoming:$(e.replace(`-> `,``))});if(e.endsWith(` ->`))return Q({outgoing:$(e.replace(` ->`,``))});if(e.includes(` <-> `)){let[t,n]=e.split(` <-> `);return Q({source:$(t),target:$(n),isBidirectional:!0})}if(e.includes(` -> `)){let[t,n]=e.split(` -> `);return Q({source:$(t),target:$(n)})}return e.endsWith(`._`)?Q({ref:{model:e.replace(`._`,``)},selector:`expanded`}):e.endsWith(`.**`)?Q({ref:{model:e.replace(`.**`,``)},selector:`descendants`}):e.endsWith(`.*`)?Q({ref:{model:e.replace(`.*`,``)},selector:`children`}):Q({ref:{model:e}})}export{Vr as a,Lt as c,Hr as i,Wr as n,Rr as o,Ur as r,Ht as s,$ as t};
|
|
@@ -668,7 +668,7 @@ type NewElementProps<Tag, Metadata> = {
|
|
|
668
668
|
summary?: MarkdownOrString | string;
|
|
669
669
|
description?: MarkdownOrString | string;
|
|
670
670
|
technology?: string;
|
|
671
|
-
tags?:
|
|
671
|
+
tags?: [Tag, ...Tag[]];
|
|
672
672
|
metadata?: Metadata;
|
|
673
673
|
icon?: string;
|
|
674
674
|
shape?: ElementShape;
|
|
@@ -694,7 +694,7 @@ type NewDeploymentNodeProps<Tag, Metadata> = {
|
|
|
694
694
|
summary?: MarkdownOrString | string;
|
|
695
695
|
description?: MarkdownOrString | string;
|
|
696
696
|
technology?: string;
|
|
697
|
-
tags?:
|
|
697
|
+
tags?: [Tag, ...Tag[]];
|
|
698
698
|
metadata?: Metadata;
|
|
699
699
|
icon?: string;
|
|
700
700
|
shape?: ElementShape;
|
|
@@ -718,7 +718,7 @@ type NewDeploymentNodeProps<Tag, Metadata> = {
|
|
|
718
718
|
type NewViewProps<Tag> = {
|
|
719
719
|
title?: string;
|
|
720
720
|
description?: MarkdownOrString | string;
|
|
721
|
-
tags?:
|
|
721
|
+
tags?: [Tag, ...Tag[]];
|
|
722
722
|
links?: Array<string | {
|
|
723
723
|
title?: string;
|
|
724
724
|
url: string;
|
|
@@ -730,7 +730,7 @@ type NewRelationProps<Kind, Tag, Metadata> = {
|
|
|
730
730
|
description?: MarkdownOrString | string;
|
|
731
731
|
technology?: string;
|
|
732
732
|
notes?: MarkdownOrString | string;
|
|
733
|
-
tags?:
|
|
733
|
+
tags?: [Tag, ...Tag[]];
|
|
734
734
|
metadata?: Metadata;
|
|
735
735
|
head?: RelationshipArrowType;
|
|
736
736
|
tail?: RelationshipArrowType;
|
|
@@ -109,10 +109,10 @@ declare class LikeC4Styles {
|
|
|
109
109
|
readonly size?: ShapeSize;
|
|
110
110
|
readonly padding?: SpacingSize;
|
|
111
111
|
readonly textSize?: TextSize;
|
|
112
|
-
}, "size" | "
|
|
112
|
+
}, "size" | "iconSize" | "padding" | "textSize"> & Required<{
|
|
113
113
|
readonly size?: ShapeSize;
|
|
114
|
-
readonly padding?: SpacingSize;
|
|
115
114
|
readonly iconSize?: IconSize;
|
|
115
|
+
readonly padding?: SpacingSize;
|
|
116
116
|
readonly textSize?: TextSize;
|
|
117
117
|
}>;
|
|
118
118
|
values: {
|
package/dist/_chunks/model.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import{n as e}from"./rolldown-runtime.mjs";import{A as t,E as n,I as r,L as i,N as a,O as o,Q as s,T as c,X as l,c as ee,et as u,i as d,l as te,m as ne,r as f,s as re}from"./libs/remeda.mjs";import{$ as ie,H as ae,O as oe,St as p,Y as m,_t as h,bt as g,ct as se,dt as ce,ft as le,j as ue,mt as de,t as _,ut as fe,vt as v,xt as y,yt as pe}from"./types.mjs";import{$ as b,A as x,B as S,D as me,E as he,F as C,H as ge,I as w,J as _e,L as T,Q as E,R as ve,S as D,U as ye,Y as be,a as O,c as k,h as A,j,k as xe,o as M,q as Se,r as Ce,u as N,y as we,z as Te}from"./utils.mjs";import{t as P}from"./libs/mnemonist.mjs";import{n as Ee,t as De}from"./manual-layout.mjs";var F=class{Aux;id;_literalId;hierarchyLevel;imported;constructor(e,t){this.$model=e,this.$element=t,this.id=this.$element.id,this._literalId=this.$element.id;let[n,r]=de(this.id);n?(this.imported={from:n,fqn:r},this.hierarchyLevel=C(r)):(this.imported=null,this.hierarchyLevel=C(this.id))}get name(){return Te(this.id)}get parent(){return this.$model.parent(this)}get kind(){return this.$element.kind}get shape(){return this.style.shape}get color(){return this.style.color}get icon(){return this.style.icon??null}get tags(){return A(this,Symbol.for(`tags`),()=>d([...this.$element.tags??[],...this.$model.specification.elements[this.$element.kind]?.tags??[]]))}get metadata(){return this.$element.metadata??{}}get title(){return this.$element.title}get hasSummary(){return!!this.$element.summary&&!!this.$element.description&&!t(this.$element.summary,this.$element.description)}get summary(){return _.memoize(this,`summary`,y(this.$element))}get description(){return _.memoize(this,`description`,g(this.$element))}get technology(){return this.$element.technology??null}get links(){return this.$element.links??[]}get defaultView(){return A(this,Symbol.for(`defaultView`),()=>D(this.scopedViews())??null)}get isRoot(){return this.parent===null}get style(){return A(this,`style`,()=>p({shape:this.$model.$styles.defaults.shape,color:this.$model.$styles.defaults.color,border:this.$model.$styles.defaults.border,opacity:this.$model.$styles.defaults.opacity,size:this.$model.$styles.defaults.size,padding:this.$model.$styles.defaults.padding,textSize:this.$model.$styles.defaults.text,iconPosition:this.$model.$styles.defaults.iconPosition,...this.$element.style}))}get projectId(){return this.imported?.from??this.$model.projectId}isAncestorOf(e){return w(this,e)}isDescendantOf(e){return w(e,this)}ancestors(){return this.$model.ancestors(this)}commonAncestor(e){let t=j(this.id,e.id);return t?this.$model.element(t):null}children(){return this.$model.children(this)}descendants(e){return e?ge([...this.$model.descendants(this)],e)[Symbol.iterator]():this.$model.descendants(this)}siblings(){return this.$model.siblings(this)}*ascendingSiblings(){yield*this.siblings();for(let e of this.ancestors())yield*e.siblings()}*descendingSiblings(){for(let e of[...this.ancestors()].reverse())yield*e.siblings();yield*this.siblings()}incoming(e=`all`){return this.$model.incoming(this,e)}*incomers(e=`all`){let t=new Set;for(let n of this.incoming(e))t.has(n.source.id)||(t.add(n.source.id),yield n.source)}outgoing(e=`all`){return this.$model.outgoing(this,e)}*outgoers(e=`all`){let t=new Set;for(let n of this.outgoing(e))t.has(n.target.id)||(t.add(n.target.id),yield n.target)}get allOutgoing(){return A(this,Symbol.for(`allOutgoing`),()=>new Set(this.outgoing()))}get allIncoming(){return A(this,Symbol.for(`allIncoming`),()=>new Set(this.incoming()))}views(){return A(this,Symbol.for(`views`),()=>{let e=new Set;for(let t of this.$model.views())t.includesElement(this.id)&&e.add(t);return e})}scopedViews(){return A(this,Symbol.for(`scopedViews`),()=>{let e=new Set;for(let t of this.$model.views())t.isScopedElementView()&&t.viewOf.id===this.id&&e.add(t);return e})}isDeployed(){return o(D(this.deployments()))}deployments(){return this.$model.deployment.instancesOf(this)}hasMetadata(){return!!this.$element.metadata&&!i(this.$element.metadata)}getMetadata(e){return e?this.$element.metadata?.[e]:this.$element.metadata??{}}isTagged(e){return this.tags.includes(e)}},Oe=class{Aux;get style(){return A(this,`style`,()=>p({shape:this.$model.$styles.defaults.shape,color:this.$model.$styles.defaults.color,border:this.$model.$styles.defaults.border,opacity:this.$model.$styles.defaults.opacity,size:this.$model.$styles.defaults.size,padding:this.$model.$styles.defaults.padding,textSize:this.$model.$styles.defaults.text,iconPosition:this.$model.$styles.defaults.iconPosition,...this.$node.style}))}get name(){return Te(this.id)}get shape(){return this.style.shape}get color(){return this.style.color}get icon(){return this.style.icon??null}get summary(){return _.memoize(this,`summary`,y(this.$node))}get description(){return _.memoize(this,`description`,g(this.$node))}get technology(){return this.$node.technology??null}get links(){return this.$node.links??[]}ancestors(){return this.$model.ancestors(this)}commonAncestor(e){let t=j(this.id,e.id);return t?this.$model.node(t):null}siblings(){return this.$model.siblings(this)}isSibling(e){return this.parent===e.parent}*ascendingSiblings(){yield*this.siblings();for(let e of this.ancestors())yield*e.siblings()}*descendingSiblings(){for(let e of[...this.ancestors()].reverse())yield*e.siblings();yield*this.siblings()}incoming(e=`all`){return this.$model.incoming(this,e)}outgoing(e=`all`){return this.$model.outgoing(this,e)}*incomers(e=`all`){let t=new Set;for(let n of this.incoming(e))t.has(n.source.id)||(t.add(n.source.id),yield n.source)}*outgoers(e=`all`){let t=new Set;for(let n of this.outgoing(e))t.has(n.target.id)||(t.add(n.target.id),yield n.target)}*views(){for(let e of this.$model.views())e._type===`deployment`&&e.includesDeployment(this.id)&&(yield e)}isDeploymentNode(){return!1}isInstance(){return!1}get allOutgoing(){return A(this,Symbol.for(`allOutgoing`),()=>z.from(new Set(this.outgoingModelRelationships()),new Set(this.outgoing())))}get allIncoming(){return A(this,Symbol.for(`allIncoming`),()=>z.from(new Set(this.incomingModelRelationships()),new Set(this.incoming())))}hasMetadata(){return!!this.$node.metadata&&!i(this.$node.metadata)}getMetadata(e){return e?this.$node.metadata?.[e]:this.$node.metadata??{}}isTagged(e){return this.tags.includes(e)}},I=class extends Oe{id;_literalId;title;hierarchyLevel;constructor(e,t){super(),this.$model=e,this.$node=t,this.id=t.id,this._literalId=t.id,this.title=t.title,this.hierarchyLevel=C(t.id)}get parent(){return this.$model.parent(this)}get kind(){return this.$node.kind}get metadata(){return this.$node.metadata??{}}get tags(){return A(this,Symbol.for(`tags`),()=>d([...this.$node.tags??[],...this.$model.$model.specification.deployments[this.kind]?.tags??[]]))}children(){return this.$model.children(this)}descendants(e=`desc`){return this.$model.descendants(this,e)}isDeploymentNode(){return!0}*instances(){for(let e of this.descendants(`desc`))e.isInstance()&&(yield e)}onlyOneInstance(){let e=this.children();if(e.size!==1)return null;let t=D(e);return t?t.isInstance()?t:t.onlyOneInstance():null}_relationshipsFromInstances=null;relationshipsFromInstances(){if(this._relationshipsFromInstances)return this._relationshipsFromInstances;let{outgoing:e,incoming:t}=this._relationshipsFromInstances={outgoing:new Set,incoming:new Set};for(let n of this.instances()){for(let t of n.element.outgoing())e.add(t);for(let e of n.element.incoming())t.add(e)}return this._relationshipsFromInstances}outgoingModelRelationships(){return this.relationshipsFromInstances().outgoing.values()}incomingModelRelationships(){return this.relationshipsFromInstances().incoming.values()}internalModelRelationships(){let{outgoing:e,incoming:t}=this.relationshipsFromInstances();return k(t,e)}},L=class extends Oe{id;_literalId;title;hierarchyLevel;constructor(e,t,n){super(),this.$model=e,this.$instance=t,this.element=n,this.id=t.id,this._literalId=t.id,this.title=t.title??n.title,this.hierarchyLevel=C(t.id)}get $node(){return this.$instance}get parent(){return b(this.$model.parent(this),`Parent of ${this.id} not found`)}get style(){return A(this,`style`,()=>p({shape:this.$model.$styles.defaults.shape,color:this.$model.$styles.defaults.color,border:this.$model.$styles.defaults.border,opacity:this.$model.$styles.defaults.opacity,size:this.$model.$styles.defaults.size,padding:this.$model.$styles.defaults.padding,textSize:this.$model.$styles.defaults.text,iconPosition:this.$model.$styles.defaults.iconPosition,...this.element.$element.style,...this.$instance.style}))}get tags(){return A(this,Symbol.for(`tags`),()=>d([...this.$instance.tags??[],...this.element.tags]))}get kind(){return this.element.kind}get metadata(){return this.$instance.metadata??this.element.metadata??{}}get summary(){return _.memoize(this,`summary`,y(this.$instance)??y(this.element.$element))}get description(){return _.memoize(this,`description`,g(this.$instance)??g(this.element.$element))}get technology(){return this.$instance.technology??this.element.technology??null}get links(){return this.$instance.links??this.element.links}isInstance(){return!0}outgoingModelRelationships(){return this.element.outgoing()}incomingModelRelationships(){return this.element.incoming()}*views(){for(let e of this.$model.views())if(e._type===`deployment`){if(e.includesDeployment(this.id)){yield e;continue}e.includesDeployment(this.parent.id)&&this.parent.onlyOneInstance()&&(yield e)}}},ke=class{constructor(e,t){this.instance=e,this.element=t}get id(){return this.instance.id}get _literalId(){return this.instance.id}get style(){return A(this,`style `,()=>({shape:this.element.shape,color:this.element.color,...this.element.$element.style}))}get shape(){return this.element.shape}get color(){return this.element.color}get title(){return this.element.title}get summary(){return this.element.summary}get description(){return this.element.description}get technology(){return this.element.technology}isDeploymentNode(){return!1}isInstance(){return!1}},R=class{boundary;source;target;constructor(e,t){this.$model=e,this.$relationship=t,this.source=e.deploymentRef(t.source),this.target=e.deploymentRef(t.target);let n=j(this.source.id,this.target.id);this.boundary=n?this.$model.node(n):null}get id(){return this.$relationship.id}get expression(){return`${this.source.id} -> ${this.target.id}`}get title(){return o(this.$relationship.title)?this.$relationship.title:null}get technology(){return r(this.$relationship.technology)?(this.kind&&this.$model.specification.relationships[this.kind])?.technology??null:this.$relationship.technology}get hasSummary(){return!!this.$relationship.summary&&!!this.$relationship.description&&!t(this.$relationship.summary,this.$relationship.description)}get summary(){return _.memoize(this,`summary`,y(this.$relationship))}get description(){return _.memoize(this,`description`,g(this.$relationship))}get tags(){return this.$relationship.tags??[]}get kind(){return this.$relationship.kind??null}get metadata(){return this.$relationship.metadata??{}}get navigateTo(){return this.$relationship.navigateTo?this.$model.$model.view(this.$relationship.navigateTo):null}get links(){return this.$relationship.links??[]}get color(){return this.$relationship.color??this.$model.$styles.defaults.relationship.color}get line(){return this.$relationship.line??this.$model.$styles.defaults.relationship.line}get head(){return this.$relationship.head??this.$model.$styles.defaults.relationship.arrow}get tail(){return this.$relationship.tail}*views(){for(let e of this.$model.views())e.includesRelation(this.id)&&(yield e)}isDeploymentRelation(){return!0}isModelRelation(){return!1}hasMetadata(){return!!this.$relationship.metadata&&!i(this.$relationship.metadata)}getMetadata(e){return e?this.$relationship.metadata?.[e]:this.$relationship.metadata??{}}isTagged(e){return this.tags.includes(e)}},z=class e{static empty(){return new e}static from(t,n){return new e(new Set(t),new Set(n))}constructor(e=new Set,t=new Set){this.model=e,this.deployment=t}get isEmpty(){return this.model.size===0&&this.deployment.size===0}get nonEmpty(){return this.model.size>0||this.deployment.size>0}get size(){return this.model.size+this.deployment.size}intersect(t){return e.from(k(this.model,t.model),k(this.deployment,t.deployment))}difference(t){return e.from(O(this.model,t.model),O(this.deployment,t.deployment))}union(t){return e.from(N(this.model,t.model),N(this.deployment,t.deployment))}};const B=e=>typeof e==`string`?e:e.id,Ae=`/`,V=e=>{if(E(!e.includes(`
|
|
2
|
-
`),`View title cannot contain newlines`),e.includes(`/`)){let t=e.split(`/`).map(e=>e.trim()).filter(e=>e.length>0);return s(t,1)?t:[``]}return[e.trim()]},H=e=>V(e).join(`/`),je=e=>{let t=V(e);return s(t,2)?t.slice(0,-1).join(`/`):null},Me=e=>e.includes(`/`)?V(e).pop()??e:e.trim();var Ne=class{#e=new Map;#t=new Map;#n=new P.default(()=>new Set);#r=new P.default(()=>new Set);#i=new Set;#a=new Map;#o=new P.default(()=>new Set);#s=new P.default(()=>new Set);#c=new P.default(()=>new Set);#l=new P.default(()=>new Set);#u=new Map;$deployments;constructor(e){this.$model=e;let t=this.$deployments=e.$data.deployments,n=f(t.elements);for(let e of ye(n)){let t=this.addElement(e);for(let e of t.tags)this.#l.get(e).add(t);t.isInstance()&&this.#r.get(t.element.id).add(t)}for(let e of f(t.relations)){let t=this.addRelation(e);for(let e of t.tags)this.#l.get(e).add(t)}}get $styles(){return this.$model.$styles}get projectId(){return this.$model.projectId}get project(){return this.$model.project}get specification(){return this.$model.specification}element(e){if(e instanceof I||e instanceof L)return e;let t=B(e);return b(this.#e.get(t),`Element ${t} not found`)}findElement(e){return this.#e.get(e)??null}node(e){let t=this.element(e);return E(t.isDeploymentNode(),`Element ${t.id} is not a deployment node`),t}findNode(e){let t=this.findElement(e);return t?(E(t.isDeploymentNode(),`Element ${t?.id} is not a deployment node`),t):null}instance(e){let t=this.element(e);return E(t.isInstance(),`Element ${t.id} is not a deployed instance`),t}findInstance(e){let t=this.findElement(e);return t?(E(t.isInstance(),`Element ${t?.id} is not a deployed instance`),t):null}roots(){return this.#i.values()}elements(){return this.#e.values()}*nodes(){for(let e of this.#e.values())e.isDeploymentNode()&&(yield e)}*nodesOfKind(e){for(let t of this.#e.values())t.isDeploymentNode()&&t.kind===e&&(yield t)}*instances(){for(let e of this.#e.values())e.isInstance()&&(yield e)}*instancesOf(e){let t=B(e),n=this.#r.get(t);n&&(yield*n)}deploymentRef(e){if(m.isInsideInstanceRef(e)){let{deployment:t,element:n}=e;return xe(this.#u,`${t}@${n}`,()=>new ke(this.instance(t),this.$model.element(n)))}return this.element(e.deployment)}relationships(){return this.#a.values()}relationship(e){let t=B(e);return b(this.#a.get(t),`DeploymentRelationModel ${t} not found`)}findRelationship(e){return this.#a.get(e)??null}*views(){for(let e of this.$model.views())e.isDeploymentView()&&(yield e)}parent(e){let t=B(e);return this.#t.get(t)||null}children(e){let t=B(e);return this.#n.get(t)}*siblings(e){let t=B(e),n=this.parent(e)?.children()??this.roots();for(let e of n)e.id!==t&&(yield e)}*ancestors(e){let t=B(e),n;for(;n=this.#t.get(t);)yield n,t=n.id}*descendants(e,t=`desc`){for(let n of this.children(e))t===`asc`?(yield n,yield*this.descendants(n.id)):(yield*this.descendants(n.id),yield n)}*incoming(e,t=`all`){let n=B(e);for(let e of this.#o.get(n))switch(!0){case t===`all`:case t===`direct`&&e.target.id===n:case t===`to-descendants`&&e.target.id!==n:yield e;break}}*outgoing(e,t=`all`){let n=B(e);for(let e of this.#s.get(n))switch(!0){case t===`all`:case t===`direct`&&e.source.id===n:case t===`from-descendants`&&e.source.id!==n:yield e;break}}addElement(e){if(this.#e.has(e.id))throw Error(`Element ${e.id} already exists`);let t=ae(e)?new I(this,Object.freeze(e)):new L(this,Object.freeze(e),this.$model.element(e.element));this.#e.set(t.id,t);let n=S(t.id);return n?(E(this.#e.has(n),`Parent ${n} of ${t.id} not found`),this.#t.set(t.id,this.node(n)),this.#n.get(n).add(t)):(E(t.isDeploymentNode(),`Root element ${t.id} is not a deployment node`),this.#i.add(t)),t}addRelation(e){if(this.#a.has(e.id))throw Error(`Relation ${e.id} already exists`);let t=new R(this,Object.freeze(e));this.#a.set(t.id,t),this.#o.get(t.target.id).add(t),this.#s.get(t.source.id).add(t);let n=t.boundary?.id??null;if(n)for(let e of[n,...x(n)])this.#c.get(e).add(t);for(let e of x(t.source.id)){if(e===n)break;this.#s.get(e).add(t)}for(let e of x(t.target.id)){if(e===n)break;this.#o.get(e).add(t)}return t}},U=class{source;target;boundary;constructor(e,t){this.model=e,this.$relationship=t,this.source=e.element(m.flatten(t.source)),this.target=e.element(m.flatten(t.target));let n=j(this.source.id,this.target.id);this.boundary=n?this.model.element(n):null}get id(){return this.$relationship.id}get expression(){return`${this.source.id} -> ${this.target.id}`}get title(){return r(this.$relationship.title)?null:this.$relationship.title}get technology(){return r(this.$relationship.technology)?(this.kind&&this.model.specification.relationships[this.kind])?.technology??null:this.$relationship.technology}get hasSummary(){return!!this.$relationship.summary&&!!this.$relationship.description&&!t(this.$relationship.summary,this.$relationship.description)}get summary(){return _.memoize(this,`summary`,y(this.$relationship))}get description(){return _.memoize(this,`description`,g(this.$relationship))}get navigateTo(){return this.$relationship.navigateTo?this.model.view(this.$relationship.navigateTo):null}get tags(){return this.$relationship.tags??[]}get kind(){return this.$relationship.kind??null}get metadata(){return this.$relationship.metadata??{}}get links(){return this.$relationship.links??[]}get color(){return this.$relationship.color??this.model.$styles.defaults.relationship.color}get line(){return this.$relationship.line??this.model.$styles.defaults.relationship.line}get head(){return this.$relationship.head??this.model.$styles.defaults.relationship.arrow}get tail(){return this.$relationship.tail}*views(){for(let e of this.model.views())e.includesRelation(this.id)&&(yield e)}isDeploymentRelation(){return!1}isModelRelation(){return!0}hasMetadata(){return!!this.$relationship.metadata&&!i(this.$relationship.metadata)}getMetadata(e){return e?this.$relationship.metadata?.[e]:this.$relationship.metadata??{}}isTagged(e){return this.tags.includes(e)}},W=class{Aux;$viewModel;$view;$edge;constructor(e,t,n,r){this.source=n,this.target=r,this.$viewModel=e,this.$view=e.$view,this.$edge=t}get id(){return this.$edge.id}get parent(){return this.$edge.parent?this.$viewModel.node(this.$edge.parent):null}get label(){return this.$edge.label??null}get description(){return _.memoize(this,`description`,this.$edge.description)}get technology(){return this.$edge.technology??null}hasParent(){return this.$edge.parent!==null}get tags(){return this.$edge.tags??[]}get stepNumber(){return this.isStep()?se(this.id):null}get navigateTo(){return this.$edge.navigateTo?this.$viewModel.$model.view(this.$edge.navigateTo):null}get color(){return this.$edge.color}get line(){return this.$edge.line??this.$viewModel.$styles.defaults.relationship.line}get head(){return this.$edge.head??this.$viewModel.$styles.defaults.relationship.arrow}get tail(){return this.$edge.tail}isStep(){return le(this.id)}*relationships(e){for(let t of this.$edge.relations)if(e){let n=this.$viewModel.$model.findRelationship(t,e);n&&(yield n)}else yield this.$viewModel.$model.relationship(t)}includesRelation(e){let t=typeof e==`string`?e:e.id;return this.$edge.relations.includes(t)}isTagged(e){return this.tags.includes(e)}},G=class{Aux;$viewModel;$view;$node;constructor(e,t){this.$viewModel=e,this.$view=e.$view,this.$node=t}get id(){return this.$node.id}get title(){return this.$node.title}get kind(){return this.$node.kind}get description(){return _.memoize(this,`description`,this.$node.description)}get technology(){return this.$node.technology??null}get notes(){return _.memoize(this,`notes`,this.$node.notes)}get parent(){return this.$node.parent?this.$viewModel.node(this.$node.parent):null}get element(){let e=this.$node.modelRef;return e?this.$viewModel.$model.element(e):null}get deployment(){let e=this.$node.deploymentRef;return e?this.$viewModel.$model.deployment.element(e):null}get shape(){return this.$node.shape}get color(){return this.$node.color}get icon(){return this.$node.icon??null}get tags(){return this.$node.tags}get links(){return this.$node.links??[]}get navigateTo(){return this.$node.navigateTo?this.$viewModel.$model.view(this.$node.navigateTo):null}get style(){return this.$node.style}get x(){return`x`in this.$node?this.$node.x:void 0}get y(){return`y`in this.$node?this.$node.y:void 0}get width(){return`width`in this.$node?this.$node.width:void 0}get height(){return`height`in this.$node?this.$node.height:void 0}children(){return A(this,`children`,()=>new Set(this.$node.children.map(e=>this.$viewModel.node(e))))}*ancestors(){let e=this.parent;for(;e;)yield e,e=e.parent}*siblings(){let e=this.parent?.children()??this.$viewModel.roots();for(let t of e)t.id!==this.id&&(yield t)}*incoming(e=`all`){for(let t of this.$node.inEdges){let n=this.$viewModel.edge(t);switch(!0){case e===`all`:case e===`direct`&&n.target.id===this.id:case e===`to-descendants`&&n.target.id!==this.id:yield n;break}}}*incomers(e=`all`){let t=new Set;for(let n of this.incoming(e))t.has(n.source.id)||(t.add(n.source.id),yield n.source)}*outgoing(e=`all`){for(let t of this.$node.outEdges){let n=this.$viewModel.edge(t);switch(!0){case e===`all`:case e===`direct`&&n.source.id===this.id:case e===`from-descendants`&&n.source.id!==this.id:yield n;break}}}*outgoers(e=`all`){let t=new Set;for(let n of this.outgoing(e))t.has(n.target.id)||(t.add(n.target.id),yield n.target)}isLayouted(){return`width`in this.$node&&`height`in this.$node}hasChildren(){return this.$node.children.length>0}hasParent(){return this.$node.parent!==null}hasElement(){return o(this.$node.modelRef)}hasDeployment(){return o(this.$node.deploymentRef)}hasDeployedInstance(){return this.hasElement()&&this.hasDeployment()}isGroup(){return ce(this.$node)}isTagged(e){return this.tags.includes(e)}},K=class{Aux;#e;#t=new Set;#n=new Map;#r=new Map;#i=new Set;#a=new Set;#o=new Set;#s=new P.default(e=>new Set);#c;id;$model;title;folder;viewPath;constructor(e,t,n,r){this.$model=e,this.#e=n,this.id=n.id,this.folder=t,this.#c=r;for(let e of this.#e.nodes){let t=new G(this,Object.freeze(e));this.#n.set(e.id,t),e.parent||this.#t.add(t),e.deploymentRef&&this.#a.add(e.deploymentRef),e.modelRef&&this.#i.add(e.modelRef);for(let e of t.tags)this.#s.get(e).add(t)}for(let e of this.#e.edges){let t=new W(this,Object.freeze(e),this.node(e.source),this.node(e.target));for(let e of t.tags)this.#s.get(e).add(t);for(let t of e.relations)this.#o.add(t);this.#r.set(e.id,t)}this.title=n.title?Me(n.title):null,this.viewPath=n.title?H(n.title):n.id}get $styles(){return this.$model.$styles}get _type(){return this.#e[v]}get stage(){return this.#e[h]}get bounds(){if(`bounds`in this.#e)return this.#e.bounds;if(this.#c)return this.#c.bounds;throw Error(`View is not layouted`)}get titleOrId(){return this.title??this.viewOf?.title??this.id}get titleOrUntitled(){return this.title??`Untitled`}get breadcrumbs(){return A(this,`breadcrumbs`,()=>this.folder.isRoot?[this]:[...this.folder.breadcrumbs,this])}get description(){return _.memoize(this,`description`,this.#e.description)}get tags(){return this.#e.tags??[]}get links(){return this.#e.links??[]}get viewOf(){if(this.isElementView()){let e=this.#e.viewOf;return e?this.$model.element(e):null}return null}get mode(){return this.isDynamicView()?this.#e.variant??`diagram`:null}get includedTags(){return[...this.#s.keys()]}get $view(){if(!this.isLayouted()||`drifts`in this.#e)return this.#e;let e=this.#c;return e?A(this,`withDriftReasons`,()=>De(this.#e,e)):this.#e}get $layouted(){if(!this.isLayouted())throw Error(`View is not layouted`);return this.$manual??this.#e}get hasManualLayout(){return this.#c!==void 0}get hasLayoutDrifts(){if(!this.isLayouted())return!1;let e=this.$manual;return!!e?.drifts&&e.drifts.length>0}get $manual(){if(!this.isLayouted())return null;let e=this.#c;return e?A(this,`snapshotWithManualLayout`,()=>Ee(this.#e,e)):null}get projectId(){return this.$model.projectId}roots(){return this.#t.values()}*compounds(){for(let e of this.#n.values())e.hasChildren()&&(yield e)}node(e){let t=B(e);return b(this.#n.get(t),`Node ${t} not found in view ${this.#e.id}`)}findNode(e){return this.#n.get(B(e))??null}findNodeWithElement(e){let t=B(e);return this.#i.has(t)?he(this.#n.values(),e=>e.hasElement()&&e.element.id===t)??null:null}nodes(){return this.#n.values()}edge(e){let t=B(e);return b(this.#r.get(t),`Edge ${t} not found in view ${this.#e.id}`)}findEdge(e){return this.#r.get(B(e))??null}edges(){return this.#r.values()}*edgesWithRelation(e){for(let t of this.#r.values())t.includesRelation(e)&&(yield t)}*elements(){for(let e of this.#n.values())e.hasElement()&&(yield e)}isTagged(e){return this.tags.includes(e)}includesElement(e){return this.#i.has(B(e))}includesDeployment(e){return this.#a.has(B(e))}includesRelation(e){return this.#o.has(B(e))}isComputed(){return this.#e[h]===`computed`}isLayouted(){return this.#e[h]===`layouted`}isDiagram(){return this.#e[h]===`layouted`}isElementView(){return this.#e[v]===`element`}isScopedElementView(){return this.#e[v]===`element`&&o(this.#e.viewOf)}isDeploymentView(){return this.#e[v]===`deployment`}isDynamicView(){return this.#e[v]===`dynamic`}},q=class e{$model;path;title;isRoot;parentPath;defaultViewId;constructor(e,t,r){this.$model=e,this.path=t.join(`/`),this.isRoot=this.path===``,this.title=n(t),this.isRoot?this.parentPath=void 0:this.parentPath=t.slice(0,-1).join(`/`),this.defaultViewId=r}get defaultView(){return this.defaultViewId?this.$model.view(this.defaultViewId):null}get breadcrumbs(){return E(!this.isRoot,`Root view folder has no breadcrumbs`),A(this,`breadcrumbs`,()=>{let e=this.parent;return e?e.isRoot?[e,this]:[...e.breadcrumbs,this]:[this]})}get parent(){return E(!this.isRoot,`Root view folder has no parent`),r(this.parentPath)?null:this.$model.viewFolder(this.parentPath)}get children(){return this.$model.viewFolderItems(this.path)}get folders(){return A(this,`folders`,()=>{let t=[];for(let n of this.children)n instanceof e&&t.push(n);return t})}get views(){return A(this,`views`,()=>{let e=[];for(let t of this.children)t instanceof K&&e.push(t);return e})}},J=class e{Aux;_elements=new Map;_parents=new Map;_children=new P.default(()=>new Set);_rootElements=new Set;_relations=new Map;_incoming=new P.default(()=>new Set);_outgoing=new P.default(()=>new Set);_internal=new P.default(()=>new Set);_views=new Map;_rootViewFolder;_viewFolders=new Map;_viewFolderItems=new P.default(()=>new Set);_allTags=new P.default(()=>new Set);static fromParsed(t){return new e(t)}static create(t){return new e(t)}static fromDump(t){let{_stage:n=`layouted`,projectId:r=`unknown`,project:i,globals:a,imports:o,deployments:s,views:c,relations:l,elements:ee,specification:u}=t;return new e({[h]:n,projectId:r,project:i,globals:{predicates:a?.predicates??{},dynamicPredicates:a?.dynamicPredicates??{},styles:a?.styles??{}},imports:o??{},deployments:{elements:s?.elements??{},relations:s?.relations??{}},views:c??{},relations:l??{},elements:ee??{},specification:u})}deployment;$data;constructor(e){this.$data=e;for(let[,t]of l(e.elements)){let e=this.addElement(t);for(let t of e.tags)this._allTags.get(t).add(e)}for(let[t,n]of l(e.imports??{}))for(let e of ye(n)){let n=this.addImportedElement(t,e);for(let e of n.tags)this._allTags.get(e).add(n)}for(let t of f(e.relations)){let e=this.addRelation(t);for(let t of e.tags)this._allTags.get(t).add(e)}if(this.deployment=new Ne(this),pe(e,`computed`)||pe(e,`layouted`)){let t=be(`/`),n=u(f(e.views),c(e=>({view:e,path:H(e.title??e.id),folderPath:e.title&&je(e.title)||``})),te((e,n)=>t(e.folderPath,n.folderPath))),r=e=>{let t=this._viewFolders.get(e);if(!t){let r=re(e,`/`);E(s(r,1),`View group path "${e}" must have at least one element`);let i;i=e===``?n.find(e=>e.view.id===`index`):n.find(t=>t.path===e),t=new q(this,r,i?.view.id),this._viewFolders.set(e,t)}return t};this._rootViewFolder=r(``);for(let{folderPath:e}of n)this._viewFolders.has(e)||re(e,`/`).reduce((e,t)=>{let n=e.join(`/`),a=r(i(n)?t:n+`/`+t);return this._viewFolderItems.get(n).add(a),e.push(t),e},[]);for(let{view:t,folderPath:i}of n){let n=new K(this,r(i),t,e.manualLayouts?.[t.id]);this._viewFolderItems.get(i).add(n),this._views.set(t.id,n);for(let e of n.tags)this._allTags.get(e).add(n)}}else this._rootViewFolder=new q(this,[``],void 0),this._viewFolders.set(this._rootViewFolder.path,this._rootViewFolder)}get asParsed(){return this}get asComputed(){return this}get asLayouted(){return this}get $styles(){return A(this,`styles`,()=>ue.from(this.project.styles,this.specification.customColors))}isParsed(){return this.stage===`parsed`}isLayouted(){return this.stage===`layouted`}isComputed(){return this.stage===`computed`}get $model(){return this.$data}get stage(){return this.$data[h]}get projectId(){return this.$data.projectId??`default`}get project(){return this.$data.project??A(this,Symbol.for(`project`),()=>({id:this.projectId,styles:{},manualLayouts:{}}))}get specification(){return this.$data.specification}get globals(){return A(this,Symbol.for(`globals`),()=>({predicates:{...this.$data.globals?.predicates},dynamicPredicates:{...this.$data.globals?.dynamicPredicates},styles:{...this.$data.globals?.styles}}))}element(e){if(e instanceof F)return e;let t=B(e);return b(this._elements.get(t),`Element ${t} not found`)}findElement(e){return this._elements.get(B(e))??null}roots(){return this._rootElements.values()}elements(){return this._elements.values()}relationships(){return this._relations.values()}relationship(e,t){if(t===`deployment`)return this.deployment.relationship(e);let n=B(e),r=this._relations.get(n)??null;return r||t===`model`?b(r,`Model relation ${n} not found`):b(this.deployment.findRelationship(n),`No model/deployment relation ${n} not found`)}findRelationship(e,t){if(t===`deployment`)return this.deployment.findRelationship(e);let n=this._relations.get(B(e))??null;return n||t===`model`?n:this.deployment.findRelationship(e)}views(){return this._views.values()}view(e){let t=B(e);return b(this._views.get(t),`View ${t} not found`)}findView(e){return this._views.get(e)??null}findManualLayout(e){return`manualLayouts`in this.$data?this.$data.manualLayouts?.[e]??null:null}viewFolder(e){return b(this._viewFolders.get(e),`View folder ${e} not found`)}get rootViewFolder(){return this._rootViewFolder}get hasViewFolders(){return this._viewFolders.size>1}viewFolderItems(e){return E(this._viewFolders.has(e),`View folder ${e} not found`),this._viewFolderItems.get(e)}parent(e){let t=B(e);return this._parents.get(t)||null}children(e){let t=B(e);return this._children.get(t)}*siblings(e){let t=B(e),n=this._parents.get(t),r=n?this._children.get(n.id).values():this.roots();for(let e of r)e.id!==t&&(yield e)}*ancestors(e){let t=B(e),n;for(;n=this._parents.get(t);)yield n,t=n.id}*descendants(e){for(let t of this.children(e))yield t,yield*this.descendants(t.id)}*incoming(e,t=`all`){let n=B(e);for(let e of this._incoming.get(n))switch(!0){case t===`all`:case t===`direct`&&e.target.id===n:case t===`to-descendants`&&e.target.id!==n:yield e;break}}*outgoing(e,t=`all`){let n=B(e);for(let e of this._outgoing.get(n))switch(!0){case t===`all`:case t===`direct`&&e.source.id===n:case t===`from-descendants`&&e.source.id!==n:yield e;break}}get tags(){return A(this,`tags`,()=>te([...this._allTags.keys()],_e))}get tagsSortedByUsage(){return A(this,`tagsSortedByUsage`,()=>u([...this._allTags.entries()],c(([e,t])=>({tag:e,count:t.size,tagged:t})),te((e,t)=>_e(e.tag,t.tag)),ee([ne(`count`),`desc`])))}findByTag(e,t){return me(this._allTags.get(e),e=>t===`elements`?e instanceof F:t===`views`?e instanceof K:t===`relationships`?e instanceof U:!0)}*elementsOfKind(e){for(let t of this._elements.values())t.kind===e&&(yield t)}*elementsWhere(e){let t=oe(e);for(let e of this._elements.values())t(e)&&(yield e)}*relationshipsWhere(e){let t=oe(e);for(let e of this._relations.values())t(e)&&(yield e)}addElement(e){if(this._elements.has(e.id))throw Error(`Element ${e.id} already exists`);let t=new F(this,Object.freeze(e));this._elements.set(t.id,t);let n=S(t.id);return n?(E(this._elements.has(n),`Parent ${n} of ${t.id} not found`),this._parents.set(t.id,this.element(n)),this._children.get(n).add(t)):this._rootElements.add(t),t}addImportedElement(e,t){E(!fe(t.id),`Imported element already has global FQN`);let n=ie(e,t.id);if(this._elements.has(n))throw Error(`Element ${n} already exists`);let r=new F(this,Object.freeze({...t,id:n}));this._elements.set(r.id,r);let i=S(r.id);for(;i;){if(i.includes(`.`)&&this._elements.has(i))return this._parents.set(r.id,this.element(i)),this._children.get(i).add(r),r;i=S(i)}return this._rootElements.add(r),r}addRelation(e){if(this._relations.has(e.id))throw Error(`Relation ${e.id} already exists`);let t=new U(this,Object.freeze(e)),{source:n,target:r}=t;this._relations.set(t.id,t),this._incoming.get(r.id).add(t),this._outgoing.get(n.id).add(t);let i=j(n.id,r.id);if(i)for(let e of[i,...x(i)])this._internal.get(e).add(t);for(let e of x(n.id)){if(e===i)break;this._outgoing.get(e).add(t)}for(let e of x(r.id)){if(e===i)break;this._incoming.get(e).add(t)}return t}};(function(e){e.EMPTY=J.create({_stage:`computed`,projectId:`default`,project:{id:`default`},specification:{elements:{},relationships:{},deployments:{},tags:{}},globals:{predicates:{},dynamicPredicates:{},styles:{}},deployments:{elements:{},relations:{}},elements:{},relations:{},views:{},imports:{}})})(J||={});let Pe;(function(e){e.isInside=e=>t=>w(e,t.source.id)&&w(e,t.target.id);let t=e.isDirectedBetween=(e,t)=>n=>(n.source.id===e||w(e,n.source.id))&&(n.target.id===t||w(t,n.target.id));e.isAnyBetween=(e,n)=>{let r=t(e,n),i=t(n,e);return e=>r(e)||i(e)};let n=e.isIncoming=e=>t=>(t.target.id===e||w(e,t.target.id))&&!w(e,t.source.id),r=e.isOutgoing=e=>t=>(t.source.id===e||w(e,t.source.id))&&!w(e,t.target.id);e.isAnyInOut=e=>{let t=n(e),i=r(e);return e=>t(e)||i(e)}})(Pe||={});const Y=Symbol.for(`nodejs.util.inspect.custom`);var Fe=class e{id;constructor(e,t,n){this.source=e,this.target=t,this.relations=n,this.id=Ce(`deployment:${e.id}:${t.id}`)}get expression(){return`${this.source.id} -> ${this.target.id}`}_boundary;get boundary(){return this._boundary??=this.source.commonAncestor(this.target),this._boundary}nonEmpty(){return this.relations.nonEmpty}[Y](t,n,r){let i=this.toString();return Object.defineProperty(i,`constructor`,{value:e,enumerable:!1}),i}toString(){let e=[...this.relations.model].map(e=>` `+e.expression);e.length?e.unshift(` model:`):e.unshift(` model: []`);let t=[...this.relations.deployment].map(e=>` `+e.expression);return t.length?t.unshift(` deployment:`):t.unshift(` deployment: []`),[this.expression,...e,...t].join(`
|
|
2
|
+
`),`View title cannot contain newlines`),e.includes(`/`)){let t=e.split(`/`).map(e=>e.trim()).filter(e=>e.length>0);return s(t,1)?t:[``]}return[e.trim()]},H=e=>V(e).join(`/`),je=e=>{let t=V(e);return s(t,2)?t.slice(0,-1).join(`/`):null},Me=e=>e.includes(`/`)?V(e).pop()??e:e.trim();var Ne=class{#e=new Map;#t=new Map;#n=new P.default(()=>new Set);#r=new P.default(()=>new Set);#i=new Set;#a=new Map;#o=new P.default(()=>new Set);#s=new P.default(()=>new Set);#c=new P.default(()=>new Set);#l=new P.default(()=>new Set);#u=new Map;$deployments;constructor(e){this.$model=e;let t=this.$deployments=e.$data.deployments,n=f(t.elements);for(let e of ye(n)){let t=this.addElement(e);for(let e of t.tags)this.#l.get(e).add(t);t.isInstance()&&this.#r.get(t.element.id).add(t)}for(let e of f(t.relations)){let t=this.addRelation(e);for(let e of t.tags)this.#l.get(e).add(t)}}get $styles(){return this.$model.$styles}get projectId(){return this.$model.projectId}get project(){return this.$model.project}get specification(){return this.$model.specification}element(e){if(e instanceof I||e instanceof L)return e;let t=B(e);return b(this.#e.get(t),`Element ${t} not found`)}findElement(e){return this.#e.get(e)??null}node(e){let t=this.element(e);return E(t.isDeploymentNode(),`Element ${t.id} is not a deployment node`),t}findNode(e){let t=this.findElement(e);return t?(E(t.isDeploymentNode(),`Element ${t?.id} is not a deployment node`),t):null}instance(e){let t=this.element(e);return E(t.isInstance(),`Element ${t.id} is not a deployed instance`),t}findInstance(e){let t=this.findElement(e);return t?(E(t.isInstance(),`Element ${t?.id} is not a deployed instance`),t):null}roots(){return this.#i.values()}elements(){return this.#e.values()}*nodes(){for(let e of this.#e.values())e.isDeploymentNode()&&(yield e)}*nodesOfKind(e){for(let t of this.#e.values())t.isDeploymentNode()&&t.kind===e&&(yield t)}*instances(){for(let e of this.#e.values())e.isInstance()&&(yield e)}*instancesOf(e){let t=B(e),n=this.#r.get(t);n&&(yield*n)}deploymentRef(e){if(m.isInsideInstanceRef(e)){let{deployment:t,element:n}=e;return xe(this.#u,`${t}@${n}`,()=>new ke(this.instance(t),this.$model.element(n)))}return this.element(e.deployment)}relationships(){return this.#a.values()}relationship(e){let t=B(e);return b(this.#a.get(t),`DeploymentRelationModel ${t} not found`)}findRelationship(e){return this.#a.get(e)??null}*views(){for(let e of this.$model.views())e.isDeploymentView()&&(yield e)}parent(e){let t=B(e);return this.#t.get(t)||null}children(e){let t=B(e);return this.#n.get(t)}*siblings(e){let t=B(e),n=this.parent(e)?.children()??this.roots();for(let e of n)e.id!==t&&(yield e)}*ancestors(e){let t=B(e),n;for(;n=this.#t.get(t);)yield n,t=n.id}*descendants(e,t=`desc`){for(let n of this.children(e))t===`asc`?(yield n,yield*this.descendants(n.id)):(yield*this.descendants(n.id),yield n)}*incoming(e,t=`all`){let n=B(e);for(let e of this.#o.get(n))switch(!0){case t===`all`:case t===`direct`&&e.target.id===n:case t===`to-descendants`&&e.target.id!==n:yield e;break}}*outgoing(e,t=`all`){let n=B(e);for(let e of this.#s.get(n))switch(!0){case t===`all`:case t===`direct`&&e.source.id===n:case t===`from-descendants`&&e.source.id!==n:yield e;break}}addElement(e){if(this.#e.has(e.id))throw Error(`Element ${e.id} already exists`);let t=ae(e)?new I(this,Object.freeze(e)):new L(this,Object.freeze(e),this.$model.element(e.element));this.#e.set(t.id,t);let n=S(t.id);return n?(E(this.#e.has(n),`Parent ${n} of ${t.id} not found`),this.#t.set(t.id,this.node(n)),this.#n.get(n).add(t)):(E(t.isDeploymentNode(),`Root element ${t.id} is not a deployment node`),this.#i.add(t)),t}addRelation(e){if(this.#a.has(e.id))throw Error(`Relation ${e.id} already exists`);let t=new R(this,Object.freeze(e));this.#a.set(t.id,t),this.#o.get(t.target.id).add(t),this.#s.get(t.source.id).add(t);let n=t.boundary?.id??null;if(n)for(let e of[n,...x(n)])this.#c.get(e).add(t);for(let e of x(t.source.id)){if(e===n)break;this.#s.get(e).add(t)}for(let e of x(t.target.id)){if(e===n)break;this.#o.get(e).add(t)}return t}},U=class{source;target;boundary;constructor(e,t){this.model=e,this.$relationship=t,this.source=e.element(m.flatten(t.source)),this.target=e.element(m.flatten(t.target));let n=j(this.source.id,this.target.id);this.boundary=n?this.model.element(n):null}get id(){return this.$relationship.id}get expression(){return`${this.source.id} -> ${this.target.id}`}get title(){return r(this.$relationship.title)?null:this.$relationship.title}get technology(){return r(this.$relationship.technology)?(this.kind&&this.model.specification.relationships[this.kind])?.technology??null:this.$relationship.technology}get hasSummary(){return!!this.$relationship.summary&&!!this.$relationship.description&&!t(this.$relationship.summary,this.$relationship.description)}get summary(){return _.memoize(this,`summary`,y(this.$relationship))}get description(){return _.memoize(this,`description`,g(this.$relationship))}get navigateTo(){return this.$relationship.navigateTo?this.model.view(this.$relationship.navigateTo):null}get tags(){return this.$relationship.tags??[]}get kind(){return this.$relationship.kind??null}get metadata(){return this.$relationship.metadata??{}}get links(){return this.$relationship.links??[]}get color(){return this.$relationship.color??this.model.$styles.defaults.relationship.color}get line(){return this.$relationship.line??this.model.$styles.defaults.relationship.line}get head(){return this.$relationship.head??this.model.$styles.defaults.relationship.arrow}get tail(){return this.$relationship.tail}*views(){for(let e of this.model.views())e.includesRelation(this.id)&&(yield e)}isDeploymentRelation(){return!1}isModelRelation(){return!0}hasMetadata(){return!!this.$relationship.metadata&&!i(this.$relationship.metadata)}getMetadata(e){return e?this.$relationship.metadata?.[e]:this.$relationship.metadata??{}}isTagged(e){return this.tags.includes(e)}},W=class{Aux;$viewModel;$view;$edge;constructor(e,t,n,r){this.source=n,this.target=r,this.$viewModel=e,this.$view=e.$view,this.$edge=t}get id(){return this.$edge.id}get parent(){return this.$edge.parent?this.$viewModel.node(this.$edge.parent):null}get label(){return this.$edge.label??null}get description(){return _.memoize(this,`description`,this.$edge.description)}get technology(){return this.$edge.technology??null}hasParent(){return this.$edge.parent!==null}get tags(){return this.$edge.tags??[]}get stepNumber(){return this.isStep()?se(this.id):null}get navigateTo(){return this.$edge.navigateTo?this.$viewModel.$model.view(this.$edge.navigateTo):null}get color(){return this.$edge.color}get line(){return this.$edge.line??this.$viewModel.$styles.defaults.relationship.line}get head(){return this.$edge.head??this.$viewModel.$styles.defaults.relationship.arrow}get tail(){return this.$edge.tail}isStep(){return le(this.id)}*relationships(e){for(let t of this.$edge.relations)if(e){let n=this.$viewModel.$model.findRelationship(t,e);n&&(yield n)}else yield this.$viewModel.$model.relationship(t)}includesRelation(e){let t=typeof e==`string`?e:e.id;return this.$edge.relations.includes(t)}isTagged(e){return this.tags.includes(e)}},G=class{Aux;$viewModel;$view;$node;constructor(e,t){this.$viewModel=e,this.$view=e.$view,this.$node=t}get id(){return this.$node.id}get title(){return this.$node.title}get kind(){return this.$node.kind}get description(){return _.memoize(this,`description`,this.$node.description)}get technology(){return this.$node.technology??null}get notes(){return _.memoize(this,`notes`,this.$node.notes)}get parent(){return this.$node.parent?this.$viewModel.node(this.$node.parent):null}get element(){let e=this.$node.modelRef;return e?this.$viewModel.$model.element(e):null}get deployment(){let e=this.$node.deploymentRef;return e?this.$viewModel.$model.deployment.element(e):null}get shape(){return this.$node.shape}get color(){return this.$node.color}get icon(){return this.$node.icon??null}get tags(){return this.$node.tags}get links(){return this.$node.links??[]}get navigateTo(){return this.$node.navigateTo?this.$viewModel.$model.view(this.$node.navigateTo):null}get style(){return this.$node.style}get x(){return`x`in this.$node?this.$node.x:void 0}get y(){return`y`in this.$node?this.$node.y:void 0}get width(){return`width`in this.$node?this.$node.width:void 0}get height(){return`height`in this.$node?this.$node.height:void 0}children(){return A(this,`children`,()=>new Set(this.$node.children.map(e=>this.$viewModel.node(e))))}*ancestors(){let e=this.parent;for(;e;)yield e,e=e.parent}*siblings(){let e=this.parent?.children()??this.$viewModel.roots();for(let t of e)t.id!==this.id&&(yield t)}*incoming(e=`all`){for(let t of this.$node.inEdges){let n=this.$viewModel.edge(t);switch(!0){case e===`all`:case e===`direct`&&n.target.id===this.id:case e===`to-descendants`&&n.target.id!==this.id:yield n;break}}}*incomers(e=`all`){let t=new Set;for(let n of this.incoming(e))t.has(n.source.id)||(t.add(n.source.id),yield n.source)}*outgoing(e=`all`){for(let t of this.$node.outEdges){let n=this.$viewModel.edge(t);switch(!0){case e===`all`:case e===`direct`&&n.source.id===this.id:case e===`from-descendants`&&n.source.id!==this.id:yield n;break}}}*outgoers(e=`all`){let t=new Set;for(let n of this.outgoing(e))t.has(n.target.id)||(t.add(n.target.id),yield n.target)}isLayouted(){return`width`in this.$node&&`height`in this.$node}hasChildren(){return this.$node.children.length>0}hasParent(){return this.$node.parent!==null}hasElement(){return o(this.$node.modelRef)}hasDeployment(){return o(this.$node.deploymentRef)}hasDeployedInstance(){return this.hasElement()&&this.hasDeployment()}isGroup(){return ce(this.$node)}isTagged(e){return this.tags.includes(e)}},K=class{Aux;#e;#t=new Set;#n=new Map;#r=new Map;#i=new Set;#a=new Set;#o=new Set;#s=new P.default(e=>new Set);#c;id;$model;title;folder;viewPath;constructor(e,t,n,r){this.$model=e,this.#e=n,this.id=n.id,this.folder=t,this.#c=r;for(let e of this.#e.nodes){let t=new G(this,Object.freeze(e));this.#n.set(e.id,t),e.parent||this.#t.add(t),e.deploymentRef&&this.#a.add(e.deploymentRef),e.modelRef&&this.#i.add(e.modelRef);for(let e of t.tags)this.#s.get(e).add(t)}for(let e of this.#e.edges){let t=new W(this,Object.freeze(e),this.node(e.source),this.node(e.target));for(let e of t.tags)this.#s.get(e).add(t);for(let t of e.relations)this.#o.add(t);this.#r.set(e.id,t)}this.title=n.title?Me(n.title):null,this.viewPath=n.title?H(n.title):n.id}get $styles(){return this.$model.$styles}get _type(){return this.#e[v]}get stage(){return this.#e[h]}get bounds(){if(`bounds`in this.#e)return this.#e.bounds;if(this.#c)return this.#c.bounds;throw Error(`View is not layouted`)}get titleOrId(){return this.title??this.viewOf?.title??this.id}get titleOrUntitled(){return this.title??`Untitled`}get breadcrumbs(){return A(this,`breadcrumbs`,()=>this.folder.isRoot?[this]:[...this.folder.breadcrumbs,this])}get description(){return _.memoize(this,`description`,this.#e.description)}get tags(){return this.#e.tags??[]}get links(){return this.#e.links??[]}get viewOf(){if(this.isElementView()){let e=this.#e.viewOf;return e?this.$model.element(e):null}return null}get mode(){return this.isDynamicView()?this.#e.variant??`diagram`:null}get includedTags(){return[...this.#s.keys()]}get $view(){if(!this.isLayouted()||`drifts`in this.#e)return this.#e;let e=this.#c;return e?A(this,`withDriftReasons`,()=>De(this.#e,e)):this.#e}get $layouted(){if(!this.isLayouted())throw Error(`View is not layouted`);return this.$manual??this.#e}get hasManualLayout(){return this.#c!==void 0}get hasLayoutDrifts(){if(!this.isLayouted())return!1;let e=this.$manual;return!!e?.drifts&&e.drifts.length>0}get $manual(){if(!this.isLayouted())return null;let e=this.#c;return e?this.#e._layout===`manual`?this.#e:A(this,`snapshotWithManualLayout`,()=>Ee(this.#e,e)):null}get projectId(){return this.$model.projectId}roots(){return this.#t.values()}*compounds(){for(let e of this.#n.values())e.hasChildren()&&(yield e)}node(e){let t=B(e);return b(this.#n.get(t),`Node ${t} not found in view ${this.#e.id}`)}findNode(e){return this.#n.get(B(e))??null}findNodeWithElement(e){let t=B(e);return this.#i.has(t)?he(this.#n.values(),e=>e.hasElement()&&e.element.id===t)??null:null}nodes(){return this.#n.values()}edge(e){let t=B(e);return b(this.#r.get(t),`Edge ${t} not found in view ${this.#e.id}`)}findEdge(e){return this.#r.get(B(e))??null}edges(){return this.#r.values()}*edgesWithRelation(e){for(let t of this.#r.values())t.includesRelation(e)&&(yield t)}*elements(){for(let e of this.#n.values())e.hasElement()&&(yield e)}isTagged(e){return this.tags.includes(e)}includesElement(e){return this.#i.has(B(e))}includesDeployment(e){return this.#a.has(B(e))}includesRelation(e){return this.#o.has(B(e))}isComputed(){return this.#e[h]===`computed`}isLayouted(){return this.#e[h]===`layouted`}isDiagram(){return this.#e[h]===`layouted`}isElementView(){return this.#e[v]===`element`}isScopedElementView(){return this.#e[v]===`element`&&o(this.#e.viewOf)}isDeploymentView(){return this.#e[v]===`deployment`}isDynamicView(){return this.#e[v]===`dynamic`}},q=class e{$model;path;title;isRoot;parentPath;defaultViewId;constructor(e,t,r){this.$model=e,this.path=t.join(`/`),this.isRoot=this.path===``,this.title=n(t),this.isRoot?this.parentPath=void 0:this.parentPath=t.slice(0,-1).join(`/`),this.defaultViewId=r}get defaultView(){return this.defaultViewId?this.$model.view(this.defaultViewId):null}get breadcrumbs(){return E(!this.isRoot,`Root view folder has no breadcrumbs`),A(this,`breadcrumbs`,()=>{let e=this.parent;return e?e.isRoot?[e,this]:[...e.breadcrumbs,this]:[this]})}get parent(){return E(!this.isRoot,`Root view folder has no parent`),r(this.parentPath)?null:this.$model.viewFolder(this.parentPath)}get children(){return this.$model.viewFolderItems(this.path)}get folders(){return A(this,`folders`,()=>{let t=[];for(let n of this.children)n instanceof e&&t.push(n);return t})}get views(){return A(this,`views`,()=>{let e=[];for(let t of this.children)t instanceof K&&e.push(t);return e})}},J=class e{Aux;_elements=new Map;_parents=new Map;_children=new P.default(()=>new Set);_rootElements=new Set;_relations=new Map;_incoming=new P.default(()=>new Set);_outgoing=new P.default(()=>new Set);_internal=new P.default(()=>new Set);_views=new Map;_rootViewFolder;_viewFolders=new Map;_viewFolderItems=new P.default(()=>new Set);_allTags=new P.default(()=>new Set);static fromParsed(t){return new e(t)}static create(t){return new e(t)}static fromDump(t){let{_stage:n=`layouted`,projectId:r=`unknown`,project:i,globals:a,imports:o,deployments:s,views:c,relations:l,elements:ee,specification:u}=t;return new e({[h]:n,projectId:r,project:i,globals:{predicates:a?.predicates??{},dynamicPredicates:a?.dynamicPredicates??{},styles:a?.styles??{}},imports:o??{},deployments:{elements:s?.elements??{},relations:s?.relations??{}},views:c??{},relations:l??{},elements:ee??{},specification:u})}deployment;$data;constructor(e){this.$data=e;for(let[,t]of l(e.elements)){let e=this.addElement(t);for(let t of e.tags)this._allTags.get(t).add(e)}for(let[t,n]of l(e.imports??{}))for(let e of ye(n)){let n=this.addImportedElement(t,e);for(let e of n.tags)this._allTags.get(e).add(n)}for(let t of f(e.relations)){let e=this.addRelation(t);for(let t of e.tags)this._allTags.get(t).add(e)}if(this.deployment=new Ne(this),pe(e,`computed`)||pe(e,`layouted`)){let t=be(`/`),n=u(f(e.views),c(e=>({view:e,path:H(e.title??e.id),folderPath:e.title&&je(e.title)||``})),te((e,n)=>t(e.folderPath,n.folderPath))),r=e=>{let t=this._viewFolders.get(e);if(!t){let r=re(e,`/`);E(s(r,1),`View group path "${e}" must have at least one element`);let i;i=e===``?n.find(e=>e.view.id===`index`):n.find(t=>t.path===e),t=new q(this,r,i?.view.id),this._viewFolders.set(e,t)}return t};this._rootViewFolder=r(``);for(let{folderPath:e}of n)this._viewFolders.has(e)||re(e,`/`).reduce((e,t)=>{let n=e.join(`/`),a=r(i(n)?t:n+`/`+t);return this._viewFolderItems.get(n).add(a),e.push(t),e},[]);for(let{view:t,folderPath:i}of n){let n=new K(this,r(i),t,e.manualLayouts?.[t.id]);this._viewFolderItems.get(i).add(n),this._views.set(t.id,n);for(let e of n.tags)this._allTags.get(e).add(n)}}else this._rootViewFolder=new q(this,[``],void 0),this._viewFolders.set(this._rootViewFolder.path,this._rootViewFolder)}get asParsed(){return this}get asComputed(){return this}get asLayouted(){return this}get $styles(){return A(this,`styles`,()=>ue.from(this.project.styles,this.specification.customColors))}isParsed(){return this.stage===`parsed`}isLayouted(){return this.stage===`layouted`}isComputed(){return this.stage===`computed`}get $model(){return this.$data}get stage(){return this.$data[h]}get projectId(){return this.$data.projectId??`default`}get project(){return this.$data.project??A(this,Symbol.for(`project`),()=>({id:this.projectId,styles:{},manualLayouts:{}}))}get specification(){return this.$data.specification}get globals(){return A(this,Symbol.for(`globals`),()=>({predicates:{...this.$data.globals?.predicates},dynamicPredicates:{...this.$data.globals?.dynamicPredicates},styles:{...this.$data.globals?.styles}}))}element(e){if(e instanceof F)return e;let t=B(e);return b(this._elements.get(t),`Element ${t} not found`)}findElement(e){return this._elements.get(B(e))??null}roots(){return this._rootElements.values()}elements(){return this._elements.values()}relationships(){return this._relations.values()}relationship(e,t){if(t===`deployment`)return this.deployment.relationship(e);let n=B(e),r=this._relations.get(n)??null;return r||t===`model`?b(r,`Model relation ${n} not found`):b(this.deployment.findRelationship(n),`No model/deployment relation ${n} not found`)}findRelationship(e,t){if(t===`deployment`)return this.deployment.findRelationship(e);let n=this._relations.get(B(e))??null;return n||t===`model`?n:this.deployment.findRelationship(e)}views(){return this._views.values()}view(e){let t=B(e);return b(this._views.get(t),`View ${t} not found`)}findView(e){return this._views.get(e)??null}findManualLayout(e){return`manualLayouts`in this.$data?this.$data.manualLayouts?.[e]??null:null}viewFolder(e){return b(this._viewFolders.get(e),`View folder ${e} not found`)}get rootViewFolder(){return this._rootViewFolder}get hasViewFolders(){return this._viewFolders.size>1}viewFolderItems(e){return E(this._viewFolders.has(e),`View folder ${e} not found`),this._viewFolderItems.get(e)}parent(e){let t=B(e);return this._parents.get(t)||null}children(e){let t=B(e);return this._children.get(t)}*siblings(e){let t=B(e),n=this._parents.get(t),r=n?this._children.get(n.id).values():this.roots();for(let e of r)e.id!==t&&(yield e)}*ancestors(e){let t=B(e),n;for(;n=this._parents.get(t);)yield n,t=n.id}*descendants(e){for(let t of this.children(e))yield t,yield*this.descendants(t.id)}*incoming(e,t=`all`){let n=B(e);for(let e of this._incoming.get(n))switch(!0){case t===`all`:case t===`direct`&&e.target.id===n:case t===`to-descendants`&&e.target.id!==n:yield e;break}}*outgoing(e,t=`all`){let n=B(e);for(let e of this._outgoing.get(n))switch(!0){case t===`all`:case t===`direct`&&e.source.id===n:case t===`from-descendants`&&e.source.id!==n:yield e;break}}get tags(){return A(this,`tags`,()=>te([...this._allTags.keys()],_e))}get tagsSortedByUsage(){return A(this,`tagsSortedByUsage`,()=>u([...this._allTags.entries()],c(([e,t])=>({tag:e,count:t.size,tagged:t})),te((e,t)=>_e(e.tag,t.tag)),ee([ne(`count`),`desc`])))}findByTag(e,t){return me(this._allTags.get(e),e=>t===`elements`?e instanceof F:t===`views`?e instanceof K:t===`relationships`?e instanceof U:!0)}*elementsOfKind(e){for(let t of this._elements.values())t.kind===e&&(yield t)}*elementsWhere(e){let t=oe(e);for(let e of this._elements.values())t(e)&&(yield e)}*relationshipsWhere(e){let t=oe(e);for(let e of this._relations.values())t(e)&&(yield e)}addElement(e){if(this._elements.has(e.id))throw Error(`Element ${e.id} already exists`);let t=new F(this,Object.freeze(e));this._elements.set(t.id,t);let n=S(t.id);return n?(E(this._elements.has(n),`Parent ${n} of ${t.id} not found`),this._parents.set(t.id,this.element(n)),this._children.get(n).add(t)):this._rootElements.add(t),t}addImportedElement(e,t){E(!fe(t.id),`Imported element already has global FQN`);let n=ie(e,t.id);if(this._elements.has(n))throw Error(`Element ${n} already exists`);let r=new F(this,Object.freeze({...t,id:n}));this._elements.set(r.id,r);let i=S(r.id);for(;i;){if(i.includes(`.`)&&this._elements.has(i))return this._parents.set(r.id,this.element(i)),this._children.get(i).add(r),r;i=S(i)}return this._rootElements.add(r),r}addRelation(e){if(this._relations.has(e.id))throw Error(`Relation ${e.id} already exists`);let t=new U(this,Object.freeze(e)),{source:n,target:r}=t;this._relations.set(t.id,t),this._incoming.get(r.id).add(t),this._outgoing.get(n.id).add(t);let i=j(n.id,r.id);if(i)for(let e of[i,...x(i)])this._internal.get(e).add(t);for(let e of x(n.id)){if(e===i)break;this._outgoing.get(e).add(t)}for(let e of x(r.id)){if(e===i)break;this._incoming.get(e).add(t)}return t}};(function(e){e.EMPTY=J.create({_stage:`computed`,projectId:`default`,project:{id:`default`},specification:{elements:{},relationships:{},deployments:{},tags:{}},globals:{predicates:{},dynamicPredicates:{},styles:{}},deployments:{elements:{},relations:{}},elements:{},relations:{},views:{},imports:{}})})(J||={});let Pe;(function(e){e.isInside=e=>t=>w(e,t.source.id)&&w(e,t.target.id);let t=e.isDirectedBetween=(e,t)=>n=>(n.source.id===e||w(e,n.source.id))&&(n.target.id===t||w(t,n.target.id));e.isAnyBetween=(e,n)=>{let r=t(e,n),i=t(n,e);return e=>r(e)||i(e)};let n=e.isIncoming=e=>t=>(t.target.id===e||w(e,t.target.id))&&!w(e,t.source.id),r=e.isOutgoing=e=>t=>(t.source.id===e||w(e,t.source.id))&&!w(e,t.target.id);e.isAnyInOut=e=>{let t=n(e),i=r(e);return e=>t(e)||i(e)}})(Pe||={});const Y=Symbol.for(`nodejs.util.inspect.custom`);var Fe=class e{id;constructor(e,t,n){this.source=e,this.target=t,this.relations=n,this.id=Ce(`deployment:${e.id}:${t.id}`)}get expression(){return`${this.source.id} -> ${this.target.id}`}_boundary;get boundary(){return this._boundary??=this.source.commonAncestor(this.target),this._boundary}nonEmpty(){return this.relations.nonEmpty}[Y](t,n,r){let i=this.toString();return Object.defineProperty(i,`constructor`,{value:e,enumerable:!1}),i}toString(){let e=[...this.relations.model].map(e=>` `+e.expression);e.length?e.unshift(` model:`):e.unshift(` model: []`);let t=[...this.relations.deployment].map(e=>` `+e.expression);return t.length?t.unshift(` deployment:`):t.unshift(` deployment: []`),[this.expression,...e,...t].join(`
|
|
3
3
|
`)}hasDirectDeploymentRelation(){for(let e of this.relations.deployment)if(e.source.id===this.source.id||e.target.id===this.target.id)return!0;return!1}*values(){yield*this.relations.model,yield*this.relations.deployment}mergeWith(t){return Array.isArray(t)?t.reduce((e,t)=>e.mergeWith(t),this):(E(this.source.id===t.source.id,`Cannot merge connections with different sources`),E(this.target.id===t.target.id,`Cannot merge connections with different targets`),new e(this.source,this.target,this.relations.union(t.relations)))}difference(t){return new e(this.source,this.target,this.relations.difference(t.relations))}intersect(t){return new e(this.source,this.target,this.relations.intersect(t.relations))}equals(t){return E(t instanceof e,`Other should ne DeploymentConnectionModel`),this.id===t.id&&this.source.id===t.source.id&&this.target.id===t.target.id&&M(this.relations.model,t.relations.model)&&M(this.relations.deployment,t.relations.deployment)}update(t){return t&&={model:this.relations.model,deployment:this.relations.deployment,...t},new e(this.source,this.target,t?new z(t.model??new Set,t.deployment??new Set):this.relations)}};function X(e,t){if(!t){let t=e;return e=>X(e,t)}let n=e.source===t.source,r=e.target===t.target;if(n&&r)return!1;let i=w(t.source.id,e.source.id),a=w(t.target.id,e.target.id);return i&&a||n&&a||r&&i}function Ie(e,t){let n=t;for(let t of e)X(t,n)&&(n=t);return n===t?null:n}function Le(e){let t=[],n=e.slice(),r;for(;r=n.shift();){let e;for(;e=Ie(n,r);){let r=n.indexOf(e);t.push(n.splice(r,1)[0])}t.push(r)}return t}function Re(e){return e.boundary?.id?`.${e.boundary.id}`:``}function ze(e,t){if(!e||Se(e)){let t=e??`asc`;return e=>Be(e,t)}return Be(e,t??`asc`)}function Be(e,t){return u(e,c(e=>({id:Re(e),conn:e})),ge(t),c(e=>e.conn))}function Ve(e,t){return e.filter(e=>X(t,e))}function He(e,t){return e.filter(X(t))}function Ue(e){let t=new Map;for(let n of e){let e=t.get(n.id);e?t.set(n.id,n.mergeWith(e)):t.set(n.id,n)}return[...t.values()]}function We(e,t){let n=new Map([...t].map(e=>[e.id,e]));return[...e].reduce((e,t)=>{let r=n.get(t.id);if(!r)return e.push(t),e;let i=t.difference(r);return i.nonEmpty()&&e.push(i),e},[])}function Z(e,t){return t?e.source===t.source&&e.target===t.target:t=>e.source===t.source&&e.target===t.target}function Ge(e,t){return t?e.source===t.source:t=>e.source===t.source}function Ke(e,t){return t?e.target===t.target:t=>e.target===t.target}function qe(e,t){if(!t){let t=e;return e=>qe(e,t)}let n=e;return T(n.source,t)&&!T(n.target,t)}function Je(e,t){if(!t){let t=e;return e=>Je(e,t)}let n=e;return T(n.target,t)&&!T(n.source,t)}function Ye(e,t){if(!t){let t=e;return e=>Ye(e,t)}let n=e;return T(n.source,t)!==T(n.target,t)}var Q=class e{id;constructor(e,t,n=new Set){this.source=e,this.target=t,this.relations=n,this.id=Ce(`model:${e.id}:${t.id}`)}_boundary;get boundary(){return this._boundary??=this.source.commonAncestor(this.target)}get expression(){return`${this.source.id} -> ${this.target.id}`}get isDirect(){return this.nonEmpty()&&!this.isImplicit}get isImplicit(){return this.nonEmpty()&&we(this.relations,a(Z(this)))}get directRelations(){return new Set(me(this.relations,Z(this)))}nonEmpty(){return this.relations.size>0}mergeWith(t){return E(this.source.id===t.source.id,`Cannot merge connections with different sources`),E(this.target.id===t.target.id,`Cannot merge connections with different targets`),new e(this.source,this.target,N(this.relations,t.relations))}difference(t){return new e(this.source,this.target,O(this.relations,t.relations))}intersect(t){return E(t instanceof e,`Cannot intersect connection with different type`),new e(this.source,this.target,k(this.relations,t.relations))}equals(t){E(t instanceof e,`Cannot merge connection with different type`);let n=t;return this.id===n.id&&this.source.id===n.source.id&&this.target.id===n.target.id&&M(this.relations,n.relations)}update(t){return new e(this.source,this.target,t)}[Y](t,n,r){let i=this.toString();return Object.defineProperty(i,`constructor`,{value:e,enumerable:!1}),i}toString(){return[this.expression,this.relations.size?` relations:`:` relations: [ ]`,...[...this.relations].map(e=>` `+e.expression)].join(`
|
|
4
4
|
`)}reversed(){return new e(this.target,this.source)}},Xe=e({findConnection:()=>$,findConnectionsBetween:()=>Ze,findConnectionsWithin:()=>Qe});function $(e,t,n=`directed`){if(e===t||ve(e,t))return[];let r=e.allOutgoing.intersect(t.allIncoming),i=r.nonEmpty?[new Fe(e,t,r)]:[];return n===`directed`?i:[...i,...$(t,e,`directed`)]}function Ze(e,t,n=`both`){if(e.allIncoming.isEmpty&&e.allOutgoing.isEmpty)return[];let r=[],i=[];for(let a of t)if(e!==a)for(let t of $(e,a,n))t.source===e?r.push(t):i.push(t);return[...r,...i]}function Qe(e){return[...e].reduce((e,t,n,r)=>(n===r.length-1||e.push(...Ze(t,r.slice(n+1),`both`)),e),[])}var $e=e({findConnection:()=>et,findConnectionsBetween:()=>tt,findConnectionsWithin:()=>nt});function et(e,t,n=`directed`){if(e===t||ve(e,t))return[];let r=k(e.allOutgoing,t.allIncoming),i=r.size>0?new Q(e,t,r):null;if(n===`directed`)return i?[i]:[];let a=k(e.allIncoming,t.allOutgoing),o=a.size>0?new Q(t,e,a):null;return i&&o?[i,o]:i?[i]:o?[o]:[]}function tt(e,t,n=`both`){if(e.allIncoming.size===0&&e.allOutgoing.size===0)return[];let r=[],i=[];for(let a of t)if(e!==a)for(let t of et(e,a,n))t.source===e?r.push(t):i.push(t);return[...r,...i]}function nt(e){return[...e].reduce((e,t,n,r)=>(n===r.length-1||e.push(...tt(t,r.slice(n+1),`both`)),e),[])}function rt(e){return e instanceof I}function it(e){return e instanceof L}function at(e){return rt(e)||it(e)}function ot(e){return e instanceof ke}function st(e){return e instanceof R}function ct(e){return e instanceof U}function lt(e){return e instanceof F}function ut(e){return e instanceof K}function dt(e){return e instanceof G}function ft(e){return e instanceof W}export{Fe as A,Ae as B,Ye as C,Ue as D,qe as E,K as F,I as G,je as H,G as I,F as J,R as K,W as L,Pe as M,J as N,ze as O,q as P,U as R,Ke as S,X as T,H as U,Me as V,L as W,Ve as _,ft as a,Ge as b,ot as c,et as d,tt as f,We as g,Q as h,st as i,Y as j,Le as k,dt as l,Xe as m,at as n,lt as o,$e as p,z as q,rt as r,ut as s,it as t,ct as u,Ie as v,Je as w,Z as x,He as y,Ne as z};
|
package/dist/_chunks/utils.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime.mjs";import{t}from"./libs/defu.mjs";import{F as n,P as r,Q as i,R as a,T as o,a as s,et as ee,f as c,k as l,l as u,t as d}from"./libs/remeda.mjs";import{s as f}from"./libs/mnemonist.mjs";import{t as te}from"./libs/natural-compare-lite.mjs";import{t as p}from"./libs/ohash.mjs";import{n as m}from"./libs/hast-util-sanitize.mjs";import{t as h}from"./libs/rehype-sanitize.mjs";import{t as g}from"./libs/rehype-stringify.mjs";import{l as _,t as v}from"./libs/mdast-util-from-markdown.mjs";import{t as y}from"./libs/remark-gfm.mjs";import{t as b}from"./libs/remark-github-blockquote-alert.mjs";import{t as ne}from"./libs/remark-parse.mjs";import{t as re}from"./libs/remark-rehype.mjs";import{t as ie}from"./libs/unified.mjs";function ae(e,t){if(e===void 0||e==null){let n=typeof t==`function`?t():t;throw Error(n??`Expected defined value, but received ${e}`)}return e}function x(e,t){if(!e)throw Error(t??`Invariant failed`)}function S(e){throw Error(`NonExhaustive value: ${e}`)}function C(e,t,n){return e.length===0||t.length===0?[]:(n??=Object.is,ee(d(e,t),s(([e,t])=>n(e,t)),o(([e,t])=>e)))}var w=e(te(),1);function T(e,t){return e===t?0:l(e)?l(t)?(0,w.default)(e,t):1:l(t)?-1:0}function E(e){return u(e,T)}function D(...e){return e.length===0?E:E(e[0])}function O(e=`.`,t=!1){return(n,r)=>{if(n===r)return 0;if(!n)return-1;if(!r)return 1;let i=n.split(e),a=r.split(e),o=Math.min(i.length,a.length);for(let e=0;e<o;e++){let t=i[e],n=a[e],r=(0,w.default)(t,n);if(r!==0)return r}let s=i.length-a.length;return t?-1*s:s}}function k(e){return e!=null&&typeof e==`string`}function A(e){return!!e&&Array.isArray(e)&&e.length>0}function j(e,t){return x(typeof t==`string`,`Path must be string`),typeof e==`object`&&!!e&&e[t]!=null}function M(e){return t=>j(t,e)}function N(...e){if(e.length===1&&typeof e[0]==`string`)return M(e[0]);let[t,n]=e;return j(t,n)}function P(...e){return(t=>e.some(e=>e(t)))}function F(e){let t=e.lastIndexOf(`.`);return t>0?e.slice(0,t):null}function I(e){let t=e.lastIndexOf(`.`);return t>0?e.slice(t+1):e}const L=e=>k(e)?e:e.id;function R(e,t){let n=L(e);return t?L(t).startsWith(n+`.`):e=>{let t=L(e);return n.startsWith(t+`.`)}}function z(e,t){if(!t)return t=>z(e,t);let n=L(e),r=L(t);return n===r||r.startsWith(n+`.`)||n.startsWith(r+`.`)}function B(e,t){return t?R(t,e):t=>R(e,t)}function V(e){return(k(e)?e:e.id).split(`.`).length}function H(e,t){let n=k(e)?e:e.id,r=k(t)?t:t.id;if(n===r)return 0;let i=V(n),a=V(r);if(z(n,r))return Math.abs(i-a);let o=U(n,r),s=o?V(o):0;return i+a-(2*s+1)}function U(e,t){let n=e.split(`.`);if(n.length<2)return null;let r=t.split(`.`);if(r.length<2)return null;let i=[];for(let e=0;e<Math.min(n.length,r.length)-1&&n[e]===r[e];e++)i.push(n[e]);return i.length===0?null:i.join(`.`)}function W(e){let t=e.split(`.`);if(t.pop(),!i(t,2))return t;for(let e=1;e<t.length;e++)t[e]=t[e-1]+`.`+t[e];return t.reverse()}function G(e,t){let n=e.split(`.`).length,r=t.split(`.`).length;switch(!0){case n>r:return 1;case n<r:return-1;default:return 0}}function K(e,t){return G(e.id,t.id)}function q(e){return e.map(e=>({item:e,fqn:e.id.split(`.`)})).sort((e,t)=>e.fqn.length-t.fqn.length).map(({item:e})=>e)}function J(e,t){let n=t;for(let t of e)t!==n&&R(t,n)&&(n=t);return n===t?null:n}function oe(e){let t=[],n=[...e],r;for(;r=n.shift();){let e;for(;e=J(n,r);)t.push(...n.splice(n.indexOf(e),1));t.push(r)}return t}function Y(e,t){if(!e||k(e)){let t=e??`asc`;return e=>Y(e,t)}let n=t===`desc`?-1:1;return e.map(e=>({item:e,fqn:e.id.split(`.`)})).sort((e,t)=>{if(e.fqn.length!==t.fqn.length)return(e.fqn.length-t.fqn.length)*n;for(let n=0;n<e.fqn.length;n++){let r=T(e.fqn[n],t.fqn[n]);if(r!==0)return r}return 0}).map(({item:e})=>e)}function se(e,t,n){let r=e.get(t);return r||(r=n(t),e.set(t,r)),r}function ce(e){return typeof e==`object`&&!!e&&Symbol.iterator in e}function le(e,t){let r=t??e;x(n(r));function*i(e){for(let t of e)r(t)&&(yield t)}return t?i(e):i}function ue(e,t){let r=t??e;x(n(r));function i(e){for(let t of e)if(r(t))return t}return t?i(e):i}function de(e,t){let n=t??e;x(typeof n==`number`&&n>=0,`Count must be a non-negative number`);function*r(e){let t=0;for(let r of e){if(t>=n)break;yield r,t++}}return t===void 0?e=>r(e):r(e)}function fe(e){return e?X(e):X}function*X(e){for(let t of e)yield*t}function pe(e,t){let r=t??e;x(n(r));function*i(e){for(let t of e)yield*r(t)}return t?i(e):i}function me(e){return e?Z(e):Z}function Z(e){let{value:t}=e[Symbol.iterator]().next();return t}function he(e,t){let r=t??e;x(n(r));function*i(e){for(let t of e)yield r(t)}return t?i(e):i}function ge(e,t,r){let i=a(r)?t:e,o=r??t;x(n(i));function s(e){let t=o;for(let n of e)t=i(t,n);return t}return a(r)?s(e):s}function _e(e,t){let r=t??e;x(n(r));function i(e){for(let t of e)if(r(t))return!0;return!1}return t?i(e):i}function ve(e){return e?Array.from(e):e=>Array.from(e)}function ye(e){return e?new Set(e):e=>new Set(e)}function be(e){return e?Q(e):Q}function*Q(e){let t=new Set;for(let n of e)t.has(n)||(t.add(n),yield n)}function xe(e,t,n){let r=typeof t==`symbol`?t:Symbol.for(t);return e.hasOwnProperty(r)||Object.defineProperty(e,r,{enumerable:!1,writable:!1,value:n()}),e[r]}function Se(...e){let t=100;return e.length===2?t=c(e[0],e[1]):e.length===1&&(t=e[0]),new Promise(e=>{setTimeout(()=>{e(`LIKEC4_DELAY`)},t??100)})}function Ce(){return Promise.resolve().then(()=>void 0)}function we(e){Promise.resolve().then(e)}const Te=(e,t)=>{let n=U(e.source.id,e.target.id),r=U(t.source.id,t.target.id);if(n&&!r)return 1;if(!n&&r)return-1;let i=n&&r?G(n,r):0;if(i!==0)return i;let a=G(e.source.id,t.source.id);return a===0?G(e.target.id,t.target.id):a};function Ee(...e){let t=new Set;for(let n of e)for(let e of n)t.add(e);return t}function $(e,...t){let n=new Set;if(e.size===0)return n;let r=i(t,2)?(0,f.intersection)(...t):t[0];if(r.size===0)return n;for(let t of e)r.has(t)&&n.add(t);return n}function De(e,t){if(e.size===0)return new Set;if(t.size===0)return new Set(e);let n=new Set;for(let r of e)t.has(r)||n.add(r);return n}function Oe(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}function ke(e,t){return(0,f.symmetricDifference)(e,t)}function Ae(e,t){if(e.size===0||t.size===0)return!1;t.size<e.size&&([e,t]=[t,e]);for(let n of e)if(t.has(n))return!0;return!1}function je(e){return x(typeof e==`object`&&r(e),`objectHash: value must be an object`),p(e)}function Me(e){let t=5381,n=e.length;x(n>0,`stringHash: empty string`);for(let r=0;r<n;r++)t=t*33^e.charCodeAt(r);return(t>>>0).toString(36)}function Ne(){return ie().use(ne).use(y).use(b).use(re,{allowDangerousHtml:!0}).use(h,t({attributes:{"*":[`className`],svg:[`width`,`height`,`viewBox`,`fill`,`ariaHidden`],path:[`d`,`fill`,`stroke`,`strokeWidth`,`strokeLinecap`,`strokeLinejoin`]},tagNames:[`svg`,`g`,`path`,`div`]},m)).use(g,{allowDangerousHtml:!0})}function Pe(e){return(``+Ne().processSync(e)).trim()}function Fe(e){return _(v(e),{includeHtml:!1,includeImageAlt:!1})}export{ae as $,W as A,F as B,pe as C,le as D,ue as E,V as F,P as G,Y as H,R as I,T as J,A as K,B as L,K as M,G as N,ce as O,H as P,x as Q,z as R,me as S,de as T,oe as U,q as V,N as W,D as X,O as Y,C as Z,ve as _,De as a,ge as b,$ as c,Te as d,S as et,Se as f,be as g,xe as h,je as i,U as j,se as k,ke as l,Ce as m,Pe as n,Oe as o,we as p,k as q,Me as r,Ae as s,Fe as t,Ee as u,ye as v,fe as w,he as x,_e as y,I as z};
|
|
1
|
+
import{r as e}from"./rolldown-runtime.mjs";import{t}from"./libs/defu.mjs";import{F as n,P as r,Q as i,R as a,T as o,a as s,et as ee,f as c,k as l,l as u,t as d}from"./libs/remeda.mjs";import{s as f}from"./libs/mnemonist.mjs";import{t as te}from"./libs/natural-compare-lite.mjs";import{t as p}from"./libs/ohash.mjs";import{n as m}from"./libs/hast-util-sanitize.mjs";import{t as h}from"./libs/rehype-sanitize.mjs";import{t as g}from"./libs/rehype-stringify.mjs";import{l as _,t as v}from"./libs/mdast-util-from-markdown.mjs";import{t as y}from"./libs/remark-gfm.mjs";import{t as b}from"./libs/remark-github-blockquote-alert.mjs";import{t as ne}from"./libs/remark-parse.mjs";import{t as re}from"./libs/remark-rehype.mjs";import{t as ie}from"./libs/unified.mjs";function ae(e,t){if(e===void 0||e==null){let n=typeof t==`function`?t():t;throw Error(n??`Expected defined value, but received ${e}`)}return e}function x(e,t){if(!e)throw Error(t??`Invariant failed`)}function S(e){throw Error(`NonExhaustive value: ${e}`)}function C(e,t,n){return e.length===0||t.length===0?[]:(n??=Object.is,ee(d(e,t),s(([e,t])=>n(e,t)),o(([e,t])=>e)))}var w=e(te(),1);function T(e,t){return e===t?0:l(e)?l(t)?(0,w.default)(e,t):1:l(t)?-1:0}function E(e){return u(e,T)}function D(...e){return e.length===0?E:E(e[0])}function O(e=`.`,t=!1){return(n,r)=>{if(n===r)return 0;if(!n)return-1;if(!r)return 1;let i=n.split(e),a=r.split(e),o=Math.min(i.length,a.length);for(let e=0;e<o;e++){let t=i[e],n=a[e],r=(0,w.default)(t,n);if(r!==0)return r}let s=i.length-a.length;return t?-1*s:s}}function k(e){return e!=null&&typeof e==`string`}function A(e){return!!e&&Array.isArray(e)&&e.length>0}function j(e,t){return x(typeof t==`string`,`Path must be string`),typeof e==`object`&&!!e&&e[t]!=null}function M(e){return t=>j(t,e)}function N(...e){if(e.length===1&&typeof e[0]==`string`)return M(e[0]);let[t,n]=e;return j(t,n)}function P(...e){return(t=>e.some(e=>e(t)))}function F(e){let t=e.lastIndexOf(`.`);return t>0?e.slice(0,t):null}function I(e){let t=e.lastIndexOf(`.`);return t>0?e.slice(t+1):e}const L=e=>k(e)?e:e.id;function R(e,t){let n=L(e);return t?L(t).startsWith(n+`.`):e=>{let t=L(e);return n.startsWith(t+`.`)}}function z(e,t){if(!t)return t=>z(e,t);let n=L(e),r=L(t);return n===r||r.startsWith(n+`.`)||n.startsWith(r+`.`)}function B(e,t){return t?R(t,e):t=>R(e,t)}function V(e){return(k(e)?e:e.id).split(`.`).length}function H(e,t){let n=k(e)?e:e.id,r=k(t)?t:t.id;if(n===r)return 0;let i=V(n),a=V(r);if(z(n,r))return Math.abs(i-a);let o=U(n,r),s=o?V(o):0;return i+a-(2*s+1)}function U(e,t){let n=e.split(`.`);if(n.length<2)return null;let r=t.split(`.`);if(r.length<2)return null;let i=[];for(let e=0;e<Math.min(n.length,r.length)-1&&n[e]===r[e];e++)i.push(n[e]);return i.length===0?null:i.join(`.`)}function W(e){let t=e.split(`.`);if(t.pop(),!i(t,2))return t;for(let e=1;e<t.length;e++)t[e]=t[e-1]+`.`+t[e];return t.reverse()}function G(e,t){let n=e.split(`.`).length,r=t.split(`.`).length;switch(!0){case n>r:return 1;case n<r:return-1;default:return 0}}function K(e,t){return G(e.id,t.id)}function q(e){return e.map(e=>({item:e,fqn:e.id.split(`.`)})).sort((e,t)=>e.fqn.length-t.fqn.length).map(({item:e})=>e)}function J(e,t){let n=t;for(let t of e)t!==n&&R(t,n)&&(n=t);return n===t?null:n}function oe(e){let t=[],n=[...e],r;for(;r=n.shift();){let e;for(;e=J(n,r);)t.push(...n.splice(n.indexOf(e),1));t.push(r)}return t}function Y(e,t){if(!e||k(e)){let t=e??`asc`;return e=>Y(e,t)}let n=t===`desc`?-1:1;return e.map(e=>({item:e,fqn:e.id.split(`.`)})).sort((e,t)=>{if(e.fqn.length!==t.fqn.length)return(e.fqn.length-t.fqn.length)*n;for(let n=0;n<e.fqn.length;n++){let r=T(e.fqn[n],t.fqn[n]);if(r!==0)return r}return 0}).map(({item:e})=>e)}function se(e,t,n){let r=e.get(t);return r||(r=n(t),e.set(t,r)),r}function ce(e){return typeof e==`object`&&!!e&&Symbol.iterator in e}function le(e,t){let r=t??e;x(n(r));function*i(e){for(let t of e)r(t)&&(yield t)}return t?i(e):i}function ue(e,t){let r=t??e;x(n(r));function i(e){for(let t of e)if(r(t))return t}return t?i(e):i}function de(e,t){let n=t??e;x(typeof n==`number`&&n>=0,`Count must be a non-negative number`);function*r(e){let t=0;for(let r of e){if(t>=n)break;yield r,t++}}return t===void 0?e=>r(e):r(e)}function fe(e){return e?X(e):X}function*X(e){for(let t of e)yield*t}function pe(e,t){let r=t??e;x(n(r));function*i(e){for(let t of e)yield*r(t)}return t?i(e):i}function me(e){return e?Z(e):Z}function Z(e){let{value:t}=e[Symbol.iterator]().next();return t}function he(e,t){let r=t??e;x(n(r));function*i(e){for(let t of e)yield r(t)}return t?i(e):i}function ge(e,t,r){let i=a(r)?t:e,o=r??t;x(n(i));function s(e){let t=o;for(let n of e)t=i(t,n);return t}return a(r)?s(e):s}function _e(e,t){let r=t??e;x(n(r));function i(e){for(let t of e)if(r(t))return!0;return!1}return t?i(e):i}function ve(e){return e?Array.from(e):e=>Array.from(e)}function ye(e){return e?new Set(e):e=>new Set(e)}function be(e){return e?Q(e):Q}function*Q(e){let t=new Set;for(let n of e)t.has(n)||(t.add(n),yield n)}function xe(e,t,n){let r=typeof t==`symbol`?t:Symbol.for(t);return e.hasOwnProperty(r)||Object.defineProperty(e,r,{enumerable:!1,writable:!1,value:n()}),e[r]}function Se(...e){let t=100;return e.length===2?t=c(e[0],e[1]):e.length===1&&(t=e[0]),new Promise(e=>{setTimeout(()=>{e(`LIKEC4_DELAY`)},t??100)})}function Ce(){return Promise.resolve().then(()=>void 0)}function we(e){Promise.resolve().then(e)}const Te=(e,t)=>{let n=U(e.source.id,e.target.id),r=U(t.source.id,t.target.id);if(n&&!r)return 1;if(!n&&r)return-1;let i=n&&r?G(n,r):0;if(i!==0)return i;let a=G(e.source.id,t.source.id);return a===0?G(e.target.id,t.target.id):a};function Ee(...e){let t=new Set;for(let n of e)for(let e of n)t.add(e);return t}function $(e,...t){let n=new Set;if(e.size===0)return n;let r=i(t,2)?(0,f.intersection)(...t):t[0];if(r.size===0)return n;for(let t of e)r.has(t)&&n.add(t);return n}function De(e,t){if(e.size===0)return new Set;if(t.size===0)return new Set(e);let n=new Set;for(let r of e)t.has(r)||n.add(r);return n}function Oe(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}function ke(e,t){return(0,f.symmetricDifference)(e,t)}function Ae(e,t){if(e.size===0||t.size===0)return!1;t.size<e.size&&([e,t]=[t,e]);for(let n of e)if(t.has(n))return!0;return!1}function je(e){return x(typeof e==`object`&&r(e),`objectHash: value must be an object`),p(e)}function Me(e){let t=5381,n=e.length;x(n>0,`stringHash: empty string`);for(let r=0;r<n;r++)t=t*33^e.charCodeAt(r);return(t>>>0).toString(36)}function Ne(){return ie().use(ne).use(y).use(b).use(re,{allowDangerousHtml:!0}).use(h,t({attributes:{"*":[`className`],svg:[`width`,`height`,`viewBox`,`fill`,`ariaHidden`],path:[`d`,`fill`,`stroke`,`strokeWidth`,`strokeLinecap`,`strokeLinejoin`]},tagNames:[`svg`,`g`,`path`,`div`],protocols:{src:[`data`]}},m)).use(g,{allowDangerousHtml:!0})}function Pe(e){return(``+Ne().processSync(e)).trim()}function Fe(e){return _(v(e),{includeHtml:!1,includeImageAlt:!1})}export{ae as $,W as A,F as B,pe as C,le as D,ue as E,V as F,P as G,Y as H,R as I,T as J,A as K,B as L,K as M,G as N,ce as O,H as P,x as Q,z as R,me as S,de as T,oe as U,q as V,N as W,D as X,O as Y,C as Z,ve as _,De as a,ge as b,$ as c,Te as d,S as et,Se as f,be as g,xe as h,je as i,U as j,se as k,ke as l,Ce as m,Pe as n,Oe as o,we as p,k as q,Me as r,Ae as s,Fe as t,Ee as u,ye as v,fe as w,he as x,_e as y,I as z};
|
package/dist/builder/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"../_chunks/libs/defu.mjs";import{B as t,C as n,F as r,M as i,Q as a,T as o,U as s,W as c,X as l,Y as u,et as d,k as f,w as p}from"../_chunks/libs/remeda.mjs";import{St as m,V as h,W as g,Y as _,_t as v,g as y,mt as b,ut as x,vt as S}from"../_chunks/types.mjs";import"../_chunks/geometry.mjs";import{B as C,Q as w,R as T,z as E}from"../_chunks/utils.mjs";import"../_chunks/libs/graphology-dag.mjs";import{t as D}from"../_chunks/libs/mnemonist.mjs";import"../_chunks/libs/natural-compare-lite.mjs";import"../_chunks/libs/ohash.mjs";import"../_chunks/libs/@ungap/structured-clone.mjs";import"../_chunks/libs/hast-util-sanitize.mjs";import"../_chunks/libs/rehype-sanitize.mjs";import"../_chunks/libs/hast-util-to-html.mjs";import"../_chunks/libs/character-entities-legacy.mjs";import"../_chunks/libs/character-entities-html4.mjs";import"../_chunks/libs/ccount.mjs";import"../_chunks/libs/comma-separated-tokens.mjs";import"../_chunks/libs/rehype-stringify.mjs";import"../_chunks/libs/devlop.mjs";import"../_chunks/libs/mdast-util-from-markdown.mjs";import"../_chunks/libs/escape-string-regexp.mjs";import"../_chunks/libs/mdast-util-find-and-replace.mjs";import"../_chunks/libs/mdast-util-gfm.mjs";import"../_chunks/libs/markdown-table.mjs";import"../_chunks/libs/longest-streak.mjs";import"../_chunks/libs/character-entities.mjs";import"../_chunks/libs/decode-named-character-reference.mjs";import"../_chunks/libs/micromark-extension-gfm.mjs";import"../_chunks/libs/remark-gfm.mjs";import"../_chunks/libs/remark-github-blockquote-alert.mjs";import"../_chunks/libs/remark-parse.mjs";import"../_chunks/libs/mdast-util-to-hast.mjs";import"../_chunks/libs/remark-rehype.mjs";import"../_chunks/libs/bail.mjs";import"../_chunks/libs/extend.mjs";import"../_chunks/libs/is-plain-obj.mjs";import"../_chunks/libs/trough.mjs";import"../_chunks/libs/unified.mjs";import"../_chunks/libs/@radix-ui/colors.mjs";import"../_chunks/libs/@mantine/colors-generator.mjs";import"../_chunks/model.mjs";import"../_chunks/manual-layout.mjs";import{n as O,t as k}from"../_chunks/Builder.view-element.mjs";import"../_chunks/libs/graphology.mjs";import{t as A}from"../_chunks/assignTagColors.mjs";function j(e){if(f(e)){let t=e;switch(!0){case t.startsWith(`tag is not #`):return{tag:{neq:t.replace(`tag is not #`,``)}};case t.startsWith(`tag is #`):return{tag:{eq:t.replace(`tag is #`,``)}};case t.startsWith(`kind is not `):return{kind:{neq:t.replace(`kind is not `,``)}};case t.startsWith(`kind is `):return{kind:{eq:t.replace(`kind is `,``)}};case t.startsWith(`source.`):return{operator:j(t.replace(`source.`,``)),participant:`source`};case t.startsWith(`target.`):return{operator:j(t.replace(`target.`,``)),participant:`target`};default:throw Error(`Unknown where operator: ${e}`)}}if(e.and)return{and:o(e.and,j)};if(e.or)return{or:o(e.or,j)};if(e.not)return{not:j(e.not)};throw Error(`Unknown where operator: ${e}`)}function M(...e){return t=>{if(e.length===2&&typeof e[1]!=`string`&&(`where`in e[1]||`with`in e[1])){let n=t.$expr(e[0]),r=e[1].where?j(e[1].where):void 0;r&&(n={where:{expr:n,condition:r}});let i=e[1].with;return i&&(n=g.is(e[0])?{custom:{...i,expr:n}}:{customRelation:{...i,expr:n}}),t.include(n),t}return t.include(...e.map(e=>t.$expr(e))),t}}function N(...e){return t=>{let n=t.$expr(e[0]);if(e.length===2&&e[1].where){let t=j(e[1].where);n={where:{expr:n,condition:t}}}return t.exclude(n),t}}function P(e,{notation:n,...r}){return i=>i.style({targets:(t(e)?e:[e]).map(e=>i.$expr(e)),...n?{notation:n}:{},style:{...r}})}function F(e,t){return n=>n.autoLayout(e,t)}function I(...e){return t=>e.reduce((e,t)=>t(e),t)}function L(e){if(!f(e))return e;let t=e=>e;if(e===`*`)return t({wildcard:!0});if(e.startsWith(`->`))return e.endsWith(`->`)?t({inout:L(e.replace(/->/g,``).trim())}):t({incoming:L(e.replace(`-> `,``))});if(e.endsWith(` ->`))return t({outgoing:L(e.replace(` ->`,``))});if(e.includes(` <-> `)){let[n,r]=e.split(` <-> `);return t({source:L(n),target:L(r),isBidirectional:!0})}if(e.includes(` -> `)){let[n,r]=e.split(` -> `);return t({source:L(n),target:L(r)})}return e.endsWith(`._`)?t({ref:{deployment:e.replace(`._`,``)},selector:`expanded`}):e.endsWith(`.**`)?t({ref:{deployment:e.replace(`.**`,``)},selector:`descendants`}):e.endsWith(`.*`)?t({ref:{deployment:e.replace(`.*`,``)},selector:`children`}):t({ref:{deployment:e}})}function R(e){let t={$expr:e[S]===`deployment`?L:k,autoLayout(n,r){return e.rules.push(m({direction:n,rankSep:r?.rank,nodeSep:r?.node})),t},exclude(...n){return e.rules.push({exclude:n}),t},include(...n){return e.rules.push({include:n}),t},style(n){return e.rules.push(n),t},get Expr(){throw Error(`Expr is not available in runtime`)},get Types(){throw Error(`Types are not available in runtime`)},get ElementExpr(){throw Error(`ElementExpr is not available in runtime`)},get TypedExpr(){throw Error(`TypedExpr is not available in runtime`)}};return t}function z(e){return t(e)?s(e,e=>({})):e}function B({tags:e,elements:t,deployments:n,relationships:r,...i}){let a={};e&&Object.assign(a,z(e));let o=z(t);for(let[e,t]of l(o))if(t.tags)for(let n of t.tags)w(n in a,`Invalid specification for element kind "${e}": tag "${n}" not found`);let s=z(n??{});for(let[e,t]of l(s))if(t.tags)for(let n of t.tags)w(n in a,`Invalid specification for deployment kind "${e}": tag "${n}" not found`);return{...i,tags:a,elements:o,deployments:s,relationships:z(r??{})}}function V(e){return i(e)?null:typeof e==`string`?{txt:e}:e}function H(t,s=new Map,l=[],f=new Map,g={predicates:{},dynamicPredicates:{},styles:{}},k=new Map,j=[],L=new D.default(()=>new Map)){let z=B(t),U=()=>({elements:structuredClone(z.elements),deployments:structuredClone(z.deployments),relationships:structuredClone(z.relationships),tags:A(structuredClone(z.tags)),...z.metadataKeys?{metadataKeys:z.metadataKeys}:{},customColors:{}}),W=e=>{if(!(!e||!a(e,1)))return o(e,e=>typeof e==`string`?{url:e}:e)},G=(e,t,n)=>{r(t)&&(n=t,t={}),t??={};let{links:i=[],title:a=null,description:o=null,tags:s=[],...c}=typeof t==`string`?{title:t}:{...t},l=W(i);return[m({id:e,title:a,description:V(o),tags:s,links:l,_stage:`parsed`,...c}),n]},K=e=>{let[t,n]=b(e),r=(t?L.get(t):s).get(n);return w(r,`Element with id "${e}" not found`),r},q=e=>{if(typeof e==`string`){let[t,n]=b(e);return t?{project:t,model:n}:{model:n}}return`project`in e||`deployment`in e?e:q(e.model)},J={get Types(){throw Error(`Types are not available in runtime`)},clone:()=>{let e=new D.default(()=>new Map);for(let[t,n]of L)e.set(t,structuredClone(n));return H(structuredClone(z),structuredClone(s),structuredClone(l),structuredClone(f),structuredClone(g),structuredClone(k),structuredClone(j),e)},__addElement:e=>{let[t,n]=b(e.id),r=C(n),i=t?L.get(t):s;if(r&&w(i.get(r),`Parent element with id "${r}" not found for element with id "${e.id}"`),i.has(n))throw Error(`Element with id "${e.id}" already exists`);return i.set(n,t?{...e,id:n}:e),J},__addRelation(e){let t=q(e.source),n=_.flatten(t),r=q(e.target),i=_.flatten(r),a=K(n),o=K(i);if(x(n)&&x(i))throw Error(`Cannot create relationship between global elements`);return!x(n)&&!x(i)&&w(!T(a,o),`Cannot create relationship between elements in the same hierarchy`),l.push({id:`rel${l.length+1}`,...e,source:t,target:r}),J},__fqn(e){return w(e.trim()!==``,`Id must be non-empty`),e},__deploymentFqn(e){return w(e.trim()!==``,`Id must be non-empty`),e},__addSourcelessRelation(){throw Error(`Can be called only in nested model`)},__addView:e=>{if(f.has(e.id))throw Error(`View with id "${e.id}" already exists`);return y(e)&&`viewOf`in e&&w(s.get(e.viewOf),`Invalid scoped view ${e.id}, wlement with id "${e.viewOf}" not found`),f.set(e.id,e),J},__addDeployment:e=>{if(k.has(e.id))throw Error(`Deployment with id "${e.id}" already exists`);let t=C(e.id);return t&&w(k.get(t),`Parent element with id "${t}" not found for node with id "${e.id}"`),h(e)&&(w(t,`Instance ${e.id} of ${e.element} must be deployed under a parent node`),w(s.get(e.element),`Instance "${e.id}" references non-existing element "${e.element}"`)),k.set(e.id,e),J},__addDeploymentRelation:e=>(w(!T(e.source.deployment,e.target.deployment),`Cannot create relationship between elements in the same hierarchy`),w(k.has(e.source.deployment),`Relation "${e.source.deployment} -> ${e.target.deployment}" references non-existing source`),w(k.has(e.target.deployment),`Relation "${e.source.deployment} -> ${e.target.deployment}" references non-existing target`),j.push({id:`deploy_rel${j.length+1}`,...e}),J),build:e=>({[v]:`parsed`,projectId:typeof e==`string`?e:e?.id??`from-builder`,project:{id:typeof e==`string`?e:`from-builder`,...typeof e==`object`&&e?e:{}},specification:U(),elements:c(structuredClone(Array.from(s.entries()))),relations:p(l,e=>[e.id,structuredClone(e)]),globals:structuredClone(g),deployments:{elements:c(structuredClone(Array.from(k.entries()))),relations:p(j,e=>[e.id,structuredClone(e)])},views:c(structuredClone(Array.from(f.entries()))),imports:d(Array.from(L.entries()),o(([e,t])=>[e,structuredClone([...t.values()])]),u(([e,t])=>t.length>0),c())}),toLikeC4Model:e=>O(J.build(e)),helpers:()=>({model:{model:(...e)=>t=>e.reduce((e,t)=>t(e),t),rel:(t,n,r)=>i=>{let{title:a=``,links:o=[],description:s=null,notes:c=null,...l}=e(typeof r==`string`?{title:r}:{...r},{title:null,links:null}),u=W(o);return i.__addRelation(m({source:{model:t},target:{model:n},title:a,...s&&{description:V(s)},...c&&{notes:V(c)},links:u,...l})),i},relTo:(t,n)=>r=>{let{title:i=``,links:a,description:o=null,notes:s=null,...c}=e(typeof n==`string`?{title:n}:{...n},{title:null,links:null});return r.__addSourcelessRelation(m({target:{model:t},title:i,...o&&{description:V(o)},...s&&{notes:V(s)},links:W(a),...c})),r},...n(z.elements,({style:e,...t},n)=>(r,i)=>{let a=(a=>{let{links:o,icon:s,color:c,shape:l,style:u,title:d,description:f,summary:p,...h}=typeof i==`string`?{title:i}:{...i},g=s??e?.icon,_=a.__fqn(r);return a.__addElement(m({id:_,kind:n,title:d??E(_),...f&&{description:V(f)},...p&&{summary:V(p)},style:m({icon:g,color:c??e?.color,shape:l??e?.shape,border:e?.border,opacity:e?.opacity,size:e?.size,padding:e?.padding,textSize:e?.textSize,...u}),links:W(o),...t,...h})),a});return a.with=(...e)=>t=>{a(t);let{__fqn:n,__addSourcelessRelation:i}=t;try{t.__fqn=e=>`${n(r)}.${e}`,t.__addSourcelessRelation=e=>t.__addRelation({...e,source:{model:n(r)}}),e.reduce((e,t)=>t(e),t)}finally{t.__fqn=n,t.__addSourcelessRelation=i}return t},a})},views:{views:(...e)=>t=>e.reduce((e,t)=>t(e),t),view:(e,t,n)=>{let[r,i]=G(e,t,n),a={...r,[S]:`element`,rules:[]},o=e=>(e.__addView(a),i&&i(R(a)),e);return o.with=(...e)=>t=>{o(t);let n=R(a);for(let t of e)t(n);return t},o},viewOf:(e,t,n,r)=>{let[i,a]=G(e,n,r),o={...i,viewOf:t,[S]:`element`,rules:[]},s=e=>(e.__addView(o),a&&a(R(o)),e);return s.with=(...e)=>t=>{s(t);let n=R(o);for(let t of e)t(n);return t},s},deploymentView:(e,t,n)=>{let[r,i]=G(e,t,n),a={...r,[S]:`deployment`,rules:[]},o=e=>(e.__addView(a),i&&i(R(a)),e);return o.with=(...e)=>t=>{o(t);let n=R(a);for(let t of e)t(n);return t},o},$autoLayout:F,$exclude:N,$include:M,$rules:I,$style:P},deployment:{deployment:(...e)=>t=>e.reduce((e,t)=>t(e),t),instanceOf:(e,t,n)=>r=>{i(t)?(t=e,e=E(e)):typeof t==`string`?n??={}:(n=t,t=e,e=E(e));let{links:a,title:o,description:s,summary:c,icon:l,color:u,shape:d,style:f,...p}=typeof n==`string`?{title:n}:{...n},h=r.__deploymentFqn(e);return r.__addDeployment(m({id:h,element:t,...o&&{title:o},...c&&{summary:V(c)},...s&&{description:V(s)},style:m({icon:l,color:u,shape:d,...f}),links:W(a),...p})),r},rel:(e,t,n)=>r=>{let{title:i=null,links:a,description:o=null,notes:s=null,...c}=typeof n==`string`?{title:n}:{...n};return r.__addDeploymentRelation(m({source:{deployment:e},target:{deployment:t},title:i,...o&&{description:V(o)},...s&&{notes:V(s)},links:W(a),...c})),r},...n(z.deployments??{},({style:e,...t},n)=>(r,i)=>{let a=(a=>{let{links:o,icon:s,style:c,title:l,description:u,summary:d,color:f,shape:p,...h}=typeof i==`string`?{title:i}:{...i},g=s??e?.icon,_=a.__deploymentFqn(r);return a.__addDeployment(m({id:_,kind:n,title:l??E(_),...u&&{description:V(u)},...d&&{summary:V(d)},style:m({icon:g,color:f??e?.color,shape:p??e?.shape,border:e?.border,opacity:e?.opacity,size:e?.size,padding:e?.padding,textSize:e?.textSize,...c}),links:W(o),...t,...h})),a});return a.with=(...e)=>t=>{a(t);let{__deploymentFqn:n}=t;try{t.__deploymentFqn=e=>`${n(r)}.${e}`,e.reduce((e,t)=>t(e),t)}finally{t.__deploymentFqn=n}return t},a})}}),with:(...e)=>{let t=J.clone();return e.reduce((e,t)=>t(e),t)},model:e=>{let t=J.clone(),n=t.helpers().model,r=n.model;return e({...n,_:r},r)(t)},deployment:e=>{let t=J.clone(),n=t.helpers().deployment,r=n.deployment;return e({...n,_:r},r)(t)},views:e=>{let t=J.clone(),n=t.helpers().views;return e({...n,_:n.views},n.views)(t)}};return J}const U={forSpecification(e){let t=H(e);return{...t.helpers(),builder:t}},specification(e){return H(e)}};export{U as Builder};
|
|
1
|
+
import{t as e}from"../_chunks/libs/defu.mjs";import{B as t,C as n,F as r,M as i,Q as a,T as o,U as s,W as c,X as l,Y as u,et as d,k as f,w as p}from"../_chunks/libs/remeda.mjs";import{St as m,V as h,W as g,Y as _,_t as v,g as y,mt as b,ut as x,vt as S}from"../_chunks/types.mjs";import"../_chunks/geometry.mjs";import{B as C,Q as w,R as T,z as E}from"../_chunks/utils.mjs";import"../_chunks/libs/graphology-dag.mjs";import{t as D}from"../_chunks/libs/mnemonist.mjs";import"../_chunks/libs/natural-compare-lite.mjs";import"../_chunks/libs/ohash.mjs";import"../_chunks/libs/@ungap/structured-clone.mjs";import"../_chunks/libs/hast-util-sanitize.mjs";import"../_chunks/libs/rehype-sanitize.mjs";import"../_chunks/libs/hast-util-to-html.mjs";import"../_chunks/libs/character-entities-legacy.mjs";import"../_chunks/libs/character-entities-html4.mjs";import"../_chunks/libs/ccount.mjs";import"../_chunks/libs/comma-separated-tokens.mjs";import"../_chunks/libs/rehype-stringify.mjs";import"../_chunks/libs/devlop.mjs";import"../_chunks/libs/mdast-util-from-markdown.mjs";import"../_chunks/libs/escape-string-regexp.mjs";import"../_chunks/libs/mdast-util-find-and-replace.mjs";import"../_chunks/libs/mdast-util-gfm.mjs";import"../_chunks/libs/markdown-table.mjs";import"../_chunks/libs/longest-streak.mjs";import"../_chunks/libs/character-entities.mjs";import"../_chunks/libs/decode-named-character-reference.mjs";import"../_chunks/libs/micromark-extension-gfm.mjs";import"../_chunks/libs/remark-gfm.mjs";import"../_chunks/libs/remark-github-blockquote-alert.mjs";import"../_chunks/libs/remark-parse.mjs";import"../_chunks/libs/mdast-util-to-hast.mjs";import"../_chunks/libs/remark-rehype.mjs";import"../_chunks/libs/bail.mjs";import"../_chunks/libs/extend.mjs";import"../_chunks/libs/is-plain-obj.mjs";import"../_chunks/libs/trough.mjs";import"../_chunks/libs/unified.mjs";import"../_chunks/libs/@radix-ui/colors.mjs";import"../_chunks/libs/@mantine/colors-generator.mjs";import"../_chunks/model.mjs";import"../_chunks/manual-layout.mjs";import{n as O,t as k}from"../_chunks/Builder.view-element.mjs";import"../_chunks/libs/graphology.mjs";import{t as A}from"../_chunks/assignTagColors.mjs";function j(e){if(f(e)){let t=e;switch(!0){case t.startsWith(`tag is not #`):return{tag:{neq:t.replace(`tag is not #`,``)}};case t.startsWith(`tag is #`):return{tag:{eq:t.replace(`tag is #`,``)}};case t.startsWith(`kind is not `):return{kind:{neq:t.replace(`kind is not `,``)}};case t.startsWith(`kind is `):return{kind:{eq:t.replace(`kind is `,``)}};case t.startsWith(`source.`):return{operator:j(t.replace(`source.`,``)),participant:`source`};case t.startsWith(`target.`):return{operator:j(t.replace(`target.`,``)),participant:`target`};default:throw Error(`Unknown where operator: ${e}`)}}if(e.and)return{and:o(e.and,j)};if(e.or)return{or:o(e.or,j)};if(e.not)return{not:j(e.not)};throw Error(`Unknown where operator: ${e}`)}function M(...e){return t=>{if(e.length===2&&typeof e[1]!=`string`&&(`where`in e[1]||`with`in e[1])){let n=t.$expr(e[0]),r=e[1].where?j(e[1].where):void 0;r&&(n={where:{expr:n,condition:r}});let i=e[1].with;return i&&(n=g.is(e[0])?{custom:{...i,expr:n}}:{customRelation:{...i,expr:n}}),t.include(n),t}return t.include(...e.map(e=>t.$expr(e))),t}}function N(...e){return t=>{let n=t.$expr(e[0]);if(e.length===2&&e[1].where){let t=j(e[1].where);n={where:{expr:n,condition:t}}}return t.exclude(n),t}}function P(e,{notation:n,...r}){return i=>i.style({targets:(t(e)?e:[e]).map(e=>i.$expr(e)),...n?{notation:n}:{},style:{...r}})}function F(e,t){return n=>n.autoLayout(e,t)}function I(...e){return t=>e.reduce((e,t)=>t(e),t)}function L(e){if(!f(e))return e;let t=e=>e;if(e===`*`)return t({wildcard:!0});if(e.startsWith(`->`))return e.endsWith(`->`)?t({inout:L(e.replace(/->/g,``).trim())}):t({incoming:L(e.replace(`-> `,``))});if(e.endsWith(` ->`))return t({outgoing:L(e.replace(` ->`,``))});if(e.includes(` <-> `)){let[n,r]=e.split(` <-> `);return t({source:L(n),target:L(r),isBidirectional:!0})}if(e.includes(` -> `)){let[n,r]=e.split(` -> `);return t({source:L(n),target:L(r)})}return e.endsWith(`._`)?t({ref:{deployment:e.replace(`._`,``)},selector:`expanded`}):e.endsWith(`.**`)?t({ref:{deployment:e.replace(`.**`,``)},selector:`descendants`}):e.endsWith(`.*`)?t({ref:{deployment:e.replace(`.*`,``)},selector:`children`}):t({ref:{deployment:e}})}function R(e){let t={$expr:e[S]===`deployment`?L:k,autoLayout(n,r){return e.rules.push(m({direction:n,rankSep:r?.rank,nodeSep:r?.node})),t},exclude(...n){return e.rules.push({exclude:n}),t},include(...n){return e.rules.push({include:n}),t},style(n){return e.rules.push(n),t},get Expr(){throw Error(`Expr is not available in runtime`)},get Types(){throw Error(`Types are not available in runtime`)},get ElementExpr(){throw Error(`ElementExpr is not available in runtime`)},get TypedExpr(){throw Error(`TypedExpr is not available in runtime`)}};return t}function z(e){return t(e)?s(e,e=>({})):e}function B({tags:e,elements:t,deployments:n,relationships:r,...i}){let a={};e&&Object.assign(a,z(e));let o=z(t);for(let[e,t]of l(o))if(t.tags)for(let n of t.tags)w(n in a,`Invalid specification for element kind "${e}": tag "${n}" not found`);let s=z(n??{});for(let[e,t]of l(s))if(t.tags)for(let n of t.tags)w(n in a,`Invalid specification for deployment kind "${e}": tag "${n}" not found`);return{...i,tags:a,elements:o,deployments:s,relationships:z(r??{})}}function V(e){return i(e)?null:typeof e==`string`?{txt:e}:e}function H(t,s=new Map,l=[],f=new Map,g={predicates:{},dynamicPredicates:{},styles:{}},k=new Map,j=[],L=new D.default(()=>new Map)){let z=B(t),U=()=>({elements:structuredClone(z.elements),deployments:structuredClone(z.deployments),relationships:structuredClone(z.relationships),tags:A(structuredClone(z.tags)),...z.metadataKeys?{metadataKeys:z.metadataKeys}:{},customColors:{}}),W=e=>{if(!(!e||!a(e,1)))return o(e,e=>typeof e==`string`?{url:e}:e)},G=(e,t,n)=>{r(t)&&(n=t,t={}),t??={};let{links:i=[],title:a=null,description:o=null,tags:s=[],...c}=typeof t==`string`?{title:t}:{...t},l=W(i);return[m({id:e,title:a,description:V(o),tags:s,links:l,_stage:`parsed`,...c}),n]},K=e=>{let[t,n]=b(e),r=(t?L.get(t):s).get(n);return w(r,`Element with id "${e}" not found`),r},q=e=>{if(typeof e==`string`){let[t,n]=b(e);return t?{project:t,model:n}:{model:n}}return`project`in e||`deployment`in e?e:q(e.model)},J={get Types(){throw Error(`Types are not available in runtime`)},clone:()=>{let e=new D.default(()=>new Map);for(let[t,n]of L)e.set(t,structuredClone(n));return H(structuredClone(z),structuredClone(s),structuredClone(l),structuredClone(f),structuredClone(g),structuredClone(k),structuredClone(j),e)},__addElement:e=>{let[t,n]=b(e.id),r=C(n),i=t?L.get(t):s;if(r&&w(i.get(r),`Parent element with id "${r}" not found for element with id "${e.id}"`),i.has(n))throw Error(`Element with id "${e.id}" already exists`);return i.set(n,t?{...e,id:n}:e),J},__addRelation(e){let t=q(e.source),n=_.flatten(t),r=q(e.target),i=_.flatten(r),a=K(n),o=K(i);if(x(n)&&x(i))throw Error(`Cannot create relationship between global elements`);return!x(n)&&!x(i)&&w(!T(a,o),`Cannot create relationship between elements in the same hierarchy`),l.push({id:`rel${l.length+1}`,...e,source:t,target:r}),J},__fqn(e){return w(e.trim()!==``,`Id must be non-empty`),e},__deploymentFqn(e){return w(e.trim()!==``,`Id must be non-empty`),e},__addSourcelessRelation(){throw Error(`Can be called only in nested model`)},__addView:e=>{if(f.has(e.id))throw Error(`View with id "${e.id}" already exists`);return y(e)&&`viewOf`in e&&w(s.get(e.viewOf),`Invalid scoped view ${e.id}, wlement with id "${e.viewOf}" not found`),f.set(e.id,e),J},__addDeployment:e=>{if(k.has(e.id))throw Error(`Deployment with id "${e.id}" already exists`);let t=C(e.id);return t&&w(k.get(t),`Parent element with id "${t}" not found for node with id "${e.id}"`),h(e)&&(w(t,`Instance ${e.id} of ${e.element} must be deployed under a parent node`),w(s.get(e.element),`Instance "${e.id}" references non-existing element "${e.element}"`)),k.set(e.id,e),J},__addDeploymentRelation:e=>(w(!T(e.source.deployment,e.target.deployment),`Cannot create relationship between elements in the same hierarchy`),w(k.has(e.source.deployment),`Relation "${e.source.deployment} -> ${e.target.deployment}" references non-existing source`),w(k.has(e.target.deployment),`Relation "${e.source.deployment} -> ${e.target.deployment}" references non-existing target`),j.push({id:`deploy_rel${j.length+1}`,...e}),J),build:e=>({[v]:`parsed`,projectId:typeof e==`string`?e:e?.id??`from-builder`,project:{id:typeof e==`string`?e:`from-builder`,...typeof e==`object`&&e?e:{}},specification:U(),elements:c(structuredClone(Array.from(s.entries()))),relations:p(l,e=>[e.id,structuredClone(e)]),globals:structuredClone(g),deployments:{elements:c(structuredClone(Array.from(k.entries()))),relations:p(j,e=>[e.id,structuredClone(e)])},views:c(structuredClone(Array.from(f.entries()))),imports:d(Array.from(L.entries()),o(([e,t])=>[e,structuredClone([...t.values()])]),u(([e,t])=>t.length>0),c())}),toLikeC4Model:e=>O(J.build(e)),helpers:()=>({model:{model:(...e)=>t=>e.reduce((e,t)=>t(e),t),rel:(t,n,r)=>i=>{let{title:a=``,links:o=[],description:s=null,notes:c=null,...l}=e(typeof r==`string`?{title:r}:{...r},{title:null,links:null}),u=W(o);return i.__addRelation(m({source:{model:t},target:{model:n},title:a,...s&&{description:V(s)},...c&&{notes:V(c)},links:u,...l})),i},relTo:(t,n)=>r=>{let{title:i=``,links:a,description:o=null,notes:s=null,...c}=e(typeof n==`string`?{title:n}:{...n},{title:null,links:null});return r.__addSourcelessRelation(m({target:{model:t},title:i,...o&&{description:V(o)},...s&&{notes:V(s)},links:W(a),...c})),r},...n(z.elements,({style:e,...t},n)=>(r,i)=>{let a=(a=>{let{links:o,icon:s,color:c,shape:l,style:u,title:d,description:f,summary:p,...h}=typeof i==`string`?{title:i}:{...i},g=s??e?.icon,_=W(o),v=a.__fqn(r);return a.__addElement(m({id:v,kind:n,...t,title:d??t.title??E(v),...f&&{description:V(f)},...p&&{summary:V(p)},style:m({icon:g,color:c??e?.color,shape:l??e?.shape,border:e?.border,opacity:e?.opacity,size:e?.size,padding:e?.padding,textSize:e?.textSize,...u}),..._&&{links:_},...h})),a});return a.with=(...e)=>t=>{a(t);let{__fqn:n,__addSourcelessRelation:i}=t;try{t.__fqn=e=>`${n(r)}.${e}`,t.__addSourcelessRelation=e=>t.__addRelation({...e,source:{model:n(r)}}),e.reduce((e,t)=>t(e),t)}finally{t.__fqn=n,t.__addSourcelessRelation=i}return t},a})},views:{views:(...e)=>t=>e.reduce((e,t)=>t(e),t),view:(e,t,n)=>{let[r,i]=G(e,t,n),a={...r,[S]:`element`,rules:[]},o=e=>(e.__addView(a),i&&i(R(a)),e);return o.with=(...e)=>t=>{o(t);let n=R(a);for(let t of e)t(n);return t},o},viewOf:(e,t,n,r)=>{let[i,a]=G(e,n,r),o={...i,viewOf:t,[S]:`element`,rules:[]},s=e=>(e.__addView(o),a&&a(R(o)),e);return s.with=(...e)=>t=>{s(t);let n=R(o);for(let t of e)t(n);return t},s},deploymentView:(e,t,n)=>{let[r,i]=G(e,t,n),a={...r,[S]:`deployment`,rules:[]},o=e=>(e.__addView(a),i&&i(R(a)),e);return o.with=(...e)=>t=>{o(t);let n=R(a);for(let t of e)t(n);return t},o},$autoLayout:F,$exclude:N,$include:M,$rules:I,$style:P},deployment:{deployment:(...e)=>t=>e.reduce((e,t)=>t(e),t),instanceOf:(e,t,n)=>r=>{i(t)?(t=e,e=E(e)):typeof t==`string`?n??={}:(n=t,t=e,e=E(e));let{links:a,title:o,description:s,summary:c,icon:l,color:u,shape:d,style:f,...p}=typeof n==`string`?{title:n}:{...n},h=r.__deploymentFqn(e);return r.__addDeployment(m({id:h,element:t,...o&&{title:o},...c&&{summary:V(c)},...s&&{description:V(s)},style:m({icon:l,color:u,shape:d,...f}),links:W(a),...p})),r},rel:(e,t,n)=>r=>{let{title:i=null,links:a,description:o=null,notes:s=null,...c}=typeof n==`string`?{title:n}:{...n};return r.__addDeploymentRelation(m({source:{deployment:e},target:{deployment:t},title:i,...o&&{description:V(o)},...s&&{notes:V(s)},links:W(a),...c})),r},...n(z.deployments??{},({style:e,...t},n)=>(r,i)=>{let a=(a=>{let{links:o,icon:s,style:c,title:l,description:u,summary:d,color:f,shape:p,...h}=typeof i==`string`?{title:i}:{...i},g=s??e?.icon,_=W(o),v=a.__deploymentFqn(r);return a.__addDeployment(m({id:v,kind:n,...t,title:l??t.title??E(v),...u&&{description:V(u)},...d&&{summary:V(d)},style:m({icon:g,color:f??e?.color,shape:p??e?.shape,border:e?.border,opacity:e?.opacity,size:e?.size,padding:e?.padding,textSize:e?.textSize,...c}),..._&&{links:_},...h})),a});return a.with=(...e)=>t=>{a(t);let{__deploymentFqn:n}=t;try{t.__deploymentFqn=e=>`${n(r)}.${e}`,e.reduce((e,t)=>t(e),t)}finally{t.__deploymentFqn=n}return t},a})}}),with:(...e)=>{let t=J.clone();return e.reduce((e,t)=>t(e),t)},model:e=>{let t=J.clone(),n=t.helpers().model,r=n.model;return e({...n,_:r},r)(t)},deployment:e=>{let t=J.clone(),n=t.helpers().deployment,r=n.deployment;return e({...n,_:r},r)(t)},views:e=>{let t=J.clone(),n=t.helpers().views;return e({...n,_:n.views},n.views)(t)}};return J}const U={forSpecification(e){let t=H(e);return{...t.helpers(),builder:t}},specification(e){return H(e)}};export{U as Builder};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likec4/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.55.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://likec4.dev",
|
|
6
6
|
"author": "Denis Davydkov <denis@davydkov.com>",
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
},
|
|
109
109
|
"devDependencies": {
|
|
110
110
|
"@dagrejs/dagre": "1.1.8",
|
|
111
|
-
"@mantine/colors-generator": "8.3.
|
|
111
|
+
"@mantine/colors-generator": "8.3.18",
|
|
112
112
|
"@rolldown/plugin-node-polyfills": "^1.0.3",
|
|
113
113
|
"@types/chroma-js": "^3.1.2",
|
|
114
114
|
"@types/extend": "3.0.4",
|
|
@@ -117,9 +117,9 @@
|
|
|
117
117
|
"@types/natural-compare-lite": "^1.4.2",
|
|
118
118
|
"@types/node": "~22.19.15",
|
|
119
119
|
"@types/unist": "3.0.3",
|
|
120
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
120
|
+
"@typescript/native-preview": "7.0.0-dev.20260409.1",
|
|
121
121
|
"chroma-js": "^3.2.0",
|
|
122
|
-
"defu": "^6.1.
|
|
122
|
+
"defu": "^6.1.7",
|
|
123
123
|
"fdir": "6.4.0",
|
|
124
124
|
"graphology": "^0.26.0",
|
|
125
125
|
"graphology-dag": "^0.4.1",
|
|
@@ -132,7 +132,7 @@
|
|
|
132
132
|
"obliterator": "^2.0.5",
|
|
133
133
|
"obuild": "0.4.31",
|
|
134
134
|
"ohash": "^2.0.11",
|
|
135
|
-
"oxlint": "1.
|
|
135
|
+
"oxlint": "1.59.0",
|
|
136
136
|
"rehype-format": "5.0.1",
|
|
137
137
|
"rehype-sanitize": "^6.0.0",
|
|
138
138
|
"rehype-stringify": "10.0.1",
|
|
@@ -140,15 +140,15 @@
|
|
|
140
140
|
"remark-github-blockquote-alert": "^2.0.1",
|
|
141
141
|
"remark-parse": "11.0.0",
|
|
142
142
|
"remark-rehype": "11.1.2",
|
|
143
|
-
"remeda": "^2.33.
|
|
144
|
-
"turbo": "2.
|
|
143
|
+
"remeda": "^2.33.7",
|
|
144
|
+
"turbo": "2.9.5",
|
|
145
145
|
"typescript": "5.9.3",
|
|
146
146
|
"unified": "11.0.5",
|
|
147
|
-
"vitest": "4.1.
|
|
147
|
+
"vitest": "4.1.3",
|
|
148
148
|
"@likec4/devops": "1.42.0",
|
|
149
|
-
"@likec4/
|
|
150
|
-
"@likec4/style-preset": "1.
|
|
151
|
-
"@likec4/
|
|
149
|
+
"@likec4/styles": "1.55.0",
|
|
150
|
+
"@likec4/style-preset": "1.55.0",
|
|
151
|
+
"@likec4/tsconfig": "1.55.0"
|
|
152
152
|
},
|
|
153
153
|
"scripts": {
|
|
154
154
|
"typecheck": "tsc -b --verbose",
|