phylotree 2.6.0 → 2.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/phylotree-menus.css +93 -0
- package/dist/phylotree.d.ts +473 -241
- package/dist/phylotree.js +1719 -717
- package/dist/phylotree.min.js +1 -1
- package/package.json +21 -12
- package/src/render/clades.js +5 -2
- package/src/render/draw.js +35 -33
- package/src/render/edges.js +5 -5
- package/src/render/events.js +2 -3
- package/src/render/menus.js +27 -4
- package/src/render/nodes.js +27 -7
- package/src/render/options.js +3 -1
- package/src/render/selection-sets.js +12 -14
- package/src/rooting.js +3 -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 i(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:h,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 h(){return 0}const u=l(o).right;l(function(t){return null===t?NaN:+t}).center;const c=Math.sqrt(50),d=Math.sqrt(10),f=Math.sqrt(2);function p(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>=c?10:s>=d?5:s>=f?2:1;let a,l,h;return r<0?(h=Math.pow(10,-r)/o,a=Math.round(t*h),l=Math.round(e*h),a/h<t&&++a,l/h>e&&--l,h=-h):(h=Math.pow(10,r)*o,a=Math.round(t/h),l=Math.round(e/h),a*h<t&&++a,l*h>e&&--l),l<a&&.5<=n&&n<2?p(t,e,2*n):[a,l,h]}function g(t,e,n){return p(t=+t,e=+e,n=+n)[2]}function _(t){return t}var m=1e-6;function y(t){return"translate("+t+",0)"}function v(t){return e=>+t(e)}function b(t,e){return e=Math.max(0,t.bandwidth()-2*e)/2,t.round()&&(e=Math.round(e)),n=>+t(n)+e}function x(){return!this.__axis}function w(t,e){var n=[],i=null,r=null,s=6,o=6,a=3,l="undefined"!=typeof window&&window.devicePixelRatio>1?0:.5,h=-1,u="y",c=y;function d(t){var d=null==i?e.ticks?e.ticks.apply(e,n):e.domain():i,f=null==r?e.tickFormat?e.tickFormat.apply(e,n):_:r,p=Math.max(s,0)+a,g=e.range(),y=+g[0]+l,w=+g[g.length-1]+l,N=(e.bandwidth?b:v)(e.copy(),l),E=t.selection?t.selection():t,S=E.selectAll(".domain").data([null]),T=E.selectAll(".tick").data(d,e).order(),M=T.exit(),k=T.enter().append("g").attr("class","tick"),A=T.select("line"),C=T.select("text");S=S.merge(S.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),T=T.merge(k),A=A.merge(k.append("line").attr("stroke","currentColor").attr("y2",h*s)),C=C.merge(k.append("text").attr("fill","currentColor").attr(u,h*p).attr("dy","0em")),t!==E&&(S=S.transition(t),T=T.transition(t),A=A.transition(t),C=C.transition(t),M=M.transition(t).attr("opacity",m).attr("transform",function(t){return isFinite(t=N(t))?c(t+l):this.getAttribute("transform")}),k.attr("opacity",m).attr("transform",function(t){var e=this.parentNode.__axis;return c((e&&isFinite(e=e(t))?e:N(t))+l)})),M.remove(),S.attr("d",o?"M"+y+","+h*o+"V"+l+"H"+w+"V"+h*o:"M"+y+","+l+"H"+w),T.attr("opacity",1).attr("transform",function(t){return c(N(t)+l)}),A.attr("y2",h*s),C.attr(u,h*p).text(f),E.filter(x).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor","middle"),E.each(function(){this.__axis=N})}return d.scale=function(t){return arguments.length?(e=t,d):e},d.ticks=function(){return n=Array.from(arguments),d},d.tickArguments=function(t){return arguments.length?(n=null==t?[]:Array.from(t),d):n.slice()},d.tickValues=function(t){return arguments.length?(i=null==t?null:Array.from(t),d):i&&i.slice()},d.tickFormat=function(t){return arguments.length?(r=t,d):r},d.tickSize=function(t){return arguments.length?(s=o=+t,d):s},d.tickSizeInner=function(t){return arguments.length?(s=+t,d):s},d.tickSizeOuter=function(t){return arguments.length?(o=+t,d):o},d.tickPadding=function(t){return arguments.length?(a=+t,d):a},d.offset=function(t){return arguments.length?(l=+t,d):l},d}var N={value:()=>{}};function E(){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 S(i)}function S(t){this._=t}function T(t,e){for(var n,i=0,r=t.length;i<r;++i)if((n=t[i]).name===e)return n.value}function M(t,e,n){for(var i=0,r=t.length;i<r;++i)if(t[i].name===e){t[i]=N,t=t.slice(0,i).concat(t.slice(i+1));break}return null!=n&&t.push({name:e,value:n}),t}S.prototype=E.prototype={constructor:S,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]=M(r[n],t.name,e);else if(null==e)for(n in r)r[n]=M(r[n],t.name,null);return this}for(;++o<a;)if((n=(t=s[o]).type)&&(n=T(r[n],t.name)))return n},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new S(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 k="http://www.w3.org/1999/xhtml",A={svg:"http://www.w3.org/2000/svg",xhtml:k,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function C(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),A.hasOwnProperty(e)?{space:A[e],local:t}:t}function z(t){return function(){var e=this.ownerDocument,n=this.namespaceURI;return n===k&&e.documentElement.namespaceURI===k?e.createElement(t):e.createElementNS(n,t)}}function $(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function P(t){var e=C(t);return(e.local?$:z)(e)}function D(){}function I(t){return null==t?D:function(){return this.querySelector(t)}}function L(){return[]}function O(t){return null==t?L:function(){return this.querySelectorAll(t)}}function U(t){return function(){return function(t){return null==t?[]:Array.isArray(t)?t:Array.from(t)}(t.apply(this,arguments))}}function j(t){return function(){return this.matches(t)}}function F(t){return function(e){return e.matches(t)}}var V=Array.prototype.find;function Y(){return this.firstElementChild}var H=Array.prototype.filter;function R(){return Array.from(this.children)}function B(t){return new Array(t.length)}function q(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function X(t,e,n,i,r,s){for(var o,a=0,l=e.length,h=s.length;a<h;++a)(o=e[a])?(o.__data__=s[a],i[a]=o):n[a]=new q(t,s[a]);for(;a<l;++a)(o=e[a])&&(r[a]=o)}function Z(t,e,n,i,r,s,o){var a,l,h,u=new Map,c=e.length,d=s.length,f=new Array(c);for(a=0;a<c;++a)(l=e[a])&&(f[a]=h=o.call(l,l.__data__,a,e)+"",u.has(h)?r[a]=l:u.set(h,l));for(a=0;a<d;++a)h=o.call(t,s[a],a,s)+"",(l=u.get(h))?(i[a]=l,l.__data__=s[a],u.delete(h)):n[a]=new q(t,s[a]);for(a=0;a<c;++a)(l=e[a])&&u.get(f[a])===l&&(r[a]=l)}function W(t){return t.__data__}function G(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}function J(t,e){return t<e?-1:t>e?1:t>=e?0:NaN}function K(t){return function(){this.removeAttribute(t)}}function Q(t){return function(){this.removeAttributeNS(t.space,t.local)}}function tt(t,e){return function(){this.setAttribute(t,e)}}function et(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function nt(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function it(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 rt(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function st(t){return function(){this.style.removeProperty(t)}}function ot(t,e,n){return function(){this.style.setProperty(t,e,n)}}function at(t,e,n){return function(){var i=e.apply(this,arguments);null==i?this.style.removeProperty(t):this.style.setProperty(t,i,n)}}function lt(t,e){return t.style.getPropertyValue(e)||rt(t).getComputedStyle(t,null).getPropertyValue(e)}function ht(t){return function(){delete this[t]}}function ut(t,e){return function(){this[t]=e}}function ct(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function dt(t){return t.trim().split(/^|\s+/)}function ft(t){return t.classList||new pt(t)}function pt(t){this._node=t,this._names=dt(t.getAttribute("class")||"")}function gt(t,e){for(var n=ft(t),i=-1,r=e.length;++i<r;)n.add(e[i])}function _t(t,e){for(var n=ft(t),i=-1,r=e.length;++i<r;)n.remove(e[i])}function mt(t){return function(){gt(this,t)}}function yt(t){return function(){_t(this,t)}}function vt(t,e){return function(){(e.apply(this,arguments)?gt:_t)(this,t)}}function bt(){this.textContent=""}function xt(t){return function(){this.textContent=t}}function wt(t){return function(){var e=t.apply(this,arguments);this.textContent=null==e?"":e}}function Nt(){this.innerHTML=""}function Et(t){return function(){this.innerHTML=t}}function St(t){return function(){var e=t.apply(this,arguments);this.innerHTML=null==e?"":e}}function Tt(){this.nextSibling&&this.parentNode.appendChild(this)}function Mt(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function kt(){return null}function At(){var t=this.parentNode;t&&t.removeChild(this)}function Ct(){var t=this.cloneNode(!1),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function zt(){var t=this.cloneNode(!0),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function $t(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 Dt(t,e,n){var i=rt(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 It(t,e){return function(){return Dt(this,t,e)}}function Lt(t,e){return function(){return Dt(this,t,e.apply(this,arguments))}}q.prototype={constructor:q,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)}},pt.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 Ot=[null];function Ut(t,e){this._groups=t,this._parents=e}function jt(){return new Ut([[document.documentElement]],Ot)}function Ft(t){return"string"==typeof t?new Ut([[document.querySelector(t)]],[document.documentElement]):new Ut([[t]],Ot)}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 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]}Ut.prototype=jt.prototype={constructor:Ut,select:function(t){"function"!=typeof t&&(t=I(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,h=i[r]=new Array(l),u=0;u<l;++u)(s=a[u])&&(o=t.call(s,s.__data__,u,a))&&("__data__"in s&&(o.__data__=s.__data__),h[u]=o);return new Ut(i,this._parents)},selectAll:function(t){t="function"==typeof t?U(t):O(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,h=0;h<l;++h)(o=a[h])&&(i.push(t.call(o,o.__data__,h,a)),r.push(o));return new Ut(i,r)},selectChild:function(t){return this.select(null==t?Y:function(t){return function(){return V.call(this.children,t)}}("function"==typeof t?t:F(t)))},selectChildren:function(t){return this.selectAll(null==t?R:function(t){return function(){return H.call(this.children,t)}}("function"==typeof t?t:F(t)))},filter:function(t){"function"!=typeof t&&(t=j(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]=[],h=0;h<a;++h)(s=o[h])&&t.call(s,s.__data__,h,o)&&l.push(s);return new Ut(i,this._parents)},data:function(t,e){if(!arguments.length)return Array.from(this,W);var n=e?Z:X,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),h=0;h<s;++h){var u=i[h],c=r[h],d=c.length,f=G(t.call(u,u&&u.__data__,h,i)),p=f.length,g=a[h]=new Array(p),_=o[h]=new Array(p);n(u,c,g,_,l[h]=new Array(d),f,e);for(var m,y,v=0,b=0;v<p;++v)if(m=g[v]){for(v>=b&&(b=v+1);!(y=_[b])&&++b<p;);m._next=y||null}}return(o=new Ut(o,i))._enter=a,o._exit=l,o},enter:function(){return new Ut(this._enter||this._groups.map(B),this._parents)},exit:function(){return new Ut(this._exit||this._groups.map(B),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 h,u=n[l],c=i[l],d=u.length,f=a[l]=new Array(d),p=0;p<d;++p)(h=u[p]||c[p])&&(f[p]=h);for(;l<r;++l)a[l]=n[l];return new Ut(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=J);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,h=r[s]=new Array(l),u=0;u<l;++u)(o=a[u])&&(h[u]=o);h.sort(e)}return new Ut(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=C(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?Q:K:"function"==typeof e?n.local?it:nt:n.local?et:tt)(n,e))},style:function(t,e,n){return arguments.length>1?this.each((null==e?st:"function"==typeof e?at:ot)(t,e,null==n?"":n)):lt(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?ht:"function"==typeof e?ct:ut)(t,e)):this.node()[t]},classed:function(t,e){var n=dt(t+"");if(arguments.length<2){for(var i=ft(this.node()),r=-1,s=n.length;++r<s;)if(!i.contains(n[r]))return!1;return!0}return this.each(("function"==typeof e?vt:e?mt:yt)(n,e))},text:function(t){return arguments.length?this.each(null==t?bt:("function"==typeof t?wt:xt)(t)):this.node().textContent},html:function(t){return arguments.length?this.each(null==t?Nt:("function"==typeof t?St:Et)(t)):this.node().innerHTML},raise:function(){return this.each(Tt)},lower:function(){return this.each(Mt)},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?kt:"function"==typeof e?e:I(e);return this.select(function(){return this.insertBefore(n.apply(this,arguments),i.apply(this,arguments)||null)})},remove:function(){return this.each(At)},clone:function(t){return this.select(t?zt:Ct)},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:$t,i=0;i<o;++i)this.each(a(s[i],e,n));return this}var a=this.node().__on;if(a)for(var l,h=0,u=a.length;h<u;++h)for(i=0,l=a[h];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?Lt:It)(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 Yt={capture:!0,passive:!1};function Ht(t){t.preventDefault(),t.stopImmediatePropagation()}function Rt(t){var e=t.document.documentElement,n=Ft(t).on("dragstart.drag",Ht,Yt);"onselectstart"in e?n.on("selectstart.drag",Ht,Yt):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}function Bt(t,e){var n=t.document.documentElement,i=Ft(t).on("dragstart.drag",null);e&&(i.on("click.drag",Ht,Yt),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 qt(t,e,n){t.prototype=e.prototype=n,n.constructor=t}function Xt(t,e){var n=Object.create(t.prototype);for(var i in e)n[i]=e[i];return n}function Zt(){}var Wt=.7,Gt=1/Wt,Jt="\\s*([+-]?\\d+)\\s*",Kt="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Qt="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",te=/^#([0-9a-f]{3,8})$/,ee=new RegExp(`^rgb\\(${Jt},${Jt},${Jt}\\)$`),ne=new RegExp(`^rgb\\(${Qt},${Qt},${Qt}\\)$`),ie=new RegExp(`^rgba\\(${Jt},${Jt},${Jt},${Kt}\\)$`),re=new RegExp(`^rgba\\(${Qt},${Qt},${Qt},${Kt}\\)$`),se=new RegExp(`^hsl\\(${Kt},${Qt},${Qt}\\)$`),oe=new RegExp(`^hsla\\(${Kt},${Qt},${Qt},${Kt}\\)$`),ae={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 le(){return this.rgb().formatHex()}function he(){return this.rgb().formatRgb()}function ue(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=te.exec(t))?(n=e[1].length,e=parseInt(e[1],16),6===n?ce(e):3===n?new pe(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?de(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?de(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=ee.exec(t))?new pe(e[1],e[2],e[3],1):(e=ne.exec(t))?new pe(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=ie.exec(t))?de(e[1],e[2],e[3],e[4]):(e=re.exec(t))?de(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=se.exec(t))?be(e[1],e[2]/100,e[3]/100,1):(e=oe.exec(t))?be(e[1],e[2]/100,e[3]/100,e[4]):ae.hasOwnProperty(t)?ce(ae[t]):"transparent"===t?new pe(NaN,NaN,NaN,0):null}function ce(t){return new pe(t>>16&255,t>>8&255,255&t,1)}function de(t,e,n,i){return i<=0&&(t=e=n=NaN),new pe(t,e,n,i)}function fe(t,e,n,i){return 1===arguments.length?((r=t)instanceof Zt||(r=ue(r)),r?new pe((r=r.rgb()).r,r.g,r.b,r.opacity):new pe):new pe(t,e,n,null==i?1:i);var r}function pe(t,e,n,i){this.r=+t,this.g=+e,this.b=+n,this.opacity=+i}function ge(){return`#${ve(this.r)}${ve(this.g)}${ve(this.b)}`}function _e(){const t=me(this.opacity);return`${1===t?"rgb(":"rgba("}${ye(this.r)}, ${ye(this.g)}, ${ye(this.b)}${1===t?")":`, ${t})`}`}function me(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function ye(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function ve(t){return((t=ye(t))<16?"0":"")+t.toString(16)}function be(t,e,n,i){return i<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new we(t,e,n,i)}function xe(t){if(t instanceof we)return new we(t.h,t.s,t.l,t.opacity);if(t instanceof Zt||(t=ue(t)),!t)return new we;if(t instanceof we)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 we(o,a,l,t.opacity)}function we(t,e,n,i){this.h=+t,this.s=+e,this.l=+n,this.opacity=+i}function Ne(t){return(t=(t||0)%360)<0?t+360:t}function Ee(t){return Math.max(0,Math.min(1,t||0))}function Se(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}qt(Zt,ue,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:le,formatHex:le,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return xe(this).formatHsl()},formatRgb:he,toString:he}),qt(pe,fe,Xt(Zt,{brighter(t){return t=null==t?Gt:Math.pow(Gt,t),new pe(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?Wt:Math.pow(Wt,t),new pe(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new pe(ye(this.r),ye(this.g),ye(this.b),me(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:ge,formatHex:ge,formatHex8:function(){return`#${ve(this.r)}${ve(this.g)}${ve(this.b)}${ve(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:_e,toString:_e})),qt(we,function(t,e,n,i){return 1===arguments.length?xe(t):new we(t,e,n,null==i?1:i)},Xt(Zt,{brighter(t){return t=null==t?Gt:Math.pow(Gt,t),new we(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?Wt:Math.pow(Wt,t),new we(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 pe(Se(t>=240?t-240:t+120,r,i),Se(t,r,i),Se(t<120?t+240:t-120,r,i),this.opacity)},clamp(){return new we(Ne(this.h),Ee(this.s),Ee(this.l),me(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=me(this.opacity);return`${1===t?"hsl(":"hsla("}${Ne(this.h)}, ${100*Ee(this.s)}%, ${100*Ee(this.l)}%${1===t?")":`, ${t})`}`}}));var Te=t=>()=>t;function Me(t){return 1===(t=+t)?ke: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):Te(isNaN(e)?n:e)}}function ke(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):Te(isNaN(t)?e:t)}var Ae=function t(e){var n=Me(e);function i(t,e){var i=n((t=fe(t)).r,(e=fe(e)).r),r=n(t.g,e.g),s=n(t.b,e.b),o=ke(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 Ce(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 ze(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]=Ue(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 $e(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 De(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]=Ue(t[n],e[n]):r[n]=e[n];return function(t){for(n in i)r[n]=i[n](t);return r}}var Ie=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Le=new RegExp(Ie.source,"g");function Oe(t,e){var n,i,r,s=Ie.lastIndex=Le.lastIndex=0,o=-1,a=[],l=[];for(t+="",e+="";(n=Ie.exec(t))&&(i=Le.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=Le.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 Ue(t,e){var n,i=typeof e;return null==e||"boolean"===i?Te(e):("number"===i?Pe:"string"===i?(n=ue(e))?(e=n,Ae):Oe:e instanceof ue?Ae:e instanceof Date?$e:function(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}(e)?Ce:Array.isArray(e)?ze:"function"!=typeof e.valueOf&&"function"!=typeof e.toString||isNaN(e)?De:Pe)(t,e)}function je(t,e){return t=+t,e=+e,function(n){return Math.round(t*(1-n)+e*n)}}var Fe,Ve=180/Math.PI,Ye={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function He(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)*Ve,skewX:Math.atan(l)*Ve,scaleX:o,scaleY:a}}function Re(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 Be=Re(function(t){const e=new("function"==typeof DOMMatrix?DOMMatrix:WebKitCSSMatrix)(t+"");return e.isIdentity?Ye:He(e.a,e.b,e.c,e.d,e.e,e.f)},"px, ","px)","deg)"),qe=Re(function(t){return null==t?Ye:(Fe||(Fe=document.createElementNS("http://www.w3.org/2000/svg","g")),Fe.setAttribute("transform",t),(t=Fe.transform.baseVal.consolidate())?He((t=t.matrix).a,t.b,t.c,t.d,t.e,t.f):Ye)},", ",")",")");function Xe(t){return((t=Math.exp(t))+1/t)/2}var Ze,We,Ge=function t(e,n,i){function r(t,r){var s,o,a=t[0],l=t[1],h=t[2],u=r[0],c=r[1],d=r[2],f=u-a,p=c-l,g=f*f+p*p;if(g<1e-12)o=Math.log(d/h)/e,s=function(t){return[a+t*f,l+t*p,h*Math.exp(e*t*o)]};else{var _=Math.sqrt(g),m=(d*d-h*h+i*g)/(2*h*n*_),y=(d*d-h*h-i*g)/(2*d*n*_),v=Math.log(Math.sqrt(m*m+1)-m),b=Math.log(Math.sqrt(y*y+1)-y);o=(b-v)/e,s=function(t){var i=t*o,r=Xe(v),s=h/(n*_)*(r*function(t){return((t=Math.exp(2*t))-1)/(t+1)}(e*i+v)-function(t){return((t=Math.exp(t))-1/t)/2}(v));return[a+s*f,l+s*p,h*r/Xe(e*i+v)]}}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),Je=0,Ke=0,Qe=0,tn=0,en=0,nn=0,rn="object"==typeof performance&&performance.now?performance:Date,sn="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function on(){return en||(sn(an),en=rn.now()+nn)}function an(){en=0}function ln(){this._call=this._time=this._next=null}function hn(t,e,n){var i=new ln;return i.restart(t,e,n),i}function un(){en=(tn=rn.now())+nn,Je=Ke=0;try{!function(){on(),++Je;for(var t,e=Ze;e;)(t=en-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Je}()}finally{Je=0,function(){var t,e,n=Ze,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:Ze=e);We=t,dn(i)}(),en=0}}function cn(){var t=rn.now(),e=t-tn;e>1e3&&(nn-=e,tn=t)}function dn(t){Je||(Ke&&(Ke=clearTimeout(Ke)),t-en>24?(t<1/0&&(Ke=setTimeout(un,t-rn.now()-nn)),Qe&&(Qe=clearInterval(Qe))):(Qe||(tn=rn.now(),Qe=setInterval(cn,1e3)),Je=1,sn(un)))}function fn(t,e,n){var i=new ln;return e=null==e?0:+e,i.restart(n=>{i.stop(),t(n+e)},e,n),i}ln.prototype=hn.prototype={constructor:ln,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?on():+n)+(null==e?0:+e),this._next||We===this||(We?We._next=this:Ze=this,We=this),this._call=t,this._time=n,dn()},stop:function(){this._call&&(this._call=null,this._time=1/0,dn())}};var pn=E("start","end","cancel","interrupt"),gn=[];function _n(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 h,u,c,d;if(1!==n.state)return l();for(h in r)if((d=r[h]).name===n.name){if(3===d.state)return fn(o);4===d.state?(d.state=6,d.timer.stop(),d.on.call("interrupt",t,t.__data__,d.index,d.group),delete r[h]):+h<e&&(d.state=6,d.timer.stop(),d.on.call("cancel",t,t.__data__,d.index,d.group),delete r[h])}if(fn(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(c=n.tween.length),h=0,u=-1;h<c;++h)(d=n.tween[h].value.call(t,t.__data__,n.index,n.group))&&(i[++u]=d);i.length=u+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:pn,tween:gn,time:s.time,delay:s.delay,duration:s.duration,ease:s.ease,timer:null,state:0})}function mn(t,e){var n=vn(t,e);if(n.state>0)throw new Error("too late; already scheduled");return n}function yn(t,e){var n=vn(t,e);if(n.state>3)throw new Error("too late; already running");return n}function vn(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function bn(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 xn(t,e){var n,i;return function(){var r=yn(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 wn(t,e,n){var i,r;if("function"!=typeof n)throw new Error;return function(){var s=yn(this,t),o=s.tween;if(o!==i){r=(i=o).slice();for(var a={name:e,value:n},l=0,h=r.length;l<h;++l)if(r[l].name===e){r[l]=a;break}l===h&&r.push(a)}s.tween=r}}function Nn(t,e,n){var i=t._id;return t.each(function(){var t=yn(this,i);(t.value||(t.value={}))[e]=n.apply(this,arguments)}),function(t){return vn(t,i).value[e]}}function En(t,e){var n;return("number"==typeof e?Pe:e instanceof ue?Ae:(n=ue(e))?(e=n,Ae):Oe)(t,e)}function Sn(t){return function(){this.removeAttribute(t)}}function Tn(t){return function(){this.removeAttributeNS(t.space,t.local)}}function Mn(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 kn(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 An(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 Cn(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 zn(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 $n(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(){mn(this,t).delay=+e.apply(this,arguments)}}function Dn(t,e){return e=+e,function(){mn(this,t).delay=e}}function In(t,e){return function(){yn(this,t).duration=+e.apply(this,arguments)}}function Ln(t,e){return e=+e,function(){yn(this,t).duration=e}}var On=jt.prototype.constructor;function Un(t){return function(){this.style.removeProperty(t)}}var jn=0;function Fn(t,e,n,i){this._groups=t,this._parents=e,this._name=n,this._id=i}function Vn(){return++jn}var Yn=jt.prototype;Fn.prototype={constructor:Fn,select:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=I(t));for(var i=this._groups,r=i.length,s=new Array(r),o=0;o<r;++o)for(var a,l,h=i[o],u=h.length,c=s[o]=new Array(u),d=0;d<u;++d)(a=h[d])&&(l=t.call(a,a.__data__,d,h))&&("__data__"in a&&(l.__data__=a.__data__),c[d]=l,_n(c[d],e,n,d,c,vn(a,n)));return new Fn(s,this._parents,e,n)},selectAll:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=O(t));for(var i=this._groups,r=i.length,s=[],o=[],a=0;a<r;++a)for(var l,h=i[a],u=h.length,c=0;c<u;++c)if(l=h[c]){for(var d,f=t.call(l,l.__data__,c,h),p=vn(l,n),g=0,_=f.length;g<_;++g)(d=f[g])&&_n(d,e,n,g,f,p);s.push(f),o.push(l)}return new Fn(s,o,e,n)},selectChild:Yn.selectChild,selectChildren:Yn.selectChildren,filter:function(t){"function"!=typeof t&&(t=j(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]=[],h=0;h<a;++h)(s=o[h])&&t.call(s,s.__data__,h,o)&&l.push(s);return new Fn(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,h=e[a],u=n[a],c=h.length,d=o[a]=new Array(c),f=0;f<c;++f)(l=h[f]||u[f])&&(d[f]=l);for(;a<i;++a)o[a]=e[a];return new Fn(o,this._parents,this._name,this._id)},selection:function(){return new On(this._groups,this._parents)},transition:function(){for(var t=this._name,e=this._id,n=Vn(),i=this._groups,r=i.length,s=0;s<r;++s)for(var o,a=i[s],l=a.length,h=0;h<l;++h)if(o=a[h]){var u=vn(o,e);_n(o,t,n,h,a,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new Fn(i,this._parents,t,n)},call:Yn.call,nodes:Yn.nodes,node:Yn.node,size:Yn.size,empty:Yn.empty,each:Yn.each,on:function(t,e){var n=this._id;return arguments.length<2?vn(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)?mn:yn;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=C(t),i="transform"===n?qe:En;return this.attrTween(t,"function"==typeof e?(n.local?Cn:An)(n,i,Nn(this,"attr."+t,e)):null==e?(n.local?Tn:Sn)(n):(n.local?kn:Mn)(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=C(t);return this.tween(n,(i.local?zn:$n)(i,e))},style:function(t,e,n){var i="transform"==(t+="")?Be:En;return null==e?this.styleTween(t,function(t,e){var n,i,r;return function(){var s=lt(this,t),o=(this.style.removeProperty(t),lt(this,t));return s===o?null:s===n&&o===i?r:r=e(n=s,i=o)}}(t,i)).on("end.style."+t,Un(t)):"function"==typeof e?this.styleTween(t,function(t,e,n){var i,r,s;return function(){var o=lt(this,t),a=n(this),l=a+"";return null==a&&(this.style.removeProperty(t),l=a=lt(this,t)),o===l?null:o===i&&l===r?s:(r=l,s=e(i=o,a))}}(t,i,Nn(this,"style."+t,e))).each(function(t,e){var n,i,r,s,o="style."+e,a="end."+o;return function(){var l=yn(this,t),h=l.on,u=null==l.value[o]?s||(s=Un(e)):void 0;h===n&&r===u||(i=(n=h).copy()).on(a,r=u),l.on=i}}(this._id,t)):this.styleTween(t,function(t,e,n){var i,r,s=n+"";return function(){var o=lt(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}}(Nn(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=vn(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?xn:wn)(n,t,e))},delay:function(t){var e=this._id;return arguments.length?this.each(("function"==typeof t?Pn:Dn)(e,t)):vn(this.node(),e).delay},duration:function(t){var e=this._id;return arguments.length?this.each(("function"==typeof t?In:Ln)(e,t)):vn(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(){yn(this,t).ease=e}}(e,t)):vn(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;yn(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=yn(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]:Yn[Symbol.iterator]};var Hn={time:null,delay:0,duration:250,ease:function(t){return((t*=2)<=1?t*t*t:(t-=2)*t*t+2)/2}};function Rn(t,e){for(var n;!(n=t.__transition)||!(n=n[e]);)if(!(t=t.parentNode))throw new Error(`transition ${e} not found`);return n}jt.prototype.interrupt=function(t){return this.each(function(){bn(this,t)})},jt.prototype.transition=function(t){var e,n;t instanceof Fn?(e=t._id,t=t._name):(e=Vn(),(n=Hn).time=on(),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,h=0;h<l;++h)(o=a[h])&&_n(o,t,e,h,a,n||Rn(o,e));return new Fn(i,this._parents,t,e)};var Bn=t=>()=>t;function qn(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 Xn(t){t.preventDefault(),t.stopImmediatePropagation()}var Zn={name:"drag"},Wn={name:"space"},Gn={name:"handle"},Jn={name:"center"};const{abs:Kn,max:Qn,min:ti}=Math;function ei(t){return[+t[0],+t[1]]}function ni(t){return[ei(t[0]),ei(t[1])]}var ii={},ri={},si={name:"xy",handles:["n","w","e","s","nw","ne","sw","se"].map(ci),input:function(t){return null==t?null:ni(t)},output:function(t){return t}},oi={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"},ai={e:"w",w:"e",nw:"ne",ne:"nw",se:"sw",sw:"se"},li={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},ui={overlay:1,selection:1,n:-1,e:null,s:1,w:null,nw:-1,ne:-1,se:1,sw:1};function ci(t){return{type:t}}function di(t){return!t.ctrlKey&&!t.button}function fi(){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 pi(){return navigator.maxTouchPoints||"ontouchstart"in this}function gi(t){for(;!t.__brush;)if(!(t=t.parentNode))return;return t.__brush}function _i(){return function(t){var e,n=fi,i=di,r=pi,s=!0,o=E("start","brush","end"),a=6;function l(e){var n=e.property("__brush",g).selectAll(".overlay").data([ci("overlay")]);n.enter().append("rect").attr("class","overlay").attr("pointer-events","all").attr("cursor",oi.overlay).merge(n).each(function(){var t=gi(this).extent;Ft(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([ci("selection")]).enter().append("rect").attr("class","selection").attr("cursor",oi.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 oi[t.type]}),e.each(h).attr("fill","none").attr("pointer-events","all").on("mousedown.brush",d).filter(r).on("touchstart.brush",d).on("touchmove.brush",f).on("touchend.brush touchcancel.brush",p).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function h(){var t=Ft(this),e=gi(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 u(t,e,n){var i=t.__brush.emitter;return!i||n&&i.clean?new c(t,e,n):i}function c(t,e,n){this.that=t,this.args=e,this.state=t.__brush,this.active=0,this.clean=n}function d(n){if((!e||n.touches)&&i.apply(this,arguments)){var r,o,a,l,c,d,f,p,g,_,m,y=this,v=n.target.__data__.type,b="selection"===(s&&n.metaKey?v="overlay":v)?Zn:s&&n.altKey?Jn:Gn,x=t===ri?null:hi[v],w=t===ii?null:ui[v],N=gi(y),E=N.extent,S=N.selection,T=E[0][0],M=E[0][1],k=E[1][0],A=E[1][1],C=0,z=0,$=x&&w&&s&&n.shiftKey,P=Array.from(n.touches||[n],t=>{const e=t.identifier;return(t=Vt(t,y)).point0=t.slice(),t.identifier=e,t});bn(y);var D=u(y,arguments,!0).beforestart();if("overlay"===v){S&&(g=!0);const e=[P[0],P[1]||P[0]];N.selection=S=[[r=t===ri?T:ti(e[0][0],e[1][0]),a=t===ii?M:ti(e[0][1],e[1][1])],[c=t===ri?k:Qn(e[0][0],e[1][0]),f=t===ii?A:Qn(e[0][1],e[1][1])]],P.length>1&&j(n)}else r=S[0][0],a=S[0][1],c=S[1][0],f=S[1][1];o=r,l=a,d=c,p=f;var I=Ft(y).attr("pointer-events","none"),L=I.selectAll(".overlay").attr("cursor",oi[v]);if(n.touches)D.moved=U,D.ended=F;else{var O=Ft(n.view).on("mousemove.brush",U,!0).on("mouseup.brush",F,!0);s&&O.on("keydown.brush",V,!0).on("keyup.brush",Y,!0),Rt(n.view)}h.call(y),D.start(n,b.name)}function U(t){for(const e of t.changedTouches||[t])for(const t of P)t.identifier===e.identifier&&(t.cur=Vt(e,y));if($&&!_&&!m&&1===P.length){const t=P[0];Kn(t.cur[0]-t[0])>Kn(t.cur[1]-t[1])?m=!0:_=!0}for(const t of P)t.cur&&(t[0]=t.cur[0],t[1]=t.cur[1]);g=!0,Xn(t),j(t)}function j(t){const e=P[0],n=e.point0;var i;switch(C=e[0]-n[0],z=e[1]-n[1],b){case Wn:case Zn:x&&(C=Qn(T-r,ti(k-c,C)),o=r+C,d=c+C),w&&(z=Qn(M-a,ti(A-f,z)),l=a+z,p=f+z);break;case Gn:P[1]?(x&&(o=Qn(T,ti(k,P[0][0])),d=Qn(T,ti(k,P[1][0])),x=1),w&&(l=Qn(M,ti(A,P[0][1])),p=Qn(M,ti(A,P[1][1])),w=1)):(x<0?(C=Qn(T-r,ti(k-r,C)),o=r+C,d=c):x>0&&(C=Qn(T-c,ti(k-c,C)),o=r,d=c+C),w<0?(z=Qn(M-a,ti(A-a,z)),l=a+z,p=f):w>0&&(z=Qn(M-f,ti(A-f,z)),l=a,p=f+z));break;case Jn:x&&(o=Qn(T,ti(k,r-C*x)),d=Qn(T,ti(k,c+C*x))),w&&(l=Qn(M,ti(A,a-z*w)),p=Qn(M,ti(A,f+z*w)))}d<o&&(x*=-1,i=r,r=c,c=i,i=o,o=d,d=i,v in ai&&L.attr("cursor",oi[v=ai[v]])),p<l&&(w*=-1,i=a,a=f,f=i,i=l,l=p,p=i,v in li&&L.attr("cursor",oi[v=li[v]])),N.selection&&(S=N.selection),_&&(o=S[0][0],d=S[1][0]),m&&(l=S[0][1],p=S[1][1]),S[0][0]===o&&S[0][1]===l&&S[1][0]===d&&S[1][1]===p||(N.selection=[[o,l],[d,p]],h.call(y),D.brush(t,b.name))}function F(t){if(function(t){t.stopImmediatePropagation()}(t),t.touches){if(t.touches.length)return;e&&clearTimeout(e),e=setTimeout(function(){e=null},500)}else Bt(t.view,g),O.on("keydown.brush keyup.brush mousemove.brush mouseup.brush",null);I.attr("pointer-events","all"),L.attr("cursor",oi.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,h.call(y)),D.end(t,b.name)}function V(t){switch(t.keyCode){case 16:$=x&&w;break;case 18:b===Gn&&(x&&(c=d-C*x,r=o+C*x),w&&(f=p-z*w,a=l+z*w),b=Jn,j(t));break;case 32:b!==Gn&&b!==Jn||(x<0?c=d-C:x>0&&(r=o-C),w<0?f=p-z:w>0&&(a=l-z),b=Wn,L.attr("cursor",oi.selection),j(t));break;default:return}Xn(t)}function Y(t){switch(t.keyCode){case 16:$&&(_=m=$=!1,j(t));break;case 18:b===Jn&&(x<0?c=d:x>0&&(r=o),w<0?f=p:w>0&&(a=l),b=Gn,j(t));break;case 32:b===Wn&&(t.altKey?(x&&(c=d-C*x,r=o+C*x),w&&(f=p-z*w,a=l+z*w),b=Jn):(x<0?c=d:x>0&&(r=o),w<0?f=p:w>0&&(a=l),b=Gn),L.attr("cursor",oi[v]),j(t));break;default:return}Xn(t)}}function f(t){u(this,arguments).moved(t)}function p(t){u(this,arguments).ended(t)}function g(){var e=this.__brush||{selection:null};return e.extent=ni(n.apply(this,arguments)),e.dim=t,e}return l.move=function(e,n,i){e.tween?e.on("start.brush",function(t){u(this,arguments).beforestart().start(t)}).on("interrupt.brush end.brush",function(t){u(this,arguments).end(t)}).tween("brush",function(){var e=this,i=e.__brush,r=u(e,arguments),s=i.selection,o=t.input("function"==typeof n?n.apply(this,arguments):n,i.extent),a=Ue(s,o);function l(t){i.selection=1===t&&null===o?null:a(t),h.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=u(e,r).beforestart();bn(e),s.selection=null===o?null:o,h.call(e),a.start(i).brush(i).end(i)})},l.clear=function(t,e){l.move(t,null,e)},c.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=Ft(this.that).datum();o.call(e,this.that,new qn(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:Bn(ni(t)),l):n},l.filter=function(t){return arguments.length?(i="function"==typeof t?t:Bn(!!t),l):i},l.touchable=function(t){return arguments.length?(r="function"==typeof t?t:Bn(!!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}(si)}const mi=Math.PI,yi=2*mi,vi=1e-6,bi=yi-vi;function xi(t){this._+=t[0];for(let e=1,n=t.length;e<n;++e)this._+=arguments[e]+t[e]}class wi{constructor(t){this._x0=this._y0=this._x1=this._y1=null,this._="",this._append=null==t?xi:function(t){let e=Math.floor(t);if(!(e>=0))throw new Error(`invalid digits: ${t}`);if(e>15)return xi;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,h=s-t,u=o-e,c=h*h+u*u;if(null===this._x1)this._append`M${this._x1=t},${this._y1=e}`;else if(c>vi)if(Math.abs(u*a-l*h)>vi&&r){let d=n-s,f=i-o,p=a*a+l*l,g=d*d+f*f,_=Math.sqrt(p),m=Math.sqrt(c),y=r*Math.tan((mi-Math.acos((p+c-g)/(2*_*m)))/2),v=y/m,b=y/_;Math.abs(v-1)>vi&&this._append`L${t+v*h},${e+v*u}`,this._append`A${r},${r},0,0,${+(u*d>h*f)},${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,h=e+a,u=1^s,c=s?i-r:r-i;null===this._x1?this._append`M${l},${h}`:(Math.abs(this._x1-l)>vi||Math.abs(this._y1-h)>vi)&&this._append`L${l},${h}`,n&&(c<0&&(c=c%yi+yi),c>bi?this._append`A${n},${n},0,1,${u},${t-o},${e-a}A${n},${n},0,1,${u},${this._x1=l},${this._y1=h}`:c>vi&&this._append`A${n},${n},0,${+(c>=mi)},${u},${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 Ni(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 Ei(t){return(t=Ni(Math.abs(t)))?t[1]:NaN}var Si,Ti=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Mi(t){if(!(e=Ti.exec(t)))throw new Error("invalid format: "+t);var e;return new ki({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 ki(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 Ai(t,e){var n=Ni(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")}Mi.prototype=ki.prototype,ki.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 Ci={"%":(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)=>Ai(100*t,e),r:Ai,s:function(t,e){var n=Ni(t,e);if(!n)return t+"";var i=n[0],r=n[1],s=r-(Si=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")+Ni(t,Math.max(0,e+s-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function zi(t){return t}var $i,Pi,Di,Ii=Array.prototype.map,Li=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Oi(t){var e,n,i=void 0===t.grouping||void 0===t.thousands?zi:(e=Ii.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?zi:function(t){return function(e){return e.replace(/[0-9]/g,function(e){return t[+e]})}}(Ii.call(t.numerals,String)),l=void 0===t.percent?"%":t.percent+"",h=void 0===t.minus?"−":t.minus+"",u=void 0===t.nan?"NaN":t.nan+"";function c(t){var e=(t=Mi(t)).fill,n=t.align,c=t.sign,d=t.symbol,f=t.zero,p=t.width,g=t.comma,_=t.precision,m=t.trim,y=t.type;"n"===y?(g=!0,y="g"):Ci[y]||(void 0===_&&(_=12),m=!0,y="g"),(f||"0"===e&&"="===n)&&(f=!0,e="0",n="=");var v="$"===d?r:"#"===d&&/[boxX]/.test(y)?"0"+y.toLowerCase():"",b="$"===d?s:/[%p]/.test(y)?l:"",x=Ci[y],w=/[defgprs%]/.test(y);function N(t){var r,s,l,d=v,N=b;if("c"===y)N=x(t)+N,t="";else{var E=(t=+t)<0||1/t<0;if(t=isNaN(t)?u:x(Math.abs(t),_),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)),E&&0===+t&&"+"!==c&&(E=!1),d=(E?"("===c?c:h:"-"===c||"("===c?"":c)+d,N=("s"===y?Li[8+Si/3]:"")+N+(E&&"("===c?")":""),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}}g&&!f&&(t=i(t,1/0));var S=d.length+t.length+N.length,T=S<p?new Array(p-S+1).join(e):"";switch(g&&f&&(t=i(T+t,T.length?p-N.length:1/0),T=""),n){case"<":t=d+t+N+T;break;case"=":t=d+T+t+N;break;case"^":t=T.slice(0,S=T.length>>1)+d+t+N+T.slice(S);break;default:t=T+d+t+N}return a(t)}return _=void 0===_?6:/[gprs]/.test(y)?Math.max(1,Math.min(21,_)):Math.max(0,Math.min(20,_)),N.toString=function(){return t+""},N}return{format:c,formatPrefix:function(t,e){var n=c(((t=Mi(t)).type="f",t)),i=3*Math.max(-8,Math.min(8,Math.floor(Ei(e)/3))),r=Math.pow(10,-i),s=Li[8+i/3];return function(t){return n(r*t)+s}}}}function Ui(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 ji(t,e){t instanceof Map?(t=[void 0,t],void 0===e&&(e=Vi)):void 0===e&&(e=Fi);for(var n,i,r,s,o,a=new Ri(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 Ri(r[s])),i.parent=n,i.depth=n.depth+1;return a.eachBefore(Hi)}function Fi(t){return t.children}function Vi(t){return Array.isArray(t)?t[1]:null}function Yi(t){void 0!==t.data.value&&(t.value=t.data.value),t.data=t.data.data}function Hi(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function Ri(t){this.data=t,this.depth=this.height=0,this.parent=null}function Bi(t,e){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(e).domain(t)}return this}function qi(t){return+t}$i=Oi({thousands:",",grouping:[3],currency:["$",""]}),Pi=$i.format,Di=$i.formatPrefix,Ri.prototype=ji.prototype={constructor:Ri,count:function(){return this.eachAfter(Ui)},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 ji(this).eachBefore(Yi)},[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 Xi=[0,1];function Zi(t){return t}function Wi(t,e){return(e-=t=+t)?function(n){return(n-t)/e}:function(t){return function(){return t}}(isNaN(e)?NaN:.5)}function Gi(t,e,n){var i=t[0],r=t[1],s=e[0],o=e[1];return r<i?(i=Wi(r,i),s=n(o,s)):(i=Wi(i,r),s=n(s,o)),function(t){return s(i(t))}}function Ji(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]=Wi(t[o],t[o+1]),s[o]=n(e[o],e[o+1]);return function(e){var n=u(t,e,1,i)-1;return s[n](r[n](e))}}function Ki(){var t,e,n,i,r,s,o=Xi,a=Xi,l=Ue,h=Zi;function u(){var t,e,n,l=Math.min(o.length,a.length);return h!==Zi&&(t=o[0],e=o[l-1],t>e&&(n=t,t=e,e=n),h=function(n){return Math.max(t,Math.min(e,n))}),i=l>2?Ji:Gi,r=s=null,c}function c(e){return null==e||isNaN(e=+e)?n:(r||(r=i(o.map(t),a,l)))(t(h(e)))}return c.invert=function(n){return h(e((s||(s=i(a,o.map(t),Pe)))(n)))},c.domain=function(t){return arguments.length?(o=Array.from(t,qi),u()):o.slice()},c.range=function(t){return arguments.length?(a=Array.from(t),u()):a.slice()},c.rangeRound=function(t){return a=Array.from(t),l=je,u()},c.clamp=function(t){return arguments.length?(h=!!t||Zi,u()):h!==Zi},c.interpolate=function(t){return arguments.length?(l=t,u()):l},c.unknown=function(t){return arguments.length?(n=t,c):n},function(n,i){return t=n,e=i,u()}}function Qi(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=Mi(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(Ei(e)/3)))-Ei(Math.abs(t)))}(s,o))||(i.precision=r),Di(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,Ei(e)-Ei(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,-Ei(Math.abs(t)))}(s))||(i.precision=r-2*("%"===i.type))}return Pi(i)}function tr(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?p(e,t,n):p(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 Qi(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],h=s[a],u=10;for(h<l&&(r=l,l=h,h=r,r=o,o=a,a=r);u-- >0;){if((r=g(l,h,n))===i)return s[o]=l,s[a]=h,e(s);if(r>0)l=Math.floor(l/r)*r,h=Math.ceil(h/r)*r;else{if(!(r<0))break;l=Math.ceil(l*r)/r,h=Math.floor(h*r)/r}i=r}return t},t}function er(){var t=Ki()(Zi,Zi);return t.copy=function(){return e=t,er().domain(e.domain()).range(e.range()).interpolate(e.interpolate()).clamp(e.clamp()).unknown(e.unknown());var e},Bi.apply(t,arguments),tr(t)}const nr=new Date,ir=new Date;function rr(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=>rr(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)=>(nr.setTime(+e),ir.setTime(+i),t(nr),t(ir),Math.floor(n(nr,ir))),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 sr=6e4,or=864e5,ar=6048e5,lr=rr(t=>t.setHours(0,0,0,0),(t,e)=>t.setDate(t.getDate()+e),(t,e)=>(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*sr)/or,t=>t.getDate()-1);lr.range;const hr=rr(t=>{t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+e)},(t,e)=>(e-t)/or,t=>t.getUTCDate()-1);hr.range;const ur=rr(t=>{t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+e)},(t,e)=>(e-t)/or,t=>Math.floor(t/or));function cr(t){return rr(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())*sr)/ar)}ur.range;const dr=cr(0),fr=cr(1),pr=cr(2),gr=cr(3),_r=cr(4),mr=cr(5),yr=cr(6);function vr(t){return rr(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)/ar)}dr.range,fr.range,pr.range,gr.range,_r.range,mr.range,yr.range;const br=vr(0),xr=vr(1),wr=vr(2),Nr=vr(3),Er=vr(4),Sr=vr(5),Tr=vr(6);br.range,xr.range,wr.range,Nr.range,Er.range,Sr.range,Tr.range;const Mr=rr(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());Mr.every=t=>isFinite(t=Math.floor(t))&&t>0?rr(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,Mr.range;const kr=rr(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 Ar(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 Cr(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 zr(t,e,n){return{y:t,m:e,d:n,H:0,M:0,S:0,L:0}}kr.every=t=>isFinite(t=Math.floor(t))&&t>0?rr(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,kr.range;var $r,Pr,Dr={"-":"",_:" ",0:"0"},Ir=/^\s*\d+/,Lr=/^%/,Or=/[\\^$*+?|[\]().{}]/g;function Ur(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 jr(t){return t.replace(Or,"\\$&")}function Fr(t){return new RegExp("^(?:"+t.map(jr).join("|")+")","i")}function Vr(t){return new Map(t.map((t,e)=>[t.toLowerCase(),e]))}function Yr(t,e,n){var i=Ir.exec(e.slice(n,n+1));return i?(t.w=+i[0],n+i[0].length):-1}function Hr(t,e,n){var i=Ir.exec(e.slice(n,n+1));return i?(t.u=+i[0],n+i[0].length):-1}function Rr(t,e,n){var i=Ir.exec(e.slice(n,n+2));return i?(t.U=+i[0],n+i[0].length):-1}function Br(t,e,n){var i=Ir.exec(e.slice(n,n+2));return i?(t.V=+i[0],n+i[0].length):-1}function qr(t,e,n){var i=Ir.exec(e.slice(n,n+2));return i?(t.W=+i[0],n+i[0].length):-1}function Xr(t,e,n){var i=Ir.exec(e.slice(n,n+4));return i?(t.y=+i[0],n+i[0].length):-1}function Zr(t,e,n){var i=Ir.exec(e.slice(n,n+2));return i?(t.y=+i[0]+(+i[0]>68?1900:2e3),n+i[0].length):-1}function Wr(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 Gr(t,e,n){var i=Ir.exec(e.slice(n,n+1));return i?(t.q=3*i[0]-3,n+i[0].length):-1}function Jr(t,e,n){var i=Ir.exec(e.slice(n,n+2));return i?(t.m=i[0]-1,n+i[0].length):-1}function Kr(t,e,n){var i=Ir.exec(e.slice(n,n+2));return i?(t.d=+i[0],n+i[0].length):-1}function Qr(t,e,n){var i=Ir.exec(e.slice(n,n+3));return i?(t.m=0,t.d=+i[0],n+i[0].length):-1}function ts(t,e,n){var i=Ir.exec(e.slice(n,n+2));return i?(t.H=+i[0],n+i[0].length):-1}function es(t,e,n){var i=Ir.exec(e.slice(n,n+2));return i?(t.M=+i[0],n+i[0].length):-1}function ns(t,e,n){var i=Ir.exec(e.slice(n,n+2));return i?(t.S=+i[0],n+i[0].length):-1}function is(t,e,n){var i=Ir.exec(e.slice(n,n+3));return i?(t.L=+i[0],n+i[0].length):-1}function rs(t,e,n){var i=Ir.exec(e.slice(n,n+6));return i?(t.L=Math.floor(i[0]/1e3),n+i[0].length):-1}function ss(t,e,n){var i=Lr.exec(e.slice(n,n+1));return i?n+i[0].length:-1}function os(t,e,n){var i=Ir.exec(e.slice(n));return i?(t.Q=+i[0],n+i[0].length):-1}function as(t,e,n){var i=Ir.exec(e.slice(n));return i?(t.s=+i[0],n+i[0].length):-1}function ls(t,e){return Ur(t.getDate(),e,2)}function hs(t,e){return Ur(t.getHours(),e,2)}function us(t,e){return Ur(t.getHours()%12||12,e,2)}function cs(t,e){return Ur(1+lr.count(Mr(t),t),e,3)}function ds(t,e){return Ur(t.getMilliseconds(),e,3)}function fs(t,e){return ds(t,e)+"000"}function ps(t,e){return Ur(t.getMonth()+1,e,2)}function gs(t,e){return Ur(t.getMinutes(),e,2)}function _s(t,e){return Ur(t.getSeconds(),e,2)}function ms(t){var e=t.getDay();return 0===e?7:e}function ys(t,e){return Ur(dr.count(Mr(t)-1,t),e,2)}function vs(t){var e=t.getDay();return e>=4||0===e?_r(t):_r.ceil(t)}function bs(t,e){return t=vs(t),Ur(_r.count(Mr(t),t)+(4===Mr(t).getDay()),e,2)}function xs(t){return t.getDay()}function ws(t,e){return Ur(fr.count(Mr(t)-1,t),e,2)}function Ns(t,e){return Ur(t.getFullYear()%100,e,2)}function Es(t,e){return Ur((t=vs(t)).getFullYear()%100,e,2)}function Ss(t,e){return Ur(t.getFullYear()%1e4,e,4)}function Ts(t,e){var n=t.getDay();return Ur((t=n>=4||0===n?_r(t):_r.ceil(t)).getFullYear()%1e4,e,4)}function Ms(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+Ur(e/60|0,"0",2)+Ur(e%60,"0",2)}function ks(t,e){return Ur(t.getUTCDate(),e,2)}function As(t,e){return Ur(t.getUTCHours(),e,2)}function Cs(t,e){return Ur(t.getUTCHours()%12||12,e,2)}function zs(t,e){return Ur(1+hr.count(kr(t),t),e,3)}function $s(t,e){return Ur(t.getUTCMilliseconds(),e,3)}function Ps(t,e){return $s(t,e)+"000"}function Ds(t,e){return Ur(t.getUTCMonth()+1,e,2)}function Is(t,e){return Ur(t.getUTCMinutes(),e,2)}function Ls(t,e){return Ur(t.getUTCSeconds(),e,2)}function Os(t){var e=t.getUTCDay();return 0===e?7:e}function Us(t,e){return Ur(br.count(kr(t)-1,t),e,2)}function js(t){var e=t.getUTCDay();return e>=4||0===e?Er(t):Er.ceil(t)}function Fs(t,e){return t=js(t),Ur(Er.count(kr(t),t)+(4===kr(t).getUTCDay()),e,2)}function Vs(t){return t.getUTCDay()}function Ys(t,e){return Ur(xr.count(kr(t)-1,t),e,2)}function Hs(t,e){return Ur(t.getUTCFullYear()%100,e,2)}function Rs(t,e){return Ur((t=js(t)).getUTCFullYear()%100,e,2)}function Bs(t,e){return Ur(t.getUTCFullYear()%1e4,e,4)}function qs(t,e){var n=t.getUTCDay();return Ur((t=n>=4||0===n?Er(t):Er.ceil(t)).getUTCFullYear()%1e4,e,4)}function Xs(){return"+0000"}function Zs(){return"%"}function Ws(t){return+t}function Gs(t){return Math.floor(+t/1e3)}function Js(t){return function(){return t}}function Ks(t){this._context=t}function Qs(t){return new Ks(t)}function to(t){return t[0]}function eo(t){return t[1]}function no(t,e){var n=Js(!0),i=null,r=Qs,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 wi(e)}(a);function a(a){var l,h,u,c=(a=function(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}(a)).length,d=!1;for(null==i&&(s=r(u=o())),l=0;l<=c;++l)!(l<c&&n(h=a[l],l,a))===d&&((d=!d)?s.lineStart():s.lineEnd()),d&&s.point(+t(h,l,a),+e(h,l,a));if(u)return s=null,u+""||null}return t="function"==typeof t?t:void 0===t?to:Js(t),e="function"==typeof e?e:void 0===e?eo:Js(e),a.x=function(e){return arguments.length?(t="function"==typeof e?e:Js(+e),a):t},a.y=function(t){return arguments.length?(e="function"==typeof t?t:Js(+t),a):e},a.defined=function(t){return arguments.length?(n="function"==typeof t?t:Js(!!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 io(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 ro(t){this._context=t}function so(t){return new ro(t)}function oo(t,e){this._context=t,this._t=e}!function(t){$r=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,h=Fr(r),u=Vr(r),c=Fr(s),d=Vr(s),f=Fr(o),p=Vr(o),g=Fr(a),_=Vr(a),m=Fr(l),y=Vr(l),v={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:ls,e:ls,f:fs,g:Es,G:Ts,H:hs,I:us,j:cs,L:ds,m:ps,M:gs,p:function(t){return r[+(t.getHours()>=12)]},q:function(t){return 1+~~(t.getMonth()/3)},Q:Ws,s:Gs,S:_s,u:ms,U:ys,V:bs,w:xs,W:ws,x:null,X:null,y:Ns,Y:Ss,Z:Ms,"%":Zs},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:ks,e:ks,f:Ps,g:Rs,G:qs,H:As,I:Cs,j:zs,L:$s,m:Ds,M:Is,p:function(t){return r[+(t.getUTCHours()>=12)]},q:function(t){return 1+~~(t.getUTCMonth()/3)},Q:Ws,s:Gs,S:Ls,u:Os,U:Us,V:Fs,w:Vs,W:Ys,x:null,X:null,y:Hs,Y:Bs,Z:Xs,"%":Zs},x={a:function(t,e,n){var i=f.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=c.exec(e.slice(n));return i?(t.w=d.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=y.get(i[0].toLowerCase()),n+i[0].length):-1},B:function(t,e,n){var i=g.exec(e.slice(n));return i?(t.m=_.get(i[0].toLowerCase()),n+i[0].length):-1},c:function(t,n,i){return E(t,e,n,i)},d:Kr,e:Kr,f:rs,g:Zr,G:Xr,H:ts,I:ts,j:Qr,L:is,m:Jr,M:es,p:function(t,e,n){var i=h.exec(e.slice(n));return i?(t.p=u.get(i[0].toLowerCase()),n+i[0].length):-1},q:Gr,Q:os,s:as,S:ns,u:Hr,U:Rr,V:Br,w:Yr,W:qr,x:function(t,e,i){return E(t,n,e,i)},X:function(t,e,n){return E(t,i,e,n)},y:Zr,Y:Xr,Z:Wr,"%":ss};function w(t,e){return function(n){var i,r,s,o=[],a=-1,l=0,h=t.length;for(n instanceof Date||(n=new Date(+n));++a<h;)37===t.charCodeAt(a)&&(o.push(t.slice(l,a)),null!=(r=Dr[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=zr(1900,void 0,1);if(E(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=Cr(zr(s.y,0,1))).getUTCDay(),i=r>4||0===r?xr.ceil(i):xr(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=Ar(zr(s.y,0,1))).getDay(),i=r>4||0===r?fr.ceil(i):fr(i),i=lr.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?Cr(zr(s.y,0,1)).getUTCDay():Ar(zr(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,Cr(s)):Ar(s)}}function E(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 Dr?e.charAt(o++):r])||(i=s(t,n,i))<0)return-1}else if(r!=n.charCodeAt(i++))return-1}return i}return v.x=w(n,v),v.X=w(i,v),v.c=w(e,v),b.x=w(n,b),b.X=w(i,b),b.c=w(e,b),{format:function(t){var e=w(t+="",v);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),$r.format,Pr=$r.parse,$r.utcFormat,$r.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"]}),Ks.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)}}},ro.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:io(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:io(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}},oo.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 ao=t=>()=>t;function lo(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 uo=new ho(1,0,0);function co(t){t.stopImmediatePropagation()}function fo(t){t.preventDefault(),t.stopImmediatePropagation()}function po(t){return!(t.ctrlKey&&"wheel"!==t.type||t.button)}function go(){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 _o(){return this.__zoom||uo}function mo(t){return-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function yo(){return navigator.maxTouchPoints||"ontouchstart"in this}function vo(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 bo=":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",xo=new RegExp("^"+("["+bo+"]["+(bo+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040")+"]*")+"$");function wo(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 No=function(t){const e=xo.exec(t);return!(null==e)};const Eo=["hasOwnProperty","toString","valueOf","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__"],So=["__proto__","constructor","prototype"],To={allowBooleanAttributes:!1,unpairedTags:[]};function Mo(t){return" "===t||"\t"===t||"\n"===t||"\r"===t}function ko(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 Lo("InvalidXml","XML declaration allowed only at the start of the document.",jo(t,e));if("?"==t[e]&&">"==t[e+1]){e++;break}continue}return e}function Ao(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 Po=new RegExp("(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['\"])(([\\s\\S])*?)\\5)?","g");function Do(t,e){const n=wo(t,Po),i={};for(let t=0;t<n.length;t++){if(0===n[t][1].length)return Lo("InvalidAttr","Attribute '"+n[t][2]+"' has no space in starting.",Fo(n[t]));if(void 0!==n[t][3]&&void 0===n[t][4])return Lo("InvalidAttr","Attribute '"+n[t][2]+"' is without value.",Fo(n[t]));if(void 0===n[t][3]&&!e.allowBooleanAttributes)return Lo("InvalidAttr","boolean attribute '"+n[t][2]+"' is not allowed.",Fo(n[t]));const r=n[t][2];if(!Oo(r))return Lo("InvalidAttr","Attribute '"+r+"' is an invalid name.",Fo(n[t]));if(Object.prototype.hasOwnProperty.call(i,r))return Lo("InvalidAttr","Attribute '"+r+"' is repeated.",Fo(n[t]));i[r]=1}return!0}function Io(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 Lo(t,e,n){return{err:{code:t,msg:e,line:n.line||n,col:n.col}}}function Oo(t){return No(t)}function Uo(t){return No(t)}function jo(t,e){const n=t.substring(0,e).split(/\r?\n/);return{line:n.length,col:n[n.length-1].length+1}}function Fo(t){return t.startIndex+t[1].length}const Vo=t=>Eo.includes(t)?"__"+t:t,Yo={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,maxNestedTags:100,strictReservedNames:!0,jPath:!0,onDangerousProperty:Vo};function Ho(t,e){if("string"!=typeof t)return;const n=t.toLowerCase();if(Eo.some(t=>n===t.toLowerCase()))throw new Error(`[SECURITY] Invalid ${e}: "${t}" is a reserved JavaScript keyword that could cause prototype pollution`);if(So.some(t=>n===t.toLowerCase()))throw new Error(`[SECURITY] Invalid ${e}: "${t}" is a reserved JavaScript keyword that could cause prototype pollution`)}function Ro(t){return"boolean"==typeof t?{enabled:t,maxEntitySize:1e4,maxExpansionDepth:10,maxTotalExpansions:1e3,maxExpandedLength:1e5,maxEntityCount:100,allowedTags:null,tagFilter:null}:"object"==typeof t&&null!==t?{enabled:!1!==t.enabled,maxEntitySize:t.maxEntitySize??1e4,maxExpansionDepth:t.maxExpansionDepth??10,maxTotalExpansions:t.maxTotalExpansions??1e3,maxExpandedLength:t.maxExpandedLength??1e5,maxEntityCount:t.maxEntityCount??100,allowedTags:t.allowedTags??null,tagFilter:t.tagFilter??null}:Ro(!0)}const Bo=function(t){const e=Object.assign({},Yo,t),n=[{value:e.attributeNamePrefix,name:"attributeNamePrefix"},{value:e.attributesGroupName,name:"attributesGroupName"},{value:e.textNodeName,name:"textNodeName"},{value:e.cdataPropName,name:"cdataPropName"},{value:e.commentPropName,name:"commentPropName"}];for(const{value:t,name:e}of n)t&&Ho(t,e);return null===e.onDangerousProperty&&(e.onDangerousProperty=Vo),e.processEntities=Ro(e.processEntities),e.stopNodes&&Array.isArray(e.stopNodes)&&(e.stopNodes=e.stopNodes.map(t=>"string"==typeof t&&t.startsWith("*.")?".."+t.substring(2):t)),e};let qo;qo="function"!=typeof Symbol?"@@xmlMetadata":Symbol("XML Node Metadata");class Xo{constructor(t){this.tagname=t,this.child=[],this[":@"]=Object.create(null)}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][qo]={startIndex:e})}static getMetaDataSymbol(){return qo}}class Zo{constructor(t){this.suppressValidationErr=!t,this.options=t}readDocType(t,e){const n=Object.create(null);let i=0;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,s=!1,o=!1,a="";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]?s=!0:a+=t[e];else{if(s&&Go(t,"!ENTITY",e)){let r,s;if(e+=7,[r,s,e]=this.readEntityExp(t,e+1,this.suppressValidationErr),-1===s.indexOf("&")){if(!1!==this.options.enabled&&this.options.maxEntityCount&&i>=this.options.maxEntityCount)throw new Error(`Entity count (${i+1}) exceeds maximum allowed (${this.options.maxEntityCount})`);const t=r.replace(/[.\-+*:]/g,"\\.");n[r]={regx:RegExp(`&${t};`,"g"),val:s},i++}}else if(s&&Go(t,"!ELEMENT",e)){e+=8;const{index:n}=this.readElementExp(t,e+1);e=n}else if(s&&Go(t,"!ATTLIST",e))e+=8;else if(s&&Go(t,"!NOTATION",e)){e+=9;const{index:n}=this.readNotationExp(t,e+1,this.suppressValidationErr);e=n}else{if(!Go(t,"!--",e))throw new Error("Invalid DOCTYPE");o=!0}r++,a=""}if(0!==r)throw new Error("Unclosed DOCTYPE")}return{entities:n,i:e}}readEntityExp(t,e){e=Wo(t,e);let n="";for(;e<t.length&&!/\s/.test(t[e])&&'"'!==t[e]&&"'"!==t[e];)n+=t[e],e++;if(Jo(n),e=Wo(t,e),!this.suppressValidationErr){if("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="";if([e,i]=this.readIdentifierVal(t,e,"entity"),!1!==this.options.enabled&&this.options.maxEntitySize&&i.length>this.options.maxEntitySize)throw new Error(`Entity "${n}" size (${i.length}) exceeds maximum allowed size (${this.options.maxEntitySize})`);return[n,i,--e]}readNotationExp(t,e){e=Wo(t,e);let n="";for(;e<t.length&&!/\s/.test(t[e]);)n+=t[e],e++;!this.suppressValidationErr&&Jo(n),e=Wo(t,e);const i=t.substring(e,e+6).toUpperCase();if(!this.suppressValidationErr&&"SYSTEM"!==i&&"PUBLIC"!==i)throw new Error(`Expected SYSTEM or PUBLIC, found "${i}"`);e+=i.length,e=Wo(t,e);let r=null,s=null;if("PUBLIC"===i)[e,r]=this.readIdentifierVal(t,e,"publicIdentifier"),'"'!==t[e=Wo(t,e)]&&"'"!==t[e]||([e,s]=this.readIdentifierVal(t,e,"systemIdentifier"));else if("SYSTEM"===i&&([e,s]=this.readIdentifierVal(t,e,"systemIdentifier"),!this.suppressValidationErr&&!s))throw new Error("Missing mandatory system identifier for SYSTEM notation");return{notationName:n,publicIdentifier:r,systemIdentifier:s,index:--e}}readIdentifierVal(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]}readElementExp(t,e){e=Wo(t,e);let n="";for(;e<t.length&&!/\s/.test(t[e]);)n+=t[e],e++;if(!this.suppressValidationErr&&!No(n))throw new Error(`Invalid element name: "${n}"`);let i="";if("E"===t[e=Wo(t,e)]&&Go(t,"MPTY",e))e+=4;else if("A"===t[e]&&Go(t,"NY",e))e+=2;else if("("===t[e]){for(e++;e<t.length&&")"!==t[e];)i+=t[e],e++;if(")"!==t[e])throw new Error("Unterminated content model")}else if(!this.suppressValidationErr)throw new Error(`Invalid Element Expression, found "${t[e]}"`);return{elementName:n,contentModel:i.trim(),index:e}}readAttlistExp(t,e){e=Wo(t,e);let n="";for(;e<t.length&&!/\s/.test(t[e]);)n+=t[e],e++;Jo(n),e=Wo(t,e);let i="";for(;e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;if(!Jo(i))throw new Error(`Invalid attribute name: "${i}"`);e=Wo(t,e);let r="";if("NOTATION"===t.substring(e,e+8).toUpperCase()){if(r="NOTATION","("!==t[e=Wo(t,e+=8)])throw new Error(`Expected '(', found "${t[e]}"`);e++;let n=[];for(;e<t.length&&")"!==t[e];){let i="";for(;e<t.length&&"|"!==t[e]&&")"!==t[e];)i+=t[e],e++;if(i=i.trim(),!Jo(i))throw new Error(`Invalid notation name: "${i}"`);n.push(i),"|"===t[e]&&(e++,e=Wo(t,e))}if(")"!==t[e])throw new Error("Unterminated list of notations");e++,r+=" ("+n.join("|")+")"}else{for(;e<t.length&&!/\s/.test(t[e]);)r+=t[e],e++;const n=["CDATA","ID","IDREF","IDREFS","ENTITY","ENTITIES","NMTOKEN","NMTOKENS"];if(!this.suppressValidationErr&&!n.includes(r.toUpperCase()))throw new Error(`Invalid attribute type: "${r}"`)}e=Wo(t,e);let s="";return"#REQUIRED"===t.substring(e,e+8).toUpperCase()?(s="#REQUIRED",e+=8):"#IMPLIED"===t.substring(e,e+7).toUpperCase()?(s="#IMPLIED",e+=7):[e,s]=this.readIdentifierVal(t,e,"ATTLIST"),{elementName:n,attributeName:i,attributeType:r,defaultValue:s,index:e}}}const Wo=(t,e)=>{for(;e<t.length&&/\s/.test(t[e]);)e++;return 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 Jo(t){if(No(t))return t;throw new Error(`Invalid entity name ${t}`)}const Ko=/^[-+]?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&&Ko.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(n.includes("e")||n.includes("E"))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,e={}){this.pattern=t,this.separator=e.separator||".",this.segments=this._parse(t),this._hasDeepWildcard=this.segments.some(t=>"deep-wildcard"===t.type),this._hasAttributeCondition=this.segments.some(t=>void 0!==t.attrName),this._hasPositionSelector=this.segments.some(t=>void 0!==t.position)}_parse(t){const e=[];let n=0,i="";for(;n<t.length;)t[n]===this.separator?n+1<t.length&&t[n+1]===this.separator?(i.trim()&&(e.push(this._parseSegment(i.trim())),i=""),e.push({type:"deep-wildcard"}),n+=2):(i.trim()&&e.push(this._parseSegment(i.trim())),i="",n++):(i+=t[n],n++);return i.trim()&&e.push(this._parseSegment(i.trim())),e}_parseSegment(t){const e={type:"tag"};let n=null,i=t;const r=t.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);if(r&&(i=r[1]+r[3],r[2])){const t=r[2].slice(1,-1);t&&(n=t)}let s,o,a=i;if(i.includes("::")){const e=i.indexOf("::");if(s=i.substring(0,e).trim(),a=i.substring(e+2).trim(),!s)throw new Error(`Invalid namespace in pattern: ${t}`)}let l=null;if(a.includes(":")){const t=a.lastIndexOf(":"),e=a.substring(0,t).trim(),n=a.substring(t+1).trim();["first","last","odd","even"].includes(n)||/^nth\(\d+\)$/.test(n)?(o=e,l=n):o=a}else o=a;if(!o)throw new Error(`Invalid segment pattern: ${t}`);if(e.tag=o,s&&(e.namespace=s),n)if(n.includes("=")){const t=n.indexOf("=");e.attrName=n.substring(0,t).trim(),e.attrValue=n.substring(t+1).trim()}else e.attrName=n.trim();if(l){const t=l.match(/^nth\((\d+)\)$/);t?(e.position="nth",e.positionValue=parseInt(t[1],10)):e.position=l}return e}get length(){return this.segments.length}hasDeepWildcard(){return this._hasDeepWildcard}hasAttributeCondition(){return this._hasAttributeCondition}hasPositionSelector(){return this._hasPositionSelector}toString(){return this.pattern}}class ra{constructor(t={}){this.separator=t.separator||".",this.path=[],this.siblingStacks=[]}push(t,e=null,n=null){if(this.path.length>0){this.path[this.path.length-1].values=void 0}const i=this.path.length;this.siblingStacks[i]||(this.siblingStacks[i]=new Map);const r=this.siblingStacks[i],s=n?`${n}:${t}`:t,o=r.get(s)||0;let a=0;for(const t of r.values())a+=t;r.set(s,o+1);const l={tag:t,position:a,counter:o};null!=n&&(l.namespace=n),null!=e&&(l.values=e),this.path.push(l)}pop(){if(0===this.path.length)return;const t=this.path.pop();return this.siblingStacks.length>this.path.length+1&&(this.siblingStacks.length=this.path.length+1),t}updateCurrent(t){if(this.path.length>0){const e=this.path[this.path.length-1];null!=t&&(e.values=t)}}getCurrentTag(){return this.path.length>0?this.path[this.path.length-1].tag:void 0}getCurrentNamespace(){return this.path.length>0?this.path[this.path.length-1].namespace:void 0}getAttrValue(t){if(0===this.path.length)return;const e=this.path[this.path.length-1];return e.values?.[t]}hasAttr(t){if(0===this.path.length)return!1;const e=this.path[this.path.length-1];return void 0!==e.values&&t in e.values}getPosition(){return 0===this.path.length?-1:this.path[this.path.length-1].position??0}getCounter(){return 0===this.path.length?-1:this.path[this.path.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this.path.length}toString(t,e=!0){const n=t||this.separator;return this.path.map(t=>e&&t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(n)}toArray(){return this.path.map(t=>t.tag)}reset(){this.path=[],this.siblingStacks=[]}matches(t){const e=t.segments;return 0!==e.length&&(t.hasDeepWildcard()?this._matchWithDeepWildcard(e):this._matchSimple(e))}_matchSimple(t){if(this.path.length!==t.length)return!1;for(let e=0;e<t.length;e++){const n=t[e],i=this.path[e],r=e===this.path.length-1;if(!this._matchSegment(n,i,r))return!1}return!0}_matchWithDeepWildcard(t){let e=this.path.length-1,n=t.length-1;for(;n>=0&&e>=0;){const i=t[n];if("deep-wildcard"===i.type){if(n--,n<0)return!0;const i=t[n];let r=!1;for(let t=e;t>=0;t--){const s=t===this.path.length-1;if(this._matchSegment(i,this.path[t],s)){e=t-1,n--,r=!0;break}}if(!r)return!1}else{const t=e===this.path.length-1;if(!this._matchSegment(i,this.path[e],t))return!1;e--,n--}}return n<0}_matchSegment(t,e,n){if("*"!==t.tag&&t.tag!==e.tag)return!1;if(void 0!==t.namespace&&"*"!==t.namespace&&t.namespace!==e.namespace)return!1;if(void 0!==t.attrName){if(!n)return!1;if(!e.values||!(t.attrName in e.values))return!1;if(void 0!==t.attrValue){const n=e.values[t.attrName];if(String(n)!==String(t.attrValue))return!1}}if(void 0!==t.position){if(!n)return!1;const i=e.counter??0;if("first"===t.position&&0!==i)return!1;if("odd"===t.position&&i%2!=1)return!1;if("even"===t.position&&i%2!=0)return!1;if("nth"===t.position&&i!==t.positionValue)return!1}return!0}snapshot(){return{path:this.path.map(t=>({...t})),siblingStacks:this.siblingStacks.map(t=>new Map(t))}}restore(t){this.path=t.path.map(t=>({...t})),this.siblingStacks=t.siblingStacks.map(t=>new Map(t))}}function sa(t,e){if(!t)return{};const n=e.attributesGroupName?t[e.attributesGroupName]:t;if(!n)return{};const i={};for(const t in n)if(t.startsWith(e.attributeNamePrefix)){i[t.substring(e.attributeNamePrefix.length)]=n[t]}else i[t]=n[t];return i}function oa(t){if(!t||"string"!=typeof t)return;const e=t.indexOf(":");if(-1!==e&&e>0){const n=t.substring(0,e);if("xmlns"!==n)return n}}class aa{constructor(t){var e;if(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)=>wa(e,10,"&#")},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:(t,e)=>wa(e,16,"&#x")}},this.addExternalEntities=la,this.parseXml=fa,this.parseTextData=ha,this.resolveNameSpace=ua,this.buildAttributesMap=da,this.isItStopNode=ma,this.replaceEntitiesValue=ga,this.readStopNodeData=ba,this.saveTextToParentTag=_a,this.addChild=pa,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,this.entityExpansionCount=0,this.currentExpandedLength=0,this.matcher=new ra,this.isCurrentNodeStopNode=!1,this.options.stopNodes&&this.options.stopNodes.length>0){this.stopNodeExpressions=[];for(let t=0;t<this.options.stopNodes.length;t++){const e=this.options.stopNodes[t];"string"==typeof e?this.stopNodeExpressions.push(new ia(e)):e instanceof ia&&this.stopNodeExpressions.push(e)}}}}function la(t){const e=Object.keys(t);for(let n=0;n<e.length;n++){const i=e[n],r=i.replace(/[.\-+*:]/g,"\\.");this.lastEntities[i]={regex:new RegExp("&"+r+";","g"),val:t[i]}}}function ha(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,e,n));const i=this.options.jPath?n.toString():n,a=this.options.tagValueProcessor(e,t,i,r,s);if(null==a)return t;if(typeof a!=typeof t||a!==t)return a;if(this.options.trimValues)return xa(t,this.options.parseTagValue,this.options.numberParseOptions);return t.trim()===t?xa(t,this.options.parseTagValue,this.options.numberParseOptions):t}}function ua(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 ca=new RegExp("([^\\s=]+)\\s*(=\\s*(['\"])([\\s\\S]*?)\\3)?","gm");function da(t,e,n){if(!0!==this.options.ignoreAttributes&&"string"==typeof t){const i=wo(t,ca),r=i.length,s={},o={};for(let t=0;t<r;t++){const r=this.resolveNameSpace(i[t][1]),s=i[t][4];if(r.length&&void 0!==s){let t=s;this.options.trimValues&&(t=t.trim()),t=this.replaceEntitiesValue(t,n,e),o[r]=t}}Object.keys(o).length>0&&"object"==typeof e&&e.updateCurrent&&e.updateCurrent(o);for(let t=0;t<r;t++){const r=this.resolveNameSpace(i[t][1]),o=this.options.jPath?e.toString():e;if(this.ignoreAttributesFn(r,o))continue;let a=i[t][4],l=this.options.attributeNamePrefix+r;if(r.length)if(this.options.transformAttributeName&&(l=this.options.transformAttributeName(l)),l=Ea(l,this.options),void 0!==a){this.options.trimValues&&(a=a.trim()),a=this.replaceEntitiesValue(a,n,e);const t=this.options.jPath?e.toString():e,i=this.options.attributeValueProcessor(r,a,t);s[l]=null==i?a:typeof i!=typeof a||i!==a?i:xa(a,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(s[l]=!0)}if(!Object.keys(s).length)return;if(this.options.attributesGroupName){const t={};return t[this.options.attributesGroupName]=s,t}return s}}const fa=function(t){t=t.replace(/\r\n?/g,"\n");const e=new Xo("!xml");let n=e,i="";this.matcher.reset(),this.entityExpansionCount=0,this.currentExpandedLength=0;const r=new Zo(this.options.processEntities);for(let s=0;s<t.length;s++){if("<"===t[s])if("/"===t[s+1]){const e=ya(t,">",s,"Closing Tag is not closed.");let r=t.substring(s+2,e).trim();if(this.options.removeNSPrefix){const t=r.indexOf(":");-1!==t&&(r=r.substr(t+1))}r=Na(this.options.transformTagName,r,"",this.options).tagName,n&&(i=this.saveTextToParentTag(i,n,this.matcher));const o=this.matcher.getCurrentTag();if(r&&-1!==this.options.unpairedTags.indexOf(r))throw new Error(`Unpaired tag can not be used as closing tag: </${r}>`);o&&-1!==this.options.unpairedTags.indexOf(o)&&(this.matcher.pop(),this.tagsNodeStack.pop()),this.matcher.pop(),this.isCurrentNodeStopNode=!1,n=this.tagsNodeStack.pop(),i="",s=e}else if("?"===t[s+1]){let e=va(t,s,!1,"?>");if(!e)throw new Error("Pi Tag is not closed.");if(i=this.saveTextToParentTag(i,n,this.matcher),this.options.ignoreDeclaration&&"?xml"===e.tagName||this.options.ignorePiTags);else{const t=new Xo(e.tagName);t.add(this.options.textNodeName,""),e.tagName!==e.tagExp&&e.attrExpPresent&&(t[":@"]=this.buildAttributesMap(e.tagExp,this.matcher,e.tagName)),this.addChild(n,t,this.matcher,s)}s=e.closeIndex+1}else if("!--"===t.substr(s+1,3)){const e=ya(t,"--\x3e",s+4,"Comment is not closed.");if(this.options.commentPropName){const r=t.substring(s+4,e-2);i=this.saveTextToParentTag(i,n,this.matcher),n.add(this.options.commentPropName,[{[this.options.textNodeName]:r}])}s=e}else if("!D"===t.substr(s+1,2)){const e=r.readDocType(t,s);this.docTypeEntities=e.entities,s=e.i}else if("!["===t.substr(s+1,2)){const e=ya(t,"]]>",s,"CDATA is not closed.")-2,r=t.substring(s+9,e);i=this.saveTextToParentTag(i,n,this.matcher);let o=this.parseTextData(r,n.tagname,this.matcher,!0,!1,!0,!0);null==o&&(o=""),this.options.cdataPropName?n.add(this.options.cdataPropName,[{[this.options.textNodeName]:r}]):n.add(this.options.textNodeName,o),s=e+2}else{let r=va(t,s,this.options.removeNSPrefix);if(!r){const e=t.substring(Math.max(0,s-50),Math.min(t.length,s+50));throw new Error(`readTagExp returned undefined at position ${s}. Context: "${e}"`)}let o=r.tagName;const a=r.rawTagName;let l=r.tagExp,h=r.attrExpPresent,u=r.closeIndex;if(({tagName:o,tagExp:l}=Na(this.options.transformTagName,o,l,this.options)),this.options.strictReservedNames&&(o===this.options.commentPropName||o===this.options.cdataPropName))throw new Error(`Invalid tag name: ${o}`);n&&i&&"!xml"!==n.tagname&&(i=this.saveTextToParentTag(i,n,this.matcher,!1));const c=n;c&&-1!==this.options.unpairedTags.indexOf(c.tagname)&&(n=this.tagsNodeStack.pop(),this.matcher.pop());let d=!1;l.length>0&&l.lastIndexOf("/")===l.length-1&&(d=!0,"/"===o[o.length-1]?(o=o.substr(0,o.length-1),l=o):l=l.substr(0,l.length-1),h=o!==l);let f,p=null;f=oa(a),o!==e.tagname&&this.matcher.push(o,{},f),o!==l&&h&&(p=this.buildAttributesMap(l,this.matcher,o),p&&sa(p,this.options)),o!==e.tagname&&(this.isCurrentNodeStopNode=this.isItStopNode(this.stopNodeExpressions,this.matcher));const g=s;if(this.isCurrentNodeStopNode){let e="";if(d)s=r.closeIndex;else if(-1!==this.options.unpairedTags.indexOf(o))s=r.closeIndex;else{const n=this.readStopNodeData(t,a,u+1);if(!n)throw new Error(`Unexpected end of ${a}`);s=n.i,e=n.tagContent}const i=new Xo(o);p&&(i[":@"]=p),i.add(this.options.textNodeName,e),this.matcher.pop(),this.isCurrentNodeStopNode=!1,this.addChild(n,i,this.matcher,g)}else{if(d){({tagName:o,tagExp:l}=Na(this.options.transformTagName,o,l,this.options));const t=new Xo(o);p&&(t[":@"]=p),this.addChild(n,t,this.matcher,g),this.matcher.pop(),this.isCurrentNodeStopNode=!1}else{if(-1!==this.options.unpairedTags.indexOf(o)){const t=new Xo(o);p&&(t[":@"]=p),this.addChild(n,t,this.matcher,g),this.matcher.pop(),this.isCurrentNodeStopNode=!1,s=r.closeIndex;continue}{const t=new Xo(o);if(this.tagsNodeStack.length>this.options.maxNestedTags)throw new Error("Maximum nested tags exceeded");this.tagsNodeStack.push(n),p&&(t[":@"]=p),this.addChild(n,t,this.matcher,g),n=t}}i="",s=u}}else i+=t[s]}return e.child};function pa(t,e,n,i){this.options.captureMetaData||(i=void 0);const r=this.options.jPath?n.toString():n,s=this.options.updateTag(e.tagname,r,e[":@"]);!1===s||("string"==typeof s?(e.tagname=s,t.addChild(e,i)):t.addChild(e,i))}function ga(t,e,n){const i=this.options.processEntities;if(!i||!i.enabled)return t;if(i.allowedTags){const r=this.options.jPath?n.toString():n;if(!(Array.isArray(i.allowedTags)?i.allowedTags.includes(e):i.allowedTags(e,r)))return t}if(i.tagFilter){const r=this.options.jPath?n.toString():n;if(!i.tagFilter(e,r))return t}for(let e in this.docTypeEntities){const n=this.docTypeEntities[e],r=t.match(n.regx);if(r){if(this.entityExpansionCount+=r.length,i.maxTotalExpansions&&this.entityExpansionCount>i.maxTotalExpansions)throw new Error(`Entity expansion limit exceeded: ${this.entityExpansionCount} > ${i.maxTotalExpansions}`);const e=t.length;if(t=t.replace(n.regx,n.val),i.maxExpandedLength&&(this.currentExpandedLength+=t.length-e,this.currentExpandedLength>i.maxExpandedLength))throw new Error(`Total expanded content size exceeded: ${this.currentExpandedLength} > ${i.maxExpandedLength}`)}}if(-1===t.indexOf("&"))return t;for(let e in this.lastEntities){const n=this.lastEntities[e];t=t.replace(n.regex,n.val)}if(-1===t.indexOf("&"))return t;if(this.options.htmlEntities)for(let e in this.htmlEntities){const n=this.htmlEntities[e];t=t.replace(n.regex,n.val)}return t=t.replace(this.ampEntity.regex,this.ampEntity.val)}function _a(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 ma(t,e){if(!t||0===t.length)return!1;for(let n=0;n<t.length;n++)if(e.matches(t[n]))return!0;return!1}function ya(t,e,n,i){const r=t.indexOf(e,n);if(-1===r)throw new Error(i);return r+e.length-1}function va(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,h=!0;-1!==a&&(l=s.substring(0,a),s=s.substring(a+1).trimStart());const u=l;if(n){const t=l.indexOf(":");-1!==t&&(l=l.substr(t+1),h=l!==r.data.substr(t+1))}return{tagName:l,tagExp:s,closeIndex:o,attrExpPresent:h,rawTagName:u}}function ba(t,e,n){const i=n;let r=1;for(;n<t.length;n++)if("<"===t[n])if("/"===t[n+1]){const s=ya(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=ya(t,"?>",n+1,"StopNode is not closed.")}else if("!--"===t.substr(n+1,3)){n=ya(t,"--\x3e",n+3,"StopNode is not closed.")}else if("!["===t.substr(n+1,2)){n=ya(t,"]]>",n,"StopNode is not closed.")-2}else{const i=va(t,n,">");if(i){(i&&i.tagName)===e&&"/"!==i.tagExp[i.tagExp.length-1]&&r++,n=i.closeIndex}}}function xa(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:""}function wa(t,e,n){const i=Number.parseInt(t,e);return i>=0&&i<=1114111?String.fromCodePoint(i):n+t+";"}function Na(t,e,n,i){if(t){const i=t(e);n===e&&(n=i),e=i}return{tagName:e=Ea(e,i),tagExp:n}}function Ea(t,e){if(So.includes(t))throw new Error(`[SECURITY] Invalid name: "${t}" is a reserved JavaScript keyword that could cause prototype pollution`);return Eo.includes(t)?e.onDangerousProperty(t):t}const Sa=Xo.getMetaDataSymbol();function Ta(t,e){if(!t||"object"!=typeof t)return{};if(!e)return t;const n={};for(const i in t)if(i.startsWith(e)){n[i.substring(e.length)]=t[i]}else n[i]=t[i];return n}function Ma(t,e,n){return ka(t,e,n)}function ka(t,e,n){let i;const r={};for(let s=0;s<t.length;s++){const o=t[s],a=Aa(o);if(void 0!==a&&a!==e.textNodeName){const t=Ta(o[":@"]||{},e.attributeNamePrefix);n.push(a,t)}if(a===e.textNodeName)void 0===i?i=o[a]:i+=""+o[a];else{if(void 0===a)continue;if(o[a]){let t=ka(o[a],e,n);const i=za(t,e);if(o[":@"]?Ca(t,o[":@"],n,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!==o[Sa]&&"object"==typeof t&&null!==t&&(t[Sa]=o[Sa]),void 0!==r[a]&&Object.prototype.hasOwnProperty.call(r,a))Array.isArray(r[a])||(r[a]=[r[a]]),r[a].push(t);else{const s=e.jPath?n.toString():n;e.isArray(a,s,i)?r[a]=[t]:r[a]=t}void 0!==a&&a!==e.textNodeName&&n.pop()}}}return"string"==typeof i?i.length>0&&(r[e.textNodeName]=i):void 0!==i&&(r[e.textNodeName]=i),r}function Aa(t){const e=Object.keys(t);for(let t=0;t<e.length;t++){const n=e[t];if(":@"!==n)return n}}function Ca(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],a=s.startsWith(i.attributeNamePrefix)?s.substring(i.attributeNamePrefix.length):s,l=i.jPath?n.toString()+"."+a:n;i.isArray(s,l,!0,!0)?t[s]=[e[s]]:t[s]=e[s]}}}function za(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 $a{constructor(t){this.externalEntities={},this.options=Bo(t)}parse(t,e){if("string"!=typeof t&&t.toString)t=t.toString();else if("string"!=typeof t)throw new Error("XML data is accepted in String or Bytes[] form.");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=ko(t,s),s.err)return s}else{if("<"!==t[s]){if(Mo(t[s]))continue;return Lo("InvalidChar","char '"+t[s]+"' is not expected.",jo(t,s))}{let o=s;if(s++,"!"===t[s]){s=Ao(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.",Lo("InvalidTag",e,jo(t,s))}const h=$o(t,s);if(!1===h)return Lo("InvalidAttr","Attributes for '"+l+"' have open quote.",jo(t,s));let u=h.value;if(s=h.index,"/"===u[u.length-1]){const n=s-u.length;u=u.substring(0,u.length-1);const r=Do(u,e);if(!0!==r)return Lo(r.err.code,r.err.msg,jo(t,n+r.err.line));i=!0}else if(a){if(!h.tagClosed)return Lo("InvalidTag","Closing tag '"+l+"' doesn't have proper closing.",jo(t,s));if(u.trim().length>0)return Lo("InvalidTag","Closing tag '"+l+"' can't have attributes or invalid starting.",jo(t,o));if(0===n.length)return Lo("InvalidTag","Closing tag '"+l+"' has not been opened.",jo(t,o));{const e=n.pop();if(l!==e.tagName){let n=jo(t,e.tagStartPos);return Lo("InvalidTag","Expected closing tag '"+e.tagName+"' (opened in line "+n.line+", col "+n.col+") instead of closing tag '"+l+"'.",jo(t,o))}0==n.length&&(r=!0)}}else{const a=Do(u,e);if(!0!==a)return Lo(a.err.code,a.err.msg,jo(t,s-u.length+a.err.line));if(!0===r)return Lo("InvalidXml","Multiple possible root nodes found.",jo(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=Ao(t,s);continue}if("?"!==t[s+1])break;if(s=ko(t,++s),s.err)return s}else if("&"===t[s]){const e=Io(t,s);if(-1==e)return Lo("InvalidChar","char '&' is not expected.",jo(t,s));s=e}else if(!0===r&&!Mo(t[s]))return Lo("InvalidXml","Extra text at the end",jo(t,s));"<"===t[s]&&s--}}}return i?1==n.length?Lo("InvalidTag","Unclosed tag '"+n[0].tagName+"'.",jo(t,n[0].tagStartPos)):!(n.length>0)||Lo("InvalidXml","Invalid '"+JSON.stringify(n.map(t=>t.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1}):Lo("InvalidXml","Start tag expected.",1)}(t,e);if(!0!==n)throw Error(`${n.err.msg}:${n.err.line}:${n.err.col}`)}const n=new aa(this.options);n.addExternalEntities(this.externalEntities);const i=n.parseXml(t);return this.options.preserveOrder||void 0===i?i:Ma(i,this.options,n.matcher)}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 Xo.getMetaDataSymbol()}}function Pa(t){return!r.has(t,"children")}function Da(t,e,n){let i=[];return function r(s){Pa(s)?e&&s!=t&&i.push(s):(n&&s!=t&&i.push(s),s.children.forEach(r))}(t),i}var Ia=Object.freeze({__proto__:null,addChild:function(t,e){return t.children?t.children.push(e):t.children=[e],t},assignAttributes:function(t){r.each(this.nodes.descendants(),function(e){e.data&&e.data.name in t&&(e.annotations=t[e.data.name])})},clearInternalNodes:function(t){t||this.nodes.each(t=>{Pa(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])})},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},getInternals:function(){return r.filter(this.nodes.descendants(),t=>r.has(t,"children"))},getNodeByName:function(t){return r.filter(this.nodes.descendants(),e=>e.data.name==t)[0]},getNodes:function(){return this.nodes},getRootNode:function(){return this.nodes},getTips:function(){return r.filter(this.nodes.descendants(),t=>!r.has(t,"children"))},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},isLeafNode:Pa,selectAllDescendants:Da,updateKeyName:function(t,e){return this.nodes.each(function(n){t in n&&(e&&(n[e]=n[t]),delete n[t])}),this}});function La(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=u,"children"in t?t.bootstrap_values=u:t.name=u,t.attribute=c,"["==i&&d.includes("&&NHX")?d.split(":").slice(1).forEach(e=>{const[i,r]=e.split("=");t[i]=n.test(r)?+r:r}):t.annotation=d,u="",c="",d=""}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 h=0,u="",c="",d="",f=null,p={"'":1,'"':1},g={name:"root"};s.push(g);for(var _=/\s/,m=0;m<t.length;m++)try{var y=t[m];switch(h){case 0:"("==y&&(o(),h=1);break;case 1:case 3:if(":"==y)h=3;else if(","==y||")"==y)try{a(),h=1,","==y&&o()}catch(t){return l(m)}else if("("==y){if(u.length>0)return l(m);o()}else{if(y in p){if(1==h&&0===u.length&&0===c.length&&0===d.length){h=2,f=y;continue}return l(m)}if(y==i){if(d.length)return l(m);h=4}else if(3==h)c+=y;else{if(_.test(y))continue;if(";"==y){m=t.length;break}u+=y}}break;case 2:if(y==f){if(m<t.length-1&&t[m+1]==f){m++,u+=f;continue}f=0,h=1;continue}u+=y;break;case 4:if(y==r)h=3;else{if(y==i)return l(m);d+=y}}}catch(t){return l(m)}return 1!=s.length?l(t.length-1):{json:g,error:null}}function Oa(t,e){let n=this;t||(t=t=>"");let i=[];return t=t||"",function e(r){if(r.notshown)return;if(Pa(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 Ua(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 ja(t,e,n){r.each(t.getTips(),t=>{t.data.test=n.matrix[t.data.name]})}function Fa(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")),La(s[0])}var Va=Object.freeze({__proto__:null,default:Fa,loadAnnotations:ja,parseAnnotations:Ua});function Ya(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]=Ya(s);else{if(void 0===e[o].push){var a=e[o];e[o]=[],e[o].push(a)}e[o].push(Ya(s))}}return e}var Ha=function(t,e){var n;if("string"==typeof t)if(DOMParser){t=(new DOMParser).parseFromString(t,"text/xml")}else{t=(new $a).parse(t)}var i=(t=Ya(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 Ra={nexml:function(t,e){return new $a({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:Ha,nexus:Fa,nwk:La,nhx:La,beast:function(t,e){e.left_delimiter="[",e.right_delimiter="]";const n=La(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 Ba(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 qa(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 Xa(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 Za(t){return Ba(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 Wa(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 Ga=Object.freeze({__proto__:null,pathToRoot:function(t){let e=[];for(;t;)e.push(t),t=t.parent;return e},reroot:function(t,e){if(!(t instanceof ji))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=ji({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(),h=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-h,t.data.__mapped_bl=h,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 ji({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;Ft(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(),Ft(n.container).node().appendChild(n.show()),Ft(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]}});function Ja(t){return t.y}function Ka(t){return t.x}function Qa(t,e,n){return{x:n+t*Math.sin(e),y:n+t*Math.cos(e)}}function tl(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=Qa(t.radius,t.angle,i);return t.x=o.x,t.y=o.y,t}function el(t,e){var n=Qa(e[0].radius,e[0].angle,t),i=Qa(e[0].radius,e[1].angle,t);return"M "+Ja(n)+","+Ka(n)+" A "+e[0].radius+","+e[0].radius+" 0,0, "+(e[1].angle>e[0].angle?1:0)+" "+Ja(i)+","+Ka(i)+" L "+Ja(e[1])+","+Ka(e[1])}function nl(t,e,n){var i=Qa(t.target.radius+(t.source.radius-t.target.radius)*e,t.target.angle,n);return{x:Ja(i),y:Ka(i)}}var il=no().x(function(t){return Ja(t)}).y(function(t){return Ka(t)}).curve(function(t){return new oo(t,0)});function rl(t,e){return{x:Ja(t.target)+(Ja(t.source)-Ja(t.target))*e,y:Ka(t.target)}}function sl(t){return t.children&&0!==t.children.length?t.children.reduce((t,e)=>t+sl(e),0):1}function ol(t,e,n,i,r){r=r||0,t._unrooted_x=0,t._unrooted_y=0,al(t,0,2*Math.PI);let s=1/0,o=-1/0,a=1/0,l=-1/0;t.each(t=>{t._unrooted_x<s&&(s=t._unrooted_x),t._unrooted_x>o&&(o=t._unrooted_x),t._unrooted_y<a&&(a=t._unrooted_y),t._unrooted_y>l&&(l=t._unrooted_y)});let h=n-2*r,u=i-2*r;h<100&&(h=100),u<100&&(u=100);let c=h/(o-s||1),d=u/(l-a||1),f=Math.min(c,d),p=r+h/2-(s+o)/2*f,g=r+u/2-(a+l)/2*f;t.each(t=>{if(t.y=t._unrooted_x*f+p,t.x=t._unrooted_y*f+g,t.parent){let e=t._unrooted_x-t.parent._unrooted_x,n=t._unrooted_y-t.parent._unrooted_y,i=180*Math.atan2(n,e)/Math.PI,r=i>90||i<-90;t.text_angle=r?i+180:i,t.text_align=r?"end":"start"}else t.text_angle=0,t.text_align="start";t.angle=t.parent?Math.atan2(t._unrooted_y-t.parent._unrooted_y,t._unrooted_x-t.parent._unrooted_x):0,t.radius=null})}function al(t,e,n){let i=sl(t);if(!t.children||0===t.children.length)return;let r=e;t.children.forEach(e=>{let s=sl(e),o=n*(s/i),a=r+o/2,l=void 0!==e.y?e.y-(t.y||0):1;l<=0&&(l=1),e._unrooted_x=t._unrooted_x+l*Math.cos(a),e._unrooted_y=t._unrooted_y+l*Math.sin(a),al(e,r,o),r+=o})}function ll(t){return"M "+Ja(t[0])+","+Ka(t[0])+" L "+Ja(t[1])+","+Ka(t[1])}function hl(t,e){return{x:Ja(t.target)+(Ja(t.source)-Ja(t.target))*e,y:Ka(t.target)+(Ka(t.source)-Ka(t.target))*e}}function ul(t){return t.tag||!1}function cl(t,e){return t[e]||!1}const dl={"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 fl(t={}){Object.keys(t).forEach(e=>{dl[e]=t[e]})}function pl(t){return arguments.length?(pl="string"==typeof t&&"equal"==t?function(t){return 1}:t,this):pl}var gl={all:t=>!0,none:t=>!1,"all-leaf-nodes":t=>Pa(t.target),"all-internal-nodes":t=>!Pa(t.target)};var _l=Object.freeze({__proto__:null,alignTips:function(t){return arguments.length?(this.options["align-tips"]=t,this):this.options["align-tips"]},css_classes:dl,initializeCssClasses:fl,internalNames:function(t){return arguments.length?(this.options["internal-names"]=t,this):this.options["internal-names"]},layoutHandler:function(t){return arguments.length?(this.layout_listener_handler=t,this):this.layout_listener_handler},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},get nodeSpan(){return pl},predefined_selecters:gl,radial:function(t){return arguments.length?(this.options["is-radial"]=t,this):this.options["is-radial"]},selectionCallback:function(t){return t?(this._selectionCallback=t,this):this._selectionCallback},selectionLabel:function(t){return arguments.length?(this.selection_attribute_name=t,this.syncEdgeLabels(),this):this.selection_attribute_name},unrooted:function(t){return arguments.length?(this.options["is-unrooted"]=t,this):this.options["is-unrooted"]}});function ml(t){return!(t.hidden||t.notshown)}function yl(t){return t.notshown}function vl(t){return t.hasHiddenNodes||!1}function bl(t){return t.collapsed||!1}function xl(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 wl(t){return Pa(t=t.data)?t.name||"":this.showInternalName(t)?t.name:""}var Nl=Object.freeze({__proto__:null,defNodeLabel:wl,drawNode:function(t,e,n){t=Ft(t);var i=Pa(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)&&!bl(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)),this.unrooted())r=r.attr("transform",t=>this.d3PhylotreeSvgRotate(t.text_angle)).attr("text-anchor",t=>t.text_align);else if(this.radial())r=r.attr("transform",t=>this.d3PhylotreeSvgRotate(t.text_angle)+this.d3PhylotreeSvgTranslate(this.alignTips()?this.shiftTip(t):null)).attr("text-anchor",t=>t.text_align);else{const t="right-to-left"==this.options.layout;r=r.attr("text-anchor",t?"end":"start").attr("transform",t=>this.d3PhylotreeSvgTranslate(this.alignTips()?this.shiftTip(t):null))}if(this.alignTips()){s=s.data([e]);const t="right-to-left"==this.options.layout,i=e=>this.radial()?"end"==e.text_align?-1:1:t?-1:1;n?s=s.enter().append("line").classed(this.css_classes["branch-tracer"],!0).merge(s).attr("x1",t=>i(t)*this.nodeBubbleSize(e)).attr("x2",0).attr("y1",0).attr("y2",0).attr("x2",t=>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=>i(t)*this.nodeBubbleSize(e)).attr("y2",0).attr("y1",0).attr("x2",t=>this.shiftTip(t)[0])).attr("transform",t=>this.d3PhylotreeSvgRotate(t.text_angle))}else s.remove();if(this.options["draw-size-bubbles"]){var o=this.nodeBubbleSize(e);if(t.selectAll("circle").data([o]).enter().append("circle").attr("r",function(t){return t}),this.shown_font_size>=5){const t="right-to-left"==this.options.layout;r=r.attr("dx",e=>(this.radial()||this.unrooted()?"end"==e.text_align?-1:1:t?-1:1)*((this.alignTips()?0:o)+.33*this.shown_font_size))}}else if(this.shown_font_size>=5){const t="right-to-left"==this.options.layout;r=r.attr("dx",e=>(this.radial()||this.unrooted()?"end"==e.text_align?-1:1:t?-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},hasHiddenNodes:vl,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];Pa(i)||cl(i,this.selection_attribute_name)||(i[this.selection_attribute_name]=t(i.children))}this.modifySelection((t,e)=>(Pa(t.target),t.target[this.selection_attribute_name]))},isNodeCollapsed:bl,nodeCssSelectors:xl,nodeLabel:function(t){return arguments.length?(this._nodeLabel=t||wl,this.update(),this):this._nodeLabel},nodeNotshown:yl,nodeSpan:function(t){return arguments.length?(this.nodeSpan="string"==typeof t&&"equal"==t?function(t){return 1}:t,this):this.nodeSpan},nodeVisible:ml,reclassNode:function(t){let e=dl[Pa(t)?"node":"internal-node"];return ul(t)&&(e+=" "+dl["tagged-node"]),cl(t,this.selection_attribute_name)&&(e+=" "+dl["selected-node"]),t.parent||(e+=" "+dl["root-node"]),(bl(t)||vl(t))&&(e+=" "+dl["collapsed-node"]),e},shiftTip:function(t){return this.unrooted()?[0,0]:this.radial()?[("end"==t.text_align?-1:1)*(this.radius_pad_for_bubbles-t.radius),0]:"right-to-left"==this.options.layout?[-t.screen_x,0]:[this.right_most_leaf-t.screen_x,0]},showInternalName:function(t){const e=this.internalNames();return!!e&&("function"==typeof e?e(t):e)},updateHasHiddenNodes:function(){let t=this.phylotree.nodes.descendants();for(let e=t.length-1;e>=0;e-=1)Pa(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}});function El(t){return[t.clade].reduce(function(t,e,n,i){return t+"path."+e+(n<i.length-1?",":"")},"")}var Sl=Object.freeze({__proto__:null,cladeCssSelectors:El,updateCollapsedClades:function(t){let e=this.svg.selectAll("."+this.css_classes["tree-container"]);var n=0;let i=e.selectAll(El(this.css_classes)).data(this.phylotree.nodes.descendants().filter(bl),function(t){return t.id||(t.id=++n)}),s=function(){},o=r.noop();this.radial()?(s=no().curve(so).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=no().y(function(t){return t[0]}).x(function(t){return t[1]}).curve(so),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 Tl(t){return!(t.target.hidden||t.target.notshown)}function Ml(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 kl=Object.freeze({__proto__:null,drawEdge:function(t,e,n){t=(t=Ft(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},edgeCssSelectors:Ml,edgeVisible:Tl,initializeEdgeLabels:function(){this.links.forEach(t=>{t.target.data.annotation&&(t.target[t.target.data.annotation]=t.target.data.annotation)})},placeAlongAnEdge:function(t,e){return this.edge_placer(t,e)},reclassEdge:function(t){let e=dl.branch;if(ul(t)&&(e+=" "+dl["tagged-branch"]),cl(t,this.selection_attribute_name)&&(e+=" "+dl["selected-branch"]),t.target&&t.target._selectionSet){e+=" phylotree-set-branch-"+t.target._selectionSet.replace(/[^a-zA-Z0-9-_]/g,"_")}return e},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+(ul(e)?1:0)},0),this.countUpdate(this,t,this.countHandler())}}});let Al="phylotree.event";function Cl(t){var e=new CustomEvent(Al,{detail:["refresh",t]});document.dispatchEvent(e)}function zl(t,e){var n=new CustomEvent(Al,{detail:["countUpdate",e,t.countHandler()]});document.dispatchEvent(n)}function $l(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 Pl(){document.addEventListener(Al,$l,!1)}var Dl=Object.freeze({__proto__:null,countUpdate:zl,d3PhylotreeAddEventListener:Pl,d3PhylotreeEventListener:$l,d3PhylotreeSvgRotate:function(t){return null!==t?"rotate ("+t+") ":""},d3PhylotreeSvgTranslate:function(t){return!t||null===t[0]&&null===t[1]?"":"translate ("+(null!==t[0]?t[0]:0)+","+(null!==t[1]?t[1]:0)+") "},d3PhylotreeTriggerLayout:function(t){var e=new CustomEvent(Al,{detail:["layout",t,t.layoutHandler()]});document.dispatchEvent(e)},rescale:function(t,e){(e=e||"y_scaled")in this&&(this[e]*=t)},resizeSvg:function(t,e,n){let i=this.size;if(this.unrooted()){if(this.baseTransform={x:0,y:0},e){let t;if(this.currentZoomTransform&&this.options.zoom){const e=this.currentZoomTransform;t=`translate(${e.x}, ${e.y}) scale(${e.k})`}else t="translate(0,0)";e.selectAll("."+dl["tree-container"]).attr("transform",t)}}else if(this.radial()){let t=this.pad_width(),n="fit-to-size"!=this.options["top-bottom-spacing"]?this.pad_height():0;if(i=[i[1]+2*t,i[0]+2*t+n],this.baseTransform={x:t,y:t+n},e){let i;if(this.currentZoomTransform&&this.options.zoom){const t=this.currentZoomTransform;i=`translate(${t.x+this.baseTransform.x*t.k}, ${t.y+this.baseTransform.y*t.k}) scale(${t.k})`}else i="translate("+t+","+(t+n)+")";e.selectAll("."+dl["tree-container"]).attr("transform",i)}}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},toggleCollapse:function(t){if(t.collapsed){t.collapsed=!1;let e=function(t){Pa(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},triggerRefresh:Cl});let Il="d3_layout_phylotree_context_menu";function Ll(t,e,n){let i=[];return function r(s){Pa(s)?e&&s!=t&&i.push(s):(n&&s!=t&&i.push(s),s.children.forEach(r))}(t),i}var Ol=Object.freeze({__proto__:null,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])},clearSelection:function(){const t=this.phylotree.nodes.descendants();return this.modifySelection(t,this.selection_attribute_name,!1,!1,"false"),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},getSelection:function(){return Ll(this.phylotree.getRootNode(),!0,!0).filter(t=>t[this.selection_attribute_name])},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(gl),t))return;t=gl[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||Cl(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||Cl(this),this.countHandler&&((o={})[e]=this.links.reduce(function(t,n){return t+(n[e]?1:0)},0),zl(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},nodeDropdownMenu:function(t,e,n,i,s){let o=Ft(e).select("#"+Il);if(o.empty()&&(o=Ft(e).append("div").attr("id",Il).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;Pa(t)||(i.collapsible&&(o.append("a").attr("class","phylotree-menu-item dropdown-item").attr("tabindex","-1").text(bl(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",e=>{o.style("display","none");const i=n.selectAllDescendants(t,!0,!0);"multi-set"===this.options["selection-mode"]&&this._activeSetName?(i.forEach(t=>this.addToSet(t,this._activeSetName)),this.update()):this.modifySelection(i)}),o.append("a").attr("class","phylotree-menu-item dropdown-item").attr("tabindex","-1").text("All terminal branches").on("click",e=>{o.style("display","none");const i=n.selectAllDescendants(t,!0,!1);"multi-set"===this.options["selection-mode"]&&this._activeSetName?(i.forEach(t=>this.addToSet(t,this._activeSetName)),this.update()):this.modifySelection(i)}),o.append("a").attr("class","phylotree-menu-item dropdown-item").attr("tabindex","-1").text("All internal branches").on("click",e=>{o.style("display","none");const i=n.selectAllDescendants(t,!1,!0);"multi-set"===this.options["selection-mode"]&&this._activeSetName?(i.forEach(t=>this.addToSet(t,this._activeSetName)),this.update()):this.modifySelection(i)}))),t.parent&&(i.selectable&&(o.append("a").attr("class","phylotree-menu-item dropdown-item").attr("tabindex","-1").text("Incident branch").on("click",e=>{o.style("display","none"),"multi-set"===this.options["selection-mode"]&&this._activeSetName?(this.addToSet(t,this._activeSetName),this.update()):this.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");const n=this.phylotree.pathToRoot(t);"multi-set"===this.options["selection-mode"]&&this._activeSetName?(n.forEach(t=>this.addToSet(t,this._activeSetName)),this.update()):this.modifySelection(n)}),(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 "+(Pa(t)?"node":"subtree")).on("click",e=>{o.style("display","none"),this.modifySelection([t],"notshown",!0,!0).updateHasHiddenNodes().update()})),vl(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")},selectAllDescendants:Ll,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},selectionCallback:function(t){return t?(this._selectionCallback=t,this):this._selectionCallback}});var Ul=Object.freeze({__proto__:null,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},off:function(t,e){return this._eventListeners&&this._eventListeners[t]&&(this._eventListeners[t]=this._eventListeners[t].filter(t=>t!==e)),this},on:function(t,e){return this._eventListeners||(this._eventListeners={}),this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(e),this}});var jl=Object.freeze({__proto__:null,_getSetsSummary:function(){const t={};return this._selectionSets&&Object.keys(this._selectionSets).forEach(e=>{t[e]=Array.from(this._selectionSets[e].members)}),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},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},getActiveSet:function(){return this._activeSetName},getNodeSet:function(t){return t._selectionSet||null},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))},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)},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)},isInSet:function(t,e){return!(!this._selectionSets||!this._selectionSets[e])&&this._selectionSets[e].members.has(t.data.name)},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},setActiveSet:function(t){return this._selectionSets&&this._selectionSets[t]?this._activeSetName=t:console.warn(`Selection set '${t}' not found`),this}});function Fl(t){return function(){return t}}class Vl{constructor(t,e={}){fl(e["css-classes"]),this.css_classes=dl,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=il,this.draw_scale_bar=null,this.edge_placer=rl,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,"is-unrooted":!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:Fl(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.currentZoomTransform=null,this.baseTransform={x:0,y:0},this.nodeSpan=this.options["node-span"],this.nodeSpan||(this.nodeSpan=function(t){return 1}),this.rescale_nodeSpan=this.phylotree.nodes.children.map(t=>{if(Pa(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(),Pl(),"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){bl(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&&(Ft(t).select("svg").remove(),this.svg=Ft(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")),Ft(this.container).on("click",t=>{this.handle_node_click(null)},!0)),this}update_layout(t,e){e&&(this.nodes=ji(t),this.nodes.each(function(t){t.id=null})),this.update(),this.syncEdgeLabels()}update(t){var e=this;this.placenodes(),this.syncEdgeLabels(),t=this.transitions(t);let n=0,i=this.svg.selectAll("."+dl["tree-container"]).data([0]);if(this.baseTransform={x:this.offsets[1]+this.options["left-offset"],y:this.pad_height()},i=i.enter().append("g").attr("class",dl["tree-container"]).merge(i).attr("transform",t=>{if(this.currentZoomTransform&&this.options.zoom){const t=this.currentZoomTransform;return`translate(${t.x+this.baseTransform.x*t.k}, ${t.y+this.baseTransform.y*t.k}) scale(${t.k})`}return this.d3PhylotreeSvgTranslate([this.baseTransform.x,this.baseTransform.y])}),this.draw_scale_bar){let t=this.svg.selectAll("."+dl["tree-scale-bar"]).data([0]);t.enter().append("g").attr("class",dl["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("."+dl["tree-scale-bar"]).remove();i=this.svg.selectAll("."+dl["tree-container"]).data([0]),this.updateCollapsedClades(t);let s=i.selectAll(Ml(dl)).data(this.links.filter(Tl),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(xl(dl)).data(this.phylotree.nodes.descendants().filter(ml),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&&Pa(t);return t.screen_x=Ja(t),t.screen_y=Ka(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("."+dl["tree-selection-brush"]).data([0]).enter().insert("g",":first-child").attr("class",dl["tree-selection-brush"]),l=_i().on("brush",(t,e)=>{var n=t.selection,i=this.links.filter(Tl).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)}return this.options.zoom&&(this.zoomBehavior||(this.zoomBehavior=function(){var t,e,n,i=po,r=go,s=vo,o=mo,a=yo,l=[0,1/0],h=[[-1/0,-1/0],[1/0,1/0]],u=250,c=Ge,d=E("start","zoom","end"),f=0,p=10;function g(t){t.property("__zoom",_o).on("wheel.zoom",w,{passive:!1}).on("mousedown.zoom",N).on("dblclick.zoom",S).filter(a).on("touchstart.zoom",T).on("touchmove.zoom",M).on("touchend.zoom touchcancel.zoom",k).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function _(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 y(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function v(t,e,n,i){t.on("start.zoom",function(){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?y(a):"function"==typeof n?n.apply(t,s):n,h=Math.max(a[1][0]-a[0][0],a[1][1]-a[0][1]),u=t.__zoom,d="function"==typeof e?e.apply(t,s):e,f=c(u.invert(l).concat(h/u.k),d.invert(l).concat(h/d.k));return function(t){if(1===t)t=d;else{var e=f(t),n=h/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)))),u=Vt(t);if(n.wheel)n.mouse[0][0]===u[0]&&n.mouse[0][1]===u[1]||(n.mouse[1]=r.invert(n.mouse[0]=u)),clearTimeout(n.wheel);else{if(r.k===a)return;n.mouse=[u,r.invert(u)],bn(this),n.start()}fo(t),n.wheel=setTimeout(function(){n.wheel=null,n.end()},150),n.zoom("mouse",s(m(_(r,a),n.mouse[0],n.mouse[1]),n.extent,h))}}function N(t,...e){if(!n&&i.apply(this,arguments)){var r=t.currentTarget,o=b(this,e,!0).event(t),a=Ft(t.view).on("mousemove.zoom",function(t){if(fo(t),!o.moved){var e=t.clientX-u,n=t.clientY-c;o.moved=e*e+n*n>f}o.event(t).zoom("mouse",s(m(o.that.__zoom,o.mouse[0]=Vt(t,r),o.mouse[1]),o.extent,h))},!0).on("mouseup.zoom",function(t){a.on("mousemove.zoom mouseup.zoom",null),Bt(t.view,o.moved),fo(t),o.event(t).end()},!0),l=Vt(t,r),u=t.clientX,c=t.clientY;Rt(t.view),co(t),o.mouse=[l,this.__zoom.invert(l)],bn(this),o.start()}}function S(t,...e){if(i.apply(this,arguments)){var n=this.__zoom,o=Vt(t.changedTouches?t.changedTouches[0]:t,this),a=n.invert(o),l=n.k*(t.shiftKey?.5:2),c=s(m(_(n,l),o,a),r.apply(this,e),h);fo(t),u>0?Ft(this).transition().duration(u).call(v,c,o,t):Ft(this).call(g.transform,c,o,t)}}function T(n,...r){if(i.apply(this,arguments)){var s,o,a,l,h=n.touches,u=h.length,c=b(this,r,n.changedTouches.length===u).event(n);for(co(n),o=0;o<u;++o)l=[l=Vt(a=h[o],this),this.__zoom.invert(l),a.identifier],c.touch0?c.touch1||c.touch0[2]===l[2]||(c.touch1=l,c.taps=0):(c.touch0=l,s=!0,c.taps=1+!!t);t&&(t=clearTimeout(t)),s&&(c.taps<2&&(e=l[0],t=setTimeout(function(){t=null},500)),bn(this),c.start())}}function M(t,...e){if(this.__zooming){var n,i,r,o,a=b(this,e).event(t),l=t.changedTouches,u=l.length;for(fo(t),n=0;n<u;++n)r=Vt(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 c=a.touch0[0],d=a.touch0[1],f=a.touch1[0],p=a.touch1[1],g=(g=f[0]-c[0])*g+(g=f[1]-c[1])*g,y=(y=p[0]-d[0])*y+(y=p[1]-d[1])*y;i=_(i,Math.sqrt(g/y)),r=[(c[0]+f[0])/2,(c[1]+f[1])/2],o=[(d[0]+p[0])/2,(d[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,h))}}function k(t,...i){if(this.__zooming){var r,s,o=b(this,i).event(t),a=t.changedTouches,l=a.length;for(co(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=Vt(s,this),Math.hypot(e[0]-s[0],e[1]-s[1])<p)){var h=Ft(this).on("dblclick.zoom");h&&h.apply(this,arguments)}}}return g.transform=function(t,e,n,i){var r=t.selection?t.selection():t;r.property("__zoom",_o),t!==r?v(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()})},g.scaleBy=function(t,e,n,i){g.scaleTo(t,function(){return this.__zoom.k*("function"==typeof e?e.apply(this,arguments):e)},n,i)},g.scaleTo=function(t,e,n,i){g.transform(t,function(){var t=r.apply(this,arguments),i=this.__zoom,o=null==n?y(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(_(i,l),o,a),t,h)},n,i)},g.translateBy=function(t,e,n,i){g.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),h)},null,i)},g.translateTo=function(t,e,n,i,o){g.transform(t,function(){var t=r.apply(this,arguments),o=this.__zoom,a=null==i?y(t):"function"==typeof i?i.apply(this,arguments):i;return s(uo.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,h)},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=Ft(this.that).datum();d.call(t,this.that,new lo(t,{sourceEvent:this.sourceEvent,target:g,transform:this.that.__zoom,dispatch:d}),e)}},g.wheelDelta=function(t){return arguments.length?(o="function"==typeof t?t:ao(+t),g):o},g.filter=function(t){return arguments.length?(i="function"==typeof t?t:ao(!!t),g):i},g.touchable=function(t){return arguments.length?(a="function"==typeof t?t:ao(!!t),g):a},g.extent=function(t){return arguments.length?(r="function"==typeof t?t:ao([[+t[0][0],+t[0][1]],[+t[1][0],+t[1][1]]]),g):r},g.scaleExtent=function(t){return arguments.length?(l[0]=+t[0],l[1]=+t[1],g):[l[0],l[1]]},g.translateExtent=function(t){return arguments.length?(h[0][0]=+t[0][0],h[1][0]=+t[1][0],h[0][1]=+t[0][1],h[1][1]=+t[1][1],g):[[h[0][0],h[0][1]],[h[1][0],h[1][1]]]},g.constrain=function(t){return arguments.length?(s=t,g):s},g.duration=function(t){return arguments.length?(u=+t,g):u},g.interpolate=function(t){return arguments.length?(c=t,g):c},g.on=function(){var t=d.on.apply(d,arguments);return t===d?g:t},g.clickDistance=function(t){return arguments.length?(f=(t=+t)*t,g):Math.sqrt(f)},g.tapDistance=function(t){return arguments.length?(p=+t,g):p},g}().scaleExtent([.1,10]).on("zoom",t=>{this.currentZoomTransform=t.transform;const e=t.transform,n=`translate(${e.x+this.baseTransform.x*e.k}, ${e.y+this.baseTransform.y*e.k}) scale(${e.k})`;this.svg.select("."+dl["tree-container"]).attr("transform",n),this.svg.select("."+dl["tree-scale-bar"]).attr("transform",t=>`translate(${e.x+this.baseTransform.x*e.k}, ${e.y+(this.baseTransform.y-10)*e.k}) scale(${e.k})`)})),this.svg.call(this.zoomBehavior),this.currentZoomTransform&&this.svg.call(this.zoomBehavior.transform,this.currentZoomTransform)),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(yl(t))return;let e=Pa(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(bl(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,Pa(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.unrooted()){let t=40,e=(this.fixed_width[0]-14+(this.fixed_width[1]-30))*t,n=this.width+e,i=this.height+e;n<100&&(n=100),i<100&&(i=100),this.shown_font_size=this.font_size,this.label_width=this._label_width(this.shown_font_size);let r=this.label_width+this.shown_font_size;ol(this.phylotree.nodes,this.scales,n,i,r),this.size=[i,n],this.draw_branch=ll,this.edge_placer=hl,this.draw_scale_bar=null}else if(this.radial()){this.draw_branch=r.partial(el,this.radial_center),this.edge_placer=nl;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 h=0;this.phylotree.nodes.each(t=>{if(!t.children){let r=t.x*this.scales[0];if(null!==e){let o=r-n,u=a(t.radius,i,t.angle,e,h),c=u>0?o/u:10*this.options["max-radius"];if(c>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)),u=Math.sqrt(r*r-4*a);h=Math.min(this.options["annular-limit"]*l,(-r+u)/2),s=this.options["max-radius"]}else s=Math.max(s,c)}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*h)),this.radial_center=this.radius_pad_for_bubbles=this.radius,this.draw_branch=r.partial(el,this.radial_center);let u=1;h&&(u=l/(l+h),this.radius*=u),this.phylotree.nodes.each(t=>{if(tl(t,this.radius,h,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=tl(e,this.radius,h,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/u,this.size[1]=this.radial_center+this.radius/u}else this.do_lr(),this.draw_branch=il,this.edge_placer=rl,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+this.label_width),Pa(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=er().domain([0,t]).range([0,e]),i=Pi(".2f");if(this.draw_scale_bar=function(t){return w(0,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 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))))}}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(ml).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=Fl(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 dl)n in t&&t[n]!=dl[n]&&(dl[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 dl)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(Ml(this.css_classes)).attr("class",this.reclassEdge.bind(this));this.edge_styler&&t.each(t=>{this.edge_styler(Ft(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(Vl.prototype,Sl),r.extend(Vl.prototype,Nl),r.extend(Vl.prototype,kl),r.extend(Vl.prototype,Dl),r.extend(Vl.prototype,Ol),r.extend(Vl.prototype,_l),r.extend(Vl.prototype,Ul),r.extend(Vl.prototype,jl);let Yl=class{constructor(t,e={}){this.newick_string="",this.nodes=[],this.links=[],this.parsed_tags=[],this.partitions=[],this.branch_length_accessor=Wa,this.branch_length=Wa,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 Ra?i=Ra[n](t,e):s.logger.error("type "+n+" not in registry! Available types are "+r.keys(Ra));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=Ha(t):(this.newick_string=t,i=La(t,e));if(i.json){s.nodes=ji(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){qa(e,t,i)}:"in-order"==e?function(e){Xa(e,t,i)}:function(e){r.isUndefined(e)||Ba(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 Vl(this,t),this.display}};function Hl(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 Rl(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?Rl(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&&Rl(t,e.parent,e,i,r)}function Bl(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 h=(i-n*(o/=a))/e,u=0;return t.forEach(function(t){var e=t[1]-h-o*t[0];u+=t[2]*e*e}),{intercept:h,slope:o,r2:1-u/l,"var (intercept)":Math.sqrt((1+n*n/(e*a))/e),"var (slope)":Math.sqrt(1/a)}}function ql(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}Yl.prototype.isLeafNode=Pa,Yl.prototype.selectAllDescendants=Da,Yl.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},Yl.prototype.hasBranchLengths=function(){let t=this.branch_length;return!!t&&r.every(this.nodes.descendants(),function(e){return!e.parent||!r.isUndefined(t(e))})},Yl.prototype.getBranchLengths=function(){let t=this.branch_length;return r.map(this.nodes.descendants(),e=>t(e))},Yl.prototype.branchName=function(t){return arguments.length?(this.nodeLabel=t,this):this.nodeLabel},Yl.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},Yl.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},Yl.prototype.getNewick=Oa,Yl.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}}`:"")},Yl.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},Yl.prototype.setBranchLength=function(t){return arguments.length?(this.branch_length_accessor=t||Wa,this):this.branch_length_accessor},Yl.prototype.maxParsimony=function(t,e){const n=r.partial(function(t,e){if(e.mp=[[0,0],[!1,!1]],Pa(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)=>Pa(t.target)?t.target[e]:t.target.mp)},Yl.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},Yl.prototype.leftChildRightSibling=Za,r.extend(Yl.prototype,Ia),r.extend(Yl.prototype,Ga),r.extend(Yl.prototype,Va);const Xl=Pr("%Y%m%d"),Zl=/([0-9]{4}).?([0-9]{2}).?([0-9]{2})$/g,Wl=function(t){if(Pa(t)&&"name"in t){let e=Zl.exec(t.name);if(e)return e[1]+e[2]+e[3]}return null},Gl=function(t,e,n=Xl){return e=e||Wl,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};function Jl(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=Hl(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,h=0,u=0;r.each(t.cot_path_to_leaves_below,function(t){e+=t,a+=t*t,u++}),r.each(t.cot_path_to_leaves_above,function(t){l+=t,h+=t*t});var c=n-u,d=(l-e+t.cot_computed_length*c)/n;d<0?d=0:d>t.cot_computed_length&&(d=t.cot_computed_length);var f=h+a+2*(l*(t.cot_computed_length-d)+e*d)+u*d*d+(t.cot_computed_length-d)*(t.cot_computed_length-d)*c;f<i&&(o=t,s=d/t.cot_computed_length,i=f),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.extractDates=Gl,t.extract_dates=Gl,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),ql(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=Bl(e);return t.traverse_and_compute(function(o){if(t.isLeafNode(o)&&!r.isNull(o.data.decimal_date_value)){Rl(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=Bl(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=Oa,t.inOrder=Xa,t.leftChildRightSibling=Za,t.loadAnnotations=ja,t.neighborJoining=function t(e,n,i){if(n<=2){let t=new Yl(""),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),[h,u]=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),c=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[h][u]+c[h][u])/2,f=(e[h][u]-c[h][u])/2,p=s.concat(0,s.filter(s.map(s.range(n),t=>{if(t!=h&&t!=u)return.5*(e[t][h]+e[t][u]-e[h][u])}),s.isNumber)),g=i[h],_=i[u],m="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]));m="InternalNode"+ ++t}i.unshift(m),e=Jl(s.max([h,u]),e),(e=Jl(s.min([h,u]),e)).unshift(p),s.each(s.range(1,n-1),t=>e[t].unshift(p[t])),s.remove(i,t=>t==g||t==_);let v=t(e,o-1,i),b=v.createNode(g,[null,[d]]),x=v.createNode(_,[null,[f]]);if(v.getNodeByName(m)){let t=v.getNodeByName(m);v.addChild(t,b),v.addChild(t,x)}else{let t=v.createNode(m,[null,[0]]);v.addChild(v.getNodes(),t),v.addChild(t,b),v.addChild(t,x)}return v}var r},t.newickParser=La,t.pairwiseDistances=Hl,t.pairwise_distances=Hl,t.parseAnnotations=Ua,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=Hl(t),a=t.getRootNode().children[0],l=Number.MAX_VALUE,h=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<h&&(h=l),l=e.cot_computed_length):e.cot_computed_length<h&&(h=e.cot_computed_length))}),l+=h;var u=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,u/100));var c=1+(u/s|0);c>500&&(s=u/(c=500));var d=t.getRootNode();d.paths_to_leaves=new Array(o),r.each(d.children,function(t){r.each(d.cot_path_to_leaves_below,function(e,n){d.paths_to_leaves[n]=e+t.cot_computed_length})}),t.traverse_and_compute(function(e){if(!t.isLeafNode(e)){e.histogram=new Array(c);for(var n=0;n<c;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 f=(o-1)*o/2*n,p=0;p<c-1&&f>d.histogram[p];p++)f-=d.histogram[p];var g=l+(p+(d.histogram[p]-f)/d.histogram[p])*s,_=[];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,h=0;h<c-1&&a>n.histogram[h];h++)a-=n.histogram[h];var u=l+(h+(n.histogram[h]-a)/n.histogram[h])*s;if(u<=g)return _.push({root:n,median:u,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(_,function(e){e.members=[],t.traverse_and_compute(function(n){t.isLeafNode(n)&&e.members.push(n)},"post-order",e.root)}),_},t.phylotree=Yl,t.postOrder=Ba,t.preOrder=qa,t.rootToTip=ql,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)}});
|
|
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){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:h,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 h(){return 0}const u=l(o).right;l(function(t){return null===t?NaN:+t}).center;const c=Math.sqrt(50),d=Math.sqrt(10),f=Math.sqrt(2);function p(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>=c?10:s>=d?5:s>=f?2:1;let a,l,h;return r<0?(h=Math.pow(10,-r)/o,a=Math.round(t*h),l=Math.round(e*h),a/h<t&&++a,l/h>e&&--l,h=-h):(h=Math.pow(10,r)*o,a=Math.round(t/h),l=Math.round(e/h),a*h<t&&++a,l*h>e&&--l),l<a&&.5<=n&&n<2?p(t,e,2*n):[a,l,h]}function _(t,e,n){return p(t=+t,e=+e,n=+n)[2]}function g(t){return t}var m=1e-6;function y(t){return"translate("+t+",0)"}function v(t){return e=>+t(e)}function b(t,e){return e=Math.max(0,t.bandwidth()-2*e)/2,t.round()&&(e=Math.round(e)),n=>+t(n)+e}function x(){return!this.__axis}function w(t,e){var n=[],i=null,r=null,s=6,o=6,a=3,l="undefined"!=typeof window&&window.devicePixelRatio>1?0:.5,h=-1,u="y",c=y;function d(t){var d=null==i?e.ticks?e.ticks.apply(e,n):e.domain():i,f=null==r?e.tickFormat?e.tickFormat.apply(e,n):g:r,p=Math.max(s,0)+a,_=e.range(),y=+_[0]+l,w=+_[_.length-1]+l,N=(e.bandwidth?b:v)(e.copy(),l),S=t.selection?t.selection():t,E=S.selectAll(".domain").data([null]),M=S.selectAll(".tick").data(d,e).order(),T=M.exit(),A=M.enter().append("g").attr("class","tick"),k=M.select("line"),C=M.select("text");E=E.merge(E.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),M=M.merge(A),k=k.merge(A.append("line").attr("stroke","currentColor").attr("y2",h*s)),C=C.merge(A.append("text").attr("fill","currentColor").attr(u,h*p).attr("dy","0em")),t!==S&&(E=E.transition(t),M=M.transition(t),k=k.transition(t),C=C.transition(t),T=T.transition(t).attr("opacity",m).attr("transform",function(t){return isFinite(t=N(t))?c(t+l):this.getAttribute("transform")}),A.attr("opacity",m).attr("transform",function(t){var e=this.parentNode.__axis;return c((e&&isFinite(e=e(t))?e:N(t))+l)})),T.remove(),E.attr("d",o?"M"+y+","+h*o+"V"+l+"H"+w+"V"+h*o:"M"+y+","+l+"H"+w),M.attr("opacity",1).attr("transform",function(t){return c(N(t)+l)}),k.attr("y2",h*s),C.attr(u,h*p).text(f),S.filter(x).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor","middle"),S.each(function(){this.__axis=N})}return d.scale=function(t){return arguments.length?(e=t,d):e},d.ticks=function(){return n=Array.from(arguments),d},d.tickArguments=function(t){return arguments.length?(n=null==t?[]:Array.from(t),d):n.slice()},d.tickValues=function(t){return arguments.length?(i=null==t?null:Array.from(t),d):i&&i.slice()},d.tickFormat=function(t){return arguments.length?(r=t,d):r},d.tickSize=function(t){return arguments.length?(s=o=+t,d):s},d.tickSizeInner=function(t){return arguments.length?(s=+t,d):s},d.tickSizeOuter=function(t){return arguments.length?(o=+t,d):o},d.tickPadding=function(t){return arguments.length?(a=+t,d):a},d.offset=function(t){return arguments.length?(l=+t,d):l},d}var N={value:()=>{}};function S(){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 M(t,e){for(var n,i=0,r=t.length;i<r;++i)if((n=t[i]).name===e)return n.value}function T(t,e,n){for(var i=0,r=t.length;i<r;++i)if(t[i].name===e){t[i]=N,t=t.slice(0,i).concat(t.slice(i+1));break}return null!=n&&t.push({name:e,value:n}),t}E.prototype=S.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]=T(r[n],t.name,e);else if(null==e)for(n in r)r[n]=T(r[n],t.name,null);return this}for(;++o<a;)if((n=(t=s[o]).type)&&(n=M(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 A="http://www.w3.org/1999/xhtml",k={svg:"http://www.w3.org/2000/svg",xhtml:A,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function C(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),k.hasOwnProperty(e)?{space:k[e],local:t}:t}function z(t){return function(){var e=this.ownerDocument,n=this.namespaceURI;return n===A&&e.documentElement.namespaceURI===A?e.createElement(t):e.createElementNS(n,t)}}function $(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function D(t){var e=C(t);return(e.local?$:z)(e)}function P(){}function L(t){return null==t?P:function(){return this.querySelector(t)}}function I(){return[]}function O(t){return null==t?I:function(){return this.querySelectorAll(t)}}function U(t){return function(){return function(t){return null==t?[]:Array.isArray(t)?t:Array.from(t)}(t.apply(this,arguments))}}function j(t){return function(){return this.matches(t)}}function F(t){return function(e){return e.matches(t)}}var V=Array.prototype.find;function R(){return this.firstElementChild}var Y=Array.prototype.filter;function B(){return Array.from(this.children)}function H(t){return new Array(t.length)}function q(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function X(t,e,n,i,r,s){for(var o,a=0,l=e.length,h=s.length;a<h;++a)(o=e[a])?(o.__data__=s[a],i[a]=o):n[a]=new q(t,s[a]);for(;a<l;++a)(o=e[a])&&(r[a]=o)}function W(t,e,n,i,r,s,o){var a,l,h,u=new Map,c=e.length,d=s.length,f=new Array(c);for(a=0;a<c;++a)(l=e[a])&&(f[a]=h=o.call(l,l.__data__,a,e)+"",u.has(h)?r[a]=l:u.set(h,l));for(a=0;a<d;++a)h=o.call(t,s[a],a,s)+"",(l=u.get(h))?(i[a]=l,l.__data__=s[a],u.delete(h)):n[a]=new q(t,s[a]);for(a=0;a<c;++a)(l=e[a])&&u.get(f[a])===l&&(r[a]=l)}function Z(t){return t.__data__}function G(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}function J(t,e){return t<e?-1:t>e?1:t>=e?0:NaN}function K(t){return function(){this.removeAttribute(t)}}function Q(t){return function(){this.removeAttributeNS(t.space,t.local)}}function tt(t,e){return function(){this.setAttribute(t,e)}}function et(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function nt(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function it(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 rt(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function st(t){return function(){this.style.removeProperty(t)}}function ot(t,e,n){return function(){this.style.setProperty(t,e,n)}}function at(t,e,n){return function(){var i=e.apply(this,arguments);null==i?this.style.removeProperty(t):this.style.setProperty(t,i,n)}}function lt(t,e){return t.style.getPropertyValue(e)||rt(t).getComputedStyle(t,null).getPropertyValue(e)}function ht(t){return function(){delete this[t]}}function ut(t,e){return function(){this[t]=e}}function ct(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function dt(t){return t.trim().split(/^|\s+/)}function ft(t){return t.classList||new pt(t)}function pt(t){this._node=t,this._names=dt(t.getAttribute("class")||"")}function _t(t,e){for(var n=ft(t),i=-1,r=e.length;++i<r;)n.add(e[i])}function gt(t,e){for(var n=ft(t),i=-1,r=e.length;++i<r;)n.remove(e[i])}function mt(t){return function(){_t(this,t)}}function yt(t){return function(){gt(this,t)}}function vt(t,e){return function(){(e.apply(this,arguments)?_t:gt)(this,t)}}function bt(){this.textContent=""}function xt(t){return function(){this.textContent=t}}function wt(t){return function(){var e=t.apply(this,arguments);this.textContent=null==e?"":e}}function Nt(){this.innerHTML=""}function St(t){return function(){this.innerHTML=t}}function Et(t){return function(){var e=t.apply(this,arguments);this.innerHTML=null==e?"":e}}function Mt(){this.nextSibling&&this.parentNode.appendChild(this)}function Tt(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function At(){return null}function kt(){var t=this.parentNode;t&&t.removeChild(this)}function Ct(){var t=this.cloneNode(!1),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function zt(){var t=this.cloneNode(!0),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function $t(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 Dt(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 Pt(t,e,n){var i=rt(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 Pt(this,t,e)}}function It(t,e){return function(){return Pt(this,t,e.apply(this,arguments))}}q.prototype={constructor:q,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)}},pt.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 Ot=[null];function Ut(t,e){this._groups=t,this._parents=e}function jt(){return new Ut([[document.documentElement]],Ot)}function Ft(t){return"string"==typeof t?new Ut([[document.querySelector(t)]],[document.documentElement]):new Ut([[t]],Ot)}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 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]}Ut.prototype=jt.prototype={constructor:Ut,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,h=i[r]=new Array(l),u=0;u<l;++u)(s=a[u])&&(o=t.call(s,s.__data__,u,a))&&("__data__"in s&&(o.__data__=s.__data__),h[u]=o);return new Ut(i,this._parents)},selectAll:function(t){t="function"==typeof t?U(t):O(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,h=0;h<l;++h)(o=a[h])&&(i.push(t.call(o,o.__data__,h,a)),r.push(o));return new Ut(i,r)},selectChild:function(t){return this.select(null==t?R:function(t){return function(){return V.call(this.children,t)}}("function"==typeof t?t:F(t)))},selectChildren:function(t){return this.selectAll(null==t?B:function(t){return function(){return Y.call(this.children,t)}}("function"==typeof t?t:F(t)))},filter:function(t){"function"!=typeof t&&(t=j(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]=[],h=0;h<a;++h)(s=o[h])&&t.call(s,s.__data__,h,o)&&l.push(s);return new Ut(i,this._parents)},data:function(t,e){if(!arguments.length)return Array.from(this,Z);var n=e?W:X,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),h=0;h<s;++h){var u=i[h],c=r[h],d=c.length,f=G(t.call(u,u&&u.__data__,h,i)),p=f.length,_=a[h]=new Array(p),g=o[h]=new Array(p);n(u,c,_,g,l[h]=new Array(d),f,e);for(var m,y,v=0,b=0;v<p;++v)if(m=_[v]){for(v>=b&&(b=v+1);!(y=g[b])&&++b<p;);m._next=y||null}}return(o=new Ut(o,i))._enter=a,o._exit=l,o},enter:function(){return new Ut(this._enter||this._groups.map(H),this._parents)},exit:function(){return new Ut(this._exit||this._groups.map(H),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 h,u=n[l],c=i[l],d=u.length,f=a[l]=new Array(d),p=0;p<d;++p)(h=u[p]||c[p])&&(f[p]=h);for(;l<r;++l)a[l]=n[l];return new Ut(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=J);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,h=r[s]=new Array(l),u=0;u<l;++u)(o=a[u])&&(h[u]=o);h.sort(e)}return new Ut(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=C(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?Q:K:"function"==typeof e?n.local?it:nt:n.local?et:tt)(n,e))},style:function(t,e,n){return arguments.length>1?this.each((null==e?st:"function"==typeof e?at:ot)(t,e,null==n?"":n)):lt(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?ht:"function"==typeof e?ct:ut)(t,e)):this.node()[t]},classed:function(t,e){var n=dt(t+"");if(arguments.length<2){for(var i=ft(this.node()),r=-1,s=n.length;++r<s;)if(!i.contains(n[r]))return!1;return!0}return this.each(("function"==typeof e?vt:e?mt:yt)(n,e))},text:function(t){return arguments.length?this.each(null==t?bt:("function"==typeof t?wt:xt)(t)):this.node().textContent},html:function(t){return arguments.length?this.each(null==t?Nt:("function"==typeof t?Et:St)(t)):this.node().innerHTML},raise:function(){return this.each(Mt)},lower:function(){return this.each(Tt)},append:function(t){var e="function"==typeof t?t:D(t);return this.select(function(){return this.appendChild(e.apply(this,arguments))})},insert:function(t,e){var n="function"==typeof t?t:D(t),i=null==e?At:"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(kt)},clone:function(t){return this.select(t?zt:Ct)},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?Dt:$t,i=0;i<o;++i)this.each(a(s[i],e,n));return this}var a=this.node().__on;if(a)for(var l,h=0,u=a.length;h<u;++h)for(i=0,l=a[h];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?It: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 Rt={capture:!0,passive:!1};function Yt(t){t.preventDefault(),t.stopImmediatePropagation()}function Bt(t){var e=t.document.documentElement,n=Ft(t).on("dragstart.drag",Yt,Rt);"onselectstart"in e?n.on("selectstart.drag",Yt,Rt):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}function Ht(t,e){var n=t.document.documentElement,i=Ft(t).on("dragstart.drag",null);e&&(i.on("click.drag",Yt,Rt),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 qt(t,e,n){t.prototype=e.prototype=n,n.constructor=t}function Xt(t,e){var n=Object.create(t.prototype);for(var i in e)n[i]=e[i];return n}function Wt(){}var Zt=.7,Gt=1/Zt,Jt="\\s*([+-]?\\d+)\\s*",Kt="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Qt="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",te=/^#([0-9a-f]{3,8})$/,ee=new RegExp(`^rgb\\(${Jt},${Jt},${Jt}\\)$`),ne=new RegExp(`^rgb\\(${Qt},${Qt},${Qt}\\)$`),ie=new RegExp(`^rgba\\(${Jt},${Jt},${Jt},${Kt}\\)$`),re=new RegExp(`^rgba\\(${Qt},${Qt},${Qt},${Kt}\\)$`),se=new RegExp(`^hsl\\(${Kt},${Qt},${Qt}\\)$`),oe=new RegExp(`^hsla\\(${Kt},${Qt},${Qt},${Kt}\\)$`),ae={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 le(){return this.rgb().formatHex()}function he(){return this.rgb().formatRgb()}function ue(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=te.exec(t))?(n=e[1].length,e=parseInt(e[1],16),6===n?ce(e):3===n?new pe(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?de(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?de(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=ee.exec(t))?new pe(e[1],e[2],e[3],1):(e=ne.exec(t))?new pe(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=ie.exec(t))?de(e[1],e[2],e[3],e[4]):(e=re.exec(t))?de(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=se.exec(t))?be(e[1],e[2]/100,e[3]/100,1):(e=oe.exec(t))?be(e[1],e[2]/100,e[3]/100,e[4]):ae.hasOwnProperty(t)?ce(ae[t]):"transparent"===t?new pe(NaN,NaN,NaN,0):null}function ce(t){return new pe(t>>16&255,t>>8&255,255&t,1)}function de(t,e,n,i){return i<=0&&(t=e=n=NaN),new pe(t,e,n,i)}function fe(t,e,n,i){return 1===arguments.length?((r=t)instanceof Wt||(r=ue(r)),r?new pe((r=r.rgb()).r,r.g,r.b,r.opacity):new pe):new pe(t,e,n,null==i?1:i);var r}function pe(t,e,n,i){this.r=+t,this.g=+e,this.b=+n,this.opacity=+i}function _e(){return`#${ve(this.r)}${ve(this.g)}${ve(this.b)}`}function ge(){const t=me(this.opacity);return`${1===t?"rgb(":"rgba("}${ye(this.r)}, ${ye(this.g)}, ${ye(this.b)}${1===t?")":`, ${t})`}`}function me(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function ye(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function ve(t){return((t=ye(t))<16?"0":"")+t.toString(16)}function be(t,e,n,i){return i<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new we(t,e,n,i)}function xe(t){if(t instanceof we)return new we(t.h,t.s,t.l,t.opacity);if(t instanceof Wt||(t=ue(t)),!t)return new we;if(t instanceof we)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 we(o,a,l,t.opacity)}function we(t,e,n,i){this.h=+t,this.s=+e,this.l=+n,this.opacity=+i}function Ne(t){return(t=(t||0)%360)<0?t+360:t}function Se(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)}qt(Wt,ue,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:le,formatHex:le,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return xe(this).formatHsl()},formatRgb:he,toString:he}),qt(pe,fe,Xt(Wt,{brighter(t){return t=null==t?Gt:Math.pow(Gt,t),new pe(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?Zt:Math.pow(Zt,t),new pe(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new pe(ye(this.r),ye(this.g),ye(this.b),me(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:_e,formatHex:_e,formatHex8:function(){return`#${ve(this.r)}${ve(this.g)}${ve(this.b)}${ve(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:ge,toString:ge})),qt(we,function(t,e,n,i){return 1===arguments.length?xe(t):new we(t,e,n,null==i?1:i)},Xt(Wt,{brighter(t){return t=null==t?Gt:Math.pow(Gt,t),new we(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?Zt:Math.pow(Zt,t),new we(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 pe(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 we(Ne(this.h),Se(this.s),Se(this.l),me(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=me(this.opacity);return`${1===t?"hsl(":"hsla("}${Ne(this.h)}, ${100*Se(this.s)}%, ${100*Se(this.l)}%${1===t?")":`, ${t})`}`}}));var Me=t=>()=>t;function Te(t){return 1===(t=+t)?Ae:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(i){return Math.pow(t+i*e,n)}}(e,n,t):Me(isNaN(e)?n:e)}}function Ae(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):Me(isNaN(t)?e:t)}var ke=function t(e){var n=Te(e);function i(t,e){var i=n((t=fe(t)).r,(e=fe(e)).r),r=n(t.g,e.g),s=n(t.b,e.b),o=Ae(t.opacity,e.opacity);return function(e){return t.r=i(e),t.g=r(e),t.b=s(e),t.opacity=o(e),t+""}}return i.gamma=t,i}(1);function Ce(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 ze(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]=Ue(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 $e(t,e){var n=new Date;return t=+t,e=+e,function(i){return n.setTime(t*(1-i)+e*i),n}}function De(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}function Pe(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]=Ue(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,Ie=new RegExp(Le.source,"g");function Oe(t,e){var n,i,r,s=Le.lastIndex=Ie.lastIndex=0,o=-1,a=[],l=[];for(t+="",e+="";(n=Le.exec(t))&&(i=Ie.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:De(n,i)})),s=Ie.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 Ue(t,e){var n,i=typeof e;return null==e||"boolean"===i?Me(e):("number"===i?De:"string"===i?(n=ue(e))?(e=n,ke):Oe:e instanceof ue?ke:e instanceof Date?$e:function(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}(e)?Ce:Array.isArray(e)?ze:"function"!=typeof e.valueOf&&"function"!=typeof e.toString||isNaN(e)?Pe:De)(t,e)}function je(t,e){return t=+t,e=+e,function(n){return Math.round(t*(1-n)+e*n)}}var Fe,Ve=180/Math.PI,Re={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Ye(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)*Ve,skewX:Math.atan(l)*Ve,scaleX:o,scaleY:a}}function Be(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:De(t,r)},{i:l-2,x:De(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:De(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:De(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:De(t,n)},{i:a-2,x:De(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 He=Be(function(t){const e=new("function"==typeof DOMMatrix?DOMMatrix:WebKitCSSMatrix)(t+"");return e.isIdentity?Re:Ye(e.a,e.b,e.c,e.d,e.e,e.f)},"px, ","px)","deg)"),qe=Be(function(t){return null==t?Re:(Fe||(Fe=document.createElementNS("http://www.w3.org/2000/svg","g")),Fe.setAttribute("transform",t),(t=Fe.transform.baseVal.consolidate())?Ye((t=t.matrix).a,t.b,t.c,t.d,t.e,t.f):Re)},", ",")",")");function Xe(t){return((t=Math.exp(t))+1/t)/2}var We,Ze,Ge=function t(e,n,i){function r(t,r){var s,o,a=t[0],l=t[1],h=t[2],u=r[0],c=r[1],d=r[2],f=u-a,p=c-l,_=f*f+p*p;if(_<1e-12)o=Math.log(d/h)/e,s=function(t){return[a+t*f,l+t*p,h*Math.exp(e*t*o)]};else{var g=Math.sqrt(_),m=(d*d-h*h+i*_)/(2*h*n*g),y=(d*d-h*h-i*_)/(2*d*n*g),v=Math.log(Math.sqrt(m*m+1)-m),b=Math.log(Math.sqrt(y*y+1)-y);o=(b-v)/e,s=function(t){var i=t*o,r=Xe(v),s=h/(n*g)*(r*function(t){return((t=Math.exp(2*t))-1)/(t+1)}(e*i+v)-function(t){return((t=Math.exp(t))-1/t)/2}(v));return[a+s*f,l+s*p,h*r/Xe(e*i+v)]}}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),Je=0,Ke=0,Qe=0,tn=0,en=0,nn=0,rn="object"==typeof performance&&performance.now?performance:Date,sn="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function on(){return en||(sn(an),en=rn.now()+nn)}function an(){en=0}function ln(){this._call=this._time=this._next=null}function hn(t,e,n){var i=new ln;return i.restart(t,e,n),i}function un(){en=(tn=rn.now())+nn,Je=Ke=0;try{!function(){on(),++Je;for(var t,e=We;e;)(t=en-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Je}()}finally{Je=0,function(){var t,e,n=We,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:We=e);Ze=t,dn(i)}(),en=0}}function cn(){var t=rn.now(),e=t-tn;e>1e3&&(nn-=e,tn=t)}function dn(t){Je||(Ke&&(Ke=clearTimeout(Ke)),t-en>24?(t<1/0&&(Ke=setTimeout(un,t-rn.now()-nn)),Qe&&(Qe=clearInterval(Qe))):(Qe||(tn=rn.now(),Qe=setInterval(cn,1e3)),Je=1,sn(un)))}function fn(t,e,n){var i=new ln;return e=null==e?0:+e,i.restart(n=>{i.stop(),t(n+e)},e,n),i}ln.prototype=hn.prototype={constructor:ln,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?on():+n)+(null==e?0:+e),this._next||Ze===this||(Ze?Ze._next=this:We=this,Ze=this),this._call=t,this._time=n,dn()},stop:function(){this._call&&(this._call=null,this._time=1/0,dn())}};var pn=S("start","end","cancel","interrupt"),_n=[];function gn(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 h,u,c,d;if(1!==n.state)return l();for(h in r)if((d=r[h]).name===n.name){if(3===d.state)return fn(o);4===d.state?(d.state=6,d.timer.stop(),d.on.call("interrupt",t,t.__data__,d.index,d.group),delete r[h]):+h<e&&(d.state=6,d.timer.stop(),d.on.call("cancel",t,t.__data__,d.index,d.group),delete r[h])}if(fn(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(c=n.tween.length),h=0,u=-1;h<c;++h)(d=n.tween[h].value.call(t,t.__data__,n.index,n.group))&&(i[++u]=d);i.length=u+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:pn,tween:_n,time:s.time,delay:s.delay,duration:s.duration,ease:s.ease,timer:null,state:0})}function mn(t,e){var n=vn(t,e);if(n.state>0)throw new Error("too late; already scheduled");return n}function yn(t,e){var n=vn(t,e);if(n.state>3)throw new Error("too late; already running");return n}function vn(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function bn(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 xn(t,e){var n,i;return function(){var r=yn(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 wn(t,e,n){var i,r;if("function"!=typeof n)throw new Error;return function(){var s=yn(this,t),o=s.tween;if(o!==i){r=(i=o).slice();for(var a={name:e,value:n},l=0,h=r.length;l<h;++l)if(r[l].name===e){r[l]=a;break}l===h&&r.push(a)}s.tween=r}}function Nn(t,e,n){var i=t._id;return t.each(function(){var t=yn(this,i);(t.value||(t.value={}))[e]=n.apply(this,arguments)}),function(t){return vn(t,i).value[e]}}function Sn(t,e){var n;return("number"==typeof e?De:e instanceof ue?ke:(n=ue(e))?(e=n,ke):Oe)(t,e)}function En(t){return function(){this.removeAttribute(t)}}function Mn(t){return function(){this.removeAttributeNS(t.space,t.local)}}function Tn(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 An(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 kn(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 Cn(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 zn(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 $n(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 Dn(t,e){return function(){mn(this,t).delay=+e.apply(this,arguments)}}function Pn(t,e){return e=+e,function(){mn(this,t).delay=e}}function Ln(t,e){return function(){yn(this,t).duration=+e.apply(this,arguments)}}function In(t,e){return e=+e,function(){yn(this,t).duration=e}}var On=jt.prototype.constructor;function Un(t){return function(){this.style.removeProperty(t)}}var jn=0;function Fn(t,e,n,i){this._groups=t,this._parents=e,this._name=n,this._id=i}function Vn(){return++jn}var Rn=jt.prototype;Fn.prototype={constructor:Fn,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,h=i[o],u=h.length,c=s[o]=new Array(u),d=0;d<u;++d)(a=h[d])&&(l=t.call(a,a.__data__,d,h))&&("__data__"in a&&(l.__data__=a.__data__),c[d]=l,gn(c[d],e,n,d,c,vn(a,n)));return new Fn(s,this._parents,e,n)},selectAll:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=O(t));for(var i=this._groups,r=i.length,s=[],o=[],a=0;a<r;++a)for(var l,h=i[a],u=h.length,c=0;c<u;++c)if(l=h[c]){for(var d,f=t.call(l,l.__data__,c,h),p=vn(l,n),_=0,g=f.length;_<g;++_)(d=f[_])&&gn(d,e,n,_,f,p);s.push(f),o.push(l)}return new Fn(s,o,e,n)},selectChild:Rn.selectChild,selectChildren:Rn.selectChildren,filter:function(t){"function"!=typeof t&&(t=j(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]=[],h=0;h<a;++h)(s=o[h])&&t.call(s,s.__data__,h,o)&&l.push(s);return new Fn(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,h=e[a],u=n[a],c=h.length,d=o[a]=new Array(c),f=0;f<c;++f)(l=h[f]||u[f])&&(d[f]=l);for(;a<i;++a)o[a]=e[a];return new Fn(o,this._parents,this._name,this._id)},selection:function(){return new On(this._groups,this._parents)},transition:function(){for(var t=this._name,e=this._id,n=Vn(),i=this._groups,r=i.length,s=0;s<r;++s)for(var o,a=i[s],l=a.length,h=0;h<l;++h)if(o=a[h]){var u=vn(o,e);gn(o,t,n,h,a,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new Fn(i,this._parents,t,n)},call:Rn.call,nodes:Rn.nodes,node:Rn.node,size:Rn.size,empty:Rn.empty,each:Rn.each,on:function(t,e){var n=this._id;return arguments.length<2?vn(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)?mn:yn;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=C(t),i="transform"===n?qe:Sn;return this.attrTween(t,"function"==typeof e?(n.local?Cn:kn)(n,i,Nn(this,"attr."+t,e)):null==e?(n.local?Mn:En)(n):(n.local?An:Tn)(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=C(t);return this.tween(n,(i.local?zn:$n)(i,e))},style:function(t,e,n){var i="transform"==(t+="")?He:Sn;return null==e?this.styleTween(t,function(t,e){var n,i,r;return function(){var s=lt(this,t),o=(this.style.removeProperty(t),lt(this,t));return s===o?null:s===n&&o===i?r:r=e(n=s,i=o)}}(t,i)).on("end.style."+t,Un(t)):"function"==typeof e?this.styleTween(t,function(t,e,n){var i,r,s;return function(){var o=lt(this,t),a=n(this),l=a+"";return null==a&&(this.style.removeProperty(t),l=a=lt(this,t)),o===l?null:o===i&&l===r?s:(r=l,s=e(i=o,a))}}(t,i,Nn(this,"style."+t,e))).each(function(t,e){var n,i,r,s,o="style."+e,a="end."+o;return function(){var l=yn(this,t),h=l.on,u=null==l.value[o]?s||(s=Un(e)):void 0;h===n&&r===u||(i=(n=h).copy()).on(a,r=u),l.on=i}}(this._id,t)):this.styleTween(t,function(t,e,n){var i,r,s=n+"";return function(){var o=lt(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}}(Nn(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=vn(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?xn:wn)(n,t,e))},delay:function(t){var e=this._id;return arguments.length?this.each(("function"==typeof t?Dn:Pn)(e,t)):vn(this.node(),e).delay},duration:function(t){var e=this._id;return arguments.length?this.each(("function"==typeof t?Ln:In)(e,t)):vn(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(){yn(this,t).ease=e}}(e,t)):vn(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;yn(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=yn(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]:Rn[Symbol.iterator]};var Yn={time:null,delay:0,duration:250,ease:function(t){return((t*=2)<=1?t*t*t:(t-=2)*t*t+2)/2}};function Bn(t,e){for(var n;!(n=t.__transition)||!(n=n[e]);)if(!(t=t.parentNode))throw new Error(`transition ${e} not found`);return n}jt.prototype.interrupt=function(t){return this.each(function(){bn(this,t)})},jt.prototype.transition=function(t){var e,n;t instanceof Fn?(e=t._id,t=t._name):(e=Vn(),(n=Yn).time=on(),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,h=0;h<l;++h)(o=a[h])&&gn(o,t,e,h,a,n||Bn(o,e));return new Fn(i,this._parents,t,e)};var Hn=t=>()=>t;function qn(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 Xn(t){t.preventDefault(),t.stopImmediatePropagation()}var Wn={name:"drag"},Zn={name:"space"},Gn={name:"handle"},Jn={name:"center"};const{abs:Kn,max:Qn,min:ti}=Math;function ei(t){return[+t[0],+t[1]]}function ni(t){return[ei(t[0]),ei(t[1])]}var ii={},ri={},si={name:"xy",handles:["n","w","e","s","nw","ne","sw","se"].map(ci),input:function(t){return null==t?null:ni(t)},output:function(t){return t}},oi={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"},ai={e:"w",w:"e",nw:"ne",ne:"nw",se:"sw",sw:"se"},li={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},ui={overlay:1,selection:1,n:-1,e:null,s:1,w:null,nw:-1,ne:-1,se:1,sw:1};function ci(t){return{type:t}}function di(t){return!t.ctrlKey&&!t.button}function fi(){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 pi(){return navigator.maxTouchPoints||"ontouchstart"in this}function _i(t){for(;!t.__brush;)if(!(t=t.parentNode))return;return t.__brush}function gi(){return function(t){var e,n=fi,i=di,r=pi,s=!0,o=S("start","brush","end"),a=6;function l(e){var n=e.property("__brush",_).selectAll(".overlay").data([ci("overlay")]);n.enter().append("rect").attr("class","overlay").attr("pointer-events","all").attr("cursor",oi.overlay).merge(n).each(function(){var t=_i(this).extent;Ft(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([ci("selection")]).enter().append("rect").attr("class","selection").attr("cursor",oi.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 oi[t.type]}),e.each(h).attr("fill","none").attr("pointer-events","all").on("mousedown.brush",d).filter(r).on("touchstart.brush",d).on("touchmove.brush",f).on("touchend.brush touchcancel.brush",p).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function h(){var t=Ft(this),e=_i(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 u(t,e,n){var i=t.__brush.emitter;return!i||n&&i.clean?new c(t,e,n):i}function c(t,e,n){this.that=t,this.args=e,this.state=t.__brush,this.active=0,this.clean=n}function d(n){if((!e||n.touches)&&i.apply(this,arguments)){var r,o,a,l,c,d,f,p,_,g,m,y=this,v=n.target.__data__.type,b="selection"===(s&&n.metaKey?v="overlay":v)?Wn:s&&n.altKey?Jn:Gn,x=t===ri?null:hi[v],w=t===ii?null:ui[v],N=_i(y),S=N.extent,E=N.selection,M=S[0][0],T=S[0][1],A=S[1][0],k=S[1][1],C=0,z=0,$=x&&w&&s&&n.shiftKey,D=Array.from(n.touches||[n],t=>{const e=t.identifier;return(t=Vt(t,y)).point0=t.slice(),t.identifier=e,t});bn(y);var P=u(y,arguments,!0).beforestart();if("overlay"===v){E&&(_=!0);const e=[D[0],D[1]||D[0]];N.selection=E=[[r=t===ri?M:ti(e[0][0],e[1][0]),a=t===ii?T:ti(e[0][1],e[1][1])],[c=t===ri?A:Qn(e[0][0],e[1][0]),f=t===ii?k:Qn(e[0][1],e[1][1])]],D.length>1&&j(n)}else r=E[0][0],a=E[0][1],c=E[1][0],f=E[1][1];o=r,l=a,d=c,p=f;var L=Ft(y).attr("pointer-events","none"),I=L.selectAll(".overlay").attr("cursor",oi[v]);if(n.touches)P.moved=U,P.ended=F;else{var O=Ft(n.view).on("mousemove.brush",U,!0).on("mouseup.brush",F,!0);s&&O.on("keydown.brush",V,!0).on("keyup.brush",R,!0),Bt(n.view)}h.call(y),P.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=Vt(e,y));if($&&!g&&!m&&1===D.length){const t=D[0];Kn(t.cur[0]-t[0])>Kn(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,Xn(t),j(t)}function j(t){const e=D[0],n=e.point0;var i;switch(C=e[0]-n[0],z=e[1]-n[1],b){case Zn:case Wn:x&&(C=Qn(M-r,ti(A-c,C)),o=r+C,d=c+C),w&&(z=Qn(T-a,ti(k-f,z)),l=a+z,p=f+z);break;case Gn:D[1]?(x&&(o=Qn(M,ti(A,D[0][0])),d=Qn(M,ti(A,D[1][0])),x=1),w&&(l=Qn(T,ti(k,D[0][1])),p=Qn(T,ti(k,D[1][1])),w=1)):(x<0?(C=Qn(M-r,ti(A-r,C)),o=r+C,d=c):x>0&&(C=Qn(M-c,ti(A-c,C)),o=r,d=c+C),w<0?(z=Qn(T-a,ti(k-a,z)),l=a+z,p=f):w>0&&(z=Qn(T-f,ti(k-f,z)),l=a,p=f+z));break;case Jn:x&&(o=Qn(M,ti(A,r-C*x)),d=Qn(M,ti(A,c+C*x))),w&&(l=Qn(T,ti(k,a-z*w)),p=Qn(T,ti(k,f+z*w)))}d<o&&(x*=-1,i=r,r=c,c=i,i=o,o=d,d=i,v in ai&&I.attr("cursor",oi[v=ai[v]])),p<l&&(w*=-1,i=a,a=f,f=i,i=l,l=p,p=i,v in li&&I.attr("cursor",oi[v=li[v]])),N.selection&&(E=N.selection),g&&(o=E[0][0],d=E[1][0]),m&&(l=E[0][1],p=E[1][1]),E[0][0]===o&&E[0][1]===l&&E[1][0]===d&&E[1][1]===p||(N.selection=[[o,l],[d,p]],h.call(y),P.brush(t,b.name))}function F(t){if(function(t){t.stopImmediatePropagation()}(t),t.touches){if(t.touches.length)return;e&&clearTimeout(e),e=setTimeout(function(){e=null},500)}else Ht(t.view,_),O.on("keydown.brush keyup.brush mousemove.brush mouseup.brush",null);L.attr("pointer-events","all"),I.attr("cursor",oi.overlay),N.selection&&(E=N.selection),function(t){return t[0][0]===t[1][0]||t[0][1]===t[1][1]}(E)&&(N.selection=null,h.call(y)),P.end(t,b.name)}function V(t){switch(t.keyCode){case 16:$=x&&w;break;case 18:b===Gn&&(x&&(c=d-C*x,r=o+C*x),w&&(f=p-z*w,a=l+z*w),b=Jn,j(t));break;case 32:b!==Gn&&b!==Jn||(x<0?c=d-C:x>0&&(r=o-C),w<0?f=p-z:w>0&&(a=l-z),b=Zn,I.attr("cursor",oi.selection),j(t));break;default:return}Xn(t)}function R(t){switch(t.keyCode){case 16:$&&(g=m=$=!1,j(t));break;case 18:b===Jn&&(x<0?c=d:x>0&&(r=o),w<0?f=p:w>0&&(a=l),b=Gn,j(t));break;case 32:b===Zn&&(t.altKey?(x&&(c=d-C*x,r=o+C*x),w&&(f=p-z*w,a=l+z*w),b=Jn):(x<0?c=d:x>0&&(r=o),w<0?f=p:w>0&&(a=l),b=Gn),I.attr("cursor",oi[v]),j(t));break;default:return}Xn(t)}}function f(t){u(this,arguments).moved(t)}function p(t){u(this,arguments).ended(t)}function _(){var e=this.__brush||{selection:null};return e.extent=ni(n.apply(this,arguments)),e.dim=t,e}return l.move=function(e,n,i){e.tween?e.on("start.brush",function(t){u(this,arguments).beforestart().start(t)}).on("interrupt.brush end.brush",function(t){u(this,arguments).end(t)}).tween("brush",function(){var e=this,i=e.__brush,r=u(e,arguments),s=i.selection,o=t.input("function"==typeof n?n.apply(this,arguments):n,i.extent),a=Ue(s,o);function l(t){i.selection=1===t&&null===o?null:a(t),h.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=u(e,r).beforestart();bn(e),s.selection=null===o?null:o,h.call(e),a.start(i).brush(i).end(i)})},l.clear=function(t,e){l.move(t,null,e)},c.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=Ft(this.that).datum();o.call(e,this.that,new qn(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:Hn(ni(t)),l):n},l.filter=function(t){return arguments.length?(i="function"==typeof t?t:Hn(!!t),l):i},l.touchable=function(t){return arguments.length?(r="function"==typeof t?t:Hn(!!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}(si)}const mi=Math.PI,yi=2*mi,vi=1e-6,bi=yi-vi;function xi(t){this._+=t[0];for(let e=1,n=t.length;e<n;++e)this._+=arguments[e]+t[e]}class wi{constructor(t){this._x0=this._y0=this._x1=this._y1=null,this._="",this._append=null==t?xi:function(t){let e=Math.floor(t);if(!(e>=0))throw new Error(`invalid digits: ${t}`);if(e>15)return xi;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,h=s-t,u=o-e,c=h*h+u*u;if(null===this._x1)this._append`M${this._x1=t},${this._y1=e}`;else if(c>vi)if(Math.abs(u*a-l*h)>vi&&r){let d=n-s,f=i-o,p=a*a+l*l,_=d*d+f*f,g=Math.sqrt(p),m=Math.sqrt(c),y=r*Math.tan((mi-Math.acos((p+c-_)/(2*g*m)))/2),v=y/m,b=y/g;Math.abs(v-1)>vi&&this._append`L${t+v*h},${e+v*u}`,this._append`A${r},${r},0,0,${+(u*d>h*f)},${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,h=e+a,u=1^s,c=s?i-r:r-i;null===this._x1?this._append`M${l},${h}`:(Math.abs(this._x1-l)>vi||Math.abs(this._y1-h)>vi)&&this._append`L${l},${h}`,n&&(c<0&&(c=c%yi+yi),c>bi?this._append`A${n},${n},0,1,${u},${t-o},${e-a}A${n},${n},0,1,${u},${this._x1=l},${this._y1=h}`:c>vi&&this._append`A${n},${n},0,${+(c>=mi)},${u},${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 Ni(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 Si(t){return(t=Ni(Math.abs(t)))?t[1]:NaN}var Ei,Mi=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Ti(t){if(!(e=Mi.exec(t)))throw new Error("invalid format: "+t);var e;return new Ai({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 Ai(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 ki(t,e){var n=Ni(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")}Ti.prototype=Ai.prototype,Ai.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 Ci={"%":(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)=>ki(100*t,e),r:ki,s:function(t,e){var n=Ni(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")+Ni(t,Math.max(0,e+s-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function zi(t){return t}var $i,Di,Pi,Li=Array.prototype.map,Ii=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Oi(t){var e,n,i=void 0===t.grouping||void 0===t.thousands?zi:(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?zi: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+"",h=void 0===t.minus?"−":t.minus+"",u=void 0===t.nan?"NaN":t.nan+"";function c(t){var e=(t=Ti(t)).fill,n=t.align,c=t.sign,d=t.symbol,f=t.zero,p=t.width,_=t.comma,g=t.precision,m=t.trim,y=t.type;"n"===y?(_=!0,y="g"):Ci[y]||(void 0===g&&(g=12),m=!0,y="g"),(f||"0"===e&&"="===n)&&(f=!0,e="0",n="=");var v="$"===d?r:"#"===d&&/[boxX]/.test(y)?"0"+y.toLowerCase():"",b="$"===d?s:/[%p]/.test(y)?l:"",x=Ci[y],w=/[defgprs%]/.test(y);function N(t){var r,s,l,d=v,N=b;if("c"===y)N=x(t)+N,t="";else{var S=(t=+t)<0||1/t<0;if(t=isNaN(t)?u: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)),S&&0===+t&&"+"!==c&&(S=!1),d=(S?"("===c?c:h:"-"===c||"("===c?"":c)+d,N=("s"===y?Ii[8+Ei/3]:"")+N+(S&&"("===c?")":""),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}}_&&!f&&(t=i(t,1/0));var E=d.length+t.length+N.length,M=E<p?new Array(p-E+1).join(e):"";switch(_&&f&&(t=i(M+t,M.length?p-N.length:1/0),M=""),n){case"<":t=d+t+N+M;break;case"=":t=d+M+t+N;break;case"^":t=M.slice(0,E=M.length>>1)+d+t+N+M.slice(E);break;default:t=M+d+t+N}return a(t)}return g=void 0===g?6:/[gprs]/.test(y)?Math.max(1,Math.min(21,g)):Math.max(0,Math.min(20,g)),N.toString=function(){return t+""},N}return{format:c,formatPrefix:function(t,e){var n=c(((t=Ti(t)).type="f",t)),i=3*Math.max(-8,Math.min(8,Math.floor(Si(e)/3))),r=Math.pow(10,-i),s=Ii[8+i/3];return function(t){return n(r*t)+s}}}}function Ui(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 ji(t,e){t instanceof Map?(t=[void 0,t],void 0===e&&(e=Vi)):void 0===e&&(e=Fi);for(var n,i,r,s,o,a=new Bi(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 Bi(r[s])),i.parent=n,i.depth=n.depth+1;return a.eachBefore(Yi)}function Fi(t){return t.children}function Vi(t){return Array.isArray(t)?t[1]:null}function Ri(t){void 0!==t.data.value&&(t.value=t.data.value),t.data=t.data.data}function Yi(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function Bi(t){this.data=t,this.depth=this.height=0,this.parent=null}function Hi(t,e){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(e).domain(t)}return this}function qi(t){return+t}$i=Oi({thousands:",",grouping:[3],currency:["$",""]}),Di=$i.format,Pi=$i.formatPrefix,Bi.prototype=ji.prototype={constructor:Bi,count:function(){return this.eachAfter(Ui)},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 ji(this).eachBefore(Ri)},[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 Xi=[0,1];function Wi(t){return t}function Zi(t,e){return(e-=t=+t)?function(n){return(n-t)/e}:function(t){return function(){return t}}(isNaN(e)?NaN:.5)}function Gi(t,e,n){var i=t[0],r=t[1],s=e[0],o=e[1];return r<i?(i=Zi(r,i),s=n(o,s)):(i=Zi(i,r),s=n(s,o)),function(t){return s(i(t))}}function Ji(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]=Zi(t[o],t[o+1]),s[o]=n(e[o],e[o+1]);return function(e){var n=u(t,e,1,i)-1;return s[n](r[n](e))}}function Ki(){var t,e,n,i,r,s,o=Xi,a=Xi,l=Ue,h=Wi;function u(){var t,e,n,l=Math.min(o.length,a.length);return h!==Wi&&(t=o[0],e=o[l-1],t>e&&(n=t,t=e,e=n),h=function(n){return Math.max(t,Math.min(e,n))}),i=l>2?Ji:Gi,r=s=null,c}function c(e){return null==e||isNaN(e=+e)?n:(r||(r=i(o.map(t),a,l)))(t(h(e)))}return c.invert=function(n){return h(e((s||(s=i(a,o.map(t),De)))(n)))},c.domain=function(t){return arguments.length?(o=Array.from(t,qi),u()):o.slice()},c.range=function(t){return arguments.length?(a=Array.from(t),u()):a.slice()},c.rangeRound=function(t){return a=Array.from(t),l=je,u()},c.clamp=function(t){return arguments.length?(h=!!t||Wi,u()):h!==Wi},c.interpolate=function(t){return arguments.length?(l=t,u()):l},c.unknown=function(t){return arguments.length?(n=t,c):n},function(n,i){return t=n,e=i,u()}}function Qi(t,e,n,i){var r,s=function(t,e,n){n=+n;const i=(e=+e)<(t=+t),r=i?_(e,t,n):_(t,e,n);return(i?-1:1)*(r<0?1/-r:r)}(t,e,n);switch((i=Ti(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(Si(e)/3)))-Si(Math.abs(t)))}(s,o))||(i.precision=r),Pi(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,Si(e)-Si(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,-Si(Math.abs(t)))}(s))||(i.precision=r-2*("%"===i.type))}return Di(i)}function tr(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?p(e,t,n):p(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 Qi(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],h=s[a],u=10;for(h<l&&(r=l,l=h,h=r,r=o,o=a,a=r);u-- >0;){if((r=_(l,h,n))===i)return s[o]=l,s[a]=h,e(s);if(r>0)l=Math.floor(l/r)*r,h=Math.ceil(h/r)*r;else{if(!(r<0))break;l=Math.ceil(l*r)/r,h=Math.floor(h*r)/r}i=r}return t},t}function er(){var t=Ki()(Wi,Wi);return t.copy=function(){return e=t,er().domain(e.domain()).range(e.range()).interpolate(e.interpolate()).clamp(e.clamp()).unknown(e.unknown());var e},Hi.apply(t,arguments),tr(t)}const nr=new Date,ir=new Date;function rr(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=>rr(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)=>(nr.setTime(+e),ir.setTime(+i),t(nr),t(ir),Math.floor(n(nr,ir))),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 sr=6e4,or=864e5,ar=6048e5,lr=rr(t=>t.setHours(0,0,0,0),(t,e)=>t.setDate(t.getDate()+e),(t,e)=>(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*sr)/or,t=>t.getDate()-1);lr.range;const hr=rr(t=>{t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+e)},(t,e)=>(e-t)/or,t=>t.getUTCDate()-1);hr.range;const ur=rr(t=>{t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+e)},(t,e)=>(e-t)/or,t=>Math.floor(t/or));function cr(t){return rr(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())*sr)/ar)}ur.range;const dr=cr(0),fr=cr(1),pr=cr(2),_r=cr(3),gr=cr(4),mr=cr(5),yr=cr(6);function vr(t){return rr(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)/ar)}dr.range,fr.range,pr.range,_r.range,gr.range,mr.range,yr.range;const br=vr(0),xr=vr(1),wr=vr(2),Nr=vr(3),Sr=vr(4),Er=vr(5),Mr=vr(6);br.range,xr.range,wr.range,Nr.range,Sr.range,Er.range,Mr.range;const Tr=rr(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());Tr.every=t=>isFinite(t=Math.floor(t))&&t>0?rr(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,Tr.range;const Ar=rr(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 kr(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 Cr(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 zr(t,e,n){return{y:t,m:e,d:n,H:0,M:0,S:0,L:0}}Ar.every=t=>isFinite(t=Math.floor(t))&&t>0?rr(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,Ar.range;var $r,Dr,Pr={"-":"",_:" ",0:"0"},Lr=/^\s*\d+/,Ir=/^%/,Or=/[\\^$*+?|[\]().{}]/g;function Ur(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 jr(t){return t.replace(Or,"\\$&")}function Fr(t){return new RegExp("^(?:"+t.map(jr).join("|")+")","i")}function Vr(t){return new Map(t.map((t,e)=>[t.toLowerCase(),e]))}function Rr(t,e,n){var i=Lr.exec(e.slice(n,n+1));return i?(t.w=+i[0],n+i[0].length):-1}function Yr(t,e,n){var i=Lr.exec(e.slice(n,n+1));return i?(t.u=+i[0],n+i[0].length):-1}function Br(t,e,n){var i=Lr.exec(e.slice(n,n+2));return i?(t.U=+i[0],n+i[0].length):-1}function Hr(t,e,n){var i=Lr.exec(e.slice(n,n+2));return i?(t.V=+i[0],n+i[0].length):-1}function qr(t,e,n){var i=Lr.exec(e.slice(n,n+2));return i?(t.W=+i[0],n+i[0].length):-1}function Xr(t,e,n){var i=Lr.exec(e.slice(n,n+4));return i?(t.y=+i[0],n+i[0].length):-1}function Wr(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 Zr(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 Gr(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 Jr(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 Kr(t,e,n){var i=Lr.exec(e.slice(n,n+2));return i?(t.d=+i[0],n+i[0].length):-1}function Qr(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 ts(t,e,n){var i=Lr.exec(e.slice(n,n+2));return i?(t.H=+i[0],n+i[0].length):-1}function es(t,e,n){var i=Lr.exec(e.slice(n,n+2));return i?(t.M=+i[0],n+i[0].length):-1}function ns(t,e,n){var i=Lr.exec(e.slice(n,n+2));return i?(t.S=+i[0],n+i[0].length):-1}function is(t,e,n){var i=Lr.exec(e.slice(n,n+3));return i?(t.L=+i[0],n+i[0].length):-1}function rs(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 ss(t,e,n){var i=Ir.exec(e.slice(n,n+1));return i?n+i[0].length:-1}function os(t,e,n){var i=Lr.exec(e.slice(n));return i?(t.Q=+i[0],n+i[0].length):-1}function as(t,e,n){var i=Lr.exec(e.slice(n));return i?(t.s=+i[0],n+i[0].length):-1}function ls(t,e){return Ur(t.getDate(),e,2)}function hs(t,e){return Ur(t.getHours(),e,2)}function us(t,e){return Ur(t.getHours()%12||12,e,2)}function cs(t,e){return Ur(1+lr.count(Tr(t),t),e,3)}function ds(t,e){return Ur(t.getMilliseconds(),e,3)}function fs(t,e){return ds(t,e)+"000"}function ps(t,e){return Ur(t.getMonth()+1,e,2)}function _s(t,e){return Ur(t.getMinutes(),e,2)}function gs(t,e){return Ur(t.getSeconds(),e,2)}function ms(t){var e=t.getDay();return 0===e?7:e}function ys(t,e){return Ur(dr.count(Tr(t)-1,t),e,2)}function vs(t){var e=t.getDay();return e>=4||0===e?gr(t):gr.ceil(t)}function bs(t,e){return t=vs(t),Ur(gr.count(Tr(t),t)+(4===Tr(t).getDay()),e,2)}function xs(t){return t.getDay()}function ws(t,e){return Ur(fr.count(Tr(t)-1,t),e,2)}function Ns(t,e){return Ur(t.getFullYear()%100,e,2)}function Ss(t,e){return Ur((t=vs(t)).getFullYear()%100,e,2)}function Es(t,e){return Ur(t.getFullYear()%1e4,e,4)}function Ms(t,e){var n=t.getDay();return Ur((t=n>=4||0===n?gr(t):gr.ceil(t)).getFullYear()%1e4,e,4)}function Ts(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+Ur(e/60|0,"0",2)+Ur(e%60,"0",2)}function As(t,e){return Ur(t.getUTCDate(),e,2)}function ks(t,e){return Ur(t.getUTCHours(),e,2)}function Cs(t,e){return Ur(t.getUTCHours()%12||12,e,2)}function zs(t,e){return Ur(1+hr.count(Ar(t),t),e,3)}function $s(t,e){return Ur(t.getUTCMilliseconds(),e,3)}function Ds(t,e){return $s(t,e)+"000"}function Ps(t,e){return Ur(t.getUTCMonth()+1,e,2)}function Ls(t,e){return Ur(t.getUTCMinutes(),e,2)}function Is(t,e){return Ur(t.getUTCSeconds(),e,2)}function Os(t){var e=t.getUTCDay();return 0===e?7:e}function Us(t,e){return Ur(br.count(Ar(t)-1,t),e,2)}function js(t){var e=t.getUTCDay();return e>=4||0===e?Sr(t):Sr.ceil(t)}function Fs(t,e){return t=js(t),Ur(Sr.count(Ar(t),t)+(4===Ar(t).getUTCDay()),e,2)}function Vs(t){return t.getUTCDay()}function Rs(t,e){return Ur(xr.count(Ar(t)-1,t),e,2)}function Ys(t,e){return Ur(t.getUTCFullYear()%100,e,2)}function Bs(t,e){return Ur((t=js(t)).getUTCFullYear()%100,e,2)}function Hs(t,e){return Ur(t.getUTCFullYear()%1e4,e,4)}function qs(t,e){var n=t.getUTCDay();return Ur((t=n>=4||0===n?Sr(t):Sr.ceil(t)).getUTCFullYear()%1e4,e,4)}function Xs(){return"+0000"}function Ws(){return"%"}function Zs(t){return+t}function Gs(t){return Math.floor(+t/1e3)}function Js(t){return function(){return t}}function Ks(t){this._context=t}function Qs(t){return new Ks(t)}function to(t){return t[0]}function eo(t){return t[1]}function no(t,e){var n=Js(!0),i=null,r=Qs,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 wi(e)}(a);function a(a){var l,h,u,c=(a=function(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}(a)).length,d=!1;for(null==i&&(s=r(u=o())),l=0;l<=c;++l)!(l<c&&n(h=a[l],l,a))===d&&((d=!d)?s.lineStart():s.lineEnd()),d&&s.point(+t(h,l,a),+e(h,l,a));if(u)return s=null,u+""||null}return t="function"==typeof t?t:void 0===t?to:Js(t),e="function"==typeof e?e:void 0===e?eo:Js(e),a.x=function(e){return arguments.length?(t="function"==typeof e?e:Js(+e),a):t},a.y=function(t){return arguments.length?(e="function"==typeof t?t:Js(+t),a):e},a.defined=function(t){return arguments.length?(n="function"==typeof t?t:Js(!!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 io(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 ro(t){this._context=t}function so(t){return new ro(t)}function oo(t,e){this._context=t,this._t=e}!function(t){$r=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,h=Fr(r),u=Vr(r),c=Fr(s),d=Vr(s),f=Fr(o),p=Vr(o),_=Fr(a),g=Vr(a),m=Fr(l),y=Vr(l),v={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:ls,e:ls,f:fs,g:Ss,G:Ms,H:hs,I:us,j:cs,L:ds,m:ps,M:_s,p:function(t){return r[+(t.getHours()>=12)]},q:function(t){return 1+~~(t.getMonth()/3)},Q:Zs,s:Gs,S:gs,u:ms,U:ys,V:bs,w:xs,W:ws,x:null,X:null,y:Ns,Y:Es,Z:Ts,"%":Ws},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:As,e:As,f:Ds,g:Bs,G:qs,H:ks,I:Cs,j:zs,L:$s,m:Ps,M:Ls,p:function(t){return r[+(t.getUTCHours()>=12)]},q:function(t){return 1+~~(t.getUTCMonth()/3)},Q:Zs,s:Gs,S:Is,u:Os,U:Us,V:Fs,w:Vs,W:Rs,x:null,X:null,y:Ys,Y:Hs,Z:Xs,"%":Ws},x={a:function(t,e,n){var i=f.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=c.exec(e.slice(n));return i?(t.w=d.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=y.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 S(t,e,n,i)},d:Kr,e:Kr,f:rs,g:Wr,G:Xr,H:ts,I:ts,j:Qr,L:is,m:Jr,M:es,p:function(t,e,n){var i=h.exec(e.slice(n));return i?(t.p=u.get(i[0].toLowerCase()),n+i[0].length):-1},q:Gr,Q:os,s:as,S:ns,u:Yr,U:Br,V:Hr,w:Rr,W:qr,x:function(t,e,i){return S(t,n,e,i)},X:function(t,e,n){return S(t,i,e,n)},y:Wr,Y:Xr,Z:Zr,"%":ss};function w(t,e){return function(n){var i,r,s,o=[],a=-1,l=0,h=t.length;for(n instanceof Date||(n=new Date(+n));++a<h;)37===t.charCodeAt(a)&&(o.push(t.slice(l,a)),null!=(r=Pr[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=zr(1900,void 0,1);if(S(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=Cr(zr(s.y,0,1))).getUTCDay(),i=r>4||0===r?xr.ceil(i):xr(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=kr(zr(s.y,0,1))).getDay(),i=r>4||0===r?fr.ceil(i):fr(i),i=lr.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?Cr(zr(s.y,0,1)).getUTCDay():kr(zr(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,Cr(s)):kr(s)}}function S(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 Pr?e.charAt(o++):r])||(i=s(t,n,i))<0)return-1}else if(r!=n.charCodeAt(i++))return-1}return i}return v.x=w(n,v),v.X=w(i,v),v.c=w(e,v),b.x=w(n,b),b.X=w(i,b),b.c=w(e,b),{format:function(t){var e=w(t+="",v);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),$r.format,Dr=$r.parse,$r.utcFormat,$r.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"]}),Ks.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)}}},ro.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:io(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:io(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}},oo.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 ao=t=>()=>t;function lo(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 uo=new ho(1,0,0);function co(t){t.stopImmediatePropagation()}function fo(t){t.preventDefault(),t.stopImmediatePropagation()}function po(t){return!(t.ctrlKey&&"wheel"!==t.type||t.button)}function _o(){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 go(){return this.__zoom||uo}function mo(t){return-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function yo(){return navigator.maxTouchPoints||"ontouchstart"in this}function vo(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 bo=":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",xo=new RegExp("^"+("["+bo+"]["+(bo+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040")+"]*")+"$");function wo(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 No=function(t){const e=xo.exec(t);return!(null==e)};const So=["hasOwnProperty","toString","valueOf","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__"],Eo=["__proto__","constructor","prototype"],Mo={allowBooleanAttributes:!1,unpairedTags:[]};function To(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.",jo(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 Po(t,e){const n=wo(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.",Fo(n[t]));if(void 0!==n[t][3]&&void 0===n[t][4])return Io("InvalidAttr","Attribute '"+n[t][2]+"' is without value.",Fo(n[t]));if(void 0===n[t][3]&&!e.allowBooleanAttributes)return Io("InvalidAttr","boolean attribute '"+n[t][2]+"' is not allowed.",Fo(n[t]));const r=n[t][2];if(!Oo(r))return Io("InvalidAttr","Attribute '"+r+"' is an invalid name.",Fo(n[t]));if(Object.prototype.hasOwnProperty.call(i,r))return Io("InvalidAttr","Attribute '"+r+"' is repeated.",Fo(n[t]));i[r]=1}return!0}function Lo(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 Oo(t){return No(t)}function Uo(t){return No(t)}function jo(t,e){const n=t.substring(0,e).split(/\r?\n/);return{line:n.length,col:n[n.length-1].length+1}}function Fo(t){return t.startIndex+t[1].length}const Vo={cent:"¢",pound:"£",curren:"¤",yen:"¥",euro:"€",dollar:"$",euro:"€",fnof:"ƒ",inr:"₹",af:"؋",birr:"ብር",peso:"₱",rub:"₽",won:"₩",yuan:"¥",cedil:"¸"},Ro={amp:"&",apos:"'",gt:">",lt:"<",quot:'"'},Yo={nbsp:" ",copy:"©",reg:"®",trade:"™",mdash:"—",ndash:"–",hellip:"…",laquo:"«",raquo:"»",lsquo:"‘",rsquo:"’",ldquo:"“",rdquo:"”",bull:"•",para:"¶",sect:"§",deg:"°",frac12:"½",frac14:"¼",frac34:"¾"},Bo=new Set("!?\\\\/[]$%{}^&*()<>|+");function Ho(t){if("#"===t[0])throw new Error(`[EntityReplacer] Invalid character '#' in entity name: "${t}"`);for(const e of t)if(Bo.has(e))throw new Error(`[EntityReplacer] Invalid character '${e}' in entity name: "${t}"`);return t}function qo(...t){const e=Object.create(null);for(const n of t)if(n)for(const t of Object.keys(n)){const i=n[t];if("string"==typeof i)e[t]=i;else if(i&&"object"==typeof i&&void 0!==i.val){const n=i.val;"string"==typeof n&&(e[t]=n)}}return e}const Xo="external",Wo="base",Zo="all";const Go=Object.freeze({allow:0,leave:1,remove:2,throw:3}),Jo=new Set([9,10,13]);class Ko{constructor(t={}){var e;this._limit=t.limit||{},this._maxTotalExpansions=this._limit.maxTotalExpansions||0,this._maxExpandedLength=this._limit.maxExpandedLength||0,this._postCheck="function"==typeof t.postCheck?t.postCheck:t=>t,this._limitTiers=(e=this._limit.applyLimitsTo??Xo)&&e!==Xo?e===Zo?new Set([Zo]):e===Wo?new Set([Wo]):Array.isArray(e)?new Set(e):new Set([Xo]):new Set([Xo]),this._numericAllowed=t.numericAllowed??!0,this._baseMap=qo(Ro,t.namedEntities||null),this._externalMap=Object.create(null),this._inputMap=Object.create(null),this._totalExpansions=0,this._expandedLength=0,this._removeSet=new Set(t.remove&&Array.isArray(t.remove)?t.remove:[]),this._leaveSet=new Set(t.leave&&Array.isArray(t.leave)?t.leave:[]);const n=function(t){if(!t)return{xmlVersion:1,onLevel:Go.allow,nullLevel:Go.remove};const e=1.1===t.xmlVersion?1.1:1,n=Go[t.onNCR]??Go.allow,i=Go[t.nullNCR]??Go.remove;return{xmlVersion:e,onLevel:n,nullLevel:Math.max(i,Go.remove)}}(t.ncr);this._ncrXmlVersion=n.xmlVersion,this._ncrOnLevel=n.onLevel,this._ncrNullLevel=n.nullLevel}setExternalEntities(t){if(t)for(const e of Object.keys(t))Ho(e);this._externalMap=qo(t)}addExternalEntity(t,e){Ho(t),"string"==typeof e&&-1===e.indexOf("&")&&(this._externalMap[t]=e)}addInputEntities(t){this._totalExpansions=0,this._expandedLength=0,this._inputMap=qo(t)}reset(){return this._inputMap=Object.create(null),this._totalExpansions=0,this._expandedLength=0,this}setXmlVersion(t){this._ncrXmlVersion=1.1===t?1.1:1}decode(t){if("string"!=typeof t||0===t.length)return t;const e=t,n=[],i=t.length;let r=0,s=0;const o=this._maxTotalExpansions>0,a=this._maxExpandedLength>0,l=o||a;for(;s<i;){if(38!==t.charCodeAt(s)){s++;continue}let e=s+1;for(;e<i&&59!==t.charCodeAt(e)&&e-s<=32;)e++;if(e>=i||59!==t.charCodeAt(e)){s++;continue}const h=t.slice(s+1,e);if(0===h.length){s++;continue}let u,c;if(this._removeSet.has(h))u="",void 0===c&&(c=Xo);else{if(this._leaveSet.has(h)){s++;continue}if(35===h.charCodeAt(0)){const t=this._resolveNCR(h);if(void 0===t){s++;continue}u=t,c=Wo}else{const t=this._resolveName(h);u=t?.value,c=t?.tier}}if(void 0!==u){if(s>r&&n.push(t.slice(r,s)),n.push(u),r=e+1,s=r,l&&this._tierCounts(c)){if(o&&(this._totalExpansions++,this._totalExpansions>this._maxTotalExpansions))throw new Error(`[EntityReplacer] Entity expansion count limit exceeded: ${this._totalExpansions} > ${this._maxTotalExpansions}`);if(a){const t=u.length-(h.length+2);if(t>0&&(this._expandedLength+=t,this._expandedLength>this._maxExpandedLength))throw new Error(`[EntityReplacer] Expanded content length limit exceeded: ${this._expandedLength} > ${this._maxExpandedLength}`)}}}else s++}r<i&&n.push(t.slice(r));const h=0===n.length?t:n.join("");return this._postCheck(h,e)}_tierCounts(t){return!!this._limitTiers.has(Zo)||this._limitTiers.has(t)}_resolveName(t){return t in this._inputMap?{value:this._inputMap[t],tier:Xo}:t in this._externalMap?{value:this._externalMap[t],tier:Xo}:t in this._baseMap?{value:this._baseMap[t],tier:Wo}:void 0}_classifyNCR(t){return 0===t?this._ncrNullLevel:t>=55296&&t<=57343||1===this._ncrXmlVersion&&t>=1&&t<=31&&!Jo.has(t)?Go.remove:-1}_applyNCRAction(t,e,n){switch(t){case Go.allow:return String.fromCodePoint(n);case Go.remove:return"";case Go.leave:return;case Go.throw:throw new Error(`[EntityDecoder] Prohibited numeric character reference &${e}; (U+${n.toString(16).toUpperCase().padStart(4,"0")})`);default:return String.fromCodePoint(n)}}_resolveNCR(t){const e=t.charCodeAt(1);let n;if(n=120===e||88===e?parseInt(t.slice(2),16):parseInt(t.slice(1),10),Number.isNaN(n)||n<0||n>1114111)return;const i=this._classifyNCR(n);if(!this._numericAllowed&&i<Go.remove)return;const r=-1===i?this._ncrOnLevel:Math.max(this._ncrOnLevel,i);return this._applyNCRAction(r,t,n)}}const Qo=t=>So.includes(t)?"__"+t:t,ta={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,entityDecoder:null,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(t,e,n){return t},captureMetaData:!1,maxNestedTags:100,strictReservedNames:!0,jPath:!0,onDangerousProperty:Qo};function ea(t,e){if("string"!=typeof t)return;const n=t.toLowerCase();if(So.some(t=>n===t.toLowerCase()))throw new Error(`[SECURITY] Invalid ${e}: "${t}" is a reserved JavaScript keyword that could cause prototype pollution`);if(Eo.some(t=>n===t.toLowerCase()))throw new Error(`[SECURITY] Invalid ${e}: "${t}" is a reserved JavaScript keyword that could cause prototype pollution`)}function na(t,e){return"boolean"==typeof t?{enabled:t,maxEntitySize:1e4,maxExpansionDepth:1e4,maxTotalExpansions:1/0,maxExpandedLength:1e5,maxEntityCount:1e3,allowedTags:null,tagFilter:null,appliesTo:"all"}:"object"==typeof t&&null!==t?{enabled:!1!==t.enabled,maxEntitySize:Math.max(1,t.maxEntitySize??1e4),maxExpansionDepth:Math.max(1,t.maxExpansionDepth??1e4),maxTotalExpansions:Math.max(1,t.maxTotalExpansions??1/0),maxExpandedLength:Math.max(1,t.maxExpandedLength??1e5),maxEntityCount:Math.max(1,t.maxEntityCount??1e3),allowedTags:t.allowedTags??null,tagFilter:t.tagFilter??null,appliesTo:t.appliesTo??"all"}:na(!0)}const ia=function(t){const e=Object.assign({},ta,t),n=[{value:e.attributeNamePrefix,name:"attributeNamePrefix"},{value:e.attributesGroupName,name:"attributesGroupName"},{value:e.textNodeName,name:"textNodeName"},{value:e.cdataPropName,name:"cdataPropName"},{value:e.commentPropName,name:"commentPropName"}];for(const{value:t,name:e}of n)t&&ea(t,e);return null===e.onDangerousProperty&&(e.onDangerousProperty=Qo),e.processEntities=na(e.processEntities,e.htmlEntities),e.unpairedTagsSet=new Set(e.unpairedTags),e.stopNodes&&Array.isArray(e.stopNodes)&&(e.stopNodes=e.stopNodes.map(t=>"string"==typeof t&&t.startsWith("*.")?".."+t.substring(2):t)),e};let ra;ra="function"!=typeof Symbol?"@@xmlMetadata":Symbol("XML Node Metadata");class sa{constructor(t){this.tagname=t,this.child=[],this[":@"]=Object.create(null)}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][ra]={startIndex:e})}static getMetaDataSymbol(){return ra}}class oa{constructor(t){this.suppressValidationErr=!t,this.options=t}readDocType(t,e){const n=Object.create(null);let i=0;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,s=!1,o=!1,a="";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]?s=!0:a+=t[e];else{if(s&&la(t,"!ENTITY",e)){let r,s;if(e+=7,[r,s,e]=this.readEntityExp(t,e+1,this.suppressValidationErr),-1===s.indexOf("&")){if(!1!==this.options.enabled&&null!=this.options.maxEntityCount&&i>=this.options.maxEntityCount)throw new Error(`Entity count (${i+1}) exceeds maximum allowed (${this.options.maxEntityCount})`);n[r]=s,i++}}else if(s&&la(t,"!ELEMENT",e)){e+=8;const{index:n}=this.readElementExp(t,e+1);e=n}else if(s&&la(t,"!ATTLIST",e))e+=8;else if(s&&la(t,"!NOTATION",e)){e+=9;const{index:n}=this.readNotationExp(t,e+1,this.suppressValidationErr);e=n}else{if(!la(t,"!--",e))throw new Error("Invalid DOCTYPE");o=!0}r++,a=""}if(0!==r)throw new Error("Unclosed DOCTYPE")}return{entities:n,i:e}}readEntityExp(t,e){const n=e=aa(t,e);for(;e<t.length&&!/\s/.test(t[e])&&'"'!==t[e]&&"'"!==t[e];)e++;let i=t.substring(n,e);if(ha(i),e=aa(t,e),!this.suppressValidationErr){if("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="";if([e,r]=this.readIdentifierVal(t,e,"entity"),!1!==this.options.enabled&&null!=this.options.maxEntitySize&&r.length>this.options.maxEntitySize)throw new Error(`Entity "${i}" size (${r.length}) exceeds maximum allowed size (${this.options.maxEntitySize})`);return[i,r,--e]}readNotationExp(t,e){const n=e=aa(t,e);for(;e<t.length&&!/\s/.test(t[e]);)e++;let i=t.substring(n,e);!this.suppressValidationErr&&ha(i),e=aa(t,e);const r=t.substring(e,e+6).toUpperCase();if(!this.suppressValidationErr&&"SYSTEM"!==r&&"PUBLIC"!==r)throw new Error(`Expected SYSTEM or PUBLIC, found "${r}"`);e+=r.length,e=aa(t,e);let s=null,o=null;if("PUBLIC"===r)[e,s]=this.readIdentifierVal(t,e,"publicIdentifier"),'"'!==t[e=aa(t,e)]&&"'"!==t[e]||([e,o]=this.readIdentifierVal(t,e,"systemIdentifier"));else if("SYSTEM"===r&&([e,o]=this.readIdentifierVal(t,e,"systemIdentifier"),!this.suppressValidationErr&&!o))throw new Error("Missing mandatory system identifier for SYSTEM notation");return{notationName:i,publicIdentifier:s,systemIdentifier:o,index:--e}}readIdentifierVal(t,e,n){let i="";const r=t[e];if('"'!==r&&"'"!==r)throw new Error(`Expected quoted string, found "${r}"`);const s=++e;for(;e<t.length&&t[e]!==r;)e++;if(i=t.substring(s,e),t[e]!==r)throw new Error(`Unterminated ${n} value`);return[++e,i]}readElementExp(t,e){const n=e=aa(t,e);for(;e<t.length&&!/\s/.test(t[e]);)e++;let i=t.substring(n,e);if(!this.suppressValidationErr&&!No(i))throw new Error(`Invalid element name: "${i}"`);let r="";if("E"===t[e=aa(t,e)]&&la(t,"MPTY",e))e+=4;else if("A"===t[e]&&la(t,"NY",e))e+=2;else if("("===t[e]){const n=++e;for(;e<t.length&&")"!==t[e];)e++;if(r=t.substring(n,e),")"!==t[e])throw new Error("Unterminated content model")}else if(!this.suppressValidationErr)throw new Error(`Invalid Element Expression, found "${t[e]}"`);return{elementName:i,contentModel:r.trim(),index:e}}readAttlistExp(t,e){let n=e=aa(t,e);for(;e<t.length&&!/\s/.test(t[e]);)e++;let i=t.substring(n,e);for(ha(i),n=e=aa(t,e);e<t.length&&!/\s/.test(t[e]);)e++;let r=t.substring(n,e);if(!ha(r))throw new Error(`Invalid attribute name: "${r}"`);e=aa(t,e);let s="";if("NOTATION"===t.substring(e,e+8).toUpperCase()){if(s="NOTATION","("!==t[e=aa(t,e+=8)])throw new Error(`Expected '(', found "${t[e]}"`);e++;let n=[];for(;e<t.length&&")"!==t[e];){const i=e;for(;e<t.length&&"|"!==t[e]&&")"!==t[e];)e++;let r=t.substring(i,e);if(r=r.trim(),!ha(r))throw new Error(`Invalid notation name: "${r}"`);n.push(r),"|"===t[e]&&(e++,e=aa(t,e))}if(")"!==t[e])throw new Error("Unterminated list of notations");e++,s+=" ("+n.join("|")+")"}else{const n=e;for(;e<t.length&&!/\s/.test(t[e]);)e++;s+=t.substring(n,e);const i=["CDATA","ID","IDREF","IDREFS","ENTITY","ENTITIES","NMTOKEN","NMTOKENS"];if(!this.suppressValidationErr&&!i.includes(s.toUpperCase()))throw new Error(`Invalid attribute type: "${s}"`)}e=aa(t,e);let o="";return"#REQUIRED"===t.substring(e,e+8).toUpperCase()?(o="#REQUIRED",e+=8):"#IMPLIED"===t.substring(e,e+7).toUpperCase()?(o="#IMPLIED",e+=7):[e,o]=this.readIdentifierVal(t,e,"ATTLIST"),{elementName:i,attributeName:r,attributeType:s,defaultValue:o,index:e}}}const aa=(t,e)=>{for(;e<t.length&&/\s/.test(t[e]);)e++;return e};function la(t,e,n){for(let i=0;i<e.length;i++)if(e[i]!==t[n+i+1])return!1;return!0}function ha(t){if(No(t))return t;throw new Error(`Invalid entity name ${t}`)}const ua=/^[-+]?0x[a-fA-F0-9]+$/,ca=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,da={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0,infinity:"original"};function fa(t,e={}){if(e=Object.assign({},da,e),!t||"string"!=typeof t)return t;let n=t.trim();if(0===n.length)return t;if(void 0!==e.skipLike&&e.skipLike.test(n))return t;if("0"===n)return 0;if(e.hex&&ua.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(isFinite(n)){if(n.includes("e")||n.includes("E"))return function(t,e,n){if(!n.eNotation)return t;const i=e.match(pa);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)&&o.length>0?n.leadingZeros&&!a?(e=(i[1]||"")+i[3],Number(e)):t:Number(e)}return t}(t,n,e);{const i=ca.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}}return function(t,e,n){const i=e===1/0;switch(n.infinity.toLowerCase()){case"null":return null;case"infinity":return e;case"string":return i?"Infinity":"-Infinity";default:return t}}(t,Number(n),e)}const pa=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;class _a{constructor(t,e={},n){this.pattern=t,this.separator=e.separator||".",this.segments=this._parse(t),this.data=n,this._hasDeepWildcard=this.segments.some(t=>"deep-wildcard"===t.type),this._hasAttributeCondition=this.segments.some(t=>void 0!==t.attrName),this._hasPositionSelector=this.segments.some(t=>void 0!==t.position)}_parse(t){const e=[];let n=0,i="";for(;n<t.length;)t[n]===this.separator?n+1<t.length&&t[n+1]===this.separator?(i.trim()&&(e.push(this._parseSegment(i.trim())),i=""),e.push({type:"deep-wildcard"}),n+=2):(i.trim()&&e.push(this._parseSegment(i.trim())),i="",n++):(i+=t[n],n++);return i.trim()&&e.push(this._parseSegment(i.trim())),e}_parseSegment(t){const e={type:"tag"};let n=null,i=t;const r=t.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);if(r&&(i=r[1]+r[3],r[2])){const t=r[2].slice(1,-1);t&&(n=t)}let s,o,a=i;if(i.includes("::")){const e=i.indexOf("::");if(s=i.substring(0,e).trim(),a=i.substring(e+2).trim(),!s)throw new Error(`Invalid namespace in pattern: ${t}`)}let l=null;if(a.includes(":")){const t=a.lastIndexOf(":"),e=a.substring(0,t).trim(),n=a.substring(t+1).trim();["first","last","odd","even"].includes(n)||/^nth\(\d+\)$/.test(n)?(o=e,l=n):o=a}else o=a;if(!o)throw new Error(`Invalid segment pattern: ${t}`);if(e.tag=o,s&&(e.namespace=s),n)if(n.includes("=")){const t=n.indexOf("=");e.attrName=n.substring(0,t).trim(),e.attrValue=n.substring(t+1).trim()}else e.attrName=n.trim();if(l){const t=l.match(/^nth\((\d+)\)$/);t?(e.position="nth",e.positionValue=parseInt(t[1],10)):e.position=l}return e}get length(){return this.segments.length}hasDeepWildcard(){return this._hasDeepWildcard}hasAttributeCondition(){return this._hasAttributeCondition}hasPositionSelector(){return this._hasPositionSelector}toString(){return this.pattern}}class ga{constructor(){this._byDepthAndTag=new Map,this._wildcardByDepth=new Map,this._deepWildcards=[],this._patterns=new Set,this._sealed=!1}add(t){if(this._sealed)throw new TypeError("ExpressionSet is sealed. Create a new ExpressionSet to add more expressions.");if(this._patterns.has(t.pattern))return this;if(this._patterns.add(t.pattern),t.hasDeepWildcard())return this._deepWildcards.push(t),this;const e=t.length,n=t.segments[t.segments.length-1],i=n?.tag;if(i&&"*"!==i){const n=`${e}:${i}`;this._byDepthAndTag.has(n)||this._byDepthAndTag.set(n,[]),this._byDepthAndTag.get(n).push(t)}else this._wildcardByDepth.has(e)||this._wildcardByDepth.set(e,[]),this._wildcardByDepth.get(e).push(t);return this}addAll(t){for(const e of t)this.add(e);return this}has(t){return this._patterns.has(t.pattern)}get size(){return this._patterns.size}seal(){return this._sealed=!0,this}get isSealed(){return this._sealed}matchesAny(t){return null!==this.findMatch(t)}findMatch(t){const e=t.getDepth(),n=`${e}:${t.getCurrentTag()}`,i=this._byDepthAndTag.get(n);if(i)for(let e=0;e<i.length;e++)if(t.matches(i[e]))return i[e];const r=this._wildcardByDepth.get(e);if(r)for(let e=0;e<r.length;e++)if(t.matches(r[e]))return r[e];for(let e=0;e<this._deepWildcards.length;e++)if(t.matches(this._deepWildcards[e]))return this._deepWildcards[e];return null}}class ma{constructor(t){this._matcher=t}get separator(){return this._matcher.separator}getCurrentTag(){const t=this._matcher.path;return t.length>0?t[t.length-1].tag:void 0}getCurrentNamespace(){const t=this._matcher.path;return t.length>0?t[t.length-1].namespace:void 0}getAttrValue(t){const e=this._matcher.path;if(0!==e.length)return e[e.length-1].values?.[t]}hasAttr(t){const e=this._matcher.path;if(0===e.length)return!1;const n=e[e.length-1];return void 0!==n.values&&t in n.values}getPosition(){const t=this._matcher.path;return 0===t.length?-1:t[t.length-1].position??0}getCounter(){const t=this._matcher.path;return 0===t.length?-1:t[t.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this._matcher.path.length}toString(t,e=!0){return this._matcher.toString(t,e)}toArray(){return this._matcher.path.map(t=>t.tag)}matches(t){return this._matcher.matches(t)}matchesAny(t){return t.matchesAny(this._matcher)}}class ya{constructor(t={}){this.separator=t.separator||".",this.path=[],this.siblingStacks=[],this._pathStringCache=null,this._view=new ma(this)}push(t,e=null,n=null){this._pathStringCache=null,this.path.length>0&&(this.path[this.path.length-1].values=void 0);const i=this.path.length;this.siblingStacks[i]||(this.siblingStacks[i]=new Map);const r=this.siblingStacks[i],s=n?`${n}:${t}`:t,o=r.get(s)||0;let a=0;for(const t of r.values())a+=t;r.set(s,o+1);const l={tag:t,position:a,counter:o};null!=n&&(l.namespace=n),null!=e&&(l.values=e),this.path.push(l)}pop(){if(0===this.path.length)return;this._pathStringCache=null;const t=this.path.pop();return this.siblingStacks.length>this.path.length+1&&(this.siblingStacks.length=this.path.length+1),t}updateCurrent(t){if(this.path.length>0){const e=this.path[this.path.length-1];null!=t&&(e.values=t)}}getCurrentTag(){return this.path.length>0?this.path[this.path.length-1].tag:void 0}getCurrentNamespace(){return this.path.length>0?this.path[this.path.length-1].namespace:void 0}getAttrValue(t){if(0!==this.path.length)return this.path[this.path.length-1].values?.[t]}hasAttr(t){if(0===this.path.length)return!1;const e=this.path[this.path.length-1];return void 0!==e.values&&t in e.values}getPosition(){return 0===this.path.length?-1:this.path[this.path.length-1].position??0}getCounter(){return 0===this.path.length?-1:this.path[this.path.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this.path.length}toString(t,e=!0){const n=t||this.separator;if(n===this.separator&&!0===e){if(null!==this._pathStringCache)return this._pathStringCache;const t=this.path.map(t=>t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(n);return this._pathStringCache=t,t}return this.path.map(t=>e&&t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(n)}toArray(){return this.path.map(t=>t.tag)}reset(){this._pathStringCache=null,this.path=[],this.siblingStacks=[]}matches(t){const e=t.segments;return 0!==e.length&&(t.hasDeepWildcard()?this._matchWithDeepWildcard(e):this._matchSimple(e))}_matchSimple(t){if(this.path.length!==t.length)return!1;for(let e=0;e<t.length;e++)if(!this._matchSegment(t[e],this.path[e],e===this.path.length-1))return!1;return!0}_matchWithDeepWildcard(t){let e=this.path.length-1,n=t.length-1;for(;n>=0&&e>=0;){const i=t[n];if("deep-wildcard"===i.type){if(n--,n<0)return!0;const i=t[n];let r=!1;for(let t=e;t>=0;t--)if(this._matchSegment(i,this.path[t],t===this.path.length-1)){e=t-1,n--,r=!0;break}if(!r)return!1}else{if(!this._matchSegment(i,this.path[e],e===this.path.length-1))return!1;e--,n--}}return n<0}_matchSegment(t,e,n){if("*"!==t.tag&&t.tag!==e.tag)return!1;if(void 0!==t.namespace&&"*"!==t.namespace&&t.namespace!==e.namespace)return!1;if(void 0!==t.attrName){if(!n)return!1;if(!e.values||!(t.attrName in e.values))return!1;if(void 0!==t.attrValue&&String(e.values[t.attrName])!==String(t.attrValue))return!1}if(void 0!==t.position){if(!n)return!1;const i=e.counter??0;if("first"===t.position&&0!==i)return!1;if("odd"===t.position&&i%2!=1)return!1;if("even"===t.position&&i%2!=0)return!1;if("nth"===t.position&&i!==t.positionValue)return!1}return!0}matchesAny(t){return t.matchesAny(this)}snapshot(){return{path:this.path.map(t=>({...t})),siblingStacks:this.siblingStacks.map(t=>new Map(t))}}restore(t){this._pathStringCache=null,this.path=t.path.map(t=>({...t})),this.siblingStacks=t.siblingStacks.map(t=>new Map(t))}readOnly(){return this._view}}function va(t,e){if(!t)return{};const n=e.attributesGroupName?t[e.attributesGroupName]:t;if(!n)return{};const i={};for(const t in n)if(t.startsWith(e.attributeNamePrefix)){i[t.substring(e.attributeNamePrefix.length)]=n[t]}else i[t]=n[t];return i}function ba(t){if(!t||"string"!=typeof t)return;const e=t.indexOf(":");if(-1!==e&&e>0){const n=t.substring(0,e);if("xmlns"!==n)return n}}class xa{constructor(t){var e;this.options=t,this.currentNode=null,this.tagsNodeStack=[],this.parseXml=Ma,this.parseTextData=wa,this.resolveNameSpace=Na,this.buildAttributesMap=Ea,this.isItStopNode=Ca,this.replaceEntitiesValue=Aa,this.readStopNodeData=Pa,this.saveTextToParentTag=ka,this.addChild=Ta,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,this.entityExpansionCount=0,this.currentExpandedLength=0;let n={...Ro};this.options.entityDecoder?this.entityDecoder=this.options.entityDecoder:("object"==typeof this.options.htmlEntities?n=this.options.htmlEntities:!0===this.options.htmlEntities&&(n={...Yo,...Vo}),this.entityDecoder=new Ko({namedEntities:n,numericAllowed:this.options.htmlEntities,limit:{maxTotalExpansions:this.options.processEntities.maxTotalExpansions,maxExpandedLength:this.options.processEntities.maxExpandedLength,applyLimitsTo:this.options.processEntities.appliesTo}})),this.matcher=new ya,this.readonlyMatcher=this.matcher.readOnly(),this.isCurrentNodeStopNode=!1,this.stopNodeExpressionsSet=new ga;const i=this.options.stopNodes;if(i&&i.length>0){for(let t=0;t<i.length;t++){const e=i[t];"string"==typeof e?this.stopNodeExpressionsSet.add(new _a(e)):e instanceof _a&&this.stopNodeExpressionsSet.add(e)}this.stopNodeExpressionsSet.seal()}}}function wa(t,e,n,i,r,s,o){const a=this.options;if(void 0!==t&&(a.trimValues&&!i&&(t=t.trim()),t.length>0)){o||(t=this.replaceEntitiesValue(t,e,n));const i=a.jPath?n.toString():n,l=a.tagValueProcessor(e,t,i,r,s);if(null==l)return t;if(typeof l!=typeof t||l!==t)return l;if(a.trimValues)return La(t,a.parseTagValue,a.numberParseOptions);return t.trim()===t?La(t,a.parseTagValue,a.numberParseOptions):t}}function Na(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 Sa=new RegExp("([^\\s=]+)\\s*(=\\s*(['\"])([\\s\\S]*?)\\3)?","gm");function Ea(t,e,n,i=!1){const r=this.options;if(!0===i||!0!==r.ignoreAttributes&&"string"==typeof t){const i=wo(t,Sa),s=i.length,o={},a=new Array(s);let l=!1;const h={};for(let t=0;t<s;t++){const e=this.resolveNameSpace(i[t][1]),s=i[t][4];if(e.length&&void 0!==s){let i=s;r.trimValues&&(i=i.trim()),i=this.replaceEntitiesValue(i,n,this.readonlyMatcher),a[t]=i,h[e]=i,l=!0}}l&&"object"==typeof e&&e.updateCurrent&&e.updateCurrent(h);const u=r.jPath?e.toString():this.readonlyMatcher;let c=!1;for(let t=0;t<s;t++){const e=this.resolveNameSpace(i[t][1]);if(this.ignoreAttributesFn(e,u))continue;let n=r.attributeNamePrefix+e;if(e.length)if(r.transformAttributeName&&(n=r.transformAttributeName(n)),n=Oa(n,r),void 0!==i[t][4]){const i=a[t],s=r.attributeValueProcessor(e,i,u);o[n]=null==s?i:typeof s!=typeof i||s!==i?s:La(i,r.parseAttributeValue,r.numberParseOptions),c=!0}else r.allowBooleanAttributes&&(o[n]=!0,c=!0)}if(!c)return;if(r.attributesGroupName){const t={};return t[r.attributesGroupName]=o,t}return o}}const Ma=function(t){t=t.replace(/\r\n?/g,"\n");const e=new sa("!xml");let n=e,i="";this.matcher.reset(),this.entityDecoder.reset(),this.entityExpansionCount=0,this.currentExpandedLength=0;const r=this.options,s=new oa(r.processEntities),o=t.length;for(let a=0;a<o;a++){if("<"===t[a]){const l=t.charCodeAt(a+1);if(47===l){const e=za(t,">",a,"Closing Tag is not closed.");let s=t.substring(a+2,e).trim();if(r.removeNSPrefix){const t=s.indexOf(":");-1!==t&&(s=s.substr(t+1))}s=Ia(r.transformTagName,s,"",r).tagName,n&&(i=this.saveTextToParentTag(i,n,this.readonlyMatcher));const o=this.matcher.getCurrentTag();if(s&&r.unpairedTagsSet.has(s))throw new Error(`Unpaired tag can not be used as closing tag: </${s}>`);o&&r.unpairedTagsSet.has(o)&&(this.matcher.pop(),this.tagsNodeStack.pop()),this.matcher.pop(),this.isCurrentNodeStopNode=!1,n=this.tagsNodeStack.pop(),i="",a=e}else if(63===l){let e=Da(t,a,!1,"?>");if(!e)throw new Error("Pi Tag is not closed.");i=this.saveTextToParentTag(i,n,this.readonlyMatcher);const s=this.buildAttributesMap(e.tagExp,this.matcher,e.tagName,!0);if(s){const t=s[this.options.attributeNamePrefix+"version"];this.entityDecoder.setXmlVersion(Number(t)||1)}if(r.ignoreDeclaration&&"?xml"===e.tagName||r.ignorePiTags);else{const t=new sa(e.tagName);t.add(r.textNodeName,""),e.tagName!==e.tagExp&&e.attrExpPresent&&!0!==r.ignoreAttributes&&(t[":@"]=s),this.addChild(n,t,this.readonlyMatcher,a)}a=e.closeIndex+1}else if(33===l&&45===t.charCodeAt(a+2)&&45===t.charCodeAt(a+3)){const e=za(t,"--\x3e",a+4,"Comment is not closed.");if(r.commentPropName){const s=t.substring(a+4,e-2);i=this.saveTextToParentTag(i,n,this.readonlyMatcher),n.add(r.commentPropName,[{[r.textNodeName]:s}])}a=e}else if(33===l&&68===t.charCodeAt(a+2)){const e=s.readDocType(t,a);this.entityDecoder.addInputEntities(e.entities),a=e.i}else if(33===l&&91===t.charCodeAt(a+2)){const e=za(t,"]]>",a,"CDATA is not closed.")-2,s=t.substring(a+9,e);i=this.saveTextToParentTag(i,n,this.readonlyMatcher);let o=this.parseTextData(s,n.tagname,this.readonlyMatcher,!0,!1,!0,!0);null==o&&(o=""),r.cdataPropName?n.add(r.cdataPropName,[{[r.textNodeName]:s}]):n.add(r.textNodeName,o),a=e+2}else{let s=Da(t,a,r.removeNSPrefix);if(!s){const e=t.substring(Math.max(0,a-50),Math.min(o,a+50));throw new Error(`readTagExp returned undefined at position ${a}. Context: "${e}"`)}let l=s.tagName;const h=s.rawTagName;let u=s.tagExp,c=s.attrExpPresent,d=s.closeIndex;if(({tagName:l,tagExp:u}=Ia(r.transformTagName,l,u,r)),r.strictReservedNames&&(l===r.commentPropName||l===r.cdataPropName||l===r.textNodeName||l===r.attributesGroupName))throw new Error(`Invalid tag name: ${l}`);n&&i&&"!xml"!==n.tagname&&(i=this.saveTextToParentTag(i,n,this.readonlyMatcher,!1));const f=n;f&&r.unpairedTagsSet.has(f.tagname)&&(n=this.tagsNodeStack.pop(),this.matcher.pop());let p=!1;u.length>0&&u.lastIndexOf("/")===u.length-1&&(p=!0,"/"===l[l.length-1]?(l=l.substr(0,l.length-1),u=l):u=u.substr(0,u.length-1),c=l!==u);let _,g=null;_=ba(h),l!==e.tagname&&this.matcher.push(l,{},_),l!==u&&c&&(g=this.buildAttributesMap(u,this.matcher,l),g&&va(g,r)),l!==e.tagname&&(this.isCurrentNodeStopNode=this.isItStopNode());const m=a;if(this.isCurrentNodeStopNode){let e="";if(p)a=s.closeIndex;else if(r.unpairedTagsSet.has(l))a=s.closeIndex;else{const n=this.readStopNodeData(t,h,d+1);if(!n)throw new Error(`Unexpected end of ${h}`);a=n.i,e=n.tagContent}const i=new sa(l);g&&(i[":@"]=g),i.add(r.textNodeName,e),this.matcher.pop(),this.isCurrentNodeStopNode=!1,this.addChild(n,i,this.readonlyMatcher,m)}else{if(p){({tagName:l,tagExp:u}=Ia(r.transformTagName,l,u,r));const t=new sa(l);g&&(t[":@"]=g),this.addChild(n,t,this.readonlyMatcher,m),this.matcher.pop(),this.isCurrentNodeStopNode=!1}else{if(r.unpairedTagsSet.has(l)){const t=new sa(l);g&&(t[":@"]=g),this.addChild(n,t,this.readonlyMatcher,m),this.matcher.pop(),this.isCurrentNodeStopNode=!1,a=s.closeIndex;continue}{const t=new sa(l);if(this.tagsNodeStack.length>r.maxNestedTags)throw new Error("Maximum nested tags exceeded");this.tagsNodeStack.push(n),g&&(t[":@"]=g),this.addChild(n,t,this.readonlyMatcher,m),n=t}}i="",a=d}}}else i+=t[a]}return e.child};function Ta(t,e,n,i){this.options.captureMetaData||(i=void 0);const r=this.options.jPath?n.toString():n,s=this.options.updateTag(e.tagname,r,e[":@"]);!1===s||("string"==typeof s?(e.tagname=s,t.addChild(e,i)):t.addChild(e,i))}function Aa(t,e,n){const i=this.options.processEntities;if(!i||!i.enabled)return t;if(i.allowedTags){const r=this.options.jPath?n.toString():n;if(!(Array.isArray(i.allowedTags)?i.allowedTags.includes(e):i.allowedTags(e,r)))return t}if(i.tagFilter){const r=this.options.jPath?n.toString():n;if(!i.tagFilter(e,r))return t}return this.entityDecoder.decode(t)}function ka(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 Ca(){return 0!==this.stopNodeExpressionsSet.size&&this.matcher.matchesAny(this.stopNodeExpressionsSet)}function za(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=t.indexOf(e,n);if(-1===r)throw new Error(i);return r}function Da(t,e,n,i=">"){const r=function(t,e,n=">"){let i=0;const r=[],s=t.length,o=n.charCodeAt(0),a=n.length>1?n.charCodeAt(1):-1;for(let n=e;n<s;n++){const e=t.charCodeAt(n);if(i)e===i&&(i=0);else if(34===e||39===e)i=e;else if(e===o){if(-1===a)return{data:String.fromCharCode(...r),index:n};if(t.charCodeAt(n+1)===a)return{data:String.fromCharCode(...r),index:n}}else if(9===e){r.push(32);continue}r.push(e)}}(t,e+1,i);if(!r)return;let s=r.data;const o=r.index,a=s.search(/\s/);let l=s,h=!0;-1!==a&&(l=s.substring(0,a),s=s.substring(a+1).trimStart());const u=l;if(n){const t=l.indexOf(":");-1!==t&&(l=l.substr(t+1),h=l!==r.data.substr(t+1))}return{tagName:l,tagExp:s,closeIndex:o,attrExpPresent:h,rawTagName:u}}function Pa(t,e,n){const i=n;let r=1;const s=t.length;for(;n<s;n++)if("<"===t[n]){const s=t.charCodeAt(n+1);if(47===s){const s=$a(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(63===s){n=za(t,"?>",n+1,"StopNode is not closed.")}else if(33===s&&45===t.charCodeAt(n+2)&&45===t.charCodeAt(n+3)){n=za(t,"--\x3e",n+3,"StopNode is not closed.")}else if(33===s&&91===t.charCodeAt(n+2)){n=za(t,"]]>",n,"StopNode is not closed.")-2}else{const i=Da(t,n,">");if(i){(i&&i.tagName)===e&&"/"!==i.tagExp[i.tagExp.length-1]&&r++,n=i.closeIndex}}}}function La(t,e,n){if(e&&"string"==typeof t){const e=t.trim();return"true"===e||"false"!==e&&fa(t,n)}return void 0!==t?t:""}function Ia(t,e,n,i){if(t){const i=t(e);n===e&&(n=i),e=i}return{tagName:e=Oa(e,i),tagExp:n}}function Oa(t,e){if(Eo.includes(t))throw new Error(`[SECURITY] Invalid name: "${t}" is a reserved JavaScript keyword that could cause prototype pollution`);return So.includes(t)?e.onDangerousProperty(t):t}const Ua=sa.getMetaDataSymbol();function ja(t,e){if(!t||"object"!=typeof t)return{};if(!e)return t;const n={};for(const i in t)if(i.startsWith(e)){n[i.substring(e.length)]=t[i]}else n[i]=t[i];return n}function Fa(t,e,n,i){return Va(t,e,n,i)}function Va(t,e,n,i){let r;const s={};for(let o=0;o<t.length;o++){const a=t[o],l=Ra(a);if(void 0!==l&&l!==e.textNodeName){const t=ja(a[":@"]||{},e.attributeNamePrefix);n.push(l,t)}if(l===e.textNodeName)void 0===r?r=a[l]:r+=""+a[l];else{if(void 0===l)continue;if(a[l]){let t=Va(a[l],e,n,i);const r=Ba(t,e);if(a[":@"]?Ya(t,a[":@"],i,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!==a[Ua]&&"object"==typeof t&&null!==t&&(t[Ua]=a[Ua]),void 0!==s[l]&&Object.prototype.hasOwnProperty.call(s,l))Array.isArray(s[l])||(s[l]=[s[l]]),s[l].push(t);else{const n=e.jPath?i.toString():i;e.isArray(l,n,r)?s[l]=[t]:s[l]=t}void 0!==l&&l!==e.textNodeName&&n.pop()}}}return"string"==typeof r?r.length>0&&(s[e.textNodeName]=r):void 0!==r&&(s[e.textNodeName]=r),s}function Ra(t){const e=Object.keys(t);for(let t=0;t<e.length;t++){const n=e[t];if(":@"!==n)return n}}function Ya(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],a=s.startsWith(i.attributeNamePrefix)?s.substring(i.attributeNamePrefix.length):s,l=i.jPath?n.toString()+"."+a:n;i.isArray(s,l,!0,!0)?t[s]=[e[s]]:t[s]=e[s]}}}function Ba(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 Ha{constructor(t){this.externalEntities={},this.options=ia(t)}parse(t,e){if("string"!=typeof t&&t.toString)t=t.toString();else if("string"!=typeof t)throw new Error("XML data is accepted in String or Bytes[] form.");if(e){!0===e&&(e={});const n=function(t,e){e=Object.assign({},Mo,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(To(t[s]))continue;return Io("InvalidChar","char '"+t[s]+"' is not expected.",jo(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,jo(t,s))}const h=$o(t,s);if(!1===h)return Io("InvalidAttr","Attributes for '"+l+"' have open quote.",jo(t,s));let u=h.value;if(s=h.index,"/"===u[u.length-1]){const n=s-u.length;u=u.substring(0,u.length-1);const r=Po(u,e);if(!0!==r)return Io(r.err.code,r.err.msg,jo(t,n+r.err.line));i=!0}else if(a){if(!h.tagClosed)return Io("InvalidTag","Closing tag '"+l+"' doesn't have proper closing.",jo(t,s));if(u.trim().length>0)return Io("InvalidTag","Closing tag '"+l+"' can't have attributes or invalid starting.",jo(t,o));if(0===n.length)return Io("InvalidTag","Closing tag '"+l+"' has not been opened.",jo(t,o));{const e=n.pop();if(l!==e.tagName){let n=jo(t,e.tagStartPos);return Io("InvalidTag","Expected closing tag '"+e.tagName+"' (opened in line "+n.line+", col "+n.col+") instead of closing tag '"+l+"'.",jo(t,o))}0==n.length&&(r=!0)}}else{const a=Po(u,e);if(!0!==a)return Io(a.err.code,a.err.msg,jo(t,s-u.length+a.err.line));if(!0===r)return Io("InvalidXml","Multiple possible root nodes found.",jo(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=Lo(t,s);if(-1==e)return Io("InvalidChar","char '&' is not expected.",jo(t,s));s=e}else if(!0===r&&!To(t[s]))return Io("InvalidXml","Extra text at the end",jo(t,s));"<"===t[s]&&s--}}}return i?1==n.length?Io("InvalidTag","Unclosed tag '"+n[0].tagName+"'.",jo(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 xa(this.options);n.entityDecoder.setExternalEntities(this.externalEntities);const i=n.parseXml(t);return this.options.preserveOrder||void 0===i?i:Fa(i,this.options,n.matcher,n.readonlyMatcher)}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 sa.getMetaDataSymbol()}}function qa(t){return!r.has(t,"children")}function Xa(t,e,n){let i=[];return function r(s){qa(s)?e&&s!=t&&i.push(s):(n&&s!=t&&i.push(s),s.children.forEach(r))}(t),i}var Wa=Object.freeze({__proto__:null,addChild:function(t,e){return t.children?t.children.push(e):t.children=[e],t},assignAttributes:function(t){r.each(this.nodes.descendants(),function(e){e.data&&e.data.name in t&&(e.annotations=t[e.data.name])})},clearInternalNodes:function(t){t||this.nodes.each(t=>{qa(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])})},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},getInternals:function(){return r.filter(this.nodes.descendants(),t=>r.has(t,"children"))},getNodeByName:function(t){return r.filter(this.nodes.descendants(),e=>e.data.name==t)[0]},getNodes:function(){return this.nodes},getRootNode:function(){return this.nodes},getTips:function(){return r.filter(this.nodes.descendants(),t=>!r.has(t,"children"))},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},isLeafNode:qa,selectAllDescendants:Xa,updateKeyName:function(t,e){return this.nodes.each(function(n){t in n&&(e&&(n[e]=n[t]),delete n[t])}),this}});function Za(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=u,"children"in t?t.bootstrap_values=u:t.name=u,t.attribute=c,"["==i&&d.includes("&&NHX")?d.split(":").slice(1).forEach(e=>{const[i,r]=e.split("=");t[i]=n.test(r)?+r:r}):t.annotation=d,u="",c="",d=""}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 h=0,u="",c="",d="",f=null,p={"'":1,'"':1},_={name:"root"};s.push(_);for(var g=/\s/,m=0;m<t.length;m++)try{var y=t[m];switch(h){case 0:"("==y&&(o(),h=1);break;case 1:case 3:if(":"==y)h=3;else if(","==y||")"==y)try{a(),h=1,","==y&&o()}catch(t){return l(m)}else if("("==y){if(u.length>0)return l(m);o()}else{if(y in p){if(1==h&&0===u.length&&0===c.length&&0===d.length){h=2,f=y;continue}return l(m)}if(y==i){if(d.length)return l(m);h=4}else if(3==h)c+=y;else{if(g.test(y))continue;if(";"==y){m=t.length;break}u+=y}}break;case 2:if(y==f){if(m<t.length-1&&t[m+1]==f){m++,u+=f;continue}f=0,h=1;continue}u+=y;break;case 4:if(y==r)h=3;else{if(y==i)return l(m);d+=y}}}catch(t){return l(m)}return 1!=s.length?l(t.length-1):{json:_,error:null}}function Ga(t,e){let n=this;t||(t=t=>"");let i=[];return t=t||"",function e(r){if(r.notshown)return;if(qa(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 Ja(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 Ka(t,e,n){r.each(t.getTips(),t=>{t.data.test=n.matrix[t.data.name]})}function Qa(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")),Za(s[0])}var tl=Object.freeze({__proto__:null,default:Qa,loadAnnotations:Ka,parseAnnotations:Ja});function el(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]=el(s);else{if(void 0===e[o].push){var a=e[o];e[o]=[],e[o].push(a)}e[o].push(el(s))}}return e}var nl=function(t,e){var n;if("string"==typeof t)if(DOMParser){t=(new DOMParser).parseFromString(t,"text/xml")}else{t=(new Ha).parse(t)}var i=(t=el(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 il={nexml:function(t,e){return new Ha({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:nl,nexus:Qa,nwk:Za,nhx:Za,beast:function(t,e){e.left_delimiter="[",e.right_delimiter="]";const n=Za(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 rl(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 sl(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 ol(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 al(t){return rl(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 ll(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 hl=Object.freeze({__proto__:null,pathToRoot:function(t){let e=[];for(;t;)e.push(t),t=t.parent;return e},reroot:function(t,e){if(!(t instanceof ji))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=ji({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(),h=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-h,t.data.__mapped_bl=h,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 ji({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;Ft(this.display.container).select("svg").remove();let e=this.display.selection_attribute_name;t["css-classes"]=Object.assign({},this.display.css_classes),delete this.display;let n=this.render(t);n.selectionLabel(e),n.update(),Ft(n.container).node().appendChild(n.show()),Ft(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]}});function ul(t){return t.y}function cl(t){return t.x}function dl(t,e,n){return{x:n+t*Math.sin(e),y:n+t*Math.cos(e)}}function fl(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=dl(t.radius,t.angle,i);return t.x=o.x,t.y=o.y,t}function pl(t,e){var n=dl(e[0].radius,e[0].angle,t),i=dl(e[0].radius,e[1].angle,t);return"M "+ul(n)+","+cl(n)+" A "+e[0].radius+","+e[0].radius+" 0,0, "+(e[1].angle>e[0].angle?1:0)+" "+ul(i)+","+cl(i)+" L "+ul(e[1])+","+cl(e[1])}function _l(t,e,n){var i=dl(t.target.radius+(t.source.radius-t.target.radius)*e,t.target.angle,n);return{x:ul(i),y:cl(i)}}var gl=no().x(function(t){return ul(t)}).y(function(t){return cl(t)}).curve(function(t){return new oo(t,0)});function ml(t,e){return{x:ul(t.target)+(ul(t.source)-ul(t.target))*e,y:cl(t.target)}}function yl(t){return t.children&&0!==t.children.length?t.children.reduce((t,e)=>t+yl(e),0):1}function vl(t,e,n,i,r){r=r||0,t._unrooted_x=0,t._unrooted_y=0,bl(t,0,2*Math.PI);let s=1/0,o=-1/0,a=1/0,l=-1/0;t.each(t=>{t._unrooted_x<s&&(s=t._unrooted_x),t._unrooted_x>o&&(o=t._unrooted_x),t._unrooted_y<a&&(a=t._unrooted_y),t._unrooted_y>l&&(l=t._unrooted_y)});let h=n-2*r,u=i-2*r;h<100&&(h=100),u<100&&(u=100);let c=h/(o-s||1),d=u/(l-a||1),f=Math.min(c,d),p=r+h/2-(s+o)/2*f,_=r+u/2-(a+l)/2*f;t.each(t=>{if(t.y=t._unrooted_x*f+p,t.x=t._unrooted_y*f+_,t.parent){let e=t._unrooted_x-t.parent._unrooted_x,n=t._unrooted_y-t.parent._unrooted_y,i=180*Math.atan2(n,e)/Math.PI,r=i>90||i<-90;t.text_angle=r?i+180:i,t.text_align=r?"end":"start"}else t.text_angle=0,t.text_align="start";t.angle=t.parent?Math.atan2(t._unrooted_y-t.parent._unrooted_y,t._unrooted_x-t.parent._unrooted_x):0,t.radius=null})}function bl(t,e,n){let i=yl(t);if(!t.children||0===t.children.length)return;let r=e;t.children.forEach(e=>{let s=yl(e),o=n*(s/i),a=r+o/2,l=void 0!==e.y?e.y-(t.y||0):1;l<=0&&(l=1),e._unrooted_x=t._unrooted_x+l*Math.cos(a),e._unrooted_y=t._unrooted_y+l*Math.sin(a),bl(e,r,o),r+=o})}function xl(t){return"M "+ul(t[0])+","+cl(t[0])+" L "+ul(t[1])+","+cl(t[1])}function wl(t,e){return{x:ul(t.target)+(ul(t.source)-ul(t.target))*e,y:cl(t.target)+(cl(t.source)-cl(t.target))*e}}function Nl(t){return t.tag||!1}function Sl(t,e){return t[e]||!1}function El(t){return!(t.hidden||Tl(t))}function Ml(t){return t.notshown}function Tl(t){if(t.notshown)return!0;if(void 0!==t.notshown_ancestor)return t.notshown_ancestor;for(let e=t.parent;e;e=e.parent)if(e.notshown)return!0;return!1}function Al(t){t.eachBefore(t=>{t.notshown_ancestor=!!t.parent&&(!!t.parent.notshown||t.parent.notshown_ancestor)})}function kl(t){return t.hasHiddenNodes||!1}function Cl(t){return t.collapsed||!1}function zl(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 $l(t){return qa(t=t.data)?t.name||"":this.showInternalName(t)?t.name:""}var Dl=Object.freeze({__proto__:null,defNodeLabel:$l,drawNode:function(t,e,n){t=Ft(t);var i=qa(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)&&!Cl(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)),this.unrooted())r=r.attr("transform",t=>this.d3PhylotreeSvgRotate(t.text_angle)).attr("text-anchor",t=>t.text_align);else if(this.radial())r=r.attr("transform",t=>this.d3PhylotreeSvgRotate(t.text_angle)+this.d3PhylotreeSvgTranslate(this.alignTips()?this.shiftTip(t):null)).attr("text-anchor",t=>t.text_align);else{const t="right-to-left"==this.options.layout;r=r.attr("text-anchor",t?"end":"start").attr("transform",t=>this.d3PhylotreeSvgTranslate(this.alignTips()?this.shiftTip(t):null))}if(this.alignTips()){s=s.data([e]);const t="right-to-left"==this.options.layout,i=e=>this.radial()?"end"==e.text_align?-1:1:t?-1:1;n?s=s.enter().append("line").classed(this.css_classes["branch-tracer"],!0).merge(s).attr("x1",t=>i(t)*this.nodeBubbleSize(e)).attr("x2",0).attr("y1",0).attr("y2",0).attr("x2",t=>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=>i(t)*this.nodeBubbleSize(e)).attr("y2",0).attr("y1",0).attr("x2",t=>this.shiftTip(t)[0])).attr("transform",t=>this.d3PhylotreeSvgRotate(t.text_angle))}else s.remove();if(this.options["draw-size-bubbles"]){var o=this.nodeBubbleSize(e);if(t.selectAll("circle").data([o]).enter().append("circle").attr("r",function(t){return t}),this.shown_font_size>=5){const t="right-to-left"==this.options.layout;r=r.attr("dx",e=>(this.radial()||this.unrooted()?"end"==e.text_align?-1:1:t?-1:1)*((this.alignTips()?0:o)+.33*this.shown_font_size))}}else if(this.shown_font_size>=5){const t="right-to-left"==this.options.layout;r=r.attr("dx",e=>(this.radial()||this.unrooted()?"end"==e.text_align?-1:1:t?-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},hasHiddenNodes:kl,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];qa(i)||Sl(i,this.selection_attribute_name)||(i[this.selection_attribute_name]=t(i.children))}this.modifySelection((t,e)=>(qa(t.target),t.target[this.selection_attribute_name]))},isNodeCollapsed:Cl,markNotshownSubtrees:Al,nodeCssSelectors:zl,nodeLabel:function(t){return arguments.length?(this._nodeLabel=t||$l,this.update(),this):this._nodeLabel},nodeNotshown:Ml,nodeOrAncestorNotshown:Tl,nodeSpan:function(t){return arguments.length?(this.nodeSpan="string"==typeof t&&"equal"==t?function(t){return 1}:t,this):this.nodeSpan},nodeVisible:El,reclassNode:function(t){let e=this.css_classes[qa(t)?"node":"internal-node"];return Nl(t)&&(e+=" "+this.css_classes["tagged-node"]),Sl(t,this.selection_attribute_name)&&(e+=" "+this.css_classes["selected-node"]),t.parent||(e+=" "+this.css_classes["root-node"]),(Cl(t)||kl(t))&&(e+=" "+this.css_classes["collapsed-node"]),e},shiftTip:function(t){return this.unrooted()?[0,0]:this.radial()?[("end"==t.text_align?-1:1)*(this.radius_pad_for_bubbles-t.radius),0]:"right-to-left"==this.options.layout?[-t.screen_x,0]:[this.right_most_leaf-t.screen_x,0]},showInternalName:function(t){const e=this.internalNames();return!!e&&("function"==typeof e?e(t):e)},updateHasHiddenNodes:function(){let t=this.phylotree.nodes.descendants();for(let e=t.length-1;e>=0;e-=1)qa(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}});function Pl(t){return[t.clade].reduce(function(t,e,n,i){return t+"path."+e+(n<i.length-1?",":"")},"")}var Ll=Object.freeze({__proto__:null,cladeCssSelectors:Pl,updateCollapsedClades:function(t){let e=this.svg.selectAll("."+this.css_classes["tree-container"]);var n=0;let i=e.selectAll(Pl(this.css_classes)).data(this.phylotree.nodes.descendants().filter(t=>Cl(t)&&!Tl(t)),function(t){return t.id||(t.id=++n)}),s=function(){},o=r.noop();this.radial()?(s=no().curve(so).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=no().y(function(t){return t[0]}).x(function(t){return t[1]}).curve(so),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 Il(t){return!(t.target.hidden||Tl(t.target))}function Ol(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 Ul=Object.freeze({__proto__:null,drawEdge:function(t,e,n){t=(t=Ft(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},edgeCssSelectors:Ol,edgeVisible:Il,initializeEdgeLabels:function(){this.links.forEach(t=>{t.target.data.annotation&&(t.target[t.target.data.annotation]=t.target.data.annotation)})},placeAlongAnEdge:function(t,e){return this.edge_placer(t,e)},reclassEdge:function(t){let e=this.css_classes.branch;if(Nl(t)&&(e+=" "+this.css_classes["tagged-branch"]),Sl(t,this.selection_attribute_name)&&(e+=" "+this.css_classes["selected-branch"]),t.target&&t.target._selectionSet){e+=" phylotree-set-branch-"+t.target._selectionSet.replace(/[^a-zA-Z0-9-_]/g,"_")}return e},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+(Nl(e)?1:0)},0),this.countUpdate(this,t,this.countHandler())}}});let jl="phylotree.event";function Fl(t){var e=new CustomEvent(jl,{detail:["refresh",t]});document.dispatchEvent(e)}function Vl(t,e){var n=new CustomEvent(jl,{detail:["countUpdate",e,t.countHandler()]});document.dispatchEvent(n)}function Rl(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 Yl(){document.addEventListener(jl,Rl,!1)}var Bl=Object.freeze({__proto__:null,countUpdate:Vl,d3PhylotreeAddEventListener:Yl,d3PhylotreeEventListener:Rl,d3PhylotreeSvgRotate:function(t){return null!==t?"rotate ("+t+") ":""},d3PhylotreeSvgTranslate:function(t){return!t||null===t[0]&&null===t[1]?"":"translate ("+(null!==t[0]?t[0]:0)+","+(null!==t[1]?t[1]:0)+") "},d3PhylotreeTriggerLayout:function(t){var e=new CustomEvent(jl,{detail:["layout",t,t.layoutHandler()]});document.dispatchEvent(e)},rescale:function(t,e){(e=e||"y_scaled")in this&&(this[e]*=t)},resizeSvg:function(t,e,n){let i=this.size;if(this.unrooted()){if(this.baseTransform={x:0,y:0},e){let t;if(this.currentZoomTransform&&this.options.zoom){const e=this.currentZoomTransform;t=`translate(${e.x}, ${e.y}) scale(${e.k})`}else t="translate(0,0)";e.selectAll("."+this.css_classes["tree-container"]).attr("transform",t)}}else if(this.radial()){let t=this.pad_width(),n="fit-to-size"!=this.options["top-bottom-spacing"]?this.pad_height():0;if(i=[i[1]+2*t,i[0]+2*t+n],this.baseTransform={x:t,y:t+n},e){let i;if(this.currentZoomTransform&&this.options.zoom){const t=this.currentZoomTransform;i=`translate(${t.x+this.baseTransform.x*t.k}, ${t.y+this.baseTransform.y*t.k}) scale(${t.k})`}else i="translate("+t+","+(t+n)+")";e.selectAll("."+this.css_classes["tree-container"]).attr("transform",i)}}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},toggleCollapse:function(t){if(t.collapsed){t.collapsed=!1;let e=function(t){qa(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},triggerRefresh:Fl});const Hl={"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 ql(t){return arguments.length?(ql="string"==typeof t&&"equal"==t?function(t){return 1}:t,this):ql}var Xl={all:t=>!0,none:t=>!1,"all-leaf-nodes":t=>qa(t.target),"all-internal-nodes":t=>!qa(t.target)};var Wl=Object.freeze({__proto__:null,alignTips:function(t){return arguments.length?(this.options["align-tips"]=t,this):this.options["align-tips"]},css_classes:Hl,initializeCssClasses:function(t={}){Object.keys(t).forEach(e=>{this.css_classes[e]=t[e]})},internalNames:function(t){return arguments.length?(this.options["internal-names"]=t,this):this.options["internal-names"]},layoutHandler:function(t){return arguments.length?(this.layout_listener_handler=t,this):this.layout_listener_handler},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},get nodeSpan(){return ql},predefined_selecters:Xl,radial:function(t){return arguments.length?(this.options["is-radial"]=t,this):this.options["is-radial"]},selectionCallback:function(t){return t?(this._selectionCallback=t,this):this._selectionCallback},selectionLabel:function(t){return arguments.length?(this.selection_attribute_name=t,this.syncEdgeLabels(),this):this.selection_attribute_name},unrooted:function(t){return arguments.length?(this.options["is-unrooted"]=t,this):this.options["is-unrooted"]}});let Zl="d3_layout_phylotree_context_menu";function Gl(t,e,n){let i=[];return function r(s){qa(s)?e&&s!=t&&i.push(s):(n&&s!=t&&i.push(s),s.children.forEach(r))}(t),i}var Jl=Object.freeze({__proto__:null,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])},clearSelection:function(){const t=this.phylotree.nodes.descendants();return this.modifySelection(t,this.selection_attribute_name,!1,!1,"false"),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},getSelection:function(){return Gl(this.phylotree.getRootNode(),!0,!0).filter(t=>t[this.selection_attribute_name])},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(Xl),t))return;t=Xl[t]}if(!this.options["restricted-selectable"]&&!this.options.selectable||this.options["binary-selectable"]){if(this.options["binary-selectable"]){const r="notshown"!=e&&"tag"!=e;"function"==typeof t?this.links.forEach(n=>{var i=t(n);n[e]=n[e]||!1,n[e]!=i&&(n[e]=i,a=!0,n.target[e]=i),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;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(t=>{t[e]=t.target[e],r&&this.options["attribute-list"].forEach(function(n){n!=e&&!0!==t[e]&&(t[n]=!1,t.target[n]=!1)})})),a&&(i||Fl(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||Fl(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},nodeDropdownMenu:function(t,e,n,i,s){let o=Ft(e).select("#"+Zl);if(o.empty()&&(o=Ft(e).append("div").attr("id",Zl).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;qa(t)||(i.collapsible&&(o.append("a").attr("class","phylotree-menu-item dropdown-item").attr("tabindex","-1").text(Cl(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",e=>{o.style("display","none");const i=n.selectAllDescendants(t,!0,!0);"multi-set"===this.options["selection-mode"]&&this._activeSetName?(i.forEach(t=>this.addToSet(t,this._activeSetName)),this.update()):this.modifySelection(i)}),o.append("a").attr("class","phylotree-menu-item dropdown-item").attr("tabindex","-1").text("All terminal branches").on("click",e=>{o.style("display","none");const i=n.selectAllDescendants(t,!0,!1);"multi-set"===this.options["selection-mode"]&&this._activeSetName?(i.forEach(t=>this.addToSet(t,this._activeSetName)),this.update()):this.modifySelection(i)}),o.append("a").attr("class","phylotree-menu-item dropdown-item").attr("tabindex","-1").text("All internal branches").on("click",e=>{o.style("display","none");const i=n.selectAllDescendants(t,!1,!0);"multi-set"===this.options["selection-mode"]&&this._activeSetName?(i.forEach(t=>this.addToSet(t,this._activeSetName)),this.update()):this.modifySelection(i)}))),t.parent&&(i.selectable&&(o.append("a").attr("class","phylotree-menu-item dropdown-item").attr("tabindex","-1").text("Incident branch").on("click",e=>{o.style("display","none"),"multi-set"===this.options["selection-mode"]&&this._activeSetName?(this.addToSet(t,this._activeSetName),this.update()):this.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");const n=this.phylotree.pathToRoot(t);"multi-set"===this.options["selection-mode"]&&this._activeSetName?(n.forEach(t=>this.addToSet(t,this._activeSetName)),this.update()):this.modifySelection(n)}),(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 "+(qa(t)?"node":"subtree")).on("click",e=>{o.style("display","none"),this.modifySelection([t].concat(Gl(t,!0,!0)),"notshown",!0,!0,"true").updateHasHiddenNodes().update()})),kl(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")},selectAllDescendants:Gl,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},selectionCallback:function(t){return t?(this._selectionCallback=t,this):this._selectionCallback}});var Kl=Object.freeze({__proto__:null,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},off:function(t,e){return this._eventListeners&&this._eventListeners[t]&&(this._eventListeners[t]=this._eventListeners[t].filter(t=>t!==e)),this},on:function(t,e){return this._eventListeners||(this._eventListeners={}),this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(e),this}});var Ql=Object.freeze({__proto__:null,_getSetsSummary:function(){const t={};return this._selectionSets&&Object.keys(this._selectionSets).forEach(e=>{t[e]=Array.from(this._selectionSets[e].members,t=>t.data.name)}),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},addToSet:function(t,e){if(!this._selectionSets||!this._selectionSets[e])return console.warn(`Selection set '${e}' not found`),this;const n="string"==typeof t?this.phylotree.getNodeByName(t):t;return n&&(Object.keys(this._selectionSets).forEach(t=>{this._selectionSets[t].members.delete(n)}),this._selectionSets[e].members.add(n),n._selectionSet=e,this.emit("setChange",{action:"add",set:e,node:n,allSets:this._getSetsSummary()}),this.refresh(),this.update()),this},getActiveSet:function(){return this._activeSetName},getNodeSet:function(t){return t._selectionSet||null},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))},handleMultiSetClick:function(t){if(!this._activeSetName||!this._selectionSets)return;t._selectionSet===this._activeSetName?this.removeFromSet(t,this._activeSetName):this.addToSet(t,this._activeSetName)},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)},isInSet:function(t,e){return!(!this._selectionSets||!this._selectionSets[e])&&this._selectionSets[e].members.has(t)},removeFromSet:function(t,e){if(!this._selectionSets||!this._selectionSets[e])return this;const n="string"==typeof t?this.phylotree.getNodeByName(t):t;return n&&this._selectionSets[e].members.has(n)&&(this._selectionSets[e].members.delete(n),delete n._selectionSet,this.emit("setChange",{action:"remove",set:e,node:n,allSets:this._getSetsSummary()}),this.refresh(),this.update()),this},setActiveSet:function(t){return this._selectionSets&&this._selectionSets[t]?this._activeSetName=t:console.warn(`Selection set '${t}' not found`),this}});function th(t){return function(){return t}}class eh{constructor(t,e={}){this.css_classes=Object.assign({},Hl,e["css-classes"]),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=gl,this.draw_scale_bar=null,this.edge_placer=ml,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,"is-unrooted":!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:th(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.currentZoomTransform=null,this.baseTransform={x:0,y:0},this.nodeSpan=this.options["node-span"],this.nodeSpan||(this.nodeSpan=function(t){return 1}),this.rescale_nodeSpan=this.phylotree.nodes.children.map(t=>{if(qa(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(),Yl(),"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){Cl(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&&(Ft(t).select("svg").remove(),this.svg=Ft(D("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")),Ft(this.container).on("click",t=>{this.handle_node_click(null)},!0)),this}update_layout(t,e){e&&(this.nodes=ji(t),this.nodes.each(function(t){t.id=null})),this.update(),this.syncEdgeLabels()}update(t){var e=this;this.placenodes(),this.syncEdgeLabels(),t=this.transitions(t);let n=0,i=this.svg.selectAll("."+this.css_classes["tree-container"]).data([0]);if(this.baseTransform={x:this.offsets[1]+this.options["left-offset"],y:this.pad_height()},i=i.enter().append("g").attr("class",this.css_classes["tree-container"]).merge(i).attr("transform",t=>{if(this.currentZoomTransform&&this.options.zoom){const t=this.currentZoomTransform;return`translate(${t.x+this.baseTransform.x*t.k}, ${t.y+this.baseTransform.y*t.k}) scale(${t.k})`}return this.d3PhylotreeSvgTranslate([this.baseTransform.x,this.baseTransform.y])}),this.draw_scale_bar){let t=this.svg.selectAll("."+this.css_classes["tree-scale-bar"]).data([0]);t.enter().append("g").attr("class",this.css_classes["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("."+this.css_classes["tree-scale-bar"]).remove();i=this.svg.selectAll("."+this.css_classes["tree-container"]).data([0]),this.updateCollapsedClades(t);let s=i.selectAll(Ol(this.css_classes)).data(this.links.filter(Il),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(zl(this.css_classes)).data(this.phylotree.nodes.descendants().filter(El),t=>t.id||(t.id=++n));if(o.exit().remove(),o=o.enter().append("g").merge(o).attr("class",t=>this.reclassNode(t)).attr("transform",t=>{const e="right-to-left"==this.options.layout&&qa(t);return t.screen_x=ul(t),t.screen_y=cl(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("."+this.css_classes["tree-selection-brush"]).data([0]).enter().insert("g",":first-child").attr("class",this.css_classes["tree-selection-brush"]),l=gi().on("brush",(t,e)=>{var n=t.selection,i=this.links.filter(Il).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)}return this.options.zoom&&(this.zoomBehavior||(this.zoomBehavior=function(){var t,e,n,i=po,r=_o,s=vo,o=mo,a=yo,l=[0,1/0],h=[[-1/0,-1/0],[1/0,1/0]],u=250,c=Ge,d=S("start","zoom","end"),f=0,p=10;function _(t){t.property("__zoom",go).on("wheel.zoom",w,{passive:!1}).on("mousedown.zoom",N).on("dblclick.zoom",E).filter(a).on("touchstart.zoom",M).on("touchmove.zoom",T).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 y(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function v(t,e,n,i){t.on("start.zoom",function(){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?y(a):"function"==typeof n?n.apply(t,s):n,h=Math.max(a[1][0]-a[0][0],a[1][1]-a[0][1]),u=t.__zoom,d="function"==typeof e?e.apply(t,s):e,f=c(u.invert(l).concat(h/u.k),d.invert(l).concat(h/d.k));return function(t){if(1===t)t=d;else{var e=f(t),n=h/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)))),u=Vt(t);if(n.wheel)n.mouse[0][0]===u[0]&&n.mouse[0][1]===u[1]||(n.mouse[1]=r.invert(n.mouse[0]=u)),clearTimeout(n.wheel);else{if(r.k===a)return;n.mouse=[u,r.invert(u)],bn(this),n.start()}fo(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,h))}}function N(t,...e){if(!n&&i.apply(this,arguments)){var r=t.currentTarget,o=b(this,e,!0).event(t),a=Ft(t.view).on("mousemove.zoom",function(t){if(fo(t),!o.moved){var e=t.clientX-u,n=t.clientY-c;o.moved=e*e+n*n>f}o.event(t).zoom("mouse",s(m(o.that.__zoom,o.mouse[0]=Vt(t,r),o.mouse[1]),o.extent,h))},!0).on("mouseup.zoom",function(t){a.on("mousemove.zoom mouseup.zoom",null),Ht(t.view,o.moved),fo(t),o.event(t).end()},!0),l=Vt(t,r),u=t.clientX,c=t.clientY;Bt(t.view),co(t),o.mouse=[l,this.__zoom.invert(l)],bn(this),o.start()}}function E(t,...e){if(i.apply(this,arguments)){var n=this.__zoom,o=Vt(t.changedTouches?t.changedTouches[0]:t,this),a=n.invert(o),l=n.k*(t.shiftKey?.5:2),c=s(m(g(n,l),o,a),r.apply(this,e),h);fo(t),u>0?Ft(this).transition().duration(u).call(v,c,o,t):Ft(this).call(_.transform,c,o,t)}}function M(n,...r){if(i.apply(this,arguments)){var s,o,a,l,h=n.touches,u=h.length,c=b(this,r,n.changedTouches.length===u).event(n);for(co(n),o=0;o<u;++o)l=[l=Vt(a=h[o],this),this.__zoom.invert(l),a.identifier],c.touch0?c.touch1||c.touch0[2]===l[2]||(c.touch1=l,c.taps=0):(c.touch0=l,s=!0,c.taps=1+!!t);t&&(t=clearTimeout(t)),s&&(c.taps<2&&(e=l[0],t=setTimeout(function(){t=null},500)),bn(this),c.start())}}function T(t,...e){if(this.__zooming){var n,i,r,o,a=b(this,e).event(t),l=t.changedTouches,u=l.length;for(fo(t),n=0;n<u;++n)r=Vt(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 c=a.touch0[0],d=a.touch0[1],f=a.touch1[0],p=a.touch1[1],_=(_=f[0]-c[0])*_+(_=f[1]-c[1])*_,y=(y=p[0]-d[0])*y+(y=p[1]-d[1])*y;i=g(i,Math.sqrt(_/y)),r=[(c[0]+f[0])/2,(c[1]+f[1])/2],o=[(d[0]+p[0])/2,(d[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,h))}}function A(t,...i){if(this.__zooming){var r,s,o=b(this,i).event(t),a=t.changedTouches,l=a.length;for(co(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=Vt(s,this),Math.hypot(e[0]-s[0],e[1]-s[1])<p)){var h=Ft(this).on("dblclick.zoom");h&&h.apply(this,arguments)}}}return _.transform=function(t,e,n,i){var r=t.selection?t.selection():t;r.property("__zoom",go),t!==r?v(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?y(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,h)},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),h)},null,i)},_.translateTo=function(t,e,n,i,o){_.transform(t,function(){var t=r.apply(this,arguments),o=this.__zoom,a=null==i?y(t):"function"==typeof i?i.apply(this,arguments):i;return s(uo.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,h)},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=Ft(this.that).datum();d.call(t,this.that,new lo(t,{sourceEvent:this.sourceEvent,target:_,transform:this.that.__zoom,dispatch:d}),e)}},_.wheelDelta=function(t){return arguments.length?(o="function"==typeof t?t:ao(+t),_):o},_.filter=function(t){return arguments.length?(i="function"==typeof t?t:ao(!!t),_):i},_.touchable=function(t){return arguments.length?(a="function"==typeof t?t:ao(!!t),_):a},_.extent=function(t){return arguments.length?(r="function"==typeof t?t:ao([[+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?(h[0][0]=+t[0][0],h[1][0]=+t[1][0],h[0][1]=+t[0][1],h[1][1]=+t[1][1],_):[[h[0][0],h[0][1]],[h[1][0],h[1][1]]]},_.constrain=function(t){return arguments.length?(s=t,_):s},_.duration=function(t){return arguments.length?(u=+t,_):u},_.interpolate=function(t){return arguments.length?(c=t,_):c},_.on=function(){var t=d.on.apply(d,arguments);return t===d?_:t},_.clickDistance=function(t){return arguments.length?(f=(t=+t)*t,_):Math.sqrt(f)},_.tapDistance=function(t){return arguments.length?(p=+t,_):p},_}().scaleExtent([.1,10]).on("zoom",t=>{this.currentZoomTransform=t.transform;const e=t.transform,n=`translate(${e.x+this.baseTransform.x*e.k}, ${e.y+this.baseTransform.y*e.k}) scale(${e.k})`;this.svg.select("."+this.css_classes["tree-container"]).attr("transform",n),this.svg.select("."+this.css_classes["tree-scale-bar"]).attr("transform",t=>`translate(${e.x+this.baseTransform.x*e.k}, ${e.y+(this.baseTransform.y-10)*e.k}) scale(${e.k})`)})),this.svg.call(this.zoomBehavior),this.currentZoomTransform&&this.svg.call(this.zoomBehavior.transform,this.currentZoomTransform)),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(Ml(t))return;let e=qa(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(Cl(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,qa(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(){Al(this.phylotree.nodes),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.unrooted()){let t=40,e=(this.fixed_width[0]-14+(this.fixed_width[1]-30))*t,n=this.width+e,i=this.height+e;n<100&&(n=100),i<100&&(i=100),this.shown_font_size=this.font_size,this.label_width=this._label_width(this.shown_font_size);let r=this.label_width+this.shown_font_size;vl(this.phylotree.nodes,this.scales,n,i,r),this.size=[i,n],this.draw_branch=xl,this.edge_placer=wl,this.draw_scale_bar=null}else if(this.radial()){this.draw_branch=r.partial(pl,this.radial_center),this.edge_placer=_l;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;const h=t=>!Tl(t);this.phylotree.nodes.each(t=>{if(!h(t))return;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=>{h(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&&h(t)){let r=t.x*this.scales[0];if(null!==e){let o=r-n,h=a(t.radius,i,t.angle,e,u),c=h>0?o/h:10*this.options["max-radius"];if(c>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)),h=Math.sqrt(r*r-4*a);u=Math.min(this.options["annular-limit"]*l,(-r+h)/2),s=this.options["max-radius"]}else s=Math.max(s,c)}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(pl,this.radial_center);let c=1;u&&(c=l/(l+u),this.radius*=c),this.phylotree.nodes.each(t=>{if(h(t)&&(fl(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=fl(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=gl,this.edge_placer=ml,this.right_most_leaf=0,this.phylotree.nodes.each(t=>{if(!Tl(t)&&(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+this.label_width),qa(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=er().domain([0,t]).range([0,e]),i=Di(".2f");if(this.draw_scale_bar=function(t){return w(0,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 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))))}}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(El).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=th(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 this.css_classes)n in t&&t[n]!=this.css_classes[n]&&(this.css_classes[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 this.css_classes)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(Ol(this.css_classes)).attr("class",this.reclassEdge.bind(this));if(this.edge_styler){let e=this;t.each(function(t){e.edge_styler(Ft(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(eh.prototype,Ll),r.extend(eh.prototype,Dl),r.extend(eh.prototype,Ul),r.extend(eh.prototype,Bl),r.extend(eh.prototype,Jl),r.extend(eh.prototype,Wl),r.extend(eh.prototype,Kl),r.extend(eh.prototype,Ql);let nh=class{constructor(t,e={}){this.newick_string="",this.nodes=[],this.links=[],this.parsed_tags=[],this.partitions=[],this.branch_length_accessor=ll,this.branch_length=ll,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 il?i=il[n](t,e):s.logger.error("type "+n+" not in registry! Available types are "+r.keys(il));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=nl(t):(this.newick_string=t,i=Za(t,e));if(i.json){s.nodes=ji(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){sl(e,t,i)}:"in-order"==e?function(e){ol(e,t,i)}:function(e){r.isUndefined(e)||rl(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 eh(this,t),this.display}};function ih(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 rh(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?rh(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&&rh(t,e.parent,e,i,r)}function sh(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 h=(i-n*(o/=a))/e,u=0;return t.forEach(function(t){var e=t[1]-h-o*t[0];u+=t[2]*e*e}),{intercept:h,slope:o,r2:1-u/l,"var (intercept)":Math.sqrt((1+n*n/(e*a))/e),"var (slope)":Math.sqrt(1/a)}}function oh(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}nh.prototype.isLeafNode=qa,nh.prototype.selectAllDescendants=Xa,nh.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},nh.prototype.hasBranchLengths=function(){let t=this.branch_length;return!!t&&r.every(this.nodes.descendants(),function(e){return!e.parent||!r.isUndefined(t(e))})},nh.prototype.getBranchLengths=function(){let t=this.branch_length;return r.map(this.nodes.descendants(),e=>t(e))},nh.prototype.branchName=function(t){return arguments.length?(this.nodeLabel=t,this):this.nodeLabel},nh.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},nh.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},nh.prototype.getNewick=Ga,nh.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}}`:"")},nh.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},nh.prototype.setBranchLength=function(t){return arguments.length?(this.branch_length_accessor=t||ll,this):this.branch_length_accessor},nh.prototype.maxParsimony=function(t,e){const n=r.partial(function(t,e){if(e.mp=[[0,0],[!1,!1]],qa(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)=>qa(t.target)?t.target[e]:t.target.mp)},nh.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},nh.prototype.leftChildRightSibling=al,r.extend(nh.prototype,Wa),r.extend(nh.prototype,hl),r.extend(nh.prototype,tl);const ah=Dr("%Y%m%d"),lh=/([0-9]{4}).?([0-9]{2}).?([0-9]{2})$/g,hh=function(t){if(qa(t)&&"name"in t){let e=lh.exec(t.name);if(e)return e[1]+e[2]+e[3]}return null},uh=function(t,e,n=ah){return e=e||hh,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};function ch(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=ih(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,h=0,u=0;r.each(t.cot_path_to_leaves_below,function(t){e+=t,a+=t*t,u++}),r.each(t.cot_path_to_leaves_above,function(t){l+=t,h+=t*t});var c=n-u,d=(l-e+t.cot_computed_length*c)/n;d<0?d=0:d>t.cot_computed_length&&(d=t.cot_computed_length);var f=h+a+2*(l*(t.cot_computed_length-d)+e*d)+u*d*d+(t.cot_computed_length-d)*(t.cot_computed_length-d)*c;f<i&&(o=t,s=d/t.cot_computed_length,i=f),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.extractDates=uh,t.extract_dates=uh,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),oh(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=sh(e);return t.traverse_and_compute(function(o){if(t.isLeafNode(o)&&!r.isNull(o.data.decimal_date_value)){rh(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=sh(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=Ga,t.inOrder=ol,t.leftChildRightSibling=al,t.loadAnnotations=Ka,t.neighborJoining=function t(e,n,i){if(n<=2){let t=new nh(""),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),[h,u]=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),c=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[h][u]+c[h][u])/2,f=(e[h][u]-c[h][u])/2,p=s.concat(0,s.filter(s.map(s.range(n),t=>{if(t!=h&&t!=u)return.5*(e[t][h]+e[t][u]-e[h][u])}),s.isNumber)),_=i[h],g=i[u],m="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]));m="InternalNode"+ ++t}i.unshift(m),e=ch(s.max([h,u]),e),(e=ch(s.min([h,u]),e)).unshift(p),s.each(s.range(1,n-1),t=>e[t].unshift(p[t])),s.remove(i,t=>t==_||t==g);let v=t(e,o-1,i),b=v.createNode(_,[null,[d]]),x=v.createNode(g,[null,[f]]);if(v.getNodeByName(m)){let t=v.getNodeByName(m);v.addChild(t,b),v.addChild(t,x)}else{let t=v.createNode(m,[null,[0]]);v.addChild(v.getNodes(),t),v.addChild(t,b),v.addChild(t,x)}return v}var r},t.newickParser=Za,t.pairwiseDistances=ih,t.pairwise_distances=ih,t.parseAnnotations=Ja,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=ih(t),a=t.getRootNode().children[0],l=Number.MAX_VALUE,h=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<h&&(h=l),l=e.cot_computed_length):e.cot_computed_length<h&&(h=e.cot_computed_length))}),l+=h;var u=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,u/100));var c=1+(u/s|0);c>500&&(s=u/(c=500));var d=t.getRootNode();d.paths_to_leaves=new Array(o),r.each(d.children,function(t){r.each(d.cot_path_to_leaves_below,function(e,n){d.paths_to_leaves[n]=e+t.cot_computed_length})}),t.traverse_and_compute(function(e){if(!t.isLeafNode(e)){e.histogram=new Array(c);for(var n=0;n<c;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 f=(o-1)*o/2*n,p=0;p<c-1&&f>d.histogram[p];p++)f-=d.histogram[p];var _=l+(p+(d.histogram[p]-f)/d.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,h=0;h<c-1&&a>n.histogram[h];h++)a-=n.histogram[h];var u=l+(h+(n.histogram[h]-a)/n.histogram[h])*s;if(u<=_)return g.push({root:n,median:u,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=nh,t.postOrder=rl,t.preOrder=sl,t.rootToTip=oh,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)}});
|
|
2
2
|
//# sourceMappingURL=phylotree.min.js.map
|