From 0101fa4fafa558a82d48e62862820424228bdf8c Mon Sep 17 00:00:00 2001 From: Rico Sonntag Date: Fri, 26 Apr 2024 17:23:14 +0200 Subject: [PATCH] WIP --- resources/css/svg.css | 6 +- resources/js/descendants-chart.min.js | 2 +- .../js/modules/lib/chart/svg/export/svg.js | 135 ++++++++++++++++-- resources/js/modules/lib/tree/date.js | 5 +- src/Module.php | 5 +- 5 files changed, 134 insertions(+), 19 deletions(-) diff --git a/resources/css/svg.css b/resources/css/svg.css index e1e4ebb..d25da13 100644 --- a/resources/css/svg.css +++ b/resources/css/svg.css @@ -57,16 +57,16 @@ font-size: 13px; } -.webtrees-descendants-chart-container svg .wt-chart-box-name { +.webtrees-descendants-chart-container svg text.wt-chart-box-name { fill: var(--link-color, currentColor); } -.webtrees-descendants-chart-container svg .wt-chart-box-name-alt { +.webtrees-descendants-chart-container svg text.wt-chart-box-name-alt { fill: currentColor; font-weight: 500; font-size: 0.85em; } -.webtrees-descendants-chart-container svg .wt-chart-box-name:hover:not(.wt-chart-box-name-alt) { +.webtrees-descendants-chart-container svg text.wt-chart-box-name:hover:not(.wt-chart-box-name-alt) { fill: var(--link-color-hover); } diff --git a/resources/js/descendants-chart.min.js b/resources/js/descendants-chart.min.js index b79e7da..e1fa9f2 100644 --- a/resources/js/descendants-chart.min.js +++ b/resources/js/descendants-chart.min.js @@ -1 +1 @@ -var t,e;t=this,e=function(t){function e(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);return t.text()}function n(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 i(t,e){t instanceof Map?(t=[void 0,t],void 0===e&&(e=a)):void 0===e&&(e=r);for(var n,i,o,u,l,c=new h(t),f=[c];n=f.pop();)if((o=e(n.data))&&(l=(o=Array.from(o)).length))for(n.children=o,u=l-1;u>=0;--u)f.push(i=o[u]=new h(o[u])),i.parent=n,i.depth=n.depth+1;return c.eachBefore(s)}function r(t){return t.children}function a(t){return Array.isArray(t)?t[1]:null}function o(t){void 0!==t.data.value&&(t.value=t.data.value),t.data=t.data.data}function s(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function h(t){this.data=t,this.depth=this.height=0,this.parent=null}function u(t,e){return t.parent===e.parent?1:2}function l(t){var e=t.children;return e?e[0]:t.t}function c(t){var e=t.children;return e?e[e.length-1]:t.t}function f(t,e,n){var i=n/(e.i-t.i);e.c-=i,e.s+=n,t.c+=i,e.z+=n,e.m+=n}function d(t,e,n){return t.a.parent===e.parent?t.a:n}function p(t,e){this._=t,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=e}function g(){var t=u,e=1,n=1,i=null;function r(r){var h=function(t){for(var e,n,i,r,a,o=new p(t,0),s=[o];e=s.pop();)if(i=e._.children)for(e.children=new Array(a=i.length),r=a-1;r>=0;--r)s.push(n=e.children[r]=new p(i[r],r)),n.parent=e;return(o.parent=new p(null,0)).children=[o],o}(r);if(h.eachAfter(a),h.parent.m=-h.z,h.eachBefore(o),i)r.eachBefore(s);else{var u=r,l=r,c=r;r.eachBefore((function(t){t.xl.x&&(l=t),t.depth>c.depth&&(c=t)}));var f=u===l?1:t(u,l)/2,d=f-u.x,g=e/(l.x+f+d),_=n/(c.depth||1);r.eachBefore((function(t){t.x=(t.x+d)*g,t.y=t.depth*_}))}return r}function a(e){var n=e.children,i=e.parent.children,r=e.i?i[e.i-1]:null;if(n){!function(t){for(var e,n=0,i=0,r=t.children,a=r.length;--a>=0;)(e=r[a]).z+=n,e.m+=n,n+=e.s+(i+=e.c)}(e);var a=(n[0].z+n[n.length-1].z)/2;r?(e.z=r.z+t(e._,r._),e.m=e.z-a):e.z=a}else r&&(e.z=r.z+t(e._,r._));e.parent.A=function(e,n,i){if(n){for(var r,a=e,o=e,s=n,h=a.parent.children[0],u=a.m,p=o.m,g=s.m,_=h.m;s=c(s),a=l(a),s&&a;)h=l(h),(o=c(o)).a=e,(r=s.z+g-a.z-u+t(s._,a._))>0&&(f(d(s,e,i),e,r),u+=r,p+=r),g+=s.m,u+=a.m,_+=h.m,p+=o.m;s&&!c(o)&&(o.t=s,o.m+=g-p),a&&!l(h)&&(h.t=a,h.m+=u-_,i=e)}return i}(e,r,e.parent.A||i[0])}function o(t){t._.x=t.z+t.parent.m,t.m+=t.parent.m}function s(t){t.x*=e,t.y=t.depth*n}return r.separation=function(e){return arguments.length?(t=e,r):t},r.size=function(t){return arguments.length?(i=!1,e=+t[0],n=+t[1],r):i?null:[e,n]},r.nodeSize=function(t){return arguments.length?(i=!0,e=+t[0],n=+t[1],r):i?[e,n]:null},r}h.prototype=i.prototype={constructor:h,count:function(){return this.eachAfter(n)},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,a=this,o=[a],s=[],h=-1;a=o.pop();)if(s.push(a),n=a.children)for(i=0,r=n.length;i=0;--i)a.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;for(t=n.pop(),e=i.pop();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 i(this).eachBefore(o)},[Symbol.iterator]:function*(){var t,e,n,i,r=this,a=[r];do{for(t=a.reverse(),a=[];r=t.pop();)if(yield r,e=r.children)for(n=0,i=e.length;n=0))throw new Error(`invalid digits: ${t}`);if(e>15)return w;const n=10**e;return function(t){this._+=t[0];for(let e=1,i=t.length;ey)if(Math.abs(l*s-h*u)>y&&r){let f=n-a,d=i-o,p=s*s+h*h,g=f*f+d*d,m=Math.sqrt(p),v=Math.sqrt(c),w=r*Math.tan((_-Math.acos((p+c-g)/(2*m*v)))/2),x=w/v,b=w/m;Math.abs(x-1)>y&&this._append`L${t+x*u},${e+x*l}`,this._append`A${r},${r},0,0,${+(l*f>u*d)},${this._x1=t+b*s},${this._y1=e+b*h}`}else this._append`L${this._x1=t},${this._y1=e}`}arc(t,e,n,i,r,a){if(t=+t,e=+e,a=!!a,(n=+n)<0)throw new Error(`negative radius: ${n}`);let o=n*Math.cos(i),s=n*Math.sin(i),h=t+o,u=e+s,l=1^a,c=a?i-r:r-i;null===this._x1?this._append`M${h},${u}`:(Math.abs(this._x1-h)>y||Math.abs(this._y1-u)>y)&&this._append`L${h},${u}`,n&&(c<0&&(c=c%m+m),c>v?this._append`A${n},${n},0,1,${l},${t-o},${e-s}A${n},${n},0,1,${l},${this._x1=h},${this._y1=u}`:c>y&&this._append`A${n},${n},0,${+(c>=_)},${l},${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 b(){return new x}function N(t,e,n){t.prototype=e.prototype=n,n.constructor=t}function A(t,e){var n=Object.create(t.prototype);for(var i in e)n[i]=e[i];return n}function k(){}b.prototype=x.prototype;var E=.7,M=1/E,$="\\s*([+-]?\\d+)\\s*",z="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",T="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",S=/^#([0-9a-f]{3,8})$/,R=new RegExp(`^rgb\\(${$},${$},${$}\\)$`),P=new RegExp(`^rgb\\(${T},${T},${T}\\)$`),O=new RegExp(`^rgba\\(${$},${$},${$},${z}\\)$`),C=new RegExp(`^rgba\\(${T},${T},${T},${z}\\)$`),D=new RegExp(`^hsl\\(${z},${T},${T}\\)$`),I=new RegExp(`^hsla\\(${z},${T},${T},${z}\\)$`),L={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 X(){return this.rgb().formatHex()}function B(){return this.rgb().formatRgb()}function H(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=S.exec(t))?(n=e[1].length,e=parseInt(e[1],16),6===n?W(e):3===n?new q(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?j(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?j(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=R.exec(t))?new q(e[1],e[2],e[3],1):(e=P.exec(t))?new q(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=O.exec(t))?j(e[1],e[2],e[3],e[4]):(e=C.exec(t))?j(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=D.exec(t))?Q(e[1],e[2]/100,e[3]/100,1):(e=I.exec(t))?Q(e[1],e[2]/100,e[3]/100,e[4]):L.hasOwnProperty(t)?W(L[t]):"transparent"===t?new q(NaN,NaN,NaN,0):null}function W(t){return new q(t>>16&255,t>>8&255,255&t,1)}function j(t,e,n,i){return i<=0&&(t=e=n=NaN),new q(t,e,n,i)}function Y(t,e,n,i){return 1===arguments.length?((r=t)instanceof k||(r=H(r)),r?new q((r=r.rgb()).r,r.g,r.b,r.opacity):new q):new q(t,e,n,null==i?1:i);var r}function q(t,e,n,i){this.r=+t,this.g=+e,this.b=+n,this.opacity=+i}function U(){return`#${K(this.r)}${K(this.g)}${K(this.b)}`}function V(){const t=G(this.opacity);return`${1===t?"rgb(":"rgba("}${F(this.r)}, ${F(this.g)}, ${F(this.b)}${1===t?")":`, ${t})`}`}function G(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function F(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function K(t){return((t=F(t))<16?"0":"")+t.toString(16)}function Q(t,e,n,i){return i<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new J(t,e,n,i)}function Z(t){if(t instanceof J)return new J(t.h,t.s,t.l,t.opacity);if(t instanceof k||(t=H(t)),!t)return new J;if(t instanceof J)return t;var e=(t=t.rgb()).r/255,n=t.g/255,i=t.b/255,r=Math.min(e,n,i),a=Math.max(e,n,i),o=NaN,s=a-r,h=(a+r)/2;return s?(o=e===a?(n-i)/s+6*(n0&&h<1?0:o,new J(o,s,h,t.opacity)}function J(t,e,n,i){this.h=+t,this.s=+e,this.l=+n,this.opacity=+i}function tt(t){return(t=(t||0)%360)<0?t+360:t}function et(t){return Math.max(0,Math.min(1,t||0))}function nt(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}N(k,H,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:X,formatHex:X,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return Z(this).formatHsl()},formatRgb:B,toString:B}),N(q,Y,A(k,{brighter(t){return t=null==t?M:Math.pow(M,t),new q(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?E:Math.pow(E,t),new q(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new q(F(this.r),F(this.g),F(this.b),G(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:U,formatHex:U,formatHex8:function(){return`#${K(this.r)}${K(this.g)}${K(this.b)}${K(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:V,toString:V})),N(J,(function(t,e,n,i){return 1===arguments.length?Z(t):new J(t,e,n,null==i?1:i)}),A(k,{brighter(t){return t=null==t?M:Math.pow(M,t),new J(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?E:Math.pow(E,t),new J(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 q(nt(t>=240?t-240:t+120,r,i),nt(t,r,i),nt(t<120?t+240:t-120,r,i),this.opacity)},clamp(){return new J(tt(this.h),et(this.s),et(this.l),G(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=G(this.opacity);return`${1===t?"hsl(":"hsla("}${tt(this.h)}, ${100*et(this.s)}%, ${100*et(this.l)}%${1===t?")":`, ${t})`}`}}));var it=t=>()=>t;function rt(t){return 1==(t=+t)?at: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):it(isNaN(e)?n:e)}}function at(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):it(isNaN(t)?e:t)}var ot=function t(e){var n=rt(e);function i(t,e){var i=n((t=Y(t)).r,(e=Y(e)).r),r=n(t.g,e.g),a=n(t.b,e.b),o=at(t.opacity,e.opacity);return function(e){return t.r=i(e),t.g=r(e),t.b=a(e),t.opacity=o(e),t+""}}return i.gamma=t,i}(1);function st(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}var ht=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,ut=new RegExp(ht.source,"g");function lt(t,e){var n,i,r,a=ht.lastIndex=ut.lastIndex=0,o=-1,s=[],h=[];for(t+="",e+="";(n=ht.exec(t))&&(i=ut.exec(e));)(r=i.index)>a&&(r=e.slice(a,r),s[o]?s[o]+=r:s[++o]=r),(n=n[0])===(i=i[0])?s[o]?s[o]+=i:s[++o]=i:(s[++o]=null,h.push({i:o,x:st(n,i)})),a=ut.lastIndex;return a180?e+=360:e-t>180&&(t+=360),a.push({i:n.push(r(n)+"rotate(",null,i)-2,x:st(t,e)})):e&&n.push(r(n)+"rotate("+e+i)}(a.rotate,o.rotate,s,h),function(t,e,n,a){t!==e?a.push({i:n.push(r(n)+"skewX(",null,i)-2,x:st(t,e)}):e&&n.push(r(n)+"skewX("+e+i)}(a.skewX,o.skewX,s,h),function(t,e,n,i,a,o){if(t!==n||e!==i){var s=a.push(r(a)+"scale(",null,",",null,")");o.push({i:s-4,x:st(t,n)},{i:s-2,x:st(e,i)})}else 1===n&&1===i||a.push(r(a)+"scale("+n+","+i+")")}(a.scaleX,a.scaleY,o.scaleX,o.scaleY,s,h),a=o=null,function(t){for(var e,n=-1,i=h.length;++n=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),xt.hasOwnProperty(e)?{space:xt[e],local:t}:t}function Nt(t){return function(){var e=this.ownerDocument,n=this.namespaceURI;return n===wt&&e.documentElement.namespaceURI===wt?e.createElement(t):e.createElementNS(n,t)}}function At(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function kt(t){var e=bt(t);return(e.local?At:Nt)(e)}function Et(){}function Mt(t){return null==t?Et:function(){return this.querySelector(t)}}function $t(t){return null==t?[]:Array.isArray(t)?t:Array.from(t)}function zt(){return[]}function Tt(t){return null==t?zt:function(){return this.querySelectorAll(t)}}function St(t){return function(){return this.matches(t)}}function Rt(t){return function(e){return e.matches(t)}}var Pt=Array.prototype.find;function Ot(){return this.firstElementChild}var Ct=Array.prototype.filter;function Dt(){return Array.from(this.children)}function It(t){return new Array(t.length)}function Lt(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function Xt(t,e,n,i,r,a){for(var o,s=0,h=e.length,u=a.length;se?1:t>=e?0:NaN}function Yt(t){return function(){this.removeAttribute(t)}}function qt(t){return function(){this.removeAttributeNS(t.space,t.local)}}function Ut(t,e){return function(){this.setAttribute(t,e)}}function Vt(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function Gt(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function Ft(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 Kt(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function Qt(t){return function(){this.style.removeProperty(t)}}function Zt(t,e,n){return function(){this.style.setProperty(t,e,n)}}function Jt(t,e,n){return function(){var i=e.apply(this,arguments);null==i?this.style.removeProperty(t):this.style.setProperty(t,i,n)}}function te(t,e){return t.style.getPropertyValue(e)||Kt(t).getComputedStyle(t,null).getPropertyValue(e)}function ee(t){return function(){delete this[t]}}function ne(t,e){return function(){this[t]=e}}function ie(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function re(t){return t.trim().split(/^|\s+/)}function ae(t){return t.classList||new oe(t)}function oe(t){this._node=t,this._names=re(t.getAttribute("class")||"")}function se(t,e){for(var n=ae(t),i=-1,r=e.length;++i=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var ze=[null];function Te(t,e){this._groups=t,this._parents=e}function Se(){return new Te([[document.documentElement]],ze)}function Re(t){return"string"==typeof t?new Te([[document.querySelector(t)]],[document.documentElement]):new Te([[t]],ze)}function Pe(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]}Te.prototype=Se.prototype={constructor:Te,select:function(t){"function"!=typeof t&&(t=Mt(t));for(var e=this._groups,n=e.length,i=new Array(n),r=0;r=x&&(x=w+1);!(v=m[x])&&++x=0;)(i=r[a])&&(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=jt);for(var n=this._groups,i=n.length,r=new Array(i),a=0;a1?this.each((null==e?Qt:"function"==typeof e?Jt:Zt)(t,e,null==n?"":n)):te(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?ee:"function"==typeof e?ie:ne)(t,e)):this.node()[t]},classed:function(t,e){var n=re(t+"");if(arguments.length<2){for(var i=ae(this.node()),r=-1,a=n.length;++r=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}}))}(t+""),o=a.length;if(!(arguments.length<2)){for(s=e?ke:Ae,i=0;i=0&&e._call.call(void 0,t),e=e._next;--De}()}finally{De=0,function(){for(var t,e,n=Oe,i=1/0;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:Oe=e);Ce=t,Qe(i)}(),He=0}}function Ke(){var t=je.now(),e=t-Be;e>Xe&&(We-=e,Be=t)}function Qe(t){De||(Ie&&(Ie=clearTimeout(Ie)),t-He>24?(t<1/0&&(Ie=setTimeout(Fe,t-je.now()-We)),Le&&(Le=clearInterval(Le))):(Le||(Be=je.now(),Le=setInterval(Ke,Xe)),De=1,Ye(Fe)))}function Ze(t,e,n){var i=new Ve;return e=null==e?0:+e,i.restart((n=>{i.stop(),t(n+e)}),e,n),i}Ve.prototype=Ge.prototype={constructor:Ve,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?qe():+n)+(null==e?0:+e),this._next||Ce===this||(Ce?Ce._next=this:Oe=this,Ce=this),this._call=t,this._time=n,Qe()},stop:function(){this._call&&(this._call=null,this._time=1/0,Qe())}};var Je={value:()=>{}};function tn(){for(var t,e=0,n=arguments.length,i={};e=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,s=a.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++o0)for(var n,i,r=new Array(n),a=0;asn)throw new Error("too late; already scheduled");return n}function _n(t,e){var n=mn(t,e);if(n.state>ln)throw new Error("too late; already running");return n}function mn(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function yn(t,e){var n,i,r,a=t.__transition,o=!0;if(a){for(r in e=null==e?null:e+"",a)(n=a[r]).name===e?(i=n.state>un&&n.state=0&&(t=t.slice(0,e)),!t||"start"===t}))}(e)?gn:_n;return function(){var o=a(this,t),s=o.on;s!==i&&(r=(i=s).copy()).on(e,n),o.on=r}}(n,t,e))},attr:function(t,e){var n=bt(t),i="transform"===n?mt:bn;return this.attrTween(t,"function"==typeof e?(n.local?$n:Mn)(n,i,xn(this,"attr."+t,e)):null==e?(n.local?An:Nn)(n):(n.local?En:kn)(n,i,e))},attrTween:function(t,e){var n="attr."+t;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(null==e)return this.tween(n,null);if("function"!=typeof e)throw new Error;var i=bt(t);return this.tween(n,(i.local?zn:Tn)(i,e))},style:function(t,e,n){var i="transform"==(t+="")?_t:bn;return null==e?this.styleTween(t,function(t,e){var n,i,r;return function(){var a=te(this,t),o=(this.style.removeProperty(t),te(this,t));return a===o?null:a===n&&o===i?r:r=e(n=a,i=o)}}(t,i)).on("end.style."+t,Dn(t)):"function"==typeof e?this.styleTween(t,function(t,e,n){var i,r,a;return function(){var o=te(this,t),s=n(this),h=s+"";return null==s&&(this.style.removeProperty(t),h=s=te(this,t)),o===h?null:o===i&&h===r?a:(r=h,a=e(i=o,s))}}(t,i,xn(this,"style."+t,e))).each(function(t,e){var n,i,r,a,o="style."+e,s="end."+o;return function(){var h=_n(this,t),u=h.on,l=null==h.value[o]?a||(a=Dn(e)):void 0;u===n&&r===l||(i=(n=u).copy()).on(s,r=l),h.on=i}}(this._id,t)):this.styleTween(t,function(t,e,n){var i,r,a=n+"";return function(){var o=te(this,t);return o===a?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 a(){var a=e.apply(this,arguments);return a!==r&&(i=(r=a)&&function(t,e,n){return function(i){this.style.setProperty(t,e.call(this,i),n)}}(t,a,n)),i}return a._value=e,a}(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}}(xn(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=mn(this.node(),n).tween,a=0,o=r.length;a()=>t;function Un(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 Vn(t,e,n){this.k=t,this.x=e,this.y=n}Vn.prototype={constructor:Vn,scale:function(t){return 1===t?this:new Vn(this.k*t,this.x,this.y)},translate:function(t,e){return 0===t&0===e?this:new Vn(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 Gn=new Vn(1,0,0);function Fn(t){for(;!t.__zoom;)if(!(t=t.parentNode))return Gn;return t.__zoom}function Kn(t){t.stopImmediatePropagation()}function Qn(t){t.preventDefault(),t.stopImmediatePropagation()}function Zn(t){return!(t.ctrlKey&&"wheel"!==t.type||t.button)}function Jn(){var t=this;return t instanceof SVGElement?(t=t.ownerSVGElement||t).hasAttribute("viewBox")?[[(t=t.viewBox.baseVal).x,t.y],[t.x+t.width,t.y+t.height]]:[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]:[[0,0],[t.clientWidth,t.clientHeight]]}function ti(){return this.__zoom||Gn}function ei(t){return-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function ni(){return navigator.maxTouchPoints||"ontouchstart"in this}function ii(t,e,n){var i=t.invertX(e[0][0])-n[0][0],r=t.invertX(e[1][0])-n[1][0],a=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>a?(a+o)/2:Math.min(0,a)||Math.max(0,o))}function ri(){var t,e,n,i=Zn,r=Jn,a=ii,o=ei,s=ni,h=[0,1/0],u=[[-1/0,-1/0],[1/0,1/0]],l=250,c=vt,f=tn("start","zoom","end"),d=500,p=150,g=0,_=10;function m(t){t.property("__zoom",ti).on("wheel.zoom",A,{passive:!1}).on("mousedown.zoom",k).on("dblclick.zoom",E).filter(s).on("touchstart.zoom",M).on("touchmove.zoom",$).on("touchend.zoom touchcancel.zoom",z).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function y(t,e){return(e=Math.max(h[0],Math.min(h[1],e)))===t.k?t:new Vn(e,t.x,t.y)}function v(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 Vn(t.k,i,r)}function w(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function x(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,a=arguments,o=b(t,a).event(i),s=r.apply(t,a),h=null==n?w(s):"function"==typeof n?n.apply(t,a):n,u=Math.max(s[1][0]-s[0][0],s[1][1]-s[0][1]),l=t.__zoom,f="function"==typeof e?e.apply(t,a):e,d=c(l.invert(h).concat(u/l.k),f.invert(h).concat(u/f.k));return function(t){if(1===t)t=f;else{var e=d(t),n=u/e[2];t=new Vn(n,h[0]-e[0]*n,h[1]-e[1]*n)}o.zoom(null,t)}}))}function b(t,e,n){return!n&&t.__zooming||new N(t,e)}function N(t,e){this.that=t,this.args=e,this.active=0,this.sourceEvent=null,this.extent=r.apply(t,e),this.taps=0}function A(t,...e){if(i.apply(this,arguments)){var n=b(this,e).event(t),r=this.__zoom,s=Math.max(h[0],Math.min(h[1],r.k*Math.pow(2,o.apply(this,arguments)))),l=Pe(t);if(n.wheel)n.mouse[0][0]===l[0]&&n.mouse[0][1]===l[1]||(n.mouse[1]=r.invert(n.mouse[0]=l)),clearTimeout(n.wheel);else{if(r.k===s)return;n.mouse=[l,r.invert(l)],yn(this),n.start()}Qn(t),n.wheel=setTimeout((function(){n.wheel=null,n.end()}),p),n.zoom("mouse",a(v(y(r,s),n.mouse[0],n.mouse[1]),n.extent,u))}}function k(t,...e){if(!n&&i.apply(this,arguments)){var r=t.currentTarget,o=b(this,e,!0).event(t),s=Re(t.view).on("mousemove.zoom",(function(t){if(Qn(t),!o.moved){var e=t.clientX-l,n=t.clientY-c;o.moved=e*e+n*n>g}o.event(t).zoom("mouse",a(v(o.that.__zoom,o.mouse[0]=Pe(t,r),o.mouse[1]),o.extent,u))}),!0).on("mouseup.zoom",(function(t){s.on("mousemove.zoom mouseup.zoom",null),function(t,e){var n=t.document.documentElement,i=Re(t).on("dragstart.drag",null);e&&(i.on("click.drag",Yn,jn),setTimeout((function(){i.on("click.drag",null)}),0)),"onselectstart"in n?i.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}(t.view,o.moved),Qn(t),o.event(t).end()}),!0),h=Pe(t,r),l=t.clientX,c=t.clientY;!function(t){var e=t.document.documentElement,n=Re(t).on("dragstart.drag",Yn,jn);"onselectstart"in e?n.on("selectstart.drag",Yn,jn):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}(t.view),Kn(t),o.mouse=[h,this.__zoom.invert(h)],yn(this),o.start()}}function E(t,...e){if(i.apply(this,arguments)){var n=this.__zoom,o=Pe(t.changedTouches?t.changedTouches[0]:t,this),s=n.invert(o),h=n.k*(t.shiftKey?.5:2),c=a(v(y(n,h),o,s),r.apply(this,e),u);Qn(t),l>0?Re(this).transition().duration(l).call(x,c,o,t):Re(this).call(m.transform,c,o,t)}}function M(n,...r){if(i.apply(this,arguments)){var a,o,s,h,u=n.touches,l=u.length,c=b(this,r,n.changedTouches.length===l).event(n);for(Kn(n),o=0;o=0&&(a-=hi(t,e)),null===t.coords&&(n.moveTo(t.spouse.x+r,a),n.lineTo(t.source.x-r,a)),t.coords&&t.coords.length>0){for(let e=0;e0&&(o=t.coords[e-1].x+r);let h=e>0?i:0,u=e+1<=t.coords.length?i:0;n.moveTo(o+h,a),n.lineTo(s-u,a)}n.moveTo(t.coords[t.coords.length-1].x+r+i,a),n.lineTo(t.source.x-r,a)}return n.toString()}(t,e)}function hi(t,e){return(t.source.data.family-Math.ceil(t.spouse.data.spouses.length/2))*e.direction*5}class ui extends oi{constructor(t,e){super(t,e),this._splittNames=!0}get direction(){return 1}get nodeWidth(){return this._boxWidth+this._xOffset}get nodeHeight(){return this._boxHeight+this._yOffset}norm(t){t.y*=this.direction}elbow(t){return si(t,this)}}class li extends oi{constructor(t,e){super(t,e),this._splittNames=!0}get direction(){return-1}get nodeWidth(){return this._boxWidth+this._xOffset}get nodeHeight(){return this._boxHeight+this._yOffset}norm(t){t.y*=this.direction}elbow(t){return si(t,this)}}function ci(t,e){const n=e.xOffset/2,i=e.yOffset/2;let r=t.source.x,a=t.source.y;if(void 0!==t.spouse&&0===t.source.data.family?(r-=fi(t,e),a-=(t.source.y-t.spouse.y)/2):r+=e.boxWidth/2*e.direction,null===t.source.data.data&&(r+=e.boxWidth/2*e.direction,a-=e.boxHeight/2+i/2),null!==t.target){let i=t.target.x-e.direction*(e.boxWidth/2+n),o=t.target.y;const s=b();return s.moveTo(r,a),s.lineTo(i,a),s.lineTo(i,o),s.lineTo(i+e.direction*n,o),s.toString()}return function(t,e){const n=b(),i=2,r=e.boxHeight/2;let a=t.source.x;if(t.spouse.data.spouses.length>=0&&(a-=fi(t,e)),null===t.coords&&(n.moveTo(a,t.spouse.y+r),n.lineTo(a,t.source.y-r)),t.coords&&t.coords.length>0){for(let e=0;e0&&(o=t.coords[e-1].y+r);let h=e>0?i:0,u=e+1<=t.coords.length?i:0;n.moveTo(a,o+h),n.lineTo(a,s-u)}n.moveTo(a,t.coords[t.coords.length-1].y+r+i),n.lineTo(a,t.source.y-r)}return n.toString()}(t,e)}function fi(t,e){return(t.source.data.family-Math.ceil(t.spouse.data.spouses.length/2))*e.direction*5}class di extends oi{constructor(t,e){super(t,e),this._xOffset=40,this._yOffset=20}get direction(){return this.isDocumentRtl?-1:1}get nodeWidth(){return this._boxHeight+this._yOffset}get nodeHeight(){return this._boxWidth+this._xOffset}norm(t){[t.x,t.y]=[t.y*this.direction,t.x]}elbow(t){return ci(t,this)}}class pi extends oi{constructor(t,e){super(t,e),this._xOffset=40,this._yOffset=20}get direction(){return this.isDocumentRtl?1:-1}get nodeWidth(){return this._boxHeight+this._yOffset}get nodeHeight(){return this._boxWidth+this._xOffset}norm(t){[t.x,t.y]=[t.y*this.direction,t.x]}elbow(t){return ci(t,this)}}class gi{constructor(){this._orientations={down:new ui(160,175),up:new li(160,175),[ai]:new di(325,95),left:new pi(325,95)}}get(){return this._orientations}}class _i{constructor(t,e=4,n=ai,i=!0,r=!0,a=!1,o=1){this._treeLayout=n,this._orientations=new gi,this._openNewTabOnClick=i,this._showAlternativeName=r,this.duration=750,this.padding=15,this._generations=e,this.textPadding=8,this._fontSize=14,this.fontColor="rgb(0, 0, 0)",this.rtl=a,this.labels=t,this.direction=o}get generations(){return this._generations}set generations(t){this._generations=t}get treeLayout(){return this._treeLayout}set treeLayout(t){this._treeLayout=t}get orientation(){return this._orientations.get()[this.treeLayout]}get openNewTabOnClick(){return this._openNewTabOnClick}get showAlternativeName(){return this._showAlternativeName}}class mi{constructor(t){this._configuration=t,this._nodes=null,this._root=null}init(t){this._configuration.showAlternativeName&&(this._configuration.orientation instanceof ui||this._configuration.orientation instanceof li)&&(this._configuration.orientation.boxHeight+=30),this._root=i(t),this._root.descendants().forEach(((t,e)=>{t.id=e}))}get nodes(){return this._nodes}get root(){return this._root}}class yi{constructor(t){this._element=t.append("defs")}get(){return this._element}}class vi{constructor(t){this._zoom=null,this._parent=t,this.init()}init(){this._zoom=ri(),this._zoom.scaleExtent([.1,20]).on("zoom",(t=>{this._parent.attr("transform",t.transform)})),this._zoom.wheelDelta((t=>-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002))),this._zoom.filter((t=>{if("wheel"===t.type){if(!t.ctrlKey)return!1;const e=Fn(this);if(e.k){if(e.k<=.1&&t.deltaY>0)return t.preventDefault(),!1;if(e.k>=20&&t.deltaY<0)return t.preventDefault(),!1}return!0}return t.button||"touchstart"!==t.type?!(t.ctrlKey&&"wheel"!==t.type||t.button):2===t.touches.length}))}get(){return this._zoom}}class wi{triggerDownload(t,e){let n=new MouseEvent("click",{view:window,bubbles:!1,cancelable:!0}),i=document.createElement("a");i.setAttribute("download",e),i.setAttribute("href",t),i.setAttribute("target","_blank"),i.dispatchEvent(n)}}class xi extends wi{copyStylesInline(t,e){let n=["svg","g","text","textPath"];for(let i=0;i{let r=(new XMLSerializer).serializeToString(t),a=window.URL||window.webkitURL||window,o=new Blob([r],{type:"image/svg+xml;charset=utf-8"}),s=a.createObjectURL(o),h=new Image;h.onload=()=>{let t=this.createCanvas(e,n),r=t.getContext("2d");r.fillStyle="rgb(255,255,255)",r.fillRect(0,0,t.width,t.height),r.drawImage(h,0,0),a.revokeObjectURL(s);let o=t.toDataURL("image/png").replace("image/png","image/octet-stream");i(o)},h.src=s}))}cloneSvg(t){return new Promise((e=>{e(t.cloneNode(!0))}))}svgToImage(t,e){const n=[4960,3508];this.cloneSvg(t.get().node()).then((e=>{this.copyStylesInline(t.get().node(),e);const i=this.calculateViewBox(t.get().node()),r=Math.max(n[0],i[2]),a=Math.max(n[1],i[3]);return e.setAttribute("width",""+r),e.setAttribute("height",""+a),e.setAttribute("viewBox",""+i),this.convertToDataUrl(e,r,a)})).then((t=>this.triggerDownload(t,e))).catch((()=>{console.log("Failed to save chart as PNG image")}))}}class bi extends wi{copyStylesInline(t,n,i){return new Promise((r=>{Promise.all(t.map((t=>function(t,n){return fetch(t,n).then(e)}(t)))).then((t=>{t.forEach((t=>{t=t.replace(new RegExp("."+i+" ","g"),"");let e=document.createElementNS("http://www.w3.org/2000/svg","style");e.appendChild(document.createTextNode(t)),n.prepend(e)})),n.classList.add("wt-global"),r(n)}))}))}convertToObjectUrl(t){return new Promise((e=>{let n=(new XMLSerializer).serializeToString(t),i=window.URL||window.webkitURL||window,r=new Blob([n],{type:"image/svg+xml;charset=utf-8"}),a=i.createObjectURL(r),o=new Image;o.onload=()=>{e(a)},o.src=a}))}cloneSvg(t){return new Promise((e=>{e(t.cloneNode(!0))}))}svgToImage(t,e,n,i){this.cloneSvg(t.get().node()).then((t=>this.copyStylesInline(e,t,n))).then((t=>this.convertToObjectUrl(t))).then((t=>this.triggerDownload(t,i))).catch((()=>{console.log("Failed to save chart as SVG image")}))}}class Ni{constructor(){this._exportClass=null}setExportClass(t){switch(t){case"png":this._exportClass=xi;break;case"svg":this._exportClass=bi}}createExport(t){switch(this.setExportClass(t),t){case"png":case"svg":return new this._exportClass}}}class Ai{constructor(t,e){this._element=t.append("svg"),this._defs=new yi(this._element),this._visual=null,this._zoom=null,this._configuration=e,this.init()}init(){this._element.attr("width","100%").attr("height","100%").attr("text-rendering","optimizeLegibility").attr("text-anchor","middle").attr("xmlns:xlink","https://www.w3.org/1999/xlink")}initEvents(t){this._element.on("contextmenu",(t=>t.preventDefault())).on("wheel",(e=>{e.ctrlKey||t.show(this._configuration.labels.zoom,300,(()=>{t.hide(200,600)}))})).on("touchend",(e=>{e.touches.length<2&&t.hide(0,600)})).on("touchmove",(e=>{e.touches.length>=2?t.hide():t.show(this._configuration.labels.move)})).on("click",(t=>this.doStopPropagation(t)),!0),this._configuration.rtl&&this._element.classed("rtl",!0),this._visual=this._element.append("g"),this._zoom=new vi(this._visual),this._element.call(this._zoom.get())}doStopPropagation(t){t.defaultPrevented&&t.stopPropagation()}export(t){return(new Ni).createExport(t)}get defs(){return this._defs}get zoom(){return this._zoom}get visual(){return this._visual}get(){return this._element}}class ki{constructor(t){this._element=t.append("div").attr("class","overlay").style("opacity",1e-6)}show(t,e=0,n=null){this._element.select("p").remove(),this._element.append("p").attr("class","tooltip").text(t),this._element.transition().duration(e).style("opacity",1).on("end",(()=>{"function"==typeof n&&n()}))}hide(t=0,e=0){this._element.transition().delay(t).duration(e).style("opacity",1e-6)}get(){return this._element}}let Ei=null;function Mi(t,e,n,i=400){null===Ei&&(Ei=document.createElement("canvas"));const r=Ei.getContext("2d"),a=`${i||""} ${n} ${e}`;return r.font!==a&&(r.font=a),r.measureText(t).width}class $i{constructor(t,e,n,i){this._svg=t,this._orientation=e,this._image=n,this._text=i}appendName(t){const e=t.append("g").attr("class","name");if(this._orientation instanceof ui||this._orientation instanceof li){const t=this,n=e.selectAll("text").data((t=>[{data:t.data,isRtl:t.data.data.isNameRtl,isAltRtl:t.data.data.isAltRtl,withImage:!0}])).enter();n.each((function(e){const n=Re(this),i=t.createNamesData(e),r=t.getAvailableWidth(e);i.forEach(((e,i)=>{const a=n.append("text").attr("class","wt-chart-box-name").attr("direction",(t=>t.isRtl?"rtl":"ltr")).attr("text-anchor","middle").attr("alignment-baseline","central").attr("y",t._text.y-5+20*i);t.addNameElements(a,t.truncateNamesData(a,e,r))}))})),this._svg._configuration.showAlternativeName&&n.filter((t=>""!==t.data.data.alternativeName)).call((t=>{const e=t.append("text").classed("wt-chart-box-name-alt",!0).attr("class","wt-chart-box-name").attr("direction",(t=>t.isAltRtl?"rtl":"ltr")).attr("text-anchor","middle").attr("alignment-baseline","central").attr("y",this._text.y+40);this.addNameElements(e,(t=>this.truncateNamesData(e,this.createAlternativeNamesData(t),this.getAvailableWidth(t))))}))}else{const t=e.selectAll("text").data((t=>[{data:t.data,isRtl:t.data.data.isNameRtl,isAltRtl:t.data.data.isAltRtl,withImage:""!==t.data.data.thumbnail}])).enter();t.call((t=>{const e=t.append("text").attr("class","wt-chart-box-name").attr("direction",(t=>t.isRtl?"rtl":"ltr")).attr("text-anchor",(t=>t.isRtl&&this._orientation.isDocumentRtl?"start":t.isRtl||this._orientation.isDocumentRtl?"end":"start")).attr("x",(t=>this.textX(t))).attr("y",this._text.y-10);this.addNameElements(e,(t=>{const[n,...i]=this.createNamesData(t),r=[].concat(n,void 0!==i[0]?i[0]:[]);return this.truncateNamesData(e,r,this.getAvailableWidth(t))}))})),this._svg._configuration.showAlternativeName&&t.filter((t=>""!==t.data.data.alternativeName)).call((t=>{const e=t.append("text").classed("wt-chart-box-name-alt",!0).attr("class","wt-chart-box-name").attr("direction",(t=>t.isAltRtl?"rtl":"ltr")).attr("text-anchor",(t=>t.isAltRtl&&this._orientation.isDocumentRtl?"start":t.isAltRtl||this._orientation.isDocumentRtl?"end":"start")).attr("x",(t=>this.textX(t))).attr("y",this._text.y+8);this.addNameElements(e,(t=>this.truncateNamesData(e,this.createAlternativeNamesData(t),this.getAvailableWidth(t))))}))}}getAvailableWidth(t){let e=this._text.width;return t.withImage&&(this._orientation instanceof di||this._orientation instanceof pi)&&(e-=this._image.width),e}addNameElements(t,e){t.selectAll("tspan").data(e).enter().call((t=>{t.append("tspan").text((t=>t.label)).attr("dx",((t,e)=>0!==e?.25*(t.isNameRtl?-1:1)+"em":null)).classed("preferred",(t=>t.isPreferred)).classed("lastName",(t=>t.isLastName))}))}createNamesData(t){let e={},n={},i={},r=Number.MAX_SAFE_INTEGER,a=Number.MAX_SAFE_INTEGER,o=0;for(let e in t.data.data.firstNames){const i=t.data.data.name.indexOf(t.data.data.firstNames[e],o);-1!==i&&(o=i,i({label:e,isPreferred:!1,isLastName:!1,isNameRtl:t.data.data.isAltRtl})))),n}truncateNames(t,e,n,i){let r=t.map((t=>t.label)).join(" ");return t.reverse().map((a=>(!1===a.isPreferred&&!1===a.isLastName&&this.measureText(r,e,n)>i&&(a.label=a.label.slice(0,1)+".",r=t.map((t=>t.label)).join(" ")),a))).map((a=>(!0===a.isPreferred&&this.measureText(r,e,n)>i&&(a.label=a.label.slice(0,1)+".",r=t.map((t=>t.label)).join(" ")),a))).map((a=>(!0===a.isLastName&&this.measureText(r,e,n)>i&&(a.label=a.label.slice(0,1)+".",r=t.map((t=>t.label)).join(" ")),a))).reverse()}textX(t){const e=this._text.x+(t.withImage?this._image.width:0);return this._orientation.isDocumentRtl?-e:e}measureText(t,e,n=400){return Mi(t,this._svg.get().style("font-family"),e,n)}}let zi=class{constructor(t,e,n,i){this._svg=t,this._orientation=e,this._image=n,this._text=i}appendDate(t){const e=t.append("g").attr("class","table");if(this._orientation instanceof ui||this._orientation instanceof li){const t=e.selectAll("text.date").data((t=>[{label:t.data.data.timespan,withImage:!0}])).enter();let n=this._text.y+45;this._svg._configuration.showAlternativeName&&(n+=30);const i=t.append("text").attr("class","date").attr("text-anchor","middle").attr("alignment-baseline","central").attr("y",n);i.append("title").text((t=>t.label));const r=i.append("tspan");r.text((t=>this.truncateDate(r,t.label,this._text.width)))}else e.selectAll("text").data((t=>{let e=[];return t.data.data.birth&&e.push({icon:"★",label:t.data.data.birth,birth:!0,withImage:""!==t.data.data.thumbnail}),t.data.data.death&&e.push({icon:"†",label:t.data.data.death,death:!0,withImage:""!==t.data.data.thumbnail}),e})).enter().call((t=>{t.append("text").attr("fill","currentColor").attr("text-anchor","middle").attr("dominant-baseline","middle").attr("x",(t=>this.textX(t))).attr("y",((t,e)=>this._text.y+30+(0===e?0:21))).append("tspan").text((t=>t.icon)).attr("dx",5*(this._orientation.isDocumentRtl?-1:1));const e=t.append("text").attr("class","date").attr("text-anchor","start").attr("dominant-baseline","middle").attr("x",(t=>this.textX(t))).attr("y",((t,e)=>this._text.y+30+(0===e?0:20)));e.append("title").text((t=>t.label));const n=e.append("tspan");n.text((t=>this.truncateDate(n,t.label,this._text.width-(t.withImage?this._image.width:0)-25))).attr("dx",15*(this._orientation.isDocumentRtl?-1:1))}))}truncateDate(t,e,n){const i=t.style("font-size"),r=t.style("font-weight");let a=!1;for(;this.measureText(e,i,r)>n&&e.length>1;)e=e.slice(0,-1).trim(),a=!0;return"."===e[e.length-1]&&(e=e.slice(0,-1).trim()),a?e+"…":e}textX(t){const e=this._text.x+(t.withImage?this._image.width:0);return this._orientation.isDocumentRtl?-e:e}measureText(t,e,n=400){return Mi(t,this._svg.get().style("font-family"),e,n)}},Ti=class{constructor(t,e){this._orientation=t,this._cornerRadius=e,this._imagePadding=5,this._imageRadius=Math.min(40,this._orientation.boxHeight/2-this._imagePadding),this._width=this.calculateImageWidth(),this._height=this.calculateImageHeight(),this._rx=this.calculateCornerRadius(),this._ry=this.calculateCornerRadius(),this._x=this.calculateX(),this._y=this.calculateY()}calculateX(){return this._orientation instanceof di||this._orientation instanceof pi?this._orientation.isDocumentRtl?this._width-this._imagePadding:-(this._orientation.boxWidth-this._imagePadding)/2+this._imagePadding:-this._orientation.boxWidth/2+this._width/2}calculateY(){return this._orientation instanceof di||this._orientation instanceof pi?-this._imageRadius:-(this._orientation.boxHeight-this._imagePadding)/2+this._imagePadding}calculateImageWidth(){return 2*this._imageRadius}calculateImageHeight(){return 2*this._imageRadius}calculateCornerRadius(){return this._cornerRadius-this._imagePadding}get x(){return this._x}get y(){return this._y}get rx(){return this._rx}get ry(){return this._ry}get width(){return this._width}get height(){return this._height}};class Si{constructor(t,e=null){this._orientation=t,this._image=e,this._textPaddingX=15,this._textPaddingY=15,(this._orientation instanceof ui||this._orientation instanceof li)&&(this._textPaddingX=5,this._textPaddingY=15),this._x=this.calculateX(),this._y=this.calculateY(),this._width=this.calculateWidth()}calculateX(){return-this._orientation.boxWidth/2+this._textPaddingX}calculateY(){return this._orientation instanceof di||this._orientation instanceof pi?-this._textPaddingY:this._image.y+this._image.height+2*this._textPaddingY}calculateWidth(){return this._orientation.boxWidth-2*this._textPaddingX}get x(){return this._x}get y(){return this._y}get width(){return this._width}}class Ri{constructor(t,e,n){this._svg=t,this._hierarchy=e,this._configuration=n,this._orientation=this._configuration.orientation,this._image=new Ti(this._orientation,20),this._text=new Si(this._orientation,this._image),this._name=new $i(this._svg,this._orientation,this._image,this._text),this._date=new zi(this._svg,this._orientation,this._image,this._text)}drawNodes(t,e){this._svg.defs.get().append("clipPath").attr("id","clip-image").append("rect").attr("rx",this._image.rx).attr("ry",this._image.ry).attr("x",this._image.x).attr("y",this._image.y).attr("width",this._image.width).attr("height",this._image.height),this._svg.visual.selectAll("g.person").data(t,(t=>t.id)).join((t=>this.nodeEnter(t,e)),(t=>this.nodeUpdate(t)),(t=>this.nodeExit(t,e))),this._hierarchy.root.eachBefore((t=>{t.x0=t.x,t.y0=t.y}))}nodeEnter(t,e){t.append("g").attr("opacity",0).attr("class",(t=>"person"+(t.data.spouse?" spouse":""))).attr("transform",(t=>"translate("+t.x+","+t.y+")")).call((t=>{t.append("rect").attr("class",(t=>"F"===t.data.data.sex?"female":"M"===t.data.data.sex?"male":"unknown")).attr("rx",20).attr("ry",20).attr("x",-this._orientation.boxWidth/2).attr("y",-this._orientation.boxHeight/2).attr("width",this._orientation.boxWidth).attr("height",this._orientation.boxHeight).attr("fill-opacity",.5),t.append("title").text((t=>t.data.data.name))})).call((t=>this.drawNode(t))).call((t=>t.transition().duration(this._configuration.duration).attr("opacity",1)))}nodeUpdate(t){t.call((t=>t.transition().duration(this._configuration.duration).attr("opacity",1).attr("transform",(t=>"translate("+t.x+","+t.y+")"))))}nodeExit(t,e){t.call((t=>t.transition().duration(this._configuration.duration).attr("opacity",0).attr("transform",(()=>"translate("+e.x0+","+e.y0+")")).remove()))}drawNode(t){const e=t.selectAll("g.image").data((t=>{let e=[];return t.data.data.thumbnail&&e.push({image:t.data.data.thumbnail}),e})).enter().append("g").attr("class","image");e.append("rect").attr("x",this._image.x).attr("y",this._image.y).attr("width",this._image.width).attr("height",this._image.height).attr("rx",this._image.rx).attr("ry",this._image.ry).attr("fill","rgb(255, 255, 255)"),e.append("image").attr("x",this._image.x).attr("y",this._image.y).attr("width",this._image.width).attr("height",this._image.height).attr("clip-path","url(#clip-image)"),e.append("rect").attr("x",this._image.x).attr("y",this._image.y).attr("width",this._image.width).attr("height",this._image.height).attr("rx",this._image.rx).attr("ry",this._image.ry).attr("fill","none").attr("stroke","rgb(200, 200, 200)").attr("stroke-width",1.5),function(t){return"string"==typeof t?new Te([document.querySelectorAll(t)],[document.documentElement]):new Te([$t(t)],ze)}("g.image image").each((function(t){let e=Re(this);(function(t,e=null){return fetch(t,e).then((t=>t.blob())).then((t=>new Promise(((e,n)=>{const i=new FileReader;i.onloadend=()=>e(i.result),i.onerror=n,i.readAsDataURL(t)}))))})(t.image).then((t=>e.attr("xlink:href",t))).catch((t=>{console.error(t)}))})),this._name.appendName(t),this._date.appendDate(t)}}class Pi{constructor(t,e){this._svg=t,this._configuration=e,this._orientation=this._configuration.orientation}drawLinks(t,e){this._svg.visual.selectAll("path.link").data(t).join((t=>this.linkEnter(t,e)),(t=>this.linkUpdate(t)),(t=>this.linkExit(t,e)))}linkEnter(t,e){t.append("path").classed("link",!0).attr("d",(t=>this._orientation.elbow(t))).call((t=>t.transition().duration(this._configuration.duration).attr("opacity",1)))}linkUpdate(t){}linkExit(t,e){}}class Oi{constructor(t,e,n){this._svg=t,this._configuration=e,this._hierarchy=n,this._hierarchy.root.x0=0,this._hierarchy.root.y0=0,this._orientation=this._configuration.orientation,this._nodeDrawer=new Ri(this._svg,this._hierarchy,this._configuration),this._linkDrawer=new Pi(this._svg,this._configuration),this.draw(this._hierarchy.root)}separation(t,e){return Object.hasOwn(t.data,"spouses")||Object.hasOwn(e.data,"spouse")?1.25:t.parent===e.parent?1:2}draw(t){const e=g().nodeSize([this._configuration.orientation.nodeWidth,this._configuration.orientation.nodeHeight]).separation(this.separation);this._nodes=e(this._hierarchy.root),this._hierarchy.root.each((t=>{this._configuration.orientation.norm(t)}));let n=this._hierarchy.root.descendants(),i=[];n.shift(),n.forEach((t=>{if(t.data&&Array.isArray(t.data.spouses)&&t.data.spouses.length>=1){const e=this.findSpouseById(t.data.spouses[0],n);this._orientation instanceof ui||this._orientation instanceof li?t.x=e.x-this._orientation.nodeWidth:t.y=e.y-this._orientation.nodeWidth}}));const r=n.find((t=>t.children&&t.children.length>0));if(void 0!==r){const t=this._orientation.nodeWidth/2;r.each((e=>{Object.hasOwn(e.data,"spouse")&&null!==e.data.spouse&&Object.hasOwn(e,"children")&&Array.isArray(e.children)&&e.children.length>=1&&this.moveChildren(e,t)}))}n.forEach((t=>{const e=this.findSpouseById(t.data.spouse,n);if(Object.hasOwn(t,"children")&&Array.isArray(t.children)&&t.children.length>0&&t.children.forEach((n=>{void 0!==n.data.spouse&&null!==n.data.spouse||i.push({spouse:e,source:t,target:n,coords:null})})),void 0!==e){let r=null;if(void 0!==e.data.spouses&&e.data.spouses.length>0){const i=e.data.spouses.indexOf(t.data.data.id),a=e.data.spouses.slice(0,i);a.length>0&&(r=[],a.forEach((t=>{const e=this.findSpouseById(t,n);void 0!==e&&r.push({x:e.x,y:e.y})})))}null!==t.data.data&&i.push({spouse:e,source:t,target:null,coords:r})}})),this._linkDrawer.drawLinks(i,t),this._nodeDrawer.drawNodes(n,t)}findSpouseById(t,e){return e.find((e=>e.data.data.id===t))}moveChildren(t,e){t.each((n=>{n.depth!==t.depth&&(0!==t.data.family&&1===t.children.length&&void 0===n.children||(this._orientation instanceof ui||this._orientation instanceof li?n.x-=e:n.y-=e))}))}centerTree(){console.log("centerTree")}togglePerson(t,e){e.children?(e._children=e.children,e.children=null):(e.children=e._children,e._children=null),this.draw(e)}}class Ci{constructor(t,e){this._configuration=e,this._parent=t,this._hierarchy=new mi(this._configuration),this._data={}}get svg(){return this._svg}updateViewBox(){let t=this._svg.visual.node().getBBox(),e=this._parent.node().getBoundingClientRect(),n=Math.max(e.width,t.width),i=Math.max(e.height,t.height,300),r=(n-t.width)/2,a=(i-t.height)/2,o=Math.ceil(t.x-r-10),s=Math.ceil(t.y-a-10);n=Math.ceil(n+20),i=Math.ceil(i+20),this._svg.get().attr("viewBox",[o,s,n,i])}get data(){return this._data}set data(t){this._data=t,this._hierarchy.init(this._data)}draw(){this._parent.html(""),this._svg=new Ai(this._parent,this._configuration),this._overlay=new ki(this._parent),this._svg.initEvents(this._overlay),new Oi(this._svg,this._configuration,this._hierarchy),this.bindClickEventListener(),this.updateViewBox()}bindClickEventListener(){let t=this;this._svg.visual.selectAll("g.person").filter((t=>""!==t.data.data.xref)).each((function(e){Re(this).on("click",(function(){t.personClick(e.data)}))}))}personClick(t){1===t.data.generation?this.redirectToIndividual(t.data.url):this.update(t.data.updateUrl)}redirectToIndividual(t){this._configuration.openNewTabOnClick?window.open(t,"_blank"):window.location=t}update(t){window.location=t}}t.DescendantsChart=class{constructor(t,e){this._selector=t,this._parent=Re(this._selector),this._configuration=new _i(e.labels,e.generations,e.treeLayout,e.openNewTabOnClick,e.showAlternativeName,e.rtl),this._cssFiles=e.cssFiles,this._chart=new Ci(this._parent,this._configuration),this.init(),this.draw(e.data)}init(){Re("#centerButton").on("click",(()=>this.center())),Re("#exportPNG").on("click",(()=>this.exportPNG())),Re("#exportSVG").on("click",(()=>this.exportSVG()))}center(){this._chart.svg.get().transition().duration(750).call(this._chart.svg.zoom.get().transform,Gn)}get configuration(){return this._configuration}update(t){this._chart.update(t)}draw(t){this._chart.data=t,this._chart.draw()}exportPNG(){this._chart.svg.export("png").svgToImage(this._chart.svg,"descendants-chart.png")}exportSVG(){this._chart.svg.export("svg").svgToImage(this._chart.svg,this._cssFiles,"webtrees-descendants-chart-container","descendants-chart.svg")}}},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).WebtreesDescendantsChart={}); +var t,e;t=this,e=function(t){function e(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);return t.text()}function n(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 i(t,e){t instanceof Map?(t=[void 0,t],void 0===e&&(e=a)):void 0===e&&(e=r);for(var n,i,o,l,u,c=new h(t),f=[c];n=f.pop();)if((o=e(n.data))&&(u=(o=Array.from(o)).length))for(n.children=o,l=u-1;l>=0;--l)f.push(i=o[l]=new h(o[l])),i.parent=n,i.depth=n.depth+1;return c.eachBefore(s)}function r(t){return t.children}function a(t){return Array.isArray(t)?t[1]:null}function o(t){void 0!==t.data.value&&(t.value=t.data.value),t.data=t.data.data}function s(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function h(t){this.data=t,this.depth=this.height=0,this.parent=null}function l(t,e){return t.parent===e.parent?1:2}function u(t){var e=t.children;return e?e[0]:t.t}function c(t){var e=t.children;return e?e[e.length-1]:t.t}function f(t,e,n){var i=n/(e.i-t.i);e.c-=i,e.s+=n,t.c+=i,e.z+=n,e.m+=n}function d(t,e,n){return t.a.parent===e.parent?t.a:n}function p(t,e){this._=t,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=e}function g(){var t=l,e=1,n=1,i=null;function r(r){var h=function(t){for(var e,n,i,r,a,o=new p(t,0),s=[o];e=s.pop();)if(i=e._.children)for(e.children=new Array(a=i.length),r=a-1;r>=0;--r)s.push(n=e.children[r]=new p(i[r],r)),n.parent=e;return(o.parent=new p(null,0)).children=[o],o}(r);if(h.eachAfter(a),h.parent.m=-h.z,h.eachBefore(o),i)r.eachBefore(s);else{var l=r,u=r,c=r;r.eachBefore((function(t){t.xu.x&&(u=t),t.depth>c.depth&&(c=t)}));var f=l===u?1:t(l,u)/2,d=f-l.x,g=e/(u.x+f+d),_=n/(c.depth||1);r.eachBefore((function(t){t.x=(t.x+d)*g,t.y=t.depth*_}))}return r}function a(e){var n=e.children,i=e.parent.children,r=e.i?i[e.i-1]:null;if(n){!function(t){for(var e,n=0,i=0,r=t.children,a=r.length;--a>=0;)(e=r[a]).z+=n,e.m+=n,n+=e.s+(i+=e.c)}(e);var a=(n[0].z+n[n.length-1].z)/2;r?(e.z=r.z+t(e._,r._),e.m=e.z-a):e.z=a}else r&&(e.z=r.z+t(e._,r._));e.parent.A=function(e,n,i){if(n){for(var r,a=e,o=e,s=n,h=a.parent.children[0],l=a.m,p=o.m,g=s.m,_=h.m;s=c(s),a=u(a),s&&a;)h=u(h),(o=c(o)).a=e,(r=s.z+g-a.z-l+t(s._,a._))>0&&(f(d(s,e,i),e,r),l+=r,p+=r),g+=s.m,l+=a.m,_+=h.m,p+=o.m;s&&!c(o)&&(o.t=s,o.m+=g-p),a&&!u(h)&&(h.t=a,h.m+=l-_,i=e)}return i}(e,r,e.parent.A||i[0])}function o(t){t._.x=t.z+t.parent.m,t.m+=t.parent.m}function s(t){t.x*=e,t.y=t.depth*n}return r.separation=function(e){return arguments.length?(t=e,r):t},r.size=function(t){return arguments.length?(i=!1,e=+t[0],n=+t[1],r):i?null:[e,n]},r.nodeSize=function(t){return arguments.length?(i=!0,e=+t[0],n=+t[1],r):i?[e,n]:null},r}h.prototype=i.prototype={constructor:h,count:function(){return this.eachAfter(n)},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,a=this,o=[a],s=[],h=-1;a=o.pop();)if(s.push(a),n=a.children)for(i=0,r=n.length;i=0;--i)a.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;for(t=n.pop(),e=i.pop();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 i(this).eachBefore(o)},[Symbol.iterator]:function*(){var t,e,n,i,r=this,a=[r];do{for(t=a.reverse(),a=[];r=t.pop();)if(yield r,e=r.children)for(n=0,i=e.length;n=0))throw new Error(`invalid digits: ${t}`);if(e>15)return w;const n=10**e;return function(t){this._+=t[0];for(let e=1,i=t.length;ey)if(Math.abs(u*s-h*l)>y&&r){let f=n-a,d=i-o,p=s*s+h*h,g=f*f+d*d,m=Math.sqrt(p),v=Math.sqrt(c),w=r*Math.tan((_-Math.acos((p+c-g)/(2*m*v)))/2),x=w/v,b=w/m;Math.abs(x-1)>y&&this._append`L${t+x*l},${e+x*u}`,this._append`A${r},${r},0,0,${+(u*f>l*d)},${this._x1=t+b*s},${this._y1=e+b*h}`}else this._append`L${this._x1=t},${this._y1=e}`}arc(t,e,n,i,r,a){if(t=+t,e=+e,a=!!a,(n=+n)<0)throw new Error(`negative radius: ${n}`);let o=n*Math.cos(i),s=n*Math.sin(i),h=t+o,l=e+s,u=1^a,c=a?i-r:r-i;null===this._x1?this._append`M${h},${l}`:(Math.abs(this._x1-h)>y||Math.abs(this._y1-l)>y)&&this._append`L${h},${l}`,n&&(c<0&&(c=c%m+m),c>v?this._append`A${n},${n},0,1,${u},${t-o},${e-s}A${n},${n},0,1,${u},${this._x1=h},${this._y1=l}`:c>y&&this._append`A${n},${n},0,${+(c>=_)},${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 b(){return new x}function A(t,e,n){t.prototype=e.prototype=n,n.constructor=t}function N(t,e){var n=Object.create(t.prototype);for(var i in e)n[i]=e[i];return n}function k(){}b.prototype=x.prototype;var E=.7,M=1/E,$="\\s*([+-]?\\d+)\\s*",z="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",T="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",S=/^#([0-9a-f]{3,8})$/,R=new RegExp(`^rgb\\(${$},${$},${$}\\)$`),P=new RegExp(`^rgb\\(${T},${T},${T}\\)$`),O=new RegExp(`^rgba\\(${$},${$},${$},${z}\\)$`),C=new RegExp(`^rgba\\(${T},${T},${T},${z}\\)$`),D=new RegExp(`^hsl\\(${z},${T},${T}\\)$`),I=new RegExp(`^hsla\\(${z},${T},${T},${z}\\)$`),L={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 X(){return this.rgb().formatHex()}function B(){return this.rgb().formatRgb()}function H(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=S.exec(t))?(n=e[1].length,e=parseInt(e[1],16),6===n?W(e):3===n?new Y(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?j(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?j(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=R.exec(t))?new Y(e[1],e[2],e[3],1):(e=P.exec(t))?new Y(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=O.exec(t))?j(e[1],e[2],e[3],e[4]):(e=C.exec(t))?j(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=D.exec(t))?Q(e[1],e[2]/100,e[3]/100,1):(e=I.exec(t))?Q(e[1],e[2]/100,e[3]/100,e[4]):L.hasOwnProperty(t)?W(L[t]):"transparent"===t?new Y(NaN,NaN,NaN,0):null}function W(t){return new Y(t>>16&255,t>>8&255,255&t,1)}function j(t,e,n,i){return i<=0&&(t=e=n=NaN),new Y(t,e,n,i)}function q(t,e,n,i){return 1===arguments.length?((r=t)instanceof k||(r=H(r)),r?new Y((r=r.rgb()).r,r.g,r.b,r.opacity):new Y):new Y(t,e,n,null==i?1:i);var r}function Y(t,e,n,i){this.r=+t,this.g=+e,this.b=+n,this.opacity=+i}function V(){return`#${K(this.r)}${K(this.g)}${K(this.b)}`}function U(){const t=G(this.opacity);return`${1===t?"rgb(":"rgba("}${F(this.r)}, ${F(this.g)}, ${F(this.b)}${1===t?")":`, ${t})`}`}function G(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function F(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function K(t){return((t=F(t))<16?"0":"")+t.toString(16)}function Q(t,e,n,i){return i<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new J(t,e,n,i)}function Z(t){if(t instanceof J)return new J(t.h,t.s,t.l,t.opacity);if(t instanceof k||(t=H(t)),!t)return new J;if(t instanceof J)return t;var e=(t=t.rgb()).r/255,n=t.g/255,i=t.b/255,r=Math.min(e,n,i),a=Math.max(e,n,i),o=NaN,s=a-r,h=(a+r)/2;return s?(o=e===a?(n-i)/s+6*(n0&&h<1?0:o,new J(o,s,h,t.opacity)}function J(t,e,n,i){this.h=+t,this.s=+e,this.l=+n,this.opacity=+i}function tt(t){return(t=(t||0)%360)<0?t+360:t}function et(t){return Math.max(0,Math.min(1,t||0))}function nt(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}A(k,H,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:X,formatHex:X,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return Z(this).formatHsl()},formatRgb:B,toString:B}),A(Y,q,N(k,{brighter(t){return t=null==t?M:Math.pow(M,t),new Y(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?E:Math.pow(E,t),new Y(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new Y(F(this.r),F(this.g),F(this.b),G(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:V,formatHex:V,formatHex8:function(){return`#${K(this.r)}${K(this.g)}${K(this.b)}${K(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:U,toString:U})),A(J,(function(t,e,n,i){return 1===arguments.length?Z(t):new J(t,e,n,null==i?1:i)}),N(k,{brighter(t){return t=null==t?M:Math.pow(M,t),new J(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?E:Math.pow(E,t),new J(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 Y(nt(t>=240?t-240:t+120,r,i),nt(t,r,i),nt(t<120?t+240:t-120,r,i),this.opacity)},clamp(){return new J(tt(this.h),et(this.s),et(this.l),G(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=G(this.opacity);return`${1===t?"hsl(":"hsla("}${tt(this.h)}, ${100*et(this.s)}%, ${100*et(this.l)}%${1===t?")":`, ${t})`}`}}));var it=t=>()=>t;function rt(t){return 1==(t=+t)?at: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):it(isNaN(e)?n:e)}}function at(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):it(isNaN(t)?e:t)}var ot=function t(e){var n=rt(e);function i(t,e){var i=n((t=q(t)).r,(e=q(e)).r),r=n(t.g,e.g),a=n(t.b,e.b),o=at(t.opacity,e.opacity);return function(e){return t.r=i(e),t.g=r(e),t.b=a(e),t.opacity=o(e),t+""}}return i.gamma=t,i}(1);function st(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}var ht=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,lt=new RegExp(ht.source,"g");function ut(t,e){var n,i,r,a=ht.lastIndex=lt.lastIndex=0,o=-1,s=[],h=[];for(t+="",e+="";(n=ht.exec(t))&&(i=lt.exec(e));)(r=i.index)>a&&(r=e.slice(a,r),s[o]?s[o]+=r:s[++o]=r),(n=n[0])===(i=i[0])?s[o]?s[o]+=i:s[++o]=i:(s[++o]=null,h.push({i:o,x:st(n,i)})),a=lt.lastIndex;return a180?e+=360:e-t>180&&(t+=360),a.push({i:n.push(r(n)+"rotate(",null,i)-2,x:st(t,e)})):e&&n.push(r(n)+"rotate("+e+i)}(a.rotate,o.rotate,s,h),function(t,e,n,a){t!==e?a.push({i:n.push(r(n)+"skewX(",null,i)-2,x:st(t,e)}):e&&n.push(r(n)+"skewX("+e+i)}(a.skewX,o.skewX,s,h),function(t,e,n,i,a,o){if(t!==n||e!==i){var s=a.push(r(a)+"scale(",null,",",null,")");o.push({i:s-4,x:st(t,n)},{i:s-2,x:st(e,i)})}else 1===n&&1===i||a.push(r(a)+"scale("+n+","+i+")")}(a.scaleX,a.scaleY,o.scaleX,o.scaleY,s,h),a=o=null,function(t){for(var e,n=-1,i=h.length;++n=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),xt.hasOwnProperty(e)?{space:xt[e],local:t}:t}function At(t){return function(){var e=this.ownerDocument,n=this.namespaceURI;return n===wt&&e.documentElement.namespaceURI===wt?e.createElement(t):e.createElementNS(n,t)}}function Nt(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function kt(t){var e=bt(t);return(e.local?Nt:At)(e)}function Et(){}function Mt(t){return null==t?Et:function(){return this.querySelector(t)}}function $t(t){return null==t?[]:Array.isArray(t)?t:Array.from(t)}function zt(){return[]}function Tt(t){return null==t?zt:function(){return this.querySelectorAll(t)}}function St(t){return function(){return this.matches(t)}}function Rt(t){return function(e){return e.matches(t)}}var Pt=Array.prototype.find;function Ot(){return this.firstElementChild}var Ct=Array.prototype.filter;function Dt(){return Array.from(this.children)}function It(t){return new Array(t.length)}function Lt(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function Xt(t,e,n,i,r,a){for(var o,s=0,h=e.length,l=a.length;se?1:t>=e?0:NaN}function qt(t){return function(){this.removeAttribute(t)}}function Yt(t){return function(){this.removeAttributeNS(t.space,t.local)}}function Vt(t,e){return function(){this.setAttribute(t,e)}}function Ut(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function Gt(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function Ft(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 Kt(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function Qt(t){return function(){this.style.removeProperty(t)}}function Zt(t,e,n){return function(){this.style.setProperty(t,e,n)}}function Jt(t,e,n){return function(){var i=e.apply(this,arguments);null==i?this.style.removeProperty(t):this.style.setProperty(t,i,n)}}function te(t,e){return t.style.getPropertyValue(e)||Kt(t).getComputedStyle(t,null).getPropertyValue(e)}function ee(t){return function(){delete this[t]}}function ne(t,e){return function(){this[t]=e}}function ie(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function re(t){return t.trim().split(/^|\s+/)}function ae(t){return t.classList||new oe(t)}function oe(t){this._node=t,this._names=re(t.getAttribute("class")||"")}function se(t,e){for(var n=ae(t),i=-1,r=e.length;++i=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var ze=[null];function Te(t,e){this._groups=t,this._parents=e}function Se(){return new Te([[document.documentElement]],ze)}function Re(t){return"string"==typeof t?new Te([[document.querySelector(t)]],[document.documentElement]):new Te([[t]],ze)}function Pe(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]}Te.prototype=Se.prototype={constructor:Te,select:function(t){"function"!=typeof t&&(t=Mt(t));for(var e=this._groups,n=e.length,i=new Array(n),r=0;r=x&&(x=w+1);!(v=m[x])&&++x=0;)(i=r[a])&&(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=jt);for(var n=this._groups,i=n.length,r=new Array(i),a=0;a1?this.each((null==e?Qt:"function"==typeof e?Jt:Zt)(t,e,null==n?"":n)):te(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?ee:"function"==typeof e?ie:ne)(t,e)):this.node()[t]},classed:function(t,e){var n=re(t+"");if(arguments.length<2){for(var i=ae(this.node()),r=-1,a=n.length;++r=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}}))}(t+""),o=a.length;if(!(arguments.length<2)){for(s=e?ke:Ne,i=0;i=0&&e._call.call(void 0,t),e=e._next;--De}()}finally{De=0,function(){for(var t,e,n=Oe,i=1/0;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:Oe=e);Ce=t,Qe(i)}(),He=0}}function Ke(){var t=je.now(),e=t-Be;e>Xe&&(We-=e,Be=t)}function Qe(t){De||(Ie&&(Ie=clearTimeout(Ie)),t-He>24?(t<1/0&&(Ie=setTimeout(Fe,t-je.now()-We)),Le&&(Le=clearInterval(Le))):(Le||(Be=je.now(),Le=setInterval(Ke,Xe)),De=1,qe(Fe)))}function Ze(t,e,n){var i=new Ue;return e=null==e?0:+e,i.restart((n=>{i.stop(),t(n+e)}),e,n),i}Ue.prototype=Ge.prototype={constructor:Ue,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?Ye():+n)+(null==e?0:+e),this._next||Ce===this||(Ce?Ce._next=this:Oe=this,Ce=this),this._call=t,this._time=n,Qe()},stop:function(){this._call&&(this._call=null,this._time=1/0,Qe())}};var Je={value:()=>{}};function tn(){for(var t,e=0,n=arguments.length,i={};e=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,s=a.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++o0)for(var n,i,r=new Array(n),a=0;asn)throw new Error("too late; already scheduled");return n}function _n(t,e){var n=mn(t,e);if(n.state>un)throw new Error("too late; already running");return n}function mn(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function yn(t,e){var n,i,r,a=t.__transition,o=!0;if(a){for(r in e=null==e?null:e+"",a)(n=a[r]).name===e?(i=n.state>ln&&n.state=0&&(t=t.slice(0,e)),!t||"start"===t}))}(e)?gn:_n;return function(){var o=a(this,t),s=o.on;s!==i&&(r=(i=s).copy()).on(e,n),o.on=r}}(n,t,e))},attr:function(t,e){var n=bt(t),i="transform"===n?mt:bn;return this.attrTween(t,"function"==typeof e?(n.local?$n:Mn)(n,i,xn(this,"attr."+t,e)):null==e?(n.local?Nn:An)(n):(n.local?En:kn)(n,i,e))},attrTween:function(t,e){var n="attr."+t;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(null==e)return this.tween(n,null);if("function"!=typeof e)throw new Error;var i=bt(t);return this.tween(n,(i.local?zn:Tn)(i,e))},style:function(t,e,n){var i="transform"==(t+="")?_t:bn;return null==e?this.styleTween(t,function(t,e){var n,i,r;return function(){var a=te(this,t),o=(this.style.removeProperty(t),te(this,t));return a===o?null:a===n&&o===i?r:r=e(n=a,i=o)}}(t,i)).on("end.style."+t,Dn(t)):"function"==typeof e?this.styleTween(t,function(t,e,n){var i,r,a;return function(){var o=te(this,t),s=n(this),h=s+"";return null==s&&(this.style.removeProperty(t),h=s=te(this,t)),o===h?null:o===i&&h===r?a:(r=h,a=e(i=o,s))}}(t,i,xn(this,"style."+t,e))).each(function(t,e){var n,i,r,a,o="style."+e,s="end."+o;return function(){var h=_n(this,t),l=h.on,u=null==h.value[o]?a||(a=Dn(e)):void 0;l===n&&r===u||(i=(n=l).copy()).on(s,r=u),h.on=i}}(this._id,t)):this.styleTween(t,function(t,e,n){var i,r,a=n+"";return function(){var o=te(this,t);return o===a?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 a(){var a=e.apply(this,arguments);return a!==r&&(i=(r=a)&&function(t,e,n){return function(i){this.style.setProperty(t,e.call(this,i),n)}}(t,a,n)),i}return a._value=e,a}(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}}(xn(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=mn(this.node(),n).tween,a=0,o=r.length;a()=>t;function Vn(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 Un(t,e,n){this.k=t,this.x=e,this.y=n}Un.prototype={constructor:Un,scale:function(t){return 1===t?this:new Un(this.k*t,this.x,this.y)},translate:function(t,e){return 0===t&0===e?this:new Un(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 Gn=new Un(1,0,0);function Fn(t){for(;!t.__zoom;)if(!(t=t.parentNode))return Gn;return t.__zoom}function Kn(t){t.stopImmediatePropagation()}function Qn(t){t.preventDefault(),t.stopImmediatePropagation()}function Zn(t){return!(t.ctrlKey&&"wheel"!==t.type||t.button)}function Jn(){var t=this;return t instanceof SVGElement?(t=t.ownerSVGElement||t).hasAttribute("viewBox")?[[(t=t.viewBox.baseVal).x,t.y],[t.x+t.width,t.y+t.height]]:[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]:[[0,0],[t.clientWidth,t.clientHeight]]}function ti(){return this.__zoom||Gn}function ei(t){return-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function ni(){return navigator.maxTouchPoints||"ontouchstart"in this}function ii(t,e,n){var i=t.invertX(e[0][0])-n[0][0],r=t.invertX(e[1][0])-n[1][0],a=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>a?(a+o)/2:Math.min(0,a)||Math.max(0,o))}function ri(){var t,e,n,i=Zn,r=Jn,a=ii,o=ei,s=ni,h=[0,1/0],l=[[-1/0,-1/0],[1/0,1/0]],u=250,c=vt,f=tn("start","zoom","end"),d=500,p=150,g=0,_=10;function m(t){t.property("__zoom",ti).on("wheel.zoom",N,{passive:!1}).on("mousedown.zoom",k).on("dblclick.zoom",E).filter(s).on("touchstart.zoom",M).on("touchmove.zoom",$).on("touchend.zoom touchcancel.zoom",z).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function y(t,e){return(e=Math.max(h[0],Math.min(h[1],e)))===t.k?t:new Un(e,t.x,t.y)}function v(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 Un(t.k,i,r)}function w(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function x(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,a=arguments,o=b(t,a).event(i),s=r.apply(t,a),h=null==n?w(s):"function"==typeof n?n.apply(t,a):n,l=Math.max(s[1][0]-s[0][0],s[1][1]-s[0][1]),u=t.__zoom,f="function"==typeof e?e.apply(t,a):e,d=c(u.invert(h).concat(l/u.k),f.invert(h).concat(l/f.k));return function(t){if(1===t)t=f;else{var e=d(t),n=l/e[2];t=new Un(n,h[0]-e[0]*n,h[1]-e[1]*n)}o.zoom(null,t)}}))}function b(t,e,n){return!n&&t.__zooming||new A(t,e)}function A(t,e){this.that=t,this.args=e,this.active=0,this.sourceEvent=null,this.extent=r.apply(t,e),this.taps=0}function N(t,...e){if(i.apply(this,arguments)){var n=b(this,e).event(t),r=this.__zoom,s=Math.max(h[0],Math.min(h[1],r.k*Math.pow(2,o.apply(this,arguments)))),u=Pe(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===s)return;n.mouse=[u,r.invert(u)],yn(this),n.start()}Qn(t),n.wheel=setTimeout((function(){n.wheel=null,n.end()}),p),n.zoom("mouse",a(v(y(r,s),n.mouse[0],n.mouse[1]),n.extent,l))}}function k(t,...e){if(!n&&i.apply(this,arguments)){var r=t.currentTarget,o=b(this,e,!0).event(t),s=Re(t.view).on("mousemove.zoom",(function(t){if(Qn(t),!o.moved){var e=t.clientX-u,n=t.clientY-c;o.moved=e*e+n*n>g}o.event(t).zoom("mouse",a(v(o.that.__zoom,o.mouse[0]=Pe(t,r),o.mouse[1]),o.extent,l))}),!0).on("mouseup.zoom",(function(t){s.on("mousemove.zoom mouseup.zoom",null),function(t,e){var n=t.document.documentElement,i=Re(t).on("dragstart.drag",null);e&&(i.on("click.drag",qn,jn),setTimeout((function(){i.on("click.drag",null)}),0)),"onselectstart"in n?i.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}(t.view,o.moved),Qn(t),o.event(t).end()}),!0),h=Pe(t,r),u=t.clientX,c=t.clientY;!function(t){var e=t.document.documentElement,n=Re(t).on("dragstart.drag",qn,jn);"onselectstart"in e?n.on("selectstart.drag",qn,jn):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}(t.view),Kn(t),o.mouse=[h,this.__zoom.invert(h)],yn(this),o.start()}}function E(t,...e){if(i.apply(this,arguments)){var n=this.__zoom,o=Pe(t.changedTouches?t.changedTouches[0]:t,this),s=n.invert(o),h=n.k*(t.shiftKey?.5:2),c=a(v(y(n,h),o,s),r.apply(this,e),l);Qn(t),u>0?Re(this).transition().duration(u).call(x,c,o,t):Re(this).call(m.transform,c,o,t)}}function M(n,...r){if(i.apply(this,arguments)){var a,o,s,h,l=n.touches,u=l.length,c=b(this,r,n.changedTouches.length===u).event(n);for(Kn(n),o=0;o=0&&(a-=hi(t,e)),null===t.coords&&(n.moveTo(t.spouse.x+r,a),n.lineTo(t.source.x-r,a)),t.coords&&t.coords.length>0){for(let e=0;e0&&(o=t.coords[e-1].x+r);let h=e>0?i:0,l=e+1<=t.coords.length?i:0;n.moveTo(o+h,a),n.lineTo(s-l,a)}n.moveTo(t.coords[t.coords.length-1].x+r+i,a),n.lineTo(t.source.x-r,a)}return n.toString()}(t,e)}function hi(t,e){return(t.source.data.family-Math.ceil(t.spouse.data.spouses.length/2))*e.direction*5}class li extends oi{constructor(t,e){super(t,e),this._splittNames=!0}get direction(){return 1}get nodeWidth(){return this._boxWidth+this._xOffset}get nodeHeight(){return this._boxHeight+this._yOffset}norm(t){t.y*=this.direction}elbow(t){return si(t,this)}}class ui extends oi{constructor(t,e){super(t,e),this._splittNames=!0}get direction(){return-1}get nodeWidth(){return this._boxWidth+this._xOffset}get nodeHeight(){return this._boxHeight+this._yOffset}norm(t){t.y*=this.direction}elbow(t){return si(t,this)}}function ci(t,e){const n=e.xOffset/2,i=e.yOffset/2;let r=t.source.x,a=t.source.y;if(void 0!==t.spouse&&0===t.source.data.family?(r-=fi(t,e),a-=(t.source.y-t.spouse.y)/2):r+=e.boxWidth/2*e.direction,null===t.source.data.data&&(r+=e.boxWidth/2*e.direction,a-=e.boxHeight/2+i/2),null!==t.target){let i=t.target.x-e.direction*(e.boxWidth/2+n),o=t.target.y;const s=b();return s.moveTo(r,a),s.lineTo(i,a),s.lineTo(i,o),s.lineTo(i+e.direction*n,o),s.toString()}return function(t,e){const n=b(),i=2,r=e.boxHeight/2;let a=t.source.x;if(t.spouse.data.spouses.length>=0&&(a-=fi(t,e)),null===t.coords&&(n.moveTo(a,t.spouse.y+r),n.lineTo(a,t.source.y-r)),t.coords&&t.coords.length>0){for(let e=0;e0&&(o=t.coords[e-1].y+r);let h=e>0?i:0,l=e+1<=t.coords.length?i:0;n.moveTo(a,o+h),n.lineTo(a,s-l)}n.moveTo(a,t.coords[t.coords.length-1].y+r+i),n.lineTo(a,t.source.y-r)}return n.toString()}(t,e)}function fi(t,e){return(t.source.data.family-Math.ceil(t.spouse.data.spouses.length/2))*e.direction*5}class di extends oi{constructor(t,e){super(t,e),this._xOffset=40,this._yOffset=20}get direction(){return this.isDocumentRtl?-1:1}get nodeWidth(){return this._boxHeight+this._yOffset}get nodeHeight(){return this._boxWidth+this._xOffset}norm(t){[t.x,t.y]=[t.y*this.direction,t.x]}elbow(t){return ci(t,this)}}class pi extends oi{constructor(t,e){super(t,e),this._xOffset=40,this._yOffset=20}get direction(){return this.isDocumentRtl?1:-1}get nodeWidth(){return this._boxHeight+this._yOffset}get nodeHeight(){return this._boxWidth+this._xOffset}norm(t){[t.x,t.y]=[t.y*this.direction,t.x]}elbow(t){return ci(t,this)}}class gi{constructor(){this._orientations={down:new li(160,175),up:new ui(160,175),[ai]:new di(325,95),left:new pi(325,95)}}get(){return this._orientations}}class _i{constructor(t,e=4,n=ai,i=!0,r=!0,a=!1,o=1){this._treeLayout=n,this._orientations=new gi,this._openNewTabOnClick=i,this._showAlternativeName=r,this.duration=750,this.padding=15,this._generations=e,this.textPadding=8,this._fontSize=14,this.fontColor="rgb(0, 0, 0)",this.rtl=a,this.labels=t,this.direction=o}get generations(){return this._generations}set generations(t){this._generations=t}get treeLayout(){return this._treeLayout}set treeLayout(t){this._treeLayout=t}get orientation(){return this._orientations.get()[this.treeLayout]}get openNewTabOnClick(){return this._openNewTabOnClick}get showAlternativeName(){return this._showAlternativeName}}class mi{constructor(t){this._configuration=t,this._nodes=null,this._root=null}init(t){this._configuration.showAlternativeName&&(this._configuration.orientation instanceof li||this._configuration.orientation instanceof ui)&&(this._configuration.orientation.boxHeight+=30),this._root=i(t),this._root.descendants().forEach(((t,e)=>{t.id=e}))}get nodes(){return this._nodes}get root(){return this._root}}class yi{constructor(t){this._element=t.append("defs")}get(){return this._element}}class vi{constructor(t){this._zoom=null,this._parent=t,this.init()}init(){this._zoom=ri(),this._zoom.scaleExtent([.1,20]).on("zoom",(t=>{this._parent.attr("transform",t.transform)})),this._zoom.wheelDelta((t=>-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002))),this._zoom.filter((t=>{if("wheel"===t.type){if(!t.ctrlKey)return!1;const e=Fn(this);if(e.k){if(e.k<=.1&&t.deltaY>0)return t.preventDefault(),!1;if(e.k>=20&&t.deltaY<0)return t.preventDefault(),!1}return!0}return t.button||"touchstart"!==t.type?!(t.ctrlKey&&"wheel"!==t.type||t.button):2===t.touches.length}))}get(){return this._zoom}}class wi{triggerDownload(t,e){let n=new MouseEvent("click",{view:window,bubbles:!1,cancelable:!0}),i=document.createElement("a");i.setAttribute("download",e),i.setAttribute("href",t),i.setAttribute("target","_blank"),i.dispatchEvent(n)}}class xi extends wi{copyStylesInline(t,e){let n=["svg","g","text","textPath"];for(let i=0;i{let r=(new XMLSerializer).serializeToString(t),a=window.URL||window.webkitURL||window,o=new Blob([r],{type:"image/svg+xml;charset=utf-8"}),s=a.createObjectURL(o),h=new Image;h.onload=()=>{let t=this.createCanvas(e,n),r=t.getContext("2d");r.fillStyle="rgb(255,255,255)",r.fillRect(0,0,t.width,t.height),r.drawImage(h,0,0),a.revokeObjectURL(s);let o=t.toDataURL("image/png").replace("image/png","image/octet-stream");i(o)},h.src=s}))}cloneSvg(t){return new Promise((e=>{e(t.cloneNode(!0))}))}svgToImage(t,e){const n=[4960,3508];this.cloneSvg(t.get().node()).then((e=>{this.copyStylesInline(t.get().node(),e);const i=this.calculateViewBox(t.get().node()),r=Math.max(n[0],i[2]),a=Math.max(n[1],i[3]);return e.setAttribute("width",""+r),e.setAttribute("height",""+a),e.setAttribute("viewBox",""+i),this.convertToDataUrl(e,r,a)})).then((t=>this.triggerDownload(t,e))).catch((()=>{console.log("Failed to save chart as PNG image")}))}}class bi extends wi{replaceCssVariables(t){const e=new RegExp("\\s*([^,}\\/\\s].*)(?!e[t]&&(e[t]=!0))).sort()}copyStylesInline(t,n,i){n.classList.add("wt-global");const r=n.querySelectorAll("[class]"),a=this.extractClassNames(r);a.push("wt-global",i);const o=document.createElementNS("http://www.w3.org/2000/svg","style");let s=new Map;return new Promise((r=>{Promise.all(t.map((t=>function(t,n){return fetch(t,n).then(e)}(t)))).then((t=>{t.forEach((t=>{const e="\\."+a.join("|\\."),n=new RegExp("(([^,}]*)("+e+"))\\b(?!-)[^}]*}","g");let i;for(;null!==(i=n.exec(t));)i.index===n.lastIndex&&n.lastIndex++,s.set(JSON.stringify(i[0]),i[0])}));let e=[...s.values()].flat().join("\n");e=this.replaceCssVariables(e),e=e.replaceAll("."+i+" ",""),o.appendChild(document.createTextNode(e)),n.prepend(o),r(n)}))}))}convertToObjectUrl(t){return new Promise((e=>{let n=(new XMLSerializer).serializeToString(t),i=window.URL||window.webkitURL||window,r=new Blob([n],{type:"image/svg+xml;charset=utf-8"}),a=i.createObjectURL(r),o=new Image;o.onload=()=>{e(a)},o.src=a}))}cloneSvg(t){return new Promise((e=>{e(t.cloneNode(!0))}))}svgToImage(t,e,n,i){this.cloneSvg(t.get().node()).then((t=>this.copyStylesInline(e,t,n))).then((t=>this.convertToObjectUrl(t))).then((t=>this.triggerDownload(t,i))).catch((()=>{console.log("Failed to save chart as SVG image")}))}}class Ai{constructor(){this._exportClass=null}setExportClass(t){switch(t){case"png":this._exportClass=xi;break;case"svg":this._exportClass=bi}}createExport(t){switch(this.setExportClass(t),t){case"png":case"svg":return new this._exportClass}}}class Ni{constructor(t,e){this._element=t.append("svg"),this._defs=new yi(this._element),this._visual=null,this._zoom=null,this._configuration=e,this.init()}init(){this._element.attr("width","100%").attr("height","100%").attr("text-rendering","optimizeLegibility").attr("text-anchor","middle").attr("xmlns:xlink","https://www.w3.org/1999/xlink")}initEvents(t){this._element.on("contextmenu",(t=>t.preventDefault())).on("wheel",(e=>{e.ctrlKey||t.show(this._configuration.labels.zoom,300,(()=>{t.hide(200,600)}))})).on("touchend",(e=>{e.touches.length<2&&t.hide(0,600)})).on("touchmove",(e=>{e.touches.length>=2?t.hide():t.show(this._configuration.labels.move)})).on("click",(t=>this.doStopPropagation(t)),!0),this._configuration.rtl&&this._element.classed("rtl",!0),this._visual=this._element.append("g"),this._zoom=new vi(this._visual),this._element.call(this._zoom.get())}doStopPropagation(t){t.defaultPrevented&&t.stopPropagation()}export(t){return(new Ai).createExport(t)}get defs(){return this._defs}get zoom(){return this._zoom}get visual(){return this._visual}get(){return this._element}}class ki{constructor(t){this._element=t.append("div").attr("class","overlay").style("opacity",1e-6)}show(t,e=0,n=null){this._element.select("p").remove(),this._element.append("p").attr("class","tooltip").text(t),this._element.transition().duration(e).style("opacity",1).on("end",(()=>{"function"==typeof n&&n()}))}hide(t=0,e=0){this._element.transition().delay(t).duration(e).style("opacity",1e-6)}get(){return this._element}}let Ei=null;function Mi(t,e,n,i=400){null===Ei&&(Ei=document.createElement("canvas"));const r=Ei.getContext("2d"),a=`${i||""} ${n} ${e}`;return r.font!==a&&(r.font=a),r.measureText(t).width}class $i{constructor(t,e,n,i){this._svg=t,this._orientation=e,this._image=n,this._text=i}appendName(t){const e=t.append("g").attr("class","name");if(this._orientation instanceof li||this._orientation instanceof ui){const t=this,n=e.selectAll("text").data((t=>[{data:t.data,isRtl:t.data.data.isNameRtl,isAltRtl:t.data.data.isAltRtl,withImage:!0}])).enter();n.each((function(e){const n=Re(this),i=t.createNamesData(e),r=t.getAvailableWidth(e);i.forEach(((e,i)=>{const a=n.append("text").attr("class","wt-chart-box-name").attr("direction",(t=>t.isRtl?"rtl":"ltr")).attr("text-anchor","middle").attr("alignment-baseline","central").attr("y",t._text.y-5+20*i);t.addNameElements(a,t.truncateNamesData(a,e,r))}))})),this._svg._configuration.showAlternativeName&&n.filter((t=>""!==t.data.data.alternativeName)).call((t=>{const e=t.append("text").classed("wt-chart-box-name-alt",!0).attr("class","wt-chart-box-name").attr("direction",(t=>t.isAltRtl?"rtl":"ltr")).attr("text-anchor","middle").attr("alignment-baseline","central").attr("y",this._text.y+40);this.addNameElements(e,(t=>this.truncateNamesData(e,this.createAlternativeNamesData(t),this.getAvailableWidth(t))))}))}else{const t=e.selectAll("text").data((t=>[{data:t.data,isRtl:t.data.data.isNameRtl,isAltRtl:t.data.data.isAltRtl,withImage:""!==t.data.data.thumbnail}])).enter();t.call((t=>{const e=t.append("text").attr("class","wt-chart-box-name").attr("direction",(t=>t.isRtl?"rtl":"ltr")).attr("text-anchor",(t=>t.isRtl&&this._orientation.isDocumentRtl?"start":t.isRtl||this._orientation.isDocumentRtl?"end":"start")).attr("x",(t=>this.textX(t))).attr("y",this._text.y-10);this.addNameElements(e,(t=>{const[n,...i]=this.createNamesData(t),r=[].concat(n,void 0!==i[0]?i[0]:[]);return this.truncateNamesData(e,r,this.getAvailableWidth(t))}))})),this._svg._configuration.showAlternativeName&&t.filter((t=>""!==t.data.data.alternativeName)).call((t=>{const e=t.append("text").classed("wt-chart-box-name-alt",!0).attr("class","wt-chart-box-name").attr("direction",(t=>t.isAltRtl?"rtl":"ltr")).attr("text-anchor",(t=>t.isAltRtl&&this._orientation.isDocumentRtl?"start":t.isAltRtl||this._orientation.isDocumentRtl?"end":"start")).attr("x",(t=>this.textX(t))).attr("y",this._text.y+8);this.addNameElements(e,(t=>this.truncateNamesData(e,this.createAlternativeNamesData(t),this.getAvailableWidth(t))))}))}}getAvailableWidth(t){let e=this._text.width;return t.withImage&&(this._orientation instanceof di||this._orientation instanceof pi)&&(e-=this._image.width),e}addNameElements(t,e){t.selectAll("tspan").data(e).enter().call((t=>{t.append("tspan").text((t=>t.label)).attr("dx",((t,e)=>0!==e?.25*(t.isNameRtl?-1:1)+"em":null)).classed("preferred",(t=>t.isPreferred)).classed("lastName",(t=>t.isLastName))}))}createNamesData(t){let e={},n={},i={},r=Number.MAX_SAFE_INTEGER,a=Number.MAX_SAFE_INTEGER,o=0;for(let e in t.data.data.firstNames){const i=t.data.data.name.indexOf(t.data.data.firstNames[e],o);-1!==i&&(o=i,i({label:e,isPreferred:!1,isLastName:!1,isNameRtl:t.data.data.isAltRtl})))),n}truncateNames(t,e,n,i){let r=t.map((t=>t.label)).join(" ");return t.reverse().map((a=>(!1===a.isPreferred&&!1===a.isLastName&&this.measureText(r,e,n)>i&&(a.label=a.label.slice(0,1)+".",r=t.map((t=>t.label)).join(" ")),a))).map((a=>(!0===a.isPreferred&&this.measureText(r,e,n)>i&&(a.label=a.label.slice(0,1)+".",r=t.map((t=>t.label)).join(" ")),a))).map((a=>(!0===a.isLastName&&this.measureText(r,e,n)>i&&(a.label=a.label.slice(0,1)+".",r=t.map((t=>t.label)).join(" ")),a))).reverse()}textX(t){const e=this._text.x+(t.withImage?this._image.width:0);return this._orientation.isDocumentRtl?-e:e}measureText(t,e,n=400){return Mi(t,this._svg.get().style("font-family"),e,n)}}let zi=class{constructor(t,e,n,i){this._svg=t,this._orientation=e,this._image=n,this._text=i}appendDate(t){const e=t.append("g");if(this._orientation instanceof li||this._orientation instanceof ui){const t=e.selectAll("text.date").data((t=>[{label:t.data.data.timespan,withImage:!0}])).enter();let n=this._text.y+45;this._svg._configuration.showAlternativeName&&(n+=30);const i=t.append("text").attr("class","date").attr("text-anchor","middle").attr("alignment-baseline","central").attr("y",n);i.append("title").text((t=>t.label));const r=i.append("tspan");r.text((t=>this.truncateDate(r,t.label,this._text.width)))}else e.selectAll("text").data((t=>{let e=[];return t.data.data.birth&&e.push({icon:"★",label:t.data.data.birth,birth:!0,withImage:""!==t.data.data.thumbnail}),t.data.data.death&&e.push({icon:"†",label:t.data.data.death,death:!0,withImage:""!==t.data.data.thumbnail}),e})).enter().call((t=>{t.append("text").attr("class","date").attr("text-anchor","middle").attr("dominant-baseline","middle").attr("x",(t=>this.textX(t))).attr("y",((t,e)=>this._text.y+30+(0===e?0:21))).append("tspan").text((t=>t.icon)).attr("dx",5*(this._orientation.isDocumentRtl?-1:1));const e=t.append("text").attr("class","date").attr("text-anchor","start").attr("dominant-baseline","middle").attr("x",(t=>this.textX(t))).attr("y",((t,e)=>this._text.y+30+(0===e?0:20)));e.append("title").text((t=>t.label));const n=e.append("tspan");n.text((t=>this.truncateDate(n,t.label,this._text.width-(t.withImage?this._image.width:0)-25))).attr("dx",15*(this._orientation.isDocumentRtl?-1:1))}))}truncateDate(t,e,n){const i=t.style("font-size"),r=t.style("font-weight");let a=!1;for(;this.measureText(e,i,r)>n&&e.length>1;)e=e.slice(0,-1).trim(),a=!0;return"."===e[e.length-1]&&(e=e.slice(0,-1).trim()),a?e+"…":e}textX(t){const e=this._text.x+(t.withImage?this._image.width:0);return this._orientation.isDocumentRtl?-e:e}measureText(t,e,n=400){return Mi(t,this._svg.get().style("font-family"),e,n)}},Ti=class{constructor(t,e){this._orientation=t,this._cornerRadius=e,this._imagePadding=5,this._imageRadius=Math.min(40,this._orientation.boxHeight/2-this._imagePadding),this._width=this.calculateImageWidth(),this._height=this.calculateImageHeight(),this._rx=this.calculateCornerRadius(),this._ry=this.calculateCornerRadius(),this._x=this.calculateX(),this._y=this.calculateY()}calculateX(){return this._orientation instanceof di||this._orientation instanceof pi?this._orientation.isDocumentRtl?this._width-this._imagePadding:-(this._orientation.boxWidth-this._imagePadding)/2+this._imagePadding:-this._orientation.boxWidth/2+this._width/2}calculateY(){return this._orientation instanceof di||this._orientation instanceof pi?-this._imageRadius:-(this._orientation.boxHeight-this._imagePadding)/2+this._imagePadding}calculateImageWidth(){return 2*this._imageRadius}calculateImageHeight(){return 2*this._imageRadius}calculateCornerRadius(){return this._cornerRadius-this._imagePadding}get x(){return this._x}get y(){return this._y}get rx(){return this._rx}get ry(){return this._ry}get width(){return this._width}get height(){return this._height}};class Si{constructor(t,e=null){this._orientation=t,this._image=e,this._textPaddingX=15,this._textPaddingY=15,(this._orientation instanceof li||this._orientation instanceof ui)&&(this._textPaddingX=5,this._textPaddingY=15),this._x=this.calculateX(),this._y=this.calculateY(),this._width=this.calculateWidth()}calculateX(){return-this._orientation.boxWidth/2+this._textPaddingX}calculateY(){return this._orientation instanceof di||this._orientation instanceof pi?-this._textPaddingY:this._image.y+this._image.height+2*this._textPaddingY}calculateWidth(){return this._orientation.boxWidth-2*this._textPaddingX}get x(){return this._x}get y(){return this._y}get width(){return this._width}}class Ri{constructor(t,e,n){this._svg=t,this._hierarchy=e,this._configuration=n,this._orientation=this._configuration.orientation,this._image=new Ti(this._orientation,20),this._text=new Si(this._orientation,this._image),this._name=new $i(this._svg,this._orientation,this._image,this._text),this._date=new zi(this._svg,this._orientation,this._image,this._text)}drawNodes(t,e){this._svg.defs.get().append("clipPath").attr("id","clip-image").append("rect").attr("rx",this._image.rx).attr("ry",this._image.ry).attr("x",this._image.x).attr("y",this._image.y).attr("width",this._image.width).attr("height",this._image.height),this._svg.visual.selectAll("g.person").data(t,(t=>t.id)).join((t=>this.nodeEnter(t,e)),(t=>this.nodeUpdate(t)),(t=>this.nodeExit(t,e))),this._hierarchy.root.eachBefore((t=>{t.x0=t.x,t.y0=t.y}))}nodeEnter(t,e){t.append("g").attr("opacity",0).attr("class","person").attr("transform",(t=>"translate("+t.x+","+t.y+")")).call((t=>{t.append("rect").attr("class",(t=>"F"===t.data.data.sex?"female":"M"===t.data.data.sex?"male":"unknown")).classed("spouse",(t=>t.data.spouse)).attr("rx",20).attr("ry",20).attr("x",-this._orientation.boxWidth/2).attr("y",-this._orientation.boxHeight/2).attr("width",this._orientation.boxWidth).attr("height",this._orientation.boxHeight).attr("fill-opacity",.5),t.append("title").text((t=>t.data.data.name))})).call((t=>this.drawNode(t))).call((t=>t.transition().duration(this._configuration.duration).attr("opacity",1)))}nodeUpdate(t){t.call((t=>t.transition().duration(this._configuration.duration).attr("opacity",1).attr("transform",(t=>"translate("+t.x+","+t.y+")"))))}nodeExit(t,e){t.call((t=>t.transition().duration(this._configuration.duration).attr("opacity",0).attr("transform",(()=>"translate("+e.x0+","+e.y0+")")).remove()))}drawNode(t){const e=t.selectAll("g.image").data((t=>{let e=[];return t.data.data.thumbnail&&e.push({image:t.data.data.thumbnail}),e})).enter().append("g").attr("class","image");e.append("rect").attr("x",this._image.x).attr("y",this._image.y).attr("width",this._image.width).attr("height",this._image.height).attr("rx",this._image.rx).attr("ry",this._image.ry).attr("fill","rgb(255, 255, 255)"),e.append("image").attr("x",this._image.x).attr("y",this._image.y).attr("width",this._image.width).attr("height",this._image.height).attr("clip-path","url(#clip-image)"),e.append("rect").attr("x",this._image.x).attr("y",this._image.y).attr("width",this._image.width).attr("height",this._image.height).attr("rx",this._image.rx).attr("ry",this._image.ry).attr("fill","none").attr("stroke","rgb(200, 200, 200)").attr("stroke-width",1.5),function(t){return"string"==typeof t?new Te([document.querySelectorAll(t)],[document.documentElement]):new Te([$t(t)],ze)}("g.image image").each((function(t){let e=Re(this);(function(t,e=null){return fetch(t,e).then((t=>t.blob())).then((t=>new Promise(((e,n)=>{const i=new FileReader;i.onloadend=()=>e(i.result),i.onerror=n,i.readAsDataURL(t)}))))})(t.image).then((t=>e.attr("xlink:href",t))).catch((t=>{console.error(t)}))})),this._name.appendName(t),this._date.appendDate(t)}}class Pi{constructor(t,e){this._svg=t,this._configuration=e,this._orientation=this._configuration.orientation}drawLinks(t,e){this._svg.visual.selectAll("path.link").data(t).join((t=>this.linkEnter(t,e)),(t=>this.linkUpdate(t)),(t=>this.linkExit(t,e)))}linkEnter(t,e){t.append("path").classed("link",!0).attr("d",(t=>this._orientation.elbow(t))).call((t=>t.transition().duration(this._configuration.duration).attr("opacity",1)))}linkUpdate(t){}linkExit(t,e){}}class Oi{constructor(t,e,n){this._svg=t,this._configuration=e,this._hierarchy=n,this._hierarchy.root.x0=0,this._hierarchy.root.y0=0,this._orientation=this._configuration.orientation,this._nodeDrawer=new Ri(this._svg,this._hierarchy,this._configuration),this._linkDrawer=new Pi(this._svg,this._configuration),this.draw(this._hierarchy.root)}separation(t,e){return Object.hasOwn(t.data,"spouses")||Object.hasOwn(e.data,"spouse")?1.25:t.parent===e.parent?1:2}draw(t){const e=g().nodeSize([this._configuration.orientation.nodeWidth,this._configuration.orientation.nodeHeight]).separation(this.separation);this._nodes=e(this._hierarchy.root),this._hierarchy.root.each((t=>{this._configuration.orientation.norm(t)}));let n=this._hierarchy.root.descendants(),i=[];n.shift(),n.forEach((t=>{if(t.data&&Array.isArray(t.data.spouses)&&t.data.spouses.length>=1){const e=this.findSpouseById(t.data.spouses[0],n);this._orientation instanceof li||this._orientation instanceof ui?t.x=e.x-this._orientation.nodeWidth:t.y=e.y-this._orientation.nodeWidth}}));const r=n.find((t=>t.children&&t.children.length>0));if(void 0!==r){const t=this._orientation.nodeWidth/2;r.each((e=>{Object.hasOwn(e.data,"spouse")&&null!==e.data.spouse&&Object.hasOwn(e,"children")&&Array.isArray(e.children)&&e.children.length>=1&&this.moveChildren(e,t)}))}n.forEach((t=>{const e=this.findSpouseById(t.data.spouse,n);if(Object.hasOwn(t,"children")&&Array.isArray(t.children)&&t.children.length>0&&t.children.forEach((n=>{void 0!==n.data.spouse&&null!==n.data.spouse||i.push({spouse:e,source:t,target:n,coords:null})})),void 0!==e){let r=null;if(void 0!==e.data.spouses&&e.data.spouses.length>0){const i=e.data.spouses.indexOf(t.data.data.id),a=e.data.spouses.slice(0,i);a.length>0&&(r=[],a.forEach((t=>{const e=this.findSpouseById(t,n);void 0!==e&&r.push({x:e.x,y:e.y})})))}null!==t.data.data&&i.push({spouse:e,source:t,target:null,coords:r})}})),this._linkDrawer.drawLinks(i,t),this._nodeDrawer.drawNodes(n,t)}findSpouseById(t,e){return e.find((e=>e.data.data.id===t))}moveChildren(t,e){t.each((n=>{n.depth!==t.depth&&(0!==t.data.family&&1===t.children.length&&void 0===n.children||(this._orientation instanceof li||this._orientation instanceof ui?n.x-=e:n.y-=e))}))}centerTree(){console.log("centerTree")}togglePerson(t,e){e.children?(e._children=e.children,e.children=null):(e.children=e._children,e._children=null),this.draw(e)}}class Ci{constructor(t,e){this._configuration=e,this._parent=t,this._hierarchy=new mi(this._configuration),this._data={}}get svg(){return this._svg}updateViewBox(){let t=this._svg.visual.node().getBBox(),e=this._parent.node().getBoundingClientRect(),n=Math.max(e.width,t.width),i=Math.max(e.height,t.height,300),r=(n-t.width)/2,a=(i-t.height)/2,o=Math.ceil(t.x-r-10),s=Math.ceil(t.y-a-10);n=Math.ceil(n+20),i=Math.ceil(i+20),this._svg.get().attr("viewBox",[o,s,n,i])}get data(){return this._data}set data(t){this._data=t,this._hierarchy.init(this._data)}draw(){this._parent.html(""),this._svg=new Ni(this._parent,this._configuration),this._overlay=new ki(this._parent),this._svg.initEvents(this._overlay),new Oi(this._svg,this._configuration,this._hierarchy),this.bindClickEventListener(),this.updateViewBox()}bindClickEventListener(){let t=this;this._svg.visual.selectAll("g.person").filter((t=>""!==t.data.data.xref)).each((function(e){Re(this).on("click",(function(){t.personClick(e.data)}))}))}personClick(t){1===t.data.generation?this.redirectToIndividual(t.data.url):this.update(t.data.updateUrl)}redirectToIndividual(t){this._configuration.openNewTabOnClick?window.open(t,"_blank"):window.location=t}update(t){window.location=t}}t.DescendantsChart=class{constructor(t,e){this._selector=t,this._parent=Re(this._selector),this._configuration=new _i(e.labels,e.generations,e.treeLayout,e.openNewTabOnClick,e.showAlternativeName,e.rtl),this._cssFiles=e.cssFiles,this._chart=new Ci(this._parent,this._configuration),this.init(),this.draw(e.data)}init(){Re("#centerButton").on("click",(()=>this.center())),Re("#exportPNG").on("click",(()=>this.exportPNG())),Re("#exportSVG").on("click",(()=>this.exportSVG()))}center(){this._chart.svg.get().transition().duration(750).call(this._chart.svg.zoom.get().transform,Gn)}get configuration(){return this._configuration}update(t){this._chart.update(t)}draw(t){this._chart.data=t,this._chart.draw()}exportPNG(){this._chart.svg.export("png").svgToImage(this._chart.svg,"descendants-chart.png")}exportSVG(){this._chart.svg.export("svg").svgToImage(this._chart.svg,this._cssFiles,"webtrees-descendants-chart-container","descendants-chart.svg")}}},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).WebtreesDescendantsChart={}); diff --git a/resources/js/modules/lib/chart/svg/export/svg.js b/resources/js/modules/lib/chart/svg/export/svg.js index f6cd1da..1ba8a0b 100644 --- a/resources/js/modules/lib/chart/svg/export/svg.js +++ b/resources/js/modules/lib/chart/svg/export/svg.js @@ -17,6 +17,88 @@ import Export from "../export"; */ export default class SvgExport extends Export { + /** + * Replaces all CSS variables in the given CSS string with its computed style equivalent. + * + * @param {String} css + * + * @returns {String} + */ + replaceCssVariables(css) + { + // Match all CSS selectors and their content + const regexSelector = new RegExp("\\s*([^,}\\\/\\s].*)(?} elements + * + * @returns {String[]} + */ + extractClassNames(elements) + { + let classes = {}; + + return Array.prototype + .concat + .apply( + [], + [...elements].map(function (element) { + return [...element.classList]; + }) + ) + // Reduce the list of classNames to a unique list + .filter(name => !classes[name] && (classes[name] = true)) + .sort(); + } + /** * Copies recursively all the styles from the list of container elements from the source * to the destination node. @@ -29,22 +111,53 @@ export default class SvgExport extends Export */ copyStylesInline(cssFiles, destinationNode, containerClassName) { + // Assign class wt-global so theme related styles are correctly set in export + destinationNode.classList.add("wt-global"); + + const elementsWithClass = destinationNode.querySelectorAll("[class]"); + const usedClasses = this.extractClassNames(elementsWithClass); + usedClasses.push("wt-global", containerClassName); + + const style = document.createElementNS( + "http://www.w3.org/2000/svg", + "style" + ); + + let cssMap = new Map(); + return new Promise(resolve => { Promise .all(cssFiles.map(url => d3.text(url))) .then((filesData) => { filesData.forEach(data => { - // Remove parent container selector as the CSS is included directly in the SVG element - data = data.replace(new RegExp("." + containerClassName + " ", "g"), ""); + const classList = "\\." + usedClasses.join("|\\."); + const regex = new RegExp("(([^,}]*)(" + classList + "))\\b(?!-)[^}]*}", 'g') + + let matches; - let style = document.createElementNS("http://www.w3.org/2000/svg", "style"); - style.appendChild(document.createTextNode(data)); + while ((matches = regex.exec(data)) !== null) { + // This is necessary to avoid infinite loops with zero-width matches + if (matches.index === regex.lastIndex) { + regex.lastIndex++; + } - destinationNode.prepend(style); + // Store all matches CSS rules (merge duplicates into same entry) + cssMap.set( + JSON.stringify(matches[0]), + matches[0] + ); + } }); - // Assign class wt-global so theme related styles are correctly set in export - destinationNode.classList.add("wt-global"); + // Convert the CSS map to the final CSS string + let finalCss = [...cssMap.values()].flat().join("\n"); + + // Remove parent container selector as the CSS is included directly in the SVG element + finalCss = this.replaceCssVariables(finalCss); + finalCss = finalCss.replaceAll("." + containerClassName + " ", ""); + + style.appendChild(document.createTextNode(finalCss)); + destinationNode.prepend(style); resolve(destinationNode); }); @@ -61,11 +174,11 @@ export default class SvgExport extends Export convertToObjectUrl(svg) { return new Promise(resolve => { - let data = (new XMLSerializer()).serializeToString(svg); - let DOMURL = window.URL || window.webkitURL || window; + let data = (new XMLSerializer()).serializeToString(svg); + let DOMURL = window.URL || window.webkitURL || window; let svgBlob = new Blob([ data ], { type: "image/svg+xml;charset=utf-8" }); - let url = DOMURL.createObjectURL(svgBlob); - let img = new Image(); + let url = DOMURL.createObjectURL(svgBlob); + let img = new Image(); img.onload = () => { resolve(url); diff --git a/resources/js/modules/lib/tree/date.js b/resources/js/modules/lib/tree/date.js index b01f9b4..4360c5f 100644 --- a/resources/js/modules/lib/tree/date.js +++ b/resources/js/modules/lib/tree/date.js @@ -45,8 +45,7 @@ export default class Date appendDate(parent) { const table = parent - .append("g") - .attr("class", "table"); + .append("g"); // Top/Bottom and Bottom/Top if ((this._orientation instanceof OrientationTopBottom) @@ -112,7 +111,7 @@ export default class Date enter .call((g) => { const col1 = g.append("text") - .attr("fill", "currentColor") + .attr("class", "date") .attr("text-anchor", "middle") .attr("dominant-baseline", "middle") .attr("x", d => this.textX(d)) diff --git a/src/Module.php b/src/Module.php index dcf90b5..5168f29 100644 --- a/src/Module.php +++ b/src/Module.php @@ -285,7 +285,10 @@ private function getAjaxRoute(Individual $individual, string $xref): string */ private function getStylesheets(): array { - return [$this->assetUrl('css/descendants-chart.css'), $this->assetUrl('css/svg.css')]; + return [ + $this->assetUrl('css/descendants-chart.css'), + $this->assetUrl('css/svg.css'), + ]; } /**