@likec4/core 1.47.0 → 1.49.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/LICENSE +1 -1
- package/dist/THIRD-PARTY-LICENSES.md +1012 -0
- package/dist/_chunks/Builder.view-element.mjs +2 -0
- package/dist/_chunks/LikeC4Model.d.mts +1283 -0
- package/dist/_chunks/RichText.mjs +1 -0
- package/dist/_chunks/_types.d.mts +777 -0
- package/dist/_chunks/_types2.d.mts +36 -0
- package/dist/_chunks/assignTagColors.mjs +1 -0
- package/dist/_chunks/calcDriftsFromSnapshot.mjs +1 -0
- package/dist/_chunks/guards.d.mts +2026 -0
- package/dist/_chunks/guards.mjs +4 -0
- package/dist/_chunks/index.d.mts +288 -0
- package/dist/_chunks/libs/@mantine/colors-generator.mjs +15 -0
- package/dist/_chunks/libs/@radix-ui/colors.mjs +1 -0
- package/dist/_chunks/libs/@ungap/structured-clone.mjs +1 -0
- package/dist/_chunks/libs/bail.mjs +1 -0
- package/dist/_chunks/libs/ccount.mjs +1 -0
- package/dist/_chunks/libs/character-entities-html4.mjs +1 -0
- package/dist/_chunks/libs/character-entities-legacy.mjs +1 -0
- package/dist/_chunks/libs/character-entities.mjs +2 -0
- package/dist/_chunks/libs/comma-separated-tokens.mjs +1 -0
- package/dist/_chunks/libs/decode-named-character-reference.mjs +1 -0
- package/dist/_chunks/libs/defu.mjs +1 -0
- package/dist/_chunks/libs/devlop.mjs +1 -0
- package/dist/_chunks/libs/escape-string-regexp.mjs +1 -0
- package/dist/_chunks/libs/extend.mjs +1 -0
- package/dist/_chunks/libs/graphology-dag.mjs +1 -0
- package/dist/_chunks/libs/graphology.mjs +1 -0
- package/dist/_chunks/libs/hast-util-sanitize.mjs +1 -0
- package/dist/_chunks/libs/hast-util-to-html.mjs +9 -0
- package/dist/_chunks/libs/is-plain-obj.mjs +1 -0
- package/dist/_chunks/libs/longest-streak.mjs +1 -0
- package/dist/_chunks/libs/markdown-table.mjs +2 -0
- package/dist/_chunks/libs/mdast-util-find-and-replace.mjs +1 -0
- package/dist/_chunks/libs/mdast-util-from-markdown.mjs +3 -0
- package/dist/_chunks/libs/mdast-util-gfm.mjs +15 -0
- package/dist/_chunks/libs/mdast-util-to-hast.mjs +11 -0
- package/dist/_chunks/libs/micromark-extension-gfm.mjs +1 -0
- package/dist/_chunks/libs/mnemonist.d.mts +164 -0
- package/dist/_chunks/libs/mnemonist.mjs +1 -0
- package/dist/_chunks/libs/natural-compare-lite.mjs +9 -0
- package/dist/_chunks/libs/ohash.mjs +1 -0
- package/dist/_chunks/libs/rehype-sanitize.mjs +1 -0
- package/dist/_chunks/libs/rehype-stringify.mjs +1 -0
- package/dist/_chunks/libs/remark-gfm.mjs +1 -0
- package/dist/_chunks/libs/remark-github-blockquote-alert.mjs +3 -0
- package/dist/_chunks/libs/remark-parse.mjs +1 -0
- package/dist/_chunks/libs/remark-rehype.mjs +1 -0
- package/dist/_chunks/libs/remeda.mjs +1 -0
- package/dist/_chunks/libs/trough.mjs +1 -0
- package/dist/_chunks/libs/unified.mjs +1 -0
- package/dist/_chunks/rolldown-runtime.mjs +1 -0
- package/dist/_chunks/theme.d.mts +148 -0
- package/dist/_chunks/to-text.d.mts +404 -0
- package/dist/_chunks/to-text.mjs +1 -0
- package/dist/_chunks/vector.d.mts +198 -0
- package/dist/_chunks/vector.mjs +1 -0
- package/dist/builder/index.d.mts +5 -775
- package/dist/builder/index.mjs +1 -1053
- package/dist/compute-view/index.d.mts +156 -56
- package/dist/compute-view/index.mjs +2 -229
- package/dist/geometry/index.d.mts +2 -109
- package/dist/geometry/index.mjs +1 -328
- package/dist/index.d.mts +14 -20
- package/dist/index.mjs +1 -18
- package/dist/model/index.d.mts +5 -57
- package/dist/model/index.mjs +1 -4
- package/dist/styles/index.d.mts +3 -117
- package/dist/styles/index.mjs +1 -63
- package/dist/types/index.d.mts +3 -47
- package/dist/types/index.mjs +1 -17
- package/dist/utils/graphology/index.d.mts +2 -1864
- package/dist/utils/graphology/index.mjs +1 -1
- package/dist/utils/index.d.mts +4 -124
- package/dist/utils/index.mjs +1 -44
- package/package.json +20 -24
- package/compute-view/relationships/package.json +0 -4
- package/dist/compute-view/relationships-view/index.d.mts +0 -51
- package/dist/compute-view/relationships-view/index.mjs +0 -185
- package/dist/model/connection/deployment/index.d.mts +0 -15
- package/dist/model/connection/deployment/index.mjs +0 -2
- package/dist/model/connection/index.d.mts +0 -75
- package/dist/model/connection/index.mjs +0 -3
- package/dist/model/connection/model/index.d.mts +0 -15
- package/dist/model/connection/model/index.mjs +0 -2
- package/dist/shared/core.3ZhnKAlZ.mjs +0 -106
- package/dist/shared/core.78IWAHAE.mjs +0 -332
- package/dist/shared/core.B85MJLTf.mjs +0 -5
- package/dist/shared/core.BFd1lU9R.mjs +0 -29
- package/dist/shared/core.BKlholso.mjs +0 -3
- package/dist/shared/core.BNN-3vPH.mjs +0 -1255
- package/dist/shared/core.BPGOjone.d.mts +0 -46
- package/dist/shared/core.BP_QHEXs.mjs +0 -785
- package/dist/shared/core.BbE4y-yl.mjs +0 -177
- package/dist/shared/core.Bdy3hhTc.mjs +0 -28382
- package/dist/shared/core.BfCKSW-g.d.mts +0 -1266
- package/dist/shared/core.BhNcrwzK.mjs +0 -7
- package/dist/shared/core.BkVA6gjl.mjs +0 -5
- package/dist/shared/core.BoYfZOBm.mjs +0 -3
- package/dist/shared/core.BsSXS-_R.mjs +0 -7
- package/dist/shared/core.C3JowhaZ.mjs +0 -32
- package/dist/shared/core.C4x8aaWa.mjs +0 -27
- package/dist/shared/core.CAgYpDtM.d.mts +0 -98
- package/dist/shared/core.CHf8VEa3.mjs +0 -1206
- package/dist/shared/core.CLSZtnFh.mjs +0 -69
- package/dist/shared/core.C_3y3eqV.d.mts +0 -139
- package/dist/shared/core.CbT8JVYL.mjs +0 -5
- package/dist/shared/core.CdNCAwq7.mjs +0 -176
- package/dist/shared/core.CmGY9blO.mjs +0 -6717
- package/dist/shared/core.CmPXpJ8l.mjs +0 -21
- package/dist/shared/core.Coi_LOUZ.mjs +0 -7
- package/dist/shared/core.CqAJJpK_.mjs +0 -3
- package/dist/shared/core.CywrQs86.d.mts +0 -31
- package/dist/shared/core.D00YbOhQ.d.mts +0 -300
- package/dist/shared/core.D0WZutNd.mjs +0 -94
- package/dist/shared/core.D4npX2q8.mjs +0 -18
- package/dist/shared/core.DB0Ue5Wx.d.mts +0 -70
- package/dist/shared/core.DC5IAaDT.d.mts +0 -334
- package/dist/shared/core.DE9qzhn8.d.mts +0 -83
- package/dist/shared/core.DGcIbsj4.mjs +0 -3946
- package/dist/shared/core.DH7TXqXf.mjs +0 -136
- package/dist/shared/core.DKhRkHRN.d.mts +0 -41
- package/dist/shared/core.DRJma0Ol.mjs +0 -22
- package/dist/shared/core.DU5SRqNF.mjs +0 -2209
- package/dist/shared/core.DXhDWKFZ.d.mts +0 -3
- package/dist/shared/core.DbfO90vF.mjs +0 -434
- package/dist/shared/core.DcS-0zys.mjs +0 -10
- package/dist/shared/core.Dh119QSP.mjs +0 -4995
- package/dist/shared/core.DjcWextK.mjs +0 -1371
- package/dist/shared/core.Dojz4bvg.d.mts +0 -504
- package/dist/shared/core.FZ305VYd.mjs +0 -21
- package/dist/shared/core.OtRNdMxy.d.mts +0 -352
- package/dist/shared/core.RfnaEmgA.mjs +0 -7
- package/dist/shared/core.btEq3i3f.mjs +0 -300
- package/dist/shared/core.oSV6SRfk.mjs +0 -13
- package/dist/shared/core.om36dXXW.mjs +0 -41
- package/dist/shared/core.osFs8tU7.d.mts +0 -466
- package/dist/shared/core.q10OP9oJ.mjs +0 -5
- package/dist/shared/core.tpvDGvdC.d.mts +0 -87
- package/dist/shared/core.uFk_o9X6.mjs +0 -13
- package/dist/types/_aux.d.mts +0 -4
- package/dist/types/_aux.mjs +0 -8
- package/dist/types/expression-model.d.mts +0 -190
- package/dist/types/expression-model.mjs +0 -109
- package/dist/types/expression.d.mts +0 -6
- package/dist/types/expression.mjs +0 -113
- package/dist/types/fqnRef.d.mts +0 -60
- package/dist/types/fqnRef.mjs +0 -45
- package/dist/types/scalar.d.mts +0 -2
- package/dist/types/scalar.mjs +0 -4
- package/dist/utils/iterable/index.d.mts +0 -132
- package/dist/utils/iterable/index.mjs +0 -62
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{r as __toESM}from"./rolldown-runtime.mjs";import{B as e$8,C as t$24,E as t,G as t$6,H as t$18,I as e$9,J as t$21,K as t$17,L as e$2,M as e$5,N as e$3,O as e,P as e$7,Q as t$16,R as e$4,S as n$2,T as t$4,V as t$13,Y as n,Z as t$10,_ as t$11,a as t$5,d as t$12,et as t$3,g as t$15,h as t$20,i as n$3,k as e$12,m as e$6,n as e$10,nt as t$23,o as n$1,q as n$4,r as t$19,rt as t$8,t as t$9,tt as e$11,u as t$1,v as t$2,w as t$7,x as t$22,y as t$14,z as e$1}from"./libs/remeda.mjs";import{$ as GroupElementKind,D as whereOperatorAsPredicate,H as ModelExpression,J as FqnRef,K as FqnExpr,U as ModelFqnExpr,W as ModelRelationExpr,_t as _type,b as isViewRuleStyle,bt as preferSummary,ct as flattenMarkdownOrString,d as isViewRuleGlobalStyle,et as MarkdownOrString,g as isElementView,gt as _stage,h as isDynamicView,l as isViewRuleAutoLayout,mt as stepEdgeId,n as isViewRuleGroup,o as isDynamicStepsParallel,p as isDeploymentView,q as RelationExpr,r as isViewRuleRank,s as isDynamicStepsSeries,u as isViewRuleGlobalPredicateRef,ut as isGroupElementKind,xt as exact,y as isViewRulePredicate}from"./RichText.mjs";import{$ as nonNullable,A as ancestorsFqn,B as parentFqn,D as ifilter,I as isAncestor,K as isNonEmptyArray,L as isDescendantOf,M as compareByFqnHierarchically,O as isIterable,Q as invariant,R as isSameHierarchy,U as sortParentsFirst,V as sortByFqnHierarchically,Z as commonHead,_ as toArray,a as difference,c as intersection,d as compareRelations,et as nonexhaustive,g as iunique,i as objectHash,j as commonAncestor,s as hasIntersection,u as union,v as toSet,w as iflat,x as imap,y as isome}from"./to-text.mjs";import{n as require_topological_sort,t as require_will_create_cycle}from"./libs/graphology-dag.mjs";import{c as import_stack,t as import_default_map}from"./libs/mnemonist.mjs";import{A as DeploymentConnectionModel,C as isAnyInOut,D as mergeConnections,E as isOutgoing,M as Connection,N as LikeC4Model,O as sortConnectionsByBoundaryHierarchy,T as isNestedConnection,_ as findAscendingConnections,c as isNestedElementOfDeployedInstanceModel,d as findConnection$3,f as findConnectionsBetween$3,g as differenceConnections,h as ConnectionModel,j as customInspectSymbol,m as find_exports$1,n as isDeploymentElementModel,o as isElementModel,p as find_exports,q as RelationshipsAccum,r as isDeploymentNodeModel,t as isDeployedInstanceModel,v as findDeepestNestedConnection,w as isIncoming,y as findDescendantConnections}from"./guards.mjs";import{r as buildElementNotations}from"./calcDriftsFromSnapshot.mjs";import{t as Graph}from"./libs/graphology.mjs";function ancestorsOfNode(r,i){let a=[],o=r.parent;for(;o;){let r=nonNullable(i.get(o),`Parent node ${o} not found`);a.push(r),o=r.parent}return a}function linkNodesWithEdges(r,i){for(let a of i){let i=r.get(a.source),s=r.get(a.target);invariant(i,`Source node ${a.source} not found`),invariant(s,`Target node ${a.target} not found`),i.outEdges.push(a.id),s.inEdges.push(a.id);let c=ancestorsOfNode(i,r),l=ancestorsOfNode(s,r),u=c.length>0&&l.length>0?t(commonHead(t$1(c),t$1(l))):null;a.parent=u?u.id:null;for(let r of c){if(r===u)break;r.outEdges.push(a.id)}for(let r of l){if(r===u)break;r.inEdges.push(a.id)}}}var import_topological_sort=require_topological_sort(),import_will_create_cycle=__toESM(require_will_create_cycle(),1);function ensureParentsFirst(r){let i=[],a=[...r],o;for(;o=a.shift();){let r=o.parent;if(r){let o=[];for(;r;){let i=a.findIndex(i=>i.id===r);if(i<0)break;let[s]=a.splice(i,1);if(!s)throw Error(`Invalid state, should not happen`);o.unshift(s),r=s.parent}i.push(...o)}i.push(o)}return i}function updateChildren(r){return r.forEach(i=>{i.children.length>0&&(i.children=r.reduce((r,a)=>(a.parent===i.id&&r.push(a.id),r),[]))}),r}function topologicalSort(r){let i=ensureParentsFirst([...r.nodes.values()]),a=[...r.edges];if(i.length<2||a.length===0)return{nodes:i,edges:a};let o=i=>nonNullable(r.nodes.get(i)),c=new Graph({multi:!0,allowSelfLoops:!0,type:`directed`}),[l,u]=t$2(t$3(a,t$4(r=>{let i=o(r.source),a=o(r.target),s=r.parent?o(r.parent):null;return{id:r.id,edge:r,parent:s,source:i,target:a}})),({source:r,target:i})=>r.children.length===0&&i.children.length===0),d=[],f=r=>{c.mergeNode(r.source),c.mergeNode(r.target),d.push(r),(0,import_will_create_cycle.default)(c,r.source,r.target)||c.mergeDirectedEdge(r.source,r.target)};for(let{edge:i,source:a,target:u}of l)if(f(i),u.parent&&u.parent!==i.parent&&t$3(ancestorsOfNode(u,r.nodes),t$5(r=>r.inEdges.includes(i.id)),t$6(r=>{c.mergeNode(r.id),(0,import_will_create_cycle.default)(c,i.source,r.id)||c.mergeDirectedEdge(i.source,r.id),(0,import_will_create_cycle.default)(c,r.id,i.target)||c.mergeDirectedEdge(r.id,i.target)})),a.parent){let r=o(a.parent);c.mergeNode(r.id),(0,import_will_create_cycle.default)(c,r.id,a.id)||c.mergeDirectedEdge(r.id,a.id),u.parent&&u.parent!==a.parent&&((0,import_will_create_cycle.default)(c,r.id,u.parent)||c.mergeDirectedEdge(r.id,u.parent))}for(let{edge:r}of u)f(r);invariant(d.length===a.length,`Not all edges were added to the graph`);let p=(0,import_topological_sort.topologicalSort)(c),m=[],h=i.slice();for(let r of p){let i=h.findIndex(i=>i.id===r);invariant(i>=0,`Node "${r}" not found`),m.push(...h.splice(i,1))}return h.length>0&&m.length>0&&(m=m.flatMap(r=>{if(h.length===0)return r;let a=i.slice(0,i.indexOf(r)).filter(r=>h.includes(r));return a.length>0?(h=h.filter(r=>!a.includes(r)),[...a,r]):r})),m.push(...h),{nodes:updateChildren(ensureParentsFirst(m)),edges:d}}function calcViewLayoutHash(r){return r.hash=objectHash({id:r.id,__:r._type??`element`,autoLayout:r.autoLayout,nodes:t$3(r.nodes,t$4(r=>({id:r.id,icon:e(r.icon)&&r.icon!==`none`?`Y`:`N`,title:r.title,description:flattenMarkdownOrString(r.description),technology:r.technology??null,shape:r.shape,size:r.style.size??null,iconSize:r.style.iconSize??null,iconPosition:r.style.iconPosition??null,textSize:r.style.textSize??null,padding:r.style.padding??null,children:r.children})),t$7(({id:r,...i})=>[r,i])),edges:t$3(r.edges,t$4(r=>({source:r.source,target:r.target,label:r.label,description:flattenMarkdownOrString(r.description),technology:r.technology??null,dir:r.dir,head:r.head,tail:r.tail,line:r.line})),t$7(({source:r,target:i,...a})=>[`${r}:${i}`,a]))}),r}var AbstractMemory=class{get Ctx(){throw Error(`Should not be called in runtime`)}constructor(r){this.state=r}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}},AbstractStageExclude=class{excluded={elements:new Set,connections:[]};constructor(r,i){this.memory=r,this.expression=i}markedToMoveExplicitToImplicit=!1;_removeElement(r){this.excluded.elements.add(r)}exclude(r){if(!r)return this;if(isIterable(r)){for(let i of r)this._removeElement(i);return this}return this._removeElement(r),this}_removeConnection(r){this.excluded.connections.push(r)}excludeConnections(r,i){if(e$1(i)&&(invariant(!this.markedToMoveExplicitToImplicit,`Already marked to move explicits`),this.markedToMoveExplicitToImplicit=i),isIterable(r)){for(let i of r)this._removeConnection(i);return this}return this._removeConnection(r),this}isDirty(){return this.excluded.elements.size>0||this.excluded.connections.length>0}isEmpty(){return!this.isDirty()}filterForMoveToImplicits(r){return this.markedToMoveExplicitToImplicit||this.excluded.elements.size>0?r:new Set}moveDisconnectedExplicitsToImplicits(r){let i=difference(new Set(this.memory.connections.flatMap(r=>[r.source,r.target])),new Set(r.connections.flatMap(r=>[r.source,r.target])));return i=intersection(i,r.elements),i=t$3(i,ifilter(i=>r.explicits.has(i)&&!isome(r.final,isDescendantOf(i))),toSet()),i.size>0&&(i=this.filterForMoveToImplicits(i),r.explicits=difference(r.explicits,i),r.final=difference(r.final,i)),r}removeElements(r){return r.elements=difference(r.elements,this.excluded.elements),r.explicits=difference(r.explicits,this.excluded.elements),r.final=difference(r.final,this.excluded.elements),r}removeConnections(r){let i=this.excluded.connections.reduce((r,i)=>{let a=r.get(i.id);return a?r.set(i.id,a.mergeWith(i)):r.set(i.id,i),r},new Map),a=new Set;r.connections=r.connections.reduce((r,o)=>{let s=i.get(o.id);if(s){a.add(o.source),a.add(o.target);let i=o.difference(s);i.nonEmpty()&&r.push(i)}else r.push(o);return r},[]);for(let i of r.connections)a.delete(i.source),a.delete(i.target),i.boundary&&r.elements.has(i.boundary)&&a.delete(i.boundary);return a.size===0?r:(a=difference(a,r.explicits),r.final=difference(r.final,a),r)}precommit(r){return r}postcommit(r){return invariant(difference(r.explicits,r.elements).size===0,`Explicits must be subset of elements`),invariant(difference(r.final,r.elements).size===0,`Final elements must be subset of elements`),r}commit(){let r=this.precommit(this.memory.mutableState());if(this.excluded.elements.size>0){let i=r.connections.filter(r=>this.excluded.elements.has(r.source)||this.excluded.elements.has(r.target)).flatMap(i=>[i,...findAscendingConnections(r.connections,i).map(r=>r.intersect(i))]).filter(r=>r.nonEmpty());this.excludeConnections(i)}return this.excluded.connections.length>0&&(r=this.removeConnections(r)),this.excluded.elements.size>0&&(r=this.removeElements(r)),this.memory.update(this.postcommit(r))}},AbstractStageInclude=class{explicits=new Set;implicits=new Set;_ordered=new Set;_connections=[];constructor(r,i){this.memory=r,this.expression=i}get elements(){return this.explicits}get connections(){return this._connections}mergedConnections(){return mergeConnections([...this.memory.connections,...this._connections])}connectWithExisting(r,i){throw Error(`Method not implements, depends on the model`)}_addExplicit(r){this._ordered.add(r),this.explicits.add(r),this.implicits.delete(r)}addExplicit(r){if(!r)return this;if(isIterable(r)){for(let i of r)this._addExplicit(i);return this}return this._addExplicit(r),this}_addImplicit(r){this.explicits.has(r)||(this._ordered.add(r),this.implicits.add(r))}addImplicit(r){if(!r)return this;if(isIterable(r)){for(let i of r)this._addImplicit(i);return this}return this._addImplicit(r),this}_addConnection(r){this._connections.push(r),this._addImplicit(r.source),this._addImplicit(r.target)}addConnections(r){if(isIterable(r)){for(let i of r)this._addConnection(i);return this}return this._addConnection(r),this}isDirty(){return this.explicits.size>0||this.implicits.size>0||this._connections.length>0}isEmpty(){return!this.isDirty()}precommit(r){return r}postcommit(r){return r}processConnections(r){return r}commit(){let r=this.precommit(this.memory.mutableState()),i=new Set;if(this._connections.length>0){let[a,o]=t$2(this._connections,i=>r.final.has(i.source));r.connections=this.processConnections(mergeConnections([...r.connections,...a,...o])),i=new Set(r.connections.flatMap(r=>[r.source,r.target]))}return r.elements=union(r.elements,this._ordered,this.explicits,i,this.implicits),r.explicits=intersection(r.elements,union(r.explicits,this.explicits)),r.final=intersection(r.elements,union(r.final,this.explicits,i)),this.memory.update(this.postcommit(r))}};function treeFromMemoryState(r,i=`final`){let a=sortParentsFirst(toArray(i===`final`?r.final:r.elements)),o=new Set(r.connections.flatMap(r=>[r.source,r.target])),s=new Set(a),c=new import_default_map.default(()=>null),l=a.reduce((r,i,a,o)=>(r.set(i,o.slice(a+1).filter(r=>isAncestor(i,r)).map(r=>(s.delete(r),r)).reduce((r,a)=>(r.some(r=>isAncestor(r,a))||(r.push(a),c.set(a,i)),r),[])),r),new import_default_map.default(()=>[]));return{root:s,connected:o,hasInOut:i=>r.connections.some(Connection.isAnyInOut(i.id)),parent:r=>c.get(r),children:r=>l.get(r)}}var StageExclude$1=class extends AbstractStageExclude{};function elementExprToPredicate(r){if(ModelFqnExpr.isCustom(r))return elementExprToPredicate(r.custom.expr);if(ModelFqnExpr.isWhere(r)){let i=elementExprToPredicate(r.where.expr),a=whereOperatorAsPredicate(r.where.condition);return r=>i(r)&&a(r)}if(ModelFqnExpr.isElementKindExpr(r))return r.isEqual?i=>i.kind===r.elementKind:i=>i.kind!==r.elementKind;if(ModelFqnExpr.isElementTagExpr(r))return r.isEqual?({tags:i})=>i.includes(r.elementTag):({tags:i})=>!i.includes(r.elementTag);if(ModelFqnExpr.isWildcard(r))return()=>!0;if(ModelFqnExpr.isModelRef(r)){let i=FqnRef.flatten(r.ref);if(r.selector===`expanded`)return r=>r.id===i||parentFqn(r.id)===i;if(r.selector===`descendants`||r.selector===`children`){let r=i+`.`;return i=>i.id.startsWith(r)}return r=>r.id===i}nonexhaustive(r)}function applyViewRuleStyle(r,i,a){let{shape:o,color:c,icon:l,...u}=r.style,d=!e$2(u);t$3(a,n(e$3(isGroupElementKind)),n(i),t$6(i=>{i.shape=o??i.shape,i.color=c??i.color,e$4(l)&&(i.icon=l),e$4(r.notation)&&(i.notation=r.notation),d&&(i.style={...i.style,...u})}))}function applyViewRuleStyles(r,i){for(let a of r)!isViewRuleStyle(a)||a.targets.length===0||applyViewRuleStyle(a,t$8(a.targets.map(elementExprToPredicate)),i);return i}var NodesGroup=class r{static kind=GroupElementKind;constructor(r,i,a=null,o=new Set){this.id=r,this.viewRule=i,this.parent=a,this.elements=o}isEmpty(){return this.elements.size===0}update(i){return new r(this.id,this.viewRule,this.parent,i)}clone(){return new r(this.id,this.viewRule,this.parent,new Set(this.elements))}},StageExclude=class extends AbstractStageExclude{excludeRelations(r){return t$3(this.memory.connections,n(i=>hasIntersection(i.relations,r)),t$6(i=>{this.excludeConnections(i.update(intersection(i.relations,r)))})),this}precommit(r){if(this.excluded.elements.size>0){let r=new Set([...this.excluded.elements].flatMap(r=>[...r.incoming(`direct`),...r.outgoing(`direct`)]));this.excludeRelations(r)}return r}postcommit(r){let i=difference(this.memory.explicits,r.explicits);for(let a of i)r.explicitFirstSeenIn.delete(a);let a=difference(this.memory.elements,r.elements);for(let i of a)r.lastSeenIn.delete(i);return r}},ActiveGroupStageExclude=class extends StageExclude{constructor(r,i){super(r,i),this.memory=r,this.expression=i}};const{findConnection:findConnection$2,findConnectionsBetween:findConnectionsBetween$2}=find_exports;var StageInclude$1=class extends AbstractStageInclude{connectWithExisting(r,i=`both`){let a=this._connections.length,o=()=>this._connections.length>a;if(!isIterable(r)){if(i===`in`||i===`both`)for(let i of this.memory.elements)this.addConnections(findConnection$2(i,r,`directed`));return(i===`out`||i===`both`)&&this.addConnections(findConnectionsBetween$2(r,this.memory.elements,`directed`)),o()}let s=[...r];if(i===`in`||i===`both`)for(let r of this.memory.elements)this.addConnections(findConnectionsBetween$2(r,s,`directed`));if(i===`out`||i===`both`)for(let r of s)this.addConnections(findConnectionsBetween$2(r,this.memory.elements,`directed`));return o()}addImplicitWithinScope(r){r&&(!this.memory.scope||isAncestor(this.memory.scope,r))&&this.addImplicit(r)}processConnections(r){return ModelExpression.isRelationExpr(this.expression)||t$3(r,t$6(({source:r,target:i,boundary:a})=>{t$3(t$9([...toArray(r.ancestors()).reverse(),r],[...toArray(i.ancestors()).reverse(),i]),t$10(([r,i])=>r===i),n$1(1),t$6(([o,s])=>{if(o===r&&s===i){this.addImplicitWithinScope(a);return}o!==r&&this.addImplicitWithinScope(o),s!==i&&this.addImplicitWithinScope(s)}))})),r}postcommit(r){let i=difference(r.explicits,this.memory.explicits);for(let a of i)r.explicitFirstSeenIn.set(a,`@root`);return r}},ActiveGroupStageInclude=class extends StageInclude$1{constructor(r,i){super(r,i),this.memory=r,this.expression=i}postcommit(r){let i=difference(r.explicits,this.memory.explicits);for(let a of i)r.explicitFirstSeenIn.set(a,this.memory.activeGroupId);for(let i of[...this.explicits,...this.implicits])r.lastSeenIn.set(i,this.memory.activeGroupId);return r}},Memory$1=class r extends AbstractMemory{static empty(i){return new r({elements:new Set,explicits:new Set,final:new Set,connections:[],groups:[],explicitFirstSeenIn:new Map,lastSeenIn:new Map},i)}constructor(r,i){super(r),this.state=r,this.scope=i}get groups(){return this.state.groups}get explicitFirstSeenIn(){return this.state.explicitFirstSeenIn}get lastSeenIn(){return this.state.lastSeenIn}stageInclude(r){return new StageInclude$1(this,r)}stageExclude(r){return new StageExclude(this,r)}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(r=>r.clone()),explicitFirstSeenIn:new Map(this.state.explicitFirstSeenIn),lastSeenIn:new Map(this.state.lastSeenIn)}}update(i){return new r({...this.state,...i},this.scope)}},ActiveGroupMemory=class r extends Memory$1{static enter(i,a){let o=`@gr${i.groups.length+1}`;if(i instanceof r){let s=import_stack.default.from([...i.stack].reverse()),c=i.mutableState();return c.groups.push(new NodesGroup(o,a,i.activeGroupId)),s.push(o),new r(c,i.scope,s)}let s=i.mutableState();s.groups.push(new NodesGroup(o,a,null));let c=import_stack.default.of(o);return new r(s,i.scope,c)}constructor(r,i,a){super(r,i),this.state=r,this.scope=i,this.stack=a}get activeGroupId(){return nonNullable(this.stack.peek(),`Stack must not be empty`)}mutableState(){return{...super.mutableState()}}update(i){return new r({...this.state,...i},this.scope,this.stack)}stageInclude(r){return new ActiveGroupStageInclude(this,r)}stageExclude(r){return new ActiveGroupStageExclude(this,r)}leave(){let i=this.mutableState();return this.stack.pop(),this.stack.peek()?new r(i,this.scope,this.stack):new Memory$1(i,this.scope)}};function updateDepthOfAncestors(r,i){let a;for(;r.parent&&(a=i.get(r.parent));){let i=a.depth??1;if(a.depth=Math.max(i,(r.depth??0)+1),a.depth===i)break;r=a}}function elementModelToNodeSource(r){let{id:i,title:a,...o}=n$2(r.$element,[`summary`,`description`,`metadata`,`style`,`tags`]),{color:s,icon:c,shape:l,...u}=r.style;return exact({id:i,title:a,modelRef:i,shape:l,color:s,icon:c,style:u,description:preferSummary(r.$element),tags:[...r.tags],...o})}function buildComputedNodes({defaults:r},i,a){let o=new Map,s=new Map;a?.forEach(({id:i,parent:a,viewRule:c,elements:l})=>{a&&nonNullable(o.get(a),`Parent group node ${a} not found`).children.push(i),o.set(i,{id:i,parent:a,kind:GroupElementKind,title:c.title??``,color:c.color??r.group.color??r.color,shape:`rectangle`,children:[],inEdges:[],outEdges:[],level:0,depth:0,tags:[],style:exact({border:c.border??r.group.border,opacity:c.opacity??r.group.opacity,size:c.size,multiple:c.multiple,padding:c.padding,textSize:c.textSize})});for(let r of l)s.set(r.id,i)}),Array.from(i).sort(compareByFqnHierarchically).forEach(({id:r,...i})=>{let a=parentFqn(r),c=0,l;for(;a&&(l=o.get(a),!l);)a=parentFqn(a);let u=i.modelRef??r;if(!l&&s.has(u)){let r=nonNullable(s.get(u));l=o.get(r),a=r}l&&(l.children.length==0&&(l.depth=1,updateDepthOfAncestors(l,o)),l.children.push(r),c=l.level+1);let d=exact({id:r,parent:a,level:c,children:[],inEdges:[],outEdges:[],...i});o.set(r,d)});let c=new Map;return a?.forEach(({id:r})=>{c.set(r,nonNullable(o.get(r)))}),i.forEach(({id:r})=>{c.set(r,nonNullable(o.get(r)))}),c}function pickRelationshipProps(r){let{title:i,description:a=null}=r;return{...i&&{title:i,description:a},...t$11(r,[`color`,`technology`,`head`,`line`,`tail`,`kind`,`navigateTo`])}}function mergePropsFromRelationships(r,i){let a=t$3(r,t$12((r,i)=>(e(i.title)&&!r.title.includes(i.title)&&r.title.push(i.title),e(i.description)&&!r.description.some(t$13(i.description))&&r.description.push(i.description),e(i.technology)&&!r.technology.includes(i.technology)&&r.technology.push(i.technology),e(i.kind)&&!r.kind.includes(i.kind)&&r.kind.push(i.kind),e(i.color)&&!r.color.includes(i.color)&&r.color.push(i.color),e(i.line)&&!r.line.includes(i.line)&&r.line.push(i.line),e(i.head)&&!r.head.includes(i.head)&&r.head.push(i.head),e(i.tail)&&!r.tail.includes(i.tail)&&r.tail.push(i.tail),e(i.navigateTo)&&!r.navigateTo.includes(i.navigateTo)&&r.navigateTo.push(i.navigateTo),i.tags&&r.tags.push(...i.tags),r),{title:[],description:[],technology:[],kind:[],head:[],tail:[],color:[],tags:[],line:[],navigateTo:[]})),o=t$14(a.title)??(a.title.length>1?`[...]`:void 0),s=n$3(a.tags),c=exact({title:o,description:t$14(a.description),technology:t$14(a.technology),kind:t$14(a.kind),head:t$14(a.head),tail:t$14(a.tail),color:t$14(a.color),line:t$14(a.line),navigateTo:t$14(a.navigateTo),...isNonEmptyArray(s)&&{tags:s}});if(i){let r=pickRelationshipProps(i);c=t$15({...c,...r},e)}return e$5(c.title)&&e(c.technology)&&(c.title=`[${c.technology}]`,delete c.technology),c}const{findConnection:findConnection$1,findConnectionsBetween:findConnectionsBetween$1,findConnectionsWithin:findConnectionsWithin$1}=find_exports$1;function resolveElements$1(r,i){let a=r.element(i.ref.deployment);if(a.isDeploymentNode()){if(i.selector===`children`)return[...a.children()];if(i.selector===`expanded`)return[a,...a.children()];if(i.selector===`descendants`)return[...a.descendants()]}return[a]}function resolveModelElements(r,i){let a=r.$model.element(i.ref.model);return i.selector===`children`?[...a.children()]:i.selector===`expanded`?[a,...a.children()]:i.selector===`descendants`?[...a.descendants()]:[a]}function deploymentExpressionToPredicate(r){if(FqnExpr.isWildcard(r))return()=>!0;if(FqnExpr.isElementTagExpr(r)||FqnExpr.isElementKindExpr(r))throw Error(`element kind and tag expressions are not supported in deployment view rules`);if(FqnExpr.isDeploymentRef(r)){let i=r.ref.deployment;if(r.selector===`expanded`){let r=i+`.`;return a=>a.id===i||a.id.startsWith(r)}if(r.selector===`descendants`){let r=i+`.`;return i=>i.id.startsWith(r)}return r.selector===`children`?r=>parentFqn(r.id)===i:r=>r.id===i}if(FqnExpr.isModelRef(r)){let i=r.ref.model;if(r.selector===`expanded`){let r=i+`.`;return a=>{let o=a.modelRef??null;return o?o===i||o.startsWith(r):!0}}if(r.selector===`descendants`){let r=i+`.`;return i=>{let a=i.modelRef??null;return a?a.startsWith(r):!0}}return r.selector===`children`?r=>{let a=r.modelRef??null;return a?parentFqn(a)===i:!0}:r=>{let a=r.modelRef??null;return a?a===i:!0}}nonexhaustive(r)}function instanceSummary(r){return preferSummary(r.$instance)??preferSummary(r.element.$element)}function deploymentNodeToNodeSource(r){let i=r.id,a=r.onlyOneInstance();return exact({id:i,deploymentRef:i,title:r.title,kind:r.kind,technology:r.technology??void 0,links:t$16(r.links,1)?[...r.links]:void 0,notation:r.$node.notation??void 0,color:r.color,shape:r.shape,modelRef:a?.element.id,icon:r.style.icon,description:preferSummary(r.$node)??void 0,tags:[...r.tags],style:n$2(r.style,[`icon`,`shape`,`color`])})}function instanceToNodeSource(r){let i=r.$instance,a=r.element,{icon:o,color:s,shape:c,...l}=r.style,u=[...a.links,...i.links??[]];return exact({id:r.id,kind:`instance`,title:r.title,description:instanceSummary(r)??void 0,technology:r.technology??void 0,tags:[...r.tags],links:t$16(u,1)?u:void 0,icon:o,color:s,shape:c,style:l,deploymentRef:i.id,modelRef:a.id,notation:i.notation})}function toNodeSource(r){return r.isInstance()?instanceToNodeSource(r):deploymentNodeToNodeSource(r)}function toComputedEdges$1(r){return r.reduce((r,i)=>{let a=[...i.relations.model,...i.relations.deployment];invariant(t$16(a,1),`Edge must have at least one relation`);let o=i.source.$model.$styles.defaults,s=i.source.id,c=i.target.id,{title:l,color:u=o.relationship.color,line:d=o.relationship.line,head:f=o.relationship.arrow,...p}=mergePropsFromRelationships(a.map(r=>r.$relationship)),m=exact({id:i.id,parent:i.boundary?.id??null,source:s,target:c,label:l??null,relations:a.map(r=>r.id),color:u,line:d,head:f,...p}),h=r.find(r=>r.source===c&&r.target===s);if(h&&m.label===h.label){h.dir=`both`;let a=h.head??m.head??i.source.$model.$styles.defaults.relationship.arrow;return h.head??=a,h.tail??=a,m.color&&(h.color??=m.color),m.line&&(h.line??=m.line),r}return r.push(m),r},[])}function buildNodes$1(r,i){let a=buildComputedNodes(r.$styles,[...i.final].map(toNodeSource));for(let i of a.values()){if(!i.deploymentRef||!i.modelRef||i.children.length>0)continue;let a=r.deployment.element(i.deploymentRef),o=a.isDeploymentNode()&&a.onlyOneInstance();if(!o)continue;i.title===a.name&&(i.title=o.title),i.description??=instanceSummary(o)??null,i.technology??=o.technology,e$2(i.tags)&&(i.tags=[...o.tags]),(!i.links||e$2(i.links))&&t$16(o.links,1)&&(i.links=[...o.links]);let s=r.$styles.defaults;i.shape===s.shape&&i.shape!==o.shape&&(i.shape=o.shape,i.notation=null),i.color===s.color&&i.color!==o.color&&(i.color=o.color,i.notation=null),!i.icon&&o.icon&&(i.icon=o.icon)}return a}function applyDeploymentViewRuleStyles(r,i){for(let a of r)!isViewRuleStyle(a)||a.targets.length===0||applyViewRuleStyle(a,t$8(a.targets.map(deploymentExpressionToPredicate)),i);return i}function findCrossBoundarySameSourceOrTarget(r){let i=new import_default_map.default(()=>[]);for(let a of r)for(let r of a.relations.model)i.get(r).push(a);let a=new import_default_map.default(()=>new Set);for(let[r,o]of i)t$16(o,2)&&t$3(o,t$17(r=>[{group:`$source-${r.source.id}`,conn:r},{group:`$target-${r.target.id}`,conn:r}]),t$18(e$6(`group`)),t$19(),n(t$16(2)),t$6(t$20(t$4(e$6(`conn`)),sortConnectionsByBoundaryHierarchy(`desc`),t$10((r,i,a)=>i===0||r.boundary===a[i-1].boundary),t$6(i=>{a.get(i).add(r)}))));return a}function findCrossBoundaryConnections(r){r=mergeConnections(r);let i=findCrossBoundarySameSourceOrTarget(r);for(let a of r){let{source:r,target:o}=a,s=a.relations.model;if(r.isDeploymentNode()!==o.isDeploymentNode()){let o=r.isDeploymentNode()?r:a.target;invariant(o.isDeploymentNode());let c=intersection(s,o.internalModelRelationships());for(let r of c)i.get(a).add(r);continue}if(r.isDeploymentNode()&&o.isDeploymentNode()){let s=union(intersection(a.relations.model,r.internalModelRelationships()),intersection(a.relations.model,o.internalModelRelationships()));for(let r of s)i.get(a).add(r)}}return t$3(i.entries(),imap(([r,i])=>r.update({model:i,deployment:null})),toArray())}function cleanCrossBoundary(r){return differenceConnections(r,findCrossBoundaryConnections(r))}function findRedundantConnections$1(r){return t$3(r,mergeConnections,t$12((i,a)=>{let{source:o,target:s,relations:c}=a;if(o.isInstance()&&s.isInstance())return i;let l=RelationshipsAccum.empty();if(o.isDeploymentNode()&&s.isDeploymentNode()){let[r]=findConnection$1(s,o,`directed`);r&&(l=c.intersect(r.relations))}for(let i of r)isNestedConnection(i,a)&&(l=l.union(c.intersect(i.relations)));return l.nonEmpty&&i.push(new DeploymentConnectionModel(o,s,l)),i},[]))}function cleanRedundantRelationships(r){return differenceConnections(r,findRedundantConnections$1(r))}var StageInclude=class extends AbstractStageInclude{connectWithExisting(r,i=`both`){let a=this._connections.length,o=()=>this._connections.length>a;if(!isIterable(r)){if(i===`in`||i===`both`)for(let i of this.memory.elements)this.addConnections(findConnection$1(i,r,`directed`));return(i===`out`||i===`both`)&&this.addConnections(findConnectionsBetween$1(r,this.memory.elements,`directed`)),o()}let s=[...r];if(i===`in`||i===`both`)for(let r of this.memory.elements)this.addConnections(findConnectionsBetween$1(r,s,`directed`));if(i===`out`||i===`both`)for(let r of s)this.addConnections(findConnectionsBetween$1(r,this.memory.elements,`directed`));return o()}processConnections(r){let i=t$3(r,cleanCrossBoundary,cleanRedundantRelationships);return t$3(i,t$6(({source:r,target:i,boundary:a})=>{t$3(t$9([...toArray(r.ancestors()).reverse(),r],[...toArray(i.ancestors()).reverse(),i]),t$10(([r,i])=>r===i),n$1(1),t$6(([o,s])=>{if(r===o&&i===s){this.addImplicit(a);return}o!==r&&o.isDeploymentNode()&&!o.onlyOneInstance()&&this.addImplicit(o),s!==i&&s.isDeploymentNode()&&!s.onlyOneInstance()&&this.addImplicit(s)}))})),i}},Memory=class r extends AbstractMemory{static empty(){return new r({elements:new Set,explicits:new Set,final:new Set,connections:[]})}stageInclude(r){return new StageInclude(this,r)}stageExclude(r){return new StageExclude$1(this,r)}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(i){return new r({...this.state,...i})}equals(i){return i instanceof r&&t$13(this.state,i.state)}diff(r){return{added:{elements:toArray(difference(r.elements,this.elements)),explicits:toArray(difference(r.explicits,this.explicits)),final:toArray(difference(r.final,this.final)),connections:toArray(differenceConnections(r.connections,this.connections))},removed:{elements:toArray(difference(this.elements,r.elements)),explicits:toArray(difference(this.explicits,r.explicits)),final:toArray(difference(this.final,r.final)),connections:differenceConnections(this.connections,r.connections)}}}toString(){return[`final:`,...[...this.final].map(r=>` `+r.id),`connections:`,...this.connections.map(r=>` `+r.expression)].join(`
|
|
2
|
+
`)}[customInspectSymbol](r,i,a){return this.toString()}};const WhereDeploymentRefPredicate={include:({expr:r,model:i,memory:a,stage:o})=>{let s=whereOperatorAsPredicate(r.where.condition);return predicateToPatch(`include`,{expr:r.where.expr,model:i,stage:o,memory:a,where:s})},exclude:({expr:r,model:i,memory:a,stage:o})=>{let s=whereOperatorAsPredicate(r.where.condition);return predicateToPatch(`exclude`,{expr:r.where.expr,model:i,stage:o,memory:a,where:s})}},IncomingRelationPredicate={include:({expr:r,model:i,memory:a,stage:o,where:s})=>{let c=[...a.elements];if(FqnExpr.isWildcard(r.incoming)){for(let r of c){if(r.allOutgoing.isEmpty)continue;let i=applyPredicate(findConnectionsBetween$1(r,[...resolveAscendingSiblings(r)],`directed`),s);o.addConnections(i)}return o}invariant(FqnExpr.isDeploymentRef(r.incoming),`Only deployment refs are supported in include`);let l=resolveElements$1(i,r.incoming);for(let r of c){let i=applyPredicate(findConnectionsBetween$1(r,l,`directed`),s);o.addConnections(i)}return o},exclude:({expr:r,model:i,memory:a,stage:o,where:s})=>{if(FqnExpr.isElementTagExpr(r.incoming)||FqnExpr.isElementKindExpr(r.incoming))throw Error(`element kind and tag expressions are not supported in exclude`);if(FqnExpr.isModelRef(r.incoming))return excludeModelRelations(resolveAllImcomingRelations(i,r.incoming),{stage:o,memory:a},s);if(FqnExpr.isWildcard(r.incoming))return o;let c=filterIncomingConnections(resolveElements$1(i,r.incoming)),l=t$3(a.connections,n(c),applyPredicate(s));return o.excludeConnections(l),o}};function filterIncomingConnections(r){return t$8(r.map(r=>{let i=i=>i===r||isAncestor(r,i);return r=>!i(r.source)&&i(r.target)}))}function resolveAllImcomingRelations(r,i){let a=resolveModelElements(r,i);return new Set(a.flatMap(r=>[...r.allIncoming]))}const OutgoingRelationPredicate={include:({expr:r,model:i,memory:a,stage:o,where:s})=>{let c=[...a.elements];if(FqnExpr.isWildcard(r.outgoing)){for(let r of c)if(!r.allIncoming.isEmpty)for(let i of resolveAscendingSiblings(r)){let a=applyPredicate(findConnection$1(i,r,`directed`),s);o.addConnections(a)}return o}invariant(FqnExpr.isDeploymentRef(r.outgoing),`Only deployment refs are supported in include`);let l=resolveElements$1(i,r.outgoing);for(let r of l){let i=applyPredicate(findConnectionsBetween$1(r,c,`directed`),s);o.addConnections(i)}return o},exclude:({expr:r,model:i,memory:a,stage:o,where:s})=>{if(FqnExpr.isElementTagExpr(r.outgoing)||FqnExpr.isElementKindExpr(r.outgoing))throw Error(`element kind and tag expressions are not supported in exclude`);if(FqnExpr.isModelRef(r.outgoing))return excludeModelRelations(resolveAllOutgoingRelations(i,r.outgoing),{stage:o,memory:a},s);if(FqnExpr.isWildcard(r.outgoing))return o;let c=filterOutgoingConnections(resolveElements$1(i,r.outgoing)),l=t$3(a.connections,n(c),applyPredicate(s));return o.excludeConnections(l),o}};function filterOutgoingConnections(r){return t$8(r.map(r=>{let i=i=>i===r||isAncestor(r,i);return r=>i(r.source)&&!i(r.target)}))}function resolveAllOutgoingRelations(r,i){let a=resolveModelElements(r,i);return new Set(a.flatMap(r=>[...r.allOutgoing]))}const DirectRelationPredicate={include:({expr:{source:r,target:i,isBidirectional:a=!1},model:o,stage:s,where:c})=>{if(FqnExpr.isElementTagExpr(r)||FqnExpr.isElementKindExpr(r)||FqnExpr.isElementTagExpr(i)||FqnExpr.isElementKindExpr(i))throw Error(`element kind and tag expressions are not supported in include`);invariant(!FqnExpr.isModelRef(r),`Invalid source model ref in direct relation`),invariant(!FqnExpr.isModelRef(i),`Invalid target model ref in direct relation`);let l=FqnExpr.isWildcard(r),u=FqnExpr.isWildcard(i),f=a?`both`:`directed`,p;switch(!0){case l&&u:p=t$3(findConnectionsWithin$1(o.instances()),applyPredicate(c),t$4(r=>(s.addImplicit(r.boundary),r)));break;case!l&&u:{let i=resolveElements$1(o,r),s=filterOutgoingConnections(i),l=s;if(a){let r=filterIncomingConnections(i);l=i=>s(i)!==r(i)}p=t$3(i,t$17(r=>findConnectionsBetween$1(r,resolveAscendingSiblings(r),f)),n(l),applyPredicate(c));break}case l&&!u:{let r=resolveElements$1(o,i),s=filterIncomingConnections(r),l=s;if(a){let i=filterOutgoingConnections(r);l=r=>i(r)!==s(r)}p=t$3(r,t$17(r=>[...resolveAscendingSiblings(r)].flatMap(i=>findConnection$1(i,r,f))),n(l),applyPredicate(c));break}default:{invariant(!l,`Inferrence failed - source should be a deployment ref`),invariant(!u,`Inferrence failed - target should be a deployment ref`);let a=resolveElements$1(o,r),s=resolveElements$1(o,i),m=filterOutgoingConnections(a),h=filterIncomingConnections(s);p=t$3(a,t$17(r=>findConnectionsBetween$1(r,s,f)),n(r=>m(r)&&h(r)),applyPredicate(c))}}return s.addConnections(p),FqnExpr.isDeploymentRef(r)&&e$7(r.selector)&&s.addImplicit(o.element(r.ref.deployment)),FqnExpr.isDeploymentRef(i)&&e$7(i.selector)&&s.addImplicit(o.element(i.ref.deployment)),s},exclude:({expr:r,model:i,memory:a,stage:o,where:s})=>{let c=deploymentExpressionToPredicate(r.target),l=deploymentExpressionToPredicate(r.source),u;switch(!0){case FqnExpr.isWildcard(r.source)&&FqnExpr.isWildcard(r.target):return o.excludeConnections(applyPredicate(a.connections,s)),o;case FqnExpr.isModelRef(r.source)&&FqnExpr.isModelRef(r.target):return u=resolveRelationsBetweenModelElements({source:r.source,target:r.target,expr:r,model:i}),excludeModelRelations(u,{stage:o,memory:a},s);case FqnExpr.isModelRef(r.source)&&FqnExpr.isWildcard(r.target):return u=resolveAllOutgoingRelations(i,r.source),excludeModelRelations(u,{stage:o,memory:a},s);case FqnExpr.isModelRef(r.source):return u=resolveAllOutgoingRelations(i,r.source),excludeModelRelations(u,{stage:o,memory:a},s,r=>c(r.target));case FqnExpr.isModelRef(r.target):return u=resolveAllImcomingRelations(i,r.target),excludeModelRelations(u,{stage:o,memory:a},s,r=>l(r.source));default:let d=i=>l(i.source)&&c(i.target)||r.isBidirectional===!0&&l(i.target)&&c(i.source),f=t$3(a.connections,n(d),applyPredicate(s));return f.length===0||o.excludeConnections(f),o}}};function resolveRelationsBetweenModelElements({source:r,target:i,expr:a,model:o}){let s=resolveModelElements(o,r),c=resolveModelElements(o,i),l=a.isBidirectional?`both`:`directed`,u=[];for(let r of s)u.push(...findConnectionsBetween$3(r,c,l));return new Set(u.flatMap(r=>[...r.relations]))}const InOutRelationPredicate$1={include:({expr:r,model:i,memory:a,stage:o,where:s})=>{let c=[...a.elements];if(FqnExpr.isWildcard(r.inout)){for(let r of c){let i=matchConnections(findConnectionsBetween$1(r,[...resolveAscendingSiblings(r)],`both`),s);o.addConnections(i)}return o}invariant(FqnExpr.isDeploymentRef(r.inout),`Only deployment refs are supported in include`);let l=resolveElements$1(i,r.inout);for(let r of c){let i=matchConnections(findConnectionsBetween$1(r,l,`both`),s);o.addConnections(i)}return o},exclude:({expr:r,model:i,memory:a,stage:o,where:s})=>{if(FqnExpr.isElementTagExpr(r.inout)||FqnExpr.isElementKindExpr(r.inout))throw Error(`element kind and tag expressions are not supported in exclude`);if(FqnExpr.isModelRef(r.inout)){let c=resolveModelElements(i,r.inout);return c.length===0?o:excludeModelRelations(union(new Set,...c.flatMap(r=>[r.allIncoming,r.allOutgoing])),{stage:o,memory:a},s)}if(FqnExpr.isWildcard(r.inout))return o;let c=resolveElements$1(i,r.inout),l=filterIncomingConnections(c),u=filterOutgoingConnections(c),d=t$3(a.connections,n(r=>l(r)!==u(r)),applyPredicate(s));return o.excludeConnections(d),o}},WhereRelationPredicate={include:({expr:r,model:i,memory:a,stage:o})=>{let s=whereOperatorAsPredicate(r.where.condition);return predicateToPatch(`include`,{expr:r.where.expr,model:i,stage:o,memory:a,where:s})},exclude:({expr:r,model:i,memory:a,stage:o})=>{let s=whereOperatorAsPredicate(r.where.condition);return predicateToPatch(`exclude`,{expr:r.where.expr,model:i,stage:o,memory:a,where:s})}},WildcardPredicate$1={include:({model:r,stage:i,where:a})=>{let o=[],s=t$3([...r.roots()],applyElementPredicate(a),t$4(r=>(r.onlyOneInstance()||o.push(...r.children()),r)));return i.addExplicit(s),o.length>1&&i.addConnections(findConnectionsWithin$1([...s,...o])),i},exclude:({stage:r,memory:i,where:a})=>{let o=t$3([...i.elements],applyElementPredicate(a));return r.exclude(o),r}};function predicateToPatch(r,{expr:i,where:a,...o}){switch(!0){case FqnExpr.isElementTagExpr(i):case FqnExpr.isElementKindExpr(i):throw Error(`element kind and tag expressions are not supported in deployment view rules`);case RelationExpr.isCustom(i):case FqnExpr.isCustom(i):case FqnExpr.isModelRef(i):return;case FqnExpr.isWhere(i):return WhereDeploymentRefPredicate[r]({...o,expr:i,where:a});case RelationExpr.isWhere(i):return WhereRelationPredicate[r]({...o,expr:i,where:a});case FqnExpr.isDeploymentRef(i):return DeploymentRefPredicate[r]({...o,expr:i,where:a});case FqnExpr.isWildcard(i):return WildcardPredicate$1[r]({...o,expr:i,where:a});case RelationExpr.isDirect(i):return DirectRelationPredicate[r]({...o,expr:i,where:a});case RelationExpr.isInOut(i):return InOutRelationPredicate$1[r]({...o,expr:i,where:a});case RelationExpr.isOutgoing(i):return OutgoingRelationPredicate[r]({...o,expr:i,where:a});case RelationExpr.isIncoming(i):return IncomingRelationPredicate[r]({...o,expr:i,where:a});default:nonexhaustive(i)}}function excludeModelRelations(r,{stage:i,memory:a},o,s=()=>!0){if(r.size===0)return i;let c=t$3(a.connections,n(r=>s(r)),n(i=>hasIntersection(i.relations.model,r)),t$4(i=>i.update({deployment:null,model:intersection(i.relations.model,r)})),applyPredicate(o),n(r=>r.nonEmpty()));return c.length===0?i:i.excludeConnections(c)}function matchConnection(r,i){return applyPredicate(r,i).nonEmpty()}function applyPredicate(...r){if(r.length===1)return i=>applyPredicate(i,r[0]);let[a,o]=r;return o===null?a:e$8(a)?a.map(r=>applyPredicate(r,o)).filter(r=>r.nonEmpty()):a.update({model:new Set([...a.relations.model.values()].filter(r=>o(toFilterableRelation(a)(r)))),deployment:new Set([...a.relations.deployment.values()].filter(r=>o(toFilterableRelation(a)(r))))})}function applyElementPredicate(...r){if(r.length===1)return i=>applyElementPredicate(i,r[0]);let[a,o]=r;return e$8(a)?a.filter(r=>applyElementPredicate(r,o)):o?.(toFilterable(a,a))??!0}function matchConnections(r,i){return i?t$3(r,n(r=>matchConnection(r,i))):r}function toFilterable(r,i){if(isElementModel(r)){let a=isDeploymentElementModel(i)&&isDeployedInstanceModel(i)?i:null;return{kind:r.kind,tags:[...r.tags,...a?.tags??[]]}}if(isNestedElementOfDeployedInstanceModel(r))return t$11(r.element,[`tags`,`kind`]);if(isDeployedInstanceModel(r))return{kind:r.element.kind,tags:[...r.tags,...r.element.tags]};if(isDeploymentNodeModel(r))return t$11(r,[`tags`,`kind`]);nonexhaustive(r)}function toFilterableRelation(r){return i=>({tags:i.tags,kind:i.kind,source:toFilterable(i.source,r.source),target:toFilterable(i.target,r.target)})}function resolveAscendingSiblings(r){let i=new Set;for(let a of r.descendingSiblings())i.add(a);return i}const DeploymentRefPredicate={include:r=>{let{expr:i,where:a}=r,o=r.model.element(i.ref.deployment);if(isDeployedInstanceModel(o))return applyElementPredicate(o,a)&&(r.stage.addExplicit(o),r.stage.connectWithExisting(o)),r.stage;switch(!0){case i.selector===`expanded`:includeDeployedNodeWithExpanded(o,r);break;case i.selector===`children`:includeDeployedNodeChildren(o,r);break;case i.selector===`descendants`:includeDeployedNodeDescendants(o,r);break;default:applyElementPredicate(o,a)&&(r.stage.addExplicit(o),r.stage.connectWithExisting(o))}return r.stage},exclude:({expr:r,stage:i,memory:a,where:o})=>{let s=deploymentExpressionToPredicate(r),c=t$3([...a.elements],n(s),applyElementPredicate(o));return i.exclude(c),i}};function includeDeployedNodeChildren(r,{stage:i,where:a}){let o=applyElementPredicate([...r.children()],a);o.length!==0&&(i.addImplicit(r),i.addConnections(findConnectionsWithin$1(o)),i.connectWithExisting(o),i.addExplicit(o))}function includeDeployedNodeWithExpanded(r,{memory:i,stage:a,where:o}){a.addImplicit(r),a.connectWithExisting(r);let s=applyElementPredicate([...r.children()],o),c=!1;for(let r of s)if(findConnectionsBetween$1(r,i.elements).length>0){c=!0;break}c&&(a.connectWithExisting(s,`in`),a.addConnections(findConnectionsWithin$1(s)),a.connectWithExisting(s,`out`)),a.addImplicit(s),a.connections.length>0&&a.addExplicit(r)}function includeDeployedNodeDescendants(r,{stage:i,where:a}){let o=r=>{let s=[];for(let i of r.children())i.isDeploymentNode()&&s.push(...o(i)),applyElementPredicate(i,a)&&s.push(i);return i.connectWithExisting(s,`in`),i.addConnections(findConnectionsWithin$1(s)),i.addImplicit(s),s},c=o(r);if(c.length===0)return;i.connectWithExisting(c,`out`);let l=findConnectedElements(i);t$3(c,n(r=>l.has(r)),t$6(r=>i.addExplicit(r)))}function findConnectedElements(r){return t$3(r.mergedConnections(),cleanCrossBoundary,cleanRedundantRelationships,t$12((r,i)=>(r.add(i.source),r.add(i.target),r),new Set))}var StageFinal$1=class r{static for(i){return new r(i)}constructor(r){this.memory=r}step1CleanConnections(r){if(r.connections.length<2)return r;let i=t$3(r.connections,cleanCrossBoundary,cleanRedundantRelationships),a=differenceConnections(r.connections,i);if(a.length===0)return r;let o=r.stageExclude({});return o.excludeConnections(a,!0),o.commit()}step2ProcessImplicits(r){let i=union(this.memory.elements,r.elements),a=union(r.final,this.memory.explicits),o=new import_default_map.default(()=>new Set);for(let i of r.connections)if(i.boundary)for(let r of i.relations.model)o.get(r).add(i.boundary);for(let[r,s]of o)if(!(s.size<2))for(let r of s)i.delete(r)&&a.add(r);let c=new Set(a),l=r=>{for(let i of c)if(r===i||isAncestor(r,i))return!0;return!1};return t$3(difference(i,c),ifilter(r=>r.isDeploymentNode()),toArray(),sortByFqnHierarchically,t$6(r=>{let i=[...r.children()].filter(l).length;if(i>=2){a.add(r);return}i===1&&isome(r.siblings(),l)&&a.add(r)})),r.update({final:a})}step3ProcessBoundaries(r){let i=new Set;for(let a of r.connections)a.boundary&&i.add(a.boundary);let a=treeFromMemoryState(r,`final`),o=r.stageExclude({}),s=o=>!(i.has(o)||r.explicits.has(o)||a.hasInOut(o)||a.root.has(o)),c=t$14([...a.root]);c&&!r.explicits.has(c)&&o.exclude(c);for(let i of r.final){let r=t$14(a.children(i));r&&!a.hasInOut(r)&&s(i)&&o.exclude(i)}return o.isDirty()?o.commit():r}commit(){let r=this.step1CleanConnections(this.memory),i=this.step2ProcessImplicits(r);return this.step3ProcessBoundaries(i)}};function processPredicates$1(r,i){let a=Memory.empty();for(let o of i)if(isViewRulePredicate(o)){let i=`include`in o?`include`:`exclude`,s=o.include??o.exclude;for(let o of s){let s=i===`include`?a.stageInclude(o):a.stageExclude(o);s=predicateToPatch(i,{expr:o,model:r,stage:s,memory:a,where:null})??s,a=s.commit()}}return StageFinal$1.for(a).commit()}function computeDeploymentView(r,{docUri:i,rules:a,...o}){let s=processPredicates$1(r.deployment,a),c=buildNodes$1(r,s),l=toComputedEdges$1(s.connections);linkNodesWithEdges(c,l);let d=topologicalSort({nodes:c,edges:l}),f=applyDeploymentViewRuleStyles(a,d.nodes),p=t$21(a,isViewRuleAutoLayout),m=buildElementNotations(f);return calcViewLayoutHash({...o,[_stage]:`computed`,[_type]:`deployment`,autoLayout:{direction:p?.direction??`TB`,...p?.nodeSep&&{nodeSep:p.nodeSep},...p?.rankSep&&{rankSep:p.rankSep}},edges:d.edges,nodes:t$4(f,r=>(r.icon===`none`&&delete r.icon,r)),...m.length>0&&{notation:{nodes:m}}})}function flattenGroupRules(r){return i=>isViewRuleGroup(i)?i.groupRules.flatMap(flattenGroupRules(r)):isViewRulePredicate(i)&&`include`in i?i.include.filter(r):[]}function applyCustomElementProperties(r,i){let a=r.flatMap(flattenGroupRules(ModelFqnExpr.isCustom));if(a.length===0)return i;let o=[...i];for(let{custom:{expr:r,...i}}of a){let{border:a,opacity:s,multiple:c,iconColor:u,iconSize:d,iconPosition:f,padding:m,size:h,textSize:g,..._}=t$22(i,e$5),v=exact({border:a,opacity:s,multiple:c,iconColor:u,iconSize:d,iconPosition:f,padding:m,size:h,textSize:g}),y=!e$9(v),b=!e$9(_),x=elementExprToPredicate(r);o.forEach((r,i)=>{isGroupElementKind(r)||!x(r)||(b&&(r={...r,..._,isCustomized:!0}),y&&(r={...r,isCustomized:!0,style:{...r.style,...v}}),o[i]=r)})}return o}function resolveGlobalRulesInElementView(r,i){return r.reduce((r,a)=>{if(isViewRuleGlobalPredicateRef(a)){let o=i.predicates[a.predicateId];return e$5(o)?r:r.concat(o)}if(isViewRuleGlobalStyle(a)){let o=i.styles[a.styleId];return e$5(o)?r:r.concat(o)}return r.push(a),r},[])}function resolveGlobalRulesInDynamicView(r,i){return r.reduce((r,a)=>{if(isViewRuleGlobalPredicateRef(a)){let o=i.dynamicPredicates[a.predicateId];return e$5(o)?r:r.concat(o)}if(isViewRuleGlobalStyle(a)){let o=i.styles[a.styleId];return e$5(o)?r:r.concat(o)}return r.push(a),r},[])}function elementsFromIncludeProperties(r,i){let a=new Set;for(let o of i)if(isViewRulePredicate(o))for(let i of o.include){let o=elementExprToPredicate(i);for(let i of r.elements())o(i)&&a.add(i)}return a}const flattenSteps=r=>{if(isDynamicStepsParallel(r)){let i=[],a=[];for(let o of r.__parallel)if(isDynamicStepsSeries(o)){let[r,...s]=o.__series;i.push(r),a.push(...s)}else i.push(o);return[...i,...a]}return isDynamicStepsSeries(r)?[...r.__series]:r};function elementsFromSteps(r,i){let a=[],o=(...[r,i])=>{if(!a.includes(r)){let o=a.indexOf(i);if(o>0){a.splice(o,0,r);return}else a.push(r)}a.includes(i)||a.push(i)};for(let s of t$17(i,flattenSteps)){let i=r.element(s.source),c=r.element(s.target),l=a.indexOf(i),u=a.indexOf(c);l>=0&&u>=0||(s.isBackward?o(c,i):o(i,c))}return new Set(a)}function findRelations(r,i,a){let o=findConnection$3(r,i,`directed`).flatMap(r=>[...r.relations]).sort(compareRelations);if(!isNonEmptyArray(o))return{};if(o.length===1){let r=o[0];return exact({title:r.title??void 0,kind:r.kind??void 0,tags:r.tags,relations:[r.id],navigateTo:r.$relationship.navigateTo,color:r.$relationship.color,line:r.$relationship.line,technology:r.technology??void 0,description:r.$relationship.description??void 0})}let s=t$3(o,t$17(r=>r.tags),n$3()),c=t$16(s,1)?s:void 0,l=t$4(o,r=>r.id),u=n$4(o).$relationship.navigateTo;u===a&&(u=void 0),u||=t$3(o,t$17(r=>r.$relationship.navigateTo&&r.$relationship.navigateTo!==a?r.$relationship.navigateTo:[]),n$3(),t$14());let f=t$3(o,t$12((r,{title:i,technology:a,$relationship:o})=>(e(i)&&r.title.add(i),e(o.color)&&r.color.add(o.color),e(o.line)&&r.line.add(o.line),e(o.kind)&&r.kind.add(o.kind),e(a)&&r.technology.add(a),e(o.description)&&!r.description.some(t$13(o.description))&&r.description.push(o.description),r),{kind:new Set,color:new Set,line:new Set,title:new Set,technology:new Set,description:[]}));return exact({tags:c??void 0,relations:l,navigateTo:u,kind:t$14([...f.kind]),title:t$14([...f.title]),color:t$14([...f.color]),line:t$14([...f.line]),technology:t$14([...f.technology]),description:t$14(f.description)})}var DynamicViewCompute=class{steps=[];constructor(r,i){this.model=r,this.view=i}compute(){let{docUri:r,rules:i,steps:a,...o}=this.view,s=resolveGlobalRulesInDynamicView(i,this.model.globals),c=elementsFromIncludeProperties(this.model,s),l=elementsFromSteps(this.model,a),d=t$3(union(intersection(c,l),l,c),toArray(),sortParentsFirst),f=d.reduce((r,i,a,o)=>{for(let s=a+1;s<o.length;s++){let a=o[s];if(isAncestor(i,a)){r.push(i);break}}return r},[]),p=(r,i,a)=>{if(isDynamicStepsSeries(r)){for(let o of r.__series)i=p(o,i,a);return i}let o=a?stepEdgeId(a,i):stepEdgeId(i),{source:s,target:c,title:l,isBackward:u,navigateTo:m,notation:g,..._}=r,v=this.model.element(s),y=d.indexOf(v);invariant(y>=0,`Source ${s} not found`);let b=this.model.element(c),x=d.indexOf(b);invariant(x>=0,`Target ${c} not found`),(f.includes(v)||f.includes(b))&&console.error(`Step ${v.id} -> ${b.id} because it involves a compound`);let{title:S,relations:C,navigateTo:w,...T}=findRelations(v,b,this.view.id),E=e(m)&&m!==this.view.id?m:w,D=r.kind&&!r.technology?this.model.specification.relationships[r.kind]?.technology:void 0;return this.steps.push(exact({...T,..._,...D&&{technology:D},id:o,source:v,target:b,navigateTo:E,title:l??S,relations:C??[],isBackward:y>x})),i+1},m=1;for(let r of a){if(isDynamicStepsParallel(r)){let i=1;for(let a of r.__parallel)i=p(a,i,m);m++;continue}m=p(r,m)}let g=buildComputedNodes(this.model.$styles,d.map(elementModelToNodeSource)),_=this.model.$styles.defaults.relationship,v=this.steps.map(({id:r,source:i,target:a,relations:o,title:s,isBackward:c,tags:l,...u})=>{let d=nonNullable(g.get(i.id),`Source node ${i.id} not found`),f=nonNullable(g.get(a.id),`Target node ${a.id} not found`),p={id:r,parent:commonAncestor(i.id,a.id),source:d.id,target:f.id,label:s??null,relations:o,color:_.color,line:_.line,head:_.arrow,tags:l??[],...u};for(c&&(p.dir=`back`);p.parent&&!g.has(p.parent);)p.parent=parentFqn(p.parent);d.outEdges.push(p.id),f.inEdges.push(p.id);for(let r of ancestorsFqn(p.source)){if(r===p.parent)break;g.get(r)?.outEdges.push(p.id)}for(let r of ancestorsFqn(p.target)){if(r===p.parent)break;g.get(r)?.inEdges.push(p.id)}return p}),y=applyCustomElementProperties(s,applyViewRuleStyles(s,d.map(r=>nonNullable(g.get(r.id))))),x=t$21(s,isViewRuleAutoLayout),S=buildElementNotations(y);return calcViewLayoutHash({...o,[_type]:`dynamic`,[_stage]:`computed`,variant:o.variant??`diagram`,autoLayout:{direction:x?.direction??`LR`,...x?.nodeSep&&{nodeSep:x.nodeSep},...x?.rankSep&&{rankSep:x.rankSep}},nodes:t$4(y,r=>(r.icon===`none`&&delete r.icon,r)),edges:v,...S.length>0&&{notation:{nodes:S}}})}};function computeDynamicView(r,i){return new DynamicViewCompute(r,i).compute()}function relationExpressionToPredicates(r){switch(!0){case ModelRelationExpr.isCustom(r):return relationExpressionToPredicates(r.customRelation.expr);case ModelRelationExpr.isWhere(r):{let i=relationExpressionToPredicates(r.where.expr),a=whereOperatorAsPredicate(r.where.condition);return r=>i(r)&&a({source:{tags:r.source.tags,kind:r.source.kind},target:{tags:r.target.tags,kind:r.target.kind},...r.tags&&{tags:r.tags},...r.kind&&{kind:r.kind}})}case ModelRelationExpr.isDirect(r):{let i=elementExprToPredicate(r.source),a=elementExprToPredicate(r.target);return o=>i(o.source)&&a(o.target)||!!r.isBidirectional&&i(o.target)&&a(o.source)}case ModelRelationExpr.isInOut(r):{let i=elementExprToPredicate(r.inout);return r=>i(r.source)||i(r.target)}case ModelRelationExpr.isIncoming(r):{let i=elementExprToPredicate(r.incoming);return r=>i(r.target)}case ModelRelationExpr.isOutgoing(r):{let i=elementExprToPredicate(r.outgoing);return r=>i(r.source)}default:nonexhaustive(r)}}function applyCustomRelationProperties(r,i,a){let o=r.flatMap(flattenGroupRules(ModelRelationExpr.isCustom)),s=Array.from(a);if(o.length===0||s.length===0)return s;for(let{customRelation:{expr:r,title:a,description:c,notes:l,...u}}of o){let o=c?{description:MarkdownOrString(c)}:{},d=l?{notes:MarkdownOrString(l)}:{},f=t$22(u,e$5),m=relationExpressionToPredicates(r);s.forEach((r,c)=>{let l,u;for(let a of i)if(a.id===r.source&&(l=a),a.id===r.target&&(u=a),l&&u)break;!l||!u||m({source:l,target:u,...t$11(r,[`kind`,`tags`])})&&(s[c]={...r,...f,...o,...d,label:a??r.label,isCustomized:!0})})}return s}function findRedundantConnections(r){return t$3([...r],mergeConnections,t$12((r,i,a,o)=>{let s=findDescendantConnections(o,i),c=union(...s.map(e$6(`relations`))),l=intersection(i.relations,c);if(s.length>0&&(l=union(l,i.directRelations)),findDeepestNestedConnection(o,i.reversed())&&(l=union(l,i.directRelations)),l.size<i.relations.size){let r=o.some(isAnyInOut(i.source)),a=o.some(isAnyInOut(i.target));r&&(l=union(l,toSet(ifilter(i.relations,isOutgoing(i.source))))),a&&(l=union(l,toSet(ifilter(i.relations,isIncoming(i.target)))))}return l.size>0&&r.push(i.update(l)),r},[]))}var StageFinal=class r{static for(i){return new r(i)}constructor(r){this.memory=r}step1CleanConnections(r){if(r.connections.length<2)return r;let i=findRedundantConnections(r.connections);if(i.length===0)return r;let a=r.stageExclude({});return a.excludeConnections(i,!0),a.commit()}step2ProcessImplicits(r){let i=union(this.memory.elements,r.elements),a=union(r.final,this.memory.explicits),o=new Set(a),c=r=>{for(let i of o)if(r===i||isAncestor(r,i))return!0;return!1};return t$3(difference(i,o),toArray(),sortByFqnHierarchically,t$6(r=>{let i=[...r.children()].filter(c).length;if(i>=2){a.add(r);return}i===1&&isome(r.siblings(),c)&&a.add(r)})),r.update({final:a})}step3ProcessBoundaries(r){let i=new Set;for(let a of r.connections)a.boundary&&a.boundary!==a.source&&a.boundary!==a.target&&i.add(a.boundary);let a=treeFromMemoryState(r,`final`),o=r.stageExclude({}),s=o=>!(i.has(o)||r.explicits.has(o)||a.hasInOut(o)||a.root.has(o)),c=t$14([...a.root]);c&&!r.explicits.has(c)&&o.exclude(c);for(let i of r.final){let r=t$14(a.children(i));r&&!a.hasInOut(r)&&s(i)&&o.exclude(i)}return o.isDirty()?o.commit():r}commit(){let r=this.step1CleanConnections(this.memory),i=this.step2ProcessImplicits(r);return this.step3ProcessBoundaries(i)}};const{findConnection,findConnectionsBetween,findConnectionsWithin}=find_exports;function resolveElements(r,i){switch(!0){case ModelFqnExpr.isElementKindExpr(i):return[...ifilter(r.elements(),r=>i.isEqual===(r.kind===i.elementKind))];case ModelFqnExpr.isElementTagExpr(i):return[...ifilter(r.elements(),r=>i.isEqual===r.tags.includes(i.elementTag))];case i.selector===`expanded`:{let a=r.element(FqnRef.flatten(i.ref));return[a,...a.children()]}case i.selector===`children`:case i.selector===`descendants`:{let a=r.element(FqnRef.flatten(i.ref)),o=i.selector===`children`?toArray(a.children()):toArray(a.descendants());return o&&o.length>0?o:[a]}case ModelFqnExpr.isModelRef(i):return[r.element(FqnRef.flatten(i.ref))];default:nonexhaustive(i)}}function includeDescendantsFromMemory(r,i){if(i.isEmpty()||r.length===0)return r;let a=t$8(r.map(r=>isDescendantOf(r))),o=toArray(ifilter(i.elements,i=>!r.includes(i)&&a(i)));return[...r,...o]}function resolveAndIncludeFromMemory(r,{memory:i,model:a}){let o=resolveElements(a,r);return ModelFqnExpr.isModelRef(r)?r.selector===`descendants`?o:includeDescendantsFromMemory(o,i):o}const ExpandedElementPredicate={include:({expr:r,model:i,stage:a,where:o})=>{let s=i.element(FqnRef.flatten(r.ref));o(s)&&(a.addExplicit(s),a.connectWithExisting(s));let c=[...s.children()].filter(o),l=[];for(let r of c)a.addImplicit(r),a.connectWithExisting(r)&&l.push(r);return a.addConnections(findConnectionsWithin(l)),a},exclude:({expr:r,model:i,stage:a,filterWhere:o})=>{let s=o(resolveElements(i,r));return a.exclude(s),a}},ElementKindOrTagPredicate={include:({expr:r,model:i,stage:a,filterWhere:o})=>{let s=o(resolveElements(i,r));if(s.length!==0)return a.addExplicit(s),a.connectWithExisting(s),a.addConnections(findConnectionsWithin(s)),a},exclude:({expr:r,model:i,stage:a,filterWhere:o})=>{let s=o(resolveElements(i,r));return a.exclude(s),a}},ElementRefPredicate={include:({expr:r,model:i,stage:a,filterWhere:o})=>{let s=o(resolveElements(i,r));if(s.length!==0)return a.addExplicit(s),a.connectWithExisting(s),a.addConnections(findConnectionsWithin(s)),a},exclude:({expr:r,model:i,stage:a,filterWhere:o})=>{let s=o(resolveElements(i,r));return a.exclude(s),a}},NoWhere=()=>!0,NoFilter=r=>r;function toComputedEdges(r){return r.reduce((r,i)=>{let a=[...i.relations];invariant(t$16(a,1),`Edge must have at least one relation`);let o=i.source.$model.$styles.defaults,s=i.source.id,c=i.target.id,{title:l,color:u=o.relationship.color,line:d=o.relationship.line,head:f=o.relationship.arrow,...p}=mergePropsFromRelationships(a.map(r=>r.$relationship),t$14(n(a,r=>r.source.id===s&&r.target.id===c))?.$relationship),m=exact({id:i.id,parent:i.boundary?.id??null,source:s,target:c,label:l??null,relations:a.map(r=>r.id),color:u,line:d,head:f,...p});return r.push(m),r},[])}function buildNodes(r,i){return buildComputedNodes(r.$styles,[...i.final].map(elementModelToNodeSource),i.groups)}const isWildcard=ModelFqnExpr.isWildcard,isAncestorOrDescendantOf=(r,i)=>r.isAncestorOf(i)||r.isDescendantOf(i),DirectRelationExprPredicate={include:({expr:{source:r,target:i,isBidirectional:a=!1},memory:o,model:s,stage:c,where:l,filterWhere:u})=>{let f=isWildcard(r),p=isWildcard(i),m=[];switch(!0){case f&&p&&o.isEmpty()&&l!==NoWhere:{let r=t$3(s.relationships(),ifilter(l),toArray(),t$4(r=>new ConnectionModel(r.source,r.target,new Set([r]))));return c.addConnections(r),c}case f&&p&&!o.isEmpty()&&l!==NoWhere:m.push(...findConnectionsWithin(o.elements));break;case f&&p:m.push(...findConnectionsWithin(s.roots()));break;case!f&&p&&l!==NoWhere:{let i=t$3(resolveElements(s,r),t$17(r=>t$3(r,e$10(e$11(a===!0),{onTrue:r=>union(r.allIncoming,r.allOutgoing),onFalse:r=>r.allOutgoing}),ifilter(l),iunique(),toArray(),t$2(i=>i.source===r),([i,a])=>t$23(t$3(i,n(i=>!isAncestorOrDescendantOf(r,i.target)),t$4(i=>new ConnectionModel(r,i.target,new Set([i])))),t$3(a,n(i=>!isAncestorOrDescendantOf(r,i.source)),t$4(i=>new ConnectionModel(i.source,r,new Set([i]))))))));return c.addConnections(i),c}case!f&&p:{let[i,c]=resolveWildcard(r,{memory:o,model:s}),l=a?`both`:`directed`;for(let r of i)m.push(...findConnectionsBetween(r,c,l));break}case f&&!p&&l!==NoWhere:{let r=t$3(resolveElements(s,i),t$17(r=>t$3(r,e$10(e$11(a===!0),{onTrue:r=>union(r.allIncoming,r.allOutgoing),onFalse:r=>r.allIncoming}),ifilter(l),toArray(),t$2(i=>i.target===r),([i,a])=>t$23(t$3(a,n(i=>!isAncestorOrDescendantOf(r,i.target)),t$4(i=>new ConnectionModel(r,i.target,new Set([i])))),t$3(i,n(i=>!isAncestorOrDescendantOf(r,i.source)),t$4(i=>new ConnectionModel(i.source,r,new Set([i]))))))));return c.addConnections(r),c}case f&&!p:{let[r,c]=resolveWildcard(i,{memory:o,model:s}),l=a?`both`:`directed`;for(let i of c)m.push(...findConnectionsBetween(i,r,l));break}default:{invariant(!isWildcard(r),`Inference failed - source must be not a wildcard`),invariant(!isWildcard(i),`Inference failed - target must be not a wildcard`);let c=resolveAndIncludeFromMemory(r,{memory:o,model:s}),l=resolveAndIncludeFromMemory(i,{memory:o,model:s}),u=a?`both`:`directed`;for(let r of c)m.push(...findConnectionsBetween(r,l,u))}}return c.addConnections(u(m)),c},exclude:({expr:{source:r,target:i,isBidirectional:a},model:o,memory:s,stage:c,where:l})=>{let u=isWildcard(r),f=isWildcard(i),p;switch(!0){case u&&f:p=t$3(s.connections,t$17(t$20(e$6(`relations`),ifilter(l),toArray())),toSet());break;case!u&&f:p=t$3(resolveElements(o,r),t$17(r=>t$3(r,e$10(e$11(a===!0),{onTrue:r=>union(r.allIncoming,r.allOutgoing),onFalse:r=>r.allOutgoing}),ifilter(l),toArray())),toSet());break;case u&&!f:p=t$3(resolveElements(o,i),t$17(r=>t$3(r,e$10(e$11(a===!0),{onTrue:r=>union(r.allIncoming,r.allOutgoing),onFalse:r=>r.allIncoming}),ifilter(l),toArray())),toSet());break;default:{invariant(!isWildcard(r),`Inferrence failed - source must be not a wildcard`),invariant(!isWildcard(i),`Inferrence failed - target must be not a wildcard`);let s=resolveElements(o,r),c=resolveElements(o,i),u=new Set;for(let r of s)for(let i of c)isSameHierarchy(r,i)||(u=union(u,intersection(r.allOutgoing,i.allIncoming),a?intersection(i.allOutgoing,r.allIncoming):new Set));p=toSet(ifilter(u,l))}}return c.excludeRelations(p),c}};function resolveWildcard(r,{memory:i,model:a}){let o=resolveElements(a,r);if(!t$16(o,1))return[[],[]];if(ModelFqnExpr.isModelRef(r)){let s=toArray(a.element(FqnRef.flatten(r.ref)).ascendingSiblings());return[includeDescendantsFromMemory(o,i),includeDescendantsFromMemory(s,i)]}return[o,t$3(o,t$4(r=>r.ascendingSiblings()),iflat(),iunique(),toArray(),r=>includeDescendantsFromMemory(r,i))]}const IncomingExprPredicate={include:({expr:r,scope:i,model:a,memory:o,stage:s,filterWhere:c})=>{let l=r.incoming,u=[];if(ModelFqnExpr.isWildcard(l)){if(!i)return;for(let r of i.ascendingSiblings())u.push(...findConnection(r,i,`directed`))}else{let r=resolveAndIncludeFromMemory(l,{memory:o,model:a}),i=[...o.elements];i.length===0&&i.push(...n$3(r.flatMap(r=>[...r.ascendingSiblings()])));let s=incomingConnectionPredicate(a,l);for(let a of i)u.push(...findConnectionsBetween(a,r,`directed`).filter(s))}return s.addConnections(c(u)),s},exclude:({expr:{incoming:r},model:i,scope:a,stage:o,where:s})=>{let c=[];if(ModelFqnExpr.isWildcard(r)){if(!a)return;c.push(...a.allIncoming)}else{let a=resolveElements(i,r);c.push(...a.flatMap(r=>[...r.allIncoming]))}return o.excludeRelations(new Set(c.filter(s))),o}};function incomingConnectionPredicate(r,i){switch(!0){case ModelFqnExpr.isElementKindExpr(i):case ModelFqnExpr.isElementTagExpr(i):{let r=elementExprToPredicate(i);return i=>r(i.target)}case ModelFqnExpr.isModelRef(i)&&i.selector===`children`:{let a=FqnRef.flatten(i.ref);return t$8([...r.children(a)].map(r=>Connection.isIncoming(r.id)))}case ModelFqnExpr.isModelRef(i)&&i.selector===`descendants`:{let a=FqnRef.flatten(i.ref);return t$8([Connection.isInside(a),...[...r.children(a)].map(r=>Connection.isIncoming(r.id))])}case ModelFqnExpr.isModelRef(i)&&i.selector===`expanded`:{let r=FqnRef.flatten(i.ref);return t$8([Connection.isIncoming(r),Connection.isInside(r)])}case ModelFqnExpr.isModelRef(i):{let r=FqnRef.flatten(i.ref);return Connection.isIncoming(r)}default:nonexhaustive(i)}}const InOutRelationPredicate={include:({expr:{inout:r},scope:i,model:a,memory:o,stage:s,filterWhere:c})=>{let l=[];if(ModelFqnExpr.isWildcard(r)){if(!i)return;l.push(...findConnectionsBetween(i,i.ascendingSiblings()))}else{let i=resolveAndIncludeFromMemory(r,{memory:o,model:a}),s=[...o.elements];s.length===0&&(s=n$3(i.flatMap(r=>toArray(r.ascendingSiblings()))));for(let r of i)l.push(...findConnectionsBetween(r,s))}return s.addConnections(c(l)),s},exclude:({expr:{inout:r},model:i,scope:a,stage:o,where:s})=>{let c=[];if(ModelFqnExpr.isWildcard(r)){if(!a)return;c.push(...a.allOutgoing),c.push(...a.allIncoming)}else{let a=resolveElements(i,r);c.push(...a.flatMap(r=>[...r.allOutgoing,...r.allIncoming]))}return o.excludeRelations(toSet(c.filter(s))),o}},OutgoingExprPredicate={include:({expr:r,scope:i,model:a,memory:o,stage:s,filterWhere:c})=>{let l=r.outgoing,u=[];if(ModelFqnExpr.isWildcard(l)){if(!i)return;u.push(...findConnectionsBetween(i,i.ascendingSiblings(),`directed`))}else{let r=resolveAndIncludeFromMemory(l,{memory:o,model:a}),i=[...o.elements];i.length===0&&i.push(...n$3(r.flatMap(r=>[...r.ascendingSiblings()])));let s=outgoingConnectionPredicate(a,l);for(let a of r)u.push(...findConnectionsBetween(a,i,`directed`).filter(s))}return s.addConnections(c(u)),s},exclude:({expr:{outgoing:r},model:i,scope:a,stage:o,where:s})=>{let c=[];if(ModelFqnExpr.isWildcard(r)){if(!a)return;c.push(...a.allOutgoing)}else{let a=resolveElements(i,r);c.push(...a.flatMap(r=>[...r.allOutgoing]))}return o.excludeRelations(toSet(c.filter(s))),o}};function outgoingConnectionPredicate(r,i){switch(!0){case ModelFqnExpr.isElementKindExpr(i):case ModelFqnExpr.isElementTagExpr(i):{let r=elementExprToPredicate(i);return i=>r(i.source)}case ModelFqnExpr.isModelRef(i)&&i.selector===`children`:{let a=FqnRef.flatten(i.ref);return t$8([...r.children(a)].map(r=>Connection.isOutgoing(r.id)))}case ModelFqnExpr.isModelRef(i)&&i.selector===`descendants`:{let a=FqnRef.flatten(i.ref);return t$8([Connection.isInside(a),...[...r.children(a)].map(r=>Connection.isOutgoing(r.id))])}case ModelFqnExpr.isModelRef(i)&&i.selector===`expanded`:{let r=FqnRef.flatten(i.ref);return t$8([Connection.isOutgoing(r),Connection.isInside(r)])}case ModelFqnExpr.isModelRef(i):{let r=FqnRef.flatten(i.ref);return Connection.isOutgoing(r)}default:nonexhaustive(i)}}const WildcardPredicate={include:({scope:r,model:i,stage:a,memory:o,where:s})=>{if(!r){let r=[...i.roots()].filter(s);if(r.length===0)return;let[o,c]=t$2(r,r=>!r.imported);return a.addExplicit(o),a.addImplicit(c),a.addConnections(findConnectionsWithin(r)),a.connectWithExisting(r),a}let c=s(r)?r:null,l=toArray(ifilter(r.children(),s)),u=l.length>0;if(!u)if(c){if(findConnectionsBetween(c,c.siblings()).length===0){let r=c.parent;r&&s(r)&&a.addExplicit(r)}l.push(c)}else return a;c&&a.addExplicit(c);let d=toSet([...o.elements,...r.descendingSiblings()]);for(let r of d)a.addConnections(findConnectionsBetween(r,l,`directed`));u&&(a.addConnections(findConnectionsWithin(l)),a.addExplicit(l));for(let r of l)a.addConnections(findConnectionsBetween(r,d,`directed`));return a},exclude:({scope:r,memory:i,stage:a,where:o})=>o===NoWhere?r?(a.exclude([r,...r.descendants()]),a):Memory$1.empty(i.scope).stageExclude(a.expression):(a.exclude(n([...i.elements],o)),a)};function processElementPredicate(r,i,a){switch(!0){case ModelFqnExpr.isCustom(r):return i===`include`?processElementPredicate(r.custom.expr,i,a):a.stage;case ModelFqnExpr.isWhere(r):{let o=whereOperatorAsPredicate(r.where.condition),s=r=>n(r,o);return processElementPredicate(r.where.expr,i,{...a,where:o,filterWhere:s})}case ModelFqnExpr.isModelRef(r)&&r.selector===`expanded`:return ExpandedElementPredicate[i]({...a,expr:r})??a.stage;case ModelFqnExpr.isWildcard(r):return WildcardPredicate[i]({...a,expr:r})??a.stage;case ModelFqnExpr.isElementKindExpr(r):case ModelFqnExpr.isElementTagExpr(r):return ElementKindOrTagPredicate[i]({...a,expr:r})??a.stage;case ModelFqnExpr.isModelRef(r):return ElementRefPredicate[i]({...a,expr:r})??a.stage;default:nonexhaustive(r)}}function processRelationtPredicate(r,i,a){switch(!0){case ModelRelationExpr.isCustom(r):return i===`include`?processRelationtPredicate(r.customRelation.expr,i,a):a.stage;case ModelRelationExpr.isWhere(r):{let o=whereOperatorAsPredicate(r.where.condition),s=r=>new Set(n([...r],o)),c=r=>t$3(r,t$4(r=>new ConnectionModel(r.source,r.target,s(r.relations))),n(r=>r.nonEmpty()));return processRelationtPredicate(r.where.expr,i,{...a,where:o,filterWhere:c})}case ModelRelationExpr.isInOut(r):return InOutRelationPredicate[i]({...a,expr:r})??a.stage;case ModelRelationExpr.isDirect(r):return DirectRelationExprPredicate[i]({...a,expr:r})??a.stage;case ModelRelationExpr.isOutgoing(r):return OutgoingExprPredicate[i]({...a,expr:r})??a.stage;case ModelRelationExpr.isIncoming(r):return IncomingExprPredicate[i]({...a,expr:r})??a.stage;default:nonexhaustive(r)}}function process_predicates(r,i,a){let o={model:r,scope:i.scope,where:NoWhere,filterWhere:NoFilter};for(let s of a){if(isViewRuleGroup(s)){i=process_predicates(r,ActiveGroupMemory.enter(i,s),s.groupRules),invariant(i instanceof ActiveGroupMemory,`processPredicates must return ActiveGroupMemory`),i=i.leave();continue}if(isViewRulePredicate(s)){let r=`include`in s?`include`:`exclude`,a=s.include??s.exclude;for(let s of a){let a=r===`include`?i.stageInclude(s):i.stageExclude(s);switch(!0){case ModelExpression.isFqnExpr(s):a=processElementPredicate(s,r,{...o,stage:a,memory:i})??a;break;case ModelExpression.isRelationExpr(s):a=processRelationtPredicate(s,r,{...o,stage:a,memory:i})??a;break;default:nonexhaustive(s)}i=a.commit()}}}return i}function processPredicates(r,i,a){return i=process_predicates(r,i,a),StageFinal.for(i).commit()}function computeElementView(r,{docUri:i,rules:a,...o}){let s=resolveGlobalRulesInElementView(a,r.globals),c=o.viewOf?r.asComputed.element(o.viewOf):null,l=processPredicates(r,Memory$1.empty(c),s);l.isEmpty()&&c&&(l=l.update({final:new Set([c])})),l=assignElementsToGroups(l);let d=buildNodes(r,l),f=toComputedEdges(l.connections);linkNodesWithEdges(d,f);let p=topologicalSort({nodes:d,edges:f}),m=applyCustomElementProperties(s,applyViewRuleStyles(s,p.nodes)),h=t$21(s,isViewRuleAutoLayout),g=buildElementNotations(m),_=collectRankConstraints(s,m);return calcViewLayoutHash({...o,_stage:`computed`,autoLayout:{direction:h?.direction??`TB`,...h?.nodeSep&&{nodeSep:h.nodeSep},...h?.rankSep&&{rankSep:h.rankSep}},edges:applyCustomRelationProperties(s,m,p.edges),nodes:t$4(m,r=>(r.icon===`none`&&delete r.icon,r)),...g.length>0&&{notation:{nodes:g}},..._.length>0&&{ranks:_}})}function collectRankConstraints(r,i){let a=[];for(let o of r){if(!isViewRuleRank(o)||o.targets.length===0)continue;let r=t$3(i,n(t$8(o.targets.map(elementExprToPredicate))),t$4(r=>r.id));t$16(r,1)&&a.push({type:o.rank,nodes:r})}return a}function assignElementsToGroups(r){if(r.groups.length===0)return r;let i=new import_default_map.default(()=>new Set),a=new Map,o=r=>{for(let o of r.ancestors()){let s=a.get(o);if(s)return a.set(r,s),i.get(s).add(r),!0}return!1},c=r=>{for(let o of r.descendants(`asc`)){let s=a.get(o);if(s)return a.set(r,s),i.get(s).add(r),!0}return!1};if(t$3(sortParentsFirst([...r.explicitFirstSeenIn.keys()]),t$6(s=>{if(!o(s)){let o=nonNullable(r.explicitFirstSeenIn.get(s));a.set(s,o),i.get(o).add(s)}})),t$3(sortParentsFirst([...r.lastSeenIn.keys()]),n(r=>!a.has(r)),t$6(s=>{if(o(s)||c(s))return;let l=nonNullable(r.lastSeenIn.get(s));a.set(s,l),i.get(l).add(s)})),i.size===0)return r;let l=r.groups.map(r=>{let a=i.get(r.id);return a?r.update(a):r});return r.update({groups:l})}function unsafeComputeView(r,i){switch(!0){case isElementView(r):return computeElementView(i,r);case isDeploymentView(r):return computeDeploymentView(i,r);case isDynamicView(r):return computeDynamicView(i,r);default:nonexhaustive(r)}}function computeView(r,i){try{return{isSuccess:!0,view:unsafeComputeView(r,i)}}catch(r){return{isSuccess:!1,error:r instanceof Error?r:Error(`Unknown error: ${r}`),view:void 0}}}function computeParsedModelData(r){let i=LikeC4Model.create(r),{views:o,_stage:s,...c}=r,l=t$24(o,r=>unsafeComputeView(r,i));return{[_stage]:`computed`,...c,views:l}}function computeLikeC4Model(r){return LikeC4Model.create(computeParsedModelData(r))}const asTypedExpr=r=>r;function $expr(r){if(!e$12(r))return r;if(r===`*`)return asTypedExpr({wildcard:!0});if(r.startsWith(`->`))return r.endsWith(`->`)?asTypedExpr({inout:$expr(r.replace(/->/g,``).trim())}):asTypedExpr({incoming:$expr(r.replace(`-> `,``))});if(r.endsWith(` ->`))return asTypedExpr({outgoing:$expr(r.replace(` ->`,``))});if(r.includes(` <-> `)){let[i,a]=r.split(` <-> `);return asTypedExpr({source:$expr(i),target:$expr(a),isBidirectional:!0})}if(r.includes(` -> `)){let[i,a]=r.split(` -> `);return asTypedExpr({source:$expr(i),target:$expr(a)})}return r.endsWith(`._`)?asTypedExpr({ref:{model:r.replace(`._`,``)},selector:`expanded`}):r.endsWith(`.**`)?asTypedExpr({ref:{model:r.replace(`.**`,``)},selector:`descendants`}):r.endsWith(`.*`)?asTypedExpr({ref:{model:r.replace(`.*`,``)},selector:`children`}):asTypedExpr({ref:{model:r}})}export{unsafeComputeView as a,linkNodesWithEdges as c,computeView as i,computeLikeC4Model as n,computeElementView as o,computeParsedModelData as r,topologicalSort as s,$expr as t};
|