@likec4/core 1.55.1 → 1.56.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 (37) hide show
  1. package/dist/THIRD-PARTY-LICENSES.md +30 -30
  2. package/dist/_chunks/Builder.view-element.mjs +2 -2
  3. package/dist/_chunks/LikeC4Model.d.mts +1 -0
  4. package/dist/_chunks/assignTagColors.mjs +1 -1
  5. package/dist/_chunks/index5.d.mts +4 -0
  6. package/dist/_chunks/libs/{@mantine/colors-generator.mjs → chroma-js.mjs} +2 -2
  7. package/dist/_chunks/libs/graphology-dag.d.mts +607 -0
  8. package/dist/_chunks/libs/hast-util-to-html.mjs +1 -1
  9. package/dist/_chunks/libs/mdast-util-find-and-replace.mjs +1 -1
  10. package/dist/_chunks/libs/mdast-util-from-markdown.mjs +1 -1
  11. package/dist/_chunks/libs/mdast-util-gfm.mjs +11 -11
  12. package/dist/_chunks/libs/mnemonist.mjs +1 -1
  13. package/dist/_chunks/libs/unified.mjs +1 -1
  14. package/dist/_chunks/manual-layout.mjs +1 -1
  15. package/dist/_chunks/mnemonist.d.mts +1 -1
  16. package/dist/_chunks/model.mjs +4 -4
  17. package/dist/_chunks/rolldown-runtime.mjs +1 -1
  18. package/dist/_chunks/types.mjs +1 -1
  19. package/dist/builder/index.d.mts +0 -6
  20. package/dist/builder/index.mjs +1 -1
  21. package/dist/compute-view/index.d.mts +0 -4
  22. package/dist/compute-view/index.mjs +2 -2
  23. package/dist/geometry/index.mjs +1 -1
  24. package/dist/index.d.mts +0 -1
  25. package/dist/index.mjs +1 -1
  26. package/dist/model/index.d.mts +0 -5
  27. package/dist/model/index.mjs +1 -1
  28. package/dist/styles/index.d.mts +0 -1
  29. package/dist/styles/index.mjs +1 -1
  30. package/dist/types/index.mjs +1 -1
  31. package/dist/utils/graphology/index.d.mts +2 -1
  32. package/dist/utils/graphology/index.mjs +1 -1
  33. package/dist/utils/index.d.mts +0 -2
  34. package/dist/utils/index.mjs +1 -1
  35. package/package.json +9 -9
  36. package/dist/_chunks/geometry.mjs +0 -1
  37. package/dist/_chunks/utils.mjs +0 -1
@@ -35,36 +35,6 @@ Repository: https://github.com/likec4/likec4
35
35
 
36
36
  ---------------------------------------
37
37
 
38
- ## @mantine/colors-generator
39
-
40
- License: MIT
41
- By: Vitaly Rtishchev
42
- Repository: https://github.com/mantinedev/mantine
43
-
44
- > MIT License
45
- >
46
- > Copyright (c) 2021 Vitaly Rtishchev
47
- >
48
- > Permission is hereby granted, free of charge, to any person obtaining a copy
49
- > of this software and associated documentation files (the "Software"), to deal
50
- > in the Software without restriction, including without limitation the rights
51
- > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
52
- > copies of the Software, and to permit persons to whom the Software is
53
- > furnished to do so, subject to the following conditions:
54
- >
55
- > The above copyright notice and this permission notice shall be included in all
56
- > copies or substantial portions of the Software.
57
- >
58
- > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59
- > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60
- > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
61
- > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
62
- > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
63
- > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
64
- > SOFTWARE.
65
-
66
- ---------------------------------------
67
-
68
38
  ## @radix-ui/colors
69
39
 
70
40
  License: MIT
@@ -471,6 +441,36 @@ Repository: https://github.com/graphology/graphology
471
441
 
472
442
  ---------------------------------------
473
443
 
444
+ ## graphology-types
445
+
446
+ License: MIT
447
+ By: Guillaume Plique
448
+ Repository: https://github.com/graphology/graphology
449
+
450
+ > The MIT License (MIT)
451
+ >
452
+ > Copyright (c) 2020-2021 Guillaume Plique (Yomguithereal)
453
+ >
454
+ > Permission is hereby granted, free of charge, to any person obtaining a copy
455
+ > of this software and associated documentation files (the "Software"), to deal
456
+ > in the Software without restriction, including without limitation the rights
457
+ > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
458
+ > copies of the Software, and to permit persons to whom the Software is
459
+ > furnished to do so, subject to the following conditions:
460
+ >
461
+ > The above copyright notice and this permission notice shall be included in
462
+ > all copies or substantial portions of the Software.
463
+ >
464
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
465
+ > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
466
+ > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
467
+ > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
468
+ > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
469
+ > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
470
+ > THE SOFTWARE.
471
+
472
+ ---------------------------------------
473
+
474
474
  ## graphology-utils, obliterator
475
475
 
476
476
  License: MIT
@@ -1,2 +1,2 @@
1
- import{r as e}from"./rolldown-runtime.mjs";import{B as t,C as n,E as r,G as i,H as a,I as o,J as s,K as c,L as l,M as u,N as d,O as f,P as p,Q as m,R as h,S as g,T as _,V as v,Y as y,Z as ee,_ as te,a as ne,d as re,et as b,g as ie,h as ae,i as oe,k as se,m as ce,n as le,nt as ue,o as de,q as fe,r as pe,rt as x,t as me,tt as he,u as ge,v as _e,w as ve,x as ye,y as S,z as be}from"./libs/remeda.mjs";import{G as C,J as xe,O as w,St as T,U as Se,W as E,Y as D,_t as Ce,b as we,d as Te,dt as Ee,et as De,g as Oe,h as ke,ht as Ae,l as je,lt as Me,n as Ne,o as Pe,p as Fe,q as O,r as Ie,s as Le,tt as Re,u as ze,vt as Be,xt as Ve,y as He}from"./types.mjs";import{$ as k,A as Ue,B as We,D as A,I as j,K as Ge,L as Ke,M as qe,O as M,Q as N,R as Je,U as Ye,V as Xe,Z as Ze,_ as P,a as F,c as I,d as Qe,et as L,g as $e,i as et,j as tt,s as nt,u as R,v as z,w as rt,x as it,y as at}from"./utils.mjs";import{n as ot,t as st}from"./libs/graphology-dag.mjs";import{c as ct,t as lt}from"./libs/mnemonist.mjs";import{A as ut,C as dt,D as ft,E as pt,M as B,N as mt,O as ht,T as gt,_ as _t,c as vt,d as yt,f as bt,g as xt,h as St,j as Ct,m as wt,n as Tt,o as Et,p as Dt,q as Ot,r as kt,t as At,v as jt,w as Mt,y as Nt}from"./model.mjs";import{r as Pt}from"./manual-layout.mjs";import{t as Ft}from"./libs/graphology.mjs";function It(e,t){let n=[],r=e.parent;for(;r;){let e=k(t.get(r),`Parent node ${r} not found`);n.push(e),r=e.parent}return n}function Lt(e,t){for(let n of t){let t=e.get(n.source),i=e.get(n.target);N(t,`Source node ${n.source} not found`),N(i,`Target node ${n.target} not found`),t.outEdges.push(n.id),i.inEdges.push(n.id);let a=It(t,e),o=It(i,e),s=a.length>0&&o.length>0?r(Ze(ge(a),ge(o))):null;n.parent=s?s.id:null;for(let e of a){if(e===s)break;e.outEdges.push(n.id)}for(let e of o){if(e===s)break;e.inEdges.push(n.id)}}}var Rt=ot(),zt=e(st(),1);function Bt(e){let t=[],n=[...e],r;for(;r=n.shift();){let e=r.parent;if(e){let r=[];for(;e;){let t=n.findIndex(t=>t.id===e);if(t<0)break;let[i]=n.splice(t,1);if(!i)throw Error(`Invalid state, should not happen`);r.unshift(i),e=i.parent}t.push(...r)}t.push(r)}return t}function Vt(e){return e.forEach(t=>{t.children.length>0&&(t.children=e.reduce((e,n)=>(n.parent===t.id&&e.push(n.id),e),[]))}),e}function Ht(e){let t=Bt([...e.nodes.values()]),n=[...e.edges];if(t.length<2||n.length===0)return{nodes:t,edges:n};let r=t=>k(e.nodes.get(t)),a=new Ft({multi:!0,allowSelfLoops:!0,type:`directed`}),[o,s]=_e(b(n,_(e=>{let t=r(e.source),n=r(e.target),i=e.parent?r(e.parent):null;return{id:e.id,edge:e,parent:i,source:t,target:n}})),({source:e,target:t})=>e.children.length===0&&t.children.length===0),c=[],l=e=>{a.mergeNode(e.source),a.mergeNode(e.target),c.push(e),(0,zt.default)(a,e.source,e.target)||a.mergeDirectedEdge(e.source,e.target)};for(let{edge:t,source:n,target:s}of o)if(l(t),s.parent&&s.parent!==t.parent&&b(It(s,e.nodes),ne(e=>e.inEdges.includes(t.id)),i(e=>{a.mergeNode(e.id),(0,zt.default)(a,t.source,e.id)||a.mergeDirectedEdge(t.source,e.id),(0,zt.default)(a,e.id,t.target)||a.mergeDirectedEdge(e.id,t.target)})),n.parent){let e=r(n.parent);a.mergeNode(e.id),(0,zt.default)(a,e.id,n.id)||a.mergeDirectedEdge(e.id,n.id),s.parent&&s.parent!==n.parent&&((0,zt.default)(a,e.id,s.parent)||a.mergeDirectedEdge(e.id,s.parent))}for(let{edge:e}of s)l(e);N(c.length===n.length,`Not all edges were added to the graph`);let u=(0,Rt.topologicalSort)(a),d=[],f=t.slice();for(let e of u){let t=f.findIndex(t=>t.id===e);N(t>=0,`Node "${e}" not found`),d.push(...f.splice(t,1))}return f.length>0&&d.length>0&&(d=d.flatMap(e=>{if(f.length===0)return e;let n=t.slice(0,t.indexOf(e)).filter(e=>f.includes(e));return n.length>0?(f=f.filter(e=>!n.includes(e)),[...n,e]):e})),d.push(...f),{nodes:Vt(Bt(d)),edges:c}}function Ut(e){return e.hash=et({id:e.id,__:e._type??`element`,autoLayout:e.autoLayout,nodes:b(e.nodes,_(e=>({id:e.id,icon:f(e.icon)&&e.icon!==`none`?`Y`:`N`,title:e.title,description:Me(e.description),technology:e.technology??null,shape:e.shape,size:e.style.size??null,iconSize:e.style.iconSize??null,iconPosition:e.style.iconPosition??null,textSize:e.style.textSize??null,padding:e.style.padding??null,children:e.children})),ve(({id:e,...t})=>[e,t])),edges:b(e.edges,_(e=>({source:e.source,target:e.target,label:e.label,description:Me(e.description),technology:e.technology??null,dir:e.dir,head:e.head,tail:e.tail,line:e.line})),ve(({source:e,target:t,...n})=>[`${e}:${t}`,n]))}),e}var Wt=class{get Ctx(){throw Error(`Should not be called in runtime`)}constructor(e){this.state=e}get elements(){return this.state.elements}get explicits(){return this.state.explicits}get final(){return this.state.final}get connections(){return this.state.connections}isEmpty(){return this.elements.size===0&&this.connections.length===0&&this.explicits.size===0&&this.final.size===0}},Gt=class{excluded={elements:new Set,connections:[]};constructor(e,t){this.memory=e,this.expression=t}markedToMoveExplicitToImplicit=!1;_removeElement(e){this.excluded.elements.add(e)}exclude(e){if(!e)return this;if(M(e)){for(let t of e)this._removeElement(t);return this}return this._removeElement(e),this}_removeConnection(e){this.excluded.connections.push(e)}excludeConnections(e,t){if(be(t)&&(N(!this.markedToMoveExplicitToImplicit,`Already marked to move explicits`),this.markedToMoveExplicitToImplicit=t),M(e)){for(let t of e)this._removeConnection(t);return this}return this._removeConnection(e),this}isDirty(){return this.excluded.elements.size>0||this.excluded.connections.length>0}isEmpty(){return!this.isDirty()}filterForMoveToImplicits(e){return this.markedToMoveExplicitToImplicit||this.excluded.elements.size>0?e:new Set}moveDisconnectedExplicitsToImplicits(e){let t=F(new Set(this.memory.connections.flatMap(e=>[e.source,e.target])),new Set(e.connections.flatMap(e=>[e.source,e.target])));return t=I(t,e.elements),t=b(t,A(t=>e.explicits.has(t)&&!at(e.final,Ke(t))),z()),t.size>0&&(t=this.filterForMoveToImplicits(t),e.explicits=F(e.explicits,t),e.final=F(e.final,t)),e}removeElements(e){return e.elements=F(e.elements,this.excluded.elements),e.explicits=F(e.explicits,this.excluded.elements),e.final=F(e.final,this.excluded.elements),e}removeConnections(e){let t=this.excluded.connections.reduce((e,t)=>{let n=e.get(t.id);return n?e.set(t.id,n.mergeWith(t)):e.set(t.id,t),e},new Map),n=new Set;e.connections=e.connections.reduce((e,r)=>{let i=t.get(r.id);if(i){n.add(r.source),n.add(r.target);let t=r.difference(i);t.nonEmpty()&&e.push(t)}else e.push(r);return e},[]);for(let t of e.connections)n.delete(t.source),n.delete(t.target),t.boundary&&e.elements.has(t.boundary)&&n.delete(t.boundary);return n.size===0?e:(n=F(n,e.explicits),e.final=F(e.final,n),e)}precommit(e){return e}postcommit(e){return N(F(e.explicits,e.elements).size===0,`Explicits must be subset of elements`),N(F(e.final,e.elements).size===0,`Final elements must be subset of elements`),e}commit(){let e=this.precommit(this.memory.mutableState());if(this.excluded.elements.size>0){let t=e.connections.filter(e=>this.excluded.elements.has(e.source)||this.excluded.elements.has(e.target)).flatMap(t=>[t,..._t(e.connections,t).map(e=>e.intersect(t))]).filter(e=>e.nonEmpty());this.excludeConnections(t)}return this.excluded.connections.length>0&&(e=this.removeConnections(e)),this.excluded.elements.size>0&&(e=this.removeElements(e)),this.memory.update(this.postcommit(e))}},Kt=class{explicits=new Set;implicits=new Set;_ordered=new Set;_connections=[];constructor(e,t){this.memory=e,this.expression=t}get elements(){return this.explicits}get connections(){return this._connections}mergedConnections(){return ft([...this.memory.connections,...this._connections])}connectWithExisting(e,t){throw Error(`Method not implements, depends on the model`)}_addExplicit(e){this._ordered.add(e),this.explicits.add(e),this.implicits.delete(e)}addExplicit(e){if(!e)return this;if(M(e)){for(let t of e)this._addExplicit(t);return this}return this._addExplicit(e),this}_addImplicit(e){this.explicits.has(e)||(this._ordered.add(e),this.implicits.add(e))}addImplicit(e){if(!e)return this;if(M(e)){for(let t of e)this._addImplicit(t);return this}return this._addImplicit(e),this}_addConnection(e){this._connections.push(e),this._addImplicit(e.source),this._addImplicit(e.target)}addConnections(e){if(M(e)){for(let t of e)this._addConnection(t);return this}return this._addConnection(e),this}isDirty(){return this.explicits.size>0||this.implicits.size>0||this._connections.length>0}isEmpty(){return!this.isDirty()}precommit(e){return e}postcommit(e){return e}processConnections(e){return e}commit(){let e=this.precommit(this.memory.mutableState()),t=new Set;if(this._connections.length>0){let[n,r]=_e(this._connections,t=>e.final.has(t.source));e.connections=this.processConnections(ft([...e.connections,...n,...r])),t=new Set(e.connections.flatMap(e=>[e.source,e.target]))}return e.elements=R(e.elements,this._ordered,this.explicits,t,this.implicits),e.explicits=I(e.elements,R(e.explicits,this.explicits)),e.final=I(e.elements,R(e.final,this.explicits,t)),this.memory.update(this.postcommit(e))}};function qt(e,t=`final`){let n=Ye(P(t===`final`?e.final:e.elements)),r=new Set(e.connections.flatMap(e=>[e.source,e.target])),i=new Set(n),a=new lt.default(()=>null),o=n.reduce((e,t,n,r)=>(e.set(t,r.slice(n+1).filter(e=>j(t,e)).map(e=>(i.delete(e),e)).reduce((e,n)=>(e.some(e=>j(e,n))||(e.push(n),a.set(n,t)),e),[])),e),new lt.default(()=>[]));return{root:i,connected:r,hasInOut:t=>e.connections.some(B.isAnyInOut(t.id)),parent:e=>a.get(e),children:e=>o.get(e)}}var Jt=class extends Gt{};function V(e){if(E.isCustom(e))return V(e.custom.expr);if(E.isWhere(e)){let t=V(e.where.expr),n=w(e.where.condition);return e=>t(e)&&n(e)}if(E.isElementKindExpr(e))return e.isEqual?t=>t.kind===e.elementKind:t=>t.kind!==e.elementKind;if(E.isElementTagExpr(e))return e.isEqual?({tags:t})=>t.includes(e.elementTag):({tags:t})=>!t.includes(e.elementTag);if(E.isWildcard(e))return()=>!0;if(E.isModelRef(e)){let t=D.flatten(e.ref);if(e.selector===`expanded`)return e=>e.id===t||We(e.id)===t;if(e.selector===`descendants`||e.selector===`children`){let e=t+`.`;return t=>t.id.startsWith(e)}return e=>e.id===t}L(e)}function Yt(e,t,n){let{shape:r,color:a,icon:o,...s}=e.style,c=!l(s);b(n,y(d(Ee)),y(t),i(t=>{t.shape=r??t.shape,t.color=a??t.color,h(o)&&(t.icon=o),h(e.notation)&&(t.notation=e.notation),c&&(t.style={...t.style,...s})}))}function Xt(e,t){for(let n of e)!we(n)||n.targets.length===0||Yt(n,x(n.targets.map(V)),t);return t}var Zt=class e{static kind=De;constructor(e,t,n=null,r=new Set){this.id=e,this.viewRule=t,this.parent=n,this.elements=r}isEmpty(){return this.elements.size===0}update(t){return new e(this.id,this.viewRule,this.parent,t)}clone(){return new e(this.id,this.viewRule,this.parent,new Set(this.elements))}},Qt=class extends Gt{excludeRelations(e){return b(this.memory.connections,y(t=>nt(t.relations,e)),i(t=>{this.excludeConnections(t.update(I(t.relations,e)))})),this}precommit(e){if(this.excluded.elements.size>0){let e=new Set([...this.excluded.elements].flatMap(e=>[...e.incoming(`direct`),...e.outgoing(`direct`)]));this.excludeRelations(e)}return e}postcommit(e){let t=F(this.memory.explicits,e.explicits);for(let n of t)e.explicitFirstSeenIn.delete(n);let n=F(this.memory.elements,e.elements);for(let t of n)e.lastSeenIn.delete(t);return e}},$t=class extends Qt{constructor(e,t){super(e,t),this.memory=e,this.expression=t}};const{findConnection:en,findConnectionsBetween:tn}=Dt;var nn=class extends Kt{connectWithExisting(e,t=`both`){let n=this._connections.length,r=()=>this._connections.length>n;if(!M(e)){if(t===`in`||t===`both`)for(let t of this.memory.elements)this.addConnections(en(t,e,`directed`));return(t===`out`||t===`both`)&&this.addConnections(tn(e,this.memory.elements,`directed`)),r()}let i=[...e];if(t===`in`||t===`both`)for(let e of this.memory.elements)this.addConnections(tn(e,i,`directed`));if(t===`out`||t===`both`)for(let e of i)this.addConnections(tn(e,this.memory.elements,`directed`));return r()}addImplicitWithinScope(e){e&&(!this.memory.scope||j(this.memory.scope,e))&&this.addImplicit(e)}processConnections(e){return Se.isRelationExpr(this.expression)||b(e,i(({source:e,target:t,boundary:n})=>{b(me([...P(e.ancestors()).reverse(),e],[...P(t.ancestors()).reverse(),t]),ee(([e,t])=>e===t),de(1),i(([r,i])=>{if(r===e&&i===t){this.addImplicitWithinScope(n);return}r!==e&&this.addImplicitWithinScope(r),i!==t&&this.addImplicitWithinScope(i)}))})),e}postcommit(e){let t=F(e.explicits,this.memory.explicits);for(let n of t)e.explicitFirstSeenIn.set(n,`@root`);return e}},rn=class extends nn{constructor(e,t){super(e,t),this.memory=e,this.expression=t}postcommit(e){let t=F(e.explicits,this.memory.explicits);for(let n of t)e.explicitFirstSeenIn.set(n,this.memory.activeGroupId);for(let t of[...this.explicits,...this.implicits])e.lastSeenIn.set(t,this.memory.activeGroupId);return e}},an=class e extends Wt{static empty(t){return new e({elements:new Set,explicits:new Set,final:new Set,connections:[],groups:[],explicitFirstSeenIn:new Map,lastSeenIn:new Map},t)}constructor(e,t){super(e),this.state=e,this.scope=t}get groups(){return this.state.groups}get explicitFirstSeenIn(){return this.state.explicitFirstSeenIn}get lastSeenIn(){return this.state.lastSeenIn}stageInclude(e){return new nn(this,e)}stageExclude(e){return new Qt(this,e)}mutableState(){return{elements:new Set(this.state.elements),explicits:new Set(this.state.explicits),final:new Set(this.state.final),connections:[...this.state.connections],groups:this.state.groups.map(e=>e.clone()),explicitFirstSeenIn:new Map(this.state.explicitFirstSeenIn),lastSeenIn:new Map(this.state.lastSeenIn)}}update(t){return new e({...this.state,...t},this.scope)}},on=class e extends an{static enter(t,n){let r=`@gr${t.groups.length+1}`;if(t instanceof e){let i=ct.default.from([...t.stack].reverse()),a=t.mutableState();return a.groups.push(new Zt(r,n,t.activeGroupId)),i.push(r),new e(a,t.scope,i)}let i=t.mutableState();i.groups.push(new Zt(r,n,null));let a=ct.default.of(r);return new e(i,t.scope,a)}constructor(e,t,n){super(e,t),this.state=e,this.scope=t,this.stack=n}get activeGroupId(){return k(this.stack.peek(),`Stack must not be empty`)}mutableState(){return{...super.mutableState()}}update(t){return new e({...this.state,...t},this.scope,this.stack)}stageInclude(e){return new rn(this,e)}stageExclude(e){return new $t(this,e)}leave(){let t=this.mutableState();return this.stack.pop(),this.stack.peek()?new e(t,this.scope,this.stack):new an(t,this.scope)}};function sn(e,t){let n;for(;e.parent&&(n=t.get(e.parent));){let t=n.depth??1;if(n.depth=Math.max(t,(e.depth??0)+1),n.depth===t)break;e=n}}function cn(e){let{id:t,title:n,...r}=g(e.$element,[`summary`,`description`,`metadata`,`style`,`tags`]),{color:i,icon:a,shape:o,...s}=e.style;return T({id:t,title:n,modelRef:t,shape:o,color:i,icon:a,style:s,description:Ve(e.$element),tags:[...e.tags],metadata:e.$element.metadata,...r})}function ln({defaults:e},t,n){let r=new Map,i=new Map;n?.forEach(({id:t,parent:n,viewRule:a,elements:o})=>{n&&k(r.get(n),`Parent group node ${n} not found`).children.push(t),r.set(t,{id:t,parent:n,kind:De,title:a.title??``,color:a.color??e.group.color??e.color,shape:`rectangle`,children:[],inEdges:[],outEdges:[],level:0,depth:0,tags:[],style:T({border:a.border??e.group.border,opacity:a.opacity??e.group.opacity,size:a.size,multiple:a.multiple,padding:a.padding,textSize:a.textSize})});for(let e of o)i.set(e.id,t)}),Array.from(t).sort(qe).forEach(({id:e,...t})=>{let n=We(e),a=0,o;for(;n&&(o=r.get(n),!o);)n=We(n);let s=t.modelRef??e;if(!o&&i.has(s)){let e=k(i.get(s));o=r.get(e),n=e}o&&(o.children.length==0&&(o.depth=1,sn(o,r)),o.children.push(e),a=o.level+1);let c=T({id:e,parent:n,level:a,children:[],inEdges:[],outEdges:[],...t});r.set(e,c)});let a=new Map;return n?.forEach(({id:e})=>{a.set(e,k(r.get(e)))}),t.forEach(({id:e})=>{a.set(e,k(r.get(e)))}),a}function un(e){let{title:t,description:n=null}=e;return{...t&&{title:t,description:n},...te(e,[`color`,`technology`,`head`,`line`,`tail`,`kind`,`navigateTo`])}}function dn(e,t){let n=b(e,re((e,t)=>(f(t.title)&&!e.title.includes(t.title)&&e.title.push(t.title),f(t.description)&&!e.description.some(v(t.description))&&e.description.push(t.description),f(t.technology)&&!e.technology.includes(t.technology)&&e.technology.push(t.technology),f(t.kind)&&!e.kind.includes(t.kind)&&e.kind.push(t.kind),f(t.color)&&!e.color.includes(t.color)&&e.color.push(t.color),f(t.line)&&!e.line.includes(t.line)&&e.line.push(t.line),f(t.head)&&!e.head.includes(t.head)&&e.head.push(t.head),f(t.tail)&&!e.tail.includes(t.tail)&&e.tail.push(t.tail),f(t.navigateTo)&&!e.navigateTo.includes(t.navigateTo)&&e.navigateTo.push(t.navigateTo),t.tags&&e.tags.push(...t.tags),e),{title:[],description:[],technology:[],kind:[],head:[],tail:[],color:[],tags:[],line:[],navigateTo:[]})),r=S(n.title)??(n.title.length>1?`[...]`:void 0),i=oe(n.tags),a=T({title:r,description:S(n.description),technology:S(n.technology),kind:S(n.kind),head:S(n.head),tail:S(n.tail),color:S(n.color),line:S(n.line),navigateTo:S(n.navigateTo),...Ge(i)&&{tags:i}});if(t){let e=un(t);a=ie({...a,...e},f)}return u(a.title)&&f(a.technology)&&(a.title=`[${a.technology}]`,delete a.technology),a}const{findConnection:fn,findConnectionsBetween:H,findConnectionsWithin:pn}=wt;function U(e,t){let n=e.element(t.ref.deployment);if(n.isDeploymentNode()){if(t.selector===`children`)return[...n.children()];if(t.selector===`expanded`)return[n,...n.children()];if(t.selector===`descendants`)return[...n.descendants()]}return[n]}function mn(e,t){let n=e.$model.element(t.ref.model);return t.selector===`children`?[...n.children()]:t.selector===`expanded`?[n,...n.children()]:t.selector===`descendants`?[...n.descendants()]:[n]}function hn(e){if(O.isWildcard(e))return()=>!0;if(O.isElementTagExpr(e)||O.isElementKindExpr(e))throw Error(`element kind and tag expressions are not supported in deployment view rules`);if(O.isDeploymentRef(e)){let t=e.ref.deployment;if(e.selector===`expanded`){let e=t+`.`;return n=>n.id===t||n.id.startsWith(e)}if(e.selector===`descendants`){let e=t+`.`;return t=>t.id.startsWith(e)}return e.selector===`children`?e=>We(e.id)===t:e=>e.id===t}if(O.isModelRef(e)){let t=e.ref.model;if(e.selector===`expanded`){let e=t+`.`;return n=>{let r=n.modelRef??null;return r?r===t||r.startsWith(e):!0}}if(e.selector===`descendants`){let e=t+`.`;return t=>{let n=t.modelRef??null;return n?n.startsWith(e):!0}}return e.selector===`children`?e=>{let n=e.modelRef??null;return n?We(n)===t:!0}:e=>{let n=e.modelRef??null;return n?n===t:!0}}L(e)}function gn(e){return Ve(e.$instance)??Ve(e.element.$element)}function _n(e){let t=e.id,n=e.onlyOneInstance();return T({id:t,deploymentRef:t,title:e.title,kind:e.kind,technology:e.technology??void 0,links:m(e.links,1)?[...e.links]:void 0,notation:e.$node.notation??void 0,color:e.color,shape:e.shape,modelRef:n?.element.id,icon:e.style.icon,description:Ve(e.$node)??void 0,tags:[...e.tags],style:g(e.style,[`icon`,`shape`,`color`])})}function vn(e){let t=e.$instance,n=e.element,{icon:r,color:i,shape:a,...o}=e.style,s=[...n.links,...t.links??[]];return T({id:e.id,kind:`instance`,title:e.title,description:gn(e)??void 0,technology:e.technology??void 0,tags:[...e.tags],links:m(s,1)?s:void 0,icon:r,color:i,shape:a,style:o,deploymentRef:t.id,modelRef:n.id,notation:t.notation})}function yn(e){return e.isInstance()?vn(e):_n(e)}function bn(e){return e.reduce((e,t)=>{let n=[...t.relations.model,...t.relations.deployment];N(m(n,1),`Edge must have at least one relation`);let r=t.source.$model.$styles.defaults,i=t.source.id,a=t.target.id,{title:o,color:s=r.relationship.color,line:c=r.relationship.line,head:l=r.relationship.arrow,...u}=dn(n.map(e=>e.$relationship)),d=T({id:t.id,parent:t.boundary?.id??null,source:i,target:a,label:o??null,relations:n.map(e=>e.id),color:s,line:c,head:l,...u}),f=e.find(e=>e.source===a&&e.target===i);if(f&&d.label===f.label){f.dir=`both`;let n=f.head??d.head??t.source.$model.$styles.defaults.relationship.arrow;return f.head??=n,f.tail??=n,d.color&&(f.color??=d.color),d.line&&(f.line??=d.line),e}return e.push(d),e},[])}function xn(e,t){let n=ln(e.$styles,[...t.final].map(yn));for(let t of n.values()){if(!t.deploymentRef||!t.modelRef||t.children.length>0)continue;let n=e.deployment.element(t.deploymentRef),r=n.isDeploymentNode()&&n.onlyOneInstance();if(!r)continue;t.title===n.name&&(t.title=r.title),t.description??=gn(r)??null,t.technology??=r.technology,l(t.tags)&&(t.tags=[...r.tags]),(!t.links||l(t.links))&&m(r.links,1)&&(t.links=[...r.links]);let i=e.$styles.defaults;t.shape===i.shape&&t.shape!==r.shape&&(t.shape=r.shape,t.notation=null),t.color===i.color&&t.color!==r.color&&(t.color=r.color,t.notation=null),!t.icon&&r.icon&&(t.icon=r.icon)}return n}function Sn(e,t){for(let n of e)!we(n)||n.targets.length===0||Yt(n,x(n.targets.map(hn)),t);return t}function Cn(e){let t=new lt.default(()=>[]);for(let n of e)for(let e of n.relations.model)t.get(e).push(n);let n=new lt.default(()=>new Set);for(let[e,r]of t)m(r,2)&&b(r,c(e=>[{group:`$source-${e.source.id}`,conn:e},{group:`$target-${e.target.id}`,conn:e}]),a(ce(`group`)),pe(),y(m(2)),i(ae(_(ce(`conn`)),ht(`desc`),ee((e,t,n)=>t===0||e.boundary===n[t-1].boundary),i(t=>{n.get(t).add(e)}))));return n}function wn(e){e=ft(e);let t=Cn(e);for(let n of e){let{source:e,target:r}=n,i=n.relations.model;if(e.isDeploymentNode()!==r.isDeploymentNode()){let r=e.isDeploymentNode()?e:n.target;N(r.isDeploymentNode());let a=I(i,r.internalModelRelationships());for(let e of a)t.get(n).add(e);continue}if(e.isDeploymentNode()&&r.isDeploymentNode()){let i=R(I(n.relations.model,e.internalModelRelationships()),I(n.relations.model,r.internalModelRelationships()));for(let e of i)t.get(n).add(e)}}return b(t.entries(),it(([e,t])=>e.update({model:t,deployment:null})),P())}function Tn(e){return xt(e,wn(e))}function En(e){return b(e,ft,re((t,n)=>{let{source:r,target:i,relations:a}=n;if(r.isInstance()&&i.isInstance())return t;let o=Ot.empty();if(r.isDeploymentNode()&&i.isDeploymentNode()){let[e]=fn(i,r,`directed`);e&&(o=a.intersect(e.relations))}for(let t of e)gt(t,n)&&(o=o.union(a.intersect(t.relations)));return o.nonEmpty&&t.push(new ut(r,i,o)),t},[]))}function Dn(e){return xt(e,En(e))}var On=class extends Kt{connectWithExisting(e,t=`both`){let n=this._connections.length,r=()=>this._connections.length>n;if(!M(e)){if(t===`in`||t===`both`)for(let t of this.memory.elements)this.addConnections(fn(t,e,`directed`));return(t===`out`||t===`both`)&&this.addConnections(H(e,this.memory.elements,`directed`)),r()}let i=[...e];if(t===`in`||t===`both`)for(let e of this.memory.elements)this.addConnections(H(e,i,`directed`));if(t===`out`||t===`both`)for(let e of i)this.addConnections(H(e,this.memory.elements,`directed`));return r()}processConnections(e){let t=b(e,Tn,Dn);return b(t,i(({source:e,target:t,boundary:n})=>{b(me([...P(e.ancestors()).reverse(),e],[...P(t.ancestors()).reverse(),t]),ee(([e,t])=>e===t),de(1),i(([r,i])=>{if(e===r&&t===i){this.addImplicit(n);return}r!==e&&r.isDeploymentNode()&&!r.onlyOneInstance()&&this.addImplicit(r),i!==t&&i.isDeploymentNode()&&!i.onlyOneInstance()&&this.addImplicit(i)}))})),t}},kn=class e extends Wt{static empty(){return new e({elements:new Set,explicits:new Set,final:new Set,connections:[]})}stageInclude(e){return new On(this,e)}stageExclude(e){return new Jt(this,e)}mutableState(){return{elements:new Set(this.state.elements),explicits:new Set(this.state.explicits),final:new Set(this.state.final),connections:[...this.state.connections]}}update(t){return new e({...this.state,...t})}equals(t){return t instanceof e&&v(this.state,t.state)}diff(e){return{added:{elements:P(F(e.elements,this.elements)),explicits:P(F(e.explicits,this.explicits)),final:P(F(e.final,this.final)),connections:P(xt(e.connections,this.connections))},removed:{elements:P(F(this.elements,e.elements)),explicits:P(F(this.explicits,e.explicits)),final:P(F(this.final,e.final)),connections:xt(this.connections,e.connections)}}}toString(){return[`final:`,...[...this.final].map(e=>` `+e.id),`connections:`,...this.connections.map(e=>` `+e.expression)].join(`
2
- `)}[Ct](e,t,n){return this.toString()}};const An={include:({expr:e,model:t,memory:n,stage:r})=>{let i=w(e.where.condition);return k(Hn(`include`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i}))},exclude:({expr:e,model:t,memory:n,stage:r})=>{let i=w(e.where.condition);return k(Hn(`exclude`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i}))}},jn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(O.isWildcard(e.incoming)){for(let e of a){if(e.allOutgoing.isEmpty)continue;let t=G(H(e,[...qn(e)],`directed`),i);r.addConnections(t)}return r}N(O.isDeploymentRef(e.incoming),`Only deployment refs are supported in include`);let o=U(t,e.incoming);for(let e of a){let t=G(H(e,o,`directed`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(O.isElementTagExpr(e.incoming)||O.isElementKindExpr(e.incoming))throw Error(`element kind and tag expressions are not supported in exclude`);if(O.isModelRef(e.incoming))return W(Nn(t,e.incoming),{stage:r,memory:n},i);if(O.isWildcard(e.incoming))return r;let a=Mn(U(t,e.incoming)),o=b(n.connections,y(a),G(i));return r.excludeConnections(o),r}};function Mn(e){return x(e.map(e=>{let t=t=>t===e||j(e,t);return e=>!t(e.source)&&t(e.target)}))}function Nn(e,t){let n=mn(e,t);return new Set(n.flatMap(e=>[...e.allIncoming]))}const Pn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(O.isWildcard(e.outgoing)){for(let e of a)if(!e.allIncoming.isEmpty)for(let t of qn(e)){let n=G(fn(t,e,`directed`),i);r.addConnections(n)}return r}N(O.isDeploymentRef(e.outgoing),`Only deployment refs are supported in include`);let o=U(t,e.outgoing);for(let e of o){let t=G(H(e,a,`directed`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(O.isElementTagExpr(e.outgoing)||O.isElementKindExpr(e.outgoing))throw Error(`element kind and tag expressions are not supported in exclude`);if(O.isModelRef(e.outgoing))return W(In(t,e.outgoing),{stage:r,memory:n},i);if(O.isWildcard(e.outgoing))return r;let a=Fn(U(t,e.outgoing)),o=b(n.connections,y(a),G(i));return r.excludeConnections(o),r}};function Fn(e){return x(e.map(e=>{let t=t=>t===e||j(e,t);return e=>t(e.source)&&!t(e.target)}))}function In(e,t){let n=mn(e,t);return new Set(n.flatMap(e=>[...e.allOutgoing]))}const Ln={include:({expr:{source:e,target:t,isBidirectional:n=!1},model:r,stage:i,where:a})=>{if(O.isElementTagExpr(e)||O.isElementKindExpr(e)||O.isElementTagExpr(t)||O.isElementKindExpr(t))throw Error(`element kind and tag expressions are not supported in include`);N(!O.isModelRef(e),`Invalid source model ref in direct relation`),N(!O.isModelRef(t),`Invalid target model ref in direct relation`);let o=O.isWildcard(e),s=O.isWildcard(t),l=n?`both`:`directed`,u;switch(!0){case o&&s:u=b(pn(r.instances()),G(a),_(e=>(i.addImplicit(e.boundary),e)));break;case!o&&s:{let t=U(r,e),i=Fn(t),o=i;if(n){let e=Mn(t);o=t=>i(t)!==e(t)}u=b(t,c(e=>H(e,qn(e),l)),y(o),G(a));break}case o&&!s:{let e=U(r,t),i=Mn(e),o=i;if(n){let t=Fn(e);o=e=>t(e)!==i(e)}u=b(e,c(e=>[...qn(e)].flatMap(t=>fn(t,e,l))),y(o),G(a));break}default:{N(!o,`Inference failed - source should be a deployment ref`),N(!s,`Inference failed - target should be a deployment ref`);let n=U(r,e),i=U(r,t),d=Fn(n),f=Mn(i);u=b(n,c(e=>H(e,i,l)),y(e=>d(e)&&f(e)),G(a))}}return i.addConnections(u),O.isDeploymentRef(e)&&p(e.selector)&&i.addImplicit(r.element(e.ref.deployment)),O.isDeploymentRef(t)&&p(t.selector)&&i.addImplicit(r.element(t.ref.deployment)),i},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=hn(e.target),o=hn(e.source),s;switch(!0){case O.isWildcard(e.source)&&O.isWildcard(e.target):return r.excludeConnections(G(n.connections,i)),r;case O.isModelRef(e.source)&&O.isModelRef(e.target):return s=Rn({source:e.source,target:e.target,expr:e,model:t}),W(s,{stage:r,memory:n},i);case O.isModelRef(e.source)&&O.isWildcard(e.target):return s=In(t,e.source),W(s,{stage:r,memory:n},i);case O.isModelRef(e.source):return s=In(t,e.source),W(s,{stage:r,memory:n},i,e=>a(e.target));case O.isModelRef(e.target):return s=Nn(t,e.target),W(s,{stage:r,memory:n},i,e=>o(e.source));default:let c=t=>o(t.source)&&a(t.target)||e.isBidirectional===!0&&o(t.target)&&a(t.source),l=b(n.connections,y(c),G(i));return l.length===0||r.excludeConnections(l),r}}};function Rn({source:e,target:t,expr:n,model:r}){let i=mn(r,e),a=mn(r,t),o=n.isBidirectional?`both`:`directed`,s=[];for(let e of i)s.push(...bt(e,a,o));return new Set(s.flatMap(e=>[...e.relations]))}const zn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(O.isWildcard(e.inout)){for(let e of a){let t=Wn(H(e,[...qn(e)],`both`),i);r.addConnections(t)}return r}N(O.isDeploymentRef(e.inout),`Only deployment refs are supported in include`);let o=U(t,e.inout);for(let e of a){let t=Wn(H(e,o,`both`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(O.isElementTagExpr(e.inout)||O.isElementKindExpr(e.inout))throw Error(`element kind and tag expressions are not supported in exclude`);if(O.isModelRef(e.inout)){let a=mn(t,e.inout);return a.length===0?r:W(R(new Set,...a.flatMap(e=>[e.allIncoming,e.allOutgoing])),{stage:r,memory:n},i)}if(O.isWildcard(e.inout))return r;let a=U(t,e.inout),o=Mn(a),s=Fn(a),c=b(n.connections,y(e=>o(e)!==s(e)),G(i));return r.excludeConnections(c),r}},Bn={include:({expr:e,model:t,memory:n,stage:r})=>{let i=w(e.where.condition);return Hn(`include`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})},exclude:({expr:e,model:t,memory:n,stage:r})=>{let i=w(e.where.condition);return Hn(`exclude`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})}},Vn={include:({model:e,stage:t,where:n})=>{let r=[],i;return i=n?b([...e.elements()],K(n)):P(it(e.roots(),e=>(e.onlyOneInstance()||r.push(...e.children()),e))),t.addExplicit(i),r.length>1?(t.addConnections(pn([...i,...r])),t.connectWithExisting(r)):t.addConnections(pn(i)),t.connectWithExisting(i),t},exclude:({stage:e,memory:t,where:n})=>{let r=b([...t.elements],K(n));return e.exclude(r),e}};function Hn(e,{expr:t,where:n,...r}){switch(!0){case O.isElementTagExpr(t):case O.isElementKindExpr(t):throw Error(`element kind and tag expressions are not supported in deployment view rules`);case xe.isCustom(t):case O.isCustom(t):case O.isModelRef(t):return;case O.isWhere(t):return An[e]({...r,expr:t,where:n});case xe.isWhere(t):return Bn[e]({...r,expr:t,where:n});case O.isDeploymentRef(t):return Jn[e]({...r,expr:t,where:n});case O.isWildcard(t):return Vn[e]({...r,expr:t,where:n});case xe.isDirect(t):return Ln[e]({...r,expr:t,where:n});case xe.isInOut(t):return zn[e]({...r,expr:t,where:n});case xe.isOutgoing(t):return Pn[e]({...r,expr:t,where:n});case xe.isIncoming(t):return jn[e]({...r,expr:t,where:n});default:L(t)}}function W(e,{stage:t,memory:n},r,i=()=>!0){if(e.size===0)return t;let a=b(n.connections,y(e=>i(e)),y(t=>nt(t.relations.model,e)),_(t=>t.update({deployment:null,model:I(t.relations.model,e)})),G(r),y(e=>e.nonEmpty()));return a.length===0?t:t.excludeConnections(a)}function Un(e,t){return G(e,t).nonEmpty()}function G(...e){if(e.length===1)return t=>G(t,e[0]);let[n,r]=e;return r===null?n:t(n)?n.map(e=>G(e,r)).filter(e=>e.nonEmpty()):n.update({model:new Set([...n.relations.model.values()].filter(e=>r(Kn(n)(e)))),deployment:new Set([...n.relations.deployment.values()].filter(e=>r(Kn(n)(e))))})}function K(...e){if(e.length===1){let t=e[0];return t==null?e=>e:e=>e.filter(e=>t(Gn(e,e)))}let[n,r]=e;return t(n)?r==null?n:n.filter(e=>r(Gn(e,e))):r?.(Gn(n,n))??!0}function Wn(e,t){return t?b(e,y(e=>Un(e,t))):e}function Gn(e,t){if(Et(e)){let n=Tt(t)&&At(t)?t:null;return{kind:e.kind,tags:[...e.tags,...n?.tags??[]],metadata:e.metadata}}if(vt(e))return te(e.element,[`tags`,`kind`,`metadata`]);if(At(e))return{kind:e.element.kind,tags:[...e.tags,...e.element.tags],metadata:e.metadata};if(kt(e))return te(e,[`tags`,`kind`,`metadata`]);L(e)}function Kn(e){return t=>({tags:t.tags,kind:t.kind,metadata:t.metadata,source:Gn(t.source,e.source),target:Gn(t.target,e.target)})}function qn(e){let t=new Set;for(let n of e.descendingSiblings())t.add(n);return t}const Jn={include:e=>{let{expr:t,where:n}=e,r=e.model.element(t.ref.deployment);if(At(r))return K(r,n)&&(e.stage.addExplicit(r),e.stage.connectWithExisting(r)),e.stage;switch(!0){case t.selector===`expanded`:Xn(r,e);break;case t.selector===`children`:Yn(r,e);break;case t.selector===`descendants`:Zn(r,e);break;default:K(r,n)&&(e.stage.addExplicit(r),e.stage.connectWithExisting(r))}return e.stage},exclude:({expr:e,stage:t,memory:n,where:r})=>{let i=hn(e),a=b([...n.elements],y(i),K(r));return t.exclude(a),t}};function Yn(e,{stage:t,where:n}){let r=K([...e.children()],n);r.length!==0&&(t.addImplicit(e),t.addConnections(pn(r)),t.connectWithExisting(r),t.addExplicit(r))}function Xn(e,{memory:t,stage:n,where:r}){n.addImplicit(e),n.connectWithExisting(e);let i=K([...e.children()],r),a=!1;for(let e of i)if(H(e,t.elements).length>0){a=!0;break}a&&(n.connectWithExisting(i,`in`),n.addConnections(pn(i)),n.connectWithExisting(i,`out`)),n.addImplicit(i),n.connections.length>0&&n.addExplicit(e)}function Zn(e,{stage:t,where:n}){let r=e=>{let i=[];for(let t of e.children())t.isDeploymentNode()&&i.push(...r(t)),K(t,n)&&i.push(t);return t.connectWithExisting(i,`in`),t.addConnections(pn(i)),t.addImplicit(i),i},a=r(e);if(a.length===0)return;t.connectWithExisting(a,`out`);let o=Qn(t);b(a,y(e=>o.has(e)),i(e=>t.addExplicit(e)))}function Qn(e){return b(e.mergedConnections(),Tn,Dn,re((e,t)=>(e.add(t.source),e.add(t.target),e),new Set))}var $n=class e{static for(t){return new e(t)}constructor(e){this.memory=e}step1CleanConnections(e){if(e.connections.length<2)return e;let t=b(e.connections,Tn,Dn),n=xt(e.connections,t);if(n.length===0)return e;let r=e.stageExclude({});return r.excludeConnections(n,!0),r.commit()}step2ProcessImplicits(e){let t=R(this.memory.elements,e.elements),n=R(e.final,this.memory.explicits),r=new lt.default(()=>new Set);for(let t of e.connections)if(t.boundary)for(let e of t.relations.model)r.get(e).add(t.boundary);for(let[e,i]of r)if(!(i.size<2))for(let e of i)t.delete(e)&&n.add(e);let a=new Set(n),o=e=>{for(let t of a)if(e===t||j(e,t))return!0;return!1};return b(F(t,a),A(e=>e.isDeploymentNode()),P(),Xe,i(e=>{let t=[...e.children()].filter(o).length;if(t>=2){n.add(e);return}t===1&&at(e.siblings(),o)&&n.add(e)})),e.update({final:n})}step3ProcessBoundaries(e){let t=new Set;for(let n of e.connections)n.boundary&&t.add(n.boundary);let n=qt(e,`final`),r=e.stageExclude({}),i=r=>!(t.has(r)||e.explicits.has(r)||n.hasInOut(r)||n.root.has(r)),a=S([...n.root]);a&&!e.explicits.has(a)&&r.exclude(a);for(let t of e.final){let e=S(n.children(t));e&&!n.hasInOut(e)&&i(t)&&r.exclude(t)}return r.isDirty()?r.commit():e}commit(){let e=this.step1CleanConnections(this.memory),t=this.step2ProcessImplicits(e);return this.step3ProcessBoundaries(t)}};function er(e,t){let n=kn.empty();for(let r of t)if(He(r)){let t=`include`in r?`include`:`exclude`,i=r.include??r.exclude;for(let r of i){let i=t===`include`?n.stageInclude(r):n.stageExclude(r);i=Hn(t,{expr:r,model:e,stage:i,memory:n,where:null})??i,n=i.commit()}}return $n.for(n).commit()}function tr(e,{docUri:t,rules:n,...r}){let i=er(e.deployment,n),a=xn(e,i),o=bn(i.connections);Lt(a,o);let c=Ht({nodes:a,edges:o}),l=Sn(n,c.nodes),u=s(n,je),d=Pt(l);return Ut({...r,[Ce]:`computed`,[Be]:`deployment`,autoLayout:{direction:u?.direction??`TB`,...u?.nodeSep&&{nodeSep:u.nodeSep},...u?.rankSep&&{rankSep:u.rankSep}},edges:c.edges,nodes:_(l,e=>(e.icon===`none`&&delete e.icon,e)),...d.length>0&&{notation:{nodes:d}}})}function nr(e){return t=>Ne(t)?t.groupRules.flatMap(nr(e)):He(t)&&`include`in t?t.include.filter(e):[]}function rr(e,t){let n=e.flatMap(nr(E.isCustom));if(n.length===0)return t;let r=[...t];for(let{custom:{expr:e,...t}}of n){let{border:n,opacity:i,multiple:a,iconColor:s,iconSize:c,iconPosition:l,padding:d,size:f,textSize:p,...m}=ye(t,u),h=T({border:n,opacity:i,multiple:a,iconColor:s,iconSize:c,iconPosition:l,padding:d,size:f,textSize:p}),g=!o(h),_=!o(m),v=V(e);r.forEach((e,t)=>{Ee(e)||!v(e)||(_&&(e={...e,...m,isCustomized:!0}),g&&(e={...e,isCustomized:!0,style:{...e.style,...h}}),r[t]=e)})}return r}function ir(e,t){return e.reduce((e,n)=>{if(ze(n)){let r=t.predicates[n.predicateId];return u(r)?e:e.concat(r)}if(Te(n)){let r=t.styles[n.styleId];return u(r)?e:e.concat(r)}return e.push(n),e},[])}function ar(e,t){return e.reduce((e,n)=>{if(ze(n)){let r=t.dynamicPredicates[n.predicateId];return u(r)?e:e.concat(r)}if(Te(n)){let r=t.styles[n.styleId];return u(r)?e:e.concat(r)}return e.push(n),e},[])}function or(e,t){let n=new Set;for(let r of t)if(He(r))for(let t of r.include){let r=V(t);for(let t of e.elements())r(t)&&n.add(t)}return n}const sr=e=>{if(Pe(e)){let t=[],n=[];for(let r of e.__parallel)if(Le(r)){let[e,...i]=r.__series;t.push(e),n.push(...i)}else t.push(r);return[...t,...n]}return Le(e)?[...e.__series]:e};function cr(e,t){let n=[],r=(...[e,t])=>{if(!n.includes(e)){let r=n.indexOf(t);if(r>0){n.splice(r,0,e);return}else n.push(e)}n.includes(t)||n.push(t)};for(let i of c(t,sr)){let t=e.element(i.source),a=e.element(i.target),o=n.indexOf(t),s=n.indexOf(a);o>=0&&s>=0||(i.isBackward?r(a,t):r(t,a))}return new Set(n)}function lr(e,t,n){let r=yt(e,t,`directed`).flatMap(e=>[...e.relations]).sort(Qe);if(!Ge(r))return{};if(r.length===1){let e=r[0];return T({title:e.title??void 0,kind:e.kind??void 0,tags:e.tags,relations:[e.id],navigateTo:e.$relationship.navigateTo,color:e.$relationship.color,line:e.$relationship.line,technology:e.technology??void 0,description:e.$relationship.description??void 0})}let i=b(r,c(e=>e.tags),oe()),a=m(i,1)?i:void 0,o=_(r,e=>e.id),s=fe(r).$relationship.navigateTo;s===n&&(s=void 0),s||=b(r,c(e=>e.$relationship.navigateTo&&e.$relationship.navigateTo!==n?e.$relationship.navigateTo:[]),oe(),S());let l=b(r,re((e,{title:t,technology:n,$relationship:r})=>(f(t)&&e.title.add(t),f(r.color)&&e.color.add(r.color),f(r.line)&&e.line.add(r.line),f(r.kind)&&e.kind.add(r.kind),f(n)&&e.technology.add(n),f(r.description)&&!e.description.some(v(r.description))&&e.description.push(r.description),e),{kind:new Set,color:new Set,line:new Set,title:new Set,technology:new Set,description:[]}));return T({tags:a??void 0,relations:o,navigateTo:s,kind:S([...l.kind]),title:S([...l.title]),color:S([...l.color]),line:S([...l.line]),technology:S([...l.technology]),description:S(l.description)})}var ur=class{steps=[];constructor(e,t){this.model=e,this.view=t}compute(){let{docUri:e,rules:t,steps:n,...r}=this.view,i=ar(t,this.model.globals),a=or(this.model,i),o=cr(this.model,n),c=b(R(I(a,o),o,a),P(),Ye),l=c.reduce((e,t,n,r)=>{for(let i=n+1;i<r.length;i++){let n=r[i];if(j(t,n)){e.push(t);break}}return e},[]),u=(e,t,n)=>{if(Le(e)){for(let r of e.__series)t=u(r,t,n);return t}let r=n?Ae(n,t):Ae(t),{source:i,target:a,title:o,isBackward:s,navigateTo:d,notation:p,...m}=e,h=this.model.element(i),g=c.indexOf(h);N(g>=0,`Source ${i} not found`);let _=this.model.element(a),v=c.indexOf(_);N(v>=0,`Target ${a} not found`),(l.includes(h)||l.includes(_))&&console.error(`Step ${h.id} -> ${_.id} because it involves a compound`);let{title:y,relations:ee,navigateTo:te,...ne}=lr(h,_,this.view.id),re=f(d)&&d!==this.view.id?d:te,b=e.kind?this.model.specification.relationships[e.kind]:void 0;return this.steps.push(T({...ne,...!e.technology&&!ne.technology&&b?.technology&&{technology:b.technology},...!e.color&&!ne.color&&b?.color&&{color:b.color},...!e.line&&!ne.line&&b?.line&&{line:b.line},...!e.head&&b?.head&&{head:b.head},...!e.tail&&b?.tail&&{tail:b.tail},...m,id:r,source:h,target:_,navigateTo:re,title:o??y,relations:ee??[],isBackward:g>v})),t+1},d=1;for(let e of n){if(Pe(e)){let t=1;for(let n of e.__parallel)t=u(n,t,d);d++;continue}d=u(e,d)}let p=ln(this.model.$styles,c.map(cn)),m=this.model.$styles.defaults.relationship,h=this.steps.map(({id:e,source:t,target:n,relations:r,title:i,isBackward:a,tags:o,...s})=>{let c=k(p.get(t.id),`Source node ${t.id} not found`),l=k(p.get(n.id),`Target node ${n.id} not found`),u={id:e,parent:tt(t.id,n.id),source:c.id,target:l.id,label:i??null,relations:r,color:m.color,line:m.line,head:m.arrow,tags:o??[],...s};for(a&&(u.dir=`back`);u.parent&&!p.has(u.parent);)u.parent=We(u.parent);c.outEdges.push(u.id),l.inEdges.push(u.id);for(let e of Ue(u.source)){if(e===u.parent)break;p.get(e)?.outEdges.push(u.id)}for(let e of Ue(u.target)){if(e===u.parent)break;p.get(e)?.inEdges.push(u.id)}return u}),g=rr(i,Xt(i,c.map(e=>k(p.get(e.id))))),v=s(i,je),y=Pt(g);return Ut({...r,[Be]:`dynamic`,[Ce]:`computed`,variant:r.variant??`diagram`,autoLayout:{direction:v?.direction??`LR`,...v?.nodeSep&&{nodeSep:v.nodeSep},...v?.rankSep&&{rankSep:v.rankSep}},nodes:_(g,e=>(e.icon===`none`&&delete e.icon,e)),edges:h,...y.length>0&&{notation:{nodes:y}}})}};function dr(e,t){return new ur(e,t).compute()}function fr(e){switch(!0){case C.isCustom(e):return fr(e.customRelation.expr);case C.isWhere(e):{let t=fr(e.where.expr),n=w(e.where.condition);return e=>t(e)&&n({source:{tags:e.source.tags,kind:e.source.kind,metadata:e.source.metadata},target:{tags:e.target.tags,kind:e.target.kind,metadata:e.target.metadata},...e.tags&&{tags:e.tags},...e.kind&&{kind:e.kind},...e.metadata&&{metadata:e.metadata}})}case C.isDirect(e):{let t=V(e.source),n=V(e.target);return r=>t(r.source)&&n(r.target)||!!e.isBidirectional&&t(r.target)&&n(r.source)}case C.isInOut(e):{let t=V(e.inout);return e=>t(e.source)||t(e.target)}case C.isIncoming(e):{let t=V(e.incoming);return e=>t(e.target)}case C.isOutgoing(e):{let t=V(e.outgoing);return e=>t(e.source)}default:L(e)}}function pr(e,t,n){let r=e.flatMap(nr(C.isCustom)),i=Array.from(n);if(r.length===0||i.length===0)return i;for(let{customRelation:{expr:e,title:n,description:a,notes:o,...s}}of r){let r=a?{description:Re(a)}:{},c=o?{notes:Re(o)}:{},l=ye(s,u),d=fr(e);i.forEach((e,a)=>{let o,s;for(let n of t)if(n.id===e.source&&(o=n),n.id===e.target&&(s=n),o&&s)break;!o||!s||d({source:o,target:s,...te(e,[`kind`,`tags`])})&&(i[a]={...e,...l,...r,...c,label:n??e.label,isCustomized:!0})})}return i}function mr(e){return b([...e],ft,re((e,t,n,r)=>{let i=Nt(r,t),a=R(...i.map(ce(`relations`))),o=I(t.relations,a);if(i.length>0&&(o=R(o,t.directRelations)),jt(r,t.reversed())&&(o=R(o,t.directRelations)),o.size<t.relations.size){let e=r.some(dt(t.source)),n=r.some(dt(t.target));e&&(o=R(o,z(A(t.relations,pt(t.source))))),n&&(o=R(o,z(A(t.relations,Mt(t.target)))))}return o.size>0&&e.push(t.update(o)),e},[]))}var hr=class e{static for(t){return new e(t)}constructor(e){this.memory=e}step1CleanConnections(e){if(e.connections.length<2)return e;let t=mr(e.connections);if(t.length===0)return e;let n=e.stageExclude({});return n.excludeConnections(t,!0),n.commit()}step2ProcessImplicits(e){let t=R(this.memory.elements,e.elements),n=R(e.final,this.memory.explicits),r=new Set(n),a=e=>{for(let t of r)if(e===t||j(e,t))return!0;return!1};return b(F(t,r),P(),Xe,i(e=>{let t=[...e.children()].filter(a).length;if(t>=2){n.add(e);return}t===1&&at(e.siblings(),a)&&n.add(e)})),e.update({final:n})}step3ProcessBoundaries(e){let t=new Set;for(let n of e.connections)n.boundary&&n.boundary!==n.source&&n.boundary!==n.target&&t.add(n.boundary);let n=qt(e,`final`),r=e.stageExclude({}),i=r=>!(t.has(r)||e.explicits.has(r)||n.hasInOut(r)||n.root.has(r)),a=S([...n.root]);a&&!e.explicits.has(a)&&r.exclude(a);for(let t of e.final){let e=S(n.children(t));e&&!n.hasInOut(e)&&i(t)&&r.exclude(t)}return r.isDirty()?r.commit():e}commit(){let e=this.step1CleanConnections(this.memory),t=this.step2ProcessImplicits(e);return this.step3ProcessBoundaries(t)}};const{findConnection:gr,findConnectionsBetween:q,findConnectionsWithin:J}=Dt;function Y(e,t){switch(!0){case E.isElementKindExpr(t):return[...A(e.elements(),e=>t.isEqual===(e.kind===t.elementKind))];case E.isElementTagExpr(t):return[...A(e.elements(),e=>t.isEqual===e.tags.includes(t.elementTag))];case t.selector===`expanded`:{let n=e.element(D.flatten(t.ref));return[n,...n.children()]}case t.selector===`children`:case t.selector===`descendants`:{let n=e.element(D.flatten(t.ref)),r=t.selector===`children`?P(n.children()):P(n.descendants());return r&&r.length>0?r:[n]}case E.isModelRef(t):return[e.element(D.flatten(t.ref))];default:L(t)}}function _r(e,t){if(t.isEmpty()||e.length===0)return e;let n=x(e.map(e=>Ke(e))),r=P(A(t.elements,t=>!e.includes(t)&&n(t)));return[...e,...r]}function vr(e,{memory:t,model:n}){let r=Y(n,e);return E.isModelRef(e)?e.selector===`descendants`?r:_r(r,t):r}const yr={include:({expr:e,model:t,stage:n,where:r})=>{let i=t.element(D.flatten(e.ref));r(i)&&(n.addExplicit(i),n.connectWithExisting(i));let a=[...i.children()].filter(r),o=[];for(let e of a)n.addImplicit(e),n.connectWithExisting(e)&&o.push(e);return n.addConnections(J(o)),n},exclude:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(Y(t,e));return n.exclude(i),n}},br={include:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(Y(t,e));if(i.length!==0)return n.addExplicit(i),n.connectWithExisting(i),n.addConnections(J(i)),n},exclude:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(Y(t,e));return n.exclude(i),n}},xr={include:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(Y(t,e));if(i.length!==0)return n.addExplicit(i),n.connectWithExisting(i),n.addConnections(J(i)),n},exclude:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(Y(t,e));return n.exclude(i),n}},X=()=>!0,Sr=e=>e;function Cr(e){return e.reduce((e,t)=>{let n=[...t.relations];N(m(n,1),`Edge must have at least one relation`);let r=t.source.$model.$styles.defaults,i=t.source.id,a=t.target.id,{title:o,color:s=r.relationship.color,line:c=r.relationship.line,head:l=r.relationship.arrow,...u}=dn(n.map(e=>e.$relationship),S(y(n,e=>e.source.id===i&&e.target.id===a))?.$relationship),d=T({id:t.id,parent:t.boundary?.id??null,source:i,target:a,label:o??null,relations:n.map(e=>e.id),color:s,line:c,head:l,...u});return e.push(d),e},[])}function wr(e,t){return ln(e.$styles,[...t.final].map(cn),t.groups)}const Z=E.isWildcard,Tr=(e,t)=>e.isAncestorOf(t)||e.isDescendantOf(t),Er={include:({expr:{source:e,target:t,isBidirectional:n=!1},memory:r,model:i,stage:a,where:o,filterWhere:s})=>{let l=Z(e),u=Z(t),d=[];switch(!0){case l&&u&&r.isEmpty()&&o!==X:{let e=b(i.relationships(),A(o),P(),_(e=>new St(e.source,e.target,new Set([e]))));return a.addConnections(e),a}case l&&u&&!r.isEmpty()&&o!==X:d.push(...J(r.elements));break;case l&&u:d.push(...J(i.roots()));break;case!l&&u&&o!==X:{let t=b(Y(i,e),c(e=>b(e,le(he(n===!0),{onTrue:e=>R(e.allIncoming,e.allOutgoing),onFalse:e=>e.allOutgoing}),A(o),$e(),P(),_e(t=>t.source===e),([t,n])=>ue(b(t,y(t=>!Tr(e,t.target)),_(t=>new St(e,t.target,new Set([t])))),b(n,y(t=>!Tr(e,t.source)),_(t=>new St(t.source,e,new Set([t]))))))));return a.addConnections(t),a}case!l&&u:{let[t,a]=Dr(e,{memory:r,model:i}),o=n?`both`:`directed`;for(let e of t)d.push(...q(e,a,o));break}case l&&!u&&o!==X:{let e=b(Y(i,t),c(e=>b(e,le(he(n===!0),{onTrue:e=>R(e.allIncoming,e.allOutgoing),onFalse:e=>e.allIncoming}),A(o),P(),_e(t=>t.target===e),([t,n])=>ue(b(n,y(t=>!Tr(e,t.target)),_(t=>new St(e,t.target,new Set([t])))),b(t,y(t=>!Tr(e,t.source)),_(t=>new St(t.source,e,new Set([t]))))))));return a.addConnections(e),a}case l&&!u:{let[e,a]=Dr(t,{memory:r,model:i}),o=n?`both`:`directed`;for(let t of a)d.push(...q(t,e,o));break}default:{N(!Z(e),`Inference failed - source must be not a wildcard`),N(!Z(t),`Inference failed - target must be not a wildcard`);let a=vr(e,{memory:r,model:i}),o=vr(t,{memory:r,model:i}),s=n?`both`:`directed`;for(let e of a)d.push(...q(e,o,s))}}return a.addConnections(s(d)),a},exclude:({expr:{source:e,target:t,isBidirectional:n},model:r,memory:i,stage:a,where:o})=>{let s=Z(e),l=Z(t),u;switch(!0){case s&&l:u=b(i.connections,c(ae(ce(`relations`),A(o),P())),z());break;case!s&&l:u=b(Y(r,e),c(e=>b(e,le(he(n===!0),{onTrue:e=>R(e.allIncoming,e.allOutgoing),onFalse:e=>e.allOutgoing}),A(o),P())),z());break;case s&&!l:u=b(Y(r,t),c(e=>b(e,le(he(n===!0),{onTrue:e=>R(e.allIncoming,e.allOutgoing),onFalse:e=>e.allIncoming}),A(o),P())),z());break;default:{N(!Z(e),`Inference failed - source must be not a wildcard`),N(!Z(t),`Inference failed - target must be not a wildcard`);let i=Y(r,e),a=Y(r,t),s=new Set;for(let e of i)for(let t of a)Je(e,t)||(s=R(s,I(e.allOutgoing,t.allIncoming),n?I(t.allOutgoing,e.allIncoming):new Set));u=z(A(s,o))}}return a.excludeRelations(u),a}};function Dr(e,{memory:t,model:n}){let r=Y(n,e);if(!m(r,1))return[[],[]];if(E.isModelRef(e)){let i=P(n.element(D.flatten(e.ref)).ascendingSiblings());return[_r(r,t),_r(i,t)]}return[r,b(r,_(e=>e.ascendingSiblings()),rt(),$e(),P(),e=>_r(e,t))]}const Or={include:({expr:e,scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=e.incoming,s=[];if(E.isWildcard(o)){if(!t)return;for(let e of t.ascendingSiblings())s.push(...gr(e,t,`directed`))}else{let e=vr(o,{memory:r,model:n}),t=[...r.elements];t.length===0&&t.push(...oe(e.flatMap(e=>[...e.ascendingSiblings()])));let i=kr(n,o);for(let n of t)s.push(...q(n,e,`directed`).filter(i))}return i.addConnections(a(s)),i},exclude:({expr:{incoming:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(E.isWildcard(e)){if(!n)return;a.push(...n.allIncoming)}else{let n=Y(t,e);a.push(...n.flatMap(e=>[...e.allIncoming]))}return r.excludeRelations(new Set(a.filter(i))),r}};function kr(e,t){switch(!0){case E.isElementKindExpr(t):case E.isElementTagExpr(t):{let e=V(t);return t=>e(t.target)}case E.isModelRef(t)&&t.selector===`children`:{let n=D.flatten(t.ref);return x([...e.children(n)].map(e=>B.isIncoming(e.id)))}case E.isModelRef(t)&&t.selector===`descendants`:{let n=D.flatten(t.ref);return x([B.isInside(n),...[...e.children(n)].map(e=>B.isIncoming(e.id))])}case E.isModelRef(t)&&t.selector===`expanded`:{let e=D.flatten(t.ref);return x([B.isIncoming(e),B.isInside(e)])}case E.isModelRef(t):{let e=D.flatten(t.ref);return B.isIncoming(e)}default:L(t)}}const Ar={include:({expr:{inout:e},scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=[];if(E.isWildcard(e)){if(!t)return;o.push(...q(t,t.ascendingSiblings()))}else{let t=vr(e,{memory:r,model:n}),i=[...r.elements];i.length===0&&(i=oe(t.flatMap(e=>P(e.ascendingSiblings()))));for(let e of t)o.push(...q(e,i))}return i.addConnections(a(o)),i},exclude:({expr:{inout:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(E.isWildcard(e)){if(!n)return;a.push(...n.allOutgoing),a.push(...n.allIncoming)}else{let n=Y(t,e);a.push(...n.flatMap(e=>[...e.allOutgoing,...e.allIncoming]))}return r.excludeRelations(z(a.filter(i))),r}},jr={include:({expr:e,scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=e.outgoing,s=[];if(E.isWildcard(o)){if(!t)return;s.push(...q(t,t.ascendingSiblings(),`directed`))}else{let e=vr(o,{memory:r,model:n}),t=[...r.elements];t.length===0&&t.push(...oe(e.flatMap(e=>[...e.ascendingSiblings()])));let i=Mr(n,o);for(let n of e)s.push(...q(n,t,`directed`).filter(i))}return i.addConnections(a(s)),i},exclude:({expr:{outgoing:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(E.isWildcard(e)){if(!n)return;a.push(...n.allOutgoing)}else{let n=Y(t,e);a.push(...n.flatMap(e=>[...e.allOutgoing]))}return r.excludeRelations(z(a.filter(i))),r}};function Mr(e,t){switch(!0){case E.isElementKindExpr(t):case E.isElementTagExpr(t):{let e=V(t);return t=>e(t.source)}case E.isModelRef(t)&&t.selector===`children`:{let n=D.flatten(t.ref);return x([...e.children(n)].map(e=>B.isOutgoing(e.id)))}case E.isModelRef(t)&&t.selector===`descendants`:{let n=D.flatten(t.ref);return x([B.isInside(n),...[...e.children(n)].map(e=>B.isOutgoing(e.id))])}case E.isModelRef(t)&&t.selector===`expanded`:{let e=D.flatten(t.ref);return x([B.isOutgoing(e),B.isInside(e)])}case E.isModelRef(t):{let e=D.flatten(t.ref);return B.isOutgoing(e)}default:L(t)}}const Nr={include:({scope:e,model:t,stage:n,memory:r,where:i})=>{if(!e){let e=i===X?[...t.roots()]:P(A(t.elements(),i));if(e.length===0)return;let[r,a]=_e(e,e=>!e.imported);return n.addExplicit(r),n.addImplicit(a),n.addConnections(J(e)),n.connectWithExisting(e),n}let a=P(A(e.children(),i)),o=a.length>0;if(!o){let t=q(e,e.siblings()),r=e.parent;t.length===0&&r&&n.addExplicit(r),a.push(e)}n.addExplicit(e);let s=z([...r.elements,...e.descendingSiblings()]);for(let e of s)n.addConnections(q(e,a,`directed`));o&&(n.addConnections(J(a)),n.addExplicit(a));for(let e of a)n.addConnections(q(e,s,`directed`));return n},exclude:({scope:e,memory:t,stage:n,where:r})=>r===X?e?(n.exclude([e,...e.descendants()]),n):an.empty(t.scope).stageExclude(n.expression):(n.exclude(y([...t.elements],r)),n)};function Pr(e,t,n){switch(!0){case E.isCustom(e):return t===`include`?Pr(e.custom.expr,t,n):n.stage;case E.isWhere(e):{let r=w(e.where.condition),i=e=>y(e,r);return Pr(e.where.expr,t,{...n,where:r,filterWhere:i})}case E.isModelRef(e)&&e.selector===`expanded`:return yr[t]({...n,expr:e})??n.stage;case E.isWildcard(e):return Nr[t]({...n,expr:e})??n.stage;case E.isElementKindExpr(e):case E.isElementTagExpr(e):return br[t]({...n,expr:e})??n.stage;case E.isModelRef(e):return xr[t]({...n,expr:e})??n.stage;default:L(e)}}function Fr(e,t,n){switch(!0){case C.isCustom(e):return t===`include`?Fr(e.customRelation.expr,t,n):n.stage;case C.isWhere(e):{let r=w(e.where.condition),i=e=>new Set(y([...e],r)),a=e=>b(e,_(e=>new St(e.source,e.target,i(e.relations))),y(e=>e.nonEmpty()));return Fr(e.where.expr,t,{...n,where:r,filterWhere:a})}case C.isInOut(e):return Ar[t]({...n,expr:e})??n.stage;case C.isDirect(e):return Er[t]({...n,expr:e})??n.stage;case C.isOutgoing(e):return jr[t]({...n,expr:e})??n.stage;case C.isIncoming(e):return Or[t]({...n,expr:e})??n.stage;default:L(e)}}function Ir(e,t,n){let r={model:e,scope:t.scope,where:X,filterWhere:Sr};for(let i of n){if(Ne(i)){t=Ir(e,on.enter(t,i),i.groupRules),N(t instanceof on,`processPredicates must return ActiveGroupMemory`),t=t.leave();continue}if(He(i)){let e=`include`in i?`include`:`exclude`,n=i.include??i.exclude;for(let i of n){let n=e===`include`?t.stageInclude(i):t.stageExclude(i);switch(!0){case Se.isFqnExpr(i):n=Pr(i,e,{...r,stage:n,memory:t})??n;break;case Se.isRelationExpr(i):n=Fr(i,e,{...r,stage:n,memory:t})??n;break;default:L(i)}t=n.commit()}}}return t}function Lr(e,t,n){return t=Ir(e,t,n),hr.for(t).commit()}function Rr(e,{docUri:t,rules:n,...r}){let i=ir(n,e.globals),a=r.viewOf?e.asComputed.element(r.viewOf):null,o=Lr(e,an.empty(a),i);o.isEmpty()&&a&&(o=o.update({final:new Set([a])})),o=Br(o);let c=wr(e,o),l=Cr(o.connections);Lt(c,l);let u=Ht({nodes:c,edges:l}),d=rr(i,Xt(i,u.nodes)),f=s(i,je),p=Pt(d),m=zr(i,d);return Ut({...r,_stage:`computed`,autoLayout:{direction:f?.direction??`TB`,...f?.nodeSep&&{nodeSep:f.nodeSep},...f?.rankSep&&{rankSep:f.rankSep}},edges:pr(i,d,u.edges),nodes:_(d,e=>(e.icon===`none`&&delete e.icon,e)),...p.length>0&&{notation:{nodes:p}},...m.length>0&&{ranks:m}})}function zr(e,t){let n=[];for(let r of e){if(!Ie(r)||r.targets.length===0)continue;let e=b(t,y(x(r.targets.map(V))),_(e=>e.id));m(e,1)&&n.push({type:r.rank,nodes:e})}return n}function Br(e){if(e.groups.length===0)return e;let t=new lt.default(()=>new Set),n=new Map,r=e=>{for(let r of e.ancestors()){let i=n.get(r);if(i)return n.set(e,i),t.get(i).add(e),!0}return!1},a=e=>{for(let r of e.descendants(`asc`)){let i=n.get(r);if(i)return n.set(e,i),t.get(i).add(e),!0}return!1};if(b(Ye([...e.explicitFirstSeenIn.keys()]),i(i=>{if(!r(i)){let r=k(e.explicitFirstSeenIn.get(i));n.set(i,r),t.get(r).add(i)}})),b(Ye([...e.lastSeenIn.keys()]),y(e=>!n.has(e)),i(i=>{if(r(i)||a(i))return;let o=k(e.lastSeenIn.get(i));n.set(i,o),t.get(o).add(i)})),t.size===0)return e;let o=e.groups.map(e=>{let n=t.get(e.id);return n?e.update(n):e});return e.update({groups:o})}function Vr(e,t){switch(!0){case Oe(e):return Rr(t,e);case Fe(e):return tr(t,e);case ke(e):return dr(t,e);default:L(e)}}function Hr(e,t){try{return{isSuccess:!0,view:Vr(e,t)}}catch(e){return{isSuccess:!1,error:e instanceof Error?e:Error(`Unknown error: ${e}`),view:void 0}}}function Ur(e){let t=mt.create(e),{views:r,_stage:i,...a}=e,o=n(r,e=>Vr(e,t));return{[Ce]:`computed`,...a,views:o}}function Wr(e){return mt.create(Ur(e))}const Q=e=>e;function $(e){if(!se(e))return e;if(e===`*`)return Q({wildcard:!0});if(e.startsWith(`->`))return e.endsWith(`->`)?Q({inout:$(e.replace(/->/g,``).trim())}):Q({incoming:$(e.replace(`-> `,``))});if(e.endsWith(` ->`))return Q({outgoing:$(e.replace(` ->`,``))});if(e.includes(` <-> `)){let[t,n]=e.split(` <-> `);return Q({source:$(t),target:$(n),isBidirectional:!0})}if(e.includes(` -> `)){let[t,n]=e.split(` -> `);return Q({source:$(t),target:$(n)})}return e.endsWith(`._`)?Q({ref:{model:e.replace(`._`,``)},selector:`expanded`}):e.endsWith(`.**`)?Q({ref:{model:e.replace(`.**`,``)},selector:`descendants`}):e.endsWith(`.*`)?Q({ref:{model:e.replace(`.*`,``)},selector:`children`}):Q({ref:{model:e}})}export{Vr as a,Lt as c,Hr as i,Wr as n,Rr as o,Ur as r,Ht as s,$ as t};
1
+ import{B as e,C as t,E as n,G as r,H as i,I as a,J as o,K as s,L as c,M as l,N as u,O as d,P as f,Q as p,R as m,S as h,T as g,V as _,Y as v,Z as ee,_ as te,a as ne,d as y,et as b,g as x,h as re,i as ie,k as ae,m as oe,n as se,nt as ce,o as le,q as ue,r as de,rt as S,t as fe,tt as pe,u as me,v as he,w as ge,x as _e,y as C,z as ve}from"./libs/remeda.mjs";import{Bt as ye,Cn as w,Dn as be,Et as T,G as E,Gt as xe,Ht as Se,J as Ce,Jt as D,Lt as we,Mt as Te,O,On as k,Ot as Ee,Qt as De,Rt as A,Sn as j,Tt as Oe,U as ke,W as M,Y as N,Yt as P,_t as Ae,b as je,cn as Me,d as Ne,dn as Pe,dt as Fe,et as Ie,fn as Le,g as Re,h as ze,ht as Be,jt as F,kt as I,l as Ve,ln as He,lt as Ue,mn as We,n as Ge,nn as Ke,o as qe,p as Je,q as L,r as Ye,rn as Xe,s as Ze,sn as R,tn as Qe,tt as $e,u as et,vn as tt,vt as nt,xn as z,y as rt,zt as B}from"./types.mjs";import{c as it,t as at}from"./libs/mnemonist.mjs";import{A as ot,C as st,D as ct,E as lt,M as V,N as ut,O as dt,T as ft,_ as pt,c as mt,d as ht,f as gt,g as _t,h as vt,j as yt,m as bt,n as xt,o as St,p as Ct,q as wt,r as Tt,t as Et,v as Dt,w as Ot,y as kt}from"./model.mjs";import{r as At}from"./manual-layout.mjs";import{t as jt}from"./libs/graphology.mjs";import{n as Mt,t as Nt}from"../utils/graphology/index.mjs";function Pt(e,t){let n=[],r=e.parent;for(;r;){let e=j(t.get(r),`Parent node ${r} not found`);n.push(e),r=e.parent}return n}function Ft(e,t){for(let r of t){let t=e.get(r.source),i=e.get(r.target);z(t,`Source node ${r.source} not found`),z(i,`Target node ${r.target} not found`),t.outEdges.push(r.id),i.inEdges.push(r.id);let a=Pt(t,e),o=Pt(i,e),s=a.length>0&&o.length>0?n(tt(me(a),me(o))):null;r.parent=s?s.id:null;for(let e of a){if(e===s)break;e.outEdges.push(r.id)}for(let e of o){if(e===s)break;e.inEdges.push(r.id)}}}function It(e){let t=[],n=[...e],r;for(;r=n.shift();){let e=r.parent;if(e){let r=[];for(;e;){let t=n.findIndex(t=>t.id===e);if(t<0)break;let[i]=n.splice(t,1);if(!i)throw Error(`Invalid state, should not happen`);r.unshift(i),e=i.parent}t.push(...r)}t.push(r)}return t}function Lt(e){return e.forEach(t=>{t.children.length>0&&(t.children=e.reduce((e,n)=>(n.parent===t.id&&e.push(n.id),e),[]))}),e}function Rt(e){let t=It([...e.nodes.values()]),n=[...e.edges];if(t.length<2||n.length===0)return{nodes:t,edges:n};let i=t=>j(e.nodes.get(t)),a=new jt({multi:!0,allowSelfLoops:!0,type:`directed`}),[o,s]=he(b(n,g(e=>{let t=i(e.source),n=i(e.target),r=e.parent?i(e.parent):null;return{id:e.id,edge:e,parent:r,source:t,target:n}})),({source:e,target:t})=>e.children.length===0&&t.children.length===0),c=[],l=e=>{a.mergeNode(e.source),a.mergeNode(e.target),c.push(e),(0,Mt.default)(a,e.source,e.target)||a.mergeDirectedEdge(e.source,e.target)};for(let{edge:t,source:n,target:s}of o)if(l(t),s.parent&&s.parent!==t.parent&&b(Pt(s,e.nodes),ne(e=>e.inEdges.includes(t.id)),r(e=>{a.mergeNode(e.id),(0,Mt.default)(a,t.source,e.id)||a.mergeDirectedEdge(t.source,e.id),(0,Mt.default)(a,e.id,t.target)||a.mergeDirectedEdge(e.id,t.target)})),n.parent){let e=i(n.parent);a.mergeNode(e.id),(0,Mt.default)(a,e.id,n.id)||a.mergeDirectedEdge(e.id,n.id),s.parent&&s.parent!==n.parent&&((0,Mt.default)(a,e.id,s.parent)||a.mergeDirectedEdge(e.id,s.parent))}for(let{edge:e}of s)l(e);z(c.length===n.length,`Not all edges were added to the graph`);let u=(0,Nt.topologicalSort)(a),d=[],f=t.slice();for(let e of u){let t=f.findIndex(t=>t.id===e);z(t>=0,`Node "${e}" not found`),d.push(...f.splice(t,1))}return f.length>0&&d.length>0&&(d=d.flatMap(e=>{if(f.length===0)return e;let n=t.slice(0,t.indexOf(e)).filter(e=>f.includes(e));return n.length>0?(f=f.filter(e=>!n.includes(e)),[...n,e]):e})),d.push(...f),{nodes:Lt(It(d)),edges:c}}function zt(e){return e.hash=Oe({id:e.id,__:e._type??`element`,autoLayout:e.autoLayout,nodes:b(e.nodes,g(e=>({id:e.id,icon:d(e.icon)&&e.icon!==`none`?`Y`:`N`,title:e.title,description:Ue(e.description),technology:e.technology??null,shape:e.shape,size:e.style.size??null,iconSize:e.style.iconSize??null,iconPosition:e.style.iconPosition??null,textSize:e.style.textSize??null,padding:e.style.padding??null,children:e.children})),ge(({id:e,...t})=>[e,t])),edges:b(e.edges,g(e=>({source:e.source,target:e.target,label:e.label,description:Ue(e.description),technology:e.technology??null,dir:e.dir,head:e.head,tail:e.tail,line:e.line})),ge(({source:e,target:t,...n})=>[`${e}:${t}`,n]))}),e}var Bt=class{get Ctx(){throw Error(`Should not be called in runtime`)}constructor(e){this.state=e}get elements(){return this.state.elements}get explicits(){return this.state.explicits}get final(){return this.state.final}get connections(){return this.state.connections}isEmpty(){return this.elements.size===0&&this.connections.length===0&&this.explicits.size===0&&this.final.size===0}},Vt=class{excluded={elements:new Set,connections:[]};constructor(e,t){this.memory=e,this.expression=t}markedToMoveExplicitToImplicit=!1;_removeElement(e){this.excluded.elements.add(e)}exclude(e){if(!e)return this;if(P(e)){for(let t of e)this._removeElement(t);return this}return this._removeElement(e),this}_removeConnection(e){this.excluded.connections.push(e)}excludeConnections(e,t){if(ve(t)&&(z(!this.markedToMoveExplicitToImplicit,`Already marked to move explicits`),this.markedToMoveExplicitToImplicit=t),P(e)){for(let t of e)this._removeConnection(t);return this}return this._removeConnection(e),this}isDirty(){return this.excluded.elements.size>0||this.excluded.connections.length>0}isEmpty(){return!this.isDirty()}filterForMoveToImplicits(e){return this.markedToMoveExplicitToImplicit||this.excluded.elements.size>0?e:new Set}moveDisconnectedExplicitsToImplicits(e){let t=T(new Set(this.memory.connections.flatMap(e=>[e.source,e.target])),new Set(e.connections.flatMap(e=>[e.source,e.target])));return t=I(t,e.elements),t=b(t,D(t=>e.explicits.has(t)&&!ye(e.final,Me(t))),B()),t.size>0&&(t=this.filterForMoveToImplicits(t),e.explicits=T(e.explicits,t),e.final=T(e.final,t)),e}removeElements(e){return e.elements=T(e.elements,this.excluded.elements),e.explicits=T(e.explicits,this.excluded.elements),e.final=T(e.final,this.excluded.elements),e}removeConnections(e){let t=this.excluded.connections.reduce((e,t)=>{let n=e.get(t.id);return n?e.set(t.id,n.mergeWith(t)):e.set(t.id,t),e},new Map),n=new Set;e.connections=e.connections.reduce((e,r)=>{let i=t.get(r.id);if(i){n.add(r.source),n.add(r.target);let t=r.difference(i);t.nonEmpty()&&e.push(t)}else e.push(r);return e},[]);for(let t of e.connections)n.delete(t.source),n.delete(t.target),t.boundary&&e.elements.has(t.boundary)&&n.delete(t.boundary);return n.size===0?e:(n=T(n,e.explicits),e.final=T(e.final,n),e)}precommit(e){return e}postcommit(e){return z(T(e.explicits,e.elements).size===0,`Explicits must be subset of elements`),z(T(e.final,e.elements).size===0,`Final elements must be subset of elements`),e}commit(){let e=this.precommit(this.memory.mutableState());if(this.excluded.elements.size>0){let t=e.connections.filter(e=>this.excluded.elements.has(e.source)||this.excluded.elements.has(e.target)).flatMap(t=>[t,...pt(e.connections,t).map(e=>e.intersect(t))]).filter(e=>e.nonEmpty());this.excludeConnections(t)}return this.excluded.connections.length>0&&(e=this.removeConnections(e)),this.excluded.elements.size>0&&(e=this.removeElements(e)),this.memory.update(this.postcommit(e))}},Ht=class{explicits=new Set;implicits=new Set;_ordered=new Set;_connections=[];constructor(e,t){this.memory=e,this.expression=t}get elements(){return this.explicits}get connections(){return this._connections}mergedConnections(){return ct([...this.memory.connections,...this._connections])}connectWithExisting(e,t){throw Error(`Method not implements, depends on the model`)}_addExplicit(e){this._ordered.add(e),this.explicits.add(e),this.implicits.delete(e)}addExplicit(e){if(!e)return this;if(P(e)){for(let t of e)this._addExplicit(t);return this}return this._addExplicit(e),this}_addImplicit(e){this.explicits.has(e)||(this._ordered.add(e),this.implicits.add(e))}addImplicit(e){if(!e)return this;if(P(e)){for(let t of e)this._addImplicit(t);return this}return this._addImplicit(e),this}_addConnection(e){this._connections.push(e),this._addImplicit(e.source),this._addImplicit(e.target)}addConnections(e){if(P(e)){for(let t of e)this._addConnection(t);return this}return this._addConnection(e),this}isDirty(){return this.explicits.size>0||this.implicits.size>0||this._connections.length>0}isEmpty(){return!this.isDirty()}precommit(e){return e}postcommit(e){return e}processConnections(e){return e}commit(){let e=this.precommit(this.memory.mutableState()),t=new Set;if(this._connections.length>0){let[n,r]=he(this._connections,t=>e.final.has(t.source));e.connections=this.processConnections(ct([...e.connections,...n,...r])),t=new Set(e.connections.flatMap(e=>[e.source,e.target]))}return e.elements=F(e.elements,this._ordered,this.explicits,t,this.implicits),e.explicits=I(e.elements,F(e.explicits,this.explicits)),e.final=I(e.elements,F(e.final,this.explicits,t)),this.memory.update(this.postcommit(e))}};function Ut(e,t=`final`){let n=We(A(t===`final`?e.final:e.elements)),r=new Set(e.connections.flatMap(e=>[e.source,e.target])),i=new Set(n),a=new at.default(()=>null),o=n.reduce((e,t,n,r)=>(e.set(t,r.slice(n+1).filter(e=>R(t,e)).map(e=>(i.delete(e),e)).reduce((e,n)=>(e.some(e=>R(e,n))||(e.push(n),a.set(n,t)),e),[])),e),new at.default(()=>[]));return{root:i,connected:r,hasInOut:t=>e.connections.some(V.isAnyInOut(t.id)),parent:e=>a.get(e),children:e=>o.get(e)}}var Wt=class extends Vt{};function H(e){if(M.isCustom(e))return H(e.custom.expr);if(M.isWhere(e)){let t=H(e.where.expr),n=O(e.where.condition);return e=>t(e)&&n(e)}if(M.isElementKindExpr(e))return e.isEqual?t=>t.kind===e.elementKind:t=>t.kind!==e.elementKind;if(M.isElementTagExpr(e))return e.isEqual?({tags:t})=>t.includes(e.elementTag):({tags:t})=>!t.includes(e.elementTag);if(M.isWildcard(e))return()=>!0;if(M.isModelRef(e)){let t=N.flatten(e.ref);if(e.selector===`expanded`)return e=>e.id===t||Pe(e.id)===t;if(e.selector===`descendants`||e.selector===`children`){let e=t+`.`;return t=>t.id.startsWith(e)}return e=>e.id===t}w(e)}function Gt(e,t,n){let{shape:i,color:a,icon:o,...s}=e.style,l=!c(s);b(n,v(u(Fe)),v(t),r(t=>{t.shape=i??t.shape,t.color=a??t.color,m(o)&&(t.icon=o),m(e.notation)&&(t.notation=e.notation),l&&(t.style={...t.style,...s})}))}function Kt(e,t){for(let n of e)!je(n)||n.targets.length===0||Gt(n,S(n.targets.map(H)),t);return t}var qt=class e{static kind=Ie;constructor(e,t,n=null,r=new Set){this.id=e,this.viewRule=t,this.parent=n,this.elements=r}isEmpty(){return this.elements.size===0}update(t){return new e(this.id,this.viewRule,this.parent,t)}clone(){return new e(this.id,this.viewRule,this.parent,new Set(this.elements))}},Jt=class extends Vt{excludeRelations(e){return b(this.memory.connections,v(t=>Ee(t.relations,e)),r(t=>{this.excludeConnections(t.update(I(t.relations,e)))})),this}precommit(e){if(this.excluded.elements.size>0){let e=new Set([...this.excluded.elements].flatMap(e=>[...e.incoming(`direct`),...e.outgoing(`direct`)]));this.excludeRelations(e)}return e}postcommit(e){let t=T(this.memory.explicits,e.explicits);for(let n of t)e.explicitFirstSeenIn.delete(n);let n=T(this.memory.elements,e.elements);for(let t of n)e.lastSeenIn.delete(t);return e}},Yt=class extends Jt{constructor(e,t){super(e,t),this.memory=e,this.expression=t}};const{findConnection:Xt,findConnectionsBetween:Zt}=Ct;var Qt=class extends Ht{connectWithExisting(e,t=`both`){let n=this._connections.length,r=()=>this._connections.length>n;if(!P(e)){if(t===`in`||t===`both`)for(let t of this.memory.elements)this.addConnections(Xt(t,e,`directed`));return(t===`out`||t===`both`)&&this.addConnections(Zt(e,this.memory.elements,`directed`)),r()}let i=[...e];if(t===`in`||t===`both`)for(let e of this.memory.elements)this.addConnections(Zt(e,i,`directed`));if(t===`out`||t===`both`)for(let e of i)this.addConnections(Zt(e,this.memory.elements,`directed`));return r()}addImplicitWithinScope(e){e&&(!this.memory.scope||R(this.memory.scope,e))&&this.addImplicit(e)}processConnections(e){return ke.isRelationExpr(this.expression)||b(e,r(({source:e,target:t,boundary:n})=>{b(fe([...A(e.ancestors()).reverse(),e],[...A(t.ancestors()).reverse(),t]),ee(([e,t])=>e===t),le(1),r(([r,i])=>{if(r===e&&i===t){this.addImplicitWithinScope(n);return}r!==e&&this.addImplicitWithinScope(r),i!==t&&this.addImplicitWithinScope(i)}))})),e}postcommit(e){let t=T(e.explicits,this.memory.explicits);for(let n of t)e.explicitFirstSeenIn.set(n,`@root`);return e}},$t=class extends Qt{constructor(e,t){super(e,t),this.memory=e,this.expression=t}postcommit(e){let t=T(e.explicits,this.memory.explicits);for(let n of t)e.explicitFirstSeenIn.set(n,this.memory.activeGroupId);for(let t of[...this.explicits,...this.implicits])e.lastSeenIn.set(t,this.memory.activeGroupId);return e}},en=class e extends Bt{static empty(t){return new e({elements:new Set,explicits:new Set,final:new Set,connections:[],groups:[],explicitFirstSeenIn:new Map,lastSeenIn:new Map},t)}constructor(e,t){super(e),this.state=e,this.scope=t}get groups(){return this.state.groups}get explicitFirstSeenIn(){return this.state.explicitFirstSeenIn}get lastSeenIn(){return this.state.lastSeenIn}stageInclude(e){return new Qt(this,e)}stageExclude(e){return new Jt(this,e)}mutableState(){return{elements:new Set(this.state.elements),explicits:new Set(this.state.explicits),final:new Set(this.state.final),connections:[...this.state.connections],groups:this.state.groups.map(e=>e.clone()),explicitFirstSeenIn:new Map(this.state.explicitFirstSeenIn),lastSeenIn:new Map(this.state.lastSeenIn)}}update(t){return new e({...this.state,...t},this.scope)}},tn=class e extends en{static enter(t,n){let r=`@gr${t.groups.length+1}`;if(t instanceof e){let i=it.default.from([...t.stack].reverse()),a=t.mutableState();return a.groups.push(new qt(r,n,t.activeGroupId)),i.push(r),new e(a,t.scope,i)}let i=t.mutableState();i.groups.push(new qt(r,n,null));let a=it.default.of(r);return new e(i,t.scope,a)}constructor(e,t,n){super(e,t),this.state=e,this.scope=t,this.stack=n}get activeGroupId(){return j(this.stack.peek(),`Stack must not be empty`)}mutableState(){return{...super.mutableState()}}update(t){return new e({...this.state,...t},this.scope,this.stack)}stageInclude(e){return new $t(this,e)}stageExclude(e){return new Yt(this,e)}leave(){let t=this.mutableState();return this.stack.pop(),this.stack.peek()?new e(t,this.scope,this.stack):new en(t,this.scope)}};function nn(e,t){let n;for(;e.parent&&(n=t.get(e.parent));){let t=n.depth??1;if(n.depth=Math.max(t,(e.depth??0)+1),n.depth===t)break;e=n}}function rn(e){let{id:t,title:n,...r}=h(e.$element,[`summary`,`description`,`metadata`,`style`,`tags`]),{color:i,icon:a,shape:o,...s}=e.style;return k({id:t,title:n,modelRef:t,shape:o,color:i,icon:a,style:s,description:be(e.$element),tags:[...e.tags],metadata:e.$element.metadata,...r})}function an({defaults:e},t,n){let r=new Map,i=new Map;n?.forEach(({id:t,parent:n,viewRule:a,elements:o})=>{n&&j(r.get(n),`Parent group node ${n} not found`).children.push(t),r.set(t,{id:t,parent:n,kind:Ie,title:a.title??``,color:a.color??e.group.color??e.color,shape:`rectangle`,children:[],inEdges:[],outEdges:[],level:0,depth:0,tags:[],style:k({border:a.border??e.group.border,opacity:a.opacity??e.group.opacity,size:a.size,multiple:a.multiple,padding:a.padding,textSize:a.textSize})});for(let e of o)i.set(e.id,t)}),Array.from(t).sort(Xe).forEach(({id:e,...t})=>{let n=Pe(e),a=0,o;for(;n&&(o=r.get(n),!o);)n=Pe(n);let s=t.modelRef??e;if(!o&&i.has(s)){let e=j(i.get(s));o=r.get(e),n=e}o&&(o.children.length==0&&(o.depth=1,nn(o,r)),o.children.push(e),a=o.level+1);let c=k({id:e,parent:n,level:a,children:[],inEdges:[],outEdges:[],...t});r.set(e,c)});let a=new Map;return n?.forEach(({id:e})=>{a.set(e,j(r.get(e)))}),t.forEach(({id:e})=>{a.set(e,j(r.get(e)))}),a}function on(e){let{title:t,description:n=null}=e;return{...t&&{title:t,description:n},...te(e,[`color`,`technology`,`head`,`line`,`tail`,`kind`,`navigateTo`])}}function sn(e,t){let n=b(e,y((e,t)=>(d(t.title)&&!e.title.includes(t.title)&&e.title.push(t.title),d(t.description)&&!e.description.some(_(t.description))&&e.description.push(t.description),d(t.technology)&&!e.technology.includes(t.technology)&&e.technology.push(t.technology),d(t.kind)&&!e.kind.includes(t.kind)&&e.kind.push(t.kind),d(t.color)&&!e.color.includes(t.color)&&e.color.push(t.color),d(t.line)&&!e.line.includes(t.line)&&e.line.push(t.line),d(t.head)&&!e.head.includes(t.head)&&e.head.push(t.head),d(t.tail)&&!e.tail.includes(t.tail)&&e.tail.push(t.tail),d(t.navigateTo)&&!e.navigateTo.includes(t.navigateTo)&&e.navigateTo.push(t.navigateTo),t.tags&&e.tags.push(...t.tags),e),{title:[],description:[],technology:[],kind:[],head:[],tail:[],color:[],tags:[],line:[],navigateTo:[]})),r=C(n.title)??(n.title.length>1?`[...]`:void 0),i=ie(n.tags),a=k({title:r,description:C(n.description),technology:C(n.technology),kind:C(n.kind),head:C(n.head),tail:C(n.tail),color:C(n.color),line:C(n.line),navigateTo:C(n.navigateTo),...De(i)&&{tags:i}});if(t){let e=on(t);a=x({...a,...e},d)}return l(a.title)&&d(a.technology)&&(a.title=`[${a.technology}]`,delete a.technology),a}const{findConnection:cn,findConnectionsBetween:U,findConnectionsWithin:ln}=bt;function W(e,t){let n=e.element(t.ref.deployment);if(n.isDeploymentNode()){if(t.selector===`children`)return[...n.children()];if(t.selector===`expanded`)return[n,...n.children()];if(t.selector===`descendants`)return[...n.descendants()]}return[n]}function un(e,t){let n=e.$model.element(t.ref.model);return t.selector===`children`?[...n.children()]:t.selector===`expanded`?[n,...n.children()]:t.selector===`descendants`?[...n.descendants()]:[n]}function dn(e){if(L.isWildcard(e))return()=>!0;if(L.isElementTagExpr(e)||L.isElementKindExpr(e))throw Error(`element kind and tag expressions are not supported in deployment view rules`);if(L.isDeploymentRef(e)){let t=e.ref.deployment;if(e.selector===`expanded`){let e=t+`.`;return n=>n.id===t||n.id.startsWith(e)}if(e.selector===`descendants`){let e=t+`.`;return t=>t.id.startsWith(e)}return e.selector===`children`?e=>Pe(e.id)===t:e=>e.id===t}if(L.isModelRef(e)){let t=e.ref.model;if(e.selector===`expanded`){let e=t+`.`;return n=>{let r=n.modelRef??null;return r?r===t||r.startsWith(e):!0}}if(e.selector===`descendants`){let e=t+`.`;return t=>{let n=t.modelRef??null;return n?n.startsWith(e):!0}}return e.selector===`children`?e=>{let n=e.modelRef??null;return n?Pe(n)===t:!0}:e=>{let n=e.modelRef??null;return n?n===t:!0}}w(e)}function fn(e){return be(e.$instance)??be(e.element.$element)}function pn(e){let t=e.id,n=e.onlyOneInstance();return k({id:t,deploymentRef:t,title:e.title,kind:e.kind,technology:e.technology??void 0,links:p(e.links,1)?[...e.links]:void 0,notation:e.$node.notation??void 0,color:e.color,shape:e.shape,modelRef:n?.element.id,icon:e.style.icon,description:be(e.$node)??void 0,tags:[...e.tags],style:h(e.style,[`icon`,`shape`,`color`])})}function mn(e){let t=e.$instance,n=e.element,{icon:r,color:i,shape:a,...o}=e.style,s=[...n.links,...t.links??[]];return k({id:e.id,kind:`instance`,title:e.title,description:fn(e)??void 0,technology:e.technology??void 0,tags:[...e.tags],links:p(s,1)?s:void 0,icon:r,color:i,shape:a,style:o,deploymentRef:t.id,modelRef:n.id,notation:t.notation})}function hn(e){return e.isInstance()?mn(e):pn(e)}function gn(e){return e.reduce((e,t)=>{let n=[...t.relations.model,...t.relations.deployment];z(p(n,1),`Edge must have at least one relation`);let r=t.source.$model.$styles.defaults,i=t.source.id,a=t.target.id,{title:o,color:s=r.relationship.color,line:c=r.relationship.line,head:l=r.relationship.arrow,...u}=sn(n.map(e=>e.$relationship)),d=k({id:t.id,parent:t.boundary?.id??null,source:i,target:a,label:o??null,relations:n.map(e=>e.id),color:s,line:c,head:l,...u}),f=e.find(e=>e.source===a&&e.target===i);if(f&&d.label===f.label){f.dir=`both`;let n=f.head??d.head??t.source.$model.$styles.defaults.relationship.arrow;return f.head??=n,f.tail??=n,d.color&&(f.color??=d.color),d.line&&(f.line??=d.line),e}return e.push(d),e},[])}function _n(e,t){let n=an(e.$styles,[...t.final].map(hn));for(let t of n.values()){if(!t.deploymentRef||!t.modelRef||t.children.length>0)continue;let n=e.deployment.element(t.deploymentRef),r=n.isDeploymentNode()&&n.onlyOneInstance();if(!r)continue;t.title===n.name&&(t.title=r.title),t.description??=fn(r)??null,t.technology??=r.technology,c(t.tags)&&(t.tags=[...r.tags]),(!t.links||c(t.links))&&p(r.links,1)&&(t.links=[...r.links]);let i=e.$styles.defaults;t.shape===i.shape&&t.shape!==r.shape&&(t.shape=r.shape,t.notation=null),t.color===i.color&&t.color!==r.color&&(t.color=r.color,t.notation=null),!t.icon&&r.icon&&(t.icon=r.icon)}return n}function vn(e,t){for(let n of e)!je(n)||n.targets.length===0||Gt(n,S(n.targets.map(dn)),t);return t}function yn(e){let t=new at.default(()=>[]);for(let n of e)for(let e of n.relations.model)t.get(e).push(n);let n=new at.default(()=>new Set);for(let[e,a]of t)p(a,2)&&b(a,s(e=>[{group:`$source-${e.source.id}`,conn:e},{group:`$target-${e.target.id}`,conn:e}]),i(oe(`group`)),de(),v(p(2)),r(re(g(oe(`conn`)),dt(`desc`),ee((e,t,n)=>t===0||e.boundary===n[t-1].boundary),r(t=>{n.get(t).add(e)}))));return n}function bn(e){e=ct(e);let t=yn(e);for(let n of e){let{source:e,target:r}=n,i=n.relations.model;if(e.isDeploymentNode()!==r.isDeploymentNode()){let r=e.isDeploymentNode()?e:n.target;z(r.isDeploymentNode());let a=I(i,r.internalModelRelationships());for(let e of a)t.get(n).add(e);continue}if(e.isDeploymentNode()&&r.isDeploymentNode()){let i=F(I(n.relations.model,e.internalModelRelationships()),I(n.relations.model,r.internalModelRelationships()));for(let e of i)t.get(n).add(e)}}return b(t.entries(),Se(([e,t])=>e.update({model:t,deployment:null})),A())}function xn(e){return _t(e,bn(e))}function Sn(e){return b(e,ct,y((t,n)=>{let{source:r,target:i,relations:a}=n;if(r.isInstance()&&i.isInstance())return t;let o=wt.empty();if(r.isDeploymentNode()&&i.isDeploymentNode()){let[e]=cn(i,r,`directed`);e&&(o=a.intersect(e.relations))}for(let t of e)ft(t,n)&&(o=o.union(a.intersect(t.relations)));return o.nonEmpty&&t.push(new ot(r,i,o)),t},[]))}function Cn(e){return _t(e,Sn(e))}var wn=class extends Ht{connectWithExisting(e,t=`both`){let n=this._connections.length,r=()=>this._connections.length>n;if(!P(e)){if(t===`in`||t===`both`)for(let t of this.memory.elements)this.addConnections(cn(t,e,`directed`));return(t===`out`||t===`both`)&&this.addConnections(U(e,this.memory.elements,`directed`)),r()}let i=[...e];if(t===`in`||t===`both`)for(let e of this.memory.elements)this.addConnections(U(e,i,`directed`));if(t===`out`||t===`both`)for(let e of i)this.addConnections(U(e,this.memory.elements,`directed`));return r()}processConnections(e){let t=b(e,xn,Cn);return b(t,r(({source:e,target:t,boundary:n})=>{b(fe([...A(e.ancestors()).reverse(),e],[...A(t.ancestors()).reverse(),t]),ee(([e,t])=>e===t),le(1),r(([r,i])=>{if(e===r&&t===i){this.addImplicit(n);return}r!==e&&r.isDeploymentNode()&&!r.onlyOneInstance()&&this.addImplicit(r),i!==t&&i.isDeploymentNode()&&!i.onlyOneInstance()&&this.addImplicit(i)}))})),t}},Tn=class e extends Bt{static empty(){return new e({elements:new Set,explicits:new Set,final:new Set,connections:[]})}stageInclude(e){return new wn(this,e)}stageExclude(e){return new Wt(this,e)}mutableState(){return{elements:new Set(this.state.elements),explicits:new Set(this.state.explicits),final:new Set(this.state.final),connections:[...this.state.connections]}}update(t){return new e({...this.state,...t})}equals(t){return t instanceof e&&_(this.state,t.state)}diff(e){return{added:{elements:A(T(e.elements,this.elements)),explicits:A(T(e.explicits,this.explicits)),final:A(T(e.final,this.final)),connections:A(_t(e.connections,this.connections))},removed:{elements:A(T(this.elements,e.elements)),explicits:A(T(this.explicits,e.explicits)),final:A(T(this.final,e.final)),connections:_t(this.connections,e.connections)}}}toString(){return[`final:`,...[...this.final].map(e=>` `+e.id),`connections:`,...this.connections.map(e=>` `+e.expression)].join(`
2
+ `)}[yt](e,t,n){return this.toString()}};const En={include:({expr:e,model:t,memory:n,stage:r})=>{let i=O(e.where.condition);return j(Rn(`include`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i}))},exclude:({expr:e,model:t,memory:n,stage:r})=>{let i=O(e.where.condition);return j(Rn(`exclude`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i}))}},Dn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(L.isWildcard(e.incoming)){for(let e of a){if(e.allOutgoing.isEmpty)continue;let t=K(U(e,[...Un(e)],`directed`),i);r.addConnections(t)}return r}z(L.isDeploymentRef(e.incoming),`Only deployment refs are supported in include`);let o=W(t,e.incoming);for(let e of a){let t=K(U(e,o,`directed`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(L.isElementTagExpr(e.incoming)||L.isElementKindExpr(e.incoming))throw Error(`element kind and tag expressions are not supported in exclude`);if(L.isModelRef(e.incoming))return G(kn(t,e.incoming),{stage:r,memory:n},i);if(L.isWildcard(e.incoming))return r;let a=On(W(t,e.incoming)),o=b(n.connections,v(a),K(i));return r.excludeConnections(o),r}};function On(e){return S(e.map(e=>{let t=t=>t===e||R(e,t);return e=>!t(e.source)&&t(e.target)}))}function kn(e,t){let n=un(e,t);return new Set(n.flatMap(e=>[...e.allIncoming]))}const An={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(L.isWildcard(e.outgoing)){for(let e of a)if(!e.allIncoming.isEmpty)for(let t of Un(e)){let n=K(cn(t,e,`directed`),i);r.addConnections(n)}return r}z(L.isDeploymentRef(e.outgoing),`Only deployment refs are supported in include`);let o=W(t,e.outgoing);for(let e of o){let t=K(U(e,a,`directed`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(L.isElementTagExpr(e.outgoing)||L.isElementKindExpr(e.outgoing))throw Error(`element kind and tag expressions are not supported in exclude`);if(L.isModelRef(e.outgoing))return G(Mn(t,e.outgoing),{stage:r,memory:n},i);if(L.isWildcard(e.outgoing))return r;let a=jn(W(t,e.outgoing)),o=b(n.connections,v(a),K(i));return r.excludeConnections(o),r}};function jn(e){return S(e.map(e=>{let t=t=>t===e||R(e,t);return e=>t(e.source)&&!t(e.target)}))}function Mn(e,t){let n=un(e,t);return new Set(n.flatMap(e=>[...e.allOutgoing]))}const Nn={include:({expr:{source:e,target:t,isBidirectional:n=!1},model:r,stage:i,where:a})=>{if(L.isElementTagExpr(e)||L.isElementKindExpr(e)||L.isElementTagExpr(t)||L.isElementKindExpr(t))throw Error(`element kind and tag expressions are not supported in include`);z(!L.isModelRef(e),`Invalid source model ref in direct relation`),z(!L.isModelRef(t),`Invalid target model ref in direct relation`);let o=L.isWildcard(e),c=L.isWildcard(t),l=n?`both`:`directed`,u;switch(!0){case o&&c:u=b(ln(r.instances()),K(a),g(e=>(i.addImplicit(e.boundary),e)));break;case!o&&c:{let t=W(r,e),i=jn(t),o=i;if(n){let e=On(t);o=t=>i(t)!==e(t)}u=b(t,s(e=>U(e,Un(e),l)),v(o),K(a));break}case o&&!c:{let e=W(r,t),i=On(e),o=i;if(n){let t=jn(e);o=e=>t(e)!==i(e)}u=b(e,s(e=>[...Un(e)].flatMap(t=>cn(t,e,l))),v(o),K(a));break}default:{z(!o,`Inference failed - source should be a deployment ref`),z(!c,`Inference failed - target should be a deployment ref`);let n=W(r,e),i=W(r,t),d=jn(n),f=On(i);u=b(n,s(e=>U(e,i,l)),v(e=>d(e)&&f(e)),K(a))}}return i.addConnections(u),L.isDeploymentRef(e)&&f(e.selector)&&i.addImplicit(r.element(e.ref.deployment)),L.isDeploymentRef(t)&&f(t.selector)&&i.addImplicit(r.element(t.ref.deployment)),i},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=dn(e.target),o=dn(e.source),s;switch(!0){case L.isWildcard(e.source)&&L.isWildcard(e.target):return r.excludeConnections(K(n.connections,i)),r;case L.isModelRef(e.source)&&L.isModelRef(e.target):return s=Pn({source:e.source,target:e.target,expr:e,model:t}),G(s,{stage:r,memory:n},i);case L.isModelRef(e.source)&&L.isWildcard(e.target):return s=Mn(t,e.source),G(s,{stage:r,memory:n},i);case L.isModelRef(e.source):return s=Mn(t,e.source),G(s,{stage:r,memory:n},i,e=>a(e.target));case L.isModelRef(e.target):return s=kn(t,e.target),G(s,{stage:r,memory:n},i,e=>o(e.source));default:let c=t=>o(t.source)&&a(t.target)||e.isBidirectional===!0&&o(t.target)&&a(t.source),l=b(n.connections,v(c),K(i));return l.length===0||r.excludeConnections(l),r}}};function Pn({source:e,target:t,expr:n,model:r}){let i=un(r,e),a=un(r,t),o=n.isBidirectional?`both`:`directed`,s=[];for(let e of i)s.push(...gt(e,a,o));return new Set(s.flatMap(e=>[...e.relations]))}const Fn={include:({expr:e,model:t,memory:n,stage:r,where:i})=>{let a=[...n.elements];if(L.isWildcard(e.inout)){for(let e of a){let t=Bn(U(e,[...Un(e)],`both`),i);r.addConnections(t)}return r}z(L.isDeploymentRef(e.inout),`Only deployment refs are supported in include`);let o=W(t,e.inout);for(let e of a){let t=Bn(U(e,o,`both`),i);r.addConnections(t)}return r},exclude:({expr:e,model:t,memory:n,stage:r,where:i})=>{if(L.isElementTagExpr(e.inout)||L.isElementKindExpr(e.inout))throw Error(`element kind and tag expressions are not supported in exclude`);if(L.isModelRef(e.inout)){let a=un(t,e.inout);return a.length===0?r:G(F(new Set,...a.flatMap(e=>[e.allIncoming,e.allOutgoing])),{stage:r,memory:n},i)}if(L.isWildcard(e.inout))return r;let a=W(t,e.inout),o=On(a),s=jn(a),c=b(n.connections,v(e=>o(e)!==s(e)),K(i));return r.excludeConnections(c),r}},In={include:({expr:e,model:t,memory:n,stage:r})=>{let i=O(e.where.condition);return Rn(`include`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})},exclude:({expr:e,model:t,memory:n,stage:r})=>{let i=O(e.where.condition);return Rn(`exclude`,{expr:e.where.expr,model:t,stage:r,memory:n,where:i})}},Ln={include:({model:e,stage:t,where:n})=>{let r=[],i;return i=n?b([...e.elements()],q(n)):A(Se(e.roots(),e=>(e.onlyOneInstance()||r.push(...e.children()),e))),t.addExplicit(i),r.length>1?(t.addConnections(ln([...i,...r])),t.connectWithExisting(r)):t.addConnections(ln(i)),t.connectWithExisting(i),t},exclude:({stage:e,memory:t,where:n})=>{let r=b([...t.elements],q(n));return e.exclude(r),e}};function Rn(e,{expr:t,where:n,...r}){switch(!0){case L.isElementTagExpr(t):case L.isElementKindExpr(t):throw Error(`element kind and tag expressions are not supported in deployment view rules`);case Ce.isCustom(t):case L.isCustom(t):case L.isModelRef(t):return;case L.isWhere(t):return En[e]({...r,expr:t,where:n});case Ce.isWhere(t):return In[e]({...r,expr:t,where:n});case L.isDeploymentRef(t):return Wn[e]({...r,expr:t,where:n});case L.isWildcard(t):return Ln[e]({...r,expr:t,where:n});case Ce.isDirect(t):return Nn[e]({...r,expr:t,where:n});case Ce.isInOut(t):return Fn[e]({...r,expr:t,where:n});case Ce.isOutgoing(t):return An[e]({...r,expr:t,where:n});case Ce.isIncoming(t):return Dn[e]({...r,expr:t,where:n});default:w(t)}}function G(e,{stage:t,memory:n},r,i=()=>!0){if(e.size===0)return t;let a=b(n.connections,v(e=>i(e)),v(t=>Ee(t.relations.model,e)),g(t=>t.update({deployment:null,model:I(t.relations.model,e)})),K(r),v(e=>e.nonEmpty()));return a.length===0?t:t.excludeConnections(a)}function zn(e,t){return K(e,t).nonEmpty()}function K(...t){if(t.length===1)return e=>K(e,t[0]);let[n,r]=t;return r===null?n:e(n)?n.map(e=>K(e,r)).filter(e=>e.nonEmpty()):n.update({model:new Set([...n.relations.model.values()].filter(e=>r(Hn(n)(e)))),deployment:new Set([...n.relations.deployment.values()].filter(e=>r(Hn(n)(e))))})}function q(...t){if(t.length===1){let e=t[0];return e==null?e=>e:t=>t.filter(t=>e(Vn(t,t)))}let[n,r]=t;return e(n)?r==null?n:n.filter(e=>r(Vn(e,e))):r?.(Vn(n,n))??!0}function Bn(e,t){return t?b(e,v(e=>zn(e,t))):e}function Vn(e,t){if(St(e)){let n=xt(t)&&Et(t)?t:null;return{kind:e.kind,tags:[...e.tags,...n?.tags??[]],metadata:e.metadata}}if(mt(e))return te(e.element,[`tags`,`kind`,`metadata`]);if(Et(e))return{kind:e.element.kind,tags:[...e.tags,...e.element.tags],metadata:e.metadata};if(Tt(e))return te(e,[`tags`,`kind`,`metadata`]);w(e)}function Hn(e){return t=>({tags:t.tags,kind:t.kind,metadata:t.metadata,source:Vn(t.source,e.source),target:Vn(t.target,e.target)})}function Un(e){let t=new Set;for(let n of e.descendingSiblings())t.add(n);return t}const Wn={include:e=>{let{expr:t,where:n}=e,r=e.model.element(t.ref.deployment);if(Et(r))return q(r,n)&&(e.stage.addExplicit(r),e.stage.connectWithExisting(r)),e.stage;switch(!0){case t.selector===`expanded`:Kn(r,e);break;case t.selector===`children`:Gn(r,e);break;case t.selector===`descendants`:qn(r,e);break;default:q(r,n)&&(e.stage.addExplicit(r),e.stage.connectWithExisting(r))}return e.stage},exclude:({expr:e,stage:t,memory:n,where:r})=>{let i=dn(e),a=b([...n.elements],v(i),q(r));return t.exclude(a),t}};function Gn(e,{stage:t,where:n}){let r=q([...e.children()],n);r.length!==0&&(t.addImplicit(e),t.addConnections(ln(r)),t.connectWithExisting(r),t.addExplicit(r))}function Kn(e,{memory:t,stage:n,where:r}){n.addImplicit(e),n.connectWithExisting(e);let i=q([...e.children()],r),a=!1;for(let e of i)if(U(e,t.elements).length>0){a=!0;break}a&&(n.connectWithExisting(i,`in`),n.addConnections(ln(i)),n.connectWithExisting(i,`out`)),n.addImplicit(i),n.connections.length>0&&n.addExplicit(e)}function qn(e,{stage:t,where:n}){let i=e=>{let r=[];for(let t of e.children())t.isDeploymentNode()&&r.push(...i(t)),q(t,n)&&r.push(t);return t.connectWithExisting(r,`in`),t.addConnections(ln(r)),t.addImplicit(r),r},a=i(e);if(a.length===0)return;t.connectWithExisting(a,`out`);let o=Jn(t);b(a,v(e=>o.has(e)),r(e=>t.addExplicit(e)))}function Jn(e){return b(e.mergedConnections(),xn,Cn,y((e,t)=>(e.add(t.source),e.add(t.target),e),new Set))}var Yn=class e{static for(t){return new e(t)}constructor(e){this.memory=e}step1CleanConnections(e){if(e.connections.length<2)return e;let t=b(e.connections,xn,Cn),n=_t(e.connections,t);if(n.length===0)return e;let r=e.stageExclude({});return r.excludeConnections(n,!0),r.commit()}step2ProcessImplicits(e){let t=F(this.memory.elements,e.elements),n=F(e.final,this.memory.explicits),i=new at.default(()=>new Set);for(let t of e.connections)if(t.boundary)for(let e of t.relations.model)i.get(e).add(t.boundary);for(let[e,r]of i)if(!(r.size<2))for(let e of r)t.delete(e)&&n.add(e);let a=new Set(n),o=e=>{for(let t of a)if(e===t||R(e,t))return!0;return!1};return b(T(t,a),D(e=>e.isDeploymentNode()),A(),Le,r(e=>{let t=[...e.children()].filter(o).length;if(t>=2){n.add(e);return}t===1&&ye(e.siblings(),o)&&n.add(e)})),e.update({final:n})}step3ProcessBoundaries(e){let t=new Set;for(let n of e.connections)n.boundary&&t.add(n.boundary);let n=Ut(e,`final`),r=e.stageExclude({}),i=r=>!(t.has(r)||e.explicits.has(r)||n.hasInOut(r)||n.root.has(r)),a=C([...n.root]);a&&!e.explicits.has(a)&&r.exclude(a);for(let t of e.final){let e=C(n.children(t));e&&!n.hasInOut(e)&&i(t)&&r.exclude(t)}return r.isDirty()?r.commit():e}commit(){let e=this.step1CleanConnections(this.memory),t=this.step2ProcessImplicits(e);return this.step3ProcessBoundaries(t)}};function Xn(e,t){let n=Tn.empty();for(let r of t)if(rt(r)){let t=`include`in r?`include`:`exclude`,i=r.include??r.exclude;for(let r of i){let i=t===`include`?n.stageInclude(r):n.stageExclude(r);i=Rn(t,{expr:r,model:e,stage:i,memory:n,where:null})??i,n=i.commit()}}return Yn.for(n).commit()}function Zn(e,{docUri:t,rules:n,...r}){let i=Xn(e.deployment,n),a=_n(e,i),s=gn(i.connections);Ft(a,s);let c=Rt({nodes:a,edges:s}),l=vn(n,c.nodes),u=o(n,Ve),d=At(l);return zt({...r,[Ae]:`computed`,[nt]:`deployment`,autoLayout:{direction:u?.direction??`TB`,...u?.nodeSep&&{nodeSep:u.nodeSep},...u?.rankSep&&{rankSep:u.rankSep}},edges:c.edges,nodes:g(l,e=>(e.icon===`none`&&delete e.icon,e)),...d.length>0&&{notation:{nodes:d}}})}function Qn(e){return t=>Ge(t)?t.groupRules.flatMap(Qn(e)):rt(t)&&`include`in t?t.include.filter(e):[]}function $n(e,t){let n=e.flatMap(Qn(M.isCustom));if(n.length===0)return t;let r=[...t];for(let{custom:{expr:e,...t}}of n){let{border:n,opacity:i,multiple:o,iconColor:s,iconSize:c,iconPosition:u,padding:d,size:f,textSize:p,...m}=_e(t,l),h=k({border:n,opacity:i,multiple:o,iconColor:s,iconSize:c,iconPosition:u,padding:d,size:f,textSize:p}),g=!a(h),_=!a(m),v=H(e);r.forEach((e,t)=>{Fe(e)||!v(e)||(_&&(e={...e,...m,isCustomized:!0}),g&&(e={...e,isCustomized:!0,style:{...e.style,...h}}),r[t]=e)})}return r}function er(e,t){return e.reduce((e,n)=>{if(et(n)){let r=t.predicates[n.predicateId];return l(r)?e:e.concat(r)}if(Ne(n)){let r=t.styles[n.styleId];return l(r)?e:e.concat(r)}return e.push(n),e},[])}function tr(e,t){return e.reduce((e,n)=>{if(et(n)){let r=t.dynamicPredicates[n.predicateId];return l(r)?e:e.concat(r)}if(Ne(n)){let r=t.styles[n.styleId];return l(r)?e:e.concat(r)}return e.push(n),e},[])}function nr(e,t){let n=new Set;for(let r of t)if(rt(r))for(let t of r.include){let r=H(t);for(let t of e.elements())r(t)&&n.add(t)}return n}const rr=e=>{if(qe(e)){let t=[],n=[];for(let r of e.__parallel)if(Ze(r)){let[e,...i]=r.__series;t.push(e),n.push(...i)}else t.push(r);return[...t,...n]}return Ze(e)?[...e.__series]:e};function ir(e,t){let n=[],r=(...[e,t])=>{if(!n.includes(e)){let r=n.indexOf(t);if(r>0){n.splice(r,0,e);return}else n.push(e)}n.includes(t)||n.push(t)};for(let i of s(t,rr)){let t=e.element(i.source),a=e.element(i.target),o=n.indexOf(t),s=n.indexOf(a);o>=0&&s>=0||(i.isBackward?r(a,t):r(t,a))}return new Set(n)}function ar(e,t,n){let r=ht(e,t,`directed`).flatMap(e=>[...e.relations]).sort(Te);if(!De(r))return{};if(r.length===1){let e=r[0];return k({title:e.title??void 0,kind:e.kind??void 0,tags:e.tags,relations:[e.id],navigateTo:e.$relationship.navigateTo,color:e.$relationship.color,line:e.$relationship.line,technology:e.technology??void 0,description:e.$relationship.description??void 0})}let i=b(r,s(e=>e.tags),ie()),a=p(i,1)?i:void 0,o=g(r,e=>e.id),c=ue(r).$relationship.navigateTo;c===n&&(c=void 0),c||=b(r,s(e=>e.$relationship.navigateTo&&e.$relationship.navigateTo!==n?e.$relationship.navigateTo:[]),ie(),C());let l=b(r,y((e,{title:t,technology:n,$relationship:r})=>(d(t)&&e.title.add(t),d(r.color)&&e.color.add(r.color),d(r.line)&&e.line.add(r.line),d(r.kind)&&e.kind.add(r.kind),d(n)&&e.technology.add(n),d(r.description)&&!e.description.some(_(r.description))&&e.description.push(r.description),e),{kind:new Set,color:new Set,line:new Set,title:new Set,technology:new Set,description:[]}));return k({tags:a??void 0,relations:o,navigateTo:c,kind:C([...l.kind]),title:C([...l.title]),color:C([...l.color]),line:C([...l.line]),technology:C([...l.technology]),description:C(l.description)})}var or=class{steps=[];constructor(e,t){this.model=e,this.view=t}compute(){let{docUri:e,rules:t,steps:n,...r}=this.view,i=tr(t,this.model.globals),a=nr(this.model,i),s=ir(this.model,n),c=b(F(I(a,s),s,a),A(),We),l=c.reduce((e,t,n,r)=>{for(let i=n+1;i<r.length;i++){let n=r[i];if(R(t,n)){e.push(t);break}}return e},[]),u=(e,t,n)=>{if(Ze(e)){for(let r of e.__series)t=u(r,t,n);return t}let r=n?Be(n,t):Be(t),{source:i,target:a,title:o,isBackward:s,navigateTo:f,notation:p,...m}=e,h=this.model.element(i),g=c.indexOf(h);z(g>=0,`Source ${i} not found`);let _=this.model.element(a),v=c.indexOf(_);z(v>=0,`Target ${a} not found`),(l.includes(h)||l.includes(_))&&console.error(`Step ${h.id} -> ${_.id} because it involves a compound`);let{title:ee,relations:te,navigateTo:ne,...y}=ar(h,_,this.view.id),b=d(f)&&f!==this.view.id?f:ne,x=e.kind?this.model.specification.relationships[e.kind]:void 0;return this.steps.push(k({...y,...!e.technology&&!y.technology&&x?.technology&&{technology:x.technology},...!e.color&&!y.color&&x?.color&&{color:x.color},...!e.line&&!y.line&&x?.line&&{line:x.line},...!e.head&&x?.head&&{head:x.head},...!e.tail&&x?.tail&&{tail:x.tail},...m,id:r,source:h,target:_,navigateTo:b,title:o??ee,relations:te??[],isBackward:g>v})),t+1},f=1;for(let e of n){if(qe(e)){let t=1;for(let n of e.__parallel)t=u(n,t,f);f++;continue}f=u(e,f)}let p=an(this.model.$styles,c.map(rn)),m=this.model.$styles.defaults.relationship,h=this.steps.map(({id:e,source:t,target:n,relations:r,title:i,isBackward:a,tags:o,...s})=>{let c=j(p.get(t.id),`Source node ${t.id} not found`),l=j(p.get(n.id),`Target node ${n.id} not found`),u={id:e,parent:Ke(t.id,n.id),source:c.id,target:l.id,label:i??null,relations:r,color:m.color,line:m.line,head:m.arrow,tags:o??[],...s};for(a&&(u.dir=`back`);u.parent&&!p.has(u.parent);)u.parent=Pe(u.parent);c.outEdges.push(u.id),l.inEdges.push(u.id);for(let e of Qe(u.source)){if(e===u.parent)break;p.get(e)?.outEdges.push(u.id)}for(let e of Qe(u.target)){if(e===u.parent)break;p.get(e)?.inEdges.push(u.id)}return u}),_=$n(i,Kt(i,c.map(e=>j(p.get(e.id))))),v=o(i,Ve),ee=At(_);return zt({...r,[nt]:`dynamic`,[Ae]:`computed`,variant:r.variant??`diagram`,autoLayout:{direction:v?.direction??`LR`,...v?.nodeSep&&{nodeSep:v.nodeSep},...v?.rankSep&&{rankSep:v.rankSep}},nodes:g(_,e=>(e.icon===`none`&&delete e.icon,e)),edges:h,...ee.length>0&&{notation:{nodes:ee}}})}};function sr(e,t){return new or(e,t).compute()}function cr(e){switch(!0){case E.isCustom(e):return cr(e.customRelation.expr);case E.isWhere(e):{let t=cr(e.where.expr),n=O(e.where.condition);return e=>t(e)&&n({source:{tags:e.source.tags,kind:e.source.kind,metadata:e.source.metadata},target:{tags:e.target.tags,kind:e.target.kind,metadata:e.target.metadata},...e.tags&&{tags:e.tags},...e.kind&&{kind:e.kind},...e.metadata&&{metadata:e.metadata}})}case E.isDirect(e):{let t=H(e.source),n=H(e.target);return r=>t(r.source)&&n(r.target)||!!e.isBidirectional&&t(r.target)&&n(r.source)}case E.isInOut(e):{let t=H(e.inout);return e=>t(e.source)||t(e.target)}case E.isIncoming(e):{let t=H(e.incoming);return e=>t(e.target)}case E.isOutgoing(e):{let t=H(e.outgoing);return e=>t(e.source)}default:w(e)}}function lr(e,t,n){let r=e.flatMap(Qn(E.isCustom)),i=Array.from(n);if(r.length===0||i.length===0)return i;for(let{customRelation:{expr:e,title:n,description:a,notes:o,...s}}of r){let r=a?{description:$e(a)}:{},c=o?{notes:$e(o)}:{},u=_e(s,l),d=cr(e);i.forEach((e,a)=>{let o,s;for(let n of t)if(n.id===e.source&&(o=n),n.id===e.target&&(s=n),o&&s)break;!o||!s||d({source:o,target:s,...te(e,[`kind`,`tags`])})&&(i[a]={...e,...u,...r,...c,label:n??e.label,isCustomized:!0})})}return i}function ur(e){return b([...e],ct,y((e,t,n,r)=>{let i=kt(r,t),a=F(...i.map(oe(`relations`))),o=I(t.relations,a);if(i.length>0&&(o=F(o,t.directRelations)),Dt(r,t.reversed())&&(o=F(o,t.directRelations)),o.size<t.relations.size){let e=r.some(st(t.source)),n=r.some(st(t.target));e&&(o=F(o,B(D(t.relations,lt(t.source))))),n&&(o=F(o,B(D(t.relations,Ot(t.target)))))}return o.size>0&&e.push(t.update(o)),e},[]))}var dr=class e{static for(t){return new e(t)}constructor(e){this.memory=e}step1CleanConnections(e){if(e.connections.length<2)return e;let t=ur(e.connections);if(t.length===0)return e;let n=e.stageExclude({});return n.excludeConnections(t,!0),n.commit()}step2ProcessImplicits(e){let t=F(this.memory.elements,e.elements),n=F(e.final,this.memory.explicits),i=new Set(n),a=e=>{for(let t of i)if(e===t||R(e,t))return!0;return!1};return b(T(t,i),A(),Le,r(e=>{let t=[...e.children()].filter(a).length;if(t>=2){n.add(e);return}t===1&&ye(e.siblings(),a)&&n.add(e)})),e.update({final:n})}step3ProcessBoundaries(e){let t=new Set;for(let n of e.connections)n.boundary&&n.boundary!==n.source&&n.boundary!==n.target&&t.add(n.boundary);let n=Ut(e,`final`),r=e.stageExclude({}),i=r=>!(t.has(r)||e.explicits.has(r)||n.hasInOut(r)||n.root.has(r)),a=C([...n.root]);a&&!e.explicits.has(a)&&r.exclude(a);for(let t of e.final){let e=C(n.children(t));e&&!n.hasInOut(e)&&i(t)&&r.exclude(t)}return r.isDirty()?r.commit():e}commit(){let e=this.step1CleanConnections(this.memory),t=this.step2ProcessImplicits(e);return this.step3ProcessBoundaries(t)}};const{findConnection:fr,findConnectionsBetween:J,findConnectionsWithin:Y}=Ct;function X(e,t){switch(!0){case M.isElementKindExpr(t):return[...D(e.elements(),e=>t.isEqual===(e.kind===t.elementKind))];case M.isElementTagExpr(t):return[...D(e.elements(),e=>t.isEqual===e.tags.includes(t.elementTag))];case t.selector===`expanded`:{let n=e.element(N.flatten(t.ref));return[n,...n.children()]}case t.selector===`children`:case t.selector===`descendants`:{let n=e.element(N.flatten(t.ref)),r=t.selector===`children`?A(n.children()):A(n.descendants());return r&&r.length>0?r:[n]}case M.isModelRef(t):return[e.element(N.flatten(t.ref))];default:w(t)}}function pr(e,t){if(t.isEmpty()||e.length===0)return e;let n=S(e.map(e=>Me(e))),r=A(D(t.elements,t=>!e.includes(t)&&n(t)));return[...e,...r]}function mr(e,{memory:t,model:n}){let r=X(n,e);return M.isModelRef(e)?e.selector===`descendants`?r:pr(r,t):r}const hr={include:({expr:e,model:t,stage:n,where:r})=>{let i=t.element(N.flatten(e.ref));r(i)&&(n.addExplicit(i),n.connectWithExisting(i));let a=[...i.children()].filter(r),o=[];for(let e of a)n.addImplicit(e),n.connectWithExisting(e)&&o.push(e);return n.addConnections(Y(o)),n},exclude:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(X(t,e));return n.exclude(i),n}},gr={include:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(X(t,e));if(i.length!==0)return n.addExplicit(i),n.connectWithExisting(i),n.addConnections(Y(i)),n},exclude:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(X(t,e));return n.exclude(i),n}},_r={include:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(X(t,e));if(i.length!==0)return n.addExplicit(i),n.connectWithExisting(i),n.addConnections(Y(i)),n},exclude:({expr:e,model:t,stage:n,filterWhere:r})=>{let i=r(X(t,e));return n.exclude(i),n}},vr=()=>!0,yr=e=>e;function br(e){return e.reduce((e,t)=>{let n=[...t.relations];z(p(n,1),`Edge must have at least one relation`);let r=t.source.$model.$styles.defaults,i=t.source.id,a=t.target.id,{title:o,color:s=r.relationship.color,line:c=r.relationship.line,head:l=r.relationship.arrow,...u}=sn(n.map(e=>e.$relationship),C(v(n,e=>e.source.id===i&&e.target.id===a))?.$relationship),d=k({id:t.id,parent:t.boundary?.id??null,source:i,target:a,label:o??null,relations:n.map(e=>e.id),color:s,line:c,head:l,...u});return e.push(d),e},[])}function xr(e,t){return an(e.$styles,[...t.final].map(rn),t.groups)}const Z=M.isWildcard,Sr=(e,t)=>e.isAncestorOf(t)||e.isDescendantOf(t),Cr={include:({expr:{source:e,target:t,isBidirectional:n=!1},memory:r,model:i,stage:a,where:o,filterWhere:c})=>{let l=Z(e),u=Z(t),d=[];switch(!0){case l&&u&&r.isEmpty()&&o!==vr:{let e=b(i.relationships(),D(o),A(),g(e=>new vt(e.source,e.target,new Set([e]))));return a.addConnections(e),a}case l&&u&&!r.isEmpty()&&o!==vr:d.push(...Y(r.elements));break;case l&&u:d.push(...Y(i.roots()));break;case!l&&u&&o!==vr:{let t=b(X(i,e),s(e=>b(e,se(pe(n===!0),{onTrue:e=>F(e.allIncoming,e.allOutgoing),onFalse:e=>e.allOutgoing}),D(o),we(),A(),he(t=>t.source===e),([t,n])=>ce(b(t,v(t=>!Sr(e,t.target)),g(t=>new vt(e,t.target,new Set([t])))),b(n,v(t=>!Sr(e,t.source)),g(t=>new vt(t.source,e,new Set([t]))))))));return a.addConnections(t),a}case!l&&u:{let[t,a]=wr(e,{memory:r,model:i}),o=n?`both`:`directed`;for(let e of t)d.push(...J(e,a,o));break}case l&&!u&&o!==vr:{let e=b(X(i,t),s(e=>b(e,se(pe(n===!0),{onTrue:e=>F(e.allIncoming,e.allOutgoing),onFalse:e=>e.allIncoming}),D(o),A(),he(t=>t.target===e),([t,n])=>ce(b(n,v(t=>!Sr(e,t.target)),g(t=>new vt(e,t.target,new Set([t])))),b(t,v(t=>!Sr(e,t.source)),g(t=>new vt(t.source,e,new Set([t]))))))));return a.addConnections(e),a}case l&&!u:{let[e,a]=wr(t,{memory:r,model:i}),o=n?`both`:`directed`;for(let t of a)d.push(...J(t,e,o));break}default:{z(!Z(e),`Inference failed - source must be not a wildcard`),z(!Z(t),`Inference failed - target must be not a wildcard`);let a=mr(e,{memory:r,model:i}),o=mr(t,{memory:r,model:i}),s=n?`both`:`directed`;for(let e of a)d.push(...J(e,o,s))}}return a.addConnections(c(d)),a},exclude:({expr:{source:e,target:t,isBidirectional:n},model:r,memory:i,stage:a,where:o})=>{let c=Z(e),l=Z(t),u;switch(!0){case c&&l:u=b(i.connections,s(re(oe(`relations`),D(o),A())),B());break;case!c&&l:u=b(X(r,e),s(e=>b(e,se(pe(n===!0),{onTrue:e=>F(e.allIncoming,e.allOutgoing),onFalse:e=>e.allOutgoing}),D(o),A())),B());break;case c&&!l:u=b(X(r,t),s(e=>b(e,se(pe(n===!0),{onTrue:e=>F(e.allIncoming,e.allOutgoing),onFalse:e=>e.allIncoming}),D(o),A())),B());break;default:{z(!Z(e),`Inference failed - source must be not a wildcard`),z(!Z(t),`Inference failed - target must be not a wildcard`);let i=X(r,e),a=X(r,t),s=new Set;for(let e of i)for(let t of a)He(e,t)||(s=F(s,I(e.allOutgoing,t.allIncoming),n?I(t.allOutgoing,e.allIncoming):new Set));u=B(D(s,o))}}return a.excludeRelations(u),a}};function wr(e,{memory:t,model:n}){let r=X(n,e);if(!p(r,1))return[[],[]];if(M.isModelRef(e)){let i=A(n.element(N.flatten(e.ref)).ascendingSiblings());return[pr(r,t),pr(i,t)]}return[r,b(r,g(e=>e.ascendingSiblings()),xe(),we(),A(),e=>pr(e,t))]}const Tr={include:({expr:e,scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=e.incoming,s=[];if(M.isWildcard(o)){if(!t)return;for(let e of t.ascendingSiblings())s.push(...fr(e,t,`directed`))}else{let e=mr(o,{memory:r,model:n}),t=[...r.elements];t.length===0&&t.push(...ie(e.flatMap(e=>[...e.ascendingSiblings()])));let i=Er(n,o);for(let n of t)s.push(...J(n,e,`directed`).filter(i))}return i.addConnections(a(s)),i},exclude:({expr:{incoming:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(M.isWildcard(e)){if(!n)return;a.push(...n.allIncoming)}else{let n=X(t,e);a.push(...n.flatMap(e=>[...e.allIncoming]))}return r.excludeRelations(new Set(a.filter(i))),r}};function Er(e,t){switch(!0){case M.isElementKindExpr(t):case M.isElementTagExpr(t):{let e=H(t);return t=>e(t.target)}case M.isModelRef(t)&&t.selector===`children`:{let n=N.flatten(t.ref);return S([...e.children(n)].map(e=>V.isIncoming(e.id)))}case M.isModelRef(t)&&t.selector===`descendants`:{let n=N.flatten(t.ref);return S([V.isInside(n),...[...e.children(n)].map(e=>V.isIncoming(e.id))])}case M.isModelRef(t)&&t.selector===`expanded`:{let e=N.flatten(t.ref);return S([V.isIncoming(e),V.isInside(e)])}case M.isModelRef(t):{let e=N.flatten(t.ref);return V.isIncoming(e)}default:w(t)}}const Dr={include:({expr:{inout:e},scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=[];if(M.isWildcard(e)){if(!t)return;o.push(...J(t,t.ascendingSiblings()))}else{let t=mr(e,{memory:r,model:n}),i=[...r.elements];i.length===0&&(i=ie(t.flatMap(e=>A(e.ascendingSiblings()))));for(let e of t)o.push(...J(e,i))}return i.addConnections(a(o)),i},exclude:({expr:{inout:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(M.isWildcard(e)){if(!n)return;a.push(...n.allOutgoing),a.push(...n.allIncoming)}else{let n=X(t,e);a.push(...n.flatMap(e=>[...e.allOutgoing,...e.allIncoming]))}return r.excludeRelations(B(a.filter(i))),r}},Or={include:({expr:e,scope:t,model:n,memory:r,stage:i,filterWhere:a})=>{let o=e.outgoing,s=[];if(M.isWildcard(o)){if(!t)return;s.push(...J(t,t.ascendingSiblings(),`directed`))}else{let e=mr(o,{memory:r,model:n}),t=[...r.elements];t.length===0&&t.push(...ie(e.flatMap(e=>[...e.ascendingSiblings()])));let i=kr(n,o);for(let n of e)s.push(...J(n,t,`directed`).filter(i))}return i.addConnections(a(s)),i},exclude:({expr:{outgoing:e},model:t,scope:n,stage:r,where:i})=>{let a=[];if(M.isWildcard(e)){if(!n)return;a.push(...n.allOutgoing)}else{let n=X(t,e);a.push(...n.flatMap(e=>[...e.allOutgoing]))}return r.excludeRelations(B(a.filter(i))),r}};function kr(e,t){switch(!0){case M.isElementKindExpr(t):case M.isElementTagExpr(t):{let e=H(t);return t=>e(t.source)}case M.isModelRef(t)&&t.selector===`children`:{let n=N.flatten(t.ref);return S([...e.children(n)].map(e=>V.isOutgoing(e.id)))}case M.isModelRef(t)&&t.selector===`descendants`:{let n=N.flatten(t.ref);return S([V.isInside(n),...[...e.children(n)].map(e=>V.isOutgoing(e.id))])}case M.isModelRef(t)&&t.selector===`expanded`:{let e=N.flatten(t.ref);return S([V.isOutgoing(e),V.isInside(e)])}case M.isModelRef(t):{let e=N.flatten(t.ref);return V.isOutgoing(e)}default:w(t)}}const Ar={include:({scope:e,model:t,stage:n,memory:r,where:i})=>{if(!e){let e=i===vr?[...t.roots()]:A(D(t.elements(),i));if(e.length===0)return;let[r,a]=he(e,e=>!e.imported);return n.addExplicit(r),n.addImplicit(a),n.addConnections(Y(e)),n.connectWithExisting(e),n}let a=A(D(e.children(),i)),o=a.length>0;if(!o){let t=J(e,e.siblings()),r=e.parent;t.length===0&&r&&n.addExplicit(r),a.push(e)}n.addExplicit(e);let s=B([...r.elements,...e.descendingSiblings()]);for(let e of s)n.addConnections(J(e,a,`directed`));o&&(n.addConnections(Y(a)),n.addExplicit(a));for(let e of a)n.addConnections(J(e,s,`directed`));return n},exclude:({scope:e,memory:t,stage:n,where:r})=>r===vr?e?(n.exclude([e,...e.descendants()]),n):en.empty(t.scope).stageExclude(n.expression):(n.exclude(v([...t.elements],r)),n)};function jr(e,t,n){switch(!0){case M.isCustom(e):return t===`include`?jr(e.custom.expr,t,n):n.stage;case M.isWhere(e):{let r=O(e.where.condition),i=e=>v(e,r);return jr(e.where.expr,t,{...n,where:r,filterWhere:i})}case M.isModelRef(e)&&e.selector===`expanded`:return hr[t]({...n,expr:e})??n.stage;case M.isWildcard(e):return Ar[t]({...n,expr:e})??n.stage;case M.isElementKindExpr(e):case M.isElementTagExpr(e):return gr[t]({...n,expr:e})??n.stage;case M.isModelRef(e):return _r[t]({...n,expr:e})??n.stage;default:w(e)}}function Mr(e,t,n){switch(!0){case E.isCustom(e):return t===`include`?Mr(e.customRelation.expr,t,n):n.stage;case E.isWhere(e):{let r=O(e.where.condition),i=e=>new Set(v([...e],r)),a=e=>b(e,g(e=>new vt(e.source,e.target,i(e.relations))),v(e=>e.nonEmpty()));return Mr(e.where.expr,t,{...n,where:r,filterWhere:a})}case E.isInOut(e):return Dr[t]({...n,expr:e})??n.stage;case E.isDirect(e):return Cr[t]({...n,expr:e})??n.stage;case E.isOutgoing(e):return Or[t]({...n,expr:e})??n.stage;case E.isIncoming(e):return Tr[t]({...n,expr:e})??n.stage;default:w(e)}}function Nr(e,t,n){let r={model:e,scope:t.scope,where:vr,filterWhere:yr};for(let i of n){if(Ge(i)){t=Nr(e,tn.enter(t,i),i.groupRules),z(t instanceof tn,`processPredicates must return ActiveGroupMemory`),t=t.leave();continue}if(rt(i)){let e=`include`in i?`include`:`exclude`,n=i.include??i.exclude;for(let i of n){let n=e===`include`?t.stageInclude(i):t.stageExclude(i);switch(!0){case ke.isFqnExpr(i):n=jr(i,e,{...r,stage:n,memory:t})??n;break;case ke.isRelationExpr(i):n=Mr(i,e,{...r,stage:n,memory:t})??n;break;default:w(i)}t=n.commit()}}}return t}function Pr(e,t,n){return t=Nr(e,t,n),dr.for(t).commit()}function Fr(e,{docUri:t,rules:n,...r}){let i=er(n,e.globals),a=r.viewOf?e.asComputed.element(r.viewOf):null,s=Pr(e,en.empty(a),i);s.isEmpty()&&a&&(s=s.update({final:new Set([a])})),s=Lr(s);let c=xr(e,s),l=br(s.connections);Ft(c,l);let u=Rt({nodes:c,edges:l}),d=$n(i,Kt(i,u.nodes)),f=o(i,Ve),p=At(d),m=Ir(i,d);return zt({...r,_stage:`computed`,autoLayout:{direction:f?.direction??`TB`,...f?.nodeSep&&{nodeSep:f.nodeSep},...f?.rankSep&&{rankSep:f.rankSep}},edges:lr(i,d,u.edges),nodes:g(d,e=>(e.icon===`none`&&delete e.icon,e)),...p.length>0&&{notation:{nodes:p}},...m.length>0&&{ranks:m}})}function Ir(e,t){let n=[];for(let r of e){if(!Ye(r)||r.targets.length===0)continue;let e=b(t,v(S(r.targets.map(H))),g(e=>e.id));p(e,1)&&n.push({type:r.rank,nodes:e})}return n}function Lr(e){if(e.groups.length===0)return e;let t=new at.default(()=>new Set),n=new Map,i=e=>{for(let r of e.ancestors()){let i=n.get(r);if(i)return n.set(e,i),t.get(i).add(e),!0}return!1},a=e=>{for(let r of e.descendants(`asc`)){let i=n.get(r);if(i)return n.set(e,i),t.get(i).add(e),!0}return!1};if(b(We([...e.explicitFirstSeenIn.keys()]),r(r=>{if(!i(r)){let i=j(e.explicitFirstSeenIn.get(r));n.set(r,i),t.get(i).add(r)}})),b(We([...e.lastSeenIn.keys()]),v(e=>!n.has(e)),r(r=>{if(i(r)||a(r))return;let o=j(e.lastSeenIn.get(r));n.set(r,o),t.get(o).add(r)})),t.size===0)return e;let o=e.groups.map(e=>{let n=t.get(e.id);return n?e.update(n):e});return e.update({groups:o})}function Rr(e,t){switch(!0){case Re(e):return Fr(t,e);case Je(e):return Zn(t,e);case ze(e):return sr(t,e);default:w(e)}}function zr(e,t){try{return{isSuccess:!0,view:Rr(e,t)}}catch(e){return{isSuccess:!1,error:e instanceof Error?e:Error(`Unknown error: ${e}`),view:void 0}}}function Br(e){let n=ut.create(e),{views:r,_stage:i,...a}=e,o=t(r,e=>Rr(e,n));return{[Ae]:`computed`,...a,views:o}}function Vr(e){return ut.create(Br(e))}const Q=e=>e;function $(e){if(!ae(e))return e;if(e===`*`)return Q({wildcard:!0});if(e.startsWith(`->`))return e.endsWith(`->`)?Q({inout:$(e.replace(/->/g,``).trim())}):Q({incoming:$(e.replace(`-> `,``))});if(e.endsWith(` ->`))return Q({outgoing:$(e.replace(` ->`,``))});if(e.includes(` <-> `)){let[t,n]=e.split(` <-> `);return Q({source:$(t),target:$(n),isBidirectional:!0})}if(e.includes(` -> `)){let[t,n]=e.split(` -> `);return Q({source:$(t),target:$(n)})}return e.endsWith(`._`)?Q({ref:{model:e.replace(`._`,``)},selector:`expanded`}):e.endsWith(`.**`)?Q({ref:{model:e.replace(`.**`,``)},selector:`descendants`}):e.endsWith(`.*`)?Q({ref:{model:e.replace(`.*`,``)},selector:`children`}):Q({ref:{model:e}})}export{Rr as a,Ft as c,zr as i,Vr as n,Fr as o,Br as r,Rt as s,$ as t};
@@ -2,6 +2,7 @@ import { $r as RelationKind, Ai as RelationId, C as LayoutedView, Ci as GroupEle
2
2
  import { i as BBox } from "./index2.mjs";
3
3
  import { i as LikeC4Styles } from "./index3.mjs";
4
4
  import { o as DefaultMap } from "./libs/mnemonist.mjs";
5
+ import "./mnemonist.mjs";
5
6
  import { IsAny, SetRequired, Tagged } from "type-fest";
6
7
 
7
8
  //#region src/model/RelationModel.d.ts
@@ -1 +1 @@
1
- import{O as e,T as t,X as n,et as r,l as i,m as a,nt as o,p as s}from"./libs/remeda.mjs";import{I as c}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};
1
+ import{O as e,T as t,X as n,et as r,l as i,m as a,nt as o,p as s}from"./libs/remeda.mjs";import{I as c,Sn as l,hn as u}from"./types.mjs";function d(d){let f=[],p=[];for(let[t,r]of n(d))e(r.color)?f.push({tag:t,spec:{color:r.color}}):p.push(t);return r(p,i(u),t((e,t)=>({tag:e,spec:{color:l(c[t%c.length])}})),o(f),i((e,t)=>u(e.tag,t.tag)),s(a(`tag`),a(`spec`)))}export{d as t};
@@ -1,4 +1,5 @@
1
1
  import { aa as NonEmptyArray, ca as ReorderedArray, ea as IterableContainer, ta as IteratorLike, xi as Fqn } from "./index.mjs";
2
+ import "./mnemonist.mjs";
2
3
 
3
4
  //#region src/utils/invariant.d.ts
4
5
  declare function nonNullable<T>(value: T, message?: string | (() => string)): NonNullable<T>;
@@ -21,6 +22,9 @@ declare function sortNatural<T extends IterableContainer<string>>(elements: T):
21
22
  * Compares two strings lexicographically first, then hierarchically based on their depth.\
22
23
  * From parent nodes to leaves
23
24
  *
25
+ * @param separator - The separator to use for splitting the strings
26
+ * @param deepestFirst - If true, deeper paths come first (reverse order)
27
+ *
24
28
  * @example
25
29
  * const lines = [
26
30
  * 'b.c',
@@ -1,4 +1,4 @@
1
- const{min:e,max:t}=Math;var n=(n,r=0,i=1)=>e(t(r,n),i),r=e=>{e._clipped=!1,e._unclipped=e.slice(0);for(let t=0;t<=3;t++)t<3?((e[t]<0||e[t]>255)&&(e._clipped=!0),e[t]=n(e[t],0,255)):t===3&&(e[t]=n(e[t],0,1));return e};const i={};for(let e of[`Boolean`,`Number`,`String`,`Function`,`Array`,`Date`,`RegExp`,`Undefined`,`Null`])i[`[object ${e}]`]=e.toLowerCase();function a(e){return i[Object.prototype.toString.call(e)]||`object`}var o=(e,t=null)=>e.length>=3?Array.prototype.slice.call(e):a(e[0])==`object`&&t?t.split(``).filter(t=>e[0][t]!==void 0).map(t=>e[0][t]):e[0].slice(0),s=e=>{if(e.length<2)return null;let t=e.length-1;return a(e[t])==`string`?e[t].toLowerCase():null};const{PI:c,min:l,max:u}=Math,d=e=>Math.round(e*100)/100,f=e=>Math.round(e*100)/100,p=c*2,m=c/3,h=c/180,g=180/c;function _(e){return[...e.slice(0,3).reverse(),...e.slice(3)]}var v={format:{},autodetect:[]},y=class{constructor(...e){let t=this;if(a(e[0])===`object`&&e[0].constructor&&e[0].constructor===this.constructor)return e[0];let n=s(e),i=!1;if(!n){i=!0,v.sorted||=(v.autodetect=v.autodetect.sort((e,t)=>t.p-e.p),!0);for(let t of v.autodetect)if(n=t.test(...e),n)break}if(v.format[n])t._rgb=r(v.format[n].apply(null,i?e:e.slice(0,-1)));else throw Error(`unknown format: `+e);t._rgb.length===3&&t._rgb.push(1)}toString(){return a(this.hex)==`function`?this.hex():`[${this._rgb.join(`,`)}]`}};const b=(...e)=>new y(...e);b.version=`3.2.0`;const x={aliceblue:`#f0f8ff`,antiquewhite:`#faebd7`,aqua:`#00ffff`,aquamarine:`#7fffd4`,azure:`#f0ffff`,beige:`#f5f5dc`,bisque:`#ffe4c4`,black:`#000000`,blanchedalmond:`#ffebcd`,blue:`#0000ff`,blueviolet:`#8a2be2`,brown:`#a52a2a`,burlywood:`#deb887`,cadetblue:`#5f9ea0`,chartreuse:`#7fff00`,chocolate:`#d2691e`,coral:`#ff7f50`,cornflowerblue:`#6495ed`,cornsilk:`#fff8dc`,crimson:`#dc143c`,cyan:`#00ffff`,darkblue:`#00008b`,darkcyan:`#008b8b`,darkgoldenrod:`#b8860b`,darkgray:`#a9a9a9`,darkgreen:`#006400`,darkgrey:`#a9a9a9`,darkkhaki:`#bdb76b`,darkmagenta:`#8b008b`,darkolivegreen:`#556b2f`,darkorange:`#ff8c00`,darkorchid:`#9932cc`,darkred:`#8b0000`,darksalmon:`#e9967a`,darkseagreen:`#8fbc8f`,darkslateblue:`#483d8b`,darkslategray:`#2f4f4f`,darkslategrey:`#2f4f4f`,darkturquoise:`#00ced1`,darkviolet:`#9400d3`,deeppink:`#ff1493`,deepskyblue:`#00bfff`,dimgray:`#696969`,dimgrey:`#696969`,dodgerblue:`#1e90ff`,firebrick:`#b22222`,floralwhite:`#fffaf0`,forestgreen:`#228b22`,fuchsia:`#ff00ff`,gainsboro:`#dcdcdc`,ghostwhite:`#f8f8ff`,gold:`#ffd700`,goldenrod:`#daa520`,gray:`#808080`,green:`#008000`,greenyellow:`#adff2f`,grey:`#808080`,honeydew:`#f0fff0`,hotpink:`#ff69b4`,indianred:`#cd5c5c`,indigo:`#4b0082`,ivory:`#fffff0`,khaki:`#f0e68c`,laserlemon:`#ffff54`,lavender:`#e6e6fa`,lavenderblush:`#fff0f5`,lawngreen:`#7cfc00`,lemonchiffon:`#fffacd`,lightblue:`#add8e6`,lightcoral:`#f08080`,lightcyan:`#e0ffff`,lightgoldenrod:`#fafad2`,lightgoldenrodyellow:`#fafad2`,lightgray:`#d3d3d3`,lightgreen:`#90ee90`,lightgrey:`#d3d3d3`,lightpink:`#ffb6c1`,lightsalmon:`#ffa07a`,lightseagreen:`#20b2aa`,lightskyblue:`#87cefa`,lightslategray:`#778899`,lightslategrey:`#778899`,lightsteelblue:`#b0c4de`,lightyellow:`#ffffe0`,lime:`#00ff00`,limegreen:`#32cd32`,linen:`#faf0e6`,magenta:`#ff00ff`,maroon:`#800000`,maroon2:`#7f0000`,maroon3:`#b03060`,mediumaquamarine:`#66cdaa`,mediumblue:`#0000cd`,mediumorchid:`#ba55d3`,mediumpurple:`#9370db`,mediumseagreen:`#3cb371`,mediumslateblue:`#7b68ee`,mediumspringgreen:`#00fa9a`,mediumturquoise:`#48d1cc`,mediumvioletred:`#c71585`,midnightblue:`#191970`,mintcream:`#f5fffa`,mistyrose:`#ffe4e1`,moccasin:`#ffe4b5`,navajowhite:`#ffdead`,navy:`#000080`,oldlace:`#fdf5e6`,olive:`#808000`,olivedrab:`#6b8e23`,orange:`#ffa500`,orangered:`#ff4500`,orchid:`#da70d6`,palegoldenrod:`#eee8aa`,palegreen:`#98fb98`,paleturquoise:`#afeeee`,palevioletred:`#db7093`,papayawhip:`#ffefd5`,peachpuff:`#ffdab9`,peru:`#cd853f`,pink:`#ffc0cb`,plum:`#dda0dd`,powderblue:`#b0e0e6`,purple:`#800080`,purple2:`#7f007f`,purple3:`#a020f0`,rebeccapurple:`#663399`,red:`#ff0000`,rosybrown:`#bc8f8f`,royalblue:`#4169e1`,saddlebrown:`#8b4513`,salmon:`#fa8072`,sandybrown:`#f4a460`,seagreen:`#2e8b57`,seashell:`#fff5ee`,sienna:`#a0522d`,silver:`#c0c0c0`,skyblue:`#87ceeb`,slateblue:`#6a5acd`,slategray:`#708090`,slategrey:`#708090`,snow:`#fffafa`,springgreen:`#00ff7f`,steelblue:`#4682b4`,tan:`#d2b48c`,teal:`#008080`,thistle:`#d8bfd8`,tomato:`#ff6347`,turquoise:`#40e0d0`,violet:`#ee82ee`,wheat:`#f5deb3`,white:`#ffffff`,whitesmoke:`#f5f5f5`,yellow:`#ffff00`,yellowgreen:`#9acd32`},S=/^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,C=/^#?([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/,w=e=>{if(e.match(S)){(e.length===4||e.length===7)&&(e=e.substr(1)),e.length===3&&(e=e.split(``),e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]);let t=parseInt(e,16);return[t>>16,t>>8&255,t&255,1]}if(e.match(C)){(e.length===5||e.length===9)&&(e=e.substr(1)),e.length===4&&(e=e.split(``),e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]+e[3]+e[3]);let t=parseInt(e,16);return[t>>24&255,t>>16&255,t>>8&255,Math.round((t&255)/255*100)/100]}throw Error(`unknown hex color: ${e}`)},{round:T}=Math,E=(...e)=>{let[t,n,r,i]=o(e,`rgba`),a=s(e)||`auto`;i===void 0&&(i=1),a===`auto`&&(a=i<1?`rgba`:`rgb`),t=T(t),n=T(n),r=T(r);let c=`000000`+(t<<16|n<<8|r).toString(16);c=c.substr(c.length-6);let l=`0`+T(i*255).toString(16);switch(l=l.substr(l.length-2),a.toLowerCase()){case`rgba`:return`#${c}${l}`;case`argb`:return`#${l}${c}`;default:return`#${c}`}};y.prototype.name=function(){let e=E(this._rgb,`rgb`);for(let t of Object.keys(x))if(x[t]===e)return t.toLowerCase();return e},v.format.named=e=>{if(e=e.toLowerCase(),x[e])return w(x[e]);throw Error(`unknown color name: `+e)},v.autodetect.push({p:5,test:(e,...t)=>{if(!t.length&&a(e)===`string`&&x[e.toLowerCase()])return`named`}}),y.prototype.alpha=function(e,t=!1){return e!==void 0&&a(e)===`number`?t?(this._rgb[3]=e,this):new y([this._rgb[0],this._rgb[1],this._rgb[2],e],`rgb`):this._rgb[3]},y.prototype.clipped=function(){return this._rgb._clipped||!1};const D={Kn:18,labWhitePoint:`d65`,Xn:.95047,Yn:1,Zn:1.08883,t0:.137931034,t1:.206896552,t2:.12841855,t3:.008856452,kE:216/24389,kKE:8,kK:24389/27,RefWhiteRGB:{X:.95047,Y:1,Z:1.08883},MtxRGB2XYZ:{m00:.4124564390896922,m01:.21267285140562253,m02:.0193338955823293,m10:.357576077643909,m11:.715152155287818,m12:.11919202588130297,m20:.18043748326639894,m21:.07217499330655958,m22:.9503040785363679},MtxXYZ2RGB:{m00:3.2404541621141045,m01:-.9692660305051868,m02:.055643430959114726,m10:-1.5371385127977166,m11:1.8760108454466942,m12:-.2040259135167538,m20:-.498531409556016,m21:.041556017530349834,m22:1.0572251882231791},As:.9414285350000001,Bs:1.040417467,Cs:1.089532651,MtxAdaptMa:{m00:.8951,m01:-.7502,m02:.0389,m10:.2664,m11:1.7135,m12:-.0685,m20:-.1614,m21:.0367,m22:1.0296},MtxAdaptMaI:{m00:.9869929054667123,m01:.43230526972339456,m02:-.008528664575177328,m10:-.14705425642099013,m11:.5183602715367776,m12:.04004282165408487,m20:.15996265166373125,m21:.0492912282128556,m22:.9684866957875502}},O=new Map([[`a`,[1.0985,.35585]],[`b`,[1.0985,.35585]],[`c`,[.98074,1.18232]],[`d50`,[.96422,.82521]],[`d55`,[.95682,.92149]],[`d65`,[.95047,1.08883]],[`e`,[1,1,1]],[`f2`,[.99186,.67393]],[`f7`,[.95041,1.08747]],[`f11`,[1.00962,.6435]],[`icc`,[.96422,.82521]]]);function k(e){let t=O.get(String(e).toLowerCase());if(!t)throw Error(`unknown Lab illuminant `+e);D.labWhitePoint=e,D.Xn=t[0],D.Zn=t[1]}function A(){return D.labWhitePoint}const j=(...e)=>{e=o(e,`lab`);let[t,n,r]=e,[i,a,s]=ee(t,n,r),[c,l,u]=te(i,a,s);return[c,l,u,e.length>3?e[3]:1]},ee=(e,t,n)=>{let{kE:r,kK:i,kKE:a,Xn:o,Yn:s,Zn:c}=D,l=(e+16)/116,u=.002*t+l,d=l-.005*n,f=u*u*u,p=d*d*d,m=f>r?f:(116*u-16)/i,h=e>a?((e+16)/116)**3:e/i,g=p>r?p:(116*d-16)/i;return[m*o,h*s,g*c]},M=e=>{let t=Math.sign(e);return e=Math.abs(e),(e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055)*t},te=(e,t,n)=>{let{MtxAdaptMa:r,MtxAdaptMaI:i,MtxXYZ2RGB:a,RefWhiteRGB:o,Xn:s,Yn:c,Zn:l}=D,u=s*r.m00+c*r.m10+l*r.m20,d=s*r.m01+c*r.m11+l*r.m21,f=s*r.m02+c*r.m12+l*r.m22,p=o.X*r.m00+o.Y*r.m10+o.Z*r.m20,m=o.X*r.m01+o.Y*r.m11+o.Z*r.m21,h=o.X*r.m02+o.Y*r.m12+o.Z*r.m22,g=(e*r.m00+t*r.m10+n*r.m20)*(p/u),_=(e*r.m01+t*r.m11+n*r.m21)*(m/d),v=(e*r.m02+t*r.m12+n*r.m22)*(h/f),y=g*i.m00+_*i.m10+v*i.m20,b=g*i.m01+_*i.m11+v*i.m21,x=g*i.m02+_*i.m12+v*i.m22,S=M(y*a.m00+b*a.m10+x*a.m20),C=M(y*a.m01+b*a.m11+x*a.m21),w=M(y*a.m02+b*a.m12+x*a.m22);return[S*255,C*255,w*255]},N=(...e)=>{let[t,n,r,...i]=o(e,`rgb`),[a,s,c]=ie(t,n,r),[l,u,d]=ne(a,s,c);return[l,u,d,...i.length>0&&i[0]<1?[i[0]]:[]]};function ne(e,t,n){let{Xn:r,Yn:i,Zn:a,kE:o,kK:s}=D,c=e/r,l=t/i,u=n/a,d=c>o?c**(1/3):(s*c+16)/116,f=l>o?l**(1/3):(s*l+16)/116,p=u>o?u**(1/3):(s*u+16)/116;return[116*f-16,500*(d-f),200*(f-p)]}function re(e){let t=Math.sign(e);return e=Math.abs(e),(e<=.04045?e/12.92:((e+.055)/1.055)**2.4)*t}const ie=(e,t,n)=>{e=re(e/255),t=re(t/255),n=re(n/255);let{MtxRGB2XYZ:r,MtxAdaptMa:i,MtxAdaptMaI:a,Xn:o,Yn:s,Zn:c,As:l,Bs:u,Cs:d}=D,f=e*r.m00+t*r.m10+n*r.m20,p=e*r.m01+t*r.m11+n*r.m21,m=e*r.m02+t*r.m12+n*r.m22,h=o*i.m00+s*i.m10+c*i.m20,g=o*i.m01+s*i.m11+c*i.m21,_=o*i.m02+s*i.m12+c*i.m22,v=f*i.m00+p*i.m10+m*i.m20,y=f*i.m01+p*i.m11+m*i.m21,b=f*i.m02+p*i.m12+m*i.m22;return v*=h/l,y*=g/u,b*=_/d,f=v*a.m00+y*a.m10+b*a.m20,p=v*a.m01+y*a.m11+b*a.m21,m=v*a.m02+y*a.m12+b*a.m22,[f,p,m]};y.prototype.lab=function(){return N(this._rgb)};const ae=(...e)=>new y(...e,`lab`);Object.assign(b,{lab:ae,getLabWhitePoint:A,setLabWhitePoint:k}),v.format.lab=j,v.autodetect.push({p:2,test:(...e)=>{if(e=o(e,`lab`),a(e)===`array`&&e.length===3)return`lab`}}),y.prototype.darken=function(e=1){let t=this,n=t.lab();return n[0]-=D.Kn*e,new y(n,`lab`).alpha(t.alpha(),!0)},y.prototype.brighten=function(e=1){return this.darken(-e)},y.prototype.darker=y.prototype.darken,y.prototype.brighter=y.prototype.brighten,y.prototype.get=function(e){let[t,n]=e.split(`.`),r=this[t]();if(n){let e=t.indexOf(n)-(t.substr(0,2)===`ok`?2:0);if(e>-1)return r[e];throw Error(`unknown channel ${n} in mode ${t}`)}else return r};const{pow:oe}=Math;y.prototype.luminance=function(e,t=`rgb`){if(e!==void 0&&a(e)===`number`){if(e===0)return new y([0,0,0,this._rgb[3]],`rgb`);if(e===1)return new y([255,255,255,this._rgb[3]],`rgb`);let n=this.luminance(),r=20,i=(n,a)=>{let o=n.interpolate(a,.5,t),s=o.luminance();return Math.abs(e-s)<1e-7||!r--?o:s>e?i(n,o):i(o,a)};return new y([...(n>e?i(new y([0,0,0]),this):i(this,new y([255,255,255]))).rgb(),this._rgb[3]])}return se(...this._rgb.slice(0,3))};const se=(e,t,n)=>(e=ce(e),t=ce(t),n=ce(n),.2126*e+.7152*t+.0722*n),ce=e=>(e/=255,e<=.03928?e/12.92:oe((e+.055)/1.055,2.4));var P={},F=(e,t,n=.5,...r)=>{let i=r[0]||`lrgb`;if(!P[i]&&!r.length&&(i=Object.keys(P)[0]),!P[i])throw Error(`interpolation mode ${i} is not defined`);return a(e)!==`object`&&(e=new y(e)),a(t)!==`object`&&(t=new y(t)),P[i](e,t,n).alpha(e.alpha()+n*(t.alpha()-e.alpha()))};y.prototype.mix=y.prototype.interpolate=function(e,t=.5,...n){return F(this,e,t,...n)},y.prototype.premultiply=function(e=!1){let t=this._rgb,n=t[3];return e?(this._rgb=[t[0]*n,t[1]*n,t[2]*n,n],this):new y([t[0]*n,t[1]*n,t[2]*n,n],`rgb`)};const{sin:le,cos:ue}=Math,de=(...e)=>{let[t,n,r]=o(e,`lch`);return isNaN(r)&&(r=0),r*=h,[t,ue(r)*n,le(r)*n]},fe=(...e)=>{e=o(e,`lch`);let[t,n,r]=e,[i,a,s]=de(t,n,r),[c,l,u]=j(i,a,s);return[c,l,u,e.length>3?e[3]:1]},pe=(...e)=>fe(..._(o(e,`hcl`))),{sqrt:me,atan2:he,round:ge}=Math,_e=(...e)=>{let[t,n,r]=o(e,`lab`),i=me(n*n+r*r),a=(he(r,n)*g+360)%360;return ge(i*1e4)===0&&(a=NaN),[t,i,a]},ve=(...e)=>{let[t,n,r,...i]=o(e,`rgb`),[a,s,c]=N(t,n,r),[l,u,d]=_e(a,s,c);return[l,u,d,...i.length>0&&i[0]<1?[i[0]]:[]]};y.prototype.lch=function(){return ve(this._rgb)},y.prototype.hcl=function(){return _(ve(this._rgb))};const ye=(...e)=>new y(...e,`lch`),be=(...e)=>new y(...e,`hcl`);Object.assign(b,{lch:ye,hcl:be}),v.format.lch=fe,v.format.hcl=pe,[`lch`,`hcl`].forEach(e=>v.autodetect.push({p:2,test:(...t)=>{if(t=o(t,e),a(t)===`array`&&t.length===3)return e}})),y.prototype.saturate=function(e=1){let t=this,n=t.lch();return n[1]+=D.Kn*e,n[1]<0&&(n[1]=0),new y(n,`lch`).alpha(t.alpha(),!0)},y.prototype.desaturate=function(e=1){return this.saturate(-e)},y.prototype.set=function(e,t,n=!1){let[r,i]=e.split(`.`),o=this[r]();if(i){let e=r.indexOf(i)-(r.substr(0,2)===`ok`?2:0);if(e>-1){if(a(t)==`string`)switch(t.charAt(0)){case`+`:o[e]+=+t;break;case`-`:o[e]+=+t;break;case`*`:o[e]*=+t.substr(1);break;case`/`:o[e]/=+t.substr(1);break;default:o[e]=+t}else if(a(t)===`number`)o[e]=t;else throw Error(`unsupported value for Color.set`);let i=new y(o,r);return n?(this._rgb=i._rgb,this):i}throw Error(`unknown channel ${i} in mode ${r}`)}else return o},y.prototype.tint=function(e=.5,...t){return F(this,`white`,e,...t)},y.prototype.shade=function(e=.5,...t){return F(this,`black`,e,...t)};const xe=(e,t,n)=>{let r=e._rgb,i=t._rgb;return new y(r[0]+n*(i[0]-r[0]),r[1]+n*(i[1]-r[1]),r[2]+n*(i[2]-r[2]),`rgb`)};P.rgb=xe;const{sqrt:Se,pow:I}=Math,Ce=(e,t,n)=>{let[r,i,a]=e._rgb,[o,s,c]=t._rgb;return new y(Se(I(r,2)*(1-n)+I(o,2)*n),Se(I(i,2)*(1-n)+I(s,2)*n),Se(I(a,2)*(1-n)+I(c,2)*n),`rgb`)};P.lrgb=Ce;const we=(e,t,n)=>{let r=e.lab(),i=t.lab();return new y(r[0]+n*(i[0]-r[0]),r[1]+n*(i[1]-r[1]),r[2]+n*(i[2]-r[2]),`lab`)};P.lab=we;var L=(e,t,n,r)=>{let i,a;r===`hsl`?(i=e.hsl(),a=t.hsl()):r===`hsv`?(i=e.hsv(),a=t.hsv()):r===`hcg`?(i=e.hcg(),a=t.hcg()):r===`hsi`?(i=e.hsi(),a=t.hsi()):r===`lch`||r===`hcl`?(r=`hcl`,i=e.hcl(),a=t.hcl()):r===`oklch`&&(i=e.oklch().reverse(),a=t.oklch().reverse());let o,s,c,l,u,d;(r.substr(0,1)===`h`||r===`oklch`)&&([o,c,u]=i,[s,l,d]=a);let f,p,m,h;return!isNaN(o)&&!isNaN(s)?(h=s>o&&s-o>180?s-(o+360):s<o&&o-s>180?s+360-o:s-o,p=o+n*h):isNaN(o)?isNaN(s)?p=NaN:(p=s,(u==1||u==0)&&r!=`hsv`&&(f=l)):(p=o,(d==1||d==0)&&r!=`hsv`&&(f=c)),f===void 0&&(f=c+n*(l-c)),m=u+n*(d-u),r===`oklch`?new y([m,f,p],r):new y([p,f,m],r)};const Te=(e,t,n)=>L(e,t,n,`lch`);P.lch=Te,P.hcl=Te;const Ee=e=>{if(a(e)==`number`&&e>=0&&e<=16777215)return[e>>16,e>>8&255,e&255,1];throw Error(`unknown num color: `+e)},De=(...e)=>{let[t,n,r]=o(e,`rgb`);return(t<<16)+(n<<8)+r};y.prototype.num=function(){return De(this._rgb)};const Oe=(...e)=>new y(...e,`num`);Object.assign(b,{num:Oe}),v.format.num=Ee,v.autodetect.push({p:5,test:(...e)=>{if(e.length===1&&a(e[0])===`number`&&e[0]>=0&&e[0]<=16777215)return`num`}});const ke=(e,t,n)=>{let r=e.num();return new y(r+n*(t.num()-r),`num`)};P.num=ke;const{floor:Ae}=Math,je=(...e)=>{e=o(e,`hcg`);let[t,n,r]=e,i,a,s;r*=255;let c=n*255;if(n===0)i=a=s=r;else{t===360&&(t=0),t>360&&(t-=360),t<0&&(t+=360),t/=60;let e=Ae(t),o=t-e,l=r*(1-n),u=l+c*(1-o),d=l+c*o,f=l+c;switch(e){case 0:[i,a,s]=[f,d,l];break;case 1:[i,a,s]=[u,f,l];break;case 2:[i,a,s]=[l,f,d];break;case 3:[i,a,s]=[l,u,f];break;case 4:[i,a,s]=[d,l,f];break;case 5:[i,a,s]=[f,l,u];break}}return[i,a,s,e.length>3?e[3]:1]},Me=(...e)=>{let[t,n,r]=o(e,`rgb`),i=l(t,n,r),a=u(t,n,r),s=a-i,c=s*100/255,d=i/(255-s)*100,f;return s===0?f=NaN:(t===a&&(f=(n-r)/s),n===a&&(f=2+(r-t)/s),r===a&&(f=4+(t-n)/s),f*=60,f<0&&(f+=360)),[f,c,d]};y.prototype.hcg=function(){return Me(this._rgb)};const Ne=(...e)=>new y(...e,`hcg`);b.hcg=Ne,v.format.hcg=je,v.autodetect.push({p:1,test:(...e)=>{if(e=o(e,`hcg`),a(e)===`array`&&e.length===3)return`hcg`}});const Pe=(e,t,n)=>L(e,t,n,`hcg`);P.hcg=Pe;const{cos:R}=Math,Fe=(...e)=>{e=o(e,`hsi`);let[t,r,i]=e,a,s,c;return isNaN(t)&&(t=0),isNaN(r)&&(r=0),t>360&&(t-=360),t<0&&(t+=360),t/=360,t<1/3?(c=(1-r)/3,a=(1+r*R(p*t)/R(m-p*t))/3,s=1-(c+a)):t<2/3?(t-=1/3,a=(1-r)/3,s=(1+r*R(p*t)/R(m-p*t))/3,c=1-(a+s)):(t-=2/3,s=(1-r)/3,c=(1+r*R(p*t)/R(m-p*t))/3,a=1-(s+c)),a=n(i*a*3),s=n(i*s*3),c=n(i*c*3),[a*255,s*255,c*255,e.length>3?e[3]:1]},{min:Ie,sqrt:Le,acos:Re}=Math,ze=(...e)=>{let[t,n,r]=o(e,`rgb`);t/=255,n/=255,r/=255;let i,a=Ie(t,n,r),s=(t+n+r)/3,c=s>0?1-a/s:0;return c===0?i=NaN:(i=(t-n+(t-r))/2,i/=Le((t-n)*(t-n)+(t-r)*(n-r)),i=Re(i),r>n&&(i=p-i),i/=p),[i*360,c,s]};y.prototype.hsi=function(){return ze(this._rgb)};const Be=(...e)=>new y(...e,`hsi`);b.hsi=Be,v.format.hsi=Fe,v.autodetect.push({p:2,test:(...e)=>{if(e=o(e,`hsi`),a(e)===`array`&&e.length===3)return`hsi`}});const Ve=(e,t,n)=>L(e,t,n,`hsi`);P.hsi=Ve;const He=(...e)=>{e=o(e,`hsl`);let[t,n,r]=e,i,a,s;if(n===0)i=a=s=r*255;else{let e=[0,0,0],o=[0,0,0],c=r<.5?r*(1+n):r+n-r*n,l=2*r-c,u=t/360;e[0]=u+1/3,e[1]=u,e[2]=u-1/3;for(let t=0;t<3;t++)e[t]<0&&(e[t]+=1),e[t]>1&&--e[t],6*e[t]<1?o[t]=l+(c-l)*6*e[t]:2*e[t]<1?o[t]=c:3*e[t]<2?o[t]=l+(c-l)*(2/3-e[t])*6:o[t]=l;[i,a,s]=[o[0]*255,o[1]*255,o[2]*255]}return e.length>3?[i,a,s,e[3]]:[i,a,s,1]},Ue=(...e)=>{e=o(e,`rgba`);let[t,n,r]=e;t/=255,n/=255,r/=255;let i=l(t,n,r),a=u(t,n,r),s=(a+i)/2,c,d;return a===i?(c=0,d=NaN):c=s<.5?(a-i)/(a+i):(a-i)/(2-a-i),t==a?d=(n-r)/(a-i):n==a?d=2+(r-t)/(a-i):r==a&&(d=4+(t-n)/(a-i)),d*=60,d<0&&(d+=360),e.length>3&&e[3]!==void 0?[d,c,s,e[3]]:[d,c,s]};y.prototype.hsl=function(){return Ue(this._rgb)};const We=(...e)=>new y(...e,`hsl`);b.hsl=We,v.format.hsl=He,v.autodetect.push({p:2,test:(...e)=>{if(e=o(e,`hsl`),a(e)===`array`&&e.length===3)return`hsl`}});const Ge=(e,t,n)=>L(e,t,n,`hsl`);P.hsl=Ge;const{floor:Ke}=Math,qe=(...e)=>{e=o(e,`hsv`);let[t,n,r]=e,i,a,s;if(r*=255,n===0)i=a=s=r;else{t===360&&(t=0),t>360&&(t-=360),t<0&&(t+=360),t/=60;let e=Ke(t),o=t-e,c=r*(1-n),l=r*(1-n*o),u=r*(1-n*(1-o));switch(e){case 0:[i,a,s]=[r,u,c];break;case 1:[i,a,s]=[l,r,c];break;case 2:[i,a,s]=[c,r,u];break;case 3:[i,a,s]=[c,l,r];break;case 4:[i,a,s]=[u,c,r];break;case 5:[i,a,s]=[r,c,l];break}}return[i,a,s,e.length>3?e[3]:1]},{min:Je,max:Ye}=Math,Xe=(...e)=>{e=o(e,`rgb`);let[t,n,r]=e,i=Je(t,n,r),a=Ye(t,n,r),s=a-i,c,l,u;return u=a/255,a===0?(c=NaN,l=0):(l=s/a,t===a&&(c=(n-r)/s),n===a&&(c=2+(r-t)/s),r===a&&(c=4+(t-n)/s),c*=60,c<0&&(c+=360)),[c,l,u]};y.prototype.hsv=function(){return Xe(this._rgb)};const Ze=(...e)=>new y(...e,`hsv`);b.hsv=Ze,v.format.hsv=qe,v.autodetect.push({p:2,test:(...e)=>{if(e=o(e,`hsv`),a(e)===`array`&&e.length===3)return`hsv`}});const Qe=(e,t,n)=>L(e,t,n,`hsv`);P.hsv=Qe;function z(e,t){let n=e.length;Array.isArray(e[0])||(e=[e]),Array.isArray(t[0])||(t=t.map(e=>[e]));let r=t[0].length,i=t[0].map((e,n)=>t.map(e=>e[n])),a=e.map(e=>i.map(t=>Array.isArray(e)?e.reduce((e,n,r)=>e+n*(t[r]||0),0):t.reduce((t,n)=>t+n*e,0)));return n===1&&(a=a[0]),r===1?a.map(e=>e[0]):a}const $e=(...e)=>{e=o(e,`lab`);let[t,n,r,...i]=e,[a,s,c]=et([t,n,r]),[l,u,d]=te(a,s,c);return[l,u,d,...i.length>0&&i[0]<1?[i[0]]:[]]};function et(e){return z([[1.2268798758459243,-.5578149944602171,.2813910456659647],[-.0405757452148008,1.112286803280317,-.0717110580655164],[-.0763729366746601,-.4214933324022432,1.5869240198367816]],z([[1,.3963377773761749,.2158037573099136],[1,-.1055613458156586,-.0638541728258133],[1,-.0894841775298119,-1.2914855480194092]],e).map(e=>e**3))}const tt=(...e)=>{let[t,n,r,...i]=o(e,`rgb`);return[...nt(ie(t,n,r)),...i.length>0&&i[0]<1?[i[0]]:[]]};function nt(e){return z([[.210454268309314,.7936177747023054,-.0040720430116193],[1.9779985324311684,-2.42859224204858,.450593709617411],[.0259040424655478,.7827717124575296,-.8086757549230774]],z([[.819022437996703,.3619062600528904,-.1288737815209879],[.0329836539323885,.9292868615863434,.0361446663506424],[.0481771893596242,.2642395317527308,.6335478284694309]],e).map(e=>Math.cbrt(e)))}y.prototype.oklab=function(){return tt(this._rgb)};const rt=(...e)=>new y(...e,`oklab`);Object.assign(b,{oklab:rt}),v.format.oklab=$e,v.autodetect.push({p:2,test:(...e)=>{if(e=o(e,`oklab`),a(e)===`array`&&e.length===3)return`oklab`}});const it=(e,t,n)=>{let r=e.oklab(),i=t.oklab();return new y(r[0]+n*(i[0]-r[0]),r[1]+n*(i[1]-r[1]),r[2]+n*(i[2]-r[2]),`oklab`)};P.oklab=it;const at=(e,t,n)=>L(e,t,n,`oklch`);P.oklch=at;const{pow:ot,sqrt:st,PI:ct,cos:lt,sin:ut,atan2:dt}=Math;var ft=(e,t=`lrgb`,n=null)=>{let r=e.length;n||=Array.from(Array(r)).map(()=>1);let i=r/n.reduce(function(e,t){return e+t});if(n.forEach((e,t)=>{n[t]*=i}),e=e.map(e=>new y(e)),t===`lrgb`)return pt(e,n);let a=e.shift(),o=a.get(t),s=[],c=0,l=0;for(let e=0;e<o.length;e++)if(o[e]=(o[e]||0)*n[0],s.push(isNaN(o[e])?0:n[0]),t.charAt(e)===`h`&&!isNaN(o[e])){let t=o[e]/180*ct;c+=lt(t)*n[0],l+=ut(t)*n[0]}let u=a.alpha()*n[0];e.forEach((e,r)=>{let i=e.get(t);u+=e.alpha()*n[r+1];for(let e=0;e<o.length;e++)if(!isNaN(i[e]))if(s[e]+=n[r+1],t.charAt(e)===`h`){let t=i[e]/180*ct;c+=lt(t)*n[r+1],l+=ut(t)*n[r+1]}else o[e]+=i[e]*n[r+1]});for(let e=0;e<o.length;e++)if(t.charAt(e)===`h`){let t=dt(l/s[e],c/s[e])/ct*180;for(;t<0;)t+=360;for(;t>=360;)t-=360;o[e]=t}else o[e]=o[e]/s[e];return u/=r,new y(o,t).alpha(u>.99999?1:u,!0)};const pt=(e,t)=>{let n=e.length,i=[0,0,0,0];for(let r=0;r<e.length;r++){let a=e[r],o=t[r]/n,s=a._rgb;i[0]+=ot(s[0],2)*o,i[1]+=ot(s[1],2)*o,i[2]+=ot(s[2],2)*o,i[3]+=s[3]*o}return i[0]=st(i[0]),i[1]=st(i[1]),i[2]=st(i[2]),i[3]>.9999999&&(i[3]=1),new y(r(i))},{pow:mt}=Math;function B(e){let t=`rgb`,r=b(`#ccc`),i=0,o=[0,1],s=[0,1],c=[],l=[0,0],u=!1,d=[],f=!1,p=0,m=1,h=!1,g={},_=!0,v=1,y=function(e){if(e||=[`#fff`,`#000`],e&&a(e)===`string`&&b.brewer&&b.brewer[e.toLowerCase()]&&(e=b.brewer[e.toLowerCase()]),a(e)===`array`){e.length===1&&(e=[e[0],e[0]]),e=e.slice(0);for(let t=0;t<e.length;t++)e[t]=b(e[t]);c.length=0;for(let t=0;t<e.length;t++)c.push(t/(e.length-1))}return T(),d=e},x=function(e){if(u!=null){let t=u.length-1,n=0;for(;n<t&&e>=u[n];)n++;return n-1}return 0},S=e=>e,C=e=>e,w=function(e,i){let o,s;if(i??=!1,isNaN(e)||e===null)return r;s=i?e:u&&u.length>2?x(e)/(u.length-2):m===p?1:(e-p)/(m-p),s=C(s),i||(s=S(s)),v!==1&&(s=mt(s,v)),s=l[0]+s*(1-l[0]-l[1]),s=n(s,0,1);let f=Math.floor(s*1e4);if(_&&g[f])o=g[f];else{if(a(d)===`array`)for(let e=0;e<c.length;e++){let n=c[e];if(s<=n){o=d[e];break}if(s>=n&&e===c.length-1){o=d[e];break}if(s>n&&s<c[e+1]){s=(s-n)/(c[e+1]-n),o=b.interpolate(d[e],d[e+1],s,t);break}}else a(d)===`function`&&(o=d(s));_&&(g[f]=o)}return o};var T=()=>g={};y(e);let E=function(e){let t=b(w(e));return f&&t[f]?t[f]():t};return E.classes=function(e){if(e!=null){if(a(e)===`array`)u=e,o=[e[0],e[e.length-1]];else{let t=b.analyze(o);u=e===0?[t.min,t.max]:b.limits(t,`e`,e)}return E}return u},E.domain=function(e){if(!arguments.length)return s;s=e.slice(0),p=e[0],m=e[e.length-1],c=[];let t=d.length;if(e.length===t&&p!==m)for(let t of Array.from(e))c.push((t-p)/(m-p));else{for(let e=0;e<t;e++)c.push(e/(t-1));if(e.length>2){let t=e.map((t,n)=>n/(e.length-1)),n=e.map(e=>(e-p)/(m-p));n.every((e,n)=>t[n]===e)||(C=e=>{if(e<=0||e>=1)return e;let r=0;for(;e>=n[r+1];)r++;let i=(e-n[r])/(n[r+1]-n[r]);return t[r]+i*(t[r+1]-t[r])})}}return o=[p,m],E},E.mode=function(e){return arguments.length?(t=e,T(),E):t},E.range=function(e,t){return y(e,t),E},E.out=function(e){return f=e,E},E.spread=function(e){return arguments.length?(i=e,E):i},E.correctLightness=function(e){return e??=!0,h=e,T(),S=h?function(e){let t=w(0,!0).lab()[0],n=w(1,!0).lab()[0],r=t>n,i=w(e,!0).lab()[0],a=t+(n-t)*e,o=i-a,s=0,c=1,l=20;for(;Math.abs(o)>.01&&l-- >0;)(function(){return r&&(o*=-1),o<0?(s=e,e+=(c-e)*.5):(c=e,e+=(s-e)*.5),i=w(e,!0).lab()[0],o=i-a})();return e}:e=>e,E},E.padding=function(e){return e==null?l:(a(e)===`number`&&(e=[e,e]),l=e,E)},E.colors=function(t,n){arguments.length<2&&(n=`hex`);let r=[];if(arguments.length===0)r=d.slice(0);else if(t===1)r=[E(.5)];else if(t>1){let e=o[0],n=o[1]-e;r=ht(0,t,!1).map(r=>E(e+r/(t-1)*n))}else{e=[];let t=[];if(u&&u.length>2)for(let e=1,n=u.length,r=1<=n;r?e<n:e>n;r?e++:e--)t.push((u[e-1]+u[e])*.5);else t=o;r=t.map(e=>E(e))}return b[n]&&(r=r.map(e=>e[n]())),r},E.cache=function(e){return e==null?_:(_=e,E)},E.gamma=function(e){return e==null?v:(v=e,E)},E.nodata=function(e){return e==null?r:(r=b(e),E)},E}function ht(e,t,n){let r=[],i=e<t,a=n?i?t+1:t-1:t;for(let t=e;i?t<a:t>a;i?t++:t--)r.push(t);return r}const gt=function(e){let t=[1,1];for(let n=1;n<e;n++){let e=[1];for(let n=1;n<=t.length;n++)e[n]=(t[n]||0)+t[n-1];t=e}return t},_t=function(e){let t,n,r,i;if(e=e.map(e=>new y(e)),e.length===2)[n,r]=e.map(e=>e.lab()),t=function(e){return new y([0,1,2].map(t=>n[t]+e*(r[t]-n[t])),`lab`)};else if(e.length===3)[n,r,i]=e.map(e=>e.lab()),t=function(e){return new y([0,1,2].map(t=>(1-e)*(1-e)*n[t]+2*(1-e)*e*r[t]+e*e*i[t]),`lab`)};else if(e.length===4){let a;[n,r,i,a]=e.map(e=>e.lab()),t=function(e){return new y([0,1,2].map(t=>(1-e)*(1-e)*(1-e)*n[t]+3*(1-e)*(1-e)*e*r[t]+3*(1-e)*e*e*i[t]+e*e*e*a[t]),`lab`)}}else if(e.length>=5){let n,r,i;n=e.map(e=>e.lab()),i=e.length-1,r=gt(i),t=function(e){let t=1-e;return new y([0,1,2].map(a=>n.reduce((n,o,s)=>n+r[s]*t**(i-s)*e**s*o[a],0)),`lab`)}}else throw RangeError(`No point in running bezier with only one color.`);return t};var vt=e=>{let t=_t(e);return t.scale=()=>B(t),t};const{round:yt}=Math;y.prototype.rgb=function(e=!0){return e===!1?this._rgb.slice(0,3):this._rgb.slice(0,3).map(yt)},y.prototype.rgba=function(e=!0){return this._rgb.slice(0,4).map((t,n)=>n<3?e===!1?t:yt(t):t)};const bt=(...e)=>new y(...e,`rgb`);Object.assign(b,{rgb:bt}),v.format.rgb=(...e)=>{let t=o(e,`rgba`);return t[3]===void 0&&(t[3]=1),t},v.autodetect.push({p:3,test:(...e)=>{if(e=o(e,`rgba`),a(e)===`array`&&(e.length===3||e.length===4&&a(e[3])==`number`&&e[3]>=0&&e[3]<=1))return`rgb`}});const V=(e,t,n)=>{if(!V[n])throw Error(`unknown blend mode `+n);return V[n](e,t)},H=e=>(t,n)=>{let r=b(n).rgb(),i=b(t).rgb();return b.rgb(e(r,i))},U=e=>(t,n)=>{let r=[];return r[0]=e(t[0],n[0]),r[1]=e(t[1],n[1]),r[2]=e(t[2],n[2]),r},xt=e=>e,St=(e,t)=>e*t/255,Ct=(e,t)=>e>t?t:e,wt=(e,t)=>e>t?e:t,Tt=(e,t)=>255*(1-(1-e/255)*(1-t/255)),Et=(e,t)=>t<128?2*e*t/255:255*(1-2*(1-e/255)*(1-t/255)),Dt=(e,t)=>255*(1-(1-t/255)/(e/255)),Ot=(e,t)=>e===255?255:(e=t/255*255/(1-e/255),e>255?255:e);V.normal=H(U(xt)),V.multiply=H(U(St)),V.screen=H(U(Tt)),V.overlay=H(U(Et)),V.darken=H(U(Ct)),V.lighten=H(U(wt)),V.dodge=H(U(Ot)),V.burn=H(U(Dt));const{pow:kt,sin:At,cos:jt}=Math;function Mt(e=300,t=-1.5,n=1,i=1,o=[0,1]){let s=0,c;a(o)===`array`?c=o[1]-o[0]:(c=0,o=[o,o]);let l=function(a){let l=p*((e+120)/360+t*a),u=kt(o[0]+c*a,i),d=(s===0?n:n[0]+a*s)*u*(1-u)/2,f=jt(l),m=At(l),h=u+d*(-.14861*f+1.78277*m),g=u+d*(-.29227*f-.90649*m),_=u+1.97294*f*d;return b(r([h*255,g*255,_*255,1]))};return l.start=function(t){return t==null?e:(e=t,l)},l.rotations=function(e){return e==null?t:(t=e,l)},l.gamma=function(e){return e==null?i:(i=e,l)},l.hue=function(e){return e==null?n:(n=e,a(n)===`array`?(s=n[1]-n[0],s===0&&(n=n[1])):s=0,l)},l.lightness=function(e){return e==null?o:(a(e)===`array`?(o=e,c=e[1]-e[0]):(o=[e,e],c=0),l)},l.scale=()=>b.scale(l),l.hue(n),l}const{floor:Nt,random:Pt}=Math;var Ft=(e=Pt)=>{let t=`#`;for(let n=0;n<6;n++)t+=`0123456789abcdef`.charAt(Nt(e()*16));return new y(t,`hex`)};const{log:It,pow:Lt,floor:Rt,abs:zt}=Math;function Bt(e,t=null){let n={min:Number.MAX_VALUE,max:Number.MAX_VALUE*-1,sum:0,values:[],count:0};return a(e)===`object`&&(e=Object.values(e)),e.forEach(e=>{t&&a(e)===`object`&&(e=e[t]),e!=null&&!isNaN(e)&&(n.values.push(e),n.sum+=e,e<n.min&&(n.min=e),e>n.max&&(n.max=e),n.count+=1)}),n.domain=[n.min,n.max],n.limits=(e,t)=>Vt(n,e,t),n}function Vt(e,t=`equal`,n=7){a(e)==`array`&&(e=Bt(e));let{min:r,max:i}=e,o=e.values.sort((e,t)=>e-t);if(n===1)return[r,i];let s=[];if(t.substr(0,1)===`c`&&(s.push(r),s.push(i)),t.substr(0,1)===`e`){s.push(r);for(let e=1;e<n;e++)s.push(r+e/n*(i-r));s.push(i)}else if(t.substr(0,1)===`l`){if(r<=0)throw Error(`Logarithmic scales are only possible for values > 0`);let e=Math.LOG10E*It(r),t=Math.LOG10E*It(i);s.push(r);for(let r=1;r<n;r++)s.push(Lt(10,e+r/n*(t-e)));s.push(i)}else if(t.substr(0,1)===`q`){s.push(r);for(let e=1;e<n;e++){let t=(o.length-1)*e/n,r=Rt(t);if(r===t)s.push(o[r]);else{let e=t-r;s.push(o[r]*(1-e)+o[r+1]*e)}}s.push(i)}else if(t.substr(0,1)===`k`){let e,t=o.length,a=Array(t),c=Array(n),l=!0,u=0,d=null;d=[],d.push(r);for(let e=1;e<n;e++)d.push(r+e/n*(i-r));for(d.push(i);l;){for(let e=0;e<n;e++)c[e]=0;for(let e=0;e<t;e++){let t=o[e],r=Number.MAX_VALUE,i;for(let o=0;o<n;o++){let n=zt(d[o]-t);n<r&&(r=n,i=o),c[i]++,a[e]=i}}let r=Array(n);for(let e=0;e<n;e++)r[e]=null;for(let n=0;n<t;n++)e=a[n],r[e]===null?r[e]=o[n]:r[e]+=o[n];for(let e=0;e<n;e++)r[e]*=1/c[e];l=!1;for(let e=0;e<n;e++)if(r[e]!==d[e]){l=!0;break}d=r,u++,u>200&&(l=!1)}let f={};for(let e=0;e<n;e++)f[e]=[];for(let n=0;n<t;n++)e=a[n],f[e].push(o[n]);let p=[];for(let e=0;e<n;e++)p.push(f[e][0]),p.push(f[e][f[e].length-1]);p=p.sort((e,t)=>e-t),s.push(p[0]);for(let e=1;e<p.length;e+=2){let t=p[e];!isNaN(t)&&s.indexOf(t)===-1&&s.push(t)}}return s}var Ht=(e,t)=>{e=new y(e),t=new y(t);let n=e.luminance(),r=t.luminance();return n>r?(n+.05)/(r+.05):(r+.05)/(n+.05)};
1
+ const{min:e,max:t}=Math;var n=(n,r=0,i=1)=>e(t(r,n),i),r=e=>{e._clipped=!1,e._unclipped=e.slice(0);for(let t=0;t<=3;t++)t<3?((e[t]<0||e[t]>255)&&(e._clipped=!0),e[t]=n(e[t],0,255)):t===3&&(e[t]=n(e[t],0,1));return e};const i={};for(let e of[`Boolean`,`Number`,`String`,`Function`,`Array`,`Date`,`RegExp`,`Undefined`,`Null`])i[`[object ${e}]`]=e.toLowerCase();function a(e){return i[Object.prototype.toString.call(e)]||`object`}var o=(e,t=null)=>e.length>=3?Array.prototype.slice.call(e):a(e[0])==`object`&&t?t.split(``).filter(t=>e[0][t]!==void 0).map(t=>e[0][t]):e[0].slice(0),s=e=>{if(e.length<2)return null;let t=e.length-1;return a(e[t])==`string`?e[t].toLowerCase():null};const{PI:c,min:l,max:u}=Math,d=e=>Math.round(e*100)/100,f=e=>Math.round(e*100)/100,p=c*2,m=c/3,h=c/180,g=180/c;function _(e){return[...e.slice(0,3).reverse(),...e.slice(3)]}var v={format:{},autodetect:[]},y=class{constructor(...e){let t=this;if(a(e[0])===`object`&&e[0].constructor&&e[0].constructor===this.constructor)return e[0];let n=s(e),i=!1;if(!n){i=!0,v.sorted||=(v.autodetect=v.autodetect.sort((e,t)=>t.p-e.p),!0);for(let t of v.autodetect)if(n=t.test(...e),n)break}if(v.format[n])t._rgb=r(v.format[n].apply(null,i?e:e.slice(0,-1)));else throw Error(`unknown format: `+e);t._rgb.length===3&&t._rgb.push(1)}toString(){return a(this.hex)==`function`?this.hex():`[${this._rgb.join(`,`)}]`}};const b=(...e)=>new y(...e);b.version=`3.2.0`;const x={aliceblue:`#f0f8ff`,antiquewhite:`#faebd7`,aqua:`#00ffff`,aquamarine:`#7fffd4`,azure:`#f0ffff`,beige:`#f5f5dc`,bisque:`#ffe4c4`,black:`#000000`,blanchedalmond:`#ffebcd`,blue:`#0000ff`,blueviolet:`#8a2be2`,brown:`#a52a2a`,burlywood:`#deb887`,cadetblue:`#5f9ea0`,chartreuse:`#7fff00`,chocolate:`#d2691e`,coral:`#ff7f50`,cornflowerblue:`#6495ed`,cornsilk:`#fff8dc`,crimson:`#dc143c`,cyan:`#00ffff`,darkblue:`#00008b`,darkcyan:`#008b8b`,darkgoldenrod:`#b8860b`,darkgray:`#a9a9a9`,darkgreen:`#006400`,darkgrey:`#a9a9a9`,darkkhaki:`#bdb76b`,darkmagenta:`#8b008b`,darkolivegreen:`#556b2f`,darkorange:`#ff8c00`,darkorchid:`#9932cc`,darkred:`#8b0000`,darksalmon:`#e9967a`,darkseagreen:`#8fbc8f`,darkslateblue:`#483d8b`,darkslategray:`#2f4f4f`,darkslategrey:`#2f4f4f`,darkturquoise:`#00ced1`,darkviolet:`#9400d3`,deeppink:`#ff1493`,deepskyblue:`#00bfff`,dimgray:`#696969`,dimgrey:`#696969`,dodgerblue:`#1e90ff`,firebrick:`#b22222`,floralwhite:`#fffaf0`,forestgreen:`#228b22`,fuchsia:`#ff00ff`,gainsboro:`#dcdcdc`,ghostwhite:`#f8f8ff`,gold:`#ffd700`,goldenrod:`#daa520`,gray:`#808080`,green:`#008000`,greenyellow:`#adff2f`,grey:`#808080`,honeydew:`#f0fff0`,hotpink:`#ff69b4`,indianred:`#cd5c5c`,indigo:`#4b0082`,ivory:`#fffff0`,khaki:`#f0e68c`,laserlemon:`#ffff54`,lavender:`#e6e6fa`,lavenderblush:`#fff0f5`,lawngreen:`#7cfc00`,lemonchiffon:`#fffacd`,lightblue:`#add8e6`,lightcoral:`#f08080`,lightcyan:`#e0ffff`,lightgoldenrod:`#fafad2`,lightgoldenrodyellow:`#fafad2`,lightgray:`#d3d3d3`,lightgreen:`#90ee90`,lightgrey:`#d3d3d3`,lightpink:`#ffb6c1`,lightsalmon:`#ffa07a`,lightseagreen:`#20b2aa`,lightskyblue:`#87cefa`,lightslategray:`#778899`,lightslategrey:`#778899`,lightsteelblue:`#b0c4de`,lightyellow:`#ffffe0`,lime:`#00ff00`,limegreen:`#32cd32`,linen:`#faf0e6`,magenta:`#ff00ff`,maroon:`#800000`,maroon2:`#7f0000`,maroon3:`#b03060`,mediumaquamarine:`#66cdaa`,mediumblue:`#0000cd`,mediumorchid:`#ba55d3`,mediumpurple:`#9370db`,mediumseagreen:`#3cb371`,mediumslateblue:`#7b68ee`,mediumspringgreen:`#00fa9a`,mediumturquoise:`#48d1cc`,mediumvioletred:`#c71585`,midnightblue:`#191970`,mintcream:`#f5fffa`,mistyrose:`#ffe4e1`,moccasin:`#ffe4b5`,navajowhite:`#ffdead`,navy:`#000080`,oldlace:`#fdf5e6`,olive:`#808000`,olivedrab:`#6b8e23`,orange:`#ffa500`,orangered:`#ff4500`,orchid:`#da70d6`,palegoldenrod:`#eee8aa`,palegreen:`#98fb98`,paleturquoise:`#afeeee`,palevioletred:`#db7093`,papayawhip:`#ffefd5`,peachpuff:`#ffdab9`,peru:`#cd853f`,pink:`#ffc0cb`,plum:`#dda0dd`,powderblue:`#b0e0e6`,purple:`#800080`,purple2:`#7f007f`,purple3:`#a020f0`,rebeccapurple:`#663399`,red:`#ff0000`,rosybrown:`#bc8f8f`,royalblue:`#4169e1`,saddlebrown:`#8b4513`,salmon:`#fa8072`,sandybrown:`#f4a460`,seagreen:`#2e8b57`,seashell:`#fff5ee`,sienna:`#a0522d`,silver:`#c0c0c0`,skyblue:`#87ceeb`,slateblue:`#6a5acd`,slategray:`#708090`,slategrey:`#708090`,snow:`#fffafa`,springgreen:`#00ff7f`,steelblue:`#4682b4`,tan:`#d2b48c`,teal:`#008080`,thistle:`#d8bfd8`,tomato:`#ff6347`,turquoise:`#40e0d0`,violet:`#ee82ee`,wheat:`#f5deb3`,white:`#ffffff`,whitesmoke:`#f5f5f5`,yellow:`#ffff00`,yellowgreen:`#9acd32`},S=/^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,C=/^#?([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/,w=e=>{if(e.match(S)){(e.length===4||e.length===7)&&(e=e.substr(1)),e.length===3&&(e=e.split(``),e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]);let t=parseInt(e,16);return[t>>16,t>>8&255,t&255,1]}if(e.match(C)){(e.length===5||e.length===9)&&(e=e.substr(1)),e.length===4&&(e=e.split(``),e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]+e[3]+e[3]);let t=parseInt(e,16);return[t>>24&255,t>>16&255,t>>8&255,Math.round((t&255)/255*100)/100]}throw Error(`unknown hex color: ${e}`)},{round:T}=Math,E=(...e)=>{let[t,n,r,i]=o(e,`rgba`),a=s(e)||`auto`;i===void 0&&(i=1),a===`auto`&&(a=i<1?`rgba`:`rgb`),t=T(t),n=T(n),r=T(r);let c=`000000`+(t<<16|n<<8|r).toString(16);c=c.substr(c.length-6);let l=`0`+T(i*255).toString(16);switch(l=l.substr(l.length-2),a.toLowerCase()){case`rgba`:return`#${c}${l}`;case`argb`:return`#${l}${c}`;default:return`#${c}`}};y.prototype.name=function(){let e=E(this._rgb,`rgb`);for(let t of Object.keys(x))if(x[t]===e)return t.toLowerCase();return e},v.format.named=e=>{if(e=e.toLowerCase(),x[e])return w(x[e]);throw Error(`unknown color name: `+e)},v.autodetect.push({p:5,test:(e,...t)=>{if(!t.length&&a(e)===`string`&&x[e.toLowerCase()])return`named`}}),y.prototype.alpha=function(e,t=!1){return e!==void 0&&a(e)===`number`?t?(this._rgb[3]=e,this):new y([this._rgb[0],this._rgb[1],this._rgb[2],e],`rgb`):this._rgb[3]},y.prototype.clipped=function(){return this._rgb._clipped||!1};const D={Kn:18,labWhitePoint:`d65`,Xn:.95047,Yn:1,Zn:1.08883,t0:.137931034,t1:.206896552,t2:.12841855,t3:.008856452,kE:216/24389,kKE:8,kK:24389/27,RefWhiteRGB:{X:.95047,Y:1,Z:1.08883},MtxRGB2XYZ:{m00:.4124564390896922,m01:.21267285140562253,m02:.0193338955823293,m10:.357576077643909,m11:.715152155287818,m12:.11919202588130297,m20:.18043748326639894,m21:.07217499330655958,m22:.9503040785363679},MtxXYZ2RGB:{m00:3.2404541621141045,m01:-.9692660305051868,m02:.055643430959114726,m10:-1.5371385127977166,m11:1.8760108454466942,m12:-.2040259135167538,m20:-.498531409556016,m21:.041556017530349834,m22:1.0572251882231791},As:.9414285350000001,Bs:1.040417467,Cs:1.089532651,MtxAdaptMa:{m00:.8951,m01:-.7502,m02:.0389,m10:.2664,m11:1.7135,m12:-.0685,m20:-.1614,m21:.0367,m22:1.0296},MtxAdaptMaI:{m00:.9869929054667123,m01:.43230526972339456,m02:-.008528664575177328,m10:-.14705425642099013,m11:.5183602715367776,m12:.04004282165408487,m20:.15996265166373125,m21:.0492912282128556,m22:.9684866957875502}},O=new Map([[`a`,[1.0985,.35585]],[`b`,[1.0985,.35585]],[`c`,[.98074,1.18232]],[`d50`,[.96422,.82521]],[`d55`,[.95682,.92149]],[`d65`,[.95047,1.08883]],[`e`,[1,1,1]],[`f2`,[.99186,.67393]],[`f7`,[.95041,1.08747]],[`f11`,[1.00962,.6435]],[`icc`,[.96422,.82521]]]);function k(e){let t=O.get(String(e).toLowerCase());if(!t)throw Error(`unknown Lab illuminant `+e);D.labWhitePoint=e,D.Xn=t[0],D.Zn=t[1]}function A(){return D.labWhitePoint}const j=(...e)=>{e=o(e,`lab`);let[t,n,r]=e,[i,a,s]=ee(t,n,r),[c,l,u]=te(i,a,s);return[c,l,u,e.length>3?e[3]:1]},ee=(e,t,n)=>{let{kE:r,kK:i,kKE:a,Xn:o,Yn:s,Zn:c}=D,l=(e+16)/116,u=.002*t+l,d=l-.005*n,f=u*u*u,p=d*d*d,m=f>r?f:(116*u-16)/i,h=e>a?((e+16)/116)**3:e/i,g=p>r?p:(116*d-16)/i;return[m*o,h*s,g*c]},M=e=>{let t=Math.sign(e);return e=Math.abs(e),(e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055)*t},te=(e,t,n)=>{let{MtxAdaptMa:r,MtxAdaptMaI:i,MtxXYZ2RGB:a,RefWhiteRGB:o,Xn:s,Yn:c,Zn:l}=D,u=s*r.m00+c*r.m10+l*r.m20,d=s*r.m01+c*r.m11+l*r.m21,f=s*r.m02+c*r.m12+l*r.m22,p=o.X*r.m00+o.Y*r.m10+o.Z*r.m20,m=o.X*r.m01+o.Y*r.m11+o.Z*r.m21,h=o.X*r.m02+o.Y*r.m12+o.Z*r.m22,g=(e*r.m00+t*r.m10+n*r.m20)*(p/u),_=(e*r.m01+t*r.m11+n*r.m21)*(m/d),v=(e*r.m02+t*r.m12+n*r.m22)*(h/f),y=g*i.m00+_*i.m10+v*i.m20,b=g*i.m01+_*i.m11+v*i.m21,x=g*i.m02+_*i.m12+v*i.m22,S=M(y*a.m00+b*a.m10+x*a.m20),C=M(y*a.m01+b*a.m11+x*a.m21),w=M(y*a.m02+b*a.m12+x*a.m22);return[S*255,C*255,w*255]},N=(...e)=>{let[t,n,r,...i]=o(e,`rgb`),[a,s,c]=ie(t,n,r),[l,u,d]=ne(a,s,c);return[l,u,d,...i.length>0&&i[0]<1?[i[0]]:[]]};function ne(e,t,n){let{Xn:r,Yn:i,Zn:a,kE:o,kK:s}=D,c=e/r,l=t/i,u=n/a,d=c>o?c**(1/3):(s*c+16)/116,f=l>o?l**(1/3):(s*l+16)/116,p=u>o?u**(1/3):(s*u+16)/116;return[116*f-16,500*(d-f),200*(f-p)]}function re(e){let t=Math.sign(e);return e=Math.abs(e),(e<=.04045?e/12.92:((e+.055)/1.055)**2.4)*t}const ie=(e,t,n)=>{e=re(e/255),t=re(t/255),n=re(n/255);let{MtxRGB2XYZ:r,MtxAdaptMa:i,MtxAdaptMaI:a,Xn:o,Yn:s,Zn:c,As:l,Bs:u,Cs:d}=D,f=e*r.m00+t*r.m10+n*r.m20,p=e*r.m01+t*r.m11+n*r.m21,m=e*r.m02+t*r.m12+n*r.m22,h=o*i.m00+s*i.m10+c*i.m20,g=o*i.m01+s*i.m11+c*i.m21,_=o*i.m02+s*i.m12+c*i.m22,v=f*i.m00+p*i.m10+m*i.m20,y=f*i.m01+p*i.m11+m*i.m21,b=f*i.m02+p*i.m12+m*i.m22;return v*=h/l,y*=g/u,b*=_/d,f=v*a.m00+y*a.m10+b*a.m20,p=v*a.m01+y*a.m11+b*a.m21,m=v*a.m02+y*a.m12+b*a.m22,[f,p,m]};y.prototype.lab=function(){return N(this._rgb)};const ae=(...e)=>new y(...e,`lab`);Object.assign(b,{lab:ae,getLabWhitePoint:A,setLabWhitePoint:k}),v.format.lab=j,v.autodetect.push({p:2,test:(...e)=>{if(e=o(e,`lab`),a(e)===`array`&&e.length===3)return`lab`}}),y.prototype.darken=function(e=1){let t=this,n=t.lab();return n[0]-=D.Kn*e,new y(n,`lab`).alpha(t.alpha(),!0)},y.prototype.brighten=function(e=1){return this.darken(-e)},y.prototype.darker=y.prototype.darken,y.prototype.brighter=y.prototype.brighten,y.prototype.get=function(e){let[t,n]=e.split(`.`),r=this[t]();if(n){let e=t.indexOf(n)-(t.substr(0,2)===`ok`?2:0);if(e>-1)return r[e];throw Error(`unknown channel ${n} in mode ${t}`)}else return r};const{pow:oe}=Math;y.prototype.luminance=function(e,t=`rgb`){if(e!==void 0&&a(e)===`number`){if(e===0)return new y([0,0,0,this._rgb[3]],`rgb`);if(e===1)return new y([255,255,255,this._rgb[3]],`rgb`);let n=this.luminance(),r=20,i=(n,a)=>{let o=n.interpolate(a,.5,t),s=o.luminance();return Math.abs(e-s)<1e-7||!r--?o:s>e?i(n,o):i(o,a)};return new y([...(n>e?i(new y([0,0,0]),this):i(this,new y([255,255,255]))).rgb(),this._rgb[3]])}return se(...this._rgb.slice(0,3))};const se=(e,t,n)=>(e=ce(e),t=ce(t),n=ce(n),.2126*e+.7152*t+.0722*n),ce=e=>(e/=255,e<=.03928?e/12.92:oe((e+.055)/1.055,2.4));var P={},F=(e,t,n=.5,...r)=>{let i=r[0]||`lrgb`;if(!P[i]&&!r.length&&(i=Object.keys(P)[0]),!P[i])throw Error(`interpolation mode ${i} is not defined`);return a(e)!==`object`&&(e=new y(e)),a(t)!==`object`&&(t=new y(t)),P[i](e,t,n).alpha(e.alpha()+n*(t.alpha()-e.alpha()))};y.prototype.mix=y.prototype.interpolate=function(e,t=.5,...n){return F(this,e,t,...n)},y.prototype.premultiply=function(e=!1){let t=this._rgb,n=t[3];return e?(this._rgb=[t[0]*n,t[1]*n,t[2]*n,n],this):new y([t[0]*n,t[1]*n,t[2]*n,n],`rgb`)};const{sin:le,cos:ue}=Math,de=(...e)=>{let[t,n,r]=o(e,`lch`);return isNaN(r)&&(r=0),r*=h,[t,ue(r)*n,le(r)*n]},fe=(...e)=>{e=o(e,`lch`);let[t,n,r]=e,[i,a,s]=de(t,n,r),[c,l,u]=j(i,a,s);return[c,l,u,e.length>3?e[3]:1]},pe=(...e)=>fe(..._(o(e,`hcl`))),{sqrt:me,atan2:he,round:ge}=Math,_e=(...e)=>{let[t,n,r]=o(e,`lab`),i=me(n*n+r*r),a=(he(r,n)*g+360)%360;return ge(i*1e4)===0&&(a=NaN),[t,i,a]},ve=(...e)=>{let[t,n,r,...i]=o(e,`rgb`),[a,s,c]=N(t,n,r),[l,u,d]=_e(a,s,c);return[l,u,d,...i.length>0&&i[0]<1?[i[0]]:[]]};y.prototype.lch=function(){return ve(this._rgb)},y.prototype.hcl=function(){return _(ve(this._rgb))};const ye=(...e)=>new y(...e,`lch`),be=(...e)=>new y(...e,`hcl`);Object.assign(b,{lch:ye,hcl:be}),v.format.lch=fe,v.format.hcl=pe,[`lch`,`hcl`].forEach(e=>v.autodetect.push({p:2,test:(...t)=>{if(t=o(t,e),a(t)===`array`&&t.length===3)return e}})),y.prototype.saturate=function(e=1){let t=this,n=t.lch();return n[1]+=D.Kn*e,n[1]<0&&(n[1]=0),new y(n,`lch`).alpha(t.alpha(),!0)},y.prototype.desaturate=function(e=1){return this.saturate(-e)},y.prototype.set=function(e,t,n=!1){let[r,i]=e.split(`.`),o=this[r]();if(i){let e=r.indexOf(i)-(r.substr(0,2)===`ok`?2:0);if(e>-1){if(a(t)==`string`)switch(t.charAt(0)){case`+`:o[e]+=+t;break;case`-`:o[e]+=+t;break;case`*`:o[e]*=+t.substr(1);break;case`/`:o[e]/=+t.substr(1);break;default:o[e]=+t}else if(a(t)===`number`)o[e]=t;else throw Error(`unsupported value for Color.set`);let i=new y(o,r);return n?(this._rgb=i._rgb,this):i}throw Error(`unknown channel ${i} in mode ${r}`)}else return o},y.prototype.tint=function(e=.5,...t){return F(this,`white`,e,...t)},y.prototype.shade=function(e=.5,...t){return F(this,`black`,e,...t)};const xe=(e,t,n)=>{let r=e._rgb,i=t._rgb;return new y(r[0]+n*(i[0]-r[0]),r[1]+n*(i[1]-r[1]),r[2]+n*(i[2]-r[2]),`rgb`)};P.rgb=xe;const{sqrt:Se,pow:I}=Math,Ce=(e,t,n)=>{let[r,i,a]=e._rgb,[o,s,c]=t._rgb;return new y(Se(I(r,2)*(1-n)+I(o,2)*n),Se(I(i,2)*(1-n)+I(s,2)*n),Se(I(a,2)*(1-n)+I(c,2)*n),`rgb`)};P.lrgb=Ce;const we=(e,t,n)=>{let r=e.lab(),i=t.lab();return new y(r[0]+n*(i[0]-r[0]),r[1]+n*(i[1]-r[1]),r[2]+n*(i[2]-r[2]),`lab`)};P.lab=we;var L=(e,t,n,r)=>{let i,a;r===`hsl`?(i=e.hsl(),a=t.hsl()):r===`hsv`?(i=e.hsv(),a=t.hsv()):r===`hcg`?(i=e.hcg(),a=t.hcg()):r===`hsi`?(i=e.hsi(),a=t.hsi()):r===`lch`||r===`hcl`?(r=`hcl`,i=e.hcl(),a=t.hcl()):r===`oklch`&&(i=e.oklch().reverse(),a=t.oklch().reverse());let o,s,c,l,u,d;(r.substr(0,1)===`h`||r===`oklch`)&&([o,c,u]=i,[s,l,d]=a);let f,p,m,h;return!isNaN(o)&&!isNaN(s)?(h=s>o&&s-o>180?s-(o+360):s<o&&o-s>180?s+360-o:s-o,p=o+n*h):isNaN(o)?isNaN(s)?p=NaN:(p=s,(u==1||u==0)&&r!=`hsv`&&(f=l)):(p=o,(d==1||d==0)&&r!=`hsv`&&(f=c)),f===void 0&&(f=c+n*(l-c)),m=u+n*(d-u),r===`oklch`?new y([m,f,p],r):new y([p,f,m],r)};const Te=(e,t,n)=>L(e,t,n,`lch`);P.lch=Te,P.hcl=Te;const Ee=e=>{if(a(e)==`number`&&e>=0&&e<=16777215)return[e>>16,e>>8&255,e&255,1];throw Error(`unknown num color: `+e)},De=(...e)=>{let[t,n,r]=o(e,`rgb`);return(t<<16)+(n<<8)+r};y.prototype.num=function(){return De(this._rgb)};const Oe=(...e)=>new y(...e,`num`);Object.assign(b,{num:Oe}),v.format.num=Ee,v.autodetect.push({p:5,test:(...e)=>{if(e.length===1&&a(e[0])===`number`&&e[0]>=0&&e[0]<=16777215)return`num`}});const ke=(e,t,n)=>{let r=e.num();return new y(r+n*(t.num()-r),`num`)};P.num=ke;const{floor:Ae}=Math,je=(...e)=>{e=o(e,`hcg`);let[t,n,r]=e,i,a,s;r*=255;let c=n*255;if(n===0)i=a=s=r;else{t===360&&(t=0),t>360&&(t-=360),t<0&&(t+=360),t/=60;let e=Ae(t),o=t-e,l=r*(1-n),u=l+c*(1-o),d=l+c*o,f=l+c;switch(e){case 0:[i,a,s]=[f,d,l];break;case 1:[i,a,s]=[u,f,l];break;case 2:[i,a,s]=[l,f,d];break;case 3:[i,a,s]=[l,u,f];break;case 4:[i,a,s]=[d,l,f];break;case 5:[i,a,s]=[f,l,u];break}}return[i,a,s,e.length>3?e[3]:1]},Me=(...e)=>{let[t,n,r]=o(e,`rgb`),i=l(t,n,r),a=u(t,n,r),s=a-i,c=s*100/255,d=i/(255-s)*100,f;return s===0?f=NaN:(t===a&&(f=(n-r)/s),n===a&&(f=2+(r-t)/s),r===a&&(f=4+(t-n)/s),f*=60,f<0&&(f+=360)),[f,c,d]};y.prototype.hcg=function(){return Me(this._rgb)};const Ne=(...e)=>new y(...e,`hcg`);b.hcg=Ne,v.format.hcg=je,v.autodetect.push({p:1,test:(...e)=>{if(e=o(e,`hcg`),a(e)===`array`&&e.length===3)return`hcg`}});const Pe=(e,t,n)=>L(e,t,n,`hcg`);P.hcg=Pe;const{cos:R}=Math,Fe=(...e)=>{e=o(e,`hsi`);let[t,r,i]=e,a,s,c;return isNaN(t)&&(t=0),isNaN(r)&&(r=0),t>360&&(t-=360),t<0&&(t+=360),t/=360,t<1/3?(c=(1-r)/3,a=(1+r*R(p*t)/R(m-p*t))/3,s=1-(c+a)):t<2/3?(t-=1/3,a=(1-r)/3,s=(1+r*R(p*t)/R(m-p*t))/3,c=1-(a+s)):(t-=2/3,s=(1-r)/3,c=(1+r*R(p*t)/R(m-p*t))/3,a=1-(s+c)),a=n(i*a*3),s=n(i*s*3),c=n(i*c*3),[a*255,s*255,c*255,e.length>3?e[3]:1]},{min:Ie,sqrt:Le,acos:Re}=Math,ze=(...e)=>{let[t,n,r]=o(e,`rgb`);t/=255,n/=255,r/=255;let i,a=Ie(t,n,r),s=(t+n+r)/3,c=s>0?1-a/s:0;return c===0?i=NaN:(i=(t-n+(t-r))/2,i/=Le((t-n)*(t-n)+(t-r)*(n-r)),i=Re(i),r>n&&(i=p-i),i/=p),[i*360,c,s]};y.prototype.hsi=function(){return ze(this._rgb)};const Be=(...e)=>new y(...e,`hsi`);b.hsi=Be,v.format.hsi=Fe,v.autodetect.push({p:2,test:(...e)=>{if(e=o(e,`hsi`),a(e)===`array`&&e.length===3)return`hsi`}});const Ve=(e,t,n)=>L(e,t,n,`hsi`);P.hsi=Ve;const He=(...e)=>{e=o(e,`hsl`);let[t,n,r]=e,i,a,s;if(n===0)i=a=s=r*255;else{let e=[0,0,0],o=[0,0,0],c=r<.5?r*(1+n):r+n-r*n,l=2*r-c,u=t/360;e[0]=u+1/3,e[1]=u,e[2]=u-1/3;for(let t=0;t<3;t++)e[t]<0&&(e[t]+=1),e[t]>1&&--e[t],6*e[t]<1?o[t]=l+(c-l)*6*e[t]:2*e[t]<1?o[t]=c:3*e[t]<2?o[t]=l+(c-l)*(2/3-e[t])*6:o[t]=l;[i,a,s]=[o[0]*255,o[1]*255,o[2]*255]}return e.length>3?[i,a,s,e[3]]:[i,a,s,1]},Ue=(...e)=>{e=o(e,`rgba`);let[t,n,r]=e;t/=255,n/=255,r/=255;let i=l(t,n,r),a=u(t,n,r),s=(a+i)/2,c,d;return a===i?(c=0,d=NaN):c=s<.5?(a-i)/(a+i):(a-i)/(2-a-i),t==a?d=(n-r)/(a-i):n==a?d=2+(r-t)/(a-i):r==a&&(d=4+(t-n)/(a-i)),d*=60,d<0&&(d+=360),e.length>3&&e[3]!==void 0?[d,c,s,e[3]]:[d,c,s]};y.prototype.hsl=function(){return Ue(this._rgb)};const We=(...e)=>new y(...e,`hsl`);b.hsl=We,v.format.hsl=He,v.autodetect.push({p:2,test:(...e)=>{if(e=o(e,`hsl`),a(e)===`array`&&e.length===3)return`hsl`}});const Ge=(e,t,n)=>L(e,t,n,`hsl`);P.hsl=Ge;const{floor:Ke}=Math,qe=(...e)=>{e=o(e,`hsv`);let[t,n,r]=e,i,a,s;if(r*=255,n===0)i=a=s=r;else{t===360&&(t=0),t>360&&(t-=360),t<0&&(t+=360),t/=60;let e=Ke(t),o=t-e,c=r*(1-n),l=r*(1-n*o),u=r*(1-n*(1-o));switch(e){case 0:[i,a,s]=[r,u,c];break;case 1:[i,a,s]=[l,r,c];break;case 2:[i,a,s]=[c,r,u];break;case 3:[i,a,s]=[c,l,r];break;case 4:[i,a,s]=[u,c,r];break;case 5:[i,a,s]=[r,c,l];break}}return[i,a,s,e.length>3?e[3]:1]},{min:Je,max:Ye}=Math,Xe=(...e)=>{e=o(e,`rgb`);let[t,n,r]=e,i=Je(t,n,r),a=Ye(t,n,r),s=a-i,c,l,u;return u=a/255,a===0?(c=NaN,l=0):(l=s/a,t===a&&(c=(n-r)/s),n===a&&(c=2+(r-t)/s),r===a&&(c=4+(t-n)/s),c*=60,c<0&&(c+=360)),[c,l,u]};y.prototype.hsv=function(){return Xe(this._rgb)};const Ze=(...e)=>new y(...e,`hsv`);b.hsv=Ze,v.format.hsv=qe,v.autodetect.push({p:2,test:(...e)=>{if(e=o(e,`hsv`),a(e)===`array`&&e.length===3)return`hsv`}});const Qe=(e,t,n)=>L(e,t,n,`hsv`);P.hsv=Qe;function $e(e,t){let n=e.length;Array.isArray(e[0])||(e=[e]),Array.isArray(t[0])||(t=t.map(e=>[e]));let r=t[0].length,i=t[0].map((e,n)=>t.map(e=>e[n])),a=e.map(e=>i.map(t=>Array.isArray(e)?e.reduce((e,n,r)=>e+n*(t[r]||0),0):t.reduce((t,n)=>t+n*e,0)));return n===1&&(a=a[0]),r===1?a.map(e=>e[0]):a}const et=(...e)=>{e=o(e,`lab`);let[t,n,r,...i]=e,[a,s,c]=tt([t,n,r]),[l,u,d]=te(a,s,c);return[l,u,d,...i.length>0&&i[0]<1?[i[0]]:[]]};function tt(e){return $e([[1.2268798758459243,-.5578149944602171,.2813910456659647],[-.0405757452148008,1.112286803280317,-.0717110580655164],[-.0763729366746601,-.4214933324022432,1.5869240198367816]],$e([[1,.3963377773761749,.2158037573099136],[1,-.1055613458156586,-.0638541728258133],[1,-.0894841775298119,-1.2914855480194092]],e).map(e=>e**3))}const nt=(...e)=>{let[t,n,r,...i]=o(e,`rgb`);return[...rt(ie(t,n,r)),...i.length>0&&i[0]<1?[i[0]]:[]]};function rt(e){return $e([[.210454268309314,.7936177747023054,-.0040720430116193],[1.9779985324311684,-2.42859224204858,.450593709617411],[.0259040424655478,.7827717124575296,-.8086757549230774]],$e([[.819022437996703,.3619062600528904,-.1288737815209879],[.0329836539323885,.9292868615863434,.0361446663506424],[.0481771893596242,.2642395317527308,.6335478284694309]],e).map(e=>Math.cbrt(e)))}y.prototype.oklab=function(){return nt(this._rgb)};const it=(...e)=>new y(...e,`oklab`);Object.assign(b,{oklab:it}),v.format.oklab=et,v.autodetect.push({p:2,test:(...e)=>{if(e=o(e,`oklab`),a(e)===`array`&&e.length===3)return`oklab`}});const at=(e,t,n)=>{let r=e.oklab(),i=t.oklab();return new y(r[0]+n*(i[0]-r[0]),r[1]+n*(i[1]-r[1]),r[2]+n*(i[2]-r[2]),`oklab`)};P.oklab=at;const ot=(e,t,n)=>L(e,t,n,`oklch`);P.oklch=ot;const{pow:st,sqrt:ct,PI:lt,cos:ut,sin:dt,atan2:ft}=Math;var pt=(e,t=`lrgb`,n=null)=>{let r=e.length;n||=Array.from(Array(r)).map(()=>1);let i=r/n.reduce(function(e,t){return e+t});if(n.forEach((e,t)=>{n[t]*=i}),e=e.map(e=>new y(e)),t===`lrgb`)return mt(e,n);let a=e.shift(),o=a.get(t),s=[],c=0,l=0;for(let e=0;e<o.length;e++)if(o[e]=(o[e]||0)*n[0],s.push(isNaN(o[e])?0:n[0]),t.charAt(e)===`h`&&!isNaN(o[e])){let t=o[e]/180*lt;c+=ut(t)*n[0],l+=dt(t)*n[0]}let u=a.alpha()*n[0];e.forEach((e,r)=>{let i=e.get(t);u+=e.alpha()*n[r+1];for(let e=0;e<o.length;e++)if(!isNaN(i[e]))if(s[e]+=n[r+1],t.charAt(e)===`h`){let t=i[e]/180*lt;c+=ut(t)*n[r+1],l+=dt(t)*n[r+1]}else o[e]+=i[e]*n[r+1]});for(let e=0;e<o.length;e++)if(t.charAt(e)===`h`){let t=ft(l/s[e],c/s[e])/lt*180;for(;t<0;)t+=360;for(;t>=360;)t-=360;o[e]=t}else o[e]=o[e]/s[e];return u/=r,new y(o,t).alpha(u>.99999?1:u,!0)};const mt=(e,t)=>{let n=e.length,i=[0,0,0,0];for(let r=0;r<e.length;r++){let a=e[r],o=t[r]/n,s=a._rgb;i[0]+=st(s[0],2)*o,i[1]+=st(s[1],2)*o,i[2]+=st(s[2],2)*o,i[3]+=s[3]*o}return i[0]=ct(i[0]),i[1]=ct(i[1]),i[2]=ct(i[2]),i[3]>.9999999&&(i[3]=1),new y(r(i))},{pow:ht}=Math;function z(e){let t=`rgb`,r=b(`#ccc`),i=0,o=[0,1],s=[0,1],c=[],l=[0,0],u=!1,d=[],f=!1,p=0,m=1,h=!1,g={},_=!0,v=1,y=function(e){if(e||=[`#fff`,`#000`],e&&a(e)===`string`&&b.brewer&&b.brewer[e.toLowerCase()]&&(e=b.brewer[e.toLowerCase()]),a(e)===`array`){e.length===1&&(e=[e[0],e[0]]),e=e.slice(0);for(let t=0;t<e.length;t++)e[t]=b(e[t]);c.length=0;for(let t=0;t<e.length;t++)c.push(t/(e.length-1))}return T(),d=e},x=function(e){if(u!=null){let t=u.length-1,n=0;for(;n<t&&e>=u[n];)n++;return n-1}return 0},S=e=>e,C=e=>e,w=function(e,i){let o,s;if(i??=!1,isNaN(e)||e===null)return r;s=i?e:u&&u.length>2?x(e)/(u.length-2):m===p?1:(e-p)/(m-p),s=C(s),i||(s=S(s)),v!==1&&(s=ht(s,v)),s=l[0]+s*(1-l[0]-l[1]),s=n(s,0,1);let f=Math.floor(s*1e4);if(_&&g[f])o=g[f];else{if(a(d)===`array`)for(let e=0;e<c.length;e++){let n=c[e];if(s<=n){o=d[e];break}if(s>=n&&e===c.length-1){o=d[e];break}if(s>n&&s<c[e+1]){s=(s-n)/(c[e+1]-n),o=b.interpolate(d[e],d[e+1],s,t);break}}else a(d)===`function`&&(o=d(s));_&&(g[f]=o)}return o};var T=()=>g={};y(e);let E=function(e){let t=b(w(e));return f&&t[f]?t[f]():t};return E.classes=function(e){if(e!=null){if(a(e)===`array`)u=e,o=[e[0],e[e.length-1]];else{let t=b.analyze(o);u=e===0?[t.min,t.max]:b.limits(t,`e`,e)}return E}return u},E.domain=function(e){if(!arguments.length)return s;s=e.slice(0),p=e[0],m=e[e.length-1],c=[];let t=d.length;if(e.length===t&&p!==m)for(let t of Array.from(e))c.push((t-p)/(m-p));else{for(let e=0;e<t;e++)c.push(e/(t-1));if(e.length>2){let t=e.map((t,n)=>n/(e.length-1)),n=e.map(e=>(e-p)/(m-p));n.every((e,n)=>t[n]===e)||(C=e=>{if(e<=0||e>=1)return e;let r=0;for(;e>=n[r+1];)r++;let i=(e-n[r])/(n[r+1]-n[r]);return t[r]+i*(t[r+1]-t[r])})}}return o=[p,m],E},E.mode=function(e){return arguments.length?(t=e,T(),E):t},E.range=function(e,t){return y(e,t),E},E.out=function(e){return f=e,E},E.spread=function(e){return arguments.length?(i=e,E):i},E.correctLightness=function(e){return e??=!0,h=e,T(),S=h?function(e){let t=w(0,!0).lab()[0],n=w(1,!0).lab()[0],r=t>n,i=w(e,!0).lab()[0],a=t+(n-t)*e,o=i-a,s=0,c=1,l=20;for(;Math.abs(o)>.01&&l-- >0;)(function(){return r&&(o*=-1),o<0?(s=e,e+=(c-e)*.5):(c=e,e+=(s-e)*.5),i=w(e,!0).lab()[0],o=i-a})();return e}:e=>e,E},E.padding=function(e){return e==null?l:(a(e)===`number`&&(e=[e,e]),l=e,E)},E.colors=function(t,n){arguments.length<2&&(n=`hex`);let r=[];if(arguments.length===0)r=d.slice(0);else if(t===1)r=[E(.5)];else if(t>1){let e=o[0],n=o[1]-e;r=gt(0,t,!1).map(r=>E(e+r/(t-1)*n))}else{e=[];let t=[];if(u&&u.length>2)for(let e=1,n=u.length,r=1<=n;r?e<n:e>n;r?e++:e--)t.push((u[e-1]+u[e])*.5);else t=o;r=t.map(e=>E(e))}return b[n]&&(r=r.map(e=>e[n]())),r},E.cache=function(e){return e==null?_:(_=e,E)},E.gamma=function(e){return e==null?v:(v=e,E)},E.nodata=function(e){return e==null?r:(r=b(e),E)},E}function gt(e,t,n){let r=[],i=e<t,a=n?i?t+1:t-1:t;for(let t=e;i?t<a:t>a;i?t++:t--)r.push(t);return r}const _t=function(e){let t=[1,1];for(let n=1;n<e;n++){let e=[1];for(let n=1;n<=t.length;n++)e[n]=(t[n]||0)+t[n-1];t=e}return t},vt=function(e){let t,n,r,i;if(e=e.map(e=>new y(e)),e.length===2)[n,r]=e.map(e=>e.lab()),t=function(e){return new y([0,1,2].map(t=>n[t]+e*(r[t]-n[t])),`lab`)};else if(e.length===3)[n,r,i]=e.map(e=>e.lab()),t=function(e){return new y([0,1,2].map(t=>(1-e)*(1-e)*n[t]+2*(1-e)*e*r[t]+e*e*i[t]),`lab`)};else if(e.length===4){let a;[n,r,i,a]=e.map(e=>e.lab()),t=function(e){return new y([0,1,2].map(t=>(1-e)*(1-e)*(1-e)*n[t]+3*(1-e)*(1-e)*e*r[t]+3*(1-e)*e*e*i[t]+e*e*e*a[t]),`lab`)}}else if(e.length>=5){let n,r,i;n=e.map(e=>e.lab()),i=e.length-1,r=_t(i),t=function(e){let t=1-e;return new y([0,1,2].map(a=>n.reduce((n,o,s)=>n+r[s]*t**(i-s)*e**s*o[a],0)),`lab`)}}else throw RangeError(`No point in running bezier with only one color.`);return t};var yt=e=>{let t=vt(e);return t.scale=()=>z(t),t};const{round:bt}=Math;y.prototype.rgb=function(e=!0){return e===!1?this._rgb.slice(0,3):this._rgb.slice(0,3).map(bt)},y.prototype.rgba=function(e=!0){return this._rgb.slice(0,4).map((t,n)=>n<3?e===!1?t:bt(t):t)};const xt=(...e)=>new y(...e,`rgb`);Object.assign(b,{rgb:xt}),v.format.rgb=(...e)=>{let t=o(e,`rgba`);return t[3]===void 0&&(t[3]=1),t},v.autodetect.push({p:3,test:(...e)=>{if(e=o(e,`rgba`),a(e)===`array`&&(e.length===3||e.length===4&&a(e[3])==`number`&&e[3]>=0&&e[3]<=1))return`rgb`}});const B=(e,t,n)=>{if(!B[n])throw Error(`unknown blend mode `+n);return B[n](e,t)},V=e=>(t,n)=>{let r=b(n).rgb(),i=b(t).rgb();return b.rgb(e(r,i))},H=e=>(t,n)=>{let r=[];return r[0]=e(t[0],n[0]),r[1]=e(t[1],n[1]),r[2]=e(t[2],n[2]),r},St=e=>e,Ct=(e,t)=>e*t/255,wt=(e,t)=>e>t?t:e,Tt=(e,t)=>e>t?e:t,Et=(e,t)=>255*(1-(1-e/255)*(1-t/255)),Dt=(e,t)=>t<128?2*e*t/255:255*(1-2*(1-e/255)*(1-t/255)),Ot=(e,t)=>255*(1-(1-t/255)/(e/255)),kt=(e,t)=>e===255?255:(e=t/255*255/(1-e/255),e>255?255:e);B.normal=V(H(St)),B.multiply=V(H(Ct)),B.screen=V(H(Et)),B.overlay=V(H(Dt)),B.darken=V(H(wt)),B.lighten=V(H(Tt)),B.dodge=V(H(kt)),B.burn=V(H(Ot));const{pow:At,sin:jt,cos:Mt}=Math;function Nt(e=300,t=-1.5,n=1,i=1,o=[0,1]){let s=0,c;a(o)===`array`?c=o[1]-o[0]:(c=0,o=[o,o]);let l=function(a){let l=p*((e+120)/360+t*a),u=At(o[0]+c*a,i),d=(s===0?n:n[0]+a*s)*u*(1-u)/2,f=Mt(l),m=jt(l),h=u+d*(-.14861*f+1.78277*m),g=u+d*(-.29227*f-.90649*m),_=u+1.97294*f*d;return b(r([h*255,g*255,_*255,1]))};return l.start=function(t){return t==null?e:(e=t,l)},l.rotations=function(e){return e==null?t:(t=e,l)},l.gamma=function(e){return e==null?i:(i=e,l)},l.hue=function(e){return e==null?n:(n=e,a(n)===`array`?(s=n[1]-n[0],s===0&&(n=n[1])):s=0,l)},l.lightness=function(e){return e==null?o:(a(e)===`array`?(o=e,c=e[1]-e[0]):(o=[e,e],c=0),l)},l.scale=()=>b.scale(l),l.hue(n),l}const{floor:Pt,random:Ft}=Math;var It=(e=Ft)=>{let t=`#`;for(let n=0;n<6;n++)t+=`0123456789abcdef`.charAt(Pt(e()*16));return new y(t,`hex`)};const{log:Lt,pow:Rt,floor:zt,abs:Bt}=Math;function Vt(e,t=null){let n={min:Number.MAX_VALUE,max:Number.MAX_VALUE*-1,sum:0,values:[],count:0};return a(e)===`object`&&(e=Object.values(e)),e.forEach(e=>{t&&a(e)===`object`&&(e=e[t]),e!=null&&!isNaN(e)&&(n.values.push(e),n.sum+=e,e<n.min&&(n.min=e),e>n.max&&(n.max=e),n.count+=1)}),n.domain=[n.min,n.max],n.limits=(e,t)=>Ht(n,e,t),n}function Ht(e,t=`equal`,n=7){a(e)==`array`&&(e=Vt(e));let{min:r,max:i}=e,o=e.values.sort((e,t)=>e-t);if(n===1)return[r,i];let s=[];if(t.substr(0,1)===`c`&&(s.push(r),s.push(i)),t.substr(0,1)===`e`){s.push(r);for(let e=1;e<n;e++)s.push(r+e/n*(i-r));s.push(i)}else if(t.substr(0,1)===`l`){if(r<=0)throw Error(`Logarithmic scales are only possible for values > 0`);let e=Math.LOG10E*Lt(r),t=Math.LOG10E*Lt(i);s.push(r);for(let r=1;r<n;r++)s.push(Rt(10,e+r/n*(t-e)));s.push(i)}else if(t.substr(0,1)===`q`){s.push(r);for(let e=1;e<n;e++){let t=(o.length-1)*e/n,r=zt(t);if(r===t)s.push(o[r]);else{let e=t-r;s.push(o[r]*(1-e)+o[r+1]*e)}}s.push(i)}else if(t.substr(0,1)===`k`){let e,t=o.length,a=Array(t),c=Array(n),l=!0,u=0,d=null;d=[],d.push(r);for(let e=1;e<n;e++)d.push(r+e/n*(i-r));for(d.push(i);l;){for(let e=0;e<n;e++)c[e]=0;for(let e=0;e<t;e++){let t=o[e],r=Number.MAX_VALUE,i;for(let o=0;o<n;o++){let n=Bt(d[o]-t);n<r&&(r=n,i=o),c[i]++,a[e]=i}}let r=Array(n);for(let e=0;e<n;e++)r[e]=null;for(let n=0;n<t;n++)e=a[n],r[e]===null?r[e]=o[n]:r[e]+=o[n];for(let e=0;e<n;e++)r[e]*=1/c[e];l=!1;for(let e=0;e<n;e++)if(r[e]!==d[e]){l=!0;break}d=r,u++,u>200&&(l=!1)}let f={};for(let e=0;e<n;e++)f[e]=[];for(let n=0;n<t;n++)e=a[n],f[e].push(o[n]);let p=[];for(let e=0;e<n;e++)p.push(f[e][0]),p.push(f[e][f[e].length-1]);p=p.sort((e,t)=>e-t),s.push(p[0]);for(let e=1;e<p.length;e+=2){let t=p[e];!isNaN(t)&&s.indexOf(t)===-1&&s.push(t)}}return s}var Ut=(e,t)=>{e=new y(e),t=new y(t);let n=e.luminance(),r=t.luminance();return n>r?(n+.05)/(r+.05):(r+.05)/(n+.05)};
2
2
  /**
3
3
  * @license
4
4
  *
@@ -12,4 +12,4 @@ const{min:e,max:t}=Math;var n=(n,r=0,i=1)=>e(t(r,n),i),r=e=>{e._clipped=!1,e._un
12
12
  * You can read more about the APCA Readability Criterion at
13
13
  * https://readtech.org/ARC/
14
14
  */
15
- const Ut=.027,Wt=1.14,W=.022,Gt=1.414;var Kt=(e,t)=>{e=new y(e),t=new y(t),e.alpha()<1&&(e=F(t,e,e.alpha(),`rgb`));let n=qt(...e.rgb()),r=qt(...t.rgb()),i=n>=W?n:n+(W-n)**+Gt,a=r>=W?r:r+(W-r)**+Gt,o=a**.56-i**.57,s=a**.65-i**.62,c=Math.abs(a-i)<5e-4?0:i<a?o*Wt:s*Wt;return(Math.abs(c)<.1?0:c>0?c-Ut:c+Ut)*100};function qt(e,t,n){return .2126729*(e/255)**2.4+.7151522*(t/255)**2.4+.072175*(n/255)**2.4}const{sqrt:G,pow:K,min:Jt,max:Yt,atan2:Xt,abs:Zt,cos:q,sin:Qt,exp:$t,PI:en}=Math;function tn(e,t,n=1,r=1,i=1){var a=function(e){return 360*e/(2*en)},o=function(e){return 2*en*e/360};e=new y(e),t=new y(t);let[s,c,l]=Array.from(e.lab()),[u,d,f]=Array.from(t.lab()),p=(s+u)/2,m=(G(K(c,2)+K(l,2))+G(K(d,2)+K(f,2)))/2,h=.5*(1-G(K(m,7)/(K(m,7)+K(25,7)))),g=c*(1+h),_=d*(1+h),v=G(K(g,2)+K(l,2)),b=G(K(_,2)+K(f,2)),x=(v+b)/2,S=a(Xt(l,g)),C=a(Xt(f,_)),w=S>=0?S:S+360,T=C>=0?C:C+360,E=Zt(w-T)>180?(w+T+360)/2:(w+T)/2,D=1-.17*q(o(E-30))+.24*q(o(2*E))+.32*q(o(3*E+6))-.2*q(o(4*E-63)),O=T-w;O=Zt(O)<=180?O:T<=w?O+360:O-360,O=2*G(v*b)*Qt(o(O)/2);let k=u-s,A=b-v,j=1+.015*K(p-50,2)/G(20+K(p-50,2)),ee=1+.045*x,M=1+.015*x*D,te=30*$t(-K((E-275)/25,2)),N=-(2*G(K(x,7)/(K(x,7)+K(25,7))))*Qt(2*o(te));return Yt(0,Jt(100,G(K(k/(n*j),2)+K(A/(r*ee),2)+K(O/(i*M),2)+N*(A/(r*ee))*(O/(i*M)))))}function nn(e,t,n=`lab`){e=new y(e),t=new y(t);let r=e.get(n),i=t.get(n),a=0;for(let e in r){let t=(r[e]||0)-(i[e]||0);a+=t*t}return Math.sqrt(a)}var rn=(...e)=>{try{return new y(...e),!0}catch{return!1}},an={cool(){return B([b.hsl(180,1,.9),b.hsl(250,.7,.4)])},hot(){return B([`#000`,`#f00`,`#ff0`,`#fff`],[0,.25,.75,1]).mode(`rgb`)}};const on={OrRd:[`#fff7ec`,`#fee8c8`,`#fdd49e`,`#fdbb84`,`#fc8d59`,`#ef6548`,`#d7301f`,`#b30000`,`#7f0000`],PuBu:[`#fff7fb`,`#ece7f2`,`#d0d1e6`,`#a6bddb`,`#74a9cf`,`#3690c0`,`#0570b0`,`#045a8d`,`#023858`],BuPu:[`#f7fcfd`,`#e0ecf4`,`#bfd3e6`,`#9ebcda`,`#8c96c6`,`#8c6bb1`,`#88419d`,`#810f7c`,`#4d004b`],Oranges:[`#fff5eb`,`#fee6ce`,`#fdd0a2`,`#fdae6b`,`#fd8d3c`,`#f16913`,`#d94801`,`#a63603`,`#7f2704`],BuGn:[`#f7fcfd`,`#e5f5f9`,`#ccece6`,`#99d8c9`,`#66c2a4`,`#41ae76`,`#238b45`,`#006d2c`,`#00441b`],YlOrBr:[`#ffffe5`,`#fff7bc`,`#fee391`,`#fec44f`,`#fe9929`,`#ec7014`,`#cc4c02`,`#993404`,`#662506`],YlGn:[`#ffffe5`,`#f7fcb9`,`#d9f0a3`,`#addd8e`,`#78c679`,`#41ab5d`,`#238443`,`#006837`,`#004529`],Reds:[`#fff5f0`,`#fee0d2`,`#fcbba1`,`#fc9272`,`#fb6a4a`,`#ef3b2c`,`#cb181d`,`#a50f15`,`#67000d`],RdPu:[`#fff7f3`,`#fde0dd`,`#fcc5c0`,`#fa9fb5`,`#f768a1`,`#dd3497`,`#ae017e`,`#7a0177`,`#49006a`],Greens:[`#f7fcf5`,`#e5f5e0`,`#c7e9c0`,`#a1d99b`,`#74c476`,`#41ab5d`,`#238b45`,`#006d2c`,`#00441b`],YlGnBu:[`#ffffd9`,`#edf8b1`,`#c7e9b4`,`#7fcdbb`,`#41b6c4`,`#1d91c0`,`#225ea8`,`#253494`,`#081d58`],Purples:[`#fcfbfd`,`#efedf5`,`#dadaeb`,`#bcbddc`,`#9e9ac8`,`#807dba`,`#6a51a3`,`#54278f`,`#3f007d`],GnBu:[`#f7fcf0`,`#e0f3db`,`#ccebc5`,`#a8ddb5`,`#7bccc4`,`#4eb3d3`,`#2b8cbe`,`#0868ac`,`#084081`],Greys:[`#ffffff`,`#f0f0f0`,`#d9d9d9`,`#bdbdbd`,`#969696`,`#737373`,`#525252`,`#252525`,`#000000`],YlOrRd:[`#ffffcc`,`#ffeda0`,`#fed976`,`#feb24c`,`#fd8d3c`,`#fc4e2a`,`#e31a1c`,`#bd0026`,`#800026`],PuRd:[`#f7f4f9`,`#e7e1ef`,`#d4b9da`,`#c994c7`,`#df65b0`,`#e7298a`,`#ce1256`,`#980043`,`#67001f`],Blues:[`#f7fbff`,`#deebf7`,`#c6dbef`,`#9ecae1`,`#6baed6`,`#4292c6`,`#2171b5`,`#08519c`,`#08306b`],PuBuGn:[`#fff7fb`,`#ece2f0`,`#d0d1e6`,`#a6bddb`,`#67a9cf`,`#3690c0`,`#02818a`,`#016c59`,`#014636`],Viridis:[`#440154`,`#482777`,`#3f4a8a`,`#31678e`,`#26838f`,`#1f9d8a`,`#6cce5a`,`#b6de2b`,`#fee825`],Spectral:[`#9e0142`,`#d53e4f`,`#f46d43`,`#fdae61`,`#fee08b`,`#ffffbf`,`#e6f598`,`#abdda4`,`#66c2a5`,`#3288bd`,`#5e4fa2`],RdYlGn:[`#a50026`,`#d73027`,`#f46d43`,`#fdae61`,`#fee08b`,`#ffffbf`,`#d9ef8b`,`#a6d96a`,`#66bd63`,`#1a9850`,`#006837`],RdBu:[`#67001f`,`#b2182b`,`#d6604d`,`#f4a582`,`#fddbc7`,`#f7f7f7`,`#d1e5f0`,`#92c5de`,`#4393c3`,`#2166ac`,`#053061`],PiYG:[`#8e0152`,`#c51b7d`,`#de77ae`,`#f1b6da`,`#fde0ef`,`#f7f7f7`,`#e6f5d0`,`#b8e186`,`#7fbc41`,`#4d9221`,`#276419`],PRGn:[`#40004b`,`#762a83`,`#9970ab`,`#c2a5cf`,`#e7d4e8`,`#f7f7f7`,`#d9f0d3`,`#a6dba0`,`#5aae61`,`#1b7837`,`#00441b`],RdYlBu:[`#a50026`,`#d73027`,`#f46d43`,`#fdae61`,`#fee090`,`#ffffbf`,`#e0f3f8`,`#abd9e9`,`#74add1`,`#4575b4`,`#313695`],BrBG:[`#543005`,`#8c510a`,`#bf812d`,`#dfc27d`,`#f6e8c3`,`#f5f5f5`,`#c7eae5`,`#80cdc1`,`#35978f`,`#01665e`,`#003c30`],RdGy:[`#67001f`,`#b2182b`,`#d6604d`,`#f4a582`,`#fddbc7`,`#ffffff`,`#e0e0e0`,`#bababa`,`#878787`,`#4d4d4d`,`#1a1a1a`],PuOr:[`#7f3b08`,`#b35806`,`#e08214`,`#fdb863`,`#fee0b6`,`#f7f7f7`,`#d8daeb`,`#b2abd2`,`#8073ac`,`#542788`,`#2d004b`],Set2:[`#66c2a5`,`#fc8d62`,`#8da0cb`,`#e78ac3`,`#a6d854`,`#ffd92f`,`#e5c494`,`#b3b3b3`],Accent:[`#7fc97f`,`#beaed4`,`#fdc086`,`#ffff99`,`#386cb0`,`#f0027f`,`#bf5b17`,`#666666`],Set1:[`#e41a1c`,`#377eb8`,`#4daf4a`,`#984ea3`,`#ff7f00`,`#ffff33`,`#a65628`,`#f781bf`,`#999999`],Set3:[`#8dd3c7`,`#ffffb3`,`#bebada`,`#fb8072`,`#80b1d3`,`#fdb462`,`#b3de69`,`#fccde5`,`#d9d9d9`,`#bc80bd`,`#ccebc5`,`#ffed6f`],Dark2:[`#1b9e77`,`#d95f02`,`#7570b3`,`#e7298a`,`#66a61e`,`#e6ab02`,`#a6761d`,`#666666`],Paired:[`#a6cee3`,`#1f78b4`,`#b2df8a`,`#33a02c`,`#fb9a99`,`#e31a1c`,`#fdbf6f`,`#ff7f00`,`#cab2d6`,`#6a3d9a`,`#ffff99`,`#b15928`],Pastel2:[`#b3e2cd`,`#fdcdac`,`#cbd5e8`,`#f4cae4`,`#e6f5c9`,`#fff2ae`,`#f1e2cc`,`#cccccc`],Pastel1:[`#fbb4ae`,`#b3cde3`,`#ccebc5`,`#decbe4`,`#fed9a6`,`#ffffcc`,`#e5d8bd`,`#fddaec`,`#f2f2f2`]},sn=Object.keys(on),cn=new Map(sn.map(e=>[e.toLowerCase(),e])),ln=typeof Proxy==`function`?new Proxy(on,{get(e,t){let n=t.toLowerCase();if(cn.has(n))return e[cn.get(n)]},getOwnPropertyNames(){return Object.getOwnPropertyNames(sn)}}):on,un=(...e)=>{e=o(e,`cmyk`);let[t,n,r,i]=e,a=e.length>4?e[4]:1;return i===1?[0,0,0,a]:[t>=1?0:255*(1-t)*(1-i),n>=1?0:255*(1-n)*(1-i),r>=1?0:255*(1-r)*(1-i),a]},{max:dn}=Math,fn=(...e)=>{let[t,n,r]=o(e,`rgb`);t/=255,n/=255,r/=255;let i=1-dn(t,dn(n,r)),a=i<1?1/(1-i):0;return[(1-t-i)*a,(1-n-i)*a,(1-r-i)*a,i]};y.prototype.cmyk=function(){return fn(this._rgb)};const pn=(...e)=>new y(...e,`cmyk`);Object.assign(b,{cmyk:pn}),v.format.cmyk=un,v.autodetect.push({p:2,test:(...e)=>{if(e=o(e,`cmyk`),a(e)===`array`&&e.length===4)return`cmyk`}});const mn=(...e)=>{let t=o(e,`hsla`),n=s(e)||`lsa`;return t[0]=d(t[0]||0)+`deg`,t[1]=d(t[1]*100)+`%`,t[2]=d(t[2]*100)+`%`,n===`hsla`||t.length>3&&t[3]<1?(t[3]=`/ `+(t.length>3?t[3]:1),n=`hsla`):t.length=3,`${n.substr(0,3)}(${t.join(` `)})`},hn=(...e)=>{let t=o(e,`lab`),n=s(e)||`lab`;return t[0]=d(t[0])+`%`,t[1]=d(t[1]),t[2]=d(t[2]),n===`laba`||t.length>3&&t[3]<1?t[3]=`/ `+(t.length>3?t[3]:1):t.length=3,`lab(${t.join(` `)})`},gn=(...e)=>{let t=o(e,`lch`),n=s(e)||`lab`;return t[0]=d(t[0])+`%`,t[1]=d(t[1]),t[2]=isNaN(t[2])?`none`:d(t[2])+`deg`,n===`lcha`||t.length>3&&t[3]<1?t[3]=`/ `+(t.length>3?t[3]:1):t.length=3,`lch(${t.join(` `)})`},_n=(...e)=>{let t=o(e,`lab`);return t[0]=d(t[0]*100)+`%`,t[1]=f(t[1]),t[2]=f(t[2]),t.length>3&&t[3]<1?t[3]=`/ `+(t.length>3?t[3]:1):t.length=3,`oklab(${t.join(` `)})`},vn=(...e)=>{let[t,n,r,...i]=o(e,`rgb`),[a,s,c]=tt(t,n,r),[l,u,d]=_e(a,s,c);return[l,u,d,...i.length>0&&i[0]<1?[i[0]]:[]]},yn=(...e)=>{let t=o(e,`lch`);return t[0]=d(t[0]*100)+`%`,t[1]=f(t[1]),t[2]=isNaN(t[2])?`none`:d(t[2])+`deg`,t.length>3&&t[3]<1?t[3]=`/ `+(t.length>3?t[3]:1):t.length=3,`oklch(${t.join(` `)})`},{round:bn}=Math,xn=(...e)=>{let t=o(e,`rgba`),n=s(e)||`rgb`;if(n.substr(0,3)===`hsl`)return mn(Ue(t),n);if(n.substr(0,3)===`lab`){let e=A();k(`d50`);let r=hn(N(t),n);return k(e),r}if(n.substr(0,3)===`lch`){let e=A();k(`d50`);let r=gn(ve(t),n);return k(e),r}return n.substr(0,5)===`oklab`?_n(tt(t)):n.substr(0,5)===`oklch`?yn(vn(t)):(t[0]=bn(t[0]),t[1]=bn(t[1]),t[2]=bn(t[2]),(n===`rgba`||t.length>3&&t[3]<1)&&(t[3]=`/ `+(t.length>3?t[3]:1),n=`rgba`),`${n.substr(0,3)}(${t.slice(0,n===`rgb`?3:4).join(` `)})`)},Sn=(...e)=>{e=o(e,`lch`);let[t,n,r,...i]=e,[a,s,c]=de(t,n,r),[l,u,d]=$e(a,s,c);return[l,u,d,...i.length>0&&i[0]<1?[i[0]]:[]]},J=`((?:-?\\d+)|(?:-?\\d+(?:\\.\\d+)?)%|none)`,Y=`((?:-?(?:\\d+(?:\\.\\d*)?|\\.\\d+)%?)|none)`,Cn=`((?:-?(?:\\d+(?:\\.\\d*)?|\\.\\d+)%)|none)`,wn=`\\s*,\\s*`,Tn=`((?:-?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:deg)?)|none)`,X=`\\s*(?:\\/\\s*((?:[01]|[01]?\\.\\d+)|\\d+(?:\\.\\d+)?%))?`,En=RegExp(`^rgba?\\(\\s*`+[J,J,J].join(`\\s+`)+X+`\\)$`),Dn=RegExp(`^rgb\\(\\s*`+[J,J,J].join(wn)+`\\s*\\)$`),On=RegExp(`^rgba\\(\\s*`+[J,J,J,Y].join(wn)+`\\s*\\)$`),kn=RegExp(`^hsla?\\(\\s*`+[Tn,Cn,Cn].join(`\\s+`)+X+`\\)$`),An=RegExp(`^hsl?\\(\\s*`+[Tn,Cn,Cn].join(wn)+`\\s*\\)$`),jn=/^hsla\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/,Mn=RegExp(`^lab\\(\\s*`+[Y,Y,Y].join(`\\s+`)+X+`\\)$`),Nn=RegExp(`^lch\\(\\s*`+[Y,Y,Tn].join(`\\s+`)+X+`\\)$`),Pn=RegExp(`^oklab\\(\\s*`+[Y,Y,Y].join(`\\s+`)+X+`\\)$`),Fn=RegExp(`^oklch\\(\\s*`+[Y,Y,Tn].join(`\\s+`)+X+`\\)$`),{round:In}=Math,Z=e=>e.map((e,t)=>t<=2?n(In(e),0,255):e),Q=(e,t=0,n=100,r=!1)=>(typeof e==`string`&&e.endsWith(`%`)&&(e=parseFloat(e.substring(0,e.length-1))/100,e=r?t+(e+1)*.5*(n-t):t+e*(n-t)),+e),$=(e,t)=>e===`none`?t:e,Ln=e=>{if(e=e.toLowerCase().trim(),e===`transparent`)return[0,0,0,0];let t;if(v.format.named)try{return v.format.named(e)}catch{}if((t=e.match(En))||(t=e.match(Dn))){let e=t.slice(1,4);for(let t=0;t<3;t++)e[t]=+Q($(e[t],0),0,255);e=Z(e);let n=t[4]===void 0?1:+Q(t[4],0,1);return e[3]=n,e}if(t=e.match(On)){let e=t.slice(1,5);for(let t=0;t<4;t++)e[t]=+Q(e[t],0,255);return e}if((t=e.match(kn))||(t=e.match(An))){let e=t.slice(1,4);e[0]=+$(e[0].replace(`deg`,``),0),e[1]=Q($(e[1],0),0,100)*.01,e[2]=Q($(e[2],0),0,100)*.01;let n=Z(He(e));return n[3]=t[4]===void 0?1:+Q(t[4],0,1),n}if(t=e.match(jn)){let e=t.slice(1,4);e[1]*=.01,e[2]*=.01;let n=He(e);for(let e=0;e<3;e++)n[e]=In(n[e]);return n[3]=+t[4],n}if(t=e.match(Mn)){let e=t.slice(1,4);e[0]=Q($(e[0],0),0,100),e[1]=Q($(e[1],0),-125,125,!0),e[2]=Q($(e[2],0),-125,125,!0);let n=A();k(`d50`);let r=Z(j(e));return k(n),r[3]=t[4]===void 0?1:+Q(t[4],0,1),r}if(t=e.match(Nn)){let e=t.slice(1,4);e[0]=Q(e[0],0,100),e[1]=Q($(e[1],0),0,150,!1),e[2]=+$(e[2].replace(`deg`,``),0);let n=A();k(`d50`);let r=Z(fe(e));return k(n),r[3]=t[4]===void 0?1:+Q(t[4],0,1),r}if(t=e.match(Pn)){let e=t.slice(1,4);e[0]=Q($(e[0],0),0,1),e[1]=Q($(e[1],0),-.4,.4,!0),e[2]=Q($(e[2],0),-.4,.4,!0);let n=Z($e(e));return n[3]=t[4]===void 0?1:+Q(t[4],0,1),n}if(t=e.match(Fn)){let e=t.slice(1,4);e[0]=Q($(e[0],0),0,1),e[1]=Q($(e[1],0),0,.4,!1),e[2]=+$(e[2].replace(`deg`,``),0);let n=Z(Sn(e));return n[3]=t[4]===void 0?1:+Q(t[4],0,1),n}};Ln.test=e=>En.test(e)||kn.test(e)||Mn.test(e)||Nn.test(e)||Pn.test(e)||Fn.test(e)||Dn.test(e)||On.test(e)||An.test(e)||jn.test(e)||e===`transparent`,y.prototype.css=function(e){return xn(this._rgb,e)};const Rn=(...e)=>new y(...e,`css`);b.css=Rn,v.format.css=Ln,v.autodetect.push({p:5,test:(e,...t)=>{if(!t.length&&a(e)===`string`&&Ln.test(e))return`css`}}),v.format.gl=(...e)=>{let t=o(e,`rgba`);return t[0]*=255,t[1]*=255,t[2]*=255,t};const zn=(...e)=>new y(...e,`gl`);b.gl=zn,y.prototype.gl=function(){let e=this._rgb;return[e[0]/255,e[1]/255,e[2]/255,e[3]]},y.prototype.hex=function(e){return E(this._rgb,e)};const Bn=(...e)=>new y(...e,`hex`);b.hex=Bn,v.format.hex=w,v.autodetect.push({p:4,test:(e,...t)=>{if(!t.length&&a(e)===`string`&&[3,4,5,6,7,8,9].indexOf(e.length)>=0)return`hex`}});const{log:Vn}=Math,Hn=e=>{let t=e/100,n,r,i;return t<66?(n=255,r=t<6?0:-155.25485562709179-.44596950469579133*(r=t-2)+104.49216199393888*Vn(r),i=t<20?0:-254.76935184120902+.8274096064007395*(i=t-10)+115.67994401066147*Vn(i)):(n=351.97690566805693+.114206453784165*(n=t-55)-40.25366309332127*Vn(n),r=325.4494125711974+.07943456536662342*(r=t-50)-28.0852963507957*Vn(r),i=255),[n,r,i,1]},{round:Un}=Math,Wn=(...e)=>{let t=o(e,`rgb`),n=t[0],r=t[2],i=1e3,a=4e4,s;for(;a-i>.4;){s=(a+i)*.5;let e=Hn(s);e[2]/e[0]>=r/n?a=s:i=s}return Un(s)};y.prototype.temp=y.prototype.kelvin=y.prototype.temperature=function(){return Wn(this._rgb)};const Gn=(...e)=>new y(...e,`temp`);Object.assign(b,{temp:Gn,kelvin:Gn,temperature:Gn}),v.format.temp=v.format.kelvin=v.format.temperature=Hn,y.prototype.oklch=function(){return vn(this._rgb)};const Kn=(...e)=>new y(...e,`oklch`);Object.assign(b,{oklch:Kn}),v.format.oklch=Sn,v.autodetect.push({p:2,test:(...e)=>{if(e=o(e,`oklch`),a(e)===`array`&&e.length===3)return`oklch`}}),Object.assign(b,{analyze:Bt,average:ft,bezier:vt,blend:V,brewer:ln,Color:y,colors:x,contrast:Ht,contrastAPCA:Kt,cubehelix:Mt,deltaE:tn,distance:nn,input:v,interpolate:F,limits:Vt,mix:F,random:Ft,scale:B,scales:an,valid:rn});var qn=b;const Jn=[.96,.907,.805,.697,.605,.547,.518,.445,.395,.34],Yn=[.32,.16,.08,.04,0,0,.04,.08,.16,.32];function Xn(e){let t=e.get(`hsl.l`);return Jn.reduce((e,n)=>Math.abs(n-t)<Math.abs(e-t)?n:e)}function Zn(e){let t=qn(e),n=Xn(t),r=Jn.findIndex(e=>e===n),i=Jn.map(e=>t.set(`hsl.l`,e)).map(e=>qn(e)).map((e,t)=>{let n=Yn[t]-Yn[r];return n>=0?e.saturate(n):e.desaturate(n*-1)});return i[r]=qn(e),{baseColorIndex:r,colors:i}}function Qn(e){return Zn(e).colors.map(e=>e.hex())}export{qn as n,Qn as t};
15
+ const Wt=.027,Gt=1.14,U=.022,Kt=1.414;var qt=(e,t)=>{e=new y(e),t=new y(t),e.alpha()<1&&(e=F(t,e,e.alpha(),`rgb`));let n=Jt(...e.rgb()),r=Jt(...t.rgb()),i=n>=U?n:n+(U-n)**+Kt,a=r>=U?r:r+(U-r)**+Kt,o=a**.56-i**.57,s=a**.65-i**.62,c=Math.abs(a-i)<5e-4?0:i<a?o*Gt:s*Gt;return(Math.abs(c)<.1?0:c>0?c-Wt:c+Wt)*100};function Jt(e,t,n){return .2126729*(e/255)**2.4+.7151522*(t/255)**2.4+.072175*(n/255)**2.4}const{sqrt:W,pow:G,min:Yt,max:Xt,atan2:Zt,abs:Qt,cos:K,sin:$t,exp:en,PI:tn}=Math;function nn(e,t,n=1,r=1,i=1){var a=function(e){return 360*e/(2*tn)},o=function(e){return 2*tn*e/360};e=new y(e),t=new y(t);let[s,c,l]=Array.from(e.lab()),[u,d,f]=Array.from(t.lab()),p=(s+u)/2,m=(W(G(c,2)+G(l,2))+W(G(d,2)+G(f,2)))/2,h=.5*(1-W(G(m,7)/(G(m,7)+G(25,7)))),g=c*(1+h),_=d*(1+h),v=W(G(g,2)+G(l,2)),b=W(G(_,2)+G(f,2)),x=(v+b)/2,S=a(Zt(l,g)),C=a(Zt(f,_)),w=S>=0?S:S+360,T=C>=0?C:C+360,E=Qt(w-T)>180?(w+T+360)/2:(w+T)/2,D=1-.17*K(o(E-30))+.24*K(o(2*E))+.32*K(o(3*E+6))-.2*K(o(4*E-63)),O=T-w;O=Qt(O)<=180?O:T<=w?O+360:O-360,O=2*W(v*b)*$t(o(O)/2);let k=u-s,A=b-v,j=1+.015*G(p-50,2)/W(20+G(p-50,2)),ee=1+.045*x,M=1+.015*x*D,te=30*en(-G((E-275)/25,2)),N=-(2*W(G(x,7)/(G(x,7)+G(25,7))))*$t(2*o(te));return Xt(0,Yt(100,W(G(k/(n*j),2)+G(A/(r*ee),2)+G(O/(i*M),2)+N*(A/(r*ee))*(O/(i*M)))))}function rn(e,t,n=`lab`){e=new y(e),t=new y(t);let r=e.get(n),i=t.get(n),a=0;for(let e in r){let t=(r[e]||0)-(i[e]||0);a+=t*t}return Math.sqrt(a)}var an=(...e)=>{try{return new y(...e),!0}catch{return!1}},on={cool(){return z([b.hsl(180,1,.9),b.hsl(250,.7,.4)])},hot(){return z([`#000`,`#f00`,`#ff0`,`#fff`],[0,.25,.75,1]).mode(`rgb`)}};const sn={OrRd:[`#fff7ec`,`#fee8c8`,`#fdd49e`,`#fdbb84`,`#fc8d59`,`#ef6548`,`#d7301f`,`#b30000`,`#7f0000`],PuBu:[`#fff7fb`,`#ece7f2`,`#d0d1e6`,`#a6bddb`,`#74a9cf`,`#3690c0`,`#0570b0`,`#045a8d`,`#023858`],BuPu:[`#f7fcfd`,`#e0ecf4`,`#bfd3e6`,`#9ebcda`,`#8c96c6`,`#8c6bb1`,`#88419d`,`#810f7c`,`#4d004b`],Oranges:[`#fff5eb`,`#fee6ce`,`#fdd0a2`,`#fdae6b`,`#fd8d3c`,`#f16913`,`#d94801`,`#a63603`,`#7f2704`],BuGn:[`#f7fcfd`,`#e5f5f9`,`#ccece6`,`#99d8c9`,`#66c2a4`,`#41ae76`,`#238b45`,`#006d2c`,`#00441b`],YlOrBr:[`#ffffe5`,`#fff7bc`,`#fee391`,`#fec44f`,`#fe9929`,`#ec7014`,`#cc4c02`,`#993404`,`#662506`],YlGn:[`#ffffe5`,`#f7fcb9`,`#d9f0a3`,`#addd8e`,`#78c679`,`#41ab5d`,`#238443`,`#006837`,`#004529`],Reds:[`#fff5f0`,`#fee0d2`,`#fcbba1`,`#fc9272`,`#fb6a4a`,`#ef3b2c`,`#cb181d`,`#a50f15`,`#67000d`],RdPu:[`#fff7f3`,`#fde0dd`,`#fcc5c0`,`#fa9fb5`,`#f768a1`,`#dd3497`,`#ae017e`,`#7a0177`,`#49006a`],Greens:[`#f7fcf5`,`#e5f5e0`,`#c7e9c0`,`#a1d99b`,`#74c476`,`#41ab5d`,`#238b45`,`#006d2c`,`#00441b`],YlGnBu:[`#ffffd9`,`#edf8b1`,`#c7e9b4`,`#7fcdbb`,`#41b6c4`,`#1d91c0`,`#225ea8`,`#253494`,`#081d58`],Purples:[`#fcfbfd`,`#efedf5`,`#dadaeb`,`#bcbddc`,`#9e9ac8`,`#807dba`,`#6a51a3`,`#54278f`,`#3f007d`],GnBu:[`#f7fcf0`,`#e0f3db`,`#ccebc5`,`#a8ddb5`,`#7bccc4`,`#4eb3d3`,`#2b8cbe`,`#0868ac`,`#084081`],Greys:[`#ffffff`,`#f0f0f0`,`#d9d9d9`,`#bdbdbd`,`#969696`,`#737373`,`#525252`,`#252525`,`#000000`],YlOrRd:[`#ffffcc`,`#ffeda0`,`#fed976`,`#feb24c`,`#fd8d3c`,`#fc4e2a`,`#e31a1c`,`#bd0026`,`#800026`],PuRd:[`#f7f4f9`,`#e7e1ef`,`#d4b9da`,`#c994c7`,`#df65b0`,`#e7298a`,`#ce1256`,`#980043`,`#67001f`],Blues:[`#f7fbff`,`#deebf7`,`#c6dbef`,`#9ecae1`,`#6baed6`,`#4292c6`,`#2171b5`,`#08519c`,`#08306b`],PuBuGn:[`#fff7fb`,`#ece2f0`,`#d0d1e6`,`#a6bddb`,`#67a9cf`,`#3690c0`,`#02818a`,`#016c59`,`#014636`],Viridis:[`#440154`,`#482777`,`#3f4a8a`,`#31678e`,`#26838f`,`#1f9d8a`,`#6cce5a`,`#b6de2b`,`#fee825`],Spectral:[`#9e0142`,`#d53e4f`,`#f46d43`,`#fdae61`,`#fee08b`,`#ffffbf`,`#e6f598`,`#abdda4`,`#66c2a5`,`#3288bd`,`#5e4fa2`],RdYlGn:[`#a50026`,`#d73027`,`#f46d43`,`#fdae61`,`#fee08b`,`#ffffbf`,`#d9ef8b`,`#a6d96a`,`#66bd63`,`#1a9850`,`#006837`],RdBu:[`#67001f`,`#b2182b`,`#d6604d`,`#f4a582`,`#fddbc7`,`#f7f7f7`,`#d1e5f0`,`#92c5de`,`#4393c3`,`#2166ac`,`#053061`],PiYG:[`#8e0152`,`#c51b7d`,`#de77ae`,`#f1b6da`,`#fde0ef`,`#f7f7f7`,`#e6f5d0`,`#b8e186`,`#7fbc41`,`#4d9221`,`#276419`],PRGn:[`#40004b`,`#762a83`,`#9970ab`,`#c2a5cf`,`#e7d4e8`,`#f7f7f7`,`#d9f0d3`,`#a6dba0`,`#5aae61`,`#1b7837`,`#00441b`],RdYlBu:[`#a50026`,`#d73027`,`#f46d43`,`#fdae61`,`#fee090`,`#ffffbf`,`#e0f3f8`,`#abd9e9`,`#74add1`,`#4575b4`,`#313695`],BrBG:[`#543005`,`#8c510a`,`#bf812d`,`#dfc27d`,`#f6e8c3`,`#f5f5f5`,`#c7eae5`,`#80cdc1`,`#35978f`,`#01665e`,`#003c30`],RdGy:[`#67001f`,`#b2182b`,`#d6604d`,`#f4a582`,`#fddbc7`,`#ffffff`,`#e0e0e0`,`#bababa`,`#878787`,`#4d4d4d`,`#1a1a1a`],PuOr:[`#7f3b08`,`#b35806`,`#e08214`,`#fdb863`,`#fee0b6`,`#f7f7f7`,`#d8daeb`,`#b2abd2`,`#8073ac`,`#542788`,`#2d004b`],Set2:[`#66c2a5`,`#fc8d62`,`#8da0cb`,`#e78ac3`,`#a6d854`,`#ffd92f`,`#e5c494`,`#b3b3b3`],Accent:[`#7fc97f`,`#beaed4`,`#fdc086`,`#ffff99`,`#386cb0`,`#f0027f`,`#bf5b17`,`#666666`],Set1:[`#e41a1c`,`#377eb8`,`#4daf4a`,`#984ea3`,`#ff7f00`,`#ffff33`,`#a65628`,`#f781bf`,`#999999`],Set3:[`#8dd3c7`,`#ffffb3`,`#bebada`,`#fb8072`,`#80b1d3`,`#fdb462`,`#b3de69`,`#fccde5`,`#d9d9d9`,`#bc80bd`,`#ccebc5`,`#ffed6f`],Dark2:[`#1b9e77`,`#d95f02`,`#7570b3`,`#e7298a`,`#66a61e`,`#e6ab02`,`#a6761d`,`#666666`],Paired:[`#a6cee3`,`#1f78b4`,`#b2df8a`,`#33a02c`,`#fb9a99`,`#e31a1c`,`#fdbf6f`,`#ff7f00`,`#cab2d6`,`#6a3d9a`,`#ffff99`,`#b15928`],Pastel2:[`#b3e2cd`,`#fdcdac`,`#cbd5e8`,`#f4cae4`,`#e6f5c9`,`#fff2ae`,`#f1e2cc`,`#cccccc`],Pastel1:[`#fbb4ae`,`#b3cde3`,`#ccebc5`,`#decbe4`,`#fed9a6`,`#ffffcc`,`#e5d8bd`,`#fddaec`,`#f2f2f2`]},cn=Object.keys(sn),ln=new Map(cn.map(e=>[e.toLowerCase(),e])),un=typeof Proxy==`function`?new Proxy(sn,{get(e,t){let n=t.toLowerCase();if(ln.has(n))return e[ln.get(n)]},getOwnPropertyNames(){return Object.getOwnPropertyNames(cn)}}):sn,dn=(...e)=>{e=o(e,`cmyk`);let[t,n,r,i]=e,a=e.length>4?e[4]:1;return i===1?[0,0,0,a]:[t>=1?0:255*(1-t)*(1-i),n>=1?0:255*(1-n)*(1-i),r>=1?0:255*(1-r)*(1-i),a]},{max:fn}=Math,pn=(...e)=>{let[t,n,r]=o(e,`rgb`);t/=255,n/=255,r/=255;let i=1-fn(t,fn(n,r)),a=i<1?1/(1-i):0;return[(1-t-i)*a,(1-n-i)*a,(1-r-i)*a,i]};y.prototype.cmyk=function(){return pn(this._rgb)};const mn=(...e)=>new y(...e,`cmyk`);Object.assign(b,{cmyk:mn}),v.format.cmyk=dn,v.autodetect.push({p:2,test:(...e)=>{if(e=o(e,`cmyk`),a(e)===`array`&&e.length===4)return`cmyk`}});const hn=(...e)=>{let t=o(e,`hsla`),n=s(e)||`lsa`;return t[0]=d(t[0]||0)+`deg`,t[1]=d(t[1]*100)+`%`,t[2]=d(t[2]*100)+`%`,n===`hsla`||t.length>3&&t[3]<1?(t[3]=`/ `+(t.length>3?t[3]:1),n=`hsla`):t.length=3,`${n.substr(0,3)}(${t.join(` `)})`},gn=(...e)=>{let t=o(e,`lab`),n=s(e)||`lab`;return t[0]=d(t[0])+`%`,t[1]=d(t[1]),t[2]=d(t[2]),n===`laba`||t.length>3&&t[3]<1?t[3]=`/ `+(t.length>3?t[3]:1):t.length=3,`lab(${t.join(` `)})`},_n=(...e)=>{let t=o(e,`lch`),n=s(e)||`lab`;return t[0]=d(t[0])+`%`,t[1]=d(t[1]),t[2]=isNaN(t[2])?`none`:d(t[2])+`deg`,n===`lcha`||t.length>3&&t[3]<1?t[3]=`/ `+(t.length>3?t[3]:1):t.length=3,`lch(${t.join(` `)})`},vn=(...e)=>{let t=o(e,`lab`);return t[0]=d(t[0]*100)+`%`,t[1]=f(t[1]),t[2]=f(t[2]),t.length>3&&t[3]<1?t[3]=`/ `+(t.length>3?t[3]:1):t.length=3,`oklab(${t.join(` `)})`},yn=(...e)=>{let[t,n,r,...i]=o(e,`rgb`),[a,s,c]=nt(t,n,r),[l,u,d]=_e(a,s,c);return[l,u,d,...i.length>0&&i[0]<1?[i[0]]:[]]},bn=(...e)=>{let t=o(e,`lch`);return t[0]=d(t[0]*100)+`%`,t[1]=f(t[1]),t[2]=isNaN(t[2])?`none`:d(t[2])+`deg`,t.length>3&&t[3]<1?t[3]=`/ `+(t.length>3?t[3]:1):t.length=3,`oklch(${t.join(` `)})`},{round:xn}=Math,Sn=(...e)=>{let t=o(e,`rgba`),n=s(e)||`rgb`;if(n.substr(0,3)===`hsl`)return hn(Ue(t),n);if(n.substr(0,3)===`lab`){let e=A();k(`d50`);let r=gn(N(t),n);return k(e),r}if(n.substr(0,3)===`lch`){let e=A();k(`d50`);let r=_n(ve(t),n);return k(e),r}return n.substr(0,5)===`oklab`?vn(nt(t)):n.substr(0,5)===`oklch`?bn(yn(t)):(t[0]=xn(t[0]),t[1]=xn(t[1]),t[2]=xn(t[2]),(n===`rgba`||t.length>3&&t[3]<1)&&(t[3]=`/ `+(t.length>3?t[3]:1),n=`rgba`),`${n.substr(0,3)}(${t.slice(0,n===`rgb`?3:4).join(` `)})`)},Cn=(...e)=>{e=o(e,`lch`);let[t,n,r,...i]=e,[a,s,c]=de(t,n,r),[l,u,d]=et(a,s,c);return[l,u,d,...i.length>0&&i[0]<1?[i[0]]:[]]},q=`((?:-?\\d+)|(?:-?\\d+(?:\\.\\d+)?)%|none)`,J=`((?:-?(?:\\d+(?:\\.\\d*)?|\\.\\d+)%?)|none)`,Y=`((?:-?(?:\\d+(?:\\.\\d*)?|\\.\\d+)%)|none)`,wn=`\\s*,\\s*`,Tn=`((?:-?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:deg)?)|none)`,X=`\\s*(?:\\/\\s*((?:[01]|[01]?\\.\\d+)|\\d+(?:\\.\\d+)?%))?`,En=RegExp(`^rgba?\\(\\s*`+[q,q,q].join(`\\s+`)+X+`\\)$`),Dn=RegExp(`^rgb\\(\\s*`+[q,q,q].join(wn)+`\\s*\\)$`),On=RegExp(`^rgba\\(\\s*`+[q,q,q,J].join(wn)+`\\s*\\)$`),kn=RegExp(`^hsla?\\(\\s*`+[Tn,Y,Y].join(`\\s+`)+X+`\\)$`),An=RegExp(`^hsl?\\(\\s*`+[Tn,Y,Y].join(wn)+`\\s*\\)$`),jn=/^hsla\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/,Mn=RegExp(`^lab\\(\\s*`+[J,J,J].join(`\\s+`)+X+`\\)$`),Nn=RegExp(`^lch\\(\\s*`+[J,J,Tn].join(`\\s+`)+X+`\\)$`),Pn=RegExp(`^oklab\\(\\s*`+[J,J,J].join(`\\s+`)+X+`\\)$`),Fn=RegExp(`^oklch\\(\\s*`+[J,J,Tn].join(`\\s+`)+X+`\\)$`),{round:In}=Math,Z=e=>e.map((e,t)=>t<=2?n(In(e),0,255):e),Q=(e,t=0,n=100,r=!1)=>(typeof e==`string`&&e.endsWith(`%`)&&(e=parseFloat(e.substring(0,e.length-1))/100,e=r?t+(e+1)*.5*(n-t):t+e*(n-t)),+e),$=(e,t)=>e===`none`?t:e,Ln=e=>{if(e=e.toLowerCase().trim(),e===`transparent`)return[0,0,0,0];let t;if(v.format.named)try{return v.format.named(e)}catch{}if((t=e.match(En))||(t=e.match(Dn))){let e=t.slice(1,4);for(let t=0;t<3;t++)e[t]=+Q($(e[t],0),0,255);e=Z(e);let n=t[4]===void 0?1:+Q(t[4],0,1);return e[3]=n,e}if(t=e.match(On)){let e=t.slice(1,5);for(let t=0;t<4;t++)e[t]=+Q(e[t],0,255);return e}if((t=e.match(kn))||(t=e.match(An))){let e=t.slice(1,4);e[0]=+$(e[0].replace(`deg`,``),0),e[1]=Q($(e[1],0),0,100)*.01,e[2]=Q($(e[2],0),0,100)*.01;let n=Z(He(e));return n[3]=t[4]===void 0?1:+Q(t[4],0,1),n}if(t=e.match(jn)){let e=t.slice(1,4);e[1]*=.01,e[2]*=.01;let n=He(e);for(let e=0;e<3;e++)n[e]=In(n[e]);return n[3]=+t[4],n}if(t=e.match(Mn)){let e=t.slice(1,4);e[0]=Q($(e[0],0),0,100),e[1]=Q($(e[1],0),-125,125,!0),e[2]=Q($(e[2],0),-125,125,!0);let n=A();k(`d50`);let r=Z(j(e));return k(n),r[3]=t[4]===void 0?1:+Q(t[4],0,1),r}if(t=e.match(Nn)){let e=t.slice(1,4);e[0]=Q(e[0],0,100),e[1]=Q($(e[1],0),0,150,!1),e[2]=+$(e[2].replace(`deg`,``),0);let n=A();k(`d50`);let r=Z(fe(e));return k(n),r[3]=t[4]===void 0?1:+Q(t[4],0,1),r}if(t=e.match(Pn)){let e=t.slice(1,4);e[0]=Q($(e[0],0),0,1),e[1]=Q($(e[1],0),-.4,.4,!0),e[2]=Q($(e[2],0),-.4,.4,!0);let n=Z(et(e));return n[3]=t[4]===void 0?1:+Q(t[4],0,1),n}if(t=e.match(Fn)){let e=t.slice(1,4);e[0]=Q($(e[0],0),0,1),e[1]=Q($(e[1],0),0,.4,!1),e[2]=+$(e[2].replace(`deg`,``),0);let n=Z(Cn(e));return n[3]=t[4]===void 0?1:+Q(t[4],0,1),n}};Ln.test=e=>En.test(e)||kn.test(e)||Mn.test(e)||Nn.test(e)||Pn.test(e)||Fn.test(e)||Dn.test(e)||On.test(e)||An.test(e)||jn.test(e)||e===`transparent`,y.prototype.css=function(e){return Sn(this._rgb,e)};const Rn=(...e)=>new y(...e,`css`);b.css=Rn,v.format.css=Ln,v.autodetect.push({p:5,test:(e,...t)=>{if(!t.length&&a(e)===`string`&&Ln.test(e))return`css`}}),v.format.gl=(...e)=>{let t=o(e,`rgba`);return t[0]*=255,t[1]*=255,t[2]*=255,t};const zn=(...e)=>new y(...e,`gl`);b.gl=zn,y.prototype.gl=function(){let e=this._rgb;return[e[0]/255,e[1]/255,e[2]/255,e[3]]},y.prototype.hex=function(e){return E(this._rgb,e)};const Bn=(...e)=>new y(...e,`hex`);b.hex=Bn,v.format.hex=w,v.autodetect.push({p:4,test:(e,...t)=>{if(!t.length&&a(e)===`string`&&[3,4,5,6,7,8,9].indexOf(e.length)>=0)return`hex`}});const{log:Vn}=Math,Hn=e=>{let t=e/100,n,r,i;return t<66?(n=255,r=t<6?0:-155.25485562709179-.44596950469579133*(r=t-2)+104.49216199393888*Vn(r),i=t<20?0:-254.76935184120902+.8274096064007395*(i=t-10)+115.67994401066147*Vn(i)):(n=351.97690566805693+.114206453784165*(n=t-55)-40.25366309332127*Vn(n),r=325.4494125711974+.07943456536662342*(r=t-50)-28.0852963507957*Vn(r),i=255),[n,r,i,1]},{round:Un}=Math,Wn=(...e)=>{let t=o(e,`rgb`),n=t[0],r=t[2],i=1e3,a=4e4,s;for(;a-i>.4;){s=(a+i)*.5;let e=Hn(s);e[2]/e[0]>=r/n?a=s:i=s}return Un(s)};y.prototype.temp=y.prototype.kelvin=y.prototype.temperature=function(){return Wn(this._rgb)};const Gn=(...e)=>new y(...e,`temp`);Object.assign(b,{temp:Gn,kelvin:Gn,temperature:Gn}),v.format.temp=v.format.kelvin=v.format.temperature=Hn,y.prototype.oklch=function(){return yn(this._rgb)};const Kn=(...e)=>new y(...e,`oklch`);Object.assign(b,{oklch:Kn}),v.format.oklch=Cn,v.autodetect.push({p:2,test:(...e)=>{if(e=o(e,`oklch`),a(e)===`array`&&e.length===3)return`oklch`}}),Object.assign(b,{analyze:Vt,average:pt,bezier:yt,blend:B,brewer:un,Color:y,colors:x,contrast:Ut,contrastAPCA:qt,cubehelix:Nt,deltaE:nn,distance:rn,input:v,interpolate:F,limits:Ht,mix:F,random:It,scale:z,scales:on,valid:an});var qn=b;export{qn as t};