@nice2dev/ui-science 1.0.10
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 +50 -0
- package/dist/index.cjs +69 -0
- package/dist/index.d.ts +1461 -0
- package/dist/index.mjs +4820 -0
- package/package.json +70 -0
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @nice2dev/ui-science
|
|
2
|
+
|
|
3
|
+
Scientific visualization components for React.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **NiceScientificChart** — Advanced scientific charting with error bars, annotations
|
|
8
|
+
- **Nice3DPlot** — 3D surface plots, scatter plots, and vector fields
|
|
9
|
+
- **NiceMolecularViewer** — Molecular structure visualization (PDB, MOL2)
|
|
10
|
+
- **NicePhylogeneticTree** — Evolutionary tree visualization
|
|
11
|
+
- **NiceGeographicMap** — GeoJSON-based mapping with projections
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @nice2dev/ui-science
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { NiceScientificChart, Nice3DPlot, NiceMolecularViewer } from '@nice2dev/ui-science';
|
|
23
|
+
|
|
24
|
+
function App() {
|
|
25
|
+
return (
|
|
26
|
+
<div>
|
|
27
|
+
<NiceScientificChart
|
|
28
|
+
data={[
|
|
29
|
+
{ x: 1, y: 2.5, error: 0.3 },
|
|
30
|
+
{ x: 2, y: 4.1, error: 0.2 },
|
|
31
|
+
]}
|
|
32
|
+
showErrorBars
|
|
33
|
+
/>
|
|
34
|
+
|
|
35
|
+
<Nice3DPlot
|
|
36
|
+
type="surface"
|
|
37
|
+
data={(x, y) => Math.sin(x) * Math.cos(y)}
|
|
38
|
+
xRange={[-Math.PI, Math.PI]}
|
|
39
|
+
yRange={[-Math.PI, Math.PI]}
|
|
40
|
+
/>
|
|
41
|
+
|
|
42
|
+
<NiceMolecularViewer format="pdb" data={pdbContent} style="ball-and-stick" />
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";var nt=Object.defineProperty;var st=(e,t,s)=>t in e?nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var ye=(e,t,s)=>st(e,typeof t!="symbol"?t+"":t,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),u=require("react");class Ye{constructor(t){ye(this,"config");ye(this,"notebooks",new Map);this.config=t}async createNotebook(t){const s={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(s.id,s),s}async getNotebook(t){return this.notebooks.get(t)||null}async listNotebooks(){return Array.from(this.notebooks.values())}async createEntry(t,s){const i=this.notebooks.get(t);if(!i)throw new Error(`Notebook not found: ${t}`);const r={id:this.generateId(),notebookId:t,type:s.type||i.settings.defaultEntryType,status:"draft",title:s.title||"Untitled Entry",objective:s.objective,hypothesis:s.hypothesis,methods:s.methods,results:s.results,conclusions:s.conclusions,sections:s.sections||[],attachments:[],tags:s.tags||[],linkedEntries:s.linkedEntries||[],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),createdBy:"current-user",lastModifiedBy:"current-user",version:1,signatures:[],comments:[]};return i.entries.push(r),i.updatedAt=new Date().toISOString(),r}async updateEntry(t,s,i){const r=this.notebooks.get(t);if(!r)throw new Error(`Notebook not found: ${t}`);const o=r.entries.findIndex(c=>c.id===s);if(o===-1)throw new Error(`Entry not found: ${s}`);const a=r.entries[o];if(a.status==="locked")throw new Error("Cannot modify locked entry");const l={...a,...i,id:a.id,notebookId:t,updatedAt:new Date().toISOString(),lastModifiedBy:"current-user",version:a.version+1};return r.entries[o]=l,r.updatedAt=new Date().toISOString(),l}async signEntry(t,s,i){const r=this.notebooks.get(t);if(!r)throw new Error(`Notebook not found: ${t}`);const o=r.entries.find(l=>l.id===s);if(!o)throw new Error(`Entry not found: ${s}`);const a={...i,signedAt:new Date().toISOString(),signatureHash:this.generateSignatureHash(o,i.userId)};return o.signatures.push(a),r.settings.autoLockAfterSign&&i.role==="author"&&(o.status="signed"),o.updatedAt=new Date().toISOString(),o}async addAttachment(t,s,i){const r=this.notebooks.get(t);if(!r)throw new Error(`Notebook not found: ${t}`);const o=r.entries.find(l=>l.id===s);if(!o)throw new Error(`Entry not found: ${s}`);const a={id:this.generateId(),name:i.name,type:i.type,size:i.size,url:URL.createObjectURL(i),uploadedAt:new Date().toISOString(),uploadedBy:"current-user"};return o.attachments.push(a),o.updatedAt=new Date().toISOString(),a}async searchEntries(t,s){var o,a,l,c,h,p;const i=[],r=t.toLowerCase();for(const f of this.notebooks.values())if(!(s!=null&&s.notebookId&&f.id!==s.notebookId))for(const m of f.entries)s!=null&&s.type&&m.type!==s.type||s!=null&&s.status&&m.status!==s.status||(o=s==null?void 0:s.tags)!=null&&o.length&&!s.tags.some(v=>m.tags.includes(v))||s!=null&&s.dateFrom&&m.createdAt<s.dateFrom||s!=null&&s.dateTo&&m.createdAt>s.dateTo||(m.title.toLowerCase().includes(r)||(a=m.objective)!=null&&a.toLowerCase().includes(r)||(l=m.hypothesis)!=null&&l.toLowerCase().includes(r)||(c=m.methods)!=null&&c.toLowerCase().includes(r)||(h=m.results)!=null&&h.toLowerCase().includes(r)||(p=m.conclusions)!=null&&p.toLowerCase().includes(r))&&i.push(m);return i}async exportEntry(t,s,i){const r=this.notebooks.get(t);if(!r)throw new Error(`Notebook not found: ${t}`);const o=r.entries.find(l=>l.id===s);if(!o)throw new Error(`Entry not found: ${s}`);const a=this.generateEntryHTML(o,r);return i==="html"?new Blob([a],{type:"text/html"}):new Blob([a],{type:"text/html"})}generateEntryHTML(t,s){return`
|
|
2
|
+
<!DOCTYPE html>
|
|
3
|
+
<html>
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>${t.title}</title>
|
|
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; }
|
|
13
|
+
</style>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<h1>${t.title}</h1>
|
|
17
|
+
<div class="meta">
|
|
18
|
+
<p>Notebook: ${s.name}</p>
|
|
19
|
+
<p>Entry ID: ${t.id}</p>
|
|
20
|
+
<p>Type: ${t.type}</p>
|
|
21
|
+
<p>Created: ${new Date(t.createdAt).toLocaleString()}</p>
|
|
22
|
+
<p>Version: ${t.version}</p>
|
|
23
|
+
</div>
|
|
24
|
+
${t.objective?`<div class="section"><h2>Objective</h2><p>${t.objective}</p></div>`:""}
|
|
25
|
+
${t.hypothesis?`<div class="section"><h2>Hypothesis</h2><p>${t.hypothesis}</p></div>`:""}
|
|
26
|
+
${t.methods?`<div class="section"><h2>Methods</h2><p>${t.methods}</p></div>`:""}
|
|
27
|
+
${t.results?`<div class="section"><h2>Results</h2><p>${t.results}</p></div>`:""}
|
|
28
|
+
${t.conclusions?`<div class="section"><h2>Conclusions</h2><p>${t.conclusions}</p></div>`:""}
|
|
29
|
+
${t.signatures.length>0?`
|
|
30
|
+
<div class="signatures">
|
|
31
|
+
<h2>Signatures</h2>
|
|
32
|
+
${t.signatures.map(i=>`
|
|
33
|
+
<p><strong>${i.userName}</strong> (${i.role}) - ${new Date(i.signedAt).toLocaleString()}</p>
|
|
34
|
+
`).join("")}
|
|
35
|
+
</div>
|
|
36
|
+
`:""}
|
|
37
|
+
</body>
|
|
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 v=[];let M="",I=!1;for(const U of m)U==='"'?I=!I:U===i&&!I?(v.push(M.trim()),M=""):M+=U;return v.push(M.trim()),v},l=a(o[0]),c=r?l:l.map((m,v)=>`col_${v+1}`),h=r?1:0,p=[];for(let m=h;m<o.length;m++){const v=a(o[m]),M={};for(let I=0;I<c.length;I++){const U=v[I],Q=parseFloat(U);M[c[I]]=!isNaN(Q)&&U!==""?Q:U}p.push(M)}return this.createDataset({name:(s==null?void 0:s.name)||"Imported CSV",data:p,source:{type:"csv"}})}async importJSON(t,s){const i=typeof t=="string"?JSON.parse(t):t;if(!Array.isArray(i))throw new Error("JSON must be an array of objects");return this.createDataset({name:(s==null?void 0:s.name)||"Imported JSON",data:i,source:{type:"json"}})}createDataset(t){const{name:s,data:i,description:r,source:o}=t,a=this.inferColumns(i),l={id:this.generateId(),name:s,description:r,columns:a,data:i,rowCount:i.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 s=new Set;t.forEach(r=>Object.keys(r).forEach(o=>s.add(o)));const i=[];for(const r of s){const o=t.map(p=>p[r]),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:r,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)}i.push(h)}return i}runAnalysis(t,s,i={}){const r=this.datasets.get(t);if(!r)throw new Error(`Dataset not found: ${t}`);const o=performance.now();let a;switch(s){case"descriptive":a=this.descriptiveAnalysis(r,i);break;case"correlation":a=this.correlationAnalysis(r,i);break;case"regression":a=this.regressionAnalysis(r,i);break;case"ttest":a=this.tTestAnalysis(r,i);break;case"distribution":a=this.distributionAnalysis(r,i);break;default:throw new Error(`Unsupported analysis type: ${s}`)}const l=performance.now()-o,c={id:this.generateId(),datasetId:t,type:s,parameters:i,result:a,createdAt:new Date().toISOString(),executionTimeMs:l};return this.analyses.set(c.id,c),c}descriptiveAnalysis(t,s){const i=s.columns||t.columns.filter(o=>o.type==="number").map(o=>o.name),r={};for(const o of i){const a=t.data.map(l=>l[o]).filter(l=>typeof l=="number");r[o]=ge.describe(a)}return r}correlationAnalysis(t,s){const i=s.columns||t.columns.filter(o=>o.type==="number").map(o=>o.name),r={};for(const o of i)r[o]=t.data.map(a=>a[o]).filter(a=>typeof a=="number");return{matrix:ge.correlationMatrix(r),columns:i}}regressionAnalysis(t,s){const{xColumn:i,yColumn:r}=s,o=t.data.map(l=>l[i]).filter(l=>typeof l=="number"),a=t.data.map(l=>l[r]).filter(l=>typeof l=="number");return ge.linearRegression(o,a)}tTestAnalysis(t,s){const{column:i,groupColumn:r}=s,o=new Map;for(const l of t.data){const c=l[r],h=l[i];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,s){const{column:i,bins:r=10}=s,o=t.data.map(f=>f[i]).filter(f=>typeof f=="number"),a=Math.min(...o),c=(Math.max(...o)-a)/r,h=new Array(r).fill(0),p=[];for(let f=0;f<=r;f++)p.push(a+f*c);for(const f of o){const m=Math.min(Math.floor((f-a)/c),r-1);h[m]++}return{histogram:h,binEdges:p,stats:ge.describe(o)}}transform(t,s){const i=this.datasets.get(t);if(!i)throw new Error(`Dataset not found: ${t}`);let r=[...i.data];switch(s.type){case"filter":r=this.applyFilter(r,s);break;case"sort":r=this.applySort(r,s);break;case"fillna":r=this.applyFillNA(r,s);break;case"dropna":r=this.applyDropNA(r,s);break;case"normalize":r=this.applyNormalize(r,s);break;case"standardize":r=this.applyStandardize(r,s);break;default:throw new Error(`Unsupported transformation: ${s.type}`)}return this.createDataset({name:`${i.name} (transformed)`,data:r})}applyFilter(t,s){const{column:i,parameters:r}=s,{operator:o,value:a}=r;return t.filter(l=>{const c=l[i];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,s){const{column:i,parameters:r}=s,o=r.ascending!==!1;return[...t].sort((a,l)=>{const c=a[i],h=l[i];return c<h?o?-1:1:c>h?o?1:-1:0})}applyFillNA(t,s){const{column:i,parameters:r}=s,o=r.value;return t.map(a=>({...a,[i]:a[i]??o}))}applyDropNA(t,s){const i=s.columns||[s.column];return t.filter(r=>i.every(o=>r[o]!=null))}applyNormalize(t,s){const{column:i}=s,r=t.map(c=>c[i]).filter(c=>typeof c=="number"),o=Math.min(...r),l=Math.max(...r)-o;return t.map(c=>({...c,[i]:typeof c[i]=="number"?(c[i]-o)/l:c[i]}))}applyStandardize(t,s){const{column:i}=s,r=t.map(l=>l[i]).filter(l=>typeof l=="number"),o=ge.mean(r),a=ge.std(r);return t.map(l=>({...l,[i]:typeof l[i]=="number"?(l[i]-o)/a:l[i]}))}exportCSV(t){const s=this.datasets.get(t);if(!s)throw new Error(`Dataset not found: ${t}`);const i=s.columns.map(o=>o.name),r=s.data.map(o=>i.map(a=>{const l=o[a];return l==null?"":typeof l=="string"&&(l.includes(",")||l.includes('"'))?`"${l.replace(/"/g,'""')}"`:String(l)}).join(","));return[i.join(","),...r].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:s}){const[i,r]=u.useState([]),[o,a]=u.useState(null),[l,c]=u.useState("data"),h=u.useCallback(()=>{r(e.listDatasets())},[e]),p=u.useMemo(()=>i.find(m=>m.id===o),[i,o]),f=async m=>{var I;const v=(I=m.target.files)==null?void 0:I[0];if(!v)return;const M=await v.text();v.name.endsWith(".csv")?await e.importCSV(M,{name:v.name}):v.name.endsWith(".json")&&await e.importJSON(M,{name:v.name}),h()};return n.jsxs("div",{className:t,style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:"'Inter', sans-serif",...s},children:[n.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid #e0e0e0",display:"flex",gap:"12px",alignItems:"center"},children:[n.jsxs("label",{style:{padding:"8px 16px",backgroundColor:"#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 #ddd"},children:[n.jsx("option",{value:"",children:"Select dataset..."}),i.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?"#1976d2":"transparent",color:l===m?"white":"#333",border:"1px solid #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:"#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,s]=u.useState(0),i=50,r=Math.ceil(e.rowCount/i),o=e.data.slice(t*i,(t+1)*i);return n.jsxs("div",{children:[n.jsx("div",{style:{overflowX:"auto",marginBottom:"16px"},children:n.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{backgroundColor:"#f5f5f5"},children:[n.jsx("th",{style:{padding:"8px 12px",border:"1px solid #ddd",textAlign:"left"},children:"#"}),e.columns.map(a=>n.jsxs("th",{style:{padding:"8px 12px",border:"1px solid #ddd",textAlign:"left"},children:[a.name,n.jsx("div",{style:{fontSize:"10px",color:"#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 #ddd",color:"#666"},children:t*i+l+1}),e.columns.map(c=>n.jsx("td",{style:{padding:"8px 12px",border:"1px solid #ddd"},children:a[c.name]!=null?String(a[c.name]):n.jsx("span",{style:{color:"#ccc"},children:"null"})},c.name))]},l))})]})}),n.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center",justifyContent:"center"},children:[n.jsx("button",{onClick:()=>s(0),disabled:t===0,children:"First"}),n.jsx("button",{onClick:()=>s(t-1),disabled:t===0,children:"Prev"}),n.jsxs("span",{children:["Page ",t+1," of ",r]}),n.jsx("button",{onClick:()=>s(t+1),disabled:t>=r-1,children:"Next"}),n.jsx("button",{onClick:()=>s(r-1),disabled:t>=r-1,children:"Last"})]})]})}function pt({dataset:e}){const t=e.columns.filter(s=>s.type==="number");return n.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(300px, 1fr))",gap:"16px"},children:t.map(s=>n.jsxs("div",{style:{padding:"16px",backgroundColor:"#f9f9f9",borderRadius:"8px"},children:[n.jsx("h3",{style:{margin:"0 0 12px 0"},children:s.name}),s.stats&&n.jsx("table",{style:{width:"100%",fontSize:"13px"},children:n.jsx("tbody",{children:Object.entries(s.stats).map(([i,r])=>n.jsxs("tr",{children:[n.jsx("td",{style:{padding:"4px 0",color:"#666"},children:i}),n.jsx("td",{style:{padding:"4px 0",textAlign:"right",fontFamily:"monospace"},children:typeof r=="number"?r.toFixed(4):String(r)})]},i))})})]},s.name))})}function xt({dataset:e,service:t}){const[s,i]=u.useState("descriptive"),[r,o]=u.useState(null),a=()=>{const l=t.runAnalysis(e.id,s,{});o(l)};return n.jsxs("div",{children:[n.jsxs("div",{style:{display:"flex",gap:"12px",marginBottom:"24px"},children:[n.jsxs("select",{value:s,onChange:l=>i(l.target.value),style:{padding:"8px 12px",borderRadius:"4px",border:"1px solid #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:"#1976d2",color:"white",border:"none",borderRadius:"4px",cursor:"pointer"},children:"Run Analysis"})]}),r&&n.jsxs("div",{style:{padding:"16px",backgroundColor:"#f9f9f9",borderRadius:"8px"},children:[n.jsxs("h3",{style:{margin:"0 0 12px 0"},children:["Results (",r.executionTimeMs.toFixed(2),"ms)"]}),n.jsx("pre",{style:{margin:0,overflow:"auto",fontSize:"12px"},children:JSON.stringify(r.result,null,2)})]})]})}const Be={apa:e=>{const t=ft(e.authors),s=e.year?` (${e.year}).`:".",i=e.title;let r="";e.type==="article"&&e.journal?(r=` *${e.journal}*`,e.volume&&(r+=`, *${e.volume}*`),e.issue&&(r+=`(${e.issue})`),e.pages&&(r+=`, ${e.pages}`),r+="."):e.type==="book"&&(r=e.publisher?` ${e.publisher}.`:"");const o=e.doi?` https://doi.org/${e.doi}`:"";return`${t}${s} ${i}.${r}${o}`},mla:e=>{const t=Ue(e.authors),s=`"${e.title}."`;let i="";return e.type==="article"&&e.journal&&(i=` *${e.journal}*`,e.volume&&(i+=`, vol. ${e.volume}`),e.issue&&(i+=`, no. ${e.issue}`),e.year&&(i+=`, ${e.year}`),e.pages&&(i+=`, pp. ${e.pages}`),i+="."),`${t} ${s}${i}`},chicago:e=>{const t=mt(e.authors),s=`"${e.title}."`;let i="";return e.type==="article"&&e.journal&&(i=` *${e.journal}*`,e.volume&&(i+=` ${e.volume}`),e.issue&&(i+=`, no. ${e.issue}`),e.year&&(i+=` (${e.year})`),e.pages&&(i+=`: ${e.pages}`),i+="."),`${t} ${s}${i}`},harvard:e=>{const t=yt(e.authors),s=e.year?` (${e.year})`:"",i=`'${e.title}'`;let r="";return e.type==="article"&&e.journal&&(r=`, *${e.journal}*`,e.volume&&(r+=`, ${e.volume}`),e.issue&&(r+=`(${e.issue})`),e.pages&&(r+=`, pp. ${e.pages}`),r+="."),`${t}${s} ${i}${r}`},ieee:e=>{const t=gt(e.authors),s=`"${e.title},"`;let i="";return e.type==="article"&&e.journal&&(i=` *${e.journal}*`,e.volume&&(i+=`, vol. ${e.volume}`),e.issue&&(i+=`, no. ${e.issue}`),e.pages&&(i+=`, pp. ${e.pages}`),e.year&&(i+=`, ${e.year}`),i+="."),`${t} ${s}${i}`},vancouver:e=>{const t=bt(e.authors),s=e.title;let i="";return e.type==="article"&&e.journal&&(i=` ${e.journal}`,e.year&&(i+=`. ${e.year}`),e.volume&&(i+=`;${e.volume}`),e.issue&&(i+=`(${e.issue})`),e.pages&&(i+=`:${e.pages}`),i+="."),`${t}. ${s}.${i}`},nature:e=>{const t=Ze(e.authors),s=e.title;let i="";return e.type==="article"&&e.journal&&(i=` *${e.journal}*`,e.volume&&(i+=` **${e.volume}**`),e.pages&&(i+=`, ${e.pages}`),e.year&&(i+=` (${e.year})`),i+="."),`${t} ${s}.${i}`},science:e=>{const t=jt(e.authors),s=e.title;let i="";return e.type==="article"&&e.journal&&(i=` *${e.journal}*`,e.volume&&(i+=` **${e.volume}**`),e.pages&&(i+=`, ${e.pages}`),e.year&&(i+=` (${e.year})`),i+="."),`${t}, ${s}.${i}`},bibtex:e=>{const t=vt(e),s=e.type==="article"?"article":e.type==="book"?"book":"misc";let r=` author = {${e.authors.map(o=>`${o.family}, ${o.given}`).join(" and ")}},
|
|
42
|
+
`;return r+=` title = {${e.title}},
|
|
43
|
+
`,e.year&&(r+=` year = {${e.year}},
|
|
44
|
+
`),e.journal&&(r+=` journal = {${e.journal}},
|
|
45
|
+
`),e.volume&&(r+=` volume = {${e.volume}},
|
|
46
|
+
`),e.issue&&(r+=` number = {${e.issue}},
|
|
47
|
+
`),e.pages&&(r+=` pages = {${e.pages}},
|
|
48
|
+
`),e.publisher&&(r+=` publisher = {${e.publisher}},
|
|
49
|
+
`),e.doi&&(r+=` doi = {${e.doi}},
|
|
50
|
+
`),e.isbn&&(r+=` isbn = {${e.isbn}},
|
|
51
|
+
`),`@${s}{${t},
|
|
52
|
+
${r}}`}};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 i=e.slice(0,-1).map(o=>`${o.family}, ${o.given.charAt(0)}.`).join(", "),r=e[e.length-1];return`${i}, & ${r.family}, ${r.given.charAt(0)}.`}const t=e.slice(0,6).map(i=>`${i.family}, ${i.given.charAt(0)}.`).join(", "),s=e[e.length-1];return`${t}, ... ${s.family}, ${s.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(s=>`${s.family} ${s.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(i=>`${i.family}, ${i.given.charAt(0)}.`),s=t.pop();return t.length>0?`${t.join(", ")} & ${s}`:s}return`${e[0].family}, ${e[0].given.charAt(0)}. et al.`}function jt(e){return Ze(e)}function vt(e){var r;const t=((r=e.authors[0])==null?void 0:r.family.toLowerCase())||"unknown",s=e.year||"0000",i=e.title.split(" ")[0].toLowerCase().replace(/[^a-z]/g,"");return`${t}${s}${i}`}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 s={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(s.id,s),this.updateCollectionCounts(),s}updateCitation(t,s){const i=this.citations.get(t);if(!i)throw new Error(`Citation not found: ${t}`);const r={...i,...s,id:i.id,createdAt:i.createdAt,updatedAt:new Date().toISOString()};return this.citations.set(t,r),this.updateCollectionCounts(),r}deleteCitation(t){this.citations.delete(t),this.updateCollectionCounts()}getCitation(t){return this.citations.get(t)}searchCitations(t,s){const i=t.toLowerCase();return Array.from(this.citations.values()).filter(r=>{var o,a,l,c,h;return s!=null&&s.collection&&!((o=r.collections)!=null&&o.includes(s.collection))||s!=null&&s.type&&r.type!==s.type||s!=null&&s.year&&r.year!==s.year||(a=s==null?void 0:s.tags)!=null&&a.length&&!s.tags.some(p=>{var f;return(f=r.tags)==null?void 0:f.includes(p)})?!1:!!(r.title.toLowerCase().includes(i)||r.authors.some(p=>p.family.toLowerCase().includes(i)||p.given.toLowerCase().includes(i))||(l=r.journal)!=null&&l.toLowerCase().includes(i)||(c=r.abstract)!=null&&c.toLowerCase().includes(i)||(h=r.doi)!=null&&h.toLowerCase().includes(i))})}listCitations(t){const s=Array.from(this.citations.values());return t&&t!=="all"?s.filter(i=>{var r;return(r=i.collections)==null?void 0:r.includes(t)}):s}createCollection(t){const s={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(s.id,s),s}listCollections(){return Array.from(this.collections.values())}formatCitation(t,s){const i=this.citations.get(t);if(!i)throw new Error(`Citation not found: ${t}`);return Be[s](i)}formatBibliography(t,s){return t.map((r,o)=>{const a=this.citations.get(r);if(!a)return null;const l=Be[s](a);return s==="bibtex"?l:["ieee","vancouver"].includes(s)?`[${o+1}] ${l}`:l}).filter(Boolean).join(`
|
|
53
|
+
|
|
54
|
+
`)}importBibtex(t){const s=[],i=/@(\w+)\{([^,]+),([^@]+)\}/g;let r;for(;(r=i.exec(t))!==null;){const o=r[1].toLowerCase(),a=this.parseBibtexFields(r[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});s.push(l)}return s}parseBibtexFields(t){const s={},i=/(\w+)\s*=\s*\{([^}]*)\}/g;let r;for(;(r=i.exec(t))!==null;)s[r[1].toLowerCase()]=r[2].trim();return s}parseBibtexAuthors(t){return t.split(" and ").map(s=>{const i=s.trim().split(",");if(i.length>=2)return{family:i[0].trim(),given:i[1].trim()};const r=s.trim().split(" ");return{given:r.slice(0,-1).join(" "),family:r[r.length-1]}})}exportBibtex(t){return(t?t.map(i=>this.citations.get(i)).filter(Boolean):Array.from(this.citations.values())).map(i=>Be.bibtex(i)).join(`
|
|
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=`
|
|
58
|
+
M 50,30 L 55,28 60,30 65,35 60,40 55,42 50,40 Z
|
|
59
|
+
M 70,25 L 80,23 85,28 87,35 85,45 78,50 72,48 68,40 70,32 Z
|
|
60
|
+
M 55,55 L 58,52 65,55 68,60 65,70 58,75 52,70 50,60 Z
|
|
61
|
+
M 80,55 L 90,50 92,60 88,70 80,75 75,65 Z
|
|
62
|
+
M 15,30 L 25,28 32,32 35,38 30,45 22,48 15,42 12,35 Z
|
|
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:s=[],polylines:i=[],polygons:r=[],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:v="#D4E6C3",oceanColor:M="#A8D4E6",borderColor:I="#999999",graticuleColor:U="#CCCCCC",width:Q="100%",height:P=400,enablePan:B=!0,enableZoom:J=!0,showControls:ne=!0,scaleBar:q={show:!0,position:"bottom-left"},legend:ae,showLayerControl:de=!1,onMarkerClick:se,onMarkerHover:H,onMapClick:Y,onPolygonClick:oe,onBoundsChange:le,className:pe,style:fe}){var ke,j,k,E;const X=u.useRef(null),[V,ie]=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,N]=u.useState(new Set(t.filter(x=>x.visible!==!1).map(x=>x.id))),z=typeof Q=="number"?Q:800,L=typeof P=="number"?P:400,y=u.useCallback((x,b)=>{switch(d){case"mercator":return Yt(x,b,z,L);case"orthographic":return Pt(x,b,z,L,V.lat,V.lng);case"robinson":return qt(x,b,z,L);case"equirectangular":default:return _t(x,b,z,L)}},[d,z,L,V]),$=u.useCallback((x,b)=>{const O=x/z*360-180,F=90-b/L*180;return{lat:Math.max(-90,Math.min(90,F)),lng:Math.max(-180,Math.min(180,O))}},[z,L]),D=u.useMemo(()=>{const x=[];for(let b=-90+p;b<90;b+=p){let O="";for(let F=-180;F<=180;F+=5){const R=y(b,F);R.visible!==!1&&(O+=O===""?`M${R.x},${R.y}`:` L${R.x},${R.y}`)}O&&x.push(O)}for(let b=-180;b<=180;b+=p){let O="";for(let F=-90;F<=90;F+=5){const R=y(F,b);R.visible!==!1&&(O+=O===""?`M${R.x},${R.y}`:` L${R.x},${R.y}`)}O&&x.push(O)}return x},[y,p]),W=u.useMemo(()=>{if(d==="orthographic"){const x=Math.min(z,L)/2-10;return`M${z/2+x},${L/2}
|
|
65
|
+
A${x},${x} 0 1,1 ${z/2-x},${L/2}
|
|
66
|
+
A${x},${x} 0 1,1 ${z/2+x},${L/2}`}return null},[d,z,L]),T=u.useMemo(()=>{const x=[...s];for(const b of t)S.has(b.id)&&b.markers&&x.push(...b.markers);return x},[s,t,S]),re=u.useMemo(()=>{const x=[...i];for(const b of t)S.has(b.id)&&b.polylines&&x.push(...b.polylines);return x},[i,t,S]),ue=u.useMemo(()=>{const x=[...r];for(const b of t)S.has(b.id)&&b.polygons&&x.push(...b.polygons);return x},[r,t,S]),me=u.useCallback(x=>{B&&(G(!0),te({x:x.clientX,y:x.clientY,center:{...V}}))},[B,V]),xe=u.useCallback(x=>{if(!K||!ee)return;const b=x.clientX-ee.x,O=x.clientY-ee.y,F=-(b/z)*360/Z,R=O/L*180/Z;ie({lat:Math.max(-85,Math.min(85,ee.center.lat+R)),lng:(ee.center.lng+F+180)%360-180})},[K,ee,z,L,Z]),he=u.useCallback(()=>{G(!1),te(null)},[]),je=u.useCallback(x=>{if(!J)return;x.preventDefault();const b=x.deltaY>0?.9:1.1;w(O=>Math.max(.5,Math.min(20,O*b)))},[J]),ve=u.useCallback(x=>{var R;if(!Y)return;const b=(R=X.current)==null?void 0:R.getBoundingClientRect();if(!b)return;const O=x.clientX-b.left,F=x.clientY-b.top;Y($(O,F))},[Y,$]),Ie=x=>{const b=y(x.position.lat,x.position.lng);if(b.visible===!1)return null;const O=(A==null?void 0:A.id)===x.id,F=(x.size||8)*(O?1.3:1),R=(()=>{switch(x.shape){case"square":return n.jsx("rect",{x:b.x-F/2,y:b.y-F/2,width:F,height:F});case"triangle":return n.jsx("polygon",{points:`${b.x},${b.y-F} ${b.x-F},${b.y+F/2} ${b.x+F},${b.y+F/2}`});case"diamond":return n.jsx("polygon",{points:`${b.x},${b.y-F} ${b.x+F},${b.y} ${b.x},${b.y+F} ${b.x-F},${b.y}`});case"pin":return n.jsx("path",{d:`M${b.x},${b.y}
|
|
67
|
+
c0,-${F*1.5} -${F},-${F*2} -${F},-${F*2.5}
|
|
68
|
+
a${F},${F} 0 1,1 ${F*2},0
|
|
69
|
+
c0,${F*.5} -${F},${F} -${F},${F*2.5}`});case"circle":default:return n.jsx("circle",{cx:b.x,cy:b.y,r:F/2})}})();return n.jsxs("g",{fill:x.color||"#E91E63",stroke:O?"#000":"#FFF",strokeWidth:O?2:1,style:{cursor:"pointer"},onMouseEnter:()=>{C(x),H==null||H(x)},onMouseLeave:()=>{C(null),H==null||H(null)},onClick:$e=>{$e.stopPropagation(),se==null||se(x)},children:[R,x.label&&n.jsx("text",{x:b.x+F,y:b.y,fontSize:10,fill:"#333",dominantBaseline:"middle",children:x.label})]},x.id)},Ee=x=>{if(x.path.length<2)return null;const b=x.path.map((O,F)=>{const R=y(O.lat,O.lng);return R.visible===!1?"":F===0?`M${R.x},${R.y}`:`L${R.x},${R.y}`}).filter(Boolean).join(" ");return b?n.jsx("path",{d:b,fill:"none",stroke:x.color||"#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},Re=x=>{if(x.path.length<3)return null;const b=x.path.map((O,F)=>{const R=y(O.lat,O.lng);return R.visible===!1?"":F===0?`M${R.x},${R.y}`:`L${R.x},${R.y}`}).filter(Boolean).join(" ")+" Z";return n.jsx("path",{d:b,fill:x.fillColor||"#4CAF5040",stroke:x.strokeColor||"#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=z/360*Z,O=x/b,F=O*100,R=Math.pow(10,Math.floor(Math.log10(F))),$e=R*(F/R>=5?5:F/R>=2?2:1);return{width:$e/O,label:$e>=1e3?`${$e/1e3} km`:`${$e} km`}},[q.show,z,Z]);return n.jsxs("div",{ref:X,className:`nice-geographic-map ${pe||""}`,style:{width:Q,height:P,position:"relative",overflow:"hidden",background:M,border:"1px solid #CCC",borderRadius:4,cursor:K?"grabbing":"grab",...fe},onMouseDown:me,onMouseMove:xe,onMouseUp:he,onMouseLeave:he,onWheel:je,onClick:ve,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:"#2196F3"})})}),d==="orthographic"&&W&&n.jsxs(n.Fragment,{children:[n.jsx("path",{d:W,fill:M,stroke:"#999",strokeWidth:1}),n.jsx("circle",{cx:z/2,cy:L/2,r:Math.min(z,L)/2-11,fill:v,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(${z/100}, ${L/100})`,children:n.jsx("path",{d:Vt,fill:v,stroke:I,strokeWidth:.2})}),ue.map(Re),re.map(Ee),T.map(Ie)]}),Ce&&n.jsxs("div",{style:{position:"absolute",[(ke=q.position)!=null&&ke.includes("bottom")?"bottom":"top"]:8,[(j=q.position)!=null&&j.includes("right")?"right":"left"]:8,background:"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:"#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,[(E=ae.position)!=null&&E.includes("left")?"left":"right"]:8,background:"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:"rgba(0,0,0,0.8)",color:"#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:"rgba(255,255,255,0.9)",padding:"2px 6px",borderRadius:4,fontSize:"0.7rem",color:"#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:"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 O=new Set(S);b.target.checked?O.add(x.id):O.delete(x.id),N(O)}}),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),ie({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=Ye;exports.Nice3DPlot=Bt;exports.NiceCitation=Mt;exports.NiceDataAnalysis=ut;exports.NiceGeographicMap=Ut;exports.NiceLabNotebook=rt;exports.NiceMolecularViewer=Ot;exports.NicePhylogeneticTree=Xt;exports.NiceScientificChart=Nt;exports.Stats=ge;exports.createCitationService=$t;exports.createDataAnalysisService=dt;exports.createLabNotebookService=it;exports.useCitation=Le;exports.useLabNotebook=Ne;
|