1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7668],{17668:(e,t,r)=>{let a;r.d(t,{A:()=>Y});var s=r(18813),n=r(77641),l=r(51975),i=r(18004),o=r(85353),d=r(94511),c=r(36593),m=r(81708),u=r(24311),p=r(35944),h=r(38098),x=r(92321),g=r(45706),f=r(72216),b=r(65356),w=r(75582),j=r(93054),v=r(1357),y=r(30280);let k={jpg:"image/jpeg",png:"image/png",webp:"image/webp"},N=async e=>{if(e instanceof Blob)return e;let t=await fetch(e,{mode:"cors"});if(!t.ok)throw Error("Unable to load the source image");return t.blob()};function _(e,t){return Math.floor((4===e&&t?16e6:36e6)/(e*e))}function U(e,t,r,a){if(!Number.isInteger(e)||!Number.isInteger(t)||e<1||t<1)throw Error("Invalid image dimensions");let s=_(r,a)*r*r,n=a?8192:16384,l=Math.min(r,Math.sqrt(s/(e*t)),n/e,n/t),i=Math.max(1,Math.floor(e*l)),o=Math.max(1,Math.floor(t*l));return{outputWidth:i,outputHeight:o,actualScale:Math.min(i/e,o/t),adjusted:i!==e*r||o!==t*r}}let R=e=>new Promise((t,r)=>{let a=URL.createObjectURL(e),s=document.createElement("img"),n=()=>URL.revokeObjectURL(a);s.onload=()=>{t({source:s,width:s.naturalWidth,height:s.naturalHeight,close:n})},s.onerror=()=>{n(),r(Error("Unable to decode image in this browser"))},s.src=a}),C=async e=>{if("function"==typeof createImageBitmap)try{let t=await createImageBitmap(e);return{source:t,width:t.width,height:t.height,close:()=>t.close()}}catch(e){}return R(e)},E=(e,t)=>new Promise((r,a)=>{e.toBlob(e=>e?r(e):a(Error("The browser could not encode the enhanced image")),k[t],"png"===t?void 0:.94)});async function L(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"png",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if("undefined"==typeof document)throw Error("Browser image upscaling is unavailable");let s=performance.now(),n=await N(e),l=await C(n);try{let e=l.width,n=l.height,i=U(e,n,r,!!a.isMobile),o=a.fitLargeImages?i.outputWidth:e*r,d=a.fitLargeImages?i.outputHeight:n*r;if(o*d>36e6)throw Error("The image is too large for browser upscaling");let c=document.createElement("canvas");c.width=o,c.height=d;let m=c.getContext("2d",{alpha:"jpg"!==t});if(!m)throw Error("Canvas is unavailable");return"jpg"===t&&(m.fillStyle="#ffffff",m.fillRect(0,0,o,d)),m.imageSmoothingEnabled=!0,m.imageSmoothingQuality="high",m.filter="contrast(1.04) saturate(1.025)",m.drawImage(l.source,0,0,o,d),m.filter="none",{blob:await E(c,t),inputWidth:e,inputHeight:n,outputWidth:o,outputHeight:d,actualScale:a.fitLargeImages?i.actualScale:r,adjusted:!!(a.fitLargeImages&&i.adjusted),durationMs:Math.max(0,Math.round(performance.now()-s))}}finally{l.close()}}let M=new Map,I={},S=0,A=Promise.resolve();function z(e,t){var r;for(let[a,s]of(null===(r=I[e])||void 0===r||r.terminate(),delete I[e],M))a.startsWith("".concat(e,"-"))&&(clearTimeout(s.timer),s.reject(Error(t)),M.delete(a))}async function P(e,t,r,a){let s;for(let n=0;n<2;n++)try{return await function(e,t,r){let a=function(e){if("undefined"==typeof Worker||"undefined"==typeof WebAssembly)throw Error("This browser cannot run local image processing");if(I[e])return I[e];let t=new Worker("background"===e?"/workers/browser-image-tools-background-remover.js":"/workers/browser-image-tools-image-cleanup.js",{name:"whisk-".concat(e)});return t.onmessage=t=>{var r;let a=M.get(t.data.id);a&&(clearTimeout(a.timer),M.delete(t.data.id),t.data.ok&&(null===(r=t.data.blob)||void 0===r?void 0:r.size)?a.resolve({blob:t.data.blob,modelTier:t.data.modelTier||e,runtimeWarm:!0===t.data.runtimeWarm}):a.reject(Error(t.data.error||"Browser processing failed")))},t.onerror=t=>z(e,t.message||"Image worker crashed"),t.onmessageerror=()=>z(e,"Image worker returned unreadable data"),I[e]=t,t}(e),s="".concat(e,"-").concat(Date.now(),"-").concat(++S);return new Promise((n,l)=>{let i=window.setTimeout(()=>{M.delete(s),z(e,"Browser processing timed out"),l(Error("Browser processing timed out"))},r);M.set(s,{resolve:n,reject:l,timer:i}),a.postMessage({id:s,...t})})}(e,t,r)}catch(t){s=t,null==a||a(t instanceof Error?t:Error(String(t)),n+1),z(e,t instanceof Error?t.message:"Image worker failed")}throw s}function T(e){let t=A.then(e);return A=t.catch(()=>void 0),t}function O(e){try{var t;let r=JSON.stringify({event_id:crypto.randomUUID(),request_id:e.requestId,anonymous_id:function(){if(a)return a;try{let e=sessionStorage.getItem("kiling-browser-tool-id");if(e&&/^[0-9a-f-]{36}$/i.test(e))return e;return a=crypto.randomUUID(),sessionStorage.setItem("kiling-browser-tool-id",a),a}catch(e){return a=crypto.randomUUID()}}(),operation:e.operation,event_type:e.eventType,status:"processing_started"===e.eventType?"processing":"processing_completed"===e.eventType?"completed":"failed",input_width:e.inputWidth,input_height:e.inputHeight,output_width:e.outputWidth,output_height:e.outputHeight,source_bytes:e.sourceBytes,output_bytes:e.outputBytes,duration_ms:null!==(t=e.durationMs)&&void 0!==t?t:0,attempt:e.attempt,model_tier:e.modelTier,runtime_warm:e.runtimeWarm,scale:e.scale,output_format:e.outputFormat,...void 0===e.error?{}:function(e){let t=e instanceof Error?e.message:String(e),r=t.toLowerCase(),a=r.includes("timeout")||r.includes("timed out")?["inference_timeout","inference"]:r.includes("memory")||r.includes("allocation")?["memory_exhausted","inference"]:r.includes("integrity")?["model_integrity_failed","model_load"]:r.includes("model")&&(r.includes("load")||r.includes("download"))?["model_load_failed","model_load"]:r.includes("wasm")||r.includes("webassembly")?["wasm_unavailable","runtime_init"]:r.includes("worker")?["worker_failed","runtime_init"]:r.includes("mask")?["mask_failed","mask_decode"]:r.includes("decode")||r.includes("source image")?["image_decode_failed","
1source_decode"]:r.includes("too large")?["input_too_large","validation"]:["processing_failed","inference"];return{error_code:a[0],error_phase:a[1],error_message:t.replace(/data:image\/[a-z0-9.+-]+;base64,[a-z0-9+/=]+/gi,"[image-data]").replace(/https?:\/\/\S+/gi,"[url]").replace(/\b[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}\b/gi,"[email]").replace(/\b[a-z0-9_-]{80,}\b/gi,"[redacted]").replace(/[\r\n\t]+/g," ").slice(0,300)}}(e.error),capabilities:function(){let e=navigator;return{worker:"undefined"!=typeof Worker,wasm:"undefined"!=typeof WebAssembly,offscreen_canvas:"undefined"!=typeof OffscreenCanvas,image_bitmap:"undefined"!=typeof createImageBitmap,indexed_db:"undefined"!=typeof indexedDB,mobile_viewport:matchMedia("(max-width: 767px)").matches,device_memory_gb:e.deviceMemory,hardware_concurrency:navigator.hardwareConcurrency}}(),page_path:location.pathname,locale:document.documentElement.lang||"en"});"function"==typeof navigator.sendBeacon&&navigator.sendBeacon("/api/browser-image-tools/events",new Blob([r],{type:"application/json"}))||fetch("/api/browser-image-tools/events",{method:"POST",headers:{"Content-Type":"application/json"},body:r,keepalive:!0}).catch(()=>void 0)}catch(e){}}var B=r(29545),W=r(30753);async function D(e){if(e.startsWith("blob:")||e.startsWith("data:")||e.startsWith("/")){let t=await fetch(e);if(!t.ok)throw Error("image_load_failed");return t.blob()}let t=await fetch("/api/download-image",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({imageUrl:e})});if(!t.ok)throw Error("image_load_failed");return t.blob()}function F(e){return new Promise((t,r)=>{let a=URL.createObjectURL(e),s=new window.Image;s.onload=()=>t({image:s,url:a}),s.onerror=()=>{URL.revokeObjectURL(a),r(Error("image_decode_failed"))},s.src=a})}function $(e){let{sourceUrl:t,cutoutUrl:r,imageName:a,copy:l}=e,i=(0,n.useRef)(null),o=(0,n.useRef)(null),d=(0,n.useRef)(null),c=(0,n.useRef)(null),p=(0,n.useRef)(null),h=(0,n.useRef)(null),g=(0,n.useRef)(e.onCancel),f=(0,n.useRef)(e.onError),w=(0,n.useRef)(l.saveFailed);g.current=e.onCancel,f.current=e.onError,w.current=l.saveFailed;
1let[j,v]=(0,n.useState)("erase"),[k,N]=(0,n.useState)(36),[_,U]=(0,n.useState)([]),[R,C]=(0,n.useState)(!0),[E,L]=(0,n.useState)(!1),M=(0,n.useCallback)(e=>{let t=i.current,r=o.current,a=c.current,s=p.current,n=null==t?void 0:t.getContext("2d"),l=null==a?void 0:a.getContext("2d"),d=null==s?void 0:s.getContext("2d");if(t&&r&&a&&s&&n&&l&&d){if(l.clearRect(0,0,a.width,a.height),!function(e,t){let r=t.points[0];if(r){if(e.strokeStyle="#fff",e.fillStyle="#fff",e.lineCap="round",e.lineJoin="round",e.lineWidth=t.size,1===t.points.length){e.beginPath(),e.arc(r.x,r.y,t.size/2,0,2*Math.PI),e.fill();return}e.beginPath(),e.moveTo(r.x,r.y),t.points.slice(1).forEach(t=>e.lineTo(t.x,t.y)),e.stroke()}}(l,e),"erase"===e.mode){n.save(),n.globalCompositeOperation="destination-out",n.drawImage(a,0,0),n.restore();return}d.clearRect(0,0,s.width,s.height),d.globalCompositeOperation="source-over",d.drawImage(r,0,0),d.globalCompositeOperation="destination-in",d.drawImage(a,0,0),d.globalCompositeOperation="source-over",n.drawImage(s,0,0)}},[]),I=(0,n.useCallback)(e=>{let t=i.current,r=d.current,a=null==t?void 0:t.getContext("2d");t&&r&&a&&(a.clearRect(0,0,t.width,t.height),a.drawImage(r,0,0),e.forEach(M))},[M]);(0,n.useEffect)(()=>{let e=!1,a=[];return(async()=>{try{var s,n,l;let[m,u]=await Promise.all([D(t),D(r)]),h=await F(m);a.push(h.url);let x=await F(u);if(a.push(x.url),e){a.splice(0).forEach(URL.revokeObjectURL);return}let g=i.current,f=x.image.naturalWidth,b=x.image.naturalHeight;if(!g||!f||!b)throw Error("invalid_image");let w=()=>{let e=document.createElement("canvas");return e.width=f,e.height=b,e},j=w(),v=w();null===(s=j.getContext("2d"))||void 0===s||s.drawImage(h.image,0,0,f,b),null===(n=v.getContext("2d"))||void 0===n||n.drawImage(x.image,0,0,f,b),o.current=j,d.current=v,c.current=w(),p.current=w(),g.width=f,g.height=b,null===(l=g.getContext("2d"))||void 0===l||l.drawImage(v,0,0)}catch(e){console.error("[CutoutEditor] load failed",e),f.current(w.current),g.current()}finally{e||C(!1)}})(),()=>{e=!0,a.forEach(URL.revokeObjectURL)}},[t,r]),(0,n.useEffect)(()=>{let e=e=>{"Escape"!==e.key||E||g.current()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[E]);let S=e=>{let t=i.current;if(!t)return null;let r=t.getBoundingClientRect();return{x:(e.clientX-r.left)/r.width*t.width,y:(e.clientY-r.top)/r.height*t.height}},A=()=>{let e=h.current;e&&(h.current=null,U(t=>[...t,e]))},z=async()=>{let t=i.current;if(t&&!E){L(!0);try{let r=await new Promise(e=>t.toBlob(e,"image/png"));if(!r)throw Error("export_failed");e.onApply(r)}catch(t){console.error("[CutoutEditor] save failed",t),e.onError(l.saveFailed)}finally{L(!1)}}};return(0,s.jsx)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-slate-950/80 p-3 backdrop-blur-sm",role:"dialog","aria-modal":"true","aria-label":l.title,children:(0,s.jsxs)("div",{className:"flex max-h-[96vh] w-full max-w-6xl flex-col overflow-hidden rounded-xl border border-border bg-card text-foreground shadow-2xl",children:[(0,s.jsxs)("div",{className:"flex items-start justify-between gap-3 border-b border-border px-4 py-3",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsxs)("h2",{className:"truncate font-semibold text-foreground",children:[(0,s.jsx)("span",{children:l.title}),(0,s.jsx)("span",{children:": "}),(0,s.jsx)("span",{className:"notranslate",translate:"no",children:a})]}),(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:(0,s.jsx)("span",{children:l.description})})]}),(0,s.jsx)(y.$,{variant:"ghost",size:"icon",onClick:e.onCancel,"aria-label":l.cancel,children:(0,s.jsx)(u.A,{className:"h-4 w-4"})})]}),(0,s.jsxs)("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-auto bg-background p-3 sm:p-5",children:[R&&(0,s.jsxs)("span",{className:"flex items-center gap-2 text-white",children:[(0,s.jsx)(x.A,{className:"h-4 w-4 animate-spin"}),(0,s.jsx)("span",{children:l.loading})]}),(0,s.jsx)("canvas",{ref:i,onPointerDown:e=>{let t=i.current,r=S(e);if(!t||!r||R||E)return;e.currentTarget.setPointerCapture(e.pointerId);let a=t.getBoundingClientRect(),s={mode:j,points:[r],size:k*t.width/
1Math.max(a.width,1)};h.current=s,M(s)},onPointerMove:e=>{let t=h.current,r=S(e);if(!t||!r)return;let a=t.points[t.points.length-1];t.points.push(r),M({...t,points:[a,r]})},onPointerUp:A,onPointerCancel:A,className:"max-h-[68vh] max-w-full touch-none rounded shadow-xl ".concat(R?"hidden":"block"),style:{backgroundColor:"#fff",backgroundImage:"linear-gradient(45deg,#e2e8f0 25%,transparent 25%),linear-gradient(-45deg,#e2e8f0 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#e2e8f0 75%),linear-gradient(-45deg,transparent 75%,#e2e8f0 75%)",backgroundPosition:"0 0,0 8px,8px -8px,-8px 0",backgroundSize:"16px 16px",cursor:"crosshair"}})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-3 border-t border-border p-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsxs)(y.$,{variant:"erase"===j?"default":"outline",onClick:()=>v("erase"),className:"erase"===j?"bg-primary text-primary-foreground hover:bg-primary/90":"",children:[(0,s.jsx)(B.A,{className:"mr-2 h-4 w-4"}),(0,s.jsx)("span",{children:l.erase})]}),(0,s.jsxs)(y.$,{variant:"restore"===j?"default":"outline",onClick:()=>v("restore"),className:"restore"===j?"bg-primary text-primary-foreground hover:bg-primary/90":"",children:[(0,s.jsx)(W.A,{className:"mr-2 h-4 w-4"}),(0,s.jsx)("span",{children:l.restore})]}),(0,s.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,s.jsx)("span",{children:l.brushSize}),(0,s.jsx)("input",{type:"range",min:"8",max:"120",step:"2",value:k,onChange:e=>N(Number(e.target.value)),className:"w-24 accent-primary"})]}),(0,s.jsxs)(y.$,{variant:"ghost",size:"sm",onClick:()=>U(e=>{let t=e.slice(0,-1);return I(t),t}),disabled:!_.length,children:[(0,s.jsx)(b.A,{className:"mr-1.5 h-4 w-4"}),(0,s.jsx)("span",{children:l.undo})]}),(0,s.jsxs)(y.$,{variant:"ghost",size:"sm",onClick:()=>{h.current=null,U([]),I([])},disabled:!_.length,children:[(0,s.jsx)(m.A,{className:"mr-1.5 h-4 w-4"}),(0,s.jsx)("span",{children:l.reset})]})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(y.$,{variant:"outline",onClick:e.onCancel,disabled:E,children:(0,s.jsx)("span",{children:l.cancel})}),(0,s.jsxs)(y.$,{onClick:z,disabled:R||E,className:"bg-primary text-primary-foreground hover:bg-primary/90",children:[E&&(0,s.jsx)(x.A,{className:"mr-2 h-4 w-4 animate-spin"}),(0,s.jsx)("span",{children:l.apply})]})]})]})]})})}let H=new Set(["image/jpeg","image/png","image/webp"]);function q(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"image/png";return new Promise((r,a)=>e.toBlob(e=>e?r(e):a(Error("Image export failed")),t))}async function J(e){let t=URL.createObjectURL(e);try{return await new Promise((e,r)=>{let a=new Image;a.onload=()=>e({width:a.naturalWidth,height:a.naturalHeight}),a.onerror=()=>r(Error("Unable to decode image")),a.src=t})}finally{URL.revokeObjectURL(t)}}async function G(e,t){let{width:r,height:a}=await J(e),s=document.createElement("canvas");s.width=r,s.height=a;let n=s.getContext("2d");if(!n)throw Error("Unable to create mask");for(let e of(n.fillStyle="#000",n.fillRect(0,0,r,a),n.fillStyle="#fff",t))n.beginPath(),n.arc(e.x*r/100,e.y*a/100,e.size*r/200,0,2*Math.PI),n.fill();return q(s)}async function X(e,t){if("transparent"===t)return e;let r=URL.createObjectURL(e),a=await new Promise((e,t)=>{let a=new Image;a.onload=()=>e(a),a.onerror=()=>t(Error("Unable to decode image")),a.src=r}).catch(e=>{throw URL.revokeObjectURL(r),e});try{let e=document.createElement("canvas");e.width=a.naturalWidth,e.height=a.naturalHeight;let r=e.getContext("2d");if(!r)throw Error("Canvas is unavailable");return r.fillStyle=t,r.fillRect(0,0,e.width,e.height),r.drawImage(a,0,0),q(e)}finally{URL.revokeObjectURL(r)}}function Y(e){let{mode:t}=e,r=(0,j.c3)("browser_tools"),a="upscale"===t?5:"background"===t?4:10,k="watermark"===t?0xa00000:0x1400000,N=(0,n.useRef)(null),R=(0,n.useRef)([]),C=(0,n.useRef)(!1),E=(0,n.useRef)(!1),M=(0,n.useRef)(null),I=(0,n.useRef)(""),[S,A]=(0,n.use
1State)([]),[z,B]=(0,n.useState)(!1),[W,D]=(0,n.useState)(!1),[F,q]=(0,n.useState)(2),[Y,Q]=(0,n.useState)("png"),[K,V]=(0,n.useState)(!1),[Z,ee]=(0,n.useState)(""),[et,er]=(0,n.useState)(42),[ea,es]=(0,n.useState)("transparent"),[en,el]=(0,n.useState)(""),ei=S.find(e=>e.id===Z),eo=S.find(e=>e.id===en),ed=S.filter(e=>"completed"===e.status&&e.outputBlob),ec=S.filter(e=>"failed"===e.status),em=S.filter(e=>"ready"===e.status||"failed"===e.status),eu=!K&&S.length>=5;(0,n.useEffect)(()=>{R.current=S},[S]),(0,n.useEffect)(()=>{let e=matchMedia("(max-width: 767px)"),t=()=>V(e.matches);return t(),e.addEventListener("change",t),()=>e.removeEventListener("change",t)},[]),(0,n.useEffect)(()=>()=>{R.current.forEach(e=>{URL.revokeObjectURL(e.previewUrl),e.outputUrl&&URL.revokeObjectURL(e.outputUrl)})},[]);let ep=(e,t)=>A(r=>r.map(r=>r.id===e?{...r,...t}:r)),eh=e=>{URL.revokeObjectURL(e.previewUrl),e.outputUrl&&URL.revokeObjectURL(e.outputUrl)},ex=e=>{C.current||A(t=>{let r=t.find(t=>t.id===e);return r&&eh(r),t.filter(t=>t.id!==e)})},eg=async e=>{if(C.current)return;let t=a-R.current.length,s=[];for(let a of e.slice(0,Math.max(0,t))){if(!H.has(a.type)){v.oR.error("".concat(a.name,": ").concat(r("file_type_error")));continue}if(a.size>k){v.oR.error("".concat(a.name,": ").concat(r("file_size_error",{size:k/1024/1024})));continue}try{let e=await J(a);s.push({id:crypto.randomUUID(),file:a,previewUrl:URL.createObjectURL(a),status:"ready",mask:[],backgroundFill:ea,...e})}catch(e){v.oR.error("".concat(a.name,": ").concat(r("processing_failed")))}}e.length>t&&v.oR.error(r("batch_limit",{max:a})),s.length&&A(e=>{let t=s.slice(0,a-e.length);s.slice(t.length).forEach(eh);let r=[...e,...t];return R.current=r,r})},ef=e=>{if(!ei)return;let t=e.currentTarget.getBoundingClientRect(),r={x:Math.max(0,Math.min(100,(e.clientX-t.left)/t.width*100)),y:Math.max(0,Math.min(100,(e.clientY-t.top)/t.height*100)),size:et/t.width*100,stroke:I.current},a=M.current,s=[];if(a){let e=Math.max(1,Math.ceil(Math.hypot(r.x-a.x,r.y-a.y)/Math.max(.4,r.size/4)));for(let t=1;t<=e;t++){let n=t/e;s.push({x:a.x+(r.x-a.x)*n,y:a.y+(r.y-a.y)*n,size:r.size,stroke:r.stroke})}}else s.push(r);M.current=r,A(e=>e.map(e=>e.id===ei.id?{...e,mask:[...e.mask,...s]}:e))},eb=async e=>{let a=performance.now(),s=crypto.randomUUID(),n={requestId:s,operation:t,inputWidth:e.width,inputHeight:e.height,sourceBytes:e.file.size,..."upscale"===t?{scale:F,outputFormat:Y}:{}};ep(e.id,{status:"processing",error:void 0,requestId:s}),O({...n,eventType:"processing_started",modelTier:"upscale"===t?"canvas-upscale-v2":void 0});try{var l,i,o;let s,d;let c="canvas-upscale-v2",m=F,u=e.width||0,p=e.height||0,h=(e,t)=>O({...n,eventType:"attempt_failed",attempt:t,durationMs:Math.round(performance.now()-a),error:e});if("upscale"===t){let t=await L(e.file,Y,F,{isMobile:K,fitLargeImages:!0});s=t.blob,u=t.outputWidth,p=t.outputHeight,m=Number(t.actualScale.toFixed(2)),t.adjusted&&(c="canvas-upscale-v2-adaptive")}else if("background"===t){let t=await (l=e.file,T(()=>P("background",{source:l,...function(){var e,t,r,a;let s=navigator;return(null===(e=s.connection)||void 0===e?void 0:e.saveData)?{preferredModel:"lite",reason:"save_data"}:["slow-2g","2g","3g"].includes((null===(t=s.connection)||void 0===t?void 0:t.effectiveType)||"")?{preferredModel:"lite",reason:"slow_network"}:"number"==typeof s.deviceMemory&&s.deviceMemory>0&&s.deviceMemory<=4?{preferredModel:"lite",reason:"low_memory"}:void 0===s.deviceMemory&&(null===(r=(a=window).matchMedia)||void 0===r?void 0:r.call(a,"(pointer: coarse)").matches)&&900>Math.min(window.screen.width,window.screen.height)?{preferredModel:"lite",reason:"mobile_memory_unknown"}:{preferredModel:"full",reason:"desktop_capable"}}()},6e4,h)));s=t.blob,c=t.modelTier,d=t.runtimeWarm}else{if(!e.mask.length)throw Error(r("select_watermark"));let t=await (i=e.file,o=await G(e.file,e.mask),T(()=>P("watermark",{source:i,mask:o,operation:"watermark_removal"},12e4,h)));s=t.blob,c=t.modelTier,d=t.runtimeWarm}let x=URL.createObjectURL(s);return ep(e.id,{status:"completed",outputBlob:s,outputUrl:x,outputWidth:u,outputHeight:p,..."upscale"===t?{outputFormat:Y,outputScale:m}:{}}),O({...n,eventType:"processing_completed",modelTier:c,runtimeWarm:d,outputWidth:u,outputHeight:p,outputBytes:s.size,durationMs:Math.round(performance.now()-a)}),!0}catch(t){return ep(e.id,{status:"failed",error:t instanceof Error?t.message:r("processing_failed")}),O({...n,eventType:"processing_failed",error:t,durationMs:Math.round(performance.now()-a)}),!1}},ew=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:em;if(!C.current&&e.length){if("watermark"===t){let t=e.find(e=>!e.mask.length);if(t){ee(t.id),v.oR.error(r("select_watermark"));return}}
1C.current=!0,D(!0),e.forEach(e=>ep(e.id,{status:"queued",error:void 0}));try{var a;let s="upscale"===t?(a=e.map(e=>({width:e.width,height:e.height})),K?1:a.some(e=>{let{width:t,height:r}=e;return!!t&&!!r&&t*r*F*F>16e6})?1:2):1,n=0,l=0;await Promise.all(Array.from({length:Math.min(s,e.length)},async()=>{for(;n<e.length;)await eb(e[n++])&&l++})),l===e.length?v.oR.success(r("complete")):v.oR.error(r("batch_partial",{completed:l,total:e.length}))}finally{C.current=!1,D(!1)}}},ej=async e=>{if(e.outputBlob)try{let r="background"===t?await X(e.outputBlob,e.backgroundFill||ea):e.outputBlob,a=URL.createObjectURL(r),s=document.createElement("a");s.href=a,s.download="kiling-".concat(t,"-").concat(e.file.name.replace(/\.[^.]+$/,""),".").concat("upscale"===t?e.outputFormat||Y:"png"),s.click(),window.setTimeout(()=>URL.revokeObjectURL(a),1e3)}catch(e){v.oR.error(r("processing_failed"))}},ev=async()=>{for(let e of ed)await ej(e),ed.length>1&&await new Promise(e=>window.setTimeout(e,300))},ey={upscale:r("upscale_title"),background:r("background_title"),watermark:r("watermark_title")},ek={upscale:r("upscale_description"),background:r("background_description"),watermark:r("watermark_description")};return(0,s.jsxs)("div",{className:"overflow-hidden rounded-[1.75rem] border border-border bg-background/70 shadow-2xl",children:[(0,s.jsxs)("div",{className:"grid min-h-[34rem] lg:grid-cols-[0.93fr_1.07fr]",children:[(0,s.jsxs)("div",{className:"min-w-0 border-b border-border p-4 sm:p-6 lg:border-b-0 lg:border-r lg:p-7",children:[(0,s.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 text-lg font-extrabold text-foreground",children:[(0,s.jsx)("span",{className:"grid h-9 w-9 place-items-center rounded-xl bg-primary/15 text-primary",children:(0,s.jsx)(l.A,{className:"h-5 w-5"})}),(0,s.jsx)("span",{children:ey[t]})]}),(0,s.jsx)("p",{className:"mt-2 text-sm leading-6 text-muted-foreground",children:(0,s.jsx)("span",{children:ek[t]})})]}),S.length>0&&(0,s.jsx)("button",{type:"button",disabled:W,onClick:()=>{C.current||A(e=>(e.forEach(eh),[]))},className:"min-h-11 shrink-0 px-2 text-xs font-semibold text-muted-foreground hover:text-foreground disabled:opacity-40",children:(0,s.jsx)("span",{children:r("clear_all")})})]}),(0,s.jsx)("input",{ref:N,"data-testid":"browser-tool-file-input",type:"file",accept:"image/jpeg,image/png,image/webp",multiple:!0,className:"sr-only",onChange:e=>{eg(Array.from(e.target.files||[])),e.target.value=""}}),(0,s.jsxs)("div",{onDragEnter:e=>{e.preventDefault(),W||B(!0)},onDragOver:e=>e.preventDefault(),onDragLeave:e=>{e.preventDefault(),e.currentTarget===e.target&&B(!1)},onDrop:e=>{e.preventDefault(),B(!1),eg(Array.from(e.dataTransfer.files))},className:"mt-5 rounded-2xl border border-dashed px-5 py-8 text-center transition sm:py-10 ".concat(z?"border-primary bg-primary/10":"border-border bg-card/40 hover:border-primary/60 hover:bg-primary/5"),children:[(0,s.jsx)("span",{className:"mx-auto grid h-12 w-12 place-items-center rounded-2xl bg-primary/10 text-primary",children:(0,s.jsx)(i.A,{className:"h-6 w-6"})}),(0,s.jsx)("p",{className:"mt-4 font-bold text-foreground",children:(0,s.jsx)("span",{children:r("drop_title")})}),(0,s.jsx)("p",{className:"mt-1 text-xs leading-5 text-muted-foreground",children:(0,s.jsx)("span",{children:r("drop_hint",{size:k/1024/1024,max:a})})}),(0,s.jsxs)(y.$,{type:"button",variant:"outline",disabled:W||S.length>=a,onClick:()=>{var e;return null===(e=N.current)||void 0===e?void 0:e.click()},className:"mt-4 min-h-11 rounded-xl border-border bg-card text-foreground hover:bg-primary/10",children:[(0,s.jsx)(o.A,{className:"mr-2 h-4 w-4"}),(0,s.jsx)("span",{children:r("add_images")})]})]}),S.length>0&&(0,s.jsxs)("div",{className:"mt-4",children:[(0,s.jsxs)("div",{className:"mb-2 flex justify-between text-xs font-semibold text-muted-foreground",children:[(0,s.jsx)("span",{children:r("selected_count",{count:S.length})}),(0,s.jsx)("span",{children:r("max_batch",{max:a})})]}),eu?(0,s.jsx)("div",{className:"max-h-[24rem] overflow-y-auto rounded-xl border border-border bg-card/40",children:(0,s.jsxs)("table",{className:"w-full table-fixed text-left text-xs",children:[(0,s.jsx)("thead",{className:"sticky top-0 z-10 bg-card text-[11px] font-bold text-muted-foreground",children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{className:"w-[56%] px-3 py-2",children:(0,s.jsx)("span",{children:r("batch_file")})}),(0,s.jsx)("th",{className:"w-[22%] px-2 py-2",children:(0,s.jsx)("span",{children:r("batch_status")})}),(0,s.jsx)("th",{className:"w-[22%] px-2 py-2 text-right",children:(0,s.jsx)("span",{children:r("batch_action")})})]})}),(0,s.jsx)("tbody",{className:"divide-y divide-border",children:S.map(e=>(0,s.jsxs)("tr",{children:[(0,s.jsx)("td",{className:"px-3 py-2",children:(0,s.jsxs)("div",{className:"flex min-w-0 items-center gap-2",children:[(0,s.jsx)("img",{src:e.outputUrl||e.previewUrl,alt:"",className:"h-10 w-12 shrink-0 rounded object-cover"}),(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsx)("p",{className:"notranslate truncate font-semibold text-foreground",translate:"no",title:e.file.name,children:e.file.name}),(0,s.jsxs)("p",{className:"notranslate text-[10px] text-muted-foreground",translate:"no",children:[e.width," \xd7 ",e.height," \xb7 ",(e.file.size/1024/1024).toFixed(1)," MB"]})]})]})}),(0,s.jsx)("td",{className:"px-2 py-2 text-muted-foreground",children:(0,s.jsx)("span",{children:r("status_".concat(e.status))})}),(0,s.jsx)("td",{className:"px-2 py-2",children:(0,s.jsxs)("div",{className:"flex justify-end gap-1",children:["watermark"===t&&!W&&(0,s.jsx)("button",{type:"button",onClick:()=>ee(e.id),"aria-label":e.mask.length?r("edit_mask"):r("mark_watermark"),className:"grid h-8 w-8 place-items-center rounded-lg hover:bg-primary/10",children:(0,s.jsx)(d.A,{className:"h-4 w-4"})}),"completed"===e.status&&(0,s.jsx)("button",{type:"button",onClick:()=>void ej(e),"aria-label":r("download"),className:"grid h-8 w-8 place-items-center rounded-lg hover:bg-primary/10",children:(0,s.jsx)(c.A,{className:"h-4 w-4"})}),"failed"===e.status&&(0,s.jsx)("button",{type:"button",onClick:()=>void ew([e]),"aria-label":r("retry"),className:"grid h-8 w-8 place-items-center rounded-lg hover:bg-primary/10",children:(0,s.jsx)(m.A,{className:"h-4 w-4"})}),(0,s.jsx)("button",{type:"button",onClick:()=>ex(e.id),disabled:W,"aria-label":r("remove_image"),className:"grid h-8 w-8 place-items-center rounded-lg hover:bg-destructive/10 disabled:opacity-40",children:(0,s.jsx)(u.A,{className:"h-4 w-4"})})]})})]},e.id))})]})}):(0,s.jsx)("div",{className:"grid max-h-[18rem] grid-cols-2 gap-2 overflow-y-auto pr-1 sm:grid-cols-3",children:S.map(e=>(0,s.jsxs)("div",{className:"group relative aspect-[4/3] overflow-hidden rounded-xl border border-border bg-black",children:[(0,s.jsx)("img",{src:e.previewUrl,alt:e.file.name,className:"h-full w-full object-cover"}),"watermark"===t&&!W&&(0,s.jsxs)("button",{type:"button",onClick:()=>ee(e.id),"aria-label":e.mask.length?r("edit_mask"):r("mark_watermark"),className:"absolute left-1.5 top-1.5 flex min-h-10 items-center gap-1 rounded-full bg-black/75 px-2 text-[10px] font-bold text-white backdrop-blur hover:bg-primary hover:text-primary-foreground",children:[(0,s.jsx)(d.A,{className:"h-4 w-4"}),(0,s.jsx)("span",{className:"hidden sm:inline",children:e.mask.length?r("edit_mask"):r("mark_watermark")})]}),(0,s.jsx)("div",{className:"absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/90 to-transparent px-2 pb-2 pt-7",children:(0,s.jsxs)("span",{className:"flex items-center gap-1.5 truncate text-[11px] font-semibold text-white",children:["completed"===e.status?(0,s.jsx)(p.A,{className:"h-3.5 w-3.5 text-primary"}):"failed"===e.status?(0,s.jsx)(h.A,{className:"h-3.5 w-3.5 text-red-300"}):"ready"!==e.status?(0,s.jsx)(x.A,{className:"h-3.5 w-3.5 animate-spin text-primary"}):null,(0,s.jsx)("span",{children:r("status_".concat(e.status))})]})}),!W&&(0,s.jsx)("button",{type:"button",onClick:()=>ex(e.id),"aria-label":r("remove_image"),className:"absolute right-1.5 top-1.5 grid h-10 w-10 place-items-center rounded-full bg-black/70 text-white sm:opacity-0 sm:group-hover:opacity-100",children:(0,s.jsx)(u.A,{className:"h-4 w-4"})})]},e.id))})]}),"upscale"===t&&(0,s.jsxs)("div",{className:"mt-5 rounded-2xl border border-border bg-card/50 p-4",children:[(0,s.jsxs)("div",{className:"grid gap-4 sm:grid-cols-3 sm:divide-x sm:divide-border",children:[(0,s.jsxs)("fieldset",{className:"space-y-2 sm:pr-4",children:[(0,s.jsx)("legend",{className:"text-sm font-bold text-foreground",children:(0,s.jsx)("span",{children:r("resolution")})}),(0,s.jsx)("div",{className:"flex gap-4",children:[2,4].map(e=>(0,s.jsxs)("label",{className:"flex cursor-pointer items-center gap-1.5 text-sm text-foreground",children:[(0,s.jsx)("input",{type:"radio",name:"browser-upscale-scale",checked:F===e,disabled:W,onChange:()=>q(e),className:"accent-primary"}),(0,s.jsxs)("span",{className:"notranslate",translate:"no",children:[e,"\xd7"]})]},e))})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between text-sm font-semibold text-foreground sm:flex-col sm:items-start sm:px-4",children:[(0,s.jsx)("span",{children:r("processing_mode")}),(0,s.jsxs)("span",{className:"flex items-center gap-1 text-xs text-primary",children:[(0,s.jsx)("span",{"aria-hidden":"true",children:"â"}),(0,s.jsx)("span",{children:r("local_zero")})]})]}),(0,s.jsxs)("label",{className:"flex items-center justify-between gap-2 text-sm font-semibold text-foreground sm:flex-col sm:items-start sm:pl-4",children:[(0,s.jsx)("span",{children:r("output_format")}),(0,s.jsxs)("select",{value:Y,disabled:W,onChange:e=>Q(e.target.value),className:"rounded-lg border border-border bg-background px-2 py-1 text-sm text-foreground",children:[(0,s.jsx)("option",{value:"png",children:"PNG"}),(0,s.jsx)("option",{value:"jpg",children:"JPG"}),(0,s.jsx)("option",{value:"webp",children:"WebP"})]})]})]}),(0,s.jsx)("p",{className:"mt-4 border-t border-border pt-3 text-xs leading-5 text-muted-foreground",children:(0,s.jsx)("span",{children:r("upscale_private",{scale:F,megapixels:_(F,K)/1e6})})}),(0,s.jsx)("p",{className:"mt-2 text-xs leading-5 text-muted-foreground",children:(0,s.jsx)("span",{children:r("upscale_auto_fit")})}),S.filter(e=>"completed"!==e.status&&e.width&&e.height).map(e=>{let t=U(e.width,e.height,F,K);return t.adjusted?(0,s.jsxs)("p",{className:"mt-2 break-words text-xs leading-5 text-primary",children:[(0,s.jsx)("span",{className:"notranslate",translate:"no",children:e.file.name})," ",(0,s.jsx)("span",{children:r("upscale_fit_notice",{width:t.outputWidth,height:t.outputHeight,scale:Number(t.actualScale.toFixed(2))})}),t.actualScale<1&&(0,s.jsxs)("span",{children:[" ",r("upscale_reduced_notice")]})]},e.id):null})]}),"background"===t&&(0,s.jsxs)("div",{className:"mt-5 rounded-2xl border border-border bg-card/50 p-4",children:[(0,s.jsx)("p",{className:"text-sm font-bold text-foreground",children:(0,s.jsx)("span",{children:r("background_fill")})}),(0,s.jsx)("div",{className:"mt-3 flex flex-wrap gap-2",children:[["transparent",r("transparent")],["#ffffff",r("white")],["#000000",r("black")]].map(e=>{let[t,r]=e;return(0,s.jsx)("button",{type:"button",onClick:()=>{es(t),A(e=>e.map(e=>({...e,backgroundFill:t})))},className:"rounded-lg border px-3 py-1.5 text-xs font-semibold ".concat(ea===t?"border-primary bg-primary text-primary-foreground":"border-border bg-background text-foreground"),children:(0,s.jsx)("span",{children:r})},t)})}),(0,s.jsx)("p",{className:"mt-3 text-xs text-muted-foreground",children:(0,s.jsx)("span",{children:r("background_model_hint")})})]}),(0,s.jsxs)("div",{className:"mt-4 flex flex-col items-stretch gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,s.jsx)("p",{className:"text-xs font-semibold text-muted-foreground",children:(0,s.jsx)("span",{children:r("zero_credits")})}),(0,s.jsxs)("div",{className:"flex flex-wrap gap-2 sm:justify-end",children:[ec.length>1&&(0,s.jsxs)(y.$,{type:"button",variant:"outline",disabled:W,onClick:()=>void ew(ec),className:"min-h-11 rounded-xl border-border",children:[(0,s.jsx)(m.A,{className:"mr-1.5 h-4 w-4"}),(0,s.jsx)("span",{children:r("retry_failed")})]}),(0,s.jsxs)(y.$,{type:"button",disabled:W||!em.length,onClick:()=>void ew(),className:"min-h-11 flex-1 rounded-xl bg-primary px-5 font-black text-primary-foreground hover:bg-primary/90 sm:flex-none",children:[W?(0,s.jsx)(x.A,{className:"mr-2 h-4 w-4 animate-spin"}):(0,s.jsx)(g.A,{className:"mr-2 h-4 w-4"}),(0,s.jsx)("span",{children:W?r("processing"):r("process_batch")})]})]})]})]}),(0,s.jsxs)("div",{className:"min-w-0 bg-primary/[0.025] p-4 sm:p-6 lg:p-7",children:[(0,s.jsxs)("div",{className:"flex flex-col items-start gap-3 sm:flex-row sm:justify-between",children:[(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 text-lg font-extrabold text-foreground",children:[(0,s.jsx)("span",{className:"grid h-9 w-9 place-items-center rounded-xl bg-primary/15 text-primary",children:(0,s.jsx)(f.A,{className:"h-5 w-5"})}),(0,s.jsx)("span",{children:r("results_title")})]}),(0,s.jsx)("p",{className:"mt-2 text-sm leading-6 text-muted-foreground",children:(0,s.jsx)("span",{children:r("results_description")})})]}),ed.length>1&&(0,s.jsxs)(y.$,{type:"button",variant:"outline",size:"sm",onClick:()=>void ev(),className:"min-h-11 shrink-0 border-border text-foreground",children:[(0,s.jsx)(c.A,{className:"mr-1 h-4 w-4"}),(0,s.jsx)("span",{children:r("download_all")})]})]}),0===S.length?(0,s.jsx)("div",{className:"mt-5 grid min-h-[27rem] place-items-center rounded-2xl border border-dashed border-border bg-background/40 p-8 text-center",children:(0,s.jsxs)("div",{children:[(0,s.jsx)(l.A,{className:"mx-auto h-9 w-9 text-primary/50"}),(0,s.jsx)("p",{className:"mt-4 text-sm text-muted-foreground",children:(0,s.jsx)("span",{children:r("result_empty")})})]})}):(0,s.jsx)("div",{className:"mt-5 grid grid-cols-1 gap-3 sm:grid-cols-2",children:S.map(e=>(0,s.jsxs)("div",{className:"overflow-hidden rounded-2xl border border-border bg-background/60",children:[(0,s.jsxs)("div",{className:"relative aspect-[4/3] overflow-hidden bg-black",children:[(0,s.jsx)("img",{src:e.outputUrl||e.previewUrl,alt:e.file.name,className:"h-full w-full object-contain ".concat(e.outputUrl||"failed"===e.status?"":"opacity-30 blur-[1px]")}),"completed"!==e.status&&(0,s.jsx)("div",{className:"absolute inset-0 grid place-items-center bg-black/30 p-4 text-center backdrop-blur-[1px]",children:"failed"===e.status?(0,s.jsxs)("div",{children:[(0,s.jsx)(h.A,{className:"mx-auto h-6 w-6 text-red-300"}),(0,s.jsx)("p",{className:"mt-2 text-xs text-red-100",children:(0,s.jsx)("span",{children:e.error})})]}):"ready"===e.status?(0,s.jsx)("span",{className:"rounded-full bg-black/60 px-3 py-1.5 text-xs text-white",children:(0,s.jsx)("span",{children:r("status_ready")})}):(0,s.jsxs)("div",{children:[(0,s.jsx)(x.A,{className:"mx-auto h-6 w-6 animate-spin text-primary"}),(0,s.jsx)("p",{className:"mt-2 text-xs text-white",children:(0,s.jsx)("span",{children:r("status_".concat(e.status))})})]})})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2 p-3",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsx)("p",{className:"notranslate truncate text-xs font-bold text-foreground",translate:"no",children:e.file.name}),(0,s.jsx)("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:(0,s.jsx)("span",{children:"completed"===e.status?"upscale"===t?"".concat(e.outputScale||F,"\xd7 \xb7 ").concat(e.outputWidth," \xd7 ").concat(e.outputHeight):r("status_completed"):r("status_".concat(e.status))})}),e.requestId&&(0,s.jsxs)("p",{className:"notranslate mt-0.5 break-all text-[10px] text-muted-foreground",translate:"no",children:["ID: ",e.requestId]})]}),(0,s.jsxs)("div",{className:"flex shrink-0 gap-1",children:["background"===t&&"completed"===e.status&&(0,s.jsx)("button",{type:"button",onClick:()=>el(e.id),"aria-label":r("refine_cutout"),className:"grid h-11 w-11 place-items-center rounded-xl bg-card text-foreground hover:bg-primary/10",children:(0,s.jsx)(d.A,{className:"h-4 w-4"})}),"completed"===e.status&&(0,s.jsx)("button",{type:"button",onClick:()=>void ej(e),"aria-label":r("download"),className:"grid h-11 w-11
1 place-items-center rounded-xl bg-primary text-primary-foreground hover:bg-primary/90",children:(0,s.jsx)(c.A,{className:"h-4 w-4"})}),"failed"===e.status&&(0,s.jsx)("button",{type:"button",onClick:()=>void ew([e]),"aria-label":r("retry"),className:"grid h-11 w-11 place-items-center rounded-xl bg-card text-foreground",children:(0,s.jsx)(m.A,{className:"h-4 w-4"})})]})]}),"background"===t&&"completed"===e.status&&(0,s.jsx)("div",{className:"flex flex-wrap gap-1 border-t border-border px-3 py-2",children:[["transparent",r("transparent")],["#ffffff",r("white")],["#000000",r("black")]].map(t=>{let[r,a]=t;return(0,s.jsx)("button",{type:"button",onClick:()=>ep(e.id,{backgroundFill:r}),className:"rounded-lg border px-2 py-1 text-[10px] font-semibold ".concat((e.backgroundFill||ea)===r?"border-primary bg-primary/15 text-primary":"border-border text-muted-foreground hover:text-foreground"),children:(0,s.jsx)("span",{children:a})},r)})})]},e.id))}),S.length>0&&(0,s.jsx)("p",{className:"mt-4 text-center text-xs text-muted-foreground",children:(0,s.jsx)("span",{children:r("completed_summary",{completed:ed.length,total:S.length})})})]})]}),ei&&(0,s.jsx)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center bg-black/80 p-3 backdrop-blur-sm",role:"dialog","aria-modal":"true","aria-label":r("mark_watermark"),children:(0,s.jsxs)("div",{className:"flex max-h-[92dvh] w-full max-w-3xl flex-col overflow-y-auto rounded-2xl border border-border bg-card p-4 text-foreground shadow-2xl sm:p-6",children:[(0,s.jsxs)("div",{className:"flex justify-between gap-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"font-bold",children:(0,s.jsx)("span",{children:r("mark_watermark")})}),(0,s.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:(0,s.jsx)("span",{children:r("brush_hint")})})]}),(0,s.jsx)("button",{type:"button","aria-label":r("close"),onClick:()=>ee(""),className:"grid h-11 w-11 shrink-0 place-items-center",children:(0,s.jsx)(u.A,{className:"h-5 w-5"})})]}),(0,s.jsx)("div",{className:"mt-4 flex max-h-[58dvh] justify-center overflow-auto rounded-xl bg-black p-2",children:(0,s.jsxs)("div",{className:"relative inline-block max-w-full touch-none select-none overflow-hidden rounded-xl",onPointerDown:e=>{E.current=!0,I.current=crypto.randomUUID(),M.current=null,e.currentTarget.setPointerCapture(e.pointerId),ef(e)},onPointerMove:e=>{E.current&&ef(e)},onPointerUp:e=>{E.current=!1,M.current=null,e.currentTarget.releasePointerCapture(e.pointerId)},onPointerCancel:()=>{E.current=!1,M.current=null},children:[(0,s.jsx)("img",{src:ei.previewUrl,alt:ei.file.name,draggable:!1,className:"block max-h-[54dvh] max-w-full object-contain"}),(0,s.jsx)("div",{className:"pointer-events-none absolute inset-0",children:ei.mask.map((e,t)=>(0,s.jsx)("span",{className:"absolute aspect-square rounded-full bg-primary/60 ring-1 ring-white/50",style:{left:"".concat(e.x,"%"),top:"".concat(e.y,"%"),width:"".concat(e.size,"%"),transform:"translate(-50%, -50%)"}},t))})]})}),(0,s.jsxs)("div",{className:"mt-4 flex flex-col gap-3 rounded-xl border border-border bg-background/50 p-3 sm:flex-row sm:items-center",children:[(0,s.jsxs)("label",{className:"flex min-w-0 flex-1 items-center gap-3 text-xs font-bold",children:[(0,s.jsx)("span",{children:r("brush_size")}),(0,s.jsx)("input",{type:"range",min:"18",max:"88",value:et,onChange:e=>er(Number(e.target.value)),className:"min-w-0 flex-1 accent-primary"})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsxs)(y.$,{type:"button",variant:"outline",disabled:!ei.mask.length,onClick:()=>ep(ei.id,{mask:ei.mask.filter(e=>{var t;return e.stroke!==(null===(t=ei.mask.at(-1))||void 0===t?void 0:t.stroke)})}),children:[(0,s.jsx)(b.A,{className:"mr-1 h-4 w-4"}),(0,s.jsx)("span",{children:r("undo_mask")})]}),(0,s.jsxs)(y.$,{type:"button",variant:"outline",disabled:!ei.mask.length,onClick:()=>ep(ei.id,{mask:[]}),children:[(0,s.jsx)(w.A,{className:"mr-1 h-4 w-4"}),(0,s.jsx)("span",{children:r("clear_mask")})]})]})]}),(0,s.jsxs)(y.$,{type:"button",disabled:!ei.mask.length,onClick:()=>ee(""),className:"mt-3 h-11 bg-primary font-bold text-primary-foreground hover:bg-primary/90",children:[(0,s.jsx)(p.A,{className:"mr-2 h-4 w-4"}),(0,s.jsx)("span",{children:r("save_mask")})]})]})}),(null==eo?void 0:eo.outputUrl)&&(0,s.jsx)($,{sourceUrl:eo.previewUrl,cutoutUrl:eo.outputUrl,imageName:eo.file.name,copy:{title:r("refine_cutout"),description:r("refine_description"),erase:r("erase"),restore:r("restore"),brushSize:r("brush_size"),undo:r("undo_mask"),reset:r("clear_mask"),cancel:r("close"),apply:r("apply"),loading:r("loading_model"),saveFailed:r("processing_failed")},onCancel:()=>el(""),onError:e=>v.oR.error(e),onApply:e=>{eo.outputUrl&&URL.revokeObjectURL(eo.outputUrl),ep(eo.id,{outputBlob:e,outputUrl:URL.createObjectURL(e)}),el("")}})]})}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.