BiNgoViewer 2.2.6__tar.gz → 2.2.7__tar.gz
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.
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/BiNgoViewer.egg-info/PKG-INFO +1 -1
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/BiNgoViewer.egg-info/SOURCES.txt +1 -1
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/PKG-INFO +1 -1
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/__init__.py +1 -1
- bingoviewer-2.2.6/bingoviewer/frontend_dist/assets/index-6KBC4l8m.js → bingoviewer-2.2.7/bingoviewer/frontend_dist/assets/index-Dz6JKlYK.js +2 -2
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/frontend_dist/index.html +1 -1
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/server/main.py +1 -1
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/pyproject.toml +1 -1
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/BiNgoViewer.egg-info/dependency_links.txt +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/BiNgoViewer.egg-info/entry_points.txt +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/BiNgoViewer.egg-info/requires.txt +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/BiNgoViewer.egg-info/top_level.txt +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/README.md +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/__main__.py +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/cli.py +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/icon.py +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/install_shortcut.py +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/server/__init__.py +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/server/api/__init__.py +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/server/api/data.py +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/server/api/genome.py +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/server/api/tracks.py +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/server/readers/__init__.py +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/server/readers/annotation_reader.py +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/server/readers/bam_reader.py +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/server/readers/bigwig_reader.py +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/server/readers/genbank_reader.py +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/server/readers/genome_reader.py +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/server/readers/vcf_reader.py +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/bingoviewer/server/state.py +0 -0
- {bingoviewer-2.2.6 → bingoviewer-2.2.7}/setup.cfg +0 -0
|
@@ -12,7 +12,7 @@ bingoviewer/cli.py
|
|
|
12
12
|
bingoviewer/icon.py
|
|
13
13
|
bingoviewer/install_shortcut.py
|
|
14
14
|
bingoviewer/frontend_dist/index.html
|
|
15
|
-
bingoviewer/frontend_dist/assets/index-
|
|
15
|
+
bingoviewer/frontend_dist/assets/index-Dz6JKlYK.js
|
|
16
16
|
bingoviewer/server/__init__.py
|
|
17
17
|
bingoviewer/server/main.py
|
|
18
18
|
bingoviewer/server/state.py
|
|
@@ -42,7 +42,7 @@ Error generating stack: `+l.message+`
|
|
|
42
42
|
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(o=>r.set(o)),r}static accessor(t){const r=(this[nc]=this[nc]={accessors:{}}).accessors,o=this.prototype;function l(i){const s=Mr(i);r[s]||(a0(o,i),r[s]=!0)}return L.isArray(t)?t.forEach(l):l(t),this}};lt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);L.reduceDescriptors(lt.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}});L.freezeMethods(lt);function Ri(e,t){const n=this||bo,r=t||n,o=lt.from(r.headers);let l=r.data;return L.forEach(e,function(s){l=s.call(n,l,o.normalize(),t?t.status:void 0)}),o.normalize(),l}function ip(e){return!!(e&&e.__CANCEL__)}let ko=class extends ne{constructor(t,n,r){super(t??"canceled",ne.ERR_CANCELED,n,r),this.name="CanceledError",this.__CANCEL__=!0}};function sp(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new ne("Request failed with status code "+n.status,[ne.ERR_BAD_REQUEST,ne.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function u0(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function c0(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,l=0,i;return t=t!==void 0?t:1e3,function(u){const c=Date.now(),h=r[l];i||(i=c),n[o]=u,r[o]=c;let d=l,g=0;for(;d!==o;)g+=n[d++],d=d%e;if(o=(o+1)%e,o===l&&(l=(l+1)%e),c-i<t)return;const T=h&&c-h;return T?Math.round(g*1e3/T):void 0}}function d0(e,t){let n=0,r=1e3/t,o,l;const i=(c,h=Date.now())=>{n=h,o=null,l&&(clearTimeout(l),l=null),e(...c)};return[(...c)=>{const h=Date.now(),d=h-n;d>=r?i(c,h):(o=c,l||(l=setTimeout(()=>{l=null,i(o)},r-d)))},()=>o&&i(o)]}const Pl=(e,t,n=3)=>{let r=0;const o=c0(50,250);return d0(l=>{const i=l.loaded,s=l.lengthComputable?l.total:void 0,u=i-r,c=o(u),h=i<=s;r=i;const d={loaded:i,total:s,progress:s?i/s:void 0,bytes:u,rate:c||void 0,estimated:c&&s&&h?(s-i)/c:void 0,event:l,lengthComputable:s!=null,[t?"download":"upload"]:!0};e(d)},n)},rc=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},oc=e=>(...t)=>L.asap(()=>e(...t)),f0=Ve.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Ve.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Ve.origin),Ve.navigator&&/(msie|trident)/i.test(Ve.navigator.userAgent)):()=>!0,p0=Ve.hasStandardBrowserEnv?{write(e,t,n,r,o,l,i){if(typeof document>"u")return;const s=[`${e}=${encodeURIComponent(t)}`];L.isNumber(n)&&s.push(`expires=${new Date(n).toUTCString()}`),L.isString(r)&&s.push(`path=${r}`),L.isString(o)&&s.push(`domain=${o}`),l===!0&&s.push("secure"),L.isString(i)&&s.push(`SameSite=${i}`),document.cookie=s.join("; ")},read(e){if(typeof document>"u")return null;const t=document.cookie.match(new RegExp("(?:^|; )"+e+"=([^;]*)"));return t?decodeURIComponent(t[1]):null},remove(e){this.write(e,"",Date.now()-864e5,"/")}}:{write(){},read(){return null},remove(){}};function h0(e){return typeof e!="string"?!1:/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function m0(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function ap(e,t,n){let r=!h0(t);return e&&(r||n==!1)?m0(e,t):t}const lc=e=>e instanceof lt?{...e}:e;function Un(e,t){t=t||{};const n={};function r(c,h,d,g){return L.isPlainObject(c)&&L.isPlainObject(h)?L.merge.call({caseless:g},c,h):L.isPlainObject(h)?L.merge({},h):L.isArray(h)?h.slice():h}function o(c,h,d,g){if(L.isUndefined(h)){if(!L.isUndefined(c))return r(void 0,c,d,g)}else return r(c,h,d,g)}function l(c,h){if(!L.isUndefined(h))return r(void 0,h)}function i(c,h){if(L.isUndefined(h)){if(!L.isUndefined(c))return r(void 0,c)}else return r(void 0,h)}function s(c,h,d){if(d in t)return r(c,h);if(d in e)return r(void 0,c)}const u={url:l,method:l,data:l,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:s,headers:(c,h,d)=>o(lc(c),lc(h),d,!0)};return L.forEach(Object.keys({...e,...t}),function(h){if(h==="__proto__"||h==="constructor"||h==="prototype")return;const d=L.hasOwnProp(u,h)?u[h]:o,g=d(e[h],t[h],h);L.isUndefined(g)&&d!==s||(n[h]=g)}),n}const up=e=>{const t=Un({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:l,headers:i,auth:s}=t;if(t.headers=i=lt.from(i),t.url=op(ap(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),s&&i.set("Authorization","Basic "+btoa((s.username||"")+":"+(s.password?unescape(encodeURIComponent(s.password)):""))),L.isFormData(n)){if(Ve.hasStandardBrowserEnv||Ve.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(L.isFunction(n.getHeaders)){const u=n.getHeaders(),c=["content-type","content-length"];Object.entries(u).forEach(([h,d])=>{c.includes(h.toLowerCase())&&i.set(h,d)})}}if(Ve.hasStandardBrowserEnv&&(r&&L.isFunction(r)&&(r=r(t)),r||r!==!1&&f0(t.url))){const u=o&&l&&p0.read(l);u&&i.set(o,u)}return t},g0=typeof XMLHttpRequest<"u",y0=g0&&function(e){return new Promise(function(n,r){const o=up(e);let l=o.data;const i=lt.from(o.headers).normalize();let{responseType:s,onUploadProgress:u,onDownloadProgress:c}=o,h,d,g,T,v;function y(){T&&T(),v&&v(),o.cancelToken&&o.cancelToken.unsubscribe(h),o.signal&&o.signal.removeEventListener("abort",h)}let x=new XMLHttpRequest;x.open(o.method.toUpperCase(),o.url,!0),x.timeout=o.timeout;function f(){if(!x)return;const m=lt.from("getAllResponseHeaders"in x&&x.getAllResponseHeaders()),S={data:!s||s==="text"||s==="json"?x.responseText:x.response,status:x.status,statusText:x.statusText,headers:m,config:e,request:x};sp(function(b){n(b),y()},function(b){r(b),y()},S),x=null}"onloadend"in x?x.onloadend=f:x.onreadystatechange=function(){!x||x.readyState!==4||x.status===0&&!(x.responseURL&&x.responseURL.indexOf("file:")===0)||setTimeout(f)},x.onabort=function(){x&&(r(new ne("Request aborted",ne.ECONNABORTED,e,x)),x=null)},x.onerror=function(w){const S=w&&w.message?w.message:"Network Error",E=new ne(S,ne.ERR_NETWORK,e,x);E.event=w||null,r(E),x=null},x.ontimeout=function(){let w=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const S=o.transitional||Ba;o.timeoutErrorMessage&&(w=o.timeoutErrorMessage),r(new ne(w,S.clarifyTimeoutError?ne.ETIMEDOUT:ne.ECONNABORTED,e,x)),x=null},l===void 0&&i.setContentType(null),"setRequestHeader"in x&&L.forEach(i.toJSON(),function(w,S){x.setRequestHeader(S,w)}),L.isUndefined(o.withCredentials)||(x.withCredentials=!!o.withCredentials),s&&s!=="json"&&(x.responseType=o.responseType),c&&([g,v]=Pl(c,!0),x.addEventListener("progress",g)),u&&x.upload&&([d,T]=Pl(u),x.upload.addEventListener("progress",d),x.upload.addEventListener("loadend",T)),(o.cancelToken||o.signal)&&(h=m=>{x&&(r(!m||m.type?new ko(null,e,x):m),x.abort(),x=null)},o.cancelToken&&o.cancelToken.subscribe(h),o.signal&&(o.signal.aborted?h():o.signal.addEventListener("abort",h)));const p=u0(o.url);if(p&&Ve.protocols.indexOf(p)===-1){r(new ne("Unsupported protocol "+p+":",ne.ERR_BAD_REQUEST,e));return}x.send(l||null)})},x0=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const l=function(c){if(!o){o=!0,s();const h=c instanceof Error?c:this.reason;r.abort(h instanceof ne?h:new ko(h instanceof Error?h.message:h))}};let i=t&&setTimeout(()=>{i=null,l(new ne(`timeout of ${t}ms exceeded`,ne.ETIMEDOUT))},t);const s=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(l):c.removeEventListener("abort",l)}),e=null)};e.forEach(c=>c.addEventListener("abort",l));const{signal:u}=r;return u.unsubscribe=()=>L.asap(s),u}},v0=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let r=0,o;for(;r<n;)o=r+t,yield e.slice(r,o),r=o},w0=async function*(e,t){for await(const n of S0(e))yield*v0(n,t)},S0=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:r}=await t.read();if(n)break;yield r}}finally{await t.cancel()}},ic=(e,t,n,r)=>{const o=w0(e,t);let l=0,i,s=u=>{i||(i=!0,r&&r(u))};return new ReadableStream({async pull(u){try{const{done:c,value:h}=await o.next();if(c){s(),u.close();return}let d=h.byteLength;if(n){let g=l+=d;n(g)}u.enqueue(new Uint8Array(h))}catch(c){throw s(c),c}},cancel(u){return s(u),o.return()}},{highWaterMark:2})},sc=64*1024,{isFunction:Uo}=L,b0=(({Request:e,Response:t})=>({Request:e,Response:t}))(L.global),{ReadableStream:ac,TextEncoder:uc}=L.global,cc=(e,...t)=>{try{return!!e(...t)}catch{return!1}},k0=e=>{e=L.merge.call({skipUndefined:!0},b0,e);const{fetch:t,Request:n,Response:r}=e,o=t?Uo(t):typeof fetch=="function",l=Uo(n),i=Uo(r);if(!o)return!1;const s=o&&Uo(ac),u=o&&(typeof uc=="function"?(v=>y=>v.encode(y))(new uc):async v=>new Uint8Array(await new n(v).arrayBuffer())),c=l&&s&&cc(()=>{let v=!1;const y=new ac,x=new n(Ve.origin,{body:y,method:"POST",get duplex(){return v=!0,"half"}}).headers.has("Content-Type");return y.cancel(),v&&!x}),h=i&&s&&cc(()=>L.isReadableStream(new r("").body)),d={stream:h&&(v=>v.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(v=>{!d[v]&&(d[v]=(y,x)=>{let f=y&&y[v];if(f)return f.call(y);throw new ne(`Response type '${v}' is not supported`,ne.ERR_NOT_SUPPORT,x)})});const g=async v=>{if(v==null)return 0;if(L.isBlob(v))return v.size;if(L.isSpecCompliantForm(v))return(await new n(Ve.origin,{method:"POST",body:v}).arrayBuffer()).byteLength;if(L.isArrayBufferView(v)||L.isArrayBuffer(v))return v.byteLength;if(L.isURLSearchParams(v)&&(v=v+""),L.isString(v))return(await u(v)).byteLength},T=async(v,y)=>{const x=L.toFiniteNumber(v.getContentLength());return x??g(y)};return async v=>{let{url:y,method:x,data:f,signal:p,cancelToken:m,timeout:w,onDownloadProgress:S,onUploadProgress:E,responseType:b,headers:P,withCredentials:N="same-origin",fetchOptions:$}=up(v),_=t||fetch;b=b?(b+"").toLowerCase():"text";let H=x0([p,m&&m.toAbortSignal()],w),j=null;const U=H&&H.unsubscribe&&(()=>{H.unsubscribe()});let O;try{if(E&&c&&x!=="get"&&x!=="head"&&(O=await T(P,f))!==0){let A=new n(y,{method:"POST",body:f,duplex:"half"}),R;if(L.isFormData(f)&&(R=A.headers.get("content-type"))&&P.setContentType(R),A.body){const[k,D]=rc(O,Pl(oc(E)));f=ic(A.body,sc,k,D)}}L.isString(N)||(N=N?"include":"omit");const G=l&&"credentials"in n.prototype,F={...$,signal:H,method:x.toUpperCase(),headers:P.normalize().toJSON(),body:f,duplex:"half",credentials:G?N:void 0};j=l&&new n(y,F);let B=await(l?_(j,$):_(y,F));const M=h&&(b==="stream"||b==="response");if(h&&(S||M&&U)){const A={};["status","statusText","headers"].forEach(Y=>{A[Y]=B[Y]});const R=L.toFiniteNumber(B.headers.get("content-length")),[k,D]=S&&rc(R,Pl(oc(S),!0))||[];B=new r(ic(B.body,sc,k,()=>{D&&D(),U&&U()}),A)}b=b||"text";let I=await d[L.findKey(d,b)||"text"](B,v);return!M&&U&&U(),await new Promise((A,R)=>{sp(A,R,{data:I,headers:lt.from(B.headers),status:B.status,statusText:B.statusText,config:v,request:j})})}catch(G){throw U&&U(),G&&G.name==="TypeError"&&/Load failed|fetch/i.test(G.message)?Object.assign(new ne("Network Error",ne.ERR_NETWORK,v,j,G&&G.response),{cause:G.cause||G}):ne.from(G,G&&G.code,v,j,G&&G.response)}}},C0=new Map,cp=e=>{let t=e&&e.env||{};const{fetch:n,Request:r,Response:o}=t,l=[r,o,n];let i=l.length,s=i,u,c,h=C0;for(;s--;)u=l[s],c=h.get(u),c===void 0&&h.set(u,c=s?new Map:k0(t)),h=c;return c};cp();const za={http:Dg,xhr:y0,fetch:{get:cp}};L.forEach(za,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const dc=e=>`- ${e}`,T0=e=>L.isFunction(e)||e===null||e===!1;function E0(e,t){e=L.isArray(e)?e:[e];const{length:n}=e;let r,o;const l={};for(let i=0;i<n;i++){r=e[i];let s;if(o=r,!T0(r)&&(o=za[(s=String(r)).toLowerCase()],o===void 0))throw new ne(`Unknown adapter '${s}'`);if(o&&(L.isFunction(o)||(o=o.get(t))))break;l[s||"#"+i]=o}if(!o){const i=Object.entries(l).map(([u,c])=>`adapter ${u} `+(c===!1?"is not supported by the environment":"is not available in the build"));let s=n?i.length>1?`since :
|
|
43
43
|
`+i.map(dc).join(`
|
|
44
44
|
`):" "+dc(i[0]):"as no adapter specified";throw new ne("There is no suitable adapter to dispatch the request "+s,"ERR_NOT_SUPPORT")}return o}const dp={getAdapter:E0,adapters:za};function ji(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new ko(null,e)}function fc(e){return ji(e),e.headers=lt.from(e.headers),e.data=Ri.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),dp.getAdapter(e.adapter||bo.adapter,e)(e).then(function(r){return ji(e),r.data=Ri.call(e,e.transformResponse,r),r.headers=lt.from(r.headers),r},function(r){return ip(r)||(ji(e),r&&r.response&&(r.response.data=Ri.call(e,e.transformResponse,r.response),r.response.headers=lt.from(r.response.headers))),Promise.reject(r)})}const fp="1.14.0",ql={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{ql[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const pc={};ql.transitional=function(t,n,r){function o(l,i){return"[Axios v"+fp+"] Transitional option '"+l+"'"+i+(r?". "+r:"")}return(l,i,s)=>{if(t===!1)throw new ne(o(i," has been removed"+(n?" in "+n:"")),ne.ERR_DEPRECATED);return n&&!pc[i]&&(pc[i]=!0,console.warn(o(i," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(l,i,s):!0}};ql.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function R0(e,t,n){if(typeof e!="object")throw new ne("options must be an object",ne.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const l=r[o],i=t[l];if(i){const s=e[l],u=s===void 0||i(s,l,e);if(u!==!0)throw new ne("option "+l+" must be "+u,ne.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new ne("Unknown option "+l,ne.ERR_BAD_OPTION)}}const ol={assertOptions:R0,validators:ql},gt=ol.validators;let zn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new tc,response:new tc}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let o={};Error.captureStackTrace?Error.captureStackTrace(o):o=new Error;const l=o.stack?o.stack.replace(/^.+\n/,""):"";try{r.stack?l&&!String(r.stack).endsWith(l.replace(/^.+\n.+\n/,""))&&(r.stack+=`
|
|
45
|
-
`+l):r.stack=l}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Un(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:l}=n;r!==void 0&&ol.assertOptions(r,{silentJSONParsing:gt.transitional(gt.boolean),forcedJSONParsing:gt.transitional(gt.boolean),clarifyTimeoutError:gt.transitional(gt.boolean),legacyInterceptorReqResOrdering:gt.transitional(gt.boolean)},!1),o!=null&&(L.isFunction(o)?n.paramsSerializer={serialize:o}:ol.assertOptions(o,{encode:gt.function,serialize:gt.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),ol.assertOptions(n,{baseUrl:gt.spelling("baseURL"),withXsrfToken:gt.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=l&&L.merge(l.common,l[n.method]);l&&L.forEach(["delete","get","head","post","put","patch","common"],v=>{delete l[v]}),n.headers=lt.concat(i,l);const s=[];let u=!0;this.interceptors.request.forEach(function(y){if(typeof y.runWhen=="function"&&y.runWhen(n)===!1)return;u=u&&y.synchronous;const x=n.transitional||Ba;x&&x.legacyInterceptorReqResOrdering?s.unshift(y.fulfilled,y.rejected):s.push(y.fulfilled,y.rejected)});const c=[];this.interceptors.response.forEach(function(y){c.push(y.fulfilled,y.rejected)});let h,d=0,g;if(!u){const v=[fc.bind(this),void 0];for(v.unshift(...s),v.push(...c),g=v.length,h=Promise.resolve(n);d<g;)h=h.then(v[d++],v[d++]);return h}g=s.length;let T=n;for(;d<g;){const v=s[d++],y=s[d++];try{T=v(T)}catch(x){y.call(this,x);break}}try{h=fc.call(this,T)}catch(v){return Promise.reject(v)}for(d=0,g=c.length;d<g;)h=h.then(c[d++],c[d++]);return h}getUri(t){t=Un(this.defaults,t);const n=ap(t.baseURL,t.url,t.allowAbsoluteUrls);return op(n,t.params,t.paramsSerializer)}};L.forEach(["delete","get","head","options"],function(t){zn.prototype[t]=function(n,r){return this.request(Un(r||{},{method:t,url:n,data:(r||{}).data}))}});L.forEach(["post","put","patch"],function(t){function n(r){return function(l,i,s){return this.request(Un(s||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:l,data:i}))}}zn.prototype[t]=n(),zn.prototype[t+"Form"]=n(!0)});let j0=class pp{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(l){n=l});const r=this;this.promise.then(o=>{if(!r._listeners)return;let l=r._listeners.length;for(;l-- >0;)r._listeners[l](o);r._listeners=null}),this.promise.then=o=>{let l;const i=new Promise(s=>{r.subscribe(s),l=s}).then(o);return i.cancel=function(){r.unsubscribe(l)},i},t(function(l,i,s){r.reason||(r.reason=new ko(l,i,s),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new pp(function(o){t=o}),cancel:t}}};function P0(e){return function(n){return e.apply(null,n)}}function _0(e){return L.isObject(e)&&e.isAxiosError===!0}const Bs={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511,WebServerIsDown:521,ConnectionTimedOut:522,OriginIsUnreachable:523,TimeoutOccurred:524,SslHandshakeFailed:525,InvalidSslCertificate:526};Object.entries(Bs).forEach(([e,t])=>{Bs[t]=e});function hp(e){const t=new zn(e),n=Yf(zn.prototype.request,t);return L.extend(n,zn.prototype,t,{allOwnKeys:!0}),L.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return hp(Un(e,o))},n}const Pe=hp(bo);Pe.Axios=zn;Pe.CanceledError=ko;Pe.CancelToken=j0;Pe.isCancel=ip;Pe.VERSION=fp;Pe.toFormData=Kl;Pe.AxiosError=ne;Pe.Cancel=Pe.CanceledError;Pe.all=function(t){return Promise.all(t)};Pe.spread=P0;Pe.isAxiosError=_0;Pe.mergeConfig=Un;Pe.AxiosHeaders=lt;Pe.formToJSON=e=>lp(L.isHTMLForm(e)?new FormData(e):e);Pe.getAdapter=dp.getAdapter;Pe.HttpStatusCode=Bs;Pe.default=Pe;const{Axios:tx,AxiosError:nx,CanceledError:rx,isCancel:ox,CancelToken:lx,VERSION:ix,all:sx,Cancel:ax,isAxiosError:ux,spread:cx,toFormData:dx,AxiosHeaders:fx,HttpStatusCode:px,formToJSON:hx,getAdapter:mx,mergeConfig:gx}=Pe,tn=Pe.create({baseURL:"/api"});function Qr(e,t,n){return new Promise((r,o)=>{const l=new XMLHttpRequest;l.open("POST",`/api${e}`),n&&l.upload.addEventListener("progress",i=>{i.lengthComputable&&n({loaded:i.loaded,total:i.total,percent:Math.round(i.loaded/i.total*100)})}),l.addEventListener("load",()=>{if(l.status>=200&&l.status<300)try{r({data:JSON.parse(l.responseText)})}catch{r({data:{}})}else{const i=new Error("Upload failed");try{i.response={status:l.status,data:JSON.parse(l.responseText)}}catch{i.response={status:l.status,data:{detail:l.statusText}}}o(i)}}),l.addEventListener("error",()=>{const i=new Error("Network error");i.response={status:0,data:{detail:"Network error — is the server running?"}},o(i)}),l.addEventListener("abort",()=>{const i=new Error("Upload aborted");i.name="CanceledError",o(i)}),l.send(t)})}const mn={load:(e,t)=>{const n=new FormData;return n.append("file",e),Qr("/genome/load",n,t)},loadPath:e=>{const t=new FormData;return t.append("path",e),Qr("/genome/load-path",t)},addChromosomes:(e,t)=>{const n=new FormData;return n.append("file",e),Qr("/genome/add-chromosomes",n,t)},chromosomes:()=>tn.get("/genome/chromosomes"),sequence:(e,t,n)=>tn.get("/genome/sequence",{params:{chrom:e,start:t,end:n}})},$t={load:(e,t,n,r)=>{const o=new FormData;return o.append("file",e),t&&o.append("name",t),n&&o.append("index",n),Qr("/tracks/load",o,r)},loadPath:(e,t)=>{const n=new FormData;return n.append("path",e),t&&n.append("name",t),Qr("/tracks/load-path",n)},list:()=>tn.get("/tracks"),remove:e=>tn.delete(`/tracks/${e}`),coverage:(e,t,n,r,o=1e3)=>tn.get(`/tracks/${e}/coverage`,{params:{chrom:t,start:n,end:r,bins:o}}),reads:(e,t,n,r)=>tn.get(`/tracks/${e}/reads`,{params:{chrom:t,start:n,end:r}}),variants:(e,t,n,r)=>tn.get(`/tracks/${e}/variants`,{params:{chrom:t,start:n,end:r}}),features:(e,t,n,r)=>tn.get(`/tracks/${e}/features`,{params:{chrom:t,start:n,end:r}})},mp=C.createContext(null),hc=["#78909c","#81c784","#ffb74d","#f06292","#ce93d8","#80cbc4","#fff176","#ff8a65"],gp={cds:"#66bb6a",exon:"#42a5f5",gene:"#7e57c2",transcript:"#ab47bc",utr:"#26c6da",rrna:"#ffa726",trna:"#ef5350",repeat:"#8d6e63",default:"#80cbc4"};function Nt(e){return e&&e.replace(/\\u([0-9a-fA-F]{4})/g,(t,n)=>String.fromCharCode(parseInt(n,16)))}function L0({children:e}){const[t,n]=C.useState([]),[r,o]=C.useState(null),l=C.useRef(t);l.current=t;const i=C.useCallback(async(x,f,p,m)=>{var w,S;try{const b=(await $t.load(x,f,p,m)).data;return b.name&&(b.name=Nt(b.name)),o(null),b}catch(E){const b=((S=(w=E.response)==null?void 0:w.data)==null?void 0:S.detail)||E.message||String(E);throw o(typeof b=="string"?b:JSON.stringify(b)),E}},[]),s=C.useCallback(x=>{n(f=>{const p=hc[f.length%hc.length],m=x.track_type==="annotations"||x.track_type==="genome_annotations";return[...f,{...x,color:p,height:M0(x.track_type),visible:!0,useArrows:!0,scaleMax:null,scaleMin:null,logScale:!1,barAutoWidth:!0,barWidth:2,showOutline:!1,outlineColor:null,outlineSmooth:0,showBars:!0,showNucleotides:!0,fwdColor:null,revColor:null,arrowStyle:"pointed",arrowSize:4,targetChromosomes:x.target_chromosomes||null,...m?{annotationColors:null}:{}}]})},[]),u=C.useCallback(async x=>{try{await $t.remove(x)}catch{}},[]),c=C.useCallback(async(x,f)=>{const p=await i(x,f);return s(p),p},[i,s]),h=C.useCallback(async x=>{var p,m;const f=l.current.find(w=>w.id===x);if(f&&f.track_type==="genome_annotations"){n(w=>w.map(S=>S.id===x?{...S,visible:!1}:S));return}try{await $t.remove(x),n(w=>w.filter(S=>S.id!==x))}catch(w){o(((m=(p=w.response)==null?void 0:p.data)==null?void 0:m.detail)||w.message)}},[]),d=C.useCallback(()=>{n(x=>x.map(f=>f.track_type==="genome_annotations"&&!f.visible?{...f,visible:!0}:f))},[]),g=C.useCallback((x,f)=>{n(p=>p.map(m=>m.id===x?{...m,...f}:m))},[]),T=C.useCallback((x,f)=>{n(p=>p.map(m=>x.includes(m.id)?{...m,...f}:m))},[]),v=C.useCallback((x,f)=>{n(p=>{const m=[...p],w=m.findIndex(b=>b.id===x),S=m.findIndex(b=>b.id===f);if(w===-1||S===-1)return p;const[E]=m.splice(w,1);return m.splice(S,0,E),m})},[]),y=C.useCallback(x=>{n(f=>{const p=f.findIndex(m=>m.id===x.id);if(p!==-1){const m=[...f];return m[p]={...m[p],name:Nt(x.name)||x.name,visible:!0,...x.targetChromosomes?{targetChromosomes:x.targetChromosomes}:{}},m}return[...f,{...x,name:Nt(x.name)||x.name,color:"#a5d6a7",height:80,visible:!0,useArrows:!0,annotationColors:null,targetChromosomes:x.targetChromosomes||null}]})},[]);return a.jsx(mp.Provider,{value:{tracks:t,setTracks:n,addTrack:c,uploadTrack:i,commitTrack:s,discardTrack:u,removeTrack:h,updateTrack:g,updateMultipleTracks:T,reorderTracks:v,addGenomeAnnotationTrack:y,restoreAnnotationTracks:d,error:r,setError:o},children:e})}function Kt(){return C.useContext(mp)}function M0(e){switch(e){case"reads":return 120;case"coverage":return 120;case"variants":return 60;case"annotations":case"genome_annotations":return 80;default:return 80}}const yp=C.createContext(null),mc={geneCds:"#66bb6a",geneExon:"#42a5f5",geneGene:"#7e57c2",geneTranscript:"#ab47bc",geneUtr:"#26c6da",geneRrna:"#ffa726",geneTrna:"#ef5350",geneRepeat:"#8d6e63",geneDefault:"#80cbc4"},yt={dark:{name:"Dark",appBg:"#1a1a1a",headerBg:"#2a2a2a",panelBg:"#252525",canvasBg:"#1a1a1a",inputBg:"#333",border:"#333",borderAccent:"#444",borderStrong:"#555",btnBg:"#555",btnText:"#fff",btnDanger:"#c62828",textPrimary:"#e0e0e0",textSecondary:"#999",textTertiary:"#777",textMuted:"#666",trackName:"#ccc",rulerTick:"#888",rulerLabel:"#ccc",tooltipBg:"#333",tooltipBorder:"#555",overlayBg:"rgba(0,0,0,0.55)",selectedRow:"#333",centerLine:"#555",...mc},light:{name:"Light",appBg:"#f5f5f5",headerBg:"#ffffff",panelBg:"#eee",canvasBg:"#ffffff",inputBg:"#fff",border:"#ddd",borderAccent:"#bbb",borderStrong:"#999",btnBg:"#e0e0e0",btnText:"#333",btnDanger:"#d32f2f",textPrimary:"#222",textSecondary:"#666",textTertiary:"#888",textMuted:"#aaa",trackName:"#333",rulerTick:"#666",rulerLabel:"#333",tooltipBg:"#fff",tooltipBorder:"#ccc",overlayBg:"rgba(0,0,0,0.25)",selectedRow:"#dde4ee",centerLine:"#ccc",...mc},colorblind:{name:"Colorblind Friendly",appBg:"#1a1a1a",headerBg:"#2a2a2a",panelBg:"#252525",canvasBg:"#1a1a1a",inputBg:"#333",border:"#333",borderAccent:"#444",borderStrong:"#555",btnBg:"#555",btnText:"#fff",btnDanger:"#cc4125",textPrimary:"#e0e0e0",textSecondary:"#999",textTertiary:"#777",textMuted:"#666",trackName:"#ccc",rulerTick:"#888",rulerLabel:"#ccc",tooltipBg:"#333",tooltipBorder:"#555",overlayBg:"rgba(0,0,0,0.55)",selectedRow:"#333",centerLine:"#555",geneCds:"#009e73",geneExon:"#0072b2",geneGene:"#cc79a7",geneTranscript:"#d55e00",geneUtr:"#56b4e9",geneRrna:"#e69f00",geneTrna:"#f0e442",geneRepeat:"#999999",geneDefault:"#56b4e9"},soft:{name:"Soft",appBg:"#f0ede8",headerBg:"#e4dfd8",panelBg:"#e9e5de",canvasBg:"#f5f2ed",inputBg:"#fff",border:"#d5cfc6",borderAccent:"#c4bdb2",borderStrong:"#a89f93",btnBg:"#d5cfc6",btnText:"#4a4540",btnDanger:"#c47066",textPrimary:"#3a3530",textSecondary:"#7a7468",textTertiary:"#9a9488",textMuted:"#b5ada2",trackName:"#4a4540",rulerTick:"#a89f93",rulerLabel:"#5a5550",tooltipBg:"#fff",tooltipBorder:"#d5cfc6",overlayBg:"rgba(0,0,0,0.2)",selectedRow:"#ddd8d0",centerLine:"#c4bdb2",geneCds:"#4caf50",geneExon:"#2e8bc0",geneGene:"#8e44ad",geneTranscript:"#c0392b",geneUtr:"#1abc9c",geneRrna:"#e67e22",geneTrna:"#e74c3c",geneRepeat:"#8d6e63",geneDefault:"#27ae60"},highContrast:{name:"High Contrast",appBg:"#000",headerBg:"#111",panelBg:"#111",canvasBg:"#000",inputBg:"#222",border:"#444",borderAccent:"#666",borderStrong:"#888",btnBg:"#444",btnText:"#fff",btnDanger:"#f44336",textPrimary:"#fff",textSecondary:"#ccc",textTertiary:"#aaa",textMuted:"#888",trackName:"#fff",rulerTick:"#aaa",rulerLabel:"#fff",tooltipBg:"#222",tooltipBorder:"#666",overlayBg:"rgba(0,0,0,0.7)",selectedRow:"#333",centerLine:"#555",geneCds:"#4caf50",geneExon:"#2196f3",geneGene:"#9c27b0",geneTranscript:"#e040fb",geneUtr:"#00e5ff",geneRrna:"#ff9800",geneTrna:"#ff1744",geneRepeat:"#ff6e40",geneDefault:"#69f0ae"}},xp="genomics-viewer-theme",vp="genomics-viewer-custom-theme";function B0(){try{const e=localStorage.getItem(xp),t=localStorage.getItem(vp);return{name:e&&(yt[e]||e==="custom")?e:"dark",custom:t?JSON.parse(t):null}}catch{return{name:"dark",custom:null}}}function A0({children:e}){const t=B0(),[n,r]=C.useState(t.name),[o,l]=C.useState(t.custom||{...yt.dark,name:"Custom"}),i=n==="custom"?o:yt[n]||yt.dark,s=C.useCallback(c=>{r(c),localStorage.setItem(xp,c)},[]),u=C.useCallback(c=>{l(c),localStorage.setItem(vp,JSON.stringify(c))},[]);return C.useEffect(()=>{document.body.style.background=i.appBg,document.body.style.color=i.textPrimary},[i.appBg,i.textPrimary]),a.jsx(yp.Provider,{value:{theme:i,themeName:n,setThemeName:s,customTheme:o,setCustomTheme:u},children:e})}function Ye(){return C.useContext(yp)}function z0(e){const t=e==null?void 0:e.compatibility;return t&&t.status!=="ok"&&t.status!=="no_genome"}function gc(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}const As=new Set([".gb",".gbk",".genbank",".fasta",".fa"]),zs=new Set([".bam",".bw",".bigwig",".wig",".bedgraph",".bdg",".vcf",".bed",".gtf",".gff",".gff2",".gff3"]),yc=50*1024*1024;function _l(e){if(!e)return"";const t=e.toLowerCase();if(t.endsWith(".vcf.gz"))return".vcf.gz";if(t.endsWith(".bam.bai"))return".bam.bai";const n=t.lastIndexOf(".");return n>=0?t.slice(n):""}function $0(e){const t=_l(e);return t===".bai"||t===".bam.bai"}function N0(e){const t=[],n=[],r=[],o=[],l=[],i=[];for(const c of e){const h=_l(c.name);As.has(h)?t.push(c):h===".bam"?n.push(c):$0(c.name)?r.push(c):zs.has(h)||h===".vcf.gz"?c.size>yc?i.push(c):o.push(c):l.push(c)}const s=[],u=[];for(const c of n){const h=c.name.replace(/\.bam$/i,""),d=r.find(g=>{const T=g.name.toLowerCase();return T===c.name.toLowerCase()+".bai"||T===h.toLowerCase()+".bai"});if(d){c.size>yc?i.push(c):s.push({file:c,indexFile:d});const g=r.indexOf(d);g!==-1&&r.splice(g,1)}else u.push(c)}for(const c of o)s.push({file:c,indexFile:null});for(const c of r)c._indexOrphan=!0;return l.push(...r),{genomeFiles:t,trackEntries:s,unpairedBams:u,largeFiles:i,unknownFiles:l}}function O0(){const{theme:e}=Ye(),{genome:t,setGenome:n,navigateTo:r}=it(),{addTrack:o,uploadTrack:l,commitTrack:i,discardTrack:s,addGenomeAnnotationTrack:u,error:c,setError:h}=Kt(),[d,g]=C.useState(!1),[T,v]=C.useState(null),[y,x]=C.useState(null),[f,p]=C.useState(null),[m,w]=C.useState(null),[S,E]=C.useState(null),[b,P]=C.useState(null),[N,$]=C.useState(""),[_,H]=C.useState(!1),j=C.useRef(null),U=C.useRef(null),O=C.useRef(null),G=[...Array.from(As),...Array.from(zs),".vcf.gz",".bai"].join(","),F={panel:{background:e.panelBg,borderBottom:`1px solid ${e.border}`,padding:"8px 12px",display:"flex",alignItems:"center",gap:12,flexWrap:"wrap",position:"relative"},group:{display:"flex",alignItems:"center",gap:6},label:{fontSize:11,color:e.textSecondary,textTransform:"uppercase",letterSpacing:1,whiteSpace:"nowrap"},fileInput:{background:e.inputBg,border:`1px solid ${e.borderAccent}`,borderRadius:4,color:e.textPrimary,padding:"4px 6px",fontSize:12,width:280,cursor:"pointer"},promptOverlay:{position:"fixed",inset:0,zIndex:9999,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},promptBox:{background:e.panelBg,border:`1px solid ${e.borderAccent}`,borderRadius:8,padding:"20px 24px",boxShadow:"0 8px 32px rgba(0,0,0,0.5)",maxWidth:440,width:"90%"},promptTitle:{fontSize:14,fontWeight:700,color:e.textPrimary,marginBottom:8},promptText:{fontSize:12,color:e.textSecondary,lineHeight:1.6,marginBottom:16},promptFile:{fontWeight:600,color:e.textPrimary},promptBtns:{display:"flex",gap:8,justifyContent:"flex-end",flexWrap:"wrap"},promptBtn:{background:e.btnBg,border:`1px solid ${e.borderStrong}`,borderRadius:4,color:e.btnText,padding:"5px 16px",cursor:"pointer",fontSize:12,fontWeight:600},promptBtnPrimary:{background:"#1976d2",border:"none",borderRadius:4,color:"#fff",padding:"5px 16px",cursor:"pointer",fontSize:12,fontWeight:600}};async function B(V){var J,ee,z;g(!0),v(null),p(null),x(`Uploading genome: ${V.name}...`);try{const q=await mn.load(V,Z=>{p({...Z,label:V.name}),Z.percent>=100&&x(`Processing genome: ${V.name}...`)});p(null);const Q=q.data;if(Q.name&&(Q.name=Nt(Q.name)),n(Q),((J=Q.chromosomes)==null?void 0:J.length)>0){const Z=Q.chromosomes[0];r(Z.name,0,Math.min(Z.length,5e4))}Q.is_annotated&&u({id:"genome_annotations",name:`${Q.name} (annotations)`,track_type:"genome_annotations",file_format:"genbank",targetChromosomes:Q.annotated_chromosomes||null}),x(`Genome loaded: ${Q.name}`),setTimeout(()=>x(null),3e3)}catch(q){v(((z=(ee=q.response)==null?void 0:ee.data)==null?void 0:z.detail)||q.message),x(null),p(null)}finally{g(!1)}}async function M(V){var ee,z;g(!0),v(null),p(null);const J=[];for(const q of V){x(`Adding chromosomes from ${q.name}...`);try{const Z=(await mn.addChromosomes(q,le=>{p({...le,label:q.name})})).data;Z.name&&(Z.name=Nt(Z.name)),n(Z),Z.is_annotated&&u({id:"genome_annotations",name:`${Z.name} (annotations)`,track_type:"genome_annotations",file_format:"genbank",targetChromosomes:Z.annotated_chromosomes||null})}catch(Q){J.push(`${q.name}: ${((z=(ee=Q.response)==null?void 0:ee.data)==null?void 0:z.detail)||Q.message}`)}}g(!1),J.length?(v(J.join("; ")),x(null)):(x(`Added chromosomes from ${V.length} file${V.length>1?"s":""}.`),setTimeout(()=>x(null),3e3))}async function I(V){var Q,Z;if(!V.length)return;g(!0),v(null),h(null),p(null);const J=[],ee=[],z=[],q=[];for(let le=0;le<V.length;le++){const{file:oe,indexFile:de}=V[le];x(`Loading track ${le+1}/${V.length}: ${oe.name}...`);try{const xe=await l(oe,void 0,de,Oe=>{p({...Oe,label:oe.name}),Oe.percent>=100&&x(`Processing: ${oe.name}...`)});z0(xe)?ee.push(xe):(i(xe),J.push(xe)),xe.hint&&q.push(xe.hint)}catch(xe){z.push(`${oe.name}: ${((Z=(Q=xe.response)==null?void 0:Q.data)==null?void 0:Z.detail)||xe.message}`)}}if(g(!1),p(null),z.length)v(z.join("; ")),x(null);else if(J.length>0&&ee.length===0){const le=`Added ${J.length} track${J.length>1?"s":""}.`;q.length?(x(le),setTimeout(()=>{x(q.join(" ")),setTimeout(()=>x(null),8e3)},2e3)):(x(le),setTimeout(()=>x(null),3e3))}else ee.length===0&&x(null);ee.length>0&&E({tracks:ee})}async function A(V){const J=Array.from(V);if(!J.length)return;const{genomeFiles:ee,trackEntries:z,unpairedBams:q,largeFiles:Q,unknownFiles:Z}=N0(J);if(Z.length){const le=Z.filter(de=>de._indexOrphan),oe=Z.filter(de=>!de._indexOrphan);le.length&&P({bamFile:null,indexFile:le[0],bamPath:"",indexPath:"",error:null}),oe.length&&v(`Unsupported: ${oe.map(de=>de.name).join(", ")}`)}if(Q.length>0){const le=Q[0],oe=(le.size/(1024*1024)).toFixed(0),de=le.name.toLowerCase().endsWith(".bam");P({bamFile:de?le:null,indexFile:null,bamPath:"",indexPath:"",error:null,_largeFile:le,_largeWarning:`${le.name} is ${oe} MB. Large files load much faster via file path — the server reads directly from disk without uploading.`}),Q.length>1&&v(`${Q.length-1} additional large file(s) skipped — load one at a time via path.`)}if(q.length>0&&Q.length===0&&P({bamFile:q[0],indexFile:null,bamPath:"",indexPath:"",error:null}),ee.length>0&&!t){if(await B(ee[0]),ee.length>1){z.length>0&&await I(z),w({files:ee.slice(1)}),j.current&&(j.current.value="");return}z.length>0&&await I(z)}else ee.length>0&&t?(z.length>0&&await I(z),w({files:ee})):z.length>0&&(t?await I(z):v("Load a genome file first (.fasta, .gb, .genbank)"));j.current&&(j.current.value="")}async function R(V){var Q,Z,le,oe,de;const J=V.trim();if(!J)return;v(null);const ee=J.toLowerCase(),z=As.has(_l(J)),q=zs.has(_l(J))||ee.endsWith(".vcf.gz")||ee.endsWith(".bai");if(z&&!t){g(!0),x("Loading genome from path...");try{const Oe=(await mn.loadPath(J)).data;if(Oe.name&&(Oe.name=Nt(Oe.name)),n(Oe),((Q=Oe.chromosomes)==null?void 0:Q.length)>0){const st=Oe.chromosomes[0];r(st.name,0,Math.min(st.length,5e4))}Oe.is_annotated&&u({id:"genome_annotations",name:`${Oe.name} (annotations)`,track_type:"genome_annotations",file_format:"genbank",targetChromosomes:Oe.annotated_chromosomes||null}),x(`Genome loaded: ${Oe.name}`),setTimeout(()=>x(null),3e3)}catch(xe){v(((le=(Z=xe.response)==null?void 0:Z.data)==null?void 0:le.detail)||xe.message),x(null)}finally{g(!1)}}else if(q||z){if(!t){v("Load a genome file first");return}g(!0),x("Loading track from path...");try{const xe=J.split(/[/\\]/).pop()||J,st=(await $t.loadPath(J,xe)).data;st.name&&(st.name=Nt(st.name)),i(st),x(`Track loaded: ${st.name}`),st.hint?setTimeout(()=>{x(st.hint),setTimeout(()=>x(null),8e3)},2e3):setTimeout(()=>x(null),3e3)}catch(xe){v(((de=(oe=xe.response)==null?void 0:oe.data)==null?void 0:de.detail)||xe.message),x(null)}finally{g(!1)}}else v(`Unsupported file type: ${J.split(/[/\\]/).pop()}`);$("")}function k(V){V.preventDefault(),R(N)}function D(V){const J=V.target.files;J!=null&&J.length&&(v(null),A(J))}async function Y(){if(!m)return;const{files:V}=m;w(null),await M(V)}async function K(){if(!m)return;const{files:V}=m;w(null),await I(V.map(J=>({file:J,indexFile:null})))}function re(){w(null)}function ue(){var V;(V=U.current)==null||V.click()}function pe(){var V;(V=O.current)==null||V.click()}function fe(V){var ee;const J=(ee=V.target.files)==null?void 0:ee[0];if(V.target.value="",!!J){if(!J.name.toLowerCase().endsWith(".bam")){P(z=>({...z,error:"Please select a .bam file"}));return}P(z=>({...z,bamFile:J,bamPath:"",error:null}))}}function ae(V){var ee;const J=(ee=V.target.files)==null?void 0:ee[0];if(V.target.value="",!!J){if(!J.name.toLowerCase().endsWith(".bai")){P(z=>({...z,error:"Please select a .bai index file"}));return}P(z=>({...z,indexFile:J,indexPath:"",error:null}))}}function ie(V){return V&&(V.bamFile||V.bamPath.trim())}function te(V){return V&&(V.indexFile||V.indexPath.trim())}function ge(V){return ie(V)&&te(V)}async function _e(){if(!b)return;const{bamFile:V,indexFile:J,bamPath:ee,indexPath:z,_largeFile:q}=b,Q=ee.trim(),Z=z.trim();if(q&&!q.name.toLowerCase().endsWith(".bam")){if(!Q){P(oe=>({...oe,error:"File path is required"}));return}P(null),await R(Q);return}if(!V&&!Q){P(oe=>({...oe,error:"BAM file or path is required"}));return}if(!J&&!Z){P(oe=>({...oe,error:"BAM index (.bai) file or path is required"}));return}if(Q&&!Q.toLowerCase().endsWith(".bam")){P(oe=>({...oe,error:"BAM path must end with .bam"}));return}if(Z&&!Z.toLowerCase().endsWith(".bai")){P(oe=>({...oe,error:"Index path must end with .bai"}));return}if(P(null),!V&&Q){await R(Q);return}await I([{file:V,indexFile:J}])}function ye(){P(null)}async function Ne(){if(S){for(const V of S.tracks)await s(V.id);E(null)}}function Je(){if(S){for(const V of S.tracks)i(V);E(null),x(`Added ${S.tracks.length} track${S.tracks.length>1?"s":""}.`),setTimeout(()=>x(null),3e3)}}const he=m?m.files.map(V=>V.name).join(", "):"",ht=m&&m.files.length>1;return a.jsxs("div",{style:F.panel,"data-tour":"file-loader",children:[a.jsxs("div",{style:F.group,title:"Select genome or track files",children:[a.jsx("span",{style:F.label,children:"Load Files"}),a.jsx("input",{ref:j,type:"file",multiple:!0,style:F.fileInput,disabled:d,accept:G,onChange:D})]}),a.jsxs("button",{style:{...F.group,background:"none",border:`1px solid ${e.borderAccent}`,borderRadius:4,padding:"3px 8px",cursor:"pointer",color:e.textSecondary,fontSize:11},onClick:()=>H(V=>!V),title:"Load file by local path (recommended for large BAM files)",children:[_?"✕":"📂"," Path"]}),_&&a.jsxs("form",{onSubmit:k,style:{display:"flex",gap:4},children:[a.jsx("input",{type:"text",value:N,onChange:V=>$(V.target.value),placeholder:"/path/to/file.bam",disabled:d,style:{background:e.inputBg,border:`1px solid ${e.borderAccent}`,borderRadius:4,color:e.textPrimary,padding:"4px 8px",fontSize:11,width:260,fontFamily:"monospace"}}),a.jsx("button",{type:"submit",disabled:d||!N.trim(),style:{background:e.btnBg,border:"none",borderRadius:4,color:e.btnText,padding:"4px 10px",cursor:"pointer",fontSize:11,fontWeight:600},children:"Load"})]}),d?a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0},children:[a.jsx("span",{style:{fontSize:10,color:e.textMuted,fontStyle:"italic",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:y||"Loading…"}),f&&a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flex:1,minWidth:100},children:[a.jsx("div",{style:{flex:1,height:6,background:e.inputBg,borderRadius:3,overflow:"hidden",minWidth:60},children:a.jsx("div",{style:{width:`${f.percent}%`,height:"100%",background:f.percent>=100?"#66bb6a":"#42a5f5",borderRadius:3,transition:"width 0.2s ease"}})}),a.jsx("span",{style:{fontSize:10,color:e.textTertiary,whiteSpace:"nowrap"},children:f.percent<100?`${gc(f.loaded)} / ${gc(f.total)}`:"Processing..."})]})]}):a.jsx("span",{style:{fontSize:10,color:e.textMuted,fontStyle:"italic"},children:"or drag & drop anywhere"}),!d&&y&&a.jsx("span",{style:{color:"#81c784",fontSize:11},children:y}),(T||c)&&a.jsx("span",{style:{color:"#ef9a9a",fontSize:11},children:T||c}),m&&a.jsx("div",{style:F.promptOverlay,children:a.jsxs("div",{style:F.promptBox,onClick:V=>V.stopPropagation(),children:[a.jsxs("div",{style:F.promptTitle,children:["Genome file",ht?"s":""," detected"]}),a.jsxs("div",{style:F.promptText,children:[a.jsx("span",{style:F.promptFile,children:he}),ht?" appear to be genome files. A genome is already loaded.":" appears to be a genome file. A genome is already loaded.",a.jsx("br",{}),"How would you like to handle ",ht?"them":"it","?"]}),a.jsxs("div",{style:F.promptBtns,children:[a.jsx("button",{style:F.promptBtn,onClick:re,children:"Skip"}),a.jsxs("button",{style:F.promptBtn,onClick:K,children:["Add as Track",ht?"s":""]}),a.jsxs("button",{style:F.promptBtnPrimary,onClick:Y,children:["Add as Chromosome",ht?"s":""]})]})]})}),S&&a.jsx("div",{style:F.promptOverlay,children:a.jsxs("div",{style:F.promptBox,onClick:V=>V.stopPropagation(),children:[a.jsx("div",{style:F.promptTitle,children:"Track compatibility warning"}),a.jsxs("div",{style:F.promptText,children:[S.tracks.map(V=>{var J;return a.jsxs("div",{style:{marginBottom:6},children:[a.jsx("span",{style:F.promptFile,children:V.name})," — ",((J=V.compatibility)==null?void 0:J.message)||"Possible mismatch with loaded genome"]},V.id)}),a.jsx("div",{style:{marginTop:8},children:S.tracks.length>1?"These tracks may not match the loaded genome.":"This track may not match the loaded genome."})]}),a.jsxs("div",{style:F.promptBtns,children:[a.jsx("button",{style:F.promptBtn,onClick:Ne,children:"Skip"}),a.jsx("button",{style:F.promptBtnPrimary,onClick:Je,children:"Load Anyway"})]})]})}),b&&(()=>{const V=b._largeFile&&!b._largeFile.name.toLowerCase().endsWith(".bam"),J=V?!!b.bamPath.trim():ge(b),ee=b.bamFile?b.bamFile.size/(1024*1024):0,z=b.bamFile&&ee>50,q=ie(b),Q=te(b),Z={flex:1,padding:"5px 8px",borderRadius:4,fontSize:11,background:e.inputBg,color:e.textPrimary,fontFamily:"monospace"},le=V?`Load ${b._largeFile.name.split(".").pop().toUpperCase()} Track`:"Load BAM Track",oe=V?"Paste the local file path for the server to read directly from disk.":"BAM files require a matching .bai index. Browse for files or paste local paths.";return a.jsx("div",{style:F.promptOverlay,onClick:ye,children:a.jsxs("div",{style:{...F.promptBox,maxWidth:500},onClick:de=>de.stopPropagation(),children:[a.jsx("div",{style:F.promptTitle,children:le}),a.jsx("div",{style:{...F.promptText,marginBottom:12},children:oe}),a.jsxs("div",{style:{marginBottom:10},children:[a.jsxs("div",{style:{fontSize:11,color:e.textSecondary,marginBottom:4,fontWeight:600},children:[V?"File path":".bam file"," ",q&&a.jsx("span",{style:{color:"#66bb6a"},children:"✓"})]}),a.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[a.jsx("input",{type:"text",value:b.bamFile?b.bamFile.name:b.bamPath,onChange:de=>P(xe=>({...xe,bamPath:de.target.value,bamFile:null,error:null})),placeholder:V?"/path/to/file":"/path/to/reads.bam",style:{...Z,border:`1px solid ${q?"#66bb6a":e.borderAccent}`}}),!V&&a.jsx("button",{style:{...F.promptBtn,padding:"4px 12px",whiteSpace:"nowrap"},onClick:ue,children:"Browse"})]})]}),!V&&a.jsxs("div",{style:{marginBottom:12},children:[a.jsxs("div",{style:{fontSize:11,color:e.textSecondary,marginBottom:4,fontWeight:600},children:[".bai index ",Q&&a.jsx("span",{style:{color:"#66bb6a"},children:"✓"})]}),a.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[a.jsx("input",{type:"text",value:b.indexFile?b.indexFile.name:b.indexPath,onChange:de=>P(xe=>({...xe,indexPath:de.target.value,indexFile:null,error:null})),placeholder:"/path/to/reads.bam.bai",style:{...Z,border:`1px solid ${Q?"#66bb6a":e.borderAccent}`}}),a.jsx("button",{style:{...F.promptBtn,padding:"4px 12px",whiteSpace:"nowrap"},onClick:pe,children:"Browse"})]})]}),a.jsx("input",{ref:U,type:"file",accept:".bam",style:{display:"none"},onChange:fe}),a.jsx("input",{ref:O,type:"file",accept:".bai,.bam.bai",style:{display:"none"},onChange:ae}),(z||b._largeWarning)&&a.jsx("div",{style:{fontSize:11,color:"#ffb74d",marginBottom:8,padding:"6px 10px",background:"rgba(255,183,77,0.1)",borderRadius:4,border:"1px solid rgba(255,183,77,0.3)"},children:b._largeWarning||a.jsxs(a.Fragment,{children:[a.jsxs("strong",{children:["Large file (",ee.toFixed(0)," MB)"]})," — uploading may be slow. Paste the file path instead for instant loading."]})}),b.error&&a.jsx("div",{style:{fontSize:11,color:"#ef9a9a",marginBottom:8,padding:"4px 0"},children:b.error}),!z&&a.jsx("div",{style:{fontSize:10,color:e.textTertiary,marginBottom:10},children:"Tip: Paste a local file path to skip uploading — the server reads directly from disk. The .bai is auto-discovered if next to the .bam."}),a.jsxs("div",{style:F.promptBtns,children:[a.jsx("button",{style:F.promptBtn,onClick:ye,children:"Cancel"}),a.jsx("button",{style:{...F.promptBtnPrimary,opacity:J?1:.4,cursor:J?"pointer":"default"},disabled:!J,onClick:_e,children:"Open"})]})]})})})()]})}const F0=320,I0=200;function wp({title:e,onClose:t,theme:n,children:r,defaultWidth:o=440,defaultHeight:l=500}){const[i,s]=C.useState(()=>({x:Math.max(20,window.innerWidth-o-40),y:80})),[u,c]=C.useState({w:o,h:Math.min(l,window.innerHeight-120)}),h=C.useRef(null),d=C.useRef(null),g=C.useRef(null),T=C.useCallback(x=>{if(x.target.closest("input, select, button, label, textarea"))return;x.preventDefault(),h.current={startX:x.clientX,startY:x.clientY,startPos:{...i}};function f(m){h.current&&s({x:Math.max(0,Math.min(window.innerWidth-100,h.current.startPos.x+m.clientX-h.current.startX)),y:Math.max(0,Math.min(window.innerHeight-40,h.current.startPos.y+m.clientY-h.current.startY))})}function p(){h.current=null,window.removeEventListener("mousemove",f),window.removeEventListener("mouseup",p)}window.addEventListener("mousemove",f),window.addEventListener("mouseup",p)},[i]),v=C.useCallback(x=>{x.preventDefault(),x.stopPropagation(),d.current={startX:x.clientX,startY:x.clientY,startSize:{...u}};function f(m){d.current&&c({w:Math.max(F0,d.current.startSize.w+m.clientX-d.current.startX),h:Math.max(I0,d.current.startSize.h+m.clientY-d.current.startY)})}function p(){d.current=null,window.removeEventListener("mousemove",f),window.removeEventListener("mouseup",p),document.body.style.cursor=""}document.body.style.cursor="nwse-resize",window.addEventListener("mousemove",f),window.addEventListener("mouseup",p)},[u]),y={panel:{position:"fixed",left:i.x,top:i.y,width:u.w,height:u.h,zIndex:1e3,background:n.panelBg,border:`1px solid ${n.borderAccent}`,borderRadius:8,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.5)",overflow:"hidden"},header:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"8px 14px",borderBottom:`1px solid ${n.border}`,cursor:"grab",userSelect:"none",flexShrink:0},title:{fontSize:13,fontWeight:700,color:n.textPrimary},closeBtn:{background:"none",border:"none",color:n.textSecondary,cursor:"pointer",fontSize:16,lineHeight:1,padding:"0 4px"},body:{flex:1,overflowY:"auto",overflowX:"hidden"},resizeHandle:{position:"absolute",right:0,bottom:0,width:14,height:14,cursor:"nwse-resize",zIndex:1}};return a.jsxs("div",{ref:g,style:y.panel,children:[a.jsxs("div",{style:y.header,onMouseDown:T,children:[a.jsx("span",{style:y.title,children:e}),a.jsx("button",{style:y.closeBtn,onClick:t,children:"✕"})]}),a.jsx("div",{style:y.body,children:r}),a.jsx("div",{style:y.resizeHandle,onMouseDown:v,title:"Drag to resize",children:a.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",style:{display:"block"},children:a.jsx("path",{d:"M12 2L2 12M12 6L6 12M12 10L10 12",stroke:n.textTertiary,strokeWidth:"1.5",fill:"none"})})})]})}const D0=["#f44336","#e53935","#ef5350","#e57373","#ff5722","#ff8a65","#ff9800","#ffa726","#ffb74d","#ffc107","#ffd54f","#fff176","#4caf50","#66bb6a","#81c784","#aed581","#009688","#26c6da","#4dd0e1","#80cbc4","#2196f3","#42a5f5","#64b5f6","#3f51b5","#7e57c2","#9575cd","#9c27b0","#ab47bc","#ce93d8","#e91e63","#f06292","#795548","#8d6e63","#607d8b","#78909c"];function U0({onClose:e}){const{theme:t}=Ye(),{tracks:n,updateTrack:r,updateMultipleTracks:o,removeTrack:l}=Kt(),[i,s]=C.useState(new Set);function u(k){s(D=>{const Y=new Set(D);return Y.has(k)?Y.delete(k):Y.add(k),Y})}function c(){s(new Set(n.map(k=>k.id)))}function h(){s(new Set)}const d=n.filter(k=>i.has(k.id)),g=d.some(k=>k.track_type==="annotations"||k.track_type==="genome_annotations"),T=d.some(k=>k.track_type==="coverage"||k.track_type==="reads"),v=d.some(k=>k.track_type==="reads"),y=d.some(k=>k.track_type==="coverage"||k.track_type==="reads"||k.track_type==="variants"),x=d.length>0&&d.every(k=>k.height===d[0].height)?d[0].height:"",f=d.length>0&&d.every(k=>k.color===d[0].color)?d[0].color:"#888888",p=d.length>0&&d.every(k=>k.visible===d[0].visible)?d[0].visible:null,m=d.length>0&&d.every(k=>k.useArrows===d[0].useArrows)?d[0].useArrows:null,w=d.length>0&&d.every(k=>k.scaleMax===d[0].scaleMax)?d[0].scaleMax:void 0,S=d.length>0&&d.every(k=>k.scaleMin===d[0].scaleMin)?d[0].scaleMin:void 0,E=w==null&&S==null,b=d.length>0&&d.every(k=>k.logScale===d[0].logScale)?d[0].logScale:null,P=d.length>0&&d.every(k=>k.barAutoWidth===d[0].barAutoWidth)?d[0].barAutoWidth:null,N=d.length>0&&d.every(k=>k.barWidth===d[0].barWidth)?d[0].barWidth:void 0,$=d.length>0&&d.every(k=>k.showOutline===d[0].showOutline)?d[0].showOutline:null,_=d.length>0&&d.every(k=>k.outlineColor===d[0].outlineColor)?d[0].outlineColor:void 0,H=d.length>0&&d.every(k=>k.outlineSmooth===d[0].outlineSmooth)?d[0].outlineSmooth:void 0,j=d.length>0&&d.every(k=>k.showBars===d[0].showBars)?d[0].showBars:null,U=d.length>0&&d.every(k=>k.showNucleotides===d[0].showNucleotides)?d[0].showNucleotides:null,O=d.length>0&&d.every(k=>(k.fwdColor||"#90a4ae")===(d[0].fwdColor||"#90a4ae"))?d[0].fwdColor||"#90a4ae":void 0,G=d.length>0&&d.every(k=>(k.revColor||"#f06292")===(d[0].revColor||"#f06292"))?d[0].revColor||"#f06292":void 0,F=d.length>0&&d.every(k=>(k.arrowStyle||"pointed")===(d[0].arrowStyle||"pointed"))?d[0].arrowStyle||"pointed":void 0,B=d.length>0&&d.every(k=>(k.arrowSize||4)===(d[0].arrowSize||4))?d[0].arrowSize||4:void 0;function M(k){o([...i],k)}function I(){for(const k of i)l(k);s(new Set)}const A=t,R={body:{padding:"8px 0",overflowY:"auto",flex:1},trackRow:{display:"flex",alignItems:"center",gap:8,padding:"5px 16px",cursor:"pointer",transition:"background 0.1s"},trackRowSelected:{background:A.selectedRow},checkbox:{width:14,height:14,cursor:"pointer",flexShrink:0},trackLabel:{fontSize:12,color:A.textPrimary,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},trackType:{fontSize:10,color:A.textTertiary,flexShrink:0},section:{padding:"12px 16px",borderTop:`1px solid ${A.border}`},sectionTitle:{fontSize:11,color:A.textSecondary,textTransform:"uppercase",letterSpacing:1,marginBottom:8},controlRow:{display:"flex",alignItems:"center",gap:10,marginBottom:6},controlLabel:{fontSize:12,color:A.textSecondary,width:90},input:{background:A.inputBg,border:`1px solid ${A.borderAccent}`,borderRadius:4,color:A.textPrimary,padding:"3px 6px",fontSize:12,width:70},colorInput:{width:28,height:22,border:"none",background:"none",cursor:"pointer",padding:0},btn:{background:A.btnBg,color:A.btnText},btnDanger:{background:A.btnDanger,border:"none",borderRadius:4,color:"#fff",padding:"5px 14px",cursor:"pointer",fontSize:12,fontWeight:600},footer:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"10px 16px",borderTop:`1px solid ${A.border}`,gap:8},smallBtn:{background:"none",border:`1px solid ${A.borderAccent}`,borderRadius:3,color:A.textSecondary,cursor:"pointer",fontSize:10,padding:"2px 8px"},cbLabel:{fontSize:12,color:A.textSecondary,cursor:"pointer",display:"flex",alignItems:"center",gap:4}};return a.jsxs(wp,{title:"Track Settings",onClose:e,theme:A,defaultWidth:460,defaultHeight:520,children:[a.jsx("div",{style:R.body,children:n.length===0?a.jsx("div",{style:{padding:16,color:A.textTertiary,fontSize:12},children:"No tracks loaded."}):n.map(k=>a.jsxs("div",{style:{...R.trackRow,...i.has(k.id)?R.trackRowSelected:{}},onClick:()=>u(k.id),children:[a.jsx("input",{type:"checkbox",checked:i.has(k.id),onChange:()=>u(k.id),onClick:D=>D.stopPropagation(),style:R.checkbox}),a.jsx("span",{style:{width:10,height:10,borderRadius:2,background:k.color,flexShrink:0}}),a.jsx("span",{style:{...R.trackLabel,opacity:k.visible?1:.4},children:k.name}),a.jsx("span",{style:R.trackType,children:k.track_type})]},k.id))}),d.length>0&&a.jsxs("div",{style:R.section,children:[a.jsxs("div",{style:R.sectionTitle,children:["Edit ",d.length," selected track",d.length>1?"s":""]}),y&&a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Fill bars"}),a.jsxs("label",{style:R.cbLabel,children:[a.jsx("input",{type:"checkbox",checked:j!==!1,ref:k=>{k&&(k.indeterminate=j===null)},onChange:k=>M({showBars:k.target.checked}),style:{cursor:"pointer"}}),"Show"]}),j!==!1&&a.jsx("input",{type:"color",value:f,style:R.colorInput,onChange:k=>M({color:k.target.value}),title:"Bar fill color"})]}),!y&&!g&&a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Color"}),a.jsx("input",{type:"color",value:f,style:R.colorInput,onChange:k=>M({color:k.target.value})})]}),g&&a.jsx(H0,{tracks:d,applyToSelected:M,theme:A}),a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Height (px)"}),a.jsx("input",{type:"range",min:30,max:500,step:1,value:x||80,onChange:k=>M({height:parseInt(k.target.value)}),style:{flex:1,cursor:"pointer",accentColor:A.textSecondary}}),a.jsx("input",{type:"text",inputMode:"numeric",value:x,placeholder:"mixed",style:{...R.input,width:48},onChange:k=>{const D=parseInt(k.target.value);D>=30&&D<=500&&M({height:D})},onBlur:k=>{const D=parseInt(k.target.value);(!D||D<30)&&M({height:30}),D>500&&M({height:500})}})]}),a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Visible"}),a.jsxs("label",{style:R.cbLabel,children:[a.jsx("input",{type:"checkbox",checked:p===!0,ref:k=>{k&&(k.indeterminate=p===null)},onChange:k=>M({visible:k.target.checked}),style:{cursor:"pointer"}}),"Show"]})]}),y&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Bar width"}),a.jsxs("label",{style:R.cbLabel,children:[a.jsx("input",{type:"checkbox",checked:P!==!1,ref:k=>{k&&(k.indeterminate=P===null)},onChange:k=>M({barAutoWidth:k.target.checked}),style:{cursor:"pointer"}}),"Auto"]})]}),P===!1&&a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel}),a.jsx("input",{type:"range",min:1,max:50,step:1,value:N??2,onChange:k=>M({barWidth:parseInt(k.target.value)}),style:{flex:1,cursor:"pointer",accentColor:A.textSecondary}}),a.jsx("input",{type:"number",min:1,max:50,step:1,value:N??2,style:{...R.input,width:48},onChange:k=>{const D=parseInt(k.target.value);D>=1&&D<=50&&M({barWidth:D})}}),a.jsx("span",{style:{fontSize:11,color:A.textTertiary},children:"px"})]})]}),y&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Peak outline"}),a.jsxs("label",{style:R.cbLabel,children:[a.jsx("input",{type:"checkbox",checked:$===!0,ref:k=>{k&&(k.indeterminate=$===null)},onChange:k=>M({showOutline:k.target.checked}),style:{cursor:"pointer"}}),"Trace peaks"]}),$===!0&&a.jsx("input",{type:"color",value:_||f||"#ffffff",onChange:k=>M({outlineColor:k.target.value}),title:"Outline color",style:{width:22,height:18,border:"none",background:"none",cursor:"pointer",padding:0,marginLeft:4}})]}),$===!0&&a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Smoothness"}),a.jsx("input",{type:"range",min:0,max:10,step:1,value:H??0,onChange:k=>M({outlineSmooth:parseInt(k.target.value)}),style:{flex:1,cursor:"pointer",accentColor:A.textSecondary}}),a.jsx("span",{style:{fontSize:11,color:A.textTertiary,width:24,textAlign:"right"},children:H??0})]})]}),g&&a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Gene style"}),a.jsxs("label",{style:R.cbLabel,children:[a.jsx("input",{type:"checkbox",checked:m===!0,ref:k=>{k&&(k.indeterminate=m===null)},onChange:k=>M({useArrows:k.target.checked}),style:{cursor:"pointer"}}),"Pointed arrows"]})]}),(v||g)&&a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Nucleotides"}),a.jsxs("label",{style:R.cbLabel,children:[a.jsx("input",{type:"checkbox",checked:U!==!1,ref:k=>{k&&(k.indeterminate=U===null)},onChange:k=>M({showNucleotides:k.target.checked}),style:{cursor:"pointer"}}),"Show when zoomed in"]})]}),v&&a.jsxs(a.Fragment,{children:[a.jsx("div",{style:{...R.sectionTitle,marginTop:12},children:"Read Appearance"}),a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Strand colors"}),a.jsx("span",{style:{fontSize:10,color:A.textTertiary,marginRight:2},children:"▶"}),a.jsx("input",{type:"color",value:O||"#90a4ae",onChange:k=>M({fwdColor:k.target.value}),title:"Forward strand color",style:{width:22,height:18,border:"none",background:"none",cursor:"pointer",padding:0}}),a.jsx("span",{style:{fontSize:10,color:A.textTertiary,marginLeft:6,marginRight:2},children:"◀"}),a.jsx("input",{type:"color",value:G||"#f06292",onChange:k=>M({revColor:k.target.value}),title:"Reverse strand color",style:{width:22,height:18,border:"none",background:"none",cursor:"pointer",padding:0}}),a.jsx("button",{style:{...R.smallBtn,marginLeft:"auto"},onClick:()=>M({fwdColor:null,revColor:null}),title:"Reset to defaults",children:"Reset"})]}),a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Arrow style"}),a.jsxs("select",{value:F||"pointed",onChange:k=>M({arrowStyle:k.target.value}),style:{background:A.inputBg,border:`1px solid ${A.borderAccent}`,borderRadius:4,color:A.textPrimary,padding:"2px 6px",fontSize:11,cursor:"pointer"},children:[a.jsx("option",{value:"pointed",children:"Pointed"}),a.jsx("option",{value:"chevron",children:"Chevron"}),a.jsx("option",{value:"fade",children:"Fade"}),a.jsx("option",{value:"flat",children:"Flat (none)"})]})]}),(F||"pointed")!=="flat"&&a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Arrow size"}),a.jsx("input",{type:"range",min:2,max:12,step:1,value:B||4,onChange:k=>M({arrowSize:parseInt(k.target.value)}),style:{flex:1,cursor:"pointer",accentColor:A.textSecondary}}),a.jsx("span",{style:{fontSize:11,color:A.textTertiary,width:20,textAlign:"right"},children:B||4})]})]}),T&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Y Scale"}),a.jsxs("label",{style:R.cbLabel,children:[a.jsx("input",{type:"checkbox",checked:E,onChange:k=>M(k.target.checked?{scaleMax:null,scaleMin:null}:{scaleMax:100,scaleMin:100}),style:{cursor:"pointer"}}),"Auto"]})]}),!E&&a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel}),a.jsx("span",{style:{fontSize:11,color:A.textTertiary,width:40},children:"+Ymax"}),a.jsx("input",{type:"number",min:1,step:10,value:w??"",placeholder:"max",style:R.input,onChange:k=>{const D=parseFloat(k.target.value);D>0&&M({scaleMax:D})}}),a.jsxs("span",{style:{fontSize:11,color:A.textTertiary,width:40},children:["−","Ymax"]}),a.jsx("input",{type:"number",min:1,step:10,value:S??"",placeholder:"min",style:R.input,onChange:k=>{const D=parseFloat(k.target.value);D>0&&M({scaleMin:D})}})]}),a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Log scale"}),a.jsxs("label",{style:R.cbLabel,children:[a.jsx("input",{type:"checkbox",checked:b===!0,ref:k=>{k&&(k.indeterminate=b===null)},onChange:k=>M({logScale:k.target.checked}),style:{cursor:"pointer"}}),"log","₂"]})]})]})]}),a.jsxs("div",{style:R.footer,children:[a.jsxs("div",{style:{display:"flex",gap:6},children:[a.jsx("button",{style:R.smallBtn,onClick:c,children:"Select all"}),a.jsx("button",{style:R.smallBtn,onClick:h,children:"Select none"})]}),a.jsx("div",{style:{display:"flex",gap:8},children:d.length>0&&a.jsxs("button",{style:R.btnDanger,onClick:I,children:["Remove (",d.length,")"]})})]})]})}const W0=[{key:"cds",label:"CDS"},{key:"exon",label:"Exon"},{key:"gene",label:"Gene"},{key:"transcript",label:"Transcript"},{key:"utr",label:"UTR"},{key:"rrna",label:"rRNA"},{key:"trna",label:"tRNA"},{key:"repeat",label:"Repeat"},{key:"default",label:"Other"}];function H0({tracks:e,applyToSelected:t,theme:n}){var T;const[r,o]=C.useState(null),l=C.useRef(null),[i,s]=C.useState(null),u=((T=e[0])==null?void 0:T.annotationColors)||{};function c(v){return u[v]||gp[v]||"#80cbc4"}function h(v,y){for(const x of e){const f={...x.annotationColors||{},[v]:y};t({annotationColors:f})}}function d(){t({annotationColors:null})}function g(v){s(v),l.current&&(l.current.value=c(v),l.current.click())}return a.jsxs("div",{style:{padding:"4px 0"},children:[a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6,padding:"0 0 0 0"},children:[a.jsx("span",{style:{fontSize:12,color:n.textSecondary,width:90},children:"Annotation colors"}),a.jsx("button",{style:{background:"none",border:`1px solid ${n.borderAccent}`,borderRadius:3,color:n.textTertiary,cursor:"pointer",fontSize:10,padding:"1px 6px"},onClick:d,children:"Reset"})]}),W0.map(({key:v,label:y})=>{const x=c(v);return a.jsxs("div",{children:[a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"3px 4px",cursor:"pointer",fontSize:11,color:n.textPrimary,borderRadius:3},onMouseEnter:f=>f.currentTarget.style.background=n.selectedRow||"rgba(255,255,255,0.05)",onMouseLeave:f=>f.currentTarget.style.background="transparent",onClick:()=>o(r===v?null:v),children:[a.jsx("span",{style:{width:14,height:14,borderRadius:3,background:x,border:"1px solid rgba(255,255,255,0.15)",flexShrink:0,cursor:"pointer"},onDoubleClick:f=>{f.stopPropagation(),g(v)},title:"Click to expand swatches, double-click for full color picker"}),a.jsx("span",{style:{flex:1},children:y}),a.jsx("span",{style:{fontSize:9,color:n.textTertiary},children:r===v?"▲":"▼"})]}),r===v&&a.jsx("div",{style:{padding:"3px 4px 6px 24px",display:"flex",flexWrap:"wrap",gap:2},children:D0.map(f=>a.jsx("span",{style:{width:16,height:16,borderRadius:3,background:f,cursor:"pointer",border:f===x?`2px solid ${n.textPrimary}`:"1px solid rgba(255,255,255,0.1)",boxSizing:"border-box"},onClick:()=>{h(v,f),o(null)}},f))})]},v)}),a.jsx("input",{ref:l,type:"color",style:{position:"absolute",left:-9999,top:-9999,opacity:0,width:0,height:0},onChange:v=>{i&&h(i,v.target.value)}})]})}const V0=["dark","light","colorblind","soft","highContrast"],xc=[{key:"appBg",label:"Background",group:"ui"},{key:"panelBg",label:"Panel",group:"ui"},{key:"canvasBg",label:"Canvas",group:"ui"},{key:"btnBg",label:"Buttons",group:"ui"},{key:"textPrimary",label:"Text",group:"ui"},{key:"textSecondary",label:"Text secondary",group:"ui"},{key:"border",label:"Borders",group:"ui"},{key:"geneCds",label:"CDS",group:"gene"},{key:"geneExon",label:"Exon",group:"gene"},{key:"geneGene",label:"Gene",group:"gene"},{key:"geneTranscript",label:"Transcript",group:"gene"},{key:"geneUtr",label:"UTR",group:"gene"},{key:"geneRrna",label:"rRNA",group:"gene"},{key:"geneTrna",label:"tRNA",group:"gene"},{key:"geneRepeat",label:"Repeat",group:"gene"},{key:"geneDefault",label:"Default feature",group:"gene"}],G0=["#000000","#1a1a1a","#333333","#4d4d4d","#666666","#808080","#999999","#b3b3b3","#cccccc","#e6e6e6","#f2f2f2","#ffffff","#4e0000","#7f0000","#b71c1c","#c62828","#d32f2f","#e53935","#ef5350","#f44336","#ef9a9a","#ffcdd2","#ffebee","#fff5f5","#4e2600","#7f3d00","#e65100","#ef6c00","#f57c00","#fb8c00","#ff9800","#ffa726","#ffb74d","#ffcc80","#ffe0b2","#fff3e0","#4e4400","#7f6f00","#f57f17","#f9a825","#fbc02d","#fdd835","#ffeb3b","#fff176","#fff59d","#fff9c4","#fffde7","#fffff0","#003300","#1b5e20","#2e7d32","#388e3c","#43a047","#4caf50","#66bb6a","#81c784","#a5d6a7","#c8e6c9","#e8f5e9","#f1f8e9","#003333","#004d40","#00695c","#00796b","#00897b","#009688","#26a69a","#4db6ac","#80cbc4","#b2dfdb","#e0f2f1","#e0f7fa","#001a33","#0d47a1","#1565c0","#1976d2","#1e88e5","#2196f3","#42a5f5","#64b5f6","#90caf9","#bbdefb","#e3f2fd","#e8eaf6","#1a0033","#311b92","#4527a0","#512da8","#5e35b1","#673ab7","#7e57c2","#9575cd","#b39ddb","#d1c4e9","#ede7f6","#f3e5f5","#330019","#880e4f","#ad1457","#c2185b","#d81b60","#e91e63","#ec407a","#f06292","#f48fb1","#f8bbd0","#fce4ec","#fff0f5","#1b0000","#3e2723","#4e342e","#5d4037","#6d4c41","#795548","#8d6e63","#a1887f","#bcaaa4","#d7ccc8","#efebe9","#fafafa"];function Y0({onClose:e}){const{theme:t,themeName:n,setThemeName:r,customTheme:o,setCustomTheme:l}=Ye(),[i,s]=C.useState(n==="custom"),[u,c]=C.useState(null),[h,d]=C.useState({left:0,top:0}),g=C.useRef(null),T=C.useRef(null);function v(b){r(b),s(!1)}function y(){const b=n==="custom"?o:yt[n]||yt.dark;l({...b,name:"Custom"}),r("custom"),s(!0)}function x(b,P){l({...o,[b]:P})}function f(b,P){const N=P.currentTarget.getBoundingClientRect(),$=window.innerWidth-N.right,_=290,H=260;let j,U;$>_+10?(j=N.right+6,U=Math.min(N.top,window.innerHeight-H-10)):(j=Math.max(10,N.left-_-6),U=Math.min(N.top,window.innerHeight-H-10)),d({left:j,top:U}),c(b)}function p(b){u&&x(u,b),c(null)}function m(b){T.current=b,g.current&&(g.current.value=E[b]||"#000000",g.current.click())}function w(b){T.current&&x(T.current,b.target.value)}const S=Q0(t),E=n==="custom"?o:yt[n]||yt.dark;return a.jsxs(wp,{title:"Color Scheme",onClose:e,theme:t,defaultWidth:420,defaultHeight:480,children:[a.jsxs("div",{style:S.body,children:[a.jsxs("div",{style:S.section,children:[a.jsx("div",{style:S.sectionTitle,children:"Presets"}),a.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:V0.map(b=>a.jsxs("button",{onClick:()=>v(b),style:{...S.presetBtn,border:n===b?`2px solid ${t.textPrimary}`:`1px solid ${t.borderAccent}`},children:[a.jsxs("div",{style:{display:"flex",gap:2,marginBottom:4},children:[a.jsx("span",{style:{width:14,height:14,borderRadius:2,background:yt[b].appBg,border:"1px solid #555"}}),a.jsx("span",{style:{width:14,height:14,borderRadius:2,background:yt[b].headerBg,border:"1px solid #555"}}),a.jsx("span",{style:{width:14,height:14,borderRadius:2,background:yt[b].btnBg,border:"1px solid #555"}})]}),a.jsx("span",{style:{fontSize:10,color:t.textSecondary},children:yt[b].name})]},b))})]}),a.jsxs("div",{style:S.section,children:[a.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[a.jsx("div",{style:S.sectionTitle,children:"Custom Palette"}),i?a.jsx("button",{onClick:()=>s(!1),style:S.smallBtn,children:"Collapse"}):a.jsx("button",{onClick:y,style:S.btn,children:"Customize"})]}),i&&a.jsxs("div",{children:[a.jsx("div",{style:{fontSize:10,color:t.textTertiary,textTransform:"uppercase",letterSpacing:1,marginTop:4,marginBottom:6},children:"Interface"}),a.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"4px 12px"},children:xc.filter(b=>b.group==="ui").map(({key:b,label:P})=>a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[a.jsx("span",{style:{display:"inline-block",width:20,height:16,borderRadius:3,background:E[b]||"#000",border:`1px solid ${t.borderAccent}`,cursor:"pointer",flexShrink:0},onMouseDown:N=>f(b,N),onDoubleClick:()=>{c(null),m(b)}}),a.jsx("span",{style:{fontSize:11,color:t.textSecondary},children:P})]},b))}),a.jsx("div",{style:{fontSize:10,color:t.textTertiary,textTransform:"uppercase",letterSpacing:1,marginTop:10,marginBottom:6},children:"Gene Features"}),a.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:"4px 12px"},children:xc.filter(b=>b.group==="gene").map(({key:b,label:P})=>a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[a.jsx("span",{style:{display:"inline-block",width:20,height:16,borderRadius:3,background:E[b]||"#000",border:`1px solid ${t.borderAccent}`,cursor:"pointer",flexShrink:0},onMouseDown:N=>f(b,N),onDoubleClick:()=>{c(null),m(b)}}),a.jsx("span",{style:{fontSize:11,color:t.textSecondary},children:P})]},b))})]})]})]}),a.jsx("div",{style:S.footer,children:a.jsx("button",{style:S.btn,onClick:e,children:"Close"})}),a.jsx("input",{ref:g,type:"color",onChange:w,style:{position:"fixed",left:-9999,top:-9999,opacity:0,width:0,height:0}}),u&&Dn.createPortal(a.jsx("div",{style:{position:"fixed",left:h.left,top:h.top,zIndex:10002,background:t.panelBg,border:`1px solid ${t.borderAccent}`,borderRadius:6,padding:8,boxShadow:"0 6px 20px rgba(0,0,0,0.6)",display:"grid",gridTemplateColumns:"repeat(12, 20px)",gap:2,maxHeight:300,overflowY:"auto"},onMouseLeave:()=>c(null),children:G0.map((b,P)=>a.jsx("span",{style:{width:20,height:20,borderRadius:3,background:b,cursor:"pointer",border:b===(E[u]||"")?`2px solid ${t.textPrimary}`:"1px solid rgba(128,128,128,0.3)",boxSizing:"border-box"},onMouseUp:()=>p(b)},P))}),document.body)]})}function Q0(e){return{overlay:{position:"fixed",inset:0,background:e.overlayBg,display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},panel:{background:e.panelBg,border:`1px solid ${e.borderAccent}`,borderRadius:8,padding:0,minWidth:440,maxWidth:560,maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.5)"},header:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"10px 16px",borderBottom:`1px solid ${e.border}`},title:{fontSize:14,fontWeight:700,color:e.textPrimary},closeBtn:{background:"none",border:"none",color:e.textSecondary,cursor:"pointer",fontSize:18,lineHeight:1,padding:"0 4px"},body:{padding:"8px 0",overflowY:"auto",flex:1},section:{padding:"8px 16px"},sectionTitle:{fontSize:11,color:e.textSecondary,textTransform:"uppercase",letterSpacing:1,marginBottom:0},presetBtn:{background:e.panelBg,borderRadius:6,padding:"8px 10px",cursor:"pointer",display:"flex",flexDirection:"column",alignItems:"center",minWidth:70},smallBtn:{background:"none",border:`1px solid ${e.borderAccent}`,borderRadius:3,color:e.textSecondary,cursor:"pointer",fontSize:10,padding:"3px 8px"},btn:{background:e.btnBg,border:"none",borderRadius:4,color:e.btnText,padding:"5px 14px",cursor:"pointer",fontSize:12,fontWeight:600},footer:{display:"flex",justifyContent:"flex-end",padding:"10px 16px",borderTop:`1px solid ${e.border}`}}}const Pi=5e4,X0=.5,K0=100,q0=800;function J0(e=200){const t=new Map;return{get(n){return t.get(n)},set(n,r){t.size>=e&&t.delete(t.keys().next().value),t.set(n,r)},findByPrefix(n){let r=null;for(const[o,l]of t)o.startsWith(n)&&(r=l);return r}}}const jn=J0(),$a=new Map;function vc(e,t){$a.set(e,t)}function Sp(e){return $a.get(e)||null}function Z0(e,t){const n=$a.get(e);return n||jn.findByPrefix(`${e}|coverage|${t}|`)||jn.findByPrefix(`${e}|reads|${t}|`)||jn.findByPrefix(`${e}|annotations|${t}|`)||jn.findByPrefix(`${e}|genome_annotations|${t}|`)||jn.findByPrefix(`${e}|variants|${t}|`)||null}function Jl(e,t,n){const[r,o]=C.useState(null),[l,i]=C.useState(!1),[s,u]=C.useState(null),c=C.useRef(null),h=C.useRef(null),d=C.useRef(null),g=C.useRef(null),T=C.useRef(!1);C.useEffect(()=>{if(!e||!t||!n)return;const{chrom:y,start:x,end:f}=t,p=f-x,m=e.track_type;h.current&&h.current.trackId!==e.id&&(h.current=null,T.current=!1);const w=h.current;if(w&&w.trackId===e.id&&w.chrom===y&&x>=w.start&&f<=w.end){const E=p/(w.viewLen||p);if(E>.8&&E<1.2){g.current&&clearTimeout(g.current);return}g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{v(e,y,x,f,p,m,n)},q0);return}return g.current&&clearTimeout(g.current),d.current&&clearTimeout(d.current),T.current&&(w==null?void 0:w.chrom)===y?d.current=setTimeout(()=>{v(e,y,x,f,p,m,n)},K0):v(e,y,x,f,p,m,n),()=>{d.current&&clearTimeout(d.current),g.current&&clearTimeout(g.current)}},[e==null?void 0:e.id,t==null?void 0:t.chrom,t==null?void 0:t.start,t==null?void 0:t.end,n]);function v(y,x,f,p,m,w,S){const b=w!=="reads"||m>Pi?X0:0,P=Math.max(0,Math.floor(f-m*b)),N=Math.ceil(p+m*b),$=(N-P)/m,_=Math.min(Math.floor(S*$),Math.max(S*2,1e3)),H=`${y.id}|${w}|${x}|${P}|${N}|${_}`,j=jn.get(H);if(j){o(j),vc(y.id,j),u(null),h.current={trackId:y.id,chrom:x,start:P,end:N,viewLen:m},T.current=!0;return}c.current&&c.current.abort();const U=new AbortController;c.current=U,T.current||i(!0),u(null);let O;if(w==="reads")m<=Pi?O=$t.reads(y.id,x,f,p):O=$t.coverage(y.id,x,P,N,_);else if(w==="coverage")O=$t.coverage(y.id,x,P,N,_);else if(w==="variants")O=$t.variants(y.id,x,P,N);else if(w==="annotations"||w==="genome_annotations")O=$t.features(y.id,x,P,N);else{i(!1);return}O.then(G=>{if(U.signal.aborted)return;const F={...G.data,mode:w==="reads"&&m<=Pi?"reads":"coverage"};jn.set(H,F),h.current={trackId:y.id,chrom:x,start:P,end:N,viewLen:m},T.current=!0,o(F),vc(y.id,F),u(null)}).catch(G=>{var F,B;if(G.name!=="CanceledError"&&!U.signal.aborted){const M=(B=(F=G.response)==null?void 0:F.data)==null?void 0:B.detail,I=typeof M=="string"?M:G.message||String(G);u(I)}}).finally(()=>{U.signal.aborted||i(!1)})}return{data:r,loading:l,error:s}}const ey=["svg","png","jpg"],ty=140;function ny({onClose:e}){const{region:t}=it(),{tracks:n}=Kt(),{theme:r}=Ye(),o=t==null?void 0:t.chrom,l=n.filter(S=>S.visible&&(!S.targetChromosomes||!o||S.targetChromosomes.includes(o))),[i,s]=C.useState("svg"),[u,c]=C.useState(!0),[h,d]=C.useState(!0),[g,T]=C.useState(new Set(l.map(S=>S.id))),[v,y]=C.useState(1200),[x,f]=C.useState(!1);function p(S){T(E=>{const b=new Set(E);return b.has(S)?b.delete(S):b.add(S),b})}async function m(){if(t){f(!0);try{const S=l.filter($=>g.has($.id)),E=h?ty:0,b=v-E,P=u?30:0,N=P+S.reduce(($,_)=>$+_.height,0);if(i==="svg"){const $=ry(t,S,r,b,E,P,N,u,h);uy($,"genomics-export.svg","image/svg+xml")}else{const $=ay(t,S,r,b,E,P,N,v,u,h),_=i==="png"?"image/png":"image/jpeg";$.toBlob(H=>{const j=URL.createObjectURL(H),U=document.createElement("a");U.href=j,U.download=`genomics-export.${i}`,U.click(),URL.revokeObjectURL(j)},_,.95)}}finally{f(!1)}}}const w=py(r);return a.jsx("div",{style:w.overlay,onClick:S=>{S.target===S.currentTarget&&e()},children:a.jsxs("div",{style:w.panel,children:[a.jsxs("div",{style:w.header,children:[a.jsx("span",{style:w.title,children:"Export Image"}),a.jsx("button",{style:w.closeBtn,onClick:e,children:"✕"})]}),a.jsxs("div",{style:w.body,children:[a.jsxs("div",{style:w.row,children:[a.jsx("span",{style:w.label,children:"Format"}),a.jsx("div",{style:{display:"flex",gap:6},children:ey.map(S=>a.jsx("button",{onClick:()=>s(S),style:{...w.fmtBtn,border:i===S?`2px solid ${r.textPrimary}`:`1px solid ${r.borderAccent}`},children:S.toUpperCase()},S))})]}),a.jsxs("div",{style:w.row,children:[a.jsx("span",{style:w.label,children:"Width (px)"}),a.jsx("input",{type:"number",min:400,max:4e3,step:100,value:v,onChange:S=>y(Math.max(400,parseInt(S.target.value)||1200)),style:w.input})]}),a.jsxs("div",{style:w.row,children:[a.jsxs("label",{style:w.cb,children:[a.jsx("input",{type:"checkbox",checked:u,onChange:S=>c(S.target.checked)})," Ruler"]}),a.jsxs("label",{style:w.cb,children:[a.jsx("input",{type:"checkbox",checked:h,onChange:S=>d(S.target.checked)})," Track labels"]})]}),a.jsxs("div",{style:{...w.row,flexDirection:"column",alignItems:"stretch",gap:4},children:[a.jsx("span",{style:w.label,children:"Include tracks"}),l.map(S=>a.jsxs("label",{style:{...w.cb,gap:6},children:[a.jsx("input",{type:"checkbox",checked:g.has(S.id),onChange:()=>p(S.id)}),a.jsx("span",{style:{width:8,height:8,borderRadius:2,background:S.color,flexShrink:0}}),a.jsx("span",{style:{fontSize:11},children:S.name})]},S.id))]}),i==="svg"&&a.jsx("div",{style:{padding:"4px 0",fontSize:10,color:r.textTertiary},children:"SVG output is fully vectorized — editable in Illustrator, Inkscape, etc."})]}),a.jsxs("div",{style:w.footer,children:[a.jsx("button",{style:w.btn,onClick:m,disabled:x||!t,children:x?"Exporting…":`Export ${i.toUpperCase()}`}),a.jsx("button",{style:{...w.btn,background:r.borderAccent},onClick:e,children:"Cancel"})]})]})})}function ry(e,t,n,r,o,l,i,s,u){const c=r+o;let h=`<?xml version="1.0" encoding="UTF-8"?>
|
|
45
|
+
`+l):r.stack=l}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Un(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:l}=n;r!==void 0&&ol.assertOptions(r,{silentJSONParsing:gt.transitional(gt.boolean),forcedJSONParsing:gt.transitional(gt.boolean),clarifyTimeoutError:gt.transitional(gt.boolean),legacyInterceptorReqResOrdering:gt.transitional(gt.boolean)},!1),o!=null&&(L.isFunction(o)?n.paramsSerializer={serialize:o}:ol.assertOptions(o,{encode:gt.function,serialize:gt.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),ol.assertOptions(n,{baseUrl:gt.spelling("baseURL"),withXsrfToken:gt.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=l&&L.merge(l.common,l[n.method]);l&&L.forEach(["delete","get","head","post","put","patch","common"],v=>{delete l[v]}),n.headers=lt.concat(i,l);const s=[];let u=!0;this.interceptors.request.forEach(function(y){if(typeof y.runWhen=="function"&&y.runWhen(n)===!1)return;u=u&&y.synchronous;const x=n.transitional||Ba;x&&x.legacyInterceptorReqResOrdering?s.unshift(y.fulfilled,y.rejected):s.push(y.fulfilled,y.rejected)});const c=[];this.interceptors.response.forEach(function(y){c.push(y.fulfilled,y.rejected)});let h,d=0,g;if(!u){const v=[fc.bind(this),void 0];for(v.unshift(...s),v.push(...c),g=v.length,h=Promise.resolve(n);d<g;)h=h.then(v[d++],v[d++]);return h}g=s.length;let T=n;for(;d<g;){const v=s[d++],y=s[d++];try{T=v(T)}catch(x){y.call(this,x);break}}try{h=fc.call(this,T)}catch(v){return Promise.reject(v)}for(d=0,g=c.length;d<g;)h=h.then(c[d++],c[d++]);return h}getUri(t){t=Un(this.defaults,t);const n=ap(t.baseURL,t.url,t.allowAbsoluteUrls);return op(n,t.params,t.paramsSerializer)}};L.forEach(["delete","get","head","options"],function(t){zn.prototype[t]=function(n,r){return this.request(Un(r||{},{method:t,url:n,data:(r||{}).data}))}});L.forEach(["post","put","patch"],function(t){function n(r){return function(l,i,s){return this.request(Un(s||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:l,data:i}))}}zn.prototype[t]=n(),zn.prototype[t+"Form"]=n(!0)});let j0=class pp{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(l){n=l});const r=this;this.promise.then(o=>{if(!r._listeners)return;let l=r._listeners.length;for(;l-- >0;)r._listeners[l](o);r._listeners=null}),this.promise.then=o=>{let l;const i=new Promise(s=>{r.subscribe(s),l=s}).then(o);return i.cancel=function(){r.unsubscribe(l)},i},t(function(l,i,s){r.reason||(r.reason=new ko(l,i,s),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new pp(function(o){t=o}),cancel:t}}};function P0(e){return function(n){return e.apply(null,n)}}function _0(e){return L.isObject(e)&&e.isAxiosError===!0}const Bs={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511,WebServerIsDown:521,ConnectionTimedOut:522,OriginIsUnreachable:523,TimeoutOccurred:524,SslHandshakeFailed:525,InvalidSslCertificate:526};Object.entries(Bs).forEach(([e,t])=>{Bs[t]=e});function hp(e){const t=new zn(e),n=Yf(zn.prototype.request,t);return L.extend(n,zn.prototype,t,{allOwnKeys:!0}),L.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return hp(Un(e,o))},n}const Pe=hp(bo);Pe.Axios=zn;Pe.CanceledError=ko;Pe.CancelToken=j0;Pe.isCancel=ip;Pe.VERSION=fp;Pe.toFormData=Kl;Pe.AxiosError=ne;Pe.Cancel=Pe.CanceledError;Pe.all=function(t){return Promise.all(t)};Pe.spread=P0;Pe.isAxiosError=_0;Pe.mergeConfig=Un;Pe.AxiosHeaders=lt;Pe.formToJSON=e=>lp(L.isHTMLForm(e)?new FormData(e):e);Pe.getAdapter=dp.getAdapter;Pe.HttpStatusCode=Bs;Pe.default=Pe;const{Axios:tx,AxiosError:nx,CanceledError:rx,isCancel:ox,CancelToken:lx,VERSION:ix,all:sx,Cancel:ax,isAxiosError:ux,spread:cx,toFormData:dx,AxiosHeaders:fx,HttpStatusCode:px,formToJSON:hx,getAdapter:mx,mergeConfig:gx}=Pe,tn=Pe.create({baseURL:"/api"});function Qr(e,t,n){return new Promise((r,o)=>{const l=new XMLHttpRequest;l.open("POST",`/api${e}`),n&&l.upload.addEventListener("progress",i=>{i.lengthComputable&&n({loaded:i.loaded,total:i.total,percent:Math.round(i.loaded/i.total*100)})}),l.addEventListener("load",()=>{if(l.status>=200&&l.status<300)try{r({data:JSON.parse(l.responseText)})}catch{r({data:{}})}else{const i=new Error("Upload failed");try{i.response={status:l.status,data:JSON.parse(l.responseText)}}catch{i.response={status:l.status,data:{detail:l.statusText}}}o(i)}}),l.addEventListener("error",()=>{const i=new Error("Network error");i.response={status:0,data:{detail:"Network error — is the server running?"}},o(i)}),l.addEventListener("abort",()=>{const i=new Error("Upload aborted");i.name="CanceledError",o(i)}),l.send(t)})}const mn={load:(e,t)=>{const n=new FormData;return n.append("file",e),Qr("/genome/load",n,t)},loadPath:e=>{const t=new FormData;return t.append("path",e),Qr("/genome/load-path",t)},addChromosomes:(e,t)=>{const n=new FormData;return n.append("file",e),Qr("/genome/add-chromosomes",n,t)},chromosomes:()=>tn.get("/genome/chromosomes"),sequence:(e,t,n)=>tn.get("/genome/sequence",{params:{chrom:e,start:t,end:n}})},$t={load:(e,t,n,r)=>{const o=new FormData;return o.append("file",e),t&&o.append("name",t),n&&o.append("index",n),Qr("/tracks/load",o,r)},loadPath:(e,t)=>{const n=new FormData;return n.append("path",e),t&&n.append("name",t),Qr("/tracks/load-path",n)},list:()=>tn.get("/tracks"),remove:e=>tn.delete(`/tracks/${e}`),coverage:(e,t,n,r,o=1e3)=>tn.get(`/tracks/${e}/coverage`,{params:{chrom:t,start:n,end:r,bins:o}}),reads:(e,t,n,r)=>tn.get(`/tracks/${e}/reads`,{params:{chrom:t,start:n,end:r}}),variants:(e,t,n,r)=>tn.get(`/tracks/${e}/variants`,{params:{chrom:t,start:n,end:r}}),features:(e,t,n,r)=>tn.get(`/tracks/${e}/features`,{params:{chrom:t,start:n,end:r}})},mp=C.createContext(null),hc=["#78909c","#81c784","#ffb74d","#f06292","#ce93d8","#80cbc4","#fff176","#ff8a65"],gp={cds:"#66bb6a",exon:"#42a5f5",gene:"#7e57c2",transcript:"#ab47bc",utr:"#26c6da",rrna:"#ffa726",trna:"#ef5350",repeat:"#8d6e63",default:"#80cbc4"};function Nt(e){return e&&e.replace(/\\u([0-9a-fA-F]{4})/g,(t,n)=>String.fromCharCode(parseInt(n,16)))}function L0({children:e}){const[t,n]=C.useState([]),[r,o]=C.useState(null),l=C.useRef(t);l.current=t;const i=C.useCallback(async(x,f,p,m)=>{var w,S;try{const b=(await $t.load(x,f,p,m)).data;return b.name&&(b.name=Nt(b.name)),o(null),b}catch(E){const b=((S=(w=E.response)==null?void 0:w.data)==null?void 0:S.detail)||E.message||String(E);throw o(typeof b=="string"?b:JSON.stringify(b)),E}},[]),s=C.useCallback(x=>{n(f=>{const p=hc[f.length%hc.length],m=x.track_type==="annotations"||x.track_type==="genome_annotations";return[...f,{...x,color:p,height:M0(x.track_type),visible:!0,useArrows:!0,scaleMax:null,scaleMin:null,logScale:!1,barAutoWidth:!0,barWidth:2,showOutline:!1,outlineColor:null,outlineSmooth:0,showBars:!0,showNucleotides:!0,fwdColor:null,revColor:null,arrowStyle:"pointed",arrowSize:4,targetChromosomes:x.target_chromosomes||null,...m?{annotationColors:null}:{}}]})},[]),u=C.useCallback(async x=>{try{await $t.remove(x)}catch{}},[]),c=C.useCallback(async(x,f)=>{const p=await i(x,f);return s(p),p},[i,s]),h=C.useCallback(async x=>{var p,m;const f=l.current.find(w=>w.id===x);if(f&&f.track_type==="genome_annotations"){n(w=>w.map(S=>S.id===x?{...S,visible:!1}:S));return}try{await $t.remove(x),n(w=>w.filter(S=>S.id!==x))}catch(w){o(((m=(p=w.response)==null?void 0:p.data)==null?void 0:m.detail)||w.message)}},[]),d=C.useCallback(()=>{n(x=>x.map(f=>f.track_type==="genome_annotations"&&!f.visible?{...f,visible:!0}:f))},[]),g=C.useCallback((x,f)=>{n(p=>p.map(m=>m.id===x?{...m,...f}:m))},[]),T=C.useCallback((x,f)=>{n(p=>p.map(m=>x.includes(m.id)?{...m,...f}:m))},[]),v=C.useCallback((x,f)=>{n(p=>{const m=[...p],w=m.findIndex(b=>b.id===x),S=m.findIndex(b=>b.id===f);if(w===-1||S===-1)return p;const[E]=m.splice(w,1);return m.splice(S,0,E),m})},[]),y=C.useCallback(x=>{n(f=>{const p=f.findIndex(m=>m.id===x.id);if(p!==-1){const m=[...f];return m[p]={...m[p],name:Nt(x.name)||x.name,visible:!0,...x.targetChromosomes?{targetChromosomes:x.targetChromosomes}:{}},m}return[...f,{...x,name:Nt(x.name)||x.name,color:"#a5d6a7",height:80,visible:!0,useArrows:!0,annotationColors:null,targetChromosomes:x.targetChromosomes||null}]})},[]);return a.jsx(mp.Provider,{value:{tracks:t,setTracks:n,addTrack:c,uploadTrack:i,commitTrack:s,discardTrack:u,removeTrack:h,updateTrack:g,updateMultipleTracks:T,reorderTracks:v,addGenomeAnnotationTrack:y,restoreAnnotationTracks:d,error:r,setError:o},children:e})}function Kt(){return C.useContext(mp)}function M0(e){switch(e){case"reads":return 120;case"coverage":return 120;case"variants":return 60;case"annotations":case"genome_annotations":return 80;default:return 80}}const yp=C.createContext(null),mc={geneCds:"#66bb6a",geneExon:"#42a5f5",geneGene:"#7e57c2",geneTranscript:"#ab47bc",geneUtr:"#26c6da",geneRrna:"#ffa726",geneTrna:"#ef5350",geneRepeat:"#8d6e63",geneDefault:"#80cbc4"},yt={dark:{name:"Dark",appBg:"#1a1a1a",headerBg:"#2a2a2a",panelBg:"#252525",canvasBg:"#1a1a1a",inputBg:"#333",border:"#333",borderAccent:"#444",borderStrong:"#555",btnBg:"#555",btnText:"#fff",btnDanger:"#c62828",textPrimary:"#e0e0e0",textSecondary:"#999",textTertiary:"#777",textMuted:"#666",trackName:"#ccc",rulerTick:"#888",rulerLabel:"#ccc",tooltipBg:"#333",tooltipBorder:"#555",overlayBg:"rgba(0,0,0,0.55)",selectedRow:"#333",centerLine:"#555",...mc},light:{name:"Light",appBg:"#f5f5f5",headerBg:"#ffffff",panelBg:"#eee",canvasBg:"#ffffff",inputBg:"#fff",border:"#ddd",borderAccent:"#bbb",borderStrong:"#999",btnBg:"#e0e0e0",btnText:"#333",btnDanger:"#d32f2f",textPrimary:"#222",textSecondary:"#666",textTertiary:"#888",textMuted:"#aaa",trackName:"#333",rulerTick:"#666",rulerLabel:"#333",tooltipBg:"#fff",tooltipBorder:"#ccc",overlayBg:"rgba(0,0,0,0.25)",selectedRow:"#dde4ee",centerLine:"#ccc",...mc},colorblind:{name:"Colorblind Friendly",appBg:"#1a1a1a",headerBg:"#2a2a2a",panelBg:"#252525",canvasBg:"#1a1a1a",inputBg:"#333",border:"#333",borderAccent:"#444",borderStrong:"#555",btnBg:"#555",btnText:"#fff",btnDanger:"#cc4125",textPrimary:"#e0e0e0",textSecondary:"#999",textTertiary:"#777",textMuted:"#666",trackName:"#ccc",rulerTick:"#888",rulerLabel:"#ccc",tooltipBg:"#333",tooltipBorder:"#555",overlayBg:"rgba(0,0,0,0.55)",selectedRow:"#333",centerLine:"#555",geneCds:"#009e73",geneExon:"#0072b2",geneGene:"#cc79a7",geneTranscript:"#d55e00",geneUtr:"#56b4e9",geneRrna:"#e69f00",geneTrna:"#f0e442",geneRepeat:"#999999",geneDefault:"#56b4e9"},soft:{name:"Soft",appBg:"#f0ede8",headerBg:"#e4dfd8",panelBg:"#e9e5de",canvasBg:"#f5f2ed",inputBg:"#fff",border:"#d5cfc6",borderAccent:"#c4bdb2",borderStrong:"#a89f93",btnBg:"#d5cfc6",btnText:"#4a4540",btnDanger:"#c47066",textPrimary:"#3a3530",textSecondary:"#7a7468",textTertiary:"#9a9488",textMuted:"#b5ada2",trackName:"#4a4540",rulerTick:"#a89f93",rulerLabel:"#5a5550",tooltipBg:"#fff",tooltipBorder:"#d5cfc6",overlayBg:"rgba(0,0,0,0.2)",selectedRow:"#ddd8d0",centerLine:"#c4bdb2",geneCds:"#4caf50",geneExon:"#2e8bc0",geneGene:"#8e44ad",geneTranscript:"#c0392b",geneUtr:"#1abc9c",geneRrna:"#e67e22",geneTrna:"#e74c3c",geneRepeat:"#8d6e63",geneDefault:"#27ae60"},highContrast:{name:"High Contrast",appBg:"#000",headerBg:"#111",panelBg:"#111",canvasBg:"#000",inputBg:"#222",border:"#444",borderAccent:"#666",borderStrong:"#888",btnBg:"#444",btnText:"#fff",btnDanger:"#f44336",textPrimary:"#fff",textSecondary:"#ccc",textTertiary:"#aaa",textMuted:"#888",trackName:"#fff",rulerTick:"#aaa",rulerLabel:"#fff",tooltipBg:"#222",tooltipBorder:"#666",overlayBg:"rgba(0,0,0,0.7)",selectedRow:"#333",centerLine:"#555",geneCds:"#4caf50",geneExon:"#2196f3",geneGene:"#9c27b0",geneTranscript:"#e040fb",geneUtr:"#00e5ff",geneRrna:"#ff9800",geneTrna:"#ff1744",geneRepeat:"#ff6e40",geneDefault:"#69f0ae"}},xp="genomics-viewer-theme",vp="genomics-viewer-custom-theme";function B0(){try{const e=localStorage.getItem(xp),t=localStorage.getItem(vp);return{name:e&&(yt[e]||e==="custom")?e:"dark",custom:t?JSON.parse(t):null}}catch{return{name:"dark",custom:null}}}function A0({children:e}){const t=B0(),[n,r]=C.useState(t.name),[o,l]=C.useState(t.custom||{...yt.dark,name:"Custom"}),i=n==="custom"?o:yt[n]||yt.dark,s=C.useCallback(c=>{r(c),localStorage.setItem(xp,c)},[]),u=C.useCallback(c=>{l(c),localStorage.setItem(vp,JSON.stringify(c))},[]);return C.useEffect(()=>{document.body.style.background=i.appBg,document.body.style.color=i.textPrimary},[i.appBg,i.textPrimary]),a.jsx(yp.Provider,{value:{theme:i,themeName:n,setThemeName:s,customTheme:o,setCustomTheme:u},children:e})}function Ye(){return C.useContext(yp)}function z0(e){const t=e==null?void 0:e.compatibility;return t&&t.status!=="ok"&&t.status!=="no_genome"}function gc(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}const As=new Set([".gb",".gbk",".genbank",".fasta",".fa"]),zs=new Set([".bam",".bw",".bigwig",".wig",".bedgraph",".bdg",".vcf",".bed",".gtf",".gff",".gff2",".gff3"]),yc=50*1024*1024;function _l(e){if(!e)return"";const t=e.toLowerCase();if(t.endsWith(".vcf.gz"))return".vcf.gz";if(t.endsWith(".bam.bai"))return".bam.bai";const n=t.lastIndexOf(".");return n>=0?t.slice(n):""}function $0(e){const t=_l(e);return t===".bai"||t===".bam.bai"}function N0(e){const t=[],n=[],r=[],o=[],l=[],i=[];for(const c of e){const h=_l(c.name);As.has(h)?t.push(c):h===".bam"?n.push(c):$0(c.name)?r.push(c):zs.has(h)||h===".vcf.gz"?c.size>yc?i.push(c):o.push(c):l.push(c)}const s=[],u=[];for(const c of n){const h=c.name.replace(/\.bam$/i,""),d=r.find(g=>{const T=g.name.toLowerCase();return T===c.name.toLowerCase()+".bai"||T===h.toLowerCase()+".bai"});if(d){c.size>yc?i.push(c):s.push({file:c,indexFile:d});const g=r.indexOf(d);g!==-1&&r.splice(g,1)}else u.push(c)}for(const c of o)s.push({file:c,indexFile:null});for(const c of r)c._indexOrphan=!0;return l.push(...r),{genomeFiles:t,trackEntries:s,unpairedBams:u,largeFiles:i,unknownFiles:l}}function O0(){const{theme:e}=Ye(),{genome:t,setGenome:n,navigateTo:r}=it(),{addTrack:o,uploadTrack:l,commitTrack:i,discardTrack:s,addGenomeAnnotationTrack:u,error:c,setError:h}=Kt(),[d,g]=C.useState(!1),[T,v]=C.useState(null),[y,x]=C.useState(null),[f,p]=C.useState(null),[m,w]=C.useState(null),[S,E]=C.useState(null),[b,P]=C.useState(null),[N,$]=C.useState(""),[_,H]=C.useState(!1),j=C.useRef(null),U=C.useRef(null),O=C.useRef(null),G=[...Array.from(As),...Array.from(zs),".vcf.gz",".bai"].join(","),F={panel:{background:e.panelBg,borderBottom:`1px solid ${e.border}`,padding:"8px 12px",display:"flex",alignItems:"center",gap:12,flexWrap:"wrap",position:"relative"},group:{display:"flex",alignItems:"center",gap:6},label:{fontSize:11,color:e.textSecondary,textTransform:"uppercase",letterSpacing:1,whiteSpace:"nowrap"},fileInput:{background:e.inputBg,border:`1px solid ${e.borderAccent}`,borderRadius:4,color:e.textPrimary,padding:"4px 6px",fontSize:12,width:280,cursor:"pointer"},promptOverlay:{position:"fixed",inset:0,zIndex:9999,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},promptBox:{background:e.panelBg,border:`1px solid ${e.borderAccent}`,borderRadius:8,padding:"20px 24px",boxShadow:"0 8px 32px rgba(0,0,0,0.5)",maxWidth:440,width:"90%"},promptTitle:{fontSize:14,fontWeight:700,color:e.textPrimary,marginBottom:8},promptText:{fontSize:12,color:e.textSecondary,lineHeight:1.6,marginBottom:16},promptFile:{fontWeight:600,color:e.textPrimary},promptBtns:{display:"flex",gap:8,justifyContent:"flex-end",flexWrap:"wrap"},promptBtn:{background:e.btnBg,border:`1px solid ${e.borderStrong}`,borderRadius:4,color:e.btnText,padding:"5px 16px",cursor:"pointer",fontSize:12,fontWeight:600},promptBtnPrimary:{background:"#1976d2",border:"none",borderRadius:4,color:"#fff",padding:"5px 16px",cursor:"pointer",fontSize:12,fontWeight:600}};async function B(V){var J,ee,z;g(!0),v(null),p(null),x(`Uploading genome: ${V.name}...`);try{const q=await mn.load(V,Z=>{p({...Z,label:V.name}),Z.percent>=100&&x(`Processing genome: ${V.name}...`)});p(null);const Q=q.data;if(Q.name&&(Q.name=Nt(Q.name)),n(Q),((J=Q.chromosomes)==null?void 0:J.length)>0){const Z=Q.chromosomes[0];r(Z.name,0,Math.min(Z.length,5e4))}Q.is_annotated&&u({id:"genome_annotations",name:`${Q.name} (annotations)`,track_type:"genome_annotations",file_format:"genbank",targetChromosomes:Q.annotated_chromosomes||null}),x(`Genome loaded: ${Q.name}`),setTimeout(()=>x(null),3e3)}catch(q){v(((z=(ee=q.response)==null?void 0:ee.data)==null?void 0:z.detail)||q.message),x(null),p(null)}finally{g(!1)}}async function M(V){var ee,z;g(!0),v(null),p(null);const J=[];for(const q of V){x(`Adding chromosomes from ${q.name}...`);try{const Z=(await mn.addChromosomes(q,le=>{p({...le,label:q.name})})).data;Z.name&&(Z.name=Nt(Z.name)),n(Z),Z.is_annotated&&u({id:"genome_annotations",name:`${Z.name} (annotations)`,track_type:"genome_annotations",file_format:"genbank",targetChromosomes:Z.annotated_chromosomes||null})}catch(Q){J.push(`${q.name}: ${((z=(ee=Q.response)==null?void 0:ee.data)==null?void 0:z.detail)||Q.message}`)}}g(!1),J.length?(v(J.join("; ")),x(null)):(x(`Added chromosomes from ${V.length} file${V.length>1?"s":""}.`),setTimeout(()=>x(null),3e3))}async function I(V){var Q,Z;if(!V.length)return;g(!0),v(null),h(null),p(null);const J=[],ee=[],z=[],q=[];for(let le=0;le<V.length;le++){const{file:oe,indexFile:de}=V[le];x(`Loading track ${le+1}/${V.length}: ${oe.name}...`);try{const xe=await l(oe,void 0,de,Oe=>{p({...Oe,label:oe.name}),Oe.percent>=100&&x(`Processing: ${oe.name}...`)});z0(xe)?ee.push(xe):(i(xe),J.push(xe)),xe.hint&&q.push(xe.hint)}catch(xe){z.push(`${oe.name}: ${((Z=(Q=xe.response)==null?void 0:Q.data)==null?void 0:Z.detail)||xe.message}`)}}if(g(!1),p(null),z.length)v(z.join("; ")),x(null);else if(J.length>0&&ee.length===0){const le=`Added ${J.length} track${J.length>1?"s":""}.`;q.length?(x(le),setTimeout(()=>{x(q.join(" ")),setTimeout(()=>x(null),8e3)},2e3)):(x(le),setTimeout(()=>x(null),3e3))}else ee.length===0&&x(null);ee.length>0&&E({tracks:ee})}async function A(V){const J=Array.from(V);if(!J.length)return;const{genomeFiles:ee,trackEntries:z,unpairedBams:q,largeFiles:Q,unknownFiles:Z}=N0(J);if(Z.length){const le=Z.filter(de=>de._indexOrphan),oe=Z.filter(de=>!de._indexOrphan);le.length&&P({bamFile:null,indexFile:le[0],bamPath:"",indexPath:"",error:null}),oe.length&&v(`Unsupported: ${oe.map(de=>de.name).join(", ")}`)}if(Q.length>0){const le=Q[0],oe=(le.size/(1024*1024)).toFixed(0),de=le.name.toLowerCase().endsWith(".bam");P({bamFile:de?le:null,indexFile:null,bamPath:"",indexPath:"",error:null,_largeFile:le,_largeWarning:`${le.name} is ${oe} MB. Large files load much faster via file path — the server reads directly from disk without uploading.`}),Q.length>1&&v(`${Q.length-1} additional large file(s) skipped — load one at a time via path.`)}if(q.length>0&&Q.length===0&&P({bamFile:q[0],indexFile:null,bamPath:"",indexPath:"",error:null}),ee.length>0&&!t){if(await B(ee[0]),ee.length>1){z.length>0&&await I(z),w({files:ee.slice(1)}),j.current&&(j.current.value="");return}z.length>0&&await I(z)}else ee.length>0&&t?(z.length>0&&await I(z),w({files:ee})):z.length>0&&(t?await I(z):v("Load a genome file first (.fasta, .gb, .genbank)"));j.current&&(j.current.value="")}async function R(V){var Q,Z,le,oe,de;const J=V.trim();if(!J)return;v(null);const ee=J.toLowerCase(),z=As.has(_l(J)),q=zs.has(_l(J))||ee.endsWith(".vcf.gz")||ee.endsWith(".bai");if(z&&!t){g(!0),x("Loading genome from path...");try{const Oe=(await mn.loadPath(J)).data;if(Oe.name&&(Oe.name=Nt(Oe.name)),n(Oe),((Q=Oe.chromosomes)==null?void 0:Q.length)>0){const st=Oe.chromosomes[0];r(st.name,0,Math.min(st.length,5e4))}Oe.is_annotated&&u({id:"genome_annotations",name:`${Oe.name} (annotations)`,track_type:"genome_annotations",file_format:"genbank",targetChromosomes:Oe.annotated_chromosomes||null}),x(`Genome loaded: ${Oe.name}`),setTimeout(()=>x(null),3e3)}catch(xe){v(((le=(Z=xe.response)==null?void 0:Z.data)==null?void 0:le.detail)||xe.message),x(null)}finally{g(!1)}}else if(q||z){if(!t){v("Load a genome file first");return}g(!0),x("Loading track from path...");try{const xe=J.split(/[/\\]/).pop()||J,st=(await $t.loadPath(J,xe)).data;st.name&&(st.name=Nt(st.name)),i(st),x(`Track loaded: ${st.name}`),st.hint?setTimeout(()=>{x(st.hint),setTimeout(()=>x(null),8e3)},2e3):setTimeout(()=>x(null),3e3)}catch(xe){v(((de=(oe=xe.response)==null?void 0:oe.data)==null?void 0:de.detail)||xe.message),x(null)}finally{g(!1)}}else v(`Unsupported file type: ${J.split(/[/\\]/).pop()}`);$("")}function k(V){V.preventDefault(),R(N)}function D(V){const J=V.target.files;J!=null&&J.length&&(v(null),A(J))}async function Y(){if(!m)return;const{files:V}=m;w(null),await M(V)}async function K(){if(!m)return;const{files:V}=m;w(null),await I(V.map(J=>({file:J,indexFile:null})))}function re(){w(null)}function ue(){var V;(V=U.current)==null||V.click()}function pe(){var V;(V=O.current)==null||V.click()}function fe(V){var ee;const J=(ee=V.target.files)==null?void 0:ee[0];if(V.target.value="",!!J){if(!J.name.toLowerCase().endsWith(".bam")){P(z=>({...z,error:"Please select a .bam file"}));return}P(z=>({...z,bamFile:J,bamPath:"",error:null}))}}function ae(V){var ee;const J=(ee=V.target.files)==null?void 0:ee[0];if(V.target.value="",!!J){if(!J.name.toLowerCase().endsWith(".bai")){P(z=>({...z,error:"Please select a .bai index file"}));return}P(z=>({...z,indexFile:J,indexPath:"",error:null}))}}function ie(V){return V&&(V.bamFile||V.bamPath.trim())}function te(V){return V&&(V.indexFile||V.indexPath.trim())}function ge(V){return ie(V)&&te(V)}async function _e(){if(!b)return;const{bamFile:V,indexFile:J,bamPath:ee,indexPath:z,_largeFile:q}=b,Q=ee.trim(),Z=z.trim();if(q&&!q.name.toLowerCase().endsWith(".bam")){if(!Q){P(oe=>({...oe,error:"File path is required"}));return}P(null),await R(Q);return}if(!V&&!Q){P(oe=>({...oe,error:"BAM file or path is required"}));return}if(!J&&!Z){P(oe=>({...oe,error:"BAM index (.bai) file or path is required"}));return}if(Q&&!Q.toLowerCase().endsWith(".bam")){P(oe=>({...oe,error:"BAM path must end with .bam"}));return}if(Z&&!Z.toLowerCase().endsWith(".bai")){P(oe=>({...oe,error:"Index path must end with .bai"}));return}if(P(null),!V&&Q){await R(Q);return}await I([{file:V,indexFile:J}])}function ye(){P(null)}async function Ne(){if(S){for(const V of S.tracks)await s(V.id);E(null)}}function Je(){if(S){for(const V of S.tracks)i(V);E(null),x(`Added ${S.tracks.length} track${S.tracks.length>1?"s":""}.`),setTimeout(()=>x(null),3e3)}}const he=m?m.files.map(V=>V.name).join(", "):"",ht=m&&m.files.length>1;return a.jsxs("div",{style:F.panel,"data-tour":"file-loader",children:[a.jsxs("div",{style:F.group,title:"Select genome or track files",children:[a.jsx("span",{style:F.label,children:"Load Files"}),a.jsx("input",{ref:j,type:"file",multiple:!0,style:F.fileInput,disabled:d,accept:G,onChange:D})]}),a.jsxs("button",{style:{...F.group,background:"none",border:`1px solid ${e.borderAccent}`,borderRadius:4,padding:"3px 8px",cursor:"pointer",color:e.textSecondary,fontSize:11},onClick:()=>H(V=>!V),title:"Load file by local path (recommended for large BAM files)",children:[_?"✕":"📂"," Path"]}),_&&a.jsxs("form",{onSubmit:k,style:{display:"flex",gap:4},children:[a.jsx("input",{type:"text",value:N,onChange:V=>$(V.target.value),placeholder:"/path/to/file.bam",disabled:d,style:{background:e.inputBg,border:`1px solid ${e.borderAccent}`,borderRadius:4,color:e.textPrimary,padding:"4px 8px",fontSize:11,width:260,fontFamily:"monospace"}}),a.jsx("button",{type:"submit",disabled:d||!N.trim(),style:{background:e.btnBg,border:"none",borderRadius:4,color:e.btnText,padding:"4px 10px",cursor:"pointer",fontSize:11,fontWeight:600},children:"Load"})]}),d?a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0},children:[a.jsx("span",{style:{fontSize:10,color:e.textMuted,fontStyle:"italic",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:y||"Loading…"}),f&&a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flex:1,minWidth:100},children:[a.jsx("div",{style:{flex:1,height:6,background:e.inputBg,borderRadius:3,overflow:"hidden",minWidth:60},children:a.jsx("div",{style:{width:`${f.percent}%`,height:"100%",background:f.percent>=100?"#66bb6a":"#42a5f5",borderRadius:3,transition:"width 0.2s ease"}})}),a.jsx("span",{style:{fontSize:10,color:e.textTertiary,whiteSpace:"nowrap"},children:f.percent<100?`${gc(f.loaded)} / ${gc(f.total)}`:"Processing..."})]})]}):a.jsx("span",{style:{fontSize:10,color:e.textMuted,fontStyle:"italic"},children:"or drag & drop anywhere"}),!d&&y&&a.jsx("span",{style:{color:"#81c784",fontSize:11},children:y}),(T||c)&&a.jsx("span",{style:{color:"#ef9a9a",fontSize:11},children:T||c}),m&&a.jsx("div",{style:F.promptOverlay,children:a.jsxs("div",{style:F.promptBox,onClick:V=>V.stopPropagation(),children:[a.jsxs("div",{style:F.promptTitle,children:["Genome file",ht?"s":""," detected"]}),a.jsxs("div",{style:F.promptText,children:[a.jsx("span",{style:F.promptFile,children:he}),ht?" appear to be genome files. A genome is already loaded.":" appears to be a genome file. A genome is already loaded.",a.jsx("br",{}),"How would you like to handle ",ht?"them":"it","?"]}),a.jsxs("div",{style:F.promptBtns,children:[a.jsx("button",{style:F.promptBtn,onClick:re,children:"Skip"}),a.jsxs("button",{style:F.promptBtn,onClick:K,children:["Add as Track",ht?"s":""]}),a.jsxs("button",{style:F.promptBtnPrimary,onClick:Y,children:["Add as Chromosome",ht?"s":""]})]})]})}),S&&a.jsx("div",{style:F.promptOverlay,children:a.jsxs("div",{style:F.promptBox,onClick:V=>V.stopPropagation(),children:[a.jsx("div",{style:F.promptTitle,children:"Track compatibility warning"}),a.jsxs("div",{style:F.promptText,children:[S.tracks.map(V=>{var J;return a.jsxs("div",{style:{marginBottom:6},children:[a.jsx("span",{style:F.promptFile,children:V.name})," — ",((J=V.compatibility)==null?void 0:J.message)||"Possible mismatch with loaded genome"]},V.id)}),a.jsx("div",{style:{marginTop:8},children:S.tracks.length>1?"These tracks may not match the loaded genome.":"This track may not match the loaded genome."})]}),a.jsxs("div",{style:F.promptBtns,children:[a.jsx("button",{style:F.promptBtn,onClick:Ne,children:"Skip"}),a.jsx("button",{style:F.promptBtnPrimary,onClick:Je,children:"Load Anyway"})]})]})}),b&&(()=>{const V=b._largeFile&&!b._largeFile.name.toLowerCase().endsWith(".bam"),J=V?!!b.bamPath.trim():ge(b),ee=b.bamFile?b.bamFile.size/(1024*1024):0,z=b.bamFile&&ee>50,q=ie(b),Q=te(b),Z={flex:1,padding:"5px 8px",borderRadius:4,fontSize:11,background:e.inputBg,color:e.textPrimary,fontFamily:"monospace"},le=V?`Load ${b._largeFile.name.split(".").pop().toUpperCase()} Track`:"Load BAM Track",oe=V?"Paste the local file path for the server to read directly from disk.":"BAM files require a matching .bai index. Browse for files or paste local paths.";return a.jsx("div",{style:F.promptOverlay,onClick:ye,children:a.jsxs("div",{style:{...F.promptBox,maxWidth:500},onClick:de=>de.stopPropagation(),children:[a.jsx("div",{style:F.promptTitle,children:le}),a.jsx("div",{style:{...F.promptText,marginBottom:12},children:oe}),a.jsxs("div",{style:{marginBottom:10},children:[a.jsxs("div",{style:{fontSize:11,color:e.textSecondary,marginBottom:4,fontWeight:600},children:[V?"File path":".bam file"," ",q&&a.jsx("span",{style:{color:"#66bb6a"},children:"✓"})]}),a.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[a.jsx("input",{type:"text",value:b.bamFile?b.bamFile.name:b.bamPath,onChange:de=>P(xe=>({...xe,bamPath:de.target.value,bamFile:null,error:null})),placeholder:V?"/path/to/file":"/path/to/reads.bam",style:{...Z,border:`1px solid ${q?"#66bb6a":e.borderAccent}`}}),!V&&a.jsx("button",{style:{...F.promptBtn,padding:"4px 12px",whiteSpace:"nowrap"},onClick:ue,children:"Browse"})]})]}),!V&&a.jsxs("div",{style:{marginBottom:12},children:[a.jsxs("div",{style:{fontSize:11,color:e.textSecondary,marginBottom:4,fontWeight:600},children:[".bai index ",Q&&a.jsx("span",{style:{color:"#66bb6a"},children:"✓"})]}),a.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[a.jsx("input",{type:"text",value:b.indexFile?b.indexFile.name:b.indexPath,onChange:de=>P(xe=>({...xe,indexPath:de.target.value,indexFile:null,error:null})),placeholder:"/path/to/reads.bam.bai",style:{...Z,border:`1px solid ${Q?"#66bb6a":e.borderAccent}`}}),a.jsx("button",{style:{...F.promptBtn,padding:"4px 12px",whiteSpace:"nowrap"},onClick:pe,children:"Browse"})]})]}),a.jsx("input",{ref:U,type:"file",accept:".bam",style:{display:"none"},onChange:fe}),a.jsx("input",{ref:O,type:"file",accept:".bai,.bam.bai",style:{display:"none"},onChange:ae}),(z||b._largeWarning)&&a.jsx("div",{style:{fontSize:11,color:"#ffb74d",marginBottom:8,padding:"6px 10px",background:"rgba(255,183,77,0.1)",borderRadius:4,border:"1px solid rgba(255,183,77,0.3)"},children:b._largeWarning||a.jsxs(a.Fragment,{children:[a.jsxs("strong",{children:["Large file (",ee.toFixed(0)," MB)"]})," — uploading may be slow. Paste the file path instead for instant loading."]})}),b.error&&a.jsx("div",{style:{fontSize:11,color:"#ef9a9a",marginBottom:8,padding:"4px 0"},children:b.error}),!z&&a.jsx("div",{style:{fontSize:10,color:e.textTertiary,marginBottom:10},children:"Tip: Paste a local file path to skip uploading — the server reads directly from disk. The .bai is auto-discovered if next to the .bam."}),a.jsxs("div",{style:F.promptBtns,children:[a.jsx("button",{style:F.promptBtn,onClick:ye,children:"Cancel"}),a.jsx("button",{style:{...F.promptBtnPrimary,opacity:J?1:.4,cursor:J?"pointer":"default"},disabled:!J,onClick:_e,children:"Open"})]})]})})})()]})}const F0=320,I0=200;function wp({title:e,onClose:t,theme:n,children:r,defaultWidth:o=440,defaultHeight:l=500}){const[i,s]=C.useState(()=>({x:Math.max(20,window.innerWidth-o-40),y:80})),[u,c]=C.useState({w:o,h:Math.min(l,window.innerHeight-120)}),h=C.useRef(null),d=C.useRef(null),g=C.useRef(null),T=C.useCallback(x=>{if(x.target.closest("input, select, button, label, textarea"))return;x.preventDefault(),h.current={startX:x.clientX,startY:x.clientY,startPos:{...i}};function f(m){h.current&&s({x:Math.max(0,Math.min(window.innerWidth-100,h.current.startPos.x+m.clientX-h.current.startX)),y:Math.max(0,Math.min(window.innerHeight-40,h.current.startPos.y+m.clientY-h.current.startY))})}function p(){h.current=null,window.removeEventListener("mousemove",f),window.removeEventListener("mouseup",p)}window.addEventListener("mousemove",f),window.addEventListener("mouseup",p)},[i]),v=C.useCallback(x=>{x.preventDefault(),x.stopPropagation(),d.current={startX:x.clientX,startY:x.clientY,startSize:{...u}};function f(m){d.current&&c({w:Math.max(F0,d.current.startSize.w+m.clientX-d.current.startX),h:Math.max(I0,d.current.startSize.h+m.clientY-d.current.startY)})}function p(){d.current=null,window.removeEventListener("mousemove",f),window.removeEventListener("mouseup",p),document.body.style.cursor=""}document.body.style.cursor="nwse-resize",window.addEventListener("mousemove",f),window.addEventListener("mouseup",p)},[u]),y={panel:{position:"fixed",left:i.x,top:i.y,width:u.w,height:u.h,zIndex:1e3,background:n.panelBg,border:`1px solid ${n.borderAccent}`,borderRadius:8,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.5)",overflow:"hidden"},header:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"8px 14px",borderBottom:`1px solid ${n.border}`,cursor:"grab",userSelect:"none",flexShrink:0},title:{fontSize:13,fontWeight:700,color:n.textPrimary},closeBtn:{background:"none",border:"none",color:n.textSecondary,cursor:"pointer",fontSize:16,lineHeight:1,padding:"0 4px"},body:{flex:1,overflowY:"auto",overflowX:"hidden"},resizeHandle:{position:"absolute",right:0,bottom:0,width:14,height:14,cursor:"nwse-resize",zIndex:1}};return a.jsxs("div",{ref:g,style:y.panel,children:[a.jsxs("div",{style:y.header,onMouseDown:T,children:[a.jsx("span",{style:y.title,children:e}),a.jsx("button",{style:y.closeBtn,onClick:t,children:"✕"})]}),a.jsx("div",{style:y.body,children:r}),a.jsx("div",{style:y.resizeHandle,onMouseDown:v,title:"Drag to resize",children:a.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",style:{display:"block"},children:a.jsx("path",{d:"M12 2L2 12M12 6L6 12M12 10L10 12",stroke:n.textTertiary,strokeWidth:"1.5",fill:"none"})})})]})}const D0=["#f44336","#e53935","#ef5350","#e57373","#ff5722","#ff8a65","#ff9800","#ffa726","#ffb74d","#ffc107","#ffd54f","#fff176","#4caf50","#66bb6a","#81c784","#aed581","#009688","#26c6da","#4dd0e1","#80cbc4","#2196f3","#42a5f5","#64b5f6","#3f51b5","#7e57c2","#9575cd","#9c27b0","#ab47bc","#ce93d8","#e91e63","#f06292","#795548","#8d6e63","#607d8b","#78909c"];function U0({onClose:e}){const{theme:t}=Ye(),{tracks:n,updateTrack:r,updateMultipleTracks:o,removeTrack:l}=Kt(),[i,s]=C.useState(new Set);function u(k){s(D=>{const Y=new Set(D);return Y.has(k)?Y.delete(k):Y.add(k),Y})}function c(){s(new Set(n.map(k=>k.id)))}function h(){s(new Set)}const d=n.filter(k=>i.has(k.id)),g=d.some(k=>k.track_type==="annotations"||k.track_type==="genome_annotations"),T=d.some(k=>k.track_type==="coverage"||k.track_type==="reads"),v=d.some(k=>k.track_type==="reads"),y=d.some(k=>k.track_type==="coverage"||k.track_type==="reads"||k.track_type==="variants"),x=d.length>0&&d.every(k=>k.height===d[0].height)?d[0].height:"",f=d.length>0&&d.every(k=>k.color===d[0].color)?d[0].color:"#888888",p=d.length>0&&d.every(k=>k.visible===d[0].visible)?d[0].visible:null,m=d.length>0&&d.every(k=>k.useArrows===d[0].useArrows)?d[0].useArrows:null,w=d.length>0&&d.every(k=>k.scaleMax===d[0].scaleMax)?d[0].scaleMax:void 0,S=d.length>0&&d.every(k=>k.scaleMin===d[0].scaleMin)?d[0].scaleMin:void 0,E=w==null&&S==null,b=d.length>0&&d.every(k=>k.logScale===d[0].logScale)?d[0].logScale:null,P=d.length>0&&d.every(k=>k.barAutoWidth===d[0].barAutoWidth)?d[0].barAutoWidth:null,N=d.length>0&&d.every(k=>k.barWidth===d[0].barWidth)?d[0].barWidth:void 0,$=d.length>0&&d.every(k=>k.showOutline===d[0].showOutline)?d[0].showOutline:null,_=d.length>0&&d.every(k=>k.outlineColor===d[0].outlineColor)?d[0].outlineColor:void 0,H=d.length>0&&d.every(k=>k.outlineSmooth===d[0].outlineSmooth)?d[0].outlineSmooth:void 0,j=d.length>0&&d.every(k=>k.showBars===d[0].showBars)?d[0].showBars:null,U=d.length>0&&d.every(k=>k.showNucleotides===d[0].showNucleotides)?d[0].showNucleotides:null,O=d.length>0&&d.every(k=>(k.fwdColor||"#90a4ae")===(d[0].fwdColor||"#90a4ae"))?d[0].fwdColor||"#90a4ae":void 0,G=d.length>0&&d.every(k=>(k.revColor||"#f06292")===(d[0].revColor||"#f06292"))?d[0].revColor||"#f06292":void 0,F=d.length>0&&d.every(k=>(k.arrowStyle||"pointed")===(d[0].arrowStyle||"pointed"))?d[0].arrowStyle||"pointed":void 0,B=d.length>0&&d.every(k=>(k.arrowSize||4)===(d[0].arrowSize||4))?d[0].arrowSize||4:void 0;function M(k){o([...i],k)}function I(){for(const k of i)l(k);s(new Set)}const A=t,R={body:{padding:"8px 0",overflowY:"auto",flex:1},trackRow:{display:"flex",alignItems:"center",gap:8,padding:"5px 16px",cursor:"pointer",transition:"background 0.1s"},trackRowSelected:{background:A.selectedRow},checkbox:{width:14,height:14,cursor:"pointer",flexShrink:0},trackLabel:{fontSize:12,color:A.textPrimary,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},trackType:{fontSize:10,color:A.textTertiary,flexShrink:0},section:{padding:"12px 16px",borderTop:`1px solid ${A.border}`},sectionTitle:{fontSize:11,color:A.textSecondary,textTransform:"uppercase",letterSpacing:1,marginBottom:8},controlRow:{display:"flex",alignItems:"center",gap:10,marginBottom:6},controlLabel:{fontSize:12,color:A.textSecondary,width:90},input:{background:A.inputBg,border:`1px solid ${A.borderAccent}`,borderRadius:4,color:A.textPrimary,padding:"3px 6px",fontSize:12,width:70},colorInput:{width:28,height:22,border:"none",background:"none",cursor:"pointer",padding:0},btn:{background:A.btnBg,color:A.btnText},btnDanger:{background:A.btnDanger,border:"none",borderRadius:4,color:"#fff",padding:"5px 14px",cursor:"pointer",fontSize:12,fontWeight:600},footer:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"10px 16px",borderTop:`1px solid ${A.border}`,gap:8},smallBtn:{background:"none",border:`1px solid ${A.borderAccent}`,borderRadius:3,color:A.textSecondary,cursor:"pointer",fontSize:10,padding:"2px 8px"},cbLabel:{fontSize:12,color:A.textSecondary,cursor:"pointer",display:"flex",alignItems:"center",gap:4}};return a.jsxs(wp,{title:"Track Settings",onClose:e,theme:A,defaultWidth:460,defaultHeight:520,children:[a.jsx("div",{style:R.body,children:n.length===0?a.jsx("div",{style:{padding:16,color:A.textTertiary,fontSize:12},children:"No tracks loaded."}):n.map(k=>a.jsxs("div",{style:{...R.trackRow,...i.has(k.id)?R.trackRowSelected:{}},onClick:()=>u(k.id),children:[a.jsx("input",{type:"checkbox",checked:i.has(k.id),onChange:()=>u(k.id),onClick:D=>D.stopPropagation(),style:R.checkbox}),a.jsx("span",{style:{width:10,height:10,borderRadius:2,background:k.color,flexShrink:0}}),a.jsx("span",{style:{...R.trackLabel,opacity:k.visible?1:.4},children:k.name}),a.jsx("span",{style:R.trackType,children:k.track_type})]},k.id))}),d.length>0&&a.jsxs("div",{style:R.section,children:[a.jsxs("div",{style:R.sectionTitle,children:["Edit ",d.length," selected track",d.length>1?"s":""]}),a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Height (px)"}),a.jsx("input",{type:"range",min:30,max:500,step:1,value:x||80,onChange:k=>M({height:parseInt(k.target.value)}),style:{flex:1,cursor:"pointer",accentColor:A.textSecondary}}),a.jsx("input",{type:"text",inputMode:"numeric",value:x,placeholder:"mixed",style:{...R.input,width:48},onChange:k=>{const D=parseInt(k.target.value);D>=30&&D<=500&&M({height:D})},onBlur:k=>{const D=parseInt(k.target.value);(!D||D<30)&&M({height:30}),D>500&&M({height:500})}})]}),a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Visible"}),a.jsxs("label",{style:R.cbLabel,children:[a.jsx("input",{type:"checkbox",checked:p===!0,ref:k=>{k&&(k.indeterminate=p===null)},onChange:k=>M({visible:k.target.checked}),style:{cursor:"pointer"}}),"Show"]})]}),y&&a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Fill bars"}),a.jsxs("label",{style:R.cbLabel,children:[a.jsx("input",{type:"checkbox",checked:j!==!1,ref:k=>{k&&(k.indeterminate=j===null)},onChange:k=>M({showBars:k.target.checked}),style:{cursor:"pointer"}}),"Show"]}),j!==!1&&a.jsx("input",{type:"color",value:f,style:R.colorInput,onChange:k=>M({color:k.target.value}),title:"Bar fill color"})]}),!y&&!g&&a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Color"}),a.jsx("input",{type:"color",value:f,style:R.colorInput,onChange:k=>M({color:k.target.value})})]}),y&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Bar width"}),a.jsxs("label",{style:R.cbLabel,children:[a.jsx("input",{type:"checkbox",checked:P!==!1,ref:k=>{k&&(k.indeterminate=P===null)},onChange:k=>M({barAutoWidth:k.target.checked}),style:{cursor:"pointer"}}),"Auto"]})]}),P===!1&&a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel}),a.jsx("input",{type:"range",min:1,max:50,step:1,value:N??2,onChange:k=>M({barWidth:parseInt(k.target.value)}),style:{flex:1,cursor:"pointer",accentColor:A.textSecondary}}),a.jsx("input",{type:"number",min:1,max:50,step:1,value:N??2,style:{...R.input,width:48},onChange:k=>{const D=parseInt(k.target.value);D>=1&&D<=50&&M({barWidth:D})}}),a.jsx("span",{style:{fontSize:11,color:A.textTertiary},children:"px"})]})]}),y&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Peak outline"}),a.jsxs("label",{style:R.cbLabel,children:[a.jsx("input",{type:"checkbox",checked:$===!0,ref:k=>{k&&(k.indeterminate=$===null)},onChange:k=>M({showOutline:k.target.checked}),style:{cursor:"pointer"}}),"Trace peaks"]}),$===!0&&a.jsx("input",{type:"color",value:_||f||"#ffffff",onChange:k=>M({outlineColor:k.target.value}),title:"Outline color",style:{width:22,height:18,border:"none",background:"none",cursor:"pointer",padding:0,marginLeft:4}})]}),$===!0&&a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Smoothness"}),a.jsx("input",{type:"range",min:0,max:10,step:1,value:H??0,onChange:k=>M({outlineSmooth:parseInt(k.target.value)}),style:{flex:1,cursor:"pointer",accentColor:A.textSecondary}}),a.jsx("span",{style:{fontSize:11,color:A.textTertiary,width:24,textAlign:"right"},children:H??0})]})]}),T&&a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Y Scale"}),a.jsxs("label",{style:R.cbLabel,children:[a.jsx("input",{type:"checkbox",checked:E,onChange:k=>M(k.target.checked?{scaleMax:null,scaleMin:null}:{scaleMax:100,scaleMin:100}),style:{cursor:"pointer"}}),"Auto"]})]}),T&&!E&&a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel}),a.jsx("span",{style:{fontSize:11,color:A.textTertiary,width:40},children:"+Ymax"}),a.jsx("input",{type:"number",min:1,step:10,value:w??"",placeholder:"max",style:R.input,onChange:k=>{const D=parseFloat(k.target.value);D>0&&M({scaleMax:D})}}),a.jsxs("span",{style:{fontSize:11,color:A.textTertiary,width:40},children:["−","Ymax"]}),a.jsx("input",{type:"number",min:1,step:10,value:S??"",placeholder:"min",style:R.input,onChange:k=>{const D=parseFloat(k.target.value);D>0&&M({scaleMin:D})}})]}),T&&a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Log scale"}),a.jsxs("label",{style:R.cbLabel,children:[a.jsx("input",{type:"checkbox",checked:b===!0,ref:k=>{k&&(k.indeterminate=b===null)},onChange:k=>M({logScale:k.target.checked}),style:{cursor:"pointer"}}),"log","₂"]})]}),g&&a.jsx(H0,{tracks:d,applyToSelected:M,theme:A}),g&&a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Gene style"}),a.jsxs("label",{style:R.cbLabel,children:[a.jsx("input",{type:"checkbox",checked:m===!0,ref:k=>{k&&(k.indeterminate=m===null)},onChange:k=>M({useArrows:k.target.checked}),style:{cursor:"pointer"}}),"Pointed arrows"]})]}),(v||g)&&a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Nucleotides"}),a.jsxs("label",{style:R.cbLabel,children:[a.jsx("input",{type:"checkbox",checked:U!==!1,ref:k=>{k&&(k.indeterminate=U===null)},onChange:k=>M({showNucleotides:k.target.checked}),style:{cursor:"pointer"}}),"Show when zoomed in"]})]}),v&&a.jsxs(a.Fragment,{children:[a.jsx("div",{style:{...R.sectionTitle,marginTop:12},children:"Read Appearance"}),a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Strand colors"}),a.jsx("span",{style:{fontSize:10,color:A.textTertiary,marginRight:2},children:"▶"}),a.jsx("input",{type:"color",value:O||"#90a4ae",onChange:k=>M({fwdColor:k.target.value}),title:"Forward strand color",style:{width:22,height:18,border:"none",background:"none",cursor:"pointer",padding:0}}),a.jsx("span",{style:{fontSize:10,color:A.textTertiary,marginLeft:6,marginRight:2},children:"◀"}),a.jsx("input",{type:"color",value:G||"#f06292",onChange:k=>M({revColor:k.target.value}),title:"Reverse strand color",style:{width:22,height:18,border:"none",background:"none",cursor:"pointer",padding:0}}),a.jsx("button",{style:{...R.smallBtn,marginLeft:"auto"},onClick:()=>M({fwdColor:null,revColor:null}),title:"Reset to defaults",children:"Reset"})]}),a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Arrow style"}),a.jsxs("select",{value:F||"pointed",onChange:k=>M({arrowStyle:k.target.value}),style:{background:A.inputBg,border:`1px solid ${A.borderAccent}`,borderRadius:4,color:A.textPrimary,padding:"2px 6px",fontSize:11,cursor:"pointer"},children:[a.jsx("option",{value:"pointed",children:"Pointed"}),a.jsx("option",{value:"chevron",children:"Chevron"}),a.jsx("option",{value:"fade",children:"Fade"}),a.jsx("option",{value:"flat",children:"Flat (none)"})]})]}),(F||"pointed")!=="flat"&&a.jsxs("div",{style:R.controlRow,children:[a.jsx("span",{style:R.controlLabel,children:"Arrow size"}),a.jsx("input",{type:"range",min:2,max:12,step:1,value:B||4,onChange:k=>M({arrowSize:parseInt(k.target.value)}),style:{flex:1,cursor:"pointer",accentColor:A.textSecondary}}),a.jsx("span",{style:{fontSize:11,color:A.textTertiary,width:20,textAlign:"right"},children:B||4})]})]})]}),a.jsxs("div",{style:R.footer,children:[a.jsxs("div",{style:{display:"flex",gap:6},children:[a.jsx("button",{style:R.smallBtn,onClick:c,children:"Select all"}),a.jsx("button",{style:R.smallBtn,onClick:h,children:"Select none"})]}),a.jsx("div",{style:{display:"flex",gap:8},children:d.length>0&&a.jsxs("button",{style:R.btnDanger,onClick:I,children:["Remove (",d.length,")"]})})]})]})}const W0=[{key:"cds",label:"CDS"},{key:"exon",label:"Exon"},{key:"gene",label:"Gene"},{key:"transcript",label:"Transcript"},{key:"utr",label:"UTR"},{key:"rrna",label:"rRNA"},{key:"trna",label:"tRNA"},{key:"repeat",label:"Repeat"},{key:"default",label:"Other"}];function H0({tracks:e,applyToSelected:t,theme:n}){var T;const[r,o]=C.useState(null),l=C.useRef(null),[i,s]=C.useState(null),u=((T=e[0])==null?void 0:T.annotationColors)||{};function c(v){return u[v]||gp[v]||"#80cbc4"}function h(v,y){for(const x of e){const f={...x.annotationColors||{},[v]:y};t({annotationColors:f})}}function d(){t({annotationColors:null})}function g(v){s(v),l.current&&(l.current.value=c(v),l.current.click())}return a.jsxs("div",{style:{padding:"4px 0"},children:[a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6,padding:"0 0 0 0"},children:[a.jsx("span",{style:{fontSize:12,color:n.textSecondary,width:90},children:"Annotation colors"}),a.jsx("button",{style:{background:"none",border:`1px solid ${n.borderAccent}`,borderRadius:3,color:n.textTertiary,cursor:"pointer",fontSize:10,padding:"1px 6px"},onClick:d,children:"Reset"})]}),W0.map(({key:v,label:y})=>{const x=c(v);return a.jsxs("div",{children:[a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"3px 4px",cursor:"pointer",fontSize:11,color:n.textPrimary,borderRadius:3},onMouseEnter:f=>f.currentTarget.style.background=n.selectedRow||"rgba(255,255,255,0.05)",onMouseLeave:f=>f.currentTarget.style.background="transparent",onClick:()=>o(r===v?null:v),children:[a.jsx("span",{style:{width:14,height:14,borderRadius:3,background:x,border:"1px solid rgba(255,255,255,0.15)",flexShrink:0,cursor:"pointer"},onDoubleClick:f=>{f.stopPropagation(),g(v)},title:"Click to expand swatches, double-click for full color picker"}),a.jsx("span",{style:{flex:1},children:y}),a.jsx("span",{style:{fontSize:9,color:n.textTertiary},children:r===v?"▲":"▼"})]}),r===v&&a.jsx("div",{style:{padding:"3px 4px 6px 24px",display:"flex",flexWrap:"wrap",gap:2},children:D0.map(f=>a.jsx("span",{style:{width:16,height:16,borderRadius:3,background:f,cursor:"pointer",border:f===x?`2px solid ${n.textPrimary}`:"1px solid rgba(255,255,255,0.1)",boxSizing:"border-box"},onClick:()=>{h(v,f),o(null)}},f))})]},v)}),a.jsx("input",{ref:l,type:"color",style:{position:"absolute",left:-9999,top:-9999,opacity:0,width:0,height:0},onChange:v=>{i&&h(i,v.target.value)}})]})}const V0=["dark","light","colorblind","soft","highContrast"],xc=[{key:"appBg",label:"Background",group:"ui"},{key:"panelBg",label:"Panel",group:"ui"},{key:"canvasBg",label:"Canvas",group:"ui"},{key:"btnBg",label:"Buttons",group:"ui"},{key:"textPrimary",label:"Text",group:"ui"},{key:"textSecondary",label:"Text secondary",group:"ui"},{key:"border",label:"Borders",group:"ui"},{key:"geneCds",label:"CDS",group:"gene"},{key:"geneExon",label:"Exon",group:"gene"},{key:"geneGene",label:"Gene",group:"gene"},{key:"geneTranscript",label:"Transcript",group:"gene"},{key:"geneUtr",label:"UTR",group:"gene"},{key:"geneRrna",label:"rRNA",group:"gene"},{key:"geneTrna",label:"tRNA",group:"gene"},{key:"geneRepeat",label:"Repeat",group:"gene"},{key:"geneDefault",label:"Default feature",group:"gene"}],G0=["#000000","#1a1a1a","#333333","#4d4d4d","#666666","#808080","#999999","#b3b3b3","#cccccc","#e6e6e6","#f2f2f2","#ffffff","#4e0000","#7f0000","#b71c1c","#c62828","#d32f2f","#e53935","#ef5350","#f44336","#ef9a9a","#ffcdd2","#ffebee","#fff5f5","#4e2600","#7f3d00","#e65100","#ef6c00","#f57c00","#fb8c00","#ff9800","#ffa726","#ffb74d","#ffcc80","#ffe0b2","#fff3e0","#4e4400","#7f6f00","#f57f17","#f9a825","#fbc02d","#fdd835","#ffeb3b","#fff176","#fff59d","#fff9c4","#fffde7","#fffff0","#003300","#1b5e20","#2e7d32","#388e3c","#43a047","#4caf50","#66bb6a","#81c784","#a5d6a7","#c8e6c9","#e8f5e9","#f1f8e9","#003333","#004d40","#00695c","#00796b","#00897b","#009688","#26a69a","#4db6ac","#80cbc4","#b2dfdb","#e0f2f1","#e0f7fa","#001a33","#0d47a1","#1565c0","#1976d2","#1e88e5","#2196f3","#42a5f5","#64b5f6","#90caf9","#bbdefb","#e3f2fd","#e8eaf6","#1a0033","#311b92","#4527a0","#512da8","#5e35b1","#673ab7","#7e57c2","#9575cd","#b39ddb","#d1c4e9","#ede7f6","#f3e5f5","#330019","#880e4f","#ad1457","#c2185b","#d81b60","#e91e63","#ec407a","#f06292","#f48fb1","#f8bbd0","#fce4ec","#fff0f5","#1b0000","#3e2723","#4e342e","#5d4037","#6d4c41","#795548","#8d6e63","#a1887f","#bcaaa4","#d7ccc8","#efebe9","#fafafa"];function Y0({onClose:e}){const{theme:t,themeName:n,setThemeName:r,customTheme:o,setCustomTheme:l}=Ye(),[i,s]=C.useState(n==="custom"),[u,c]=C.useState(null),[h,d]=C.useState({left:0,top:0}),g=C.useRef(null),T=C.useRef(null);function v(b){r(b),s(!1)}function y(){const b=n==="custom"?o:yt[n]||yt.dark;l({...b,name:"Custom"}),r("custom"),s(!0)}function x(b,P){l({...o,[b]:P})}function f(b,P){const N=P.currentTarget.getBoundingClientRect(),$=window.innerWidth-N.right,_=290,H=260;let j,U;$>_+10?(j=N.right+6,U=Math.min(N.top,window.innerHeight-H-10)):(j=Math.max(10,N.left-_-6),U=Math.min(N.top,window.innerHeight-H-10)),d({left:j,top:U}),c(b)}function p(b){u&&x(u,b),c(null)}function m(b){T.current=b,g.current&&(g.current.value=E[b]||"#000000",g.current.click())}function w(b){T.current&&x(T.current,b.target.value)}const S=Q0(t),E=n==="custom"?o:yt[n]||yt.dark;return a.jsxs(wp,{title:"Color Scheme",onClose:e,theme:t,defaultWidth:420,defaultHeight:480,children:[a.jsxs("div",{style:S.body,children:[a.jsxs("div",{style:S.section,children:[a.jsx("div",{style:S.sectionTitle,children:"Presets"}),a.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:V0.map(b=>a.jsxs("button",{onClick:()=>v(b),style:{...S.presetBtn,border:n===b?`2px solid ${t.textPrimary}`:`1px solid ${t.borderAccent}`},children:[a.jsxs("div",{style:{display:"flex",gap:2,marginBottom:4},children:[a.jsx("span",{style:{width:14,height:14,borderRadius:2,background:yt[b].appBg,border:"1px solid #555"}}),a.jsx("span",{style:{width:14,height:14,borderRadius:2,background:yt[b].headerBg,border:"1px solid #555"}}),a.jsx("span",{style:{width:14,height:14,borderRadius:2,background:yt[b].btnBg,border:"1px solid #555"}})]}),a.jsx("span",{style:{fontSize:10,color:t.textSecondary},children:yt[b].name})]},b))})]}),a.jsxs("div",{style:S.section,children:[a.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[a.jsx("div",{style:S.sectionTitle,children:"Custom Palette"}),i?a.jsx("button",{onClick:()=>s(!1),style:S.smallBtn,children:"Collapse"}):a.jsx("button",{onClick:y,style:S.btn,children:"Customize"})]}),i&&a.jsxs("div",{children:[a.jsx("div",{style:{fontSize:10,color:t.textTertiary,textTransform:"uppercase",letterSpacing:1,marginTop:4,marginBottom:6},children:"Interface"}),a.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"4px 12px"},children:xc.filter(b=>b.group==="ui").map(({key:b,label:P})=>a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[a.jsx("span",{style:{display:"inline-block",width:20,height:16,borderRadius:3,background:E[b]||"#000",border:`1px solid ${t.borderAccent}`,cursor:"pointer",flexShrink:0},onMouseDown:N=>f(b,N),onDoubleClick:()=>{c(null),m(b)}}),a.jsx("span",{style:{fontSize:11,color:t.textSecondary},children:P})]},b))}),a.jsx("div",{style:{fontSize:10,color:t.textTertiary,textTransform:"uppercase",letterSpacing:1,marginTop:10,marginBottom:6},children:"Gene Features"}),a.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:"4px 12px"},children:xc.filter(b=>b.group==="gene").map(({key:b,label:P})=>a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[a.jsx("span",{style:{display:"inline-block",width:20,height:16,borderRadius:3,background:E[b]||"#000",border:`1px solid ${t.borderAccent}`,cursor:"pointer",flexShrink:0},onMouseDown:N=>f(b,N),onDoubleClick:()=>{c(null),m(b)}}),a.jsx("span",{style:{fontSize:11,color:t.textSecondary},children:P})]},b))})]})]})]}),a.jsx("div",{style:S.footer,children:a.jsx("button",{style:S.btn,onClick:e,children:"Close"})}),a.jsx("input",{ref:g,type:"color",onChange:w,style:{position:"fixed",left:-9999,top:-9999,opacity:0,width:0,height:0}}),u&&Dn.createPortal(a.jsx("div",{style:{position:"fixed",left:h.left,top:h.top,zIndex:10002,background:t.panelBg,border:`1px solid ${t.borderAccent}`,borderRadius:6,padding:8,boxShadow:"0 6px 20px rgba(0,0,0,0.6)",display:"grid",gridTemplateColumns:"repeat(12, 20px)",gap:2,maxHeight:300,overflowY:"auto"},onMouseLeave:()=>c(null),children:G0.map((b,P)=>a.jsx("span",{style:{width:20,height:20,borderRadius:3,background:b,cursor:"pointer",border:b===(E[u]||"")?`2px solid ${t.textPrimary}`:"1px solid rgba(128,128,128,0.3)",boxSizing:"border-box"},onMouseUp:()=>p(b)},P))}),document.body)]})}function Q0(e){return{overlay:{position:"fixed",inset:0,background:e.overlayBg,display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},panel:{background:e.panelBg,border:`1px solid ${e.borderAccent}`,borderRadius:8,padding:0,minWidth:440,maxWidth:560,maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.5)"},header:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"10px 16px",borderBottom:`1px solid ${e.border}`},title:{fontSize:14,fontWeight:700,color:e.textPrimary},closeBtn:{background:"none",border:"none",color:e.textSecondary,cursor:"pointer",fontSize:18,lineHeight:1,padding:"0 4px"},body:{padding:"8px 0",overflowY:"auto",flex:1},section:{padding:"8px 16px"},sectionTitle:{fontSize:11,color:e.textSecondary,textTransform:"uppercase",letterSpacing:1,marginBottom:0},presetBtn:{background:e.panelBg,borderRadius:6,padding:"8px 10px",cursor:"pointer",display:"flex",flexDirection:"column",alignItems:"center",minWidth:70},smallBtn:{background:"none",border:`1px solid ${e.borderAccent}`,borderRadius:3,color:e.textSecondary,cursor:"pointer",fontSize:10,padding:"3px 8px"},btn:{background:e.btnBg,border:"none",borderRadius:4,color:e.btnText,padding:"5px 14px",cursor:"pointer",fontSize:12,fontWeight:600},footer:{display:"flex",justifyContent:"flex-end",padding:"10px 16px",borderTop:`1px solid ${e.border}`}}}const Pi=5e4,X0=.5,K0=100,q0=800;function J0(e=200){const t=new Map;return{get(n){return t.get(n)},set(n,r){t.size>=e&&t.delete(t.keys().next().value),t.set(n,r)},findByPrefix(n){let r=null;for(const[o,l]of t)o.startsWith(n)&&(r=l);return r}}}const jn=J0(),$a=new Map;function vc(e,t){$a.set(e,t)}function Sp(e){return $a.get(e)||null}function Z0(e,t){const n=$a.get(e);return n||jn.findByPrefix(`${e}|coverage|${t}|`)||jn.findByPrefix(`${e}|reads|${t}|`)||jn.findByPrefix(`${e}|annotations|${t}|`)||jn.findByPrefix(`${e}|genome_annotations|${t}|`)||jn.findByPrefix(`${e}|variants|${t}|`)||null}function Jl(e,t,n){const[r,o]=C.useState(null),[l,i]=C.useState(!1),[s,u]=C.useState(null),c=C.useRef(null),h=C.useRef(null),d=C.useRef(null),g=C.useRef(null),T=C.useRef(!1);C.useEffect(()=>{if(!e||!t||!n)return;const{chrom:y,start:x,end:f}=t,p=f-x,m=e.track_type;h.current&&h.current.trackId!==e.id&&(h.current=null,T.current=!1);const w=h.current;if(w&&w.trackId===e.id&&w.chrom===y&&x>=w.start&&f<=w.end){const E=p/(w.viewLen||p);if(E>.8&&E<1.2){g.current&&clearTimeout(g.current);return}g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{v(e,y,x,f,p,m,n)},q0);return}return g.current&&clearTimeout(g.current),d.current&&clearTimeout(d.current),T.current&&(w==null?void 0:w.chrom)===y?d.current=setTimeout(()=>{v(e,y,x,f,p,m,n)},K0):v(e,y,x,f,p,m,n),()=>{d.current&&clearTimeout(d.current),g.current&&clearTimeout(g.current)}},[e==null?void 0:e.id,t==null?void 0:t.chrom,t==null?void 0:t.start,t==null?void 0:t.end,n]);function v(y,x,f,p,m,w,S){const b=w!=="reads"||m>Pi?X0:0,P=Math.max(0,Math.floor(f-m*b)),N=Math.ceil(p+m*b),$=(N-P)/m,_=Math.min(Math.floor(S*$),Math.max(S*2,1e3)),H=`${y.id}|${w}|${x}|${P}|${N}|${_}`,j=jn.get(H);if(j){o(j),vc(y.id,j),u(null),h.current={trackId:y.id,chrom:x,start:P,end:N,viewLen:m},T.current=!0;return}c.current&&c.current.abort();const U=new AbortController;c.current=U,T.current||i(!0),u(null);let O;if(w==="reads")m<=Pi?O=$t.reads(y.id,x,f,p):O=$t.coverage(y.id,x,P,N,_);else if(w==="coverage")O=$t.coverage(y.id,x,P,N,_);else if(w==="variants")O=$t.variants(y.id,x,P,N);else if(w==="annotations"||w==="genome_annotations")O=$t.features(y.id,x,P,N);else{i(!1);return}O.then(G=>{if(U.signal.aborted)return;const F={...G.data,mode:w==="reads"&&m<=Pi?"reads":"coverage"};jn.set(H,F),h.current={trackId:y.id,chrom:x,start:P,end:N,viewLen:m},T.current=!0,o(F),vc(y.id,F),u(null)}).catch(G=>{var F,B;if(G.name!=="CanceledError"&&!U.signal.aborted){const M=(B=(F=G.response)==null?void 0:F.data)==null?void 0:B.detail,I=typeof M=="string"?M:G.message||String(G);u(I)}}).finally(()=>{U.signal.aborted||i(!1)})}return{data:r,loading:l,error:s}}const ey=["svg","png","jpg"],ty=140;function ny({onClose:e}){const{region:t}=it(),{tracks:n}=Kt(),{theme:r}=Ye(),o=t==null?void 0:t.chrom,l=n.filter(S=>S.visible&&(!S.targetChromosomes||!o||S.targetChromosomes.includes(o))),[i,s]=C.useState("svg"),[u,c]=C.useState(!0),[h,d]=C.useState(!0),[g,T]=C.useState(new Set(l.map(S=>S.id))),[v,y]=C.useState(1200),[x,f]=C.useState(!1);function p(S){T(E=>{const b=new Set(E);return b.has(S)?b.delete(S):b.add(S),b})}async function m(){if(t){f(!0);try{const S=l.filter($=>g.has($.id)),E=h?ty:0,b=v-E,P=u?30:0,N=P+S.reduce(($,_)=>$+_.height,0);if(i==="svg"){const $=ry(t,S,r,b,E,P,N,u,h);uy($,"genomics-export.svg","image/svg+xml")}else{const $=ay(t,S,r,b,E,P,N,v,u,h),_=i==="png"?"image/png":"image/jpeg";$.toBlob(H=>{const j=URL.createObjectURL(H),U=document.createElement("a");U.href=j,U.download=`genomics-export.${i}`,U.click(),URL.revokeObjectURL(j)},_,.95)}}finally{f(!1)}}}const w=py(r);return a.jsx("div",{style:w.overlay,onClick:S=>{S.target===S.currentTarget&&e()},children:a.jsxs("div",{style:w.panel,children:[a.jsxs("div",{style:w.header,children:[a.jsx("span",{style:w.title,children:"Export Image"}),a.jsx("button",{style:w.closeBtn,onClick:e,children:"✕"})]}),a.jsxs("div",{style:w.body,children:[a.jsxs("div",{style:w.row,children:[a.jsx("span",{style:w.label,children:"Format"}),a.jsx("div",{style:{display:"flex",gap:6},children:ey.map(S=>a.jsx("button",{onClick:()=>s(S),style:{...w.fmtBtn,border:i===S?`2px solid ${r.textPrimary}`:`1px solid ${r.borderAccent}`},children:S.toUpperCase()},S))})]}),a.jsxs("div",{style:w.row,children:[a.jsx("span",{style:w.label,children:"Width (px)"}),a.jsx("input",{type:"number",min:400,max:4e3,step:100,value:v,onChange:S=>y(Math.max(400,parseInt(S.target.value)||1200)),style:w.input})]}),a.jsxs("div",{style:w.row,children:[a.jsxs("label",{style:w.cb,children:[a.jsx("input",{type:"checkbox",checked:u,onChange:S=>c(S.target.checked)})," Ruler"]}),a.jsxs("label",{style:w.cb,children:[a.jsx("input",{type:"checkbox",checked:h,onChange:S=>d(S.target.checked)})," Track labels"]})]}),a.jsxs("div",{style:{...w.row,flexDirection:"column",alignItems:"stretch",gap:4},children:[a.jsx("span",{style:w.label,children:"Include tracks"}),l.map(S=>a.jsxs("label",{style:{...w.cb,gap:6},children:[a.jsx("input",{type:"checkbox",checked:g.has(S.id),onChange:()=>p(S.id)}),a.jsx("span",{style:{width:8,height:8,borderRadius:2,background:S.color,flexShrink:0}}),a.jsx("span",{style:{fontSize:11},children:S.name})]},S.id))]}),i==="svg"&&a.jsx("div",{style:{padding:"4px 0",fontSize:10,color:r.textTertiary},children:"SVG output is fully vectorized — editable in Illustrator, Inkscape, etc."})]}),a.jsxs("div",{style:w.footer,children:[a.jsx("button",{style:w.btn,onClick:m,disabled:x||!t,children:x?"Exporting…":`Export ${i.toUpperCase()}`}),a.jsx("button",{style:{...w.btn,background:r.borderAccent},onClick:e,children:"Cancel"})]})]})})}function ry(e,t,n,r,o,l,i,s,u){const c=r+o;let h=`<?xml version="1.0" encoding="UTF-8"?>
|
|
46
46
|
`;h+=`<svg xmlns="http://www.w3.org/2000/svg" width="${c}" height="${i}" viewBox="0 0 ${c} ${i}" font-family="Arial, Helvetica, sans-serif">
|
|
47
47
|
`,h+=`<defs>
|
|
48
48
|
`,h+=` <clipPath id="trackClip"><rect width="${r}" height="${i}"/></clipPath>
|
|
@@ -94,4 +94,4 @@ ${A.join(`
|
|
|
94
94
|
`)}
|
|
95
95
|
|
|
96
96
|
Tip: If files were moved, re-add them using the 📂 Path button.`):(y("Session restored"),setTimeout(()=>{y(null),e()},1200))}catch(G){f(G.message)}finally{m(!1)}}const $=bc(),_=yy(c);return a.jsx("div",{style:_.overlay,onClick:H=>{H.target===H.currentTarget&&e()},children:a.jsxs("div",{style:_.panel,children:[a.jsxs("div",{style:_.header,children:[a.jsx("span",{style:_.title,children:"Session"}),a.jsx("button",{style:_.closeBtn,onClick:e,children:"✕"})]}),a.jsxs("div",{style:_.body,children:[a.jsxs("div",{style:_.section,children:[a.jsx("div",{style:_.sectionTitle,children:"Save"}),a.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:a.jsx("button",{style:_.btn,onClick:S,disabled:!r||p,children:"Save to file"})}),a.jsx("div",{style:{fontSize:10,color:c.textTertiary,marginTop:4},children:"Session is also auto-saved to browser storage."})]}),a.jsxs("div",{style:_.section,children:[a.jsx("div",{style:_.sectionTitle,children:"Restore"}),a.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[a.jsx("button",{style:_.btn,onClick:E,disabled:p,children:"Load from file"}),$&&a.jsx("button",{style:_.btn,onClick:P,disabled:p,children:"Restore last session"})]}),a.jsx("input",{ref:w,type:"file",accept:".json",style:{display:"none"},onChange:b}),$&&a.jsxs("div",{style:{fontSize:10,color:c.textTertiary,marginTop:4},children:["Last auto-save: ",new Date($.savedAt).toLocaleString(),$.genome&&` — ${$.genome.name}`,$.tracks&&` — ${$.tracks.length} tracks`]})]}),v&&a.jsx("div",{style:{padding:"4px 16px",fontSize:11,color:"#81c784"},children:v}),x&&a.jsx("div",{style:{padding:"4px 16px",fontSize:11,color:"#ef9a9a",whiteSpace:"pre-wrap"},children:x})]}),a.jsx("div",{style:_.footer,children:a.jsx("button",{style:_.btn,onClick:e,children:"Close"})})]})})}function yy(e){return{overlay:{position:"fixed",inset:0,background:e.overlayBg,display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},panel:{background:e.panelBg,border:`1px solid ${e.borderAccent}`,borderRadius:8,padding:0,minWidth:380,maxWidth:480,maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.5)"},header:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"10px 16px",borderBottom:`1px solid ${e.border}`},title:{fontSize:14,fontWeight:700,color:e.textPrimary},closeBtn:{background:"none",border:"none",color:e.textSecondary,cursor:"pointer",fontSize:18,lineHeight:1,padding:"0 4px"},body:{padding:"8px 0",overflowY:"auto",flex:1},section:{padding:"8px 16px"},sectionTitle:{fontSize:11,color:e.textSecondary,textTransform:"uppercase",letterSpacing:1,marginBottom:6},btn:{background:e.btnBg,border:"none",borderRadius:4,color:e.btnText,padding:"5px 14px",cursor:"pointer",fontSize:12,fontWeight:600},footer:{display:"flex",justifyContent:"flex-end",padding:"10px 16px",borderTop:`1px solid ${e.border}`}}}const bn=[{target:"file-loader",title:"Load Files",description:"Select genome and track files using the file picker, drag and drop, or paste a local file path. Supported formats: FASTA, GenBank, BAM (+BAI), BigWig, WIG, BedGraph, VCF, BED, GTF, GFF.",position:"bottom"},{target:"nav-bar",title:"Navigation & Scrubber",description:"Switch chromosomes, type coordinates (chr1:1000-5000) to jump, zoom with -/+, and pan with ◀/▶. The blue scrubber bar shows your position — click or drag it to scroll across the entire chromosome.",position:"bottom"},{target:"track-area",title:"Track Interaction",description:"Left-click drag to pan, scroll to zoom. Right-click drag to select a region — hover the blue highlight for stats. Double-click a gene to zoom in with context. Hover features for detailed tooltips.",position:"inside"},{target:"skeleton-track-label",title:"Track Controls",description:"Drag ≡ to reorder tracks, click the color swatch to change colors, and click × to remove. Drag the bottom edge of a track to resize its height.",position:"right"},{target:"btn-settings",title:"Track Settings",description:"Select tracks and adjust: height, color, Y-axis scale (auto/manual/log), bar width, peak outline trace with color picker, show/hide bars, pointed arrows, and nucleotide display for BAM reads (shows A/C/G/T with mismatch highlighting when zoomed in).",position:"bottom",action:"open-settings"},{target:"header-btns",title:"Themes",description:"Choose from built-in themes (Dark, Light, Colorblind, Soft, High Contrast) or create a fully custom theme. Theme preferences persist across sessions.",position:"bottom",action:"open-theme"},{target:"btn-export",title:"Export Image",description:"Export your current view as SVG or PNG. The export respects all track settings including peak outlines, bar visibility, and scale labels.",position:"bottom"},{target:"header-btns",title:"Sessions",description:"Save Session exports your entire state (genome, tracks, region, zoom, colors, settings) as a JSON file. Restore it later or share with collaborators. Sessions also auto-save to your browser. An exit guard warns you before closing if you have unsaved work.",position:"bottom"},{target:"file-loader",title:"Large File Tips",description:"For large BAM files, use the 📂 Path button to paste a local file path — the server reads directly from disk without uploading. For large WIG files, convert to BigWig format for instant loading. The app checks for updates automatically in the background.",position:"bottom"}],kn=8,Cn=14,Tt=340,xy=230,Br="rgba(0,0,0,0.55)";function vy({onClose:e,theme:t,onAction:n}){const[r,o]=C.useState(0),[l,i]=C.useState(null),[s,u]=C.useState(xy),c=C.useRef(null),h=bn[r],d=r===0,g=r===bn.length-1;C.useEffect(()=>{var b;const E=(b=bn[r])==null?void 0:b.action;E&&n&&n(E)},[r,n]);const T=C.useCallback(E=>{var P;((P=bn[E])==null?void 0:P.action)&&n&&n(null)},[n]),v=C.useCallback(()=>{T(r),r<bn.length-1?o(E=>E+1):e()},[r,e,T]),y=C.useCallback(()=>{T(r),r>0&&o(E=>E-1)},[r,T]);C.useEffect(()=>{function E(b){b.key==="Escape"?e():b.key==="ArrowRight"||b.key==="Enter"?v():b.key==="ArrowLeft"&&y()}return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[e,v,y]),C.useEffect(()=>{function E(){const b=document.querySelector(`[data-tour="${h.target}"]`);if(b){const P=b.getBoundingClientRect();i({top:P.top,left:P.left,width:P.width,height:P.height})}else i(null)}return E(),window.addEventListener("resize",E),window.addEventListener("scroll",E,!0),()=>{window.removeEventListener("resize",E),window.removeEventListener("scroll",E,!0)}},[h.target]),C.useEffect(()=>{c.current&&u(c.current.getBoundingClientRect().height)});const x=l?{top:l.top-kn,left:l.left-kn,width:l.width+kn*2,height:l.height+kn*2}:null;let f,p,m=null,w=Tt/2;if(!l)f=(window.innerHeight-s)/2,p=(window.innerWidth-Tt)/2;else{const E=h.position||"bottom",b=l.top+l.height+kn,P=l.top-kn,N=l.left+l.width+kn,$=l.left+l.width/2;E==="inside"?(f=l.top+Math.max(20,(l.height-s)/2),p=l.left+Math.max(16,(l.width-Tt)/2)):E==="right"?(f=l.top+l.height/2-s/2,p=N+Cn,m="left",w=s/2,p+Tt>window.innerWidth-12&&(f=b+Cn,p=$-Tt/2,m="up",w=Math.max(20,Math.min(Tt-20,$-p)))):(b+Cn+s<=window.innerHeight?(f=b+Cn,m="up"):P-Cn-s>=0?(f=P-Cn-s,m="down"):(f=b+Cn,m="up"),l.width<200?(p=Math.max(12,l.left+l.width-Tt),p<12&&(p=12)):p=$-Tt/2,w=Math.max(20,Math.min(Tt-20,$-p))),p=Math.max(12,Math.min(window.innerWidth-Tt-12,p)),f=Math.max(12,Math.min(window.innerHeight-s-12,f))}const S={card:{position:"fixed",top:f,left:p,width:Tt,zIndex:10002,background:t.panelBg,border:`1px solid ${t.borderAccent}`,borderRadius:10,padding:"20px 24px 16px",color:t.textPrimary,boxShadow:"0 8px 32px rgba(0,0,0,0.5)"},stepCounter:{fontSize:11,fontWeight:600,color:t.textTertiary,textTransform:"uppercase",letterSpacing:1.2,marginBottom:10},title:{fontSize:16,fontWeight:700,marginBottom:6,color:t.textPrimary},description:{fontSize:13,lineHeight:1.6,color:t.textSecondary,marginBottom:20},dots:{display:"flex",justifyContent:"center",gap:8,marginBottom:14},dot:E=>({width:7,height:7,borderRadius:"50%",background:E?"#42a5f5":t.borderStrong,cursor:"pointer"}),nav:{display:"flex",alignItems:"center",justifyContent:"space-between"},btnPrimary:{background:"#1976d2",border:"none",borderRadius:5,color:"#fff",padding:"6px 18px",cursor:"pointer",fontSize:12,fontWeight:600},btnSecondary:{background:t.btnBg,border:`1px solid ${t.borderStrong}`,borderRadius:5,color:t.btnText,padding:"6px 14px",cursor:"pointer",fontSize:12,fontWeight:600},btnDisabled:{background:t.btnBg,border:`1px solid ${t.border}`,borderRadius:5,color:t.textMuted,padding:"6px 14px",fontSize:12,fontWeight:600,cursor:"default",opacity:.5},skip:{background:"none",border:"none",color:t.textTertiary,fontSize:11,cursor:"pointer",textDecoration:"underline",padding:0},arrowUp:{position:"absolute",top:-7,left:w-7,width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent",borderBottom:`7px solid ${t.panelBg}`},arrowDown:{position:"absolute",bottom:-7,left:w-7,width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent",borderTop:`7px solid ${t.panelBg}`},arrowLeft:{position:"absolute",left:-7,top:w-7,width:0,height:0,borderTop:"7px solid transparent",borderBottom:"7px solid transparent",borderRight:`7px solid ${t.panelBg}`}};return a.jsxs(a.Fragment,{children:[a.jsx("div",{style:{position:"fixed",inset:0,zIndex:1e4},onClick:e}),x?a.jsxs(a.Fragment,{children:[a.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,height:Math.max(0,x.top),background:Br,zIndex:10001,pointerEvents:"none"}}),a.jsx("div",{style:{position:"fixed",top:x.top+x.height,left:0,right:0,bottom:0,background:Br,zIndex:10001,pointerEvents:"none"}}),a.jsx("div",{style:{position:"fixed",top:x.top,left:0,width:Math.max(0,x.left),height:x.height,background:Br,zIndex:10001,pointerEvents:"none"}}),a.jsx("div",{style:{position:"fixed",top:x.top,left:x.left+x.width,right:0,height:x.height,background:Br,zIndex:10001,pointerEvents:"none"}}),a.jsx("div",{style:{position:"fixed",top:x.top,left:x.left,width:x.width,height:x.height,borderRadius:6,border:"2px solid rgba(255,255,255,0.22)",zIndex:10001,pointerEvents:"none",boxSizing:"border-box"}})]}):a.jsx("div",{style:{position:"fixed",inset:0,background:Br,zIndex:10001,pointerEvents:"none"}}),a.jsxs("div",{ref:c,style:S.card,onClick:E=>E.stopPropagation(),children:[m==="up"&&a.jsx("div",{style:S.arrowUp}),m==="down"&&a.jsx("div",{style:S.arrowDown}),m==="left"&&a.jsx("div",{style:S.arrowLeft}),a.jsxs("div",{style:S.stepCounter,children:["Step ",r+1," of ",bn.length]}),a.jsx("div",{style:S.title,children:h.title}),a.jsx("div",{style:S.description,children:h.description}),a.jsx("div",{style:S.dots,children:bn.map((E,b)=>a.jsx("div",{style:S.dot(b===r),onClick:()=>o(b)},b))}),a.jsxs("div",{style:S.nav,children:[a.jsx("button",{style:S.skip,onClick:e,children:"Skip Tour"}),a.jsxs("div",{style:{display:"flex",gap:8},children:[a.jsx("button",{style:d?S.btnDisabled:S.btnSecondary,onClick:y,disabled:d,children:"Previous"}),a.jsx("button",{style:S.btnPrimary,onClick:v,children:g?"Finish":"Next"})]})]})]})]})}function wy(){const{theme:e}=Ye(),{genome:t,region:n,navigateTo:r,zoom:o,pan:l}=it(),[i,s]=C.useState(""),u=C.useRef(null),c=C.useRef(!1),h=C.useMemo(()=>{if(!t)return{toShort:{},toLong:{}};const w={},S={};return t.chromosomes.forEach((E,b)=>{const P=`chr${b+1}`;w[E.name]=P,S[P.toLowerCase()]=E.name,S[E.name.toLowerCase()]=E.name}),{toShort:w,toLong:S}},[t]);C.useEffect(()=>{if(n){const w=h.toShort[n.chrom]||n.chrom;s(`${w}:${n.start.toLocaleString()}-${n.end.toLocaleString()}`)}},[n,h]);const d=C.useMemo(()=>{if(!t||!n)return 0;const w=t.chromosomes.find(S=>S.name===n.chrom);return w?w.length:0},[t,n==null?void 0:n.chrom]),g=C.useCallback(w=>{if(!u.current||!n||!d)return;const S=u.current.getBoundingClientRect(),E=Math.max(0,Math.min(1,(w-S.left)/S.width)),b=n.end-n.start,P=E*d;r(n.chrom,P-b/2,P+b/2)},[n,d,r]),T=C.useCallback(w=>{w.preventDefault(),c.current=!0,g(w.clientX);function S(b){c.current&&g(b.clientX)}function E(){c.current=!1,window.removeEventListener("mousemove",S),window.removeEventListener("mouseup",E),document.body.style.cursor="",document.body.style.userSelect=""}document.body.style.cursor="grabbing",document.body.style.userSelect="none",window.addEventListener("mousemove",S),window.addEventListener("mouseup",E)},[g]),v={bar:{background:e.headerBg,borderBottom:`1px solid ${e.border}`,padding:"6px 12px",display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},select:{background:e.inputBg,border:`1px solid ${e.borderAccent}`,borderRadius:4,color:e.textPrimary,padding:"4px 6px",fontSize:12},coordInput:{background:e.inputBg,border:`1px solid ${e.borderAccent}`,borderRadius:4,color:e.textPrimary,padding:"4px 8px",fontSize:12,width:220,fontFamily:"monospace"},btn:{background:e.btnBg,border:"none",borderRadius:4,color:e.btnText,padding:"4px 10px",cursor:"pointer",fontSize:13},info:{color:e.textSecondary,fontSize:11,marginLeft:8},scrubberWrap:{flex:1,minWidth:120,height:14,position:"relative",background:e.inputBg,borderRadius:7,border:`1px solid ${e.borderAccent}`,cursor:"pointer",overflow:"hidden"}};function y(w){if(!t)return;const S=t.chromosomes.find(E=>E.name===w.target.value);S&&r(S.name,0,Math.min(S.length,5e4))}function x(w){w.preventDefault();const E=i.replace(/,/g,"").trim().match(/^(\S+):(\d+)-(\d+)$/);if(E){const b=h.toLong[E[1].toLowerCase()]||E[1];r(b,parseInt(E[2]),parseInt(E[3]))}}if(!t)return a.jsx("div",{style:{...v.bar,opacity:.4},"data-tour":"nav-bar",children:a.jsx("span",{style:{fontSize:12,color:e.textMuted,fontStyle:"italic"},children:"Load a genome to enable navigation"})});const f=n?n.end-n.start:0;let p=0,m=100;return n&&d>0&&(p=n.start/d*100,m=Math.max(1,f/d*100)),a.jsxs("div",{style:v.bar,"data-tour":"nav-bar",children:[a.jsx("select",{style:v.select,value:(n==null?void 0:n.chrom)||"",onChange:y,children:t.chromosomes.map((w,S)=>a.jsxs("option",{value:w.name,children:["chr",S+1," ","—"," ",w.name," (",(w.length/1e3).toFixed(0)," kbp)"]},w.name))}),a.jsxs("form",{onSubmit:x,style:{display:"flex",gap:4},children:[a.jsx("input",{style:v.coordInput,value:i,onChange:w=>s(w.target.value),placeholder:"chr1:start-end"}),a.jsx("button",{style:v.btn,type:"submit",children:"Go"})]}),a.jsx("button",{style:v.btn,onClick:()=>o(2),title:"Zoom out",children:"-"}),a.jsx("button",{style:v.btn,onClick:()=>o(.5),title:"Zoom in",children:"+"}),a.jsx("button",{style:v.btn,onClick:()=>l(-f*.5),title:"Pan left",children:"◀"}),a.jsx("button",{style:v.btn,onClick:()=>l(f*.5),title:"Pan right",children:"▶"}),n&&d>0&&a.jsx("div",{ref:u,style:v.scrubberWrap,onMouseDown:T,title:"Drag to scroll across the chromosome",children:a.jsx("div",{style:{position:"absolute",left:`${p}%`,width:`${m}%`,top:1,bottom:1,background:"#42a5f5",borderRadius:6,minWidth:8,opacity:.7,transition:c.current?"none":"left 0.1s ease"}})}),n&&a.jsxs("span",{style:v.info,children:[f.toLocaleString()," bp"]})]})}function Cp(e){const{region:t,zoom:n,navigateTo:r,setSelection:o,clearSelection:l}=it(),i=C.useRef(null),s=C.useRef(null),u=C.useRef(t);u.current=t,C.useEffect(()=>{const c=e.current;if(!c)return;function h(y){const x=u.current;if(x){if(y.button===2){y.preventDefault();const f=c.getBoundingClientRect(),p=(y.clientX-f.left)/f.width,m=x.start+p*(x.end-x.start);s.current={startX:y.clientX,startBp:m,region:{...x},containerWidth:f.width};return}y.button===0&&(l(),i.current={x:y.clientX,startRegion:{...x},containerWidth:c.offsetWidth||c.clientWidth||1})}}function d(y){if(s.current){const E=s.current,b=c.getBoundingClientRect(),P=Math.max(0,Math.min(1,(y.clientX-b.left)/b.width)),N=E.region.start+P*(E.region.end-E.region.start),$=Math.min(E.startBp,N),_=Math.max(E.startBp,N);Math.abs(_-$)>=1&&o({chrom:E.region.chrom,start:Math.floor($),end:Math.ceil(_)});return}if(!i.current)return;const x=y.clientX-i.current.x,{chrom:f,start:p,end:m}=i.current.startRegion,w=(m-p)/i.current.containerWidth,S=-x*w;r(f,p+S,m+S)}function g(y){if(s.current){s.current=null;return}i.current=null}function T(y){y.preventDefault()}function v(y){y.preventDefault();const x=c.getBoundingClientRect(),f=(y.clientX-x.left)/x.width,p=y.deltaY>0?1.4:.7;n(p,f)}return c.addEventListener("mousedown",h),c.addEventListener("contextmenu",T),window.addEventListener("mousemove",d),window.addEventListener("mouseup",g),c.addEventListener("wheel",v,{passive:!1}),()=>{c.removeEventListener("mousedown",h),c.removeEventListener("contextmenu",T),window.removeEventListener("mousemove",d),window.removeEventListener("mouseup",g),c.removeEventListener("wheel",v)}},[n,r,o,l,e])}const Tn=30;function Sy({width:e}){const t=C.useRef(null),n=C.useRef(null),{region:r,selection:o}=it(),{theme:l}=Ye();return Cp(t),C.useEffect(()=>{const i=n.current;if(!i||!r)return;const s=window.devicePixelRatio||1;i.width=e*s,i.height=Tn*s;const u=i.getContext("2d");u.scale(s,s);const{start:c,end:h}=r,d=h-c;if(u.clearRect(0,0,e,Tn),u.fillStyle=l.canvasBg,u.fillRect(0,0,e,Tn),o&&o.chrom===r.chrom){const p=(o.start-c)/d,m=(o.end-c)/d,w=Math.max(0,p*e),S=Math.min(e,m*e);S-w>=1&&(u.fillStyle="rgba(100, 181, 246, 0.25)",u.fillRect(w,0,S-w,Tn),u.strokeStyle="rgba(100, 181, 246, 0.6)",u.lineWidth=1,u.beginPath(),u.moveTo(w,0),u.lineTo(w,Tn),u.moveTo(S,0),u.lineTo(S,Tn),u.stroke())}const g=Math.min(10,Math.floor(e/80)),T=d/g,v=Math.pow(10,Math.floor(Math.log10(T))),y=[1,2,5,10].map(p=>p*v),x=y.find(p=>p>=T)||y[y.length-1],f=Math.ceil(c/x)*x;u.strokeStyle=l.rulerTick,u.fillStyle=l.rulerLabel,u.font="10px Arial, Helvetica, sans-serif",u.textAlign="center",u.beginPath(),u.moveTo(0,20),u.lineTo(e,20),u.lineWidth=1,u.stroke();for(let p=f;p<=h;p+=x){const m=(p-c)/d*e;u.beginPath(),u.moveTo(m,14),u.lineTo(m,20),u.stroke(),u.fillText(by(p),m,11)}},[r,o,e,l]),a.jsx("div",{ref:t,style:{position:"relative"},children:a.jsx("canvas",{ref:n,style:{display:"block",width:"100%",height:Tn}})})}function by(e){return e>=1e6?`${(e/1e6).toFixed(2)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Mi(e,t){if(t<=0||e.length===0)return e;const n=new Array(e.length);for(let r=0;r<e.length;r++){let o=0,l=0;const i=Math.max(0,r-t),s=Math.min(e.length-1,r+t);for(let u=i;u<=s;u++)o+=e[u],l++;n[r]=o/l}return n}function Yn(e,t){return e<=0||t<=0?0:Math.log2(e+1)/Math.log2(t+1)}function ky({track:e,width:t,height:n,onWarning:r}){const o=C.useRef(null),{region:l}=it(),{theme:i}=Ye(),{data:s,loading:u,error:c}=Jl(e,l,t);return C.useEffect(()=>{var G,F;const h=o.current;if(!h)return;const d=window.devicePixelRatio||1;h.width=t*d,h.height=n*d;const g=h.getContext("2d");if(g.scale(d,d),g.clearRect(0,0,t,n),g.fillStyle=i.canvasBg,g.fillRect(0,0,t,n),u&&!((G=s==null?void 0:s.bins)!=null&&G.length)){g.fillStyle=i.textTertiary,g.font="11px Arial, Helvetica, sans-serif",g.fillText("Loading…",8,n/2+4),r&&r(null);return}if(c){g.fillStyle="#ef9a9a",g.font="11px Arial, Helvetica, sans-serif",g.fillText(typeof c=="string"?c:JSON.stringify(c),8,n/2+4),r&&r(null);return}if(!((F=s==null?void 0:s.bins)!=null&&F.length)){r&&r(null);return}const T=s.max_value||0,v=s.min_value||0,y=v<0,x=l.start,f=l.end-l.start,p=e.color||"#78909c",m=e.scaleMax!=null?e.scaleMax:null,w=e.scaleMin!=null?e.scaleMin:null,S=e.logScale===!0,E=e.barAutoWidth!==!1,b=e.barWidth||2,P=e.showOutline===!0,N=e.outlineColor||null,$=e.outlineSmooth||0,_=e.showBars!==!1,H=p,j=Cy(p,-40),U=t/f;function O(B){return E?U>=1?Math.max(1,Math.min(U,B)):Math.max(1,B):Math.min(b,B)}if(y){const M=Math.round(n/2),I=M-12/2,A=n-M-12/2,R=m??(T||1),k=w??(Math.abs(v)||1);if(g.strokeStyle=i.centerLine,g.lineWidth=1,g.beginPath(),g.moveTo(0,M),g.lineTo(t,M),g.stroke(),_)for(const Y of s.bins){const K=(Y.end-Y.start)/f*t,re=O(K),ue=(Y.start-x)/f*t,pe=Y.forward!=null?Y.forward:Math.max(0,Y.value),fe=Y.reverse!=null?Y.reverse:Math.min(0,Y.value);if(pe>0){const ae=S?Yn(pe,R):pe/R;g.fillStyle=H,g.fillRect(ue,M-ae*I,re,ae*I)}if(fe<0){const ae=S?Yn(Math.abs(fe),k):Math.abs(fe)/k;g.fillStyle=j,g.fillRect(ue,M,re,ae*A)}}if(P&&s.bins.length>0){const Y=N||i.textPrimary||"#fff",K=N||i.textPrimary||"#fff",re=s.bins.map(ie=>{const te=ie.forward!=null?ie.forward:Math.max(0,ie.value);return te>0?S?Yn(te,R):te/R:0}),ue=s.bins.map(ie=>{const te=ie.reverse!=null?ie.reverse:Math.min(0,ie.value);return te<0?S?Yn(Math.abs(te),k):Math.abs(te)/k:0}),pe=Mi(re,$),fe=Mi(ue,$),ae=s.bins.map(ie=>((ie.start+ie.end)/2-x)/f*t);Bi(g,ae,pe.map(ie=>M-ie*I),Y,$>0),Bi(g,ae,fe.map(ie=>M+ie*A),K,$>0)}const D=S?" log₂":"";Ar(g,`+${R.toFixed(1)}${D}`,2,2,i),Ar(g,`−${k.toFixed(1)}${D}`,2,n-12,i),Ar(g,"0",2,M-6,i,!0)}else{const B=m??(T||1);if(_){g.fillStyle=H;for(const I of s.bins){const A=(I.end-I.start)/f*t,R=O(A),k=(I.start-x)/f*t,Y=(S?Yn(I.value,B):I.value/B)*(n-14);g.fillRect(k,n-Y-2,R,Y)}}if(P&&s.bins.length>0){const I=s.bins.map(D=>S?Yn(D.value,B):D.value/B),A=Mi(I,$),R=s.bins.map(D=>((D.start+D.end)/2-x)/f*t),k=A.map(D=>n-D*(n-14)-2);Bi(g,R,k,N||i.textPrimary||"#fff",$>0)}const M=S?" log₂":"";Ar(g,`${B.toFixed(1)}${M}`,2,2,i),Ar(g,"0",2,n-12,i,!0)}if(r){const B=[];m!=null&&T>m&&B.push(`Bars clipped: max value ${T.toFixed(1)} exceeds scale ${m.toFixed(1)}`),y&&w!=null&&Math.abs(v)>w&&B.push(`Negative bars clipped: min value ${Math.abs(v).toFixed(1)} exceeds scale ${w.toFixed(1)}`),r(B.length>0?B.join(`
|
|
97
|
-
`):null)}},[s,u,c,t,n,l,e.color,e.scaleMax,e.scaleMin,e.logScale,e.barAutoWidth,e.barWidth,e.showOutline,e.outlineColor,e.outlineSmooth,e.showBars,i]),a.jsx("canvas",{ref:o,style:{display:"block",width:"100%",height:n}})}function Bi(e,t,n,r,o){if(!(t.length<2)){if(e.beginPath(),e.moveTo(t[0],n[0]),o){for(let l=0;l<t.length-1;l++){const i=(t[l]+t[l+1])/2,s=(n[l]+n[l+1])/2;e.quadraticCurveTo(t[l],n[l],i,s)}e.lineTo(t[t.length-1],n[n.length-1])}else for(let l=0;l<t.length;l++)e.lineTo(t[l],n[l]);e.strokeStyle=r,e.lineWidth=1.5,e.stroke()}}function Ar(e,t,n,r,o,l=!1){e.font="10px Arial, Helvetica, sans-serif",e.textAlign="left",e.textBaseline="top";const i=e.measureText(t),s=2,u=i.width+s*2,c=12;e.fillStyle=o.canvasBg||"#1e1e1e",e.globalAlpha=.75,e.fillRect(n,r,u,c),e.globalAlpha=1,e.fillStyle=l?o.textTertiary||"#666":o.textSecondary||"#aaa",e.fillText(t,n+s,r+1),e.textBaseline="alphabetic"}function Cy(e,t){const n=e.match(/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);if(!n)return e;const r=o=>Math.max(0,Math.min(255,o+t));return`rgb(${r(parseInt(n[1],16))},${r(parseInt(n[2],16))},${r(parseInt(n[3],16))})`}const Cc=6,Ai=8,zi=14,$i=2,Ty="#9c27b0",Wo=10,Ey={A:"#4caf50",T:"#f44336",C:"#2196f3",G:"#ff9800",N:"#9e9e9e"},Ry="#ffeb3b";function Tc(e,t){return e<=0||t<=0?0:Math.log2(e+1)/Math.log2(t+1)}function jy({track:e,width:t,height:n,onWarning:r}){const o=C.useRef(null),{region:l}=it(),{theme:i}=Ye(),{data:s,loading:u}=Jl(e,l,t),[c,h]=C.useState(null),d=C.useRef(null),[g,T]=C.useState(0),v=C.useRef(null),y=e.showNucleotides!==!1,x=e.useArrows!==!1,f=e.logScale===!0,p=e.fwdColor||"#90a4ae",m=e.revColor||"#f06292",w=e.arrowStyle||"pointed",S=e.arrowSize||4,E=C.useRef(null);C.useEffect(()=>{if(l&&E.current){const N=E.current;(N.chrom!==l.chrom||Math.abs(N.start-l.start)>N.end-N.start)&&T(0)}E.current=l},[l==null?void 0:l.chrom,l==null?void 0:l.start,l==null?void 0:l.end]),C.useEffect(()=>{if(!l||!y){h(null);return}const N=l.end-l.start;if(t/N<Cc||N>2e3){h(null);return}if(c&&c.chrom===l.chrom&&c.start<=l.start&&c.end>=l.end)return;const _=Math.max(0,l.start-500),H=l.end+500,j=`${l.chrom}:${_}-${H}`;d.current!==j&&(d.current=j,mn.sequence(l.chrom,_,H).then(U=>h({chrom:l.chrom,start:_,end:H,sequence:U.data.sequence})).catch(()=>{}))},[l==null?void 0:l.chrom,l==null?void 0:l.start,l==null?void 0:l.end,t,y]);const b=C.useCallback(N=>{var U;if(!((U=s==null?void 0:s.reads)!=null&&U.length)||!N.shiftKey&&Math.abs(N.deltaX)>Math.abs(N.deltaY))return;const $=y&&c?zi:Ai,_=Math.max(0,...s.reads.map(O=>O.row)),H=Math.floor(n/($+$i)),j=Math.max(0,_-H+2);j<=0||(N.preventDefault(),N.stopPropagation(),T(O=>Math.max(0,Math.min(j,O+Math.sign(N.deltaY)*3))))},[s,n,y,c]);C.useEffect(()=>{var Y;const N=o.current;if(!N)return;const $=window.devicePixelRatio||1;N.width=t*$,N.height=n*$;const _=N.getContext("2d");if(_.scale($,$),_.clearRect(0,0,t,n),_.fillStyle=i.canvasBg,_.fillRect(0,0,t,n),u&&!s){_.fillStyle=i.textTertiary,_.font="11px Arial, Helvetica, sans-serif",_.fillText("Loading…",8,n/2+4),r&&r(null);return}if(!s){r&&r(null);return}const H=l.start,j=l.end-l.start;if(s.bins){const K=s.max_value||1,re=e.scaleMax!=null?e.scaleMax:K,ue=e.color||"#78909c",pe=e.barAutoWidth!==!1,fe=e.barWidth||2,ae=t/j;if(e.showBars!==!1){_.fillStyle=ue;for(const te of s.bins){const ge=(te.end-te.start)/j*t,_e=pe?ae>=1?Math.max(1,Math.min(ae,ge)):Math.max(1,ge):Math.min(fe,ge),ye=(te.start-H)/j*t,Je=(f?Tc(te.value,re):Math.min(1,te.value/re))*(n-14);_.fillRect(ye,n-Je-2,_e,Je)}}if(e.showOutline&&s.bins.length>0){const te=e.outlineSmooth||0,ge=s.bins.map(he=>f?Tc(he.value,re):Math.min(1,he.value/re)),_e=_y(ge,te),ye=s.bins.map(he=>((he.start+he.end)/2-H)/j*t),Ne=_e.map(he=>n-he*(n-14)-2),Je=e.outlineColor||i.textPrimary||"#fff";if(_.beginPath(),_.moveTo(ye[0],Ne[0]),te>0){for(let he=0;he<ye.length-1;he++)_.quadraticCurveTo(ye[he],Ne[he],(ye[he]+ye[he+1])/2,(Ne[he]+Ne[he+1])/2);_.lineTo(ye[ye.length-1],Ne[Ne.length-1])}else for(let he=0;he<ye.length;he++)_.lineTo(ye[he],Ne[he]);_.strokeStyle=Je,_.lineWidth=1.5,_.stroke()}const ie=f?" log₂":"";Ec(_,`${re.toFixed(1)}${ie}`,2,2,i),Ec(_,"0",2,n-12,i,!0),_.fillStyle="#ffb74d",_.font="10px Arial, Helvetica, sans-serif",_.textAlign="right",_.fillText("zoom in for reads",t-4,10),r&&r(e.scaleMax!=null&&K>e.scaleMax?`Bars clipped: max value ${K.toFixed(1)} exceeds scale ${e.scaleMax.toFixed(1)}`:null);return}if(!((Y=s.reads)!=null&&Y.length)){_.fillStyle=i.textTertiary,_.font="11px Arial, Helvetica, sans-serif",_.fillText("No reads in region",8,n/2+4),r&&r(null);return}const U=K=>(K-H)/j*t,O=t/j,G=y&&O>=Cc&&c!=null,F=G?zi:Ai,B=$i,I=Math.max(0,...s.reads.map(K=>K.row))+1,A=Math.floor(n/(F+B)),R=I>A,k=Math.min(g,Math.max(0,I-A+1));let D=0;for(const K of s.reads){const re=(K.row-k)*(F+B)+2;if(re+F<0||re>n){D++;continue}const ue=K.strand==="+"?p:m,pe=K.segments;if(pe&&pe.length>0){const fe=U(K.start),ae=U(K.end);_.strokeStyle=ue,_.lineWidth=1,_.beginPath(),_.moveTo(fe,re+F/2),_.lineTo(ae,re+F/2),_.stroke();let ie=0;for(const te of pe)if(te.type==="M"){const ge=U(te.start),_e=Math.max(1,U(te.end)-ge);if(_.fillStyle=ue,_.fillRect(ge,re,_e,F),G&&K.sequence){const ye=te.end-te.start;for(let Ne=0;Ne<ye;Ne++){const Je=te.start+Ne,he=U(Je),ht=U(Je+1)-he,V=(K.sequence[ie+Ne]||"").toUpperCase();let J="";c&&Je>=c.start&&Je<c.end&&(J=(c.sequence[Je-c.start]||"").toUpperCase());const ee=J&&V&&V!==J&&V!=="N";ee&&(_.fillStyle=Ry,_.fillRect(he,re,ht,F)),ht>=6&&(_.fillStyle=ee?"#000":Ey[V]||"#999",_.font=`bold ${Math.min(11,ht-1)}px monospace`,_.textAlign="center",_.textBaseline="middle",_.fillText(V,he+ht/2,re+F/2))}ie+=ye}}else if(te.type==="D"){const ge=U(te.start),_e=U(te.end)-ge;_e>=1&&(_.strokeStyle=ue,_.lineWidth=1,_.beginPath(),_.moveTo(ge,re+F/2),_.lineTo(ge+_e,re+F/2),_.stroke())}else if(te.type==="N"){const ge=U(te.start),_e=U(te.end)-ge;_e>=2&&(_.setLineDash([2,2]),_.strokeStyle=ue,_.lineWidth=1,_.beginPath(),_.moveTo(ge,re+F/2),_.lineTo(ge+_e,re+F/2),_.stroke(),_.setLineDash([]))}else te.type==="I"?(_.fillStyle=Ty,_.fillRect(U(te.pos)-1,re-1,2,F+2),G&&(ie+=te.length)):te.type==="S"&&G&&(ie+=te.length)}else{const fe=U(K.start),ae=Math.max(2,U(K.end)-fe);_.fillStyle=K.strand==="+"?p:m,_.fillRect(fe,re,ae,F)}if(x&&w!=="flat"){const fe=U(K.start),ae=Math.max(2,U(K.end)-fe),ie=Math.min(S,ae/2);ie>=2&&Py(_,w,K.strand,fe,re,ae,F,ie,ue,i.canvasBg)}if(!G&&!y){const fe=U(K.start);Math.max(2,U(K.end)-fe)>60&&(_.fillStyle=i.canvasBg,_.font="8px Arial, Helvetica, sans-serif",_.textAlign="left",_.fillText(K.name.slice(0,20),fe+2,re+F-1))}}if(R){const K=t-Wo;_.fillStyle=i.inputBg||"#2a2a2a",_.fillRect(K,0,Wo,n);const re=A/I,ue=Math.max(20,re*n),fe=(I>A?k/(I-A):0)*(n-ue);_.fillStyle="#555",_.fillRect(K+1,fe,Wo-2,ue)}r&&(D>0&&!R?r(`${D} read${D>1?"s":""} hidden — increase track height to show all`):r(R?`${I} rows · Shift+scroll or drag scrollbar to navigate`:null))},[s,u,t,n,l,c,g,e.color,e.scaleMax,e.scaleMin,e.barAutoWidth,e.barWidth,e.showOutline,e.outlineColor,e.outlineSmooth,e.showBars,e.showNucleotides,e.useArrows,e.logScale,e.fwdColor,e.revColor,e.arrowStyle,e.arrowSize,i]);const P=C.useCallback(N=>{var I;if(!((I=s==null?void 0:s.reads)!=null&&I.length))return;const $=o.current;if(!$)return;const _=$.getBoundingClientRect();if((N.clientX-_.left)*(t/_.width)<t-Wo)return;const j=y&&c?zi:Ai,O=Math.max(0,...s.reads.map(A=>A.row))+1,G=Math.floor(n/(j+$i)),F=Math.max(0,O-G+1);if(F<=0)return;N.preventDefault(),v.current={maxScroll:F,startY:N.clientY,startRow:g};function B(A){if(!v.current)return;const R=A.clientY-v.current.startY,k=Math.round(R/n*v.current.maxScroll);T(Math.max(0,Math.min(v.current.maxScroll,v.current.startRow+k)))}function M(){v.current=null,window.removeEventListener("mousemove",B),window.removeEventListener("mouseup",M)}window.addEventListener("mousemove",B),window.addEventListener("mouseup",M)},[s,t,n,g,y,c]);return a.jsx("canvas",{ref:o,style:{display:"block",width:"100%",height:n},onWheel:b,onMouseDown:P})}function Py(e,t,n,r,o,l,i,s,u,c){const h=n==="+";if(t==="pointed")e.fillStyle=c,h?(e.beginPath(),e.moveTo(r+l,o+i/2),e.lineTo(r+l-s,o),e.lineTo(r+l-s,o+i),e.fill()):(e.beginPath(),e.moveTo(r,o+i/2),e.lineTo(r+s,o),e.lineTo(r+s,o+i),e.fill());else if(t==="chevron")e.strokeStyle=c,e.lineWidth=1.5,h?(e.beginPath(),e.moveTo(r+l-s,o),e.lineTo(r+l,o+i/2),e.lineTo(r+l-s,o+i),e.stroke()):(e.beginPath(),e.moveTo(r+s,o),e.lineTo(r,o+i/2),e.lineTo(r+s,o+i),e.stroke());else if(t==="fade")if(h){const d=e.createLinearGradient(r+l-s*2,0,r+l,0);d.addColorStop(0,"rgba(0,0,0,0)"),d.addColorStop(1,c),e.fillStyle=d,e.fillRect(r+l-s*2,o,s*2,i)}else{const d=e.createLinearGradient(r,0,r+s*2,0);d.addColorStop(0,c),d.addColorStop(1,"rgba(0,0,0,0)"),e.fillStyle=d,e.fillRect(r,o,s*2,i)}}function _y(e,t){if(t<=0||e.length===0)return e;const n=new Array(e.length);for(let r=0;r<e.length;r++){let o=0,l=0;const i=Math.max(0,r-t),s=Math.min(e.length-1,r+t);for(let u=i;u<=s;u++)o+=e[u],l++;n[r]=o/l}return n}function Ec(e,t,n,r,o,l=!1){e.font="10px Arial, Helvetica, sans-serif",e.textAlign="left",e.textBaseline="top";const i=2,s=e.measureText(t).width+i*2;e.fillStyle=o.canvasBg||"#1e1e1e",e.globalAlpha=.75,e.fillRect(n,r,s,12),e.globalAlpha=1,e.fillStyle=l?o.textTertiary||"#666":o.textSecondary||"#aaa",e.fillText(t,n+i,r+1),e.textBaseline="alphabetic"}const Ly=16,My=22,By=4,Tp=8,Rc=6,jc={A:"#4caf50",T:"#f44336",C:"#2196f3",G:"#ff9800",N:"#9e9e9e"};function Ay({track:e,width:t,height:n,onWarning:r}){var N,$,_,H;const o=C.useRef(null),{region:l,navigateTo:i}=it(),{tracks:s}=Kt(),{theme:u}=Ye(),{data:c,loading:h,error:d}=Jl(e,l,t),g=e.useArrows!==!1,T=e.showNucleotides!==!1,v=C.useRef([]),[y,x]=C.useState(null),[f,p]=C.useState(null),m=C.useRef(null);C.useEffect(()=>{if(!l||!T){p(null);return}const j=l.end-l.start;if(t/j<Rc||j>2e3){p(null);return}if(f&&f.chrom===l.chrom&&f.start<=l.start&&f.end>=l.end)return;const O=Math.max(0,l.start-500),G=l.end+500,F=`${l.chrom}:${O}-${G}`;m.current!==F&&(m.current=F,mn.sequence(l.chrom,O,G).then(B=>p({chrom:l.chrom,start:O,end:G,sequence:B.data.sequence})).catch(()=>{}))},[l==null?void 0:l.chrom,l==null?void 0:l.start,l==null?void 0:l.end,t,T]),C.useEffect(()=>{var k,D;const j=o.current;if(!j)return;const U=window.devicePixelRatio||1;j.width=t*U,j.height=n*U;const O=j.getContext("2d");if(O.scale(U,U),O.clearRect(0,0,t,n),O.fillStyle=u.canvasBg,O.fillRect(0,0,t,n),v.current=[],h&&!((k=c==null?void 0:c.features)!=null&&k.length)){O.fillStyle=u.textTertiary,O.font="11px Arial, Helvetica, sans-serif",O.fillText("Loading…",8,n/2+4),r&&r(null);return}if(d){O.fillStyle="#ef9a9a",O.font="11px Arial, Helvetica, sans-serif",O.fillText(typeof d=="string"?d:JSON.stringify(d),8,n/2+4),r&&r(null);return}if(!((D=c==null?void 0:c.features)!=null&&D.length)){c&&(O.fillStyle=u.textTertiary,O.font="11px Arial, Helvetica, sans-serif",O.fillText("No features in region",8,n/2+4)),r&&r(null);return}const G=l.end-l.start,F=t/G,B=T&&F>=Rc&&f!=null,M=B?My:Ly,I=[],A=[];let R=0;if(B){const K=n-14;O.fillStyle=u.canvasBg,O.fillRect(0,K,t,14),O.strokeStyle=u.border||"#333",O.lineWidth=.5,O.beginPath(),O.moveTo(0,K),O.lineTo(t,K),O.stroke();const re=Math.min(10,F-1);if(re>=5){O.font=`bold ${re}px monospace`,O.textAlign="center",O.textBaseline="middle";for(let ue=Math.floor(l.start);ue<Math.ceil(l.end);ue++)if(f&&ue>=f.start&&ue<f.end){const pe=(f.sequence[ue-f.start]||"").toUpperCase(),fe=(ue-l.start)/G*t;O.fillStyle=jc[pe]||"#999",O.fillText(pe,fe+F/2,K+14/2)}}}for(const Y of c.features){let K=I.findIndex(ae=>Y.start>=ae);K===-1&&(K=I.length),I[K]=Y.end;const re=(Y.start-l.start)/G*t,ue=Math.max(2,(Y.end-Y.start)/G*t),pe=K*(M+By)+2;if(pe+M>n){R++;continue}const fe=_c(Y.feature_type,e,u);if(Y.sub_features&&Y.sub_features.length>0){O.fillStyle=fe+"66",O.fillRect(re,pe+M/2-1,ue,2);for(const ae of Y.sub_features){const ie=(ae.start-l.start)/G*t,te=Math.max(1,(ae.end-ae.start)/G*t),ge=_c(ae.feature_type,e,u),_e=ae.feature_type==="CDS"?M:M-6,ye=ae.feature_type==="CDS"?pe:pe+3;g?Pc(O,ge,ie,ye,te,_e,ae.strand||Y.strand):(O.fillStyle=ge,O.fillRect(ie,ye,te,_e))}}else g?Pc(O,fe,re,pe,ue,M,Y.strand):(O.fillStyle=fe,O.fillRect(re,pe,ue,M));if(B){const ae=Math.max(Y.start,l.start),ie=Math.min(Y.end,l.end);for(let te=ae;te<ie;te++)if(f&&te>=f.start&&te<f.end){const ge=(f.sequence[te-f.start]||"").toUpperCase(),_e=(te-l.start)/G*t,ye=F;ye>=6&&(O.fillStyle=jc[ge]||"#999",O.font=`bold ${Math.min(10,ye-1)}px monospace`,O.textAlign="center",O.textBaseline="middle",O.fillText(ge,_e+ye/2,pe+M/2))}}else if(ue>20){O.fillStyle="#fff",O.font="10px Arial, Helvetica, sans-serif",O.textAlign="left",O.textBaseline="alphabetic";const ae=Y.name||Y.feature_type,ie=Math.floor((ue-(g?Tp:0)-4)/6);ie>0&&O.fillText(ae.slice(0,ie),re+3,pe+M-4)}A.push({feat:Y,x:re,y:pe,w:ue,h:M})}v.current=A,r&&r(R>0?`${R} feature${R>1?"s":""} hidden — increase track height to show all`:null)},[c,h,d,t,n,l,f,e.color,e.annotationColors,g,e.showNucleotides,u]);const w=C.useCallback(j=>{const U=o.current;if(!U)return;const O=U.getBoundingClientRect(),G=(j.clientX-O.left)*(t/O.width),F=(j.clientY-O.top)*(n/O.height);for(const B of v.current)if(G>=B.x&&G<=B.x+B.w&&F>=B.y&&F<=B.y+B.h){const M=Math.min(j.clientX+14,window.innerWidth-300),I=Math.min(j.clientY+14,window.innerHeight-260);x({feat:B.feat,x:Math.max(4,M),y:Math.max(4,I)});return}x(null)},[t,n]),S=C.useCallback(()=>x(null),[]),E=C.useCallback(j=>{const U=o.current;if(!U||!l)return;const O=U.getBoundingClientRect(),G=(j.clientX-O.left)*(t/O.width),F=(j.clientY-O.top)*(n/O.height);for(const B of v.current)if(G>=B.x&&G<=B.x+B.w&&F>=B.y&&F<=B.y+B.h){const M=B.feat,A=(M.end-M.start)*.15/(1-.3),R=M.start-A,k=M.end+A;i(l.chrom,R,k),x(null);return}},[t,n,l,i]),b=y?zy(y.feat,s,l==null?void 0:l.chrom):[],P=y?Dn.createPortal(a.jsxs("div",{style:{position:"fixed",left:y.x,top:y.y,background:u.tooltipBg,border:`1px solid ${u.tooltipBorder}`,borderRadius:4,padding:"6px 10px",color:u.textPrimary,fontSize:11,lineHeight:1.5,maxWidth:280,zIndex:1e4,pointerEvents:"none",boxShadow:"0 4px 12px rgba(0,0,0,0.5)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:[a.jsx("div",{style:{fontWeight:700,fontSize:12,marginBottom:2},children:y.feat.name||y.feat.feature_type}),a.jsx(Jt,{label:"Type",value:y.feat.feature_type}),a.jsx(Jt,{label:"Strand",value:y.feat.strand||"."}),a.jsx(Jt,{label:"Location",value:`${y.feat.start.toLocaleString()}–${y.feat.end.toLocaleString()}`}),a.jsx(Jt,{label:"Length",value:`${(y.feat.end-y.feat.start).toLocaleString()} bp`}),((N=y.feat.attributes)==null?void 0:N.gene)&&y.feat.attributes.gene!==y.feat.name&&a.jsx(Jt,{label:"Gene",value:y.feat.attributes.gene}),(($=y.feat.attributes)==null?void 0:$.locus_tag)&&a.jsx(Jt,{label:"Locus",value:y.feat.attributes.locus_tag}),((_=y.feat.attributes)==null?void 0:_.product)&&a.jsx(Jt,{label:"Product",value:y.feat.attributes.product}),((H=y.feat.attributes)==null?void 0:H.note)&&a.jsx(Jt,{label:"Note",value:String(y.feat.attributes.note).slice(0,120)}),b.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("div",{style:{borderTop:`1px solid ${u.tooltipBorder}`,margin:"4px 0",paddingTop:4},children:a.jsx("span",{style:{color:u.textSecondary,fontWeight:600,fontSize:10,textTransform:"uppercase"},children:"Track totals in gene"})}),b.map(j=>a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:8},children:[a.jsx("span",{style:{color:u.textSecondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:j.name}),a.jsx("span",{style:{color:u.textPrimary,fontWeight:600,flexShrink:0},children:j.total.toFixed(1)})]},j.trackId))]})]}),document.body):null;return a.jsxs("div",{style:{position:"relative",width:"100%",height:n},children:[a.jsx("canvas",{ref:o,style:{display:"block",width:"100%",height:n},onMouseMove:w,onMouseLeave:S,onDoubleClick:E}),P]})}function Jt({label:e,value:t}){return t?a.jsxs("div",{style:{display:"flex",gap:6},children:[a.jsxs("span",{style:{opacity:.6,flexShrink:0},children:[e,":"]}),a.jsx("span",{children:t})]}):null}function zy(e,t,n){var o;if(!e||!n)return[];const r=[];for(const l of t){if(l.track_type!=="coverage"&&l.track_type!=="reads")continue;const i=Z0(l.id,n);if(!((o=i==null?void 0:i.bins)!=null&&o.length))continue;let s=0;for(const u of i.bins){if(u.end<=e.start||u.start>=e.end)continue;const c=u.forward!=null?u.forward:Math.max(0,u.value||0),h=u.reverse!=null?Math.abs(u.reverse):Math.abs(Math.min(0,u.value||0));s+=c+h}s>0&&r.push({trackId:l.id,name:l.name,total:s})}return r}function Pc(e,t,n,r,o,l,i){e.fillStyle=t;const s=Math.min(Tp,o*.4);e.beginPath(),i==="+"?(e.moveTo(n,r),e.lineTo(n+o-s,r),e.lineTo(n+o,r+l/2),e.lineTo(n+o-s,r+l),e.lineTo(n,r+l),e.closePath()):i==="-"?(e.moveTo(n+s,r),e.lineTo(n+o,r),e.lineTo(n+o,r+l),e.lineTo(n+s,r+l),e.lineTo(n,r+l/2),e.closePath()):e.rect(n,r,o,l),e.fill(),e.strokeStyle="rgba(0,0,0,0.25)",e.lineWidth=.5,e.stroke()}function _c(e,t,n){const r=t.annotationColors;switch(e==null?void 0:e.toLowerCase()){case"cds":return(r==null?void 0:r.cds)||(n==null?void 0:n.geneCds)||"#66bb6a";case"exon":return(r==null?void 0:r.exon)||(n==null?void 0:n.geneExon)||"#42a5f5";case"gene":return(r==null?void 0:r.gene)||(n==null?void 0:n.geneGene)||"#7e57c2";case"mrna":case"transcript":return(r==null?void 0:r.transcript)||(n==null?void 0:n.geneTranscript)||"#ab47bc";case"utr":case"3utr":case"5utr":return(r==null?void 0:r.utr)||(n==null?void 0:n.geneUtr)||"#26c6da";case"rrna":return(r==null?void 0:r.rrna)||(n==null?void 0:n.geneRrna)||"#ffa726";case"trna":return(r==null?void 0:r.trna)||(n==null?void 0:n.geneTrna)||"#ef5350";case"repeat_region":return(r==null?void 0:r.repeat)||(n==null?void 0:n.geneRepeat)||"#8d6e63";default:return(r==null?void 0:r.default)||t.color||(n==null?void 0:n.geneDefault)||"#80cbc4"}}function $y({track:e,width:t,height:n,onWarning:r}){const o=C.useRef(null),{region:l}=it(),{theme:i}=Ye(),{data:s,loading:u}=Jl(e,l,t);return C.useEffect(()=>{var f,p;const c=o.current;if(!c)return;const h=window.devicePixelRatio||1;c.width=t*h,c.height=n*h;const d=c.getContext("2d");if(d.scale(h,h),d.clearRect(0,0,t,n),d.fillStyle=i.canvasBg,d.fillRect(0,0,t,n),u&&!((f=s==null?void 0:s.variants)!=null&&f.length)){d.fillStyle=i.textTertiary,d.font="11px Arial, Helvetica, sans-serif",d.fillText("Loading…",8,n/2+4),r&&r(null);return}if(!((p=s==null?void 0:s.variants)!=null&&p.length)){s&&(d.fillStyle=i.textTertiary,d.font="11px Arial, Helvetica, sans-serif",d.fillText("No variants in region",8,n/2+4)),r&&r(null);return}const g=l.end-l.start,T=e.barAutoWidth!==!1,v=e.barWidth||2,y=T?1:Math.max(.5,v),x=T?5:Math.max(2,v*2);for(const m of s.variants){const w=(m.pos-l.start)/g*t,S=Ny(m.ref,m.alt);d.strokeStyle=S,d.lineWidth=y,d.beginPath(),d.moveTo(w,n-4),d.lineTo(w,14),d.stroke(),d.fillStyle=S,d.beginPath(),d.arc(w,10,x,0,Math.PI*2),d.fill(),g<5e3&&(d.fillStyle=i.textPrimary,d.font="9px Arial, Helvetica, sans-serif",d.textAlign="center",d.fillText(`${m.ref}>${m.alt[0]||"?"}`,w,n-6))}if(r){const m=s.variants.filter(w=>w.pos>=l.start&&w.pos<=l.end).length;r(m>50?`${m} variants overlapping — zoom in for detail`:null)}},[s,u,t,n,l,e.color,e.barAutoWidth,e.barWidth,i]),a.jsx("canvas",{ref:o,style:{display:"block",width:"100%",height:n}})}function Ny(e,t){const n=t[0]||"";return e.length===1&&n.length===1?"#ffb74d":n.length>e.length?"#81c784":n.length<e.length?"#e57373":"#b0bec5"}function Oy({message:e,theme:t}){const[n,r]=C.useState(!1),o=C.useRef(null),l=o.current?o.current.getBoundingClientRect():null;return a.jsxs(a.Fragment,{children:[a.jsx("span",{ref:o,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:12,height:12,borderRadius:"50%",background:"rgba(229, 57, 53, 0.85)",color:"#fff",fontSize:9,fontWeight:800,lineHeight:1,cursor:"default",flexShrink:0,fontFamily:"Arial, Helvetica, sans-serif"},children:"!"}),n&&l&&Dn.createPortal(a.jsx("div",{style:{position:"fixed",left:Math.min(l.right+6,window.innerWidth-220),top:l.top-4,background:t.tooltipBg||"#333",border:`1px solid ${t.tooltipBorder||"#555"}`,borderRadius:4,padding:"4px 8px",color:t.textPrimary||"#e0e0e0",fontSize:11,lineHeight:1.4,maxWidth:200,zIndex:10001,pointerEvents:"none",boxShadow:"0 3px 10px rgba(0,0,0,0.5)",whiteSpace:"pre-wrap",fontFamily:"Arial, Helvetica, sans-serif"},children:e}),document.body)]})}function Fy({width:e,height:t,trackData:n,trackType:r}){const{region:o,selection:l,clearSelection:i}=it(),{theme:s}=Ye(),[u,c]=C.useState(!1),[h,d]=C.useState({x:0,y:0}),g=C.useRef(null),T=C.useCallback($=>{d({x:$.clientX,y:$.clientY}),c(!0)},[]),v=C.useCallback(()=>c(!1),[]);if(!l||!o||l.chrom!==o.chrom)return null;const y=o.end-o.start;if(y<=0)return null;const x=(l.start-o.start)/y,f=(l.end-o.start)/y,p=Math.max(0,x*e),w=Math.min(e,f*e)-p;if(w<1)return null;const S=Iy(l,n,r),E=l.end-l.start,b=260,P=Math.min(h.x+14,window.innerWidth-b-10),N=Math.min(h.y+14,window.innerHeight-200);return a.jsxs("div",{ref:g,style:{position:"absolute",top:0,left:0,width:e,height:t,pointerEvents:"none"},children:[a.jsx("div",{style:{position:"absolute",left:p,top:0,width:w,height:"100%",background:"rgba(100, 181, 246, 0.2)",borderLeft:"1px solid rgba(100, 181, 246, 0.6)",borderRight:"1px solid rgba(100, 181, 246, 0.6)",pointerEvents:"auto",cursor:"crosshair"},onMouseMove:T,onMouseLeave:v,onClick:$=>{$.stopPropagation(),i()}}),u&&Dn.createPortal(a.jsxs("div",{style:{position:"fixed",left:P,top:N,background:s.panelBg,border:`1px solid ${s.borderAccent}`,borderRadius:6,padding:"8px 12px",fontSize:11,color:s.textPrimary,lineHeight:1.6,pointerEvents:"none",zIndex:1e4,boxShadow:"0 4px 16px rgba(0,0,0,0.4)",minWidth:180,maxWidth:b},children:[a.jsx("div",{style:{fontWeight:700,marginBottom:4,fontSize:12},children:"Selected Region"}),a.jsxs("div",{children:[a.jsx("span",{style:{color:s.textSecondary},children:"Region:"})," ",l.chrom,":",l.start.toLocaleString(),"-",l.end.toLocaleString()]}),a.jsxs("div",{children:[a.jsx("span",{style:{color:s.textSecondary},children:"Length:"})," ",E.toLocaleString()," bp"]}),S.map(($,_)=>a.jsxs("div",{children:[a.jsxs("span",{style:{color:s.textSecondary},children:[$.label,":"]})," ",$.value]},_)),a.jsx("div",{style:{fontSize:9,color:s.textTertiary,marginTop:4},children:"Click to dismiss"})]}),document.body)]})}function Iy(e,t,n){const r=[];if(!t)return r;if(n==="reads"&&t.reads){const o=t.reads.filter(i=>i.end>e.start&&i.start<e.end);r.push({label:"Reads in region",value:o.length.toLocaleString()});let l=0;for(const i of o)if(i.cigar){const s=i.cigar.match(/(\d+)I/g);if(s)for(const u of s)l+=parseInt(u)}if(l>0&&r.push({label:"Insertion bases",value:l.toLocaleString()}),o.length>0){const i=o.reduce((s,u)=>s+(u.mapq||0),0)/o.length;r.push({label:"Avg MAPQ",value:i.toFixed(1)})}}if((n==="coverage"||n==="reads")&&t.bins){const o=t.bins.filter(l=>l.end>e.start&&l.start<e.end);if(o.length>0){const l=o.map(c=>c.value),i=l.reduce((c,h)=>c+h,0)/l.length,s=Math.max(...l),u=Math.min(...l);r.push({label:"Avg coverage",value:i.toFixed(1)}),r.push({label:"Max coverage",value:s.toFixed(1)}),u!==s&&r.push({label:"Min coverage",value:u.toFixed(1)})}}if(n==="variants"&&t.variants){const o=t.variants.filter(l=>l.pos>=e.start&&l.pos<e.end);r.push({label:"Variants in region",value:o.length.toLocaleString()})}if((n==="annotations"||n==="genome_annotations")&&t.features){const o=t.features.filter(l=>l.end>e.start&&l.start<e.end);r.push({label:"Features in region",value:o.length.toLocaleString()})}return r}class Dy extends C.Component{constructor(t){super(t),this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}render(){var t;return this.state.hasError?a.jsxs("div",{style:{padding:8,color:"#ef9a9a",fontSize:11},children:["Track error: ",((t=this.state.error)==null?void 0:t.message)||"Unknown error"]}):this.props.children}}function Uy({track:e,containerWidth:t,labelWidth:n=140,onLabelResizeStart:r,isDragging:o,isDropTarget:l,onDragStart:i,onDragOver:s,onDrop:u,onDragEnd:c}){const{theme:h}=Ye(),{updateTrack:d,removeTrack:g}=Kt(),T=C.useRef(null),v=C.useRef(null),[y,x]=C.useState(!1),[f,p]=C.useState(!1),[m,w]=C.useState(null),S=C.useRef(null),E=C.useRef(null),b=e.track_type==="annotations"||e.track_type==="genome_annotations";Cp(T);const P=["#f44336","#ef5350","#e57373","#ff5722","#ff8a65","#ff9800","#ffa726","#ffb74d","#ffc107","#fff176","#4caf50","#66bb6a","#81c784","#aed581","#009688","#26c6da","#80cbc4","#2196f3","#42a5f5","#64b5f6","#7e57c2","#9575cd","#9c27b0","#ab47bc","#ce93d8","#e91e63","#f06292","#795548","#8d6e63","#607d8b","#78909c"],N=t-n,$={row:{display:"flex",borderBottom:`1px solid ${h.border}`,minHeight:40},label:{width:n,minWidth:n,background:h.panelBg,borderRight:`1px solid ${h.border}`,display:"flex",flexDirection:"column",justifyContent:"center",padding:"4px 8px",overflow:"hidden",position:"relative"},trackName:{fontSize:11,color:h.trackName,fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},trackType:{fontSize:10,color:h.textTertiary,marginTop:2},trackArea:{flex:1,overflow:"hidden",position:"relative"}},_=C.useCallback(j=>{j.preventDefault(),j.stopPropagation();const U=j.clientY,O=e.height;function G(B){const M=Math.max(30,Math.min(500,O+(B.clientY-U)));d(e.id,{height:M})}function F(){window.removeEventListener("mousemove",G),window.removeEventListener("mouseup",F),document.body.style.cursor="",document.body.style.userSelect=""}document.body.style.cursor="ns-resize",document.body.style.userSelect="none",window.addEventListener("mousemove",G),window.addEventListener("mouseup",F)},[e.id,e.height,d]);function H(){const j={track:e,width:N,height:e.height,onWarning:w};switch(e.track_type){case"reads":return a.jsx(jy,{...j});case"coverage":return a.jsx(ky,{...j});case"variants":return a.jsx($y,{...j});case"annotations":case"genome_annotations":return a.jsx(Ay,{...j});default:return a.jsx("div",{style:{padding:8,color:h.textTertiary,fontSize:11},children:"Unknown track type"})}}return a.jsxs("div",{style:{...$.row,height:e.height,position:"relative",opacity:o?.4:1,borderTop:l?"2px solid #888":void 0},onDragOver:j=>{j.preventDefault(),j.dataTransfer.dropEffect="move",s==null||s()},onDrop:j=>{j.preventDefault(),u==null||u()},onDragEnd:c,children:[a.jsxs("div",{style:$.label,children:[a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[a.jsx("div",{draggable:!0,onDragStart:j=>{j.dataTransfer.effectAllowed="move",j.dataTransfer.setData("text/plain",e.id),i==null||i()},style:{cursor:"grab",color:h.textMuted,fontSize:14,lineHeight:1,userSelect:"none",flexShrink:0,padding:"0 2px"},title:"Drag to reorder tracks",children:"≡"}),a.jsx("div",{ref:S,children:b?a.jsxs(a.Fragment,{children:[a.jsx("span",{style:{display:"inline-block",width:10,height:10,borderRadius:2,background:"#888",cursor:"pointer",verticalAlign:"middle",border:"1px solid rgba(255,255,255,0.2)",backgroundImage:"linear-gradient(135deg, #ef5350 25%, #66bb6a 25%, #66bb6a 50%, #42a5f5 50%, #42a5f5 75%, #ffa726 75%)"},title:"Click to customize annotation colors",onMouseDown:j=>{j.stopPropagation(),p(U=>!U)}}),f&&Dn.createPortal(a.jsx(Gy,{track:e,theme:h,anchorRef:S,onClose:()=>p(!1),onChange:(j,U)=>{const O={...e.annotationColors||{},[j]:U};d(e.id,{annotationColors:O})},onReset:()=>d(e.id,{annotationColors:null})}),document.body)]}):a.jsxs(a.Fragment,{children:[a.jsx("span",{style:{display:"inline-block",width:10,height:10,borderRadius:2,background:e.color,cursor:"pointer",verticalAlign:"middle",border:"1px solid rgba(255,255,255,0.2)"},title:"Click to pick color, double-click for full palette",onMouseDown:j=>{j.stopPropagation(),x(!0)},onDoubleClick:j=>{var U;j.stopPropagation(),x(!1),(U=E.current)==null||U.click()}}),a.jsx("input",{ref:E,type:"color",value:e.color||"#78909c",onChange:j=>d(e.id,{color:j.target.value}),style:{position:"absolute",left:-9999,top:-9999,opacity:0,width:0,height:0}}),y&&Dn.createPortal(a.jsx("div",{style:{position:"fixed",left:S.current?S.current.getBoundingClientRect().left:0,top:S.current?S.current.getBoundingClientRect().bottom+4:0,zIndex:10001,background:h.panelBg,border:`1px solid ${h.borderAccent}`,borderRadius:4,padding:6,boxShadow:"0 4px 12px rgba(0,0,0,0.5)",display:"grid",gridTemplateColumns:"repeat(5, 18px)",gap:3},onMouseLeave:()=>x(!1),children:P.map(j=>a.jsx("span",{style:{width:18,height:18,borderRadius:3,background:j,cursor:"pointer",border:j===e.color?`2px solid ${h.textPrimary}`:"1px solid rgba(255,255,255,0.15)",boxSizing:"border-box"},onMouseUp:()=>{d(e.id,{color:j}),x(!1)}},j))}),document.body)]})}),a.jsx("div",{style:{...$.trackName,flex:1},title:e.name,children:e.name}),a.jsx("span",{title:"Remove track",onClick:j=>{j.stopPropagation(),g(e.id)},style:{color:"#e53935",fontSize:13,fontWeight:700,cursor:"pointer",lineHeight:1,flexShrink:0,padding:"0 2px",opacity:.7,transition:"opacity 0.15s"},onMouseEnter:j=>j.currentTarget.style.opacity="1",onMouseLeave:j=>j.currentTarget.style.opacity="0.7",children:"×"})]}),a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[a.jsxs("div",{style:$.trackType,children:[e.file_format," · ",e.track_type]}),m&&a.jsx(Oy,{message:m,theme:h})]}),r&&a.jsx("div",{onMouseDown:r,style:{position:"absolute",right:-3,top:0,bottom:0,width:6,cursor:"ew-resize",zIndex:10},onMouseEnter:j=>j.currentTarget.style.background="rgba(255,255,255,0.15)",onMouseLeave:j=>j.currentTarget.style.background="transparent"})]}),a.jsxs("div",{style:$.trackArea,ref:T,children:[a.jsx(Dy,{children:H()}),a.jsx(Fy,{width:N,height:e.height,trackData:Sp(e.id),trackType:e.track_type})]}),a.jsx("div",{ref:v,onMouseDown:_,title:"Drag to resize track height",style:{position:"absolute",left:0,right:0,bottom:-2,height:5,cursor:"ns-resize",zIndex:10,background:"transparent"},onMouseEnter:j=>j.currentTarget.style.background="rgba(255,255,255,0.15)",onMouseLeave:j=>j.currentTarget.style.background="transparent"})]})}const Wy=[{key:"cds",label:"CDS"},{key:"exon",label:"Exon"},{key:"gene",label:"Gene"},{key:"transcript",label:"Transcript"},{key:"utr",label:"UTR"},{key:"rrna",label:"rRNA"},{key:"trna",label:"tRNA"},{key:"repeat",label:"Repeat"},{key:"default",label:"Other"}],Hy=["#f44336","#ef5350","#e57373","#ff5722","#ff8a65","#ff9800","#ffa726","#ffb74d","#ffc107","#fff176","#4caf50","#66bb6a","#81c784","#aed581","#009688","#26c6da","#80cbc4","#2196f3","#42a5f5","#64b5f6","#7e57c2","#9575cd","#9c27b0","#ab47bc","#ce93d8","#e91e63","#f06292","#795548","#8d6e63","#607d8b","#78909c"],Vy={cds:"geneCds",exon:"geneExon",gene:"geneGene",transcript:"geneTranscript",utr:"geneUtr",rrna:"geneRrna",trna:"geneTrna",repeat:"geneRepeat",default:"geneDefault"};function Gy({track:e,theme:t,anchorRef:n,onClose:r,onChange:o,onReset:l}){var d;const[i,s]=C.useState(null),u=e.annotationColors||{},c=(d=n.current)==null?void 0:d.getBoundingClientRect();function h(g){return u[g]||t[Vy[g]]||gp[g]}return a.jsxs("div",{style:{position:"fixed",left:c?Math.min(c.left,window.innerWidth-220):0,top:c?c.bottom+4:0,zIndex:10001,background:t.panelBg,border:`1px solid ${t.borderAccent}`,borderRadius:6,padding:"8px 0",boxShadow:"0 6px 20px rgba(0,0,0,0.5)",width:210,maxHeight:340,overflowY:"auto"},onMouseLeave:r,children:[a.jsx("div",{style:{fontSize:10,fontWeight:700,color:t.textSecondary,textTransform:"uppercase",letterSpacing:1,padding:"0 10px 6px",borderBottom:`1px solid ${t.border}`,marginBottom:4},children:"Annotation Colors"}),Wy.map(({key:g,label:T})=>{const v=h(g);return a.jsxs("div",{children:[a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 10px",cursor:"pointer",fontSize:11,color:t.textPrimary},onMouseEnter:y=>y.currentTarget.style.background=t.selectedRow,onMouseLeave:y=>y.currentTarget.style.background="transparent",onClick:()=>s(i===g?null:g),children:[a.jsx("span",{style:{display:"inline-block",width:14,height:14,borderRadius:3,background:v,border:"1px solid rgba(255,255,255,0.15)",flexShrink:0}}),a.jsx("span",{style:{flex:1},children:T}),a.jsx("span",{style:{fontSize:9,color:t.textTertiary},children:i===g?"▲":"▼"})]}),i===g&&a.jsx("div",{style:{padding:"4px 10px 6px 32px",display:"grid",gridTemplateColumns:"repeat(5, 18px)",gap:3},children:Hy.map(y=>a.jsx("span",{style:{width:18,height:18,borderRadius:3,background:y,cursor:"pointer",border:y===v?`2px solid ${t.textPrimary}`:"1px solid rgba(255,255,255,0.15)",boxSizing:"border-box"},onClick:()=>{o(g,y),s(null)}},y))})]},g)}),a.jsx("div",{style:{borderTop:`1px solid ${t.border}`,marginTop:4,paddingTop:4},children:a.jsx("div",{style:{padding:"4px 10px",fontSize:10,color:t.textTertiary,cursor:"pointer",textAlign:"center"},onMouseEnter:g=>{g.currentTarget.style.color=t.textPrimary},onMouseLeave:g=>{g.currentTarget.style.color=t.textTertiary},onClick:l,children:"Reset to defaults"})})]})}function Yy({labelWidth:e}){const{genome:t,region:n}=it(),{tracks:r}=Kt(),{theme:o,themeName:l,customTheme:i}=Ye(),[s,u]=C.useState(!1),[c,h]=C.useState(!1),d=!!t;C.useEffect(()=>{if(!d)return;function y(x){x.preventDefault(),x.returnValue=""}return window.addEventListener("beforeunload",y),()=>window.removeEventListener("beforeunload",y)},[d]),C.useEffect(()=>{if(!d)return;function y(x){(x.ctrlKey||x.metaKey)&&x.key==="w"&&(x.preventDefault(),u(!0))}return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[d]);const g=C.useCallback(()=>u(!1),[]),T=C.useCallback(()=>{window.onbeforeunload=null,window.close(),window.location.href="about:blank"},[]),v=C.useCallback(()=>{h(!0);try{const y=Na(t,n,r,l,i,e);Oa(y),kp(y)}catch{}h(!1),window.onbeforeunload=null,window.close(),window.location.href="about:blank"},[t,n,r,l,i,e]);return s?a.jsx("div",{style:{position:"fixed",inset:0,zIndex:1e4,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:g,children:a.jsxs("div",{style:{background:o.panelBg,border:`1px solid ${o.borderAccent}`,borderRadius:8,padding:"24px 28px",maxWidth:400,width:"90%",boxShadow:"0 8px 32px rgba(0,0,0,0.6)"},onClick:y=>y.stopPropagation(),children:[a.jsx("div",{style:{fontSize:16,fontWeight:700,color:o.textPrimary,marginBottom:8},children:"Leave BiNgo Genome Viewer?"}),a.jsxs("div",{style:{fontSize:12,color:o.textSecondary,lineHeight:1.7,marginBottom:20},children:["You have an active session with"," ",a.jsxs("strong",{style:{color:o.textPrimary},children:[r.length," track",r.length!==1?"s":""]})," loaded. Unsaved changes will be lost."]}),a.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[a.jsx("button",{onClick:g,style:{background:"#1976d2",border:"none",borderRadius:4,color:"#fff",padding:"8px 16px",cursor:"pointer",fontSize:13,fontWeight:600,width:"100%"},children:"Return to App"}),a.jsx("button",{onClick:v,disabled:c,style:{background:o.btnBg,border:`1px solid ${o.borderStrong}`,borderRadius:4,color:o.btnText,padding:"8px 16px",cursor:"pointer",fontSize:13,fontWeight:600,width:"100%"},children:c?"Saving...":"Save Session & Exit"}),a.jsx("button",{onClick:T,style:{background:"transparent",border:`1px solid ${o.border}`,borderRadius:4,color:"#e57373",padding:"8px 16px",cursor:"pointer",fontSize:13,fontWeight:600,width:"100%"},children:"Exit Without Saving"})]})]})}):null}const Lc="2.2.6";let Qy=0;function Mc({size:e=32}){const[t]=Is.useState(()=>`blogo${++Qy}`);return a.jsxs("svg",{width:e,height:e,viewBox:"0 0 100 100",style:{flexShrink:0},xmlns:"http://www.w3.org/2000/svg",children:[a.jsxs("defs",{children:[a.jsxs("radialGradient",{id:`${t}_bg`,cx:"35%",cy:"30%",r:"65%",children:[a.jsx("stop",{offset:"0%",stopColor:"#5eb8ff"}),a.jsx("stop",{offset:"50%",stopColor:"#1976d2"}),a.jsx("stop",{offset:"100%",stopColor:"#0d47a1"})]}),a.jsxs("radialGradient",{id:`${t}_sh`,cx:"30%",cy:"25%",r:"30%",children:[a.jsx("stop",{offset:"0%",stopColor:"#ffffff",stopOpacity:"0.7"}),a.jsx("stop",{offset:"100%",stopColor:"#ffffff",stopOpacity:"0"})]})]}),a.jsx("circle",{cx:"50",cy:"50",r:"48",fill:`url(#${t}_bg)`}),a.jsx("circle",{cx:"50",cy:"48",r:"28",fill:"white"}),a.jsx("circle",{cx:"50",cy:"48",r:"28",fill:"none",stroke:"#1565c0",strokeWidth:"2.5"}),a.jsx("text",{x:"50",y:"39",textAnchor:"middle",fontSize:"13",fontWeight:"800",fontFamily:"Arial, sans-serif",fill:"#0d47a1",children:"BN"}),a.jsx("text",{x:"50",y:"64",textAnchor:"middle",fontSize:"30",fontWeight:"900",fontFamily:"Arial, sans-serif",fill:"#0d47a1",children:"1"}),a.jsx("circle",{cx:"50",cy:"50",r:"48",fill:`url(#${t}_sh)`})]})}function Xy({theme:e,labelWidth:t}){return a.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${e.border}`,height:60,opacity:.45},children:[a.jsx("div",{"data-tour":"skeleton-track-label",style:{width:t,minWidth:t,background:e.panelBg,borderRight:`1px solid ${e.border}`,padding:"6px 8px",display:"flex",flexDirection:"column",justifyContent:"center",gap:4},children:a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[a.jsx("span",{style:{fontSize:14,color:e.textTertiary,userSelect:"none",lineHeight:1},children:"≡"}),a.jsx("span",{style:{width:10,height:10,borderRadius:2,background:"#78909c",flexShrink:0}}),a.jsx("span",{style:{fontSize:11,fontWeight:600,color:e.textSecondary,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"Track Name"}),a.jsx("span",{style:{fontSize:13,color:e.textTertiary,lineHeight:1,padding:"0 2px"},children:"×"})]})}),a.jsx("div",{style:{flex:1,background:e.canvasBg}})]})}function Ky(){const{theme:e}=Ye(),{genome:t,region:n,setGenome:r,navigateTo:o}=it(),{tracks:l,reorderTracks:i,addTrack:s,uploadTrack:u,commitTrack:c,discardTrack:h,addGenomeAnnotationTrack:d,restoreAnnotationTracks:g}=Kt(),T=C.useRef(null),[v,y]=C.useState(800),[x,f]=C.useState(!1),[p,m]=C.useState(!1),[w,S]=C.useState(!1),[E,b]=C.useState(!1),[P,N]=C.useState(!1),[$,_]=C.useState(!1),[H,j]=C.useState(140),[U,O]=C.useState(null),[G,F]=C.useState(null),[B,M]=C.useState(!1),[I,A]=C.useState(null),[R,k]=C.useState(null),[D,Y]=C.useState(null),K=C.useRef(0);my(H),C.useEffect(()=>{const z=()=>fetch("/api/heartbeat").catch(()=>{});z();const q=setInterval(z,1e4);return()=>clearInterval(q)},[]);const re=C.useRef(n==null?void 0:n.chrom);C.useEffect(()=>{n!=null&&n.chrom&&n.chrom!==re.current&&(re.current=n.chrom,g())},[n==null?void 0:n.chrom,g]);const ue=new Set([".gb",".gbk",".genbank",".fasta",".fa"]),pe=new Set([".bam",".bw",".bigwig",".wig",".bedgraph",".bdg",".vcf",".bed",".gtf",".gff",".gff2",".gff3"]),fe=new Set([".bai"]);function ae(z){if(!z)return"";if(z.toLowerCase().endsWith(".vcf.gz"))return".vcf.gz";const q=z.lastIndexOf(".");return q>=0?z.slice(q).toLowerCase():""}const ie=C.useCallback(z=>{var q,Q;z.preventDefault(),z.stopPropagation(),(Q=(q=z.dataTransfer)==null?void 0:q.types)!=null&&Q.includes("Files")&&(K.current++,K.current===1&&M(!0))},[]),te=C.useCallback(z=>{var q,Q;z.preventDefault(),z.stopPropagation(),(Q=(q=z.dataTransfer)==null?void 0:q.types)!=null&&Q.includes("Files")&&(K.current--,K.current<=0&&(K.current=0,M(!1)))},[]),ge=C.useCallback(z=>{z.preventDefault(),z.stopPropagation()},[]);function _e(z){const q=z==null?void 0:z.compatibility;return q&&q.status!=="ok"&&q.status!=="no_genome"}const ye=C.useCallback(async z=>{var Oe,st,Fa,Ia,Da;if(z.preventDefault(),z.stopPropagation(),K.current=0,M(!1),!((st=(Oe=z.dataTransfer)==null?void 0:Oe.types)!=null&&st.includes("Files")))return;const q=Array.from(z.dataTransfer.files);if(!q.length)return;const Q=[],Z=[],le=[],oe=[];for(const Ee of q){const Le=ae(Ee.name),mt=Ee.name.toLowerCase();ue.has(Le)?Q.push(Ee):pe.has(Le)||Le===".vcf.gz"?Z.push(Ee):fe.has(Le)||mt.endsWith(".bam.bai")?le.push(Ee):oe.push(Ee)}const de=Z.filter(Ee=>Ee.name.toLowerCase().endsWith(".bam")&&Ee.size>50*1024*1024),xe=le.filter(Ee=>Ee.size>10*1024*1024);if(de.length||xe.length){const Ee=[...de,...xe].map(mt=>mt.name).join(", "),Le=[...de,...xe].reduce((mt,Co)=>mt+Co.size,0)/(1024*1024);A({error:`${Ee} (${Le.toFixed(0)} MB) — large files load faster via the Path button. Click 📂 Path in the toolbar and paste the file path instead of uploading.`}),setTimeout(()=>A(null),1e4);return}if(oe.length&&!Q.length&&!Z.length&&!le.length){A({error:`Unsupported file${oe.length>1?"s":""}: ${oe.map(Ee=>Ee.name).join(", ")}`}),setTimeout(()=>A(null),4e3);return}try{if(Q.length>0&&!t){A({msg:`Loading genome: ${Q[0].name}...`});const Le=(await mn.load(Q[0])).data;if(Le.name&&(Le.name=Nt(Le.name)),r(Le),((Fa=Le.chromosomes)==null?void 0:Fa.length)>0){const mt=Le.chromosomes[0];o(mt.name,0,Math.min(mt.length,5e4))}Le.is_annotated&&d({id:"genome_annotations",name:`${Le.name} (annotations)`,track_type:"genome_annotations",file_format:"genbank",targetChromosomes:Le.annotated_chromosomes||null})}else Q.length>0&&t&&k({files:Q});if(Z.length>0){if(!t&&Q.length===0){A({error:"Load a genome file first (.fasta, .gb, .genbank)"}),setTimeout(()=>A(null),4e3);return}A({msg:`Loading ${Z.length} track${Z.length>1?"s":""}...`});const Ee=[],Le=[],mt=[];for(const Co of Z)try{const Sn=await u(Co,void 0);_e(Sn)?Le.push(Sn):(c(Sn),Ee.push(Sn))}catch(Sn){mt.push(`${Co.name}: ${((Da=(Ia=Sn.response)==null?void 0:Ia.data)==null?void 0:Da.detail)||Sn.message}`)}if(mt.length){A({error:mt.join("; ")}),setTimeout(()=>A(null),5e3);return}Le.length>0&&Y({tracks:Le})}oe.length?(A({error:`Skipped unsupported: ${oe.map(Ee=>Ee.name).join(", ")}`}),setTimeout(()=>A(null),4e3)):(A({msg:"Files loaded"}),setTimeout(()=>A(null),2e3))}catch(Ee){A({error:Ee.message||"Drop failed"}),setTimeout(()=>A(null),5e3)}},[t,r,o,s,d]),Ne=C.useCallback(async()=>{var q,Q;if(!R)return;const z=R.files;k(null);try{const Z=[];for(const le of z){A({msg:`Adding chromosomes from ${le.name}...`});try{const de=(await mn.addChromosomes(le)).data;de.name&&(de.name=Nt(de.name)),r(de),de.is_annotated&&d({id:"genome_annotations",name:`${de.name} (annotations)`,track_type:"genome_annotations",file_format:"genbank",targetChromosomes:de.annotated_chromosomes||null})}catch(oe){Z.push(`${le.name}: ${((Q=(q=oe.response)==null?void 0:q.data)==null?void 0:Q.detail)||oe.message}`)}}Z.length?(A({error:Z.join("; ")}),setTimeout(()=>A(null),5e3)):(A({msg:`Added chromosomes from ${z.length} file${z.length>1?"s":""}`}),setTimeout(()=>A(null),3e3))}catch(Z){A({error:Z.message||"Failed to add chromosomes"}),setTimeout(()=>A(null),5e3)}},[R,r,d]),Je=C.useCallback(async()=>{var q,Q;if(!R)return;const z=R.files;k(null);try{A({msg:`Loading ${z.length} track${z.length>1?"s":""}...`});const Z=[];for(const le of z)try{await s(le,void 0)}catch(oe){Z.push(`${le.name}: ${((Q=(q=oe.response)==null?void 0:q.data)==null?void 0:Q.detail)||oe.message}`)}Z.length?(A({error:Z.join("; ")}),setTimeout(()=>A(null),5e3)):(A({msg:`Added ${z.length} track${z.length>1?"s":""}`}),setTimeout(()=>A(null),3e3))}catch(Z){A({error:Z.message||"Failed to load tracks"}),setTimeout(()=>A(null),5e3)}},[R,s]),he=C.useCallback(async()=>{if(D){for(const z of D.tracks)await h(z.id);Y(null)}},[D,h]),ht=C.useCallback(()=>{if(D){for(const z of D.tracks)c(z);Y(null),A({msg:`Added ${D.tracks.length} track${D.tracks.length>1?"s":""}`}),setTimeout(()=>A(null),3e3)}},[D,c]),V=C.useCallback(z=>{z.preventDefault();const q=z.clientX,Q=H;function Z(oe){j(Math.max(60,Math.min(400,Q+(oe.clientX-q))))}function le(){window.removeEventListener("mousemove",Z),window.removeEventListener("mouseup",le),document.body.style.cursor="",document.body.style.userSelect=""}document.body.style.cursor="ew-resize",document.body.style.userSelect="none",window.addEventListener("mousemove",Z),window.addEventListener("mouseup",le)},[H]);C.useEffect(()=>{if(!T.current)return;const z=new ResizeObserver(q=>{for(const Q of q)y(Q.contentRect.width)});return z.observe(T.current),()=>z.disconnect()},[]);const J=C.useCallback(z=>z.visible?!z.targetChromosomes||!(n!=null&&n.chrom)?!0:z.targetChromosomes.includes(n.chrom):!1,[n==null?void 0:n.chrom]),ee={app:{display:"flex",flexDirection:"column",height:"100vh",background:e.appBg,color:e.textPrimary},header:{background:e.headerBg,borderBottom:`2px solid ${e.borderAccent}`,padding:"8px 16px",display:"flex",alignItems:"center",justifyContent:"space-between"},headerLeft:{display:"flex",alignItems:"center",gap:12},title:{fontSize:18,fontWeight:700,color:e.textPrimary,letterSpacing:1},subtitle:{fontSize:11,color:e.textTertiary},headerBtns:{display:"flex",gap:8},btn:{background:e.btnBg,border:`1px solid ${e.borderStrong}`,borderRadius:4,color:e.btnText,padding:"5px 14px",cursor:"pointer",fontSize:12,fontWeight:600,display:"flex",alignItems:"center",gap:6},trackArea:{flex:1,overflowY:"auto",overflowX:"hidden",display:"flex",flexDirection:"column"},emptyState:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",flex:1,color:e.textMuted,gap:12},emptyTitle:{fontSize:22,fontWeight:300},emptyHint:{fontSize:13}};return a.jsxs("div",{style:ee.app,onDragEnter:ie,onDragLeave:te,onDragOver:ge,onDrop:ye,children:[a.jsxs("div",{style:ee.header,children:[a.jsxs("div",{style:ee.headerLeft,children:[a.jsx(Mc,{size:34}),a.jsxs("div",{children:[a.jsx("div",{style:ee.title,children:"BiNgo Genome Viewer"}),t&&a.jsxs("div",{style:ee.subtitle,children:[t.name," · ",t.chromosomes.length," chr"]})]}),a.jsxs("button",{onClick:()=>N(!0),title:"About / References",style:{background:"none",border:`1px solid ${e.border}`,borderRadius:10,padding:"2px 8px",display:"flex",alignItems:"center",gap:4,cursor:"pointer",color:e.textSecondary,fontSize:11,fontWeight:600,lineHeight:1,flexShrink:0},onMouseEnter:z=>{z.currentTarget.style.color=e.textPrimary,z.currentTarget.style.borderColor=e.textSecondary},onMouseLeave:z=>{z.currentTarget.style.color=e.textSecondary,z.currentTarget.style.borderColor=e.border},children:[a.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"currentColor",style:{flexShrink:0},children:[a.jsx("path",{d:"M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"}),a.jsx("circle",{cx:"8",cy:"4.5",r:"1.2"}),a.jsx("rect",{x:"7",y:"6.5",width:"2",height:"5.5",rx:"0.8"})]}),"Info"]}),a.jsxs("button",{onClick:()=>_(!0),title:"Guided Tour",style:{background:"none",border:`1px solid ${e.border}`,borderRadius:10,padding:"2px 8px",display:"flex",alignItems:"center",gap:4,cursor:"pointer",color:e.textSecondary,fontSize:11,fontWeight:600,lineHeight:1,flexShrink:0},onMouseEnter:z=>{z.currentTarget.style.color=e.textPrimary,z.currentTarget.style.borderColor=e.textSecondary},onMouseLeave:z=>{z.currentTarget.style.color=e.textSecondary,z.currentTarget.style.borderColor=e.border},children:[a.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"currentColor",style:{flexShrink:0},children:[a.jsx("path",{d:"M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"}),a.jsx("path",{d:"M5.255 5.786a.237.237 0 0 0 .241.247h.825c.138 0 .248-.113.266-.25.09-.656.54-1.134 1.342-1.134.686 0 1.314.343 1.314 1.168 0 .635-.374.927-.965 1.371-.673.489-1.206 1.06-1.168 1.987l.003.217a.25.25 0 0 0 .25.246h.811a.25.25 0 0 0 .25-.25v-.105c0-.718.273-.927 1.01-1.486.609-.463 1.244-.977 1.244-2.056 0-1.511-1.276-2.241-2.673-2.241-1.267 0-2.655.59-2.75 2.286zM8 13.5a1 1 0 1 0 0-2 1 1 0 0 0 0 2z"})]}),"Help"]})]}),a.jsxs("div",{style:ee.headerBtns,"data-tour":"header-btns",children:[a.jsxs("button",{style:ee.btn,onClick:()=>b(!0),title:"Save or restore a session",children:[a.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[a.jsx("path",{d:"M2 2h8v8H2z"}),a.jsx("path",{d:"M4 2v4h4V2"}),a.jsx("path",{d:"M5 3h2"})]}),"Save Session"]}),a.jsxs("button",{style:ee.btn,onClick:()=>m(!0),title:"Customize color theme",children:[a.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",style:{flexShrink:0},children:[a.jsx("rect",{x:"0",y:"0",width:"5.5",height:"5.5",rx:"1",fill:"#66bb6a"}),a.jsx("rect",{x:"6.5",y:"0",width:"5.5",height:"5.5",rx:"1",fill:"#42a5f5"}),a.jsx("rect",{x:"0",y:"6.5",width:"5.5",height:"5.5",rx:"1",fill:"#ffa726"}),a.jsx("rect",{x:"6.5",y:"6.5",width:"5.5",height:"5.5",rx:"1",fill:"#ab47bc"})]}),"Theme"]}),a.jsxs("button",{"data-tour":"btn-export",style:{...ee.btn,...n&&l.length>0?{}:{opacity:.35,cursor:"default"}},onClick:()=>{n&&l.length>0&&S(!0)},title:"Export current view as SVG or PNG",children:[a.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:a.jsx("path",{d:"M6 1v7M3 5.5L6 8.5 9 5.5M2 11h8"})}),"Export Image"]}),a.jsxs("button",{"data-tour":"btn-settings",style:{...ee.btn,...l.length===0?{opacity:.35,cursor:"default"}:{}},onClick:()=>{l.length>0&&f(!0)},title:"Adjust height, scale, color, and bar width for tracks",children:["⚙"," Track Settings"]})]})]}),a.jsx(O0,{}),a.jsx(wy,{}),a.jsxs("div",{style:ee.trackArea,ref:T,"data-tour":"track-area",children:[l.filter(J).length===0&&a.jsx(Xy,{theme:e,labelWidth:H}),t?n?a.jsxs(a.Fragment,{children:[a.jsxs("div",{style:{display:"flex"},children:[a.jsx("div",{style:{width:H,minWidth:H,background:e.panelBg,borderRight:`1px solid ${e.border}`,position:"relative"},children:a.jsx("div",{onMouseDown:V,style:{position:"absolute",right:-3,top:0,bottom:0,width:6,cursor:"ew-resize",zIndex:10},onMouseEnter:z=>z.currentTarget.style.background="rgba(255,255,255,0.15)",onMouseLeave:z=>z.currentTarget.style.background="transparent"})}),a.jsx(Sy,{width:v-H})]}),l.filter(J).map(z=>a.jsx(Uy,{track:z,containerWidth:v,labelWidth:H,onLabelResizeStart:V,isDragging:U===z.id,isDropTarget:G===z.id,onDragStart:()=>O(z.id),onDragOver:()=>F(z.id),onDrop:()=>{U&&U!==z.id&&i(U,z.id),O(null),F(null)},onDragEnd:()=>{O(null),F(null)}},z.id)),l.length===0&&a.jsx("div",{style:{padding:24,color:e.textMuted,fontSize:13},children:"Add tracks above — BAM, VCF, BigWig, BED, GTF, GFF, WIG..."})]}):a.jsx("div",{style:ee.emptyState,children:a.jsx("div",{style:ee.emptyHint,children:"Select a chromosome to begin"})}):a.jsxs("div",{style:ee.emptyState,children:[a.jsx("div",{style:ee.emptyTitle,children:"No genome loaded"}),a.jsx("div",{style:ee.emptyHint,children:"Load a FASTA or GenBank file above to get started"})]})]}),x&&a.jsx(U0,{onClose:()=>f(!1)}),p&&a.jsx(Y0,{onClose:()=>m(!1)}),w&&a.jsx(ny,{onClose:()=>S(!1)}),E&&a.jsx(gy,{onClose:()=>b(!1),labelWidth:H,setLabelWidth:j}),$&&a.jsx(vy,{onClose:()=>{_(!1),f(!1),m(!1)},theme:e,onAction:z=>{z==="open-settings"?(f(!0),m(!1)):z==="open-theme"?(m(!0),f(!1)):(f(!1),m(!1))}}),P&&a.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.6)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999},onClick:()=>N(!1),children:a.jsxs("div",{style:{background:e.panelBg,border:`1px solid ${e.border}`,borderRadius:8,padding:"28px 36px",maxWidth:520,maxHeight:"85vh",overflowY:"auto",color:e.textPrimary,lineHeight:1.7},onClick:z=>z.stopPropagation(),children:[a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:16},children:[a.jsx(Mc,{size:44}),a.jsx("div",{style:{fontSize:20,fontWeight:700},children:"BiNgo Genome Viewer"})]}),a.jsxs("div",{style:{fontSize:13,color:e.textSecondary,marginBottom:12},children:[a.jsx("strong",{style:{color:e.textPrimary},children:"Version:"})," ",Lc]}),a.jsxs("div",{style:{fontSize:13,color:e.textSecondary,marginBottom:12},children:[a.jsx("strong",{style:{color:e.textPrimary},children:"Publisher:"})," Billy M Ngo"]}),a.jsxs("div",{style:{fontSize:13,color:e.textSecondary,marginBottom:20},children:[a.jsx("strong",{style:{color:e.textPrimary},children:"Published:"})," April 2026"]}),a.jsxs("div",{style:{fontSize:12,color:e.textSecondary,background:e.canvasBg,border:`1px solid ${e.border}`,borderRadius:4,padding:"10px 14px",fontFamily:"monospace",lineHeight:1.6,marginBottom:20,userSelect:"all"},children:["Ngo, B.M. (2026). BiNgo Genome Viewer (v",Lc,") [Software]."]}),a.jsxs("details",{style:{marginBottom:20},children:[a.jsx("summary",{style:{cursor:"pointer",fontSize:13,fontWeight:600,color:e.textPrimary,marginBottom:8},children:"References & Acknowledgments"}),a.jsxs("div",{style:{fontSize:11,color:e.textSecondary,lineHeight:1.8,paddingTop:8},children:[a.jsx("div",{style:{fontWeight:600,color:e.textPrimary,marginBottom:4},children:"Software Dependencies"}),a.jsxs("div",{children:[a.jsx("strong",{children:"FastAPI"})," ","—"," Ram","í","rez, S. (2018). A modern web framework for building APIs with Python."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"Uvicorn"})," ","—"," Encode OSS. ASGI server implementation for Python."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"BioPython"})," ","—"," Cock, P.J.A. et al. (2009). ",a.jsx("em",{children:"Bioinformatics"}),", 25(11), 1422","–","1423."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"pyfaidx"})," ","—"," Shirley, M.D. et al. (2015). ",a.jsx("em",{children:"PeerJ PrePrints"}),", 3:e1196."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"bamnostic"})," ","—"," Sherman, M.A. & Mills, R.E. (2019). Pure Python BAM parser."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"React"})," ","—"," Meta Platforms, Inc. JavaScript UI library."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"Vite"})," ","—"," You, E. (2020). Next generation frontend tooling."]}),a.jsx("div",{style:{fontWeight:600,color:e.textPrimary,marginTop:12,marginBottom:4},children:"File Format Specifications"}),a.jsxs("div",{children:[a.jsx("strong",{children:"SAM/BAM"})," ","—"," Li, H. et al. (2009). ",a.jsx("em",{children:"Bioinformatics"}),", 25(16), 2078","–","2079."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"VCF"})," ","—"," Danecek, P. et al. (2011). ",a.jsx("em",{children:"Bioinformatics"}),", 27(15), 2156","–","2158."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"BigWig/WIG"})," ","—"," Kent, W.J. et al. (2010). ",a.jsx("em",{children:"Bioinformatics"}),", 26(17), 2204","–","2207."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"BED"})," ","—"," UCSC Genome Browser, UC Santa Cruz."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"GFF3"})," ","—"," Sequence Ontology Project."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"GTF"})," ","—"," Ensembl genome database project."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"GenBank"})," ","—"," Benson, D.A. et al. (2013). ",a.jsx("em",{children:"Nucleic Acids Res."}),", 41(D1), D36","–","D42."]}),a.jsx("div",{style:{fontWeight:600,color:e.textPrimary,marginTop:12,marginBottom:4},children:"Inspiration"}),a.jsxs("div",{children:[a.jsx("strong",{children:"IGV"})," ","—"," Robinson, J.T. et al. (2011). ",a.jsx("em",{children:"Nature Biotechnology"}),", 29(1), 24","–","26."]}),a.jsx("div",{style:{fontWeight:600,color:e.textPrimary,marginTop:12,marginBottom:4},children:"Acknowledgments"}),a.jsx("div",{children:"Early version testing and feedback:"}),a.jsx("div",{children:"Amanda Antoch, Isaac Poarch, Otto Chipashvili, Jake Colautti"})]})]}),a.jsx("div",{style:{textAlign:"right"},children:a.jsx("button",{onClick:()=>N(!1),style:{background:e.btnBg,border:`1px solid ${e.borderStrong}`,borderRadius:4,color:e.btnText,padding:"5px 18px",cursor:"pointer",fontSize:12,fontWeight:600},children:"Close"})})]})}),R&&(()=>{const z=R.files.length>1,q=R.files.map(Q=>Q.name).join(", ");return a.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.45)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999},children:a.jsxs("div",{style:{background:e.panelBg,border:`1px solid ${e.borderAccent}`,borderRadius:8,padding:"20px 24px",maxWidth:440,width:"90%",boxShadow:"0 8px 32px rgba(0,0,0,0.5)"},onClick:Q=>Q.stopPropagation(),children:[a.jsxs("div",{style:{fontSize:14,fontWeight:700,color:e.textPrimary,marginBottom:8},children:["Genome file",z?"s":""," detected"]}),a.jsxs("div",{style:{fontSize:12,color:e.textSecondary,lineHeight:1.6,marginBottom:16},children:[a.jsx("strong",{style:{color:e.textPrimary},children:q}),z?" appear to be genome files. A genome is already loaded.":" appears to be a genome file. A genome is already loaded.",a.jsx("br",{}),"How would you like to handle ",z?"them":"it","?"]}),a.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",flexWrap:"wrap"},children:[a.jsx("button",{onClick:()=>k(null),style:{background:e.btnBg,border:`1px solid ${e.borderStrong}`,borderRadius:4,color:e.btnText,padding:"5px 16px",cursor:"pointer",fontSize:12,fontWeight:600},children:"Skip"}),a.jsxs("button",{onClick:Je,style:{background:e.btnBg,border:`1px solid ${e.borderStrong}`,borderRadius:4,color:e.btnText,padding:"5px 16px",cursor:"pointer",fontSize:12,fontWeight:600},children:["Add as Track",z?"s":""]}),a.jsxs("button",{onClick:Ne,style:{background:"#1976d2",border:"none",borderRadius:4,color:"#fff",padding:"5px 16px",cursor:"pointer",fontSize:12,fontWeight:600},children:["Add as Chromosome",z?"s":""]})]})]})})})(),D&&a.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.45)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999},children:a.jsxs("div",{style:{background:e.panelBg,border:`1px solid ${e.borderAccent}`,borderRadius:8,padding:"20px 24px",maxWidth:480,width:"90%",boxShadow:"0 8px 32px rgba(0,0,0,0.5)"},onClick:z=>z.stopPropagation(),children:[a.jsx("div",{style:{fontSize:14,fontWeight:700,color:e.textPrimary,marginBottom:8},children:"Track compatibility warning"}),a.jsxs("div",{style:{fontSize:12,color:e.textSecondary,lineHeight:1.6,marginBottom:16},children:[D.tracks.map(z=>{var q;return a.jsxs("div",{style:{marginBottom:6},children:[a.jsx("strong",{style:{color:e.textPrimary},children:z.name})," — ",((q=z.compatibility)==null?void 0:q.message)||"Possible mismatch with loaded genome"]},z.id)}),a.jsx("div",{style:{marginTop:8},children:D.tracks.length>1?"These tracks may not match the loaded genome.":"This track may not match the loaded genome."})]}),a.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",flexWrap:"wrap"},children:[a.jsx("button",{onClick:he,style:{background:e.btnBg,border:`1px solid ${e.borderStrong}`,borderRadius:4,color:e.btnText,padding:"5px 16px",cursor:"pointer",fontSize:12,fontWeight:600},children:"Skip"}),a.jsx("button",{onClick:ht,style:{background:"#1976d2",border:"none",borderRadius:4,color:"#fff",padding:"5px 16px",cursor:"pointer",fontSize:12,fontWeight:600},children:"Load Anyway"})]})]})}),B&&a.jsx("div",{style:{position:"fixed",inset:0,zIndex:9998,background:"rgba(0,0,0,0.45)",display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none"},children:a.jsxs("div",{style:{border:`3px dashed ${e.textSecondary}`,borderRadius:16,padding:"40px 60px",textAlign:"center"},children:[a.jsx("div",{style:{fontSize:28,fontWeight:300,color:e.textPrimary,marginBottom:8},children:"Drop files here"}),a.jsx("div",{style:{fontSize:13,color:e.textSecondary},children:"Genome (.gb, .fasta) or track files (.bam, .bw, .wig, .vcf, .bed, .gff, .gtf)"})]})}),I&&a.jsx("div",{style:{position:"fixed",bottom:20,left:"50%",transform:"translateX(-50%)",zIndex:10001,padding:"8px 20px",borderRadius:6,background:I.error?"#c62828":e.panelBg,border:`1px solid ${I.error?"#e53935":e.borderAccent}`,color:I.error?"#fff":"#81c784",fontSize:12,fontWeight:600,boxShadow:"0 4px 16px rgba(0,0,0,0.5)"},children:I.error||I.msg}),t&&a.jsx(Yy,{labelWidth:H})]})}function qy(){return a.jsx(A0,{children:a.jsx(Jm,{children:a.jsx(L0,{children:a.jsx(Ky,{})})})})}Ni.createRoot(document.getElementById("root")).render(a.jsx(Is.StrictMode,{children:a.jsx(qy,{})}));
|
|
97
|
+
`):null)}},[s,u,c,t,n,l,e.color,e.scaleMax,e.scaleMin,e.logScale,e.barAutoWidth,e.barWidth,e.showOutline,e.outlineColor,e.outlineSmooth,e.showBars,i]),a.jsx("canvas",{ref:o,style:{display:"block",width:"100%",height:n}})}function Bi(e,t,n,r,o){if(!(t.length<2)){if(e.beginPath(),e.moveTo(t[0],n[0]),o){for(let l=0;l<t.length-1;l++){const i=(t[l]+t[l+1])/2,s=(n[l]+n[l+1])/2;e.quadraticCurveTo(t[l],n[l],i,s)}e.lineTo(t[t.length-1],n[n.length-1])}else for(let l=0;l<t.length;l++)e.lineTo(t[l],n[l]);e.strokeStyle=r,e.lineWidth=1.5,e.stroke()}}function Ar(e,t,n,r,o,l=!1){e.font="10px Arial, Helvetica, sans-serif",e.textAlign="left",e.textBaseline="top";const i=e.measureText(t),s=2,u=i.width+s*2,c=12;e.fillStyle=o.canvasBg||"#1e1e1e",e.globalAlpha=.75,e.fillRect(n,r,u,c),e.globalAlpha=1,e.fillStyle=l?o.textTertiary||"#666":o.textSecondary||"#aaa",e.fillText(t,n+s,r+1),e.textBaseline="alphabetic"}function Cy(e,t){const n=e.match(/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);if(!n)return e;const r=o=>Math.max(0,Math.min(255,o+t));return`rgb(${r(parseInt(n[1],16))},${r(parseInt(n[2],16))},${r(parseInt(n[3],16))})`}const Cc=6,Ai=8,zi=14,$i=2,Ty="#9c27b0",Wo=10,Ey={A:"#4caf50",T:"#f44336",C:"#2196f3",G:"#ff9800",N:"#9e9e9e"},Ry="#ffeb3b";function Tc(e,t){return e<=0||t<=0?0:Math.log2(e+1)/Math.log2(t+1)}function jy({track:e,width:t,height:n,onWarning:r}){const o=C.useRef(null),{region:l}=it(),{theme:i}=Ye(),{data:s,loading:u}=Jl(e,l,t),[c,h]=C.useState(null),d=C.useRef(null),[g,T]=C.useState(0),v=C.useRef(null),y=e.showNucleotides!==!1,x=e.useArrows!==!1,f=e.logScale===!0,p=e.fwdColor||"#90a4ae",m=e.revColor||"#f06292",w=e.arrowStyle||"pointed",S=e.arrowSize||4,E=C.useRef(null);C.useEffect(()=>{if(l&&E.current){const N=E.current;(N.chrom!==l.chrom||Math.abs(N.start-l.start)>N.end-N.start)&&T(0)}E.current=l},[l==null?void 0:l.chrom,l==null?void 0:l.start,l==null?void 0:l.end]),C.useEffect(()=>{if(!l||!y){h(null);return}const N=l.end-l.start;if(t/N<Cc||N>2e3){h(null);return}if(c&&c.chrom===l.chrom&&c.start<=l.start&&c.end>=l.end)return;const _=Math.max(0,l.start-500),H=l.end+500,j=`${l.chrom}:${_}-${H}`;d.current!==j&&(d.current=j,mn.sequence(l.chrom,_,H).then(U=>h({chrom:l.chrom,start:_,end:H,sequence:U.data.sequence})).catch(()=>{}))},[l==null?void 0:l.chrom,l==null?void 0:l.start,l==null?void 0:l.end,t,y]);const b=C.useCallback(N=>{var U;if(!((U=s==null?void 0:s.reads)!=null&&U.length)||!N.shiftKey&&Math.abs(N.deltaX)>Math.abs(N.deltaY))return;const $=y&&c?zi:Ai,_=Math.max(0,...s.reads.map(O=>O.row)),H=Math.floor(n/($+$i)),j=Math.max(0,_-H+2);j<=0||(N.preventDefault(),N.stopPropagation(),T(O=>Math.max(0,Math.min(j,O+Math.sign(N.deltaY)*3))))},[s,n,y,c]);C.useEffect(()=>{var Y;const N=o.current;if(!N)return;const $=window.devicePixelRatio||1;N.width=t*$,N.height=n*$;const _=N.getContext("2d");if(_.scale($,$),_.clearRect(0,0,t,n),_.fillStyle=i.canvasBg,_.fillRect(0,0,t,n),u&&!s){_.fillStyle=i.textTertiary,_.font="11px Arial, Helvetica, sans-serif",_.fillText("Loading…",8,n/2+4),r&&r(null);return}if(!s){r&&r(null);return}const H=l.start,j=l.end-l.start;if(s.bins){const K=s.max_value||1,re=e.scaleMax!=null?e.scaleMax:K,ue=e.color||"#78909c",pe=e.barAutoWidth!==!1,fe=e.barWidth||2,ae=t/j;if(e.showBars!==!1){_.fillStyle=ue;for(const te of s.bins){const ge=(te.end-te.start)/j*t,_e=pe?ae>=1?Math.max(1,Math.min(ae,ge)):Math.max(1,ge):Math.min(fe,ge),ye=(te.start-H)/j*t,Je=(f?Tc(te.value,re):Math.min(1,te.value/re))*(n-14);_.fillRect(ye,n-Je-2,_e,Je)}}if(e.showOutline&&s.bins.length>0){const te=e.outlineSmooth||0,ge=s.bins.map(he=>f?Tc(he.value,re):Math.min(1,he.value/re)),_e=_y(ge,te),ye=s.bins.map(he=>((he.start+he.end)/2-H)/j*t),Ne=_e.map(he=>n-he*(n-14)-2),Je=e.outlineColor||i.textPrimary||"#fff";if(_.beginPath(),_.moveTo(ye[0],Ne[0]),te>0){for(let he=0;he<ye.length-1;he++)_.quadraticCurveTo(ye[he],Ne[he],(ye[he]+ye[he+1])/2,(Ne[he]+Ne[he+1])/2);_.lineTo(ye[ye.length-1],Ne[Ne.length-1])}else for(let he=0;he<ye.length;he++)_.lineTo(ye[he],Ne[he]);_.strokeStyle=Je,_.lineWidth=1.5,_.stroke()}const ie=f?" log₂":"";Ec(_,`${re.toFixed(1)}${ie}`,2,2,i),Ec(_,"0",2,n-12,i,!0),_.fillStyle="#ffb74d",_.font="10px Arial, Helvetica, sans-serif",_.textAlign="right",_.fillText("zoom in for reads",t-4,10),r&&r(e.scaleMax!=null&&K>e.scaleMax?`Bars clipped: max value ${K.toFixed(1)} exceeds scale ${e.scaleMax.toFixed(1)}`:null);return}if(!((Y=s.reads)!=null&&Y.length)){_.fillStyle=i.textTertiary,_.font="11px Arial, Helvetica, sans-serif",_.fillText("No reads in region",8,n/2+4),r&&r(null);return}const U=K=>(K-H)/j*t,O=t/j,G=y&&O>=Cc&&c!=null,F=G?zi:Ai,B=$i,I=Math.max(0,...s.reads.map(K=>K.row))+1,A=Math.floor(n/(F+B)),R=I>A,k=Math.min(g,Math.max(0,I-A+1));let D=0;for(const K of s.reads){const re=(K.row-k)*(F+B)+2;if(re+F<0||re>n){D++;continue}const ue=K.strand==="+"?p:m,pe=K.segments;if(pe&&pe.length>0){const fe=U(K.start),ae=U(K.end);_.strokeStyle=ue,_.lineWidth=1,_.beginPath(),_.moveTo(fe,re+F/2),_.lineTo(ae,re+F/2),_.stroke();let ie=0;for(const te of pe)if(te.type==="M"){const ge=U(te.start),_e=Math.max(1,U(te.end)-ge);if(_.fillStyle=ue,_.fillRect(ge,re,_e,F),G&&K.sequence){const ye=te.end-te.start;for(let Ne=0;Ne<ye;Ne++){const Je=te.start+Ne,he=U(Je),ht=U(Je+1)-he,V=(K.sequence[ie+Ne]||"").toUpperCase();let J="";c&&Je>=c.start&&Je<c.end&&(J=(c.sequence[Je-c.start]||"").toUpperCase());const ee=J&&V&&V!==J&&V!=="N";ee&&(_.fillStyle=Ry,_.fillRect(he,re,ht,F)),ht>=6&&(_.fillStyle=ee?"#000":Ey[V]||"#999",_.font=`bold ${Math.min(11,ht-1)}px monospace`,_.textAlign="center",_.textBaseline="middle",_.fillText(V,he+ht/2,re+F/2))}ie+=ye}}else if(te.type==="D"){const ge=U(te.start),_e=U(te.end)-ge;_e>=1&&(_.strokeStyle=ue,_.lineWidth=1,_.beginPath(),_.moveTo(ge,re+F/2),_.lineTo(ge+_e,re+F/2),_.stroke())}else if(te.type==="N"){const ge=U(te.start),_e=U(te.end)-ge;_e>=2&&(_.setLineDash([2,2]),_.strokeStyle=ue,_.lineWidth=1,_.beginPath(),_.moveTo(ge,re+F/2),_.lineTo(ge+_e,re+F/2),_.stroke(),_.setLineDash([]))}else te.type==="I"?(_.fillStyle=Ty,_.fillRect(U(te.pos)-1,re-1,2,F+2),G&&(ie+=te.length)):te.type==="S"&&G&&(ie+=te.length)}else{const fe=U(K.start),ae=Math.max(2,U(K.end)-fe);_.fillStyle=K.strand==="+"?p:m,_.fillRect(fe,re,ae,F)}if(x&&w!=="flat"){const fe=U(K.start),ae=Math.max(2,U(K.end)-fe),ie=Math.min(S,ae/2);ie>=2&&Py(_,w,K.strand,fe,re,ae,F,ie,ue,i.canvasBg)}if(!G&&!y){const fe=U(K.start);Math.max(2,U(K.end)-fe)>60&&(_.fillStyle=i.canvasBg,_.font="8px Arial, Helvetica, sans-serif",_.textAlign="left",_.fillText(K.name.slice(0,20),fe+2,re+F-1))}}if(R){const K=t-Wo;_.fillStyle=i.inputBg||"#2a2a2a",_.fillRect(K,0,Wo,n);const re=A/I,ue=Math.max(20,re*n),fe=(I>A?k/(I-A):0)*(n-ue);_.fillStyle="#555",_.fillRect(K+1,fe,Wo-2,ue)}r&&(D>0&&!R?r(`${D} read${D>1?"s":""} hidden — increase track height to show all`):r(R?`${I} rows · Shift+scroll or drag scrollbar to navigate`:null))},[s,u,t,n,l,c,g,e.color,e.scaleMax,e.scaleMin,e.barAutoWidth,e.barWidth,e.showOutline,e.outlineColor,e.outlineSmooth,e.showBars,e.showNucleotides,e.useArrows,e.logScale,e.fwdColor,e.revColor,e.arrowStyle,e.arrowSize,i]);const P=C.useCallback(N=>{var I;if(!((I=s==null?void 0:s.reads)!=null&&I.length))return;const $=o.current;if(!$)return;const _=$.getBoundingClientRect();if((N.clientX-_.left)*(t/_.width)<t-Wo)return;const j=y&&c?zi:Ai,O=Math.max(0,...s.reads.map(A=>A.row))+1,G=Math.floor(n/(j+$i)),F=Math.max(0,O-G+1);if(F<=0)return;N.preventDefault(),v.current={maxScroll:F,startY:N.clientY,startRow:g};function B(A){if(!v.current)return;const R=A.clientY-v.current.startY,k=Math.round(R/n*v.current.maxScroll);T(Math.max(0,Math.min(v.current.maxScroll,v.current.startRow+k)))}function M(){v.current=null,window.removeEventListener("mousemove",B),window.removeEventListener("mouseup",M)}window.addEventListener("mousemove",B),window.addEventListener("mouseup",M)},[s,t,n,g,y,c]);return a.jsx("canvas",{ref:o,style:{display:"block",width:"100%",height:n},onWheel:b,onMouseDown:P})}function Py(e,t,n,r,o,l,i,s,u,c){const h=n==="+";if(t==="pointed")e.fillStyle=c,h?(e.beginPath(),e.moveTo(r+l,o+i/2),e.lineTo(r+l-s,o),e.lineTo(r+l-s,o+i),e.fill()):(e.beginPath(),e.moveTo(r,o+i/2),e.lineTo(r+s,o),e.lineTo(r+s,o+i),e.fill());else if(t==="chevron")e.strokeStyle=c,e.lineWidth=1.5,h?(e.beginPath(),e.moveTo(r+l-s,o),e.lineTo(r+l,o+i/2),e.lineTo(r+l-s,o+i),e.stroke()):(e.beginPath(),e.moveTo(r+s,o),e.lineTo(r,o+i/2),e.lineTo(r+s,o+i),e.stroke());else if(t==="fade")if(h){const d=e.createLinearGradient(r+l-s*2,0,r+l,0);d.addColorStop(0,"rgba(0,0,0,0)"),d.addColorStop(1,c),e.fillStyle=d,e.fillRect(r+l-s*2,o,s*2,i)}else{const d=e.createLinearGradient(r,0,r+s*2,0);d.addColorStop(0,c),d.addColorStop(1,"rgba(0,0,0,0)"),e.fillStyle=d,e.fillRect(r,o,s*2,i)}}function _y(e,t){if(t<=0||e.length===0)return e;const n=new Array(e.length);for(let r=0;r<e.length;r++){let o=0,l=0;const i=Math.max(0,r-t),s=Math.min(e.length-1,r+t);for(let u=i;u<=s;u++)o+=e[u],l++;n[r]=o/l}return n}function Ec(e,t,n,r,o,l=!1){e.font="10px Arial, Helvetica, sans-serif",e.textAlign="left",e.textBaseline="top";const i=2,s=e.measureText(t).width+i*2;e.fillStyle=o.canvasBg||"#1e1e1e",e.globalAlpha=.75,e.fillRect(n,r,s,12),e.globalAlpha=1,e.fillStyle=l?o.textTertiary||"#666":o.textSecondary||"#aaa",e.fillText(t,n+i,r+1),e.textBaseline="alphabetic"}const Ly=16,My=22,By=4,Tp=8,Rc=6,jc={A:"#4caf50",T:"#f44336",C:"#2196f3",G:"#ff9800",N:"#9e9e9e"};function Ay({track:e,width:t,height:n,onWarning:r}){var N,$,_,H;const o=C.useRef(null),{region:l,navigateTo:i}=it(),{tracks:s}=Kt(),{theme:u}=Ye(),{data:c,loading:h,error:d}=Jl(e,l,t),g=e.useArrows!==!1,T=e.showNucleotides!==!1,v=C.useRef([]),[y,x]=C.useState(null),[f,p]=C.useState(null),m=C.useRef(null);C.useEffect(()=>{if(!l||!T){p(null);return}const j=l.end-l.start;if(t/j<Rc||j>2e3){p(null);return}if(f&&f.chrom===l.chrom&&f.start<=l.start&&f.end>=l.end)return;const O=Math.max(0,l.start-500),G=l.end+500,F=`${l.chrom}:${O}-${G}`;m.current!==F&&(m.current=F,mn.sequence(l.chrom,O,G).then(B=>p({chrom:l.chrom,start:O,end:G,sequence:B.data.sequence})).catch(()=>{}))},[l==null?void 0:l.chrom,l==null?void 0:l.start,l==null?void 0:l.end,t,T]),C.useEffect(()=>{var k,D;const j=o.current;if(!j)return;const U=window.devicePixelRatio||1;j.width=t*U,j.height=n*U;const O=j.getContext("2d");if(O.scale(U,U),O.clearRect(0,0,t,n),O.fillStyle=u.canvasBg,O.fillRect(0,0,t,n),v.current=[],h&&!((k=c==null?void 0:c.features)!=null&&k.length)){O.fillStyle=u.textTertiary,O.font="11px Arial, Helvetica, sans-serif",O.fillText("Loading…",8,n/2+4),r&&r(null);return}if(d){O.fillStyle="#ef9a9a",O.font="11px Arial, Helvetica, sans-serif",O.fillText(typeof d=="string"?d:JSON.stringify(d),8,n/2+4),r&&r(null);return}if(!((D=c==null?void 0:c.features)!=null&&D.length)){c&&(O.fillStyle=u.textTertiary,O.font="11px Arial, Helvetica, sans-serif",O.fillText("No features in region",8,n/2+4)),r&&r(null);return}const G=l.end-l.start,F=t/G,B=T&&F>=Rc&&f!=null,M=B?My:Ly,I=[],A=[];let R=0;if(B){const K=n-14;O.fillStyle=u.canvasBg,O.fillRect(0,K,t,14),O.strokeStyle=u.border||"#333",O.lineWidth=.5,O.beginPath(),O.moveTo(0,K),O.lineTo(t,K),O.stroke();const re=Math.min(10,F-1);if(re>=5){O.font=`bold ${re}px monospace`,O.textAlign="center",O.textBaseline="middle";for(let ue=Math.floor(l.start);ue<Math.ceil(l.end);ue++)if(f&&ue>=f.start&&ue<f.end){const pe=(f.sequence[ue-f.start]||"").toUpperCase(),fe=(ue-l.start)/G*t;O.fillStyle=jc[pe]||"#999",O.fillText(pe,fe+F/2,K+14/2)}}}for(const Y of c.features){let K=I.findIndex(ae=>Y.start>=ae);K===-1&&(K=I.length),I[K]=Y.end;const re=(Y.start-l.start)/G*t,ue=Math.max(2,(Y.end-Y.start)/G*t),pe=K*(M+By)+2;if(pe+M>n){R++;continue}const fe=_c(Y.feature_type,e,u);if(Y.sub_features&&Y.sub_features.length>0){O.fillStyle=fe+"66",O.fillRect(re,pe+M/2-1,ue,2);for(const ae of Y.sub_features){const ie=(ae.start-l.start)/G*t,te=Math.max(1,(ae.end-ae.start)/G*t),ge=_c(ae.feature_type,e,u),_e=ae.feature_type==="CDS"?M:M-6,ye=ae.feature_type==="CDS"?pe:pe+3;g?Pc(O,ge,ie,ye,te,_e,ae.strand||Y.strand):(O.fillStyle=ge,O.fillRect(ie,ye,te,_e))}}else g?Pc(O,fe,re,pe,ue,M,Y.strand):(O.fillStyle=fe,O.fillRect(re,pe,ue,M));if(B){const ae=Math.max(Y.start,l.start),ie=Math.min(Y.end,l.end);for(let te=ae;te<ie;te++)if(f&&te>=f.start&&te<f.end){const ge=(f.sequence[te-f.start]||"").toUpperCase(),_e=(te-l.start)/G*t,ye=F;ye>=6&&(O.fillStyle=jc[ge]||"#999",O.font=`bold ${Math.min(10,ye-1)}px monospace`,O.textAlign="center",O.textBaseline="middle",O.fillText(ge,_e+ye/2,pe+M/2))}}else if(ue>20){O.fillStyle="#fff",O.font="10px Arial, Helvetica, sans-serif",O.textAlign="left",O.textBaseline="alphabetic";const ae=Y.name||Y.feature_type,ie=Math.floor((ue-(g?Tp:0)-4)/6);ie>0&&O.fillText(ae.slice(0,ie),re+3,pe+M-4)}A.push({feat:Y,x:re,y:pe,w:ue,h:M})}v.current=A,r&&r(R>0?`${R} feature${R>1?"s":""} hidden — increase track height to show all`:null)},[c,h,d,t,n,l,f,e.color,e.annotationColors,g,e.showNucleotides,u]);const w=C.useCallback(j=>{const U=o.current;if(!U)return;const O=U.getBoundingClientRect(),G=(j.clientX-O.left)*(t/O.width),F=(j.clientY-O.top)*(n/O.height);for(const B of v.current)if(G>=B.x&&G<=B.x+B.w&&F>=B.y&&F<=B.y+B.h){const M=Math.min(j.clientX+14,window.innerWidth-300),I=Math.min(j.clientY+14,window.innerHeight-260);x({feat:B.feat,x:Math.max(4,M),y:Math.max(4,I)});return}x(null)},[t,n]),S=C.useCallback(()=>x(null),[]),E=C.useCallback(j=>{const U=o.current;if(!U||!l)return;const O=U.getBoundingClientRect(),G=(j.clientX-O.left)*(t/O.width),F=(j.clientY-O.top)*(n/O.height);for(const B of v.current)if(G>=B.x&&G<=B.x+B.w&&F>=B.y&&F<=B.y+B.h){const M=B.feat,A=(M.end-M.start)*.15/(1-.3),R=M.start-A,k=M.end+A;i(l.chrom,R,k),x(null);return}},[t,n,l,i]),b=y?zy(y.feat,s,l==null?void 0:l.chrom):[],P=y?Dn.createPortal(a.jsxs("div",{style:{position:"fixed",left:y.x,top:y.y,background:u.tooltipBg,border:`1px solid ${u.tooltipBorder}`,borderRadius:4,padding:"6px 10px",color:u.textPrimary,fontSize:11,lineHeight:1.5,maxWidth:280,zIndex:1e4,pointerEvents:"none",boxShadow:"0 4px 12px rgba(0,0,0,0.5)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:[a.jsx("div",{style:{fontWeight:700,fontSize:12,marginBottom:2},children:y.feat.name||y.feat.feature_type}),a.jsx(Jt,{label:"Type",value:y.feat.feature_type}),a.jsx(Jt,{label:"Strand",value:y.feat.strand||"."}),a.jsx(Jt,{label:"Location",value:`${y.feat.start.toLocaleString()}–${y.feat.end.toLocaleString()}`}),a.jsx(Jt,{label:"Length",value:`${(y.feat.end-y.feat.start).toLocaleString()} bp`}),((N=y.feat.attributes)==null?void 0:N.gene)&&y.feat.attributes.gene!==y.feat.name&&a.jsx(Jt,{label:"Gene",value:y.feat.attributes.gene}),(($=y.feat.attributes)==null?void 0:$.locus_tag)&&a.jsx(Jt,{label:"Locus",value:y.feat.attributes.locus_tag}),((_=y.feat.attributes)==null?void 0:_.product)&&a.jsx(Jt,{label:"Product",value:y.feat.attributes.product}),((H=y.feat.attributes)==null?void 0:H.note)&&a.jsx(Jt,{label:"Note",value:String(y.feat.attributes.note).slice(0,120)}),b.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("div",{style:{borderTop:`1px solid ${u.tooltipBorder}`,margin:"4px 0",paddingTop:4},children:a.jsx("span",{style:{color:u.textSecondary,fontWeight:600,fontSize:10,textTransform:"uppercase"},children:"Track totals in gene"})}),b.map(j=>a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:8},children:[a.jsx("span",{style:{color:u.textSecondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:j.name}),a.jsx("span",{style:{color:u.textPrimary,fontWeight:600,flexShrink:0},children:j.total.toFixed(1)})]},j.trackId))]})]}),document.body):null;return a.jsxs("div",{style:{position:"relative",width:"100%",height:n},children:[a.jsx("canvas",{ref:o,style:{display:"block",width:"100%",height:n},onMouseMove:w,onMouseLeave:S,onDoubleClick:E}),P]})}function Jt({label:e,value:t}){return t?a.jsxs("div",{style:{display:"flex",gap:6},children:[a.jsxs("span",{style:{opacity:.6,flexShrink:0},children:[e,":"]}),a.jsx("span",{children:t})]}):null}function zy(e,t,n){var o;if(!e||!n)return[];const r=[];for(const l of t){if(l.track_type!=="coverage"&&l.track_type!=="reads")continue;const i=Z0(l.id,n);if(!((o=i==null?void 0:i.bins)!=null&&o.length))continue;let s=0;for(const u of i.bins){if(u.end<=e.start||u.start>=e.end)continue;const c=u.forward!=null?u.forward:Math.max(0,u.value||0),h=u.reverse!=null?Math.abs(u.reverse):Math.abs(Math.min(0,u.value||0));s+=c+h}s>0&&r.push({trackId:l.id,name:l.name,total:s})}return r}function Pc(e,t,n,r,o,l,i){e.fillStyle=t;const s=Math.min(Tp,o*.4);e.beginPath(),i==="+"?(e.moveTo(n,r),e.lineTo(n+o-s,r),e.lineTo(n+o,r+l/2),e.lineTo(n+o-s,r+l),e.lineTo(n,r+l),e.closePath()):i==="-"?(e.moveTo(n+s,r),e.lineTo(n+o,r),e.lineTo(n+o,r+l),e.lineTo(n+s,r+l),e.lineTo(n,r+l/2),e.closePath()):e.rect(n,r,o,l),e.fill(),e.strokeStyle="rgba(0,0,0,0.25)",e.lineWidth=.5,e.stroke()}function _c(e,t,n){const r=t.annotationColors;switch(e==null?void 0:e.toLowerCase()){case"cds":return(r==null?void 0:r.cds)||(n==null?void 0:n.geneCds)||"#66bb6a";case"exon":return(r==null?void 0:r.exon)||(n==null?void 0:n.geneExon)||"#42a5f5";case"gene":return(r==null?void 0:r.gene)||(n==null?void 0:n.geneGene)||"#7e57c2";case"mrna":case"transcript":return(r==null?void 0:r.transcript)||(n==null?void 0:n.geneTranscript)||"#ab47bc";case"utr":case"3utr":case"5utr":return(r==null?void 0:r.utr)||(n==null?void 0:n.geneUtr)||"#26c6da";case"rrna":return(r==null?void 0:r.rrna)||(n==null?void 0:n.geneRrna)||"#ffa726";case"trna":return(r==null?void 0:r.trna)||(n==null?void 0:n.geneTrna)||"#ef5350";case"repeat_region":return(r==null?void 0:r.repeat)||(n==null?void 0:n.geneRepeat)||"#8d6e63";default:return(r==null?void 0:r.default)||t.color||(n==null?void 0:n.geneDefault)||"#80cbc4"}}function $y({track:e,width:t,height:n,onWarning:r}){const o=C.useRef(null),{region:l}=it(),{theme:i}=Ye(),{data:s,loading:u}=Jl(e,l,t);return C.useEffect(()=>{var f,p;const c=o.current;if(!c)return;const h=window.devicePixelRatio||1;c.width=t*h,c.height=n*h;const d=c.getContext("2d");if(d.scale(h,h),d.clearRect(0,0,t,n),d.fillStyle=i.canvasBg,d.fillRect(0,0,t,n),u&&!((f=s==null?void 0:s.variants)!=null&&f.length)){d.fillStyle=i.textTertiary,d.font="11px Arial, Helvetica, sans-serif",d.fillText("Loading…",8,n/2+4),r&&r(null);return}if(!((p=s==null?void 0:s.variants)!=null&&p.length)){s&&(d.fillStyle=i.textTertiary,d.font="11px Arial, Helvetica, sans-serif",d.fillText("No variants in region",8,n/2+4)),r&&r(null);return}const g=l.end-l.start,T=e.barAutoWidth!==!1,v=e.barWidth||2,y=T?1:Math.max(.5,v),x=T?5:Math.max(2,v*2);for(const m of s.variants){const w=(m.pos-l.start)/g*t,S=Ny(m.ref,m.alt);d.strokeStyle=S,d.lineWidth=y,d.beginPath(),d.moveTo(w,n-4),d.lineTo(w,14),d.stroke(),d.fillStyle=S,d.beginPath(),d.arc(w,10,x,0,Math.PI*2),d.fill(),g<5e3&&(d.fillStyle=i.textPrimary,d.font="9px Arial, Helvetica, sans-serif",d.textAlign="center",d.fillText(`${m.ref}>${m.alt[0]||"?"}`,w,n-6))}if(r){const m=s.variants.filter(w=>w.pos>=l.start&&w.pos<=l.end).length;r(m>50?`${m} variants overlapping — zoom in for detail`:null)}},[s,u,t,n,l,e.color,e.barAutoWidth,e.barWidth,i]),a.jsx("canvas",{ref:o,style:{display:"block",width:"100%",height:n}})}function Ny(e,t){const n=t[0]||"";return e.length===1&&n.length===1?"#ffb74d":n.length>e.length?"#81c784":n.length<e.length?"#e57373":"#b0bec5"}function Oy({message:e,theme:t}){const[n,r]=C.useState(!1),o=C.useRef(null),l=o.current?o.current.getBoundingClientRect():null;return a.jsxs(a.Fragment,{children:[a.jsx("span",{ref:o,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:12,height:12,borderRadius:"50%",background:"rgba(229, 57, 53, 0.85)",color:"#fff",fontSize:9,fontWeight:800,lineHeight:1,cursor:"default",flexShrink:0,fontFamily:"Arial, Helvetica, sans-serif"},children:"!"}),n&&l&&Dn.createPortal(a.jsx("div",{style:{position:"fixed",left:Math.min(l.right+6,window.innerWidth-220),top:l.top-4,background:t.tooltipBg||"#333",border:`1px solid ${t.tooltipBorder||"#555"}`,borderRadius:4,padding:"4px 8px",color:t.textPrimary||"#e0e0e0",fontSize:11,lineHeight:1.4,maxWidth:200,zIndex:10001,pointerEvents:"none",boxShadow:"0 3px 10px rgba(0,0,0,0.5)",whiteSpace:"pre-wrap",fontFamily:"Arial, Helvetica, sans-serif"},children:e}),document.body)]})}function Fy({width:e,height:t,trackData:n,trackType:r}){const{region:o,selection:l,clearSelection:i}=it(),{theme:s}=Ye(),[u,c]=C.useState(!1),[h,d]=C.useState({x:0,y:0}),g=C.useRef(null),T=C.useCallback($=>{d({x:$.clientX,y:$.clientY}),c(!0)},[]),v=C.useCallback(()=>c(!1),[]);if(!l||!o||l.chrom!==o.chrom)return null;const y=o.end-o.start;if(y<=0)return null;const x=(l.start-o.start)/y,f=(l.end-o.start)/y,p=Math.max(0,x*e),w=Math.min(e,f*e)-p;if(w<1)return null;const S=Iy(l,n,r),E=l.end-l.start,b=260,P=Math.min(h.x+14,window.innerWidth-b-10),N=Math.min(h.y+14,window.innerHeight-200);return a.jsxs("div",{ref:g,style:{position:"absolute",top:0,left:0,width:e,height:t,pointerEvents:"none"},children:[a.jsx("div",{style:{position:"absolute",left:p,top:0,width:w,height:"100%",background:"rgba(100, 181, 246, 0.2)",borderLeft:"1px solid rgba(100, 181, 246, 0.6)",borderRight:"1px solid rgba(100, 181, 246, 0.6)",pointerEvents:"auto",cursor:"crosshair"},onMouseMove:T,onMouseLeave:v,onClick:$=>{$.stopPropagation(),i()}}),u&&Dn.createPortal(a.jsxs("div",{style:{position:"fixed",left:P,top:N,background:s.panelBg,border:`1px solid ${s.borderAccent}`,borderRadius:6,padding:"8px 12px",fontSize:11,color:s.textPrimary,lineHeight:1.6,pointerEvents:"none",zIndex:1e4,boxShadow:"0 4px 16px rgba(0,0,0,0.4)",minWidth:180,maxWidth:b},children:[a.jsx("div",{style:{fontWeight:700,marginBottom:4,fontSize:12},children:"Selected Region"}),a.jsxs("div",{children:[a.jsx("span",{style:{color:s.textSecondary},children:"Region:"})," ",l.chrom,":",l.start.toLocaleString(),"-",l.end.toLocaleString()]}),a.jsxs("div",{children:[a.jsx("span",{style:{color:s.textSecondary},children:"Length:"})," ",E.toLocaleString()," bp"]}),S.map(($,_)=>a.jsxs("div",{children:[a.jsxs("span",{style:{color:s.textSecondary},children:[$.label,":"]})," ",$.value]},_)),a.jsx("div",{style:{fontSize:9,color:s.textTertiary,marginTop:4},children:"Click to dismiss"})]}),document.body)]})}function Iy(e,t,n){const r=[];if(!t)return r;if(n==="reads"&&t.reads){const o=t.reads.filter(i=>i.end>e.start&&i.start<e.end);r.push({label:"Reads in region",value:o.length.toLocaleString()});let l=0;for(const i of o)if(i.cigar){const s=i.cigar.match(/(\d+)I/g);if(s)for(const u of s)l+=parseInt(u)}if(l>0&&r.push({label:"Insertion bases",value:l.toLocaleString()}),o.length>0){const i=o.reduce((s,u)=>s+(u.mapq||0),0)/o.length;r.push({label:"Avg MAPQ",value:i.toFixed(1)})}}if((n==="coverage"||n==="reads")&&t.bins){const o=t.bins.filter(l=>l.end>e.start&&l.start<e.end);if(o.length>0){const l=o.map(c=>c.value),i=l.reduce((c,h)=>c+h,0)/l.length,s=Math.max(...l),u=Math.min(...l);r.push({label:"Avg coverage",value:i.toFixed(1)}),r.push({label:"Max coverage",value:s.toFixed(1)}),u!==s&&r.push({label:"Min coverage",value:u.toFixed(1)})}}if(n==="variants"&&t.variants){const o=t.variants.filter(l=>l.pos>=e.start&&l.pos<e.end);r.push({label:"Variants in region",value:o.length.toLocaleString()})}if((n==="annotations"||n==="genome_annotations")&&t.features){const o=t.features.filter(l=>l.end>e.start&&l.start<e.end);r.push({label:"Features in region",value:o.length.toLocaleString()})}return r}class Dy extends C.Component{constructor(t){super(t),this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}render(){var t;return this.state.hasError?a.jsxs("div",{style:{padding:8,color:"#ef9a9a",fontSize:11},children:["Track error: ",((t=this.state.error)==null?void 0:t.message)||"Unknown error"]}):this.props.children}}function Uy({track:e,containerWidth:t,labelWidth:n=140,onLabelResizeStart:r,isDragging:o,isDropTarget:l,onDragStart:i,onDragOver:s,onDrop:u,onDragEnd:c}){const{theme:h}=Ye(),{updateTrack:d,removeTrack:g}=Kt(),T=C.useRef(null),v=C.useRef(null),[y,x]=C.useState(!1),[f,p]=C.useState(!1),[m,w]=C.useState(null),S=C.useRef(null),E=C.useRef(null),b=e.track_type==="annotations"||e.track_type==="genome_annotations";Cp(T);const P=["#f44336","#ef5350","#e57373","#ff5722","#ff8a65","#ff9800","#ffa726","#ffb74d","#ffc107","#fff176","#4caf50","#66bb6a","#81c784","#aed581","#009688","#26c6da","#80cbc4","#2196f3","#42a5f5","#64b5f6","#7e57c2","#9575cd","#9c27b0","#ab47bc","#ce93d8","#e91e63","#f06292","#795548","#8d6e63","#607d8b","#78909c"],N=t-n,$={row:{display:"flex",borderBottom:`1px solid ${h.border}`,minHeight:40},label:{width:n,minWidth:n,background:h.panelBg,borderRight:`1px solid ${h.border}`,display:"flex",flexDirection:"column",justifyContent:"center",padding:"4px 8px",overflow:"hidden",position:"relative"},trackName:{fontSize:11,color:h.trackName,fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},trackType:{fontSize:10,color:h.textTertiary,marginTop:2},trackArea:{flex:1,overflow:"hidden",position:"relative"}},_=C.useCallback(j=>{j.preventDefault(),j.stopPropagation();const U=j.clientY,O=e.height;function G(B){const M=Math.max(30,Math.min(500,O+(B.clientY-U)));d(e.id,{height:M})}function F(){window.removeEventListener("mousemove",G),window.removeEventListener("mouseup",F),document.body.style.cursor="",document.body.style.userSelect=""}document.body.style.cursor="ns-resize",document.body.style.userSelect="none",window.addEventListener("mousemove",G),window.addEventListener("mouseup",F)},[e.id,e.height,d]);function H(){const j={track:e,width:N,height:e.height,onWarning:w};switch(e.track_type){case"reads":return a.jsx(jy,{...j});case"coverage":return a.jsx(ky,{...j});case"variants":return a.jsx($y,{...j});case"annotations":case"genome_annotations":return a.jsx(Ay,{...j});default:return a.jsx("div",{style:{padding:8,color:h.textTertiary,fontSize:11},children:"Unknown track type"})}}return a.jsxs("div",{style:{...$.row,height:e.height,position:"relative",opacity:o?.4:1,borderTop:l?"2px solid #888":void 0},onDragOver:j=>{j.preventDefault(),j.dataTransfer.dropEffect="move",s==null||s()},onDrop:j=>{j.preventDefault(),u==null||u()},onDragEnd:c,children:[a.jsxs("div",{style:$.label,children:[a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[a.jsx("div",{draggable:!0,onDragStart:j=>{j.dataTransfer.effectAllowed="move",j.dataTransfer.setData("text/plain",e.id),i==null||i()},style:{cursor:"grab",color:h.textMuted,fontSize:14,lineHeight:1,userSelect:"none",flexShrink:0,padding:"0 2px"},title:"Drag to reorder tracks",children:"≡"}),a.jsx("div",{ref:S,children:b?a.jsxs(a.Fragment,{children:[a.jsx("span",{style:{display:"inline-block",width:10,height:10,borderRadius:2,background:"#888",cursor:"pointer",verticalAlign:"middle",border:"1px solid rgba(255,255,255,0.2)",backgroundImage:"linear-gradient(135deg, #ef5350 25%, #66bb6a 25%, #66bb6a 50%, #42a5f5 50%, #42a5f5 75%, #ffa726 75%)"},title:"Click to customize annotation colors",onMouseDown:j=>{j.stopPropagation(),p(U=>!U)}}),f&&Dn.createPortal(a.jsx(Gy,{track:e,theme:h,anchorRef:S,onClose:()=>p(!1),onChange:(j,U)=>{const O={...e.annotationColors||{},[j]:U};d(e.id,{annotationColors:O})},onReset:()=>d(e.id,{annotationColors:null})}),document.body)]}):a.jsxs(a.Fragment,{children:[a.jsx("span",{style:{display:"inline-block",width:10,height:10,borderRadius:2,background:e.color,cursor:"pointer",verticalAlign:"middle",border:"1px solid rgba(255,255,255,0.2)"},title:"Click to pick color, double-click for full palette",onMouseDown:j=>{j.stopPropagation(),x(!0)},onDoubleClick:j=>{var U;j.stopPropagation(),x(!1),(U=E.current)==null||U.click()}}),a.jsx("input",{ref:E,type:"color",value:e.color||"#78909c",onChange:j=>d(e.id,{color:j.target.value}),style:{position:"absolute",left:-9999,top:-9999,opacity:0,width:0,height:0}}),y&&Dn.createPortal(a.jsx("div",{style:{position:"fixed",left:S.current?S.current.getBoundingClientRect().left:0,top:S.current?S.current.getBoundingClientRect().bottom+4:0,zIndex:10001,background:h.panelBg,border:`1px solid ${h.borderAccent}`,borderRadius:4,padding:6,boxShadow:"0 4px 12px rgba(0,0,0,0.5)",display:"grid",gridTemplateColumns:"repeat(5, 18px)",gap:3},onMouseLeave:()=>x(!1),children:P.map(j=>a.jsx("span",{style:{width:18,height:18,borderRadius:3,background:j,cursor:"pointer",border:j===e.color?`2px solid ${h.textPrimary}`:"1px solid rgba(255,255,255,0.15)",boxSizing:"border-box"},onMouseUp:()=>{d(e.id,{color:j}),x(!1)}},j))}),document.body)]})}),a.jsx("div",{style:{...$.trackName,flex:1},title:e.name,children:e.name}),a.jsx("span",{title:"Remove track",onClick:j=>{j.stopPropagation(),g(e.id)},style:{color:"#e53935",fontSize:13,fontWeight:700,cursor:"pointer",lineHeight:1,flexShrink:0,padding:"0 2px",opacity:.7,transition:"opacity 0.15s"},onMouseEnter:j=>j.currentTarget.style.opacity="1",onMouseLeave:j=>j.currentTarget.style.opacity="0.7",children:"×"})]}),a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[a.jsxs("div",{style:$.trackType,children:[e.file_format," · ",e.track_type]}),m&&a.jsx(Oy,{message:m,theme:h})]}),r&&a.jsx("div",{onMouseDown:r,style:{position:"absolute",right:-3,top:0,bottom:0,width:6,cursor:"ew-resize",zIndex:10},onMouseEnter:j=>j.currentTarget.style.background="rgba(255,255,255,0.15)",onMouseLeave:j=>j.currentTarget.style.background="transparent"})]}),a.jsxs("div",{style:$.trackArea,ref:T,children:[a.jsx(Dy,{children:H()}),a.jsx(Fy,{width:N,height:e.height,trackData:Sp(e.id),trackType:e.track_type})]}),a.jsx("div",{ref:v,onMouseDown:_,title:"Drag to resize track height",style:{position:"absolute",left:0,right:0,bottom:-2,height:5,cursor:"ns-resize",zIndex:10,background:"transparent"},onMouseEnter:j=>j.currentTarget.style.background="rgba(255,255,255,0.15)",onMouseLeave:j=>j.currentTarget.style.background="transparent"})]})}const Wy=[{key:"cds",label:"CDS"},{key:"exon",label:"Exon"},{key:"gene",label:"Gene"},{key:"transcript",label:"Transcript"},{key:"utr",label:"UTR"},{key:"rrna",label:"rRNA"},{key:"trna",label:"tRNA"},{key:"repeat",label:"Repeat"},{key:"default",label:"Other"}],Hy=["#f44336","#ef5350","#e57373","#ff5722","#ff8a65","#ff9800","#ffa726","#ffb74d","#ffc107","#fff176","#4caf50","#66bb6a","#81c784","#aed581","#009688","#26c6da","#80cbc4","#2196f3","#42a5f5","#64b5f6","#7e57c2","#9575cd","#9c27b0","#ab47bc","#ce93d8","#e91e63","#f06292","#795548","#8d6e63","#607d8b","#78909c"],Vy={cds:"geneCds",exon:"geneExon",gene:"geneGene",transcript:"geneTranscript",utr:"geneUtr",rrna:"geneRrna",trna:"geneTrna",repeat:"geneRepeat",default:"geneDefault"};function Gy({track:e,theme:t,anchorRef:n,onClose:r,onChange:o,onReset:l}){var d;const[i,s]=C.useState(null),u=e.annotationColors||{},c=(d=n.current)==null?void 0:d.getBoundingClientRect();function h(g){return u[g]||t[Vy[g]]||gp[g]}return a.jsxs("div",{style:{position:"fixed",left:c?Math.min(c.left,window.innerWidth-220):0,top:c?c.bottom+4:0,zIndex:10001,background:t.panelBg,border:`1px solid ${t.borderAccent}`,borderRadius:6,padding:"8px 0",boxShadow:"0 6px 20px rgba(0,0,0,0.5)",width:210,maxHeight:340,overflowY:"auto"},onMouseLeave:r,children:[a.jsx("div",{style:{fontSize:10,fontWeight:700,color:t.textSecondary,textTransform:"uppercase",letterSpacing:1,padding:"0 10px 6px",borderBottom:`1px solid ${t.border}`,marginBottom:4},children:"Annotation Colors"}),Wy.map(({key:g,label:T})=>{const v=h(g);return a.jsxs("div",{children:[a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 10px",cursor:"pointer",fontSize:11,color:t.textPrimary},onMouseEnter:y=>y.currentTarget.style.background=t.selectedRow,onMouseLeave:y=>y.currentTarget.style.background="transparent",onClick:()=>s(i===g?null:g),children:[a.jsx("span",{style:{display:"inline-block",width:14,height:14,borderRadius:3,background:v,border:"1px solid rgba(255,255,255,0.15)",flexShrink:0}}),a.jsx("span",{style:{flex:1},children:T}),a.jsx("span",{style:{fontSize:9,color:t.textTertiary},children:i===g?"▲":"▼"})]}),i===g&&a.jsx("div",{style:{padding:"4px 10px 6px 32px",display:"grid",gridTemplateColumns:"repeat(5, 18px)",gap:3},children:Hy.map(y=>a.jsx("span",{style:{width:18,height:18,borderRadius:3,background:y,cursor:"pointer",border:y===v?`2px solid ${t.textPrimary}`:"1px solid rgba(255,255,255,0.15)",boxSizing:"border-box"},onClick:()=>{o(g,y),s(null)}},y))})]},g)}),a.jsx("div",{style:{borderTop:`1px solid ${t.border}`,marginTop:4,paddingTop:4},children:a.jsx("div",{style:{padding:"4px 10px",fontSize:10,color:t.textTertiary,cursor:"pointer",textAlign:"center"},onMouseEnter:g=>{g.currentTarget.style.color=t.textPrimary},onMouseLeave:g=>{g.currentTarget.style.color=t.textTertiary},onClick:l,children:"Reset to defaults"})})]})}function Yy({labelWidth:e}){const{genome:t,region:n}=it(),{tracks:r}=Kt(),{theme:o,themeName:l,customTheme:i}=Ye(),[s,u]=C.useState(!1),[c,h]=C.useState(!1),d=!!t;C.useEffect(()=>{if(!d)return;function y(x){x.preventDefault(),x.returnValue=""}return window.addEventListener("beforeunload",y),()=>window.removeEventListener("beforeunload",y)},[d]),C.useEffect(()=>{if(!d)return;function y(x){(x.ctrlKey||x.metaKey)&&x.key==="w"&&(x.preventDefault(),u(!0))}return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[d]);const g=C.useCallback(()=>u(!1),[]),T=C.useCallback(()=>{window.onbeforeunload=null,window.close(),window.location.href="about:blank"},[]),v=C.useCallback(()=>{h(!0);try{const y=Na(t,n,r,l,i,e);Oa(y),kp(y)}catch{}h(!1),window.onbeforeunload=null,window.close(),window.location.href="about:blank"},[t,n,r,l,i,e]);return s?a.jsx("div",{style:{position:"fixed",inset:0,zIndex:1e4,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:g,children:a.jsxs("div",{style:{background:o.panelBg,border:`1px solid ${o.borderAccent}`,borderRadius:8,padding:"24px 28px",maxWidth:400,width:"90%",boxShadow:"0 8px 32px rgba(0,0,0,0.6)"},onClick:y=>y.stopPropagation(),children:[a.jsx("div",{style:{fontSize:16,fontWeight:700,color:o.textPrimary,marginBottom:8},children:"Leave BiNgo Genome Viewer?"}),a.jsxs("div",{style:{fontSize:12,color:o.textSecondary,lineHeight:1.7,marginBottom:20},children:["You have an active session with"," ",a.jsxs("strong",{style:{color:o.textPrimary},children:[r.length," track",r.length!==1?"s":""]})," loaded. Unsaved changes will be lost."]}),a.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[a.jsx("button",{onClick:g,style:{background:"#1976d2",border:"none",borderRadius:4,color:"#fff",padding:"8px 16px",cursor:"pointer",fontSize:13,fontWeight:600,width:"100%"},children:"Return to App"}),a.jsx("button",{onClick:v,disabled:c,style:{background:o.btnBg,border:`1px solid ${o.borderStrong}`,borderRadius:4,color:o.btnText,padding:"8px 16px",cursor:"pointer",fontSize:13,fontWeight:600,width:"100%"},children:c?"Saving...":"Save Session & Exit"}),a.jsx("button",{onClick:T,style:{background:"transparent",border:`1px solid ${o.border}`,borderRadius:4,color:"#e57373",padding:"8px 16px",cursor:"pointer",fontSize:13,fontWeight:600,width:"100%"},children:"Exit Without Saving"})]})]})}):null}const Lc="2.2.7";let Qy=0;function Mc({size:e=32}){const[t]=Is.useState(()=>`blogo${++Qy}`);return a.jsxs("svg",{width:e,height:e,viewBox:"0 0 100 100",style:{flexShrink:0},xmlns:"http://www.w3.org/2000/svg",children:[a.jsxs("defs",{children:[a.jsxs("radialGradient",{id:`${t}_bg`,cx:"35%",cy:"30%",r:"65%",children:[a.jsx("stop",{offset:"0%",stopColor:"#5eb8ff"}),a.jsx("stop",{offset:"50%",stopColor:"#1976d2"}),a.jsx("stop",{offset:"100%",stopColor:"#0d47a1"})]}),a.jsxs("radialGradient",{id:`${t}_sh`,cx:"30%",cy:"25%",r:"30%",children:[a.jsx("stop",{offset:"0%",stopColor:"#ffffff",stopOpacity:"0.7"}),a.jsx("stop",{offset:"100%",stopColor:"#ffffff",stopOpacity:"0"})]})]}),a.jsx("circle",{cx:"50",cy:"50",r:"48",fill:`url(#${t}_bg)`}),a.jsx("circle",{cx:"50",cy:"48",r:"28",fill:"white"}),a.jsx("circle",{cx:"50",cy:"48",r:"28",fill:"none",stroke:"#1565c0",strokeWidth:"2.5"}),a.jsx("text",{x:"50",y:"39",textAnchor:"middle",fontSize:"13",fontWeight:"800",fontFamily:"Arial, sans-serif",fill:"#0d47a1",children:"BN"}),a.jsx("text",{x:"50",y:"64",textAnchor:"middle",fontSize:"30",fontWeight:"900",fontFamily:"Arial, sans-serif",fill:"#0d47a1",children:"1"}),a.jsx("circle",{cx:"50",cy:"50",r:"48",fill:`url(#${t}_sh)`})]})}function Xy({theme:e,labelWidth:t}){return a.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${e.border}`,height:60,opacity:.45},children:[a.jsx("div",{"data-tour":"skeleton-track-label",style:{width:t,minWidth:t,background:e.panelBg,borderRight:`1px solid ${e.border}`,padding:"6px 8px",display:"flex",flexDirection:"column",justifyContent:"center",gap:4},children:a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[a.jsx("span",{style:{fontSize:14,color:e.textTertiary,userSelect:"none",lineHeight:1},children:"≡"}),a.jsx("span",{style:{width:10,height:10,borderRadius:2,background:"#78909c",flexShrink:0}}),a.jsx("span",{style:{fontSize:11,fontWeight:600,color:e.textSecondary,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"Track Name"}),a.jsx("span",{style:{fontSize:13,color:e.textTertiary,lineHeight:1,padding:"0 2px"},children:"×"})]})}),a.jsx("div",{style:{flex:1,background:e.canvasBg}})]})}function Ky(){const{theme:e}=Ye(),{genome:t,region:n,setGenome:r,navigateTo:o}=it(),{tracks:l,reorderTracks:i,addTrack:s,uploadTrack:u,commitTrack:c,discardTrack:h,addGenomeAnnotationTrack:d,restoreAnnotationTracks:g}=Kt(),T=C.useRef(null),[v,y]=C.useState(800),[x,f]=C.useState(!1),[p,m]=C.useState(!1),[w,S]=C.useState(!1),[E,b]=C.useState(!1),[P,N]=C.useState(!1),[$,_]=C.useState(!1),[H,j]=C.useState(140),[U,O]=C.useState(null),[G,F]=C.useState(null),[B,M]=C.useState(!1),[I,A]=C.useState(null),[R,k]=C.useState(null),[D,Y]=C.useState(null),K=C.useRef(0);my(H),C.useEffect(()=>{const z=()=>fetch("/api/heartbeat").catch(()=>{});z();const q=setInterval(z,1e4);return()=>clearInterval(q)},[]);const re=C.useRef(n==null?void 0:n.chrom);C.useEffect(()=>{n!=null&&n.chrom&&n.chrom!==re.current&&(re.current=n.chrom,g())},[n==null?void 0:n.chrom,g]);const ue=new Set([".gb",".gbk",".genbank",".fasta",".fa"]),pe=new Set([".bam",".bw",".bigwig",".wig",".bedgraph",".bdg",".vcf",".bed",".gtf",".gff",".gff2",".gff3"]),fe=new Set([".bai"]);function ae(z){if(!z)return"";if(z.toLowerCase().endsWith(".vcf.gz"))return".vcf.gz";const q=z.lastIndexOf(".");return q>=0?z.slice(q).toLowerCase():""}const ie=C.useCallback(z=>{var q,Q;z.preventDefault(),z.stopPropagation(),(Q=(q=z.dataTransfer)==null?void 0:q.types)!=null&&Q.includes("Files")&&(K.current++,K.current===1&&M(!0))},[]),te=C.useCallback(z=>{var q,Q;z.preventDefault(),z.stopPropagation(),(Q=(q=z.dataTransfer)==null?void 0:q.types)!=null&&Q.includes("Files")&&(K.current--,K.current<=0&&(K.current=0,M(!1)))},[]),ge=C.useCallback(z=>{z.preventDefault(),z.stopPropagation()},[]);function _e(z){const q=z==null?void 0:z.compatibility;return q&&q.status!=="ok"&&q.status!=="no_genome"}const ye=C.useCallback(async z=>{var Oe,st,Fa,Ia,Da;if(z.preventDefault(),z.stopPropagation(),K.current=0,M(!1),!((st=(Oe=z.dataTransfer)==null?void 0:Oe.types)!=null&&st.includes("Files")))return;const q=Array.from(z.dataTransfer.files);if(!q.length)return;const Q=[],Z=[],le=[],oe=[];for(const Ee of q){const Le=ae(Ee.name),mt=Ee.name.toLowerCase();ue.has(Le)?Q.push(Ee):pe.has(Le)||Le===".vcf.gz"?Z.push(Ee):fe.has(Le)||mt.endsWith(".bam.bai")?le.push(Ee):oe.push(Ee)}const de=Z.filter(Ee=>Ee.name.toLowerCase().endsWith(".bam")&&Ee.size>50*1024*1024),xe=le.filter(Ee=>Ee.size>10*1024*1024);if(de.length||xe.length){const Ee=[...de,...xe].map(mt=>mt.name).join(", "),Le=[...de,...xe].reduce((mt,Co)=>mt+Co.size,0)/(1024*1024);A({error:`${Ee} (${Le.toFixed(0)} MB) — large files load faster via the Path button. Click 📂 Path in the toolbar and paste the file path instead of uploading.`}),setTimeout(()=>A(null),1e4);return}if(oe.length&&!Q.length&&!Z.length&&!le.length){A({error:`Unsupported file${oe.length>1?"s":""}: ${oe.map(Ee=>Ee.name).join(", ")}`}),setTimeout(()=>A(null),4e3);return}try{if(Q.length>0&&!t){A({msg:`Loading genome: ${Q[0].name}...`});const Le=(await mn.load(Q[0])).data;if(Le.name&&(Le.name=Nt(Le.name)),r(Le),((Fa=Le.chromosomes)==null?void 0:Fa.length)>0){const mt=Le.chromosomes[0];o(mt.name,0,Math.min(mt.length,5e4))}Le.is_annotated&&d({id:"genome_annotations",name:`${Le.name} (annotations)`,track_type:"genome_annotations",file_format:"genbank",targetChromosomes:Le.annotated_chromosomes||null})}else Q.length>0&&t&&k({files:Q});if(Z.length>0){if(!t&&Q.length===0){A({error:"Load a genome file first (.fasta, .gb, .genbank)"}),setTimeout(()=>A(null),4e3);return}A({msg:`Loading ${Z.length} track${Z.length>1?"s":""}...`});const Ee=[],Le=[],mt=[];for(const Co of Z)try{const Sn=await u(Co,void 0);_e(Sn)?Le.push(Sn):(c(Sn),Ee.push(Sn))}catch(Sn){mt.push(`${Co.name}: ${((Da=(Ia=Sn.response)==null?void 0:Ia.data)==null?void 0:Da.detail)||Sn.message}`)}if(mt.length){A({error:mt.join("; ")}),setTimeout(()=>A(null),5e3);return}Le.length>0&&Y({tracks:Le})}oe.length?(A({error:`Skipped unsupported: ${oe.map(Ee=>Ee.name).join(", ")}`}),setTimeout(()=>A(null),4e3)):(A({msg:"Files loaded"}),setTimeout(()=>A(null),2e3))}catch(Ee){A({error:Ee.message||"Drop failed"}),setTimeout(()=>A(null),5e3)}},[t,r,o,s,d]),Ne=C.useCallback(async()=>{var q,Q;if(!R)return;const z=R.files;k(null);try{const Z=[];for(const le of z){A({msg:`Adding chromosomes from ${le.name}...`});try{const de=(await mn.addChromosomes(le)).data;de.name&&(de.name=Nt(de.name)),r(de),de.is_annotated&&d({id:"genome_annotations",name:`${de.name} (annotations)`,track_type:"genome_annotations",file_format:"genbank",targetChromosomes:de.annotated_chromosomes||null})}catch(oe){Z.push(`${le.name}: ${((Q=(q=oe.response)==null?void 0:q.data)==null?void 0:Q.detail)||oe.message}`)}}Z.length?(A({error:Z.join("; ")}),setTimeout(()=>A(null),5e3)):(A({msg:`Added chromosomes from ${z.length} file${z.length>1?"s":""}`}),setTimeout(()=>A(null),3e3))}catch(Z){A({error:Z.message||"Failed to add chromosomes"}),setTimeout(()=>A(null),5e3)}},[R,r,d]),Je=C.useCallback(async()=>{var q,Q;if(!R)return;const z=R.files;k(null);try{A({msg:`Loading ${z.length} track${z.length>1?"s":""}...`});const Z=[];for(const le of z)try{await s(le,void 0)}catch(oe){Z.push(`${le.name}: ${((Q=(q=oe.response)==null?void 0:q.data)==null?void 0:Q.detail)||oe.message}`)}Z.length?(A({error:Z.join("; ")}),setTimeout(()=>A(null),5e3)):(A({msg:`Added ${z.length} track${z.length>1?"s":""}`}),setTimeout(()=>A(null),3e3))}catch(Z){A({error:Z.message||"Failed to load tracks"}),setTimeout(()=>A(null),5e3)}},[R,s]),he=C.useCallback(async()=>{if(D){for(const z of D.tracks)await h(z.id);Y(null)}},[D,h]),ht=C.useCallback(()=>{if(D){for(const z of D.tracks)c(z);Y(null),A({msg:`Added ${D.tracks.length} track${D.tracks.length>1?"s":""}`}),setTimeout(()=>A(null),3e3)}},[D,c]),V=C.useCallback(z=>{z.preventDefault();const q=z.clientX,Q=H;function Z(oe){j(Math.max(60,Math.min(400,Q+(oe.clientX-q))))}function le(){window.removeEventListener("mousemove",Z),window.removeEventListener("mouseup",le),document.body.style.cursor="",document.body.style.userSelect=""}document.body.style.cursor="ew-resize",document.body.style.userSelect="none",window.addEventListener("mousemove",Z),window.addEventListener("mouseup",le)},[H]);C.useEffect(()=>{if(!T.current)return;const z=new ResizeObserver(q=>{for(const Q of q)y(Q.contentRect.width)});return z.observe(T.current),()=>z.disconnect()},[]);const J=C.useCallback(z=>z.visible?!z.targetChromosomes||!(n!=null&&n.chrom)?!0:z.targetChromosomes.includes(n.chrom):!1,[n==null?void 0:n.chrom]),ee={app:{display:"flex",flexDirection:"column",height:"100vh",background:e.appBg,color:e.textPrimary},header:{background:e.headerBg,borderBottom:`2px solid ${e.borderAccent}`,padding:"8px 16px",display:"flex",alignItems:"center",justifyContent:"space-between"},headerLeft:{display:"flex",alignItems:"center",gap:12},title:{fontSize:18,fontWeight:700,color:e.textPrimary,letterSpacing:1},subtitle:{fontSize:11,color:e.textTertiary},headerBtns:{display:"flex",gap:8},btn:{background:e.btnBg,border:`1px solid ${e.borderStrong}`,borderRadius:4,color:e.btnText,padding:"5px 14px",cursor:"pointer",fontSize:12,fontWeight:600,display:"flex",alignItems:"center",gap:6},trackArea:{flex:1,overflowY:"auto",overflowX:"hidden",display:"flex",flexDirection:"column"},emptyState:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",flex:1,color:e.textMuted,gap:12},emptyTitle:{fontSize:22,fontWeight:300},emptyHint:{fontSize:13}};return a.jsxs("div",{style:ee.app,onDragEnter:ie,onDragLeave:te,onDragOver:ge,onDrop:ye,children:[a.jsxs("div",{style:ee.header,children:[a.jsxs("div",{style:ee.headerLeft,children:[a.jsx(Mc,{size:34}),a.jsxs("div",{children:[a.jsx("div",{style:ee.title,children:"BiNgo Genome Viewer"}),t&&a.jsxs("div",{style:ee.subtitle,children:[t.name," · ",t.chromosomes.length," chr"]})]}),a.jsxs("button",{onClick:()=>N(!0),title:"About / References",style:{background:"none",border:`1px solid ${e.border}`,borderRadius:10,padding:"2px 8px",display:"flex",alignItems:"center",gap:4,cursor:"pointer",color:e.textSecondary,fontSize:11,fontWeight:600,lineHeight:1,flexShrink:0},onMouseEnter:z=>{z.currentTarget.style.color=e.textPrimary,z.currentTarget.style.borderColor=e.textSecondary},onMouseLeave:z=>{z.currentTarget.style.color=e.textSecondary,z.currentTarget.style.borderColor=e.border},children:[a.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"currentColor",style:{flexShrink:0},children:[a.jsx("path",{d:"M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"}),a.jsx("circle",{cx:"8",cy:"4.5",r:"1.2"}),a.jsx("rect",{x:"7",y:"6.5",width:"2",height:"5.5",rx:"0.8"})]}),"Info"]}),a.jsxs("button",{onClick:()=>_(!0),title:"Guided Tour",style:{background:"none",border:`1px solid ${e.border}`,borderRadius:10,padding:"2px 8px",display:"flex",alignItems:"center",gap:4,cursor:"pointer",color:e.textSecondary,fontSize:11,fontWeight:600,lineHeight:1,flexShrink:0},onMouseEnter:z=>{z.currentTarget.style.color=e.textPrimary,z.currentTarget.style.borderColor=e.textSecondary},onMouseLeave:z=>{z.currentTarget.style.color=e.textSecondary,z.currentTarget.style.borderColor=e.border},children:[a.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"currentColor",style:{flexShrink:0},children:[a.jsx("path",{d:"M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"}),a.jsx("path",{d:"M5.255 5.786a.237.237 0 0 0 .241.247h.825c.138 0 .248-.113.266-.25.09-.656.54-1.134 1.342-1.134.686 0 1.314.343 1.314 1.168 0 .635-.374.927-.965 1.371-.673.489-1.206 1.06-1.168 1.987l.003.217a.25.25 0 0 0 .25.246h.811a.25.25 0 0 0 .25-.25v-.105c0-.718.273-.927 1.01-1.486.609-.463 1.244-.977 1.244-2.056 0-1.511-1.276-2.241-2.673-2.241-1.267 0-2.655.59-2.75 2.286zM8 13.5a1 1 0 1 0 0-2 1 1 0 0 0 0 2z"})]}),"Help"]})]}),a.jsxs("div",{style:ee.headerBtns,"data-tour":"header-btns",children:[a.jsxs("button",{style:ee.btn,onClick:()=>b(!0),title:"Save or restore a session",children:[a.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[a.jsx("path",{d:"M2 2h8v8H2z"}),a.jsx("path",{d:"M4 2v4h4V2"}),a.jsx("path",{d:"M5 3h2"})]}),"Save Session"]}),a.jsxs("button",{style:ee.btn,onClick:()=>m(!0),title:"Customize color theme",children:[a.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",style:{flexShrink:0},children:[a.jsx("rect",{x:"0",y:"0",width:"5.5",height:"5.5",rx:"1",fill:"#66bb6a"}),a.jsx("rect",{x:"6.5",y:"0",width:"5.5",height:"5.5",rx:"1",fill:"#42a5f5"}),a.jsx("rect",{x:"0",y:"6.5",width:"5.5",height:"5.5",rx:"1",fill:"#ffa726"}),a.jsx("rect",{x:"6.5",y:"6.5",width:"5.5",height:"5.5",rx:"1",fill:"#ab47bc"})]}),"Theme"]}),a.jsxs("button",{"data-tour":"btn-export",style:{...ee.btn,...n&&l.length>0?{}:{opacity:.35,cursor:"default"}},onClick:()=>{n&&l.length>0&&S(!0)},title:"Export current view as SVG or PNG",children:[a.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:a.jsx("path",{d:"M6 1v7M3 5.5L6 8.5 9 5.5M2 11h8"})}),"Export Image"]}),a.jsxs("button",{"data-tour":"btn-settings",style:{...ee.btn,...l.length===0?{opacity:.35,cursor:"default"}:{}},onClick:()=>{l.length>0&&f(!0)},title:"Adjust height, scale, color, and bar width for tracks",children:["⚙"," Track Settings"]})]})]}),a.jsx(O0,{}),a.jsx(wy,{}),a.jsxs("div",{style:ee.trackArea,ref:T,"data-tour":"track-area",children:[l.filter(J).length===0&&a.jsx(Xy,{theme:e,labelWidth:H}),t?n?a.jsxs(a.Fragment,{children:[a.jsxs("div",{style:{display:"flex"},children:[a.jsx("div",{style:{width:H,minWidth:H,background:e.panelBg,borderRight:`1px solid ${e.border}`,position:"relative"},children:a.jsx("div",{onMouseDown:V,style:{position:"absolute",right:-3,top:0,bottom:0,width:6,cursor:"ew-resize",zIndex:10},onMouseEnter:z=>z.currentTarget.style.background="rgba(255,255,255,0.15)",onMouseLeave:z=>z.currentTarget.style.background="transparent"})}),a.jsx(Sy,{width:v-H})]}),l.filter(J).map(z=>a.jsx(Uy,{track:z,containerWidth:v,labelWidth:H,onLabelResizeStart:V,isDragging:U===z.id,isDropTarget:G===z.id,onDragStart:()=>O(z.id),onDragOver:()=>F(z.id),onDrop:()=>{U&&U!==z.id&&i(U,z.id),O(null),F(null)},onDragEnd:()=>{O(null),F(null)}},z.id)),l.length===0&&a.jsx("div",{style:{padding:24,color:e.textMuted,fontSize:13},children:"Add tracks above — BAM, VCF, BigWig, BED, GTF, GFF, WIG..."})]}):a.jsx("div",{style:ee.emptyState,children:a.jsx("div",{style:ee.emptyHint,children:"Select a chromosome to begin"})}):a.jsxs("div",{style:ee.emptyState,children:[a.jsx("div",{style:ee.emptyTitle,children:"No genome loaded"}),a.jsx("div",{style:ee.emptyHint,children:"Load a FASTA or GenBank file above to get started"})]})]}),x&&a.jsx(U0,{onClose:()=>f(!1)}),p&&a.jsx(Y0,{onClose:()=>m(!1)}),w&&a.jsx(ny,{onClose:()=>S(!1)}),E&&a.jsx(gy,{onClose:()=>b(!1),labelWidth:H,setLabelWidth:j}),$&&a.jsx(vy,{onClose:()=>{_(!1),f(!1),m(!1)},theme:e,onAction:z=>{z==="open-settings"?(f(!0),m(!1)):z==="open-theme"?(m(!0),f(!1)):(f(!1),m(!1))}}),P&&a.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.6)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999},onClick:()=>N(!1),children:a.jsxs("div",{style:{background:e.panelBg,border:`1px solid ${e.border}`,borderRadius:8,padding:"28px 36px",maxWidth:520,maxHeight:"85vh",overflowY:"auto",color:e.textPrimary,lineHeight:1.7},onClick:z=>z.stopPropagation(),children:[a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:16},children:[a.jsx(Mc,{size:44}),a.jsx("div",{style:{fontSize:20,fontWeight:700},children:"BiNgo Genome Viewer"})]}),a.jsxs("div",{style:{fontSize:13,color:e.textSecondary,marginBottom:12},children:[a.jsx("strong",{style:{color:e.textPrimary},children:"Version:"})," ",Lc]}),a.jsxs("div",{style:{fontSize:13,color:e.textSecondary,marginBottom:12},children:[a.jsx("strong",{style:{color:e.textPrimary},children:"Publisher:"})," Billy M Ngo"]}),a.jsxs("div",{style:{fontSize:13,color:e.textSecondary,marginBottom:20},children:[a.jsx("strong",{style:{color:e.textPrimary},children:"Published:"})," April 2026"]}),a.jsxs("div",{style:{fontSize:12,color:e.textSecondary,background:e.canvasBg,border:`1px solid ${e.border}`,borderRadius:4,padding:"10px 14px",fontFamily:"monospace",lineHeight:1.6,marginBottom:20,userSelect:"all"},children:["Ngo, B.M. (2026). BiNgo Genome Viewer (v",Lc,") [Software]."]}),a.jsxs("details",{style:{marginBottom:20},children:[a.jsx("summary",{style:{cursor:"pointer",fontSize:13,fontWeight:600,color:e.textPrimary,marginBottom:8},children:"References & Acknowledgments"}),a.jsxs("div",{style:{fontSize:11,color:e.textSecondary,lineHeight:1.8,paddingTop:8},children:[a.jsx("div",{style:{fontWeight:600,color:e.textPrimary,marginBottom:4},children:"Software Dependencies"}),a.jsxs("div",{children:[a.jsx("strong",{children:"FastAPI"})," ","—"," Ram","í","rez, S. (2018). A modern web framework for building APIs with Python."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"Uvicorn"})," ","—"," Encode OSS. ASGI server implementation for Python."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"BioPython"})," ","—"," Cock, P.J.A. et al. (2009). ",a.jsx("em",{children:"Bioinformatics"}),", 25(11), 1422","–","1423."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"pyfaidx"})," ","—"," Shirley, M.D. et al. (2015). ",a.jsx("em",{children:"PeerJ PrePrints"}),", 3:e1196."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"bamnostic"})," ","—"," Sherman, M.A. & Mills, R.E. (2019). Pure Python BAM parser."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"React"})," ","—"," Meta Platforms, Inc. JavaScript UI library."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"Vite"})," ","—"," You, E. (2020). Next generation frontend tooling."]}),a.jsx("div",{style:{fontWeight:600,color:e.textPrimary,marginTop:12,marginBottom:4},children:"File Format Specifications"}),a.jsxs("div",{children:[a.jsx("strong",{children:"SAM/BAM"})," ","—"," Li, H. et al. (2009). ",a.jsx("em",{children:"Bioinformatics"}),", 25(16), 2078","–","2079."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"VCF"})," ","—"," Danecek, P. et al. (2011). ",a.jsx("em",{children:"Bioinformatics"}),", 27(15), 2156","–","2158."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"BigWig/WIG"})," ","—"," Kent, W.J. et al. (2010). ",a.jsx("em",{children:"Bioinformatics"}),", 26(17), 2204","–","2207."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"BED"})," ","—"," UCSC Genome Browser, UC Santa Cruz."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"GFF3"})," ","—"," Sequence Ontology Project."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"GTF"})," ","—"," Ensembl genome database project."]}),a.jsxs("div",{children:[a.jsx("strong",{children:"GenBank"})," ","—"," Benson, D.A. et al. (2013). ",a.jsx("em",{children:"Nucleic Acids Res."}),", 41(D1), D36","–","D42."]}),a.jsx("div",{style:{fontWeight:600,color:e.textPrimary,marginTop:12,marginBottom:4},children:"Inspiration"}),a.jsxs("div",{children:[a.jsx("strong",{children:"IGV"})," ","—"," Robinson, J.T. et al. (2011). ",a.jsx("em",{children:"Nature Biotechnology"}),", 29(1), 24","–","26."]}),a.jsx("div",{style:{fontWeight:600,color:e.textPrimary,marginTop:12,marginBottom:4},children:"Acknowledgments"}),a.jsx("div",{children:"Early version testing and feedback:"}),a.jsx("div",{children:"Amanda Antoch, Isaac Poarch, Otto Chipashvili, Jake Colautti"})]})]}),a.jsx("div",{style:{textAlign:"right"},children:a.jsx("button",{onClick:()=>N(!1),style:{background:e.btnBg,border:`1px solid ${e.borderStrong}`,borderRadius:4,color:e.btnText,padding:"5px 18px",cursor:"pointer",fontSize:12,fontWeight:600},children:"Close"})})]})}),R&&(()=>{const z=R.files.length>1,q=R.files.map(Q=>Q.name).join(", ");return a.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.45)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999},children:a.jsxs("div",{style:{background:e.panelBg,border:`1px solid ${e.borderAccent}`,borderRadius:8,padding:"20px 24px",maxWidth:440,width:"90%",boxShadow:"0 8px 32px rgba(0,0,0,0.5)"},onClick:Q=>Q.stopPropagation(),children:[a.jsxs("div",{style:{fontSize:14,fontWeight:700,color:e.textPrimary,marginBottom:8},children:["Genome file",z?"s":""," detected"]}),a.jsxs("div",{style:{fontSize:12,color:e.textSecondary,lineHeight:1.6,marginBottom:16},children:[a.jsx("strong",{style:{color:e.textPrimary},children:q}),z?" appear to be genome files. A genome is already loaded.":" appears to be a genome file. A genome is already loaded.",a.jsx("br",{}),"How would you like to handle ",z?"them":"it","?"]}),a.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",flexWrap:"wrap"},children:[a.jsx("button",{onClick:()=>k(null),style:{background:e.btnBg,border:`1px solid ${e.borderStrong}`,borderRadius:4,color:e.btnText,padding:"5px 16px",cursor:"pointer",fontSize:12,fontWeight:600},children:"Skip"}),a.jsxs("button",{onClick:Je,style:{background:e.btnBg,border:`1px solid ${e.borderStrong}`,borderRadius:4,color:e.btnText,padding:"5px 16px",cursor:"pointer",fontSize:12,fontWeight:600},children:["Add as Track",z?"s":""]}),a.jsxs("button",{onClick:Ne,style:{background:"#1976d2",border:"none",borderRadius:4,color:"#fff",padding:"5px 16px",cursor:"pointer",fontSize:12,fontWeight:600},children:["Add as Chromosome",z?"s":""]})]})]})})})(),D&&a.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.45)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999},children:a.jsxs("div",{style:{background:e.panelBg,border:`1px solid ${e.borderAccent}`,borderRadius:8,padding:"20px 24px",maxWidth:480,width:"90%",boxShadow:"0 8px 32px rgba(0,0,0,0.5)"},onClick:z=>z.stopPropagation(),children:[a.jsx("div",{style:{fontSize:14,fontWeight:700,color:e.textPrimary,marginBottom:8},children:"Track compatibility warning"}),a.jsxs("div",{style:{fontSize:12,color:e.textSecondary,lineHeight:1.6,marginBottom:16},children:[D.tracks.map(z=>{var q;return a.jsxs("div",{style:{marginBottom:6},children:[a.jsx("strong",{style:{color:e.textPrimary},children:z.name})," — ",((q=z.compatibility)==null?void 0:q.message)||"Possible mismatch with loaded genome"]},z.id)}),a.jsx("div",{style:{marginTop:8},children:D.tracks.length>1?"These tracks may not match the loaded genome.":"This track may not match the loaded genome."})]}),a.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",flexWrap:"wrap"},children:[a.jsx("button",{onClick:he,style:{background:e.btnBg,border:`1px solid ${e.borderStrong}`,borderRadius:4,color:e.btnText,padding:"5px 16px",cursor:"pointer",fontSize:12,fontWeight:600},children:"Skip"}),a.jsx("button",{onClick:ht,style:{background:"#1976d2",border:"none",borderRadius:4,color:"#fff",padding:"5px 16px",cursor:"pointer",fontSize:12,fontWeight:600},children:"Load Anyway"})]})]})}),B&&a.jsx("div",{style:{position:"fixed",inset:0,zIndex:9998,background:"rgba(0,0,0,0.45)",display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none"},children:a.jsxs("div",{style:{border:`3px dashed ${e.textSecondary}`,borderRadius:16,padding:"40px 60px",textAlign:"center"},children:[a.jsx("div",{style:{fontSize:28,fontWeight:300,color:e.textPrimary,marginBottom:8},children:"Drop files here"}),a.jsx("div",{style:{fontSize:13,color:e.textSecondary},children:"Genome (.gb, .fasta) or track files (.bam, .bw, .wig, .vcf, .bed, .gff, .gtf)"})]})}),I&&a.jsx("div",{style:{position:"fixed",bottom:20,left:"50%",transform:"translateX(-50%)",zIndex:10001,padding:"8px 20px",borderRadius:6,background:I.error?"#c62828":e.panelBg,border:`1px solid ${I.error?"#e53935":e.borderAccent}`,color:I.error?"#fff":"#81c784",fontSize:12,fontWeight:600,boxShadow:"0 4px 16px rgba(0,0,0,0.5)"},children:I.error||I.msg}),t&&a.jsx(Yy,{labelWidth:H})]})}function qy(){return a.jsx(A0,{children:a.jsx(Jm,{children:a.jsx(L0,{children:a.jsx(Ky,{})})})})}Ni.createRoot(document.getElementById("root")).render(a.jsx(Is.StrictMode,{children:a.jsx(qy,{})}));
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
body { font-family: Arial, Helvetica, sans-serif; background: #1a1a1a; color: #e0e0e0; height: 100vh; overflow: hidden; }
|
|
11
11
|
#root { height: 100vh; display: flex; flex-direction: column; }
|
|
12
12
|
</style>
|
|
13
|
-
<script type="module" crossorigin src="/assets/index-
|
|
13
|
+
<script type="module" crossorigin src="/assets/index-Dz6JKlYK.js"></script>
|
|
14
14
|
</head>
|
|
15
15
|
<body>
|
|
16
16
|
<div id="root"></div>
|
|
@@ -24,7 +24,7 @@ from api.genome import router as genome_router
|
|
|
24
24
|
from api.tracks import router as tracks_router
|
|
25
25
|
from api.data import router as data_router
|
|
26
26
|
|
|
27
|
-
app = FastAPI(title="BiNgo Genome Viewer API", version="2.2.
|
|
27
|
+
app = FastAPI(title="BiNgo Genome Viewer API", version="2.2.7")
|
|
28
28
|
|
|
29
29
|
app.add_middleware(
|
|
30
30
|
CORSMiddleware,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|