import{c as I,u as A,a3 as L}from"./rpcWorker-CVTx5FIM.js";import{s as V,f as U,g as $,a as B,b as F}from"./color-DlNyb7sX.js";function T(t,a,n,o,r,c){n<0&&(t+=n,n=-n),o<0&&(a+=o,o=-o),c&&(r.fillStyle=c),r.fillRect(t,a,n,o)}function y(t,a,n,o,r,c){n<0&&(t+=n,n=-n),o<0&&(a+=o,o=-o),c&&(r.strokeStyle=c),r.strokeRect(t,a,n,o)}function j({ctx:t,self:a,chainData:n,view:o,asm:r}){var c,u,h,C,S;const M=[],R=[],{chains:b}=n,{height:x}=a,k=I.getConf(a,"featureHeight");for(const g of b){let s=Number.MAX_VALUE,e=Number.MIN_VALUE;for(const i of g){const d=r.getCanonicalRefName(i.refName)||i.refName,l=(c=o.bpToPx({refName:d,coord:i.start}))===null||c===void 0?void 0:c.offsetPx,m=(u=o.bpToPx({refName:d,coord:i.end}))===null||u===void 0?void 0:u.offsetPx;l!==void 0&&m!==void 0&&(s=Math.min(s,l),e=Math.max(e,m))}const f=Math.abs(e-s);M.push(f),R.push(s)}const E=Math.log(A.max(M)),H=Math.max(Math.log(A.min(M))-1,0),O=(x-20)/(E-H),z=k/2-.5;for(let g=0;g<b.length;g++){const s=b[g],e=M[g],f=(Math.log(e)-H)*O,i=R[g];T(i-o.offsetPx,f+z,e,1,t,"black");const d=s[0];let l;d.flags&2048?l=((h=d.SA)===null||h===void 0?void 0:h.split(";")[0].split(",")[2])==="-"?-1:1:l=d.strand;for(const m of s){const p=r.getCanonicalRefName(m.refName)||m.refName,N=(C=o.bpToPx({refName:p,coord:m.start}))===null||C===void 0?void 0:C.offsetPx,_=(S=o.bpToPx({refName:p,coord:m.end}))===null||S===void 0?void 0:S.offsetPx;if(N!==void 0&&_!==void 0){const v=Math.max(_-N,2),P=N-o.offsetPx,D=m.strand*l===-1?"color_rev_strand":"color_fwd_strand";y(P,f,v,k,t,V[D]),T(P,f,v,k,t,U[D])}}}}function q({ctx:t,self:a,chainData:n,view:o,asm:r}){var c,u,h,C,S,M,R;const b=[],x=I.getConf(a,"featureHeight"),k=((c=a.colorBy)===null||c===void 0?void 0:c.type)||"insertSizeAndOrientation",{chains:E,stats:H}=n;for(const s of E)if(s.length>1){const e=s[0],f=s[1],i=r.getCanonicalRefName(e.refName)||e.refName,d=r.getCanonicalRefName(f.refName)||f.refName,l=(u=o.bpToPx({refName:i,coord:e.start}))===null||u===void 0?void 0:u.offsetPx,m=(h=o.bpToPx({refName:i,coord:e.end}))===null||h===void 0?void 0:h.offsetPx,p=(C=o.bpToPx({refName:d,coord:f.start}))===null||C===void 0?void 0:C.offsetPx,N=(S=o.bpToPx({refName:d,coord:f.end}))===null||S===void 0?void 0:S.offsetPx;let _=0;if(l!==void 0&&m!==void 0&&p!==void 0&&N!==void 0){if(e.refName===f.refName){const v=Math.min(e.start,f.start),P=Math.max(e.end,f.end);_=Math.abs(P-v)}b.push({r1s:l,r1e:m,r2s:p,r2e:N,v0:e,v1:f,distance:_})}}else if(a.drawSingletons){const e=s[0],f=r.getCanonicalRefName(e.refName)||e.refName,i=(M=o.bpToPx({refName:f,coord:e.start}))===null||M===void 0?void 0:M.offsetPx,d=(R=o.bpToPx({refName:f,coord:e.end}))===null||R===void 0?void 0:R.offsetPx;if(i!==void 0&&d!==void 0){const l=Math.max(d-i,2);T(i-o.offsetPx,0,l,x,t,"#f00"),y(i-o.offsetPx,0,l,x,t,"#a00")}}const O=Math.log(A.max(b.map(s=>s.distance))),z=Math.max(Math.log(A.min(b.map(s=>s.distance)))-1,0),g=(a.height-20)/(O-z);for(const{r1e:s,r1s:e,r2e:f,r2s:i,distance:d,v0:l,v1:m}of b){const p=Math.max(s-e,2),N=Math.max(f-i,2),[_,v]=G({type:k,v0:l,v1:m,stats:H})||[],P=(Math.log(d)-z)*g,X=x/2-.5,D=i-s;T(s-o.offsetPx,P+X,D,1,t,"black"),y(e-o.offsetPx,P,p,x,t,v),y(i-o.offsetPx,P,N,x,t,v),T(e-o.offsetPx,P,p,x,t,_),T(i-o.offsetPx,P,N,x,t,_)}}function G({type:t,v0:a,v1:n,stats:o}){if(t==="insertSizeAndOrientation")return $(a,n,o);if(t==="orientation")return B(a);if(t==="insertSize")return F(a,n,o);if(t==="gradient"){const r=Math.min(a.start,n.start),c=Math.max(a.end,n.end);return[`hsl(${Math.log10(Math.abs(c-r))*10},50%,50%)`,`hsl(${Math.log10(Math.abs(c-r))*10},50%,30%)`]}}function Q(t,a){const{chainData:n}=t;if(!n)return;const{assemblyManager:o}=A.getSession(t),r=A.getContainingView(t),c=r.assemblyNames[0],u=o.get(c);if(!u)return;L(n)?q({self:t,view:r,asm:u,ctx:a,chainData:n}):j({self:t,view:r,asm:u,ctx:a,chainData:n})}export{Q as drawFeats};
