@likec4/core 1.56.0 → 1.58.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{B as e,C as t,E as n,G as r,H as i,I as a,J as o,K as s,L as c,M as l,N as u,O as d,P as f,Q as p,R as m,S as h,T as g,V as _,Y as v,Z as ee,_ as te,a as ne,d as y,et as b,g as x,h as re,i as ie,k as ae,m as oe,n as se,nt as ce,o as le,q as ue,r as de,rt as S,t as fe,tt as pe,u as me,v as he,w as ge,x as _e,y as C,z as ve}from"./libs/remeda.mjs";import{Bt as ye,Cn as w,Dn as be,Et as T,G as E,Gt as xe,Ht as Se,J as Ce,Jt as D,Lt as we,Mt as Te,O,On as k,Ot as Ee,Qt as De,Rt as A,Sn as j,Tt as Oe,U as ke,W as M,Y as N,Yt as P,_t as Ae,b as je,cn as Me,d as Ne,dn as Pe,dt as Fe,et as Ie,fn as Le,g as Re,h as ze,ht as Be,jt as F,kt as I,l as Ve,ln as He,lt as Ue,mn as We,n as Ge,nn as Ke,o as qe,p as Je,q as L,r as Ye,rn as Xe,s as Ze,sn as R,tn as Qe,tt as $e,u as et,vn as tt,vt as nt,xn as z,y as rt,zt as B}from"./types.mjs";import{c as it,t as at}from"./libs/mnemonist.mjs";import{A as ot,C as st,D as ct,E as lt,M as V,N as ut,O as dt,T as ft,_ as pt,c as mt,d as ht,f as gt,g as _t,h as vt,j as yt,m as bt,n as xt,o as St,p as Ct,q as wt,r as Tt,t as Et,v as Dt,w as Ot,y as kt}from"./model.mjs";import{r as At}from"./manual-layout.mjs";import{t as jt}from"./libs/graphology.mjs";import{n as Mt,t as Nt}from"../utils/graphology/index.mjs";function Pt(e,t){let n=[],r=e.parent;for(;r;){let e=j(t.get(r),`Parent node ${r} not found`);n.push(e),r=e.parent}return n}function Ft(e,t){for(let r of t){let t=e.get(r.source),i=e.get(r.target);z(t,`Source node ${r.source} not found`),z(i,`Target node ${r.target} not found`),t.outEdges.push(r.id),i.inEdges.push(r.id);let a=Pt(t,e),o=Pt(i,e),s=a.length>0&&o.length>0?n(tt(me(a),me(o))):null;r.parent=s?s.id:null;for(let e of a){if(e===s)break;e.outEdges.push(r.id)}for(let e of o){if(e===s)break;e.inEdges.push(r.id)}}}function It(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 Lt(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 Rt(e){let t=It([...e.nodes.values()]),n=[...e.edges];if(t.length<2||n.length===0)return{nodes:t,edges:n};let i=t=>j(e.nodes.get(t)),a=new jt({multi:!0,allowSelfLoops:!0,type:`directed`}),[o,s]=he(b(n,g(e=>{let t=i(e.source),n=i(e.target),r=e.parent?i(e.parent):null;return{id:e.id,edge:e,parent:r,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,Mt.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(Pt(s,e.nodes),ne(e=>e.inEdges.includes(t.id)),r(e=>{a.mergeNode(e.id),(0,Mt.default)(a,t.source,e.id)||a.mergeDirectedEdge(t.source,e.id),(0,Mt.default)(a,e.id,t.target)||a.mergeDirectedEdge(e.id,t.target)})),n.parent){let e=i(n.parent);a.mergeNode(e.id),(0,Mt.default)(a,e.id,n.id)||a.mergeDirectedEdge(e.id,n.id),s.parent&&s.parent!==n.parent&&((0,Mt.default)(a,e.id,s.parent)||a.mergeDirectedEdge(e.id,s.parent))}for(let{edge:e}of s)l(e);z(c.length===n.length,`Not all edges were added to the graph`);let u=(0,Nt.topologicalSort)(a),d=[],f=t.slice();for(let e of u){let t=f.findIndex(t=>t.id===e);z(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:Lt(It(d)),edges:c}}function zt(e){return e.hash=Oe({id:e.id,__:e._type??`element`,autoLayout:e.autoLayout,nodes:b(e.nodes,g(e=>({id:e.id,icon:d(e.icon)&&e.icon!==`none`?`Y`:`N`,title:e.title,description:Ue(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})),ge(({id:e,...t})=>[e,t])),edges:b(e.edges,g(e=>({source:e.source,target:e.target,label:e.label,description:Ue(e.description),technology:e.technology??null,dir:e.dir,head:e.head,tail:e.tail,line:e.line})),ge(({source:e,target:t,...n})=>[`${e}:${t}`,n]))}),e}var Bt=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}},Vt=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(P(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(ve(t)&&(z(!this.markedToMoveExplicitToImplicit,`Already marked to move explicits`),this.markedToMoveExplicitToImplicit=t),P(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=T(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,D(t=>e.explicits.has(t)&&!ye(e.final,Me(t))),B()),t.size>0&&(t=this.filterForMoveToImplicits(t),e.explicits=T(e.explicits,t),e.final=T(e.final,t)),e}removeElements(e){return e.elements=T(e.elements,this.excluded.elements),e.explicits=T(e.explicits,this.excluded.elements),e.final=T(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=T(n,e.explicits),e.final=T(e.final,n),e)}precommit(e){return e}postcommit(e){return z(T(e.explicits,e.elements).size===0,`Explicits must be subset of elements`),z(T(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,...pt(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))}},Ht=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 ct([...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(P(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(P(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(P(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]=he(this._connections,t=>e.final.has(t.source));e.connections=this.processConnections(ct([...e.connections,...n,...r])),t=new Set(e.connections.flatMap(e=>[e.source,e.target]))}return e.elements=F(e.elements,this._ordered,this.explicits,t,this.implicits),e.explicits=I(e.elements,F(e.explicits,this.explicits)),e.final=I(e.elements,F(e.final,this.explicits,t)),this.memory.update(this.postcommit(e))}};function Ut(e,t=`final`){let n=We(A(t===`final`?e.final:e.elements)),r=new Set(e.connections.flatMap(e=>[e.source,e.target])),i=new Set(n),a=new at.default(()=>null),o=n.reduce((e,t,n,r)=>(e.set(t,r.slice(n+1).filter(e=>R(t,e)).map(e=>(i.delete(e),e)).reduce((e,n)=>(e.some(e=>R(e,n))||(e.push(n),a.set(n,t)),e),[])),e),new at.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 Wt=class extends Vt{};function H(e){if(M.isCustom(e))return H(e.custom.expr);if(M.isWhere(e)){let t=H(e.where.expr),n=O(e.where.condition);return e=>t(e)&&n(e)}if(M.isElementKindExpr(e))return e.isEqual?t=>t.kind===e.elementKind:t=>t.kind!==e.elementKind;if(M.isElementTagExpr(e))return e.isEqual?({tags:t})=>t.includes(e.elementTag):({tags:t})=>!t.includes(e.elementTag);if(M.isWildcard(e))return()=>!0;if(M.isModelRef(e)){let t=N.flatten(e.ref);if(e.selector===`expanded`)return e=>e.id===t||Pe(e.id)===t;if(e.selector===`descendants`||e.selector===`children`){let e=t+`.`;return t=>t.id.startsWith(e)}return e=>e.id===t}w(e)}function Gt(e,t,n){let{shape:i,color:a,icon:o,...s}=e.style,l=!c(s);b(n,v(u(Fe)),v(t),r(t=>{t.shape=i??t.shape,t.color=a??t.color,m(o)&&(t.icon=o),m(e.notation)&&(t.notation=e.notation),l&&(t.style={...t.style,...s})}))}function Kt(e,t){for(let n of e)!je(n)||n.targets.length===0||Gt(n,S(n.targets.map(H)),t);return t}var qt=class e{static kind=Ie;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))}},Jt=class extends Vt{excludeRelations(e){return b(this.memory.connections,v(t=>Ee(t.relations,e)),r(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=T(this.memory.explicits,e.explicits);for(let n of t)e.explicitFirstSeenIn.delete(n);let n=T(this.memory.elements,e.elements);for(let t of n)e.lastSeenIn.delete(t);return e}},Yt=class extends Jt{constructor(e,t){super(e,t),this.memory=e,this.expression=t}};const{findConnection:Xt,findConnectionsBetween:Zt}=Ct;var Qt=class extends Ht{connectWithExisting(e,t=`both`){let n=this._connections.length,r=()=>this._connections.length>n;if(!P(e)){if(t===`in`||t===`both`)for(let t of this.memory.elements)this.addConnections(Xt(t,e,`directed`));return(t===`out`||t===`both`)&&this.addConnections(Zt(e,this.memory.elements,`directed`)),r()}let i=[...e];if(t===`in`||t===`both`)for(let e of this.memory.elements)this.addConnections(Zt(e,i,`directed`));if(t===`out`||t===`both`)for(let e of i)this.addConnections(Zt(e,this.memory.elements,`directed`));return r()}addImplicitWithinScope(e){e&&(!this.memory.scope||R(this.memory.scope,e))&&this.addImplicit(e)}processConnections(e){return ke.isRelationExpr(this.expression)||b(e,r(({source:e,target:t,boundary:n})=>{b(fe([...A(e.ancestors()).reverse(),e],[...A(t.ancestors()).reverse(),t]),ee(([e,t])=>e===t),le(1),r(([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=T(e.explicits,this.memory.explicits);for(let n of t)e.explicitFirstSeenIn.set(n,`@root`);return e}},$t=class extends Qt{constructor(e,t){super(e,t),this.memory=e,this.expression=t}postcommit(e){let t=T(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}},en=class e extends Bt{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 Qt(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],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)}},tn=class e extends en{static enter(t,n){let r=`@gr${t.groups.length+1}`;if(t instanceof e){let i=it.default.from([...t.stack].reverse()),a=t.mutableState();return a.groups.push(new qt(r,n,t.activeGroupId)),i.push(r),new e(a,t.scope,i)}let i=t.mutableState();i.groups.push(new qt(r,n,null));let a=it.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 j(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 $t(this,e)}stageExclude(e){return new Yt(this,e)}leave(){let t=this.mutableState();return this.stack.pop(),this.stack.peek()?new e(t,this.scope,this.stack):new en(t,this.scope)}};function nn(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 rn(e){let{id:t,title:n,...r}=h(e.$element,[`summary`,`description`,`metadata`,`style`,`tags`]),{color:i,icon:a,shape:o,...s}=e.style;return k({id:t,title:n,modelRef:t,shape:o,color:i,icon:a,style:s,description:be(e.$element),tags:[...e.tags],metadata:e.$element.metadata,...r})}function an({defaults:e},t,n){let r=new Map,i=new Map;n?.forEach(({id:t,parent:n,viewRule:a,elements:o})=>{n&&j(r.get(n),`Parent group node ${n} not found`).children.push(t),r.set(t,{id:t,parent:n,kind:Ie,title:a.title??``,color:a.color??e.group.color??e.color,shape:`rectangle`,children:[],inEdges:[],outEdges:[],level:0,depth:0,tags:[],style:k({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(Xe).forEach(({id:e,...t})=>{let n=Pe(e),a=0,o;for(;n&&(o=r.get(n),!o);)n=Pe(n);let s=t.modelRef??e;if(!o&&i.has(s)){let e=j(i.get(s));o=r.get(e),n=e}o&&(o.children.length==0&&(o.depth=1,nn(o,r)),o.children.push(e),a=o.level+1);let c=k({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,j(r.get(e)))}),t.forEach(({id:e})=>{a.set(e,j(r.get(e)))}),a}function on(e){let{title:t,description:n=null}=e;return{...t&&{title:t,description:n},...te(e,[`color`,`technology`,`head`,`line`,`tail`,`kind`,`navigateTo`])}}function sn(e,t){let n=b(e,y((e,t)=>(d(t.title)&&!e.title.includes(t.title)&&e.title.push(t.title),d(t.description)&&!e.description.some(_(t.description))&&e.description.push(t.description),d(t.technology)&&!e.technology.includes(t.technology)&&e.technology.push(t.technology),d(t.kind)&&!e.kind.includes(t.kind)&&e.kind.push(t.kind),d(t.color)&&!e.color.includes(t.color)&&e.color.push(t.color),d(t.line)&&!e.line.includes(t.line)&&e.line.push(t.line),d(t.head)&&!e.head.includes(t.head)&&e.head.push(t.head),d(t.tail)&&!e.tail.includes(t.tail)&&e.tail.push(t.tail),d(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=C(n.title)??(n.title.length>1?`[...]`:void 0),i=ie(n.tags),a=k({title:r,description:C(n.description),technology:C(n.technology),kind:C(n.kind),head:C(n.head),tail:C(n.tail),color:C(n.color),line:C(n.line),navigateTo:C(n.navigateTo),...De(i)&&{tags:i}});if(t){let e=on(t);a=x({...a,...e},d)}return l(a.title)&&d(a.technology)&&(a.title=`[${a.technology}]`,delete a.technology),a}const{findConnection:cn,findConnectionsBetween:U,findConnectionsWithin:ln}=bt;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 un(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 dn(e){if(L.isWildcard(e))return()=>!0;if(L.isElementTagExpr(e)||L.isElementKindExpr(e))throw Error(`element kind and tag expressions are not supported in deployment view rules`);if(L.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=>Pe(e.id)===t:e=>e.id===t}if(L.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?Pe(n)===t:!0}:e=>{let n=e.modelRef??null;return n?n===t:!0}}w(e)}function fn(e){return be(e.$instance)??be(e.element.$element)}function pn(e){let t=e.id,n=e.onlyOneInstance();return k({id:t,deploymentRef:t,title:e.title,kind:e.kind,technology:e.technology??void 0,links:p(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:be(e.$node)??void 0,tags:[...e.tags],style:h(e.style,[`icon`,`shape`,`color`])})}function mn(e){let t=e.$instance,n=e.element,{icon:r,color:i,shape:a,...o}=e.style,s=[...n.links,...t.links??[]];return k({id:e.id,kind:`instance`,title:e.title,description:fn(e)??void 0,technology:e.technology??void 0,tags:[...e.tags],links:p(s,1)?s:void 0,icon:r,color:i,shape:a,style:o,deploymentRef:t.id,modelRef:n.id,notation:t.notation})}function hn(e){return e.isInstance()?mn(e):pn(e)}function gn(e){return e.reduce((e,t)=>{let n=[...t.relations.model,...t.relations.deployment];z(p(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}=sn(n.map(e=>e.$relationship)),d=k({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 _n(e,t){let n=an(e.$styles,[...t.final].map(hn));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??=fn(r)??null,t.technology??=r.technology,c(t.tags)&&(t.tags=[...r.tags]),(!t.links||c(t.links))&&p(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 vn(e,t){for(let n of e)!je(n)||n.targets.length===0||Gt(n,S(n.targets.map(dn)),t);return t}function yn(e){let t=new at.default(()=>[]);for(let n of e)for(let e of n.relations.model)t.get(e).push(n);let n=new at.default(()=>new Set);for(let[e,a]of t)p(a,2)&&b(a,s(e=>[{group:`$source-${e.source.id}`,conn:e},{group:`$target-${e.target.id}`,conn:e}]),i(oe(`group`)),de(),v(p(2)),r(re(g(oe(`conn`)),dt(`desc`),ee((e,t,n)=>t===0||e.boundary===n[t-1].boundary),r(t=>{n.get(t).add(e)}))));return n}function bn(e){e=ct(e);let t=yn(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;z(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=F(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(),Se(([e,t])=>e.update({model:t,deployment:null})),A())}function xn(e){return _t(e,bn(e))}function Sn(e){return b(e,ct,y((t,n)=>{let{source:r,target:i,relations:a}=n;if(r.isInstance()&&i.isInstance())return t;let o=wt.empty();if(r.isDeploymentNode()&&i.isDeploymentNode()){let[e]=cn(i,r,`directed`);e&&(o=a.intersect(e.relations))}for(let t of e)ft(t,n)&&(o=o.union(a.intersect(t.relations)));return o.nonEmpty&&t.push(new ot(r,i,o)),t},[]))}function Cn(e){return _t(e,Sn(e))}var wn=class extends Ht{connectWithExisting(e,t=`both`){let n=this._connections.length,r=()=>this._connections.length>n;if(!P(e)){if(t===`in`||t===`both`)for(let t of this.memory.elements)this.addConnections(cn(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,xn,Cn);return b(t,r(({source:e,target:t,boundary:n})=>{b(fe([...A(e.ancestors()).reverse(),e],[...A(t.ancestors()).reverse(),t]),ee(([e,t])=>e===t),le(1),r(([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}},Tn=class e extends Bt{static empty(){return new e({elements:new Set,explicits:new Set,final:new Set,connections:[]})}stageInclude(e){return new wn(this,e)}stageExclude(e){return new Wt(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&&_(this.state,t.state)}diff(e){return{added:{elements:A(T(e.elements,this.elements)),explicits:A(T(e.explicits,this.explicits)),final:A(T(e.final,this.final)),connections:A(_t(e.connections,this.connections))},removed:{elements:A(T(this.elements,e.elements)),explicits:A(T(this.explicits,e.explicits)),final:A(T(this.final,e.final)),connections:_t(this.connections,e.connections)}}}toString(){return[`final:`,...[...this.final].map(e=>` `+e.id),`connections:`,...this.connections.map(e=>` `+e.expression)].join(`
2
- `)}[yt](e,t,n){return this.toString()}};const En={include:({expr:e,model:t,memory:n,stage:r})=>{let i=O(e.where.condition);return j(Rn(`include`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i}))},exclude:({expr:e,model:t,memory:n,stage:r})=>{let i=O(e.where.condition);return j(Rn(`exclude`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i}))}},Dn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(L.isWildcard(e.incoming)){for(let e of a){if(e.allOutgoing.isEmpty)continue;let t=K(U(e,[...Un(e)],`directed`),i);r.addConnections(t)}return r}z(L.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(L.isElementTagExpr(e.incoming)||L.isElementKindExpr(e.incoming))throw Error(`element kind and tag expressions are not supported in exclude`);if(L.isModelRef(e.incoming))return G(kn(t,e.incoming),{stage:r,memory:n},i);if(L.isWildcard(e.incoming))return r;let a=On(W(t,e.incoming)),o=b(n.connections,v(a),K(i));return r.excludeConnections(o),r}};function On(e){return S(e.map(e=>{let t=t=>t===e||R(e,t);return e=>!t(e.source)&&t(e.target)}))}function kn(e,t){let n=un(e,t);return new Set(n.flatMap(e=>[...e.allIncoming]))}const An={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(L.isWildcard(e.outgoing)){for(let e of a)if(!e.allIncoming.isEmpty)for(let t of Un(e)){let n=K(cn(t,e,`directed`),i);r.addConnections(n)}return r}z(L.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(L.isElementTagExpr(e.outgoing)||L.isElementKindExpr(e.outgoing))throw Error(`element kind and tag expressions are not supported in exclude`);if(L.isModelRef(e.outgoing))return G(Mn(t,e.outgoing),{stage:r,memory:n},i);if(L.isWildcard(e.outgoing))return r;let a=jn(W(t,e.outgoing)),o=b(n.connections,v(a),K(i));return r.excludeConnections(o),r}};function jn(e){return S(e.map(e=>{let t=t=>t===e||R(e,t);return e=>t(e.source)&&!t(e.target)}))}function Mn(e,t){let n=un(e,t);return new Set(n.flatMap(e=>[...e.allOutgoing]))}const Nn={include:({expr:{source:e,target:t,isBidirectional:n=!1},model:r,stage:i,where:a})=>{if(L.isElementTagExpr(e)||L.isElementKindExpr(e)||L.isElementTagExpr(t)||L.isElementKindExpr(t))throw Error(`element kind and tag expressions are not supported in include`);z(!L.isModelRef(e),`Invalid source model ref in direct relation`),z(!L.isModelRef(t),`Invalid target model ref in direct relation`);let o=L.isWildcard(e),c=L.isWildcard(t),l=n?`both`:`directed`,u;switch(!0){case o&&c:u=b(ln(r.instances()),K(a),g(e=>(i.addImplicit(e.boundary),e)));break;case!o&&c:{let t=W(r,e),i=jn(t),o=i;if(n){let e=On(t);o=t=>i(t)!==e(t)}u=b(t,s(e=>U(e,Un(e),l)),v(o),K(a));break}case o&&!c:{let e=W(r,t),i=On(e),o=i;if(n){let t=jn(e);o=e=>t(e)!==i(e)}u=b(e,s(e=>[...Un(e)].flatMap(t=>cn(t,e,l))),v(o),K(a));break}default:{z(!o,`Inference failed - source should be a deployment ref`),z(!c,`Inference failed - target should be a deployment ref`);let n=W(r,e),i=W(r,t),d=jn(n),f=On(i);u=b(n,s(e=>U(e,i,l)),v(e=>d(e)&&f(e)),K(a))}}return i.addConnections(u),L.isDeploymentRef(e)&&f(e.selector)&&i.addImplicit(r.element(e.ref.deployment)),L.isDeploymentRef(t)&&f(t.selector)&&i.addImplicit(r.element(t.ref.deployment)),i},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=dn(e.target),o=dn(e.source),s;switch(!0){case L.isWildcard(e.source)&&L.isWildcard(e.target):return r.excludeConnections(K(n.connections,i)),r;case L.isModelRef(e.source)&&L.isModelRef(e.target):return s=Pn({source:e.source,target:e.target,expr:e,model:t}),G(s,{stage:r,memory:n},i);case L.isModelRef(e.source)&&L.isWildcard(e.target):return s=Mn(t,e.source),G(s,{stage:r,memory:n},i);case L.isModelRef(e.source):return s=Mn(t,e.source),G(s,{stage:r,memory:n},i,e=>a(e.target));case L.isModelRef(e.target):return s=kn(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,v(c),K(i));return l.length===0||r.excludeConnections(l),r}}};function Pn({source:e,target:t,expr:n,model:r}){let i=un(r,e),a=un(r,t),o=n.isBidirectional?`both`:`directed`,s=[];for(let e of i)s.push(...gt(e,a,o));return new Set(s.flatMap(e=>[...e.relations]))}const Fn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(L.isWildcard(e.inout)){for(let e of a){let t=Bn(U(e,[...Un(e)],`both`),i);r.addConnections(t)}return r}z(L.isDeploymentRef(e.inout),`Only deployment refs are supported in include`);let o=W(t,e.inout);for(let e of a){let t=Bn(U(e,o,`both`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(L.isElementTagExpr(e.inout)||L.isElementKindExpr(e.inout))throw Error(`element kind and tag expressions are not supported in exclude`);if(L.isModelRef(e.inout)){let a=un(t,e.inout);return a.length===0?r:G(F(new Set,...a.flatMap(e=>[e.allIncoming,e.allOutgoing])),{stage:r,memory:n},i)}if(L.isWildcard(e.inout))return r;let a=W(t,e.inout),o=On(a),s=jn(a),c=b(n.connections,v(e=>o(e)!==s(e)),K(i));return r.excludeConnections(c),r}},In={include:({expr:e,model:t,memory:n,stage:r})=>{let i=O(e.where.condition);return Rn(`include`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})},exclude:({expr:e,model:t,memory:n,stage:r})=>{let i=O(e.where.condition);return Rn(`exclude`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})}},Ln={include:({model:e,stage:t,where:n})=>{let r=[],i;return i=n?b([...e.elements()],q(n)):A(Se(e.roots(),e=>(e.onlyOneInstance()||r.push(...e.children()),e))),t.addExplicit(i),r.length>1?(t.addConnections(ln([...i,...r])),t.connectWithExisting(r)):t.addConnections(ln(i)),t.connectWithExisting(i),t},exclude:({stage:e,memory:t,where:n})=>{let r=b([...t.elements],q(n));return e.exclude(r),e}};function Rn(e,{expr:t,where:n,...r}){switch(!0){case L.isElementTagExpr(t):case L.isElementKindExpr(t):throw Error(`element kind and tag expressions are not supported in deployment view rules`);case Ce.isCustom(t):case L.isCustom(t):case L.isModelRef(t):return;case L.isWhere(t):return En[e]({...r,expr:t,where:n});case Ce.isWhere(t):return In[e]({...r,expr:t,where:n});case L.isDeploymentRef(t):return Wn[e]({...r,expr:t,where:n});case L.isWildcard(t):return Ln[e]({...r,expr:t,where:n});case Ce.isDirect(t):return Nn[e]({...r,expr:t,where:n});case Ce.isInOut(t):return Fn[e]({...r,expr:t,where:n});case Ce.isOutgoing(t):return An[e]({...r,expr:t,where:n});case Ce.isIncoming(t):return Dn[e]({...r,expr:t,where:n});default:w(t)}}function G(e,{stage:t,memory:n},r,i=()=>!0){if(e.size===0)return t;let a=b(n.connections,v(e=>i(e)),v(t=>Ee(t.relations.model,e)),g(t=>t.update({deployment:null,model:I(t.relations.model,e)})),K(r),v(e=>e.nonEmpty()));return a.length===0?t:t.excludeConnections(a)}function zn(e,t){return K(e,t).nonEmpty()}function K(...t){if(t.length===1)return e=>K(e,t[0]);let[n,r]=t;return r===null?n:e(n)?n.map(e=>K(e,r)).filter(e=>e.nonEmpty()):n.update({model:new Set([...n.relations.model.values()].filter(e=>r(Hn(n)(e)))),deployment:new Set([...n.relations.deployment.values()].filter(e=>r(Hn(n)(e))))})}function q(...t){if(t.length===1){let e=t[0];return e==null?e=>e:t=>t.filter(t=>e(Vn(t,t)))}let[n,r]=t;return e(n)?r==null?n:n.filter(e=>r(Vn(e,e))):r?.(Vn(n,n))??!0}function Bn(e,t){return t?b(e,v(e=>zn(e,t))):e}function Vn(e,t){if(St(e)){let n=xt(t)&&Et(t)?t:null;return{kind:e.kind,tags:[...e.tags,...n?.tags??[]],metadata:e.metadata}}if(mt(e))return te(e.element,[`tags`,`kind`,`metadata`]);if(Et(e))return{kind:e.element.kind,tags:[...e.tags,...e.element.tags],metadata:e.metadata};if(Tt(e))return te(e,[`tags`,`kind`,`metadata`]);w(e)}function Hn(e){return t=>({tags:t.tags,kind:t.kind,metadata:t.metadata,source:Vn(t.source,e.source),target:Vn(t.target,e.target)})}function Un(e){let t=new Set;for(let n of e.descendingSiblings())t.add(n);return t}const Wn={include:e=>{let{expr:t,where:n}=e,r=e.model.element(t.ref.deployment);if(Et(r))return q(r,n)&&(e.stage.addExplicit(r),e.stage.connectWithExisting(r)),e.stage;switch(!0){case t.selector===`expanded`:Kn(r,e);break;case t.selector===`children`:Gn(r,e);break;case t.selector===`descendants`:qn(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=dn(e),a=b([...n.elements],v(i),q(r));return t.exclude(a),t}};function Gn(e,{stage:t,where:n}){let r=q([...e.children()],n);r.length!==0&&(t.addImplicit(e),t.addConnections(ln(r)),t.connectWithExisting(r),t.addExplicit(r))}function Kn(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(ln(i)),n.connectWithExisting(i,`out`)),n.addImplicit(i),n.connections.length>0&&n.addExplicit(e)}function qn(e,{stage:t,where:n}){let i=e=>{let r=[];for(let t of e.children())t.isDeploymentNode()&&r.push(...i(t)),q(t,n)&&r.push(t);return t.connectWithExisting(r,`in`),t.addConnections(ln(r)),t.addImplicit(r),r},a=i(e);if(a.length===0)return;t.connectWithExisting(a,`out`);let o=Jn(t);b(a,v(e=>o.has(e)),r(e=>t.addExplicit(e)))}function Jn(e){return b(e.mergedConnections(),xn,Cn,y((e,t)=>(e.add(t.source),e.add(t.target),e),new Set))}var Yn=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,xn,Cn),n=_t(e.connections,t);if(n.length===0)return e;let r=e.stageExclude({});return r.excludeConnections(n,!0),r.commit()}step2ProcessImplicits(e){let t=F(this.memory.elements,e.elements),n=F(e.final,this.memory.explicits),i=new at.default(()=>new Set);for(let t of e.connections)if(t.boundary)for(let e of t.relations.model)i.get(e).add(t.boundary);for(let[e,r]of i)if(!(r.size<2))for(let e of r)t.delete(e)&&n.add(e);let a=new Set(n),o=e=>{for(let t of a)if(e===t||R(e,t))return!0;return!1};return b(T(t,a),D(e=>e.isDeploymentNode()),A(),Le,r(e=>{let t=[...e.children()].filter(o).length;if(t>=2){n.add(e);return}t===1&&ye(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=Ut(e,`final`),r=e.stageExclude({}),i=r=>!(t.has(r)||e.explicits.has(r)||n.hasInOut(r)||n.root.has(r)),a=C([...n.root]);a&&!e.explicits.has(a)&&r.exclude(a);for(let t of e.final){let e=C(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 Xn(e,t){let n=Tn.empty();for(let r of t)if(rt(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=Rn(t,{expr:r,model:e,stage:i,memory:n,where:null})??i,n=i.commit()}}return Yn.for(n).commit()}function Zn(e,{docUri:t,rules:n,...r}){let i=Xn(e.deployment,n),a=_n(e,i),s=gn(i.connections);Ft(a,s);let c=Rt({nodes:a,edges:s}),l=vn(n,c.nodes),u=o(n,Ve),d=At(l);return zt({...r,[Ae]:`computed`,[nt]:`deployment`,autoLayout:{direction:u?.direction??`TB`,...u?.nodeSep&&{nodeSep:u.nodeSep},...u?.rankSep&&{rankSep:u.rankSep}},edges:c.edges,nodes:g(l,e=>(e.icon===`none`&&delete e.icon,e)),...d.length>0&&{notation:{nodes:d}}})}function Qn(e){return t=>Ge(t)?t.groupRules.flatMap(Qn(e)):rt(t)&&`include`in t?t.include.filter(e):[]}function $n(e,t){let n=e.flatMap(Qn(M.isCustom));if(n.length===0)return t;let r=[...t];for(let{custom:{expr:e,...t}}of n){let{border:n,opacity:i,multiple:o,iconColor:s,iconSize:c,iconPosition:u,padding:d,size:f,textSize:p,...m}=_e(t,l),h=k({border:n,opacity:i,multiple:o,iconColor:s,iconSize:c,iconPosition:u,padding:d,size:f,textSize:p}),g=!a(h),_=!a(m),v=H(e);r.forEach((e,t)=>{Fe(e)||!v(e)||(_&&(e={...e,...m,isCustomized:!0}),g&&(e={...e,isCustomized:!0,style:{...e.style,...h}}),r[t]=e)})}return r}function er(e,t){return e.reduce((e,n)=>{if(et(n)){let r=t.predicates[n.predicateId];return l(r)?e:e.concat(r)}if(Ne(n)){let r=t.styles[n.styleId];return l(r)?e:e.concat(r)}return e.push(n),e},[])}function tr(e,t){return e.reduce((e,n)=>{if(et(n)){let r=t.dynamicPredicates[n.predicateId];return l(r)?e:e.concat(r)}if(Ne(n)){let r=t.styles[n.styleId];return l(r)?e:e.concat(r)}return e.push(n),e},[])}function nr(e,t){let n=new Set;for(let r of t)if(rt(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 rr=e=>{if(qe(e)){let t=[],n=[];for(let r of e.__parallel)if(Ze(r)){let[e,...i]=r.__series;t.push(e),n.push(...i)}else t.push(r);return[...t,...n]}return Ze(e)?[...e.__series]:e};function ir(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 s(t,rr)){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 ar(e,t,n){let r=ht(e,t,`directed`).flatMap(e=>[...e.relations]).sort(Te);if(!De(r))return{};if(r.length===1){let e=r[0];return k({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,s(e=>e.tags),ie()),a=p(i,1)?i:void 0,o=g(r,e=>e.id),c=ue(r).$relationship.navigateTo;c===n&&(c=void 0),c||=b(r,s(e=>e.$relationship.navigateTo&&e.$relationship.navigateTo!==n?e.$relationship.navigateTo:[]),ie(),C());let l=b(r,y((e,{title:t,technology:n,$relationship:r})=>(d(t)&&e.title.add(t),d(r.color)&&e.color.add(r.color),d(r.line)&&e.line.add(r.line),d(r.kind)&&e.kind.add(r.kind),d(n)&&e.technology.add(n),d(r.description)&&!e.description.some(_(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 k({tags:a??void 0,relations:o,navigateTo:c,kind:C([...l.kind]),title:C([...l.title]),color:C([...l.color]),line:C([...l.line]),technology:C([...l.technology]),description:C(l.description)})}var or=class{steps=[];constructor(e,t){this.model=e,this.view=t}compute(){let{docUri:e,rules:t,steps:n,...r}=this.view,i=tr(t,this.model.globals),a=nr(this.model,i),s=ir(this.model,n),c=b(F(I(a,s),s,a),A(),We),l=c.reduce((e,t,n,r)=>{for(let i=n+1;i<r.length;i++){let n=r[i];if(R(t,n)){e.push(t);break}}return e},[]),u=(e,t,n)=>{if(Ze(e)){for(let r of e.__series)t=u(r,t,n);return t}let r=n?Be(n,t):Be(t),{source:i,target:a,title:o,isBackward:s,navigateTo:f,notation:p,...m}=e,h=this.model.element(i),g=c.indexOf(h);z(g>=0,`Source ${i} not found`);let _=this.model.element(a),v=c.indexOf(_);z(v>=0,`Target ${a} not found`),(l.includes(h)||l.includes(_))&&console.error(`Step ${h.id} -> ${_.id} because it involves a compound`);let{title:ee,relations:te,navigateTo:ne,...y}=ar(h,_,this.view.id),b=d(f)&&f!==this.view.id?f:ne,x=e.kind?this.model.specification.relationships[e.kind]:void 0;return this.steps.push(k({...y,...!e.technology&&!y.technology&&x?.technology&&{technology:x.technology},...!e.color&&!y.color&&x?.color&&{color:x.color},...!e.line&&!y.line&&x?.line&&{line:x.line},...!e.head&&x?.head&&{head:x.head},...!e.tail&&x?.tail&&{tail:x.tail},...m,id:r,source:h,target:_,navigateTo:b,title:o??ee,relations:te??[],isBackward:g>v})),t+1},f=1;for(let e of n){if(qe(e)){let t=1;for(let n of e.__parallel)t=u(n,t,f);f++;continue}f=u(e,f)}let p=an(this.model.$styles,c.map(rn)),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=j(p.get(t.id),`Source node ${t.id} not found`),l=j(p.get(n.id),`Target node ${n.id} not found`),u={id:e,parent:Ke(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=Pe(u.parent);c.outEdges.push(u.id),l.inEdges.push(u.id);for(let e of Qe(u.source)){if(e===u.parent)break;p.get(e)?.outEdges.push(u.id)}for(let e of Qe(u.target)){if(e===u.parent)break;p.get(e)?.inEdges.push(u.id)}return u}),_=$n(i,Kt(i,c.map(e=>j(p.get(e.id))))),v=o(i,Ve),ee=At(_);return zt({...r,[nt]:`dynamic`,[Ae]:`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,...ee.length>0&&{notation:{nodes:ee}}})}};function sr(e,t){return new or(e,t).compute()}function cr(e){switch(!0){case E.isCustom(e):return cr(e.customRelation.expr);case E.isWhere(e):{let t=cr(e.where.expr),n=O(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 E.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 E.isInOut(e):{let t=H(e.inout);return e=>t(e.source)||t(e.target)}case E.isIncoming(e):{let t=H(e.incoming);return e=>t(e.target)}case E.isOutgoing(e):{let t=H(e.outgoing);return e=>t(e.source)}default:w(e)}}function lr(e,t,n){let r=e.flatMap(Qn(E.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:$e(a)}:{},c=o?{notes:$e(o)}:{},u=_e(s,l),d=cr(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,...u,...r,...c,label:n??e.label,isCustomized:!0})})}return i}function ur(e){return b([...e],ct,y((e,t,n,r)=>{let i=kt(r,t),a=F(...i.map(oe(`relations`))),o=I(t.relations,a);if(i.length>0&&(o=F(o,t.directRelations)),Dt(r,t.reversed())&&(o=F(o,t.directRelations)),o.size<t.relations.size){let e=r.some(st(t.source)),n=r.some(st(t.target));e&&(o=F(o,B(D(t.relations,lt(t.source))))),n&&(o=F(o,B(D(t.relations,Ot(t.target)))))}return o.size>0&&e.push(t.update(o)),e},[]))}var dr=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=ur(e.connections);if(t.length===0)return e;let n=e.stageExclude({});return n.excludeConnections(t,!0),n.commit()}step2ProcessImplicits(e){let t=F(this.memory.elements,e.elements),n=F(e.final,this.memory.explicits),i=new Set(n),a=e=>{for(let t of i)if(e===t||R(e,t))return!0;return!1};return b(T(t,i),A(),Le,r(e=>{let t=[...e.children()].filter(a).length;if(t>=2){n.add(e);return}t===1&&ye(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=Ut(e,`final`),r=e.stageExclude({}),i=r=>!(t.has(r)||e.explicits.has(r)||n.hasInOut(r)||n.root.has(r)),a=C([...n.root]);a&&!e.explicits.has(a)&&r.exclude(a);for(let t of e.final){let e=C(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:fr,findConnectionsBetween:J,findConnectionsWithin:Y}=Ct;function X(e,t){switch(!0){case M.isElementKindExpr(t):return[...D(e.elements(),e=>t.isEqual===(e.kind===t.elementKind))];case M.isElementTagExpr(t):return[...D(e.elements(),e=>t.isEqual===e.tags.includes(t.elementTag))];case t.selector===`expanded`:{let n=e.element(N.flatten(t.ref));return[n,...n.children()]}case t.selector===`children`:case t.selector===`descendants`:{let n=e.element(N.flatten(t.ref)),r=t.selector===`children`?A(n.children()):A(n.descendants());return r&&r.length>0?r:[n]}case M.isModelRef(t):return[e.element(N.flatten(t.ref))];default:w(t)}}function pr(e,t){if(t.isEmpty()||e.length===0)return e;let n=S(e.map(e=>Me(e))),r=A(D(t.elements,t=>!e.includes(t)&&n(t)));return[...e,...r]}function mr(e,{memory:t,model:n}){let r=X(n,e);return M.isModelRef(e)?e.selector===`descendants`?r:pr(r,t):r}const hr={include:({expr:e,model:t,stage:n,where:r})=>{let i=t.element(N.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}},gr={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}},_r={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}},vr=()=>!0,yr=e=>e;function br(e){return e.reduce((e,t)=>{let n=[...t.relations];z(p(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}=sn(n.map(e=>e.$relationship),C(v(n,e=>e.source.id===i&&e.target.id===a))?.$relationship),d=k({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 xr(e,t){return an(e.$styles,[...t.final].map(rn),t.groups)}const Z=M.isWildcard,Sr=(e,t)=>e.isAncestorOf(t)||e.isDescendantOf(t),Cr={include:({expr:{source:e,target:t,isBidirectional:n=!1},memory:r,model:i,stage:a,where:o,filterWhere:c})=>{let l=Z(e),u=Z(t),d=[];switch(!0){case l&&u&&r.isEmpty()&&o!==vr:{let e=b(i.relationships(),D(o),A(),g(e=>new vt(e.source,e.target,new Set([e]))));return a.addConnections(e),a}case l&&u&&!r.isEmpty()&&o!==vr:d.push(...Y(r.elements));break;case l&&u:d.push(...Y(i.roots()));break;case!l&&u&&o!==vr:{let t=b(X(i,e),s(e=>b(e,se(pe(n===!0),{onTrue:e=>F(e.allIncoming,e.allOutgoing),onFalse:e=>e.allOutgoing}),D(o),we(),A(),he(t=>t.source===e),([t,n])=>ce(b(t,v(t=>!Sr(e,t.target)),g(t=>new vt(e,t.target,new Set([t])))),b(n,v(t=>!Sr(e,t.source)),g(t=>new vt(t.source,e,new Set([t]))))))));return a.addConnections(t),a}case!l&&u:{let[t,a]=wr(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!==vr:{let e=b(X(i,t),s(e=>b(e,se(pe(n===!0),{onTrue:e=>F(e.allIncoming,e.allOutgoing),onFalse:e=>e.allIncoming}),D(o),A(),he(t=>t.target===e),([t,n])=>ce(b(n,v(t=>!Sr(e,t.target)),g(t=>new vt(e,t.target,new Set([t])))),b(t,v(t=>!Sr(e,t.source)),g(t=>new vt(t.source,e,new Set([t]))))))));return a.addConnections(e),a}case l&&!u:{let[e,a]=wr(t,{memory:r,model:i}),o=n?`both`:`directed`;for(let t of a)d.push(...J(t,e,o));break}default:{z(!Z(e),`Inference failed - source must be not a wildcard`),z(!Z(t),`Inference failed - target must be not a wildcard`);let a=mr(e,{memory:r,model:i}),o=mr(t,{memory:r,model:i}),s=n?`both`:`directed`;for(let e of a)d.push(...J(e,o,s))}}return a.addConnections(c(d)),a},exclude:({expr:{source:e,target:t,isBidirectional:n},model:r,memory:i,stage:a,where:o})=>{let c=Z(e),l=Z(t),u;switch(!0){case c&&l:u=b(i.connections,s(re(oe(`relations`),D(o),A())),B());break;case!c&&l:u=b(X(r,e),s(e=>b(e,se(pe(n===!0),{onTrue:e=>F(e.allIncoming,e.allOutgoing),onFalse:e=>e.allOutgoing}),D(o),A())),B());break;case c&&!l:u=b(X(r,t),s(e=>b(e,se(pe(n===!0),{onTrue:e=>F(e.allIncoming,e.allOutgoing),onFalse:e=>e.allIncoming}),D(o),A())),B());break;default:{z(!Z(e),`Inference failed - source must be not a wildcard`),z(!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)He(e,t)||(s=F(s,I(e.allOutgoing,t.allIncoming),n?I(t.allOutgoing,e.allIncoming):new Set));u=B(D(s,o))}}return a.excludeRelations(u),a}};function wr(e,{memory:t,model:n}){let r=X(n,e);if(!p(r,1))return[[],[]];if(M.isModelRef(e)){let i=A(n.element(N.flatten(e.ref)).ascendingSiblings());return[pr(r,t),pr(i,t)]}return[r,b(r,g(e=>e.ascendingSiblings()),xe(),we(),A(),e=>pr(e,t))]}const Tr={include:({expr:e,scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=e.incoming,s=[];if(M.isWildcard(o)){if(!t)return;for(let e of t.ascendingSiblings())s.push(...fr(e,t,`directed`))}else{let e=mr(o,{memory:r,model:n}),t=[...r.elements];t.length===0&&t.push(...ie(e.flatMap(e=>[...e.ascendingSiblings()])));let i=Er(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(M.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 Er(e,t){switch(!0){case M.isElementKindExpr(t):case M.isElementTagExpr(t):{let e=H(t);return t=>e(t.target)}case M.isModelRef(t)&&t.selector===`children`:{let n=N.flatten(t.ref);return S([...e.children(n)].map(e=>V.isIncoming(e.id)))}case M.isModelRef(t)&&t.selector===`descendants`:{let n=N.flatten(t.ref);return S([V.isInside(n),...[...e.children(n)].map(e=>V.isIncoming(e.id))])}case M.isModelRef(t)&&t.selector===`expanded`:{let e=N.flatten(t.ref);return S([V.isIncoming(e),V.isInside(e)])}case M.isModelRef(t):{let e=N.flatten(t.ref);return V.isIncoming(e)}default:w(t)}}const Dr={include:({expr:{inout:e},scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=[];if(M.isWildcard(e)){if(!t)return;o.push(...J(t,t.ascendingSiblings()))}else{let t=mr(e,{memory:r,model:n}),i=[...r.elements];i.length===0&&(i=ie(t.flatMap(e=>A(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(M.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(B(a.filter(i))),r}},Or={include:({expr:e,scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=e.outgoing,s=[];if(M.isWildcard(o)){if(!t)return;s.push(...J(t,t.ascendingSiblings(),`directed`))}else{let e=mr(o,{memory:r,model:n}),t=[...r.elements];t.length===0&&t.push(...ie(e.flatMap(e=>[...e.ascendingSiblings()])));let i=kr(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(M.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(B(a.filter(i))),r}};function kr(e,t){switch(!0){case M.isElementKindExpr(t):case M.isElementTagExpr(t):{let e=H(t);return t=>e(t.source)}case M.isModelRef(t)&&t.selector===`children`:{let n=N.flatten(t.ref);return S([...e.children(n)].map(e=>V.isOutgoing(e.id)))}case M.isModelRef(t)&&t.selector===`descendants`:{let n=N.flatten(t.ref);return S([V.isInside(n),...[...e.children(n)].map(e=>V.isOutgoing(e.id))])}case M.isModelRef(t)&&t.selector===`expanded`:{let e=N.flatten(t.ref);return S([V.isOutgoing(e),V.isInside(e)])}case M.isModelRef(t):{let e=N.flatten(t.ref);return V.isOutgoing(e)}default:w(t)}}const Ar={include:({scope:e,model:t,stage:n,memory:r,where:i})=>{if(!e){let e=i===vr?[...t.roots()]:A(D(t.elements(),i));if(e.length===0)return;let[r,a]=he(e,e=>!e.imported);return n.addExplicit(r),n.addImplicit(a),n.addConnections(Y(e)),n.connectWithExisting(e),n}let a=A(D(e.children(),i)),o=a.length>0;if(!o){let t=J(e,e.siblings()),r=e.parent;t.length===0&&r&&n.addExplicit(r),a.push(e)}n.addExplicit(e);let s=B([...r.elements,...e.descendingSiblings()]);for(let e of s)n.addConnections(J(e,a,`directed`));o&&(n.addConnections(Y(a)),n.addExplicit(a));for(let e of a)n.addConnections(J(e,s,`directed`));return n},exclude:({scope:e,memory:t,stage:n,where:r})=>r===vr?e?(n.exclude([e,...e.descendants()]),n):en.empty(t.scope).stageExclude(n.expression):(n.exclude(v([...t.elements],r)),n)};function jr(e,t,n){switch(!0){case M.isCustom(e):return t===`include`?jr(e.custom.expr,t,n):n.stage;case M.isWhere(e):{let r=O(e.where.condition),i=e=>v(e,r);return jr(e.where.expr,t,{...n,where:r,filterWhere:i})}case M.isModelRef(e)&&e.selector===`expanded`:return hr[t]({...n,expr:e})??n.stage;case M.isWildcard(e):return Ar[t]({...n,expr:e})??n.stage;case M.isElementKindExpr(e):case M.isElementTagExpr(e):return gr[t]({...n,expr:e})??n.stage;case M.isModelRef(e):return _r[t]({...n,expr:e})??n.stage;default:w(e)}}function Mr(e,t,n){switch(!0){case E.isCustom(e):return t===`include`?Mr(e.customRelation.expr,t,n):n.stage;case E.isWhere(e):{let r=O(e.where.condition),i=e=>new Set(v([...e],r)),a=e=>b(e,g(e=>new vt(e.source,e.target,i(e.relations))),v(e=>e.nonEmpty()));return Mr(e.where.expr,t,{...n,where:r,filterWhere:a})}case E.isInOut(e):return Dr[t]({...n,expr:e})??n.stage;case E.isDirect(e):return Cr[t]({...n,expr:e})??n.stage;case E.isOutgoing(e):return Or[t]({...n,expr:e})??n.stage;case E.isIncoming(e):return Tr[t]({...n,expr:e})??n.stage;default:w(e)}}function Nr(e,t,n){let r={model:e,scope:t.scope,where:vr,filterWhere:yr};for(let i of n){if(Ge(i)){t=Nr(e,tn.enter(t,i),i.groupRules),z(t instanceof tn,`processPredicates must return ActiveGroupMemory`),t=t.leave();continue}if(rt(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 ke.isFqnExpr(i):n=jr(i,e,{...r,stage:n,memory:t})??n;break;case ke.isRelationExpr(i):n=Mr(i,e,{...r,stage:n,memory:t})??n;break;default:w(i)}t=n.commit()}}}return t}function Pr(e,t,n){return t=Nr(e,t,n),dr.for(t).commit()}function Fr(e,{docUri:t,rules:n,...r}){let i=er(n,e.globals),a=r.viewOf?e.asComputed.element(r.viewOf):null,s=Pr(e,en.empty(a),i);s.isEmpty()&&a&&(s=s.update({final:new Set([a])})),s=Lr(s);let c=xr(e,s),l=br(s.connections);Ft(c,l);let u=Rt({nodes:c,edges:l}),d=$n(i,Kt(i,u.nodes)),f=o(i,Ve),p=At(d),m=Ir(i,d);return zt({...r,_stage:`computed`,autoLayout:{direction:f?.direction??`TB`,...f?.nodeSep&&{nodeSep:f.nodeSep},...f?.rankSep&&{rankSep:f.rankSep}},edges:lr(i,d,u.edges),nodes:g(d,e=>(e.icon===`none`&&delete e.icon,e)),...p.length>0&&{notation:{nodes:p}},...m.length>0&&{ranks:m}})}function Ir(e,t){let n=[];for(let r of e){if(!Ye(r)||r.targets.length===0)continue;let e=b(t,v(S(r.targets.map(H))),g(e=>e.id));p(e,1)&&n.push({type:r.rank,nodes:e})}return n}function Lr(e){if(e.groups.length===0)return e;let t=new at.default(()=>new Set),n=new Map,i=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(We([...e.explicitFirstSeenIn.keys()]),r(r=>{if(!i(r)){let i=j(e.explicitFirstSeenIn.get(r));n.set(r,i),t.get(i).add(r)}})),b(We([...e.lastSeenIn.keys()]),v(e=>!n.has(e)),r(r=>{if(i(r)||a(r))return;let o=j(e.lastSeenIn.get(r));n.set(r,o),t.get(o).add(r)})),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 Rr(e,t){switch(!0){case Re(e):return Fr(t,e);case Je(e):return Zn(t,e);case ze(e):return sr(t,e);default:w(e)}}function zr(e,t){try{return{isSuccess:!0,view:Rr(e,t)}}catch(e){return{isSuccess:!1,error:e instanceof Error?e:Error(`Unknown error: ${e}`),view:void 0}}}function Br(e){let n=ut.create(e),{views:r,_stage:i,...a}=e,o=t(r,e=>Rr(e,n));return{[Ae]:`computed`,...a,views:o}}function Vr(e){return ut.create(Br(e))}const Q=e=>e;function $(e){if(!ae(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{Rr as a,Ft as c,zr as i,Vr as n,Fr as o,Br as r,Rt as s,$ as t};
1
+ import{B as e,C as t,E as n,G as r,H as i,I as a,J as o,K as s,L as c,M as l,N as u,O as d,P as f,Q as p,R as m,S as h,T as g,V as _,Y as v,Z as ee,_ as te,a as ne,d as y,et as b,g as x,h as re,i as ie,k as ae,m as oe,n as se,nt as ce,o as le,q as ue,r as de,rt as S,t as fe,tt as pe,u as me,v as he,w as ge,x as _e,y as C,z as ve}from"./libs/remeda.mjs";import{An as ye,Bt as be,Dt as xe,En as w,Ft as Se,G as Ce,Gt as we,Ht as T,Jt as Te,K as E,Mt as D,O,Ot as Ee,Pt as k,Qt as De,Tn as A,Ut as Oe,Vt as j,X as M,Y as N,Z as P,Zt as F,_n as ke,_t as Ae,an as je,b as Me,bt as Ne,d as Pe,dn as Fe,dt as Ie,fn as Le,g as Re,h as ze,hn as Be,in as Ve,jn as I,jt as He,kt as L,l as Ue,mn as We,n as Ge,nt as Ke,o as qe,on as Je,p as Ye,pt as Xe,q as R,r as Ze,rt as Qe,s as $e,tn as et,u as tt,un as z,wn as B,xn as nt,y as rt,yt as it}from"./types.mjs";import{c as at,t as ot}from"./libs/mnemonist.mjs";import{A as st,C as ct,D as lt,E as ut,M as V,N as dt,O as ft,T as pt,_ as mt,c as ht,d as gt,f as _t,g as vt,h as yt,j as bt,m as xt,n as St,o as Ct,p as wt,q as Tt,r as Et,t as Dt,v as Ot,w as kt,y as At}from"./model.mjs";import{r as jt}from"./manual-layout.mjs";import{t as Mt}from"./libs/graphology.mjs";import{n as Nt,t as Pt}from"../utils/graphology/index.mjs";function Ft(e,t){let n=[],r=e.parent;for(;r;){let e=A(t.get(r),`Parent node ${r} not found`);n.push(e),r=e.parent}return n}function It(e,t){for(let r of t){let t=e.get(r.source),i=e.get(r.target);B(t,`Source node ${r.source} not found`),B(i,`Target node ${r.target} not found`),t.outEdges.push(r.id),i.inEdges.push(r.id);let a=Ft(t,e),o=Ft(i,e),s=a.length>0&&o.length>0?n(nt(me(a),me(o))):null;r.parent=s?s.id:null;for(let e of a){if(e===s)break;e.outEdges.push(r.id)}for(let e of o){if(e===s)break;e.inEdges.push(r.id)}}}function H(e){if(E.isCustom(e))return H(e.custom.expr);if(E.isWhere(e)){let t=H(e.where.expr),n=O(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=P.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}w(e)}function Lt(e){return function t(n){switch(!0){case R.isCustom(n):return t(n.customRelation.expr);case R.isWhere(n):{let e=t(n.where.expr),r=O(n.where.condition);return t=>e(t)&&r({source:{tags:t.source.tags,kind:t.source.kind,metadata:t.source.metadata},target:{tags:t.target.tags,kind:t.target.kind,metadata:t.target.metadata},...t.tags&&{tags:t.tags},...t.kind&&{kind:t.kind},...t.metadata&&{metadata:t.metadata}})}case R.isDirect(n):{let t=e(n.source),r=e(n.target);return e=>t(e.source)&&r(e.target)||!!n.isBidirectional&&t(e.target)&&r(e.source)}case R.isInOut(n):{let t=e(n.inout);return e=>t(e.source)||t(e.target)}case R.isIncoming(n):{let t=e(n.incoming);return e=>t(e.target)}case R.isOutgoing(n):{let t=e(n.outgoing);return e=>t(e.source)}default:w(n)}}}const Rt=Lt(H);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 i=t=>A(e.nodes.get(t)),a=new Mt({multi:!0,allowSelfLoops:!0,type:`directed`}),[o,s]=he(b(n,g(e=>{let t=i(e.source),n=i(e.target),r=e.parent?i(e.parent):null;return{id:e.id,edge:e,parent:r,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,Nt.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)),r(e=>{a.mergeNode(e.id),(0,Nt.default)(a,t.source,e.id)||a.mergeDirectedEdge(t.source,e.id),(0,Nt.default)(a,e.id,t.target)||a.mergeDirectedEdge(e.id,t.target)})),n.parent){let e=i(n.parent);a.mergeNode(e.id),(0,Nt.default)(a,e.id,n.id)||a.mergeDirectedEdge(e.id,n.id),s.parent&&s.parent!==n.parent&&((0,Nt.default)(a,e.id,s.parent)||a.mergeDirectedEdge(e.id,s.parent))}for(let{edge:e}of s)l(e);B(c.length===n.length,`Not all edges were added to the graph`);let u=(0,Pt.topologicalSort)(a),d=[],f=t.slice();for(let e of u){let t=f.findIndex(t=>t.id===e);B(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=Ee({id:e.id,__:e._type??`element`,autoLayout:e.autoLayout,nodes:b(e.nodes,g(e=>({id:e.id,icon:d(e.icon)&&e.icon!==`none`?`Y`:`N`,title:e.title,description:Ie(e.description),technology:e.technology??null,shape:e.shape,size:e.style.size??null,iconSize:e.style.iconSize??null,iconColor:e.style.iconColor??null,iconPosition:e.style.iconPosition??null,border:e.style.border??null,opacity:e.style.opacity??null,multiple:e.style.multiple??null,textSize:e.style.textSize??null,padding:e.style.padding??null,children:e.children})),ge(({id:e,...t})=>[e,t])),edges:b(e.edges,g(e=>({id:e.id,source:e.source,target:e.target,label:e.label,description:Ie(e.description),technology:e.technology??null,dir:e.dir,head:e.head,tail:e.tail,line:e.line})),ge(e=>[e.id,{...e}]))}),e}var Ut=class{state;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{memory;expression;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(De(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(ve(t)&&(B(!this.markedToMoveExplicitToImplicit,`Already marked to move explicits`),this.markedToMoveExplicitToImplicit=t),De(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=L(new Set(this.memory.connections.flatMap(e=>[e.source,e.target])),new Set(e.connections.flatMap(e=>[e.source,e.target])));return t=D(t,e.elements),t=b(t,F(t=>e.explicits.has(t)&&!Oe(e.final,Fe(t))),T()),t.size>0&&(t=this.filterForMoveToImplicits(t),e.explicits=L(e.explicits,t),e.final=L(e.final,t)),e}removeElements(e){return e.elements=L(e.elements,this.excluded.elements),e.explicits=L(e.explicits,this.excluded.elements),e.final=L(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=L(n,e.explicits),e.final=L(e.final,n),e)}precommit(e){return e}postcommit(e){return B(L(e.explicits,e.elements).size===0,`Explicits must be subset of elements`),B(L(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,...mt(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{memory;expression;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 lt([...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(De(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(De(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(De(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]=he(this._connections,t=>e.final.has(t.source));e.connections=this.processConnections(lt([...e.connections,...n,...r])),t=new Set(e.connections.flatMap(e=>[e.source,e.target]))}return e.elements=k(e.elements,this._ordered,this.explicits,t,this.implicits),e.explicits=D(e.elements,k(e.explicits,this.explicits)),e.final=D(e.elements,k(e.final,this.explicits,t)),this.memory.update(this.postcommit(e))}};function Kt(e,t=`final`){let n=ke(j(t===`final`?e.final:e.elements)),r=new Set(e.connections.flatMap(e=>[e.source,e.target])),i=new Set(n),a=new ot.default(()=>null),o=n.reduce((e,t,n,r)=>(e.set(t,r.slice(n+1).filter(e=>z(t,e)).map(e=>(i.delete(e),e)).reduce((e,n)=>(e.some(e=>z(e,n))||(e.push(n),a.set(n,t)),e),[])),e),new ot.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 Jt(e,t,n){let{shape:i,color:a,icon:o,...s}=e.style,l=!c(s);b(n,v(u(Xe)),v(t),r(t=>{t.shape=i??t.shape,t.color=a??t.color,m(o)&&(t.icon=o),m(e.notation)&&(t.notation=e.notation),l&&(t.style={...t.style,...s})}))}function Yt(e,t){for(let n of e)!Me(n)||n.targets.length===0||Jt(n,S(n.targets.map(H)),t);return t}var Xt=class e{id;viewRule;parent;elements;static kind=Ke;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,v(t=>He(t.relations,e)),r(t=>{this.excludeConnections(t.update(D(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=L(this.memory.explicits,e.explicits);for(let n of t)e.explicitFirstSeenIn.delete(n);let n=L(this.memory.elements,e.elements);for(let t of n)e.lastSeenIn.delete(t);return e}},Qt=class extends Zt{memory;expression;constructor(e,t){super(e,t),this.memory=e,this.expression=t}};const{findConnection:$t,findConnectionsBetween:en}=wt;var tn=class extends Gt{connectWithExisting(e,t=`both`){let n=this._connections.length,r=()=>this._connections.length>n;if(!De(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||z(this.memory.scope,e))&&this.addImplicit(e)}processConnections(e){return Ce.isRelationExpr(this.expression)||b(e,r(({source:e,target:t,boundary:n})=>{b(fe([...j(e.ancestors()).reverse(),e],[...j(t.ancestors()).reverse(),t]),ee(([e,t])=>e===t),le(1),r(([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=L(e.explicits,this.memory.explicits);for(let n of t)e.explicitFirstSeenIn.set(n,`@root`);return e}},nn=class extends tn{memory;expression;constructor(e,t){super(e,t),this.memory=e,this.expression=t}postcommit(e){let t=L(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{state;scope;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{state;scope;stack;static enter(t,n){let r=`@gr${t.groups.length+1}`;if(t instanceof e){let i=at.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=at.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 A(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}=h(e.$element,[`summary`,`description`,`metadata`,`style`,`tags`]),{color:i,icon:a,shape:o,...s}=e.style;return I({id:t,title:n,modelRef:t,shape:o,color:i,icon:a,style:s,description:ye(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&&A(r.get(n),`Parent group node ${n} not found`).children.push(t),r.set(t,{id:t,parent:n,kind:Ke,title:a.title??``,color:a.color??e.group.color??e.color,shape:`rectangle`,children:[],inEdges:[],outEdges:[],level:0,depth:0,tags:[],style:I({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(Je).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=A(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=I({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,A(r.get(e)))}),t.forEach(({id:e})=>{a.set(e,A(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,y((e,t)=>(d(t.title)&&!e.title.includes(t.title)&&e.title.push(t.title),d(t.description)&&!e.description.some(_(t.description))&&e.description.push(t.description),d(t.technology)&&!e.technology.includes(t.technology)&&e.technology.push(t.technology),d(t.kind)&&!e.kind.includes(t.kind)&&e.kind.push(t.kind),d(t.color)&&!e.color.includes(t.color)&&e.color.push(t.color),d(t.line)&&!e.line.includes(t.line)&&e.line.push(t.line),d(t.head)&&!e.head.includes(t.head)&&e.head.push(t.head),d(t.tail)&&!e.tail.includes(t.tail)&&e.tail.push(t.tail),d(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=C(n.title)??(n.title.length>1?`[...]`:void 0),i=ie(n.tags),a=I({title:r,description:C(n.description),technology:C(n.technology),kind:C(n.kind),head:C(n.head),tail:C(n.tail),color:C(n.color),line:C(n.line),navigateTo:C(n.navigateTo),...et(i)&&{tags:i}});if(t){let e=ln(t);a=x({...a,...e},d)}return l(a.title)&&d(a.technology)&&(a.title=`[${a.technology}]`,delete a.technology),a}const{findConnection:dn,findConnectionsBetween:U,findConnectionsWithin:fn}=xt;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(N.isWildcard(e))return()=>!0;if(N.isElementTagExpr(e)||N.isElementKindExpr(e))throw Error(`element kind and tag expressions are not supported in deployment view rules`);if(N.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(N.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}}w(e)}function hn(e){return ye(e.$instance)??ye(e.element.$element)}function gn(e){let t=e.id,n=e.onlyOneInstance();return I({id:t,deploymentRef:t,title:e.title,kind:e.kind,technology:e.technology??void 0,links:p(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:ye(e.$node)??void 0,tags:[...e.tags],style:h(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 I({id:e.id,kind:`instance`,title:e.title,description:hn(e)??void 0,technology:e.technology??void 0,tags:[...e.tags],links:p(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)}const yn=(e,t,n)=>xe(`model:${e}:${t}:${n}`);function bn(e){let t=new Set;for(let n=0;n<e.length;n++){if(t.has(n))continue;let r=e[n];for(let i=n+1;i<e.length;i++){if(t.has(i))continue;let n=e[i];if(r.source===n.target&&r.target===n.source&&r.label===n.label){r.dir=`both`;let e=r.head??n.head;e&&(r.head||=e,r.tail||=e),n.color&&(r.color||=n.color),n.line&&(r.line||=n.line),t.add(i);break}}}return t.size>0?e.filter((e,n)=>!t.has(n)):e}function xn(e,t){let n=[],r=[];for(let i of e){let e=[...i.relations.model,...i.relations.deployment];B(p(e,1),`Edge must have at least one relation`);let a=i.source.$model.$styles.defaults,o=i.source.id,s=i.target.id;if(t&&e.length>1){let[c,l]=b(e,he(e=>t(e,i)));if(c.length>0){for(let e of c){let{title:t,color:r=a.relationship.color,line:c=a.relationship.line,head:l=a.relationship.arrow,...u}=un([e.$relationship],e.$relationship);n.push({id:yn(o,s,e.id),parent:i.boundary?.id??null,source:o,target:s,label:t??null,relations:[e.id],color:r,line:c,head:l,...u})}if(l.length>0){let e=C(v(l,e=>e.source.id===o&&e.target.id===s)),{title:t,color:n=a.relationship.color,line:c=a.relationship.line,head:u=a.relationship.arrow,...d}=un(l.map(e=>e.$relationship),e?.$relationship);r.push({id:i.id,parent:i.boundary?.id??null,source:o,target:s,label:t??null,relations:l.map(e=>e.id),color:n,line:c,head:u,...d})}continue}}let{title:c,color:l=a.relationship.color,line:u=a.relationship.line,head:d=a.relationship.arrow,...f}=un(e.map(e=>e.$relationship)),m=I({id:i.id,parent:i.boundary?.id??null,source:o,target:s,label:c??null,relations:e.map(e=>e.id),color:l,line:u,head:d,...f});r.push(m)}return[...n,...bn(r)]}function Sn(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,c(t.tags)&&(t.tags=[...r.tags]),(!t.links||c(t.links))&&p(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 Cn(e,t){for(let n of e)!Me(n)||n.targets.length===0||Jt(n,S(n.targets.map(mn)),t);return t}function wn(e){let t=new ot.default(()=>[]);for(let n of e)for(let e of n.relations.model)t.get(e).push(n);let n=new ot.default(()=>new Set);for(let[e,a]of t)p(a,2)&&b(a,s(e=>[{group:`$source-${e.source.id}`,conn:e},{group:`$target-${e.target.id}`,conn:e}]),i(oe(`group`)),de(),v(p(2)),r(re(g(oe(`conn`)),ft(`desc`),ee((e,t,n)=>t===0||e.boundary===n[t-1].boundary),r(t=>{n.get(t).add(e)}))));return n}function Tn(e){e=lt(e);let t=wn(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;B(r.isDeploymentNode());let a=D(i,r.internalModelRelationships());for(let e of a)t.get(n).add(e);continue}if(e.isDeploymentNode()&&r.isDeploymentNode()){let i=k(D(n.relations.model,e.internalModelRelationships()),D(n.relations.model,r.internalModelRelationships()));for(let e of i)t.get(n).add(e)}}return b(t.entries(),we(([e,t])=>e.update({model:t,deployment:null})),j())}function En(e){return vt(e,Tn(e))}function Dn(e){return b(e,lt,y((t,n)=>{let{source:r,target:i,relations:a}=n;if(r.isInstance()&&i.isInstance())return t;let o=Tt.empty();if(r.isDeploymentNode()&&i.isDeploymentNode()){let[e]=dn(i,r,`directed`);e&&(o=a.intersect(e.relations))}for(let t of e)pt(t,n)&&(o=o.union(a.intersect(t.relations)));return o.nonEmpty&&t.push(new st(r,i,o)),t},[]))}function On(e){return vt(e,Dn(e))}var kn=class extends Gt{connectWithExisting(e,t=`both`){let n=this._connections.length,r=()=>this._connections.length>n;if(!De(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,En,On);return b(t,r(({source:e,target:t,boundary:n})=>{b(fe([...j(e.ancestors()).reverse(),e],[...j(t.ancestors()).reverse(),t]),ee(([e,t])=>e===t),le(1),r(([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}},An=class e extends Ut{static empty(){return new e({elements:new Set,explicits:new Set,final:new Set,connections:[]})}stageInclude(e){return new kn(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&&_(this.state,t.state)}diff(e){return{added:{elements:j(L(e.elements,this.elements)),explicits:j(L(e.explicits,this.explicits)),final:j(L(e.final,this.final)),connections:j(vt(e.connections,this.connections))},removed:{elements:j(L(this.elements,e.elements)),explicits:j(L(this.explicits,e.explicits)),final:j(L(this.final,e.final)),connections:vt(this.connections,e.connections)}}}toString(){return[`final:`,...[...this.final].map(e=>` `+e.id),`connections:`,...this.connections.map(e=>` `+e.expression)].join(`
2
+ `)}[bt](e,t,n){return this.toString()}};const jn={include:({expr:e,model:t,memory:n,stage:r})=>{let i=O(e.where.condition);return A(Un(`include`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i}))},exclude:({expr:e,model:t,memory:n,stage:r})=>{let i=O(e.where.condition);return A(Un(`exclude`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i}))}},Mn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(N.isWildcard(e.incoming)){for(let e of a){if(e.allOutgoing.isEmpty)continue;let t=K(U(e,[...Jn(e)],`directed`),i);r.addConnections(t)}return r}B(N.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(N.isElementTagExpr(e.incoming)||N.isElementKindExpr(e.incoming))throw Error(`element kind and tag expressions are not supported in exclude`);if(N.isModelRef(e.incoming))return G(Pn(t,e.incoming),{stage:r,memory:n},i);if(N.isWildcard(e.incoming))return r;let a=Nn(W(t,e.incoming)),o=b(n.connections,v(a),K(i));return r.excludeConnections(o),r}};function Nn(e){return S(e.map(e=>{let t=t=>t===e||z(e,t);return e=>!t(e.source)&&t(e.target)}))}function Pn(e,t){let n=pn(e,t);return new Set(n.flatMap(e=>[...e.allIncoming]))}const Fn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(N.isWildcard(e.outgoing)){for(let e of a)if(!e.allIncoming.isEmpty)for(let t of Jn(e)){let n=K(dn(t,e,`directed`),i);r.addConnections(n)}return r}B(N.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(N.isElementTagExpr(e.outgoing)||N.isElementKindExpr(e.outgoing))throw Error(`element kind and tag expressions are not supported in exclude`);if(N.isModelRef(e.outgoing))return G(Ln(t,e.outgoing),{stage:r,memory:n},i);if(N.isWildcard(e.outgoing))return r;let a=In(W(t,e.outgoing)),o=b(n.connections,v(a),K(i));return r.excludeConnections(o),r}};function In(e){return S(e.map(e=>{let t=t=>t===e||z(e,t);return e=>t(e.source)&&!t(e.target)}))}function Ln(e,t){let n=pn(e,t);return new Set(n.flatMap(e=>[...e.allOutgoing]))}const Rn={include:({expr:{source:e,target:t,isBidirectional:n=!1},model:r,stage:i,where:a})=>{if(N.isElementTagExpr(e)||N.isElementKindExpr(e)||N.isElementTagExpr(t)||N.isElementKindExpr(t))throw Error(`element kind and tag expressions are not supported in include`);B(!N.isModelRef(e),`Invalid source model ref in direct relation`),B(!N.isModelRef(t),`Invalid target model ref in direct relation`);let o=N.isWildcard(e),c=N.isWildcard(t),l=n?`both`:`directed`,u;switch(!0){case o&&c:u=b(fn(r.instances()),K(a),g(e=>(i.addImplicit(e.boundary),e)));break;case!o&&c:{let t=W(r,e),i=In(t),o=i;if(n){let e=Nn(t);o=t=>i(t)!==e(t)}u=b(t,s(e=>U(e,Jn(e),l)),v(o),K(a));break}case o&&!c:{let e=W(r,t),i=Nn(e),o=i;if(n){let t=In(e);o=e=>t(e)!==i(e)}u=b(e,s(e=>[...Jn(e)].flatMap(t=>dn(t,e,l))),v(o),K(a));break}default:{B(!o,`Inference failed - source should be a deployment ref`),B(!c,`Inference failed - target should be a deployment ref`);let n=W(r,e),i=W(r,t),d=In(n),f=Nn(i);u=b(n,s(e=>U(e,i,l)),v(e=>d(e)&&f(e)),K(a))}}return i.addConnections(u),N.isDeploymentRef(e)&&f(e.selector)&&i.addImplicit(r.element(e.ref.deployment)),N.isDeploymentRef(t)&&f(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 N.isWildcard(e.source)&&N.isWildcard(e.target):return r.excludeConnections(K(n.connections,i)),r;case N.isModelRef(e.source)&&N.isModelRef(e.target):return s=zn({source:e.source,target:e.target,expr:e,model:t}),G(s,{stage:r,memory:n},i);case N.isModelRef(e.source)&&N.isWildcard(e.target):return s=Ln(t,e.source),G(s,{stage:r,memory:n},i);case N.isModelRef(e.source):return s=Ln(t,e.source),G(s,{stage:r,memory:n},i,e=>a(e.target));case N.isModelRef(e.target):return s=Pn(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,v(c),K(i));return l.length===0||r.excludeConnections(l),r}}};function zn({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(..._t(e,a,o));return new Set(s.flatMap(e=>[...e.relations]))}const Bn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(N.isWildcard(e.inout)){for(let e of a){let t=Gn(U(e,[...Jn(e)],`both`),i);r.addConnections(t)}return r}B(N.isDeploymentRef(e.inout),`Only deployment refs are supported in include`);let o=W(t,e.inout);for(let e of a){let t=Gn(U(e,o,`both`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(N.isElementTagExpr(e.inout)||N.isElementKindExpr(e.inout))throw Error(`element kind and tag expressions are not supported in exclude`);if(N.isModelRef(e.inout)){let a=pn(t,e.inout);return a.length===0?r:G(k(new Set,...a.flatMap(e=>[e.allIncoming,e.allOutgoing])),{stage:r,memory:n},i)}if(N.isWildcard(e.inout))return r;let a=W(t,e.inout),o=Nn(a),s=In(a),c=b(n.connections,v(e=>o(e)!==s(e)),K(i));return r.excludeConnections(c),r}},Vn={include:({expr:e,model:t,memory:n,stage:r})=>{let i=O(e.where.condition);return Un(`include`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})},exclude:({expr:e,model:t,memory:n,stage:r})=>{let i=O(e.where.condition);return Un(`exclude`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})}},Hn={include:({model:e,stage:t,where:n})=>{let r=[],i;return i=n?b([...e.elements()],q(n)):j(we(e.roots(),e=>(e.onlyOneInstance()||r.push(...e.children()),e))),t.addExplicit(i),r.length>1?(t.addConnections(fn([...i,...r])),t.connectWithExisting(r)):t.addConnections(fn(i)),t.connectWithExisting(i),t},exclude:({stage:e,memory:t,where:n})=>{let r=b([...t.elements],q(n));return e.exclude(r),e}};function Un(e,{expr:t,where:n,...r}){switch(!0){case N.isElementTagExpr(t):case N.isElementKindExpr(t):throw Error(`element kind and tag expressions are not supported in deployment view rules`);case M.isCustom(t):case N.isCustom(t):case N.isModelRef(t):return;case N.isWhere(t):return jn[e]({...r,expr:t,where:n});case M.isWhere(t):return Vn[e]({...r,expr:t,where:n});case N.isDeploymentRef(t):return Yn[e]({...r,expr:t,where:n});case N.isWildcard(t):return Hn[e]({...r,expr:t,where:n});case M.isDirect(t):return Rn[e]({...r,expr:t,where:n});case M.isInOut(t):return Bn[e]({...r,expr:t,where:n});case M.isOutgoing(t):return Fn[e]({...r,expr:t,where:n});case M.isIncoming(t):return Mn[e]({...r,expr:t,where:n});default:w(t)}}function G(e,{stage:t,memory:n},r,i=()=>!0){if(e.size===0)return t;let a=b(n.connections,v(e=>i(e)),v(t=>He(t.relations.model,e)),g(t=>t.update({deployment:null,model:D(t.relations.model,e)})),K(r),v(e=>e.nonEmpty()));return a.length===0?t:t.excludeConnections(a)}function Wn(e,t){return K(e,t).nonEmpty()}function K(...t){if(t.length===1)return e=>K(e,t[0]);let[n,r]=t;return r===null?n:e(n)?n.map(e=>K(e,r)).filter(e=>e.nonEmpty()):n.update({model:new Set([...n.relations.model.values()].filter(e=>r(qn(n)(e)))),deployment:new Set([...n.relations.deployment.values()].filter(e=>r(qn(n)(e))))})}function q(...t){if(t.length===1){let e=t[0];return e==null?e=>e:t=>t.filter(t=>e(Kn(t,t)))}let[n,r]=t;return e(n)?r==null?n:n.filter(e=>r(Kn(e,e))):r?.(Kn(n,n))??!0}function Gn(e,t){return t?b(e,v(e=>Wn(e,t))):e}function Kn(e,t){if(Ct(e)){let n=St(t)&&Dt(t)?t:null;return{kind:e.kind,tags:[...e.tags,...n?.tags??[]],metadata:n?.metadata??e.metadata}}if(ht(e))return te(e.element,[`tags`,`kind`,`metadata`]);if(Dt(e))return{kind:e.element.kind,tags:[...e.tags,...e.element.tags],metadata:e.metadata};if(Et(e))return te(e,[`tags`,`kind`,`metadata`]);w(e)}function qn(e){return t=>({tags:t.tags,kind:t.kind,metadata:t.metadata,source:Kn(t.source,e.source),target:Kn(t.target,e.target)})}function Jn(e){let t=new Set;for(let n of e.descendingSiblings())t.add(n);return t}const Yn={include:e=>{let{expr:t,where:n}=e,r=e.model.element(t.ref.deployment);if(Dt(r))return q(r,n)&&(e.stage.addExplicit(r),e.stage.connectWithExisting(r)),e.stage;switch(!0){case t.selector===`expanded`:Zn(r,e);break;case t.selector===`children`:Xn(r,e);break;case t.selector===`descendants`:Qn(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],v(i),q(r));return t.exclude(a),t}};function Xn(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 Zn(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 Qn(e,{stage:t,where:n}){let i=e=>{let r=[];for(let t of e.children())t.isDeploymentNode()&&r.push(...i(t)),q(t,n)&&r.push(t);return t.connectWithExisting(r,`in`),t.addConnections(fn(r)),t.addImplicit(r),r},a=i(e);if(a.length===0)return;t.connectWithExisting(a,`out`);let o=$n(t);b(a,v(e=>o.has(e)),r(e=>t.addExplicit(e)))}function $n(e){return b(e.mergedConnections(),En,On,y((e,t)=>(e.add(t.source),e.add(t.target),e),new Set))}var er=class e{memory;includeAncestors;static for(t,n){return new e(t,n)}constructor(e,t){this.memory=e,this.includeAncestors=t}step1CleanConnections(e){if(e.connections.length<2)return e;let t=b(e.connections,En,On),n=vt(e.connections,t);if(n.length===0)return e;let r=e.stageExclude({});return r.excludeConnections(n,!0),r.commit()}step2ProcessImplicits(e){let t=k(this.memory.elements,e.elements),n=k(e.final,this.memory.explicits),i=new ot.default(()=>new Set);for(let t of e.connections)if(t.boundary)for(let e of t.relations.model)i.get(e).add(t.boundary);for(let[e,r]of i)if(!(r.size<2))for(let e of r)t.delete(e)&&n.add(e);let a=new Set(n),o=e=>{for(let t of a)if(e===t||z(e,t))return!0;return!1};return b(L(t,a),F(e=>e.isDeploymentNode()),j(),Be,r(e=>{let t=[...e.children()].filter(o).length;if(t>=2){n.add(e);return}t===1&&Oe(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=C([...n.root]);a&&!e.explicits.has(a)&&r.exclude(a);for(let t of e.final){let e=C(n.children(t));e&&!n.hasInOut(e)&&i(t)&&r.exclude(t)}return r.isDirty()?r.commit():e}step4AddAncestor(e){let t=new Set;for(let n of e.final)for(let e of n.ancestors())t.add(e);if(t.size>0){let n=k(e.final,t);return e.update({final:n})}return e}commit(){let e=this.step1CleanConnections(this.memory),t=this.step2ProcessImplicits(e),n=this.step3ProcessBoundaries(t);return this.includeAncestors===!0?this.step4AddAncestor(n):n}};const tr=Lt(mn);function nr(e,t){let n=[],r=[];for(let e of t)if(rt(e)&&`include`in e)for(let t of e.include)M.isCustom(t)&&(t.customRelation.multiple===!0?n.push(t):t.customRelation.multiple===!1&&r.push(t));let i=new Set,a=e.specification.relationships;for(let e of Object.keys(a)){let t=a[e];(t?.style??t)?.multiple&&i.add(e)}if(n.length===0&&r.length===0&&i.size===0)return;let o=n.map(e=>({pred:tr(e.customRelation.expr)})),s=r.map(e=>({pred:tr(e.customRelation.expr)}));return(e,t)=>{let n=e=>{if(e&&typeof e==`object`){if(`tags`in e&&`kind`in e&&`metadata`in e)return e;if(e.instance&&e.element)return{id:e.id,tags:e.instance.tags,kind:e.element.kind,metadata:e.instance.metadata}}return e??{}},r=n(t?.source??e.source),a=n(t?.target??e.target);if(s.length>0){for(let{pred:t}of s)if(t({source:r,target:a,kind:e.kind,tags:e.tags,metadata:e.metadata}))return!1}if(i.size>0){let t=e.kind;if(t&&i.has(t))return!0}if(o.length>0){for(let{pred:t}of o)if(t({source:r,target:a,kind:e.kind,tags:e.tags,metadata:e.metadata}))return!0}return!1}}function rr(e,t){let n=An.empty(),r=!1;for(let i of t){if(rt(i)){let t=`include`in i?`include`:`exclude`,r=i.include??i.exclude;for(let i of r){let r=t===`include`?n.stageInclude(i):n.stageExclude(i);r=Un(t,{expr:i,model:e,stage:r,memory:n,where:null})??r,n=r.commit()}}`includeAncestors`in i&&(r=i.includeAncestors)}return er.for(n,r).commit()}function ir(e,{docUri:t,rules:n,...r}){let i=rr(e.deployment,n),a=Sn(e,i),s=nr(e,n),c=xn(i.connections,s);It(a,c);let l=Vt({nodes:a,edges:c}),u=Cn(n,l.nodes),d=o(n,Ue),f=jt(u);return Ht({...r,[it]:`computed`,[Ne]:`deployment`,autoLayout:{direction:d?.direction??`TB`,...d?.nodeSep&&{nodeSep:d.nodeSep},...d?.rankSep&&{rankSep:d.rankSep}},edges:l.edges,nodes:g(u,e=>(e.icon===`none`&&delete e.icon,e)),...f.length>0&&{notation:{nodes:f}}})}function ar(e){return t=>Ge(t)?t.groupRules.flatMap(ar(e)):rt(t)&&`include`in t?t.include.filter(e):[]}function or(e,t){let n=e.flatMap(ar(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:o,iconColor:s,iconSize:c,iconPosition:u,padding:d,size:f,textSize:p,...m}=_e(t,l),h=I({border:n,opacity:i,multiple:o,iconColor:s,iconSize:c,iconPosition:u,padding:d,size:f,textSize:p}),g=!a(h),_=!a(m),v=H(e);r.forEach((e,t)=>{Xe(e)||!v(e)||(_&&(e={...e,...m,isCustomized:!0}),g&&(e={...e,isCustomized:!0,style:{...e.style,...h}}),r[t]=e)})}return r}function sr(e,t){return e.reduce((e,n)=>{if(tt(n)){let r=t.predicates[n.predicateId];return l(r)?e:e.concat(r)}if(Pe(n)){let r=t.styles[n.styleId];return l(r)?e:e.concat(r)}return e.push(n),e},[])}function cr(e,t){return e.reduce((e,n)=>{if(tt(n)){let r=t.dynamicPredicates[n.predicateId];return l(r)?e:e.concat(r)}if(Pe(n)){let r=t.styles[n.styleId];return l(r)?e:e.concat(r)}return e.push(n),e},[])}function lr(e,t){let n=new Set;for(let r of t)if(rt(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 ur=e=>{if(qe(e)){let t=[],n=[];for(let r of e.__parallel)if($e(r)){let[e,...i]=r.__series;t.push(e),n.push(...i)}else t.push(r);return[...t,...n]}return $e(e)?[...e.__series]:e};function dr(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 s(t,ur)){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 fr(e,t,n){let r=gt(e,t,`directed`).flatMap(e=>[...e.relations]).sort(Se);if(!et(r))return{};if(r.length===1){let e=r[0];return I({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,s(e=>e.tags),ie()),a=p(i,1)?i:void 0,o=g(r,e=>e.id),c=ue(r).$relationship.navigateTo;c===n&&(c=void 0),c||=b(r,s(e=>e.$relationship.navigateTo&&e.$relationship.navigateTo!==n?e.$relationship.navigateTo:[]),ie(),C());let l=b(r,y((e,{title:t,technology:n,$relationship:r})=>(d(t)&&e.title.add(t),d(r.color)&&e.color.add(r.color),d(r.line)&&e.line.add(r.line),d(r.kind)&&e.kind.add(r.kind),d(n)&&e.technology.add(n),d(r.description)&&!e.description.some(_(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 I({tags:a??void 0,relations:o,navigateTo:c,kind:C([...l.kind]),title:C([...l.title]),color:C([...l.color]),line:C([...l.line]),technology:C([...l.technology]),description:C(l.description)})}var pr=class{model;view;steps=[];constructor(e,t){this.model=e,this.view=t}compute(){let{docUri:e,rules:t,steps:n,...r}=this.view,i=cr(t,this.model.globals),a=lr(this.model,i),s=dr(this.model,n),c=b(k(D(a,s),s,a),j(),ke),l=c.reduce((e,t,n,r)=>{for(let i=n+1;i<r.length;i++){let n=r[i];if(z(t,n)){e.push(t);break}}return e},[]),u=(e,t,n)=>{if($e(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:f,notation:p,...m}=e,h=this.model.element(i),g=c.indexOf(h);B(g>=0,`Source ${i} not found`);let _=this.model.element(a),v=c.indexOf(_);B(v>=0,`Target ${a} not found`),(l.includes(h)||l.includes(_))&&console.error(`Step ${h.id} -> ${_.id} because it involves a compound`);let{title:ee,relations:te,navigateTo:ne,...y}=fr(h,_,this.view.id),b=d(f)&&f!==this.view.id?f:ne,x=e.kind?this.model.specification.relationships[e.kind]:void 0;return this.steps.push(I({...y,...!e.technology&&!y.technology&&x?.technology&&{technology:x.technology},...!e.color&&!y.color&&x?.color&&{color:x.color},...!e.line&&!y.line&&x?.line&&{line:x.line},...!e.head&&x?.head&&{head:x.head},...!e.tail&&x?.tail&&{tail:x.tail},...m,id:r,source:h,target:_,navigateTo:b,title:o??ee,relations:te??[],isBackward:g>v})),t+1},f=1;for(let e of n){if(qe(e)){let t=1;for(let n of e.__parallel)t=u(n,t,f);f++;continue}f=u(e,f)}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=A(p.get(t.id),`Source node ${t.id} not found`),l=A(p.get(n.id),`Target node ${n.id} not found`),u={id:e,parent:je(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 Ve(u.source)){if(e===u.parent)break;p.get(e)?.outEdges.push(u.id)}for(let e of Ve(u.target)){if(e===u.parent)break;p.get(e)?.inEdges.push(u.id)}return u}),_=or(i,Yt(i,c.map(e=>A(p.get(e.id))))),v=o(i,Ue),ee=jt(_);return Ht({...r,[Ne]:`dynamic`,[it]:`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,...ee.length>0&&{notation:{nodes:ee}}})}};function mr(e,t){return new pr(e,t).compute()}function hr(e,t,n){let r=e.flatMap(ar(R.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,multiple:s,...c}}of r){let r=a?{description:Qe(a)}:{},s=o?{notes:Qe(o)}:{},u=_e(c,l),d=Rt(e);i.forEach((e,a)=>{let o,c;for(let n of t)if(n.id===e.source&&(o=n),n.id===e.target&&(c=n),o&&c)break;!o||!c||d({source:o,target:c,...te(e,[`kind`,`tags`])})&&(i[a]={...e,...u,...r,...s,label:n??e.label,isCustomized:!0})})}return i}function gr(e){return b([...e],lt,y((e,t,n,r)=>{let i=At(r,t),a=k(...i.map(oe(`relations`))),o=D(t.relations,a);if(i.length>0&&(o=k(o,t.directRelations)),Ot(r,t.reversed())&&(o=k(o,t.directRelations)),o.size<t.relations.size){let e=r.some(ct(t.source)),n=r.some(ct(t.target));e&&(o=k(o,T(F(t.relations,ut(t.source))))),n&&(o=k(o,T(F(t.relations,kt(t.target)))))}return o.size>0&&e.push(t.update(o)),e},[]))}var _r=class e{memory;static for(t){return new e(t)}constructor(e){this.memory=e}step1CleanConnections(e){if(e.connections.length<2)return e;let t=gr(e.connections);if(t.length===0)return e;let n=e.stageExclude({});return n.excludeConnections(t,!0),n.commit()}step2ProcessImplicits(e){let t=k(this.memory.elements,e.elements),n=k(e.final,this.memory.explicits),i=new Set(n),a=e=>{for(let t of i)if(e===t||z(e,t))return!0;return!1};return b(L(t,i),j(),Be,r(e=>{let t=[...e.children()].filter(a).length;if(t>=2){n.add(e);return}t===1&&Oe(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=C([...n.root]);a&&!e.explicits.has(a)&&r.exclude(a);for(let t of e.final){let e=C(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:vr,findConnectionsBetween:J,findConnectionsWithin:Y}=wt;function X(e,t){switch(!0){case E.isElementKindExpr(t):return[...F(e.elements(),e=>t.isEqual===(e.kind===t.elementKind))];case E.isElementTagExpr(t):return[...F(e.elements(),e=>t.isEqual===e.tags.includes(t.elementTag))];case t.selector===`expanded`:{let n=e.element(P.flatten(t.ref));return[n,...n.children()]}case t.selector===`children`:case t.selector===`descendants`:{let n=e.element(P.flatten(t.ref)),r=t.selector===`children`?j(n.children()):j(n.descendants());return r&&r.length>0?r:[n]}case E.isModelRef(t):return[e.element(P.flatten(t.ref))];default:w(t)}}function yr(e,t){if(t.isEmpty()||e.length===0)return e;let n=S(e.map(e=>Fe(e))),r=j(F(t.elements,t=>!e.includes(t)&&n(t)));return[...e,...r]}function br(e,{memory:t,model:n}){let r=X(n,e);return E.isModelRef(e)?e.selector===`descendants`?r:yr(r,t):r}const xr={include:({expr:e,model:t,stage:n,where:r})=>{let i=t.element(P.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}},Sr={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}},Cr={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}},wr=()=>!0,Tr=e=>e,Er=(e,t,n)=>xe(`model:${e}:${t}:${n}`);function Dr(e,t){return e.flatMap(e=>{let n=[...e.relations];B(p(n,1),`Edge must have at least one relation`);let r=e.source.$model.$styles.defaults,i=e.source.id,a=e.target.id,o=v(n,e=>e.source.id===i&&e.target.id===a);if(t&&n.length>1){let[o,s]=b(n,he(n=>t(n,e)));if(o.length>0){let t=o.map(t=>{let{title:n,color:o=r.relationship.color,line:s=r.relationship.line,head:c=r.relationship.arrow,...l}=un([t.$relationship],t.$relationship);return{id:Er(i,a,t.id),parent:e.boundary?.id??null,source:i,target:a,label:n??null,relations:[t.id],color:o,line:s,head:c,...l}});if(s.length>0){let{title:n,color:o=r.relationship.color,line:c=r.relationship.line,head:l=r.relationship.arrow,...u}=un(s.map(e=>e.$relationship),C(v(s,e=>e.source.id===i&&e.target.id===a))?.$relationship);t.push({id:e.id,parent:e.boundary?.id??null,source:i,target:a,label:n??null,relations:s.map(e=>e.id),color:o,line:c,head:l,...u})}return t}}let{title:s,color:c=r.relationship.color,line:l=r.relationship.line,head:u=r.relationship.arrow,...d}=un(n.map(e=>e.$relationship),C(o)?.$relationship);return[I({id:e.id,parent:e.boundary?.id??null,source:i,target:a,label:s??null,relations:n.map(e=>e.id),color:c,line:l,head:u,...d})]})}function Or(e,t){return cn(e.$styles,[...t.final].map(sn),t.groups)}const Z=E.isWildcard,kr=(e,t)=>e.isAncestorOf(t)||e.isDescendantOf(t),Ar={include:({expr:{source:e,target:t,isBidirectional:n=!1},memory:r,model:i,stage:a,where:o,filterWhere:c})=>{let l=Z(e),u=Z(t),d=[];switch(!0){case l&&u&&r.isEmpty()&&o!==wr:{let e=b(i.relationships(),F(o),j(),g(e=>new yt(e.source,e.target,new Set([e]))));return a.addConnections(e),a}case l&&u&&!r.isEmpty()&&o!==wr:d.push(...Y(r.elements));break;case l&&u:d.push(...Y(i.roots()));break;case!l&&u&&o!==wr:{let t=b(X(i,e),s(e=>b(e,se(pe(n===!0),{onTrue:e=>k(e.allIncoming,e.allOutgoing),onFalse:e=>e.allOutgoing}),F(o),be(),j(),he(t=>t.source===e),([t,n])=>ce(b(t,v(t=>!kr(e,t.target)),g(t=>new yt(e,t.target,new Set([t])))),b(n,v(t=>!kr(e,t.source)),g(t=>new yt(t.source,e,new Set([t]))))))));return a.addConnections(t),a}case!l&&u:{let[t,a]=jr(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!==wr:{let e=b(X(i,t),s(e=>b(e,se(pe(n===!0),{onTrue:e=>k(e.allIncoming,e.allOutgoing),onFalse:e=>e.allIncoming}),F(o),j(),he(t=>t.target===e),([t,n])=>ce(b(n,v(t=>!kr(e,t.target)),g(t=>new yt(e,t.target,new Set([t])))),b(t,v(t=>!kr(e,t.source)),g(t=>new yt(t.source,e,new Set([t]))))))));return a.addConnections(e),a}case l&&!u:{let[e,a]=jr(t,{memory:r,model:i}),o=n?`both`:`directed`;for(let t of a)d.push(...J(t,e,o));break}default:{B(!Z(e),`Inference failed - source must be not a wildcard`),B(!Z(t),`Inference failed - target must be not a wildcard`);let a=br(e,{memory:r,model:i}),o=br(t,{memory:r,model:i}),s=n?`both`:`directed`;for(let e of a)d.push(...J(e,o,s))}}return a.addConnections(c(d)),a},exclude:({expr:{source:e,target:t,isBidirectional:n},model:r,memory:i,stage:a,where:o})=>{let c=Z(e),l=Z(t),u;switch(!0){case c&&l:u=b(i.connections,s(re(oe(`relations`),F(o),j())),T());break;case!c&&l:u=b(X(r,e),s(e=>b(e,se(pe(n===!0),{onTrue:e=>k(e.allIncoming,e.allOutgoing),onFalse:e=>e.allOutgoing}),F(o),j())),T());break;case c&&!l:u=b(X(r,t),s(e=>b(e,se(pe(n===!0),{onTrue:e=>k(e.allIncoming,e.allOutgoing),onFalse:e=>e.allIncoming}),F(o),j())),T());break;default:{B(!Z(e),`Inference failed - source must be not a wildcard`),B(!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)Le(e,t)||(s=k(s,D(e.allOutgoing,t.allIncoming),n?D(t.allOutgoing,e.allIncoming):new Set));u=T(F(s,o))}}return a.excludeRelations(u),a}};function jr(e,{memory:t,model:n}){let r=X(n,e);if(!p(r,1))return[[],[]];if(E.isModelRef(e)){let i=j(n.element(P.flatten(e.ref)).ascendingSiblings());return[yr(r,t),yr(i,t)]}return[r,b(r,g(e=>e.ascendingSiblings()),Te(),be(),j(),e=>yr(e,t))]}const Mr={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(...vr(e,t,`directed`))}else{let e=br(o,{memory:r,model:n}),t=[...r.elements];t.length===0&&t.push(...ie(e.flatMap(e=>[...e.ascendingSiblings()])));let i=Nr(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 Nr(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=P.flatten(t.ref);return S([...e.children(n)].map(e=>V.isIncoming(e.id)))}case E.isModelRef(t)&&t.selector===`descendants`:{let n=P.flatten(t.ref);return S([V.isInside(n),...[...e.children(n)].map(e=>V.isIncoming(e.id))])}case E.isModelRef(t)&&t.selector===`expanded`:{let e=P.flatten(t.ref);return S([V.isIncoming(e),V.isInside(e)])}case E.isModelRef(t):{let e=P.flatten(t.ref);return V.isIncoming(e)}default:w(t)}}const Pr={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=br(e,{memory:r,model:n}),i=[...r.elements];i.length===0&&(i=ie(t.flatMap(e=>j(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(T(a.filter(i))),r}},Fr={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=br(o,{memory:r,model:n}),t=[...r.elements];t.length===0&&t.push(...ie(e.flatMap(e=>[...e.ascendingSiblings()])));let i=Ir(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(T(a.filter(i))),r}};function Ir(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=P.flatten(t.ref);return S([...e.children(n)].map(e=>V.isOutgoing(e.id)))}case E.isModelRef(t)&&t.selector===`descendants`:{let n=P.flatten(t.ref);return S([V.isInside(n),...[...e.children(n)].map(e=>V.isOutgoing(e.id))])}case E.isModelRef(t)&&t.selector===`expanded`:{let e=P.flatten(t.ref);return S([V.isOutgoing(e),V.isInside(e)])}case E.isModelRef(t):{let e=P.flatten(t.ref);return V.isOutgoing(e)}default:w(t)}}const Lr={include:({scope:e,model:t,stage:n,memory:r,where:i})=>{if(!e){let e=i===wr?[...t.roots()]:j(F(t.elements(),i));if(e.length===0)return;let[r,a]=he(e,e=>!e.imported);return n.addExplicit(r),n.addImplicit(a),n.addConnections(Y(e)),n.connectWithExisting(e),n}let a=j(F(e.children(),i)),o=a.length>0;if(!o){let t=J(e,e.siblings()),r=e.parent;t.length===0&&r&&n.addExplicit(r),a.push(e)}n.addExplicit(e);let s=T([...r.elements,...e.descendingSiblings()]);for(let e of s)n.addConnections(J(e,a,`directed`));o&&(n.addConnections(Y(a)),n.addExplicit(a));for(let e of a)n.addConnections(J(e,s,`directed`));return n},exclude:({scope:e,memory:t,stage:n,where:r})=>r===wr?e?(n.exclude([e,...e.descendants()]),n):rn.empty(t.scope).stageExclude(n.expression):(n.exclude(v([...t.elements],r)),n)};function Rr(e,t,n){switch(!0){case E.isCustom(e):return t===`include`?Rr(e.custom.expr,t,n):n.stage;case E.isWhere(e):{let r=O(e.where.condition),i=e=>v(e,r);return Rr(e.where.expr,t,{...n,where:r,filterWhere:i})}case E.isModelRef(e)&&e.selector===`expanded`:return xr[t]({...n,expr:e})??n.stage;case E.isWildcard(e):return Lr[t]({...n,expr:e})??n.stage;case E.isElementKindExpr(e):case E.isElementTagExpr(e):return Sr[t]({...n,expr:e})??n.stage;case E.isModelRef(e):return Cr[t]({...n,expr:e})??n.stage;default:w(e)}}function zr(e,t,n){switch(!0){case R.isCustom(e):return t===`include`?zr(e.customRelation.expr,t,n):n.stage;case R.isWhere(e):{let r=O(e.where.condition),i=e=>new Set(v([...e],r)),a=e=>b(e,g(e=>new yt(e.source,e.target,i(e.relations))),v(e=>e.nonEmpty()));return zr(e.where.expr,t,{...n,where:r,filterWhere:a})}case R.isInOut(e):return Pr[t]({...n,expr:e})??n.stage;case R.isDirect(e):return Ar[t]({...n,expr:e})??n.stage;case R.isOutgoing(e):return Fr[t]({...n,expr:e})??n.stage;case R.isIncoming(e):return Mr[t]({...n,expr:e})??n.stage;default:w(e)}}function Br(e,t,n){let r={model:e,scope:t.scope,where:wr,filterWhere:Tr};for(let i of n){if(Ge(i)){t=Br(e,an.enter(t,i),i.groupRules),B(t instanceof an,`processPredicates must return ActiveGroupMemory`),t=t.leave();continue}if(rt(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 Ce.isFqnExpr(i):n=Rr(i,e,{...r,stage:n,memory:t})??n;break;case Ce.isRelationExpr(i):n=zr(i,e,{...r,stage:n,memory:t})??n;break;default:w(i)}t=n.commit()}}}return t}function Vr(e,t,n){return t=Br(e,t,n),_r.for(t).commit()}function Hr(e,t){let n=t.flatMap(ar(R.isCustom)).filter(e=>e.customRelation.multiple===!0),r=t.flatMap(ar(R.isCustom)).filter(e=>e.customRelation.multiple===!1),i=new Set,a=e.specification.relationships;for(let e of Object.keys(a)){let t=a[e];(t?.style??t)?.multiple&&i.add(e)}if(n.length===0&&r.length===0&&i.size===0)return;let o=n.map(e=>({pred:Rt(e.customRelation.expr)})),s=r.map(e=>({pred:Rt(e.customRelation.expr)}));return(e,t)=>{let n=t?.source??e.source,r=t?.target??e.target;if(s.length>0){for(let{pred:t}of s)if(t({source:n,target:r,kind:e.kind,tags:e.tags,metadata:e.metadata}))return!1}if(i.size>0){let t=e.kind;if(t&&i.has(t))return!0}if(o.length>0){for(let{pred:t}of o)if(t({source:n,target:r,kind:e.kind,tags:e.tags,metadata:e.metadata}))return!0}return!1}}function Ur(e,{docUri:t,rules:n,...r}){let i=sr(n,e.globals),a=r.viewOf?e.asComputed.element(r.viewOf):null,s=Vr(e,rn.empty(a),i);s.isEmpty()&&a&&(s=s.update({final:new Set([a])})),s=Gr(s);let c=Or(e,s),l=Hr(e,i),u=Dr(s.connections,l);It(c,u);let d=Vt({nodes:c,edges:u}),f=or(i,Yt(i,d.nodes)),p=o(i,Ue),m=jt(f),h=Wr(i,f);return Ht({...r,_stage:`computed`,autoLayout:{direction:p?.direction??`TB`,...p?.nodeSep&&{nodeSep:p.nodeSep},...p?.rankSep&&{rankSep:p.rankSep}},edges:hr(i,f,d.edges),nodes:g(f,e=>(e.icon===`none`&&delete e.icon,e)),...m.length>0&&{notation:{nodes:m}},...h.length>0&&{ranks:h}})}function Wr(e,t){let n=[];for(let r of e){if(!Ze(r)||r.targets.length===0)continue;let e=b(t,v(S(r.targets.map(H))),g(e=>e.id));p(e,1)&&n.push({type:r.rank,nodes:e})}return n}function Gr(e){if(e.groups.length===0)return e;let t=new ot.default(()=>new Set),n=new Map,i=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(ke([...e.explicitFirstSeenIn.keys()]),r(r=>{if(!i(r)){let i=A(e.explicitFirstSeenIn.get(r));n.set(r,i),t.get(i).add(r)}})),b(ke([...e.lastSeenIn.keys()]),v(e=>!n.has(e)),r(r=>{if(i(r)||a(r))return;let o=A(e.lastSeenIn.get(r));n.set(r,o),t.get(o).add(r)})),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 Kr(e,t){switch(!0){case Re(e):return Ur(t,e);case Ye(e):return ir(t,e);case ze(e):return mr(t,e);default:w(e)}}function qr(e,t){try{return{isSuccess:!0,view:Kr(e,t)}}catch(e){return{isSuccess:!1,error:e instanceof Error?e:Error(`Unknown error: ${e}`),view:void 0}}}function Jr(e){let n=dt.create(e),{views:r,_stage:i,...a}=e,o=t(r,e=>Kr(e,n));return{[it]:`computed`,...a,views:o}}function Yr(e){return dt.create(Jr(e))}const Q=e=>e;function $(e){if(!ae(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{Kr as a,It as c,qr as i,Yr as n,Ur as o,Jr as r,Vt as s,$ as t};
@@ -1,6 +1,6 @@
1
- import { $r as RelationKind, Ai as RelationId, C as LayoutedView, Ci as GroupElementKind, Di as NodeId, Fr as AnyParsed, Gn as WhereOperator, Gr as LooseElementId, Hr as ElementKind, Ht as DynamicViewDisplayVariant, Ir as Aux, Jr as LooseViewId, Li as ViewId$1, Lr as DeploymentFqn, Mr as Any, Ni as StepEdgeId, Nr as AnyComputed, Ot as Element, Pr as AnyLayouted, Qr as RelationId$1, Rr as DeploymentId, Rt as ModelGlobals, S as ComputedView, St as DeploymentNode, Ti as IconUrl, Ur as Fqn, Vr as ElementId, Wr as LooseDeploymentId, Xi as _type, Xr as MetadataKey, Yi as _stage, Yr as Metadata, Zr as ProjectId$1, _ as ComputedLikeC4ModelData, _r as RelationshipLineType, aa as NonEmptyArray, ai as Unknown, b as ParsedLikeC4ModelData, bt as DeploymentElement, ci as UnknownParsed, ct as LikeC4Project, d as AuxFromDump, er as FqnRef, et as ViewManualLayoutSnapshot, f as LikeC4ModelDump, gt as Specification, ii as Tags, jt as Relationship, k as ViewWithType, ki as ProjectId, kt as ElementStyle, l as RichTextOrEmpty, li as ViewId, mi as toComputed, mr as RelationshipArrowType, ni as StrictViewId, nr as Color, oi as UnknownComputed, ot as ComputedNodeStyle, qr as LooseTag, ra as Link, ri as Tag, si as UnknownLayouted, sr as ElementShape, ta as IteratorLike, ti as Stage, v as LayoutedLikeC4ModelData, wt as DeploymentRelationship, yi as EdgeId, yt as DeployedInstance, zr as DeploymentKind } from "./index.mjs";
1
+ import { $r as RelationId$1, Ai as ProjectId, At as ElementStyle, Br as DeploymentKind, C as LayoutedView, Ct as DeploymentNode, Ei as IconUrl, Fr as AnyLayouted, Gr as LooseDeploymentId, Hr as ElementId, Ir as AnyParsed, Jr as LooseTag, Kn as WhereOperator, Kr as LooseElementId, Lr as Aux, Mt as Relationship, Nr as Any, Oi as NodeId, Pi as StepEdgeId, Pr as AnyComputed, Qr as ProjectId$1, Ri as ViewId$1, Rr as DeploymentFqn, S as ComputedView, Tt as DeploymentRelationship, Ur as ElementKind, Ut as DynamicViewDisplayVariant, Wr as Fqn, Xi as _stage, Xr as Metadata, Yr as LooseViewId, Zi as _type, Zr as MetadataKey, _ as ComputedLikeC4ModelData, _t as Specification, ai as Tags, b as ParsedLikeC4ModelData, bi as EdgeId, bt as DeployedInstance, ci as UnknownLayouted, cr as ElementShape, d as AuxFromDump, ei as RelationKind, f as LikeC4ModelDump, hi as toComputed, hr as RelationshipArrowType, ia as Link, ii as Tag, ji as RelationId, k as ViewWithType, kt as Element, l as RichTextOrEmpty, li as UnknownParsed, lt as LikeC4Project, na as IteratorLike, ni as Stage, oa as NonEmptyArray, oi as Unknown, ri as StrictViewId, rr as Color, si as UnknownComputed, st as ComputedNodeStyle, tr as FqnRef, tt as ViewManualLayoutSnapshot, ui as ViewId, v as LayoutedLikeC4ModelData, vr as RelationshipLineType, wi as GroupElementKind, xt as DeploymentElement, zr as DeploymentId, zt as ModelGlobals } from "./index.mjs";
2
2
  import { i as BBox } from "./index2.mjs";
3
- import { i as LikeC4Styles } from "./index3.mjs";
3
+ import { o as LikeC4Styles } from "./index3.mjs";
4
4
  import { o as DefaultMap } from "./libs/mnemonist.mjs";
5
5
  import "./mnemonist.mjs";
6
6
  import { IsAny, SetRequired, Tagged } from "type-fest";
@@ -1,4 +1,4 @@
1
- import { An as Expression, At as ModelRelation, Ei as MarkdownOrString, Hn as Participant, Ir as Aux, Mr as Any, On as ModelFqnExpr, Ot as Element, Sr as ThemeColor, W as ParsedDeploymentView, _i as DeploymentFqn, _r as RelationshipLineType, _t as TagSpecification, aa as NonEmptyArray, b as ParsedLikeC4ModelData, br as SpacingSize, bt as DeploymentElement, dt as LikeC4ProjectStylesConfig, ei as SpecAux, ht as RelationshipSpecification, in as ParsedElementView, kn as ModelRelationExpr, ln as AnyViewRuleStyle, lr as IconPosition, mr as RelationshipArrowType, mt as ElementSpecification$1, na as KeysOf, pi as setProject, sr as ElementShape, tr as BorderStyle, un as AutoLayoutDirection, vr as ShapeSize, w as ParsedView, wt as DeploymentRelationship, xi as Fqn, xr as TextSize } from "./index.mjs";
1
+ import { An as ModelRelationExpr, Cr as ThemeColor, Di as MarkdownOrString, Lr as Aux, Nr as Any, Si as Fqn, Sr as TextSize, Tt as DeploymentRelationship, Un as Participant, W as ParsedDeploymentView, an as ParsedElementView, b as ParsedLikeC4ModelData, cr as ElementShape, dn as AutoLayoutDirection, ft as LikeC4ProjectStylesConfig, gt as RelationshipSpecification, hr as RelationshipArrowType, ht as ElementSpecification$1, jn as Expression, jt as ModelRelation, kn as ModelFqnExpr, kt as Element, mi as setProject, nr as BorderStyle, oa as NonEmptyArray, ra as KeysOf, ti as SpecAux, un as AnyViewRuleStyle, ur as IconPosition, vi as DeploymentFqn, vr as RelationshipLineType, vt as TagSpecification, w as ParsedView, xr as SpacingSize, xt as DeploymentElement, yr as ShapeSize } from "./index.mjs";
2
2
  import { n as LikeC4Model } from "./LikeC4Model.mjs";
3
3
  import { IfNever, IsLiteral, IsNever, LastArrayElement, PartialDeep, Simplify, Split, Tagged, TupleToUnion, Writable } from "type-fest";
4
4
 
@@ -339,7 +339,9 @@ type Op<T> = (b: T) => T;
339
339
  declare function $rules<B extends LikeC4ViewBuilder<AnyTypes, any, any>>(...rules: Op<B>[]): (b: B) => B;
340
340
  //#endregion
341
341
  //#region src/builder/Builder.view-deployment.d.ts
342
- interface DeploymentViewBuilder<T extends AnyTypes> extends LikeC4ViewBuilder<T, T['DeploymentFqn'], Types.ToExpression<T>> {}
342
+ interface DeploymentViewBuilder<T extends AnyTypes> extends LikeC4ViewBuilder<T, T['DeploymentFqn'], Types.ToExpression<T>> {
343
+ includeAncestors(value: boolean): this;
344
+ }
343
345
  type DeploymentRulesBuilderOp<Types extends AnyTypes> = (b: DeploymentViewBuilder<Types>) => DeploymentViewBuilder<Types>;
344
346
  interface AddDeploymentViewRules<Id extends string> {
345
347
  with<S extends AnyTypes>(...rules: DeploymentRulesBuilderOp<S>[]): (builder: ViewsBuilder<S>) => ViewsBuilder<Types.AddView<S, Id>>;
@@ -358,6 +360,7 @@ interface AddDeploymentViewHelper {
358
360
  <const Id extends string, T extends AnyTypes>(id: Id, propsOrTitle: T['NewViewProps'] | string, bulder: (b: DeploymentViewBuilder<T>) => DeploymentViewBuilder<T>): (builder: ViewsBuilder<T>) => ViewsBuilder<Types.AddView<T, Id>>;
359
361
  }
360
362
  declare function $deploymentExpr<T extends AnyTypes>(expr: ViewPredicate.DeploymentExpression<T> | Expression): Types.ToExpression<T>;
363
+ declare function $includeAncestors<B extends DeploymentViewBuilder<AnyTypes>>(value: boolean): (b: B) => B;
361
364
  //#endregion
362
365
  //#region src/builder/Builder.view-element.d.ts
363
366
  interface ElementViewBuilder<T extends AnyTypes> extends LikeC4ViewBuilder<T, T['Fqn'], Expression<Types.ToAux<T>>> {}
@@ -428,6 +431,7 @@ type ViewsHelpers = {
428
431
  $style: typeof $style;
429
432
  $rules: typeof $rules;
430
433
  $autoLayout: typeof $autoLayout;
434
+ $includeAncestors: typeof $includeAncestors;
431
435
  };
432
436
  type ViewsBuilderFunction<A extends AnyTypes, B extends AnyTypes> = (helpers: Simplify<ViewsHelpers['views'] & Omit<ViewsHelpers, 'viewOf'> & {
433
437
  viewOf: TypedAddViewOfHelper<A>;
@@ -782,4 +786,4 @@ declare namespace Types {
782
786
  type DeploymentRules<B> = DeploymentRulesBuilderOp<From<B>>;
783
787
  }
784
788
  //#endregion
785
- export { DeloymentModelHelpers as $, AddDeploymentViewHelper as A, ViewPredicate as B, AddViewHelper as C, ElementViewRulesBuilder as D, ElementViewBuilder as E, $exclude as F, NestedRelationshipHelper as G, ModelBuilder as H, $include as I, AddElement as J, RelationshipHelper as K, $rules as L, DeploymentRulesBuilderOp as M, DeploymentViewBuilder as N, TypedAddViewOfHelper as O, $autoLayout as P, DeloymentModelBuildFunction as Q, $style as R, $expr as S, AddViewRules as T, ModelBuilderFunction as U, AddElementHelpers as V, ModelHelpers as W, AddDeploymentNodeHelpers as X, AddDeployedInstance as Y, AddDeploymentRelation as Z, ViewsBuilder as _, Invalid as a, mkViewBuilder as b, NewElementProps as c, Types as d, DeploymentModelBuilder as et, TypesNested as f, BuilderMethods as g, Builder as h, BuilderSpecification as i, AddDeploymentViewRules as j, $deploymentExpr as k, NewRelationProps as l, Warn as m, AnyTypesNested as n, AddDeploymentNode as nt, Metadata as o, ValidId as p, model as q, BuilderProjectSpecification as r, NewDeploymentNodeProps as s, AnyTypes as t, deployment as tt, NewViewProps as u, ViewsBuilderFunction as v, AddViewOfHelper as w, views as x, ViewsHelpers as y, LikeC4ViewBuilder as z };
789
+ export { DeloymentModelBuildFunction as $, $includeAncestors as A, LikeC4ViewBuilder as B, AddViewHelper as C, ElementViewRulesBuilder as D, ElementViewBuilder as E, $autoLayout as F, ModelHelpers as G, AddElementHelpers as H, $exclude as I, model as J, NestedRelationshipHelper as K, $include as L, AddDeploymentViewRules as M, DeploymentRulesBuilderOp as N, TypedAddViewOfHelper as O, DeploymentViewBuilder as P, AddDeploymentRelation as Q, $rules as R, $expr as S, AddViewRules as T, ModelBuilder as U, ViewPredicate as V, ModelBuilderFunction as W, AddDeployedInstance as X, AddElement as Y, AddDeploymentNodeHelpers as Z, ViewsBuilder as _, Invalid as a, mkViewBuilder as b, NewElementProps as c, Types as d, DeloymentModelHelpers as et, TypesNested as f, BuilderMethods as g, Builder as h, BuilderSpecification as i, AddDeploymentViewHelper as j, $deploymentExpr as k, NewRelationProps as l, Warn as m, AnyTypesNested as n, deployment as nt, Metadata as o, ValidId as p, RelationshipHelper as q, BuilderProjectSpecification as r, AddDeploymentNode as rt, NewDeploymentNodeProps as s, AnyTypes as t, DeploymentModelBuilder as tt, NewViewProps as u, ViewsBuilderFunction as v, AddViewOfHelper as w, views as x, ViewsHelpers as y, $style as z };
@@ -1,4 +1,4 @@
1
- import { G as DiagramEdge, K as DiagramNode, Xi as _type, Yi as _stage, at as ComputedNode, fn as BaseViewProperties, hn as ViewAutoLayout, ki as ProjectId, rt as ComputedEdge } from "./index.mjs";
1
+ import { Ai as ProjectId, K as DiagramEdge, Xi as _stage, Zi as _type, gn as ViewAutoLayout, it as ComputedEdge, ot as ComputedNode, pn as BaseViewProperties, q as DiagramNode } from "./index.mjs";
2
2
  import { i as BBox } from "./index2.mjs";
3
3
 
4
4
  //#region src/compute-view/projects-view/_types.d.ts
@@ -1 +1 @@
1
- import{O as e,T as t,X as n,et as r,l as i,m as a,nt as o,p as s}from"./libs/remeda.mjs";import{I as c,Sn as l,hn as u}from"./types.mjs";function d(d){let f=[],p=[];for(let[t,r]of n(d))e(r.color)?f.push({tag:t,spec:{color:r.color}}):p.push(t);return r(p,i(u),t((e,t)=>({tag:e,spec:{color:l(c[t%c.length])}})),o(f),i((e,t)=>u(e.tag,t.tag)),s(a(`tag`),a(`spec`)))}export{d as t};
1
+ import{O as e,T as t,X as n,et as r,l as i,m as a,nt as o,p as s}from"./libs/remeda.mjs";import{R as c,Tn as l,vn as u}from"./types.mjs";function d(d){let f=[],p=[];for(let[t,r]of n(d))e(r.color)?f.push({tag:t,spec:{color:r.color}}):p.push(t);return r(p,i(u),t((e,t)=>({tag:e,spec:{color:l(c[t%c.length])}})),o(f),i((e,t)=>u(e.tag,t.tag)),s(a(`tag`),a(`spec`)))}export{d as t};
@@ -660,6 +660,10 @@ declare namespace FqnExpr {
660
660
  border?: BorderStyle;
661
661
  opacity?: number;
662
662
  navigateTo?: StrictViewId<A>;
663
+ /**
664
+ * If true, each matching element is rendered as multiple shapes.
665
+ * @default false
666
+ */
663
667
  multiple?: boolean;
664
668
  size?: ShapeSize;
665
669
  padding?: ShapeSize;
@@ -739,6 +743,11 @@ declare namespace RelationExpr {
739
743
  line?: RelationshipLineType;
740
744
  head?: RelationshipArrowType;
741
745
  tail?: RelationshipArrowType;
746
+ /**
747
+ * If true, each matching relationship is rendered as a separate edge.
748
+ * @default false
749
+ */
750
+ multiple?: boolean;
742
751
  };
743
752
  }
744
753
  function isCustom<A extends AnyAux$1>(expr: Expression<A>): expr is Custom<A>;
@@ -851,6 +860,10 @@ declare namespace ModelFqnExpr {
851
860
  border?: BorderStyle;
852
861
  opacity?: number;
853
862
  navigateTo?: StrictViewId<A>;
863
+ /**
864
+ * If true, each matching element is rendered as multiple shapes.
865
+ * @default false
866
+ */
854
867
  multiple?: boolean;
855
868
  size?: ShapeSize;
856
869
  padding?: ShapeSize;
@@ -927,6 +940,11 @@ declare namespace ModelRelationExpr {
927
940
  line?: RelationshipLineType;
928
941
  head?: RelationshipArrowType;
929
942
  tail?: RelationshipArrowType;
943
+ /**
944
+ * If true, each matching relationship is rendered as a separate edge.
945
+ * @default false
946
+ */
947
+ multiple?: boolean;
930
948
  };
931
949
  }
932
950
  function isCustom<A extends AnyAux>(expr: ModelExpression<A>): expr is Custom<A>;
@@ -997,6 +1015,10 @@ interface AnyViewRuleStyle<Expr> {
997
1015
  style: {
998
1016
  border?: BorderStyle;
999
1017
  opacity?: number;
1018
+ /**
1019
+ * If true, the element is rendered as multiple shapes.
1020
+ * @default false
1021
+ */
1000
1022
  multiple?: boolean;
1001
1023
  size?: ShapeSize;
1002
1024
  padding?: SpacingSize;
@@ -1090,6 +1112,10 @@ interface ElementViewRuleGroup<A extends Any = Any> {
1090
1112
  color?: Color;
1091
1113
  border?: BorderStyle;
1092
1114
  opacity?: number;
1115
+ /**
1116
+ * If true, each matching element in the group is rendered as multiple shapes.
1117
+ * @default false
1118
+ */
1093
1119
  multiple?: boolean;
1094
1120
  size?: ShapeSize;
1095
1121
  padding?: SpacingSize;
@@ -1324,6 +1350,10 @@ interface ElementSpecification {
1324
1350
  size?: ShapeSize;
1325
1351
  padding?: SpacingSize;
1326
1352
  textSize?: TextSize;
1353
+ /**
1354
+ * If true, the element is rendered as multiple shapes.
1355
+ * @default false
1356
+ */
1327
1357
  multiple?: boolean;
1328
1358
  };
1329
1359
  }
@@ -1344,6 +1374,12 @@ interface RelationshipSpecification {
1344
1374
  line?: RelationshipLineType;
1345
1375
  head?: RelationshipArrowType;
1346
1376
  tail?: RelationshipArrowType;
1377
+ /**
1378
+ * If true, matching relationships are rendered as separate edges instead of
1379
+ * being merged into a single connection.
1380
+ * @default false
1381
+ */
1382
+ multiple?: boolean;
1347
1383
  }
1348
1384
  type Specification<A> = A extends Any ? {
1349
1385
  tags: { [key in Tag<A>]: TagSpecification };
@@ -1591,6 +1627,11 @@ interface DiagramEdge<A extends Any = Any> extends ComputedEdge<A> {
1591
1627
  * (Absolute coordinates)
1592
1628
  */
1593
1629
  labelBBox?: BBox | null;
1630
+ /**
1631
+ * Whether the label position was manually set by the user.
1632
+ * When set, the label keeps its position and is not auto-centered on the edge.
1633
+ */
1634
+ isLabelCustomized?: boolean;
1594
1635
  /**
1595
1636
  * List of reasons causing edge drift
1596
1637
  */
@@ -1717,7 +1758,15 @@ type DeploymentViewRule<A extends Any = Unknown> = ExclusiveUnion<{
1717
1758
  Exclude: DeploymentViewExcludePredicate<A>;
1718
1759
  Style: DeploymentViewRuleStyle<A>;
1719
1760
  AutoLayout: ViewRuleAutoLayout;
1761
+ IncludeAncestors: ParsedViewRuleAncestors;
1720
1762
  }>;
1763
+ interface ParsedViewRuleAncestors<A extends Any = Unknown> {
1764
+ /**
1765
+ * When true, ancestor elements of included deployment nodes are also included in the view.
1766
+ * @default false (ancestors are not included)
1767
+ */
1768
+ includeAncestors: boolean;
1769
+ }
1721
1770
  interface ParsedDeploymentView<A extends Any = Unknown> extends BaseParsedViewProperties<A> {
1722
1771
  [_type]: 'deployment';
1723
1772
  readonly rules: DeploymentViewRule<A>[];
@@ -1893,8 +1942,26 @@ declare namespace ViewChange {
1893
1942
  rankSep?: number | null;
1894
1943
  };
1895
1944
  }
1945
+ interface ChangeProperty {
1946
+ op: 'change-property';
1947
+ /**
1948
+ * Change title
1949
+ */
1950
+ title?: string;
1951
+ /**
1952
+ * Change description
1953
+ */
1954
+ description?: MarkdownOrString;
1955
+ /**
1956
+ * Add or remove tags
1957
+ */
1958
+ tag?: {
1959
+ add?: Tag$1 | Tag$1[];
1960
+ remove?: Tag$1 | Tag$1[];
1961
+ };
1962
+ }
1896
1963
  }
1897
- type ViewChange = ViewChange.ChangeElementStyle | ViewChange.SaveViewSnapshot | ViewChange.ResetManualLayout | ViewChange.ChangeAutoLayout;
1964
+ type ViewChange = ViewChange.ChangeElementStyle | ViewChange.SaveViewSnapshot | ViewChange.ResetManualLayout | ViewChange.ChangeAutoLayout | ViewChange.ChangeProperty;
1898
1965
  //#endregion
1899
1966
  //#region src/types/RichText.d.ts
1900
1967
  interface RichTextEmpty {
@@ -2015,4 +2082,4 @@ type GuardedBy<G> = G extends Guard<infer To> ? Or<IsAny<To>, IsUnknown<To>> ext
2015
2082
  */
2016
2083
  declare function isAnyOf<const Predicates extends NonEmptyArray<Guard<any>>>(...predicates: Predicates): <T>(value: T) => value is T & GuardedBy<Predicates[number]>;
2017
2084
  //#endregion
2018
- export { LayoutedViewDriftReason as $, ExclusiveUnion as $i, whereOperatorAsPredicate as $n, RelationKind as $r, ElementViewPredicate as $t, isComputedView as A, RelationId$1 as Ai, Expression as An, Sizes as Ar, ModelRelation as At, DeploymentViewIncludePredicate as B, isGlobalFqn as Bi, OperatorPredicate as Bn, EdgeId as Br, DynamicStepsParallel as Bt, LayoutedView as C, GroupElementKind as Ci, isAutoLayoutDirection as Cn, ThemeColorValues as Cr, DeploymentRelation as Ct, ViewRule as D, NodeId$1 as Di, ModelExpression as Dn, DefaultTagColors as Dr, AbstractRelationship as Dt, ViewOnStage as E, MarkdownOrString as Ei, isViewRuleGlobalStyle as En, BorderStyles as Er, isDeploymentNode as Et, isExtendsElementView as F, StepEdgeKind as Fi, EqualOperator as Fn, AnyParsed as Fr, GlobalPredicates as Ft, DiagramEdge as G, stepEdgeId as Gi, WhereOperator as Gn, LooseElementId as Gr, DynamicViewStep as Gt, DeploymentViewRule as H, isStepEdgeId as Hi, Participant as Hn, ElementKind as Hr, DynamicViewDisplayVariant as Ht, isScopedElementView as I, Tag$1 as Ii, Filterable as In, Aux as Ir, GlobalStyleID as It, LayoutedDeploymentView as J, _layout as Ji, isMetadataEqual as Jn, LooseViewId as Jr, isDynamicStep as Jt, DiagramNode as K, ExtractOnStage as Ki, isAndOperator as Kn, LooseLiteral as Kr, ParsedDynamicView as Kt, isViewRulePredicate as L, ViewId$1 as Li, KindEqual as Ln, DeploymentFqn as Lr, GlobalStyles as Lt, isDiagramView as M, RelationshipKind as Mi, PredicateSelector as Mn, Any as Mr, ensureSizes as Mt, isDynamicView as N, StepEdgeId as Ni, RelationExpr as Nn, AnyComputed as Nr, GlobalDynamicPredicates as Nt, ViewRulePredicate as O, NoneIcon as Oi, ModelFqnExpr as On, ElementShapes as Or, Element as Ot, isElementView as P, StepEdgeIdLiteral as Pi, AndOperator as Pn, AnyLayouted as Pr, GlobalPredicateId as Pt, DiagramNodeDriftReason as Q, Coalesce as Qi, isTagEqual as Qn, RelationId as Qr, ElementViewIncludePredicate as Qt, isViewRuleStyle as R, extractStep as Ri, MetadataEqual as Rn, DeploymentId as Rr, ModelGlobals as Rt, ComputedView as S, GlobalFqn as Si, ViewWithNotation as Sn, ThemeColor as Sr, DeploymentNode as St, ProcessedView as T, IconUrl as Ti, isViewRuleGlobalPredicateRef as Tn, isThemeColor as Tr, isDeployedInstance as Tt, DeploymentViewRuleStyle as U, scalar_d_exports as Ui, ParticipantOperator as Un, Fqn as Ur, DynamicViewIncludeRule as Ut, DeploymentViewPredicate as V, isGroupElementKind as Vi, OrOperator as Vn, ElementId as Vr, DynamicStepsSeries as Vt, ParsedDeploymentView as W, splitGlobalFqn as Wi, TagEqual as Wn, LooseDeploymentId as Wr, DynamicViewRule as Wt, LayoutedElementView as X, _type as Xi, isOrOperator as Xn, MetadataKey as Xr, isDynamicStepsSeries as Xt, LayoutedDynamicView as Y, _stage as Yi, isNotOperator as Yn, Metadata as Yr, isDynamicStepsParallel as Yt, DiagramEdgeDriftReason as Z, isOnStage as Zi, isParticipantOperator as Zn, ProjectId as Zr, ElementViewExcludePredicate as Zt, ComputedLikeC4ModelData as _, DeploymentFqn$1 as _i, ViewRuleGlobalPredicateRef as _n, RelationshipLineType as _r, TagSpecification as _t, isNonEmptyArray as a, NonEmptyArray as aa, Unknown as ai, isViewRuleGroup as an, CustomColorDefinitions as ar, ComputedNode as at, ParsedLikeC4ModelData as b, ElementKind$1 as bi, ViewType as bn, SpacingSize as br, DeploymentElement as bt, RichTextEmpty as c, ReorderedArray as ca, UnknownParsed as ci, AnyIncludePredicate as cn, HexColor as cr, LikeC4Project as ct, AuxFromDump as d, preferDescription as di, BaseParsedViewProperties as dn, LikeC4StyleDefaults as dr, LikeC4ProjectStylesConfig as dt, IterableContainer as ea, SpecAux as ei, ElementViewRule as en, FqnRef as er, ViewManualLayoutSnapshot as et, LikeC4ModelDump as f, preferSummary as fi, BaseViewProperties as fn, LikeC4StylesConfig as fr, LikeC4ProjectStylesCustomStylesheets as ft, AuxFromLikeC4ModelData as g, BuiltInIcon as gi, ViewRuleAutoLayout as gn, RelationshipColorValues as gr, Specification as gt, SpecificationDump as h, AnyFqn as hi, ViewAutoLayout as hn, RelationshipArrowTypes as hr, RelationshipSpecification as ht, isAnyOf as i, NTuple as ia, Tags as ii, ParsedElementView as in, CustomColor as ir, ComputedElementView as it, isDeploymentView as j, RelationKind$1 as ji, FqnExpr as jn, ThemeColors as jr, Relationship as jt, ViewWithType as k, ProjectId$1 as ki, ModelRelationExpr as kn, IconPositions as kr, ElementStyle as kt, RichTextOrEmpty as l, exact as la, ViewId as li, AnyViewRuleStyle as ln, IconPosition as lr, LikeC4ProjectManualLayoutsConfig as lt, SpecTypesFromDump as m, toComputed as mi, RankValue as mn, RelationshipArrowType as mr, ElementSpecification as mt, GuardedBy as n, KeysOf as na, StrictViewId as ni, ElementViewRuleRank as nn, Color as nr, ComputedDynamicView as nt, isString as o, NonEmptyReadonlyArray as oa, UnknownComputed as oi, isViewRuleRank as on, ElementColorValues as or, ComputedNodeStyle as ot, ProjectDump as p, setProject as pi, NodeNotation as pn, LikeC4Theme as pr, LikeC4ProjectTheme as pt, LayoutType as q, ModelStage as qi, isKindEqual as qn, LooseTag as qr, getParallelStepsPrefix as qt, hasProp as r, Link as ra, Tag as ri, ElementViewRuleStyle as rn, ColorLiteral as rr, ComputedEdge as rt, RichText as s, Predicate as sa, UnknownLayouted as si, AnyExcludePredicate as sn, ElementShape as sr, ComputedRankConstraint as st, Guard as t, IteratorLike as ta, Stage as ti, ElementViewRuleGroup as tn, BorderStyle as tr, ComputedDeploymentView as tt, ViewChange as u, _aux_d_exports as ui, AutoLayoutDirection as un, IconSize as ur, LikeC4ProjectStyleDefaults as ut, LayoutedLikeC4ModelData as v, DeploymentKind$1 as vi, ViewRuleGlobalStyle as vn, ShapeSize as vr, isTagColorSpecified as vt, ParsedView as w, Icon as wi, isViewRuleAutoLayout as wn, isCustomColor as wr, DeploymentRelationship as wt, AnyView as x, Fqn$1 as xi, ViewWithHash as xn, TextSize as xr, DeploymentElementRef$1 as xt, LikeC4ModelData as y, EdgeId$1 as yi, ViewRuleRank as yn, Size as yr, DeployedInstance as yt, DeploymentViewExcludePredicate as z, flattenMarkdownOrString as zi, NotOperator as zn, DeploymentKind as zr, DynamicStep as zt };
2085
+ export { DiagramNodeDriftReason as $, Coalesce as $i, isTagEqual as $n, RelationId as $r, ElementViewIncludePredicate as $t, isComputedView as A, ProjectId$1 as Ai, ModelRelationExpr as An, IconPositions as Ar, ElementStyle as At, DeploymentViewIncludePredicate as B, flattenMarkdownOrString as Bi, NotOperator as Bn, DeploymentKind as Br, DynamicStep as Bt, LayoutedView as C, GlobalFqn as Ci, ViewWithNotation as Cn, ThemeColor as Cr, DeploymentNode as Ct, ViewRule as D, MarkdownOrString as Di, isViewRuleGlobalStyle as Dn, BorderStyles as Dr, isDeploymentNode as Dt, ViewOnStage as E, IconUrl as Ei, isViewRuleGlobalPredicateRef as En, isThemeColor as Er, isDeployedInstance as Et, isExtendsElementView as F, StepEdgeIdLiteral as Fi, AndOperator as Fn, AnyLayouted as Fr, GlobalPredicateId as Ft, ParsedViewRuleAncestors as G, splitGlobalFqn as Gi, TagEqual as Gn, LooseDeploymentId as Gr, DynamicViewRule as Gt, DeploymentViewRule as H, isGroupElementKind as Hi, OrOperator as Hn, ElementId as Hr, DynamicStepsSeries as Ht, isScopedElementView as I, StepEdgeKind as Ii, EqualOperator as In, AnyParsed as Ir, GlobalPredicates as It, LayoutType as J, ModelStage as Ji, isKindEqual as Jn, LooseTag as Jr, getParallelStepsPrefix as Jt, DiagramEdge as K, stepEdgeId as Ki, WhereOperator as Kn, LooseElementId as Kr, DynamicViewStep as Kt, isViewRulePredicate as L, Tag$1 as Li, Filterable as Ln, Aux as Lr, GlobalStyleID as Lt, isDiagramView as M, RelationKind$1 as Mi, FqnExpr as Mn, ThemeColors as Mr, Relationship as Mt, isDynamicView as N, RelationshipKind as Ni, PredicateSelector as Nn, Any as Nr, ensureSizes as Nt, ViewRulePredicate as O, NodeId$1 as Oi, ModelExpression as On, DefaultTagColors as Or, AbstractRelationship as Ot, isElementView as P, StepEdgeId as Pi, RelationExpr as Pn, AnyComputed as Pr, GlobalDynamicPredicates as Pt, DiagramEdgeDriftReason as Q, isOnStage as Qi, isParticipantOperator as Qn, ProjectId as Qr, ElementViewExcludePredicate as Qt, isViewRuleStyle as R, ViewId$1 as Ri, KindEqual as Rn, DeploymentFqn as Rr, GlobalStyles as Rt, ComputedView as S, Fqn$1 as Si, ViewWithHash as Sn, TextSize as Sr, DeploymentElementRef$1 as St, ProcessedView as T, Icon as Ti, isViewRuleAutoLayout as Tn, isCustomColor as Tr, DeploymentRelationship as Tt, DeploymentViewRuleStyle as U, isStepEdgeId as Ui, Participant as Un, ElementKind as Ur, DynamicViewDisplayVariant as Ut, DeploymentViewPredicate as V, isGlobalFqn as Vi, OperatorPredicate as Vn, EdgeId as Vr, DynamicStepsParallel as Vt, ParsedDeploymentView as W, scalar_d_exports as Wi, ParticipantOperator as Wn, Fqn as Wr, DynamicViewIncludeRule as Wt, LayoutedDynamicView as X, _stage as Xi, isNotOperator as Xn, Metadata as Xr, isDynamicStepsParallel as Xt, LayoutedDeploymentView as Y, _layout as Yi, isMetadataEqual as Yn, LooseViewId as Yr, isDynamicStep as Yt, LayoutedElementView as Z, _type as Zi, isOrOperator as Zn, MetadataKey as Zr, isDynamicStepsSeries as Zt, ComputedLikeC4ModelData as _, BuiltInIcon as _i, ViewRuleAutoLayout as _n, RelationshipColorValues as _r, Specification as _t, isNonEmptyArray as a, NTuple as aa, Tags as ai, ParsedElementView as an, CustomColor as ar, ComputedElementView as at, ParsedLikeC4ModelData as b, EdgeId$1 as bi, ViewRuleRank as bn, Size as br, DeployedInstance as bt, RichTextEmpty as c, Predicate as ca, UnknownLayouted as ci, AnyExcludePredicate as cn, ElementShape as cr, ComputedRankConstraint as ct, AuxFromDump as d, _aux_d_exports as di, AutoLayoutDirection as dn, IconSize as dr, LikeC4ProjectStyleDefaults as dt, ExclusiveUnion as ea, RelationKind as ei, ElementViewPredicate as en, whereOperatorAsPredicate as er, LayoutedViewDriftReason as et, LikeC4ModelDump as f, preferDescription as fi, BaseParsedViewProperties as fn, LikeC4StyleDefaults as fr, LikeC4ProjectStylesConfig as ft, AuxFromLikeC4ModelData as g, AnyFqn as gi, ViewAutoLayout as gn, RelationshipArrowTypes as gr, RelationshipSpecification as gt, SpecificationDump as h, toComputed as hi, RankValue as hn, RelationshipArrowType as hr, ElementSpecification as ht, isAnyOf as i, Link as ia, Tag as ii, ElementViewRuleStyle as in, ColorLiteral as ir, ComputedEdge as it, isDeploymentView as j, RelationId$1 as ji, Expression as jn, Sizes as jr, ModelRelation as jt, ViewWithType as k, NoneIcon as ki, ModelFqnExpr as kn, ElementShapes as kr, Element as kt, RichTextOrEmpty as l, ReorderedArray as la, UnknownParsed as li, AnyIncludePredicate as ln, HexColor as lr, LikeC4Project as lt, SpecTypesFromDump as m, setProject as mi, NodeNotation as mn, LikeC4Theme as mr, LikeC4ProjectTheme as mt, GuardedBy as n, IteratorLike as na, Stage as ni, ElementViewRuleGroup as nn, BorderStyle as nr, ComputedDeploymentView as nt, isString as o, NonEmptyArray as oa, Unknown as oi, isViewRuleGroup as on, CustomColorDefinitions as or, ComputedNode as ot, ProjectDump as p, preferSummary as pi, BaseViewProperties as pn, LikeC4StylesConfig as pr, LikeC4ProjectStylesCustomStylesheets as pt, DiagramNode as q, ExtractOnStage as qi, isAndOperator as qn, LooseLiteral as qr, ParsedDynamicView as qt, hasProp as r, KeysOf as ra, StrictViewId as ri, ElementViewRuleRank as rn, Color as rr, ComputedDynamicView as rt, RichText as s, NonEmptyReadonlyArray as sa, UnknownComputed as si, isViewRuleRank as sn, ElementColorValues as sr, ComputedNodeStyle as st, Guard as t, IterableContainer as ta, SpecAux as ti, ElementViewRule as tn, FqnRef as tr, ViewManualLayoutSnapshot as tt, ViewChange as u, exact as ua, ViewId as ui, AnyViewRuleStyle as un, IconPosition as ur, LikeC4ProjectManualLayoutsConfig as ut, LayoutedLikeC4ModelData as v, DeploymentFqn$1 as vi, ViewRuleGlobalPredicateRef as vn, RelationshipLineType as vr, TagSpecification as vt, ParsedView as w, GroupElementKind as wi, isAutoLayoutDirection as wn, ThemeColorValues as wr, DeploymentRelation as wt, AnyView as x, ElementKind$1 as xi, ViewType as xn, SpacingSize as xr, DeploymentElement as xt, LikeC4ModelData as y, DeploymentKind$1 as yi, ViewRuleGlobalStyle as yn, ShapeSize as yr, isTagColorSpecified as yt, DeploymentViewExcludePredicate as z, extractStep as zi, MetadataEqual as zn, DeploymentId as zr, ModelGlobals as zt };
@@ -1,5 +1,6 @@
1
- import { Cr as ThemeColorValues, Dr as DefaultTagColors, Ii as Tag, Sr as ThemeColor, _t as TagSpecification, ar as CustomColorDefinitions, br as SpacingSize, dr as LikeC4StyleDefaults, dt as LikeC4ProjectStylesConfig, fr as LikeC4StylesConfig, ft as LikeC4ProjectStylesCustomStylesheets, gr as RelationshipColorValues, ia as NTuple, lr as IconPosition, nr as Color, or as ElementColorValues, ot as ComputedNodeStyle, pr as LikeC4Theme, rr as ColorLiteral, tr as BorderStyle, ur as IconSize, vr as ShapeSize, xr as TextSize } from "./index.mjs";
1
+ import { Cr as ThemeColor, Li as Tag, Or as DefaultTagColors, Sr as TextSize, _r as RelationshipColorValues, aa as NTuple, dr as IconSize, fr as LikeC4StyleDefaults, ft as LikeC4ProjectStylesConfig, ir as ColorLiteral, lr as HexColor, mr as LikeC4Theme, nr as BorderStyle, or as CustomColorDefinitions, pr as LikeC4StylesConfig, pt as LikeC4ProjectStylesCustomStylesheets, rr as Color, sr as ElementColorValues, st as ComputedNodeStyle, ur as IconPosition, vt as TagSpecification, wr as ThemeColorValues, xr as SpacingSize, yr as ShapeSize } from "./index.mjs";
2
2
  import { LiteralUnion } from "type-fest";
3
+ import chroma from "chroma-js";
3
4
 
4
5
  //#region src/styles/assignTagColors.d.ts
5
6
  declare function assignTagColors(tags: {
@@ -138,7 +139,17 @@ declare class LikeC4Styles {
138
139
  }
139
140
  //#endregion
140
141
  //#region src/styles/compute-color-values.d.ts
142
+ /**
143
+ * Returns true when the input is a valid color literal parseable by chroma-js
144
+ * (e.g. `#ff0000`, `rgb(255, 0, 0)`, named CSS colors). Useful as a safety
145
+ * check before calling color-math helpers that throw on malformed input.
146
+ */
147
+ declare function isValidColor(color: string | chroma.Color): boolean;
141
148
  declare function computeColorValues(color: ColorLiteral): ThemeColorValues;
149
+ declare function getContrastedColorsAPCA(refColor: string | chroma.Color): {
150
+ hiContrast: HexColor;
151
+ loContrast: HexColor;
152
+ };
142
153
  //#endregion
143
154
  //#region src/styles/defaults.d.ts
144
155
  declare const styleDefaults: LikeC4StyleDefaults;
@@ -146,4 +157,4 @@ declare const styleDefaults: LikeC4StyleDefaults;
146
157
  //#region src/styles/theme.d.ts
147
158
  declare const defaultTheme: LikeC4Theme;
148
159
  //#endregion
149
- export { assignTagColors as a, LikeC4Styles as i, styleDefaults as n, computeColorValues as r, defaultTheme as t };
160
+ export { isValidColor as a, getContrastedColorsAPCA as i, styleDefaults as n, LikeC4Styles as o, computeColorValues as r, assignTagColors as s, defaultTheme as t };
@@ -1,4 +1,4 @@
1
- import { Br as EdgeId, Mr as Any, ai as Unknown, ca as ReorderedArray, ea as IterableContainer, ta as IteratorLike, xi as Fqn } from "./index.mjs";
1
+ import { Nr as Any, Si as Fqn, Vr as EdgeId, la as ReorderedArray, na as IteratorLike, oi as Unknown, ta as IterableContainer } from "./index.mjs";
2
2
  import { C as ElementModel, S as NodeModel, T as RelationshipModel, a as DeploymentNodeModel, c as NestedElementOfDeployedInstanceModel, i as DeploymentElementModel, l as RelationshipsAccum, r as DeployedInstanceModel, s as DeploymentRelationModel, w as AnyRelationshipModel, x as EdgeModel, y as LikeC4ViewModel } from "./LikeC4Model.mjs";
3
3
 
4
4
  //#region src/model/connection/Connection.d.ts