@nice2dev/ui-science 1.2.2 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +15 -14
- package/dist/index.d.ts +6 -1
- package/dist/index.mjs +1425 -1361
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var st=Object.defineProperty;var it=(e,t,r)=>t in e?st(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var
|
|
1
|
+
"use strict";var st=Object.defineProperty;var it=(e,t,r)=>t in e?st(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Se=(e,t,r)=>it(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),pe=require("@nice2dev/ui-core"),h=require("react");class Ye{constructor(t){Se(this,"config");Se(this,"notebooks",new Map);this.config=t}async createNotebook(t){const r={id:this.generateId(),name:t.name||"Untitled Notebook",description:t.description,project:t.project,owner:t.owner||"current-user",collaborators:t.collaborators||[],entries:[],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),isArchived:!1,settings:t.settings||{requireSignatures:!0,requireWitness:!1,autoLockAfterSign:!0,defaultEntryType:"experiment",customFields:[],templates:[]}};return this.notebooks.set(r.id,r),r}async getNotebook(t){return this.notebooks.get(t)||null}async listNotebooks(){return Array.from(this.notebooks.values())}async createEntry(t,r){const s=this.notebooks.get(t);if(!s)throw new Error(`Notebook not found: ${t}`);const i={id:this.generateId(),notebookId:t,type:r.type||s.settings.defaultEntryType,status:"draft",title:r.title||"Untitled Entry",objective:r.objective,hypothesis:r.hypothesis,methods:r.methods,results:r.results,conclusions:r.conclusions,sections:r.sections||[],attachments:[],tags:r.tags||[],linkedEntries:r.linkedEntries||[],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),createdBy:"current-user",lastModifiedBy:"current-user",version:1,signatures:[],comments:[]};return s.entries.push(i),s.updatedAt=new Date().toISOString(),i}async updateEntry(t,r,s){const i=this.notebooks.get(t);if(!i)throw new Error(`Notebook not found: ${t}`);const o=i.entries.findIndex(c=>c.id===r);if(o===-1)throw new Error(`Entry not found: ${r}`);const a=i.entries[o];if(a.status==="locked")throw new Error("Cannot modify locked entry");const l={...a,...s,id:a.id,notebookId:t,updatedAt:new Date().toISOString(),lastModifiedBy:"current-user",version:a.version+1};return i.entries[o]=l,i.updatedAt=new Date().toISOString(),l}async signEntry(t,r,s){const i=this.notebooks.get(t);if(!i)throw new Error(`Notebook not found: ${t}`);const o=i.entries.find(l=>l.id===r);if(!o)throw new Error(`Entry not found: ${r}`);const a={...s,signedAt:new Date().toISOString(),signatureHash:this.generateSignatureHash(o,s.userId)};return o.signatures.push(a),i.settings.autoLockAfterSign&&s.role==="author"&&(o.status="signed"),o.updatedAt=new Date().toISOString(),o}async addAttachment(t,r,s){const i=this.notebooks.get(t);if(!i)throw new Error(`Notebook not found: ${t}`);const o=i.entries.find(l=>l.id===r);if(!o)throw new Error(`Entry not found: ${r}`);const a={id:this.generateId(),name:s.name,type:s.type,size:s.size,url:URL.createObjectURL(s),uploadedAt:new Date().toISOString(),uploadedBy:"current-user"};return o.attachments.push(a),o.updatedAt=new Date().toISOString(),a}async searchEntries(t,r){var o,a,l,c,u,x;const s=[],i=t.toLowerCase();for(const y of this.notebooks.values())if(!(r!=null&&r.notebookId&&y.id!==r.notebookId))for(const f of y.entries)r!=null&&r.type&&f.type!==r.type||r!=null&&r.status&&f.status!==r.status||(o=r==null?void 0:r.tags)!=null&&o.length&&!r.tags.some(m=>f.tags.includes(m))||r!=null&&r.dateFrom&&f.createdAt<r.dateFrom||r!=null&&r.dateTo&&f.createdAt>r.dateTo||(f.title.toLowerCase().includes(i)||(a=f.objective)!=null&&a.toLowerCase().includes(i)||(l=f.hypothesis)!=null&&l.toLowerCase().includes(i)||(c=f.methods)!=null&&c.toLowerCase().includes(i)||(u=f.results)!=null&&u.toLowerCase().includes(i)||(x=f.conclusions)!=null&&x.toLowerCase().includes(i))&&s.push(f);return s}async exportEntry(t,r,s){const i=this.notebooks.get(t);if(!i)throw new Error(`Notebook not found: ${t}`);const o=i.entries.find(l=>l.id===r);if(!o)throw new Error(`Entry not found: ${r}`);const a=this.generateEntryHTML(o,i);return s==="html"?new Blob([a],{type:"text/html"}):new Blob([a],{type:"text/html"})}generateEntryHTML(t,r){return`
|
|
2
2
|
<!DOCTYPE html>
|
|
3
3
|
<html>
|
|
4
4
|
<head>
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
`:""}
|
|
40
40
|
</body>
|
|
41
41
|
</html>
|
|
42
|
-
`}generateId(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}generateSignatureHash(t,r){const s=JSON.stringify({entry:t,userId:r,timestamp:Date.now()});return Buffer.from(s).toString("base64").substring(0,32)}}function ot(e){return new Pe(e)}const Ve=h.createContext(null);function Fe(){const e=h.useContext(Ve);if(!e)throw new Error("useLabNotebook must be used within LabNotebookProvider");return e}function qe({service:e,children:t}){const[r,s]=h.useState([]),[i,o]=h.useState(null),[a,l]=h.useState(null),c=h.useCallback(async()=>{const g=await e.listNotebooks();s(g)},[e]),u=h.useMemo(()=>r.find(g=>g.id===i)||null,[r,i]),x=h.useMemo(()=>(u==null?void 0:u.entries.find(g=>g.id===a))||null,[u,a]),m=h.useCallback(g=>{o(g),l(null)},[]),f={service:e,notebooks:r,currentNotebook:u,currentEntry:x,setCurrentNotebook:m,setCurrentEntry:l,refresh:c};return n.jsx(Ve.Provider,{value:f,children:t})}const V={container:{display:"flex",height:"100%",backgroundColor:"var(--nice-bg-secondary, #f5f5f5)",fontFamily:"'Inter', sans-serif"},sidebar:{width:"280px",backgroundColor:"var(--nice-bg, #fff)",borderRight:"1px solid var(--nice-border, #e0e0e0)",display:"flex",flexDirection:"column"},main:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},header:{padding:"16px 24px",borderBottom:"1px solid var(--nice-border, #e0e0e0)",backgroundColor:"var(--nice-bg, #fff)"},content:{flex:1,padding:"24px",overflow:"auto"},entryCard:{padding:"12px 16px",borderBottom:"1px solid var(--nice-border, #eee)",cursor:"pointer",transition:"background-color 0.15s"},badge:{display:"inline-block",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:500,textTransform:"uppercase"},input:{width:"100%",padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)",borderRadius:"4px",fontSize:"14px"},textarea:{width:"100%",padding:"12px",border:"1px solid var(--nice-border, #ddd)",borderRadius:"4px",fontSize:"14px",minHeight:"100px",resize:"vertical"},button:{padding:"8px 16px",backgroundColor:"var(--nice-primary-hover, #1976d2)",color:"var(--nice-text-on-primary, #fff)",border:"none",borderRadius:"4px",cursor:"pointer",fontSize:"14px"}},Ie={draft:"var(--nice-text-secondary, #9e9e9e)","in-progress":"var(--nice-primary, #2196f3)",completed:"var(--nice-success, #4caf50)",reviewed:"var(--nice-warning, #ff9800)",signed:"var(--nice-accent, #9c27b0)",locked:"var(--nice-danger, #f44336)"},Ue={experiment:"EXP",protocol:"PRO",observation:"OBS",calculation:"CALC",meeting:"MEET",report:"REP",note:"NOTE"};function at({service:e,className:t,style:r}){return n.jsx(qe,{service:e,children:n.jsxs("div",{className:t,style:{...V.container,...r},children:[n.jsx(lt,{}),n.jsx(ct,{})]})})}function lt(){const{t:e}=pe.useNiceTranslation(),{notebooks:t,currentNotebook:r,setCurrentNotebook:s,service:i,refresh:o}=Fe(),[a,l]=h.useState(!1),[c,u]=h.useState(""),x=async()=>{c.trim()&&(await i.createNotebook({name:c.trim()}),await o(),u(""),l(!1))};return n.jsxs("div",{style:V.sidebar,children:[n.jsx("div",{style:{padding:"16px",borderBottom:"1px solid var(--nice-border, #e0e0e0)"},children:n.jsx("h2",{style:{margin:0,fontSize:"18px"},children:e("labNotebook.labNotebooks","Lab Notebooks")})}),n.jsx("div",{style:{flex:1,overflow:"auto"},children:t.map(m=>n.jsxs("div",{onClick:()=>s(m.id),style:{...V.entryCard,backgroundColor:(r==null?void 0:r.id)===m.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsx("div",{style:{fontWeight:500},children:m.name}),n.jsx("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)",marginTop:"4px"},children:e("labNotebook.entries","{entries} entries").replace("{entries}",String(m.entries.length))})]},m.id))}),n.jsx("div",{style:{padding:"16px",borderTop:"1px solid var(--nice-border, #e0e0e0)"},children:a?n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[n.jsx("input",{type:"text",value:c,onChange:m=>u(m.target.value),placeholder:e("labNotebook.notebookName","Notebook name"),style:V.input,autoFocus:!0}),n.jsxs("div",{style:{display:"flex",gap:"8px"},children:[n.jsx("button",{onClick:x,style:V.button,children:e("labNotebook.create","Create")}),n.jsx("button",{onClick:()=>l(!1),style:{...V.button,backgroundColor:"var(--nice-bg-tertiary, #9e9e9e)"},children:e("labNotebook.cancel","Cancel")})]})]}):n.jsx("button",{onClick:()=>l(!0),style:{...V.button,width:"100%"},children:e("labNotebook.newNotebook","+ New Notebook")})})]})}function ct(){const{t:e}=pe.useNiceTranslation(),{currentNotebook:t,currentEntry:r,setCurrentEntry:s,service:i,refresh:o}=Fe(),[a,l]=h.useState(!1);if(!t)return n.jsx("div",{style:{...V.main,justifyContent:"center",alignItems:"center"},children:n.jsx("div",{style:{textAlign:"center",color:"var(--nice-text-secondary, #666)"},children:n.jsx("div",{style:{fontSize:"18px"},children:e("labNotebook.selectANotebookToGet","Select a notebook to get started")})})});const c=async u=>{const x=await i.createEntry(t.id,{...u,title:u.title||e("labNotebook.untitledEntry","Untitled Entry")});await o(),s(x.id),l(!1)};return n.jsxs("div",{style:V.main,children:[n.jsx("div",{style:V.header,children:n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[n.jsx("h1",{style:{margin:0,fontSize:"20px"},children:t.name}),n.jsx("button",{onClick:()=>l(!0),style:V.button,children:e("labNotebook.newEntry","+ New Entry")})]})}),n.jsxs("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[n.jsx("div",{style:{width:"300px",borderRight:"1px solid var(--nice-border, #e0e0e0)",overflow:"auto"},children:t.entries.map(u=>n.jsxs("div",{onClick:()=>s(u.id),style:{...V.entryCard,backgroundColor:(r==null?void 0:r.id)===u.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[n.jsx("span",{style:{fontSize:"10px",fontWeight:600,color:"var(--nice-text-secondary, #666)"},children:Ue[u.type]}),n.jsx("span",{style:{fontWeight:500},children:u.title})]}),n.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[n.jsx("span",{style:{...V.badge,backgroundColor:`${Ie[u.status]}20`,color:Ie[u.status]},children:u.status}),n.jsx("span",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:new Date(u.updatedAt).toLocaleDateString()})]})]},u.id))}),n.jsx("div",{style:V.content,children:r?n.jsx(dt,{entry:r}):a?n.jsx(ut,{onSubmit:c,onCancel:()=>l(!1)}):n.jsx("div",{style:{textAlign:"center",color:"var(--nice-text-secondary, #666)",marginTop:"100px"},children:e("labNotebook.selectAnEntryOrCreate","Select an entry or create a new one")})})]})]})}function dt({entry:e}){const{t}=pe.useNiceTranslation(),{service:r,currentNotebook:s,refresh:i}=Fe(),[o,a]=h.useState(!1),[l,c]=h.useState(e),u=e.status==="locked"||e.status==="signed",x=async()=>{s&&(await r.updateEntry(s.id,e.id,l),await i(),a(!1))},m=async()=>{s&&(await r.signEntry(s.id,e.id,{userId:"current-user",userName:"Current User",role:"author"}),await i())};return n.jsxs("div",{children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:"24px"},children:[n.jsxs("div",{children:[n.jsx("h2",{style:{margin:0},children:e.title}),n.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[n.jsx("span",{style:{...V.badge,backgroundColor:`${Ie[e.status]}20`,color:Ie[e.status]},children:e.status}),n.jsxs("span",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:["v",e.version]})]})]}),!u&&n.jsx("div",{style:{display:"flex",gap:"8px"},children:o?n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:x,style:V.button,children:t("labNotebook.save","Save")}),n.jsx("button",{onClick:()=>{a(!1),c(e)},style:{...V.button,backgroundColor:"var(--nice-bg-tertiary, #9e9e9e)"},children:t("labNotebook.cancel","Cancel")})]}):n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>a(!0),style:V.button,children:t("labNotebook.edit","Edit")}),n.jsx("button",{onClick:m,style:{...V.button,backgroundColor:"var(--nice-accent, #9c27b0)"},children:t("labNotebook.sign","Sign")})]})})]}),o?n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:t("labNotebook.title","Title")}),n.jsx("input",{type:"text",value:l.title,onChange:f=>c({...l,title:f.target.value}),style:V.input})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:t("labNotebook.objective","Objective")}),n.jsx("textarea",{value:l.objective||"",onChange:f=>c({...l,objective:f.target.value}),style:V.textarea})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:t("labNotebook.methods","Methods")}),n.jsx("textarea",{value:l.methods||"",onChange:f=>c({...l,methods:f.target.value}),style:V.textarea})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:t("labNotebook.results","Results")}),n.jsx("textarea",{value:l.results||"",onChange:f=>c({...l,results:f.target.value}),style:V.textarea})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:t("labNotebook.conclusions","Conclusions")}),n.jsx("textarea",{value:l.conclusions||"",onChange:f=>c({...l,conclusions:f.target.value}),style:V.textarea})]})]}):n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"24px"},children:[e.objective&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:t("labNotebook.objective","Objective")}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.objective})]}),e.hypothesis&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:t("labNotebook.hypothesis","Hypothesis")}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.hypothesis})]}),e.methods&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:t("labNotebook.methods","Methods")}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.methods})]}),e.results&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:t("labNotebook.results","Results")}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.results})]}),e.conclusions&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:t("labNotebook.conclusions","Conclusions")}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.conclusions})]}),e.signatures.length>0&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-accent, #9c27b0)"},children:t("labNotebook.signatures","Signatures")}),e.signatures.map((f,g)=>n.jsxs("div",{style:{padding:"8px",backgroundColor:"var(--nice-bg-secondary, #f5f5f5)",borderRadius:"4px",marginBottom:"8px"},children:[n.jsx("strong",{children:f.userName})," (",f.role,")",n.jsx("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:new Date(f.signedAt).toLocaleString()})]},g))]}),e.attachments.length>0&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0"},children:t("labNotebook.attachments","Attachments")}),e.attachments.map(f=>n.jsx("a",{href:f.url,target:"_blank",rel:"noopener noreferrer",style:{display:"block",color:"var(--nice-primary-hover, #1976d2)",textDecoration:"none"},children:t("labNotebook.kb","{name} ({size} KB)").replace("{name}",String(f.name)).replace("{size}",String((f.size/1024).toFixed(1)))},f.id))]})]})]})}function ut({onSubmit:e,onCancel:t}){const{t:r}=pe.useNiceTranslation(),[s,i]=h.useState({title:"",type:"experiment",objective:""}),o=a=>{var l;a.preventDefault(),(l=s.title)!=null&&l.trim()&&e(s)};return n.jsxs("form",{onSubmit:o,style:{display:"flex",flexDirection:"column",gap:"16px"},children:[n.jsx("h2",{style:{margin:0},children:r("labNotebook.newEntry2","New Entry")}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:r("labNotebook.type","Type")}),n.jsx("select",{value:s.type,onChange:a=>i({...s,type:a.target.value}),style:V.input,children:Object.entries(Ue).map(([a,l])=>n.jsxs("option",{value:a,children:[l," ",a]},a))})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:r("labNotebook.title2","Title *")}),n.jsx("input",{type:"text",value:s.title,onChange:a=>i({...s,title:a.target.value}),placeholder:r("labNotebook.enterEntryTitle","Enter entry title"),style:V.input,required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:r("labNotebook.objective","Objective")}),n.jsx("textarea",{value:s.objective,onChange:a=>i({...s,objective:a.target.value}),placeholder:r("labNotebook.whatIsTheGoalOf","What is the goal of this entry?"),style:V.textarea})]}),n.jsxs("div",{style:{display:"flex",gap:"8px"},children:[n.jsx("button",{type:"submit",style:V.button,children:r("labNotebook.createEntry","Create Entry")}),n.jsx("button",{type:"button",onClick:t,style:{...V.button,backgroundColor:"var(--nice-bg-tertiary, #9e9e9e)"},children:r("labNotebook.cancel","Cancel")})]})]})}const ve=(function(){return{mean(e){return e.length===0?NaN:e.reduce((t,r)=>t+r,0)/e.length},median(e){if(e.length===0)return NaN;const t=[...e].sort((s,i)=>s-i),r=Math.floor(t.length/2);return t.length%2!==0?t[r]:(t[r-1]+t[r])/2},variance(e,t=!1){if(e.length===0)return NaN;const r=this.mean(e),s=e.map(o=>Math.pow(o-r,2)),i=t?e.length:e.length-1;return s.reduce((o,a)=>o+a,0)/i},std(e,t=!1){return Math.sqrt(this.variance(e,t))},mode(e){const t=new Map;let r=0,s=e[0];for(const i of e){const o=(t.get(i)||0)+1;t.set(i,o),o>r&&(r=o,s=i)}return s},percentile(e,t){if(e.length===0)return NaN;const r=[...e].sort((l,c)=>l-c),s=t/100*(r.length-1),i=Math.floor(s),o=Math.ceil(s),a=s-i;return r[i]*(1-a)+r[o]*a},quartiles(e){return{q1:this.percentile(e,25),q2:this.percentile(e,50),q3:this.percentile(e,75)}},skewness(e){const t=e.length;if(t<3)return NaN;const r=this.mean(e),s=this.std(e),i=e.map(o=>Math.pow((o-r)/s,3));return t/((t-1)*(t-2))*i.reduce((o,a)=>o+a,0)},kurtosis(e){const t=e.length;if(t<4)return NaN;const r=this.mean(e),s=this.std(e),o=e.map(a=>Math.pow((a-r)/s,4)).reduce((a,l)=>a+l,0);return t*(t+1)/((t-1)*(t-2)*(t-3))*o-3*Math.pow(t-1,2)/((t-2)*(t-3))},correlation(e,t){if(e.length!==t.length||e.length<2)return NaN;const r=e.length,s=this.mean(e),i=this.mean(t);let o=0,a=0,l=0;for(let c=0;c<r;c++){const u=e[c]-s,x=t[c]-i;o+=u*x,a+=u*u,l+=x*x}return o/Math.sqrt(a*l)},correlationMatrix(e){const t=Object.keys(e),r={};for(const s of t){r[s]={};for(const i of t)r[s][i]=this.correlation(e[s],e[i])}return r},covariance(e,t,r=!1){if(e.length!==t.length||e.length<2)return NaN;const s=e.length,i=this.mean(e),o=this.mean(t);let a=0;for(let l=0;l<s;l++)a+=(e[l]-i)*(t[l]-o);return a/(r?s:s-1)},linearRegression(e,t){if(e.length!==t.length||e.length<2)throw new Error("Invalid input arrays");const r=e.length,s=this.mean(e),i=this.mean(t);let o=0,a=0;for(let g=0;g<r;g++)o+=(e[g]-s)*(t[g]-i),a+=Math.pow(e[g]-s,2);const l=o/a,c=i-l*s;let u=0,x=0;for(let g=0;g<r;g++){const M=l*e[g]+c;u+=Math.pow(t[g]-i,2),x+=Math.pow(t[g]-M,2)}const m=1-x/u,f=`y = ${l.toFixed(4)}x + ${c.toFixed(4)}`;return{slope:l,intercept:c,r2:m,equation:f}},tTest(e,t){const r=e.length,s=t.length,i=this.mean(e),o=this.mean(t),a=this.variance(e),l=this.variance(t),c=Math.sqrt(a/r+l/s),u=(i-o)/c,x=Math.pow(a/r+l/s,2)/(Math.pow(a/r,2)/(r-1)+Math.pow(l/s,2)/(s-1)),m=2*(1-this.normalCDF(Math.abs(u)));return{tStatistic:u,pValue:m,degreesOfFreedom:x,meanDiff:i-o}},normalCDF(e){const t=.254829592,r=-.284496736,s=1.421413741,i=-1.453152027,o=1.061405429,a=.3275911,l=e<0?-1:1;e=Math.abs(e)/Math.sqrt(2);const c=1/(1+a*e),u=1-((((o*c+i)*c+s)*c+r)*c+t)*c*Math.exp(-e*e);return .5*(1+l*u)},chiSquare(e,t){if(e.length!==t.length)throw new Error("Arrays must have same length");let r=0;for(let o=0;o<e.length;o++)r+=Math.pow(e[o]-t[o],2)/t[o];const s=e.length-1;return{chiSquare:r,pValue:.05,degreesOfFreedom:s}},zScore(e){const t=this.mean(e),r=this.std(e);return e.map(s=>(s-t)/r)},minMaxNormalize(e,t=0,r=1){const s=Math.min(...e),o=Math.max(...e)-s;return e.map(a=>t+(a-s)/o*(r-t))},describe(e){const t=e.filter(s=>s!=null&&!isNaN(s)),r=this.quartiles(t);return{count:t.length,mean:this.mean(t),median:r.q2,std:this.std(t),min:Math.min(...t),max:Math.max(...t),q1:r.q1,q3:r.q3,skewness:this.skewness(t),kurtosis:this.kurtosis(t),mode:this.mode(t),variance:this.variance(t)}}}})();class Ke{constructor(t={}){be(this,"config");be(this,"datasets",new Map);be(this,"analyses",new Map);this.config={maxRowsInMemory:1e5,...t}}async importCSV(t,r){const s=(r==null?void 0:r.delimiter)||",",i=(r==null?void 0:r.header)!==!1,o=t.split(`
|
|
43
|
-
`).filter(f=>f.trim());if(o.length===0)throw new Error("Empty CSV content");const a=f=>{const
|
|
44
|
-
`)}getDataset(t){return this.datasets.get(t)}listDatasets(){return Array.from(this.datasets.values())}generateId(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}}function ht(e){return new Ke(e)}function pt({service:e,className:t,style:r}){const{t:s}=pe.useNiceTranslation(),[i,o]=h.useState([]),[a,l]=h.useState(null),[c,u]=h.useState("data"),x=h.useCallback(()=>{o(e.listDatasets())},[e]),
|
|
42
|
+
`}generateId(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}generateSignatureHash(t,r){const s=JSON.stringify({entry:t,userId:r,timestamp:Date.now()});return Buffer.from(s).toString("base64").substring(0,32)}}function ot(e){return new Ye(e)}const Ve=h.createContext(null);function Te(){const e=h.useContext(Ve);if(!e)throw new Error("useLabNotebook must be used within LabNotebookProvider");return e}function qe({service:e,children:t}){const[r,s]=h.useState([]),[i,o]=h.useState(null),[a,l]=h.useState(null),c=h.useCallback(async()=>{const m=await e.listNotebooks();s(m)},[e]),u=h.useMemo(()=>r.find(m=>m.id===i)||null,[r,i]),x=h.useMemo(()=>(u==null?void 0:u.entries.find(m=>m.id===a))||null,[u,a]),y=h.useCallback(m=>{o(m),l(null)},[]),f={service:e,notebooks:r,currentNotebook:u,currentEntry:x,setCurrentNotebook:y,setCurrentEntry:l,refresh:c};return n.jsx(Ve.Provider,{value:f,children:t})}const K={container:{display:"flex",height:"100%",backgroundColor:"var(--nice-bg-secondary, #f5f5f5)",fontFamily:"'Inter', sans-serif"},sidebar:{width:"280px",backgroundColor:"var(--nice-bg, #fff)",borderRight:"1px solid var(--nice-border, #e0e0e0)",display:"flex",flexDirection:"column"},main:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},header:{padding:"16px 24px",borderBottom:"1px solid var(--nice-border, #e0e0e0)",backgroundColor:"var(--nice-bg, #fff)"},content:{flex:1,padding:"24px",overflow:"auto"},entryCard:{padding:"12px 16px",borderBottom:"1px solid var(--nice-border, #eee)",cursor:"pointer",transition:"background-color 0.15s"},badge:{display:"inline-block",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:500,textTransform:"uppercase"},input:{width:"100%",padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)",borderRadius:"4px",fontSize:"14px"},textarea:{width:"100%",padding:"12px",border:"1px solid var(--nice-border, #ddd)",borderRadius:"4px",fontSize:"14px",minHeight:"100px",resize:"vertical"},button:{padding:"8px 16px",backgroundColor:"var(--nice-primary-hover, #1976d2)",color:"var(--nice-text-on-primary, #fff)",border:"none",borderRadius:"4px",cursor:"pointer",fontSize:"14px"}},Be={draft:"var(--nice-text-secondary, #9e9e9e)","in-progress":"var(--nice-primary, #2196f3)",completed:"var(--nice-success, #4caf50)",reviewed:"var(--nice-warning, #ff9800)",signed:"var(--nice-accent, #9c27b0)",locked:"var(--nice-danger, #f44336)"},Ue={experiment:"EXP",protocol:"PRO",observation:"OBS",calculation:"CALC",meeting:"MEET",report:"REP",note:"NOTE"};function at({service:e,className:t,style:r}){return n.jsx(qe,{service:e,children:n.jsxs("div",{className:t,style:{...K.container,...r},children:[n.jsx(lt,{}),n.jsx(ct,{})]})})}function lt(){const{t:e}=pe.useNiceTranslation(),{notebooks:t,currentNotebook:r,setCurrentNotebook:s,service:i,refresh:o}=Te(),[a,l]=h.useState(!1),[c,u]=h.useState(""),x=async()=>{c.trim()&&(await i.createNotebook({name:c.trim()}),await o(),u(""),l(!1))};return n.jsxs("div",{style:K.sidebar,children:[n.jsx("div",{style:{padding:"16px",borderBottom:"1px solid var(--nice-border, #e0e0e0)"},children:n.jsx("h2",{style:{margin:0,fontSize:"18px"},children:e("labNotebook.labNotebooks","Lab Notebooks")})}),n.jsx("div",{style:{flex:1,overflow:"auto"},children:t.map(y=>n.jsxs("div",{role:"button",tabIndex:0,onKeyDown:pe.clickOnActivationKey,onClick:()=>s(y.id),style:{...K.entryCard,backgroundColor:(r==null?void 0:r.id)===y.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsx("div",{style:{fontWeight:500},children:y.name}),n.jsx("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)",marginTop:"4px"},children:e("labNotebook.entries","{entries} entries").replace("{entries}",String(y.entries.length))})]},y.id))}),n.jsx("div",{style:{padding:"16px",borderTop:"1px solid var(--nice-border, #e0e0e0)"},children:a?n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[n.jsx("input",{type:"text",value:c,onChange:y=>u(y.target.value),placeholder:e("labNotebook.notebookName","Notebook name"),style:K.input,autoFocus:!0}),n.jsxs("div",{style:{display:"flex",gap:"8px"},children:[n.jsx("button",{onClick:x,style:K.button,children:e("labNotebook.create","Create")}),n.jsx("button",{onClick:()=>l(!1),style:{...K.button,backgroundColor:"var(--nice-bg-tertiary, #9e9e9e)"},children:e("labNotebook.cancel","Cancel")})]})]}):n.jsx("button",{onClick:()=>l(!0),style:{...K.button,width:"100%"},children:e("labNotebook.newNotebook","+ New Notebook")})})]})}function ct(){const{t:e}=pe.useNiceTranslation(),{currentNotebook:t,currentEntry:r,setCurrentEntry:s,service:i,refresh:o}=Te(),[a,l]=h.useState(!1);if(!t)return n.jsx("div",{style:{...K.main,justifyContent:"center",alignItems:"center"},children:n.jsx("div",{style:{textAlign:"center",color:"var(--nice-text-secondary, #666)"},children:n.jsx("div",{style:{fontSize:"18px"},children:e("labNotebook.selectANotebookToGet","Select a notebook to get started")})})});const c=async u=>{const x=await i.createEntry(t.id,{...u,title:u.title||e("labNotebook.untitledEntry","Untitled Entry")});await o(),s(x.id),l(!1)};return n.jsxs("div",{style:K.main,children:[n.jsx("div",{style:K.header,children:n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[n.jsx("h1",{style:{margin:0,fontSize:"20px"},children:t.name}),n.jsx("button",{onClick:()=>l(!0),style:K.button,children:e("labNotebook.newEntry","+ New Entry")})]})}),n.jsxs("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[n.jsx("div",{style:{width:"300px",borderRight:"1px solid var(--nice-border, #e0e0e0)",overflow:"auto"},children:t.entries.map(u=>n.jsxs("div",{role:"button",tabIndex:0,onKeyDown:pe.clickOnActivationKey,onClick:()=>s(u.id),style:{...K.entryCard,backgroundColor:(r==null?void 0:r.id)===u.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[n.jsx("span",{style:{fontSize:"10px",fontWeight:600,color:"var(--nice-text-secondary, #666)"},children:Ue[u.type]}),n.jsx("span",{style:{fontWeight:500},children:u.title})]}),n.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[n.jsx("span",{style:{...K.badge,backgroundColor:`${Be[u.status]}20`,color:Be[u.status]},children:u.status}),n.jsx("span",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:new Date(u.updatedAt).toLocaleDateString()})]})]},u.id))}),n.jsx("div",{style:K.content,children:r?n.jsx(dt,{entry:r}):a?n.jsx(ut,{onSubmit:c,onCancel:()=>l(!1)}):n.jsx("div",{style:{textAlign:"center",color:"var(--nice-text-secondary, #666)",marginTop:"100px"},children:e("labNotebook.selectAnEntryOrCreate","Select an entry or create a new one")})})]})]})}function dt({entry:e}){const{t}=pe.useNiceTranslation(),{service:r,currentNotebook:s,refresh:i}=Te(),[o,a]=h.useState(!1),[l,c]=h.useState(e),u=e.status==="locked"||e.status==="signed",x=async()=>{s&&(await r.updateEntry(s.id,e.id,l),await i(),a(!1))},y=async()=>{s&&(await r.signEntry(s.id,e.id,{userId:"current-user",userName:"Current User",role:"author"}),await i())};return n.jsxs("div",{children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:"24px"},children:[n.jsxs("div",{children:[n.jsx("h2",{style:{margin:0},children:e.title}),n.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[n.jsx("span",{style:{...K.badge,backgroundColor:`${Be[e.status]}20`,color:Be[e.status]},children:e.status}),n.jsxs("span",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:["v",e.version]})]})]}),!u&&n.jsx("div",{style:{display:"flex",gap:"8px"},children:o?n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:x,style:K.button,children:t("labNotebook.save","Save")}),n.jsx("button",{onClick:()=>{a(!1),c(e)},style:{...K.button,backgroundColor:"var(--nice-bg-tertiary, #9e9e9e)"},children:t("labNotebook.cancel","Cancel")})]}):n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>a(!0),style:K.button,children:t("labNotebook.edit","Edit")}),n.jsx("button",{onClick:y,style:{...K.button,backgroundColor:"var(--nice-accent, #9c27b0)"},children:t("labNotebook.sign","Sign")})]})})]}),o?n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:t("labNotebook.title","Title")}),n.jsx("input",{type:"text",value:l.title,onChange:f=>c({...l,title:f.target.value}),style:K.input})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:t("labNotebook.objective","Objective")}),n.jsx("textarea",{value:l.objective||"",onChange:f=>c({...l,objective:f.target.value}),style:K.textarea})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:t("labNotebook.methods","Methods")}),n.jsx("textarea",{value:l.methods||"",onChange:f=>c({...l,methods:f.target.value}),style:K.textarea})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:t("labNotebook.results","Results")}),n.jsx("textarea",{value:l.results||"",onChange:f=>c({...l,results:f.target.value}),style:K.textarea})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:t("labNotebook.conclusions","Conclusions")}),n.jsx("textarea",{value:l.conclusions||"",onChange:f=>c({...l,conclusions:f.target.value}),style:K.textarea})]})]}):n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"24px"},children:[e.objective&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:t("labNotebook.objective","Objective")}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.objective})]}),e.hypothesis&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:t("labNotebook.hypothesis","Hypothesis")}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.hypothesis})]}),e.methods&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:t("labNotebook.methods","Methods")}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.methods})]}),e.results&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:t("labNotebook.results","Results")}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.results})]}),e.conclusions&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:t("labNotebook.conclusions","Conclusions")}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.conclusions})]}),e.signatures.length>0&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-accent, #9c27b0)"},children:t("labNotebook.signatures","Signatures")}),e.signatures.map((f,m)=>n.jsxs("div",{style:{padding:"8px",backgroundColor:"var(--nice-bg-secondary, #f5f5f5)",borderRadius:"4px",marginBottom:"8px"},children:[n.jsx("strong",{children:f.userName})," (",f.role,")",n.jsx("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:new Date(f.signedAt).toLocaleString()})]},m))]}),e.attachments.length>0&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0"},children:t("labNotebook.attachments","Attachments")}),e.attachments.map(f=>n.jsx("a",{href:f.url,target:"_blank",rel:"noopener noreferrer",style:{display:"block",color:"var(--nice-primary-hover, #1976d2)",textDecoration:"none"},children:t("labNotebook.kb","{name} ({size} KB)").replace("{name}",String(f.name)).replace("{size}",String((f.size/1024).toFixed(1)))},f.id))]})]})]})}function ut({onSubmit:e,onCancel:t}){const{t:r}=pe.useNiceTranslation(),[s,i]=h.useState({title:"",type:"experiment",objective:""}),o=a=>{var l;a.preventDefault(),(l=s.title)!=null&&l.trim()&&e(s)};return n.jsxs("form",{onSubmit:o,style:{display:"flex",flexDirection:"column",gap:"16px"},children:[n.jsx("h2",{style:{margin:0},children:r("labNotebook.newEntry2","New Entry")}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:r("labNotebook.type","Type")}),n.jsx("select",{value:s.type,onChange:a=>i({...s,type:a.target.value}),style:K.input,children:Object.entries(Ue).map(([a,l])=>n.jsxs("option",{value:a,children:[l," ",a]},a))})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:r("labNotebook.title2","Title *")}),n.jsx("input",{type:"text",value:s.title,onChange:a=>i({...s,title:a.target.value}),placeholder:r("labNotebook.enterEntryTitle","Enter entry title"),style:K.input,required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:r("labNotebook.objective","Objective")}),n.jsx("textarea",{value:s.objective,onChange:a=>i({...s,objective:a.target.value}),placeholder:r("labNotebook.whatIsTheGoalOf","What is the goal of this entry?"),style:K.textarea})]}),n.jsxs("div",{style:{display:"flex",gap:"8px"},children:[n.jsx("button",{type:"submit",style:K.button,children:r("labNotebook.createEntry","Create Entry")}),n.jsx("button",{type:"button",onClick:t,style:{...K.button,backgroundColor:"var(--nice-bg-tertiary, #9e9e9e)"},children:r("labNotebook.cancel","Cancel")})]})]})}const ke=(function(){return{mean(e){return e.length===0?NaN:e.reduce((t,r)=>t+r,0)/e.length},median(e){if(e.length===0)return NaN;const t=[...e].sort((s,i)=>s-i),r=Math.floor(t.length/2);return t.length%2!==0?t[r]:(t[r-1]+t[r])/2},variance(e,t=!1){if(e.length===0)return NaN;const r=this.mean(e),s=e.map(o=>Math.pow(o-r,2)),i=t?e.length:e.length-1;return s.reduce((o,a)=>o+a,0)/i},std(e,t=!1){return Math.sqrt(this.variance(e,t))},mode(e){const t=new Map;let r=0,s=e[0];for(const i of e){const o=(t.get(i)||0)+1;t.set(i,o),o>r&&(r=o,s=i)}return s},percentile(e,t){if(e.length===0)return NaN;const r=[...e].sort((l,c)=>l-c),s=t/100*(r.length-1),i=Math.floor(s),o=Math.ceil(s),a=s-i;return r[i]*(1-a)+r[o]*a},quartiles(e){return{q1:this.percentile(e,25),q2:this.percentile(e,50),q3:this.percentile(e,75)}},skewness(e){const t=e.length;if(t<3)return NaN;const r=this.mean(e),s=this.std(e),i=e.map(o=>Math.pow((o-r)/s,3));return t/((t-1)*(t-2))*i.reduce((o,a)=>o+a,0)},kurtosis(e){const t=e.length;if(t<4)return NaN;const r=this.mean(e),s=this.std(e),o=e.map(a=>Math.pow((a-r)/s,4)).reduce((a,l)=>a+l,0);return t*(t+1)/((t-1)*(t-2)*(t-3))*o-3*Math.pow(t-1,2)/((t-2)*(t-3))},correlation(e,t){if(e.length!==t.length||e.length<2)return NaN;const r=e.length,s=this.mean(e),i=this.mean(t);let o=0,a=0,l=0;for(let c=0;c<r;c++){const u=e[c]-s,x=t[c]-i;o+=u*x,a+=u*u,l+=x*x}return o/Math.sqrt(a*l)},correlationMatrix(e){const t=Object.keys(e),r={};for(const s of t){r[s]={};for(const i of t)r[s][i]=this.correlation(e[s],e[i])}return r},covariance(e,t,r=!1){if(e.length!==t.length||e.length<2)return NaN;const s=e.length,i=this.mean(e),o=this.mean(t);let a=0;for(let l=0;l<s;l++)a+=(e[l]-i)*(t[l]-o);return a/(r?s:s-1)},linearRegression(e,t){if(e.length!==t.length||e.length<2)throw new Error("Invalid input arrays");const r=e.length,s=this.mean(e),i=this.mean(t);let o=0,a=0;for(let m=0;m<r;m++)o+=(e[m]-s)*(t[m]-i),a+=Math.pow(e[m]-s,2);const l=o/a,c=i-l*s;let u=0,x=0;for(let m=0;m<r;m++){const M=l*e[m]+c;u+=Math.pow(t[m]-i,2),x+=Math.pow(t[m]-M,2)}const y=1-x/u,f=`y = ${l.toFixed(4)}x + ${c.toFixed(4)}`;return{slope:l,intercept:c,r2:y,equation:f}},tTest(e,t){const r=e.length,s=t.length,i=this.mean(e),o=this.mean(t),a=this.variance(e),l=this.variance(t),c=Math.sqrt(a/r+l/s),u=(i-o)/c,x=Math.pow(a/r+l/s,2)/(Math.pow(a/r,2)/(r-1)+Math.pow(l/s,2)/(s-1)),y=2*(1-this.normalCDF(Math.abs(u)));return{tStatistic:u,pValue:y,degreesOfFreedom:x,meanDiff:i-o}},normalCDF(e){const t=.254829592,r=-.284496736,s=1.421413741,i=-1.453152027,o=1.061405429,a=.3275911,l=e<0?-1:1;e=Math.abs(e)/Math.sqrt(2);const c=1/(1+a*e),u=1-((((o*c+i)*c+s)*c+r)*c+t)*c*Math.exp(-e*e);return .5*(1+l*u)},chiSquare(e,t){if(e.length!==t.length)throw new Error("Arrays must have same length");let r=0;for(let o=0;o<e.length;o++)r+=Math.pow(e[o]-t[o],2)/t[o];const s=e.length-1;return{chiSquare:r,pValue:.05,degreesOfFreedom:s}},zScore(e){const t=this.mean(e),r=this.std(e);return e.map(s=>(s-t)/r)},minMaxNormalize(e,t=0,r=1){const s=Math.min(...e),o=Math.max(...e)-s;return e.map(a=>t+(a-s)/o*(r-t))},describe(e){const t=e.filter(s=>s!=null&&!isNaN(s)),r=this.quartiles(t);return{count:t.length,mean:this.mean(t),median:r.q2,std:this.std(t),min:Math.min(...t),max:Math.max(...t),q1:r.q1,q3:r.q3,skewness:this.skewness(t),kurtosis:this.kurtosis(t),mode:this.mode(t),variance:this.variance(t)}}}})();class Ke{constructor(t={}){Se(this,"config");Se(this,"datasets",new Map);Se(this,"analyses",new Map);this.config={maxRowsInMemory:1e5,...t}}async importCSV(t,r){const s=(r==null?void 0:r.delimiter)||",",i=(r==null?void 0:r.header)!==!1,o=t.split(`
|
|
43
|
+
`).filter(f=>f.trim());if(o.length===0)throw new Error("Empty CSV content");const a=f=>{const m=[];let M="",E=!1;for(const q of f)q==='"'?E=!E:q===s&&!E?(m.push(M.trim()),M=""):M+=q;return m.push(M.trim()),m},l=a(o[0]),c=i?l:l.map((f,m)=>`col_${m+1}`),u=i?1:0,x=[];for(let f=u;f<o.length;f++){const m=a(o[f]),M={};for(let E=0;E<c.length;E++){const q=m[E],re=parseFloat(q);M[c[E]]=!isNaN(re)&&q!==""?re:q}x.push(M)}return this.createDataset({name:(r==null?void 0:r.name)||"Imported CSV",data:x,source:{type:"csv"}})}async importJSON(t,r){const s=typeof t=="string"?JSON.parse(t):t;if(!Array.isArray(s))throw new Error("JSON must be an array of objects");return this.createDataset({name:(r==null?void 0:r.name)||"Imported JSON",data:s,source:{type:"json"}})}createDataset(t){const{name:r,data:s,description:i,source:o}=t,a=this.inferColumns(s),l={id:this.generateId(),name:r,description:i,columns:a,data:s,rowCount:s.length,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),source:o};return this.datasets.set(l.id,l),l}inferColumns(t){if(t.length===0)return[];const r=new Set;t.forEach(i=>Object.keys(i).forEach(o=>r.add(o)));const s=[];for(const i of r){const o=t.map(x=>x[i]),a=o.filter(x=>x!=null),l=new Set(a);let c="mixed";a.every(x=>typeof x=="number")?c="number":a.every(x=>typeof x=="string")?c=l.size<a.length*.5?"category":"string":a.every(x=>typeof x=="boolean")?c="boolean":a.every(x=>x instanceof Date||!isNaN(Date.parse(x)))&&(c="date");const u={name:i,type:c,nullable:o.some(x=>x==null),unique:l.size,missing:o.length-a.length};if(c==="number"){const x=a.filter(y=>typeof y=="number");u.stats=ke.describe(x)}s.push(u)}return s}runAnalysis(t,r,s={}){const i=this.datasets.get(t);if(!i)throw new Error(`Dataset not found: ${t}`);const o=performance.now();let a;switch(r){case"descriptive":a=this.descriptiveAnalysis(i,s);break;case"correlation":a=this.correlationAnalysis(i,s);break;case"regression":a=this.regressionAnalysis(i,s);break;case"ttest":a=this.tTestAnalysis(i,s);break;case"distribution":a=this.distributionAnalysis(i,s);break;default:throw new Error(`Unsupported analysis type: ${r}`)}const l=performance.now()-o,c={id:this.generateId(),datasetId:t,type:r,parameters:s,result:a,createdAt:new Date().toISOString(),executionTimeMs:l};return this.analyses.set(c.id,c),c}descriptiveAnalysis(t,r){const s=r.columns||t.columns.filter(o=>o.type==="number").map(o=>o.name),i={};for(const o of s){const a=t.data.map(l=>l[o]).filter(l=>typeof l=="number");i[o]=ke.describe(a)}return i}correlationAnalysis(t,r){const s=r.columns||t.columns.filter(o=>o.type==="number").map(o=>o.name),i={};for(const o of s)i[o]=t.data.map(a=>a[o]).filter(a=>typeof a=="number");return{matrix:ke.correlationMatrix(i),columns:s}}regressionAnalysis(t,r){const{xColumn:s,yColumn:i}=r,o=t.data.map(l=>l[s]).filter(l=>typeof l=="number"),a=t.data.map(l=>l[i]).filter(l=>typeof l=="number");return ke.linearRegression(o,a)}tTestAnalysis(t,r){const{column:s,groupColumn:i}=r,o=new Map;for(const l of t.data){const c=l[i],u=l[s];typeof u=="number"&&(o.has(c)||o.set(c,[]),o.get(c).push(u))}const a=Array.from(o.keys());if(a.length!==2)throw new Error("T-test requires exactly 2 groups");return ke.tTest(o.get(a[0]),o.get(a[1]))}distributionAnalysis(t,r){const{column:s,bins:i=10}=r,o=t.data.map(y=>y[s]).filter(y=>typeof y=="number"),a=Math.min(...o),c=(Math.max(...o)-a)/i,u=new Array(i).fill(0),x=[];for(let y=0;y<=i;y++)x.push(a+y*c);for(const y of o){const f=Math.min(Math.floor((y-a)/c),i-1);u[f]++}return{histogram:u,binEdges:x,stats:ke.describe(o)}}transform(t,r){const s=this.datasets.get(t);if(!s)throw new Error(`Dataset not found: ${t}`);let i=[...s.data];switch(r.type){case"filter":i=this.applyFilter(i,r);break;case"sort":i=this.applySort(i,r);break;case"fillna":i=this.applyFillNA(i,r);break;case"dropna":i=this.applyDropNA(i,r);break;case"normalize":i=this.applyNormalize(i,r);break;case"standardize":i=this.applyStandardize(i,r);break;default:throw new Error(`Unsupported transformation: ${r.type}`)}return this.createDataset({name:`${s.name} (transformed)`,data:i})}applyFilter(t,r){const{column:s,parameters:i}=r,{operator:o,value:a}=i;return t.filter(l=>{const c=l[s];switch(o){case"==":return c===a;case"!=":return c!==a;case">":return c>a;case">=":return c>=a;case"<":return c<a;case"<=":return c<=a;case"contains":return String(c).includes(a);case"startswith":return String(c).startsWith(a);default:return!0}})}applySort(t,r){const{column:s,parameters:i}=r,o=i.ascending!==!1;return[...t].sort((a,l)=>{const c=a[s],u=l[s];return c<u?o?-1:1:c>u?o?1:-1:0})}applyFillNA(t,r){const{column:s,parameters:i}=r,o=i.value;return t.map(a=>({...a,[s]:a[s]??o}))}applyDropNA(t,r){const s=r.columns||[r.column];return t.filter(i=>s.every(o=>i[o]!=null))}applyNormalize(t,r){const{column:s}=r,i=t.map(c=>c[s]).filter(c=>typeof c=="number"),o=Math.min(...i),l=Math.max(...i)-o;return t.map(c=>({...c,[s]:typeof c[s]=="number"?(c[s]-o)/l:c[s]}))}applyStandardize(t,r){const{column:s}=r,i=t.map(l=>l[s]).filter(l=>typeof l=="number"),o=ke.mean(i),a=ke.std(i);return t.map(l=>({...l,[s]:typeof l[s]=="number"?(l[s]-o)/a:l[s]}))}exportCSV(t){const r=this.datasets.get(t);if(!r)throw new Error(`Dataset not found: ${t}`);const s=r.columns.map(o=>o.name),i=r.data.map(o=>s.map(a=>{const l=o[a];return l==null?"":typeof l=="string"&&(l.includes(",")||l.includes('"'))?`"${l.replace(/"/g,'""')}"`:String(l)}).join(","));return[s.join(","),...i].join(`
|
|
44
|
+
`)}getDataset(t){return this.datasets.get(t)}listDatasets(){return Array.from(this.datasets.values())}generateId(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}}function ht(e){return new Ke(e)}function pt({service:e,className:t,style:r}){const{t:s}=pe.useNiceTranslation(),[i,o]=h.useState([]),[a,l]=h.useState(null),[c,u]=h.useState("data"),x=h.useCallback(()=>{o(e.listDatasets())},[e]),y=h.useMemo(()=>i.find(m=>m.id===a),[i,a]),f=async m=>{var q;const M=(q=m.target.files)==null?void 0:q[0];if(!M)return;const E=await M.text();M.name.endsWith(".csv")?await e.importCSV(E,{name:M.name}):M.name.endsWith(".json")&&await e.importJSON(E,{name:M.name}),x()};return n.jsxs("div",{className:t,style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:"'Inter', sans-serif",...r},children:[n.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--nice-border, #e0e0e0)",display:"flex",gap:"12px",alignItems:"center"},children:[n.jsxs("label",{style:{padding:"8px 16px",backgroundColor:"var(--nice-primary-hover, #1976d2)",color:"white",borderRadius:"4px",cursor:"pointer"},children:[s("dataAnalysis.importData","Import Data"),n.jsx("input",{type:"file",accept:".csv,.json",onChange:f,style:{display:"none"}})]}),n.jsxs("select",{value:a||"",onChange:m=>l(m.target.value||null),style:{padding:"8px 12px",borderRadius:"4px",border:"1px solid var(--nice-border, #ddd)"},children:[n.jsx("option",{value:"",children:s("dataAnalysis.selectDataset","Select dataset...")}),i.map(m=>n.jsx("option",{value:m.id,children:s("dataAnalysis.rows","{name} ({rowCount} rows)").replace("{name}",String(m.name)).replace("{rowCount}",String(m.rowCount))},m.id))]}),y&&n.jsx("div",{style:{marginLeft:"auto",display:"flex",gap:"8px"},children:["data","stats","analysis"].map(m=>n.jsx("button",{onClick:()=>u(m),style:{padding:"8px 16px",backgroundColor:c===m?"var(--nice-primary-hover, #1976d2)":"transparent",color:c===m?"white":"var(--nice-text, #333)",border:"1px solid var(--nice-border, #ddd)",borderRadius:"4px",cursor:"pointer",textTransform:"capitalize"},children:m},m))})]}),n.jsx("div",{style:{flex:1,overflow:"auto",padding:"16px"},children:y?c==="data"?n.jsx(xt,{dataset:y}):c==="stats"?n.jsx(ft,{dataset:y}):n.jsx(yt,{dataset:y,service:e}):n.jsx("div",{style:{textAlign:"center",color:"var(--nice-text-secondary, #666)",padding:"48px"},children:n.jsx("div",{style:{fontSize:"18px"},children:s("dataAnalysis.importADatasetOrSelect","Import a dataset or select an existing one to begin")})})})]})}function xt({dataset:e}){const{t}=pe.useNiceTranslation(),[r,s]=h.useState(0),i=50,o=Math.ceil(e.rowCount/i),a=e.data.slice(r*i,(r+1)*i);return n.jsxs("div",{children:[n.jsx("div",{style:{overflowX:"auto",marginBottom:"16px"},children:n.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{backgroundColor:"var(--nice-bg-secondary, #f5f5f5)"},children:[n.jsx("th",{style:{padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)",textAlign:"left"},children:"#"}),e.columns.map(l=>n.jsxs("th",{style:{padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)",textAlign:"left"},children:[l.name,n.jsx("div",{style:{fontSize:"10px",color:"var(--nice-text-secondary, #666)",fontWeight:"normal"},children:l.type})]},l.name))]})}),n.jsx("tbody",{children:a.map((l,c)=>n.jsxs("tr",{children:[n.jsx("td",{style:{padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)",color:"var(--nice-text-secondary, #666)"},children:r*i+c+1}),e.columns.map(u=>n.jsx("td",{style:{padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)"},children:l[u.name]!=null?String(l[u.name]):n.jsx("span",{style:{color:"var(--nice-text-secondary, #ccc)"},children:t("dataAnalysis.null","null")})},u.name))]},c))})]})}),n.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center",justifyContent:"center"},children:[n.jsx("button",{onClick:()=>s(0),disabled:r===0,children:t("dataAnalysis.first","First")}),n.jsx("button",{onClick:()=>s(r-1),disabled:r===0,children:t("dataAnalysis.prev","Prev")}),n.jsx("span",{children:t("dataAnalysis.pageOf","Page {page} of {totalPages}").replace("{page}",String(r+1)).replace("{totalPages}",String(o))}),n.jsx("button",{onClick:()=>s(r+1),disabled:r>=o-1,children:t("dataAnalysis.next","Next")}),n.jsx("button",{onClick:()=>s(o-1),disabled:r>=o-1,children:t("dataAnalysis.last","Last")})]})]})}function ft({dataset:e}){const t=e.columns.filter(r=>r.type==="number");return n.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(300px, 1fr))",gap:"16px"},children:t.map(r=>n.jsxs("div",{style:{padding:"16px",backgroundColor:"var(--nice-bg-secondary, #f9f9f9)",borderRadius:"8px"},children:[n.jsx("h3",{style:{margin:"0 0 12px 0"},children:r.name}),r.stats&&n.jsx("table",{style:{width:"100%",fontSize:"13px"},children:n.jsx("tbody",{children:Object.entries(r.stats).map(([s,i])=>n.jsxs("tr",{children:[n.jsx("td",{style:{padding:"4px 0",color:"var(--nice-text-secondary, #666)"},children:s}),n.jsx("td",{style:{padding:"4px 0",textAlign:"right",fontFamily:"monospace"},children:typeof i=="number"?i.toFixed(4):String(i)})]},s))})})]},r.name))})}function yt({dataset:e,service:t}){const{t:r}=pe.useNiceTranslation(),[s,i]=h.useState("descriptive"),[o,a]=h.useState(null),l=()=>{const c=t.runAnalysis(e.id,s,{});a(c)};return n.jsxs("div",{children:[n.jsxs("div",{style:{display:"flex",gap:"12px",marginBottom:"24px"},children:[n.jsxs("select",{value:s,onChange:c=>i(c.target.value),style:{padding:"8px 12px",borderRadius:"4px",border:"1px solid var(--nice-border, #ddd)"},children:[n.jsx("option",{value:"descriptive",children:r("dataAnalysis.descriptiveStatistics","Descriptive Statistics")}),n.jsx("option",{value:"correlation",children:r("dataAnalysis.correlationMatrix","Correlation Matrix")}),n.jsx("option",{value:"distribution",children:r("dataAnalysis.distributionAnalysis","Distribution Analysis")})]}),n.jsx("button",{onClick:l,style:{padding:"8px 16px",backgroundColor:"var(--nice-primary-hover, #1976d2)",color:"white",border:"none",borderRadius:"4px",cursor:"pointer"},children:r("dataAnalysis.runAnalysis","Run Analysis")})]}),o&&n.jsxs("div",{style:{padding:"16px",backgroundColor:"var(--nice-bg-secondary, #f9f9f9)",borderRadius:"8px"},children:[n.jsx("h3",{style:{margin:"0 0 12px 0"},children:r("dataAnalysis.resultsMs","Results ({executionTimeMs}ms)").replace("{executionTimeMs}",String(o.executionTimeMs.toFixed(2)))}),n.jsx("pre",{style:{margin:0,overflow:"auto",fontSize:"12px"},children:JSON.stringify(o.result,null,2)})]})]})}const Le={apa:e=>{const t=mt(e.authors),r=e.year?` (${e.year}).`:".",s=e.title;let i="";e.type==="article"&&e.journal?(i=` *${e.journal}*`,e.volume&&(i+=`, *${e.volume}*`),e.issue&&(i+=`(${e.issue})`),e.pages&&(i+=`, ${e.pages}`),i+="."):e.type==="book"&&(i=e.publisher?` ${e.publisher}.`:"");const o=e.doi?` https://doi.org/${e.doi}`:"";return`${t}${r} ${s}.${i}${o}`},mla:e=>{const t=Ze(e.authors),r=`"${e.title}."`;let s="";return e.type==="article"&&e.journal&&(s=` *${e.journal}*`,e.volume&&(s+=`, vol. ${e.volume}`),e.issue&&(s+=`, no. ${e.issue}`),e.year&&(s+=`, ${e.year}`),e.pages&&(s+=`, pp. ${e.pages}`),s+="."),`${t} ${r}${s}`},chicago:e=>{const t=gt(e.authors),r=`"${e.title}."`;let s="";return e.type==="article"&&e.journal&&(s=` *${e.journal}*`,e.volume&&(s+=` ${e.volume}`),e.issue&&(s+=`, no. ${e.issue}`),e.year&&(s+=` (${e.year})`),e.pages&&(s+=`: ${e.pages}`),s+="."),`${t} ${r}${s}`},harvard:e=>{const t=bt(e.authors),r=e.year?` (${e.year})`:"",s=`'${e.title}'`;let i="";return e.type==="article"&&e.journal&&(i=`, *${e.journal}*`,e.volume&&(i+=`, ${e.volume}`),e.issue&&(i+=`(${e.issue})`),e.pages&&(i+=`, pp. ${e.pages}`),i+="."),`${t}${r} ${s}${i}`},ieee:e=>{const t=vt(e.authors),r=`"${e.title},"`;let s="";return e.type==="article"&&e.journal&&(s=` *${e.journal}*`,e.volume&&(s+=`, vol. ${e.volume}`),e.issue&&(s+=`, no. ${e.issue}`),e.pages&&(s+=`, pp. ${e.pages}`),e.year&&(s+=`, ${e.year}`),s+="."),`${t} ${r}${s}`},vancouver:e=>{const t=jt(e.authors),r=e.title;let s="";return e.type==="article"&&e.journal&&(s=` ${e.journal}`,e.year&&(s+=`. ${e.year}`),e.volume&&(s+=`;${e.volume}`),e.issue&&(s+=`(${e.issue})`),e.pages&&(s+=`:${e.pages}`),s+="."),`${t}. ${r}.${s}`},nature:e=>{const t=Je(e.authors),r=e.title;let s="";return e.type==="article"&&e.journal&&(s=` *${e.journal}*`,e.volume&&(s+=` **${e.volume}**`),e.pages&&(s+=`, ${e.pages}`),e.year&&(s+=` (${e.year})`),s+="."),`${t} ${r}.${s}`},science:e=>{const t=$t(e.authors),r=e.title;let s="";return e.type==="article"&&e.journal&&(s=` *${e.journal}*`,e.volume&&(s+=` **${e.volume}**`),e.pages&&(s+=`, ${e.pages}`),e.year&&(s+=` (${e.year})`),s+="."),`${t}, ${r}.${s}`},bibtex:e=>{const t=Mt(e),r=e.type==="article"?"article":e.type==="book"?"book":"misc";let i=` author = {${e.authors.map(o=>`${o.family}, ${o.given}`).join(" and ")}},
|
|
45
45
|
`;return i+=` title = {${e.title}},
|
|
46
46
|
`,e.year&&(i+=` year = {${e.year}},
|
|
47
47
|
`),e.journal&&(i+=` journal = {${e.journal}},
|
|
@@ -52,21 +52,22 @@
|
|
|
52
52
|
`),e.doi&&(i+=` doi = {${e.doi}},
|
|
53
53
|
`),e.isbn&&(i+=` isbn = {${e.isbn}},
|
|
54
54
|
`),`@${r}{${t},
|
|
55
|
-
${i}}`}};function
|
|
55
|
+
${i}}`}};function mt(e){if(e.length===0)return"";if(e.length===1)return`${e[0].family}, ${e[0].given.charAt(0)}.`;if(e.length===2)return`${e[0].family}, ${e[0].given.charAt(0)}., & ${e[1].family}, ${e[1].given.charAt(0)}.`;if(e.length<=7){const s=e.slice(0,-1).map(o=>`${o.family}, ${o.given.charAt(0)}.`).join(", "),i=e[e.length-1];return`${s}, & ${i.family}, ${i.given.charAt(0)}.`}const t=e.slice(0,6).map(s=>`${s.family}, ${s.given.charAt(0)}.`).join(", "),r=e[e.length-1];return`${t}, ... ${r.family}, ${r.given.charAt(0)}.`}function Ze(e){return e.length===0?"":e.length===1?`${e[0].family}, ${e[0].given}.`:e.length===2?`${e[0].family}, ${e[0].given}, and ${e[1].given} ${e[1].family}.`:`${e[0].family}, ${e[0].given}, et al.`}function gt(e){return Ze(e)}function bt(e){return e.length===0?"":e.length===1?`${e[0].family}, ${e[0].given.charAt(0)}.`:e.length===2?`${e[0].family}, ${e[0].given.charAt(0)}. and ${e[1].family}, ${e[1].given.charAt(0)}.`:`${e[0].family}, ${e[0].given.charAt(0)}. et al.`}function vt(e){return e.length===0?"":e.map(t=>`${t.given.charAt(0)}. ${t.family}`).join(", ")}function jt(e){if(e.length===0)return"";const t=e.slice(0,6).map(r=>`${r.family} ${r.given.charAt(0)}`);return e.length>6?t.join(", ")+", et al":t.join(", ")}function Je(e){if(e.length===0)return"";if(e.length<=5){const t=e.map(s=>`${s.family}, ${s.given.charAt(0)}.`),r=t.pop();return t.length>0?`${t.join(", ")} & ${r}`:r}return`${e[0].family}, ${e[0].given.charAt(0)}. et al.`}function $t(e){return Je(e)}function Mt(e){var i;const t=((i=e.authors[0])==null?void 0:i.family.toLowerCase())||"unknown",r=e.year||"0000",s=e.title.split(" ")[0].toLowerCase().replace(/[^a-z]/g,"");return`${t}${r}${s}`}class Ge{constructor(t={}){Se(this,"config");Se(this,"citations",new Map);Se(this,"collections",new Map);this.config=t,this.collections.set("all",{id:"all",name:"All References",citationCount:0,createdAt:new Date().toISOString()})}addCitation(t){const r={id:this.generateId(),type:t.type||"misc",title:t.title||"Untitled",authors:t.authors||[],year:t.year,month:t.month,day:t.day,journal:t.journal,volume:t.volume,issue:t.issue,pages:t.pages,publisher:t.publisher,edition:t.edition,doi:t.doi,isbn:t.isbn,issn:t.issn,pmid:t.pmid,arxiv:t.arxiv,url:t.url,abstract:t.abstract,keywords:t.keywords,language:t.language,accessed:t.accessed,booktitle:t.booktitle,conference:t.conference,location:t.location,school:t.school,degree:t.degree,notes:t.notes,tags:t.tags||[],collections:t.collections||["all"],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),sourceDatabase:t.sourceDatabase};return this.citations.set(r.id,r),this.updateCollectionCounts(),r}updateCitation(t,r){const s=this.citations.get(t);if(!s)throw new Error(`Citation not found: ${t}`);const i={...s,...r,id:s.id,createdAt:s.createdAt,updatedAt:new Date().toISOString()};return this.citations.set(t,i),this.updateCollectionCounts(),i}deleteCitation(t){this.citations.delete(t),this.updateCollectionCounts()}getCitation(t){return this.citations.get(t)}searchCitations(t,r){const s=t.toLowerCase();return Array.from(this.citations.values()).filter(i=>{var o,a,l,c,u;return r!=null&&r.collection&&!((o=i.collections)!=null&&o.includes(r.collection))||r!=null&&r.type&&i.type!==r.type||r!=null&&r.year&&i.year!==r.year||(a=r==null?void 0:r.tags)!=null&&a.length&&!r.tags.some(x=>{var y;return(y=i.tags)==null?void 0:y.includes(x)})?!1:!!(i.title.toLowerCase().includes(s)||i.authors.some(x=>x.family.toLowerCase().includes(s)||x.given.toLowerCase().includes(s))||(l=i.journal)!=null&&l.toLowerCase().includes(s)||(c=i.abstract)!=null&&c.toLowerCase().includes(s)||(u=i.doi)!=null&&u.toLowerCase().includes(s))})}listCitations(t){const r=Array.from(this.citations.values());return t&&t!=="all"?r.filter(s=>{var i;return(i=s.collections)==null?void 0:i.includes(t)}):r}createCollection(t){const r={id:this.generateId(),name:t.name||"Untitled Collection",description:t.description,parentId:t.parentId,color:t.color,citationCount:0,createdAt:new Date().toISOString()};return this.collections.set(r.id,r),r}listCollections(){return Array.from(this.collections.values())}formatCitation(t,r){const s=this.citations.get(t);if(!s)throw new Error(`Citation not found: ${t}`);return Le[r](s)}formatBibliography(t,r){return t.map((i,o)=>{const a=this.citations.get(i);if(!a)return null;const l=Le[r](a);return r==="bibtex"?l:["ieee","vancouver"].includes(r)?`[${o+1}] ${l}`:l}).filter(Boolean).join(`
|
|
56
56
|
|
|
57
|
-
`)}importBibtex(t){const r=[],s=/@(\w+)\{([^,]+),([^@]+)\}/g;let i;for(;(i=s.exec(t))!==null;){const o=i[1].toLowerCase(),a=this.parseBibtexFields(i[3]),l=this.addCitation({type:o==="article"?"article":o==="book"?"book":"misc",title:a.title||"",authors:this.parseBibtexAuthors(a.author||""),year:a.year?parseInt(a.year,10):void 0,journal:a.journal,volume:a.volume,issue:a.number,pages:a.pages,publisher:a.publisher,doi:a.doi,isbn:a.isbn,url:a.url,abstract:a.abstract});r.push(l)}return r}parseBibtexFields(t){const r={},s=/(\w+)\s*=\s*\{([^}]*)\}/g;let i;for(;(i=s.exec(t))!==null;)r[i[1].toLowerCase()]=i[2].trim();return r}parseBibtexAuthors(t){return t.split(" and ").map(r=>{const s=r.trim().split(",");if(s.length>=2)return{family:s[0].trim(),given:s[1].trim()};const i=r.trim().split(" ");return{given:i.slice(0,-1).join(" "),family:i[i.length-1]}})}exportBibtex(t){return(t?t.map(s=>this.citations.get(s)).filter(Boolean):Array.from(this.citations.values())).map(s=>
|
|
57
|
+
`)}importBibtex(t){const r=[],s=/@(\w+)\{([^,]+),([^@]+)\}/g;let i;for(;(i=s.exec(t))!==null;){const o=i[1].toLowerCase(),a=this.parseBibtexFields(i[3]),l=this.addCitation({type:o==="article"?"article":o==="book"?"book":"misc",title:a.title||"",authors:this.parseBibtexAuthors(a.author||""),year:a.year?parseInt(a.year,10):void 0,journal:a.journal,volume:a.volume,issue:a.number,pages:a.pages,publisher:a.publisher,doi:a.doi,isbn:a.isbn,url:a.url,abstract:a.abstract});r.push(l)}return r}parseBibtexFields(t){const r={},s=/(\w+)\s*=\s*\{([^}]*)\}/g;let i;for(;(i=s.exec(t))!==null;)r[i[1].toLowerCase()]=i[2].trim();return r}parseBibtexAuthors(t){return t.split(" and ").map(r=>{const s=r.trim().split(",");if(s.length>=2)return{family:s[0].trim(),given:s[1].trim()};const i=r.trim().split(" ");return{given:i.slice(0,-1).join(" "),family:i[i.length-1]}})}exportBibtex(t){return(t?t.map(s=>this.citations.get(s)).filter(Boolean):Array.from(this.citations.values())).map(s=>Le.bibtex(s)).join(`
|
|
58
58
|
|
|
59
|
-
`)}async searchDatabase(t,r,s=10){var i,o;try{if(t==="crossref")return await this.searchCrossref(r,s);if(t==="pubmed")return await this.searchPubMed(r,s);throw new Error(`Unknown database: ${t}`)}catch(a){return(o=(i=this.config).onError)==null||o.call(i,a),{source:t,total:0,results:[]}}}async searchCrossref(t,r){const s=new URLSearchParams({query:t,rows:String(r)});this.config.crossrefEmail&&s.set("mailto",this.config.crossrefEmail);const i=await fetch(`https://api.crossref.org/works?${s}`);if(!i.ok)throw new Error(`Crossref API error: ${i.status}`);const o=await i.json(),a=o.message.items.map(l=>{var c,u,x,m,f,g;return{type:"article",title:((c=l.title)==null?void 0:c[0])||"",authors:(l.author||[]).map(M=>({given:M.given||"",family:M.family||"",orcid:M.ORCID})),year:(m=(x=(u=l.published)==null?void 0:u["date-parts"])==null?void 0:x[0])==null?void 0:m[0],journal:(f=l["container-title"])==null?void 0:f[0],volume:l.volume,issue:l.issue,pages:l.page,doi:l.DOI,issn:(g=l.ISSN)==null?void 0:g[0],publisher:l.publisher,abstract:l.abstract,sourceDatabase:"crossref"}});return{source:"crossref",total:o.message["total-results"],results:a}}async searchPubMed(t,r){const s=`https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=${encodeURIComponent(t)}&retmax=${r}&retmode=json`,i=await fetch(s);if(!i.ok)throw new Error(`PubMed API error: ${i.status}`);const o=await i.json(),a=o.esearchresult.idlist;if(a.length===0)return{source:"pubmed",total:0,results:[]};const l=`https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=${a.join(",")}&retmode=json`,c=await fetch(l);if(!c.ok)throw new Error(`PubMed API error: ${c.status}`);const u=await c.json(),x=a.map(m=>{var g;const f=u.result[m];return{type:"article",title:f.title||"",authors:(f.authors||[]).map(M=>{const E=M.name.split(" ");return{family:E.pop()||"",given:E.join(" ")}}),year:f.pubdate?parseInt(f.pubdate.split(" ")[0],10):void 0,journal:f.source,volume:f.volume,issue:f.issue,pages:f.pages,pmid:m,doi:(g=f.elocationid)==null?void 0:g.replace("doi: ",""),sourceDatabase:"pubmed"}});return{source:"pubmed",total:parseInt(o.esearchresult.count,10),results:x}}async fetchByDOI(t){var r,s,i,o,a;try{const l=await fetch(`https://api.crossref.org/works/${encodeURIComponent(t)}`);if(!l.ok)return null;const u=(await l.json()).message;return this.addCitation({type:"article",title:((r=u.title)==null?void 0:r[0])||"",authors:(u.author||[]).map(x=>({given:x.given||"",family:x.family||"",orcid:x.ORCID})),year:(o=(i=(s=u.published)==null?void 0:s["date-parts"])==null?void 0:i[0])==null?void 0:o[0],journal:(a=u["container-title"])==null?void 0:a[0],volume:u.volume,issue:u.issue,pages:u.page,doi:u.DOI,publisher:u.publisher,abstract:u.abstract,sourceDatabase:"crossref"})}catch{return null}}updateCollectionCounts(){for(const t of this.collections.values())t.id==="all"?t.citationCount=this.citations.size:t.citationCount=Array.from(this.citations.values()).filter(r=>{var s;return(s=r.collections)==null?void 0:s.includes(t.id)}).length}generateId(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}}function St(e){return new Ge(e)}const Qe=h.createContext(null);function Le(){const e=h.useContext(Qe);if(!e)throw new Error("useCitation must be used within CitationProvider");return e}const he={container:{display:"flex",height:"100%",fontFamily:"'Inter', sans-serif",fontSize:"14px"},sidebar:{width:"240px",backgroundColor:"var(--nice-bg-secondary, #f5f5f5)",borderRight:"1px solid var(--nice-border, #e0e0e0)",display:"flex",flexDirection:"column"},main:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},toolbar:{padding:"12px 16px",borderBottom:"1px solid var(--nice-border, #e0e0e0)",display:"flex",gap:"12px",alignItems:"center"},list:{flex:1,overflow:"auto"},listItem:{padding:"12px 16px",borderBottom:"1px solid var(--nice-border, #eee)",cursor:"pointer"},detail:{width:"400px",borderLeft:"1px solid var(--nice-border, #e0e0e0)",overflow:"auto",padding:"16px"},input:{padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)",borderRadius:"4px",fontSize:"14px"},button:{padding:"8px 16px",backgroundColor:"var(--nice-primary-hover, #1976d2)",color:"white",border:"none",borderRadius:"4px",cursor:"pointer"}};function wt({service:e,className:t,style:r}){const{t:s}=pe.useNiceTranslation(),[i,o]=h.useState([]),[a,l]=h.useState([]),[c,u]=h.useState("all"),[x,m]=h.useState(null),[f,g]=h.useState(""),[M,E]=h.useState("apa"),Y=h.useCallback(()=>{o(e.listCitations(c)),l(e.listCollections())},[e,c]),H=h.useMemo(()=>f?e.searchCitations(f,{collection:c}):i,[i,f,c,e]),P=h.useMemo(()=>i.find(R=>R.id===x),[i,x]),G={service:e,citations:i,collections:a,selectedCollection:c,setSelectedCollection:u,selectedCitation:x,setSelectedCitation:m,searchQuery:f,setSearchQuery:g,citationStyle:M,setCitationStyle:E,refresh:Y};return n.jsx(Qe.Provider,{value:G,children:n.jsxs("div",{className:t,style:{...he.container,...r},children:[n.jsxs("div",{style:he.sidebar,children:[n.jsx("div",{style:{padding:"16px",fontWeight:600},children:s("citation.collections","Collections")}),a.map(R=>n.jsxs("div",{onClick:()=>{u(R.id),Y()},style:{...he.listItem,backgroundColor:c===R.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsx("div",{children:R.name}),n.jsx("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:s("citation.items","{citationCount} items").replace("{citationCount}",String(R.citationCount))})]},R.id))]}),n.jsxs("div",{style:he.main,children:[n.jsxs("div",{style:he.toolbar,children:[n.jsx("input",{type:"text",placeholder:s("citation.searchReferences","Search references..."),value:f,onChange:R=>g(R.target.value),style:{...he.input,flex:1}}),n.jsxs("select",{value:M,onChange:R=>E(R.target.value),style:he.input,children:[n.jsx("option",{value:"apa",children:s("citation.apa","APA")}),n.jsx("option",{value:"mla",children:s("citation.mla","MLA")}),n.jsx("option",{value:"chicago",children:s("citation.chicago","Chicago")}),n.jsx("option",{value:"harvard",children:s("citation.harvard","Harvard")}),n.jsx("option",{value:"ieee",children:s("citation.ieee","IEEE")}),n.jsx("option",{value:"vancouver",children:s("citation.vancouver","Vancouver")}),n.jsx("option",{value:"bibtex",children:"BibTeX"})]}),n.jsx(kt,{})]}),n.jsxs("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[n.jsxs("div",{style:he.list,children:[H.map(R=>n.jsxs("div",{onClick:()=>m(R.id),style:{...he.listItem,backgroundColor:x===R.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsx("div",{style:{fontWeight:500,marginBottom:"4px"},children:R.title}),n.jsxs("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:[R.authors.map(ne=>ne.family).join(", "),R.year&&` (${R.year})`]}),R.journal&&n.jsx("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #888)",fontStyle:"italic"},children:R.journal})]},R.id)),H.length===0&&n.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--nice-text-secondary, #666)"},children:s("citation.noReferencesFound","No references found")})]}),P&&n.jsx("div",{style:he.detail,children:n.jsx(Ct,{citation:P})})]})]})]})})}function kt(){const{t:e}=pe.useNiceTranslation(),{service:t,refresh:r}=Le(),[s,i]=h.useState(!1),[o,a]=h.useState(""),[l,c]=h.useState(!1),u=async()=>{if(o.trim()){c(!0);try{await t.fetchByDOI(o.trim()),r(),a(""),i(!1)}finally{c(!1)}}};return n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>i(!0),style:he.button,children:e("citation.addReference","+ Add Reference")}),s&&n.jsx("div",{style:{position:"fixed",inset:0,backgroundColor:"var(--nice-overlay-50, rgba(0, 0, 0, 0.5))",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},onClick:()=>i(!1),children:n.jsxs("div",{style:{backgroundColor:"white",padding:"24px",borderRadius:"8px",width:"400px"},onClick:x=>x.stopPropagation(),children:[n.jsx("h3",{style:{margin:"0 0 16px 0"},children:e("citation.addReferenceByDoi","Add Reference by DOI")}),n.jsx("input",{type:"text",value:o,onChange:x=>a(x.target.value),placeholder:e("citation.enterDoiEG10","Enter DOI (e.g., 10.1000/xyz123)"),style:{...he.input,width:"100%",marginBottom:"16px"}}),n.jsxs("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[n.jsx("button",{onClick:()=>i(!1),style:{...he.button,backgroundColor:"var(--nice-bg-tertiary, #9e9e9e)"},children:e("citation.cancel","Cancel")}),n.jsx("button",{onClick:u,disabled:l,style:he.button,children:l?e("citation.loading","Loading..."):e("citation.add","Add")})]})]})})]})}function Ct({citation:e}){const{t}=pe.useNiceTranslation(),{service:r,citationStyle:s}=Le(),[i,o]=h.useState(!1),a=h.useMemo(()=>r.formatCitation(e.id,s),[r,e.id,s]),l=()=>{navigator.clipboard.writeText(a),o(!0),setTimeout(()=>o(!1),2e3)};return n.jsxs("div",{children:[n.jsx("h2",{style:{margin:"0 0 8px 0",fontSize:"18px"},children:e.title}),n.jsx("div",{style:{color:"var(--nice-text-secondary, #666)",marginBottom:"16px"},children:e.authors.map(c=>`${c.given} ${c.family}`).join(", ")}),n.jsxs("div",{style:{marginBottom:"16px"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"8px"},children:[n.jsx("strong",{children:t("citation.formatted","Formatted ({citationStyle})").replace("{citationStyle}",String(s.toUpperCase()))}),n.jsx("button",{onClick:l,style:{...he.button,padding:"4px 8px",fontSize:"12px"},children:i?t("citation.copied","Copied!"):t("citation.copy","Copy")})]}),n.jsx("div",{style:{padding:"12px",backgroundColor:"var(--nice-bg-secondary, #f5f5f5)",borderRadius:"4px",whiteSpace:"pre-wrap",fontSize:"13px"},dangerouslySetInnerHTML:{__html:a.replace(/\*([^*]+)\*/g,"<em>$1</em>")}})]}),n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px",fontSize:"13px"},children:[e.journal&&n.jsxs("div",{children:[n.jsx("strong",{children:t("citation.journal","Journal:")})," ",e.journal]}),e.year&&n.jsxs("div",{children:[n.jsx("strong",{children:t("citation.year","Year:")})," ",e.year]}),e.volume&&n.jsxs("div",{children:[n.jsx("strong",{children:t("citation.volume","Volume:")})," ",e.volume,e.issue&&`(${e.issue})`]}),e.pages&&n.jsxs("div",{children:[n.jsx("strong",{children:t("citation.pages","Pages:")})," ",e.pages]}),e.doi&&n.jsxs("div",{children:[n.jsx("strong",{children:t("citation.doi","DOI:")})," ",n.jsx("a",{href:`https://doi.org/${e.doi}`,target:"_blank",rel:"noopener noreferrer",children:e.doi})]}),e.pmid&&n.jsxs("div",{children:[n.jsx("strong",{children:t("citation.pmid","PMID:")})," ",n.jsx("a",{href:`https://pubmed.ncbi.nlm.nih.gov/${e.pmid}`,target:"_blank",rel:"noopener noreferrer",children:e.pmid})]}),e.abstract&&n.jsxs("div",{style:{marginTop:"8px"},children:[n.jsx("strong",{children:t("citation.abstract","Abstract:")}),n.jsx("p",{style:{margin:"8px 0 0 0",color:"var(--nice-text, #444)"},children:e.abstract})]})]})]})}const Nt=[],At={series:[],xAxes:[],yAxes:[],annotations:[],selectedSeries:[],zoom:{x:null,y:null},cursor:null,hoveredPoint:null};function Ce(e){return e.reduce((t,r)=>t+r,0)/e.length}function Dt(e){const t=[...e].sort((s,i)=>s-i),r=Math.floor(t.length/2);return t.length%2?t[r]:(t[r-1]+t[r])/2}function Ee(e){const t=Ce(e),r=e.map(s=>Math.pow(s-t,2));return Math.sqrt(Ce(r))}function zt(e){return Ee(e)/Math.sqrt(e.length)}function It(e){const t=Ce(e),r=zt(e),s=1.96;return[t-s*r,t+s*r]}function Et(e){const t=e.length,r=e.map(M=>typeof M.x=="number"?M.x:0),s=e.map(M=>M.y),i=r.reduce((M,E)=>M+E,0),o=s.reduce((M,E)=>M+E,0),a=r.reduce((M,E,Y)=>M+E*s[Y],0),l=r.reduce((M,E)=>M+E*E,0),c=(t*a-i*o)/(t*l-i*i),u=(o-c*i)/t,x=o/t,m=s.reduce((M,E)=>M+Math.pow(E-x,2),0),g=1-s.reduce((M,E,Y)=>M+Math.pow(E-(c*r[Y]+u),2),0)/m;return{slope:c,intercept:u,r2:g}}function Ft(e,t){const r=Ce(e),s=Ce(t),i=Ee(e)**2,o=Ee(t)**2,a=e.length,l=t.length,c=((a-1)*i+(l-1)*o)/(a+l-2),u=Math.sqrt(c*(1/a+1/l)),x=(r-s)/u,m=Math.exp(-.717*Math.abs(x)-.416*x*x);return{t:x,p:m,significant:m<.05}}function Oe(e,t,r,s=5){const o=(t-e)/(s-1);return Array.from({length:s},(a,l)=>e+l*o)}function We(e,t){return Math.abs(e)>=1e6?(e/1e6).toFixed(1)+"M":Math.abs(e)>=1e3?(e/1e3).toFixed(1)+"K":Math.abs(e)<.01?e.toExponential(2):e.toFixed(2).replace(/\.?0+$/,"")}function Bt({series:e=Nt,title:t,subtitle:r,width:s="100%",height:i=400,type:o="scatter",xAxis:a,yAxis:l,statOverlays:c=[],annotations:u=[],legend:x={show:!0,position:"top",orientation:"horizontal",interactive:!0},tooltip:m={enabled:!0,mode:"point"},zoom:f={enabled:!0,mode:"xy",wheel:!0,drag:!0,resetButton:!0},export:g,statisticalTests:M=[],gridLines:E=!0,aspectRatio:Y,animation:H=!0,theme:P="light",onPointClick:G,onPointHover:R,onZoomChange:ne,onAnnotationChange:ce,className:Z,style:ue}){const{t:ee}=pe.useNiceTranslation(),J=h.useRef(null);h.useRef(null);const[se,X]=h.useState({...At,series:e,annotations:u}),[te,de]=h.useState({width:0,height:0}),[me,oe]=h.useState({x:null,y:null}),[W,q]=h.useState(null),[ae,U]=h.useState(new Set(e.map(d=>d.id))),w=h.useMemo(()=>{const d=e.filter($=>ae.has($.id)&&$.visible!==!1);if(d.length===0)return{xMin:0,xMax:1,yMin:0,yMax:1};let b=1/0,S=-1/0,I=1/0,z=-1/0;for(const $ of d)for(const N of $.data){const _=typeof N.x=="number"?N.x:0;if(b=Math.min(b,_),S=Math.max(S,_),I=Math.min(I,N.y),z=Math.max(z,N.y),N.error){const[O,le]=Array.isArray(N.error)?N.error:[-N.error,N.error];I=Math.min(I,N.y+O),z=Math.max(z,N.y+le)}}const T=(S-b)*.05||.5,y=(z-I)*.05||.5;return{xMin:b-T,xMax:S+T,yMin:I-y,yMax:z+y}},[e,ae]),K=h.useMemo(()=>{const d={};for(const b of e){if(!ae.has(b.id))continue;const S=b.data.map(I=>I.y);c.includes("mean")&&(d[`${b.id}_mean`]=Ce(S)),c.includes("median")&&(d[`${b.id}_median`]=Dt(S)),c.includes("std-dev")&&(d[`${b.id}_std`]=Ee(S)),c.includes("regression")&&(d[`${b.id}_regression`]=Et(b.data)),c.includes("confidence-interval")&&(d[`${b.id}_ci95`]=It(S))}return d},[e,ae,c]),Q=h.useMemo(()=>M.map(d=>{if(d.type==="t-test"&&d.series.length===2){const b=e.find(I=>I.id===d.series[0]),S=e.find(I=>I.id===d.series[1]);if(b&&S){const I=Ft(b.data.map(z=>z.y),S.data.map(z=>z.y));return{...d,result:{statistic:I.t,pValue:I.p,significant:I.significant,interpretation:I.significant?`Significant difference (p = ${I.p.toFixed(4)})`:`No significant difference (p = ${I.p.toFixed(4)})`}}}}return d}),[M,e]),re=h.useCallback(d=>{U(b=>{const S=new Set(b);return S.has(d)?S.delete(d):S.add(d),S})},[]),ie=h.useCallback(()=>{oe({x:null,y:null}),ne==null||ne(null,null)},[ne]),A=h.useMemo(()=>{switch(P){case"dark":return["var(--nice-primary-light, #60a5fa)","var(--nice-color-accent-pink, #f472b6)","var(--nice-success-light, #34d399)","var(--nice-warning-light, #fbbf24)","var(--nice-accent, #a78bfa)","#fb923c"];case"publication":return["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b"];case"presentation":return["var(--nice-primary, #3b82f6)","var(--nice-danger, #ef4444)","var(--nice-success, #22c55e)","var(--nice-warning, #f59e0b)","var(--nice-accent, #8b5cf6)","var(--nice-color-accent-pink, #ec4899)"];default:return["var(--nice-primary-hover, #2563eb)","var(--nice-danger-dark, #dc2626)","var(--nice-success-dark, #16a34a)","#ca8a04","var(--nice-accent, #7c3aed)","var(--nice-color-accent-pink, #db2777)"]}},[P]),k=h.useMemo(()=>{switch(P){case"dark":return{bg:"var(--nice-bg-secondary, #1f2937)",text:"var(--nice-text-primary, #f3f4f6)",grid:"var(--nice-text, #374151)",axis:"var(--nice-text-muted, #9ca3af)",tooltip:"var(--nice-text, #374151)"};case"publication":return{bg:"var(--nice-bg, #fff)",text:"var(--nice-text, #000000)",grid:"var(--nice-border, #e5e5e5)",axis:"var(--nice-text, #333333)",tooltip:"var(--nice-bg, #fff)"};default:return{bg:"var(--nice-bg, #fff)",text:"var(--nice-text, #1f2937)",grid:"var(--nice-border, #e5e7eb)",axis:"var(--nice-text-secondary, #4b5563)",tooltip:"var(--nice-bg, #fff)"}}},[P]);return n.jsxs("div",{ref:J,className:`nice-scientific-chart nice-scientific-chart--${P} ${Z||""}`,style:{width:s,height:Y?"auto":i,aspectRatio:Y==null?void 0:Y.toString(),backgroundColor:k.bg,color:k.text,fontFamily:P==="publication"?"Times New Roman, serif":"system-ui, sans-serif",...ue},children:[t&&n.jsxs("div",{className:"nice-scientific-chart__title",children:[t,r&&n.jsx("div",{className:"nice-scientific-chart__subtitle",style:{color:k.axis},children:r})]}),x.show&&n.jsx("div",{className:"nice-scientific-chart__legend",style:{flexDirection:x.orientation==="vertical"?"column":"row"},children:e.map((d,b)=>n.jsxs("button",{type:"button",className:"nice-scientific-chart__legend-item",onClick:()=>x.interactive&&re(d.id),style:{cursor:x.interactive?"pointer":"default",opacity:ae.has(d.id)?1:.4},children:[n.jsx("span",{className:"nice-scientific-chart__swatch",style:{backgroundColor:d.color||A[b%A.length]}}),d.name]},d.id))}),n.jsxs("div",{className:"nice-scientific-chart__canvas",children:[n.jsxs("svg",{width:"100%",height:"100%",children:[E&&n.jsxs("g",{className:"nice-scientific-chart__grid",stroke:k.grid,strokeWidth:1,children:[[0,.25,.5,.75,1].map(d=>n.jsx("line",{x1:"10%",y1:`${d*100}%`,x2:"95%",y2:`${d*100}%`,strokeDasharray:"2,2"},`h-${d}`)),[0,.25,.5,.75,1].map(d=>n.jsx("line",{x1:`${10+d*85}%`,y1:"5%",x2:`${10+d*85}%`,y2:"90%",strokeDasharray:"2,2"},`v-${d}`))]}),e.filter(d=>ae.has(d.id)&&d.visible!==!1).map((d,b)=>{var z,T,y;const S=d.color||A[b%A.length],I=d.type||o;return n.jsx("g",{className:"nice-scientific-chart__series",children:I==="scatter"||I==="line"?n.jsxs(n.Fragment,{children:[I==="line"&&d.data.length>1&&n.jsx("svg",{x:"0",y:"0",width:"100%",height:"100%",viewBox:"0 0 100 100",preserveAspectRatio:"none",style:{overflow:"visible"},children:n.jsx("polyline",{fill:"none",stroke:S,strokeWidth:((z=d.line)==null?void 0:z.width)||2,vectorEffect:"non-scaling-stroke",strokeDasharray:((T=d.line)==null?void 0:T.style)==="dashed"?"5,5":((y=d.line)==null?void 0:y.style)==="dotted"?"2,2":void 0,points:d.data.map(($,N)=>{const _=10+((typeof $.x=="number"?$.x:N)-w.xMin)/(w.xMax-w.xMin)*85,O=90-($.y-w.yMin)/(w.yMax-w.yMin)*85;return`${_},${O}`}).join(" ")})}),d.data.map(($,N)=>{var xe,ge,ye,fe,$e;const _=10+((typeof $.x=="number"?$.x:N)-w.xMin)/(w.xMax-w.xMin)*85,O=90-($.y-w.yMin)/(w.yMax-w.yMin)*85,le=$.size||((xe=d.marker)==null?void 0:xe.size)||6;return n.jsxs("g",{className:"nice-scientific-chart__point",children:[$.error&&n.jsx("line",{x1:`${_}%`,y1:`${90-($.y+(Array.isArray($.error)?$.error[1]:$.error)-w.yMin)/(w.yMax-w.yMin)*85}%`,x2:`${_}%`,y2:`${90-($.y-(Array.isArray($.error)?Math.abs($.error[0]):$.error)-w.yMin)/(w.yMax-w.yMin)*85}%`,stroke:S,strokeWidth:1}),n.jsx("circle",{cx:`${_}%`,cy:`${O}%`,r:le/2,fill:$.color||((ge=d.marker)==null?void 0:ge.fillColor)||S,stroke:((ye=d.marker)==null?void 0:ye.strokeColor)||S,strokeWidth:((fe=d.marker)==null?void 0:fe.strokeWidth)||1,opacity:(($e=d.marker)==null?void 0:$e.opacity)??1,style:{cursor:G?"pointer":void 0},onMouseEnter:()=>{q({seriesId:d.id,pointIndex:N}),R==null||R($,d)},onMouseLeave:()=>{q(null),R==null||R(null,null)},onClick:Me=>G==null?void 0:G($,d,Me)})]},N)}),K[`${d.id}_regression`]&&n.jsx("line",{x1:"10%",y1:`${90-(K[`${d.id}_regression`].intercept+K[`${d.id}_regression`].slope*w.xMin-w.yMin)/(w.yMax-w.yMin)*85}%`,x2:"95%",y2:`${90-(K[`${d.id}_regression`].intercept+K[`${d.id}_regression`].slope*w.xMax-w.yMin)/(w.yMax-w.yMin)*85}%`,stroke:S,strokeWidth:1,strokeDasharray:"5,3",opacity:.7}),K[`${d.id}_mean`]&&n.jsx("line",{x1:"10%",y1:`${90-(K[`${d.id}_mean`]-w.yMin)/(w.yMax-w.yMin)*85}%`,x2:"95%",y2:`${90-(K[`${d.id}_mean`]-w.yMin)/(w.yMax-w.yMin)*85}%`,stroke:S,strokeWidth:1,strokeDasharray:"10,5",opacity:.5})]}):null},d.id)}),n.jsxs("g",{className:"nice-scientific-chart__axes",stroke:k.axis,strokeWidth:1,children:[n.jsx("line",{x1:"10%",y1:"90%",x2:"95%",y2:"90%"}),n.jsx("line",{x1:"10%",y1:"5%",x2:"10%",y2:"90%"}),Oe(w.xMin,w.xMax,"linear",6).map((d,b)=>n.jsxs("g",{children:[n.jsx("line",{x1:`${10+b*17}%`,y1:"90%",x2:`${10+b*17}%`,y2:"92%"}),n.jsx("text",{x:`${10+b*17}%`,y:"96%",textAnchor:"middle",fill:k.axis,fontSize:"0.75rem",children:We(d)})]},`x-${b}`)),Oe(w.yMin,w.yMax,"linear",6).map((d,b)=>n.jsxs("g",{children:[n.jsx("line",{x1:"8%",y1:`${90-b*17}%`,x2:"10%",y2:`${90-b*17}%`}),n.jsx("text",{x:"7%",y:`${90-b*17}%`,textAnchor:"end",dominantBaseline:"middle",fill:k.axis,fontSize:"0.75rem",children:We(d)})]},`y-${b}`))]}),u.filter(d=>d.visible!==!1).map(d=>{var b,S,I,z,T,y,$;return n.jsxs("g",{className:"nice-scientific-chart__annotation",children:[d.type==="text"&&d.text&&n.jsx("text",{x:`${10+(d.position.x-w.xMin)/(w.xMax-w.xMin)*85}%`,y:`${90-(d.position.y-w.yMin)/(w.yMax-w.yMin)*85}%`,fill:((b=d.style)==null?void 0:b.color)||k.text,fontSize:((S=d.style)==null?void 0:S.fontSize)||12,fontWeight:(I=d.style)==null?void 0:I.fontWeight,children:d.text}),d.type==="line"&&n.jsx("line",{x1:`${10+(d.position.x-w.xMin)/(w.xMax-w.xMin)*85}%`,y1:`${90-(d.position.y-w.yMin)/(w.yMax-w.yMin)*85}%`,x2:`${10+(d.position.x2-w.xMin)/(w.xMax-w.xMin)*85}%`,y2:`${90-(d.position.y2-w.yMin)/(w.yMax-w.yMin)*85}%`,stroke:((z=d.style)==null?void 0:z.color)||k.text,strokeWidth:((T=d.style)==null?void 0:T.lineWidth)||1,strokeDasharray:((y=d.style)==null?void 0:y.lineStyle)==="dashed"?"5,5":(($=d.style)==null?void 0:$.lineStyle)==="dotted"?"2,2":void 0})]},d.id)})]}),m.enabled&&W&&n.jsx("div",{className:"nice-scientific-chart__tooltip",style:{background:k.tooltip,borderColor:k.grid},children:(()=>{const d=e.find(S=>S.id===W.seriesId),b=d==null?void 0:d.data[W.pointIndex];return!d||!b?null:m.format?m.format(b,d):n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"nice-scientific-chart__tooltip-title",children:d.name}),n.jsxs("div",{children:["X: ",b.x instanceof Date?b.x.toISOString():String(b.x)]}),n.jsxs("div",{children:["Y: ",b.y.toFixed(4)]}),b.error&&n.jsx("div",{children:ee("scientificChart.error","Error: ±{error}").replace("{error}",String(Array.isArray(b.error)?`${b.error[0]}, +${b.error[1]}`:b.error))})]})})()})]}),Q.some(d=>d.result)&&n.jsxs("div",{className:"nice-scientific-chart__stats",style:{borderTopColor:k.grid},children:[n.jsx("strong",{children:ee("scientificChart.statisticalTests","Statistical Tests:")}),Q.filter(d=>d.result).map((d,b)=>n.jsxs("div",{children:[d.type,": ",d.result.interpretation]},b))]}),f.enabled&&f.resetButton&&(me.x||me.y)&&n.jsx("button",{type:"button",className:"nice-scientific-chart__reset-zoom",onClick:ie,style:{background:k.bg,borderColor:k.grid},children:ee("scientificChart.resetZoom","Reset Zoom")}),g&&g.formats.length>0&&n.jsxs("div",{className:"nice-scientific-chart__export",style:{borderTopColor:k.grid},children:[n.jsx("span",{className:"nice-scientific-chart__export-label",children:ee("scientificChart.export","Export:")}),g.formats.map(d=>n.jsx("button",{type:"button",className:"nice-scientific-chart__export-btn",style:{borderColor:k.grid},children:d.toUpperCase()},d))]})]})}const Rt=[],Xe={rotationX:25,rotationY:-45,rotationZ:0,zoom:1,panX:0,panY:0};function Tt(e,t){const r=t*Math.PI/180,s=Math.cos(r),i=Math.sin(r);return{x:e.x,y:e.y*s-e.z*i,z:e.y*i+e.z*s}}function _t(e,t){const r=t*Math.PI/180,s=Math.cos(r),i=Math.sin(r);return{x:e.x*s+e.z*i,y:e.y,z:-e.x*i+e.z*s}}function Lt(e,t){const r=t*Math.PI/180,s=Math.cos(r),i=Math.sin(r);return{x:e.x*s-e.y*i,y:e.x*i+e.y*s,z:e.z}}function je(e,t,r){let s=Tt(e,r.rotationX);s=_t(s,r.rotationY),s=Lt(s,r.rotationZ);const i=s.z+t,o=t/Math.max(i,.1);return{x:(s.x*o*r.zoom+r.panX)*100+50,y:(-s.y*o*r.zoom+r.panY)*100+50,depth:i}}function we(e,t,r,s){const i=Math.max(0,Math.min(1,(e-t)/(r-t))),o={viridis:[[68,1,84],[59,82,139],[33,145,140],[94,201,98],[253,231,37]],plasma:[[13,8,135],[126,3,168],[204,71,120],[248,149,64],[240,249,33]],inferno:[[0,0,4],[87,16,110],[188,55,84],[249,142,9],[252,255,164]],magma:[[0,0,4],[81,18,124],[183,55,121],[254,159,109],[252,253,191]],cividis:[[0,32,77],[57,86,109],[128,133,121],[200,178,107],[253,231,55]],jet:[[0,0,127],[0,0,255],[0,255,255],[255,255,0],[255,0,0],[127,0,0]],rainbow:[[150,0,90],[0,0,200],[0,200,200],[0,200,0],[200,200,0],[200,0,0]],coolwarm:[[59,76,192],[98,130,234],[221,221,221],[220,170,132],[180,4,38]],RdBu:[[103,0,31],[178,24,43],[244,165,130],[247,247,247],[146,197,222],[33,102,172],[5,48,97]],spectral:[[158,1,66],[213,62,79],[253,174,97],[255,255,191],[171,221,164],[43,131,186],[94,79,162]],turbo:[[48,18,59],[86,121,245],[51,185,131],[192,212,49],[249,141,10],[122,4,3]],grayscale:[[0,0,0],[255,255,255]]},a=o[s]||o.viridis,l=i*(a.length-1),c=Math.floor(l),u=l-c;if(c>=a.length-1){const E=a[a.length-1];return`rgb(${E[0]}, ${E[1]}, ${E[2]})`}const x=a[c],m=a[c+1],f=Math.round(x[0]+u*(m[0]-x[0])),g=Math.round(x[1]+u*(m[1]-x[1])),M=Math.round(x[2]+u*(m[2]-x[2]));return`rgb(${f}, ${g}, ${M})`}function Ot({data:e=Rt,title:t,width:r="100%",height:s=500,scene:i={},showColorBar:o=!0,animation:a,showLegend:l=!0,legendPosition:c="top-right",enableRotation:u=!0,enableZoom:x=!0,enablePan:m=!0,showAxes:f=!0,showAxisLabels:g=!0,focalLength:M=3,theme:E="light",onCameraChange:Y,onPointClick:H,onPointHover:P,className:G,style:R}){const{t:ne}=pe.useNiceTranslation(),ce=h.useRef(null),[Z,ue]=h.useState(Xe),[ee,J]=h.useState(!1),[se,X]=h.useState(null),[te,de]=h.useState(null),[me,oe]=h.useState(0),W=h.useMemo(()=>{let A=1/0,k=-1/0,d=1/0,b=-1/0,S=1/0,I=-1/0,z=1/0,T=-1/0;for(const $ of e)if($.type==="scatter3d")for(const N of $.points)A=Math.min(A,N.x),k=Math.max(k,N.x),d=Math.min(d,N.y),b=Math.max(b,N.y),S=Math.min(S,N.z),I=Math.max(I,N.z),typeof N.color=="number"&&(z=Math.min(z,N.color),T=Math.max(T,N.color));else if($.type==="surface"||$.type==="wireframe"){const N=$;for(const _ of N.xData)A=Math.min(A,_),k=Math.max(k,_);for(const _ of N.yData)d=Math.min(d,_),b=Math.max(b,_);for(const _ of N.zData)for(const O of _)S=Math.min(S,O),I=Math.max(I,O),z=Math.min(z,O),T=Math.max(T,O)}const y=Math.max(k-A,b-d,I-S)||1;return{xMin:A,xMax:k,yMin:d,yMax:b,zMin:S,zMax:I,colorMin:z,colorMax:T,maxRange:y}},[e]),q=h.useCallback(A=>{const k=2/W.maxRange;return{x:(A.x-(W.xMin+W.xMax)/2)*k,y:(A.y-(W.yMin+W.yMax)/2)*k,z:(A.z-(W.zMin+W.zMax)/2)*k}},[W]),ae=h.useCallback(A=>{!u&&!m||(J(!0),X({x:A.clientX,y:A.clientY,viewState:{...Z}}))},[u,m,Z]),U=h.useCallback(A=>{if(!ee||!se)return;const k=A.clientX-se.x,d=A.clientY-se.y;A.shiftKey&&m?ue({...se.viewState,panX:se.viewState.panX+k*.002,panY:se.viewState.panY+d*.002}):u&&ue({...se.viewState,rotationY:se.viewState.rotationY+k*.5,rotationX:se.viewState.rotationX+d*.5})},[ee,se,u,m]),w=h.useCallback(()=>{J(!1),X(null)},[]),K=h.useCallback(A=>{if(!x)return;A.preventDefault();const k=A.deltaY>0?.9:1.1;ue(d=>({...d,zoom:Math.max(.1,Math.min(10,d.zoom*k))}))},[x]),Q=h.useMemo(()=>{switch(E){case"dark":return{bg:"var(--nice-bg, #1a1a2e)",text:"var(--nice-text-secondary, #e0e0e0)",axis:"var(--nice-text-secondary, #555)",grid:"var(--nice-text, #333)"};case"scientific":return{bg:"var(--nice-bg-secondary, #f8f8f8)",text:"var(--nice-text, #333)",axis:"var(--nice-text-secondary, #666)",grid:"var(--nice-border, #ddd)"};default:return{bg:"var(--nice-bg, #fff)",text:"var(--nice-text, #333)",axis:"var(--nice-text-secondary, #888)",grid:"var(--nice-border, #e0e0e0)"}}},[E]),re=h.useMemo(()=>{var k;const A=[];for(const d of e)if(d.type==="scatter3d"){const b=d,S=b.points.map(I=>{var N,_,O,le,xe;const z=q(I),T=je(z,M,Z);let y=(N=b.marker)==null?void 0:N.color;if(Array.isArray((_=b.marker)==null?void 0:_.color)){const ge=b.points.indexOf(I);y=we(b.marker.color[ge],W.colorMin,W.colorMax,((O=b.marker)==null?void 0:O.colorScale)||"viridis")}else typeof I.color=="number"&&(y=we(I.color,W.colorMin,W.colorMax,((le=b.marker)==null?void 0:le.colorScale)||"viridis"));const $=Array.isArray(I.size)?I.size[0]:I.size||((xe=b.marker)==null?void 0:xe.size)||5;return{...T,color:y,size:$,original:I}});A.push({type:"scatter",points:S,data:d})}else if(d.type==="surface"||d.type==="wireframe"){const b=d,S=[];for(let I=0;I<b.xData.length;I++)for(let z=0;z<b.yData.length;z++){const T={x:b.xData[I],y:b.yData[z],z:b.zData[I][z]},y=q(T),$=je(y,M,Z),N=we(((k=b.colorData)==null?void 0:k[I][z])??b.zData[I][z],W.colorMin,W.colorMax,b.colorScale||"viridis");S.push({...$,color:N,size:3,original:T})}A.push({type:d.type,points:S,data:d})}for(const d of A)d.points.sort((b,S)=>b.depth-S.depth);return A},[e,Z,M,q,W]),ie=h.useMemo(()=>{var d,b,S;if(!f)return null;const A=1.2,k={x:[je({x:-A,y:0,z:0},M,Z),je({x:A,y:0,z:0},M,Z)],y:[je({x:0,y:-A,z:0},M,Z),je({x:0,y:A,z:0},M,Z)],z:[je({x:0,y:0,z:-A},M,Z),je({x:0,y:0,z:A},M,Z)]};return n.jsxs("g",{className:"nice-3d-plot__axes",children:[n.jsx("line",{x1:`${k.x[0].x}%`,y1:`${k.x[0].y}%`,x2:`${k.x[1].x}%`,y2:`${k.x[1].y}%`,stroke:"var(--nice-danger, #e74c3c)",strokeWidth:1.5}),g&&n.jsx("text",{x:`${k.x[1].x+2}%`,y:`${k.x[1].y}%`,fill:"var(--nice-danger, #e74c3c)",fontSize:"12",children:((d=i.xAxis)==null?void 0:d.title)||"X"}),n.jsx("line",{x1:`${k.y[0].x}%`,y1:`${k.y[0].y}%`,x2:`${k.y[1].x}%`,y2:`${k.y[1].y}%`,stroke:"var(--nice-success, #2ecc71)",strokeWidth:1.5}),g&&n.jsx("text",{x:`${k.y[1].x}%`,y:`${k.y[1].y-2}%`,fill:"var(--nice-success, #2ecc71)",fontSize:"12",textAnchor:"middle",children:((b=i.yAxis)==null?void 0:b.title)||"Y"}),n.jsx("line",{x1:`${k.z[0].x}%`,y1:`${k.z[0].y}%`,x2:`${k.z[1].x}%`,y2:`${k.z[1].y}%`,stroke:"var(--nice-primary, #3498db)",strokeWidth:1.5}),g&&n.jsx("text",{x:`${k.z[1].x+2}%`,y:`${k.z[1].y}%`,fill:"var(--nice-primary, #3498db)",fontSize:"12",children:((S=i.zAxis)==null?void 0:S.title)||"Z"})]})},[f,g,Z,M,i]);return n.jsxs("div",{ref:ce,className:`nice-3d-plot nice-3d-plot--${E}${ee?" nice-3d-plot--dragging":""} ${G||""}`,style:{width:r,height:s,backgroundColor:Q.bg,color:Q.text,...R},onMouseDown:ae,onMouseMove:U,onMouseUp:w,onMouseLeave:w,onWheel:K,children:[t&&n.jsx("div",{className:"nice-3d-plot__title",children:t}),n.jsxs("svg",{width:"100%",height:"100%",className:"nice-3d-plot__canvas",children:[ie,re.map((A,k)=>n.jsxs("g",{className:"nice-3d-plot__data",children:[A.type==="scatter"&&A.points.map((d,b)=>{var S;return n.jsx("circle",{cx:`${d.x}%`,cy:`${d.y}%`,r:d.size||4,fill:d.color||"var(--nice-primary, #3498db)",opacity:((S=A.data.marker)==null?void 0:S.opacity)??.8,style:{cursor:H?"pointer":void 0},onMouseEnter:()=>{de({point:d.original,dataIndex:k}),P==null||P(d.original,k)},onMouseLeave:()=>{de(null),P==null||P(null,k)},onClick:()=>H==null?void 0:H(d.original,k)},b)}),(A.type==="surface"||A.type==="wireframe")&&A.points.map((d,b)=>n.jsx("rect",{x:`${d.x-1}%`,y:`${d.y-1}%`,width:"2%",height:"2%",fill:d.color||"var(--nice-primary, #3498db)",opacity:A.data.opacity??.7},b))]},A.data.id||k))]}),l&&e.length>1&&n.jsx("div",{style:{position:"absolute",padding:"8px",background:"var(--nice-overlay-light-90, rgba(255, 255, 255, 0.9))",borderRadius:4,fontSize:"0.8rem",...c==="top-right"&&{top:8,right:8},...c==="top-left"&&{top:8,left:8},...c==="bottom-right"&&{bottom:8,right:8},...c==="bottom-left"&&{bottom:8,left:8}},children:e.map((A,k)=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[n.jsx("span",{style:{width:12,height:12,background:"var(--nice-primary, #3498db)",borderRadius:2}}),A.name]},A.id||k))}),o&&Number.isFinite(W.colorMin)&&Number.isFinite(W.colorMax)&&n.jsxs("div",{style:{position:"absolute",right:16,top:"50%",transform:"translateY(-50%)",width:16,height:150,background:`linear-gradient(to top, ${we(0,0,1,"viridis")}, ${we(.5,0,1,"viridis")}, ${we(1,0,1,"viridis")})`,borderRadius:2,border:"1px solid var(--nice-border, #ccc)"},children:[n.jsx("div",{style:{position:"absolute",top:-16,right:20,fontSize:"0.7rem"},children:W.colorMax.toFixed(2)}),n.jsx("div",{style:{position:"absolute",bottom:-16,right:20,fontSize:"0.7rem"},children:W.colorMin.toFixed(2)})]}),te&&n.jsxs("div",{style:{position:"absolute",bottom:8,left:8,background:"var(--nice-overlay-80, rgba(0, 0, 0, 0.8))",color:"var(--nice-color-white, #fff)",padding:"4px 8px",borderRadius:4,fontSize:"0.75rem"},children:["X: ",te.point.x.toFixed(4),", Y: ",te.point.y.toFixed(4),", Z:"," ",te.point.z.toFixed(4)]}),n.jsx("div",{style:{position:"absolute",bottom:8,right:8,display:"flex",gap:4},children:n.jsx("button",{onClick:()=>ue(Xe),style:{padding:"4px 8px",fontSize:"0.75rem",cursor:"pointer"},children:ne("plot3d.resetView","Reset View")})})]})}const He={H:"var(--nice-bg, #fff)",C:"#909090",N:"#3050F8",O:"#FF0D0D",S:"#FFFF30",P:"#FF8000",F:"#90E050",Cl:"#1FF01F",Br:"#A62929",I:"#940094",He:"#D9FFFF",Ne:"#B3E3F5",Ar:"#80D1E3",Kr:"#5CB8D1",Xe:"#429EB0",Li:"#CC80FF",Na:"#AB5CF2",K:"#8F40D4",Rb:"#702EB0",Cs:"#57178F",Be:"#C2FF00",Mg:"#8AFF00",Ca:"#3DFF00",Sr:"var(--nice-success, #00ff00)",Ba:"#00C900",B:"#FFB5B5",Al:"#BFA6A6",Ga:"#C28F8F",In:"#A67573",Tl:"#A6544D",Si:"#F0C8A0",Ge:"#668F8F",Sn:"#668080",Pb:"#575961",As:"#BD80E3",Sb:"#9E63B5",Bi:"#9E4FB5",Se:"#FFA100",Te:"#D47A00",Po:"#AB5C00",Fe:"#E06633",Co:"#F090A0",Ni:"#50D050",Cu:"#C88033",Zn:"#7D80B0",Mn:"#9C7AC7",Cr:"#8A99C7",V:"#A6A6AB",Ti:"#BFC2C7",Sc:"#E6E6E6",Au:"#FFD123",Ag:"#C0C0C0",Pt:"#D0D0E0",Pd:"#006985",Ru:"#248F8F",Rh:"#0A7D8C",Os:"#266696",Ir:"#175487"},ze={H:.31,C:.77,N:.71,O:.66,S:1.05,P:1.07,F:.57,Cl:1.02,Br:1.2,I:1.39,He:.28,Ne:.58,Ar:1.06,Li:1.28,Na:1.66,K:2.03,Mg:1.41,Ca:1.76,Fe:1.26,Zn:1.22,Cu:1.28,Ni:1.24},Wt={H:1.2,C:1.7,N:1.55,O:1.52,S:1.8,P:1.8,F:1.47,Cl:1.75,Br:1.85,I:1.98,He:1.4,Ne:1.54,Ar:1.88,Li:1.82,Na:2.27,K:2.75,Mg:1.73,Ca:2.31,Fe:2,Zn:1.39,Cu:1.4,Ni:1.63};function Ye(e){const t=[],r=[],s=new Map,i=new Map;let o="Unknown";const a=e.split(`
|
|
60
|
-
`);for(const l of a){const c=l.substring(0,6).trim();if(c==="HEADER")o=l.substring(10,50).trim()||o;else if(c==="ATOM"||c==="HETATM"){const u=parseInt(l.substring(6,11).trim(),10),x=l.substring(12,16).trim(),m=l.substring(17,20).trim(),f=l.substring(21,22).trim()||"A",g=parseInt(l.substring(22,26).trim(),10),M=parseFloat(l.substring(30,38).trim()),E=parseFloat(l.substring(38,46).trim()),Y=parseFloat(l.substring(46,54).trim()),H=parseFloat(l.substring(54,60).trim())||1,P=parseFloat(l.substring(60,66).trim())||0,G=l.substring(76,78).trim()||x.replace(/\d/g,"").substring(0,1),R={id:t.length,serial:u,name:x,element:G.toUpperCase(),residueName:m,residueSeq:g,chainId:f,x:M,y:E,z:Y,occupancy:H,bFactor:P,color:He[G.toUpperCase()]||"var(--nice-text-secondary, #808080)",radius:ze[G.toUpperCase()]||1.5};t.push(R);const ne=`${f}_${g}_${m}`;s.has(ne)||s.set(ne,{id:s.size,name:m,seq:g,chainId:f,atoms:[]}),s.get(ne).atoms.push(R.id),i.has(f)||i.set(f,{id:f,residues:[]})}else if(c==="CONECT"){const u=l.substring(6).trim().split(/\s+/).map(Number),x=u[0],m=t.find(f=>f.serial===x);if(m)for(let f=1;f<u.length;f++){const g=u[f],M=t.find(E=>E.serial===g);M&&m.id<M.id&&r.push({id:r.length,atom1:m.id,atom2:M.id,order:1})}}}if(r.length===0)for(let l=0;l<t.length;l++)for(let c=l+1;c<t.length;c++){const u=t[l],x=t[c],m=u.x-x.x,f=u.y-x.y,g=u.z-x.z,M=Math.sqrt(m*m+f*f+g*g),E=(ze[u.element]||1.5)+(ze[x.element]||1.5)+.4;M<E&&M>.4&&r.push({id:r.length,atom1:l,atom2:c,order:1,length:M})}return{id:"mol_"+Date.now(),name:o,atoms:t,bonds:r,residues:Array.from(s.values()),chains:Array.from(i.values())}}function Xt(e,t,r,s,i,o){const a=g=>g*Math.PI/180,l=t*Math.cos(a(s))-r*Math.sin(a(s)),c=t*Math.sin(a(s))+r*Math.cos(a(s)),u=e*Math.cos(a(i))+c*Math.sin(a(i)),x=-e*Math.sin(a(i))+c*Math.cos(a(i)),m=u*Math.cos(a(o))-l*Math.sin(a(o)),f=u*Math.sin(a(o))+l*Math.cos(a(o));return[m,f,x]}function De(e,t,r,s,i,o){const a=e-i.x,l=t-i.y,c=r-i.z,[u,x,m]=Xt(a,l,c,s.rotX,s.rotY,s.rotZ),f=500,g=f/(f+m*50);return{x:50+u*o*s.zoom*g+s.panX,y:50-x*o*s.zoom*g+s.panY,depth:m}}function Yt({molecule:e,format:t="pdb",style:r="ball-stick",colorScheme:s="element",showHydrogens:i=!0,showWaters:o=!1,showLabels:a=!1,labelType:l="element",width:c="100%",height:u=500,backgroundColor:x="#000000",enableRotation:m=!0,enableZoom:f=!0,showControls:g=!0,measurements:M=[],surfaces:E=[],labels:Y=[],selection:H,highlightColor:P="var(--nice-warning, #ffff00)",spin:G=!1,spinSpeed:R=.5,onAtomClick:ne,onAtomHover:ce,onSelectionChange:Z,className:ue,styleOverride:ee}){const{t:J}=pe.useNiceTranslation(),se=h.useRef(null),[X,te]=h.useState(null),[de,me]=h.useState({rotX:0,rotY:0,rotZ:0,zoom:1,panX:0,panY:0}),[oe,W]=h.useState(!1),[q,ae]=h.useState(null),[U,w]=h.useState(null),[K,Q]=h.useState(r);h.useEffect(()=>{if(!e){te(null);return}typeof e=="string"?(t==="pdb"||console.warn(`Format ${t} parsing not implemented, using PDB parser`),te(Ye(e))):te(e)},[e,t]),h.useEffect(()=>{if(!G)return;const y=setInterval(()=>{me($=>({...$,rotY:($.rotY+R)%360}))},16);return()=>clearInterval(y)},[G,R]);const{center:re,scale:ie}=h.useMemo(()=>{if(!X||X.atoms.length===0)return{center:{x:0,y:0,z:0},scale:1};let y=1/0,$=-1/0,N=1/0,_=-1/0,O=1/0,le=-1/0;for(const fe of X.atoms)y=Math.min(y,fe.x),$=Math.max($,fe.x),N=Math.min(N,fe.y),_=Math.max(_,fe.y),O=Math.min(O,fe.z),le=Math.max(le,fe.z);const xe={x:(y+$)/2,y:(N+_)/2,z:(O+le)/2},ge=Math.max($-y,_-N,le-O),ye=ge>0?35/ge:1;return{center:xe,scale:ye}},[X]),A=h.useMemo(()=>X?X.atoms.filter(y=>!i&&y.element==="H"||!o&&y.residueName==="HOH"?!1:y.visible!==!1).map(y=>({atom:y,...De(y.x,y.y,y.z,de,re,ie)})).sort((y,$)=>y.depth-$.depth):[],[X,de,re,ie,i,o]),k=h.useMemo(()=>X?X.bonds.filter(y=>y.visible!==!1).map(y=>{const $=X.atoms[y.atom1],N=X.atoms[y.atom2];if(!$||!N||!i&&($.element==="H"||N.element==="H"))return null;const _=De($.x,$.y,$.z,de,re,ie),O=De(N.x,N.y,N.z,de,re,ie);return{bond:y,x1:_.x,y1:_.y,x2:O.x,y2:O.y,depth:(_.depth+O.depth)/2,color1:$.color,color2:N.color}}).filter(Boolean).sort((y,$)=>y.depth-$.depth):[],[X,de,re,ie,i]),d=h.useCallback(y=>{m&&(W(!0),ae({x:y.clientX,y:y.clientY,view:{...de}}))},[m,de]),b=h.useCallback(y=>{if(!oe||!q)return;const $=y.clientX-q.x,N=y.clientY-q.y;y.shiftKey?me({...q.view,panX:q.view.panX+$*.1,panY:q.view.panY+N*.1}):me({...q.view,rotY:q.view.rotY+$*.5,rotX:q.view.rotX+N*.5})},[oe,q]),S=h.useCallback(()=>{W(!1),ae(null)},[]),I=h.useCallback(y=>{if(!f)return;y.preventDefault();const $=y.deltaY>0?.9:1.1;me(N=>({...N,zoom:Math.max(.1,Math.min(10,N.zoom*$))}))},[f]),z=h.useCallback(y=>{switch(K){case"space-filling":return(Wt[y.element]||1.5)*4;case"ball-stick":return(ze[y.element]||.5)*3;case"stick":case"wireframe":return 2;default:return 4}},[K]),T=h.useCallback(y=>(K==="wireframe"?1:K==="stick"?3:2)*(y.order||1),[K]);return X?n.jsxs("div",{ref:se,className:`nice-molecular-viewer${oe?" nice-molecular-viewer--dragging":""} ${ue||""}`,style:{width:c,height:u,backgroundColor:x,...ee},onMouseDown:d,onMouseMove:b,onMouseUp:S,onMouseLeave:S,onWheel:I,children:[n.jsxs("svg",{width:"100%",height:"100%",className:"nice-molecular-viewer__canvas",children:[K!=="space-filling"&&k.map((y,$)=>n.jsx("line",{x1:`${y.x1}%`,y1:`${y.y1}%`,x2:`${y.x2}%`,y2:`${y.y2}%`,stroke:y.bond.color||"var(--nice-text-secondary, #888888)",strokeWidth:T(y.bond),strokeLinecap:"round"},`bond-${$}`)),A.map(({atom:y,x:$,y:N})=>{var xe;const _=(xe=H==null?void 0:H.atoms)==null?void 0:xe.includes(y.id),O=(U==null?void 0:U.id)===y.id,le=z(y);return n.jsxs("g",{children:[n.jsx("circle",{cx:`${$}%`,cy:`${N}%`,r:le,fill:y.color||He[y.element]||"#808080",stroke:_?P:O?"#fff":"none",strokeWidth:_||O?2:0,style:{cursor:"pointer"},onMouseEnter:()=>{w(y),ce==null||ce(y)},onMouseLeave:()=>{w(null),ce==null||ce(null)},onClick:()=>ne==null?void 0:ne(y)}),a&&n.jsx("text",{x:`${$}%`,y:`${N-le*.15}%`,fill:"var(--nice-color-white, #fff)",fontSize:"10",textAnchor:"middle",dominantBaseline:"middle",style:{pointerEvents:"none"},children:l==="element"?y.element:l==="name"?y.name:l==="residue"?y.residueName:l==="chain"?y.chainId:l==="serial"?y.serial:y.element})]},`atom-${y.id}`)}),M.map(y=>{if(y.atoms.length<2)return null;const $=X.atoms[y.atoms[0]],N=X.atoms[y.atoms[1]];if(!$||!N)return null;const _=De($.x,$.y,$.z,de,re,ie),O=De(N.x,N.y,N.z,de,re,ie);return n.jsxs("g",{children:[n.jsx("line",{x1:`${_.x}%`,y1:`${_.y}%`,x2:`${O.x}%`,y2:`${O.y}%`,stroke:y.color||"var(--nice-warning, #ffff00)",strokeWidth:1,strokeDasharray:"3,3"}),n.jsxs("text",{x:`${(_.x+O.x)/2}%`,y:`${(_.y+O.y)/2-1}%`,fill:y.color||"var(--nice-warning, #ffff00)",fontSize:"10",textAnchor:"middle",children:[y.value.toFixed(2)," ",y.unit]})]},y.id)})]}),n.jsxs("div",{style:{position:"absolute",top:8,left:8,color:"var(--nice-text-primary, #fff)",fontSize:"0.8rem"},children:[n.jsx("div",{style:{fontWeight:"bold"},children:X.name}),n.jsx("div",{children:J("molecularViewer.atomsBonds","{atoms} atoms, {bonds} bonds").replace("{atoms}",String(X.atoms.length)).replace("{bonds}",String(X.bonds.length))}),X.formula&&n.jsx("div",{children:J("molecularViewer.formula","Formula: {formula}").replace("{formula}",String(X.formula))})]}),U&&n.jsxs("div",{style:{position:"absolute",bottom:8,left:8,background:"var(--nice-overlay-80, rgba(0, 0, 0, 0.8))",color:"var(--nice-color-white, #fff)",padding:"4px 8px",borderRadius:4,fontSize:"0.75rem"},children:[n.jsxs("div",{children:[n.jsx("b",{children:U.element})," (",U.name,")"]}),U.residueName&&n.jsxs("div",{children:[J("molecularViewer.residue","Residue:")," ",U.residueName," ",U.residueSeq]}),U.chainId&&n.jsx("div",{children:J("molecularViewer.chain","Chain: {chainId}").replace("{chainId}",String(U.chainId))}),n.jsx("div",{children:J("molecularViewer.position","Position: ({x}, {y}, {z})").replace("{x}",String(U.x.toFixed(2))).replace("{y}",String(U.y.toFixed(2))).replace("{z}",String(U.z.toFixed(2)))})]}),g&&n.jsxs("div",{style:{position:"absolute",top:8,right:8,display:"flex",flexDirection:"column",gap:4},children:[n.jsxs("select",{value:K,onChange:y=>Q(y.target.value),style:{padding:"2px 4px",fontSize:"0.75rem"},children:[n.jsx("option",{value:"ball-stick",children:J("molecularViewer.ballStick","Ball & Stick")}),n.jsx("option",{value:"space-filling",children:J("molecularViewer.spaceFilling","Space Filling")}),n.jsx("option",{value:"stick",children:J("molecularViewer.stick","Stick")}),n.jsx("option",{value:"wireframe",children:J("molecularViewer.wireframe","Wireframe")})]}),n.jsx("button",{onClick:()=>me({rotX:0,rotY:0,rotZ:0,zoom:1,panX:0,panY:0}),style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:J("molecularViewer.resetView","Reset View")})]})]}):n.jsx("div",{className:`nice-molecular-viewer nice-molecular-viewer--empty ${ue||""}`,style:{width:c,height:u,backgroundColor:x,...ee},children:J("molecularViewer.loadAMoleculePdbMol","Load a molecule (PDB, MOL, SDF)")})}function Pt(e){let t=0,r=0;function s(){var l;const o={id:`node_${r++}`};if(e[t]==="(")for(t++,o.children=[];;){const c=s();if(c&&(c.parent=o.id,o.children.push(c)),e[t]===","){t++;continue}if(e[t]===")"){t++;break}if(t>=e.length)break}let a="";for(;t<e.length&&!"[:,;()".includes(e[t]);)a+=e[t++];if(a.trim()){const c=a.match(/^([^[\]]+)?(?:\[([^\]]+)\])?$/);if(c){if(o.name=((l=c[1])==null?void 0:l.trim())||void 0,c[2]){const u=parseFloat(c[2]);isNaN(u)||(o.bootstrap=u)}}else o.name=a.trim()}if(e[t]===":"){t++;let c="";for(;t<e.length&&!"[,;()".includes(e[t]);)c+=e[t++];const u=parseFloat(c);isNaN(u)||(o.branchLength=u)}return o}return e.replace(/\s+/g,"").replace(/;$/,"")?s():null}function et(e,t=[]){if(t.push(e),e.children)for(const r of e.children)et(r,t);return t}function tt(e){return!e.children||e.children.length===0?1:e.children.reduce((t,r)=>t+tt(r),0)}function nt(e,t,r){if(!e.children||e.children.length===0||e.collapsed)return t.set(e.id,r.value),r.value+=1,t.get(e.id);let s=1/0,i=-1/0;for(const a of e.children){const l=nt(a,t,r);s=Math.min(s,l),i=Math.max(i,l)}const o=(s+i)/2;return t.set(e.id,o),o}function rt(e,t,r=0){const s=r+(e.branchLength||1);if(t.set(e.id,s),e.children&&!e.collapsed)for(const i of e.children)rt(i,t,s)}function Vt({tree:e,layout:t="rectangular",branchStyle:r="rectangular",nodeShape:s="circle",nodeSize:i=5,showBranchLengths:o=!1,showBootstrap:a=!1,bootstrapThreshold:l=70,showLeafLabels:c=!0,showInternalLabels:u=!1,labelFontSize:x=11,branchWidth:m=1.5,branchColor:f="var(--nice-text-secondary, #666666)",nodeColor:g="var(--nice-text, #333333)",highlightColor:M="var(--nice-primary, #2196f3)",clades:E=[],annotations:Y=[],colorScale:H,width:P="100%",height:G=500,padding:R=40,enableZoom:ne=!0,enablePan:ce=!0,showControls:Z=!0,onNodeClick:ue,onNodeHover:ee,onBranchClick:J,className:se,style:X}){const{t:te}=pe.useNiceTranslation(),de=h.useRef(null),[me,oe]=h.useState(1),[W,q]=h.useState({x:0,y:0}),[ae,U]=h.useState(!1),[w,K]=h.useState(null),[Q,re]=h.useState(null),[ie,A]=h.useState(t),[k,d]=h.useState(new Set),b=h.useMemo(()=>e?typeof e=="string"?Pt(e):e:null,[e]),S=h.useMemo(()=>{if(!b)return null;const j=C=>{var F;return{...C,collapsed:k.has(C.id),children:(F=C.children)==null?void 0:F.map(j)}};return j(b)},[b,k]),{positions:I,leafCount:z,maxX:T}=h.useMemo(()=>{if(!S)return{positions:{x:new Map,y:new Map},leafCount:0,maxX:0};const j=new Map,C=new Map,F=tt(S);nt(S,C,{value:0}),rt(S,j,0);const p=Math.max(...Array.from(j.values()));return{positions:{x:j,y:C},leafCount:F,maxX:p||1}},[S]),y=h.useMemo(()=>S?et(S):[],[S]),$=typeof P=="number"?P:800,N=typeof G=="number"?G:500,_=$-R*2,O=N-R*2,le=j=>R+j/T*_*.7,xe=j=>R+j/(z-1||1)*O,ge=(j,C)=>{const F=C/(z-1||1)*2*Math.PI-Math.PI/2,p=j/T*Math.min(_,O)*.4;return{x:$/2+p*Math.cos(F),y:N/2+p*Math.sin(F)}},ye=j=>{const C=I.x.get(j)||0,F=I.y.get(j)||0;return ie==="radial"||ie==="circular"?ge(C,F):{x:le(C),y:xe(F)}},fe=h.useCallback(j=>{ce&&(U(!0),K({x:j.clientX,y:j.clientY,pan:{...W}}))},[ce,W]),$e=h.useCallback(j=>{if(!ae||!w)return;const C=j.clientX-w.x,F=j.clientY-w.y;q({x:w.pan.x+C,y:w.pan.y+F})},[ae,w]),Me=h.useCallback(()=>{U(!1),K(null)},[]),Be=h.useCallback(j=>{if(!ne)return;j.preventDefault();const C=j.deltaY>0?.9:1.1;oe(F=>Math.max(.1,Math.min(5,F*C)))},[ne]),Re=h.useCallback(j=>{d(C=>{const F=new Set(C);return F.has(j)?F.delete(j):F.add(j),F})},[]),Te=(j,C)=>{const F=ye(j.id),p=ye(C.id);if(ie==="radial"||ie==="circular")return n.jsx("line",{x1:F.x,y1:F.y,x2:p.x,y2:p.y,stroke:C.color||f,strokeWidth:m});switch(r){case"rectangular":return n.jsx("path",{d:`M${F.x},${F.y} H${p.x} V${p.y}`,stroke:C.color||f,strokeWidth:m,fill:"none"});case"diagonal":return n.jsx("line",{x1:F.x,y1:F.y,x2:p.x,y2:p.y,stroke:C.color||f,strokeWidth:m});case"curved":{const v=(F.x+p.x)/2;return n.jsx("path",{d:`M${F.x},${F.y} C${v},${F.y} ${v},${p.y} ${p.x},${p.y}`,stroke:C.color||f,strokeWidth:m,fill:"none"})}default:return n.jsx("line",{x1:F.x,y1:F.y,x2:p.x,y2:p.y,stroke:C.color||f,strokeWidth:m})}},Ne=j=>{const C=ye(j.id),F=!j.children||j.children.length===0||j.collapsed,p=(Q==null?void 0:Q.id)===j.id,v=p?i*1.5:i,L=(()=>{switch(s){case"circle":return n.jsx("circle",{cx:C.x,cy:C.y,r:v});case"square":return n.jsx("rect",{x:C.x-v,y:C.y-v,width:v*2,height:v*2});case"triangle":{const D=v*1.5;return n.jsx("polygon",{points:`${C.x},${C.y-D} ${C.x-D},${C.y+D} ${C.x+D},${C.y+D}`})}case"diamond":return n.jsx("polygon",{points:`${C.x},${C.y-v} ${C.x+v},${C.y} ${C.x},${C.y+v} ${C.x-v},${C.y}`});case"none":return null;default:return n.jsx("circle",{cx:C.x,cy:C.y,r:v})}})();return n.jsxs("g",{children:[L&&n.jsx("g",{fill:j.highlighted?M:j.color||g,stroke:p?M:"none",strokeWidth:2,style:{cursor:"pointer"},onMouseEnter:()=>{re(j),ee==null||ee(j)},onMouseLeave:()=>{re(null),ee==null||ee(null)},onClick:()=>ue==null?void 0:ue(j),onDoubleClick:()=>{j.children&&j.children.length>0&&Re(j.id)},children:L}),j.collapsed&&j.children&&n.jsx("polygon",{points:`${C.x+8},${C.y-6} ${C.x+20},${C.y} ${C.x+8},${C.y+6}`,fill:g,opacity:.5}),F&&c&&j.name&&n.jsx("text",{x:C.x+i+5,y:C.y,fontSize:x,fill:"var(--nice-text, #333)",dominantBaseline:"middle",children:j.name}),!F&&u&&j.name&&n.jsx("text",{x:C.x,y:C.y-i-3,fontSize:x*.9,fill:"var(--nice-text-secondary, #666)",textAnchor:"middle",children:j.name}),a&&j.bootstrap!==void 0&&j.bootstrap>=l&&n.jsx("text",{x:C.x,y:C.y-i-2,fontSize:x*.8,fill:"var(--nice-color-accent-pink, #e91e63)",textAnchor:"middle",children:j.bootstrap.toFixed(0)})]},j.id)},Ae=j=>{const C=[];if(j.children&&!j.collapsed)for(const F of j.children)C.push(n.jsx("g",{children:Te(j,F)},`branch-${j.id}-${F.id}`)),C.push(...Ae(F));return C};return S?n.jsxs("div",{ref:de,className:`nice-phylogenetic-tree${ae?" nice-phylogenetic-tree--dragging":""} ${se||""}`,style:{width:P,height:G,...X},onMouseDown:fe,onMouseMove:$e,onMouseUp:Me,onMouseLeave:Me,onWheel:Be,children:[n.jsxs("svg",{width:"100%",height:"100%",style:{transform:`translate(${W.x}px, ${W.y}px) scale(${me})`,transformOrigin:"center center"},children:[E.map(j=>{const C=y.filter(B=>j.nodeIds.includes(B.id));if(C.length===0)return null;const F=C.map(B=>ye(B.id)),p=Math.min(...F.map(B=>B.x))-10,v=Math.max(...F.map(B=>B.x))+10,L=Math.min(...F.map(B=>B.y))-10,D=Math.max(...F.map(B=>B.y))+10;return n.jsxs("g",{children:[n.jsx("rect",{x:p,y:L,width:v-p,height:D-L,fill:j.background||`${j.color}20`||"var(--nice-primary-bg, #e3f2fd)",stroke:j.color||"var(--nice-primary, #2196f3)",strokeWidth:1,strokeDasharray:"4,2",rx:4}),j.showLabel&&n.jsx("text",{x:v+5,y:(L+D)/2,fontSize:10,fill:j.color||"var(--nice-text-secondary, #666)",dominantBaseline:"middle",children:j.name})]},j.id)}),Ae(S),y.map(j=>Ne(j)),Y.map(j=>{if(!y.find(v=>v.id===j.nodeId))return null;const F=ye(j.nodeId),p={left:{x:-10,y:0},right:{x:10,y:0},above:{x:0,y:-10},below:{x:0,y:10}}[j.position||"right"];return n.jsx("text",{x:F.x+p.x,y:F.y+p.y,fontSize:j.fontSize||9,fill:j.color||"var(--nice-danger, #ff5722)",textAnchor:j.position==="left"?"end":j.position==="right"?"start":"middle",dominantBaseline:"middle",children:j.text},`ann-${j.nodeId}`)})]}),n.jsx("div",{style:{position:"absolute",top:8,left:8,fontSize:"0.75rem",color:"var(--nice-text-secondary, #666)"},children:te("phylogeneticTree.nodesLeaves","{allNodes} nodes • {leafCount} leaves").replace("{allNodes}",String(y.length)).replace("{leafCount}",String(z))}),Q&&n.jsxs("div",{style:{position:"absolute",bottom:8,left:8,background:"var(--nice-overlay-light-95, rgba(255, 255, 255, 0.95))",padding:"4px 8px",borderRadius:4,fontSize:"0.75rem",boxShadow:"0 1px 4px var(--nice-overlay-10, rgba(0, 0, 0, 0.1))"},children:[n.jsx("div",{children:n.jsx("b",{children:Q.name||Q.id})}),Q.branchLength!==void 0&&n.jsx("div",{children:te("phylogeneticTree.branchLength","Branch length: {branchLength}").replace("{branchLength}",String(Q.branchLength.toFixed(4)))}),Q.bootstrap!==void 0&&n.jsx("div",{children:te("phylogeneticTree.bootstrap","Bootstrap: {bootstrap}").replace("{bootstrap}",String(Q.bootstrap))}),Q.children&&n.jsx("div",{children:te("phylogeneticTree.children","Children: {children}").replace("{children}",String(Q.children.length))})]}),Z&&n.jsxs("div",{style:{position:"absolute",top:8,right:8,display:"flex",flexDirection:"column",gap:4},children:[n.jsxs("select",{value:ie,onChange:j=>A(j.target.value),style:{padding:"2px 4px",fontSize:"0.75rem"},children:[n.jsx("option",{value:"rectangular",children:te("phylogeneticTree.rectangular","Rectangular")}),n.jsx("option",{value:"radial",children:te("phylogeneticTree.radial","Radial")}),n.jsx("option",{value:"diagonal",children:te("phylogeneticTree.diagonal","Diagonal")})]}),n.jsx("button",{onClick:()=>{oe(1),q({x:0,y:0})},style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:te("phylogeneticTree.resetView","Reset View")}),n.jsx("button",{onClick:()=>d(new Set),style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:te("phylogeneticTree.expandAll","Expand All")})]})]}):n.jsx("div",{className:`nice-phylogenetic-tree nice-phylogenetic-tree--empty ${se||""}`,style:{width:P,height:G,...X},children:te("phylogeneticTree.loadAPhylogeneticTreeNewick","Load a phylogenetic tree (Newick format)")})}const ke=e=>e*Math.PI/180;function qt(e,t,r,s){const i=(t+180)/360*r,o=ke(e),a=Math.log(Math.tan(Math.PI/4+o/2)),l=s/2-r*a/(2*Math.PI);return{x:i,y:l}}function Ut(e,t,r,s){const i=(t+180)/360*r,o=(90-e)/180*s;return{x:i,y:o}}function Kt(e,t,r,s,i,o){const a=ke(e),l=ke(t),c=ke(i),u=ke(o);if(Math.sin(c)*Math.sin(a)+Math.cos(c)*Math.cos(a)*Math.cos(l-u)<0)return{x:0,y:0,visible:!1};const m=Math.min(r,s)/2-10,f=r/2+m*Math.cos(a)*Math.sin(l-u),g=s/2-m*(Math.cos(c)*Math.sin(a)-Math.sin(c)*Math.cos(a)*Math.cos(l-u));return{x:f,y:g,visible:!0}}function Zt(e,t,r,s){const i=[[0,1,0],[5,.9986,.062],[10,.9954,.124],[15,.99,.186],[20,.9822,.248],[25,.973,.31],[30,.96,.372],[35,.9427,.434],[40,.9216,.4958],[45,.8962,.5571],[50,.8679,.6176],[55,.835,.6769],[60,.7986,.7346],[65,.7597,.7903],[70,.7186,.8435],[75,.6732,.8936],[80,.6213,.9394],[85,.5722,.9761],[90,.5322,1]],o=Math.abs(e);let a=1,l=0;for(let m=0;m<i.length-1;m++)if(o>=i[m][0]&&o<=i[m+1][0]){const f=(o-i[m][0])/5;a=i[m][1]+f*(i[m+1][1]-i[m][1]),l=i[m][2]+f*(i[m+1][2]-i[m][2]);break}const c=r/(2*Math.PI),u=r/2+c*ke(t)*a,x=s/2-c*l*1.3523*Math.sign(e);return{x:u,y:x}}const Jt=`
|
|
59
|
+
`)}async searchDatabase(t,r,s=10){var i,o;try{if(t==="crossref")return await this.searchCrossref(r,s);if(t==="pubmed")return await this.searchPubMed(r,s);throw new Error(`Unknown database: ${t}`)}catch(a){return(o=(i=this.config).onError)==null||o.call(i,a),{source:t,total:0,results:[]}}}async searchCrossref(t,r){const s=new URLSearchParams({query:t,rows:String(r)});this.config.crossrefEmail&&s.set("mailto",this.config.crossrefEmail);const i=await fetch(`https://api.crossref.org/works?${s}`);if(!i.ok)throw new Error(`Crossref API error: ${i.status}`);const o=await i.json(),a=o.message.items.map(l=>{var c,u,x,y,f,m;return{type:"article",title:((c=l.title)==null?void 0:c[0])||"",authors:(l.author||[]).map(M=>({given:M.given||"",family:M.family||"",orcid:M.ORCID})),year:(y=(x=(u=l.published)==null?void 0:u["date-parts"])==null?void 0:x[0])==null?void 0:y[0],journal:(f=l["container-title"])==null?void 0:f[0],volume:l.volume,issue:l.issue,pages:l.page,doi:l.DOI,issn:(m=l.ISSN)==null?void 0:m[0],publisher:l.publisher,abstract:l.abstract,sourceDatabase:"crossref"}});return{source:"crossref",total:o.message["total-results"],results:a}}async searchPubMed(t,r){const s=`https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=${encodeURIComponent(t)}&retmax=${r}&retmode=json`,i=await fetch(s);if(!i.ok)throw new Error(`PubMed API error: ${i.status}`);const o=await i.json(),a=o.esearchresult.idlist;if(a.length===0)return{source:"pubmed",total:0,results:[]};const l=`https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=${a.join(",")}&retmode=json`,c=await fetch(l);if(!c.ok)throw new Error(`PubMed API error: ${c.status}`);const u=await c.json(),x=a.map(y=>{var m;const f=u.result[y];return{type:"article",title:f.title||"",authors:(f.authors||[]).map(M=>{const E=M.name.split(" ");return{family:E.pop()||"",given:E.join(" ")}}),year:f.pubdate?parseInt(f.pubdate.split(" ")[0],10):void 0,journal:f.source,volume:f.volume,issue:f.issue,pages:f.pages,pmid:y,doi:(m=f.elocationid)==null?void 0:m.replace("doi: ",""),sourceDatabase:"pubmed"}});return{source:"pubmed",total:parseInt(o.esearchresult.count,10),results:x}}async fetchByDOI(t){var r,s,i,o,a;try{const l=await fetch(`https://api.crossref.org/works/${encodeURIComponent(t)}`);if(!l.ok)return null;const u=(await l.json()).message;return this.addCitation({type:"article",title:((r=u.title)==null?void 0:r[0])||"",authors:(u.author||[]).map(x=>({given:x.given||"",family:x.family||"",orcid:x.ORCID})),year:(o=(i=(s=u.published)==null?void 0:s["date-parts"])==null?void 0:i[0])==null?void 0:o[0],journal:(a=u["container-title"])==null?void 0:a[0],volume:u.volume,issue:u.issue,pages:u.page,doi:u.DOI,publisher:u.publisher,abstract:u.abstract,sourceDatabase:"crossref"})}catch{return null}}updateCollectionCounts(){for(const t of this.collections.values())t.id==="all"?t.citationCount=this.citations.size:t.citationCount=Array.from(this.citations.values()).filter(r=>{var s;return(s=r.collections)==null?void 0:s.includes(t.id)}).length}generateId(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}}function wt(e){return new Ge(e)}const Qe=h.createContext(null);function _e(){const e=h.useContext(Qe);if(!e)throw new Error("useCitation must be used within CitationProvider");return e}const Me={container:{display:"flex",height:"100%",fontFamily:"'Inter', sans-serif",fontSize:"14px"},sidebar:{width:"240px",backgroundColor:"var(--nice-bg-secondary, #f5f5f5)",borderRight:"1px solid var(--nice-border, #e0e0e0)",display:"flex",flexDirection:"column"},main:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},toolbar:{padding:"12px 16px",borderBottom:"1px solid var(--nice-border, #e0e0e0)",display:"flex",gap:"12px",alignItems:"center"},list:{flex:1,overflow:"auto"},listItem:{padding:"12px 16px",borderBottom:"1px solid var(--nice-border, #eee)",cursor:"pointer"},detail:{width:"400px",borderLeft:"1px solid var(--nice-border, #e0e0e0)",overflow:"auto",padding:"16px"},input:{padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)",borderRadius:"4px",fontSize:"14px"},button:{padding:"8px 16px",backgroundColor:"var(--nice-primary-hover, #1976d2)",color:"white",border:"none",borderRadius:"4px",cursor:"pointer"}};function St({service:e,className:t,style:r}){const{t:s}=pe.useNiceTranslation(),[i,o]=h.useState([]),[a,l]=h.useState([]),[c,u]=h.useState("all"),[x,y]=h.useState(null),[f,m]=h.useState(""),[M,E]=h.useState("apa"),q=h.useCallback(()=>{o(e.listCitations(c)),l(e.listCollections())},[e,c]),re=h.useMemo(()=>f?e.searchCitations(f,{collection:c}):i,[i,f,c,e]),U=h.useMemo(()=>i.find(B=>B.id===x),[i,x]),te={service:e,citations:i,collections:a,selectedCollection:c,setSelectedCollection:u,selectedCitation:x,setSelectedCitation:y,searchQuery:f,setSearchQuery:m,citationStyle:M,setCitationStyle:E,refresh:q};return n.jsx(Qe.Provider,{value:te,children:n.jsxs("div",{className:t,style:{...Me.container,...r},children:[n.jsxs("div",{style:Me.sidebar,children:[n.jsx("div",{style:{padding:"16px",fontWeight:600},children:s("citation.collections","Collections")}),a.map(B=>n.jsxs("div",{role:"button",tabIndex:0,onKeyDown:pe.clickOnActivationKey,onClick:()=>{u(B.id),q()},style:{...Me.listItem,backgroundColor:c===B.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsx("div",{children:B.name}),n.jsx("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:s("citation.items","{citationCount} items").replace("{citationCount}",String(B.citationCount))})]},B.id))]}),n.jsxs("div",{style:Me.main,children:[n.jsxs("div",{style:Me.toolbar,children:[n.jsx("input",{type:"text",placeholder:s("citation.searchReferences","Search references..."),value:f,onChange:B=>m(B.target.value),style:{...Me.input,flex:1}}),n.jsxs("select",{value:M,onChange:B=>E(B.target.value),style:Me.input,children:[n.jsx("option",{value:"apa",children:s("citation.apa","APA")}),n.jsx("option",{value:"mla",children:s("citation.mla","MLA")}),n.jsx("option",{value:"chicago",children:s("citation.chicago","Chicago")}),n.jsx("option",{value:"harvard",children:s("citation.harvard","Harvard")}),n.jsx("option",{value:"ieee",children:s("citation.ieee","IEEE")}),n.jsx("option",{value:"vancouver",children:s("citation.vancouver","Vancouver")}),n.jsx("option",{value:"bibtex",children:"BibTeX"})]}),n.jsx(kt,{})]}),n.jsxs("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[n.jsxs("div",{style:Me.list,children:[re.map(B=>n.jsxs("div",{role:"button",tabIndex:0,onKeyDown:pe.clickOnActivationKey,onClick:()=>y(B.id),style:{...Me.listItem,backgroundColor:x===B.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsx("div",{style:{fontWeight:500,marginBottom:"4px"},children:B.title}),n.jsxs("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:[B.authors.map(ie=>ie.family).join(", "),B.year&&` (${B.year})`]}),B.journal&&n.jsx("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #888)",fontStyle:"italic"},children:B.journal})]},B.id)),re.length===0&&n.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--nice-text-secondary, #666)"},children:s("citation.noReferencesFound","No references found")})]}),U&&n.jsx("div",{style:Me.detail,children:n.jsx(Ct,{citation:U})})]})]})]})})}function kt(){const{t:e}=pe.useNiceTranslation(),{service:t,refresh:r}=_e(),[s,i]=h.useState(!1),[o,a]=h.useState(""),[l,c]=h.useState(!1),u=async()=>{if(o.trim()){c(!0);try{await t.fetchByDOI(o.trim()),r(),a(""),i(!1)}finally{c(!1)}}};return n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>i(!0),style:Me.button,children:e("citation.addReference","+ Add Reference")}),s&&n.jsx("div",{role:"presentation",style:{position:"fixed",inset:0,backgroundColor:"var(--nice-overlay-50, rgba(0, 0, 0, 0.5))",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},onClick:()=>i(!1),children:n.jsxs("div",{role:"presentation",style:{backgroundColor:"white",padding:"24px",borderRadius:"8px",width:"400px"},onClick:x=>x.stopPropagation(),children:[n.jsx("h3",{style:{margin:"0 0 16px 0"},children:e("citation.addReferenceByDoi","Add Reference by DOI")}),n.jsx("input",{type:"text",value:o,onChange:x=>a(x.target.value),placeholder:e("citation.enterDoiEG10","Enter DOI (e.g., 10.1000/xyz123)"),style:{...Me.input,width:"100%",marginBottom:"16px"}}),n.jsxs("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[n.jsx("button",{onClick:()=>i(!1),style:{...Me.button,backgroundColor:"var(--nice-bg-tertiary, #9e9e9e)"},children:e("citation.cancel","Cancel")}),n.jsx("button",{onClick:u,disabled:l,style:Me.button,children:l?e("citation.loading","Loading..."):e("citation.add","Add")})]})]})})]})}function Ct({citation:e}){const{t}=pe.useNiceTranslation(),{service:r,citationStyle:s}=_e(),[i,o]=h.useState(!1),a=h.useMemo(()=>r.formatCitation(e.id,s),[r,e.id,s]),l=()=>{navigator.clipboard.writeText(a),o(!0),setTimeout(()=>o(!1),2e3)};return n.jsxs("div",{children:[n.jsx("h2",{style:{margin:"0 0 8px 0",fontSize:"18px"},children:e.title}),n.jsx("div",{style:{color:"var(--nice-text-secondary, #666)",marginBottom:"16px"},children:e.authors.map(c=>`${c.given} ${c.family}`).join(", ")}),n.jsxs("div",{style:{marginBottom:"16px"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"8px"},children:[n.jsx("strong",{children:t("citation.formatted","Formatted ({citationStyle})").replace("{citationStyle}",String(s.toUpperCase()))}),n.jsx("button",{onClick:l,style:{...Me.button,padding:"4px 8px",fontSize:"12px"},children:i?t("citation.copied","Copied!"):t("citation.copy","Copy")})]}),n.jsx("div",{style:{padding:"12px",backgroundColor:"var(--nice-bg-secondary, #f5f5f5)",borderRadius:"4px",whiteSpace:"pre-wrap",fontSize:"13px"},dangerouslySetInnerHTML:{__html:a.replace(/\*([^*]+)\*/g,"<em>$1</em>")}})]}),n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px",fontSize:"13px"},children:[e.journal&&n.jsxs("div",{children:[n.jsx("strong",{children:t("citation.journal","Journal:")})," ",e.journal]}),e.year&&n.jsxs("div",{children:[n.jsx("strong",{children:t("citation.year","Year:")})," ",e.year]}),e.volume&&n.jsxs("div",{children:[n.jsx("strong",{children:t("citation.volume","Volume:")})," ",e.volume,e.issue&&`(${e.issue})`]}),e.pages&&n.jsxs("div",{children:[n.jsx("strong",{children:t("citation.pages","Pages:")})," ",e.pages]}),e.doi&&n.jsxs("div",{children:[n.jsx("strong",{children:t("citation.doi","DOI:")})," ",n.jsx("a",{href:`https://doi.org/${e.doi}`,target:"_blank",rel:"noopener noreferrer",children:e.doi})]}),e.pmid&&n.jsxs("div",{children:[n.jsx("strong",{children:t("citation.pmid","PMID:")})," ",n.jsx("a",{href:`https://pubmed.ncbi.nlm.nih.gov/${e.pmid}`,target:"_blank",rel:"noopener noreferrer",children:e.pmid})]}),e.abstract&&n.jsxs("div",{style:{marginTop:"8px"},children:[n.jsx("strong",{children:t("citation.abstract","Abstract:")}),n.jsx("p",{style:{margin:"8px 0 0 0",color:"var(--nice-text, #444)"},children:e.abstract})]})]})]})}const Nt=[],At={series:[],xAxes:[],yAxes:[],annotations:[],selectedSeries:[],zoom:{x:null,y:null},cursor:null,hoveredPoint:null};function Ie(e){return e.reduce((t,r)=>t+r,0)/e.length}function Dt(e){const t=[...e].sort((s,i)=>s-i),r=Math.floor(t.length/2);return t.length%2?t[r]:(t[r-1]+t[r])/2}function Re(e){const t=Ie(e),r=e.map(s=>Math.pow(s-t,2));return Math.sqrt(Ie(r))}function zt(e){return Re(e)/Math.sqrt(e.length)}function It(e){const t=Ie(e),r=zt(e),s=1.96;return[t-s*r,t+s*r]}function Et(e){const t=e.length,r=e.map(M=>typeof M.x=="number"?M.x:0),s=e.map(M=>M.y),i=r.reduce((M,E)=>M+E,0),o=s.reduce((M,E)=>M+E,0),a=r.reduce((M,E,q)=>M+E*s[q],0),l=r.reduce((M,E)=>M+E*E,0),c=(t*a-i*o)/(t*l-i*i),u=(o-c*i)/t,x=o/t,y=s.reduce((M,E)=>M+Math.pow(E-x,2),0),m=1-s.reduce((M,E,q)=>M+Math.pow(E-(c*r[q]+u),2),0)/y;return{slope:c,intercept:u,r2:m}}function Ft(e,t){const r=Ie(e),s=Ie(t),i=Re(e)**2,o=Re(t)**2,a=e.length,l=t.length,c=((a-1)*i+(l-1)*o)/(a+l-2),u=Math.sqrt(c*(1/a+1/l)),x=(r-s)/u,y=Math.exp(-.717*Math.abs(x)-.416*x*x);return{t:x,p:y,significant:y<.05}}function Oe(e,t,r,s=5){const o=(t-e)/(s-1);return Array.from({length:s},(a,l)=>e+l*o)}function We(e,t){return Math.abs(e)>=1e6?(e/1e6).toFixed(1)+"M":Math.abs(e)>=1e3?(e/1e3).toFixed(1)+"K":Math.abs(e)<.01?e.toExponential(2):e.toFixed(2).replace(/\.?0+$/,"")}function Bt({series:e=Nt,title:t,subtitle:r,width:s="100%",height:i=400,type:o="scatter",xAxis:a,yAxis:l,statOverlays:c=[],annotations:u=[],legend:x={show:!0,position:"top",orientation:"horizontal",interactive:!0},tooltip:y={enabled:!0,mode:"point"},zoom:f={enabled:!0,mode:"xy",wheel:!0,drag:!0,resetButton:!0},export:m,statisticalTests:M=[],gridLines:E=!0,aspectRatio:q,animation:re=!0,theme:U="light",onPointClick:te,onPointHover:B,onZoomChange:ie,onAnnotationChange:me,onExport:ee,className:je,style:ue}){const{t:Q}=pe.useNiceTranslation(),oe=h.useRef(null),P=h.useRef(null);h.useRef(null);const[se,ge]=h.useState({...At,series:e,annotations:u}),[we,xe]=h.useState({width:0,height:0}),[Y,H]=h.useState({x:null,y:null}),[he,Z]=h.useState(null),[ne,fe]=h.useState(new Set(e.map(d=>d.id))),$=h.useMemo(()=>{const d=e.filter(_=>ne.has(_.id)&&_.visible!==!1);if(d.length===0)return{xMin:0,xMax:1,yMin:0,yMax:1};let j=1/0,k=-1/0,L=1/0,V=-1/0;for(const _ of d)for(const G of _.data){const be=typeof G.x=="number"?G.x:0;if(j=Math.min(j,be),k=Math.max(k,be),L=Math.min(L,G.y),V=Math.max(V,G.y),G.error){const[ce,ye]=Array.isArray(G.error)?G.error:[-G.error,G.error];L=Math.min(L,G.y+ce),V=Math.max(V,G.y+ye)}}const de=(k-j)*.05||.5,le=(V-L)*.05||.5;return{xMin:j-de,xMax:k+de,yMin:L-le,yMax:V+le}},[e,ne]),J=h.useMemo(()=>{const d={};for(const j of e){if(!ne.has(j.id))continue;const k=j.data.map(L=>L.y);c.includes("mean")&&(d[`${j.id}_mean`]=Ie(k)),c.includes("median")&&(d[`${j.id}_median`]=Dt(k)),c.includes("std-dev")&&(d[`${j.id}_std`]=Re(k)),c.includes("regression")&&(d[`${j.id}_regression`]=Et(j.data)),c.includes("confidence-interval")&&(d[`${j.id}_ci95`]=It(k))}return d},[e,ne,c]),ae=h.useMemo(()=>M.map(d=>{if(d.type==="t-test"&&d.series.length===2){const j=e.find(L=>L.id===d.series[0]),k=e.find(L=>L.id===d.series[1]);if(j&&k){const L=Ft(j.data.map(V=>V.y),k.data.map(V=>V.y));return{...d,result:{statistic:L.t,pValue:L.p,significant:L.significant,interpretation:L.significant?`Significant difference (p = ${L.p.toFixed(4)})`:`No significant difference (p = ${L.p.toFixed(4)})`}}}}return d}),[M,e]),S=h.useCallback(d=>{fe(j=>{const k=new Set(j);return k.has(d)?k.delete(d):k.add(d),k})},[]),D=h.useCallback(()=>{H({x:null,y:null}),ie==null||ie(null,null)},[ie]),A=h.useMemo(()=>{switch(U){case"dark":return["var(--nice-primary-light, #60a5fa)","var(--nice-color-accent-pink, #f472b6)","var(--nice-success-light, #34d399)","var(--nice-warning-light, #fbbf24)","var(--nice-accent, #a78bfa)","#fb923c"];case"publication":return["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b"];case"presentation":return["var(--nice-primary, #3b82f6)","var(--nice-danger, #ef4444)","var(--nice-success, #22c55e)","var(--nice-warning, #f59e0b)","var(--nice-accent, #8b5cf6)","var(--nice-color-accent-pink, #ec4899)"];default:return["var(--nice-primary-hover, #2563eb)","var(--nice-danger-dark, #dc2626)","var(--nice-success-dark, #16a34a)","#ca8a04","var(--nice-accent, #7c3aed)","var(--nice-color-accent-pink, #db2777)"]}},[U]),N=h.useMemo(()=>{switch(U){case"dark":return{bg:"var(--nice-bg-secondary, #1f2937)",text:"var(--nice-text-primary, #f3f4f6)",grid:"var(--nice-text, #374151)",axis:"var(--nice-text-muted, #9ca3af)",tooltip:"var(--nice-text, #374151)"};case"publication":return{bg:"var(--nice-bg, #fff)",text:"var(--nice-text, #000000)",grid:"var(--nice-border, #e5e5e5)",axis:"var(--nice-text, #333333)",tooltip:"var(--nice-bg, #fff)"};default:return{bg:"var(--nice-bg, #fff)",text:"var(--nice-text, #1f2937)",grid:"var(--nice-border, #e5e7eb)",axis:"var(--nice-text-secondary, #4b5563)",tooltip:"var(--nice-bg, #fff)"}}},[U]),R=(d,j)=>({x:10+((typeof d.x=="number"?d.x:j)-$.xMin)/($.xMax-$.xMin)*85,y:90-(d.y-$.yMin)/($.yMax-$.yMin)*85}),X=he?e.find(d=>d.id===he.seriesId):void 0,T=he?X==null?void 0:X.data[he.pointIndex]:void 0,W=he&&T?R(T,he.pointIndex):null,g=((m==null?void 0:m.formats)??[]).filter(d=>d!=="pdf"||!!ee),z=d=>{if(ee){ee(d);return}const j=(t||"chart").replace(/[^\w-]+/g,"_"),k=(ce,ye)=>{const ve=URL.createObjectURL(ce),$e=document.createElement("a");$e.href=ve,$e.download=`${j}.${ye}`,$e.click(),URL.revokeObjectURL(ve)},L=e.filter(ce=>ne.has(ce.id)&&ce.visible!==!1);if(d==="csv"){const ce=ve=>JSON.stringify(ve instanceof Date?ve.toISOString():ve??""),ye=L.flatMap(ve=>ve.data.map($e=>[ve.name,$e.x,$e.y].map(ce).join(",")));k(new Blob([["series,x,y",...ye].join(`
|
|
60
|
+
`)],{type:"text/csv"}),"csv");return}if(d==="json"){const ce=L.map(ye=>({id:ye.id,name:ye.name,data:ye.data}));k(new Blob([JSON.stringify(ce,null,2)],{type:"application/json"}),"json");return}const V=P.current;if(!V)return;const de=new XMLSerializer().serializeToString(V);if(d==="svg"){k(new Blob([de],{type:"image/svg+xml"}),"svg");return}const le=V.getBoundingClientRect(),_=((m==null?void 0:m.dpi)??96)/96,G=document.createElement("canvas");G.width=Math.round(((m==null?void 0:m.width)??le.width)*_),G.height=Math.round(((m==null?void 0:m.height)??le.height)*_);const be=new Image;be.onload=()=>{var ce;(ce=G.getContext("2d"))==null||ce.drawImage(be,0,0,G.width,G.height),G.toBlob(ye=>ye&&k(ye,"png"))},be.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(de)}`};return n.jsxs("div",{ref:oe,className:`nice-scientific-chart nice-scientific-chart--${U} ${je||""}`,style:{width:s,height:q?"auto":i,aspectRatio:q==null?void 0:q.toString(),backgroundColor:N.bg,color:N.text,fontFamily:U==="publication"?"Times New Roman, serif":"system-ui, sans-serif",...ue},children:[t&&n.jsxs("div",{className:"nice-scientific-chart__title",children:[t,r&&n.jsx("div",{className:"nice-scientific-chart__subtitle",style:{color:N.axis},children:r})]}),x.show&&n.jsx("div",{className:"nice-scientific-chart__legend",style:{flexDirection:x.orientation==="vertical"?"column":"row"},children:e.map((d,j)=>n.jsxs("button",{type:"button",className:"nice-scientific-chart__legend-item",onClick:()=>x.interactive&&S(d.id),style:{cursor:x.interactive?"pointer":"default",opacity:ne.has(d.id)?1:.4},children:[n.jsx("span",{className:"nice-scientific-chart__swatch",style:{backgroundColor:d.color||A[j%A.length]}}),d.name]},d.id))}),n.jsxs("div",{className:"nice-scientific-chart__canvas",children:[n.jsxs("svg",{ref:P,width:"100%",height:"100%",children:[E&&n.jsxs("g",{className:"nice-scientific-chart__grid",stroke:N.grid,strokeWidth:1,children:[[0,.25,.5,.75,1].map(d=>n.jsx("line",{x1:"10%",y1:`${d*100}%`,x2:"95%",y2:`${d*100}%`,strokeDasharray:"2,2"},`h-${d}`)),[0,.25,.5,.75,1].map(d=>n.jsx("line",{x1:`${10+d*85}%`,y1:"5%",x2:`${10+d*85}%`,y2:"90%",strokeDasharray:"2,2"},`v-${d}`))]}),e.filter(d=>ne.has(d.id)&&d.visible!==!1).map((d,j)=>{var V,de,le;const k=d.color||A[j%A.length],L=d.type||o;return n.jsx("g",{className:"nice-scientific-chart__series",children:L==="scatter"||L==="line"?n.jsxs(n.Fragment,{children:[L==="line"&&d.data.length>1&&n.jsx("svg",{x:"0",y:"0",width:"100%",height:"100%",viewBox:"0 0 100 100",preserveAspectRatio:"none",style:{overflow:"visible"},children:n.jsx("polyline",{fill:"none",stroke:k,strokeWidth:((V=d.line)==null?void 0:V.width)||2,vectorEffect:"non-scaling-stroke",strokeDasharray:((de=d.line)==null?void 0:de.style)==="dashed"?"5,5":((le=d.line)==null?void 0:le.style)==="dotted"?"2,2":void 0,points:d.data.map((_,G)=>{const be=10+((typeof _.x=="number"?_.x:G)-$.xMin)/($.xMax-$.xMin)*85,ce=90-(_.y-$.yMin)/($.yMax-$.yMin)*85;return`${be},${ce}`}).join(" ")})}),d.data.map((_,G)=>{var ve,$e,Ce,v,w;const be=10+((typeof _.x=="number"?_.x:G)-$.xMin)/($.xMax-$.xMin)*85,ce=90-(_.y-$.yMin)/($.yMax-$.yMin)*85,ye=_.size||((ve=d.marker)==null?void 0:ve.size)||6;return n.jsxs("g",{className:"nice-scientific-chart__point",children:[_.error&&n.jsx("line",{x1:`${be}%`,y1:`${90-(_.y+(Array.isArray(_.error)?_.error[1]:_.error)-$.yMin)/($.yMax-$.yMin)*85}%`,x2:`${be}%`,y2:`${90-(_.y-(Array.isArray(_.error)?Math.abs(_.error[0]):_.error)-$.yMin)/($.yMax-$.yMin)*85}%`,stroke:k,strokeWidth:1}),n.jsx("circle",{cx:`${be}%`,cy:`${ce}%`,r:ye/2,fill:_.color||(($e=d.marker)==null?void 0:$e.fillColor)||k,stroke:((Ce=d.marker)==null?void 0:Ce.strokeColor)||k,strokeWidth:((v=d.marker)==null?void 0:v.strokeWidth)||1,opacity:((w=d.marker)==null?void 0:w.opacity)??1,style:{cursor:te?"pointer":void 0},onMouseEnter:()=>{Z({seriesId:d.id,pointIndex:G}),B==null||B(_,d)},onMouseLeave:()=>{Z(null),B==null||B(null,null)},onClick:I=>te==null?void 0:te(_,d,I)})]},G)}),J[`${d.id}_regression`]&&n.jsx("line",{x1:"10%",y1:`${90-(J[`${d.id}_regression`].intercept+J[`${d.id}_regression`].slope*$.xMin-$.yMin)/($.yMax-$.yMin)*85}%`,x2:"95%",y2:`${90-(J[`${d.id}_regression`].intercept+J[`${d.id}_regression`].slope*$.xMax-$.yMin)/($.yMax-$.yMin)*85}%`,stroke:k,strokeWidth:1,strokeDasharray:"5,3",opacity:.7}),J[`${d.id}_mean`]&&n.jsx("line",{x1:"10%",y1:`${90-(J[`${d.id}_mean`]-$.yMin)/($.yMax-$.yMin)*85}%`,x2:"95%",y2:`${90-(J[`${d.id}_mean`]-$.yMin)/($.yMax-$.yMin)*85}%`,stroke:k,strokeWidth:1,strokeDasharray:"10,5",opacity:.5})]}):null},d.id)}),n.jsxs("g",{className:"nice-scientific-chart__axes",stroke:N.axis,strokeWidth:1,children:[n.jsx("line",{x1:"10%",y1:"90%",x2:"95%",y2:"90%"}),n.jsx("line",{x1:"10%",y1:"5%",x2:"10%",y2:"90%"}),Oe($.xMin,$.xMax,"linear",6).map((d,j)=>n.jsxs("g",{children:[n.jsx("line",{x1:`${10+j*17}%`,y1:"90%",x2:`${10+j*17}%`,y2:"92%"}),n.jsx("text",{x:`${10+j*17}%`,y:"96%",textAnchor:"middle",fill:N.axis,fontSize:"0.75rem",children:We(d)})]},`x-${j}`)),Oe($.yMin,$.yMax,"linear",6).map((d,j)=>n.jsxs("g",{children:[n.jsx("line",{x1:"8%",y1:`${90-j*17}%`,x2:"10%",y2:`${90-j*17}%`}),n.jsx("text",{x:"7%",y:`${90-j*17}%`,textAnchor:"end",dominantBaseline:"middle",fill:N.axis,fontSize:"0.75rem",children:We(d)})]},`y-${j}`))]}),u.filter(d=>d.visible!==!1).map(d=>{var j,k,L,V,de,le,_;return n.jsxs("g",{className:"nice-scientific-chart__annotation",children:[d.type==="text"&&d.text&&n.jsx("text",{x:`${10+(d.position.x-$.xMin)/($.xMax-$.xMin)*85}%`,y:`${90-(d.position.y-$.yMin)/($.yMax-$.yMin)*85}%`,fill:((j=d.style)==null?void 0:j.color)||N.text,fontSize:((k=d.style)==null?void 0:k.fontSize)||12,fontWeight:(L=d.style)==null?void 0:L.fontWeight,children:d.text}),d.type==="line"&&n.jsx("line",{x1:`${10+(d.position.x-$.xMin)/($.xMax-$.xMin)*85}%`,y1:`${90-(d.position.y-$.yMin)/($.yMax-$.yMin)*85}%`,x2:`${10+(d.position.x2-$.xMin)/($.xMax-$.xMin)*85}%`,y2:`${90-(d.position.y2-$.yMin)/($.yMax-$.yMin)*85}%`,stroke:((V=d.style)==null?void 0:V.color)||N.text,strokeWidth:((de=d.style)==null?void 0:de.lineWidth)||1,strokeDasharray:((le=d.style)==null?void 0:le.lineStyle)==="dashed"?"5,5":((_=d.style)==null?void 0:_.lineStyle)==="dotted"?"2,2":void 0})]},d.id)})]}),y.enabled&&he&&W&&n.jsx("div",{className:"nice-scientific-chart__tooltip",style:{background:N.tooltip,borderColor:N.grid,left:`${W.x}%`,top:`${W.y}%`,transform:`translate(${W.x>65?"calc(-100% - 10px)":"10px"}, ${W.y<25?"10px":"calc(-100% - 10px)"})`},children:(()=>{const d=X,j=T;return!d||!j?null:y.format?y.format(j,d):n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"nice-scientific-chart__tooltip-title",children:d.name}),n.jsxs("div",{children:["X: ",j.x instanceof Date?j.x.toISOString():String(j.x)]}),n.jsxs("div",{children:["Y: ",j.y.toFixed(4)]}),j.error&&n.jsx("div",{children:Q("scientificChart.error","Error: ±{error}").replace("{error}",String(Array.isArray(j.error)?`${j.error[0]}, +${j.error[1]}`:j.error))})]})})()})]}),ae.some(d=>d.result)&&n.jsxs("div",{className:"nice-scientific-chart__stats",style:{borderTopColor:N.grid},children:[n.jsx("strong",{children:Q("scientificChart.statisticalTests","Statistical Tests:")}),ae.filter(d=>d.result).map((d,j)=>n.jsxs("div",{children:[d.type,": ",d.result.interpretation]},j))]}),f.enabled&&f.resetButton&&(Y.x||Y.y)&&n.jsx("button",{type:"button",className:"nice-scientific-chart__reset-zoom",onClick:D,style:{background:N.bg,borderColor:N.grid},children:Q("scientificChart.resetZoom","Reset Zoom")}),g.length>0&&n.jsxs("div",{className:"nice-scientific-chart__export",style:{borderTopColor:N.grid},children:[n.jsx("span",{className:"nice-scientific-chart__export-label",children:Q("scientificChart.export","Export:")}),g.map(d=>n.jsx("button",{type:"button",className:"nice-scientific-chart__export-btn",style:{borderColor:N.grid},onClick:()=>z(d),children:d.toUpperCase()},d))]})]})}const Rt=[],Xe={rotationX:25,rotationY:-45,rotationZ:0,zoom:1,panX:0,panY:0};function Tt(e,t){const r=t*Math.PI/180,s=Math.cos(r),i=Math.sin(r);return{x:e.x,y:e.y*s-e.z*i,z:e.y*i+e.z*s}}function Lt(e,t){const r=t*Math.PI/180,s=Math.cos(r),i=Math.sin(r);return{x:e.x*s+e.z*i,y:e.y,z:-e.x*i+e.z*s}}function _t(e,t){const r=t*Math.PI/180,s=Math.cos(r),i=Math.sin(r);return{x:e.x*s-e.y*i,y:e.x*i+e.y*s,z:e.z}}function Ne(e,t,r){let s=Tt(e,r.rotationX);s=Lt(s,r.rotationY),s=_t(s,r.rotationZ);const i=s.z+t,o=t/Math.max(i,.1);return{x:(s.x*o*r.zoom+r.panX)*100+50,y:(-s.y*o*r.zoom+r.panY)*100+50,depth:i}}function De(e,t,r,s){const i=Math.max(0,Math.min(1,(e-t)/(r-t))),o={viridis:[[68,1,84],[59,82,139],[33,145,140],[94,201,98],[253,231,37]],plasma:[[13,8,135],[126,3,168],[204,71,120],[248,149,64],[240,249,33]],inferno:[[0,0,4],[87,16,110],[188,55,84],[249,142,9],[252,255,164]],magma:[[0,0,4],[81,18,124],[183,55,121],[254,159,109],[252,253,191]],cividis:[[0,32,77],[57,86,109],[128,133,121],[200,178,107],[253,231,55]],jet:[[0,0,127],[0,0,255],[0,255,255],[255,255,0],[255,0,0],[127,0,0]],rainbow:[[150,0,90],[0,0,200],[0,200,200],[0,200,0],[200,200,0],[200,0,0]],coolwarm:[[59,76,192],[98,130,234],[221,221,221],[220,170,132],[180,4,38]],RdBu:[[103,0,31],[178,24,43],[244,165,130],[247,247,247],[146,197,222],[33,102,172],[5,48,97]],spectral:[[158,1,66],[213,62,79],[253,174,97],[255,255,191],[171,221,164],[43,131,186],[94,79,162]],turbo:[[48,18,59],[86,121,245],[51,185,131],[192,212,49],[249,141,10],[122,4,3]],grayscale:[[0,0,0],[255,255,255]]},a=o[s]||o.viridis,l=i*(a.length-1),c=Math.floor(l),u=l-c;if(c>=a.length-1){const E=a[a.length-1];return`rgb(${E[0]}, ${E[1]}, ${E[2]})`}const x=a[c],y=a[c+1],f=Math.round(x[0]+u*(y[0]-x[0])),m=Math.round(x[1]+u*(y[1]-x[1])),M=Math.round(x[2]+u*(y[2]-x[2]));return`rgb(${f}, ${m}, ${M})`}function Ot({data:e=Rt,title:t,width:r="100%",height:s=500,scene:i={},showColorBar:o=!0,animation:a,showLegend:l=!0,legendPosition:c="top-right",enableRotation:u=!0,enableZoom:x=!0,enablePan:y=!0,showAxes:f=!0,showAxisLabels:m=!0,focalLength:M=3,theme:E="light",onCameraChange:q,onPointClick:re,onPointHover:U,className:te,style:B}){const{t:ie}=pe.useNiceTranslation(),me=h.useRef(null),[ee,je]=h.useState(Xe),[ue,Q]=h.useState(!1),[oe,P]=h.useState(null),[se,ge]=h.useState(null),[we,xe]=h.useState(0),Y=h.useMemo(()=>{let S=1/0,D=-1/0,A=1/0,N=-1/0,R=1/0,X=-1/0,T=1/0,W=-1/0;for(const z of e)if(z.type==="scatter3d")for(const d of z.points)S=Math.min(S,d.x),D=Math.max(D,d.x),A=Math.min(A,d.y),N=Math.max(N,d.y),R=Math.min(R,d.z),X=Math.max(X,d.z),typeof d.color=="number"&&(T=Math.min(T,d.color),W=Math.max(W,d.color));else if(z.type==="surface"||z.type==="wireframe"){const d=z;for(const j of d.xData)S=Math.min(S,j),D=Math.max(D,j);for(const j of d.yData)A=Math.min(A,j),N=Math.max(N,j);for(const j of d.zData)for(const k of j)R=Math.min(R,k),X=Math.max(X,k),T=Math.min(T,k),W=Math.max(W,k)}const g=Math.max(D-S,N-A,X-R)||1;return{xMin:S,xMax:D,yMin:A,yMax:N,zMin:R,zMax:X,colorMin:T,colorMax:W,maxRange:g}},[e]),H=h.useCallback(S=>{const D=2/Y.maxRange;return{x:(S.x-(Y.xMin+Y.xMax)/2)*D,y:(S.y-(Y.yMin+Y.yMax)/2)*D,z:(S.z-(Y.zMin+Y.zMax)/2)*D}},[Y]),he=h.useCallback(S=>{!u&&!y||(Q(!0),P({x:S.clientX,y:S.clientY,viewState:{...ee}}))},[u,y,ee]),Z=h.useCallback(S=>{if(!ue||!oe)return;const D=S.clientX-oe.x,A=S.clientY-oe.y;S.shiftKey&&y?je({...oe.viewState,panX:oe.viewState.panX+D*.002,panY:oe.viewState.panY+A*.002}):u&&je({...oe.viewState,rotationY:oe.viewState.rotationY+D*.5,rotationX:oe.viewState.rotationX+A*.5})},[ue,oe,u,y]),ne=h.useCallback(()=>{Q(!1),P(null)},[]),fe=h.useCallback(S=>{if(!x)return;S.preventDefault();const D=S.deltaY>0?.9:1.1;je(A=>({...A,zoom:Math.max(.1,Math.min(10,A.zoom*D))}))},[x]),$=h.useMemo(()=>{switch(E){case"dark":return{bg:"var(--nice-bg, #1a1a2e)",text:"var(--nice-text-secondary, #e0e0e0)",axis:"var(--nice-text-secondary, #555)",grid:"var(--nice-text, #333)"};case"scientific":return{bg:"var(--nice-bg-secondary, #f8f8f8)",text:"var(--nice-text, #333)",axis:"var(--nice-text-secondary, #666)",grid:"var(--nice-border, #ddd)"};default:return{bg:"var(--nice-bg, #fff)",text:"var(--nice-text, #333)",axis:"var(--nice-text-secondary, #888)",grid:"var(--nice-border, #e0e0e0)"}}},[E]),J=h.useMemo(()=>{var D;const S=[];for(const A of e)if(A.type==="scatter3d"){const N=A,R=N.points.map(X=>{var d,j,k,L,V;const T=H(X),W=Ne(T,M,ee);let g=(d=N.marker)==null?void 0:d.color;if(Array.isArray((j=N.marker)==null?void 0:j.color)){const de=N.points.indexOf(X);g=De(N.marker.color[de],Y.colorMin,Y.colorMax,((k=N.marker)==null?void 0:k.colorScale)||"viridis")}else typeof X.color=="number"&&(g=De(X.color,Y.colorMin,Y.colorMax,((L=N.marker)==null?void 0:L.colorScale)||"viridis"));const z=Array.isArray(X.size)?X.size[0]:X.size||((V=N.marker)==null?void 0:V.size)||5;return{...W,color:g,size:z,original:X}});S.push({type:"scatter",points:R,data:A})}else if(A.type==="surface"||A.type==="wireframe"){const N=A,R=[];for(let X=0;X<N.xData.length;X++)for(let T=0;T<N.yData.length;T++){const W={x:N.xData[X],y:N.yData[T],z:N.zData[X][T]},g=H(W),z=Ne(g,M,ee),d=De(((D=N.colorData)==null?void 0:D[X][T])??N.zData[X][T],Y.colorMin,Y.colorMax,N.colorScale||"viridis");R.push({...z,color:d,size:3,original:W})}S.push({type:A.type,points:R,data:A})}for(const A of S)A.points.sort((N,R)=>N.depth-R.depth);return S},[e,ee,M,H,Y]),ae=h.useMemo(()=>{var A,N,R;if(!f)return null;const S=1.2,D={x:[Ne({x:-S,y:0,z:0},M,ee),Ne({x:S,y:0,z:0},M,ee)],y:[Ne({x:0,y:-S,z:0},M,ee),Ne({x:0,y:S,z:0},M,ee)],z:[Ne({x:0,y:0,z:-S},M,ee),Ne({x:0,y:0,z:S},M,ee)]};return n.jsxs("g",{className:"nice-3d-plot__axes",children:[n.jsx("line",{x1:`${D.x[0].x}%`,y1:`${D.x[0].y}%`,x2:`${D.x[1].x}%`,y2:`${D.x[1].y}%`,stroke:"var(--nice-danger, #e74c3c)",strokeWidth:1.5}),m&&n.jsx("text",{x:`${D.x[1].x+2}%`,y:`${D.x[1].y}%`,fill:"var(--nice-danger, #e74c3c)",fontSize:"12",children:((A=i.xAxis)==null?void 0:A.title)||"X"}),n.jsx("line",{x1:`${D.y[0].x}%`,y1:`${D.y[0].y}%`,x2:`${D.y[1].x}%`,y2:`${D.y[1].y}%`,stroke:"var(--nice-success, #2ecc71)",strokeWidth:1.5}),m&&n.jsx("text",{x:`${D.y[1].x}%`,y:`${D.y[1].y-2}%`,fill:"var(--nice-success, #2ecc71)",fontSize:"12",textAnchor:"middle",children:((N=i.yAxis)==null?void 0:N.title)||"Y"}),n.jsx("line",{x1:`${D.z[0].x}%`,y1:`${D.z[0].y}%`,x2:`${D.z[1].x}%`,y2:`${D.z[1].y}%`,stroke:"var(--nice-primary, #3498db)",strokeWidth:1.5}),m&&n.jsx("text",{x:`${D.z[1].x+2}%`,y:`${D.z[1].y}%`,fill:"var(--nice-primary, #3498db)",fontSize:"12",children:((R=i.zAxis)==null?void 0:R.title)||"Z"})]})},[f,m,ee,M,i]);return n.jsxs("div",{ref:me,className:`nice-3d-plot nice-3d-plot--${E}${ue?" nice-3d-plot--dragging":""} ${te||""}`,style:{width:r,height:s,backgroundColor:$.bg,color:$.text,...B},onMouseDown:he,onMouseMove:Z,onMouseUp:ne,onMouseLeave:ne,onWheel:fe,children:[t&&n.jsx("div",{className:"nice-3d-plot__title",children:t}),n.jsxs("svg",{width:"100%",height:"100%",className:"nice-3d-plot__canvas",children:[ae,J.map((S,D)=>n.jsxs("g",{className:"nice-3d-plot__data",children:[S.type==="scatter"&&S.points.map((A,N)=>{var R;return n.jsx("circle",{cx:`${A.x}%`,cy:`${A.y}%`,r:A.size||4,fill:A.color||"var(--nice-primary, #3498db)",opacity:((R=S.data.marker)==null?void 0:R.opacity)??.8,style:{cursor:re?"pointer":void 0},onMouseEnter:()=>{ge({point:A.original,dataIndex:D}),U==null||U(A.original,D)},onMouseLeave:()=>{ge(null),U==null||U(null,D)},onClick:()=>re==null?void 0:re(A.original,D)},N)}),(S.type==="surface"||S.type==="wireframe")&&S.points.map((A,N)=>n.jsx("rect",{x:`${A.x-1}%`,y:`${A.y-1}%`,width:"2%",height:"2%",fill:A.color||"var(--nice-primary, #3498db)",opacity:S.data.opacity??.7},N))]},S.data.id||D))]}),l&&e.length>1&&n.jsx("div",{style:{position:"absolute",padding:"8px",background:"var(--nice-overlay-light-90, rgba(255, 255, 255, 0.9))",borderRadius:4,fontSize:"0.8rem",...c==="top-right"&&{top:8,right:8},...c==="top-left"&&{top:8,left:8},...c==="bottom-right"&&{bottom:8,right:8},...c==="bottom-left"&&{bottom:8,left:8}},children:e.map((S,D)=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[n.jsx("span",{style:{width:12,height:12,background:"var(--nice-primary, #3498db)",borderRadius:2}}),S.name]},S.id||D))}),o&&Number.isFinite(Y.colorMin)&&Number.isFinite(Y.colorMax)&&n.jsxs("div",{style:{position:"absolute",right:16,top:"50%",transform:"translateY(-50%)",width:16,height:150,background:`linear-gradient(to top, ${De(0,0,1,"viridis")}, ${De(.5,0,1,"viridis")}, ${De(1,0,1,"viridis")})`,borderRadius:2,border:"1px solid var(--nice-border, #ccc)"},children:[n.jsx("div",{style:{position:"absolute",top:-16,right:20,fontSize:"0.7rem"},children:Y.colorMax.toFixed(2)}),n.jsx("div",{style:{position:"absolute",bottom:-16,right:20,fontSize:"0.7rem"},children:Y.colorMin.toFixed(2)})]}),se&&n.jsxs("div",{style:{position:"absolute",bottom:8,left:8,background:"var(--nice-overlay-80, rgba(0, 0, 0, 0.8))",color:"var(--nice-color-white, #fff)",padding:"4px 8px",borderRadius:4,fontSize:"0.75rem"},children:["X: ",se.point.x.toFixed(4),", Y: ",se.point.y.toFixed(4),", Z:"," ",se.point.z.toFixed(4)]}),n.jsx("div",{style:{position:"absolute",bottom:8,right:8,display:"flex",gap:4},children:n.jsx("button",{onClick:()=>je(Xe),style:{padding:"4px 8px",fontSize:"0.75rem",cursor:"pointer"},children:ie("plot3d.resetView","Reset View")})})]})}const He={H:"var(--nice-bg, #fff)",C:"#909090",N:"#3050F8",O:"#FF0D0D",S:"#FFFF30",P:"#FF8000",F:"#90E050",Cl:"#1FF01F",Br:"#A62929",I:"#940094",He:"#D9FFFF",Ne:"#B3E3F5",Ar:"#80D1E3",Kr:"#5CB8D1",Xe:"#429EB0",Li:"#CC80FF",Na:"#AB5CF2",K:"#8F40D4",Rb:"#702EB0",Cs:"#57178F",Be:"#C2FF00",Mg:"#8AFF00",Ca:"#3DFF00",Sr:"var(--nice-success, #00ff00)",Ba:"#00C900",B:"#FFB5B5",Al:"#BFA6A6",Ga:"#C28F8F",In:"#A67573",Tl:"#A6544D",Si:"#F0C8A0",Ge:"#668F8F",Sn:"#668080",Pb:"#575961",As:"#BD80E3",Sb:"#9E63B5",Bi:"#9E4FB5",Se:"#FFA100",Te:"#D47A00",Po:"#AB5C00",Fe:"#E06633",Co:"#F090A0",Ni:"#50D050",Cu:"#C88033",Zn:"#7D80B0",Mn:"#9C7AC7",Cr:"#8A99C7",V:"#A6A6AB",Ti:"#BFC2C7",Sc:"#E6E6E6",Au:"#FFD123",Ag:"#C0C0C0",Pt:"#D0D0E0",Pd:"#006985",Ru:"#248F8F",Rh:"#0A7D8C",Os:"#266696",Ir:"#175487"},Fe={H:.31,C:.77,N:.71,O:.66,S:1.05,P:1.07,F:.57,Cl:1.02,Br:1.2,I:1.39,He:.28,Ne:.58,Ar:1.06,Li:1.28,Na:1.66,K:2.03,Mg:1.41,Ca:1.76,Fe:1.26,Zn:1.22,Cu:1.28,Ni:1.24},Wt={H:1.2,C:1.7,N:1.55,O:1.52,S:1.8,P:1.8,F:1.47,Cl:1.75,Br:1.85,I:1.98,He:1.4,Ne:1.54,Ar:1.88,Li:1.82,Na:2.27,K:2.75,Mg:1.73,Ca:2.31,Fe:2,Zn:1.39,Cu:1.4,Ni:1.63};function Pe(e){const t=[],r=[],s=new Map,i=new Map;let o="Unknown";const a=e.split(`
|
|
61
|
+
`);for(const l of a){const c=l.substring(0,6).trim();if(c==="HEADER")o=l.substring(10,50).trim()||o;else if(c==="ATOM"||c==="HETATM"){const u=parseInt(l.substring(6,11).trim(),10),x=l.substring(12,16).trim(),y=l.substring(17,20).trim(),f=l.substring(21,22).trim()||"A",m=parseInt(l.substring(22,26).trim(),10),M=parseFloat(l.substring(30,38).trim()),E=parseFloat(l.substring(38,46).trim()),q=parseFloat(l.substring(46,54).trim()),re=parseFloat(l.substring(54,60).trim())||1,U=parseFloat(l.substring(60,66).trim())||0,te=l.substring(76,78).trim()||x.replace(/\d/g,"").substring(0,1),B={id:t.length,serial:u,name:x,element:te.toUpperCase(),residueName:y,residueSeq:m,chainId:f,x:M,y:E,z:q,occupancy:re,bFactor:U,color:He[te.toUpperCase()]||"var(--nice-text-secondary, #808080)",radius:Fe[te.toUpperCase()]||1.5};t.push(B);const ie=`${f}_${m}_${y}`;s.has(ie)||s.set(ie,{id:s.size,name:y,seq:m,chainId:f,atoms:[]}),s.get(ie).atoms.push(B.id),i.has(f)||i.set(f,{id:f,residues:[]})}else if(c==="CONECT"){const u=l.substring(6).trim().split(/\s+/).map(Number),x=u[0],y=t.find(f=>f.serial===x);if(y)for(let f=1;f<u.length;f++){const m=u[f],M=t.find(E=>E.serial===m);M&&y.id<M.id&&r.push({id:r.length,atom1:y.id,atom2:M.id,order:1})}}}if(r.length===0)for(let l=0;l<t.length;l++)for(let c=l+1;c<t.length;c++){const u=t[l],x=t[c],y=u.x-x.x,f=u.y-x.y,m=u.z-x.z,M=Math.sqrt(y*y+f*f+m*m),E=(Fe[u.element]||1.5)+(Fe[x.element]||1.5)+.4;M<E&&M>.4&&r.push({id:r.length,atom1:l,atom2:c,order:1,length:M})}return{id:"mol_"+Date.now(),name:o,atoms:t,bonds:r,residues:Array.from(s.values()),chains:Array.from(i.values())}}function Xt(e,t,r,s,i,o){const a=m=>m*Math.PI/180,l=t*Math.cos(a(s))-r*Math.sin(a(s)),c=t*Math.sin(a(s))+r*Math.cos(a(s)),u=e*Math.cos(a(i))+c*Math.sin(a(i)),x=-e*Math.sin(a(i))+c*Math.cos(a(i)),y=u*Math.cos(a(o))-l*Math.sin(a(o)),f=u*Math.sin(a(o))+l*Math.cos(a(o));return[y,f,x]}function Ee(e,t,r,s,i,o){const a=e-i.x,l=t-i.y,c=r-i.z,[u,x,y]=Xt(a,l,c,s.rotX,s.rotY,s.rotZ),f=500,m=f/(f+y*50);return{x:50+u*o*s.zoom*m+s.panX,y:50-x*o*s.zoom*m+s.panY,depth:y}}function Pt({molecule:e,format:t="pdb",style:r="ball-stick",colorScheme:s="element",showHydrogens:i=!0,showWaters:o=!1,showLabels:a=!1,labelType:l="element",width:c="100%",height:u=500,backgroundColor:x="#000000",enableRotation:y=!0,enableZoom:f=!0,showControls:m=!0,measurements:M=[],surfaces:E=[],labels:q=[],selection:re,highlightColor:U="var(--nice-warning, #ffff00)",spin:te=!1,spinSpeed:B=.5,onAtomClick:ie,onAtomHover:me,onSelectionChange:ee,className:je,styleOverride:ue}){const{t:Q}=pe.useNiceTranslation(),oe=h.useRef(null),[P,se]=h.useState(null),[ge,we]=h.useState({rotX:0,rotY:0,rotZ:0,zoom:1,panX:0,panY:0}),[xe,Y]=h.useState(!1),[H,he]=h.useState(null),[Z,ne]=h.useState(null),[fe,$]=h.useState(r);h.useEffect(()=>{if(!e){se(null);return}typeof e=="string"?(t==="pdb"||console.warn(`Format ${t} parsing not implemented, using PDB parser`),se(Pe(e))):se(e)},[e,t]),h.useEffect(()=>{if(!te)return;const g=setInterval(()=>{we(z=>({...z,rotY:(z.rotY+B)%360}))},16);return()=>clearInterval(g)},[te,B]);const{center:J,scale:ae}=h.useMemo(()=>{if(!P||P.atoms.length===0)return{center:{x:0,y:0,z:0},scale:1};let g=1/0,z=-1/0,d=1/0,j=-1/0,k=1/0,L=-1/0;for(const _ of P.atoms)g=Math.min(g,_.x),z=Math.max(z,_.x),d=Math.min(d,_.y),j=Math.max(j,_.y),k=Math.min(k,_.z),L=Math.max(L,_.z);const V={x:(g+z)/2,y:(d+j)/2,z:(k+L)/2},de=Math.max(z-g,j-d,L-k),le=de>0?35/de:1;return{center:V,scale:le}},[P]),S=h.useMemo(()=>P?P.atoms.filter(g=>!i&&g.element==="H"||!o&&g.residueName==="HOH"?!1:g.visible!==!1).map(g=>({atom:g,...Ee(g.x,g.y,g.z,ge,J,ae)})).sort((g,z)=>g.depth-z.depth):[],[P,ge,J,ae,i,o]),D=h.useMemo(()=>P?P.bonds.filter(g=>g.visible!==!1).map(g=>{const z=P.atoms[g.atom1],d=P.atoms[g.atom2];if(!z||!d||!i&&(z.element==="H"||d.element==="H"))return null;const j=Ee(z.x,z.y,z.z,ge,J,ae),k=Ee(d.x,d.y,d.z,ge,J,ae);return{bond:g,x1:j.x,y1:j.y,x2:k.x,y2:k.y,depth:(j.depth+k.depth)/2,color1:z.color,color2:d.color}}).filter(Boolean).sort((g,z)=>g.depth-z.depth):[],[P,ge,J,ae,i]),A=h.useCallback(g=>{y&&(Y(!0),he({x:g.clientX,y:g.clientY,view:{...ge}}))},[y,ge]),N=h.useCallback(g=>{if(!xe||!H)return;const z=g.clientX-H.x,d=g.clientY-H.y;g.shiftKey?we({...H.view,panX:H.view.panX+z*.1,panY:H.view.panY+d*.1}):we({...H.view,rotY:H.view.rotY+z*.5,rotX:H.view.rotX+d*.5})},[xe,H]),R=h.useCallback(()=>{Y(!1),he(null)},[]),X=h.useCallback(g=>{if(!f)return;g.preventDefault();const z=g.deltaY>0?.9:1.1;we(d=>({...d,zoom:Math.max(.1,Math.min(10,d.zoom*z))}))},[f]),T=h.useCallback(g=>{switch(fe){case"space-filling":return(Wt[g.element]||1.5)*4;case"ball-stick":return(Fe[g.element]||.5)*3;case"stick":case"wireframe":return 2;default:return 4}},[fe]),W=h.useCallback(g=>(fe==="wireframe"?1:fe==="stick"?3:2)*(g.order||1),[fe]);return P?n.jsxs("div",{ref:oe,className:`nice-molecular-viewer${xe?" nice-molecular-viewer--dragging":""} ${je||""}`,style:{width:c,height:u,backgroundColor:x,...ue},onMouseDown:A,onMouseMove:N,onMouseUp:R,onMouseLeave:R,onWheel:X,children:[n.jsxs("svg",{width:"100%",height:"100%",className:"nice-molecular-viewer__canvas",children:[fe!=="space-filling"&&D.map((g,z)=>n.jsx("line",{x1:`${g.x1}%`,y1:`${g.y1}%`,x2:`${g.x2}%`,y2:`${g.y2}%`,stroke:g.bond.color||"var(--nice-text-secondary, #888888)",strokeWidth:W(g.bond),strokeLinecap:"round"},`bond-${z}`)),S.map(({atom:g,x:z,y:d})=>{var V;const j=(V=re==null?void 0:re.atoms)==null?void 0:V.includes(g.id),k=(Z==null?void 0:Z.id)===g.id,L=T(g);return n.jsxs("g",{children:[n.jsx("circle",{cx:`${z}%`,cy:`${d}%`,r:L,fill:g.color||He[g.element]||"#808080",stroke:j?U:k?"#fff":"none",strokeWidth:j||k?2:0,style:{cursor:"pointer"},onMouseEnter:()=>{ne(g),me==null||me(g)},onMouseLeave:()=>{ne(null),me==null||me(null)},onClick:()=>ie==null?void 0:ie(g)}),a&&n.jsx("text",{x:`${z}%`,y:`${d-L*.15}%`,fill:"var(--nice-color-white, #fff)",fontSize:"10",textAnchor:"middle",dominantBaseline:"middle",style:{pointerEvents:"none"},children:l==="element"?g.element:l==="name"?g.name:l==="residue"?g.residueName:l==="chain"?g.chainId:l==="serial"?g.serial:g.element})]},`atom-${g.id}`)}),M.map(g=>{if(g.atoms.length<2)return null;const z=P.atoms[g.atoms[0]],d=P.atoms[g.atoms[1]];if(!z||!d)return null;const j=Ee(z.x,z.y,z.z,ge,J,ae),k=Ee(d.x,d.y,d.z,ge,J,ae);return n.jsxs("g",{children:[n.jsx("line",{x1:`${j.x}%`,y1:`${j.y}%`,x2:`${k.x}%`,y2:`${k.y}%`,stroke:g.color||"var(--nice-warning, #ffff00)",strokeWidth:1,strokeDasharray:"3,3"}),n.jsxs("text",{x:`${(j.x+k.x)/2}%`,y:`${(j.y+k.y)/2-1}%`,fill:g.color||"var(--nice-warning, #ffff00)",fontSize:"10",textAnchor:"middle",children:[g.value.toFixed(2)," ",g.unit]})]},g.id)})]}),n.jsxs("div",{style:{position:"absolute",top:8,left:8,color:"var(--nice-text-primary, #fff)",fontSize:"0.8rem"},children:[n.jsx("div",{style:{fontWeight:"bold"},children:P.name}),n.jsx("div",{children:Q("molecularViewer.atomsBonds","{atoms} atoms, {bonds} bonds").replace("{atoms}",String(P.atoms.length)).replace("{bonds}",String(P.bonds.length))}),P.formula&&n.jsx("div",{children:Q("molecularViewer.formula","Formula: {formula}").replace("{formula}",String(P.formula))})]}),Z&&n.jsxs("div",{style:{position:"absolute",bottom:8,left:8,background:"var(--nice-overlay-80, rgba(0, 0, 0, 0.8))",color:"var(--nice-color-white, #fff)",padding:"4px 8px",borderRadius:4,fontSize:"0.75rem"},children:[n.jsxs("div",{children:[n.jsx("b",{children:Z.element})," (",Z.name,")"]}),Z.residueName&&n.jsxs("div",{children:[Q("molecularViewer.residue","Residue:")," ",Z.residueName," ",Z.residueSeq]}),Z.chainId&&n.jsx("div",{children:Q("molecularViewer.chain","Chain: {chainId}").replace("{chainId}",String(Z.chainId))}),n.jsx("div",{children:Q("molecularViewer.position","Position: ({x}, {y}, {z})").replace("{x}",String(Z.x.toFixed(2))).replace("{y}",String(Z.y.toFixed(2))).replace("{z}",String(Z.z.toFixed(2)))})]}),m&&n.jsxs("div",{style:{position:"absolute",top:8,right:8,display:"flex",flexDirection:"column",gap:4},children:[n.jsxs("select",{value:fe,onChange:g=>$(g.target.value),style:{padding:"2px 4px",fontSize:"0.75rem"},children:[n.jsx("option",{value:"ball-stick",children:Q("molecularViewer.ballStick","Ball & Stick")}),n.jsx("option",{value:"space-filling",children:Q("molecularViewer.spaceFilling","Space Filling")}),n.jsx("option",{value:"stick",children:Q("molecularViewer.stick","Stick")}),n.jsx("option",{value:"wireframe",children:Q("molecularViewer.wireframe","Wireframe")})]}),n.jsx("button",{onClick:()=>we({rotX:0,rotY:0,rotZ:0,zoom:1,panX:0,panY:0}),style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:Q("molecularViewer.resetView","Reset View")})]})]}):n.jsx("div",{className:`nice-molecular-viewer nice-molecular-viewer--empty ${je||""}`,style:{width:c,height:u,backgroundColor:x,...ue},children:Q("molecularViewer.loadAMoleculePdbMol","Load a molecule (PDB, MOL, SDF)")})}function Yt(e){let t=0,r=0;function s(){var l;const o={id:`node_${r++}`};if(e[t]==="(")for(t++,o.children=[];;){const c=s();if(c&&(c.parent=o.id,o.children.push(c)),e[t]===","){t++;continue}if(e[t]===")"){t++;break}if(t>=e.length)break}let a="";for(;t<e.length&&!"[:,;()".includes(e[t]);)a+=e[t++];if(a.trim()){const c=a.match(/^([^[\]]+)?(?:\[([^\]]+)\])?$/);if(c){if(o.name=((l=c[1])==null?void 0:l.trim())||void 0,c[2]){const u=parseFloat(c[2]);isNaN(u)||(o.bootstrap=u)}}else o.name=a.trim()}if(e[t]===":"){t++;let c="";for(;t<e.length&&!"[,;()".includes(e[t]);)c+=e[t++];const u=parseFloat(c);isNaN(u)||(o.branchLength=u)}return o}return e.replace(/\s+/g,"").replace(/;$/,"")?s():null}function et(e,t=[]){if(t.push(e),e.children)for(const r of e.children)et(r,t);return t}function tt(e){return!e.children||e.children.length===0?1:e.children.reduce((t,r)=>t+tt(r),0)}function nt(e,t,r){if(!e.children||e.children.length===0||e.collapsed)return t.set(e.id,r.value),r.value+=1,t.get(e.id);let s=1/0,i=-1/0;for(const a of e.children){const l=nt(a,t,r);s=Math.min(s,l),i=Math.max(i,l)}const o=(s+i)/2;return t.set(e.id,o),o}function rt(e,t,r=0){const s=r+(e.branchLength||1);if(t.set(e.id,s),e.children&&!e.collapsed)for(const i of e.children)rt(i,t,s)}function Vt({tree:e,layout:t="rectangular",branchStyle:r="rectangular",nodeShape:s="circle",nodeSize:i=5,showBranchLengths:o=!1,showBootstrap:a=!1,bootstrapThreshold:l=70,showLeafLabels:c=!0,showInternalLabels:u=!1,labelFontSize:x=11,branchWidth:y=1.5,branchColor:f="var(--nice-text-secondary, #666666)",nodeColor:m="var(--nice-text, #333333)",highlightColor:M="var(--nice-primary, #2196f3)",clades:E=[],annotations:q=[],colorScale:re,width:U="100%",height:te=500,padding:B=40,enableZoom:ie=!0,enablePan:me=!0,showControls:ee=!0,onNodeClick:je,onNodeHover:ue,onBranchClick:Q,className:oe,style:P}){const{t:se}=pe.useNiceTranslation(),ge=h.useRef(null),[we,xe]=h.useState(1),[Y,H]=h.useState({x:0,y:0}),[he,Z]=h.useState(!1),[ne,fe]=h.useState(null),[$,J]=h.useState(null),[ae,S]=h.useState(t),[D,A]=h.useState(new Set),N=h.useMemo(()=>e?typeof e=="string"?Yt(e):e:null,[e]),R=h.useMemo(()=>{if(!N)return null;const v=w=>{var I;return{...w,collapsed:D.has(w.id),children:(I=w.children)==null?void 0:I.map(v)}};return v(N)},[N,D]),{positions:X,leafCount:T,maxX:W}=h.useMemo(()=>{if(!R)return{positions:{x:new Map,y:new Map},leafCount:0,maxX:0};const v=new Map,w=new Map,I=tt(R);nt(R,w,{value:0}),rt(R,v,0);const p=Math.max(...Array.from(v.values()));return{positions:{x:v,y:w},leafCount:I,maxX:p||1}},[R]),g=h.useMemo(()=>R?et(R):[],[R]),z=typeof U=="number"?U:800,d=typeof te=="number"?te:500,j=z-B*2,k=d-B*2,L=v=>B+v/W*j*.7,V=v=>B+v/(T-1||1)*k,de=(v,w)=>{const I=w/(T-1||1)*2*Math.PI-Math.PI/2,p=v/W*Math.min(j,k)*.4;return{x:z/2+p*Math.cos(I),y:d/2+p*Math.sin(I)}},le=v=>{const w=X.x.get(v)||0,I=X.y.get(v)||0;return ae==="radial"||ae==="circular"?de(w,I):{x:L(w),y:V(I)}},_=h.useCallback(v=>{me&&(Z(!0),fe({x:v.clientX,y:v.clientY,pan:{...Y}}))},[me,Y]),G=h.useCallback(v=>{if(!he||!ne)return;const w=v.clientX-ne.x,I=v.clientY-ne.y;H({x:ne.pan.x+w,y:ne.pan.y+I})},[he,ne]),be=h.useCallback(()=>{Z(!1),fe(null)},[]),ce=h.useCallback(v=>{if(!ie)return;v.preventDefault();const w=v.deltaY>0?.9:1.1;xe(I=>Math.max(.1,Math.min(5,I*w)))},[ie]),ye=h.useCallback(v=>{A(w=>{const I=new Set(w);return I.has(v)?I.delete(v):I.add(v),I})},[]),ve=(v,w)=>{const I=le(v.id),p=le(w.id);if(ae==="radial"||ae==="circular")return n.jsx("line",{x1:I.x,y1:I.y,x2:p.x,y2:p.y,stroke:w.color||f,strokeWidth:y});switch(r){case"rectangular":return n.jsx("path",{d:`M${I.x},${I.y} H${p.x} V${p.y}`,stroke:w.color||f,strokeWidth:y,fill:"none"});case"diagonal":return n.jsx("line",{x1:I.x,y1:I.y,x2:p.x,y2:p.y,stroke:w.color||f,strokeWidth:y});case"curved":{const b=(I.x+p.x)/2;return n.jsx("path",{d:`M${I.x},${I.y} C${b},${I.y} ${b},${p.y} ${p.x},${p.y}`,stroke:w.color||f,strokeWidth:y,fill:"none"})}default:return n.jsx("line",{x1:I.x,y1:I.y,x2:p.x,y2:p.y,stroke:w.color||f,strokeWidth:y})}},$e=v=>{const w=le(v.id),I=!v.children||v.children.length===0||v.collapsed,p=($==null?void 0:$.id)===v.id,b=p?i*1.5:i,O=(()=>{switch(s){case"circle":return n.jsx("circle",{cx:w.x,cy:w.y,r:b});case"square":return n.jsx("rect",{x:w.x-b,y:w.y-b,width:b*2,height:b*2});case"triangle":{const C=b*1.5;return n.jsx("polygon",{points:`${w.x},${w.y-C} ${w.x-C},${w.y+C} ${w.x+C},${w.y+C}`})}case"diamond":return n.jsx("polygon",{points:`${w.x},${w.y-b} ${w.x+b},${w.y} ${w.x},${w.y+b} ${w.x-b},${w.y}`});case"none":return null;default:return n.jsx("circle",{cx:w.x,cy:w.y,r:b})}})();return n.jsxs("g",{children:[O&&n.jsx("g",{fill:v.highlighted?M:v.color||m,stroke:p?M:"none",strokeWidth:2,style:{cursor:"pointer"},onMouseEnter:()=>{J(v),ue==null||ue(v)},onMouseLeave:()=>{J(null),ue==null||ue(null)},onClick:()=>je==null?void 0:je(v),onDoubleClick:()=>{v.children&&v.children.length>0&&ye(v.id)},children:O}),v.collapsed&&v.children&&n.jsx("polygon",{points:`${w.x+8},${w.y-6} ${w.x+20},${w.y} ${w.x+8},${w.y+6}`,fill:m,opacity:.5}),I&&c&&v.name&&n.jsx("text",{x:w.x+i+5,y:w.y,fontSize:x,fill:"var(--nice-text, #333)",dominantBaseline:"middle",children:v.name}),!I&&u&&v.name&&n.jsx("text",{x:w.x,y:w.y-i-3,fontSize:x*.9,fill:"var(--nice-text-secondary, #666)",textAnchor:"middle",children:v.name}),a&&v.bootstrap!==void 0&&v.bootstrap>=l&&n.jsx("text",{x:w.x,y:w.y-i-2,fontSize:x*.8,fill:"var(--nice-color-accent-pink, #e91e63)",textAnchor:"middle",children:v.bootstrap.toFixed(0)})]},v.id)},Ce=v=>{const w=[];if(v.children&&!v.collapsed)for(const I of v.children)w.push(n.jsx("g",{children:ve(v,I)},`branch-${v.id}-${I.id}`)),w.push(...Ce(I));return w};return R?n.jsxs("div",{ref:ge,className:`nice-phylogenetic-tree${he?" nice-phylogenetic-tree--dragging":""} ${oe||""}`,style:{width:U,height:te,...P},onMouseDown:_,onMouseMove:G,onMouseUp:be,onMouseLeave:be,onWheel:ce,children:[n.jsxs("svg",{width:"100%",height:"100%",style:{transform:`translate(${Y.x}px, ${Y.y}px) scale(${we})`,transformOrigin:"center center"},children:[E.map(v=>{const w=g.filter(F=>v.nodeIds.includes(F.id));if(w.length===0)return null;const I=w.map(F=>le(F.id)),p=Math.min(...I.map(F=>F.x))-10,b=Math.max(...I.map(F=>F.x))+10,O=Math.min(...I.map(F=>F.y))-10,C=Math.max(...I.map(F=>F.y))+10;return n.jsxs("g",{children:[n.jsx("rect",{x:p,y:O,width:b-p,height:C-O,fill:v.background||`${v.color}20`||"var(--nice-primary-bg, #e3f2fd)",stroke:v.color||"var(--nice-primary, #2196f3)",strokeWidth:1,strokeDasharray:"4,2",rx:4}),v.showLabel&&n.jsx("text",{x:b+5,y:(O+C)/2,fontSize:10,fill:v.color||"var(--nice-text-secondary, #666)",dominantBaseline:"middle",children:v.name})]},v.id)}),Ce(R),g.map(v=>$e(v)),q.map(v=>{if(!g.find(b=>b.id===v.nodeId))return null;const I=le(v.nodeId),p={left:{x:-10,y:0},right:{x:10,y:0},above:{x:0,y:-10},below:{x:0,y:10}}[v.position||"right"];return n.jsx("text",{x:I.x+p.x,y:I.y+p.y,fontSize:v.fontSize||9,fill:v.color||"var(--nice-danger, #ff5722)",textAnchor:v.position==="left"?"end":v.position==="right"?"start":"middle",dominantBaseline:"middle",children:v.text},`ann-${v.nodeId}`)})]}),n.jsx("div",{style:{position:"absolute",top:8,left:8,fontSize:"0.75rem",color:"var(--nice-text-secondary, #666)"},children:se("phylogeneticTree.nodesLeaves","{allNodes} nodes • {leafCount} leaves").replace("{allNodes}",String(g.length)).replace("{leafCount}",String(T))}),$&&n.jsxs("div",{style:{position:"absolute",bottom:8,left:8,background:"var(--nice-overlay-light-95, rgba(255, 255, 255, 0.95))",padding:"4px 8px",borderRadius:4,fontSize:"0.75rem",boxShadow:"0 1px 4px var(--nice-overlay-10, rgba(0, 0, 0, 0.1))"},children:[n.jsx("div",{children:n.jsx("b",{children:$.name||$.id})}),$.branchLength!==void 0&&n.jsx("div",{children:se("phylogeneticTree.branchLength","Branch length: {branchLength}").replace("{branchLength}",String($.branchLength.toFixed(4)))}),$.bootstrap!==void 0&&n.jsx("div",{children:se("phylogeneticTree.bootstrap","Bootstrap: {bootstrap}").replace("{bootstrap}",String($.bootstrap))}),$.children&&n.jsx("div",{children:se("phylogeneticTree.children","Children: {children}").replace("{children}",String($.children.length))})]}),ee&&n.jsxs("div",{style:{position:"absolute",top:8,right:8,display:"flex",flexDirection:"column",gap:4},children:[n.jsxs("select",{value:ae,onChange:v=>S(v.target.value),style:{padding:"2px 4px",fontSize:"0.75rem"},children:[n.jsx("option",{value:"rectangular",children:se("phylogeneticTree.rectangular","Rectangular")}),n.jsx("option",{value:"radial",children:se("phylogeneticTree.radial","Radial")}),n.jsx("option",{value:"diagonal",children:se("phylogeneticTree.diagonal","Diagonal")})]}),n.jsx("button",{onClick:()=>{xe(1),H({x:0,y:0})},style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:se("phylogeneticTree.resetView","Reset View")}),n.jsx("button",{onClick:()=>A(new Set),style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:se("phylogeneticTree.expandAll","Expand All")})]})]}):n.jsx("div",{className:`nice-phylogenetic-tree nice-phylogenetic-tree--empty ${oe||""}`,style:{width:U,height:te,...P},children:se("phylogeneticTree.loadAPhylogeneticTreeNewick","Load a phylogenetic tree (Newick format)")})}const ze=e=>e*Math.PI/180;function qt(e,t,r,s){const i=(t+180)/360*r,o=ze(e),a=Math.log(Math.tan(Math.PI/4+o/2)),l=s/2-r*a/(2*Math.PI);return{x:i,y:l}}function Ut(e,t,r,s){const i=(t+180)/360*r,o=(90-e)/180*s;return{x:i,y:o}}function Kt(e,t,r,s,i,o){const a=ze(e),l=ze(t),c=ze(i),u=ze(o);if(Math.sin(c)*Math.sin(a)+Math.cos(c)*Math.cos(a)*Math.cos(l-u)<0)return{x:0,y:0,visible:!1};const y=Math.min(r,s)/2-10,f=r/2+y*Math.cos(a)*Math.sin(l-u),m=s/2-y*(Math.cos(c)*Math.sin(a)-Math.sin(c)*Math.cos(a)*Math.cos(l-u));return{x:f,y:m,visible:!0}}function Zt(e,t,r,s){const i=[[0,1,0],[5,.9986,.062],[10,.9954,.124],[15,.99,.186],[20,.9822,.248],[25,.973,.31],[30,.96,.372],[35,.9427,.434],[40,.9216,.4958],[45,.8962,.5571],[50,.8679,.6176],[55,.835,.6769],[60,.7986,.7346],[65,.7597,.7903],[70,.7186,.8435],[75,.6732,.8936],[80,.6213,.9394],[85,.5722,.9761],[90,.5322,1]],o=Math.abs(e);let a=1,l=0;for(let y=0;y<i.length-1;y++)if(o>=i[y][0]&&o<=i[y+1][0]){const f=(o-i[y][0])/5;a=i[y][1]+f*(i[y+1][1]-i[y][1]),l=i[y][2]+f*(i[y+1][2]-i[y][2]);break}const c=r/(2*Math.PI),u=r/2+c*ze(t)*a,x=s/2-c*l*1.3523*Math.sign(e);return{x:u,y:x}}const Jt=`
|
|
61
62
|
M 50,30 L 55,28 60,30 65,35 60,40 55,42 50,40 Z
|
|
62
63
|
M 70,25 L 80,23 85,28 87,35 85,45 78,50 72,48 68,40 70,32 Z
|
|
63
64
|
M 55,55 L 58,52 65,55 68,60 65,70 58,75 52,70 50,60 Z
|
|
64
65
|
M 80,55 L 90,50 92,60 88,70 80,75 75,65 Z
|
|
65
66
|
M 15,30 L 25,28 32,32 35,38 30,45 22,48 15,42 12,35 Z
|
|
66
67
|
M 30,55 L 35,50 40,52 42,58 38,65 32,68 28,62 Z
|
|
67
|
-
`;function Gt({projection:e="equirectangular",layers:t=[],markers:r=[],polylines:s=[],polygons:i=[],heatmap:o,bounds:a,center:l={lat:0,lng:0},zoom:c=1,showGraticule:u=!0,graticuleInterval:x=30,showCoastlines:
|
|
68
|
-
A${p},${p} 0 1,1 ${
|
|
69
|
-
A${p},${p} 0 1,1 ${
|
|
70
|
-
c0,-${
|
|
71
|
-
a${
|
|
72
|
-
c0,${
|
|
68
|
+
`;function Gt({projection:e="equirectangular",layers:t=[],markers:r=[],polylines:s=[],polygons:i=[],heatmap:o,bounds:a,center:l={lat:0,lng:0},zoom:c=1,showGraticule:u=!0,graticuleInterval:x=30,showCoastlines:y=!0,showBorders:f=!1,landColor:m="#D4E6C3",oceanColor:M="#A8D4E6",borderColor:E="var(--nice-text-muted, #999999)",graticuleColor:q="var(--nice-border, #cccccc)",width:re="100%",height:U=400,enablePan:te=!0,enableZoom:B=!0,showControls:ie=!0,scaleBar:me={show:!0,position:"bottom-left"},legend:ee,showLayerControl:je=!1,onMarkerClick:ue,onMarkerHover:Q,onMapClick:oe,onPolygonClick:P,onBoundsChange:se,className:ge,style:we}){var Ce,v,w,I;const{t:xe}=pe.useNiceTranslation(),Y=h.useRef(null),[H,he]=h.useState(l),[Z,ne]=h.useState(c),[fe,$]=h.useState(!1),[J,ae]=h.useState(null),[S,D]=h.useState(null),[A,N]=h.useState(e),[R,X]=h.useState(new Set(t.filter(p=>p.visible!==!1).map(p=>p.id))),T=typeof re=="number"?re:800,W=typeof U=="number"?U:400,g=h.useCallback((p,b)=>{switch(A){case"mercator":return qt(p,b,T,W);case"orthographic":return Kt(p,b,T,W,H.lat,H.lng);case"robinson":return Zt(p,b,T,W);case"equirectangular":default:return Ut(p,b,T,W)}},[A,T,W,H]),z=h.useCallback((p,b)=>{const O=p/T*360-180,C=90-b/W*180;return{lat:Math.max(-90,Math.min(90,C)),lng:Math.max(-180,Math.min(180,O))}},[T,W]),d=h.useMemo(()=>{const p=[];for(let b=-90+x;b<90;b+=x){let O="";for(let C=-180;C<=180;C+=5){const F=g(b,C);F.visible!==!1&&(O+=O===""?`M${F.x},${F.y}`:` L${F.x},${F.y}`)}O&&p.push(O)}for(let b=-180;b<=180;b+=x){let O="";for(let C=-90;C<=90;C+=5){const F=g(C,b);F.visible!==!1&&(O+=O===""?`M${F.x},${F.y}`:` L${F.x},${F.y}`)}O&&p.push(O)}return p},[g,x]),j=h.useMemo(()=>{if(A==="orthographic"){const p=Math.min(T,W)/2-10;return`M${T/2+p},${W/2}
|
|
69
|
+
A${p},${p} 0 1,1 ${T/2-p},${W/2}
|
|
70
|
+
A${p},${p} 0 1,1 ${T/2+p},${W/2}`}return null},[A,T,W]),k=h.useMemo(()=>{const p=[...r];for(const b of t)R.has(b.id)&&b.markers&&p.push(...b.markers);return p},[r,t,R]),L=h.useMemo(()=>{const p=[...s];for(const b of t)R.has(b.id)&&b.polylines&&p.push(...b.polylines);return p},[s,t,R]),V=h.useMemo(()=>{const p=[...i];for(const b of t)R.has(b.id)&&b.polygons&&p.push(...b.polygons);return p},[i,t,R]),de=h.useCallback(p=>{te&&($(!0),ae({x:p.clientX,y:p.clientY,center:{...H}}))},[te,H]),le=h.useCallback(p=>{if(!fe||!J)return;const b=p.clientX-J.x,O=p.clientY-J.y,C=-(b/T)*360/Z,F=O/W*180/Z;he({lat:Math.max(-85,Math.min(85,J.center.lat+F)),lng:(J.center.lng+C+180)%360-180})},[fe,J,T,W,Z]),_=h.useCallback(()=>{$(!1),ae(null)},[]),G=h.useCallback(p=>{if(!B)return;p.preventDefault();const b=p.deltaY>0?.9:1.1;ne(O=>Math.max(.5,Math.min(20,O*b)))},[B]),be=h.useCallback(p=>{var F;if(!oe)return;const b=(F=Y.current)==null?void 0:F.getBoundingClientRect();if(!b)return;const O=p.clientX-b.left,C=p.clientY-b.top;oe(z(O,C))},[oe,z]),ce=p=>{const b=g(p.position.lat,p.position.lng);if(b.visible===!1)return null;const O=(S==null?void 0:S.id)===p.id,C=(p.size||8)*(O?1.3:1),F=(()=>{switch(p.shape){case"square":return n.jsx("rect",{x:b.x-C/2,y:b.y-C/2,width:C,height:C});case"triangle":return n.jsx("polygon",{points:`${b.x},${b.y-C} ${b.x-C},${b.y+C/2} ${b.x+C},${b.y+C/2}`});case"diamond":return n.jsx("polygon",{points:`${b.x},${b.y-C} ${b.x+C},${b.y} ${b.x},${b.y+C} ${b.x-C},${b.y}`});case"pin":return n.jsx("path",{d:`M${b.x},${b.y}
|
|
71
|
+
c0,-${C*1.5} -${C},-${C*2} -${C},-${C*2.5}
|
|
72
|
+
a${C},${C} 0 1,1 ${C*2},0
|
|
73
|
+
c0,${C*.5} -${C},${C} -${C},${C*2.5}`});case"circle":default:return n.jsx("circle",{cx:b.x,cy:b.y,r:C/2})}})();return n.jsxs("g",{fill:p.color||"var(--nice-color-accent-pink, #e91e63)",stroke:O?"var(--nice-text, #000)":"var(--nice-bg, #fff)",strokeWidth:O?2:1,style:{cursor:"pointer"},onMouseEnter:()=>{D(p),Q==null||Q(p)},onMouseLeave:()=>{D(null),Q==null||Q(null)},onClick:Ae=>{Ae.stopPropagation(),ue==null||ue(p)},children:[F,p.label&&n.jsx("text",{x:b.x+C,y:b.y,fontSize:10,fill:"var(--nice-text, #333)",dominantBaseline:"middle",children:p.label})]},p.id)},ye=p=>{if(p.path.length<2)return null;const b=p.path.map((O,C)=>{const F=g(O.lat,O.lng);return F.visible===!1?"":C===0?`M${F.x},${F.y}`:`L${F.x},${F.y}`}).filter(Boolean).join(" ");return b?n.jsx("path",{d:b,fill:"none",stroke:p.color||"var(--nice-primary, #2196f3)",strokeWidth:p.width||2,strokeDasharray:p.style==="dashed"?"8,4":p.style==="dotted"?"2,2":void 0,markerEnd:p.arrows?"url(#arrow)":void 0},p.id):null},ve=p=>{if(p.path.length<3)return null;const b=p.path.map((O,C)=>{const F=g(O.lat,O.lng);return F.visible===!1?"":C===0?`M${F.x},${F.y}`:`L${F.x},${F.y}`}).filter(Boolean).join(" ")+" Z";return n.jsx("path",{d:b,fill:p.fillColor||"#4CAF5040",stroke:p.strokeColor||"var(--nice-success, #4caf50)",strokeWidth:p.strokeWidth||1,fillOpacity:p.fillOpacity||.5,style:{cursor:"pointer"},onClick:()=>P==null?void 0:P(p)},p.id)},$e=h.useMemo(()=>{if(!me.show)return null;const p=111,b=T/360*Z,O=p/b,C=O*100,F=Math.pow(10,Math.floor(Math.log10(C))),Ae=F*(C/F>=5?5:C/F>=2?2:1);return{width:Ae/O,label:Ae>=1e3?xe("geographicMap.km","{scaleKm} km").replace("{scaleKm}",String(Ae/1e3)):xe("geographicMap.km","{scaleKm} km").replace("{scaleKm}",String(Ae))}},[me.show,T,Z,xe]);return n.jsxs("div",{role:"presentation",ref:Y,className:`nice-geographic-map ${ge||""}`,style:{width:re,height:U,position:"relative",overflow:"hidden",background:M,border:"1px solid var(--nice-border, #ccc)",borderRadius:4,cursor:fe?"grabbing":"grab",...we},onMouseDown:de,onMouseMove:le,onMouseUp:_,onMouseLeave:_,onWheel:G,onClick:be,children:[n.jsxs("svg",{width:"100%",height:"100%",children:[n.jsx("defs",{children:n.jsx("marker",{id:"arrow",markerWidth:"10",markerHeight:"10",refX:"9",refY:"3",orient:"auto",children:n.jsx("path",{d:"M0,0 L0,6 L9,3 z",fill:"var(--nice-primary, #2196f3)"})})}),A==="orthographic"&&j&&n.jsxs(n.Fragment,{children:[n.jsx("path",{d:j,fill:M,stroke:"var(--nice-text-muted, #999)",strokeWidth:1}),n.jsx("circle",{cx:T/2,cy:W/2,r:Math.min(T,W)/2-11,fill:m,opacity:.3})]}),u&&d.map((p,b)=>n.jsx("path",{d:p,fill:"none",stroke:q,strokeWidth:.5,strokeOpacity:.7},`graticule-${b}`)),y&&A!=="orthographic"&&n.jsx("g",{transform:`scale(${T/100}, ${W/100})`,children:n.jsx("path",{d:Jt,fill:m,stroke:E,strokeWidth:.2})}),V.map(ve),L.map(ye),k.map(ce)]}),$e&&n.jsxs("div",{style:{position:"absolute",[(Ce=me.position)!=null&&Ce.includes("bottom")?"bottom":"top"]:8,[(v=me.position)!=null&&v.includes("right")?"right":"left"]:8,background:"color-mix(in srgb, var(--nice-bg-elevated, #ffffff) 90%, transparent)",color:"var(--nice-text-primary, #333)",padding:"4px 8px",borderRadius:4,fontSize:"0.7rem"},children:[n.jsx("div",{style:{width:$e.width,height:4,background:"currentColor",marginBottom:2}}),n.jsx("div",{children:$e.label})]}),ee&&n.jsxs("div",{style:{position:"absolute",[(w=ee.position)!=null&&w.includes("bottom")?"bottom":"top"]:8,[(I=ee.position)!=null&&I.includes("left")?"left":"right"]:8,background:"var(--nice-overlay-light-95, rgba(255, 255, 255, 0.95))",padding:8,borderRadius:4,fontSize:"0.75rem",minWidth:100},children:[ee.title&&n.jsx("div",{style:{fontWeight:"bold",marginBottom:4},children:ee.title}),ee.items.map((p,b)=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:2},children:[p.shape==="line"?n.jsx("div",{style:{width:16,height:2,background:p.color}}):n.jsx("div",{style:{width:12,height:12,background:p.color,borderRadius:p.shape==="circle"?"50%":0}}),n.jsx("span",{children:p.label})]},b))]}),(S==null?void 0:S.tooltip)&&n.jsx("div",{style:{position:"absolute",top:g(S.position.lat,S.position.lng).y-30,left:g(S.position.lat,S.position.lng).x,transform:"translateX(-50%)",background:"var(--nice-overlay-80, rgba(0, 0, 0, 0.8))",color:"var(--nice-color-white, #fff)",padding:"4px 8px",borderRadius:4,fontSize:"0.75rem",pointerEvents:"none",whiteSpace:"nowrap"},children:S.tooltip}),n.jsxs("div",{style:{position:"absolute",bottom:8,right:8,background:"color-mix(in srgb, var(--nice-bg-elevated, #ffffff) 90%, transparent)",padding:"2px 6px",borderRadius:4,fontSize:"0.7rem",color:"var(--nice-text-secondary, #666)"},children:[H.lat.toFixed(2),"°, ",H.lng.toFixed(2),"°"]}),je&&t.length>0&&n.jsxs("div",{style:{position:"absolute",top:8,left:8,background:"var(--nice-overlay-light-95, rgba(255, 255, 255, 0.95))",padding:8,borderRadius:4,fontSize:"0.75rem"},children:[n.jsx("div",{style:{fontWeight:"bold",marginBottom:4},children:xe("geographicMap.layers","Layers")}),t.map(p=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:4,cursor:"pointer"},children:[n.jsx("input",{type:"checkbox",checked:R.has(p.id),onChange:b=>{const O=new Set(R);b.target.checked?O.add(p.id):O.delete(p.id),X(O)}}),p.name]},p.id))]}),ie&&n.jsxs("div",{style:{position:"absolute",top:8,right:8,display:"flex",flexDirection:"column",gap:4},children:[n.jsxs("select",{value:A,onChange:p=>N(p.target.value),style:{padding:"2px 4px",fontSize:"0.75rem"},children:[n.jsx("option",{value:"equirectangular",children:xe("geographicMap.equirectangular","Equirectangular")}),n.jsx("option",{value:"mercator",children:xe("geographicMap.mercator","Mercator")}),n.jsx("option",{value:"orthographic",children:xe("geographicMap.orthographic","Orthographic")}),n.jsx("option",{value:"robinson",children:xe("geographicMap.robinson","Robinson")})]}),n.jsx("button",{onClick:()=>{ne(1),he({lat:0,lng:0})},style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:xe("geographicMap.resetView","Reset View")})]})]})}exports.CitationService=Ge;exports.DataAnalysisService=Ke;exports.LabNotebookProvider=qe;exports.LabNotebookService=Ye;exports.Nice3DPlot=Ot;exports.NiceCitation=St;exports.NiceDataAnalysis=pt;exports.NiceGeographicMap=Gt;exports.NiceLabNotebook=at;exports.NiceMolecularViewer=Pt;exports.NicePhylogeneticTree=Vt;exports.NiceScientificChart=Bt;exports.Stats=ke;exports.createCitationService=wt;exports.createDataAnalysisService=ht;exports.createLabNotebookService=ot;exports.useCitation=_e;exports.useLabNotebook=Te;
|