import{n as D,a as S}from"./CCHOD-L1.js";import{p as w,t as R,g as m,d as h,a as F}from"./Db_QKtB5.js";import{c as d,C as U}from"./OyE1vH6U.js";import{p as C}from"./BkOFT6Jj.js";function B(c){if(typeof document>"u")return{r:0,g:0,b:0,a:255};const e=document.createElement("canvas");e.width=1,e.height=1;const t=e.getContext("2d",{willReadFrequently:!0});if(!t)return console.error("Failed to get context for color parsing, returning default black"),{r:0,g:0,b:0,a:255};t.fillStyle=c,t.fillRect(0,0,1,1);try{const a=t.getImageData(0,0,1,1).data;return{r:a[0],g:a[1],b:a[2],a:a[3]}}catch(a){return console.error("Failed to getImageData for color parsing, returning default black:",a),{r:0,g:0,b:0,a:255}}}function N(c,e,t){const a=c.reduce((n,f)=>n+f,0),r=Math.ceil(a/e);if(e<=0||r<=0||!Number.isFinite(e)||!Number.isFinite(r))return{dataUrl:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",height:0};if(typeof document>"u")throw new Error("Canvas API (document) not available. Ensure tests mock the DOM and Canvas.");const A=document.createElement("canvas");A.width=e,A.height=r;const i=A.getContext("2d",{willReadFrequently:!0});if(!i)throw new Error("Failed to get canvas 2D context. Check canvas support or mocks.");if(typeof i.createImageData!="function"||typeof i.putImageData!="function")throw new Error("Canvas context mock is incomplete. Missing 'createImageData' or 'putImageData'. Please update test environment mocks (e.g., jest-canvas-mock).");let o;try{o=i.createImageData(e,r)}catch(n){throw console.error(`Error calling ctx.createImageData(${e}, ${r}). Check mock implementation.`,n),n}const l=o.data,p=l.length,{r:b,g:k,b:x,a:E}=B(t);let g=0,s=0;c.forEach((n,f)=>{if(n===0)return;if(f%2!==0){const I=g+n;for(;g<I;){const v=Math.floor(g/e),y=g%e;s=(v*e+y)*4,s>=0&&s<p-3&&(l[s]=b,l[s+1]=k,l[s+2]=x,l[s+3]=E),g++}}else g+=n}),i.putImageData(o,0,0);let u="";try{u=A.toDataURL()}catch(n){console.error("Error calling canvas.toDataURL(). Check mock implementation.",n),u="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="}return{dataUrl:u,height:r}}var V=D('<image x="0" y="0"></image>');function q(c,e){w(e,!0);const t=C(e,"colorFill",3,"rgba(255, 0, 0, 0.2)"),a=C(e,"opacity",3,.4);if(!e.segmentation)throw new Error("Segmentation data is required");const r=h(()=>{const l=t().replace(/rgba?\((\d+,\s*\d+,\s*\d+)(?:,\s*[\d.]+)?\)/,"rgb($1)");return N(e.segmentation,e.width,l)}),A=h(()=>m(r).dataUrl),i=h(()=>m(r).height);var o=V();R(()=>{d(o,"href",m(A)),d(o,"width",e.width),d(o,"height",m(i)),d(o,"opacity",a())}),S(c,o),F()}function K(c,e){const t=C(e,"isSelected",3,!1);U(c,{get checked(){return t()},get onCheckedChange(){return e.onSelect}})}export{q as S,K as a};
