UNPKG

family-chart

Version:
2 lines 109 kB
// https://donatso.github.io/family-chart/ v0.7.0 Copyright 2025 donatso !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("d3")):"function"==typeof define&&define.amd?define(["d3"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).f3=e(t.f3)}(this,(function(t){"use strict";function e(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,i.get?i:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var n=e(t),i="object"==typeof window&&window.d3?window.d3:n;function a(t,e,n){return n.find((n=>n.id!==e.id&&(n.id===t.rels.mother||n.id===t.rels.father)))}function r(t,e,n){if(t.exiting=n,e)0!==t.depth||t.spouse?t.spouse?(t._x=t.spouse.x,t._y=t.spouse.y):t.is_ancestry?(t._x=t.parent.x,t._y=t.parent.y):(t._x=t.psx,t._y=t.psy):(t._x=t.x,t._y=t.y);else if(n){const e=t.x>0?1:-1,n=t.y>0?1:-1;t._x=t.x+400*e,t._y=t.y+400*n}}function s(t,e){const n=e?"rels":"_rels",i=e?"_rels":"rels";function a(e){t.data[n]&&t.data[n][e]&&(t.data[i]||(t.data[i]={}),t.data[i][e]=t.data[n][e],delete t.data[n][e])}t.is_ancestry||t.data.main?(a("father"),a("mother")):function(){if(!t.data[n]||!t.data[n].children)return;const e=t.data[n].children.slice(0),a=t.spouse?[t.spouse]:t.spouses||[];[t,...a].forEach((t=>e.forEach((e=>{t.data[n].children.includes(e)&&(t.data[i]||(t.data[i]={}),t.data[i].children||(t.data[i].children=[]),t.data[i].children.push(e),t.data[n].children.splice(t.data[n].children.indexOf(e),1))}))))}()}function o({tree:t,data_stash:e,private_cards_config:n}){const i={},a=n.condition;if(!a)return console.error("private_cards_config.condition is not set");t.forEach((t=>{if(t.data._new_rel_data)return;const n=function(t){const n=[];let r=!1;return s(t),i[t]=r,r;function s(t){if(r)return;if(i.hasOwnProperty(t))return r=i[t],r;const o=e.find((e=>e.id===t));if(o._new_rel_data)return;if(a(o))return r=!0,!0;const d=o.rels;[d.father,d.mother,...d.spouses||[]].forEach((t=>{t&&(n.includes(t)||(n.push(t),s(t)))}))}}(t.data.id);n&&(t.is_private=n)}))}function d(t,e){const n=t.rels,i=[n.father,n.mother,...n.spouses||[],...n.children||[]].filter((t=>!!t)),a=[];for(let n=0;n<i.length;n++){if(!r(e.find((t=>t.id===i[n])),[t])){a.push(i[n]);break}}return 0===a.length;function r(t,n){let i;return s(t)&&(i=[t]),function t(a,r){if(i)return;r=[...r,a],o((function(t){s(t)&&(i=r)})),i||o(d);function o(t){if(!a)return;const e=a.rels;[e.father,e.mother,...e.spouses||[],...e.children||[]].filter((t=>t&&![...n,...r].find((e=>e.id===t)))).forEach((e=>t(e)))}function d(n){const i=e.find((t=>t.id===n));t(i,r)}}(t,[t]),i}function s(t){return"object"==typeof t?t.id===e[0].id:t===e[0].id}}function l(t,e){const n=e[0];if(t.id===n.id)return!0;const i=[];let a=!1;return function t(r){if(a)return;const s=r.rels;[s.father,s.mother,...s.spouses||[],...s.children||[]].filter((t=>!!t)).forEach((r=>{if(i.includes(r))return;i.push(r);const s=e.find((t=>t.id===r));s.id===n.id?a=!0:t(s)}))}(t),a}function c(t,e,n){const i=t.id;n.forEach((t=>{t.rels.father===i&&(t.rels.father=e),t.rels.mother===i&&(t.rels.mother=e),(t.rels.spouses||[]).includes(i)&&(t.rels.spouses=t.rels.spouses.filter((t=>t!==i)),t.rels.spouses.includes(e)||t.rels.spouses.push(e)),(t.rels.children||[]).includes(i)&&(t.rels.children=t.rels.children.filter((t=>t!==i)),t.rels.children.includes(e)||t.rels.children.push(e))}));const a=n.find((t=>t.id===e)),r=n.find((t=>t.id===i));(r.rels.children||[]).forEach((t=>{a.rels.children||(a.rels.children=[]),a.rels.children.includes(t)||a.rels.children.push(t)})),(r.rels.spouses||[]).forEach((t=>{a.rels.spouses||(a.rels.spouses=[]),a.rels.spouses.includes(t)||a.rels.spouses.push(t)})),a.rels.father&&r.rels.father&&console.error("link rel already has father"),a.rels.mother&&r.rels.mother&&console.error("link rel already has mother"),r.rels.father&&(a.rels.father=r.rels.father),r.rels.mother&&(a.rels.mother=r.rels.mother),n.splice(n.findIndex((t=>t.id===i)),1)}function h(t,e){const n=t._new_rel_data?e.find((e=>e.id===t._new_rel_data.rel_id)):null,i=function(t,e){const n=[];return i(t),n;function i(t){[t.rels.father,t.rels.mother].forEach((t=>{t&&(n.push(t),i(e.find((e=>e.id===t))))}))}}(t,e),a=r(t,e);return t._new_rel_data&&["son","daughter"].includes(t._new_rel_data.rel_type)&&a.push(...r(n,e)),e.filter((e=>e.id!==t.id&&e.id!==n?.id&&!e._new_rel_data&&!e.to_add&&!e.unknown)).filter((t=>!i.includes(t.id))).filter((t=>!a.includes(t.id))).filter((e=>!(e.rels.spouses||[]).includes(t.id)));function r(t,e){const n=[];return function t(i){(i.rels.children?[...i.rels.children]:[]).forEach((i=>{n.push(i),t(e.find((t=>t.id===i)))}))}(t),n}}function u(t,e){Object.keys(t.data).forEach((n=>{if(n.includes("__ref__")){const i=n.split("__ref__")[1],a=e.find((t=>t.id===i));if(!a)return;const r=n.split("__ref__")[0]+"__ref__"+t.id;a.data[r]=t.data[n]}}))}function p(t,e){Object.keys(t.data).forEach((n=>{if(n.includes("__ref__")){const i=n.split("__ref__")[1],a=e.find((t=>t.id===i));if(!a)return;const r=n.split("__ref__")[0]+"__ref__"+t.id;delete a.data[r]}}))}function f(t,e){return delete t.to_add,t}function _(t,e){return m(t,e),!1}function m(t,e){return d(t,e)?(e.forEach((e=>{for(let n in e.rels)e.rels.hasOwnProperty(n)&&(e.rels[n]===t.id?delete e.rels[n]:Array.isArray(e.rels[n])&&e.rels[n].includes(t.id)&&e.rels[n].splice(e.rels[n].findIndex((e=>e===t.id)),1))})),p(t,e),e.splice(e.findIndex((e=>e.id===t.id)),1),e.forEach((t=>{t.to_add&&m(t,e)})),0===e.length&&e.push(x({}).data[0]),{success:!0}):(p(t,e),t.data={gender:t.data.gender},t.unknown=!0,{success:!0})}function g({datum:t,data_stash:e,rel_type:n,rel_datum:i}){function a(t){!function(){if(!i.rels.spouses)return;i.rels.spouses.forEach((t=>{const n=e.find((e=>e.id===t));n.to_add&&_(n,e)}))}(),i.rels.spouses||(i.rels.spouses=[]),i.rels.spouses.push(t.id),t.rels.spouses=[i.id]}"daughter"===n||"son"===n?function(t){t.data.other_parent&&(!function(n){"_new"===n&&(n=s().id);const r=e.find((t=>t.id===n));t.rels["M"===r.data.gender?"father":"mother"]=r.id,r.rels.hasOwnProperty("children")||(r.rels.children=[]);function s(){const t=v({rel_type:"spouse",rel_datum:i});return a(t),b({data_stash:e,datum:t}),t}r.rels.children.push(t.id)}(t.data.other_parent),delete t.data.other_parent);t.rels["M"===i.data.gender?"father":"mother"]=i.id,i.rels.children||(i.rels.children=[]);i.rels.children.push(t.id)}(t):"father"===n||"mother"===n?function(t){const n="M"===t.data.gender,a=i.rels[n?"father":"mother"];a&&_(e.find((t=>t.id===a)),e);i.rels[n?"father":"mother"]=t.id,function(){const a=i.rels[n?"mother":"father"];if(!a)return;const r=e.find((t=>t.id===a));t.rels.spouses=[a],r.rels.spouses||(r.rels.spouses=[]),r.rels.spouses.push(t.id)}(),t.rels.children=[i.id]}(t):"spouse"===n&&a(t)}function y({data:t,rels:e}){return{id:(n=(new Date).getTime(),i=performance&&performance.now&&1e3*performance.now()||0,"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var e=16*Math.random();return n>0?(e=(n+e)%16|0,n=Math.floor(n/16)):(e=(i+e)%16|0,i=Math.floor(i/16)),("x"===t?e:3&e|8).toString(16)}))),data:t||{},rels:e||{}};var n,i}function v({data:t,rel_type:e,rel_datum:n}){const i=function(t,e){return["daughter","mother"].includes(e)||"spouse"===e&&"M"===t.data.gender?"F":"M"}(n,e);return y({data:t=Object.assign(t||{},{gender:i})})}function b({data_stash:t,datum:e}){t.push(e)}function x({data:t,version:e}){return{data:[y({data:t})],version:e}}function C({amount:t,svg:e,transition_time:n=500}){const a=e.__zoomObj?e:e.parentNode,r=a.__zoomObj;i.select(a).transition().duration(n||0).delay(n?100:0).call(r.scaleBy,t)}function w(t,e){const n=t.data.rels;return[n.father,n.mother,...n.spouses||[],...n.children||[]].filter((t=>t)).every((t=>e.some((e=>e.data.id===t))))}function $(t,e,n=!0){const i=[];function a(t,e){return t.every((t=>e.some((e=>t.id===e.id))))}function r(t){const e={},n=t;return(t.children||[]).forEach((t=>{const i=t.data.rels,a=i.father===n.data.id?i.mother:i.father;e[a]||(e[a]=[]),e[a].push(t)})),e}!function s(o){if(!o.children)return;const d=o.data,l=(o.data.rels.spouses||[]).map((t=>e.find((e=>e.id===t)))),c=r(o);l.forEach((l=>{if(i.some((t=>t.some((t=>a([d,l],[t.p1,t.p2]))))))return;const h=function(n,i,s){const o=[];return d(t),o;function d(t){if(t!==n&&t.children){const n=t.data,l=(t.data.rels.spouses||[]).map((t=>e.find((e=>e.id===t)))),c=r(t);l.forEach((e=>{a([i,s],[n,e])?o.push({d:t,p1:n,p2:e}):(c[e.id]||[]).forEach((t=>{d(t)}))}))}}}(o,d,l);if(h.length>0){const e=[{d:o,p1:d,p2:l},...h];i.push(e),function(e){if(e.forEach((({d:n,p1:i,p2:a},r)=>{n.data._tgdp_sp||(n.data._tgdp_sp={});let s=t===n?"main":n.parent.data.id;!function(t,e,n){t.data.__tgdp_sp&&t.data.__tgdp_sp[e]&&t.data.__tgdp_sp[e].hasOwnProperty(n.id)&&(t.data._tgdp_sp[e][n.id]=t.data.__tgdp_sp[e][n.id],delete t.data.__tgdp_sp[e][n.id])}(n,s,a),n.data._tgdp_sp[s]||(n.data._tgdp_sp[s]={});let o=1;n.data._tgdp_sp[s].hasOwnProperty(a.id)?o=n.data._tgdp_sp[s][a.id]:n.data._tgdp_sp[s][a.id]=o,e[r].val=o})),n){if(e.every((t=>t.val<0))){const n=e.sort(((t,e)=>e.val-t.val))[0],{d:i,p1:a,p2:r}=n,s=t===i?"main":i.parent.data.id;i.data._tgdp_sp[s][r.id]=1}if(e.filter((t=>t.val>0)).length>1){const n=e.sort(((t,e)=>e.val-t.val))[0];e.forEach((e=>{if(e===n)return;const{d:i,p1:a,p2:r}=e,s=t===i?"main":i.parent.data.id;i.data._tgdp_sp[s][r.id]=-1}))}}}(e),function(e){e.forEach((({d:e,p1:n,p2:i})=>{const a=t===e?"main":e.parent.data.id;if(e.data._tgdp_sp[a][i.id]<0){const t=r(e);t[i.id]&&(e.children=e.children.filter((e=>!t[i.id].includes(e))),0===e.children.length&&delete e.children)}}))}(e)}else{let e=t===o?"main":o.parent.data.id;!function(t,e,n){t.data._tgdp_sp&&t.data._tgdp_sp[e]&&t.data._tgdp_sp[e].hasOwnProperty(n.id)&&(t.data.__tgdp_sp||(t.data.__tgdp_sp={}),t.data.__tgdp_sp[e]||(t.data.__tgdp_sp[e]={}),t.data.__tgdp_sp[e][n.id]=t.data._tgdp_sp[e][n.id],delete t.data._tgdp_sp[e][n.id])}(o,e,l),(c[l.id]||[]).forEach((t=>{s(t)}))}}))}(t),function(t){let e=0;t.forEach((t=>{e+=1,t.forEach((t=>{t.d._toggle_id_sp||(t.d._toggle_id_sp={}),t.d._toggle_id_sp[t.p2.id]=e}))}))}(i)}function k(t,e=!0){const n=[];!function i(a){if(a.children){if(n.some((t=>t.includes(a))))return;const r=function(e){const n=[];return i(t),n;function i(t){var a,r;t.children&&(a=e,r=t.children,a!==r&&a.every((t=>r.some((e=>t.data.id===e.data.id))))?n.push(t):t.children.forEach((t=>{i(t)})))}}(a.children);if(r.length>0){const i=[a,...r];n.push(i),function(n){if(n.forEach((e=>{e.data._tgdp||(e.data._tgdp={});const n=t===e?"main":e.parent.data.id;e.data._tgdp[n]||(e.data._tgdp[n]=-1),e._toggle=e.data._tgdp[n]})),e){if(n.every((t=>t._toggle<0))){const e=n.sort(((t,e)=>e._toggle-t._toggle))[0],i=t===e?"main":e.parent.data.id;e.data._tgdp[i]=1}if(n.filter((t=>t._toggle>0)).length>1){const e=n.sort(((t,e)=>e._toggle-t._toggle))[0];n.forEach((n=>{if(n===e)return;const i=n,a=t===i?"main":i.parent.data.id;i.data._tgdp[a]=-1}))}}}(i),function(e){e.forEach((e=>{const n=t===e?"main":e.parent.data.id;e.data._tgdp[n]<0&&delete e.children}))}(i)}else a.children.forEach((t=>{i(t)}))}}(t),function(t){let e=0;t.forEach((t=>{e+=1,t.forEach((t=>{t._toggle_id=e}))}))}(n)}function M({data:t,main_id:e=null,node_separation:n=250,level_separation:r=150,single_parent_empty_card:s=!0,is_horizontal:d=!1,one_level_rels:l=!1,sortChildrenFunction:c,sortSpousesFunction:h,ancestry_depth:u,progeny_depth:p,show_siblings_of_main:f=!1,modifyTreeHierarchy:_,private_cards_config:m,duplicate_branch_toggle:g=!1,on_toggle_one_close_others:v=!0}){if(!t||!t.length)return{data:[],data_stash:[],dim:{width:0,height:0},main_id:null};d&&([n,r]=[r,n]);const b=s?function(t){const e=[];for(let e=0;e<t.length;e++){const i=t[e];if(i.rels.children&&i.rels.children.length>0){i.rels.spouses||(i.rels.spouses=[]);const e="M"===i.data.gender;let a;i.rels.children.forEach((r=>{const s=t.find((t=>t.id===r));s.rels[e?"father":"mother"]===i.id&&(s.rels[e?"mother":"father"]||(a||(a=n(i)),a.rels.children.push(s.id),s.rels[e?"mother":"father"]=a.id))}))}}return e.forEach((e=>t.push(e))),t;function n(n){return n.rels.spouses.map((e=>t.find((t=>t.id===e)))).find((t=>t.to_add))||function(t){const n=y({data:{gender:"M"===t.data.gender?"F":"M"},rels:{spouses:[t.id],children:[]}});return n.to_add=!0,e.push(n),t.rels.spouses.push(n.id),n}(n)}}(t):t,x=null!==e&&b.find((t=>t.id===e))||b[0],C=L(x,"children",!1),M=L(x,"parents",!0);b.forEach((t=>t.main=t===x)),function(t,e){const n=(t[0].x-e[0].x)/2;t.forEach((t=>t.x-=n)),e.forEach((t=>t.x+=n))}(M,C);const S=(E=C,(I=M).forEach((t=>{t.is_ancestry=!0})),I.forEach((t=>1===t.depth?t.parent=E[0]:null)),[...E,...I.slice(1)]);var I,E;!function({tree:t}){t.forEach((e=>{delete e.children,t.forEach((t=>{t.parent===e&&(t.is_ancestry?(e.parents||(e.parents=[]),e.parents.push(t)):(e.children||(e.children=[]),e.children.push(t)))}))}))}({tree:S}),function({tree:t,node_separation:e}){for(let n=t.length;n--;){const i=t[n];if(!i.is_ancestry&&i.data.rels.spouses&&i.data.rels.spouses.length>0){if(l&&i.depth>0)continue;const n="M"===i.data.data.gender?-1:1;i.x+=i.data.rels.spouses.length/2*e*n,i.data.rels.spouses.forEach(((a,r)=>{const s={data:b.find((t=>t.id===a)),added:!0};s.x=i.x-e*(r+1)*n,s.y=i.y,s.sx=r>0?s.x:s.x+e/2*n,s.sy=r>0?s.y:s.y+e/2*n,s.depth=i.depth,s.spouse=i,i.spouses||(i.spouses=[]),i.spouses.push(s),t.push(s)}))}if(i.parents&&2===i.parents.length){const t=i.parents[0],n=i.parents[1],a=t.x-(t.x-n.x)/2,r=(t,n)=>a+e/2*(t.x<n.x?1:-1);n.x=r(t,n),t.x=r(n,t)}}}({tree:S,node_separation:n}),f&&!l&&function({tree:t,data_stash:e,node_separation:n,sortChildrenFunction:a}){const r=t.find((t=>t.data.main)),s=r.data.rels.father,o=r.data.rels.mother,d=e.filter((t=>!(t.id===r.data.id||!(s&&t.rels.father===s||o&&t.rels.mother===o)))),l=function(){const e=[];for(let n=0;n<d.length;n++){const i={data:d[n],sibling:!0,parents:[]},a=r.parents.find((t=>t.data.id===i.data.rels.father)),s=r.parents.find((t=>t.data.id===i.data.rels.mother));a&&i.parents.push(a),s&&i.parents.push(s),i.x=void 0,i.y=r.y,i.depth=r.depth-1,t.push(i),e.push(i)}return e}();!function(){const t=[r,...l];a&&t.sort(((t,e)=>a(t.data,e.data))),t.sort(((t,e)=>{const n=r.parents.find((e=>e.data.id===t.data.rels.father)),i=r.parents.find((e=>e.data.id===t.data.rels.mother)),a=r.parents.find((t=>t.data.id===e.data.rels.father)),s=r.parents.find((t=>t.data.id===e.data.rels.mother));return!i&&s?-1:i&&!s||!n&&a?1:n&&!a?-1:0}));const e=r.x,s=(r.spouses||[]).map((t=>t.x)),o=i.extent([e,...s]),d=t.findIndex((t=>t.data.id===r.data.id));for(let e=0;e<t.length;e++){if(e===d)continue;t[e].x=e<d?o[0]-n*(d-e):o[1]+n*(e-d)}}()}({tree:S,data_stash:b,node_separation:n,sortChildrenFunction:c}),function({tree:t}){t.forEach((t=>{if(t.is_ancestry)return;if(0===t.depth)return;if(t.added)return;if(t.sibling)return;const e=t.parent,n=(e.spouses||[]).find((e=>e.data.id===t.data.rels.father||e.data.id===t.data.rels.mother));if(e&&n){e.added||n.added||console.error("no added spouse",e,n);const a=e.added?e:n;i(t,a)}else if(e||n){const a=e||n;a.sx=a.x,a.sy=a.y,i(t,a)}function i(t,e){t.psx=d?e.y:e.sx,t.psy=d?e.sx:e.y}}))}({tree:S}),function({tree:t}){t.forEach((t=>{if(t.y*=t.is_ancestry?-1:1,d){const e=t.x;t.x=t.y,t.y=e}}))}({tree:S}),S.forEach((t=>t.all_rels_displayed=w(t,S))),m&&o({tree:S,data_stash:b,private_cards_config:m}),function({tree:t}){const e=[];t.forEach((n=>{if(e.includes(n.data.id)){const i=t.filter((t=>t.data.id===n.data.id));i.forEach(((t,a)=>{t.tid=`${n.data.id}--x${a+1}`,t.duplicate=i.length,e.push(n.data.id)}))}else n.tid=n.data.id,e.push(n.data.id)}))}({tree:S}),function(t){t.forEach((t=>{if(t.data.main)t.from=[],t.to=[],t.to_ancestry=t.parents;else if(t.is_ancestry)t.from=[t.parent],t.to=t.parents;else{if(t.added)return t.from=[],t.from_spouse=t.spouse,void(t.to=[]);if(t.sibling)return;const e=t.parent,n=(t.parent.spouses||[]).find((e=>e.data.id===t.data.rels.father||e.data.id===t.data.rels.mother));t.from=[e],n&&t.from.push(n),e.to||(e.to=[]),e.to.push(t),n&&(n.to||(n.to=[]),n.to.push(t))}}))}(S),g&&function(t){t.forEach((t=>{if(!t.spouse)return;const e=t.spouse;if(t.duplicate&&e.data._tgdp_sp){const n=e.data.main?"main":e.parent.data.id;e.data._tgdp_sp[n]?.hasOwnProperty(t.data.id)&&(t._toggle=e.data._tgdp_sp[n][t.data.id])}}))}(S);const A=function(t,e,n){d&&([e,n]=[n,e]);const a=i.extent(t,(t=>t.x)),r=i.extent(t,(t=>t.y));return{width:a[1]-a[0]+e,height:r[1]-r[0]+n,x_off:-a[0]+e/2,y_off:-r[0]+n/2}}(S,n,r);return{data:S,data_stash:b,dim:A,main_id:x.id,is_horizontal:d};function L(t,e,s){const o="children"===e?function(t){const e=[...t.rels.children||[]].map((t=>b.find((e=>e.id===t))));c&&e.sort(c);(function(t){t.sort(((t,e)=>{const n=t._new_rel_data,i=e._new_rel_data;return n&&!i?1:!n&&i?-1:0}))})(e),h&&h(t,b);return function(t,e,n){if(!e.rels.children)return;const i=e.rels.spouses||[];t.sort(((t,r)=>{const s=a(t,e,n)||{},o=a(r,e,n)||{},d=i.indexOf(s.id),l=i.indexOf(o.id);return"M"===e.data.gender?d-l:l-d}))}(e,t,b),e}:function(t){return[t.rels.father,t.rels.mother].filter((t=>t)).map((t=>b.find((e=>e.id===t))))},d=i.tree().nodeSize([n,r]).separation((function(t,e){let n=1;s||(m(t,e)||(n+=.25),l||function(t,e){return y(t)||y(e)}(t,e)&&(n+=function(t,e){return.5*((t.data.rels.spouses||[]).length+(e.data.rels.spouses||[]).length)}(t,e)),m(t,e)&&!function(t,e){return t.data.rels.father===e.data.rels.father&&t.data.rels.mother===e.data.rels.mother}(t,e)&&(n+=.125));return n})),f=i.hierarchy(t,o);return s&&function(t){function e(t){t.children&&2===t.children.length&&(t.children[0]._spouse=t.children[1],t.children[1]._spouse=t.children[0]),t.children&&t.children.forEach((t=>e(t)))}e(t)}(f),function(t,e){let n=e?u:p;l&&(n=1);return n||0===n?(i(t,0),t):t;function i(t,e){e===n?t.children&&delete t.children:t.children&&t.children.forEach((t=>{i(t,e+1)}))}}(f,s),g&&function(t,e,n){n?k(t,v):$(t,e,v)}(f,b,s),_&&_(f,s),d(f),f.descendants();function m(t,e){return t.parent==e.parent}function y(t){return t.data.rels.spouses&&t.data.rels.spouses.length>0}}}function S({t:t,svg:e,transition_time:n=2e3}){const a=e.__zoomObj?e:e.parentNode,r=a.__zoomObj;i.select(a).transition().duration(n||0).delay(n?100:0).call(r.transform,i.zoomIdentity.scale(t.k).translate(t.x,t.y))}function I({svg:t,svg_dim:e,tree_dim:n,with_transition:i,transition_time:a}){S({t:E(e,n),svg:t,with_transition:i,transition_time:a})}function E(t,e){let n=Math.min(t.width/e.width,t.height/e.height);n>1&&(n=1);return{k:n,x:e.x_off+(t.width-e.width*n)/n/2,y:e.y_off+(t.height-e.height*n)/n/2}}function A({datum:t,svg:e,svg_dim:n,scale:i,transition_time:a}){const r=i||1;S({t:{k:r,x:(n.width/2-t.x*r)/r,y:(n.height/2-t.y)/r},svg:e,with_transition:!0,transition_time:a})}function L(t,e){const n=i.line().curve(i.curveMonotoneY),a=i.line().curve(i.curveBasis),r=e?t._d():t.d;return t.curve?!0===t.curve?a(r):void 0:n(r)}function R(t,e){const n=i.select(t).selectAll("div.card_cont_2fake").data(e,(t=>t.data.id)),a=n.exit(),r=n.enter().append("div").attr("class","card_cont_2fake").style("display","none").attr("data-id",(()=>Math.random())),s=r.merge(n);a.each((function(t){t.unique_id=i.select(this).attr("data-id"),i.select(this).remove()})),r.each((function(t){t.unique_id=i.select(this).attr("data-id")})),s.each((function(t){t.unique_id=i.select(this).attr("data-id")}))}function H(t){i.select(t()).append("div").attr("class","cards_view_fake").style("display","none")}function D(t){return i.select(t()).select("div.cards_view_fake").node()}var T=Object.freeze({__proto__:null,assignUniqueIdToTreeData:R,setupHtmlSvg:H,getCardsViewFake:D,onZoomSetup:function(t,e){return function(n){const a=n.transform;i.select(t()).style("transform",`translate(${a.x}px, ${a.y}px) scale(${a.k}) `),i.select(e()).style("transform",`translate(${a.x}px, ${a.y}px) scale(${a.k}) `)}},setupReactiveTreeData:function(t){let e=[];return function(n){const i=function(t,e){return e.length>0?e.filter((e=>!t.find((t=>t.data.id===e.data.id)))):[]}(n,e);return e=[...n,...i],R(D(t),e),e}},createHtmlSvg:function(t){const e=i.select(t).select("#f3Canvas").append("div").attr("id","htmlSvg").attr("style","position: absolute; width: 100%; height: 100%; z-index: 2; top: 0; left: 0");return e.append("div").attr("class","cards_view").style("transform-origin","0 0"),H((()=>e.node())),e.node()},getUniqueId:function(t){return t.unique_id}});function F(t,e,n){const i=.4*n,a=Math.max(...t.data.map((t=>t.is_ancestry?t.depth:0)));let r=e.depth*i;return 0===e.depth&&!e.spouse||e.is_ancestry||(r+=a*i,e.spouse&&(r+=i),r+=e.depth*i),r}function O(t,{d:e}){var n,i;return n=t.getTree().data,i=!1,n.forEach((t=>{t.data.hide_rels=i,s(t,i)})),t.updateMainId(e.data.id),t.updateTree({tree_position:t.state.tree_fit_on_change}),!0}function P(t,{d:e,cardEditForm:n}){const i=e.data;n({datum:i,postSubmit:e=>{i.to_add&&f(i,t.getData()),e&&e.delete&&(i.main&&t.updateMainId(null),m(i,t.getData())),t.updateTree()},store:t})}function z(t,{d:e}){e.data.hide_rels=!e.data.hide_rels,s(e,e.data.hide_rels),t.updateTree({tree_position:t.state.tree_fit_on_change})}function q(){return`\n <g data-icon="user">\n ${vt()}\n <path d="M12,4A4,4 0 0,1 16,8A4,4 0 0,1 12,12A4,4 0 0,1 8,8A4,4 0 0,1 12,4M12,14C16.42,14 20,15.79 20,18V20H4V18C4,15.79 7.58,14 12,14Z" />\n </g>\n `}function j(){return`\n <g data-icon="user-edit">\n ${vt()}\n <path d="M21.7,13.35L20.7,14.35L18.65,12.3L19.65,11.3C19.86,11.09 20.21,11.09 20.42,11.3L21.7,12.58C21.91,\n 12.79 21.91,13.14 21.7,13.35M12,18.94L18.06,12.88L20.11,14.93L14.06,21H12V18.94M12,14C7.58,14 4,15.79 4,\n 18V20H10V18.11L14,14.11C13.34,14.03 12.67,14 12,14M12,4A4,4 0 0,0 8,8A4,4 0 0,0 12,12A4,4 0 0,0 16,8A4,4 0 0,0 12,4Z" />\n </g>\n `}function V(){return`\n <g data-icon="user-plus">\n ${vt()}\n <path d="M15,14C12.33,14 7,15.33 7,18V20H23V18C23,15.33 17.67,14 15,14M6,10V7H4V10H1V12H4V15H6V12H9V10M15,12A4,4 0 0,0 19,8A4,4 0 0,0 15,4A4,4 0 0,0 11,8A4,4 0 0,0 15,12Z" />\n </g>\n `}function U(){return`\n <g data-icon="user-plus-close">\n ${vt()}\n <path d="M15,14C12.33,14 7,15.33 7,18V20H23V18C23,15.33 17.67,14 15,14M6,10V7H4V10H1V12H4V15H6V12H9V10M15,12A4,4 0 0,0 19,8A4,4 0 0,0 15,4A4,4 0 0,0 11,8A4,4 0 0,0 15,12Z" />\n <line x1="3" y1="3" x2="24" y2="24" stroke="currentColor" stroke-width="2" />\n </g>\n `}function B(){return`\n <g data-icon="plus">\n ${vt()}\n <path d="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z" />\n </g>\n `}function N(){return`\n <g data-icon="pencil">\n ${vt()}\n <path d="M20.71,7.04C21.1,6.65 21.1,6 20.71,5.63L18.37,3.29C18,2.9 17.35,2.9 16.96,3.29L15.12,5.12L18.87,8.87M3,17.25V21H6.75L17.81,9.93L14.06,6.18L3,17.25Z" />\n </g>\n `}function Z(){return`\n <g data-icon="pencil-off">\n ${vt()}\n <path d="M18.66,2C18.4,2 18.16,2.09 17.97,2.28L16.13,4.13L19.88,7.88L21.72,6.03C22.11,5.64 22.11,5 21.72,4.63L19.38,2.28C19.18,2.09 18.91,2 18.66,2M3.28,4L2,5.28L8.5,11.75L4,16.25V20H7.75L12.25,15.5L18.72,22L20,20.72L13.5,14.25L9.75,10.5L3.28,4M15.06,5.19L11.03,9.22L14.78,12.97L18.81,8.94L15.06,5.19Z" />\n </g>\n `}function W(){return`\n <g data-icon="trash">\n ${vt()}\n <path d="M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19M8,9H16V19H8V9M15.5,4L14.5,3H9.5L8.5,4H5V6H19V4H15.5Z" />\n </g>\n `}function K(){return`\n <g data-icon="history-back">\n ${vt()}\n <path d="M20 13.5C20 17.09 17.09 20 13.5 20H6V18H13.5C16 18 18 16 18 13.5S16 9 13.5 9H7.83L10.91 12.09L9.5 13.5L4 8L9.5 2.5L10.92 3.91L7.83 7H13.5C17.09 7 20 9.91 20 13.5Z" />\n </g>\n `}function J(){return`\n <g data-icon="history-forward">\n ${vt()}\n <path d="M10.5 18H18V20H10.5C6.91 20 4 17.09 4 13.5S6.91 7 10.5 7H16.17L13.08 3.91L14.5 2.5L20 8L14.5 13.5L13.09 12.09L16.17 9H10.5C8 9 6 11 6 13.5S8 18 10.5 18Z" />\n </g>\n `}function G(){return'\n <g data-icon="person">\n <path d="M256 288c79.5 0 144-64.5 144-144S335.5 0 256 0 112 \n 64.5 112 144s64.5 144 144 144zm128 32h-55.1c-22.2 10.2-46.9 16-72.9 16s-50.6-5.8-72.9-16H128C57.3 320 0 377.3 \n 0 448v16c0 26.5 21.5 48 48 48h416c26.5 0 48-21.5 48-48v-16c0-70.7-57.3-128-128-128z" />\n </g>\n '}function Y(){return'\n <g transform="translate(31,25)" data-icon="mini-tree">\n <rect x="-31" y="-25" width="72" height="15" fill="rgba(0,0,0,0)"></rect>\n <g>\n <rect x="-31" y="-25" width="72" height="15" fill="rgba(0,0,0,0)"></rect>\n <line y2="-17.5" stroke="#fff" />\n <line x1="-20" x2="20" y1="-17.5" y2="-17.5" stroke="#fff" />\n <rect x="-31" y="-25" width="25" height="15" rx="5" ry="5" class="card-male" />\n <rect x="6" y="-25" width="25" height="15" rx="5" ry="5" class="card-female" />\n </g>\n </g>\n '}function Q(){return`\n <g data-icon="toggle-on">\n ${vt()}\n <circle class="f3-small-circle" r="4" cx="18" cy="12" />\n <path d="M17,7H7A5,5 0 0,0 2,12A5,5 0 0,0 7,17H17A5,5 0 0,0 22,12A5,5 0 0,0 17,7M17,15A3,3 0 0,1 14,12A3,3 0 0,1 17,9A3,3 0 0,1 20,12A3,3 0 0,1 17,15Z" />\n </g>\n `}function X(){return`\n <g data-icon="toggle-off">\n ${vt()}\n <circle class="f3-small-circle" r="4" cx="6" cy="12" />\n <path d="M17,7H7A5,5 0 0,0 2,12A5,5 0 0,0 7,17H17A5,5 0 0,0 22,12A5,5 0 0,0 17,7M7,15A3,3 0 0,1 4,12A3,3 0 0,1 7,9A3,3 0 0,1 10,12A3,3 0 0,1 7,15Z" />\n </g>\n `}function tt(){return`\n <g data-icon="chevron-down">\n ${vt()}\n <path d="M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z" />\n </g>\n `}function et(){return`\n <g data-icon="chevron-up">\n ${vt()}\n <path d="M7.41,15.41L12,10.83L16.59,15.41L18,14L12,8L6,14L7.41,15.41Z" />\n </g>\n `}function nt(){return`\n <g data-icon="link-off">\n ${vt()}\n <path d="M17,7H13V8.9H17C18.71,8.9 20.1,10.29 20.1,12C20.1,13.43 19.12,14.63 17.79,15L19.25,16.44C20.88,15.61 22,13.95 \n 22,12A5,5 0 0,0 17,7M16,11H13.81L15.81,13H16V11M2,4.27L5.11,7.38C3.29,8.12 2,9.91 2,12A5,5 0 0,0 7,17H11V15.1H7C5.29,15.1 \n 3.9,13.71 3.9,12C3.9,10.41 5.11,9.1 6.66,8.93L8.73,11H8V13H10.73L13,15.27V17H14.73L18.74,21L20,19.74L3.27,3L2,4.27Z" />\n </g>\n `}function it(){return`\n <g data-icon="info">\n ${vt()}\n <path d="M13,9H11V7H13M13,17H11V11H13M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z" />\n </g>\n `}function at(){return yt(V())}function rt(){return yt(U())}function st(){return yt(B())}function ot(){return yt(N())}function dt(){return yt(Z())}function lt(){return yt(K())}function ct(){return yt(J())}function ht(){return yt('\n <g data-icon="person">\n <path d="M256 288c79.5 0 144-64.5 144-144S335.5 0 256 0 112 \n 64.5 112 144s64.5 144 144 144zm128 32h-55.1c-22.2 10.2-46.9 16-72.9 16s-50.6-5.8-72.9-16H128C57.3 320 0 377.3 \n 0 448v16c0 26.5 21.5 48 48 48h416c26.5 0 48-21.5 48-48v-16c0-70.7-57.3-128-128-128z" />\n </g>\n ',"0 0 512 512")}function ut(){return yt('\n <g transform="translate(31,25)" data-icon="mini-tree">\n <rect x="-31" y="-25" width="72" height="15" fill="rgba(0,0,0,0)"></rect>\n <g>\n <rect x="-31" y="-25" width="72" height="15" fill="rgba(0,0,0,0)"></rect>\n <line y2="-17.5" stroke="#fff" />\n <line x1="-20" x2="20" y1="-17.5" y2="-17.5" stroke="#fff" />\n <rect x="-31" y="-25" width="25" height="15" rx="5" ry="5" class="card-male" />\n <rect x="6" y="-25" width="25" height="15" rx="5" ry="5" class="card-female" />\n </g>\n </g>\n ',"0 0 72 25")}function pt(){return yt(Q())}function ft(){return yt(X())}function _t(){return yt(tt())}function mt(){return yt(nt())}function gt(){return yt(it())}function yt(t,e="0 0 24 24"){const n=t.match(/data-icon="([^"]+)"/);return`\n <svg xmlns="http://www.w3.org/2000/svg" viewBox="${e}" style="fill: currentColor" ${n?`data-icon="${n[1]}"`:""}>\n ${t}\n </svg>\n `}function vt(){return'\n <circle r="12" cx="12" cy="12" style="fill: rgba(0,0,0,0)" />\n '}var bt=Object.freeze({__proto__:null,userIcon:q,userEditIcon:j,userPlusIcon:V,userPlusCloseIcon:U,plusIcon:B,pencilIcon:N,pencilOffIcon:Z,trashIcon:W,historyBackIcon:K,historyForwardIcon:J,personIcon:G,miniTreeIcon:Y,toggleIconOn:Q,toggleIconOff:X,chevronDownIcon:tt,chevronUpIcon:et,linkOffIcon:nt,infoIcon:it,userSvgIcon:function(){return yt(q())},userEditSvgIcon:function(){return yt(j())},userPlusSvgIcon:at,userPlusCloseSvgIcon:rt,plusSvgIcon:st,pencilSvgIcon:ot,pencilOffSvgIcon:dt,trashSvgIcon:function(){return yt(W())},historyBackSvgIcon:lt,historyForwardSvgIcon:ct,personSvgIcon:ht,miniTreeSvgIcon:ut,toggleSvgIconOn:pt,toggleSvgIconOff:ft,chevronDownSvgIcon:_t,chevronUpSvgIcon:function(){return yt(et())},linkOffSvgIcon:mt,infoSvgIcon:gt});var xt=Object.freeze({__proto__:null,manualZoom:C,getCurrentZoom:function(t){const e=t.__zoomObj?t:t.parentNode;return i.zoomTransform(e)},zoomTo:function(t,e){const n=t.__zoomObj?t:t.parentNode;C({amount:e/i.zoomTransform(n).k,svg:t})},isAllRelativeDisplayed:w,cardChangeMain:O,cardEdit:P,cardShowHideRels:z,handleRelsOfNewDatum:g,createNewPerson:y,createNewPersonWithGenderFromRel:v,addNewPerson:b,createTreeDataWithMainNode:x,addNewPersonAndHandleRels:function({datum:t,data_stash:e,rel_type:n,rel_datum:i}){b({data_stash:e,datum:t}),g({datum:t,data_stash:e,rel_type:n,rel_datum:i})},checkIfRelativesConnectedWithoutPerson:d,checkIfConnectedToFirstPerson:l,createForm:function({datum:t,store:e,fields:n,postSubmit:i,addRelative:a,removeRelative:r,deletePerson:s,onCancel:o,editFirst:d,link_existing_rel_config:l,getKinshipInfo:c,onFormCreation:p}){const f={datum_id:t.id,fields:[],onSubmit:function(n){n.preventDefault();new FormData(n.target).forEach(((e,n)=>t.data[n]=e)),u(t,e.getData()),t.to_add&&delete t.to_add;t.unknown&&delete t.unknown;i()},getKinshipInfo:c,onFormCreation:p};t._new_rel_data||(f.onDelete=function(){s(),i({delete:!0})},f.addRelative=()=>a.activate(t),f.addRelativeCancel=()=>a.onCancel(),f.addRelativeActive=a.is_active,f.removeRelative=()=>r.activate(t),f.removeRelativeCancel=()=>r.onCancel(),f.removeRelativeActive=r.is_active,f.editable=!1),t._new_rel_data&&(f.title=t._new_rel_data.label,f.new_rel=!0,f.editable=!0,f.onCancel=o),(t._new_rel_data||t.to_add||t.unknown)&&l&&(f.linkExistingRelative=function(t,e,n){return{label:n.label,options:h(t,e).map((t=>({value:t.id,label:n.linkRelLabel(t)}))).sort(((t,e)=>"string"==typeof t.label&&"string"==typeof e.label?t.label.localeCompare(e.label):t.label<e.label?-1:1)),onSelect:m}}(t,e.getData(),l)),f.onDelete&&(f.can_delete=!0),d&&(f.editable=!0);const _=(t.rels.children||[]).some((t=>!e.getDatum(t)._new_rel_data));return f.gender_field={id:"gender",type:"switch",label:"Gender",initial_value:t.data.gender,disabled:["father","mother"].some((e=>e===t._new_rel_data?.rel_type))||_,options:[{value:"M",label:"Male"},{value:"F",label:"Female"}]},n.forEach((n=>{"rel_reference"===n.type?function(n){n.getRelLabel||console.error("getRelLabel is not set");"spouse"===n.rel_type&&(t.rels.spouses||[]).forEach((i=>{const a=e.getDatum(i),r=`${n.id}__ref__${i}`;f.fields.push({id:r,type:"rel_reference",label:n.label,rel_id:i,rel_label:n.getRelLabel(a),initial_value:t.data[r]})}))}(n):"select"===n.type?function(e){if(!e.optionCreator&&!e.options)return console.error("optionCreator or options is not set for field",e);f.fields.push({id:e.id,type:e.type,label:e.label,initial_value:t.data[e.id],placeholder:e.placeholder,options:e.options||e.optionCreator(t)})}(n):f.fields.push({id:n.id,type:n.type,label:n.label,initial_value:t.data[n.id]})})),f;function m(t){const e=t.target.value;i({link_rel_id:e})}},syncRelReference:u,onDeleteSyncRelReference:p,moveToAddToAdded:f,removeToAdd:_,deletePerson:m,cleanupDataJson:function(t){return t.forEach((e=>e.to_add?_(e,t):e)),t.forEach((t=>{delete t.main,delete t._tgdp,delete t._tgdp_sp,delete t.__tgdp_sp})),t.forEach((t=>{Object.keys(t).forEach((t=>{"_"===t[0]&&console.error("key starts with _",t)}))})),t},removeToAddFromData:function(t){return t.forEach((e=>e.to_add?_(e,t):e)),t},formInfoSetup:function(t,e){const n=document.createElement("div");return i(),n;function i(){const a=function(t){return` \n <form id="familyForm" class="f3-form ${t.editable?"":"non-editable"}">\n ${d()}\n ${t.title?`<h3 class="f3-form-title">${t.title}</h3>`:""}\n <div style="text-align: right; display: ${t.new_rel?"none":"block"}">\n ${t.addRelative&&!t.no_edit?i():""}\n ${t.no_edit?l():a()}\n </div>\n\n ${r()}\n\n ${s()}\n \n <div class="f3-form-buttons">\n <button type="button" class="f3-cancel-btn">Cancel</button>\n <button type="submit">Submit</button>\n </div>\n\n ${t.linkExistingRelative?o():""}\n\n <hr>\n\n ${t.onDelete?e():""}\n\n ${t.removeRelative?n():""}\n </form>\n `;function e(){return`\n <div>\n <button type="button" class="f3-delete-btn" ${t.can_delete?"":"disabled"}>\n Delete\n </button>\n </div>\n `}function n(){return`\n <div>\n <button type="button" class="f3-remove-relative-btn${t.removeRelativeActive?" active":""}">\n ${t.removeRelativeActive?"Cancel Remove Relation":"Remove Relation"}\n </button>\n </div>\n `}function i(){return`\n <span class="f3-add-relative-btn">\n ${t.addRelativeActive?rt():at()}\n </span>\n `}function a(){return`\n <span class="f3-edit-btn">\n ${t.editable?dt():ot()}\n </span>\n `}function r(){return t.editable?`\n <div class="f3-radio-group">\n ${t.gender_field.options.map((e=>`\n <label>\n <input type="radio" name="${t.gender_field.id}" \n value="${e.value}" \n ${e.value===t.gender_field.initial_value?"checked":""}\n ${t.gender_field.disabled?"disabled":""}\n >\n ${e.label}\n </label>\n `)).join("")}\n </div>\n `:""}function s(){if(!t.editable)return n();let e="";return t.fields.forEach((t=>{"text"===t.type?e+=`\n <div class="f3-form-field">\n <label>${t.label}</label>\n <input type="${t.type}" \n name="${t.id}" \n value="${t.initial_value||""}"\n placeholder="${t.label}">\n </div>`:"textarea"===t.type?e+=`\n <div class="f3-form-field">\n <label>${t.label}</label>\n <textarea name="${t.id}" \n placeholder="${t.label}">${t.initial_value||""}</textarea>\n </div>`:"select"===t.type?e+=`\n <div class="f3-form-field">\n <label>${t.label}</label>\n <select name="${t.id}" value="${t.initial_value||""}">\n <option value="">${t.placeholder||`Select ${t.label}`}</option>\n ${t.options.map((e=>`<option ${e.value===t.initial_value?"selected":""} value="${e.value}">${e.label}</option>`)).join("")}\n </select>\n </div>`:"rel_reference"===t.type&&(e+=`\n <div class="f3-form-field">\n <label>${t.label} - <i>${t.rel_label}</i></label>\n <input type="text" \n name="${t.id}" \n value="${t.initial_value||""}"\n placeholder="${t.label}">\n </div>`)})),e;function n(){let e="";return t.fields.forEach((t=>{if("rel_reference"===t.type){if(!t.initial_value)return;e+=`\n <div class="f3-info-field">\n <span class="f3-info-field-label">${t.label} - <i>${t.rel_label}</i></span>\n <span class="f3-info-field-value">${t.initial_value||""}</span>\n </div>`}else if("select"===t.type){if(!t.initial_value)return;e+=`\n <div class="f3-info-field">\n <span class="f3-info-field-label">${t.label}</span>\n <span class="f3-info-field-value">${t.options.find((e=>e.value===t.initial_value))?.label||""}</span>\n </div>`}else e+=`\n <div class="f3-info-field">\n <span class="f3-info-field-label">${t.label}</span>\n <span class="f3-info-field-value">${t.initial_value||""}</span>\n </div>`})),e}}function o(){return`\n <div>\n <hr>\n <div class="f3-link-existing-relative">\n <label>${t.linkExistingRelative.hasOwnProperty("title")?t.linkExistingRelative.title:"Profile already exists?"}</label>\n <select>\n <option value="">${t.linkExistingRelative.hasOwnProperty("select_placeholder")?t.linkExistingRelative.select_placeholder:"Select profile"}</option>\n ${t.linkExistingRelative.options.map((t=>`<option value="${t.value}">${t.label}</option>`)).join("")}\n </select>\n </div>\n </div>\n `}function d(){return'\n <span class="f3-close-btn">\n ×\n </span>\n '}function l(){return'<div style="height: 24px;"></div>'}}(t);return n.innerHTML=a,function(){const a=n.querySelector("form");a.addEventListener("submit",t.onSubmit);a.querySelector(".f3-cancel-btn").addEventListener("click",c);const r=a.querySelector(".f3-edit-btn");r&&r.addEventListener("click",h);const s=a.querySelector(".f3-delete-btn");s&&t.onDelete&&s.addEventListener("click",t.onDelete);const o=a.querySelector(".f3-add-relative-btn");o&&t.addRelative&&o.addEventListener("click",(()=>{t.addRelativeActive?t.addRelativeCancel():t.addRelative(),t.addRelativeActive=!t.addRelativeActive,i()}));const d=a.querySelector(".f3-remove-relative-btn");d&&t.removeRelative&&d.addEventListener("click",(()=>{t.removeRelativeActive?t.removeRelativeCancel():t.removeRelative(),t.removeRelativeActive=!t.removeRelativeActive,i()}));a.querySelector(".f3-close-btn").addEventListener("click",e);const l=a.querySelector(".f3-link-existing-relative select");l&&l.addEventListener("change",t.linkExistingRelative.onSelect);t.onFormCreation&&t.onFormCreation({cont:n,form_creator:t});if(t.getKinshipInfo){const e=t.getKinshipInfo();e&&n.appendChild(e)}function c(){t.editable=!1,t.onCancel&&t.onCancel(),i()}function h(){t.editable=!t.editable,i()}}(),n}},createHistory:function(t,e,n){let i=[],a=-1;return{changed:function(){a<i.length-1&&(i=i.slice(0,a+1));const n=e();n.main_id=t.getMainId(),i.push(n),a++},back:function(){if(!s())return;a--,o(i[a])},forward:function(){if(!r())return;a++,o(i[a])},canForward:r,canBack:s};function r(){return a<i.length-1}function s(){return a>0}function o(e){const i=t.getMainId();(e=JSON.parse(JSON.stringify(e))).find((t=>t.id===i))||t.updateMainId(e.main_id),t.updateData(e),n()}},createHistoryControls:function(t,e){const n=i.select(t).append("div").attr("class","f3-history-controls");t.insertBefore(n.node(),t.firstChild);const a=n.append("button").attr("class","f3-back-button").on("click",(()=>{e.back(),s()})),r=n.append("button").attr("class","f3-forward-button").on("click",(()=>{e.forward(),s()}));return a.html(lt()),r.html(ct()),{back_btn:a.node(),forward_btn:r.node(),updateButtons:s,destroy:function(){e=null,i.select(t).select(".f3-history-controls").remove()}};function s(){a.classed("disabled",!e.canBack()),r.classed("disabled",!e.canForward()),e.canBack()||e.canForward()?n.style("opacity",1).style("pointer-events","auto"):n.style("opacity",0).style("pointer-events","none")}},treeFit:I,calculateTreeFit:E,cardToMiddle:A});function Ct({d:t,card_dim:e,card_display:n}){return{template:`\n <g class="card-body">\n <rect width="${e.w}" height="${e.h}" class="card-body-rect" />\n ${wt({d:t,card_dim:e,card_display:n}).template}\n </g>\n `}}function wt({d:t,card_dim:e,card_display:n}){return{template:`\n <g>\n <g class="card-text" clip-path="url(#card_text_clip)">\n <g transform="translate(${e.text_x}, ${e.text_y})">\n <text>\n ${Array.isArray(n)?n.map((e=>`<tspan x="0" dy="14">${e(t.data)}</tspan>`)).join("\n"):n(t.data)}\n </text>\n </g>\n </g>\n <rect width="${e.w-10}" height="${e.h}" style="mask: url(#fade)" class="text-overflow-mask" /> \n </g>\n `}}function $t({d:t,card_dim:e,is_new:n}){return{template:`\n <rect width="${e.w}" height="${e.h}" rx="4" ry="4" class="card-outline ${t.data.main&&!n?"card-main-outline":""} ${n?"card-new-outline":""}" />\n `}}function kt({x:t,y:e,rt:n,closed:i}){return{template:`\n <g style="\n transform: translate(-12.2px, -.5px);\n cursor: pointer;\n " \n fill="currentColor" class="card_break_link${i?" closed":""}"\n >\n <g style="transform: translate(${t}px,${e}px)scale(.02)rotate(${n+"deg"})">\n <rect width="1000" height="700" y="150" style="opacity: 0" />\n <g class="link_upper">\n <g>\n <path d="M616.3,426.4c19,4.5,38.1-7.4,42.6-26.4c4.4-19-7.4-38-26.5-42.5L522.5,332c-18,11.1-53.9,33.4-53.9,33.4l80.4,18.6c-7.8,4.9-19.5,12.1-31.3,19.4L616.3,426.4L616.3,426.4z"/>\n <path d="M727.4,244.2c-50.2-11.6-100.3,3.3-135.7,35.4c28.6,22.6,64.5,30.2,116.4,51.3l141,32.6c23.9,5.6,56.6,47.2,51.1,71l-4.1,17c-5.6,23.7-47.3,56.4-71.2,51l-143.4-33.2c-66.8-8.6-104.1-16.6-132.9-7.5c17.4,44.9,55.9,80.8,106.5,92.4L800.9,588c81.3,18.8,162.3-31.5,181.2-112.4l4-17c18.8-81.1-31.7-161.8-112.9-180.6L727.4,244.2z"/>\n </g>\n </g>\n <g class="link_lower">\n <path d="M421.2,384.9l-128,127.6c-13.9,13.8-13.9,36.2,0,50s36.3,13.8,50.2,0.1l136.2-135.8v-36.7l-58.4,58.1V384.9L421.2,384.9z"/>\n <path d="M204.6,742.8c-17.4,17.3-63.3,17.2-80.6,0.1l-12.3-12.3c-17.3-17.3,0.6-81.2,17.9-98.5l100.2-99.9c12.5-14.9,45.8-40.8,66.1-103.7c-47.7-9.4-98.9,4.2-135.8,40.9L54.2,575c-58.9,58.8-58.9,154,0,212.8L66.6,800c58.9,58.8,154.5,58.8,213.4,0l105.8-105.6c38.4-38.3,51.3-91.9,39.7-141c-44,22.7-89,62.3-116,84.8L204.6,742.8z"/>\n </g>\n <g class="link_particles">\n <path d="M351.9,248.4l-26.5,63.4l80.6,30.1L351.9,248.4z"/>\n <path d="M529.3,208l-43,26.6l35.4,52.3L529.3,208z"/>\n <path d="M426.6,158.8l-44-2.9l61.7,134.6L426.6,158.8z"/>\n </g>\n </g>\n </g>\n `}}function Mt(t,e,n){const i=document.createElementNS("http://www.w3.org/2000/svg","g");i.innerHTML=t,n?e.insertBefore(i,e.firstChild):e.appendChild(i)}const St={miniTree:function(t,e){if(t.data.to_add)return;const n=e.card_dim;if(t.all_rels_displayed)return;const a=i.create("svg:g").html(function({d:t,card_dim:e}){return{template:`\n <g class="card_family_tree" style="cursor: pointer">\n <rect x="-31" y="-25" width="72" height="15" fill="rgba(0,0,0,0)"></rect>\n <g transform="translate(${.8*e.w},6)scale(.9)">\n <rect x="-31" y="-25" width="72" height="15" fill="rgba(0,0,0,0)"></rect>\n <line y2="-17.5" stroke="#fff" />\n <line x1="-20" x2="20" y1="-17.5" y2="-17.5" stroke="#fff" />\n <rect x="-31" y="-25" width="25" height="15" rx="5" ry="5" class="card-male" />\n <rect x="6" y="-25" width="25" height="15" rx="5" ry="5" class="card-female" />\n </g>\n </g>\n `}}({d:t,card_dim:n}).template);return a.on("click",(function(n){n.stopPropagation(),e.onMiniTreeClick?e.onMiniTreeClick.call(this,n,t):O(e.store,{d:t})})),a.node()},lineBreak:function(t,e){if(t.data.to_add)return;const n=e.card_dim,a=i.create("svg:g").html(function({d:t,card_dim:e}){let n="",i=t.data.rels,a=t.data._rels||{},r=t.data.hide_rels,s=t=>t.father||t.mother,o=t=>t.children&&t.children.length>0;if((t.is_ancestry||t.data.main)&&(s(i)||s(a))&&(n+=kt({x:e.w/2,y:0,rt:-45,closed:r}).template),!t.is_ancestry&&t.added){const s=t.spouse,d=s.data.rels,l=s.data._rels||{};(o(i)||o(a))&&(o(d)||o(l))&&(n+=kt({x:t.sx-t.x+e.w/2+24.4,y:(t.x!==t.sx?e.h/2:e.h)+1,rt:135,closed:r}).template)}return{template:n}}({d:t,card_dim:n}).template);return a.on("click",(n=>{n.stopPropagation(),z(e.store,{d:t})})),a.node()},cardBody:function(t,e){const n=e.cardEditForm?"ADD":"UNKNOWN",a=e.card_dim;let r;t.data.to_add?(r=i.create("svg:g").html(function({d:t,card_dim:e,card_add:n,label:i}){return{template:`\n <g class="card-body ${n?"card_add":"card-unknown"}">\n <rect class="card-body-rect" width="${e.w}" height="${e.h}" fill="rgb(59, 85, 96)" />\n <text transform="translate(${e.w/2}, ${e.h/2})" text-anchor="middle" fill="#fff">\n <tspan font-size="18" dy="8">${i}</tspan>\n </text>\n </g>\n `}}({d:t,card_dim:a,card_add:e.cardEditForm,label:n}).template),r.on("click",(n=>{n.stopPropagation(),P(e.store,{d:t,cardEditForm:e.cardEditForm})}))):(r=i.create("svg:g").html(Ct({d:t,card_dim:a,card_display:e.card_display}).template),r.on("click",(function(n){n.stopPropagation(),e.onCardClick?e.onCardClick.call(this,n,t):O(e.store,{d:t})})));return r.node()},cardImage:function(t,e){if(t.data.to_add)return;const n=e.card_dim;return i.create("svg:g").html(function({d:t,image:e,card_dim:n,maleIcon:i,femaleIcon:a}){return{template:`\n <g style="transform: translate(${n.img_x}px,${n.img_y}px);" class="card_image" clip-path="url(#card_image_clip)">\n ${e?`<image href="${e}" height="${n.img_h}" width="${n.img_w}" preserveAspectRatio="xMidYMin slice" />`:"F"===t.data.data.gender&&a?a({card_dim:n}):"M"===t.data.data.gender&&i?i({card_dim:n}):`\n <g class="genderless-icon">\n <rect height="${n.img_h}" width="${n.img_w}" fill="rgb(59, 85, 96)" />\n <g transform="scale(${.001616*n.img_w})">\n <path transform="translate(50,40)" fill="lightgrey" d="M256 288c79.5 0 144-64.5 144-144S335.5 0 256 0 112 \n 64.5 112 144s64.5 144 144 144zm128 32h-55.1c-22.2 10.2-46.9 16-72.9 16s-50.6-5.8-72.9-16H128C57.3 320 0 377.3 \n 0 448v16c0 26.5 21.5 48 48 48h416c26.5 0 48-21.5 48-48v-16c0-70.7-57.3-128-128-128z" />\n </g>\n </g>\n `} \n </g>\n `}}({d:t,image:t.data.data.avatar||null,card_dim:n,maleIcon:null,femaleIcon:null}).template).node()},cardEdit:function(t,e){if(t.data.to_add)return;const n=e.card_dim,a=i.create("svg:g").html(function({d:t,card_dim:e,x:n,y:i}){return{template:`\n <g transform="translate(${n||e.w-20},${i||e.h-20})scale(.6)" style="cursor: pointer" class="card_edit pencil_icon">\n <circle fill="rgba(0,0,0,0)" r="17" cx="8.5" cy="8.5" />\n <path fill="currentColor" transform="translate(-1.5, -1.5)"\n d="M19.082,2.123L17.749,0.79c-1.052-1.052-2.766-1.054-3.819,0L1.925,12.794c-0.06,0.06-0.104,0.135-0.127,0.216\n l-1.778,6.224c-0.05,0.175-0.001,0.363,0.127,0.491c0.095,0.095,0.223,0.146,0.354,0.146c0.046,0,0.092-0.006,0.137-0.02\n l6.224-1.778c0.082-0.023,0.156-0.066,0.216-0.127L19.082,5.942C20.134,4.89,20.134,3.176,19.082,2.123z M3.076,13.057l9.428-9.428\n l3.738,3.739l-9.428,9.428L3.076,13.057z M2.566,13.961l3.345,3.344l-4.683,1.339L2.566,13.961z M18.375,5.235L16.95,6.66\n l-3.738-3.739l1.425-1.425c0.664-0.663,1.741-0.664,2.405,0l1.333,1.333C19.038,3.493,19.038,4.572,18.375,5.235z"/>\n </g>\n `}}({card_dim:n,x:n.w-46,y:n.h-20}).template);return a.on("click",(n=>{n.stopPropagation(),P(e.store,{d:t,cardEditForm:e.cardEditForm})})),a.node()},cardAdd:function(t,e){if(t.data.to_add)return;const n=e.card_dim,a=i.create("svg:g").html(function({d:t,card_dim:e,x:n,y:i}){return{template:`\n <g class="card_add_relative">\n <g transform="translate(${n||e.w/2},${i||e.h})scale(.13)">\n <circle r="80" cx="40" cy="40" fill="rgba(0,0,0,0)" />\n <g transform="translate(-10, -8)">\n <line\n x1="10" x2="90" y1="50" y2="50"\n stroke="currentColor" stroke-width="15" stroke-linecap="round"\n />\n <line\n x1="50" x2="50" y1="10" y2="90"\n stroke="currentColor" stroke-width="15" stroke-linecap="round"\n />\n </g>\n </g>\n </g>\n `}}({card_dim:n,x:n.w-26,y:n.h-20}).template);return a.on("click",(n=>{n.stopPropagation(),e.addRelative({d:t})})),a.node()}};function It(t,e,n){t&&(n?e.insertBefore(t,e.firstChild):e.appendChild(t))}function Et(t,e){function n(t,e,n){const{w:i,h:a}=t,r=e,s=n||[],o=t=>s.includes(t);return`${o("lx")?"M0,0":`M0,${r} Q 0,0 5,0`} ${o("rx")?`H${i}`:`H${i-r} Q ${i},0 ${i},5`} ${o("ry")?`V${a}`:`V${a-r} Q ${i},${a} ${i-r},${a}`} ${o("ly")?"H0":`H${r} Q 0,${a} 0,${a-r}`} z`}t.querySelector("defs#f3CardDef")||t.insertAdjacentHTML("afterbegin",`\n <defs id="f3CardDef">\n <linearGradient id="fadeGrad">\n <stop offset="0.9" stop-color="white" stop-opacity="0"/>\n <stop offset=".91" stop-color="white" stop-opacity=".5"/>\n <stop offset="1" stop-color="white" stop-opacity="1"/>\n </linearGradient>\n <mask id="fade" maskContentUnits="objectBoundingBox"><rect width="1" height="1" fill="url(#fadeGrad)"/></mask>\n <clipPath id="card_clip"><path d="${n({w:e.w,h:e.h},5)}"></clipPath>\n <clipPath id="card_text_clip"><rect width="${e.w-10}" height="${e.h}"></rect></clipPath>\n <clipPath id="card_image_clip"><path d="M0,0 Q 0,0 0,0 H${e.img_w} V${e.img_h} H0 Q 0,${e.img_h} 0,${e.img_h} z"></clipPath>\n <clipPath id="card_image_clip_curved"><path d="${n({w:e.img_w,h:e.img_h},5,["rx","ry"])}"></clipPath>\n </defs>\n `)}function At(t,e){this.cont=t,this.popup_cont=null,this.active=!1,this.onClose=e,this.init()}At.prototype.init=function(){this.popup_cont=i.select(this.cont).append("div").attr("class","f3-popup").node(),this.create()},At.prototype.create=function(){const t=i.select(this.popup_cont);t.html('\n <div class="f3-popup-content">\n <span class="f3-popup-close">&times;</span>\n <div class="f3-popup-content-inner"></div>\n </div>\n '),t.select(".f3-popup-close").on("click",(()=>{this.close()})),t.on("click",(e=>{e.target==t.node()&&this.close()}))},At.prototype.activate=function(t){t&&i.select(this.popup_cont).select(".f3-popup-content-inner").node().appendChild(t),this.open()},At.prototype.open=function(){this.active=!0},At.prototype.close=function(){this.popup_cont.remove(),this.active=!1,this.onClose&&this.onClose()};var Lt=Object.freeze({__proto__:null,infoPopup:function(..