@likec4/core 1.49.0 → 1.51.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.
Files changed (80) hide show
  1. package/dist/THIRD-PARTY-LICENSES.md +24 -2
  2. package/dist/_chunks/Builder.view-element.mjs +2 -2
  3. package/dist/_chunks/LikeC4Model.d.mts +3 -3
  4. package/dist/_chunks/_types.d.mts +1 -1
  5. package/dist/_chunks/_types2.d.mts +2 -2
  6. package/dist/_chunks/assignTagColors.mjs +1 -1
  7. package/dist/_chunks/geometry.mjs +1 -0
  8. package/dist/_chunks/index.d.mts +1964 -219
  9. package/dist/_chunks/{theme.d.mts → index3.d.mts} +1 -1
  10. package/dist/_chunks/index4.d.mts +288 -0
  11. package/dist/_chunks/{to-text.d.mts → index5.d.mts} +1 -1
  12. package/dist/_chunks/libs/@mantine/colors-generator.mjs +2 -2
  13. package/dist/_chunks/libs/@radix-ui/colors.mjs +1 -1
  14. package/dist/_chunks/libs/@ungap/structured-clone.mjs +1 -1
  15. package/dist/_chunks/libs/bail.mjs +1 -1
  16. package/dist/_chunks/libs/ccount.mjs +1 -1
  17. package/dist/_chunks/libs/character-entities-html4.mjs +1 -1
  18. package/dist/_chunks/libs/character-entities-legacy.mjs +1 -1
  19. package/dist/_chunks/libs/character-entities.mjs +2 -2
  20. package/dist/_chunks/libs/comma-separated-tokens.mjs +1 -1
  21. package/dist/_chunks/libs/decode-named-character-reference.mjs +1 -1
  22. package/dist/_chunks/libs/defu.mjs +1 -1
  23. package/dist/_chunks/libs/devlop.mjs +1 -1
  24. package/dist/_chunks/libs/escape-string-regexp.mjs +1 -1
  25. package/dist/_chunks/libs/extend.mjs +1 -1
  26. package/dist/_chunks/libs/graphology-dag.mjs +1 -1
  27. package/dist/_chunks/libs/graphology.mjs +1 -1
  28. package/dist/_chunks/libs/hast-util-sanitize.mjs +1 -1
  29. package/dist/_chunks/libs/hast-util-to-html.mjs +2 -2
  30. package/dist/_chunks/libs/is-plain-obj.mjs +1 -1
  31. package/dist/_chunks/libs/longest-streak.mjs +1 -1
  32. package/dist/_chunks/libs/markdown-table.mjs +2 -2
  33. package/dist/_chunks/libs/mdast-util-find-and-replace.mjs +1 -1
  34. package/dist/_chunks/libs/mdast-util-from-markdown.mjs +2 -2
  35. package/dist/_chunks/libs/mdast-util-gfm.mjs +9 -9
  36. package/dist/_chunks/libs/mdast-util-to-hast.mjs +7 -7
  37. package/dist/_chunks/libs/micromark-extension-gfm.mjs +1 -1
  38. package/dist/_chunks/libs/mnemonist.mjs +1 -1
  39. package/dist/_chunks/libs/natural-compare-lite.mjs +2 -2
  40. package/dist/_chunks/libs/ohash.mjs +1 -1
  41. package/dist/_chunks/libs/rehype-sanitize.mjs +1 -1
  42. package/dist/_chunks/libs/rehype-stringify.mjs +1 -1
  43. package/dist/_chunks/libs/remark-gfm.mjs +1 -1
  44. package/dist/_chunks/libs/remark-github-blockquote-alert.mjs +2 -2
  45. package/dist/_chunks/libs/remark-parse.mjs +1 -1
  46. package/dist/_chunks/libs/remark-rehype.mjs +1 -1
  47. package/dist/_chunks/libs/remeda.mjs +2 -1
  48. package/dist/_chunks/libs/trough.mjs +1 -1
  49. package/dist/_chunks/libs/unified.mjs +1 -1
  50. package/dist/_chunks/manual-layout.mjs +1 -0
  51. package/dist/_chunks/mnemonist.d.mts +1 -0
  52. package/dist/_chunks/model.mjs +4 -0
  53. package/dist/_chunks/rolldown-runtime.mjs +1 -1
  54. package/dist/_chunks/types.mjs +1 -0
  55. package/dist/_chunks/utils.mjs +1 -0
  56. package/dist/builder/index.d.mts +5 -2
  57. package/dist/builder/index.mjs +1 -1
  58. package/dist/compute-view/index.d.mts +6 -5
  59. package/dist/compute-view/index.mjs +2 -2
  60. package/dist/geometry/index.d.mts +1 -1
  61. package/dist/geometry/index.mjs +1 -1
  62. package/dist/index.d.mts +5 -7
  63. package/dist/index.mjs +1 -1
  64. package/dist/model/index.d.mts +7 -4
  65. package/dist/model/index.mjs +1 -1
  66. package/dist/styles/index.d.mts +3 -2
  67. package/dist/styles/index.mjs +1 -1
  68. package/dist/types/index.d.mts +3 -3
  69. package/dist/types/index.mjs +1 -1
  70. package/dist/utils/graphology/index.mjs +1 -1
  71. package/dist/utils/index.d.mts +4 -2
  72. package/dist/utils/index.mjs +1 -1
  73. package/package.json +11 -11
  74. package/dist/_chunks/RichText.mjs +0 -1
  75. package/dist/_chunks/calcDriftsFromSnapshot.mjs +0 -1
  76. package/dist/_chunks/guards.d.mts +0 -2026
  77. package/dist/_chunks/guards.mjs +0 -4
  78. package/dist/_chunks/to-text.mjs +0 -1
  79. package/dist/_chunks/vector.mjs +0 -1
  80. /package/dist/_chunks/{vector.d.mts → index2.d.mts} +0 -0
@@ -41,6 +41,28 @@ License: MIT
41
41
  By: Vitaly Rtishchev
42
42
  Repository: https://github.com/mantinedev/mantine
43
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
+
44
66
  ---------------------------------------
45
67
 
46
68
  ## @radix-ui/colors
@@ -657,11 +679,11 @@ Repositories: https://github.com/wooorm/longest-streak, https://github.com/wooor
657
679
 
658
680
  ---------------------------------------
659
681
 
660
- ## mdast-util-gfm-autolink-literal, mdast-util-gfm-strikethrough, mdast-util-gfm-table, mdast-util-gfm-task-list-item, micromark-extension-gfm, micromark-extension-gfm-autolink-literal, micromark-extension-gfm-strikethrough, micromark-extension-gfm-task-list-item
682
+ ## mdast-util-gfm-autolink-literal, mdast-util-gfm-strikethrough, mdast-util-gfm-table, mdast-util-gfm-task-list-item, micromark-extension-gfm, micromark-extension-gfm-autolink-literal, micromark-extension-gfm-strikethrough, micromark-extension-gfm-tagfilter, micromark-extension-gfm-task-list-item
661
683
 
662
684
  License: MIT
663
685
  By: Titus Wormer
664
- Repositories: https://github.com/syntax-tree/mdast-util-gfm-autolink-literal, https://github.com/syntax-tree/mdast-util-gfm-strikethrough, https://github.com/syntax-tree/mdast-util-gfm-table, https://github.com/syntax-tree/mdast-util-gfm-task-list-item, https://github.com/micromark/micromark-extension-gfm, https://github.com/micromark/micromark-extension-gfm-autolink-literal, https://github.com/micromark/micromark-extension-gfm-strikethrough, https://github.com/micromark/micromark-extension-gfm-task-list-item
686
+ Repositories: https://github.com/syntax-tree/mdast-util-gfm-autolink-literal, https://github.com/syntax-tree/mdast-util-gfm-strikethrough, https://github.com/syntax-tree/mdast-util-gfm-table, https://github.com/syntax-tree/mdast-util-gfm-task-list-item, https://github.com/micromark/micromark-extension-gfm, https://github.com/micromark/micromark-extension-gfm-autolink-literal, https://github.com/micromark/micromark-extension-gfm-strikethrough, https://github.com/micromark/micromark-extension-gfm-tagfilter, https://github.com/micromark/micromark-extension-gfm-task-list-item
665
687
 
666
688
  > (The MIT License)
667
689
  >
@@ -1,2 +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};
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{$ as xe,D as C,H as Se,J as w,K as T,U as E,W as D,_t as Ce,b as we,bt as Te,ct as Ee,d as De,et as Oe,g as ke,gt as Ae,h as je,l as Me,mt as Ne,n as Pe,o as Fe,p as Ie,q as O,r as Le,s as Re,u as ze,ut as Be,xt as k,y as Ve}from"./types.mjs";import{$ as A,A as He,B as Ue,D as j,I as M,K as We,L as Ge,M as Ke,O as N,Q as P,R as qe,U as Je,V as Ye,Z as Xe,_ as F,a as I,c as L,d as Ze,et as R,g as Qe,i as $e,j as et,s as tt,u as z,v as B,w as nt,x as rt,y as it}from"./utils.mjs";import{n as at,t as ot}from"./libs/graphology-dag.mjs";import{c as st,t as ct}from"./libs/mnemonist.mjs";import{A as lt,C as ut,D as dt,E as ft,M as V,N as pt,O as mt,T as ht,_ as gt,c as _t,d as vt,f as yt,g as bt,h as xt,j as St,m as Ct,n as wt,o as Tt,p as Et,q as Dt,r as Ot,t as kt,v as At,w as jt,y as Mt}from"./model.mjs";import{r as Nt}from"./manual-layout.mjs";import{t as Pt}from"./libs/graphology.mjs";function Ft(e,t){let n=[],r=e.parent;for(;r;){let e=A(t.get(r),`Parent node ${r} not found`);n.push(e),r=e.parent}return n}function It(e,t){for(let n of t){let t=e.get(n.source),i=e.get(n.target);P(t,`Source node ${n.source} not found`),P(i,`Target node ${n.target} not found`),t.outEdges.push(n.id),i.inEdges.push(n.id);let a=Ft(t,e),o=Ft(i,e),s=a.length>0&&o.length>0?r(Xe(ge(a),ge(o))):null;n.parent=s?s.id:null;for(let e of a){if(e===s)break;e.outEdges.push(n.id)}for(let e of o){if(e===s)break;e.inEdges.push(n.id)}}}var Lt=at(),Rt=e(ot(),1);function zt(e){let t=[],n=[...e],r;for(;r=n.shift();){let e=r.parent;if(e){let r=[];for(;e;){let t=n.findIndex(t=>t.id===e);if(t<0)break;let[i]=n.splice(t,1);if(!i)throw Error(`Invalid state, should not happen`);r.unshift(i),e=i.parent}t.push(...r)}t.push(r)}return t}function Bt(e){return e.forEach(t=>{t.children.length>0&&(t.children=e.reduce((e,n)=>(n.parent===t.id&&e.push(n.id),e),[]))}),e}function Vt(e){let t=zt([...e.nodes.values()]),n=[...e.edges];if(t.length<2||n.length===0)return{nodes:t,edges:n};let r=t=>A(e.nodes.get(t)),a=new Pt({multi:!0,allowSelfLoops:!0,type:`directed`}),[o,s]=_e(b(n,_(e=>{let t=r(e.source),n=r(e.target),i=e.parent?r(e.parent):null;return{id:e.id,edge:e,parent:i,source:t,target:n}})),({source:e,target:t})=>e.children.length===0&&t.children.length===0),c=[],l=e=>{a.mergeNode(e.source),a.mergeNode(e.target),c.push(e),(0,Rt.default)(a,e.source,e.target)||a.mergeDirectedEdge(e.source,e.target)};for(let{edge:t,source:n,target:s}of o)if(l(t),s.parent&&s.parent!==t.parent&&b(Ft(s,e.nodes),ne(e=>e.inEdges.includes(t.id)),i(e=>{a.mergeNode(e.id),(0,Rt.default)(a,t.source,e.id)||a.mergeDirectedEdge(t.source,e.id),(0,Rt.default)(a,e.id,t.target)||a.mergeDirectedEdge(e.id,t.target)})),n.parent){let e=r(n.parent);a.mergeNode(e.id),(0,Rt.default)(a,e.id,n.id)||a.mergeDirectedEdge(e.id,n.id),s.parent&&s.parent!==n.parent&&((0,Rt.default)(a,e.id,s.parent)||a.mergeDirectedEdge(e.id,s.parent))}for(let{edge:e}of s)l(e);P(c.length===n.length,`Not all edges were added to the graph`);let u=(0,Lt.topologicalSort)(a),d=[],f=t.slice();for(let e of u){let t=f.findIndex(t=>t.id===e);P(t>=0,`Node "${e}" not found`),d.push(...f.splice(t,1))}return f.length>0&&d.length>0&&(d=d.flatMap(e=>{if(f.length===0)return e;let n=t.slice(0,t.indexOf(e)).filter(e=>f.includes(e));return n.length>0?(f=f.filter(e=>!n.includes(e)),[...n,e]):e})),d.push(...f),{nodes:Bt(zt(d)),edges:c}}function Ht(e){return e.hash=$e({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:Ee(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:Ee(e.description),technology:e.technology??null,dir:e.dir,head:e.head,tail:e.tail,line:e.line})),ve(({source:e,target:t,...n})=>[`${e}:${t}`,n]))}),e}var Ut=class{get Ctx(){throw Error(`Should not be called in runtime`)}constructor(e){this.state=e}get elements(){return this.state.elements}get explicits(){return this.state.explicits}get final(){return this.state.final}get connections(){return this.state.connections}isEmpty(){return this.elements.size===0&&this.connections.length===0&&this.explicits.size===0&&this.final.size===0}},Wt=class{excluded={elements:new Set,connections:[]};constructor(e,t){this.memory=e,this.expression=t}markedToMoveExplicitToImplicit=!1;_removeElement(e){this.excluded.elements.add(e)}exclude(e){if(!e)return this;if(N(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)&&(P(!this.markedToMoveExplicitToImplicit,`Already marked to move explicits`),this.markedToMoveExplicitToImplicit=t),N(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=I(new Set(this.memory.connections.flatMap(e=>[e.source,e.target])),new Set(e.connections.flatMap(e=>[e.source,e.target])));return t=L(t,e.elements),t=b(t,j(t=>e.explicits.has(t)&&!it(e.final,Ge(t))),B()),t.size>0&&(t=this.filterForMoveToImplicits(t),e.explicits=I(e.explicits,t),e.final=I(e.final,t)),e}removeElements(e){return e.elements=I(e.elements,this.excluded.elements),e.explicits=I(e.explicits,this.excluded.elements),e.final=I(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=I(n,e.explicits),e.final=I(e.final,n),e)}precommit(e){return e}postcommit(e){return P(I(e.explicits,e.elements).size===0,`Explicits must be subset of elements`),P(I(e.final,e.elements).size===0,`Final elements must be subset of elements`),e}commit(){let e=this.precommit(this.memory.mutableState());if(this.excluded.elements.size>0){let t=e.connections.filter(e=>this.excluded.elements.has(e.source)||this.excluded.elements.has(e.target)).flatMap(t=>[t,...gt(e.connections,t).map(e=>e.intersect(t))]).filter(e=>e.nonEmpty());this.excludeConnections(t)}return this.excluded.connections.length>0&&(e=this.removeConnections(e)),this.excluded.elements.size>0&&(e=this.removeElements(e)),this.memory.update(this.postcommit(e))}},Gt=class{explicits=new Set;implicits=new Set;_ordered=new Set;_connections=[];constructor(e,t){this.memory=e,this.expression=t}get elements(){return this.explicits}get connections(){return this._connections}mergedConnections(){return dt([...this.memory.connections,...this._connections])}connectWithExisting(e,t){throw Error(`Method not implements, depends on the model`)}_addExplicit(e){this._ordered.add(e),this.explicits.add(e),this.implicits.delete(e)}addExplicit(e){if(!e)return this;if(N(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(N(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(N(e)){for(let t of e)this._addConnection(t);return this}return this._addConnection(e),this}isDirty(){return this.explicits.size>0||this.implicits.size>0||this._connections.length>0}isEmpty(){return!this.isDirty()}precommit(e){return e}postcommit(e){return e}processConnections(e){return e}commit(){let e=this.precommit(this.memory.mutableState()),t=new Set;if(this._connections.length>0){let[n,r]=_e(this._connections,t=>e.final.has(t.source));e.connections=this.processConnections(dt([...e.connections,...n,...r])),t=new Set(e.connections.flatMap(e=>[e.source,e.target]))}return e.elements=z(e.elements,this._ordered,this.explicits,t,this.implicits),e.explicits=L(e.elements,z(e.explicits,this.explicits)),e.final=L(e.elements,z(e.final,this.explicits,t)),this.memory.update(this.postcommit(e))}};function Kt(e,t=`final`){let n=Je(F(t===`final`?e.final:e.elements)),r=new Set(e.connections.flatMap(e=>[e.source,e.target])),i=new Set(n),a=new ct.default(()=>null),o=n.reduce((e,t,n,r)=>(e.set(t,r.slice(n+1).filter(e=>M(t,e)).map(e=>(i.delete(e),e)).reduce((e,n)=>(e.some(e=>M(e,n))||(e.push(n),a.set(n,t)),e),[])),e),new ct.default(()=>[]));return{root:i,connected:r,hasInOut:t=>e.connections.some(V.isAnyInOut(t.id)),parent:e=>a.get(e),children:e=>o.get(e)}}var qt=class extends Wt{};function H(e){if(E.isCustom(e))return H(e.custom.expr);if(E.isWhere(e)){let t=H(e.where.expr),n=C(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=w.flatten(e.ref);if(e.selector===`expanded`)return e=>e.id===t||Ue(e.id)===t;if(e.selector===`descendants`||e.selector===`children`){let e=t+`.`;return t=>t.id.startsWith(e)}return e=>e.id===t}R(e)}function Jt(e,t,n){let{shape:r,color:a,icon:o,...s}=e.style,c=!l(s);b(n,y(d(Be)),y(t),i(t=>{t.shape=r??t.shape,t.color=a??t.color,h(o)&&(t.icon=o),h(e.notation)&&(t.notation=e.notation),c&&(t.style={...t.style,...s})}))}function Yt(e,t){for(let n of e)!we(n)||n.targets.length===0||Jt(n,x(n.targets.map(H)),t);return t}var Xt=class e{static kind=xe;constructor(e,t,n=null,r=new Set){this.id=e,this.viewRule=t,this.parent=n,this.elements=r}isEmpty(){return this.elements.size===0}update(t){return new e(this.id,this.viewRule,this.parent,t)}clone(){return new e(this.id,this.viewRule,this.parent,new Set(this.elements))}},Zt=class extends Wt{excludeRelations(e){return b(this.memory.connections,y(t=>tt(t.relations,e)),i(t=>{this.excludeConnections(t.update(L(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=I(this.memory.explicits,e.explicits);for(let n of t)e.explicitFirstSeenIn.delete(n);let n=I(this.memory.elements,e.elements);for(let t of n)e.lastSeenIn.delete(t);return e}},Qt=class extends Zt{constructor(e,t){super(e,t),this.memory=e,this.expression=t}};const{findConnection:$t,findConnectionsBetween:en}=Et;var tn=class extends Gt{connectWithExisting(e,t=`both`){let n=this._connections.length,r=()=>this._connections.length>n;if(!N(e)){if(t===`in`||t===`both`)for(let t of this.memory.elements)this.addConnections($t(t,e,`directed`));return(t===`out`||t===`both`)&&this.addConnections(en(e,this.memory.elements,`directed`)),r()}let i=[...e];if(t===`in`||t===`both`)for(let e of this.memory.elements)this.addConnections(en(e,i,`directed`));if(t===`out`||t===`both`)for(let e of i)this.addConnections(en(e,this.memory.elements,`directed`));return r()}addImplicitWithinScope(e){e&&(!this.memory.scope||M(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([...F(e.ancestors()).reverse(),e],[...F(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=I(e.explicits,this.memory.explicits);for(let n of t)e.explicitFirstSeenIn.set(n,`@root`);return e}},nn=class extends tn{constructor(e,t){super(e,t),this.memory=e,this.expression=t}postcommit(e){let t=I(e.explicits,this.memory.explicits);for(let n of t)e.explicitFirstSeenIn.set(n,this.memory.activeGroupId);for(let t of[...this.explicits,...this.implicits])e.lastSeenIn.set(t,this.memory.activeGroupId);return e}},rn=class e extends Ut{static empty(t){return new e({elements:new Set,explicits:new Set,final:new Set,connections:[],groups:[],explicitFirstSeenIn:new Map,lastSeenIn:new Map},t)}constructor(e,t){super(e),this.state=e,this.scope=t}get groups(){return this.state.groups}get explicitFirstSeenIn(){return this.state.explicitFirstSeenIn}get lastSeenIn(){return this.state.lastSeenIn}stageInclude(e){return new tn(this,e)}stageExclude(e){return new Zt(this,e)}mutableState(){return{elements:new Set(this.state.elements),explicits:new Set(this.state.explicits),final:new Set(this.state.final),connections:[...this.state.connections],groups:this.state.groups.map(e=>e.clone()),explicitFirstSeenIn:new Map(this.state.explicitFirstSeenIn),lastSeenIn:new Map(this.state.lastSeenIn)}}update(t){return new e({...this.state,...t},this.scope)}},an=class e extends rn{static enter(t,n){let r=`@gr${t.groups.length+1}`;if(t instanceof e){let i=st.default.from([...t.stack].reverse()),a=t.mutableState();return a.groups.push(new Xt(r,n,t.activeGroupId)),i.push(r),new e(a,t.scope,i)}let i=t.mutableState();i.groups.push(new Xt(r,n,null));let a=st.default.of(r);return new e(i,t.scope,a)}constructor(e,t,n){super(e,t),this.state=e,this.scope=t,this.stack=n}get activeGroupId(){return A(this.stack.peek(),`Stack must not be empty`)}mutableState(){return{...super.mutableState()}}update(t){return new e({...this.state,...t},this.scope,this.stack)}stageInclude(e){return new nn(this,e)}stageExclude(e){return new Qt(this,e)}leave(){let t=this.mutableState();return this.stack.pop(),this.stack.peek()?new e(t,this.scope,this.stack):new rn(t,this.scope)}};function on(e,t){let n;for(;e.parent&&(n=t.get(e.parent));){let t=n.depth??1;if(n.depth=Math.max(t,(e.depth??0)+1),n.depth===t)break;e=n}}function sn(e){let{id:t,title:n,...r}=g(e.$element,[`summary`,`description`,`metadata`,`style`,`tags`]),{color:i,icon:a,shape:o,...s}=e.style;return k({id:t,title:n,modelRef:t,shape:o,color:i,icon:a,style:s,description:Te(e.$element),tags:[...e.tags],...r})}function cn({defaults:e},t,n){let r=new Map,i=new Map;n?.forEach(({id:t,parent:n,viewRule:a,elements:o})=>{n&&A(r.get(n),`Parent group node ${n} not found`).children.push(t),r.set(t,{id:t,parent:n,kind:xe,title:a.title??``,color:a.color??e.group.color??e.color,shape:`rectangle`,children:[],inEdges:[],outEdges:[],level:0,depth:0,tags:[],style:k({border:a.border??e.group.border,opacity:a.opacity??e.group.opacity,size:a.size,multiple:a.multiple,padding:a.padding,textSize:a.textSize})});for(let e of o)i.set(e.id,t)}),Array.from(t).sort(Ke).forEach(({id:e,...t})=>{let n=Ue(e),a=0,o;for(;n&&(o=r.get(n),!o);)n=Ue(n);let s=t.modelRef??e;if(!o&&i.has(s)){let e=A(i.get(s));o=r.get(e),n=e}o&&(o.children.length==0&&(o.depth=1,on(o,r)),o.children.push(e),a=o.level+1);let c=k({id:e,parent:n,level:a,children:[],inEdges:[],outEdges:[],...t});r.set(e,c)});let a=new Map;return n?.forEach(({id:e})=>{a.set(e,A(r.get(e)))}),t.forEach(({id:e})=>{a.set(e,A(r.get(e)))}),a}function ln(e){let{title:t,description:n=null}=e;return{...t&&{title:t,description:n},...te(e,[`color`,`technology`,`head`,`line`,`tail`,`kind`,`navigateTo`])}}function un(e,t){let n=b(e,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=k({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),...We(i)&&{tags:i}});if(t){let e=ln(t);a=ie({...a,...e},f)}return u(a.title)&&f(a.technology)&&(a.title=`[${a.technology}]`,delete a.technology),a}const{findConnection:dn,findConnectionsBetween:U,findConnectionsWithin:fn}=Ct;function W(e,t){let n=e.element(t.ref.deployment);if(n.isDeploymentNode()){if(t.selector===`children`)return[...n.children()];if(t.selector===`expanded`)return[n,...n.children()];if(t.selector===`descendants`)return[...n.descendants()]}return[n]}function pn(e,t){let n=e.$model.element(t.ref.model);return t.selector===`children`?[...n.children()]:t.selector===`expanded`?[n,...n.children()]:t.selector===`descendants`?[...n.descendants()]:[n]}function mn(e){if(T.isWildcard(e))return()=>!0;if(T.isElementTagExpr(e)||T.isElementKindExpr(e))throw Error(`element kind and tag expressions are not supported in deployment view rules`);if(T.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=>Ue(e.id)===t:e=>e.id===t}if(T.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?Ue(n)===t:!0}:e=>{let n=e.modelRef??null;return n?n===t:!0}}R(e)}function hn(e){return Te(e.$instance)??Te(e.element.$element)}function gn(e){let t=e.id,n=e.onlyOneInstance();return k({id:t,deploymentRef:t,title:e.title,kind:e.kind,technology:e.technology??void 0,links: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:Te(e.$node)??void 0,tags:[...e.tags],style:g(e.style,[`icon`,`shape`,`color`])})}function _n(e){let t=e.$instance,n=e.element,{icon:r,color:i,shape:a,...o}=e.style,s=[...n.links,...t.links??[]];return k({id:e.id,kind:`instance`,title:e.title,description:hn(e)??void 0,technology:e.technology??void 0,tags:[...e.tags],links:m(s,1)?s:void 0,icon:r,color:i,shape:a,style:o,deploymentRef:t.id,modelRef:n.id,notation:t.notation})}function vn(e){return e.isInstance()?_n(e):gn(e)}function yn(e){return e.reduce((e,t)=>{let n=[...t.relations.model,...t.relations.deployment];P(m(n,1),`Edge must have at least one relation`);let r=t.source.$model.$styles.defaults,i=t.source.id,a=t.target.id,{title:o,color:s=r.relationship.color,line:c=r.relationship.line,head:l=r.relationship.arrow,...u}=un(n.map(e=>e.$relationship)),d=k({id:t.id,parent:t.boundary?.id??null,source:i,target:a,label:o??null,relations:n.map(e=>e.id),color:s,line:c,head:l,...u}),f=e.find(e=>e.source===a&&e.target===i);if(f&&d.label===f.label){f.dir=`both`;let n=f.head??d.head??t.source.$model.$styles.defaults.relationship.arrow;return f.head??=n,f.tail??=n,d.color&&(f.color??=d.color),d.line&&(f.line??=d.line),e}return e.push(d),e},[])}function bn(e,t){let n=cn(e.$styles,[...t.final].map(vn));for(let t of n.values()){if(!t.deploymentRef||!t.modelRef||t.children.length>0)continue;let n=e.deployment.element(t.deploymentRef),r=n.isDeploymentNode()&&n.onlyOneInstance();if(!r)continue;t.title===n.name&&(t.title=r.title),t.description??=hn(r)??null,t.technology??=r.technology,l(t.tags)&&(t.tags=[...r.tags]),(!t.links||l(t.links))&&m(r.links,1)&&(t.links=[...r.links]);let i=e.$styles.defaults;t.shape===i.shape&&t.shape!==r.shape&&(t.shape=r.shape,t.notation=null),t.color===i.color&&t.color!==r.color&&(t.color=r.color,t.notation=null),!t.icon&&r.icon&&(t.icon=r.icon)}return n}function xn(e,t){for(let n of e)!we(n)||n.targets.length===0||Jt(n,x(n.targets.map(mn)),t);return t}function Sn(e){let t=new ct.default(()=>[]);for(let n of e)for(let e of n.relations.model)t.get(e).push(n);let n=new ct.default(()=>new Set);for(let[e,r]of t)m(r,2)&&b(r,c(e=>[{group:`$source-${e.source.id}`,conn:e},{group:`$target-${e.target.id}`,conn:e}]),a(ce(`group`)),pe(),y(m(2)),i(ae(_(ce(`conn`)),mt(`desc`),ee((e,t,n)=>t===0||e.boundary===n[t-1].boundary),i(t=>{n.get(t).add(e)}))));return n}function Cn(e){e=dt(e);let t=Sn(e);for(let n of e){let{source:e,target:r}=n,i=n.relations.model;if(e.isDeploymentNode()!==r.isDeploymentNode()){let r=e.isDeploymentNode()?e:n.target;P(r.isDeploymentNode());let a=L(i,r.internalModelRelationships());for(let e of a)t.get(n).add(e);continue}if(e.isDeploymentNode()&&r.isDeploymentNode()){let i=z(L(n.relations.model,e.internalModelRelationships()),L(n.relations.model,r.internalModelRelationships()));for(let e of i)t.get(n).add(e)}}return b(t.entries(),rt(([e,t])=>e.update({model:t,deployment:null})),F())}function wn(e){return bt(e,Cn(e))}function Tn(e){return b(e,dt,re((t,n)=>{let{source:r,target:i,relations:a}=n;if(r.isInstance()&&i.isInstance())return t;let o=Dt.empty();if(r.isDeploymentNode()&&i.isDeploymentNode()){let[e]=dn(i,r,`directed`);e&&(o=a.intersect(e.relations))}for(let t of e)ht(t,n)&&(o=o.union(a.intersect(t.relations)));return o.nonEmpty&&t.push(new lt(r,i,o)),t},[]))}function En(e){return bt(e,Tn(e))}var Dn=class extends Gt{connectWithExisting(e,t=`both`){let n=this._connections.length,r=()=>this._connections.length>n;if(!N(e)){if(t===`in`||t===`both`)for(let t of this.memory.elements)this.addConnections(dn(t,e,`directed`));return(t===`out`||t===`both`)&&this.addConnections(U(e,this.memory.elements,`directed`)),r()}let i=[...e];if(t===`in`||t===`both`)for(let e of this.memory.elements)this.addConnections(U(e,i,`directed`));if(t===`out`||t===`both`)for(let e of i)this.addConnections(U(e,this.memory.elements,`directed`));return r()}processConnections(e){let t=b(e,wn,En);return b(t,i(({source:e,target:t,boundary:n})=>{b(me([...F(e.ancestors()).reverse(),e],[...F(t.ancestors()).reverse(),t]),ee(([e,t])=>e===t),de(1),i(([r,i])=>{if(e===r&&t===i){this.addImplicit(n);return}r!==e&&r.isDeploymentNode()&&!r.onlyOneInstance()&&this.addImplicit(r),i!==t&&i.isDeploymentNode()&&!i.onlyOneInstance()&&this.addImplicit(i)}))})),t}},On=class e extends Ut{static empty(){return new e({elements:new Set,explicits:new Set,final:new Set,connections:[]})}stageInclude(e){return new Dn(this,e)}stageExclude(e){return new qt(this,e)}mutableState(){return{elements:new Set(this.state.elements),explicits:new Set(this.state.explicits),final:new Set(this.state.final),connections:[...this.state.connections]}}update(t){return new e({...this.state,...t})}equals(t){return t instanceof e&&v(this.state,t.state)}diff(e){return{added:{elements:F(I(e.elements,this.elements)),explicits:F(I(e.explicits,this.explicits)),final:F(I(e.final,this.final)),connections:F(bt(e.connections,this.connections))},removed:{elements:F(I(this.elements,e.elements)),explicits:F(I(this.explicits,e.explicits)),final:F(I(this.final,e.final)),connections:bt(this.connections,e.connections)}}}toString(){return[`final:`,...[...this.final].map(e=>` `+e.id),`connections:`,...this.connections.map(e=>` `+e.expression)].join(`
2
+ `)}[St](e,t,n){return this.toString()}};const kn={include:({expr:e,model:t,memory:n,stage:r})=>{let i=C(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=C(e.where.condition);return Vn(`exclude`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})}},An={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(T.isWildcard(e.incoming)){for(let e of a){if(e.allOutgoing.isEmpty)continue;let t=K(U(e,[...Kn(e)],`directed`),i);r.addConnections(t)}return r}P(T.isDeploymentRef(e.incoming),`Only deployment refs are supported in include`);let o=W(t,e.incoming);for(let e of a){let t=K(U(e,o,`directed`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(T.isElementTagExpr(e.incoming)||T.isElementKindExpr(e.incoming))throw Error(`element kind and tag expressions are not supported in exclude`);if(T.isModelRef(e.incoming))return G(Mn(t,e.incoming),{stage:r,memory:n},i);if(T.isWildcard(e.incoming))return r;let a=jn(W(t,e.incoming)),o=b(n.connections,y(a),K(i));return r.excludeConnections(o),r}};function jn(e){return x(e.map(e=>{let t=t=>t===e||M(e,t);return e=>!t(e.source)&&t(e.target)}))}function Mn(e,t){let n=pn(e,t);return new Set(n.flatMap(e=>[...e.allIncoming]))}const Nn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(T.isWildcard(e.outgoing)){for(let e of a)if(!e.allIncoming.isEmpty)for(let t of Kn(e)){let n=K(dn(t,e,`directed`),i);r.addConnections(n)}return r}P(T.isDeploymentRef(e.outgoing),`Only deployment refs are supported in include`);let o=W(t,e.outgoing);for(let e of o){let t=K(U(e,a,`directed`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(T.isElementTagExpr(e.outgoing)||T.isElementKindExpr(e.outgoing))throw Error(`element kind and tag expressions are not supported in exclude`);if(T.isModelRef(e.outgoing))return G(Fn(t,e.outgoing),{stage:r,memory:n},i);if(T.isWildcard(e.outgoing))return r;let a=Pn(W(t,e.outgoing)),o=b(n.connections,y(a),K(i));return r.excludeConnections(o),r}};function Pn(e){return x(e.map(e=>{let t=t=>t===e||M(e,t);return e=>t(e.source)&&!t(e.target)}))}function Fn(e,t){let n=pn(e,t);return new Set(n.flatMap(e=>[...e.allOutgoing]))}const In={include:({expr:{source:e,target:t,isBidirectional:n=!1},model:r,stage:i,where:a})=>{if(T.isElementTagExpr(e)||T.isElementKindExpr(e)||T.isElementTagExpr(t)||T.isElementKindExpr(t))throw Error(`element kind and tag expressions are not supported in include`);P(!T.isModelRef(e),`Invalid source model ref in direct relation`),P(!T.isModelRef(t),`Invalid target model ref in direct relation`);let o=T.isWildcard(e),s=T.isWildcard(t),l=n?`both`:`directed`,u;switch(!0){case o&&s:u=b(fn(r.instances()),K(a),_(e=>(i.addImplicit(e.boundary),e)));break;case!o&&s:{let t=W(r,e),i=Pn(t),o=i;if(n){let e=jn(t);o=t=>i(t)!==e(t)}u=b(t,c(e=>U(e,Kn(e),l)),y(o),K(a));break}case o&&!s:{let e=W(r,t),i=jn(e),o=i;if(n){let t=Pn(e);o=e=>t(e)!==i(e)}u=b(e,c(e=>[...Kn(e)].flatMap(t=>dn(t,e,l))),y(o),K(a));break}default:{P(!o,`Inference failed - source should be a deployment ref`),P(!s,`Inference failed - target should be a deployment ref`);let n=W(r,e),i=W(r,t),d=Pn(n),f=jn(i);u=b(n,c(e=>U(e,i,l)),y(e=>d(e)&&f(e)),K(a))}}return i.addConnections(u),T.isDeploymentRef(e)&&p(e.selector)&&i.addImplicit(r.element(e.ref.deployment)),T.isDeploymentRef(t)&&p(t.selector)&&i.addImplicit(r.element(t.ref.deployment)),i},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=mn(e.target),o=mn(e.source),s;switch(!0){case T.isWildcard(e.source)&&T.isWildcard(e.target):return r.excludeConnections(K(n.connections,i)),r;case T.isModelRef(e.source)&&T.isModelRef(e.target):return s=Ln({source:e.source,target:e.target,expr:e,model:t}),G(s,{stage:r,memory:n},i);case T.isModelRef(e.source)&&T.isWildcard(e.target):return s=Fn(t,e.source),G(s,{stage:r,memory:n},i);case T.isModelRef(e.source):return s=Fn(t,e.source),G(s,{stage:r,memory:n},i,e=>a(e.target));case T.isModelRef(e.target):return s=Mn(t,e.target),G(s,{stage:r,memory:n},i,e=>o(e.source));default:let c=t=>o(t.source)&&a(t.target)||e.isBidirectional===!0&&o(t.target)&&a(t.source),l=b(n.connections,y(c),K(i));return l.length===0||r.excludeConnections(l),r}}};function Ln({source:e,target:t,expr:n,model:r}){let i=pn(r,e),a=pn(r,t),o=n.isBidirectional?`both`:`directed`,s=[];for(let e of i)s.push(...yt(e,a,o));return new Set(s.flatMap(e=>[...e.relations]))}const Rn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(T.isWildcard(e.inout)){for(let e of a){let t=Un(U(e,[...Kn(e)],`both`),i);r.addConnections(t)}return r}P(T.isDeploymentRef(e.inout),`Only deployment refs are supported in include`);let o=W(t,e.inout);for(let e of a){let t=Un(U(e,o,`both`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(T.isElementTagExpr(e.inout)||T.isElementKindExpr(e.inout))throw Error(`element kind and tag expressions are not supported in exclude`);if(T.isModelRef(e.inout)){let a=pn(t,e.inout);return a.length===0?r:G(z(new Set,...a.flatMap(e=>[e.allIncoming,e.allOutgoing])),{stage:r,memory:n},i)}if(T.isWildcard(e.inout))return r;let a=W(t,e.inout),o=jn(a),s=Pn(a),c=b(n.connections,y(e=>o(e)!==s(e)),K(i));return r.excludeConnections(c),r}},zn={include:({expr:e,model:t,memory:n,stage:r})=>{let i=C(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=C(e.where.condition);return Vn(`exclude`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})}},Bn={include:({model:e,stage:t,where:n})=>{let r=[],i=b([...e.roots()],q(n),_(e=>(e.onlyOneInstance()||r.push(...e.children()),e)));return t.addExplicit(i),r.length>1&&t.addConnections(fn([...i,...r])),t},exclude:({stage:e,memory:t,where:n})=>{let r=b([...t.elements],q(n));return e.exclude(r),e}};function Vn(e,{expr:t,where:n,...r}){switch(!0){case T.isElementTagExpr(t):case T.isElementKindExpr(t):throw Error(`element kind and tag expressions are not supported in deployment view rules`);case O.isCustom(t):case T.isCustom(t):case T.isModelRef(t):return;case T.isWhere(t):return kn[e]({...r,expr:t,where:n});case O.isWhere(t):return zn[e]({...r,expr:t,where:n});case T.isDeploymentRef(t):return qn[e]({...r,expr:t,where:n});case T.isWildcard(t):return Bn[e]({...r,expr:t,where:n});case O.isDirect(t):return In[e]({...r,expr:t,where:n});case O.isInOut(t):return Rn[e]({...r,expr:t,where:n});case O.isOutgoing(t):return Nn[e]({...r,expr:t,where:n});case O.isIncoming(t):return An[e]({...r,expr:t,where:n});default:R(t)}}function G(e,{stage:t,memory:n},r,i=()=>!0){if(e.size===0)return t;let a=b(n.connections,y(e=>i(e)),y(t=>tt(t.relations.model,e)),_(t=>t.update({deployment:null,model:L(t.relations.model,e)})),K(r),y(e=>e.nonEmpty()));return a.length===0?t:t.excludeConnections(a)}function Hn(e,t){return K(e,t).nonEmpty()}function K(...e){if(e.length===1)return t=>K(t,e[0]);let[n,r]=e;return r===null?n:t(n)?n.map(e=>K(e,r)).filter(e=>e.nonEmpty()):n.update({model:new Set([...n.relations.model.values()].filter(e=>r(Gn(n)(e)))),deployment:new Set([...n.relations.deployment.values()].filter(e=>r(Gn(n)(e))))})}function q(...e){if(e.length===1)return t=>q(t,e[0]);let[n,r]=e;return t(n)?n.filter(e=>q(e,r)):r?.(Wn(n,n))??!0}function Un(e,t){return t?b(e,y(e=>Hn(e,t))):e}function Wn(e,t){if(Tt(e)){let n=wt(t)&&kt(t)?t:null;return{kind:e.kind,tags:[...e.tags,...n?.tags??[]]}}if(_t(e))return te(e.element,[`tags`,`kind`]);if(kt(e))return{kind:e.element.kind,tags:[...e.tags,...e.element.tags]};if(Ot(e))return te(e,[`tags`,`kind`]);R(e)}function Gn(e){return t=>({tags:t.tags,kind:t.kind,source:Wn(t.source,e.source),target:Wn(t.target,e.target)})}function Kn(e){let t=new Set;for(let n of e.descendingSiblings())t.add(n);return t}const qn={include:e=>{let{expr:t,where:n}=e,r=e.model.element(t.ref.deployment);if(kt(r))return q(r,n)&&(e.stage.addExplicit(r),e.stage.connectWithExisting(r)),e.stage;switch(!0){case t.selector===`expanded`:Yn(r,e);break;case t.selector===`children`:Jn(r,e);break;case t.selector===`descendants`:Xn(r,e);break;default:q(r,n)&&(e.stage.addExplicit(r),e.stage.connectWithExisting(r))}return e.stage},exclude:({expr:e,stage:t,memory:n,where:r})=>{let i=mn(e),a=b([...n.elements],y(i),q(r));return t.exclude(a),t}};function Jn(e,{stage:t,where:n}){let r=q([...e.children()],n);r.length!==0&&(t.addImplicit(e),t.addConnections(fn(r)),t.connectWithExisting(r),t.addExplicit(r))}function Yn(e,{memory:t,stage:n,where:r}){n.addImplicit(e),n.connectWithExisting(e);let i=q([...e.children()],r),a=!1;for(let e of i)if(U(e,t.elements).length>0){a=!0;break}a&&(n.connectWithExisting(i,`in`),n.addConnections(fn(i)),n.connectWithExisting(i,`out`)),n.addImplicit(i),n.connections.length>0&&n.addExplicit(e)}function Xn(e,{stage:t,where:n}){let r=e=>{let i=[];for(let t of e.children())t.isDeploymentNode()&&i.push(...r(t)),q(t,n)&&i.push(t);return t.connectWithExisting(i,`in`),t.addConnections(fn(i)),t.addImplicit(i),i},a=r(e);if(a.length===0)return;t.connectWithExisting(a,`out`);let o=Zn(t);b(a,y(e=>o.has(e)),i(e=>t.addExplicit(e)))}function Zn(e){return b(e.mergedConnections(),wn,En,re((e,t)=>(e.add(t.source),e.add(t.target),e),new Set))}var Qn=class e{static for(t){return new e(t)}constructor(e){this.memory=e}step1CleanConnections(e){if(e.connections.length<2)return e;let t=b(e.connections,wn,En),n=bt(e.connections,t);if(n.length===0)return e;let r=e.stageExclude({});return r.excludeConnections(n,!0),r.commit()}step2ProcessImplicits(e){let t=z(this.memory.elements,e.elements),n=z(e.final,this.memory.explicits),r=new ct.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||M(e,t))return!0;return!1};return b(I(t,a),j(e=>e.isDeploymentNode()),F(),Ye,i(e=>{let t=[...e.children()].filter(o).length;if(t>=2){n.add(e);return}t===1&&it(e.siblings(),o)&&n.add(e)})),e.update({final:n})}step3ProcessBoundaries(e){let t=new Set;for(let n of e.connections)n.boundary&&t.add(n.boundary);let n=Kt(e,`final`),r=e.stageExclude({}),i=r=>!(t.has(r)||e.explicits.has(r)||n.hasInOut(r)||n.root.has(r)),a=S([...n.root]);a&&!e.explicits.has(a)&&r.exclude(a);for(let t of e.final){let e=S(n.children(t));e&&!n.hasInOut(e)&&i(t)&&r.exclude(t)}return r.isDirty()?r.commit():e}commit(){let e=this.step1CleanConnections(this.memory),t=this.step2ProcessImplicits(e);return this.step3ProcessBoundaries(t)}};function $n(e,t){let n=On.empty();for(let r of t)if(Ve(r)){let t=`include`in r?`include`:`exclude`,i=r.include??r.exclude;for(let r of i){let i=t===`include`?n.stageInclude(r):n.stageExclude(r);i=Vn(t,{expr:r,model:e,stage:i,memory:n,where:null})??i,n=i.commit()}}return Qn.for(n).commit()}function er(e,{docUri:t,rules:n,...r}){let i=$n(e.deployment,n),a=bn(e,i),o=yn(i.connections);It(a,o);let c=Vt({nodes:a,edges:o}),l=xn(n,c.nodes),u=s(n,Me),d=Nt(l);return Ht({...r,[Ae]:`computed`,[Ce]:`deployment`,autoLayout:{direction:u?.direction??`TB`,...u?.nodeSep&&{nodeSep:u.nodeSep},...u?.rankSep&&{rankSep:u.rankSep}},edges:c.edges,nodes:_(l,e=>(e.icon===`none`&&delete e.icon,e)),...d.length>0&&{notation:{nodes:d}}})}function tr(e){return t=>Pe(t)?t.groupRules.flatMap(tr(e)):Ve(t)&&`include`in t?t.include.filter(e):[]}function nr(e,t){let n=e.flatMap(tr(E.isCustom));if(n.length===0)return t;let r=[...t];for(let{custom:{expr:e,...t}}of n){let{border:n,opacity:i,multiple:a,iconColor:s,iconSize:c,iconPosition:l,padding:d,size:f,textSize:p,...m}=ye(t,u),h=k({border:n,opacity:i,multiple:a,iconColor:s,iconSize:c,iconPosition:l,padding:d,size:f,textSize:p}),g=!o(h),_=!o(m),v=H(e);r.forEach((e,t)=>{Be(e)||!v(e)||(_&&(e={...e,...m,isCustomized:!0}),g&&(e={...e,isCustomized:!0,style:{...e.style,...h}}),r[t]=e)})}return r}function rr(e,t){return e.reduce((e,n)=>{if(ze(n)){let r=t.predicates[n.predicateId];return u(r)?e:e.concat(r)}if(De(n)){let r=t.styles[n.styleId];return u(r)?e:e.concat(r)}return e.push(n),e},[])}function ir(e,t){return e.reduce((e,n)=>{if(ze(n)){let r=t.dynamicPredicates[n.predicateId];return u(r)?e:e.concat(r)}if(De(n)){let r=t.styles[n.styleId];return u(r)?e:e.concat(r)}return e.push(n),e},[])}function ar(e,t){let n=new Set;for(let r of t)if(Ve(r))for(let t of r.include){let r=H(t);for(let t of e.elements())r(t)&&n.add(t)}return n}const or=e=>{if(Fe(e)){let t=[],n=[];for(let r of e.__parallel)if(Re(r)){let[e,...i]=r.__series;t.push(e),n.push(...i)}else t.push(r);return[...t,...n]}return Re(e)?[...e.__series]:e};function sr(e,t){let n=[],r=(...[e,t])=>{if(!n.includes(e)){let r=n.indexOf(t);if(r>0){n.splice(r,0,e);return}else n.push(e)}n.includes(t)||n.push(t)};for(let i of c(t,or)){let t=e.element(i.source),a=e.element(i.target),o=n.indexOf(t),s=n.indexOf(a);o>=0&&s>=0||(i.isBackward?r(a,t):r(t,a))}return new Set(n)}function cr(e,t,n){let r=vt(e,t,`directed`).flatMap(e=>[...e.relations]).sort(Ze);if(!We(r))return{};if(r.length===1){let e=r[0];return k({title:e.title??void 0,kind:e.kind??void 0,tags:e.tags,relations:[e.id],navigateTo:e.$relationship.navigateTo,color:e.$relationship.color,line:e.$relationship.line,technology:e.technology??void 0,description:e.$relationship.description??void 0})}let i=b(r,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 k({tags:a??void 0,relations:o,navigateTo:s,kind:S([...l.kind]),title:S([...l.title]),color:S([...l.color]),line:S([...l.line]),technology:S([...l.technology]),description:S(l.description)})}var lr=class{steps=[];constructor(e,t){this.model=e,this.view=t}compute(){let{docUri:e,rules:t,steps:n,...r}=this.view,i=ir(t,this.model.globals),a=ar(this.model,i),o=sr(this.model,n),c=b(z(L(a,o),o,a),F(),Je),l=c.reduce((e,t,n,r)=>{for(let i=n+1;i<r.length;i++){let n=r[i];if(M(t,n)){e.push(t);break}}return e},[]),u=(e,t,n)=>{if(Re(e)){for(let r of e.__series)t=u(r,t,n);return t}let r=n?Ne(n,t):Ne(t),{source:i,target:a,title:o,isBackward:s,navigateTo:d,notation:p,...m}=e,h=this.model.element(i),g=c.indexOf(h);P(g>=0,`Source ${i} not found`);let _=this.model.element(a),v=c.indexOf(_);P(v>=0,`Target ${a} not found`),(l.includes(h)||l.includes(_))&&console.error(`Step ${h.id} -> ${_.id} because it involves a compound`);let{title:y,relations:ee,navigateTo:te,...ne}=cr(h,_,this.view.id),re=f(d)&&d!==this.view.id?d:te,b=e.kind&&!e.technology?this.model.specification.relationships[e.kind]?.technology:void 0;return this.steps.push(k({...ne,...m,...b&&{technology:b},id:r,source:h,target:_,navigateTo:re,title:o??y,relations:ee??[],isBackward:g>v})),t+1},d=1;for(let e of n){if(Fe(e)){let t=1;for(let n of e.__parallel)t=u(n,t,d);d++;continue}d=u(e,d)}let p=cn(this.model.$styles,c.map(sn)),m=this.model.$styles.defaults.relationship,h=this.steps.map(({id:e,source:t,target:n,relations:r,title:i,isBackward:a,tags:o,...s})=>{let c=A(p.get(t.id),`Source node ${t.id} not found`),l=A(p.get(n.id),`Target node ${n.id} not found`),u={id:e,parent:et(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=Ue(u.parent);c.outEdges.push(u.id),l.inEdges.push(u.id);for(let e of He(u.source)){if(e===u.parent)break;p.get(e)?.outEdges.push(u.id)}for(let e of He(u.target)){if(e===u.parent)break;p.get(e)?.inEdges.push(u.id)}return u}),g=nr(i,Yt(i,c.map(e=>A(p.get(e.id))))),v=s(i,Me),y=Nt(g);return Ht({...r,[Ce]:`dynamic`,[Ae]:`computed`,variant:r.variant??`diagram`,autoLayout:{direction:v?.direction??`LR`,...v?.nodeSep&&{nodeSep:v.nodeSep},...v?.rankSep&&{rankSep:v.rankSep}},nodes:_(g,e=>(e.icon===`none`&&delete e.icon,e)),edges:h,...y.length>0&&{notation:{nodes:y}}})}};function ur(e,t){return new lr(e,t).compute()}function dr(e){switch(!0){case D.isCustom(e):return dr(e.customRelation.expr);case D.isWhere(e):{let t=dr(e.where.expr),n=C(e.where.condition);return e=>t(e)&&n({source:{tags:e.source.tags,kind:e.source.kind},target:{tags:e.target.tags,kind:e.target.kind},...e.tags&&{tags:e.tags},...e.kind&&{kind:e.kind}})}case D.isDirect(e):{let t=H(e.source),n=H(e.target);return r=>t(r.source)&&n(r.target)||!!e.isBidirectional&&t(r.target)&&n(r.source)}case D.isInOut(e):{let t=H(e.inout);return e=>t(e.source)||t(e.target)}case D.isIncoming(e):{let t=H(e.incoming);return e=>t(e.target)}case D.isOutgoing(e):{let t=H(e.outgoing);return e=>t(e.source)}default:R(e)}}function fr(e,t,n){let r=e.flatMap(tr(D.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:Oe(a)}:{},c=o?{notes:Oe(o)}:{},l=ye(s,u),d=dr(e);i.forEach((e,a)=>{let o,s;for(let n of t)if(n.id===e.source&&(o=n),n.id===e.target&&(s=n),o&&s)break;!o||!s||d({source:o,target:s,...te(e,[`kind`,`tags`])})&&(i[a]={...e,...l,...r,...c,label:n??e.label,isCustomized:!0})})}return i}function pr(e){return b([...e],dt,re((e,t,n,r)=>{let i=Mt(r,t),a=z(...i.map(ce(`relations`))),o=L(t.relations,a);if(i.length>0&&(o=z(o,t.directRelations)),At(r,t.reversed())&&(o=z(o,t.directRelations)),o.size<t.relations.size){let e=r.some(ut(t.source)),n=r.some(ut(t.target));e&&(o=z(o,B(j(t.relations,ft(t.source))))),n&&(o=z(o,B(j(t.relations,jt(t.target)))))}return o.size>0&&e.push(t.update(o)),e},[]))}var mr=class e{static for(t){return new e(t)}constructor(e){this.memory=e}step1CleanConnections(e){if(e.connections.length<2)return e;let t=pr(e.connections);if(t.length===0)return e;let n=e.stageExclude({});return n.excludeConnections(t,!0),n.commit()}step2ProcessImplicits(e){let t=z(this.memory.elements,e.elements),n=z(e.final,this.memory.explicits),r=new Set(n),a=e=>{for(let t of r)if(e===t||M(e,t))return!0;return!1};return b(I(t,r),F(),Ye,i(e=>{let t=[...e.children()].filter(a).length;if(t>=2){n.add(e);return}t===1&&it(e.siblings(),a)&&n.add(e)})),e.update({final:n})}step3ProcessBoundaries(e){let t=new Set;for(let n of e.connections)n.boundary&&n.boundary!==n.source&&n.boundary!==n.target&&t.add(n.boundary);let n=Kt(e,`final`),r=e.stageExclude({}),i=r=>!(t.has(r)||e.explicits.has(r)||n.hasInOut(r)||n.root.has(r)),a=S([...n.root]);a&&!e.explicits.has(a)&&r.exclude(a);for(let t of e.final){let e=S(n.children(t));e&&!n.hasInOut(e)&&i(t)&&r.exclude(t)}return r.isDirty()?r.commit():e}commit(){let e=this.step1CleanConnections(this.memory),t=this.step2ProcessImplicits(e);return this.step3ProcessBoundaries(t)}};const{findConnection:hr,findConnectionsBetween:J,findConnectionsWithin:Y}=Et;function X(e,t){switch(!0){case E.isElementKindExpr(t):return[...j(e.elements(),e=>t.isEqual===(e.kind===t.elementKind))];case E.isElementTagExpr(t):return[...j(e.elements(),e=>t.isEqual===e.tags.includes(t.elementTag))];case t.selector===`expanded`:{let n=e.element(w.flatten(t.ref));return[n,...n.children()]}case t.selector===`children`:case t.selector===`descendants`:{let n=e.element(w.flatten(t.ref)),r=t.selector===`children`?F(n.children()):F(n.descendants());return r&&r.length>0?r:[n]}case E.isModelRef(t):return[e.element(w.flatten(t.ref))];default:R(t)}}function gr(e,t){if(t.isEmpty()||e.length===0)return e;let n=x(e.map(e=>Ge(e))),r=F(j(t.elements,t=>!e.includes(t)&&n(t)));return[...e,...r]}function _r(e,{memory:t,model:n}){let r=X(n,e);return E.isModelRef(e)?e.selector===`descendants`?r:gr(r,t):r}const vr={include:({expr:e,model:t,stage:n,where:r})=>{let i=t.element(w.flatten(e.ref));r(i)&&(n.addExplicit(i),n.connectWithExisting(i));let a=[...i.children()].filter(r),o=[];for(let e of a)n.addImplicit(e),n.connectWithExisting(e)&&o.push(e);return n.addConnections(Y(o)),n},exclude:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(X(t,e));return n.exclude(i),n}},yr={include:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(X(t,e));if(i.length!==0)return n.addExplicit(i),n.connectWithExisting(i),n.addConnections(Y(i)),n},exclude:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(X(t,e));return n.exclude(i),n}},br={include:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(X(t,e));if(i.length!==0)return n.addExplicit(i),n.connectWithExisting(i),n.addConnections(Y(i)),n},exclude:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(X(t,e));return n.exclude(i),n}},xr=()=>!0,Sr=e=>e;function Cr(e){return e.reduce((e,t)=>{let n=[...t.relations];P(m(n,1),`Edge must have at least one relation`);let r=t.source.$model.$styles.defaults,i=t.source.id,a=t.target.id,{title:o,color:s=r.relationship.color,line:c=r.relationship.line,head:l=r.relationship.arrow,...u}=un(n.map(e=>e.$relationship),S(y(n,e=>e.source.id===i&&e.target.id===a))?.$relationship),d=k({id:t.id,parent:t.boundary?.id??null,source:i,target:a,label:o??null,relations:n.map(e=>e.id),color:s,line:c,head:l,...u});return e.push(d),e},[])}function wr(e,t){return cn(e.$styles,[...t.final].map(sn),t.groups)}const Z=E.isWildcard,Tr=(e,t)=>e.isAncestorOf(t)||e.isDescendantOf(t),Er={include:({expr:{source:e,target:t,isBidirectional:n=!1},memory:r,model:i,stage:a,where:o,filterWhere:s})=>{let l=Z(e),u=Z(t),d=[];switch(!0){case l&&u&&r.isEmpty()&&o!==xr:{let e=b(i.relationships(),j(o),F(),_(e=>new xt(e.source,e.target,new Set([e]))));return a.addConnections(e),a}case l&&u&&!r.isEmpty()&&o!==xr:d.push(...Y(r.elements));break;case l&&u:d.push(...Y(i.roots()));break;case!l&&u&&o!==xr:{let t=b(X(i,e),c(e=>b(e,le(he(n===!0),{onTrue:e=>z(e.allIncoming,e.allOutgoing),onFalse:e=>e.allOutgoing}),j(o),Qe(),F(),_e(t=>t.source===e),([t,n])=>ue(b(t,y(t=>!Tr(e,t.target)),_(t=>new xt(e,t.target,new Set([t])))),b(n,y(t=>!Tr(e,t.source)),_(t=>new xt(t.source,e,new Set([t]))))))));return a.addConnections(t),a}case!l&&u:{let[t,a]=Dr(e,{memory:r,model:i}),o=n?`both`:`directed`;for(let e of t)d.push(...J(e,a,o));break}case l&&!u&&o!==xr:{let e=b(X(i,t),c(e=>b(e,le(he(n===!0),{onTrue:e=>z(e.allIncoming,e.allOutgoing),onFalse:e=>e.allIncoming}),j(o),F(),_e(t=>t.target===e),([t,n])=>ue(b(n,y(t=>!Tr(e,t.target)),_(t=>new xt(e,t.target,new Set([t])))),b(t,y(t=>!Tr(e,t.source)),_(t=>new xt(t.source,e,new Set([t]))))))));return a.addConnections(e),a}case l&&!u:{let[e,a]=Dr(t,{memory:r,model:i}),o=n?`both`:`directed`;for(let t of a)d.push(...J(t,e,o));break}default:{P(!Z(e),`Inference failed - source must be not a wildcard`),P(!Z(t),`Inference failed - target must be not a wildcard`);let a=_r(e,{memory:r,model:i}),o=_r(t,{memory:r,model:i}),s=n?`both`:`directed`;for(let e of a)d.push(...J(e,o,s))}}return a.addConnections(s(d)),a},exclude:({expr:{source:e,target:t,isBidirectional:n},model:r,memory:i,stage:a,where:o})=>{let s=Z(e),l=Z(t),u;switch(!0){case s&&l:u=b(i.connections,c(ae(ce(`relations`),j(o),F())),B());break;case!s&&l:u=b(X(r,e),c(e=>b(e,le(he(n===!0),{onTrue:e=>z(e.allIncoming,e.allOutgoing),onFalse:e=>e.allOutgoing}),j(o),F())),B());break;case s&&!l:u=b(X(r,t),c(e=>b(e,le(he(n===!0),{onTrue:e=>z(e.allIncoming,e.allOutgoing),onFalse:e=>e.allIncoming}),j(o),F())),B());break;default:{P(!Z(e),`Inference failed - source must be not a wildcard`),P(!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)qe(e,t)||(s=z(s,L(e.allOutgoing,t.allIncoming),n?L(t.allOutgoing,e.allIncoming):new Set));u=B(j(s,o))}}return a.excludeRelations(u),a}};function Dr(e,{memory:t,model:n}){let r=X(n,e);if(!m(r,1))return[[],[]];if(E.isModelRef(e)){let i=F(n.element(w.flatten(e.ref)).ascendingSiblings());return[gr(r,t),gr(i,t)]}return[r,b(r,_(e=>e.ascendingSiblings()),nt(),Qe(),F(),e=>gr(e,t))]}const Or={include:({expr:e,scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=e.incoming,s=[];if(E.isWildcard(o)){if(!t)return;for(let e of t.ascendingSiblings())s.push(...hr(e,t,`directed`))}else{let e=_r(o,{memory:r,model:n}),t=[...r.elements];t.length===0&&t.push(...oe(e.flatMap(e=>[...e.ascendingSiblings()])));let i=kr(n,o);for(let n of t)s.push(...J(n,e,`directed`).filter(i))}return i.addConnections(a(s)),i},exclude:({expr:{incoming:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(E.isWildcard(e)){if(!n)return;a.push(...n.allIncoming)}else{let n=X(t,e);a.push(...n.flatMap(e=>[...e.allIncoming]))}return r.excludeRelations(new Set(a.filter(i))),r}};function kr(e,t){switch(!0){case E.isElementKindExpr(t):case E.isElementTagExpr(t):{let e=H(t);return t=>e(t.target)}case E.isModelRef(t)&&t.selector===`children`:{let n=w.flatten(t.ref);return x([...e.children(n)].map(e=>V.isIncoming(e.id)))}case E.isModelRef(t)&&t.selector===`descendants`:{let n=w.flatten(t.ref);return x([V.isInside(n),...[...e.children(n)].map(e=>V.isIncoming(e.id))])}case E.isModelRef(t)&&t.selector===`expanded`:{let e=w.flatten(t.ref);return x([V.isIncoming(e),V.isInside(e)])}case E.isModelRef(t):{let e=w.flatten(t.ref);return V.isIncoming(e)}default:R(t)}}const Ar={include:({expr:{inout:e},scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=[];if(E.isWildcard(e)){if(!t)return;o.push(...J(t,t.ascendingSiblings()))}else{let t=_r(e,{memory:r,model:n}),i=[...r.elements];i.length===0&&(i=oe(t.flatMap(e=>F(e.ascendingSiblings()))));for(let e of t)o.push(...J(e,i))}return i.addConnections(a(o)),i},exclude:({expr:{inout:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(E.isWildcard(e)){if(!n)return;a.push(...n.allOutgoing),a.push(...n.allIncoming)}else{let n=X(t,e);a.push(...n.flatMap(e=>[...e.allOutgoing,...e.allIncoming]))}return r.excludeRelations(B(a.filter(i))),r}},jr={include:({expr:e,scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=e.outgoing,s=[];if(E.isWildcard(o)){if(!t)return;s.push(...J(t,t.ascendingSiblings(),`directed`))}else{let e=_r(o,{memory:r,model:n}),t=[...r.elements];t.length===0&&t.push(...oe(e.flatMap(e=>[...e.ascendingSiblings()])));let i=Mr(n,o);for(let n of e)s.push(...J(n,t,`directed`).filter(i))}return i.addConnections(a(s)),i},exclude:({expr:{outgoing:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(E.isWildcard(e)){if(!n)return;a.push(...n.allOutgoing)}else{let n=X(t,e);a.push(...n.flatMap(e=>[...e.allOutgoing]))}return r.excludeRelations(B(a.filter(i))),r}};function Mr(e,t){switch(!0){case E.isElementKindExpr(t):case E.isElementTagExpr(t):{let e=H(t);return t=>e(t.source)}case E.isModelRef(t)&&t.selector===`children`:{let n=w.flatten(t.ref);return x([...e.children(n)].map(e=>V.isOutgoing(e.id)))}case E.isModelRef(t)&&t.selector===`descendants`:{let n=w.flatten(t.ref);return x([V.isInside(n),...[...e.children(n)].map(e=>V.isOutgoing(e.id))])}case E.isModelRef(t)&&t.selector===`expanded`:{let e=w.flatten(t.ref);return x([V.isOutgoing(e),V.isInside(e)])}case E.isModelRef(t):{let e=w.flatten(t.ref);return V.isOutgoing(e)}default:R(t)}}const Nr={include:({scope:e,model:t,stage:n,memory:r,where:i})=>{if(!e){let e=[...t.roots()].filter(i);if(e.length===0)return;let[r,a]=_e(e,e=>!e.imported);return n.addExplicit(r),n.addImplicit(a),n.addConnections(Y(e)),n.connectWithExisting(e),n}let a=i(e)?e:null,o=F(j(e.children(),i)),s=o.length>0;if(!s)if(a){if(J(a,a.siblings()).length===0){let e=a.parent;e&&i(e)&&n.addExplicit(e)}o.push(a)}else return n;a&&n.addExplicit(a);let c=B([...r.elements,...e.descendingSiblings()]);for(let e of c)n.addConnections(J(e,o,`directed`));s&&(n.addConnections(Y(o)),n.addExplicit(o));for(let e of o)n.addConnections(J(e,c,`directed`));return n},exclude:({scope:e,memory:t,stage:n,where:r})=>r===xr?e?(n.exclude([e,...e.descendants()]),n):rn.empty(t.scope).stageExclude(n.expression):(n.exclude(y([...t.elements],r)),n)};function Pr(e,t,n){switch(!0){case E.isCustom(e):return t===`include`?Pr(e.custom.expr,t,n):n.stage;case E.isWhere(e):{let r=C(e.where.condition),i=e=>y(e,r);return Pr(e.where.expr,t,{...n,where:r,filterWhere:i})}case E.isModelRef(e)&&e.selector===`expanded`:return vr[t]({...n,expr:e})??n.stage;case E.isWildcard(e):return Nr[t]({...n,expr:e})??n.stage;case E.isElementKindExpr(e):case E.isElementTagExpr(e):return yr[t]({...n,expr:e})??n.stage;case E.isModelRef(e):return br[t]({...n,expr:e})??n.stage;default:R(e)}}function Fr(e,t,n){switch(!0){case D.isCustom(e):return t===`include`?Fr(e.customRelation.expr,t,n):n.stage;case D.isWhere(e):{let r=C(e.where.condition),i=e=>new Set(y([...e],r)),a=e=>b(e,_(e=>new xt(e.source,e.target,i(e.relations))),y(e=>e.nonEmpty()));return Fr(e.where.expr,t,{...n,where:r,filterWhere:a})}case D.isInOut(e):return Ar[t]({...n,expr:e})??n.stage;case D.isDirect(e):return Er[t]({...n,expr:e})??n.stage;case D.isOutgoing(e):return jr[t]({...n,expr:e})??n.stage;case D.isIncoming(e):return Or[t]({...n,expr:e})??n.stage;default:R(e)}}function Ir(e,t,n){let r={model:e,scope:t.scope,where:xr,filterWhere:Sr};for(let i of n){if(Pe(i)){t=Ir(e,an.enter(t,i),i.groupRules),P(t instanceof an,`processPredicates must return ActiveGroupMemory`),t=t.leave();continue}if(Ve(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:R(i)}t=n.commit()}}}return t}function Lr(e,t,n){return t=Ir(e,t,n),mr.for(t).commit()}function Rr(e,{docUri:t,rules:n,...r}){let i=rr(n,e.globals),a=r.viewOf?e.asComputed.element(r.viewOf):null,o=Lr(e,rn.empty(a),i);o.isEmpty()&&a&&(o=o.update({final:new Set([a])})),o=Br(o);let c=wr(e,o),l=Cr(o.connections);It(c,l);let u=Vt({nodes:c,edges:l}),d=nr(i,Yt(i,u.nodes)),f=s(i,Me),p=Nt(d),m=zr(i,d);return Ht({...r,_stage:`computed`,autoLayout:{direction:f?.direction??`TB`,...f?.nodeSep&&{nodeSep:f.nodeSep},...f?.rankSep&&{rankSep:f.rankSep}},edges:fr(i,d,u.edges),nodes:_(d,e=>(e.icon===`none`&&delete e.icon,e)),...p.length>0&&{notation:{nodes:p}},...m.length>0&&{ranks:m}})}function zr(e,t){let n=[];for(let r of e){if(!Le(r)||r.targets.length===0)continue;let e=b(t,y(x(r.targets.map(H))),_(e=>e.id));m(e,1)&&n.push({type:r.rank,nodes:e})}return n}function Br(e){if(e.groups.length===0)return e;let t=new ct.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(Je([...e.explicitFirstSeenIn.keys()]),i(i=>{if(!r(i)){let r=A(e.explicitFirstSeenIn.get(i));n.set(i,r),t.get(r).add(i)}})),b(Je([...e.lastSeenIn.keys()]),y(e=>!n.has(e)),i(i=>{if(r(i)||a(i))return;let o=A(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 ke(e):return Rr(t,e);case Ie(e):return er(t,e);case je(e):return ur(t,e);default:R(e)}}function Hr(e,t){try{return{isSuccess:!0,view:Vr(e,t)}}catch(e){return{isSuccess:!1,error:e instanceof Error?e:Error(`Unknown error: ${e}`),view:void 0}}}function Ur(e){let t=pt.create(e),{views:r,_stage:i,...a}=e,o=n(r,e=>Vr(e,t));return{[Ae]:`computed`,...a,views:o}}function Wr(e){return pt.create(Ur(e))}const Q=e=>e;function $(e){if(!se(e))return e;if(e===`*`)return Q({wildcard:!0});if(e.startsWith(`->`))return e.endsWith(`->`)?Q({inout:$(e.replace(/->/g,``).trim())}):Q({incoming:$(e.replace(`-> `,``))});if(e.endsWith(` ->`))return Q({outgoing:$(e.replace(` ->`,``))});if(e.includes(` <-> `)){let[t,n]=e.split(` <-> `);return Q({source:$(t),target:$(n),isBidirectional:!0})}if(e.includes(` -> `)){let[t,n]=e.split(` -> `);return Q({source:$(t),target:$(n)})}return e.endsWith(`._`)?Q({ref:{model:e.replace(`._`,``)},selector:`expanded`}):e.endsWith(`.**`)?Q({ref:{model:e.replace(`.**`,``)},selector:`descendants`}):e.endsWith(`.*`)?Q({ref:{model:e.replace(`.*`,``)},selector:`children`}):Q({ref:{model:e}})}export{Vr as a,It as c,Hr as i,Wr as n,Rr as o,Ur as r,Vt as s,$ as t};
@@ -1,6 +1,6 @@
1
- import { $n as FqnRef, Br as ElementId, C as LayoutedView, Ei as NodeId, Fr as Aux, Gn as WhereOperator, Hr as Fqn, Ht as DynamicViewDisplayVariant, Ii as ViewId$1, Ir as DeploymentFqn, Ji as _stage, Jr as Metadata, Kr as LooseTag, Lr as DeploymentId, Mi as StepEdgeId, Mr as AnyComputed, Nr as AnyLayouted, Oi as ProjectId, Ot as Element, Pr as AnyParsed, Qr as RelationKind, Rr as DeploymentKind, Rt as ModelGlobals, S as ComputedView, Si as GroupElementKind, St as DeploymentNode, Ur as LooseDeploymentId, Vr as ElementKind, Wr as LooseElementId, Xr as ProjectId$1, Yi as _type, Yr as MetadataKey, Zr as RelationId$1, _ as ComputedLikeC4ModelData, ai as UnknownComputed, b as ParsedLikeC4ModelData, bt as DeploymentElement, ci as ViewId, ct as LikeC4Project, d as AuxFromDump, ea as IteratorLike, ei as Stage, et as ViewManualLayoutSnapshot, f as LikeC4ModelDump, gr as RelationshipLineType, gt as Specification, ia as NonEmptyArray, ii as Unknown, jr as Any, jt as Relationship, k as ViewWithType, ki as RelationId, kt as ElementStyle, l as RichTextOrEmpty, na as Link, ni as Tag, oi as UnknownLayouted, or as ElementShape, ot as ComputedNodeStyle, pi as toComputed, pr as RelationshipArrowType, qr as LooseViewId, ri as Tags, si as UnknownParsed, ti as StrictViewId, tr as Color, v as LayoutedLikeC4ModelData, vi as EdgeId, wi as IconUrl, wt as DeploymentRelationship, yt as DeployedInstance } from "./guards.mjs";
2
- import { i as BBox } from "./vector.mjs";
3
- import { i as LikeC4Styles } from "./theme.mjs";
1
+ import { $n as FqnRef, Br as ElementId, C as LayoutedView, Ei as NodeId, Fr as Aux, Gn as WhereOperator, Hr as Fqn, Ht as DynamicViewDisplayVariant, Ii as ViewId$1, Ir as DeploymentFqn, Ji as _stage, Jr as Metadata, Kr as LooseTag, Lr as DeploymentId, Mi as StepEdgeId, Mr as AnyComputed, Nr as AnyLayouted, Oi as ProjectId, Ot as Element, Pr as AnyParsed, Qr as RelationKind, Rr as DeploymentKind, Rt as ModelGlobals, S as ComputedView, Si as GroupElementKind, St as DeploymentNode, Ur as LooseDeploymentId, Vr as ElementKind, Wr as LooseElementId, Xr as ProjectId$1, Yi as _type, Yr as MetadataKey, Zr as RelationId$1, _ as ComputedLikeC4ModelData, ai as UnknownComputed, b as ParsedLikeC4ModelData, bt as DeploymentElement, ci as ViewId, ct as LikeC4Project, d as AuxFromDump, ea as IteratorLike, ei as Stage, et as ViewManualLayoutSnapshot, f as LikeC4ModelDump, gr as RelationshipLineType, gt as Specification, ia as NonEmptyArray, ii as Unknown, jr as Any, jt as Relationship, k as ViewWithType, ki as RelationId, kt as ElementStyle, l as RichTextOrEmpty, na as Link, ni as Tag, oi as UnknownLayouted, or as ElementShape, ot as ComputedNodeStyle, pi as toComputed, pr as RelationshipArrowType, qr as LooseViewId, ri as Tags, si as UnknownParsed, ti as StrictViewId, tr as Color, v as LayoutedLikeC4ModelData, vi as EdgeId, wi as IconUrl, wt as DeploymentRelationship, yt as DeployedInstance } from "./index.mjs";
2
+ import { i as BBox } from "./index2.mjs";
3
+ import { i as LikeC4Styles } from "./index3.mjs";
4
4
  import { o as DefaultMap } from "./libs/mnemonist.mjs";
5
5
  import { IsAny, SetRequired, Tagged } from "type-fest";
6
6
 
@@ -1,4 +1,4 @@
1
- import { $r as SpecAux, An as ModelRelationExpr, At as ModelRelation, Fr as Aux, Hn as Participant, Ot as Element, Ti as MarkdownOrString, W as ParsedDeploymentView, _r as ShapeSize, _t as TagSpecification, b as ParsedLikeC4ModelData, bi as Fqn, br as TextSize, bt as DeploymentElement, cr as IconPosition, dt as LikeC4ProjectStylesConfig, er as BorderStyle, fi as setProject, gi as DeploymentFqn, gr as RelationshipLineType, ht as RelationshipSpecification, ia as NonEmptyArray, in as ParsedElementView, jn as Expression, jr as Any, kn as ModelFqnExpr, ln as AnyViewRuleStyle, mt as ElementSpecification$1, or as ElementShape, pr as RelationshipArrowType, ta as KeysOf, un as AutoLayoutDirection, w as ParsedView, wt as DeploymentRelationship, xr as ThemeColor, yr as SpacingSize } from "./guards.mjs";
1
+ import { $r as SpecAux, An as ModelRelationExpr, At as ModelRelation, Fr as Aux, Hn as Participant, Ot as Element, Ti as MarkdownOrString, W as ParsedDeploymentView, _r as ShapeSize, _t as TagSpecification, b as ParsedLikeC4ModelData, bi as Fqn, br as TextSize, bt as DeploymentElement, cr as IconPosition, dt as LikeC4ProjectStylesConfig, er as BorderStyle, fi as setProject, gi as DeploymentFqn, gr as RelationshipLineType, ht as RelationshipSpecification, ia as NonEmptyArray, in as ParsedElementView, jn as Expression, jr as Any, kn as ModelFqnExpr, ln as AnyViewRuleStyle, mt as ElementSpecification$1, or as ElementShape, pr as RelationshipArrowType, ta as KeysOf, un as AutoLayoutDirection, w as ParsedView, wt as DeploymentRelationship, xr as ThemeColor, yr as SpacingSize } 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
 
@@ -1,5 +1,5 @@
1
- import { G as DiagramEdge, Ji as _stage, K as DiagramNode, Oi as ProjectId, Yi as _type, at as ComputedNode, fn as BaseViewProperties, hn as ViewAutoLayout, rt as ComputedEdge } from "./guards.mjs";
2
- import { i as BBox } from "./vector.mjs";
1
+ import { G as DiagramEdge, Ji as _stage, K as DiagramNode, Oi as ProjectId, Yi as _type, at as ComputedNode, fn as BaseViewProperties, hn as ViewAutoLayout, rt as ComputedEdge } from "./index.mjs";
2
+ import { i as BBox } from "./index2.mjs";
3
3
 
4
4
  //#region src/compute-view/projects-view/_types.d.ts
5
5
  interface ComputedProjectNode extends ComputedNode {
@@ -1 +1 @@
1
- import{O as e,T as t$3,X as t,et as t$1,l as t$2,m as e$1,nt as t$4,p as t$5}from"./libs/remeda.mjs";import{F as DefaultTagColors}from"./RichText.mjs";import{$ as nonNullable,J as compareNatural}from"./to-text.mjs";function assignTagColors(a){let o=[],s=[];for(let[r,i]of t(a))e(i.color)?o.push({tag:r,spec:{color:i.color}}):s.push(r);return t$1(s,t$2(compareNatural),t$3((n,r)=>({tag:n,spec:{color:nonNullable(DefaultTagColors[r%DefaultTagColors.length])}})),t$4(o),t$2((n,r)=>compareNatural(n.tag,r.tag)),t$5(e$1(`tag`),e$1(`spec`)))}export{assignTagColors as t};
1
+ import{O as e,T as t,X as n,et as r,l as i,m as a,nt as o,p as s}from"./libs/remeda.mjs";import{F as c}from"./types.mjs";import{$ as l,J as u}from"./utils.mjs";function d(d){let f=[],p=[];for(let[t,r]of n(d))e(r.color)?f.push({tag:t,spec:{color:r.color}}):p.push(t);return r(p,i(u),t((e,t)=>({tag:e,spec:{color:l(c[t%c.length])}})),o(f),i((e,t)=>u(e.tag,t.tag)),s(a(`tag`),a(`spec`)))}export{d as t};
@@ -0,0 +1 @@
1
+ import{Q as e}from"./libs/remeda.mjs";import{Q as t}from"./utils.mjs";function n(e){return Array.isArray(e)&&e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`}function r(e){return n(e)?{x:e[0],y:e[1]}:[e.x,e.y]}const i={center({x:e,y:t,width:n,height:r}){return{x:e+n/2,y:t+r/2}},toPoints({x:e,y:t,width:n,height:r}){return[{x:e,y:t},{x:e+n,y:t},{x:e+n,y:t+r},{x:e,y:t+r}]},fromPoints(e){let{x1:t,y1:n,x2:r,y2:i}=a.fromPoints(e);return{x:t,y:n,width:r-t,height:i-n}},merge(...n){if(t(e(n,1),`No boxes provided`),n.length===1)return n[0];let r=n[0].x,i=n[0].y,a=n[0].x+n[0].width,o=n[0].y+n[0].height;for(let e=1;e<n.length;e++){let t=n[e];r=Math.min(r,t.x),i=Math.min(i,t.y),a=Math.max(a,t.x+t.width),o=Math.max(o,t.y+t.height)}return{x:Math.floor(r),y:Math.floor(i),width:Math.round(a-r),height:Math.round(o-i)}},fromRectBox(e){return{x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),width:Math.abs(e.x2-e.x1),height:Math.abs(e.y2-e.y1)}},toRectBox(e){return{x1:e.x,y1:e.y,x2:e.x+e.width,y2:e.y+e.height}},expand(e,t){return t===0?e:{x:e.x-t,y:e.y-t,width:e.width+t*2,height:e.height+t*2}},shrink(e,t){return t===0?e:{x:e.x+t,y:e.y+t,width:e.width-t*2,height:e.height-t*2}},includes(e,t){return e===t?!0:e.x<=t.x&&e.y<=t.y&&e.x+e.width>=t.x+t.width&&e.y+e.height>=t.y+t.height}},a={center({x1:e,y1:t,x2:n,y2:r}){return{x:(e+n)/2,y:(t+r)/2}},fromPoints(e){t(e.length>0,`At least one point is required`);let n=1/0,r=1/0,i=-1/0,a=-1/0;for(let[t,o]of e)n=Math.min(n,t),r=Math.min(r,o),i=Math.max(i,t),a=Math.max(a,o);return{x1:n,y1:r,x2:i,y2:a}},merge(...e){t(e.length>0,`No boxes provided`);let n=1/0,r=1/0,i=-1/0,a=-1/0;for(let t of e)n=Math.min(n,t.x1),r=Math.min(r,t.y1),i=Math.max(i,t.x2),a=Math.max(a,t.y2);return{x1:n,y1:r,x2:i,y2:a}},toBBox(e){return{x:e.x1,y:e.y1,width:e.x2-e.x1,height:e.y2-e.y1}},includes(e,t){return e===t?!0:e.x1<=t.x1&&e.y1<=t.y1&&e.x2>=t.x2&&e.y2>=t.y2}};var o=class e{constructor(e,n){this.x=e,this.y=n,t(typeof e==`number`&&!isNaN(e)&&isFinite(e)&&typeof n==`number`&&!isNaN(n)&&isFinite(n),`Invalid arguments for Vector: (${e}, ${n})`)}static create(...t){return t.length===2?new e(t[0],t[1]):new e(t[0].x,t[0].y)}static add(e,t){return{x:e.x+t.x,y:e.y+t.y}}static subtract(e,t){return{x:e.x-t.x,y:e.y-t.y}}static multiply(e,t){return{x:e.x*t,y:e.y*t}}static divide(e,t){return{x:e.x/t,y:e.y/t}}static dot(e,t){return e.x*t.x+e.y*t.y}add(t){return new e(this.x+t.x,this.y+t.y)}subtract(t){return new e(this.x-t.x,this.y-t.y)}multiply(t){return new e(this.x*t,this.y*t)}divide(t){return new e(this.x/t,this.y/t)}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}length(){return this.x===0&&this.y===0?0:Math.sqrt(this.x**2+this.y**2)}normalize(){let t=this.length();return t===0?new e(0,0):new e(this.x/t,this.y/t)}round(){return new e(Math.round(this.x),Math.round(this.y))}trunc(){return new e(Math.trunc(this.x),Math.trunc(this.y))}toObject(){return{x:this.x,y:this.y}}};function s(...e){return e.length===1&&e[0]instanceof o?e[0]:e.length===2?new o(e[0],e[1]):new o(e[0].x,e[0].y)}export{r as a,a as i,s as n,n as o,i as r,o as t};