@nice2dev/ui-science 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var nt=Object.defineProperty;var rt=(e,t,r)=>t in e?nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var ye=(e,t,r)=>rt(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),u=require("react");class Xe{constructor(t){ye(this,"config");ye(this,"notebooks",new Map);this.config=t}async createNotebook(t){const r={id:this.generateId(),name:t.name||"Untitled Notebook",description:t.description,project:t.project,owner:t.owner||"current-user",collaborators:t.collaborators||[],entries:[],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),isArchived:!1,settings:t.settings||{requireSignatures:!0,requireWitness:!1,autoLockAfterSign:!0,defaultEntryType:"experiment",customFields:[],templates:[]}};return this.notebooks.set(r.id,r),r}async getNotebook(t){return this.notebooks.get(t)||null}async listNotebooks(){return Array.from(this.notebooks.values())}async createEntry(t,r){const s=this.notebooks.get(t);if(!s)throw new Error(`Notebook not found: ${t}`);const i={id:this.generateId(),notebookId:t,type:r.type||s.settings.defaultEntryType,status:"draft",title:r.title||"Untitled Entry",objective:r.objective,hypothesis:r.hypothesis,methods:r.methods,results:r.results,conclusions:r.conclusions,sections:r.sections||[],attachments:[],tags:r.tags||[],linkedEntries:r.linkedEntries||[],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),createdBy:"current-user",lastModifiedBy:"current-user",version:1,signatures:[],comments:[]};return s.entries.push(i),s.updatedAt=new Date().toISOString(),i}async updateEntry(t,r,s){const i=this.notebooks.get(t);if(!i)throw new Error(`Notebook not found: ${t}`);const o=i.entries.findIndex(c=>c.id===r);if(o===-1)throw new Error(`Entry not found: ${r}`);const a=i.entries[o];if(a.status==="locked")throw new Error("Cannot modify locked entry");const l={...a,...s,id:a.id,notebookId:t,updatedAt:new Date().toISOString(),lastModifiedBy:"current-user",version:a.version+1};return i.entries[o]=l,i.updatedAt=new Date().toISOString(),l}async signEntry(t,r,s){const i=this.notebooks.get(t);if(!i)throw new Error(`Notebook not found: ${t}`);const o=i.entries.find(l=>l.id===r);if(!o)throw new Error(`Entry not found: ${r}`);const a={...s,signedAt:new Date().toISOString(),signatureHash:this.generateSignatureHash(o,s.userId)};return o.signatures.push(a),i.settings.autoLockAfterSign&&s.role==="author"&&(o.status="signed"),o.updatedAt=new Date().toISOString(),o}async addAttachment(t,r,s){const i=this.notebooks.get(t);if(!i)throw new Error(`Notebook not found: ${t}`);const o=i.entries.find(l=>l.id===r);if(!o)throw new Error(`Entry not found: ${r}`);const a={id:this.generateId(),name:s.name,type:s.type,size:s.size,url:URL.createObjectURL(s),uploadedAt:new Date().toISOString(),uploadedBy:"current-user"};return o.attachments.push(a),o.updatedAt=new Date().toISOString(),a}async searchEntries(t,r){var o,a,l,c,h,p;const s=[],i=t.toLowerCase();for(const f of this.notebooks.values())if(!(r!=null&&r.notebookId&&f.id!==r.notebookId))for(const m of f.entries)r!=null&&r.type&&m.type!==r.type||r!=null&&r.status&&m.status!==r.status||(o=r==null?void 0:r.tags)!=null&&o.length&&!r.tags.some(j=>m.tags.includes(j))||r!=null&&r.dateFrom&&m.createdAt<r.dateFrom||r!=null&&r.dateTo&&m.createdAt>r.dateTo||(m.title.toLowerCase().includes(i)||(a=m.objective)!=null&&a.toLowerCase().includes(i)||(l=m.hypothesis)!=null&&l.toLowerCase().includes(i)||(c=m.methods)!=null&&c.toLowerCase().includes(i)||(h=m.results)!=null&&h.toLowerCase().includes(i)||(p=m.conclusions)!=null&&p.toLowerCase().includes(i))&&s.push(m);return s}async exportEntry(t,r,s){const i=this.notebooks.get(t);if(!i)throw new Error(`Notebook not found: ${t}`);const o=i.entries.find(l=>l.id===r);if(!o)throw new Error(`Entry not found: ${r}`);const a=this.generateEntryHTML(o,i);return s==="html"?new Blob([a],{type:"text/html"}):new Blob([a],{type:"text/html"})}generateEntryHTML(t,r){return`
1
+ "use strict";var st=Object.defineProperty;var it=(e,t,r)=>t in e?st(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Se=(e,t,r)=>it(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),pe=require("@nice2dev/ui-core"),h=require("react");class Ye{constructor(t){Se(this,"config");Se(this,"notebooks",new Map);this.config=t}async createNotebook(t){const r={id:this.generateId(),name:t.name||"Untitled Notebook",description:t.description,project:t.project,owner:t.owner||"current-user",collaborators:t.collaborators||[],entries:[],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),isArchived:!1,settings:t.settings||{requireSignatures:!0,requireWitness:!1,autoLockAfterSign:!0,defaultEntryType:"experiment",customFields:[],templates:[]}};return this.notebooks.set(r.id,r),r}async getNotebook(t){return this.notebooks.get(t)||null}async listNotebooks(){return Array.from(this.notebooks.values())}async createEntry(t,r){const s=this.notebooks.get(t);if(!s)throw new Error(`Notebook not found: ${t}`);const i={id:this.generateId(),notebookId:t,type:r.type||s.settings.defaultEntryType,status:"draft",title:r.title||"Untitled Entry",objective:r.objective,hypothesis:r.hypothesis,methods:r.methods,results:r.results,conclusions:r.conclusions,sections:r.sections||[],attachments:[],tags:r.tags||[],linkedEntries:r.linkedEntries||[],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),createdBy:"current-user",lastModifiedBy:"current-user",version:1,signatures:[],comments:[]};return s.entries.push(i),s.updatedAt=new Date().toISOString(),i}async updateEntry(t,r,s){const i=this.notebooks.get(t);if(!i)throw new Error(`Notebook not found: ${t}`);const o=i.entries.findIndex(c=>c.id===r);if(o===-1)throw new Error(`Entry not found: ${r}`);const a=i.entries[o];if(a.status==="locked")throw new Error("Cannot modify locked entry");const l={...a,...s,id:a.id,notebookId:t,updatedAt:new Date().toISOString(),lastModifiedBy:"current-user",version:a.version+1};return i.entries[o]=l,i.updatedAt=new Date().toISOString(),l}async signEntry(t,r,s){const i=this.notebooks.get(t);if(!i)throw new Error(`Notebook not found: ${t}`);const o=i.entries.find(l=>l.id===r);if(!o)throw new Error(`Entry not found: ${r}`);const a={...s,signedAt:new Date().toISOString(),signatureHash:this.generateSignatureHash(o,s.userId)};return o.signatures.push(a),i.settings.autoLockAfterSign&&s.role==="author"&&(o.status="signed"),o.updatedAt=new Date().toISOString(),o}async addAttachment(t,r,s){const i=this.notebooks.get(t);if(!i)throw new Error(`Notebook not found: ${t}`);const o=i.entries.find(l=>l.id===r);if(!o)throw new Error(`Entry not found: ${r}`);const a={id:this.generateId(),name:s.name,type:s.type,size:s.size,url:URL.createObjectURL(s),uploadedAt:new Date().toISOString(),uploadedBy:"current-user"};return o.attachments.push(a),o.updatedAt=new Date().toISOString(),a}async searchEntries(t,r){var o,a,l,c,u,x;const s=[],i=t.toLowerCase();for(const y of this.notebooks.values())if(!(r!=null&&r.notebookId&&y.id!==r.notebookId))for(const f of y.entries)r!=null&&r.type&&f.type!==r.type||r!=null&&r.status&&f.status!==r.status||(o=r==null?void 0:r.tags)!=null&&o.length&&!r.tags.some(m=>f.tags.includes(m))||r!=null&&r.dateFrom&&f.createdAt<r.dateFrom||r!=null&&r.dateTo&&f.createdAt>r.dateTo||(f.title.toLowerCase().includes(i)||(a=f.objective)!=null&&a.toLowerCase().includes(i)||(l=f.hypothesis)!=null&&l.toLowerCase().includes(i)||(c=f.methods)!=null&&c.toLowerCase().includes(i)||(u=f.results)!=null&&u.toLowerCase().includes(i)||(x=f.conclusions)!=null&&x.toLowerCase().includes(i))&&s.push(f);return s}async exportEntry(t,r,s){const i=this.notebooks.get(t);if(!i)throw new Error(`Notebook not found: ${t}`);const o=i.entries.find(l=>l.id===r);if(!o)throw new Error(`Entry not found: ${r}`);const a=this.generateEntryHTML(o,i);return s==="html"?new Blob([a],{type:"text/html"}):new Blob([a],{type:"text/html"})}generateEntryHTML(t,r){return`
2
2
  <!DOCTYPE html>
3
3
  <html>
4
4
  <head>
@@ -39,9 +39,9 @@
39
39
  `:""}
40
40
  </body>
41
41
  </html>
42
- `}generateId(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}generateSignatureHash(t,r){const s=JSON.stringify({entry:t,userId:r,timestamp:Date.now()});return Buffer.from(s).toString("base64").substring(0,32)}}function st(e){return new Xe(e)}const Ye=u.createContext(null);function Ie(){const e=u.useContext(Ye);if(!e)throw new Error("useLabNotebook must be used within LabNotebookProvider");return e}function Pe({service:e,children:t}){const[r,s]=u.useState([]),[i,o]=u.useState(null),[a,l]=u.useState(null),c=u.useCallback(async()=>{const j=await e.listNotebooks();s(j)},[e]),h=u.useMemo(()=>r.find(j=>j.id===i)||null,[r,i]),p=u.useMemo(()=>(h==null?void 0:h.entries.find(j=>j.id===a))||null,[h,a]),f=u.useCallback(j=>{o(j),l(null)},[]),m={service:e,notebooks:r,currentNotebook:h,currentEntry:p,setCurrentNotebook:f,setCurrentEntry:l,refresh:c};return n.jsx(Ye.Provider,{value:m,children:t})}const Y={container:{display:"flex",height:"100%",backgroundColor:"var(--nice-bg-secondary, #f5f5f5)",fontFamily:"'Inter', sans-serif"},sidebar:{width:"280px",backgroundColor:"var(--nice-bg, #fff)",borderRight:"1px solid var(--nice-border, #e0e0e0)",display:"flex",flexDirection:"column"},main:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},header:{padding:"16px 24px",borderBottom:"1px solid var(--nice-border, #e0e0e0)",backgroundColor:"var(--nice-bg, #fff)"},content:{flex:1,padding:"24px",overflow:"auto"},entryCard:{padding:"12px 16px",borderBottom:"1px solid var(--nice-border, #eee)",cursor:"pointer",transition:"background-color 0.15s"},badge:{display:"inline-block",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:500,textTransform:"uppercase"},input:{width:"100%",padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)",borderRadius:"4px",fontSize:"14px"},textarea:{width:"100%",padding:"12px",border:"1px solid var(--nice-border, #ddd)",borderRadius:"4px",fontSize:"14px",minHeight:"100px",resize:"vertical"},button:{padding:"8px 16px",backgroundColor:"var(--nice-primary-hover, #1976d2)",color:"var(--nice-text-on-primary, #fff)",border:"none",borderRadius:"4px",cursor:"pointer",fontSize:"14px"}},Ne={draft:"var(--nice-text-secondary, #9e9e9e)","in-progress":"var(--nice-primary, #2196f3)",completed:"var(--nice-success, #4caf50)",reviewed:"var(--nice-warning, #ff9800)",signed:"var(--nice-accent, #9c27b0)",locked:"var(--nice-danger, #f44336)"},qe={experiment:"EXP",protocol:"PRO",observation:"OBS",calculation:"CALC",meeting:"MEET",report:"REP",note:"NOTE"};function it({service:e,className:t,style:r}){return n.jsx(Pe,{service:e,children:n.jsxs("div",{className:t,style:{...Y.container,...r},children:[n.jsx(ot,{}),n.jsx(at,{})]})})}function ot(){const{notebooks:e,currentNotebook:t,setCurrentNotebook:r,service:s,refresh:i}=Ie(),[o,a]=u.useState(!1),[l,c]=u.useState(""),h=async()=>{l.trim()&&(await s.createNotebook({name:l.trim()}),await i(),c(""),a(!1))};return n.jsxs("div",{style:Y.sidebar,children:[n.jsx("div",{style:{padding:"16px",borderBottom:"1px solid var(--nice-border, #e0e0e0)"},children:n.jsx("h2",{style:{margin:0,fontSize:"18px"},children:"Lab Notebooks"})}),n.jsx("div",{style:{flex:1,overflow:"auto"},children:e.map(p=>n.jsxs("div",{onClick:()=>r(p.id),style:{...Y.entryCard,backgroundColor:(t==null?void 0:t.id)===p.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsx("div",{style:{fontWeight:500},children:p.name}),n.jsxs("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)",marginTop:"4px"},children:[p.entries.length," entries"]})]},p.id))}),n.jsx("div",{style:{padding:"16px",borderTop:"1px solid var(--nice-border, #e0e0e0)"},children:o?n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[n.jsx("input",{type:"text",value:l,onChange:p=>c(p.target.value),placeholder:"Notebook name",style:Y.input,autoFocus:!0}),n.jsxs("div",{style:{display:"flex",gap:"8px"},children:[n.jsx("button",{onClick:h,style:Y.button,children:"Create"}),n.jsx("button",{onClick:()=>a(!1),style:{...Y.button,backgroundColor:"var(--nice-bg-tertiary, #9e9e9e)"},children:"Cancel"})]})]}):n.jsx("button",{onClick:()=>a(!0),style:{...Y.button,width:"100%"},children:"+ New Notebook"})})]})}function at(){const{currentNotebook:e,currentEntry:t,setCurrentEntry:r,service:s,refresh:i}=Ie(),[o,a]=u.useState(!1);if(!e)return n.jsx("div",{style:{...Y.main,justifyContent:"center",alignItems:"center"},children:n.jsx("div",{style:{textAlign:"center",color:"var(--nice-text-secondary, #666)"},children:n.jsx("div",{style:{fontSize:"18px"},children:"Select a notebook to get started"})})});const l=async c=>{const h=await s.createEntry(e.id,c);await i(),r(h.id),a(!1)};return n.jsxs("div",{style:Y.main,children:[n.jsx("div",{style:Y.header,children:n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[n.jsx("h1",{style:{margin:0,fontSize:"20px"},children:e.name}),n.jsx("button",{onClick:()=>a(!0),style:Y.button,children:"+ New Entry"})]})}),n.jsxs("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[n.jsx("div",{style:{width:"300px",borderRight:"1px solid var(--nice-border, #e0e0e0)",overflow:"auto"},children:e.entries.map(c=>n.jsxs("div",{onClick:()=>r(c.id),style:{...Y.entryCard,backgroundColor:(t==null?void 0:t.id)===c.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[n.jsx("span",{style:{fontSize:"10px",fontWeight:600,color:"var(--nice-text-secondary, #666)"},children:qe[c.type]}),n.jsx("span",{style:{fontWeight:500},children:c.title})]}),n.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[n.jsx("span",{style:{...Y.badge,backgroundColor:`${Ne[c.status]}20`,color:Ne[c.status]},children:c.status}),n.jsx("span",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:new Date(c.updatedAt).toLocaleDateString()})]})]},c.id))}),n.jsx("div",{style:Y.content,children:t?n.jsx(lt,{entry:t}):o?n.jsx(ct,{onSubmit:l,onCancel:()=>a(!1)}):n.jsx("div",{style:{textAlign:"center",color:"var(--nice-text-secondary, #666)",marginTop:"100px"},children:"Select an entry or create a new one"})})]})]})}function lt({entry:e}){const{service:t,currentNotebook:r,refresh:s}=Ie(),[i,o]=u.useState(!1),[a,l]=u.useState(e),c=e.status==="locked"||e.status==="signed",h=async()=>{r&&(await t.updateEntry(r.id,e.id,a),await s(),o(!1))},p=async()=>{r&&(await t.signEntry(r.id,e.id,{userId:"current-user",userName:"Current User",role:"author"}),await s())};return n.jsxs("div",{children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:"24px"},children:[n.jsxs("div",{children:[n.jsx("h2",{style:{margin:0},children:e.title}),n.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[n.jsx("span",{style:{...Y.badge,backgroundColor:`${Ne[e.status]}20`,color:Ne[e.status]},children:e.status}),n.jsxs("span",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:["v",e.version]})]})]}),!c&&n.jsx("div",{style:{display:"flex",gap:"8px"},children:i?n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:h,style:Y.button,children:"Save"}),n.jsx("button",{onClick:()=>{o(!1),l(e)},style:{...Y.button,backgroundColor:"var(--nice-bg-tertiary, #9e9e9e)"},children:"Cancel"})]}):n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>o(!0),style:Y.button,children:"Edit"}),n.jsx("button",{onClick:p,style:{...Y.button,backgroundColor:"var(--nice-accent, #9c27b0)"},children:"Sign"})]})})]}),i?n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Title"}),n.jsx("input",{type:"text",value:a.title,onChange:f=>l({...a,title:f.target.value}),style:Y.input})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Objective"}),n.jsx("textarea",{value:a.objective||"",onChange:f=>l({...a,objective:f.target.value}),style:Y.textarea})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Methods"}),n.jsx("textarea",{value:a.methods||"",onChange:f=>l({...a,methods:f.target.value}),style:Y.textarea})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Results"}),n.jsx("textarea",{value:a.results||"",onChange:f=>l({...a,results:f.target.value}),style:Y.textarea})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Conclusions"}),n.jsx("textarea",{value:a.conclusions||"",onChange:f=>l({...a,conclusions:f.target.value}),style:Y.textarea})]})]}):n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"24px"},children:[e.objective&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:"Objective"}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.objective})]}),e.hypothesis&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:"Hypothesis"}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.hypothesis})]}),e.methods&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:"Methods"}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.methods})]}),e.results&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:"Results"}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.results})]}),e.conclusions&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:"Conclusions"}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.conclusions})]}),e.signatures.length>0&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-accent, #9c27b0)"},children:"Signatures"}),e.signatures.map((f,m)=>n.jsxs("div",{style:{padding:"8px",backgroundColor:"var(--nice-bg-secondary, #f5f5f5)",borderRadius:"4px",marginBottom:"8px"},children:[n.jsx("strong",{children:f.userName})," (",f.role,")",n.jsx("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:new Date(f.signedAt).toLocaleString()})]},m))]}),e.attachments.length>0&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0"},children:"Attachments"}),e.attachments.map(f=>n.jsxs("a",{href:f.url,target:"_blank",rel:"noopener noreferrer",style:{display:"block",color:"var(--nice-primary-hover, #1976d2)",textDecoration:"none"},children:[f.name," (",(f.size/1024).toFixed(1)," KB)"]},f.id))]})]})]})}function ct({onSubmit:e,onCancel:t}){const[r,s]=u.useState({title:"",type:"experiment",objective:""}),i=o=>{var a;o.preventDefault(),(a=r.title)!=null&&a.trim()&&e(r)};return n.jsxs("form",{onSubmit:i,style:{display:"flex",flexDirection:"column",gap:"16px"},children:[n.jsx("h2",{style:{margin:0},children:"New Entry"}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Type"}),n.jsx("select",{value:r.type,onChange:o=>s({...r,type:o.target.value}),style:Y.input,children:Object.entries(qe).map(([o,a])=>n.jsxs("option",{value:o,children:[a," ",o]},o))})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Title *"}),n.jsx("input",{type:"text",value:r.title,onChange:o=>s({...r,title:o.target.value}),placeholder:"Enter entry title",style:Y.input,required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:"Objective"}),n.jsx("textarea",{value:r.objective,onChange:o=>s({...r,objective:o.target.value}),placeholder:"What is the goal of this entry?",style:Y.textarea})]}),n.jsxs("div",{style:{display:"flex",gap:"8px"},children:[n.jsx("button",{type:"submit",style:Y.button,children:"Create Entry"}),n.jsx("button",{type:"button",onClick:t,style:{...Y.button,backgroundColor:"var(--nice-bg-tertiary, #9e9e9e)"},children:"Cancel"})]})]})}const ge=(function(){return{mean(e){return e.length===0?NaN:e.reduce((t,r)=>t+r,0)/e.length},median(e){if(e.length===0)return NaN;const t=[...e].sort((s,i)=>s-i),r=Math.floor(t.length/2);return t.length%2!==0?t[r]:(t[r-1]+t[r])/2},variance(e,t=!1){if(e.length===0)return NaN;const r=this.mean(e),s=e.map(o=>Math.pow(o-r,2)),i=t?e.length:e.length-1;return s.reduce((o,a)=>o+a,0)/i},std(e,t=!1){return Math.sqrt(this.variance(e,t))},mode(e){const t=new Map;let r=0,s=e[0];for(const i of e){const o=(t.get(i)||0)+1;t.set(i,o),o>r&&(r=o,s=i)}return s},percentile(e,t){if(e.length===0)return NaN;const r=[...e].sort((l,c)=>l-c),s=t/100*(r.length-1),i=Math.floor(s),o=Math.ceil(s),a=s-i;return r[i]*(1-a)+r[o]*a},quartiles(e){return{q1:this.percentile(e,25),q2:this.percentile(e,50),q3:this.percentile(e,75)}},skewness(e){const t=e.length;if(t<3)return NaN;const r=this.mean(e),s=this.std(e),i=e.map(o=>Math.pow((o-r)/s,3));return t/((t-1)*(t-2))*i.reduce((o,a)=>o+a,0)},kurtosis(e){const t=e.length;if(t<4)return NaN;const r=this.mean(e),s=this.std(e),o=e.map(a=>Math.pow((a-r)/s,4)).reduce((a,l)=>a+l,0);return t*(t+1)/((t-1)*(t-2)*(t-3))*o-3*Math.pow(t-1,2)/((t-2)*(t-3))},correlation(e,t){if(e.length!==t.length||e.length<2)return NaN;const r=e.length,s=this.mean(e),i=this.mean(t);let o=0,a=0,l=0;for(let c=0;c<r;c++){const h=e[c]-s,p=t[c]-i;o+=h*p,a+=h*h,l+=p*p}return o/Math.sqrt(a*l)},correlationMatrix(e){const t=Object.keys(e),r={};for(const s of t){r[s]={};for(const i of t)r[s][i]=this.correlation(e[s],e[i])}return r},covariance(e,t,r=!1){if(e.length!==t.length||e.length<2)return NaN;const s=e.length,i=this.mean(e),o=this.mean(t);let a=0;for(let l=0;l<s;l++)a+=(e[l]-i)*(t[l]-o);return a/(r?s:s-1)},linearRegression(e,t){if(e.length!==t.length||e.length<2)throw new Error("Invalid input arrays");const r=e.length,s=this.mean(e),i=this.mean(t);let o=0,a=0;for(let j=0;j<r;j++)o+=(e[j]-s)*(t[j]-i),a+=Math.pow(e[j]-s,2);const l=o/a,c=i-l*s;let h=0,p=0;for(let j=0;j<r;j++){const M=l*e[j]+c;h+=Math.pow(t[j]-i,2),p+=Math.pow(t[j]-M,2)}const f=1-p/h,m=`y = ${l.toFixed(4)}x + ${c.toFixed(4)}`;return{slope:l,intercept:c,r2:f,equation:m}},tTest(e,t){const r=e.length,s=t.length,i=this.mean(e),o=this.mean(t),a=this.variance(e),l=this.variance(t),c=Math.sqrt(a/r+l/s),h=(i-o)/c,p=Math.pow(a/r+l/s,2)/(Math.pow(a/r,2)/(r-1)+Math.pow(l/s,2)/(s-1)),f=2*(1-this.normalCDF(Math.abs(h)));return{tStatistic:h,pValue:f,degreesOfFreedom:p,meanDiff:i-o}},normalCDF(e){const t=.254829592,r=-.284496736,s=1.421413741,i=-1.453152027,o=1.061405429,a=.3275911,l=e<0?-1:1;e=Math.abs(e)/Math.sqrt(2);const c=1/(1+a*e),h=1-((((o*c+i)*c+s)*c+r)*c+t)*c*Math.exp(-e*e);return .5*(1+l*h)},chiSquare(e,t){if(e.length!==t.length)throw new Error("Arrays must have same length");let r=0;for(let o=0;o<e.length;o++)r+=Math.pow(e[o]-t[o],2)/t[o];const s=e.length-1;return{chiSquare:r,pValue:.05,degreesOfFreedom:s}},zScore(e){const t=this.mean(e),r=this.std(e);return e.map(s=>(s-t)/r)},minMaxNormalize(e,t=0,r=1){const s=Math.min(...e),o=Math.max(...e)-s;return e.map(a=>t+(a-s)/o*(r-t))},describe(e){const t=e.filter(s=>s!=null&&!isNaN(s)),r=this.quartiles(t);return{count:t.length,mean:this.mean(t),median:r.q2,std:this.std(t),min:Math.min(...t),max:Math.max(...t),q1:r.q1,q3:r.q3,skewness:this.skewness(t),kurtosis:this.kurtosis(t),mode:this.mode(t),variance:this.variance(t)}}}})();class Ve{constructor(t={}){ye(this,"config");ye(this,"datasets",new Map);ye(this,"analyses",new Map);this.config={maxRowsInMemory:1e5,...t}}async importCSV(t,r){const s=(r==null?void 0:r.delimiter)||",",i=(r==null?void 0:r.header)!==!1,o=t.split(`
43
- `).filter(m=>m.trim());if(o.length===0)throw new Error("Empty CSV content");const a=m=>{const j=[];let M="",E=!1;for(const U of m)U==='"'?E=!E:U===s&&!E?(j.push(M.trim()),M=""):M+=U;return j.push(M.trim()),j},l=a(o[0]),c=i?l:l.map((m,j)=>`col_${j+1}`),h=i?1:0,p=[];for(let m=h;m<o.length;m++){const j=a(o[m]),M={};for(let E=0;E<c.length;E++){const U=j[E],Q=parseFloat(U);M[c[E]]=!isNaN(Q)&&U!==""?Q:U}p.push(M)}return this.createDataset({name:(r==null?void 0:r.name)||"Imported CSV",data:p,source:{type:"csv"}})}async importJSON(t,r){const s=typeof t=="string"?JSON.parse(t):t;if(!Array.isArray(s))throw new Error("JSON must be an array of objects");return this.createDataset({name:(r==null?void 0:r.name)||"Imported JSON",data:s,source:{type:"json"}})}createDataset(t){const{name:r,data:s,description:i,source:o}=t,a=this.inferColumns(s),l={id:this.generateId(),name:r,description:i,columns:a,data:s,rowCount:s.length,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),source:o};return this.datasets.set(l.id,l),l}inferColumns(t){if(t.length===0)return[];const r=new Set;t.forEach(i=>Object.keys(i).forEach(o=>r.add(o)));const s=[];for(const i of r){const o=t.map(p=>p[i]),a=o.filter(p=>p!=null),l=new Set(a);let c="mixed";a.every(p=>typeof p=="number")?c="number":a.every(p=>typeof p=="string")?c=l.size<a.length*.5?"category":"string":a.every(p=>typeof p=="boolean")?c="boolean":a.every(p=>p instanceof Date||!isNaN(Date.parse(p)))&&(c="date");const h={name:i,type:c,nullable:o.some(p=>p==null),unique:l.size,missing:o.length-a.length};if(c==="number"){const p=a.filter(f=>typeof f=="number");h.stats=ge.describe(p)}s.push(h)}return s}runAnalysis(t,r,s={}){const i=this.datasets.get(t);if(!i)throw new Error(`Dataset not found: ${t}`);const o=performance.now();let a;switch(r){case"descriptive":a=this.descriptiveAnalysis(i,s);break;case"correlation":a=this.correlationAnalysis(i,s);break;case"regression":a=this.regressionAnalysis(i,s);break;case"ttest":a=this.tTestAnalysis(i,s);break;case"distribution":a=this.distributionAnalysis(i,s);break;default:throw new Error(`Unsupported analysis type: ${r}`)}const l=performance.now()-o,c={id:this.generateId(),datasetId:t,type:r,parameters:s,result:a,createdAt:new Date().toISOString(),executionTimeMs:l};return this.analyses.set(c.id,c),c}descriptiveAnalysis(t,r){const s=r.columns||t.columns.filter(o=>o.type==="number").map(o=>o.name),i={};for(const o of s){const a=t.data.map(l=>l[o]).filter(l=>typeof l=="number");i[o]=ge.describe(a)}return i}correlationAnalysis(t,r){const s=r.columns||t.columns.filter(o=>o.type==="number").map(o=>o.name),i={};for(const o of s)i[o]=t.data.map(a=>a[o]).filter(a=>typeof a=="number");return{matrix:ge.correlationMatrix(i),columns:s}}regressionAnalysis(t,r){const{xColumn:s,yColumn:i}=r,o=t.data.map(l=>l[s]).filter(l=>typeof l=="number"),a=t.data.map(l=>l[i]).filter(l=>typeof l=="number");return ge.linearRegression(o,a)}tTestAnalysis(t,r){const{column:s,groupColumn:i}=r,o=new Map;for(const l of t.data){const c=l[i],h=l[s];typeof h=="number"&&(o.has(c)||o.set(c,[]),o.get(c).push(h))}const a=Array.from(o.keys());if(a.length!==2)throw new Error("T-test requires exactly 2 groups");return ge.tTest(o.get(a[0]),o.get(a[1]))}distributionAnalysis(t,r){const{column:s,bins:i=10}=r,o=t.data.map(f=>f[s]).filter(f=>typeof f=="number"),a=Math.min(...o),c=(Math.max(...o)-a)/i,h=new Array(i).fill(0),p=[];for(let f=0;f<=i;f++)p.push(a+f*c);for(const f of o){const m=Math.min(Math.floor((f-a)/c),i-1);h[m]++}return{histogram:h,binEdges:p,stats:ge.describe(o)}}transform(t,r){const s=this.datasets.get(t);if(!s)throw new Error(`Dataset not found: ${t}`);let i=[...s.data];switch(r.type){case"filter":i=this.applyFilter(i,r);break;case"sort":i=this.applySort(i,r);break;case"fillna":i=this.applyFillNA(i,r);break;case"dropna":i=this.applyDropNA(i,r);break;case"normalize":i=this.applyNormalize(i,r);break;case"standardize":i=this.applyStandardize(i,r);break;default:throw new Error(`Unsupported transformation: ${r.type}`)}return this.createDataset({name:`${s.name} (transformed)`,data:i})}applyFilter(t,r){const{column:s,parameters:i}=r,{operator:o,value:a}=i;return t.filter(l=>{const c=l[s];switch(o){case"==":return c===a;case"!=":return c!==a;case">":return c>a;case">=":return c>=a;case"<":return c<a;case"<=":return c<=a;case"contains":return String(c).includes(a);case"startswith":return String(c).startsWith(a);default:return!0}})}applySort(t,r){const{column:s,parameters:i}=r,o=i.ascending!==!1;return[...t].sort((a,l)=>{const c=a[s],h=l[s];return c<h?o?-1:1:c>h?o?1:-1:0})}applyFillNA(t,r){const{column:s,parameters:i}=r,o=i.value;return t.map(a=>({...a,[s]:a[s]??o}))}applyDropNA(t,r){const s=r.columns||[r.column];return t.filter(i=>s.every(o=>i[o]!=null))}applyNormalize(t,r){const{column:s}=r,i=t.map(c=>c[s]).filter(c=>typeof c=="number"),o=Math.min(...i),l=Math.max(...i)-o;return t.map(c=>({...c,[s]:typeof c[s]=="number"?(c[s]-o)/l:c[s]}))}applyStandardize(t,r){const{column:s}=r,i=t.map(l=>l[s]).filter(l=>typeof l=="number"),o=ge.mean(i),a=ge.std(i);return t.map(l=>({...l,[s]:typeof l[s]=="number"?(l[s]-o)/a:l[s]}))}exportCSV(t){const r=this.datasets.get(t);if(!r)throw new Error(`Dataset not found: ${t}`);const s=r.columns.map(o=>o.name),i=r.data.map(o=>s.map(a=>{const l=o[a];return l==null?"":typeof l=="string"&&(l.includes(",")||l.includes('"'))?`"${l.replace(/"/g,'""')}"`:String(l)}).join(","));return[s.join(","),...i].join(`
44
- `)}getDataset(t){return this.datasets.get(t)}listDatasets(){return Array.from(this.datasets.values())}generateId(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}}function dt(e){return new Ve(e)}function ut({service:e,className:t,style:r}){const[s,i]=u.useState([]),[o,a]=u.useState(null),[l,c]=u.useState("data"),h=u.useCallback(()=>{i(e.listDatasets())},[e]),p=u.useMemo(()=>s.find(m=>m.id===o),[s,o]),f=async m=>{var E;const j=(E=m.target.files)==null?void 0:E[0];if(!j)return;const M=await j.text();j.name.endsWith(".csv")?await e.importCSV(M,{name:j.name}):j.name.endsWith(".json")&&await e.importJSON(M,{name:j.name}),h()};return n.jsxs("div",{className:t,style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:"'Inter', sans-serif",...r},children:[n.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--nice-border, #e0e0e0)",display:"flex",gap:"12px",alignItems:"center"},children:[n.jsxs("label",{style:{padding:"8px 16px",backgroundColor:"var(--nice-primary-hover, #1976d2)",color:"white",borderRadius:"4px",cursor:"pointer"},children:["Import Data",n.jsx("input",{type:"file",accept:".csv,.json",onChange:f,style:{display:"none"}})]}),n.jsxs("select",{value:o||"",onChange:m=>a(m.target.value||null),style:{padding:"8px 12px",borderRadius:"4px",border:"1px solid var(--nice-border, #ddd)"},children:[n.jsx("option",{value:"",children:"Select dataset..."}),s.map(m=>n.jsxs("option",{value:m.id,children:[m.name," (",m.rowCount," rows)"]},m.id))]}),p&&n.jsx("div",{style:{marginLeft:"auto",display:"flex",gap:"8px"},children:["data","stats","analysis"].map(m=>n.jsx("button",{onClick:()=>c(m),style:{padding:"8px 16px",backgroundColor:l===m?"var(--nice-primary-hover, #1976d2)":"transparent",color:l===m?"white":"var(--nice-text, #333)",border:"1px solid var(--nice-border, #ddd)",borderRadius:"4px",cursor:"pointer",textTransform:"capitalize"},children:m},m))})]}),n.jsx("div",{style:{flex:1,overflow:"auto",padding:"16px"},children:p?l==="data"?n.jsx(ht,{dataset:p}):l==="stats"?n.jsx(pt,{dataset:p}):n.jsx(xt,{dataset:p,service:e}):n.jsx("div",{style:{textAlign:"center",color:"var(--nice-text-secondary, #666)",padding:"48px"},children:n.jsx("div",{style:{fontSize:"18px"},children:"Import a dataset or select an existing one to begin"})})})]})}function ht({dataset:e}){const[t,r]=u.useState(0),s=50,i=Math.ceil(e.rowCount/s),o=e.data.slice(t*s,(t+1)*s);return n.jsxs("div",{children:[n.jsx("div",{style:{overflowX:"auto",marginBottom:"16px"},children:n.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{backgroundColor:"var(--nice-bg-secondary, #f5f5f5)"},children:[n.jsx("th",{style:{padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)",textAlign:"left"},children:"#"}),e.columns.map(a=>n.jsxs("th",{style:{padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)",textAlign:"left"},children:[a.name,n.jsx("div",{style:{fontSize:"10px",color:"var(--nice-text-secondary, #666)",fontWeight:"normal"},children:a.type})]},a.name))]})}),n.jsx("tbody",{children:o.map((a,l)=>n.jsxs("tr",{children:[n.jsx("td",{style:{padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)",color:"var(--nice-text-secondary, #666)"},children:t*s+l+1}),e.columns.map(c=>n.jsx("td",{style:{padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)"},children:a[c.name]!=null?String(a[c.name]):n.jsx("span",{style:{color:"var(--nice-text-secondary, #ccc)"},children:"null"})},c.name))]},l))})]})}),n.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center",justifyContent:"center"},children:[n.jsx("button",{onClick:()=>r(0),disabled:t===0,children:"First"}),n.jsx("button",{onClick:()=>r(t-1),disabled:t===0,children:"Prev"}),n.jsxs("span",{children:["Page ",t+1," of ",i]}),n.jsx("button",{onClick:()=>r(t+1),disabled:t>=i-1,children:"Next"}),n.jsx("button",{onClick:()=>r(i-1),disabled:t>=i-1,children:"Last"})]})]})}function pt({dataset:e}){const t=e.columns.filter(r=>r.type==="number");return n.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(300px, 1fr))",gap:"16px"},children:t.map(r=>n.jsxs("div",{style:{padding:"16px",backgroundColor:"var(--nice-bg-secondary, #f9f9f9)",borderRadius:"8px"},children:[n.jsx("h3",{style:{margin:"0 0 12px 0"},children:r.name}),r.stats&&n.jsx("table",{style:{width:"100%",fontSize:"13px"},children:n.jsx("tbody",{children:Object.entries(r.stats).map(([s,i])=>n.jsxs("tr",{children:[n.jsx("td",{style:{padding:"4px 0",color:"var(--nice-text-secondary, #666)"},children:s}),n.jsx("td",{style:{padding:"4px 0",textAlign:"right",fontFamily:"monospace"},children:typeof i=="number"?i.toFixed(4):String(i)})]},s))})})]},r.name))})}function xt({dataset:e,service:t}){const[r,s]=u.useState("descriptive"),[i,o]=u.useState(null),a=()=>{const l=t.runAnalysis(e.id,r,{});o(l)};return n.jsxs("div",{children:[n.jsxs("div",{style:{display:"flex",gap:"12px",marginBottom:"24px"},children:[n.jsxs("select",{value:r,onChange:l=>s(l.target.value),style:{padding:"8px 12px",borderRadius:"4px",border:"1px solid var(--nice-border, #ddd)"},children:[n.jsx("option",{value:"descriptive",children:"Descriptive Statistics"}),n.jsx("option",{value:"correlation",children:"Correlation Matrix"}),n.jsx("option",{value:"distribution",children:"Distribution Analysis"})]}),n.jsx("button",{onClick:a,style:{padding:"8px 16px",backgroundColor:"var(--nice-primary-hover, #1976d2)",color:"white",border:"none",borderRadius:"4px",cursor:"pointer"},children:"Run Analysis"})]}),i&&n.jsxs("div",{style:{padding:"16px",backgroundColor:"var(--nice-bg-secondary, #f9f9f9)",borderRadius:"8px"},children:[n.jsxs("h3",{style:{margin:"0 0 12px 0"},children:["Results (",i.executionTimeMs.toFixed(2),"ms)"]}),n.jsx("pre",{style:{margin:0,overflow:"auto",fontSize:"12px"},children:JSON.stringify(i.result,null,2)})]})]})}const _e={apa:e=>{const t=ft(e.authors),r=e.year?` (${e.year}).`:".",s=e.title;let i="";e.type==="article"&&e.journal?(i=` *${e.journal}*`,e.volume&&(i+=`, *${e.volume}*`),e.issue&&(i+=`(${e.issue})`),e.pages&&(i+=`, ${e.pages}`),i+="."):e.type==="book"&&(i=e.publisher?` ${e.publisher}.`:"");const o=e.doi?` https://doi.org/${e.doi}`:"";return`${t}${r} ${s}.${i}${o}`},mla:e=>{const t=Ue(e.authors),r=`"${e.title}."`;let s="";return e.type==="article"&&e.journal&&(s=` *${e.journal}*`,e.volume&&(s+=`, vol. ${e.volume}`),e.issue&&(s+=`, no. ${e.issue}`),e.year&&(s+=`, ${e.year}`),e.pages&&(s+=`, pp. ${e.pages}`),s+="."),`${t} ${r}${s}`},chicago:e=>{const t=mt(e.authors),r=`"${e.title}."`;let s="";return e.type==="article"&&e.journal&&(s=` *${e.journal}*`,e.volume&&(s+=` ${e.volume}`),e.issue&&(s+=`, no. ${e.issue}`),e.year&&(s+=` (${e.year})`),e.pages&&(s+=`: ${e.pages}`),s+="."),`${t} ${r}${s}`},harvard:e=>{const t=yt(e.authors),r=e.year?` (${e.year})`:"",s=`'${e.title}'`;let i="";return e.type==="article"&&e.journal&&(i=`, *${e.journal}*`,e.volume&&(i+=`, ${e.volume}`),e.issue&&(i+=`(${e.issue})`),e.pages&&(i+=`, pp. ${e.pages}`),i+="."),`${t}${r} ${s}${i}`},ieee:e=>{const t=gt(e.authors),r=`"${e.title},"`;let s="";return e.type==="article"&&e.journal&&(s=` *${e.journal}*`,e.volume&&(s+=`, vol. ${e.volume}`),e.issue&&(s+=`, no. ${e.issue}`),e.pages&&(s+=`, pp. ${e.pages}`),e.year&&(s+=`, ${e.year}`),s+="."),`${t} ${r}${s}`},vancouver:e=>{const t=bt(e.authors),r=e.title;let s="";return e.type==="article"&&e.journal&&(s=` ${e.journal}`,e.year&&(s+=`. ${e.year}`),e.volume&&(s+=`;${e.volume}`),e.issue&&(s+=`(${e.issue})`),e.pages&&(s+=`:${e.pages}`),s+="."),`${t}. ${r}.${s}`},nature:e=>{const t=Ze(e.authors),r=e.title;let s="";return e.type==="article"&&e.journal&&(s=` *${e.journal}*`,e.volume&&(s+=` **${e.volume}**`),e.pages&&(s+=`, ${e.pages}`),e.year&&(s+=` (${e.year})`),s+="."),`${t} ${r}.${s}`},science:e=>{const t=vt(e.authors),r=e.title;let s="";return e.type==="article"&&e.journal&&(s=` *${e.journal}*`,e.volume&&(s+=` **${e.volume}**`),e.pages&&(s+=`, ${e.pages}`),e.year&&(s+=` (${e.year})`),s+="."),`${t}, ${r}.${s}`},bibtex:e=>{const t=jt(e),r=e.type==="article"?"article":e.type==="book"?"book":"misc";let i=` author = {${e.authors.map(o=>`${o.family}, ${o.given}`).join(" and ")}},
42
+ `}generateId(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}generateSignatureHash(t,r){const s=JSON.stringify({entry:t,userId:r,timestamp:Date.now()});return Buffer.from(s).toString("base64").substring(0,32)}}function ot(e){return new Ye(e)}const Ve=h.createContext(null);function Te(){const e=h.useContext(Ve);if(!e)throw new Error("useLabNotebook must be used within LabNotebookProvider");return e}function qe({service:e,children:t}){const[r,s]=h.useState([]),[i,o]=h.useState(null),[a,l]=h.useState(null),c=h.useCallback(async()=>{const m=await e.listNotebooks();s(m)},[e]),u=h.useMemo(()=>r.find(m=>m.id===i)||null,[r,i]),x=h.useMemo(()=>(u==null?void 0:u.entries.find(m=>m.id===a))||null,[u,a]),y=h.useCallback(m=>{o(m),l(null)},[]),f={service:e,notebooks:r,currentNotebook:u,currentEntry:x,setCurrentNotebook:y,setCurrentEntry:l,refresh:c};return n.jsx(Ve.Provider,{value:f,children:t})}const K={container:{display:"flex",height:"100%",backgroundColor:"var(--nice-bg-secondary, #f5f5f5)",fontFamily:"'Inter', sans-serif"},sidebar:{width:"280px",backgroundColor:"var(--nice-bg, #fff)",borderRight:"1px solid var(--nice-border, #e0e0e0)",display:"flex",flexDirection:"column"},main:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},header:{padding:"16px 24px",borderBottom:"1px solid var(--nice-border, #e0e0e0)",backgroundColor:"var(--nice-bg, #fff)"},content:{flex:1,padding:"24px",overflow:"auto"},entryCard:{padding:"12px 16px",borderBottom:"1px solid var(--nice-border, #eee)",cursor:"pointer",transition:"background-color 0.15s"},badge:{display:"inline-block",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:500,textTransform:"uppercase"},input:{width:"100%",padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)",borderRadius:"4px",fontSize:"14px"},textarea:{width:"100%",padding:"12px",border:"1px solid var(--nice-border, #ddd)",borderRadius:"4px",fontSize:"14px",minHeight:"100px",resize:"vertical"},button:{padding:"8px 16px",backgroundColor:"var(--nice-primary-hover, #1976d2)",color:"var(--nice-text-on-primary, #fff)",border:"none",borderRadius:"4px",cursor:"pointer",fontSize:"14px"}},Be={draft:"var(--nice-text-secondary, #9e9e9e)","in-progress":"var(--nice-primary, #2196f3)",completed:"var(--nice-success, #4caf50)",reviewed:"var(--nice-warning, #ff9800)",signed:"var(--nice-accent, #9c27b0)",locked:"var(--nice-danger, #f44336)"},Ue={experiment:"EXP",protocol:"PRO",observation:"OBS",calculation:"CALC",meeting:"MEET",report:"REP",note:"NOTE"};function at({service:e,className:t,style:r}){return n.jsx(qe,{service:e,children:n.jsxs("div",{className:t,style:{...K.container,...r},children:[n.jsx(lt,{}),n.jsx(ct,{})]})})}function lt(){const{t:e}=pe.useNiceTranslation(),{notebooks:t,currentNotebook:r,setCurrentNotebook:s,service:i,refresh:o}=Te(),[a,l]=h.useState(!1),[c,u]=h.useState(""),x=async()=>{c.trim()&&(await i.createNotebook({name:c.trim()}),await o(),u(""),l(!1))};return n.jsxs("div",{style:K.sidebar,children:[n.jsx("div",{style:{padding:"16px",borderBottom:"1px solid var(--nice-border, #e0e0e0)"},children:n.jsx("h2",{style:{margin:0,fontSize:"18px"},children:e("labNotebook.labNotebooks","Lab Notebooks")})}),n.jsx("div",{style:{flex:1,overflow:"auto"},children:t.map(y=>n.jsxs("div",{role:"button",tabIndex:0,onKeyDown:pe.clickOnActivationKey,onClick:()=>s(y.id),style:{...K.entryCard,backgroundColor:(r==null?void 0:r.id)===y.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsx("div",{style:{fontWeight:500},children:y.name}),n.jsx("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)",marginTop:"4px"},children:e("labNotebook.entries","{entries} entries").replace("{entries}",String(y.entries.length))})]},y.id))}),n.jsx("div",{style:{padding:"16px",borderTop:"1px solid var(--nice-border, #e0e0e0)"},children:a?n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[n.jsx("input",{type:"text",value:c,onChange:y=>u(y.target.value),placeholder:e("labNotebook.notebookName","Notebook name"),style:K.input,autoFocus:!0}),n.jsxs("div",{style:{display:"flex",gap:"8px"},children:[n.jsx("button",{onClick:x,style:K.button,children:e("labNotebook.create","Create")}),n.jsx("button",{onClick:()=>l(!1),style:{...K.button,backgroundColor:"var(--nice-bg-tertiary, #9e9e9e)"},children:e("labNotebook.cancel","Cancel")})]})]}):n.jsx("button",{onClick:()=>l(!0),style:{...K.button,width:"100%"},children:e("labNotebook.newNotebook","+ New Notebook")})})]})}function ct(){const{t:e}=pe.useNiceTranslation(),{currentNotebook:t,currentEntry:r,setCurrentEntry:s,service:i,refresh:o}=Te(),[a,l]=h.useState(!1);if(!t)return n.jsx("div",{style:{...K.main,justifyContent:"center",alignItems:"center"},children:n.jsx("div",{style:{textAlign:"center",color:"var(--nice-text-secondary, #666)"},children:n.jsx("div",{style:{fontSize:"18px"},children:e("labNotebook.selectANotebookToGet","Select a notebook to get started")})})});const c=async u=>{const x=await i.createEntry(t.id,{...u,title:u.title||e("labNotebook.untitledEntry","Untitled Entry")});await o(),s(x.id),l(!1)};return n.jsxs("div",{style:K.main,children:[n.jsx("div",{style:K.header,children:n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[n.jsx("h1",{style:{margin:0,fontSize:"20px"},children:t.name}),n.jsx("button",{onClick:()=>l(!0),style:K.button,children:e("labNotebook.newEntry","+ New Entry")})]})}),n.jsxs("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[n.jsx("div",{style:{width:"300px",borderRight:"1px solid var(--nice-border, #e0e0e0)",overflow:"auto"},children:t.entries.map(u=>n.jsxs("div",{role:"button",tabIndex:0,onKeyDown:pe.clickOnActivationKey,onClick:()=>s(u.id),style:{...K.entryCard,backgroundColor:(r==null?void 0:r.id)===u.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[n.jsx("span",{style:{fontSize:"10px",fontWeight:600,color:"var(--nice-text-secondary, #666)"},children:Ue[u.type]}),n.jsx("span",{style:{fontWeight:500},children:u.title})]}),n.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[n.jsx("span",{style:{...K.badge,backgroundColor:`${Be[u.status]}20`,color:Be[u.status]},children:u.status}),n.jsx("span",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:new Date(u.updatedAt).toLocaleDateString()})]})]},u.id))}),n.jsx("div",{style:K.content,children:r?n.jsx(dt,{entry:r}):a?n.jsx(ut,{onSubmit:c,onCancel:()=>l(!1)}):n.jsx("div",{style:{textAlign:"center",color:"var(--nice-text-secondary, #666)",marginTop:"100px"},children:e("labNotebook.selectAnEntryOrCreate","Select an entry or create a new one")})})]})]})}function dt({entry:e}){const{t}=pe.useNiceTranslation(),{service:r,currentNotebook:s,refresh:i}=Te(),[o,a]=h.useState(!1),[l,c]=h.useState(e),u=e.status==="locked"||e.status==="signed",x=async()=>{s&&(await r.updateEntry(s.id,e.id,l),await i(),a(!1))},y=async()=>{s&&(await r.signEntry(s.id,e.id,{userId:"current-user",userName:"Current User",role:"author"}),await i())};return n.jsxs("div",{children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:"24px"},children:[n.jsxs("div",{children:[n.jsx("h2",{style:{margin:0},children:e.title}),n.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[n.jsx("span",{style:{...K.badge,backgroundColor:`${Be[e.status]}20`,color:Be[e.status]},children:e.status}),n.jsxs("span",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:["v",e.version]})]})]}),!u&&n.jsx("div",{style:{display:"flex",gap:"8px"},children:o?n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:x,style:K.button,children:t("labNotebook.save","Save")}),n.jsx("button",{onClick:()=>{a(!1),c(e)},style:{...K.button,backgroundColor:"var(--nice-bg-tertiary, #9e9e9e)"},children:t("labNotebook.cancel","Cancel")})]}):n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>a(!0),style:K.button,children:t("labNotebook.edit","Edit")}),n.jsx("button",{onClick:y,style:{...K.button,backgroundColor:"var(--nice-accent, #9c27b0)"},children:t("labNotebook.sign","Sign")})]})})]}),o?n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:t("labNotebook.title","Title")}),n.jsx("input",{type:"text",value:l.title,onChange:f=>c({...l,title:f.target.value}),style:K.input})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:t("labNotebook.objective","Objective")}),n.jsx("textarea",{value:l.objective||"",onChange:f=>c({...l,objective:f.target.value}),style:K.textarea})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:t("labNotebook.methods","Methods")}),n.jsx("textarea",{value:l.methods||"",onChange:f=>c({...l,methods:f.target.value}),style:K.textarea})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:t("labNotebook.results","Results")}),n.jsx("textarea",{value:l.results||"",onChange:f=>c({...l,results:f.target.value}),style:K.textarea})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:t("labNotebook.conclusions","Conclusions")}),n.jsx("textarea",{value:l.conclusions||"",onChange:f=>c({...l,conclusions:f.target.value}),style:K.textarea})]})]}):n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"24px"},children:[e.objective&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:t("labNotebook.objective","Objective")}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.objective})]}),e.hypothesis&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:t("labNotebook.hypothesis","Hypothesis")}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.hypothesis})]}),e.methods&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:t("labNotebook.methods","Methods")}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.methods})]}),e.results&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:t("labNotebook.results","Results")}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.results})]}),e.conclusions&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-primary-hover, #1976d2)"},children:t("labNotebook.conclusions","Conclusions")}),n.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:e.conclusions})]}),e.signatures.length>0&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0",color:"var(--nice-accent, #9c27b0)"},children:t("labNotebook.signatures","Signatures")}),e.signatures.map((f,m)=>n.jsxs("div",{style:{padding:"8px",backgroundColor:"var(--nice-bg-secondary, #f5f5f5)",borderRadius:"4px",marginBottom:"8px"},children:[n.jsx("strong",{children:f.userName})," (",f.role,")",n.jsx("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:new Date(f.signedAt).toLocaleString()})]},m))]}),e.attachments.length>0&&n.jsxs("section",{children:[n.jsx("h3",{style:{margin:"0 0 8px 0"},children:t("labNotebook.attachments","Attachments")}),e.attachments.map(f=>n.jsx("a",{href:f.url,target:"_blank",rel:"noopener noreferrer",style:{display:"block",color:"var(--nice-primary-hover, #1976d2)",textDecoration:"none"},children:t("labNotebook.kb","{name} ({size} KB)").replace("{name}",String(f.name)).replace("{size}",String((f.size/1024).toFixed(1)))},f.id))]})]})]})}function ut({onSubmit:e,onCancel:t}){const{t:r}=pe.useNiceTranslation(),[s,i]=h.useState({title:"",type:"experiment",objective:""}),o=a=>{var l;a.preventDefault(),(l=s.title)!=null&&l.trim()&&e(s)};return n.jsxs("form",{onSubmit:o,style:{display:"flex",flexDirection:"column",gap:"16px"},children:[n.jsx("h2",{style:{margin:0},children:r("labNotebook.newEntry2","New Entry")}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:r("labNotebook.type","Type")}),n.jsx("select",{value:s.type,onChange:a=>i({...s,type:a.target.value}),style:K.input,children:Object.entries(Ue).map(([a,l])=>n.jsxs("option",{value:a,children:[l," ",a]},a))})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:r("labNotebook.title2","Title *")}),n.jsx("input",{type:"text",value:s.title,onChange:a=>i({...s,title:a.target.value}),placeholder:r("labNotebook.enterEntryTitle","Enter entry title"),style:K.input,required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:500},children:r("labNotebook.objective","Objective")}),n.jsx("textarea",{value:s.objective,onChange:a=>i({...s,objective:a.target.value}),placeholder:r("labNotebook.whatIsTheGoalOf","What is the goal of this entry?"),style:K.textarea})]}),n.jsxs("div",{style:{display:"flex",gap:"8px"},children:[n.jsx("button",{type:"submit",style:K.button,children:r("labNotebook.createEntry","Create Entry")}),n.jsx("button",{type:"button",onClick:t,style:{...K.button,backgroundColor:"var(--nice-bg-tertiary, #9e9e9e)"},children:r("labNotebook.cancel","Cancel")})]})]})}const ke=(function(){return{mean(e){return e.length===0?NaN:e.reduce((t,r)=>t+r,0)/e.length},median(e){if(e.length===0)return NaN;const t=[...e].sort((s,i)=>s-i),r=Math.floor(t.length/2);return t.length%2!==0?t[r]:(t[r-1]+t[r])/2},variance(e,t=!1){if(e.length===0)return NaN;const r=this.mean(e),s=e.map(o=>Math.pow(o-r,2)),i=t?e.length:e.length-1;return s.reduce((o,a)=>o+a,0)/i},std(e,t=!1){return Math.sqrt(this.variance(e,t))},mode(e){const t=new Map;let r=0,s=e[0];for(const i of e){const o=(t.get(i)||0)+1;t.set(i,o),o>r&&(r=o,s=i)}return s},percentile(e,t){if(e.length===0)return NaN;const r=[...e].sort((l,c)=>l-c),s=t/100*(r.length-1),i=Math.floor(s),o=Math.ceil(s),a=s-i;return r[i]*(1-a)+r[o]*a},quartiles(e){return{q1:this.percentile(e,25),q2:this.percentile(e,50),q3:this.percentile(e,75)}},skewness(e){const t=e.length;if(t<3)return NaN;const r=this.mean(e),s=this.std(e),i=e.map(o=>Math.pow((o-r)/s,3));return t/((t-1)*(t-2))*i.reduce((o,a)=>o+a,0)},kurtosis(e){const t=e.length;if(t<4)return NaN;const r=this.mean(e),s=this.std(e),o=e.map(a=>Math.pow((a-r)/s,4)).reduce((a,l)=>a+l,0);return t*(t+1)/((t-1)*(t-2)*(t-3))*o-3*Math.pow(t-1,2)/((t-2)*(t-3))},correlation(e,t){if(e.length!==t.length||e.length<2)return NaN;const r=e.length,s=this.mean(e),i=this.mean(t);let o=0,a=0,l=0;for(let c=0;c<r;c++){const u=e[c]-s,x=t[c]-i;o+=u*x,a+=u*u,l+=x*x}return o/Math.sqrt(a*l)},correlationMatrix(e){const t=Object.keys(e),r={};for(const s of t){r[s]={};for(const i of t)r[s][i]=this.correlation(e[s],e[i])}return r},covariance(e,t,r=!1){if(e.length!==t.length||e.length<2)return NaN;const s=e.length,i=this.mean(e),o=this.mean(t);let a=0;for(let l=0;l<s;l++)a+=(e[l]-i)*(t[l]-o);return a/(r?s:s-1)},linearRegression(e,t){if(e.length!==t.length||e.length<2)throw new Error("Invalid input arrays");const r=e.length,s=this.mean(e),i=this.mean(t);let o=0,a=0;for(let m=0;m<r;m++)o+=(e[m]-s)*(t[m]-i),a+=Math.pow(e[m]-s,2);const l=o/a,c=i-l*s;let u=0,x=0;for(let m=0;m<r;m++){const M=l*e[m]+c;u+=Math.pow(t[m]-i,2),x+=Math.pow(t[m]-M,2)}const y=1-x/u,f=`y = ${l.toFixed(4)}x + ${c.toFixed(4)}`;return{slope:l,intercept:c,r2:y,equation:f}},tTest(e,t){const r=e.length,s=t.length,i=this.mean(e),o=this.mean(t),a=this.variance(e),l=this.variance(t),c=Math.sqrt(a/r+l/s),u=(i-o)/c,x=Math.pow(a/r+l/s,2)/(Math.pow(a/r,2)/(r-1)+Math.pow(l/s,2)/(s-1)),y=2*(1-this.normalCDF(Math.abs(u)));return{tStatistic:u,pValue:y,degreesOfFreedom:x,meanDiff:i-o}},normalCDF(e){const t=.254829592,r=-.284496736,s=1.421413741,i=-1.453152027,o=1.061405429,a=.3275911,l=e<0?-1:1;e=Math.abs(e)/Math.sqrt(2);const c=1/(1+a*e),u=1-((((o*c+i)*c+s)*c+r)*c+t)*c*Math.exp(-e*e);return .5*(1+l*u)},chiSquare(e,t){if(e.length!==t.length)throw new Error("Arrays must have same length");let r=0;for(let o=0;o<e.length;o++)r+=Math.pow(e[o]-t[o],2)/t[o];const s=e.length-1;return{chiSquare:r,pValue:.05,degreesOfFreedom:s}},zScore(e){const t=this.mean(e),r=this.std(e);return e.map(s=>(s-t)/r)},minMaxNormalize(e,t=0,r=1){const s=Math.min(...e),o=Math.max(...e)-s;return e.map(a=>t+(a-s)/o*(r-t))},describe(e){const t=e.filter(s=>s!=null&&!isNaN(s)),r=this.quartiles(t);return{count:t.length,mean:this.mean(t),median:r.q2,std:this.std(t),min:Math.min(...t),max:Math.max(...t),q1:r.q1,q3:r.q3,skewness:this.skewness(t),kurtosis:this.kurtosis(t),mode:this.mode(t),variance:this.variance(t)}}}})();class Ke{constructor(t={}){Se(this,"config");Se(this,"datasets",new Map);Se(this,"analyses",new Map);this.config={maxRowsInMemory:1e5,...t}}async importCSV(t,r){const s=(r==null?void 0:r.delimiter)||",",i=(r==null?void 0:r.header)!==!1,o=t.split(`
43
+ `).filter(f=>f.trim());if(o.length===0)throw new Error("Empty CSV content");const a=f=>{const m=[];let M="",E=!1;for(const q of f)q==='"'?E=!E:q===s&&!E?(m.push(M.trim()),M=""):M+=q;return m.push(M.trim()),m},l=a(o[0]),c=i?l:l.map((f,m)=>`col_${m+1}`),u=i?1:0,x=[];for(let f=u;f<o.length;f++){const m=a(o[f]),M={};for(let E=0;E<c.length;E++){const q=m[E],re=parseFloat(q);M[c[E]]=!isNaN(re)&&q!==""?re:q}x.push(M)}return this.createDataset({name:(r==null?void 0:r.name)||"Imported CSV",data:x,source:{type:"csv"}})}async importJSON(t,r){const s=typeof t=="string"?JSON.parse(t):t;if(!Array.isArray(s))throw new Error("JSON must be an array of objects");return this.createDataset({name:(r==null?void 0:r.name)||"Imported JSON",data:s,source:{type:"json"}})}createDataset(t){const{name:r,data:s,description:i,source:o}=t,a=this.inferColumns(s),l={id:this.generateId(),name:r,description:i,columns:a,data:s,rowCount:s.length,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),source:o};return this.datasets.set(l.id,l),l}inferColumns(t){if(t.length===0)return[];const r=new Set;t.forEach(i=>Object.keys(i).forEach(o=>r.add(o)));const s=[];for(const i of r){const o=t.map(x=>x[i]),a=o.filter(x=>x!=null),l=new Set(a);let c="mixed";a.every(x=>typeof x=="number")?c="number":a.every(x=>typeof x=="string")?c=l.size<a.length*.5?"category":"string":a.every(x=>typeof x=="boolean")?c="boolean":a.every(x=>x instanceof Date||!isNaN(Date.parse(x)))&&(c="date");const u={name:i,type:c,nullable:o.some(x=>x==null),unique:l.size,missing:o.length-a.length};if(c==="number"){const x=a.filter(y=>typeof y=="number");u.stats=ke.describe(x)}s.push(u)}return s}runAnalysis(t,r,s={}){const i=this.datasets.get(t);if(!i)throw new Error(`Dataset not found: ${t}`);const o=performance.now();let a;switch(r){case"descriptive":a=this.descriptiveAnalysis(i,s);break;case"correlation":a=this.correlationAnalysis(i,s);break;case"regression":a=this.regressionAnalysis(i,s);break;case"ttest":a=this.tTestAnalysis(i,s);break;case"distribution":a=this.distributionAnalysis(i,s);break;default:throw new Error(`Unsupported analysis type: ${r}`)}const l=performance.now()-o,c={id:this.generateId(),datasetId:t,type:r,parameters:s,result:a,createdAt:new Date().toISOString(),executionTimeMs:l};return this.analyses.set(c.id,c),c}descriptiveAnalysis(t,r){const s=r.columns||t.columns.filter(o=>o.type==="number").map(o=>o.name),i={};for(const o of s){const a=t.data.map(l=>l[o]).filter(l=>typeof l=="number");i[o]=ke.describe(a)}return i}correlationAnalysis(t,r){const s=r.columns||t.columns.filter(o=>o.type==="number").map(o=>o.name),i={};for(const o of s)i[o]=t.data.map(a=>a[o]).filter(a=>typeof a=="number");return{matrix:ke.correlationMatrix(i),columns:s}}regressionAnalysis(t,r){const{xColumn:s,yColumn:i}=r,o=t.data.map(l=>l[s]).filter(l=>typeof l=="number"),a=t.data.map(l=>l[i]).filter(l=>typeof l=="number");return ke.linearRegression(o,a)}tTestAnalysis(t,r){const{column:s,groupColumn:i}=r,o=new Map;for(const l of t.data){const c=l[i],u=l[s];typeof u=="number"&&(o.has(c)||o.set(c,[]),o.get(c).push(u))}const a=Array.from(o.keys());if(a.length!==2)throw new Error("T-test requires exactly 2 groups");return ke.tTest(o.get(a[0]),o.get(a[1]))}distributionAnalysis(t,r){const{column:s,bins:i=10}=r,o=t.data.map(y=>y[s]).filter(y=>typeof y=="number"),a=Math.min(...o),c=(Math.max(...o)-a)/i,u=new Array(i).fill(0),x=[];for(let y=0;y<=i;y++)x.push(a+y*c);for(const y of o){const f=Math.min(Math.floor((y-a)/c),i-1);u[f]++}return{histogram:u,binEdges:x,stats:ke.describe(o)}}transform(t,r){const s=this.datasets.get(t);if(!s)throw new Error(`Dataset not found: ${t}`);let i=[...s.data];switch(r.type){case"filter":i=this.applyFilter(i,r);break;case"sort":i=this.applySort(i,r);break;case"fillna":i=this.applyFillNA(i,r);break;case"dropna":i=this.applyDropNA(i,r);break;case"normalize":i=this.applyNormalize(i,r);break;case"standardize":i=this.applyStandardize(i,r);break;default:throw new Error(`Unsupported transformation: ${r.type}`)}return this.createDataset({name:`${s.name} (transformed)`,data:i})}applyFilter(t,r){const{column:s,parameters:i}=r,{operator:o,value:a}=i;return t.filter(l=>{const c=l[s];switch(o){case"==":return c===a;case"!=":return c!==a;case">":return c>a;case">=":return c>=a;case"<":return c<a;case"<=":return c<=a;case"contains":return String(c).includes(a);case"startswith":return String(c).startsWith(a);default:return!0}})}applySort(t,r){const{column:s,parameters:i}=r,o=i.ascending!==!1;return[...t].sort((a,l)=>{const c=a[s],u=l[s];return c<u?o?-1:1:c>u?o?1:-1:0})}applyFillNA(t,r){const{column:s,parameters:i}=r,o=i.value;return t.map(a=>({...a,[s]:a[s]??o}))}applyDropNA(t,r){const s=r.columns||[r.column];return t.filter(i=>s.every(o=>i[o]!=null))}applyNormalize(t,r){const{column:s}=r,i=t.map(c=>c[s]).filter(c=>typeof c=="number"),o=Math.min(...i),l=Math.max(...i)-o;return t.map(c=>({...c,[s]:typeof c[s]=="number"?(c[s]-o)/l:c[s]}))}applyStandardize(t,r){const{column:s}=r,i=t.map(l=>l[s]).filter(l=>typeof l=="number"),o=ke.mean(i),a=ke.std(i);return t.map(l=>({...l,[s]:typeof l[s]=="number"?(l[s]-o)/a:l[s]}))}exportCSV(t){const r=this.datasets.get(t);if(!r)throw new Error(`Dataset not found: ${t}`);const s=r.columns.map(o=>o.name),i=r.data.map(o=>s.map(a=>{const l=o[a];return l==null?"":typeof l=="string"&&(l.includes(",")||l.includes('"'))?`"${l.replace(/"/g,'""')}"`:String(l)}).join(","));return[s.join(","),...i].join(`
44
+ `)}getDataset(t){return this.datasets.get(t)}listDatasets(){return Array.from(this.datasets.values())}generateId(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}}function ht(e){return new Ke(e)}function pt({service:e,className:t,style:r}){const{t:s}=pe.useNiceTranslation(),[i,o]=h.useState([]),[a,l]=h.useState(null),[c,u]=h.useState("data"),x=h.useCallback(()=>{o(e.listDatasets())},[e]),y=h.useMemo(()=>i.find(m=>m.id===a),[i,a]),f=async m=>{var q;const M=(q=m.target.files)==null?void 0:q[0];if(!M)return;const E=await M.text();M.name.endsWith(".csv")?await e.importCSV(E,{name:M.name}):M.name.endsWith(".json")&&await e.importJSON(E,{name:M.name}),x()};return n.jsxs("div",{className:t,style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:"'Inter', sans-serif",...r},children:[n.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--nice-border, #e0e0e0)",display:"flex",gap:"12px",alignItems:"center"},children:[n.jsxs("label",{style:{padding:"8px 16px",backgroundColor:"var(--nice-primary-hover, #1976d2)",color:"white",borderRadius:"4px",cursor:"pointer"},children:[s("dataAnalysis.importData","Import Data"),n.jsx("input",{type:"file",accept:".csv,.json",onChange:f,style:{display:"none"}})]}),n.jsxs("select",{value:a||"",onChange:m=>l(m.target.value||null),style:{padding:"8px 12px",borderRadius:"4px",border:"1px solid var(--nice-border, #ddd)"},children:[n.jsx("option",{value:"",children:s("dataAnalysis.selectDataset","Select dataset...")}),i.map(m=>n.jsx("option",{value:m.id,children:s("dataAnalysis.rows","{name} ({rowCount} rows)").replace("{name}",String(m.name)).replace("{rowCount}",String(m.rowCount))},m.id))]}),y&&n.jsx("div",{style:{marginLeft:"auto",display:"flex",gap:"8px"},children:["data","stats","analysis"].map(m=>n.jsx("button",{onClick:()=>u(m),style:{padding:"8px 16px",backgroundColor:c===m?"var(--nice-primary-hover, #1976d2)":"transparent",color:c===m?"white":"var(--nice-text, #333)",border:"1px solid var(--nice-border, #ddd)",borderRadius:"4px",cursor:"pointer",textTransform:"capitalize"},children:m},m))})]}),n.jsx("div",{style:{flex:1,overflow:"auto",padding:"16px"},children:y?c==="data"?n.jsx(xt,{dataset:y}):c==="stats"?n.jsx(ft,{dataset:y}):n.jsx(yt,{dataset:y,service:e}):n.jsx("div",{style:{textAlign:"center",color:"var(--nice-text-secondary, #666)",padding:"48px"},children:n.jsx("div",{style:{fontSize:"18px"},children:s("dataAnalysis.importADatasetOrSelect","Import a dataset or select an existing one to begin")})})})]})}function xt({dataset:e}){const{t}=pe.useNiceTranslation(),[r,s]=h.useState(0),i=50,o=Math.ceil(e.rowCount/i),a=e.data.slice(r*i,(r+1)*i);return n.jsxs("div",{children:[n.jsx("div",{style:{overflowX:"auto",marginBottom:"16px"},children:n.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{backgroundColor:"var(--nice-bg-secondary, #f5f5f5)"},children:[n.jsx("th",{style:{padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)",textAlign:"left"},children:"#"}),e.columns.map(l=>n.jsxs("th",{style:{padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)",textAlign:"left"},children:[l.name,n.jsx("div",{style:{fontSize:"10px",color:"var(--nice-text-secondary, #666)",fontWeight:"normal"},children:l.type})]},l.name))]})}),n.jsx("tbody",{children:a.map((l,c)=>n.jsxs("tr",{children:[n.jsx("td",{style:{padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)",color:"var(--nice-text-secondary, #666)"},children:r*i+c+1}),e.columns.map(u=>n.jsx("td",{style:{padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)"},children:l[u.name]!=null?String(l[u.name]):n.jsx("span",{style:{color:"var(--nice-text-secondary, #ccc)"},children:t("dataAnalysis.null","null")})},u.name))]},c))})]})}),n.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center",justifyContent:"center"},children:[n.jsx("button",{onClick:()=>s(0),disabled:r===0,children:t("dataAnalysis.first","First")}),n.jsx("button",{onClick:()=>s(r-1),disabled:r===0,children:t("dataAnalysis.prev","Prev")}),n.jsx("span",{children:t("dataAnalysis.pageOf","Page {page} of {totalPages}").replace("{page}",String(r+1)).replace("{totalPages}",String(o))}),n.jsx("button",{onClick:()=>s(r+1),disabled:r>=o-1,children:t("dataAnalysis.next","Next")}),n.jsx("button",{onClick:()=>s(o-1),disabled:r>=o-1,children:t("dataAnalysis.last","Last")})]})]})}function ft({dataset:e}){const t=e.columns.filter(r=>r.type==="number");return n.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(300px, 1fr))",gap:"16px"},children:t.map(r=>n.jsxs("div",{style:{padding:"16px",backgroundColor:"var(--nice-bg-secondary, #f9f9f9)",borderRadius:"8px"},children:[n.jsx("h3",{style:{margin:"0 0 12px 0"},children:r.name}),r.stats&&n.jsx("table",{style:{width:"100%",fontSize:"13px"},children:n.jsx("tbody",{children:Object.entries(r.stats).map(([s,i])=>n.jsxs("tr",{children:[n.jsx("td",{style:{padding:"4px 0",color:"var(--nice-text-secondary, #666)"},children:s}),n.jsx("td",{style:{padding:"4px 0",textAlign:"right",fontFamily:"monospace"},children:typeof i=="number"?i.toFixed(4):String(i)})]},s))})})]},r.name))})}function yt({dataset:e,service:t}){const{t:r}=pe.useNiceTranslation(),[s,i]=h.useState("descriptive"),[o,a]=h.useState(null),l=()=>{const c=t.runAnalysis(e.id,s,{});a(c)};return n.jsxs("div",{children:[n.jsxs("div",{style:{display:"flex",gap:"12px",marginBottom:"24px"},children:[n.jsxs("select",{value:s,onChange:c=>i(c.target.value),style:{padding:"8px 12px",borderRadius:"4px",border:"1px solid var(--nice-border, #ddd)"},children:[n.jsx("option",{value:"descriptive",children:r("dataAnalysis.descriptiveStatistics","Descriptive Statistics")}),n.jsx("option",{value:"correlation",children:r("dataAnalysis.correlationMatrix","Correlation Matrix")}),n.jsx("option",{value:"distribution",children:r("dataAnalysis.distributionAnalysis","Distribution Analysis")})]}),n.jsx("button",{onClick:l,style:{padding:"8px 16px",backgroundColor:"var(--nice-primary-hover, #1976d2)",color:"white",border:"none",borderRadius:"4px",cursor:"pointer"},children:r("dataAnalysis.runAnalysis","Run Analysis")})]}),o&&n.jsxs("div",{style:{padding:"16px",backgroundColor:"var(--nice-bg-secondary, #f9f9f9)",borderRadius:"8px"},children:[n.jsx("h3",{style:{margin:"0 0 12px 0"},children:r("dataAnalysis.resultsMs","Results ({executionTimeMs}ms)").replace("{executionTimeMs}",String(o.executionTimeMs.toFixed(2)))}),n.jsx("pre",{style:{margin:0,overflow:"auto",fontSize:"12px"},children:JSON.stringify(o.result,null,2)})]})]})}const Le={apa:e=>{const t=mt(e.authors),r=e.year?` (${e.year}).`:".",s=e.title;let i="";e.type==="article"&&e.journal?(i=` *${e.journal}*`,e.volume&&(i+=`, *${e.volume}*`),e.issue&&(i+=`(${e.issue})`),e.pages&&(i+=`, ${e.pages}`),i+="."):e.type==="book"&&(i=e.publisher?` ${e.publisher}.`:"");const o=e.doi?` https://doi.org/${e.doi}`:"";return`${t}${r} ${s}.${i}${o}`},mla:e=>{const t=Ze(e.authors),r=`"${e.title}."`;let s="";return e.type==="article"&&e.journal&&(s=` *${e.journal}*`,e.volume&&(s+=`, vol. ${e.volume}`),e.issue&&(s+=`, no. ${e.issue}`),e.year&&(s+=`, ${e.year}`),e.pages&&(s+=`, pp. ${e.pages}`),s+="."),`${t} ${r}${s}`},chicago:e=>{const t=gt(e.authors),r=`"${e.title}."`;let s="";return e.type==="article"&&e.journal&&(s=` *${e.journal}*`,e.volume&&(s+=` ${e.volume}`),e.issue&&(s+=`, no. ${e.issue}`),e.year&&(s+=` (${e.year})`),e.pages&&(s+=`: ${e.pages}`),s+="."),`${t} ${r}${s}`},harvard:e=>{const t=bt(e.authors),r=e.year?` (${e.year})`:"",s=`'${e.title}'`;let i="";return e.type==="article"&&e.journal&&(i=`, *${e.journal}*`,e.volume&&(i+=`, ${e.volume}`),e.issue&&(i+=`(${e.issue})`),e.pages&&(i+=`, pp. ${e.pages}`),i+="."),`${t}${r} ${s}${i}`},ieee:e=>{const t=vt(e.authors),r=`"${e.title},"`;let s="";return e.type==="article"&&e.journal&&(s=` *${e.journal}*`,e.volume&&(s+=`, vol. ${e.volume}`),e.issue&&(s+=`, no. ${e.issue}`),e.pages&&(s+=`, pp. ${e.pages}`),e.year&&(s+=`, ${e.year}`),s+="."),`${t} ${r}${s}`},vancouver:e=>{const t=jt(e.authors),r=e.title;let s="";return e.type==="article"&&e.journal&&(s=` ${e.journal}`,e.year&&(s+=`. ${e.year}`),e.volume&&(s+=`;${e.volume}`),e.issue&&(s+=`(${e.issue})`),e.pages&&(s+=`:${e.pages}`),s+="."),`${t}. ${r}.${s}`},nature:e=>{const t=Je(e.authors),r=e.title;let s="";return e.type==="article"&&e.journal&&(s=` *${e.journal}*`,e.volume&&(s+=` **${e.volume}**`),e.pages&&(s+=`, ${e.pages}`),e.year&&(s+=` (${e.year})`),s+="."),`${t} ${r}.${s}`},science:e=>{const t=$t(e.authors),r=e.title;let s="";return e.type==="article"&&e.journal&&(s=` *${e.journal}*`,e.volume&&(s+=` **${e.volume}**`),e.pages&&(s+=`, ${e.pages}`),e.year&&(s+=` (${e.year})`),s+="."),`${t}, ${r}.${s}`},bibtex:e=>{const t=Mt(e),r=e.type==="article"?"article":e.type==="book"?"book":"misc";let i=` author = {${e.authors.map(o=>`${o.family}, ${o.given}`).join(" and ")}},
45
45
  `;return i+=` title = {${e.title}},
46
46
  `,e.year&&(i+=` year = {${e.year}},
47
47
  `),e.journal&&(i+=` journal = {${e.journal}},
@@ -52,21 +52,22 @@
52
52
  `),e.doi&&(i+=` doi = {${e.doi}},
53
53
  `),e.isbn&&(i+=` isbn = {${e.isbn}},
54
54
  `),`@${r}{${t},
55
- ${i}}`}};function ft(e){if(e.length===0)return"";if(e.length===1)return`${e[0].family}, ${e[0].given.charAt(0)}.`;if(e.length===2)return`${e[0].family}, ${e[0].given.charAt(0)}., & ${e[1].family}, ${e[1].given.charAt(0)}.`;if(e.length<=7){const s=e.slice(0,-1).map(o=>`${o.family}, ${o.given.charAt(0)}.`).join(", "),i=e[e.length-1];return`${s}, & ${i.family}, ${i.given.charAt(0)}.`}const t=e.slice(0,6).map(s=>`${s.family}, ${s.given.charAt(0)}.`).join(", "),r=e[e.length-1];return`${t}, ... ${r.family}, ${r.given.charAt(0)}.`}function Ue(e){return e.length===0?"":e.length===1?`${e[0].family}, ${e[0].given}.`:e.length===2?`${e[0].family}, ${e[0].given}, and ${e[1].given} ${e[1].family}.`:`${e[0].family}, ${e[0].given}, et al.`}function mt(e){return Ue(e)}function yt(e){return e.length===0?"":e.length===1?`${e[0].family}, ${e[0].given.charAt(0)}.`:e.length===2?`${e[0].family}, ${e[0].given.charAt(0)}. and ${e[1].family}, ${e[1].given.charAt(0)}.`:`${e[0].family}, ${e[0].given.charAt(0)}. et al.`}function gt(e){return e.length===0?"":e.map(t=>`${t.given.charAt(0)}. ${t.family}`).join(", ")}function bt(e){if(e.length===0)return"";const t=e.slice(0,6).map(r=>`${r.family} ${r.given.charAt(0)}`);return e.length>6?t.join(", ")+", et al":t.join(", ")}function Ze(e){if(e.length===0)return"";if(e.length<=5){const t=e.map(s=>`${s.family}, ${s.given.charAt(0)}.`),r=t.pop();return t.length>0?`${t.join(", ")} & ${r}`:r}return`${e[0].family}, ${e[0].given.charAt(0)}. et al.`}function vt(e){return Ze(e)}function jt(e){var i;const t=((i=e.authors[0])==null?void 0:i.family.toLowerCase())||"unknown",r=e.year||"0000",s=e.title.split(" ")[0].toLowerCase().replace(/[^a-z]/g,"");return`${t}${r}${s}`}class Ke{constructor(t={}){ye(this,"config");ye(this,"citations",new Map);ye(this,"collections",new Map);this.config=t,this.collections.set("all",{id:"all",name:"All References",citationCount:0,createdAt:new Date().toISOString()})}addCitation(t){const r={id:this.generateId(),type:t.type||"misc",title:t.title||"Untitled",authors:t.authors||[],year:t.year,month:t.month,day:t.day,journal:t.journal,volume:t.volume,issue:t.issue,pages:t.pages,publisher:t.publisher,edition:t.edition,doi:t.doi,isbn:t.isbn,issn:t.issn,pmid:t.pmid,arxiv:t.arxiv,url:t.url,abstract:t.abstract,keywords:t.keywords,language:t.language,accessed:t.accessed,booktitle:t.booktitle,conference:t.conference,location:t.location,school:t.school,degree:t.degree,notes:t.notes,tags:t.tags||[],collections:t.collections||["all"],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),sourceDatabase:t.sourceDatabase};return this.citations.set(r.id,r),this.updateCollectionCounts(),r}updateCitation(t,r){const s=this.citations.get(t);if(!s)throw new Error(`Citation not found: ${t}`);const i={...s,...r,id:s.id,createdAt:s.createdAt,updatedAt:new Date().toISOString()};return this.citations.set(t,i),this.updateCollectionCounts(),i}deleteCitation(t){this.citations.delete(t),this.updateCollectionCounts()}getCitation(t){return this.citations.get(t)}searchCitations(t,r){const s=t.toLowerCase();return Array.from(this.citations.values()).filter(i=>{var o,a,l,c,h;return r!=null&&r.collection&&!((o=i.collections)!=null&&o.includes(r.collection))||r!=null&&r.type&&i.type!==r.type||r!=null&&r.year&&i.year!==r.year||(a=r==null?void 0:r.tags)!=null&&a.length&&!r.tags.some(p=>{var f;return(f=i.tags)==null?void 0:f.includes(p)})?!1:!!(i.title.toLowerCase().includes(s)||i.authors.some(p=>p.family.toLowerCase().includes(s)||p.given.toLowerCase().includes(s))||(l=i.journal)!=null&&l.toLowerCase().includes(s)||(c=i.abstract)!=null&&c.toLowerCase().includes(s)||(h=i.doi)!=null&&h.toLowerCase().includes(s))})}listCitations(t){const r=Array.from(this.citations.values());return t&&t!=="all"?r.filter(s=>{var i;return(i=s.collections)==null?void 0:i.includes(t)}):r}createCollection(t){const r={id:this.generateId(),name:t.name||"Untitled Collection",description:t.description,parentId:t.parentId,color:t.color,citationCount:0,createdAt:new Date().toISOString()};return this.collections.set(r.id,r),r}listCollections(){return Array.from(this.collections.values())}formatCitation(t,r){const s=this.citations.get(t);if(!s)throw new Error(`Citation not found: ${t}`);return _e[r](s)}formatBibliography(t,r){return t.map((i,o)=>{const a=this.citations.get(i);if(!a)return null;const l=_e[r](a);return r==="bibtex"?l:["ieee","vancouver"].includes(r)?`[${o+1}] ${l}`:l}).filter(Boolean).join(`
55
+ ${i}}`}};function mt(e){if(e.length===0)return"";if(e.length===1)return`${e[0].family}, ${e[0].given.charAt(0)}.`;if(e.length===2)return`${e[0].family}, ${e[0].given.charAt(0)}., & ${e[1].family}, ${e[1].given.charAt(0)}.`;if(e.length<=7){const s=e.slice(0,-1).map(o=>`${o.family}, ${o.given.charAt(0)}.`).join(", "),i=e[e.length-1];return`${s}, & ${i.family}, ${i.given.charAt(0)}.`}const t=e.slice(0,6).map(s=>`${s.family}, ${s.given.charAt(0)}.`).join(", "),r=e[e.length-1];return`${t}, ... ${r.family}, ${r.given.charAt(0)}.`}function Ze(e){return e.length===0?"":e.length===1?`${e[0].family}, ${e[0].given}.`:e.length===2?`${e[0].family}, ${e[0].given}, and ${e[1].given} ${e[1].family}.`:`${e[0].family}, ${e[0].given}, et al.`}function gt(e){return Ze(e)}function bt(e){return e.length===0?"":e.length===1?`${e[0].family}, ${e[0].given.charAt(0)}.`:e.length===2?`${e[0].family}, ${e[0].given.charAt(0)}. and ${e[1].family}, ${e[1].given.charAt(0)}.`:`${e[0].family}, ${e[0].given.charAt(0)}. et al.`}function vt(e){return e.length===0?"":e.map(t=>`${t.given.charAt(0)}. ${t.family}`).join(", ")}function jt(e){if(e.length===0)return"";const t=e.slice(0,6).map(r=>`${r.family} ${r.given.charAt(0)}`);return e.length>6?t.join(", ")+", et al":t.join(", ")}function Je(e){if(e.length===0)return"";if(e.length<=5){const t=e.map(s=>`${s.family}, ${s.given.charAt(0)}.`),r=t.pop();return t.length>0?`${t.join(", ")} & ${r}`:r}return`${e[0].family}, ${e[0].given.charAt(0)}. et al.`}function $t(e){return Je(e)}function Mt(e){var i;const t=((i=e.authors[0])==null?void 0:i.family.toLowerCase())||"unknown",r=e.year||"0000",s=e.title.split(" ")[0].toLowerCase().replace(/[^a-z]/g,"");return`${t}${r}${s}`}class Ge{constructor(t={}){Se(this,"config");Se(this,"citations",new Map);Se(this,"collections",new Map);this.config=t,this.collections.set("all",{id:"all",name:"All References",citationCount:0,createdAt:new Date().toISOString()})}addCitation(t){const r={id:this.generateId(),type:t.type||"misc",title:t.title||"Untitled",authors:t.authors||[],year:t.year,month:t.month,day:t.day,journal:t.journal,volume:t.volume,issue:t.issue,pages:t.pages,publisher:t.publisher,edition:t.edition,doi:t.doi,isbn:t.isbn,issn:t.issn,pmid:t.pmid,arxiv:t.arxiv,url:t.url,abstract:t.abstract,keywords:t.keywords,language:t.language,accessed:t.accessed,booktitle:t.booktitle,conference:t.conference,location:t.location,school:t.school,degree:t.degree,notes:t.notes,tags:t.tags||[],collections:t.collections||["all"],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),sourceDatabase:t.sourceDatabase};return this.citations.set(r.id,r),this.updateCollectionCounts(),r}updateCitation(t,r){const s=this.citations.get(t);if(!s)throw new Error(`Citation not found: ${t}`);const i={...s,...r,id:s.id,createdAt:s.createdAt,updatedAt:new Date().toISOString()};return this.citations.set(t,i),this.updateCollectionCounts(),i}deleteCitation(t){this.citations.delete(t),this.updateCollectionCounts()}getCitation(t){return this.citations.get(t)}searchCitations(t,r){const s=t.toLowerCase();return Array.from(this.citations.values()).filter(i=>{var o,a,l,c,u;return r!=null&&r.collection&&!((o=i.collections)!=null&&o.includes(r.collection))||r!=null&&r.type&&i.type!==r.type||r!=null&&r.year&&i.year!==r.year||(a=r==null?void 0:r.tags)!=null&&a.length&&!r.tags.some(x=>{var y;return(y=i.tags)==null?void 0:y.includes(x)})?!1:!!(i.title.toLowerCase().includes(s)||i.authors.some(x=>x.family.toLowerCase().includes(s)||x.given.toLowerCase().includes(s))||(l=i.journal)!=null&&l.toLowerCase().includes(s)||(c=i.abstract)!=null&&c.toLowerCase().includes(s)||(u=i.doi)!=null&&u.toLowerCase().includes(s))})}listCitations(t){const r=Array.from(this.citations.values());return t&&t!=="all"?r.filter(s=>{var i;return(i=s.collections)==null?void 0:i.includes(t)}):r}createCollection(t){const r={id:this.generateId(),name:t.name||"Untitled Collection",description:t.description,parentId:t.parentId,color:t.color,citationCount:0,createdAt:new Date().toISOString()};return this.collections.set(r.id,r),r}listCollections(){return Array.from(this.collections.values())}formatCitation(t,r){const s=this.citations.get(t);if(!s)throw new Error(`Citation not found: ${t}`);return Le[r](s)}formatBibliography(t,r){return t.map((i,o)=>{const a=this.citations.get(i);if(!a)return null;const l=Le[r](a);return r==="bibtex"?l:["ieee","vancouver"].includes(r)?`[${o+1}] ${l}`:l}).filter(Boolean).join(`
56
56
 
57
- `)}importBibtex(t){const r=[],s=/@(\w+)\{([^,]+),([^@]+)\}/g;let i;for(;(i=s.exec(t))!==null;){const o=i[1].toLowerCase(),a=this.parseBibtexFields(i[3]),l=this.addCitation({type:o==="article"?"article":o==="book"?"book":"misc",title:a.title||"",authors:this.parseBibtexAuthors(a.author||""),year:a.year?parseInt(a.year,10):void 0,journal:a.journal,volume:a.volume,issue:a.number,pages:a.pages,publisher:a.publisher,doi:a.doi,isbn:a.isbn,url:a.url,abstract:a.abstract});r.push(l)}return r}parseBibtexFields(t){const r={},s=/(\w+)\s*=\s*\{([^}]*)\}/g;let i;for(;(i=s.exec(t))!==null;)r[i[1].toLowerCase()]=i[2].trim();return r}parseBibtexAuthors(t){return t.split(" and ").map(r=>{const s=r.trim().split(",");if(s.length>=2)return{family:s[0].trim(),given:s[1].trim()};const i=r.trim().split(" ");return{given:i.slice(0,-1).join(" "),family:i[i.length-1]}})}exportBibtex(t){return(t?t.map(s=>this.citations.get(s)).filter(Boolean):Array.from(this.citations.values())).map(s=>_e.bibtex(s)).join(`
57
+ `)}importBibtex(t){const r=[],s=/@(\w+)\{([^,]+),([^@]+)\}/g;let i;for(;(i=s.exec(t))!==null;){const o=i[1].toLowerCase(),a=this.parseBibtexFields(i[3]),l=this.addCitation({type:o==="article"?"article":o==="book"?"book":"misc",title:a.title||"",authors:this.parseBibtexAuthors(a.author||""),year:a.year?parseInt(a.year,10):void 0,journal:a.journal,volume:a.volume,issue:a.number,pages:a.pages,publisher:a.publisher,doi:a.doi,isbn:a.isbn,url:a.url,abstract:a.abstract});r.push(l)}return r}parseBibtexFields(t){const r={},s=/(\w+)\s*=\s*\{([^}]*)\}/g;let i;for(;(i=s.exec(t))!==null;)r[i[1].toLowerCase()]=i[2].trim();return r}parseBibtexAuthors(t){return t.split(" and ").map(r=>{const s=r.trim().split(",");if(s.length>=2)return{family:s[0].trim(),given:s[1].trim()};const i=r.trim().split(" ");return{given:i.slice(0,-1).join(" "),family:i[i.length-1]}})}exportBibtex(t){return(t?t.map(s=>this.citations.get(s)).filter(Boolean):Array.from(this.citations.values())).map(s=>Le.bibtex(s)).join(`
58
58
 
59
- `)}async searchDatabase(t,r,s=10){var i,o;try{if(t==="crossref")return await this.searchCrossref(r,s);if(t==="pubmed")return await this.searchPubMed(r,s);throw new Error(`Unknown database: ${t}`)}catch(a){return(o=(i=this.config).onError)==null||o.call(i,a),{source:t,total:0,results:[]}}}async searchCrossref(t,r){const s=new URLSearchParams({query:t,rows:String(r)});this.config.crossrefEmail&&s.set("mailto",this.config.crossrefEmail);const i=await fetch(`https://api.crossref.org/works?${s}`);if(!i.ok)throw new Error(`Crossref API error: ${i.status}`);const o=await i.json(),a=o.message.items.map(l=>{var c,h,p,f,m,j;return{type:"article",title:((c=l.title)==null?void 0:c[0])||"",authors:(l.author||[]).map(M=>({given:M.given||"",family:M.family||"",orcid:M.ORCID})),year:(f=(p=(h=l.published)==null?void 0:h["date-parts"])==null?void 0:p[0])==null?void 0:f[0],journal:(m=l["container-title"])==null?void 0:m[0],volume:l.volume,issue:l.issue,pages:l.page,doi:l.DOI,issn:(j=l.ISSN)==null?void 0:j[0],publisher:l.publisher,abstract:l.abstract,sourceDatabase:"crossref"}});return{source:"crossref",total:o.message["total-results"],results:a}}async searchPubMed(t,r){const s=`https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=${encodeURIComponent(t)}&retmax=${r}&retmode=json`,i=await fetch(s);if(!i.ok)throw new Error(`PubMed API error: ${i.status}`);const o=await i.json(),a=o.esearchresult.idlist;if(a.length===0)return{source:"pubmed",total:0,results:[]};const l=`https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=${a.join(",")}&retmode=json`,c=await fetch(l);if(!c.ok)throw new Error(`PubMed API error: ${c.status}`);const h=await c.json(),p=a.map(f=>{var j;const m=h.result[f];return{type:"article",title:m.title||"",authors:(m.authors||[]).map(M=>{const E=M.name.split(" ");return{family:E.pop()||"",given:E.join(" ")}}),year:m.pubdate?parseInt(m.pubdate.split(" ")[0],10):void 0,journal:m.source,volume:m.volume,issue:m.issue,pages:m.pages,pmid:f,doi:(j=m.elocationid)==null?void 0:j.replace("doi: ",""),sourceDatabase:"pubmed"}});return{source:"pubmed",total:parseInt(o.esearchresult.count,10),results:p}}async fetchByDOI(t){var r,s,i,o,a;try{const l=await fetch(`https://api.crossref.org/works/${encodeURIComponent(t)}`);if(!l.ok)return null;const h=(await l.json()).message;return this.addCitation({type:"article",title:((r=h.title)==null?void 0:r[0])||"",authors:(h.author||[]).map(p=>({given:p.given||"",family:p.family||"",orcid:p.ORCID})),year:(o=(i=(s=h.published)==null?void 0:s["date-parts"])==null?void 0:i[0])==null?void 0:o[0],journal:(a=h["container-title"])==null?void 0:a[0],volume:h.volume,issue:h.issue,pages:h.page,doi:h.DOI,publisher:h.publisher,abstract:h.abstract,sourceDatabase:"crossref"})}catch{return null}}updateCollectionCounts(){for(const t of this.collections.values())t.id==="all"?t.citationCount=this.citations.size:t.citationCount=Array.from(this.citations.values()).filter(r=>{var s;return(s=r.collections)==null?void 0:s.includes(t.id)}).length}generateId(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}}function $t(e){return new Ke(e)}const Je=u.createContext(null);function Re(){const e=u.useContext(Je);if(!e)throw new Error("useCitation must be used within CitationProvider");return e}const ce={container:{display:"flex",height:"100%",fontFamily:"'Inter', sans-serif",fontSize:"14px"},sidebar:{width:"240px",backgroundColor:"var(--nice-bg-secondary, #f5f5f5)",borderRight:"1px solid var(--nice-border, #e0e0e0)",display:"flex",flexDirection:"column"},main:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},toolbar:{padding:"12px 16px",borderBottom:"1px solid var(--nice-border, #e0e0e0)",display:"flex",gap:"12px",alignItems:"center"},list:{flex:1,overflow:"auto"},listItem:{padding:"12px 16px",borderBottom:"1px solid var(--nice-border, #eee)",cursor:"pointer"},detail:{width:"400px",borderLeft:"1px solid var(--nice-border, #e0e0e0)",overflow:"auto",padding:"16px"},input:{padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)",borderRadius:"4px",fontSize:"14px"},button:{padding:"8px 16px",backgroundColor:"var(--nice-primary-hover, #1976d2)",color:"white",border:"none",borderRadius:"4px",cursor:"pointer"}};function Mt({service:e,className:t,style:r}){const[s,i]=u.useState([]),[o,a]=u.useState([]),[l,c]=u.useState("all"),[h,p]=u.useState(null),[f,m]=u.useState(""),[j,M]=u.useState("apa"),E=u.useCallback(()=>{i(e.listCitations(l)),a(e.listCollections())},[e,l]),U=u.useMemo(()=>f?e.searchCitations(f,{collection:l}):s,[s,f,l,e]),Q=u.useMemo(()=>s.find(_=>_.id===h),[s,h]),P={service:e,citations:s,collections:o,selectedCollection:l,setSelectedCollection:c,selectedCitation:h,setSelectedCitation:p,searchQuery:f,setSearchQuery:m,citationStyle:j,setCitationStyle:M,refresh:E};return n.jsx(Je.Provider,{value:P,children:n.jsxs("div",{className:t,style:{...ce.container,...r},children:[n.jsxs("div",{style:ce.sidebar,children:[n.jsx("div",{style:{padding:"16px",fontWeight:600},children:"Collections"}),o.map(_=>n.jsxs("div",{onClick:()=>{c(_.id),E()},style:{...ce.listItem,backgroundColor:l===_.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsx("div",{children:_.name}),n.jsxs("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:[_.citationCount," items"]})]},_.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:_=>m(_.target.value),style:{...ce.input,flex:1}}),n.jsxs("select",{value:j,onChange:_=>M(_.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(wt,{})]}),n.jsxs("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[n.jsxs("div",{style:ce.list,children:[U.map(_=>n.jsxs("div",{onClick:()=>p(_.id),style:{...ce.listItem,backgroundColor:h===_.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsx("div",{style:{fontWeight:500,marginBottom:"4px"},children:_.title}),n.jsxs("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:[_.authors.map(J=>J.family).join(", "),_.year&&` (${_.year})`]}),_.journal&&n.jsx("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #888)",fontStyle:"italic"},children:_.journal})]},_.id)),U.length===0&&n.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--nice-text-secondary, #666)"},children:"No references found"})]}),Q&&n.jsx("div",{style:ce.detail,children:n.jsx(St,{citation:Q})})]})]})]})})}function wt(){const{service:e,refresh:t}=Re(),[r,s]=u.useState(!1),[i,o]=u.useState(""),[a,l]=u.useState(!1),c=async()=>{if(i.trim()){l(!0);try{await e.fetchByDOI(i.trim()),t(),o(""),s(!1)}finally{l(!1)}}};return n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>s(!0),style:ce.button,children:"+ Add Reference"}),r&&n.jsx("div",{style:{position:"fixed",inset:0,backgroundColor:"var(--nice-overlay-50, rgba(0, 0, 0, 0.5))",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},onClick:()=>s(!1),children:n.jsxs("div",{style:{backgroundColor:"white",padding:"24px",borderRadius:"8px",width:"400px"},onClick:h=>h.stopPropagation(),children:[n.jsx("h3",{style:{margin:"0 0 16px 0"},children:"Add Reference by DOI"}),n.jsx("input",{type:"text",value:i,onChange:h=>o(h.target.value),placeholder:"Enter DOI (e.g., 10.1000/xyz123)",style:{...ce.input,width:"100%",marginBottom:"16px"}}),n.jsxs("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[n.jsx("button",{onClick:()=>s(!1),style:{...ce.button,backgroundColor:"var(--nice-bg-tertiary, #9e9e9e)"},children:"Cancel"}),n.jsx("button",{onClick:c,disabled:a,style:ce.button,children:a?"Loading...":"Add"})]})]})})]})}function St({citation:e}){const{service:t,citationStyle:r}=Re(),[s,i]=u.useState(!1),o=u.useMemo(()=>t.formatCitation(e.id,r),[t,e.id,r]),a=()=>{navigator.clipboard.writeText(o),i(!0),setTimeout(()=>i(!1),2e3)};return n.jsxs("div",{children:[n.jsx("h2",{style:{margin:"0 0 8px 0",fontSize:"18px"},children:e.title}),n.jsx("div",{style:{color:"var(--nice-text-secondary, #666)",marginBottom:"16px"},children:e.authors.map(l=>`${l.given} ${l.family}`).join(", ")}),n.jsxs("div",{style:{marginBottom:"16px"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"8px"},children:[n.jsxs("strong",{children:["Formatted (",r.toUpperCase(),")"]}),n.jsx("button",{onClick:a,style:{...ce.button,padding:"4px 8px",fontSize:"12px"},children:s?"Copied!":"Copy"})]}),n.jsx("div",{style:{padding:"12px",backgroundColor:"var(--nice-bg-secondary, #f5f5f5)",borderRadius:"4px",whiteSpace:"pre-wrap",fontSize:"13px"},dangerouslySetInnerHTML:{__html:o.replace(/\*([^*]+)\*/g,"<em>$1</em>")}})]}),n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px",fontSize:"13px"},children:[e.journal&&n.jsxs("div",{children:[n.jsx("strong",{children:"Journal:"})," ",e.journal]}),e.year&&n.jsxs("div",{children:[n.jsx("strong",{children:"Year:"})," ",e.year]}),e.volume&&n.jsxs("div",{children:[n.jsx("strong",{children:"Volume:"})," ",e.volume,e.issue&&`(${e.issue})`]}),e.pages&&n.jsxs("div",{children:[n.jsx("strong",{children:"Pages:"})," ",e.pages]}),e.doi&&n.jsxs("div",{children:[n.jsx("strong",{children:"DOI:"})," ",n.jsx("a",{href:`https://doi.org/${e.doi}`,target:"_blank",rel:"noopener noreferrer",children:e.doi})]}),e.pmid&&n.jsxs("div",{children:[n.jsx("strong",{children:"PMID:"})," ",n.jsx("a",{href:`https://pubmed.ncbi.nlm.nih.gov/${e.pmid}`,target:"_blank",rel:"noopener noreferrer",children:e.pmid})]}),e.abstract&&n.jsxs("div",{style:{marginTop:"8px"},children:[n.jsx("strong",{children:"Abstract:"}),n.jsx("p",{style:{margin:"8px 0 0 0",color:"var(--nice-text, #444)"},children:e.abstract})]})]})]})}const Ct=[],kt={series:[],xAxes:[],yAxes:[],annotations:[],selectedSeries:[],zoom:{x:null,y:null},cursor:null,hoveredPoint:null};function Se(e){return e.reduce((t,r)=>t+r,0)/e.length}function Dt(e){const t=[...e].sort((s,i)=>s-i),r=Math.floor(t.length/2);return t.length%2?t[r]:(t[r-1]+t[r])/2}function ze(e){const t=Se(e),r=e.map(s=>Math.pow(s-t,2));return Math.sqrt(Se(r))}function At(e){return ze(e)/Math.sqrt(e.length)}function Nt(e){const t=Se(e),r=At(e),s=1.96;return[t-s*r,t+s*r]}function zt(e){const t=e.length,r=e.map(M=>typeof M.x=="number"?M.x:0),s=e.map(M=>M.y),i=r.reduce((M,E)=>M+E,0),o=s.reduce((M,E)=>M+E,0),a=r.reduce((M,E,U)=>M+E*s[U],0),l=r.reduce((M,E)=>M+E*E,0),c=(t*a-i*o)/(t*l-i*i),h=(o-c*i)/t,p=o/t,f=s.reduce((M,E)=>M+Math.pow(E-p,2),0),j=1-s.reduce((M,E,U)=>M+Math.pow(E-(c*r[U]+h),2),0)/f;return{slope:c,intercept:h,r2:j}}function It(e,t){const r=Se(e),s=Se(t),i=ze(e)**2,o=ze(t)**2,a=e.length,l=t.length,c=((a-1)*i+(l-1)*o)/(a+l-2),h=Math.sqrt(c*(1/a+1/l)),p=(r-s)/h,f=Math.exp(-.717*Math.abs(p)-.416*p*p);return{t:p,p:f,significant:f<.05}}function Le(e,t,r,s=5){const o=(t-e)/(s-1);return Array.from({length:s},(a,l)=>e+l*o)}function Te(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 Et({series:e=Ct,title:t,subtitle:r,width:s="100%",height:i=400,type:o="scatter",xAxis:a,yAxis:l,statOverlays:c=[],annotations:h=[],legend:p={show:!0,position:"top",orientation:"horizontal",interactive:!0},tooltip:f={enabled:!0,mode:"point"},zoom:m={enabled:!0,mode:"xy",wheel:!0,drag:!0,resetButton:!0},export:j,statisticalTests:M=[],gridLines:E=!0,aspectRatio:U,animation:Q=!0,theme:P="light",onPointClick:_,onPointHover:J,onZoomChange:ne,onAnnotationChange:q,className:ae,style:de}){const re=u.useRef(null);u.useRef(null);const[H,X]=u.useState({...kt,series:e,annotations:h}),[oe,le]=u.useState({width:0,height:0}),[pe,fe]=u.useState({x:null,y:null}),[W,V]=u.useState(null),[se,Z]=u.useState(new Set(e.map(d=>d.id))),S=u.useMemo(()=>{const d=e.filter($=>se.has($.id)&&$.visible!==!1);if(d.length===0)return{xMin:0,xMax:1,yMin:0,yMax:1};let g=1/0,w=-1/0,I=1/0,z=-1/0;for(const $ of d)for(const D of $.data){const L=typeof D.x=="number"?D.x:0;if(g=Math.min(g,L),w=Math.max(w,L),I=Math.min(I,D.y),z=Math.max(z,D.y),D.error){const[O,ie]=Array.isArray(D.error)?D.error:[-D.error,D.error];I=Math.min(I,D.y+O),z=Math.max(z,D.y+ie)}}const R=(w-g)*.05||.5,y=(z-I)*.05||.5;return{xMin:g-R,xMax:w+R,yMin:I-y,yMax:z+y}},[e,se]),K=u.useMemo(()=>{const d={};for(const g of e){if(!se.has(g.id))continue;const w=g.data.map(I=>I.y);c.includes("mean")&&(d[`${g.id}_mean`]=Se(w)),c.includes("median")&&(d[`${g.id}_median`]=Dt(w)),c.includes("std-dev")&&(d[`${g.id}_std`]=ze(w)),c.includes("regression")&&(d[`${g.id}_regression`]=zt(g.data)),c.includes("confidence-interval")&&(d[`${g.id}_ci95`]=Nt(w))}return d},[e,se,c]),G=u.useMemo(()=>M.map(d=>{if(d.type==="t-test"&&d.series.length===2){const g=e.find(I=>I.id===d.series[0]),w=e.find(I=>I.id===d.series[1]);if(g&&w){const I=It(g.data.map(z=>z.y),w.data.map(z=>z.y));return{...d,result:{statistic:I.t,pValue:I.p,significant:I.significant,interpretation:I.significant?`Significant difference (p = ${I.p.toFixed(4)})`:`No significant difference (p = ${I.p.toFixed(4)})`}}}}return d}),[M,e]),ee=u.useCallback(d=>{Z(g=>{const w=new Set(g);return w.has(d)?w.delete(d):w.add(d),w})},[]),te=u.useCallback(()=>{fe({x:null,y:null}),ne==null||ne(null,null)},[ne]),A=u.useMemo(()=>{switch(P){case"dark":return["var(--nice-primary-light, #60a5fa)","var(--nice-color-accent-pink, #f472b6)","var(--nice-success-light, #34d399)","var(--nice-warning-light, #fbbf24)","var(--nice-accent, #a78bfa)","#fb923c"];case"publication":return["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b"];case"presentation":return["var(--nice-primary, #3b82f6)","var(--nice-danger, #ef4444)","var(--nice-success, #22c55e)","var(--nice-warning, #f59e0b)","var(--nice-accent, #8b5cf6)","var(--nice-color-accent-pink, #ec4899)"];default:return["var(--nice-primary-hover, #2563eb)","var(--nice-danger-dark, #dc2626)","var(--nice-success-dark, #16a34a)","#ca8a04","var(--nice-accent, #7c3aed)","var(--nice-color-accent-pink, #db2777)"]}},[P]),C=u.useMemo(()=>{switch(P){case"dark":return{bg:"var(--nice-bg-secondary, #1f2937)",text:"var(--nice-text-primary, #f3f4f6)",grid:"var(--nice-text, #374151)",axis:"var(--nice-text-muted, #9ca3af)",tooltip:"var(--nice-text, #374151)"};case"publication":return{bg:"var(--nice-bg, #fff)",text:"var(--nice-text, #000000)",grid:"var(--nice-border, #e5e5e5)",axis:"var(--nice-text, #333333)",tooltip:"var(--nice-bg, #fff)"};default:return{bg:"var(--nice-bg, #fff)",text:"var(--nice-text, #1f2937)",grid:"var(--nice-border, #e5e7eb)",axis:"var(--nice-text-secondary, #4b5563)",tooltip:"var(--nice-bg, #fff)"}}},[P]);return n.jsxs("div",{ref:re,className:`nice-scientific-chart nice-scientific-chart--${P} ${ae||""}`,style:{width:s,height:U?"auto":i,aspectRatio:U==null?void 0:U.toString(),backgroundColor:C.bg,color:C.text,fontFamily:P==="publication"?"Times New Roman, serif":"system-ui, sans-serif",...de},children:[t&&n.jsxs("div",{className:"nice-scientific-chart__title",children:[t,r&&n.jsx("div",{className:"nice-scientific-chart__subtitle",style:{color:C.axis},children:r})]}),p.show&&n.jsx("div",{className:"nice-scientific-chart__legend",style:{flexDirection:p.orientation==="vertical"?"column":"row"},children:e.map((d,g)=>n.jsxs("button",{type:"button",className:"nice-scientific-chart__legend-item",onClick:()=>p.interactive&&ee(d.id),style:{cursor:p.interactive?"pointer":"default",opacity:se.has(d.id)?1:.4},children:[n.jsx("span",{className:"nice-scientific-chart__swatch",style:{backgroundColor:d.color||A[g%A.length]}}),d.name]},d.id))}),n.jsxs("div",{className:"nice-scientific-chart__canvas",children:[n.jsxs("svg",{width:"100%",height:"100%",children:[E&&n.jsxs("g",{className:"nice-scientific-chart__grid",stroke:C.grid,strokeWidth:1,children:[[0,.25,.5,.75,1].map(d=>n.jsx("line",{x1:"10%",y1:`${d*100}%`,x2:"95%",y2:`${d*100}%`,strokeDasharray:"2,2"},`h-${d}`)),[0,.25,.5,.75,1].map(d=>n.jsx("line",{x1:`${10+d*85}%`,y1:"5%",x2:`${10+d*85}%`,y2:"90%",strokeDasharray:"2,2"},`v-${d}`))]}),e.filter(d=>se.has(d.id)&&d.visible!==!1).map((d,g)=>{var z,R,y;const w=d.color||A[g%A.length],I=d.type||o;return n.jsx("g",{className:"nice-scientific-chart__series",children:I==="scatter"||I==="line"?n.jsxs(n.Fragment,{children:[I==="line"&&d.data.length>1&&n.jsx("svg",{x:"0",y:"0",width:"100%",height:"100%",viewBox:"0 0 100 100",preserveAspectRatio:"none",style:{overflow:"visible"},children:n.jsx("polyline",{fill:"none",stroke:w,strokeWidth:((z=d.line)==null?void 0:z.width)||2,vectorEffect:"non-scaling-stroke",strokeDasharray:((R=d.line)==null?void 0:R.style)==="dashed"?"5,5":((y=d.line)==null?void 0:y.style)==="dotted"?"2,2":void 0,points:d.data.map(($,D)=>{const L=10+((typeof $.x=="number"?$.x:D)-S.xMin)/(S.xMax-S.xMin)*85,O=90-($.y-S.yMin)/(S.yMax-S.yMin)*85;return`${L},${O}`}).join(" ")})}),d.data.map(($,D)=>{var ue,me,xe,he,ve;const L=10+((typeof $.x=="number"?$.x:D)-S.xMin)/(S.xMax-S.xMin)*85,O=90-($.y-S.yMin)/(S.yMax-S.yMin)*85,ie=$.size||((ue=d.marker)==null?void 0:ue.size)||6;return n.jsxs("g",{className:"nice-scientific-chart__point",children:[$.error&&n.jsx("line",{x1:`${L}%`,y1:`${90-($.y+(Array.isArray($.error)?$.error[1]:$.error)-S.yMin)/(S.yMax-S.yMin)*85}%`,x2:`${L}%`,y2:`${90-($.y-(Array.isArray($.error)?Math.abs($.error[0]):$.error)-S.yMin)/(S.yMax-S.yMin)*85}%`,stroke:w,strokeWidth:1}),n.jsx("circle",{cx:`${L}%`,cy:`${O}%`,r:ie/2,fill:$.color||((me=d.marker)==null?void 0:me.fillColor)||w,stroke:((xe=d.marker)==null?void 0:xe.strokeColor)||w,strokeWidth:((he=d.marker)==null?void 0:he.strokeWidth)||1,opacity:((ve=d.marker)==null?void 0:ve.opacity)??1,style:{cursor:_?"pointer":void 0},onMouseEnter:()=>{V({seriesId:d.id,pointIndex:D}),J==null||J($,d)},onMouseLeave:()=>{V(null),J==null||J(null,null)},onClick:je=>_==null?void 0:_($,d,je)})]},D)}),K[`${d.id}_regression`]&&n.jsx("line",{x1:"10%",y1:`${90-(K[`${d.id}_regression`].intercept+K[`${d.id}_regression`].slope*S.xMin-S.yMin)/(S.yMax-S.yMin)*85}%`,x2:"95%",y2:`${90-(K[`${d.id}_regression`].intercept+K[`${d.id}_regression`].slope*S.xMax-S.yMin)/(S.yMax-S.yMin)*85}%`,stroke:w,strokeWidth:1,strokeDasharray:"5,3",opacity:.7}),K[`${d.id}_mean`]&&n.jsx("line",{x1:"10%",y1:`${90-(K[`${d.id}_mean`]-S.yMin)/(S.yMax-S.yMin)*85}%`,x2:"95%",y2:`${90-(K[`${d.id}_mean`]-S.yMin)/(S.yMax-S.yMin)*85}%`,stroke:w,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%"}),Le(S.xMin,S.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:Te(d)})]},`x-${g}`)),Le(S.yMin,S.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:Te(d)})]},`y-${g}`))]}),h.filter(d=>d.visible!==!1).map(d=>{var g,w,I,z,R,y,$;return n.jsxs("g",{className:"nice-scientific-chart__annotation",children:[d.type==="text"&&d.text&&n.jsx("text",{x:`${10+(d.position.x-S.xMin)/(S.xMax-S.xMin)*85}%`,y:`${90-(d.position.y-S.yMin)/(S.yMax-S.yMin)*85}%`,fill:((g=d.style)==null?void 0:g.color)||C.text,fontSize:((w=d.style)==null?void 0:w.fontSize)||12,fontWeight:(I=d.style)==null?void 0:I.fontWeight,children:d.text}),d.type==="line"&&n.jsx("line",{x1:`${10+(d.position.x-S.xMin)/(S.xMax-S.xMin)*85}%`,y1:`${90-(d.position.y-S.yMin)/(S.yMax-S.yMin)*85}%`,x2:`${10+(d.position.x2-S.xMin)/(S.xMax-S.xMin)*85}%`,y2:`${90-(d.position.y2-S.yMin)/(S.yMax-S.yMin)*85}%`,stroke:((z=d.style)==null?void 0:z.color)||C.text,strokeWidth:((R=d.style)==null?void 0:R.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&&W&&n.jsx("div",{className:"nice-scientific-chart__tooltip",style:{background:C.tooltip,borderColor:C.grid},children:(()=>{const d=e.find(w=>w.id===W.seriesId),g=d==null?void 0:d.data[W.pointIndex];return!d||!g?null:f.format?f.format(g,d):n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"nice-scientific-chart__tooltip-title",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:{borderTopColor: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",{type:"button",className:"nice-scientific-chart__reset-zoom",onClick:te,style:{background:C.bg,borderColor:C.grid},children:"Reset Zoom"}),j&&j.formats.length>0&&n.jsxs("div",{className:"nice-scientific-chart__export",style:{borderTopColor:C.grid},children:[n.jsx("span",{className:"nice-scientific-chart__export-label",children:"Export:"}),j.formats.map(d=>n.jsx("button",{type:"button",className:"nice-scientific-chart__export-btn",style:{borderColor:C.grid},children:d.toUpperCase()},d))]})]})}const Ft=[],Oe={rotationX:25,rotationY:-45,rotationZ:0,zoom:1,panX:0,panY:0};function Bt(e,t){const r=t*Math.PI/180,s=Math.cos(r),i=Math.sin(r);return{x:e.x,y:e.y*s-e.z*i,z:e.y*i+e.z*s}}function _t(e,t){const r=t*Math.PI/180,s=Math.cos(r),i=Math.sin(r);return{x:e.x*s+e.z*i,y:e.y,z:-e.x*i+e.z*s}}function Rt(e,t){const r=t*Math.PI/180,s=Math.cos(r),i=Math.sin(r);return{x:e.x*s-e.y*i,y:e.x*i+e.y*s,z:e.z}}function be(e,t,r){let s=Bt(e,r.rotationX);s=_t(s,r.rotationY),s=Rt(s,r.rotationZ);const i=s.z+t,o=t/Math.max(i,.1);return{x:(s.x*o*r.zoom+r.panX)*100+50,y:(-s.y*o*r.zoom+r.panY)*100+50,depth:i}}function Me(e,t,r,s){const i=Math.max(0,Math.min(1,(e-t)/(r-t))),o={viridis:[[68,1,84],[59,82,139],[33,145,140],[94,201,98],[253,231,37]],plasma:[[13,8,135],[126,3,168],[204,71,120],[248,149,64],[240,249,33]],inferno:[[0,0,4],[87,16,110],[188,55,84],[249,142,9],[252,255,164]],magma:[[0,0,4],[81,18,124],[183,55,121],[254,159,109],[252,253,191]],cividis:[[0,32,77],[57,86,109],[128,133,121],[200,178,107],[253,231,55]],jet:[[0,0,127],[0,0,255],[0,255,255],[255,255,0],[255,0,0],[127,0,0]],rainbow:[[150,0,90],[0,0,200],[0,200,200],[0,200,0],[200,200,0],[200,0,0]],coolwarm:[[59,76,192],[98,130,234],[221,221,221],[220,170,132],[180,4,38]],RdBu:[[103,0,31],[178,24,43],[244,165,130],[247,247,247],[146,197,222],[33,102,172],[5,48,97]],spectral:[[158,1,66],[213,62,79],[253,174,97],[255,255,191],[171,221,164],[43,131,186],[94,79,162]],turbo:[[48,18,59],[86,121,245],[51,185,131],[192,212,49],[249,141,10],[122,4,3]],grayscale:[[0,0,0],[255,255,255]]},a=o[s]||o.viridis,l=i*(a.length-1),c=Math.floor(l),h=l-c;if(c>=a.length-1){const E=a[a.length-1];return`rgb(${E[0]}, ${E[1]}, ${E[2]})`}const p=a[c],f=a[c+1],m=Math.round(p[0]+h*(f[0]-p[0])),j=Math.round(p[1]+h*(f[1]-p[1])),M=Math.round(p[2]+h*(f[2]-p[2]));return`rgb(${m}, ${j}, ${M})`}function Lt({data:e=Ft,title:t,width:r="100%",height:s=500,scene:i={},showColorBar:o=!0,animation:a,showLegend:l=!0,legendPosition:c="top-right",enableRotation:h=!0,enableZoom:p=!0,enablePan:f=!0,showAxes:m=!0,showAxisLabels:j=!0,focalLength:M=3,theme:E="light",onCameraChange:U,onPointClick:Q,onPointHover:P,className:_,style:J}){const ne=u.useRef(null),[q,ae]=u.useState(Oe),[de,re]=u.useState(!1),[H,X]=u.useState(null),[oe,le]=u.useState(null),[pe,fe]=u.useState(0),W=u.useMemo(()=>{let A=1/0,C=-1/0,d=1/0,g=-1/0,w=1/0,I=-1/0,z=1/0,R=-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),w=Math.min(w,D.z),I=Math.max(I,D.z),typeof D.color=="number"&&(z=Math.min(z,D.color),R=Math.max(R,D.color));else if($.type==="surface"||$.type==="wireframe"){const D=$;for(const L of D.xData)A=Math.min(A,L),C=Math.max(C,L);for(const L of D.yData)d=Math.min(d,L),g=Math.max(g,L);for(const L of D.zData)for(const O of L)w=Math.min(w,O),I=Math.max(I,O),z=Math.min(z,O),R=Math.max(R,O)}const y=Math.max(C-A,g-d,I-w)||1;return{xMin:A,xMax:C,yMin:d,yMax:g,zMin:w,zMax:I,colorMin:z,colorMax:R,maxRange:y}},[e]),V=u.useCallback(A=>{const C=2/W.maxRange;return{x:(A.x-(W.xMin+W.xMax)/2)*C,y:(A.y-(W.yMin+W.yMax)/2)*C,z:(A.z-(W.zMin+W.zMax)/2)*C}},[W]),se=u.useCallback(A=>{!h&&!f||(re(!0),X({x:A.clientX,y:A.clientY,viewState:{...q}}))},[h,f,q]),Z=u.useCallback(A=>{if(!de||!H)return;const C=A.clientX-H.x,d=A.clientY-H.y;A.shiftKey&&f?ae({...H.viewState,panX:H.viewState.panX+C*.002,panY:H.viewState.panY+d*.002}):h&&ae({...H.viewState,rotationY:H.viewState.rotationY+C*.5,rotationX:H.viewState.rotationX+d*.5})},[de,H,h,f]),S=u.useCallback(()=>{re(!1),X(null)},[]),K=u.useCallback(A=>{if(!p)return;A.preventDefault();const C=A.deltaY>0?.9:1.1;ae(d=>({...d,zoom:Math.max(.1,Math.min(10,d.zoom*C))}))},[p]),G=u.useMemo(()=>{switch(E){case"dark":return{bg:"var(--nice-bg, #1a1a2e)",text:"var(--nice-text-secondary, #e0e0e0)",axis:"var(--nice-text-secondary, #555)",grid:"var(--nice-text, #333)"};case"scientific":return{bg:"var(--nice-bg-secondary, #f8f8f8)",text:"var(--nice-text, #333)",axis:"var(--nice-text-secondary, #666)",grid:"var(--nice-border, #ddd)"};default:return{bg:"var(--nice-bg, #fff)",text:"var(--nice-text, #333)",axis:"var(--nice-text-secondary, #888)",grid:"var(--nice-border, #e0e0e0)"}}},[E]),ee=u.useMemo(()=>{var C;const A=[];for(const d of e)if(d.type==="scatter3d"){const g=d,w=g.points.map(I=>{var D,L,O,ie,ue;const z=V(I),R=be(z,M,q);let y=(D=g.marker)==null?void 0:D.color;if(Array.isArray((L=g.marker)==null?void 0:L.color)){const me=g.points.indexOf(I);y=Me(g.marker.color[me],W.colorMin,W.colorMax,((O=g.marker)==null?void 0:O.colorScale)||"viridis")}else typeof I.color=="number"&&(y=Me(I.color,W.colorMin,W.colorMax,((ie=g.marker)==null?void 0:ie.colorScale)||"viridis"));const $=Array.isArray(I.size)?I.size[0]:I.size||((ue=g.marker)==null?void 0:ue.size)||5;return{...R,color:y,size:$,original:I}});A.push({type:"scatter",points:w,data:d})}else if(d.type==="surface"||d.type==="wireframe"){const g=d,w=[];for(let I=0;I<g.xData.length;I++)for(let z=0;z<g.yData.length;z++){const R={x:g.xData[I],y:g.yData[z],z:g.zData[I][z]},y=V(R),$=be(y,M,q),D=Me(((C=g.colorData)==null?void 0:C[I][z])??g.zData[I][z],W.colorMin,W.colorMax,g.colorScale||"viridis");w.push({...$,color:D,size:3,original:R})}A.push({type:d.type,points:w,data:d})}for(const d of A)d.points.sort((g,w)=>g.depth-w.depth);return A},[e,q,M,V,W]),te=u.useMemo(()=>{var d,g,w;if(!m)return null;const A=1.2,C={x:[be({x:-A,y:0,z:0},M,q),be({x:A,y:0,z:0},M,q)],y:[be({x:0,y:-A,z:0},M,q),be({x:0,y:A,z:0},M,q)],z:[be({x:0,y:0,z:-A},M,q),be({x:0,y:0,z:A},M,q)]};return n.jsxs("g",{className:"nice-3d-plot__axes",children:[n.jsx("line",{x1:`${C.x[0].x}%`,y1:`${C.x[0].y}%`,x2:`${C.x[1].x}%`,y2:`${C.x[1].y}%`,stroke:"var(--nice-danger, #e74c3c)",strokeWidth:1.5}),j&&n.jsx("text",{x:`${C.x[1].x+2}%`,y:`${C.x[1].y}%`,fill:"var(--nice-danger, #e74c3c)",fontSize:"12",children:((d=i.xAxis)==null?void 0:d.title)||"X"}),n.jsx("line",{x1:`${C.y[0].x}%`,y1:`${C.y[0].y}%`,x2:`${C.y[1].x}%`,y2:`${C.y[1].y}%`,stroke:"var(--nice-success, #2ecc71)",strokeWidth:1.5}),j&&n.jsx("text",{x:`${C.y[1].x}%`,y:`${C.y[1].y-2}%`,fill:"var(--nice-success, #2ecc71)",fontSize:"12",textAnchor:"middle",children:((g=i.yAxis)==null?void 0:g.title)||"Y"}),n.jsx("line",{x1:`${C.z[0].x}%`,y1:`${C.z[0].y}%`,x2:`${C.z[1].x}%`,y2:`${C.z[1].y}%`,stroke:"var(--nice-primary, #3498db)",strokeWidth:1.5}),j&&n.jsx("text",{x:`${C.z[1].x+2}%`,y:`${C.z[1].y}%`,fill:"var(--nice-primary, #3498db)",fontSize:"12",children:((w=i.zAxis)==null?void 0:w.title)||"Z"})]})},[m,j,q,M,i]);return n.jsxs("div",{ref:ne,className:`nice-3d-plot nice-3d-plot--${E}${de?" nice-3d-plot--dragging":""} ${_||""}`,style:{width:r,height:s,backgroundColor:G.bg,color:G.text,...J},onMouseDown:se,onMouseMove:Z,onMouseUp:S,onMouseLeave:S,onWheel:K,children:[t&&n.jsx("div",{className:"nice-3d-plot__title",children:t}),n.jsxs("svg",{width:"100%",height:"100%",className:"nice-3d-plot__canvas",children:[te,ee.map((A,C)=>n.jsxs("g",{className:"nice-3d-plot__data",children:[A.type==="scatter"&&A.points.map((d,g)=>{var w;return n.jsx("circle",{cx:`${d.x}%`,cy:`${d.y}%`,r:d.size||4,fill:d.color||"var(--nice-primary, #3498db)",opacity:((w=A.data.marker)==null?void 0:w.opacity)??.8,style:{cursor:Q?"pointer":void 0},onMouseEnter:()=>{le({point:d.original,dataIndex:C}),P==null||P(d.original,C)},onMouseLeave:()=>{le(null),P==null||P(null,C)},onClick:()=>Q==null?void 0:Q(d.original,C)},g)}),(A.type==="surface"||A.type==="wireframe")&&A.points.map((d,g)=>n.jsx("rect",{x:`${d.x-1}%`,y:`${d.y-1}%`,width:"2%",height:"2%",fill:d.color||"var(--nice-primary, #3498db)",opacity:A.data.opacity??.7},g))]},A.data.id||C))]}),l&&e.length>1&&n.jsx("div",{style:{position:"absolute",padding:"8px",background:"var(--nice-overlay-light-90, rgba(255, 255, 255, 0.9))",borderRadius:4,fontSize:"0.8rem",...c==="top-right"&&{top:8,right:8},...c==="top-left"&&{top:8,left:8},...c==="bottom-right"&&{bottom:8,right:8},...c==="bottom-left"&&{bottom:8,left:8}},children:e.map((A,C)=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[n.jsx("span",{style:{width:12,height:12,background:"var(--nice-primary, #3498db)",borderRadius:2}}),A.name]},A.id||C))}),o&&Number.isFinite(W.colorMin)&&Number.isFinite(W.colorMax)&&n.jsxs("div",{style:{position:"absolute",right:16,top:"50%",transform:"translateY(-50%)",width:16,height:150,background:`linear-gradient(to top, ${Me(0,0,1,"viridis")}, ${Me(.5,0,1,"viridis")}, ${Me(1,0,1,"viridis")})`,borderRadius:2,border:"1px solid var(--nice-border, #ccc)"},children:[n.jsx("div",{style:{position:"absolute",top:-16,right:20,fontSize:"0.7rem"},children:W.colorMax.toFixed(2)}),n.jsx("div",{style:{position:"absolute",bottom:-16,right:20,fontSize:"0.7rem"},children:W.colorMin.toFixed(2)})]}),oe&&n.jsxs("div",{style:{position:"absolute",bottom:8,left:8,background:"var(--nice-overlay-80, rgba(0, 0, 0, 0.8))",color:"var(--nice-color-white, #fff)",padding:"4px 8px",borderRadius:4,fontSize:"0.75rem"},children:["X: ",oe.point.x.toFixed(4),", Y: ",oe.point.y.toFixed(4),", Z:"," ",oe.point.z.toFixed(4)]}),n.jsx("div",{style:{position:"absolute",bottom:8,right:8,display:"flex",gap:4},children:n.jsx("button",{onClick:()=>ae(Oe),style:{padding:"4px 8px",fontSize:"0.75rem",cursor:"pointer"},children:"Reset View"})})]})}const Ge={H:"var(--nice-bg, #fff)",C:"#909090",N:"#3050F8",O:"#FF0D0D",S:"#FFFF30",P:"#FF8000",F:"#90E050",Cl:"#1FF01F",Br:"#A62929",I:"#940094",He:"#D9FFFF",Ne:"#B3E3F5",Ar:"#80D1E3",Kr:"#5CB8D1",Xe:"#429EB0",Li:"#CC80FF",Na:"#AB5CF2",K:"#8F40D4",Rb:"#702EB0",Cs:"#57178F",Be:"#C2FF00",Mg:"#8AFF00",Ca:"#3DFF00",Sr:"var(--nice-success, #00ff00)",Ba:"#00C900",B:"#FFB5B5",Al:"#BFA6A6",Ga:"#C28F8F",In:"#A67573",Tl:"#A6544D",Si:"#F0C8A0",Ge:"#668F8F",Sn:"#668080",Pb:"#575961",As:"#BD80E3",Sb:"#9E63B5",Bi:"#9E4FB5",Se:"#FFA100",Te:"#D47A00",Po:"#AB5C00",Fe:"#E06633",Co:"#F090A0",Ni:"#50D050",Cu:"#C88033",Zn:"#7D80B0",Mn:"#9C7AC7",Cr:"#8A99C7",V:"#A6A6AB",Ti:"#BFC2C7",Sc:"#E6E6E6",Au:"#FFD123",Ag:"#C0C0C0",Pt:"#D0D0E0",Pd:"#006985",Ru:"#248F8F",Rh:"#0A7D8C",Os:"#266696",Ir:"#175487"},Ae={H:.31,C:.77,N:.71,O:.66,S:1.05,P:1.07,F:.57,Cl:1.02,Br:1.2,I:1.39,He:.28,Ne:.58,Ar:1.06,Li:1.28,Na:1.66,K:2.03,Mg:1.41,Ca:1.76,Fe:1.26,Zn:1.22,Cu:1.28,Ni:1.24},Tt={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 We(e){const t=[],r=[],s=new Map,i=new Map;let o="Unknown";const a=e.split(`
60
- `);for(const l of a){const c=l.substring(0,6).trim();if(c==="HEADER")o=l.substring(10,50).trim()||o;else if(c==="ATOM"||c==="HETATM"){const h=parseInt(l.substring(6,11).trim(),10),p=l.substring(12,16).trim(),f=l.substring(17,20).trim(),m=l.substring(21,22).trim()||"A",j=parseInt(l.substring(22,26).trim(),10),M=parseFloat(l.substring(30,38).trim()),E=parseFloat(l.substring(38,46).trim()),U=parseFloat(l.substring(46,54).trim()),Q=parseFloat(l.substring(54,60).trim())||1,P=parseFloat(l.substring(60,66).trim())||0,_=l.substring(76,78).trim()||p.replace(/\d/g,"").substring(0,1),J={id:t.length,serial:h,name:p,element:_.toUpperCase(),residueName:f,residueSeq:j,chainId:m,x:M,y:E,z:U,occupancy:Q,bFactor:P,color:Ge[_.toUpperCase()]||"var(--nice-text-secondary, #808080)",radius:Ae[_.toUpperCase()]||1.5};t.push(J);const ne=`${m}_${j}_${f}`;s.has(ne)||s.set(ne,{id:s.size,name:f,seq:j,chainId:m,atoms:[]}),s.get(ne).atoms.push(J.id),i.has(m)||i.set(m,{id:m,residues:[]})}else if(c==="CONECT"){const h=l.substring(6).trim().split(/\s+/).map(Number),p=h[0],f=t.find(m=>m.serial===p);if(f)for(let m=1;m<h.length;m++){const j=h[m],M=t.find(E=>E.serial===j);M&&f.id<M.id&&r.push({id:r.length,atom1:f.id,atom2:M.id,order:1})}}}if(r.length===0)for(let l=0;l<t.length;l++)for(let c=l+1;c<t.length;c++){const h=t[l],p=t[c],f=h.x-p.x,m=h.y-p.y,j=h.z-p.z,M=Math.sqrt(f*f+m*m+j*j),E=(Ae[h.element]||1.5)+(Ae[p.element]||1.5)+.4;M<E&&M>.4&&r.push({id:r.length,atom1:l,atom2:c,order:1,length:M})}return{id:"mol_"+Date.now(),name:o,atoms:t,bonds:r,residues:Array.from(s.values()),chains:Array.from(i.values())}}function Ot(e,t,r,s,i,o){const a=j=>j*Math.PI/180,l=t*Math.cos(a(s))-r*Math.sin(a(s)),c=t*Math.sin(a(s))+r*Math.cos(a(s)),h=e*Math.cos(a(i))+c*Math.sin(a(i)),p=-e*Math.sin(a(i))+c*Math.cos(a(i)),f=h*Math.cos(a(o))-l*Math.sin(a(o)),m=h*Math.sin(a(o))+l*Math.cos(a(o));return[f,m,p]}function De(e,t,r,s,i,o){const a=e-i.x,l=t-i.y,c=r-i.z,[h,p,f]=Ot(a,l,c,s.rotX,s.rotY,s.rotZ),m=500,j=m/(m+f*50);return{x:50+h*o*s.zoom*j+s.panX,y:50-p*o*s.zoom*j+s.panY,depth:f}}function Wt({molecule:e,format:t="pdb",style:r="ball-stick",colorScheme:s="element",showHydrogens:i=!0,showWaters:o=!1,showLabels:a=!1,labelType:l="element",width:c="100%",height:h=500,backgroundColor:p="#000000",enableRotation:f=!0,enableZoom:m=!0,showControls:j=!0,measurements:M=[],surfaces:E=[],labels:U=[],selection:Q,highlightColor:P="var(--nice-warning, #ffff00)",spin:_=!1,spinSpeed:J=.5,onAtomClick:ne,onAtomHover:q,onSelectionChange:ae,className:de,styleOverride:re}){const H=u.useRef(null),[X,oe]=u.useState(null),[le,pe]=u.useState({rotX:0,rotY:0,rotZ:0,zoom:1,panX:0,panY:0}),[fe,W]=u.useState(!1),[V,se]=u.useState(null),[Z,S]=u.useState(null),[K,G]=u.useState(r);u.useEffect(()=>{if(!e){oe(null);return}typeof e=="string"?(t==="pdb"||console.warn(`Format ${t} parsing not implemented, using PDB parser`),oe(We(e))):oe(e)},[e,t]),u.useEffect(()=>{if(!_)return;const y=setInterval(()=>{pe($=>({...$,rotY:($.rotY+J)%360}))},16);return()=>clearInterval(y)},[_,J]);const{center:ee,scale:te}=u.useMemo(()=>{if(!X||X.atoms.length===0)return{center:{x:0,y:0,z:0},scale:1};let y=1/0,$=-1/0,D=1/0,L=-1/0,O=1/0,ie=-1/0;for(const he of X.atoms)y=Math.min(y,he.x),$=Math.max($,he.x),D=Math.min(D,he.y),L=Math.max(L,he.y),O=Math.min(O,he.z),ie=Math.max(ie,he.z);const ue={x:(y+$)/2,y:(D+L)/2,z:(O+ie)/2},me=Math.max($-y,L-D,ie-O),xe=me>0?35/me:1;return{center:ue,scale:xe}},[X]),A=u.useMemo(()=>X?X.atoms.filter(y=>!i&&y.element==="H"||!o&&y.residueName==="HOH"?!1:y.visible!==!1).map(y=>({atom:y,...De(y.x,y.y,y.z,le,ee,te)})).sort((y,$)=>y.depth-$.depth):[],[X,le,ee,te,i,o]),C=u.useMemo(()=>X?X.bonds.filter(y=>y.visible!==!1).map(y=>{const $=X.atoms[y.atom1],D=X.atoms[y.atom2];if(!$||!D||!i&&($.element==="H"||D.element==="H"))return null;const L=De($.x,$.y,$.z,le,ee,te),O=De(D.x,D.y,D.z,le,ee,te);return{bond:y,x1:L.x,y1:L.y,x2:O.x,y2:O.y,depth:(L.depth+O.depth)/2,color1:$.color,color2:D.color}}).filter(Boolean).sort((y,$)=>y.depth-$.depth):[],[X,le,ee,te,i]),d=u.useCallback(y=>{f&&(W(!0),se({x:y.clientX,y:y.clientY,view:{...le}}))},[f,le]),g=u.useCallback(y=>{if(!fe||!V)return;const $=y.clientX-V.x,D=y.clientY-V.y;y.shiftKey?pe({...V.view,panX:V.view.panX+$*.1,panY:V.view.panY+D*.1}):pe({...V.view,rotY:V.view.rotY+$*.5,rotX:V.view.rotX+D*.5})},[fe,V]),w=u.useCallback(()=>{W(!1),se(null)},[]),I=u.useCallback(y=>{if(!m)return;y.preventDefault();const $=y.deltaY>0?.9:1.1;pe(D=>({...D,zoom:Math.max(.1,Math.min(10,D.zoom*$))}))},[m]),z=u.useCallback(y=>{switch(K){case"space-filling":return(Tt[y.element]||1.5)*4;case"ball-stick":return(Ae[y.element]||.5)*3;case"stick":case"wireframe":return 2;default:return 4}},[K]),R=u.useCallback(y=>(K==="wireframe"?1:K==="stick"?3:2)*(y.order||1),[K]);return X?n.jsxs("div",{ref:H,className:`nice-molecular-viewer${fe?" nice-molecular-viewer--dragging":""} ${de||""}`,style:{width:c,height:h,backgroundColor:p,...re},onMouseDown:d,onMouseMove:g,onMouseUp:w,onMouseLeave:w,onWheel:I,children:[n.jsxs("svg",{width:"100%",height:"100%",className:"nice-molecular-viewer__canvas",children:[K!=="space-filling"&&C.map((y,$)=>n.jsx("line",{x1:`${y.x1}%`,y1:`${y.y1}%`,x2:`${y.x2}%`,y2:`${y.y2}%`,stroke:y.bond.color||"var(--nice-text-secondary, #888888)",strokeWidth:R(y.bond),strokeLinecap:"round"},`bond-${$}`)),A.map(({atom:y,x:$,y:D})=>{var ue;const L=(ue=Q==null?void 0:Q.atoms)==null?void 0:ue.includes(y.id),O=(Z==null?void 0:Z.id)===y.id,ie=z(y);return n.jsxs("g",{children:[n.jsx("circle",{cx:`${$}%`,cy:`${D}%`,r:ie,fill:y.color||Ge[y.element]||"#808080",stroke:L?P:O?"#fff":"none",strokeWidth:L||O?2:0,style:{cursor:"pointer"},onMouseEnter:()=>{S(y),q==null||q(y)},onMouseLeave:()=>{S(null),q==null||q(null)},onClick:()=>ne==null?void 0:ne(y)}),a&&n.jsx("text",{x:`${$}%`,y:`${D-ie*.15}%`,fill:"var(--nice-color-white, #fff)",fontSize:"10",textAnchor:"middle",dominantBaseline:"middle",style:{pointerEvents:"none"},children:l==="element"?y.element:l==="name"?y.name:l==="residue"?y.residueName:l==="chain"?y.chainId:l==="serial"?y.serial:y.element})]},`atom-${y.id}`)}),M.map(y=>{if(y.atoms.length<2)return null;const $=X.atoms[y.atoms[0]],D=X.atoms[y.atoms[1]];if(!$||!D)return null;const L=De($.x,$.y,$.z,le,ee,te),O=De(D.x,D.y,D.z,le,ee,te);return n.jsxs("g",{children:[n.jsx("line",{x1:`${L.x}%`,y1:`${L.y}%`,x2:`${O.x}%`,y2:`${O.y}%`,stroke:y.color||"var(--nice-warning, #ffff00)",strokeWidth:1,strokeDasharray:"3,3"}),n.jsxs("text",{x:`${(L.x+O.x)/2}%`,y:`${(L.y+O.y)/2-1}%`,fill:y.color||"var(--nice-warning, #ffff00)",fontSize:"10",textAnchor:"middle",children:[y.value.toFixed(2)," ",y.unit]})]},y.id)})]}),n.jsxs("div",{style:{position:"absolute",top:8,left:8,color:"var(--nice-text-primary, #fff)",fontSize:"0.8rem"},children:[n.jsx("div",{style:{fontWeight:"bold"},children:X.name}),n.jsxs("div",{children:[X.atoms.length," atoms, ",X.bonds.length," bonds"]}),X.formula&&n.jsxs("div",{children:["Formula: ",X.formula]})]}),Z&&n.jsxs("div",{style:{position:"absolute",bottom:8,left:8,background:"var(--nice-overlay-80, rgba(0, 0, 0, 0.8))",color:"var(--nice-color-white, #fff)",padding:"4px 8px",borderRadius:4,fontSize:"0.75rem"},children:[n.jsxs("div",{children:[n.jsx("b",{children:Z.element})," (",Z.name,")"]}),Z.residueName&&n.jsxs("div",{children:["Residue: ",Z.residueName," ",Z.residueSeq]}),Z.chainId&&n.jsxs("div",{children:["Chain: ",Z.chainId]}),n.jsxs("div",{children:["Position: (",Z.x.toFixed(2),", ",Z.y.toFixed(2),","," ",Z.z.toFixed(2),")"]})]}),j&&n.jsxs("div",{style:{position:"absolute",top:8,right:8,display:"flex",flexDirection:"column",gap:4},children:[n.jsxs("select",{value:K,onChange:y=>G(y.target.value),style:{padding:"2px 4px",fontSize:"0.75rem"},children:[n.jsx("option",{value:"ball-stick",children:"Ball & Stick"}),n.jsx("option",{value:"space-filling",children:"Space Filling"}),n.jsx("option",{value:"stick",children:"Stick"}),n.jsx("option",{value:"wireframe",children:"Wireframe"})]}),n.jsx("button",{onClick:()=>pe({rotX:0,rotY:0,rotZ:0,zoom:1,panX:0,panY:0}),style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:"Reset View"})]})]}):n.jsx("div",{className:`nice-molecular-viewer nice-molecular-viewer--empty ${de||""}`,style:{width:c,height:h,backgroundColor:p,...re},children:"Load a molecule (PDB, MOL, SDF)"})}function Xt(e){let t=0,r=0;function s(){var l;const o={id:`node_${r++}`};if(e[t]==="(")for(t++,o.children=[];;){const c=s();if(c&&(c.parent=o.id,o.children.push(c)),e[t]===","){t++;continue}if(e[t]===")"){t++;break}if(t>=e.length)break}let a="";for(;t<e.length&&!"[:,;()".includes(e[t]);)a+=e[t++];if(a.trim()){const c=a.match(/^([^[\]]+)?(?:\[([^\]]+)\])?$/);if(c){if(o.name=((l=c[1])==null?void 0:l.trim())||void 0,c[2]){const h=parseFloat(c[2]);isNaN(h)||(o.bootstrap=h)}}else o.name=a.trim()}if(e[t]===":"){t++;let c="";for(;t<e.length&&!"[,;()".includes(e[t]);)c+=e[t++];const h=parseFloat(c);isNaN(h)||(o.branchLength=h)}return o}return e.replace(/\s+/g,"").replace(/;$/,"")?s():null}function Qe(e,t=[]){if(t.push(e),e.children)for(const r of e.children)Qe(r,t);return t}function He(e){return!e.children||e.children.length===0?1:e.children.reduce((t,r)=>t+He(r),0)}function et(e,t,r){if(!e.children||e.children.length===0||e.collapsed)return t.set(e.id,r.value),r.value+=1,t.get(e.id);let s=1/0,i=-1/0;for(const a of e.children){const l=et(a,t,r);s=Math.min(s,l),i=Math.max(i,l)}const o=(s+i)/2;return t.set(e.id,o),o}function tt(e,t,r=0){const s=r+(e.branchLength||1);if(t.set(e.id,s),e.children&&!e.collapsed)for(const i of e.children)tt(i,t,s)}function Yt({tree:e,layout:t="rectangular",branchStyle:r="rectangular",nodeShape:s="circle",nodeSize:i=5,showBranchLengths:o=!1,showBootstrap:a=!1,bootstrapThreshold:l=70,showLeafLabels:c=!0,showInternalLabels:h=!1,labelFontSize:p=11,branchWidth:f=1.5,branchColor:m="var(--nice-text-secondary, #666666)",nodeColor:j="var(--nice-text, #333333)",highlightColor:M="var(--nice-primary, #2196f3)",clades:E=[],annotations:U=[],colorScale:Q,width:P="100%",height:_=500,padding:J=40,enableZoom:ne=!0,enablePan:q=!0,showControls:ae=!0,onNodeClick:de,onNodeHover:re,onBranchClick:H,className:X,style:oe}){const le=u.useRef(null),[pe,fe]=u.useState(1),[W,V]=u.useState({x:0,y:0}),[se,Z]=u.useState(!1),[S,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"?Xt(e):e:null,[e]),w=u.useMemo(()=>{if(!g)return null;const v=k=>{var F;return{...k,collapsed:C.has(k.id),children:(F=k.children)==null?void 0:F.map(v)}};return v(g)},[g,C]),{positions:I,leafCount:z,maxX:R}=u.useMemo(()=>{if(!w)return{positions:{x:new Map,y:new Map},leafCount:0,maxX:0};const v=new Map,k=new Map,F=He(w);et(w,k,{value:0}),tt(w,v,0);const x=Math.max(...Array.from(v.values()));return{positions:{x:v,y:k},leafCount:F,maxX:x||1}},[w]),y=u.useMemo(()=>w?Qe(w):[],[w]),$=typeof P=="number"?P:800,D=typeof _=="number"?_:500,L=$-J*2,O=D-J*2,ie=v=>J+v/R*L*.7,ue=v=>J+v/(z-1||1)*O,me=(v,k)=>{const F=k/(z-1||1)*2*Math.PI-Math.PI/2,x=v/R*Math.min(L,O)*.4;return{x:$/2+x*Math.cos(F),y:D/2+x*Math.sin(F)}},xe=v=>{const k=I.x.get(v)||0,F=I.y.get(v)||0;return te==="radial"||te==="circular"?me(k,F):{x:ie(k),y:ue(F)}},he=u.useCallback(v=>{q&&(Z(!0),K({x:v.clientX,y:v.clientY,pan:{...W}}))},[q,W]),ve=u.useCallback(v=>{if(!se||!S)return;const k=v.clientX-S.x,F=v.clientY-S.y;V({x:S.pan.x+k,y:S.pan.y+F})},[se,S]),je=u.useCallback(()=>{Z(!1),K(null)},[]),Ee=u.useCallback(v=>{if(!ne)return;v.preventDefault();const k=v.deltaY>0?.9:1.1;fe(F=>Math.max(.1,Math.min(5,F*k)))},[ne]),Fe=u.useCallback(v=>{d(k=>{const F=new Set(k);return F.has(v)?F.delete(v):F.add(v),F})},[]),Be=(v,k)=>{const F=xe(v.id),x=xe(k.id);if(te==="radial"||te==="circular")return n.jsx("line",{x1:F.x,y1:F.y,x2:x.x,y2:x.y,stroke:k.color||m,strokeWidth:f});switch(r){case"rectangular":return n.jsx("path",{d:`M${F.x},${F.y} H${x.x} V${x.y}`,stroke:k.color||m,strokeWidth:f,fill:"none"});case"diagonal":return n.jsx("line",{x1:F.x,y1:F.y,x2:x.x,y2:x.y,stroke:k.color||m,strokeWidth:f});case"curved":{const b=(F.x+x.x)/2;return n.jsx("path",{d:`M${F.x},${F.y} C${b},${F.y} ${b},${x.y} ${x.x},${x.y}`,stroke:k.color||m,strokeWidth:f,fill:"none"})}default:return n.jsx("line",{x1:F.x,y1:F.y,x2:x.x,y2:x.y,stroke:k.color||m,strokeWidth:f})}},Ce=v=>{const k=xe(v.id),F=!v.children||v.children.length===0||v.collapsed,x=(G==null?void 0:G.id)===v.id,b=x?i*1.5:i,T=(()=>{switch(s){case"circle":return n.jsx("circle",{cx:k.x,cy:k.y,r:b});case"square":return n.jsx("rect",{x:k.x-b,y:k.y-b,width:b*2,height:b*2});case"triangle":{const N=b*1.5;return n.jsx("polygon",{points:`${k.x},${k.y-N} ${k.x-N},${k.y+N} ${k.x+N},${k.y+N}`})}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:[T&&n.jsx("g",{fill:v.highlighted?M:v.color||j,stroke:x?M:"none",strokeWidth:2,style:{cursor:"pointer"},onMouseEnter:()=>{ee(v),re==null||re(v)},onMouseLeave:()=>{ee(null),re==null||re(null)},onClick:()=>de==null?void 0:de(v),onDoubleClick:()=>{v.children&&v.children.length>0&&Fe(v.id)},children:T}),v.collapsed&&v.children&&n.jsx("polygon",{points:`${k.x+8},${k.y-6} ${k.x+20},${k.y} ${k.x+8},${k.y+6}`,fill:j,opacity:.5}),F&&c&&v.name&&n.jsx("text",{x:k.x+i+5,y:k.y,fontSize:p,fill:"var(--nice-text, #333)",dominantBaseline:"middle",children:v.name}),!F&&h&&v.name&&n.jsx("text",{x:k.x,y:k.y-i-3,fontSize:p*.9,fill:"var(--nice-text-secondary, #666)",textAnchor:"middle",children:v.name}),a&&v.bootstrap!==void 0&&v.bootstrap>=l&&n.jsx("text",{x:k.x,y:k.y-i-2,fontSize:p*.8,fill:"var(--nice-color-accent-pink, #e91e63)",textAnchor:"middle",children:v.bootstrap.toFixed(0)})]},v.id)},ke=v=>{const k=[];if(v.children&&!v.collapsed)for(const F of v.children)k.push(n.jsx("g",{children:Be(v,F)},`branch-${v.id}-${F.id}`)),k.push(...ke(F));return k};return w?n.jsxs("div",{ref:le,className:`nice-phylogenetic-tree${se?" nice-phylogenetic-tree--dragging":""} ${X||""}`,style:{width:P,height:_,...oe},onMouseDown:he,onMouseMove:ve,onMouseUp:je,onMouseLeave:je,onWheel:Ee,children:[n.jsxs("svg",{width:"100%",height:"100%",style:{transform:`translate(${W.x}px, ${W.y}px) scale(${pe})`,transformOrigin:"center center"},children:[E.map(v=>{const k=y.filter(B=>v.nodeIds.includes(B.id));if(k.length===0)return null;const F=k.map(B=>xe(B.id)),x=Math.min(...F.map(B=>B.x))-10,b=Math.max(...F.map(B=>B.x))+10,T=Math.min(...F.map(B=>B.y))-10,N=Math.max(...F.map(B=>B.y))+10;return n.jsxs("g",{children:[n.jsx("rect",{x,y:T,width:b-x,height:N-T,fill:v.background||`${v.color}20`||"var(--nice-primary-bg, #e3f2fd)",stroke:v.color||"var(--nice-primary, #2196f3)",strokeWidth:1,strokeDasharray:"4,2",rx:4}),v.showLabel&&n.jsx("text",{x:b+5,y:(T+N)/2,fontSize:10,fill:v.color||"var(--nice-text-secondary, #666)",dominantBaseline:"middle",children:v.name})]},v.id)}),ke(w),y.map(v=>Ce(v)),U.map(v=>{if(!y.find(b=>b.id===v.nodeId))return null;const F=xe(v.nodeId),x={left:{x:-10,y:0},right:{x:10,y:0},above:{x:0,y:-10},below:{x:0,y:10}}[v.position||"right"];return n.jsx("text",{x:F.x+x.x,y:F.y+x.y,fontSize:v.fontSize||9,fill:v.color||"var(--nice-danger, #ff5722)",textAnchor:v.position==="left"?"end":v.position==="right"?"start":"middle",dominantBaseline:"middle",children:v.text},`ann-${v.nodeId}`)})]}),n.jsxs("div",{style:{position:"absolute",top:8,left:8,fontSize:"0.75rem",color:"var(--nice-text-secondary, #666)"},children:[y.length," nodes • ",z," leaves"]}),G&&n.jsxs("div",{style:{position:"absolute",bottom:8,left:8,background:"var(--nice-overlay-light-95, rgba(255, 255, 255, 0.95))",padding:"4px 8px",borderRadius:4,fontSize:"0.75rem",boxShadow:"0 1px 4px var(--nice-overlay-10, rgba(0, 0, 0, 0.1))"},children:[n.jsx("div",{children:n.jsx("b",{children:G.name||G.id})}),G.branchLength!==void 0&&n.jsxs("div",{children:["Branch length: ",G.branchLength.toFixed(4)]}),G.bootstrap!==void 0&&n.jsxs("div",{children:["Bootstrap: ",G.bootstrap]}),G.children&&n.jsxs("div",{children:["Children: ",G.children.length]})]}),ae&&n.jsxs("div",{style:{position:"absolute",top:8,right:8,display:"flex",flexDirection:"column",gap:4},children:[n.jsxs("select",{value:te,onChange:v=>A(v.target.value),style:{padding:"2px 4px",fontSize:"0.75rem"},children:[n.jsx("option",{value:"rectangular",children:"Rectangular"}),n.jsx("option",{value:"radial",children:"Radial"}),n.jsx("option",{value:"diagonal",children:"Diagonal"})]}),n.jsx("button",{onClick:()=>{fe(1),V({x:0,y:0})},style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:"Reset View"}),n.jsx("button",{onClick:()=>d(new Set),style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:"Expand All"})]})]}):n.jsx("div",{className:`nice-phylogenetic-tree nice-phylogenetic-tree--empty ${X||""}`,style:{width:P,height:_,...oe},children:"Load a phylogenetic tree (Newick format)"})}const we=e=>e*Math.PI/180;function Pt(e,t,r,s){const i=(t+180)/360*r,o=we(e),a=Math.log(Math.tan(Math.PI/4+o/2)),l=s/2-r*a/(2*Math.PI);return{x:i,y:l}}function qt(e,t,r,s){const i=(t+180)/360*r,o=(90-e)/180*s;return{x:i,y:o}}function Vt(e,t,r,s,i,o){const a=we(e),l=we(t),c=we(i),h=we(o);if(Math.sin(c)*Math.sin(a)+Math.cos(c)*Math.cos(a)*Math.cos(l-h)<0)return{x:0,y:0,visible:!1};const f=Math.min(r,s)/2-10,m=r/2+f*Math.cos(a)*Math.sin(l-h),j=s/2-f*(Math.cos(c)*Math.sin(a)-Math.sin(c)*Math.cos(a)*Math.cos(l-h));return{x:m,y:j,visible:!0}}function Ut(e,t,r,s){const i=[[0,1,0],[5,.9986,.062],[10,.9954,.124],[15,.99,.186],[20,.9822,.248],[25,.973,.31],[30,.96,.372],[35,.9427,.434],[40,.9216,.4958],[45,.8962,.5571],[50,.8679,.6176],[55,.835,.6769],[60,.7986,.7346],[65,.7597,.7903],[70,.7186,.8435],[75,.6732,.8936],[80,.6213,.9394],[85,.5722,.9761],[90,.5322,1]],o=Math.abs(e);let a=1,l=0;for(let f=0;f<i.length-1;f++)if(o>=i[f][0]&&o<=i[f+1][0]){const m=(o-i[f][0])/5;a=i[f][1]+m*(i[f+1][1]-i[f][1]),l=i[f][2]+m*(i[f+1][2]-i[f][2]);break}const c=r/(2*Math.PI),h=r/2+c*we(t)*a,p=s/2-c*l*1.3523*Math.sign(e);return{x:h,y:p}}const Zt=`
59
+ `)}async searchDatabase(t,r,s=10){var i,o;try{if(t==="crossref")return await this.searchCrossref(r,s);if(t==="pubmed")return await this.searchPubMed(r,s);throw new Error(`Unknown database: ${t}`)}catch(a){return(o=(i=this.config).onError)==null||o.call(i,a),{source:t,total:0,results:[]}}}async searchCrossref(t,r){const s=new URLSearchParams({query:t,rows:String(r)});this.config.crossrefEmail&&s.set("mailto",this.config.crossrefEmail);const i=await fetch(`https://api.crossref.org/works?${s}`);if(!i.ok)throw new Error(`Crossref API error: ${i.status}`);const o=await i.json(),a=o.message.items.map(l=>{var c,u,x,y,f,m;return{type:"article",title:((c=l.title)==null?void 0:c[0])||"",authors:(l.author||[]).map(M=>({given:M.given||"",family:M.family||"",orcid:M.ORCID})),year:(y=(x=(u=l.published)==null?void 0:u["date-parts"])==null?void 0:x[0])==null?void 0:y[0],journal:(f=l["container-title"])==null?void 0:f[0],volume:l.volume,issue:l.issue,pages:l.page,doi:l.DOI,issn:(m=l.ISSN)==null?void 0:m[0],publisher:l.publisher,abstract:l.abstract,sourceDatabase:"crossref"}});return{source:"crossref",total:o.message["total-results"],results:a}}async searchPubMed(t,r){const s=`https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=${encodeURIComponent(t)}&retmax=${r}&retmode=json`,i=await fetch(s);if(!i.ok)throw new Error(`PubMed API error: ${i.status}`);const o=await i.json(),a=o.esearchresult.idlist;if(a.length===0)return{source:"pubmed",total:0,results:[]};const l=`https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=${a.join(",")}&retmode=json`,c=await fetch(l);if(!c.ok)throw new Error(`PubMed API error: ${c.status}`);const u=await c.json(),x=a.map(y=>{var m;const f=u.result[y];return{type:"article",title:f.title||"",authors:(f.authors||[]).map(M=>{const E=M.name.split(" ");return{family:E.pop()||"",given:E.join(" ")}}),year:f.pubdate?parseInt(f.pubdate.split(" ")[0],10):void 0,journal:f.source,volume:f.volume,issue:f.issue,pages:f.pages,pmid:y,doi:(m=f.elocationid)==null?void 0:m.replace("doi: ",""),sourceDatabase:"pubmed"}});return{source:"pubmed",total:parseInt(o.esearchresult.count,10),results:x}}async fetchByDOI(t){var r,s,i,o,a;try{const l=await fetch(`https://api.crossref.org/works/${encodeURIComponent(t)}`);if(!l.ok)return null;const u=(await l.json()).message;return this.addCitation({type:"article",title:((r=u.title)==null?void 0:r[0])||"",authors:(u.author||[]).map(x=>({given:x.given||"",family:x.family||"",orcid:x.ORCID})),year:(o=(i=(s=u.published)==null?void 0:s["date-parts"])==null?void 0:i[0])==null?void 0:o[0],journal:(a=u["container-title"])==null?void 0:a[0],volume:u.volume,issue:u.issue,pages:u.page,doi:u.DOI,publisher:u.publisher,abstract:u.abstract,sourceDatabase:"crossref"})}catch{return null}}updateCollectionCounts(){for(const t of this.collections.values())t.id==="all"?t.citationCount=this.citations.size:t.citationCount=Array.from(this.citations.values()).filter(r=>{var s;return(s=r.collections)==null?void 0:s.includes(t.id)}).length}generateId(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}}function wt(e){return new Ge(e)}const Qe=h.createContext(null);function _e(){const e=h.useContext(Qe);if(!e)throw new Error("useCitation must be used within CitationProvider");return e}const Me={container:{display:"flex",height:"100%",fontFamily:"'Inter', sans-serif",fontSize:"14px"},sidebar:{width:"240px",backgroundColor:"var(--nice-bg-secondary, #f5f5f5)",borderRight:"1px solid var(--nice-border, #e0e0e0)",display:"flex",flexDirection:"column"},main:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},toolbar:{padding:"12px 16px",borderBottom:"1px solid var(--nice-border, #e0e0e0)",display:"flex",gap:"12px",alignItems:"center"},list:{flex:1,overflow:"auto"},listItem:{padding:"12px 16px",borderBottom:"1px solid var(--nice-border, #eee)",cursor:"pointer"},detail:{width:"400px",borderLeft:"1px solid var(--nice-border, #e0e0e0)",overflow:"auto",padding:"16px"},input:{padding:"8px 12px",border:"1px solid var(--nice-border, #ddd)",borderRadius:"4px",fontSize:"14px"},button:{padding:"8px 16px",backgroundColor:"var(--nice-primary-hover, #1976d2)",color:"white",border:"none",borderRadius:"4px",cursor:"pointer"}};function St({service:e,className:t,style:r}){const{t:s}=pe.useNiceTranslation(),[i,o]=h.useState([]),[a,l]=h.useState([]),[c,u]=h.useState("all"),[x,y]=h.useState(null),[f,m]=h.useState(""),[M,E]=h.useState("apa"),q=h.useCallback(()=>{o(e.listCitations(c)),l(e.listCollections())},[e,c]),re=h.useMemo(()=>f?e.searchCitations(f,{collection:c}):i,[i,f,c,e]),U=h.useMemo(()=>i.find(B=>B.id===x),[i,x]),te={service:e,citations:i,collections:a,selectedCollection:c,setSelectedCollection:u,selectedCitation:x,setSelectedCitation:y,searchQuery:f,setSearchQuery:m,citationStyle:M,setCitationStyle:E,refresh:q};return n.jsx(Qe.Provider,{value:te,children:n.jsxs("div",{className:t,style:{...Me.container,...r},children:[n.jsxs("div",{style:Me.sidebar,children:[n.jsx("div",{style:{padding:"16px",fontWeight:600},children:s("citation.collections","Collections")}),a.map(B=>n.jsxs("div",{role:"button",tabIndex:0,onKeyDown:pe.clickOnActivationKey,onClick:()=>{u(B.id),q()},style:{...Me.listItem,backgroundColor:c===B.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsx("div",{children:B.name}),n.jsx("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:s("citation.items","{citationCount} items").replace("{citationCount}",String(B.citationCount))})]},B.id))]}),n.jsxs("div",{style:Me.main,children:[n.jsxs("div",{style:Me.toolbar,children:[n.jsx("input",{type:"text",placeholder:s("citation.searchReferences","Search references..."),value:f,onChange:B=>m(B.target.value),style:{...Me.input,flex:1}}),n.jsxs("select",{value:M,onChange:B=>E(B.target.value),style:Me.input,children:[n.jsx("option",{value:"apa",children:s("citation.apa","APA")}),n.jsx("option",{value:"mla",children:s("citation.mla","MLA")}),n.jsx("option",{value:"chicago",children:s("citation.chicago","Chicago")}),n.jsx("option",{value:"harvard",children:s("citation.harvard","Harvard")}),n.jsx("option",{value:"ieee",children:s("citation.ieee","IEEE")}),n.jsx("option",{value:"vancouver",children:s("citation.vancouver","Vancouver")}),n.jsx("option",{value:"bibtex",children:"BibTeX"})]}),n.jsx(kt,{})]}),n.jsxs("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[n.jsxs("div",{style:Me.list,children:[re.map(B=>n.jsxs("div",{role:"button",tabIndex:0,onKeyDown:pe.clickOnActivationKey,onClick:()=>y(B.id),style:{...Me.listItem,backgroundColor:x===B.id?"var(--nice-primary-bg, #e3f2fd)":"transparent"},children:[n.jsx("div",{style:{fontWeight:500,marginBottom:"4px"},children:B.title}),n.jsxs("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #666)"},children:[B.authors.map(ie=>ie.family).join(", "),B.year&&` (${B.year})`]}),B.journal&&n.jsx("div",{style:{fontSize:"12px",color:"var(--nice-text-secondary, #888)",fontStyle:"italic"},children:B.journal})]},B.id)),re.length===0&&n.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--nice-text-secondary, #666)"},children:s("citation.noReferencesFound","No references found")})]}),U&&n.jsx("div",{style:Me.detail,children:n.jsx(Ct,{citation:U})})]})]})]})})}function kt(){const{t:e}=pe.useNiceTranslation(),{service:t,refresh:r}=_e(),[s,i]=h.useState(!1),[o,a]=h.useState(""),[l,c]=h.useState(!1),u=async()=>{if(o.trim()){c(!0);try{await t.fetchByDOI(o.trim()),r(),a(""),i(!1)}finally{c(!1)}}};return n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>i(!0),style:Me.button,children:e("citation.addReference","+ Add Reference")}),s&&n.jsx("div",{role:"presentation",style:{position:"fixed",inset:0,backgroundColor:"var(--nice-overlay-50, rgba(0, 0, 0, 0.5))",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},onClick:()=>i(!1),children:n.jsxs("div",{role:"presentation",style:{backgroundColor:"white",padding:"24px",borderRadius:"8px",width:"400px"},onClick:x=>x.stopPropagation(),children:[n.jsx("h3",{style:{margin:"0 0 16px 0"},children:e("citation.addReferenceByDoi","Add Reference by DOI")}),n.jsx("input",{type:"text",value:o,onChange:x=>a(x.target.value),placeholder:e("citation.enterDoiEG10","Enter DOI (e.g., 10.1000/xyz123)"),style:{...Me.input,width:"100%",marginBottom:"16px"}}),n.jsxs("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[n.jsx("button",{onClick:()=>i(!1),style:{...Me.button,backgroundColor:"var(--nice-bg-tertiary, #9e9e9e)"},children:e("citation.cancel","Cancel")}),n.jsx("button",{onClick:u,disabled:l,style:Me.button,children:l?e("citation.loading","Loading..."):e("citation.add","Add")})]})]})})]})}function Ct({citation:e}){const{t}=pe.useNiceTranslation(),{service:r,citationStyle:s}=_e(),[i,o]=h.useState(!1),a=h.useMemo(()=>r.formatCitation(e.id,s),[r,e.id,s]),l=()=>{navigator.clipboard.writeText(a),o(!0),setTimeout(()=>o(!1),2e3)};return n.jsxs("div",{children:[n.jsx("h2",{style:{margin:"0 0 8px 0",fontSize:"18px"},children:e.title}),n.jsx("div",{style:{color:"var(--nice-text-secondary, #666)",marginBottom:"16px"},children:e.authors.map(c=>`${c.given} ${c.family}`).join(", ")}),n.jsxs("div",{style:{marginBottom:"16px"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"8px"},children:[n.jsx("strong",{children:t("citation.formatted","Formatted ({citationStyle})").replace("{citationStyle}",String(s.toUpperCase()))}),n.jsx("button",{onClick:l,style:{...Me.button,padding:"4px 8px",fontSize:"12px"},children:i?t("citation.copied","Copied!"):t("citation.copy","Copy")})]}),n.jsx("div",{style:{padding:"12px",backgroundColor:"var(--nice-bg-secondary, #f5f5f5)",borderRadius:"4px",whiteSpace:"pre-wrap",fontSize:"13px"},dangerouslySetInnerHTML:{__html:a.replace(/\*([^*]+)\*/g,"<em>$1</em>")}})]}),n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px",fontSize:"13px"},children:[e.journal&&n.jsxs("div",{children:[n.jsx("strong",{children:t("citation.journal","Journal:")})," ",e.journal]}),e.year&&n.jsxs("div",{children:[n.jsx("strong",{children:t("citation.year","Year:")})," ",e.year]}),e.volume&&n.jsxs("div",{children:[n.jsx("strong",{children:t("citation.volume","Volume:")})," ",e.volume,e.issue&&`(${e.issue})`]}),e.pages&&n.jsxs("div",{children:[n.jsx("strong",{children:t("citation.pages","Pages:")})," ",e.pages]}),e.doi&&n.jsxs("div",{children:[n.jsx("strong",{children:t("citation.doi","DOI:")})," ",n.jsx("a",{href:`https://doi.org/${e.doi}`,target:"_blank",rel:"noopener noreferrer",children:e.doi})]}),e.pmid&&n.jsxs("div",{children:[n.jsx("strong",{children:t("citation.pmid","PMID:")})," ",n.jsx("a",{href:`https://pubmed.ncbi.nlm.nih.gov/${e.pmid}`,target:"_blank",rel:"noopener noreferrer",children:e.pmid})]}),e.abstract&&n.jsxs("div",{style:{marginTop:"8px"},children:[n.jsx("strong",{children:t("citation.abstract","Abstract:")}),n.jsx("p",{style:{margin:"8px 0 0 0",color:"var(--nice-text, #444)"},children:e.abstract})]})]})]})}const Nt=[],At={series:[],xAxes:[],yAxes:[],annotations:[],selectedSeries:[],zoom:{x:null,y:null},cursor:null,hoveredPoint:null};function Ie(e){return e.reduce((t,r)=>t+r,0)/e.length}function Dt(e){const t=[...e].sort((s,i)=>s-i),r=Math.floor(t.length/2);return t.length%2?t[r]:(t[r-1]+t[r])/2}function Re(e){const t=Ie(e),r=e.map(s=>Math.pow(s-t,2));return Math.sqrt(Ie(r))}function zt(e){return Re(e)/Math.sqrt(e.length)}function It(e){const t=Ie(e),r=zt(e),s=1.96;return[t-s*r,t+s*r]}function Et(e){const t=e.length,r=e.map(M=>typeof M.x=="number"?M.x:0),s=e.map(M=>M.y),i=r.reduce((M,E)=>M+E,0),o=s.reduce((M,E)=>M+E,0),a=r.reduce((M,E,q)=>M+E*s[q],0),l=r.reduce((M,E)=>M+E*E,0),c=(t*a-i*o)/(t*l-i*i),u=(o-c*i)/t,x=o/t,y=s.reduce((M,E)=>M+Math.pow(E-x,2),0),m=1-s.reduce((M,E,q)=>M+Math.pow(E-(c*r[q]+u),2),0)/y;return{slope:c,intercept:u,r2:m}}function Ft(e,t){const r=Ie(e),s=Ie(t),i=Re(e)**2,o=Re(t)**2,a=e.length,l=t.length,c=((a-1)*i+(l-1)*o)/(a+l-2),u=Math.sqrt(c*(1/a+1/l)),x=(r-s)/u,y=Math.exp(-.717*Math.abs(x)-.416*x*x);return{t:x,p:y,significant:y<.05}}function Oe(e,t,r,s=5){const o=(t-e)/(s-1);return Array.from({length:s},(a,l)=>e+l*o)}function We(e,t){return Math.abs(e)>=1e6?(e/1e6).toFixed(1)+"M":Math.abs(e)>=1e3?(e/1e3).toFixed(1)+"K":Math.abs(e)<.01?e.toExponential(2):e.toFixed(2).replace(/\.?0+$/,"")}function Bt({series:e=Nt,title:t,subtitle:r,width:s="100%",height:i=400,type:o="scatter",xAxis:a,yAxis:l,statOverlays:c=[],annotations:u=[],legend:x={show:!0,position:"top",orientation:"horizontal",interactive:!0},tooltip:y={enabled:!0,mode:"point"},zoom:f={enabled:!0,mode:"xy",wheel:!0,drag:!0,resetButton:!0},export:m,statisticalTests:M=[],gridLines:E=!0,aspectRatio:q,animation:re=!0,theme:U="light",onPointClick:te,onPointHover:B,onZoomChange:ie,onAnnotationChange:me,onExport:ee,className:je,style:ue}){const{t:Q}=pe.useNiceTranslation(),oe=h.useRef(null),P=h.useRef(null);h.useRef(null);const[se,ge]=h.useState({...At,series:e,annotations:u}),[we,xe]=h.useState({width:0,height:0}),[Y,H]=h.useState({x:null,y:null}),[he,Z]=h.useState(null),[ne,fe]=h.useState(new Set(e.map(d=>d.id))),$=h.useMemo(()=>{const d=e.filter(_=>ne.has(_.id)&&_.visible!==!1);if(d.length===0)return{xMin:0,xMax:1,yMin:0,yMax:1};let j=1/0,k=-1/0,L=1/0,V=-1/0;for(const _ of d)for(const G of _.data){const be=typeof G.x=="number"?G.x:0;if(j=Math.min(j,be),k=Math.max(k,be),L=Math.min(L,G.y),V=Math.max(V,G.y),G.error){const[ce,ye]=Array.isArray(G.error)?G.error:[-G.error,G.error];L=Math.min(L,G.y+ce),V=Math.max(V,G.y+ye)}}const de=(k-j)*.05||.5,le=(V-L)*.05||.5;return{xMin:j-de,xMax:k+de,yMin:L-le,yMax:V+le}},[e,ne]),J=h.useMemo(()=>{const d={};for(const j of e){if(!ne.has(j.id))continue;const k=j.data.map(L=>L.y);c.includes("mean")&&(d[`${j.id}_mean`]=Ie(k)),c.includes("median")&&(d[`${j.id}_median`]=Dt(k)),c.includes("std-dev")&&(d[`${j.id}_std`]=Re(k)),c.includes("regression")&&(d[`${j.id}_regression`]=Et(j.data)),c.includes("confidence-interval")&&(d[`${j.id}_ci95`]=It(k))}return d},[e,ne,c]),ae=h.useMemo(()=>M.map(d=>{if(d.type==="t-test"&&d.series.length===2){const j=e.find(L=>L.id===d.series[0]),k=e.find(L=>L.id===d.series[1]);if(j&&k){const L=Ft(j.data.map(V=>V.y),k.data.map(V=>V.y));return{...d,result:{statistic:L.t,pValue:L.p,significant:L.significant,interpretation:L.significant?`Significant difference (p = ${L.p.toFixed(4)})`:`No significant difference (p = ${L.p.toFixed(4)})`}}}}return d}),[M,e]),S=h.useCallback(d=>{fe(j=>{const k=new Set(j);return k.has(d)?k.delete(d):k.add(d),k})},[]),D=h.useCallback(()=>{H({x:null,y:null}),ie==null||ie(null,null)},[ie]),A=h.useMemo(()=>{switch(U){case"dark":return["var(--nice-primary-light, #60a5fa)","var(--nice-color-accent-pink, #f472b6)","var(--nice-success-light, #34d399)","var(--nice-warning-light, #fbbf24)","var(--nice-accent, #a78bfa)","#fb923c"];case"publication":return["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b"];case"presentation":return["var(--nice-primary, #3b82f6)","var(--nice-danger, #ef4444)","var(--nice-success, #22c55e)","var(--nice-warning, #f59e0b)","var(--nice-accent, #8b5cf6)","var(--nice-color-accent-pink, #ec4899)"];default:return["var(--nice-primary-hover, #2563eb)","var(--nice-danger-dark, #dc2626)","var(--nice-success-dark, #16a34a)","#ca8a04","var(--nice-accent, #7c3aed)","var(--nice-color-accent-pink, #db2777)"]}},[U]),N=h.useMemo(()=>{switch(U){case"dark":return{bg:"var(--nice-bg-secondary, #1f2937)",text:"var(--nice-text-primary, #f3f4f6)",grid:"var(--nice-text, #374151)",axis:"var(--nice-text-muted, #9ca3af)",tooltip:"var(--nice-text, #374151)"};case"publication":return{bg:"var(--nice-bg, #fff)",text:"var(--nice-text, #000000)",grid:"var(--nice-border, #e5e5e5)",axis:"var(--nice-text, #333333)",tooltip:"var(--nice-bg, #fff)"};default:return{bg:"var(--nice-bg, #fff)",text:"var(--nice-text, #1f2937)",grid:"var(--nice-border, #e5e7eb)",axis:"var(--nice-text-secondary, #4b5563)",tooltip:"var(--nice-bg, #fff)"}}},[U]),R=(d,j)=>({x:10+((typeof d.x=="number"?d.x:j)-$.xMin)/($.xMax-$.xMin)*85,y:90-(d.y-$.yMin)/($.yMax-$.yMin)*85}),X=he?e.find(d=>d.id===he.seriesId):void 0,T=he?X==null?void 0:X.data[he.pointIndex]:void 0,W=he&&T?R(T,he.pointIndex):null,g=((m==null?void 0:m.formats)??[]).filter(d=>d!=="pdf"||!!ee),z=d=>{if(ee){ee(d);return}const j=(t||"chart").replace(/[^\w-]+/g,"_"),k=(ce,ye)=>{const ve=URL.createObjectURL(ce),$e=document.createElement("a");$e.href=ve,$e.download=`${j}.${ye}`,$e.click(),URL.revokeObjectURL(ve)},L=e.filter(ce=>ne.has(ce.id)&&ce.visible!==!1);if(d==="csv"){const ce=ve=>JSON.stringify(ve instanceof Date?ve.toISOString():ve??""),ye=L.flatMap(ve=>ve.data.map($e=>[ve.name,$e.x,$e.y].map(ce).join(",")));k(new Blob([["series,x,y",...ye].join(`
60
+ `)],{type:"text/csv"}),"csv");return}if(d==="json"){const ce=L.map(ye=>({id:ye.id,name:ye.name,data:ye.data}));k(new Blob([JSON.stringify(ce,null,2)],{type:"application/json"}),"json");return}const V=P.current;if(!V)return;const de=new XMLSerializer().serializeToString(V);if(d==="svg"){k(new Blob([de],{type:"image/svg+xml"}),"svg");return}const le=V.getBoundingClientRect(),_=((m==null?void 0:m.dpi)??96)/96,G=document.createElement("canvas");G.width=Math.round(((m==null?void 0:m.width)??le.width)*_),G.height=Math.round(((m==null?void 0:m.height)??le.height)*_);const be=new Image;be.onload=()=>{var ce;(ce=G.getContext("2d"))==null||ce.drawImage(be,0,0,G.width,G.height),G.toBlob(ye=>ye&&k(ye,"png"))},be.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(de)}`};return n.jsxs("div",{ref:oe,className:`nice-scientific-chart nice-scientific-chart--${U} ${je||""}`,style:{width:s,height:q?"auto":i,aspectRatio:q==null?void 0:q.toString(),backgroundColor:N.bg,color:N.text,fontFamily:U==="publication"?"Times New Roman, serif":"system-ui, sans-serif",...ue},children:[t&&n.jsxs("div",{className:"nice-scientific-chart__title",children:[t,r&&n.jsx("div",{className:"nice-scientific-chart__subtitle",style:{color:N.axis},children:r})]}),x.show&&n.jsx("div",{className:"nice-scientific-chart__legend",style:{flexDirection:x.orientation==="vertical"?"column":"row"},children:e.map((d,j)=>n.jsxs("button",{type:"button",className:"nice-scientific-chart__legend-item",onClick:()=>x.interactive&&S(d.id),style:{cursor:x.interactive?"pointer":"default",opacity:ne.has(d.id)?1:.4},children:[n.jsx("span",{className:"nice-scientific-chart__swatch",style:{backgroundColor:d.color||A[j%A.length]}}),d.name]},d.id))}),n.jsxs("div",{className:"nice-scientific-chart__canvas",children:[n.jsxs("svg",{ref:P,width:"100%",height:"100%",children:[E&&n.jsxs("g",{className:"nice-scientific-chart__grid",stroke:N.grid,strokeWidth:1,children:[[0,.25,.5,.75,1].map(d=>n.jsx("line",{x1:"10%",y1:`${d*100}%`,x2:"95%",y2:`${d*100}%`,strokeDasharray:"2,2"},`h-${d}`)),[0,.25,.5,.75,1].map(d=>n.jsx("line",{x1:`${10+d*85}%`,y1:"5%",x2:`${10+d*85}%`,y2:"90%",strokeDasharray:"2,2"},`v-${d}`))]}),e.filter(d=>ne.has(d.id)&&d.visible!==!1).map((d,j)=>{var V,de,le;const k=d.color||A[j%A.length],L=d.type||o;return n.jsx("g",{className:"nice-scientific-chart__series",children:L==="scatter"||L==="line"?n.jsxs(n.Fragment,{children:[L==="line"&&d.data.length>1&&n.jsx("svg",{x:"0",y:"0",width:"100%",height:"100%",viewBox:"0 0 100 100",preserveAspectRatio:"none",style:{overflow:"visible"},children:n.jsx("polyline",{fill:"none",stroke:k,strokeWidth:((V=d.line)==null?void 0:V.width)||2,vectorEffect:"non-scaling-stroke",strokeDasharray:((de=d.line)==null?void 0:de.style)==="dashed"?"5,5":((le=d.line)==null?void 0:le.style)==="dotted"?"2,2":void 0,points:d.data.map((_,G)=>{const be=10+((typeof _.x=="number"?_.x:G)-$.xMin)/($.xMax-$.xMin)*85,ce=90-(_.y-$.yMin)/($.yMax-$.yMin)*85;return`${be},${ce}`}).join(" ")})}),d.data.map((_,G)=>{var ve,$e,Ce,v,w;const be=10+((typeof _.x=="number"?_.x:G)-$.xMin)/($.xMax-$.xMin)*85,ce=90-(_.y-$.yMin)/($.yMax-$.yMin)*85,ye=_.size||((ve=d.marker)==null?void 0:ve.size)||6;return n.jsxs("g",{className:"nice-scientific-chart__point",children:[_.error&&n.jsx("line",{x1:`${be}%`,y1:`${90-(_.y+(Array.isArray(_.error)?_.error[1]:_.error)-$.yMin)/($.yMax-$.yMin)*85}%`,x2:`${be}%`,y2:`${90-(_.y-(Array.isArray(_.error)?Math.abs(_.error[0]):_.error)-$.yMin)/($.yMax-$.yMin)*85}%`,stroke:k,strokeWidth:1}),n.jsx("circle",{cx:`${be}%`,cy:`${ce}%`,r:ye/2,fill:_.color||(($e=d.marker)==null?void 0:$e.fillColor)||k,stroke:((Ce=d.marker)==null?void 0:Ce.strokeColor)||k,strokeWidth:((v=d.marker)==null?void 0:v.strokeWidth)||1,opacity:((w=d.marker)==null?void 0:w.opacity)??1,style:{cursor:te?"pointer":void 0},onMouseEnter:()=>{Z({seriesId:d.id,pointIndex:G}),B==null||B(_,d)},onMouseLeave:()=>{Z(null),B==null||B(null,null)},onClick:I=>te==null?void 0:te(_,d,I)})]},G)}),J[`${d.id}_regression`]&&n.jsx("line",{x1:"10%",y1:`${90-(J[`${d.id}_regression`].intercept+J[`${d.id}_regression`].slope*$.xMin-$.yMin)/($.yMax-$.yMin)*85}%`,x2:"95%",y2:`${90-(J[`${d.id}_regression`].intercept+J[`${d.id}_regression`].slope*$.xMax-$.yMin)/($.yMax-$.yMin)*85}%`,stroke:k,strokeWidth:1,strokeDasharray:"5,3",opacity:.7}),J[`${d.id}_mean`]&&n.jsx("line",{x1:"10%",y1:`${90-(J[`${d.id}_mean`]-$.yMin)/($.yMax-$.yMin)*85}%`,x2:"95%",y2:`${90-(J[`${d.id}_mean`]-$.yMin)/($.yMax-$.yMin)*85}%`,stroke:k,strokeWidth:1,strokeDasharray:"10,5",opacity:.5})]}):null},d.id)}),n.jsxs("g",{className:"nice-scientific-chart__axes",stroke:N.axis,strokeWidth:1,children:[n.jsx("line",{x1:"10%",y1:"90%",x2:"95%",y2:"90%"}),n.jsx("line",{x1:"10%",y1:"5%",x2:"10%",y2:"90%"}),Oe($.xMin,$.xMax,"linear",6).map((d,j)=>n.jsxs("g",{children:[n.jsx("line",{x1:`${10+j*17}%`,y1:"90%",x2:`${10+j*17}%`,y2:"92%"}),n.jsx("text",{x:`${10+j*17}%`,y:"96%",textAnchor:"middle",fill:N.axis,fontSize:"0.75rem",children:We(d)})]},`x-${j}`)),Oe($.yMin,$.yMax,"linear",6).map((d,j)=>n.jsxs("g",{children:[n.jsx("line",{x1:"8%",y1:`${90-j*17}%`,x2:"10%",y2:`${90-j*17}%`}),n.jsx("text",{x:"7%",y:`${90-j*17}%`,textAnchor:"end",dominantBaseline:"middle",fill:N.axis,fontSize:"0.75rem",children:We(d)})]},`y-${j}`))]}),u.filter(d=>d.visible!==!1).map(d=>{var j,k,L,V,de,le,_;return n.jsxs("g",{className:"nice-scientific-chart__annotation",children:[d.type==="text"&&d.text&&n.jsx("text",{x:`${10+(d.position.x-$.xMin)/($.xMax-$.xMin)*85}%`,y:`${90-(d.position.y-$.yMin)/($.yMax-$.yMin)*85}%`,fill:((j=d.style)==null?void 0:j.color)||N.text,fontSize:((k=d.style)==null?void 0:k.fontSize)||12,fontWeight:(L=d.style)==null?void 0:L.fontWeight,children:d.text}),d.type==="line"&&n.jsx("line",{x1:`${10+(d.position.x-$.xMin)/($.xMax-$.xMin)*85}%`,y1:`${90-(d.position.y-$.yMin)/($.yMax-$.yMin)*85}%`,x2:`${10+(d.position.x2-$.xMin)/($.xMax-$.xMin)*85}%`,y2:`${90-(d.position.y2-$.yMin)/($.yMax-$.yMin)*85}%`,stroke:((V=d.style)==null?void 0:V.color)||N.text,strokeWidth:((de=d.style)==null?void 0:de.lineWidth)||1,strokeDasharray:((le=d.style)==null?void 0:le.lineStyle)==="dashed"?"5,5":((_=d.style)==null?void 0:_.lineStyle)==="dotted"?"2,2":void 0})]},d.id)})]}),y.enabled&&he&&W&&n.jsx("div",{className:"nice-scientific-chart__tooltip",style:{background:N.tooltip,borderColor:N.grid,left:`${W.x}%`,top:`${W.y}%`,transform:`translate(${W.x>65?"calc(-100% - 10px)":"10px"}, ${W.y<25?"10px":"calc(-100% - 10px)"})`},children:(()=>{const d=X,j=T;return!d||!j?null:y.format?y.format(j,d):n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"nice-scientific-chart__tooltip-title",children:d.name}),n.jsxs("div",{children:["X: ",j.x instanceof Date?j.x.toISOString():String(j.x)]}),n.jsxs("div",{children:["Y: ",j.y.toFixed(4)]}),j.error&&n.jsx("div",{children:Q("scientificChart.error","Error: ±{error}").replace("{error}",String(Array.isArray(j.error)?`${j.error[0]}, +${j.error[1]}`:j.error))})]})})()})]}),ae.some(d=>d.result)&&n.jsxs("div",{className:"nice-scientific-chart__stats",style:{borderTopColor:N.grid},children:[n.jsx("strong",{children:Q("scientificChart.statisticalTests","Statistical Tests:")}),ae.filter(d=>d.result).map((d,j)=>n.jsxs("div",{children:[d.type,": ",d.result.interpretation]},j))]}),f.enabled&&f.resetButton&&(Y.x||Y.y)&&n.jsx("button",{type:"button",className:"nice-scientific-chart__reset-zoom",onClick:D,style:{background:N.bg,borderColor:N.grid},children:Q("scientificChart.resetZoom","Reset Zoom")}),g.length>0&&n.jsxs("div",{className:"nice-scientific-chart__export",style:{borderTopColor:N.grid},children:[n.jsx("span",{className:"nice-scientific-chart__export-label",children:Q("scientificChart.export","Export:")}),g.map(d=>n.jsx("button",{type:"button",className:"nice-scientific-chart__export-btn",style:{borderColor:N.grid},onClick:()=>z(d),children:d.toUpperCase()},d))]})]})}const Rt=[],Xe={rotationX:25,rotationY:-45,rotationZ:0,zoom:1,panX:0,panY:0};function Tt(e,t){const r=t*Math.PI/180,s=Math.cos(r),i=Math.sin(r);return{x:e.x,y:e.y*s-e.z*i,z:e.y*i+e.z*s}}function Lt(e,t){const r=t*Math.PI/180,s=Math.cos(r),i=Math.sin(r);return{x:e.x*s+e.z*i,y:e.y,z:-e.x*i+e.z*s}}function _t(e,t){const r=t*Math.PI/180,s=Math.cos(r),i=Math.sin(r);return{x:e.x*s-e.y*i,y:e.x*i+e.y*s,z:e.z}}function Ne(e,t,r){let s=Tt(e,r.rotationX);s=Lt(s,r.rotationY),s=_t(s,r.rotationZ);const i=s.z+t,o=t/Math.max(i,.1);return{x:(s.x*o*r.zoom+r.panX)*100+50,y:(-s.y*o*r.zoom+r.panY)*100+50,depth:i}}function De(e,t,r,s){const i=Math.max(0,Math.min(1,(e-t)/(r-t))),o={viridis:[[68,1,84],[59,82,139],[33,145,140],[94,201,98],[253,231,37]],plasma:[[13,8,135],[126,3,168],[204,71,120],[248,149,64],[240,249,33]],inferno:[[0,0,4],[87,16,110],[188,55,84],[249,142,9],[252,255,164]],magma:[[0,0,4],[81,18,124],[183,55,121],[254,159,109],[252,253,191]],cividis:[[0,32,77],[57,86,109],[128,133,121],[200,178,107],[253,231,55]],jet:[[0,0,127],[0,0,255],[0,255,255],[255,255,0],[255,0,0],[127,0,0]],rainbow:[[150,0,90],[0,0,200],[0,200,200],[0,200,0],[200,200,0],[200,0,0]],coolwarm:[[59,76,192],[98,130,234],[221,221,221],[220,170,132],[180,4,38]],RdBu:[[103,0,31],[178,24,43],[244,165,130],[247,247,247],[146,197,222],[33,102,172],[5,48,97]],spectral:[[158,1,66],[213,62,79],[253,174,97],[255,255,191],[171,221,164],[43,131,186],[94,79,162]],turbo:[[48,18,59],[86,121,245],[51,185,131],[192,212,49],[249,141,10],[122,4,3]],grayscale:[[0,0,0],[255,255,255]]},a=o[s]||o.viridis,l=i*(a.length-1),c=Math.floor(l),u=l-c;if(c>=a.length-1){const E=a[a.length-1];return`rgb(${E[0]}, ${E[1]}, ${E[2]})`}const x=a[c],y=a[c+1],f=Math.round(x[0]+u*(y[0]-x[0])),m=Math.round(x[1]+u*(y[1]-x[1])),M=Math.round(x[2]+u*(y[2]-x[2]));return`rgb(${f}, ${m}, ${M})`}function Ot({data:e=Rt,title:t,width:r="100%",height:s=500,scene:i={},showColorBar:o=!0,animation:a,showLegend:l=!0,legendPosition:c="top-right",enableRotation:u=!0,enableZoom:x=!0,enablePan:y=!0,showAxes:f=!0,showAxisLabels:m=!0,focalLength:M=3,theme:E="light",onCameraChange:q,onPointClick:re,onPointHover:U,className:te,style:B}){const{t:ie}=pe.useNiceTranslation(),me=h.useRef(null),[ee,je]=h.useState(Xe),[ue,Q]=h.useState(!1),[oe,P]=h.useState(null),[se,ge]=h.useState(null),[we,xe]=h.useState(0),Y=h.useMemo(()=>{let S=1/0,D=-1/0,A=1/0,N=-1/0,R=1/0,X=-1/0,T=1/0,W=-1/0;for(const z of e)if(z.type==="scatter3d")for(const d of z.points)S=Math.min(S,d.x),D=Math.max(D,d.x),A=Math.min(A,d.y),N=Math.max(N,d.y),R=Math.min(R,d.z),X=Math.max(X,d.z),typeof d.color=="number"&&(T=Math.min(T,d.color),W=Math.max(W,d.color));else if(z.type==="surface"||z.type==="wireframe"){const d=z;for(const j of d.xData)S=Math.min(S,j),D=Math.max(D,j);for(const j of d.yData)A=Math.min(A,j),N=Math.max(N,j);for(const j of d.zData)for(const k of j)R=Math.min(R,k),X=Math.max(X,k),T=Math.min(T,k),W=Math.max(W,k)}const g=Math.max(D-S,N-A,X-R)||1;return{xMin:S,xMax:D,yMin:A,yMax:N,zMin:R,zMax:X,colorMin:T,colorMax:W,maxRange:g}},[e]),H=h.useCallback(S=>{const D=2/Y.maxRange;return{x:(S.x-(Y.xMin+Y.xMax)/2)*D,y:(S.y-(Y.yMin+Y.yMax)/2)*D,z:(S.z-(Y.zMin+Y.zMax)/2)*D}},[Y]),he=h.useCallback(S=>{!u&&!y||(Q(!0),P({x:S.clientX,y:S.clientY,viewState:{...ee}}))},[u,y,ee]),Z=h.useCallback(S=>{if(!ue||!oe)return;const D=S.clientX-oe.x,A=S.clientY-oe.y;S.shiftKey&&y?je({...oe.viewState,panX:oe.viewState.panX+D*.002,panY:oe.viewState.panY+A*.002}):u&&je({...oe.viewState,rotationY:oe.viewState.rotationY+D*.5,rotationX:oe.viewState.rotationX+A*.5})},[ue,oe,u,y]),ne=h.useCallback(()=>{Q(!1),P(null)},[]),fe=h.useCallback(S=>{if(!x)return;S.preventDefault();const D=S.deltaY>0?.9:1.1;je(A=>({...A,zoom:Math.max(.1,Math.min(10,A.zoom*D))}))},[x]),$=h.useMemo(()=>{switch(E){case"dark":return{bg:"var(--nice-bg, #1a1a2e)",text:"var(--nice-text-secondary, #e0e0e0)",axis:"var(--nice-text-secondary, #555)",grid:"var(--nice-text, #333)"};case"scientific":return{bg:"var(--nice-bg-secondary, #f8f8f8)",text:"var(--nice-text, #333)",axis:"var(--nice-text-secondary, #666)",grid:"var(--nice-border, #ddd)"};default:return{bg:"var(--nice-bg, #fff)",text:"var(--nice-text, #333)",axis:"var(--nice-text-secondary, #888)",grid:"var(--nice-border, #e0e0e0)"}}},[E]),J=h.useMemo(()=>{var D;const S=[];for(const A of e)if(A.type==="scatter3d"){const N=A,R=N.points.map(X=>{var d,j,k,L,V;const T=H(X),W=Ne(T,M,ee);let g=(d=N.marker)==null?void 0:d.color;if(Array.isArray((j=N.marker)==null?void 0:j.color)){const de=N.points.indexOf(X);g=De(N.marker.color[de],Y.colorMin,Y.colorMax,((k=N.marker)==null?void 0:k.colorScale)||"viridis")}else typeof X.color=="number"&&(g=De(X.color,Y.colorMin,Y.colorMax,((L=N.marker)==null?void 0:L.colorScale)||"viridis"));const z=Array.isArray(X.size)?X.size[0]:X.size||((V=N.marker)==null?void 0:V.size)||5;return{...W,color:g,size:z,original:X}});S.push({type:"scatter",points:R,data:A})}else if(A.type==="surface"||A.type==="wireframe"){const N=A,R=[];for(let X=0;X<N.xData.length;X++)for(let T=0;T<N.yData.length;T++){const W={x:N.xData[X],y:N.yData[T],z:N.zData[X][T]},g=H(W),z=Ne(g,M,ee),d=De(((D=N.colorData)==null?void 0:D[X][T])??N.zData[X][T],Y.colorMin,Y.colorMax,N.colorScale||"viridis");R.push({...z,color:d,size:3,original:W})}S.push({type:A.type,points:R,data:A})}for(const A of S)A.points.sort((N,R)=>N.depth-R.depth);return S},[e,ee,M,H,Y]),ae=h.useMemo(()=>{var A,N,R;if(!f)return null;const S=1.2,D={x:[Ne({x:-S,y:0,z:0},M,ee),Ne({x:S,y:0,z:0},M,ee)],y:[Ne({x:0,y:-S,z:0},M,ee),Ne({x:0,y:S,z:0},M,ee)],z:[Ne({x:0,y:0,z:-S},M,ee),Ne({x:0,y:0,z:S},M,ee)]};return n.jsxs("g",{className:"nice-3d-plot__axes",children:[n.jsx("line",{x1:`${D.x[0].x}%`,y1:`${D.x[0].y}%`,x2:`${D.x[1].x}%`,y2:`${D.x[1].y}%`,stroke:"var(--nice-danger, #e74c3c)",strokeWidth:1.5}),m&&n.jsx("text",{x:`${D.x[1].x+2}%`,y:`${D.x[1].y}%`,fill:"var(--nice-danger, #e74c3c)",fontSize:"12",children:((A=i.xAxis)==null?void 0:A.title)||"X"}),n.jsx("line",{x1:`${D.y[0].x}%`,y1:`${D.y[0].y}%`,x2:`${D.y[1].x}%`,y2:`${D.y[1].y}%`,stroke:"var(--nice-success, #2ecc71)",strokeWidth:1.5}),m&&n.jsx("text",{x:`${D.y[1].x}%`,y:`${D.y[1].y-2}%`,fill:"var(--nice-success, #2ecc71)",fontSize:"12",textAnchor:"middle",children:((N=i.yAxis)==null?void 0:N.title)||"Y"}),n.jsx("line",{x1:`${D.z[0].x}%`,y1:`${D.z[0].y}%`,x2:`${D.z[1].x}%`,y2:`${D.z[1].y}%`,stroke:"var(--nice-primary, #3498db)",strokeWidth:1.5}),m&&n.jsx("text",{x:`${D.z[1].x+2}%`,y:`${D.z[1].y}%`,fill:"var(--nice-primary, #3498db)",fontSize:"12",children:((R=i.zAxis)==null?void 0:R.title)||"Z"})]})},[f,m,ee,M,i]);return n.jsxs("div",{ref:me,className:`nice-3d-plot nice-3d-plot--${E}${ue?" nice-3d-plot--dragging":""} ${te||""}`,style:{width:r,height:s,backgroundColor:$.bg,color:$.text,...B},onMouseDown:he,onMouseMove:Z,onMouseUp:ne,onMouseLeave:ne,onWheel:fe,children:[t&&n.jsx("div",{className:"nice-3d-plot__title",children:t}),n.jsxs("svg",{width:"100%",height:"100%",className:"nice-3d-plot__canvas",children:[ae,J.map((S,D)=>n.jsxs("g",{className:"nice-3d-plot__data",children:[S.type==="scatter"&&S.points.map((A,N)=>{var R;return n.jsx("circle",{cx:`${A.x}%`,cy:`${A.y}%`,r:A.size||4,fill:A.color||"var(--nice-primary, #3498db)",opacity:((R=S.data.marker)==null?void 0:R.opacity)??.8,style:{cursor:re?"pointer":void 0},onMouseEnter:()=>{ge({point:A.original,dataIndex:D}),U==null||U(A.original,D)},onMouseLeave:()=>{ge(null),U==null||U(null,D)},onClick:()=>re==null?void 0:re(A.original,D)},N)}),(S.type==="surface"||S.type==="wireframe")&&S.points.map((A,N)=>n.jsx("rect",{x:`${A.x-1}%`,y:`${A.y-1}%`,width:"2%",height:"2%",fill:A.color||"var(--nice-primary, #3498db)",opacity:S.data.opacity??.7},N))]},S.data.id||D))]}),l&&e.length>1&&n.jsx("div",{style:{position:"absolute",padding:"8px",background:"var(--nice-overlay-light-90, rgba(255, 255, 255, 0.9))",borderRadius:4,fontSize:"0.8rem",...c==="top-right"&&{top:8,right:8},...c==="top-left"&&{top:8,left:8},...c==="bottom-right"&&{bottom:8,right:8},...c==="bottom-left"&&{bottom:8,left:8}},children:e.map((S,D)=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[n.jsx("span",{style:{width:12,height:12,background:"var(--nice-primary, #3498db)",borderRadius:2}}),S.name]},S.id||D))}),o&&Number.isFinite(Y.colorMin)&&Number.isFinite(Y.colorMax)&&n.jsxs("div",{style:{position:"absolute",right:16,top:"50%",transform:"translateY(-50%)",width:16,height:150,background:`linear-gradient(to top, ${De(0,0,1,"viridis")}, ${De(.5,0,1,"viridis")}, ${De(1,0,1,"viridis")})`,borderRadius:2,border:"1px solid var(--nice-border, #ccc)"},children:[n.jsx("div",{style:{position:"absolute",top:-16,right:20,fontSize:"0.7rem"},children:Y.colorMax.toFixed(2)}),n.jsx("div",{style:{position:"absolute",bottom:-16,right:20,fontSize:"0.7rem"},children:Y.colorMin.toFixed(2)})]}),se&&n.jsxs("div",{style:{position:"absolute",bottom:8,left:8,background:"var(--nice-overlay-80, rgba(0, 0, 0, 0.8))",color:"var(--nice-color-white, #fff)",padding:"4px 8px",borderRadius:4,fontSize:"0.75rem"},children:["X: ",se.point.x.toFixed(4),", Y: ",se.point.y.toFixed(4),", Z:"," ",se.point.z.toFixed(4)]}),n.jsx("div",{style:{position:"absolute",bottom:8,right:8,display:"flex",gap:4},children:n.jsx("button",{onClick:()=>je(Xe),style:{padding:"4px 8px",fontSize:"0.75rem",cursor:"pointer"},children:ie("plot3d.resetView","Reset View")})})]})}const He={H:"var(--nice-bg, #fff)",C:"#909090",N:"#3050F8",O:"#FF0D0D",S:"#FFFF30",P:"#FF8000",F:"#90E050",Cl:"#1FF01F",Br:"#A62929",I:"#940094",He:"#D9FFFF",Ne:"#B3E3F5",Ar:"#80D1E3",Kr:"#5CB8D1",Xe:"#429EB0",Li:"#CC80FF",Na:"#AB5CF2",K:"#8F40D4",Rb:"#702EB0",Cs:"#57178F",Be:"#C2FF00",Mg:"#8AFF00",Ca:"#3DFF00",Sr:"var(--nice-success, #00ff00)",Ba:"#00C900",B:"#FFB5B5",Al:"#BFA6A6",Ga:"#C28F8F",In:"#A67573",Tl:"#A6544D",Si:"#F0C8A0",Ge:"#668F8F",Sn:"#668080",Pb:"#575961",As:"#BD80E3",Sb:"#9E63B5",Bi:"#9E4FB5",Se:"#FFA100",Te:"#D47A00",Po:"#AB5C00",Fe:"#E06633",Co:"#F090A0",Ni:"#50D050",Cu:"#C88033",Zn:"#7D80B0",Mn:"#9C7AC7",Cr:"#8A99C7",V:"#A6A6AB",Ti:"#BFC2C7",Sc:"#E6E6E6",Au:"#FFD123",Ag:"#C0C0C0",Pt:"#D0D0E0",Pd:"#006985",Ru:"#248F8F",Rh:"#0A7D8C",Os:"#266696",Ir:"#175487"},Fe={H:.31,C:.77,N:.71,O:.66,S:1.05,P:1.07,F:.57,Cl:1.02,Br:1.2,I:1.39,He:.28,Ne:.58,Ar:1.06,Li:1.28,Na:1.66,K:2.03,Mg:1.41,Ca:1.76,Fe:1.26,Zn:1.22,Cu:1.28,Ni:1.24},Wt={H:1.2,C:1.7,N:1.55,O:1.52,S:1.8,P:1.8,F:1.47,Cl:1.75,Br:1.85,I:1.98,He:1.4,Ne:1.54,Ar:1.88,Li:1.82,Na:2.27,K:2.75,Mg:1.73,Ca:2.31,Fe:2,Zn:1.39,Cu:1.4,Ni:1.63};function Pe(e){const t=[],r=[],s=new Map,i=new Map;let o="Unknown";const a=e.split(`
61
+ `);for(const l of a){const c=l.substring(0,6).trim();if(c==="HEADER")o=l.substring(10,50).trim()||o;else if(c==="ATOM"||c==="HETATM"){const u=parseInt(l.substring(6,11).trim(),10),x=l.substring(12,16).trim(),y=l.substring(17,20).trim(),f=l.substring(21,22).trim()||"A",m=parseInt(l.substring(22,26).trim(),10),M=parseFloat(l.substring(30,38).trim()),E=parseFloat(l.substring(38,46).trim()),q=parseFloat(l.substring(46,54).trim()),re=parseFloat(l.substring(54,60).trim())||1,U=parseFloat(l.substring(60,66).trim())||0,te=l.substring(76,78).trim()||x.replace(/\d/g,"").substring(0,1),B={id:t.length,serial:u,name:x,element:te.toUpperCase(),residueName:y,residueSeq:m,chainId:f,x:M,y:E,z:q,occupancy:re,bFactor:U,color:He[te.toUpperCase()]||"var(--nice-text-secondary, #808080)",radius:Fe[te.toUpperCase()]||1.5};t.push(B);const ie=`${f}_${m}_${y}`;s.has(ie)||s.set(ie,{id:s.size,name:y,seq:m,chainId:f,atoms:[]}),s.get(ie).atoms.push(B.id),i.has(f)||i.set(f,{id:f,residues:[]})}else if(c==="CONECT"){const u=l.substring(6).trim().split(/\s+/).map(Number),x=u[0],y=t.find(f=>f.serial===x);if(y)for(let f=1;f<u.length;f++){const m=u[f],M=t.find(E=>E.serial===m);M&&y.id<M.id&&r.push({id:r.length,atom1:y.id,atom2:M.id,order:1})}}}if(r.length===0)for(let l=0;l<t.length;l++)for(let c=l+1;c<t.length;c++){const u=t[l],x=t[c],y=u.x-x.x,f=u.y-x.y,m=u.z-x.z,M=Math.sqrt(y*y+f*f+m*m),E=(Fe[u.element]||1.5)+(Fe[x.element]||1.5)+.4;M<E&&M>.4&&r.push({id:r.length,atom1:l,atom2:c,order:1,length:M})}return{id:"mol_"+Date.now(),name:o,atoms:t,bonds:r,residues:Array.from(s.values()),chains:Array.from(i.values())}}function Xt(e,t,r,s,i,o){const a=m=>m*Math.PI/180,l=t*Math.cos(a(s))-r*Math.sin(a(s)),c=t*Math.sin(a(s))+r*Math.cos(a(s)),u=e*Math.cos(a(i))+c*Math.sin(a(i)),x=-e*Math.sin(a(i))+c*Math.cos(a(i)),y=u*Math.cos(a(o))-l*Math.sin(a(o)),f=u*Math.sin(a(o))+l*Math.cos(a(o));return[y,f,x]}function Ee(e,t,r,s,i,o){const a=e-i.x,l=t-i.y,c=r-i.z,[u,x,y]=Xt(a,l,c,s.rotX,s.rotY,s.rotZ),f=500,m=f/(f+y*50);return{x:50+u*o*s.zoom*m+s.panX,y:50-x*o*s.zoom*m+s.panY,depth:y}}function Pt({molecule:e,format:t="pdb",style:r="ball-stick",colorScheme:s="element",showHydrogens:i=!0,showWaters:o=!1,showLabels:a=!1,labelType:l="element",width:c="100%",height:u=500,backgroundColor:x="#000000",enableRotation:y=!0,enableZoom:f=!0,showControls:m=!0,measurements:M=[],surfaces:E=[],labels:q=[],selection:re,highlightColor:U="var(--nice-warning, #ffff00)",spin:te=!1,spinSpeed:B=.5,onAtomClick:ie,onAtomHover:me,onSelectionChange:ee,className:je,styleOverride:ue}){const{t:Q}=pe.useNiceTranslation(),oe=h.useRef(null),[P,se]=h.useState(null),[ge,we]=h.useState({rotX:0,rotY:0,rotZ:0,zoom:1,panX:0,panY:0}),[xe,Y]=h.useState(!1),[H,he]=h.useState(null),[Z,ne]=h.useState(null),[fe,$]=h.useState(r);h.useEffect(()=>{if(!e){se(null);return}typeof e=="string"?(t==="pdb"||console.warn(`Format ${t} parsing not implemented, using PDB parser`),se(Pe(e))):se(e)},[e,t]),h.useEffect(()=>{if(!te)return;const g=setInterval(()=>{we(z=>({...z,rotY:(z.rotY+B)%360}))},16);return()=>clearInterval(g)},[te,B]);const{center:J,scale:ae}=h.useMemo(()=>{if(!P||P.atoms.length===0)return{center:{x:0,y:0,z:0},scale:1};let g=1/0,z=-1/0,d=1/0,j=-1/0,k=1/0,L=-1/0;for(const _ of P.atoms)g=Math.min(g,_.x),z=Math.max(z,_.x),d=Math.min(d,_.y),j=Math.max(j,_.y),k=Math.min(k,_.z),L=Math.max(L,_.z);const V={x:(g+z)/2,y:(d+j)/2,z:(k+L)/2},de=Math.max(z-g,j-d,L-k),le=de>0?35/de:1;return{center:V,scale:le}},[P]),S=h.useMemo(()=>P?P.atoms.filter(g=>!i&&g.element==="H"||!o&&g.residueName==="HOH"?!1:g.visible!==!1).map(g=>({atom:g,...Ee(g.x,g.y,g.z,ge,J,ae)})).sort((g,z)=>g.depth-z.depth):[],[P,ge,J,ae,i,o]),D=h.useMemo(()=>P?P.bonds.filter(g=>g.visible!==!1).map(g=>{const z=P.atoms[g.atom1],d=P.atoms[g.atom2];if(!z||!d||!i&&(z.element==="H"||d.element==="H"))return null;const j=Ee(z.x,z.y,z.z,ge,J,ae),k=Ee(d.x,d.y,d.z,ge,J,ae);return{bond:g,x1:j.x,y1:j.y,x2:k.x,y2:k.y,depth:(j.depth+k.depth)/2,color1:z.color,color2:d.color}}).filter(Boolean).sort((g,z)=>g.depth-z.depth):[],[P,ge,J,ae,i]),A=h.useCallback(g=>{y&&(Y(!0),he({x:g.clientX,y:g.clientY,view:{...ge}}))},[y,ge]),N=h.useCallback(g=>{if(!xe||!H)return;const z=g.clientX-H.x,d=g.clientY-H.y;g.shiftKey?we({...H.view,panX:H.view.panX+z*.1,panY:H.view.panY+d*.1}):we({...H.view,rotY:H.view.rotY+z*.5,rotX:H.view.rotX+d*.5})},[xe,H]),R=h.useCallback(()=>{Y(!1),he(null)},[]),X=h.useCallback(g=>{if(!f)return;g.preventDefault();const z=g.deltaY>0?.9:1.1;we(d=>({...d,zoom:Math.max(.1,Math.min(10,d.zoom*z))}))},[f]),T=h.useCallback(g=>{switch(fe){case"space-filling":return(Wt[g.element]||1.5)*4;case"ball-stick":return(Fe[g.element]||.5)*3;case"stick":case"wireframe":return 2;default:return 4}},[fe]),W=h.useCallback(g=>(fe==="wireframe"?1:fe==="stick"?3:2)*(g.order||1),[fe]);return P?n.jsxs("div",{ref:oe,className:`nice-molecular-viewer${xe?" nice-molecular-viewer--dragging":""} ${je||""}`,style:{width:c,height:u,backgroundColor:x,...ue},onMouseDown:A,onMouseMove:N,onMouseUp:R,onMouseLeave:R,onWheel:X,children:[n.jsxs("svg",{width:"100%",height:"100%",className:"nice-molecular-viewer__canvas",children:[fe!=="space-filling"&&D.map((g,z)=>n.jsx("line",{x1:`${g.x1}%`,y1:`${g.y1}%`,x2:`${g.x2}%`,y2:`${g.y2}%`,stroke:g.bond.color||"var(--nice-text-secondary, #888888)",strokeWidth:W(g.bond),strokeLinecap:"round"},`bond-${z}`)),S.map(({atom:g,x:z,y:d})=>{var V;const j=(V=re==null?void 0:re.atoms)==null?void 0:V.includes(g.id),k=(Z==null?void 0:Z.id)===g.id,L=T(g);return n.jsxs("g",{children:[n.jsx("circle",{cx:`${z}%`,cy:`${d}%`,r:L,fill:g.color||He[g.element]||"#808080",stroke:j?U:k?"#fff":"none",strokeWidth:j||k?2:0,style:{cursor:"pointer"},onMouseEnter:()=>{ne(g),me==null||me(g)},onMouseLeave:()=>{ne(null),me==null||me(null)},onClick:()=>ie==null?void 0:ie(g)}),a&&n.jsx("text",{x:`${z}%`,y:`${d-L*.15}%`,fill:"var(--nice-color-white, #fff)",fontSize:"10",textAnchor:"middle",dominantBaseline:"middle",style:{pointerEvents:"none"},children:l==="element"?g.element:l==="name"?g.name:l==="residue"?g.residueName:l==="chain"?g.chainId:l==="serial"?g.serial:g.element})]},`atom-${g.id}`)}),M.map(g=>{if(g.atoms.length<2)return null;const z=P.atoms[g.atoms[0]],d=P.atoms[g.atoms[1]];if(!z||!d)return null;const j=Ee(z.x,z.y,z.z,ge,J,ae),k=Ee(d.x,d.y,d.z,ge,J,ae);return n.jsxs("g",{children:[n.jsx("line",{x1:`${j.x}%`,y1:`${j.y}%`,x2:`${k.x}%`,y2:`${k.y}%`,stroke:g.color||"var(--nice-warning, #ffff00)",strokeWidth:1,strokeDasharray:"3,3"}),n.jsxs("text",{x:`${(j.x+k.x)/2}%`,y:`${(j.y+k.y)/2-1}%`,fill:g.color||"var(--nice-warning, #ffff00)",fontSize:"10",textAnchor:"middle",children:[g.value.toFixed(2)," ",g.unit]})]},g.id)})]}),n.jsxs("div",{style:{position:"absolute",top:8,left:8,color:"var(--nice-text-primary, #fff)",fontSize:"0.8rem"},children:[n.jsx("div",{style:{fontWeight:"bold"},children:P.name}),n.jsx("div",{children:Q("molecularViewer.atomsBonds","{atoms} atoms, {bonds} bonds").replace("{atoms}",String(P.atoms.length)).replace("{bonds}",String(P.bonds.length))}),P.formula&&n.jsx("div",{children:Q("molecularViewer.formula","Formula: {formula}").replace("{formula}",String(P.formula))})]}),Z&&n.jsxs("div",{style:{position:"absolute",bottom:8,left:8,background:"var(--nice-overlay-80, rgba(0, 0, 0, 0.8))",color:"var(--nice-color-white, #fff)",padding:"4px 8px",borderRadius:4,fontSize:"0.75rem"},children:[n.jsxs("div",{children:[n.jsx("b",{children:Z.element})," (",Z.name,")"]}),Z.residueName&&n.jsxs("div",{children:[Q("molecularViewer.residue","Residue:")," ",Z.residueName," ",Z.residueSeq]}),Z.chainId&&n.jsx("div",{children:Q("molecularViewer.chain","Chain: {chainId}").replace("{chainId}",String(Z.chainId))}),n.jsx("div",{children:Q("molecularViewer.position","Position: ({x}, {y}, {z})").replace("{x}",String(Z.x.toFixed(2))).replace("{y}",String(Z.y.toFixed(2))).replace("{z}",String(Z.z.toFixed(2)))})]}),m&&n.jsxs("div",{style:{position:"absolute",top:8,right:8,display:"flex",flexDirection:"column",gap:4},children:[n.jsxs("select",{value:fe,onChange:g=>$(g.target.value),style:{padding:"2px 4px",fontSize:"0.75rem"},children:[n.jsx("option",{value:"ball-stick",children:Q("molecularViewer.ballStick","Ball & Stick")}),n.jsx("option",{value:"space-filling",children:Q("molecularViewer.spaceFilling","Space Filling")}),n.jsx("option",{value:"stick",children:Q("molecularViewer.stick","Stick")}),n.jsx("option",{value:"wireframe",children:Q("molecularViewer.wireframe","Wireframe")})]}),n.jsx("button",{onClick:()=>we({rotX:0,rotY:0,rotZ:0,zoom:1,panX:0,panY:0}),style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:Q("molecularViewer.resetView","Reset View")})]})]}):n.jsx("div",{className:`nice-molecular-viewer nice-molecular-viewer--empty ${je||""}`,style:{width:c,height:u,backgroundColor:x,...ue},children:Q("molecularViewer.loadAMoleculePdbMol","Load a molecule (PDB, MOL, SDF)")})}function Yt(e){let t=0,r=0;function s(){var l;const o={id:`node_${r++}`};if(e[t]==="(")for(t++,o.children=[];;){const c=s();if(c&&(c.parent=o.id,o.children.push(c)),e[t]===","){t++;continue}if(e[t]===")"){t++;break}if(t>=e.length)break}let a="";for(;t<e.length&&!"[:,;()".includes(e[t]);)a+=e[t++];if(a.trim()){const c=a.match(/^([^[\]]+)?(?:\[([^\]]+)\])?$/);if(c){if(o.name=((l=c[1])==null?void 0:l.trim())||void 0,c[2]){const u=parseFloat(c[2]);isNaN(u)||(o.bootstrap=u)}}else o.name=a.trim()}if(e[t]===":"){t++;let c="";for(;t<e.length&&!"[,;()".includes(e[t]);)c+=e[t++];const u=parseFloat(c);isNaN(u)||(o.branchLength=u)}return o}return e.replace(/\s+/g,"").replace(/;$/,"")?s():null}function et(e,t=[]){if(t.push(e),e.children)for(const r of e.children)et(r,t);return t}function tt(e){return!e.children||e.children.length===0?1:e.children.reduce((t,r)=>t+tt(r),0)}function nt(e,t,r){if(!e.children||e.children.length===0||e.collapsed)return t.set(e.id,r.value),r.value+=1,t.get(e.id);let s=1/0,i=-1/0;for(const a of e.children){const l=nt(a,t,r);s=Math.min(s,l),i=Math.max(i,l)}const o=(s+i)/2;return t.set(e.id,o),o}function rt(e,t,r=0){const s=r+(e.branchLength||1);if(t.set(e.id,s),e.children&&!e.collapsed)for(const i of e.children)rt(i,t,s)}function Vt({tree:e,layout:t="rectangular",branchStyle:r="rectangular",nodeShape:s="circle",nodeSize:i=5,showBranchLengths:o=!1,showBootstrap:a=!1,bootstrapThreshold:l=70,showLeafLabels:c=!0,showInternalLabels:u=!1,labelFontSize:x=11,branchWidth:y=1.5,branchColor:f="var(--nice-text-secondary, #666666)",nodeColor:m="var(--nice-text, #333333)",highlightColor:M="var(--nice-primary, #2196f3)",clades:E=[],annotations:q=[],colorScale:re,width:U="100%",height:te=500,padding:B=40,enableZoom:ie=!0,enablePan:me=!0,showControls:ee=!0,onNodeClick:je,onNodeHover:ue,onBranchClick:Q,className:oe,style:P}){const{t:se}=pe.useNiceTranslation(),ge=h.useRef(null),[we,xe]=h.useState(1),[Y,H]=h.useState({x:0,y:0}),[he,Z]=h.useState(!1),[ne,fe]=h.useState(null),[$,J]=h.useState(null),[ae,S]=h.useState(t),[D,A]=h.useState(new Set),N=h.useMemo(()=>e?typeof e=="string"?Yt(e):e:null,[e]),R=h.useMemo(()=>{if(!N)return null;const v=w=>{var I;return{...w,collapsed:D.has(w.id),children:(I=w.children)==null?void 0:I.map(v)}};return v(N)},[N,D]),{positions:X,leafCount:T,maxX:W}=h.useMemo(()=>{if(!R)return{positions:{x:new Map,y:new Map},leafCount:0,maxX:0};const v=new Map,w=new Map,I=tt(R);nt(R,w,{value:0}),rt(R,v,0);const p=Math.max(...Array.from(v.values()));return{positions:{x:v,y:w},leafCount:I,maxX:p||1}},[R]),g=h.useMemo(()=>R?et(R):[],[R]),z=typeof U=="number"?U:800,d=typeof te=="number"?te:500,j=z-B*2,k=d-B*2,L=v=>B+v/W*j*.7,V=v=>B+v/(T-1||1)*k,de=(v,w)=>{const I=w/(T-1||1)*2*Math.PI-Math.PI/2,p=v/W*Math.min(j,k)*.4;return{x:z/2+p*Math.cos(I),y:d/2+p*Math.sin(I)}},le=v=>{const w=X.x.get(v)||0,I=X.y.get(v)||0;return ae==="radial"||ae==="circular"?de(w,I):{x:L(w),y:V(I)}},_=h.useCallback(v=>{me&&(Z(!0),fe({x:v.clientX,y:v.clientY,pan:{...Y}}))},[me,Y]),G=h.useCallback(v=>{if(!he||!ne)return;const w=v.clientX-ne.x,I=v.clientY-ne.y;H({x:ne.pan.x+w,y:ne.pan.y+I})},[he,ne]),be=h.useCallback(()=>{Z(!1),fe(null)},[]),ce=h.useCallback(v=>{if(!ie)return;v.preventDefault();const w=v.deltaY>0?.9:1.1;xe(I=>Math.max(.1,Math.min(5,I*w)))},[ie]),ye=h.useCallback(v=>{A(w=>{const I=new Set(w);return I.has(v)?I.delete(v):I.add(v),I})},[]),ve=(v,w)=>{const I=le(v.id),p=le(w.id);if(ae==="radial"||ae==="circular")return n.jsx("line",{x1:I.x,y1:I.y,x2:p.x,y2:p.y,stroke:w.color||f,strokeWidth:y});switch(r){case"rectangular":return n.jsx("path",{d:`M${I.x},${I.y} H${p.x} V${p.y}`,stroke:w.color||f,strokeWidth:y,fill:"none"});case"diagonal":return n.jsx("line",{x1:I.x,y1:I.y,x2:p.x,y2:p.y,stroke:w.color||f,strokeWidth:y});case"curved":{const b=(I.x+p.x)/2;return n.jsx("path",{d:`M${I.x},${I.y} C${b},${I.y} ${b},${p.y} ${p.x},${p.y}`,stroke:w.color||f,strokeWidth:y,fill:"none"})}default:return n.jsx("line",{x1:I.x,y1:I.y,x2:p.x,y2:p.y,stroke:w.color||f,strokeWidth:y})}},$e=v=>{const w=le(v.id),I=!v.children||v.children.length===0||v.collapsed,p=($==null?void 0:$.id)===v.id,b=p?i*1.5:i,O=(()=>{switch(s){case"circle":return n.jsx("circle",{cx:w.x,cy:w.y,r:b});case"square":return n.jsx("rect",{x:w.x-b,y:w.y-b,width:b*2,height:b*2});case"triangle":{const C=b*1.5;return n.jsx("polygon",{points:`${w.x},${w.y-C} ${w.x-C},${w.y+C} ${w.x+C},${w.y+C}`})}case"diamond":return n.jsx("polygon",{points:`${w.x},${w.y-b} ${w.x+b},${w.y} ${w.x},${w.y+b} ${w.x-b},${w.y}`});case"none":return null;default:return n.jsx("circle",{cx:w.x,cy:w.y,r:b})}})();return n.jsxs("g",{children:[O&&n.jsx("g",{fill:v.highlighted?M:v.color||m,stroke:p?M:"none",strokeWidth:2,style:{cursor:"pointer"},onMouseEnter:()=>{J(v),ue==null||ue(v)},onMouseLeave:()=>{J(null),ue==null||ue(null)},onClick:()=>je==null?void 0:je(v),onDoubleClick:()=>{v.children&&v.children.length>0&&ye(v.id)},children:O}),v.collapsed&&v.children&&n.jsx("polygon",{points:`${w.x+8},${w.y-6} ${w.x+20},${w.y} ${w.x+8},${w.y+6}`,fill:m,opacity:.5}),I&&c&&v.name&&n.jsx("text",{x:w.x+i+5,y:w.y,fontSize:x,fill:"var(--nice-text, #333)",dominantBaseline:"middle",children:v.name}),!I&&u&&v.name&&n.jsx("text",{x:w.x,y:w.y-i-3,fontSize:x*.9,fill:"var(--nice-text-secondary, #666)",textAnchor:"middle",children:v.name}),a&&v.bootstrap!==void 0&&v.bootstrap>=l&&n.jsx("text",{x:w.x,y:w.y-i-2,fontSize:x*.8,fill:"var(--nice-color-accent-pink, #e91e63)",textAnchor:"middle",children:v.bootstrap.toFixed(0)})]},v.id)},Ce=v=>{const w=[];if(v.children&&!v.collapsed)for(const I of v.children)w.push(n.jsx("g",{children:ve(v,I)},`branch-${v.id}-${I.id}`)),w.push(...Ce(I));return w};return R?n.jsxs("div",{ref:ge,className:`nice-phylogenetic-tree${he?" nice-phylogenetic-tree--dragging":""} ${oe||""}`,style:{width:U,height:te,...P},onMouseDown:_,onMouseMove:G,onMouseUp:be,onMouseLeave:be,onWheel:ce,children:[n.jsxs("svg",{width:"100%",height:"100%",style:{transform:`translate(${Y.x}px, ${Y.y}px) scale(${we})`,transformOrigin:"center center"},children:[E.map(v=>{const w=g.filter(F=>v.nodeIds.includes(F.id));if(w.length===0)return null;const I=w.map(F=>le(F.id)),p=Math.min(...I.map(F=>F.x))-10,b=Math.max(...I.map(F=>F.x))+10,O=Math.min(...I.map(F=>F.y))-10,C=Math.max(...I.map(F=>F.y))+10;return n.jsxs("g",{children:[n.jsx("rect",{x:p,y:O,width:b-p,height:C-O,fill:v.background||`${v.color}20`||"var(--nice-primary-bg, #e3f2fd)",stroke:v.color||"var(--nice-primary, #2196f3)",strokeWidth:1,strokeDasharray:"4,2",rx:4}),v.showLabel&&n.jsx("text",{x:b+5,y:(O+C)/2,fontSize:10,fill:v.color||"var(--nice-text-secondary, #666)",dominantBaseline:"middle",children:v.name})]},v.id)}),Ce(R),g.map(v=>$e(v)),q.map(v=>{if(!g.find(b=>b.id===v.nodeId))return null;const I=le(v.nodeId),p={left:{x:-10,y:0},right:{x:10,y:0},above:{x:0,y:-10},below:{x:0,y:10}}[v.position||"right"];return n.jsx("text",{x:I.x+p.x,y:I.y+p.y,fontSize:v.fontSize||9,fill:v.color||"var(--nice-danger, #ff5722)",textAnchor:v.position==="left"?"end":v.position==="right"?"start":"middle",dominantBaseline:"middle",children:v.text},`ann-${v.nodeId}`)})]}),n.jsx("div",{style:{position:"absolute",top:8,left:8,fontSize:"0.75rem",color:"var(--nice-text-secondary, #666)"},children:se("phylogeneticTree.nodesLeaves","{allNodes} nodes • {leafCount} leaves").replace("{allNodes}",String(g.length)).replace("{leafCount}",String(T))}),$&&n.jsxs("div",{style:{position:"absolute",bottom:8,left:8,background:"var(--nice-overlay-light-95, rgba(255, 255, 255, 0.95))",padding:"4px 8px",borderRadius:4,fontSize:"0.75rem",boxShadow:"0 1px 4px var(--nice-overlay-10, rgba(0, 0, 0, 0.1))"},children:[n.jsx("div",{children:n.jsx("b",{children:$.name||$.id})}),$.branchLength!==void 0&&n.jsx("div",{children:se("phylogeneticTree.branchLength","Branch length: {branchLength}").replace("{branchLength}",String($.branchLength.toFixed(4)))}),$.bootstrap!==void 0&&n.jsx("div",{children:se("phylogeneticTree.bootstrap","Bootstrap: {bootstrap}").replace("{bootstrap}",String($.bootstrap))}),$.children&&n.jsx("div",{children:se("phylogeneticTree.children","Children: {children}").replace("{children}",String($.children.length))})]}),ee&&n.jsxs("div",{style:{position:"absolute",top:8,right:8,display:"flex",flexDirection:"column",gap:4},children:[n.jsxs("select",{value:ae,onChange:v=>S(v.target.value),style:{padding:"2px 4px",fontSize:"0.75rem"},children:[n.jsx("option",{value:"rectangular",children:se("phylogeneticTree.rectangular","Rectangular")}),n.jsx("option",{value:"radial",children:se("phylogeneticTree.radial","Radial")}),n.jsx("option",{value:"diagonal",children:se("phylogeneticTree.diagonal","Diagonal")})]}),n.jsx("button",{onClick:()=>{xe(1),H({x:0,y:0})},style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:se("phylogeneticTree.resetView","Reset View")}),n.jsx("button",{onClick:()=>A(new Set),style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:se("phylogeneticTree.expandAll","Expand All")})]})]}):n.jsx("div",{className:`nice-phylogenetic-tree nice-phylogenetic-tree--empty ${oe||""}`,style:{width:U,height:te,...P},children:se("phylogeneticTree.loadAPhylogeneticTreeNewick","Load a phylogenetic tree (Newick format)")})}const ze=e=>e*Math.PI/180;function qt(e,t,r,s){const i=(t+180)/360*r,o=ze(e),a=Math.log(Math.tan(Math.PI/4+o/2)),l=s/2-r*a/(2*Math.PI);return{x:i,y:l}}function Ut(e,t,r,s){const i=(t+180)/360*r,o=(90-e)/180*s;return{x:i,y:o}}function Kt(e,t,r,s,i,o){const a=ze(e),l=ze(t),c=ze(i),u=ze(o);if(Math.sin(c)*Math.sin(a)+Math.cos(c)*Math.cos(a)*Math.cos(l-u)<0)return{x:0,y:0,visible:!1};const y=Math.min(r,s)/2-10,f=r/2+y*Math.cos(a)*Math.sin(l-u),m=s/2-y*(Math.cos(c)*Math.sin(a)-Math.sin(c)*Math.cos(a)*Math.cos(l-u));return{x:f,y:m,visible:!0}}function Zt(e,t,r,s){const i=[[0,1,0],[5,.9986,.062],[10,.9954,.124],[15,.99,.186],[20,.9822,.248],[25,.973,.31],[30,.96,.372],[35,.9427,.434],[40,.9216,.4958],[45,.8962,.5571],[50,.8679,.6176],[55,.835,.6769],[60,.7986,.7346],[65,.7597,.7903],[70,.7186,.8435],[75,.6732,.8936],[80,.6213,.9394],[85,.5722,.9761],[90,.5322,1]],o=Math.abs(e);let a=1,l=0;for(let y=0;y<i.length-1;y++)if(o>=i[y][0]&&o<=i[y+1][0]){const f=(o-i[y][0])/5;a=i[y][1]+f*(i[y+1][1]-i[y][1]),l=i[y][2]+f*(i[y+1][2]-i[y][2]);break}const c=r/(2*Math.PI),u=r/2+c*ze(t)*a,x=s/2-c*l*1.3523*Math.sign(e);return{x:u,y:x}}const Jt=`
61
62
  M 50,30 L 55,28 60,30 65,35 60,40 55,42 50,40 Z
62
63
  M 70,25 L 80,23 85,28 87,35 85,45 78,50 72,48 68,40 70,32 Z
63
64
  M 55,55 L 58,52 65,55 68,60 65,70 58,75 52,70 50,60 Z
64
65
  M 80,55 L 90,50 92,60 88,70 80,75 75,65 Z
65
66
  M 15,30 L 25,28 32,32 35,38 30,45 22,48 15,42 12,35 Z
66
67
  M 30,55 L 35,50 40,52 42,58 38,65 32,68 28,62 Z
67
- `;function Kt({projection:e="equirectangular",layers:t=[],markers:r=[],polylines:s=[],polygons:i=[],heatmap:o,bounds:a,center:l={lat:0,lng:0},zoom:c=1,showGraticule:h=!0,graticuleInterval:p=30,showCoastlines:f=!0,showBorders:m=!1,landColor:j="#D4E6C3",oceanColor:M="#A8D4E6",borderColor:E="var(--nice-text-muted, #999999)",graticuleColor:U="var(--nice-border, #cccccc)",width:Q="100%",height:P=400,enablePan:_=!0,enableZoom:J=!0,showControls:ne=!0,scaleBar:q={show:!0,position:"bottom-left"},legend:ae,showLayerControl:de=!1,onMarkerClick:re,onMarkerHover:H,onMapClick:X,onPolygonClick:oe,onBoundsChange:le,className:pe,style:fe}){var ke,v,k,F;const W=u.useRef(null),[V,se]=u.useState(l),[Z,S]=u.useState(c),[K,G]=u.useState(!1),[ee,te]=u.useState(null),[A,C]=u.useState(null),[d,g]=u.useState(e),[w,I]=u.useState(new Set(t.filter(x=>x.visible!==!1).map(x=>x.id))),z=typeof Q=="number"?Q:800,R=typeof P=="number"?P:400,y=u.useCallback((x,b)=>{switch(d){case"mercator":return Pt(x,b,z,R);case"orthographic":return Vt(x,b,z,R,V.lat,V.lng);case"robinson":return Ut(x,b,z,R);case"equirectangular":default:return qt(x,b,z,R)}},[d,z,R,V]),$=u.useCallback((x,b)=>{const T=x/z*360-180,N=90-b/R*180;return{lat:Math.max(-90,Math.min(90,N)),lng:Math.max(-180,Math.min(180,T))}},[z,R]),D=u.useMemo(()=>{const x=[];for(let b=-90+p;b<90;b+=p){let T="";for(let N=-180;N<=180;N+=5){const B=y(b,N);B.visible!==!1&&(T+=T===""?`M${B.x},${B.y}`:` L${B.x},${B.y}`)}T&&x.push(T)}for(let b=-180;b<=180;b+=p){let T="";for(let N=-90;N<=90;N+=5){const B=y(N,b);B.visible!==!1&&(T+=T===""?`M${B.x},${B.y}`:` L${B.x},${B.y}`)}T&&x.push(T)}return x},[y,p]),L=u.useMemo(()=>{if(d==="orthographic"){const x=Math.min(z,R)/2-10;return`M${z/2+x},${R/2}
68
- A${x},${x} 0 1,1 ${z/2-x},${R/2}
69
- A${x},${x} 0 1,1 ${z/2+x},${R/2}`}return null},[d,z,R]),O=u.useMemo(()=>{const x=[...r];for(const b of t)w.has(b.id)&&b.markers&&x.push(...b.markers);return x},[r,t,w]),ie=u.useMemo(()=>{const x=[...s];for(const b of t)w.has(b.id)&&b.polylines&&x.push(...b.polylines);return x},[s,t,w]),ue=u.useMemo(()=>{const x=[...i];for(const b of t)w.has(b.id)&&b.polygons&&x.push(...b.polygons);return x},[i,t,w]),me=u.useCallback(x=>{_&&(G(!0),te({x:x.clientX,y:x.clientY,center:{...V}}))},[_,V]),xe=u.useCallback(x=>{if(!K||!ee)return;const b=x.clientX-ee.x,T=x.clientY-ee.y,N=-(b/z)*360/Z,B=T/R*180/Z;se({lat:Math.max(-85,Math.min(85,ee.center.lat+B)),lng:(ee.center.lng+N+180)%360-180})},[K,ee,z,R,Z]),he=u.useCallback(()=>{G(!1),te(null)},[]),ve=u.useCallback(x=>{if(!J)return;x.preventDefault();const b=x.deltaY>0?.9:1.1;S(T=>Math.max(.5,Math.min(20,T*b)))},[J]),je=u.useCallback(x=>{var B;if(!X)return;const b=(B=W.current)==null?void 0:B.getBoundingClientRect();if(!b)return;const T=x.clientX-b.left,N=x.clientY-b.top;X($(T,N))},[X,$]),Ee=x=>{const b=y(x.position.lat,x.position.lng);if(b.visible===!1)return null;const T=(A==null?void 0:A.id)===x.id,N=(x.size||8)*(T?1.3:1),B=(()=>{switch(x.shape){case"square":return n.jsx("rect",{x:b.x-N/2,y:b.y-N/2,width:N,height:N});case"triangle":return n.jsx("polygon",{points:`${b.x},${b.y-N} ${b.x-N},${b.y+N/2} ${b.x+N},${b.y+N/2}`});case"diamond":return n.jsx("polygon",{points:`${b.x},${b.y-N} ${b.x+N},${b.y} ${b.x},${b.y+N} ${b.x-N},${b.y}`});case"pin":return n.jsx("path",{d:`M${b.x},${b.y}
70
- c0,-${N*1.5} -${N},-${N*2} -${N},-${N*2.5}
71
- a${N},${N} 0 1,1 ${N*2},0
72
- c0,${N*.5} -${N},${N} -${N},${N*2.5}`});case"circle":default:return n.jsx("circle",{cx:b.x,cy:b.y,r:N/2})}})();return n.jsxs("g",{fill:x.color||"var(--nice-color-accent-pink, #e91e63)",stroke:T?"var(--nice-text, #000)":"var(--nice-bg, #fff)",strokeWidth:T?2:1,style:{cursor:"pointer"},onMouseEnter:()=>{C(x),H==null||H(x)},onMouseLeave:()=>{C(null),H==null||H(null)},onClick:$e=>{$e.stopPropagation(),re==null||re(x)},children:[B,x.label&&n.jsx("text",{x:b.x+N,y:b.y,fontSize:10,fill:"var(--nice-text, #333)",dominantBaseline:"middle",children:x.label})]},x.id)},Fe=x=>{if(x.path.length<2)return null;const b=x.path.map((T,N)=>{const B=y(T.lat,T.lng);return B.visible===!1?"":N===0?`M${B.x},${B.y}`:`L${B.x},${B.y}`}).filter(Boolean).join(" ");return b?n.jsx("path",{d:b,fill:"none",stroke:x.color||"var(--nice-primary, #2196f3)",strokeWidth:x.width||2,strokeDasharray:x.style==="dashed"?"8,4":x.style==="dotted"?"2,2":void 0,markerEnd:x.arrows?"url(#arrow)":void 0},x.id):null},Be=x=>{if(x.path.length<3)return null;const b=x.path.map((T,N)=>{const B=y(T.lat,T.lng);return B.visible===!1?"":N===0?`M${B.x},${B.y}`:`L${B.x},${B.y}`}).filter(Boolean).join(" ")+" Z";return n.jsx("path",{d:b,fill:x.fillColor||"#4CAF5040",stroke:x.strokeColor||"var(--nice-success, #4caf50)",strokeWidth:x.strokeWidth||1,fillOpacity:x.fillOpacity||.5,style:{cursor:"pointer"},onClick:()=>oe==null?void 0:oe(x)},x.id)},Ce=u.useMemo(()=>{if(!q.show)return null;const x=111,b=z/360*Z,T=x/b,N=T*100,B=Math.pow(10,Math.floor(Math.log10(N))),$e=B*(N/B>=5?5:N/B>=2?2:1);return{width:$e/T,label:$e>=1e3?`${$e/1e3} km`:`${$e} km`}},[q.show,z,Z]);return n.jsxs("div",{ref:W,className:`nice-geographic-map ${pe||""}`,style:{width:Q,height:P,position:"relative",overflow:"hidden",background:M,border:"1px solid var(--nice-border, #ccc)",borderRadius:4,cursor:K?"grabbing":"grab",...fe},onMouseDown:me,onMouseMove:xe,onMouseUp:he,onMouseLeave:he,onWheel:ve,onClick:je,children:[n.jsxs("svg",{width:"100%",height:"100%",children:[n.jsx("defs",{children:n.jsx("marker",{id:"arrow",markerWidth:"10",markerHeight:"10",refX:"9",refY:"3",orient:"auto",children:n.jsx("path",{d:"M0,0 L0,6 L9,3 z",fill:"var(--nice-primary, #2196f3)"})})}),d==="orthographic"&&L&&n.jsxs(n.Fragment,{children:[n.jsx("path",{d:L,fill:M,stroke:"var(--nice-text-muted, #999)",strokeWidth:1}),n.jsx("circle",{cx:z/2,cy:R/2,r:Math.min(z,R)/2-11,fill:j,opacity:.3})]}),h&&D.map((x,b)=>n.jsx("path",{d:x,fill:"none",stroke:U,strokeWidth:.5,strokeOpacity:.7},`graticule-${b}`)),f&&d!=="orthographic"&&n.jsx("g",{transform:`scale(${z/100}, ${R/100})`,children:n.jsx("path",{d:Zt,fill:j,stroke:E,strokeWidth:.2})}),ue.map(Be),ie.map(Fe),O.map(Ee)]}),Ce&&n.jsxs("div",{style:{position:"absolute",[(ke=q.position)!=null&&ke.includes("bottom")?"bottom":"top"]:8,[(v=q.position)!=null&&v.includes("right")?"right":"left"]:8,background:"color-mix(in srgb, var(--nice-bg-elevated, #ffffff) 90%, transparent)",color:"var(--nice-text-primary, #333)",padding:"4px 8px",borderRadius:4,fontSize:"0.7rem"},children:[n.jsx("div",{style:{width:Ce.width,height:4,background:"currentColor",marginBottom:2}}),n.jsx("div",{children:Ce.label})]}),ae&&n.jsxs("div",{style:{position:"absolute",[(k=ae.position)!=null&&k.includes("bottom")?"bottom":"top"]:8,[(F=ae.position)!=null&&F.includes("left")?"left":"right"]:8,background:"var(--nice-overlay-light-95, rgba(255, 255, 255, 0.95))",padding:8,borderRadius:4,fontSize:"0.75rem",minWidth:100},children:[ae.title&&n.jsx("div",{style:{fontWeight:"bold",marginBottom:4},children:ae.title}),ae.items.map((x,b)=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:2},children:[x.shape==="line"?n.jsx("div",{style:{width:16,height:2,background:x.color}}):n.jsx("div",{style:{width:12,height:12,background:x.color,borderRadius:x.shape==="circle"?"50%":0}}),n.jsx("span",{children:x.label})]},b))]}),(A==null?void 0:A.tooltip)&&n.jsx("div",{style:{position:"absolute",top:y(A.position.lat,A.position.lng).y-30,left:y(A.position.lat,A.position.lng).x,transform:"translateX(-50%)",background:"var(--nice-overlay-80, rgba(0, 0, 0, 0.8))",color:"var(--nice-color-white, #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:"color-mix(in srgb, var(--nice-bg-elevated, #ffffff) 90%, transparent)",padding:"2px 6px",borderRadius:4,fontSize:"0.7rem",color:"var(--nice-text-secondary, #666)"},children:[V.lat.toFixed(2),"°, ",V.lng.toFixed(2),"°"]}),de&&t.length>0&&n.jsxs("div",{style:{position:"absolute",top:8,left:8,background:"var(--nice-overlay-light-95, rgba(255, 255, 255, 0.95))",padding:8,borderRadius:4,fontSize:"0.75rem"},children:[n.jsx("div",{style:{fontWeight:"bold",marginBottom:4},children:"Layers"}),t.map(x=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:4,cursor:"pointer"},children:[n.jsx("input",{type:"checkbox",checked:w.has(x.id),onChange:b=>{const T=new Set(w);b.target.checked?T.add(x.id):T.delete(x.id),I(T)}}),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:()=>{S(1),se({lat:0,lng:0})},style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:"Reset View"})]})]})}exports.CitationService=Ke;exports.DataAnalysisService=Ve;exports.LabNotebookProvider=Pe;exports.LabNotebookService=Xe;exports.Nice3DPlot=Lt;exports.NiceCitation=Mt;exports.NiceDataAnalysis=ut;exports.NiceGeographicMap=Kt;exports.NiceLabNotebook=it;exports.NiceMolecularViewer=Wt;exports.NicePhylogeneticTree=Yt;exports.NiceScientificChart=Et;exports.Stats=ge;exports.createCitationService=$t;exports.createDataAnalysisService=dt;exports.createLabNotebookService=st;exports.useCitation=Re;exports.useLabNotebook=Ie;
68
+ `;function Gt({projection:e="equirectangular",layers:t=[],markers:r=[],polylines:s=[],polygons:i=[],heatmap:o,bounds:a,center:l={lat:0,lng:0},zoom:c=1,showGraticule:u=!0,graticuleInterval:x=30,showCoastlines:y=!0,showBorders:f=!1,landColor:m="#D4E6C3",oceanColor:M="#A8D4E6",borderColor:E="var(--nice-text-muted, #999999)",graticuleColor:q="var(--nice-border, #cccccc)",width:re="100%",height:U=400,enablePan:te=!0,enableZoom:B=!0,showControls:ie=!0,scaleBar:me={show:!0,position:"bottom-left"},legend:ee,showLayerControl:je=!1,onMarkerClick:ue,onMarkerHover:Q,onMapClick:oe,onPolygonClick:P,onBoundsChange:se,className:ge,style:we}){var Ce,v,w,I;const{t:xe}=pe.useNiceTranslation(),Y=h.useRef(null),[H,he]=h.useState(l),[Z,ne]=h.useState(c),[fe,$]=h.useState(!1),[J,ae]=h.useState(null),[S,D]=h.useState(null),[A,N]=h.useState(e),[R,X]=h.useState(new Set(t.filter(p=>p.visible!==!1).map(p=>p.id))),T=typeof re=="number"?re:800,W=typeof U=="number"?U:400,g=h.useCallback((p,b)=>{switch(A){case"mercator":return qt(p,b,T,W);case"orthographic":return Kt(p,b,T,W,H.lat,H.lng);case"robinson":return Zt(p,b,T,W);case"equirectangular":default:return Ut(p,b,T,W)}},[A,T,W,H]),z=h.useCallback((p,b)=>{const O=p/T*360-180,C=90-b/W*180;return{lat:Math.max(-90,Math.min(90,C)),lng:Math.max(-180,Math.min(180,O))}},[T,W]),d=h.useMemo(()=>{const p=[];for(let b=-90+x;b<90;b+=x){let O="";for(let C=-180;C<=180;C+=5){const F=g(b,C);F.visible!==!1&&(O+=O===""?`M${F.x},${F.y}`:` L${F.x},${F.y}`)}O&&p.push(O)}for(let b=-180;b<=180;b+=x){let O="";for(let C=-90;C<=90;C+=5){const F=g(C,b);F.visible!==!1&&(O+=O===""?`M${F.x},${F.y}`:` L${F.x},${F.y}`)}O&&p.push(O)}return p},[g,x]),j=h.useMemo(()=>{if(A==="orthographic"){const p=Math.min(T,W)/2-10;return`M${T/2+p},${W/2}
69
+ A${p},${p} 0 1,1 ${T/2-p},${W/2}
70
+ A${p},${p} 0 1,1 ${T/2+p},${W/2}`}return null},[A,T,W]),k=h.useMemo(()=>{const p=[...r];for(const b of t)R.has(b.id)&&b.markers&&p.push(...b.markers);return p},[r,t,R]),L=h.useMemo(()=>{const p=[...s];for(const b of t)R.has(b.id)&&b.polylines&&p.push(...b.polylines);return p},[s,t,R]),V=h.useMemo(()=>{const p=[...i];for(const b of t)R.has(b.id)&&b.polygons&&p.push(...b.polygons);return p},[i,t,R]),de=h.useCallback(p=>{te&&($(!0),ae({x:p.clientX,y:p.clientY,center:{...H}}))},[te,H]),le=h.useCallback(p=>{if(!fe||!J)return;const b=p.clientX-J.x,O=p.clientY-J.y,C=-(b/T)*360/Z,F=O/W*180/Z;he({lat:Math.max(-85,Math.min(85,J.center.lat+F)),lng:(J.center.lng+C+180)%360-180})},[fe,J,T,W,Z]),_=h.useCallback(()=>{$(!1),ae(null)},[]),G=h.useCallback(p=>{if(!B)return;p.preventDefault();const b=p.deltaY>0?.9:1.1;ne(O=>Math.max(.5,Math.min(20,O*b)))},[B]),be=h.useCallback(p=>{var F;if(!oe)return;const b=(F=Y.current)==null?void 0:F.getBoundingClientRect();if(!b)return;const O=p.clientX-b.left,C=p.clientY-b.top;oe(z(O,C))},[oe,z]),ce=p=>{const b=g(p.position.lat,p.position.lng);if(b.visible===!1)return null;const O=(S==null?void 0:S.id)===p.id,C=(p.size||8)*(O?1.3:1),F=(()=>{switch(p.shape){case"square":return n.jsx("rect",{x:b.x-C/2,y:b.y-C/2,width:C,height:C});case"triangle":return n.jsx("polygon",{points:`${b.x},${b.y-C} ${b.x-C},${b.y+C/2} ${b.x+C},${b.y+C/2}`});case"diamond":return n.jsx("polygon",{points:`${b.x},${b.y-C} ${b.x+C},${b.y} ${b.x},${b.y+C} ${b.x-C},${b.y}`});case"pin":return n.jsx("path",{d:`M${b.x},${b.y}
71
+ c0,-${C*1.5} -${C},-${C*2} -${C},-${C*2.5}
72
+ a${C},${C} 0 1,1 ${C*2},0
73
+ c0,${C*.5} -${C},${C} -${C},${C*2.5}`});case"circle":default:return n.jsx("circle",{cx:b.x,cy:b.y,r:C/2})}})();return n.jsxs("g",{fill:p.color||"var(--nice-color-accent-pink, #e91e63)",stroke:O?"var(--nice-text, #000)":"var(--nice-bg, #fff)",strokeWidth:O?2:1,style:{cursor:"pointer"},onMouseEnter:()=>{D(p),Q==null||Q(p)},onMouseLeave:()=>{D(null),Q==null||Q(null)},onClick:Ae=>{Ae.stopPropagation(),ue==null||ue(p)},children:[F,p.label&&n.jsx("text",{x:b.x+C,y:b.y,fontSize:10,fill:"var(--nice-text, #333)",dominantBaseline:"middle",children:p.label})]},p.id)},ye=p=>{if(p.path.length<2)return null;const b=p.path.map((O,C)=>{const F=g(O.lat,O.lng);return F.visible===!1?"":C===0?`M${F.x},${F.y}`:`L${F.x},${F.y}`}).filter(Boolean).join(" ");return b?n.jsx("path",{d:b,fill:"none",stroke:p.color||"var(--nice-primary, #2196f3)",strokeWidth:p.width||2,strokeDasharray:p.style==="dashed"?"8,4":p.style==="dotted"?"2,2":void 0,markerEnd:p.arrows?"url(#arrow)":void 0},p.id):null},ve=p=>{if(p.path.length<3)return null;const b=p.path.map((O,C)=>{const F=g(O.lat,O.lng);return F.visible===!1?"":C===0?`M${F.x},${F.y}`:`L${F.x},${F.y}`}).filter(Boolean).join(" ")+" Z";return n.jsx("path",{d:b,fill:p.fillColor||"#4CAF5040",stroke:p.strokeColor||"var(--nice-success, #4caf50)",strokeWidth:p.strokeWidth||1,fillOpacity:p.fillOpacity||.5,style:{cursor:"pointer"},onClick:()=>P==null?void 0:P(p)},p.id)},$e=h.useMemo(()=>{if(!me.show)return null;const p=111,b=T/360*Z,O=p/b,C=O*100,F=Math.pow(10,Math.floor(Math.log10(C))),Ae=F*(C/F>=5?5:C/F>=2?2:1);return{width:Ae/O,label:Ae>=1e3?xe("geographicMap.km","{scaleKm} km").replace("{scaleKm}",String(Ae/1e3)):xe("geographicMap.km","{scaleKm} km").replace("{scaleKm}",String(Ae))}},[me.show,T,Z,xe]);return n.jsxs("div",{role:"presentation",ref:Y,className:`nice-geographic-map ${ge||""}`,style:{width:re,height:U,position:"relative",overflow:"hidden",background:M,border:"1px solid var(--nice-border, #ccc)",borderRadius:4,cursor:fe?"grabbing":"grab",...we},onMouseDown:de,onMouseMove:le,onMouseUp:_,onMouseLeave:_,onWheel:G,onClick:be,children:[n.jsxs("svg",{width:"100%",height:"100%",children:[n.jsx("defs",{children:n.jsx("marker",{id:"arrow",markerWidth:"10",markerHeight:"10",refX:"9",refY:"3",orient:"auto",children:n.jsx("path",{d:"M0,0 L0,6 L9,3 z",fill:"var(--nice-primary, #2196f3)"})})}),A==="orthographic"&&j&&n.jsxs(n.Fragment,{children:[n.jsx("path",{d:j,fill:M,stroke:"var(--nice-text-muted, #999)",strokeWidth:1}),n.jsx("circle",{cx:T/2,cy:W/2,r:Math.min(T,W)/2-11,fill:m,opacity:.3})]}),u&&d.map((p,b)=>n.jsx("path",{d:p,fill:"none",stroke:q,strokeWidth:.5,strokeOpacity:.7},`graticule-${b}`)),y&&A!=="orthographic"&&n.jsx("g",{transform:`scale(${T/100}, ${W/100})`,children:n.jsx("path",{d:Jt,fill:m,stroke:E,strokeWidth:.2})}),V.map(ve),L.map(ye),k.map(ce)]}),$e&&n.jsxs("div",{style:{position:"absolute",[(Ce=me.position)!=null&&Ce.includes("bottom")?"bottom":"top"]:8,[(v=me.position)!=null&&v.includes("right")?"right":"left"]:8,background:"color-mix(in srgb, var(--nice-bg-elevated, #ffffff) 90%, transparent)",color:"var(--nice-text-primary, #333)",padding:"4px 8px",borderRadius:4,fontSize:"0.7rem"},children:[n.jsx("div",{style:{width:$e.width,height:4,background:"currentColor",marginBottom:2}}),n.jsx("div",{children:$e.label})]}),ee&&n.jsxs("div",{style:{position:"absolute",[(w=ee.position)!=null&&w.includes("bottom")?"bottom":"top"]:8,[(I=ee.position)!=null&&I.includes("left")?"left":"right"]:8,background:"var(--nice-overlay-light-95, rgba(255, 255, 255, 0.95))",padding:8,borderRadius:4,fontSize:"0.75rem",minWidth:100},children:[ee.title&&n.jsx("div",{style:{fontWeight:"bold",marginBottom:4},children:ee.title}),ee.items.map((p,b)=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:2},children:[p.shape==="line"?n.jsx("div",{style:{width:16,height:2,background:p.color}}):n.jsx("div",{style:{width:12,height:12,background:p.color,borderRadius:p.shape==="circle"?"50%":0}}),n.jsx("span",{children:p.label})]},b))]}),(S==null?void 0:S.tooltip)&&n.jsx("div",{style:{position:"absolute",top:g(S.position.lat,S.position.lng).y-30,left:g(S.position.lat,S.position.lng).x,transform:"translateX(-50%)",background:"var(--nice-overlay-80, rgba(0, 0, 0, 0.8))",color:"var(--nice-color-white, #fff)",padding:"4px 8px",borderRadius:4,fontSize:"0.75rem",pointerEvents:"none",whiteSpace:"nowrap"},children:S.tooltip}),n.jsxs("div",{style:{position:"absolute",bottom:8,right:8,background:"color-mix(in srgb, var(--nice-bg-elevated, #ffffff) 90%, transparent)",padding:"2px 6px",borderRadius:4,fontSize:"0.7rem",color:"var(--nice-text-secondary, #666)"},children:[H.lat.toFixed(2),"°, ",H.lng.toFixed(2),"°"]}),je&&t.length>0&&n.jsxs("div",{style:{position:"absolute",top:8,left:8,background:"var(--nice-overlay-light-95, rgba(255, 255, 255, 0.95))",padding:8,borderRadius:4,fontSize:"0.75rem"},children:[n.jsx("div",{style:{fontWeight:"bold",marginBottom:4},children:xe("geographicMap.layers","Layers")}),t.map(p=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:4,cursor:"pointer"},children:[n.jsx("input",{type:"checkbox",checked:R.has(p.id),onChange:b=>{const O=new Set(R);b.target.checked?O.add(p.id):O.delete(p.id),X(O)}}),p.name]},p.id))]}),ie&&n.jsxs("div",{style:{position:"absolute",top:8,right:8,display:"flex",flexDirection:"column",gap:4},children:[n.jsxs("select",{value:A,onChange:p=>N(p.target.value),style:{padding:"2px 4px",fontSize:"0.75rem"},children:[n.jsx("option",{value:"equirectangular",children:xe("geographicMap.equirectangular","Equirectangular")}),n.jsx("option",{value:"mercator",children:xe("geographicMap.mercator","Mercator")}),n.jsx("option",{value:"orthographic",children:xe("geographicMap.orthographic","Orthographic")}),n.jsx("option",{value:"robinson",children:xe("geographicMap.robinson","Robinson")})]}),n.jsx("button",{onClick:()=>{ne(1),he({lat:0,lng:0})},style:{padding:"2px 4px",fontSize:"0.75rem",cursor:"pointer"},children:xe("geographicMap.resetView","Reset View")})]})]})}exports.CitationService=Ge;exports.DataAnalysisService=Ke;exports.LabNotebookProvider=qe;exports.LabNotebookService=Ye;exports.Nice3DPlot=Ot;exports.NiceCitation=St;exports.NiceDataAnalysis=pt;exports.NiceGeographicMap=Gt;exports.NiceLabNotebook=at;exports.NiceMolecularViewer=Pt;exports.NicePhylogeneticTree=Vt;exports.NiceScientificChart=Bt;exports.Stats=ke;exports.createCitationService=wt;exports.createDataAnalysisService=ht;exports.createLabNotebookService=ot;exports.useCitation=_e;exports.useLabNotebook=Te;