import{t as b,r as y,a as _}from"./BQSWrPvQ.js";import{p as u,t as w,a as v,e as A}from"./BlPzMKBp.js";import{f as S,c as j,a as g}from"./DE1eCaeQ.js";import{p,r as F,b as M}from"./BZbDFF1N.js";import{P as O}from"./Bk6sjZbM.js";import{g as d}from"./pKKESLv8.js";const P=({ctx:e,coords:{x:t,y:a,width:s,height:l},colors:{stroke:n,fill:i,textBackground:h,text:o},labelText:c,lineWidth:f=2})=>{if(e.beginPath(),e.strokeStyle=n,e.lineWidth=f,e.strokeRect(t,a,s,l),e.fillStyle=i,e.fillRect(t,a,s,l),c){e.fillStyle=h,e.font="18px Arial bold";const m=e.measureText(c);e.fillRect(t-1,a-21,m.width+14,20),e.fillStyle=o,e.fillText(c,t+6,a-6);return}e.closePath()},k=({annotation:e,imageBox:t,containerBox:a,objectFit:s="contain"})=>{const l=a.width/a.height,n=t.width/t.height;let i,h=0,o=0;return n===l?i=a.width/t.width:s==="cover"?i=Math.max(a.width/t.width,a.height/t.height):i=Math.min(a.width/t.width,a.height/t.height),h=(a.width-t.width*i)/2,o=(a.height-t.height*i)/2,{x:Math.ceil(e.x*i+h),y:Math.ceil(e.y*i+o),width:Math.ceil(e.width*i),height:Math.ceil(e.height*i)}},C=({canvas:e,annotations:t,imageBox:a,containerBox:s,sampleImageObjectFit:l="contain",renderOptions:{showLabels:n=!1}={}})=>{if(e){const i=e.getContext("2d");if(!i)return;t.forEach(h=>{const{x:o,y:c,width:f,height:m}=k({annotation:h,imageBox:a,containerBox:s,objectFit:l});if(h.annotation_label&&i){const r=h.annotation_label.annotation_label_name;P({ctx:i,coords:{x:o,y:c,width:f,height:m},colors:{stroke:d(r,1).color,fill:d(r,.3).color,text:d(r,1).contrastColor,textBackground:d(r,.8).color},labelText:n?r:void 0})}}),i.closePath()}};var I=b("<img>");function U(e,t){u(t,!0);const a=p(t,"objectFit",3,"contain"),s=F(t,["$$slots","$$events","$$legacy","sample","objectFit"]),{class:l,...n}=s;var i=I();let h;w(o=>h=j(i,h,{src:O+t.sample.file_path_abs,alt:t.sample.file_path_abs,class:o,decoding:"async",style:`--object-fit: ${a()??""}`,loading:"lazy",...n},"svelte-1c6bz0a"),[()=>S("sample-image rounded-lg bg-black",l)]),y(i),_(e,i),v()}var R=b('<canvas class="canvas svelte-1bh4ey0"></canvas>');function N(e,t){u(t,!0);const a=p(t,"sampleImageObjectFit",3,"contain");let s;A(()=>(C({canvas:s,sampleImageObjectFit:a(),annotations:t.sample.annotations,imageBox:{width:t.sample.width,height:t.sample.height},containerBox:{width:t.containerWidth,height:t.containerHeight},renderOptions:t.renderOptions}),()=>{const n=s.getContext("2d");n==null||n.clearRect(0,0,t.containerWidth,t.containerHeight)}));var l=R();M(l,n=>s=n,()=>s),w(()=>{g(l,"width",t.containerWidth),g(l,"height",t.containerHeight)}),_(e,l),v()}export{U as S,N as a};
