gedcom-ts
Version:
TypeScript GEDCOM toolkit for browser apps: import .ged/.zip, edit typed genealogy data, and export GEDCOM or GEDZIP.
2 lines (1 loc) • 3.8 kB
JavaScript
var b=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var R=(e,t)=>()=>(e&&(t=e(e=0)),t);var j=(e,t)=>{for(var s in t)b(e,s,{get:t[s],enumerable:!0})},Z=(e,t,s,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of J(t))!Q.call(e,a)&&a!==s&&b(e,a,{get:()=>t[a],enumerable:!(n=q(t,a))||n.enumerable});return e};var I=e=>Z(b({},"__esModule",{value:!0}),e);function eo(e){return e!=null&&oo.includes(e)}function y(e){return eo(e)?e:"en"}var oo,g=R(()=>{oo=["en","fr","de","nl","es","zh","it","pt","pl","ar","he"]});function to(){let e=globalThis;return e[M]??(e[M]=new Map),e[M]}function v(e){let t=to().get(e);if(!t)throw new x(e);return t}var M,x,O=R(()=>{g();M="__GEDCOM_TS_BOOKLET_LOCALE_CACHE__";x=class extends Error{constructor(t){super(`Booklet locale "${t}" is not loaded. Call await ensureBookletLocale("${t}") before using sync booklet APIs.`),this.name="BookletLocaleNotLoadedError"}}});function H(e){let t=y(e);return v(t).messages}var Y=R(()=>{g();O();O()});var _=R(()=>{});var po={};j(po,{rasterizeGenerationTimelinePng:()=>Lo});module.exports=I(po);Y();_();function B(e,t,s){let n=s-t;return n<=0?.5:Math.min(1,Math.max(0,(e-t)/n))}var ao="#19196f",no="#4a4a9e",ro="#b8b8cc",D="#1a1a28",T="#6a6a7a",so="#e8e8f0",P=920,r=148,co=28,w=56,uo=48,C=22,W=36;function mo(e){switch(e){case"birth":return"#2d8a4e";case"death":return"#8a2d3d";case"marriage":return"#c47a20"}}function Ao(e,t=!1){return w+W+e*C+uo+36+(t?12:0)}async function Lo(e,t,s){let n=H(s),a=n.timeline,m=P-r-co,f=Math.max(e.rows.length,1),S=Ao(f,!!t),E=document.createElement("canvas");E.width=P,E.height=S;let o=E.getContext("2d");if(!o)throw new Error("Canvas 2D indisponible pour la frise chronologique.");o.fillStyle="#ffffff",o.fillRect(0,0,P,S),o.fillStyle=ao,o.font="bold 15px Helvetica, Arial, sans-serif",o.fillText(n.timelineTitle(e.chapterTitle),20,24),t&&(o.fillStyle=T,o.font="11px Helvetica, Arial, sans-serif",o.fillText(t,20,42));let d=w+(t?12:0),A=d+W,{yearMin:L,yearMax:p}=e;o.strokeStyle=so,o.lineWidth=1;for(let l of e.tickYears){let u=r+B(l,L,p)*m;o.beginPath(),o.moveTo(u,A-4),o.lineTo(u,A+f*C),o.stroke(),o.fillStyle=T,o.font="10px Helvetica, Arial, sans-serif",o.textAlign="center",o.fillText(String(l),u,d+14)}o.textAlign="left",o.strokeStyle=D,o.lineWidth=1.5,o.beginPath(),o.moveTo(r,A-2),o.lineTo(r+m,A-2),o.stroke(),e.rows.forEach((l,u)=>{let c=A+u*C+C/2;if(o.fillStyle=D,o.font="11px Helvetica, Arial, sans-serif",o.textAlign="right",o.fillText(l.shortName,r-10,c+4),o.textAlign="left",!l.hasLifeSpan){o.fillStyle=T,o.font="10px Helvetica, Arial, sans-serif",o.fillText(n.timelineUnknownDates,r+4,c+4);return}let K=l.birthYear??l.deathYear??L,V=l.deathYear??l.birthYear??p,G=r+B(K,L,p)*m,z=r+B(V,L,p)*m,$=Math.max(4,z-G),U=l.birthYear==null||l.deathYear==null;o.fillStyle=U?ro:no,U&&o.setLineDash([4,3]),o.fillRect(G,c-5,$,10),o.setLineDash([]);for(let k of l.markers){let h=r+B(k.year,L,p)*m;o.fillStyle=mo(k.kind),o.beginPath(),k.kind==="marriage"?(o.moveTo(h,c-7),o.lineTo(h+5,c),o.lineTo(h,c+7),o.lineTo(h-5,c)):o.arc(h,c,k.kind==="birth"?4:3.5,0,Math.PI*2),o.fill()}});let N=S-28,X=[["\u25CF",a.legendBirth],["\u25CF",a.legendDeath],["\u25C6",a.legendMarriage]],i=20;o.font="10px Helvetica, Arial, sans-serif";for(let[l,u]of X)o.fillStyle=D,o.fillText(`${l} ${u}`,i,N),i+=88;o.fillStyle=T,o.fillText(`${e.yearMin} \u2013 ${e.yearMax}`,i+8,N),e.overflowCount>0&&(o.fillStyle=T,o.font="italic 10px Helvetica, Arial, sans-serif",o.fillText(a.overflow(e.overflowCount),20,N-14));let F=await new Promise(l=>{E.toBlob(l,"image/png")});if(!F)throw new Error("Export PNG de la frise chronologique impossible.");return new Uint8Array(await F.arrayBuffer())}0&&(module.exports={rasterizeGenerationTimelinePng});