Files
laoyang 7f00d3e553 feat(kin,movies): 家谱改用第三方库 family-chart;观影设置按钮改纯图标并统一页头度量
家谱(v13):
- 自研布局是死结,不是样式问题:连线的横杆是网格项,只能横跨「父母列→子女列」
  整段区间,中间夹着与血缘无关的人(如媳妇那侧的岳父母)时必然从卡片上穿过。
  换成 family-chart(D3 生态,MIT)后,排布只走本家血脉 + 配偶,姻亲不进画布,
  这个死结在构造上就不存在了。
- 接入踩到并修掉的坑:main_id = data[0].id(「我」必须排最前);
  卡片回调里自定义字段在 d.data.data(双层);库的 family-chart.css 是死文件
  (全挂在 .f3 作用域,运行时没有 .f3 元素);库的 svg 撑满选择器永不命中
  (必须自己补 .kin-chart svg.main_svg);setCanAdd/setOnCardClick 不在 chart 上
  (写错会抛异常,把 updateTree 一起带走 → 整张图空白,页面照样 200)。
- 关掉 setSingleParentEmptyCard:库默认给孩子只登记一位父母的人自动补一张无名
  配偶卡,看着像「凭空多出一个配偶」。
- 卡片用原生 <a> 链成员页,不依赖库的点击回调。

观影按钮(用户本轮原话):
- 「记一场电影」与「设置」高度仍不一致 —— 根因是文字按钮高度由 padding+line-height
  自然推出(43.8px),而 .btn-icon 写死了 40px。抽出 --act-* / --act-h 变量,两边同源。
- 设置按钮去掉「设置」二字,只留图标,图标换成三条横线(☰)。
- 设置按钮在所有页面排最右(.movie-set 用 margin-left:auto 顶到行尾)。
- 除设置外其他按钮都有颜色,与设置区分(主按钮实心 / 次要浅底 / 危险淡红)。
  顺带修掉一个特异性 bug:删除按钮被 .btn 品牌底盖成实心红,与「编辑」难分辨。
- 设置下拉四个条目文字前都加图标(行内 SVG,不引外部字体)。

测试与部署:
- 新增 _fb_kin_check.py(桌面,12 条)+ _fb_kin_falsify.py(6/6)证明
  「整张家谱空白」这类只靠通用几何抓不到的坏法能被抓住。
- _fb_geom_mobile.py 家谱段重写为窄屏语义(库按容器 fit 缩放是正常行为,
  改为断「比例没被压扁 / 缩放不至于看不清」),并加 _fb_kin_mobile_falsify.py(4/4)。
- _fb_btn_check.py(59 条)+ _fb_btn_falsify.py(3/3)覆盖观影页头按钮五条需求。
- familybook_deploy.sh / familybook_smoke.sh 的家谱断言改为第三方库形态,
  设置按钮断言改为 btn-icon 纯图标 + 三条横线 + 条目图标。
- 新增 .gitattributes:vendor 库与 .min.js 标 -text,原样入库不被改写行尾。
2026-10-01 19:35:48 +08:00

3 lines
104 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// https://donatso.github.io/family-chart/ v0.9.0 Copyright 2025 donatso
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3")):"function"==typeof define&&define.amd?define(["exports","d3"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).f3={},e.d3)}(this,function(e,t){"use strict";function n(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,Object.freeze(t)}var i=n(t);function r(e,t,n){return n.find(n=>n.id!==t.id&&e.rels.parents.includes(n.id))}function s(e,t,n){if(e.exiting=n,t)if(0!==e.depth||e.spouse)if(e.spouse)e._x=e.spouse.x,e._y=e.spouse.y;else if(e.is_ancestry){if(!e.parent)throw new Error("no parent");e._x=e.parent.x,e._y=e.parent.y}else e._x=e.psx,e._y=e.psy;else e._x=e.x,e._y=e.y;else if(n){const t=e.x>0?1:-1,n=e.y>0?1:-1;e._x=e.x+400*t,e._y=e.y+400*n}}function a({tree:e,data_stash:t,private_cards_config:n}){const i={},r=n.condition;if(!r)return console.error("private_cards_config.condition is not set");e.forEach(e=>{if(e.data._new_rel_data)return;const n=function(e){const n=[];let s=!1;return a(e),i[e]=s,s;function a(e){if(s)return;if(i.hasOwnProperty(e))return s=i[e],s;const o=t.find(t=>t.id===e);if(!o)throw new Error("no d");if(o._new_rel_data)return;if(r(o))return s=!0,!0;const d=o.rels;[...d.parents,...d.spouses||[]].forEach(e=>{e&&(n.includes(e)||(n.push(e),a(e)))})}}(e.data.id);n&&(e.is_private=n)})}function o(e,t){const n=t.find(t=>t.id===e);if(!n)throw new Error("no datum");const r=i.hierarchy(n,e=>function(e){return e.rels.parents.filter(e=>e).map(e=>t.find(t=>t.id===e)).filter(e=>e&&!e._new_rel_data&&!e.to_add)}(e)),s=i.hierarchy(n,e=>function(e){return[...e.rels.children||[]].map(e=>t.find(t=>t.id===e)).filter(e=>e&&!e._new_rel_data&&!e.to_add)}(e));return{ancestry:r.height,progeny:s.height}}function d({data:e,rels:t}){return{id:(n=(new Date).getTime(),i=performance&&performance.now&&1e3*performance.now()||0,"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random();return n>0?(t=(n+t)%16|0,n=Math.floor(n/16)):(t=(i+t)%16|0,i=Math.floor(i/16)),("x"===e?t:3&t|8).toString(16)})),data:e||{},rels:Object.assign({parents:[],children:[],spouses:[]},t||{})};var n,i}function l(e,t){const n=e.data.rels;return[...n.parents,...n.spouses||[],...n.children||[]].filter(e=>e).every(e=>t.some(t=>t.data.id===e))}function c(e,t,n){const i=.4*n,r=Math.max(...e.data.map(e=>e.is_ancestry?e.depth:0));let s=t.depth*i;return 0===t.depth&&!t.spouse||t.is_ancestry||(s+=r*i,t.spouse&&(s+=i),s+=t.depth*i),s}function u(e,t,n=!0){const i=[];function r(e,t){return e.every(e=>t.some(t=>e.id===t.id))}function s(e){const t={},n=e;return(e.children||[]).forEach(e=>{const i=e.data.rels,r=i.parents[0]===n.data.id?i.parents[1]:i.parents[0];t[r]||(t[r]=[]),t[r].push(e)}),t}!function a(o){if(!o.children)return;const d=o.data,l=(o.data.rels.spouses||[]).map(e=>t.find(t=>t.id===e)),c=s(o);l.forEach(l=>{if(i.some(e=>e.some(e=>r([d,l],[e.p1,e.p2]))))return;const u=function(n,i,a){const o=[];return d(e),o;function d(e){if(e!==n&&e.children){const n=e.data,l=(e.data.rels.spouses||[]).map(e=>t.find(t=>t.id===e)),c=s(e);l.forEach(t=>{r([i,a],[n,t])?o.push({d:e,p1:n,p2:t}):(c[t.id]||[]).forEach(e=>{d(e)})})}}}(o,d,l);if(u.length>0){const t=[{d:o,p1:d,p2:l},...u];i.push(t),function(t){if(t.forEach(({d:n,p1:i,p2:r},s)=>{n.data._tgdp_sp||(n.data._tgdp_sp={});let a=e===n?"main":n.parent.data.id;!function(e,t,n){e.data.__tgdp_sp&&e.data.__tgdp_sp[t]&&e.data.__tgdp_sp[t].hasOwnProperty(n.id)&&(e.data._tgdp_sp[t][n.id]=e.data.__tgdp_sp[t][n.id],delete e.data.__tgdp_sp[t][n.id])}(n,a,r),n.data._tgdp_sp[a]||(n.data._tgdp_sp[a]={});let o=1;n.data._tgdp_sp[a].hasOwnProperty(r.id)?o=n.data._tgdp_sp[a][r.id]:n.data._tgdp_sp[a][r.id]=o,t[s].val=o}),n){if(t.every(e=>e.val<0)){const n=t.sort((e,t)=>t.val-e.val)[0],{d:i,p1:r,p2:s}=n,a=e===i?"main":i.parent.data.id;i.data._tgdp_sp[a][s.id]=1}if(t.filter(e=>e.val>0).length>1){const n=t.sort((e,t)=>t.val-e.val)[0];t.forEach(t=>{if(t===n)return;const{d:i,p1:r,p2:s}=t,a=e===i?"main":i.parent.data.id;i.data._tgdp_sp[a][s.id]=-1})}}}(t),function(t){t.forEach(({d:t,p1:n,p2:i})=>{const r=e===t?"main":t.parent.data.id;if(t.data._tgdp_sp[r][i.id]<0){const e=s(t);e[i.id]&&(t.children=t.children.filter(t=>!e[i.id].includes(t)),0===t.children.length&&delete t.children)}})}(t)}else{let t=e===o?"main":o.parent.data.id;!function(e,t,n){e.data._tgdp_sp&&e.data._tgdp_sp[t]&&e.data._tgdp_sp[t].hasOwnProperty(n.id)&&(e.data.__tgdp_sp||(e.data.__tgdp_sp={}),e.data.__tgdp_sp[t]||(e.data.__tgdp_sp[t]={}),e.data.__tgdp_sp[t][n.id]=e.data._tgdp_sp[t][n.id],delete e.data._tgdp_sp[t][n.id])}(o,t,l),(c[l.id]||[]).forEach(e=>{a(e)})}})}(e),function(e){let t=0;e.forEach(e=>{t+=1,e.forEach(e=>{e.d._toggle_id_sp||(e.d._toggle_id_sp={}),e.d._toggle_id_sp[e.p2.id]=t})})}(i)}function h(e,t=!0){const n=[];!function i(r){if(r.children){if(n.some(e=>e.includes(r)))return;const s=function(t){const n=[];return i(e),n;function i(e){var r,s;e.children&&(r=t,s=e.children,r!==s&&r.every(e=>s.some(t=>e.data.id===t.data.id))?n.push(e):e.children.forEach(e=>{i(e)}))}}(r.children);if(s.length>0){const i=[r,...s];n.push(i),function(n){if(n.forEach(t=>{t.data._tgdp||(t.data._tgdp={});const n=e===t?"main":t.parent.data.id;t.data._tgdp[n]||(t.data._tgdp[n]=-1),t._toggle=t.data._tgdp[n]}),t){if(n.every(e=>e._toggle<0)){const t=n.sort((e,t)=>t._toggle-e._toggle)[0],i=e===t?"main":t.parent.data.id;t.data._tgdp[i]=1}if(n.filter(e=>e._toggle>0).length>1){const t=n.sort((e,t)=>t._toggle-e._toggle)[0];n.forEach(n=>{if(n===t)return;const i=n,r=e===i?"main":i.parent.data.id;i.data._tgdp[r]=-1})}}}(i),function(t){t.forEach(t=>{const n=e===t?"main":t.parent.data.id;t.data._tgdp[n]<0&&delete t.children})}(i)}else r.children.forEach(e=>{i(e)})}}(e),function(e){let t=0;e.forEach(e=>{t+=1,e.forEach(e=>{e._toggle_id=t})})}(n)}function p(e){return e.forEach(e=>{e.rels.parents||(e.rels.parents=[]),e.rels.spouses||(e.rels.spouses=[]),e.rels.children||(e.rels.children=[]),function(e){e.rels.parents||(e.rels.parents=[]);e.rels.father&&e.rels.parents.push(e.rels.father);e.rels.mother&&e.rels.parents.push(e.rels.mother);delete e.rels.father,delete e.rels.mother}(e)}),e}function f(e,t=!1){return e.forEach(n=>{var i;if(t){let t,r;null===(i=n.rels.parents)||void 0===i||i.forEach(n=>{const i=e.find(e=>e.id===n);if(!i)throw new Error("Parent not found");"M"===i.data.gender&&(t?r=i.id:t=i.id),"F"===i.data.gender&&(r?t=i.id:r=i.id)}),t&&(n.rels.father=t),r&&(n.rels.mother=r),delete n.rels.parents}n.rels.parents&&0===n.rels.parents.length&&delete n.rels.parents,n.rels.spouses&&0===n.rels.spouses.length&&delete n.rels.spouses,n.rels.children&&0===n.rels.children.length&&delete n.rels.children}),e}function _(e,{main_id:t=null,node_separation:n=250,level_separation:s=150,single_parent_empty_card:o=!0,is_horizontal:c=!1,one_level_rels:p=!1,sortChildrenFunction:f,sortSpousesFunction:_,ancestry_depth:g,progeny_depth:m,show_siblings_of_main:v=!1,modifyTreeHierarchy:y,private_cards_config:w,duplicate_branch_toggle:b=!1,on_toggle_one_close_others:C=!0}){if(!e||!e.length)throw new Error("No data");c&&([n,s]=[s,n]);const x=o?function(e){const t=[];for(let t=0;t<e.length;t++){const i=e[t];if(i.rels.children&&i.rels.children.length>0){let t;i.rels.spouses||(i.rels.spouses=[]),i.rels.children.forEach(r=>{const s=e.find(e=>e.id===r);if(2!==s.rels.parents.length){if(t||(t=n(i)),t.rels.children||(t.rels.children=[]),t.rels.children.push(s.id),1!==s.rels.parents.length)throw new Error("child has more than 1 parent");s.rels.parents.push(t.id)}})}}return t.forEach(t=>e.push(t)),e;function n(n){return(n.rels.spouses||[]).map(t=>e.find(e=>e.id===t)).filter(e=>void 0!==e).find(e=>e.to_add)||function(e){const n=d({data:{gender:"M"===e.data.gender?"F":"M"},rels:{spouses:[e.id]}});n.to_add=!0,t.push(n),e.rels.spouses||(e.rels.spouses=[]);return e.rels.spouses.push(n.id),n}(n)}}(e):e;t&&x.find(e=>e.id===t)||(t=x[0].id);const $=x.find(e=>e.id===t);if(!$)throw new Error("Main not found");const k=R($,"children",!1),E=R($,"parents",!0);x.forEach(e=>e.main=e===$),function(e,t){const n=(e[0].x-t[0].x)/2;e.forEach(e=>e.x-=n),t.forEach(e=>e.x+=n)}(E,k);const S=(I=k,(M=E).forEach(e=>{e.is_ancestry=!0}),M.forEach(e=>1===e.depth?e.parent=I[0]:null),[...I,...M.slice(1)]);var M,I;!function(e){e.forEach(t=>{if(delete t.children,e.forEach(e=>{e.parent===t&&(e.is_ancestry?(t.parents||(t.parents=[]),t.parents.push(e)):(t.children||(t.children=[]),t.children.push(e)))}),t.parents&&2===t.parents.length){const e=t.parents[0],n=t.parents[1];e.coparent=n,n.coparent=e}})}(S),function(e,t){for(let n=e.length;n--;){const i=e[n];if(!i.is_ancestry){let n=i.data.rels.spouses||[];if(i._ignore_spouses&&(n=n.filter(e=>!i._ignore_spouses.includes(e))),n.length>0){if(p&&i.depth>0)continue;const r="M"===i.data.data.gender?-1:1;i.x+=n.length/2*t*r,n.forEach((n,s)=>{const a={data:x.find(e=>e.id===n),added:!0,depth:i.depth,spouse:i,x:i.x-t*(s+1)*r,y:i.y,tid:`${i.data.id}-spouse-${s}`};a.sx=s>0?a.x:a.x+t/2*r,a.sy=s>0?a.y:a.y+t/2*r,i.spouses||(i.spouses=[]),i.spouses.push(a),e.push(a)})}}if(i.parents&&2===i.parents.length){const e=i.parents[0],n=i.parents[1],r=e.x-(e.x-n.x)/2,s=(e,n)=>r+t/2*(e.x<n.x?1:-1);n.x=s(e,n),e.x=s(n,e)}}}(S,n),v&&!p&&function({tree:e,data_stash:t,node_separation:n,sortChildrenFunction:r}){const s=e.find(e=>e.data.main);if(!s)throw new Error("no main");const a=s.data.rels.parents[0],o=s.data.rels.parents[1],d=function(e){return t.filter(t=>!!(t.id!==e.data.id&&(a&&t.rels.parents.includes(a)||o&&t.rels.parents.includes(o))))}(s);if(d.length>0&&!s.parents)throw new Error("no parents");const l=function(t){const n=[];for(let i=0;i<d.length;i++){const r={data:d[i],sibling:!0,x:0,y:t.y,depth:t.depth-1,parents:[]},s=t.parents.find(e=>e.data.id===r.data.rels.parents[0]),a=t.parents.find(e=>e.data.id===r.data.rels.parents[1]);s&&r.parents.push(s),a&&r.parents.push(a),e.push(r),n.push(r)}return n}(s);!function(e){var t,s;const a=[e,...l];r&&a.sort((e,t)=>r(e.data,t.data)),a.sort((t,n)=>{const i=e.parents.find(e=>e.data.id===t.data.rels.parents[0]),r=e.parents.find(e=>e.data.id===t.data.rels.parents[1]),s=e.parents.find(e=>e.data.id===n.data.rels.parents[0]),a=e.parents.find(e=>e.data.id===n.data.rels.parents[1]);return!r&&a?-1:r&&!a||!i&&s?1:i&&!s?-1:0});const o=e.x,d=(e.spouses||[]).map(e=>e.x),c=i.extent([o,...d]),u=a.findIndex(t=>t.data.id===e.data.id);for(let e=0;e<a.length;e++){if(e===u)continue;a[e].x=e<u?(null!==(t=c[0])&&void 0!==t?t:0)-n*(u-e):(null!==(s=c[1])&&void 0!==s?s:0)+n*(e-u)}}(s)}({tree:S,data_stash:x,node_separation:n,sortChildrenFunction:f}),function(e){e.forEach(e=>{if(e.is_ancestry)return;if(0===e.depth)return;if(e.added)return;if(e.sibling)return;const t=e.parent,n=((null==t?void 0:t.spouses)||[]).find(t=>e.data.rels.parents.includes(t.data.id));if(t&&n){t.added||n.added||console.error("no added spouse",t,n);const r=t.added?t:n;i(e,r)}else if(t||n){const r=t||n;if(!r)throw new Error("no progeny parent");r.sx=r.x,r.sy=r.y,i(e,r)}function i(e,t){e.psx=c?t.y:t.sx,e.psy=c?t.sx:t.y}})}(S),function(e){e.forEach(e=>{if(e.y*=e.is_ancestry?-1:1,c){const t=e.x;e.x=e.y,e.y=t}})}(S),S.forEach(e=>e.all_rels_displayed=l(e,S)),w&&a({tree:S,data_stash:x,private_cards_config:w}),function(e){const t=[];e.forEach(n=>{if(t.includes(n.data.id)){const i=e.filter(e=>e.data.id===n.data.id);i.forEach((e,r)=>{e.tid=`${n.data.id}--x${r+1}`,e.duplicate=i.length,t.push(n.data.id)})}else n.tid=n.data.id,t.push(n.data.id)})}(S),b&&function(e){e.forEach(e=>{if(!e.spouse)return;const t=e.spouse;if(e.duplicate&&t.data._tgdp_sp){const n=t.data.main?"main":t.parent.data.id;t.data._tgdp_sp[n]?.hasOwnProperty(e.data.id)&&(e._toggle=t.data._tgdp_sp[n][e.data.id])}})}(S);const A=function(e,t,n){c&&([t,n]=[n,t]);const r=i.extent(e,e=>e.x),s=i.extent(e,e=>e.y);if(void 0===r[0]||void 0===r[1]||void 0===s[0]||void 0===s[1])throw new Error("No extent");return{width:r[1]-r[0]+t,height:s[1]-s[0]+n,x_off:-r[0]+t/2,y_off:-s[0]+n/2}}(S,n,s);return{data:S,data_stash:x,dim:A,main_id:$.id,is_horizontal:c};function R(e,t,a){const o="children"===t?function(e){const t=[...e.rels.children||[]].map(e=>x.find(t=>t.id===e)).filter(e=>void 0!==e);f&&t.sort(f);(function(e){e.sort((e,t)=>{const n=e._new_rel_data,i=t._new_rel_data;return n&&!i?1:!n&&i?-1:0})})(t),_&&_(e,x);return function(e,t,n){if(!t.rels.children)return;const i=t.rels.spouses||[];e.sort((e,s)=>{const a=r(e,t,n),o=r(s,t,n),d=a?i.indexOf(a.id):-1,l=o?i.indexOf(o.id):-1;return"M"===t.data.gender?d-l:l-d})}(t,e,x),t}:function(e){let t=[...e.rels.parents];const n=x.find(e=>e.id===t[0]);n&&"F"===n.data.gender&&t.reverse();return t.filter(e=>e).map(e=>x.find(t=>t.id===e)).filter(e=>void 0!==e)},d=i.tree().nodeSize([n,s]).separation(function(e,t){let n=1;a||(v(e,t)||(n+=.25),p||function(e,t){return w(e)||w(t)}(e,t)&&(n+=function(e,t){return.5*((e.data.rels.spouses||[]).length+(t.data.rels.spouses||[]).length)}(e,t)),v(e,t)&&!function(e,t){const n=[...e.data.rels.parents].sort(),i=[...t.data.rels.parents].sort();return n.length===i.length&&n.every((e,t)=>e===i[t])}(e,t)&&(n+=.125));return n}),l=i.hierarchy(e,o);!function(e,t){let n=t?g:m;p&&(n=1);return n||0===n?(i(e,0),e):e;function i(e,t){t===n?e.children&&delete e.children:e.children&&e.children.forEach(e=>{i(e,t+1)})}}(l,a),b&&function(e,t,n){n?h(e,C):u(e,t,C)}(l,x,a),y&&y(l,a),d(l);const c=l.descendants();return c.forEach(e=>{void 0===e.x&&(e.x=0),void 0===e.y&&(e.y=0)}),c;function v(e,t){return e.parent==t.parent}function w(e){return e.data.rels.spouses&&e.data.rels.spouses.length>0}}}function g(e){return m(e.data,e)}function m(e,t){return _(p(e),t)}function v(e){let t;const n=Object.assign({transition_time:1e3},e);n.main_id_history=[],n.data&&(s(n.data),p(n.data));return{state:n,updateTree:e=>{n.data&&0!==n.data.length&&(n.tree=function(){const e={main_id:n.main_id};void 0!==n.node_separation&&(e.node_separation=n.node_separation);void 0!==n.level_separation&&(e.level_separation=n.level_separation);void 0!==n.single_parent_empty_card&&(e.single_parent_empty_card=n.single_parent_empty_card);void 0!==n.is_horizontal&&(e.is_horizontal=n.is_horizontal);void 0!==n.one_level_rels&&(e.one_level_rels=n.one_level_rels);void 0!==n.modifyTreeHierarchy&&(e.modifyTreeHierarchy=n.modifyTreeHierarchy);void 0!==n.sortChildrenFunction&&(e.sortChildrenFunction=n.sortChildrenFunction);void 0!==n.sortSpousesFunction&&(e.sortSpousesFunction=n.sortSpousesFunction);void 0!==n.ancestry_depth&&(e.ancestry_depth=n.ancestry_depth);void 0!==n.progeny_depth&&(e.progeny_depth=n.progeny_depth);void 0!==n.show_siblings_of_main&&(e.show_siblings_of_main=n.show_siblings_of_main);void 0!==n.private_cards_config&&(e.private_cards_config=n.private_cards_config);void 0!==n.duplicate_branch_toggle&&(e.duplicate_branch_toggle=n.duplicate_branch_toggle);return _(n.data,e)}(),!n.main_id&&n.tree&&r(n.tree.main_id),t&&t(e))},updateData:e=>{s(e),p(e),n.data=e,function(){if(n.main_id){!n.data.find(e=>e.id===n.main_id)&&n.data.length>0&&r(n.data[0].id)}else n.data.length>0&&r(n.data[0].id)}()},updateMainId:r,getMainId:()=>n.main_id,getData:()=>n.data,getTree:()=>n.tree,setOnUpdate:e=>t=e,getMainDatum:function(){const e=n.data.find(e=>e.id===n.main_id);if(!e)throw new Error("Main datum not found");return e},getDatum:i,getTreeMainDatum:function(){if(!n.tree)throw new Error("No tree");const e=n.tree.data.find(e=>e.data.id===n.main_id);if(!e)throw new Error("No tree main datum");return e},getTreeDatum:function(e){if(!n.tree)throw new Error("No tree");const t=n.tree.data.find(t=>t.data.id===e);return t||void 0},getLastAvailableMainDatum:function(){let e=n.main_id_history.slice(0).reverse().find(e=>i(e));!e&&n.data.length>0&&(e=n.data[0].id);if(!e)throw new Error("No main id");e!==n.main_id&&r(e);const t=i(e);if(!t)throw new Error("Main datum not found");return t},methods:{}};function i(e){const t=n.data.find(t=>t.id===e);if(t)return t}function r(e){e!==n.main_id&&(n.main_id_history=n.main_id_history.filter(t=>t!==e).slice(-10),n.main_id_history.push(e),n.main_id=e)}function s(e){if(void 0===n.legacy_format){for(let t of e)if(t.rels.father||t.rels.mother)return void(n.legacy_format=!0);n.legacy_format=!1}}}function y({t:e,svg:t,transition_time:n=2e3}){const r=E(t),s=r.__zoomObj;i.select(r).transition().duration(n||0).delay(n?100:0).call(s.transform,i.zoomIdentity.scale(e.k).translate(e.x,e.y))}function w({svg:e,svg_dim:t,tree_dim:n,transition_time:i}){y({t:b(t,n),svg:e,transition_time:i})}function b(e,t){let n=Math.min(e.width/t.width,e.height/t.height);n>1&&(n=1);return{k:n,x:t.x_off+(e.width-t.width*n)/n/2,y:t.y_off+(e.height-t.height*n)/n/2}}function C({datum:e,svg:t,svg_dim:n,scale:i,transition_time:r}){const s=i||1;y({t:{k:s,x:(n.width/2-e.x*s)/s,y:(n.height/2-e.y)/s},svg:t,transition_time:r})}function x({amount:e,svg:t,transition_time:n=500}){const r=E(t),s=r.__zoomObj;if(!s)throw new Error("Zoom object not found");i.select(r).transition().duration(n||0).delay(n?100:0).call(s.scaleBy,e)}function $(e){const t=E(e);return i.zoomTransform(t)}function k(e,t){const n=E(e);x({amount:t/i.zoomTransform(n).k,svg:e})}function E(e){const t=e.__zoomObj?e:e.parentNode;if(!t.__zoomObj)throw new Error("Zoom object not found");return t}function S(e,t={}){if(e.__zoom)return void console.log("zoom already setup");const n=e.querySelector(".view"),r=i.zoom().on("zoom",t.onZoom||function(e){i.select(n).attr("transform",e.transform)});i.select(e).call(r),e.__zoomObj=r,t.zoom_polite&&r.filter(function(e){return!("wheel"===e.type&&!e.ctrlKey)&&!(e.touches&&e.touches.length<2)})}function M(e,t,n={}){const r=t.data.reduce((e,n)=>(function(e,t=!1){const n=[];return(e.spouses||e.coparent)&&function(e){function t(e,t){return{d:[[e.x,e.y],[t.x,t.y]],_d:()=>[e.is_ancestry?[r(e,"x")-1e-4,r(e,"y")]:[e.x,e.y],e.is_ancestry?[r(t,"x"),r(t,"y")]:[e.x-1e-4,e.y]],curve:!1,id:a(e,t),depth:e.depth,spouse:!0,is_ancestry:t.is_ancestry,source:e,target:t}}e.spouses?e.spouses.forEach(i=>n.push(t(e,i))):e.coparent&&n.push(t(e,e.coparent))}(e),function(e){if(!e.parents)return;const t=e.parents[0],r=e.parents[1]||t,o={x:i(t,r,"x"),y:i(t,r,"y")};n.push({d:s(e,o),_d:()=>s({x:e.x,y:e.y},{x:e.x,y:e.y}),curve:!0,id:a(e,t,r),depth:e.depth+1,is_ancestry:!0,source:e,target:[t,r]})}(e),function(e){e.children&&0!==e.children.length&&e.children.forEach((i,o)=>{const d=function(e,t){const n=(t.spouses||[]).find(t=>e.data.rels.parents.includes(t.data.id));return n}(i,e)||e,l=d.sx;if("number"!=typeof l)throw new Error("sx is not a number");const c=t?{x:e.x,y:l}:{x:l,y:e.y};n.push({d:s(i,c),_d:()=>s(c,{x:r(c,"x"),y:r(c,"y")}),curve:!0,id:a(i,e,d),depth:e.depth+1,is_ancestry:!1,source:[e,d],target:i})})}(e),n;function i(e,t,n,i=!1){return i?r(e,n)-(r(e,n)-r(t,n))/2:e[n]-(e[n]-t[n])/2}function r(e,t){const n=e.hasOwnProperty(`_${t}`)?e[`_${t}`]:e[t];if("number"!=typeof n)throw new Error(`${t} is not a number`);return n}function s(e,n){return t?function(e,t){const n=e.x+(t.x-e.x)/2;return[[e.x,e.y],[n,e.y],[n,e.y],[n,t.y],[n,t.y],[t.x,t.y]]}(e,n):function(e,t){const n=e.y+(t.y-e.y)/2;return[[e.x,e.y],[e.x,n],[e.x,n],[t.x,n],[t.x,n],[t.x,t.y]]}(e,n)}function a(...e){return e.map(e=>e.tid).sort().join(", ")}}(n,t.is_horizontal).forEach(t=>e[t.id]=t),e),{}),s=Object.values(r),a=i.select(e).select(".links_view").selectAll("path.link").data(s,e=>e.id);if(void 0===n.transition_time)throw new Error("transition_time is undefined");const o=a.exit(),d=a.enter().append("path").attr("class","link"),l=d.merge(a);o.each(function(e){const t=i.select(this);t.transition("op").duration(800).style("opacity",0),t.transition("path").duration(n.transition_time).attr("d",I(e,!0)).on("end",()=>t.remove())}),d.each(function(e){i.select(this).attr("fill","none").attr("stroke","#fff").attr("stroke-width",1).style("opacity",0).attr("d",I(e,!0))}),l.each(function(e){const r=i.select(this),s=n.initial?c(t,e,n.transition_time):0;r.transition("path").duration(n.transition_time).delay(s).attr("d",I(e)).style("opacity",1)})}function I(e,t=!1){const n=i.line().curve(i.curveMonotoneY),r=i.line().curve(i.curveBasis),s=t?e._d():e.d;return e.curve?r(s):n(s)}function A(e,t={}){const n=e.getBoundingClientRect(),r=`\n <svg class="main_svg">\n <rect width="${n.width}" height="${n.height}" fill="transparent" />\n <g class="view">\n <g class="links_view"></g>\n <g class="cards_view"></g>\n </g>\n <g style="transform: translate(100%, 100%)">\n <g class="fit_screen_icon cursor-pointer" style="transform: translate(-50px, -50px); display: none">\n <rect width="27" height="27" stroke-dasharray="13.5" stroke-dashoffset="6.75" \n style="stroke:#fff;stroke-width:4px;fill:transparent;"/>\n <circle r="5" cx="13.5" cy="13.5" style="fill:#fff" /> \n </g>\n </g>\n </svg>\n `,s=function(e){let t=e.querySelector("#f3Canvas");t||(t=i.create("div").attr("id","f3Canvas").attr("style","position: relative; overflow: hidden; width: 100%; height: 100%;").node());return t}(e),a=i.create("div").node();a.innerHTML=r;const o=a.querySelector("svg");return s.appendChild(o),e.appendChild(s),S(s,t),o}function R(e){return A(e,{onZoom:D(()=>e.querySelector("svg .view"),()=>e.querySelector("#htmlSvg .cards_view"))}),H(e),{svg:e.querySelector("svg.main_svg"),svgView:e.querySelector("svg .view"),htmlSvg:e.querySelector("#htmlSvg"),htmlView:e.querySelector("#htmlSvg .cards_view")}}function H(e){const t=i.select(e).select("#f3Canvas").append("div").attr("id","htmlSvg").attr("style","position: absolute; width: 100%; height: 100%; z-index: 2; top: 0; left: 0");return t.append("div").attr("class","cards_view").style("transform-origin","0 0"),t.node()}function D(e,t){return function(n){const r=n.transform;i.select(e()).style("transform",`translate(${r.x}px, ${r.y}px) scale(${r.k}) `),i.select(t()).style("transform",`translate(${r.x}px, ${r.y}px) scale(${r.k}) `)}}var F=Object.freeze({__proto__:null,createHtmlSvg:H,default:R,onZoomSetup:D});function O(e){let t=[];return function(n){const r=function(e,t){return t.length>0?t.filter(t=>!e.find(e=>e.data.id===t.data.id)):[]}(n,t);return t=[...n,...r],function(e,t){const n=i.select(e).selectAll("div.card_cont_2fake").data(t,e=>e.data.id),r=n.exit(),s=n.enter().append("div").attr("class","card_cont_2fake").style("display","none").attr("data-id",()=>Math.random()),a=s.merge(n);function o(e){e.unique_id=i.select(this).attr("data-id")}function d(e){e.unique_id=i.select(this).attr("data-id")}function l(e){e&&(e.unique_id=i.select(this).attr("data-id"),i.select(this).remove())}r.each(l),s.each(o),a.each(d)}(L(e),t),t}}function L(e){return i.select(e()).select("div.cards_view_fake").node()}const T=O;function P(e,t,n,r={}){r.initial=r.hasOwnProperty("initial")?r.initial:!i.select(t.parentNode).select(".card_cont").node(),r.transition_time=r.hasOwnProperty("transition_time")?r.transition_time:1e3,r.cardComponent?function(e,t,n,r={}){const a=r.cardHtmlDiv?r.cardHtmlDiv:e.closest("#f3Canvas").querySelector("#htmlSvg"),o=i.select(L(()=>a)).selectAll("div.card_cont_fake").data(t.data,e=>e.data.id),d=o.exit(),l=o.enter().append("div").attr("class","card_cont_fake").style("display","none"),u=l.merge(o);d.each(e=>s(e,!1,!0)),l.each(e=>s(e,!0,!1)),d.each(function(e){const t=e,s=t?[t._x,t._y]:[0,0],a=i.select(n(e)),o=i.select(this);a.transition().duration(r.transition_time).style("opacity",0).style("transform",`translate(${s[0]}px, ${s[1]}px)`).on("end",()=>o.remove())}),o.each(function(e){}),l.each(function(e){i.select(n(e)).style("position","absolute").style("top","0").style("left","0").style("opacity",0).style("transform",`translate(${e._x}px, ${e._y}px)`)}),u.each(function(e){const s=i.select(n(e)),a=r.initial?c(t,e,r.transition_time):0;s.transition().duration(r.transition_time).delay(a).style("transform",`translate(${e.x}px, ${e.y}px)`).style("opacity",1)})}(t,e,n,r):r.cardHtml?function(e,t,n,r={}){const a=function(e){if(r.cardHtmlDiv)return r.cardHtmlDiv;const t=e.closest("#f3Canvas");if(!t)throw new Error("canvas not found");const n=t.querySelector("#htmlSvg");if(!n)throw new Error("htmlSvg not found");return n}(e),o=i.select(a).select(".cards_view").selectAll("div.card_cont").data(t.data,e=>e.tid),d=o.exit(),l=o.enter().append("div").attr("class","card_cont").style("pointer-events","none"),u=l.merge(o);d.each(e=>s(e,!1,!0)),l.each(e=>s(e,!0,!1)),d.each(function(e){const t=e,n=t?[t._x,t._y]:[0,0],s=i.select(this);s.transition().duration(r.transition_time).style("opacity",0).style("transform",`translate(${n[0]}px, ${n[1]}px)`).on("end",()=>s.remove())}),o.each(function(e){}),l.each(function(e){i.select(this).style("position","absolute").style("top","0").style("left","0").style("transform",`translate(${e._x}px, ${e._y}px)`).style("opacity",0),n.call(this,e)}),u.each(function(e){n.call(this,e);const s=r.initial?c(t,e,r.transition_time):0;i.select(this).transition().duration(r.transition_time).delay(s).style("transform",`translate(${e.x}px, ${e.y}px)`).style("opacity",1)})}(t,e,n,r):function(e,t,n,r={}){const a=i.select(e).select(".cards_view").selectAll("g.card_cont").data(t.data,e=>e.data.id),o=a.exit(),d=a.enter().append("g").attr("class","card_cont"),l=d.merge(a);o.each(e=>s(e,!1,!0)),d.each(e=>s(e,!0,!1)),o.each(function(e){const t=e,n=t?[t._x,t._y]:[0,0],s=i.select(this);s.transition().duration(r.transition_time).style("opacity",0).attr("transform",`translate(${n[0]}, ${n[1]})`).on("end",()=>s.remove())}),a.each(function(e){}),d.each(function(e){i.select(this).attr("transform",`translate(${e._x}, ${e._y})`).style("opacity",0),n.call(this,e)}),l.each(function(e){n.call(this,e);const s=r.initial?c(t,e,r.transition_time):0;i.select(this).transition().duration(r.transition_time).delay(s).attr("transform",`translate(${e.x}, ${e.y})`).style("opacity",1)})}(t,e,n,r),M(t,e,r);const a=r.tree_position||"fit";return r.initial?w({svg:t,svg_dim:t.getBoundingClientRect(),tree_dim:e.dim,transition_time:0}):"fit"===a?w({svg:t,svg_dim:t.getBoundingClientRect(),tree_dim:e.dim,transition_time:r.transition_time}):"main_to_middle"===a&&C({datum:e.data[0],svg:t,svg_dim:t.getBoundingClientRect(),scale:r.scale,transition_time:r.transition_time}),!0}function q(e,{d:t}){return e.updateMainId(t.data.id),e.updateTree({}),!0}function j(e,t){const n=e.rels,i=[...n.parents,...n.spouses||[],...n.children||[]].filter(e=>!!e);for(const n of i){if(!V(t.find(e=>e.id===n),t,[e.id]))return!1}return!0}function V(e,t,n=[]){const i=t[0];if(e.id===i.id)return!0;const r=[...n];let s=!1;return function e(n){if(s)return;const a=n.rels;[...a.parents,...a.spouses||[],...a.children||[]].filter(e=>!!e).forEach(n=>{if(r.includes(n))return;r.push(n);const a=t.find(e=>e.id===n);a.id===i.id?s=!0:e(a)})}(e),s}function z(e,t,n){n.forEach((t,n)=>e.data[n]=t),N(e,t),e.to_add&&delete e.to_add,e.unknown&&delete e.unknown}function N(e,t){Object.keys(e.data).forEach(n=>{if(n.includes("__ref__")){const i=n.split("__ref__")[1],r=t.find(e=>e.id===i);if(!r)return;const s=n.split("__ref__")[0]+"__ref__"+e.id;r.data[s]=e.data[n]}})}function U(e,t){Object.keys(e.data).forEach(n=>{if(n.includes("__ref__")){const i=n.split("__ref__")[1],r=t.find(e=>e.id===i);if(!r)return;const s=n.split("__ref__")[0]+"__ref__"+e.id;delete r.data[s]}})}function B(e,t){return Z(e,t,!1),!1}function Z(e,t,n=!0){return j(e,t)?(t.forEach(t=>{for(let n in t.rels){if(!t.rels.hasOwnProperty(n))continue;const i=n;Array.isArray(t.rels[i])&&t.rels[i].includes(e.id)&&t.rels[i].splice(t.rels[i].findIndex(t=>t===e.id),1)}}),U(e,t),t.splice(t.findIndex(t=>t.id===e.id),1),0===t.length&&t.push(d({data:{gender:"M"}})),n&&W(t),{success:!0}):(U(e,t),e.data={gender:e.data.gender},e.unknown=!0,{success:!0})}function J(e){return W(e),e.forEach(e=>{delete e.main,delete e._tgdp,delete e._tgdp_sp,delete e.__tgdp_sp}),e.forEach(e=>{Object.keys(e).forEach(e=>{"_"===e[0]&&console.error("key starts with _",e)})}),e}function W(e){for(let t=e.length-1;t>=0;t--)e[t].to_add&&B(e[t],e)}function G(){return`\n <g data-icon="user">\n ${Me()}\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 K(){return`\n <g data-icon="user-edit">\n ${Me()}\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 Y(){return`\n <g data-icon="user-plus">\n ${Me()}\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 Q(){return`\n <g data-icon="user-plus-close">\n ${Me()}\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 X(){return`\n <g data-icon="plus">\n ${Me()}\n <path d="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z" />\n </g>\n `}function ee(){return`\n <g data-icon="pencil">\n ${Me()}\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 te(){return`\n <g data-icon="pencil-off">\n ${Me()}\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 ne(){return`\n <g data-icon="trash">\n ${Me()}\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 ie(){return`\n <g data-icon="history-back">\n ${Me()}\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 re(){return`\n <g data-icon="history-forward">\n ${Me()}\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 se(){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 ae(){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 oe(){return`\n <g data-icon="toggle-on">\n ${Me()}\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 de(){return`\n <g data-icon="toggle-off">\n ${Me()}\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 le(){return`\n <g data-icon="chevron-down">\n ${Me()}\n <path d="M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z" />\n </g>\n `}function ce(){return`\n <g data-icon="chevron-up">\n ${Me()}\n <path d="M7.41,15.41L12,10.83L16.59,15.41L18,14L12,8L6,14L7.41,15.41Z" />\n </g>\n `}function ue(){return`\n <g data-icon="link-off">\n ${Me()}\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 he(){return`\n <g data-icon="info">\n ${Me()}\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 pe(){return Se(Y())}function fe(){return Se(Q())}function _e(){return Se(X())}function ge(){return Se(ee())}function me(){return Se(te())}function ve(){return Se(ie())}function ye(){return Se(re())}function we(){return Se('\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 be(){return Se('\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 Ce(){return Se(oe())}function xe(){return Se(de())}function $e(){return Se(le())}function ke(){return Se(ue())}function Ee(){return Se(he())}function Se(e,t="0 0 24 24"){const n=e.match(/data-icon="([^"]+)"/);return`\n <svg xmlns="http://www.w3.org/2000/svg" viewBox="${t}" style="fill: currentColor" ${n?`data-icon="${n[1]}"`:""}>\n ${e}\n </svg>\n `}function Me(){return'\n <circle r="12" cx="12" cy="12" style="fill: rgba(0,0,0,0)" />\n '}var Ie=Object.freeze({__proto__:null,chevronDownIcon:le,chevronDownSvgIcon:$e,chevronUpIcon:ce,chevronUpSvgIcon:function(){return Se(ce())},historyBackIcon:ie,historyBackSvgIcon:ve,historyForwardIcon:re,historyForwardSvgIcon:ye,infoIcon:he,infoSvgIcon:Ee,linkOffIcon:ue,linkOffSvgIcon:ke,miniTreeIcon:ae,miniTreeSvgIcon:be,pencilIcon:ee,pencilOffIcon:te,pencilOffSvgIcon:me,pencilSvgIcon:ge,personIcon:se,personSvgIcon:we,plusIcon:X,plusSvgIcon:_e,toggleIconOff:de,toggleIconOn:oe,toggleSvgIconOff:xe,toggleSvgIconOn:Ce,trashIcon:ne,trashSvgIcon:function(){return Se(ne())},userEditIcon:K,userEditSvgIcon:function(){return Se(K())},userIcon:G,userPlusCloseIcon:Q,userPlusCloseSvgIcon:fe,userPlusIcon:Y,userPlusSvgIcon:pe,userSvgIcon:function(){return Se(G())}});function Ae(e){return` \n <form id="familyForm" class="f3-form ${e.editable?"":"non-editable"}">\n ${Fe()}\n <div style="text-align: right; display: 'block'">\n ${e.no_edit?"":function(e){return`\n <span class="f3-add-relative-btn">\n ${e.addRelativeActive?fe():pe()}\n </span>\n `}(e)}\n ${e.no_edit?'<div style="height: 24px;"></div>':function(e){return`\n <span class="f3-edit-btn">\n ${e.editable?me():ge()}\n </span>\n `}(e)}\n </div>\n\n ${Re(e)}\n\n ${He(e)}\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 ${e.linkExistingRelative?De(e):""}\n\n <hr>\n ${function(e){return`\n <div>\n <button type="button" class="f3-delete-btn" ${e.can_delete?"":"disabled"}>\n Delete\n </button>\n </div>\n `}(e)}\n\n ${function(e){return`\n <div>\n <button type="button" class="f3-remove-relative-btn${e.removeRelativeActive?" active":""}">\n ${e.removeRelativeActive?"Cancel Remove Relation":"Remove Relation"}\n </button>\n </div>\n `}(e)}\n </form>\n `}function Re(e){return e.editable?`\n <div class="f3-radio-group">\n ${e.gender_field.options.map(t=>`\n <label>\n <input type="radio" name="${e.gender_field.id}" \n value="${t.value}" \n ${t.value===e.gender_field.initial_value?"checked":""}\n ${e.gender_field.disabled?"disabled":""}\n >\n ${t.label}\n </label>\n `).join("")}\n </div>\n `:""}function He(e){if(!e.editable)return function(){let t="";return e.fields.forEach(e=>{var n;if("rel_reference"===e.type){if(!e.initial_value)return;t+=`\n <div class="f3-info-field">\n <span class="f3-info-field-label">${e.label} - <i>${e.rel_label}</i></span>\n <span class="f3-info-field-value">${e.initial_value||""}</span>\n </div>`}else if("select"===e.type){const i=e;if(!e.initial_value)return;t+=`\n <div class="f3-info-field">\n <span class="f3-info-field-label">${i.label}</span>\n <span class="f3-info-field-value">${(null===(n=i.options.find(e=>e.value===i.initial_value))||void 0===n?void 0:n.label)||""}</span>\n </div>`}else t+=`\n <div class="f3-info-field">\n <span class="f3-info-field-label">${e.label}</span>\n <span class="f3-info-field-value">${e.initial_value||""}</span>\n </div>`}),t}();let t="";return e.fields.forEach(e=>{if("text"===e.type)t+=`\n <div class="f3-form-field">\n <label>${e.label}</label>\n <input type="${e.type}" \n name="${e.id}" \n value="${e.initial_value||""}"\n placeholder="${e.label}">\n </div>`;else if("textarea"===e.type)t+=`\n <div class="f3-form-field">\n <label>${e.label}</label>\n <textarea name="${e.id}" \n placeholder="${e.label}">${e.initial_value||""}</textarea>\n </div>`;else if("select"===e.type){const n=e;t+=`\n <div class="f3-form-field">\n <label>${n.label}</label>\n <select name="${n.id}" value="${n.initial_value||""}">\n <option value="">${n.placeholder||`Select ${n.label}`}</option>\n ${n.options.map(e=>`<option ${e.value===n.initial_value?"selected":""} value="${e.value}">${e.label}</option>`).join("")}\n </select>\n </div>`}else"rel_reference"===e.type&&(t+=`\n <div class="f3-form-field">\n <label>${e.label} - <i>${e.rel_label}</i></label>\n <input type="text" \n name="${e.id}" \n value="${e.initial_value||""}"\n placeholder="${e.label}">\n </div>`)}),t}function De(e){return`\n <div>\n <hr>\n <div class="f3-link-existing-relative">\n <label>${e.linkExistingRelative.hasOwnProperty("title")?e.linkExistingRelative.title:"Profile already exists?"}</label>\n <select>\n <option value="">${e.linkExistingRelative.hasOwnProperty("select_placeholder")?e.linkExistingRelative.select_placeholder:"Select profile"}</option>\n ${e.linkExistingRelative.options.map(e=>`<option value="${e.value}">${e.label}</option>`).join("")}\n </select>\n </div>\n </div>\n `}function Fe(){return'\n <span class="f3-close-btn">\n ×\n </span>\n '}function Oe(e,t){return Te(e,t)}function Le(e,t){return Te(e,t)}function Te(e,t){const n=function(e){return"new_rel"in e}(e),i=document.createElement("div");return function r(){const s=n?function(e){return` \n <form id="familyForm" class="f3-form">\n \n <span class="f3-close-btn">\n ×\n </span>\n \n <h3 class="f3-form-title">${e.title}</h3>\n ${Re(e)}\n\n ${He(e)}\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 ${e.linkExistingRelative?De(e):""}\n </form>\n `}(e):Ae(e);i.innerHTML=s,function(e,t,n,i){const r=e.querySelector("form");r.addEventListener("submit",t.onSubmit);r.querySelector(".f3-cancel-btn").addEventListener("click",s);function s(){t.editable=!1,t.onCancel&&t.onCancel(),i()}r.querySelector(".f3-close-btn").addEventListener("click",n)}(i,e,t,r),n?function(e,t){const n=e.querySelector("form"),i=n.querySelector(".f3-link-existing-relative select");i&&i.addEventListener("change",t.linkExistingRelative.onSelect)}(i,e):function(e,t,n){const i=e.querySelector("form"),r=i.querySelector(".f3-edit-btn");r&&r.addEventListener("click",l);const s=i.querySelector(".f3-delete-btn");s&&t.onDelete&&s.addEventListener("click",t.onDelete);const a=i.querySelector(".f3-add-relative-btn");a&&t.addRelative&&a.addEventListener("click",()=>{t.addRelativeActive?t.addRelativeCancel():t.addRelative(),t.addRelativeActive=!t.addRelativeActive,n()});const o=i.querySelector(".f3-remove-relative-btn");o&&t.removeRelative&&o.addEventListener("click",()=>{t.removeRelativeActive?t.removeRelativeCancel():t.removeRelative(),t.removeRelativeActive=!t.removeRelativeActive,n()});const d=i.querySelector(".f3-link-existing-relative select");d&&d.addEventListener("change",t.linkExistingRelative.onSelect);function l(){t.editable=!t.editable,n()}}(i,e,r);e.onFormCreation&&e.onFormCreation({cont:i,form_creator:e})}(),i}function Pe(e,t,n){let i=[],r=-1;return{changed:function(){r<i.length-1&&(i=i.slice(0,r+1));const n=t();n.main_id=e.getMainId(),i.push(n),r++},back:function(){if(!a())return;r--,o(i[r])},forward:function(){if(!s())return;r++,o(i[r])},canForward:s,canBack:a};function s(){return r<i.length-1}function a(){return r>0}function o(t){const i=e.getMainId();(t=JSON.parse(JSON.stringify(t))).find(e=>e.id===i)||e.updateMainId(t.main_id),e.updateData(t),n()}}function qe(e,t){const n=i.select(e).append("div").attr("class","f3-history-controls");e.insertBefore(n.node(),e.firstChild);const r=n.append("button").attr("class","f3-back-button").on("click",()=>{t.back(),a()}),s=n.append("button").attr("class","f3-forward-button").on("click",()=>{t.forward(),a()});return r.html(ve()),s.html(ye()),{back_btn:r.node(),forward_btn:s.node(),updateButtons:a,destroy:function(){i.select(e).select(".f3-history-controls").remove()}};function a(){r.classed("disabled",!t.canBack()),s.classed("disabled",!t.canForward()),t.canBack()||t.canForward()?n.style("opacity",1).style("pointer-events","auto"):n.style("opacity",0).style("pointer-events","none")}}var je=Object.freeze({__proto__:null,addNewPerson:function({data_stash:e,datum:t}){e.push(t)},calculateDelay:c,calculateTreeFit:b,cardChangeMain:q,cardComponentSetup:function(e){const t=()=>e.querySelector("#htmlSvg");return A(e,{onZoom:D(()=>e.querySelector("svg .view"),()=>e.querySelector("#htmlSvg .cards_view"))}),i.select(t()).append("div").attr("class","cards_view_fake").style("display","none"),O(t)},cardToMiddle:C,checkIfConnectedToFirstPerson:V,checkIfRelativesConnectedWithoutPerson:j,cleanupDataJson:J,createFormEdit:Le,createFormNew:Oe,createHistory:Pe,createHistoryControls:qe,createNewPerson:d,createNewPersonWithGenderFromRel:function({data:e,rel_type:t,rel_datum:n}){const i=function(e,t){return["daughter","mother"].includes(t)||"spouse"===t&&"M"===e.data.gender?"F":"M"}(n,t);return d({data:e=Object.assign(e||{},{gender:i})})},deletePerson:Z,getCurrentZoom:$,htmlContSetup:R,isAllRelativeDisplayed:l,manualZoom:x,moveToAddToAdded:function(e,t){return delete e.to_add,e},onDeleteSyncRelReference:U,removeToAdd:B,removeToAddFromData:W,setupZoom:S,submitFormData:z,syncRelReference:N,treeFit:w,zoomTo:k});function Ve({d:e,card_dim:t,card_display:n}){return{template:`\n <g class="card-body">\n <rect width="${t.w}" height="${t.h}" class="card-body-rect" />\n ${ze({d:e,card_dim:t,card_display:n}).template}\n </g>\n `}}function ze({d:e,card_dim:t,card_display:n}){return{template:`\n <g>\n <g class="card-text" clip-path="url(#card_text_clip)">\n <g transform="translate(${t.text_x}, ${t.text_y})">\n <text>\n ${Array.isArray(n)?n.map(t=>`<tspan x="0" dy="14">${t(e.data)}</tspan>`).join("\n"):n(e.data)}\n </text>\n </g>\n </g>\n <rect width="${t.w-10}" height="${t.h}" style="mask: url(#fade)" class="text-overflow-mask" /> \n </g>\n `}}function Ne({d:e,card_dim:t,is_new:n}){return{template:`\n <rect width="${t.w}" height="${t.h}" rx="4" ry="4" class="card-outline ${e.data.main&&!n?"card-main-outline":""} ${n?"card-new-outline":""}" />\n `}}function Ue(e,t,n){const i=document.createElementNS("http://www.w3.org/2000/svg","g");i.innerHTML=e,n?t.insertBefore(i,t.firstChild):t.appendChild(i)}const Be={miniTree:function(e,t){if(e.data.to_add)return;const n=t.card_dim;if(e.all_rels_displayed)return;const r=i.create("svg:g").html(function({d:e,card_dim:t}){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*t.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:e,card_dim:n}).template);return r.on("click",function(n){n.stopPropagation(),t.onMiniTreeClick?t.onMiniTreeClick.call(this,n,e):q(t.store,{d:e})}),r.node()},cardBody:function(e,t){const n=t.card_dim,r=i.create("svg:g").html(Ve({d:e,card_dim:n,card_display:t.card_display}).template);return r.on("click",function(n){n.stopPropagation(),t.onCardClick?t.onCardClick.call(this,n,e):q(t.store,{d:e})}),r.node()},cardImage:function(e,t){if(e.data.to_add)return;const n=t.card_dim;return i.create("svg:g").html(function({d:e,image:t,card_dim:n,maleIcon:i,femaleIcon:r}){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 ${t?`<image href="${t}" height="${n.img_h}" width="${n.img_w}" preserveAspectRatio="xMidYMin slice" />`:(e.data.data.gender,e.data.data.gender,`\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:e,image:e.data.data.avatar||null,card_dim:n,maleIcon:void 0,femaleIcon:void 0}).template).node()}};function Ze(e,t,n=!1){e&&(n?t.insertBefore(e,t.firstChild):t.appendChild(e))}function Je(e){const t="default"===e.style?s:"imageCircleRect"===e.style?function(t){return t.data.data[e.cardImageField]?a(t):o(t)}:"imageCircle"===e.style?a:"imageRect"===e.style?function(e){return n(e)}:"rect"===e.style?o:s;return function(n){if(this.innerHTML=`\n <div class="card ${function(e){const t=[];"M"===e.data.data.gender?t.push("card-male"):"F"===e.data.data.gender?t.push("card-female"):t.push("card-genderless");t.push(`card-depth-${e.is_ancestry?-e.depth:e.depth}`),e.data.main&&t.push("card-main");e.data._new_rel_data&&t.push("card-new-rel");e.data.to_add&&t.push("card-to-add");e.data.unknown&&t.push("card-unknown");return t}(n).join(" ")}" data-id="${n.tid}" style="transform: translate(-50%, -50%); pointer-events: auto;">\n ${e.mini_tree?function(t){return e.mini_tree?t.data.to_add||t.data._new_rel_data||t.all_rels_displayed?"":`<div class="mini-tree">${be()}</div>`:""}(n):""}\n ${e.cardInnerHtmlCreator&&!n.data._new_rel_data?e.cardInnerHtmlCreator(n):t(n)}\n </div>\n `,this.querySelector(".card").addEventListener("click",t=>e.onCardClick(t,n)),e.onCardUpdate&&e.onCardUpdate.call(this,n),e.onCardMouseenter&&i.select(this).select(".card").on("mouseenter",t=>e.onCardMouseenter(t,n)),e.onCardMouseleave&&i.select(this).select(".card").on("mouseleave",t=>e.onCardMouseleave(t,n)),n.duplicate&&function(e,t){i.select(e).on("mouseenter",n=>{i.select(e.closest(".cards_view")).selectAll(".card_cont").select(".card").classed("f3-card-duplicate-hover",e=>e.data.id===t.data.id)}),i.select(e).on("mouseleave",t=>{i.select(e.closest(".cards_view")).selectAll(".card_cont").select(".card").classed("f3-card-duplicate-hover",!1)})}(this,n),e.duplicate_branch_toggle&&function(e,t,n,r){if(!t.hasOwnProperty("_toggle"))return;const s=e.querySelector(".card"),a=s.querySelector(".card-inner"),o=e.querySelector(".card").offsetWidth;let d,l;e.querySelector(".card").offsetHeight;const c={};if(t.spouse){const e=t.spouse,i=e.data.main?"main":e.parent.data.id;if(d=e.data._tgdp_sp[i][t.data.id]<0,c.top=60,c.left=t.sx-t.x-30+o/2,n&&(c.top=t.sy-t.x+4,c.left=o/2+4,Math.abs(t.sx-t.y)<10&&(c.left=o-4)),l=e._toggle_id_sp?e._toggle_id_sp[t.data.id]:-1,-1===l)return}else{const e=t.data.main?"main":t.parent.data.id;d=t.data._tgdp[e]<0,c.top=-65,c.left=o/2-30,n&&(c.top=5,c.left=-55),l=t._toggle_id}if(a.style.zIndex=1,i.select(s).append("div").attr("class","f3-toggle-div").attr("style","cursor: pointer; width: 60px; height: 60px;position: absolute; z-index: -1;").style("top",c.top+"px").style("left",c.left+"px").on("click",e=>{if(e.stopPropagation(),t.spouse){const e=t.spouse,n=e.data.main?"main":e.parent.data.id;e.data._tgdp_sp[n].hasOwnProperty(t.data.id)||console.error("no toggle",t,e);let i=e.data._tgdp_sp[n][t.data.id];i=i<0?(new Date).getTime():-(new Date).getTime(),e.data._tgdp_sp[n][t.data.id]=i}else{const e=t.data.main?"main":t.parent.data.id;let n=t.data._tgdp[e];n=n<0?(new Date).getTime():-(new Date).getTime(),t.data._tgdp[e]=n}r()}).append("div").html(d?xe():Ce()).select("svg").classed("f3-toggle-icon",!0).style("color",d?"#585656":"#61bf52").style("padding","0"),i.select(s).select(".f3-toggle-icon .f3-small-circle").style("fill","#fff"),i.select(s).select(".f3-toggle-icon").append("text").attr("transform",d?"translate(10.6, 14.5)":"translate(4.1, 14.5)").attr("fill","#fff").attr("font-size","7px").text("C"+l),d){let e;e=t.is_ancestry?n?"translate(5, -30)rotate(-90)":"translate(0, -10)":n?"translate(11, -22)rotate(90)":"translate(-7, -32)rotate(180)",i.select(s).select(".f3-toggle-div").insert("div").html(be()).select("svg").attr("style","position: absolute; z-index: -1;top: 0;left: 0;border-radius: 0;").style("width","66px").style("height","112px").attr("transform",e).attr("viewBox","0 0 72 125").select("line").attr("y1",t.is_ancestry?"62":"92")}}(this,n,e.store.state.is_horizontal,e.store.updateTree),location.origin.includes("localhost")&&(n.__node=this.querySelector(".card"),n.__label=n.data.data["first name"],n.data.to_add)){const e=n.spouse||n.coparent||null;e&&i.select(this).select(".card").attr("data-to-add",e.data.data["first name"])}};function n(t){return`\n <div class="card-inner card-image-rect" ${d()}>\n ${t.data.data[e.cardImageField]?`<img src="${t.data.data[e.cardImageField]}" ${l()}>`:c(t)}\n <div class="card-label">${r(t)}</div>\n ${t.duplicate?u(t):""}\n </div>\n `}function r(t){return t.data._new_rel_data?function(e){const t=[];t.push(`data-rel-type="${e.data._new_rel_data.rel_type}"`),["son","daughter"].includes(e.data._new_rel_data.rel_type)&&t.push(`data-other-parent-id="${e.data._new_rel_data.other_parent_id}"`);return`<div ${t.join(" ")}>${e.data._new_rel_data.label}</div>`}(t):t.data.to_add?`<div>${e.empty_card_label||"ADD"}</div>`:t.data.unknown?`<div>${e.unknown_card_label||"UNKNOWN"}</div>`:`\n ${e.card_display.map(e=>`<div>${e(t.data)}</div>`).join("")}\n `}function s(e){return n(e)}function a(t){return function(t){return`\n <div class="card-inner card-image-circle" ${d()}>\n ${t.data.data[e.cardImageField]?`<img src="${t.data.data[e.cardImageField]}" ${l()}>`:c(t)}\n <div class="card-label">${r(t)}</div>\n ${t.duplicate?u(t):""}\n </div>\n `}(t)}function o(e){return function(e){return`\n <div class="card-inner card-rect" ${d()}>\n ${r(e)}\n ${e.duplicate?u(e):""}\n </div>\n `}(e)}function d(){let t='style="';return e.card_dim.w||e.card_dim.h?(t+=`width: ${e.card_dim.w}px; min-height: ${e.card_dim.h}px;`,e.card_dim.height_auto?t+="height: auto;":t+=`height: ${e.card_dim.h}px;`,t+='"',t):""}function l(){let t='style="position: relative;';return e.card_dim.img_w||e.card_dim.img_h||e.card_dim.img_x||e.card_dim.img_y?(t+=`width: ${e.card_dim.img_w}px; height: ${e.card_dim.img_h}px;`,t+=`left: ${e.card_dim.img_x}px; top: ${e.card_dim.img_y}px;`,t+='"',t):""}function c(t){return t.data._new_rel_data?`<div class="person-icon" ${l()}>${_e()}</div>`:`<div class="person-icon" ${l()}>${e.defaultPersonIcon?e.defaultPersonIcon(t):we()}</div>`}function u(e){return`<div class="f3-card-duplicate-tag">x${e.duplicate}</div>`}}function We(e,t){function n(e,t,n){const{w:i,h:r}=e,s=t,a=n||[],o=e=>a.includes(e);return`${o("lx")?"M0,0":`M0,${s} Q 0,0 5,0`} ${o("rx")?`H${i}`:`H${i-s} Q ${i},0 ${i},5`} ${o("ry")?`V${r}`:`V${r-s} Q ${i},${r} ${i-s},${r}`} ${o("ly")?"H0":`H${s} Q 0,${r} 0,${r-s}`} z`}e.querySelector("defs#f3CardDef")||e.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:t.w,h:t.h},5)}"></clipPath>\n <clipPath id="card_text_clip"><rect width="${t.w-10}" height="${t.h}"></rect></clipPath>\n <clipPath id="card_image_clip"><path d="M0,0 Q 0,0 0,0 H${t.img_w} V${t.img_h} H0 Q 0,${t.img_h} 0,${t.img_h} z"></clipPath>\n <clipPath id="card_image_clip_curved"><path d="${n({w:t.img_w,h:t.img_h},5,["rx","ry"])}"></clipPath>\n </defs>\n `)}function Ge(e){return We((e=function(e){const t={img:!0,mini_tree:!0,link_break:!1,card_dim:{w:220,h:70,text_x:75,text_y:15,img_w:60,img_h:60,img_x:5,img_y:5}};e||(e={});for(const n in t)void 0===e[n]&&(e[n]=t[n]);return e}(e)).svg,e.card_dim),function(t){const n="M"===t.data.data.gender?"card-male":"F"===t.data.data.gender?"card-female":"card-genderless",r=e.card_dim,s=i.create("svg:g").attr("class",`card ${n}`).attr("transform",`translate(${[-r.w/2,-r.h/2]})`);s.append("g").attr("class","card-inner").attr("clip-path","url(#card_clip)"),this.innerHTML="",this.appendChild(s.node()),s.on("click",function(n){n.stopPropagation(),e.onCardClick.call(this,n,t)}),t.data._new_rel_data?(Ue(Ne({d:t,card_dim:r,is_new:t.data.to_add}).template,s.node(),!0),Ue(function({d:e,card_dim:t,label:n}){return{template:`\n <g class="card-body">\n <rect class="card-body-rect" width="${t.w}" height="${t.h}" />\n <text transform="translate(${t.img_w+5}, ${t.h/2})">\n <tspan font-size="18" dy="8" pointer-events="none">${n}</tspan>\n </text>\n </g>\n `}}({d:t,card_dim:r,label:t.data._new_rel_data.label}).template,this.querySelector(".card-inner"),!0),i.select(this.querySelector(".card-inner")).append("g").attr("class","card-edit-icon").attr("fill","currentColor").attr("transform",`translate(-1,2)scale(${r.img_h/22})`).html(X())):(Ue(Ne({d:t,card_dim:r,is_new:t.data.to_add}).template,s.node(),!0),Ue(Ve({d:t,card_dim:r,card_display:e.card_display}).template,this.querySelector(".card-inner"),!1),e.img&&Ze(Be.cardImage(t,e),this.querySelector(".card")),e.mini_tree&&Ze(Be.miniTree(t,e),this.querySelector(".card"),!0)),e.onCardUpdate&&e.onCardUpdate.call(this,t)}}function Ke(e){return void 0===e.onCardClick&&(e.onCardClick=(t,n)=>{e.store.updateMainId(n.data.id),e.store.updateTree({})}),Ge(e)}function Ye(e,t){return new Qe(e,t)}class Qe{constructor(e,t){this.cont=e,this.active=!1,this.onClose=t,this.popup_cont=i.select(this.cont).append("div").attr("class","f3-popup").node(),this.create()}create(){const e=i.select(this.popup_cont);e.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 '),e.select(".f3-popup-close").on("click",()=>{this.close()}),e.on("click",t=>{t.target==e.node()&&this.close()})}activate(e){const t=i.select(this.popup_cont).select(".f3-popup-content-inner").node();e&&t.appendChild(e),this.open()}open(){this.active=!0}close(){this.popup_cont.remove(),this.active=!1,this.onClose&&this.onClose()}}function Xe(e,t,n){const i=t.find(t=>t.id===e),r={};return function e(n,i,s,a){if(!n)return;if(r[n])return;i&&(r[n]=i);const o=t.find(e=>e.id===n),d=o.rels;if("self"===i)d.parents.forEach(t=>e(t,"parent",s-1,n)),(d.spouses||[]).forEach(t=>e(t,"spouse",s)),(d.children||[]).forEach(t=>e(t,"child",s+1));else if("parent"===i)d.parents.forEach(t=>e(t,"grandparent",s-1,n)),(d.children||[]).forEach(t=>{a&&a===t||e(t,"sibling",s+1)});else if("spouse"===i);else if("child"===i)(d.children||[]).forEach(t=>e(t,"grandchild",s+1));else if("sibling"===i)(d.children||[]).forEach(t=>e(t,"nephew",s+1));else if("grandparent"===i)a||console.error(`${i} should have prev_rel_id`),d.parents.forEach(t=>e(t,"great-grandparent",s-1,n)),(d.children||[]).forEach(t=>{a&&a===t||e(t,"uncle",s+1)});else if(i.includes("grandchild"))(d.children||[]).forEach(t=>e(t,it(i,s+1),s+1));else if(i.includes("great-grandparent"))a||console.error(`${i} should have prev_rel_id`),d.parents.forEach(t=>e(t,it(i,s-1),s-1,n)),(d.children||[]).forEach(t=>{if(a&&a===t)return;const n=nt(s+1);0===n?e(t,"granduncle",s+1):n>0?e(t,it("granduncle",s+1),s+1):console.error(`${i} should have great_count > -1`)});else if("nephew"===i)(d.children||[]).forEach(t=>e(t,"grandnephew",s+1));else if(i.includes("grandnephew"))(d.children||[]).forEach(t=>e(t,it(i,s+1),s+1));else if("uncle"===i)(d.children||[]).forEach(t=>e(t,"1st Cousin",s+1));else if("granduncle"===i)(d.children||[]).forEach(t=>e(t,"1st Cousin 1x removed",s+1));else if(i.includes("great-granduncle")){const t=s+1,n=Math.abs(t);(d.children||[]).forEach(i=>e(i,`1st Cousin ${n}x removed`,t))}else i.slice(4).startsWith("Cousin")?(d.children||[]).forEach(t=>{const n=s+1,r=Math.abs(n),a=+i[0];0===n?e(t,`${tt(a+1)} Cousin`,n):n<0?e(t,`${tt(a+1)} Cousin ${r}x removed`,n):n>0&&e(t,`${tt(a)} Cousin ${r}x removed`,n)}):console.error(`${i} not found`)}(i.id,"self",0),function(e){const n=[];Object.keys(e).forEach(r=>{const s=e[r];if(s.includes("child"))return;if("spouse"===s)return;const a=et(i.id,r,t);if(!a)return console.error(`${t.find(e=>e.id===r).data} not found in main_ancestry`);a.is_half_kin&&n.push(r)}),n.forEach(t=>{e[t]=`Half ${e[t]}`})}(r),n.show_in_law&&function(e,t){Object.keys(e).forEach(n=>{const i=e[n],r=t.find(e=>e.id===n);if("spouse"===i){const t=[];r.rels.parents.forEach(e=>(s(e).rels.children||[]).forEach(e=>t.push(e))),t.forEach(t=>{e[t]||(e[t]="sibling-in-law")})}"sibling"===i&&(r.rels.spouses||[]).forEach(t=>{e[t]||(e[t]="sibling-in-law")}),"child"===i&&(r.rels.spouses||[]).forEach(t=>{e[t]||(e[t]="child-in-law")}),"uncle"===i&&(r.rels.spouses||[]).forEach(t=>{e[t]||(e[t]="uncle-in-law")}),i.includes("Cousin")&&(r.rels.spouses||[]).forEach(t=>{e[t]||(e[t]=`${i} in-law`)})})}(r,t),function(e){Object.keys(e).forEach(n=>{const i=e[n],r=t.find(e=>e.id===n).data.gender;if(i.includes("parent")){const t="M"===r?"father":"F"===r?"mother":"parent";e[n]=e[n].replace("parent",t)}else if(i.includes("sibling")){const t="M"===r?"brother":"F"===r?"sister":"sibling";e[n]=e[n].replace("sibling",t)}else if(i.includes("child")){const t="M"===r?"son":"F"===r?"daughter":"child";e[n]=e[n].replace("child",t)}else if(i.includes("uncle")){const t="M"===r?"uncle":"F"===r?"aunt":"aunt/uncle";e[n]=e[n].replace("uncle",t)}else if(i.includes("nephew")){const t="M"===r?"nephew":"F"===r?"niece":"neice/nephew";e[n]=e[n].replace("nephew",t)}})}(r),r;function s(e){return t.find(t=>t.id===e)}}function et(e,t,n){const i=function(e){const t=[];return function e(i){const r=n.find(e=>e.id===i),s=r.rels;t.push(o(s)),s.parents.forEach(t=>e(t))}(e),t}(e);let r,s,a;return function(e){const t=n.find(t=>t.id===e);i.find(e=>e[0]===t.id||e[1]===t.id)&&(s=!0,r=e,a=!1)}(t),function(t){(n.find(t=>t.id===e).rels.spouses||[]).includes(t)&&(r=[e,t])}(t),function t(d){if(r)return;if(d===e)return s=!0,r=d,void(a=!1);const l=n.find(e=>e.id===d),c=l.rels,u=o(c),h=i.find(e=>e[0]&&u[0]&&e[0]===u[0]||e[1]&&u[1]&&e[1]===u[1]);if(h)return r=u.filter((e,t)=>e===h[t]),f=h,void(a=(p=u).some((e,t)=>e!==f[t])||f.some((e,t)=>e!==p[t]));var p,f;c.parents.forEach(e=>t(e))}(t),r?{found:r,is_ancestor:s,is_half_kin:a}:null;function o(e){return e.parents}}function tt(e){const t=["st","nd","rd"];return t[e-1]?e+t[e-1]:e+"th"}function nt(e){return Math.abs(e)-2}function it(e,t){const n=nt(t);return e.includes("great-")&&(e=e.split("great-")[1]),1===n?`great-${e}`:n>1?`${n}x-great-${e}`:(console.error(`${e} should have great_count > 1`),e)}function rt(e,t,n,r){var s;let a;const o=r[t].toLowerCase();if(o.includes("in-law")){a=t;const i=n.find(e=>e.id===a);t=o.includes("sister")||o.includes("brother")?e:null===(s=i.rels.spouses)||void 0===s?void 0:s.find(e=>r[e]&&!r[e].includes("in-law"))}const d=et(e,t,n);if(!d)return console.error(`${t} not found in main_ancestry`);const l=d.is_ancestor?d.found:d.found[0],c=n.find(e=>e.id===l),u=i.hierarchy(c,function(e){return[...e.rels.children||[]].map(e=>n.find(t=>t.id===e)).filter(e=>e)}),h=u.descendants().map(e=>e.data.id),p=g(e,h),f=g(t,h);!function e(t){t.children=(t.children||[]).filter(e=>!!p.includes(e.data.id)||!!f.includes(e.data.id)),t.children.forEach(t=>e(t)),0===t.children.length&&delete t.children}(u);const _=u.descendants().map(e=>{const t={id:e.data.id,data:JSON.parse(JSON.stringify(e.data.data)),kinship:r[e.data.id],rels:{parents:[],spouses:[],children:[]}};return e.children&&e.children.length>0&&(t.rels.children=e.children.map(e=>e.data.id)),t});return _.length>0&&!d.is_ancestor&&!d.is_half_kin&&function(e){const i=e[0];if(!d)return console.error(`${t} not found in main_ancestry`);const s=l===d.found[0]?d.found[1]:d.found[0];i.rels.spouses=[s];const a=n.find(e=>e.id===s),o={id:a.id,data:JSON.parse(JSON.stringify(a.data)),kinship:r[a.id],rels:{spouses:[i.id],children:i.rels.children,parents:[]}};e.push(o),(i.rels.children||[]).forEach(t=>{const i=n.find(e=>e.id===t);e.find(e=>e.id===t).rels.parents=[...i.rels.parents]})}(_),a&&function(e){o.includes("sister")||o.includes("brother")?function(e){var n;const i=e.find(e=>e.id===t),s=m(a);e.push({id:a,data:JSON.parse(JSON.stringify(s.data)),kinship:r[a],rels:{spouses:[],children:[],parents:[]}});const o=[];s.rels.parents.forEach(e=>(m(e).rels.children||[]).forEach(e=>o.push(e)));const d=null===(n=m(t).rels.spouses)||void 0===n?void 0:n.find(e=>o.includes(e));i.rels.spouses=[d];const l=m(d),c={id:l.id,data:JSON.parse(JSON.stringify(l.data)),kinship:r[l.id],rels:{spouses:[i.id],children:[],parents:[]}};e.push(c),s.rels.parents.forEach(t=>{const n=m(t),i="M"===n.data.gender?"Father-in-law":"F"===n.data.gender?"Mother-in-law":"Parent-in-law",r={id:n.id,data:JSON.parse(JSON.stringify(n.data)),kinship:i,rels:{spouses:[],children:[d,a],parents:[]}},o=s.rels.parents.find(e=>e!=e);o&&r.rels.parents.push(o),e.unshift(r)})}(e):function(e){const i=e.find(e=>e.id===t),s=a;i.rels.spouses=[s];const o=n.find(e=>e.id===s),d={id:o.id,data:JSON.parse(JSON.stringify(o.data)),kinship:r[o.id],rels:{spouses:[i.id],children:[],parents:[]}};e.push(d)}(e)}(_),_;function g(e,t){const i=[e];return function e(r){const s=n.find(e=>e.id===r);s.rels.parents.forEach(n=>{t.includes(n)&&(i.push(n),e(n))})}(e),i}function m(e){return n.find(t=>t.id===e)}}function st(e,t,n){const i=e.id;n.forEach(e=>{e.rels.parents.includes(i)&&(e.rels.parents[e.rels.parents.indexOf(i)]=t),e.rels.spouses&&e.rels.spouses.includes(i)&&(e.rels.spouses=e.rels.spouses.filter(e=>e!==i),e.rels.spouses.includes(t)||e.rels.spouses.push(t)),e.rels.children&&e.rels.children.includes(i)&&(e.rels.children=e.rels.children.filter(e=>e!==i),e.rels.children.includes(t)||e.rels.children.push(t))});const r=n.find(e=>e.id===t),s=n.find(e=>e.id===i);if(!s)throw new Error("New rel not found");if(!r)throw new Error("Link rel not found");if((s.rels.children||[]).forEach(e=>{r.rels.children||(r.rels.children=[]),r.rels.children.includes(e)||r.rels.children.push(e)}),(s.rels.spouses||[]).forEach(e=>{r.rels.spouses||(r.rels.spouses=[]),r.rels.spouses.includes(e)||r.rels.spouses.push(e)}),0===r.rels.parents.length)r.rels.parents=[...s.rels.parents];else{const e=r.rels.parents.find(e=>{var t;return"M"===(null===(t=n.find(t=>t.id===e))||void 0===t?void 0:t.data.gender)}),t=r.rels.parents.find(e=>{var t;return"F"===(null===(t=n.find(t=>t.id===e))||void 0===t?void 0:t.data.gender)}),i=s.rels.parents.find(e=>{var t;return"M"===(null===(t=n.find(t=>t.id===e))||void 0===t?void 0:t.data.gender)}),a=s.rels.parents.find(e=>{var t;return"F"===(null===(t=n.find(t=>t.id===e))||void 0===t?void 0:t.data.gender)});i&&(e?(console.error("link rel already has father"),r.rels.parents[r.rels.parents.indexOf(e)]=i):r.rels.parents.push(i)),a&&(t?(console.error("link rel already has mother"),r.rels.parents[r.rels.parents.indexOf(t)]=a):r.rels.parents.push(a))}n.splice(n.findIndex(e=>e.id===i),1)}function at(e,t){const n=e._new_rel_data?t.find(t=>t.id===e._new_rel_data.rel_id):null,i=function(e,t){const n=[];return i(e),n;function i(e){e.rels.parents.forEach(e=>{if(e){n.push(e);const r=t.find(t=>t.id===e);if(!r)throw new Error("Parent not found");i(r)}})}}(e,t),r=s(e,t);if(e._new_rel_data&&["son","daughter"].includes(e._new_rel_data.rel_type)){if(!n)throw new Error("Rel datum not found");r.push(...s(n,t))}return t.filter(t=>t.id!==e.id&&t.id!==(null==n?void 0:n.id)&&!t._new_rel_data&&!t.to_add&&!t.unknown).filter(e=>!i.includes(e.id)).filter(e=>!r.includes(e.id)).filter(t=>!(t.rels.spouses||[]).includes(e.id));function s(e,t){const n=[];return function e(i){(i.rels.children?[...i.rels.children]:[]).forEach(i=>{n.push(i);const r=t.find(e=>e.id===i);if(!r)throw new Error("Child not found");e(r)})}(e),n}}function ot({datum:e,store:t,fields:n,postSubmitHandler:i,addRelative:r,removeRelative:s,deletePerson:a,onCancel:o,editFirst:d,link_existing_rel_config:l,onFormCreation:c,no_edit:u,onSubmit:h,onDelete:p,canEdit:f,canDelete:_}){let g=!_||_(e);let m;!f||f(e)||(u=!0,g=!1);const v={datum_id:e.id,fields:[],onSubmit:function(n){h?h(n,e,r,()=>i({})):(n.preventDefault(),r(),i({}));function r(){const i=new FormData(n.target);z(e,t.getData(),i)}},onCancel:o,onFormCreation:c,no_edit:u,gender_field:{id:"gender",type:"switch",label:"Gender",initial_value:e.data.gender,disabled:!1,options:[{value:"M",label:"Male"},{value:"F",label:"Female"}]}};if(e._new_rel_data)m=Object.assign(Object.assign({},v),{title:e._new_rel_data.label,new_rel:!0,editable:!0});else{if(!r)throw new Error("addRelative is required");if(!s)throw new Error("removeRelative is required");m=Object.assign(Object.assign({},v),{onDelete:function(){p?p(e,()=>a(),()=>i({delete:!0})):(a(),i({delete:!0}))},addRelative:()=>r.activate(e),addRelativeCancel:()=>r.onCancel(),addRelativeActive:r.is_active,removeRelative:()=>s.activate(e),removeRelativeCancel:()=>s.onCancel(),removeRelativeActive:s.is_active,editable:!1,can_delete:g})}return(e._new_rel_data||e.to_add||e.unknown)&&l&&(m.linkExistingRelative=function(e,t,n){if(!n)throw new Error("link_existing_rel_config is required");const i={title:n.title,select_placeholder:n.select_placeholder,options:at(e,t).map(e=>({value:e.id,label:n.linkRelLabel(e)})).sort((e,t)=>"string"==typeof e.label&&"string"==typeof t.label?e.label.localeCompare(t.label):e.label<t.label?-1:1),onSelect:y};return i}(e,t.getData(),l)),u?m.editable=!1:d&&(m.editable=!0),n.forEach(n=>{"rel_reference"===n.type?function(n){n.getRelLabel||console.error("getRelLabel is not set");"spouse"===n.rel_type&&(e.rels.spouses||[]).forEach(i=>{const r=t.getDatum(i);if(!r)throw new Error("Spouse not found");const s=`${n.id}__ref__${i}`,a={id:s,type:"rel_reference",label:n.label,rel_id:i,rel_label:n.getRelLabel(r),initial_value:e.data[s],rel_type:n.rel_type};m.fields.push(a)})}(n):"select"===n.type?function(t){if(!t.options&&!t.optionCreator)return console.error("optionCreator or options is not set for field",t);const n={id:t.id,type:t.type,label:t.label,initial_value:e.data[t.id],placeholder:t.placeholder,options:t.options||t.optionCreator(e)};m.fields.push(n)}(n):m.fields.push({id:n.id,type:n.type,label:n.label,initial_value:e.data[n.id]})}),m;function y(e){const t=e.target.value;i({link_rel_id:t})}}class dt{constructor(e,t,n){return this.store=e,this.onActivate=t,this.cancelCallback=n,this.datum=null,this.onChange=null,this.onCancel=null,this.is_active=!1,this.addRelLabels=this.addRelLabelsDefault(),this}activate(e){this.is_active&&this.onCancel(),this.onActivate(),this.is_active=!0,this.store.state.one_level_rels=!0;const t=this.store;this.datum=e;let n=this.datum.data.gender;!function(e,t,n,i){let r={parent:!0,spouse:!0,child:!0};i&&(r=Object.assign(r,i(e))),e.rels.spouses||(e.rels.spouses=[]),e.rels.children||(e.rels.children=[]),r.parent&&function(){const i=e.rels.parents,r=i.find(e=>{var n;return"M"===(null===(n=t.find(t=>t.id===e))||void 0===n?void 0:n.data.gender)}),s=i.find(e=>{var n;return"F"===(null===(n=t.find(t=>t.id===e))||void 0===n?void 0:n.data.gender)});if(i.length<2&&!r){const i=d({data:{gender:"M"},rels:{children:[e.id]}});i._new_rel_data={rel_type:"father",label:n.father,rel_id:e.id},e.rels.parents.push(i.id),t.push(i)}if(i.length<2&&!s){const i=d({data:{gender:"F"},rels:{children:[e.id]}});i._new_rel_data={rel_type:"mother",label:n.mother,rel_id:e.id},e.rels.parents.push(i.id),t.push(i)}const a=t.find(t=>t.id===e.rels.parents[0]),o=t.find(t=>t.id===e.rels.parents[1]);a.rels.spouses||(a.rels.spouses=[]),o.rels.spouses||(o.rels.spouses=[]),a.rels.spouses.includes(o.id)||a.rels.spouses.push(o.id),o.rels.spouses.includes(a.id)||o.rels.spouses.push(a.id),a.rels.children||(a.rels.children=[]),o.rels.children||(o.rels.children=[]),a.rels.children.includes(e.id)||a.rels.children.push(e.id),o.rels.children.includes(e.id)||o.rels.children.push(e.id)}(),r.spouse&&(function(){if(e.rels.spouses||(e.rels.spouses=[]),e.rels.children){let i;e.rels.children.forEach(r=>{const s=t.find(e=>e.id===r);if(1===s.rels.parents.length){const r="M"===t.find(e=>e.id===s.rels.parents[0]).data.gender?"F":"M";i||(i=d({data:{gender:r},rels:{spouses:[e.id]}})),i._new_rel_data={rel_type:"spouse",label:n.spouse,rel_id:e.id},i.rels.children.push(s.id),e.rels.spouses.push(i.id),s.rels.parents.push(i.id),t.push(i)}})}}(),function(){e.rels.spouses||(e.rels.spouses=[]);const i=d({data:{gender:"M"===e.data.gender?"F":"M"},rels:{spouses:[e.id]}});i._new_rel_data={rel_type:"spouse",label:n.spouse,rel_id:e.id},e.rels.spouses.push(i.id),t.push(i)}()),r.child&&(e.rels.children||(e.rels.children=[]),e.rels.spouses||(e.rels.spouses=[]),e.rels.spouses.forEach(i=>{const r=t.find(e=>e.id===i);r.rels.children||(r.rels.children=[]);const s=d({data:{gender:"M"},rels:{parents:[e.id,r.id]}});s._new_rel_data={rel_type:"son",label:n.son,other_parent_id:r.id,rel_id:e.id},r.rels.children.push(s.id),e.rels.children.push(s.id),t.push(s);const a=d({data:{gender:"F"},rels:{parents:[e.id,r.id]}});a._new_rel_data={rel_type:"daughter",label:n.daughter,other_parent_id:r.id,rel_id:e.id},r.rels.children.push(a.id),e.rels.children.push(a.id),t.push(a)}))}(e,this.getStoreData(),this.addRelLabels,this.canAdd),t.updateTree({}),this.onChange=function(i,r){(null==i?void 0:i._new_rel_data)?(null==r?void 0:r.link_rel_id)?st(i,r.link_rel_id,t.getData()):delete i._new_rel_data:i.id===e.id?i.data.gender!==n&&(n=i.data.gender,t.getData().forEach(e=>{const t=e._new_rel_data;t&&"spouse"===t.rel_type&&(e.data.gender="M"===e.data.gender?"F":"M")})):console.error("Something went wrong")},this.onCancel=()=>function(e){if(!e.is_active)return;e.is_active=!1,e.store.state.one_level_rels=!1,e.cleanUp(),e.cancelCallback(e.datum),e.datum=null,e.onChange=null,e.onCancel=null}(this)}setAddRelLabels(e){if("object"==typeof e){for(const t in e){const n=t;this.addRelLabels[n]=e[n]}return this}console.error("add_rel_labels must be an object")}setCanAdd(e){return this.canAdd=e,this}addRelLabelsDefault(){return{father:"Add Father",mother:"Add Mother",spouse:"Add Spouse",son:"Add Son",daughter:"Add Daughter"}}getStoreData(){return this.store.getData()}cleanUp(e){return e||(e=this.store.getData()),function(e){for(let t=e.length-1;t>=0;t--){const n=e[t];n._new_rel_data&&(e.forEach(e=>{e.rels.parents.includes(n.id)&&e.rels.parents.splice(e.rels.parents.indexOf(n.id),1),e.rels.children&&e.rels.children.includes(n.id)&&e.rels.children.splice(e.rels.children.indexOf(n.id),1),e.rels.spouses&&e.rels.spouses.includes(n.id)&&e.rels.spouses.splice(e.rels.spouses.indexOf(n.id),1)}),e.splice(t,1))}}(e),e}}class lt{constructor(e,t,n,i){return this.store=e,this.onActivate=t,this.cancelCallback=n,this.modal=i,this.datum=null,this.onChange=null,this.onCancel=null,this.is_active=!1,this}activate(e){this.is_active&&this.onCancel(),this.onActivate(),this.is_active=!0,this.store.state.one_level_rels=!0;const t=this.store;t.updateTree({}),this.datum=e,this.onChange=function(n,r){const s=function(t){if(t.is_ancestry){if(e.rels.parents.includes(t.data.id))return"parent"}else if(t.spouse){if(!e.rels.spouses)throw new Error("Spouses not found");if(e.rels.spouses.includes(t.data.id))return"spouse"}else{if(!e.rels.children)throw new Error("Children not found");if(e.rels.children.includes(t.data.id))return"children"}return null}(n),a=e.rels;"parent"===s?function(){const i=n.data.id,s=t.getDatum(i);if(!s)throw new Error("Parent not found");if(!s.rels.children)throw new Error("Parent has no children");s.rels.children=s.rels.children.filter(t=>t!==e.id),a.parents=a.parents.filter(e=>e!==i),r()}.call(this):"spouse"===s?function(){const s=n.data;o()?d.call(this):l.call(this,!0);function o(){return(s.rels.children||[]).some(e=>{const n=t.getDatum(e);if(!n)throw new Error("Child not found");return!!n.rels.parents.includes(s.id)})}function d(){const t="M"===e.data.gender?"f3-male-bg":"F"===e.data.gender?"f3-female-bg":null,n="M"===s.data.gender?"f3-male-bg":"F"===s.data.gender?"f3-female-bg":null,r=i.create("div").html(`\n <p>You are removing a spouse relationship. Since there are shared children, please choose which parent should keep them in the family tree.</p>\n <div class="f3-modal-options">\n <button data-option="assign-to-current" class="f3-btn ${t}">Keep children with current person</button>\n <button data-option="assign-to-spouse" class="f3-btn ${n}">Keep children with spouse</button>\n </div>\n `);r.selectAll('[data-option="assign-to-current"]').on("click",()=>{l(!0),this.modal.close()}),r.selectAll('[data-option="assign-to-spouse"]').on("click",()=>{l(!1),this.modal.close()}),this.modal.activate(r.node())}function l(i){n.data.rels.spouses=n.data.rels.spouses.filter(t=>t!==e.id),a.spouses=a.spouses.filter(e=>e!==n.data.id);const s=i?e:n.data,o=i?n.data:e;(a.children||[]).forEach(e=>{const n=t.getDatum(e);if(!n)throw new Error("Child not found");n.rels.parents.includes(o.id)&&(n.rels.parents=n.rels.parents.filter(e=>e!==o.id))}),o.rels.children&&(o.rels.children=o.rels.children.filter(e=>!(s.rels.children||[]).includes(e))),r()}}.call(this):"children"===s&&function(){if(!a.children)throw new Error("Children not found");a.children=a.children.filter(e=>e!==n.data.id),n.data.rels.parents=n.data.rels.parents.filter(t=>t!==e.id),r()}.call(this)}.bind(this),this.onCancel=function(){if(!this.is_active)return;if(this.is_active=!1,this.store.state.one_level_rels=!1,!this.datum)throw new Error("Datum not found");this.cancelCallback(this.datum),this.datum=null,this.onChange=null,this.onCancel=null}.bind(this)}}class ct{constructor(e){this.cont=e,this.active=!1,this.onClose=null,this.modal_cont=i.select(this.cont).append("div").attr("class","f3-modal").node(),i.select(this.modal_cont).style("display","none"),this.create()}create(){const e=i.select(this.modal_cont);e.html('\n <div class="f3-modal-content">\n <span class="f3-modal-close">&times;</span>\n <div class="f3-modal-content-inner"></div>\n <div class="f3-modal-content-bottom"></div>\n </div>\n '),e.select(".f3-modal-close").on("click",()=>{this.close()}),e.on("click",t=>{t.target==e.node()&&this.close()})}activate(e,{boolean:t,onAccept:n,onCancel:r}={}){this.reset();const s=i.select(this.modal_cont).select(".f3-modal-content-inner").node();if("string"==typeof e?s.innerHTML=e:s.appendChild(e),t){if(!n)throw new Error("onAccept is required");if(!r)throw new Error("onCancel is required");i.select(this.modal_cont).select(".f3-modal-content-bottom").html('\n <button class="f3-modal-accept f3-btn">Accept</button>\n <button class="f3-modal-cancel f3-btn">Cancel</button>\n '),i.select(this.modal_cont).select(".f3-modal-accept").on("click",()=>{n(),this.reset(),this.close()}),i.select(this.modal_cont).select(".f3-modal-cancel").on("click",()=>{this.close()}),this.onClose=r}this.open()}reset(){this.onClose=null,i.select(this.modal_cont).select(".f3-modal-content-inner").html(""),i.select(this.modal_cont).select(".f3-modal-content-bottom").html("")}open(){this.modal_cont.style.display="block",this.active=!0}close(){this.modal_cont.style.display="none",this.active=!1,this.onClose&&this.onClose()}}class ut{constructor(e,t){return this.cont=e,this.store=t,this.fields=[{type:"text",label:"first name",id:"first name"},{type:"text",label:"last name",id:"last name"},{type:"text",label:"birthday",id:"birthday"},{type:"text",label:"avatar",id:"avatar"}],this.is_fixed=!0,this.no_edit=!1,this.onChange=null,this.editFirst=!1,this.postSubmit=null,this.onFormCreation=null,this.createFormEdit=null,this.createFormNew=null,this.formCont=this.getFormContDefault(),this.modal=this.setupModal(),this.addRelativeInstance=this.setupAddRelative(),this.removeRelativeInstance=this.setupRemoveRelative(),this.history=this.createHistory(),this}open(e){e.rels||(e=e.data),this.addRelativeInstance.is_active?function(t){e._new_rel_data?t.cardEditForm(e):(t.addRelativeInstance.onCancel(),t.cardEditForm(e),t.store.updateMainId(e.id),t.store.updateTree({}))}(this):this.removeRelativeInstance.is_active?function(t,n){if(!n)throw new Error("Tree datum not found");if(!t.removeRelativeInstance.datum)throw new Error("Remove relative datum not found");if(!t.removeRelativeInstance.onCancel)throw new Error("Remove relative onCancel not found");if(!t.removeRelativeInstance.onChange)throw new Error("Remove relative onChange not found");if(e.id===t.removeRelativeInstance.datum.id)t.removeRelativeInstance.onCancel(),t.cardEditForm(e);else{function i(){t.removeRelativeInstance.onCancel(),t.updateHistory(),t.store.updateTree({})}t.removeRelativeInstance.onChange(n,i.bind(t))}}(this,this.store.getTreeDatum(e.id)):this.cardEditForm(e)}setupAddRelative(){return((e,t,n)=>new dt(e,t,n))(this.store,()=>function(e){e.removeRelativeInstance.is_active&&e.removeRelativeInstance.onCancel()}(this),e=>function(e,t){e.store.updateMainId(t.id),e.store.updateTree({}),e.openFormWithId(t.id)}(this,e))}setupRemoveRelative(){return((e,t,n,i)=>new lt(e,t,n,i))(this.store,function(){this.addRelativeInstance.is_active&&this.addRelativeInstance.onCancel();e(this.cont,!0)}.bind(this),function(t){e(this.cont,!1),this.store.updateMainId(t.id),this.store.updateTree({}),this.openFormWithId(t.id)}.bind(this),this.modal);function e(e,t){i.select(e).select("#f3Canvas").classed("f3-remove-relative-active",t)}}createHistory(){const e=Pe(this.store,this._getStoreDataCopy.bind(this),function(){var e;console.log("historyUpdateTree"),this.addRelativeInstance.is_active&&this.addRelativeInstance.onCancel();this.removeRelativeInstance.is_active&&this.removeRelativeInstance.onCancel();this.store.updateTree({initial:!1}),this.history.controls.updateButtons(),this.openFormWithId(null===(e=this.store.getMainDatum())||void 0===e?void 0:e.id),this.onChange&&this.onChange()}.bind(this)),t=this.cont.querySelector(".f3-nav-cont");if(!t)throw new Error("Nav cont not found");const n=qe(t,e);return e.changed(),n.updateButtons(),Object.assign(Object.assign({},e),{controls:n})}openWithoutRelCancel(e){this.cardEditForm(e)}getFormContDefault(){let e=i.select(this.cont).select("div.f3-form-cont").node();return e||(e=i.select(this.cont).append("div").classed("f3-form-cont",!0).node()),{el:e,populate(t){e.innerHTML="",e.appendChild(t)},open(){i.select(e).classed("opened",!0)},close(){i.select(e).classed("opened",!1).html("")}}}setFormCont(e){return this.formCont=e,this}cardEditForm(e){const t={},n=null==e?void 0:e._new_rel_data;n?t.onCancel=()=>this.addRelativeInstance.onCancel():(t.addRelative=this.addRelativeInstance,t.removeRelative=this.removeRelativeInstance,t.deletePerson=()=>{Z(e,this.store.getData()),this.openFormWithId(this.store.getLastAvailableMainDatum().id),this.store.updateTree({})});const i=ot(Object.assign({store:this.store,datum:e,postSubmitHandler:t=>function(t,n){if(t.addRelativeInstance.is_active){t.addRelativeInstance.onChange(e,n),t.postSubmit&&t.postSubmit(e,t.store.getData());const i=t.addRelativeInstance.datum;if(!i)throw new Error("Active datum not found");t.store.updateMainId(i.id),t.openWithoutRelCancel(i)}else(e.to_add||e.unknown)&&(null==n?void 0:n.link_rel_id)?(st(e,n.link_rel_id,t.store.getData()),t.store.updateMainId(n.link_rel_id),t.openFormWithId(n.link_rel_id)):(null==n?void 0:n.delete)||(t.postSubmit&&t.postSubmit(e,t.store.getData()),t.openFormWithId(e.id));t.is_fixed||t.closeForm();t.store.updateTree({}),t.updateHistory()}(this,t),fields:this.fields,onCancel:()=>{},editFirst:this.editFirst,no_edit:this.no_edit,link_existing_rel_config:this.link_existing_rel_config,onFormCreation:this.onFormCreation,onSubmit:this.onSubmit,onDelete:this.onDelete,canEdit:this.canEdit,canDelete:this.canDelete},t)),r=n?(this.createFormNew||Oe)(i,this.closeForm.bind(this)):(this.createFormEdit||Le)(i,this.closeForm.bind(this));this.formCont.populate(r),this.openForm()}openForm(){this.formCont.open()}closeForm(){this.formCont.close(),this.store.updateTree({})}fixed(){return this.is_fixed=!0,this.formCont.el&&i.select(this.formCont.el).style("position","relative"),this}absolute(){return this.is_fixed=!1,this.formCont.el&&i.select(this.formCont.el).style("position","absolute"),this}setCardClickOpen(e){return e.setOnCardClick((t,n)=>{this.isAddingRelative()||this.isRemovingRelative()?this.open(n.data):(this.open(n.data),e.onCardClickDefault(t,n))}),this}openFormWithId(e){if(e){const t=this.store.getDatum(e);if(!t)throw new Error("Datum not found");this.openWithoutRelCancel(t)}else{const e=this.store.getMainDatum();if(!e)throw new Error("Main datum not found");this.openWithoutRelCancel(e)}}setNoEdit(){return this.no_edit=!0,this}setEdit(){return this.no_edit=!1,this}setFields(e){const t=[];if(!Array.isArray(e))return console.error("fields must be an array"),this;for(const n of e)"string"==typeof n?t.push({type:"text",label:n,id:n}):"object"==typeof n?n.id?t.push(n):console.error("fields must be an array of objects with id property"):console.error("fields must be an array of strings or objects");return this.fields=t,this}setOnChange(e){return this.onChange=e,this}setCanEdit(e){return this.canEdit=e,this}setCanDelete(e){return this.canDelete=e,this}setCanAdd(e){return this.addRelativeInstance.setCanAdd(e),this}addRelative(e){return e||(e=this.store.getMainDatum()),this.addRelativeInstance.activate(e),this}setupModal(){return e=this.cont,new ct(e);var e}setEditFirst(e){return this.editFirst=e,this}isAddingRelative(){return this.addRelativeInstance.is_active}isRemovingRelative(){return this.removeRelativeInstance.is_active}setAddRelLabels(e){return this.addRelativeInstance.setAddRelLabels(e),this}setLinkExistingRelConfig(e){return this.link_existing_rel_config=e,this}setOnFormCreation(e){return this.onFormCreation=e,this}setCreateFormEdit(e){return this.createFormEdit=e,this}setCreateFormNew(e){return this.createFormNew=e,this}_getStoreDataCopy(){let e=JSON.parse(JSON.stringify(this.store.getData()));return this.addRelativeInstance.is_active&&(e=this.addRelativeInstance.cleanUp(e)),e=J(e),e}getStoreDataCopy(){return this.exportData()}exportData(){let e=this._getStoreDataCopy();return e=f(e,this.store.state.legacy_format),e}getDataJson(){return JSON.stringify(this.exportData(),null,2)}updateHistory(){this.history&&(this.history.changed(),this.history.controls.updateButtons()),this.onChange&&this.onChange()}setPostSubmit(e){return this.postSubmit=e,this}setOnSubmit(e){return this.onSubmit=e,this}setOnDelete(e){return this.onDelete=e,this}destroy(){return this.history.controls.destroy(),this.history=null,this.formCont.el&&i.select(this.formCont.el).remove(),this.addRelativeInstance.onCancel&&this.addRelativeInstance.onCancel(),this.store.updateTree({}),this}}class ht{constructor(e,t,n={}){this.cont=e,this.options=[],this.onSelect=t,this.config=n,this.autocomplete_cont=i.select(this.cont).append("div").attr("class","f3-autocomplete-cont").node(),this.create()}create(){var e;const t=this;i.select(this.autocomplete_cont).html(`\n <div class="f3-autocomplete">\n <div class="f3-autocomplete-input-cont">\n <input type="text" placeholder="${(null===(e=this.config)||void 0===e?void 0:e.placeholder)||"Search"}">\n <span class="f3-autocomplete-toggle">${$e()}</span>\n </div>\n <div class="f3-autocomplete-items" tabindex="0"></div>\n </div>\n `);const n=i.select(this.autocomplete_cont).select(".f3-autocomplete"),r=n.select("input"),s=n.select(".f3-autocomplete-items");function a(){n.classed("active",!0);const e=r.property("value"),i=t.options.filter(t=>t.label.toLowerCase().includes(e.toLowerCase()));i.forEach(function(t){const n=t.label.toLowerCase().indexOf(e.toLowerCase());t.label_html=-1!==n?t.label.substring(0,n)+"<strong>"+t.label.substring(n,n+e.length)+"</strong>"+t.label.substring(n+e.length):t.label}),i.sort(function(e,t){return e.label<t.label?-1:e.label>t.label?1:0}),d(i)}function o(){n.classed("active",!1),d([])}function d(e){s.selectAll("div.f3-autocomplete-item").data(e,e=>null==e?void 0:e.value).join("div").attr("class","f3-autocomplete-item").on("click",(e,n)=>{t.onSelect(n.value)}).html(e=>e.optionHtml?e.optionHtml(e):function(e){return`<div class="${e.class?e.class:""}">${e.label_html}</div>`}(e))}n.on("focusout",()=>{setTimeout(()=>{n.node().contains(document.activeElement)||o()},200)}),r.on("focus",()=>{t.options=t.getOptions(),a()}).on("input",a).on("keydown",function(e){const n=s.selectAll("div.f3-autocomplete-item").nodes(),r=n.findIndex(e=>i.select(e).classed("f3-selected"));if("ArrowDown"===e.key){e.preventDefault();a(n,r<n.length-1?r+1:0)}else if("ArrowUp"===e.key){e.preventDefault();a(n,r>0?r-1:n.length-1)}else if("Enter"===e.key&&-1!==r){e.preventDefault();const s=i.select(n[r]).datum();s&&t.onSelect(s.value)}function a(e,t){e.forEach(e=>i.select(e).classed("f3-selected",!1)),e[t]&&(i.select(e[t]).classed("f3-selected",!0),e[t].scrollIntoView({block:"nearest"}))}}),s.on("wheel",e=>e.stopPropagation()),n.select(".f3-autocomplete-toggle").on("click",e=>{e.stopPropagation();const t=n.classed("active");if(n.classed("active",!t),t)o();else{r.node().focus(),a()}})}setOptionsGetter(e){return this.getOptions=e,this}setOptionsGetterPerson(e,t){return this.getOptions=()=>{const i=[];return e().forEach(e=>{e.to_add||e.unknown||e._new_rel_data||i.find(t=>t.value===e.id)||i.push({label:t(e),value:e.id,optionHtml:n(e)})}),i},this;function n(t){const n=!V(t,e());return e=>`\n <div>\n <span style="float: left; width: 10px; height: 10px; margin-right: 10px;" class="f3-${function(e){return"M"===e.data.gender?"male":"F"===e.data.gender?"female":"genderless"}(t)}-color">${we()}</span>\n <span>${e.label_html}</span>\n ${n?`<span style="float: right; width: 10px; height: 10px; margin-left: 5px;" title="This profile is not connected to the main profile">${ke()}</span>`:""}\n </div>\n `}}destroy(){this.autocomplete_cont.remove()}}function pt(e){const t=[];return Array.isArray(e)?e.forEach(e=>{"function"==typeof e?t.push(e):"string"==typeof e?t.push(t=>t.data[e]):Array.isArray(e)&&t.push(t=>e.map(e=>t.data[e]).join(" "))}):"function"==typeof e?t.push(e):"string"==typeof e&&t.push(t=>t.data[e]),t}function ft(e,t){return new _t(e,t)}let _t=class{constructor(e,t){return this.cont=e,this.svg=this.cont.querySelector("svg.main_svg"),this.store=t,this.card_display=[e=>`${e.data["first name"]} ${e.data["last name"]}`],this.cardImageField="avatar",this.onCardClick=this.onCardClickDefault,this.style="default",this.mini_tree=!1,this.card_dim={},this}getCard(){return Je({store:this.store,card_display:this.card_display,cardImageField:this.cardImageField,defaultPersonIcon:this.defaultPersonIcon,onCardClick:this.onCardClick,style:this.style,mini_tree:this.mini_tree,onCardUpdate:this.onCardUpdate,card_dim:this.card_dim,empty_card_label:this.store.state.single_parent_empty_card_label||"",unknown_card_label:this.store.state.unknown_card_label||"",cardInnerHtmlCreator:this.cardInnerHtmlCreator,duplicate_branch_toggle:this.store.state.duplicate_branch_toggle,onCardMouseenter:this.onCardMouseenter?this.onCardMouseenter.bind(this):void 0,onCardMouseleave:this.onCardMouseleave?this.onCardMouseleave.bind(this):void 0})}setCardDisplay(e){return this.card_display=pt(e),this}setCardImageField(e){return this.cardImageField=e,this}setDefaultPersonIcon(e){return this.defaultPersonIcon=e,this}setOnCardClick(e){return this.onCardClick=e,this}onCardClickDefault(e,t){this.store.updateMainId(t.data.id),this.store.updateTree({})}setStyle(e){return this.style=e,this}setMiniTree(e){return this.mini_tree=e,this}setOnCardUpdate(e){return this.onCardUpdate=e,this}setCardDim(e){if("object"!=typeof e)return console.error("card_dim must be an object"),this;for(let t in e){const n=e[t];if("number"!=typeof n&&"boolean"!=typeof n)return console.error(`card_dim.${t} must be a number or boolean`),this;"width"===t&&(t="w"),"height"===t&&(t="h"),"img_width"===t&&(t="img_w"),"img_height"===t&&(t="img_h"),"img_x"===t&&(t="img_x"),"img_y"===t&&(t="img_y"),this.card_dim[t]=n}return this}resetCardDim(){return this.card_dim={},this}setCardInnerHtmlCreator(e){return this.cardInnerHtmlCreator=e,this}setOnHoverPathToMain(){return this.onCardMouseenter=this.onEnterPathToMain.bind(this),this.onCardMouseleave=this.onLeavePathToMain.bind(this),this}unsetOnHoverPathToMain(){return this.onCardMouseenter=void 0,this.onCardMouseleave=void 0,this}onEnterPathToMain(e,t){this.to_transition=t.data.id;const n=this.store.getTreeMainDatum(),r=i.select(this.cont).select("div.cards_view").selectAll(".card_cont"),s=i.select(this.cont).select("svg.main_svg .links_view").selectAll(".link"),{cards_node_to_main:a,links_node_to_main:o}=function(e,t,n,i){const r=n.is_ancestry,s=t.data();let a=[],o=[];if(r){const r=[];let c=n,u=0;for(;c!==i&&u<100;){u++;const e=s.find(e=>!0===e.spouse&&(e.source===c||e.target===c));if(e){const t=l(s.filter(t=>Array.isArray(t.target)&&t.target.includes(e.source)&&t.target.includes(e.target)),i);if(!t)break;r.push(e),r.push(t),c=t.source}else{const e=l(s.filter(e=>Array.isArray(e.target)&&e.target.includes(c)),i);if(!e)break;r.push(e),c=e.source}}t.each(function(e){r.includes(e)&&a.push({link:e,node:this})});const h=d(n,r);e.each(function(e){h.includes(e)&&o.push({card:e,node:this})})}else if(n.spouse&&n.spouse.data===i.data){t.each(function(e){e.target===n&&a.push({link:e,node:this})});const r=[i,n];e.each(function(e){r.includes(e)&&o.push({card:e,node:this})})}else if(n.sibling){t.each(function(e){if(!Array.isArray(n.parents))throw new Error("datum.parents is not an array");e.source===n&&a.push({link:e,node:this}),e.source===i&&Array.isArray(e.target)&&2===e.target.length&&a.push({link:e,node:this}),n.parents.includes(e.source)&&!Array.isArray(e.target)&&n.parents.includes(e.target)&&a.push({link:e,node:this})});const r=[i,n,...n.parents||[]];e.each(function(e){r.includes(e)&&o.push({card:e,node:this})})}else{let r=[],l=n,c=0;for(;l!==i&&c<100;){c++;const e=s.find(e=>e.target===l&&Array.isArray(e.source));if(e){const t=s.find(t=>{return!0===t.spouse&&(n=[t.source,t.target],i=e.source,n.every(e=>i.some(t=>e===t)));var n,i});r.push(e),r.push(t),l=t?t.source:e.source[0]}else{const e=s.find(e=>e.target===l&&!Array.isArray(e.source));if(!e)break;r.push(e),l=e.source}}t.each(function(e){r.includes(e)&&a.push({link:e,node:this})});const u=d(i,r);e.each(function(e){u.includes(e)&&o.push({card:e,node:this})})}return{cards_node_to_main:o,links_node_to_main:a};function d(e,t){const r=t.filter(e=>e).reduce((e,t)=>(Array.isArray(t.target)?e.push(...t.target):e.push(t.target),Array.isArray(t.source)?e.push(...t.source):e.push(t.source),e),[]),s=[i,n];return function e(t){t.data.rels.children&&t.data.rels.children.forEach(t=>{const n=r.find(e=>e.data.id===t);n&&(s.push(n),e(n))})}(e),s}function l(e,t){return 0===e.length?null:1===e.length?e[0]:e.find(e=>e.source===t)}}(r,s,t,n);return a.forEach(e=>{const n=200*Math.abs(t.depth-e.card.depth);i.select(e.node.querySelector("div.card-inner")).transition().duration(0).delay(n).on("end",()=>this.to_transition===t.data.id&&i.select(e.node.querySelector("div.card-inner")).classed("f3-path-to-main",!0))}),o.forEach(e=>{const n=200*Math.abs(t.depth-e.link.depth);i.select(e.node).transition().duration(0).delay(n).on("end",()=>this.to_transition===t.data.id&&i.select(e.node).classed("f3-path-to-main",!0))}),this}onLeavePathToMain(e,t){return this.to_transition=!1,i.select(this.cont).select("div.cards_view").selectAll("div.card-inner").classed("f3-path-to-main",!1),i.select(this.cont).select("svg.main_svg .links_view").selectAll(".link").classed("f3-path-to-main",!1),this}};function gt(e,t){return new mt(e,t)}let mt=class{constructor(e,t){return this.cont=e,this.store=t,this.svg=this.cont.querySelector("svg.main_svg"),this.card_dim={w:220,h:70,text_x:75,text_y:15,img_w:60,img_h:60,img_x:5,img_y:5},this.card_display=[],this.mini_tree=!0,this.link_break=!1,this.onCardClick=this.onCardClickDefault.bind(this),this}getCard(){return Ge({store:this.store,svg:this.svg,card_dim:this.card_dim,card_display:this.card_display,mini_tree:this.mini_tree,link_break:this.link_break,onCardClick:this.onCardClick,onCardUpdate:this.onCardUpdate})}setCardDisplay(e){return this.card_display=pt(e),this}setCardDim(e){if("object"!=typeof e)return console.error("card_dim must be an object"),this;for(let t in e){const n=e[t];if("number"!=typeof n&&"boolean"!=typeof n)return console.error(`card_dim.${t} must be a number or boolean`),this;"width"===t&&(t="w"),"height"===t&&(t="h"),"img_width"===t&&(t="img_w"),"img_height"===t&&(t="img_h"),"img_x"===t&&(t="img_x"),"img_y"===t&&(t="img_y"),this.card_dim[t]=n}return function(e,t){e.querySelector("defs#f3CardDef")&&e.querySelector("defs#f3CardDef").remove(),We(e,t)}(this.svg,this.card_dim),this}setOnCardUpdate(e){return this.onCardUpdate=e,this}setMiniTree(e){return this.mini_tree=e,this}setLinkBreak(e){return this.link_break=e,this}onCardClickDefault(e,t){this.store.updateMainId(t.data.id),this.store.updateTree({})}setOnCardClick(e){return this.onCardClick=e,this}};function vt(e,t){return new yt(e,t)}class yt{constructor(e,t){this.getCard=null,this.transition_time=2e3,this.linkSpouseText=null,this.personSearch=null,this.is_card_html=!1,this.beforeUpdate=null,this.afterUpdate=null,this.cont=function(e){"string"==typeof e&&(e=document.querySelector(e));if(!e)throw new Error("cont not found");return e}(e);const{svg:n}=R(this.cont);this.svg=n,function(e){i.select(e).append("div").attr("class","f3-nav-cont")}(this.cont);const r=t&&t.length>0?t[0].id:"";return this.store=this.createStore(t,r),this.setOnUpdate(),this.editTreeInstance=null,this}createStore(e,t){return v({data:e,main_id:t,node_separation:250,level_separation:150,single_parent_empty_card:!0,is_horizontal:!1})}setOnUpdate(){this.store.setOnUpdate(e=>{this.beforeUpdate&&this.beforeUpdate(e),e=Object.assign({transition_time:this.store.state.transition_time},e||{}),this.is_card_html&&(e=Object.assign({},e||{},{cardHtml:!0})),P(this.store.getTree(),this.svg,this.getCard(),e||{}),this.linkSpouseText&&function(e,t,n){const r=[];t.data.forEach(e=>{e.coparent&&"F"===e.data.data.gender&&r.push({nodes:[e,e.coparent],id:`${e.data.id}--${e.coparent.data.id}`}),e.spouses&&e.spouses.forEach(t=>r.push({nodes:[t,e],id:`${t.data.id}--${e.data.id}`}))});const s=i.select(e).select(".links_view").selectAll("g.link-text").data(r,e=>e.id),a=s.exit(),o=s.enter().append("g").attr("class","link-text"),d=o.merge(s),l=(e,t)=>e.spouse&&"F"===e.data.data.gender?e.x-n.node_separation/2:t.spouse&&"M"===t.data.data.gender?t.x+n.node_separation/2:Math.min(e.x,t.x)+n.node_separation/2;a.each(function(e){const t=i.select(this);t.transition("text").duration(100).style("opacity",0).on("end",()=>t.remove())}),o.each(function(e){const[t,n]=e.nodes,r=i.select(this);r.attr("transform",`translate(${l(t,n)}, ${t.y-3})`).style("opacity",0),r.append("text").style("font-size","12px").style("fill","#fff").style("text-anchor","middle")}),d.each(function(e){const[r,s]=e.nodes,a=i.select(this),o=n.initial?c(t,r,n.transition_time):0;a.select("text").text(n.linkSpouseText(r,s)),a.transition("text").duration(n.transition_time).delay(o).attr("transform",`translate(${l(r,s)}, ${r.y-3})`),a.transition("text-op").duration(100).delay(o+n.transition_time).style("opacity",1)})}(this.svg,this.store.getTree(),Object.assign({},e||{},{linkSpouseText:this.linkSpouseText,node_separation:this.store.state.node_separation})),this.afterUpdate&&this.afterUpdate(e)})}updateTree(e={initial:!1}){return this.store.updateTree(e),this}updateData(e){return this.store.updateData(e),this}setCardYSpacing(e){return"number"!=typeof e?(console.error("card_y_spacing must be a number"),this):(this.store.state.level_separation=e,this)}setCardXSpacing(e){return"number"!=typeof e?(console.error("card_x_spacing must be a number"),this):(this.store.state.node_separation=e,this)}setOrientationVertical(){return this.store.state.is_horizontal=!1,this}setOrientationHorizontal(){return this.store.state.is_horizontal=!0,this}setShowSiblingsOfMain(e){return this.store.state.show_siblings_of_main=e,this}setModifyTreeHierarchy(e){return this.store.state.modifyTreeHierarchy=e,this}setPrivateCardsConfig(e){return this.store.state.private_cards_config=e,this}setLinkSpouseText(e){return this.linkSpouseText=e,this}setSingleParentEmptyCard(e,{label:t="Unknown"}={}){return this.store.state.single_parent_empty_card=e,this.store.state.single_parent_empty_card_label=t,this.editTreeInstance&&this.editTreeInstance.addRelativeInstance.is_active&&this.editTreeInstance.addRelativeInstance.onCancel(),W(this.store.getData()||[]),this}setCard(e){if(e===ft)return this.setCardHtml();if(e===gt)return this.setCardSvg();throw new Error("Card must be an instance of cardHtml or cardSvg")}setCardHtml(){const e=this.cont.querySelector("#htmlSvg");if(!e)throw new Error("htmlSvg not found");this.is_card_html=!0,this.svg.querySelector(".cards_view").innerHTML="",e.style.display="block";const t=ft(this.cont,this.store);return this.getCard=()=>t.getCard(),t}setCardSvg(){const e=this.cont.querySelector("#htmlSvg");if(!e)throw new Error("htmlSvg not found");this.is_card_html=!1,this.svg.querySelector(".cards_view").innerHTML="",e.style.display="none";const t=gt(this.cont,this.store);return this.getCard=()=>t.getCard(),t}setTransitionTime(e){return this.store.state.transition_time=e,this}setSortChildrenFunction(e){return this.store.state.sortChildrenFunction=e,this}setSortSpousesFunction(e){return this.store.state.sortSpousesFunction=e,this}setAncestryDepth(e){return this.store.state.ancestry_depth=e,this}setProgenyDepth(e){return this.store.state.progeny_depth=e,this}getMaxDepth(e){return o(e,this.store.getData())}calculateKinships(e,t={}){return Xe(e,this.store.getData(),t)}getKinshipsDataStash(e,t){return rt(e,t,this.store.getData(),this.calculateKinships(e))}setDuplicateBranchToggle(e){return this.store.state.duplicate_branch_toggle=e,this}editTree(){return this.editTreeInstance=(e=this.cont,t=this.store,new ut(e,t));var e,t}updateMain(e){let t;return t=e.id?e.id:e.data.id,this.store.updateMainId(t),this.store.updateTree({}),this}updateMainId(e){return this.store.updateMainId(e),this}getMainDatum(){return this.store.getMainDatum()}setBeforeUpdate(e){return this.beforeUpdate=e,this}setAfterUpdate(e){return this.afterUpdate=e,this}setPersonDropdown(e,{cont:t=this.cont.querySelector(".f3-nav-cont"),onSelect:n,placeholder:i="Search"}={}){return n||(n=function(e){const t=this.store.getDatum(e);if(!t)throw new Error("Datum not found");this.editTreeInstance&&this.editTreeInstance.open(t);this.updateMainId(e),this.updateTree({initial:!1})}.bind(this)),this.personSearch=function(e,t,n={}){return new ht(e,t,n)}(t,n,{placeholder:i}),this.personSearch.setOptionsGetterPerson(this.store.getData,e),this}unSetPersonSearch(){return this.personSearch.destroy(),this.personSearch=null,this}}function wt(e){return(e=e[0].toUpperCase()+e.slice(1)).includes("great-")&&(e=e.replace("great-","Great-")),e}var bt=Object.freeze({__proto__:null,Card:Ke,CardHtml:Je,CardSvg:Ge,appendElement:Ze,infoPopup:Ye,kinshipInfo:function(e,t,n){const{self_id:r,getLabel:s,title:a}=e,o=Xe(r,n,e),d=o[t];if(!d)return;let l=d;l="self"===d?"You":wt(l);const c=`\n <div class="f3-kinship-info">\n <div class="f3-info-field">\n <span class="f3-info-field-label">${a}</span>\n <span class="f3-info-field-value">\n <span>${l}</span>\n <span class="f3-kinship-info-icon">${Ee()}</span>\n </span>\n </div>\n </div>\n `,u=i.create("div").html(c).select("div").node();let h=null;return i.select(u).select(".f3-kinship-info-icon").on("click",e=>function(e,a){const d=250,l=400;let c=e.clientX-d-10,u=e.clientY-l-10;c+d>window.innerWidth&&(c=window.innerWidth-d-10);u<0&&(u=10);if(h&&h.active)return h.close(),void(h=null);h=Ye(a),i.select(h.popup_cont).style("width",`${d}px`).style("height",`${l}px`).style("left",`${c}px`).style("top",`${u}px`);const p=h.popup_cont.querySelector(".f3-popup-content-inner");h.activate(),function(e,t,n,r,s,a){i.select(s).select("#SmallChart").node()||i.select(s).append("div").attr("id","SmallChart").attr("class","f3");const o=i.select("#SmallChart");o.selectAll("*").remove();const d=rt(e,t,n,r);let l=!0;const c=o.append("div");function u(e){const n=vt("#SmallChart",e).setTransitionTime(500).setCardXSpacing(170).setCardYSpacing(70).setSingleParentEmptyCard(!1);function r(e){let n="self"===e.data.kinship?"You":e.data.kinship;return n=wt(n),l||(n=a(e.data)),`\n <div class="card-inner card-rect ${i()}">\n <div class="card-label">${n}</div>\n </div>\n `;function i(){return"self"===e.data.kinship?"card-kinship-self"+(l?"":" f3-real-label"):e.data.id===t?"card-kinship-rel":"card-kinship-default"}}function s(){c.classed("f3-kinship-labels-toggle",!0),c.append("label").text("Kinship labels").append("input").attr("type","checkbox").attr("checked",!0).on("change",e=>{l=!l,n.updateTree({initial:!1,tree_position:"inherit"})})}function o(e){const t=n.cont.querySelector("svg.main_svg");$(t).k>e&&k(t,e)}n.setCardHtml().setStyle("rect").setCardInnerHtmlCreator(e=>r(e)).setOnCardUpdate(function(e){i.select(this).select(".card").classed("card-main",!1)}).onCardClick=(e,t)=>{},n.updateTree({initial:!0}),setTimeout(()=>o(.65),100),s()}u(d)}(r,t,n,o,p,s)}(e,u)),u}});const Ct=gt,xt=ft,$t=Object.assign({},F,{setupHtmlSvg:function(e){i.select(e()).append("div").attr("class","cards_view_fake").style("display","none")},setupReactiveTreeData:T,getUniqueId:function(e){return e.unique_id}});var kt=Object.freeze({__proto__:null,CalculateTree:g,Card:Ke,CardHtml:xt,CardHtmlClass:_t,CardSvg:Ct,CardSvgClass:mt,calculateTree:m,cardHtml:ft,cardSvg:gt,createChart:vt,createStore:v,createSvg:A,elements:bt,formatData:p,formatDataForExport:f,handlers:je,htmlHandlers:$t,icons:Ie,view:P});e.CalculateTree=g,e.Card=Ke,e.CardHtml=xt,e.CardHtmlClass=_t,e.CardSvg=Ct,e.CardSvgClass=mt,e.calculateTree=m,e.cardHtml=ft,e.cardSvg=gt,e.createChart=vt,e.createStore=v,e.createSvg=A,e.default=kt,e.elements=bt,e.formatData=p,e.formatDataForExport=f,e.handlers=je,e.htmlHandlers=$t,e.icons=Ie,e.view=P,Object.defineProperty(e,"__esModule",{value:!0})});