UNPKG

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.29 kB
var k=(e,t)=>()=>(e&&(t=e(e=0)),t);function q(e){return e!=null&&$.includes(e)}function b(e){return q(e)?e:"en"}var $,y=k(()=>{$=["en","fr","de","nl","es","zh","it","pt","pl","ar","he"]});function J(){let e=globalThis;return e[R]??(e[R]=new Map),e[R]}function U(e){let t=J().get(e);if(!t)throw new g(e);return t}var R,g,x=k(()=>{y();R="__GEDCOM_TS_BOOKLET_LOCALE_CACHE__";g=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 v(e){let t=b(e);return U(t).messages}var H=k(()=>{y();x();x()});var Y=k(()=>{});H();Y();function p(e,t,C){let s=C-t;return s<=0?.5:Math.min(1,Math.max(0,(e-t)/s))}var j="#19196f",Z="#4a4a9e",I="#b8b8cc",O="#1a1a28",h="#6a6a7a",oo="#e8e8f0",D=920,a=148,eo=28,_=56,to=48,M=22,w=36;function lo(e){switch(e){case"birth":return"#2d8a4e";case"death":return"#8a2d3d";case"marriage":return"#c47a20"}}function ao(e,t=!1){return _+w+e*M+to+36+(t?12:0)}async function Co(e,t,C){let s=v(C),B=s.timeline,c=D-a-eo,P=Math.max(e.rows.length,1),S=ao(P,!!t),T=document.createElement("canvas");T.width=D,T.height=S;let o=T.getContext("2d");if(!o)throw new Error("Canvas 2D indisponible pour la frise chronologique.");o.fillStyle="#ffffff",o.fillRect(0,0,D,S),o.fillStyle=j,o.font="bold 15px Helvetica, Arial, sans-serif",o.fillText(s.timelineTitle(e.chapterTitle),20,24),t&&(o.fillStyle=h,o.font="11px Helvetica, Arial, sans-serif",o.fillText(t,20,42));let f=_+(t?12:0),u=f+w,{yearMin:m,yearMax:A}=e;o.strokeStyle=oo,o.lineWidth=1;for(let l of e.tickYears){let r=a+p(l,m,A)*c;o.beginPath(),o.moveTo(r,u-4),o.lineTo(r,u+P*M),o.stroke(),o.fillStyle=h,o.font="10px Helvetica, Arial, sans-serif",o.textAlign="center",o.fillText(String(l),r,f+14)}o.textAlign="left",o.strokeStyle=O,o.lineWidth=1.5,o.beginPath(),o.moveTo(a,u-2),o.lineTo(a+c,u-2),o.stroke(),e.rows.forEach((l,r)=>{let n=u+r*M+M/2;if(o.fillStyle=O,o.font="11px Helvetica, Arial, sans-serif",o.textAlign="right",o.fillText(l.shortName,a-10,n+4),o.textAlign="left",!l.hasLifeSpan){o.fillStyle=h,o.font="10px Helvetica, Arial, sans-serif",o.fillText(s.timelineUnknownDates,a+4,n+4);return}let X=l.birthYear??l.deathYear??m,K=l.deathYear??l.birthYear??A,F=a+p(X,m,A)*c,V=a+p(K,m,A)*c,z=Math.max(4,V-F),G=l.birthYear==null||l.deathYear==null;o.fillStyle=G?I:Z,G&&o.setLineDash([4,3]),o.fillRect(F,n-5,z,10),o.setLineDash([]);for(let E of l.markers){let L=a+p(E.year,m,A)*c;o.fillStyle=lo(E.kind),o.beginPath(),E.kind==="marriage"?(o.moveTo(L,n-7),o.lineTo(L+5,n),o.lineTo(L,n+7),o.lineTo(L-5,n)):o.arc(L,n,E.kind==="birth"?4:3.5,0,Math.PI*2),o.fill()}});let N=S-28,W=[["\u25CF",B.legendBirth],["\u25CF",B.legendDeath],["\u25C6",B.legendMarriage]],i=20;o.font="10px Helvetica, Arial, sans-serif";for(let[l,r]of W)o.fillStyle=O,o.fillText(`${l} ${r}`,i,N),i+=88;o.fillStyle=h,o.fillText(`${e.yearMin} \u2013 ${e.yearMax}`,i+8,N),e.overflowCount>0&&(o.fillStyle=h,o.font="italic 10px Helvetica, Arial, sans-serif",o.fillText(B.overflow(e.overflowCount),20,N-14));let d=await new Promise(l=>{T.toBlob(l,"image/png")});if(!d)throw new Error("Export PNG de la frise chronologique impossible.");return new Uint8Array(await d.arrayBuffer())}export{Co as rasterizeGenerationTimelinePng};