@grunwaldlab/heat-tree 0.1.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.
@@ -0,0 +1,20 @@
1
+ (function(ct,ft){typeof exports=="object"&&typeof module<"u"?ft(exports):typeof define=="function"&&define.amd?define(["exports"],ft):(ct=typeof globalThis<"u"?globalThis:ct||self,ft(ct.HeatTree={}))})(this,(function(ct){"use strict";function ft(e,t){return e==null||t==null?NaN:e<t?-1:e>t?1:e>=t?0:NaN}var wn={value:()=>{}};function Gt(){for(var e=0,t=arguments.length,n={},i;e<t;++e){if(!(i=arguments[e]+"")||i in n||/[\s.]/.test(i))throw new Error("illegal type: "+i);n[i]=[]}return new Tt(n)}function Tt(e){this._=e}function vn(e,t){return e.trim().split(/^|\s+/).map(function(n){var i="",s=n.indexOf(".");if(s>=0&&(i=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:i}})}Tt.prototype=Gt.prototype={constructor:Tt,on:function(e,t){var n=this._,i=vn(e+"",n),s,a=-1,r=i.length;if(arguments.length<2){for(;++a<r;)if((s=(e=i[a]).type)&&(s=_n(n[s],e.name)))return s;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++a<r;)if(s=(e=i[a]).type)n[s]=we(n[s],e.name,t);else if(t==null)for(s in n)n[s]=we(n[s],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new Tt(e)},call:function(e,t){if((s=arguments.length-2)>0)for(var n=new Array(s),i=0,s,a;i<s;++i)n[i]=arguments[i+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(a=this._[e],i=0,s=a.length;i<s;++i)a[i].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var i=this._[e],s=0,a=i.length;s<a;++s)i[s].value.apply(t,n)}};function _n(e,t){for(var n=0,i=e.length,s;n<i;++n)if((s=e[n]).name===t)return s.value}function we(e,t,n){for(var i=0,s=e.length;i<s;++i)if(e[i].name===t){e[i]=wn,e=e.slice(0,i).concat(e.slice(i+1));break}return n!=null&&e.push({name:t,value:n}),e}var Zt="http://www.w3.org/1999/xhtml";const ve={svg:"http://www.w3.org/2000/svg",xhtml:Zt,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Ct(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),ve.hasOwnProperty(t)?{space:ve[t],local:e}:e}function Sn(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===Zt&&t.documentElement.namespaceURI===Zt?t.createElement(e):t.createElementNS(n,e)}}function Tn(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function _e(e){var t=Ct(e);return(t.local?Tn:Sn)(t)}function Cn(){}function Ut(e){return e==null?Cn:function(){return this.querySelector(e)}}function Ln(e){typeof e!="function"&&(e=Ut(e));for(var t=this._groups,n=t.length,i=new Array(n),s=0;s<n;++s)for(var a=t[s],r=a.length,o=i[s]=new Array(r),c,l,h=0;h<r;++h)(c=a[h])&&(l=e.call(c,c.__data__,h,a))&&("__data__"in c&&(l.__data__=c.__data__),o[h]=l);return new O(i,this._parents)}function Mn(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function Pn(){return[]}function Se(e){return e==null?Pn:function(){return this.querySelectorAll(e)}}function En(e){return function(){return Mn(e.apply(this,arguments))}}function $n(e){typeof e=="function"?e=En(e):e=Se(e);for(var t=this._groups,n=t.length,i=[],s=[],a=0;a<n;++a)for(var r=t[a],o=r.length,c,l=0;l<o;++l)(c=r[l])&&(i.push(e.call(c,c.__data__,l,r)),s.push(c));return new O(i,s)}function Te(e){return function(){return this.matches(e)}}function Ce(e){return function(t){return t.matches(e)}}var zn=Array.prototype.find;function An(e){return function(){return zn.call(this.children,e)}}function Nn(){return this.firstElementChild}function kn(e){return this.select(e==null?Nn:An(typeof e=="function"?e:Ce(e)))}var Rn=Array.prototype.filter;function Fn(){return Array.from(this.children)}function Bn(e){return function(){return Rn.call(this.children,e)}}function Xn(e){return this.selectAll(e==null?Fn:Bn(typeof e=="function"?e:Ce(e)))}function Vn(e){typeof e!="function"&&(e=Te(e));for(var t=this._groups,n=t.length,i=new Array(n),s=0;s<n;++s)for(var a=t[s],r=a.length,o=i[s]=[],c,l=0;l<r;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&o.push(c);return new O(i,this._parents)}function Le(e){return new Array(e.length)}function Hn(){return new O(this._enter||this._groups.map(Le),this._parents)}function Lt(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}Lt.prototype={constructor:Lt,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function Dn(e){return function(){return e}}function On(e,t,n,i,s,a){for(var r=0,o,c=t.length,l=a.length;r<l;++r)(o=t[r])?(o.__data__=a[r],i[r]=o):n[r]=new Lt(e,a[r]);for(;r<c;++r)(o=t[r])&&(s[r]=o)}function In(e,t,n,i,s,a,r){var o,c,l=new Map,h=t.length,u=a.length,f=new Array(h),d;for(o=0;o<h;++o)(c=t[o])&&(f[o]=d=r.call(c,c.__data__,o,t)+"",l.has(d)?s[o]=c:l.set(d,c));for(o=0;o<u;++o)d=r.call(e,a[o],o,a)+"",(c=l.get(d))?(i[o]=c,c.__data__=a[o],l.delete(d)):n[o]=new Lt(e,a[o]);for(o=0;o<h;++o)(c=t[o])&&l.get(f[o])===c&&(s[o]=c)}function Yn(e){return e.__data__}function qn(e,t){if(!arguments.length)return Array.from(this,Yn);var n=t?In:On,i=this._parents,s=this._groups;typeof e!="function"&&(e=Dn(e));for(var a=s.length,r=new Array(a),o=new Array(a),c=new Array(a),l=0;l<a;++l){var h=i[l],u=s[l],f=u.length,d=Gn(e.call(h,h&&h.__data__,l,i)),b=d.length,m=o[l]=new Array(b),S=r[l]=new Array(b),y=c[l]=new Array(f);n(h,u,m,S,y,d,t);for(var T=0,$=0,g,z;T<b;++T)if(g=m[T]){for(T>=$&&($=T+1);!(z=S[$])&&++$<b;);g._next=z||null}}return r=new O(r,i),r._enter=o,r._exit=c,r}function Gn(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Zn(){return new O(this._exit||this._groups.map(Le),this._parents)}function Un(e,t,n){var i=this.enter(),s=this,a=this.exit();return typeof e=="function"?(i=e(i),i&&(i=i.selection())):i=i.append(e+""),t!=null&&(s=t(s),s&&(s=s.selection())),n==null?a.remove():n(a),i&&s?i.merge(s).order():s}function Wn(e){for(var t=e.selection?e.selection():e,n=this._groups,i=t._groups,s=n.length,a=i.length,r=Math.min(s,a),o=new Array(s),c=0;c<r;++c)for(var l=n[c],h=i[c],u=l.length,f=o[c]=new Array(u),d,b=0;b<u;++b)(d=l[b]||h[b])&&(f[b]=d);for(;c<s;++c)o[c]=n[c];return new O(o,this._parents)}function Kn(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var i=e[t],s=i.length-1,a=i[s],r;--s>=0;)(r=i[s])&&(a&&r.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(r,a),a=r);return this}function Qn(e){e||(e=Jn);function t(u,f){return u&&f?e(u.__data__,f.__data__):!u-!f}for(var n=this._groups,i=n.length,s=new Array(i),a=0;a<i;++a){for(var r=n[a],o=r.length,c=s[a]=new Array(o),l,h=0;h<o;++h)(l=r[h])&&(c[h]=l);c.sort(t)}return new O(s,this._parents).order()}function Jn(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function jn(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function ti(){return Array.from(this)}function ei(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var i=e[t],s=0,a=i.length;s<a;++s){var r=i[s];if(r)return r}return null}function ni(){let e=0;for(const t of this)++e;return e}function ii(){return!this.node()}function si(e){for(var t=this._groups,n=0,i=t.length;n<i;++n)for(var s=t[n],a=0,r=s.length,o;a<r;++a)(o=s[a])&&e.call(o,o.__data__,a,s);return this}function ai(e){return function(){this.removeAttribute(e)}}function ri(e){return function(){this.removeAttributeNS(e.space,e.local)}}function oi(e,t){return function(){this.setAttribute(e,t)}}function li(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function ci(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function hi(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function ui(e,t){var n=Ct(e);if(arguments.length<2){var i=this.node();return n.local?i.getAttributeNS(n.space,n.local):i.getAttribute(n)}return this.each((t==null?n.local?ri:ai:typeof t=="function"?n.local?hi:ci:n.local?li:oi)(n,t))}function Me(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function di(e){return function(){this.style.removeProperty(e)}}function fi(e,t,n){return function(){this.style.setProperty(e,t,n)}}function pi(e,t,n){return function(){var i=t.apply(this,arguments);i==null?this.style.removeProperty(e):this.style.setProperty(e,i,n)}}function mi(e,t,n){return arguments.length>1?this.each((t==null?di:typeof t=="function"?pi:fi)(e,t,n??"")):ht(this.node(),e)}function ht(e,t){return e.style.getPropertyValue(t)||Me(e).getComputedStyle(e,null).getPropertyValue(t)}function gi(e){return function(){delete this[e]}}function xi(e,t){return function(){this[e]=t}}function yi(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function bi(e,t){return arguments.length>1?this.each((t==null?gi:typeof t=="function"?yi:xi)(e,t)):this.node()[e]}function Pe(e){return e.trim().split(/^|\s+/)}function Wt(e){return e.classList||new Ee(e)}function Ee(e){this._node=e,this._names=Pe(e.getAttribute("class")||"")}Ee.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function $e(e,t){for(var n=Wt(e),i=-1,s=t.length;++i<s;)n.add(t[i])}function ze(e,t){for(var n=Wt(e),i=-1,s=t.length;++i<s;)n.remove(t[i])}function wi(e){return function(){$e(this,e)}}function vi(e){return function(){ze(this,e)}}function _i(e,t){return function(){(t.apply(this,arguments)?$e:ze)(this,e)}}function Si(e,t){var n=Pe(e+"");if(arguments.length<2){for(var i=Wt(this.node()),s=-1,a=n.length;++s<a;)if(!i.contains(n[s]))return!1;return!0}return this.each((typeof t=="function"?_i:t?wi:vi)(n,t))}function Ti(){this.textContent=""}function Ci(e){return function(){this.textContent=e}}function Li(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function Mi(e){return arguments.length?this.each(e==null?Ti:(typeof e=="function"?Li:Ci)(e)):this.node().textContent}function Pi(){this.innerHTML=""}function Ei(e){return function(){this.innerHTML=e}}function $i(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function zi(e){return arguments.length?this.each(e==null?Pi:(typeof e=="function"?$i:Ei)(e)):this.node().innerHTML}function Ai(){this.nextSibling&&this.parentNode.appendChild(this)}function Ni(){return this.each(Ai)}function ki(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Ri(){return this.each(ki)}function Fi(e){var t=typeof e=="function"?e:_e(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function Bi(){return null}function Xi(e,t){var n=typeof e=="function"?e:_e(e),i=t==null?Bi:typeof t=="function"?t:Ut(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),i.apply(this,arguments)||null)})}function Vi(){var e=this.parentNode;e&&e.removeChild(this)}function Hi(){return this.each(Vi)}function Di(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Oi(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Ii(e){return this.select(e?Oi:Di)}function Yi(e){return arguments.length?this.property("__data__",e):this.node().__data__}function qi(e){return function(t){e.call(this,t,this.__data__)}}function Gi(e){return e.trim().split(/^|\s+/).map(function(t){var n="",i=t.indexOf(".");return i>=0&&(n=t.slice(i+1),t=t.slice(0,i)),{type:t,name:n}})}function Zi(e){return function(){var t=this.__on;if(t){for(var n=0,i=-1,s=t.length,a;n<s;++n)a=t[n],(!e.type||a.type===e.type)&&a.name===e.name?this.removeEventListener(a.type,a.listener,a.options):t[++i]=a;++i?t.length=i:delete this.__on}}}function Ui(e,t,n){return function(){var i=this.__on,s,a=qi(t);if(i){for(var r=0,o=i.length;r<o;++r)if((s=i[r]).type===e.type&&s.name===e.name){this.removeEventListener(s.type,s.listener,s.options),this.addEventListener(s.type,s.listener=a,s.options=n),s.value=t;return}}this.addEventListener(e.type,a,n),s={type:e.type,name:e.name,value:t,listener:a,options:n},i?i.push(s):this.__on=[s]}}function Wi(e,t,n){var i=Gi(e+""),s,a=i.length,r;if(arguments.length<2){var o=this.node().__on;if(o){for(var c=0,l=o.length,h;c<l;++c)for(s=0,h=o[c];s<a;++s)if((r=i[s]).type===h.type&&r.name===h.name)return h.value}return}for(o=t?Ui:Zi,s=0;s<a;++s)this.each(o(i[s],t,n));return this}function Ae(e,t,n){var i=Me(e),s=i.CustomEvent;typeof s=="function"?s=new s(t,n):(s=i.document.createEvent("Event"),n?(s.initEvent(t,n.bubbles,n.cancelable),s.detail=n.detail):s.initEvent(t,!1,!1)),e.dispatchEvent(s)}function Ki(e,t){return function(){return Ae(this,e,t)}}function Qi(e,t){return function(){return Ae(this,e,t.apply(this,arguments))}}function Ji(e,t){return this.each((typeof t=="function"?Qi:Ki)(e,t))}function*ji(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var i=e[t],s=0,a=i.length,r;s<a;++s)(r=i[s])&&(yield r)}var Ne=[null];function O(e,t){this._groups=e,this._parents=t}function pt(){return new O([[document.documentElement]],Ne)}function ts(){return this}O.prototype=pt.prototype={constructor:O,select:Ln,selectAll:$n,selectChild:kn,selectChildren:Xn,filter:Vn,data:qn,enter:Hn,exit:Zn,join:Un,merge:Wn,selection:ts,order:Kn,sort:Qn,call:jn,nodes:ti,node:ei,size:ni,empty:ii,each:si,attr:ui,style:mi,property:bi,classed:Si,text:Mi,html:zi,raise:Ni,lower:Ri,append:Fi,insert:Xi,remove:Hi,clone:Ii,datum:Yi,on:Wi,dispatch:Ji,[Symbol.iterator]:ji};function Z(e){return typeof e=="string"?new O([[document.querySelector(e)]],[document.documentElement]):new O([[e]],Ne)}function es(e){let t;for(;t=e.sourceEvent;)e=t;return e}function it(e,t){if(e=es(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var i=n.createSVGPoint();return i.x=e.clientX,i.y=e.clientY,i=i.matrixTransform(t.getScreenCTM().inverse()),[i.x,i.y]}if(t.getBoundingClientRect){var s=t.getBoundingClientRect();return[e.clientX-s.left-t.clientLeft,e.clientY-s.top-t.clientTop]}}return[e.pageX,e.pageY]}const Kt={capture:!0,passive:!1};function Qt(e){e.preventDefault(),e.stopImmediatePropagation()}function ns(e){var t=e.document.documentElement,n=Z(e).on("dragstart.drag",Qt,Kt);"onselectstart"in t?n.on("selectstart.drag",Qt,Kt):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function is(e,t){var n=e.document.documentElement,i=Z(e).on("dragstart.drag",null);t&&(i.on("click.drag",Qt,Kt),setTimeout(function(){i.on("click.drag",null)},0)),"onselectstart"in n?i.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}function Jt(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function ke(e,t){var n=Object.create(e.prototype);for(var i in t)n[i]=t[i];return n}function mt(){}var gt=.7,Mt=1/gt,ut="\\s*([+-]?\\d+)\\s*",xt="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",U="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",ss=/^#([0-9a-f]{3,8})$/,as=new RegExp(`^rgb\\(${ut},${ut},${ut}\\)$`),rs=new RegExp(`^rgb\\(${U},${U},${U}\\)$`),os=new RegExp(`^rgba\\(${ut},${ut},${ut},${xt}\\)$`),ls=new RegExp(`^rgba\\(${U},${U},${U},${xt}\\)$`),cs=new RegExp(`^hsl\\(${xt},${U},${U}\\)$`),hs=new RegExp(`^hsla\\(${xt},${U},${U},${xt}\\)$`),Re={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Jt(mt,yt,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:Fe,formatHex:Fe,formatHex8:us,formatHsl:ds,formatRgb:Be,toString:Be});function Fe(){return this.rgb().formatHex()}function us(){return this.rgb().formatHex8()}function ds(){return Oe(this).formatHsl()}function Be(){return this.rgb().formatRgb()}function yt(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=ss.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?Xe(t):n===3?new D(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Pt(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Pt(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=as.exec(e))?new D(t[1],t[2],t[3],1):(t=rs.exec(e))?new D(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=os.exec(e))?Pt(t[1],t[2],t[3],t[4]):(t=ls.exec(e))?Pt(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=cs.exec(e))?De(t[1],t[2]/100,t[3]/100,1):(t=hs.exec(e))?De(t[1],t[2]/100,t[3]/100,t[4]):Re.hasOwnProperty(e)?Xe(Re[e]):e==="transparent"?new D(NaN,NaN,NaN,0):null}function Xe(e){return new D(e>>16&255,e>>8&255,e&255,1)}function Pt(e,t,n,i){return i<=0&&(e=t=n=NaN),new D(e,t,n,i)}function fs(e){return e instanceof mt||(e=yt(e)),e?(e=e.rgb(),new D(e.r,e.g,e.b,e.opacity)):new D}function jt(e,t,n,i){return arguments.length===1?fs(e):new D(e,t,n,i??1)}function D(e,t,n,i){this.r=+e,this.g=+t,this.b=+n,this.opacity=+i}Jt(D,jt,ke(mt,{brighter(e){return e=e==null?Mt:Math.pow(Mt,e),new D(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?gt:Math.pow(gt,e),new D(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new D(st(this.r),st(this.g),st(this.b),Et(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Ve,formatHex:Ve,formatHex8:ps,formatRgb:He,toString:He}));function Ve(){return`#${at(this.r)}${at(this.g)}${at(this.b)}`}function ps(){return`#${at(this.r)}${at(this.g)}${at(this.b)}${at((isNaN(this.opacity)?1:this.opacity)*255)}`}function He(){const e=Et(this.opacity);return`${e===1?"rgb(":"rgba("}${st(this.r)}, ${st(this.g)}, ${st(this.b)}${e===1?")":`, ${e})`}`}function Et(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function st(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function at(e){return e=st(e),(e<16?"0":"")+e.toString(16)}function De(e,t,n,i){return i<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new I(e,t,n,i)}function Oe(e){if(e instanceof I)return new I(e.h,e.s,e.l,e.opacity);if(e instanceof mt||(e=yt(e)),!e)return new I;if(e instanceof I)return e;e=e.rgb();var t=e.r/255,n=e.g/255,i=e.b/255,s=Math.min(t,n,i),a=Math.max(t,n,i),r=NaN,o=a-s,c=(a+s)/2;return o?(t===a?r=(n-i)/o+(n<i)*6:n===a?r=(i-t)/o+2:r=(t-n)/o+4,o/=c<.5?a+s:2-a-s,r*=60):o=c>0&&c<1?0:r,new I(r,o,c,e.opacity)}function ms(e,t,n,i){return arguments.length===1?Oe(e):new I(e,t,n,i??1)}function I(e,t,n,i){this.h=+e,this.s=+t,this.l=+n,this.opacity=+i}Jt(I,ms,ke(mt,{brighter(e){return e=e==null?Mt:Math.pow(Mt,e),new I(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?gt:Math.pow(gt,e),new I(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,i=n+(n<.5?n:1-n)*t,s=2*n-i;return new D(te(e>=240?e-240:e+120,s,i),te(e,s,i),te(e<120?e+240:e-120,s,i),this.opacity)},clamp(){return new I(Ie(this.h),$t(this.s),$t(this.l),Et(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=Et(this.opacity);return`${e===1?"hsl(":"hsla("}${Ie(this.h)}, ${$t(this.s)*100}%, ${$t(this.l)*100}%${e===1?")":`, ${e})`}`}}));function Ie(e){return e=(e||0)%360,e<0?e+360:e}function $t(e){return Math.max(0,Math.min(1,e||0))}function te(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Ye=e=>()=>e;function gs(e,t){return function(n){return e+n*t}}function xs(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(i){return Math.pow(e+i*t,n)}}function ys(e){return(e=+e)==1?qe:function(t,n){return n-t?xs(t,n,e):Ye(isNaN(t)?n:t)}}function qe(e,t){var n=t-e;return n?gs(e,n):Ye(isNaN(e)?t:e)}const Ge=(function e(t){var n=ys(t);function i(s,a){var r=n((s=jt(s)).r,(a=jt(a)).r),o=n(s.g,a.g),c=n(s.b,a.b),l=qe(s.opacity,a.opacity);return function(h){return s.r=r(h),s.g=o(h),s.b=c(h),s.opacity=l(h),s+""}}return i.gamma=e,i})(1);function nt(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var ee=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,ne=new RegExp(ee.source,"g");function bs(e){return function(){return e}}function ws(e){return function(t){return e(t)+""}}function vs(e,t){var n=ee.lastIndex=ne.lastIndex=0,i,s,a,r=-1,o=[],c=[];for(e=e+"",t=t+"";(i=ee.exec(e))&&(s=ne.exec(t));)(a=s.index)>n&&(a=t.slice(n,a),o[r]?o[r]+=a:o[++r]=a),(i=i[0])===(s=s[0])?o[r]?o[r]+=s:o[++r]=s:(o[++r]=null,c.push({i:r,x:nt(i,s)})),n=ne.lastIndex;return n<t.length&&(a=t.slice(n),o[r]?o[r]+=a:o[++r]=a),o.length<2?c[0]?ws(c[0].x):bs(t):(t=c.length,function(l){for(var h=0,u;h<t;++h)o[(u=c[h]).i]=u.x(l);return o.join("")})}var Ze=180/Math.PI,ie={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Ue(e,t,n,i,s,a){var r,o,c;return(r=Math.sqrt(e*e+t*t))&&(e/=r,t/=r),(c=e*n+t*i)&&(n-=e*c,i-=t*c),(o=Math.sqrt(n*n+i*i))&&(n/=o,i/=o,c/=o),e*i<t*n&&(e=-e,t=-t,c=-c,r=-r),{translateX:s,translateY:a,rotate:Math.atan2(t,e)*Ze,skewX:Math.atan(c)*Ze,scaleX:r,scaleY:o}}var zt;function _s(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?ie:Ue(t.a,t.b,t.c,t.d,t.e,t.f)}function Ss(e){return e==null||(zt||(zt=document.createElementNS("http://www.w3.org/2000/svg","g")),zt.setAttribute("transform",e),!(e=zt.transform.baseVal.consolidate()))?ie:(e=e.matrix,Ue(e.a,e.b,e.c,e.d,e.e,e.f))}function We(e,t,n,i){function s(l){return l.length?l.pop()+" ":""}function a(l,h,u,f,d,b){if(l!==u||h!==f){var m=d.push("translate(",null,t,null,n);b.push({i:m-4,x:nt(l,u)},{i:m-2,x:nt(h,f)})}else(u||f)&&d.push("translate("+u+t+f+n)}function r(l,h,u,f){l!==h?(l-h>180?h+=360:h-l>180&&(l+=360),f.push({i:u.push(s(u)+"rotate(",null,i)-2,x:nt(l,h)})):h&&u.push(s(u)+"rotate("+h+i)}function o(l,h,u,f){l!==h?f.push({i:u.push(s(u)+"skewX(",null,i)-2,x:nt(l,h)}):h&&u.push(s(u)+"skewX("+h+i)}function c(l,h,u,f,d,b){if(l!==u||h!==f){var m=d.push(s(d)+"scale(",null,",",null,")");b.push({i:m-4,x:nt(l,u)},{i:m-2,x:nt(h,f)})}else(u!==1||f!==1)&&d.push(s(d)+"scale("+u+","+f+")")}return function(l,h){var u=[],f=[];return l=e(l),h=e(h),a(l.translateX,l.translateY,h.translateX,h.translateY,u,f),r(l.rotate,h.rotate,u,f),o(l.skewX,h.skewX,u,f),c(l.scaleX,l.scaleY,h.scaleX,h.scaleY,u,f),l=h=null,function(d){for(var b=-1,m=f.length,S;++b<m;)u[(S=f[b]).i]=S.x(d);return u.join("")}}}var Ts=We(_s,"px, ","px)","deg)"),Cs=We(Ss,", ",")",")"),Ls=1e-12;function Ke(e){return((e=Math.exp(e))+1/e)/2}function Ms(e){return((e=Math.exp(e))-1/e)/2}function Ps(e){return((e=Math.exp(2*e))-1)/(e+1)}const Es=(function e(t,n,i){function s(a,r){var o=a[0],c=a[1],l=a[2],h=r[0],u=r[1],f=r[2],d=h-o,b=u-c,m=d*d+b*b,S,y;if(m<Ls)y=Math.log(f/l)/t,S=function(N){return[o+N*d,c+N*b,l*Math.exp(t*N*y)]};else{var T=Math.sqrt(m),$=(f*f-l*l+i*m)/(2*l*n*T),g=(f*f-l*l-i*m)/(2*f*n*T),z=Math.log(Math.sqrt($*$+1)-$),A=Math.log(Math.sqrt(g*g+1)-g);y=(A-z)/t,S=function(N){var v=N*y,L=Ke(z),M=l/(n*T)*(L*Ps(t*v+z)-Ms(z));return[o+M*d,c+M*b,l*L/Ke(t*v+z)]}}return S.duration=y*1e3*t/Math.SQRT2,S}return s.rho=function(a){var r=Math.max(.001,+a),o=r*r,c=o*o;return e(r,o,c)},s})(Math.SQRT2,2,4);var dt=0,bt=0,wt=0,Qe=1e3,At,vt,Nt=0,rt=0,kt=0,_t=typeof performance=="object"&&performance.now?performance:Date,Je=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function se(){return rt||(Je($s),rt=_t.now()+kt)}function $s(){rt=0}function Rt(){this._call=this._time=this._next=null}Rt.prototype=je.prototype={constructor:Rt,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?se():+n)+(t==null?0:+t),!this._next&&vt!==this&&(vt?vt._next=this:At=this,vt=this),this._call=e,this._time=n,ae()},stop:function(){this._call&&(this._call=null,this._time=1/0,ae())}};function je(e,t,n){var i=new Rt;return i.restart(e,t,n),i}function zs(){se(),++dt;for(var e=At,t;e;)(t=rt-e._time)>=0&&e._call.call(void 0,t),e=e._next;--dt}function tn(){rt=(Nt=_t.now())+kt,dt=bt=0;try{zs()}finally{dt=0,Ns(),rt=0}}function As(){var e=_t.now(),t=e-Nt;t>Qe&&(kt-=t,Nt=e)}function Ns(){for(var e,t=At,n,i=1/0;t;)t._call?(i>t._time&&(i=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:At=n);vt=e,ae(i)}function ae(e){if(!dt){bt&&(bt=clearTimeout(bt));var t=e-rt;t>24?(e<1/0&&(bt=setTimeout(tn,e-_t.now()-kt)),wt&&(wt=clearInterval(wt))):(wt||(Nt=_t.now(),wt=setInterval(As,Qe)),dt=1,Je(tn))}}function en(e,t,n){var i=new Rt;return t=t==null?0:+t,i.restart(s=>{i.stop(),e(s+t)},t,n),i}var ks=Gt("start","end","cancel","interrupt"),Rs=[],nn=0,sn=1,re=2,Ft=3,an=4,oe=5,Bt=6;function Xt(e,t,n,i,s,a){var r=e.__transition;if(!r)e.__transition={};else if(n in r)return;Fs(e,n,{name:t,index:i,group:s,on:ks,tween:Rs,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:nn})}function le(e,t){var n=Y(e,t);if(n.state>nn)throw new Error("too late; already scheduled");return n}function W(e,t){var n=Y(e,t);if(n.state>Ft)throw new Error("too late; already running");return n}function Y(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Fs(e,t,n){var i=e.__transition,s;i[t]=n,n.timer=je(a,0,n.time);function a(l){n.state=sn,n.timer.restart(r,n.delay,n.time),n.delay<=l&&r(l-n.delay)}function r(l){var h,u,f,d;if(n.state!==sn)return c();for(h in i)if(d=i[h],d.name===n.name){if(d.state===Ft)return en(r);d.state===an?(d.state=Bt,d.timer.stop(),d.on.call("interrupt",e,e.__data__,d.index,d.group),delete i[h]):+h<t&&(d.state=Bt,d.timer.stop(),d.on.call("cancel",e,e.__data__,d.index,d.group),delete i[h])}if(en(function(){n.state===Ft&&(n.state=an,n.timer.restart(o,n.delay,n.time),o(l))}),n.state=re,n.on.call("start",e,e.__data__,n.index,n.group),n.state===re){for(n.state=Ft,s=new Array(f=n.tween.length),h=0,u=-1;h<f;++h)(d=n.tween[h].value.call(e,e.__data__,n.index,n.group))&&(s[++u]=d);s.length=u+1}}function o(l){for(var h=l<n.duration?n.ease.call(null,l/n.duration):(n.timer.restart(c),n.state=oe,1),u=-1,f=s.length;++u<f;)s[u].call(e,h);n.state===oe&&(n.on.call("end",e,e.__data__,n.index,n.group),c())}function c(){n.state=Bt,n.timer.stop(),delete i[t];for(var l in i)return;delete e.__transition}}function Vt(e,t){var n=e.__transition,i,s,a=!0,r;if(n){t=t==null?null:t+"";for(r in n){if((i=n[r]).name!==t){a=!1;continue}s=i.state>re&&i.state<oe,i.state=Bt,i.timer.stop(),i.on.call(s?"interrupt":"cancel",e,e.__data__,i.index,i.group),delete n[r]}a&&delete e.__transition}}function Bs(e){return this.each(function(){Vt(this,e)})}function Xs(e,t){var n,i;return function(){var s=W(this,e),a=s.tween;if(a!==n){i=n=a;for(var r=0,o=i.length;r<o;++r)if(i[r].name===t){i=i.slice(),i.splice(r,1);break}}s.tween=i}}function Vs(e,t,n){var i,s;if(typeof n!="function")throw new Error;return function(){var a=W(this,e),r=a.tween;if(r!==i){s=(i=r).slice();for(var o={name:t,value:n},c=0,l=s.length;c<l;++c)if(s[c].name===t){s[c]=o;break}c===l&&s.push(o)}a.tween=s}}function Hs(e,t){var n=this._id;if(e+="",arguments.length<2){for(var i=Y(this.node(),n).tween,s=0,a=i.length,r;s<a;++s)if((r=i[s]).name===e)return r.value;return null}return this.each((t==null?Xs:Vs)(n,e,t))}function ce(e,t,n){var i=e._id;return e.each(function(){var s=W(this,i);(s.value||(s.value={}))[t]=n.apply(this,arguments)}),function(s){return Y(s,i).value[t]}}function rn(e,t){var n;return(typeof t=="number"?nt:t instanceof yt?Ge:(n=yt(t))?(t=n,Ge):vs)(e,t)}function Ds(e){return function(){this.removeAttribute(e)}}function Os(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Is(e,t,n){var i,s=n+"",a;return function(){var r=this.getAttribute(e);return r===s?null:r===i?a:a=t(i=r,n)}}function Ys(e,t,n){var i,s=n+"",a;return function(){var r=this.getAttributeNS(e.space,e.local);return r===s?null:r===i?a:a=t(i=r,n)}}function qs(e,t,n){var i,s,a;return function(){var r,o=n(this),c;return o==null?void this.removeAttribute(e):(r=this.getAttribute(e),c=o+"",r===c?null:r===i&&c===s?a:(s=c,a=t(i=r,o)))}}function Gs(e,t,n){var i,s,a;return function(){var r,o=n(this),c;return o==null?void this.removeAttributeNS(e.space,e.local):(r=this.getAttributeNS(e.space,e.local),c=o+"",r===c?null:r===i&&c===s?a:(s=c,a=t(i=r,o)))}}function Zs(e,t){var n=Ct(e),i=n==="transform"?Cs:rn;return this.attrTween(e,typeof t=="function"?(n.local?Gs:qs)(n,i,ce(this,"attr."+e,t)):t==null?(n.local?Os:Ds)(n):(n.local?Ys:Is)(n,i,t))}function Us(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function Ws(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function Ks(e,t){var n,i;function s(){var a=t.apply(this,arguments);return a!==i&&(n=(i=a)&&Ws(e,a)),n}return s._value=t,s}function Qs(e,t){var n,i;function s(){var a=t.apply(this,arguments);return a!==i&&(n=(i=a)&&Us(e,a)),n}return s._value=t,s}function Js(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var i=Ct(e);return this.tween(n,(i.local?Ks:Qs)(i,t))}function js(e,t){return function(){le(this,e).delay=+t.apply(this,arguments)}}function ta(e,t){return t=+t,function(){le(this,e).delay=t}}function ea(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?js:ta)(t,e)):Y(this.node(),t).delay}function na(e,t){return function(){W(this,e).duration=+t.apply(this,arguments)}}function ia(e,t){return t=+t,function(){W(this,e).duration=t}}function sa(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?na:ia)(t,e)):Y(this.node(),t).duration}function aa(e,t){if(typeof t!="function")throw new Error;return function(){W(this,e).ease=t}}function ra(e){var t=this._id;return arguments.length?this.each(aa(t,e)):Y(this.node(),t).ease}function oa(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;W(this,e).ease=n}}function la(e){if(typeof e!="function")throw new Error;return this.each(oa(this._id,e))}function ca(e){typeof e!="function"&&(e=Te(e));for(var t=this._groups,n=t.length,i=new Array(n),s=0;s<n;++s)for(var a=t[s],r=a.length,o=i[s]=[],c,l=0;l<r;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&o.push(c);return new Q(i,this._parents,this._name,this._id)}function ha(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,i=t.length,s=n.length,a=Math.min(i,s),r=new Array(i),o=0;o<a;++o)for(var c=t[o],l=n[o],h=c.length,u=r[o]=new Array(h),f,d=0;d<h;++d)(f=c[d]||l[d])&&(u[d]=f);for(;o<i;++o)r[o]=t[o];return new Q(r,this._parents,this._name,this._id)}function ua(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function da(e,t,n){var i,s,a=ua(t)?le:W;return function(){var r=a(this,e),o=r.on;o!==i&&(s=(i=o).copy()).on(t,n),r.on=s}}function fa(e,t){var n=this._id;return arguments.length<2?Y(this.node(),n).on.on(e):this.each(da(n,e,t))}function pa(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function ma(){return this.on("end.remove",pa(this._id))}function ga(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Ut(e));for(var i=this._groups,s=i.length,a=new Array(s),r=0;r<s;++r)for(var o=i[r],c=o.length,l=a[r]=new Array(c),h,u,f=0;f<c;++f)(h=o[f])&&(u=e.call(h,h.__data__,f,o))&&("__data__"in h&&(u.__data__=h.__data__),l[f]=u,Xt(l[f],t,n,f,l,Y(h,n)));return new Q(a,this._parents,t,n)}function xa(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Se(e));for(var i=this._groups,s=i.length,a=[],r=[],o=0;o<s;++o)for(var c=i[o],l=c.length,h,u=0;u<l;++u)if(h=c[u]){for(var f=e.call(h,h.__data__,u,c),d,b=Y(h,n),m=0,S=f.length;m<S;++m)(d=f[m])&&Xt(d,t,n,m,f,b);a.push(f),r.push(h)}return new Q(a,r,t,n)}var ya=pt.prototype.constructor;function ba(){return new ya(this._groups,this._parents)}function wa(e,t){var n,i,s;return function(){var a=ht(this,e),r=(this.style.removeProperty(e),ht(this,e));return a===r?null:a===n&&r===i?s:s=t(n=a,i=r)}}function on(e){return function(){this.style.removeProperty(e)}}function va(e,t,n){var i,s=n+"",a;return function(){var r=ht(this,e);return r===s?null:r===i?a:a=t(i=r,n)}}function _a(e,t,n){var i,s,a;return function(){var r=ht(this,e),o=n(this),c=o+"";return o==null&&(c=o=(this.style.removeProperty(e),ht(this,e))),r===c?null:r===i&&c===s?a:(s=c,a=t(i=r,o))}}function Sa(e,t){var n,i,s,a="style."+t,r="end."+a,o;return function(){var c=W(this,e),l=c.on,h=c.value[a]==null?o||(o=on(t)):void 0;(l!==n||s!==h)&&(i=(n=l).copy()).on(r,s=h),c.on=i}}function Ta(e,t,n){var i=(e+="")=="transform"?Ts:rn;return t==null?this.styleTween(e,wa(e,i)).on("end.style."+e,on(e)):typeof t=="function"?this.styleTween(e,_a(e,i,ce(this,"style."+e,t))).each(Sa(this._id,e)):this.styleTween(e,va(e,i,t),n).on("end.style."+e,null)}function Ca(e,t,n){return function(i){this.style.setProperty(e,t.call(this,i),n)}}function La(e,t,n){var i,s;function a(){var r=t.apply(this,arguments);return r!==s&&(i=(s=r)&&Ca(e,r,n)),i}return a._value=t,a}function Ma(e,t,n){var i="style."+(e+="");if(arguments.length<2)return(i=this.tween(i))&&i._value;if(t==null)return this.tween(i,null);if(typeof t!="function")throw new Error;return this.tween(i,La(e,t,n??""))}function Pa(e){return function(){this.textContent=e}}function Ea(e){return function(){var t=e(this);this.textContent=t??""}}function $a(e){return this.tween("text",typeof e=="function"?Ea(ce(this,"text",e)):Pa(e==null?"":e+""))}function za(e){return function(t){this.textContent=e.call(this,t)}}function Aa(e){var t,n;function i(){var s=e.apply(this,arguments);return s!==n&&(t=(n=s)&&za(s)),t}return i._value=e,i}function Na(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,Aa(e))}function ka(){for(var e=this._name,t=this._id,n=ln(),i=this._groups,s=i.length,a=0;a<s;++a)for(var r=i[a],o=r.length,c,l=0;l<o;++l)if(c=r[l]){var h=Y(c,t);Xt(c,e,n,l,r,{time:h.time+h.delay+h.duration,delay:0,duration:h.duration,ease:h.ease})}return new Q(i,this._parents,e,n)}function Ra(){var e,t,n=this,i=n._id,s=n.size();return new Promise(function(a,r){var o={value:r},c={value:function(){--s===0&&a()}};n.each(function(){var l=W(this,i),h=l.on;h!==e&&(t=(e=h).copy(),t._.cancel.push(o),t._.interrupt.push(o),t._.end.push(c)),l.on=t}),s===0&&a()})}var Fa=0;function Q(e,t,n,i){this._groups=e,this._parents=t,this._name=n,this._id=i}function ln(){return++Fa}var J=pt.prototype;Q.prototype={constructor:Q,select:ga,selectAll:xa,selectChild:J.selectChild,selectChildren:J.selectChildren,filter:ca,merge:ha,selection:ba,transition:ka,call:J.call,nodes:J.nodes,node:J.node,size:J.size,empty:J.empty,each:J.each,on:fa,attr:Zs,attrTween:Js,style:Ta,styleTween:Ma,text:$a,textTween:Na,remove:ma,tween:Hs,delay:ea,duration:sa,ease:ra,easeVarying:la,end:Ra,[Symbol.iterator]:J[Symbol.iterator]};function Ba(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Xa={time:null,delay:0,duration:250,ease:Ba};function Va(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function Ha(e){var t,n;e instanceof Q?(t=e._id,e=e._name):(t=ln(),(n=Xa).time=se(),e=e==null?null:e+"");for(var i=this._groups,s=i.length,a=0;a<s;++a)for(var r=i[a],o=r.length,c,l=0;l<o;++l)(c=r[l])&&Xt(c,e,t,l,r,n||Va(c,t));return new Q(i,this._parents,e,t)}pt.prototype.interrupt=Bs,pt.prototype.transition=Ha;const he=Math.PI,ue=2*he,ot=1e-6,Da=ue-ot;function cn(e){this._+=e[0];for(let t=1,n=e.length;t<n;++t)this._+=arguments[t]+e[t]}function Oa(e){let t=Math.floor(e);if(!(t>=0))throw new Error(`invalid digits: ${e}`);if(t>15)return cn;const n=10**t;return function(i){this._+=i[0];for(let s=1,a=i.length;s<a;++s)this._+=Math.round(arguments[s]*n)/n+i[s]}}class Ia{constructor(t){this._x0=this._y0=this._x1=this._y1=null,this._="",this._append=t==null?cn:Oa(t)}moveTo(t,n){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+n}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._append`Z`)}lineTo(t,n){this._append`L${this._x1=+t},${this._y1=+n}`}quadraticCurveTo(t,n,i,s){this._append`Q${+t},${+n},${this._x1=+i},${this._y1=+s}`}bezierCurveTo(t,n,i,s,a,r){this._append`C${+t},${+n},${+i},${+s},${this._x1=+a},${this._y1=+r}`}arcTo(t,n,i,s,a){if(t=+t,n=+n,i=+i,s=+s,a=+a,a<0)throw new Error(`negative radius: ${a}`);let r=this._x1,o=this._y1,c=i-t,l=s-n,h=r-t,u=o-n,f=h*h+u*u;if(this._x1===null)this._append`M${this._x1=t},${this._y1=n}`;else if(f>ot)if(!(Math.abs(u*c-l*h)>ot)||!a)this._append`L${this._x1=t},${this._y1=n}`;else{let d=i-r,b=s-o,m=c*c+l*l,S=d*d+b*b,y=Math.sqrt(m),T=Math.sqrt(f),$=a*Math.tan((he-Math.acos((m+f-S)/(2*y*T)))/2),g=$/T,z=$/y;Math.abs(g-1)>ot&&this._append`L${t+g*h},${n+g*u}`,this._append`A${a},${a},0,0,${+(u*d>h*b)},${this._x1=t+z*c},${this._y1=n+z*l}`}}arc(t,n,i,s,a,r){if(t=+t,n=+n,i=+i,r=!!r,i<0)throw new Error(`negative radius: ${i}`);let o=i*Math.cos(s),c=i*Math.sin(s),l=t+o,h=n+c,u=1^r,f=r?s-a:a-s;this._x1===null?this._append`M${l},${h}`:(Math.abs(this._x1-l)>ot||Math.abs(this._y1-h)>ot)&&this._append`L${l},${h}`,i&&(f<0&&(f=f%ue+ue),f>Da?this._append`A${i},${i},0,1,${u},${t-o},${n-c}A${i},${i},0,1,${u},${this._x1=l},${this._y1=h}`:f>ot&&this._append`A${i},${i},0,${+(f>=he)},${u},${this._x1=t+i*Math.cos(a)},${this._y1=n+i*Math.sin(a)}`)}rect(t,n,i,s){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+n}h${i=+i}v${+s}h${-i}Z`}toString(){return this._}}function Ya(e,t){return e.parent===t.parent?1:2}function qa(e){return e.reduce(Ga,0)/e.length}function Ga(e,t){return e+t.x}function Za(e){return 1+e.reduce(Ua,0)}function Ua(e,t){return Math.max(e,t.y)}function Wa(e){for(var t;t=e.children;)e=t[0];return e}function Ka(e){for(var t;t=e.children;)e=t[t.length-1];return e}function Qa(){var e=Ya,t=1,n=1,i=!1;function s(a){var r,o=0;a.eachAfter(function(f){var d=f.children;d?(f.x=qa(d),f.y=Za(d)):(f.x=r?o+=e(f,r):0,f.y=0,r=f)});var c=Wa(a),l=Ka(a),h=c.x-e(c,l)/2,u=l.x+e(l,c)/2;return a.eachAfter(i?function(f){f.x=(f.x-a.x)*t,f.y=(a.y-f.y)*n}:function(f){f.x=(f.x-h)/(u-h)*t,f.y=(1-(a.y?f.y/a.y:1))*n})}return s.separation=function(a){return arguments.length?(e=a,s):e},s.size=function(a){return arguments.length?(i=!1,t=+a[0],n=+a[1],s):i?null:[t,n]},s.nodeSize=function(a){return arguments.length?(i=!0,t=+a[0],n=+a[1],s):i?[t,n]:null},s}function Ja(e){var t=0,n=e.children,i=n&&n.length;if(!i)t=1;else for(;--i>=0;)t+=n[i].value;e.value=t}function ja(){return this.eachAfter(Ja)}function tr(e,t){let n=-1;for(const i of this)e.call(t,i,++n,this);return this}function er(e,t){for(var n=this,i=[n],s,a,r=-1;n=i.pop();)if(e.call(t,n,++r,this),s=n.children)for(a=s.length-1;a>=0;--a)i.push(s[a]);return this}function nr(e,t){for(var n=this,i=[n],s=[],a,r,o,c=-1;n=i.pop();)if(s.push(n),a=n.children)for(r=0,o=a.length;r<o;++r)i.push(a[r]);for(;n=s.pop();)e.call(t,n,++c,this);return this}function ir(e,t){let n=-1;for(const i of this)if(e.call(t,i,++n,this))return i}function sr(e){return this.eachAfter(function(t){for(var n=+e(t.data)||0,i=t.children,s=i&&i.length;--s>=0;)n+=i[s].value;t.value=n})}function ar(e){return this.eachBefore(function(t){t.children&&t.children.sort(e)})}function rr(e){for(var t=this,n=or(t,e),i=[t];t!==n;)t=t.parent,i.push(t);for(var s=i.length;e!==n;)i.splice(s,0,e),e=e.parent;return i}function or(e,t){if(e===t)return e;var n=e.ancestors(),i=t.ancestors(),s=null;for(e=n.pop(),t=i.pop();e===t;)s=e,e=n.pop(),t=i.pop();return s}function lr(){for(var e=this,t=[e];e=e.parent;)t.push(e);return t}function cr(){return Array.from(this)}function hr(){var e=[];return this.eachBefore(function(t){t.children||e.push(t)}),e}function ur(){var e=this,t=[];return e.each(function(n){n!==e&&t.push({source:n.parent,target:n})}),t}function*dr(){var e=this,t,n=[e],i,s,a;do for(t=n.reverse(),n=[];e=t.pop();)if(yield e,i=e.children)for(s=0,a=i.length;s<a;++s)n.push(i[s]);while(n.length)}function de(e,t){e instanceof Map?(e=[void 0,e],t===void 0&&(t=mr)):t===void 0&&(t=pr);for(var n=new Ht(e),i,s=[n],a,r,o,c;i=s.pop();)if((r=t(i.data))&&(c=(r=Array.from(r)).length))for(i.children=r,o=c-1;o>=0;--o)s.push(a=r[o]=new Ht(r[o])),a.parent=i,a.depth=i.depth+1;return n.eachBefore(xr)}function fr(){return de(this).eachBefore(gr)}function pr(e){return e.children}function mr(e){return Array.isArray(e)?e[1]:null}function gr(e){e.data.value!==void 0&&(e.value=e.data.value),e.data=e.data.data}function xr(e){var t=0;do e.height=t;while((e=e.parent)&&e.height<++t)}function Ht(e){this.data=e,this.depth=this.height=0,this.parent=null}Ht.prototype=de.prototype={constructor:Ht,count:ja,each:tr,eachAfter:nr,eachBefore:er,find:ir,sum:sr,sort:ar,path:rr,ancestors:lr,descendants:cr,leaves:hr,links:ur,copy:fr,[Symbol.iterator]:dr};function Dt(e){return function(){return e}}const fe=Math.sqrt,hn=Math.PI,yr=2*hn;function br(e){let t=3;return e.digits=function(n){if(!arguments.length)return t;if(n==null)t=null;else{const i=Math.floor(n);if(!(i>=0))throw new RangeError(`invalid digits: ${n}`);t=i}return e},()=>new Ia(t)}const wr={draw(e,t){const n=fe(t/hn);e.moveTo(n,0),e.arc(0,0,n,0,yr)}},pe=fe(3),vr={draw(e,t){const n=-fe(t/(pe*3));e.moveTo(0,n*2),e.lineTo(-pe*n,-n),e.lineTo(pe*n,-n),e.closePath()}};function _r(e,t){let n=null,i=br(s);e=typeof e=="function"?e:Dt(e||wr),t=typeof t=="function"?t:Dt(t===void 0?64:+t);function s(){let a;if(n||(n=a=i()),e.apply(this,arguments).draw(n,+t.apply(this,arguments)),a)return n=null,a+""||null}return s.type=function(a){return arguments.length?(e=typeof a=="function"?a:Dt(a),s):e},s.size=function(a){return arguments.length?(t=typeof a=="function"?a:Dt(+a),s):t},s.context=function(a){return arguments.length?(n=a??null,s):n},s}const Ot=e=>()=>e;function Sr(e,{sourceEvent:t,target:n,transform:i,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:i,enumerable:!0,configurable:!0},_:{value:s}})}function j(e,t,n){this.k=e,this.x=t,this.y=n}j.prototype={constructor:j,scale:function(e){return e===1?this:new j(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new j(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var me=new j(1,0,0);j.prototype;function ge(e){e.stopImmediatePropagation()}function St(e){e.preventDefault(),e.stopImmediatePropagation()}function Tr(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Cr(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function un(){return this.__zoom||me}function Lr(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Mr(){return navigator.maxTouchPoints||"ontouchstart"in this}function Pr(e,t,n){var i=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],a=e.invertY(t[0][1])-n[0][1],r=e.invertY(t[1][1])-n[1][1];return e.translate(s>i?(i+s)/2:Math.min(0,i)||Math.max(0,s),r>a?(a+r)/2:Math.min(0,a)||Math.max(0,r))}function Er(){var e=Tr,t=Cr,n=Pr,i=Lr,s=Mr,a=[0,1/0],r=[[-1/0,-1/0],[1/0,1/0]],o=250,c=Es,l=Gt("start","zoom","end"),h,u,f,d=500,b=150,m=0,S=10;function y(p){p.property("__zoom",un).on("wheel.zoom",v,{passive:!1}).on("mousedown.zoom",L).on("dblclick.zoom",M).filter(s).on("touchstart.zoom",R).on("touchmove.zoom",k).on("touchend.zoom touchcancel.zoom",X).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}y.transform=function(p,w,x,P){var _=p.selection?p.selection():p;_.property("__zoom",un),p!==_?z(p,w,x,P):_.interrupt().each(function(){A(this,arguments).event(P).start().zoom(null,typeof w=="function"?w.apply(this,arguments):w).end()})},y.scaleBy=function(p,w,x,P){y.scaleTo(p,function(){var _=this.__zoom.k,C=typeof w=="function"?w.apply(this,arguments):w;return _*C},x,P)},y.scaleTo=function(p,w,x,P){y.transform(p,function(){var _=t.apply(this,arguments),C=this.__zoom,E=x==null?g(_):typeof x=="function"?x.apply(this,arguments):x,F=C.invert(E),B=typeof w=="function"?w.apply(this,arguments):w;return n($(T(C,B),E,F),_,r)},x,P)},y.translateBy=function(p,w,x,P){y.transform(p,function(){return n(this.__zoom.translate(typeof w=="function"?w.apply(this,arguments):w,typeof x=="function"?x.apply(this,arguments):x),t.apply(this,arguments),r)},null,P)},y.translateTo=function(p,w,x,P,_){y.transform(p,function(){var C=t.apply(this,arguments),E=this.__zoom,F=P==null?g(C):typeof P=="function"?P.apply(this,arguments):P;return n(me.translate(F[0],F[1]).scale(E.k).translate(typeof w=="function"?-w.apply(this,arguments):-w,typeof x=="function"?-x.apply(this,arguments):-x),C,r)},P,_)};function T(p,w){return w=Math.max(a[0],Math.min(a[1],w)),w===p.k?p:new j(w,p.x,p.y)}function $(p,w,x){var P=w[0]-x[0]*p.k,_=w[1]-x[1]*p.k;return P===p.x&&_===p.y?p:new j(p.k,P,_)}function g(p){return[(+p[0][0]+ +p[1][0])/2,(+p[0][1]+ +p[1][1])/2]}function z(p,w,x,P){p.on("start.zoom",function(){A(this,arguments).event(P).start()}).on("interrupt.zoom end.zoom",function(){A(this,arguments).event(P).end()}).tween("zoom",function(){var _=this,C=arguments,E=A(_,C).event(P),F=t.apply(_,C),B=x==null?g(F):typeof x=="function"?x.apply(_,C):x,K=Math.max(F[1][0]-F[0][0],F[1][1]-F[0][1]),H=_.__zoom,q=typeof w=="function"?w.apply(_,C):w,tt=c(H.invert(B).concat(K/H.k),q.invert(B).concat(K/q.k));return function(G){if(G===1)G=q;else{var et=tt(G),be=K/et[2];G=new j(be,B[0]-et[0]*be,B[1]-et[1]*be)}E.zoom(null,G)}})}function A(p,w,x){return!x&&p.__zooming||new N(p,w)}function N(p,w){this.that=p,this.args=w,this.active=0,this.sourceEvent=null,this.extent=t.apply(p,w),this.taps=0}N.prototype={event:function(p){return p&&(this.sourceEvent=p),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(p,w){return this.mouse&&p!=="mouse"&&(this.mouse[1]=w.invert(this.mouse[0])),this.touch0&&p!=="touch"&&(this.touch0[1]=w.invert(this.touch0[0])),this.touch1&&p!=="touch"&&(this.touch1[1]=w.invert(this.touch1[0])),this.that.__zoom=w,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(p){var w=Z(this.that).datum();l.call(p,this.that,new Sr(p,{sourceEvent:this.sourceEvent,target:y,transform:this.that.__zoom,dispatch:l}),w)}};function v(p,...w){if(!e.apply(this,arguments))return;var x=A(this,w).event(p),P=this.__zoom,_=Math.max(a[0],Math.min(a[1],P.k*Math.pow(2,i.apply(this,arguments)))),C=it(p);if(x.wheel)(x.mouse[0][0]!==C[0]||x.mouse[0][1]!==C[1])&&(x.mouse[1]=P.invert(x.mouse[0]=C)),clearTimeout(x.wheel);else{if(P.k===_)return;x.mouse=[C,P.invert(C)],Vt(this),x.start()}St(p),x.wheel=setTimeout(E,b),x.zoom("mouse",n($(T(P,_),x.mouse[0],x.mouse[1]),x.extent,r));function E(){x.wheel=null,x.end()}}function L(p,...w){if(f||!e.apply(this,arguments))return;var x=p.currentTarget,P=A(this,w,!0).event(p),_=Z(p.view).on("mousemove.zoom",B,!0).on("mouseup.zoom",K,!0),C=it(p,x),E=p.clientX,F=p.clientY;ns(p.view),ge(p),P.mouse=[C,this.__zoom.invert(C)],Vt(this),P.start();function B(H){if(St(H),!P.moved){var q=H.clientX-E,tt=H.clientY-F;P.moved=q*q+tt*tt>m}P.event(H).zoom("mouse",n($(P.that.__zoom,P.mouse[0]=it(H,x),P.mouse[1]),P.extent,r))}function K(H){_.on("mousemove.zoom mouseup.zoom",null),is(H.view,P.moved),St(H),P.event(H).end()}}function M(p,...w){if(e.apply(this,arguments)){var x=this.__zoom,P=it(p.changedTouches?p.changedTouches[0]:p,this),_=x.invert(P),C=x.k*(p.shiftKey?.5:2),E=n($(T(x,C),P,_),t.apply(this,w),r);St(p),o>0?Z(this).transition().duration(o).call(z,E,P,p):Z(this).call(y.transform,E,P,p)}}function R(p,...w){if(e.apply(this,arguments)){var x=p.touches,P=x.length,_=A(this,w,p.changedTouches.length===P).event(p),C,E,F,B;for(ge(p),E=0;E<P;++E)F=x[E],B=it(F,this),B=[B,this.__zoom.invert(B),F.identifier],_.touch0?!_.touch1&&_.touch0[2]!==B[2]&&(_.touch1=B,_.taps=0):(_.touch0=B,C=!0,_.taps=1+!!h);h&&(h=clearTimeout(h)),C&&(_.taps<2&&(u=B[0],h=setTimeout(function(){h=null},d)),Vt(this),_.start())}}function k(p,...w){if(this.__zooming){var x=A(this,w).event(p),P=p.changedTouches,_=P.length,C,E,F,B;for(St(p),C=0;C<_;++C)E=P[C],F=it(E,this),x.touch0&&x.touch0[2]===E.identifier?x.touch0[0]=F:x.touch1&&x.touch1[2]===E.identifier&&(x.touch1[0]=F);if(E=x.that.__zoom,x.touch1){var K=x.touch0[0],H=x.touch0[1],q=x.touch1[0],tt=x.touch1[1],G=(G=q[0]-K[0])*G+(G=q[1]-K[1])*G,et=(et=tt[0]-H[0])*et+(et=tt[1]-H[1])*et;E=T(E,Math.sqrt(G/et)),F=[(K[0]+q[0])/2,(K[1]+q[1])/2],B=[(H[0]+tt[0])/2,(H[1]+tt[1])/2]}else if(x.touch0)F=x.touch0[0],B=x.touch0[1];else return;x.zoom("touch",n($(E,F,B),x.extent,r))}}function X(p,...w){if(this.__zooming){var x=A(this,w).event(p),P=p.changedTouches,_=P.length,C,E;for(ge(p),f&&clearTimeout(f),f=setTimeout(function(){f=null},d),C=0;C<_;++C)E=P[C],x.touch0&&x.touch0[2]===E.identifier?delete x.touch0:x.touch1&&x.touch1[2]===E.identifier&&delete x.touch1;if(x.touch1&&!x.touch0&&(x.touch0=x.touch1,delete x.touch1),x.touch0)x.touch0[1]=this.__zoom.invert(x.touch0[0]);else if(x.end(),x.taps===2&&(E=it(E,this),Math.hypot(u[0]-E[0],u[1]-E[1])<S)){var F=Z(this).on("dblclick.zoom");F&&F.apply(this,arguments)}}}return y.wheelDelta=function(p){return arguments.length?(i=typeof p=="function"?p:Ot(+p),y):i},y.filter=function(p){return arguments.length?(e=typeof p=="function"?p:Ot(!!p),y):e},y.touchable=function(p){return arguments.length?(s=typeof p=="function"?p:Ot(!!p),y):s},y.extent=function(p){return arguments.length?(t=typeof p=="function"?p:Ot([[+p[0][0],+p[0][1]],[+p[1][0],+p[1][1]]]),y):t},y.scaleExtent=function(p){return arguments.length?(a[0]=+p[0],a[1]=+p[1],y):[a[0],a[1]]},y.translateExtent=function(p){return arguments.length?(r[0][0]=+p[0][0],r[1][0]=+p[1][0],r[0][1]=+p[0][1],r[1][1]=+p[1][1],y):[[r[0][0],r[0][1]],[r[1][0],r[1][1]]]},y.constrain=function(p){return arguments.length?(n=p,y):n},y.duration=function(p){return arguments.length?(o=+p,y):o},y.interpolate=function(p){return arguments.length?(c=p,y):c},y.on=function(){var p=l.on.apply(l,arguments);return p===l?y:p},y.clickDistance=function(p){return arguments.length?(m=(p=+p)*p,y):Math.sqrt(m)},y.tapDistance=function(p){return arguments.length?(S=+p,y):S},y}function dn(e){const t=Math.floor(Math.log10(e)),n=e/Math.pow(10,t);let i;return n<=1?i=1:n<=2?i=2:n<=5?i=5:i=10,i*Math.pow(10,t)}function $r(e){return .4330127*e*e}function fn(e,t,n){const i=n*2-1,s=e-(n-1)*t;let a=0;for(let c=1;c<=n;c++)a+=c;const r=s/a,o=[];for(let c=0;c<i;c++)c%2===0?o.push(r*(n-c/2)):o.push(t);return o.join(",")}function zr(e,t={}){const{capitalizeFirstOnly:n=!0,preserveAcronyms:i=!0}=t;let s=e;return s=s.replace(/[_]/g," "),i?s=s.replace(/([a-z])([A-Z])/g,"$1 $2"):s=s.replace(/([A-Z])/g," $1"),n?s=s.charAt(0).toUpperCase()+s.slice(1).toLowerCase():s=s.replace(/\b\w/g,a=>a.toUpperCase()),s.trim().replace(/\s+/g," ")}function pn(e,t,n=5){const i=t-e;if(i===0)return[e];const s=i/(n-1),a=Math.pow(10,Math.floor(Math.log10(s))),r=s/a;let o;r<=1?o=1:r<=2?o=2:r<=5?o=5:o=10;const c=o*a,l=Math.floor(e/c)*c,h=[];let u=l;for(;u<=t+c*.001;)u>=e-c*.001&&h.push(u),u+=c;return(h.length===0||h[0]>e)&&h.unshift(e),h[h.length-1]<t&&h.push(t),h}function It(e,t){const n=Math.max(...t)-Math.min(...t),i=t.length>1?Math.abs(t[1]-t[0]):n;if(n===0)return e.toPrecision(3);const s=Math.floor(Math.log10(Math.abs(i)));if(s>=0)return Math.round(e).toString();{const a=Math.min(3,-s);return e.toFixed(a)}}class mn{constructor(){this.subscribers=new Map}subscribe(t,n){return this.subscribers.has(t)||this.subscribers.set(t,new Set),this.subscribers.get(t).add(n),()=>this.unsubscribe(t,n)}unsubscribe(t,n){this.subscribers.has(t)&&this.subscribers.get(t).delete(n)}notify(t,n){this.subscribers.has(t)&&this.subscribers.get(t).forEach(i=>{i(n)})}}function Ar(e){e=e.trim(),e[e.length-1]===";"&&(e=e.slice(0,-1));let t=0;function n(){let s={};if(e[t]==="(")for(t++,s.children=[];;){let r=n();if(s.children.push(r),e[t]===",")t++;else if(e[t]===")"){t++;break}else break}let a="";for(;t<e.length&&e[t]!==","&&e[t]!==")";)a+=e[t++];if(a=a.trim(),a){let r=a.split(":");s.name=r[0]||"",r.length>1&&(s.length=parseFloat(r[1]))}return s}const i=n();if(t!==e.length)throw new Error(`Unexpected character at position ${t}: '${e[t]}'`);return i}function Nr(e,t=" "){let n=new Map,i=[],s=new Map;const a=e.trim().split(`
2
+ `);if(a.length==0)console.error("Empty metatdata table");else{const r=a[0].split(t),o=r.indexOf("node_id");if(o===-1)console.warn('Metadata table must contain a "node_id" column');else{i=r.filter((l,h)=>h!==o);const c=new Map;i.forEach(l=>c.set(l,[]));for(let l=1;l<a.length;l++){const h=a[l].split(t),u=h[o],f={};for(let d=0;d<r.length;d++)if(d!==o){const b=r[d],m=h[d];f[b]=m,c.get(b).push(m)}n.set(u,f)}i.forEach(l=>{const h=c.get(l),u=h.map(d=>parseFloat(d)).filter(d=>!isNaN(d)),f=u.length>0&&u.length===h.filter(d=>d!=="").length;s.set(l,f?"continuous":"categorical")})}}return{metadataMap:n,columnTypes:s}}class Yt{defaultValue;constructor(t){t===void 0?console.error("A defualt value for a NullScale is needed."):this.defaultValue=t}getValue(){return this.defaultValue}}class kr{constructor(t=null,n=null,i=null){this.validValues=n?new Set(n):null,this.transformFn=i,this.defaultValue=t}getValue(t){let n=this.transformFn?this.transformFn(t):t;return this.validValues!==null&&!this.validValues.has(n)&&(n=null),(n==null||n==="")&&(n=this.defaultValue),n}}class Rr{constructor(t,n,i){if(!Array.isArray(t)||t.length===0)throw new Error("values must be a non-empty array");this.outputCategories=n,this.defaultValue=i;const s=new Map;for(const o of t)o==null||o===""||(s.has(o)?s.set(o,s.get(o)+1):s.set(o,1));const a=new Map([...s.entries()].sort((o,c)=>o[0]-c[0]));a.length>n.length?this.otheredCategories=a.keys().slice(n.length-2,a.length):this.otheredCategories=[],this.categoryMap=new Map;const r=[...a.keys()];for(let o=0;o<r.length;o++)o<n.length?this.categoryMap.set(r[o],n[o]):this.categoryMap.set(r[o],n[n.length-1])}getValue(t){return t==null||t===""?this.defaultValue:this.categoryMap.get(t)}}class Fr{constructor(t,n,i,s){this.dataMin=t,this.dataMax=n,this.sizeMin=i,this.sizeMax=s}getValue(t){const n=Math.max(this.dataMin,Math.min(this.dataMax,t));if(this.dataMin===this.dataMax)return t===this.dataMax?(this.sizeMin+this.sizeMax)/2:t<this.dataMin?this.sizeMin:this.sizeMax;const i=(n-this.dataMin)/(this.dataMax-this.dataMin);return this.sizeMin+i*(this.sizeMax-this.sizeMin)}}class Br{constructor(t,n,i=0,s=1,a=null,r=null){if(this.dataMin=t,this.dataMax=n,this.transformMin=i,this.transformMax=s,this.nullColor="#808080",a===null)this.colors=["#440154","#31688e","#35b779","#fde724"].map(o=>this._hexToRgb(o));else{if(a.length<1)throw new Error("At least 1 color is required");this.colors=a.map(o=>this._hexToRgb(o))}if(this.colors.length===1){this.colorPositions=[0];return}if(r===null)this.colorPositions=this.colors.map((o,c)=>c/(this.colors.length-1));else{if(r.length!==this.colors.length)throw new Error("colorPositions must have the same length as colors");const o=r.map((h,u)=>({pos:h,color:this.colors[u]}));o.sort((h,u)=>h.pos-u.pos),this.colorPositions=o.map(h=>h.pos),this.colors=o.map(h=>h.color);const c=this.colorPositions[0],l=this.colorPositions[this.colorPositions.length-1];c===l?this.colorPositions=this.colorPositions.map(()=>0):this.colorPositions=this.colorPositions.map(h=>(h-c)/(l-c))}}getValue(t){if(t==null||t==="")return this.nullColor;if(this.colors.length===1)return this._rgbToHex(this.colors[0].r,this.colors[0].g,this.colors[0].b);if(this.dataMin===this.dataMax){if(t<this.dataMin)return this._rgbToHex(this.colors[0].r,this.colors[0].g,this.colors[0].b);if(t>this.dataMax){const l=this.colors[this.colors.length-1];return this._rgbToHex(l.r,l.g,l.b)}else{const l=Math.floor(this.colors.length/2),h=this.colors[l];return this._rgbToHex(h.r,h.g,h.b)}}const i=(Math.max(this.dataMin,Math.min(this.dataMax,t))-this.dataMin)/(this.dataMax-this.dataMin),s=this.transformMin+i*(this.transformMax-this.transformMin),a=Math.max(0,Math.min(1,s));if(a<=this.colorPositions[0])return this._rgbToHex(this.colors[0].r,this.colors[0].g,this.colors[0].b);if(a>=this.colorPositions[this.colorPositions.length-1]){const l=this.colors[this.colors.length-1];return this._rgbToHex(l.r,l.g,l.b)}let r=0;for(let l=0;l<this.colorPositions.length-1;l++)a>=this.colorPositions[l]&&(r=l);const o=Math.min(r+1,this.colors.length-1);if(a===this.colorPositions[r]){const l=this.colors[r];return this._rgbToHex(l.r,l.g,l.b)}if(a===this.colorPositions[o]){const l=this.colors[o];return this._rgbToHex(l.r,l.g,l.b)}const c=(a-this.colorPositions[r])/(this.colorPositions[o]-this.colorPositions[r]);return this._interpolateColor(this.colors[r],this.colors[o],c)}_interpolateColor(t,n,i){const s=Math.round(t.r+(n.r-t.r)*i),a=Math.round(t.g+(n.g-t.g)*i),r=Math.round(t.b+(n.b-t.b)*i);return this._rgbToHex(s,a,r)}_hexToRgb(t){const n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return n?{r:parseInt(n[1],16),g:parseInt(n[2],16),b:parseInt(n[3],16)}:null}_rgbToHex(t,n,i){return"#"+[t,n,i].map(s=>{const a=s.toString(16);return a.length===1?"0"+a:a}).join("")}}class Xr{defaultPalette=["#440154","#31688e","#35b779","#fde724"];constructor(t,n=0,i=1,s=null,a=null,r=10){if(!Array.isArray(t)||t.length===0)throw new Error("categoryData must be a non-empty array");this.transformMin=n,this.transformMax=i,this.nullColor="#808080",this.maxColors=r,this.frequencyMap=new Map;for(const o of t)this.frequencyMap.has(o)?this.frequencyMap.set(o,this.frequencyMap.get(o)+1):this.frequencyMap.set(o,1);if(this.categories=[...this.frequencyMap.entries()].sort((o,c)=>c[1]-o[1]).map(o=>o[0]),s===null)this.colors=this.defaultPalette.map(o=>this._hexToRgb(o));else{if(s.length<1)throw new Error("At least 1 color is required");this.colors=s.map(o=>this._hexToRgb(o))}if(this.colors.length===1){this.colorPositions=[0],this._assignColors();return}if(a===null)this.colorPositions=this.colors.map((o,c)=>c/(this.colors.length-1));else{if(a.length!==this.colors.length)throw new Error("colorPositions must have the same length as colors");const o=a.map((h,u)=>({pos:h,color:this.colors[u]}));o.sort((h,u)=>h.pos-u.pos),this.colorPositions=o.map(h=>h.pos),this.colors=o.map(h=>h.color);const c=this.colorPositions[0],l=this.colorPositions[this.colorPositions.length-1];c===l?this.colorPositions=this.colorPositions.map(()=>0):this.colorPositions=this.colorPositions.map(h=>(h-c)/(l-c))}this._assignColors()}_assignColors(){if(this.categoryColorMap=new Map,this.colors.length===1){const t=this._rgbToHex(this.colors[0].r,this.colors[0].g,this.colors[0].b);for(const n of this.categories)this.categoryColorMap.set(n,t);return}if(this.categories.length===1){const t=this._getColorAtPosition(this.transformMin);this.categoryColorMap.set(this.categories[0],t)}else{const t=this.categories.length>this.maxColors?this.maxColors:this.categories.length;for(let n=0;n<this.categories.length;n++){const i=n>=t?1:n/(t-1),s=this.transformMin+i*(this.transformMax-this.transformMin),a=this._getColorAtPosition(s);this.categoryColorMap.set(this.categories[n],a)}}}_getColorAtPosition(t){if(t=Math.max(0,Math.min(1,t)),this.colors.length===1)return this._rgbToHex(this.colors[0].r,this.colors[0].g,this.colors[0].b);if(t<=this.colorPositions[0])return this._rgbToHex(this.colors[0].r,this.colors[0].g,this.colors[0].b);if(t>=this.colorPositions[this.colorPositions.length-1]){const a=this.colors[this.colors.length-1];return this._rgbToHex(a.r,a.g,a.b)}let n=0;for(let a=0;a<this.colorPositions.length-1;a++)t>=this.colorPositions[a]&&(n=a);const i=Math.min(n+1,this.colors.length-1);if(t===this.colorPositions[n]){const a=this.colors[n];return this._rgbToHex(a.r,a.g,a.b)}if(t===this.colorPositions[i]){const a=this.colors[i];return this._rgbToHex(a.r,a.g,a.b)}const s=(t-this.colorPositions[n])/(this.colorPositions[i]-this.colorPositions[n]);return this._interpolateColor(this.colors[n],this.colors[i],s)}getValue(t){if(t==null||t==="")return this.nullColor;if(this.categoryColorMap.has(t))return this.categoryColorMap.get(t);throw new Error(`Unknown category: ${t}`)}_interpolateColor(t,n,i){const s=Math.round(t.r+(n.r-t.r)*i),a=Math.round(t.g+(n.g-t.g)*i),r=Math.round(t.b+(n.b-t.b)*i);return this._rgbToHex(s,a,r)}_hexToRgb(t){const n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return n?{r:parseInt(n[1],16),g:parseInt(n[2],16),b:parseInt(n[3],16)}:null}_rgbToHex(t,n,i){return"#"+[t,n,i].map(s=>{const a=s.toString(16);return a.length===1?"0"+a:a}).join("")}}class Vr{state;scale;constructor(t,n={}){if(!n.scaleType)throw new Error("scaleType is required");if(n.default===void 0)throw new Error("default is required");this.state={scaleType:void 0,default:void 0,isCategorical:void 0,outputValues:null,outputRegex:null,colorPalette:null,outputRange:null,inputUnits:null,title:null,maxCategories:7,otherCategory:"#888888",otherLabel:"Other",transformMin:0,transformMax:1,transformFn:null,colorPositions:null,...n},this.updateScale(t)}setScale(t){this.scale=t}getValue(t){return this.scale.getValue(t)}updateScale(t){const{scaleType:n,isCategorical:i}=this.state;let s;if(n==="null"){s=new Yt(this.state.default),this.setScale(s);return}let a=!0;if(i&&(this.state.outputValues||this.state.outputRegex)){if(this.state.outputValues){for(let r=0;r<t.length;r++)if(t[r]&&!this.state.outputValues.includes(t[r])){a=!1;break}}if(this.state.outputRegex){for(let r=0;r<t.length;r++)if(t[r]&&!this.state.outputRegex.test(t[r])){a=!1;break}}}else a=!1;if(n==="identity"||a){s=new kr(this.state.default,this.state.outputValues,this.state.transformFn),this.setScale(s);return}if(n==="text"){if(!i)throw new Error("Text scales can only be used with categorical data");s=new Rr(t,this.state.outputValues,this.state.default),this.setScale(s);return}if(n==="size"){if(i)throw new Error("Size scales can only be used with continuous data");const r=t.map(o=>Number(o)).filter(o=>!isNaN(o));if(r.length===0)console.warn("No numeric values found for size scale, using NullScale"),s=new Yt(this.state.default);else{const o=Math.min(...r),c=Math.max(...r),l=this.state.outputRange||[.5,2];s=new Fr(o,c,l[0],l[1])}this.setScale(s);return}if(n==="color"){if(i)s=new Xr(t,this.state.transformMin,this.state.transformMax,this.state.colorPalette,this.state.colorPositions,this.state.maxCategories);else{const r=t.map(o=>Number(o)).filter(o=>!isNaN(o));if(r.length===0)console.warn("No numeric values found for color scale, using NullScale"),s=new Yt(this.state.default);else{const o=Math.min(...r),c=Math.max(...r);s=new Br(o,c,this.state.transformMin,this.state.transformMax,this.state.colorPalette,this.state.colorPositions)}}this.setScale(s);return}throw new Error(`Unknown scale type: ${n}`)}}class gn extends mn{tree;metadata=new Map;metadataTableNames=new Map;columnType=new Map;columnName=new Map;columnDisplayName=new Map;columnAesthetic=new Map;#t=0;constructor(t,n=[],i=[]){super(),this.tree=this.parseTree(t),Array.isArray(n)&&n.forEach((s,a)=>{const r=i[a]||`Metadata ${a+1}`;this.addTable(s,r)})}parseTree(t){const n=Ar(t),i=de(n,a=>a.children).sum(a=>a.children?0:1).each(function(a){a.leafCount=a.value,delete a.value,delete a.data.children}).sort((a,r)=>a.leafCount-r.leafCount||ft(a.data.length,r.data.length));let s=0;return i.each(a=>{a.id=++s}),i}setTree(t){this.tree=this.parseTree(t),this.metadata.keys().forEach(this.#n),this.notify("treeUpdated",this)}getMetadataTableNames(){return Array.from(this.metadataTableNames.values())}addTable(t,n=null,i=" "){const{metadataMap:s,columnTypes:a}=Nr(t,i),r=`table_${this.#t++}`;n||(n=`Metadata ${this.#t}`),this.metadataTableNames.set(r,n);const o=new Map;for(const[l,h]of a){const u=`${r}_${l}`;o.set(l,u),this.columnType.set(u,h),this.columnName.set(u,l),this.columnDisplayName.set(u,zr(l))}const c=new Map;for(const[l,h]of s){const u={};for(const[f,d]of Object.entries(h)){const b=o.get(f);b&&(u[b]=d)}c.set(l,u)}return this.metadata.set(r,c),this.#n(r),this.notify("metadataAdded",{tableId:r,columnIds:o.values()}),r}deleteTable(t){const n=this.metadata.get(t);if(!n){console.warn(`Table ${t} does not exist`);return}const i=Object.keys(n.values().next().value);for(const s of i)this.columnType.delete(s),this.columnName.delete(s),this.columnDisplayName.delete(s),this.columnAesthetic.delete(s);this.#s(t),this.metadata.delete(t),this.metadataTableNames.delete(t),this.notify("metadataRemoved",{tableId:t,columnIds:i})}getAesthetic(t,n,i={}){this.columnAesthetic.has(t)||this.columnAesthetic.set(t,new Map);const s=this.columnAesthetic.get(t);if(s.has(n))return s.get(n);const a=this.#e(t,i);return s.set(n,a),a}setAesthetic(t,n,i){this.columnAesthetic.has(t)||this.columnAesthetic.set(t,new Map),this.columnAesthetic.get(t).set(n,i)}#e(t,n={}){const i=this.columnType.get(t),s=i==="categorical";i||console.error(`Column ${t} not found`);let a=[];this.tree.each(c=>{c.metadata&&c.metadata[t]!==void 0&&a.push(c.metadata[t])}),a.length===0&&console.error(`No values found for column ${t}`);const r=this.columnDisplayName.get(t)||t;return new Vr(a,{isCategorical:s,inputUnits:r,...n})}#n(t){const n=this.metadata.get(t);this.tree.each(i=>{const s=i.data.name;if(s&&n.has(s)){const a=n.get(s);i.metadata={...i.metadata,...a}}})}#s(t){const n=this.metadata.get(t),i=Object.keys(n.values().next().value);this.tree.each(s=>{i.forEach(a=>{delete s[a]})})}}function Hr(e,t){const n=e.leaves().map(m=>({x:m.x,width:(m.tipLabelBounds.width+t.nodeLabelOffset)*m.tipLabelSize,height:m.tipLabelBounds.height*m.tipLabelSize,labelScale:m.tipLabelSize}));let i=0,s=1/0,a=0,r=1/0;function o(m){m<s&&(m<i?s=i:s=m)}function c(m){m>i&&(m>s?i=s:i=m)}function l(m){m<r&&(m<a?r=a:r=m)}function h(m){m>a&&(m>r?a=r:a=m)}const u=Math.min(...n.map(m=>m.labelScale)),f=Math.max(...n.map(m=>m.x)),d=e.descendants().filter(m=>m.data.length>0&&m.children),b=d.length>0?Math.min(...d.map(m=>m.data.length)):1/0;return h(t.minFontPx/u),c(Math.max(...n.map(m=>m.width*a/(f/t.minBranchLenProp-m.x)))),o(Math.min(...n.map(m=>(t.viewWidth-m.width*a)/m.x))),l(Math.min(...n.map(m=>(t.viewWidth-m.x*i)/m.width))),a!=r&&l(t.viewHeight/n.reduce((m,S)=>m+S.height,0)),a!=r&&h(t.idealFontPx/u),i!=s&&o(Math.min(...n.map(m=>(t.viewWidth-m.width*a)/m.x))),isFinite(b)&&(i!=s&&c(t.minBranchThicknessPx/b),a!=r&&l(Math.min(...n.map(m=>(t.viewWidth-m.x*i)/m.width)))),a!=r&&l(t.maxFontPx/u),{branchLenToPxFactor_min:i,branchLenToPxFactor_max:s,labelSizeToPxFactor_min:a,labelSizeToPxFactor_max:r}}function Dr(e,t){const i=e.leaves().map((g,z)=>({radius:g.radius,angle:g.angle,cos:g.cos,sin:g.sin,width:(g.tipLabelBounds.width+t.nodeLabelOffset)*g.tipLabelSize,height:g.tipLabelBounds.height*g.tipLabelSize,labelScale:g.tipLabelSize}));let s=0,a=1/0,r=0,o=1/0;function c(g){g<a&&(g<s?a=s:a=g)}function l(g){g>s&&(g>a?s=a:s=g)}function h(g){g<o&&(g<r?o=r:o=g)}function u(g){g>r&&(g>o?r=o:r=g)}const f=Math.min(...i.map(g=>g.labelScale)),d=Math.max(...i.map(g=>g.radius)),b=Math.min(...i.map(g=>g.radius)),m=e.descendants().filter(g=>g.data.length>0&&g.children),S=m.length>0?Math.min(...m.map(g=>g.data.length)):1/0;u(t.minFontPx/f),s!==a&&l(Math.max(...i.map(g=>g.width*r/(d/t.minBranchLenProp-g.radius))));function y(){const g=Math.min(...i.filter(v=>v.cos>0).map(v=>(t.viewWidth/2-v.width*v.cos*r)/(v.radius*v.cos))),z=Math.min(...i.filter(v=>v.cos<0).map(v=>(t.viewWidth/2-v.width*-v.cos*r)/(v.radius*-v.cos))),A=Math.min(...i.filter(v=>v.sin>0).map(v=>(t.viewHeight/2-v.width*v.sin*r)/(v.radius*v.sin))),N=Math.min(...i.filter(v=>v.sin<0).map(v=>(t.viewHeight/2-v.width*-v.sin*r)/(v.radius*-v.sin)));c(Math.min((g+z)/2,(N+A)/2))}function T(){const g=Math.min(...i.filter(v=>v.cos>0).map(v=>(t.viewWidth/2-v.radius*v.cos*s)/(v.width*v.cos))),z=Math.min(...i.filter(v=>v.cos<0).map(v=>(t.viewWidth/2-v.radius*-v.cos*s)/(v.width*-v.cos))),A=Math.min(...i.filter(v=>v.sin>0).map(v=>(t.viewHeight/2-v.radius*v.sin*s)/(v.width*v.sin))),N=Math.min(...i.filter(v=>v.sin<0).map(v=>(t.viewHeight/2-v.radius*-v.sin*s)/(v.width*-v.sin)));h(Math.min((g+z)/2,(N+A)/2))}y(),T();const $=i.reduce((g,z)=>g+z.height,0);return $>0&&b>0&&(s!==a&&l($*r/(b*2*Math.PI)),r!==o&&h(d*a*2*Math.PI/$)),r!==o&&T(),r!==o&&u(t.idealFontPx/f),s!==a&&y(),isFinite(S)&&S>0&&s!==a&&l(t.minBranchThicknessPx/S),r!==o&&T(),r!==o&&h(t.maxFontPx/f),{branchLenToPxFactor_min:s,branchLenToPxFactor_max:a,labelSizeToPxFactor_min:r,labelSizeToPxFactor_max:o}}class xn{constructor(){this.metricsCache=new Map,this.setupHiddenEnvironment()}setupHiddenEnvironment(){this.hiddenContainer=document.createElement("div"),this.hiddenContainer.style.cssText=`
3
+ position: absolute;
4
+ top: -9999px;
5
+ left: -9999px;
6
+ visibility: hidden;
7
+ width: 5000px;
8
+ height: 5000px;
9
+ overflow: hidden;
10
+ `,this.hiddenSVG=document.createElementNS("http://www.w3.org/2000/svg","svg"),this.hiddenSVG.setAttribute("width","5000"),this.hiddenSVG.setAttribute("height","5000"),this.hiddenSVG.setAttribute("viewBox","0 0 5000 5000"),this.hiddenContainer.appendChild(this.hiddenSVG),document.body.appendChild(this.hiddenContainer),this.hiddenD3SVG=Z(this.hiddenSVG),this.textGroup=this.hiddenD3SVG.append("g").attr("id","text-measurement-group")}getRelativeTextSize(t,n={}){const i=`${t}-${JSON.stringify(n)}`;if(this.metricsCache.has(i))return this.metricsCache.get(i);const s=this.textGroup.append("text").attr("x",1e3).attr("y",2500).text(t);Object.keys(n).forEach(l=>{s.style(l,n[l])}),this.hiddenSVG.getBoundingClientRect();const a=s.node().getBBox(),r=window.getComputedStyle(s.node()),o=parseFloat(r.fontSize);s.remove();const c={width:a.width/o,height:a.height/o};return this.metricsCache.set(i,c),c}getTextSize(t,n,i={}){const s=this.getRelativeTextSize(t,i);return{width:s.width,height:s.height,widthPx:s.width*n,heightPx:s.height*n}}clearCache(){this.metricsCache.clear()}destroy(){this.hiddenContainer&&this.hiddenContainer.parentNode&&this.hiddenContainer.parentNode.removeChild(this.hiddenContainer),this.metricsCache.clear()}}class Or extends mn{#t={tipLabelText:{title:"Tip label text",scaleType:"identity",default:"",downstream:["updateTipLabelText","updateCoordinates"],hasLegend:!1},tipLabelColor:{title:"Tip label color",scaleType:"color",default:"#000000",otherCategory:"#555555",downstream:[],hasLegend:!0},tipLabelSize:{title:"Tip label size",scaleType:"size",default:1,isCategorical:!1,outputRange:[.5,2],downstream:["updateCoordinates"],hasLegend:!0},tipLabelFont:{title:"Tip label font",scaleType:"identity",default:"sans-serif",downstream:["updateCoordinates"],hasLegend:!1},tipLabelStyle:{title:"Tip label font style",scaleType:"text",outputValues:["normal","bold","italic","bold italic"],default:"normal",otherCategory:"italic",downstream:["updateCoordinates"],hasLegend:!1},nodeLabelText:{title:"Node label text",scaleType:"identity",default:"",downstream:["updateNodeLabelText"],hasLegend:!1},nodeLabelSize:{title:"Node label size",scaleType:"size",default:1,isCategorical:!1,outputRange:[.5,2],downstream:["updateCoordinates"],hasLegend:!1}};state={treeData:null,layout:"rectangular",aesthetics:Object.fromEntries(Object.keys(this.#t).map(t=>[t,void 0])),viewWidth:800,viewHeight:600,labelSpacing:.1,nodeLabelSizeScale:.67,nodeLabelOffset:.3,maxLabelWidthProportion:.03,branchThicknessProp:.15,minFontPx:12,idealFontPx:18,maxFontPx:32,minBranchThicknessPx:1,minBranchLenProp:.5,collapsedRootLineProp:.05,branchLengthScale:1,treeHeightScale:1};textSizeEstimator;displayedRoot;occupiedWidth;occupiedHeight;branchLenToPxFactor;labelSizeToPxFactor;aestheticsScales={};legends=[];constructor(t={},n=new xn){if(super(),!t.treeData||!t.treeData.tree){console.error("TreeState initialized without valid tree data");return}if(!n){console.error("TreeState initialized without textSizeEstimator");return}t.aesthetics={...this.state.aesthetics,...t.aesthetics},this.state={...this.state,...t},this.textSizeEstimator=n,this.#e(),this.state.treeData.subscribe("treeUpdate",()=>{this.#e()}),this.state.treeData.subscribe("metadataRemoved",i=>{this.setAesthetics(Object.fromEntries(i.columnIds.map(s=>[s,void 0])))})}#e(){this.displayedRoot=this.state.treeData.tree,this.updateLayout(),this.setAesthetics(this.state.aesthetics,!0)}setLayout(t,n=!1){if(!["circular","rectangular"].includes(t)){console.warn(`Invalid layout type: ${t}`);return}(n||this.state.layout!==t)&&(this.state.layout=t,this.update(),this.notify("layoutChange",{layout:t}))}setBranchLengthScale(t){if(t<.01||t>100){console.warn(`Branch length scale out of range: ${t}`);return}this.state.branchLengthScale=t,this.updateCoordinates(),this.notify("branchLengthScaleChange",{scale:t})}setTreeHeightScale(t){if(t<.1||t>10){console.warn(`Tree height scale out of range: ${t}`);return}this.state.treeHeightScale=t,this.updateCoordinates(),this.notify("treeHeightScaleChange",{scale:t})}setAesthetics(t,n=!1){const i=new Set;let s=!1;for(const[a,r]of Object.entries(t)){const o=this.#t[a];if(!o){console.warn(`Unknown aesthetic: ${a}`);continue}if(n||r!==this.state.aesthetics[a]){this.state.aesthetics[a]=r,r?this.aestheticsScales[a]=this.state.treeData.getAesthetic(r,a,o):this.aestheticsScales[a]=new Yt(o.default),this.state.treeData.tree.each(c=>{r&&r!==null&&r!==void 0?c.metadata&&c.metadata[r]!==void 0?c[a]=this.aestheticsScales[a].getValue(c.metadata[r]):c[a]=o.default:c[a]=this.aestheticsScales[a].getValue()});for(const c of o.downstream)i.add(c);o.hasLegend&&(s=!0)}this.notify(`${a}Change`)}s&&this.#n();for(const a of i)this[a]()}#n(){this.legends=[];for(const[t,n]of Object.entries(this.state.aesthetics)){const i=this.#t[t];if(!i.hasLegend||!n)continue;const s=this.aestheticsScales[t];s&&this.legends.push({aestheticId:t,aesthetic:s,type:i.scaleType})}this.notify("legendsChange")}setTargetTreeDimensions(t,n){this.state.viewWidth=t,this.state.viewHeight=n,this.updateCoordinates()}collapseSubtree(t){if(!t){console.warn("Tried to collapse non-existant node");return}if(!t.children){console.warn("Tried to collapse node with no children");return}t.collapsedChildren=t.children,delete t.children,this.update()}expandSubtree(t){!t||!t.collapsedChildren||(t.children=t.collapsedChildren,delete t.collapsedChildren,this.update())}hideSubtree(t){if(!t){console.warn("Tried to hide non-existent node");return}if(!t.parent){console.warn("Cannot hide the root node");return}t.hidden=!0;const n=t.parent;n.children&&(n.hiddenChildren=n.hiddenChildren||[],n.hiddenChildren.push(t),n.children=n.children.filter(i=>i!==t),n.children.length===0&&(delete n.children,this.hideSubtree(n))),this.update()}showSubtree(t){if(!t||!t.hidden)return;const n=t.parent;!n||!n.hiddenChildren||(n.hiddenChildren=n.hiddenChildren.filter(i=>i!==t),n.hiddenChildren.length===0&&delete n.hiddenChildren,n.children||(n.children=[]),n.children.push(t),n.children.sort((i,s)=>{const a=n.data.children?n.data.children.indexOf(i.data):0,r=n.data.children?n.data.children.indexOf(s.data):0;return a-r}),delete t.hidden,this.update())}showAllHidden(){const t=[];this.state.treeData.tree.each(n=>{n.hiddenChildren&&t.push(...n.hiddenChildren)});for(const n of t)this.showSubtree(n)}collapseRoot(t){!t||t===this.displayedRoot||(this.displayedRoot=t,this.displayedRoot.collapsedParent=this.displayedRoot.parent,delete this.displayedRoot.parent,this.update())}expandRoot(){if(!this.displayedRoot||!this.displayedRoot.collapsedParent)return;this.displayedRoot.parent=this.displayedRoot.collapsedParent,delete this.displayedRoot.collapsedParent;let t=this.displayedRoot;for(;t.parent&&!t.collapsedParent;)t=t.parent;this.displayedRoot=t,this.update()}updateTipLabelText(){this.state.treeData.tree.each(t=>{this.state.aesthetics.tipLabelText===null?t.tipLabelText="":(t.children||t.collapsedChildren)&&(this.state.aesthetics.tipLabelText===void 0||!t.tipLabelText)?t.tipLabelText=`Clade with ${t.leafCount} tips`:t.tipLabelText||(t.tipLabelText=t.data.name||"")})}updateNodeLabelText(){this.state.treeData.tree.each(t=>{t.children||t.collapsedChildren?t.nodeLabelText=t.data.name||"":t.nodeLabelText||(t.tipLabel=t.data.name||"")})}update(){this.updateLayout(),this.updateCoordinates()}updateLayout(){Qa().separation((n,i)=>1)(this.displayedRoot),this.displayedRoot.each(n=>{n.parent?(n.branchLen=n.data.length?n.data.length:0,n.y=n.parent.y+n.branchLen):n.y=0}),this.displayedRoot.each(n=>{const i=n.x,s=n.y;n.x=s,n.y=i}),this.state.layout==="circular"&&this.displayedRoot.each(n=>{n.angle=n.y*Math.PI*2+Math.PI,n.cos=Math.cos(n.angle),n.sin=Math.sin(n.angle),n.radius=n.x}),this.displayedRoot.eachAfter(n=>{n.x=n.x-this.displayedRoot.x,n.y=n.y-this.displayedRoot.y})}getCollapsedTriangleHeight(t){return t.tipLabelSizePx+1.1}getCollapsedTriangleOffset(t){return this.getCollapsedTriangleHeight(t)*.52}updateCoordinates(){this.displayedRoot.each(n=>{n.tipLabelBounds=this.textSizeEstimator.getRelativeTextSize(n.tipLabelText,{"font-family":n.tipLabelFont,"font-style":n.tipLabelStyle}),n.nodeLabelBounds=this.textSizeEstimator.getRelativeTextSize(n.nodeLabelText,{"font-family":n.nodeLabelFont,"font-style":n.nodeLabelStyle})});let t;this.state.layout==="circular"?t=Dr(this.displayedRoot,this.state):t=Hr(this.displayedRoot,this.state),this.branchLenToPxFactor=t.branchLenToPxFactor_max*this.state.branchLengthScale,this.labelSizeToPxFactor=t.labelSizeToPxFactor_min,this.displayedRoot.each(n=>{n.branchLenPx=n.branchLen*this.branchLenToPxFactor,n.tipLabelSizePx=n.tipLabelSize*this.labelSizeToPxFactor,n.nodeLabelSizePx=n.nodeLabelSize*this.labelSizeToPxFactor*this.state.nodeLabelSizeScale;let i=n.tipLabelSizePx*this.state.nodeLabelOffset;n.collapsedChildren&&(i+=this.getCollapsedTriangleOffset(n)*1.3),n.tipLabelXOffsetPx=i,n.nodeLabelXOffsetPx=n.nodeLabelSizePx*this.state.nodeLabelOffset,n.tipLabelYOffsetPx=n.tipLabelSizePx*n.tipLabelBounds.height/2,n.nodeLabelYOffsetPx=n.nodeLabelSizePx*n.nodeLabelBounds.height/2,n.tipLabelBounds.widthPx=n.tipLabelBounds.width*n.tipLabelSizePx,n.tipLabelBounds.heightPx=n.tipLabelBounds.height*n.tipLabelSizePx}),this.state.layout==="circular"?this.displayedRoot.each(n=>{n.radiusPx=n.radius*this.branchLenToPxFactor,n.xPx=n.radiusPx*n.cos,n.yPx=n.radiusPx*n.sin}):this.displayedRoot.each(n=>{n.xPx=n.x*this.branchLenToPxFactor,n.yPx=n.y*this.displayedRoot.leaves().length*this.labelSizeToPxFactor*(1+this.state.labelSpacing)*this.state.treeHeightScale}),this.state.layout==="circular"?this.state.treeData.tree.eachAfter(n=>{if(n.children)n.bounds={minRadius:n.radiusPx,maxRadius:Math.max(...n.children.map(i=>i.bounds.maxRadius)),minAngle:Math.min(...n.children.map(i=>i.bounds.minAngle)),maxAngle:Math.max(...n.children.map(i=>i.bounds.maxAngle)),minX:Math.min(...n.children.map(i=>i.bounds.minX)),maxX:Math.max(...n.children.map(i=>i.bounds.maxX)),minY:Math.min(...n.children.map(i=>i.bounds.minY)),maxY:Math.max(...n.children.map(i=>i.bounds.maxY))};else{const i=n.radiusPx,s=i+n.tipLabelXOffsetPx+n.tipLabelBounds.widthPx,a=Math.atan(n.tipLabelYOffsetPx/n.radiusPx),r=n.angle-a,o=n.angle+a,c=[i*Math.cos(r),i*Math.cos(o),s*Math.cos(o),s*Math.cos(r)],l=[i*Math.sin(r),i*Math.sin(o),s*Math.sin(o),s*Math.sin(r)];n.bounds={minRadius:i,maxRadius:s,minAngle:r,maxAngle:o,minX:Math.min(...c),maxX:Math.max(...c),minY:Math.min(...l),maxY:Math.max(...l)}}}):this.state.treeData.tree.eachAfter(n=>{n.children?n.bounds={minX:n.xPx,maxX:Math.max(...n.children.map(i=>i.bounds.maxX)),minY:Math.min(...n.children.map(i=>i.bounds.minY)),maxY:Math.max(...n.children.map(i=>i.bounds.maxY))}:n.bounds={minX:n.xPx,maxX:n.xPx+n.tipLabelXOffsetPx+n.tipLabelBounds.widthPx,minY:n.yPx-n.tipLabelYOffsetPx,maxY:n.yPx+n.tipLabelYOffsetPx}}),this.notify("coordinateChange")}}const Ir={refresh:["m 16,7 h 5 V 2","M 22,12 A 10,10 0 0 1 13.58,21.9 10,10 0 0 1 2.5,15.2 10,10 0 0 1 7.4,3.14 10,10 0 0 1 20,6"],outwardArrows:["m 9,19 3,3 3,-3","M 12,22 V 15","m 9,5 3,-3 3,3","M 12,2 V 9","m 5,9 -3,3 3,3","M 2,12 H 9","M 19,15 22,12 19,9","M 22,12 H 15"],compress:["M 5,12 H 19","m 9,18 3,-3 3,3","m 12,15 v 7","m 9,6 3,3 3,-3","M 12,9 V 2"],expand:["M 5,2 H 19","M 5,22 H 19","m 9,8 3,-3 3,3","m 9,16 3,3 3,-3","M 12,5 V 19"],circle:["M 12,2 A 10,10 0 1 1 12,22 A 10,10 0 1 1 12,2"],trash:["M 3,6 H 21","M 19,6 V 20 A 2,2 0 0 1 17,22 H 7 A 2,2 0 0 1 5,20 V 6","M 8,6 V 4 A 2,2 0 0 1 10,2 H 14 A 2,2 0 0 1 16,4 V 6","M 10,11 V 17","M 14,11 V 17"]};function Yr(e,t,n,i=2){const s=Ir[t],a=(n-i*2)/24,r=e.append("rect").attr("width","100%").attr("height","100%").attr("rx","5px").attr("ry","5px").attr("fill","#CCC"),o=e.append("g").attr("transform",`translate(${i}, ${i}) scale(${a})`).attr("stroke","#555").attr("fill","none").attr("stroke-linecap","round").attr("stroke-linejoin","round").attr("stroke-width",2);return s.forEach(c=>{o.append("path").attr("d",c)}),r}class xe{constructor(t={}){this.state={aesthetic:null,x:0,y:0,origin:"top left",maxX:1/0,maxY:1/0,titleFontSize:16,labelFontSize:14,...t},this.coordinates={},this.group=null,this.textSizeEstimator=this.state.treeState.textSizeEstimator}render(t){this.group=t.append("g").attr("class","ht-legend"),this.updateCoordinates(),this.updatePosition()}updateCoordinates(){throw new Error("updateCoordinates must be implemented by subclass")}updatePosition(){if(!this.group)return;let t=this.state.x,n=this.state.y;const{width:i,height:s}=this.coordinates;this.state.origin.includes("right")&&(t-=i),this.state.origin.includes("bottom")&&(n-=s),this.group.attr("transform",`translate(${t}, ${n})`)}renderTitle(t){return this.group.append("text").attr("class","legend-title").attr("x",0).attr("y",0).attr("text-anchor","start").style("font-size",`${this.state.titleFontSize}px`).style("text-decoration","underline").text(t)}}class qr extends xe{constructor(t={}){super(t),this.scaleBarEdgeHeight=6,this.titleSpacing=10,this.unitLabelSpacing=2,this.minBarLength=80,this.maxBarLength=160,this.lineThickness=2,this.showTitle=!1,this.title="Branch length"}updateCoordinates(){let t=dn(1),n=t*this.state.treeState.branchLenToPxFactor;for((n<this.minBarLength||n>this.maxBarLength)&&(t=dn(this.minBarLength/this.state.treeState.branchLenToPxFactor),n=t*this.state.treeState.branchLenToPxFactor);n<this.minBarLength;)t*=2,n=t*this.state.treeState.branchLenToPxFactor;for(;n>this.maxBarLength;)t/=2,n=t*this.state.treeState.branchLenToPxFactor;t=t.toPrecision(3);const i=this.textSizeEstimator.getTextSize(t,this.state.labelFontSize);this.textSizeEstimator.getTextSize(this.title,this.state.titleFontSize);let s=0;this.showTitle&&(s=this.state.titleFontSize+this.titleSpacing);const a=s+this.unitLabelSpacing+i.heightPx+10;this.coordinates={width:n+this.lineThickness,height:a+this.scaleBarEdgeHeight,title:{x:0,y:this.state.titleFontSize,text:"Branch Length"},bar:{x1:0,y1:a,x2:n,y2:a},leftTick:{x1:0,y1:a-this.scaleBarEdgeHeight,x2:0,y2:a+this.scaleBarEdgeHeight},rightTick:{x1:n,y1:a-this.scaleBarEdgeHeight,x2:n,y2:a+this.scaleBarEdgeHeight},label:{x:n/2,y:a-this.unitLabelSpacing,text:t}}}render(t){super.render(t),this.showTitle&&this.renderTitle(this.coordinates.title.text).attr("x",this.coordinates.title.x).attr("y",this.coordinates.title.y),this.group.append("line").attr("class","bar").attr("x1",this.coordinates.bar.x1).attr("y1",this.coordinates.bar.y1).attr("x2",this.coordinates.bar.x2).attr("y2",this.coordinates.bar.y2).attr("stroke","#000").attr("stroke-width",this.lineThickness),this.group.append("line").attr("class","left-tick").attr("x1",this.coordinates.leftTick.x1).attr("y1",this.coordinates.leftTick.y1).attr("x2",this.coordinates.leftTick.x2).attr("y2",this.coordinates.leftTick.y2).attr("stroke","#000").attr("stroke-width",this.lineThickness),this.group.append("line").attr("class","right-tick").attr("x1",this.coordinates.rightTick.x1).attr("y1",this.coordinates.rightTick.y1).attr("x2",this.coordinates.rightTick.x2).attr("y2",this.coordinates.rightTick.y2).attr("stroke","#000").attr("stroke-width",this.lineThickness),this.group.append("text").attr("class","label").attr("x",this.coordinates.label.x).attr("y",this.coordinates.label.y).attr("text-anchor","middle").attr("dominant-baseline","ideographic").style("font-size",`${this.state.labelFontSize}px`).text(this.coordinates.label.text)}}class Gr extends xe{constructor(t={}){super(t),this.padding=10,this.exampleLetter="A",this.tickHeight=5,this.verticalSpacing=5,this.showTitle=!0}updateCoordinates(){const t=this.state.aesthetic.scale.dataMin,n=this.state.aesthetic.scale.dataMax,i=this.state.aesthetic.scale.sizeMin,s=this.state.aesthetic.scale.sizeMax,a=pn(t,n,5),r=s*this.state.treeState.labelSizeToPxFactor*.7,o=i*this.state.treeState.labelSizeToPxFactor*.7;this.textSizeEstimator.getTextSize(this.state.aesthetic.state.title,this.state.titleFontSize);const l=Math.max(a.length*30,100),h=a.map(T=>{const $=It(T,a);return this.textSizeEstimator.getTextSize($,this.state.labelFontSize)}),u=h[0].widthPx/2,f=h[h.length-1].widthPx/2,d=l+u+f;let b=0;this.showTitle&&(b=this.state.titleFontSize+this.verticalSpacing);const m=b+r,S=this.textSizeEstimator.getTextSize(this.state.aesthetic.state.inputUnits||"",this.state.labelFontSize),y=m+this.tickHeight+this.state.labelFontSize+S.heightPx;this.coordinates={width:d,height:y,leftOverhang:u,title:{x:u,y:this.state.titleFontSize,text:this.state.aesthetic.state.title},polygon:[],ticks:[],labels:[],units:{x:d/2,y,text:this.state.aesthetic.state.inputUnits||""}},a.forEach((T,$)=>{const g=u+$/(a.length-1)*l;this.coordinates.ticks.push({x1:g,y1:m,x2:g,y2:m+this.tickHeight}),this.coordinates.labels.push({x:g,y:m+this.tickHeight,text:It(T,a)})}),this.coordinates.polygon=[{x:u,y:m},{x:u,y:m-o},{x:u+l,y:m-r},{x:u+l,y:m}]}render(t){super.render(t),this.showTitle&&this.renderTitle(this.coordinates.title.text).attr("x",this.coordinates.title.x).attr("y",this.coordinates.title.y);const n=this.coordinates.polygon.map(i=>`${i.x},${i.y}`).join(" ");this.group.append("polygon").attr("points",n).attr("fill","#f0f0f0").attr("stroke","#ccc").attr("stroke-width",1),this.coordinates.ticks.forEach(i=>{this.group.append("line").attr("x1",i.x1).attr("y1",i.y1).attr("x2",i.x2).attr("y2",i.y2).attr("stroke","#000").attr("stroke-width",1)}),this.coordinates.labels.forEach(i=>{this.group.append("text").attr("x",i.x).attr("y",i.y).attr("text-anchor","middle").attr("dominant-baseline","hanging").style("font-size",`${this.state.labelFontSize}px`).text(i.text)}),this.coordinates.units.text&&this.group.append("text").attr("x",this.coordinates.units.x).attr("y",this.coordinates.units.y).attr("text-anchor","middle").attr("dominant-baseline","ideographic").style("font-size",`${this.state.labelFontSize}px`).style("font-style","italic").text(this.coordinates.units.text)}}class Zr extends xe{constructor(t={}){super(t),this.exampleLetter="A",this.verticalSpacing=5,this.horizontalSpacing=10,this.showTitle=!0,this.squareSize=12,this.itemLabelGap=5,this.itemGap=15,this.maxCategoriesPerRow=5,this.gradientHeight=20,this.tickHeight=5,this.numGradientStops=20}updateCoordinates(){const t=this.state.aesthetic,n=t.state.isCategorical,i=this.textSizeEstimator.getTextSize(t.state.title,this.state.titleFontSize);let s=0;this.showTitle&&(s=this.state.titleFontSize+this.verticalSpacing),n?this.#t(s,i):this.#e(s,i)}#t(t,n){const i=this.state.aesthetic,s=i.scale.categories,a=this.state.maxX-this.state.x;this.coordinates={width:0,height:t,title:{x:0,y:this.state.titleFontSize,text:i.state.title},items:[],isCategorical:!0};let r=0,o=t+this.verticalSpacing+this.squareSize/2,c=this.squareSize;s.slice(0,i.scale.maxColors).forEach((l,h)=>{const u=i.scale.getValue(l),f=this.textSizeEstimator.getTextSize(l,this.state.labelFontSize),d=this.squareSize+this.itemLabelGap+f.widthPx;r>0&&r+d>a&&(r=0,o+=c+this.verticalSpacing,c=this.squareSize),this.coordinates.items.push({x:r,y:o,color:u,label:h<i.scale.maxColors-1?l:i.state.otherLabel,squareX:r,squareY:o-this.squareSize/2,labelX:r+this.squareSize+this.itemLabelGap,labelY:o}),r+=d+this.itemGap,this.coordinates.width=Math.max(this.coordinates.width,r-this.itemGap)}),this.coordinates.height=o+this.squareSize/2}#e(t,n){const i=this.state.aesthetic,s=i.scale.dataMin,a=i.scale.dataMax,r=pn(s,a,5),c=Math.max(r.length*30,120),l=r.map(T=>{const $=It(T,r);return this.textSizeEstimator.getTextSize($,this.state.labelFontSize)}),h=l[0].widthPx/2,u=l[l.length-1].widthPx/2,f=c+h+u,d=t+this.verticalSpacing,b=d+this.gradientHeight,m=b+this.tickHeight,S=this.textSizeEstimator.getTextSize(i.state.inputUnits||"",this.state.labelFontSize),y=m+this.state.labelFontSize+S.heightPx;this.coordinates={width:f,height:y,leftOverhang:h,isCategorical:!1,title:{x:h,y:this.state.titleFontSize,text:i.state.title},gradient:{x:h,y:d,width:c,height:this.gradientHeight},ticks:[],labels:[],units:{x:f/2,y,text:i.state.inputUnits||""}},r.forEach((T,$)=>{const g=h+$/(r.length-1)*c;this.coordinates.ticks.push({x1:g,y1:b,x2:g,y2:b+this.tickHeight}),this.coordinates.labels.push({x:g,y:m,text:It(T,r)})})}render(t){super.render(t),this.showTitle&&this.renderTitle(this.coordinates.title.text).attr("x",this.coordinates.title.x).attr("y",this.coordinates.title.y),this.coordinates.isCategorical?this.#n():this.#s()}#n(){this.coordinates.items.forEach(t=>{this.group.append("rect").attr("x",t.squareX).attr("y",t.squareY).attr("width",this.squareSize).attr("height",this.squareSize).attr("fill",t.color).attr("stroke","#000").attr("stroke-width",1),this.group.append("text").attr("x",t.labelX).attr("y",t.labelY).attr("text-anchor","start").attr("dominant-baseline","central").style("font-size",`${this.state.labelFontSize}px`).text(t.label)})}#s(){const t=this.state.aesthetic,n=t.scale.dataMin,i=t.scale.dataMax,s=`color-gradient-${Math.random().toString(36).substr(2,9)}`,r=this.group.append("defs").append("linearGradient").attr("id",s).attr("x1","0%").attr("x2","100%").attr("y1","0%").attr("y2","0%");for(let o=0;o<=this.numGradientStops;o++){const c=o/this.numGradientStops,l=n+c*(i-n),h=t.scale.getValue(l);r.append("stop").attr("offset",`${c*100}%`).attr("stop-color",h)}this.group.append("rect").attr("x",this.coordinates.gradient.x).attr("y",this.coordinates.gradient.y).attr("width",this.coordinates.gradient.width).attr("height",this.coordinates.gradient.height).style("fill",`url(#${s})`).style("stroke","#000").style("stroke-width",1),this.coordinates.ticks.forEach(o=>{this.group.append("line").attr("x1",o.x1).attr("y1",o.y1).attr("x2",o.x2).attr("y2",o.y2).attr("stroke","#000").attr("stroke-width",1)}),this.coordinates.labels.forEach(o=>{this.group.append("text").attr("x",o.x).attr("y",o.y).attr("text-anchor","middle").attr("dominant-baseline","hanging").style("font-size",`${this.state.labelFontSize}px`).text(o.text)}),this.coordinates.units.text&&this.group.append("text").attr("x",this.coordinates.units.x).attr("y",this.coordinates.units.y).attr("text-anchor","middle").attr("dominant-baseline","ideographic").style("font-size",`${this.state.labelFontSize}px`).style("font-style","italic").text(this.coordinates.units.text)}}class Ur{constructor(t,n,i={}){if(!t)throw new Error("TreeView requires a TreeState instance");if(!n)throw new Error("TreeView requires an SVG container element");this.treeState=t,this.svg=Z(n),this.options={buttonSize:25,controlsMargin:3,buttonPadding:2,manualZoomAndPanEnabled:!0,autoZoom:"Default",autoPan:"Default",transitionDuration:500,legendSpacing:10,legendPadding:10,...i},this.layers={},this.selections={},this.legendInstances=[],this.currentTransform={x:0,y:0,k:1},this.isTransitioning=!1,this.wasCircularLayout=this.treeState.state.layout==="circular",this.isExpanding=!1,this.activeTransitions=new Set,this.selectedNode=null,this.selectionButtons=[{id:"collapse-subtree",icon:"compress",isVisible:s=>s&&s!==this.treeState.displayedRoot&&(s.children||s.collapsedChildren),onClick:s=>{s&&s!==this.treeState.displayedRoot&&s.children&&(this.treeState.collapseSubtree(s),this.#e())}},{id:"collapse-root",icon:"expand",isVisible:s=>s&&s!==this.treeState.displayedRoot&&(s.children||s.collapsedChildren),onClick:s=>{s&&s!==this.treeState.displayedRoot&&s.children&&(this.treeState.collapseRoot(s),this.#e())}},{id:"hide",icon:"trash",isVisible:s=>s&&s!==this.treeState.displayedRoot,onClick:s=>{s&&s!==this.treeState.displayedRoot&&(this.treeState.hideSubtree(s),this.#e())}}],this.#t(),this.initializeZoom(),this.#s(),this.#S()}destroy(){this.svg.selectAll("*").remove(),this.layers={},this.selections={},this.selectedNode=null,this.legendInstances=[]}reattach(t){this.svg=Z(t),this.#t(),this.initializeZoom(),this.#u(!1),this.#f(!1),this.#h(!1),this.#a(!1),this.fitToView({transition:!1,forcePanToTop:!0})}#t(){const t=this.svg.append("g").attr("class","tree-elements");this.layers.branchLayer=t.append("g").attr("class","branch-layer"),this.layers.nodeLayer=t.append("g").attr("class","node-layer"),this.layers.hitLayer=t.append("g").attr("class","hit-layer"),this.layers.legendLayer=t.append("g").attr("class","legend-layer"),this.layers.treeGroup=t,this.layers.selectionRect=t.append("path").attr("class","selection-rect").attr("fill","none").attr("stroke","grey").attr("stroke-width",2).attr("stroke-dasharray","5,5").attr("pointer-events","none").style("display","none"),this.layers.selectionBtns=this.svg.append("g").attr("class","selection-btns").style("display","none"),this.#n()}#e(){this.selectedNode=null,this.layers.selectionRect.style("display","none"),this.layers.selectionBtns.style("display","none")}#n(){const t=this.layers.selectionBtns;this.selectionButtons.forEach(n=>{const i=t.append("svg").attr("class",`btn-${n.id}`).attr("width",this.options.buttonSize).attr("height",this.options.buttonSize).style("cursor","pointer").on("click",()=>{n.onClick(this.selectedNode)});Yr(i,n.icon,this.options.buttonSize),n.element=i})}initializeZoom(){this.treeZoom=Er().filter(t=>!(!this.options.manualZoomAndPanEnabled||t.type==="dblclick")).on("zoom",t=>{this.currentTransform=t.transform,this.layers.treeGroup.attr("transform",t.transform),this.#w(t.sourceEvent===null)}),this.svg.call(this.treeZoom)}#s(){this.treeState.subscribe("coordinateChange",()=>{this.#x()}),this.treeState.subscribe("layoutChange",()=>{this.#x()}),this.treeState.subscribe("legendsChange",()=>{this.#a(!0)}),this.treeState.subscribe("tipLabelTextChange",()=>{this.#T()}),this.treeState.subscribe("tipLabelColorChange",()=>{this.#C()}),this.treeState.subscribe("tipLabelSizeChange",()=>{this.#L(),this.#a(!0)}),this.treeState.subscribe("tipLabelFontChange",()=>{this.#M()}),this.treeState.subscribe("tipLabelStyleChange",()=>{this.#P()}),this.treeState.subscribe("nodeLabelTextChange",()=>{this.#E()})}#S(){this.#u(!1),this.#f(!1),this.#h(!1),this.#a(!1),this.fitToView({transition:!1,forcePanToTop:!0})}#x(){const t=this.#u(!0),n=this.#f(!0);this.#h(!0),this.#a(!0),this.selectedNode&&this.#$(!0),this.isExpanding&&t&&n&&setTimeout(()=>{t.transition("branch group fade in").duration(150).attr("opacity",1),n.transition("node group fade in").duration(150).attr("opacity",1),this.layers.selectionBtns.attr("opacity",0).transition("fade in selection buttons").duration(150).attr("opacity",1),setTimeout(()=>{this.isExpanding=!1},150)},this.options.transitionDuration),this.fitToView()}#T(){this.selections.nodes&&this.selections.nodes.selectAll(".tip-label").text(t=>t.tipLabelText||"")}#C(){this.selections.nodes&&this.selections.nodes.selectAll(".tip-label").style("fill",t=>t.tipLabelColor||"#000")}#L(){this.selections.nodes&&this.selections.nodes.selectAll(".tip-label").style("font-size",t=>`${t.tipLabelSizePx||12}px`)}#M(){this.selections.nodes&&this.selections.nodes.selectAll(".tip-label").style("font-family",t=>t.tipLabelFont||"sans-serif")}#P(){this.selections.nodes&&this.selections.nodes.selectAll(".tip-label").style("font-style",t=>t.tipLabelStyle.includes("italic")?"italic":"normal").style("font-weight",t=>t.tipLabelStyle.includes("bold")?"bold":"normal")}#E(){this.selections.nodes&&this.selections.nodes.selectAll(".node-label").text(t=>t.nodeLabelText||"")}#a(t=!0){this.layers.legendLayer.selectAll("*").remove(),this.legendInstances=[];const n=this.#y();if(!n)return;n.maxX-n.minX;let i=n.minX,s=n.maxY+this.options.legendSpacing;const a=new qr({treeState:this.treeState,x:i,y:s,origin:"top left",maxX:n.maxX,maxY:1/0});a.render(this.layers.legendLayer),this.legendInstances.push(a),i+=a.coordinates.width+this.options.legendSpacing;for(const r of this.treeState.legends){let o;r.type==="size"?o=new Gr({treeState:this.treeState,aesthetic:r.aesthetic,x:i,y:s,origin:"top left",maxX:n.maxX,maxY:1/0}):r.type==="color"&&(o=new Zr({treeState:this.treeState,aesthetic:r.aesthetic,x:i,y:s,origin:"top left",maxX:n.maxX,maxY:1/0})),i+o.coordinates.width+this.options.legendSpacing>n.maxX&&(i=n.minX,s+=Math.max(...this.legendInstances.map(c=>c.coordinates.height))),o&&(o.render(this.layers.legendLayer),this.legendInstances.push(o),i+=o.coordinates.width+this.options.legendSpacing)}this.fitToView({transition:t})}fitToView(t){if(t={transition:!0,padding:5,autoZoom:this.options.autoZoom,autoPan:this.options.autoPan,forcePanToTop:!1,...t},(!t.autoZoom||t.autoZoom=="None")&&(!t.autoPan||t.autoPan=="None"))return;const{width:n,height:i}=this.svg.node().getBoundingClientRect(),s=this.getCurrentBoundsWithLegends();if(!s)return;s.minX-=t.padding,s.maxX+=t.padding,s.minY-=t.padding,s.maxY+=t.padding;const a=s.maxX-s.minX,r=s.maxY-s.minY,o=0,c=n-o,l=i;let h=this.currentTransform.k,u=this.currentTransform.x,f=this.currentTransform.y;const d=c/a,b=l/r;if(t.autoZoom=="Default"&&(this.treeState.state.layout=="circular"||b>=1||!this.options.manualZoomAndPanEnabled?t.autoZoom="Both":t.autoZoom="X"),t.autoZoom&&t.autoZoom!="None"&&(t.autoZoom=="X"?h=Math.min(1,d):t.autoZoom=="Y"?h=Math.min(1,b):t.autoZoom=="Both"?h=Math.min(d,b):console.error(`Value of ${t.autoZoom} is invalid for input.autoZoom.`)),t.autoPan=="Default"&&(t.autoPan="Both"),t.autoPan&&t.autoPan!="None"){if(t.autoPan=="Both"||t.autoPan=="X"){const S=a*h;if(S<=c)u=o+(c-S)/2-s.minX*h;else{const y=-s.minX*h-o,T=n-s.maxX*h;y>0?u=o-s.minX*h:T>0?u=n-s.maxX*h:u=o+c/2-(s.minX+s.maxX)/2*h}}if(t.autoPan=="Both"||t.autoPan=="Y"){const S=r*h;if(S<=l)f=(l-S)/2-s.minY*h;else{const y=-s.minY*h,T=i-s.maxY*h;f>y||t.forcePanToTop?f=y:f<T&&(f=T)}}}const m=me.translate(u,f).scale(h);t.transition?this.svg.transition("zoom").duration(this.options.transitionDuration).call(this.treeZoom.transform,m):this.svg.call(this.treeZoom.transform,m)}#y(){const t=this.treeState.displayedRoot;return{minX:t.bounds.minX,maxX:t.bounds.maxX,minY:t.bounds.minY,maxY:t.bounds.maxY}}getCurrentBoundsWithLegends(){const t=this.#y();if(!t)return null;let n=t.maxY,i=t.minX;for(const s of this.legendInstances)s.coordinates&&(n=Math.max(n,s.state.y+s.coordinates.height));return this.treeState.state.layout!=="circular"&&this.treeState.displayedRoot.collapsedParent&&(i-=this.#g()),{minX:i,maxX:t.maxX,minY:t.minY,maxY:n}}#b(t){this.selectedNode===t?this.#e():(this.selectedNode=t,this.layers.selectionRect.attr("d",this.#r(t)).style("display","block"),this.#w(!1))}#$(t=!1){this.selectedNode&&(t?this.layers.selectionRect.transition("update selection rect").duration(this.options.transitionDuration).attr("d",this.#r(this.selectedNode)):this.layers.selectionRect.attr("d",this.#r(this.selectedNode)))}#r(t){if(!t)return"";if(this.treeState.state.layout==="circular"){const i={x:t.bounds.minRadius*Math.cos(t.bounds.minAngle),y:t.bounds.minRadius*Math.sin(t.bounds.minAngle)},s={x:t.bounds.minRadius*Math.cos(t.bounds.maxAngle),y:t.bounds.minRadius*Math.sin(t.bounds.maxAngle)},a={x:t.bounds.maxRadius*Math.cos(t.bounds.minAngle),y:t.bounds.maxRadius*Math.sin(t.bounds.minAngle)},r={x:t.bounds.maxRadius*Math.cos(t.bounds.maxAngle),y:t.bounds.maxRadius*Math.sin(t.bounds.maxAngle)},o=t.bounds.maxAngle-t.bounds.minAngle>Math.PI?1:0;return`M${i.x},${i.y} L${a.x},${a.y} A${t.bounds.maxRadius},${t.bounds.maxRadius} 0 ${o},1 ${r.x},${r.y} L${s.x},${s.y} A${t.bounds.minRadius},${t.bounds.minRadius} 0 ${o},0 ${i.x},${i.y} Z`}else{const i={x:t.bounds.minX,y:t.bounds.minY},s={x:t.bounds.maxX,y:t.bounds.minY},a={x:t.bounds.maxX,y:t.bounds.maxY},r={x:t.bounds.minX,y:t.bounds.maxY};return`M${i.x},${i.y} L${s.x},${s.y} L${a.x},${a.y} L${r.x},${r.y} L${i.x},${i.y} Z`}}#w(t=!0,n=1.1){if(!this.selectedNode){this.layers.selectionBtns.style("display","none");return}const i=this.treeState.state.layout==="circular";let s,a;if(i){const f=this.selectedNode.bounds.minAngle,d=this.selectedNode.bounds.maxAngle,b=this.selectedNode.bounds.minRadius,m=this.selectedNode.bounds.maxRadius,S=20;let y=1/0,T=0;for(let $=0;$<=S;$++){const g=f+(d-f)*$/S,z=b*Math.cos(g),A=b*Math.sin(g),N=m*Math.cos(g),v=m*Math.sin(g);z<y&&(y=z,T=A),N<y&&(y=N,T=v)}s=y,a=T}else s=this.selectedNode.bounds.minX,a=this.selectedNode.bounds.minY;let r=0;this.selectionButtons.forEach(f=>{if(f.isVisible(this.selectedNode)){const b=r*(this.options.buttonSize*n);f.element.style("display","block").attr("transform",`translate(0, ${b})`),r++}else f.element.style("display","none")});const o=r*this.options.buttonSize+(r-1)*this.options.buttonSize*(n-1);let c=s*this.currentTransform.k+this.currentTransform.x-this.options.buttonSize*n,l=a*this.currentTransform.k+this.currentTransform.y-this.options.buttonSize*(n-1);const{width:h,height:u}=this.svg.node().getBoundingClientRect();c=Math.max(c,0),c=Math.min(c,h-this.options.buttonSize),l=Math.max(l,0),l=Math.min(l,u-o),t?this.layers.selectionBtns.attr("opacity",0).attr("transform",`translate(${c},${l})`):this.layers.selectionBtns.attr("transform",`translate(${c},${l})`).attr("opacity",1).style("display","block")}#h(){const t=this.treeState.displayedRoot;if(!t)return;const n=this.treeState.state.layout==="circular",i=this.treeState.labelSizeToPxFactor*this.treeState.state.branchThicknessProp,s=this.#g(),a=this.layers.hitLayer.selectAll(".hit").data(t.descendants().filter(d=>d.children?d.children.filter(m=>!m.hidden).length>1:!1),d=>d.id);a.exit().remove(),a.enter().append("path").attr("class","hit").attr("fill","transparent").style("cursor","pointer").on("click",(d,b)=>{this.#b(b),d.stopPropagation()}).merge(a).attr("d",d=>this.#r(d)),this.layers.hitLayer.selectAll(".hit").sort((d,b)=>d.depth-b.depth);const o=this.layers.hitLayer.selectAll(".tip-hit").data(t.descendants().filter(d=>!d.children&&!d.collapsedChildren),d=>d.id);o.exit().remove(),o.enter().append("path").attr("class","tip-hit").attr("fill","transparent").style("cursor","pointer").on("click",(d,b)=>{this.#b(b),d.stopPropagation()}).merge(o).attr("d",d=>this.#r(d));const l=this.layers.hitLayer.selectAll(".collapsed-hit").data(t.descendants().filter(d=>d.collapsedChildren),d=>d.id);l.exit().remove(),l.enter().append("rect").attr("class","collapsed-hit").attr("fill","transparent").style("cursor","pointer").on("click",(d,b)=>{b.collapsedChildren&&(this.isExpanding=!0,this.treeState.expandSubtree(b)),d.stopPropagation()}).merge(l).attr("transform",d=>`translate(${d.xPx}, ${d.yPx}) rotate(${this.#o(d)})`).attr("x",d=>this.#i(d)?-(this.treeState.getCollapsedTriangleHeight(d)+d.tipLabelBounds.width*this.treeState.labelSizeToPxFactor):0).attr("y",d=>-d.tipLabelYOffsetPx*1.5).attr("width",d=>this.treeState.getCollapsedTriangleHeight(d)+d.tipLabelBounds.width*this.treeState.labelSizeToPxFactor).attr("height",d=>Math.max(d.tipLabelSizePx,this.treeState.getCollapsedTriangleHeight(d)));const u=this.layers.hitLayer.selectAll(".collapsed-root-hit").data(t.collapsedParent?[t]:[],d=>d.id);u.exit().remove(),u.enter().append("rect").attr("class","collapsed-root-hit").attr("fill","transparent").style("cursor","pointer").on("click",(d,b)=>{b.collapsedParent&&(this.isExpanding=!0,this.treeState.expandRoot()),d.stopPropagation()}).merge(u).attr("transform",d=>{if(!d.collapsedParent)return`translate(${d.xPx}, ${d.yPx})`;let b=0;if(n){const m=d.children||[];m.length>0&&(b=m.reduce((y,T)=>y+T.angle,0)/m.length*(180/Math.PI))}return`translate(${d.xPx}, ${d.yPx}) rotate(${b})`}).attr("x",-s).attr("y",-i*5).attr("width",s).attr("height",i*10)}#u(t=!0){const n=this.treeState.displayedRoot;if(!n)return;const i=n.links(),s=this.treeState.labelSizeToPxFactor*this.treeState.state.branchThicknessProp,a=this.layers.branchLayer.selectAll(".branch-group").data(i,c=>c.target.id);t?a.exit().attr("opacity",0).remove():a.exit().remove();const r=a.enter().append("g").attr("class","branch-group");this.#z(r),this.isExpanding&&t&&r.attr("opacity",0);const o=r.merge(a);return this.#A(o,t,s),this.selections.branches=o,r}#z(t){t.append("path").attr("class","offset").attr("fill","none").attr("stroke","#000").attr("stroke-opacity",1).attr("stroke-linecap","round"),t.append("path").attr("class","extension").attr("fill","none").attr("stroke","#000").attr("stroke-opacity",1).attr("stroke-linecap","round")}#A(t,n,i){this.treeState.state.layout;const s=t.select(".offset"),a=t.select(".extension");n?(s.transition().duration(this.options.transitionDuration).attr("stroke-width",i).attr("d",r=>this.#l(r,"offset")),a.transition().duration(this.options.transitionDuration).attr("stroke-width",i).attr("d",r=>this.#l(r,"extension"))):(s.attr("stroke-width",i).attr("d",r=>this.#l(r,"offset")),a.attr("stroke-width",i).attr("d",r=>this.#l(r,"extension")))}#l(t,n){if(this.treeState.state.layout==="circular")if(n==="offset"){const s={x:t.source.radiusPx*t.target.cos,y:t.source.radiusPx*t.target.sin},a=t.target.angle>t.source.angle?1:0;return`M${t.source.xPx},${t.source.yPx} A${t.source.radiusPx},${t.source.radiusPx} 0 0,${a} ${s.x},${s.y}`}else{const s={x:t.source.radiusPx*t.target.cos,y:t.source.radiusPx*t.target.sin};return`M${s.x},${s.y} L${t.target.xPx},${t.target.yPx}`}else return n==="offset"?(t.target.angle>t.source.angle,`M${t.source.xPx},${t.source.yPx} L${t.source.xPx},${t.target.yPx}`):`M${t.source.xPx},${t.target.yPx} L${t.target.xPx},${t.target.yPx}`}#d(t){const n=$r(this.treeState.getCollapsedTriangleHeight(t));return _r().type(vr).size(n)()}#f(t=!0){const n=this.treeState.displayedRoot;if(!n)return;const i=this.treeState.state.layout==="circular";this.wasCircularLayout;const s=n.descendants().filter(h=>!h.hidden),a=this.treeState.labelSizeToPxFactor*this.treeState.state.branchThicknessProp,r=this.#g(),o=this.layers.nodeLayer.selectAll(".node").data(s,h=>h.id);t?o.exit().attr("opacity",0).remove():o.exit().remove();const c=o.enter().append("g").attr("class","node").attr("transform",h=>`translate(${h.xPx}, ${h.yPx})`);this.#N(c,a),this.isExpanding&&t&&c.attr("opacity",0);const l=c.merge(o);return this.#k(l,t),this.#R(l,t),this.#F(l,t),this.#B(l,t,a,r),this.selections.nodes=l,this.wasCircularLayout=i,c}#N(t,n){t.append("path").attr("class","node-shape").attr("d",i=>i.collapsedChildren?this.#d(i):null).attr("fill","#000").style("display",i=>i.collapsedChildren?null:"none"),t.append("line").attr("class","collapsed-root-line").attr("stroke","#000").attr("stroke-width",n).style("display",i=>i.collapsedParent?null:"none"),t.filter(i=>i.tipLabelText&&i.tipLabelText.trim()!=="").append("text").attr("class","tip-label").style("text-anchor",i=>this.#p(i)).style("font-size",i=>`${i.tipLabelSizePx}px`).style("font-family",i=>i.tipLabelFont||"sans-serif").style("font-style",i=>i.tipLabelStyle||"normal").style("font-weight",i=>i.tipLabelStyle==="bold"?"bold":"normal").style("fill",i=>i.tipLabelColor||"#000").style("display",i=>i.children?"none":null).text(i=>i.tipLabelText||""),t.filter(i=>!i.nodeLabelText||i.nodeLabelText.trim()===""||!i.children?!1:i.children.filter(a=>!a.hidden).length>1).append("text").attr("class","node-label").style("text-anchor",i=>this.#m(i)).style("font-size",i=>`${i.nodeLabelSizePx}px`).style("fill","#000").style("display",i=>i.children||i.collapsedChildren?null:"none").text(i=>i.nodeLabelText||"")}#k(t,n){n?t.transition("update node positions").duration(this.options.transitionDuration).attr("transform",i=>`translate(${i.xPx}, ${i.yPx})`):t.attr("transform",i=>`translate(${i.xPx}, ${i.yPx})`)}#R(t,n){this.treeState.state.layout;const i=t.selectAll(".tip-label");n?(i.attr("x",a=>this.#i(a)?-a.tipLabelXOffsetPx:a.tipLabelXOffsetPx),i.transition("update tip labels").duration(this.options.transitionDuration).attr("dy",a=>a.tipLabelSizePx/2.5).attr("transform",a=>`rotate(${this.#o(a)})`).style("text-anchor",a=>this.#p(a)).style("font-size",a=>`${a.tipLabelSizePx}px`)):i.attr("dy",a=>a.tipLabelSizePx/2.5).attr("x",a=>this.#i(a)?-a.tipLabelXOffsetPx:a.tipLabelXOffsetPx).attr("transform",a=>`rotate(${this.#o(a)})`).style("text-anchor",a=>this.#p(a)).style("font-size",a=>`${a.tipLabelSizePx}px`),i.text(a=>a.tipLabelText||"").style("fill",a=>a.tipLabelColor||"#000").style("font-family",a=>a.tipLabelFont||"sans-serif").style("font-style",a=>a.tipLabelStyle||"normal").style("display",a=>a.children?"none":null);const s=t.selectAll(".node-label");n?s.transition("update node labels").duration(this.options.transitionDuration).attr("dy",a=>this.#_(a)).attr("x",a=>this.#i(a)?a.nodeLabelXOffsetPx:-a.nodeLabelXOffsetPx).attr("transform",a=>`rotate(${this.#o(a)})`).style("text-anchor",a=>this.#m(a)).style("font-size",a=>`${a.nodeLabelSizePx}px`):s.attr("dy",a=>this.#_(a)).attr("x",a=>this.#i(a)?a.nodeLabelXOffsetPx:-a.nodeLabelXOffsetPx).attr("transform",a=>`rotate(${this.#o(a)})`).style("text-anchor",a=>this.#m(a)).style("font-size",a=>`${a.nodeLabelSizePx}px`),s.text(a=>a.nodeLabelText||"").style("display",a=>!a.children&&!a.collapsedChildren||a.children&&a.children.filter(o=>!o.hidden).length<=1?"none":null)}#F(t,n){const i=t.selectAll(".node-shape");i.attr("transform",s=>`rotate(${this.#v(s)}) translate(0, ${this.treeState.getCollapsedTriangleOffset(s)})`).style("display",s=>s.collapsedChildren?null:"none"),n?i.transition().duration(this.options.transitionDuration).attr("d",s=>s.collapsedChildren?this.#d(s):null).attr("transform",s=>`rotate(${this.#v(s)}) translate(0, ${this.treeState.getCollapsedTriangleOffset(s)})`):i.attr("d",s=>s.collapsedChildren?this.#d(s):null)}#B(t,n,i,s){this.treeState.state.layout;const a=t.selectAll(".collapsed-root-line");n?a.transition().duration(this.options.transitionDuration).attr("x2",r=>this.#c(r,s).x).attr("y2",r=>this.#c(r,s).y).attr("stroke-width",i).attr("stroke-dasharray",r=>r.collapsedParent?fn(s,i,4):null):a.attr("x2",r=>this.#c(r,s).x).attr("y2",r=>this.#c(r,s).y).attr("stroke-width",i).attr("stroke-dasharray",r=>r.collapsedParent?fn(s,i,4):null),a.attr("x1",0).attr("y1",0).style("display",r=>r.collapsedParent?null:"none")}#o(t){if(!(this.treeState.state.layout==="circular"))return 0;const i=t.angle*(180/Math.PI);return this.#i(t)?i+180:i}#v(t){return this.treeState.state.layout==="circular"?t.angle*(180/Math.PI)-90:-90}#p(t){return this.treeState.state.layout==="circular"&&this.#i(t)?t.children?"start":"end":t.children?"end":"start"}#m(t){return this.treeState.state.layout==="circular"&&this.#i(t)?t.children||t.collapsedChildren?"start":"end":t.children||t.collapsedChildren?"end":"start"}#_(t){if(t.collapsedParent)return this.treeState.labelSizeToPxFactor*1.2;{const n=t.parent&&t.parent.yPx>t.yPx,i=t.nodeLabelSizePx;return n?-i*.3:i*1}}#i(t){return this.treeState.state.layout==="circular"?t.angle<Math.PI*1.5||t.angle>Math.PI*2.5:!1}#c(t,n){if(!t.collapsedParent)return{x:0,y:0};if(this.treeState.state.layout==="circular"){const s=t.children||[];if(s.length===0)return{x:-n,y:0};const a=s.reduce((r,o)=>r+o.angle,0)/s.length;return{x:-n*Math.cos(a),y:-n*Math.sin(a)}}return{x:-n,y:0}}#g(){const t=this.treeState.displayedRoot;return t?this.treeState.state.layout==="circular"?Math.max(...t.leaves().map(s=>s.radiusPx))*this.treeState.state.collapsedRootLineProp*2:Math.max(...t.leaves().map(s=>s.xPx))*this.treeState.state.collapsedRootLineProp:0}}function Wr(e,t,n,i,s,a,r,o){let l=null,h=null,u=null,f=null,d=null,b=null,m=!0;const S=document.createElement("div");S.className="ht-toggle-container";const y=document.createElement("button");y.className="ht-control-panel-toggle",y.innerHTML=`
11
+ <svg width="16" height="16" viewBox="0 0 16 16" class="ht-toggle-arrow">
12
+ <path d="M8 4 L12 8 L8 12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" transform="rotate(-90 8 8)"/>
13
+ </svg>
14
+ <svg width="16" height="16" viewBox="0 0 16 16" class="ht-hamburger-icon">
15
+ <line x1="2" y1="4" x2="14" y2="4" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
16
+ <line x1="2" y1="8" x2="14" y2="8" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
17
+ <line x1="2" y1="12" x2="14" y2="12" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
18
+ </svg>
19
+ `,y.title="Toggle control panel",S.appendChild(y);const T=document.createElement("div");T.className="ht-collapsible-panel";const $=document.createElement("div");$.className="ht-tabs";const g=document.createElement("div");g.className="ht-controls hidden";const z=[{id:"data",label:"Data",requiresTree:!1},{id:"controls",label:"Controls",requiresTree:!0},{id:"tree-manipulation",label:"Tree Manipulation",requiresTree:!0},{id:"tip-label-settings",label:"Tip Label Settings",requiresTree:!0},{id:"export",label:"Export",requiresTree:!0}],A={};z.forEach(_=>{const C=document.createElement("div");C.className="ht-tab",C.textContent=_.label,C.addEventListener("click",()=>{C.classList.contains("disabled")||(l===_.id?w():p(_.id))}),A[_.id]=C,$.appendChild(C)});function N(){const _=n()!==null;if(z.forEach(C=>{const E=A[C.id];C.requiresTree&&!_?E.classList.add("disabled"):E.classList.remove("disabled")}),l){const C=z.find(E=>E.id===l);C&&C.requiresTree&&!_&&p("data")}}T.addEventListener("transitionend",_=>{_.propertyName==="max-height"&&o&&o()}),g.addEventListener("transitionend",_=>{_.propertyName==="max-height"&&o&&o()}),y.addEventListener("click",()=>{m=!m,m?(T.classList.remove("ht-panel-collapsed"),y.classList.remove("collapsed")):(T.classList.add("ht-panel-collapsed"),y.classList.add("collapsed"))});function v(){const _=n();return!_||!_.state.treeData?[]:_.state.treeData.getMetadataTableNames()}function L(){return h}function M(_){v().includes(_)?h=_:console.warn(`Metadata table not found: ${_}`)}function R(){const _=v();h=_.length>0?_[0]:null}function k(){const _=n();if(_){if(u){let C=!1;_.displayedRoot.each(E=>{E!==_.displayedRoot&&E.collapsedChildren&&(C=!0)}),u.disabled=!C}if(f&&(f.disabled=!_.displayedRoot.collapsedParent),d){let C=!1;_.state.treeData.tree.each(E=>{E.hiddenChildren&&E.hiddenChildren.length>0&&(C=!0)}),d.disabled=!C}}}function X(){const _=n();if(!_)return"tree";for(const[C,E]of t.entries())if(E===_.state.treeData)return C;return"tree"}function p(_){const C=z.find(E=>E.id===_);C&&C.requiresTree&&!n()||(l=_,Object.keys(A).forEach(E=>{E===_?A[E].classList.add("active"):A[E].classList.remove("active")}),g.classList.remove("hidden"),x(_))}function w(){l=null,Object.keys(A).forEach(_=>{A[_].classList.remove("active")}),g.classList.add("hidden"),g.innerHTML=""}function x(_){switch(g.innerHTML="",_){case"data":Kr(g,t,n,s,a,v,L,M,R,P,r,24);break;case"controls":Qr(g,n,i,r,24);break;case"tree-manipulation":Jr(g,n,P,k,r,24,C=>{u=C},C=>{f=C},C=>{d=C});break;case"tip-label-settings":jr(g,n,r,24);break;case"export":to(g,n,i,X,r,24);break}}function P(){R(),b&&(b(),b=null),u=null,f=null,d=null;const _=n();_&&(b=_.subscribe("coordinateChange",k)),N(),l&&x(l)}return T.appendChild($),T.appendChild(g),e.appendChild(S),e.appendChild(T),N(),p(z[0].id),R(),P}function Kr(e,t,n,i,s,a,r,o,c,l,h,u){e.innerHTML="";const f=V("Select tree:",u);e.appendChild(f);const d=document.createElement("select");d.className="ht-select",d.style.height=`${u}px`;const b=Array.from(t.keys()),m=n(),S=m?Array.from(t.entries()).find(([L,M])=>M===m.state.treeData)?.[0]:null;if(b.length===0){const L=document.createElement("option");L.textContent="No trees loaded",L.value="",d.appendChild(L),d.disabled=!0}else b.forEach(L=>{const M=document.createElement("option");M.value=L,M.textContent=L,L===S&&(M.selected=!0),d.appendChild(M)}),d.addEventListener("change",L=>{i(L.target.value)});e.appendChild(d);const y=document.createElement("input");y.type="file",y.accept=".nwk,.newick,.tree,.tre,.treefile",y.style.display="none",y.addEventListener("change",async L=>{const M=L.target.files[0];if(M)try{const R=await M.text();let k=M.name.replace(/\.(nwk|newick|tree|tre)$/i,""),X=k,p=1;for(;t.has(X);)X=`${k} (${p})`,p++;s(X,R),y.value="",l(),i(X)}catch(R){console.error("Error loading tree file:",R),alert(`Error loading tree file: ${R.message}`)}}),e.appendChild(y);const T=lt("+","Add tree from Newick file",u);if(T.addEventListener("click",()=>{y.click()}),e.appendChild(T),!m)return;const $=V("Available metadata:",u);e.appendChild($);const g=document.createElement("select");g.className="ht-select",g.style.height=`${u}px`;const z=a(),A=r();if(z.length===0){const L=document.createElement("option");L.textContent="No metadata",L.value="",g.appendChild(L),g.disabled=!0}else z.forEach(L=>{const M=document.createElement("option");M.value=L,M.textContent=L,L===A&&(M.selected=!0),g.appendChild(M)}),g.addEventListener("change",L=>{o(L.target.value)});e.appendChild(g);const N=document.createElement("input");N.type="file",N.accept=".tsv,.csv,.txt",N.style.display="none",N.addEventListener("change",async L=>{const M=L.target.files[0];if(!M)return;const R=n();if(!R||!R.state.treeData){alert("No tree selected. Please select a tree first."),N.value="";return}try{const k=await M.text();let X=M.name.replace(/\.(tsv|csv|txt)$/i,""),p=" ";M.name.toLowerCase().endsWith(".csv")&&(p=",");const w=R.state.treeData.addTable(k,X,p),x=R.state.treeData.metadataTableNames.get(w);N.value="",o(x),l()}catch(k){console.error("Error loading metadata file:",k),alert(`Error loading metadata file: ${k.message}`),N.value=""}}),e.appendChild(N);const v=lt("+","Add metadata table",u);v.addEventListener("click",()=>{const L=n();if(!L||!L.state.treeData){alert("No tree selected. Please select a tree first.");return}N.click()}),e.appendChild(v)}function Qr(e,t,n,i,s){e.innerHTML="";const a=t(),r=n();if(!a||!r){e.textContent="No tree selected";return}const o=lt("Fit to view","Fit the tree to the current view window",s);o.addEventListener("click",()=>{r.fitToView({transition:!0,autoPan:"Both",autoZoom:"Both"})}),e.appendChild(o);const c=V("Manual zoom/pan:",s);e.appendChild(c);const l=bn(r.options.manualZoomAndPanEnabled,s);l.addEventListener("click",()=>{r.options.manualZoomAndPanEnabled=!r.options.manualZoomAndPanEnabled,r.options.manualZoomAndPanEnabled?l.classList.add("active"):l.classList.remove("active"),r.initializeZoom()}),e.appendChild(l);const h=V("Auto-zoom:",s);e.appendChild(h);const u=document.createElement("select");u.className="ht-select",u.style.height=`${s}px`,["Default","Both","X","Y","None"].forEach(S=>{const y=document.createElement("option");y.value=S,y.textContent=S,S===r.options.autoZoom&&(y.selected=!0),u.appendChild(y)}),u.addEventListener("change",S=>{r.options.autoZoom=S.target.value}),e.appendChild(u);const d=V("Auto-pan:",s);e.appendChild(d);const b=document.createElement("select");b.className="ht-select",b.style.height=`${s}px`,["Default","Both","X","Y","None"].forEach(S=>{const y=document.createElement("option");y.value=S,y.textContent=S,S===r.options.autoPan&&(y.selected=!0),b.appendChild(y)}),b.addEventListener("change",S=>{r.options.autoPan=S.target.value}),e.appendChild(b)}function Jr(e,t,n,i,s,a,r,o,c){e.innerHTML="";const l=t();if(!l){e.textContent="No tree selected";return}const h=lt("Expand subtrees","Expand all collapsed subtrees",a),u=()=>{let L=!1;return l.displayedRoot.each(M=>{M!==l.displayedRoot&&M.collapsedChildren&&(L=!0)}),L};h.disabled=!u(),h.addEventListener("click",()=>{const L=[];l.displayedRoot.each(M=>{if(M!==l.displayedRoot&&M.collapsedChildren){let R=!0,k=M.parent;for(;k&&k!==l.displayedRoot;){if(k.collapsedChildren){R=!1;break}k=k.parent}R&&L.push(M)}}),L.forEach(M=>{l.expandSubtree(M)}),i()}),r(h),e.appendChild(h);const f=lt("Expand root","Expand the collapsed root",a);f.disabled=!l.displayedRoot.collapsedParent,f.addEventListener("click",()=>{l.displayedRoot.collapsedParent&&(l.expandRoot(),i())}),o(f),e.appendChild(f);const d=lt("Show hidden","Show all hidden nodes",a),b=()=>{let L=!1;return l.state.treeData.tree.each(M=>{M.hiddenChildren&&M.hiddenChildren.length>0&&(L=!0)}),L};d.disabled=!b(),d.addEventListener("click",()=>{l.showAllHidden(),i()}),c(d),e.appendChild(d);const m=V("Branch length:",a);e.appendChild(m);const S=(L,M=10)=>{const R=Math.log10(1/M),k=Math.log10(M);return(Math.log10(L)-R)/(k-R)*100},y=(L,M=10)=>{const R=Math.log10(1/M),k=Math.log10(M),X=R+L/100*(k-R);return Math.pow(10,X)},T=yn(0,100,S(l.state.branchLengthScale),.1,a);T.addEventListener("input",L=>{const M=parseFloat(L.target.value),R=y(M);l.setBranchLengthScale(R)}),e.appendChild(T);const $=V("Tree height:",a);e.appendChild($);const g=yn(0,100,S(l.state.treeHeightScale),.1,a);g.addEventListener("input",L=>{const M=parseFloat(L.target.value),R=y(M);l.setTreeHeightScale(R)}),e.appendChild(g);const z=V("Radial layout:",a);e.appendChild(z);const A=l.state.layout==="circular",N=bn(A,a),v=()=>{l.state.layout==="circular"?N.classList.add("active"):N.classList.remove("active")};l.subscribe("layoutChange",v),N.addEventListener("click",()=>{const L=l.state.layout;l.setLayout(L==="circular"?"rectangular":"circular")}),e.appendChild(N)}function jr(e,t,n,i){e.innerHTML="";const s=t();if(!s){e.textContent="No tree selected";return}const a=V("Text:",i);e.appendChild(a);const r=document.createElement("div");r.style.display="flex";const o=qt(s,"tipLabelText","Default",i,!0,null);r.appendChild(o),e.appendChild(r);const c=V("Color:",i);e.appendChild(c);const l=document.createElement("div");l.style.display="flex";const h=qt(s,"tipLabelColor","Default",i,!1,null);l.appendChild(h),e.appendChild(l);const u=V("Size:",i);e.appendChild(u);const f=document.createElement("div");f.style.display="flex";const d=qt(s,"tipLabelSize","Default",i,!1,!0);f.appendChild(d),e.appendChild(f);const b=V("Style:",i);e.appendChild(b);const m=document.createElement("div");m.style.display="flex";const S=qt(s,"tipLabelStyle","Default",i,!1,!1);m.appendChild(S),e.appendChild(m);const y=V("Font:",i);e.appendChild(y);const T=document.createElement("select");T.className="ht-select",T.style.height=`${i}px`;const $=["sans-serif","serif","monospace"],g=s.state.aesthetics.tipLabelFont!==void 0?s.aestheticsScales.tipLabelFont.getValue():"sans-serif";$.forEach(z=>{const A=document.createElement("option");A.value=z,A.textContent=z,z===g&&(A.selected=!0),T.appendChild(A)}),T.addEventListener("change",z=>{const A=z.target.value;s.setAesthetics({tipLabelFont:void 0}),s.state.treeData.tree.each(N=>{N.tipLabelFont=A}),s.updateCoordinates()}),e.appendChild(T)}function qt(e,t,n,i,s=!1,a=null){const r=document.createElement("select");if(r.className="ht-select",r.style.height=`${i}px`,r.style.flex="1",s){const f=document.createElement("option");f.value="none",f.textContent="None",r.appendChild(f)}const o=document.createElement("option");o.value="",o.textContent=n,r.appendChild(o);const c=e.state.treeData,l=Array.from(c.columnDisplayName.keys());let h=l;a!==null&&(a?h=l.filter(f=>c.columnType.get(f)==="continuous"):h=l.filter(f=>c.columnType.get(f)==="categorical")),h.forEach(f=>{const d=document.createElement("option");d.value=f,d.textContent=c.columnDisplayName.get(f),e.state.aesthetics[t]===f&&(d.selected=!0),r.appendChild(d)});const u=e.state.aesthetics[t];return u===null?r.value="none":u===void 0||u===""?r.value="":r.value=u,r.addEventListener("change",f=>{let d;f.target.value==="none"?d=null:f.target.value===""?d=void 0:d=f.target.value;const b={};b[t]=d,e.setAesthetics(b)}),r}function to(e,t,n,i,s,a){e.innerHTML="";const r=t(),o=n();if(!r||!o){e.textContent="No tree selected";return}const c=o.getCurrentBoundsWithLegends(),l=c.maxX-c.minX,h=c.maxY-c.minY,u={format:"svg",width:l,height:h,margin:18},f=l/h,d=300,b=2.54,m=w=>w/d*b,S=w=>w/b*d,y=(w,x)=>x==="png"?Math.round(w):Math.round(m(w)*100)/100,T=(w,x)=>x==="png"?w:S(w),$=()=>{const w=o.getCurrentBoundsWithLegends(),x=w.maxX-w.minX,P=w.maxY-w.minY;u.width=x,u.height=P,M.value=y(x,u.format),k.value=y(P,u.format)},g=r.subscribe("coordinateChange",$),z=r.subscribe("legendsChange",$);e.dataset.cleanup=()=>{g(),z()};const A=lt("Export","Export the tree to a file",a);A.classList.add("primary"),A.addEventListener("click",()=>{const x=i().replace(/[^a-z0-9_-]/gi,"_"),P=u.format==="svg"?"svg":"png",_=`${x}.${P}`;eo(o,u,_)}),e.appendChild(A);const N=V("Output format:",a);e.appendChild(N);const v=document.createElement("select");v.className="ht-select",v.style.height=`${a}px`,["SVG","PNG"].forEach(w=>{const x=document.createElement("option");x.value=w.toLowerCase(),x.textContent=w,w.toLowerCase()===u.format&&(x.selected=!0),v.appendChild(x)}),v.addEventListener("change",w=>{u.format=w.target.value,M.value=y(u.width,u.format),k.value=y(u.height,u.format),p.value=y(u.margin,u.format);const x=u.format==="png"?"px":"cm";L.textContent=`Width (${x}):`,R.textContent=`Height (${x}):`,X.textContent=`Margin (${x}):`}),e.appendChild(v);const L=V(`Width (${u.format==="png"?"px":"cm"}):`,a);e.appendChild(L);const M=ye(y(u.width,u.format),.1,1e4,.1,a);M.addEventListener("input",w=>{const x=parseFloat(w.target.value);isNaN(x)||x<=0||(u.width=T(x,u.format),u.height=u.width/f,k.value=y(u.height,u.format))}),e.appendChild(M);const R=V(`Height (${u.format==="png"?"px":"cm"}):`,a);e.appendChild(R);const k=ye(y(u.height,u.format),.1,1e4,.1,a);k.addEventListener("input",w=>{const x=parseFloat(w.target.value);isNaN(x)||x<=0||(u.height=T(x,u.format),u.width=u.height*f,M.value=y(u.width,u.format))}),e.appendChild(k);const X=V(`Margin (${u.format==="png"?"px":"cm"}):`,a);e.appendChild(X);const p=ye(y(u.margin,u.format),0,100,.1,a);p.addEventListener("input",w=>{const x=parseFloat(w.target.value);isNaN(x)||x<0||(u.margin=T(x,u.format))}),e.appendChild(p)}function eo(e,t,n){const i=e.getCurrentBoundsWithLegends(),s=i.maxX-i.minX,a=i.maxY-i.minY,r=t.width/s,o=t.height/a,c=Math.min(r,o),l=t.width+2*t.margin,h=t.height+2*t.margin,u=t.margin-i.minX*c,f=t.margin-i.minY*c,d=document.createElementNS("http://www.w3.org/2000/svg","svg");d.setAttribute("width",l),d.setAttribute("height",h),d.setAttribute("xmlns","http://www.w3.org/2000/svg");const b=document.createElementNS("http://www.w3.org/2000/svg","g");b.setAttribute("transform",`translate(${u}, ${f}) scale(${c})`);const S=e.layers.treeGroup.node().cloneNode(!0);S.removeAttribute("transform");const y=S.querySelector(".selection-rect");y&&y.remove(),b.appendChild(S),d.appendChild(b);const $=new XMLSerializer().serializeToString(d);t.format==="svg"?no($,n,"image/svg+xml"):t.format==="png"&&io($,l,h,n)}function no(e,t,n){const i=new Blob([e],{type:n}),s=URL.createObjectURL(i),a=document.createElement("a");a.href=s,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(s)}function io(e,t,n,i){const s=document.createElement("canvas");s.width=t,s.height=n;const a=s.getContext("2d"),r=new Image,o=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),c=URL.createObjectURL(o);r.onload=()=>{a.fillStyle="white",a.fillRect(0,0,t,n),a.drawImage(r,0,0),s.toBlob(l=>{const h=URL.createObjectURL(l),u=document.createElement("a");u.href=h,u.download=i,document.body.appendChild(u),u.click(),document.body.removeChild(u),URL.revokeObjectURL(h),URL.revokeObjectURL(c)})},r.src=c}function V(e,t){const n=document.createElement("label");return n.className="ht-control-label",n.textContent=e,n.style.height=`${t}px`,n}function lt(e,t="",n){const i=document.createElement("button");return i.className="ht-button",i.textContent=e,i.title=t,i.style.height=`${n}px`,i}function yn(e,t,n,i,s){const a=document.createElement("input");return a.type="range",a.className="ht-slider",a.min=e,a.max=t,a.value=n,a.step=i,a.style.height=`${s}px`,a}function bn(e,t){const n=Math.min(24,t-4),i=n-4,s=document.createElement("div");s.className=e?"ht-toggle active":"ht-toggle",s.style.height=`${n}px`;const a=document.createElement("div");return a.className="ht-toggle-knob",a.style.width=`${i}px`,a.style.height=`${i}px`,s.appendChild(a),s}function ye(e,t,n,i,s){const a=document.createElement("input");return a.type="number",a.className="ht-number-input",a.value=e,a.min=t,a.max=n,a.step=i,a.style.height=`${s}px`,a}const so=".ht-widget{display:flex;flex-direction:column;width:100%;height:100%}.ht-toolbar{flex:0 0 auto;margin-bottom:4px;display:flex;flex-direction:column;position:relative}.ht-toggle-container{position:absolute;top:0;right:0;z-index:10;padding:4px 8px;pointer-events:none}.ht-control-panel-toggle{background-color:transparent;border:none;cursor:pointer;padding:4px;display:flex;align-items:center;gap:4px;transition:opacity .2s;pointer-events:auto}.ht-control-panel-toggle:hover{opacity:.7}.ht-control-panel-toggle .ht-toggle-arrow{transition:transform .3s}.ht-control-panel-toggle.collapsed .ht-toggle-arrow{transform:rotate(180deg)}.ht-control-panel-toggle .ht-hamburger-icon{color:#333}.ht-collapsible-panel{max-height:1000px;overflow:hidden;transition:max-height .3s ease-in-out}.ht-collapsible-panel.ht-panel-collapsed{max-height:0}.ht-tabs{display:flex;gap:20px;padding:4px 8px;background-color:#f5f5f5;border-bottom:2px solid #ddd;-webkit-user-select:none;user-select:none}.ht-tab{cursor:pointer;padding:2px 4px;font-family:sans-serif;font-size:14px;color:#333;border-bottom:2px solid transparent;transition:all .2s}.ht-tab:hover{color:#666}.ht-tab.active{color:#000;font-weight:700;border-bottom-color:#007bff}.ht-tab.active:hover{color:#000}.ht-tab.disabled{color:#999;cursor:not-allowed;opacity:.5}.ht-tab.disabled:hover{color:#999}.ht-controls{padding:2px 8px;background-color:#fafafa;border-bottom:1px solid #ddd;display:flex;flex-wrap:wrap;gap:8px;align-items:center;height:26px;max-height:1000px;overflow:hidden;transition:max-height .3s ease-in-out}.ht-controls.hidden{max-height:0;padding-top:0;padding-bottom:0;border-bottom:none}.ht-control-label{font-family:sans-serif;font-size:14px;color:#333;white-space:nowrap;display:flex;align-items:center}.ht-button{font-size:14px;font-family:sans-serif;background-color:#e0e0e0;border:1px solid #ccc;border-radius:4px;cursor:pointer;transition:background-color .2s;white-space:nowrap}.ht-button:hover{background-color:#d0d0d0}.ht-button:disabled{background-color:#f0f0f0;color:#999;cursor:not-allowed}.ht-button.primary{background-color:#007bff;color:#fff;font-weight:700}.ht-button.primary:hover{background-color:#0056b3}.ht-select{padding:1px 2px;font-size:14px;border:1px solid #ccc;border-radius:4px}.ht-slider{cursor:pointer;width:150px}.ht-toggle{width:50px;background-color:#ccc;border-radius:12px;position:relative;cursor:pointer;transition:background-color .3s;flex-shrink:0}.ht-toggle.active{background-color:#007bff}.ht-toggle-knob{background-color:#fff;border-radius:50%;position:absolute;top:2px;left:2px;transition:left .3s}.ht-toggle.active .ht-toggle-knob{left:calc(100% - 2px);transform:translate(-100%)}.ht-number-input{font-size:14px;border:1px solid #ccc;border-radius:4px;width:80px}.ht-tree{flex:1 1 auto;min-height:0;position:relative}.ht-tree svg{display:block}";function ao(){const e="heat-tree-styles";if(!document.getElementById(e)){const t=document.createElement("style");t.id=e,t.textContent=so,document.head.appendChild(t)}}function ro(e,t,n={}){if(typeof e=="string")n=t||{},t=e,e={trees:[]};else if(e&&typeof e=="object"){if(!t||typeof t!="string")throw new Error("heatTree requires a container selector as the second argument when first argument is a config object");e.trees||(e.trees=[])}else throw new Error("heatTree requires either a container selector string or a configuration object as the first argument");if(!Array.isArray(e.trees))throw new Error("treesConfig.trees must be an array");ao(),n={buttonSize:25,transitionDuration:500,manualZoomAndPanEnabled:!0,autoZoom:"Default",autoPan:"Default",...n};const i=new xn,s=new Map,a=new Map;e.trees.forEach((g,z)=>{if(!g.newick)throw new Error(`Tree at index ${z} is missing newick string`);const A=g.name||`Tree ${z+1}`;let N=[],v=[];g.metadata&&(Array.isArray(g.metadata)?g.metadata:[g.metadata]).forEach((k,X)=>{k.name&&k.data?(N.push(k.data),v.push(k.name)):(N.push(k),v.push(`Metadata ${X+1}`))});const L=new gn(g.newick,N,v);let M;g.aesthetics?M=Object.fromEntries(Object.entries(g.aesthetics).map(([R,k])=>{for(const[X,p]of L.columnName.entries())if(p===k)return[R,X]})):M=void 0,s.set(A,L),a.set(A,M)});const r=new Map,o=new Map,c=document.querySelector(t);if(!c)throw new Error(`Container element not found: ${t}`);const l=document.createElement("div");l.className="ht-widget";const h=document.createElement("div");h.className="ht-toolbar";const u=document.createElement("div");u.className="ht-tree";const f=document.createElementNS("http://www.w3.org/2000/svg","svg");f.setAttribute("width","100%"),f.setAttribute("height","100%"),u.appendChild(f),l.appendChild(h),l.appendChild(u),c.appendChild(l);let d=null,b=null,m=null,S=null;function y(){m&&m.fitToView()}function T(g,z,A=[],N=[]){let v=g,L=1;for(;s.has(v);)v=`${g} (${L})`,L++;const M=new gn(z,A,N);return s.set(v,M),v}function $(g){if(!s.has(g)){console.error(`Tree not found: ${g}`);return}if(!(d===g&&m)){for(;f.firstChild;)f.removeChild(f.firstChild);if(!r.has(g)){const z=new Or({treeData:s.get(g),aesthetics:a.get(g),...n},i);r.set(g,z)}if(o.has(g))o.get(g).reattach(f);else{const z=r.get(g),A=new Ur(z,f,n);o.set(g,A)}d=g,b=r.get(g),m=o.get(g),S&&S()}}if(S=Wr(h,s,()=>b,()=>m,$,T,n,y),s.size>0){const g=Array.from(s.keys())[0];$(g)}return{treeDataInstances:s,treeStateCache:r,treeViewCache:o,getCurrentTreeState:()=>b,getCurrentTreeView:()=>m,getCurrentTreeName:()=>d,switchToTree:$,addNewTree:T,container:l}}ct.heatTree=ro,Object.defineProperty(ct,Symbol.toStringTag,{value:"Module"})}));
20
+ //# sourceMappingURL=heat-tree.umd.js.map