@nice2dev/ui-science 1.0.11 โ 1.0.14
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/README.md +14 -0
- package/dist/index.cjs +32 -32
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +753 -751
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
"use strict";var nt=Object.defineProperty;var
|
|
1
|
+
"use strict";var nt=Object.defineProperty;var rt=(e,t,r)=>t in e?nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var ye=(e,t,r)=>rt(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),u=require("react");class Xe{constructor(t){ye(this,"config");ye(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,h,p;const s=[],i=t.toLowerCase();for(const f of this.notebooks.values())if(!(r!=null&&r.notebookId&&f.id!==r.notebookId))for(const m of f.entries)r!=null&&r.type&&m.type!==r.type||r!=null&&r.status&&m.status!==r.status||(o=r==null?void 0:r.tags)!=null&&o.length&&!r.tags.some(j=>m.tags.includes(j))||r!=null&&r.dateFrom&&m.createdAt<r.dateFrom||r!=null&&r.dateTo&&m.createdAt>r.dateTo||(m.title.toLowerCase().includes(i)||(a=m.objective)!=null&&a.toLowerCase().includes(i)||(l=m.hypothesis)!=null&&l.toLowerCase().includes(i)||(c=m.methods)!=null&&c.toLowerCase().includes(i)||(h=m.results)!=null&&h.toLowerCase().includes(i)||(p=m.conclusions)!=null&&p.toLowerCase().includes(i))&&s.push(m);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>
|
|
5
5
|
<meta charset="utf-8">
|
|
6
6
|
<title>${t.title}</title>
|
|
7
7
|
<style>
|
|
8
|
-
body { font-family: 'Times New Roman', serif; max-width: 800px; margin: 0 auto; padding: 20px; }
|
|
9
|
-
h1 { border-bottom: 2px solid #333; }
|
|
10
|
-
.meta { color: #666; font-size: 0.9em; }
|
|
11
|
-
.section { margin: 20px 0; }
|
|
12
|
-
.signatures { border-top: 1px solid #ccc; margin-top: 40px; padding-top: 20px; }
|
|
8
|
+
body { font-family: 'Times New Roman', serif; max-width: 800px; margin: 0 auto; padding: var(--nice-space-5, 20px); }
|
|
9
|
+
h1 { border-bottom: 2px solid var(--nice-text, #333); }
|
|
10
|
+
.meta { color: var(--nice-text-secondary, #666); font-size: 0.9em; }
|
|
11
|
+
.section { margin: var(--nice-space-5, 20px) 0; }
|
|
12
|
+
.signatures { border-top: 1px solid var(--nice-border, #ccc); margin-top: var(--nice-space-10, 40px); padding-top: var(--nice-space-5, 20px); }
|
|
13
13
|
</style>
|
|
14
14
|
</head>
|
|
15
15
|
<body>
|
|
16
16
|
<h1>${t.title}</h1>
|
|
17
17
|
<div class="meta">
|
|
18
|
-
<p>Notebook: ${
|
|
18
|
+
<p>Notebook: ${r.name}</p>
|
|
19
19
|
<p>Entry ID: ${t.id}</p>
|
|
20
20
|
<p>Type: ${t.type}</p>
|
|
21
21
|
<p>Created: ${new Date(t.createdAt).toLocaleString()}</p>
|
|
@@ -29,41 +29,41 @@
|
|
|
29
29
|
${t.signatures.length>0?`
|
|
30
30
|
<div class="signatures">
|
|
31
31
|
<h2>Signatures</h2>
|
|
32
|
-
${t.signatures.map(
|
|
33
|
-
<p><strong>${
|
|
32
|
+
${t.signatures.map(s=>`
|
|
33
|
+
<p><strong>${s.userName}</strong> (${s.role}) - ${new Date(s.signedAt).toLocaleString()}</p>
|
|
34
34
|
`).join("")}
|
|
35
35
|
</div>
|
|
36
36
|
`:""}
|
|
37
37
|
</body>
|
|
38
38
|
</html>
|
|
39
|
-
`}generateId(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}generateSignatureHash(t,s){const i=JSON.stringify({entry:t,userId:s,timestamp:Date.now()});return Buffer.from(i).toString("base64").substring(0,32)}}function it(e){return new Ye(e)}const _e=u.createContext(null);function Ne(){const e=u.useContext(_e);if(!e)throw new Error("useLabNotebook must be used within LabNotebookProvider");return e}function Pe({service:e,children:t}){const[s,i]=u.useState([]),[r,o]=u.useState(null),[a,l]=u.useState(null),c=u.useCallback(async()=>{const v=await e.listNotebooks();i(v)},[e]),h=u.useMemo(()=>s.find(v=>v.id===r)||null,[s,r]),p=u.useMemo(()=>(h==null?void 0:h.entries.find(v=>v.id===a))||null,[h,a]),f=u.useCallback(v=>{o(v),l(null)},[]),m={service:e,notebooks:s,currentNotebook:h,currentEntry:p,setCurrentNotebook:f,setCurrentEntry:l,refresh:c};return n.jsx(_e.Provider,{value:m,children:t})}const _={container:{display:"flex",height:"100%",backgroundColor:"#f5f5f5",fontFamily:"'Inter', sans-serif"},sidebar:{width:"280px",backgroundColor:"#fff",borderRight:"1px solid #e0e0e0",display:"flex",flexDirection:"column"},main:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},header:{padding:"16px 24px",borderBottom:"1px solid #e0e0e0",backgroundColor:"#fff"},content:{flex:1,padding:"24px",overflow:"auto"},entryCard:{padding:"12px 16px",borderBottom:"1px solid #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 #ddd",borderRadius:"4px",fontSize:"14px"},textarea:{width:"100%",padding:"12px",border:"1px solid #ddd",borderRadius:"4px",fontSize:"14px",minHeight:"100px",resize:"vertical"},button:{padding:"8px 16px",backgroundColor:"#1976d2",color:"#fff",border:"none",borderRadius:"4px",cursor:"pointer",fontSize:"14px"}},Fe={draft:"#9e9e9e","in-progress":"#2196f3",completed:"#4caf50",reviewed:"#ff9800",signed:"#9c27b0",locked:"#f44336"},qe={experiment:"๐งช",protocol:"๐",observation:"๐",calculation:"๐ข",meeting:"๐ฅ",report:"๐",note:"๐"};function rt({service:e,className:t,style:s}){return n.jsx(Pe,{service:e,children:n.jsxs("div",{className:t,style:{..._.container,...s},children:[n.jsx(ot,{}),n.jsx(at,{})]})})}function ot(){const{notebooks:e,currentNotebook:t,setCurrentNotebook:s,service:i,refresh:r}=Ne(),[o,a]=u.useState(!1),[l,c]=u.useState(""),h=async()=>{l.trim()&&(await i.createNotebook({name:l.trim()}),await r(),c(""),a(!1))};return n.jsxs("div",{style:_.sidebar,children:[n.jsx("div",{style:{padding:"16px",borderBottom:"1px solid #e0e0e0"},children:n.jsx("h2",{style:{margin:0,fontSize:"18px"},children:"๐ Lab Notebooks"})}),n.jsx("div",{style:{flex:1,overflow:"auto"},children:e.map(p=>n.jsxs("div",{onClick:()=>s(p.id),style:{..._.entryCard,backgroundColor:(t==null?void 0:t.id)===p.id?"#e3f2fd":"transparent"},children:[n.jsx("div",{style:{fontWeight:500},children:p.name}),n.jsxs("div",{style:{fontSize:"12px",color:"#666",marginTop:"4px"},children:[p.entries.length," entries"]})]},p.id))}),n.jsx("div",{style:{padding:"16px",borderTop:"1px solid #e0e0e0"},children:o?n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[n.jsx("input",{type:"text",value:l,onChange:p=>c(p.target.value),placeholder:"Notebook name",style:_.input,autoFocus:!0}),n.jsxs("div",{style:{display:"flex",gap:"8px"},children:[n.jsx("button",{onClick:h,style:_.button,children:"Create"}),n.jsx("button",{onClick:()=>a(!1),style:{..._.button,backgroundColor:"#9e9e9e"},children:"Cancel"})]})]}):n.jsx("button",{onClick:()=>a(!0),style:{..._.button,width:"100%"},children:"+ New Notebook"})})]})}function at(){const{currentNotebook:e,currentEntry:t,setCurrentEntry:s,service:i,refresh:r}=Ne(),[o,a]=u.useState(!1);if(!e)return n.jsx("div",{style:{..._.main,justifyContent:"center",alignItems:"center"},children:n.jsxs("div",{style:{textAlign:"center",color:"#666"},children:[n.jsx("div",{style:{fontSize:"48px",marginBottom:"16px"},children:"๐"}),n.jsx("div",{style:{fontSize:"18px"},children:"Select a notebook to get started"})]})});const l=async c=>{const h=await i.createEntry(e.id,c);await r(),s(h.id),a(!1)};return n.jsxs("div",{style:_.main,children:[n.jsx("div",{style:_.header,children:n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[n.jsx("h1",{style:{margin:0,fontSize:"20px"},children:e.name}),n.jsx("button",{onClick:()=>a(!0),style:_.button,children:"+ New Entry"})]})}),n.jsxs("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[n.jsx("div",{style:{width:"300px",borderRight:"1px solid #e0e0e0",overflow:"auto"},children:e.entries.map(c=>n.jsxs("div",{onClick:()=>s(c.id),style:{..._.entryCard,backgroundColor:(t==null?void 0:t.id)===c.id?"#e3f2fd":"transparent"},children:[n.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[n.jsx("span",{children:qe[c.type]}),n.jsx("span",{style:{fontWeight:500},children:c.title})]}),n.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[n.jsx("span",{style:{..._.badge,backgroundColor:`${Fe[c.status]}20`,color:Fe[c.status]},children:c.status}),n.jsx("span",{style:{fontSize:"12px",color:"#666"},children:new Date(c.updatedAt).toLocaleDateString()})]})]},c.id))}),n.jsx("div",{style:_.content,children:t?n.jsx(lt,{entry:t}):o?n.jsx(ct,{onSubmit:l,onCancel:()=>a(!1)}):n.jsx("div",{style:{textAlign:"center",color:"#666",marginTop:"100px"},children:"Select an entry or create a new one"})})]})]})}function lt({entry:e}){const{service:t,currentNotebook:s,refresh:i}=Ne(),[r,o]=u.useState(!1),[a,l]=u.useState(e),c=e.status==="locked"||e.status==="signed",h=async()=>{s&&(await t.updateEntry(s.id,e.id,a),await i(),o(!1))},p=async()=>{s&&(await t.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:{..._.badge,backgroundColor:`${Fe[e.status]}20`,color:Fe[e.status]},children:e.status}),n.jsxs("span",{style:{fontSize:"12px",color:"#666"},children:["v",e.version]})]})]}),!c&&n.jsx("div",{style:{display:"flex",gap:"8px"},children:r?n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:h,style:_.button,children:"Save"}),n.jsx("button",{onClick:()=>{o(!1),l(e)},style:{..._.button,backgroundColor:"#9e9e9e"},children:"Cancel"})]}):n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>o(!0),style:_.button,children:"Edit"}),n.jsx("button",{onClick:p,style:{..._.button,backgroundColor:"#9c27b0"},children:"Sign"})]})})]}),r?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:"Title"}),n.jsx("input",{type:"text",value:a.title,onChange:f=>l({...a,title:f.target.value}),style:_.input})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Objective"}),n.jsx("textarea",{value:a.objective||"",onChange:f=>l({...a,objective:f.target.value}),style:_.textarea})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Methods"}),n.jsx("textarea",{value:a.methods||"",onChange:f=>l({...a,methods:f.target.value}),style:_.textarea})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Results"}),n.jsx("textarea",{value:a.results||"",onChange:f=>l({...a,results:f.target.value}),style:_.textarea})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Conclusions"}),n.jsx("textarea",{value:a.conclusions||"",onChange:f=>l({...a,conclusions:f.target.value}),style:_.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:"#1976d2"},children:"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:"#1976d2"},children:"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:"#1976d2"},children:"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:"#1976d2"},children:"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:"#1976d2"},children:"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:"#9c27b0"},children:"Signatures"}),e.signatures.map((f,m)=>n.jsxs("div",{style:{padding:"8px",backgroundColor:"#f5f5f5",borderRadius:"4px",marginBottom:"8px"},children:[n.jsx("strong",{children:f.userName})," (",f.role,")",n.jsx("div",{style:{fontSize:"12px",color:"#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:"Attachments"}),e.attachments.map(f=>n.jsxs("a",{href:f.url,target:"_blank",rel:"noopener noreferrer",style:{display:"block",color:"#1976d2",textDecoration:"none"},children:["๐ ",f.name," (",(f.size/1024).toFixed(1)," KB)"]},f.id))]})]})]})}function ct({onSubmit:e,onCancel:t}){const[s,i]=u.useState({title:"",type:"experiment",objective:""}),r=o=>{var a;o.preventDefault(),(a=s.title)!=null&&a.trim()&&e(s)};return n.jsxs("form",{onSubmit:r,style:{display:"flex",flexDirection:"column",gap:"16px"},children:[n.jsx("h2",{style:{margin:0},children:"New Entry"}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Type"}),n.jsx("select",{value:s.type,onChange:o=>i({...s,type:o.target.value}),style:_.input,children:Object.entries(qe).map(([o,a])=>n.jsxs("option",{value:o,children:[a," ",o]},o))})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Title *"}),n.jsx("input",{type:"text",value:s.title,onChange:o=>i({...s,title:o.target.value}),placeholder:"Enter entry title",style:_.input,required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Objective"}),n.jsx("textarea",{value:s.objective,onChange:o=>i({...s,objective:o.target.value}),placeholder:"What is the goal of this entry?",style:_.textarea})]}),n.jsxs("div",{style:{display:"flex",gap:"8px"},children:[n.jsx("button",{type:"submit",style:_.button,children:"Create Entry"}),n.jsx("button",{type:"button",onClick:t,style:{..._.button,backgroundColor:"#9e9e9e"},children:"Cancel"})]})]})}const ge={mean(e){return e.length===0?NaN:e.reduce((t,s)=>t+s,0)/e.length},median(e){if(e.length===0)return NaN;const t=[...e].sort((i,r)=>i-r),s=Math.floor(t.length/2);return t.length%2!==0?t[s]:(t[s-1]+t[s])/2},variance(e,t=!1){if(e.length===0)return NaN;const s=this.mean(e),i=e.map(o=>Math.pow(o-s,2)),r=t?e.length:e.length-1;return i.reduce((o,a)=>o+a,0)/r},std(e,t=!1){return Math.sqrt(this.variance(e,t))},mode(e){const t=new Map;let s=0,i=e[0];for(const r of e){const o=(t.get(r)||0)+1;t.set(r,o),o>s&&(s=o,i=r)}return i},percentile(e,t){if(e.length===0)return NaN;const s=[...e].sort((l,c)=>l-c),i=t/100*(s.length-1),r=Math.floor(i),o=Math.ceil(i),a=i-r;return s[r]*(1-a)+s[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 s=this.mean(e),i=this.std(e),r=e.map(o=>Math.pow((o-s)/i,3));return t/((t-1)*(t-2))*r.reduce((o,a)=>o+a,0)},kurtosis(e){const t=e.length;if(t<4)return NaN;const s=this.mean(e),i=this.std(e),o=e.map(a=>Math.pow((a-s)/i,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 s=e.length,i=this.mean(e),r=this.mean(t);let o=0,a=0,l=0;for(let c=0;c<s;c++){const h=e[c]-i,p=t[c]-r;o+=h*p,a+=h*h,l+=p*p}return o/Math.sqrt(a*l)},correlationMatrix(e){const t=Object.keys(e),s={};for(const i of t){s[i]={};for(const r of t)s[i][r]=this.correlation(e[i],e[r])}return s},covariance(e,t,s=!1){if(e.length!==t.length||e.length<2)return NaN;const i=e.length,r=this.mean(e),o=this.mean(t);let a=0;for(let l=0;l<i;l++)a+=(e[l]-r)*(t[l]-o);return a/(s?i:i-1)},linearRegression(e,t){if(e.length!==t.length||e.length<2)throw new Error("Invalid input arrays");const s=e.length,i=this.mean(e),r=this.mean(t);let o=0,a=0;for(let v=0;v<s;v++)o+=(e[v]-i)*(t[v]-r),a+=Math.pow(e[v]-i,2);const l=o/a,c=r-l*i;let h=0,p=0;for(let v=0;v<s;v++){const M=l*e[v]+c;h+=Math.pow(t[v]-r,2),p+=Math.pow(t[v]-M,2)}const f=1-p/h,m=`y = ${l.toFixed(4)}x + ${c.toFixed(4)}`;return{slope:l,intercept:c,r2:f,equation:m}},tTest(e,t){const s=e.length,i=t.length,r=this.mean(e),o=this.mean(t),a=this.variance(e),l=this.variance(t),c=Math.sqrt(a/s+l/i),h=(r-o)/c,p=Math.pow(a/s+l/i,2)/(Math.pow(a/s,2)/(s-1)+Math.pow(l/i,2)/(i-1)),f=2*(1-this.normalCDF(Math.abs(h)));return{tStatistic:h,pValue:f,degreesOfFreedom:p,meanDiff:r-o}},normalCDF(e){const t=.254829592,s=-.284496736,i=1.421413741,r=-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),h=1-((((o*c+r)*c+i)*c+s)*c+t)*c*Math.exp(-e*e);return .5*(1+l*h)},chiSquare(e,t){if(e.length!==t.length)throw new Error("Arrays must have same length");let s=0;for(let o=0;o<e.length;o++)s+=Math.pow(e[o]-t[o],2)/t[o];const i=e.length-1;return{chiSquare:s,pValue:.05,degreesOfFreedom:i}},zScore(e){const t=this.mean(e),s=this.std(e);return e.map(i=>(i-t)/s)},minMaxNormalize(e,t=0,s=1){const i=Math.min(...e),o=Math.max(...e)-i;return e.map(a=>t+(a-i)/o*(s-t))},describe(e){const t=e.filter(i=>i!=null&&!isNaN(i)),s=this.quartiles(t);return{count:t.length,mean:this.mean(t),median:s.q2,std:this.std(t),min:Math.min(...t),max:Math.max(...t),q1:s.q1,q3:s.q3,skewness:this.skewness(t),kurtosis:this.kurtosis(t),mode:this.mode(t),variance:this.variance(t)}}};class Ve{constructor(t={}){ye(this,"config");ye(this,"datasets",new Map);ye(this,"analyses",new Map);this.config={maxRowsInMemory:1e5,...t}}async importCSV(t,s){const i=(s==null?void 0:s.delimiter)||",",r=(s==null?void 0:s.header)!==!1,o=t.split(`
|
|
40
|
-
`).filter(m=>m.trim());if(o.length===0)throw new Error("Empty CSV content");const a=m=>{const
|
|
41
|
-
`)}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 dt(e){return new Ve(e)}function ut({service:e,className:t,style:
|
|
42
|
-
`;return
|
|
43
|
-
`,e.year&&(
|
|
44
|
-
`),e.journal&&(
|
|
45
|
-
`),e.volume&&(
|
|
46
|
-
`),e.issue&&(
|
|
47
|
-
`),e.pages&&(
|
|
48
|
-
`),e.publisher&&(
|
|
49
|
-
`),e.doi&&(
|
|
50
|
-
`),e.isbn&&(
|
|
51
|
-
`),`@${
|
|
52
|
-
${
|
|
39
|
+
`}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 st(e){return new Xe(e)}const Ye=u.createContext(null);function Ie(){const e=u.useContext(Ye);if(!e)throw new Error("useLabNotebook must be used within LabNotebookProvider");return e}function Pe({service:e,children:t}){const[r,s]=u.useState([]),[i,o]=u.useState(null),[a,l]=u.useState(null),c=u.useCallback(async()=>{const j=await e.listNotebooks();s(j)},[e]),h=u.useMemo(()=>r.find(j=>j.id===i)||null,[r,i]),p=u.useMemo(()=>(h==null?void 0:h.entries.find(j=>j.id===a))||null,[h,a]),f=u.useCallback(j=>{o(j),l(null)},[]),m={service:e,notebooks:r,currentNotebook:h,currentEntry:p,setCurrentNotebook:f,setCurrentEntry:l,refresh:c};return n.jsx(Ye.Provider,{value:m,children:t})}const Y={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-bg, #fff)",border:"none",borderRadius:"4px",cursor:"pointer",fontSize:"14px"}},ze={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)"},qe={experiment:"๐งช",protocol:"๐",observation:"๐",calculation:"๐ข",meeting:"๐ฅ",report:"๐",note:"๐"};function it({service:e,className:t,style:r}){return n.jsx(Pe,{service:e,children:n.jsxs("div",{className:t,style:{...Y.container,...r},children:[n.jsx(ot,{}),n.jsx(at,{})]})})}function ot(){const{notebooks:e,currentNotebook:t,setCurrentNotebook:r,service:s,refresh:i}=Ie(),[o,a]=u.useState(!1),[l,c]=u.useState(""),h=async()=>{l.trim()&&(await s.createNotebook({name:l.trim()}),await i(),c(""),a(!1))};return n.jsxs("div",{style:Y.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:"๐ Lab Notebooks"})}),n.jsx("div",{style:{flex:1,overflow:"auto"},children:e.map(p=>n.jsxs("div",{onClick:()=>r(p.id),style:{...Y.entryCard,backgroundColor:(t==null?void 0:t.id)===p.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsx("div",{style:{fontWeight:500},children:p.name}),n.jsxs("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)",marginTop:"4px"},children:[p.entries.length," entries"]})]},p.id))}),n.jsx("div",{style:{padding:"16px",borderTop:"1px solid var(--nice-border, #e0e0e0)"},children:o?n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[n.jsx("input",{type:"text",value:l,onChange:p=>c(p.target.value),placeholder:"Notebook name",style:Y.input,autoFocus:!0}),n.jsxs("div",{style:{display:"flex",gap:"8px"},children:[n.jsx("button",{onClick:h,style:Y.button,children:"Create"}),n.jsx("button",{onClick:()=>a(!1),style:{...Y.button,backgroundColor:"var(--nice-text-secondary, #9e9e9e)"},children:"Cancel"})]})]}):n.jsx("button",{onClick:()=>a(!0),style:{...Y.button,width:"100%"},children:"+ New Notebook"})})]})}function at(){const{currentNotebook:e,currentEntry:t,setCurrentEntry:r,service:s,refresh:i}=Ie(),[o,a]=u.useState(!1);if(!e)return n.jsx("div",{style:{...Y.main,justifyContent:"center",alignItems:"center"},children:n.jsxs("div",{style:{textAlign:"center",color:"var(--nice-text-secondary, #666)"},children:[n.jsx("div",{style:{fontSize:"48px",marginBottom:"16px"},children:"๐"}),n.jsx("div",{style:{fontSize:"18px"},children:"Select a notebook to get started"})]})});const l=async c=>{const h=await s.createEntry(e.id,c);await i(),r(h.id),a(!1)};return n.jsxs("div",{style:Y.main,children:[n.jsx("div",{style:Y.header,children:n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[n.jsx("h1",{style:{margin:0,fontSize:"20px"},children:e.name}),n.jsx("button",{onClick:()=>a(!0),style:Y.button,children:"+ 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:e.entries.map(c=>n.jsxs("div",{onClick:()=>r(c.id),style:{...Y.entryCard,backgroundColor:(t==null?void 0:t.id)===c.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[n.jsx("span",{children:qe[c.type]}),n.jsx("span",{style:{fontWeight:500},children:c.title})]}),n.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[n.jsx("span",{style:{...Y.badge,backgroundColor:`${ze[c.status]}20`,color:ze[c.status]},children:c.status}),n.jsx("span",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:new Date(c.updatedAt).toLocaleDateString()})]})]},c.id))}),n.jsx("div",{style:Y.content,children:t?n.jsx(lt,{entry:t}):o?n.jsx(ct,{onSubmit:l,onCancel:()=>a(!1)}):n.jsx("div",{style:{textAlign:"center",color:"var(--nice-text-secondary, #666)",marginTop:"100px"},children:"Select an entry or create a new one"})})]})]})}function lt({entry:e}){const{service:t,currentNotebook:r,refresh:s}=Ie(),[i,o]=u.useState(!1),[a,l]=u.useState(e),c=e.status==="locked"||e.status==="signed",h=async()=>{r&&(await t.updateEntry(r.id,e.id,a),await s(),o(!1))},p=async()=>{r&&(await t.signEntry(r.id,e.id,{userId:"current-user",userName:"Current User",role:"author"}),await s())};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:{...Y.badge,backgroundColor:`${ze[e.status]}20`,color:ze[e.status]},children:e.status}),n.jsxs("span",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:["v",e.version]})]})]}),!c&&n.jsx("div",{style:{display:"flex",gap:"8px"},children:i?n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:h,style:Y.button,children:"Save"}),n.jsx("button",{onClick:()=>{o(!1),l(e)},style:{...Y.button,backgroundColor:"var(--nice-text-secondary, #9e9e9e)"},children:"Cancel"})]}):n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>o(!0),style:Y.button,children:"Edit"}),n.jsx("button",{onClick:p,style:{...Y.button,backgroundColor:"var(--nice-accent, #9c27b0)"},children:"Sign"})]})})]}),i?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:"Title"}),n.jsx("input",{type:"text",value:a.title,onChange:f=>l({...a,title:f.target.value}),style:Y.input})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Objective"}),n.jsx("textarea",{value:a.objective||"",onChange:f=>l({...a,objective:f.target.value}),style:Y.textarea})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Methods"}),n.jsx("textarea",{value:a.methods||"",onChange:f=>l({...a,methods:f.target.value}),style:Y.textarea})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Results"}),n.jsx("textarea",{value:a.results||"",onChange:f=>l({...a,results:f.target.value}),style:Y.textarea})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Conclusions"}),n.jsx("textarea",{value:a.conclusions||"",onChange:f=>l({...a,conclusions:f.target.value}),style:Y.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:"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:"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:"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:"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:"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:"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:"Attachments"}),e.attachments.map(f=>n.jsxs("a",{href:f.url,target:"_blank",rel:"noopener noreferrer",style:{display:"block",color:"var(--nice-primary-hover, #1976d2)",textDecoration:"none"},children:["๐ ",f.name," (",(f.size/1024).toFixed(1)," KB)"]},f.id))]})]})]})}function ct({onSubmit:e,onCancel:t}){const[r,s]=u.useState({title:"",type:"experiment",objective:""}),i=o=>{var a;o.preventDefault(),(a=r.title)!=null&&a.trim()&&e(r)};return n.jsxs("form",{onSubmit:i,style:{display:"flex",flexDirection:"column",gap:"16px"},children:[n.jsx("h2",{style:{margin:0},children:"New Entry"}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Type"}),n.jsx("select",{value:r.type,onChange:o=>s({...r,type:o.target.value}),style:Y.input,children:Object.entries(qe).map(([o,a])=>n.jsxs("option",{value:o,children:[a," ",o]},o))})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Title *"}),n.jsx("input",{type:"text",value:r.title,onChange:o=>s({...r,title:o.target.value}),placeholder:"Enter entry title",style:Y.input,required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Objective"}),n.jsx("textarea",{value:r.objective,onChange:o=>s({...r,objective:o.target.value}),placeholder:"What is the goal of this entry?",style:Y.textarea})]}),n.jsxs("div",{style:{display:"flex",gap:"8px"},children:[n.jsx("button",{type:"submit",style:Y.button,children:"Create Entry"}),n.jsx("button",{type:"button",onClick:t,style:{...Y.button,backgroundColor:"var(--nice-text-secondary, #9e9e9e)"},children:"Cancel"})]})]})}const ge={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 h=e[c]-s,p=t[c]-i;o+=h*p,a+=h*h,l+=p*p}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 j=0;j<r;j++)o+=(e[j]-s)*(t[j]-i),a+=Math.pow(e[j]-s,2);const l=o/a,c=i-l*s;let h=0,p=0;for(let j=0;j<r;j++){const M=l*e[j]+c;h+=Math.pow(t[j]-i,2),p+=Math.pow(t[j]-M,2)}const f=1-p/h,m=`y = ${l.toFixed(4)}x + ${c.toFixed(4)}`;return{slope:l,intercept:c,r2:f,equation:m}},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),h=(i-o)/c,p=Math.pow(a/r+l/s,2)/(Math.pow(a/r,2)/(r-1)+Math.pow(l/s,2)/(s-1)),f=2*(1-this.normalCDF(Math.abs(h)));return{tStatistic:h,pValue:f,degreesOfFreedom:p,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),h=1-((((o*c+i)*c+s)*c+r)*c+t)*c*Math.exp(-e*e);return .5*(1+l*h)},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 Ve{constructor(t={}){ye(this,"config");ye(this,"datasets",new Map);ye(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(`
|
|
40
|
+
`).filter(m=>m.trim());if(o.length===0)throw new Error("Empty CSV content");const a=m=>{const j=[];let M="",E=!1;for(const U of m)U==='"'?E=!E:U===s&&!E?(j.push(M.trim()),M=""):M+=U;return j.push(M.trim()),j},l=a(o[0]),c=i?l:l.map((m,j)=>`col_${j+1}`),h=i?1:0,p=[];for(let m=h;m<o.length;m++){const j=a(o[m]),M={};for(let E=0;E<c.length;E++){const U=j[E],Q=parseFloat(U);M[c[E]]=!isNaN(Q)&&U!==""?Q:U}p.push(M)}return this.createDataset({name:(r==null?void 0:r.name)||"Imported CSV",data:p,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(p=>p[i]),a=o.filter(p=>p!=null),l=new Set(a);let c="mixed";a.every(p=>typeof p=="number")?c="number":a.every(p=>typeof p=="string")?c=l.size<a.length*.5?"category":"string":a.every(p=>typeof p=="boolean")?c="boolean":a.every(p=>p instanceof Date||!isNaN(Date.parse(p)))&&(c="date");const h={name:i,type:c,nullable:o.some(p=>p==null),unique:l.size,missing:o.length-a.length};if(c==="number"){const p=a.filter(f=>typeof f=="number");h.stats=ge.describe(p)}s.push(h)}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]=ge.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:ge.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 ge.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],h=l[s];typeof h=="number"&&(o.has(c)||o.set(c,[]),o.get(c).push(h))}const a=Array.from(o.keys());if(a.length!==2)throw new Error("T-test requires exactly 2 groups");return ge.tTest(o.get(a[0]),o.get(a[1]))}distributionAnalysis(t,r){const{column:s,bins:i=10}=r,o=t.data.map(f=>f[s]).filter(f=>typeof f=="number"),a=Math.min(...o),c=(Math.max(...o)-a)/i,h=new Array(i).fill(0),p=[];for(let f=0;f<=i;f++)p.push(a+f*c);for(const f of o){const m=Math.min(Math.floor((f-a)/c),i-1);h[m]++}return{histogram:h,binEdges:p,stats:ge.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],h=l[s];return c<h?o?-1:1:c>h?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=ge.mean(i),a=ge.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(`
|
|
41
|
+
`)}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 dt(e){return new Ve(e)}function ut({service:e,className:t,style:r}){const[s,i]=u.useState([]),[o,a]=u.useState(null),[l,c]=u.useState("data"),h=u.useCallback(()=>{i(e.listDatasets())},[e]),p=u.useMemo(()=>s.find(m=>m.id===o),[s,o]),f=async m=>{var E;const j=(E=m.target.files)==null?void 0:E[0];if(!j)return;const M=await j.text();j.name.endsWith(".csv")?await e.importCSV(M,{name:j.name}):j.name.endsWith(".json")&&await e.importJSON(M,{name:j.name}),h()};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:["Import Data",n.jsx("input",{type:"file",accept:".csv,.json",onChange:f,style:{display:"none"}})]}),n.jsxs("select",{value:o||"",onChange:m=>a(m.target.value||null),style:{padding:"8px 12px",borderRadius:"4px",border:"1px solid var(--nice-border, #ddd)"},children:[n.jsx("option",{value:"",children:"Select dataset..."}),s.map(m=>n.jsxs("option",{value:m.id,children:[m.name," (",m.rowCount," rows)"]},m.id))]}),p&&n.jsx("div",{style:{marginLeft:"auto",display:"flex",gap:"8px"},children:["data","stats","analysis"].map(m=>n.jsx("button",{onClick:()=>c(m),style:{padding:"8px 16px",backgroundColor:l===m?"var(--nice-primary-hover, #1976d2)":"transparent",color:l===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:p?l==="data"?n.jsx(ht,{dataset:p}):l==="stats"?n.jsx(pt,{dataset:p}):n.jsx(xt,{dataset:p,service:e}):n.jsxs("div",{style:{textAlign:"center",color:"var(--nice-text-secondary, #666)",padding:"48px"},children:[n.jsx("div",{style:{fontSize:"48px",marginBottom:"16px"},children:"๐"}),n.jsx("div",{style:{fontSize:"18px"},children:"Import a dataset or select an existing one to begin"})]})})]})}function ht({dataset:e}){const[t,r]=u.useState(0),s=50,i=Math.ceil(e.rowCount/s),o=e.data.slice(t*s,(t+1)*s);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(a=>n.jsxs("th",{style:{padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)",textAlign:"left"},children:[a.name,n.jsx("div",{style:{fontSize:"10px",color:"var(--nice-text-secondary, #666)",fontWeight:"normal"},children:a.type})]},a.name))]})}),n.jsx("tbody",{children:o.map((a,l)=>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:t*s+l+1}),e.columns.map(c=>n.jsx("td",{style:{padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)"},children:a[c.name]!=null?String(a[c.name]):n.jsx("span",{style:{color:"var(--nice-border, #ccc)"},children:"null"})},c.name))]},l))})]})}),n.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center",justifyContent:"center"},children:[n.jsx("button",{onClick:()=>r(0),disabled:t===0,children:"First"}),n.jsx("button",{onClick:()=>r(t-1),disabled:t===0,children:"Prev"}),n.jsxs("span",{children:["Page ",t+1," of ",i]}),n.jsx("button",{onClick:()=>r(t+1),disabled:t>=i-1,children:"Next"}),n.jsx("button",{onClick:()=>r(i-1),disabled:t>=i-1,children:"Last"})]})]})}function pt({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 xt({dataset:e,service:t}){const[r,s]=u.useState("descriptive"),[i,o]=u.useState(null),a=()=>{const l=t.runAnalysis(e.id,r,{});o(l)};return n.jsxs("div",{children:[n.jsxs("div",{style:{display:"flex",gap:"12px",marginBottom:"24px"},children:[n.jsxs("select",{value:r,onChange:l=>s(l.target.value),style:{padding:"8px 12px",borderRadius:"4px",border:"1px solid var(--nice-border, #ddd)"},children:[n.jsx("option",{value:"descriptive",children:"Descriptive Statistics"}),n.jsx("option",{value:"correlation",children:"Correlation Matrix"}),n.jsx("option",{value:"distribution",children:"Distribution Analysis"})]}),n.jsx("button",{onClick:a,style:{padding:"8px 16px",backgroundColor:"var(--nice-primary-hover, #1976d2)",color:"white",border:"none",borderRadius:"4px",cursor:"pointer"},children:"Run Analysis"})]}),i&&n.jsxs("div",{style:{padding:"16px",backgroundColor:"var(--nice-bg-secondary, #f9f9f9)",borderRadius:"8px"},children:[n.jsxs("h3",{style:{margin:"0 0 12px 0"},children:["Results (",i.executionTimeMs.toFixed(2),"ms)"]}),n.jsx("pre",{style:{margin:0,overflow:"auto",fontSize:"12px"},children:JSON.stringify(i.result,null,2)})]})]})}const Re={apa:e=>{const t=ft(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=Ue(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=mt(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=yt(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=gt(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=bt(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=Ze(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=vt(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=jt(e),r=e.type==="article"?"article":e.type==="book"?"book":"misc";let i=` author = {${e.authors.map(o=>`${o.family}, ${o.given}`).join(" and ")}},
|
|
42
|
+
`;return i+=` title = {${e.title}},
|
|
43
|
+
`,e.year&&(i+=` year = {${e.year}},
|
|
44
|
+
`),e.journal&&(i+=` journal = {${e.journal}},
|
|
45
|
+
`),e.volume&&(i+=` volume = {${e.volume}},
|
|
46
|
+
`),e.issue&&(i+=` number = {${e.issue}},
|
|
47
|
+
`),e.pages&&(i+=` pages = {${e.pages}},
|
|
48
|
+
`),e.publisher&&(i+=` publisher = {${e.publisher}},
|
|
49
|
+
`),e.doi&&(i+=` doi = {${e.doi}},
|
|
50
|
+
`),e.isbn&&(i+=` isbn = {${e.isbn}},
|
|
51
|
+
`),`@${r}{${t},
|
|
52
|
+
${i}}`}};function ft(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 Ue(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 mt(e){return Ue(e)}function yt(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 gt(e){return e.length===0?"":e.map(t=>`${t.given.charAt(0)}. ${t.family}`).join(", ")}function bt(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 Ze(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 vt(e){return Ze(e)}function jt(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 Ke{constructor(t={}){ye(this,"config");ye(this,"citations",new Map);ye(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,h;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(p=>{var f;return(f=i.tags)==null?void 0:f.includes(p)})?!1:!!(i.title.toLowerCase().includes(s)||i.authors.some(p=>p.family.toLowerCase().includes(s)||p.given.toLowerCase().includes(s))||(l=i.journal)!=null&&l.toLowerCase().includes(s)||(c=i.abstract)!=null&&c.toLowerCase().includes(s)||(h=i.doi)!=null&&h.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 Re[r](s)}formatBibliography(t,r){return t.map((i,o)=>{const a=this.citations.get(i);if(!a)return null;const l=Re[r](a);return r==="bibtex"?l:["ieee","vancouver"].includes(r)?`[${o+1}] ${l}`:l}).filter(Boolean).join(`
|
|
53
53
|
|
|
54
|
-
`)}importBibtex(t){const
|
|
54
|
+
`)}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=>Re.bibtex(s)).join(`
|
|
55
55
|
|
|
56
|
-
`)}async searchDatabase(t,s,i=10){var r,o;try{if(t==="crossref")return await this.searchCrossref(s,i);if(t==="pubmed")return await this.searchPubMed(s,i);throw new Error(`Unknown database: ${t}`)}catch(a){return(o=(r=this.config).onError)==null||o.call(r,a),{source:t,total:0,results:[]}}}async searchCrossref(t,s){const i=new URLSearchParams({query:t,rows:String(s)});this.config.crossrefEmail&&i.set("mailto",this.config.crossrefEmail);const r=await fetch(`https://api.crossref.org/works?${i}`);if(!r.ok)throw new Error(`Crossref API error: ${r.status}`);const o=await r.json(),a=o.message.items.map(l=>{var c,h,p,f,m,v;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:(f=(p=(h=l.published)==null?void 0:h["date-parts"])==null?void 0:p[0])==null?void 0:f[0],journal:(m=l["container-title"])==null?void 0:m[0],volume:l.volume,issue:l.issue,pages:l.page,doi:l.DOI,issn:(v=l.ISSN)==null?void 0:v[0],publisher:l.publisher,abstract:l.abstract,sourceDatabase:"crossref"}});return{source:"crossref",total:o.message["total-results"],results:a}}async searchPubMed(t,s){const i=`https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=${encodeURIComponent(t)}&retmax=${s}&retmode=json`,r=await fetch(i);if(!r.ok)throw new Error(`PubMed API error: ${r.status}`);const o=await r.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 h=await c.json(),p=a.map(f=>{var v;const m=h.result[f];return{type:"article",title:m.title||"",authors:(m.authors||[]).map(M=>{const I=M.name.split(" ");return{family:I.pop()||"",given:I.join(" ")}}),year:m.pubdate?parseInt(m.pubdate.split(" ")[0],10):void 0,journal:m.source,volume:m.volume,issue:m.issue,pages:m.pages,pmid:f,doi:(v=m.elocationid)==null?void 0:v.replace("doi: ",""),sourceDatabase:"pubmed"}});return{source:"pubmed",total:parseInt(o.esearchresult.count,10),results:p}}async fetchByDOI(t){var s,i,r,o,a;try{const l=await fetch(`https://api.crossref.org/works/${encodeURIComponent(t)}`);if(!l.ok)return null;const h=(await l.json()).message;return this.addCitation({type:"article",title:((s=h.title)==null?void 0:s[0])||"",authors:(h.author||[]).map(p=>({given:p.given||"",family:p.family||"",orcid:p.ORCID})),year:(o=(r=(i=h.published)==null?void 0:i["date-parts"])==null?void 0:r[0])==null?void 0:o[0],journal:(a=h["container-title"])==null?void 0:a[0],volume:h.volume,issue:h.issue,pages:h.page,doi:h.DOI,publisher:h.publisher,abstract:h.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(s=>{var i;return(i=s.collections)==null?void 0:i.includes(t.id)}).length}generateId(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}}function $t(e){return new Ke(e)}const Je=u.createContext(null);function Le(){const e=u.useContext(Je);if(!e)throw new Error("useCitation must be used within CitationProvider");return e}const ce={container:{display:"flex",height:"100%",fontFamily:"'Inter', sans-serif",fontSize:"14px"},sidebar:{width:"240px",backgroundColor:"#f5f5f5",borderRight:"1px solid #e0e0e0",display:"flex",flexDirection:"column"},main:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},toolbar:{padding:"12px 16px",borderBottom:"1px solid #e0e0e0",display:"flex",gap:"12px",alignItems:"center"},list:{flex:1,overflow:"auto"},listItem:{padding:"12px 16px",borderBottom:"1px solid #eee",cursor:"pointer"},detail:{width:"400px",borderLeft:"1px solid #e0e0e0",overflow:"auto",padding:"16px"},input:{padding:"8px 12px",border:"1px solid #ddd",borderRadius:"4px",fontSize:"14px"},button:{padding:"8px 16px",backgroundColor:"#1976d2",color:"white",border:"none",borderRadius:"4px",cursor:"pointer"}};function Mt({service:e,className:t,style:s}){const[i,r]=u.useState([]),[o,a]=u.useState([]),[l,c]=u.useState("all"),[h,p]=u.useState(null),[f,m]=u.useState(""),[v,M]=u.useState("apa"),I=u.useCallback(()=>{r(e.listCitations(l)),a(e.listCollections())},[e,l]),U=u.useMemo(()=>f?e.searchCitations(f,{collection:l}):i,[i,f,l,e]),Q=u.useMemo(()=>i.find(B=>B.id===h),[i,h]),P={service:e,citations:i,collections:o,selectedCollection:l,setSelectedCollection:c,selectedCitation:h,setSelectedCitation:p,searchQuery:f,setSearchQuery:m,citationStyle:v,setCitationStyle:M,refresh:I};return n.jsx(Je.Provider,{value:P,children:n.jsxs("div",{className:t,style:{...ce.container,...s},children:[n.jsxs("div",{style:ce.sidebar,children:[n.jsx("div",{style:{padding:"16px",fontWeight:600},children:"Collections"}),o.map(B=>n.jsxs("div",{onClick:()=>{c(B.id),I()},style:{...ce.listItem,backgroundColor:l===B.id?"#e3f2fd":"transparent"},children:[n.jsx("div",{children:B.name}),n.jsxs("div",{style:{fontSize:"12px",color:"#666"},children:[B.citationCount," items"]})]},B.id))]}),n.jsxs("div",{style:ce.main,children:[n.jsxs("div",{style:ce.toolbar,children:[n.jsx("input",{type:"text",placeholder:"Search references...",value:f,onChange:B=>m(B.target.value),style:{...ce.input,flex:1}}),n.jsxs("select",{value:v,onChange:B=>M(B.target.value),style:ce.input,children:[n.jsx("option",{value:"apa",children:"APA"}),n.jsx("option",{value:"mla",children:"MLA"}),n.jsx("option",{value:"chicago",children:"Chicago"}),n.jsx("option",{value:"harvard",children:"Harvard"}),n.jsx("option",{value:"ieee",children:"IEEE"}),n.jsx("option",{value:"vancouver",children:"Vancouver"}),n.jsx("option",{value:"bibtex",children:"BibTeX"})]}),n.jsx(St,{})]}),n.jsxs("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[n.jsxs("div",{style:ce.list,children:[U.map(B=>n.jsxs("div",{onClick:()=>p(B.id),style:{...ce.listItem,backgroundColor:h===B.id?"#e3f2fd":"transparent"},children:[n.jsx("div",{style:{fontWeight:500,marginBottom:"4px"},children:B.title}),n.jsxs("div",{style:{fontSize:"12px",color:"#666"},children:[B.authors.map(J=>J.family).join(", "),B.year&&` (${B.year})`]}),B.journal&&n.jsx("div",{style:{fontSize:"12px",color:"#888",fontStyle:"italic"},children:B.journal})]},B.id)),U.length===0&&n.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#666"},children:"No references found"})]}),Q&&n.jsx("div",{style:ce.detail,children:n.jsx(wt,{citation:Q})})]})]})]})})}function St(){const{service:e,refresh:t}=Le(),[s,i]=u.useState(!1),[r,o]=u.useState(""),[a,l]=u.useState(!1),c=async()=>{if(r.trim()){l(!0);try{await e.fetchByDOI(r.trim()),t(),o(""),i(!1)}finally{l(!1)}}};return n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>i(!0),style:ce.button,children:"+ Add Reference"}),s&&n.jsx("div",{style:{position:"fixed",inset:0,backgroundColor:"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:h=>h.stopPropagation(),children:[n.jsx("h3",{style:{margin:"0 0 16px 0"},children:"Add Reference by DOI"}),n.jsx("input",{type:"text",value:r,onChange:h=>o(h.target.value),placeholder:"Enter DOI (e.g., 10.1000/xyz123)",style:{...ce.input,width:"100%",marginBottom:"16px"}}),n.jsxs("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[n.jsx("button",{onClick:()=>i(!1),style:{...ce.button,backgroundColor:"#9e9e9e"},children:"Cancel"}),n.jsx("button",{onClick:c,disabled:a,style:ce.button,children:a?"Loading...":"Add"})]})]})})]})}function wt({citation:e}){const{service:t,citationStyle:s}=Le(),[i,r]=u.useState(!1),o=u.useMemo(()=>t.formatCitation(e.id,s),[t,e.id,s]),a=()=>{navigator.clipboard.writeText(o),r(!0),setTimeout(()=>r(!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:"#666",marginBottom:"16px"},children:e.authors.map(l=>`${l.given} ${l.family}`).join(", ")}),n.jsxs("div",{style:{marginBottom:"16px"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"8px"},children:[n.jsxs("strong",{children:["Formatted (",s.toUpperCase(),")"]}),n.jsx("button",{onClick:a,style:{...ce.button,padding:"4px 8px",fontSize:"12px"},children:i?"Copied!":"Copy"})]}),n.jsx("div",{style:{padding:"12px",backgroundColor:"#f5f5f5",borderRadius:"4px",whiteSpace:"pre-wrap",fontSize:"13px"},dangerouslySetInnerHTML:{__html:o.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:"Journal:"})," ",e.journal]}),e.year&&n.jsxs("div",{children:[n.jsx("strong",{children:"Year:"})," ",e.year]}),e.volume&&n.jsxs("div",{children:[n.jsx("strong",{children:"Volume:"})," ",e.volume,e.issue&&`(${e.issue})`]}),e.pages&&n.jsxs("div",{children:[n.jsx("strong",{children:"Pages:"})," ",e.pages]}),e.doi&&n.jsxs("div",{children:[n.jsx("strong",{children:"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:"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:"Abstract:"}),n.jsx("p",{style:{margin:"8px 0 0 0",color:"#444"},children:e.abstract})]})]})]})}const Ct={series:[],xAxes:[],yAxes:[],annotations:[],selectedSeries:[],zoom:{x:null,y:null},cursor:null,hoveredPoint:null};function we(e){return e.reduce((t,s)=>t+s,0)/e.length}function kt(e){const t=[...e].sort((i,r)=>i-r),s=Math.floor(t.length/2);return t.length%2?t[s]:(t[s-1]+t[s])/2}function ze(e){const t=we(e),s=e.map(i=>Math.pow(i-t,2));return Math.sqrt(we(s))}function Dt(e){return ze(e)/Math.sqrt(e.length)}function At(e){const t=we(e),s=Dt(e),i=1.96;return[t-i*s,t+i*s]}function Ft(e){const t=e.length,s=e.map(M=>typeof M.x=="number"?M.x:0),i=e.map(M=>M.y),r=s.reduce((M,I)=>M+I,0),o=i.reduce((M,I)=>M+I,0),a=s.reduce((M,I,U)=>M+I*i[U],0),l=s.reduce((M,I)=>M+I*I,0),c=(t*a-r*o)/(t*l-r*r),h=(o-c*r)/t,p=o/t,f=i.reduce((M,I)=>M+Math.pow(I-p,2),0),v=1-i.reduce((M,I,U)=>M+Math.pow(I-(c*s[U]+h),2),0)/f;return{slope:c,intercept:h,r2:v}}function zt(e,t){const s=we(e),i=we(t),r=ze(e)**2,o=ze(t)**2,a=e.length,l=t.length,c=((a-1)*r+(l-1)*o)/(a+l-2),h=Math.sqrt(c*(1/a+1/l)),p=(s-i)/h,f=Math.exp(-.717*Math.abs(p)-.416*p*p);return{t:p,p:f,significant:f<.05}}function We(e,t,s,i=5){const o=(t-e)/(i-1);return Array.from({length:i},(a,l)=>e+l*o)}function Oe(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 Nt({series:e,title:t,subtitle:s,width:i="100%",height:r=400,type:o="scatter",xAxis:a,yAxis:l,statOverlays:c=[],annotations:h=[],legend:p={show:!0,position:"top",orientation:"horizontal",interactive:!0},tooltip:f={enabled:!0,mode:"point"},zoom:m={enabled:!0,mode:"xy",wheel:!0,drag:!0,resetButton:!0},export:v,statisticalTests:M=[],gridLines:I=!0,aspectRatio:U,animation:Q=!0,theme:P="light",onPointClick:B,onPointHover:J,onZoomChange:ne,onAnnotationChange:q,className:ae,style:de}){const se=u.useRef(null);u.useRef(null);const[H,Y]=u.useState({...Ct,series:e,annotations:h}),[oe,le]=u.useState({width:0,height:0}),[pe,fe]=u.useState({x:null,y:null}),[X,V]=u.useState(null),[ie,Z]=u.useState(new Set(e.map(d=>d.id))),w=u.useMemo(()=>{const d=e.filter($=>ie.has($.id)&&$.visible!==!1);if(d.length===0)return{xMin:0,xMax:1,yMin:0,yMax:1};let g=1/0,S=-1/0,N=1/0,z=-1/0;for(const $ of d)for(const D of $.data){const W=typeof D.x=="number"?D.x:0;if(g=Math.min(g,W),S=Math.max(S,W),N=Math.min(N,D.y),z=Math.max(z,D.y),D.error){const[T,re]=Array.isArray(D.error)?D.error:[-D.error,D.error];N=Math.min(N,D.y+T),z=Math.max(z,D.y+re)}}const L=(S-g)*.05||.5,y=(z-N)*.05||.5;return{xMin:g-L,xMax:S+L,yMin:N-y,yMax:z+y}},[e,ie]),K=u.useMemo(()=>{const d={};for(const g of e){if(!ie.has(g.id))continue;const S=g.data.map(N=>N.y);c.includes("mean")&&(d[`${g.id}_mean`]=we(S)),c.includes("median")&&(d[`${g.id}_median`]=kt(S)),c.includes("std-dev")&&(d[`${g.id}_std`]=ze(S)),c.includes("regression")&&(d[`${g.id}_regression`]=Ft(g.data)),c.includes("confidence-interval")&&(d[`${g.id}_ci95`]=At(S))}return d},[e,ie,c]),G=u.useMemo(()=>M.map(d=>{if(d.type==="t-test"&&d.series.length===2){const g=e.find(N=>N.id===d.series[0]),S=e.find(N=>N.id===d.series[1]);if(g&&S){const N=zt(g.data.map(z=>z.y),S.data.map(z=>z.y));return{...d,result:{statistic:N.t,pValue:N.p,significant:N.significant,interpretation:N.significant?`Significant difference (p = ${N.p.toFixed(4)})`:`No significant difference (p = ${N.p.toFixed(4)})`}}}}return d}),[M,e]),ee=u.useCallback(d=>{Z(g=>{const S=new Set(g);return S.has(d)?S.delete(d):S.add(d),S})},[]),te=u.useCallback(()=>{fe({x:null,y:null}),ne==null||ne(null,null)},[ne]),A=u.useMemo(()=>{switch(P){case"dark":return["#60a5fa","#f472b6","#34d399","#fbbf24","#a78bfa","#fb923c"];case"publication":return["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b"];case"presentation":return["#3b82f6","#ef4444","#22c55e","#f59e0b","#8b5cf6","#ec4899"];default:return["#2563eb","#dc2626","#16a34a","#ca8a04","#7c3aed","#db2777"]}},[P]),C=u.useMemo(()=>{switch(P){case"dark":return{bg:"#1f2937",text:"#f3f4f6",grid:"#374151",axis:"#9ca3af",tooltip:"#374151"};case"publication":return{bg:"#ffffff",text:"#000000",grid:"#e5e5e5",axis:"#333333",tooltip:"#ffffff"};default:return{bg:"#ffffff",text:"#1f2937",grid:"#e5e7eb",axis:"#4b5563",tooltip:"#ffffff"}}},[P]);return n.jsxs("div",{ref:se,className:`nice-scientific-chart nice-scientific-chart--${P} ${ae||""}`,style:{width:i,height:U?"auto":r,aspectRatio:U==null?void 0:U.toString(),backgroundColor:C.bg,color:C.text,fontFamily:P==="publication"?"Times New Roman, serif":"system-ui, sans-serif",...de},children:[t&&n.jsxs("div",{className:"nice-scientific-chart__title",style:{textAlign:"center",fontWeight:"bold",fontSize:"1.25rem",padding:"0.5rem"},children:[t,s&&n.jsx("div",{style:{fontSize:"0.875rem",fontWeight:"normal",color:C.axis},children:s})]}),p.show&&n.jsx("div",{className:"nice-scientific-chart__legend",style:{display:"flex",flexDirection:p.orientation==="vertical"?"column":"row",flexWrap:"wrap",gap:"0.5rem",padding:"0.5rem",justifyContent:"center"},children:e.map((d,g)=>n.jsxs("button",{onClick:()=>p.interactive&&ee(d.id),style:{display:"flex",alignItems:"center",gap:"0.25rem",background:"none",border:"none",cursor:p.interactive?"pointer":"default",opacity:ie.has(d.id)?1:.4,color:"inherit",fontSize:"0.875rem"},children:[n.jsx("span",{style:{width:12,height:12,borderRadius:2,backgroundColor:d.color||A[g%A.length]}}),d.name]},d.id))}),n.jsxs("div",{className:"nice-scientific-chart__canvas",style:{flex:1,position:"relative",minHeight:200},children:[n.jsxs("svg",{width:"100%",height:"100%",style:{overflow:"visible"},children:[I&&n.jsxs("g",{className:"nice-scientific-chart__grid",stroke:C.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=>ie.has(d.id)&&d.visible!==!1).map((d,g)=>{var z,L,y;const S=d.color||A[g%A.length],N=d.type||o;return n.jsx("g",{className:"nice-scientific-chart__series",children:N==="scatter"||N==="line"?n.jsxs(n.Fragment,{children:[N==="line"&&d.data.length>1&&n.jsx("polyline",{fill:"none",stroke:S,strokeWidth:((z=d.line)==null?void 0:z.width)||2,strokeDasharray:((L=d.line)==null?void 0:L.style)==="dashed"?"5,5":((y=d.line)==null?void 0:y.style)==="dotted"?"2,2":void 0,points:d.data.map(($,D)=>{const W=10+((typeof $.x=="number"?$.x:D)-w.xMin)/(w.xMax-w.xMin)*85,T=90-($.y-w.yMin)/(w.yMax-w.yMin)*85;return`${W}%,${T}%`}).join(" ")}),d.data.map(($,D)=>{var ue,me,xe,he,je;const W=10+((typeof $.x=="number"?$.x:D)-w.xMin)/(w.xMax-w.xMin)*85,T=90-($.y-w.yMin)/(w.yMax-w.yMin)*85,re=$.size||((ue=d.marker)==null?void 0:ue.size)||6;return n.jsxs("g",{className:"nice-scientific-chart__point",children:[$.error&&n.jsx("line",{x1:`${W}%`,y1:`${90-($.y+(Array.isArray($.error)?$.error[1]:$.error)-w.yMin)/(w.yMax-w.yMin)*85}%`,x2:`${W}%`,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:`${W}%`,cy:`${T}%`,r:re/2,fill:$.color||((me=d.marker)==null?void 0:me.fillColor)||S,stroke:((xe=d.marker)==null?void 0:xe.strokeColor)||S,strokeWidth:((he=d.marker)==null?void 0:he.strokeWidth)||1,opacity:((je=d.marker)==null?void 0:je.opacity)??1,style:{cursor:B?"pointer":void 0},onMouseEnter:()=>{V({seriesId:d.id,pointIndex:D}),J==null||J($,d)},onMouseLeave:()=>{V(null),J==null||J(null,null)},onClick:ve=>B==null?void 0:B($,d,ve)})]},D)}),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:C.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%"}),We(w.xMin,w.xMax,"linear",6).map((d,g)=>n.jsxs("g",{children:[n.jsx("line",{x1:`${10+g*17}%`,y1:"90%",x2:`${10+g*17}%`,y2:"92%"}),n.jsx("text",{x:`${10+g*17}%`,y:"96%",textAnchor:"middle",fill:C.axis,fontSize:"0.75rem",children:Oe(d)})]},`x-${g}`)),We(w.yMin,w.yMax,"linear",6).map((d,g)=>n.jsxs("g",{children:[n.jsx("line",{x1:"8%",y1:`${90-g*17}%`,x2:"10%",y2:`${90-g*17}%`}),n.jsx("text",{x:"7%",y:`${90-g*17}%`,textAnchor:"end",dominantBaseline:"middle",fill:C.axis,fontSize:"0.75rem",children:Oe(d)})]},`y-${g}`))]}),h.filter(d=>d.visible!==!1).map(d=>{var g,S,N,z,L,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:((g=d.style)==null?void 0:g.color)||C.text,fontSize:((S=d.style)==null?void 0:S.fontSize)||12,fontWeight:(N=d.style)==null?void 0:N.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)||C.text,strokeWidth:((L=d.style)==null?void 0:L.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)})]}),f.enabled&&X&&n.jsx("div",{className:"nice-scientific-chart__tooltip",style:{position:"absolute",padding:"0.5rem",background:C.tooltip,border:`1px solid ${C.grid}`,borderRadius:4,boxShadow:"0 2px 4px rgba(0,0,0,0.1)",pointerEvents:"none",fontSize:"0.75rem"},children:(()=>{const d=e.find(S=>S.id===X.seriesId),g=d==null?void 0:d.data[X.pointIndex];return!d||!g?null:f.format?f.format(g,d):n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{fontWeight:"bold"},children:d.name}),n.jsxs("div",{children:["X: ",g.x instanceof Date?g.x.toISOString():String(g.x)]}),n.jsxs("div",{children:["Y: ",g.y.toFixed(4)]}),g.error&&n.jsxs("div",{children:["Error: ยฑ",Array.isArray(g.error)?`${g.error[0]}, +${g.error[1]}`:g.error]})]})})()})]}),G.some(d=>d.result)&&n.jsxs("div",{className:"nice-scientific-chart__stats",style:{padding:"0.5rem",fontSize:"0.75rem",borderTop:`1px solid ${C.grid}`},children:[n.jsx("strong",{children:"Statistical Tests:"}),G.filter(d=>d.result).map((d,g)=>n.jsxs("div",{children:[d.type,": ",d.result.interpretation]},g))]}),m.enabled&&m.resetButton&&(pe.x||pe.y)&&n.jsx("button",{onClick:te,style:{position:"absolute",top:8,right:8,padding:"0.25rem 0.5rem",fontSize:"0.75rem",background:C.bg,border:`1px solid ${C.grid}`,borderRadius:4,cursor:"pointer"},children:"Reset Zoom"}),v&&v.formats.length>0&&n.jsxs("div",{className:"nice-scientific-chart__export",style:{padding:"0.5rem",borderTop:`1px solid ${C.grid}`},children:[n.jsx("span",{style:{fontSize:"0.75rem",marginRight:"0.5rem"},children:"Export:"}),v.formats.map(d=>n.jsx("button",{style:{marginRight:"0.25rem",padding:"0.25rem 0.5rem",fontSize:"0.75rem",background:"none",border:`1px solid ${C.grid}`,borderRadius:4,cursor:"pointer"},children:d.toUpperCase()},d))]})]})}const Te={rotationX:25,rotationY:-45,rotationZ:0,zoom:1,panX:0,panY:0};function It(e,t){const s=t*Math.PI/180,i=Math.cos(s),r=Math.sin(s);return{x:e.x,y:e.y*i-e.z*r,z:e.y*r+e.z*i}}function Et(e,t){const s=t*Math.PI/180,i=Math.cos(s),r=Math.sin(s);return{x:e.x*i+e.z*r,y:e.y,z:-e.x*r+e.z*i}}function Rt(e,t){const s=t*Math.PI/180,i=Math.cos(s),r=Math.sin(s);return{x:e.x*i-e.y*r,y:e.x*r+e.y*i,z:e.z}}function be(e,t,s){let i=It(e,s.rotationX);i=Et(i,s.rotationY),i=Rt(i,s.rotationZ);const r=i.z+t,o=t/Math.max(r,.1);return{x:(i.x*o*s.zoom+s.panX)*100+50,y:(-i.y*o*s.zoom+s.panY)*100+50,depth:r}}function Me(e,t,s,i){const r=Math.max(0,Math.min(1,(e-t)/(s-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[i]||o.viridis,l=r*(a.length-1),c=Math.floor(l),h=l-c;if(c>=a.length-1){const I=a[a.length-1];return`rgb(${I[0]}, ${I[1]}, ${I[2]})`}const p=a[c],f=a[c+1],m=Math.round(p[0]+h*(f[0]-p[0])),v=Math.round(p[1]+h*(f[1]-p[1])),M=Math.round(p[2]+h*(f[2]-p[2]));return`rgb(${m}, ${v}, ${M})`}function Bt({data:e,title:t,width:s="100%",height:i=500,scene:r={},showColorBar:o=!0,animation:a,showLegend:l=!0,legendPosition:c="top-right",enableRotation:h=!0,enableZoom:p=!0,enablePan:f=!0,showAxes:m=!0,showAxisLabels:v=!0,focalLength:M=3,theme:I="light",onCameraChange:U,onPointClick:Q,onPointHover:P,className:B,style:J}){const ne=u.useRef(null),[q,ae]=u.useState(Te),[de,se]=u.useState(!1),[H,Y]=u.useState(null),[oe,le]=u.useState(null),[pe,fe]=u.useState(0),X=u.useMemo(()=>{let A=1/0,C=-1/0,d=1/0,g=-1/0,S=1/0,N=-1/0,z=1/0,L=-1/0;for(const $ of e)if($.type==="scatter3d")for(const D of $.points)A=Math.min(A,D.x),C=Math.max(C,D.x),d=Math.min(d,D.y),g=Math.max(g,D.y),S=Math.min(S,D.z),N=Math.max(N,D.z),typeof D.color=="number"&&(z=Math.min(z,D.color),L=Math.max(L,D.color));else if($.type==="surface"||$.type==="wireframe"){const D=$;for(const W of D.xData)A=Math.min(A,W),C=Math.max(C,W);for(const W of D.yData)d=Math.min(d,W),g=Math.max(g,W);for(const W of D.zData)for(const T of W)S=Math.min(S,T),N=Math.max(N,T),z=Math.min(z,T),L=Math.max(L,T)}const y=Math.max(C-A,g-d,N-S)||1;return{xMin:A,xMax:C,yMin:d,yMax:g,zMin:S,zMax:N,colorMin:z,colorMax:L,maxRange:y}},[e]),V=u.useCallback(A=>{const C=2/X.maxRange;return{x:(A.x-(X.xMin+X.xMax)/2)*C,y:(A.y-(X.yMin+X.yMax)/2)*C,z:(A.z-(X.zMin+X.zMax)/2)*C}},[X]),ie=u.useCallback(A=>{!h&&!f||(se(!0),Y({x:A.clientX,y:A.clientY,viewState:{...q}}))},[h,f,q]),Z=u.useCallback(A=>{if(!de||!H)return;const C=A.clientX-H.x,d=A.clientY-H.y;A.shiftKey&&f?ae({...H.viewState,panX:H.viewState.panX+C*.002,panY:H.viewState.panY+d*.002}):h&&ae({...H.viewState,rotationY:H.viewState.rotationY+C*.5,rotationX:H.viewState.rotationX+d*.5})},[de,H,h,f]),w=u.useCallback(()=>{se(!1),Y(null)},[]),K=u.useCallback(A=>{if(!p)return;A.preventDefault();const C=A.deltaY>0?.9:1.1;ae(d=>({...d,zoom:Math.max(.1,Math.min(10,d.zoom*C))}))},[p]),G=u.useMemo(()=>{switch(I){case"dark":return{bg:"#1a1a2e",text:"#e0e0e0",axis:"#555",grid:"#333"};case"scientific":return{bg:"#f8f8f8",text:"#333",axis:"#666",grid:"#ddd"};default:return{bg:"#ffffff",text:"#333",axis:"#888",grid:"#e0e0e0"}}},[I]),ee=u.useMemo(()=>{var C;const A=[];for(const d of e)if(d.type==="scatter3d"){const g=d,S=g.points.map(N=>{var D,W,T,re,ue;const z=V(N),L=be(z,M,q);let y=(D=g.marker)==null?void 0:D.color;if(Array.isArray((W=g.marker)==null?void 0:W.color)){const me=g.points.indexOf(N);y=Me(g.marker.color[me],X.colorMin,X.colorMax,((T=g.marker)==null?void 0:T.colorScale)||"viridis")}else typeof N.color=="number"&&(y=Me(N.color,X.colorMin,X.colorMax,((re=g.marker)==null?void 0:re.colorScale)||"viridis"));const $=Array.isArray(N.size)?N.size[0]:N.size||((ue=g.marker)==null?void 0:ue.size)||5;return{...L,color:y,size:$,original:N}});A.push({type:"scatter",points:S,data:d})}else if(d.type==="surface"||d.type==="wireframe"){const g=d,S=[];for(let N=0;N<g.xData.length;N++)for(let z=0;z<g.yData.length;z++){const L={x:g.xData[N],y:g.yData[z],z:g.zData[N][z]},y=V(L),$=be(y,M,q),D=Me(((C=g.colorData)==null?void 0:C[N][z])??g.zData[N][z],X.colorMin,X.colorMax,g.colorScale||"viridis");S.push({...$,color:D,size:3,original:L})}A.push({type:d.type,points:S,data:d})}for(const d of A)d.points.sort((g,S)=>g.depth-S.depth);return A},[e,q,M,V,X]),te=u.useMemo(()=>{var d,g,S;if(!m)return null;const A=1.2,C={x:[be({x:-A,y:0,z:0},M,q),be({x:A,y:0,z:0},M,q)],y:[be({x:0,y:-A,z:0},M,q),be({x:0,y:A,z:0},M,q)],z:[be({x:0,y:0,z:-A},M,q),be({x:0,y:0,z:A},M,q)]};return n.jsxs("g",{className:"nice-3d-plot__axes",children:[n.jsx("line",{x1:`${C.x[0].x}%`,y1:`${C.x[0].y}%`,x2:`${C.x[1].x}%`,y2:`${C.x[1].y}%`,stroke:"#e74c3c",strokeWidth:1.5}),v&&n.jsx("text",{x:`${C.x[1].x+2}%`,y:`${C.x[1].y}%`,fill:"#e74c3c",fontSize:"12",children:((d=r.xAxis)==null?void 0:d.title)||"X"}),n.jsx("line",{x1:`${C.y[0].x}%`,y1:`${C.y[0].y}%`,x2:`${C.y[1].x}%`,y2:`${C.y[1].y}%`,stroke:"#2ecc71",strokeWidth:1.5}),v&&n.jsx("text",{x:`${C.y[1].x}%`,y:`${C.y[1].y-2}%`,fill:"#2ecc71",fontSize:"12",textAnchor:"middle",children:((g=r.yAxis)==null?void 0:g.title)||"Y"}),n.jsx("line",{x1:`${C.z[0].x}%`,y1:`${C.z[0].y}%`,x2:`${C.z[1].x}%`,y2:`${C.z[1].y}%`,stroke:"#3498db",strokeWidth:1.5}),v&&n.jsx("text",{x:`${C.z[1].x+2}%`,y:`${C.z[1].y}%`,fill:"#3498db",fontSize:"12",children:((S=r.zAxis)==null?void 0:S.title)||"Z"})]})},[m,v,q,M,r]);return n.jsxs("div",{ref:ne,className:`nice-3d-plot nice-3d-plot--${I} ${B||""}`,style:{width:s,height:i,backgroundColor:G.bg,color:G.text,position:"relative",overflow:"hidden",userSelect:"none",cursor:de?"grabbing":"grab",...J},onMouseDown:ie,onMouseMove:Z,onMouseUp:w,onMouseLeave:w,onWheel:K,children:[t&&n.jsx("div",{style:{position:"absolute",top:8,left:8,fontWeight:"bold",fontSize:"1.1rem"},children:t}),n.jsxs("svg",{width:"100%",height:"100%",style:{position:"absolute",top:0,left:0},children:[te,ee.map((A,C)=>n.jsxs("g",{className:"nice-3d-plot__data",children:[A.type==="scatter"&&A.points.map((d,g)=>{var S;return n.jsx("circle",{cx:`${d.x}%`,cy:`${d.y}%`,r:d.size||4,fill:d.color||"#3498db",opacity:((S=A.data.marker)==null?void 0:S.opacity)??.8,style:{cursor:Q?"pointer":void 0},onMouseEnter:()=>{le({point:d.original,dataIndex:C}),P==null||P(d.original,C)},onMouseLeave:()=>{le(null),P==null||P(null,C)},onClick:()=>Q==null?void 0:Q(d.original,C)},g)}),(A.type==="surface"||A.type==="wireframe")&&A.points.map((d,g)=>n.jsx("rect",{x:`${d.x-1}%`,y:`${d.y-1}%`,width:"2%",height:"2%",fill:d.color||"#3498db",opacity:A.data.opacity??.7},g))]},A.data.id||C))]}),l&&e.length>1&&n.jsx("div",{style:{position:"absolute",padding:"8px",background:"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,C)=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[n.jsx("span",{style:{width:12,height:12,background:"#3498db",borderRadius:2}}),A.name]},A.id||C))}),o&&n.jsxs("div",{style:{position:"absolute",right:16,top:"50%",transform:"translateY(-50%)",width:16,height:150,background:`linear-gradient(to top, ${Me(0,0,1,"viridis")}, ${Me(.5,0,1,"viridis")}, ${Me(1,0,1,"viridis")})`,borderRadius:2,border:"1px solid #ccc"},children:[n.jsx("div",{style:{position:"absolute",top:-16,right:20,fontSize:"0.7rem"},children:X.colorMax.toFixed(2)}),n.jsx("div",{style:{position:"absolute",bottom:-16,right:20,fontSize:"0.7rem"},children:X.colorMin.toFixed(2)})]}),oe&&n.jsxs("div",{style:{position:"absolute",bottom:8,left:8,background:"rgba(0,0,0,0.8)",color:"#fff",padding:"4px 8px",borderRadius:4,fontSize:"0.75rem"},children:["X: ",oe.point.x.toFixed(4),", Y: ",oe.point.y.toFixed(4),", Z:"," ",oe.point.z.toFixed(4)]}),n.jsx("div",{style:{position:"absolute",bottom:8,right:8,display:"flex",gap:4},children:n.jsx("button",{onClick:()=>ae(Te),style:{padding:"4px 8px",fontSize:"0.75rem",cursor:"pointer"},children:"Reset View"})})]})}const Ge={H:"#FFFFFF",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:"#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"},Ae={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},Lt={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 Xe(e){const t=[],s=[],i=new Map,r=new Map;let o="Unknown";const a=e.split(`
|
|
57
|
-
`);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 h=parseInt(l.substring(6,11).trim(),10),p=l.substring(12,16).trim(),f=l.substring(17,20).trim(),m=l.substring(21,22).trim()||"A",v=parseInt(l.substring(22,26).trim(),10),M=parseFloat(l.substring(30,38).trim()),I=parseFloat(l.substring(38,46).trim()),U=parseFloat(l.substring(46,54).trim()),Q=parseFloat(l.substring(54,60).trim())||1,P=parseFloat(l.substring(60,66).trim())||0,B=l.substring(76,78).trim()||p.replace(/\d/g,"").substring(0,1),J={id:t.length,serial:h,name:p,element:B.toUpperCase(),residueName:f,residueSeq:v,chainId:m,x:M,y:I,z:U,occupancy:Q,bFactor:P,color:Ge[B.toUpperCase()]||"#808080",radius:Ae[B.toUpperCase()]||1.5};t.push(J);const ne=`${m}_${v}_${f}`;i.has(ne)||i.set(ne,{id:i.size,name:f,seq:v,chainId:m,atoms:[]}),i.get(ne).atoms.push(J.id),r.has(m)||r.set(m,{id:m,residues:[]})}else if(c==="CONECT"){const h=l.substring(6).trim().split(/\s+/).map(Number),p=h[0],f=t.find(m=>m.serial===p);if(f)for(let m=1;m<h.length;m++){const v=h[m],M=t.find(I=>I.serial===v);M&&f.id<M.id&&s.push({id:s.length,atom1:f.id,atom2:M.id,order:1})}}}if(s.length===0)for(let l=0;l<t.length;l++)for(let c=l+1;c<t.length;c++){const h=t[l],p=t[c],f=h.x-p.x,m=h.y-p.y,v=h.z-p.z,M=Math.sqrt(f*f+m*m+v*v),I=(Ae[h.element]||1.5)+(Ae[p.element]||1.5)+.4;M<I&&M>.4&&s.push({id:s.length,atom1:l,atom2:c,order:1,length:M})}return{id:"mol_"+Date.now(),name:o,atoms:t,bonds:s,residues:Array.from(i.values()),chains:Array.from(r.values())}}function Wt(e,t,s,i,r,o){const a=v=>v*Math.PI/180,l=t*Math.cos(a(i))-s*Math.sin(a(i)),c=t*Math.sin(a(i))+s*Math.cos(a(i)),h=e*Math.cos(a(r))+c*Math.sin(a(r)),p=-e*Math.sin(a(r))+c*Math.cos(a(r)),f=h*Math.cos(a(o))-l*Math.sin(a(o)),m=h*Math.sin(a(o))+l*Math.cos(a(o));return[f,m,p]}function De(e,t,s,i,r,o){const a=e-r.x,l=t-r.y,c=s-r.z,[h,p,f]=Wt(a,l,c,i.rotX,i.rotY,i.rotZ),m=500,v=m/(m+f*50);return{x:50+h*o*i.zoom*v+i.panX,y:50-p*o*i.zoom*v+i.panY,depth:f}}function Ot({molecule:e,format:t="pdb",style:s="ball-stick",colorScheme:i="element",showHydrogens:r=!0,showWaters:o=!1,showLabels:a=!1,labelType:l="element",width:c="100%",height:h=500,backgroundColor:p="#000000",enableRotation:f=!0,enableZoom:m=!0,showControls:v=!0,measurements:M=[],surfaces:I=[],labels:U=[],selection:Q,highlightColor:P="#FFFF00",spin:B=!1,spinSpeed:J=.5,onAtomClick:ne,onAtomHover:q,onSelectionChange:ae,className:de,styleOverride:se}){const H=u.useRef(null),[Y,oe]=u.useState(null),[le,pe]=u.useState({rotX:0,rotY:0,rotZ:0,zoom:1,panX:0,panY:0}),[fe,X]=u.useState(!1),[V,ie]=u.useState(null),[Z,w]=u.useState(null),[K,G]=u.useState(s);u.useEffect(()=>{if(!e){oe(null);return}typeof e=="string"?(t==="pdb"||console.warn(`Format ${t} parsing not implemented, using PDB parser`),oe(Xe(e))):oe(e)},[e,t]),u.useEffect(()=>{if(!B)return;const y=setInterval(()=>{pe($=>({...$,rotY:($.rotY+J)%360}))},16);return()=>clearInterval(y)},[B,J]);const{center:ee,scale:te}=u.useMemo(()=>{if(!Y||Y.atoms.length===0)return{center:{x:0,y:0,z:0},scale:1};let y=1/0,$=-1/0,D=1/0,W=-1/0,T=1/0,re=-1/0;for(const he of Y.atoms)y=Math.min(y,he.x),$=Math.max($,he.x),D=Math.min(D,he.y),W=Math.max(W,he.y),T=Math.min(T,he.z),re=Math.max(re,he.z);const ue={x:(y+$)/2,y:(D+W)/2,z:(T+re)/2},me=Math.max($-y,W-D,re-T),xe=me>0?35/me:1;return{center:ue,scale:xe}},[Y]),A=u.useMemo(()=>Y?Y.atoms.filter(y=>!r&&y.element==="H"||!o&&y.residueName==="HOH"?!1:y.visible!==!1).map(y=>({atom:y,...De(y.x,y.y,y.z,le,ee,te)})).sort((y,$)=>y.depth-$.depth):[],[Y,le,ee,te,r,o]),C=u.useMemo(()=>Y?Y.bonds.filter(y=>y.visible!==!1).map(y=>{const $=Y.atoms[y.atom1],D=Y.atoms[y.atom2];if(!$||!D||!r&&($.element==="H"||D.element==="H"))return null;const W=De($.x,$.y,$.z,le,ee,te),T=De(D.x,D.y,D.z,le,ee,te);return{bond:y,x1:W.x,y1:W.y,x2:T.x,y2:T.y,depth:(W.depth+T.depth)/2,color1:$.color,color2:D.color}}).filter(Boolean).sort((y,$)=>y.depth-$.depth):[],[Y,le,ee,te,r]),d=u.useCallback(y=>{f&&(X(!0),ie({x:y.clientX,y:y.clientY,view:{...le}}))},[f,le]),g=u.useCallback(y=>{if(!fe||!V)return;const $=y.clientX-V.x,D=y.clientY-V.y;y.shiftKey?pe({...V.view,panX:V.view.panX+$*.1,panY:V.view.panY+D*.1}):pe({...V.view,rotY:V.view.rotY+$*.5,rotX:V.view.rotX+D*.5})},[fe,V]),S=u.useCallback(()=>{X(!1),ie(null)},[]),N=u.useCallback(y=>{if(!m)return;y.preventDefault();const $=y.deltaY>0?.9:1.1;pe(D=>({...D,zoom:Math.max(.1,Math.min(10,D.zoom*$))}))},[m]),z=u.useCallback(y=>{switch(K){case"space-filling":return(Lt[y.element]||1.5)*4;case"ball-stick":return(Ae[y.element]||.5)*3;case"stick":case"wireframe":return 2;default:return 4}},[K]),L=u.useCallback(y=>(K==="wireframe"?1:K==="stick"?3:2)*(y.order||1),[K]);return Y?n.jsxs("div",{ref:H,className:`nice-molecular-viewer ${de||""}`,style:{width:c,height:h,backgroundColor:p,position:"relative",overflow:"hidden",cursor:fe?"grabbing":"grab",...se},onMouseDown:d,onMouseMove:g,onMouseUp:S,onMouseLeave:S,onWheel:N,children:[n.jsxs("svg",{width:"100%",height:"100%",style:{position:"absolute"},children:[K!=="space-filling"&&C.map((y,$)=>n.jsx("line",{x1:`${y.x1}%`,y1:`${y.y1}%`,x2:`${y.x2}%`,y2:`${y.y2}%`,stroke:y.bond.color||"#888888",strokeWidth:L(y.bond),strokeLinecap:"round"},`bond-${$}`)),A.map(({atom:y,x:$,y:D})=>{var ue;const W=(ue=Q==null?void 0:Q.atoms)==null?void 0:ue.includes(y.id),T=(Z==null?void 0:Z.id)===y.id,re=z(y);return n.jsxs("g",{children:[n.jsx("circle",{cx:`${$}%`,cy:`${D}%`,r:re,fill:y.color||Ge[y.element]||"#808080",stroke:W?P:T?"#FFFFFF":"none",strokeWidth:W||T?2:0,style:{cursor:"pointer"},onMouseEnter:()=>{w(y),q==null||q(y)},onMouseLeave:()=>{w(null),q==null||q(null)},onClick:()=>ne==null?void 0:ne(y)}),a&&n.jsx("text",{x:`${$}%`,y:`${D-re*.15}%`,fill:"#FFFFFF",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 $=Y.atoms[y.atoms[0]],D=Y.atoms[y.atoms[1]];if(!$||!D)return null;const W=De($.x,$.y,$.z,le,ee,te),T=De(D.x,D.y,D.z,le,ee,te);return n.jsxs("g",{children:[n.jsx("line",{x1:`${W.x}%`,y1:`${W.y}%`,x2:`${T.x}%`,y2:`${T.y}%`,stroke:y.color||"#FFFF00",strokeWidth:1,strokeDasharray:"3,3"}),n.jsxs("text",{x:`${(W.x+T.x)/2}%`,y:`${(W.y+T.y)/2-1}%`,fill:y.color||"#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:"#FFF",fontSize:"0.8rem"},children:[n.jsx("div",{style:{fontWeight:"bold"},children:Y.name}),n.jsxs("div",{children:[Y.atoms.length," atoms, ",Y.bonds.length," bonds"]}),Y.formula&&n.jsxs("div",{children:["Formula: ",Y.formula]})]}),Z&&n.jsxs("div",{style:{position:"absolute",bottom:8,left:8,background:"rgba(0,0,0,0.8)",color:"#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:["Residue: ",Z.residueName," ",Z.residueSeq]}),Z.chainId&&n.jsxs("div",{children:["Chain: ",Z.chainId]}),n.jsxs("div",{children:["Position: (",Z.x.toFixed(2),", ",Z.y.toFixed(2),","," ",Z.z.toFixed(2),")"]})]}),v&&n.jsxs("div",{style:{position:"absolute",top:8,right:8,display:"flex",flexDirection:"column",gap:4},children:[n.jsxs("select",{value:K,onChange:y=>G(y.target.value),style:{padding:"2px 4px",fontSize:"0.75rem"},children:[n.jsx("option",{value:"ball-stick",children:"Ball & Stick"}),n.jsx("option",{value:"space-filling",children:"Space Filling"}),n.jsx("option",{value:"stick",children:"Stick"}),n.jsx("option",{value:"wireframe",children:"Wireframe"})]}),n.jsx("button",{onClick:()=>pe({rotX:0,rotY:0,rotZ:0,zoom:1,panX:0,panY:0}),style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:"Reset View"})]})]}):n.jsx("div",{className:`nice-molecular-viewer nice-molecular-viewer--empty ${de||""}`,style:{width:c,height:h,backgroundColor:p,display:"flex",alignItems:"center",justifyContent:"center",color:"#666",...se},children:"Load a molecule (PDB, MOL, SDF)"})}function Tt(e){let t=0,s=0;function i(){var l;const o={id:`node_${s++}`};if(e[t]==="(")for(t++,o.children=[];;){const c=i();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 h=parseFloat(c[2]);isNaN(h)||(o.bootstrap=h)}}else o.name=a.trim()}if(e[t]===":"){t++;let c="";for(;t<e.length&&!"[,;()".includes(e[t]);)c+=e[t++];const h=parseFloat(c);isNaN(h)||(o.branchLength=h)}return o}return e.replace(/\s+/g,"").replace(/;$/,"")?i():null}function Qe(e,t=[]){if(t.push(e),e.children)for(const s of e.children)Qe(s,t);return t}function He(e){return!e.children||e.children.length===0?1:e.children.reduce((t,s)=>t+He(s),0)}function et(e,t,s){if(!e.children||e.children.length===0||e.collapsed)return t.set(e.id,s.value),s.value+=1,t.get(e.id);let i=1/0,r=-1/0;for(const a of e.children){const l=et(a,t,s);i=Math.min(i,l),r=Math.max(r,l)}const o=(i+r)/2;return t.set(e.id,o),o}function tt(e,t,s=0){const i=s+(e.branchLength||1);if(t.set(e.id,i),e.children&&!e.collapsed)for(const r of e.children)tt(r,t,i)}function Xt({tree:e,layout:t="rectangular",branchStyle:s="rectangular",nodeShape:i="circle",nodeSize:r=5,showBranchLengths:o=!1,showBootstrap:a=!1,bootstrapThreshold:l=70,showLeafLabels:c=!0,showInternalLabels:h=!1,labelFontSize:p=11,branchWidth:f=1.5,branchColor:m="#666666",nodeColor:v="#333333",highlightColor:M="#2196F3",clades:I=[],annotations:U=[],colorScale:Q,width:P="100%",height:B=500,padding:J=40,enableZoom:ne=!0,enablePan:q=!0,showControls:ae=!0,onNodeClick:de,onNodeHover:se,onBranchClick:H,className:Y,style:oe}){const le=u.useRef(null),[pe,fe]=u.useState(1),[X,V]=u.useState({x:0,y:0}),[ie,Z]=u.useState(!1),[w,K]=u.useState(null),[G,ee]=u.useState(null),[te,A]=u.useState(t),[C,d]=u.useState(new Set),g=u.useMemo(()=>e?typeof e=="string"?Tt(e):e:null,[e]),S=u.useMemo(()=>{if(!g)return null;const j=k=>{var E;return{...k,collapsed:C.has(k.id),children:(E=k.children)==null?void 0:E.map(j)}};return j(g)},[g,C]),{positions:N,leafCount:z,maxX:L}=u.useMemo(()=>{if(!S)return{positions:{x:new Map,y:new Map},leafCount:0,maxX:0};const j=new Map,k=new Map,E=He(S);et(S,k,{value:0}),tt(S,j,0);const x=Math.max(...Array.from(j.values()));return{positions:{x:j,y:k},leafCount:E,maxX:x||1}},[S]),y=u.useMemo(()=>S?Qe(S):[],[S]),$=typeof P=="number"?P:800,D=typeof B=="number"?B:500,W=$-J*2,T=D-J*2,re=j=>J+j/L*W*.7,ue=j=>J+j/(z-1||1)*T,me=(j,k)=>{const E=k/(z-1||1)*2*Math.PI-Math.PI/2,x=j/L*Math.min(W,T)*.4;return{x:$/2+x*Math.cos(E),y:D/2+x*Math.sin(E)}},xe=j=>{const k=N.x.get(j)||0,E=N.y.get(j)||0;return te==="radial"||te==="circular"?me(k,E):{x:re(k),y:ue(E)}},he=u.useCallback(j=>{q&&(Z(!0),K({x:j.clientX,y:j.clientY,pan:{...X}}))},[q,X]),je=u.useCallback(j=>{if(!ie||!w)return;const k=j.clientX-w.x,E=j.clientY-w.y;V({x:w.pan.x+k,y:w.pan.y+E})},[ie,w]),ve=u.useCallback(()=>{Z(!1),K(null)},[]),Ie=u.useCallback(j=>{if(!ne)return;j.preventDefault();const k=j.deltaY>0?.9:1.1;fe(E=>Math.max(.1,Math.min(5,E*k)))},[ne]),Ee=u.useCallback(j=>{d(k=>{const E=new Set(k);return E.has(j)?E.delete(j):E.add(j),E})},[]),Re=(j,k)=>{const E=xe(j.id),x=xe(k.id);if(te==="radial"||te==="circular")return n.jsx("line",{x1:E.x,y1:E.y,x2:x.x,y2:x.y,stroke:k.color||m,strokeWidth:f});switch(s){case"rectangular":return n.jsx("path",{d:`M${E.x},${E.y} H${x.x} V${x.y}`,stroke:k.color||m,strokeWidth:f,fill:"none"});case"diagonal":return n.jsx("line",{x1:E.x,y1:E.y,x2:x.x,y2:x.y,stroke:k.color||m,strokeWidth:f});case"curved":const b=(E.x+x.x)/2;return n.jsx("path",{d:`M${E.x},${E.y} C${b},${E.y} ${b},${x.y} ${x.x},${x.y}`,stroke:k.color||m,strokeWidth:f,fill:"none"});default:return n.jsx("line",{x1:E.x,y1:E.y,x2:x.x,y2:x.y,stroke:k.color||m,strokeWidth:f})}},Ce=j=>{const k=xe(j.id),E=!j.children||j.children.length===0||j.collapsed,x=(G==null?void 0:G.id)===j.id,b=x?r*1.5:r,O=(()=>{switch(i){case"circle":return n.jsx("circle",{cx:k.x,cy:k.y,r:b});case"square":return n.jsx("rect",{x:k.x-b,y:k.y-b,width:b*2,height:b*2});case"triangle":const F=b*1.5;return n.jsx("polygon",{points:`${k.x},${k.y-F} ${k.x-F},${k.y+F} ${k.x+F},${k.y+F}`});case"diamond":return n.jsx("polygon",{points:`${k.x},${k.y-b} ${k.x+b},${k.y} ${k.x},${k.y+b} ${k.x-b},${k.y}`});case"none":return null;default:return n.jsx("circle",{cx:k.x,cy:k.y,r:b})}})();return n.jsxs("g",{children:[O&&n.jsx("g",{fill:j.highlighted?M:j.color||v,stroke:x?M:"none",strokeWidth:2,style:{cursor:"pointer"},onMouseEnter:()=>{ee(j),se==null||se(j)},onMouseLeave:()=>{ee(null),se==null||se(null)},onClick:()=>de==null?void 0:de(j),onDoubleClick:()=>{j.children&&j.children.length>0&&Ee(j.id)},children:O}),j.collapsed&&j.children&&n.jsx("polygon",{points:`${k.x+8},${k.y-6} ${k.x+20},${k.y} ${k.x+8},${k.y+6}`,fill:v,opacity:.5}),E&&c&&j.name&&n.jsx("text",{x:k.x+r+5,y:k.y,fontSize:p,fill:"#333",dominantBaseline:"middle",children:j.name}),!E&&h&&j.name&&n.jsx("text",{x:k.x,y:k.y-r-3,fontSize:p*.9,fill:"#666",textAnchor:"middle",children:j.name}),a&&j.bootstrap!==void 0&&j.bootstrap>=l&&n.jsx("text",{x:k.x,y:k.y-r-2,fontSize:p*.8,fill:"#E91E63",textAnchor:"middle",children:j.bootstrap.toFixed(0)})]},j.id)},ke=j=>{const k=[];if(j.children&&!j.collapsed)for(const E of j.children)k.push(n.jsx("g",{children:Re(j,E)},`branch-${j.id}-${E.id}`)),k.push(...ke(E));return k};return S?n.jsxs("div",{ref:le,className:`nice-phylogenetic-tree ${Y||""}`,style:{width:P,height:B,position:"relative",overflow:"hidden",background:"#FAFAFA",border:"1px solid #E0E0E0",borderRadius:4,cursor:ie?"grabbing":"grab",...oe},onMouseDown:he,onMouseMove:je,onMouseUp:ve,onMouseLeave:ve,onWheel:Ie,children:[n.jsxs("svg",{width:"100%",height:"100%",style:{transform:`translate(${X.x}px, ${X.y}px) scale(${pe})`,transformOrigin:"center center"},children:[I.map(j=>{const k=y.filter(R=>j.nodeIds.includes(R.id));if(k.length===0)return null;const E=k.map(R=>xe(R.id)),x=Math.min(...E.map(R=>R.x))-10,b=Math.max(...E.map(R=>R.x))+10,O=Math.min(...E.map(R=>R.y))-10,F=Math.max(...E.map(R=>R.y))+10;return n.jsxs("g",{children:[n.jsx("rect",{x,y:O,width:b-x,height:F-O,fill:j.background||`${j.color}20`||"#E3F2FD",stroke:j.color||"#2196F3",strokeWidth:1,strokeDasharray:"4,2",rx:4}),j.showLabel&&n.jsx("text",{x:b+5,y:(O+F)/2,fontSize:10,fill:j.color||"#666",dominantBaseline:"middle",children:j.name})]},j.id)}),ke(S),y.map(j=>Ce(j)),U.map(j=>{if(!y.find(b=>b.id===j.nodeId))return null;const E=xe(j.nodeId),x={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:E.x+x.x,y:E.y+x.y,fontSize:j.fontSize||9,fill:j.color||"#FF5722",textAnchor:j.position==="left"?"end":j.position==="right"?"start":"middle",dominantBaseline:"middle",children:j.text},`ann-${j.nodeId}`)})]}),n.jsxs("div",{style:{position:"absolute",top:8,left:8,fontSize:"0.75rem",color:"#666"},children:[y.length," nodes โข ",z," leaves"]}),G&&n.jsxs("div",{style:{position:"absolute",bottom:8,left:8,background:"rgba(255,255,255,0.95)",padding:"4px 8px",borderRadius:4,fontSize:"0.75rem",boxShadow:"0 1px 4px rgba(0,0,0,0.1)"},children:[n.jsx("div",{children:n.jsx("b",{children:G.name||G.id})}),G.branchLength!==void 0&&n.jsxs("div",{children:["Branch length: ",G.branchLength.toFixed(4)]}),G.bootstrap!==void 0&&n.jsxs("div",{children:["Bootstrap: ",G.bootstrap]}),G.children&&n.jsxs("div",{children:["Children: ",G.children.length]})]}),ae&&n.jsxs("div",{style:{position:"absolute",top:8,right:8,display:"flex",flexDirection:"column",gap:4},children:[n.jsxs("select",{value:te,onChange:j=>A(j.target.value),style:{padding:"2px 4px",fontSize:"0.75rem"},children:[n.jsx("option",{value:"rectangular",children:"Rectangular"}),n.jsx("option",{value:"radial",children:"Radial"}),n.jsx("option",{value:"diagonal",children:"Diagonal"})]}),n.jsx("button",{onClick:()=>{fe(1),V({x:0,y:0})},style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:"Reset View"}),n.jsx("button",{onClick:()=>d(new Set),style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:"Expand All"})]})]}):n.jsx("div",{className:`nice-phylogenetic-tree nice-phylogenetic-tree--empty ${Y||""}`,style:{width:P,height:B,display:"flex",alignItems:"center",justifyContent:"center",background:"#F5F5F5",color:"#666",border:"1px dashed #CCC",borderRadius:4,...oe},children:"Load a phylogenetic tree (Newick format)"})}const Se=e=>e*Math.PI/180;function Yt(e,t,s,i){const r=(t+180)/360*s,o=Se(e),a=Math.log(Math.tan(Math.PI/4+o/2)),l=i/2-s*a/(2*Math.PI);return{x:r,y:l}}function _t(e,t,s,i){const r=(t+180)/360*s,o=(90-e)/180*i;return{x:r,y:o}}function Pt(e,t,s,i,r,o){const a=Se(e),l=Se(t),c=Se(r),h=Se(o);if(Math.sin(c)*Math.sin(a)+Math.cos(c)*Math.cos(a)*Math.cos(l-h)<0)return{x:0,y:0,visible:!1};const f=Math.min(s,i)/2-10,m=s/2+f*Math.cos(a)*Math.sin(l-h),v=i/2-f*(Math.cos(c)*Math.sin(a)-Math.sin(c)*Math.cos(a)*Math.cos(l-h));return{x:m,y:v,visible:!0}}function qt(e,t,s,i){const r=[[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 f=0;f<r.length-1;f++)if(o>=r[f][0]&&o<=r[f+1][0]){const m=(o-r[f][0])/5;a=r[f][1]+m*(r[f+1][1]-r[f][1]),l=r[f][2]+m*(r[f+1][2]-r[f][2]);break}const c=s/(2*Math.PI),h=s/2+c*Se(t)*a,p=i/2-c*l*1.3523*Math.sign(e);return{x:h,y:p}}const Vt=`
|
|
56
|
+
`)}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,h,p,f,m,j;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:(f=(p=(h=l.published)==null?void 0:h["date-parts"])==null?void 0:p[0])==null?void 0:f[0],journal:(m=l["container-title"])==null?void 0:m[0],volume:l.volume,issue:l.issue,pages:l.page,doi:l.DOI,issn:(j=l.ISSN)==null?void 0:j[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 h=await c.json(),p=a.map(f=>{var j;const m=h.result[f];return{type:"article",title:m.title||"",authors:(m.authors||[]).map(M=>{const E=M.name.split(" ");return{family:E.pop()||"",given:E.join(" ")}}),year:m.pubdate?parseInt(m.pubdate.split(" ")[0],10):void 0,journal:m.source,volume:m.volume,issue:m.issue,pages:m.pages,pmid:f,doi:(j=m.elocationid)==null?void 0:j.replace("doi: ",""),sourceDatabase:"pubmed"}});return{source:"pubmed",total:parseInt(o.esearchresult.count,10),results:p}}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 h=(await l.json()).message;return this.addCitation({type:"article",title:((r=h.title)==null?void 0:r[0])||"",authors:(h.author||[]).map(p=>({given:p.given||"",family:p.family||"",orcid:p.ORCID})),year:(o=(i=(s=h.published)==null?void 0:s["date-parts"])==null?void 0:i[0])==null?void 0:o[0],journal:(a=h["container-title"])==null?void 0:a[0],volume:h.volume,issue:h.issue,pages:h.page,doi:h.DOI,publisher:h.publisher,abstract:h.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 $t(e){return new Ke(e)}const Je=u.createContext(null);function Le(){const e=u.useContext(Je);if(!e)throw new Error("useCitation must be used within CitationProvider");return e}const ce={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 Mt({service:e,className:t,style:r}){const[s,i]=u.useState([]),[o,a]=u.useState([]),[l,c]=u.useState("all"),[h,p]=u.useState(null),[f,m]=u.useState(""),[j,M]=u.useState("apa"),E=u.useCallback(()=>{i(e.listCitations(l)),a(e.listCollections())},[e,l]),U=u.useMemo(()=>f?e.searchCitations(f,{collection:l}):s,[s,f,l,e]),Q=u.useMemo(()=>s.find(R=>R.id===h),[s,h]),P={service:e,citations:s,collections:o,selectedCollection:l,setSelectedCollection:c,selectedCitation:h,setSelectedCitation:p,searchQuery:f,setSearchQuery:m,citationStyle:j,setCitationStyle:M,refresh:E};return n.jsx(Je.Provider,{value:P,children:n.jsxs("div",{className:t,style:{...ce.container,...r},children:[n.jsxs("div",{style:ce.sidebar,children:[n.jsx("div",{style:{padding:"16px",fontWeight:600},children:"Collections"}),o.map(R=>n.jsxs("div",{onClick:()=>{c(R.id),E()},style:{...ce.listItem,backgroundColor:l===R.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsx("div",{children:R.name}),n.jsxs("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:[R.citationCount," items"]})]},R.id))]}),n.jsxs("div",{style:ce.main,children:[n.jsxs("div",{style:ce.toolbar,children:[n.jsx("input",{type:"text",placeholder:"Search references...",value:f,onChange:R=>m(R.target.value),style:{...ce.input,flex:1}}),n.jsxs("select",{value:j,onChange:R=>M(R.target.value),style:ce.input,children:[n.jsx("option",{value:"apa",children:"APA"}),n.jsx("option",{value:"mla",children:"MLA"}),n.jsx("option",{value:"chicago",children:"Chicago"}),n.jsx("option",{value:"harvard",children:"Harvard"}),n.jsx("option",{value:"ieee",children:"IEEE"}),n.jsx("option",{value:"vancouver",children:"Vancouver"}),n.jsx("option",{value:"bibtex",children:"BibTeX"})]}),n.jsx(St,{})]}),n.jsxs("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[n.jsxs("div",{style:ce.list,children:[U.map(R=>n.jsxs("div",{onClick:()=>p(R.id),style:{...ce.listItem,backgroundColor:h===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(J=>J.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)),U.length===0&&n.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--nice-text-secondary, #666)"},children:"No references found"})]}),Q&&n.jsx("div",{style:ce.detail,children:n.jsx(wt,{citation:Q})})]})]})]})})}function St(){const{service:e,refresh:t}=Le(),[r,s]=u.useState(!1),[i,o]=u.useState(""),[a,l]=u.useState(!1),c=async()=>{if(i.trim()){l(!0);try{await e.fetchByDOI(i.trim()),t(),o(""),s(!1)}finally{l(!1)}}};return n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>s(!0),style:ce.button,children:"+ Add Reference"}),r&&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:()=>s(!1),children:n.jsxs("div",{style:{backgroundColor:"white",padding:"24px",borderRadius:"8px",width:"400px"},onClick:h=>h.stopPropagation(),children:[n.jsx("h3",{style:{margin:"0 0 16px 0"},children:"Add Reference by DOI"}),n.jsx("input",{type:"text",value:i,onChange:h=>o(h.target.value),placeholder:"Enter DOI (e.g., 10.1000/xyz123)",style:{...ce.input,width:"100%",marginBottom:"16px"}}),n.jsxs("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[n.jsx("button",{onClick:()=>s(!1),style:{...ce.button,backgroundColor:"var(--nice-text-secondary, #9e9e9e)"},children:"Cancel"}),n.jsx("button",{onClick:c,disabled:a,style:ce.button,children:a?"Loading...":"Add"})]})]})})]})}function wt({citation:e}){const{service:t,citationStyle:r}=Le(),[s,i]=u.useState(!1),o=u.useMemo(()=>t.formatCitation(e.id,r),[t,e.id,r]),a=()=>{navigator.clipboard.writeText(o),i(!0),setTimeout(()=>i(!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(l=>`${l.given} ${l.family}`).join(", ")}),n.jsxs("div",{style:{marginBottom:"16px"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"8px"},children:[n.jsxs("strong",{children:["Formatted (",r.toUpperCase(),")"]}),n.jsx("button",{onClick:a,style:{...ce.button,padding:"4px 8px",fontSize:"12px"},children:s?"Copied!":"Copy"})]}),n.jsx("div",{style:{padding:"12px",backgroundColor:"var(--nice-bg-secondary, #f5f5f5)",borderRadius:"4px",whiteSpace:"pre-wrap",fontSize:"13px"},dangerouslySetInnerHTML:{__html:o.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:"Journal:"})," ",e.journal]}),e.year&&n.jsxs("div",{children:[n.jsx("strong",{children:"Year:"})," ",e.year]}),e.volume&&n.jsxs("div",{children:[n.jsx("strong",{children:"Volume:"})," ",e.volume,e.issue&&`(${e.issue})`]}),e.pages&&n.jsxs("div",{children:[n.jsx("strong",{children:"Pages:"})," ",e.pages]}),e.doi&&n.jsxs("div",{children:[n.jsx("strong",{children:"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:"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:"Abstract:"}),n.jsx("p",{style:{margin:"8px 0 0 0",color:"var(--nice-text, #444)"},children:e.abstract})]})]})]})}const Ct={series:[],xAxes:[],yAxes:[],annotations:[],selectedSeries:[],zoom:{x:null,y:null},cursor:null,hoveredPoint:null};function we(e){return e.reduce((t,r)=>t+r,0)/e.length}function kt(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 Ne(e){const t=we(e),r=e.map(s=>Math.pow(s-t,2));return Math.sqrt(we(r))}function Dt(e){return Ne(e)/Math.sqrt(e.length)}function At(e){const t=we(e),r=Dt(e),s=1.96;return[t-s*r,t+s*r]}function zt(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,U)=>M+E*s[U],0),l=r.reduce((M,E)=>M+E*E,0),c=(t*a-i*o)/(t*l-i*i),h=(o-c*i)/t,p=o/t,f=s.reduce((M,E)=>M+Math.pow(E-p,2),0),j=1-s.reduce((M,E,U)=>M+Math.pow(E-(c*r[U]+h),2),0)/f;return{slope:c,intercept:h,r2:j}}function Nt(e,t){const r=we(e),s=we(t),i=Ne(e)**2,o=Ne(t)**2,a=e.length,l=t.length,c=((a-1)*i+(l-1)*o)/(a+l-2),h=Math.sqrt(c*(1/a+1/l)),p=(r-s)/h,f=Math.exp(-.717*Math.abs(p)-.416*p*p);return{t:p,p:f,significant:f<.05}}function _e(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 It({series:e,title:t,subtitle:r,width:s="100%",height:i=400,type:o="scatter",xAxis:a,yAxis:l,statOverlays:c=[],annotations:h=[],legend:p={show:!0,position:"top",orientation:"horizontal",interactive:!0},tooltip:f={enabled:!0,mode:"point"},zoom:m={enabled:!0,mode:"xy",wheel:!0,drag:!0,resetButton:!0},export:j,statisticalTests:M=[],gridLines:E=!0,aspectRatio:U,animation:Q=!0,theme:P="light",onPointClick:R,onPointHover:J,onZoomChange:ne,onAnnotationChange:q,className:ae,style:de}){const re=u.useRef(null);u.useRef(null);const[H,X]=u.useState({...Ct,series:e,annotations:h}),[oe,le]=u.useState({width:0,height:0}),[pe,fe]=u.useState({x:null,y:null}),[T,V]=u.useState(null),[se,Z]=u.useState(new Set(e.map(d=>d.id))),w=u.useMemo(()=>{const d=e.filter($=>se.has($.id)&&$.visible!==!1);if(d.length===0)return{xMin:0,xMax:1,yMin:0,yMax:1};let g=1/0,S=-1/0,I=1/0,N=-1/0;for(const $ of d)for(const D of $.data){const _=typeof D.x=="number"?D.x:0;if(g=Math.min(g,_),S=Math.max(S,_),I=Math.min(I,D.y),N=Math.max(N,D.y),D.error){const[O,ie]=Array.isArray(D.error)?D.error:[-D.error,D.error];I=Math.min(I,D.y+O),N=Math.max(N,D.y+ie)}}const L=(S-g)*.05||.5,y=(N-I)*.05||.5;return{xMin:g-L,xMax:S+L,yMin:I-y,yMax:N+y}},[e,se]),K=u.useMemo(()=>{const d={};for(const g of e){if(!se.has(g.id))continue;const S=g.data.map(I=>I.y);c.includes("mean")&&(d[`${g.id}_mean`]=we(S)),c.includes("median")&&(d[`${g.id}_median`]=kt(S)),c.includes("std-dev")&&(d[`${g.id}_std`]=Ne(S)),c.includes("regression")&&(d[`${g.id}_regression`]=zt(g.data)),c.includes("confidence-interval")&&(d[`${g.id}_ci95`]=At(S))}return d},[e,se,c]),G=u.useMemo(()=>M.map(d=>{if(d.type==="t-test"&&d.series.length===2){const g=e.find(I=>I.id===d.series[0]),S=e.find(I=>I.id===d.series[1]);if(g&&S){const I=Nt(g.data.map(N=>N.y),S.data.map(N=>N.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]),ee=u.useCallback(d=>{Z(g=>{const S=new Set(g);return S.has(d)?S.delete(d):S.add(d),S})},[]),te=u.useCallback(()=>{fe({x:null,y:null}),ne==null||ne(null,null)},[ne]),A=u.useMemo(()=>{switch(P){case"dark":return["var(--nice-primary-light, #60a5fa)","var(--nice-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-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-accent-pink, #db2777)"]}},[P]),C=u.useMemo(()=>{switch(P){case"dark":return{bg:"var(--nice-text, #1f2937)",text:"var(--nice-bg-secondary, #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:re,className:`nice-scientific-chart nice-scientific-chart--${P} ${ae||""}`,style:{width:s,height:U?"auto":i,aspectRatio:U==null?void 0:U.toString(),backgroundColor:C.bg,color:C.text,fontFamily:P==="publication"?"Times New Roman, serif":"system-ui, sans-serif",...de},children:[t&&n.jsxs("div",{className:"nice-scientific-chart__title",style:{textAlign:"center",fontWeight:"bold",fontSize:"1.25rem",padding:"0.5rem"},children:[t,r&&n.jsx("div",{style:{fontSize:"0.875rem",fontWeight:"normal",color:C.axis},children:r})]}),p.show&&n.jsx("div",{className:"nice-scientific-chart__legend",style:{display:"flex",flexDirection:p.orientation==="vertical"?"column":"row",flexWrap:"wrap",gap:"0.5rem",padding:"0.5rem",justifyContent:"center"},children:e.map((d,g)=>n.jsxs("button",{onClick:()=>p.interactive&&ee(d.id),style:{display:"flex",alignItems:"center",gap:"0.25rem",background:"none",border:"none",cursor:p.interactive?"pointer":"default",opacity:se.has(d.id)?1:.4,color:"inherit",fontSize:"0.875rem"},children:[n.jsx("span",{style:{width:12,height:12,borderRadius:2,backgroundColor:d.color||A[g%A.length]}}),d.name]},d.id))}),n.jsxs("div",{className:"nice-scientific-chart__canvas",style:{flex:1,position:"relative",minHeight:200},children:[n.jsxs("svg",{width:"100%",height:"100%",style:{overflow:"visible"},children:[E&&n.jsxs("g",{className:"nice-scientific-chart__grid",stroke:C.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=>se.has(d.id)&&d.visible!==!1).map((d,g)=>{var N,L,y;const S=d.color||A[g%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("polyline",{fill:"none",stroke:S,strokeWidth:((N=d.line)==null?void 0:N.width)||2,strokeDasharray:((L=d.line)==null?void 0:L.style)==="dashed"?"5,5":((y=d.line)==null?void 0:y.style)==="dotted"?"2,2":void 0,points:d.data.map(($,D)=>{const _=10+((typeof $.x=="number"?$.x:D)-w.xMin)/(w.xMax-w.xMin)*85,O=90-($.y-w.yMin)/(w.yMax-w.yMin)*85;return`${_}%,${O}%`}).join(" ")}),d.data.map(($,D)=>{var ue,me,xe,he,ve;const _=10+((typeof $.x=="number"?$.x:D)-w.xMin)/(w.xMax-w.xMin)*85,O=90-($.y-w.yMin)/(w.yMax-w.yMin)*85,ie=$.size||((ue=d.marker)==null?void 0:ue.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:ie/2,fill:$.color||((me=d.marker)==null?void 0:me.fillColor)||S,stroke:((xe=d.marker)==null?void 0:xe.strokeColor)||S,strokeWidth:((he=d.marker)==null?void 0:he.strokeWidth)||1,opacity:((ve=d.marker)==null?void 0:ve.opacity)??1,style:{cursor:R?"pointer":void 0},onMouseEnter:()=>{V({seriesId:d.id,pointIndex:D}),J==null||J($,d)},onMouseLeave:()=>{V(null),J==null||J(null,null)},onClick:je=>R==null?void 0:R($,d,je)})]},D)}),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:C.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%"}),_e(w.xMin,w.xMax,"linear",6).map((d,g)=>n.jsxs("g",{children:[n.jsx("line",{x1:`${10+g*17}%`,y1:"90%",x2:`${10+g*17}%`,y2:"92%"}),n.jsx("text",{x:`${10+g*17}%`,y:"96%",textAnchor:"middle",fill:C.axis,fontSize:"0.75rem",children:We(d)})]},`x-${g}`)),_e(w.yMin,w.yMax,"linear",6).map((d,g)=>n.jsxs("g",{children:[n.jsx("line",{x1:"8%",y1:`${90-g*17}%`,x2:"10%",y2:`${90-g*17}%`}),n.jsx("text",{x:"7%",y:`${90-g*17}%`,textAnchor:"end",dominantBaseline:"middle",fill:C.axis,fontSize:"0.75rem",children:We(d)})]},`y-${g}`))]}),h.filter(d=>d.visible!==!1).map(d=>{var g,S,I,N,L,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:((g=d.style)==null?void 0:g.color)||C.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:((N=d.style)==null?void 0:N.color)||C.text,strokeWidth:((L=d.style)==null?void 0:L.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)})]}),f.enabled&&T&&n.jsx("div",{className:"nice-scientific-chart__tooltip",style:{position:"absolute",padding:"0.5rem",background:C.tooltip,border:`1px solid ${C.grid}`,borderRadius:4,boxShadow:"0 2px 4px var(--nice-overlay-10, rgba(0, 0, 0, 0.1))",pointerEvents:"none",fontSize:"0.75rem"},children:(()=>{const d=e.find(S=>S.id===T.seriesId),g=d==null?void 0:d.data[T.pointIndex];return!d||!g?null:f.format?f.format(g,d):n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{fontWeight:"bold"},children:d.name}),n.jsxs("div",{children:["X: ",g.x instanceof Date?g.x.toISOString():String(g.x)]}),n.jsxs("div",{children:["Y: ",g.y.toFixed(4)]}),g.error&&n.jsxs("div",{children:["Error: ยฑ",Array.isArray(g.error)?`${g.error[0]}, +${g.error[1]}`:g.error]})]})})()})]}),G.some(d=>d.result)&&n.jsxs("div",{className:"nice-scientific-chart__stats",style:{padding:"0.5rem",fontSize:"0.75rem",borderTop:`1px solid ${C.grid}`},children:[n.jsx("strong",{children:"Statistical Tests:"}),G.filter(d=>d.result).map((d,g)=>n.jsxs("div",{children:[d.type,": ",d.result.interpretation]},g))]}),m.enabled&&m.resetButton&&(pe.x||pe.y)&&n.jsx("button",{onClick:te,style:{position:"absolute",top:8,right:8,padding:"0.25rem 0.5rem",fontSize:"0.75rem",background:C.bg,border:`1px solid ${C.grid}`,borderRadius:4,cursor:"pointer"},children:"Reset Zoom"}),j&&j.formats.length>0&&n.jsxs("div",{className:"nice-scientific-chart__export",style:{padding:"0.5rem",borderTop:`1px solid ${C.grid}`},children:[n.jsx("span",{style:{fontSize:"0.75rem",marginRight:"0.5rem"},children:"Export:"}),j.formats.map(d=>n.jsx("button",{style:{marginRight:"0.25rem",padding:"0.25rem 0.5rem",fontSize:"0.75rem",background:"none",border:`1px solid ${C.grid}`,borderRadius:4,cursor:"pointer"},children:d.toUpperCase()},d))]})]})}const Oe={rotationX:25,rotationY:-45,rotationZ:0,zoom:1,panX:0,panY:0};function Et(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 Ft(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 Bt(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 be(e,t,r){let s=Et(e,r.rotationX);s=Ft(s,r.rotationY),s=Bt(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 Me(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),h=l-c;if(c>=a.length-1){const E=a[a.length-1];return`rgb(${E[0]}, ${E[1]}, ${E[2]})`}const p=a[c],f=a[c+1],m=Math.round(p[0]+h*(f[0]-p[0])),j=Math.round(p[1]+h*(f[1]-p[1])),M=Math.round(p[2]+h*(f[2]-p[2]));return`rgb(${m}, ${j}, ${M})`}function Rt({data:e,title:t,width:r="100%",height:s=500,scene:i={},showColorBar:o=!0,animation:a,showLegend:l=!0,legendPosition:c="top-right",enableRotation:h=!0,enableZoom:p=!0,enablePan:f=!0,showAxes:m=!0,showAxisLabels:j=!0,focalLength:M=3,theme:E="light",onCameraChange:U,onPointClick:Q,onPointHover:P,className:R,style:J}){const ne=u.useRef(null),[q,ae]=u.useState(Oe),[de,re]=u.useState(!1),[H,X]=u.useState(null),[oe,le]=u.useState(null),[pe,fe]=u.useState(0),T=u.useMemo(()=>{let A=1/0,C=-1/0,d=1/0,g=-1/0,S=1/0,I=-1/0,N=1/0,L=-1/0;for(const $ of e)if($.type==="scatter3d")for(const D of $.points)A=Math.min(A,D.x),C=Math.max(C,D.x),d=Math.min(d,D.y),g=Math.max(g,D.y),S=Math.min(S,D.z),I=Math.max(I,D.z),typeof D.color=="number"&&(N=Math.min(N,D.color),L=Math.max(L,D.color));else if($.type==="surface"||$.type==="wireframe"){const D=$;for(const _ of D.xData)A=Math.min(A,_),C=Math.max(C,_);for(const _ of D.yData)d=Math.min(d,_),g=Math.max(g,_);for(const _ of D.zData)for(const O of _)S=Math.min(S,O),I=Math.max(I,O),N=Math.min(N,O),L=Math.max(L,O)}const y=Math.max(C-A,g-d,I-S)||1;return{xMin:A,xMax:C,yMin:d,yMax:g,zMin:S,zMax:I,colorMin:N,colorMax:L,maxRange:y}},[e]),V=u.useCallback(A=>{const C=2/T.maxRange;return{x:(A.x-(T.xMin+T.xMax)/2)*C,y:(A.y-(T.yMin+T.yMax)/2)*C,z:(A.z-(T.zMin+T.zMax)/2)*C}},[T]),se=u.useCallback(A=>{!h&&!f||(re(!0),X({x:A.clientX,y:A.clientY,viewState:{...q}}))},[h,f,q]),Z=u.useCallback(A=>{if(!de||!H)return;const C=A.clientX-H.x,d=A.clientY-H.y;A.shiftKey&&f?ae({...H.viewState,panX:H.viewState.panX+C*.002,panY:H.viewState.panY+d*.002}):h&&ae({...H.viewState,rotationY:H.viewState.rotationY+C*.5,rotationX:H.viewState.rotationX+d*.5})},[de,H,h,f]),w=u.useCallback(()=>{re(!1),X(null)},[]),K=u.useCallback(A=>{if(!p)return;A.preventDefault();const C=A.deltaY>0?.9:1.1;ae(d=>({...d,zoom:Math.max(.1,Math.min(10,d.zoom*C))}))},[p]),G=u.useMemo(()=>{switch(E){case"dark":return{bg:"var(--nice-bg, #1a1a2e)",text:"var(--nice-border, #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]),ee=u.useMemo(()=>{var C;const A=[];for(const d of e)if(d.type==="scatter3d"){const g=d,S=g.points.map(I=>{var D,_,O,ie,ue;const N=V(I),L=be(N,M,q);let y=(D=g.marker)==null?void 0:D.color;if(Array.isArray((_=g.marker)==null?void 0:_.color)){const me=g.points.indexOf(I);y=Me(g.marker.color[me],T.colorMin,T.colorMax,((O=g.marker)==null?void 0:O.colorScale)||"viridis")}else typeof I.color=="number"&&(y=Me(I.color,T.colorMin,T.colorMax,((ie=g.marker)==null?void 0:ie.colorScale)||"viridis"));const $=Array.isArray(I.size)?I.size[0]:I.size||((ue=g.marker)==null?void 0:ue.size)||5;return{...L,color:y,size:$,original:I}});A.push({type:"scatter",points:S,data:d})}else if(d.type==="surface"||d.type==="wireframe"){const g=d,S=[];for(let I=0;I<g.xData.length;I++)for(let N=0;N<g.yData.length;N++){const L={x:g.xData[I],y:g.yData[N],z:g.zData[I][N]},y=V(L),$=be(y,M,q),D=Me(((C=g.colorData)==null?void 0:C[I][N])??g.zData[I][N],T.colorMin,T.colorMax,g.colorScale||"viridis");S.push({...$,color:D,size:3,original:L})}A.push({type:d.type,points:S,data:d})}for(const d of A)d.points.sort((g,S)=>g.depth-S.depth);return A},[e,q,M,V,T]),te=u.useMemo(()=>{var d,g,S;if(!m)return null;const A=1.2,C={x:[be({x:-A,y:0,z:0},M,q),be({x:A,y:0,z:0},M,q)],y:[be({x:0,y:-A,z:0},M,q),be({x:0,y:A,z:0},M,q)],z:[be({x:0,y:0,z:-A},M,q),be({x:0,y:0,z:A},M,q)]};return n.jsxs("g",{className:"nice-3d-plot__axes",children:[n.jsx("line",{x1:`${C.x[0].x}%`,y1:`${C.x[0].y}%`,x2:`${C.x[1].x}%`,y2:`${C.x[1].y}%`,stroke:"var(--nice-danger, #e74c3c)",strokeWidth:1.5}),j&&n.jsx("text",{x:`${C.x[1].x+2}%`,y:`${C.x[1].y}%`,fill:"var(--nice-danger, #e74c3c)",fontSize:"12",children:((d=i.xAxis)==null?void 0:d.title)||"X"}),n.jsx("line",{x1:`${C.y[0].x}%`,y1:`${C.y[0].y}%`,x2:`${C.y[1].x}%`,y2:`${C.y[1].y}%`,stroke:"var(--nice-success, #2ecc71)",strokeWidth:1.5}),j&&n.jsx("text",{x:`${C.y[1].x}%`,y:`${C.y[1].y-2}%`,fill:"var(--nice-success, #2ecc71)",fontSize:"12",textAnchor:"middle",children:((g=i.yAxis)==null?void 0:g.title)||"Y"}),n.jsx("line",{x1:`${C.z[0].x}%`,y1:`${C.z[0].y}%`,x2:`${C.z[1].x}%`,y2:`${C.z[1].y}%`,stroke:"var(--nice-primary, #3498db)",strokeWidth:1.5}),j&&n.jsx("text",{x:`${C.z[1].x+2}%`,y:`${C.z[1].y}%`,fill:"var(--nice-primary, #3498db)",fontSize:"12",children:((S=i.zAxis)==null?void 0:S.title)||"Z"})]})},[m,j,q,M,i]);return n.jsxs("div",{ref:ne,className:`nice-3d-plot nice-3d-plot--${E} ${R||""}`,style:{width:r,height:s,backgroundColor:G.bg,color:G.text,position:"relative",overflow:"hidden",userSelect:"none",cursor:de?"grabbing":"grab",...J},onMouseDown:se,onMouseMove:Z,onMouseUp:w,onMouseLeave:w,onWheel:K,children:[t&&n.jsx("div",{style:{position:"absolute",top:8,left:8,fontWeight:"bold",fontSize:"1.1rem"},children:t}),n.jsxs("svg",{width:"100%",height:"100%",style:{position:"absolute",top:0,left:0},children:[te,ee.map((A,C)=>n.jsxs("g",{className:"nice-3d-plot__data",children:[A.type==="scatter"&&A.points.map((d,g)=>{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:Q?"pointer":void 0},onMouseEnter:()=>{le({point:d.original,dataIndex:C}),P==null||P(d.original,C)},onMouseLeave:()=>{le(null),P==null||P(null,C)},onClick:()=>Q==null?void 0:Q(d.original,C)},g)}),(A.type==="surface"||A.type==="wireframe")&&A.points.map((d,g)=>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},g))]},A.data.id||C))]}),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,C)=>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||C))}),o&&n.jsxs("div",{style:{position:"absolute",right:16,top:"50%",transform:"translateY(-50%)",width:16,height:150,background:`linear-gradient(to top, ${Me(0,0,1,"viridis")}, ${Me(.5,0,1,"viridis")}, ${Me(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:T.colorMax.toFixed(2)}),n.jsx("div",{style:{position:"absolute",bottom:-16,right:20,fontSize:"0.7rem"},children:T.colorMin.toFixed(2)})]}),oe&&n.jsxs("div",{style:{position:"absolute",bottom:8,left:8,background:"var(--nice-overlay-80, rgba(0, 0, 0, 0.8))",color:"var(--nice-bg, #fff)",padding:"4px 8px",borderRadius:4,fontSize:"0.75rem"},children:["X: ",oe.point.x.toFixed(4),", Y: ",oe.point.y.toFixed(4),", Z:"," ",oe.point.z.toFixed(4)]}),n.jsx("div",{style:{position:"absolute",bottom:8,right:8,display:"flex",gap:4},children:n.jsx("button",{onClick:()=>ae(Oe),style:{padding:"4px 8px",fontSize:"0.75rem",cursor:"pointer"},children:"Reset View"})})]})}const Ge={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"},Ae={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},Lt={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 Te(e){const t=[],r=[],s=new Map,i=new Map;let o="Unknown";const a=e.split(`
|
|
57
|
+
`);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 h=parseInt(l.substring(6,11).trim(),10),p=l.substring(12,16).trim(),f=l.substring(17,20).trim(),m=l.substring(21,22).trim()||"A",j=parseInt(l.substring(22,26).trim(),10),M=parseFloat(l.substring(30,38).trim()),E=parseFloat(l.substring(38,46).trim()),U=parseFloat(l.substring(46,54).trim()),Q=parseFloat(l.substring(54,60).trim())||1,P=parseFloat(l.substring(60,66).trim())||0,R=l.substring(76,78).trim()||p.replace(/\d/g,"").substring(0,1),J={id:t.length,serial:h,name:p,element:R.toUpperCase(),residueName:f,residueSeq:j,chainId:m,x:M,y:E,z:U,occupancy:Q,bFactor:P,color:Ge[R.toUpperCase()]||"var(--nice-text-secondary, #808080)",radius:Ae[R.toUpperCase()]||1.5};t.push(J);const ne=`${m}_${j}_${f}`;s.has(ne)||s.set(ne,{id:s.size,name:f,seq:j,chainId:m,atoms:[]}),s.get(ne).atoms.push(J.id),i.has(m)||i.set(m,{id:m,residues:[]})}else if(c==="CONECT"){const h=l.substring(6).trim().split(/\s+/).map(Number),p=h[0],f=t.find(m=>m.serial===p);if(f)for(let m=1;m<h.length;m++){const j=h[m],M=t.find(E=>E.serial===j);M&&f.id<M.id&&r.push({id:r.length,atom1:f.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 h=t[l],p=t[c],f=h.x-p.x,m=h.y-p.y,j=h.z-p.z,M=Math.sqrt(f*f+m*m+j*j),E=(Ae[h.element]||1.5)+(Ae[p.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 _t(e,t,r,s,i,o){const a=j=>j*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)),h=e*Math.cos(a(i))+c*Math.sin(a(i)),p=-e*Math.sin(a(i))+c*Math.cos(a(i)),f=h*Math.cos(a(o))-l*Math.sin(a(o)),m=h*Math.sin(a(o))+l*Math.cos(a(o));return[f,m,p]}function De(e,t,r,s,i,o){const a=e-i.x,l=t-i.y,c=r-i.z,[h,p,f]=_t(a,l,c,s.rotX,s.rotY,s.rotZ),m=500,j=m/(m+f*50);return{x:50+h*o*s.zoom*j+s.panX,y:50-p*o*s.zoom*j+s.panY,depth:f}}function Wt({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:h=500,backgroundColor:p="var(--nice-text, #000000)",enableRotation:f=!0,enableZoom:m=!0,showControls:j=!0,measurements:M=[],surfaces:E=[],labels:U=[],selection:Q,highlightColor:P="var(--nice-warning, #ffff00)",spin:R=!1,spinSpeed:J=.5,onAtomClick:ne,onAtomHover:q,onSelectionChange:ae,className:de,styleOverride:re}){const H=u.useRef(null),[X,oe]=u.useState(null),[le,pe]=u.useState({rotX:0,rotY:0,rotZ:0,zoom:1,panX:0,panY:0}),[fe,T]=u.useState(!1),[V,se]=u.useState(null),[Z,w]=u.useState(null),[K,G]=u.useState(r);u.useEffect(()=>{if(!e){oe(null);return}typeof e=="string"?(t==="pdb"||console.warn(`Format ${t} parsing not implemented, using PDB parser`),oe(Te(e))):oe(e)},[e,t]),u.useEffect(()=>{if(!R)return;const y=setInterval(()=>{pe($=>({...$,rotY:($.rotY+J)%360}))},16);return()=>clearInterval(y)},[R,J]);const{center:ee,scale:te}=u.useMemo(()=>{if(!X||X.atoms.length===0)return{center:{x:0,y:0,z:0},scale:1};let y=1/0,$=-1/0,D=1/0,_=-1/0,O=1/0,ie=-1/0;for(const he of X.atoms)y=Math.min(y,he.x),$=Math.max($,he.x),D=Math.min(D,he.y),_=Math.max(_,he.y),O=Math.min(O,he.z),ie=Math.max(ie,he.z);const ue={x:(y+$)/2,y:(D+_)/2,z:(O+ie)/2},me=Math.max($-y,_-D,ie-O),xe=me>0?35/me:1;return{center:ue,scale:xe}},[X]),A=u.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,le,ee,te)})).sort((y,$)=>y.depth-$.depth):[],[X,le,ee,te,i,o]),C=u.useMemo(()=>X?X.bonds.filter(y=>y.visible!==!1).map(y=>{const $=X.atoms[y.atom1],D=X.atoms[y.atom2];if(!$||!D||!i&&($.element==="H"||D.element==="H"))return null;const _=De($.x,$.y,$.z,le,ee,te),O=De(D.x,D.y,D.z,le,ee,te);return{bond:y,x1:_.x,y1:_.y,x2:O.x,y2:O.y,depth:(_.depth+O.depth)/2,color1:$.color,color2:D.color}}).filter(Boolean).sort((y,$)=>y.depth-$.depth):[],[X,le,ee,te,i]),d=u.useCallback(y=>{f&&(T(!0),se({x:y.clientX,y:y.clientY,view:{...le}}))},[f,le]),g=u.useCallback(y=>{if(!fe||!V)return;const $=y.clientX-V.x,D=y.clientY-V.y;y.shiftKey?pe({...V.view,panX:V.view.panX+$*.1,panY:V.view.panY+D*.1}):pe({...V.view,rotY:V.view.rotY+$*.5,rotX:V.view.rotX+D*.5})},[fe,V]),S=u.useCallback(()=>{T(!1),se(null)},[]),I=u.useCallback(y=>{if(!m)return;y.preventDefault();const $=y.deltaY>0?.9:1.1;pe(D=>({...D,zoom:Math.max(.1,Math.min(10,D.zoom*$))}))},[m]),N=u.useCallback(y=>{switch(K){case"space-filling":return(Lt[y.element]||1.5)*4;case"ball-stick":return(Ae[y.element]||.5)*3;case"stick":case"wireframe":return 2;default:return 4}},[K]),L=u.useCallback(y=>(K==="wireframe"?1:K==="stick"?3:2)*(y.order||1),[K]);return X?n.jsxs("div",{ref:H,className:`nice-molecular-viewer ${de||""}`,style:{width:c,height:h,backgroundColor:p,position:"relative",overflow:"hidden",cursor:fe?"grabbing":"grab",...re},onMouseDown:d,onMouseMove:g,onMouseUp:S,onMouseLeave:S,onWheel:I,children:[n.jsxs("svg",{width:"100%",height:"100%",style:{position:"absolute"},children:[K!=="space-filling"&&C.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:L(y.bond),strokeLinecap:"round"},`bond-${$}`)),A.map(({atom:y,x:$,y:D})=>{var ue;const _=(ue=Q==null?void 0:Q.atoms)==null?void 0:ue.includes(y.id),O=(Z==null?void 0:Z.id)===y.id,ie=N(y);return n.jsxs("g",{children:[n.jsx("circle",{cx:`${$}%`,cy:`${D}%`,r:ie,fill:y.color||Ge[y.element]||"var(--nice-text-secondary, #808080)",stroke:_?P:O?"var(--nice-bg, #fff)":"none",strokeWidth:_||O?2:0,style:{cursor:"pointer"},onMouseEnter:()=>{w(y),q==null||q(y)},onMouseLeave:()=>{w(null),q==null||q(null)},onClick:()=>ne==null?void 0:ne(y)}),a&&n.jsx("text",{x:`${$}%`,y:`${D-ie*.15}%`,fill:"var(--nice-bg, #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]],D=X.atoms[y.atoms[1]];if(!$||!D)return null;const _=De($.x,$.y,$.z,le,ee,te),O=De(D.x,D.y,D.z,le,ee,te);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-bg, #fff)",fontSize:"0.8rem"},children:[n.jsx("div",{style:{fontWeight:"bold"},children:X.name}),n.jsxs("div",{children:[X.atoms.length," atoms, ",X.bonds.length," bonds"]}),X.formula&&n.jsxs("div",{children:["Formula: ",X.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-bg, #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:["Residue: ",Z.residueName," ",Z.residueSeq]}),Z.chainId&&n.jsxs("div",{children:["Chain: ",Z.chainId]}),n.jsxs("div",{children:["Position: (",Z.x.toFixed(2),", ",Z.y.toFixed(2),","," ",Z.z.toFixed(2),")"]})]}),j&&n.jsxs("div",{style:{position:"absolute",top:8,right:8,display:"flex",flexDirection:"column",gap:4},children:[n.jsxs("select",{value:K,onChange:y=>G(y.target.value),style:{padding:"2px 4px",fontSize:"0.75rem"},children:[n.jsx("option",{value:"ball-stick",children:"Ball & Stick"}),n.jsx("option",{value:"space-filling",children:"Space Filling"}),n.jsx("option",{value:"stick",children:"Stick"}),n.jsx("option",{value:"wireframe",children:"Wireframe"})]}),n.jsx("button",{onClick:()=>pe({rotX:0,rotY:0,rotZ:0,zoom:1,panX:0,panY:0}),style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:"Reset View"})]})]}):n.jsx("div",{className:`nice-molecular-viewer nice-molecular-viewer--empty ${de||""}`,style:{width:c,height:h,backgroundColor:p,display:"flex",alignItems:"center",justifyContent:"center",color:"var(--nice-text-secondary, #666)",...re},children:"Load a molecule (PDB, MOL, SDF)"})}function Ot(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 h=parseFloat(c[2]);isNaN(h)||(o.bootstrap=h)}}else o.name=a.trim()}if(e[t]===":"){t++;let c="";for(;t<e.length&&!"[,;()".includes(e[t]);)c+=e[t++];const h=parseFloat(c);isNaN(h)||(o.branchLength=h)}return o}return e.replace(/\s+/g,"").replace(/;$/,"")?s():null}function Qe(e,t=[]){if(t.push(e),e.children)for(const r of e.children)Qe(r,t);return t}function He(e){return!e.children||e.children.length===0?1:e.children.reduce((t,r)=>t+He(r),0)}function et(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=et(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 tt(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)tt(i,t,s)}function Tt({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:h=!1,labelFontSize:p=11,branchWidth:f=1.5,branchColor:m="var(--nice-text-secondary, #666666)",nodeColor:j="var(--nice-text, #333333)",highlightColor:M="var(--nice-primary, #2196f3)",clades:E=[],annotations:U=[],colorScale:Q,width:P="100%",height:R=500,padding:J=40,enableZoom:ne=!0,enablePan:q=!0,showControls:ae=!0,onNodeClick:de,onNodeHover:re,onBranchClick:H,className:X,style:oe}){const le=u.useRef(null),[pe,fe]=u.useState(1),[T,V]=u.useState({x:0,y:0}),[se,Z]=u.useState(!1),[w,K]=u.useState(null),[G,ee]=u.useState(null),[te,A]=u.useState(t),[C,d]=u.useState(new Set),g=u.useMemo(()=>e?typeof e=="string"?Ot(e):e:null,[e]),S=u.useMemo(()=>{if(!g)return null;const v=k=>{var F;return{...k,collapsed:C.has(k.id),children:(F=k.children)==null?void 0:F.map(v)}};return v(g)},[g,C]),{positions:I,leafCount:N,maxX:L}=u.useMemo(()=>{if(!S)return{positions:{x:new Map,y:new Map},leafCount:0,maxX:0};const v=new Map,k=new Map,F=He(S);et(S,k,{value:0}),tt(S,v,0);const x=Math.max(...Array.from(v.values()));return{positions:{x:v,y:k},leafCount:F,maxX:x||1}},[S]),y=u.useMemo(()=>S?Qe(S):[],[S]),$=typeof P=="number"?P:800,D=typeof R=="number"?R:500,_=$-J*2,O=D-J*2,ie=v=>J+v/L*_*.7,ue=v=>J+v/(N-1||1)*O,me=(v,k)=>{const F=k/(N-1||1)*2*Math.PI-Math.PI/2,x=v/L*Math.min(_,O)*.4;return{x:$/2+x*Math.cos(F),y:D/2+x*Math.sin(F)}},xe=v=>{const k=I.x.get(v)||0,F=I.y.get(v)||0;return te==="radial"||te==="circular"?me(k,F):{x:ie(k),y:ue(F)}},he=u.useCallback(v=>{q&&(Z(!0),K({x:v.clientX,y:v.clientY,pan:{...T}}))},[q,T]),ve=u.useCallback(v=>{if(!se||!w)return;const k=v.clientX-w.x,F=v.clientY-w.y;V({x:w.pan.x+k,y:w.pan.y+F})},[se,w]),je=u.useCallback(()=>{Z(!1),K(null)},[]),Ee=u.useCallback(v=>{if(!ne)return;v.preventDefault();const k=v.deltaY>0?.9:1.1;fe(F=>Math.max(.1,Math.min(5,F*k)))},[ne]),Fe=u.useCallback(v=>{d(k=>{const F=new Set(k);return F.has(v)?F.delete(v):F.add(v),F})},[]),Be=(v,k)=>{const F=xe(v.id),x=xe(k.id);if(te==="radial"||te==="circular")return n.jsx("line",{x1:F.x,y1:F.y,x2:x.x,y2:x.y,stroke:k.color||m,strokeWidth:f});switch(r){case"rectangular":return n.jsx("path",{d:`M${F.x},${F.y} H${x.x} V${x.y}`,stroke:k.color||m,strokeWidth:f,fill:"none"});case"diagonal":return n.jsx("line",{x1:F.x,y1:F.y,x2:x.x,y2:x.y,stroke:k.color||m,strokeWidth:f});case"curved":{const b=(F.x+x.x)/2;return n.jsx("path",{d:`M${F.x},${F.y} C${b},${F.y} ${b},${x.y} ${x.x},${x.y}`,stroke:k.color||m,strokeWidth:f,fill:"none"})}default:return n.jsx("line",{x1:F.x,y1:F.y,x2:x.x,y2:x.y,stroke:k.color||m,strokeWidth:f})}},Ce=v=>{const k=xe(v.id),F=!v.children||v.children.length===0||v.collapsed,x=(G==null?void 0:G.id)===v.id,b=x?i*1.5:i,W=(()=>{switch(s){case"circle":return n.jsx("circle",{cx:k.x,cy:k.y,r:b});case"square":return n.jsx("rect",{x:k.x-b,y:k.y-b,width:b*2,height:b*2});case"triangle":{const z=b*1.5;return n.jsx("polygon",{points:`${k.x},${k.y-z} ${k.x-z},${k.y+z} ${k.x+z},${k.y+z}`})}case"diamond":return n.jsx("polygon",{points:`${k.x},${k.y-b} ${k.x+b},${k.y} ${k.x},${k.y+b} ${k.x-b},${k.y}`});case"none":return null;default:return n.jsx("circle",{cx:k.x,cy:k.y,r:b})}})();return n.jsxs("g",{children:[W&&n.jsx("g",{fill:v.highlighted?M:v.color||j,stroke:x?M:"none",strokeWidth:2,style:{cursor:"pointer"},onMouseEnter:()=>{ee(v),re==null||re(v)},onMouseLeave:()=>{ee(null),re==null||re(null)},onClick:()=>de==null?void 0:de(v),onDoubleClick:()=>{v.children&&v.children.length>0&&Fe(v.id)},children:W}),v.collapsed&&v.children&&n.jsx("polygon",{points:`${k.x+8},${k.y-6} ${k.x+20},${k.y} ${k.x+8},${k.y+6}`,fill:j,opacity:.5}),F&&c&&v.name&&n.jsx("text",{x:k.x+i+5,y:k.y,fontSize:p,fill:"var(--nice-text, #333)",dominantBaseline:"middle",children:v.name}),!F&&h&&v.name&&n.jsx("text",{x:k.x,y:k.y-i-3,fontSize:p*.9,fill:"var(--nice-text-secondary, #666)",textAnchor:"middle",children:v.name}),a&&v.bootstrap!==void 0&&v.bootstrap>=l&&n.jsx("text",{x:k.x,y:k.y-i-2,fontSize:p*.8,fill:"var(--nice-accent-pink, #e91e63)",textAnchor:"middle",children:v.bootstrap.toFixed(0)})]},v.id)},ke=v=>{const k=[];if(v.children&&!v.collapsed)for(const F of v.children)k.push(n.jsx("g",{children:Be(v,F)},`branch-${v.id}-${F.id}`)),k.push(...ke(F));return k};return S?n.jsxs("div",{ref:le,className:`nice-phylogenetic-tree ${X||""}`,style:{width:P,height:R,position:"relative",overflow:"hidden",background:"var(--nice-bg-secondary, #fafafa)",border:"1px solid var(--nice-border, #e0e0e0)",borderRadius:4,cursor:se?"grabbing":"grab",...oe},onMouseDown:he,onMouseMove:ve,onMouseUp:je,onMouseLeave:je,onWheel:Ee,children:[n.jsxs("svg",{width:"100%",height:"100%",style:{transform:`translate(${T.x}px, ${T.y}px) scale(${pe})`,transformOrigin:"center center"},children:[E.map(v=>{const k=y.filter(B=>v.nodeIds.includes(B.id));if(k.length===0)return null;const F=k.map(B=>xe(B.id)),x=Math.min(...F.map(B=>B.x))-10,b=Math.max(...F.map(B=>B.x))+10,W=Math.min(...F.map(B=>B.y))-10,z=Math.max(...F.map(B=>B.y))+10;return n.jsxs("g",{children:[n.jsx("rect",{x,y:W,width:b-x,height:z-W,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:(W+z)/2,fontSize:10,fill:v.color||"var(--nice-text-secondary, #666)",dominantBaseline:"middle",children:v.name})]},v.id)}),ke(S),y.map(v=>Ce(v)),U.map(v=>{if(!y.find(b=>b.id===v.nodeId))return null;const F=xe(v.nodeId),x={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:F.x+x.x,y:F.y+x.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.jsxs("div",{style:{position:"absolute",top:8,left:8,fontSize:"0.75rem",color:"var(--nice-text-secondary, #666)"},children:[y.length," nodes โข ",N," leaves"]}),G&&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:G.name||G.id})}),G.branchLength!==void 0&&n.jsxs("div",{children:["Branch length: ",G.branchLength.toFixed(4)]}),G.bootstrap!==void 0&&n.jsxs("div",{children:["Bootstrap: ",G.bootstrap]}),G.children&&n.jsxs("div",{children:["Children: ",G.children.length]})]}),ae&&n.jsxs("div",{style:{position:"absolute",top:8,right:8,display:"flex",flexDirection:"column",gap:4},children:[n.jsxs("select",{value:te,onChange:v=>A(v.target.value),style:{padding:"2px 4px",fontSize:"0.75rem"},children:[n.jsx("option",{value:"rectangular",children:"Rectangular"}),n.jsx("option",{value:"radial",children:"Radial"}),n.jsx("option",{value:"diagonal",children:"Diagonal"})]}),n.jsx("button",{onClick:()=>{fe(1),V({x:0,y:0})},style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:"Reset View"}),n.jsx("button",{onClick:()=>d(new Set),style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:"Expand All"})]})]}):n.jsx("div",{className:`nice-phylogenetic-tree nice-phylogenetic-tree--empty ${X||""}`,style:{width:P,height:R,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--nice-bg-secondary, #f5f5f5)",color:"var(--nice-text-secondary, #666)",border:"1px dashed var(--nice-border, #ccc)",borderRadius:4,...oe},children:"Load a phylogenetic tree (Newick format)"})}const Se=e=>e*Math.PI/180;function Xt(e,t,r,s){const i=(t+180)/360*r,o=Se(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 Yt(e,t,r,s){const i=(t+180)/360*r,o=(90-e)/180*s;return{x:i,y:o}}function Pt(e,t,r,s,i,o){const a=Se(e),l=Se(t),c=Se(i),h=Se(o);if(Math.sin(c)*Math.sin(a)+Math.cos(c)*Math.cos(a)*Math.cos(l-h)<0)return{x:0,y:0,visible:!1};const f=Math.min(r,s)/2-10,m=r/2+f*Math.cos(a)*Math.sin(l-h),j=s/2-f*(Math.cos(c)*Math.sin(a)-Math.sin(c)*Math.cos(a)*Math.cos(l-h));return{x:m,y:j,visible:!0}}function qt(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 f=0;f<i.length-1;f++)if(o>=i[f][0]&&o<=i[f+1][0]){const m=(o-i[f][0])/5;a=i[f][1]+m*(i[f+1][1]-i[f][1]),l=i[f][2]+m*(i[f+1][2]-i[f][2]);break}const c=r/(2*Math.PI),h=r/2+c*Se(t)*a,p=s/2-c*l*1.3523*Math.sign(e);return{x:h,y:p}}const Vt=`
|
|
58
58
|
M 50,30 L 55,28 60,30 65,35 60,40 55,42 50,40 Z
|
|
59
59
|
M 70,25 L 80,23 85,28 87,35 85,45 78,50 72,48 68,40 70,32 Z
|
|
60
60
|
M 55,55 L 58,52 65,55 68,60 65,70 58,75 52,70 50,60 Z
|
|
61
61
|
M 80,55 L 90,50 92,60 88,70 80,75 75,65 Z
|
|
62
62
|
M 15,30 L 25,28 32,32 35,38 30,45 22,48 15,42 12,35 Z
|
|
63
63
|
M 30,55 L 35,50 40,52 42,58 38,65 32,68 28,62 Z
|
|
64
|
-
`;function Ut({projection:e="equirectangular",layers:t=[],markers:
|
|
65
|
-
A${x},${x} 0 1,1 ${
|
|
66
|
-
A${x},${x} 0 1,1 ${
|
|
67
|
-
c0,-${
|
|
68
|
-
a${
|
|
69
|
-
c0,${
|
|
64
|
+
`;function Ut({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:h=!0,graticuleInterval:p=30,showCoastlines:f=!0,showBorders:m=!1,landColor:j="#D4E6C3",oceanColor:M="#A8D4E6",borderColor:E="var(--nice-text-muted, #999999)",graticuleColor:U="var(--nice-border, #cccccc)",width:Q="100%",height:P=400,enablePan:R=!0,enableZoom:J=!0,showControls:ne=!0,scaleBar:q={show:!0,position:"bottom-left"},legend:ae,showLayerControl:de=!1,onMarkerClick:re,onMarkerHover:H,onMapClick:X,onPolygonClick:oe,onBoundsChange:le,className:pe,style:fe}){var ke,v,k,F;const T=u.useRef(null),[V,se]=u.useState(l),[Z,w]=u.useState(c),[K,G]=u.useState(!1),[ee,te]=u.useState(null),[A,C]=u.useState(null),[d,g]=u.useState(e),[S,I]=u.useState(new Set(t.filter(x=>x.visible!==!1).map(x=>x.id))),N=typeof Q=="number"?Q:800,L=typeof P=="number"?P:400,y=u.useCallback((x,b)=>{switch(d){case"mercator":return Xt(x,b,N,L);case"orthographic":return Pt(x,b,N,L,V.lat,V.lng);case"robinson":return qt(x,b,N,L);case"equirectangular":default:return Yt(x,b,N,L)}},[d,N,L,V]),$=u.useCallback((x,b)=>{const W=x/N*360-180,z=90-b/L*180;return{lat:Math.max(-90,Math.min(90,z)),lng:Math.max(-180,Math.min(180,W))}},[N,L]),D=u.useMemo(()=>{const x=[];for(let b=-90+p;b<90;b+=p){let W="";for(let z=-180;z<=180;z+=5){const B=y(b,z);B.visible!==!1&&(W+=W===""?`M${B.x},${B.y}`:` L${B.x},${B.y}`)}W&&x.push(W)}for(let b=-180;b<=180;b+=p){let W="";for(let z=-90;z<=90;z+=5){const B=y(z,b);B.visible!==!1&&(W+=W===""?`M${B.x},${B.y}`:` L${B.x},${B.y}`)}W&&x.push(W)}return x},[y,p]),_=u.useMemo(()=>{if(d==="orthographic"){const x=Math.min(N,L)/2-10;return`M${N/2+x},${L/2}
|
|
65
|
+
A${x},${x} 0 1,1 ${N/2-x},${L/2}
|
|
66
|
+
A${x},${x} 0 1,1 ${N/2+x},${L/2}`}return null},[d,N,L]),O=u.useMemo(()=>{const x=[...r];for(const b of t)S.has(b.id)&&b.markers&&x.push(...b.markers);return x},[r,t,S]),ie=u.useMemo(()=>{const x=[...s];for(const b of t)S.has(b.id)&&b.polylines&&x.push(...b.polylines);return x},[s,t,S]),ue=u.useMemo(()=>{const x=[...i];for(const b of t)S.has(b.id)&&b.polygons&&x.push(...b.polygons);return x},[i,t,S]),me=u.useCallback(x=>{R&&(G(!0),te({x:x.clientX,y:x.clientY,center:{...V}}))},[R,V]),xe=u.useCallback(x=>{if(!K||!ee)return;const b=x.clientX-ee.x,W=x.clientY-ee.y,z=-(b/N)*360/Z,B=W/L*180/Z;se({lat:Math.max(-85,Math.min(85,ee.center.lat+B)),lng:(ee.center.lng+z+180)%360-180})},[K,ee,N,L,Z]),he=u.useCallback(()=>{G(!1),te(null)},[]),ve=u.useCallback(x=>{if(!J)return;x.preventDefault();const b=x.deltaY>0?.9:1.1;w(W=>Math.max(.5,Math.min(20,W*b)))},[J]),je=u.useCallback(x=>{var B;if(!X)return;const b=(B=T.current)==null?void 0:B.getBoundingClientRect();if(!b)return;const W=x.clientX-b.left,z=x.clientY-b.top;X($(W,z))},[X,$]),Ee=x=>{const b=y(x.position.lat,x.position.lng);if(b.visible===!1)return null;const W=(A==null?void 0:A.id)===x.id,z=(x.size||8)*(W?1.3:1),B=(()=>{switch(x.shape){case"square":return n.jsx("rect",{x:b.x-z/2,y:b.y-z/2,width:z,height:z});case"triangle":return n.jsx("polygon",{points:`${b.x},${b.y-z} ${b.x-z},${b.y+z/2} ${b.x+z},${b.y+z/2}`});case"diamond":return n.jsx("polygon",{points:`${b.x},${b.y-z} ${b.x+z},${b.y} ${b.x},${b.y+z} ${b.x-z},${b.y}`});case"pin":return n.jsx("path",{d:`M${b.x},${b.y}
|
|
67
|
+
c0,-${z*1.5} -${z},-${z*2} -${z},-${z*2.5}
|
|
68
|
+
a${z},${z} 0 1,1 ${z*2},0
|
|
69
|
+
c0,${z*.5} -${z},${z} -${z},${z*2.5}`});case"circle":default:return n.jsx("circle",{cx:b.x,cy:b.y,r:z/2})}})();return n.jsxs("g",{fill:x.color||"var(--nice-accent-pink, #e91e63)",stroke:W?"var(--nice-text, #000)":"var(--nice-bg, #fff)",strokeWidth:W?2:1,style:{cursor:"pointer"},onMouseEnter:()=>{C(x),H==null||H(x)},onMouseLeave:()=>{C(null),H==null||H(null)},onClick:$e=>{$e.stopPropagation(),re==null||re(x)},children:[B,x.label&&n.jsx("text",{x:b.x+z,y:b.y,fontSize:10,fill:"var(--nice-text, #333)",dominantBaseline:"middle",children:x.label})]},x.id)},Fe=x=>{if(x.path.length<2)return null;const b=x.path.map((W,z)=>{const B=y(W.lat,W.lng);return B.visible===!1?"":z===0?`M${B.x},${B.y}`:`L${B.x},${B.y}`}).filter(Boolean).join(" ");return b?n.jsx("path",{d:b,fill:"none",stroke:x.color||"var(--nice-primary, #2196f3)",strokeWidth:x.width||2,strokeDasharray:x.style==="dashed"?"8,4":x.style==="dotted"?"2,2":void 0,markerEnd:x.arrows?"url(#arrow)":void 0},x.id):null},Be=x=>{if(x.path.length<3)return null;const b=x.path.map((W,z)=>{const B=y(W.lat,W.lng);return B.visible===!1?"":z===0?`M${B.x},${B.y}`:`L${B.x},${B.y}`}).filter(Boolean).join(" ")+" Z";return n.jsx("path",{d:b,fill:x.fillColor||"#4CAF5040",stroke:x.strokeColor||"var(--nice-success, #4caf50)",strokeWidth:x.strokeWidth||1,fillOpacity:x.fillOpacity||.5,style:{cursor:"pointer"},onClick:()=>oe==null?void 0:oe(x)},x.id)},Ce=u.useMemo(()=>{if(!q.show)return null;const x=111,b=N/360*Z,W=x/b,z=W*100,B=Math.pow(10,Math.floor(Math.log10(z))),$e=B*(z/B>=5?5:z/B>=2?2:1);return{width:$e/W,label:$e>=1e3?`${$e/1e3} km`:`${$e} km`}},[q.show,N,Z]);return n.jsxs("div",{ref:T,className:`nice-geographic-map ${pe||""}`,style:{width:Q,height:P,position:"relative",overflow:"hidden",background:M,border:"1px solid var(--nice-border, #ccc)",borderRadius:4,cursor:K?"grabbing":"grab",...fe},onMouseDown:me,onMouseMove:xe,onMouseUp:he,onMouseLeave:he,onWheel:ve,onClick:je,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)"})})}),d==="orthographic"&&_&&n.jsxs(n.Fragment,{children:[n.jsx("path",{d:_,fill:M,stroke:"var(--nice-text-muted, #999)",strokeWidth:1}),n.jsx("circle",{cx:N/2,cy:L/2,r:Math.min(N,L)/2-11,fill:j,opacity:.3})]}),h&&D.map((x,b)=>n.jsx("path",{d:x,fill:"none",stroke:U,strokeWidth:.5,strokeOpacity:.7},`graticule-${b}`)),f&&d!=="orthographic"&&n.jsx("g",{transform:`scale(${N/100}, ${L/100})`,children:n.jsx("path",{d:Vt,fill:j,stroke:E,strokeWidth:.2})}),ue.map(Be),ie.map(Fe),O.map(Ee)]}),Ce&&n.jsxs("div",{style:{position:"absolute",[(ke=q.position)!=null&&ke.includes("bottom")?"bottom":"top"]:8,[(v=q.position)!=null&&v.includes("right")?"right":"left"]:8,background:"var(--nice-overlay-light-90, rgba(255, 255, 255, 0.9))",padding:"4px 8px",borderRadius:4,fontSize:"0.7rem"},children:[n.jsx("div",{style:{width:Ce.width,height:4,background:"var(--nice-text, #333)",marginBottom:2}}),n.jsx("div",{children:Ce.label})]}),ae&&n.jsxs("div",{style:{position:"absolute",[(k=ae.position)!=null&&k.includes("bottom")?"bottom":"top"]:8,[(F=ae.position)!=null&&F.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:[ae.title&&n.jsx("div",{style:{fontWeight:"bold",marginBottom:4},children:ae.title}),ae.items.map((x,b)=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:2},children:[x.shape==="line"?n.jsx("div",{style:{width:16,height:2,background:x.color}}):n.jsx("div",{style:{width:12,height:12,background:x.color,borderRadius:x.shape==="circle"?"50%":0}}),n.jsx("span",{children:x.label})]},b))]}),(A==null?void 0:A.tooltip)&&n.jsx("div",{style:{position:"absolute",top:y(A.position.lat,A.position.lng).y-30,left:y(A.position.lat,A.position.lng).x,transform:"translateX(-50%)",background:"var(--nice-overlay-80, rgba(0, 0, 0, 0.8))",color:"var(--nice-bg, #fff)",padding:"4px 8px",borderRadius:4,fontSize:"0.75rem",pointerEvents:"none",whiteSpace:"nowrap"},children:A.tooltip}),n.jsxs("div",{style:{position:"absolute",bottom:8,right:8,background:"var(--nice-overlay-light-90, rgba(255, 255, 255, 0.9))",padding:"2px 6px",borderRadius:4,fontSize:"0.7rem",color:"var(--nice-text-secondary, #666)"},children:[V.lat.toFixed(2),"ยฐ, ",V.lng.toFixed(2),"ยฐ"]}),de&&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:"Layers"}),t.map(x=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:4,cursor:"pointer"},children:[n.jsx("input",{type:"checkbox",checked:S.has(x.id),onChange:b=>{const W=new Set(S);b.target.checked?W.add(x.id):W.delete(x.id),I(W)}}),x.name]},x.id))]}),ne&&n.jsxs("div",{style:{position:"absolute",top:8,right:8,display:"flex",flexDirection:"column",gap:4},children:[n.jsxs("select",{value:d,onChange:x=>g(x.target.value),style:{padding:"2px 4px",fontSize:"0.75rem"},children:[n.jsx("option",{value:"equirectangular",children:"Equirectangular"}),n.jsx("option",{value:"mercator",children:"Mercator"}),n.jsx("option",{value:"orthographic",children:"Orthographic"}),n.jsx("option",{value:"robinson",children:"Robinson"})]}),n.jsx("button",{onClick:()=>{w(1),se({lat:0,lng:0})},style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:"Reset View"})]})]})}exports.CitationService=Ke;exports.DataAnalysisService=Ve;exports.LabNotebookProvider=Pe;exports.LabNotebookService=Xe;exports.Nice3DPlot=Rt;exports.NiceCitation=Mt;exports.NiceDataAnalysis=ut;exports.NiceGeographicMap=Ut;exports.NiceLabNotebook=it;exports.NiceMolecularViewer=Wt;exports.NicePhylogeneticTree=Tt;exports.NiceScientificChart=It;exports.Stats=ge;exports.createCitationService=$t;exports.createDataAnalysisService=dt;exports.createLabNotebookService=st;exports.useCitation=Le;exports.useLabNotebook=Ie;
|