chrono-phylo-tree
Version:
A React-based phylogenetic tree visualization library
16 lines (15 loc) • 36.2 kB
JavaScript
(function(R,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],o):(R=typeof globalThis<"u"?globalThis:R||self,o(R["chrono-phylo-tree"]={},R["react/jsx-runtime"],R.React))})(this,function(R,o,M){"use strict";var Wt=Object.defineProperty;var Kt=(R,o,M)=>o in R?Wt(R,o,{enumerable:!0,configurable:!0,writable:!0,value:M}):R[o]=M;var ct=(R,o,M)=>Kt(R,typeof o!="symbol"?o+"":o,M);const Tt=(i,...n)=>i.sort((h,s)=>{for(const u of n){const[f,c]=[h,s].map(b=>u(b));if(f!==c)return f-c}return 0});class pt{constructor({id:n,name:h="",apparition:s=0,duration:u=0,ancestor:f,descendants:c=[],description:b,image:y}){ct(this,"id");ct(this,"name","");ct(this,"apparition",0);ct(this,"duration",0);ct(this,"ancestor");ct(this,"descendants",[]);ct(this,"description");ct(this,"display",!0);ct(this,"image");if(u<=0)throw new Error("The duration of the species must be greater than 0");this.id=n,this.name=h,this.apparition=s,this.duration=u,this.ancestor=f,this.descendants=c,this.description=b===""?void 0:b,this.image=y===""?void 0:y}onPosition(n=!0){return n&&this.firstAncestor().stepsUntil(this)%2===0}copy(){const n=this.firstAncestor(),h=n.allDescendants(!1).indexOf(this);return pt.fromJSON(n.toJSON()).allDescendants(!1)[h]}unlinkAncestor(){if(!this.ancestor)return;this.ancestor.descendants=this.ancestor.descendants.filter(h=>h!==this);const n=this.ancestor;return this.ancestor=void 0,[n.firstAncestor(),this]}unlinkDescendant(n){if(this.descendants.includes(n))return this.descendants=this.descendants.filter(h=>h!==n),n.ancestor=void 0,[this.firstAncestor(),n]}linkAncestor(n){if(!(this.ancestor===n&&n.descendants.includes(this))){if(n.apparition>this.apparition)throw new Error(`The ancestor's apparition (${n.apparition}) must be before or equal the descendant's apparition (${this.apparition})`);if(n.extinction()<this.apparition)throw new Error(`The ancestor's extinction (${n.extinction()}) must be after or equal the descendant's apparition (${this.apparition})`);this.ancestor!==n&&this.unlinkAncestor(),this.ancestor=n,n.descendants.push(this)}}linkDescendant(n){if(!(n.ancestor===this&&this.descendants.includes(n))){if(n.apparition<this.apparition)throw new Error(`The descendant's apparition (${n.apparition}) must be after or equal the ancestor's apparition (${this.apparition})`);if(n.extinction()>this.extinction())throw new Error(`The descendant's extinction (${n.extinction()}) must be before or equal the ancestor's extinction (${this.extinction()})`);this.descendants.includes(n)||(n.ancestor&&n.unlinkAncestor(),this.descendants.push(n),n.ancestor=this)}}linkDescendants(n){for(const h of n)try{this.linkDescendant(h)}catch(s){console.error(`Error linking descendant ${h.name} to ancestor ${this.name}:`,s)}}addDescendant({id:n,name:h="",afterApparition:s=0,duration:u=0,description:f,image:c,copy:b=!1}){if(s<0||s>this.duration)throw new Error(`The apparition of the descendant must be between the apparition (${this.apparition}) and the extinction (${this.extinction()}) of the ancestor`);const y=b?this.copy():this,a=new pt({id:n,name:h,apparition:y.apparition+Math.max(s,0),duration:Math.max(u,0),description:f,image:c});return a.linkAncestor(y),b?y:a}removeDescendant(n){this.descendants=this.descendants.filter(h=>h!==n)}addAncestor({id:n,name:h="",previousApparition:s=0,duration:u=0,description:f,image:c,display:b=!0,copy:y=!1}){if(s<0)throw new Error(`The apparition of the ancestor must be before or equal the apparition (${this.apparition}) of the descendant`);if(u<s)throw new Error(`The extiction of the ancestor must be after or equal the apparition (${this.apparition}) of the descendant`);const a=y?this.copy():this,g=new pt({id:n,name:h,apparition:a.apparition-Math.max(s,0),duration:u,description:f,image:c});return g.display=b,a.linkAncestor(g),y?a:g}extinction(){return this.apparition+this.duration}absoluteExtinction(){return this.descendants.length>0?Math.max(...this.allDescendants(!1).map(n=>n.extinction())):this.extinction()}absoluteDuration(){return this.absoluteExtinction()-this.apparition}firstAncestor(n=!1){return this.ancestor?this.ancestor.display||n?this.ancestor.firstAncestor():this:this}cousinsExtinction(){return this.firstAncestor().absoluteExtinction()}allDescendants(n=!0){const h=n?Tt(this.descendants,a=>-a.apparition,a=>-a.absoluteExtinction()):this.descendants;if(h.length===0)return[this];const s=h.filter(a=>a.apparition>=this.extinction()),u=h.filter(a=>s.indexOf(a)===-1),c=(this.onPosition(n)?Math.ceil:Math.floor)(s.length/2),b=s.slice(0,c),y=s.slice(c);return b.flatMap(a=>a.allDescendants(n)).concat([this]).concat(y.flatMap(a=>a.allDescendants(n))).concat(u.flatMap(a=>a.allDescendants(n)))}stepsChain(n,h=!1){var s;return this.allDescendants(!1).includes(n)?[this].concat(((s=this.descendants.find(u=>u.allDescendants(!1).includes(n)))==null?void 0:s.stepsChain(n))??[]).filter(u=>u.display||h):[]}stepsUntil(n,h=!1){if(this.allDescendants(!1).includes(n))return this.stepsChain(n,h).length-1}stepsUntilLastDescendant(n=!1){return this.descendants.length===0?0:Math.max(...this.allDescendants(!1).filter(h=>h.descendants.length===0).map(h=>this.stepsUntil(h,n)??0))}toJSON(){return{name:this.name,apparition:this.ancestor?void 0:this.apparition,afterApparition:this.ancestor?this.apparition-this.ancestor.apparition:void 0,description:this.description,duration:this.duration,descendants:this.descendants.length>0?this.descendants.map(n=>n.toJSON()):void 0,image:this.image}}async saveJSON(n){try{const h=JSON.stringify(this.toJSON(),null,2),s=new Blob([h],{type:"application/json"}),u=URL.createObjectURL(s),f=document.createElement("a");f.href=u,f.download=n??`${this.name}.json`,f.click(),URL.revokeObjectURL(u)}catch(h){console.error("Error saving file:",h)}}static fromJSON({id:n,name:h,duration:s,description:u,image:f,descendants:c,...b},y){const a=b.afterApparition??0,g=y?y.apparition:b.apparition??0,w=new pt({id:n,name:h,apparition:g+a,duration:s,ancestor:y,description:u,image:f});if(c)for(const C of c)w.descendants.push(pt.fromJSON(C,w));return w}}const Mt=({speciesList:i,width:n=1e3,height:h=50,padding:s=0,stroke:u="grey",format:f=w=>w.toString(),chronoScale:c=!0,showImages:b=!0,presentTime:y,handleMouseMove:a,children:g})=>{const w=i.map(P=>P.copy()),C=Math.min(...w.map(P=>P.apparition)),I=Math.max(...w.map(P=>P.apparition-C)),T=new pt({name:"",apparition:C,duration:I});return T.display=!1,T.linkDescendants(w),o.jsx(Et,{commonAncestor:T,width:n,height:h,padding:s,stroke:u,format:f,chronoScale:c,showImages:b,presentTime:y,handleMouseMove:a,children:(P,F,H,V)=>g==null?void 0:g(P,F,H,V)})},Et=({commonAncestor:i,width:n=1e3,height:h=50,padding:s=0,stroke:u="grey",format:f=w=>w.toString(),chronoScale:c=!0,showImages:b=!0,presentTime:y,handleMouseMove:a,children:g})=>{const[w,C]=M.useState(!1),[I,T]=M.useState(void 0),[P,F]=M.useState(void 0),[H,V]=M.useState(i.allDescendants().reduce((t,e)=>t.set(e,!0),new Map));M.useEffect(()=>{V(i.allDescendants().reduce((t,e)=>t.set(e,!0),new Map))},[i]);const Z=t=>{T(w?void 0:t),C(!w)},it=t=>{const e=new Map(H);e.set(t,!H.get(t)),V(e)},et=t=>{F(t)},Q=y!==void 0&&c,_=t=>b?t.map(e=>e.image?2:1).reduce((e,r)=>e+r):t.length;return o.jsxs(o.Fragment,{children:[o.jsx("svg",{width:n*(Q?(Math.min(y,i.absoluteExtinction())-i.apparition)/i.absoluteDuration():1),height:h*_(Q?i.allDescendants().filter(t=>t.apparition<y):i.allDescendants()),onMouseMove:t=>{a==null||a(t.clientX,t.clientY)},children:o.jsx(St,{commonAncestor:i,species:i,y:-1,scaleX:n/(c?i.absoluteDuration():Math.max(0,i.stepsUntilLastDescendant())+1),scaleY:h,padding:s,stroke:u,format:f,chronoScale:c,showImages:b,presentTime:y,toggleShowMenu:Z,hoverShowMenu:et,showDesc:H,changeShowDesc:it})}),g==null?void 0:g(I,w,Z,P)]})},St=({commonAncestor:i,species:n,y:h,scaleX:s,scaleY:u,padding:f=0,stroke:c="grey",format:b=P=>P.toString(),chronoScale:y=!0,showImages:a=!0,presentTime:g=void 0,toggleShowMenu:w,hoverShowMenu:C,showDesc:I,changeShowDesc:T})=>{const P=g!==void 0&&y,F=i.allDescendants().filter(_=>P?_.apparition<g:!0),H=F.indexOf(n),V=(y?n.apparition-i.apparition:i.stepsUntil(n)??0)*s,Z=V+(y?Math.min(I.get(n)?n.duration:n.absoluteDuration(),P?g-n.apparition:n.absoluteDuration()):1)*s,it=a&&H>0?[...Array(H).keys()].map(_=>F[_]).map(_=>(_.image?2:1)*u).reduce((_,t)=>_+t):H*u,et=n.descendants.filter(_=>P?_.apparition<g:!0),Q=et.length>0?V+(Math.min(...et.map(_=>_.apparition))-n.apparition)*s:Z;return o.jsxs("g",{children:[h>=0&&o.jsx("line",{x1:V,y1:h,x2:V,y2:it,stroke:c}),n.display&&o.jsx(Lt,{commonAncestor:i,species:n,height:u,x1:V,x2:Z,x0:Q,y:it,stroke:c,changeShowDesc:()=>T(n),showDesc:I.get(n),padding:f,format:b,chronoScale:y,showImages:a,presentTime:g,toggleShowMenu:w,hoverShowMenu:C}),n.descendants.map((_,t)=>o.jsx("g",{className:I.get(n)&&et.includes(_)?"block":"hidden",children:o.jsx(St,{commonAncestor:i,species:_,y:_.display?it:-1,scaleX:s,scaleY:u,padding:f,stroke:c,format:b,chronoScale:y,showImages:a,presentTime:g,toggleShowMenu:w,showDesc:I,changeShowDesc:T,hoverShowMenu:C})},F.length+t))]},H)},Lt=({commonAncestor:i,species:n,height:h,x1:s,x2:u,x0:f,y:c,stroke:b,showDesc:y=!0,changeShowDesc:a=()=>{},padding:g=0,format:w=Z=>Z.toString(),chronoScale:C=!0,showImages:I=!0,presentTime:T,toggleShowMenu:P,hoverShowMenu:F,className:H,buttonClassName:V})=>{const Z=T!==void 0,it=i.allDescendants().filter(r=>Z?r.apparition<T:!0),et=r=>it.indexOf(r),Q=n.ancestor&&et(n)>et(n.ancestor)?-3:1,_=n.descendants.filter(r=>Z?r.apparition<T:!0),t=_.filter(r=>r.apparition===n.extinction()).length===0,e=w(Math.min(y?n.extinction():n.absoluteExtinction(),Z?T:n.absoluteExtinction()));return o.jsxs("g",{children:[o.jsx("line",{x1:s,y1:c,x2:u,y2:c,stroke:b}),o.jsx("foreignObject",{x:s+g,y:c+g*Q,width:(C?f??u:u)-s-2*g,height:h+(I&&n.image?h:0),children:o.jsxs("div",{className:`flex flex-row justify-between w-full ${H??""}`,children:[o.jsx("div",{children:C?w(n.apparition):""}),o.jsxs("button",{className:`p-0.625 justify-center flex flex-col items-center ${V??""}`,onClick:()=>P(n),onMouseEnter:()=>F(n),onMouseLeave:()=>F(void 0),children:[n.name,n.image&&I&&o.jsx("img",{src:n.image,alt:n.name,style:{height:h}})]}),_.length>0?o.jsx("button",{onClick:a,className:"h-1",style:{maxWidth:4},children:(t||!y)&&(!f||f===u)?e:""}):o.jsx("div",{children:C?e:""})]})}),C&&f&&f<u&&o.jsx("foreignObject",{x:f+g,y:c+g*Q,width:u-f-2*g,height:h,children:o.jsx("div",{className:"flex flex-row justify-end w-full",children:(t||!y)&&C?e:""})})]})},It=(i,n,h)=>i<n?n:i>h?h:i;function Ft(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var vt={exports:{}};/* @license
Papa Parse
v5.5.2
https://github.com/mholt/PapaParse
License: MIT
*/var jt=vt.exports,Dt;function Nt(){return Dt||(Dt=1,function(i,n){((h,s)=>{i.exports=s()})(jt,function h(){var s=typeof self<"u"?self:typeof window<"u"?window:s!==void 0?s:{},u,f=!s.document&&!!s.postMessage,c=s.IS_PAPA_WORKER||!1,b={},y=0,a={};function g(t){this._handle=null,this._finished=!1,this._completed=!1,this._halted=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},(function(e){var r=et(e);r.chunkSize=parseInt(r.chunkSize),e.step||e.chunk||(r.chunkSize=null),this._handle=new P(r),(this._handle.streamer=this)._config=r}).call(this,t),this.parseChunk=function(e,r){var d=parseInt(this._config.skipFirstNLines)||0;if(this.isFirstChunk&&0<d){let E=this._config.newline;E||(l=this._config.quoteChar||'"',E=this._handle.guessLineEndings(e,l)),e=[...e.split(E).slice(d)].join(E)}this.isFirstChunk&&_(this._config.beforeFirstChunk)&&(l=this._config.beforeFirstChunk(e))!==void 0&&(e=l),this.isFirstChunk=!1,this._halted=!1;var d=this._partialLine+e,l=(this._partialLine="",this._handle.parse(d,this._baseIndex,!this._finished));if(!this._handle.paused()&&!this._handle.aborted()){if(e=l.meta.cursor,d=(this._finished||(this._partialLine=d.substring(e-this._baseIndex),this._baseIndex=e),l&&l.data&&(this._rowCount+=l.data.length),this._finished||this._config.preview&&this._rowCount>=this._config.preview),c)s.postMessage({results:l,workerId:a.WORKER_ID,finished:d});else if(_(this._config.chunk)&&!r){if(this._config.chunk(l,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);this._completeResults=l=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(l.data),this._completeResults.errors=this._completeResults.errors.concat(l.errors),this._completeResults.meta=l.meta),this._completed||!d||!_(this._config.complete)||l&&l.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),d||l&&l.meta.paused||this._nextChunk(),l}this._halted=!0},this._sendError=function(e){_(this._config.error)?this._config.error(e):c&&this._config.error&&s.postMessage({workerId:a.WORKER_ID,error:e,finished:!1})}}function w(t){var e;(t=t||{}).chunkSize||(t.chunkSize=a.RemoteChunkSize),g.call(this,t),this._nextChunk=f?function(){this._readChunk(),this._chunkLoaded()}:function(){this._readChunk()},this.stream=function(r){this._input=r,this._nextChunk()},this._readChunk=function(){if(this._finished)this._chunkLoaded();else{if(e=new XMLHttpRequest,this._config.withCredentials&&(e.withCredentials=this._config.withCredentials),f||(e.onload=Q(this._chunkLoaded,this),e.onerror=Q(this._chunkError,this)),e.open(this._config.downloadRequestBody?"POST":"GET",this._input,!f),this._config.downloadRequestHeaders){var r,d=this._config.downloadRequestHeaders;for(r in d)e.setRequestHeader(r,d[r])}var l;this._config.chunkSize&&(l=this._start+this._config.chunkSize-1,e.setRequestHeader("Range","bytes="+this._start+"-"+l));try{e.send(this._config.downloadRequestBody)}catch(E){this._chunkError(E.message)}f&&e.status===0&&this._chunkError()}},this._chunkLoaded=function(){e.readyState===4&&(e.status<200||400<=e.status?this._chunkError():(this._start+=this._config.chunkSize||e.responseText.length,this._finished=!this._config.chunkSize||this._start>=(r=>(r=r.getResponseHeader("Content-Range"))!==null?parseInt(r.substring(r.lastIndexOf("/")+1)):-1)(e),this.parseChunk(e.responseText)))},this._chunkError=function(r){r=e.statusText||r,this._sendError(new Error(r))}}function C(t){(t=t||{}).chunkSize||(t.chunkSize=a.LocalChunkSize),g.call(this,t);var e,r,d=typeof FileReader<"u";this.stream=function(l){this._input=l,r=l.slice||l.webkitSlice||l.mozSlice,d?((e=new FileReader).onload=Q(this._chunkLoaded,this),e.onerror=Q(this._chunkError,this)):e=new FileReaderSync,this._nextChunk()},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount<this._config.preview)||this._readChunk()},this._readChunk=function(){var l=this._input,E=(this._config.chunkSize&&(E=Math.min(this._start+this._config.chunkSize,this._input.size),l=r.call(l,this._start,E)),e.readAsText(l,this._config.encoding));d||this._chunkLoaded({target:{result:E}})},this._chunkLoaded=function(l){this._start+=this._config.chunkSize,this._finished=!this._config.chunkSize||this._start>=this._input.size,this.parseChunk(l.target.result)},this._chunkError=function(){this._sendError(e.error)}}function I(t){var e;g.call(this,t=t||{}),this.stream=function(r){return e=r,this._nextChunk()},this._nextChunk=function(){var r,d;if(!this._finished)return r=this._config.chunkSize,e=r?(d=e.substring(0,r),e.substring(r)):(d=e,""),this._finished=!e,this.parseChunk(d)}}function T(t){g.call(this,t=t||{});var e=[],r=!0,d=!1;this.pause=function(){g.prototype.pause.apply(this,arguments),this._input.pause()},this.resume=function(){g.prototype.resume.apply(this,arguments),this._input.resume()},this.stream=function(l){this._input=l,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError)},this._checkIsFinished=function(){d&&e.length===1&&(this._finished=!0)},this._nextChunk=function(){this._checkIsFinished(),e.length?this.parseChunk(e.shift()):r=!0},this._streamData=Q(function(l){try{e.push(typeof l=="string"?l:l.toString(this._config.encoding)),r&&(r=!1,this._checkIsFinished(),this.parseChunk(e.shift()))}catch(E){this._streamError(E)}},this),this._streamError=Q(function(l){this._streamCleanUp(),this._sendError(l)},this),this._streamEnd=Q(function(){this._streamCleanUp(),d=!0,this._streamData("")},this),this._streamCleanUp=Q(function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError)},this)}function P(t){var e,r,d,l,E=Math.pow(2,53),J=-E,st=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,at=/^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/,S=this,q=0,m=0,Y=!1,k=!1,D=[],p={data:[],errors:[],meta:{}};function W(O){return t.skipEmptyLines==="greedy"?O.join("").trim()==="":O.length===1&&O[0].length===0}function B(){if(p&&d&&(ot("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+a.DefaultDelimiter+"'"),d=!1),t.skipEmptyLines&&(p.data=p.data.filter(function(v){return!W(v)})),G()){let v=function($,K){_(t.transformHeader)&&($=t.transformHeader($,K)),D.push($)};if(p)if(Array.isArray(p.data[0])){for(var O=0;G()&&O<p.data.length;O++)p.data[O].forEach(v);p.data.splice(0,1)}else p.data.forEach(v)}function L(v,$){for(var K=t.header?{}:[],j=0;j<v.length;j++){var N=j,A=v[j],A=((ht,x)=>(U=>(t.dynamicTypingFunction&&t.dynamicTyping[U]===void 0&&(t.dynamicTyping[U]=t.dynamicTypingFunction(U)),(t.dynamicTyping[U]||t.dynamicTyping)===!0))(ht)?x==="true"||x==="TRUE"||x!=="false"&&x!=="FALSE"&&((U=>{if(st.test(U)&&(U=parseFloat(U),J<U&&U<E))return 1})(x)?parseFloat(x):at.test(x)?new Date(x):x===""?null:x):x)(N=t.header?j>=D.length?"__parsed_extra":D[j]:N,A=t.transform?t.transform(A,N):A);N==="__parsed_extra"?(K[N]=K[N]||[],K[N].push(A)):K[N]=A}return t.header&&(j>D.length?ot("FieldMismatch","TooManyFields","Too many fields: expected "+D.length+" fields but parsed "+j,m+$):j<D.length&&ot("FieldMismatch","TooFewFields","Too few fields: expected "+D.length+" fields but parsed "+j,m+$)),K}var z;p&&(t.header||t.dynamicTyping||t.transform)&&(z=1,!p.data.length||Array.isArray(p.data[0])?(p.data=p.data.map(L),z=p.data.length):p.data=L(p.data,0),t.header&&p.meta&&(p.meta.fields=D),m+=z)}function G(){return t.header&&D.length===0}function ot(O,L,z,v){O={type:O,code:L,message:z},v!==void 0&&(O.row=v),p.errors.push(O)}_(t.step)&&(l=t.step,t.step=function(O){p=O,G()?B():(B(),p.data.length!==0&&(q+=O.data.length,t.preview&&q>t.preview?r.abort():(p.data=p.data[0],l(p,S))))}),this.parse=function(O,L,z){var v=t.quoteChar||'"',v=(t.newline||(t.newline=this.guessLineEndings(O,v)),d=!1,t.delimiter?_(t.delimiter)&&(t.delimiter=t.delimiter(O),p.meta.delimiter=t.delimiter):((v=(($,K,j,N,A)=>{var ht,x,U,gt;A=A||[","," ","|",";",a.RECORD_SEP,a.UNIT_SEP];for(var _t=0;_t<A.length;_t++){for(var dt,bt=A[_t],tt=0,lt=0,X=0,rt=(U=void 0,new H({comments:N,delimiter:bt,newline:K,preview:10}).parse($)),ft=0;ft<rt.data.length;ft++)j&&W(rt.data[ft])?X++:(dt=rt.data[ft].length,lt+=dt,U===void 0?U=dt:0<dt&&(tt+=Math.abs(dt-U),U=dt));0<rt.data.length&&(lt/=rt.data.length-X),(x===void 0||tt<=x)&&(gt===void 0||gt<lt)&&1.99<lt&&(x=tt,ht=bt,gt=lt)}return{successful:!!(t.delimiter=ht),bestDelimiter:ht}})(O,t.newline,t.skipEmptyLines,t.comments,t.delimitersToGuess)).successful?t.delimiter=v.bestDelimiter:(d=!0,t.delimiter=a.DefaultDelimiter),p.meta.delimiter=t.delimiter),et(t));return t.preview&&t.header&&v.preview++,e=O,r=new H(v),p=r.parse(e,L,z),B(),Y?{meta:{paused:!0}}:p||{meta:{paused:!1}}},this.paused=function(){return Y},this.pause=function(){Y=!0,r.abort(),e=_(t.chunk)?"":e.substring(r.getCharIndex())},this.resume=function(){S.streamer._halted?(Y=!1,S.streamer.parseChunk(e,!0)):setTimeout(S.resume,3)},this.aborted=function(){return k},this.abort=function(){k=!0,r.abort(),p.meta.aborted=!0,_(t.complete)&&t.complete(p),e=""},this.guessLineEndings=function($,v){$=$.substring(0,1048576);var v=new RegExp(F(v)+"([^]*?)"+F(v),"gm"),z=($=$.replace(v,"")).split("\r"),v=$.split(`
`),$=1<v.length&&v[0].length<z[0].length;if(z.length===1||$)return`
`;for(var K=0,j=0;j<z.length;j++)z[j][0]===`
`&&K++;return K>=z.length/2?`\r
`:"\r"}}function F(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function H(t){var e=(t=t||{}).delimiter,r=t.newline,d=t.comments,l=t.step,E=t.preview,J=t.fastMode,st=null,at=!1,S=t.quoteChar==null?'"':t.quoteChar,q=S;if(t.escapeChar!==void 0&&(q=t.escapeChar),(typeof e!="string"||-1<a.BAD_DELIMITERS.indexOf(e))&&(e=","),d===e)throw new Error("Comment character same as delimiter");d===!0?d="#":(typeof d!="string"||-1<a.BAD_DELIMITERS.indexOf(d))&&(d=!1),r!==`
`&&r!=="\r"&&r!==`\r
`&&(r=`
`);var m=0,Y=!1;this.parse=function(k,D,p){if(typeof k!="string")throw new Error("Input must be a string");var W=k.length,B=e.length,G=r.length,ot=d.length,O=_(l),L=[],z=[],v=[],$=m=0;if(!k)return tt();if(J||J!==!1&&k.indexOf(S)===-1){for(var K=k.split(r),j=0;j<K.length;j++){if(v=K[j],m+=v.length,j!==K.length-1)m+=r.length;else if(p)return tt();if(!d||v.substring(0,ot)!==d){if(O){if(L=[],gt(v.split(e)),lt(),Y)return tt()}else gt(v.split(e));if(E&&E<=j)return L=L.slice(0,E),tt(!0)}}return tt()}for(var N=k.indexOf(e,m),A=k.indexOf(r,m),ht=new RegExp(F(q)+F(S),"g"),x=k.indexOf(S,m);;)if(k[m]===S)for(x=m,m++;;){if((x=k.indexOf(S,x+1))===-1)return p||z.push({type:"Quotes",code:"MissingQuotes",message:"Quoted field unterminated",row:L.length,index:m}),dt();if(x===W-1)return dt(k.substring(m,x).replace(ht,S));if(S===q&&k[x+1]===q)x++;else if(S===q||x===0||k[x-1]!==q){N!==-1&&N<x+1&&(N=k.indexOf(e,x+1));var U=_t((A=A!==-1&&A<x+1?k.indexOf(r,x+1):A)===-1?N:Math.min(N,A));if(k.substr(x+1+U,B)===e){v.push(k.substring(m,x).replace(ht,S)),k[m=x+1+U+B]!==S&&(x=k.indexOf(S,m)),N=k.indexOf(e,m),A=k.indexOf(r,m);break}if(U=_t(A),k.substring(x+1+U,x+1+U+G)===r){if(v.push(k.substring(m,x).replace(ht,S)),bt(x+1+U+G),N=k.indexOf(e,m),x=k.indexOf(S,m),O&&(lt(),Y))return tt();if(E&&L.length>=E)return tt(!0);break}z.push({type:"Quotes",code:"InvalidQuotes",message:"Trailing quote on quoted field is malformed",row:L.length,index:m}),x++}}else if(d&&v.length===0&&k.substring(m,m+ot)===d){if(A===-1)return tt();m=A+G,A=k.indexOf(r,m),N=k.indexOf(e,m)}else if(N!==-1&&(N<A||A===-1))v.push(k.substring(m,N)),m=N+B,N=k.indexOf(e,m);else{if(A===-1)break;if(v.push(k.substring(m,A)),bt(A+G),O&&(lt(),Y))return tt();if(E&&L.length>=E)return tt(!0)}return dt();function gt(X){L.push(X),$=m}function _t(X){var rt=0;return rt=X!==-1&&(X=k.substring(x+1,X))&&X.trim()===""?X.length:rt}function dt(X){return p||(X===void 0&&(X=k.substring(m)),v.push(X),m=W,gt(v),O&<()),tt()}function bt(X){m=X,gt(v),v=[],A=k.indexOf(r,m)}function tt(X){if(t.header&&!D&&L.length&&!at){var rt=L[0],ft={},xt=new Set(rt);let At=!1;for(let yt=0;yt<rt.length;yt++){let ut=rt[yt];if(ft[ut=_(t.transformHeader)?t.transformHeader(ut,yt):ut]){let mt,Ct=ft[ut];for(;mt=ut+"_"+Ct,Ct++,xt.has(mt););xt.add(mt),rt[yt]=mt,ft[ut]++,At=!0,(st=st===null?{}:st)[mt]=ut}else ft[ut]=1,rt[yt]=ut;xt.add(ut)}At&&console.warn("Duplicate headers found and renamed."),at=!0}return{data:L,errors:z,meta:{delimiter:e,linebreak:r,aborted:Y,truncated:!!X,cursor:$+(D||0),renamedHeaders:st}}}function lt(){l(tt()),L=[],z=[]}},this.abort=function(){Y=!0},this.getCharIndex=function(){return m}}function V(t){var e=t.data,r=b[e.workerId],d=!1;if(e.error)r.userError(e.error,e.file);else if(e.results&&e.results.data){var l={abort:function(){d=!0,Z(e.workerId,{data:[],errors:[],meta:{aborted:!0}})},pause:it,resume:it};if(_(r.userStep)){for(var E=0;E<e.results.data.length&&(r.userStep({data:e.results.data[E],errors:e.results.errors,meta:e.results.meta},l),!d);E++);delete e.results}else _(r.userChunk)&&(r.userChunk(e.results,l,e.file),delete e.results)}e.finished&&!d&&Z(e.workerId,e.results)}function Z(t,e){var r=b[t];_(r.userComplete)&&r.userComplete(e),r.terminate(),delete b[t]}function it(){throw new Error("Not implemented.")}function et(t){if(typeof t!="object"||t===null)return t;var e,r=Array.isArray(t)?[]:{};for(e in t)r[e]=et(t[e]);return r}function Q(t,e){return function(){t.apply(e,arguments)}}function _(t){return typeof t=="function"}return a.parse=function(t,e){var r=(e=e||{}).dynamicTyping||!1;if(_(r)&&(e.dynamicTypingFunction=r,r={}),e.dynamicTyping=r,e.transform=!!_(e.transform)&&e.transform,!e.worker||!a.WORKERS_SUPPORTED)return r=null,a.NODE_STREAM_INPUT,typeof t=="string"?(t=(d=>d.charCodeAt(0)!==65279?d:d.slice(1))(t),r=new(e.download?w:I)(e)):t.readable===!0&&_(t.read)&&_(t.on)?r=new T(e):(s.File&&t instanceof File||t instanceof Object)&&(r=new C(e)),r.stream(t);(r=(()=>{var d;return!!a.WORKERS_SUPPORTED&&(d=(()=>{var l=s.URL||s.webkitURL||null,E=h.toString();return a.BLOB_URL||(a.BLOB_URL=l.createObjectURL(new Blob(["var global = (function() { if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } if (typeof global !== 'undefined') { return global; } return {}; })(); global.IS_PAPA_WORKER=true; ","(",E,")();"],{type:"text/javascript"})))})(),(d=new s.Worker(d)).onmessage=V,d.id=y++,b[d.id]=d)})()).userStep=e.step,r.userChunk=e.chunk,r.userComplete=e.complete,r.userError=e.error,e.step=_(e.step),e.chunk=_(e.chunk),e.complete=_(e.complete),e.error=_(e.error),delete e.worker,r.postMessage({input:t,config:e,workerId:r.id})},a.unparse=function(t,e){var r=!1,d=!0,l=",",E=`\r
`,J='"',st=J+J,at=!1,S=null,q=!1,m=((()=>{if(typeof e=="object"){if(typeof e.delimiter!="string"||a.BAD_DELIMITERS.filter(function(D){return e.delimiter.indexOf(D)!==-1}).length||(l=e.delimiter),typeof e.quotes!="boolean"&&typeof e.quotes!="function"&&!Array.isArray(e.quotes)||(r=e.quotes),typeof e.skipEmptyLines!="boolean"&&typeof e.skipEmptyLines!="string"||(at=e.skipEmptyLines),typeof e.newline=="string"&&(E=e.newline),typeof e.quoteChar=="string"&&(J=e.quoteChar),typeof e.header=="boolean"&&(d=e.header),Array.isArray(e.columns)){if(e.columns.length===0)throw new Error("Option columns is empty");S=e.columns}e.escapeChar!==void 0&&(st=e.escapeChar+J),e.escapeFormulae instanceof RegExp?q=e.escapeFormulae:typeof e.escapeFormulae=="boolean"&&e.escapeFormulae&&(q=/^[=+\-@\t\r].*$/)}})(),new RegExp(F(J),"g"));if(typeof t=="string"&&(t=JSON.parse(t)),Array.isArray(t)){if(!t.length||Array.isArray(t[0]))return Y(null,t,at);if(typeof t[0]=="object")return Y(S||Object.keys(t[0]),t,at)}else if(typeof t=="object")return typeof t.data=="string"&&(t.data=JSON.parse(t.data)),Array.isArray(t.data)&&(t.fields||(t.fields=t.meta&&t.meta.fields||S),t.fields||(t.fields=Array.isArray(t.data[0])?t.fields:typeof t.data[0]=="object"?Object.keys(t.data[0]):[]),Array.isArray(t.data[0])||typeof t.data[0]=="object"||(t.data=[t.data])),Y(t.fields||[],t.data||[],at);throw new Error("Unable to serialize unrecognized input");function Y(D,p,W){var B="",G=(typeof D=="string"&&(D=JSON.parse(D)),typeof p=="string"&&(p=JSON.parse(p)),Array.isArray(D)&&0<D.length),ot=!Array.isArray(p[0]);if(G&&d){for(var O=0;O<D.length;O++)0<O&&(B+=l),B+=k(D[O],O);0<p.length&&(B+=E)}for(var L=0;L<p.length;L++){var z=(G?D:p[L]).length,v=!1,$=G?Object.keys(p[L]).length===0:p[L].length===0;if(W&&!G&&(v=W==="greedy"?p[L].join("").trim()==="":p[L].length===1&&p[L][0].length===0),W==="greedy"&&G){for(var K=[],j=0;j<z;j++){var N=ot?D[j]:j;K.push(p[L][N])}v=K.join("").trim()===""}if(!v){for(var A=0;A<z;A++){0<A&&!$&&(B+=l);var ht=G&&ot?D[A]:A;B+=k(p[L][ht],A)}L<p.length-1&&(!W||0<z&&!$)&&(B+=E)}}return B}function k(D,p){var W,B;return D==null?"":D.constructor===Date?JSON.stringify(D).slice(1,25):(B=!1,q&&typeof D=="string"&&q.test(D)&&(D="'"+D,B=!0),W=D.toString().replace(m,st),(B=B||r===!0||typeof r=="function"&&r(D,p)||Array.isArray(r)&&r[p]||((G,ot)=>{for(var O=0;O<ot.length;O++)if(-1<G.indexOf(ot[O]))return!0;return!1})(W,a.BAD_DELIMITERS)||-1<W.indexOf(l)||W.charAt(0)===" "||W.charAt(W.length-1)===" ")?J+W+J:W)}},a.RECORD_SEP="",a.UNIT_SEP="",a.BYTE_ORDER_MARK="\uFEFF",a.BAD_DELIMITERS=["\r",`
`,'"',a.BYTE_ORDER_MARK],a.WORKERS_SUPPORTED=!f&&!!s.Worker,a.NODE_STREAM_INPUT=1,a.LocalChunkSize=10485760,a.RemoteChunkSize=5242880,a.DefaultDelimiter=",",a.Parser=H,a.ParserHandle=P,a.NetworkStreamer=w,a.FileStreamer=C,a.StringStreamer=I,a.ReadableStreamStreamer=T,s.jQuery&&((u=s.jQuery).fn.parse=function(t){var e=t.config||{},r=[];return this.each(function(E){if(!(u(this).prop("tagName").toUpperCase()==="INPUT"&&u(this).attr("type").toLowerCase()==="file"&&s.FileReader)||!this.files||this.files.length===0)return!0;for(var J=0;J<this.files.length;J++)r.push({file:this.files[J],inputElem:this,instanceConfig:u.extend({},e)})}),d(),this;function d(){if(r.length===0)_(t.complete)&&t.complete();else{var E,J,st,at,S=r[0];if(_(t.before)){var q=t.before(S.file,S.inputElem);if(typeof q=="object"){if(q.action==="abort")return E="AbortError",J=S.file,st=S.inputElem,at=q.reason,void(_(t.error)&&t.error({name:E},J,st,at));if(q.action==="skip")return void l();typeof q.config=="object"&&(S.instanceConfig=u.extend(S.instanceConfig,q.config))}else if(q==="skip")return void l()}var m=S.instanceConfig.complete;S.instanceConfig.complete=function(Y){_(m)&&m(Y,S.file,S.inputElem),l()},a.parse(S.file,S.instanceConfig)}}function l(){r.splice(0,1),d()}}),c&&(s.onmessage=function(t){t=t.data,a.WORKER_ID===void 0&&t&&(a.WORKER_ID=t.workerId),typeof t.input=="string"?s.postMessage({workerId:a.WORKER_ID,results:a.parse(t.input,t.config),finished:!0}):(s.File&&t.input instanceof File||t.input instanceof Object)&&(t=a.parse(t.input,t.config))&&s.postMessage({workerId:a.WORKER_ID,results:t,finished:!0})}),(w.prototype=Object.create(g.prototype)).constructor=w,(C.prototype=Object.create(g.prototype)).constructor=C,(I.prototype=Object.create(I.prototype)).constructor=I,(T.prototype=Object.create(g.prototype)).constructor=T,a})}(vt)),vt.exports}var Pt=Nt();const Ut=Ft(Pt);let Ot=[];const wt=async i=>{const s=await(await fetch(i)).body.getReader().read(),f=new TextDecoder("utf-8").decode(s.value),{data:c}=Ut.parse(f,{header:!0,dynamicTyping:!0,delimiter:";"});return c},qt=(i="/translate.csv")=>(async(n="/translate.csv")=>{Ot=await wt(n)})(i),nt=(i,n,h=[],s="/translate.csv")=>{const[u,f]=M.useState([]);M.useEffect(()=>{wt(s).then(f),qt(s)},[n]);const c=u.find(b=>b.code===i)??Ot.find(b=>b.code===i);try{const b=c[n];return h.reduce((a,g,w)=>a.replace(`{${w}}`,g),b)}catch{return}},zt=async(i,n,h=[],s="/translate.csv")=>{const f=(await wt(s)).find(c=>c.code===i);try{const c=f[n];return h.reduce((b,y,a)=>b.replace(`{${a}}`,y),c)}catch{return""}},$t=(i="/translate.csv")=>{const[n,h]=M.useState(new Map);return M.useEffect(()=>{(async()=>{const f=(await wt(i)).find(c=>c.code==="lan");if(f){delete f.code;const c=new Map(Object.entries(f));h(c)}})()},[]),n},Rt=({species:i,language:n,open:h,onClose:s,saveSpecies:u,createDescendant:f,createAncestor:c,deleteAncestor:b,deleteSpecies:y})=>{const[a,g]=M.useState(i.name),[w,C]=M.useState(i.apparition),[I,T]=M.useState(i.duration),[P,F]=M.useState(i.description??""),[H,V]=M.useState(!1),[Z,it]=M.useState(!1),[et,Q]=M.useState(i.image??""),_=()=>{V(!H)},t=()=>{it(!Z)},e=r=>r.ancestor?r.ancestor.descendants.length===1&&e(r.ancestor):!0;return o.jsx(Jt,{open:h,onClose:s,children:o.jsx("form",{style:{backgroundColor:"grey"},className:"flex flex-col text-start w-auto fixed p-2.5",children:o.jsxs(kt,{name:a,setName:g,apparition:w,setApparition:r=>{C(i.ancestor?It(r,i.ancestor.apparition,i.ancestor.extinction()):r),T(i.descendants.length>0?Math.max(Math.max(...i.descendants.map(d=>d.apparition))-w,I):I)},minApparition:i.ancestor?i.ancestor.apparition:void 0,maxApparition:i.ancestor?i.ancestor.extinction():void 0,duration:I,setDuration:T,minDuration:i.descendants.length>0?Math.max(...i.descendants.map(r=>r.apparition))-w:void 0,maxDuration:i.descendants.length>0?Math.max(...i.descendants.map(r=>r.apparition))-w:void 0,description:P,setDescription:F,image:et,setImage:Q,language:n,children:[o.jsx("button",{onClick:async()=>{try{await(u==null?void 0:u(i,a,w,I,P,et)),s==null||s()}catch(r){console.error(r)}},children:nt("spbtn00",n??"")}),o.jsx("button",{type:"button",onClick:y,children:nt("spbtn01",n??"")}),o.jsx("button",{type:"button",onClick:_,children:nt("spbtn02",n??"")}),H&&o.jsx(Bt,{species:i,language:n,onClose:s,createDescendant:f}),i.ancestor?e(i)&&o.jsx("button",{type:"button",onClick:async()=>{try{await(b==null?void 0:b()),s==null||s()}catch(r){console.error(r)}},children:nt("spbtn04"+(i.ancestor.ancestor?"_0":""),n??"")}):o.jsx("button",{type:"button",onClick:t,children:nt("spbtn03",n??"")}),Z&&o.jsx(Ht,{species:i,language:n,onClose:s,createAncestor:c}),o.jsx("button",{type:"button",onClick:s,children:nt("spbtn05",n??"")})]})})})},kt=({name:i,setName:n,apparition:h,setApparition:s,minApparition:u,maxApparition:f,duration:c,setDuration:b,minDuration:y,maxDuration:a,description:g,setDescription:w,language:C,image:I,setImage:T,children:P})=>o.jsxs(o.Fragment,{children:[o.jsx("table",{children:o.jsxs("tbody",{children:[o.jsxs("tr",{children:[o.jsxs("td",{children:[nt("splbl00",C??""),":"]}),o.jsx("td",{children:o.jsx("input",{type:"text",value:i,onChange:F=>n(F.target.value)})})]}),o.jsxs("tr",{children:[o.jsxs("td",{children:[nt("splbl01",C??""),":"]}),o.jsx("td",{children:o.jsx("input",{type:"number",min:u,max:f,value:h,onChange:F=>s(Number(F.target.value))})})]}),o.jsxs("tr",{children:[o.jsxs("td",{children:[nt("splbl02",C??""),":"]}),o.jsx("td",{children:o.jsx("input",{type:"number",min:y,max:a,value:c,onChange:F=>b(Number(F.target.value))})})]}),o.jsxs("tr",{children:[o.jsxs("td",{children:[nt("splbl03",C??""),":"]}),o.jsx("td",{children:o.jsx("textarea",{value:g,onChange:F=>w(F.target.value)})})]}),o.jsxs("tr",{children:[o.jsxs("td",{children:[nt("splbl04",C??""),":"]}),o.jsx("td",{children:o.jsx("input",{type:"text",value:I,onChange:F=>T(F.target.value)})})]}),o.jsx("tr",{children:o.jsx("td",{colSpan:2,children:o.jsx("img",{src:I,style:{height:"100px"}})})})]})}),P]}),Bt=({species:i,language:n,onClose:h,createDescendant:s})=>{const[u,f]=M.useState(""),[c,b]=M.useState(i.duration),[y,a]=M.useState(i.duration),[g,w]=M.useState(""),[C,I]=M.useState("");return o.jsx(o.Fragment,{children:o.jsx(kt,{name:u,setName:f,apparition:i.apparition+c,setApparition:T=>b(T-i.apparition),minApparition:i.apparition,maxApparition:i.extinction(),duration:y,setDuration:a,description:g,setDescription:w,image:C,setImage:I,language:n,children:o.jsx("button",{type:"button",onClick:async()=>{try{await(s==null?void 0:s(i,u,c,y,g,C)),h==null||h()}catch(T){console.error(T)}},children:nt("cdbtn00",n??"")})})})},Ht=({species:i,language:n,onClose:h,createAncestor:s})=>{const[u,f]=M.useState(""),[c,b]=M.useState(i.duration),[y,a]=M.useState(i.duration),[g,w]=M.useState(""),[C,I]=M.useState("");return o.jsx(o.Fragment,{children:o.jsx(kt,{name:u,setName:f,apparition:i.apparition-c,setApparition:T=>{b(i.apparition-T),a(Math.max(i.apparition-T,y))},maxApparition:i.apparition,duration:y,setDuration:a,minDuration:c,description:g,setDescription:w,image:C,setImage:I,language:n,children:o.jsx("button",{type:"button",onClick:async()=>{try{await(s==null?void 0:s(i,u,c,y,g,C)),h==null||h()}catch(T){console.error(T)}},children:nt("cdbtn00",n??"")})})})},Jt=({open:i,onClose:n,children:h})=>o.jsx("div",{style:{backgroundColor:i?"rgba(0, 0, 0, 0.2)":"rgba(0, 0, 0, 0)"},className:`flex fixed inset-0 justify-center items-center transition-colors duration-300 ease-in-out ${i?"visible":"hidden"}`,onClick:n,children:o.jsx("div",{onClick:s=>s.stopPropagation(),className:"flex justify-center items-center",children:h})});R.Menu=Rt,R.MultiplePhTrees=Mt,R.PhTree=Et,R.Species=pt,R.codeText=nt,R.codeTextAlt=zt,R.getLanguageOptions=$t,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})});