@likec4/core 1.55.1 → 1.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/THIRD-PARTY-LICENSES.md +30 -30
- package/dist/_chunks/Builder.view-element.mjs +2 -2
- package/dist/_chunks/LikeC4Model.d.mts +2 -1
- package/dist/_chunks/_types.d.mts +7 -3
- package/dist/_chunks/_types2.d.mts +1 -1
- package/dist/_chunks/assignTagColors.mjs +1 -1
- package/dist/_chunks/index.d.mts +64 -2
- package/dist/_chunks/index3.d.mts +1 -1
- package/dist/_chunks/index4.d.mts +1 -1
- package/dist/_chunks/index5.d.mts +13 -2
- package/dist/_chunks/libs/chroma-js.mjs +15 -0
- package/dist/_chunks/libs/graphology-dag.d.mts +607 -0
- package/dist/_chunks/libs/graphology-dag.mjs +1 -1
- package/dist/_chunks/libs/hast-util-to-html.mjs +1 -1
- package/dist/_chunks/libs/mdast-util-find-and-replace.mjs +1 -1
- package/dist/_chunks/libs/mdast-util-from-markdown.mjs +1 -1
- package/dist/_chunks/libs/mdast-util-gfm.mjs +11 -11
- package/dist/_chunks/libs/mnemonist.d.mts +33 -33
- package/dist/_chunks/libs/mnemonist.mjs +1 -1
- package/dist/_chunks/libs/unified.mjs +1 -1
- package/dist/_chunks/manual-layout.mjs +1 -1
- package/dist/_chunks/mnemonist.d.mts +1 -1
- package/dist/_chunks/model.mjs +4 -4
- package/dist/_chunks/rolldown-runtime.mjs +1 -1
- package/dist/_chunks/types.mjs +1 -1
- package/dist/builder/index.d.mts +2 -8
- package/dist/builder/index.mjs +1 -1
- package/dist/compute-view/index.d.mts +2 -6
- package/dist/compute-view/index.mjs +2 -2
- package/dist/geometry/index.mjs +1 -1
- package/dist/index.d.mts +4 -5
- package/dist/index.mjs +1 -1
- package/dist/model/index.d.mts +0 -5
- package/dist/model/index.mjs +1 -1
- package/dist/styles/index.d.mts +1 -2
- package/dist/styles/index.mjs +1 -1
- package/dist/types/index.d.mts +2 -2
- package/dist/types/index.mjs +1 -1
- package/dist/utils/graphology/index.d.mts +2 -1
- package/dist/utils/graphology/index.mjs +1 -1
- package/dist/utils/index.d.mts +3 -5
- package/dist/utils/index.mjs +1 -1
- package/package.json +10 -10
- package/dist/_chunks/geometry.mjs +0 -1
- package/dist/_chunks/libs/@mantine/colors-generator.mjs +0 -15
- package/dist/_chunks/utils.mjs +0 -1
|
@@ -35,36 +35,6 @@ Repository: https://github.com/likec4/likec4
|
|
|
35
35
|
|
|
36
36
|
---------------------------------------
|
|
37
37
|
|
|
38
|
-
## @mantine/colors-generator
|
|
39
|
-
|
|
40
|
-
License: MIT
|
|
41
|
-
By: Vitaly Rtishchev
|
|
42
|
-
Repository: https://github.com/mantinedev/mantine
|
|
43
|
-
|
|
44
|
-
> MIT License
|
|
45
|
-
>
|
|
46
|
-
> Copyright (c) 2021 Vitaly Rtishchev
|
|
47
|
-
>
|
|
48
|
-
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
49
|
-
> of this software and associated documentation files (the "Software"), to deal
|
|
50
|
-
> in the Software without restriction, including without limitation the rights
|
|
51
|
-
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
52
|
-
> copies of the Software, and to permit persons to whom the Software is
|
|
53
|
-
> furnished to do so, subject to the following conditions:
|
|
54
|
-
>
|
|
55
|
-
> The above copyright notice and this permission notice shall be included in all
|
|
56
|
-
> copies or substantial portions of the Software.
|
|
57
|
-
>
|
|
58
|
-
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
59
|
-
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
60
|
-
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
61
|
-
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
62
|
-
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
63
|
-
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
64
|
-
> SOFTWARE.
|
|
65
|
-
|
|
66
|
-
---------------------------------------
|
|
67
|
-
|
|
68
38
|
## @radix-ui/colors
|
|
69
39
|
|
|
70
40
|
License: MIT
|
|
@@ -471,6 +441,36 @@ Repository: https://github.com/graphology/graphology
|
|
|
471
441
|
|
|
472
442
|
---------------------------------------
|
|
473
443
|
|
|
444
|
+
## graphology-types
|
|
445
|
+
|
|
446
|
+
License: MIT
|
|
447
|
+
By: Guillaume Plique
|
|
448
|
+
Repository: https://github.com/graphology/graphology
|
|
449
|
+
|
|
450
|
+
> The MIT License (MIT)
|
|
451
|
+
>
|
|
452
|
+
> Copyright (c) 2020-2021 Guillaume Plique (Yomguithereal)
|
|
453
|
+
>
|
|
454
|
+
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
455
|
+
> of this software and associated documentation files (the "Software"), to deal
|
|
456
|
+
> in the Software without restriction, including without limitation the rights
|
|
457
|
+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
458
|
+
> copies of the Software, and to permit persons to whom the Software is
|
|
459
|
+
> furnished to do so, subject to the following conditions:
|
|
460
|
+
>
|
|
461
|
+
> The above copyright notice and this permission notice shall be included in
|
|
462
|
+
> all copies or substantial portions of the Software.
|
|
463
|
+
>
|
|
464
|
+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
465
|
+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
466
|
+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
467
|
+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
468
|
+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
469
|
+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
470
|
+
> THE SOFTWARE.
|
|
471
|
+
|
|
472
|
+
---------------------------------------
|
|
473
|
+
|
|
474
474
|
## graphology-utils, obliterator
|
|
475
475
|
|
|
476
476
|
License: MIT
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime.mjs";import{B as t,C as n,E as r,G as i,H as a,I as o,J as s,K as c,L as l,M as u,N as d,O as f,P as p,Q as m,R as h,S as g,T as _,V as v,Y as y,Z as ee,_ as te,a as ne,d as re,et as b,g as ie,h as ae,i as oe,k as se,m as ce,n as le,nt as ue,o as de,q as fe,r as pe,rt as x,t as me,tt as he,u as ge,v as _e,w as ve,x as ye,y as S,z as be}from"./libs/remeda.mjs";import{G as C,J as xe,O as w,St as T,U as Se,W as E,Y as D,_t as Ce,b as we,d as Te,dt as Ee,et as De,g as Oe,h as ke,ht as Ae,l as je,lt as Me,n as Ne,o as Pe,p as Fe,q as O,r as Ie,s as Le,tt as Re,u as ze,vt as Be,xt as Ve,y as He}from"./types.mjs";import{$ as k,A as Ue,B as We,D as A,I as j,K as Ge,L as Ke,M as qe,O as M,Q as N,R as Je,U as Ye,V as Xe,Z as Ze,_ as P,a as F,c as I,d as Qe,et as L,g as $e,i as et,j as tt,s as nt,u as R,v as z,w as rt,x as it,y as at}from"./utils.mjs";import{n as ot,t as st}from"./libs/graphology-dag.mjs";import{c as ct,t as lt}from"./libs/mnemonist.mjs";import{A as ut,C as dt,D as ft,E as pt,M as B,N as mt,O as ht,T as gt,_ as _t,c as vt,d as yt,f as bt,g as xt,h as St,j as Ct,m as wt,n as Tt,o as Et,p as Dt,q as Ot,r as kt,t as At,v as jt,w as Mt,y as Nt}from"./model.mjs";import{r as Pt}from"./manual-layout.mjs";import{t as Ft}from"./libs/graphology.mjs";function It(e,t){let n=[],r=e.parent;for(;r;){let e=k(t.get(r),`Parent node ${r} not found`);n.push(e),r=e.parent}return n}function Lt(e,t){for(let n of t){let t=e.get(n.source),i=e.get(n.target);N(t,`Source node ${n.source} not found`),N(i,`Target node ${n.target} not found`),t.outEdges.push(n.id),i.inEdges.push(n.id);let a=It(t,e),o=It(i,e),s=a.length>0&&o.length>0?r(Ze(ge(a),ge(o))):null;n.parent=s?s.id:null;for(let e of a){if(e===s)break;e.outEdges.push(n.id)}for(let e of o){if(e===s)break;e.inEdges.push(n.id)}}}var Rt=ot(),zt=e(st(),1);function Bt(e){let t=[],n=[...e],r;for(;r=n.shift();){let e=r.parent;if(e){let r=[];for(;e;){let t=n.findIndex(t=>t.id===e);if(t<0)break;let[i]=n.splice(t,1);if(!i)throw Error(`Invalid state, should not happen`);r.unshift(i),e=i.parent}t.push(...r)}t.push(r)}return t}function Vt(e){return e.forEach(t=>{t.children.length>0&&(t.children=e.reduce((e,n)=>(n.parent===t.id&&e.push(n.id),e),[]))}),e}function Ht(e){let t=Bt([...e.nodes.values()]),n=[...e.edges];if(t.length<2||n.length===0)return{nodes:t,edges:n};let r=t=>k(e.nodes.get(t)),a=new Ft({multi:!0,allowSelfLoops:!0,type:`directed`}),[o,s]=_e(b(n,_(e=>{let t=r(e.source),n=r(e.target),i=e.parent?r(e.parent):null;return{id:e.id,edge:e,parent:i,source:t,target:n}})),({source:e,target:t})=>e.children.length===0&&t.children.length===0),c=[],l=e=>{a.mergeNode(e.source),a.mergeNode(e.target),c.push(e),(0,zt.default)(a,e.source,e.target)||a.mergeDirectedEdge(e.source,e.target)};for(let{edge:t,source:n,target:s}of o)if(l(t),s.parent&&s.parent!==t.parent&&b(It(s,e.nodes),ne(e=>e.inEdges.includes(t.id)),i(e=>{a.mergeNode(e.id),(0,zt.default)(a,t.source,e.id)||a.mergeDirectedEdge(t.source,e.id),(0,zt.default)(a,e.id,t.target)||a.mergeDirectedEdge(e.id,t.target)})),n.parent){let e=r(n.parent);a.mergeNode(e.id),(0,zt.default)(a,e.id,n.id)||a.mergeDirectedEdge(e.id,n.id),s.parent&&s.parent!==n.parent&&((0,zt.default)(a,e.id,s.parent)||a.mergeDirectedEdge(e.id,s.parent))}for(let{edge:e}of s)l(e);N(c.length===n.length,`Not all edges were added to the graph`);let u=(0,Rt.topologicalSort)(a),d=[],f=t.slice();for(let e of u){let t=f.findIndex(t=>t.id===e);N(t>=0,`Node "${e}" not found`),d.push(...f.splice(t,1))}return f.length>0&&d.length>0&&(d=d.flatMap(e=>{if(f.length===0)return e;let n=t.slice(0,t.indexOf(e)).filter(e=>f.includes(e));return n.length>0?(f=f.filter(e=>!n.includes(e)),[...n,e]):e})),d.push(...f),{nodes:Vt(Bt(d)),edges:c}}function Ut(e){return e.hash=et({id:e.id,__:e._type??`element`,autoLayout:e.autoLayout,nodes:b(e.nodes,_(e=>({id:e.id,icon:f(e.icon)&&e.icon!==`none`?`Y`:`N`,title:e.title,description:Me(e.description),technology:e.technology??null,shape:e.shape,size:e.style.size??null,iconSize:e.style.iconSize??null,iconPosition:e.style.iconPosition??null,textSize:e.style.textSize??null,padding:e.style.padding??null,children:e.children})),ve(({id:e,...t})=>[e,t])),edges:b(e.edges,_(e=>({source:e.source,target:e.target,label:e.label,description:Me(e.description),technology:e.technology??null,dir:e.dir,head:e.head,tail:e.tail,line:e.line})),ve(({source:e,target:t,...n})=>[`${e}:${t}`,n]))}),e}var Wt=class{get Ctx(){throw Error(`Should not be called in runtime`)}constructor(e){this.state=e}get elements(){return this.state.elements}get explicits(){return this.state.explicits}get final(){return this.state.final}get connections(){return this.state.connections}isEmpty(){return this.elements.size===0&&this.connections.length===0&&this.explicits.size===0&&this.final.size===0}},Gt=class{excluded={elements:new Set,connections:[]};constructor(e,t){this.memory=e,this.expression=t}markedToMoveExplicitToImplicit=!1;_removeElement(e){this.excluded.elements.add(e)}exclude(e){if(!e)return this;if(M(e)){for(let t of e)this._removeElement(t);return this}return this._removeElement(e),this}_removeConnection(e){this.excluded.connections.push(e)}excludeConnections(e,t){if(be(t)&&(N(!this.markedToMoveExplicitToImplicit,`Already marked to move explicits`),this.markedToMoveExplicitToImplicit=t),M(e)){for(let t of e)this._removeConnection(t);return this}return this._removeConnection(e),this}isDirty(){return this.excluded.elements.size>0||this.excluded.connections.length>0}isEmpty(){return!this.isDirty()}filterForMoveToImplicits(e){return this.markedToMoveExplicitToImplicit||this.excluded.elements.size>0?e:new Set}moveDisconnectedExplicitsToImplicits(e){let t=F(new Set(this.memory.connections.flatMap(e=>[e.source,e.target])),new Set(e.connections.flatMap(e=>[e.source,e.target])));return t=I(t,e.elements),t=b(t,A(t=>e.explicits.has(t)&&!at(e.final,Ke(t))),z()),t.size>0&&(t=this.filterForMoveToImplicits(t),e.explicits=F(e.explicits,t),e.final=F(e.final,t)),e}removeElements(e){return e.elements=F(e.elements,this.excluded.elements),e.explicits=F(e.explicits,this.excluded.elements),e.final=F(e.final,this.excluded.elements),e}removeConnections(e){let t=this.excluded.connections.reduce((e,t)=>{let n=e.get(t.id);return n?e.set(t.id,n.mergeWith(t)):e.set(t.id,t),e},new Map),n=new Set;e.connections=e.connections.reduce((e,r)=>{let i=t.get(r.id);if(i){n.add(r.source),n.add(r.target);let t=r.difference(i);t.nonEmpty()&&e.push(t)}else e.push(r);return e},[]);for(let t of e.connections)n.delete(t.source),n.delete(t.target),t.boundary&&e.elements.has(t.boundary)&&n.delete(t.boundary);return n.size===0?e:(n=F(n,e.explicits),e.final=F(e.final,n),e)}precommit(e){return e}postcommit(e){return N(F(e.explicits,e.elements).size===0,`Explicits must be subset of elements`),N(F(e.final,e.elements).size===0,`Final elements must be subset of elements`),e}commit(){let e=this.precommit(this.memory.mutableState());if(this.excluded.elements.size>0){let t=e.connections.filter(e=>this.excluded.elements.has(e.source)||this.excluded.elements.has(e.target)).flatMap(t=>[t,..._t(e.connections,t).map(e=>e.intersect(t))]).filter(e=>e.nonEmpty());this.excludeConnections(t)}return this.excluded.connections.length>0&&(e=this.removeConnections(e)),this.excluded.elements.size>0&&(e=this.removeElements(e)),this.memory.update(this.postcommit(e))}},Kt=class{explicits=new Set;implicits=new Set;_ordered=new Set;_connections=[];constructor(e,t){this.memory=e,this.expression=t}get elements(){return this.explicits}get connections(){return this._connections}mergedConnections(){return ft([...this.memory.connections,...this._connections])}connectWithExisting(e,t){throw Error(`Method not implements, depends on the model`)}_addExplicit(e){this._ordered.add(e),this.explicits.add(e),this.implicits.delete(e)}addExplicit(e){if(!e)return this;if(M(e)){for(let t of e)this._addExplicit(t);return this}return this._addExplicit(e),this}_addImplicit(e){this.explicits.has(e)||(this._ordered.add(e),this.implicits.add(e))}addImplicit(e){if(!e)return this;if(M(e)){for(let t of e)this._addImplicit(t);return this}return this._addImplicit(e),this}_addConnection(e){this._connections.push(e),this._addImplicit(e.source),this._addImplicit(e.target)}addConnections(e){if(M(e)){for(let t of e)this._addConnection(t);return this}return this._addConnection(e),this}isDirty(){return this.explicits.size>0||this.implicits.size>0||this._connections.length>0}isEmpty(){return!this.isDirty()}precommit(e){return e}postcommit(e){return e}processConnections(e){return e}commit(){let e=this.precommit(this.memory.mutableState()),t=new Set;if(this._connections.length>0){let[n,r]=_e(this._connections,t=>e.final.has(t.source));e.connections=this.processConnections(ft([...e.connections,...n,...r])),t=new Set(e.connections.flatMap(e=>[e.source,e.target]))}return e.elements=R(e.elements,this._ordered,this.explicits,t,this.implicits),e.explicits=I(e.elements,R(e.explicits,this.explicits)),e.final=I(e.elements,R(e.final,this.explicits,t)),this.memory.update(this.postcommit(e))}};function qt(e,t=`final`){let n=Ye(P(t===`final`?e.final:e.elements)),r=new Set(e.connections.flatMap(e=>[e.source,e.target])),i=new Set(n),a=new lt.default(()=>null),o=n.reduce((e,t,n,r)=>(e.set(t,r.slice(n+1).filter(e=>j(t,e)).map(e=>(i.delete(e),e)).reduce((e,n)=>(e.some(e=>j(e,n))||(e.push(n),a.set(n,t)),e),[])),e),new lt.default(()=>[]));return{root:i,connected:r,hasInOut:t=>e.connections.some(B.isAnyInOut(t.id)),parent:e=>a.get(e),children:e=>o.get(e)}}var Jt=class extends Gt{};function V(e){if(E.isCustom(e))return V(e.custom.expr);if(E.isWhere(e)){let t=V(e.where.expr),n=w(e.where.condition);return e=>t(e)&&n(e)}if(E.isElementKindExpr(e))return e.isEqual?t=>t.kind===e.elementKind:t=>t.kind!==e.elementKind;if(E.isElementTagExpr(e))return e.isEqual?({tags:t})=>t.includes(e.elementTag):({tags:t})=>!t.includes(e.elementTag);if(E.isWildcard(e))return()=>!0;if(E.isModelRef(e)){let t=D.flatten(e.ref);if(e.selector===`expanded`)return e=>e.id===t||We(e.id)===t;if(e.selector===`descendants`||e.selector===`children`){let e=t+`.`;return t=>t.id.startsWith(e)}return e=>e.id===t}L(e)}function Yt(e,t,n){let{shape:r,color:a,icon:o,...s}=e.style,c=!l(s);b(n,y(d(Ee)),y(t),i(t=>{t.shape=r??t.shape,t.color=a??t.color,h(o)&&(t.icon=o),h(e.notation)&&(t.notation=e.notation),c&&(t.style={...t.style,...s})}))}function Xt(e,t){for(let n of e)!we(n)||n.targets.length===0||Yt(n,x(n.targets.map(V)),t);return t}var Zt=class e{static kind=De;constructor(e,t,n=null,r=new Set){this.id=e,this.viewRule=t,this.parent=n,this.elements=r}isEmpty(){return this.elements.size===0}update(t){return new e(this.id,this.viewRule,this.parent,t)}clone(){return new e(this.id,this.viewRule,this.parent,new Set(this.elements))}},Qt=class extends Gt{excludeRelations(e){return b(this.memory.connections,y(t=>nt(t.relations,e)),i(t=>{this.excludeConnections(t.update(I(t.relations,e)))})),this}precommit(e){if(this.excluded.elements.size>0){let e=new Set([...this.excluded.elements].flatMap(e=>[...e.incoming(`direct`),...e.outgoing(`direct`)]));this.excludeRelations(e)}return e}postcommit(e){let t=F(this.memory.explicits,e.explicits);for(let n of t)e.explicitFirstSeenIn.delete(n);let n=F(this.memory.elements,e.elements);for(let t of n)e.lastSeenIn.delete(t);return e}},$t=class extends Qt{constructor(e,t){super(e,t),this.memory=e,this.expression=t}};const{findConnection:en,findConnectionsBetween:tn}=Dt;var nn=class extends Kt{connectWithExisting(e,t=`both`){let n=this._connections.length,r=()=>this._connections.length>n;if(!M(e)){if(t===`in`||t===`both`)for(let t of this.memory.elements)this.addConnections(en(t,e,`directed`));return(t===`out`||t===`both`)&&this.addConnections(tn(e,this.memory.elements,`directed`)),r()}let i=[...e];if(t===`in`||t===`both`)for(let e of this.memory.elements)this.addConnections(tn(e,i,`directed`));if(t===`out`||t===`both`)for(let e of i)this.addConnections(tn(e,this.memory.elements,`directed`));return r()}addImplicitWithinScope(e){e&&(!this.memory.scope||j(this.memory.scope,e))&&this.addImplicit(e)}processConnections(e){return Se.isRelationExpr(this.expression)||b(e,i(({source:e,target:t,boundary:n})=>{b(me([...P(e.ancestors()).reverse(),e],[...P(t.ancestors()).reverse(),t]),ee(([e,t])=>e===t),de(1),i(([r,i])=>{if(r===e&&i===t){this.addImplicitWithinScope(n);return}r!==e&&this.addImplicitWithinScope(r),i!==t&&this.addImplicitWithinScope(i)}))})),e}postcommit(e){let t=F(e.explicits,this.memory.explicits);for(let n of t)e.explicitFirstSeenIn.set(n,`@root`);return e}},rn=class extends nn{constructor(e,t){super(e,t),this.memory=e,this.expression=t}postcommit(e){let t=F(e.explicits,this.memory.explicits);for(let n of t)e.explicitFirstSeenIn.set(n,this.memory.activeGroupId);for(let t of[...this.explicits,...this.implicits])e.lastSeenIn.set(t,this.memory.activeGroupId);return e}},an=class e extends Wt{static empty(t){return new e({elements:new Set,explicits:new Set,final:new Set,connections:[],groups:[],explicitFirstSeenIn:new Map,lastSeenIn:new Map},t)}constructor(e,t){super(e),this.state=e,this.scope=t}get groups(){return this.state.groups}get explicitFirstSeenIn(){return this.state.explicitFirstSeenIn}get lastSeenIn(){return this.state.lastSeenIn}stageInclude(e){return new nn(this,e)}stageExclude(e){return new Qt(this,e)}mutableState(){return{elements:new Set(this.state.elements),explicits:new Set(this.state.explicits),final:new Set(this.state.final),connections:[...this.state.connections],groups:this.state.groups.map(e=>e.clone()),explicitFirstSeenIn:new Map(this.state.explicitFirstSeenIn),lastSeenIn:new Map(this.state.lastSeenIn)}}update(t){return new e({...this.state,...t},this.scope)}},on=class e extends an{static enter(t,n){let r=`@gr${t.groups.length+1}`;if(t instanceof e){let i=ct.default.from([...t.stack].reverse()),a=t.mutableState();return a.groups.push(new Zt(r,n,t.activeGroupId)),i.push(r),new e(a,t.scope,i)}let i=t.mutableState();i.groups.push(new Zt(r,n,null));let a=ct.default.of(r);return new e(i,t.scope,a)}constructor(e,t,n){super(e,t),this.state=e,this.scope=t,this.stack=n}get activeGroupId(){return k(this.stack.peek(),`Stack must not be empty`)}mutableState(){return{...super.mutableState()}}update(t){return new e({...this.state,...t},this.scope,this.stack)}stageInclude(e){return new rn(this,e)}stageExclude(e){return new $t(this,e)}leave(){let t=this.mutableState();return this.stack.pop(),this.stack.peek()?new e(t,this.scope,this.stack):new an(t,this.scope)}};function sn(e,t){let n;for(;e.parent&&(n=t.get(e.parent));){let t=n.depth??1;if(n.depth=Math.max(t,(e.depth??0)+1),n.depth===t)break;e=n}}function cn(e){let{id:t,title:n,...r}=g(e.$element,[`summary`,`description`,`metadata`,`style`,`tags`]),{color:i,icon:a,shape:o,...s}=e.style;return T({id:t,title:n,modelRef:t,shape:o,color:i,icon:a,style:s,description:Ve(e.$element),tags:[...e.tags],metadata:e.$element.metadata,...r})}function ln({defaults:e},t,n){let r=new Map,i=new Map;n?.forEach(({id:t,parent:n,viewRule:a,elements:o})=>{n&&k(r.get(n),`Parent group node ${n} not found`).children.push(t),r.set(t,{id:t,parent:n,kind:De,title:a.title??``,color:a.color??e.group.color??e.color,shape:`rectangle`,children:[],inEdges:[],outEdges:[],level:0,depth:0,tags:[],style:T({border:a.border??e.group.border,opacity:a.opacity??e.group.opacity,size:a.size,multiple:a.multiple,padding:a.padding,textSize:a.textSize})});for(let e of o)i.set(e.id,t)}),Array.from(t).sort(qe).forEach(({id:e,...t})=>{let n=We(e),a=0,o;for(;n&&(o=r.get(n),!o);)n=We(n);let s=t.modelRef??e;if(!o&&i.has(s)){let e=k(i.get(s));o=r.get(e),n=e}o&&(o.children.length==0&&(o.depth=1,sn(o,r)),o.children.push(e),a=o.level+1);let c=T({id:e,parent:n,level:a,children:[],inEdges:[],outEdges:[],...t});r.set(e,c)});let a=new Map;return n?.forEach(({id:e})=>{a.set(e,k(r.get(e)))}),t.forEach(({id:e})=>{a.set(e,k(r.get(e)))}),a}function un(e){let{title:t,description:n=null}=e;return{...t&&{title:t,description:n},...te(e,[`color`,`technology`,`head`,`line`,`tail`,`kind`,`navigateTo`])}}function dn(e,t){let n=b(e,re((e,t)=>(f(t.title)&&!e.title.includes(t.title)&&e.title.push(t.title),f(t.description)&&!e.description.some(v(t.description))&&e.description.push(t.description),f(t.technology)&&!e.technology.includes(t.technology)&&e.technology.push(t.technology),f(t.kind)&&!e.kind.includes(t.kind)&&e.kind.push(t.kind),f(t.color)&&!e.color.includes(t.color)&&e.color.push(t.color),f(t.line)&&!e.line.includes(t.line)&&e.line.push(t.line),f(t.head)&&!e.head.includes(t.head)&&e.head.push(t.head),f(t.tail)&&!e.tail.includes(t.tail)&&e.tail.push(t.tail),f(t.navigateTo)&&!e.navigateTo.includes(t.navigateTo)&&e.navigateTo.push(t.navigateTo),t.tags&&e.tags.push(...t.tags),e),{title:[],description:[],technology:[],kind:[],head:[],tail:[],color:[],tags:[],line:[],navigateTo:[]})),r=S(n.title)??(n.title.length>1?`[...]`:void 0),i=oe(n.tags),a=T({title:r,description:S(n.description),technology:S(n.technology),kind:S(n.kind),head:S(n.head),tail:S(n.tail),color:S(n.color),line:S(n.line),navigateTo:S(n.navigateTo),...Ge(i)&&{tags:i}});if(t){let e=un(t);a=ie({...a,...e},f)}return u(a.title)&&f(a.technology)&&(a.title=`[${a.technology}]`,delete a.technology),a}const{findConnection:fn,findConnectionsBetween:H,findConnectionsWithin:pn}=wt;function U(e,t){let n=e.element(t.ref.deployment);if(n.isDeploymentNode()){if(t.selector===`children`)return[...n.children()];if(t.selector===`expanded`)return[n,...n.children()];if(t.selector===`descendants`)return[...n.descendants()]}return[n]}function mn(e,t){let n=e.$model.element(t.ref.model);return t.selector===`children`?[...n.children()]:t.selector===`expanded`?[n,...n.children()]:t.selector===`descendants`?[...n.descendants()]:[n]}function hn(e){if(O.isWildcard(e))return()=>!0;if(O.isElementTagExpr(e)||O.isElementKindExpr(e))throw Error(`element kind and tag expressions are not supported in deployment view rules`);if(O.isDeploymentRef(e)){let t=e.ref.deployment;if(e.selector===`expanded`){let e=t+`.`;return n=>n.id===t||n.id.startsWith(e)}if(e.selector===`descendants`){let e=t+`.`;return t=>t.id.startsWith(e)}return e.selector===`children`?e=>We(e.id)===t:e=>e.id===t}if(O.isModelRef(e)){let t=e.ref.model;if(e.selector===`expanded`){let e=t+`.`;return n=>{let r=n.modelRef??null;return r?r===t||r.startsWith(e):!0}}if(e.selector===`descendants`){let e=t+`.`;return t=>{let n=t.modelRef??null;return n?n.startsWith(e):!0}}return e.selector===`children`?e=>{let n=e.modelRef??null;return n?We(n)===t:!0}:e=>{let n=e.modelRef??null;return n?n===t:!0}}L(e)}function gn(e){return Ve(e.$instance)??Ve(e.element.$element)}function _n(e){let t=e.id,n=e.onlyOneInstance();return T({id:t,deploymentRef:t,title:e.title,kind:e.kind,technology:e.technology??void 0,links:m(e.links,1)?[...e.links]:void 0,notation:e.$node.notation??void 0,color:e.color,shape:e.shape,modelRef:n?.element.id,icon:e.style.icon,description:Ve(e.$node)??void 0,tags:[...e.tags],style:g(e.style,[`icon`,`shape`,`color`])})}function vn(e){let t=e.$instance,n=e.element,{icon:r,color:i,shape:a,...o}=e.style,s=[...n.links,...t.links??[]];return T({id:e.id,kind:`instance`,title:e.title,description:gn(e)??void 0,technology:e.technology??void 0,tags:[...e.tags],links:m(s,1)?s:void 0,icon:r,color:i,shape:a,style:o,deploymentRef:t.id,modelRef:n.id,notation:t.notation})}function yn(e){return e.isInstance()?vn(e):_n(e)}function bn(e){return e.reduce((e,t)=>{let n=[...t.relations.model,...t.relations.deployment];N(m(n,1),`Edge must have at least one relation`);let r=t.source.$model.$styles.defaults,i=t.source.id,a=t.target.id,{title:o,color:s=r.relationship.color,line:c=r.relationship.line,head:l=r.relationship.arrow,...u}=dn(n.map(e=>e.$relationship)),d=T({id:t.id,parent:t.boundary?.id??null,source:i,target:a,label:o??null,relations:n.map(e=>e.id),color:s,line:c,head:l,...u}),f=e.find(e=>e.source===a&&e.target===i);if(f&&d.label===f.label){f.dir=`both`;let n=f.head??d.head??t.source.$model.$styles.defaults.relationship.arrow;return f.head??=n,f.tail??=n,d.color&&(f.color??=d.color),d.line&&(f.line??=d.line),e}return e.push(d),e},[])}function xn(e,t){let n=ln(e.$styles,[...t.final].map(yn));for(let t of n.values()){if(!t.deploymentRef||!t.modelRef||t.children.length>0)continue;let n=e.deployment.element(t.deploymentRef),r=n.isDeploymentNode()&&n.onlyOneInstance();if(!r)continue;t.title===n.name&&(t.title=r.title),t.description??=gn(r)??null,t.technology??=r.technology,l(t.tags)&&(t.tags=[...r.tags]),(!t.links||l(t.links))&&m(r.links,1)&&(t.links=[...r.links]);let i=e.$styles.defaults;t.shape===i.shape&&t.shape!==r.shape&&(t.shape=r.shape,t.notation=null),t.color===i.color&&t.color!==r.color&&(t.color=r.color,t.notation=null),!t.icon&&r.icon&&(t.icon=r.icon)}return n}function Sn(e,t){for(let n of e)!we(n)||n.targets.length===0||Yt(n,x(n.targets.map(hn)),t);return t}function Cn(e){let t=new lt.default(()=>[]);for(let n of e)for(let e of n.relations.model)t.get(e).push(n);let n=new lt.default(()=>new Set);for(let[e,r]of t)m(r,2)&&b(r,c(e=>[{group:`$source-${e.source.id}`,conn:e},{group:`$target-${e.target.id}`,conn:e}]),a(ce(`group`)),pe(),y(m(2)),i(ae(_(ce(`conn`)),ht(`desc`),ee((e,t,n)=>t===0||e.boundary===n[t-1].boundary),i(t=>{n.get(t).add(e)}))));return n}function wn(e){e=ft(e);let t=Cn(e);for(let n of e){let{source:e,target:r}=n,i=n.relations.model;if(e.isDeploymentNode()!==r.isDeploymentNode()){let r=e.isDeploymentNode()?e:n.target;N(r.isDeploymentNode());let a=I(i,r.internalModelRelationships());for(let e of a)t.get(n).add(e);continue}if(e.isDeploymentNode()&&r.isDeploymentNode()){let i=R(I(n.relations.model,e.internalModelRelationships()),I(n.relations.model,r.internalModelRelationships()));for(let e of i)t.get(n).add(e)}}return b(t.entries(),it(([e,t])=>e.update({model:t,deployment:null})),P())}function Tn(e){return xt(e,wn(e))}function En(e){return b(e,ft,re((t,n)=>{let{source:r,target:i,relations:a}=n;if(r.isInstance()&&i.isInstance())return t;let o=Ot.empty();if(r.isDeploymentNode()&&i.isDeploymentNode()){let[e]=fn(i,r,`directed`);e&&(o=a.intersect(e.relations))}for(let t of e)gt(t,n)&&(o=o.union(a.intersect(t.relations)));return o.nonEmpty&&t.push(new ut(r,i,o)),t},[]))}function Dn(e){return xt(e,En(e))}var On=class extends Kt{connectWithExisting(e,t=`both`){let n=this._connections.length,r=()=>this._connections.length>n;if(!M(e)){if(t===`in`||t===`both`)for(let t of this.memory.elements)this.addConnections(fn(t,e,`directed`));return(t===`out`||t===`both`)&&this.addConnections(H(e,this.memory.elements,`directed`)),r()}let i=[...e];if(t===`in`||t===`both`)for(let e of this.memory.elements)this.addConnections(H(e,i,`directed`));if(t===`out`||t===`both`)for(let e of i)this.addConnections(H(e,this.memory.elements,`directed`));return r()}processConnections(e){let t=b(e,Tn,Dn);return b(t,i(({source:e,target:t,boundary:n})=>{b(me([...P(e.ancestors()).reverse(),e],[...P(t.ancestors()).reverse(),t]),ee(([e,t])=>e===t),de(1),i(([r,i])=>{if(e===r&&t===i){this.addImplicit(n);return}r!==e&&r.isDeploymentNode()&&!r.onlyOneInstance()&&this.addImplicit(r),i!==t&&i.isDeploymentNode()&&!i.onlyOneInstance()&&this.addImplicit(i)}))})),t}},kn=class e extends Wt{static empty(){return new e({elements:new Set,explicits:new Set,final:new Set,connections:[]})}stageInclude(e){return new On(this,e)}stageExclude(e){return new Jt(this,e)}mutableState(){return{elements:new Set(this.state.elements),explicits:new Set(this.state.explicits),final:new Set(this.state.final),connections:[...this.state.connections]}}update(t){return new e({...this.state,...t})}equals(t){return t instanceof e&&v(this.state,t.state)}diff(e){return{added:{elements:P(F(e.elements,this.elements)),explicits:P(F(e.explicits,this.explicits)),final:P(F(e.final,this.final)),connections:P(xt(e.connections,this.connections))},removed:{elements:P(F(this.elements,e.elements)),explicits:P(F(this.explicits,e.explicits)),final:P(F(this.final,e.final)),connections:xt(this.connections,e.connections)}}}toString(){return[`final:`,...[...this.final].map(e=>` `+e.id),`connections:`,...this.connections.map(e=>` `+e.expression)].join(`
|
|
2
|
-
`)}[Ct](e,t,n){return this.toString()}};const An={include:({expr:e,model:t,memory:n,stage:r})=>{let i=w(e.where.condition);return k(Hn(`include`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i}))},exclude:({expr:e,model:t,memory:n,stage:r})=>{let i=w(e.where.condition);return k(Hn(`exclude`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i}))}},jn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(O.isWildcard(e.incoming)){for(let e of a){if(e.allOutgoing.isEmpty)continue;let t=G(H(e,[...qn(e)],`directed`),i);r.addConnections(t)}return r}N(O.isDeploymentRef(e.incoming),`Only deployment refs are supported in include`);let o=U(t,e.incoming);for(let e of a){let t=G(H(e,o,`directed`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(O.isElementTagExpr(e.incoming)||O.isElementKindExpr(e.incoming))throw Error(`element kind and tag expressions are not supported in exclude`);if(O.isModelRef(e.incoming))return W(Nn(t,e.incoming),{stage:r,memory:n},i);if(O.isWildcard(e.incoming))return r;let a=Mn(U(t,e.incoming)),o=b(n.connections,y(a),G(i));return r.excludeConnections(o),r}};function Mn(e){return x(e.map(e=>{let t=t=>t===e||j(e,t);return e=>!t(e.source)&&t(e.target)}))}function Nn(e,t){let n=mn(e,t);return new Set(n.flatMap(e=>[...e.allIncoming]))}const Pn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(O.isWildcard(e.outgoing)){for(let e of a)if(!e.allIncoming.isEmpty)for(let t of qn(e)){let n=G(fn(t,e,`directed`),i);r.addConnections(n)}return r}N(O.isDeploymentRef(e.outgoing),`Only deployment refs are supported in include`);let o=U(t,e.outgoing);for(let e of o){let t=G(H(e,a,`directed`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(O.isElementTagExpr(e.outgoing)||O.isElementKindExpr(e.outgoing))throw Error(`element kind and tag expressions are not supported in exclude`);if(O.isModelRef(e.outgoing))return W(In(t,e.outgoing),{stage:r,memory:n},i);if(O.isWildcard(e.outgoing))return r;let a=Fn(U(t,e.outgoing)),o=b(n.connections,y(a),G(i));return r.excludeConnections(o),r}};function Fn(e){return x(e.map(e=>{let t=t=>t===e||j(e,t);return e=>t(e.source)&&!t(e.target)}))}function In(e,t){let n=mn(e,t);return new Set(n.flatMap(e=>[...e.allOutgoing]))}const Ln={include:({expr:{source:e,target:t,isBidirectional:n=!1},model:r,stage:i,where:a})=>{if(O.isElementTagExpr(e)||O.isElementKindExpr(e)||O.isElementTagExpr(t)||O.isElementKindExpr(t))throw Error(`element kind and tag expressions are not supported in include`);N(!O.isModelRef(e),`Invalid source model ref in direct relation`),N(!O.isModelRef(t),`Invalid target model ref in direct relation`);let o=O.isWildcard(e),s=O.isWildcard(t),l=n?`both`:`directed`,u;switch(!0){case o&&s:u=b(pn(r.instances()),G(a),_(e=>(i.addImplicit(e.boundary),e)));break;case!o&&s:{let t=U(r,e),i=Fn(t),o=i;if(n){let e=Mn(t);o=t=>i(t)!==e(t)}u=b(t,c(e=>H(e,qn(e),l)),y(o),G(a));break}case o&&!s:{let e=U(r,t),i=Mn(e),o=i;if(n){let t=Fn(e);o=e=>t(e)!==i(e)}u=b(e,c(e=>[...qn(e)].flatMap(t=>fn(t,e,l))),y(o),G(a));break}default:{N(!o,`Inference failed - source should be a deployment ref`),N(!s,`Inference failed - target should be a deployment ref`);let n=U(r,e),i=U(r,t),d=Fn(n),f=Mn(i);u=b(n,c(e=>H(e,i,l)),y(e=>d(e)&&f(e)),G(a))}}return i.addConnections(u),O.isDeploymentRef(e)&&p(e.selector)&&i.addImplicit(r.element(e.ref.deployment)),O.isDeploymentRef(t)&&p(t.selector)&&i.addImplicit(r.element(t.ref.deployment)),i},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=hn(e.target),o=hn(e.source),s;switch(!0){case O.isWildcard(e.source)&&O.isWildcard(e.target):return r.excludeConnections(G(n.connections,i)),r;case O.isModelRef(e.source)&&O.isModelRef(e.target):return s=Rn({source:e.source,target:e.target,expr:e,model:t}),W(s,{stage:r,memory:n},i);case O.isModelRef(e.source)&&O.isWildcard(e.target):return s=In(t,e.source),W(s,{stage:r,memory:n},i);case O.isModelRef(e.source):return s=In(t,e.source),W(s,{stage:r,memory:n},i,e=>a(e.target));case O.isModelRef(e.target):return s=Nn(t,e.target),W(s,{stage:r,memory:n},i,e=>o(e.source));default:let c=t=>o(t.source)&&a(t.target)||e.isBidirectional===!0&&o(t.target)&&a(t.source),l=b(n.connections,y(c),G(i));return l.length===0||r.excludeConnections(l),r}}};function Rn({source:e,target:t,expr:n,model:r}){let i=mn(r,e),a=mn(r,t),o=n.isBidirectional?`both`:`directed`,s=[];for(let e of i)s.push(...bt(e,a,o));return new Set(s.flatMap(e=>[...e.relations]))}const zn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(O.isWildcard(e.inout)){for(let e of a){let t=Wn(H(e,[...qn(e)],`both`),i);r.addConnections(t)}return r}N(O.isDeploymentRef(e.inout),`Only deployment refs are supported in include`);let o=U(t,e.inout);for(let e of a){let t=Wn(H(e,o,`both`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(O.isElementTagExpr(e.inout)||O.isElementKindExpr(e.inout))throw Error(`element kind and tag expressions are not supported in exclude`);if(O.isModelRef(e.inout)){let a=mn(t,e.inout);return a.length===0?r:W(R(new Set,...a.flatMap(e=>[e.allIncoming,e.allOutgoing])),{stage:r,memory:n},i)}if(O.isWildcard(e.inout))return r;let a=U(t,e.inout),o=Mn(a),s=Fn(a),c=b(n.connections,y(e=>o(e)!==s(e)),G(i));return r.excludeConnections(c),r}},Bn={include:({expr:e,model:t,memory:n,stage:r})=>{let i=w(e.where.condition);return Hn(`include`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})},exclude:({expr:e,model:t,memory:n,stage:r})=>{let i=w(e.where.condition);return Hn(`exclude`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})}},Vn={include:({model:e,stage:t,where:n})=>{let r=[],i;return i=n?b([...e.elements()],K(n)):P(it(e.roots(),e=>(e.onlyOneInstance()||r.push(...e.children()),e))),t.addExplicit(i),r.length>1?(t.addConnections(pn([...i,...r])),t.connectWithExisting(r)):t.addConnections(pn(i)),t.connectWithExisting(i),t},exclude:({stage:e,memory:t,where:n})=>{let r=b([...t.elements],K(n));return e.exclude(r),e}};function Hn(e,{expr:t,where:n,...r}){switch(!0){case O.isElementTagExpr(t):case O.isElementKindExpr(t):throw Error(`element kind and tag expressions are not supported in deployment view rules`);case xe.isCustom(t):case O.isCustom(t):case O.isModelRef(t):return;case O.isWhere(t):return An[e]({...r,expr:t,where:n});case xe.isWhere(t):return Bn[e]({...r,expr:t,where:n});case O.isDeploymentRef(t):return Jn[e]({...r,expr:t,where:n});case O.isWildcard(t):return Vn[e]({...r,expr:t,where:n});case xe.isDirect(t):return Ln[e]({...r,expr:t,where:n});case xe.isInOut(t):return zn[e]({...r,expr:t,where:n});case xe.isOutgoing(t):return Pn[e]({...r,expr:t,where:n});case xe.isIncoming(t):return jn[e]({...r,expr:t,where:n});default:L(t)}}function W(e,{stage:t,memory:n},r,i=()=>!0){if(e.size===0)return t;let a=b(n.connections,y(e=>i(e)),y(t=>nt(t.relations.model,e)),_(t=>t.update({deployment:null,model:I(t.relations.model,e)})),G(r),y(e=>e.nonEmpty()));return a.length===0?t:t.excludeConnections(a)}function Un(e,t){return G(e,t).nonEmpty()}function G(...e){if(e.length===1)return t=>G(t,e[0]);let[n,r]=e;return r===null?n:t(n)?n.map(e=>G(e,r)).filter(e=>e.nonEmpty()):n.update({model:new Set([...n.relations.model.values()].filter(e=>r(Kn(n)(e)))),deployment:new Set([...n.relations.deployment.values()].filter(e=>r(Kn(n)(e))))})}function K(...e){if(e.length===1){let t=e[0];return t==null?e=>e:e=>e.filter(e=>t(Gn(e,e)))}let[n,r]=e;return t(n)?r==null?n:n.filter(e=>r(Gn(e,e))):r?.(Gn(n,n))??!0}function Wn(e,t){return t?b(e,y(e=>Un(e,t))):e}function Gn(e,t){if(Et(e)){let n=Tt(t)&&At(t)?t:null;return{kind:e.kind,tags:[...e.tags,...n?.tags??[]],metadata:e.metadata}}if(vt(e))return te(e.element,[`tags`,`kind`,`metadata`]);if(At(e))return{kind:e.element.kind,tags:[...e.tags,...e.element.tags],metadata:e.metadata};if(kt(e))return te(e,[`tags`,`kind`,`metadata`]);L(e)}function Kn(e){return t=>({tags:t.tags,kind:t.kind,metadata:t.metadata,source:Gn(t.source,e.source),target:Gn(t.target,e.target)})}function qn(e){let t=new Set;for(let n of e.descendingSiblings())t.add(n);return t}const Jn={include:e=>{let{expr:t,where:n}=e,r=e.model.element(t.ref.deployment);if(At(r))return K(r,n)&&(e.stage.addExplicit(r),e.stage.connectWithExisting(r)),e.stage;switch(!0){case t.selector===`expanded`:Xn(r,e);break;case t.selector===`children`:Yn(r,e);break;case t.selector===`descendants`:Zn(r,e);break;default:K(r,n)&&(e.stage.addExplicit(r),e.stage.connectWithExisting(r))}return e.stage},exclude:({expr:e,stage:t,memory:n,where:r})=>{let i=hn(e),a=b([...n.elements],y(i),K(r));return t.exclude(a),t}};function Yn(e,{stage:t,where:n}){let r=K([...e.children()],n);r.length!==0&&(t.addImplicit(e),t.addConnections(pn(r)),t.connectWithExisting(r),t.addExplicit(r))}function Xn(e,{memory:t,stage:n,where:r}){n.addImplicit(e),n.connectWithExisting(e);let i=K([...e.children()],r),a=!1;for(let e of i)if(H(e,t.elements).length>0){a=!0;break}a&&(n.connectWithExisting(i,`in`),n.addConnections(pn(i)),n.connectWithExisting(i,`out`)),n.addImplicit(i),n.connections.length>0&&n.addExplicit(e)}function Zn(e,{stage:t,where:n}){let r=e=>{let i=[];for(let t of e.children())t.isDeploymentNode()&&i.push(...r(t)),K(t,n)&&i.push(t);return t.connectWithExisting(i,`in`),t.addConnections(pn(i)),t.addImplicit(i),i},a=r(e);if(a.length===0)return;t.connectWithExisting(a,`out`);let o=Qn(t);b(a,y(e=>o.has(e)),i(e=>t.addExplicit(e)))}function Qn(e){return b(e.mergedConnections(),Tn,Dn,re((e,t)=>(e.add(t.source),e.add(t.target),e),new Set))}var $n=class e{static for(t){return new e(t)}constructor(e){this.memory=e}step1CleanConnections(e){if(e.connections.length<2)return e;let t=b(e.connections,Tn,Dn),n=xt(e.connections,t);if(n.length===0)return e;let r=e.stageExclude({});return r.excludeConnections(n,!0),r.commit()}step2ProcessImplicits(e){let t=R(this.memory.elements,e.elements),n=R(e.final,this.memory.explicits),r=new lt.default(()=>new Set);for(let t of e.connections)if(t.boundary)for(let e of t.relations.model)r.get(e).add(t.boundary);for(let[e,i]of r)if(!(i.size<2))for(let e of i)t.delete(e)&&n.add(e);let a=new Set(n),o=e=>{for(let t of a)if(e===t||j(e,t))return!0;return!1};return b(F(t,a),A(e=>e.isDeploymentNode()),P(),Xe,i(e=>{let t=[...e.children()].filter(o).length;if(t>=2){n.add(e);return}t===1&&at(e.siblings(),o)&&n.add(e)})),e.update({final:n})}step3ProcessBoundaries(e){let t=new Set;for(let n of e.connections)n.boundary&&t.add(n.boundary);let n=qt(e,`final`),r=e.stageExclude({}),i=r=>!(t.has(r)||e.explicits.has(r)||n.hasInOut(r)||n.root.has(r)),a=S([...n.root]);a&&!e.explicits.has(a)&&r.exclude(a);for(let t of e.final){let e=S(n.children(t));e&&!n.hasInOut(e)&&i(t)&&r.exclude(t)}return r.isDirty()?r.commit():e}commit(){let e=this.step1CleanConnections(this.memory),t=this.step2ProcessImplicits(e);return this.step3ProcessBoundaries(t)}};function er(e,t){let n=kn.empty();for(let r of t)if(He(r)){let t=`include`in r?`include`:`exclude`,i=r.include??r.exclude;for(let r of i){let i=t===`include`?n.stageInclude(r):n.stageExclude(r);i=Hn(t,{expr:r,model:e,stage:i,memory:n,where:null})??i,n=i.commit()}}return $n.for(n).commit()}function tr(e,{docUri:t,rules:n,...r}){let i=er(e.deployment,n),a=xn(e,i),o=bn(i.connections);Lt(a,o);let c=Ht({nodes:a,edges:o}),l=Sn(n,c.nodes),u=s(n,je),d=Pt(l);return Ut({...r,[Ce]:`computed`,[Be]:`deployment`,autoLayout:{direction:u?.direction??`TB`,...u?.nodeSep&&{nodeSep:u.nodeSep},...u?.rankSep&&{rankSep:u.rankSep}},edges:c.edges,nodes:_(l,e=>(e.icon===`none`&&delete e.icon,e)),...d.length>0&&{notation:{nodes:d}}})}function nr(e){return t=>Ne(t)?t.groupRules.flatMap(nr(e)):He(t)&&`include`in t?t.include.filter(e):[]}function rr(e,t){let n=e.flatMap(nr(E.isCustom));if(n.length===0)return t;let r=[...t];for(let{custom:{expr:e,...t}}of n){let{border:n,opacity:i,multiple:a,iconColor:s,iconSize:c,iconPosition:l,padding:d,size:f,textSize:p,...m}=ye(t,u),h=T({border:n,opacity:i,multiple:a,iconColor:s,iconSize:c,iconPosition:l,padding:d,size:f,textSize:p}),g=!o(h),_=!o(m),v=V(e);r.forEach((e,t)=>{Ee(e)||!v(e)||(_&&(e={...e,...m,isCustomized:!0}),g&&(e={...e,isCustomized:!0,style:{...e.style,...h}}),r[t]=e)})}return r}function ir(e,t){return e.reduce((e,n)=>{if(ze(n)){let r=t.predicates[n.predicateId];return u(r)?e:e.concat(r)}if(Te(n)){let r=t.styles[n.styleId];return u(r)?e:e.concat(r)}return e.push(n),e},[])}function ar(e,t){return e.reduce((e,n)=>{if(ze(n)){let r=t.dynamicPredicates[n.predicateId];return u(r)?e:e.concat(r)}if(Te(n)){let r=t.styles[n.styleId];return u(r)?e:e.concat(r)}return e.push(n),e},[])}function or(e,t){let n=new Set;for(let r of t)if(He(r))for(let t of r.include){let r=V(t);for(let t of e.elements())r(t)&&n.add(t)}return n}const sr=e=>{if(Pe(e)){let t=[],n=[];for(let r of e.__parallel)if(Le(r)){let[e,...i]=r.__series;t.push(e),n.push(...i)}else t.push(r);return[...t,...n]}return Le(e)?[...e.__series]:e};function cr(e,t){let n=[],r=(...[e,t])=>{if(!n.includes(e)){let r=n.indexOf(t);if(r>0){n.splice(r,0,e);return}else n.push(e)}n.includes(t)||n.push(t)};for(let i of c(t,sr)){let t=e.element(i.source),a=e.element(i.target),o=n.indexOf(t),s=n.indexOf(a);o>=0&&s>=0||(i.isBackward?r(a,t):r(t,a))}return new Set(n)}function lr(e,t,n){let r=yt(e,t,`directed`).flatMap(e=>[...e.relations]).sort(Qe);if(!Ge(r))return{};if(r.length===1){let e=r[0];return T({title:e.title??void 0,kind:e.kind??void 0,tags:e.tags,relations:[e.id],navigateTo:e.$relationship.navigateTo,color:e.$relationship.color,line:e.$relationship.line,technology:e.technology??void 0,description:e.$relationship.description??void 0})}let i=b(r,c(e=>e.tags),oe()),a=m(i,1)?i:void 0,o=_(r,e=>e.id),s=fe(r).$relationship.navigateTo;s===n&&(s=void 0),s||=b(r,c(e=>e.$relationship.navigateTo&&e.$relationship.navigateTo!==n?e.$relationship.navigateTo:[]),oe(),S());let l=b(r,re((e,{title:t,technology:n,$relationship:r})=>(f(t)&&e.title.add(t),f(r.color)&&e.color.add(r.color),f(r.line)&&e.line.add(r.line),f(r.kind)&&e.kind.add(r.kind),f(n)&&e.technology.add(n),f(r.description)&&!e.description.some(v(r.description))&&e.description.push(r.description),e),{kind:new Set,color:new Set,line:new Set,title:new Set,technology:new Set,description:[]}));return T({tags:a??void 0,relations:o,navigateTo:s,kind:S([...l.kind]),title:S([...l.title]),color:S([...l.color]),line:S([...l.line]),technology:S([...l.technology]),description:S(l.description)})}var ur=class{steps=[];constructor(e,t){this.model=e,this.view=t}compute(){let{docUri:e,rules:t,steps:n,...r}=this.view,i=ar(t,this.model.globals),a=or(this.model,i),o=cr(this.model,n),c=b(R(I(a,o),o,a),P(),Ye),l=c.reduce((e,t,n,r)=>{for(let i=n+1;i<r.length;i++){let n=r[i];if(j(t,n)){e.push(t);break}}return e},[]),u=(e,t,n)=>{if(Le(e)){for(let r of e.__series)t=u(r,t,n);return t}let r=n?Ae(n,t):Ae(t),{source:i,target:a,title:o,isBackward:s,navigateTo:d,notation:p,...m}=e,h=this.model.element(i),g=c.indexOf(h);N(g>=0,`Source ${i} not found`);let _=this.model.element(a),v=c.indexOf(_);N(v>=0,`Target ${a} not found`),(l.includes(h)||l.includes(_))&&console.error(`Step ${h.id} -> ${_.id} because it involves a compound`);let{title:y,relations:ee,navigateTo:te,...ne}=lr(h,_,this.view.id),re=f(d)&&d!==this.view.id?d:te,b=e.kind?this.model.specification.relationships[e.kind]:void 0;return this.steps.push(T({...ne,...!e.technology&&!ne.technology&&b?.technology&&{technology:b.technology},...!e.color&&!ne.color&&b?.color&&{color:b.color},...!e.line&&!ne.line&&b?.line&&{line:b.line},...!e.head&&b?.head&&{head:b.head},...!e.tail&&b?.tail&&{tail:b.tail},...m,id:r,source:h,target:_,navigateTo:re,title:o??y,relations:ee??[],isBackward:g>v})),t+1},d=1;for(let e of n){if(Pe(e)){let t=1;for(let n of e.__parallel)t=u(n,t,d);d++;continue}d=u(e,d)}let p=ln(this.model.$styles,c.map(cn)),m=this.model.$styles.defaults.relationship,h=this.steps.map(({id:e,source:t,target:n,relations:r,title:i,isBackward:a,tags:o,...s})=>{let c=k(p.get(t.id),`Source node ${t.id} not found`),l=k(p.get(n.id),`Target node ${n.id} not found`),u={id:e,parent:tt(t.id,n.id),source:c.id,target:l.id,label:i??null,relations:r,color:m.color,line:m.line,head:m.arrow,tags:o??[],...s};for(a&&(u.dir=`back`);u.parent&&!p.has(u.parent);)u.parent=We(u.parent);c.outEdges.push(u.id),l.inEdges.push(u.id);for(let e of Ue(u.source)){if(e===u.parent)break;p.get(e)?.outEdges.push(u.id)}for(let e of Ue(u.target)){if(e===u.parent)break;p.get(e)?.inEdges.push(u.id)}return u}),g=rr(i,Xt(i,c.map(e=>k(p.get(e.id))))),v=s(i,je),y=Pt(g);return Ut({...r,[Be]:`dynamic`,[Ce]:`computed`,variant:r.variant??`diagram`,autoLayout:{direction:v?.direction??`LR`,...v?.nodeSep&&{nodeSep:v.nodeSep},...v?.rankSep&&{rankSep:v.rankSep}},nodes:_(g,e=>(e.icon===`none`&&delete e.icon,e)),edges:h,...y.length>0&&{notation:{nodes:y}}})}};function dr(e,t){return new ur(e,t).compute()}function fr(e){switch(!0){case C.isCustom(e):return fr(e.customRelation.expr);case C.isWhere(e):{let t=fr(e.where.expr),n=w(e.where.condition);return e=>t(e)&&n({source:{tags:e.source.tags,kind:e.source.kind,metadata:e.source.metadata},target:{tags:e.target.tags,kind:e.target.kind,metadata:e.target.metadata},...e.tags&&{tags:e.tags},...e.kind&&{kind:e.kind},...e.metadata&&{metadata:e.metadata}})}case C.isDirect(e):{let t=V(e.source),n=V(e.target);return r=>t(r.source)&&n(r.target)||!!e.isBidirectional&&t(r.target)&&n(r.source)}case C.isInOut(e):{let t=V(e.inout);return e=>t(e.source)||t(e.target)}case C.isIncoming(e):{let t=V(e.incoming);return e=>t(e.target)}case C.isOutgoing(e):{let t=V(e.outgoing);return e=>t(e.source)}default:L(e)}}function pr(e,t,n){let r=e.flatMap(nr(C.isCustom)),i=Array.from(n);if(r.length===0||i.length===0)return i;for(let{customRelation:{expr:e,title:n,description:a,notes:o,...s}}of r){let r=a?{description:Re(a)}:{},c=o?{notes:Re(o)}:{},l=ye(s,u),d=fr(e);i.forEach((e,a)=>{let o,s;for(let n of t)if(n.id===e.source&&(o=n),n.id===e.target&&(s=n),o&&s)break;!o||!s||d({source:o,target:s,...te(e,[`kind`,`tags`])})&&(i[a]={...e,...l,...r,...c,label:n??e.label,isCustomized:!0})})}return i}function mr(e){return b([...e],ft,re((e,t,n,r)=>{let i=Nt(r,t),a=R(...i.map(ce(`relations`))),o=I(t.relations,a);if(i.length>0&&(o=R(o,t.directRelations)),jt(r,t.reversed())&&(o=R(o,t.directRelations)),o.size<t.relations.size){let e=r.some(dt(t.source)),n=r.some(dt(t.target));e&&(o=R(o,z(A(t.relations,pt(t.source))))),n&&(o=R(o,z(A(t.relations,Mt(t.target)))))}return o.size>0&&e.push(t.update(o)),e},[]))}var hr=class e{static for(t){return new e(t)}constructor(e){this.memory=e}step1CleanConnections(e){if(e.connections.length<2)return e;let t=mr(e.connections);if(t.length===0)return e;let n=e.stageExclude({});return n.excludeConnections(t,!0),n.commit()}step2ProcessImplicits(e){let t=R(this.memory.elements,e.elements),n=R(e.final,this.memory.explicits),r=new Set(n),a=e=>{for(let t of r)if(e===t||j(e,t))return!0;return!1};return b(F(t,r),P(),Xe,i(e=>{let t=[...e.children()].filter(a).length;if(t>=2){n.add(e);return}t===1&&at(e.siblings(),a)&&n.add(e)})),e.update({final:n})}step3ProcessBoundaries(e){let t=new Set;for(let n of e.connections)n.boundary&&n.boundary!==n.source&&n.boundary!==n.target&&t.add(n.boundary);let n=qt(e,`final`),r=e.stageExclude({}),i=r=>!(t.has(r)||e.explicits.has(r)||n.hasInOut(r)||n.root.has(r)),a=S([...n.root]);a&&!e.explicits.has(a)&&r.exclude(a);for(let t of e.final){let e=S(n.children(t));e&&!n.hasInOut(e)&&i(t)&&r.exclude(t)}return r.isDirty()?r.commit():e}commit(){let e=this.step1CleanConnections(this.memory),t=this.step2ProcessImplicits(e);return this.step3ProcessBoundaries(t)}};const{findConnection:gr,findConnectionsBetween:q,findConnectionsWithin:J}=Dt;function Y(e,t){switch(!0){case E.isElementKindExpr(t):return[...A(e.elements(),e=>t.isEqual===(e.kind===t.elementKind))];case E.isElementTagExpr(t):return[...A(e.elements(),e=>t.isEqual===e.tags.includes(t.elementTag))];case t.selector===`expanded`:{let n=e.element(D.flatten(t.ref));return[n,...n.children()]}case t.selector===`children`:case t.selector===`descendants`:{let n=e.element(D.flatten(t.ref)),r=t.selector===`children`?P(n.children()):P(n.descendants());return r&&r.length>0?r:[n]}case E.isModelRef(t):return[e.element(D.flatten(t.ref))];default:L(t)}}function _r(e,t){if(t.isEmpty()||e.length===0)return e;let n=x(e.map(e=>Ke(e))),r=P(A(t.elements,t=>!e.includes(t)&&n(t)));return[...e,...r]}function vr(e,{memory:t,model:n}){let r=Y(n,e);return E.isModelRef(e)?e.selector===`descendants`?r:_r(r,t):r}const yr={include:({expr:e,model:t,stage:n,where:r})=>{let i=t.element(D.flatten(e.ref));r(i)&&(n.addExplicit(i),n.connectWithExisting(i));let a=[...i.children()].filter(r),o=[];for(let e of a)n.addImplicit(e),n.connectWithExisting(e)&&o.push(e);return n.addConnections(J(o)),n},exclude:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(Y(t,e));return n.exclude(i),n}},br={include:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(Y(t,e));if(i.length!==0)return n.addExplicit(i),n.connectWithExisting(i),n.addConnections(J(i)),n},exclude:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(Y(t,e));return n.exclude(i),n}},xr={include:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(Y(t,e));if(i.length!==0)return n.addExplicit(i),n.connectWithExisting(i),n.addConnections(J(i)),n},exclude:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(Y(t,e));return n.exclude(i),n}},X=()=>!0,Sr=e=>e;function Cr(e){return e.reduce((e,t)=>{let n=[...t.relations];N(m(n,1),`Edge must have at least one relation`);let r=t.source.$model.$styles.defaults,i=t.source.id,a=t.target.id,{title:o,color:s=r.relationship.color,line:c=r.relationship.line,head:l=r.relationship.arrow,...u}=dn(n.map(e=>e.$relationship),S(y(n,e=>e.source.id===i&&e.target.id===a))?.$relationship),d=T({id:t.id,parent:t.boundary?.id??null,source:i,target:a,label:o??null,relations:n.map(e=>e.id),color:s,line:c,head:l,...u});return e.push(d),e},[])}function wr(e,t){return ln(e.$styles,[...t.final].map(cn),t.groups)}const Z=E.isWildcard,Tr=(e,t)=>e.isAncestorOf(t)||e.isDescendantOf(t),Er={include:({expr:{source:e,target:t,isBidirectional:n=!1},memory:r,model:i,stage:a,where:o,filterWhere:s})=>{let l=Z(e),u=Z(t),d=[];switch(!0){case l&&u&&r.isEmpty()&&o!==X:{let e=b(i.relationships(),A(o),P(),_(e=>new St(e.source,e.target,new Set([e]))));return a.addConnections(e),a}case l&&u&&!r.isEmpty()&&o!==X:d.push(...J(r.elements));break;case l&&u:d.push(...J(i.roots()));break;case!l&&u&&o!==X:{let t=b(Y(i,e),c(e=>b(e,le(he(n===!0),{onTrue:e=>R(e.allIncoming,e.allOutgoing),onFalse:e=>e.allOutgoing}),A(o),$e(),P(),_e(t=>t.source===e),([t,n])=>ue(b(t,y(t=>!Tr(e,t.target)),_(t=>new St(e,t.target,new Set([t])))),b(n,y(t=>!Tr(e,t.source)),_(t=>new St(t.source,e,new Set([t]))))))));return a.addConnections(t),a}case!l&&u:{let[t,a]=Dr(e,{memory:r,model:i}),o=n?`both`:`directed`;for(let e of t)d.push(...q(e,a,o));break}case l&&!u&&o!==X:{let e=b(Y(i,t),c(e=>b(e,le(he(n===!0),{onTrue:e=>R(e.allIncoming,e.allOutgoing),onFalse:e=>e.allIncoming}),A(o),P(),_e(t=>t.target===e),([t,n])=>ue(b(n,y(t=>!Tr(e,t.target)),_(t=>new St(e,t.target,new Set([t])))),b(t,y(t=>!Tr(e,t.source)),_(t=>new St(t.source,e,new Set([t]))))))));return a.addConnections(e),a}case l&&!u:{let[e,a]=Dr(t,{memory:r,model:i}),o=n?`both`:`directed`;for(let t of a)d.push(...q(t,e,o));break}default:{N(!Z(e),`Inference failed - source must be not a wildcard`),N(!Z(t),`Inference failed - target must be not a wildcard`);let a=vr(e,{memory:r,model:i}),o=vr(t,{memory:r,model:i}),s=n?`both`:`directed`;for(let e of a)d.push(...q(e,o,s))}}return a.addConnections(s(d)),a},exclude:({expr:{source:e,target:t,isBidirectional:n},model:r,memory:i,stage:a,where:o})=>{let s=Z(e),l=Z(t),u;switch(!0){case s&&l:u=b(i.connections,c(ae(ce(`relations`),A(o),P())),z());break;case!s&&l:u=b(Y(r,e),c(e=>b(e,le(he(n===!0),{onTrue:e=>R(e.allIncoming,e.allOutgoing),onFalse:e=>e.allOutgoing}),A(o),P())),z());break;case s&&!l:u=b(Y(r,t),c(e=>b(e,le(he(n===!0),{onTrue:e=>R(e.allIncoming,e.allOutgoing),onFalse:e=>e.allIncoming}),A(o),P())),z());break;default:{N(!Z(e),`Inference failed - source must be not a wildcard`),N(!Z(t),`Inference failed - target must be not a wildcard`);let i=Y(r,e),a=Y(r,t),s=new Set;for(let e of i)for(let t of a)Je(e,t)||(s=R(s,I(e.allOutgoing,t.allIncoming),n?I(t.allOutgoing,e.allIncoming):new Set));u=z(A(s,o))}}return a.excludeRelations(u),a}};function Dr(e,{memory:t,model:n}){let r=Y(n,e);if(!m(r,1))return[[],[]];if(E.isModelRef(e)){let i=P(n.element(D.flatten(e.ref)).ascendingSiblings());return[_r(r,t),_r(i,t)]}return[r,b(r,_(e=>e.ascendingSiblings()),rt(),$e(),P(),e=>_r(e,t))]}const Or={include:({expr:e,scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=e.incoming,s=[];if(E.isWildcard(o)){if(!t)return;for(let e of t.ascendingSiblings())s.push(...gr(e,t,`directed`))}else{let e=vr(o,{memory:r,model:n}),t=[...r.elements];t.length===0&&t.push(...oe(e.flatMap(e=>[...e.ascendingSiblings()])));let i=kr(n,o);for(let n of t)s.push(...q(n,e,`directed`).filter(i))}return i.addConnections(a(s)),i},exclude:({expr:{incoming:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(E.isWildcard(e)){if(!n)return;a.push(...n.allIncoming)}else{let n=Y(t,e);a.push(...n.flatMap(e=>[...e.allIncoming]))}return r.excludeRelations(new Set(a.filter(i))),r}};function kr(e,t){switch(!0){case E.isElementKindExpr(t):case E.isElementTagExpr(t):{let e=V(t);return t=>e(t.target)}case E.isModelRef(t)&&t.selector===`children`:{let n=D.flatten(t.ref);return x([...e.children(n)].map(e=>B.isIncoming(e.id)))}case E.isModelRef(t)&&t.selector===`descendants`:{let n=D.flatten(t.ref);return x([B.isInside(n),...[...e.children(n)].map(e=>B.isIncoming(e.id))])}case E.isModelRef(t)&&t.selector===`expanded`:{let e=D.flatten(t.ref);return x([B.isIncoming(e),B.isInside(e)])}case E.isModelRef(t):{let e=D.flatten(t.ref);return B.isIncoming(e)}default:L(t)}}const Ar={include:({expr:{inout:e},scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=[];if(E.isWildcard(e)){if(!t)return;o.push(...q(t,t.ascendingSiblings()))}else{let t=vr(e,{memory:r,model:n}),i=[...r.elements];i.length===0&&(i=oe(t.flatMap(e=>P(e.ascendingSiblings()))));for(let e of t)o.push(...q(e,i))}return i.addConnections(a(o)),i},exclude:({expr:{inout:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(E.isWildcard(e)){if(!n)return;a.push(...n.allOutgoing),a.push(...n.allIncoming)}else{let n=Y(t,e);a.push(...n.flatMap(e=>[...e.allOutgoing,...e.allIncoming]))}return r.excludeRelations(z(a.filter(i))),r}},jr={include:({expr:e,scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=e.outgoing,s=[];if(E.isWildcard(o)){if(!t)return;s.push(...q(t,t.ascendingSiblings(),`directed`))}else{let e=vr(o,{memory:r,model:n}),t=[...r.elements];t.length===0&&t.push(...oe(e.flatMap(e=>[...e.ascendingSiblings()])));let i=Mr(n,o);for(let n of e)s.push(...q(n,t,`directed`).filter(i))}return i.addConnections(a(s)),i},exclude:({expr:{outgoing:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(E.isWildcard(e)){if(!n)return;a.push(...n.allOutgoing)}else{let n=Y(t,e);a.push(...n.flatMap(e=>[...e.allOutgoing]))}return r.excludeRelations(z(a.filter(i))),r}};function Mr(e,t){switch(!0){case E.isElementKindExpr(t):case E.isElementTagExpr(t):{let e=V(t);return t=>e(t.source)}case E.isModelRef(t)&&t.selector===`children`:{let n=D.flatten(t.ref);return x([...e.children(n)].map(e=>B.isOutgoing(e.id)))}case E.isModelRef(t)&&t.selector===`descendants`:{let n=D.flatten(t.ref);return x([B.isInside(n),...[...e.children(n)].map(e=>B.isOutgoing(e.id))])}case E.isModelRef(t)&&t.selector===`expanded`:{let e=D.flatten(t.ref);return x([B.isOutgoing(e),B.isInside(e)])}case E.isModelRef(t):{let e=D.flatten(t.ref);return B.isOutgoing(e)}default:L(t)}}const Nr={include:({scope:e,model:t,stage:n,memory:r,where:i})=>{if(!e){let e=i===X?[...t.roots()]:P(A(t.elements(),i));if(e.length===0)return;let[r,a]=_e(e,e=>!e.imported);return n.addExplicit(r),n.addImplicit(a),n.addConnections(J(e)),n.connectWithExisting(e),n}let a=P(A(e.children(),i)),o=a.length>0;if(!o){let t=q(e,e.siblings()),r=e.parent;t.length===0&&r&&n.addExplicit(r),a.push(e)}n.addExplicit(e);let s=z([...r.elements,...e.descendingSiblings()]);for(let e of s)n.addConnections(q(e,a,`directed`));o&&(n.addConnections(J(a)),n.addExplicit(a));for(let e of a)n.addConnections(q(e,s,`directed`));return n},exclude:({scope:e,memory:t,stage:n,where:r})=>r===X?e?(n.exclude([e,...e.descendants()]),n):an.empty(t.scope).stageExclude(n.expression):(n.exclude(y([...t.elements],r)),n)};function Pr(e,t,n){switch(!0){case E.isCustom(e):return t===`include`?Pr(e.custom.expr,t,n):n.stage;case E.isWhere(e):{let r=w(e.where.condition),i=e=>y(e,r);return Pr(e.where.expr,t,{...n,where:r,filterWhere:i})}case E.isModelRef(e)&&e.selector===`expanded`:return yr[t]({...n,expr:e})??n.stage;case E.isWildcard(e):return Nr[t]({...n,expr:e})??n.stage;case E.isElementKindExpr(e):case E.isElementTagExpr(e):return br[t]({...n,expr:e})??n.stage;case E.isModelRef(e):return xr[t]({...n,expr:e})??n.stage;default:L(e)}}function Fr(e,t,n){switch(!0){case C.isCustom(e):return t===`include`?Fr(e.customRelation.expr,t,n):n.stage;case C.isWhere(e):{let r=w(e.where.condition),i=e=>new Set(y([...e],r)),a=e=>b(e,_(e=>new St(e.source,e.target,i(e.relations))),y(e=>e.nonEmpty()));return Fr(e.where.expr,t,{...n,where:r,filterWhere:a})}case C.isInOut(e):return Ar[t]({...n,expr:e})??n.stage;case C.isDirect(e):return Er[t]({...n,expr:e})??n.stage;case C.isOutgoing(e):return jr[t]({...n,expr:e})??n.stage;case C.isIncoming(e):return Or[t]({...n,expr:e})??n.stage;default:L(e)}}function Ir(e,t,n){let r={model:e,scope:t.scope,where:X,filterWhere:Sr};for(let i of n){if(Ne(i)){t=Ir(e,on.enter(t,i),i.groupRules),N(t instanceof on,`processPredicates must return ActiveGroupMemory`),t=t.leave();continue}if(He(i)){let e=`include`in i?`include`:`exclude`,n=i.include??i.exclude;for(let i of n){let n=e===`include`?t.stageInclude(i):t.stageExclude(i);switch(!0){case Se.isFqnExpr(i):n=Pr(i,e,{...r,stage:n,memory:t})??n;break;case Se.isRelationExpr(i):n=Fr(i,e,{...r,stage:n,memory:t})??n;break;default:L(i)}t=n.commit()}}}return t}function Lr(e,t,n){return t=Ir(e,t,n),hr.for(t).commit()}function Rr(e,{docUri:t,rules:n,...r}){let i=ir(n,e.globals),a=r.viewOf?e.asComputed.element(r.viewOf):null,o=Lr(e,an.empty(a),i);o.isEmpty()&&a&&(o=o.update({final:new Set([a])})),o=Br(o);let c=wr(e,o),l=Cr(o.connections);Lt(c,l);let u=Ht({nodes:c,edges:l}),d=rr(i,Xt(i,u.nodes)),f=s(i,je),p=Pt(d),m=zr(i,d);return Ut({...r,_stage:`computed`,autoLayout:{direction:f?.direction??`TB`,...f?.nodeSep&&{nodeSep:f.nodeSep},...f?.rankSep&&{rankSep:f.rankSep}},edges:pr(i,d,u.edges),nodes:_(d,e=>(e.icon===`none`&&delete e.icon,e)),...p.length>0&&{notation:{nodes:p}},...m.length>0&&{ranks:m}})}function zr(e,t){let n=[];for(let r of e){if(!Ie(r)||r.targets.length===0)continue;let e=b(t,y(x(r.targets.map(V))),_(e=>e.id));m(e,1)&&n.push({type:r.rank,nodes:e})}return n}function Br(e){if(e.groups.length===0)return e;let t=new lt.default(()=>new Set),n=new Map,r=e=>{for(let r of e.ancestors()){let i=n.get(r);if(i)return n.set(e,i),t.get(i).add(e),!0}return!1},a=e=>{for(let r of e.descendants(`asc`)){let i=n.get(r);if(i)return n.set(e,i),t.get(i).add(e),!0}return!1};if(b(Ye([...e.explicitFirstSeenIn.keys()]),i(i=>{if(!r(i)){let r=k(e.explicitFirstSeenIn.get(i));n.set(i,r),t.get(r).add(i)}})),b(Ye([...e.lastSeenIn.keys()]),y(e=>!n.has(e)),i(i=>{if(r(i)||a(i))return;let o=k(e.lastSeenIn.get(i));n.set(i,o),t.get(o).add(i)})),t.size===0)return e;let o=e.groups.map(e=>{let n=t.get(e.id);return n?e.update(n):e});return e.update({groups:o})}function Vr(e,t){switch(!0){case Oe(e):return Rr(t,e);case Fe(e):return tr(t,e);case ke(e):return dr(t,e);default:L(e)}}function Hr(e,t){try{return{isSuccess:!0,view:Vr(e,t)}}catch(e){return{isSuccess:!1,error:e instanceof Error?e:Error(`Unknown error: ${e}`),view:void 0}}}function Ur(e){let t=mt.create(e),{views:r,_stage:i,...a}=e,o=n(r,e=>Vr(e,t));return{[Ce]:`computed`,...a,views:o}}function Wr(e){return mt.create(Ur(e))}const Q=e=>e;function $(e){if(!se(e))return e;if(e===`*`)return Q({wildcard:!0});if(e.startsWith(`->`))return e.endsWith(`->`)?Q({inout:$(e.replace(/->/g,``).trim())}):Q({incoming:$(e.replace(`-> `,``))});if(e.endsWith(` ->`))return Q({outgoing:$(e.replace(` ->`,``))});if(e.includes(` <-> `)){let[t,n]=e.split(` <-> `);return Q({source:$(t),target:$(n),isBidirectional:!0})}if(e.includes(` -> `)){let[t,n]=e.split(` -> `);return Q({source:$(t),target:$(n)})}return e.endsWith(`._`)?Q({ref:{model:e.replace(`._`,``)},selector:`expanded`}):e.endsWith(`.**`)?Q({ref:{model:e.replace(`.**`,``)},selector:`descendants`}):e.endsWith(`.*`)?Q({ref:{model:e.replace(`.*`,``)},selector:`children`}):Q({ref:{model:e}})}export{Vr as a,Lt as c,Hr as i,Wr as n,Rr as o,Ur as r,Ht as s,$ as t};
|
|
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 C,w as he,x as ge,y as w,z as _e}from"./libs/remeda.mjs";import{$t as ve,At as T,Bt as E,Cn as D,Dt as O,Et as ye,G as k,J as A,Kt as be,Mt as j,Nt as xe,O as M,On as Se,Rt as Ce,Sn as N,Tt as we,U as Te,Ut as Ee,Vt as De,W as P,Xt as F,Y as I,Yt as L,_t as Oe,b as ke,cn as R,d as Ae,dt as je,et as Me,fn as Ne,g as Pe,h as Fe,hn as Ie,ht as Le,in as Re,kn as z,kt as ze,l as Be,ln as Ve,lt as He,n as Ue,nn as We,o as Ge,p as Ke,pn as qe,q as B,r as Je,rn as Ye,s as Xe,tt as Ze,u as Qe,un as $e,vt as et,wn as V,y as tt,yn as nt,zt as H}from"./types.mjs";import{c as rt,t as it}from"./libs/mnemonist.mjs";import{A as at,C as ot,D as st,E as ct,M as U,N as lt,O as ut,T as dt,_ as ft,c as pt,d as mt,f as ht,g as gt,h as _t,j as vt,m as yt,n as bt,o as xt,p as St,q as Ct,r as wt,t as Tt,v as Et,w as Dt,y as Ot}from"./model.mjs";import{r as kt}from"./manual-layout.mjs";import{t as At}from"./libs/graphology.mjs";import{n as jt,t as Mt}from"../utils/graphology/index.mjs";function Nt(e,t){let n=[],r=e.parent;for(;r;){let e=D(t.get(r),`Parent node ${r} not found`);n.push(e),r=e.parent}return n}function Pt(e,t){for(let r of t){let t=e.get(r.source),i=e.get(r.target);N(t,`Source node ${r.source} not found`),N(i,`Target node ${r.target} not found`),t.outEdges.push(r.id),i.inEdges.push(r.id);let a=Nt(t,e),o=Nt(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 W(e){if(P.isCustom(e))return W(e.custom.expr);if(P.isWhere(e)){let t=W(e.where.expr),n=M(e.where.condition);return e=>t(e)&&n(e)}if(P.isElementKindExpr(e))return e.isEqual?t=>t.kind===e.elementKind:t=>t.kind!==e.elementKind;if(P.isElementTagExpr(e))return e.isEqual?({tags:t})=>t.includes(e.elementTag):({tags:t})=>!t.includes(e.elementTag);if(P.isWildcard(e))return()=>!0;if(P.isModelRef(e)){let t=I.flatten(e.ref);if(e.selector===`expanded`)return e=>e.id===t||Ne(e.id)===t;if(e.selector===`descendants`||e.selector===`children`){let e=t+`.`;return t=>t.id.startsWith(e)}return e=>e.id===t}V(e)}function Ft(e){return function t(n){switch(!0){case k.isCustom(n):return t(n.customRelation.expr);case k.isWhere(n):{let e=t(n.where.expr),r=M(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 k.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 k.isInOut(n):{let t=e(n.inout);return e=>t(e.source)||t(e.target)}case k.isIncoming(n):{let t=e(n.incoming);return e=>t(e.target)}case k.isOutgoing(n):{let t=e(n.outgoing);return e=>t(e.source)}default:V(n)}}}const It=Ft(W);function Lt(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 Rt(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 zt(e){let t=Lt([...e.nodes.values()]),n=[...e.edges];if(t.length<2||n.length===0)return{nodes:t,edges:n};let i=t=>D(e.nodes.get(t)),a=new At({multi:!0,allowSelfLoops:!0,type:`directed`}),[o,s]=C(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,jt.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(Nt(s,e.nodes),ne(e=>e.inEdges.includes(t.id)),r(e=>{a.mergeNode(e.id),(0,jt.default)(a,t.source,e.id)||a.mergeDirectedEdge(t.source,e.id),(0,jt.default)(a,e.id,t.target)||a.mergeDirectedEdge(e.id,t.target)})),n.parent){let e=i(n.parent);a.mergeNode(e.id),(0,jt.default)(a,e.id,n.id)||a.mergeDirectedEdge(e.id,n.id),s.parent&&s.parent!==n.parent&&((0,jt.default)(a,e.id,s.parent)||a.mergeDirectedEdge(e.id,s.parent))}for(let{edge:e}of s)l(e);N(c.length===n.length,`Not all edges were added to the graph`);let u=(0,Mt.topologicalSort)(a),d=[],f=t.slice();for(let e of u){let t=f.findIndex(t=>t.id===e);N(t>=0,`Node "${e}" not found`),d.push(...f.splice(t,1))}return f.length>0&&d.length>0&&(d=d.flatMap(e=>{if(f.length===0)return e;let n=t.slice(0,t.indexOf(e)).filter(e=>f.includes(e));return n.length>0?(f=f.filter(e=>!n.includes(e)),[...n,e]):e})),d.push(...f),{nodes:Rt(Lt(d)),edges:c}}function Bt(e){return e.hash=ye({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:He(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})),he(({id:e,...t})=>[e,t])),edges:b(e.edges,g(e=>({id:e.id,source:e.source,target:e.target,label:e.label,description:He(e.description),technology:e.technology??null,dir:e.dir,head:e.head,tail:e.tail,line:e.line})),he(e=>[e.id,{...e}]))}),e}var Vt=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}},Ht=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(F(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(_e(t)&&(N(!this.markedToMoveExplicitToImplicit,`Already marked to move explicits`),this.markedToMoveExplicitToImplicit=t),F(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=O(new Set(this.memory.connections.flatMap(e=>[e.source,e.target])),new Set(e.connections.flatMap(e=>[e.source,e.target])));return t=T(t,e.elements),t=b(t,L(t=>e.explicits.has(t)&&!De(e.final,Ve(t))),E()),t.size>0&&(t=this.filterForMoveToImplicits(t),e.explicits=O(e.explicits,t),e.final=O(e.final,t)),e}removeElements(e){return e.elements=O(e.elements,this.excluded.elements),e.explicits=O(e.explicits,this.excluded.elements),e.final=O(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=O(n,e.explicits),e.final=O(e.final,n),e)}precommit(e){return e}postcommit(e){return N(O(e.explicits,e.elements).size===0,`Explicits must be subset of elements`),N(O(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,...ft(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))}},Ut=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 st([...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(F(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(F(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(F(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]=C(this._connections,t=>e.final.has(t.source));e.connections=this.processConnections(st([...e.connections,...n,...r])),t=new Set(e.connections.flatMap(e=>[e.source,e.target]))}return e.elements=j(e.elements,this._ordered,this.explicits,t,this.implicits),e.explicits=T(e.elements,j(e.explicits,this.explicits)),e.final=T(e.elements,j(e.final,this.explicits,t)),this.memory.update(this.postcommit(e))}};function Wt(e,t=`final`){let n=Ie(H(t===`final`?e.final:e.elements)),r=new Set(e.connections.flatMap(e=>[e.source,e.target])),i=new Set(n),a=new it.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 it.default(()=>[]));return{root:i,connected:r,hasInOut:t=>e.connections.some(U.isAnyInOut(t.id)),parent:e=>a.get(e),children:e=>o.get(e)}}var Gt=class extends Ht{};function Kt(e,t,n){let{shape:i,color:a,icon:o,...s}=e.style,l=!c(s);b(n,v(u(je)),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 qt(e,t){for(let n of e)!ke(n)||n.targets.length===0||Kt(n,S(n.targets.map(W)),t);return t}var Jt=class e{id;viewRule;parent;elements;static kind=Me;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))}},Yt=class extends Ht{excludeRelations(e){return b(this.memory.connections,v(t=>ze(t.relations,e)),r(t=>{this.excludeConnections(t.update(T(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=O(this.memory.explicits,e.explicits);for(let n of t)e.explicitFirstSeenIn.delete(n);let n=O(this.memory.elements,e.elements);for(let t of n)e.lastSeenIn.delete(t);return e}},Xt=class extends Yt{memory;expression;constructor(e,t){super(e,t),this.memory=e,this.expression=t}};const{findConnection:Zt,findConnectionsBetween:Qt}=St;var $t=class extends Ut{connectWithExisting(e,t=`both`){let n=this._connections.length,r=()=>this._connections.length>n;if(!F(e)){if(t===`in`||t===`both`)for(let t of this.memory.elements)this.addConnections(Zt(t,e,`directed`));return(t===`out`||t===`both`)&&this.addConnections(Qt(e,this.memory.elements,`directed`)),r()}let i=[...e];if(t===`in`||t===`both`)for(let e of this.memory.elements)this.addConnections(Qt(e,i,`directed`));if(t===`out`||t===`both`)for(let e of i)this.addConnections(Qt(e,this.memory.elements,`directed`));return r()}addImplicitWithinScope(e){e&&(!this.memory.scope||R(this.memory.scope,e))&&this.addImplicit(e)}processConnections(e){return Te.isRelationExpr(this.expression)||b(e,r(({source:e,target:t,boundary:n})=>{b(fe([...H(e.ancestors()).reverse(),e],[...H(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=O(e.explicits,this.memory.explicits);for(let n of t)e.explicitFirstSeenIn.set(n,`@root`);return e}},en=class extends $t{memory;expression;constructor(e,t){super(e,t),this.memory=e,this.expression=t}postcommit(e){let t=O(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}},tn=class e extends Vt{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 $t(this,e)}stageExclude(e){return new Yt(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)}},nn=class e extends tn{state;scope;stack;static enter(t,n){let r=`@gr${t.groups.length+1}`;if(t instanceof e){let i=rt.default.from([...t.stack].reverse()),a=t.mutableState();return a.groups.push(new Jt(r,n,t.activeGroupId)),i.push(r),new e(a,t.scope,i)}let i=t.mutableState();i.groups.push(new Jt(r,n,null));let a=rt.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 D(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 en(this,e)}stageExclude(e){return new Xt(this,e)}leave(){let t=this.mutableState();return this.stack.pop(),this.stack.peek()?new e(t,this.scope,this.stack):new tn(t,this.scope)}};function rn(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 an(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 z({id:t,title:n,modelRef:t,shape:o,color:i,icon:a,style:s,description:Se(e.$element),tags:[...e.tags],metadata:e.$element.metadata,...r})}function on({defaults:e},t,n){let r=new Map,i=new Map;n?.forEach(({id:t,parent:n,viewRule:a,elements:o})=>{n&&D(r.get(n),`Parent group node ${n} not found`).children.push(t),r.set(t,{id:t,parent:n,kind:Me,title:a.title??``,color:a.color??e.group.color??e.color,shape:`rectangle`,children:[],inEdges:[],outEdges:[],level:0,depth:0,tags:[],style:z({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(Re).forEach(({id:e,...t})=>{let n=Ne(e),a=0,o;for(;n&&(o=r.get(n),!o);)n=Ne(n);let s=t.modelRef??e;if(!o&&i.has(s)){let e=D(i.get(s));o=r.get(e),n=e}o&&(o.children.length==0&&(o.depth=1,rn(o,r)),o.children.push(e),a=o.level+1);let c=z({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,D(r.get(e)))}),t.forEach(({id:e})=>{a.set(e,D(r.get(e)))}),a}function sn(e){let{title:t,description:n=null}=e;return{...t&&{title:t,description:n},...te(e,[`color`,`technology`,`head`,`line`,`tail`,`kind`,`navigateTo`])}}function cn(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=w(n.title)??(n.title.length>1?`[...]`:void 0),i=ie(n.tags),a=z({title:r,description:w(n.description),technology:w(n.technology),kind:w(n.kind),head:w(n.head),tail:w(n.tail),color:w(n.color),line:w(n.line),navigateTo:w(n.navigateTo),...ve(i)&&{tags:i}});if(t){let e=sn(t);a=x({...a,...e},d)}return l(a.title)&&d(a.technology)&&(a.title=`[${a.technology}]`,delete a.technology),a}const{findConnection:ln,findConnectionsBetween:G,findConnectionsWithin:un}=yt;function K(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 dn(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 fn(e){if(B.isWildcard(e))return()=>!0;if(B.isElementTagExpr(e)||B.isElementKindExpr(e))throw Error(`element kind and tag expressions are not supported in deployment view rules`);if(B.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=>Ne(e.id)===t:e=>e.id===t}if(B.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?Ne(n)===t:!0}:e=>{let n=e.modelRef??null;return n?n===t:!0}}V(e)}function pn(e){return Se(e.$instance)??Se(e.element.$element)}function mn(e){let t=e.id,n=e.onlyOneInstance();return z({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:Se(e.$node)??void 0,tags:[...e.tags],style:h(e.style,[`icon`,`shape`,`color`])})}function hn(e){let t=e.$instance,n=e.element,{icon:r,color:i,shape:a,...o}=e.style,s=[...n.links,...t.links??[]];return z({id:e.id,kind:`instance`,title:e.title,description:pn(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 gn(e){return e.isInstance()?hn(e):mn(e)}const _n=(e,t,n)=>we(`model:${e}:${t}:${n}`);function vn(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 yn(e,t){let n=[],r=[];for(let i of e){let e=[...i.relations.model,...i.relations.deployment];N(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,C(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}=cn([e.$relationship],e.$relationship);n.push({id:_n(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=w(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}=cn(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}=cn(e.map(e=>e.$relationship)),m=z({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,...vn(r)]}function bn(e,t){let n=on(e.$styles,[...t.final].map(gn));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??=pn(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 xn(e,t){for(let n of e)!ke(n)||n.targets.length===0||Kt(n,S(n.targets.map(fn)),t);return t}function Sn(e){let t=new it.default(()=>[]);for(let n of e)for(let e of n.relations.model)t.get(e).push(n);let n=new it.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`)),ut(`desc`),ee((e,t,n)=>t===0||e.boundary===n[t-1].boundary),r(t=>{n.get(t).add(e)}))));return n}function Cn(e){e=st(e);let t=Sn(e);for(let n of e){let{source:e,target:r}=n,i=n.relations.model;if(e.isDeploymentNode()!==r.isDeploymentNode()){let r=e.isDeploymentNode()?e:n.target;N(r.isDeploymentNode());let a=T(i,r.internalModelRelationships());for(let e of a)t.get(n).add(e);continue}if(e.isDeploymentNode()&&r.isDeploymentNode()){let i=j(T(n.relations.model,e.internalModelRelationships()),T(n.relations.model,r.internalModelRelationships()));for(let e of i)t.get(n).add(e)}}return b(t.entries(),Ee(([e,t])=>e.update({model:t,deployment:null})),H())}function wn(e){return gt(e,Cn(e))}function Tn(e){return b(e,st,y((t,n)=>{let{source:r,target:i,relations:a}=n;if(r.isInstance()&&i.isInstance())return t;let o=Ct.empty();if(r.isDeploymentNode()&&i.isDeploymentNode()){let[e]=ln(i,r,`directed`);e&&(o=a.intersect(e.relations))}for(let t of e)dt(t,n)&&(o=o.union(a.intersect(t.relations)));return o.nonEmpty&&t.push(new at(r,i,o)),t},[]))}function En(e){return gt(e,Tn(e))}var Dn=class extends Ut{connectWithExisting(e,t=`both`){let n=this._connections.length,r=()=>this._connections.length>n;if(!F(e)){if(t===`in`||t===`both`)for(let t of this.memory.elements)this.addConnections(ln(t,e,`directed`));return(t===`out`||t===`both`)&&this.addConnections(G(e,this.memory.elements,`directed`)),r()}let i=[...e];if(t===`in`||t===`both`)for(let e of this.memory.elements)this.addConnections(G(e,i,`directed`));if(t===`out`||t===`both`)for(let e of i)this.addConnections(G(e,this.memory.elements,`directed`));return r()}processConnections(e){let t=b(e,wn,En);return b(t,r(({source:e,target:t,boundary:n})=>{b(fe([...H(e.ancestors()).reverse(),e],[...H(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}},On=class e extends Vt{static empty(){return new e({elements:new Set,explicits:new Set,final:new Set,connections:[]})}stageInclude(e){return new Dn(this,e)}stageExclude(e){return new Gt(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:H(O(e.elements,this.elements)),explicits:H(O(e.explicits,this.explicits)),final:H(O(e.final,this.final)),connections:H(gt(e.connections,this.connections))},removed:{elements:H(O(this.elements,e.elements)),explicits:H(O(this.explicits,e.explicits)),final:H(O(this.final,e.final)),connections:gt(this.connections,e.connections)}}}toString(){return[`final:`,...[...this.final].map(e=>` `+e.id),`connections:`,...this.connections.map(e=>` `+e.expression)].join(`
|
|
2
|
+
`)}[vt](e,t,n){return this.toString()}};const kn={include:({expr:e,model:t,memory:n,stage:r})=>{let i=M(e.where.condition);return D(Vn(`include`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i}))},exclude:({expr:e,model:t,memory:n,stage:r})=>{let i=M(e.where.condition);return D(Vn(`exclude`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i}))}},An={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(B.isWildcard(e.incoming)){for(let e of a){if(e.allOutgoing.isEmpty)continue;let t=q(G(e,[...qn(e)],`directed`),i);r.addConnections(t)}return r}N(B.isDeploymentRef(e.incoming),`Only deployment refs are supported in include`);let o=K(t,e.incoming);for(let e of a){let t=q(G(e,o,`directed`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(B.isElementTagExpr(e.incoming)||B.isElementKindExpr(e.incoming))throw Error(`element kind and tag expressions are not supported in exclude`);if(B.isModelRef(e.incoming))return Hn(Mn(t,e.incoming),{stage:r,memory:n},i);if(B.isWildcard(e.incoming))return r;let a=jn(K(t,e.incoming)),o=b(n.connections,v(a),q(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=dn(e,t);return new Set(n.flatMap(e=>[...e.allIncoming]))}const Nn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(B.isWildcard(e.outgoing)){for(let e of a)if(!e.allIncoming.isEmpty)for(let t of qn(e)){let n=q(ln(t,e,`directed`),i);r.addConnections(n)}return r}N(B.isDeploymentRef(e.outgoing),`Only deployment refs are supported in include`);let o=K(t,e.outgoing);for(let e of o){let t=q(G(e,a,`directed`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(B.isElementTagExpr(e.outgoing)||B.isElementKindExpr(e.outgoing))throw Error(`element kind and tag expressions are not supported in exclude`);if(B.isModelRef(e.outgoing))return Hn(Fn(t,e.outgoing),{stage:r,memory:n},i);if(B.isWildcard(e.outgoing))return r;let a=Pn(K(t,e.outgoing)),o=b(n.connections,v(a),q(i));return r.excludeConnections(o),r}};function Pn(e){return S(e.map(e=>{let t=t=>t===e||R(e,t);return e=>t(e.source)&&!t(e.target)}))}function Fn(e,t){let n=dn(e,t);return new Set(n.flatMap(e=>[...e.allOutgoing]))}const In={include:({expr:{source:e,target:t,isBidirectional:n=!1},model:r,stage:i,where:a})=>{if(B.isElementTagExpr(e)||B.isElementKindExpr(e)||B.isElementTagExpr(t)||B.isElementKindExpr(t))throw Error(`element kind and tag expressions are not supported in include`);N(!B.isModelRef(e),`Invalid source model ref in direct relation`),N(!B.isModelRef(t),`Invalid target model ref in direct relation`);let o=B.isWildcard(e),c=B.isWildcard(t),l=n?`both`:`directed`,u;switch(!0){case o&&c:u=b(un(r.instances()),q(a),g(e=>(i.addImplicit(e.boundary),e)));break;case!o&&c:{let t=K(r,e),i=Pn(t),o=i;if(n){let e=jn(t);o=t=>i(t)!==e(t)}u=b(t,s(e=>G(e,qn(e),l)),v(o),q(a));break}case o&&!c:{let e=K(r,t),i=jn(e),o=i;if(n){let t=Pn(e);o=e=>t(e)!==i(e)}u=b(e,s(e=>[...qn(e)].flatMap(t=>ln(t,e,l))),v(o),q(a));break}default:{N(!o,`Inference failed - source should be a deployment ref`),N(!c,`Inference failed - target should be a deployment ref`);let n=K(r,e),i=K(r,t),d=Pn(n),f=jn(i);u=b(n,s(e=>G(e,i,l)),v(e=>d(e)&&f(e)),q(a))}}return i.addConnections(u),B.isDeploymentRef(e)&&f(e.selector)&&i.addImplicit(r.element(e.ref.deployment)),B.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=fn(e.target),o=fn(e.source),s;switch(!0){case B.isWildcard(e.source)&&B.isWildcard(e.target):return r.excludeConnections(q(n.connections,i)),r;case B.isModelRef(e.source)&&B.isModelRef(e.target):return s=Ln({source:e.source,target:e.target,expr:e,model:t}),Hn(s,{stage:r,memory:n},i);case B.isModelRef(e.source)&&B.isWildcard(e.target):return s=Fn(t,e.source),Hn(s,{stage:r,memory:n},i);case B.isModelRef(e.source):return s=Fn(t,e.source),Hn(s,{stage:r,memory:n},i,e=>a(e.target));case B.isModelRef(e.target):return s=Mn(t,e.target),Hn(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),q(i));return l.length===0||r.excludeConnections(l),r}}};function Ln({source:e,target:t,expr:n,model:r}){let i=dn(r,e),a=dn(r,t),o=n.isBidirectional?`both`:`directed`,s=[];for(let e of i)s.push(...ht(e,a,o));return new Set(s.flatMap(e=>[...e.relations]))}const Rn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(B.isWildcard(e.inout)){for(let e of a){let t=Wn(G(e,[...qn(e)],`both`),i);r.addConnections(t)}return r}N(B.isDeploymentRef(e.inout),`Only deployment refs are supported in include`);let o=K(t,e.inout);for(let e of a){let t=Wn(G(e,o,`both`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(B.isElementTagExpr(e.inout)||B.isElementKindExpr(e.inout))throw Error(`element kind and tag expressions are not supported in exclude`);if(B.isModelRef(e.inout)){let a=dn(t,e.inout);return a.length===0?r:Hn(j(new Set,...a.flatMap(e=>[e.allIncoming,e.allOutgoing])),{stage:r,memory:n},i)}if(B.isWildcard(e.inout))return r;let a=K(t,e.inout),o=jn(a),s=Pn(a),c=b(n.connections,v(e=>o(e)!==s(e)),q(i));return r.excludeConnections(c),r}},zn={include:({expr:e,model:t,memory:n,stage:r})=>{let i=M(e.where.condition);return Vn(`include`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})},exclude:({expr:e,model:t,memory:n,stage:r})=>{let i=M(e.where.condition);return Vn(`exclude`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})}},Bn={include:({model:e,stage:t,where:n})=>{let r=[],i;return i=n?b([...e.elements()],J(n)):H(Ee(e.roots(),e=>(e.onlyOneInstance()||r.push(...e.children()),e))),t.addExplicit(i),r.length>1?(t.addConnections(un([...i,...r])),t.connectWithExisting(r)):t.addConnections(un(i)),t.connectWithExisting(i),t},exclude:({stage:e,memory:t,where:n})=>{let r=b([...t.elements],J(n));return e.exclude(r),e}};function Vn(e,{expr:t,where:n,...r}){switch(!0){case B.isElementTagExpr(t):case B.isElementKindExpr(t):throw Error(`element kind and tag expressions are not supported in deployment view rules`);case A.isCustom(t):case B.isCustom(t):case B.isModelRef(t):return;case B.isWhere(t):return kn[e]({...r,expr:t,where:n});case A.isWhere(t):return zn[e]({...r,expr:t,where:n});case B.isDeploymentRef(t):return Jn[e]({...r,expr:t,where:n});case B.isWildcard(t):return Bn[e]({...r,expr:t,where:n});case A.isDirect(t):return In[e]({...r,expr:t,where:n});case A.isInOut(t):return Rn[e]({...r,expr:t,where:n});case A.isOutgoing(t):return Nn[e]({...r,expr:t,where:n});case A.isIncoming(t):return An[e]({...r,expr:t,where:n});default:V(t)}}function Hn(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=>ze(t.relations.model,e)),g(t=>t.update({deployment:null,model:T(t.relations.model,e)})),q(r),v(e=>e.nonEmpty()));return a.length===0?t:t.excludeConnections(a)}function Un(e,t){return q(e,t).nonEmpty()}function q(...t){if(t.length===1)return e=>q(e,t[0]);let[n,r]=t;return r===null?n:e(n)?n.map(e=>q(e,r)).filter(e=>e.nonEmpty()):n.update({model:new Set([...n.relations.model.values()].filter(e=>r(Kn(n)(e)))),deployment:new Set([...n.relations.deployment.values()].filter(e=>r(Kn(n)(e))))})}function J(...t){if(t.length===1){let e=t[0];return e==null?e=>e:t=>t.filter(t=>e(Gn(t,t)))}let[n,r]=t;return e(n)?r==null?n:n.filter(e=>r(Gn(e,e))):r?.(Gn(n,n))??!0}function Wn(e,t){return t?b(e,v(e=>Un(e,t))):e}function Gn(e,t){if(xt(e)){let n=bt(t)&&Tt(t)?t:null;return{kind:e.kind,tags:[...e.tags,...n?.tags??[]],metadata:e.metadata}}if(pt(e))return te(e.element,[`tags`,`kind`,`metadata`]);if(Tt(e))return{kind:e.element.kind,tags:[...e.tags,...e.element.tags],metadata:e.metadata};if(wt(e))return te(e,[`tags`,`kind`,`metadata`]);V(e)}function Kn(e){return t=>({tags:t.tags,kind:t.kind,metadata:t.metadata,source:Gn(t.source,e.source),target:Gn(t.target,e.target)})}function qn(e){let t=new Set;for(let n of e.descendingSiblings())t.add(n);return t}const Jn={include:e=>{let{expr:t,where:n}=e,r=e.model.element(t.ref.deployment);if(Tt(r))return J(r,n)&&(e.stage.addExplicit(r),e.stage.connectWithExisting(r)),e.stage;switch(!0){case t.selector===`expanded`:Xn(r,e);break;case t.selector===`children`:Yn(r,e);break;case t.selector===`descendants`:Zn(r,e);break;default:J(r,n)&&(e.stage.addExplicit(r),e.stage.connectWithExisting(r))}return e.stage},exclude:({expr:e,stage:t,memory:n,where:r})=>{let i=fn(e),a=b([...n.elements],v(i),J(r));return t.exclude(a),t}};function Yn(e,{stage:t,where:n}){let r=J([...e.children()],n);r.length!==0&&(t.addImplicit(e),t.addConnections(un(r)),t.connectWithExisting(r),t.addExplicit(r))}function Xn(e,{memory:t,stage:n,where:r}){n.addImplicit(e),n.connectWithExisting(e);let i=J([...e.children()],r),a=!1;for(let e of i)if(G(e,t.elements).length>0){a=!0;break}a&&(n.connectWithExisting(i,`in`),n.addConnections(un(i)),n.connectWithExisting(i,`out`)),n.addImplicit(i),n.connections.length>0&&n.addExplicit(e)}function Zn(e,{stage:t,where:n}){let i=e=>{let r=[];for(let t of e.children())t.isDeploymentNode()&&r.push(...i(t)),J(t,n)&&r.push(t);return t.connectWithExisting(r,`in`),t.addConnections(un(r)),t.addImplicit(r),r},a=i(e);if(a.length===0)return;t.connectWithExisting(a,`out`);let o=Qn(t);b(a,v(e=>o.has(e)),r(e=>t.addExplicit(e)))}function Qn(e){return b(e.mergedConnections(),wn,En,y((e,t)=>(e.add(t.source),e.add(t.target),e),new Set))}var $n=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,wn,En),n=gt(e.connections,t);if(n.length===0)return e;let r=e.stageExclude({});return r.excludeConnections(n,!0),r.commit()}step2ProcessImplicits(e){let t=j(this.memory.elements,e.elements),n=j(e.final,this.memory.explicits),i=new it.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(O(t,a),L(e=>e.isDeploymentNode()),H(),qe,r(e=>{let t=[...e.children()].filter(o).length;if(t>=2){n.add(e);return}t===1&&De(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=Wt(e,`final`),r=e.stageExclude({}),i=r=>!(t.has(r)||e.explicits.has(r)||n.hasInOut(r)||n.root.has(r)),a=w([...n.root]);a&&!e.explicits.has(a)&&r.exclude(a);for(let t of e.final){let e=w(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=j(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 er=Ft(fn);function tr(e,t){let n=[],r=[];for(let e of t)if(tt(e)&&`include`in e)for(let t of e.include)A.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:er(e.customRelation.expr)})),s=r.map(e=>({pred:er(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 nr(e,t){let n=On.empty(),r=!1;for(let i of t){if(tt(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=Vn(t,{expr:i,model:e,stage:r,memory:n,where:null})??r,n=r.commit()}}`includeAncestors`in i&&(r=i.includeAncestors)}return $n.for(n,r).commit()}function rr(e,{docUri:t,rules:n,...r}){let i=nr(e.deployment,n),a=bn(e,i),s=tr(e,n),c=yn(i.connections,s);Pt(a,c);let l=zt({nodes:a,edges:c}),u=xn(n,l.nodes),d=o(n,Be),f=kt(u);return Bt({...r,[Oe]:`computed`,[et]:`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 ir(e){return t=>Ue(t)?t.groupRules.flatMap(ir(e)):tt(t)&&`include`in t?t.include.filter(e):[]}function ar(e,t){let n=e.flatMap(ir(P.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}=ge(t,l),h=z({border:n,opacity:i,multiple:o,iconColor:s,iconSize:c,iconPosition:u,padding:d,size:f,textSize:p}),g=!a(h),_=!a(m),v=W(e);r.forEach((e,t)=>{je(e)||!v(e)||(_&&(e={...e,...m,isCustomized:!0}),g&&(e={...e,isCustomized:!0,style:{...e.style,...h}}),r[t]=e)})}return r}function or(e,t){return e.reduce((e,n)=>{if(Qe(n)){let r=t.predicates[n.predicateId];return l(r)?e:e.concat(r)}if(Ae(n)){let r=t.styles[n.styleId];return l(r)?e:e.concat(r)}return e.push(n),e},[])}function sr(e,t){return e.reduce((e,n)=>{if(Qe(n)){let r=t.dynamicPredicates[n.predicateId];return l(r)?e:e.concat(r)}if(Ae(n)){let r=t.styles[n.styleId];return l(r)?e:e.concat(r)}return e.push(n),e},[])}function cr(e,t){let n=new Set;for(let r of t)if(tt(r))for(let t of r.include){let r=W(t);for(let t of e.elements())r(t)&&n.add(t)}return n}const lr=e=>{if(Ge(e)){let t=[],n=[];for(let r of e.__parallel)if(Xe(r)){let[e,...i]=r.__series;t.push(e),n.push(...i)}else t.push(r);return[...t,...n]}return Xe(e)?[...e.__series]:e};function ur(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,lr)){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 dr(e,t,n){let r=mt(e,t,`directed`).flatMap(e=>[...e.relations]).sort(xe);if(!ve(r))return{};if(r.length===1){let e=r[0];return z({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(),w());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 z({tags:a??void 0,relations:o,navigateTo:c,kind:w([...l.kind]),title:w([...l.title]),color:w([...l.color]),line:w([...l.line]),technology:w([...l.technology]),description:w(l.description)})}var fr=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=sr(t,this.model.globals),a=cr(this.model,i),s=ur(this.model,n),c=b(j(T(a,s),s,a),H(),Ie),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(Xe(e)){for(let r of e.__series)t=u(r,t,n);return t}let r=n?Le(n,t):Le(t),{source:i,target:a,title:o,isBackward:s,navigateTo:f,notation:p,...m}=e,h=this.model.element(i),g=c.indexOf(h);N(g>=0,`Source ${i} not found`);let _=this.model.element(a),v=c.indexOf(_);N(v>=0,`Target ${a} not found`),(l.includes(h)||l.includes(_))&&console.error(`Step ${h.id} -> ${_.id} because it involves a compound`);let{title:ee,relations:te,navigateTo:ne,...y}=dr(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(z({...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(Ge(e)){let t=1;for(let n of e.__parallel)t=u(n,t,f);f++;continue}f=u(e,f)}let p=on(this.model.$styles,c.map(an)),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=D(p.get(t.id),`Source node ${t.id} not found`),l=D(p.get(n.id),`Target node ${n.id} not found`),u={id:e,parent:Ye(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=Ne(u.parent);c.outEdges.push(u.id),l.inEdges.push(u.id);for(let e of We(u.source)){if(e===u.parent)break;p.get(e)?.outEdges.push(u.id)}for(let e of We(u.target)){if(e===u.parent)break;p.get(e)?.inEdges.push(u.id)}return u}),_=ar(i,qt(i,c.map(e=>D(p.get(e.id))))),v=o(i,Be),ee=kt(_);return Bt({...r,[et]:`dynamic`,[Oe]:`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 pr(e,t){return new fr(e,t).compute()}function mr(e,t,n){let r=e.flatMap(ir(k.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:Ze(a)}:{},s=o?{notes:Ze(o)}:{},u=ge(c,l),d=It(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 hr(e){return b([...e],st,y((e,t,n,r)=>{let i=Ot(r,t),a=j(...i.map(oe(`relations`))),o=T(t.relations,a);if(i.length>0&&(o=j(o,t.directRelations)),Et(r,t.reversed())&&(o=j(o,t.directRelations)),o.size<t.relations.size){let e=r.some(ot(t.source)),n=r.some(ot(t.target));e&&(o=j(o,E(L(t.relations,ct(t.source))))),n&&(o=j(o,E(L(t.relations,Dt(t.target)))))}return o.size>0&&e.push(t.update(o)),e},[]))}var gr=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=hr(e.connections);if(t.length===0)return e;let n=e.stageExclude({});return n.excludeConnections(t,!0),n.commit()}step2ProcessImplicits(e){let t=j(this.memory.elements,e.elements),n=j(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(O(t,i),H(),qe,r(e=>{let t=[...e.children()].filter(a).length;if(t>=2){n.add(e);return}t===1&&De(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=Wt(e,`final`),r=e.stageExclude({}),i=r=>!(t.has(r)||e.explicits.has(r)||n.hasInOut(r)||n.root.has(r)),a=w([...n.root]);a&&!e.explicits.has(a)&&r.exclude(a);for(let t of e.final){let e=w(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:_r,findConnectionsBetween:Y,findConnectionsWithin:vr}=St;function X(e,t){switch(!0){case P.isElementKindExpr(t):return[...L(e.elements(),e=>t.isEqual===(e.kind===t.elementKind))];case P.isElementTagExpr(t):return[...L(e.elements(),e=>t.isEqual===e.tags.includes(t.elementTag))];case t.selector===`expanded`:{let n=e.element(I.flatten(t.ref));return[n,...n.children()]}case t.selector===`children`:case t.selector===`descendants`:{let n=e.element(I.flatten(t.ref)),r=t.selector===`children`?H(n.children()):H(n.descendants());return r&&r.length>0?r:[n]}case P.isModelRef(t):return[e.element(I.flatten(t.ref))];default:V(t)}}function yr(e,t){if(t.isEmpty()||e.length===0)return e;let n=S(e.map(e=>Ve(e))),r=H(L(t.elements,t=>!e.includes(t)&&n(t)));return[...e,...r]}function br(e,{memory:t,model:n}){let r=X(n,e);return P.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(I.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(vr(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(vr(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(vr(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)=>we(`model:${e}:${t}:${n}`);function Dr(e,t){return e.flatMap(e=>{let n=[...e.relations];N(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,C(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}=cn([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}=cn(s.map(e=>e.$relationship),w(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}=cn(n.map(e=>e.$relationship),w(o)?.$relationship);return[z({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 on(e.$styles,[...t.final].map(an),t.groups)}const Z=P.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(),L(o),H(),g(e=>new _t(e.source,e.target,new Set([e]))));return a.addConnections(e),a}case l&&u&&!r.isEmpty()&&o!==wr:d.push(...vr(r.elements));break;case l&&u:d.push(...vr(i.roots()));break;case!l&&u&&o!==wr:{let t=b(X(i,e),s(e=>b(e,se(pe(n===!0),{onTrue:e=>j(e.allIncoming,e.allOutgoing),onFalse:e=>e.allOutgoing}),L(o),Ce(),H(),C(t=>t.source===e),([t,n])=>ce(b(t,v(t=>!kr(e,t.target)),g(t=>new _t(e,t.target,new Set([t])))),b(n,v(t=>!kr(e,t.source)),g(t=>new _t(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(...Y(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=>j(e.allIncoming,e.allOutgoing),onFalse:e=>e.allIncoming}),L(o),H(),C(t=>t.target===e),([t,n])=>ce(b(n,v(t=>!kr(e,t.target)),g(t=>new _t(e,t.target,new Set([t])))),b(t,v(t=>!kr(e,t.source)),g(t=>new _t(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(...Y(t,e,o));break}default:{N(!Z(e),`Inference failed - source must be not a wildcard`),N(!Z(t),`Inference failed - target must be not a wildcard`);let a=br(e,{memory:r,model:i}),o=br(t,{memory:r,model:i}),s=n?`both`:`directed`;for(let e of a)d.push(...Y(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`),L(o),H())),E());break;case!c&&l:u=b(X(r,e),s(e=>b(e,se(pe(n===!0),{onTrue:e=>j(e.allIncoming,e.allOutgoing),onFalse:e=>e.allOutgoing}),L(o),H())),E());break;case c&&!l:u=b(X(r,t),s(e=>b(e,se(pe(n===!0),{onTrue:e=>j(e.allIncoming,e.allOutgoing),onFalse:e=>e.allIncoming}),L(o),H())),E());break;default:{N(!Z(e),`Inference failed - source must be not a wildcard`),N(!Z(t),`Inference failed - target must be not a wildcard`);let i=X(r,e),a=X(r,t),s=new Set;for(let e of i)for(let t of a)$e(e,t)||(s=j(s,T(e.allOutgoing,t.allIncoming),n?T(t.allOutgoing,e.allIncoming):new Set));u=E(L(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(P.isModelRef(e)){let i=H(n.element(I.flatten(e.ref)).ascendingSiblings());return[yr(r,t),yr(i,t)]}return[r,b(r,g(e=>e.ascendingSiblings()),be(),Ce(),H(),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(P.isWildcard(o)){if(!t)return;for(let e of t.ascendingSiblings())s.push(..._r(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(...Y(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(P.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 P.isElementKindExpr(t):case P.isElementTagExpr(t):{let e=W(t);return t=>e(t.target)}case P.isModelRef(t)&&t.selector===`children`:{let n=I.flatten(t.ref);return S([...e.children(n)].map(e=>U.isIncoming(e.id)))}case P.isModelRef(t)&&t.selector===`descendants`:{let n=I.flatten(t.ref);return S([U.isInside(n),...[...e.children(n)].map(e=>U.isIncoming(e.id))])}case P.isModelRef(t)&&t.selector===`expanded`:{let e=I.flatten(t.ref);return S([U.isIncoming(e),U.isInside(e)])}case P.isModelRef(t):{let e=I.flatten(t.ref);return U.isIncoming(e)}default:V(t)}}const Pr={include:({expr:{inout:e},scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=[];if(P.isWildcard(e)){if(!t)return;o.push(...Y(t,t.ascendingSiblings()))}else{let t=br(e,{memory:r,model:n}),i=[...r.elements];i.length===0&&(i=ie(t.flatMap(e=>H(e.ascendingSiblings()))));for(let e of t)o.push(...Y(e,i))}return i.addConnections(a(o)),i},exclude:({expr:{inout:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(P.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(E(a.filter(i))),r}},Fr={include:({expr:e,scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=e.outgoing,s=[];if(P.isWildcard(o)){if(!t)return;s.push(...Y(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(...Y(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(P.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(E(a.filter(i))),r}};function Ir(e,t){switch(!0){case P.isElementKindExpr(t):case P.isElementTagExpr(t):{let e=W(t);return t=>e(t.source)}case P.isModelRef(t)&&t.selector===`children`:{let n=I.flatten(t.ref);return S([...e.children(n)].map(e=>U.isOutgoing(e.id)))}case P.isModelRef(t)&&t.selector===`descendants`:{let n=I.flatten(t.ref);return S([U.isInside(n),...[...e.children(n)].map(e=>U.isOutgoing(e.id))])}case P.isModelRef(t)&&t.selector===`expanded`:{let e=I.flatten(t.ref);return S([U.isOutgoing(e),U.isInside(e)])}case P.isModelRef(t):{let e=I.flatten(t.ref);return U.isOutgoing(e)}default:V(t)}}const Lr={include:({scope:e,model:t,stage:n,memory:r,where:i})=>{if(!e){let e=i===wr?[...t.roots()]:H(L(t.elements(),i));if(e.length===0)return;let[r,a]=C(e,e=>!e.imported);return n.addExplicit(r),n.addImplicit(a),n.addConnections(vr(e)),n.connectWithExisting(e),n}let a=H(L(e.children(),i)),o=a.length>0;if(!o){let t=Y(e,e.siblings()),r=e.parent;t.length===0&&r&&n.addExplicit(r),a.push(e)}n.addExplicit(e);let s=E([...r.elements,...e.descendingSiblings()]);for(let e of s)n.addConnections(Y(e,a,`directed`));o&&(n.addConnections(vr(a)),n.addExplicit(a));for(let e of a)n.addConnections(Y(e,s,`directed`));return n},exclude:({scope:e,memory:t,stage:n,where:r})=>r===wr?e?(n.exclude([e,...e.descendants()]),n):tn.empty(t.scope).stageExclude(n.expression):(n.exclude(v([...t.elements],r)),n)};function Rr(e,t,n){switch(!0){case P.isCustom(e):return t===`include`?Rr(e.custom.expr,t,n):n.stage;case P.isWhere(e):{let r=M(e.where.condition),i=e=>v(e,r);return Rr(e.where.expr,t,{...n,where:r,filterWhere:i})}case P.isModelRef(e)&&e.selector===`expanded`:return xr[t]({...n,expr:e})??n.stage;case P.isWildcard(e):return Lr[t]({...n,expr:e})??n.stage;case P.isElementKindExpr(e):case P.isElementTagExpr(e):return Sr[t]({...n,expr:e})??n.stage;case P.isModelRef(e):return Cr[t]({...n,expr:e})??n.stage;default:V(e)}}function zr(e,t,n){switch(!0){case k.isCustom(e):return t===`include`?zr(e.customRelation.expr,t,n):n.stage;case k.isWhere(e):{let r=M(e.where.condition),i=e=>new Set(v([...e],r)),a=e=>b(e,g(e=>new _t(e.source,e.target,i(e.relations))),v(e=>e.nonEmpty()));return zr(e.where.expr,t,{...n,where:r,filterWhere:a})}case k.isInOut(e):return Pr[t]({...n,expr:e})??n.stage;case k.isDirect(e):return Ar[t]({...n,expr:e})??n.stage;case k.isOutgoing(e):return Fr[t]({...n,expr:e})??n.stage;case k.isIncoming(e):return Mr[t]({...n,expr:e})??n.stage;default:V(e)}}function Br(e,t,n){let r={model:e,scope:t.scope,where:wr,filterWhere:Tr};for(let i of n){if(Ue(i)){t=Br(e,nn.enter(t,i),i.groupRules),N(t instanceof nn,`processPredicates must return ActiveGroupMemory`),t=t.leave();continue}if(tt(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 Te.isFqnExpr(i):n=Rr(i,e,{...r,stage:n,memory:t})??n;break;case Te.isRelationExpr(i):n=zr(i,e,{...r,stage:n,memory:t})??n;break;default:V(i)}t=n.commit()}}}return t}function Vr(e,t,n){return t=Br(e,t,n),gr.for(t).commit()}function Hr(e,t){let n=t.flatMap(ir(k.isCustom)).filter(e=>e.customRelation.multiple===!0),r=t.flatMap(ir(k.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:It(e.customRelation.expr)})),s=r.map(e=>({pred:It(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=or(n,e.globals),a=r.viewOf?e.asComputed.element(r.viewOf):null,s=Vr(e,tn.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);Pt(c,u);let d=zt({nodes:c,edges:u}),f=ar(i,qt(i,d.nodes)),p=o(i,Be),m=kt(f),h=Wr(i,f);return Bt({...r,_stage:`computed`,autoLayout:{direction:p?.direction??`TB`,...p?.nodeSep&&{nodeSep:p.nodeSep},...p?.rankSep&&{rankSep:p.rankSep}},edges:mr(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(!Je(r)||r.targets.length===0)continue;let e=b(t,v(S(r.targets.map(W))),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 it.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(Ie([...e.explicitFirstSeenIn.keys()]),r(r=>{if(!i(r)){let i=D(e.explicitFirstSeenIn.get(r));n.set(r,i),t.get(i).add(r)}})),b(Ie([...e.lastSeenIn.keys()]),v(e=>!n.has(e)),r(r=>{if(i(r)||a(r))return;let o=D(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 Pe(e):return Ur(t,e);case Ke(e):return rr(t,e);case Fe(e):return pr(t,e);default:V(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=lt.create(e),{views:r,_stage:i,...a}=e,o=t(r,e=>Kr(e,n));return{[Oe]:`computed`,...a,views:o}}function Yr(e){return lt.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,Pt as c,qr as i,Yr as n,Ur as o,Jr as r,zt as s,$ as t};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { $r as
|
|
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
3
|
import { i as LikeC4Styles } from "./index3.mjs";
|
|
4
4
|
import { o as DefaultMap } from "./libs/mnemonist.mjs";
|
|
5
|
+
import "./mnemonist.mjs";
|
|
5
6
|
import { IsAny, SetRequired, Tagged } from "type-fest";
|
|
6
7
|
|
|
7
8
|
//#region src/model/RelationModel.d.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { An as
|
|
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 {
|
|
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 {
|
|
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{
|
|
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{Cn as c,I as l,gn 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:c(l[t%l.length])}})),o(f),i((e,t)=>u(e.tag,t.tag)),s(a(`tag`),a(`spec`)))}export{d as t};
|