phylotree 2.1.7 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/phylotree.js +833 -35
- package/dist/phylotree.min.js +1 -1
- package/package.json +4 -1
- package/src/branches.js +52 -3
- package/src/formats/newick.js +90 -0
- package/src/main.js +86 -3
- package/src/nodes.js +53 -0
- package/src/render/draw.js +62 -5
- package/src/render/edges.js +15 -3
- package/src/render/event-emitter.js +64 -0
- package/src/render/events.js +11 -1
- package/src/render/menus.js +82 -17
- package/src/render/nodes.js +12 -4
- package/src/render/selection-sets.js +259 -0
- package/src/render/styles/phylotree-menus.css +93 -0
- package/src/rooting.js +22 -0
package/dist/phylotree.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("underscore"),require("lodash")):"function"==typeof define&&define.amd?define(["exports","underscore","lodash"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).phylotree=t.phylotree||{},t._,t._$1)}(this,function(t,e,n){"use strict";function r(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}}),e.default=t,Object.freeze(e)}var i=r(e),o=r(n);function s(t,e){return null==t||null==e?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function a(t,e){return null==t||null==e?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function l(t){let e,n,r;function i(t,r,i=0,o=t.length){if(i<o){if(0!==e(r,r))return o;do{const e=i+o>>>1;n(t[e],r)<0?i=e+1:o=e}while(i<o)}return i}return 2!==t.length?(e=s,n=(e,n)=>s(t(e),n),r=(e,n)=>t(e)-n):(e=t===s||t===a?t:u,n=t,r=t),{left:i,center:function(t,e,n=0,o=t.length){const s=i(t,e,n,o-1);return s>n&&r(t[s-1],e)>-r(t[s],e)?s-1:s},right:function(t,r,i=0,o=t.length){if(i<o){if(0!==e(r,r))return o;do{const e=i+o>>>1;n(t[e],r)<=0?i=e+1:o=e}while(i<o)}return i}}}function u(){return 0}const c=l(s).right;l(function(t){return null===t?NaN:+t}).center;var h=c;const f=Math.sqrt(50),d=Math.sqrt(10),p=Math.sqrt(2);function _(t,e,n){const r=(e-t)/Math.max(0,n),i=Math.floor(Math.log10(r)),o=r/Math.pow(10,i),s=o>=f?10:o>=d?5:o>=p?2:1;let a,l,u;return i<0?(u=Math.pow(10,-i)/s,a=Math.round(t*u),l=Math.round(e*u),a/u<t&&++a,l/u>e&&--l,u=-u):(u=Math.pow(10,i)*s,a=Math.round(t/u),l=Math.round(e/u),a*u<t&&++a,l*u>e&&--l),l<a&&.5<=n&&n<2?_(t,e,2*n):[a,l,u]}function g(t,e,n){return _(t=+t,e=+e,n=+n)[2]}function m(t){return t}var v=1e-6;function y(t){return"translate("+t+",0)"}function b(t){return"translate(0,"+t+")"}function x(t){return e=>+t(e)}function w(t,e){return e=Math.max(0,t.bandwidth()-2*e)/2,t.round()&&(e=Math.round(e)),n=>+t(n)+e}function N(){return!this.__axis}function M(t,e){var n=[],r=null,i=null,o=6,s=6,a=3,l="undefined"!=typeof window&&window.devicePixelRatio>1?0:.5,u=1===t||4===t?-1:1,c=4===t||2===t?"x":"y",h=1===t||3===t?y:b;function f(f){var d=null==r?e.ticks?e.ticks.apply(e,n):e.domain():r,p=null==i?e.tickFormat?e.tickFormat.apply(e,n):m:i,_=Math.max(o,0)+a,g=e.range(),y=+g[0]+l,b=+g[g.length-1]+l,M=(e.bandwidth?w:x)(e.copy(),l),T=f.selection?f.selection():f,E=T.selectAll(".domain").data([null]),A=T.selectAll(".tick").data(d,e).order(),k=A.exit(),S=A.enter().append("g").attr("class","tick"),C=A.select("line"),z=A.select("text");E=E.merge(E.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),A=A.merge(S),C=C.merge(S.append("line").attr("stroke","currentColor").attr(c+"2",u*o)),z=z.merge(S.append("text").attr("fill","currentColor").attr(c,u*_).attr("dy",1===t?"0em":3===t?"0.71em":"0.32em")),f!==T&&(E=E.transition(f),A=A.transition(f),C=C.transition(f),z=z.transition(f),k=k.transition(f).attr("opacity",v).attr("transform",function(t){return isFinite(t=M(t))?h(t+l):this.getAttribute("transform")}),S.attr("opacity",v).attr("transform",function(t){var e=this.parentNode.__axis;return h((e&&isFinite(e=e(t))?e:M(t))+l)})),k.remove(),E.attr("d",4===t||2===t?s?"M"+u*s+","+y+"H"+l+"V"+b+"H"+u*s:"M"+l+","+y+"V"+b:s?"M"+y+","+u*s+"V"+l+"H"+b+"V"+u*s:"M"+y+","+l+"H"+b),A.attr("opacity",1).attr("transform",function(t){return h(M(t)+l)}),C.attr(c+"2",u*o),z.attr(c,u*_).text(p),T.filter(N).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",2===t?"start":4===t?"end":"middle"),T.each(function(){this.__axis=M})}return f.scale=function(t){return arguments.length?(e=t,f):e},f.ticks=function(){return n=Array.from(arguments),f},f.tickArguments=function(t){return arguments.length?(n=null==t?[]:Array.from(t),f):n.slice()},f.tickValues=function(t){return arguments.length?(r=null==t?null:Array.from(t),f):r&&r.slice()},f.tickFormat=function(t){return arguments.length?(i=t,f):i},f.tickSize=function(t){return arguments.length?(o=s=+t,f):o},f.tickSizeInner=function(t){return arguments.length?(o=+t,f):o},f.tickSizeOuter=function(t){return arguments.length?(s=+t,f):s},f.tickPadding=function(t){return arguments.length?(a=+t,f):a},f.offset=function(t){return arguments.length?(l=+t,f):l},f}var T={value:()=>{}};function E(){for(var t,e=0,n=arguments.length,r={};e<n;++e){if(!(t=arguments[e]+"")||t in r||/[\s.]/.test(t))throw new Error("illegal type: "+t);r[t]=[]}return new A(r)}function A(t){this._=t}function k(t,e){for(var n,r=0,i=t.length;r<i;++r)if((n=t[r]).name===e)return n.value}function S(t,e,n){for(var r=0,i=t.length;r<i;++r)if(t[r].name===e){t[r]=T,t=t.slice(0,r).concat(t.slice(r+1));break}return null!=n&&t.push({name:e,value:n}),t}A.prototype=E.prototype={constructor:A,on:function(t,e){var n,r,i=this._,o=(r=i,(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&&!r.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:e}})),s=-1,a=o.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++s<a;)if(n=(t=o[s]).type)i[n]=S(i[n],t.name,e);else if(null==e)for(n in i)i[n]=S(i[n],t.name,null);return this}for(;++s<a;)if((n=(t=o[s]).type)&&(n=k(i[n],t.name)))return n},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new A(t)},call:function(t,e){if((n=arguments.length-2)>0)for(var n,r,i=new Array(n),o=0;o<n;++o)i[o]=arguments[o+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(o=0,n=(r=this._[t]).length;o<n;++o)r[o].value.apply(e,i)},apply:function(t,e,n){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var r=this._[t],i=0,o=r.length;i<o;++i)r[i].value.apply(e,n)}};var C="http://www.w3.org/1999/xhtml",z={svg:"http://www.w3.org/2000/svg",xhtml:C,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function D(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),z.hasOwnProperty(e)?{space:z[e],local:t}:t}function $(t){return function(){var e=this.ownerDocument,n=this.namespaceURI;return n===C&&e.documentElement.namespaceURI===C?e.createElement(t):e.createElementNS(n,t)}}function P(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function O(t){var e=D(t);return(e.local?P:$)(e)}function I(){}function L(t){return null==t?I:function(){return this.querySelector(t)}}function U(){return[]}function F(t){return null==t?U:function(){return this.querySelectorAll(t)}}function j(t){return function(){return function(t){return null==t?[]:Array.isArray(t)?t:Array.from(t)}(t.apply(this,arguments))}}function H(t){return function(){return this.matches(t)}}function Y(t){return function(e){return e.matches(t)}}var V=Array.prototype.find;function B(){return this.firstElementChild}var R=Array.prototype.filter;function q(){return Array.from(this.children)}function X(t){return new Array(t.length)}function Z(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function W(t,e,n,r,i,o){for(var s,a=0,l=e.length,u=o.length;a<u;++a)(s=e[a])?(s.__data__=o[a],r[a]=s):n[a]=new Z(t,o[a]);for(;a<l;++a)(s=e[a])&&(i[a]=s)}function G(t,e,n,r,i,o,s){var a,l,u,c=new Map,h=e.length,f=o.length,d=new Array(h);for(a=0;a<h;++a)(l=e[a])&&(d[a]=u=s.call(l,l.__data__,a,e)+"",c.has(u)?i[a]=l:c.set(u,l));for(a=0;a<f;++a)u=s.call(t,o[a],a,o)+"",(l=c.get(u))?(r[a]=l,l.__data__=o[a],c.delete(u)):n[a]=new Z(t,o[a]);for(a=0;a<h;++a)(l=e[a])&&c.get(d[a])===l&&(i[a]=l)}function K(t){return t.__data__}function J(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}function Q(t,e){return t<e?-1:t>e?1:t>=e?0:NaN}function tt(t){return function(){this.removeAttribute(t)}}function et(t){return function(){this.removeAttributeNS(t.space,t.local)}}function nt(t,e){return function(){this.setAttribute(t,e)}}function rt(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function it(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function ot(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 st(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function at(t){return function(){this.style.removeProperty(t)}}function lt(t,e,n){return function(){this.style.setProperty(t,e,n)}}function ut(t,e,n){return function(){var r=e.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,n)}}function ct(t,e){return t.style.getPropertyValue(e)||st(t).getComputedStyle(t,null).getPropertyValue(e)}function ht(t){return function(){delete this[t]}}function ft(t,e){return function(){this[t]=e}}function dt(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function pt(t){return t.trim().split(/^|\s+/)}function _t(t){return t.classList||new gt(t)}function gt(t){this._node=t,this._names=pt(t.getAttribute("class")||"")}function mt(t,e){for(var n=_t(t),r=-1,i=e.length;++r<i;)n.add(e[r])}function vt(t,e){for(var n=_t(t),r=-1,i=e.length;++r<i;)n.remove(e[r])}function yt(t){return function(){mt(this,t)}}function bt(t){return function(){vt(this,t)}}function xt(t,e){return function(){(e.apply(this,arguments)?mt:vt)(this,t)}}function wt(){this.textContent=""}function Nt(t){return function(){this.textContent=t}}function Mt(t){return function(){var e=t.apply(this,arguments);this.textContent=null==e?"":e}}function Tt(){this.innerHTML=""}function Et(t){return function(){this.innerHTML=t}}function At(t){return function(){var e=t.apply(this,arguments);this.innerHTML=null==e?"":e}}function kt(){this.nextSibling&&this.parentNode.appendChild(this)}function St(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Ct(){return null}function zt(){var t=this.parentNode;t&&t.removeChild(this)}function Dt(){var t=this.cloneNode(!1),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function $t(){var t=this.cloneNode(!0),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function Pt(t){return function(){var e=this.__on;if(e){for(var n,r=0,i=-1,o=e.length;r<o;++r)n=e[r],t.type&&n.type!==t.type||n.name!==t.name?e[++i]=n:this.removeEventListener(n.type,n.listener,n.options);++i?e.length=i:delete this.__on}}}function Ot(t,e,n){return function(){var r,i=this.__on,o=function(t){return function(e){t.call(this,e,this.__data__)}}(e);if(i)for(var s=0,a=i.length;s<a;++s)if((r=i[s]).type===t.type&&r.name===t.name)return this.removeEventListener(r.type,r.listener,r.options),this.addEventListener(r.type,r.listener=o,r.options=n),void(r.value=e);this.addEventListener(t.type,o,n),r={type:t.type,name:t.name,value:e,listener:o,options:n},i?i.push(r):this.__on=[r]}}function It(t,e,n){var r=st(t),i=r.CustomEvent;"function"==typeof i?i=new i(e,n):(i=r.document.createEvent("Event"),n?(i.initEvent(e,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(e,!1,!1)),t.dispatchEvent(i)}function Lt(t,e){return function(){return It(this,t,e)}}function Ut(t,e){return function(){return It(this,t,e.apply(this,arguments))}}Z.prototype={constructor:Z,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)}},gt.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 Ft=[null];function jt(t,e){this._groups=t,this._parents=e}function Ht(){return new jt([[document.documentElement]],Ft)}function Yt(t){return"string"==typeof t?new jt([[document.querySelector(t)]],[document.documentElement]):new jt([[t]],Ft)}function Vt(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 r=n.createSVGPoint();return r.x=t.clientX,r.y=t.clientY,[(r=r.matrixTransform(e.getScreenCTM().inverse())).x,r.y]}if(e.getBoundingClientRect){var i=e.getBoundingClientRect();return[t.clientX-i.left-e.clientLeft,t.clientY-i.top-e.clientTop]}}return[t.pageX,t.pageY]}jt.prototype=Ht.prototype={constructor:jt,select:function(t){"function"!=typeof t&&(t=L(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i<n;++i)for(var o,s,a=e[i],l=a.length,u=r[i]=new Array(l),c=0;c<l;++c)(o=a[c])&&(s=t.call(o,o.__data__,c,a))&&("__data__"in o&&(s.__data__=o.__data__),u[c]=s);return new jt(r,this._parents)},selectAll:function(t){t="function"==typeof t?j(t):F(t);for(var e=this._groups,n=e.length,r=[],i=[],o=0;o<n;++o)for(var s,a=e[o],l=a.length,u=0;u<l;++u)(s=a[u])&&(r.push(t.call(s,s.__data__,u,a)),i.push(s));return new jt(r,i)},selectChild:function(t){return this.select(null==t?B:function(t){return function(){return V.call(this.children,t)}}("function"==typeof t?t:Y(t)))},selectChildren:function(t){return this.selectAll(null==t?q:function(t){return function(){return R.call(this.children,t)}}("function"==typeof t?t:Y(t)))},filter:function(t){"function"!=typeof t&&(t=H(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i<n;++i)for(var o,s=e[i],a=s.length,l=r[i]=[],u=0;u<a;++u)(o=s[u])&&t.call(o,o.__data__,u,s)&&l.push(o);return new jt(r,this._parents)},data:function(t,e){if(!arguments.length)return Array.from(this,K);var n=e?G:W,r=this._parents,i=this._groups;"function"!=typeof t&&(t=function(t){return function(){return t}}(t));for(var o=i.length,s=new Array(o),a=new Array(o),l=new Array(o),u=0;u<o;++u){var c=r[u],h=i[u],f=h.length,d=J(t.call(c,c&&c.__data__,u,r)),p=d.length,_=a[u]=new Array(p),g=s[u]=new Array(p);n(c,h,_,g,l[u]=new Array(f),d,e);for(var m,v,y=0,b=0;y<p;++y)if(m=_[y]){for(y>=b&&(b=y+1);!(v=g[b])&&++b<p;);m._next=v||null}}return(s=new jt(s,r))._enter=a,s._exit=l,s},enter:function(){return new jt(this._enter||this._groups.map(X),this._parents)},exit:function(){return new jt(this._exit||this._groups.map(X),this._parents)},join:function(t,e,n){var r=this.enter(),i=this,o=this.exit();return"function"==typeof t?(r=t(r))&&(r=r.selection()):r=r.append(t+""),null!=e&&(i=e(i))&&(i=i.selection()),null==n?o.remove():n(o),r&&i?r.merge(i).order():i},merge:function(t){for(var e=t.selection?t.selection():t,n=this._groups,r=e._groups,i=n.length,o=r.length,s=Math.min(i,o),a=new Array(i),l=0;l<s;++l)for(var u,c=n[l],h=r[l],f=c.length,d=a[l]=new Array(f),p=0;p<f;++p)(u=c[p]||h[p])&&(d[p]=u);for(;l<i;++l)a[l]=n[l];return new jt(a,this._parents)},selection:function(){return this},order:function(){for(var t=this._groups,e=-1,n=t.length;++e<n;)for(var r,i=t[e],o=i.length-1,s=i[o];--o>=0;)(r=i[o])&&(s&&4^r.compareDocumentPosition(s)&&s.parentNode.insertBefore(r,s),s=r);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=Q);for(var n=this._groups,r=n.length,i=new Array(r),o=0;o<r;++o){for(var s,a=n[o],l=a.length,u=i[o]=new Array(l),c=0;c<l;++c)(s=a[c])&&(u[c]=s);u.sort(e)}return new jt(i,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 r=t[e],i=0,o=r.length;i<o;++i){var s=r[i];if(s)return s}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,r=e.length;n<r;++n)for(var i,o=e[n],s=0,a=o.length;s<a;++s)(i=o[s])&&t.call(i,i.__data__,s,o);return this},attr:function(t,e){var n=D(t);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((null==e?n.local?et:tt:"function"==typeof e?n.local?ot:it:n.local?rt:nt)(n,e))},style:function(t,e,n){return arguments.length>1?this.each((null==e?at:"function"==typeof e?ut:lt)(t,e,null==n?"":n)):ct(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?ht:"function"==typeof e?dt:ft)(t,e)):this.node()[t]},classed:function(t,e){var n=pt(t+"");if(arguments.length<2){for(var r=_t(this.node()),i=-1,o=n.length;++i<o;)if(!r.contains(n[i]))return!1;return!0}return this.each(("function"==typeof e?xt:e?yt:bt)(n,e))},text:function(t){return arguments.length?this.each(null==t?wt:("function"==typeof t?Mt:Nt)(t)):this.node().textContent},html:function(t){return arguments.length?this.each(null==t?Tt:("function"==typeof t?At:Et)(t)):this.node().innerHTML},raise:function(){return this.each(kt)},lower:function(){return this.each(St)},append:function(t){var e="function"==typeof t?t:O(t);return this.select(function(){return this.appendChild(e.apply(this,arguments))})},insert:function(t,e){var n="function"==typeof t?t:O(t),r=null==e?Ct:"function"==typeof e?e:L(e);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})},remove:function(){return this.each(zt)},clone:function(t){return this.select(t?$t:Dt)},datum:function(t){return arguments.length?this.property("__data__",t):this.node().__data__},on:function(t,e,n){var r,i,o=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+""),s=o.length;if(!(arguments.length<2)){for(a=e?Ot:Pt,r=0;r<s;++r)this.each(a(o[r],e,n));return this}var a=this.node().__on;if(a)for(var l,u=0,c=a.length;u<c;++u)for(r=0,l=a[u];r<s;++r)if((i=o[r]).type===l.type&&i.name===l.name)return l.value},dispatch:function(t,e){return this.each(("function"==typeof e?Ut:Lt)(t,e))},[Symbol.iterator]:function*(){for(var t=this._groups,e=0,n=t.length;e<n;++e)for(var r,i=t[e],o=0,s=i.length;o<s;++o)(r=i[o])&&(yield r)}};const Bt={capture:!0,passive:!1};function Rt(t){t.preventDefault(),t.stopImmediatePropagation()}function qt(t){var e=t.document.documentElement,n=Yt(t).on("dragstart.drag",Rt,Bt);"onselectstart"in e?n.on("selectstart.drag",Rt,Bt):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}function Xt(t,e){var n=t.document.documentElement,r=Yt(t).on("dragstart.drag",null);e&&(r.on("click.drag",Rt,Bt),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in n?r.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}function Zt(t,e,n){t.prototype=e.prototype=n,n.constructor=t}function Wt(t,e){var n=Object.create(t.prototype);for(var r in e)n[r]=e[r];return n}function Gt(){}var Kt=.7,Jt=1/Kt,Qt="\\s*([+-]?\\d+)\\s*",te="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",ee="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",ne=/^#([0-9a-f]{3,8})$/,re=new RegExp(`^rgb\\(${Qt},${Qt},${Qt}\\)$`),ie=new RegExp(`^rgb\\(${ee},${ee},${ee}\\)$`),oe=new RegExp(`^rgba\\(${Qt},${Qt},${Qt},${te}\\)$`),se=new RegExp(`^rgba\\(${ee},${ee},${ee},${te}\\)$`),ae=new RegExp(`^hsl\\(${te},${ee},${ee}\\)$`),le=new RegExp(`^hsla\\(${te},${ee},${ee},${te}\\)$`),ue={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 ce(){return this.rgb().formatHex()}function he(){return this.rgb().formatRgb()}function fe(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=ne.exec(t))?(n=e[1].length,e=parseInt(e[1],16),6===n?de(e):3===n?new ge(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?pe(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?pe(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=re.exec(t))?new ge(e[1],e[2],e[3],1):(e=ie.exec(t))?new ge(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=oe.exec(t))?pe(e[1],e[2],e[3],e[4]):(e=se.exec(t))?pe(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=ae.exec(t))?we(e[1],e[2]/100,e[3]/100,1):(e=le.exec(t))?we(e[1],e[2]/100,e[3]/100,e[4]):ue.hasOwnProperty(t)?de(ue[t]):"transparent"===t?new ge(NaN,NaN,NaN,0):null}function de(t){return new ge(t>>16&255,t>>8&255,255&t,1)}function pe(t,e,n,r){return r<=0&&(t=e=n=NaN),new ge(t,e,n,r)}function _e(t,e,n,r){return 1===arguments.length?((i=t)instanceof Gt||(i=fe(i)),i?new ge((i=i.rgb()).r,i.g,i.b,i.opacity):new ge):new ge(t,e,n,null==r?1:r);var i}function ge(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}function me(){return`#${xe(this.r)}${xe(this.g)}${xe(this.b)}`}function ve(){const t=ye(this.opacity);return`${1===t?"rgb(":"rgba("}${be(this.r)}, ${be(this.g)}, ${be(this.b)}${1===t?")":`, ${t})`}`}function ye(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function be(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function xe(t){return((t=be(t))<16?"0":"")+t.toString(16)}function we(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new Me(t,e,n,r)}function Ne(t){if(t instanceof Me)return new Me(t.h,t.s,t.l,t.opacity);if(t instanceof Gt||(t=fe(t)),!t)return new Me;if(t instanceof Me)return t;var e=(t=t.rgb()).r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),o=Math.max(e,n,r),s=NaN,a=o-i,l=(o+i)/2;return a?(s=e===o?(n-r)/a+6*(n<r):n===o?(r-e)/a+2:(e-n)/a+4,a/=l<.5?o+i:2-o-i,s*=60):a=l>0&&l<1?0:s,new Me(s,a,l,t.opacity)}function Me(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}function Te(t){return(t=(t||0)%360)<0?t+360:t}function Ee(t){return Math.max(0,Math.min(1,t||0))}function Ae(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}Zt(Gt,fe,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:ce,formatHex:ce,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return Ne(this).formatHsl()},formatRgb:he,toString:he}),Zt(ge,_e,Wt(Gt,{brighter(t){return t=null==t?Jt:Math.pow(Jt,t),new ge(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?Kt:Math.pow(Kt,t),new ge(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new ge(be(this.r),be(this.g),be(this.b),ye(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:me,formatHex:me,formatHex8:function(){return`#${xe(this.r)}${xe(this.g)}${xe(this.b)}${xe(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:ve,toString:ve})),Zt(Me,function(t,e,n,r){return 1===arguments.length?Ne(t):new Me(t,e,n,null==r?1:r)},Wt(Gt,{brighter(t){return t=null==t?Jt:Math.pow(Jt,t),new Me(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?Kt:Math.pow(Kt,t),new Me(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,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new ge(Ae(t>=240?t-240:t+120,i,r),Ae(t,i,r),Ae(t<120?t+240:t-120,i,r),this.opacity)},clamp(){return new Me(Te(this.h),Ee(this.s),Ee(this.l),ye(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=ye(this.opacity);return`${1===t?"hsl(":"hsla("}${Te(this.h)}, ${100*Ee(this.s)}%, ${100*Ee(this.l)}%${1===t?")":`, ${t})`}`}}));var ke=t=>()=>t;function Se(t){return 1===(t=+t)?Ce: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(r){return Math.pow(t+r*e,n)}}(e,n,t):ke(isNaN(e)?n:e)}}function Ce(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):ke(isNaN(t)?e:t)}var ze=function t(e){var n=Se(e);function r(t,e){var r=n((t=_e(t)).r,(e=_e(e)).r),i=n(t.g,e.g),o=n(t.b,e.b),s=Ce(t.opacity,e.opacity);return function(e){return t.r=r(e),t.g=i(e),t.b=o(e),t.opacity=s(e),t+""}}return r.gamma=t,r}(1);function De(t,e){e||(e=[]);var n,r=t?Math.min(e.length,t.length):0,i=e.slice();return function(o){for(n=0;n<r;++n)i[n]=t[n]*(1-o)+e[n]*o;return i}}function $e(t,e){var n,r=e?e.length:0,i=t?Math.min(r,t.length):0,o=new Array(i),s=new Array(r);for(n=0;n<i;++n)o[n]=je(t[n],e[n]);for(;n<r;++n)s[n]=e[n];return function(t){for(n=0;n<i;++n)s[n]=o[n](t);return s}}function Pe(t,e){var n=new Date;return t=+t,e=+e,function(r){return n.setTime(t*(1-r)+e*r),n}}function Oe(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}function Ie(t,e){var n,r={},i={};for(n in null!==t&&"object"==typeof t||(t={}),null!==e&&"object"==typeof e||(e={}),e)n in t?r[n]=je(t[n],e[n]):i[n]=e[n];return function(t){for(n in r)i[n]=r[n](t);return i}}var Le=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Ue=new RegExp(Le.source,"g");function Fe(t,e){var n,r,i,o=Le.lastIndex=Ue.lastIndex=0,s=-1,a=[],l=[];for(t+="",e+="";(n=Le.exec(t))&&(r=Ue.exec(e));)(i=r.index)>o&&(i=e.slice(o,i),a[s]?a[s]+=i:a[++s]=i),(n=n[0])===(r=r[0])?a[s]?a[s]+=r:a[++s]=r:(a[++s]=null,l.push({i:s,x:Oe(n,r)})),o=Ue.lastIndex;return o<e.length&&(i=e.slice(o),a[s]?a[s]+=i:a[++s]=i),a.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,r=0;r<e;++r)a[(n=l[r]).i]=n.x(t);return a.join("")})}function je(t,e){var n,r=typeof e;return null==e||"boolean"===r?ke(e):("number"===r?Oe:"string"===r?(n=fe(e))?(e=n,ze):Fe:e instanceof fe?ze:e instanceof Date?Pe:function(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}(e)?De:Array.isArray(e)?$e:"function"!=typeof e.valueOf&&"function"!=typeof e.toString||isNaN(e)?Ie:Oe)(t,e)}function He(t,e){return t=+t,e=+e,function(n){return Math.round(t*(1-n)+e*n)}}var Ye,Ve=180/Math.PI,Be={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Re(t,e,n,r,i,o){var s,a,l;return(s=Math.sqrt(t*t+e*e))&&(t/=s,e/=s),(l=t*n+e*r)&&(n-=t*l,r-=e*l),(a=Math.sqrt(n*n+r*r))&&(n/=a,r/=a,l/=a),t*r<e*n&&(t=-t,e=-e,l=-l,s=-s),{translateX:i,translateY:o,rotate:Math.atan2(e,t)*Ve,skewX:Math.atan(l)*Ve,scaleX:s,scaleY:a}}function qe(t,e,n,r){function i(t){return t.length?t.pop()+" ":""}return function(o,s){var a=[],l=[];return o=t(o),s=t(s),function(t,r,i,o,s,a){if(t!==i||r!==o){var l=s.push("translate(",null,e,null,n);a.push({i:l-4,x:Oe(t,i)},{i:l-2,x:Oe(r,o)})}else(i||o)&&s.push("translate("+i+e+o+n)}(o.translateX,o.translateY,s.translateX,s.translateY,a,l),function(t,e,n,o){t!==e?(t-e>180?e+=360:e-t>180&&(t+=360),o.push({i:n.push(i(n)+"rotate(",null,r)-2,x:Oe(t,e)})):e&&n.push(i(n)+"rotate("+e+r)}(o.rotate,s.rotate,a,l),function(t,e,n,o){t!==e?o.push({i:n.push(i(n)+"skewX(",null,r)-2,x:Oe(t,e)}):e&&n.push(i(n)+"skewX("+e+r)}(o.skewX,s.skewX,a,l),function(t,e,n,r,o,s){if(t!==n||e!==r){var a=o.push(i(o)+"scale(",null,",",null,")");s.push({i:a-4,x:Oe(t,n)},{i:a-2,x:Oe(e,r)})}else 1===n&&1===r||o.push(i(o)+"scale("+n+","+r+")")}(o.scaleX,o.scaleY,s.scaleX,s.scaleY,a,l),o=s=null,function(t){for(var e,n=-1,r=l.length;++n<r;)a[(e=l[n]).i]=e.x(t);return a.join("")}}}var Xe=qe(function(t){const e=new("function"==typeof DOMMatrix?DOMMatrix:WebKitCSSMatrix)(t+"");return e.isIdentity?Be:Re(e.a,e.b,e.c,e.d,e.e,e.f)},"px, ","px)","deg)"),Ze=qe(function(t){return null==t?Be:(Ye||(Ye=document.createElementNS("http://www.w3.org/2000/svg","g")),Ye.setAttribute("transform",t),(t=Ye.transform.baseVal.consolidate())?Re((t=t.matrix).a,t.b,t.c,t.d,t.e,t.f):Be)},", ",")",")");function We(t){return((t=Math.exp(t))+1/t)/2}var Ge,Ke,Je=function t(e,n,r){function i(t,i){var o,s,a=t[0],l=t[1],u=t[2],c=i[0],h=i[1],f=i[2],d=c-a,p=h-l,_=d*d+p*p;if(_<1e-12)s=Math.log(f/u)/e,o=function(t){return[a+t*d,l+t*p,u*Math.exp(e*t*s)]};else{var g=Math.sqrt(_),m=(f*f-u*u+r*_)/(2*u*n*g),v=(f*f-u*u-r*_)/(2*f*n*g),y=Math.log(Math.sqrt(m*m+1)-m),b=Math.log(Math.sqrt(v*v+1)-v);s=(b-y)/e,o=function(t){var r=t*s,i=We(y),o=u/(n*g)*(i*function(t){return((t=Math.exp(2*t))-1)/(t+1)}(e*r+y)-function(t){return((t=Math.exp(t))-1/t)/2}(y));return[a+o*d,l+o*p,u*i/We(e*r+y)]}}return o.duration=1e3*s*e/Math.SQRT2,o}return i.rho=function(e){var n=Math.max(.001,+e),r=n*n;return t(n,r,r*r)},i}(Math.SQRT2,2,4),Qe=0,tn=0,en=0,nn=0,rn=0,on=0,sn="object"==typeof performance&&performance.now?performance:Date,an="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function ln(){return rn||(an(un),rn=sn.now()+on)}function un(){rn=0}function cn(){this._call=this._time=this._next=null}function hn(t,e,n){var r=new cn;return r.restart(t,e,n),r}function fn(){rn=(nn=sn.now())+on,Qe=tn=0;try{!function(){ln(),++Qe;for(var t,e=Ge;e;)(t=rn-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Qe}()}finally{Qe=0,function(){var t,e,n=Ge,r=1/0;for(;n;)n._call?(r>n._time&&(r=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:Ge=e);Ke=t,pn(r)}(),rn=0}}function dn(){var t=sn.now(),e=t-nn;e>1e3&&(on-=e,nn=t)}function pn(t){Qe||(tn&&(tn=clearTimeout(tn)),t-rn>24?(t<1/0&&(tn=setTimeout(fn,t-sn.now()-on)),en&&(en=clearInterval(en))):(en||(nn=sn.now(),en=setInterval(dn,1e3)),Qe=1,an(fn)))}function _n(t,e,n){var r=new cn;return e=null==e?0:+e,r.restart(n=>{r.stop(),t(n+e)},e,n),r}cn.prototype=hn.prototype={constructor:cn,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?ln():+n)+(null==e?0:+e),this._next||Ke===this||(Ke?Ke._next=this:Ge=this,Ke=this),this._call=t,this._time=n,pn()},stop:function(){this._call&&(this._call=null,this._time=1/0,pn())}};var gn=E("start","end","cancel","interrupt"),mn=[];function vn(t,e,n,r,i,o){var s=t.__transition;if(s){if(n in s)return}else t.__transition={};!function(t,e,n){var r,i=t.__transition;function o(t){n.state=1,n.timer.restart(s,n.delay,n.time),n.delay<=t&&s(t-n.delay)}function s(o){var u,c,h,f;if(1!==n.state)return l();for(u in i)if((f=i[u]).name===n.name){if(3===f.state)return _n(s);4===f.state?(f.state=6,f.timer.stop(),f.on.call("interrupt",t,t.__data__,f.index,f.group),delete i[u]):+u<e&&(f.state=6,f.timer.stop(),f.on.call("cancel",t,t.__data__,f.index,f.group),delete i[u])}if(_n(function(){3===n.state&&(n.state=4,n.timer.restart(a,n.delay,n.time),a(o))}),n.state=2,n.on.call("start",t,t.__data__,n.index,n.group),2===n.state){for(n.state=3,r=new Array(h=n.tween.length),u=0,c=-1;u<h;++u)(f=n.tween[u].value.call(t,t.__data__,n.index,n.group))&&(r[++c]=f);r.length=c+1}}function a(e){for(var i=e<n.duration?n.ease.call(null,e/n.duration):(n.timer.restart(l),n.state=5,1),o=-1,s=r.length;++o<s;)r[o].call(t,i);5===n.state&&(n.on.call("end",t,t.__data__,n.index,n.group),l())}function l(){for(var r in n.state=6,n.timer.stop(),delete i[e],i)return;delete t.__transition}i[e]=n,n.timer=hn(o,0,n.time)}(t,n,{name:e,index:r,group:i,on:gn,tween:mn,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:0})}function yn(t,e){var n=xn(t,e);if(n.state>0)throw new Error("too late; already scheduled");return n}function bn(t,e){var n=xn(t,e);if(n.state>3)throw new Error("too late; already running");return n}function xn(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function wn(t,e){var n,r,i,o=t.__transition,s=!0;if(o){for(i in e=null==e?null:e+"",o)(n=o[i]).name===e?(r=n.state>2&&n.state<5,n.state=6,n.timer.stop(),n.on.call(r?"interrupt":"cancel",t,t.__data__,n.index,n.group),delete o[i]):s=!1;s&&delete t.__transition}}function Nn(t,e){var n,r;return function(){var i=bn(this,t),o=i.tween;if(o!==n)for(var s=0,a=(r=n=o).length;s<a;++s)if(r[s].name===e){(r=r.slice()).splice(s,1);break}i.tween=r}}function Mn(t,e,n){var r,i;if("function"!=typeof n)throw new Error;return function(){var o=bn(this,t),s=o.tween;if(s!==r){i=(r=s).slice();for(var a={name:e,value:n},l=0,u=i.length;l<u;++l)if(i[l].name===e){i[l]=a;break}l===u&&i.push(a)}o.tween=i}}function Tn(t,e,n){var r=t._id;return t.each(function(){var t=bn(this,r);(t.value||(t.value={}))[e]=n.apply(this,arguments)}),function(t){return xn(t,r).value[e]}}function En(t,e){var n;return("number"==typeof e?Oe:e instanceof fe?ze:(n=fe(e))?(e=n,ze):Fe)(t,e)}function An(t){return function(){this.removeAttribute(t)}}function kn(t){return function(){this.removeAttributeNS(t.space,t.local)}}function Sn(t,e,n){var r,i,o=n+"";return function(){var s=this.getAttribute(t);return s===o?null:s===r?i:i=e(r=s,n)}}function Cn(t,e,n){var r,i,o=n+"";return function(){var s=this.getAttributeNS(t.space,t.local);return s===o?null:s===r?i:i=e(r=s,n)}}function zn(t,e,n){var r,i,o;return function(){var s,a,l=n(this);if(null!=l)return(s=this.getAttribute(t))===(a=l+"")?null:s===r&&a===i?o:(i=a,o=e(r=s,l));this.removeAttribute(t)}}function Dn(t,e,n){var r,i,o;return function(){var s,a,l=n(this);if(null!=l)return(s=this.getAttributeNS(t.space,t.local))===(a=l+"")?null:s===r&&a===i?o:(i=a,o=e(r=s,l));this.removeAttributeNS(t.space,t.local)}}function $n(t,e){var n,r;function i(){var i=e.apply(this,arguments);return i!==r&&(n=(r=i)&&function(t,e){return function(n){this.setAttributeNS(t.space,t.local,e.call(this,n))}}(t,i)),n}return i._value=e,i}function Pn(t,e){var n,r;function i(){var i=e.apply(this,arguments);return i!==r&&(n=(r=i)&&function(t,e){return function(n){this.setAttribute(t,e.call(this,n))}}(t,i)),n}return i._value=e,i}function On(t,e){return function(){yn(this,t).delay=+e.apply(this,arguments)}}function In(t,e){return e=+e,function(){yn(this,t).delay=e}}function Ln(t,e){return function(){bn(this,t).duration=+e.apply(this,arguments)}}function Un(t,e){return e=+e,function(){bn(this,t).duration=e}}var Fn=Ht.prototype.constructor;function jn(t){return function(){this.style.removeProperty(t)}}var Hn=0;function Yn(t,e,n,r){this._groups=t,this._parents=e,this._name=n,this._id=r}function Vn(){return++Hn}var Bn=Ht.prototype;Yn.prototype={constructor:Yn,select:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=L(t));for(var r=this._groups,i=r.length,o=new Array(i),s=0;s<i;++s)for(var a,l,u=r[s],c=u.length,h=o[s]=new Array(c),f=0;f<c;++f)(a=u[f])&&(l=t.call(a,a.__data__,f,u))&&("__data__"in a&&(l.__data__=a.__data__),h[f]=l,vn(h[f],e,n,f,h,xn(a,n)));return new Yn(o,this._parents,e,n)},selectAll:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=F(t));for(var r=this._groups,i=r.length,o=[],s=[],a=0;a<i;++a)for(var l,u=r[a],c=u.length,h=0;h<c;++h)if(l=u[h]){for(var f,d=t.call(l,l.__data__,h,u),p=xn(l,n),_=0,g=d.length;_<g;++_)(f=d[_])&&vn(f,e,n,_,d,p);o.push(d),s.push(l)}return new Yn(o,s,e,n)},selectChild:Bn.selectChild,selectChildren:Bn.selectChildren,filter:function(t){"function"!=typeof t&&(t=H(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i<n;++i)for(var o,s=e[i],a=s.length,l=r[i]=[],u=0;u<a;++u)(o=s[u])&&t.call(o,o.__data__,u,s)&&l.push(o);return new Yn(r,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,r=e.length,i=n.length,o=Math.min(r,i),s=new Array(r),a=0;a<o;++a)for(var l,u=e[a],c=n[a],h=u.length,f=s[a]=new Array(h),d=0;d<h;++d)(l=u[d]||c[d])&&(f[d]=l);for(;a<r;++a)s[a]=e[a];return new Yn(s,this._parents,this._name,this._id)},selection:function(){return new Fn(this._groups,this._parents)},transition:function(){for(var t=this._name,e=this._id,n=Vn(),r=this._groups,i=r.length,o=0;o<i;++o)for(var s,a=r[o],l=a.length,u=0;u<l;++u)if(s=a[u]){var c=xn(s,e);vn(s,t,n,u,a,{time:c.time+c.delay+c.duration,delay:0,duration:c.duration,ease:c.ease})}return new Yn(r,this._parents,t,n)},call:Bn.call,nodes:Bn.nodes,node:Bn.node,size:Bn.size,empty:Bn.empty,each:Bn.each,on:function(t,e){var n=this._id;return arguments.length<2?xn(this.node(),n).on.on(t):this.each(function(t,e,n){var r,i,o=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)?yn:bn;return function(){var s=o(this,t),a=s.on;a!==r&&(i=(r=a).copy()).on(e,n),s.on=i}}(n,t,e))},attr:function(t,e){var n=D(t),r="transform"===n?Ze:En;return this.attrTween(t,"function"==typeof e?(n.local?Dn:zn)(n,r,Tn(this,"attr."+t,e)):null==e?(n.local?kn:An)(n):(n.local?Cn:Sn)(n,r,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 r=D(t);return this.tween(n,(r.local?$n:Pn)(r,e))},style:function(t,e,n){var r="transform"==(t+="")?Xe:En;return null==e?this.styleTween(t,function(t,e){var n,r,i;return function(){var o=ct(this,t),s=(this.style.removeProperty(t),ct(this,t));return o===s?null:o===n&&s===r?i:i=e(n=o,r=s)}}(t,r)).on("end.style."+t,jn(t)):"function"==typeof e?this.styleTween(t,function(t,e,n){var r,i,o;return function(){var s=ct(this,t),a=n(this),l=a+"";return null==a&&(this.style.removeProperty(t),l=a=ct(this,t)),s===l?null:s===r&&l===i?o:(i=l,o=e(r=s,a))}}(t,r,Tn(this,"style."+t,e))).each(function(t,e){var n,r,i,o,s="style."+e,a="end."+s;return function(){var l=bn(this,t),u=l.on,c=null==l.value[s]?o||(o=jn(e)):void 0;u===n&&i===c||(r=(n=u).copy()).on(a,i=c),l.on=r}}(this._id,t)):this.styleTween(t,function(t,e,n){var r,i,o=n+"";return function(){var s=ct(this,t);return s===o?null:s===r?i:i=e(r=s,n)}}(t,r,e),n).on("end.style."+t,null)},styleTween:function(t,e,n){var r="style."+(t+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(null==e)return this.tween(r,null);if("function"!=typeof e)throw new Error;return this.tween(r,function(t,e,n){var r,i;function o(){var o=e.apply(this,arguments);return o!==i&&(r=(i=o)&&function(t,e,n){return function(r){this.style.setProperty(t,e.call(this,r),n)}}(t,o,n)),r}return o._value=e,o}(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}}(Tn(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 r(){var r=t.apply(this,arguments);return r!==n&&(e=(n=r)&&function(t){return function(e){this.textContent=t.call(this,e)}}(r)),e}return r._value=t,r}(t))},remove:function(){return this.on("end.remove",function(t){return function(){var e=this.parentNode;for(var n in this.__transition)if(+n!==t)return;e&&e.removeChild(this)}}(this._id))},tween:function(t,e){var n=this._id;if(t+="",arguments.length<2){for(var r,i=xn(this.node(),n).tween,o=0,s=i.length;o<s;++o)if((r=i[o]).name===t)return r.value;return null}return this.each((null==e?Nn:Mn)(n,t,e))},delay:function(t){var e=this._id;return arguments.length?this.each(("function"==typeof t?On:In)(e,t)):xn(this.node(),e).delay},duration:function(t){var e=this._id;return arguments.length?this.each(("function"==typeof t?Ln:Un)(e,t)):xn(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(){bn(this,t).ease=e}}(e,t)):xn(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;bn(this,t).ease=n}}(this._id,t))},end:function(){var t,e,n=this,r=n._id,i=n.size();return new Promise(function(o,s){var a={value:s},l={value:function(){0===--i&&o()}};n.each(function(){var n=bn(this,r),i=n.on;i!==t&&((e=(t=i).copy())._.cancel.push(a),e._.interrupt.push(a),e._.end.push(l)),n.on=e}),0===i&&o()})},[Symbol.iterator]:Bn[Symbol.iterator]};var Rn={time:null,delay:0,duration:250,ease:function(t){return((t*=2)<=1?t*t*t:(t-=2)*t*t+2)/2}};function qn(t,e){for(var n;!(n=t.__transition)||!(n=n[e]);)if(!(t=t.parentNode))throw new Error(`transition ${e} not found`);return n}Ht.prototype.interrupt=function(t){return this.each(function(){wn(this,t)})},Ht.prototype.transition=function(t){var e,n;t instanceof Yn?(e=t._id,t=t._name):(e=Vn(),(n=Rn).time=ln(),t=null==t?null:t+"");for(var r=this._groups,i=r.length,o=0;o<i;++o)for(var s,a=r[o],l=a.length,u=0;u<l;++u)(s=a[u])&&vn(s,t,e,u,a,n||qn(s,e));return new Yn(r,this._parents,t,e)};var Xn=t=>()=>t;function Zn(t,{sourceEvent:e,target:n,selection:r,mode:i,dispatch:o}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},selection:{value:r,enumerable:!0,configurable:!0},mode:{value:i,enumerable:!0,configurable:!0},_:{value:o}})}function Wn(t){t.preventDefault(),t.stopImmediatePropagation()}var Gn={name:"drag"},Kn={name:"space"},Jn={name:"handle"},Qn={name:"center"};const{abs:tr,max:er,min:nr}=Math;function rr(t){return[+t[0],+t[1]]}function ir(t){return[rr(t[0]),rr(t[1])]}var or={name:"x",handles:["w","e"].map(dr),input:function(t,e){return null==t?null:[[+t[0],e[0][1]],[+t[1],e[1][1]]]},output:function(t){return t&&[t[0][0],t[1][0]]}},sr={name:"y",handles:["n","s"].map(dr),input:function(t,e){return null==t?null:[[e[0][0],+t[0]],[e[1][0],+t[1]]]},output:function(t){return t&&[t[0][1],t[1][1]]}},ar={name:"xy",handles:["n","w","e","s","nw","ne","sw","se"].map(dr),input:function(t){return null==t?null:ir(t)},output:function(t){return t}},lr={overlay:"crosshair",selection:"move",n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"},ur={e:"w",w:"e",nw:"ne",ne:"nw",se:"sw",sw:"se"},cr={n:"s",s:"n",nw:"sw",ne:"se",se:"ne",sw:"nw"},hr={overlay:1,selection:1,n:null,e:1,s:null,w:-1,nw:-1,ne:1,se:1,sw:-1},fr={overlay:1,selection:1,n:-1,e:null,s:1,w:null,nw:-1,ne:-1,se:1,sw:1};function dr(t){return{type:t}}function pr(t){return!t.ctrlKey&&!t.button}function _r(){var t=this.ownerSVGElement||this;return 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]]}function gr(){return navigator.maxTouchPoints||"ontouchstart"in this}function mr(t){for(;!t.__brush;)if(!(t=t.parentNode))return;return t.__brush}function vr(){return function(t){var e,n=_r,r=pr,i=gr,o=!0,s=E("start","brush","end"),a=6;function l(e){var n=e.property("__brush",_).selectAll(".overlay").data([dr("overlay")]);n.enter().append("rect").attr("class","overlay").attr("pointer-events","all").attr("cursor",lr.overlay).merge(n).each(function(){var t=mr(this).extent;Yt(this).attr("x",t[0][0]).attr("y",t[0][1]).attr("width",t[1][0]-t[0][0]).attr("height",t[1][1]-t[0][1])}),e.selectAll(".selection").data([dr("selection")]).enter().append("rect").attr("class","selection").attr("cursor",lr.selection).attr("fill","#777").attr("fill-opacity",.3).attr("stroke","#fff").attr("shape-rendering","crispEdges");var r=e.selectAll(".handle").data(t.handles,function(t){return t.type});r.exit().remove(),r.enter().append("rect").attr("class",function(t){return"handle handle--"+t.type}).attr("cursor",function(t){return lr[t.type]}),e.each(u).attr("fill","none").attr("pointer-events","all").on("mousedown.brush",f).filter(i).on("touchstart.brush",f).on("touchmove.brush",d).on("touchend.brush touchcancel.brush",p).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function u(){var t=Yt(this),e=mr(this).selection;e?(t.selectAll(".selection").style("display",null).attr("x",e[0][0]).attr("y",e[0][1]).attr("width",e[1][0]-e[0][0]).attr("height",e[1][1]-e[0][1]),t.selectAll(".handle").style("display",null).attr("x",function(t){return"e"===t.type[t.type.length-1]?e[1][0]-a/2:e[0][0]-a/2}).attr("y",function(t){return"s"===t.type[0]?e[1][1]-a/2:e[0][1]-a/2}).attr("width",function(t){return"n"===t.type||"s"===t.type?e[1][0]-e[0][0]+a:a}).attr("height",function(t){return"e"===t.type||"w"===t.type?e[1][1]-e[0][1]+a:a})):t.selectAll(".selection,.handle").style("display","none").attr("x",null).attr("y",null).attr("width",null).attr("height",null)}function c(t,e,n){var r=t.__brush.emitter;return!r||n&&r.clean?new h(t,e,n):r}function h(t,e,n){this.that=t,this.args=e,this.state=t.__brush,this.active=0,this.clean=n}function f(n){if((!e||n.touches)&&r.apply(this,arguments)){var i,s,a,l,h,f,d,p,_,g,m,v=this,y=n.target.__data__.type,b="selection"===(o&&n.metaKey?y="overlay":y)?Gn:o&&n.altKey?Qn:Jn,x=t===sr?null:hr[y],w=t===or?null:fr[y],N=mr(v),M=N.extent,T=N.selection,E=M[0][0],A=M[0][1],k=M[1][0],S=M[1][1],C=0,z=0,D=x&&w&&o&&n.shiftKey,$=Array.from(n.touches||[n],t=>{const e=t.identifier;return(t=Vt(t,v)).point0=t.slice(),t.identifier=e,t});wn(v);var P=c(v,arguments,!0).beforestart();if("overlay"===y){T&&(_=!0);const e=[$[0],$[1]||$[0]];N.selection=T=[[i=t===sr?E:nr(e[0][0],e[1][0]),a=t===or?A:nr(e[0][1],e[1][1])],[h=t===sr?k:er(e[0][0],e[1][0]),d=t===or?S:er(e[0][1],e[1][1])]],$.length>1&&F(n)}else i=T[0][0],a=T[0][1],h=T[1][0],d=T[1][1];s=i,l=a,f=h,p=d;var O=Yt(v).attr("pointer-events","none"),I=O.selectAll(".overlay").attr("cursor",lr[y]);if(n.touches)P.moved=U,P.ended=j;else{var L=Yt(n.view).on("mousemove.brush",U,!0).on("mouseup.brush",j,!0);o&&L.on("keydown.brush",H,!0).on("keyup.brush",Y,!0),qt(n.view)}u.call(v),P.start(n,b.name)}function U(t){for(const e of t.changedTouches||[t])for(const t of $)t.identifier===e.identifier&&(t.cur=Vt(e,v));if(D&&!g&&!m&&1===$.length){const t=$[0];tr(t.cur[0]-t[0])>tr(t.cur[1]-t[1])?m=!0:g=!0}for(const t of $)t.cur&&(t[0]=t.cur[0],t[1]=t.cur[1]);_=!0,Wn(t),F(t)}function F(t){const e=$[0],n=e.point0;var r;switch(C=e[0]-n[0],z=e[1]-n[1],b){case Kn:case Gn:x&&(C=er(E-i,nr(k-h,C)),s=i+C,f=h+C),w&&(z=er(A-a,nr(S-d,z)),l=a+z,p=d+z);break;case Jn:$[1]?(x&&(s=er(E,nr(k,$[0][0])),f=er(E,nr(k,$[1][0])),x=1),w&&(l=er(A,nr(S,$[0][1])),p=er(A,nr(S,$[1][1])),w=1)):(x<0?(C=er(E-i,nr(k-i,C)),s=i+C,f=h):x>0&&(C=er(E-h,nr(k-h,C)),s=i,f=h+C),w<0?(z=er(A-a,nr(S-a,z)),l=a+z,p=d):w>0&&(z=er(A-d,nr(S-d,z)),l=a,p=d+z));break;case Qn:x&&(s=er(E,nr(k,i-C*x)),f=er(E,nr(k,h+C*x))),w&&(l=er(A,nr(S,a-z*w)),p=er(A,nr(S,d+z*w)))}f<s&&(x*=-1,r=i,i=h,h=r,r=s,s=f,f=r,y in ur&&I.attr("cursor",lr[y=ur[y]])),p<l&&(w*=-1,r=a,a=d,d=r,r=l,l=p,p=r,y in cr&&I.attr("cursor",lr[y=cr[y]])),N.selection&&(T=N.selection),g&&(s=T[0][0],f=T[1][0]),m&&(l=T[0][1],p=T[1][1]),T[0][0]===s&&T[0][1]===l&&T[1][0]===f&&T[1][1]===p||(N.selection=[[s,l],[f,p]],u.call(v),P.brush(t,b.name))}function j(t){if(function(t){t.stopImmediatePropagation()}(t),t.touches){if(t.touches.length)return;e&&clearTimeout(e),e=setTimeout(function(){e=null},500)}else Xt(t.view,_),L.on("keydown.brush keyup.brush mousemove.brush mouseup.brush",null);O.attr("pointer-events","all"),I.attr("cursor",lr.overlay),N.selection&&(T=N.selection),function(t){return t[0][0]===t[1][0]||t[0][1]===t[1][1]}(T)&&(N.selection=null,u.call(v)),P.end(t,b.name)}function H(t){switch(t.keyCode){case 16:D=x&&w;break;case 18:b===Jn&&(x&&(h=f-C*x,i=s+C*x),w&&(d=p-z*w,a=l+z*w),b=Qn,F(t));break;case 32:b!==Jn&&b!==Qn||(x<0?h=f-C:x>0&&(i=s-C),w<0?d=p-z:w>0&&(a=l-z),b=Kn,I.attr("cursor",lr.selection),F(t));break;default:return}Wn(t)}function Y(t){switch(t.keyCode){case 16:D&&(g=m=D=!1,F(t));break;case 18:b===Qn&&(x<0?h=f:x>0&&(i=s),w<0?d=p:w>0&&(a=l),b=Jn,F(t));break;case 32:b===Kn&&(t.altKey?(x&&(h=f-C*x,i=s+C*x),w&&(d=p-z*w,a=l+z*w),b=Qn):(x<0?h=f:x>0&&(i=s),w<0?d=p:w>0&&(a=l),b=Jn),I.attr("cursor",lr[y]),F(t));break;default:return}Wn(t)}}function d(t){c(this,arguments).moved(t)}function p(t){c(this,arguments).ended(t)}function _(){var e=this.__brush||{selection:null};return e.extent=ir(n.apply(this,arguments)),e.dim=t,e}return l.move=function(e,n,r){e.tween?e.on("start.brush",function(t){c(this,arguments).beforestart().start(t)}).on("interrupt.brush end.brush",function(t){c(this,arguments).end(t)}).tween("brush",function(){var e=this,r=e.__brush,i=c(e,arguments),o=r.selection,s=t.input("function"==typeof n?n.apply(this,arguments):n,r.extent),a=je(o,s);function l(t){r.selection=1===t&&null===s?null:a(t),u.call(e),i.brush()}return null!==o&&null!==s?l:l(1)}):e.each(function(){var e=this,i=arguments,o=e.__brush,s=t.input("function"==typeof n?n.apply(e,i):n,o.extent),a=c(e,i).beforestart();wn(e),o.selection=null===s?null:s,u.call(e),a.start(r).brush(r).end(r)})},l.clear=function(t,e){l.move(t,null,e)},h.prototype={beforestart:function(){return 1===++this.active&&(this.state.emitter=this,this.starting=!0),this},start:function(t,e){return this.starting?(this.starting=!1,this.emit("start",t,e)):this.emit("brush",t),this},brush:function(t,e){return this.emit("brush",t,e),this},end:function(t,e){return 0===--this.active&&(delete this.state.emitter,this.emit("end",t,e)),this},emit:function(e,n,r){var i=Yt(this.that).datum();s.call(e,this.that,new Zn(e,{sourceEvent:n,target:l,selection:t.output(this.state.selection),mode:r,dispatch:s}),i)}},l.extent=function(t){return arguments.length?(n="function"==typeof t?t:Xn(ir(t)),l):n},l.filter=function(t){return arguments.length?(r="function"==typeof t?t:Xn(!!t),l):r},l.touchable=function(t){return arguments.length?(i="function"==typeof t?t:Xn(!!t),l):i},l.handleSize=function(t){return arguments.length?(a=+t,l):a},l.keyModifiers=function(t){return arguments.length?(o=!!t,l):o},l.on=function(){var t=s.on.apply(s,arguments);return t===s?l:t},l}(ar)}const yr=Math.PI,br=2*yr,xr=1e-6,wr=br-xr;function Nr(t){this._+=t[0];for(let e=1,n=t.length;e<n;++e)this._+=arguments[e]+t[e]}class Mr{constructor(t){this._x0=this._y0=this._x1=this._y1=null,this._="",this._append=null==t?Nr:function(t){let e=Math.floor(t);if(!(e>=0))throw new Error(`invalid digits: ${t}`);if(e>15)return Nr;const n=10**e;return function(t){this._+=t[0];for(let e=1,r=t.length;e<r;++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,r){this._append`Q${+t},${+e},${this._x1=+n},${this._y1=+r}`}bezierCurveTo(t,e,n,r,i,o){this._append`C${+t},${+e},${+n},${+r},${this._x1=+i},${this._y1=+o}`}arcTo(t,e,n,r,i){if(t=+t,e=+e,n=+n,r=+r,(i=+i)<0)throw new Error(`negative radius: ${i}`);let o=this._x1,s=this._y1,a=n-t,l=r-e,u=o-t,c=s-e,h=u*u+c*c;if(null===this._x1)this._append`M${this._x1=t},${this._y1=e}`;else if(h>xr)if(Math.abs(c*a-l*u)>xr&&i){let f=n-o,d=r-s,p=a*a+l*l,_=f*f+d*d,g=Math.sqrt(p),m=Math.sqrt(h),v=i*Math.tan((yr-Math.acos((p+h-_)/(2*g*m)))/2),y=v/m,b=v/g;Math.abs(y-1)>xr&&this._append`L${t+y*u},${e+y*c}`,this._append`A${i},${i},0,0,${+(c*f>u*d)},${this._x1=t+b*a},${this._y1=e+b*l}`}else this._append`L${this._x1=t},${this._y1=e}`;else;}arc(t,e,n,r,i,o){if(t=+t,e=+e,o=!!o,(n=+n)<0)throw new Error(`negative radius: ${n}`);let s=n*Math.cos(r),a=n*Math.sin(r),l=t+s,u=e+a,c=1^o,h=o?r-i:i-r;null===this._x1?this._append`M${l},${u}`:(Math.abs(this._x1-l)>xr||Math.abs(this._y1-u)>xr)&&this._append`L${l},${u}`,n&&(h<0&&(h=h%br+br),h>wr?this._append`A${n},${n},0,1,${c},${t-s},${e-a}A${n},${n},0,1,${c},${this._x1=l},${this._y1=u}`:h>xr&&this._append`A${n},${n},0,${+(h>=yr)},${c},${this._x1=t+n*Math.cos(i)},${this._y1=e+n*Math.sin(i)}`)}rect(t,e,n,r){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${n=+n}v${+r}h${-n}Z`}toString(){return this._}}function Tr(t,e){if((n=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var n,r=t.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+t.slice(n+1)]}function Er(t){return(t=Tr(Math.abs(t)))?t[1]:NaN}var Ar,kr=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Sr(t){if(!(e=kr.exec(t)))throw new Error("invalid format: "+t);var e;return new Cr({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}function Cr(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}function zr(t,e){var n=Tr(t,e);if(!n)return t+"";var r=n[0],i=n[1];return i<0?"0."+new Array(-i).join("0")+r:r.length>i+1?r.slice(0,i+1)+"."+r.slice(i+1):r+new Array(i-r.length+2).join("0")}Sr.prototype=Cr.prototype,Cr.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};var Dr={"%":(t,e)=>(100*t).toFixed(e),b:t=>Math.round(t).toString(2),c:t=>t+"",d:function(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)},e:(t,e)=>t.toExponential(e),f:(t,e)=>t.toFixed(e),g:(t,e)=>t.toPrecision(e),o:t=>Math.round(t).toString(8),p:(t,e)=>zr(100*t,e),r:zr,s:function(t,e){var n=Tr(t,e);if(!n)return t+"";var r=n[0],i=n[1],o=i-(Ar=3*Math.max(-8,Math.min(8,Math.floor(i/3))))+1,s=r.length;return o===s?r:o>s?r+new Array(o-s+1).join("0"):o>0?r.slice(0,o)+"."+r.slice(o):"0."+new Array(1-o).join("0")+Tr(t,Math.max(0,e+o-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function $r(t){return t}var Pr,Or,Ir,Lr=Array.prototype.map,Ur=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Fr(t){var e,n,r=void 0===t.grouping||void 0===t.thousands?$r:(e=Lr.call(t.grouping,Number),n=t.thousands+"",function(t,r){for(var i=t.length,o=[],s=0,a=e[0],l=0;i>0&&a>0&&(l+a+1>r&&(a=Math.max(1,r-l)),o.push(t.substring(i-=a,i+a)),!((l+=a+1)>r));)a=e[s=(s+1)%e.length];return o.reverse().join(n)}),i=void 0===t.currency?"":t.currency[0]+"",o=void 0===t.currency?"":t.currency[1]+"",s=void 0===t.decimal?".":t.decimal+"",a=void 0===t.numerals?$r:function(t){return function(e){return e.replace(/[0-9]/g,function(e){return t[+e]})}}(Lr.call(t.numerals,String)),l=void 0===t.percent?"%":t.percent+"",u=void 0===t.minus?"−":t.minus+"",c=void 0===t.nan?"NaN":t.nan+"";function h(t){var e=(t=Sr(t)).fill,n=t.align,h=t.sign,f=t.symbol,d=t.zero,p=t.width,_=t.comma,g=t.precision,m=t.trim,v=t.type;"n"===v?(_=!0,v="g"):Dr[v]||(void 0===g&&(g=12),m=!0,v="g"),(d||"0"===e&&"="===n)&&(d=!0,e="0",n="=");var y="$"===f?i:"#"===f&&/[boxX]/.test(v)?"0"+v.toLowerCase():"",b="$"===f?o:/[%p]/.test(v)?l:"",x=Dr[v],w=/[defgprs%]/.test(v);function N(t){var i,o,l,f=y,N=b;if("c"===v)N=x(t)+N,t="";else{var M=(t=+t)<0||1/t<0;if(t=isNaN(t)?c:x(Math.abs(t),g),m&&(t=function(t){t:for(var e,n=t.length,r=1,i=-1;r<n;++r)switch(t[r]){case".":i=e=r;break;case"0":0===i&&(i=r),e=r;break;default:if(!+t[r])break t;i>0&&(i=0)}return i>0?t.slice(0,i)+t.slice(e+1):t}(t)),M&&0===+t&&"+"!==h&&(M=!1),f=(M?"("===h?h:u:"-"===h||"("===h?"":h)+f,N=("s"===v?Ur[8+Ar/3]:"")+N+(M&&"("===h?")":""),w)for(i=-1,o=t.length;++i<o;)if(48>(l=t.charCodeAt(i))||l>57){N=(46===l?s+t.slice(i+1):t.slice(i))+N,t=t.slice(0,i);break}}_&&!d&&(t=r(t,1/0));var T=f.length+t.length+N.length,E=T<p?new Array(p-T+1).join(e):"";switch(_&&d&&(t=r(E+t,E.length?p-N.length:1/0),E=""),n){case"<":t=f+t+N+E;break;case"=":t=f+E+t+N;break;case"^":t=E.slice(0,T=E.length>>1)+f+t+N+E.slice(T);break;default:t=E+f+t+N}return a(t)}return g=void 0===g?6:/[gprs]/.test(v)?Math.max(1,Math.min(21,g)):Math.max(0,Math.min(20,g)),N.toString=function(){return t+""},N}return{format:h,formatPrefix:function(t,e){var n=h(((t=Sr(t)).type="f",t)),r=3*Math.max(-8,Math.min(8,Math.floor(Er(e)/3))),i=Math.pow(10,-r),o=Ur[8+r/3];return function(t){return n(i*t)+o}}}}function jr(t){var e=0,n=t.children,r=n&&n.length;if(r)for(;--r>=0;)e+=n[r].value;else e=1;t.value=e}function Hr(t,e){t instanceof Map?(t=[void 0,t],void 0===e&&(e=Vr)):void 0===e&&(e=Yr);for(var n,r,i,o,s,a=new qr(t),l=[a];n=l.pop();)if((i=e(n.data))&&(s=(i=Array.from(i)).length))for(n.children=i,o=s-1;o>=0;--o)l.push(r=i[o]=new qr(i[o])),r.parent=n,r.depth=n.depth+1;return a.eachBefore(Rr)}function Yr(t){return t.children}function Vr(t){return Array.isArray(t)?t[1]:null}function Br(t){void 0!==t.data.value&&(t.value=t.data.value),t.data=t.data.data}function Rr(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function qr(t){this.data=t,this.depth=this.height=0,this.parent=null}function Xr(t,e){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(e).domain(t)}return this}function Zr(t){return+t}Pr=Fr({thousands:",",grouping:[3],currency:["$",""]}),Or=Pr.format,Ir=Pr.formatPrefix,qr.prototype=Hr.prototype={constructor:qr,count:function(){return this.eachAfter(jr)},each:function(t,e){let n=-1;for(const r of this)t.call(e,r,++n,this);return this},eachAfter:function(t,e){for(var n,r,i,o=this,s=[o],a=[],l=-1;o=s.pop();)if(a.push(o),n=o.children)for(r=0,i=n.length;r<i;++r)s.push(n[r]);for(;o=a.pop();)t.call(e,o,++l,this);return this},eachBefore:function(t,e){for(var n,r,i=this,o=[i],s=-1;i=o.pop();)if(t.call(e,i,++s,this),n=i.children)for(r=n.length-1;r>=0;--r)o.push(n[r]);return this},find:function(t,e){let n=-1;for(const r of this)if(t.call(e,r,++n,this))return r},sum:function(t){return this.eachAfter(function(e){for(var n=+t(e.data)||0,r=e.children,i=r&&r.length;--i>=0;)n+=r[i].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(),r=e.ancestors(),i=null;t=n.pop(),e=r.pop();for(;t===e;)i=t,t=n.pop(),e=r.pop();return i}(e,t),r=[e];e!==n;)e=e.parent,r.push(e);for(var i=r.length;t!==n;)r.splice(i,0,t),t=t.parent;return r},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 Hr(this).eachBefore(Br)},[Symbol.iterator]:function*(){var t,e,n,r,i=this,o=[i];do{for(t=o.reverse(),o=[];i=t.pop();)if(yield i,e=i.children)for(n=0,r=e.length;n<r;++n)o.push(e[n])}while(o.length)}};var Wr=[0,1];function Gr(t){return t}function Kr(t,e){return(e-=t=+t)?function(n){return(n-t)/e}:function(t){return function(){return t}}(isNaN(e)?NaN:.5)}function Jr(t,e,n){var r=t[0],i=t[1],o=e[0],s=e[1];return i<r?(r=Kr(i,r),o=n(s,o)):(r=Kr(r,i),o=n(o,s)),function(t){return o(r(t))}}function Qr(t,e,n){var r=Math.min(t.length,e.length)-1,i=new Array(r),o=new Array(r),s=-1;for(t[r]<t[0]&&(t=t.slice().reverse(),e=e.slice().reverse());++s<r;)i[s]=Kr(t[s],t[s+1]),o[s]=n(e[s],e[s+1]);return function(e){var n=h(t,e,1,r)-1;return o[n](i[n](e))}}function ti(){var t,e,n,r,i,o,s=Wr,a=Wr,l=je,u=Gr;function c(){var t,e,n,l=Math.min(s.length,a.length);return u!==Gr&&(t=s[0],e=s[l-1],t>e&&(n=t,t=e,e=n),u=function(n){return Math.max(t,Math.min(e,n))}),r=l>2?Qr:Jr,i=o=null,h}function h(e){return null==e||isNaN(e=+e)?n:(i||(i=r(s.map(t),a,l)))(t(u(e)))}return h.invert=function(n){return u(e((o||(o=r(a,s.map(t),Oe)))(n)))},h.domain=function(t){return arguments.length?(s=Array.from(t,Zr),c()):s.slice()},h.range=function(t){return arguments.length?(a=Array.from(t),c()):a.slice()},h.rangeRound=function(t){return a=Array.from(t),l=He,c()},h.clamp=function(t){return arguments.length?(u=!!t||Gr,c()):u!==Gr},h.interpolate=function(t){return arguments.length?(l=t,c()):l},h.unknown=function(t){return arguments.length?(n=t,h):n},function(n,r){return t=n,e=r,c()}}function ei(t,e,n,r){var i,o=function(t,e,n){n=+n;const r=(e=+e)<(t=+t),i=r?g(e,t,n):g(t,e,n);return(r?-1:1)*(i<0?1/-i:i)}(t,e,n);switch((r=Sr(null==r?",f":r)).type){case"s":var s=Math.max(Math.abs(t),Math.abs(e));return null!=r.precision||isNaN(i=function(t,e){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(Er(e)/3)))-Er(Math.abs(t)))}(o,s))||(r.precision=i),Ir(r,s);case"":case"e":case"g":case"p":case"r":null!=r.precision||isNaN(i=function(t,e){return t=Math.abs(t),e=Math.abs(e)-t,Math.max(0,Er(e)-Er(t))+1}(o,Math.max(Math.abs(t),Math.abs(e))))||(r.precision=i-("e"===r.type));break;case"f":case"%":null!=r.precision||isNaN(i=function(t){return Math.max(0,-Er(Math.abs(t)))}(o))||(r.precision=i-2*("%"===r.type))}return Or(r)}function ni(t){var e=t.domain;return t.ticks=function(t){var n=e();return function(t,e,n){if(!((n=+n)>0))return[];if((t=+t)===(e=+e))return[t];const r=e<t,[i,o,s]=r?_(e,t,n):_(t,e,n);if(!(o>=i))return[];const a=o-i+1,l=new Array(a);if(r)if(s<0)for(let t=0;t<a;++t)l[t]=(o-t)/-s;else for(let t=0;t<a;++t)l[t]=(o-t)*s;else if(s<0)for(let t=0;t<a;++t)l[t]=(i+t)/-s;else for(let t=0;t<a;++t)l[t]=(i+t)*s;return l}(n[0],n[n.length-1],null==t?10:t)},t.tickFormat=function(t,n){var r=e();return ei(r[0],r[r.length-1],null==t?10:t,n)},t.nice=function(n){null==n&&(n=10);var r,i,o=e(),s=0,a=o.length-1,l=o[s],u=o[a],c=10;for(u<l&&(i=l,l=u,u=i,i=s,s=a,a=i);c-- >0;){if((i=g(l,u,n))===r)return o[s]=l,o[a]=u,e(o);if(i>0)l=Math.floor(l/i)*i,u=Math.ceil(u/i)*i;else{if(!(i<0))break;l=Math.ceil(l*i)/i,u=Math.floor(u*i)/i}r=i}return t},t}function ri(){var t=ti()(Gr,Gr);return t.copy=function(){return e=t,ri().domain(e.domain()).range(e.range()).interpolate(e.interpolate()).clamp(e.clamp()).unknown(e.unknown());var e},Xr.apply(t,arguments),ni(t)}const ii=new Date,oi=new Date;function si(t,e,n,r){function i(e){return t(e=0===arguments.length?new Date:new Date(+e)),e}return i.floor=e=>(t(e=new Date(+e)),e),i.ceil=n=>(t(n=new Date(n-1)),e(n,1),t(n),n),i.round=t=>{const e=i(t),n=i.ceil(t);return t-e<n-t?e:n},i.offset=(t,n)=>(e(t=new Date(+t),null==n?1:Math.floor(n)),t),i.range=(n,r,o)=>{const s=[];if(n=i.ceil(n),o=null==o?1:Math.floor(o),!(n<r&&o>0))return s;let a;do{s.push(a=new Date(+n)),e(n,o),t(n)}while(a<n&&n<r);return s},i.filter=n=>si(e=>{if(e>=e)for(;t(e),!n(e);)e.setTime(e-1)},(t,r)=>{if(t>=t)if(r<0)for(;++r<=0;)for(;e(t,-1),!n(t););else for(;--r>=0;)for(;e(t,1),!n(t););}),n&&(i.count=(e,r)=>(ii.setTime(+e),oi.setTime(+r),t(ii),t(oi),Math.floor(n(ii,oi))),i.every=t=>(t=Math.floor(t),isFinite(t)&&t>0?t>1?i.filter(r?e=>r(e)%t===0:e=>i.count(0,e)%t===0):i:null)),i}const ai=6e4,li=864e5,ui=6048e5,ci=si(t=>t.setHours(0,0,0,0),(t,e)=>t.setDate(t.getDate()+e),(t,e)=>(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*ai)/li,t=>t.getDate()-1);ci.range;const hi=si(t=>{t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+e)},(t,e)=>(e-t)/li,t=>t.getUTCDate()-1);hi.range;const fi=si(t=>{t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+e)},(t,e)=>(e-t)/li,t=>Math.floor(t/li));function di(t){return si(e=>{e.setDate(e.getDate()-(e.getDay()+7-t)%7),e.setHours(0,0,0,0)},(t,e)=>{t.setDate(t.getDate()+7*e)},(t,e)=>(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*ai)/ui)}fi.range;const pi=di(0),_i=di(1),gi=di(2),mi=di(3),vi=di(4),yi=di(5),bi=di(6);function xi(t){return si(e=>{e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-t)%7),e.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+7*e)},(t,e)=>(e-t)/ui)}pi.range,_i.range,gi.range,mi.range,vi.range,yi.range,bi.range;const wi=xi(0),Ni=xi(1),Mi=xi(2),Ti=xi(3),Ei=xi(4),Ai=xi(5),ki=xi(6);wi.range,Ni.range,Mi.range,Ti.range,Ei.range,Ai.range,ki.range;const Si=si(t=>{t.setMonth(0,1),t.setHours(0,0,0,0)},(t,e)=>{t.setFullYear(t.getFullYear()+e)},(t,e)=>e.getFullYear()-t.getFullYear(),t=>t.getFullYear());Si.every=t=>isFinite(t=Math.floor(t))&&t>0?si(e=>{e.setFullYear(Math.floor(e.getFullYear()/t)*t),e.setMonth(0,1),e.setHours(0,0,0,0)},(e,n)=>{e.setFullYear(e.getFullYear()+n*t)}):null,Si.range;const Ci=si(t=>{t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCFullYear(t.getUTCFullYear()+e)},(t,e)=>e.getUTCFullYear()-t.getUTCFullYear(),t=>t.getUTCFullYear());function zi(t){if(0<=t.y&&t.y<100){var e=new Date(-1,t.m,t.d,t.H,t.M,t.S,t.L);return e.setFullYear(t.y),e}return new Date(t.y,t.m,t.d,t.H,t.M,t.S,t.L)}function Di(t){if(0<=t.y&&t.y<100){var e=new Date(Date.UTC(-1,t.m,t.d,t.H,t.M,t.S,t.L));return e.setUTCFullYear(t.y),e}return new Date(Date.UTC(t.y,t.m,t.d,t.H,t.M,t.S,t.L))}function $i(t,e,n){return{y:t,m:e,d:n,H:0,M:0,S:0,L:0}}Ci.every=t=>isFinite(t=Math.floor(t))&&t>0?si(e=>{e.setUTCFullYear(Math.floor(e.getUTCFullYear()/t)*t),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,n)=>{e.setUTCFullYear(e.getUTCFullYear()+n*t)}):null,Ci.range;var Pi,Oi,Ii={"-":"",_:" ",0:"0"},Li=/^\s*\d+/,Ui=/^%/,Fi=/[\\^$*+?|[\]().{}]/g;function ji(t,e,n){var r=t<0?"-":"",i=(r?-t:t)+"",o=i.length;return r+(o<n?new Array(n-o+1).join(e)+i:i)}function Hi(t){return t.replace(Fi,"\\$&")}function Yi(t){return new RegExp("^(?:"+t.map(Hi).join("|")+")","i")}function Vi(t){return new Map(t.map((t,e)=>[t.toLowerCase(),e]))}function Bi(t,e,n){var r=Li.exec(e.slice(n,n+1));return r?(t.w=+r[0],n+r[0].length):-1}function Ri(t,e,n){var r=Li.exec(e.slice(n,n+1));return r?(t.u=+r[0],n+r[0].length):-1}function qi(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.U=+r[0],n+r[0].length):-1}function Xi(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.V=+r[0],n+r[0].length):-1}function Zi(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.W=+r[0],n+r[0].length):-1}function Wi(t,e,n){var r=Li.exec(e.slice(n,n+4));return r?(t.y=+r[0],n+r[0].length):-1}function Gi(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function Ki(t,e,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(n,n+6));return r?(t.Z=r[1]?0:-(r[2]+(r[3]||"00")),n+r[0].length):-1}function Ji(t,e,n){var r=Li.exec(e.slice(n,n+1));return r?(t.q=3*r[0]-3,n+r[0].length):-1}function Qi(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.m=r[0]-1,n+r[0].length):-1}function to(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.d=+r[0],n+r[0].length):-1}function eo(t,e,n){var r=Li.exec(e.slice(n,n+3));return r?(t.m=0,t.d=+r[0],n+r[0].length):-1}function no(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.H=+r[0],n+r[0].length):-1}function ro(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.M=+r[0],n+r[0].length):-1}function io(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.S=+r[0],n+r[0].length):-1}function oo(t,e,n){var r=Li.exec(e.slice(n,n+3));return r?(t.L=+r[0],n+r[0].length):-1}function so(t,e,n){var r=Li.exec(e.slice(n,n+6));return r?(t.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function ao(t,e,n){var r=Ui.exec(e.slice(n,n+1));return r?n+r[0].length:-1}function lo(t,e,n){var r=Li.exec(e.slice(n));return r?(t.Q=+r[0],n+r[0].length):-1}function uo(t,e,n){var r=Li.exec(e.slice(n));return r?(t.s=+r[0],n+r[0].length):-1}function co(t,e){return ji(t.getDate(),e,2)}function ho(t,e){return ji(t.getHours(),e,2)}function fo(t,e){return ji(t.getHours()%12||12,e,2)}function po(t,e){return ji(1+ci.count(Si(t),t),e,3)}function _o(t,e){return ji(t.getMilliseconds(),e,3)}function go(t,e){return _o(t,e)+"000"}function mo(t,e){return ji(t.getMonth()+1,e,2)}function vo(t,e){return ji(t.getMinutes(),e,2)}function yo(t,e){return ji(t.getSeconds(),e,2)}function bo(t){var e=t.getDay();return 0===e?7:e}function xo(t,e){return ji(pi.count(Si(t)-1,t),e,2)}function wo(t){var e=t.getDay();return e>=4||0===e?vi(t):vi.ceil(t)}function No(t,e){return t=wo(t),ji(vi.count(Si(t),t)+(4===Si(t).getDay()),e,2)}function Mo(t){return t.getDay()}function To(t,e){return ji(_i.count(Si(t)-1,t),e,2)}function Eo(t,e){return ji(t.getFullYear()%100,e,2)}function Ao(t,e){return ji((t=wo(t)).getFullYear()%100,e,2)}function ko(t,e){return ji(t.getFullYear()%1e4,e,4)}function So(t,e){var n=t.getDay();return ji((t=n>=4||0===n?vi(t):vi.ceil(t)).getFullYear()%1e4,e,4)}function Co(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+ji(e/60|0,"0",2)+ji(e%60,"0",2)}function zo(t,e){return ji(t.getUTCDate(),e,2)}function Do(t,e){return ji(t.getUTCHours(),e,2)}function $o(t,e){return ji(t.getUTCHours()%12||12,e,2)}function Po(t,e){return ji(1+hi.count(Ci(t),t),e,3)}function Oo(t,e){return ji(t.getUTCMilliseconds(),e,3)}function Io(t,e){return Oo(t,e)+"000"}function Lo(t,e){return ji(t.getUTCMonth()+1,e,2)}function Uo(t,e){return ji(t.getUTCMinutes(),e,2)}function Fo(t,e){return ji(t.getUTCSeconds(),e,2)}function jo(t){var e=t.getUTCDay();return 0===e?7:e}function Ho(t,e){return ji(wi.count(Ci(t)-1,t),e,2)}function Yo(t){var e=t.getUTCDay();return e>=4||0===e?Ei(t):Ei.ceil(t)}function Vo(t,e){return t=Yo(t),ji(Ei.count(Ci(t),t)+(4===Ci(t).getUTCDay()),e,2)}function Bo(t){return t.getUTCDay()}function Ro(t,e){return ji(Ni.count(Ci(t)-1,t),e,2)}function qo(t,e){return ji(t.getUTCFullYear()%100,e,2)}function Xo(t,e){return ji((t=Yo(t)).getUTCFullYear()%100,e,2)}function Zo(t,e){return ji(t.getUTCFullYear()%1e4,e,4)}function Wo(t,e){var n=t.getUTCDay();return ji((t=n>=4||0===n?Ei(t):Ei.ceil(t)).getUTCFullYear()%1e4,e,4)}function Go(){return"+0000"}function Ko(){return"%"}function Jo(t){return+t}function Qo(t){return Math.floor(+t/1e3)}function ts(t){return function(){return t}}function es(t){this._context=t}function ns(t){return new es(t)}function rs(t){return t[0]}function is(t){return t[1]}function os(t,e){var n=ts(!0),r=null,i=ns,o=null,s=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 Mr(e)}(a);function a(a){var l,u,c,h=(a=function(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}(a)).length,f=!1;for(null==r&&(o=i(c=s())),l=0;l<=h;++l)!(l<h&&n(u=a[l],l,a))===f&&((f=!f)?o.lineStart():o.lineEnd()),f&&o.point(+t(u,l,a),+e(u,l,a));if(c)return o=null,c+""||null}return t="function"==typeof t?t:void 0===t?rs:ts(t),e="function"==typeof e?e:void 0===e?is:ts(e),a.x=function(e){return arguments.length?(t="function"==typeof e?e:ts(+e),a):t},a.y=function(t){return arguments.length?(e="function"==typeof t?t:ts(+t),a):e},a.defined=function(t){return arguments.length?(n="function"==typeof t?t:ts(!!t),a):n},a.curve=function(t){return arguments.length?(i=t,null!=r&&(o=i(r)),a):i},a.context=function(t){return arguments.length?(null==t?r=o=null:o=i(r=t),a):r},a}function ss(t,e,n){t._context.bezierCurveTo((2*t._x0+t._x1)/3,(2*t._y0+t._y1)/3,(t._x0+2*t._x1)/3,(t._y0+2*t._y1)/3,(t._x0+4*t._x1+e)/6,(t._y0+4*t._y1+n)/6)}function as(t){this._context=t}function ls(t){return new as(t)}function us(t,e){this._context=t,this._t=e}!function(t){Pi=function(t){var e=t.dateTime,n=t.date,r=t.time,i=t.periods,o=t.days,s=t.shortDays,a=t.months,l=t.shortMonths,u=Yi(i),c=Vi(i),h=Yi(o),f=Vi(o),d=Yi(s),p=Vi(s),_=Yi(a),g=Vi(a),m=Yi(l),v=Vi(l),y={a:function(t){return s[t.getDay()]},A:function(t){return o[t.getDay()]},b:function(t){return l[t.getMonth()]},B:function(t){return a[t.getMonth()]},c:null,d:co,e:co,f:go,g:Ao,G:So,H:ho,I:fo,j:po,L:_o,m:mo,M:vo,p:function(t){return i[+(t.getHours()>=12)]},q:function(t){return 1+~~(t.getMonth()/3)},Q:Jo,s:Qo,S:yo,u:bo,U:xo,V:No,w:Mo,W:To,x:null,X:null,y:Eo,Y:ko,Z:Co,"%":Ko},b={a:function(t){return s[t.getUTCDay()]},A:function(t){return o[t.getUTCDay()]},b:function(t){return l[t.getUTCMonth()]},B:function(t){return a[t.getUTCMonth()]},c:null,d:zo,e:zo,f:Io,g:Xo,G:Wo,H:Do,I:$o,j:Po,L:Oo,m:Lo,M:Uo,p:function(t){return i[+(t.getUTCHours()>=12)]},q:function(t){return 1+~~(t.getUTCMonth()/3)},Q:Jo,s:Qo,S:Fo,u:jo,U:Ho,V:Vo,w:Bo,W:Ro,x:null,X:null,y:qo,Y:Zo,Z:Go,"%":Ko},x={a:function(t,e,n){var r=d.exec(e.slice(n));return r?(t.w=p.get(r[0].toLowerCase()),n+r[0].length):-1},A:function(t,e,n){var r=h.exec(e.slice(n));return r?(t.w=f.get(r[0].toLowerCase()),n+r[0].length):-1},b:function(t,e,n){var r=m.exec(e.slice(n));return r?(t.m=v.get(r[0].toLowerCase()),n+r[0].length):-1},B:function(t,e,n){var r=_.exec(e.slice(n));return r?(t.m=g.get(r[0].toLowerCase()),n+r[0].length):-1},c:function(t,n,r){return M(t,e,n,r)},d:to,e:to,f:so,g:Gi,G:Wi,H:no,I:no,j:eo,L:oo,m:Qi,M:ro,p:function(t,e,n){var r=u.exec(e.slice(n));return r?(t.p=c.get(r[0].toLowerCase()),n+r[0].length):-1},q:Ji,Q:lo,s:uo,S:io,u:Ri,U:qi,V:Xi,w:Bi,W:Zi,x:function(t,e,r){return M(t,n,e,r)},X:function(t,e,n){return M(t,r,e,n)},y:Gi,Y:Wi,Z:Ki,"%":ao};function w(t,e){return function(n){var r,i,o,s=[],a=-1,l=0,u=t.length;for(n instanceof Date||(n=new Date(+n));++a<u;)37===t.charCodeAt(a)&&(s.push(t.slice(l,a)),null!=(i=Ii[r=t.charAt(++a)])?r=t.charAt(++a):i="e"===r?" ":"0",(o=e[r])&&(r=o(n,i)),s.push(r),l=a+1);return s.push(t.slice(l,a)),s.join("")}}function N(t,e){return function(n){var r,i,o=$i(1900,void 0,1);if(M(o,t,n+="",0)!=n.length)return null;if("Q"in o)return new Date(o.Q);if("s"in o)return new Date(1e3*o.s+("L"in o?o.L:0));if(e&&!("Z"in o)&&(o.Z=0),"p"in o&&(o.H=o.H%12+12*o.p),void 0===o.m&&(o.m="q"in o?o.q:0),"V"in o){if(o.V<1||o.V>53)return null;"w"in o||(o.w=1),"Z"in o?(i=(r=Di($i(o.y,0,1))).getUTCDay(),r=i>4||0===i?Ni.ceil(r):Ni(r),r=hi.offset(r,7*(o.V-1)),o.y=r.getUTCFullYear(),o.m=r.getUTCMonth(),o.d=r.getUTCDate()+(o.w+6)%7):(i=(r=zi($i(o.y,0,1))).getDay(),r=i>4||0===i?_i.ceil(r):_i(r),r=ci.offset(r,7*(o.V-1)),o.y=r.getFullYear(),o.m=r.getMonth(),o.d=r.getDate()+(o.w+6)%7)}else("W"in o||"U"in o)&&("w"in o||(o.w="u"in o?o.u%7:"W"in o?1:0),i="Z"in o?Di($i(o.y,0,1)).getUTCDay():zi($i(o.y,0,1)).getDay(),o.m=0,o.d="W"in o?(o.w+6)%7+7*o.W-(i+5)%7:o.w+7*o.U-(i+6)%7);return"Z"in o?(o.H+=o.Z/100|0,o.M+=o.Z%100,Di(o)):zi(o)}}function M(t,e,n,r){for(var i,o,s=0,a=e.length,l=n.length;s<a;){if(r>=l)return-1;if(37===(i=e.charCodeAt(s++))){if(i=e.charAt(s++),!(o=x[i in Ii?e.charAt(s++):i])||(r=o(t,n,r))<0)return-1}else if(i!=n.charCodeAt(r++))return-1}return r}return y.x=w(n,y),y.X=w(r,y),y.c=w(e,y),b.x=w(n,b),b.X=w(r,b),b.c=w(e,b),{format:function(t){var e=w(t+="",y);return e.toString=function(){return t},e},parse:function(t){var e=N(t+="",!1);return e.toString=function(){return t},e},utcFormat:function(t){var e=w(t+="",b);return e.toString=function(){return t},e},utcParse:function(t){var e=N(t+="",!0);return e.toString=function(){return t},e}}}(t),Pi.format,Oi=Pi.parse,Pi.utcFormat,Pi.utcParse}({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}),es.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:this._context.lineTo(t,e)}}},as.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:ss(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:ss(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}},us.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN,this._point=0},lineEnd:function(){0<this._t&&this._t<1&&2===this._point&&this._context.lineTo(this._x,this._y),(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line>=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,e),this._context.lineTo(t,e);else{var n=this._x*(1-this._t)+t*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,e)}}this._x=t,this._y=e}};var cs=t=>()=>t;function hs(t,{sourceEvent:e,target:n,transform:r,dispatch:i}){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:r,enumerable:!0,configurable:!0},_:{value:i}})}function fs(t,e,n){this.k=t,this.x=e,this.y=n}fs.prototype={constructor:fs,scale:function(t){return 1===t?this:new fs(this.k*t,this.x,this.y)},translate:function(t,e){return 0===t&0===e?this:new fs(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 ds=new fs(1,0,0);function ps(t){t.stopImmediatePropagation()}function _s(t){t.preventDefault(),t.stopImmediatePropagation()}function gs(t){return!(t.ctrlKey&&"wheel"!==t.type||t.button)}function ms(){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 vs(){return this.__zoom||ds}function ys(t){return-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function bs(){return navigator.maxTouchPoints||"ontouchstart"in this}function xs(t,e,n){var r=t.invertX(e[0][0])-n[0][0],i=t.invertX(e[1][0])-n[1][0],o=t.invertY(e[0][1])-n[0][1],s=t.invertY(e[1][1])-n[1][1];return t.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),s>o?(o+s)/2:Math.min(0,o)||Math.max(0,s))}fs.prototype;const ws=":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",Ns=new RegExp("^"+("["+ws+"]["+(ws+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040")+"]*")+"$");function Ms(t,e){const n=[];let r=e.exec(t);for(;r;){const i=[];i.startIndex=e.lastIndex-r[0].length;const o=r.length;for(let t=0;t<o;t++)i.push(r[t]);n.push(i),r=e.exec(t)}return n}const Ts=function(t){const e=Ns.exec(t);return!(null==e)};const Es={allowBooleanAttributes:!1,unpairedTags:[]};function As(t){return" "===t||"\t"===t||"\n"===t||"\r"===t}function ks(t,e){const n=e;for(;e<t.length;e++)if("?"==t[e]||" "==t[e]){const r=t.substr(n,e-n);if(e>5&&"xml"===r)return Is("InvalidXml","XML declaration allowed only at the start of the document.",Fs(t,e));if("?"==t[e]&&">"==t[e+1]){e++;break}continue}return e}function Ss(t,e){if(t.length>e+5&&"-"===t[e+1]&&"-"===t[e+2]){for(e+=3;e<t.length;e++)if("-"===t[e]&&"-"===t[e+1]&&">"===t[e+2]){e+=2;break}}else if(t.length>e+8&&"D"===t[e+1]&&"O"===t[e+2]&&"C"===t[e+3]&&"T"===t[e+4]&&"Y"===t[e+5]&&"P"===t[e+6]&&"E"===t[e+7]){let n=1;for(e+=8;e<t.length;e++)if("<"===t[e])n++;else if(">"===t[e]&&(n--,0===n))break}else if(t.length>e+9&&"["===t[e+1]&&"C"===t[e+2]&&"D"===t[e+3]&&"A"===t[e+4]&&"T"===t[e+5]&&"A"===t[e+6]&&"["===t[e+7])for(e+=8;e<t.length;e++)if("]"===t[e]&&"]"===t[e+1]&&">"===t[e+2]){e+=2;break}return e}const Cs='"',zs="'";function Ds(t,e){let n="",r="",i=!1;for(;e<t.length;e++){if(t[e]===Cs||t[e]===zs)""===r?r=t[e]:r!==t[e]||(r="");else if(">"===t[e]&&""===r){i=!0;break}n+=t[e]}return""===r&&{value:n,index:e,tagClosed:i}}const $s=new RegExp("(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['\"])(([\\s\\S])*?)\\5)?","g");function Ps(t,e){const n=Ms(t,$s),r={};for(let t=0;t<n.length;t++){if(0===n[t][1].length)return Is("InvalidAttr","Attribute '"+n[t][2]+"' has no space in starting.",js(n[t]));if(void 0!==n[t][3]&&void 0===n[t][4])return Is("InvalidAttr","Attribute '"+n[t][2]+"' is without value.",js(n[t]));if(void 0===n[t][3]&&!e.allowBooleanAttributes)return Is("InvalidAttr","boolean attribute '"+n[t][2]+"' is not allowed.",js(n[t]));const i=n[t][2];if(!Ls(i))return Is("InvalidAttr","Attribute '"+i+"' is an invalid name.",js(n[t]));if(r.hasOwnProperty(i))return Is("InvalidAttr","Attribute '"+i+"' is repeated.",js(n[t]));r[i]=1}return!0}function Os(t,e){if(";"===t[++e])return-1;if("#"===t[e])return function(t,e){let n=/\d/;for("x"===t[e]&&(e++,n=/[\da-fA-F]/);e<t.length;e++){if(";"===t[e])return e;if(!t[e].match(n))break}return-1}(t,++e);let n=0;for(;e<t.length;e++,n++)if(!(t[e].match(/\w/)&&n<20)){if(";"===t[e])break;return-1}return e}function Is(t,e,n){return{err:{code:t,msg:e,line:n.line||n,col:n.col}}}function Ls(t){return Ts(t)}function Us(t){return Ts(t)}function Fs(t,e){const n=t.substring(0,e).split(/\r?\n/);return{line:n.length,col:n[n.length-1].length+1}}function js(t){return t.startIndex+t[1].length}const Hs={preserveOrder:!1,attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(t,e,n){return t},captureMetaData:!1};let Ys;Ys="function"!=typeof Symbol?"@@xmlMetadata":Symbol("XML Node Metadata");class Vs{constructor(t){this.tagname=t,this.child=[],this[":@"]={}}add(t,e){"__proto__"===t&&(t="#__proto__"),this.child.push({[t]:e})}addChild(t,e){"__proto__"===t.tagname&&(t.tagname="#__proto__"),t[":@"]&&Object.keys(t[":@"]).length>0?this.child.push({[t.tagname]:t.child,":@":t[":@"]}):this.child.push({[t.tagname]:t.child}),void 0!==e&&(this.child[this.child.length-1][Ys]={startIndex:e})}static getMetaDataSymbol(){return Ys}}function Bs(t,e){const n={};if("O"!==t[e+3]||"C"!==t[e+4]||"T"!==t[e+5]||"Y"!==t[e+6]||"P"!==t[e+7]||"E"!==t[e+8])throw new Error("Invalid Tag instead of DOCTYPE");{e+=9;let r=1,i=!1,o=!1,s="";for(;e<t.length;e++)if("<"!==t[e]||o)if(">"===t[e]){if(o?"-"===t[e-1]&&"-"===t[e-2]&&(o=!1,r--):r--,0===r)break}else"["===t[e]?i=!0:s+=t[e];else{if(i&&Gs(t,"!ENTITY",e)){let r,i;e+=7,[r,i,e]=qs(t,e+1),-1===i.indexOf("&")&&(n[r]={regx:RegExp(`&${r};`,"g"),val:i})}else if(i&&Gs(t,"!ELEMENT",e)){e+=8;const{index:n}=Ws(t,e+1);e=n}else if(i&&Gs(t,"!ATTLIST",e))e+=8;else if(i&&Gs(t,"!NOTATION",e)){e+=9;const{index:n}=Xs(t,e+1);e=n}else{if(!Gs(t,"!--",e))throw new Error("Invalid DOCTYPE");o=!0}r++,s=""}if(0!==r)throw new Error("Unclosed DOCTYPE")}return{entities:n,i:e}}const Rs=(t,e)=>{for(;e<t.length&&/\s/.test(t[e]);)e++;return e};function qs(t,e){e=Rs(t,e);let n="";for(;e<t.length&&!/\s/.test(t[e])&&'"'!==t[e]&&"'"!==t[e];)n+=t[e],e++;if(Ks(n),e=Rs(t,e),"SYSTEM"===t.substring(e,e+6).toUpperCase())throw new Error("External entities are not supported");if("%"===t[e])throw new Error("Parameter entities are not supported");let r="";return[e,r]=Zs(t,e,"entity"),[n,r,--e]}function Xs(t,e){e=Rs(t,e);let n="";for(;e<t.length&&!/\s/.test(t[e]);)n+=t[e],e++;Ks(n),e=Rs(t,e);const r=t.substring(e,e+6).toUpperCase();if("SYSTEM"!==r&&"PUBLIC"!==r)throw new Error(`Expected SYSTEM or PUBLIC, found "${r}"`);e+=r.length,e=Rs(t,e);let i=null,o=null;if("PUBLIC"===r)[e,i]=Zs(t,e,"publicIdentifier"),'"'!==t[e=Rs(t,e)]&&"'"!==t[e]||([e,o]=Zs(t,e,"systemIdentifier"));else if("SYSTEM"===r&&([e,o]=Zs(t,e,"systemIdentifier"),!o))throw new Error("Missing mandatory system identifier for SYSTEM notation");return{notationName:n,publicIdentifier:i,systemIdentifier:o,index:--e}}function Zs(t,e,n){let r="";const i=t[e];if('"'!==i&&"'"!==i)throw new Error(`Expected quoted string, found "${i}"`);for(e++;e<t.length&&t[e]!==i;)r+=t[e],e++;if(t[e]!==i)throw new Error(`Unterminated ${n} value`);return[++e,r]}function Ws(t,e){e=Rs(t,e);let n="";for(;e<t.length&&!/\s/.test(t[e]);)n+=t[e],e++;if(!Ks(n))throw new Error(`Invalid element name: "${n}"`);let r="";if("E"===t[e=Rs(t,e)]&&Gs(t,"MPTY",e))e+=4;else if("A"===t[e]&&Gs(t,"NY",e))e+=2;else{if("("!==t[e])throw new Error(`Invalid Element Expression, found "${t[e]}"`);for(e++;e<t.length&&")"!==t[e];)r+=t[e],e++;if(")"!==t[e])throw new Error("Unterminated content model")}return{elementName:n,contentModel:r.trim(),index:e}}function Gs(t,e,n){for(let r=0;r<e.length;r++)if(e[r]!==t[n+r+1])return!1;return!0}function Ks(t){if(Ts(t))return t;throw new Error(`Invalid entity name ${t}`)}const Js=/^[-+]?0x[a-fA-F0-9]+$/,Qs=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,ta={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};function ea(t,e={}){if(e=Object.assign({},ta,e),!t||"string"!=typeof t)return t;let n=t.trim();if(void 0!==e.skipLike&&e.skipLike.test(n))return t;if("0"===t)return 0;if(e.hex&&Js.test(n))return function(t,e){if(parseInt)return parseInt(t,e);if(Number.parseInt)return Number.parseInt(t,e);if(window&&window.parseInt)return window.parseInt(t,e);throw new Error("parseInt, Number.parseInt, window.parseInt are not supported")}(n,16);if(-1!==n.search(/.+[eE].+/))return function(t,e,n){if(!n.eNotation)return t;const r=e.match(na);if(r){let i=r[1]||"";const o=-1===r[3].indexOf("e")?"E":"e",s=r[2],a=i?t[s.length+1]===o:t[s.length]===o;return s.length>1&&a?t:1!==s.length||!r[3].startsWith(`.${o}`)&&r[3][0]!==o?n.leadingZeros&&!a?(e=(r[1]||"")+r[3],Number(e)):t:Number(e)}return t}(t,n,e);{const r=Qs.exec(n);if(r){const i=r[1]||"",o=r[2];let s=function(t){if(t&&-1!==t.indexOf("."))return"."===(t=t.replace(/0+$/,""))?t="0":"."===t[0]?t="0"+t:"."===t[t.length-1]&&(t=t.substring(0,t.length-1)),t;return t}(r[3]);const a=i?"."===t[o.length+1]:"."===t[o.length];if(!e.leadingZeros&&(o.length>1||1===o.length&&!a))return t;{const r=Number(n),a=String(r);if(0===r)return r;if(-1!==a.search(/[eE]/))return e.eNotation?r:t;if(-1!==n.indexOf("."))return"0"===a||a===s||a===`${i}${s}`?r:t;let l=o?s:n;return o?l===a||i+l===a?r:t:l===a||l===i+a?r:t}}return t}}const na=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;class ra{constructor(t){var e;this.options=t,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:'"'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"¢"},pound:{regex:/&(pound|#163);/g,val:"£"},yen:{regex:/&(yen|#165);/g,val:"¥"},euro:{regex:/&(euro|#8364);/g,val:"€"},copyright:{regex:/&(copy|#169);/g,val:"©"},reg:{regex:/&(reg|#174);/g,val:"®"},inr:{regex:/&(inr|#8377);/g,val:"₹"},num_dec:{regex:/&#([0-9]{1,7});/g,val:(t,e)=>String.fromCodePoint(Number.parseInt(e,10))},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:(t,e)=>String.fromCodePoint(Number.parseInt(e,16))}},this.addExternalEntities=ia,this.parseXml=ua,this.parseTextData=oa,this.resolveNameSpace=sa,this.buildAttributesMap=la,this.isItStopNode=da,this.replaceEntitiesValue=ha,this.readStopNodeData=ga,this.saveTextToParentTag=fa,this.addChild=ca,this.ignoreAttributesFn="function"==typeof(e=this.options.ignoreAttributes)?e:Array.isArray(e)?t=>{for(const n of e){if("string"==typeof n&&t===n)return!0;if(n instanceof RegExp&&n.test(t))return!0}}:()=>!1}}function ia(t){const e=Object.keys(t);for(let n=0;n<e.length;n++){const r=e[n];this.lastEntities[r]={regex:new RegExp("&"+r+";","g"),val:t[r]}}}function oa(t,e,n,r,i,o,s){if(void 0!==t&&(this.options.trimValues&&!r&&(t=t.trim()),t.length>0)){s||(t=this.replaceEntitiesValue(t));const r=this.options.tagValueProcessor(e,t,n,i,o);if(null==r)return t;if(typeof r!=typeof t||r!==t)return r;if(this.options.trimValues)return ma(t,this.options.parseTagValue,this.options.numberParseOptions);return t.trim()===t?ma(t,this.options.parseTagValue,this.options.numberParseOptions):t}}function sa(t){if(this.options.removeNSPrefix){const e=t.split(":"),n="/"===t.charAt(0)?"/":"";if("xmlns"===e[0])return"";2===e.length&&(t=n+e[1])}return t}const aa=new RegExp("([^\\s=]+)\\s*(=\\s*(['\"])([\\s\\S]*?)\\3)?","gm");function la(t,e,n){if(!0!==this.options.ignoreAttributes&&"string"==typeof t){const n=Ms(t,aa),r=n.length,i={};for(let t=0;t<r;t++){const r=this.resolveNameSpace(n[t][1]);if(this.ignoreAttributesFn(r,e))continue;let o=n[t][4],s=this.options.attributeNamePrefix+r;if(r.length)if(this.options.transformAttributeName&&(s=this.options.transformAttributeName(s)),"__proto__"===s&&(s="#__proto__"),void 0!==o){this.options.trimValues&&(o=o.trim()),o=this.replaceEntitiesValue(o);const t=this.options.attributeValueProcessor(r,o,e);i[s]=null==t?o:typeof t!=typeof o||t!==o?t:ma(o,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(i[s]=!0)}if(!Object.keys(i).length)return;if(this.options.attributesGroupName){const t={};return t[this.options.attributesGroupName]=i,t}return i}}const ua=function(t){t=t.replace(/\r\n?/g,"\n");const e=new Vs("!xml");let n=e,r="",i="";for(let o=0;o<t.length;o++){if("<"===t[o])if("/"===t[o+1]){const e=pa(t,">",o,"Closing Tag is not closed.");let s=t.substring(o+2,e).trim();if(this.options.removeNSPrefix){const t=s.indexOf(":");-1!==t&&(s=s.substr(t+1))}this.options.transformTagName&&(s=this.options.transformTagName(s)),n&&(r=this.saveTextToParentTag(r,n,i));const a=i.substring(i.lastIndexOf(".")+1);if(s&&-1!==this.options.unpairedTags.indexOf(s))throw new Error(`Unpaired tag can not be used as closing tag: </${s}>`);let l=0;a&&-1!==this.options.unpairedTags.indexOf(a)?(l=i.lastIndexOf(".",i.lastIndexOf(".")-1),this.tagsNodeStack.pop()):l=i.lastIndexOf("."),i=i.substring(0,l),n=this.tagsNodeStack.pop(),r="",o=e}else if("?"===t[o+1]){let e=_a(t,o,!1,"?>");if(!e)throw new Error("Pi Tag is not closed.");if(r=this.saveTextToParentTag(r,n,i),this.options.ignoreDeclaration&&"?xml"===e.tagName||this.options.ignorePiTags);else{const t=new Vs(e.tagName);t.add(this.options.textNodeName,""),e.tagName!==e.tagExp&&e.attrExpPresent&&(t[":@"]=this.buildAttributesMap(e.tagExp,i,e.tagName)),this.addChild(n,t,i,o)}o=e.closeIndex+1}else if("!--"===t.substr(o+1,3)){const e=pa(t,"--\x3e",o+4,"Comment is not closed.");if(this.options.commentPropName){const s=t.substring(o+4,e-2);r=this.saveTextToParentTag(r,n,i),n.add(this.options.commentPropName,[{[this.options.textNodeName]:s}])}o=e}else if("!D"===t.substr(o+1,2)){const e=Bs(t,o);this.docTypeEntities=e.entities,o=e.i}else if("!["===t.substr(o+1,2)){const e=pa(t,"]]>",o,"CDATA is not closed.")-2,s=t.substring(o+9,e);r=this.saveTextToParentTag(r,n,i);let a=this.parseTextData(s,n.tagname,i,!0,!1,!0,!0);null==a&&(a=""),this.options.cdataPropName?n.add(this.options.cdataPropName,[{[this.options.textNodeName]:s}]):n.add(this.options.textNodeName,a),o=e+2}else{let s=_a(t,o,this.options.removeNSPrefix),a=s.tagName;const l=s.rawTagName;let u=s.tagExp,c=s.attrExpPresent,h=s.closeIndex;this.options.transformTagName&&(a=this.options.transformTagName(a)),n&&r&&"!xml"!==n.tagname&&(r=this.saveTextToParentTag(r,n,i,!1));const f=n;f&&-1!==this.options.unpairedTags.indexOf(f.tagname)&&(n=this.tagsNodeStack.pop(),i=i.substring(0,i.lastIndexOf("."))),a!==e.tagname&&(i+=i?"."+a:a);const d=o;if(this.isItStopNode(this.options.stopNodes,i,a)){let e="";if(u.length>0&&u.lastIndexOf("/")===u.length-1)"/"===a[a.length-1]?(a=a.substr(0,a.length-1),i=i.substr(0,i.length-1),u=a):u=u.substr(0,u.length-1),o=s.closeIndex;else if(-1!==this.options.unpairedTags.indexOf(a))o=s.closeIndex;else{const n=this.readStopNodeData(t,l,h+1);if(!n)throw new Error(`Unexpected end of ${l}`);o=n.i,e=n.tagContent}const r=new Vs(a);a!==u&&c&&(r[":@"]=this.buildAttributesMap(u,i,a)),e&&(e=this.parseTextData(e,a,i,!0,c,!0,!0)),i=i.substr(0,i.lastIndexOf(".")),r.add(this.options.textNodeName,e),this.addChild(n,r,i,d)}else{if(u.length>0&&u.lastIndexOf("/")===u.length-1){"/"===a[a.length-1]?(a=a.substr(0,a.length-1),i=i.substr(0,i.length-1),u=a):u=u.substr(0,u.length-1),this.options.transformTagName&&(a=this.options.transformTagName(a));const t=new Vs(a);a!==u&&c&&(t[":@"]=this.buildAttributesMap(u,i,a)),this.addChild(n,t,i,d),i=i.substr(0,i.lastIndexOf("."))}else{const t=new Vs(a);this.tagsNodeStack.push(n),a!==u&&c&&(t[":@"]=this.buildAttributesMap(u,i,a)),this.addChild(n,t,i,d),n=t}r="",o=h}}else r+=t[o]}return e.child};function ca(t,e,n,r){this.options.captureMetaData||(r=void 0);const i=this.options.updateTag(e.tagname,n,e[":@"]);!1===i||("string"==typeof i?(e.tagname=i,t.addChild(e,r)):t.addChild(e,r))}const ha=function(t){if(this.options.processEntities){for(let e in this.docTypeEntities){const n=this.docTypeEntities[e];t=t.replace(n.regx,n.val)}for(let e in this.lastEntities){const n=this.lastEntities[e];t=t.replace(n.regex,n.val)}if(this.options.htmlEntities)for(let e in this.htmlEntities){const n=this.htmlEntities[e];t=t.replace(n.regex,n.val)}t=t.replace(this.ampEntity.regex,this.ampEntity.val)}return t};function fa(t,e,n,r){return t&&(void 0===r&&(r=0===e.child.length),void 0!==(t=this.parseTextData(t,e.tagname,n,!1,!!e[":@"]&&0!==Object.keys(e[":@"]).length,r))&&""!==t&&e.add(this.options.textNodeName,t),t=""),t}function da(t,e,n){const r="*."+n;for(const n in t){const i=t[n];if(r===i||e===i)return!0}return!1}function pa(t,e,n,r){const i=t.indexOf(e,n);if(-1===i)throw new Error(r);return i+e.length-1}function _a(t,e,n,r=">"){const i=function(t,e,n=">"){let r,i="";for(let o=e;o<t.length;o++){let e=t[o];if(r)e===r&&(r="");else if('"'===e||"'"===e)r=e;else if(e===n[0]){if(!n[1])return{data:i,index:o};if(t[o+1]===n[1])return{data:i,index:o}}else"\t"===e&&(e=" ");i+=e}}(t,e+1,r);if(!i)return;let o=i.data;const s=i.index,a=o.search(/\s/);let l=o,u=!0;-1!==a&&(l=o.substring(0,a),o=o.substring(a+1).trimStart());const c=l;if(n){const t=l.indexOf(":");-1!==t&&(l=l.substr(t+1),u=l!==i.data.substr(t+1))}return{tagName:l,tagExp:o,closeIndex:s,attrExpPresent:u,rawTagName:c}}function ga(t,e,n){const r=n;let i=1;for(;n<t.length;n++)if("<"===t[n])if("/"===t[n+1]){const o=pa(t,">",n,`${e} is not closed`);if(t.substring(n+2,o).trim()===e&&(i--,0===i))return{tagContent:t.substring(r,n),i:o};n=o}else if("?"===t[n+1]){n=pa(t,"?>",n+1,"StopNode is not closed.")}else if("!--"===t.substr(n+1,3)){n=pa(t,"--\x3e",n+3,"StopNode is not closed.")}else if("!["===t.substr(n+1,2)){n=pa(t,"]]>",n,"StopNode is not closed.")-2}else{const r=_a(t,n,">");if(r){(r&&r.tagName)===e&&"/"!==r.tagExp[r.tagExp.length-1]&&i++,n=r.closeIndex}}}function ma(t,e,n){if(e&&"string"==typeof t){const e=t.trim();return"true"===e||"false"!==e&&ea(t,n)}return void 0!==t?t:""}const va=Vs.getMetaDataSymbol();function ya(t,e){return ba(t,e)}function ba(t,e,n){let r;const i={};for(let o=0;o<t.length;o++){const s=t[o],a=xa(s);let l="";if(l=void 0===n?a:n+"."+a,a===e.textNodeName)void 0===r?r=s[a]:r+=""+s[a];else{if(void 0===a)continue;if(s[a]){let t=ba(s[a],e,l);const n=Na(t,e);void 0!==s[va]&&(t[va]=s[va]),s[":@"]?wa(t,s[":@"],l,e):1!==Object.keys(t).length||void 0===t[e.textNodeName]||e.alwaysCreateTextNode?0===Object.keys(t).length&&(e.alwaysCreateTextNode?t[e.textNodeName]="":t=""):t=t[e.textNodeName],void 0!==i[a]&&i.hasOwnProperty(a)?(Array.isArray(i[a])||(i[a]=[i[a]]),i[a].push(t)):e.isArray(a,l,n)?i[a]=[t]:i[a]=t}}}return"string"==typeof r?r.length>0&&(i[e.textNodeName]=r):void 0!==r&&(i[e.textNodeName]=r),i}function xa(t){const e=Object.keys(t);for(let t=0;t<e.length;t++){const n=e[t];if(":@"!==n)return n}}function wa(t,e,n,r){if(e){const i=Object.keys(e),o=i.length;for(let s=0;s<o;s++){const o=i[s];r.isArray(o,n+"."+o,!0,!0)?t[o]=[e[o]]:t[o]=e[o]}}}function Na(t,e){const{textNodeName:n}=e,r=Object.keys(t).length;return 0===r||!(1!==r||!t[n]&&"boolean"!=typeof t[n]&&0!==t[n])}class Ma{constructor(t){this.externalEntities={},this.options=function(t){return Object.assign({},Hs,t)}(t)}parse(t,e){if("string"==typeof t);else{if(!t.toString)throw new Error("XML data is accepted in String or Bytes[] form.");t=t.toString()}if(e){!0===e&&(e={});const n=function(t,e){e=Object.assign({},Es,e);const n=[];let r=!1,i=!1;"\ufeff"===t[0]&&(t=t.substr(1));for(let o=0;o<t.length;o++)if("<"===t[o]&&"?"===t[o+1]){if(o+=2,o=ks(t,o),o.err)return o}else{if("<"!==t[o]){if(As(t[o]))continue;return Is("InvalidChar","char '"+t[o]+"' is not expected.",Fs(t,o))}{let s=o;if(o++,"!"===t[o]){o=Ss(t,o);continue}{let a=!1;"/"===t[o]&&(a=!0,o++);let l="";for(;o<t.length&&">"!==t[o]&&" "!==t[o]&&"\t"!==t[o]&&"\n"!==t[o]&&"\r"!==t[o];o++)l+=t[o];if(l=l.trim(),"/"===l[l.length-1]&&(l=l.substring(0,l.length-1),o--),!Us(l)){let e;return e=0===l.trim().length?"Invalid space after '<'.":"Tag '"+l+"' is an invalid name.",Is("InvalidTag",e,Fs(t,o))}const u=Ds(t,o);if(!1===u)return Is("InvalidAttr","Attributes for '"+l+"' have open quote.",Fs(t,o));let c=u.value;if(o=u.index,"/"===c[c.length-1]){const n=o-c.length;c=c.substring(0,c.length-1);const i=Ps(c,e);if(!0!==i)return Is(i.err.code,i.err.msg,Fs(t,n+i.err.line));r=!0}else if(a){if(!u.tagClosed)return Is("InvalidTag","Closing tag '"+l+"' doesn't have proper closing.",Fs(t,o));if(c.trim().length>0)return Is("InvalidTag","Closing tag '"+l+"' can't have attributes or invalid starting.",Fs(t,s));if(0===n.length)return Is("InvalidTag","Closing tag '"+l+"' has not been opened.",Fs(t,s));{const e=n.pop();if(l!==e.tagName){let n=Fs(t,e.tagStartPos);return Is("InvalidTag","Expected closing tag '"+e.tagName+"' (opened in line "+n.line+", col "+n.col+") instead of closing tag '"+l+"'.",Fs(t,s))}0==n.length&&(i=!0)}}else{const a=Ps(c,e);if(!0!==a)return Is(a.err.code,a.err.msg,Fs(t,o-c.length+a.err.line));if(!0===i)return Is("InvalidXml","Multiple possible root nodes found.",Fs(t,o));-1!==e.unpairedTags.indexOf(l)||n.push({tagName:l,tagStartPos:s}),r=!0}for(o++;o<t.length;o++)if("<"===t[o]){if("!"===t[o+1]){o++,o=Ss(t,o);continue}if("?"!==t[o+1])break;if(o=ks(t,++o),o.err)return o}else if("&"===t[o]){const e=Os(t,o);if(-1==e)return Is("InvalidChar","char '&' is not expected.",Fs(t,o));o=e}else if(!0===i&&!As(t[o]))return Is("InvalidXml","Extra text at the end",Fs(t,o));"<"===t[o]&&o--}}}return r?1==n.length?Is("InvalidTag","Unclosed tag '"+n[0].tagName+"'.",Fs(t,n[0].tagStartPos)):!(n.length>0)||Is("InvalidXml","Invalid '"+JSON.stringify(n.map(t=>t.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1}):Is("InvalidXml","Start tag expected.",1)}(t,e);if(!0!==n)throw Error(`${n.err.msg}:${n.err.line}:${n.err.col}`)}const n=new ra(this.options);n.addExternalEntities(this.externalEntities);const r=n.parseXml(t);return this.options.preserveOrder||void 0===r?r:ya(r,this.options)}addEntity(t,e){if(-1!==e.indexOf("&"))throw new Error("Entity value can't have '&'");if(-1!==t.indexOf("&")||-1!==t.indexOf(";"))throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'");if("&"===e)throw new Error("An entity with value '&' is not permitted");this.externalEntities[t]=e}static getMetaDataSymbol(){return Vs.getMetaDataSymbol()}}function Ta(t){return!i.has(t,"children")}function Ea(t,e,n){let r=[];return function i(o){Ta(o)?e&&o!=t&&r.push(o):(n&&o!=t&&r.push(o),o.children.forEach(i))}(t),r}var Aa=Object.freeze({__proto__:null,graftANode:function(t,e,n,r){let i=this.nodes.descendants();if(t.parent){if(i.indexOf(t)>=0){let i=t.parent.children.indexOf(t),o={name:n,parent:t.parent,attribute:r?r[2]:null,original_child_order:t.original_child_order},s={name:e,parent:o,attribute:r?r[1]:null,original_child_order:2};o.children=[t,s],t.parent.children[i]=o,t.parent=o,t.attribute=r?r[0]:null,t.original_child_order=1}}return this},addChild:function(t,e){return t.children?t.children.push(e):t.children=[e],t},createNode:function(t,e){return{data:{name:t,attribute:e?e[1]:null},parent:""}},deleteANode:function(t){let e=this.nodes.descendants();if("number"!=typeof t)return this.deleteANode(e.indexOf(t));if(t>0&&t<e.length){let n=e[t];if(n.parent){let r=n.parent.children.indexOf(n);r>=0&&(e.splice(t,1),n.children&&n.children.forEach(function(t){t.original_child_order=n.parent.children.length,n.parent.children.push(t),t.parent=n.parent}),n.parent.children.length>2?n.parent.children.splice(r,1):n.parent.parent?(n.parent.parent.children[n.parent.parent.children.indexOf(n.parent)]=n.parent.children[1-r],n.parent.children[1-r].parent=n.parent.parent,e.splice(e.indexOf(n.parent),1)):(e.splice(0,1),e.parent=null,delete e.data.attribute,delete e.data.annotation,delete e.data.original_child_order,e.name="root",e.data.name="root"))}}return this},getTips:function(){return i.filter(this.nodes.descendants(),t=>!i.has(t,"children"))},getInternals:function(){return i.filter(this.nodes.descendants(),t=>i.has(t,"children"))},getRootNode:function(){return this.nodes},getNodes:function(){return this.nodes},getNodeByName:function(t){return i.filter(this.nodes.descendants(),e=>e.data.name==t)[0]},assignAttributes:function(t){i.each(this.nodes.descendants(),function(e){e.data&&e.data.name in t&&(e.annotations=t[e.data.name])})},isLeafNode:Ta,updateKeyName:function(t,e){return this.nodes.each(function(n){t in n&&(e&&(n[e]=n[t]),delete n[t])}),this},clearInternalNodes:function(t){t||this.nodes.each(t=>{Ta(t)||(t[this.selection_attribute_name]=!1,t.data.traits||(t.data.traits={}),t.data.traits[this.selection_attribute_name]=t[this.selection_attribute_name])})},selectAllDescendants:Ea});function ka(t,e={}){const n=/^-?\d+(\.\d+)?$/;let r=e.left_delimiter||"{",i=e.right_delimiter||"}",o=[];function s(){let t=o[o.length-1];"children"in t||(t.children=[]),o.push({name:null}),t.children.push(o[o.length-1]),o[o.length-1].original_child_order=t.children.length}function a(){let t=o.pop();t.name=c,"children"in t?t.bootstrap_values=c:t.name=c,t.attribute=h,"["==r&&f.includes("&&NHX")?f.split(":").slice(1).forEach(e=>{const[r,i]=e.split("=");t[r]=n.test(i)?+i:i}):t.annotation=f,c="",h="",f=""}function l(e){return{json:null,error:"Unexpected '"+t[e]+"' in '"+t.substring(e-20,e+1)+"[ERROR HERE]"+t.substring(e+1,e+20)+"'"}}let u=0,c="",h="",f="",d=null,p={"'":1,'"':1},_={name:"root"};o.push(_);for(var g=/\s/,m=0;m<t.length;m++)try{var v=t[m];switch(u){case 0:"("==v&&(s(),u=1);break;case 1:case 3:if(":"==v)u=3;else if(","==v||")"==v)try{a(),u=1,","==v&&s()}catch(t){return l(m)}else if("("==v){if(c.length>0)return l(m);s()}else{if(v in p){if(1==u&&0===c.length&&0===h.length&&0===f.length){u=2,d=v;continue}return l(m)}if(v==r){if(f.length)return l(m);u=4}else if(3==u)h+=v;else{if(g.test(v))continue;if(";"==v){m=t.length;break}c+=v}}break;case 2:if(v==d){if(m<t.length-1&&t[m+1]==d){m++,c+=d;continue}d=0,u=1;continue}c+=v;break;case 4:if(v==i)u=3;else{if(v==r)return l(m);f+=v}}}catch(t){return l(m)}return 1!=o.length?l(t.length-1):{json:_,error:null}}function Sa(t,e){let n=this;t||(t=t=>"");let r=[];return t=t||"",function e(i){if(i.notshown)return;if(Ta(i)||(r.push("("),i.children.forEach(function(t,n){n&&r.push(","),e(t)}),r.push(")")),"root"!==i.data.name){const t=i.data.name.replaceAll("'","''");/\W/.test(t)?r.push("'"+t+"'"):r.push(t)}r.push(t(i));let o=n.branch_length_accessor(i);void 0!==o&&r.push(":"+o)}(e||this.nodes),r.join("")+";"}function Ca(t){let e=t,n=e.toUpperCase().indexOf("BEGIN DATA;"),r=e.slice(n);if(r.length<2)return"";n=r.toUpperCase().indexOf("END;");let o=r.slice(0,n);r=i.map(o.split(";"),t=>t.trim());let s=i.filter(r,t=>t.toUpperCase().startsWith("DIMENSION"));s=s[0].split(" "),s=i.object(i.map(i.rest(s),t=>t.split("=")));let a=i.filter(r,t=>t.toUpperCase().startsWith("FORMAT"));a=a[0].split(" "),a=i.object(i.map(i.rest(a),t=>t.split("="))),a.symbols=i.reject(a.symbols.split(""),t=>'"'==t);let l=i.filter(r,t=>t.toUpperCase().startsWith("MATRIX"));return l=l[0].split("\n"),l=i.object(i.map(i.rest(l),t=>i.compact(t.split(" ")))),l=i.mapObject(l,(t,e)=>"?"==t?a.symbols:Array(t)),{dimensions:s,format:a,matrix:l}}function za(t,e,n){i.each(t.getTips(),t=>{t.data.test=n.matrix[t.data.name]})}function Da(t){let e=t,n=e.toUpperCase().indexOf("BEGIN TREES;"),r=e.slice(n);if(r.length<2)return"";n=r.toUpperCase().indexOf("END;");let o=r.slice(0,n).split("\n");return o=i.filter(o,t=>t.trim().toUpperCase().startsWith("TREE")),ka(o[0])}var $a=Object.freeze({__proto__:null,parseAnnotations:Ca,loadAnnotations:za,default:Da});function Pa(t){var e={};if(1==t.nodeType){if(t.attributes.length>0){e["@attributes"]={};for(var n=0;n<t.attributes.length;n++){var r=t.attributes.item(n);e["@attributes"][r.nodeName]=r.nodeValue}}}else 3==t.nodeType&&(e=t.nodeValue);if(t.hasChildNodes()&&1===t.childNodes.length&&3===t.childNodes[0].nodeType)e=t.childNodes[0].nodeValue;else if(t.hasChildNodes())for(var i=0;i<t.childNodes.length;i++){var o=t.childNodes.item(i),s=o.nodeName;if(void 0===e[s])e[s]=Pa(o);else{if(void 0===e[s].push){var a=e[s];e[s]=[],e[s].push(a)}e[s].push(Pa(o))}}return e}var Oa=function(t,e){var n;if("string"==typeof t)if(DOMParser){t=(new DOMParser).parseFromString(t,"text/xml")}else{t=(new Ma).parse(t)}var r=(t=Pa(t)).phyloxml.phylogeny;return Array.isArray(r)&&(r=r[0],console.warn("PhyloXML files with multiple phylogenies are not currently supported. Only the first phylogeny will be loaded.")),(n=r.clade).name="root",function t(e,n){e.clade&&(Array.isArray(e.clade)||(e.clade=[e.clade]),e.clade.forEach(t),e.children=e.clade,delete e.clade),e.annotation=1,e.attribute="0.01",e.branch_length&&(e.attribute=e.branch_length),e.taxonomy&&(e.name=e.taxonomy.scientific_name),e.annotation=""}(n),{json:n,error:null}};var Ia={nexml:function(t,e){return new Ma({ignoreAttributes:!1,attributeNamePrefix:"",parseAttributeValue:!0}).parse(t)["nex:nexml"].trees.tree.map(function(t){var e=t.node.map(t=>t),n=e.reduce(function(t,e){return e.edges=[],e.name=e.id,t[e.id]=e,t},{}),r=e.filter(t=>t.root),o=r>0?r[0].id:e[0].id;return n[o].name="root",t.edge.map(t=>t).forEach(function(t){n[t.source].edges.push(t)}),function t(e,r){if(e.edges){var o=i.pluck(e.edges,"target");e.children=i.values(i.pick(n,o)),e.children.forEach(function(t,n){t.attribute=e.edges[n].length||""}),e.children.forEach(t),e.annotation=""}}(n[o]),n[o]})},phyloxml:Oa,nexus:Da,nwk:ka,nhx:ka,beast:function(t,e){e.left_delimiter="[",e.right_delimiter="]";const n=ka(t,e);return function t(e){if(e.annotation){e.beast={};const t=e.annotation.split(/=|,|{|}/).filter(t=>t);for(var n=0;n<t.length;n+=2){let r=t[n].replace(/&|%/g,"");/[a-df-zA-DF-Z]+/.test(t[n+2])?e.beast[r]=+t[n+1]:(e.beast[r]=[+t[n+1],+t[n+2]],n++)}}e.annotation=void 0,e.children&&e.children.forEach(t)}(n.json),n}};function La(t,e,n){let r,i,o,s=[t],a=[];for(;t=s.pop();)if((!n||!n(t))&&(a.push(t),r=t.children,r))for(i=0,o=r.length;i<o;++i)s.push(r[i]);for(;t=a.pop();)e(t);return t}function Ua(t,e,n){let r,i,o=[t];for(;t=o.pop();)if((!n||!n(t))&&(e(t),r=t.children,r))for(i=r.length-1;i>=0;--i)o.push(r[i]);return t}function Fa(t,e,n){let r,i,o,s,a=[t];do{for(r=a.reverse(),a=[];t=r.pop();)if((!n||!n(t))&&(e(t),i=t.children,i))for(o=0,s=i.length;o<s;++o)a.push(i[o])}while(a.length);return t}function ja(t){return La(t,function(t){t.children&&(t.children[0].data.multiway_parent=t,t.children[1].data.multiway_parent=t.parent)}),o.map(t.descendants(),t=>{let e=t.data.multiway_parent,n="unknown";return e&&(n=e.data.name),{source:t.data.multiway_parent,target:t,name:n}})}function Ha(t,e){let n=t.data;if("attribute"in n&&n.attribute&&n.attribute.length){e>0&&(n.attribute=String(e));let t=parseFloat(n.attribute);if(!isNaN(t))return Math.max(0,t)}if("root"==n.name)return 0;console.warn("Undefined branch length at "+n.name+"!")}var Ya=Object.freeze({__proto__:null,reroot:function(t,e){if(!(t instanceof Hr))throw new Error("node needs to be an instance of a d3.hierarchy node!");let n=this.nodes.copy();if(e=void 0!==e?e:.5,t.parent){var r=Hr({name:"new_root"});r.children=[t.copy()],r.data.__mapped_bl=void 0,n.each(t=>{t.data.__mapped_bl=this.branch_length_accessor(t)}),this.setBranchLength(t=>t.data.__mapped_bl);let s=t,a=t.parent,l=i.noop(),u=void 0===t.data.__mapped_bl?void 0:t.data.__mapped_bl*e;var o;if(l=a.data.__mapped_bl,a.data.__mapped_bl=void 0===t.data.__mapped_bl?void 0:t.data.__mapped_bl-u,t.data.__mapped_bl=u,a.parent){for(r.children.push(a);a.parent;){o=a.children.indexOf(s),a.parent.parent?a.children.splice(o,1,a.parent):a.children.splice(o,1);let t=a.parent.data.__mapped_bl;void 0!==t&&(a.parent.data.__mapped_bl=l,l=t),s=a,a=a.parent}o=a.children.indexOf(s),a.children.splice(o,1)}else o=a.children.indexOf(s),a.children.splice(o,1),l=a.data.__mapped_bl,s=r;if(1==a.children.length)l&&(a.children[0].data.__mapped_bl+=l),s.children=s.children.concat(a.children);else{let e=new Hr({name:"__reroot_top_clade",__mapped_bl:l});i.extendOwn(r.children[0],t),e.data.__mapped_bl=l,e.children=a.children.map(function(t){return t.parent=e,t}),e.parent=s,s.children.push(e)}}if(this.update(r),this.traverse_and_compute(t=>{i.each(t.children,e=>{e.parent=t})},"pre-order"),!i.isUndefined(this.display)){let t=this.display.options;Yt(this.display.container).select("svg").remove();let e=this.display.selection_attribute_name;delete this.display;let n=this.render(t);n.selectionLabel(e),n.update(),Yt(n.container).node().appendChild(n.show()),Yt(this.display.container).dispatch("reroot")}return this},rootpath:function(t,e){if(t=t||"attribute",e=e||"y_scaled","parent"in this){let n=parseFloat(this[t]);this[e]=this.parent[e]+(isNaN(n)?.1:n)}else this[e]=0;return this[e]},pathToRoot:function(t){let e=[];for(;t;)e.push(t),t=t.parent;return e}});function Va(t){return t.y}function Ba(t){return t.x}function Ra(t,e,n){return{x:n+t*Math.sin(e),y:n+t*Math.cos(e)}}function qa(t,e,n,r,i,o){t.radius=e*(t.radius+n),t.angle=2*Math.PI*t.x*i[0]/o[0];let s=Ra(t.radius,t.angle,r);return t.x=s.x,t.y=s.y,t}function Xa(t,e){var n=Ra(e[0].radius,e[0].angle,t),r=Ra(e[0].radius,e[1].angle,t);return"M "+Va(n)+","+Ba(n)+" A "+e[0].radius+","+e[0].radius+" 0,0, "+(e[1].angle>e[0].angle?1:0)+" "+Va(r)+","+Ba(r)+" L "+Va(e[1])+","+Ba(e[1])}function Za(t,e,n){var r=Ra(t.target.radius+(t.source.radius-t.target.radius)*e,t.target.angle,n);return{x:Va(r),y:Ba(r)}}var Wa=os().x(function(t){return Va(t)}).y(function(t){return Ba(t)}).curve(function(t){return new us(t,0)});function Ga(t,e){return{x:Va(t.target)+(Va(t.source)-Va(t.target))*e,y:Ba(t.target)}}function Ka(t){return t.tag||!1}function Ja(t,e){return t[e]||!1}const Qa={"tree-container":"phylotree-container","tree-scale-bar":"tree-scale-bar",node:"node","internal-node":"internal-node","tagged-node":"node-tagged","selected-node":"node-selected","collapsed-node":"node-collapsed","root-node":"root-node",branch:"branch","selected-branch":"branch-selected","tagged-branch":"branch-tagged","tree-selection-brush":"tree-selection-brush","branch-tracer":"branch-tracer",clade:"clade",node_text:"phylotree-node-text"};function tl(t={}){Object.keys(t).forEach(e=>{Qa[e]=t[e]})}function el(t){return arguments.length?(el="string"==typeof t&&"equal"==t?function(t){return 1}:t,this):el}var nl={all:t=>!0,none:t=>!1,"all-leaf-nodes":t=>Ta(t.target),"all-internal-nodes":t=>!Ta(t.target)};var rl=Object.freeze({__proto__:null,css_classes:Qa,initializeCssClasses:tl,internalNames:function(t){return arguments.length?(this.options["internal-names"]=t,this):this.options["internal-names"]},radial:function(t){return arguments.length?(this.options["is-radial"]=t,this):this.options["is-radial"]},alignTips:function(t){return arguments.length?(this.options["align-tips"]=t,this):this.options["align-tips"]},nodeBubbleSize:function(t){return this.options["draw-size-bubbles"]&&this.options["bubble-styler"]?this.options["bubble-styler"](t):this.options["draw-size-bubbles"]?this.relative_nodeSpan(t)*this.scales[0]*.25:0},shiftTip:function(t){return this.options["is-radial"]?[("end"==t.text_align?-1:1)*(this.radius_pad_for_bubbles-t.radius),0]:(this.options["right-to-left"],[this.right_most_leaf-t.screen_x,0])},layoutHandler:function(t){return arguments.length?(this.layout_listener_handler=t,this):this.layout_listener_handler},selectionLabel:function(t){return arguments.length?(this.selection_attribute_name=t,this.syncEdgeLabels(),this):this.selection_attribute_name},get nodeSpan(){return el},predefined_selecters:nl,selectionCallback:function(t){return t?(this._selectionCallback=t,this):this._selectionCallback}});function il(t){return!(t.hidden||t.notshown)}function ol(t){return t.notshown}function sl(t){return t.hasHiddenNodes||!1}function al(t){return t.collapsed||!1}function ll(t){return[t.node,t["internal-node"],t["collapsed-node"],t["tagged-node"],t["root-node"]].reduce(function(t,e,n,r){return t+"g."+e+(n<r.length-1?",":"")},"")}function ul(t){return Ta(t=t.data)?t.name||"":this.showInternalName(t)?t.name:""}var cl=Object.freeze({__proto__:null,shiftTip:function(t){return this.radial()?[("end"==t.text_align?-1:1)*(this.radius_pad_for_bubbles-t.radius),0]:(this.options["right-to-left"],[this.right_most_leaf-t.screen_x,0])},drawNode:function(t,e,n){t=Yt(t);var r=Ta(e);r&&(t=t.attr("data-node-name",e.data.name));var i=t.selectAll("text").data([e]),o=t.selectAll("line");if(r||this.showInternalName(e)&&!al(e))if(i=i.enter().append("text").classed(this.css_classes.node_text,!0).merge(i).on("click",t=>{this.handle_node_click(e,t)}).attr("dy",t=>.33*this.shown_font_size).text(t=>this.options["show-labels"]?this._nodeLabel(t):"").style("font-size",t=>this.ensure_size_is_in_px(this.shown_font_size)),i=this.radial()?i.attr("transform",t=>this.d3PhylotreeSvgRotate(t.text_angle)+this.d3PhylotreeSvgTranslate(this.alignTips()?this.shiftTip(t):null)).attr("text-anchor",t=>t.text_align):i.attr("text-anchor","start").attr("transform",t=>"right-to-left"==this.options.layout?this.d3PhylotreeSvgTranslate([-20,0]):this.d3PhylotreeSvgTranslate(this.alignTips()?this.shiftTip(t):null)),this.alignTips()?(o=o.data([e]),n?o=o.enter().append("line").classed(this.css_classes["branch-tracer"],!0).merge(o).attr("x1",t=>("end"==t.text_align?-1:1)*this.nodeBubbleSize(e)).attr("x2",0).attr("y1",0).attr("y2",0).attr("x2",t=>"right-to-left"==this.options.layout?t.screen_x:this.shiftTip(t)[0]).attr("transform",t=>this.d3PhylotreeSvgRotate(t.text_angle)).attr("x2",t=>"right-to-left"==this.options.layout?t.screen_x:this.shiftTip(t)[0]).attr("transform",t=>this.d3PhylotreeSvgRotate(t.text_angle)):(o=o.enter().append("line").classed(this.css_classes["branch-tracer"],!0).merge(o).attr("x1",t=>("end"==t.text_align?-1:1)*this.nodeBubbleSize(e)).attr("y2",0).attr("y1",0).attr("x2",t=>this.shiftTip(t)[0])).attr("transform",t=>this.d3PhylotreeSvgRotate(t.text_angle))):o.remove(),this.options["draw-size-bubbles"]){var s=this.nodeBubbleSize(e);t.selectAll("circle").data([s]).enter().append("circle").attr("r",function(t){return t}),this.shown_font_size>=5&&(i=i.attr("dx",t=>("end"==t.text_align?-1:1)*((this.alignTips()?0:s)+.33*this.shown_font_size)))}else this.shown_font_size>=5&&(i=i.attr("dx",t=>("end"==t.text_align?-1:1)*this.shown_font_size*.33));if(!r){let n=t.selectAll("circle").data([e]).enter().append("circle"),r=this.node_circle_size()(e);r>0?n.merge(n).attr("r",t=>Math.min(.75*this.shown_font_size,r)).on("click",t=>{this.handle_node_click(e,t)}):n.remove()}return this.node_styler&&this.node_styler(t,e),e},updateHasHiddenNodes:function(){let t=this.phylotree.nodes.descendants();for(let e=t.length-1;e>=0;e-=1)Ta(t[e])?t[e].hasHiddenNodes=t[e].notshown:t[e].hasHiddenNodes=t[e].children.reduce(function(t,e){return e.notshown||t},!1);return this},showInternalName:function(t){const e=this.internalNames();return!!e&&("function"==typeof e?e(t):e)},nodeSpan:function(t){return arguments.length?(this.nodeSpan="string"==typeof t&&"equal"==t?function(t){return 1}:t,this):this.nodeSpan},reclassNode:function(t){let e=Qa[Ta(t)?"node":"internal-node"];return Ka(t)&&(e+=" "+Qa["tagged-node"]),Ja(t,this.selection_attribute_name)&&(e+=" "+Qa["selected-node"]),t.parent||(e+=" "+Qa["root-node"]),(al(t)||sl(t))&&(e+=" "+Qa["collapsed-node"]),e},nodeVisible:il,nodeNotshown:ol,hasHiddenNodes:sl,isNodeCollapsed:al,nodeCssSelectors:ll,internalLabel:function(t,e){this.phylotree.clearInternalNodes(e);for(var n=this.phylotree.nodes.descendants().length-1;n>=0;n--){var r=this.phylotree.nodes.descendants()[n];Ta(r)||Ja(r,this.selection_attribute_name)||(r[this.selection_attribute_name]=t(r.children))}this.modifySelection((t,e)=>(Ta(t.target),t.target[this.selection_attribute_name]))},defNodeLabel:ul,nodeLabel:function(t){return arguments.length?(this._nodeLabel=t||ul,this.update(),this):this._nodeLabel}});function hl(t){return[t.clade].reduce(function(t,e,n,r){return t+"path."+e+(n<r.length-1?",":"")},"")}var fl=Object.freeze({__proto__:null,cladeCssSelectors:hl,updateCollapsedClades:function(t){let e=this.svg.selectAll("."+this.css_classes["tree-container"]);var n=0;let r=e.selectAll(hl(this.css_classes)).data(this.phylotree.nodes.descendants().filter(al),function(t){return t.id||(t.id=++n)}),o=function(){},s=i.noop();this.radial()?(o=os().curve(ls).y(function(t){return t[0]}).x(function(t){return t[1]}),s=function(t,e,n,r,i){return e?[n.screen_y+(t[0]-r)/50,n.screen_x+(t[1]-i)/50]:[n.screen_y,n.screen_x]}):(o=os().y(function(t){return t[0]}).x(function(t){return t[1]}).curve(ls),s=function(t,e,n,r,i){return e?[n.screen_y+(t[0]-r)/50,n.screen_x+(t[1]-i)/50]:[n.screen_y,n.screen_x]}),r.exit().each(function(t){t.collapsed_clade=null}).remove(),t?r.enter().insert("path",":first-child").attr("class",this.css_classes.clade).merge(r).attr("d",function(t){if(t.collapsed_clade)return t.collapsed_clade;let e=t.collapsed[0][0],n=t.collapsed[0][1];return o(t.collapsed.map(function(r,i){return s(r,i,t,e,n)}))}).attr("d",function(t){return t.collapsed_clade=o(t.collapsed)}):r.enter().insert("path",":first-child").attr("class",this.css_classes.clade).merge(r).attr("d",function(t){return t.collapsed_clade?t.collapsed_clade:t.collapsed_clade=o(t.collapsed)})}});function dl(t){return!(t.target.hidden||t.target.notshown)}function pl(t){return[t.branch,t["selected-branch"],t["tagged-branch"]].reduce(function(t,e,n,r){return t+"path."+e+(n<r.length-1?",":"")},"")}var _l=Object.freeze({__proto__:null,drawEdge:function(t,e,n){t=(t=Yt(t)).attr("class",t=>this.reclassEdge(t)).on("click",t=>{this.modifySelection([e.target],this.selection_attribute_name),this.update()});let r=this.draw_branch([e.source,e.target]);n?(t.datum().existing_path&&(t=t.attr("d",function(t){return t.existing_path})),t=t.attr("d",r)):t=t.attr("d",r),e.existing_path=r;var i=this.phylotree.branch_length_accessor(e.target);if(void 0!==i){var o=t.selectAll("title");o.empty()&&(o=t.append("title")),o.text("Length = "+i)}else t.selectAll("title").remove();return this.edge_styler&&this.edge_styler(t,e,n),this.phylotree},reclassEdge:function(t){let e=Qa.branch;return Ka(t)&&(e+=" "+Qa["tagged-branch"]),Ja(t,this.selection_attribute_name)&&(e+=" "+Qa["selected-branch"]),e},initializeEdgeLabels:function(){this.links.forEach(t=>{t.target.data.annotation&&(t.target[t.target.data.annotation]=t.target.data.annotation)})},syncEdgeLabels:function(){if(this.links.forEach(t=>{t[this.selection_attribute_name]=t.target[this.selection_attribute_name]||!1,t.tag=t.target.tag||!1}),this.countHandler()){let t={};t[this.selection_attribute_name]=this.links.reduce((t,e)=>t+(e[this.selection_attribute_name]?1:0),0),t.tagged=this.links.reduce(function(t,e){return t+(Ka(e)?1:0)},0),this.countUpdate(this,t,this.countHandler())}},edgeVisible:dl,edgeCssSelectors:pl,placeAlongAnEdge:function(t,e){return this.edge_placer(t,e)}});let gl="phylotree.event";function ml(t){var e=new CustomEvent(gl,{detail:["refresh",t]});document.dispatchEvent(e)}function vl(t,e){var n=new CustomEvent(gl,{detail:["countUpdate",e,t.countHandler()]});document.dispatchEvent(n)}function yl(t){switch(t.detail[0]){case"refresh":t.detail[1].refresh();break;case"countUpdate":case"layout":t.detail[2](t.detail[1])}return!0}function bl(){document.addEventListener(gl,yl,!1)}var xl=Object.freeze({__proto__:null,toggleCollapse:function(t){if(t.collapsed){t.collapsed=!1;let e=function(t){Ta(t)||t.collapsed||t.children.forEach(e),t.hidden=!1};e(t)}else t.collapsed=!0;return this.placenodes(),this},resizeSvg:function(t,e,n){let r=this.size;if(this.radial()){let t=this.pad_width(),n="fit-to-size"!=this.options["top-bottom-spacing"]?this.pad_height():0;r=[r[1]+2*t,r[0]+2*t+n],e&&e.selectAll("."+Qa["tree-container"]).attr("transform","translate ("+t+","+(t+n)+")")}else r=[r[0]+("fit-to-size"!=this.options["top-bottom-spacing"]?this.pad_height():0),r[1]+("fit-to-size"!=this.options["left-right-spacing"]?this.pad_width():0)];return e&&(n&&(e=e.transition(100)),e.attr("height",r[0]).attr("width",r[1])),this.size=r,r},rescale:function(t,e){(e=e||"y_scaled")in this&&(this[e]*=t)},triggerRefresh:ml,countUpdate:vl,d3PhylotreeTriggerLayout:function(t){var e=new CustomEvent(gl,{detail:["layout",t,t.layoutHandler()]});document.dispatchEvent(e)},d3PhylotreeEventListener:yl,d3PhylotreeAddEventListener:bl,d3PhylotreeSvgTranslate:function(t){return!t||null===t[0]&&null===t[1]?"":"translate ("+(null!==t[0]?t[0]:0)+","+(null!==t[1]?t[1]:0)+") "},d3PhylotreeSvgRotate:function(t){return null!==t?"rotate ("+t+") ":""}});let wl="d3_layout_phylotree_context_menu";function Nl(t,e,n){let r=[];return function i(o){Ta(o)?e&&o!=t&&r.push(o):(n&&o!=t&&r.push(o),o.children.forEach(i))}(t),r}var Ml=Object.freeze({__proto__:null,nodeDropdownMenu:function(t,e,n,r,o){let s=Yt(e).select("#"+wl);if(s.empty()&&(s=Yt(e).append("div").attr("id",wl).attr("class","dropdown-menu").attr("role","menu")),s.selectAll("a").remove(),s.selectAll("h6").remove(),s.selectAll("div").remove(),t){if(!i.some([Boolean(t.menu_items),r.hide,r.selectable,r.collapsible])||!r["show-menu"])return;Ta(t)||(r.collapsible&&(s.append("a").attr("class","dropdown-item").attr("tabindex","-1").text(al(t)?"Expand Subtree":"Collapse Subtree").on("click",e=>{s.style("display","none"),this.toggleCollapse(t).update()}),r.selectable&&(s.append("div").attr("class","dropdown-divider"),s.append("h6").attr("class","dropdown-header").text("Toggle selection"))),r.selectable&&(s.append("a").attr("class","dropdown-item").attr("tabindex","-1").text("All descendant branches").on("click",function(e){s.style("display","none"),n.modifySelection(n.selectAllDescendants(t,!0,!0))}),s.append("a").attr("class","dropdown-item").attr("tabindex","-1").text("All terminal branches").on("click",function(e){s.style("display","none"),n.modifySelection(n.selectAllDescendants(t,!0,!1))}),s.append("a").attr("class","dropdown-item").attr("tabindex","-1").text("All internal branches").on("click",function(e){s.style("display","none"),n.modifySelection(n.selectAllDescendants(t,!1,!0))}))),t.parent&&(r.selectable&&(s.append("a").attr("class","dropdown-item").attr("tabindex","-1").text("Incident branch").on("click",function(e){s.style("display","none"),n.modifySelection([t])}),s.append("a").attr("class","dropdown-item").attr("tabindex","-1").text("Path to root").on("click",e=>{s.style("display","none"),this.modifySelection(this.phylotree.pathToRoot(t))}),(r.reroot||r.hide)&&s.append("div").attr("class","dropdown-divider")),r.reroot&&s.append("a").attr("class","dropdown-item").attr("tabindex","-1").text("Reroot on this node").on("click",e=>{s.style("display","none"),this.phylotree.reroot(t),this.update()}),r.hide&&s.append("a").attr("class","dropdown-item").attr("tabindex","-1").text("Hide this "+(Ta(t)?"node":"subtree")).on("click",e=>{s.style("display","none"),this.modifySelection([t],"notshown",!0,!0).updateHasHiddenNodes().update()})),sl(t)&&s.append("a").attr("class","dropdown-item").attr("tabindex","-1").text("Show all descendant nodes").on("click",function(e){s.style("display","none"),n.modifySelection(n.selectAllDescendants(t,!0,!0),"notshown",!0,!0,"false").updateHasHiddenNodes().update()});var a=[];if("menu_items"in t&&"object"==typeof t.menu_items&&t.menu_items.forEach(function(e){3==e.length&&(e[2]&&!e[2](t)||a.push([e[0],e[1]]))}),a.length){const e=[r.hide,r.selectable,r.collapsible];i.some(e)&&s.append("div").attr("class","dropdown-divider"),a.forEach(function(e){s.append("a").attr("class","dropdown-item").attr("tabindex","-1").text(e[0](t)).on("click",i.partial(e[1],t))})}let l=document.querySelector(e).getBoundingClientRect();s.style("position","absolute").style("left",o.clientX-l.x+12+"px").style("top",o.clientY-l.y+"px").style("display","block")}else s.style("display","none")},addCustomMenu:function(t,e,n,r){"menu_items"in t||(t.menu_items=[]),t.menu_items.some(function(t){return t[0]==e&&t[1]==n&&t[2]==r})||t.menu_items.push([e,n,r])},modifySelection:function(t,e,n,r,o){if(e=e||this.selection_attribute_name,o=o||"toggle",this.options["restricted-selectable"].length){if(!i.contains(i.keys(nl),t))return;t=nl[t]}if(!this.options["restricted-selectable"]&&!this.options.selectable||this.options["binary-selectable"])this.options["binary-selectable"]&&("function"==typeof t?this.links.forEach(function(n){var r=t(n);n[e]=n[e]||!1,n[e]!=r&&(n[e]=r,a=!0,n.target[e]=r),this.options["attribute-list"].forEach(function(t){t!=e&&!0===n[e]&&(n[t]=!1,n.target[t]=!1)})}):(t.forEach(function(t){var n;n=!t[e],t[e]!=n&&(t[e]=n,a=!0)}),this.links.forEach(function(t){t[e]=t.target[e],this.options["attribute-list"].forEach(function(n){n!=e&&!0!==t[e]&&(t[n]=!1,t.target[n]=!1)})})),a&&(r||ml(this),this.countHandler()&&((s={})[e]=this.links.reduce(function(t,n){return t+(n[e]?1:0)},0),this.countUpdate(this,s,this.countHandler())),n&&this.placenodes()));else{var s,a=!1;"function"==typeof t?this.links.forEach(function(n){let r=t(n);n[e]=n[e]||!1,n[e]!=r&&(n[e]=r,a=!0,n.target[e]=r)}):(t.forEach(function(t){var n;switch(o){case"true":n=!0;break;case"false":n=!1;break;default:n=!t[e]}t[e]!=n&&(t[e]=n,a=!0)}),this.links.forEach(function(t){t[e]=t.target[e]})),a&&(r||ml(this),this.countHandler&&((s={})[e]=this.links.reduce(function(t,n){return t+(n[e]?1:0)},0),vl(this,s,this.countHandler)),n&&this.placenodes())}return this._selectionCallback&&"tag"!=e&&this._selectionCallback(this.getSelection()),this.refresh(),this.update(),this},getSelection:function(){return Nl(this.phylotree.getRootNode(),!0,!0).filter(t=>t[this.selection_attribute_name])},selectAllDescendants:Nl,selectionCallback:function(t){return t?(this._selectionCallback=t,this):this._selectionCallback}});function Tl(t){return function(){return t}}class El{constructor(t,e={}){tl(e["css-classes"]),this.css_classes=Qa,this.phylotree=t,this.container=e.container,this.separation=function(t,e){return 0},this._nodeLabel=this.defNodeLabel,this.svg=null,this._selectionCallback=null,this.scales=[1,1],this.size=[1,1],this.fixed_width=[14,30],this.scale_bar_font_size=12,this.draw_branch=Wa,this.draw_scale_bar=null,this.edge_placer=Ga,this.count_listener_handler=function(){},this.layout_listener_handler=function(){},this.node_styler=void 0,this.edge_styler=void 0,this.selection_attribute_name="selected",this.right_most_leaf=0,this.label_width=0,this.radial_center=0,this.radius=1,this.radius_pad_for_bubbles=0,this.rescale_nodeSpan=1,this.relative_nodeSpan=function(t){return this.nodeSpan(t)/this.rescale_nodeSpan};let n={layout:"left-to-right",logger:console,branches:"step",scaling:!0,bootstrap:!1,"color-fill":!0,"font-size":14,"internal-names":!1,selectable:!0,"restricted-selectable":!1,collapsible:!0,"left-right-spacing":"fixed-step","top-bottom-spacing":"fixed-step","left-offset":0,"show-scale":"top","draw-size-bubbles":!1,"bubble-styler":this.radius_pad_for_bubbles,"binary-selectable":!1,"is-radial":!1,"attribute-list":[],"max-radius":768,"annular-limit":.38196601125010515,compression:.2,"align-tips":!1,"maximum-per-node-spacing":100,"minimum-per-node-spacing":2,"maximum-per-level-spacing":100,"minimum-per-level-spacing":10,node_circle_size:Tl(3),transitions:null,brush:!0,reroot:!0,hide:!0,"label-nodes-with-name":!1,zoom:!1,"show-menu":!0,"show-labels":!0,"node-styler":null,"edge-styler":null,"node-span":null};this.ensure_size_is_in_px=function(t){return"number"==typeof t?t+"px":t},this.options=i.defaults(e,n),this.font_size=this.options["font-size"],this.offsets=[0,this.font_size/2],this.shown_font_size=this.font_size,this.width=this.options.width||800,this.height=this.options.height||600,this.node_styler=this.options["node-styler"],this.edge_styler=this.options["edge-styler"],this.nodeSpan=this.options["node-span"],this.nodeSpan||(this.nodeSpan=function(t){return 1}),this.rescale_nodeSpan=this.phylotree.nodes.children.map(t=>{if(Ta(t)||this.showInternalName(t))return this.nodeSpan(t)}).reduce(function(t,e){return Math.min(e,t||1e200)},null)||1,this.initialize_svg(this.container),this.links=this.phylotree.nodes.links(),this.initializeEdgeLabels(),this.update(),bl()}pad_height(){return this.draw_scale_bar?this.scale_bar_font_size+25:0}pad_width(){this.label_width=this._label_width(this.shown_font_size);const t=this.options["show-labels"]?this.label_width:0;return this.offsets[1]+this.options["left-offset"]+t}collapse_node(t){al(t)||(t.collapsed=!0)}set_size(t){if(!arguments.length)return this.size;let e=t;return"fixed-step"!=this.options["top-bottom-spacing"]&&(this.size[0]=e[0]),"fixed-step"!=this.options["left-right-spacing"]&&(this.size[1]=e[1]),this}initialize_svg(t){var e;return this.svg!==t&&(Yt(t).select("svg").remove(),this.svg=(e="svg",Yt(O(e).call(document.documentElement))).attr("width",this.width).attr("height",this.height),this.set_size([this.height,this.width]),"phylotree-container"==this.css_classes["tree-container"]&&(this.svg.selectAll("*").remove(),this.svg.append("defs")),Yt(this.container).on("click",t=>{this.handle_node_click(null)},!0)),this}update_layout(t,e){e&&(this.nodes=Hr(t),this.nodes.each(function(t){t.id=null})),this.update(),this.syncEdgeLabels()}update(t){var e=this;this.placenodes(),t=this.transitions(t);let n=0,r=this.svg.selectAll("."+Qa["tree-container"]).data([0]);if(r=r.enter().append("g").attr("class",Qa["tree-container"]).merge(r).attr("transform",t=>this.d3PhylotreeSvgTranslate([this.offsets[1]+this.options["left-offset"],this.pad_height()])),this.draw_scale_bar){let t=this.svg.selectAll("."+Qa["tree-scale-bar"]).data([0]);t.enter().append("g").attr("class",Qa["tree-scale-bar"]).style("font-size",this.ensure_size_is_in_px(this.scale_bar_font_size)).merge(t).attr("transform",t=>this.d3PhylotreeSvgTranslate([this.offsets[1]+this.options["left-offset"],this.pad_height()-10])).call(this.draw_scale_bar),t.selectAll("text").style("text-anchor","end")}else this.svg.selectAll("."+Qa["tree-scale-bar"]).remove();r=this.svg.selectAll("."+Qa["tree-container"]).data([0]),this.updateCollapsedClades(t);let o=r.selectAll(pl(Qa)).data(this.links.filter(dl),t=>t.target.id||(t.target.id=++n));o.exit().remove(),o=o.enter().insert("path",":first-child").merge(o).each(function(n){e.drawEdge(this,n,t)});let s=r.selectAll(ll(Qa)).data(this.phylotree.nodes.descendants().filter(il),t=>t.id||(t.id=++n));if(s.exit().remove(),s=s.enter().append("g").attr("class",this.reclassNode).merge(s).attr("transform",t=>{const e="right-to-left"==this.options.layout&&Ta(t);return t.screen_x=Va(t),t.screen_y=Ba(t),this.d3PhylotreeSvgTranslate([e?0:t.screen_x,t.screen_y])}).each(function(n){e.drawNode(this,n,t)}).attr("transform",t=>{if(!i.isUndefined(t.screen_x)&&!i.isUndefined(t.screen_y))return"translate("+t.screen_x+","+t.screen_y+")"}),this.options["label-nodes-with-name"]&&(s=s.attr("id",t=>"node-"+t.name)),this.resizeSvg(this.phylotree,this.svg,t),this.options.brush){var a=r.selectAll("."+Qa["tree-selection-brush"]).data([0]).enter().insert("g",":first-child").attr("class",Qa["tree-selection-brush"]),l=vr().on("brush",(t,e)=>{var n=t.selection,r=this.links.filter(dl).filter((t,e)=>t.source.screen_x>=n[0][0]&&t.source.screen_x<=n[1][0]&&t.source.screen_y>=n[0][1]&&t.source.screen_y<=n[1][1]&&t.target.screen_x>=n[0][0]&&t.target.screen_x<=n[1][0]&&t.target.screen_y>=n[0][1]&&t.target.screen_y<=n[1][1]).map(t=>t.target);this.modifySelection(this.phylotree.links.map(t=>t.target),"tag",!1,r.length>0,"false"),this.modifySelection(r,"tag",!1,!1,"true")}).on("end",()=>{});a.call(l)}if(this.syncEdgeLabels(),this.options.zoom){let t=function(){var t,e,n,r=gs,i=ms,o=xs,s=ys,a=bs,l=[0,1/0],u=[[-1/0,-1/0],[1/0,1/0]],c=250,h=Je,f=E("start","zoom","end"),d=0,p=10;function _(t){t.property("__zoom",vs).on("wheel.zoom",w,{passive:!1}).on("mousedown.zoom",N).on("dblclick.zoom",M).filter(a).on("touchstart.zoom",T).on("touchmove.zoom",A).on("touchend.zoom touchcancel.zoom",k).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function g(t,e){return(e=Math.max(l[0],Math.min(l[1],e)))===t.k?t:new fs(e,t.x,t.y)}function m(t,e,n){var r=e[0]-n[0]*t.k,i=e[1]-n[1]*t.k;return r===t.x&&i===t.y?t:new fs(t.k,r,i)}function v(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function y(t,e,n,r){t.on("start.zoom",function(){b(this,arguments).event(r).start()}).on("interrupt.zoom end.zoom",function(){b(this,arguments).event(r).end()}).tween("zoom",function(){var t=this,o=arguments,s=b(t,o).event(r),a=i.apply(t,o),l=null==n?v(a):"function"==typeof n?n.apply(t,o):n,u=Math.max(a[1][0]-a[0][0],a[1][1]-a[0][1]),c=t.__zoom,f="function"==typeof e?e.apply(t,o):e,d=h(c.invert(l).concat(u/c.k),f.invert(l).concat(u/f.k));return function(t){if(1===t)t=f;else{var e=d(t),n=u/e[2];t=new fs(n,l[0]-e[0]*n,l[1]-e[1]*n)}s.zoom(null,t)}})}function b(t,e,n){return!n&&t.__zooming||new x(t,e)}function x(t,e){this.that=t,this.args=e,this.active=0,this.sourceEvent=null,this.extent=i.apply(t,e),this.taps=0}function w(t,...e){if(r.apply(this,arguments)){var n=b(this,e).event(t),i=this.__zoom,a=Math.max(l[0],Math.min(l[1],i.k*Math.pow(2,s.apply(this,arguments)))),c=Vt(t);if(n.wheel)n.mouse[0][0]===c[0]&&n.mouse[0][1]===c[1]||(n.mouse[1]=i.invert(n.mouse[0]=c)),clearTimeout(n.wheel);else{if(i.k===a)return;n.mouse=[c,i.invert(c)],wn(this),n.start()}_s(t),n.wheel=setTimeout(function(){n.wheel=null,n.end()},150),n.zoom("mouse",o(m(g(i,a),n.mouse[0],n.mouse[1]),n.extent,u))}}function N(t,...e){if(!n&&r.apply(this,arguments)){var i=t.currentTarget,s=b(this,e,!0).event(t),a=Yt(t.view).on("mousemove.zoom",function(t){if(_s(t),!s.moved){var e=t.clientX-c,n=t.clientY-h;s.moved=e*e+n*n>d}s.event(t).zoom("mouse",o(m(s.that.__zoom,s.mouse[0]=Vt(t,i),s.mouse[1]),s.extent,u))},!0).on("mouseup.zoom",function(t){a.on("mousemove.zoom mouseup.zoom",null),Xt(t.view,s.moved),_s(t),s.event(t).end()},!0),l=Vt(t,i),c=t.clientX,h=t.clientY;qt(t.view),ps(t),s.mouse=[l,this.__zoom.invert(l)],wn(this),s.start()}}function M(t,...e){if(r.apply(this,arguments)){var n=this.__zoom,s=Vt(t.changedTouches?t.changedTouches[0]:t,this),a=n.invert(s),l=n.k*(t.shiftKey?.5:2),h=o(m(g(n,l),s,a),i.apply(this,e),u);_s(t),c>0?Yt(this).transition().duration(c).call(y,h,s,t):Yt(this).call(_.transform,h,s,t)}}function T(n,...i){if(r.apply(this,arguments)){var o,s,a,l,u=n.touches,c=u.length,h=b(this,i,n.changedTouches.length===c).event(n);for(ps(n),s=0;s<c;++s)l=[l=Vt(a=u[s],this),this.__zoom.invert(l),a.identifier],h.touch0?h.touch1||h.touch0[2]===l[2]||(h.touch1=l,h.taps=0):(h.touch0=l,o=!0,h.taps=1+!!t);t&&(t=clearTimeout(t)),o&&(h.taps<2&&(e=l[0],t=setTimeout(function(){t=null},500)),wn(this),h.start())}}function A(t,...e){if(this.__zooming){var n,r,i,s,a=b(this,e).event(t),l=t.changedTouches,c=l.length;for(_s(t),n=0;n<c;++n)i=Vt(r=l[n],this),a.touch0&&a.touch0[2]===r.identifier?a.touch0[0]=i:a.touch1&&a.touch1[2]===r.identifier&&(a.touch1[0]=i);if(r=a.that.__zoom,a.touch1){var h=a.touch0[0],f=a.touch0[1],d=a.touch1[0],p=a.touch1[1],_=(_=d[0]-h[0])*_+(_=d[1]-h[1])*_,v=(v=p[0]-f[0])*v+(v=p[1]-f[1])*v;r=g(r,Math.sqrt(_/v)),i=[(h[0]+d[0])/2,(h[1]+d[1])/2],s=[(f[0]+p[0])/2,(f[1]+p[1])/2]}else{if(!a.touch0)return;i=a.touch0[0],s=a.touch0[1]}a.zoom("touch",o(m(r,i,s),a.extent,u))}}function k(t,...r){if(this.__zooming){var i,o,s=b(this,r).event(t),a=t.changedTouches,l=a.length;for(ps(t),n&&clearTimeout(n),n=setTimeout(function(){n=null},500),i=0;i<l;++i)o=a[i],s.touch0&&s.touch0[2]===o.identifier?delete s.touch0:s.touch1&&s.touch1[2]===o.identifier&&delete s.touch1;if(s.touch1&&!s.touch0&&(s.touch0=s.touch1,delete s.touch1),s.touch0)s.touch0[1]=this.__zoom.invert(s.touch0[0]);else if(s.end(),2===s.taps&&(o=Vt(o,this),Math.hypot(e[0]-o[0],e[1]-o[1])<p)){var u=Yt(this).on("dblclick.zoom");u&&u.apply(this,arguments)}}}return _.transform=function(t,e,n,r){var i=t.selection?t.selection():t;i.property("__zoom",vs),t!==i?y(t,e,n,r):i.interrupt().each(function(){b(this,arguments).event(r).start().zoom(null,"function"==typeof e?e.apply(this,arguments):e).end()})},_.scaleBy=function(t,e,n,r){_.scaleTo(t,function(){return this.__zoom.k*("function"==typeof e?e.apply(this,arguments):e)},n,r)},_.scaleTo=function(t,e,n,r){_.transform(t,function(){var t=i.apply(this,arguments),r=this.__zoom,s=null==n?v(t):"function"==typeof n?n.apply(this,arguments):n,a=r.invert(s),l="function"==typeof e?e.apply(this,arguments):e;return o(m(g(r,l),s,a),t,u)},n,r)},_.translateBy=function(t,e,n,r){_.transform(t,function(){return o(this.__zoom.translate("function"==typeof e?e.apply(this,arguments):e,"function"==typeof n?n.apply(this,arguments):n),i.apply(this,arguments),u)},null,r)},_.translateTo=function(t,e,n,r,s){_.transform(t,function(){var t=i.apply(this,arguments),s=this.__zoom,a=null==r?v(t):"function"==typeof r?r.apply(this,arguments):r;return o(ds.translate(a[0],a[1]).scale(s.k).translate("function"==typeof e?-e.apply(this,arguments):-e,"function"==typeof n?-n.apply(this,arguments):-n),t,u)},r,s)},x.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=Yt(this.that).datum();f.call(t,this.that,new hs(t,{sourceEvent:this.sourceEvent,target:_,type:t,transform:this.that.__zoom,dispatch:f}),e)}},_.wheelDelta=function(t){return arguments.length?(s="function"==typeof t?t:cs(+t),_):s},_.filter=function(t){return arguments.length?(r="function"==typeof t?t:cs(!!t),_):r},_.touchable=function(t){return arguments.length?(a="function"==typeof t?t:cs(!!t),_):a},_.extent=function(t){return arguments.length?(i="function"==typeof t?t:cs([[+t[0][0],+t[0][1]],[+t[1][0],+t[1][1]]]),_):i},_.scaleExtent=function(t){return arguments.length?(l[0]=+t[0],l[1]=+t[1],_):[l[0],l[1]]},_.translateExtent=function(t){return arguments.length?(u[0][0]=+t[0][0],u[1][0]=+t[1][0],u[0][1]=+t[0][1],u[1][1]=+t[1][1],_):[[u[0][0],u[0][1]],[u[1][0],u[1][1]]]},_.constrain=function(t){return arguments.length?(o=t,_):o},_.duration=function(t){return arguments.length?(c=+t,_):c},_.interpolate=function(t){return arguments.length?(h=t,_):h},_.on=function(){var t=f.on.apply(f,arguments);return t===f?_:t},_.clickDistance=function(t){return arguments.length?(d=(t=+t)*t,_):Math.sqrt(d)},_.tapDistance=function(t){return arguments.length?(p=+t,_):p},_}().scaleExtent([.1,10]).on("zoom",t=>{Yt("."+Qa["tree-container"]).attr("transform",e=>t.transform),Yt("."+Qa["tree-scale-bar"]).attr("transform",e=>{let n=t.transform;return n.y-=10,n})});this.svg.call(t)}return this}_handle_single_node_layout(t){let e=this.nodeSpan(t)/this.rescale_nodeSpan;this.x=t.x=this.x+this.separation(this.last_node,t)+.5*(this.last_span+e),this._extents[1][1]=Math.max(this._extents[1][1],t.y),this._extents[1][0]=Math.min(this._extents[1][0],t.y-.5*e),this.is_under_collapsed_parent?this._extents[0][1]=Math.max(this._extents[0][1],this.save_x+(t.x-this.save_x)*this.options.compression+this.save_span+(.5*e+this.separation(this.last_node,t))*this.options.compression):this._extents[0][1]=Math.max(this._extents[0][1],this.x+.5*e+this.separation(this.last_node,t)),this.last_node=t,this.last_span=e}tree_layout(t){if(ol(t))return;let e=Ta(t);t.text_angle=null,t.text_align=null,t.radius=null,t.angle=null;let n=!1;if(t.parent)if(this.do_scaling){if(n)return 0;if(t.y=this.phylotree.branch_length_accessor(t),void 0===t.y)return n=!0,0;t.y+=t.parent.y}else t.y=e?this.max_depth:t.depth;else this.x=0,t.y=0,this.last_node=null,this.last_span=0,this._extents=[[0,0],[0,0]];if(e&&this._handle_single_node_layout(t),!e)if(al(t)&&!this.is_under_collapsed_parent){if(this.save_x=this.x,this.save_span=.5*this.last_span,this.is_under_collapsed_parent=!0,this.process_internal_node(t),this.is_under_collapsed_parent=!1,"number"==typeof t.x){t.x=this.save_x+(t.x-this.save_x)*this.options.compression+this.save_span,t.collapsed=[[t.x,t.y]];var r=e=>{e.hidden=!0,Ta(e)?(this.x=e.x=this.save_x+(e.x-this.save_x)*this.options.compression+this.save_span,t.collapsed.push([e.x,e.y])):e.children.map(r)};this.x=this.save_x,r(t),t.collapsed.splice(1,0,[this.save_x,t.y]),t.collapsed.push([this.x,t.y]),t.collapsed.push([t.x,t.y]),t.hidden=!1}}else this.process_internal_node(t);return t.x}process_internal_node(t){let e=0;if(this.showInternalName(t)){let e=t.children.length/2|0,n=0,r=!1;for(let i=0;i<t.children.length;i++){"number"==typeof this.tree_layout(t.children[i])&&n++,n>=e&&!r&&(this._handle_single_node_layout(t),r=!0)}0==n?(t.notshown=!0,t.x=void 0):r||this._handle_single_node_layout(t)}else t.x=t.children.map(this.tree_layout.bind(this)).reduce((t,n)=>"number"==typeof n?t+n:(e+=1,t),0),e==t.children.length?(t.notshown=!0,t.x=void 0):t.x/=t.children.length-e}do_lr(t){if(this.radial()&&t&&(this.offsets[1]=0),"fixed-step"==this.options["left-right-spacing"])this.size[1]=this.max_depth*this.fixed_width[1],this.scales[1]=(this.size[1]-this.offsets[1]-this.options["left-offset"])/this._extents[1][1],this.label_width=this._label_width(this.shown_font_size),this.radial()&&(this.label_width*=2);else{this.label_width=this._label_width(this.shown_font_size),t=!0;let e=this.size[1]-this.offsets[1]-this.options["left-offset"];.5*e<this.label_width&&(this.shown_font_size*=.5*e/this.label_width,this.label_width=.5*e),this.scales[1]=(this.size[1]-this.offsets[1]-this.options["left-offset"]-this.label_width)/this._extents[1][1]}}placenodes(){this._extents=[[0,0],[0,0]],this.x=0,this.last_span=0,this.last_node=null,this.last_span=0,this.save_x=this.x,this.save_span=.5*this.last_span,this.do_scaling=this.options.scaling;this.is_under_collapsed_parent=!1,this.max_depth=1,this.phylotree.nodes.x=this.tree_layout(this.phylotree.nodes,this.do_scaling),this.max_depth=function(t,e){let n;if(void 0===e)for(const e of t)null!=e&&(n<e||void 0===n&&e>=e)&&(n=e);else{let r=-1;for(let i of t)null!=(i=e(i,++r,t))&&(n<i||void 0===n&&i>=i)&&(n=i)}return n}(this.phylotree.nodes.descendants(),t=>t.depth),this.do_scaling;let t=!1;if(this.draw_scale_bar=this.options["show-scale"]&&this.do_scaling,this.offsets[1]=Math.max(this.font_size,-this._extents[1][0]*this.fixed_width[0]),"fixed-step"==this.options["top-bottom-spacing"]?(this.size[0]=this._extents[0][1]*this.fixed_width[0],this.scales[0]=this.fixed_width[0]):(this.scales[0]=(this.size[0]-this.pad_height())/this._extents[0][1],t=!0),this.shown_font_size=Math.min(this.font_size,this.scales[0]),this.radial()){this.draw_branch=i.partial(Xa,this.radial_center),this.edge_placer=Za;let e=null,n=null,r=null,o=0,s=this._extents[0][1]*this.scales[0],a=function(t,e,n,r,i){return i=i||0,Math.sqrt((e-t)*(e-t)+2*(t+i)*(e+i)*(1-Math.cos(n-r)))},l=0;this.phylotree.nodes.each(t=>{let e=t.x*this.scales[0];t.angle=2*Math.PI*e/s,t.text_angle=t.angle-Math.PI/2,t.text_angle=t.text_angle>0&&t.text_angle<Math.PI,t.text_align=t.text_angle?"end":"start",t.text_angle=(t.text_angle?180:0)+180*t.angle/Math.PI}),this.do_lr(t),this.phylotree.nodes.each(t=>{t.radius=t.y*this.scales[1]/this.size[1],l=Math.max(t.radius,l)});let u=0;this.phylotree.nodes.each(t=>{if(!t.children){let i=t.x*this.scales[0];if(null!==e){let s=i-n,c=a(t.radius,r,t.angle,e,u),h=c>0?s/c:10*this.options["max-radius"];if(h>this.options["max-radius"]){let n=s/this.options["max-radius"],i=t.radius+r,a=t.radius*r-(n*n-(r-t.radius)*(r-t.radius))/2/(1-Math.cos(e-t.angle)),c=Math.sqrt(i*i-4*a);u=Math.min(this.options["annular-limit"]*l,(-i+c)/2),o=this.options["max-radius"]}else o=Math.max(o,h)}e=t.angle,n=i,r=t.radius}}),this.radius=Math.min(this.options["max-radius"],Math.max(s/2/Math.PI,o)),t&&(this.radius=Math.min(this.radius,.5*(Math.min(s,this._extents[1][1]*this.scales[1])-this.label_width)-this.radius*u)),this.radial_center=this.radius_pad_for_bubbles=this.radius,this.draw_branch=i.partial(Xa,this.radial_center);let c=1;u&&(c=l/(l+u),this.radius*=c),this.phylotree.nodes.each(t=>{if(qa(t,this.radius,u,this.radial_center,this.scales,this.size),l=Math.max(l,t.radius),this.options["draw-size-bubbles"]?this.radius_pad_for_bubbles=Math.max(this.radius_pad_for_bubbles,t.radius+this.nodeBubbleSize(t)):this.radius_pad_for_bubbles=Math.max(this.radius_pad_for_bubbles,t.radius),t.collapsed){t.collapsed=t.collapsed.map(t=>{let e={};return e.x=t[0],e.y=t[1],e=qa(e,this.radius,u,this.radial_center,this.scales,this.size),[e.x,e.y]});let e=t.collapsed[1];t.collapsed=t.collapsed.filter(function(n,r){return r<3||r>t.collapsed.length-4||Math.sqrt(Math.pow(n[0]-e[0],2)+Math.pow(n[1]-e[1],2))>3&&(e=n,!0)})}}),this.size[0]=this.radial_center+this.radius/c,this.size[1]=this.radial_center+this.radius/c}else this.do_lr(),this.draw_branch=Wa,this.edge_placer=Ga,this.right_most_leaf=0,this.phylotree.nodes.each(t=>{if(t.x*=this.scales[0],t.y*=.8*this.scales[1],"right-to-left"==this.options.layout&&(t.y=this._extents[1][1]*this.scales[1]-t.y),Ta(t)&&(this.right_most_leaf=Math.max(this.right_most_leaf,t.y+this.nodeBubbleSize(t))),t.collapsed){t.collapsed.forEach(t=>{t[0]*=this.scales[0],t[1]*=.8*this.scales[1]});let e=t.collapsed[1][0];t.collapsed=t.collapsed.filter(function(n,r){return r<3||r>t.collapsed.length-4||n[0]-e>3&&(e=n[0],!0)})}});if(this.draw_scale_bar){let t,e;if(this.radial()){if(e=Math.min(this.radius/5,50),t=Math.pow(10,Math.ceil(Math.log(this._extents[1][1]*e/this.radius)/Math.log(10))),e=t*(this.radius/this._extents[1][1]),e<30){let n=Math.ceil(30/e);e*=n,t*=n}}else t=this._extents[1][1],e=this.size[1]-this.offsets[1]-this.options["left-offset"]-this.shown_font_size;let n=ri().domain([0,t]).range([0,e]),r=Or(".2f");if(this.draw_scale_bar=function(t){return M(1,t)}().scale(n).tickFormat(function(t){return 0===t?"":r(t)}),this.radial())this.draw_scale_bar.tickValues([t]);else{let t=function(t,e){return e?Math.round(t*(e=Math.pow(10,e)))/e:Math.round(t)},i=n.ticks();i=i.length>1?i[1]:i[0],this.draw_scale_bar.ticks(Math.min(10,t(e/(this.shown_font_size*r(i).length*2),0)))}}else this.draw_scale_bar=null;return this}spacing_x(t,e){return arguments.length?(this.fixed_width[0]!=t&&t>=this.options["minimum-per-node-spacing"]&&t<=this.options["maximum-per-node-spacing"]&&(this.fixed_width[0]=t,e||this.placenodes()),this):this.fixed_width[0]}spacing_y(t,e){return arguments.length?(this.fixed_width[1]!=t&&t>=this.options["minimum-per-level-spacing"]&&t<=this.options["maximum-per-level-spacing"]&&(this.fixed_width[1]=t,e||this.placenodes()),this):this.fixed_width[1]}_label_width(t){t=t||this.shown_font_size;let e=0;return this.phylotree.nodes.descendants().filter(il).forEach(n=>{let r=12+this._nodeLabel(n).length*t*.8;null!==n.angle&&(r*=Math.max(Math.abs(Math.cos(n.angle)),Math.abs(Math.sin(n.angle)))),e=Math.max(r,e)}),e}font_size(t){return arguments.length?(this.font_size=void 0===t?12:t,this):this.font_size}scale_bar_font_size(t){return arguments.length?(this.scale_bar_font_size=void 0===t?12:t,this):this.scale_bar_font_size}node_circle_size(t,e){return arguments.length?(this.options.node_circle_size=Tl(void 0===t?3:t),this):this.options.node_circle_size}css(t){if(0===arguments.length)return this.css_classes;if(arguments.length>2){var e={};return e[t[0]]=t[1],this.css(e)}for(var n in Qa)n in t&&t[n]!=Qa[n]&&(Qa[n]=t[n]);return this}transitions(t){return void 0!==t?t:null!==this.options.transitions?this.options.transitions:this.phylotree.nodes.descendants().length<=300}css_classes(t,e){if(!arguments.length)return this.css_classes;let n=!1;for(var r in Qa)r in t&&t[r]!=this.css_classes[r]&&(n=!0,this.css_classes[r]=t[r]);return e&&n&&this.layout(),this}layout(t){return this.svg?(this.svg.selectAll("."+this.css_classes["tree-container"]+",."+this.css_classes["tree-scale-bar"]+",."+this.css_classes["tree-selection-brush"]),this.d3PhylotreeTriggerLayout(this),this.update()):(this.d3PhylotreeTriggerLayout(this),this)}handle_node_click(t,e){this.nodeDropdownMenu(t,this.container,this,this.options,e)}refresh(){if(this.svg){let t=this.svg.selectAll("."+this.css_classes["tree-container"]).selectAll(pl(this.css_classes)).attr("class",this.reclassEdge.bind(this));this.edge_styler&&t.each(t=>{this.edge_styler(Yt(this),t)})}return this}countHandler(t){return arguments.length?(this.count_listener_handler=t,this):this.count_listener_handler}style_nodes(t){return arguments.length?(this.node_styler=t,this):this.node_styler}style_edges(t){return arguments.length?(this.edge_styler=t.bind(this),this):this.edge_styler}itemSelected(t,e){return t[e]||!1}show(){return this.svg.node()}}i.extend(El.prototype,fl),i.extend(El.prototype,cl),i.extend(El.prototype,_l),i.extend(El.prototype,xl),i.extend(El.prototype,Ml),i.extend(El.prototype,rl);let Al=class{constructor(t,e={}){this.newick_string="",this.nodes=[],this.links=[],this.parsed_tags=[],this.partitions=[],this.branch_length_accessor=Ha,this.branch_length=Ha,this.logger=e.logger||console,this.selection_attribute_name="selected";var n=e.type||void 0,r=[],o=this;if(i.isString(n))n in Ia?r=Ia[n](t,e):o.logger.error("type "+n+" not in registry! Available types are "+i.keys(Ia));else if(i.isFunction(n))try{r=n(t,e)}catch(t){o.logger.error("Could not parse custom format!")}else"root"==t.name?r={json:t,error:null}:"string"!=typeof t?r=t:"application/xml"==t.contentType?r=Oa(t):(this.newick_string=t,r=ka(t,e));if(r.json){o.nodes=Hr(r.json);let t={};o.nodes.each(e=>{e.data.annotation&&(t[e.data.annotation]=!0)}),o.parsed_tags=Object.keys(t)}else o.nodes=[];return o.links=o.nodes.links(),this.hasBranchLengths()||(console.warn("Phylotree User Warning : NO BRANCH LENGTHS DETECTED, SETTING ALL LENGTHS TO 1"),this.setBranchLength(t=>1)),o}json(t){var e=0;this.traverse_and_compute(function(t){t.json_export_index=e++},t);var n=new Array(e);return e=0,this.traverse_and_compute(function(t){let r=i.clone(t);delete r.json_export_index,t.parent&&(r.parent=t.parent.json_export_index),t.children&&(r.children=i.map(t.children,function(t){return t.json_export_index})),n[e++]=r},t),this.traverse_and_compute(function(t){delete t.json_export_index},t),JSON.stringify(n)}traverse_and_compute(t,e,n,r){return(e="pre-order"==(e=e||"post-order")?function(e){Ua(e,t,r)}:"in-order"==e?function(e){Fa(e,t,r)}:function(e){i.isUndefined(e)||La(e,t,r)})(n||this.nodes),this}get_parsed_tags(){return this.parsed_tags}update(t){this.nodes=t}render(t){return this.display=new El(this,t),this.display}};function kl(t){var e=t.branch_length_accessor;if(!e)throw"A non-null branch lengths accessor function is required for this operation";var n=0;function r(t){for(var e=0;e<t.children.length;e++)for(var n=0;n<t.children.length;n++)e!=n&&i.each(t.children[n].cot_path_to_leaves_below,function(r,i){t.children[e].cot_path_to_leaves_above&&(t.children[e].cot_path_to_leaves_above[i]=r+t.children[n].cot_computed_length)})}return t.traverse_and_compute(function(r){if(r.cot_computed_length=e(r),r.parent&&i.isUndefined(r.cot_computed_length))throw"Non-null branch lengths are required for this operation: missing branch length at node "+r.data.name;t.isLeafNode(r)?(r.cot_leaf_index=n++,r.cot_path_to_leaves_below={},r.cot_path_to_leaves_below[r.cot_leaf_index]=0,r.cot_path_to_leaves_above={}):(r.cot_path_to_leaves_below={},r.cot_path_to_leaves_above={})}),t.traverse_and_compute(function(t){t.parent&&i.each(t.cot_path_to_leaves_below,function(e,n){t.parent.cot_path_to_leaves_below[n]=e+t.cot_computed_length})}),r(t.getRootNode()),t.traverse_and_compute(function(e){e.parent&&(i.each(e.parent.cot_path_to_leaves_above,function(t,n){e.cot_path_to_leaves_above[n]=t+e.parent.cot_computed_length}),t.isLeafNode(e)||r(e))},"pre-order"),n}function Sl(t,e,n,r,i){var o=t.branch_length(e),s=!1;if(n||(r=e.data.rootToTip,i=0,s=!0),e.children)for(var a=0;a<e.children.length;a++)e.children[a]!=n?Sl(t,e.children[a],e,r,i):s=!0;e.data.rtta=e.data.rootToTip-r+i,s&&(r-=o,i+=o),e.parent&&s&&Sl(t,e.parent,e,r,i)}function Cl(t){var e=t.reduce(function(t,e){return e[2]+t},0),n=t.reduce(function(t,e){return e[2]*e[0]+t},0),r=t.reduce(function(t,e){return e[2]*e[1]+t},0),i=n/e,o=r/e,s=0,a=0,l=0;t.forEach(function(t){var e=t[0]-i;a+=t[2]*e*e,s+=t[2]*e*t[1],l+=t[2]*(t[1]-o)*(t[1]-o)});var u=(r-n*(s/=a))/e,c=0;return t.forEach(function(t){var e=t[1]-u-s*t[0];c+=t[2]*e*e}),{intercept:u,slope:s,r2:1-c/l,"var (intercept)":Math.sqrt((1+n*n/(e*a))/e),"var (slope)":Math.sqrt(1/a)}}function zl(t){var e=t.branch_length_accessor,n=0;t.traverse_and_compute(r=>{if(r.parent&&(r.data._computed_length=e(r),!i.isNumber(r.data._computed_length)))throw"rootToTip cannot be run on trees with missing branch lengths";t.isLeafNode(r)&&(r.data.leaf_index=n++),"r2t"in r.data&&delete r.data.r2t}),t.traverse_and_compute(e=>{e.parent&&("r2t"in e.parent.data||(e.parent.data.r2t={}),t.isLeafNode(e)?e.parent.data.r2t[e.data.leaf_index]=e.data._computed_length:(i.each(e.data.r2t,function(t,n){e.parent.data.r2t[n]=t+e.data._computed_length}),delete e.data.r2t),delete e.data._computed_length)});var r=t.getRootNode().data.r2t;return t.traverse_and_compute(e=>{t.isLeafNode(e)&&(e.data.rootToTip=r[e.data.leaf_index]||0,delete e.data.leaf_index)}),delete t.getRootNode().data.r2t,t}Al.prototype.isLeafNode=Ta,Al.prototype.selectAllDescendants=Ea,Al.prototype.mrca=function(t){var e;return t=t.map(function(t){return"string"==typeof t?t:t.data.name}),this.traverse_and_compute(function(n){n.children?n.parent?(n.data.mrca=i.union(...n.descendants().map(t=>t.data.mrca)),e||n.data.mrca.length!=t.length||(e=n)):e||(e=n):n.data.mrca=i.intersection([n.data.name],t)}),e},Al.prototype.hasBranchLengths=function(){let t=this.branch_length;return!!t&&i.every(this.nodes.descendants(),function(e){return!e.parent||!i.isUndefined(t(e))})},Al.prototype.getBranchLengths=function(){let t=this.branch_length;return i.map(this.nodes.descendants(),e=>t(e))},Al.prototype.branchName=function(t){return arguments.length?(this.nodeLabel=t,this):this.nodeLabel},Al.prototype.normalizeBranchLengths=function(t){let e=this.branch_length,n=i.map(this.nodes.descendants(),function(t){return e(t)?e(t):null});const r=i.max(n),o=i.min(n);return i.each(this.nodes.descendants(),t=>{let n=e(t);n&&e(t,function(t){return(t-o)/(r-o)}(n))}),this},Al.prototype.scaleBranchLengths=function(t){let e=this.branch_length;return i.each(this.nodes.descendants(),n=>{let r=e(n);r&&e(n,t(r))}),this},Al.prototype.getNewick=Sa,Al.prototype.resortChildren=function(t,e,n){return this.nodes.sum(function(t){return t.value}).sort(t),this.display&&(this.display.update_layout(this.nodes),this.display.update()),this},Al.prototype.setBranchLength=function(t){return arguments.length?(this.branch_length_accessor=t||Ha,this):this.branch_length_accessor},Al.prototype.maxParsimony=function(t,e){const n=i.partial(function(t,e){if(e.mp=[[0,0],[!1,!1]],Ta(e))e.mp[1][0]=e.mp[1][1]=e[t]||!1,e.mp[0][0]=e.mp[1][0]?1:0,e.mp[0][1]=1-e.mp[0][0];else{e.children.forEach(n);var r=e.children.reduce(function(t,e){return e.mp[0][0]+t},0),i=e.children.reduce(function(t,e){return e.mp[0][1]+t},0);e[t]?(e.mp[0][0]=i+1,e.mp[1][0]=!0,e.mp[0][1]=i,e.mp[1][1]=!0):(r<i+1?(e.mp[0][0]=r,e.mp[1][0]=!1):(e.mp[0][0]=i+1,e.mp[1][0]=!0),i<r+1?(e.mp[0][1]=i,e.mp[1][1]=!0):(e.mp[0][1]=r+1,e.mp[1][1]=!1))}},e);n(this.nodes),this.nodes.each(t=>{t.parent?t.mp=t.mp[1][t.parent.mp?1:0]:t.mp=t.mp[1][t.mp[0][0]<t.mp[0][1]?0:1]}),this.display.modifySelection((t,n)=>Ta(t.target)?t.target[e]:t.target.mp)},Al.prototype.getTipLengths=function(){let t=this.getTips(),e=i.map(t,t=>({name:t.data.name,length:parseFloat(t.data.attribute)}));return e=i.sortBy(e,t=>-t.length),e},Al.prototype.leftChildRightSibling=ja,i.extend(Al.prototype,Aa),i.extend(Al.prototype,Ya),i.extend(Al.prototype,$a);const Dl=Oi("%Y%m%d"),$l=/([0-9]{4}).?([0-9]{2}).?([0-9]{2})$/g,Pl=function(t){if(Ta(t)&&"name"in t){let e=$l.exec(t.name);if(e)return e[1]+e[2]+e[3]}return null};function Ol(t,e){let n=[];for(let r of o.range(e.length))if(r!=t){let i=[];for(let n of o.range(e[r].length))n!=t&&i.push(e[r][n]);n.push(i)}return n}t.centerOfTree=function(t,e){e=e||2;var n=kl(t),r=Number.MAX_VALUE,o=0,s=null;return 2==e?t.traverse_and_compute(function(t){if(t.parent){var e=0,a=0,l=0,u=0,c=0;i.each(t.cot_path_to_leaves_below,function(t){e+=t,a+=t*t,c++}),i.each(t.cot_path_to_leaves_above,function(t){l+=t,u+=t*t});var h=n-c,f=(l-e+t.cot_computed_length*h)/n;f<0?f=0:f>t.cot_computed_length&&(f=t.cot_computed_length);var d=u+a+2*(l*(t.cot_computed_length-f)+e*f)+c*f*f+(t.cot_computed_length-f)*(t.cot_computed_length-f)*h;d<r&&(s=t,o=f/t.cot_computed_length,r=d),delete t.cot_computed_length,delete t.cot_path_to_leaves_below,delete t.cot_path_to_leaves_above,delete t.cot_leaf_index}}):t.traverse_and_compute(function(t){if(t.parent)for(var n=t.cot_computed_length>0?.05*t.cot_computed_length:.1,a=0;a<t.cot_computed_length;){var l=0;i.each(t.cot_path_to_leaves_below,function(t){l+=Math.pow(t+a,e)}),i.each(t.cot_path_to_leaves_above,function(n){l+=Math.pow(n+(t.cot_computed_length-a),e)}),l<r&&(s=t,o=a/t.cot_computed_length,r=l),a+=n}}),{location:s,breakpoint:o,distance:r}},t.clusterPicker=function(t,e,n,r,o){r=r||t.getRootNode(),o=i.isNumber(o)?o:1;let s=t.branch_length;t.traverse_and_compute(function(t){if(t.parent){if(t._computed_length=s(t),!i.isNumber(t._computed_length))throw"clusterPicker cannot be run on trees with missing branch lengths";t.max_path_length=0}}),t.traverse_and_compute(function(t){t.parent&&(t.parent.max_path_length=Math.max(t.parent.max_path_length,t.max_path_length+t._computed_length))});var a=[];return t.traverse_and_compute(i.noop,"pre-order",r,function(r){if(!t.isLeafNode(r)){var s=i.isString(r.data.bootstrap_values)?+r.data.bootstrap_values:o;if(s>=e){var l=i.reduce(r.children,function(t,e){return e.max_path_length+e._computed_length+t},0);if(l<=n)return a.push({root:r,diameter:l,bootstrap:s}),!0}}return!1}),t.traverse_and_compute(function(t){t.parent&&(delete t._computed_length,delete t.max_path_length)},"post-order",r),i.each(a,function(e){e.members=[],t.traverse_and_compute(function(n){t.isLeafNode(n)&&e.members.push(n)},"post-order",e.root)}),a},t.computeMidpoint=function(t){if(!t.hasBranchLengths())throw"Center of tree calculation cannot be performed on trees that do not have fully specified branch lengths";var e=t.branch_length;t.traverse_and_compute(function(n){if(n.parent){var r,i=e(n);t.isLeafNode(n)?(r=n,n.max_path=0,n.max_path_terminus=n):(i+=n.max_path,r=n.max_path_terminus),(!n.parent.max_path||n.parent.max_path<i)&&(n.parent.max_path=i,n.parent.max_path_terminus=r)}});var n=t.getRootNode(),r=0;if(n.children.forEach(function(t){if(t.max_path_terminus!==n.max_path_terminus){var i=t.max_path+e(t);i>=r&&(r=i)}}),n.max_path>r){r=.5*(r+n.max_path);for(var i=n.max_path_terminus;;){var o=e(i);if(!(o<=r))return{location:i,breakpoint:r/o};r-=o,i=i.parent}}return{location:n,breakpoint:0}},t.extract_dates=function(t,e,n=Dl){return e=e||Pl,t.traverse_and_compute(function(t){var r=e(t);if(r)try{t.data.date_value=n(r);var i=t.data.date_value.getFullYear(),o=new Date(i,0,1),s=new Date(i+1,0,1);return void(t.data.decimal_date_value=i+(t.data.date_value-o)/(s-o))}catch(t){}t.data.date_value=null,t.data.decimal_date_value=null}),t},t.fitRootToTip=function(t){var e=[],n=0,r=0;!function(t){t.traverse_and_compute(function(e){t.isLeafNode(e)&&(e.data.copy_number=1)})}(t),zl(t),t.traverse_and_compute(function(n){t.isLeafNode(n)&&!i.isNull(n.data.decimal_date_value)&&e.push([n.data.decimal_date_value,n.data.rtta,n.data.copy_number])});let o=Cl(e);return t.traverse_and_compute(function(s){if(t.isLeafNode(s)&&!i.isNull(s.data.decimal_date_value)){Sl(t,s,null,0,0),e=[],t.traverse_and_compute(function(n){t.isLeafNode(n)&&!i.isNull(n.data.decimal_date_value)&&e.push([n.data.decimal_date_value,n.data.rtta,n.data.copy_number])});var a=Cl(e),l=a.r2;l>n&&(n=l,r=s,o=a)}}),{root:r,fit:o}},t.getDistanceMatrix=function(t){let e=o.keys(t)[0],n=t[e].length;return o.mapValues(t,e=>o.map(t,t=>o.sum(o.map(o.range(n),n=>e[n]!=t[n]&&"-"!=e[n]&&"-"!=t[n]))))},t.getNewick=Sa,t.inOrder=Fa,t.leftChildRightSibling=ja,t.loadAnnotations=za,t.neighborJoining=function t(e,n,r){if(n<=2){let t=new Al(""),n=t.getNodes(),i=e[0][1]/2,o=t.createNode(r[0],[null,[i]]),s=t.createNode(r[1],[null,[i]]);return t.addChild(n,o),t.addChild(n,s),t}{let s=n,a=(i=e,o.map(i,o.sum)),l=function(t,e,n){let r=o.chunk(o.fill(Array(n*n),0),n);for(let i of o.range(n))for(let s of o.range(o.parseInt(i)+1,n))r[i][s]=(n-2)*t[i][s]-e[i]-e[s],r[s][i]=r[i][s];return r}(e,a,s),[u,c,h]=function(t,e){let n=-1,r=-1,i=1/0;for(let s of o.range(e))for(let a of o.range(n,e))t[s][a]<i&&(n=s,r=a,i=t[n][r]);return[n,r,i]}(l,s),f=function(t,e){let n=o.chunk(Array(e*e),e);for(let r of o.range(e))for(let i of o.range(parseInt(r)+1,e))n[r][i]=(t[r]-t[i])/(e-2),n[i][r]=n[r][i];return n}(a,s),d=(e[u][c]+f[u][c])/2,p=(e[u][c]-f[u][c])/2,_=o.concat(0,o.filter(o.map(o.range(n),t=>{if(t!=u&&t!=c)return.5*(e[t][u]+e[t][c]-e[u][c])}),o.isNumber)),g=r[u],m=r[c],v="InternalNode0",y=o.filter(r,t=>o.includes(t,"InternalNode"));if(y.length){let t=o.max(o.map(y,t=>o.split(t,"InternalNode")[1]));v="InternalNode"+ ++t}r.unshift(v),e=Ol(o.max([u,c]),e),(e=Ol(o.min([u,c]),e)).unshift(_),o.each(o.range(1,n-1),t=>e[t].unshift(_[t])),o.remove(r,t=>t==g||t==m);let b=t(e,s-1,r),x=b.createNode(g,[null,[d]]),w=b.createNode(m,[null,[p]]);if(b.getNodeByName(v)){let t=b.getNodeByName(v);b.addChild(t,x),b.addChild(t,w)}else{let t=b.createNode(v,[null,[0]]);b.addChild(b.getNodes(),t),b.addChild(t,x),b.addChild(t,w)}return b}var i},t.newickParser=ka,t.pairwise_distances=kl,t.parseAnnotations=Ca,t.parseFasta=function(t){let e=o.split(t,"\n");return o.chain(e).map((t,e)=>t.startsWith(">")?e:-1).filter(t=>-1!=t).map((t,n,r)=>o.slice(e,r[n],r[n+1])).keyBy(t=>o.trim(t[0],">")).mapValues(t=>o.tail(t).join("")).value()},t.phylopart=function(t,e,n,r,o){r=i.isNumber(r)?r:1;var s=kl(t),a=t.getRootNode().children[0],l=Number.MAX_VALUE,u=Number.MAX_VALUE;if(!(n>0&&n<1))throw"Invalid percentile threshold in perform_phylopart";t.traverse_and_compute(function(e){t.isLeafNode(e)&&(e.cot_computed_length<l?(l<u&&(u=l),l=e.cot_computed_length):e.cot_computed_length<u&&(u=e.cot_computed_length))}),l+=u;var c=i.reduce(a.cot_path_to_leaves_below,function(t,e){return e>t?e:t},0)+i.reduce(a.cot_path_to_leaves_above,function(t,e){return e>t?e:t},0)+a.cot_computed_length-l;i.isUndefined(o)&&(o=Math.min(.001,c/100));var h=1+(c/o|0);h>500&&(o=c/(h=500));var f=t.getRootNode();f.paths_to_leaves=new Array(s),i.each(f.children,function(t){i.each(f.cot_path_to_leaves_below,function(e,n){f.paths_to_leaves[n]=e+t.cot_computed_length})}),t.traverse_and_compute(function(e){if(!t.isLeafNode(e)){e.histogram=new Array(h);for(var n=0;n<h;n++)e.histogram[n]=0;if(e.parent){var r=0;e.paths_to_leaves=[],i.each(e.cot_path_to_leaves_below,function(t,n){e.paths_to_leaves[r++]=t})}}delete e.cot_path_to_leaves_above,delete e.cot_path_to_leaves_below}),t.traverse_and_compute(function(e){if(!t.isLeafNode(e)){for(var n=0;n<e.paths_to_leaves.length;n++)for(var r=n+1;r<e.paths_to_leaves.length;r++){var i=e.paths_to_leaves[n]+e.paths_to_leaves[r];e.histogram[(i-l)/o|0]++}e.leaf_count=e.paths_to_leaves.length,delete e.paths_to_leaves}});for(var d=(s-1)*s/2*n,p=0;p<h-1&&d>f.histogram[p];p++)d-=f.histogram[p];var _=l+(p+(f.histogram[p]-d)/f.histogram[p])*o,g=[];return t.traverse_and_compute(i.noop,"pre-order",null,function(n){if(!t.isLeafNode(n)){var s=i.isString(n.data.bootstrap_values)?+n.data.bootstrap_values:r;if(s>=e){for(var a=n.leaf_count*(n.leaf_count-1)*.25,u=0;u<h-1&&a>n.histogram[u];u++)a-=n.histogram[u];var c=l+(u+(n.histogram[u]-a)/n.histogram[u])*o;if(c<=_)return g.push({root:n,median:c,bootstrap:s}),!0}}return!1}),t.traverse_and_compute(function(e){t.isLeafNode(e)||"histogram"in e&&(delete e.histogram,delete e.leaf_count)}),i.each(g,function(e){e.members=[],t.traverse_and_compute(function(n){t.isLeafNode(n)&&e.members.push(n)},"post-order",e.root)}),g},t.phylotree=Al,t.postOrder=La,t.preOrder=Ua,t.rootToTip=zl,t.sackin=function(t){let e=t.getTips(),n=i.map(e,t=>t.depth);return i.reduce(n,function(t,e){return t+e},0)},Object.defineProperty(t,"__esModule",{value:!0})});
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("underscore"),require("lodash")):"function"==typeof define&&define.amd?define(["exports","underscore","lodash"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).phylotree=t.phylotree||{},t._,t._$1)}(this,function(t,e,n){"use strict";function i(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach(function(n){if("default"!==n){var i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,i.get?i:{enumerable:!0,get:function(){return t[n]}})}}),e.default=t,Object.freeze(e)}var r=i(e),s=i(n);function o(t,e){return null==t||null==e?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function a(t,e){return null==t||null==e?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function l(t){let e,n,i;function r(t,i,r=0,s=t.length){if(r<s){if(0!==e(i,i))return s;do{const e=r+s>>>1;n(t[e],i)<0?r=e+1:s=e}while(r<s)}return r}return 2!==t.length?(e=o,n=(e,n)=>o(t(e),n),i=(e,n)=>t(e)-n):(e=t===o||t===a?t:u,n=t,i=t),{left:r,center:function(t,e,n=0,s=t.length){const o=r(t,e,n,s-1);return o>n&&i(t[o-1],e)>-i(t[o],e)?o-1:o},right:function(t,i,r=0,s=t.length){if(r<s){if(0!==e(i,i))return s;do{const e=r+s>>>1;n(t[e],i)<=0?r=e+1:s=e}while(r<s)}return r}}}function u(){return 0}const c=l(o).right;l(function(t){return null===t?NaN:+t}).center;var h=c;const f=Math.sqrt(50),d=Math.sqrt(10),p=Math.sqrt(2);function _(t,e,n){const i=(e-t)/Math.max(0,n),r=Math.floor(Math.log10(i)),s=i/Math.pow(10,r),o=s>=f?10:s>=d?5:s>=p?2:1;let a,l,u;return r<0?(u=Math.pow(10,-r)/o,a=Math.round(t*u),l=Math.round(e*u),a/u<t&&++a,l/u>e&&--l,u=-u):(u=Math.pow(10,r)*o,a=Math.round(t/u),l=Math.round(e/u),a*u<t&&++a,l*u>e&&--l),l<a&&.5<=n&&n<2?_(t,e,2*n):[a,l,u]}function g(t,e,n){return _(t=+t,e=+e,n=+n)[2]}function m(t){return t}var v=1e-6;function y(t){return"translate("+t+",0)"}function b(t){return"translate(0,"+t+")"}function x(t){return e=>+t(e)}function w(t,e){return e=Math.max(0,t.bandwidth()-2*e)/2,t.round()&&(e=Math.round(e)),n=>+t(n)+e}function N(){return!this.__axis}function M(t,e){var n=[],i=null,r=null,s=6,o=6,a=3,l="undefined"!=typeof window&&window.devicePixelRatio>1?0:.5,u=1===t||4===t?-1:1,c=4===t||2===t?"x":"y",h=1===t||3===t?y:b;function f(f){var d=null==i?e.ticks?e.ticks.apply(e,n):e.domain():i,p=null==r?e.tickFormat?e.tickFormat.apply(e,n):m:r,_=Math.max(s,0)+a,g=e.range(),y=+g[0]+l,b=+g[g.length-1]+l,M=(e.bandwidth?w:x)(e.copy(),l),S=f.selection?f.selection():f,T=S.selectAll(".domain").data([null]),E=S.selectAll(".tick").data(d,e).order(),A=E.exit(),k=E.enter().append("g").attr("class","tick"),C=E.select("line"),z=E.select("text");T=T.merge(T.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),E=E.merge(k),C=C.merge(k.append("line").attr("stroke","currentColor").attr(c+"2",u*s)),z=z.merge(k.append("text").attr("fill","currentColor").attr(c,u*_).attr("dy",1===t?"0em":3===t?"0.71em":"0.32em")),f!==S&&(T=T.transition(f),E=E.transition(f),C=C.transition(f),z=z.transition(f),A=A.transition(f).attr("opacity",v).attr("transform",function(t){return isFinite(t=M(t))?h(t+l):this.getAttribute("transform")}),k.attr("opacity",v).attr("transform",function(t){var e=this.parentNode.__axis;return h((e&&isFinite(e=e(t))?e:M(t))+l)})),A.remove(),T.attr("d",4===t||2===t?o?"M"+u*o+","+y+"H"+l+"V"+b+"H"+u*o:"M"+l+","+y+"V"+b:o?"M"+y+","+u*o+"V"+l+"H"+b+"V"+u*o:"M"+y+","+l+"H"+b),E.attr("opacity",1).attr("transform",function(t){return h(M(t)+l)}),C.attr(c+"2",u*s),z.attr(c,u*_).text(p),S.filter(N).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",2===t?"start":4===t?"end":"middle"),S.each(function(){this.__axis=M})}return f.scale=function(t){return arguments.length?(e=t,f):e},f.ticks=function(){return n=Array.from(arguments),f},f.tickArguments=function(t){return arguments.length?(n=null==t?[]:Array.from(t),f):n.slice()},f.tickValues=function(t){return arguments.length?(i=null==t?null:Array.from(t),f):i&&i.slice()},f.tickFormat=function(t){return arguments.length?(r=t,f):r},f.tickSize=function(t){return arguments.length?(s=o=+t,f):s},f.tickSizeInner=function(t){return arguments.length?(s=+t,f):s},f.tickSizeOuter=function(t){return arguments.length?(o=+t,f):o},f.tickPadding=function(t){return arguments.length?(a=+t,f):a},f.offset=function(t){return arguments.length?(l=+t,f):l},f}var S={value:()=>{}};function T(){for(var t,e=0,n=arguments.length,i={};e<n;++e){if(!(t=arguments[e]+"")||t in i||/[\s.]/.test(t))throw new Error("illegal type: "+t);i[t]=[]}return new E(i)}function E(t){this._=t}function A(t,e){for(var n,i=0,r=t.length;i<r;++i)if((n=t[i]).name===e)return n.value}function k(t,e,n){for(var i=0,r=t.length;i<r;++i)if(t[i].name===e){t[i]=S,t=t.slice(0,i).concat(t.slice(i+1));break}return null!=n&&t.push({name:e,value:n}),t}E.prototype=T.prototype={constructor:E,on:function(t,e){var n,i,r=this._,s=(i=r,(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}})),o=-1,a=s.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++o<a;)if(n=(t=s[o]).type)r[n]=k(r[n],t.name,e);else if(null==e)for(n in r)r[n]=k(r[n],t.name,null);return this}for(;++o<a;)if((n=(t=s[o]).type)&&(n=A(r[n],t.name)))return n},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new E(t)},call:function(t,e){if((n=arguments.length-2)>0)for(var n,i,r=new Array(n),s=0;s<n;++s)r[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,r)},apply:function(t,e,n){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var i=this._[t],r=0,s=i.length;r<s;++r)i[r].value.apply(e,n)}};var C="http://www.w3.org/1999/xhtml",z={svg:"http://www.w3.org/2000/svg",xhtml:C,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function $(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),z.hasOwnProperty(e)?{space:z[e],local:t}:t}function D(t){return function(){var e=this.ownerDocument,n=this.namespaceURI;return n===C&&e.documentElement.namespaceURI===C?e.createElement(t):e.createElementNS(n,t)}}function O(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function P(t){var e=$(t);return(e.local?O:D)(e)}function I(){}function L(t){return null==t?I:function(){return this.querySelector(t)}}function U(){return[]}function F(t){return null==t?U:function(){return this.querySelectorAll(t)}}function j(t){return function(){return function(t){return null==t?[]:Array.isArray(t)?t:Array.from(t)}(t.apply(this,arguments))}}function H(t){return function(){return this.matches(t)}}function Y(t){return function(e){return e.matches(t)}}var B=Array.prototype.find;function V(){return this.firstElementChild}var R=Array.prototype.filter;function q(){return Array.from(this.children)}function X(t){return new Array(t.length)}function Z(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function W(t,e,n,i,r,s){for(var o,a=0,l=e.length,u=s.length;a<u;++a)(o=e[a])?(o.__data__=s[a],i[a]=o):n[a]=new Z(t,s[a]);for(;a<l;++a)(o=e[a])&&(r[a]=o)}function G(t,e,n,i,r,s,o){var a,l,u,c=new Map,h=e.length,f=s.length,d=new Array(h);for(a=0;a<h;++a)(l=e[a])&&(d[a]=u=o.call(l,l.__data__,a,e)+"",c.has(u)?r[a]=l:c.set(u,l));for(a=0;a<f;++a)u=o.call(t,s[a],a,s)+"",(l=c.get(u))?(i[a]=l,l.__data__=s[a],c.delete(u)):n[a]=new Z(t,s[a]);for(a=0;a<h;++a)(l=e[a])&&c.get(d[a])===l&&(r[a]=l)}function K(t){return t.__data__}function J(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}function Q(t,e){return t<e?-1:t>e?1:t>=e?0:NaN}function tt(t){return function(){this.removeAttribute(t)}}function et(t){return function(){this.removeAttributeNS(t.space,t.local)}}function nt(t,e){return function(){this.setAttribute(t,e)}}function it(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function rt(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function st(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 ot(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function at(t){return function(){this.style.removeProperty(t)}}function lt(t,e,n){return function(){this.style.setProperty(t,e,n)}}function ut(t,e,n){return function(){var i=e.apply(this,arguments);null==i?this.style.removeProperty(t):this.style.setProperty(t,i,n)}}function ct(t,e){return t.style.getPropertyValue(e)||ot(t).getComputedStyle(t,null).getPropertyValue(e)}function ht(t){return function(){delete this[t]}}function ft(t,e){return function(){this[t]=e}}function dt(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function pt(t){return t.trim().split(/^|\s+/)}function _t(t){return t.classList||new gt(t)}function gt(t){this._node=t,this._names=pt(t.getAttribute("class")||"")}function mt(t,e){for(var n=_t(t),i=-1,r=e.length;++i<r;)n.add(e[i])}function vt(t,e){for(var n=_t(t),i=-1,r=e.length;++i<r;)n.remove(e[i])}function yt(t){return function(){mt(this,t)}}function bt(t){return function(){vt(this,t)}}function xt(t,e){return function(){(e.apply(this,arguments)?mt:vt)(this,t)}}function wt(){this.textContent=""}function Nt(t){return function(){this.textContent=t}}function Mt(t){return function(){var e=t.apply(this,arguments);this.textContent=null==e?"":e}}function St(){this.innerHTML=""}function Tt(t){return function(){this.innerHTML=t}}function Et(t){return function(){var e=t.apply(this,arguments);this.innerHTML=null==e?"":e}}function At(){this.nextSibling&&this.parentNode.appendChild(this)}function kt(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Ct(){return null}function zt(){var t=this.parentNode;t&&t.removeChild(this)}function $t(){var t=this.cloneNode(!1),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function Dt(){var t=this.cloneNode(!0),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function Ot(t){return function(){var e=this.__on;if(e){for(var n,i=0,r=-1,s=e.length;i<s;++i)n=e[i],t.type&&n.type!==t.type||n.name!==t.name?e[++r]=n:this.removeEventListener(n.type,n.listener,n.options);++r?e.length=r:delete this.__on}}}function Pt(t,e,n){return function(){var i,r=this.__on,s=function(t){return function(e){t.call(this,e,this.__data__)}}(e);if(r)for(var o=0,a=r.length;o<a;++o)if((i=r[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},r?r.push(i):this.__on=[i]}}function It(t,e,n){var i=ot(t),r=i.CustomEvent;"function"==typeof r?r=new r(e,n):(r=i.document.createEvent("Event"),n?(r.initEvent(e,n.bubbles,n.cancelable),r.detail=n.detail):r.initEvent(e,!1,!1)),t.dispatchEvent(r)}function Lt(t,e){return function(){return It(this,t,e)}}function Ut(t,e){return function(){return It(this,t,e.apply(this,arguments))}}Z.prototype={constructor:Z,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)}},gt.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 Ft=[null];function jt(t,e){this._groups=t,this._parents=e}function Ht(){return new jt([[document.documentElement]],Ft)}function Yt(t){return"string"==typeof t?new jt([[document.querySelector(t)]],[document.documentElement]):new jt([[t]],Ft)}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 r=e.getBoundingClientRect();return[t.clientX-r.left-e.clientLeft,t.clientY-r.top-e.clientTop]}}return[t.pageX,t.pageY]}jt.prototype=Ht.prototype={constructor:jt,select:function(t){"function"!=typeof t&&(t=L(t));for(var e=this._groups,n=e.length,i=new Array(n),r=0;r<n;++r)for(var s,o,a=e[r],l=a.length,u=i[r]=new Array(l),c=0;c<l;++c)(s=a[c])&&(o=t.call(s,s.__data__,c,a))&&("__data__"in s&&(o.__data__=s.__data__),u[c]=o);return new jt(i,this._parents)},selectAll:function(t){t="function"==typeof t?j(t):F(t);for(var e=this._groups,n=e.length,i=[],r=[],s=0;s<n;++s)for(var o,a=e[s],l=a.length,u=0;u<l;++u)(o=a[u])&&(i.push(t.call(o,o.__data__,u,a)),r.push(o));return new jt(i,r)},selectChild:function(t){return this.select(null==t?V:function(t){return function(){return B.call(this.children,t)}}("function"==typeof t?t:Y(t)))},selectChildren:function(t){return this.selectAll(null==t?q:function(t){return function(){return R.call(this.children,t)}}("function"==typeof t?t:Y(t)))},filter:function(t){"function"!=typeof t&&(t=H(t));for(var e=this._groups,n=e.length,i=new Array(n),r=0;r<n;++r)for(var s,o=e[r],a=o.length,l=i[r]=[],u=0;u<a;++u)(s=o[u])&&t.call(s,s.__data__,u,o)&&l.push(s);return new jt(i,this._parents)},data:function(t,e){if(!arguments.length)return Array.from(this,K);var n=e?G:W,i=this._parents,r=this._groups;"function"!=typeof t&&(t=function(t){return function(){return t}}(t));for(var s=r.length,o=new Array(s),a=new Array(s),l=new Array(s),u=0;u<s;++u){var c=i[u],h=r[u],f=h.length,d=J(t.call(c,c&&c.__data__,u,i)),p=d.length,_=a[u]=new Array(p),g=o[u]=new Array(p);n(c,h,_,g,l[u]=new Array(f),d,e);for(var m,v,y=0,b=0;y<p;++y)if(m=_[y]){for(y>=b&&(b=y+1);!(v=g[b])&&++b<p;);m._next=v||null}}return(o=new jt(o,i))._enter=a,o._exit=l,o},enter:function(){return new jt(this._enter||this._groups.map(X),this._parents)},exit:function(){return new jt(this._exit||this._groups.map(X),this._parents)},join:function(t,e,n){var i=this.enter(),r=this,s=this.exit();return"function"==typeof t?(i=t(i))&&(i=i.selection()):i=i.append(t+""),null!=e&&(r=e(r))&&(r=r.selection()),null==n?s.remove():n(s),i&&r?i.merge(r).order():r},merge:function(t){for(var e=t.selection?t.selection():t,n=this._groups,i=e._groups,r=n.length,s=i.length,o=Math.min(r,s),a=new Array(r),l=0;l<o;++l)for(var u,c=n[l],h=i[l],f=c.length,d=a[l]=new Array(f),p=0;p<f;++p)(u=c[p]||h[p])&&(d[p]=u);for(;l<r;++l)a[l]=n[l];return new jt(a,this._parents)},selection:function(){return this},order:function(){for(var t=this._groups,e=-1,n=t.length;++e<n;)for(var i,r=t[e],s=r.length-1,o=r[s];--s>=0;)(i=r[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=Q);for(var n=this._groups,i=n.length,r=new Array(i),s=0;s<i;++s){for(var o,a=n[s],l=a.length,u=r[s]=new Array(l),c=0;c<l;++c)(o=a[c])&&(u[c]=o);u.sort(e)}return new jt(r,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],r=0,s=i.length;r<s;++r){var o=i[r];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 r,s=e[n],o=0,a=s.length;o<a;++o)(r=s[o])&&t.call(r,r.__data__,o,s);return this},attr:function(t,e){var n=$(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?et:tt:"function"==typeof e?n.local?st:rt:n.local?it:nt)(n,e))},style:function(t,e,n){return arguments.length>1?this.each((null==e?at:"function"==typeof e?ut:lt)(t,e,null==n?"":n)):ct(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?ht:"function"==typeof e?dt:ft)(t,e)):this.node()[t]},classed:function(t,e){var n=pt(t+"");if(arguments.length<2){for(var i=_t(this.node()),r=-1,s=n.length;++r<s;)if(!i.contains(n[r]))return!1;return!0}return this.each(("function"==typeof e?xt:e?yt:bt)(n,e))},text:function(t){return arguments.length?this.each(null==t?wt:("function"==typeof t?Mt:Nt)(t)):this.node().textContent},html:function(t){return arguments.length?this.each(null==t?St:("function"==typeof t?Et:Tt)(t)):this.node().innerHTML},raise:function(){return this.each(At)},lower:function(){return this.each(kt)},append:function(t){var e="function"==typeof t?t:P(t);return this.select(function(){return this.appendChild(e.apply(this,arguments))})},insert:function(t,e){var n="function"==typeof t?t:P(t),i=null==e?Ct:"function"==typeof e?e:L(e);return this.select(function(){return this.insertBefore(n.apply(this,arguments),i.apply(this,arguments)||null)})},remove:function(){return this.each(zt)},clone:function(t){return this.select(t?Dt:$t)},datum:function(t){return arguments.length?this.property("__data__",t):this.node().__data__},on:function(t,e,n){var i,r,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(a=e?Pt:Ot,i=0;i<o;++i)this.each(a(s[i],e,n));return this}var a=this.node().__on;if(a)for(var l,u=0,c=a.length;u<c;++u)for(i=0,l=a[u];i<o;++i)if((r=s[i]).type===l.type&&r.name===l.name)return l.value},dispatch:function(t,e){return this.each(("function"==typeof e?Ut:Lt)(t,e))},[Symbol.iterator]:function*(){for(var t=this._groups,e=0,n=t.length;e<n;++e)for(var i,r=t[e],s=0,o=r.length;s<o;++s)(i=r[s])&&(yield i)}};const Vt={capture:!0,passive:!1};function Rt(t){t.preventDefault(),t.stopImmediatePropagation()}function qt(t){var e=t.document.documentElement,n=Yt(t).on("dragstart.drag",Rt,Vt);"onselectstart"in e?n.on("selectstart.drag",Rt,Vt):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}function Xt(t,e){var n=t.document.documentElement,i=Yt(t).on("dragstart.drag",null);e&&(i.on("click.drag",Rt,Vt),setTimeout(function(){i.on("click.drag",null)},0)),"onselectstart"in n?i.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}function Zt(t,e,n){t.prototype=e.prototype=n,n.constructor=t}function Wt(t,e){var n=Object.create(t.prototype);for(var i in e)n[i]=e[i];return n}function Gt(){}var Kt=.7,Jt=1/Kt,Qt="\\s*([+-]?\\d+)\\s*",te="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",ee="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",ne=/^#([0-9a-f]{3,8})$/,ie=new RegExp(`^rgb\\(${Qt},${Qt},${Qt}\\)$`),re=new RegExp(`^rgb\\(${ee},${ee},${ee}\\)$`),se=new RegExp(`^rgba\\(${Qt},${Qt},${Qt},${te}\\)$`),oe=new RegExp(`^rgba\\(${ee},${ee},${ee},${te}\\)$`),ae=new RegExp(`^hsl\\(${te},${ee},${ee}\\)$`),le=new RegExp(`^hsla\\(${te},${ee},${ee},${te}\\)$`),ue={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 ce(){return this.rgb().formatHex()}function he(){return this.rgb().formatRgb()}function fe(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=ne.exec(t))?(n=e[1].length,e=parseInt(e[1],16),6===n?de(e):3===n?new ge(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?pe(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?pe(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=ie.exec(t))?new ge(e[1],e[2],e[3],1):(e=re.exec(t))?new ge(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=se.exec(t))?pe(e[1],e[2],e[3],e[4]):(e=oe.exec(t))?pe(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=ae.exec(t))?we(e[1],e[2]/100,e[3]/100,1):(e=le.exec(t))?we(e[1],e[2]/100,e[3]/100,e[4]):ue.hasOwnProperty(t)?de(ue[t]):"transparent"===t?new ge(NaN,NaN,NaN,0):null}function de(t){return new ge(t>>16&255,t>>8&255,255&t,1)}function pe(t,e,n,i){return i<=0&&(t=e=n=NaN),new ge(t,e,n,i)}function _e(t,e,n,i){return 1===arguments.length?((r=t)instanceof Gt||(r=fe(r)),r?new ge((r=r.rgb()).r,r.g,r.b,r.opacity):new ge):new ge(t,e,n,null==i?1:i);var r}function ge(t,e,n,i){this.r=+t,this.g=+e,this.b=+n,this.opacity=+i}function me(){return`#${xe(this.r)}${xe(this.g)}${xe(this.b)}`}function ve(){const t=ye(this.opacity);return`${1===t?"rgb(":"rgba("}${be(this.r)}, ${be(this.g)}, ${be(this.b)}${1===t?")":`, ${t})`}`}function ye(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function be(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function xe(t){return((t=be(t))<16?"0":"")+t.toString(16)}function we(t,e,n,i){return i<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new Me(t,e,n,i)}function Ne(t){if(t instanceof Me)return new Me(t.h,t.s,t.l,t.opacity);if(t instanceof Gt||(t=fe(t)),!t)return new Me;if(t instanceof Me)return t;var e=(t=t.rgb()).r/255,n=t.g/255,i=t.b/255,r=Math.min(e,n,i),s=Math.max(e,n,i),o=NaN,a=s-r,l=(s+r)/2;return a?(o=e===s?(n-i)/a+6*(n<i):n===s?(i-e)/a+2:(e-n)/a+4,a/=l<.5?s+r:2-s-r,o*=60):a=l>0&&l<1?0:o,new Me(o,a,l,t.opacity)}function Me(t,e,n,i){this.h=+t,this.s=+e,this.l=+n,this.opacity=+i}function Se(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)}Zt(Gt,fe,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:ce,formatHex:ce,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return Ne(this).formatHsl()},formatRgb:he,toString:he}),Zt(ge,_e,Wt(Gt,{brighter(t){return t=null==t?Jt:Math.pow(Jt,t),new ge(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?Kt:Math.pow(Kt,t),new ge(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new ge(be(this.r),be(this.g),be(this.b),ye(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:me,formatHex:me,formatHex8:function(){return`#${xe(this.r)}${xe(this.g)}${xe(this.b)}${xe(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:ve,toString:ve})),Zt(Me,function(t,e,n,i){return 1===arguments.length?Ne(t):new Me(t,e,n,null==i?1:i)},Wt(Gt,{brighter(t){return t=null==t?Jt:Math.pow(Jt,t),new Me(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?Kt:Math.pow(Kt,t),new Me(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,r=2*n-i;return new ge(Ee(t>=240?t-240:t+120,r,i),Ee(t,r,i),Ee(t<120?t+240:t-120,r,i),this.opacity)},clamp(){return new Me(Se(this.h),Te(this.s),Te(this.l),ye(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=ye(this.opacity);return`${1===t?"hsl(":"hsla("}${Se(this.h)}, ${100*Te(this.s)}%, ${100*Te(this.l)}%${1===t?")":`, ${t})`}`}}));var Ae=t=>()=>t;function ke(t){return 1===(t=+t)?Ce: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):Ae(isNaN(e)?n:e)}}function Ce(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):Ae(isNaN(t)?e:t)}var ze=function t(e){var n=ke(e);function i(t,e){var i=n((t=_e(t)).r,(e=_e(e)).r),r=n(t.g,e.g),s=n(t.b,e.b),o=Ce(t.opacity,e.opacity);return function(e){return t.r=i(e),t.g=r(e),t.b=s(e),t.opacity=o(e),t+""}}return i.gamma=t,i}(1);function $e(t,e){e||(e=[]);var n,i=t?Math.min(e.length,t.length):0,r=e.slice();return function(s){for(n=0;n<i;++n)r[n]=t[n]*(1-s)+e[n]*s;return r}}function De(t,e){var n,i=e?e.length:0,r=t?Math.min(i,t.length):0,s=new Array(r),o=new Array(i);for(n=0;n<r;++n)s[n]=je(t[n],e[n]);for(;n<i;++n)o[n]=e[n];return function(t){for(n=0;n<r;++n)o[n]=s[n](t);return o}}function Oe(t,e){var n=new Date;return t=+t,e=+e,function(i){return n.setTime(t*(1-i)+e*i),n}}function Pe(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}function Ie(t,e){var n,i={},r={};for(n in null!==t&&"object"==typeof t||(t={}),null!==e&&"object"==typeof e||(e={}),e)n in t?i[n]=je(t[n],e[n]):r[n]=e[n];return function(t){for(n in i)r[n]=i[n](t);return r}}var Le=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Ue=new RegExp(Le.source,"g");function Fe(t,e){var n,i,r,s=Le.lastIndex=Ue.lastIndex=0,o=-1,a=[],l=[];for(t+="",e+="";(n=Le.exec(t))&&(i=Ue.exec(e));)(r=i.index)>s&&(r=e.slice(s,r),a[o]?a[o]+=r:a[++o]=r),(n=n[0])===(i=i[0])?a[o]?a[o]+=i:a[++o]=i:(a[++o]=null,l.push({i:o,x:Pe(n,i)})),s=Ue.lastIndex;return s<e.length&&(r=e.slice(s),a[o]?a[o]+=r:a[++o]=r),a.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)a[(n=l[i]).i]=n.x(t);return a.join("")})}function je(t,e){var n,i=typeof e;return null==e||"boolean"===i?Ae(e):("number"===i?Pe:"string"===i?(n=fe(e))?(e=n,ze):Fe:e instanceof fe?ze:e instanceof Date?Oe:function(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}(e)?$e:Array.isArray(e)?De:"function"!=typeof e.valueOf&&"function"!=typeof e.toString||isNaN(e)?Ie:Pe)(t,e)}function He(t,e){return t=+t,e=+e,function(n){return Math.round(t*(1-n)+e*n)}}var Ye,Be=180/Math.PI,Ve={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Re(t,e,n,i,r,s){var o,a,l;return(o=Math.sqrt(t*t+e*e))&&(t/=o,e/=o),(l=t*n+e*i)&&(n-=t*l,i-=e*l),(a=Math.sqrt(n*n+i*i))&&(n/=a,i/=a,l/=a),t*i<e*n&&(t=-t,e=-e,l=-l,o=-o),{translateX:r,translateY:s,rotate:Math.atan2(e,t)*Be,skewX:Math.atan(l)*Be,scaleX:o,scaleY:a}}function qe(t,e,n,i){function r(t){return t.length?t.pop()+" ":""}return function(s,o){var a=[],l=[];return s=t(s),o=t(o),function(t,i,r,s,o,a){if(t!==r||i!==s){var l=o.push("translate(",null,e,null,n);a.push({i:l-4,x:Pe(t,r)},{i:l-2,x:Pe(i,s)})}else(r||s)&&o.push("translate("+r+e+s+n)}(s.translateX,s.translateY,o.translateX,o.translateY,a,l),function(t,e,n,s){t!==e?(t-e>180?e+=360:e-t>180&&(t+=360),s.push({i:n.push(r(n)+"rotate(",null,i)-2,x:Pe(t,e)})):e&&n.push(r(n)+"rotate("+e+i)}(s.rotate,o.rotate,a,l),function(t,e,n,s){t!==e?s.push({i:n.push(r(n)+"skewX(",null,i)-2,x:Pe(t,e)}):e&&n.push(r(n)+"skewX("+e+i)}(s.skewX,o.skewX,a,l),function(t,e,n,i,s,o){if(t!==n||e!==i){var a=s.push(r(s)+"scale(",null,",",null,")");o.push({i:a-4,x:Pe(t,n)},{i:a-2,x:Pe(e,i)})}else 1===n&&1===i||s.push(r(s)+"scale("+n+","+i+")")}(s.scaleX,s.scaleY,o.scaleX,o.scaleY,a,l),s=o=null,function(t){for(var e,n=-1,i=l.length;++n<i;)a[(e=l[n]).i]=e.x(t);return a.join("")}}}var Xe=qe(function(t){const e=new("function"==typeof DOMMatrix?DOMMatrix:WebKitCSSMatrix)(t+"");return e.isIdentity?Ve:Re(e.a,e.b,e.c,e.d,e.e,e.f)},"px, ","px)","deg)"),Ze=qe(function(t){return null==t?Ve:(Ye||(Ye=document.createElementNS("http://www.w3.org/2000/svg","g")),Ye.setAttribute("transform",t),(t=Ye.transform.baseVal.consolidate())?Re((t=t.matrix).a,t.b,t.c,t.d,t.e,t.f):Ve)},", ",")",")");function We(t){return((t=Math.exp(t))+1/t)/2}var Ge,Ke,Je=function t(e,n,i){function r(t,r){var s,o,a=t[0],l=t[1],u=t[2],c=r[0],h=r[1],f=r[2],d=c-a,p=h-l,_=d*d+p*p;if(_<1e-12)o=Math.log(f/u)/e,s=function(t){return[a+t*d,l+t*p,u*Math.exp(e*t*o)]};else{var g=Math.sqrt(_),m=(f*f-u*u+i*_)/(2*u*n*g),v=(f*f-u*u-i*_)/(2*f*n*g),y=Math.log(Math.sqrt(m*m+1)-m),b=Math.log(Math.sqrt(v*v+1)-v);o=(b-y)/e,s=function(t){var i=t*o,r=We(y),s=u/(n*g)*(r*function(t){return((t=Math.exp(2*t))-1)/(t+1)}(e*i+y)-function(t){return((t=Math.exp(t))-1/t)/2}(y));return[a+s*d,l+s*p,u*r/We(e*i+y)]}}return s.duration=1e3*o*e/Math.SQRT2,s}return r.rho=function(e){var n=Math.max(.001,+e),i=n*n;return t(n,i,i*i)},r}(Math.SQRT2,2,4),Qe=0,tn=0,en=0,nn=0,rn=0,sn=0,on="object"==typeof performance&&performance.now?performance:Date,an="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function ln(){return rn||(an(un),rn=on.now()+sn)}function un(){rn=0}function cn(){this._call=this._time=this._next=null}function hn(t,e,n){var i=new cn;return i.restart(t,e,n),i}function fn(){rn=(nn=on.now())+sn,Qe=tn=0;try{!function(){ln(),++Qe;for(var t,e=Ge;e;)(t=rn-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Qe}()}finally{Qe=0,function(){var t,e,n=Ge,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:Ge=e);Ke=t,pn(i)}(),rn=0}}function dn(){var t=on.now(),e=t-nn;e>1e3&&(sn-=e,nn=t)}function pn(t){Qe||(tn&&(tn=clearTimeout(tn)),t-rn>24?(t<1/0&&(tn=setTimeout(fn,t-on.now()-sn)),en&&(en=clearInterval(en))):(en||(nn=on.now(),en=setInterval(dn,1e3)),Qe=1,an(fn)))}function _n(t,e,n){var i=new cn;return e=null==e?0:+e,i.restart(n=>{i.stop(),t(n+e)},e,n),i}cn.prototype=hn.prototype={constructor:cn,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?ln():+n)+(null==e?0:+e),this._next||Ke===this||(Ke?Ke._next=this:Ge=this,Ke=this),this._call=t,this._time=n,pn()},stop:function(){this._call&&(this._call=null,this._time=1/0,pn())}};var gn=T("start","end","cancel","interrupt"),mn=[];function vn(t,e,n,i,r,s){var o=t.__transition;if(o){if(n in o)return}else t.__transition={};!function(t,e,n){var i,r=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 u,c,h,f;if(1!==n.state)return l();for(u in r)if((f=r[u]).name===n.name){if(3===f.state)return _n(o);4===f.state?(f.state=6,f.timer.stop(),f.on.call("interrupt",t,t.__data__,f.index,f.group),delete r[u]):+u<e&&(f.state=6,f.timer.stop(),f.on.call("cancel",t,t.__data__,f.index,f.group),delete r[u])}if(_n(function(){3===n.state&&(n.state=4,n.timer.restart(a,n.delay,n.time),a(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(h=n.tween.length),u=0,c=-1;u<h;++u)(f=n.tween[u].value.call(t,t.__data__,n.index,n.group))&&(i[++c]=f);i.length=c+1}}function a(e){for(var r=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,r);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 r[e],r)return;delete t.__transition}r[e]=n,n.timer=hn(s,0,n.time)}(t,n,{name:e,index:i,group:r,on:gn,tween:mn,time:s.time,delay:s.delay,duration:s.duration,ease:s.ease,timer:null,state:0})}function yn(t,e){var n=xn(t,e);if(n.state>0)throw new Error("too late; already scheduled");return n}function bn(t,e){var n=xn(t,e);if(n.state>3)throw new Error("too late; already running");return n}function xn(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function wn(t,e){var n,i,r,s=t.__transition,o=!0;if(s){for(r in e=null==e?null:e+"",s)(n=s[r]).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[r]):o=!1;o&&delete t.__transition}}function Nn(t,e){var n,i;return function(){var r=bn(this,t),s=r.tween;if(s!==n)for(var o=0,a=(i=n=s).length;o<a;++o)if(i[o].name===e){(i=i.slice()).splice(o,1);break}r.tween=i}}function Mn(t,e,n){var i,r;if("function"!=typeof n)throw new Error;return function(){var s=bn(this,t),o=s.tween;if(o!==i){r=(i=o).slice();for(var a={name:e,value:n},l=0,u=r.length;l<u;++l)if(r[l].name===e){r[l]=a;break}l===u&&r.push(a)}s.tween=r}}function Sn(t,e,n){var i=t._id;return t.each(function(){var t=bn(this,i);(t.value||(t.value={}))[e]=n.apply(this,arguments)}),function(t){return xn(t,i).value[e]}}function Tn(t,e){var n;return("number"==typeof e?Pe:e instanceof fe?ze:(n=fe(e))?(e=n,ze):Fe)(t,e)}function En(t){return function(){this.removeAttribute(t)}}function An(t){return function(){this.removeAttributeNS(t.space,t.local)}}function kn(t,e,n){var i,r,s=n+"";return function(){var o=this.getAttribute(t);return o===s?null:o===i?r:r=e(i=o,n)}}function Cn(t,e,n){var i,r,s=n+"";return function(){var o=this.getAttributeNS(t.space,t.local);return o===s?null:o===i?r:r=e(i=o,n)}}function zn(t,e,n){var i,r,s;return function(){var o,a,l=n(this);if(null!=l)return(o=this.getAttribute(t))===(a=l+"")?null:o===i&&a===r?s:(r=a,s=e(i=o,l));this.removeAttribute(t)}}function $n(t,e,n){var i,r,s;return function(){var o,a,l=n(this);if(null!=l)return(o=this.getAttributeNS(t.space,t.local))===(a=l+"")?null:o===i&&a===r?s:(r=a,s=e(i=o,l));this.removeAttributeNS(t.space,t.local)}}function Dn(t,e){var n,i;function r(){var r=e.apply(this,arguments);return r!==i&&(n=(i=r)&&function(t,e){return function(n){this.setAttributeNS(t.space,t.local,e.call(this,n))}}(t,r)),n}return r._value=e,r}function On(t,e){var n,i;function r(){var r=e.apply(this,arguments);return r!==i&&(n=(i=r)&&function(t,e){return function(n){this.setAttribute(t,e.call(this,n))}}(t,r)),n}return r._value=e,r}function Pn(t,e){return function(){yn(this,t).delay=+e.apply(this,arguments)}}function In(t,e){return e=+e,function(){yn(this,t).delay=e}}function Ln(t,e){return function(){bn(this,t).duration=+e.apply(this,arguments)}}function Un(t,e){return e=+e,function(){bn(this,t).duration=e}}var Fn=Ht.prototype.constructor;function jn(t){return function(){this.style.removeProperty(t)}}var Hn=0;function Yn(t,e,n,i){this._groups=t,this._parents=e,this._name=n,this._id=i}function Bn(){return++Hn}var Vn=Ht.prototype;Yn.prototype={constructor:Yn,select:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=L(t));for(var i=this._groups,r=i.length,s=new Array(r),o=0;o<r;++o)for(var a,l,u=i[o],c=u.length,h=s[o]=new Array(c),f=0;f<c;++f)(a=u[f])&&(l=t.call(a,a.__data__,f,u))&&("__data__"in a&&(l.__data__=a.__data__),h[f]=l,vn(h[f],e,n,f,h,xn(a,n)));return new Yn(s,this._parents,e,n)},selectAll:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=F(t));for(var i=this._groups,r=i.length,s=[],o=[],a=0;a<r;++a)for(var l,u=i[a],c=u.length,h=0;h<c;++h)if(l=u[h]){for(var f,d=t.call(l,l.__data__,h,u),p=xn(l,n),_=0,g=d.length;_<g;++_)(f=d[_])&&vn(f,e,n,_,d,p);s.push(d),o.push(l)}return new Yn(s,o,e,n)},selectChild:Vn.selectChild,selectChildren:Vn.selectChildren,filter:function(t){"function"!=typeof t&&(t=H(t));for(var e=this._groups,n=e.length,i=new Array(n),r=0;r<n;++r)for(var s,o=e[r],a=o.length,l=i[r]=[],u=0;u<a;++u)(s=o[u])&&t.call(s,s.__data__,u,o)&&l.push(s);return new Yn(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,r=n.length,s=Math.min(i,r),o=new Array(i),a=0;a<s;++a)for(var l,u=e[a],c=n[a],h=u.length,f=o[a]=new Array(h),d=0;d<h;++d)(l=u[d]||c[d])&&(f[d]=l);for(;a<i;++a)o[a]=e[a];return new Yn(o,this._parents,this._name,this._id)},selection:function(){return new Fn(this._groups,this._parents)},transition:function(){for(var t=this._name,e=this._id,n=Bn(),i=this._groups,r=i.length,s=0;s<r;++s)for(var o,a=i[s],l=a.length,u=0;u<l;++u)if(o=a[u]){var c=xn(o,e);vn(o,t,n,u,a,{time:c.time+c.delay+c.duration,delay:0,duration:c.duration,ease:c.ease})}return new Yn(i,this._parents,t,n)},call:Vn.call,nodes:Vn.nodes,node:Vn.node,size:Vn.size,empty:Vn.empty,each:Vn.each,on:function(t,e){var n=this._id;return arguments.length<2?xn(this.node(),n).on.on(t):this.each(function(t,e,n){var i,r,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)?yn:bn;return function(){var o=s(this,t),a=o.on;a!==i&&(r=(i=a).copy()).on(e,n),o.on=r}}(n,t,e))},attr:function(t,e){var n=$(t),i="transform"===n?Ze:Tn;return this.attrTween(t,"function"==typeof e?(n.local?$n:zn)(n,i,Sn(this,"attr."+t,e)):null==e?(n.local?An:En)(n):(n.local?Cn:kn)(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=$(t);return this.tween(n,(i.local?Dn:On)(i,e))},style:function(t,e,n){var i="transform"==(t+="")?Xe:Tn;return null==e?this.styleTween(t,function(t,e){var n,i,r;return function(){var s=ct(this,t),o=(this.style.removeProperty(t),ct(this,t));return s===o?null:s===n&&o===i?r:r=e(n=s,i=o)}}(t,i)).on("end.style."+t,jn(t)):"function"==typeof e?this.styleTween(t,function(t,e,n){var i,r,s;return function(){var o=ct(this,t),a=n(this),l=a+"";return null==a&&(this.style.removeProperty(t),l=a=ct(this,t)),o===l?null:o===i&&l===r?s:(r=l,s=e(i=o,a))}}(t,i,Sn(this,"style."+t,e))).each(function(t,e){var n,i,r,s,o="style."+e,a="end."+o;return function(){var l=bn(this,t),u=l.on,c=null==l.value[o]?s||(s=jn(e)):void 0;u===n&&r===c||(i=(n=u).copy()).on(a,r=c),l.on=i}}(this._id,t)):this.styleTween(t,function(t,e,n){var i,r,s=n+"";return function(){var o=ct(this,t);return o===s?null:o===i?r:r=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,r;function s(){var s=e.apply(this,arguments);return s!==r&&(i=(r=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}}(Sn(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",function(t){return function(){var e=this.parentNode;for(var n in this.__transition)if(+n!==t)return;e&&e.removeChild(this)}}(this._id))},tween:function(t,e){var n=this._id;if(t+="",arguments.length<2){for(var i,r=xn(this.node(),n).tween,s=0,o=r.length;s<o;++s)if((i=r[s]).name===t)return i.value;return null}return this.each((null==e?Nn:Mn)(n,t,e))},delay:function(t){var e=this._id;return arguments.length?this.each(("function"==typeof t?Pn:In)(e,t)):xn(this.node(),e).delay},duration:function(t){var e=this._id;return arguments.length?this.each(("function"==typeof t?Ln:Un)(e,t)):xn(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(){bn(this,t).ease=e}}(e,t)):xn(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;bn(this,t).ease=n}}(this._id,t))},end:function(){var t,e,n=this,i=n._id,r=n.size();return new Promise(function(s,o){var a={value:o},l={value:function(){0===--r&&s()}};n.each(function(){var n=bn(this,i),r=n.on;r!==t&&((e=(t=r).copy())._.cancel.push(a),e._.interrupt.push(a),e._.end.push(l)),n.on=e}),0===r&&s()})},[Symbol.iterator]:Vn[Symbol.iterator]};var Rn={time:null,delay:0,duration:250,ease:function(t){return((t*=2)<=1?t*t*t:(t-=2)*t*t+2)/2}};function qn(t,e){for(var n;!(n=t.__transition)||!(n=n[e]);)if(!(t=t.parentNode))throw new Error(`transition ${e} not found`);return n}Ht.prototype.interrupt=function(t){return this.each(function(){wn(this,t)})},Ht.prototype.transition=function(t){var e,n;t instanceof Yn?(e=t._id,t=t._name):(e=Bn(),(n=Rn).time=ln(),t=null==t?null:t+"");for(var i=this._groups,r=i.length,s=0;s<r;++s)for(var o,a=i[s],l=a.length,u=0;u<l;++u)(o=a[u])&&vn(o,t,e,u,a,n||qn(o,e));return new Yn(i,this._parents,t,e)};var Xn=t=>()=>t;function Zn(t,{sourceEvent:e,target:n,selection:i,mode:r,dispatch:s}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},selection:{value:i,enumerable:!0,configurable:!0},mode:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function Wn(t){t.preventDefault(),t.stopImmediatePropagation()}var Gn={name:"drag"},Kn={name:"space"},Jn={name:"handle"},Qn={name:"center"};const{abs:ti,max:ei,min:ni}=Math;function ii(t){return[+t[0],+t[1]]}function ri(t){return[ii(t[0]),ii(t[1])]}var si={name:"x",handles:["w","e"].map(di),input:function(t,e){return null==t?null:[[+t[0],e[0][1]],[+t[1],e[1][1]]]},output:function(t){return t&&[t[0][0],t[1][0]]}},oi={name:"y",handles:["n","s"].map(di),input:function(t,e){return null==t?null:[[e[0][0],+t[0]],[e[1][0],+t[1]]]},output:function(t){return t&&[t[0][1],t[1][1]]}},ai={name:"xy",handles:["n","w","e","s","nw","ne","sw","se"].map(di),input:function(t){return null==t?null:ri(t)},output:function(t){return t}},li={overlay:"crosshair",selection:"move",n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"},ui={e:"w",w:"e",nw:"ne",ne:"nw",se:"sw",sw:"se"},ci={n:"s",s:"n",nw:"sw",ne:"se",se:"ne",sw:"nw"},hi={overlay:1,selection:1,n:null,e:1,s:null,w:-1,nw:-1,ne:1,se:1,sw:-1},fi={overlay:1,selection:1,n:-1,e:null,s:1,w:null,nw:-1,ne:-1,se:1,sw:1};function di(t){return{type:t}}function pi(t){return!t.ctrlKey&&!t.button}function _i(){var t=this.ownerSVGElement||this;return 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]]}function gi(){return navigator.maxTouchPoints||"ontouchstart"in this}function mi(t){for(;!t.__brush;)if(!(t=t.parentNode))return;return t.__brush}function vi(){return function(t){var e,n=_i,i=pi,r=gi,s=!0,o=T("start","brush","end"),a=6;function l(e){var n=e.property("__brush",_).selectAll(".overlay").data([di("overlay")]);n.enter().append("rect").attr("class","overlay").attr("pointer-events","all").attr("cursor",li.overlay).merge(n).each(function(){var t=mi(this).extent;Yt(this).attr("x",t[0][0]).attr("y",t[0][1]).attr("width",t[1][0]-t[0][0]).attr("height",t[1][1]-t[0][1])}),e.selectAll(".selection").data([di("selection")]).enter().append("rect").attr("class","selection").attr("cursor",li.selection).attr("fill","#777").attr("fill-opacity",.3).attr("stroke","#fff").attr("shape-rendering","crispEdges");var i=e.selectAll(".handle").data(t.handles,function(t){return t.type});i.exit().remove(),i.enter().append("rect").attr("class",function(t){return"handle handle--"+t.type}).attr("cursor",function(t){return li[t.type]}),e.each(u).attr("fill","none").attr("pointer-events","all").on("mousedown.brush",f).filter(r).on("touchstart.brush",f).on("touchmove.brush",d).on("touchend.brush touchcancel.brush",p).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function u(){var t=Yt(this),e=mi(this).selection;e?(t.selectAll(".selection").style("display",null).attr("x",e[0][0]).attr("y",e[0][1]).attr("width",e[1][0]-e[0][0]).attr("height",e[1][1]-e[0][1]),t.selectAll(".handle").style("display",null).attr("x",function(t){return"e"===t.type[t.type.length-1]?e[1][0]-a/2:e[0][0]-a/2}).attr("y",function(t){return"s"===t.type[0]?e[1][1]-a/2:e[0][1]-a/2}).attr("width",function(t){return"n"===t.type||"s"===t.type?e[1][0]-e[0][0]+a:a}).attr("height",function(t){return"e"===t.type||"w"===t.type?e[1][1]-e[0][1]+a:a})):t.selectAll(".selection,.handle").style("display","none").attr("x",null).attr("y",null).attr("width",null).attr("height",null)}function c(t,e,n){var i=t.__brush.emitter;return!i||n&&i.clean?new h(t,e,n):i}function h(t,e,n){this.that=t,this.args=e,this.state=t.__brush,this.active=0,this.clean=n}function f(n){if((!e||n.touches)&&i.apply(this,arguments)){var r,o,a,l,h,f,d,p,_,g,m,v=this,y=n.target.__data__.type,b="selection"===(s&&n.metaKey?y="overlay":y)?Gn:s&&n.altKey?Qn:Jn,x=t===oi?null:hi[y],w=t===si?null:fi[y],N=mi(v),M=N.extent,S=N.selection,T=M[0][0],E=M[0][1],A=M[1][0],k=M[1][1],C=0,z=0,$=x&&w&&s&&n.shiftKey,D=Array.from(n.touches||[n],t=>{const e=t.identifier;return(t=Bt(t,v)).point0=t.slice(),t.identifier=e,t});wn(v);var O=c(v,arguments,!0).beforestart();if("overlay"===y){S&&(_=!0);const e=[D[0],D[1]||D[0]];N.selection=S=[[r=t===oi?T:ni(e[0][0],e[1][0]),a=t===si?E:ni(e[0][1],e[1][1])],[h=t===oi?A:ei(e[0][0],e[1][0]),d=t===si?k:ei(e[0][1],e[1][1])]],D.length>1&&F(n)}else r=S[0][0],a=S[0][1],h=S[1][0],d=S[1][1];o=r,l=a,f=h,p=d;var P=Yt(v).attr("pointer-events","none"),I=P.selectAll(".overlay").attr("cursor",li[y]);if(n.touches)O.moved=U,O.ended=j;else{var L=Yt(n.view).on("mousemove.brush",U,!0).on("mouseup.brush",j,!0);s&&L.on("keydown.brush",H,!0).on("keyup.brush",Y,!0),qt(n.view)}u.call(v),O.start(n,b.name)}function U(t){for(const e of t.changedTouches||[t])for(const t of D)t.identifier===e.identifier&&(t.cur=Bt(e,v));if($&&!g&&!m&&1===D.length){const t=D[0];ti(t.cur[0]-t[0])>ti(t.cur[1]-t[1])?m=!0:g=!0}for(const t of D)t.cur&&(t[0]=t.cur[0],t[1]=t.cur[1]);_=!0,Wn(t),F(t)}function F(t){const e=D[0],n=e.point0;var i;switch(C=e[0]-n[0],z=e[1]-n[1],b){case Kn:case Gn:x&&(C=ei(T-r,ni(A-h,C)),o=r+C,f=h+C),w&&(z=ei(E-a,ni(k-d,z)),l=a+z,p=d+z);break;case Jn:D[1]?(x&&(o=ei(T,ni(A,D[0][0])),f=ei(T,ni(A,D[1][0])),x=1),w&&(l=ei(E,ni(k,D[0][1])),p=ei(E,ni(k,D[1][1])),w=1)):(x<0?(C=ei(T-r,ni(A-r,C)),o=r+C,f=h):x>0&&(C=ei(T-h,ni(A-h,C)),o=r,f=h+C),w<0?(z=ei(E-a,ni(k-a,z)),l=a+z,p=d):w>0&&(z=ei(E-d,ni(k-d,z)),l=a,p=d+z));break;case Qn:x&&(o=ei(T,ni(A,r-C*x)),f=ei(T,ni(A,h+C*x))),w&&(l=ei(E,ni(k,a-z*w)),p=ei(E,ni(k,d+z*w)))}f<o&&(x*=-1,i=r,r=h,h=i,i=o,o=f,f=i,y in ui&&I.attr("cursor",li[y=ui[y]])),p<l&&(w*=-1,i=a,a=d,d=i,i=l,l=p,p=i,y in ci&&I.attr("cursor",li[y=ci[y]])),N.selection&&(S=N.selection),g&&(o=S[0][0],f=S[1][0]),m&&(l=S[0][1],p=S[1][1]),S[0][0]===o&&S[0][1]===l&&S[1][0]===f&&S[1][1]===p||(N.selection=[[o,l],[f,p]],u.call(v),O.brush(t,b.name))}function j(t){if(function(t){t.stopImmediatePropagation()}(t),t.touches){if(t.touches.length)return;e&&clearTimeout(e),e=setTimeout(function(){e=null},500)}else Xt(t.view,_),L.on("keydown.brush keyup.brush mousemove.brush mouseup.brush",null);P.attr("pointer-events","all"),I.attr("cursor",li.overlay),N.selection&&(S=N.selection),function(t){return t[0][0]===t[1][0]||t[0][1]===t[1][1]}(S)&&(N.selection=null,u.call(v)),O.end(t,b.name)}function H(t){switch(t.keyCode){case 16:$=x&&w;break;case 18:b===Jn&&(x&&(h=f-C*x,r=o+C*x),w&&(d=p-z*w,a=l+z*w),b=Qn,F(t));break;case 32:b!==Jn&&b!==Qn||(x<0?h=f-C:x>0&&(r=o-C),w<0?d=p-z:w>0&&(a=l-z),b=Kn,I.attr("cursor",li.selection),F(t));break;default:return}Wn(t)}function Y(t){switch(t.keyCode){case 16:$&&(g=m=$=!1,F(t));break;case 18:b===Qn&&(x<0?h=f:x>0&&(r=o),w<0?d=p:w>0&&(a=l),b=Jn,F(t));break;case 32:b===Kn&&(t.altKey?(x&&(h=f-C*x,r=o+C*x),w&&(d=p-z*w,a=l+z*w),b=Qn):(x<0?h=f:x>0&&(r=o),w<0?d=p:w>0&&(a=l),b=Jn),I.attr("cursor",li[y]),F(t));break;default:return}Wn(t)}}function d(t){c(this,arguments).moved(t)}function p(t){c(this,arguments).ended(t)}function _(){var e=this.__brush||{selection:null};return e.extent=ri(n.apply(this,arguments)),e.dim=t,e}return l.move=function(e,n,i){e.tween?e.on("start.brush",function(t){c(this,arguments).beforestart().start(t)}).on("interrupt.brush end.brush",function(t){c(this,arguments).end(t)}).tween("brush",function(){var e=this,i=e.__brush,r=c(e,arguments),s=i.selection,o=t.input("function"==typeof n?n.apply(this,arguments):n,i.extent),a=je(s,o);function l(t){i.selection=1===t&&null===o?null:a(t),u.call(e),r.brush()}return null!==s&&null!==o?l:l(1)}):e.each(function(){var e=this,r=arguments,s=e.__brush,o=t.input("function"==typeof n?n.apply(e,r):n,s.extent),a=c(e,r).beforestart();wn(e),s.selection=null===o?null:o,u.call(e),a.start(i).brush(i).end(i)})},l.clear=function(t,e){l.move(t,null,e)},h.prototype={beforestart:function(){return 1===++this.active&&(this.state.emitter=this,this.starting=!0),this},start:function(t,e){return this.starting?(this.starting=!1,this.emit("start",t,e)):this.emit("brush",t),this},brush:function(t,e){return this.emit("brush",t,e),this},end:function(t,e){return 0===--this.active&&(delete this.state.emitter,this.emit("end",t,e)),this},emit:function(e,n,i){var r=Yt(this.that).datum();o.call(e,this.that,new Zn(e,{sourceEvent:n,target:l,selection:t.output(this.state.selection),mode:i,dispatch:o}),r)}},l.extent=function(t){return arguments.length?(n="function"==typeof t?t:Xn(ri(t)),l):n},l.filter=function(t){return arguments.length?(i="function"==typeof t?t:Xn(!!t),l):i},l.touchable=function(t){return arguments.length?(r="function"==typeof t?t:Xn(!!t),l):r},l.handleSize=function(t){return arguments.length?(a=+t,l):a},l.keyModifiers=function(t){return arguments.length?(s=!!t,l):s},l.on=function(){var t=o.on.apply(o,arguments);return t===o?l:t},l}(ai)}const yi=Math.PI,bi=2*yi,xi=1e-6,wi=bi-xi;function Ni(t){this._+=t[0];for(let e=1,n=t.length;e<n;++e)this._+=arguments[e]+t[e]}class Mi{constructor(t){this._x0=this._y0=this._x1=this._y1=null,this._="",this._append=null==t?Ni:function(t){let e=Math.floor(t);if(!(e>=0))throw new Error(`invalid digits: ${t}`);if(e>15)return Ni;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,r,s){this._append`C${+t},${+e},${+n},${+i},${this._x1=+r},${this._y1=+s}`}arcTo(t,e,n,i,r){if(t=+t,e=+e,n=+n,i=+i,(r=+r)<0)throw new Error(`negative radius: ${r}`);let s=this._x1,o=this._y1,a=n-t,l=i-e,u=s-t,c=o-e,h=u*u+c*c;if(null===this._x1)this._append`M${this._x1=t},${this._y1=e}`;else if(h>xi)if(Math.abs(c*a-l*u)>xi&&r){let f=n-s,d=i-o,p=a*a+l*l,_=f*f+d*d,g=Math.sqrt(p),m=Math.sqrt(h),v=r*Math.tan((yi-Math.acos((p+h-_)/(2*g*m)))/2),y=v/m,b=v/g;Math.abs(y-1)>xi&&this._append`L${t+y*u},${e+y*c}`,this._append`A${r},${r},0,0,${+(c*f>u*d)},${this._x1=t+b*a},${this._y1=e+b*l}`}else this._append`L${this._x1=t},${this._y1=e}`;else;}arc(t,e,n,i,r,s){if(t=+t,e=+e,s=!!s,(n=+n)<0)throw new Error(`negative radius: ${n}`);let o=n*Math.cos(i),a=n*Math.sin(i),l=t+o,u=e+a,c=1^s,h=s?i-r:r-i;null===this._x1?this._append`M${l},${u}`:(Math.abs(this._x1-l)>xi||Math.abs(this._y1-u)>xi)&&this._append`L${l},${u}`,n&&(h<0&&(h=h%bi+bi),h>wi?this._append`A${n},${n},0,1,${c},${t-o},${e-a}A${n},${n},0,1,${c},${this._x1=l},${this._y1=u}`:h>xi&&this._append`A${n},${n},0,${+(h>=yi)},${c},${this._x1=t+n*Math.cos(r)},${this._y1=e+n*Math.sin(r)}`)}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 Si(t,e){if((n=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var n,i=t.slice(0,n);return[i.length>1?i[0]+i.slice(2):i,+t.slice(n+1)]}function Ti(t){return(t=Si(Math.abs(t)))?t[1]:NaN}var Ei,Ai=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function ki(t){if(!(e=Ai.exec(t)))throw new Error("invalid format: "+t);var e;return new Ci({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}function Ci(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}function zi(t,e){var n=Si(t,e);if(!n)return t+"";var i=n[0],r=n[1];return r<0?"0."+new Array(-r).join("0")+i:i.length>r+1?i.slice(0,r+1)+"."+i.slice(r+1):i+new Array(r-i.length+2).join("0")}ki.prototype=Ci.prototype,Ci.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};var $i={"%":(t,e)=>(100*t).toFixed(e),b:t=>Math.round(t).toString(2),c:t=>t+"",d:function(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)},e:(t,e)=>t.toExponential(e),f:(t,e)=>t.toFixed(e),g:(t,e)=>t.toPrecision(e),o:t=>Math.round(t).toString(8),p:(t,e)=>zi(100*t,e),r:zi,s:function(t,e){var n=Si(t,e);if(!n)return t+"";var i=n[0],r=n[1],s=r-(Ei=3*Math.max(-8,Math.min(8,Math.floor(r/3))))+1,o=i.length;return s===o?i:s>o?i+new Array(s-o+1).join("0"):s>0?i.slice(0,s)+"."+i.slice(s):"0."+new Array(1-s).join("0")+Si(t,Math.max(0,e+s-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function Di(t){return t}var Oi,Pi,Ii,Li=Array.prototype.map,Ui=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Fi(t){var e,n,i=void 0===t.grouping||void 0===t.thousands?Di:(e=Li.call(t.grouping,Number),n=t.thousands+"",function(t,i){for(var r=t.length,s=[],o=0,a=e[0],l=0;r>0&&a>0&&(l+a+1>i&&(a=Math.max(1,i-l)),s.push(t.substring(r-=a,r+a)),!((l+=a+1)>i));)a=e[o=(o+1)%e.length];return s.reverse().join(n)}),r=void 0===t.currency?"":t.currency[0]+"",s=void 0===t.currency?"":t.currency[1]+"",o=void 0===t.decimal?".":t.decimal+"",a=void 0===t.numerals?Di:function(t){return function(e){return e.replace(/[0-9]/g,function(e){return t[+e]})}}(Li.call(t.numerals,String)),l=void 0===t.percent?"%":t.percent+"",u=void 0===t.minus?"−":t.minus+"",c=void 0===t.nan?"NaN":t.nan+"";function h(t){var e=(t=ki(t)).fill,n=t.align,h=t.sign,f=t.symbol,d=t.zero,p=t.width,_=t.comma,g=t.precision,m=t.trim,v=t.type;"n"===v?(_=!0,v="g"):$i[v]||(void 0===g&&(g=12),m=!0,v="g"),(d||"0"===e&&"="===n)&&(d=!0,e="0",n="=");var y="$"===f?r:"#"===f&&/[boxX]/.test(v)?"0"+v.toLowerCase():"",b="$"===f?s:/[%p]/.test(v)?l:"",x=$i[v],w=/[defgprs%]/.test(v);function N(t){var r,s,l,f=y,N=b;if("c"===v)N=x(t)+N,t="";else{var M=(t=+t)<0||1/t<0;if(t=isNaN(t)?c:x(Math.abs(t),g),m&&(t=function(t){t:for(var e,n=t.length,i=1,r=-1;i<n;++i)switch(t[i]){case".":r=e=i;break;case"0":0===r&&(r=i),e=i;break;default:if(!+t[i])break t;r>0&&(r=0)}return r>0?t.slice(0,r)+t.slice(e+1):t}(t)),M&&0===+t&&"+"!==h&&(M=!1),f=(M?"("===h?h:u:"-"===h||"("===h?"":h)+f,N=("s"===v?Ui[8+Ei/3]:"")+N+(M&&"("===h?")":""),w)for(r=-1,s=t.length;++r<s;)if(48>(l=t.charCodeAt(r))||l>57){N=(46===l?o+t.slice(r+1):t.slice(r))+N,t=t.slice(0,r);break}}_&&!d&&(t=i(t,1/0));var S=f.length+t.length+N.length,T=S<p?new Array(p-S+1).join(e):"";switch(_&&d&&(t=i(T+t,T.length?p-N.length:1/0),T=""),n){case"<":t=f+t+N+T;break;case"=":t=f+T+t+N;break;case"^":t=T.slice(0,S=T.length>>1)+f+t+N+T.slice(S);break;default:t=T+f+t+N}return a(t)}return g=void 0===g?6:/[gprs]/.test(v)?Math.max(1,Math.min(21,g)):Math.max(0,Math.min(20,g)),N.toString=function(){return t+""},N}return{format:h,formatPrefix:function(t,e){var n=h(((t=ki(t)).type="f",t)),i=3*Math.max(-8,Math.min(8,Math.floor(Ti(e)/3))),r=Math.pow(10,-i),s=Ui[8+i/3];return function(t){return n(r*t)+s}}}}function ji(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 Hi(t,e){t instanceof Map?(t=[void 0,t],void 0===e&&(e=Bi)):void 0===e&&(e=Yi);for(var n,i,r,s,o,a=new qi(t),l=[a];n=l.pop();)if((r=e(n.data))&&(o=(r=Array.from(r)).length))for(n.children=r,s=o-1;s>=0;--s)l.push(i=r[s]=new qi(r[s])),i.parent=n,i.depth=n.depth+1;return a.eachBefore(Ri)}function Yi(t){return t.children}function Bi(t){return Array.isArray(t)?t[1]:null}function Vi(t){void 0!==t.data.value&&(t.value=t.data.value),t.data=t.data.data}function Ri(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function qi(t){this.data=t,this.depth=this.height=0,this.parent=null}function Xi(t,e){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(e).domain(t)}return this}function Zi(t){return+t}Oi=Fi({thousands:",",grouping:[3],currency:["$",""]}),Pi=Oi.format,Ii=Oi.formatPrefix,qi.prototype=Hi.prototype={constructor:qi,count:function(){return this.eachAfter(ji)},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,r,s=this,o=[s],a=[],l=-1;s=o.pop();)if(a.push(s),n=s.children)for(i=0,r=n.length;i<r;++i)o.push(n[i]);for(;s=a.pop();)t.call(e,s,++l,this);return this},eachBefore:function(t,e){for(var n,i,r=this,s=[r],o=-1;r=s.pop();)if(t.call(e,r,++o,this),n=r.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,r=i&&i.length;--r>=0;)n+=i[r].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(),r=null;t=n.pop(),e=i.pop();for(;t===e;)r=t,t=n.pop(),e=i.pop();return r}(e,t),i=[e];e!==n;)e=e.parent,i.push(e);for(var r=i.length;t!==n;)i.splice(r,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 Hi(this).eachBefore(Vi)},[Symbol.iterator]:function*(){var t,e,n,i,r=this,s=[r];do{for(t=s.reverse(),s=[];r=t.pop();)if(yield r,e=r.children)for(n=0,i=e.length;n<i;++n)s.push(e[n])}while(s.length)}};var Wi=[0,1];function Gi(t){return t}function Ki(t,e){return(e-=t=+t)?function(n){return(n-t)/e}:function(t){return function(){return t}}(isNaN(e)?NaN:.5)}function Ji(t,e,n){var i=t[0],r=t[1],s=e[0],o=e[1];return r<i?(i=Ki(r,i),s=n(o,s)):(i=Ki(i,r),s=n(s,o)),function(t){return s(i(t))}}function Qi(t,e,n){var i=Math.min(t.length,e.length)-1,r=new Array(i),s=new Array(i),o=-1;for(t[i]<t[0]&&(t=t.slice().reverse(),e=e.slice().reverse());++o<i;)r[o]=Ki(t[o],t[o+1]),s[o]=n(e[o],e[o+1]);return function(e){var n=h(t,e,1,i)-1;return s[n](r[n](e))}}function tr(){var t,e,n,i,r,s,o=Wi,a=Wi,l=je,u=Gi;function c(){var t,e,n,l=Math.min(o.length,a.length);return u!==Gi&&(t=o[0],e=o[l-1],t>e&&(n=t,t=e,e=n),u=function(n){return Math.max(t,Math.min(e,n))}),i=l>2?Qi:Ji,r=s=null,h}function h(e){return null==e||isNaN(e=+e)?n:(r||(r=i(o.map(t),a,l)))(t(u(e)))}return h.invert=function(n){return u(e((s||(s=i(a,o.map(t),Pe)))(n)))},h.domain=function(t){return arguments.length?(o=Array.from(t,Zi),c()):o.slice()},h.range=function(t){return arguments.length?(a=Array.from(t),c()):a.slice()},h.rangeRound=function(t){return a=Array.from(t),l=He,c()},h.clamp=function(t){return arguments.length?(u=!!t||Gi,c()):u!==Gi},h.interpolate=function(t){return arguments.length?(l=t,c()):l},h.unknown=function(t){return arguments.length?(n=t,h):n},function(n,i){return t=n,e=i,c()}}function er(t,e,n,i){var r,s=function(t,e,n){n=+n;const i=(e=+e)<(t=+t),r=i?g(e,t,n):g(t,e,n);return(i?-1:1)*(r<0?1/-r:r)}(t,e,n);switch((i=ki(null==i?",f":i)).type){case"s":var o=Math.max(Math.abs(t),Math.abs(e));return null!=i.precision||isNaN(r=function(t,e){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(Ti(e)/3)))-Ti(Math.abs(t)))}(s,o))||(i.precision=r),Ii(i,o);case"":case"e":case"g":case"p":case"r":null!=i.precision||isNaN(r=function(t,e){return t=Math.abs(t),e=Math.abs(e)-t,Math.max(0,Ti(e)-Ti(t))+1}(s,Math.max(Math.abs(t),Math.abs(e))))||(i.precision=r-("e"===i.type));break;case"f":case"%":null!=i.precision||isNaN(r=function(t){return Math.max(0,-Ti(Math.abs(t)))}(s))||(i.precision=r-2*("%"===i.type))}return Pi(i)}function nr(t){var e=t.domain;return t.ticks=function(t){var n=e();return function(t,e,n){if(!((n=+n)>0))return[];if((t=+t)===(e=+e))return[t];const i=e<t,[r,s,o]=i?_(e,t,n):_(t,e,n);if(!(s>=r))return[];const a=s-r+1,l=new Array(a);if(i)if(o<0)for(let t=0;t<a;++t)l[t]=(s-t)/-o;else for(let t=0;t<a;++t)l[t]=(s-t)*o;else if(o<0)for(let t=0;t<a;++t)l[t]=(r+t)/-o;else for(let t=0;t<a;++t)l[t]=(r+t)*o;return l}(n[0],n[n.length-1],null==t?10:t)},t.tickFormat=function(t,n){var i=e();return er(i[0],i[i.length-1],null==t?10:t,n)},t.nice=function(n){null==n&&(n=10);var i,r,s=e(),o=0,a=s.length-1,l=s[o],u=s[a],c=10;for(u<l&&(r=l,l=u,u=r,r=o,o=a,a=r);c-- >0;){if((r=g(l,u,n))===i)return s[o]=l,s[a]=u,e(s);if(r>0)l=Math.floor(l/r)*r,u=Math.ceil(u/r)*r;else{if(!(r<0))break;l=Math.ceil(l*r)/r,u=Math.floor(u*r)/r}i=r}return t},t}function ir(){var t=tr()(Gi,Gi);return t.copy=function(){return e=t,ir().domain(e.domain()).range(e.range()).interpolate(e.interpolate()).clamp(e.clamp()).unknown(e.unknown());var e},Xi.apply(t,arguments),nr(t)}const rr=new Date,sr=new Date;function or(t,e,n,i){function r(e){return t(e=0===arguments.length?new Date:new Date(+e)),e}return r.floor=e=>(t(e=new Date(+e)),e),r.ceil=n=>(t(n=new Date(n-1)),e(n,1),t(n),n),r.round=t=>{const e=r(t),n=r.ceil(t);return t-e<n-t?e:n},r.offset=(t,n)=>(e(t=new Date(+t),null==n?1:Math.floor(n)),t),r.range=(n,i,s)=>{const o=[];if(n=r.ceil(n),s=null==s?1:Math.floor(s),!(n<i&&s>0))return o;let a;do{o.push(a=new Date(+n)),e(n,s),t(n)}while(a<n&&n<i);return o},r.filter=n=>or(e=>{if(e>=e)for(;t(e),!n(e);)e.setTime(e-1)},(t,i)=>{if(t>=t)if(i<0)for(;++i<=0;)for(;e(t,-1),!n(t););else for(;--i>=0;)for(;e(t,1),!n(t););}),n&&(r.count=(e,i)=>(rr.setTime(+e),sr.setTime(+i),t(rr),t(sr),Math.floor(n(rr,sr))),r.every=t=>(t=Math.floor(t),isFinite(t)&&t>0?t>1?r.filter(i?e=>i(e)%t===0:e=>r.count(0,e)%t===0):r:null)),r}const ar=6e4,lr=864e5,ur=6048e5,cr=or(t=>t.setHours(0,0,0,0),(t,e)=>t.setDate(t.getDate()+e),(t,e)=>(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*ar)/lr,t=>t.getDate()-1);cr.range;const hr=or(t=>{t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+e)},(t,e)=>(e-t)/lr,t=>t.getUTCDate()-1);hr.range;const fr=or(t=>{t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+e)},(t,e)=>(e-t)/lr,t=>Math.floor(t/lr));function dr(t){return or(e=>{e.setDate(e.getDate()-(e.getDay()+7-t)%7),e.setHours(0,0,0,0)},(t,e)=>{t.setDate(t.getDate()+7*e)},(t,e)=>(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*ar)/ur)}fr.range;const pr=dr(0),_r=dr(1),gr=dr(2),mr=dr(3),vr=dr(4),yr=dr(5),br=dr(6);function xr(t){return or(e=>{e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-t)%7),e.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+7*e)},(t,e)=>(e-t)/ur)}pr.range,_r.range,gr.range,mr.range,vr.range,yr.range,br.range;const wr=xr(0),Nr=xr(1),Mr=xr(2),Sr=xr(3),Tr=xr(4),Er=xr(5),Ar=xr(6);wr.range,Nr.range,Mr.range,Sr.range,Tr.range,Er.range,Ar.range;const kr=or(t=>{t.setMonth(0,1),t.setHours(0,0,0,0)},(t,e)=>{t.setFullYear(t.getFullYear()+e)},(t,e)=>e.getFullYear()-t.getFullYear(),t=>t.getFullYear());kr.every=t=>isFinite(t=Math.floor(t))&&t>0?or(e=>{e.setFullYear(Math.floor(e.getFullYear()/t)*t),e.setMonth(0,1),e.setHours(0,0,0,0)},(e,n)=>{e.setFullYear(e.getFullYear()+n*t)}):null,kr.range;const Cr=or(t=>{t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCFullYear(t.getUTCFullYear()+e)},(t,e)=>e.getUTCFullYear()-t.getUTCFullYear(),t=>t.getUTCFullYear());function zr(t){if(0<=t.y&&t.y<100){var e=new Date(-1,t.m,t.d,t.H,t.M,t.S,t.L);return e.setFullYear(t.y),e}return new Date(t.y,t.m,t.d,t.H,t.M,t.S,t.L)}function $r(t){if(0<=t.y&&t.y<100){var e=new Date(Date.UTC(-1,t.m,t.d,t.H,t.M,t.S,t.L));return e.setUTCFullYear(t.y),e}return new Date(Date.UTC(t.y,t.m,t.d,t.H,t.M,t.S,t.L))}function Dr(t,e,n){return{y:t,m:e,d:n,H:0,M:0,S:0,L:0}}Cr.every=t=>isFinite(t=Math.floor(t))&&t>0?or(e=>{e.setUTCFullYear(Math.floor(e.getUTCFullYear()/t)*t),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,n)=>{e.setUTCFullYear(e.getUTCFullYear()+n*t)}):null,Cr.range;var Or,Pr,Ir={"-":"",_:" ",0:"0"},Lr=/^\s*\d+/,Ur=/^%/,Fr=/[\\^$*+?|[\]().{}]/g;function jr(t,e,n){var i=t<0?"-":"",r=(i?-t:t)+"",s=r.length;return i+(s<n?new Array(n-s+1).join(e)+r:r)}function Hr(t){return t.replace(Fr,"\\$&")}function Yr(t){return new RegExp("^(?:"+t.map(Hr).join("|")+")","i")}function Br(t){return new Map(t.map((t,e)=>[t.toLowerCase(),e]))}function Vr(t,e,n){var i=Lr.exec(e.slice(n,n+1));return i?(t.w=+i[0],n+i[0].length):-1}function Rr(t,e,n){var i=Lr.exec(e.slice(n,n+1));return i?(t.u=+i[0],n+i[0].length):-1}function qr(t,e,n){var i=Lr.exec(e.slice(n,n+2));return i?(t.U=+i[0],n+i[0].length):-1}function Xr(t,e,n){var i=Lr.exec(e.slice(n,n+2));return i?(t.V=+i[0],n+i[0].length):-1}function Zr(t,e,n){var i=Lr.exec(e.slice(n,n+2));return i?(t.W=+i[0],n+i[0].length):-1}function Wr(t,e,n){var i=Lr.exec(e.slice(n,n+4));return i?(t.y=+i[0],n+i[0].length):-1}function Gr(t,e,n){var i=Lr.exec(e.slice(n,n+2));return i?(t.y=+i[0]+(+i[0]>68?1900:2e3),n+i[0].length):-1}function Kr(t,e,n){var i=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(n,n+6));return i?(t.Z=i[1]?0:-(i[2]+(i[3]||"00")),n+i[0].length):-1}function Jr(t,e,n){var i=Lr.exec(e.slice(n,n+1));return i?(t.q=3*i[0]-3,n+i[0].length):-1}function Qr(t,e,n){var i=Lr.exec(e.slice(n,n+2));return i?(t.m=i[0]-1,n+i[0].length):-1}function ts(t,e,n){var i=Lr.exec(e.slice(n,n+2));return i?(t.d=+i[0],n+i[0].length):-1}function es(t,e,n){var i=Lr.exec(e.slice(n,n+3));return i?(t.m=0,t.d=+i[0],n+i[0].length):-1}function ns(t,e,n){var i=Lr.exec(e.slice(n,n+2));return i?(t.H=+i[0],n+i[0].length):-1}function is(t,e,n){var i=Lr.exec(e.slice(n,n+2));return i?(t.M=+i[0],n+i[0].length):-1}function rs(t,e,n){var i=Lr.exec(e.slice(n,n+2));return i?(t.S=+i[0],n+i[0].length):-1}function ss(t,e,n){var i=Lr.exec(e.slice(n,n+3));return i?(t.L=+i[0],n+i[0].length):-1}function os(t,e,n){var i=Lr.exec(e.slice(n,n+6));return i?(t.L=Math.floor(i[0]/1e3),n+i[0].length):-1}function as(t,e,n){var i=Ur.exec(e.slice(n,n+1));return i?n+i[0].length:-1}function ls(t,e,n){var i=Lr.exec(e.slice(n));return i?(t.Q=+i[0],n+i[0].length):-1}function us(t,e,n){var i=Lr.exec(e.slice(n));return i?(t.s=+i[0],n+i[0].length):-1}function cs(t,e){return jr(t.getDate(),e,2)}function hs(t,e){return jr(t.getHours(),e,2)}function fs(t,e){return jr(t.getHours()%12||12,e,2)}function ds(t,e){return jr(1+cr.count(kr(t),t),e,3)}function ps(t,e){return jr(t.getMilliseconds(),e,3)}function _s(t,e){return ps(t,e)+"000"}function gs(t,e){return jr(t.getMonth()+1,e,2)}function ms(t,e){return jr(t.getMinutes(),e,2)}function vs(t,e){return jr(t.getSeconds(),e,2)}function ys(t){var e=t.getDay();return 0===e?7:e}function bs(t,e){return jr(pr.count(kr(t)-1,t),e,2)}function xs(t){var e=t.getDay();return e>=4||0===e?vr(t):vr.ceil(t)}function ws(t,e){return t=xs(t),jr(vr.count(kr(t),t)+(4===kr(t).getDay()),e,2)}function Ns(t){return t.getDay()}function Ms(t,e){return jr(_r.count(kr(t)-1,t),e,2)}function Ss(t,e){return jr(t.getFullYear()%100,e,2)}function Ts(t,e){return jr((t=xs(t)).getFullYear()%100,e,2)}function Es(t,e){return jr(t.getFullYear()%1e4,e,4)}function As(t,e){var n=t.getDay();return jr((t=n>=4||0===n?vr(t):vr.ceil(t)).getFullYear()%1e4,e,4)}function ks(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+jr(e/60|0,"0",2)+jr(e%60,"0",2)}function Cs(t,e){return jr(t.getUTCDate(),e,2)}function zs(t,e){return jr(t.getUTCHours(),e,2)}function $s(t,e){return jr(t.getUTCHours()%12||12,e,2)}function Ds(t,e){return jr(1+hr.count(Cr(t),t),e,3)}function Os(t,e){return jr(t.getUTCMilliseconds(),e,3)}function Ps(t,e){return Os(t,e)+"000"}function Is(t,e){return jr(t.getUTCMonth()+1,e,2)}function Ls(t,e){return jr(t.getUTCMinutes(),e,2)}function Us(t,e){return jr(t.getUTCSeconds(),e,2)}function Fs(t){var e=t.getUTCDay();return 0===e?7:e}function js(t,e){return jr(wr.count(Cr(t)-1,t),e,2)}function Hs(t){var e=t.getUTCDay();return e>=4||0===e?Tr(t):Tr.ceil(t)}function Ys(t,e){return t=Hs(t),jr(Tr.count(Cr(t),t)+(4===Cr(t).getUTCDay()),e,2)}function Bs(t){return t.getUTCDay()}function Vs(t,e){return jr(Nr.count(Cr(t)-1,t),e,2)}function Rs(t,e){return jr(t.getUTCFullYear()%100,e,2)}function qs(t,e){return jr((t=Hs(t)).getUTCFullYear()%100,e,2)}function Xs(t,e){return jr(t.getUTCFullYear()%1e4,e,4)}function Zs(t,e){var n=t.getUTCDay();return jr((t=n>=4||0===n?Tr(t):Tr.ceil(t)).getUTCFullYear()%1e4,e,4)}function Ws(){return"+0000"}function Gs(){return"%"}function Ks(t){return+t}function Js(t){return Math.floor(+t/1e3)}function Qs(t){return function(){return t}}function to(t){this._context=t}function eo(t){return new to(t)}function no(t){return t[0]}function io(t){return t[1]}function ro(t,e){var n=Qs(!0),i=null,r=eo,s=null,o=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 Mi(e)}(a);function a(a){var l,u,c,h=(a=function(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}(a)).length,f=!1;for(null==i&&(s=r(c=o())),l=0;l<=h;++l)!(l<h&&n(u=a[l],l,a))===f&&((f=!f)?s.lineStart():s.lineEnd()),f&&s.point(+t(u,l,a),+e(u,l,a));if(c)return s=null,c+""||null}return t="function"==typeof t?t:void 0===t?no:Qs(t),e="function"==typeof e?e:void 0===e?io:Qs(e),a.x=function(e){return arguments.length?(t="function"==typeof e?e:Qs(+e),a):t},a.y=function(t){return arguments.length?(e="function"==typeof t?t:Qs(+t),a):e},a.defined=function(t){return arguments.length?(n="function"==typeof t?t:Qs(!!t),a):n},a.curve=function(t){return arguments.length?(r=t,null!=i&&(s=r(i)),a):r},a.context=function(t){return arguments.length?(null==t?i=s=null:s=r(i=t),a):i},a}function so(t,e,n){t._context.bezierCurveTo((2*t._x0+t._x1)/3,(2*t._y0+t._y1)/3,(t._x0+2*t._x1)/3,(t._y0+2*t._y1)/3,(t._x0+4*t._x1+e)/6,(t._y0+4*t._y1+n)/6)}function oo(t){this._context=t}function ao(t){return new oo(t)}function lo(t,e){this._context=t,this._t=e}!function(t){Or=function(t){var e=t.dateTime,n=t.date,i=t.time,r=t.periods,s=t.days,o=t.shortDays,a=t.months,l=t.shortMonths,u=Yr(r),c=Br(r),h=Yr(s),f=Br(s),d=Yr(o),p=Br(o),_=Yr(a),g=Br(a),m=Yr(l),v=Br(l),y={a:function(t){return o[t.getDay()]},A:function(t){return s[t.getDay()]},b:function(t){return l[t.getMonth()]},B:function(t){return a[t.getMonth()]},c:null,d:cs,e:cs,f:_s,g:Ts,G:As,H:hs,I:fs,j:ds,L:ps,m:gs,M:ms,p:function(t){return r[+(t.getHours()>=12)]},q:function(t){return 1+~~(t.getMonth()/3)},Q:Ks,s:Js,S:vs,u:ys,U:bs,V:ws,w:Ns,W:Ms,x:null,X:null,y:Ss,Y:Es,Z:ks,"%":Gs},b={a:function(t){return o[t.getUTCDay()]},A:function(t){return s[t.getUTCDay()]},b:function(t){return l[t.getUTCMonth()]},B:function(t){return a[t.getUTCMonth()]},c:null,d:Cs,e:Cs,f:Ps,g:qs,G:Zs,H:zs,I:$s,j:Ds,L:Os,m:Is,M:Ls,p:function(t){return r[+(t.getUTCHours()>=12)]},q:function(t){return 1+~~(t.getUTCMonth()/3)},Q:Ks,s:Js,S:Us,u:Fs,U:js,V:Ys,w:Bs,W:Vs,x:null,X:null,y:Rs,Y:Xs,Z:Ws,"%":Gs},x={a:function(t,e,n){var i=d.exec(e.slice(n));return i?(t.w=p.get(i[0].toLowerCase()),n+i[0].length):-1},A:function(t,e,n){var i=h.exec(e.slice(n));return i?(t.w=f.get(i[0].toLowerCase()),n+i[0].length):-1},b:function(t,e,n){var i=m.exec(e.slice(n));return i?(t.m=v.get(i[0].toLowerCase()),n+i[0].length):-1},B:function(t,e,n){var i=_.exec(e.slice(n));return i?(t.m=g.get(i[0].toLowerCase()),n+i[0].length):-1},c:function(t,n,i){return M(t,e,n,i)},d:ts,e:ts,f:os,g:Gr,G:Wr,H:ns,I:ns,j:es,L:ss,m:Qr,M:is,p:function(t,e,n){var i=u.exec(e.slice(n));return i?(t.p=c.get(i[0].toLowerCase()),n+i[0].length):-1},q:Jr,Q:ls,s:us,S:rs,u:Rr,U:qr,V:Xr,w:Vr,W:Zr,x:function(t,e,i){return M(t,n,e,i)},X:function(t,e,n){return M(t,i,e,n)},y:Gr,Y:Wr,Z:Kr,"%":as};function w(t,e){return function(n){var i,r,s,o=[],a=-1,l=0,u=t.length;for(n instanceof Date||(n=new Date(+n));++a<u;)37===t.charCodeAt(a)&&(o.push(t.slice(l,a)),null!=(r=Ir[i=t.charAt(++a)])?i=t.charAt(++a):r="e"===i?" ":"0",(s=e[i])&&(i=s(n,r)),o.push(i),l=a+1);return o.push(t.slice(l,a)),o.join("")}}function N(t,e){return function(n){var i,r,s=Dr(1900,void 0,1);if(M(s,t,n+="",0)!=n.length)return null;if("Q"in s)return new Date(s.Q);if("s"in s)return new Date(1e3*s.s+("L"in s?s.L:0));if(e&&!("Z"in s)&&(s.Z=0),"p"in s&&(s.H=s.H%12+12*s.p),void 0===s.m&&(s.m="q"in s?s.q:0),"V"in s){if(s.V<1||s.V>53)return null;"w"in s||(s.w=1),"Z"in s?(r=(i=$r(Dr(s.y,0,1))).getUTCDay(),i=r>4||0===r?Nr.ceil(i):Nr(i),i=hr.offset(i,7*(s.V-1)),s.y=i.getUTCFullYear(),s.m=i.getUTCMonth(),s.d=i.getUTCDate()+(s.w+6)%7):(r=(i=zr(Dr(s.y,0,1))).getDay(),i=r>4||0===r?_r.ceil(i):_r(i),i=cr.offset(i,7*(s.V-1)),s.y=i.getFullYear(),s.m=i.getMonth(),s.d=i.getDate()+(s.w+6)%7)}else("W"in s||"U"in s)&&("w"in s||(s.w="u"in s?s.u%7:"W"in s?1:0),r="Z"in s?$r(Dr(s.y,0,1)).getUTCDay():zr(Dr(s.y,0,1)).getDay(),s.m=0,s.d="W"in s?(s.w+6)%7+7*s.W-(r+5)%7:s.w+7*s.U-(r+6)%7);return"Z"in s?(s.H+=s.Z/100|0,s.M+=s.Z%100,$r(s)):zr(s)}}function M(t,e,n,i){for(var r,s,o=0,a=e.length,l=n.length;o<a;){if(i>=l)return-1;if(37===(r=e.charCodeAt(o++))){if(r=e.charAt(o++),!(s=x[r in Ir?e.charAt(o++):r])||(i=s(t,n,i))<0)return-1}else if(r!=n.charCodeAt(i++))return-1}return i}return y.x=w(n,y),y.X=w(i,y),y.c=w(e,y),b.x=w(n,b),b.X=w(i,b),b.c=w(e,b),{format:function(t){var e=w(t+="",y);return e.toString=function(){return t},e},parse:function(t){var e=N(t+="",!1);return e.toString=function(){return t},e},utcFormat:function(t){var e=w(t+="",b);return e.toString=function(){return t},e},utcParse:function(t){var e=N(t+="",!0);return e.toString=function(){return t},e}}}(t),Or.format,Pr=Or.parse,Or.utcFormat,Or.utcParse}({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}),to.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:this._context.lineTo(t,e)}}},oo.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:so(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:so(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}},lo.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN,this._point=0},lineEnd:function(){0<this._t&&this._t<1&&2===this._point&&this._context.lineTo(this._x,this._y),(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line>=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,e),this._context.lineTo(t,e);else{var n=this._x*(1-this._t)+t*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,e)}}this._x=t,this._y=e}};var uo=t=>()=>t;function co(t,{sourceEvent:e,target:n,transform:i,dispatch:r}){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:r}})}function ho(t,e,n){this.k=t,this.x=e,this.y=n}ho.prototype={constructor:ho,scale:function(t){return 1===t?this:new ho(this.k*t,this.x,this.y)},translate:function(t,e){return 0===t&0===e?this:new ho(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 fo=new ho(1,0,0);function po(t){t.stopImmediatePropagation()}function _o(t){t.preventDefault(),t.stopImmediatePropagation()}function go(t){return!(t.ctrlKey&&"wheel"!==t.type||t.button)}function mo(){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 vo(){return this.__zoom||fo}function yo(t){return-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function bo(){return navigator.maxTouchPoints||"ontouchstart"in this}function xo(t,e,n){var i=t.invertX(e[0][0])-n[0][0],r=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(r>i?(i+r)/2:Math.min(0,i)||Math.max(0,r),o>s?(s+o)/2:Math.min(0,s)||Math.max(0,o))}ho.prototype;const wo=":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",No=new RegExp("^"+("["+wo+"]["+(wo+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040")+"]*")+"$");function Mo(t,e){const n=[];let i=e.exec(t);for(;i;){const r=[];r.startIndex=e.lastIndex-i[0].length;const s=i.length;for(let t=0;t<s;t++)r.push(i[t]);n.push(r),i=e.exec(t)}return n}const So=function(t){const e=No.exec(t);return!(null==e)};const To={allowBooleanAttributes:!1,unpairedTags:[]};function Eo(t){return" "===t||"\t"===t||"\n"===t||"\r"===t}function Ao(t,e){const n=e;for(;e<t.length;e++)if("?"==t[e]||" "==t[e]){const i=t.substr(n,e-n);if(e>5&&"xml"===i)return Io("InvalidXml","XML declaration allowed only at the start of the document.",Fo(t,e));if("?"==t[e]&&">"==t[e+1]){e++;break}continue}return e}function ko(t,e){if(t.length>e+5&&"-"===t[e+1]&&"-"===t[e+2]){for(e+=3;e<t.length;e++)if("-"===t[e]&&"-"===t[e+1]&&">"===t[e+2]){e+=2;break}}else if(t.length>e+8&&"D"===t[e+1]&&"O"===t[e+2]&&"C"===t[e+3]&&"T"===t[e+4]&&"Y"===t[e+5]&&"P"===t[e+6]&&"E"===t[e+7]){let n=1;for(e+=8;e<t.length;e++)if("<"===t[e])n++;else if(">"===t[e]&&(n--,0===n))break}else if(t.length>e+9&&"["===t[e+1]&&"C"===t[e+2]&&"D"===t[e+3]&&"A"===t[e+4]&&"T"===t[e+5]&&"A"===t[e+6]&&"["===t[e+7])for(e+=8;e<t.length;e++)if("]"===t[e]&&"]"===t[e+1]&&">"===t[e+2]){e+=2;break}return e}const Co='"',zo="'";function $o(t,e){let n="",i="",r=!1;for(;e<t.length;e++){if(t[e]===Co||t[e]===zo)""===i?i=t[e]:i!==t[e]||(i="");else if(">"===t[e]&&""===i){r=!0;break}n+=t[e]}return""===i&&{value:n,index:e,tagClosed:r}}const Do=new RegExp("(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['\"])(([\\s\\S])*?)\\5)?","g");function Oo(t,e){const n=Mo(t,Do),i={};for(let t=0;t<n.length;t++){if(0===n[t][1].length)return Io("InvalidAttr","Attribute '"+n[t][2]+"' has no space in starting.",jo(n[t]));if(void 0!==n[t][3]&&void 0===n[t][4])return Io("InvalidAttr","Attribute '"+n[t][2]+"' is without value.",jo(n[t]));if(void 0===n[t][3]&&!e.allowBooleanAttributes)return Io("InvalidAttr","boolean attribute '"+n[t][2]+"' is not allowed.",jo(n[t]));const r=n[t][2];if(!Lo(r))return Io("InvalidAttr","Attribute '"+r+"' is an invalid name.",jo(n[t]));if(i.hasOwnProperty(r))return Io("InvalidAttr","Attribute '"+r+"' is repeated.",jo(n[t]));i[r]=1}return!0}function Po(t,e){if(";"===t[++e])return-1;if("#"===t[e])return function(t,e){let n=/\d/;for("x"===t[e]&&(e++,n=/[\da-fA-F]/);e<t.length;e++){if(";"===t[e])return e;if(!t[e].match(n))break}return-1}(t,++e);let n=0;for(;e<t.length;e++,n++)if(!(t[e].match(/\w/)&&n<20)){if(";"===t[e])break;return-1}return e}function Io(t,e,n){return{err:{code:t,msg:e,line:n.line||n,col:n.col}}}function Lo(t){return So(t)}function Uo(t){return So(t)}function Fo(t,e){const n=t.substring(0,e).split(/\r?\n/);return{line:n.length,col:n[n.length-1].length+1}}function jo(t){return t.startIndex+t[1].length}const Ho={preserveOrder:!1,attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(t,e,n){return t},captureMetaData:!1};let Yo;Yo="function"!=typeof Symbol?"@@xmlMetadata":Symbol("XML Node Metadata");class Bo{constructor(t){this.tagname=t,this.child=[],this[":@"]={}}add(t,e){"__proto__"===t&&(t="#__proto__"),this.child.push({[t]:e})}addChild(t,e){"__proto__"===t.tagname&&(t.tagname="#__proto__"),t[":@"]&&Object.keys(t[":@"]).length>0?this.child.push({[t.tagname]:t.child,":@":t[":@"]}):this.child.push({[t.tagname]:t.child}),void 0!==e&&(this.child[this.child.length-1][Yo]={startIndex:e})}static getMetaDataSymbol(){return Yo}}function Vo(t,e){const n={};if("O"!==t[e+3]||"C"!==t[e+4]||"T"!==t[e+5]||"Y"!==t[e+6]||"P"!==t[e+7]||"E"!==t[e+8])throw new Error("Invalid Tag instead of DOCTYPE");{e+=9;let i=1,r=!1,s=!1,o="";for(;e<t.length;e++)if("<"!==t[e]||s)if(">"===t[e]){if(s?"-"===t[e-1]&&"-"===t[e-2]&&(s=!1,i--):i--,0===i)break}else"["===t[e]?r=!0:o+=t[e];else{if(r&&Go(t,"!ENTITY",e)){let i,r;e+=7,[i,r,e]=qo(t,e+1),-1===r.indexOf("&")&&(n[i]={regx:RegExp(`&${i};`,"g"),val:r})}else if(r&&Go(t,"!ELEMENT",e)){e+=8;const{index:n}=Wo(t,e+1);e=n}else if(r&&Go(t,"!ATTLIST",e))e+=8;else if(r&&Go(t,"!NOTATION",e)){e+=9;const{index:n}=Xo(t,e+1);e=n}else{if(!Go(t,"!--",e))throw new Error("Invalid DOCTYPE");s=!0}i++,o=""}if(0!==i)throw new Error("Unclosed DOCTYPE")}return{entities:n,i:e}}const Ro=(t,e)=>{for(;e<t.length&&/\s/.test(t[e]);)e++;return e};function qo(t,e){e=Ro(t,e);let n="";for(;e<t.length&&!/\s/.test(t[e])&&'"'!==t[e]&&"'"!==t[e];)n+=t[e],e++;if(Ko(n),e=Ro(t,e),"SYSTEM"===t.substring(e,e+6).toUpperCase())throw new Error("External entities are not supported");if("%"===t[e])throw new Error("Parameter entities are not supported");let i="";return[e,i]=Zo(t,e,"entity"),[n,i,--e]}function Xo(t,e){e=Ro(t,e);let n="";for(;e<t.length&&!/\s/.test(t[e]);)n+=t[e],e++;Ko(n),e=Ro(t,e);const i=t.substring(e,e+6).toUpperCase();if("SYSTEM"!==i&&"PUBLIC"!==i)throw new Error(`Expected SYSTEM or PUBLIC, found "${i}"`);e+=i.length,e=Ro(t,e);let r=null,s=null;if("PUBLIC"===i)[e,r]=Zo(t,e,"publicIdentifier"),'"'!==t[e=Ro(t,e)]&&"'"!==t[e]||([e,s]=Zo(t,e,"systemIdentifier"));else if("SYSTEM"===i&&([e,s]=Zo(t,e,"systemIdentifier"),!s))throw new Error("Missing mandatory system identifier for SYSTEM notation");return{notationName:n,publicIdentifier:r,systemIdentifier:s,index:--e}}function Zo(t,e,n){let i="";const r=t[e];if('"'!==r&&"'"!==r)throw new Error(`Expected quoted string, found "${r}"`);for(e++;e<t.length&&t[e]!==r;)i+=t[e],e++;if(t[e]!==r)throw new Error(`Unterminated ${n} value`);return[++e,i]}function Wo(t,e){e=Ro(t,e);let n="";for(;e<t.length&&!/\s/.test(t[e]);)n+=t[e],e++;if(!Ko(n))throw new Error(`Invalid element name: "${n}"`);let i="";if("E"===t[e=Ro(t,e)]&&Go(t,"MPTY",e))e+=4;else if("A"===t[e]&&Go(t,"NY",e))e+=2;else{if("("!==t[e])throw new Error(`Invalid Element Expression, found "${t[e]}"`);for(e++;e<t.length&&")"!==t[e];)i+=t[e],e++;if(")"!==t[e])throw new Error("Unterminated content model")}return{elementName:n,contentModel:i.trim(),index:e}}function Go(t,e,n){for(let i=0;i<e.length;i++)if(e[i]!==t[n+i+1])return!1;return!0}function Ko(t){if(So(t))return t;throw new Error(`Invalid entity name ${t}`)}const Jo=/^[-+]?0x[a-fA-F0-9]+$/,Qo=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,ta={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};function ea(t,e={}){if(e=Object.assign({},ta,e),!t||"string"!=typeof t)return t;let n=t.trim();if(void 0!==e.skipLike&&e.skipLike.test(n))return t;if("0"===t)return 0;if(e.hex&&Jo.test(n))return function(t,e){if(parseInt)return parseInt(t,e);if(Number.parseInt)return Number.parseInt(t,e);if(window&&window.parseInt)return window.parseInt(t,e);throw new Error("parseInt, Number.parseInt, window.parseInt are not supported")}(n,16);if(-1!==n.search(/.+[eE].+/))return function(t,e,n){if(!n.eNotation)return t;const i=e.match(na);if(i){let r=i[1]||"";const s=-1===i[3].indexOf("e")?"E":"e",o=i[2],a=r?t[o.length+1]===s:t[o.length]===s;return o.length>1&&a?t:1!==o.length||!i[3].startsWith(`.${s}`)&&i[3][0]!==s?n.leadingZeros&&!a?(e=(i[1]||"")+i[3],Number(e)):t:Number(e)}return t}(t,n,e);{const i=Qo.exec(n);if(i){const r=i[1]||"",s=i[2];let o=function(t){if(t&&-1!==t.indexOf("."))return"."===(t=t.replace(/0+$/,""))?t="0":"."===t[0]?t="0"+t:"."===t[t.length-1]&&(t=t.substring(0,t.length-1)),t;return t}(i[3]);const a=r?"."===t[s.length+1]:"."===t[s.length];if(!e.leadingZeros&&(s.length>1||1===s.length&&!a))return t;{const i=Number(n),a=String(i);if(0===i)return i;if(-1!==a.search(/[eE]/))return e.eNotation?i:t;if(-1!==n.indexOf("."))return"0"===a||a===o||a===`${r}${o}`?i:t;let l=s?o:n;return s?l===a||r+l===a?i:t:l===a||l===r+a?i:t}}return t}}const na=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;class ia{constructor(t){var e;this.options=t,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:'"'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"¢"},pound:{regex:/&(pound|#163);/g,val:"£"},yen:{regex:/&(yen|#165);/g,val:"¥"},euro:{regex:/&(euro|#8364);/g,val:"€"},copyright:{regex:/&(copy|#169);/g,val:"©"},reg:{regex:/&(reg|#174);/g,val:"®"},inr:{regex:/&(inr|#8377);/g,val:"₹"},num_dec:{regex:/&#([0-9]{1,7});/g,val:(t,e)=>String.fromCodePoint(Number.parseInt(e,10))},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:(t,e)=>String.fromCodePoint(Number.parseInt(e,16))}},this.addExternalEntities=ra,this.parseXml=ua,this.parseTextData=sa,this.resolveNameSpace=oa,this.buildAttributesMap=la,this.isItStopNode=da,this.replaceEntitiesValue=ha,this.readStopNodeData=ga,this.saveTextToParentTag=fa,this.addChild=ca,this.ignoreAttributesFn="function"==typeof(e=this.options.ignoreAttributes)?e:Array.isArray(e)?t=>{for(const n of e){if("string"==typeof n&&t===n)return!0;if(n instanceof RegExp&&n.test(t))return!0}}:()=>!1}}function ra(t){const e=Object.keys(t);for(let n=0;n<e.length;n++){const i=e[n];this.lastEntities[i]={regex:new RegExp("&"+i+";","g"),val:t[i]}}}function sa(t,e,n,i,r,s,o){if(void 0!==t&&(this.options.trimValues&&!i&&(t=t.trim()),t.length>0)){o||(t=this.replaceEntitiesValue(t));const i=this.options.tagValueProcessor(e,t,n,r,s);if(null==i)return t;if(typeof i!=typeof t||i!==t)return i;if(this.options.trimValues)return ma(t,this.options.parseTagValue,this.options.numberParseOptions);return t.trim()===t?ma(t,this.options.parseTagValue,this.options.numberParseOptions):t}}function oa(t){if(this.options.removeNSPrefix){const e=t.split(":"),n="/"===t.charAt(0)?"/":"";if("xmlns"===e[0])return"";2===e.length&&(t=n+e[1])}return t}const aa=new RegExp("([^\\s=]+)\\s*(=\\s*(['\"])([\\s\\S]*?)\\3)?","gm");function la(t,e,n){if(!0!==this.options.ignoreAttributes&&"string"==typeof t){const n=Mo(t,aa),i=n.length,r={};for(let t=0;t<i;t++){const i=this.resolveNameSpace(n[t][1]);if(this.ignoreAttributesFn(i,e))continue;let s=n[t][4],o=this.options.attributeNamePrefix+i;if(i.length)if(this.options.transformAttributeName&&(o=this.options.transformAttributeName(o)),"__proto__"===o&&(o="#__proto__"),void 0!==s){this.options.trimValues&&(s=s.trim()),s=this.replaceEntitiesValue(s);const t=this.options.attributeValueProcessor(i,s,e);r[o]=null==t?s:typeof t!=typeof s||t!==s?t:ma(s,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(r[o]=!0)}if(!Object.keys(r).length)return;if(this.options.attributesGroupName){const t={};return t[this.options.attributesGroupName]=r,t}return r}}const ua=function(t){t=t.replace(/\r\n?/g,"\n");const e=new Bo("!xml");let n=e,i="",r="";for(let s=0;s<t.length;s++){if("<"===t[s])if("/"===t[s+1]){const e=pa(t,">",s,"Closing Tag is not closed.");let o=t.substring(s+2,e).trim();if(this.options.removeNSPrefix){const t=o.indexOf(":");-1!==t&&(o=o.substr(t+1))}this.options.transformTagName&&(o=this.options.transformTagName(o)),n&&(i=this.saveTextToParentTag(i,n,r));const a=r.substring(r.lastIndexOf(".")+1);if(o&&-1!==this.options.unpairedTags.indexOf(o))throw new Error(`Unpaired tag can not be used as closing tag: </${o}>`);let l=0;a&&-1!==this.options.unpairedTags.indexOf(a)?(l=r.lastIndexOf(".",r.lastIndexOf(".")-1),this.tagsNodeStack.pop()):l=r.lastIndexOf("."),r=r.substring(0,l),n=this.tagsNodeStack.pop(),i="",s=e}else if("?"===t[s+1]){let e=_a(t,s,!1,"?>");if(!e)throw new Error("Pi Tag is not closed.");if(i=this.saveTextToParentTag(i,n,r),this.options.ignoreDeclaration&&"?xml"===e.tagName||this.options.ignorePiTags);else{const t=new Bo(e.tagName);t.add(this.options.textNodeName,""),e.tagName!==e.tagExp&&e.attrExpPresent&&(t[":@"]=this.buildAttributesMap(e.tagExp,r,e.tagName)),this.addChild(n,t,r,s)}s=e.closeIndex+1}else if("!--"===t.substr(s+1,3)){const e=pa(t,"--\x3e",s+4,"Comment is not closed.");if(this.options.commentPropName){const o=t.substring(s+4,e-2);i=this.saveTextToParentTag(i,n,r),n.add(this.options.commentPropName,[{[this.options.textNodeName]:o}])}s=e}else if("!D"===t.substr(s+1,2)){const e=Vo(t,s);this.docTypeEntities=e.entities,s=e.i}else if("!["===t.substr(s+1,2)){const e=pa(t,"]]>",s,"CDATA is not closed.")-2,o=t.substring(s+9,e);i=this.saveTextToParentTag(i,n,r);let a=this.parseTextData(o,n.tagname,r,!0,!1,!0,!0);null==a&&(a=""),this.options.cdataPropName?n.add(this.options.cdataPropName,[{[this.options.textNodeName]:o}]):n.add(this.options.textNodeName,a),s=e+2}else{let o=_a(t,s,this.options.removeNSPrefix),a=o.tagName;const l=o.rawTagName;let u=o.tagExp,c=o.attrExpPresent,h=o.closeIndex;this.options.transformTagName&&(a=this.options.transformTagName(a)),n&&i&&"!xml"!==n.tagname&&(i=this.saveTextToParentTag(i,n,r,!1));const f=n;f&&-1!==this.options.unpairedTags.indexOf(f.tagname)&&(n=this.tagsNodeStack.pop(),r=r.substring(0,r.lastIndexOf("."))),a!==e.tagname&&(r+=r?"."+a:a);const d=s;if(this.isItStopNode(this.options.stopNodes,r,a)){let e="";if(u.length>0&&u.lastIndexOf("/")===u.length-1)"/"===a[a.length-1]?(a=a.substr(0,a.length-1),r=r.substr(0,r.length-1),u=a):u=u.substr(0,u.length-1),s=o.closeIndex;else if(-1!==this.options.unpairedTags.indexOf(a))s=o.closeIndex;else{const n=this.readStopNodeData(t,l,h+1);if(!n)throw new Error(`Unexpected end of ${l}`);s=n.i,e=n.tagContent}const i=new Bo(a);a!==u&&c&&(i[":@"]=this.buildAttributesMap(u,r,a)),e&&(e=this.parseTextData(e,a,r,!0,c,!0,!0)),r=r.substr(0,r.lastIndexOf(".")),i.add(this.options.textNodeName,e),this.addChild(n,i,r,d)}else{if(u.length>0&&u.lastIndexOf("/")===u.length-1){"/"===a[a.length-1]?(a=a.substr(0,a.length-1),r=r.substr(0,r.length-1),u=a):u=u.substr(0,u.length-1),this.options.transformTagName&&(a=this.options.transformTagName(a));const t=new Bo(a);a!==u&&c&&(t[":@"]=this.buildAttributesMap(u,r,a)),this.addChild(n,t,r,d),r=r.substr(0,r.lastIndexOf("."))}else{const t=new Bo(a);this.tagsNodeStack.push(n),a!==u&&c&&(t[":@"]=this.buildAttributesMap(u,r,a)),this.addChild(n,t,r,d),n=t}i="",s=h}}else i+=t[s]}return e.child};function ca(t,e,n,i){this.options.captureMetaData||(i=void 0);const r=this.options.updateTag(e.tagname,n,e[":@"]);!1===r||("string"==typeof r?(e.tagname=r,t.addChild(e,i)):t.addChild(e,i))}const ha=function(t){if(this.options.processEntities){for(let e in this.docTypeEntities){const n=this.docTypeEntities[e];t=t.replace(n.regx,n.val)}for(let e in this.lastEntities){const n=this.lastEntities[e];t=t.replace(n.regex,n.val)}if(this.options.htmlEntities)for(let e in this.htmlEntities){const n=this.htmlEntities[e];t=t.replace(n.regex,n.val)}t=t.replace(this.ampEntity.regex,this.ampEntity.val)}return t};function fa(t,e,n,i){return t&&(void 0===i&&(i=0===e.child.length),void 0!==(t=this.parseTextData(t,e.tagname,n,!1,!!e[":@"]&&0!==Object.keys(e[":@"]).length,i))&&""!==t&&e.add(this.options.textNodeName,t),t=""),t}function da(t,e,n){const i="*."+n;for(const n in t){const r=t[n];if(i===r||e===r)return!0}return!1}function pa(t,e,n,i){const r=t.indexOf(e,n);if(-1===r)throw new Error(i);return r+e.length-1}function _a(t,e,n,i=">"){const r=function(t,e,n=">"){let i,r="";for(let s=e;s<t.length;s++){let e=t[s];if(i)e===i&&(i="");else if('"'===e||"'"===e)i=e;else if(e===n[0]){if(!n[1])return{data:r,index:s};if(t[s+1]===n[1])return{data:r,index:s}}else"\t"===e&&(e=" ");r+=e}}(t,e+1,i);if(!r)return;let s=r.data;const o=r.index,a=s.search(/\s/);let l=s,u=!0;-1!==a&&(l=s.substring(0,a),s=s.substring(a+1).trimStart());const c=l;if(n){const t=l.indexOf(":");-1!==t&&(l=l.substr(t+1),u=l!==r.data.substr(t+1))}return{tagName:l,tagExp:s,closeIndex:o,attrExpPresent:u,rawTagName:c}}function ga(t,e,n){const i=n;let r=1;for(;n<t.length;n++)if("<"===t[n])if("/"===t[n+1]){const s=pa(t,">",n,`${e} is not closed`);if(t.substring(n+2,s).trim()===e&&(r--,0===r))return{tagContent:t.substring(i,n),i:s};n=s}else if("?"===t[n+1]){n=pa(t,"?>",n+1,"StopNode is not closed.")}else if("!--"===t.substr(n+1,3)){n=pa(t,"--\x3e",n+3,"StopNode is not closed.")}else if("!["===t.substr(n+1,2)){n=pa(t,"]]>",n,"StopNode is not closed.")-2}else{const i=_a(t,n,">");if(i){(i&&i.tagName)===e&&"/"!==i.tagExp[i.tagExp.length-1]&&r++,n=i.closeIndex}}}function ma(t,e,n){if(e&&"string"==typeof t){const e=t.trim();return"true"===e||"false"!==e&&ea(t,n)}return void 0!==t?t:""}const va=Bo.getMetaDataSymbol();function ya(t,e){return ba(t,e)}function ba(t,e,n){let i;const r={};for(let s=0;s<t.length;s++){const o=t[s],a=xa(o);let l="";if(l=void 0===n?a:n+"."+a,a===e.textNodeName)void 0===i?i=o[a]:i+=""+o[a];else{if(void 0===a)continue;if(o[a]){let t=ba(o[a],e,l);const n=Na(t,e);void 0!==o[va]&&(t[va]=o[va]),o[":@"]?wa(t,o[":@"],l,e):1!==Object.keys(t).length||void 0===t[e.textNodeName]||e.alwaysCreateTextNode?0===Object.keys(t).length&&(e.alwaysCreateTextNode?t[e.textNodeName]="":t=""):t=t[e.textNodeName],void 0!==r[a]&&r.hasOwnProperty(a)?(Array.isArray(r[a])||(r[a]=[r[a]]),r[a].push(t)):e.isArray(a,l,n)?r[a]=[t]:r[a]=t}}}return"string"==typeof i?i.length>0&&(r[e.textNodeName]=i):void 0!==i&&(r[e.textNodeName]=i),r}function xa(t){const e=Object.keys(t);for(let t=0;t<e.length;t++){const n=e[t];if(":@"!==n)return n}}function wa(t,e,n,i){if(e){const r=Object.keys(e),s=r.length;for(let o=0;o<s;o++){const s=r[o];i.isArray(s,n+"."+s,!0,!0)?t[s]=[e[s]]:t[s]=e[s]}}}function Na(t,e){const{textNodeName:n}=e,i=Object.keys(t).length;return 0===i||!(1!==i||!t[n]&&"boolean"!=typeof t[n]&&0!==t[n])}class Ma{constructor(t){this.externalEntities={},this.options=function(t){return Object.assign({},Ho,t)}(t)}parse(t,e){if("string"==typeof t);else{if(!t.toString)throw new Error("XML data is accepted in String or Bytes[] form.");t=t.toString()}if(e){!0===e&&(e={});const n=function(t,e){e=Object.assign({},To,e);const n=[];let i=!1,r=!1;"\ufeff"===t[0]&&(t=t.substr(1));for(let s=0;s<t.length;s++)if("<"===t[s]&&"?"===t[s+1]){if(s+=2,s=Ao(t,s),s.err)return s}else{if("<"!==t[s]){if(Eo(t[s]))continue;return Io("InvalidChar","char '"+t[s]+"' is not expected.",Fo(t,s))}{let o=s;if(s++,"!"===t[s]){s=ko(t,s);continue}{let a=!1;"/"===t[s]&&(a=!0,s++);let l="";for(;s<t.length&&">"!==t[s]&&" "!==t[s]&&"\t"!==t[s]&&"\n"!==t[s]&&"\r"!==t[s];s++)l+=t[s];if(l=l.trim(),"/"===l[l.length-1]&&(l=l.substring(0,l.length-1),s--),!Uo(l)){let e;return e=0===l.trim().length?"Invalid space after '<'.":"Tag '"+l+"' is an invalid name.",Io("InvalidTag",e,Fo(t,s))}const u=$o(t,s);if(!1===u)return Io("InvalidAttr","Attributes for '"+l+"' have open quote.",Fo(t,s));let c=u.value;if(s=u.index,"/"===c[c.length-1]){const n=s-c.length;c=c.substring(0,c.length-1);const r=Oo(c,e);if(!0!==r)return Io(r.err.code,r.err.msg,Fo(t,n+r.err.line));i=!0}else if(a){if(!u.tagClosed)return Io("InvalidTag","Closing tag '"+l+"' doesn't have proper closing.",Fo(t,s));if(c.trim().length>0)return Io("InvalidTag","Closing tag '"+l+"' can't have attributes or invalid starting.",Fo(t,o));if(0===n.length)return Io("InvalidTag","Closing tag '"+l+"' has not been opened.",Fo(t,o));{const e=n.pop();if(l!==e.tagName){let n=Fo(t,e.tagStartPos);return Io("InvalidTag","Expected closing tag '"+e.tagName+"' (opened in line "+n.line+", col "+n.col+") instead of closing tag '"+l+"'.",Fo(t,o))}0==n.length&&(r=!0)}}else{const a=Oo(c,e);if(!0!==a)return Io(a.err.code,a.err.msg,Fo(t,s-c.length+a.err.line));if(!0===r)return Io("InvalidXml","Multiple possible root nodes found.",Fo(t,s));-1!==e.unpairedTags.indexOf(l)||n.push({tagName:l,tagStartPos:o}),i=!0}for(s++;s<t.length;s++)if("<"===t[s]){if("!"===t[s+1]){s++,s=ko(t,s);continue}if("?"!==t[s+1])break;if(s=Ao(t,++s),s.err)return s}else if("&"===t[s]){const e=Po(t,s);if(-1==e)return Io("InvalidChar","char '&' is not expected.",Fo(t,s));s=e}else if(!0===r&&!Eo(t[s]))return Io("InvalidXml","Extra text at the end",Fo(t,s));"<"===t[s]&&s--}}}return i?1==n.length?Io("InvalidTag","Unclosed tag '"+n[0].tagName+"'.",Fo(t,n[0].tagStartPos)):!(n.length>0)||Io("InvalidXml","Invalid '"+JSON.stringify(n.map(t=>t.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1}):Io("InvalidXml","Start tag expected.",1)}(t,e);if(!0!==n)throw Error(`${n.err.msg}:${n.err.line}:${n.err.col}`)}const n=new ia(this.options);n.addExternalEntities(this.externalEntities);const i=n.parseXml(t);return this.options.preserveOrder||void 0===i?i:ya(i,this.options)}addEntity(t,e){if(-1!==e.indexOf("&"))throw new Error("Entity value can't have '&'");if(-1!==t.indexOf("&")||-1!==t.indexOf(";"))throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'");if("&"===e)throw new Error("An entity with value '&' is not permitted");this.externalEntities[t]=e}static getMetaDataSymbol(){return Bo.getMetaDataSymbol()}}function Sa(t){return!r.has(t,"children")}function Ta(t,e,n){let i=[];return function r(s){Sa(s)?e&&s!=t&&i.push(s):(n&&s!=t&&i.push(s),s.children.forEach(r))}(t),i}var Ea=Object.freeze({__proto__:null,graftANode:function(t,e,n,i){let r=this.nodes.descendants();if(t.parent){if(r.indexOf(t)>=0){let r=t.parent.children.indexOf(t),s={name:n,parent:t.parent,attribute:i?i[2]:null,original_child_order:t.original_child_order},o={name:e,parent:s,attribute:i?i[1]:null,original_child_order:2};s.children=[t,o],t.parent.children[r]=s,t.parent=s,t.attribute=i?i[0]:null,t.original_child_order=1}}return this},addChild:function(t,e){return t.children?t.children.push(e):t.children=[e],t},createNode:function(t,e){return{data:{name:t,attribute:e?e[1]:null},parent:""}},deleteANode:function(t){let e=this.nodes.descendants();if("number"!=typeof t)return this.deleteANode(e.indexOf(t));if(t>0&&t<e.length){let n=e[t];if(n.parent){let i=n.parent.children.indexOf(n);i>=0&&(e.splice(t,1),n.children&&n.children.forEach(function(t){t.original_child_order=n.parent.children.length,n.parent.children.push(t),t.parent=n.parent}),n.parent.children.length>2?n.parent.children.splice(i,1):n.parent.parent?(n.parent.parent.children[n.parent.parent.children.indexOf(n.parent)]=n.parent.children[1-i],n.parent.children[1-i].parent=n.parent.parent,e.splice(e.indexOf(n.parent),1)):(e.splice(0,1),e.parent=null,delete e.data.attribute,delete e.data.annotation,delete e.data.original_child_order,e.name="root",e.data.name="root"))}}return this},getTips:function(){return r.filter(this.nodes.descendants(),t=>!r.has(t,"children"))},getInternals:function(){return r.filter(this.nodes.descendants(),t=>r.has(t,"children"))},getRootNode:function(){return this.nodes},getNodes:function(){return this.nodes},getNodeByName:function(t){return r.filter(this.nodes.descendants(),e=>e.data.name==t)[0]},assignAttributes:function(t){r.each(this.nodes.descendants(),function(e){e.data&&e.data.name in t&&(e.annotations=t[e.data.name])})},isLeafNode:Sa,updateKeyName:function(t,e){return this.nodes.each(function(n){t in n&&(e&&(n[e]=n[t]),delete n[t])}),this},clearInternalNodes:function(t){t||this.nodes.each(t=>{Sa(t)||(t[this.selection_attribute_name]=!1,t.data.traits||(t.data.traits={}),t.data.traits[this.selection_attribute_name]=t[this.selection_attribute_name])})},selectAllDescendants:Ta});function Aa(t,e={}){const n=/^-?\d+(\.\d+)?$/;let i=e.left_delimiter||"{",r=e.right_delimiter||"}",s=[];function o(){let t=s[s.length-1];"children"in t||(t.children=[]),s.push({name:null}),t.children.push(s[s.length-1]),s[s.length-1].original_child_order=t.children.length}function a(){let t=s.pop();t.name=c,"children"in t?t.bootstrap_values=c:t.name=c,t.attribute=h,"["==i&&f.includes("&&NHX")?f.split(":").slice(1).forEach(e=>{const[i,r]=e.split("=");t[i]=n.test(r)?+r:r}):t.annotation=f,c="",h="",f=""}function l(e){return{json:null,error:"Unexpected '"+t[e]+"' in '"+t.substring(e-20,e+1)+"[ERROR HERE]"+t.substring(e+1,e+20)+"'"}}let u=0,c="",h="",f="",d=null,p={"'":1,'"':1},_={name:"root"};s.push(_);for(var g=/\s/,m=0;m<t.length;m++)try{var v=t[m];switch(u){case 0:"("==v&&(o(),u=1);break;case 1:case 3:if(":"==v)u=3;else if(","==v||")"==v)try{a(),u=1,","==v&&o()}catch(t){return l(m)}else if("("==v){if(c.length>0)return l(m);o()}else{if(v in p){if(1==u&&0===c.length&&0===h.length&&0===f.length){u=2,d=v;continue}return l(m)}if(v==i){if(f.length)return l(m);u=4}else if(3==u)h+=v;else{if(g.test(v))continue;if(";"==v){m=t.length;break}c+=v}}break;case 2:if(v==d){if(m<t.length-1&&t[m+1]==d){m++,c+=d;continue}d=0,u=1;continue}c+=v;break;case 4:if(v==r)u=3;else{if(v==i)return l(m);f+=v}}}catch(t){return l(m)}return 1!=s.length?l(t.length-1):{json:_,error:null}}function ka(t,e){let n=this;t||(t=t=>"");let i=[];return t=t||"",function e(r){if(r.notshown)return;if(Sa(r)||(i.push("("),r.children.forEach(function(t,n){n&&i.push(","),e(t)}),i.push(")")),"root"!==r.data.name){const t=r.data.name.replaceAll("'","''");/\W/.test(t)?i.push("'"+t+"'"):i.push(t)}i.push(t(r));let s=n.branch_length_accessor(r);void 0!==s&&i.push(":"+s)}(e||this.nodes),i.join("")+";"}function Ca(t){let e=t,n=e.toUpperCase().indexOf("BEGIN DATA;"),i=e.slice(n);if(i.length<2)return"";n=i.toUpperCase().indexOf("END;");let s=i.slice(0,n);i=r.map(s.split(";"),t=>t.trim());let o=r.filter(i,t=>t.toUpperCase().startsWith("DIMENSION"));o=o[0].split(" "),o=r.object(r.map(r.rest(o),t=>t.split("=")));let a=r.filter(i,t=>t.toUpperCase().startsWith("FORMAT"));a=a[0].split(" "),a=r.object(r.map(r.rest(a),t=>t.split("="))),a.symbols=r.reject(a.symbols.split(""),t=>'"'==t);let l=r.filter(i,t=>t.toUpperCase().startsWith("MATRIX"));return l=l[0].split("\n"),l=r.object(r.map(r.rest(l),t=>r.compact(t.split(" ")))),l=r.mapObject(l,(t,e)=>"?"==t?a.symbols:Array(t)),{dimensions:o,format:a,matrix:l}}function za(t,e,n){r.each(t.getTips(),t=>{t.data.test=n.matrix[t.data.name]})}function $a(t){let e=t,n=e.toUpperCase().indexOf("BEGIN TREES;"),i=e.slice(n);if(i.length<2)return"";n=i.toUpperCase().indexOf("END;");let s=i.slice(0,n).split("\n");return s=r.filter(s,t=>t.trim().toUpperCase().startsWith("TREE")),Aa(s[0])}var Da=Object.freeze({__proto__:null,parseAnnotations:Ca,loadAnnotations:za,default:$a});function Oa(t){var e={};if(1==t.nodeType){if(t.attributes.length>0){e["@attributes"]={};for(var n=0;n<t.attributes.length;n++){var i=t.attributes.item(n);e["@attributes"][i.nodeName]=i.nodeValue}}}else 3==t.nodeType&&(e=t.nodeValue);if(t.hasChildNodes()&&1===t.childNodes.length&&3===t.childNodes[0].nodeType)e=t.childNodes[0].nodeValue;else if(t.hasChildNodes())for(var r=0;r<t.childNodes.length;r++){var s=t.childNodes.item(r),o=s.nodeName;if(void 0===e[o])e[o]=Oa(s);else{if(void 0===e[o].push){var a=e[o];e[o]=[],e[o].push(a)}e[o].push(Oa(s))}}return e}var Pa=function(t,e){var n;if("string"==typeof t)if(DOMParser){t=(new DOMParser).parseFromString(t,"text/xml")}else{t=(new Ma).parse(t)}var i=(t=Oa(t)).phyloxml.phylogeny;return Array.isArray(i)&&(i=i[0],console.warn("PhyloXML files with multiple phylogenies are not currently supported. Only the first phylogeny will be loaded.")),(n=i.clade).name="root",function t(e,n){e.clade&&(Array.isArray(e.clade)||(e.clade=[e.clade]),e.clade.forEach(t),e.children=e.clade,delete e.clade),e.annotation=1,e.attribute="0.01",e.branch_length&&(e.attribute=e.branch_length),e.taxonomy&&(e.name=e.taxonomy.scientific_name),e.annotation=""}(n),{json:n,error:null}};var Ia={nexml:function(t,e){return new Ma({ignoreAttributes:!1,attributeNamePrefix:"",parseAttributeValue:!0}).parse(t)["nex:nexml"].trees.tree.map(function(t){var e=t.node.map(t=>t),n=e.reduce(function(t,e){return e.edges=[],e.name=e.id,t[e.id]=e,t},{}),i=e.filter(t=>t.root),s=i>0?i[0].id:e[0].id;return n[s].name="root",t.edge.map(t=>t).forEach(function(t){n[t.source].edges.push(t)}),function t(e,i){if(e.edges){var s=r.pluck(e.edges,"target");e.children=r.values(r.pick(n,s)),e.children.forEach(function(t,n){t.attribute=e.edges[n].length||""}),e.children.forEach(t),e.annotation=""}}(n[s]),n[s]})},phyloxml:Pa,nexus:$a,nwk:Aa,nhx:Aa,beast:function(t,e){e.left_delimiter="[",e.right_delimiter="]";const n=Aa(t,e);return function t(e){if(e.annotation){e.beast={};const t=e.annotation.split(/=|,|{|}/).filter(t=>t);for(var n=0;n<t.length;n+=2){let i=t[n].replace(/&|%/g,"");/[a-df-zA-DF-Z]+/.test(t[n+2])?e.beast[i]=+t[n+1]:(e.beast[i]=[+t[n+1],+t[n+2]],n++)}}e.annotation=void 0,e.children&&e.children.forEach(t)}(n.json),n}};function La(t,e,n){let i,r,s,o=[t],a=[];for(;t=o.pop();)if((!n||!n(t))&&(a.push(t),i=t.children,i))for(r=0,s=i.length;r<s;++r)o.push(i[r]);for(;t=a.pop();)e(t);return t}function Ua(t,e,n){let i,r,s=[t];for(;t=s.pop();)if((!n||!n(t))&&(e(t),i=t.children,i))for(r=i.length-1;r>=0;--r)s.push(i[r]);return t}function Fa(t,e,n){let i,r,s,o,a=[t];do{for(i=a.reverse(),a=[];t=i.pop();)if((!n||!n(t))&&(e(t),r=t.children,r))for(s=0,o=r.length;s<o;++s)a.push(r[s])}while(a.length);return t}function ja(t){return La(t,function(t){t.children&&(t.children[0].data.multiway_parent=t,t.children[1].data.multiway_parent=t.parent)}),s.map(t.descendants(),t=>{let e=t.data.multiway_parent,n="unknown";return e&&(n=e.data.name),{source:t.data.multiway_parent,target:t,name:n}})}function Ha(t,e){let n=t.data;if("attribute"in n&&n.attribute&&n.attribute.length){e>0&&(n.attribute=String(e));let t=parseFloat(n.attribute);if(!isNaN(t))return Math.max(0,t)}if("root"==n.name)return 0;console.warn("Undefined branch length at "+n.name+"!")}var Ya=Object.freeze({__proto__:null,reroot:function(t,e){if(!(t instanceof Hi))throw new Error("node needs to be an instance of a d3.hierarchy node!");let n=this.nodes.copy();if(e=void 0!==e?e:.5,t.parent){var i=Hi({name:"new_root"});i.children=[t.copy()],i.data.__mapped_bl=void 0,n.each(t=>{t.data.__mapped_bl=this.branch_length_accessor(t)}),this.setBranchLength(t=>t.data.__mapped_bl);let o=t,a=t.parent,l=r.noop(),u=void 0===t.data.__mapped_bl?void 0:t.data.__mapped_bl*e;var s;if(l=a.data.__mapped_bl,a.data.__mapped_bl=void 0===t.data.__mapped_bl?void 0:t.data.__mapped_bl-u,t.data.__mapped_bl=u,a.parent){for(i.children.push(a);a.parent;){s=a.children.indexOf(o),a.parent.parent?a.children.splice(s,1,a.parent):a.children.splice(s,1);let t=a.parent.data.__mapped_bl;void 0!==t&&(a.parent.data.__mapped_bl=l,l=t),o=a,a=a.parent}s=a.children.indexOf(o),a.children.splice(s,1)}else s=a.children.indexOf(o),a.children.splice(s,1),l=a.data.__mapped_bl,o=i;if(1==a.children.length)l&&(a.children[0].data.__mapped_bl+=l),o.children=o.children.concat(a.children);else{let e=new Hi({name:"__reroot_top_clade",__mapped_bl:l});r.extendOwn(i.children[0],t),e.data.__mapped_bl=l,e.children=a.children.map(function(t){return t.parent=e,t}),e.parent=o,o.children.push(e)}}if(this.update(i),this.traverse_and_compute(t=>{r.each(t.children,e=>{e.parent=t})},"pre-order"),!r.isUndefined(this.display)){let t=this.display.options;Yt(this.display.container).select("svg").remove();let e=this.display.selection_attribute_name;delete this.display;let n=this.render(t);n.selectionLabel(e),n.update(),Yt(n.container).node().appendChild(n.show()),Yt(this.display.container).dispatch("reroot"),n.emit&&n.emit("rerooted",this.nodes)}return this},rootpath:function(t,e){if(t=t||"attribute",e=e||"y_scaled","parent"in this){let n=parseFloat(this[t]);this[e]=this.parent[e]+(isNaN(n)?.1:n)}else this[e]=0;return this[e]},pathToRoot:function(t){let e=[];for(;t;)e.push(t),t=t.parent;return e}});function Ba(t){return t.y}function Va(t){return t.x}function Ra(t,e,n){return{x:n+t*Math.sin(e),y:n+t*Math.cos(e)}}function qa(t,e,n,i,r,s){t.radius=e*(t.radius+n),t.angle=2*Math.PI*t.x*r[0]/s[0];let o=Ra(t.radius,t.angle,i);return t.x=o.x,t.y=o.y,t}function Xa(t,e){var n=Ra(e[0].radius,e[0].angle,t),i=Ra(e[0].radius,e[1].angle,t);return"M "+Ba(n)+","+Va(n)+" A "+e[0].radius+","+e[0].radius+" 0,0, "+(e[1].angle>e[0].angle?1:0)+" "+Ba(i)+","+Va(i)+" L "+Ba(e[1])+","+Va(e[1])}function Za(t,e,n){var i=Ra(t.target.radius+(t.source.radius-t.target.radius)*e,t.target.angle,n);return{x:Ba(i),y:Va(i)}}var Wa=ro().x(function(t){return Ba(t)}).y(function(t){return Va(t)}).curve(function(t){return new lo(t,0)});function Ga(t,e){return{x:Ba(t.target)+(Ba(t.source)-Ba(t.target))*e,y:Va(t.target)}}function Ka(t){return t.tag||!1}function Ja(t,e){return t[e]||!1}const Qa={"tree-container":"phylotree-container","tree-scale-bar":"tree-scale-bar",node:"node","internal-node":"internal-node","tagged-node":"node-tagged","selected-node":"node-selected","collapsed-node":"node-collapsed","root-node":"root-node",branch:"branch","selected-branch":"branch-selected","tagged-branch":"branch-tagged","tree-selection-brush":"tree-selection-brush","branch-tracer":"branch-tracer",clade:"clade",node_text:"phylotree-node-text"};function tl(t={}){Object.keys(t).forEach(e=>{Qa[e]=t[e]})}function el(t){return arguments.length?(el="string"==typeof t&&"equal"==t?function(t){return 1}:t,this):el}var nl={all:t=>!0,none:t=>!1,"all-leaf-nodes":t=>Sa(t.target),"all-internal-nodes":t=>!Sa(t.target)};var il=Object.freeze({__proto__:null,css_classes:Qa,initializeCssClasses:tl,internalNames:function(t){return arguments.length?(this.options["internal-names"]=t,this):this.options["internal-names"]},radial:function(t){return arguments.length?(this.options["is-radial"]=t,this):this.options["is-radial"]},alignTips:function(t){return arguments.length?(this.options["align-tips"]=t,this):this.options["align-tips"]},nodeBubbleSize:function(t){return this.options["draw-size-bubbles"]&&this.options["bubble-styler"]?this.options["bubble-styler"](t):this.options["draw-size-bubbles"]?this.relative_nodeSpan(t)*this.scales[0]*.25:0},shiftTip:function(t){return this.options["is-radial"]?[("end"==t.text_align?-1:1)*(this.radius_pad_for_bubbles-t.radius),0]:(this.options["right-to-left"],[this.right_most_leaf-t.screen_x,0])},layoutHandler:function(t){return arguments.length?(this.layout_listener_handler=t,this):this.layout_listener_handler},selectionLabel:function(t){return arguments.length?(this.selection_attribute_name=t,this.syncEdgeLabels(),this):this.selection_attribute_name},get nodeSpan(){return el},predefined_selecters:nl,selectionCallback:function(t){return t?(this._selectionCallback=t,this):this._selectionCallback}});function rl(t){return!(t.hidden||t.notshown)}function sl(t){return t.notshown}function ol(t){return t.hasHiddenNodes||!1}function al(t){return t.collapsed||!1}function ll(t){return[t.node,t["internal-node"],t["collapsed-node"],t["tagged-node"],t["root-node"]].reduce(function(t,e,n,i){return t+"g."+e+(n<i.length-1?",":"")},"")}function ul(t){return Sa(t=t.data)?t.name||"":this.showInternalName(t)?t.name:""}var cl=Object.freeze({__proto__:null,shiftTip:function(t){return this.radial()?[("end"==t.text_align?-1:1)*(this.radius_pad_for_bubbles-t.radius),0]:(this.options["right-to-left"],[this.right_most_leaf-t.screen_x,0])},drawNode:function(t,e,n){t=Yt(t);var i=Sa(e);i&&(t=t.attr("data-node-name",e.data.name));var r=t.selectAll("text").data([e]),s=t.selectAll("line");if(i||this.showInternalName(e)&&!al(e))if(r=r.enter().append("text").classed(this.css_classes.node_text,!0).merge(r).on("click",(t,n)=>{this.emit("nodeClick",e,t),this.handle_node_click(e,t)}).on("mouseenter",t=>{this.emit("nodeHover",e,t)}).attr("dy",t=>.33*this.shown_font_size).text(t=>this.options["show-labels"]?this._nodeLabel(t):"").style("font-size",t=>this.ensure_size_is_in_px(this.shown_font_size)),r=this.radial()?r.attr("transform",t=>this.d3PhylotreeSvgRotate(t.text_angle)+this.d3PhylotreeSvgTranslate(this.alignTips()?this.shiftTip(t):null)).attr("text-anchor",t=>t.text_align):r.attr("text-anchor","start").attr("transform",t=>"right-to-left"==this.options.layout?this.d3PhylotreeSvgTranslate([-20,0]):this.d3PhylotreeSvgTranslate(this.alignTips()?this.shiftTip(t):null)),this.alignTips()?(s=s.data([e]),n?s=s.enter().append("line").classed(this.css_classes["branch-tracer"],!0).merge(s).attr("x1",t=>("end"==t.text_align?-1:1)*this.nodeBubbleSize(e)).attr("x2",0).attr("y1",0).attr("y2",0).attr("x2",t=>"right-to-left"==this.options.layout?t.screen_x:this.shiftTip(t)[0]).attr("transform",t=>this.d3PhylotreeSvgRotate(t.text_angle)).attr("x2",t=>"right-to-left"==this.options.layout?t.screen_x:this.shiftTip(t)[0]).attr("transform",t=>this.d3PhylotreeSvgRotate(t.text_angle)):(s=s.enter().append("line").classed(this.css_classes["branch-tracer"],!0).merge(s).attr("x1",t=>("end"==t.text_align?-1:1)*this.nodeBubbleSize(e)).attr("y2",0).attr("y1",0).attr("x2",t=>this.shiftTip(t)[0])).attr("transform",t=>this.d3PhylotreeSvgRotate(t.text_angle))):s.remove(),this.options["draw-size-bubbles"]){var o=this.nodeBubbleSize(e);t.selectAll("circle").data([o]).enter().append("circle").attr("r",function(t){return t}),this.shown_font_size>=5&&(r=r.attr("dx",t=>("end"==t.text_align?-1:1)*((this.alignTips()?0:o)+.33*this.shown_font_size)))}else this.shown_font_size>=5&&(r=r.attr("dx",t=>("end"==t.text_align?-1:1)*this.shown_font_size*.33));if(!i){let n=t.selectAll("circle").data([e]).enter().append("circle"),i=this.node_circle_size()(e);i>0?n.merge(n).attr("r",t=>Math.min(.75*this.shown_font_size,i)).on("click",(t,n)=>{this.emit("nodeClick",e,t),this.handle_node_click(e,t)}).on("mouseenter",t=>{this.emit("nodeHover",e,t)}):n.remove()}return this.node_styler&&this.node_styler(t,e),e},updateHasHiddenNodes:function(){let t=this.phylotree.nodes.descendants();for(let e=t.length-1;e>=0;e-=1)Sa(t[e])?t[e].hasHiddenNodes=t[e].notshown:t[e].hasHiddenNodes=t[e].children.reduce(function(t,e){return e.notshown||t},!1);return this},showInternalName:function(t){const e=this.internalNames();return!!e&&("function"==typeof e?e(t):e)},nodeSpan:function(t){return arguments.length?(this.nodeSpan="string"==typeof t&&"equal"==t?function(t){return 1}:t,this):this.nodeSpan},reclassNode:function(t){let e=Qa[Sa(t)?"node":"internal-node"];return Ka(t)&&(e+=" "+Qa["tagged-node"]),Ja(t,this.selection_attribute_name)&&(e+=" "+Qa["selected-node"]),t.parent||(e+=" "+Qa["root-node"]),(al(t)||ol(t))&&(e+=" "+Qa["collapsed-node"]),e},nodeVisible:rl,nodeNotshown:sl,hasHiddenNodes:ol,isNodeCollapsed:al,nodeCssSelectors:ll,internalLabel:function(t,e){this.phylotree.clearInternalNodes(e);for(var n=this.phylotree.nodes.descendants().length-1;n>=0;n--){var i=this.phylotree.nodes.descendants()[n];Sa(i)||Ja(i,this.selection_attribute_name)||(i[this.selection_attribute_name]=t(i.children))}this.modifySelection((t,e)=>(Sa(t.target),t.target[this.selection_attribute_name]))},defNodeLabel:ul,nodeLabel:function(t){return arguments.length?(this._nodeLabel=t||ul,this.update(),this):this._nodeLabel}});function hl(t){return[t.clade].reduce(function(t,e,n,i){return t+"path."+e+(n<i.length-1?",":"")},"")}var fl=Object.freeze({__proto__:null,cladeCssSelectors:hl,updateCollapsedClades:function(t){let e=this.svg.selectAll("."+this.css_classes["tree-container"]);var n=0;let i=e.selectAll(hl(this.css_classes)).data(this.phylotree.nodes.descendants().filter(al),function(t){return t.id||(t.id=++n)}),s=function(){},o=r.noop();this.radial()?(s=ro().curve(ao).y(function(t){return t[0]}).x(function(t){return t[1]}),o=function(t,e,n,i,r){return e?[n.screen_y+(t[0]-i)/50,n.screen_x+(t[1]-r)/50]:[n.screen_y,n.screen_x]}):(s=ro().y(function(t){return t[0]}).x(function(t){return t[1]}).curve(ao),o=function(t,e,n,i,r){return e?[n.screen_y+(t[0]-i)/50,n.screen_x+(t[1]-r)/50]:[n.screen_y,n.screen_x]}),i.exit().each(function(t){t.collapsed_clade=null}).remove(),t?i.enter().insert("path",":first-child").attr("class",this.css_classes.clade).merge(i).attr("d",function(t){if(t.collapsed_clade)return t.collapsed_clade;let e=t.collapsed[0][0],n=t.collapsed[0][1];return s(t.collapsed.map(function(i,r){return o(i,r,t,e,n)}))}).attr("d",function(t){return t.collapsed_clade=s(t.collapsed)}):i.enter().insert("path",":first-child").attr("class",this.css_classes.clade).merge(i).attr("d",function(t){return t.collapsed_clade?t.collapsed_clade:t.collapsed_clade=s(t.collapsed)})}});function dl(t){return!(t.target.hidden||t.target.notshown)}function pl(t){return[t.branch,t["selected-branch"],t["tagged-branch"]].reduce(function(t,e,n,i){return t+"path."+e+(n<i.length-1?",":"")},"")}var _l=Object.freeze({__proto__:null,drawEdge:function(t,e,n){t=(t=Yt(t)).attr("class",t=>this.reclassEdge(t)).on("click",(t,n)=>{this.emit("branchClick",e,t),"multi-set"===this.options["selection-mode"]&&this._activeSetName?this.handleMultiSetClick(e.target):(this.modifySelection([e.target],this.selection_attribute_name),this.update())});let i=this.draw_branch([e.source,e.target]);n?(t.datum().existing_path&&(t=t.attr("d",function(t){return t.existing_path})),t=t.attr("d",i)):t=t.attr("d",i),e.existing_path=i;var r=this.phylotree.branch_length_accessor(e.target);if(void 0!==r){var s=t.selectAll("title");s.empty()&&(s=t.append("title")),s.text("Length = "+r)}else t.selectAll("title").remove();return this.edge_styler&&this.edge_styler(t,e,n),this.phylotree},reclassEdge:function(t){let e=Qa.branch;if(Ka(t)&&(e+=" "+Qa["tagged-branch"]),Ja(t,this.selection_attribute_name)&&(e+=" "+Qa["selected-branch"]),t.target&&t.target._selectionSet){e+=" phylotree-set-branch-"+t.target._selectionSet.replace(/[^a-zA-Z0-9-_]/g,"_")}return e},initializeEdgeLabels:function(){this.links.forEach(t=>{t.target.data.annotation&&(t.target[t.target.data.annotation]=t.target.data.annotation)})},syncEdgeLabels:function(){if(this.links.forEach(t=>{t[this.selection_attribute_name]=t.target[this.selection_attribute_name]||!1,t.tag=t.target.tag||!1}),this.countHandler()){let t={};t[this.selection_attribute_name]=this.links.reduce((t,e)=>t+(e[this.selection_attribute_name]?1:0),0),t.tagged=this.links.reduce(function(t,e){return t+(Ka(e)?1:0)},0),this.countUpdate(this,t,this.countHandler())}},edgeVisible:dl,edgeCssSelectors:pl,placeAlongAnEdge:function(t,e){return this.edge_placer(t,e)}});let gl="phylotree.event";function ml(t){var e=new CustomEvent(gl,{detail:["refresh",t]});document.dispatchEvent(e)}function vl(t,e){var n=new CustomEvent(gl,{detail:["countUpdate",e,t.countHandler()]});document.dispatchEvent(n)}function yl(t){switch(t.detail[0]){case"refresh":t.detail[1].refresh();break;case"countUpdate":case"layout":t.detail[2](t.detail[1])}return!0}function bl(){document.addEventListener(gl,yl,!1)}var xl=Object.freeze({__proto__:null,toggleCollapse:function(t){if(t.collapsed){t.collapsed=!1;let e=function(t){Sa(t)||t.collapsed||t.children.forEach(e),t.hidden=!1};e(t)}else t.collapsed=!0;return this.placenodes(),this.emit("collapsed",t,t.collapsed),this},resizeSvg:function(t,e,n){let i=this.size;if(this.radial()){let t=this.pad_width(),n="fit-to-size"!=this.options["top-bottom-spacing"]?this.pad_height():0;i=[i[1]+2*t,i[0]+2*t+n],e&&e.selectAll("."+Qa["tree-container"]).attr("transform","translate ("+t+","+(t+n)+")")}else i=[i[0]+("fit-to-size"!=this.options["top-bottom-spacing"]?this.pad_height():0),i[1]+("fit-to-size"!=this.options["left-right-spacing"]?this.pad_width():0)];return e&&(n&&(e=e.transition(100)),this.options.responsive?e.attr("viewBox",`0 0 ${i[1]} ${i[0]}`):e.attr("height",i[0]).attr("width",i[1])),this.size=i,i},rescale:function(t,e){(e=e||"y_scaled")in this&&(this[e]*=t)},triggerRefresh:ml,countUpdate:vl,d3PhylotreeTriggerLayout:function(t){var e=new CustomEvent(gl,{detail:["layout",t,t.layoutHandler()]});document.dispatchEvent(e)},d3PhylotreeEventListener:yl,d3PhylotreeAddEventListener:bl,d3PhylotreeSvgTranslate:function(t){return!t||null===t[0]&&null===t[1]?"":"translate ("+(null!==t[0]?t[0]:0)+","+(null!==t[1]?t[1]:0)+") "},d3PhylotreeSvgRotate:function(t){return null!==t?"rotate ("+t+") ":""}});let wl="d3_layout_phylotree_context_menu";function Nl(t,e,n){let i=[];return function r(s){Sa(s)?e&&s!=t&&i.push(s):(n&&s!=t&&i.push(s),s.children.forEach(r))}(t),i}var Ml=Object.freeze({__proto__:null,nodeDropdownMenu:function(t,e,n,i,s){let o=Yt(e).select("#"+wl);if(o.empty()&&(o=Yt(e).append("div").attr("id",wl).attr("class","phylotree-context-menu dropdown-menu").attr("role","menu")),o.selectAll("a").remove(),o.selectAll("h6").remove(),o.selectAll("div").remove(),t){if(!r.some([Boolean(t.menu_items),i.hide,i.selectable,i.collapsible])||!i["show-menu"])return;Sa(t)||(i.collapsible&&(o.append("a").attr("class","phylotree-menu-item dropdown-item").attr("tabindex","-1").text(al(t)?"Expand Subtree":"Collapse Subtree").on("click",e=>{o.style("display","none"),this.toggleCollapse(t).update()}),i.selectable&&(o.append("div").attr("class","phylotree-menu-divider dropdown-divider"),o.append("h6").attr("class","phylotree-menu-header dropdown-header").text("Toggle selection"))),i.selectable&&(o.append("a").attr("class","phylotree-menu-item dropdown-item").attr("tabindex","-1").text("All descendant branches").on("click",function(e){o.style("display","none"),n.modifySelection(n.selectAllDescendants(t,!0,!0))}),o.append("a").attr("class","phylotree-menu-item dropdown-item").attr("tabindex","-1").text("All terminal branches").on("click",function(e){o.style("display","none"),n.modifySelection(n.selectAllDescendants(t,!0,!1))}),o.append("a").attr("class","phylotree-menu-item dropdown-item").attr("tabindex","-1").text("All internal branches").on("click",function(e){o.style("display","none"),n.modifySelection(n.selectAllDescendants(t,!1,!0))}))),t.parent&&(i.selectable&&(o.append("a").attr("class","phylotree-menu-item dropdown-item").attr("tabindex","-1").text("Incident branch").on("click",function(e){o.style("display","none"),n.modifySelection([t])}),o.append("a").attr("class","phylotree-menu-item dropdown-item").attr("tabindex","-1").text("Path to root").on("click",e=>{o.style("display","none"),this.modifySelection(this.phylotree.pathToRoot(t))}),(i.reroot||i.hide)&&o.append("div").attr("class","phylotree-menu-divider dropdown-divider")),i.reroot&&o.append("a").attr("class","phylotree-menu-item dropdown-item").attr("tabindex","-1").text("Reroot on this node").on("click",e=>{o.style("display","none"),this.phylotree.reroot(t),this.update()}),i.hide&&o.append("a").attr("class","phylotree-menu-item dropdown-item").attr("tabindex","-1").text("Hide this "+(Sa(t)?"node":"subtree")).on("click",e=>{o.style("display","none"),this.modifySelection([t],"notshown",!0,!0).updateHasHiddenNodes().update()})),ol(t)&&o.append("a").attr("class","phylotree-menu-item dropdown-item").attr("tabindex","-1").text("Show all descendant nodes").on("click",function(e){o.style("display","none"),n.modifySelection(n.selectAllDescendants(t,!0,!0),"notshown",!0,!0,"false").updateHasHiddenNodes().update()});var a=[];if("menu_items"in t&&"object"==typeof t.menu_items&&t.menu_items.forEach(function(e){3==e.length&&(e[2]&&!e[2](t)||a.push([e[0],e[1]]))}),a.length){const e=[i.hide,i.selectable,i.collapsible];r.some(e)&&o.append("div").attr("class","phylotree-menu-divider dropdown-divider"),a.forEach(function(e){o.append("a").attr("class","phylotree-menu-item dropdown-item").attr("tabindex","-1").text(e[0](t)).on("click",r.partial(e[1],t))})}let l=document.querySelector(e).getBoundingClientRect();o.style("position","absolute").style("left",s.clientX-l.x+12+"px").style("top",s.clientY-l.y+"px").style("display","block")}else o.style("display","none")},addCustomMenu:function(t,e,n,i){"menu_items"in t||(t.menu_items=[]),t.menu_items.some(function(t){return t[0]==e&&t[1]==n&&t[2]==i})||t.menu_items.push([e,n,i])},modifySelection:function(t,e,n,i,s){if(e=e||this.selection_attribute_name,s=s||"toggle",this.options["restricted-selectable"].length){if(!r.contains(r.keys(nl),t))return;t=nl[t]}if(!this.options["restricted-selectable"]&&!this.options.selectable||this.options["binary-selectable"])this.options["binary-selectable"]&&("function"==typeof t?this.links.forEach(function(n){var i=t(n);n[e]=n[e]||!1,n[e]!=i&&(n[e]=i,a=!0,n.target[e]=i),this.options["attribute-list"].forEach(function(t){t!=e&&!0===n[e]&&(n[t]=!1,n.target[t]=!1)})}):(t.forEach(function(t){var n;n=!t[e],t[e]!=n&&(t[e]=n,a=!0)}),this.links.forEach(function(t){t[e]=t.target[e],this.options["attribute-list"].forEach(function(n){n!=e&&!0!==t[e]&&(t[n]=!1,t.target[n]=!1)})})),a&&(i||ml(this),this.countHandler()&&((o={})[e]=this.links.reduce(function(t,n){return t+(n[e]?1:0)},0),this.countUpdate(this,o,this.countHandler())),n&&this.placenodes()));else{var o,a=!1;"function"==typeof t?this.links.forEach(function(n){let i=t(n);n[e]=n[e]||!1,n[e]!=i&&(n[e]=i,a=!0,n.target[e]=i)}):(t.forEach(function(t){var n;switch(s){case"true":n=!0;break;case"false":n=!1;break;default:n=!t[e]}t[e]!=n&&(t[e]=n,a=!0)}),this.links.forEach(function(t){t[e]=t.target[e]})),a&&(i||ml(this),this.countHandler&&((o={})[e]=this.links.reduce(function(t,n){return t+(n[e]?1:0)},0),vl(this,o,this.countHandler)),n&&this.placenodes())}if("tag"!=e){const t=this.getSelection();this._selectionCallback&&this._selectionCallback(t),this.emit("selectionChange",t)}return this.refresh(),this.update(),this},getSelection:function(){return Nl(this.phylotree.getRootNode(),!0,!0).filter(t=>t[this.selection_attribute_name])},selectAllDescendants:Nl,selectionCallback:function(t){return t?(this._selectionCallback=t,this):this._selectionCallback},selectNodes:function(t){if(!t||!Array.isArray(t)||0===t.length)return this;const e=this.phylotree.nodes.descendants().filter(e=>t.includes(e.data.name));return e.length>0&&this.modifySelection(e,this.selection_attribute_name,!1,!1,"true"),this},deselectNodes:function(t){if(!t||!Array.isArray(t)||0===t.length)return this;const e=this.phylotree.nodes.descendants().filter(e=>t.includes(e.data.name));return e.length>0&&this.modifySelection(e,this.selection_attribute_name,!1,!1,"false"),this},clearSelection:function(){const t=this.phylotree.nodes.descendants();return this.modifySelection(t,this.selection_attribute_name,!1,!1,"false"),this}});var Sl=Object.freeze({__proto__:null,on:function(t,e){return this._eventListeners||(this._eventListeners={}),this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(e),this},off:function(t,e){return this._eventListeners&&this._eventListeners[t]&&(this._eventListeners[t]=this._eventListeners[t].filter(t=>t!==e)),this},emit:function(t,...e){return this._eventListeners&&this._eventListeners[t]&&this._eventListeners[t].forEach(n=>{try{n.apply(this,e)}catch(e){console.error(`Error in ${t} event handler:`,e)}}),this}});var Tl=Object.freeze({__proto__:null,initializeSelectionSets:function(t){this._selectionSets={},this._activeSetName=null,t.forEach(t=>{this._selectionSets[t.name]={name:t.name,color:t.color,members:new Set}}),t.length>0&&(this._activeSetName=t[0].name),this._injectSetStyles(t)},_injectSetStyles:function(t){const e="phylotree-selection-set-styles";let n=document.getElementById(e);n||(n=document.createElement("style"),n.id=e,document.head.appendChild(n));const i=t.map(t=>{const e=t.name.replace(/[^a-zA-Z0-9-_]/g,"_");return`\n .phylotree-set-${e} path.branch {\n stroke: ${t.color} !important;\n }\n .phylotree-set-${e} .node circle {\n fill: ${t.color} !important;\n }\n .phylotree-set-branch-${e} {\n stroke: ${t.color} !important;\n }\n `}).join("\n");n.textContent=i},setActiveSet:function(t){return this._selectionSets&&this._selectionSets[t]?this._activeSetName=t:console.warn(`Selection set '${t}' not found`),this},getActiveSet:function(){return this._activeSetName},getSetMembers:function(t){if(!this._selectionSets||!this._selectionSets[t])return[];const e=this._selectionSets[t].members;return this.phylotree.nodes.descendants().filter(t=>e.has(t.data.name))},addToSet:function(t,e){if(!this._selectionSets||!this._selectionSets[e])return console.warn(`Selection set '${e}' not found`),this;const n="string"==typeof t?t:t.data.name,i="string"==typeof t?this.phylotree.getNodeByName(t):t;return i&&(Object.keys(this._selectionSets).forEach(t=>{this._selectionSets[t].members.delete(n)}),this._selectionSets[e].members.add(n),i._selectionSet=e,this.emit("setChange",{action:"add",set:e,node:i,allSets:this._getSetsSummary()}),this.refresh(),this.update()),this},removeFromSet:function(t,e){if(!this._selectionSets||!this._selectionSets[e])return this;const n="string"==typeof t?t:t.data.name,i="string"==typeof t?this.phylotree.getNodeByName(t):t;return this._selectionSets[e].members.has(n)&&(this._selectionSets[e].members.delete(n),i&&delete i._selectionSet,this.emit("setChange",{action:"remove",set:e,node:i,allSets:this._getSetsSummary()}),this.refresh(),this.update()),this},_getSetsSummary:function(){const t={};return this._selectionSets&&Object.keys(this._selectionSets).forEach(e=>{t[e]=Array.from(this._selectionSets[e].members)}),t},handleMultiSetClick:function(t){if(!this._activeSetName||!this._selectionSets)return;t.data.name,t._selectionSet===this._activeSetName?this.removeFromSet(t,this._activeSetName):this.addToSet(t,this._activeSetName)},isInSet:function(t,e){return!(!this._selectionSets||!this._selectionSets[e])&&this._selectionSets[e].members.has(t.data.name)},getNodeSet:function(t){return t._selectionSet||null}});function El(t){return function(){return t}}class Al{constructor(t,e={}){tl(e["css-classes"]),this.css_classes=Qa,this.phylotree=t,this.container=e.container,this.separation=function(t,e){return 0},this._nodeLabel=this.defNodeLabel,this.svg=null,this._selectionCallback=null,this._eventListeners={},this.scales=[1,1],this.size=[1,1],this.fixed_width=[14,30],this.scale_bar_font_size=12,this.draw_branch=Wa,this.draw_scale_bar=null,this.edge_placer=Ga,this.count_listener_handler=function(){},this.layout_listener_handler=function(){},this.node_styler=void 0,this.edge_styler=void 0,this.selection_attribute_name="selected",this.right_most_leaf=0,this.label_width=0,this.radial_center=0,this.radius=1,this.radius_pad_for_bubbles=0,this.rescale_nodeSpan=1,this.relative_nodeSpan=function(t){return this.nodeSpan(t)/this.rescale_nodeSpan};let n={layout:"left-to-right",logger:console,branches:"step",scaling:!0,bootstrap:!1,"color-fill":!0,"font-size":14,"internal-names":!1,selectable:!0,"restricted-selectable":!1,collapsible:!0,"left-right-spacing":"fixed-step","top-bottom-spacing":"fixed-step","left-offset":0,"show-scale":"top","draw-size-bubbles":!1,"bubble-styler":this.radius_pad_for_bubbles,"binary-selectable":!1,"is-radial":!1,"attribute-list":[],"max-radius":768,"annular-limit":.38196601125010515,compression:.2,"align-tips":!1,"maximum-per-node-spacing":100,"minimum-per-node-spacing":2,"maximum-per-level-spacing":100,"minimum-per-level-spacing":10,node_circle_size:El(3),transitions:null,brush:!0,reroot:!0,hide:!0,"label-nodes-with-name":!1,zoom:!1,"show-menu":!0,"show-labels":!0,"node-styler":null,"edge-styler":null,"node-span":null,responsive:!1,"preserve-aspect-ratio":"xMidYMid meet","selection-mode":"single","selection-sets":[],"initial-selection":[],"initial-sets":{}};this.ensure_size_is_in_px=function(t){return"number"==typeof t?t+"px":t},this.options=r.defaults(e,n),this.font_size=this.options["font-size"],this.offsets=[0,this.font_size/2],this.shown_font_size=this.font_size,this.width=this.options.width||800,this.height=this.options.height||600,this.node_styler=this.options["node-styler"],this.edge_styler=this.options["edge-styler"],this.nodeSpan=this.options["node-span"],this.nodeSpan||(this.nodeSpan=function(t){return 1}),this.rescale_nodeSpan=this.phylotree.nodes.children.map(t=>{if(Sa(t)||this.showInternalName(t))return this.nodeSpan(t)}).reduce(function(t,e){return Math.min(e,t||1e200)},null)||1,this.initialize_svg(this.container),this.links=this.phylotree.nodes.links(),this.initializeEdgeLabels(),this.update(),bl(),"multi-set"===this.options["selection-mode"]&&this.options["selection-sets"].length>0&&this.initializeSelectionSets(this.options["selection-sets"]),this.applyInitialSelection()}applyInitialSelection(){this.options["initial-selection"]&&this.options["initial-selection"].length>0&&this.selectNodes(this.options["initial-selection"]),"multi-set"===this.options["selection-mode"]&&this.options["initial-sets"]&&Object.entries(this.options["initial-sets"]).forEach(([t,e])=>{e.forEach(e=>{this.addToSet(e,t)})})}pad_height(){return this.draw_scale_bar?this.scale_bar_font_size+25:0}pad_width(){this.label_width=this._label_width(this.shown_font_size);const t=this.options["show-labels"]?this.label_width:0;return this.offsets[1]+this.options["left-offset"]+t}collapse_node(t){al(t)||(t.collapsed=!0)}set_size(t){if(!arguments.length)return this.size;let e=t;return"fixed-step"!=this.options["top-bottom-spacing"]&&(this.size[0]=e[0]),"fixed-step"!=this.options["left-right-spacing"]&&(this.size[1]=e[1]),this}initialize_svg(t){return this.svg!==t&&(Yt(t).select("svg").remove(),this.svg=Yt(P("svg").call(document.documentElement)),this.options.responsive?this.svg.attr("viewBox",`0 0 ${this.width} ${this.height}`).attr("preserveAspectRatio",this.options["preserve-aspect-ratio"]).style("width","100%").style("height","auto").style("max-width","100%"):this.svg.attr("width",this.width).attr("height",this.height),this.set_size([this.height,this.width]),"phylotree-container"==this.css_classes["tree-container"]&&(this.svg.selectAll("*").remove(),this.svg.append("defs")),Yt(this.container).on("click",t=>{this.handle_node_click(null)},!0)),this}update_layout(t,e){e&&(this.nodes=Hi(t),this.nodes.each(function(t){t.id=null})),this.update(),this.syncEdgeLabels()}update(t){var e=this;this.placenodes(),t=this.transitions(t);let n=0,i=this.svg.selectAll("."+Qa["tree-container"]).data([0]);if(i=i.enter().append("g").attr("class",Qa["tree-container"]).merge(i).attr("transform",t=>this.d3PhylotreeSvgTranslate([this.offsets[1]+this.options["left-offset"],this.pad_height()])),this.draw_scale_bar){let t=this.svg.selectAll("."+Qa["tree-scale-bar"]).data([0]);t.enter().append("g").attr("class",Qa["tree-scale-bar"]).style("font-size",this.ensure_size_is_in_px(this.scale_bar_font_size)).merge(t).attr("transform",t=>this.d3PhylotreeSvgTranslate([this.offsets[1]+this.options["left-offset"],this.pad_height()-10])).call(this.draw_scale_bar),t.selectAll("text").style("text-anchor","end")}else this.svg.selectAll("."+Qa["tree-scale-bar"]).remove();i=this.svg.selectAll("."+Qa["tree-container"]).data([0]),this.updateCollapsedClades(t);let s=i.selectAll(pl(Qa)).data(this.links.filter(dl),t=>t.target.id||(t.target.id=++n));s.exit().remove(),s=s.enter().insert("path",":first-child").merge(s).each(function(n){e.drawEdge(this,n,t)});let o=i.selectAll(ll(Qa)).data(this.phylotree.nodes.descendants().filter(rl),t=>t.id||(t.id=++n));if(o.exit().remove(),o=o.enter().append("g").attr("class",this.reclassNode).merge(o).attr("transform",t=>{const e="right-to-left"==this.options.layout&&Sa(t);return t.screen_x=Ba(t),t.screen_y=Va(t),this.d3PhylotreeSvgTranslate([e?0:t.screen_x,t.screen_y])}).each(function(n){e.drawNode(this,n,t)}).attr("transform",t=>{if(!r.isUndefined(t.screen_x)&&!r.isUndefined(t.screen_y))return"translate("+t.screen_x+","+t.screen_y+")"}),this.options["label-nodes-with-name"]&&(o=o.attr("id",t=>"node-"+t.name)),this.resizeSvg(this.phylotree,this.svg,t),this.options.brush){var a=i.selectAll("."+Qa["tree-selection-brush"]).data([0]).enter().insert("g",":first-child").attr("class",Qa["tree-selection-brush"]),l=vi().on("brush",(t,e)=>{var n=t.selection,i=this.links.filter(dl).filter((t,e)=>t.source.screen_x>=n[0][0]&&t.source.screen_x<=n[1][0]&&t.source.screen_y>=n[0][1]&&t.source.screen_y<=n[1][1]&&t.target.screen_x>=n[0][0]&&t.target.screen_x<=n[1][0]&&t.target.screen_y>=n[0][1]&&t.target.screen_y<=n[1][1]).map(t=>t.target);this.modifySelection(this.phylotree.links.map(t=>t.target),"tag",!1,i.length>0,"false"),this.modifySelection(i,"tag",!1,!1,"true")}).on("end",()=>{});a.call(l)}if(this.syncEdgeLabels(),this.options.zoom){let t=function(){var t,e,n,i=go,r=mo,s=xo,o=yo,a=bo,l=[0,1/0],u=[[-1/0,-1/0],[1/0,1/0]],c=250,h=Je,f=T("start","zoom","end"),d=0,p=10;function _(t){t.property("__zoom",vo).on("wheel.zoom",w,{passive:!1}).on("mousedown.zoom",N).on("dblclick.zoom",M).filter(a).on("touchstart.zoom",S).on("touchmove.zoom",E).on("touchend.zoom touchcancel.zoom",A).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function g(t,e){return(e=Math.max(l[0],Math.min(l[1],e)))===t.k?t:new ho(e,t.x,t.y)}function m(t,e,n){var i=e[0]-n[0]*t.k,r=e[1]-n[1]*t.k;return i===t.x&&r===t.y?t:new ho(t.k,i,r)}function v(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function y(t,e,n,i){t.on("start.zoom",function(){b(this,arguments).event(i).start()}).on("interrupt.zoom end.zoom",function(){b(this,arguments).event(i).end()}).tween("zoom",function(){var t=this,s=arguments,o=b(t,s).event(i),a=r.apply(t,s),l=null==n?v(a):"function"==typeof n?n.apply(t,s):n,u=Math.max(a[1][0]-a[0][0],a[1][1]-a[0][1]),c=t.__zoom,f="function"==typeof e?e.apply(t,s):e,d=h(c.invert(l).concat(u/c.k),f.invert(l).concat(u/f.k));return function(t){if(1===t)t=f;else{var e=d(t),n=u/e[2];t=new ho(n,l[0]-e[0]*n,l[1]-e[1]*n)}o.zoom(null,t)}})}function b(t,e,n){return!n&&t.__zooming||new x(t,e)}function x(t,e){this.that=t,this.args=e,this.active=0,this.sourceEvent=null,this.extent=r.apply(t,e),this.taps=0}function w(t,...e){if(i.apply(this,arguments)){var n=b(this,e).event(t),r=this.__zoom,a=Math.max(l[0],Math.min(l[1],r.k*Math.pow(2,o.apply(this,arguments)))),c=Bt(t);if(n.wheel)n.mouse[0][0]===c[0]&&n.mouse[0][1]===c[1]||(n.mouse[1]=r.invert(n.mouse[0]=c)),clearTimeout(n.wheel);else{if(r.k===a)return;n.mouse=[c,r.invert(c)],wn(this),n.start()}_o(t),n.wheel=setTimeout(function(){n.wheel=null,n.end()},150),n.zoom("mouse",s(m(g(r,a),n.mouse[0],n.mouse[1]),n.extent,u))}}function N(t,...e){if(!n&&i.apply(this,arguments)){var r=t.currentTarget,o=b(this,e,!0).event(t),a=Yt(t.view).on("mousemove.zoom",function(t){if(_o(t),!o.moved){var e=t.clientX-c,n=t.clientY-h;o.moved=e*e+n*n>d}o.event(t).zoom("mouse",s(m(o.that.__zoom,o.mouse[0]=Bt(t,r),o.mouse[1]),o.extent,u))},!0).on("mouseup.zoom",function(t){a.on("mousemove.zoom mouseup.zoom",null),Xt(t.view,o.moved),_o(t),o.event(t).end()},!0),l=Bt(t,r),c=t.clientX,h=t.clientY;qt(t.view),po(t),o.mouse=[l,this.__zoom.invert(l)],wn(this),o.start()}}function M(t,...e){if(i.apply(this,arguments)){var n=this.__zoom,o=Bt(t.changedTouches?t.changedTouches[0]:t,this),a=n.invert(o),l=n.k*(t.shiftKey?.5:2),h=s(m(g(n,l),o,a),r.apply(this,e),u);_o(t),c>0?Yt(this).transition().duration(c).call(y,h,o,t):Yt(this).call(_.transform,h,o,t)}}function S(n,...r){if(i.apply(this,arguments)){var s,o,a,l,u=n.touches,c=u.length,h=b(this,r,n.changedTouches.length===c).event(n);for(po(n),o=0;o<c;++o)l=[l=Bt(a=u[o],this),this.__zoom.invert(l),a.identifier],h.touch0?h.touch1||h.touch0[2]===l[2]||(h.touch1=l,h.taps=0):(h.touch0=l,s=!0,h.taps=1+!!t);t&&(t=clearTimeout(t)),s&&(h.taps<2&&(e=l[0],t=setTimeout(function(){t=null},500)),wn(this),h.start())}}function E(t,...e){if(this.__zooming){var n,i,r,o,a=b(this,e).event(t),l=t.changedTouches,c=l.length;for(_o(t),n=0;n<c;++n)r=Bt(i=l[n],this),a.touch0&&a.touch0[2]===i.identifier?a.touch0[0]=r:a.touch1&&a.touch1[2]===i.identifier&&(a.touch1[0]=r);if(i=a.that.__zoom,a.touch1){var h=a.touch0[0],f=a.touch0[1],d=a.touch1[0],p=a.touch1[1],_=(_=d[0]-h[0])*_+(_=d[1]-h[1])*_,v=(v=p[0]-f[0])*v+(v=p[1]-f[1])*v;i=g(i,Math.sqrt(_/v)),r=[(h[0]+d[0])/2,(h[1]+d[1])/2],o=[(f[0]+p[0])/2,(f[1]+p[1])/2]}else{if(!a.touch0)return;r=a.touch0[0],o=a.touch0[1]}a.zoom("touch",s(m(i,r,o),a.extent,u))}}function A(t,...i){if(this.__zooming){var r,s,o=b(this,i).event(t),a=t.changedTouches,l=a.length;for(po(t),n&&clearTimeout(n),n=setTimeout(function(){n=null},500),r=0;r<l;++r)s=a[r],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])<p)){var u=Yt(this).on("dblclick.zoom");u&&u.apply(this,arguments)}}}return _.transform=function(t,e,n,i){var r=t.selection?t.selection():t;r.property("__zoom",vo),t!==r?y(t,e,n,i):r.interrupt().each(function(){b(this,arguments).event(i).start().zoom(null,"function"==typeof e?e.apply(this,arguments):e).end()})},_.scaleBy=function(t,e,n,i){_.scaleTo(t,function(){return this.__zoom.k*("function"==typeof e?e.apply(this,arguments):e)},n,i)},_.scaleTo=function(t,e,n,i){_.transform(t,function(){var t=r.apply(this,arguments),i=this.__zoom,o=null==n?v(t):"function"==typeof n?n.apply(this,arguments):n,a=i.invert(o),l="function"==typeof e?e.apply(this,arguments):e;return s(m(g(i,l),o,a),t,u)},n,i)},_.translateBy=function(t,e,n,i){_.transform(t,function(){return s(this.__zoom.translate("function"==typeof e?e.apply(this,arguments):e,"function"==typeof n?n.apply(this,arguments):n),r.apply(this,arguments),u)},null,i)},_.translateTo=function(t,e,n,i,o){_.transform(t,function(){var t=r.apply(this,arguments),o=this.__zoom,a=null==i?v(t):"function"==typeof i?i.apply(this,arguments):i;return s(fo.translate(a[0],a[1]).scale(o.k).translate("function"==typeof e?-e.apply(this,arguments):-e,"function"==typeof n?-n.apply(this,arguments):-n),t,u)},i,o)},x.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=Yt(this.that).datum();f.call(t,this.that,new co(t,{sourceEvent:this.sourceEvent,target:_,type:t,transform:this.that.__zoom,dispatch:f}),e)}},_.wheelDelta=function(t){return arguments.length?(o="function"==typeof t?t:uo(+t),_):o},_.filter=function(t){return arguments.length?(i="function"==typeof t?t:uo(!!t),_):i},_.touchable=function(t){return arguments.length?(a="function"==typeof t?t:uo(!!t),_):a},_.extent=function(t){return arguments.length?(r="function"==typeof t?t:uo([[+t[0][0],+t[0][1]],[+t[1][0],+t[1][1]]]),_):r},_.scaleExtent=function(t){return arguments.length?(l[0]=+t[0],l[1]=+t[1],_):[l[0],l[1]]},_.translateExtent=function(t){return arguments.length?(u[0][0]=+t[0][0],u[1][0]=+t[1][0],u[0][1]=+t[0][1],u[1][1]=+t[1][1],_):[[u[0][0],u[0][1]],[u[1][0],u[1][1]]]},_.constrain=function(t){return arguments.length?(s=t,_):s},_.duration=function(t){return arguments.length?(c=+t,_):c},_.interpolate=function(t){return arguments.length?(h=t,_):h},_.on=function(){var t=f.on.apply(f,arguments);return t===f?_:t},_.clickDistance=function(t){return arguments.length?(d=(t=+t)*t,_):Math.sqrt(d)},_.tapDistance=function(t){return arguments.length?(p=+t,_):p},_}().scaleExtent([.1,10]).on("zoom",t=>{Yt("."+Qa["tree-container"]).attr("transform",e=>t.transform),Yt("."+Qa["tree-scale-bar"]).attr("transform",e=>{let n=t.transform;return n.y-=10,n})});this.svg.call(t)}return this.emit("rendered"),this}_handle_single_node_layout(t){let e=this.nodeSpan(t)/this.rescale_nodeSpan;this.x=t.x=this.x+this.separation(this.last_node,t)+.5*(this.last_span+e),this._extents[1][1]=Math.max(this._extents[1][1],t.y),this._extents[1][0]=Math.min(this._extents[1][0],t.y-.5*e),this.is_under_collapsed_parent?this._extents[0][1]=Math.max(this._extents[0][1],this.save_x+(t.x-this.save_x)*this.options.compression+this.save_span+(.5*e+this.separation(this.last_node,t))*this.options.compression):this._extents[0][1]=Math.max(this._extents[0][1],this.x+.5*e+this.separation(this.last_node,t)),this.last_node=t,this.last_span=e}tree_layout(t){if(sl(t))return;let e=Sa(t);t.text_angle=null,t.text_align=null,t.radius=null,t.angle=null;let n=!1;if(t.parent)if(this.do_scaling){if(n)return 0;if(t.y=this.phylotree.branch_length_accessor(t),void 0===t.y)return n=!0,0;t.y+=t.parent.y}else t.y=e?this.max_depth:t.depth;else this.x=0,t.y=0,this.last_node=null,this.last_span=0,this._extents=[[0,0],[0,0]];if(e&&this._handle_single_node_layout(t),!e)if(al(t)&&!this.is_under_collapsed_parent){if(this.save_x=this.x,this.save_span=.5*this.last_span,this.is_under_collapsed_parent=!0,this.process_internal_node(t),this.is_under_collapsed_parent=!1,"number"==typeof t.x){t.x=this.save_x+(t.x-this.save_x)*this.options.compression+this.save_span,t.collapsed=[[t.x,t.y]];var i=e=>{e.hidden=!0,Sa(e)?(this.x=e.x=this.save_x+(e.x-this.save_x)*this.options.compression+this.save_span,t.collapsed.push([e.x,e.y])):e.children.map(i)};this.x=this.save_x,i(t),t.collapsed.splice(1,0,[this.save_x,t.y]),t.collapsed.push([this.x,t.y]),t.collapsed.push([t.x,t.y]),t.hidden=!1}}else this.process_internal_node(t);return t.x}process_internal_node(t){let e=0;if(this.showInternalName(t)){let e=t.children.length/2|0,n=0,i=!1;for(let r=0;r<t.children.length;r++){"number"==typeof this.tree_layout(t.children[r])&&n++,n>=e&&!i&&(this._handle_single_node_layout(t),i=!0)}0==n?(t.notshown=!0,t.x=void 0):i||this._handle_single_node_layout(t)}else t.x=t.children.map(this.tree_layout.bind(this)).reduce((t,n)=>"number"==typeof n?t+n:(e+=1,t),0),e==t.children.length?(t.notshown=!0,t.x=void 0):t.x/=t.children.length-e}do_lr(t){if(this.radial()&&t&&(this.offsets[1]=0),"fixed-step"==this.options["left-right-spacing"])this.size[1]=this.max_depth*this.fixed_width[1],this.scales[1]=(this.size[1]-this.offsets[1]-this.options["left-offset"])/this._extents[1][1],this.label_width=this._label_width(this.shown_font_size),this.radial()&&(this.label_width*=2);else{this.label_width=this._label_width(this.shown_font_size),t=!0;let e=this.size[1]-this.offsets[1]-this.options["left-offset"];.5*e<this.label_width&&(this.shown_font_size*=.5*e/this.label_width,this.label_width=.5*e),this.scales[1]=(this.size[1]-this.offsets[1]-this.options["left-offset"]-this.label_width)/this._extents[1][1]}}placenodes(){this._extents=[[0,0],[0,0]],this.x=0,this.last_span=0,this.last_node=null,this.last_span=0,this.save_x=this.x,this.save_span=.5*this.last_span,this.do_scaling=this.options.scaling;this.is_under_collapsed_parent=!1,this.max_depth=1,this.phylotree.nodes.x=this.tree_layout(this.phylotree.nodes,this.do_scaling),this.max_depth=function(t,e){let n;if(void 0===e)for(const e of t)null!=e&&(n<e||void 0===n&&e>=e)&&(n=e);else{let i=-1;for(let r of t)null!=(r=e(r,++i,t))&&(n<r||void 0===n&&r>=r)&&(n=r)}return n}(this.phylotree.nodes.descendants(),t=>t.depth),this.do_scaling;let t=!1;if(this.draw_scale_bar=this.options["show-scale"]&&this.do_scaling,this.offsets[1]=Math.max(this.font_size,-this._extents[1][0]*this.fixed_width[0]),"fixed-step"==this.options["top-bottom-spacing"]?(this.size[0]=this._extents[0][1]*this.fixed_width[0],this.scales[0]=this.fixed_width[0]):(this.scales[0]=(this.size[0]-this.pad_height())/this._extents[0][1],t=!0),this.shown_font_size=Math.min(this.font_size,this.scales[0]),this.radial()){this.draw_branch=r.partial(Xa,this.radial_center),this.edge_placer=Za;let e=null,n=null,i=null,s=0,o=this._extents[0][1]*this.scales[0],a=function(t,e,n,i,r){return r=r||0,Math.sqrt((e-t)*(e-t)+2*(t+r)*(e+r)*(1-Math.cos(n-i)))},l=0;this.phylotree.nodes.each(t=>{let e=t.x*this.scales[0];t.angle=2*Math.PI*e/o,t.text_angle=t.angle-Math.PI/2,t.text_angle=t.text_angle>0&&t.text_angle<Math.PI,t.text_align=t.text_angle?"end":"start",t.text_angle=(t.text_angle?180:0)+180*t.angle/Math.PI}),this.do_lr(t),this.phylotree.nodes.each(t=>{t.radius=t.y*this.scales[1]/this.size[1],l=Math.max(t.radius,l)});let u=0;this.phylotree.nodes.each(t=>{if(!t.children){let r=t.x*this.scales[0];if(null!==e){let o=r-n,c=a(t.radius,i,t.angle,e,u),h=c>0?o/c:10*this.options["max-radius"];if(h>this.options["max-radius"]){let n=o/this.options["max-radius"],r=t.radius+i,a=t.radius*i-(n*n-(i-t.radius)*(i-t.radius))/2/(1-Math.cos(e-t.angle)),c=Math.sqrt(r*r-4*a);u=Math.min(this.options["annular-limit"]*l,(-r+c)/2),s=this.options["max-radius"]}else s=Math.max(s,h)}e=t.angle,n=r,i=t.radius}}),this.radius=Math.min(this.options["max-radius"],Math.max(o/2/Math.PI,s)),t&&(this.radius=Math.min(this.radius,.5*(Math.min(o,this._extents[1][1]*this.scales[1])-this.label_width)-this.radius*u)),this.radial_center=this.radius_pad_for_bubbles=this.radius,this.draw_branch=r.partial(Xa,this.radial_center);let c=1;u&&(c=l/(l+u),this.radius*=c),this.phylotree.nodes.each(t=>{if(qa(t,this.radius,u,this.radial_center,this.scales,this.size),l=Math.max(l,t.radius),this.options["draw-size-bubbles"]?this.radius_pad_for_bubbles=Math.max(this.radius_pad_for_bubbles,t.radius+this.nodeBubbleSize(t)):this.radius_pad_for_bubbles=Math.max(this.radius_pad_for_bubbles,t.radius),t.collapsed){t.collapsed=t.collapsed.map(t=>{let e={};return e.x=t[0],e.y=t[1],e=qa(e,this.radius,u,this.radial_center,this.scales,this.size),[e.x,e.y]});let e=t.collapsed[1];t.collapsed=t.collapsed.filter(function(n,i){return i<3||i>t.collapsed.length-4||Math.sqrt(Math.pow(n[0]-e[0],2)+Math.pow(n[1]-e[1],2))>3&&(e=n,!0)})}}),this.size[0]=this.radial_center+this.radius/c,this.size[1]=this.radial_center+this.radius/c}else this.do_lr(),this.draw_branch=Wa,this.edge_placer=Ga,this.right_most_leaf=0,this.phylotree.nodes.each(t=>{if(t.x*=this.scales[0],t.y*=.8*this.scales[1],"right-to-left"==this.options.layout&&(t.y=this._extents[1][1]*this.scales[1]-t.y),Sa(t)&&(this.right_most_leaf=Math.max(this.right_most_leaf,t.y+this.nodeBubbleSize(t))),t.collapsed){t.collapsed.forEach(t=>{t[0]*=this.scales[0],t[1]*=.8*this.scales[1]});let e=t.collapsed[1][0];t.collapsed=t.collapsed.filter(function(n,i){return i<3||i>t.collapsed.length-4||n[0]-e>3&&(e=n[0],!0)})}});if(this.draw_scale_bar){let t,e;if(this.radial()){if(e=Math.min(this.radius/5,50),t=Math.pow(10,Math.ceil(Math.log(this._extents[1][1]*e/this.radius)/Math.log(10))),e=t*(this.radius/this._extents[1][1]),e<30){let n=Math.ceil(30/e);e*=n,t*=n}}else t=this._extents[1][1],e=this.size[1]-this.offsets[1]-this.options["left-offset"]-this.shown_font_size;let n=ir().domain([0,t]).range([0,e]),i=Pi(".2f");if(this.draw_scale_bar=function(t){return M(1,t)}().scale(n).tickFormat(function(t){return 0===t?"":i(t)}),this.radial())this.draw_scale_bar.tickValues([t]);else{let t=function(t,e){return e?Math.round(t*(e=Math.pow(10,e)))/e:Math.round(t)},r=n.ticks();r=r.length>1?r[1]:r[0],this.draw_scale_bar.ticks(Math.min(10,t(e/(this.shown_font_size*i(r).length*2),0)))}}else this.draw_scale_bar=null;return this}spacing_x(t,e){return arguments.length?(this.fixed_width[0]!=t&&t>=this.options["minimum-per-node-spacing"]&&t<=this.options["maximum-per-node-spacing"]&&(this.fixed_width[0]=t,e||this.placenodes()),this):this.fixed_width[0]}spacing_y(t,e){return arguments.length?(this.fixed_width[1]!=t&&t>=this.options["minimum-per-level-spacing"]&&t<=this.options["maximum-per-level-spacing"]&&(this.fixed_width[1]=t,e||this.placenodes()),this):this.fixed_width[1]}_label_width(t){t=t||this.shown_font_size;let e=0;return this.phylotree.nodes.descendants().filter(rl).forEach(n=>{let i=12+this._nodeLabel(n).length*t*.8;null!==n.angle&&(i*=Math.max(Math.abs(Math.cos(n.angle)),Math.abs(Math.sin(n.angle)))),e=Math.max(i,e)}),e}font_size(t){return arguments.length?(this.font_size=void 0===t?12:t,this):this.font_size}scale_bar_font_size(t){return arguments.length?(this.scale_bar_font_size=void 0===t?12:t,this):this.scale_bar_font_size}node_circle_size(t,e){return arguments.length?(this.options.node_circle_size=El(void 0===t?3:t),this):this.options.node_circle_size}css(t){if(0===arguments.length)return this.css_classes;if(arguments.length>2){var e={};return e[t[0]]=t[1],this.css(e)}for(var n in Qa)n in t&&t[n]!=Qa[n]&&(Qa[n]=t[n]);return this}transitions(t){return void 0!==t?t:null!==this.options.transitions?this.options.transitions:this.phylotree.nodes.descendants().length<=300}css_classes(t,e){if(!arguments.length)return this.css_classes;let n=!1;for(var i in Qa)i in t&&t[i]!=this.css_classes[i]&&(n=!0,this.css_classes[i]=t[i]);return e&&n&&this.layout(),this}layout(t){return this.svg?(this.svg.selectAll("."+this.css_classes["tree-container"]+",."+this.css_classes["tree-scale-bar"]+",."+this.css_classes["tree-selection-brush"]),this.d3PhylotreeTriggerLayout(this),this.update()):(this.d3PhylotreeTriggerLayout(this),this)}handle_node_click(t,e){this.nodeDropdownMenu(t,this.container,this,this.options,e)}refresh(){if(this.svg){let t=this.svg.selectAll("."+this.css_classes["tree-container"]).selectAll(pl(this.css_classes)).attr("class",this.reclassEdge.bind(this));this.edge_styler&&t.each(t=>{this.edge_styler(Yt(this),t)})}return this}countHandler(t){return arguments.length?(this.count_listener_handler=t,this):this.count_listener_handler}style_nodes(t){return arguments.length?(this.node_styler=t,this):this.node_styler}style_edges(t){return arguments.length?(this.edge_styler=t.bind(this),this):this.edge_styler}itemSelected(t,e){return t[e]||!1}show(){return this.svg.node()}}r.extend(Al.prototype,fl),r.extend(Al.prototype,cl),r.extend(Al.prototype,_l),r.extend(Al.prototype,xl),r.extend(Al.prototype,Ml),r.extend(Al.prototype,il),r.extend(Al.prototype,Sl),r.extend(Al.prototype,Tl);let kl=class{constructor(t,e={}){this.newick_string="",this.nodes=[],this.links=[],this.parsed_tags=[],this.partitions=[],this.branch_length_accessor=Ha,this.branch_length=Ha,this.logger=e.logger||console,this.selection_attribute_name="selected";var n=e.type||void 0,i=[],s=this;if(r.isString(n))n in Ia?i=Ia[n](t,e):s.logger.error("type "+n+" not in registry! Available types are "+r.keys(Ia));else if(r.isFunction(n))try{i=n(t,e)}catch(t){s.logger.error("Could not parse custom format!")}else"root"==t.name?i={json:t,error:null}:"string"!=typeof t?i=t:"application/xml"==t.contentType?i=Pa(t):(this.newick_string=t,i=Aa(t,e));if(i.json){s.nodes=Hi(i.json);let t={};s.nodes.each(e=>{e.data.annotation&&(t[e.data.annotation]=!0)}),s.parsed_tags=Object.keys(t)}else s.nodes=[];return s.links=s.nodes.links(),this.hasBranchLengths()||(console.warn("Phylotree User Warning : NO BRANCH LENGTHS DETECTED, SETTING ALL LENGTHS TO 1"),this.setBranchLength(t=>1)),s}json(t){var e=0;this.traverse_and_compute(function(t){t.json_export_index=e++},t);var n=new Array(e);return e=0,this.traverse_and_compute(function(t){let i=r.clone(t);delete i.json_export_index,t.parent&&(i.parent=t.parent.json_export_index),t.children&&(i.children=r.map(t.children,function(t){return t.json_export_index})),n[e++]=i},t),this.traverse_and_compute(function(t){delete t.json_export_index},t),JSON.stringify(n)}traverse_and_compute(t,e,n,i){return(e="pre-order"==(e=e||"post-order")?function(e){Ua(e,t,i)}:"in-order"==e?function(e){Fa(e,t,i)}:function(e){r.isUndefined(e)||La(e,t,i)})(n||this.nodes),this}get_parsed_tags(){return this.parsed_tags}update(t){this.nodes=t}render(t){return this.display=new Al(this,t),this.display}};function Cl(t){var e=t.branch_length_accessor;if(!e)throw"A non-null branch lengths accessor function is required for this operation";var n=0;function i(t){for(var e=0;e<t.children.length;e++)for(var n=0;n<t.children.length;n++)e!=n&&r.each(t.children[n].cot_path_to_leaves_below,function(i,r){t.children[e].cot_path_to_leaves_above&&(t.children[e].cot_path_to_leaves_above[r]=i+t.children[n].cot_computed_length)})}return t.traverse_and_compute(function(i){if(i.cot_computed_length=e(i),i.parent&&r.isUndefined(i.cot_computed_length))throw"Non-null branch lengths are required for this operation: missing branch length at node "+i.data.name;t.isLeafNode(i)?(i.cot_leaf_index=n++,i.cot_path_to_leaves_below={},i.cot_path_to_leaves_below[i.cot_leaf_index]=0,i.cot_path_to_leaves_above={}):(i.cot_path_to_leaves_below={},i.cot_path_to_leaves_above={})}),t.traverse_and_compute(function(t){t.parent&&r.each(t.cot_path_to_leaves_below,function(e,n){t.parent.cot_path_to_leaves_below[n]=e+t.cot_computed_length})}),i(t.getRootNode()),t.traverse_and_compute(function(e){e.parent&&(r.each(e.parent.cot_path_to_leaves_above,function(t,n){e.cot_path_to_leaves_above[n]=t+e.parent.cot_computed_length}),t.isLeafNode(e)||i(e))},"pre-order"),n}function zl(t,e,n,i,r){var s=t.branch_length(e),o=!1;if(n||(i=e.data.rootToTip,r=0,o=!0),e.children)for(var a=0;a<e.children.length;a++)e.children[a]!=n?zl(t,e.children[a],e,i,r):o=!0;e.data.rtta=e.data.rootToTip-i+r,o&&(i-=s,r+=s),e.parent&&o&&zl(t,e.parent,e,i,r)}function $l(t){var e=t.reduce(function(t,e){return e[2]+t},0),n=t.reduce(function(t,e){return e[2]*e[0]+t},0),i=t.reduce(function(t,e){return e[2]*e[1]+t},0),r=n/e,s=i/e,o=0,a=0,l=0;t.forEach(function(t){var e=t[0]-r;a+=t[2]*e*e,o+=t[2]*e*t[1],l+=t[2]*(t[1]-s)*(t[1]-s)});var u=(i-n*(o/=a))/e,c=0;return t.forEach(function(t){var e=t[1]-u-o*t[0];c+=t[2]*e*e}),{intercept:u,slope:o,r2:1-c/l,"var (intercept)":Math.sqrt((1+n*n/(e*a))/e),"var (slope)":Math.sqrt(1/a)}}function Dl(t){var e=t.branch_length_accessor,n=0;t.traverse_and_compute(i=>{if(i.parent&&(i.data._computed_length=e(i),!r.isNumber(i.data._computed_length)))throw"rootToTip cannot be run on trees with missing branch lengths";t.isLeafNode(i)&&(i.data.leaf_index=n++),"r2t"in i.data&&delete i.data.r2t}),t.traverse_and_compute(e=>{e.parent&&("r2t"in e.parent.data||(e.parent.data.r2t={}),t.isLeafNode(e)?e.parent.data.r2t[e.data.leaf_index]=e.data._computed_length:(r.each(e.data.r2t,function(t,n){e.parent.data.r2t[n]=t+e.data._computed_length}),delete e.data.r2t),delete e.data._computed_length)});var i=t.getRootNode().data.r2t;return t.traverse_and_compute(e=>{t.isLeafNode(e)&&(e.data.rootToTip=i[e.data.leaf_index]||0,delete e.data.leaf_index)}),delete t.getRootNode().data.r2t,t}kl.prototype.isLeafNode=Sa,kl.prototype.selectAllDescendants=Ta,kl.prototype.mrca=function(t){var e;return t=t.map(function(t){return"string"==typeof t?t:t.data.name}),this.traverse_and_compute(function(n){n.children?n.parent?(n.data.mrca=r.union(...n.descendants().map(t=>t.data.mrca)),e||n.data.mrca.length!=t.length||(e=n)):e||(e=n):n.data.mrca=r.intersection([n.data.name],t)}),e},kl.prototype.hasBranchLengths=function(){let t=this.branch_length;return!!t&&r.every(this.nodes.descendants(),function(e){return!e.parent||!r.isUndefined(t(e))})},kl.prototype.getBranchLengths=function(){let t=this.branch_length;return r.map(this.nodes.descendants(),e=>t(e))},kl.prototype.branchName=function(t){return arguments.length?(this.nodeLabel=t,this):this.nodeLabel},kl.prototype.normalizeBranchLengths=function(t){let e=this.branch_length,n=r.map(this.nodes.descendants(),function(t){return e(t)?e(t):null});const i=r.max(n),s=r.min(n);return r.each(this.nodes.descendants(),t=>{let n=e(t);n&&e(t,function(t){return(t-s)/(i-s)}(n))}),this},kl.prototype.scaleBranchLengths=function(t){let e=this.branch_length;return r.each(this.nodes.descendants(),n=>{let i=e(n);i&&e(n,t(i))}),this},kl.prototype.getNewick=ka,kl.prototype.getTaggedNewick=function(t={}){const e=t.tag||"Foreground",n=t.multiSet||!1,i=this.display?this.display.selection_attribute_name:"selected";return this.display&&this.display._selectionSets,this.getNewick(t=>n&&t._selectionSet?`{${t._selectionSet}}`:t[i]?`{${e}}`:"")},kl.prototype.resortChildren=function(t,e,n){return this.nodes.sum(function(t){return t.value}).sort(t),this.display&&(this.display.update_layout(this.nodes),this.display.update()),this},kl.prototype.setBranchLength=function(t){return arguments.length?(this.branch_length_accessor=t||Ha,this):this.branch_length_accessor},kl.prototype.maxParsimony=function(t,e){const n=r.partial(function(t,e){if(e.mp=[[0,0],[!1,!1]],Sa(e))e.mp[1][0]=e.mp[1][1]=e[t]||!1,e.mp[0][0]=e.mp[1][0]?1:0,e.mp[0][1]=1-e.mp[0][0];else{e.children.forEach(n);var i=e.children.reduce(function(t,e){return e.mp[0][0]+t},0),r=e.children.reduce(function(t,e){return e.mp[0][1]+t},0);e[t]?(e.mp[0][0]=r+1,e.mp[1][0]=!0,e.mp[0][1]=r,e.mp[1][1]=!0):(i<r+1?(e.mp[0][0]=i,e.mp[1][0]=!1):(e.mp[0][0]=r+1,e.mp[1][0]=!0),r<i+1?(e.mp[0][1]=r,e.mp[1][1]=!0):(e.mp[0][1]=i+1,e.mp[1][1]=!1))}},e);n(this.nodes),this.nodes.each(t=>{t.parent?t.mp=t.mp[1][t.parent.mp?1:0]:t.mp=t.mp[1][t.mp[0][0]<t.mp[0][1]?0:1]}),this.display.modifySelection((t,n)=>Sa(t.target)?t.target[e]:t.target.mp)},kl.prototype.getTipLengths=function(){let t=this.getTips(),e=r.map(t,t=>({name:t.data.name,length:parseFloat(t.data.attribute)}));return e=r.sortBy(e,t=>-t.length),e},kl.prototype.leftChildRightSibling=ja,r.extend(kl.prototype,Ea),r.extend(kl.prototype,Ya),r.extend(kl.prototype,Da);const Ol=Pr("%Y%m%d"),Pl=/([0-9]{4}).?([0-9]{2}).?([0-9]{2})$/g,Il=function(t){if(Sa(t)&&"name"in t){let e=Pl.exec(t.name);if(e)return e[1]+e[2]+e[3]}return null};function Ll(t,e){let n=[];for(let i of s.range(e.length))if(i!=t){let r=[];for(let n of s.range(e[i].length))n!=t&&r.push(e[i][n]);n.push(r)}return n}t.centerOfTree=function(t,e){e=e||2;var n=Cl(t),i=Number.MAX_VALUE,s=0,o=null;return 2==e?t.traverse_and_compute(function(t){if(t.parent){var e=0,a=0,l=0,u=0,c=0;r.each(t.cot_path_to_leaves_below,function(t){e+=t,a+=t*t,c++}),r.each(t.cot_path_to_leaves_above,function(t){l+=t,u+=t*t});var h=n-c,f=(l-e+t.cot_computed_length*h)/n;f<0?f=0:f>t.cot_computed_length&&(f=t.cot_computed_length);var d=u+a+2*(l*(t.cot_computed_length-f)+e*f)+c*f*f+(t.cot_computed_length-f)*(t.cot_computed_length-f)*h;d<i&&(o=t,s=f/t.cot_computed_length,i=d),delete t.cot_computed_length,delete t.cot_path_to_leaves_below,delete t.cot_path_to_leaves_above,delete t.cot_leaf_index}}):t.traverse_and_compute(function(t){if(t.parent)for(var n=t.cot_computed_length>0?.05*t.cot_computed_length:.1,a=0;a<t.cot_computed_length;){var l=0;r.each(t.cot_path_to_leaves_below,function(t){l+=Math.pow(t+a,e)}),r.each(t.cot_path_to_leaves_above,function(n){l+=Math.pow(n+(t.cot_computed_length-a),e)}),l<i&&(o=t,s=a/t.cot_computed_length,i=l),a+=n}}),{location:o,breakpoint:s,distance:i}},t.clusterPicker=function(t,e,n,i,s){i=i||t.getRootNode(),s=r.isNumber(s)?s:1;let o=t.branch_length;t.traverse_and_compute(function(t){if(t.parent){if(t._computed_length=o(t),!r.isNumber(t._computed_length))throw"clusterPicker cannot be run on trees with missing branch lengths";t.max_path_length=0}}),t.traverse_and_compute(function(t){t.parent&&(t.parent.max_path_length=Math.max(t.parent.max_path_length,t.max_path_length+t._computed_length))});var a=[];return t.traverse_and_compute(r.noop,"pre-order",i,function(i){if(!t.isLeafNode(i)){var o=r.isString(i.data.bootstrap_values)?+i.data.bootstrap_values:s;if(o>=e){var l=r.reduce(i.children,function(t,e){return e.max_path_length+e._computed_length+t},0);if(l<=n)return a.push({root:i,diameter:l,bootstrap:o}),!0}}return!1}),t.traverse_and_compute(function(t){t.parent&&(delete t._computed_length,delete t.max_path_length)},"post-order",i),r.each(a,function(e){e.members=[],t.traverse_and_compute(function(n){t.isLeafNode(n)&&e.members.push(n)},"post-order",e.root)}),a},t.computeMidpoint=function(t){if(!t.hasBranchLengths())throw"Center of tree calculation cannot be performed on trees that do not have fully specified branch lengths";var e=t.branch_length;t.traverse_and_compute(function(n){if(n.parent){var i,r=e(n);t.isLeafNode(n)?(i=n,n.max_path=0,n.max_path_terminus=n):(r+=n.max_path,i=n.max_path_terminus),(!n.parent.max_path||n.parent.max_path<r)&&(n.parent.max_path=r,n.parent.max_path_terminus=i)}});var n=t.getRootNode(),i=0;if(n.children.forEach(function(t){if(t.max_path_terminus!==n.max_path_terminus){var r=t.max_path+e(t);r>=i&&(i=r)}}),n.max_path>i){i=.5*(i+n.max_path);for(var r=n.max_path_terminus;;){var s=e(r);if(!(s<=i))return{location:r,breakpoint:i/s};i-=s,r=r.parent}}return{location:n,breakpoint:0}},t.extract_dates=function(t,e,n=Ol){return e=e||Il,t.traverse_and_compute(function(t){var i=e(t);if(i)try{t.data.date_value=n(i);var r=t.data.date_value.getFullYear(),s=new Date(r,0,1),o=new Date(r+1,0,1);return void(t.data.decimal_date_value=r+(t.data.date_value-s)/(o-s))}catch(t){}t.data.date_value=null,t.data.decimal_date_value=null}),t},t.fitRootToTip=function(t){var e=[],n=0,i=0;!function(t){t.traverse_and_compute(function(e){t.isLeafNode(e)&&(e.data.copy_number=1)})}(t),Dl(t),t.traverse_and_compute(function(n){t.isLeafNode(n)&&!r.isNull(n.data.decimal_date_value)&&e.push([n.data.decimal_date_value,n.data.rtta,n.data.copy_number])});let s=$l(e);return t.traverse_and_compute(function(o){if(t.isLeafNode(o)&&!r.isNull(o.data.decimal_date_value)){zl(t,o,null,0,0),e=[],t.traverse_and_compute(function(n){t.isLeafNode(n)&&!r.isNull(n.data.decimal_date_value)&&e.push([n.data.decimal_date_value,n.data.rtta,n.data.copy_number])});var a=$l(e),l=a.r2;l>n&&(n=l,i=o,s=a)}}),{root:i,fit:s}},t.getDistanceMatrix=function(t){let e=s.keys(t)[0],n=t[e].length;return s.mapValues(t,e=>s.map(t,t=>s.sum(s.map(s.range(n),n=>e[n]!=t[n]&&"-"!=e[n]&&"-"!=t[n]))))},t.getNewick=ka,t.inOrder=Fa,t.leftChildRightSibling=ja,t.loadAnnotations=za,t.neighborJoining=function t(e,n,i){if(n<=2){let t=new kl(""),n=t.getNodes(),r=e[0][1]/2,s=t.createNode(i[0],[null,[r]]),o=t.createNode(i[1],[null,[r]]);return t.addChild(n,s),t.addChild(n,o),t}{let o=n,a=(r=e,s.map(r,s.sum)),l=function(t,e,n){let i=s.chunk(s.fill(Array(n*n),0),n);for(let r of s.range(n))for(let o of s.range(s.parseInt(r)+1,n))i[r][o]=(n-2)*t[r][o]-e[r]-e[o],i[o][r]=i[r][o];return i}(e,a,o),[u,c,h]=function(t,e){let n=-1,i=-1,r=1/0;for(let o of s.range(e))for(let a of s.range(n,e))t[o][a]<r&&(n=o,i=a,r=t[n][i]);return[n,i,r]}(l,o),f=function(t,e){let n=s.chunk(Array(e*e),e);for(let i of s.range(e))for(let r of s.range(parseInt(i)+1,e))n[i][r]=(t[i]-t[r])/(e-2),n[r][i]=n[i][r];return n}(a,o),d=(e[u][c]+f[u][c])/2,p=(e[u][c]-f[u][c])/2,_=s.concat(0,s.filter(s.map(s.range(n),t=>{if(t!=u&&t!=c)return.5*(e[t][u]+e[t][c]-e[u][c])}),s.isNumber)),g=i[u],m=i[c],v="InternalNode0",y=s.filter(i,t=>s.includes(t,"InternalNode"));if(y.length){let t=s.max(s.map(y,t=>s.split(t,"InternalNode")[1]));v="InternalNode"+ ++t}i.unshift(v),e=Ll(s.max([u,c]),e),(e=Ll(s.min([u,c]),e)).unshift(_),s.each(s.range(1,n-1),t=>e[t].unshift(_[t])),s.remove(i,t=>t==g||t==m);let b=t(e,o-1,i),x=b.createNode(g,[null,[d]]),w=b.createNode(m,[null,[p]]);if(b.getNodeByName(v)){let t=b.getNodeByName(v);b.addChild(t,x),b.addChild(t,w)}else{let t=b.createNode(v,[null,[0]]);b.addChild(b.getNodes(),t),b.addChild(t,x),b.addChild(t,w)}return b}var r},t.newickParser=Aa,t.pairwise_distances=Cl,t.parseAnnotations=Ca,t.parseFasta=function(t){let e=s.split(t,"\n");return s.chain(e).map((t,e)=>t.startsWith(">")?e:-1).filter(t=>-1!=t).map((t,n,i)=>s.slice(e,i[n],i[n+1])).keyBy(t=>s.trim(t[0],">")).mapValues(t=>s.tail(t).join("")).value()},t.phylopart=function(t,e,n,i,s){i=r.isNumber(i)?i:1;var o=Cl(t),a=t.getRootNode().children[0],l=Number.MAX_VALUE,u=Number.MAX_VALUE;if(!(n>0&&n<1))throw"Invalid percentile threshold in perform_phylopart";t.traverse_and_compute(function(e){t.isLeafNode(e)&&(e.cot_computed_length<l?(l<u&&(u=l),l=e.cot_computed_length):e.cot_computed_length<u&&(u=e.cot_computed_length))}),l+=u;var c=r.reduce(a.cot_path_to_leaves_below,function(t,e){return e>t?e:t},0)+r.reduce(a.cot_path_to_leaves_above,function(t,e){return e>t?e:t},0)+a.cot_computed_length-l;r.isUndefined(s)&&(s=Math.min(.001,c/100));var h=1+(c/s|0);h>500&&(s=c/(h=500));var f=t.getRootNode();f.paths_to_leaves=new Array(o),r.each(f.children,function(t){r.each(f.cot_path_to_leaves_below,function(e,n){f.paths_to_leaves[n]=e+t.cot_computed_length})}),t.traverse_and_compute(function(e){if(!t.isLeafNode(e)){e.histogram=new Array(h);for(var n=0;n<h;n++)e.histogram[n]=0;if(e.parent){var i=0;e.paths_to_leaves=[],r.each(e.cot_path_to_leaves_below,function(t,n){e.paths_to_leaves[i++]=t})}}delete e.cot_path_to_leaves_above,delete e.cot_path_to_leaves_below}),t.traverse_and_compute(function(e){if(!t.isLeafNode(e)){for(var n=0;n<e.paths_to_leaves.length;n++)for(var i=n+1;i<e.paths_to_leaves.length;i++){var r=e.paths_to_leaves[n]+e.paths_to_leaves[i];e.histogram[(r-l)/s|0]++}e.leaf_count=e.paths_to_leaves.length,delete e.paths_to_leaves}});for(var d=(o-1)*o/2*n,p=0;p<h-1&&d>f.histogram[p];p++)d-=f.histogram[p];var _=l+(p+(f.histogram[p]-d)/f.histogram[p])*s,g=[];return t.traverse_and_compute(r.noop,"pre-order",null,function(n){if(!t.isLeafNode(n)){var o=r.isString(n.data.bootstrap_values)?+n.data.bootstrap_values:i;if(o>=e){for(var a=n.leaf_count*(n.leaf_count-1)*.25,u=0;u<h-1&&a>n.histogram[u];u++)a-=n.histogram[u];var c=l+(u+(n.histogram[u]-a)/n.histogram[u])*s;if(c<=_)return g.push({root:n,median:c,bootstrap:o}),!0}}return!1}),t.traverse_and_compute(function(e){t.isLeafNode(e)||"histogram"in e&&(delete e.histogram,delete e.leaf_count)}),r.each(g,function(e){e.members=[],t.traverse_and_compute(function(n){t.isLeafNode(n)&&e.members.push(n)},"post-order",e.root)}),g},t.phylotree=kl,t.postOrder=La,t.preOrder=Ua,t.rootToTip=Dl,t.sackin=function(t){let e=t.getTips(),n=r.map(e,t=>t.depth);return r.reduce(n,function(t,e){return t+e},0)},Object.defineProperty(t,"__esModule",{value:!0})});
|
|
2
2
|
//# sourceMappingURL=phylotree.min.js.map
|