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