@grunwaldlab/heat-tree 0.1.0 → 0.1.1

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,2 @@
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).HeatTree={})}(this,function(t){"use strict";var e={value:()=>{}};function n(){for(var t,e=0,n=arguments.length,a={};e<n;++e){if(!(t=arguments[e]+"")||t in a||/[\s.]/.test(t))throw new Error("illegal type: "+t);a[t]=[]}return new i(a)}function i(t){this._=t}function a(t,e){for(var n,i=0,a=t.length;i<a;++i)if((n=t[i]).name===e)return n.value}function s(t,n,i){for(var a=0,s=t.length;a<s;++a)if(t[a].name===n){t[a]=e,t=t.slice(0,a).concat(t.slice(a+1));break}return null!=i&&t.push({name:n,value:i}),t}i.prototype=n.prototype={constructor:i,on:function(t,e){var n,i,o=this._,r=(i=o,(t+"").trim().split(/^|\s+/).map(function(t){var e="",n=t.indexOf(".");if(n>=0&&(e=t.slice(n+1),t=t.slice(0,n)),t&&!i.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:e}})),l=-1,h=r.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++l<h;)if(n=(t=r[l]).type)o[n]=s(o[n],t.name,e);else if(null==e)for(n in o)o[n]=s(o[n],t.name,null);return this}for(;++l<h;)if((n=(t=r[l]).type)&&(n=a(o[n],t.name)))return n},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new i(t)},call:function(t,e){if((n=arguments.length-2)>0)for(var n,i,a=new Array(n),s=0;s<n;++s)a[s]=arguments[s+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(s=0,n=(i=this._[t]).length;s<n;++s)i[s].value.apply(e,a)},apply:function(t,e,n){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var i=this._[t],a=0,s=i.length;a<s;++a)i[a].value.apply(e,n)}};var o="http://www.w3.org/1999/xhtml";const r={svg:"http://www.w3.org/2000/svg",xhtml:o,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function l(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),r.hasOwnProperty(e)?{space:r[e],local:t}:t}function h(t){return function(){var e=this.ownerDocument,n=this.namespaceURI;return n===o&&e.documentElement.namespaceURI===o?e.createElement(t):e.createElementNS(n,t)}}function c(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function u(t){var e=l(t);return(e.local?c:h)(e)}function d(){}function p(t){return null==t?d:function(){return this.querySelector(t)}}function f(){return[]}function g(t){return null==t?f:function(){return this.querySelectorAll(t)}}function m(t){return function(){return null==(e=t.apply(this,arguments))?[]:Array.isArray(e)?e:Array.from(e);var e}}function y(t){return function(){return this.matches(t)}}function x(t){return function(e){return e.matches(t)}}var b=Array.prototype.find;function v(){return this.firstElementChild}var w=Array.prototype.filter;function _(){return Array.from(this.children)}function S(t){return new Array(t.length)}function C(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function M(t,e,n,i,a,s){for(var o,r=0,l=e.length,h=s.length;r<h;++r)(o=e[r])?(o.__data__=s[r],i[r]=o):n[r]=new C(t,s[r]);for(;r<l;++r)(o=e[r])&&(a[r]=o)}function T(t,e,n,i,a,s,o){var r,l,h,c=new Map,u=e.length,d=s.length,p=new Array(u);for(r=0;r<u;++r)(l=e[r])&&(p[r]=h=o.call(l,l.__data__,r,e)+"",c.has(h)?a[r]=l:c.set(h,l));for(r=0;r<d;++r)h=o.call(t,s[r],r,s)+"",(l=c.get(h))?(i[r]=l,l.__data__=s[r],c.delete(h)):n[r]=new C(t,s[r]);for(r=0;r<u;++r)(l=e[r])&&c.get(p[r])===l&&(a[r]=l)}function L(t){return t.__data__}function P(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}function k(t,e){return t<e?-1:t>e?1:t>=e?0:NaN}function z(t){return function(){this.removeAttribute(t)}}function $(t){return function(){this.removeAttributeNS(t.space,t.local)}}function E(t,e){return function(){this.setAttribute(t,e)}}function A(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function N(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function R(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}}function B(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function H(t){return function(){this.style.removeProperty(t)}}function F(t,e,n){return function(){this.style.setProperty(t,e,n)}}function X(t,e,n){return function(){var i=e.apply(this,arguments);null==i?this.style.removeProperty(t):this.style.setProperty(t,i,n)}}function V(t,e){return t.style.getPropertyValue(e)||B(t).getComputedStyle(t,null).getPropertyValue(e)}function D(t){return function(){delete this[t]}}function Y(t,e){return function(){this[t]=e}}function O(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function q(t){return t.trim().split(/^|\s+/)}function I(t){return t.classList||new Z(t)}function Z(t){this._node=t,this._names=q(t.getAttribute("class")||"")}function j(t,e){for(var n=I(t),i=-1,a=e.length;++i<a;)n.add(e[i])}function G(t,e){for(var n=I(t),i=-1,a=e.length;++i<a;)n.remove(e[i])}function U(t){return function(){j(this,t)}}function W(t){return function(){G(this,t)}}function K(t,e){return function(){(e.apply(this,arguments)?j:G)(this,t)}}function Q(){this.textContent=""}function J(t){return function(){this.textContent=t}}function tt(t){return function(){var e=t.apply(this,arguments);this.textContent=null==e?"":e}}function et(){this.innerHTML=""}function nt(t){return function(){this.innerHTML=t}}function it(t){return function(){var e=t.apply(this,arguments);this.innerHTML=null==e?"":e}}function at(){this.nextSibling&&this.parentNode.appendChild(this)}function st(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function ot(){return null}function rt(){var t=this.parentNode;t&&t.removeChild(this)}function lt(){var t=this.cloneNode(!1),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function ht(){var t=this.cloneNode(!0),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function ct(t){return function(){var e=this.__on;if(e){for(var n,i=0,a=-1,s=e.length;i<s;++i)n=e[i],t.type&&n.type!==t.type||n.name!==t.name?e[++a]=n:this.removeEventListener(n.type,n.listener,n.options);++a?e.length=a:delete this.__on}}}function ut(t,e,n){return function(){var i,a=this.__on,s=function(t){return function(e){t.call(this,e,this.__data__)}}(e);if(a)for(var o=0,r=a.length;o<r;++o)if((i=a[o]).type===t.type&&i.name===t.name)return this.removeEventListener(i.type,i.listener,i.options),this.addEventListener(i.type,i.listener=s,i.options=n),void(i.value=e);this.addEventListener(t.type,s,n),i={type:t.type,name:t.name,value:e,listener:s,options:n},a?a.push(i):this.__on=[i]}}function dt(t,e,n){var i=B(t),a=i.CustomEvent;"function"==typeof a?a=new a(e,n):(a=i.document.createEvent("Event"),n?(a.initEvent(e,n.bubbles,n.cancelable),a.detail=n.detail):a.initEvent(e,!1,!1)),t.dispatchEvent(a)}function pt(t,e){return function(){return dt(this,t,e)}}function ft(t,e){return function(){return dt(this,t,e.apply(this,arguments))}}C.prototype={constructor:C,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}},Z.prototype={add:function(t){this._names.indexOf(t)<0&&(this._names.push(t),this._node.setAttribute("class",this._names.join(" ")))},remove:function(t){var e=this._names.indexOf(t);e>=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var gt=[null];function mt(t,e){this._groups=t,this._parents=e}function yt(){return new mt([[document.documentElement]],gt)}function xt(t){return"string"==typeof t?new mt([[document.querySelector(t)]],[document.documentElement]):new mt([[t]],gt)}function bt(t,e){if(t=function(t){let e;for(;e=t.sourceEvent;)t=e;return t}(t),void 0===e&&(e=t.currentTarget),e){var n=e.ownerSVGElement||e;if(n.createSVGPoint){var i=n.createSVGPoint();return i.x=t.clientX,i.y=t.clientY,[(i=i.matrixTransform(e.getScreenCTM().inverse())).x,i.y]}if(e.getBoundingClientRect){var a=e.getBoundingClientRect();return[t.clientX-a.left-e.clientLeft,t.clientY-a.top-e.clientTop]}}return[t.pageX,t.pageY]}mt.prototype=yt.prototype={constructor:mt,select:function(t){"function"!=typeof t&&(t=p(t));for(var e=this._groups,n=e.length,i=new Array(n),a=0;a<n;++a)for(var s,o,r=e[a],l=r.length,h=i[a]=new Array(l),c=0;c<l;++c)(s=r[c])&&(o=t.call(s,s.__data__,c,r))&&("__data__"in s&&(o.__data__=s.__data__),h[c]=o);return new mt(i,this._parents)},selectAll:function(t){t="function"==typeof t?m(t):g(t);for(var e=this._groups,n=e.length,i=[],a=[],s=0;s<n;++s)for(var o,r=e[s],l=r.length,h=0;h<l;++h)(o=r[h])&&(i.push(t.call(o,o.__data__,h,r)),a.push(o));return new mt(i,a)},selectChild:function(t){return this.select(null==t?v:function(t){return function(){return b.call(this.children,t)}}("function"==typeof t?t:x(t)))},selectChildren:function(t){return this.selectAll(null==t?_:function(t){return function(){return w.call(this.children,t)}}("function"==typeof t?t:x(t)))},filter:function(t){"function"!=typeof t&&(t=y(t));for(var e=this._groups,n=e.length,i=new Array(n),a=0;a<n;++a)for(var s,o=e[a],r=o.length,l=i[a]=[],h=0;h<r;++h)(s=o[h])&&t.call(s,s.__data__,h,o)&&l.push(s);return new mt(i,this._parents)},data:function(t,e){if(!arguments.length)return Array.from(this,L);var n,i=e?T:M,a=this._parents,s=this._groups;"function"!=typeof t&&(n=t,t=function(){return n});for(var o=s.length,r=new Array(o),l=new Array(o),h=new Array(o),c=0;c<o;++c){var u=a[c],d=s[c],p=d.length,f=P(t.call(u,u&&u.__data__,c,a)),g=f.length,m=l[c]=new Array(g),y=r[c]=new Array(g);i(u,d,m,y,h[c]=new Array(p),f,e);for(var x,b,v=0,w=0;v<g;++v)if(x=m[v]){for(v>=w&&(w=v+1);!(b=y[w])&&++w<g;);x._next=b||null}}return(r=new mt(r,a))._enter=l,r._exit=h,r},enter:function(){return new mt(this._enter||this._groups.map(S),this._parents)},exit:function(){return new mt(this._exit||this._groups.map(S),this._parents)},join:function(t,e,n){var i=this.enter(),a=this,s=this.exit();return"function"==typeof t?(i=t(i))&&(i=i.selection()):i=i.append(t+""),null!=e&&(a=e(a))&&(a=a.selection()),null==n?s.remove():n(s),i&&a?i.merge(a).order():a},merge:function(t){for(var e=t.selection?t.selection():t,n=this._groups,i=e._groups,a=n.length,s=i.length,o=Math.min(a,s),r=new Array(a),l=0;l<o;++l)for(var h,c=n[l],u=i[l],d=c.length,p=r[l]=new Array(d),f=0;f<d;++f)(h=c[f]||u[f])&&(p[f]=h);for(;l<a;++l)r[l]=n[l];return new mt(r,this._parents)},selection:function(){return this},order:function(){for(var t=this._groups,e=-1,n=t.length;++e<n;)for(var i,a=t[e],s=a.length-1,o=a[s];--s>=0;)(i=a[s])&&(o&&4^i.compareDocumentPosition(o)&&o.parentNode.insertBefore(i,o),o=i);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=k);for(var n=this._groups,i=n.length,a=new Array(i),s=0;s<i;++s){for(var o,r=n[s],l=r.length,h=a[s]=new Array(l),c=0;c<l;++c)(o=r[c])&&(h[c]=o);h.sort(e)}return new mt(a,this._parents).order()},call:function(){var t=arguments[0];return arguments[0]=this,t.apply(null,arguments),this},nodes:function(){return Array.from(this)},node:function(){for(var t=this._groups,e=0,n=t.length;e<n;++e)for(var i=t[e],a=0,s=i.length;a<s;++a){var o=i[a];if(o)return o}return null},size:function(){let t=0;for(const e of this)++t;return t},empty:function(){return!this.node()},each:function(t){for(var e=this._groups,n=0,i=e.length;n<i;++n)for(var a,s=e[n],o=0,r=s.length;o<r;++o)(a=s[o])&&t.call(a,a.__data__,o,s);return this},attr:function(t,e){var n=l(t);if(arguments.length<2){var i=this.node();return n.local?i.getAttributeNS(n.space,n.local):i.getAttribute(n)}return this.each((null==e?n.local?$:z:"function"==typeof e?n.local?R:N:n.local?A:E)(n,e))},style:function(t,e,n){return arguments.length>1?this.each((null==e?H:"function"==typeof e?X:F)(t,e,null==n?"":n)):V(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?D:"function"==typeof e?O:Y)(t,e)):this.node()[t]},classed:function(t,e){var n=q(t+"");if(arguments.length<2){for(var i=I(this.node()),a=-1,s=n.length;++a<s;)if(!i.contains(n[a]))return!1;return!0}return this.each(("function"==typeof e?K:e?U:W)(n,e))},text:function(t){return arguments.length?this.each(null==t?Q:("function"==typeof t?tt:J)(t)):this.node().textContent},html:function(t){return arguments.length?this.each(null==t?et:("function"==typeof t?it:nt)(t)):this.node().innerHTML},raise:function(){return this.each(at)},lower:function(){return this.each(st)},append:function(t){var e="function"==typeof t?t:u(t);return this.select(function(){return this.appendChild(e.apply(this,arguments))})},insert:function(t,e){var n="function"==typeof t?t:u(t),i=null==e?ot:"function"==typeof e?e:p(e);return this.select(function(){return this.insertBefore(n.apply(this,arguments),i.apply(this,arguments)||null)})},remove:function(){return this.each(rt)},clone:function(t){return this.select(t?ht:lt)},datum:function(t){return arguments.length?this.property("__data__",t):this.node().__data__},on:function(t,e,n){var i,a,s=function(t){return t.trim().split(/^|\s+/).map(function(t){var e="",n=t.indexOf(".");return n>=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}})}(t+""),o=s.length;if(!(arguments.length<2)){for(r=e?ut:ct,i=0;i<o;++i)this.each(r(s[i],e,n));return this}var r=this.node().__on;if(r)for(var l,h=0,c=r.length;h<c;++h)for(i=0,l=r[h];i<o;++i)if((a=s[i]).type===l.type&&a.name===l.name)return l.value},dispatch:function(t,e){return this.each(("function"==typeof e?ft:pt)(t,e))},[Symbol.iterator]:function*(){for(var t=this._groups,e=0,n=t.length;e<n;++e)for(var i,a=t[e],s=0,o=a.length;s<o;++s)(i=a[s])&&(yield i)}};const vt={capture:!0,passive:!1};function wt(t){t.preventDefault(),t.stopImmediatePropagation()}function _t(t,e,n){t.prototype=e.prototype=n,n.constructor=t}function St(t,e){var n=Object.create(t.prototype);for(var i in e)n[i]=e[i];return n}function Ct(){}var Mt=.7,Tt=1/Mt,Lt="\\s*([+-]?\\d+)\\s*",Pt="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",kt="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",zt=/^#([0-9a-f]{3,8})$/,$t=new RegExp(`^rgb\\(${Lt},${Lt},${Lt}\\)$`),Et=new RegExp(`^rgb\\(${kt},${kt},${kt}\\)$`),At=new RegExp(`^rgba\\(${Lt},${Lt},${Lt},${Pt}\\)$`),Nt=new RegExp(`^rgba\\(${kt},${kt},${kt},${Pt}\\)$`),Rt=new RegExp(`^hsl\\(${Pt},${kt},${kt}\\)$`),Bt=new RegExp(`^hsla\\(${Pt},${kt},${kt},${Pt}\\)$`),Ht={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};function Ft(){return this.rgb().formatHex()}function Xt(){return this.rgb().formatRgb()}function Vt(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=zt.exec(t))?(n=e[1].length,e=parseInt(e[1],16),6===n?Dt(e):3===n?new qt(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?Yt(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?Yt(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=$t.exec(t))?new qt(e[1],e[2],e[3],1):(e=Et.exec(t))?new qt(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=At.exec(t))?Yt(e[1],e[2],e[3],e[4]):(e=Nt.exec(t))?Yt(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=Rt.exec(t))?Wt(e[1],e[2]/100,e[3]/100,1):(e=Bt.exec(t))?Wt(e[1],e[2]/100,e[3]/100,e[4]):Ht.hasOwnProperty(t)?Dt(Ht[t]):"transparent"===t?new qt(NaN,NaN,NaN,0):null}function Dt(t){return new qt(t>>16&255,t>>8&255,255&t,1)}function Yt(t,e,n,i){return i<=0&&(t=e=n=NaN),new qt(t,e,n,i)}function Ot(t,e,n,i){return 1===arguments.length?((a=t)instanceof Ct||(a=Vt(a)),a?new qt((a=a.rgb()).r,a.g,a.b,a.opacity):new qt):new qt(t,e,n,null==i?1:i);var a}function qt(t,e,n,i){this.r=+t,this.g=+e,this.b=+n,this.opacity=+i}function It(){return`#${Ut(this.r)}${Ut(this.g)}${Ut(this.b)}`}function Zt(){const t=jt(this.opacity);return`${1===t?"rgb(":"rgba("}${Gt(this.r)}, ${Gt(this.g)}, ${Gt(this.b)}${1===t?")":`, ${t})`}`}function jt(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function Gt(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function Ut(t){return((t=Gt(t))<16?"0":"")+t.toString(16)}function Wt(t,e,n,i){return i<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new Qt(t,e,n,i)}function Kt(t){if(t instanceof Qt)return new Qt(t.h,t.s,t.l,t.opacity);if(t instanceof Ct||(t=Vt(t)),!t)return new Qt;if(t instanceof Qt)return t;var e=(t=t.rgb()).r/255,n=t.g/255,i=t.b/255,a=Math.min(e,n,i),s=Math.max(e,n,i),o=NaN,r=s-a,l=(s+a)/2;return r?(o=e===s?(n-i)/r+6*(n<i):n===s?(i-e)/r+2:(e-n)/r+4,r/=l<.5?s+a:2-s-a,o*=60):r=l>0&&l<1?0:o,new Qt(o,r,l,t.opacity)}function Qt(t,e,n,i){this.h=+t,this.s=+e,this.l=+n,this.opacity=+i}function Jt(t){return(t=(t||0)%360)<0?t+360:t}function te(t){return Math.max(0,Math.min(1,t||0))}function ee(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}_t(Ct,Vt,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:Ft,formatHex:Ft,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return Kt(this).formatHsl()},formatRgb:Xt,toString:Xt}),_t(qt,Ot,St(Ct,{brighter(t){return t=null==t?Tt:Math.pow(Tt,t),new qt(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?Mt:Math.pow(Mt,t),new qt(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new qt(Gt(this.r),Gt(this.g),Gt(this.b),jt(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:It,formatHex:It,formatHex8:function(){return`#${Ut(this.r)}${Ut(this.g)}${Ut(this.b)}${Ut(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:Zt,toString:Zt})),_t(Qt,function(t,e,n,i){return 1===arguments.length?Kt(t):new Qt(t,e,n,null==i?1:i)},St(Ct,{brighter(t){return t=null==t?Tt:Math.pow(Tt,t),new Qt(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?Mt:Math.pow(Mt,t),new Qt(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,i=n+(n<.5?n:1-n)*e,a=2*n-i;return new qt(ee(t>=240?t-240:t+120,a,i),ee(t,a,i),ee(t<120?t+240:t-120,a,i),this.opacity)},clamp(){return new Qt(Jt(this.h),te(this.s),te(this.l),jt(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 t=jt(this.opacity);return`${1===t?"hsl(":"hsla("}${Jt(this.h)}, ${100*te(this.s)}%, ${100*te(this.l)}%${1===t?")":`, ${t})`}`}}));const ne=t=>()=>t;function ie(t){return 1===(t=+t)?ae:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(i){return Math.pow(t+i*e,n)}}(e,n,t):ne(isNaN(e)?n:e)}}function ae(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):ne(isNaN(t)?e:t)}const se=function t(e){var n=ie(e);function i(t,e){var i=n((t=Ot(t)).r,(e=Ot(e)).r),a=n(t.g,e.g),s=n(t.b,e.b),o=ae(t.opacity,e.opacity);return function(e){return t.r=i(e),t.g=a(e),t.b=s(e),t.opacity=o(e),t+""}}return i.gamma=t,i}(1);function oe(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}var re=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,le=new RegExp(re.source,"g");function he(t,e){var n,i,a,s=re.lastIndex=le.lastIndex=0,o=-1,r=[],l=[];for(t+="",e+="";(n=re.exec(t))&&(i=le.exec(e));)(a=i.index)>s&&(a=e.slice(s,a),r[o]?r[o]+=a:r[++o]=a),(n=n[0])===(i=i[0])?r[o]?r[o]+=i:r[++o]=i:(r[++o]=null,l.push({i:o,x:oe(n,i)})),s=le.lastIndex;return s<e.length&&(a=e.slice(s),r[o]?r[o]+=a:r[++o]=a),r.length<2?l[0]?function(t){return function(e){return t(e)+""}}(l[0].x):function(t){return function(){return t}}(e):(e=l.length,function(t){for(var n,i=0;i<e;++i)r[(n=l[i]).i]=n.x(t);return r.join("")})}var ce,ue=180/Math.PI,de={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function pe(t,e,n,i,a,s){var o,r,l;return(o=Math.sqrt(t*t+e*e))&&(t/=o,e/=o),(l=t*n+e*i)&&(n-=t*l,i-=e*l),(r=Math.sqrt(n*n+i*i))&&(n/=r,i/=r,l/=r),t*i<e*n&&(t=-t,e=-e,l=-l,o=-o),{translateX:a,translateY:s,rotate:Math.atan2(e,t)*ue,skewX:Math.atan(l)*ue,scaleX:o,scaleY:r}}function fe(t,e,n,i){function a(t){return t.length?t.pop()+" ":""}return function(s,o){var r=[],l=[];return s=t(s),o=t(o),function(t,i,a,s,o,r){if(t!==a||i!==s){var l=o.push("translate(",null,e,null,n);r.push({i:l-4,x:oe(t,a)},{i:l-2,x:oe(i,s)})}else(a||s)&&o.push("translate("+a+e+s+n)}(s.translateX,s.translateY,o.translateX,o.translateY,r,l),function(t,e,n,s){t!==e?(t-e>180?e+=360:e-t>180&&(t+=360),s.push({i:n.push(a(n)+"rotate(",null,i)-2,x:oe(t,e)})):e&&n.push(a(n)+"rotate("+e+i)}(s.rotate,o.rotate,r,l),function(t,e,n,s){t!==e?s.push({i:n.push(a(n)+"skewX(",null,i)-2,x:oe(t,e)}):e&&n.push(a(n)+"skewX("+e+i)}(s.skewX,o.skewX,r,l),function(t,e,n,i,s,o){if(t!==n||e!==i){var r=s.push(a(s)+"scale(",null,",",null,")");o.push({i:r-4,x:oe(t,n)},{i:r-2,x:oe(e,i)})}else 1===n&&1===i||s.push(a(s)+"scale("+n+","+i+")")}(s.scaleX,s.scaleY,o.scaleX,o.scaleY,r,l),s=o=null,function(t){for(var e,n=-1,i=l.length;++n<i;)r[(e=l[n]).i]=e.x(t);return r.join("")}}}var ge=fe(function(t){const e=new("function"==typeof DOMMatrix?DOMMatrix:WebKitCSSMatrix)(t+"");return e.isIdentity?de:pe(e.a,e.b,e.c,e.d,e.e,e.f)},"px, ","px)","deg)"),me=fe(function(t){return null==t?de:(ce||(ce=document.createElementNS("http://www.w3.org/2000/svg","g")),ce.setAttribute("transform",t),(t=ce.transform.baseVal.consolidate())?pe((t=t.matrix).a,t.b,t.c,t.d,t.e,t.f):de)},", ",")",")");function ye(t){return((t=Math.exp(t))+1/t)/2}const xe=function t(e,n,i){function a(t,a){var s,o,r=t[0],l=t[1],h=t[2],c=a[0],u=a[1],d=a[2],p=c-r,f=u-l,g=p*p+f*f;if(g<1e-12)o=Math.log(d/h)/e,s=function(t){return[r+t*p,l+t*f,h*Math.exp(e*t*o)]};else{var m=Math.sqrt(g),y=(d*d-h*h+i*g)/(2*h*n*m),x=(d*d-h*h-i*g)/(2*d*n*m),b=Math.log(Math.sqrt(y*y+1)-y),v=Math.log(Math.sqrt(x*x+1)-x);o=(v-b)/e,s=function(t){var i,a=t*o,s=ye(b),c=h/(n*m)*(s*(i=e*a+b,((i=Math.exp(2*i))-1)/(i+1))-function(t){return((t=Math.exp(t))-1/t)/2}(b));return[r+c*p,l+c*f,h*s/ye(e*a+b)]}}return s.duration=1e3*o*e/Math.SQRT2,s}return a.rho=function(e){var n=Math.max(.001,+e),i=n*n;return t(n,i,i*i)},a}(Math.SQRT2,2,4);var be,ve,we=0,_e=0,Se=0,Ce=0,Me=0,Te=0,Le="object"==typeof performance&&performance.now?performance:Date,Pe="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function ke(){return Me||(Pe(ze),Me=Le.now()+Te)}function ze(){Me=0}function $e(){this._call=this._time=this._next=null}function Ee(t,e,n){var i=new $e;return i.restart(t,e,n),i}function Ae(){Me=(Ce=Le.now())+Te,we=_e=0;try{!function(){ke(),++we;for(var t,e=be;e;)(t=Me-e._time)>=0&&e._call.call(void 0,t),e=e._next;--we}()}finally{we=0,function(){var t,e,n=be,i=1/0;for(;n;)n._call?(i>n._time&&(i=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:be=e);ve=t,Re(i)}(),Me=0}}function Ne(){var t=Le.now(),e=t-Ce;e>1e3&&(Te-=e,Ce=t)}function Re(t){we||(_e&&(_e=clearTimeout(_e)),t-Me>24?(t<1/0&&(_e=setTimeout(Ae,t-Le.now()-Te)),Se&&(Se=clearInterval(Se))):(Se||(Ce=Le.now(),Se=setInterval(Ne,1e3)),we=1,Pe(Ae)))}function Be(t,e,n){var i=new $e;return e=null==e?0:+e,i.restart(n=>{i.stop(),t(n+e)},e,n),i}$e.prototype=Ee.prototype={constructor:$e,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?ke():+n)+(null==e?0:+e),this._next||ve===this||(ve?ve._next=this:be=this,ve=this),this._call=t,this._time=n,Re()},stop:function(){this._call&&(this._call=null,this._time=1/0,Re())}};var He=n("start","end","cancel","interrupt"),Fe=[];function Xe(t,e,n,i,a,s){var o=t.__transition;if(o){if(n in o)return}else t.__transition={};!function(t,e,n){var i,a=t.__transition;function s(t){n.state=1,n.timer.restart(o,n.delay,n.time),n.delay<=t&&o(t-n.delay)}function o(s){var h,c,u,d;if(1!==n.state)return l();for(h in a)if((d=a[h]).name===n.name){if(3===d.state)return Be(o);4===d.state?(d.state=6,d.timer.stop(),d.on.call("interrupt",t,t.__data__,d.index,d.group),delete a[h]):+h<e&&(d.state=6,d.timer.stop(),d.on.call("cancel",t,t.__data__,d.index,d.group),delete a[h])}if(Be(function(){3===n.state&&(n.state=4,n.timer.restart(r,n.delay,n.time),r(s))}),n.state=2,n.on.call("start",t,t.__data__,n.index,n.group),2===n.state){for(n.state=3,i=new Array(u=n.tween.length),h=0,c=-1;h<u;++h)(d=n.tween[h].value.call(t,t.__data__,n.index,n.group))&&(i[++c]=d);i.length=c+1}}function r(e){for(var a=e<n.duration?n.ease.call(null,e/n.duration):(n.timer.restart(l),n.state=5,1),s=-1,o=i.length;++s<o;)i[s].call(t,a);5===n.state&&(n.on.call("end",t,t.__data__,n.index,n.group),l())}function l(){for(var i in n.state=6,n.timer.stop(),delete a[e],a)return;delete t.__transition}a[e]=n,n.timer=Ee(s,0,n.time)}(t,n,{name:e,index:i,group:a,on:He,tween:Fe,time:s.time,delay:s.delay,duration:s.duration,ease:s.ease,timer:null,state:0})}function Ve(t,e){var n=Ye(t,e);if(n.state>0)throw new Error("too late; already scheduled");return n}function De(t,e){var n=Ye(t,e);if(n.state>3)throw new Error("too late; already running");return n}function Ye(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function Oe(t,e){var n,i,a,s=t.__transition,o=!0;if(s){for(a in e=null==e?null:e+"",s)(n=s[a]).name===e?(i=n.state>2&&n.state<5,n.state=6,n.timer.stop(),n.on.call(i?"interrupt":"cancel",t,t.__data__,n.index,n.group),delete s[a]):o=!1;o&&delete t.__transition}}function qe(t,e){var n,i;return function(){var a=De(this,t),s=a.tween;if(s!==n)for(var o=0,r=(i=n=s).length;o<r;++o)if(i[o].name===e){(i=i.slice()).splice(o,1);break}a.tween=i}}function Ie(t,e,n){var i,a;if("function"!=typeof n)throw new Error;return function(){var s=De(this,t),o=s.tween;if(o!==i){a=(i=o).slice();for(var r={name:e,value:n},l=0,h=a.length;l<h;++l)if(a[l].name===e){a[l]=r;break}l===h&&a.push(r)}s.tween=a}}function Ze(t,e,n){var i=t._id;return t.each(function(){var t=De(this,i);(t.value||(t.value={}))[e]=n.apply(this,arguments)}),function(t){return Ye(t,i).value[e]}}function je(t,e){var n;return("number"==typeof e?oe:e instanceof Vt?se:(n=Vt(e))?(e=n,se):he)(t,e)}function Ge(t){return function(){this.removeAttribute(t)}}function Ue(t){return function(){this.removeAttributeNS(t.space,t.local)}}function We(t,e,n){var i,a,s=n+"";return function(){var o=this.getAttribute(t);return o===s?null:o===i?a:a=e(i=o,n)}}function Ke(t,e,n){var i,a,s=n+"";return function(){var o=this.getAttributeNS(t.space,t.local);return o===s?null:o===i?a:a=e(i=o,n)}}function Qe(t,e,n){var i,a,s;return function(){var o,r,l=n(this);if(null!=l)return(o=this.getAttribute(t))===(r=l+"")?null:o===i&&r===a?s:(a=r,s=e(i=o,l));this.removeAttribute(t)}}function Je(t,e,n){var i,a,s;return function(){var o,r,l=n(this);if(null!=l)return(o=this.getAttributeNS(t.space,t.local))===(r=l+"")?null:o===i&&r===a?s:(a=r,s=e(i=o,l));this.removeAttributeNS(t.space,t.local)}}function tn(t,e){var n,i;function a(){var a=e.apply(this,arguments);return a!==i&&(n=(i=a)&&function(t,e){return function(n){this.setAttributeNS(t.space,t.local,e.call(this,n))}}(t,a)),n}return a._value=e,a}function en(t,e){var n,i;function a(){var a=e.apply(this,arguments);return a!==i&&(n=(i=a)&&function(t,e){return function(n){this.setAttribute(t,e.call(this,n))}}(t,a)),n}return a._value=e,a}function nn(t,e){return function(){Ve(this,t).delay=+e.apply(this,arguments)}}function an(t,e){return e=+e,function(){Ve(this,t).delay=e}}function sn(t,e){return function(){De(this,t).duration=+e.apply(this,arguments)}}function on(t,e){return e=+e,function(){De(this,t).duration=e}}var rn=yt.prototype.constructor;function ln(t){return function(){this.style.removeProperty(t)}}var hn=0;function cn(t,e,n,i){this._groups=t,this._parents=e,this._name=n,this._id=i}function un(){return++hn}var dn=yt.prototype;cn.prototype={constructor:cn,select:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=p(t));for(var i=this._groups,a=i.length,s=new Array(a),o=0;o<a;++o)for(var r,l,h=i[o],c=h.length,u=s[o]=new Array(c),d=0;d<c;++d)(r=h[d])&&(l=t.call(r,r.__data__,d,h))&&("__data__"in r&&(l.__data__=r.__data__),u[d]=l,Xe(u[d],e,n,d,u,Ye(r,n)));return new cn(s,this._parents,e,n)},selectAll:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=g(t));for(var i=this._groups,a=i.length,s=[],o=[],r=0;r<a;++r)for(var l,h=i[r],c=h.length,u=0;u<c;++u)if(l=h[u]){for(var d,p=t.call(l,l.__data__,u,h),f=Ye(l,n),m=0,y=p.length;m<y;++m)(d=p[m])&&Xe(d,e,n,m,p,f);s.push(p),o.push(l)}return new cn(s,o,e,n)},selectChild:dn.selectChild,selectChildren:dn.selectChildren,filter:function(t){"function"!=typeof t&&(t=y(t));for(var e=this._groups,n=e.length,i=new Array(n),a=0;a<n;++a)for(var s,o=e[a],r=o.length,l=i[a]=[],h=0;h<r;++h)(s=o[h])&&t.call(s,s.__data__,h,o)&&l.push(s);return new cn(i,this._parents,this._name,this._id)},merge:function(t){if(t._id!==this._id)throw new Error;for(var e=this._groups,n=t._groups,i=e.length,a=n.length,s=Math.min(i,a),o=new Array(i),r=0;r<s;++r)for(var l,h=e[r],c=n[r],u=h.length,d=o[r]=new Array(u),p=0;p<u;++p)(l=h[p]||c[p])&&(d[p]=l);for(;r<i;++r)o[r]=e[r];return new cn(o,this._parents,this._name,this._id)},selection:function(){return new rn(this._groups,this._parents)},transition:function(){for(var t=this._name,e=this._id,n=un(),i=this._groups,a=i.length,s=0;s<a;++s)for(var o,r=i[s],l=r.length,h=0;h<l;++h)if(o=r[h]){var c=Ye(o,e);Xe(o,t,n,h,r,{time:c.time+c.delay+c.duration,delay:0,duration:c.duration,ease:c.ease})}return new cn(i,this._parents,t,n)},call:dn.call,nodes:dn.nodes,node:dn.node,size:dn.size,empty:dn.empty,each:dn.each,on:function(t,e){var n=this._id;return arguments.length<2?Ye(this.node(),n).on.on(t):this.each(function(t,e,n){var i,a,s=function(t){return(t+"").trim().split(/^|\s+/).every(function(t){var e=t.indexOf(".");return e>=0&&(t=t.slice(0,e)),!t||"start"===t})}(e)?Ve:De;return function(){var o=s(this,t),r=o.on;r!==i&&(a=(i=r).copy()).on(e,n),o.on=a}}(n,t,e))},attr:function(t,e){var n=l(t),i="transform"===n?me:je;return this.attrTween(t,"function"==typeof e?(n.local?Je:Qe)(n,i,Ze(this,"attr."+t,e)):null==e?(n.local?Ue:Ge)(n):(n.local?Ke:We)(n,i,e))},attrTween:function(t,e){var n="attr."+t;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(null==e)return this.tween(n,null);if("function"!=typeof e)throw new Error;var i=l(t);return this.tween(n,(i.local?tn:en)(i,e))},style:function(t,e,n){var i="transform"==(t+="")?ge:je;return null==e?this.styleTween(t,function(t,e){var n,i,a;return function(){var s=V(this,t),o=(this.style.removeProperty(t),V(this,t));return s===o?null:s===n&&o===i?a:a=e(n=s,i=o)}}(t,i)).on("end.style."+t,ln(t)):"function"==typeof e?this.styleTween(t,function(t,e,n){var i,a,s;return function(){var o=V(this,t),r=n(this),l=r+"";return null==r&&(this.style.removeProperty(t),l=r=V(this,t)),o===l?null:o===i&&l===a?s:(a=l,s=e(i=o,r))}}(t,i,Ze(this,"style."+t,e))).each(function(t,e){var n,i,a,s,o="style."+e,r="end."+o;return function(){var l=De(this,t),h=l.on,c=null==l.value[o]?s||(s=ln(e)):void 0;h===n&&a===c||(i=(n=h).copy()).on(r,a=c),l.on=i}}(this._id,t)):this.styleTween(t,function(t,e,n){var i,a,s=n+"";return function(){var o=V(this,t);return o===s?null:o===i?a:a=e(i=o,n)}}(t,i,e),n).on("end.style."+t,null)},styleTween:function(t,e,n){var i="style."+(t+="");if(arguments.length<2)return(i=this.tween(i))&&i._value;if(null==e)return this.tween(i,null);if("function"!=typeof e)throw new Error;return this.tween(i,function(t,e,n){var i,a;function s(){var s=e.apply(this,arguments);return s!==a&&(i=(a=s)&&function(t,e,n){return function(i){this.style.setProperty(t,e.call(this,i),n)}}(t,s,n)),i}return s._value=e,s}(t,e,null==n?"":n))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var e=t(this);this.textContent=null==e?"":e}}(Ze(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},textTween:function(t){var e="text";if(arguments.length<1)return(e=this.tween(e))&&e._value;if(null==t)return this.tween(e,null);if("function"!=typeof t)throw new Error;return this.tween(e,function(t){var e,n;function i(){var i=t.apply(this,arguments);return i!==n&&(e=(n=i)&&function(t){return function(e){this.textContent=t.call(this,e)}}(i)),e}return i._value=t,i}(t))},remove:function(){return this.on("end.remove",(t=this._id,function(){var e=this.parentNode;for(var n in this.__transition)if(+n!==t)return;e&&e.removeChild(this)}));var t},tween:function(t,e){var n=this._id;if(t+="",arguments.length<2){for(var i,a=Ye(this.node(),n).tween,s=0,o=a.length;s<o;++s)if((i=a[s]).name===t)return i.value;return null}return this.each((null==e?qe:Ie)(n,t,e))},delay:function(t){var e=this._id;return arguments.length?this.each(("function"==typeof t?nn:an)(e,t)):Ye(this.node(),e).delay},duration:function(t){var e=this._id;return arguments.length?this.each(("function"==typeof t?sn:on)(e,t)):Ye(this.node(),e).duration},ease:function(t){var e=this._id;return arguments.length?this.each(function(t,e){if("function"!=typeof e)throw new Error;return function(){De(this,t).ease=e}}(e,t)):Ye(this.node(),e).ease},easeVarying:function(t){if("function"!=typeof t)throw new Error;return this.each(function(t,e){return function(){var n=e.apply(this,arguments);if("function"!=typeof n)throw new Error;De(this,t).ease=n}}(this._id,t))},end:function(){var t,e,n=this,i=n._id,a=n.size();return new Promise(function(s,o){var r={value:o},l={value:function(){0===--a&&s()}};n.each(function(){var n=De(this,i),a=n.on;a!==t&&((e=(t=a).copy())._.cancel.push(r),e._.interrupt.push(r),e._.end.push(l)),n.on=e}),0===a&&s()})},[Symbol.iterator]:dn[Symbol.iterator]};var pn={time:null,delay:0,duration:250,ease:function(t){return((t*=2)<=1?t*t*t:(t-=2)*t*t+2)/2}};function fn(t,e){for(var n;!(n=t.__transition)||!(n=n[e]);)if(!(t=t.parentNode))throw new Error(`transition ${e} not found`);return n}yt.prototype.interrupt=function(t){return this.each(function(){Oe(this,t)})},yt.prototype.transition=function(t){var e,n;t instanceof cn?(e=t._id,t=t._name):(e=un(),(n=pn).time=ke(),t=null==t?null:t+"");for(var i=this._groups,a=i.length,s=0;s<a;++s)for(var o,r=i[s],l=r.length,h=0;h<l;++h)(o=r[h])&&Xe(o,t,e,h,r,n||fn(o,e));return new cn(i,this._parents,t,e)};const gn=Math.PI,mn=2*gn,yn=1e-6,xn=mn-yn;function bn(t){this._+=t[0];for(let e=1,n=t.length;e<n;++e)this._+=arguments[e]+t[e]}class vn{constructor(t){this._x0=this._y0=this._x1=this._y1=null,this._="",this._append=null==t?bn:function(t){let e=Math.floor(t);if(!(e>=0))throw new Error(`invalid digits: ${t}`);if(e>15)return bn;const n=10**e;return function(t){this._+=t[0];for(let e=1,i=t.length;e<i;++e)this._+=Math.round(arguments[e]*n)/n+t[e]}}(t)}moveTo(t,e){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}`}closePath(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._append`Z`)}lineTo(t,e){this._append`L${this._x1=+t},${this._y1=+e}`}quadraticCurveTo(t,e,n,i){this._append`Q${+t},${+e},${this._x1=+n},${this._y1=+i}`}bezierCurveTo(t,e,n,i,a,s){this._append`C${+t},${+e},${+n},${+i},${this._x1=+a},${this._y1=+s}`}arcTo(t,e,n,i,a){if(t=+t,e=+e,n=+n,i=+i,(a=+a)<0)throw new Error(`negative radius: ${a}`);let s=this._x1,o=this._y1,r=n-t,l=i-e,h=s-t,c=o-e,u=h*h+c*c;if(null===this._x1)this._append`M${this._x1=t},${this._y1=e}`;else if(u>yn)if(Math.abs(c*r-l*h)>yn&&a){let d=n-s,p=i-o,f=r*r+l*l,g=d*d+p*p,m=Math.sqrt(f),y=Math.sqrt(u),x=a*Math.tan((gn-Math.acos((f+u-g)/(2*m*y)))/2),b=x/y,v=x/m;Math.abs(b-1)>yn&&this._append`L${t+b*h},${e+b*c}`,this._append`A${a},${a},0,0,${+(c*d>h*p)},${this._x1=t+v*r},${this._y1=e+v*l}`}else this._append`L${this._x1=t},${this._y1=e}`;else;}arc(t,e,n,i,a,s){if(t=+t,e=+e,s=!!s,(n=+n)<0)throw new Error(`negative radius: ${n}`);let o=n*Math.cos(i),r=n*Math.sin(i),l=t+o,h=e+r,c=1^s,u=s?i-a:a-i;null===this._x1?this._append`M${l},${h}`:(Math.abs(this._x1-l)>yn||Math.abs(this._y1-h)>yn)&&this._append`L${l},${h}`,n&&(u<0&&(u=u%mn+mn),u>xn?this._append`A${n},${n},0,1,${c},${t-o},${e-r}A${n},${n},0,1,${c},${this._x1=l},${this._y1=h}`:u>yn&&this._append`A${n},${n},0,${+(u>=gn)},${c},${this._x1=t+n*Math.cos(a)},${this._y1=e+n*Math.sin(a)}`)}rect(t,e,n,i){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${n=+n}v${+i}h${-n}Z`}toString(){return this._}}function wn(t,e){return t.parent===e.parent?1:2}function _n(t,e){return t+e.x}function Sn(t,e){return Math.max(t,e.y)}function Cn(){var t=wn,e=1,n=1,i=!1;function a(a){var s,o=0;a.eachAfter(function(e){var n=e.children;n?(e.x=function(t){return t.reduce(_n,0)/t.length}(n),e.y=function(t){return 1+t.reduce(Sn,0)}(n)):(e.x=s?o+=t(e,s):0,e.y=0,s=e)});var r=function(t){for(var e;e=t.children;)t=e[0];return t}(a),l=function(t){for(var e;e=t.children;)t=e[e.length-1];return t}(a),h=r.x-t(r,l)/2,c=l.x+t(l,r)/2;return a.eachAfter(i?function(t){t.x=(t.x-a.x)*e,t.y=(a.y-t.y)*n}:function(t){t.x=(t.x-h)/(c-h)*e,t.y=(1-(a.y?t.y/a.y:1))*n})}return a.separation=function(e){return arguments.length?(t=e,a):t},a.size=function(t){return arguments.length?(i=!1,e=+t[0],n=+t[1],a):i?null:[e,n]},a.nodeSize=function(t){return arguments.length?(i=!0,e=+t[0],n=+t[1],a):i?[e,n]:null},a}function Mn(t){var e=0,n=t.children,i=n&&n.length;if(i)for(;--i>=0;)e+=n[i].value;else e=1;t.value=e}function Tn(t,e){t instanceof Map?(t=[void 0,t],void 0===e&&(e=Pn)):void 0===e&&(e=Ln);for(var n,i,a,s,o,r=new $n(t),l=[r];n=l.pop();)if((a=e(n.data))&&(o=(a=Array.from(a)).length))for(n.children=a,s=o-1;s>=0;--s)l.push(i=a[s]=new $n(a[s])),i.parent=n,i.depth=n.depth+1;return r.eachBefore(zn)}function Ln(t){return t.children}function Pn(t){return Array.isArray(t)?t[1]:null}function kn(t){void 0!==t.data.value&&(t.value=t.data.value),t.data=t.data.data}function zn(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function $n(t){this.data=t,this.depth=this.height=0,this.parent=null}function En(t){return function(){return t}}$n.prototype=Tn.prototype={constructor:$n,count:function(){return this.eachAfter(Mn)},each:function(t,e){let n=-1;for(const i of this)t.call(e,i,++n,this);return this},eachAfter:function(t,e){for(var n,i,a,s=this,o=[s],r=[],l=-1;s=o.pop();)if(r.push(s),n=s.children)for(i=0,a=n.length;i<a;++i)o.push(n[i]);for(;s=r.pop();)t.call(e,s,++l,this);return this},eachBefore:function(t,e){for(var n,i,a=this,s=[a],o=-1;a=s.pop();)if(t.call(e,a,++o,this),n=a.children)for(i=n.length-1;i>=0;--i)s.push(n[i]);return this},find:function(t,e){let n=-1;for(const i of this)if(t.call(e,i,++n,this))return i},sum:function(t){return this.eachAfter(function(e){for(var n=+t(e.data)||0,i=e.children,a=i&&i.length;--a>=0;)n+=i[a].value;e.value=n})},sort:function(t){return this.eachBefore(function(e){e.children&&e.children.sort(t)})},path:function(t){for(var e=this,n=function(t,e){if(t===e)return t;var n=t.ancestors(),i=e.ancestors(),a=null;t=n.pop(),e=i.pop();for(;t===e;)a=t,t=n.pop(),e=i.pop();return a}(e,t),i=[e];e!==n;)e=e.parent,i.push(e);for(var a=i.length;t!==n;)i.splice(a,0,t),t=t.parent;return i},ancestors:function(){for(var t=this,e=[t];t=t.parent;)e.push(t);return e},descendants:function(){return Array.from(this)},leaves:function(){var t=[];return this.eachBefore(function(e){e.children||t.push(e)}),t},links:function(){var t=this,e=[];return t.each(function(n){n!==t&&e.push({source:n.parent,target:n})}),e},copy:function(){return Tn(this).eachBefore(kn)},[Symbol.iterator]:function*(){var t,e,n,i,a=this,s=[a];do{for(t=s.reverse(),s=[];a=t.pop();)if(yield a,e=a.children)for(n=0,i=e.length;n<i;++n)s.push(e[n])}while(s.length)}};const An=Math.sqrt,Nn=Math.PI,Rn=2*Nn;const Bn={draw(t,e){const n=An(e/Nn);t.moveTo(n,0),t.arc(0,0,n,0,Rn)}},Hn=An(3),Fn={draw(t,e){const n=-An(e/(3*Hn));t.moveTo(0,2*n),t.lineTo(-Hn*n,-n),t.lineTo(Hn*n,-n),t.closePath()}};function Xn(t,e){let n=null,i=function(t){let e=3;return t.digits=function(n){if(!arguments.length)return e;if(null==n)e=null;else{const t=Math.floor(n);if(!(t>=0))throw new RangeError(`invalid digits: ${n}`);e=t}return t},()=>new vn(e)}(a);function a(){let a;if(n||(n=a=i()),t.apply(this,arguments).draw(n,+e.apply(this,arguments)),a)return n=null,a+""||null}return t="function"==typeof t?t:En(t||Bn),e="function"==typeof e?e:En(void 0===e?64:+e),a.type=function(e){return arguments.length?(t="function"==typeof e?e:En(e),a):t},a.size=function(t){return arguments.length?(e="function"==typeof t?t:En(+t),a):e},a.context=function(t){return arguments.length?(n=null==t?null:t,a):n},a}const Vn=t=>()=>t;function Dn(t,{sourceEvent:e,target:n,transform:i,dispatch:a}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:i,enumerable:!0,configurable:!0},_:{value:a}})}function Yn(t,e,n){this.k=t,this.x=e,this.y=n}Yn.prototype={constructor:Yn,scale:function(t){return 1===t?this:new Yn(this.k*t,this.x,this.y)},translate:function(t,e){return 0===t&0===e?this:new Yn(this.k,this.x+this.k*t,this.y+this.k*e)},apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},applyX:function(t){return t*this.k+this.x},applyY:function(t){return t*this.k+this.y},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},invertX:function(t){return(t-this.x)/this.k},invertY:function(t){return(t-this.y)/this.k},rescaleX:function(t){return t.copy().domain(t.range().map(this.invertX,this).map(t.invert,t))},rescaleY:function(t){return t.copy().domain(t.range().map(this.invertY,this).map(t.invert,t))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var On=new Yn(1,0,0);function qn(t){t.stopImmediatePropagation()}function In(t){t.preventDefault(),t.stopImmediatePropagation()}function Zn(t){return!(t.ctrlKey&&"wheel"!==t.type||t.button)}function jn(){var t=this;return t instanceof SVGElement?(t=t.ownerSVGElement||t).hasAttribute("viewBox")?[[(t=t.viewBox.baseVal).x,t.y],[t.x+t.width,t.y+t.height]]:[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]:[[0,0],[t.clientWidth,t.clientHeight]]}function Gn(){return this.__zoom||On}function Un(t){return-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function Wn(){return navigator.maxTouchPoints||"ontouchstart"in this}function Kn(t,e,n){var i=t.invertX(e[0][0])-n[0][0],a=t.invertX(e[1][0])-n[1][0],s=t.invertY(e[0][1])-n[0][1],o=t.invertY(e[1][1])-n[1][1];return t.translate(a>i?(i+a)/2:Math.min(0,i)||Math.max(0,a),o>s?(s+o)/2:Math.min(0,s)||Math.max(0,o))}function Qn(){var t,e,i,a=Zn,s=jn,o=Kn,r=Un,l=Wn,h=[0,1/0],c=[[-1/0,-1/0],[1/0,1/0]],u=250,d=xe,p=n("start","zoom","end"),f=0,g=10;function m(t){t.property("__zoom",Gn).on("wheel.zoom",S,{passive:!1}).on("mousedown.zoom",C).on("dblclick.zoom",M).filter(l).on("touchstart.zoom",T).on("touchmove.zoom",L).on("touchend.zoom touchcancel.zoom",P).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function y(t,e){return(e=Math.max(h[0],Math.min(h[1],e)))===t.k?t:new Yn(e,t.x,t.y)}function x(t,e,n){var i=e[0]-n[0]*t.k,a=e[1]-n[1]*t.k;return i===t.x&&a===t.y?t:new Yn(t.k,i,a)}function b(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function v(t,e,n,i){t.on("start.zoom",function(){w(this,arguments).event(i).start()}).on("interrupt.zoom end.zoom",function(){w(this,arguments).event(i).end()}).tween("zoom",function(){var t=this,a=arguments,o=w(t,a).event(i),r=s.apply(t,a),l=null==n?b(r):"function"==typeof n?n.apply(t,a):n,h=Math.max(r[1][0]-r[0][0],r[1][1]-r[0][1]),c=t.__zoom,u="function"==typeof e?e.apply(t,a):e,p=d(c.invert(l).concat(h/c.k),u.invert(l).concat(h/u.k));return function(t){if(1===t)t=u;else{var e=p(t),n=h/e[2];t=new Yn(n,l[0]-e[0]*n,l[1]-e[1]*n)}o.zoom(null,t)}})}function w(t,e,n){return!n&&t.__zooming||new _(t,e)}function _(t,e){this.that=t,this.args=e,this.active=0,this.sourceEvent=null,this.extent=s.apply(t,e),this.taps=0}function S(t,...e){if(a.apply(this,arguments)){var n=w(this,e).event(t),i=this.__zoom,s=Math.max(h[0],Math.min(h[1],i.k*Math.pow(2,r.apply(this,arguments)))),l=bt(t);if(n.wheel)n.mouse[0][0]===l[0]&&n.mouse[0][1]===l[1]||(n.mouse[1]=i.invert(n.mouse[0]=l)),clearTimeout(n.wheel);else{if(i.k===s)return;n.mouse=[l,i.invert(l)],Oe(this),n.start()}In(t),n.wheel=setTimeout(function(){n.wheel=null,n.end()},150),n.zoom("mouse",o(x(y(i,s),n.mouse[0],n.mouse[1]),n.extent,c))}}function C(t,...e){if(!i&&a.apply(this,arguments)){var n,s,r,l=t.currentTarget,h=w(this,e,!0).event(t),u=xt(t.view).on("mousemove.zoom",function(t){if(In(t),!h.moved){var e=t.clientX-p,n=t.clientY-g;h.moved=e*e+n*n>f}h.event(t).zoom("mouse",o(x(h.that.__zoom,h.mouse[0]=bt(t,l),h.mouse[1]),h.extent,c))},!0).on("mouseup.zoom",function(t){u.on("mousemove.zoom mouseup.zoom",null),e=t.view,n=h.moved,i=e.document.documentElement,a=xt(e).on("dragstart.drag",null),n&&(a.on("click.drag",wt,vt),setTimeout(function(){a.on("click.drag",null)},0)),"onselectstart"in i?a.on("selectstart.drag",null):(i.style.MozUserSelect=i.__noselect,delete i.__noselect),In(t),h.event(t).end();var e,n,i,a},!0),d=bt(t,l),p=t.clientX,g=t.clientY;n=t.view,s=n.document.documentElement,r=xt(n).on("dragstart.drag",wt,vt),"onselectstart"in s?r.on("selectstart.drag",wt,vt):(s.__noselect=s.style.MozUserSelect,s.style.MozUserSelect="none"),qn(t),h.mouse=[d,this.__zoom.invert(d)],Oe(this),h.start()}}function M(t,...e){if(a.apply(this,arguments)){var n=this.__zoom,i=bt(t.changedTouches?t.changedTouches[0]:t,this),r=n.invert(i),l=n.k*(t.shiftKey?.5:2),h=o(x(y(n,l),i,r),s.apply(this,e),c);In(t),u>0?xt(this).transition().duration(u).call(v,h,i,t):xt(this).call(m.transform,h,i,t)}}function T(n,...i){if(a.apply(this,arguments)){var s,o,r,l,h=n.touches,c=h.length,u=w(this,i,n.changedTouches.length===c).event(n);for(qn(n),o=0;o<c;++o)l=[l=bt(r=h[o],this),this.__zoom.invert(l),r.identifier],u.touch0?u.touch1||u.touch0[2]===l[2]||(u.touch1=l,u.taps=0):(u.touch0=l,s=!0,u.taps=1+!!t);t&&(t=clearTimeout(t)),s&&(u.taps<2&&(e=l[0],t=setTimeout(function(){t=null},500)),Oe(this),u.start())}}function L(t,...e){if(this.__zooming){var n,i,a,s,r=w(this,e).event(t),l=t.changedTouches,h=l.length;for(In(t),n=0;n<h;++n)a=bt(i=l[n],this),r.touch0&&r.touch0[2]===i.identifier?r.touch0[0]=a:r.touch1&&r.touch1[2]===i.identifier&&(r.touch1[0]=a);if(i=r.that.__zoom,r.touch1){var u=r.touch0[0],d=r.touch0[1],p=r.touch1[0],f=r.touch1[1],g=(g=p[0]-u[0])*g+(g=p[1]-u[1])*g,m=(m=f[0]-d[0])*m+(m=f[1]-d[1])*m;i=y(i,Math.sqrt(g/m)),a=[(u[0]+p[0])/2,(u[1]+p[1])/2],s=[(d[0]+f[0])/2,(d[1]+f[1])/2]}else{if(!r.touch0)return;a=r.touch0[0],s=r.touch0[1]}r.zoom("touch",o(x(i,a,s),r.extent,c))}}function P(t,...n){if(this.__zooming){var a,s,o=w(this,n).event(t),r=t.changedTouches,l=r.length;for(qn(t),i&&clearTimeout(i),i=setTimeout(function(){i=null},500),a=0;a<l;++a)s=r[a],o.touch0&&o.touch0[2]===s.identifier?delete o.touch0:o.touch1&&o.touch1[2]===s.identifier&&delete o.touch1;if(o.touch1&&!o.touch0&&(o.touch0=o.touch1,delete o.touch1),o.touch0)o.touch0[1]=this.__zoom.invert(o.touch0[0]);else if(o.end(),2===o.taps&&(s=bt(s,this),Math.hypot(e[0]-s[0],e[1]-s[1])<g)){var h=xt(this).on("dblclick.zoom");h&&h.apply(this,arguments)}}}return m.transform=function(t,e,n,i){var a=t.selection?t.selection():t;a.property("__zoom",Gn),t!==a?v(t,e,n,i):a.interrupt().each(function(){w(this,arguments).event(i).start().zoom(null,"function"==typeof e?e.apply(this,arguments):e).end()})},m.scaleBy=function(t,e,n,i){m.scaleTo(t,function(){return this.__zoom.k*("function"==typeof e?e.apply(this,arguments):e)},n,i)},m.scaleTo=function(t,e,n,i){m.transform(t,function(){var t=s.apply(this,arguments),i=this.__zoom,a=null==n?b(t):"function"==typeof n?n.apply(this,arguments):n,r=i.invert(a),l="function"==typeof e?e.apply(this,arguments):e;return o(x(y(i,l),a,r),t,c)},n,i)},m.translateBy=function(t,e,n,i){m.transform(t,function(){return o(this.__zoom.translate("function"==typeof e?e.apply(this,arguments):e,"function"==typeof n?n.apply(this,arguments):n),s.apply(this,arguments),c)},null,i)},m.translateTo=function(t,e,n,i,a){m.transform(t,function(){var t=s.apply(this,arguments),a=this.__zoom,r=null==i?b(t):"function"==typeof i?i.apply(this,arguments):i;return o(On.translate(r[0],r[1]).scale(a.k).translate("function"==typeof e?-e.apply(this,arguments):-e,"function"==typeof n?-n.apply(this,arguments):-n),t,c)},i,a)},_.prototype={event:function(t){return t&&(this.sourceEvent=t),this},start:function(){return 1===++this.active&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(t,e){return this.mouse&&"mouse"!==t&&(this.mouse[1]=e.invert(this.mouse[0])),this.touch0&&"touch"!==t&&(this.touch0[1]=e.invert(this.touch0[0])),this.touch1&&"touch"!==t&&(this.touch1[1]=e.invert(this.touch1[0])),this.that.__zoom=e,this.emit("zoom"),this},end:function(){return 0===--this.active&&(delete this.that.__zooming,this.emit("end")),this},emit:function(t){var e=xt(this.that).datum();p.call(t,this.that,new Dn(t,{sourceEvent:this.sourceEvent,target:m,transform:this.that.__zoom,dispatch:p}),e)}},m.wheelDelta=function(t){return arguments.length?(r="function"==typeof t?t:Vn(+t),m):r},m.filter=function(t){return arguments.length?(a="function"==typeof t?t:Vn(!!t),m):a},m.touchable=function(t){return arguments.length?(l="function"==typeof t?t:Vn(!!t),m):l},m.extent=function(t){return arguments.length?(s="function"==typeof t?t:Vn([[+t[0][0],+t[0][1]],[+t[1][0],+t[1][1]]]),m):s},m.scaleExtent=function(t){return arguments.length?(h[0]=+t[0],h[1]=+t[1],m):[h[0],h[1]]},m.translateExtent=function(t){return arguments.length?(c[0][0]=+t[0][0],c[1][0]=+t[1][0],c[0][1]=+t[0][1],c[1][1]=+t[1][1],m):[[c[0][0],c[0][1]],[c[1][0],c[1][1]]]},m.constrain=function(t){return arguments.length?(o=t,m):o},m.duration=function(t){return arguments.length?(u=+t,m):u},m.interpolate=function(t){return arguments.length?(d=t,m):d},m.on=function(){var t=p.on.apply(p,arguments);return t===p?m:t},m.clickDistance=function(t){return arguments.length?(f=(t=+t)*t,m):Math.sqrt(f)},m.tapDistance=function(t){return arguments.length?(g=+t,m):g},m}Yn.prototype;function Jn(t){const e=Math.floor(Math.log10(t)),n=t/Math.pow(10,e);let i;return i=n<=1?1:n<=2?2:n<=5?5:10,i*Math.pow(10,e)}function ti(t,e,n){const i=2*n-1,a=t-(n-1)*e;let s=0;for(let l=1;l<=n;l++)s+=l;const o=a/s,r=[];for(let l=0;l<i;l++)l%2==0?r.push(o*(n-l/2)):r.push(e);return r.join(",")}function ei(t,e={}){const{capitalizeFirstOnly:n=!0,preserveAcronyms:i=!0}=e;let a=t;return a=a.replace(/[_]/g," "),a=i?a.replace(/([a-z])([A-Z])/g,"$1 $2"):a.replace(/([A-Z])/g," $1"),a=n?a.charAt(0).toUpperCase()+a.slice(1).toLowerCase():a.replace(/\b\w/g,t=>t.toUpperCase()),a.trim().replace(/\s+/g," ")}function ni(t,e,n=5){const i=e-t;if(0===i)return[t];const a=i/(n-1),s=Math.pow(10,Math.floor(Math.log10(a))),o=a/s;let r;r=o<=1?1:o<=2?2:o<=5?5:10;const l=r*s,h=[];let c=Math.floor(t/l)*l;for(;c<=e+.001*l;)c>=t-.001*l&&h.push(c),c+=l;return(0===h.length||h[0]>t)&&h.unshift(t),h[h.length-1]<e&&h.push(e),h}function ii(t,e){const n=Math.max(...e)-Math.min(...e),i=e.length>1?Math.abs(e[1]-e[0]):n;if(0===n)return t.toPrecision(3);const a=Math.floor(Math.log10(Math.abs(i)));if(a>=0)return Math.round(t).toString();{const e=Math.min(3,-a);return t.toFixed(e)}}class ai{constructor(){this.subscribers=new Map}subscribe(t,e){return this.subscribers.has(t)||this.subscribers.set(t,new Set),this.subscribers.get(t).add(e),()=>this.unsubscribe(t,e)}unsubscribe(t,e){this.subscribers.has(t)&&this.subscribers.get(t).delete(e)}notify(t,e){this.subscribers.has(t)&&this.subscribers.get(t).forEach(t=>{t(e)})}}class si{constructor(t,e,n={}){this.container=t,this.callback=e,this.options={debounce:250,immediate:!1,...n},this.lastWidth=0,this.lastHeight=0,this.timeoutId=null,this.init()}init(){this.observer=new ResizeObserver(t=>{for(const e of t)this.handleResize(e)}),this.observer.observe(this.container);const t=this.container.getBoundingClientRect();this.lastWidth=t.width,this.lastHeight=t.height,this.options.immediate&&this.callback({width:this.lastWidth,height:this.lastHeight,target:this.container,contentRect:t})}handleResize(t){const{width:e,height:n}=t.contentRect;e===this.lastWidth&&n===this.lastHeight||(this.lastWidth=e,this.lastHeight=n,this.options.debounce>0?this.debouncedCallback(t):this.executeCallback(t))}debouncedCallback(t){clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.executeCallback(t)},this.options.debounce)}executeCallback(t){this.callback({width:t.contentRect.width,height:t.contentRect.height,target:t.target,contentRect:t.contentRect,borderBoxSize:t.borderBoxSize?.[0],contentBoxSize:t.contentBoxSize?.[0],devicePixelContentBoxSize:t.devicePixelContentBoxSize?.[0]})}destroy(){this.observer&&this.observer.disconnect(),clearTimeout(this.timeoutId)}}class oi{defaultValue;constructor(t){void 0===t?console.error("A defualt value for a NullScale is needed."):this.defaultValue=t}getValue(){return this.defaultValue}}class ri{constructor(t=null,e=null,n=null){this.validValues=e?new Set(e):null,this.transformFn=n,this.defaultValue=t}getValue(t){let e=this.transformFn?this.transformFn(t):t;return null===this.validValues||this.validValues.has(e)||(e=null),null!=e&&""!==e||(e=this.defaultValue),e}}class li{constructor(t,e,n){if(!Array.isArray(t)||0===t.length)throw new Error("values must be a non-empty array");this.outputCategories=e,this.defaultValue=n;const i=new Map;for(const o of t)null!=o&&""!==o&&(i.has(o)?i.set(o,i.get(o)+1):i.set(o,1));const a=new Map([...i.entries()].sort((t,e)=>t[0]-e[0]));a.length>e.length?this.otheredCategories=a.keys().slice(e.length-2,a.length):this.otheredCategories=[],this.categoryMap=new Map;const s=[...a.keys()];for(let o=0;o<s.length;o++)o<e.length?this.categoryMap.set(s[o],e[o]):this.categoryMap.set(s[o],e[e.length-1])}getValue(t){return null==t||""===t?this.defaultValue:this.categoryMap.get(t)}}class hi{constructor(t,e,n,i){this.dataMin=t,this.dataMax=e,this.sizeMin=n,this.sizeMax=i}getValue(t){const e=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 n=(e-this.dataMin)/(this.dataMax-this.dataMin);return this.sizeMin+n*(this.sizeMax-this.sizeMin)}}class ci{constructor(t,e,n=0,i=1,a=null,s=null){if(this.dataMin=t,this.dataMax=e,this.transformMin=n,this.transformMax=i,this.nullColor="#808080",null===a)this.colors=["#440154","#31688e","#35b779","#fde724"].map(t=>this._hexToRgb(t));else{if(a.length<1)throw new Error("At least 1 color is required");this.colors=a.map(t=>this._hexToRgb(t))}if(1!==this.colors.length)if(null===s)this.colorPositions=this.colors.map((t,e)=>e/(this.colors.length-1));else{if(s.length!==this.colors.length)throw new Error("colorPositions must have the same length as colors");const t=s.map((t,e)=>({pos:t,color:this.colors[e]}));t.sort((t,e)=>t.pos-e.pos),this.colorPositions=t.map(t=>t.pos),this.colors=t.map(t=>t.color);const e=this.colorPositions[0],n=this.colorPositions[this.colorPositions.length-1];this.colorPositions=e===n?this.colorPositions.map(()=>0):this.colorPositions.map(t=>(t-e)/(n-e))}else this.colorPositions=[0]}getValue(t){if(null==t||""===t)return this.nullColor;if(1===this.colors.length)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 t=this.colors[this.colors.length-1];return this._rgbToHex(t.r,t.g,t.b)}{const t=Math.floor(this.colors.length/2),e=this.colors[t];return this._rgbToHex(e.r,e.g,e.b)}}const e=(Math.max(this.dataMin,Math.min(this.dataMax,t))-this.dataMin)/(this.dataMax-this.dataMin),n=this.transformMin+e*(this.transformMax-this.transformMin),i=Math.max(0,Math.min(1,n));if(i<=this.colorPositions[0])return this._rgbToHex(this.colors[0].r,this.colors[0].g,this.colors[0].b);if(i>=this.colorPositions[this.colorPositions.length-1]){const t=this.colors[this.colors.length-1];return this._rgbToHex(t.r,t.g,t.b)}let a=0;for(let r=0;r<this.colorPositions.length-1;r++)i>=this.colorPositions[r]&&(a=r);const s=Math.min(a+1,this.colors.length-1);if(i===this.colorPositions[a]){const t=this.colors[a];return this._rgbToHex(t.r,t.g,t.b)}if(i===this.colorPositions[s]){const t=this.colors[s];return this._rgbToHex(t.r,t.g,t.b)}const o=(i-this.colorPositions[a])/(this.colorPositions[s]-this.colorPositions[a]);return this._interpolateColor(this.colors[a],this.colors[s],o)}_interpolateColor(t,e,n){const i=Math.round(t.r+(e.r-t.r)*n),a=Math.round(t.g+(e.g-t.g)*n),s=Math.round(t.b+(e.b-t.b)*n);return this._rgbToHex(i,a,s)}_hexToRgb(t){const e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null}_rgbToHex(t,e,n){return"#"+[t,e,n].map(t=>{const e=t.toString(16);return 1===e.length?"0"+e:e}).join("")}}class ui{defaultPalette=["#440154","#31688e","#35b779","#fde724"];constructor(t,e=0,n=1,i=null,a=null,s=10){if(!Array.isArray(t)||0===t.length)throw new Error("categoryData must be a non-empty array");this.transformMin=e,this.transformMax=n,this.nullColor="#808080",this.maxColors=s,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((t,e)=>e[1]-t[1]).map(t=>t[0]),null===i)this.colors=this.defaultPalette.map(t=>this._hexToRgb(t));else{if(i.length<1)throw new Error("At least 1 color is required");this.colors=i.map(t=>this._hexToRgb(t))}if(1===this.colors.length)return this.colorPositions=[0],void this._assignColors();if(null===a)this.colorPositions=this.colors.map((t,e)=>e/(this.colors.length-1));else{if(a.length!==this.colors.length)throw new Error("colorPositions must have the same length as colors");const t=a.map((t,e)=>({pos:t,color:this.colors[e]}));t.sort((t,e)=>t.pos-e.pos),this.colorPositions=t.map(t=>t.pos),this.colors=t.map(t=>t.color);const e=this.colorPositions[0],n=this.colorPositions[this.colorPositions.length-1];this.colorPositions=e===n?this.colorPositions.map(()=>0):this.colorPositions.map(t=>(t-e)/(n-e))}this._assignColors()}_assignColors(){if(this.categoryColorMap=new Map,1===this.colors.length){const t=this._rgbToHex(this.colors[0].r,this.colors[0].g,this.colors[0].b);for(const e of this.categories)this.categoryColorMap.set(e,t);return}if(1===this.categories.length){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 e=0;e<this.categories.length;e++){const n=e>=t?1:e/(t-1),i=this.transformMin+n*(this.transformMax-this.transformMin),a=this._getColorAtPosition(i);this.categoryColorMap.set(this.categories[e],a)}}}_getColorAtPosition(t){if(t=Math.max(0,Math.min(1,t)),1===this.colors.length)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 t=this.colors[this.colors.length-1];return this._rgbToHex(t.r,t.g,t.b)}let e=0;for(let a=0;a<this.colorPositions.length-1;a++)t>=this.colorPositions[a]&&(e=a);const n=Math.min(e+1,this.colors.length-1);if(t===this.colorPositions[e]){const t=this.colors[e];return this._rgbToHex(t.r,t.g,t.b)}if(t===this.colorPositions[n]){const t=this.colors[n];return this._rgbToHex(t.r,t.g,t.b)}const i=(t-this.colorPositions[e])/(this.colorPositions[n]-this.colorPositions[e]);return this._interpolateColor(this.colors[e],this.colors[n],i)}getValue(t){if(null==t||""===t)return this.nullColor;if(this.categoryColorMap.has(t))return this.categoryColorMap.get(t);throw new Error(`Unknown category: ${t}`)}_interpolateColor(t,e,n){const i=Math.round(t.r+(e.r-t.r)*n),a=Math.round(t.g+(e.g-t.g)*n),s=Math.round(t.b+(e.b-t.b)*n);return this._rgbToHex(i,a,s)}_hexToRgb(t){const e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null}_rgbToHex(t,e,n){return"#"+[t,e,n].map(t=>{const e=t.toString(16);return 1===e.length?"0"+e:e}).join("")}}class di{state;scale;constructor(t,e={}){if(!e.scaleType)throw new Error("scaleType is required");if(void 0===e.default)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,...e},this.updateScale(t)}setScale(t){this.scale=t}getValue(t){return this.scale.getValue(t)}updateScale(t){const{scaleType:e,isCategorical:n}=this.state;let i;if("null"===e)return i=new oi(this.state.default),void this.setScale(i);let a=!0;if(n&&(this.state.outputValues||this.state.outputRegex)){if(this.state.outputValues)for(let e=0;e<t.length;e++)if(t[e]&&!this.state.outputValues.includes(t[e])){a=!1;break}if(this.state.outputRegex)for(let e=0;e<t.length;e++)if(t[e]&&!this.state.outputRegex.test(t[e])){a=!1;break}}else a=!1;if("identity"===e||a)return i=new ri(this.state.default,this.state.outputValues,this.state.transformFn),void this.setScale(i);if("text"===e){if(!n)throw new Error("Text scales can only be used with categorical data");return i=new li(t,this.state.outputValues,this.state.default),void this.setScale(i)}if("size"===e){if(n)throw new Error("Size scales can only be used with continuous data");const e=t.map(t=>Number(t)).filter(t=>!isNaN(t));if(0===e.length)console.warn("No numeric values found for size scale, using NullScale"),i=new oi(this.state.default);else{const t=Math.min(...e),n=Math.max(...e),a=this.state.outputRange||[.5,2];i=new hi(t,n,a[0],a[1])}return void this.setScale(i)}if("color"!==e)throw new Error(`Unknown scale type: ${e}`);if(n)i=new ui(t,this.state.transformMin,this.state.transformMax,this.state.colorPalette,this.state.colorPositions,this.state.maxCategories);else{const e=t.map(t=>Number(t)).filter(t=>!isNaN(t));if(0===e.length)console.warn("No numeric values found for color scale, using NullScale"),i=new oi(this.state.default);else{const t=Math.min(...e),n=Math.max(...e);i=new ci(t,n,this.state.transformMin,this.state.transformMax,this.state.colorPalette,this.state.colorPositions)}}this.setScale(i)}}class pi extends ai{tree;metadata=new Map;metadataTableNames=new Map;columnType=new Map;columnName=new Map;columnDisplayName=new Map;columnAesthetic=new Map;#t=0;constructor(t,e=[],n=[]){super(),this.tree=this.parseTree(t),Array.isArray(e)&&e.forEach((t,e)=>{const i=n[e]||`Metadata ${e+1}`;this.addTable(t,i)})}parseTree(t){const e=function(t){";"===(t=t.trim())[t.length-1]&&(t=t.slice(0,-1));let e=0;const n=function n(){let i={};if("("===t[e])for(e++,i.children=[];;){let a=n();if(i.children.push(a),","!==t[e]){if(")"===t[e]){e++;break}break}e++}let a="";for(;e<t.length&&","!==t[e]&&")"!==t[e];)a+=t[e++];if(a=a.trim(),a){let t=a.split(":");i.name=t[0]||"",t.length>1&&(i.length=parseFloat(t[1]))}return i}();if(e!==t.length)throw new Error(`Unexpected character at position ${e}: '${t[e]}'`);return n}(t),n=Tn(e,t=>t.children).sum(t=>t.children?0:1).each(function(t){t.leafCount=t.value,delete t.value,delete t.data.children}).sort((t,e)=>t.leafCount-e.leafCount||function(t,e){return null==t||null==e?NaN:t<e?-1:t>e?1:t>=e?0:NaN}(t.data.length,e.data.length));let i=0;return n.each(t=>{t.id=++i}),n}setTree(t){this.tree=this.parseTree(t),this.metadata.keys().forEach(this.#e),this.notify("treeUpdated",this)}getMetadataTableNames(){return Array.from(this.metadataTableNames.values())}addTable(t,e=null,n="\t"){const{metadataMap:i,columnTypes:a}=function(t,e="\t"){let n=new Map,i=[],a=new Map;const s=t.trim().split("\n");if(0==s.length)console.error("Empty metatdata table");else{const t=s[0].split(e),o=t.indexOf("node_id");if(-1===o)console.warn('Metadata table must contain a "node_id" column');else{i=t.filter((t,e)=>e!==o);const r=new Map;i.forEach(t=>r.set(t,[]));for(let i=1;i<s.length;i++){const a=s[i].split(e),l=a[o],h={};for(let e=0;e<t.length;e++)if(e!==o){const n=t[e],i=a[e];h[n]=i,r.get(n).push(i)}n.set(l,h)}i.forEach(t=>{const e=r.get(t),n=e.map(t=>parseFloat(t)).filter(t=>!isNaN(t)),i=n.length>0&&n.length===e.filter(t=>""!==t).length;a.set(t,i?"continuous":"categorical")})}}return{metadataMap:n,columnTypes:a}}(t,n),s="table_"+this.#t++;e||(e=`Metadata ${this.#t}`),this.metadataTableNames.set(s,e);const o=new Map;for(const[l,h]of a){const t=`${s}_${l}`;o.set(l,t),this.columnType.set(t,h),this.columnName.set(t,l),this.columnDisplayName.set(t,ei(l))}const r=new Map;for(const[l,h]of i){const t={};for(const[e,n]of Object.entries(h)){const i=o.get(e);i&&(t[i]=n)}r.set(l,t)}return this.metadata.set(s,r),this.#e(s),this.notify("metadataAdded",{tableId:s,columnIds:o.values()}),s}deleteTable(t){const e=this.metadata.get(t);if(!e)return void console.warn(`Table ${t} does not exist`);const n=Object.keys(e.values().next().value);for(const i of n)this.columnType.delete(i),this.columnName.delete(i),this.columnDisplayName.delete(i),this.columnAesthetic.delete(i);this.#n(t),this.metadata.delete(t),this.metadataTableNames.delete(t),this.notify("metadataRemoved",{tableId:t,columnIds:n})}getAesthetic(t,e,n={}){this.columnAesthetic.has(t)||this.columnAesthetic.set(t,new Map);const i=this.columnAesthetic.get(t);if(i.has(e))return i.get(e);const a=this.#i(t,n);return i.set(e,a),a}setAesthetic(t,e,n){this.columnAesthetic.has(t)||this.columnAesthetic.set(t,new Map),this.columnAesthetic.get(t).set(e,n)}#i(t,e={}){const n=this.columnType.get(t),i="categorical"===n;n||console.error(`Column ${t} not found`);let a=[];this.tree.each(e=>{e.metadata&&void 0!==e.metadata[t]&&a.push(e.metadata[t])}),0===a.length&&console.error(`No values found for column ${t}`);const s=this.columnDisplayName.get(t)||t;return new di(a,{isCategorical:i,inputUnits:s,...e})}#e(t){const e=this.metadata.get(t);this.tree.each(t=>{const n=t.data.name;if(n&&e.has(n)){const i=e.get(n);t.metadata={...t.metadata,...i}}})}#n(t){const e=this.metadata.get(t),n=Object.keys(e.values().next().value);this.tree.each(t=>{n.forEach(e=>{delete t[e]})})}}function fi(t,e){const n=t.leaves().map((t,n)=>({radius:t.radius,angle:t.angle,cos:t.cos,sin:t.sin,width:(t.tipLabelBounds.width+e.nodeLabelOffset)*t.tipLabelSize,height:t.tipLabelBounds.height*t.tipLabelSize,labelScale:t.tipLabelSize}));let i=0,a=1/0,s=0,o=1/0;function r(t){t>i&&(i=t>a?a:t)}function l(t){t<o&&(o=t<s?s:t)}function h(t){t>s&&(s=t>o?o:t)}const c=Math.min(...n.map(t=>t.labelScale)),u=Math.max(...n.map(t=>t.radius)),d=Math.min(...n.map(t=>t.radius)),p=t.descendants().filter(t=>t.data.length>0&&t.children),f=p.length>0?Math.min(...p.map(t=>t.data.length)):1/0;function g(){const t=Math.min(...n.filter(t=>t.cos>0).map(t=>(e.viewWidth/2-t.width*t.cos*s)/(t.radius*t.cos))),o=Math.min(...n.filter(t=>t.cos<0).map(t=>(e.viewWidth/2-t.width*-t.cos*s)/(t.radius*-t.cos))),r=Math.min(...n.filter(t=>t.sin>0).map(t=>(e.viewHeight/2-t.width*t.sin*s)/(t.radius*t.sin))),l=Math.min(...n.filter(t=>t.sin<0).map(t=>(e.viewHeight/2-t.width*-t.sin*s)/(t.radius*-t.sin)));var h;(h=Math.min((t+o)/2,(l+r)/2))<a&&(a=h<i?i:h)}function m(){const t=Math.min(...n.filter(t=>t.cos>0).map(t=>(e.viewWidth/2-t.radius*t.cos*i)/(t.width*t.cos))),a=Math.min(...n.filter(t=>t.cos<0).map(t=>(e.viewWidth/2-t.radius*-t.cos*i)/(t.width*-t.cos))),s=Math.min(...n.filter(t=>t.sin>0).map(t=>(e.viewHeight/2-t.radius*t.sin*i)/(t.width*t.sin))),o=Math.min(...n.filter(t=>t.sin<0).map(t=>(e.viewHeight/2-t.radius*-t.sin*i)/(t.width*-t.sin)));l(Math.min((t+a)/2,(o+s)/2))}h(e.minFontPx/c),i!==a&&r(Math.max(...n.map(t=>t.width*s/(u/e.minBranchLenProp-t.radius)))),g(),m();const y=n.reduce((t,e)=>t+e.height,0);return y>0&&d>0&&(i!==a&&r(y*s/(2*d*Math.PI)),s!==o&&l(u*a*2*Math.PI/y)),s!==o&&m(),s!==o&&h(e.idealFontPx/c),i!==a&&g(),isFinite(f)&&f>0&&i!==a&&r(e.minBranchThicknessPx/f),s!==o&&m(),s!==o&&l(e.maxFontPx/c),{branchLenToPxFactor_min:i,branchLenToPxFactor_max:a,labelSizeToPxFactor_min:s,labelSizeToPxFactor_max:o}}class gi{constructor(){this.metricsCache=new Map,this.setupHiddenEnvironment()}setupHiddenEnvironment(){this.hiddenContainer=document.createElement("div"),this.hiddenContainer.style.cssText="\n position: absolute;\n top: -9999px;\n left: -9999px;\n visibility: hidden;\n width: 5000px;\n height: 5000px;\n overflow: hidden;\n ",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=xt(this.hiddenSVG),this.textGroup=this.hiddenD3SVG.append("g").attr("id","text-measurement-group")}getRelativeTextSize(t,e={}){const n=`${t}-${JSON.stringify(e)}`;if(this.metricsCache.has(n))return this.metricsCache.get(n);const i=this.textGroup.append("text").attr("x",1e3).attr("y",2500).text(t);Object.keys(e).forEach(t=>{i.style(t,e[t])}),this.hiddenSVG.getBoundingClientRect();const a=i.node().getBBox(),s=window.getComputedStyle(i.node()),o=parseFloat(s.fontSize);i.remove();const r={width:a.width/o,height:a.height/o};return this.metricsCache.set(n,r),r}getTextSize(t,e,n={}){const i=this.getRelativeTextSize(t,n);return{width:i.width,height:i.height,widthPx:i.width*e,heightPx:i.height*e}}clearCache(){this.metricsCache.clear()}destroy(){this.hiddenContainer&&this.hiddenContainer.parentNode&&this.hiddenContainer.parentNode.removeChild(this.hiddenContainer),this.metricsCache.clear()}}class mi extends ai{#a={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.#a).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={},e=new gi){super(),t.treeData&&t.treeData.tree?e?(t.aesthetics={...this.state.aesthetics,...t.aesthetics},this.state={...this.state,...t},this.textSizeEstimator=e,this.#s(),this.state.treeData.subscribe("treeUpdate",()=>{this.#s()}),this.state.treeData.subscribe("metadataRemoved",t=>{this.setAesthetics(Object.fromEntries(t.columnIds.map(t=>[t,void 0])))})):console.error("TreeState initialized without textSizeEstimator"):console.error("TreeState initialized without valid tree data")}#s(){this.displayedRoot=this.state.treeData.tree,this.updateLayout(),this.setAesthetics(this.state.aesthetics,!0)}setLayout(t,e=!1){["circular","rectangular"].includes(t)?(e||this.state.layout!==t)&&(this.state.layout=t,this.update(),this.notify("layoutChange",{layout:t})):console.warn(`Invalid layout type: ${t}`)}setBranchLengthScale(t){t<.01||t>100?console.warn(`Branch length scale out of range: ${t}`):(this.state.branchLengthScale=t,this.updateCoordinates(),this.notify("branchLengthScaleChange",{scale:t}))}setTreeHeightScale(t){t<.1||t>10?console.warn(`Tree height scale out of range: ${t}`):(this.state.treeHeightScale=t,this.updateCoordinates(),this.notify("treeHeightScaleChange",{scale:t}))}setAesthetics(t,e=!1){const n=new Set;let i=!1;for(const[a,s]of Object.entries(t)){const t=this.#a[a];if(t){if(e||s!==this.state.aesthetics[a]){this.state.aesthetics[a]=s,this.aestheticsScales[a]=s?this.state.treeData.getAesthetic(s,a,t):new oi(t.default),this.state.treeData.tree.each(e=>{s&&null!=s?e.metadata&&void 0!==e.metadata[s]?e[a]=this.aestheticsScales[a].getValue(e.metadata[s]):e[a]=t.default:e[a]=this.aestheticsScales[a].getValue()});for(const e of t.downstream)n.add(e);t.hasLegend&&(i=!0)}this.notify(`${a}Change`)}else console.warn(`Unknown aesthetic: ${a}`)}i&&this.#o();for(const a of n)this[a]()}#o(){this.legends=[];for(const[t,e]of Object.entries(this.state.aesthetics)){const n=this.#a[t];if(!n.hasLegend||!e)continue;const i=this.aestheticsScales[t];i&&this.legends.push({aestheticId:t,aesthetic:i,type:n.scaleType})}this.notify("legendsChange")}setTargetTreeDimensions(t,e){this.state.viewWidth=t,this.state.viewHeight=e,this.updateCoordinates()}collapseSubtree(t){t?t.children?(t.collapsedChildren=t.children,delete t.children,this.update()):console.warn("Tried to collapse node with no children"):console.warn("Tried to collapse non-existant node")}expandSubtree(t){t&&t.collapsedChildren&&(t.children=t.collapsedChildren,delete t.collapsedChildren,this.update())}rotateSubtree(t){if(!t)return void console.warn("Tried to rotate non-existent node");if(!t.children||t.children.length<2)return void console.warn("Tried to rotate node with fewer than 2 children");const e=t.children.shift();t.children.push(e),this.update()}hideSubtree(t){if(!t)return void console.warn("Tried to hide non-existent node");if(!t.parent)return void console.warn("Cannot hide the root node");t.hidden=!0;const e=t.parent;e.children&&(e.hiddenChildren=e.hiddenChildren||[],e.hiddenChildren.push(t),e.children=e.children.filter(e=>e!==t),0===e.children.length&&(delete e.children,this.hideSubtree(e))),this.update()}showSubtree(t){if(!t||!t.hidden)return;const e=t.parent;e&&e.hiddenChildren&&(e.hiddenChildren=e.hiddenChildren.filter(e=>e!==t),0===e.hiddenChildren.length&&delete e.hiddenChildren,e.children||(e.children=[]),e.children.push(t),e.children.sort((t,n)=>(e.data.children?e.data.children.indexOf(t.data):0)-(e.data.children?e.data.children.indexOf(n.data):0)),delete t.hidden,this.update())}showAllHidden(){const t=[];this.state.treeData.tree.each(e=>{e.hiddenChildren&&t.push(...e.hiddenChildren)});for(const e of t)this.showSubtree(e)}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=>{null===this.state.aesthetics.tipLabelText?t.tipLabelText="":!t.children&&!t.collapsedChildren||void 0!==this.state.aesthetics.tipLabelText&&t.tipLabelText?t.tipLabelText||(t.tipLabelText=t.data.name||""):t.tipLabelText=`Clade with ${t.leafCount} tips`})}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(){Cn().separation((t,e)=>1)(this.displayedRoot),this.displayedRoot.each(t=>{t.parent?(t.branchLen=t.data.length?t.data.length:0,t.y=t.parent.y+t.branchLen):t.y=0}),this.displayedRoot.each(t=>{const e=t.x,n=t.y;t.x=n,t.y=e,t.angle=t.y*Math.PI*2+Math.PI,t.cos=Math.cos(t.angle),t.sin=Math.sin(t.angle),t.radius=t.x}),this.displayedRoot.eachAfter(t=>{t.x=t.x-this.displayedRoot.x,t.y=t.y-this.displayedRoot.y})}getCollapsedTriangleHeight(t){return t.tipLabelSizePx+1.1}getCollapsedTriangleOffset(t){return.52*this.getCollapsedTriangleHeight(t)}updateCoordinates(){let t;this.displayedRoot.each(t=>{t.tipLabelBounds=this.textSizeEstimator.getRelativeTextSize(t.tipLabelText,{"font-family":t.tipLabelFont,"font-style":t.tipLabelStyle}),t.nodeLabelBounds=this.textSizeEstimator.getRelativeTextSize(t.nodeLabelText,{"font-family":t.nodeLabelFont,"font-style":t.nodeLabelStyle})}),t="circular"===this.state.layout?fi(this.displayedRoot,this.state):function(t,e){const n=t.leaves().map(t=>({x:t.x,width:(t.tipLabelBounds.width+e.nodeLabelOffset)*t.tipLabelSize,height:t.tipLabelBounds.height*t.tipLabelSize,labelScale:t.tipLabelSize}));let i=0,a=1/0,s=0,o=1/0;function r(t){t<a&&(a=t<i?i:t)}function l(t){t>i&&(i=t>a?a:t)}function h(t){t<o&&(o=t<s?s:t)}function c(t){t>s&&(s=t>o?o:t)}const u=Math.min(...n.map(t=>t.labelScale)),d=Math.max(...n.map(t=>t.x)),p=t.descendants().filter(t=>t.data.length>0&&t.children),f=p.length>0?Math.min(...p.map(t=>t.data.length)):1/0;return c(e.minFontPx/u),l(Math.max(...n.map(t=>t.width*s/(d/e.minBranchLenProp-t.x)))),r(Math.min(...n.map(t=>(e.viewWidth-t.width*s)/t.x))),h(Math.min(...n.map(t=>(e.viewWidth-t.x*i)/t.width))),s!=o&&h(e.viewHeight/n.reduce((t,e)=>t+e.height,0)),s!=o&&c(e.idealFontPx/u),i!=a&&r(Math.min(...n.map(t=>(e.viewWidth-t.width*s)/t.x))),isFinite(f)&&(i!=a&&l(e.minBranchThicknessPx/f),s!=o&&h(Math.min(...n.map(t=>(e.viewWidth-t.x*i)/t.width)))),s!=o&&h(e.maxFontPx/u),{branchLenToPxFactor_min:i,branchLenToPxFactor_max:a,labelSizeToPxFactor_min:s,labelSizeToPxFactor_max:o}}(this.displayedRoot,this.state),this.branchLenToPxFactor=t.branchLenToPxFactor_max*this.state.branchLengthScale,this.labelSizeToPxFactor=t.labelSizeToPxFactor_min,this.displayedRoot.each(t=>{t.branchLenPx=t.branchLen*this.branchLenToPxFactor,t.tipLabelSizePx=t.tipLabelSize*this.labelSizeToPxFactor,t.nodeLabelSizePx=t.nodeLabelSize*this.labelSizeToPxFactor*this.state.nodeLabelSizeScale;let e=t.tipLabelSizePx*this.state.nodeLabelOffset;t.collapsedChildren&&(e+=1.3*this.getCollapsedTriangleOffset(t)),t.tipLabelXOffsetPx=e,t.nodeLabelXOffsetPx=t.nodeLabelSizePx*this.state.nodeLabelOffset,t.tipLabelYOffsetPx=t.tipLabelSizePx*t.tipLabelBounds.height/2,t.nodeLabelYOffsetPx=t.nodeLabelSizePx*t.nodeLabelBounds.height/2,t.tipLabelBounds.widthPx=t.tipLabelBounds.width*t.tipLabelSizePx,t.tipLabelBounds.heightPx=t.tipLabelBounds.height*t.tipLabelSizePx}),"circular"===this.state.layout?this.displayedRoot.each(t=>{t.radiusPx=t.radius*this.branchLenToPxFactor,t.xPx=t.radiusPx*t.cos,t.yPx=t.radiusPx*t.sin}):this.displayedRoot.each(t=>{t.xPx=t.x*this.branchLenToPxFactor,t.yPx=t.y*this.displayedRoot.leaves().length*this.labelSizeToPxFactor*(1+this.state.labelSpacing)*this.state.treeHeightScale}),"circular"===this.state.layout?this.state.treeData.tree.eachAfter(t=>{if(t.children)t.bounds={minRadius:t.radiusPx,maxRadius:Math.max(...t.children.map(t=>t.bounds.maxRadius)),minAngle:Math.min(...t.children.map(t=>t.bounds.minAngle)),maxAngle:Math.max(...t.children.map(t=>t.bounds.maxAngle)),minX:Math.min(...t.children.map(t=>t.bounds.minX)),maxX:Math.max(...t.children.map(t=>t.bounds.maxX)),minY:Math.min(...t.children.map(t=>t.bounds.minY)),maxY:Math.max(...t.children.map(t=>t.bounds.maxY))};else{const e=t.radiusPx,n=e+t.tipLabelXOffsetPx+t.tipLabelBounds.widthPx,i=Math.atan(t.tipLabelYOffsetPx/t.radiusPx),a=t.angle-i,s=t.angle+i,o=[e*Math.cos(a),e*Math.cos(s),n*Math.cos(s),n*Math.cos(a)],r=[e*Math.sin(a),e*Math.sin(s),n*Math.sin(s),n*Math.sin(a)];t.bounds={minRadius:e,maxRadius:n,minAngle:a,maxAngle:s,minX:Math.min(...o),maxX:Math.max(...o),minY:Math.min(...r),maxY:Math.max(...r)}}}):this.state.treeData.tree.eachAfter(t=>{t.children?t.bounds={minX:t.xPx,maxX:Math.max(...t.children.map(t=>t.bounds.maxX)),minY:Math.min(...t.children.map(t=>t.bounds.minY)),maxY:Math.max(...t.children.map(t=>t.bounds.maxY))}:t.bounds={minX:t.xPx,maxX:t.xPx+t.tipLabelXOffsetPx+t.tipLabelBounds.widthPx,minY:t.yPx-t.tipLabelYOffsetPx,maxY:t.yPx+t.tipLabelYOffsetPx}}),this.notify("coordinateChange")}}const yi={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"],rotate:["M 3,12 H 8","M 13,6 H 8 v 12 h 5","m 17,4 c 0,0 9,8 0,16","M 17,8 V 4 h 4","M 21,20 H 17 V 16"]};class xi{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,e=this.state.y;const{width:n,height:i}=this.coordinates;this.state.origin.includes("right")&&(t-=n),this.state.origin.includes("bottom")&&(e-=i),this.group.attr("transform",`translate(${t}, ${e})`)}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 bi extends xi{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=Jn(1),e=t*this.state.treeState.branchLenToPxFactor;for((e<this.minBarLength||e>this.maxBarLength)&&(t=Jn(this.minBarLength/this.state.treeState.branchLenToPxFactor),e=t*this.state.treeState.branchLenToPxFactor);e<this.minBarLength;)t*=2,e=t*this.state.treeState.branchLenToPxFactor;for(;e>this.maxBarLength;)t/=2,e=t*this.state.treeState.branchLenToPxFactor;t=t.toPrecision(3);const n=this.textSizeEstimator.getTextSize(t,this.state.labelFontSize);this.textSizeEstimator.getTextSize(this.title,this.state.titleFontSize);let i=0;this.showTitle&&(i=this.state.titleFontSize+this.titleSpacing);const a=i+this.unitLabelSpacing+n.heightPx+10;this.coordinates={width:e+this.lineThickness,height:a+this.scaleBarEdgeHeight,title:{x:0,y:this.state.titleFontSize,text:"Branch Length"},bar:{x1:0,y1:a,x2:e,y2:a},leftTick:{x1:0,y1:a-this.scaleBarEdgeHeight,x2:0,y2:a+this.scaleBarEdgeHeight},rightTick:{x1:e,y1:a-this.scaleBarEdgeHeight,x2:e,y2:a+this.scaleBarEdgeHeight},label:{x:e/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 vi extends xi{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,e=this.state.aesthetic.scale.dataMax,n=this.state.aesthetic.scale.sizeMin,i=this.state.aesthetic.scale.sizeMax,a=ni(t,e,5),s=i*this.state.treeState.labelSizeToPxFactor*.7,o=n*this.state.treeState.labelSizeToPxFactor*.7;this.textSizeEstimator.getTextSize(this.state.aesthetic.state.title,this.state.titleFontSize);const r=Math.max(30*a.length,100),l=a.map(t=>{const e=ii(t,a);return this.textSizeEstimator.getTextSize(e,this.state.labelFontSize)}),h=l[0].widthPx/2,c=l[l.length-1].widthPx/2,u=r+h+c;let d=0;this.showTitle&&(d=this.state.titleFontSize+this.verticalSpacing);const p=d+s,f=this.textSizeEstimator.getTextSize(this.state.aesthetic.state.inputUnits||"",this.state.labelFontSize),g=p+this.tickHeight+this.state.labelFontSize+f.heightPx;this.coordinates={width:u,height:g,leftOverhang:h,title:{x:h,y:this.state.titleFontSize,text:this.state.aesthetic.state.title},polygon:[],ticks:[],labels:[],units:{x:u/2,y:g,text:this.state.aesthetic.state.inputUnits||""}},a.forEach((t,e)=>{const n=h+e/(a.length-1)*r;this.coordinates.ticks.push({x1:n,y1:p,x2:n,y2:p+this.tickHeight}),this.coordinates.labels.push({x:n,y:p+this.tickHeight,text:ii(t,a)})}),this.coordinates.polygon=[{x:h,y:p},{x:h,y:p-o},{x:h+r,y:p-s},{x:h+r,y:p}]}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 e=this.coordinates.polygon.map(t=>`${t.x},${t.y}`).join(" ");this.group.append("polygon").attr("points",e).attr("fill","#f0f0f0").attr("stroke","#ccc").attr("stroke-width",1),this.coordinates.ticks.forEach(t=>{this.group.append("line").attr("x1",t.x1).attr("y1",t.y1).attr("x2",t.x2).attr("y2",t.y2).attr("stroke","#000").attr("stroke-width",1)}),this.coordinates.labels.forEach(t=>{this.group.append("text").attr("x",t.x).attr("y",t.y).attr("text-anchor","middle").attr("dominant-baseline","hanging").style("font-size",`${this.state.labelFontSize}px`).text(t.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 wi extends xi{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,e=t.state.isCategorical,n=this.textSizeEstimator.getTextSize(t.state.title,this.state.titleFontSize);let i=0;this.showTitle&&(i=this.state.titleFontSize+this.verticalSpacing),e?this.#r(i,n):this.#l(i,n)}#r(t,e){const n=this.state.aesthetic,i=n.scale.categories,a=this.state.maxX-this.state.x;this.coordinates={width:0,height:t,title:{x:0,y:this.state.titleFontSize,text:n.state.title},items:[],isCategorical:!0};let s=0,o=t+this.verticalSpacing+this.squareSize/2,r=this.squareSize;i.slice(0,n.scale.maxColors).forEach((t,e)=>{const i=n.scale.getValue(t),l=this.textSizeEstimator.getTextSize(t,this.state.labelFontSize),h=this.squareSize+this.itemLabelGap+l.widthPx;s>0&&s+h>a&&(s=0,o+=r+this.verticalSpacing,r=this.squareSize),this.coordinates.items.push({x:s,y:o,color:i,label:e<n.scale.maxColors-1?t:n.state.otherLabel,squareX:s,squareY:o-this.squareSize/2,labelX:s+this.squareSize+this.itemLabelGap,labelY:o}),s+=h+this.itemGap,this.coordinates.width=Math.max(this.coordinates.width,s-this.itemGap)}),this.coordinates.height=o+this.squareSize/2}#l(t,e){const n=this.state.aesthetic,i=ni(n.scale.dataMin,n.scale.dataMax,5),a=Math.max(30*i.length,120),s=i.map(t=>{const e=ii(t,i);return this.textSizeEstimator.getTextSize(e,this.state.labelFontSize)}),o=s[0].widthPx/2,r=s[s.length-1].widthPx/2,l=a+o+r,h=t+this.verticalSpacing,c=h+this.gradientHeight,u=c+this.tickHeight,d=this.textSizeEstimator.getTextSize(n.state.inputUnits||"",this.state.labelFontSize),p=u+this.state.labelFontSize+d.heightPx;this.coordinates={width:l,height:p,leftOverhang:o,isCategorical:!1,title:{x:o,y:this.state.titleFontSize,text:n.state.title},gradient:{x:o,y:h,width:a,height:this.gradientHeight},ticks:[],labels:[],units:{x:l/2,y:p,text:n.state.inputUnits||""}},i.forEach((t,e)=>{const n=o+e/(i.length-1)*a;this.coordinates.ticks.push({x1:n,y1:c,x2:n,y2:c+this.tickHeight}),this.coordinates.labels.push({x:n,y:u,text:ii(t,i)})})}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.#h():this.#c()}#h(){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)})}#c(){const t=this.state.aesthetic,e=t.scale.dataMin,n=t.scale.dataMax,i=`color-gradient-${Math.random().toString(36).substr(2,9)}`,a=this.group.append("defs").append("linearGradient").attr("id",i).attr("x1","0%").attr("x2","100%").attr("y1","0%").attr("y2","0%");for(let s=0;s<=this.numGradientStops;s++){const i=s/this.numGradientStops,o=e+i*(n-e),r=t.scale.getValue(o);a.append("stop").attr("offset",100*i+"%").attr("stop-color",r)}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(#${i})`).style("stroke","#000").style("stroke-width",1),this.coordinates.ticks.forEach(t=>{this.group.append("line").attr("x1",t.x1).attr("y1",t.y1).attr("x2",t.x2).attr("y2",t.y2).attr("stroke","#000").attr("stroke-width",1)}),this.coordinates.labels.forEach(t=>{this.group.append("text").attr("x",t.x).attr("y",t.y).attr("text-anchor","middle").attr("dominant-baseline","hanging").style("font-size",`${this.state.labelFontSize}px`).text(t.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 _i{constructor(t,e,n={}){if(!t)throw new Error("TreeView requires a TreeState instance");if(!e)throw new Error("TreeView requires an SVG container element");this.treeState=t,this.svg=xt(e),this.options={buttonSize:25,controlsMargin:3,buttonPadding:2,manualZoomAndPanEnabled:!0,autoZoom:"Default",autoPan:"Default",transitionDuration:500,legendSpacing:10,legendPadding:10,...n},this.layers={},this.selections={},this.legendInstances=[],this.currentTransform={x:0,y:0,k:1},this.isTransitioning=!1,this.isExpanding=!1,this.activeTransitions=new Set,this.selectedNode=null,this.selectionButtons=[{id:"collapse-subtree",icon:"compress",isVisible:t=>t&&t!==this.treeState.displayedRoot&&(t.children||t.collapsedChildren),onClick:t=>{t&&t!==this.treeState.displayedRoot&&t.children&&(this.treeState.collapseSubtree(t),this.#u())}},{id:"collapse-root",icon:"expand",isVisible:t=>t&&t!==this.treeState.displayedRoot&&(t.children||t.collapsedChildren),onClick:t=>{t&&t!==this.treeState.displayedRoot&&t.children&&(this.treeState.collapseRoot(t),this.#u())}},{id:"hide",icon:"trash",isVisible:t=>t&&t!==this.treeState.displayedRoot,onClick:t=>{t&&t!==this.treeState.displayedRoot&&(this.treeState.hideSubtree(t),this.#u())}},{id:"rotate-subtree",icon:"rotate",isVisible:t=>{if(!t||!t.children)return!1;return t.children.filter(t=>!t.hidden).length>1},onClick:t=>{if(t&&t.children){t.children.filter(t=>!t.hidden).length>1&&this.treeState.rotateSubtree(t)}}}],this.#d(),this.initializeZoom(),this.#p(),this.#f()}destroy(){this.svg.selectAll("*").remove(),this.layers={},this.selections={},this.selectedNode=null,this.legendInstances=[]}reattach(t){this.svg=xt(t),this.#d(),this.initializeZoom(),this.#g(!1),this.#m(!1),this.#y(!1),this.#o(!1),this.fitToView({transition:!1,forcePanToTop:!0})}#d(){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.#x()}#u(){this.selectedNode=null,this.layers.selectionRect.style("display","none"),this.layers.selectionBtns.style("display","none")}#x(){const t=this.layers.selectionBtns;this.selectionButtons.forEach(e=>{const n=t.append("g").attr("class",`btn-${e.id}`).style("cursor","pointer").on("click",()=>{e.onClick(this.selectedNode)});!function(t,e,n,i=2){const a=yi[e],s=(n-2*i)/24,o=t.append("rect").attr("width",n).attr("height",n).attr("rx","5px").attr("ry","5px").attr("fill","#CCC"),r=t.append("g").attr("transform",`translate(${i}, ${i}) scale(${s})`).attr("stroke","#555").attr("fill","none").attr("stroke-linecap","round").attr("stroke-linejoin","round").attr("stroke-width",2);a.forEach(t=>{r.append("path").attr("d",t)})}(n,e.icon,this.options.buttonSize),e.element=n})}initializeZoom(){this.treeZoom=Qn().filter(t=>!!this.options.manualZoomAndPanEnabled&&"dblclick"!==t.type).on("zoom",t=>{this.currentTransform=t.transform,this.layers.treeGroup.attr("transform",t.transform),this.#b(null===t.sourceEvent)}),this.svg.call(this.treeZoom)}#p(){this.treeState.subscribe("coordinateChange",()=>{this.#v()}),this.treeState.subscribe("layoutChange",()=>{this.#v()}),this.treeState.subscribe("legendsChange",()=>{this.#o(!0)}),this.treeState.subscribe("tipLabelTextChange",()=>{this.#w()}),this.treeState.subscribe("tipLabelColorChange",()=>{this.#_()}),this.treeState.subscribe("tipLabelSizeChange",()=>{this.#S(),this.#o(!0)}),this.treeState.subscribe("tipLabelFontChange",()=>{this.#C()}),this.treeState.subscribe("tipLabelStyleChange",()=>{this.#M()}),this.treeState.subscribe("nodeLabelTextChange",()=>{this.#T()})}#f(){this.#g(!1),this.#m(!1),this.#y(!1),this.#o(!1),this.fitToView({transition:!1,forcePanToTop:!0})}#v(){const t=this.#g(!0),e=this.#m(!0);this.#y(!0),this.#o(!0),this.selectedNode&&this.#L(!0),this.isExpanding&&t&&e?setTimeout(()=>{t.transition("branch group fade in").duration(150).attr("opacity",1),e.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.selectedNode&&setTimeout(()=>{this.#b(!1)},this.options.transitionDuration),this.fitToView()}#w(){this.selections.nodes&&this.selections.nodes.selectAll(".tip-label").text(t=>t.tipLabelText||"")}#_(){this.selections.nodes&&this.selections.nodes.selectAll(".tip-label").style("fill",t=>t.tipLabelColor||"#000")}#S(){this.selections.nodes&&this.selections.nodes.selectAll(".tip-label").style("font-size",t=>`${t.tipLabelSizePx||12}px`)}#C(){this.selections.nodes&&this.selections.nodes.selectAll(".tip-label").style("font-family",t=>t.tipLabelFont||"sans-serif")}#M(){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")}#T(){this.selections.nodes&&this.selections.nodes.selectAll(".node-label").text(t=>t.nodeLabelText||"")}#o(t=!0){this.layers.legendLayer.selectAll("*").remove(),this.legendInstances=[];const e=this.#P();if(!e)return;e.maxX,e.minX;let n=e.minX,i=e.maxY+this.options.legendSpacing;const a=new bi({treeState:this.treeState,x:n,y:i,origin:"top left",maxX:e.maxX,maxY:1/0});a.render(this.layers.legendLayer),this.legendInstances.push(a),n+=a.coordinates.width+this.options.legendSpacing;for(const s of this.treeState.legends){let t;"size"===s.type?t=new vi({treeState:this.treeState,aesthetic:s.aesthetic,x:n,y:i,origin:"top left",maxX:e.maxX,maxY:1/0}):"color"===s.type&&(t=new wi({treeState:this.treeState,aesthetic:s.aesthetic,x:n,y:i,origin:"top left",maxX:e.maxX,maxY:1/0})),n+t.coordinates.width+this.options.legendSpacing>e.maxX&&(n=e.minX,i+=Math.max(...this.legendInstances.map(t=>t.coordinates.height))),t&&(t.render(this.layers.legendLayer),this.legendInstances.push(t),n+=t.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}).autoZoom&&"None"!=t.autoZoom||t.autoPan&&"None"!=t.autoPan))return;const{width:e,height:n}=this.svg.node().getBoundingClientRect(),i=this.getCurrentBoundsWithLegends();if(!i)return;i.minX-=t.padding,i.maxX+=t.padding,i.minY-=t.padding,i.maxY+=t.padding;const a=i.maxX-i.minX,s=i.maxY-i.minY,o=e-0,r=n;let l=this.currentTransform.k,h=this.currentTransform.x,c=this.currentTransform.y;const u=o/a,d=r/s;if("Default"==t.autoZoom&&("circular"!=this.treeState.state.layout&&this.options.manualZoomAndPanEnabled?t.autoZoom="X":t.autoZoom="Both"),t.autoZoom&&"None"!=t.autoZoom&&("X"==t.autoZoom?l=Math.min(1,u):"Y"==t.autoZoom?l=Math.min(1,d):"Both"==t.autoZoom?l=Math.min(u,d):console.error(`Value of ${t.autoZoom} is invalid for input.autoZoom.`)),"Default"==t.autoPan&&(t.autoPan="Both"),t.autoPan&&"None"!=t.autoPan){if("Both"==t.autoPan||"X"==t.autoPan){const t=a*l;if(t<=o)h=0+(o-t)/2-i.minX*l;else{const t=-i.minX*l-0,n=e-i.maxX*l;h=t>0?0-i.minX*l:n>0?e-i.maxX*l:0+o/2-(i.minX+i.maxX)/2*l}}if("Both"==t.autoPan||"Y"==t.autoPan){const e=s*l;if(e<=r)c=(r-e)/2-i.minY*l;else{const e=-i.minY*l,a=n-i.maxY*l;c>e||t.forcePanToTop?c=e:c<a&&(c=a)}}}const p=On.translate(h,c).scale(l);t.transition?this.svg.transition("zoom").duration(this.options.transitionDuration).call(this.treeZoom.transform,p):this.svg.call(this.treeZoom.transform,p)}#P(){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.#P();if(!t)return null;let e=t.maxY,n=t.minX;for(const i of this.legendInstances)i.coordinates&&(e=Math.max(e,i.state.y+i.coordinates.height));return"circular"!==this.treeState.state.layout&&this.treeState.displayedRoot.collapsedParent&&(n-=this.#k()),{minX:n,maxX:t.maxX,minY:t.minY,maxY:e}}#z(t){this.selectedNode===t?this.#u():(this.selectedNode=t,this.layers.selectionRect.attr("d",this.#$(t)).style("display","block"),this.#b(!1))}#L(t=!1){this.selectedNode&&(t?this.layers.selectionRect.transition("update selection rect").duration(this.options.transitionDuration).attr("d",this.#$(this.selectedNode)):this.layers.selectionRect.attr("d",this.#$(this.selectedNode)))}#$(t){if(!t)return"";let e,n,i,a,s,o;if("circular"===this.treeState.state.layout)e={x:t.bounds.minRadius*Math.cos(t.bounds.minAngle),y:t.bounds.minRadius*Math.sin(t.bounds.minAngle)},i={x:t.bounds.maxRadius*Math.cos(t.bounds.maxAngle),y:t.bounds.maxRadius*Math.sin(t.bounds.maxAngle)},o=this.#E(i.x,i.y,t.bounds.maxRadius,t.bounds.maxAngle,t.bounds.minAngle,!1),s=this.#E(e.x,e.y,t.bounds.minRadius,t.bounds.minAngle,t.bounds.maxAngle,!0);else{e={x:t.bounds.minX,y:t.bounds.minY},n={x:t.bounds.minX,y:t.bounds.maxY},i={x:t.bounds.maxX,y:t.bounds.maxY},a={x:t.bounds.maxX,y:t.bounds.minY};const r=this.treeState.displayedRoot,l=r.bounds.maxY-r.bounds.minY,h=Math.abs(n.y-e.y)/l,c=Math.max(1,Math.ceil(h/.25));s=this.#A(e,n,c),o=this.#A(i,a,c)}return`M${e.x},${e.y} ${s} L${i.x},${i.y} ${o} Z`}#A(t,e,n=1){let i="";for(let a=0;a<n;a++){const s=a/n,o=(a+1)/n,r=t.x+(e.x-t.x)*s,l=t.y+(e.y-t.y)*s,h=t.x+(e.x-t.x)*o,c=t.y+(e.y-t.y)*o;i+=`C${r},${l+(c-l)/3} ${h},${c-(c-l)/3} ${h},${c}`,a<n-1&&(i+=" ")}return i}#b(t=!0,e=1.1){if(!this.selectedNode)return void this.layers.selectionBtns.style("display","none");let n,i;if("circular"===this.treeState.state.layout){const t=this.selectedNode.bounds.minAngle,e=this.selectedNode.bounds.maxAngle,a=this.selectedNode.bounds.minRadius,s=this.selectedNode.bounds.maxRadius,o=20;let r=1/0,l=0;for(let n=0;n<=o;n++){const i=t+(e-t)*n/o,h=a*Math.cos(i),c=a*Math.sin(i),u=s*Math.cos(i),d=s*Math.sin(i);h<r&&(r=h,l=c),u<r&&(r=u,l=d)}n=r,i=l}else n=this.selectedNode.bounds.minX,i=this.selectedNode.bounds.minY;let a=0;this.selectionButtons.forEach(t=>{if(t.isVisible(this.selectedNode)){const n=a*(this.options.buttonSize*e);t.element.style("display","block").attr("transform",`translate(0, ${n})`),a++}else t.element.style("display","none")});const s=a*this.options.buttonSize+(a-1)*this.options.buttonSize*(e-1);let o=n*this.currentTransform.k+this.currentTransform.x-this.options.buttonSize*e,r=i*this.currentTransform.k+this.currentTransform.y-this.options.buttonSize*(e-1);const{width:l,height:h}=this.svg.node().getBoundingClientRect();o=Math.max(o,0),o=Math.min(o,l-this.options.buttonSize),r=Math.max(r,0),r=Math.min(r,h-s),t?this.layers.selectionBtns.attr("opacity",0).attr("transform",`translate(${o},${r})`):this.layers.selectionBtns.attr("transform",`translate(${o},${r})`).attr("opacity",1).style("display","block")}#y(){const t=this.treeState.displayedRoot;if(!t)return;const e="circular"===this.treeState.state.layout,n=this.treeState.labelSizeToPxFactor*this.treeState.state.branchThicknessProp,i=this.#k(),a=this.layers.hitLayer.selectAll(".hit").data(t.descendants().filter(t=>{if(!t.children)return!1;return t.children.filter(t=>!t.hidden).length>1}),t=>t.id);a.exit().remove();a.enter().append("path").attr("class","hit").attr("fill","transparent").style("cursor","pointer").on("click",(t,e)=>{this.#z(e),t.stopPropagation()}).merge(a).attr("d",t=>this.#$(t)),this.layers.hitLayer.selectAll(".hit").sort((t,e)=>t.depth-e.depth);const s=this.layers.hitLayer.selectAll(".tip-hit").data(t.descendants().filter(t=>!t.children&&!t.collapsedChildren),t=>t.id);s.exit().remove();s.enter().append("path").attr("class","tip-hit").attr("fill","transparent").style("cursor","pointer").on("click",(t,e)=>{this.#z(e),t.stopPropagation()}).merge(s).attr("d",t=>this.#$(t));const o=this.layers.hitLayer.selectAll(".collapsed-hit").data(t.descendants().filter(t=>t.collapsedChildren),t=>t.id);o.exit().remove();o.enter().append("rect").attr("class","collapsed-hit").attr("fill","transparent").style("cursor","pointer").on("click",(t,e)=>{e.collapsedChildren&&(this.isExpanding=!0,this.treeState.expandSubtree(e)),t.stopPropagation()}).merge(o).attr("transform",t=>`translate(${t.xPx}, ${t.yPx}) rotate(${this.#N(t)})`).attr("y",t=>-t.tipLabelSizePx/2.5).attr("width",t=>this.treeState.getCollapsedTriangleHeight(t)+t.tipLabelBounds.width*this.treeState.labelSizeToPxFactor).attr("height",t=>Math.max(t.tipLabelSizePx,this.treeState.getCollapsedTriangleHeight(t)));const r=this.layers.hitLayer.selectAll(".collapsed-root-hit").data(t.collapsedParent?[t]:[],t=>t.id);r.exit().remove();r.enter().append("rect").attr("class","collapsed-root-hit").attr("fill","transparent").style("cursor","pointer").on("click",(t,e)=>{e.collapsedParent&&(this.isExpanding=!0,this.treeState.expandRoot()),t.stopPropagation()}).merge(r).attr("transform",t=>{if(!t.collapsedParent)return`translate(${t.xPx}, ${t.yPx})`;let n=0;if(e){const e=t.children||[];if(e.length>0){n=e.reduce((t,e)=>t+e.angle,0)/e.length*(180/Math.PI)}}return`translate(${t.xPx}, ${t.yPx}) rotate(${n})`}).attr("x",-i).attr("y",5*-n).attr("width",i).attr("height",10*n)}#g(t=!0){const e=this.treeState.displayedRoot;if(!e)return;const n=e.links(),i=this.treeState.labelSizeToPxFactor*this.treeState.state.branchThicknessProp,a=this.layers.branchLayer.selectAll(".branch-group").data(n,t=>t.target.id);t?a.exit().attr("opacity",0).remove():a.exit().remove();const s=a.enter().append("g").attr("class","branch-group");this.#R(s),this.isExpanding&&t&&s.attr("opacity",0);const o=s.merge(a);return this.#B(o,t,i),this.selections.branches=o,s}#R(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")}#B(t,e,n){this.treeState.state.layout;const i=t.select(".offset"),a=t.select(".extension");e?(i.transition().duration(this.options.transitionDuration).attr("stroke-width",n).attr("d",t=>this.#H(t,"offset")),a.transition().duration(this.options.transitionDuration).attr("stroke-width",n).attr("d",t=>this.#H(t,"extension"))):(i.attr("stroke-width",n).attr("d",t=>this.#H(t,"offset")),a.attr("stroke-width",n).attr("d",t=>this.#H(t,"extension")))}#E(t,e,n,i,a,s){let o=a-i;s&&o<0?o+=2*Math.PI:!s&&o>0&&(o-=2*Math.PI);const r=Math.abs(o),l=Math.max(1,Math.ceil(r/(Math.PI/2))),h=o/l,c=4/3*Math.tan(h/4);let u="",d=i,p=t,f=e;for(let g=0;g<l;g++){const t=d+h,e=n*Math.cos(t),i=n*Math.sin(t);u+=` C${p-c*n*Math.sin(d)},${f+c*n*Math.cos(d)} ${e+c*n*Math.sin(t)},${i-c*n*Math.cos(t)} ${e},${i}`,d=t,p=e,f=i}return u}#H(t,e){const n="circular"===this.treeState.state.layout;if("offset"===e){if(n){t.source.radiusPx,t.target.cos,t.source.radiusPx,t.target.sin;const e=t.target.angle>t.source.angle,n=this.#E(t.source.xPx,t.source.yPx,t.source.radiusPx,t.source.angle,t.target.angle,e);return`M${t.source.xPx},${t.source.yPx}${n}`}{const e=t.source.xPx,n=t.source.yPx,i=t.source.xPx,a=t.target.yPx;return`M${e},${n} C${e},${n+(a-n)/3} ${i},${a-(a-n)/3} ${i},${a}`}}if(n){const e={x:t.source.radiusPx*t.target.cos,y:t.source.radiusPx*t.target.sin};return`M${e.x},${e.y} L${t.target.xPx},${t.target.yPx}`}return`M${t.source.xPx},${t.target.yPx} L${t.target.xPx},${t.target.yPx}`}#F(t){const e=.4330127*(n=this.treeState.getCollapsedTriangleHeight(t))*n;var n;return Xn().type(Fn).size(e)()}#m(t=!0){const e=this.treeState.displayedRoot;if(!e)return;this.treeState.state.layout;const n=e.descendants().filter(t=>!t.hidden),i=this.treeState.labelSizeToPxFactor*this.treeState.state.branchThicknessProp,a=this.#k(),s=this.layers.nodeLayer.selectAll(".node").data(n,t=>t.id);t?s.exit().attr("opacity",0).remove():s.exit().remove();const o=s.enter().append("g").attr("class","node").attr("transform",t=>`translate(${t.xPx}, ${t.yPx})`);this.#X(o,i),this.isExpanding&&t&&o.attr("opacity",0);const r=o.merge(s);return this.#V(r,t),this.#D(r,t),this.#Y(r,t),this.#O(r,t,i,a),this.selections.nodes=r,o}#X(t,e){t.append("path").attr("class","node-shape").attr("d",t=>t.collapsedChildren?this.#F(t):null).attr("fill","#000").style("display",t=>t.collapsedChildren?null:"none"),t.append("line").attr("class","collapsed-root-line").attr("stroke","#000").attr("stroke-width",e).style("display",t=>t.collapsedParent?null:"none"),t.filter(t=>t.tipLabelText&&""!==t.tipLabelText.trim()).append("text").attr("class","tip-label").style("text-anchor",t=>this.#q(t)).style("font-size",t=>`${t.tipLabelSizePx}px`).style("font-family",t=>t.tipLabelFont||"sans-serif").style("font-style",t=>t.tipLabelStyle||"normal").style("font-weight",t=>"bold"===t.tipLabelStyle?"bold":"normal").style("fill",t=>t.tipLabelColor||"#000").style("display",t=>t.children?"none":null).text(t=>t.tipLabelText||""),t.filter(t=>{if(!t.nodeLabelText||""===t.nodeLabelText.trim())return!1;if(!t.children)return!1;return t.children.filter(t=>!t.hidden).length>1}).append("text").attr("class","node-label").style("text-anchor",t=>this.#I(t)).style("font-size",t=>`${t.nodeLabelSizePx}px`).style("fill","#000").style("display",t=>t.children||t.collapsedChildren?null:"none").text(t=>t.nodeLabelText||"")}#V(t,e){e?t.transition("update node positions").duration(this.options.transitionDuration).attr("transform",t=>`translate(${t.xPx}, ${t.yPx}) rotate(${this.#N(t)})`):t.attr("transform",t=>`translate(${t.xPx}, ${t.yPx}) rotate(${this.#N(t)})`)}#D(t,e){const n="circular"===this.treeState.state.layout,i=t.selectAll(".tip-label");i.attr("x",t=>this.#Z(t)&&n?-t.tipLabelXOffsetPx:t.tipLabelXOffsetPx).style("text-anchor",t=>this.#q(t)).attr("transform",t=>`rotate(${this.#Z(t)&&n?180:0})`).text(t=>t.tipLabelText||"").style("fill",t=>t.tipLabelColor||"#000").style("font-family",t=>t.tipLabelFont||"sans-serif").style("font-style",t=>t.tipLabelStyle||"normal").style("display",t=>t.children?"none":null),e?i.transition("update tip labels").duration(this.options.transitionDuration).attr("dy",t=>t.tipLabelSizePx/2.5).style("font-size",t=>`${t.tipLabelSizePx}px`):i.attr("dy",t=>t.tipLabelSizePx/2.5).style("font-size",t=>`${t.tipLabelSizePx}px`);const a=t.selectAll(".node-label");a.attr("x",t=>this.#Z(t)&&n?t.nodeLabelXOffsetPx:-t.nodeLabelXOffsetPx).attr("transform",t=>`rotate(${this.#Z(t)&&n?180:0})`).style("text-anchor",t=>this.#I(t)).text(t=>t.nodeLabelText||"").style("display",t=>{if(!t.children&&!t.collapsedChildren)return"none";if(t.children){if(t.children.filter(t=>!t.hidden).length<=1)return"none"}return null}),e?a.transition("update node labels").duration(this.options.transitionDuration).attr("dy",t=>this.#j(t)).style("font-size",t=>`${t.nodeLabelSizePx}px`):a.attr("dy",t=>this.#j(t)).style("font-size",t=>`${t.nodeLabelSizePx}px`)}#Y(t,e){const n=t.selectAll(".node-shape");n.attr("transform",t=>`rotate(-90) translate(0, ${this.treeState.getCollapsedTriangleOffset(t)})`).style("display",t=>t.collapsedChildren?null:"none"),e?n.transition().duration(this.options.transitionDuration).attr("d",t=>t.collapsedChildren?this.#F(t):null):n.attr("d",t=>t.collapsedChildren?this.#F(t):null)}#O(t,e,n,i){const a=t.selectAll(".collapsed-root-line");e?a.transition().duration(this.options.transitionDuration).attr("x2",-i).attr("y2",0).attr("stroke-width",n).attr("stroke-dasharray",t=>t.collapsedParent?ti(i,n,4):null):a.attr("x2",-i).attr("y2",0).attr("stroke-width",n).attr("stroke-dasharray",t=>t.collapsedParent?ti(i,n,4):null),a.attr("x1",0).attr("y1",0).style("display",t=>t.collapsedParent?null:"none")}#N(t){if(!("circular"===this.treeState.state.layout))return 0;return t.angle*(180/Math.PI)}#q(t){return"circular"===this.treeState.state.layout&&this.#Z(t)?t.children?"start":"end":t.children?"end":"start"}#I(t){return"circular"===this.treeState.state.layout&&this.#Z(t)?t.children||t.collapsedChildren?"start":"end":t.children||t.collapsedChildren?"end":"start"}#j(t){const e=t.parent&&t.parent.yPx>t.yPx,n=t.nodeLabelSizePx;return e?.3*-n:1*n}#Z(t){return t.angle<1.5*Math.PI||t.angle>2.5*Math.PI}#k(){const t=this.treeState.displayedRoot;if(!t)return 0;if("circular"===this.treeState.state.layout){return Math.max(...t.leaves().map(t=>t.radiusPx))*this.treeState.state.collapsedRootLineProp*2}return Math.max(...t.leaves().map(t=>t.xPx))*this.treeState.state.collapsedRootLineProp}}function Si(t,e,n){const i=t.getCurrentBoundsWithLegends(),a=i.maxX-i.minX,s=i.maxY-i.minY,o=e.width/a,r=e.height/s,l=Math.min(o,r),h=e.width+2*e.margin,c=e.height+2*e.margin,u=e.margin-i.minX*l,d=e.margin-i.minY*l,p=document.createElementNS("http://www.w3.org/2000/svg","svg");p.setAttribute("width",h),p.setAttribute("height",c),p.setAttribute("xmlns","http://www.w3.org/2000/svg");const f=document.createElementNS("http://www.w3.org/2000/svg","g");f.setAttribute("transform",`translate(${u}, ${d}) scale(${l})`);const g=t.layers.treeGroup.node().cloneNode(!0);g.removeAttribute("transform");const m=g.querySelector(".selection-rect");m&&m.remove(),f.appendChild(g),p.appendChild(f);const y=(new XMLSerializer).serializeToString(p);"svg"===e.format?function(t,e,n){const i=new Blob([t],{type:n}),a=URL.createObjectURL(i),s=document.createElement("a");s.href=a,s.download=e,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(a)}(y,n,"image/svg+xml"):"png"===e.format&&function(t,e,n,i){const a=document.createElement("canvas");a.width=e,a.height=n;const s=a.getContext("2d"),o=new Image,r=new Blob([t],{type:"image/svg+xml;charset=utf-8"}),l=URL.createObjectURL(r);o.onload=()=>{s.fillStyle="white",s.fillRect(0,0,e,n),s.drawImage(o,0,0),a.toBlob(t=>{const e=URL.createObjectURL(t),n=document.createElement("a");n.href=e,n.download=i,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(e),URL.revokeObjectURL(l)})},o.src=l}(y,h,c,n)}function Ci(t,e,n,i,a,s,o){let r=null,l=null,h=null,c=null,u=null,d=null,p=!0;const f=document.createElement("div");f.className="ht-toggle-container";const g=document.createElement("button");g.className="ht-control-panel-toggle",g.innerHTML='\n <svg width="16" height="16" viewBox="0 0 16 16" class="ht-toggle-arrow">\n <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)"/>\n </svg>\n <svg width="16" height="16" viewBox="0 0 16 16" class="ht-hamburger-icon">\n <line x1="2" y1="4" x2="14" y2="4" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>\n <line x1="2" y1="8" x2="14" y2="8" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>\n <line x1="2" y1="12" x2="14" y2="12" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>\n </svg>\n ',g.title="Toggle control panel",f.appendChild(g);const m=document.createElement("div");m.className="ht-collapsible-panel";const y=document.createElement("div");y.className="ht-tabs";const x=document.createElement("div");x.className="ht-controls hidden";const b=[{id:"data",label:"Data",requiresTree:!1},{id:"controls",label:"Controls",requiresTree:!0},{id:"tree-manipulation",label:"Tree",requiresTree:!0},{id:"tip-label-settings",label:"Tip Labels",requiresTree:!0},{id:"export",label:"Export",requiresTree:!0}],v={};function w(){const t=null!==n();if(b.forEach(e=>{const n=v[e.id];e.requiresTree&&!t?n.classList.add("disabled"):n.classList.remove("disabled")}),r){const e=b.find(t=>t.id===r);e&&e.requiresTree&&!t&&P("data")}}function _(){const t=n();return t&&t.state.treeData?t.state.treeData.getMetadataTableNames():[]}function S(){return l}function C(t){_().includes(t)?l=t:console.warn(`Metadata table not found: ${t}`)}function M(){const t=_();l=t.length>0?t[0]:null}function T(){const t=n();if(t){if(h){let e=!1;t.displayedRoot.each(n=>{n!==t.displayedRoot&&n.collapsedChildren&&(e=!0)}),h.disabled=!e}if(c&&(c.disabled=!t.displayedRoot.collapsedParent),u){let e=!1;t.state.treeData.tree.each(t=>{t.hiddenChildren&&t.hiddenChildren.length>0&&(e=!0)}),u.disabled=!e}}}function L(){const t=n();if(!t)return"tree";for(const[n,i]of e.entries())if(i===t.state.treeData)return n;return"tree"}function P(t){const e=b.find(e=>e.id===t);e&&e.requiresTree&&!n()||(r=t,Object.keys(v).forEach(e=>{e===t?v[e].classList.add("active"):v[e].classList.remove("active")}),x.classList.remove("hidden"),k(t))}function k(t){switch(x.innerHTML="",t){case"data":!function(t,e,n,i,a,s,o,r,l,h,c,u){t.innerHTML="";const d=Ti(),p=Li("Select tree:",u);d.appendChild(p);const f=document.createElement("select");f.className="ht-select",f.style.height=`${u}px`;const g=Array.from(e.keys()),m=n(),y=m?Array.from(e.entries()).find(([t,e])=>e===m.state.treeData)?.[0]:null;if(0===g.length){const t=document.createElement("option");t.textContent="No trees loaded",t.value="",f.appendChild(t),f.disabled=!0}else g.forEach(t=>{const e=document.createElement("option");e.value=t,e.textContent=t,t===y&&(e.selected=!0),f.appendChild(e)}),f.addEventListener("change",t=>{i(t.target.value)});d.appendChild(f),t.appendChild(d);const x=document.createElement("input");x.type="file",x.accept=".nwk,.newick,.tree,.tre,.treefile",x.style.display="none",x.addEventListener("change",async t=>{const n=t.target.files[0];if(n)try{const t=await n.text();let s=n.name.replace(/\.(nwk|newick|tree|tre)$/i,""),o=s,r=1;for(;e.has(o);)o=`${s} (${r})`,r++;a(o,t),x.value="",h(),i(o)}catch(s){console.error("Error loading tree file:",s),alert(`Error loading tree file: ${s.message}`)}}),t.appendChild(x);const b=Pi("+","Add tree from Newick file",u);if(b.addEventListener("click",()=>{x.click()}),t.appendChild(b),!m)return;const v=Ti(),w=Li("Available metadata:",u);v.appendChild(w);const _=document.createElement("select");_.className="ht-select",_.style.height=`${u}px`;const S=s(),C=o();if(0===S.length){const t=document.createElement("option");t.textContent="No metadata",t.value="",_.appendChild(t),_.disabled=!0}else S.forEach(t=>{const e=document.createElement("option");e.value=t,e.textContent=t,t===C&&(e.selected=!0),_.appendChild(e)}),_.addEventListener("change",t=>{r(t.target.value)});v.appendChild(_),t.appendChild(v);const M=document.createElement("input");M.type="file",M.accept=".tsv,.csv,.txt",M.style.display="none",M.addEventListener("change",async t=>{const e=t.target.files[0];if(!e)return;const i=n();if(!i||!i.state.treeData)return alert("No tree selected. Please select a tree first."),void(M.value="");try{const t=await e.text();let n=e.name.replace(/\.(tsv|csv|txt)$/i,""),a="\t";e.name.toLowerCase().endsWith(".csv")&&(a=",");const s=i.state.treeData.addTable(t,n,a),o=i.state.treeData.metadataTableNames.get(s);M.value="",r(o),h()}catch(a){console.error("Error loading metadata file:",a),alert(`Error loading metadata file: ${a.message}`),M.value=""}}),t.appendChild(M);const T=Pi("+","Add metadata table",u);T.addEventListener("click",()=>{const t=n();t&&t.state.treeData?M.click():alert("No tree selected. Please select a tree first.")}),t.appendChild(T)}(x,e,n,a,s,_,S,C,0,z,0,24);break;case"controls":!function(t,e,n,i,a){t.innerHTML="";const s=e(),o=n();if(!s||!o)return void(t.textContent="No tree selected");const r=Pi("Fit to view","Fit the tree to the current view window",a);r.addEventListener("click",()=>{o.fitToView({transition:!0,autoPan:"Both",autoZoom:"Both"})}),t.appendChild(r);const l=Ti(),h=Li("Manual zoom/pan:",a);l.appendChild(h);const c=zi(o.options.manualZoomAndPanEnabled,a);c.addEventListener("click",()=>{o.options.manualZoomAndPanEnabled=!o.options.manualZoomAndPanEnabled,o.options.manualZoomAndPanEnabled?c.classList.add("active"):(c.classList.remove("active"),o.fitToView()),o.initializeZoom()}),l.appendChild(c),t.appendChild(l);const u=Ti(),d=Li("Auto-zoom:",a);u.appendChild(d);const p=document.createElement("select");p.className="ht-select",p.style.height=`${a}px`;["Default","Both","X","Y","None"].forEach(t=>{const e=document.createElement("option");e.value=t,e.textContent=t,t===o.options.autoZoom&&(e.selected=!0),p.appendChild(e)}),p.addEventListener("change",t=>{o.options.autoZoom=t.target.value}),u.appendChild(p),t.appendChild(u);const f=Ti(),g=Li("Auto-pan:",a);f.appendChild(g);const m=document.createElement("select");m.className="ht-select",m.style.height=`${a}px`;["Default","Both","X","Y","None"].forEach(t=>{const e=document.createElement("option");e.value=t,e.textContent=t,t===o.options.autoPan&&(e.selected=!0),m.appendChild(e)}),m.addEventListener("change",t=>{o.options.autoPan=t.target.value}),f.appendChild(m),t.appendChild(f)}(x,n,i,0,24);break;case"tree-manipulation":!function(t,e,n,i,a,s,o,r,l){t.innerHTML="";const h=e();if(!h)return void(t.textContent="No tree selected");const c=Pi("Expand subtrees","Expand all collapsed subtrees",s),u=()=>{let t=!1;return h.displayedRoot.each(e=>{e!==h.displayedRoot&&e.collapsedChildren&&(t=!0)}),t};c.disabled=!u(),c.addEventListener("click",()=>{const t=[];h.displayedRoot.each(e=>{if(e!==h.displayedRoot&&e.collapsedChildren){let n=!0,i=e.parent;for(;i&&i!==h.displayedRoot;){if(i.collapsedChildren){n=!1;break}i=i.parent}n&&t.push(e)}}),t.forEach(t=>{h.expandSubtree(t)}),i()}),o(c),t.appendChild(c);const d=Pi("Expand root","Expand the collapsed root",s);d.disabled=!h.displayedRoot.collapsedParent,d.addEventListener("click",()=>{h.displayedRoot.collapsedParent&&(h.expandRoot(),i())}),r(d),t.appendChild(d);const p=Pi("Show hidden","Show all hidden nodes",s),f=()=>{let t=!1;return h.state.treeData.tree.each(e=>{e.hiddenChildren&&e.hiddenChildren.length>0&&(t=!0)}),t};p.disabled=!f(),p.addEventListener("click",()=>{h.showAllHidden(),i()}),l(p),t.appendChild(p);const g=Ti(),m=Li("Branch length:",s);g.appendChild(m);const y=(t,e=10)=>{const n=Math.log10(1/e),i=Math.log10(e);return(Math.log10(t)-n)/(i-n)*100},x=(t,e=10)=>{const n=Math.log10(1/e),i=n+t/100*(Math.log10(e)-n);return Math.pow(10,i)},b=ki(0,100,y(h.state.branchLengthScale),.1,s);b.addEventListener("input",t=>{const e=parseFloat(t.target.value),n=x(e);h.setBranchLengthScale(n)}),g.appendChild(b),t.appendChild(g);const v=Ti(),w=Li("Tree height:",s);v.appendChild(w);const _=ki(0,100,y(h.state.treeHeightScale),.1,s);_.addEventListener("input",t=>{const e=parseFloat(t.target.value),n=x(e);h.setTreeHeightScale(n)}),v.appendChild(_),t.appendChild(v);const S=Ti(),C=Li("Radial layout:",s);S.appendChild(C);const M=zi("circular"===h.state.layout,s),T=()=>{"circular"===h.state.layout?M.classList.add("active"):M.classList.remove("active")};h.subscribe("layoutChange",T),M.addEventListener("click",()=>{const t=h.state.layout;h.setLayout("circular"===t?"rectangular":"circular")}),S.appendChild(M),t.appendChild(S)}(x,n,0,T,0,24,t=>{h=t},t=>{c=t},t=>{u=t});break;case"tip-label-settings":!function(t,e,n,i){t.innerHTML="";const a=e();if(!a)return void(t.textContent="No tree selected");const s=Ti(),o=Li("Text:",i);s.appendChild(o);const r=Mi(a,"tipLabelText","Default",i,!0,null);s.appendChild(r),t.appendChild(s);const l=Ti(),h=Li("Color:",i);l.appendChild(h);const c=Mi(a,"tipLabelColor","Default",i,!1,null);l.appendChild(c),t.appendChild(l);const u=Ti(),d=Li("Size:",i);u.appendChild(d);const p=Mi(a,"tipLabelSize","Default",i,!1,!0);u.appendChild(p),t.appendChild(u);const f=Ti(),g=Li("Style:",i);f.appendChild(g);const m=Mi(a,"tipLabelStyle","Default",i,!1,!1);f.appendChild(m),t.appendChild(f);const y=Ti(),x=Li("Font:",i);y.appendChild(x);const b=document.createElement("select");b.className="ht-select",b.style.height=`${i}px`;const v=["sans-serif","serif","monospace"],w=void 0!==a.state.aesthetics.tipLabelFont?a.aestheticsScales.tipLabelFont.getValue():"sans-serif";v.forEach(t=>{const e=document.createElement("option");e.value=t,e.textContent=t,t===w&&(e.selected=!0),b.appendChild(e)}),b.addEventListener("change",t=>{const e=t.target.value;a.setAesthetics({tipLabelFont:void 0}),a.state.treeData.tree.each(t=>{t.tipLabelFont=e}),a.updateCoordinates()}),y.appendChild(b),t.appendChild(y)}(x,n,0,24);break;case"export":!function(t,e,n,i,a,s){t.innerHTML="";const o=e(),r=n();if(!o||!r)return void(t.textContent="No tree selected");const l=r.getCurrentBoundsWithLegends(),h=l.maxX-l.minX,c=l.maxY-l.minY,u={format:"svg",width:h,height:c,margin:18},d=h/c,p=300,f=2.54,g=t=>t/p*f,m=t=>t/f*p,y=(t,e)=>"png"===e?Math.round(t):Math.round(100*g(t))/100,x=(t,e)=>"png"===e?t:m(t),b=()=>{const t=r.getCurrentBoundsWithLegends(),e=t.maxX-t.minX,n=t.maxY-t.minY;u.width=e,u.height=n,P.value=y(e,u.format),$.value=y(n,u.format)},v=o.subscribe("coordinateChange",b),w=o.subscribe("legendsChange",b);t.dataset.cleanup=()=>{v(),w()};const _=Pi("Export","Export the tree to a file",s);_.classList.add("primary"),_.addEventListener("click",()=>{const t=i().replace(/[^a-z0-9_-]/gi,"_"),e="svg"===u.format?"svg":"png";Si(r,u,`${t}.${e}`)}),t.appendChild(_);const S=Ti(),C=Li("Output format:",s);S.appendChild(C);const M=document.createElement("select");M.className="ht-select",M.style.height=`${s}px`,["SVG","PNG"].forEach(t=>{const e=document.createElement("option");e.value=t.toLowerCase(),e.textContent=t,t.toLowerCase()===u.format&&(e.selected=!0),M.appendChild(e)}),M.addEventListener("change",t=>{u.format=t.target.value,P.value=y(u.width,u.format),$.value=y(u.height,u.format),N.value=y(u.margin,u.format);const e="png"===u.format?"px":"cm";L.textContent=`Width (${e}):`,z.textContent=`Height (${e}):`,A.textContent=`Margin (${e}):`}),S.appendChild(M),t.appendChild(S);const T=Ti(),L=Li(`Width (${"png"===u.format?"px":"cm"}):`,s);T.appendChild(L);const P=$i(y(u.width,u.format),.1,1e4,.1,s);P.addEventListener("input",t=>{const e=parseFloat(t.target.value);isNaN(e)||e<=0||(u.width=x(e,u.format),u.height=u.width/d,$.value=y(u.height,u.format))}),T.appendChild(P),t.appendChild(T);const k=Ti(),z=Li(`Height (${"png"===u.format?"px":"cm"}):`,s);k.appendChild(z);const $=$i(y(u.height,u.format),.1,1e4,.1,s);$.addEventListener("input",t=>{const e=parseFloat(t.target.value);isNaN(e)||e<=0||(u.height=x(e,u.format),u.width=u.height*d,P.value=y(u.width,u.format))}),k.appendChild($),t.appendChild(k);const E=Ti(),A=Li(`Margin (${"png"===u.format?"px":"cm"}):`,s);E.appendChild(A);const N=$i(y(u.margin,u.format),0,100,.1,s);N.addEventListener("input",t=>{const e=parseFloat(t.target.value);isNaN(e)||e<0||(u.margin=x(e,u.format))}),E.appendChild(N),t.appendChild(E)}(x,n,i,L,0,24)}}function z(){M(),d&&(d(),d=null),h=null,c=null,u=null;const t=n();t&&(d=t.subscribe("coordinateChange",T)),w(),r&&k(r)}return b.forEach(t=>{const e=document.createElement("div");e.className="ht-tab",e.textContent=t.label,e.addEventListener("click",()=>{e.classList.contains("disabled")||(r===t.id?(r=null,Object.keys(v).forEach(t=>{v[t].classList.remove("active")}),x.classList.add("hidden"),x.innerHTML=""):P(t.id))}),v[t.id]=e,y.appendChild(e)}),g.addEventListener("click",()=>{p=!p,p?(m.classList.remove("ht-panel-collapsed"),g.classList.remove("collapsed")):(m.classList.add("ht-panel-collapsed"),g.classList.add("collapsed"))}),m.appendChild(y),m.appendChild(x),t.appendChild(f),t.appendChild(m),w(),P(b[0].id),M(),z}function Mi(t,e,n,i,a=!1,s=null){const o=document.createElement("select");if(o.className="ht-select",o.style.height=`${i}px`,o.style.flex="1",a){const t=document.createElement("option");t.value="none",t.textContent="None",o.appendChild(t)}const r=document.createElement("option");r.value="",r.textContent=n,o.appendChild(r);const l=t.state.treeData,h=Array.from(l.columnDisplayName.keys());let c=h;null!==s&&(c=s?h.filter(t=>"continuous"===l.columnType.get(t)):h.filter(t=>"categorical"===l.columnType.get(t))),c.forEach(n=>{const i=document.createElement("option");i.value=n,i.textContent=l.columnDisplayName.get(n),t.state.aesthetics[e]===n&&(i.selected=!0),o.appendChild(i)});const u=t.state.aesthetics[e];return o.value=null===u?"none":void 0===u||""===u?"":u,o.addEventListener("change",n=>{let i;i="none"===n.target.value?null:""===n.target.value?void 0:n.target.value;const a={};a[e]=i,t.setAesthetics(a)}),o}function Ti(){const t=document.createElement("div");return t.className="ht-control-group",t}function Li(t,e){const n=document.createElement("label");return n.className="ht-control-label",n.textContent=t,n.style.height=`${e}px`,n}function Pi(t,e="",n){const i=document.createElement("button");return i.className="ht-button",i.textContent=t,i.title=e,i.style.height=`${n}px`,i}function ki(t,e,n,i,a){const s=document.createElement("input");return s.type="range",s.className="ht-slider",s.min=t,s.max=e,s.value=n,s.step=i,s.style.height=`${a}px`,s}function zi(t,e){const n=Math.min(24,e-4),i=n-4,a=document.createElement("div");a.className=t?"ht-toggle active":"ht-toggle",a.style.height=`${n}px`;const s=document.createElement("div");return s.className="ht-toggle-knob",s.style.width=`${i}px`,s.style.height=`${i}px`,a.appendChild(s),a}function $i(t,e,n,i,a){const s=document.createElement("input");return s.type="number",s.className="ht-number-input",s.value=t,s.min=e,s.max=n,s.step=i,s.style.height=`${a}px`,s}t.heatTree=function(t,e=[],n={}){e&&!Array.isArray(e)&&(e=[e]),null==e&&(e=[]),function(){const t="heat-tree-styles";if(!document.getElementById(t)){const e=document.createElement("style");e.id=t,e.textContent=".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;column-gap:8px;row-gap:2px;align-items:center;min-height:26px}.ht-controls.hidden{display:none}.ht-control-group{display:flex;align-items:center;gap:4px;white-space:nowrap}.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}",document.head.appendChild(e)}}(),n={buttonSize:25,transitionDuration:500,manualZoomAndPanEnabled:!0,autoZoom:"Default",autoPan:"Default",...n};const i=new gi,a=new Map,s=new Map;e.forEach((t,e)=>{if(!t.newick)throw new Error(`Tree at index ${e} is missing newick string`);const n=t.name||`Tree ${e+1}`;let i=[],o=[];if(t.metadata){(Array.isArray(t.metadata)?t.metadata:[t.metadata]).forEach((t,e)=>{t.name&&t.data?(i.push(t.data),o.push(t.name)):(i.push(t),o.push(`Metadata ${e+1}`))})}const r=new pi(t.newick,i,o);let l;l=t.aesthetics?Object.fromEntries(Object.entries(t.aesthetics).map(([t,e])=>{for(const[n,i]of r.columnName.entries())if(i===e)return[t,n]})):void 0,a.set(n,r),s.set(n,l)});const o=new Map,r=new Map,l=document.querySelector(t);if(!l)throw new Error(`Container element not found: ${t}`);const h=document.createElement("div");h.className="ht-widget";const c=document.createElement("div");c.className="ht-toolbar";const u=document.createElement("div");u.className="ht-tree";const d=document.createElementNS("http://www.w3.org/2000/svg","svg");d.setAttribute("width","100%"),d.setAttribute("height","100%"),u.appendChild(d),h.appendChild(c),h.appendChild(u),l.appendChild(h);let p=null,f=null,g=null,m=null;function y(t,e,n=[],i=[]){let s=t,o=1;for(;a.has(s);)s=`${t} (${o})`,o++;const r=new pi(e,n,i);return a.set(s,r),s}function x(t){if(a.has(t)){if(p!==t||!g){for(;d.firstChild;)d.removeChild(d.firstChild);if(!o.has(t)){const e=new mi({treeData:a.get(t),aesthetics:s.get(t),...n},i);o.set(t,e)}if(r.has(t)){r.get(t).reattach(d)}else{const e=o.get(t),i=new _i(e,d,n);r.set(t,i)}p=t,f=o.get(t),g=r.get(t),m&&m()}}else console.error(`Tree not found: ${t}`)}if(new si(u,t=>{g&&g.fitToView()},{debounce:100,immediate:!0}),m=Ci(c,a,()=>f,()=>g,x,y),a.size>0){x(Array.from(a.keys())[0])}return{treeDataInstances:a,treeStateCache:o,treeViewCache:r,getCurrentTreeState:()=>f,getCurrentTreeView:()=>g,getCurrentTreeName:()=>p,switchToTree:x,addNewTree:y,container:h}},Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
2
+ //# sourceMappingURL=heat-tree.umd.min.js.map